<commit_before>import Ember from 'ember';
import DS from 'ember-data';

import HasManyQuery from 'ember-data-has-many-query';
import config from 'ember-get-config';
import GenericDataAdapterMixin from 'ember-osf/mixins/generic-data-adapter';

import {
    singularize
} from 'ember-inflector';

/**
 * @module ember-osf
 * @submodule adapters
 */

/**
 * Base adapter class for all OSF APIv2 endpoints
 *
 * @class OsfAdapter
 * @extends DS.JSONAPIAdapter
 * @uses HasManyQuery.RESTAdapterMixin
 * @uses GenericDataAdapterMixin
 */
export default DS.JSONAPIAdapter.extend(HasManyQuery.RESTAdapterMixin, GenericDataAdapterMixin, {
    authorizer: config['ember-simple-auth'].authorizer,
    host: config.OSF.apiUrl,
    namespace: config.OSF.apiNamespace,
    buildURL(modelName, id, snapshot, requestType) {
        var url = this._super(...arguments);
        var options = (snapshot ? snapshot.adapterOptions : false) || {};
        if (requestType === 'deleteRecord' || requestType === 'updateRecord' || requestType === 'findRecord') {
            if (snapshot.record.get('links.self')) {
                url = snapshot.record.get('links.self');
            }
        } else if (options.url) {
            url = options.url;
        }

        // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing
        // slash to URLs for single documents, but DRF redirects to force a trailing slash
        if (url.lastIndexOf('/') !== url.length - 1) {<commit_msg>Override buildQuery so include parameters are changed to embed.<commit_after>import Ember from 'ember';
import DS from 'ember-data';

import HasManyQuery from 'ember-data-has-many-query';
import config from 'ember-get-config';
import GenericDataAdapterMixin from 'ember-osf/mixins/generic-data-adapter';

import {
    singularize
} from 'ember-inflector';

/**
 * @module ember-osf
 * @submodule adapters
 */

/**
 * Base adapter class for all OSF APIv2 endpoints
 *
 * @class OsfAdapter
 * @extends DS.JSONAPIAdapter
 * @uses HasManyQuery.RESTAdapterMixin
 * @uses GenericDataAdapterMixin
 */
export default DS.JSONAPIAdapter.extend(HasManyQuery.RESTAdapterMixin, GenericDataAdapterMixin, {
    authorizer: config['ember-simple-auth'].authorizer,
    host: config.OSF.apiUrl,
    namespace: config.OSF.apiNamespace,
    /**
     * Overrides buildQuery method - Allows users to embed resources with findRecord
     * OSF APIv2 does not have "include" functionality, instead we use 'embed'.
     * Usage: findRecord(type, id, {include: 'resource'}) or findRecord(type, id, {include: ['resource1', resource2]})
     * Swaps included resources with embedded resources
     */
    buildQuery() {
        var query = this._super(...arguments);
        if (query.include) {
            query.embed = query.include;
        }
        delete query.include;
        return query;
    },
    buildURL(modelName, id, snapshot, requestType) {
        var url = this._super(...arguments);
        var options = (snapshot ? snapshot.adapterOptions : false) || {};
        if (requestType === 'deleteRecord' || requestType === 'updateRecord' || requestType === 'findRecord') {
            if (snapshot.record.get('links.self')) {
                url = snapshot.record.get('links.self');
            }
        } else if (options.url) {
            url = options.url;
        }

        // Fix issue where CORS request failed on 301s: Ember does not seem to append trailing
        // slash to URLs for single documents, but DRF redirects to force a trailing slash
        if (url.lastIndexOf('/') !== url.length - 1) {
{'fraction_non_alphanumeric': 0.11967715001391595, 'fraction_numerical': 0.0036181463957695517, 'mean_word_length': 3.056433408577878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924374', 'n_tokens_mistral': 1040, 'n_tokens_neox': 1019, 'n_words': 288}