<commit_before>// -------------------------------------------------------------------------- \\
// File: Store.js                                                             \\
// Module: DataStore                                                          \\
// Requires: Core, Foundation, Record.js                                      \\
// Author: <NAME>                                                       \\
// License: © 2010-2015 FastMail Pty Ltd. MIT Licensed.                       \\
// -------------------------------------------------------------------------- \\

"use strict";

/**
    Module: DataStore

    The DataStore module provides classes for managing the CRUD lifecycle of
    data records.
*/

( function ( NS ) {

// Same as O.Status, inlined here for efficiency

// Core states:
var EMPTY        =   1;
var READY        =   2;
var DESTROYED    =   4;
var NON_EXISTENT =   8;
// Properties:
var LOADING      =  16; // Request in progress to fetch record or updates
var COMMITTING   =  32; // Request in progress to commit record
var NEW          =  64; // Record is not created on source (has no source id)
var DIRTY        = 128; // Record has local changes not yet committing
var OBSOLETE     = 256; // Record may have changes not yet requested

// ---

// Error messages.
var Status = NS.Status;
var CANNOT_CREATE_EXISTING_RECORD_ERROR =
        'O.Store Error: Cannot create existing record',
    CANNOT_WRITE_TO_UNREADY_RECORD_ERROR =
        'O.Store Error: Cannot write to unready record',
    FETCHED_IS_DESTROYED_OR_NON_EXISTENT_ERROR =
        'O.Store Error: Record loaded which has status destroyed or non-existent',
    SOURCE_COMMIT_CREATE_MISMATCH_ERROR =
        'O.Store Error: Source committed a create on a record not marked new',
    SOURCE_COMMIT_DESTROY_MISMATCH_ERROR =
        'O.Store Error: Source commited a destroy on a record not marked destroyed';

// ---

var sk = 1;
var generateStoreKey = function () {
    return 'k' + ( sk++ );
};

// ---

var filter = function ( accept, storeKey ) {
    return accept( this._skToData[ storeKey ], this, storeKey );
};

var sort = function ( compare, a, b ) {
    var _skToData = this._skToData,
        aIsFirst = compare( _skToData[ a ], _skToData[ b ], this );
    return aIsFirst || ( ~~a.slice( 1 ) - ~~b.slice( 1 ) );
};

// ---

var isEqual = NS.isEqual;
var guid = NS.guid;
var invoke = NS.RunLoop.invoke.bind( NS.RunLoop );

// ---

var typeToForeignRefAttrs = {};

var getForeignRefAttrs = function ( Type ) {
    var typeId = guid( Type );
    var foreignRefAttrs = typeToForeignRefAttrs[ typeId ];
    var proto, attrs, attrKey, propKey, attribute;
    if ( !foreignRefAttrs ) {
        proto = Type.prototype;
        attrs = NS.meta( proto ).attrs;
        foreignRefAttrs = [];
        for ( attrKey in attrs ) {
            propKey = attrs[ attrKey ];
            attribute = proto[ propKey ];
            if ( attribute instanceof NS.ToOneAttribute ) {
                foreignRefAttrs.push([ attrKey, 1, attribute.Type ]);
            }
            if ( attribute instanceof NS.ToManyAttribute ) {
                foreignRefAttrs.push([ attrKey, 0, attribute.recordType ]);
            }<commit_msg>Don't look up propKey if it's been removed<commit_after>// -------------------------------------------------------------------------- \\
// File: Store.js                                                             \\
// Module: DataStore                                                          \\
// Requires: Core, Foundation, Record.js                                      \\
// Author: <NAME>                                                       \\
// License: © 2010-2015 FastMail Pty Ltd. MIT Licensed.                       \\
// -------------------------------------------------------------------------- \\

"use strict";

/**
    Module: DataStore

    The DataStore module provides classes for managing the CRUD lifecycle of
    data records.
*/

( function ( NS ) {

// Same as O.Status, inlined here for efficiency

// Core states:
var EMPTY        =   1;
var READY        =   2;
var DESTROYED    =   4;
var NON_EXISTENT =   8;
// Properties:
var LOADING      =  16; // Request in progress to fetch record or updates
var COMMITTING   =  32; // Request in progress to commit record
var NEW          =  64; // Record is not created on source (has no source id)
var DIRTY        = 128; // Record has local changes not yet committing
var OBSOLETE     = 256; // Record may have changes not yet requested

// ---

// Error messages.
var Status = NS.Status;
var CANNOT_CREATE_EXISTING_RECORD_ERROR =
        'O.Store Error: Cannot create existing record',
    CANNOT_WRITE_TO_UNREADY_RECORD_ERROR =
        'O.Store Error: Cannot write to unready record',
    FETCHED_IS_DESTROYED_OR_NON_EXISTENT_ERROR =
        'O.Store Error: Record loaded which has status destroyed or non-existent',
    SOURCE_COMMIT_CREATE_MISMATCH_ERROR =
        'O.Store Error: Source committed a create on a record not marked new',
    SOURCE_COMMIT_DESTROY_MISMATCH_ERROR =
        'O.Store Error: Source commited a destroy on a record not marked destroyed';

// ---

var sk = 1;
var generateStoreKey = function () {
    return 'k' + ( sk++ );
};

// ---

var filter = function ( accept, storeKey ) {
    return accept( this._skToData[ storeKey ], this, storeKey );
};

var sort = function ( compare, a, b ) {
    var _skToData = this._skToData,
        aIsFirst = compare( _skToData[ a ], _skToData[ b ], this );
    return aIsFirst || ( ~~a.slice( 1 ) - ~~b.slice( 1 ) );
};

// ---

var isEqual = NS.isEqual;
var guid = NS.guid;
var invoke = NS.RunLoop.invoke.bind( NS.RunLoop );

// ---

var typeToForeignRefAttrs = {};

var getForeignRefAttrs = function ( Type ) {
    var typeId = guid( Type );
    var foreignRefAttrs = typeToForeignRefAttrs[ typeId ];
    var proto, attrs, attrKey, propKey, attribute;
    if ( !foreignRefAttrs ) {
        proto = Type.prototype;
        attrs = NS.meta( proto ).attrs;
        foreignRefAttrs = [];
        for ( attrKey in attrs ) {
            propKey = attrs[ attrKey ];
            attribute = propKey && proto[ propKey ];
            if ( attribute instanceof NS.ToOneAttribute ) {
                foreignRefAttrs.push([ attrKey, 1, attribute.Type ]);
            }
            if ( attribute instanceof NS.ToManyAttribute ) {
                foreignRefAttrs.push([ attrKey, 0, attribute.recordType ]);
            }
{'fraction_non_alphanumeric': 0.1458204334365325, 'fraction_numerical': 0.008978328173374612, 'mean_word_length': 1.6720430107526882, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3856830', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1760, 'n_words': 568}