<commit_before>import Response from 'ember-cli-mirage/response';

import summaryFixture from '../mirage/fixtures/summary';
import searchFixture from '../mirage/fixtures/search';
import categoriesFixture from '../mirage/fixtures/categories';
import crateFixture from '../mirage/fixtures/crate';
import crateVersionsFixture from '../mirage/fixtures/crate_versions';
import crateAuthorsFixture from '../mirage/fixtures/crate_authors';
import crateOwnersFixture from '../mirage/fixtures/crate_owners';
import crateTeamsFixture from '../mirage/fixtures/crate_teams';
import crateReverseDependenciesFixture from '../mirage/fixtures/crate_reverse_dependencies';
import crateDependenciesFixture from '../mirage/fixtures/crate_dependencies';
import crateDownloadsFixture from '../mirage/fixtures/crate_downloads';

export default function() {
    this.get('/summary', () => summaryFixture);

    this.namespace = '/api/v1';

    this.get('/crates', (schema, request) => {
        const { start, end } = pageParams(request);
        const payload = {
            crates: searchFixture.crates.slice(start, end),
            meta: searchFixture.meta,
        };

        if (request.queryParams.team_id) {
            let teamId = request.queryParams.team_id;
            payload.user = schema.teams.find(teamId);

        } else if (request.queryParams.user_id) {
            let userId = request.queryParams.user_id;
            payload.user = schema.users.find(userId);
        }

        return payload;
    });

    this.get('/categories', () => categoriesFixture);

    this.get('/crates/nanomsg', () => crateFixture);
    this.get('/crates/nanomsg/versions', () => crateVersionsFixture);
    this.get('/crates/nanomsg/:version_num/authors', () => crateAuthorsFixture);
    this.get('/crates/nanomsg/owner_user', () => crateOwnersFixture);
    this.get('/crates/nanomsg/owner_team', () => crateTeamsFixture);
    this.get('/crates/nanomsg/reverse_dependencies', () => crateReverseDependenciesFixture);
    this.get('/crates/nanomsg/:version_num/dependencies', () => crateDependenciesFixture);
    this.get('/crates/nanomsg/downloads', () => crateDownloadsFixture);
    this.get('/crates/nanomsg/:version_num/downloads', () => crateDownloadsFixture);

    this.get('/keywords', function(schema, request) {
        let { start, end } = pageParams(request);

        let allKeywords = schema.keywords.all().sort((a, b) => a.crates_cnt - b.crates_cnt);
        let keywords = allKeywords.slice(start, end);
        let total = allKeywords.length;

        return withMeta(this.serialize(keywords), { total });
    });

    this.get('/keywords/:keyword_id', (schema, request) => {
        let keywordId = request.params.keyword_id;
        let keyword = schema.keywords.find(keywordId);
        return keyword ? keyword : notFound();
    });<commit_msg>mirage/config: Replace hardcoded "nanomsg" crate name with ":crate_id" param<commit_after>import Response from 'ember-cli-mirage/response';

import summaryFixture from '../mirage/fixtures/summary';
import searchFixture from '../mirage/fixtures/search';
import categoriesFixture from '../mirage/fixtures/categories';
import crateFixture from '../mirage/fixtures/crate';
import crateVersionsFixture from '../mirage/fixtures/crate_versions';
import crateAuthorsFixture from '../mirage/fixtures/crate_authors';
import crateOwnersFixture from '../mirage/fixtures/crate_owners';
import crateTeamsFixture from '../mirage/fixtures/crate_teams';
import crateReverseDependenciesFixture from '../mirage/fixtures/crate_reverse_dependencies';
import crateDependenciesFixture from '../mirage/fixtures/crate_dependencies';
import crateDownloadsFixture from '../mirage/fixtures/crate_downloads';

export default function() {
    this.get('/summary', () => summaryFixture);

    this.namespace = '/api/v1';

    this.get('/crates', (schema, request) => {
        const { start, end } = pageParams(request);
        const payload = {
            crates: searchFixture.crates.slice(start, end),
            meta: searchFixture.meta,
        };

        if (request.queryParams.team_id) {
            let teamId = request.queryParams.team_id;
            payload.user = schema.teams.find(teamId);

        } else if (request.queryParams.user_id) {
            let userId = request.queryParams.user_id;
            payload.user = schema.users.find(userId);
        }

        return payload;
    });

    this.get('/categories', () => categoriesFixture);

    this.get('/crates/:crate_id', () => crateFixture);
    this.get('/crates/:crate_id/versions', () => crateVersionsFixture);
    this.get('/crates/:crate_id/:version_num/authors', () => crateAuthorsFixture);
    this.get('/crates/:crate_id/owner_user', () => crateOwnersFixture);
    this.get('/crates/:crate_id/owner_team', () => crateTeamsFixture);
    this.get('/crates/:crate_id/reverse_dependencies', () => crateReverseDependenciesFixture);
    this.get('/crates/:crate_id/:version_num/dependencies', () => crateDependenciesFixture);
    this.get('/crates/:crate_id/downloads', () => crateDownloadsFixture);
    this.get('/crates/:crate_id/:version_num/downloads', () => crateDownloadsFixture);

    this.get('/keywords', function(schema, request) {
        let { start, end } = pageParams(request);

        let allKeywords = schema.keywords.all().sort((a, b) => a.crates_cnt - b.crates_cnt);
        let keywords = allKeywords.slice(start, end);
        let total = allKeywords.length;

        return withMeta(this.serialize(keywords), { total });
    });

    this.get('/keywords/:keyword_id', (schema, request) => {
        let keywordId = request.params.keyword_id;
        let keyword = schema.keywords.find(keywordId);
        return keyword ? keyword : notFound();
    });
{'fraction_non_alphanumeric': 0.14848222029488292, 'fraction_numerical': 0.0003469210754553339, 'mean_word_length': 3.6276083467094704, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6295909', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1710, 'n_words': 292}