<commit_before>(function (enyo) {
	//*@public
	/**
		The _enyo.Store_ object is a runtime database of _records_ as they are created.
		While there can be multiple _stores_, there is always a top-level _store_ at
		_enyo.store_ that is used by _enyo.Model_ and _enyo.Collection_. The _store serves
		as a liason between _records_ and the requested _enyo.Source_ that dictates how they
		are retrieved and/or persisted. You can register _observers_ or _event listeners_ for
		a _record_ or _collection_ through the _store_ or a reference to the object directly.
		Every _record_ and every _collection_ has a reference to a _store_. If none is
		explicitly provided it will resolve to _enyo.store_.

		The _enyo.store_ indexes _records_ internally for faster lookup. Explore the API
		to see how these methods interact.
	*/
	enyo.kind({
		name: "enyo.Store",
		kind: enyo.Object,
		/**
			The hash of named _sources_ that are available for use on this _store_.
			The default _source_ is _ajax_ but other may be added by providing
			`enyo.defaultStoreProperties` with a _sources_ hash of those to add.
		*/
		sources: {ajax: "enyo.AjaxSource", jsonp: "enyo.JsonpSource"},
		/**
			By default, the store indexes records in several ways one of which is by its
			_primaryKey_ value if it exists. This is intended to be unique and it will
			complain when it finds multiple instances of the same _record_. Set this flag to
			`true` and it will no longer complain but __note__: having duplicate entries of the
			same unique _primaryKey_ in a single _store_ means you cannot use _find_ or
			_findLocal_ on that _primaryKey_, you would need to use _euid_.
		*/
		ignoreDuplicates: false,
		//*@protected
		records: null,
		collections: null,
		concat: ["sources"],
		//*@public
		/**
			Will create a new record of _kind_ (string or constructor) and accepts
			an optional _attributes_ and _options_ parameter(s) that will be passed
			to the constructor of the _enyo.Model_ (see enyo.Model.constructor). If
			_kind_ is not provided _enyo.Model_ will be used by default. Returns the
			newly created instance. Will set the _records_ _store_ property to this
			_store_.
		*/
		createRecord: function (kind, attrs, opts) {
			if (arguments.length < 3) {
				if (enyo.isObject(kind)) {
					opts = attrs;
					attrs = kind;
					kind = enyo.Model;
				}
			}
			var Kind = (enyo.isString(kind) && enyo.getPath(kind)) || (enyo.isFunction(kind) && kind);
			// test to see if opts are opts or attrs are opts
			opts = opts || {};
			enyo.mixin(opts, {store: this});
			// if we didn't find the constructor we just use default
			if (!Kind) { Kind = enyo.Model; }
			return new Kind(attrs, opts);
		},
		/**
			Retrieve a _record_ if it exists by its _euid_.
		*/
		getRecord: function (euid) {
			return this.records.euid[euid];
		},
		/**
			Retrieve a _collection_ if it exists by its _euid_.
		*/
		getCollection: function (euid) {
			return this.collections[euid];
		},
		/**
			Creates a _collection_ of _kind_ (string or constructor) and accepts
			an optional _records_ array and options to be passed to the constructor
			of the _collection_ as the second parameter. Will set the _store_ property
			to this _store_. Returns the newly created instance. If _kind_ is omitted
			_enyo.Collection_ will be used by default.
		*/
		createCollection: function (kind, records, opts) {
			if (arguments.length < 3) {
				if (enyo.isArray(kind)) {
					opts = records;
					records = kind;
					kind = enyo.Collection;
				}
			}
			var Kind = (enyo.isString(kind) && enyo.getPath(kind)) || (enyo.isFunction(kind) && kind);
			// test to see if opts are opts or records are opts
			opts = opts || {};
			enyo.mixin(opts, {store: this});
			// if we didn't find the constructor we just use default
			if (!Kind) { Kind = enyo.Collection; }
			return new Kind(records, opts);
		},
		/**
			Add a record by its _euid_ and if it has a value for its known
			_primaryKey_ we index it by this value as well for quicker reference
			later. This is mostly used internally as it is called automatically by
			_models_ as they are created. Returns `true` on successful addition,
			`false` otherwise.
		*/
		addRecord: function (rec) {
			var rr = this.records,
				pk = rec.primaryKey,
				// this is the object storing the primary keys by instance of a kind
				// since there could be overlap, have to create it if it doesn't already
				// exist
				kn = rr.pk[rec.kindName] || (rr.pk[rec.kindName] = {}),
				f  = false, id, p;
			// the one true universally unique identifier across all bounds at runtime
			// is the simplest case
			if (!rr.euid[rec.euid]) { (rr.euid[rec.euid]=rec) && (f=true); }
			// if there is a value for the primary key we need to add that
			if (enyo.exists((id=rec.get(pk)))) {
				// in this special indexing we ensure that a primary key does not
				// have duplicate entry -- same primary key value but different euid
				// indicates duplicates
				if ((p=kn[id]) && p.euid != rec.euid) {
					// we have a duplicate
					if (!this.ignoreDuplicates) {
						this.warn("duplicate record added to store, euid's `" + p.euid + "` and `" + rec.euid + "`" +
							", for primary key `" + pk + ": " + rec.get(pk) + "`, previous submission being overwritten " +
							"by newer, be careful as you don't know which instance you may have in any given control; " +
							"use strategies when possible to avoid this scenario or set enyo.store's `ignoreDuplicates` " +
							"flag to true.");
					}
				}
				f = (kn[id]=rec) && true;
			}
			// regardless of whether or not the record has a primary key now, that could be because
			// it is delayed in retrieving one, doesn't have one and won't, or either way we want to
			// know if it changes so mappings are accurate internally
			rec.addObserver(pk, this._recordKeyChanged);
			// for kind name registration we have to make sure that there are any entries
			// for that kind already
			if (!rr.kn[rec.kindName]) { rr.kn[rec.kindName] = {}; }
			if (!rr.kn[rec.kindName][rec.euid]) { (rr.kn[rec.kindName][rec.euid]=rec) && (f=true); }
			if (f) { rec.store = this; }
			return f;
		},
		/**
			Adds a collection to the _store_. This is typically done automatically
			and does not need to be called. Accepts a reference to the _collection_.
			Will set the _store_ to the _store_ property on the _collection_. Returns
			`true` on successful addition, `false` otherwise.
		*/
		addCollection: function (c) {
			var cc = this.collections,
				f  = false;
			if (!cc[c.euid]) { (cc[c.euid]=c) && (f=true); }
			if (f) {
				c.store = this;
				c.addListener("destroy", this._collectionDestroyed);
			}
			return f;
		},
		/**
			Removes a _collection_ from the _store_. Accepts a reference to the _collection_
			or the euid of the _collection_ to remove. Returns `true` on successful removal,
			`false` otherwise.
		*/
		removeCollection: function (c) {
			var cc = this.collections;
			c = (enyo.isString(c) && cc[c]) || c;
			delete cc[c.euid];
			c.removeListener("destroy", this._collectionDestroyed);
		},
		/**
			Will remove the reference for the given _record_ if it was in
			the _store_. This is called automatically when a _record_ is destroyed.
		*/
		removeRecord: function (rec) {
			var rr = this.records,
				pk = rec.primaryKey, id;
			rec.euid && delete rr.euid[rec.euid];
			(enyo.exists(id=rec.get(pk))) && (delete rr.pk[rec.kindName][id]);
			rec.euid && delete rr.kn[rec.kindName][rec.euid];
			rec.removeListener("destroy", this._recordDestroyed);
		},
		/**
			Requires a hash with _key_ _value_ pairs that are the source's name by
			which it can be referred to by this _store_ and the constructor, instance
			or path to either in a string.
		*/
		addSources: function (props) {
			var dd = this.sources;
			for (var k in props) { dd[k] = props; }
			this._initSources();
		},
		/**
			Accepts the name of a source of this _store_ to remove.
		*/
		removeSource: function (name) {
			delete this.sources[name];
		},
		/**
			Accepts an array of sources names to remove from the _store_.
		*/
		removeSources: function (sources) {
			var dd = this.sources;
			for (var i=0, k; (k=sources[i]); ++i) { delete dd[k]; }
		},
		/**
			This method is designed to query for a _record or records_ via a _source_ and can
			use various strategies to perform compilation of the results in the current _store_.
			This is an asynchronous method and requires 2 parameters, the kind of record to use
			as a constructor or string, and an options hash that includes a _success_ method,
			optionally a _fail_ method, a _source_ designating what source to use (or will use
			record kind's default), a _strategy_ (explained below), and a _attributes_ hash of the
			attributes to use in the query. How these _attributes_ are used in the query depends on
			the _source_ being used. The _success_ method expects to receive the original options
			hash passed into find followed by the result-set (returned by the _strategy_ explained below).

			There is a special use for this method if an _euid_ or _primaryKey_ value is provided, the<commit_msg>fix missing key<commit_after>(function (enyo) {
	//*@public
	/**
		The _enyo.Store_ object is a runtime database of _records_ as they are created.
		While there can be multiple _stores_, there is always a top-level _store_ at
		_enyo.store_ that is used by _enyo.Model_ and _enyo.Collection_. The _store serves
		as a liason between _records_ and the requested _enyo.Source_ that dictates how they
		are retrieved and/or persisted. You can register _observers_ or _event listeners_ for
		a _record_ or _collection_ through the _store_ or a reference to the object directly.
		Every _record_ and every _collection_ has a reference to a _store_. If none is
		explicitly provided it will resolve to _enyo.store_.

		The _enyo.store_ indexes _records_ internally for faster lookup. Explore the API
		to see how these methods interact.
	*/
	enyo.kind({
		name: "enyo.Store",
		kind: enyo.Object,
		/**
			The hash of named _sources_ that are available for use on this _store_.
			The default _source_ is _ajax_ but other may be added by providing
			`enyo.defaultStoreProperties` with a _sources_ hash of those to add.
		*/
		sources: {ajax: "enyo.AjaxSource", jsonp: "enyo.JsonpSource"},
		/**
			By default, the store indexes records in several ways one of which is by its
			_primaryKey_ value if it exists. This is intended to be unique and it will
			complain when it finds multiple instances of the same _record_. Set this flag to
			`true` and it will no longer complain but __note__: having duplicate entries of the
			same unique _primaryKey_ in a single _store_ means you cannot use _find_ or
			_findLocal_ on that _primaryKey_, you would need to use _euid_.
		*/
		ignoreDuplicates: false,
		//*@protected
		records: null,
		collections: null,
		concat: ["sources"],
		//*@public
		/**
			Will create a new record of _kind_ (string or constructor) and accepts
			an optional _attributes_ and _options_ parameter(s) that will be passed
			to the constructor of the _enyo.Model_ (see enyo.Model.constructor). If
			_kind_ is not provided _enyo.Model_ will be used by default. Returns the
			newly created instance. Will set the _records_ _store_ property to this
			_store_.
		*/
		createRecord: function (kind, attrs, opts) {
			if (arguments.length < 3) {
				if (enyo.isObject(kind)) {
					opts = attrs;
					attrs = kind;
					kind = enyo.Model;
				}
			}
			var Kind = (enyo.isString(kind) && enyo.getPath(kind)) || (enyo.isFunction(kind) && kind);
			// test to see if opts are opts or attrs are opts
			opts = opts || {};
			enyo.mixin(opts, {store: this});
			// if we didn't find the constructor we just use default
			if (!Kind) { Kind = enyo.Model; }
			return new Kind(attrs, opts);
		},
		/**
			Retrieve a _record_ if it exists by its _euid_.
		*/
		getRecord: function (euid) {
			return this.records.euid[euid];
		},
		/**
			Retrieve a _collection_ if it exists by its _euid_.
		*/
		getCollection: function (euid) {
			return this.collections[euid];
		},
		/**
			Creates a _collection_ of _kind_ (string or constructor) and accepts
			an optional _records_ array and options to be passed to the constructor
			of the _collection_ as the second parameter. Will set the _store_ property
			to this _store_. Returns the newly created instance. If _kind_ is omitted
			_enyo.Collection_ will be used by default.
		*/
		createCollection: function (kind, records, opts) {
			if (arguments.length < 3) {
				if (enyo.isArray(kind)) {
					opts = records;
					records = kind;
					kind = enyo.Collection;
				}
			}
			var Kind = (enyo.isString(kind) && enyo.getPath(kind)) || (enyo.isFunction(kind) && kind);
			// test to see if opts are opts or records are opts
			opts = opts || {};
			enyo.mixin(opts, {store: this});
			// if we didn't find the constructor we just use default
			if (!Kind) { Kind = enyo.Collection; }
			return new Kind(records, opts);
		},
		/**
			Add a record by its _euid_ and if it has a value for its known
			_primaryKey_ we index it by this value as well for quicker reference
			later. This is mostly used internally as it is called automatically by
			_models_ as they are created. Returns `true` on successful addition,
			`false` otherwise.
		*/
		addRecord: function (rec) {
			var rr = this.records,
				pk = rec.primaryKey,
				// this is the object storing the primary keys by instance of a kind
				// since there could be overlap, have to create it if it doesn't already
				// exist
				kn = rr.pk[rec.kindName] || (rr.pk[rec.kindName] = {}),
				f  = false, id, p;
			// the one true universally unique identifier across all bounds at runtime
			// is the simplest case
			if (!rr.euid[rec.euid]) { (rr.euid[rec.euid]=rec) && (f=true); }
			// if there is a value for the primary key we need to add that
			if (enyo.exists((id=rec.get(pk)))) {
				// in this special indexing we ensure that a primary key does not
				// have duplicate entry -- same primary key value but different euid
				// indicates duplicates
				if ((p=kn[id]) && p.euid != rec.euid) {
					// we have a duplicate
					if (!this.ignoreDuplicates) {
						this.warn("duplicate record added to store, euid's `" + p.euid + "` and `" + rec.euid + "`" +
							", for primary key `" + pk + ": " + rec.get(pk) + "`, previous submission being overwritten " +
							"by newer, be careful as you don't know which instance you may have in any given control; " +
							"use strategies when possible to avoid this scenario or set enyo.store's `ignoreDuplicates` " +
							"flag to true.");
					}
				}
				f = (kn[id]=rec) && true;
			}
			// regardless of whether or not the record has a primary key now, that could be because
			// it is delayed in retrieving one, doesn't have one and won't, or either way we want to
			// know if it changes so mappings are accurate internally
			rec.addObserver(pk, this._recordKeyChanged);
			// for kind name registration we have to make sure that there are any entries
			// for that kind already
			if (!rr.kn[rec.kindName]) { rr.kn[rec.kindName] = {}; }
			if (!rr.kn[rec.kindName][rec.euid]) { (rr.kn[rec.kindName][rec.euid]=rec) && (f=true); }
			if (f) { rec.store = this; }
			return f;
		},
		/**
			Adds a collection to the _store_. This is typically done automatically
			and does not need to be called. Accepts a reference to the _collection_.
			Will set the _store_ to the _store_ property on the _collection_. Returns
			`true` on successful addition, `false` otherwise.
		*/
		addCollection: function (c) {
			var cc = this.collections,
				f  = false;
			if (!cc[c.euid]) { (cc[c.euid]=c) && (f=true); }
			if (f) {
				c.store = this;
				c.addListener("destroy", this._collectionDestroyed);
			}
			return f;
		},
		/**
			Removes a _collection_ from the _store_. Accepts a reference to the _collection_
			or the euid of the _collection_ to remove. Returns `true` on successful removal,
			`false` otherwise.
		*/
		removeCollection: function (c) {
			var cc = this.collections;
			c = (enyo.isString(c) && cc[c]) || c;
			delete cc[c.euid];
			c.removeListener("destroy", this._collectionDestroyed);
		},
		/**
			Will remove the reference for the given _record_ if it was in
			the _store_. This is called automatically when a _record_ is destroyed.
		*/
		removeRecord: function (rec) {
			var rr = this.records,
				pk = rec.primaryKey, id;
			rec.euid && delete rr.euid[rec.euid];
			(enyo.exists(id=rec.get(pk))) && (delete rr.pk[rec.kindName][id]);
			rec.euid && delete rr.kn[rec.kindName][rec.euid];
			rec.removeListener("destroy", this._recordDestroyed);
		},
		/**
			Requires a hash with _key_ _value_ pairs that are the source's name by
			which it can be referred to by this _store_ and the constructor, instance
			or path to either in a string.
		*/
		addSources: function (props) {
			var dd = this.sources;
			for (var k in props) { dd[k] = props[k]; }
			this._initSources();
		},
		/**
			Accepts the name of a source of this _store_ to remove.
		*/
		removeSource: function (name) {
			delete this.sources[name];
		},
		/**
			Accepts an array of sources names to remove from the _store_.
		*/
		removeSources: function (sources) {
			var dd = this.sources;
			for (var i=0, k; (k=sources[i]); ++i) { delete dd[k]; }
		},
		/**
			This method is designed to query for a _record or records_ via a _source_ and can
			use various strategies to perform compilation of the results in the current _store_.
			This is an asynchronous method and requires 2 parameters, the kind of record to use
			as a constructor or string, and an options hash that includes a _success_ method,
			optionally a _fail_ method, a _source_ designating what source to use (or will use
			record kind's default), a _strategy_ (explained below), and a _attributes_ hash of the
			attributes to use in the query. How these _attributes_ are used in the query depends on
			the _source_ being used. The _success_ method expects to receive the original options
			hash passed into find followed by the result-set (returned by the _strategy_ explained below).

			There is a special use for this method if an _euid_ or _primaryKey_ value is provided, the
{'fraction_non_alphanumeric': 0.09520679265954533, 'fraction_numerical': 0.00043823609969871266, 'mean_word_length': 3.1443813847900115, 'pattern_counts': {'":': 2, '<': 7, '<?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': '5750118', 'n_tokens_mistral': 6451, 'n_tokens_neox': 5558, 'n_words': 2337}