<commit_before>import SmartArgs from './lib/smartArguments.js';
import createSearchFilters from '../lib/createSearchFilters';

export default class Link {
    get config() { return this.linker.linkConfig; }

    get isVirtual() { return this.linker.isVirtual() }

    constructor(linker, object, collection) {
        this.linker = linker;
        this.object = object;
        this.linkedCollection = (collection) ? collection : linker.getLinkedCollection();

        if (this.linker.isVirtual()) {
            this.linkStorageField = this.config.relatedLinker.linkConfig.field;
        } else {
            this.linkStorageField = this.config.field;
        }
    }

    /**
     * Gets the stored link information value
     * @returns {*}
     */
    value() {
        if (this.isVirtual) {
            throw new Meteor.Error('You can only take the value from the main link.');
        }

        return this.object[this.linkStorageField];
    }

    /**
     * Finds linked data.
     *
     * @param filters
     * @param options
     * @returns {*}
     * @param userId
     */
    find(filters = {}, options = {}, userId = undefined) {
        let linker = this.linker;
        const linkedCollection = this.linkedCollection;

        let $metaFilters;
        if (filters.$meta) {
            $metaFilters = filters.$meta;
            delete filters.$meta;
        }

        const searchFilters = createSearchFilters(
            this.object,
            this.linkStorageField,
            linker.strategy,
            linker.isVirtual(),
            $metaFilters
        );

        let appliedFilters = _.extend({}, filters, searchFilters);

        return linkedCollection.find(appliedFilters, options, userId);
    }

    /**
     * @param filters
     * @param options
     * @param others
     * @returns {*|{content}|any}
     */
    fetch(filters, options, ...others) {
        let result = this.find(filters, options, ...others).fetch();

        if (this.linker.isOneResult()) {
            return _.first(result);
        }

        return result;
    }<commit_msg>workaround part deux<commit_after>import SmartArgs from './lib/smartArguments.js';
import createSearchFilters from '../lib/createSearchFilters';

export default class Link {
    get config() { return this.linker.linkConfig; }

    get isVirtual() { return this.linker.isVirtual() }

    constructor(linker, object, collection) {
        this.linker = linker;
        this.object = object;
        this.linkedCollection = (collection) ? collection : linker.getLinkedCollection();

        if (this.linker.isVirtual()) {
            this.linkStorageField = this.config.relatedLinker.linkConfig.field;
        } else {
            this.linkStorageField = this.config.field;
        }
    }

    /**
     * Gets the stored link information value
     * @returns {*}
     */
    value() {
        if (this.isVirtual) {
            throw new Meteor.Error('You can only take the value from the main link.');
        }

        return this.object[this.linkStorageField];
    }

    /**
     * Finds linked data.
     *
     * @param filters
     * @param options
     * @returns {*}
     * @param userId
     */
    find(filters = {}, options = {}, userId = undefined) {
        let linker = this.linker;
        const linkedCollection = this.linkedCollection;

        let $metaFilters;
        if (filters.$meta) {
            $metaFilters = filters.$meta;
            delete filters.$meta;
        }

        const searchFilters = createSearchFilters(
            this.object,
            this.linkStorageField,
            linker.strategy,
            linker.isVirtual(),
            $metaFilters
        );

        let appliedFilters = _.extend({}, filters, searchFilters);

        return (linkedCollection.find && linkedCollection.find(appliedFilters, options, userId)) || linkedCollection.default.find(appliedFilters, options, userId);
    }

    /**
     * @param filters
     * @param options
     * @param others
     * @returns {*|{content}|any}
     */
    fetch(filters, options, ...others) {
        let result = this.find(filters, options, ...others).fetch();

        if (this.linker.isOneResult()) {
            return _.first(result);
        }

        return result;
    }
{'fraction_non_alphanumeric': 0.11914794007490637, 'fraction_numerical': 0.0, 'mean_word_length': 2.0304964539007093, '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': '4303538', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1155, 'n_words': 264}