<commit_before>"use strict";

var getAliasMap = require("./getAliasMap"),
    Field = require("./Field"),
    getRequiredFields = require("./getRequiredFields");

module.exports = function modelFactory(tn, fullModel) {
    var model = fullModel[tn],
        requiredFields = getRequiredFields(model, fullModel),
        aliasMap = Object.freeze(getAliasMap(tn, fullModel)),
        fields = Object.keys(fullModel[tn].fields).reduce(function(obj, field) {
            obj[field] = new Field(fullModel[tn].fields[field]);

            return obj;
        }, {});

    /**
     * The model is publicly exposed
     * hence, we need a tamper-free interface
     */
    // TODO: simplify interface, it contains much unused crud
    return Object.create(null, {
        primary: {
            get: function() {
                return model.primary;
            },
            enumerable: true
        },
        // alias for primary
        pk: {
            get: function() {
                return model.primary;
            }
        },
        getField: {
            value: function(f) {
                if (fields[f]) {
                    return Object.freeze(fields[f]);
                }
            },
            enumerable: true
        },
        requiredFields: {
            get: function() {
                // return a copy to avoid tampering
                return requiredFields.slice();
            },
            enumerable: true
        },
        aliasMap: {
            get: function() {
                return aliasMap;
            },
            enumerable: true
        },
        extendedBy: {
            get: function() {
                return model.extendedBy || [];<commit_msg>removed "pk", as unused alias<commit_after>"use strict";

var getAliasMap = require("./getAliasMap"),
    Field = require("./Field"),
    getRequiredFields = require("./getRequiredFields");

module.exports = function modelFactory(tn, fullModel) {
    var model = fullModel[tn],
        requiredFields = getRequiredFields(model, fullModel),
        aliasMap = Object.freeze(getAliasMap(tn, fullModel)),
        fields = Object.keys(fullModel[tn].fields).reduce(function(obj, field) {
            obj[field] = new Field(fullModel[tn].fields[field]);

            return obj;
        }, {});

    /**
     * The model is publicly exposed
     * hence, we need a tamper-free interface
     */
    // TODO: simplify interface, it contains much unused crud
    return Object.create(null, {
        primary: {
            get: function() {
                return model.primary;
            },
            enumerable: true
        },
        getField: {
            value: function(f) {
                if (fields[f]) {
                    return Object.freeze(fields[f]);
                }
            },
            enumerable: true
        },
        requiredFields: {
            get: function() {
                // return a copy to avoid tampering
                return requiredFields.slice();
            },
            enumerable: true
        },
        aliasMap: {
            get: function() {
                return aliasMap;
            },
            enumerable: true
        },
        extendedBy: {
            get: function() {
                return model.extendedBy || [];
{'fraction_non_alphanumeric': 0.11313868613138686, 'fraction_numerical': 0.0, 'mean_word_length': 1.4973424449506454, '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': '5543857', 'n_tokens_mistral': 842, 'n_tokens_neox': 814, 'n_words': 196}