From 592dca41b5c9e4f52cb2f0e80571fef1b6dcfa99 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Sun, 29 Jan 2017 20:23:46 -0800 Subject: [PATCH] 3.0.0-rc.7 --- AUTHORS | 1 + dist/js-data.es2015.js | 172 +++++++++++++++-------------------- dist/js-data.es2015.js.map | 2 +- dist/js-data.js | 182 ++++++++++++++++--------------------- dist/js-data.js.map | 2 +- dist/js-data.min.js | 8 +- dist/js-data.min.map | 2 +- 7 files changed, 161 insertions(+), 208 deletions(-) diff --git a/AUTHORS b/AUTHORS index 766f1a9a..69d5465d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,6 +7,7 @@ # Alex antoinebrault +Cory Robinson David Madner Frans Krojegård InternalFX diff --git a/dist/js-data.es2015.js b/dist/js-data.es2015.js index c1b9a57a..2ce31ae7 100644 --- a/dist/js-data.es2015.js +++ b/dist/js-data.es2015.js @@ -1,6 +1,6 @@ /*! * js-data -* @version 3.0.0-rc.6 - Homepage +* @version 3.0.0-rc.7 - Homepage * @author js-data project authors * @copyright (c) 2014-2016 js-data project authors * @license MIT @@ -10,7 +10,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; @@ -25,6 +25,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol + + + + + + var defineProperty = function (obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { @@ -40,31 +46,6 @@ var defineProperty = function (obj, key, value) { return obj; }; -var get$1 = function get$1(object, property, receiver) { - if (object === null) object = Function.prototype; - var desc = Object.getOwnPropertyDescriptor(object, property); - - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - - if (parent === null) { - return undefined; - } else { - return get$1(parent, property, receiver); - } - } else if ("value" in desc) { - return desc.value; - } else { - var getter = desc.get; - - if (getter === undefined) { - return undefined; - } - - return getter.call(receiver); - } -}; - @@ -81,27 +62,9 @@ var get$1 = function get$1(object, property, receiver) { -var set$1 = function set$1(object, property, value, receiver) { - var desc = Object.getOwnPropertyDescriptor(object, property); - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - if (parent !== null) { - set$1(parent, property, value, receiver); - } - } else if ("value" in desc && desc.writable) { - desc.value = value; - } else { - var setter = desc.set; - if (setter !== undefined) { - setter.call(receiver, value); - } - } - - return value; -}; @@ -387,7 +350,7 @@ var utils = { * @throws {Error} Throws an error if the constructor is being improperly * invoked. */ - classCallCheck: function classCallCheck(instance, ctor) { + classCallCheck: function classCallCheck$$1(instance, ctor) { if (!(instance instanceof ctor)) { throw utils.err('' + ctor.name)(500, 'Cannot call a class as a function'); } @@ -424,7 +387,7 @@ var utils = { } else if (utils.isDate(from)) { to = new Date(from.getTime()); } else if (utils.isRegExp(from)) { - to = new RegExp(from.source, from.toString().match(/[^\/]*$/)[0]); + to = new RegExp(from.source, from.toString().match(/[^/]*$/)[0]); to.lastIndex = from.lastIndex; } else if (utils.isObject(from)) { if (plain) { @@ -992,7 +955,7 @@ var utils = { * @see utils.set * @since 3.0.0 */ - 'get': function get(object, prop) { + 'get': function get$$1(object, prop) { if (!prop) { return; } @@ -1501,13 +1464,10 @@ var utils = { * @since 3.0.0 */ pick: function pick(props, keys) { - var _props = {}; - utils.forOwn(props, function (value, key) { - if (keys.indexOf(key) !== -1) { - _props[key] = value; - } - }); - return _props; + return keys.reduce(function (map, key) { + map[key] = props[key]; + return map; + }, {}); }, @@ -1640,7 +1600,7 @@ var utils = { * object. * @param {*} [value] The value to set. */ - set: function set(object, path, value) { + set: function set$$1(object, path, value) { if (utils.isObject(path)) { utils.forOwn(path, function (value, _path) { utils.set(object, _path, value); @@ -2164,7 +2124,7 @@ var reserved = { }; // Used by our JavaScript implementation of the LIKE operator -var escapeRegExp = /([.*+?^=!:${}()|[\]\/\\])/g; +var escapeRegExp = /([.*+?^=!:${}()|[\]/\\])/g; var percentRegExp = /%/g; var underscoreRegExp = /_/g; var escape = function escape(pattern) { @@ -3671,6 +3631,15 @@ var COLLECTION_DEFAULTS = { */ commitOnMerge: true, + /** + * Whether record events should bubble up and be emitted by the collection. + * + * @name Collection#emitRecordEvents + * @type {boolean} + * @default true + */ + emitRecordEvents: true, + /** * Field to be used as the unique identifier for records in this collection. * Defaults to `"id"` unless {@link Collection#mapper} is set, in which case @@ -3838,7 +3807,9 @@ var Collection$1 = Component$1.extend({ * @param {...*} [arg] Args passed to {@link Collection#emit}. */ _onRecordEvent: function _onRecordEvent() { - this.emit.apply(this, arguments); + if (this.emitRecordEvents) { + this.emit.apply(this, arguments); + } }, @@ -3935,7 +3906,9 @@ var Collection$1 = Component$1.extend({ }); // Finally, return the inserted data var result = singular ? records[0] : records; - this.emit('add', result); + if (!opts.silent) { + this.emit('add', result); + } return this.afterAdd(records, opts, result) || result; }, @@ -4639,7 +4612,7 @@ var hasOneType = 'hasOne'; var DOMAIN$6 = 'Relation'; function Relation(relatedMapper) { - var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; utils.classCallCheck(this, Relation); @@ -4842,9 +4815,9 @@ var HasManyRelation = Relation.extend({ validateOptions: function validateOptions(related, opts) { Relation.prototype.validateOptions.call(this, related, opts); - var localKeys = opts.localKeys; - var foreignKeys = opts.foreignKeys; - var foreignKey = opts.foreignKey; + var localKeys = opts.localKeys, + foreignKeys = opts.foreignKeys, + foreignKey = opts.foreignKey; if (!foreignKey && !localKeys && !foreignKeys) { @@ -4953,7 +4926,7 @@ var HasOneRelation = Relation.extend({ * @returns {Function} Invocation function, which accepts the target as the only * parameter. */ -var belongsTo$1 = function belongsTo$1(related, opts) { +var belongsTo = function belongsTo(related, opts) { return function (mapper) { Relation.belongsTo(related, opts).assignTo(mapper); }; @@ -4973,7 +4946,7 @@ var belongsTo$1 = function belongsTo$1(related, opts) { * @returns {Function} Invocation function, which accepts the target as the only * parameter. */ -var hasMany$1 = function hasMany$1(related, opts) { +var hasMany = function hasMany(related, opts) { return function (mapper) { Relation.hasMany(related, opts).assignTo(mapper); }; @@ -4993,7 +4966,7 @@ var hasMany$1 = function hasMany$1(related, opts) { * @returns {Function} Invocation function, which accepts the target as the only * parameter. */ -var hasOne$1 = function hasOne$1(related, opts) { +var hasOne = function hasOne(related, opts) { return function (mapper) { Relation.hasOne(related, opts).assignTo(mapper); }; @@ -5308,7 +5281,7 @@ var Record$1 = Component$1.extend({ * @returns {*} Value at path. * @since 3.0.0 */ - 'get': function get(key) { + 'get': function get$$1(key) { return utils.get(this, key); }, @@ -5669,7 +5642,7 @@ var Record$1 = Component$1.extend({ * session.skill_level = 'beginner' * * // Update the record in the database - * return user.save() + * return session.save() * }) * * @method Record#save @@ -5744,7 +5717,7 @@ var Record$1 = Component$1.extend({ * @param {boolean} [opts.silent=false] Whether to trigger change events. * @since 3.0.0 */ - 'set': function set(key, value, opts) { + 'set': function set$$1(key, value, opts) { if (utils.isObject(key)) { opts = value; } @@ -6470,12 +6443,16 @@ var validationKeywords = { */ properties: function properties(value, schema, opts) { opts || (opts = {}); + + if (utils.isArray(value)) { + return; + } + // Can be a boolean or an object // Technically the default is an "empty schema", but here "true" is // functionally the same var additionalProperties = schema.additionalProperties === undefined ? true : schema.additionalProperties; - // "s": The property set of the instance to validate. - var toValidate = {}; + var validated = []; // "p": The property set from "properties". // Default is an object var properties = schema.properties || {}; @@ -6484,28 +6461,24 @@ var validationKeywords = { var patternProperties = schema.patternProperties || {}; var errors = []; - // Collect set "s" - utils.forOwn(value, function (_value, prop) { - toValidate[prop] = undefined; - }); - // Remove from "s" all elements of "p", if any. - utils.forOwn(properties || {}, function (_schema, prop) { + utils.forOwn(properties, function (_schema, prop) { opts.prop = prop; errors = errors.concat(_validate(value[prop], _schema, opts) || []); - delete toValidate[prop]; + validated.push(prop); }); - // For each regex in "pp", remove all elements of "s" which this regex - // matches. + + var toValidate = utils.omit(value, validated); utils.forOwn(patternProperties, function (_schema, pattern) { utils.forOwn(toValidate, function (undef, prop) { if (prop.match(pattern)) { opts.prop = prop; + // console.log(_schema) errors = errors.concat(_validate(value[prop], _schema, opts) || []); - delete toValidate[prop]; + validated.push(prop); } }); }); - var keys = Object.keys(toValidate); + var keys = Object.keys(utils.omit(value, validated)); // If "s" is not empty, validation fails if (additionalProperties === false) { if (keys.length) { @@ -7028,7 +7001,8 @@ function Schema(definition) { // TODO: schema validation utils.fillIn(this, definition); - if (this.type === 'object' && this.properties) { + if (this.type === 'object') { + this.properties = this.properties || {}; utils.forOwn(this.properties, function (_definition, prop) { if (!(_definition instanceof Schema)) { _this2.properties[prop] = new Schema(_definition); @@ -7700,8 +7674,8 @@ function Mapper(opts) { (function () { var superClass = Record$1; _this2.recordClass = superClass.extend({ - constructor: function Record$1() { - var subClass = function Record$1(props, opts) { + constructor: function Record() { + var subClass = function Record(props, opts) { utils.classCallCheck(this, subClass); superClass.call(this, props, opts); }; @@ -8079,8 +8053,8 @@ var Mapper$1 = Component$1.extend({ * @see http://www.js-data.io/v3.0/docs/relations * @since 3.0.0 */ - belongsTo: function belongsTo(relatedMapper, opts) { - return belongsTo$1(relatedMapper, opts)(this); + belongsTo: function belongsTo$$1(relatedMapper, opts) { + return belongsTo(relatedMapper, opts)(this); }, @@ -9164,8 +9138,8 @@ var Mapper$1 = Component$1.extend({ * @see http://www.js-data.io/v3.0/docs/relations * @since 3.0.0 */ - hasMany: function hasMany(relatedMapper, opts) { - return hasMany$1(relatedMapper, opts)(this); + hasMany: function hasMany$$1(relatedMapper, opts) { + return hasMany(relatedMapper, opts)(this); }, @@ -9185,8 +9159,8 @@ var Mapper$1 = Component$1.extend({ * @see http://www.js-data.io/v3.0/docs/relations * @since 3.0.0 */ - hasOne: function hasOne(relatedMapper, opts) { - return hasOne$1(relatedMapper, opts)(this); + hasOne: function hasOne$$1(relatedMapper, opts) { + return hasOne(relatedMapper, opts)(this); }, @@ -11195,7 +11169,7 @@ Component$1.extend(props); * @since 3.0.0 */ -var DOMAIN$9 = 'SimpleStore'; +var DOMAIN$8 = 'SimpleStore'; var proxiedCollectionMethods = [ /** * Wrapper for {@link Collection#add}. @@ -12501,6 +12475,7 @@ var props$2 = { * @param {string} name Name of the {@link Mapper} to target. * @param {(string|number)} id Passed to {@link Mapper#find}. * @param {Object} [opts] Passed to {@link Mapper#find}. + * @param {boolean} [opts.force] Bypass cacheFind * @param {boolean|Function} [opts.usePendingFind] See {@link SimpleStore#usePendingFind} * @returns {Promise} Resolves with the result, if any. * @since 3.0.0 @@ -12615,6 +12590,7 @@ var props$2 = { * @param {string} name Name of the {@link Mapper} to target. * @param {Object} [query] Passed to {@link Mapper.findAll}. * @param {Object} [opts] Passed to {@link Mapper.findAll}. + * @param {boolean} [opts.force] Bypass cacheFindAll * @param {boolean|Function} [opts.usePendingFindAll] See {@link SimpleStore#usePendingFindAll} * @returns {Promise} Resolves with the result, if any. * @since 3.0.0 @@ -12667,7 +12643,7 @@ var props$2 = { getCollection: function getCollection(name) { var collection = this._collections[name]; if (!collection) { - throw utils.err(DOMAIN$9 + '#getCollection', name)(404, 'collection'); + throw utils.err(DOMAIN$8 + '#getCollection', name)(404, 'collection'); } return collection; }, @@ -13023,7 +12999,7 @@ var props$2 = { var _this12 = this; opts || (opts = {}); - return Container.prototype.updateAll.call(this, name, query, props, opts).then(function (result) { + return Container.prototype.updateAll.call(this, name, props, query, opts).then(function (result) { return _this12._end(name, result, opts); }); }, @@ -13293,7 +13269,7 @@ var SimpleStore$1 = Container.extend(props$2); * @since 3.0.0 */ -var DOMAIN$10 = 'LinkedCollection'; +var DOMAIN$9 = 'LinkedCollection'; /** * Extends {@link Collection}. Used by a {@link DataStore} to implement an @@ -13327,7 +13303,7 @@ function LinkedCollection(records, opts) { // Make sure this collection has a reference to a datastore if (!this.datastore) { - throw utils.err('new ' + DOMAIN$10, 'opts.datastore')(400, 'DataStore', this.datastore); + throw utils.err('new ' + DOMAIN$9, 'opts.datastore')(400, 'DataStore', this.datastore); } } @@ -14093,7 +14069,7 @@ var DataStore$1 = SimpleStore$1.extend(props$1); * @type {Object} */ var version = { - full: '3.0.0-rc.6', + full: '3.0.0-rc.7', major: 3, minor: 0, patch: 0 @@ -14285,5 +14261,5 @@ var version = { * @type {Constructor} */ -export { version, Collection$1 as Collection, Component$1 as Component, Container, DataStore$1 as DataStore, Index, LinkedCollection$1 as LinkedCollection, Mapper$1 as Mapper, Query$1 as Query, Record$1 as Record, Schema$1 as Schema, Settable, SimpleStore$1 as SimpleStore, utils, belongsTo$1 as belongsTo, hasMany$1 as hasMany, hasOne$1 as hasOne, belongsToType, hasManyType, hasOneType }; +export { version, Collection$1 as Collection, Component$1 as Component, Container, DataStore$1 as DataStore, Index, LinkedCollection$1 as LinkedCollection, Mapper$1 as Mapper, Query$1 as Query, Record$1 as Record, Schema$1 as Schema, Settable, SimpleStore$1 as SimpleStore, utils, belongsTo, hasMany, hasOne, belongsToType, hasManyType, hasOneType }; //# sourceMappingURL=js-data.es2015.js.map diff --git a/dist/js-data.es2015.js.map b/dist/js-data.es2015.js.map index 70d9bfbf..b8523f90 100644 --- a/dist/js-data.es2015.js.map +++ b/dist/js-data.es2015.js.map @@ -1 +1 @@ -{"version":3,"file":null,"sources":["../src/utils.js","../src/Settable.js","../src/Component.js","../src/Query.js","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.js","../src/Relation.js","../src/Relation/BelongsTo.js","../src/Relation/HasMany.js","../src/Relation/HasOne.js","../src/relations.js","../src/decorators.js","../src/Record.js","../src/Schema.js","../src/Mapper.js","../src/Container.js","../src/SimpleStore.js","../src/LinkedCollection.js","../src/DataStore.js","../src/index.js"],"sourcesContent":["/**\n * Utility methods used by JSData.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @namespace utils\n * @type {Object}\n */\n\nconst DOMAIN = 'utils'\n\nconst INFINITY = 1 / 0\nconst MAX_INTEGER = 1.7976931348623157e+308\nconst BOOL_TAG = '[object Boolean]'\nconst DATE_TAG = '[object Date]'\nconst FUNC_TAG = '[object Function]'\nconst NUMBER_TAG = '[object Number]'\nconst OBJECT_TAG = '[object Object]'\nconst REGEXP_TAG = '[object RegExp]'\nconst STRING_TAG = '[object String]'\nconst objToString = Object.prototype.toString\nconst PATH = /^(.+)\\.(.+)$/\n\nconst ERRORS = {\n '400' () { return `expected: ${arguments[0]}, found: ${arguments[2] ? arguments[1] : typeof arguments[1]}` },\n '404' () { return `${arguments[0]} not found` }\n}\n\nconst toInteger = function (value) {\n if (!value) {\n return 0\n }\n // Coerce to number\n value = +value\n if (value === INFINITY || value === -INFINITY) {\n const sign = (value < 0 ? -1 : 1)\n return sign * MAX_INTEGER\n }\n const remainder = value % 1\n return value === value ? (remainder ? value - remainder : value) : 0 // eslint-disable-line\n}\n\nconst toStr = function (value) {\n return objToString.call(value)\n}\n\nconst isPlainObject = function (value) {\n return (!!value && typeof value === 'object' && value.constructor === Object)\n}\n\nconst mkdirP = function (object, path) {\n if (!path) {\n return object\n }\n const parts = path.split('.')\n parts.forEach(function (key) {\n if (!object[key]) {\n object[key] = {}\n }\n object = object[key]\n })\n return object\n}\n\nconst utils = {\n /**\n * Reference to the Promise constructor used by JSData. Defaults to\n * `window.Promise` or `global.Promise`.\n *\n * @example Make JSData use a different `Promise` constructor\n * import Promise from 'bluebird'\n * import {utils} from 'js-data'\n * utils.Promise = Promise\n *\n * @name utils.Promise\n * @since 3.0.0\n * @type {Function}\n */\n Promise: Promise,\n\n /**\n * Shallow copy properties that meet the following criteria from `src` to\n * `dest`:\n *\n * - own enumerable\n * - not a function\n * - does not start with \"_\"\n *\n * @method utils._\n * @param {Object} dest Destination object.\n * @param {Object} src Source object.\n * @private\n * @since 3.0.0\n */\n _ (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (key && dest[key] === undefined && !utils.isFunction(value) && key.indexOf('_') !== 0) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Recursively iterates over relations found in `opts.with`.\n *\n * @method utils._forRelation\n * @param {Object} opts Configuration options.\n * @param {Relation} def Relation definition.\n * @param {Function} fn Callback function.\n * @param {*} [thisArg] Execution context for the callback function.\n * @private\n * @since 3.0.0\n */\n _forRelation (opts, def, fn, thisArg) {\n const relationName = def.relation\n let containedName = null\n let index\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n if ((index = utils._getIndex(opts.with, relationName)) >= 0) {\n containedName = relationName\n } else if ((index = utils._getIndex(opts.with, def.localField)) >= 0) {\n containedName = def.localField\n }\n\n if (opts.withAll) {\n fn.call(thisArg, def, {})\n return\n } else if (!containedName) {\n return\n }\n let optsCopy = {}\n utils.fillIn(optsCopy, def.getRelation())\n utils.fillIn(optsCopy, opts)\n optsCopy.with = opts.with.slice()\n optsCopy._activeWith = optsCopy.with.splice(index, 1)[0]\n optsCopy.with.forEach(function (relation, i) {\n if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {\n optsCopy.with[i] = relation.substr(containedName.length + 1)\n } else {\n optsCopy.with[i] = ''\n }\n })\n fn.call(thisArg, def, optsCopy)\n },\n\n /**\n * Find the index of a relation in the given list\n *\n * @method utils._getIndex\n * @param {string[]} list List to search.\n * @param {string} relation Relation to find.\n * @private\n * @returns {number}\n */\n _getIndex (list, relation) {\n let index = -1\n list.forEach(function (_relation, i) {\n if (_relation === relation) {\n index = i\n return false\n } else if (utils.isObject(_relation)) {\n if (_relation.relation === relation) {\n index = i\n return false\n }\n }\n })\n return index\n },\n\n /**\n * Define hidden (non-enumerable), writable properties on `target` from the\n * provided `props`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {}\n * utils.addHiddenPropsToTarget(Cat.prototype, {\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat.say() // \"meow\"\n *\n * @method utils.addHiddenPropsToTarget\n * @param {Object} target That to which `props` should be added.\n * @param {Object} props Properties to be added to `target`.\n * @since 3.0.0\n */\n addHiddenPropsToTarget (target, props) {\n const map = {}\n Object.keys(props).forEach(function (propName) {\n const descriptor = Object.getOwnPropertyDescriptor(props, propName)\n\n descriptor.enumerable = false\n map[propName] = descriptor\n })\n Object.defineProperties(target, map)\n },\n\n /**\n * Return whether the two objects are deeply different.\n *\n * @example\n * import {utils} from 'js-data'\n * utils.areDifferent({}, {}) // false\n * utils.areDifferent({ a: 1 }, { a: 1 }) // false\n * utils.areDifferent({ foo: 'bar' }, {}) // true\n *\n * @method utils.areDifferent\n * @param {Object} a Base object.\n * @param {Object} b Comparison object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Whether the two objects are deeply different.\n * @see utils.diffObjects\n * @since 3.0.0\n */\n areDifferent (newObject, oldObject, opts) {\n opts || (opts = {})\n const diff = utils.diffObjects(newObject, oldObject, opts)\n const diffCount = Object.keys(diff.added).length +\n Object.keys(diff.removed).length +\n Object.keys(diff.changed).length\n return diffCount > 0\n },\n\n /**\n * Verified that the given constructor is being invoked via `new`, as opposed\n * to just being called like a normal function.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {\n * utils.classCallCheck(this, Cat)\n * }\n * const cat = new Cat() // this is ok\n * Cat() // this throws an error\n *\n * @method utils.classCallCheck\n * @param {*} instance Instance that is being constructed.\n * @param {Constructor} ctor Constructor function used to construct the\n * instance.\n * @since 3.0.0\n * @throws {Error} Throws an error if the constructor is being improperly\n * invoked.\n */\n classCallCheck (instance, ctor) {\n if (!(instance instanceof ctor)) {\n throw utils.err(`${ctor.name}`)(500, 'Cannot call a class as a function')\n }\n },\n\n /**\n * Deep copy a value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' } }\n * const b = utils.copy(a)\n * a === b // false\n * utils.areDifferent(a, b) // false\n *\n * @param {*} from Value to deep copy.\n * @param {*} [to] Destination object for the copy operation.\n * @param {*} [stackFrom] For internal use.\n * @param {*} [stackTo] For internal use.\n * @param {string[]|RegExp[]} [blacklist] List of strings or RegExp of\n * properties to skip.\n * @param {boolean} [plain] Whether to make a plain copy (don't try to use\n * original prototype).\n * @returns {*} Deep copy of `from`.\n * @since 3.0.0\n */\n copy (from, to, stackFrom, stackTo, blacklist, plain) {\n if (!to) {\n to = from\n if (from) {\n if (utils.isArray(from)) {\n to = utils.copy(from, [], stackFrom, stackTo, blacklist, plain)\n } else if (utils.isDate(from)) {\n to = new Date(from.getTime())\n } else if (utils.isRegExp(from)) {\n to = new RegExp(from.source, from.toString().match(/[^\\/]*$/)[0])\n to.lastIndex = from.lastIndex\n } else if (utils.isObject(from)) {\n if (plain) {\n to = utils.copy(from, {}, stackFrom, stackTo, blacklist, plain)\n } else {\n to = utils.copy(from, Object.create(Object.getPrototypeOf(from)), stackFrom, stackTo, blacklist, plain)\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(500, 'Cannot copy! Source and destination are identical.')\n }\n\n stackFrom = stackFrom || []\n stackTo = stackTo || []\n\n if (utils.isObject(from)) {\n let index = stackFrom.indexOf(from)\n if (index !== -1) {\n return stackTo[index]\n }\n\n stackFrom.push(from)\n stackTo.push(to)\n }\n\n let result\n if (utils.isArray(from)) {\n let i\n to.length = 0\n for (i = 0; i < from.length; i++) {\n result = utils.copy(from[i], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[i])) {\n stackFrom.push(from[i])\n stackTo.push(result)\n }\n to.push(result)\n }\n } else {\n if (utils.isArray(to)) {\n to.length = 0\n } else {\n utils.forOwn(to, function (value, key) {\n delete to[key]\n })\n }\n for (var key in from) {\n if (from.hasOwnProperty(key)) {\n if (utils.isBlacklisted(key, blacklist)) {\n continue\n }\n result = utils.copy(from[key], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[key])) {\n stackFrom.push(from[key])\n stackTo.push(result)\n }\n to[key] = result\n }\n }\n }\n }\n return to\n },\n\n /**\n * Recursively shallow fill in own enumerable properties from `source` to\n * `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"bip\"}\n *\n * @method utils.deepFillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n deepFillIn (dest, source) {\n if (source) {\n utils.forOwn(source, function (value, key) {\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepFillIn(existing, value)\n } else if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n }\n return dest\n },\n\n /**\n * Recursively shallow copy enumerable properties from `source` to `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"boop\"}\n *\n * @method utils.deepMixIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepFillIn\n * @since 3.0.0\n */\n deepMixIn (dest, source) {\n if (source) {\n for (var key in source) {\n const value = source[key]\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepMixIn(existing, value)\n } else {\n dest[key] = value\n }\n }\n }\n return dest\n },\n\n /**\n * Return a diff of the base object to the comparison object.\n *\n * @example\n * import {utils} from 'js-data'\n * const oldObject = { foo: 'bar', a: 1234 }\n * const newObject = { beep: 'boop', a: 5678 }\n * const diff = utils.diffObjects(oldObject, newObject)\n * console.log(diff.added) // {\"beep\":\"boop\"}\n * console.log(diff.changed) // {\"a\":5678}\n * console.log(diff.removed) // {\"foo\":undefined}\n *\n * @method utils.diffObjects\n * @param {Object} newObject Comparison object.\n * @param {Object} oldObject Base object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} The diff from the base object to the comparison object.\n * @see utils.areDifferent\n * @since 3.0.0\n */\n diffObjects (newObject, oldObject, opts) {\n opts || (opts = {})\n let equalsFn = opts.equalsFn\n let blacklist = opts.ignore\n const diff = {\n added: {},\n changed: {},\n removed: {}\n }\n if (!utils.isFunction(equalsFn)) {\n equalsFn = utils.deepEqual\n }\n\n const newKeys = Object.keys(newObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n const oldKeys = Object.keys(oldObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n\n // Check for properties that were added or changed\n newKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (equalsFn(oldValue, newValue)) {\n return\n }\n if (oldValue === undefined) {\n diff.added[key] = newValue\n } else {\n diff.changed[key] = newValue\n }\n })\n\n // Check for properties that were removed\n oldKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (newValue === undefined && oldValue !== undefined) {\n diff.removed[key] = undefined\n }\n })\n\n return diff\n },\n\n /**\n * Return whether the two values are equal according to the `==` operator.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.equal(1,1)) // true\n * console.log(utils.equal(1,'1')) // true\n * console.log(utils.equal(93, 66)) // false\n *\n * @method utils.equal\n * @param {*} a First value in the comparison.\n * @param {*} b Second value in the comparison.\n * @returns {boolean} Whether the two values are equal according to `==`.\n * @since 3.0.0\n */\n equal (a, b) {\n return a == b // eslint-disable-line\n },\n\n /**\n * Produce a factory function for making Error objects with the provided\n * metadata. Used throughout the various js-data components.\n *\n * @example\n * import {utils} from 'js-data'\n * const errorFactory = utils.err('domain', 'target')\n * const error400 = errorFactory(400, 'expected type', 'actual type')\n * console.log(error400) // [Error: [domain:target] expected: expected type, found: string\nhttp://www.js-data.io/v3.0/docs/errors#400]\n * @method utils.err\n * @param {string} domain Namespace.\n * @param {string} target Target.\n * @returns {Function} Factory function.\n * @since 3.0.0\n */\n err (domain, target) {\n return function (code) {\n const prefix = `[${domain}:${target}] `\n let message = ERRORS[code].apply(null, Array.prototype.slice.call(arguments, 1))\n message = `${prefix}${message}\nhttp://www.js-data.io/v3.0/docs/errors#${code}`\n return new Error(message)\n }\n },\n\n /**\n * Add eventing capabilities into the target object.\n *\n * @example\n * import {utils} from 'js-data'\n * const user = { name: 'John' }\n * utils.eventify(user)\n * user.on('foo', () => console.log(arguments))\n * user.emit('foo', 1, 'bar') // should log to console values (1, \"bar\")\n *\n * @method utils.eventify\n * @param {Object} target Target object.\n * @param {Function} [getter] Custom getter for retrieving the object's event\n * listeners.\n * @param {Function} [setter] Custom setter for setting the object's event\n * listeners.\n * @since 3.0.0\n */\n eventify (target, getter, setter) {\n target = target || this\n let _events = {}\n if (!getter && !setter) {\n getter = function () { return _events }\n setter = function (value) { _events = value }\n }\n Object.defineProperties(target, {\n emit: {\n value (...args) {\n const events = getter.call(this) || {}\n const type = args.shift()\n let listeners = events[type] || []\n let i\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n listeners = events.all || []\n args.unshift(type)\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n }\n },\n off: {\n value (type, func) {\n const events = getter.call(this)\n const listeners = events[type]\n if (!listeners) {\n setter.call(this, {})\n } else if (func) {\n for (let i = 0; i < listeners.length; i++) {\n if (listeners[i].f === func) {\n listeners.splice(i, 1)\n break\n }\n }\n } else {\n listeners.splice(0, listeners.length)\n }\n }\n },\n on: {\n value (type, func, thisArg) {\n if (!getter.call(this)) {\n setter.call(this, {})\n }\n const events = getter.call(this)\n events[type] = events[type] || []\n events[type].push({\n c: thisArg,\n f: func\n })\n }\n }\n })\n },\n\n /**\n * Used for sublcassing. Invoke this method in the context of a superclass to\n * to produce a subclass based on `props` and `classProps`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Animal () {}\n * Animal.extend = utils.extend\n * const Cat = Animal.extend({\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat instanceof Animal // true\n * cat instanceof Cat // true\n * cat.say() // \"meow\"\n *\n * @method utils.extend\n * @param {Object} props Instance properties for the subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to use as the subclass.\n * @param {Object} props Static properties for the subclass.\n * @returns {Constructor} A new subclass.\n * @since 3.0.0\n */\n extend (props, classProps) {\n const superClass = this\n let subClass\n\n props || (props = {})\n classProps || (classProps = {})\n\n if (props.hasOwnProperty('constructor')) {\n subClass = props.constructor\n delete props.constructor\n } else {\n subClass = function (...args) {\n utils.classCallCheck(this, subClass)\n superClass.apply(this, args)\n }\n }\n\n // Setup inheritance of instance members\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n configurable: true,\n enumerable: false,\n value: subClass,\n writable: true\n }\n })\n\n const obj = Object\n // Setup inheritance of static members\n if (obj.setPrototypeOf) {\n obj.setPrototypeOf(subClass, superClass)\n } else if (classProps.strictEs6Class) {\n subClass.__proto__ = superClass // eslint-disable-line\n } else {\n utils.forOwn(superClass, function (value, key) {\n subClass[key] = value\n })\n }\n if (!subClass.hasOwnProperty('__super__')) {\n Object.defineProperty(subClass, '__super__', {\n configurable: true,\n value: superClass\n })\n }\n\n utils.addHiddenPropsToTarget(subClass.prototype, props)\n utils.fillIn(subClass, classProps)\n\n return subClass\n },\n\n /**\n * Shallow copy own enumerable properties from `src` to `dest` that are on\n * `src` but are missing from `dest.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: 'bar', beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.fillIn(b, a)\n * console.log(b) // {\"foo\":\"bar\",\"beep\":\"bip\"}\n *\n * @method utils.fillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.deepFillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n fillIn (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Find the last index of an item in an array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = { name: 'John', age: 20 }\n * const sara = { name: 'Sara', age: 25 }\n * const dan = { name: 'Dan', age: 20 }\n * const users = [john, sara, dan]\n *\n * console.log(utils.findIndex(users, (user) => user.age === 25)) // 1\n * console.log(utils.findIndex(users, (user) => user.age > 19)) // 2\n * console.log(utils.findIndex(users, (user) => user.name === 'John')) // 0\n * console.log(utils.findIndex(users, (user) => user.name === 'Jimmy')) // -1\n *\n * @method utils.findIndex\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n * @returns {number} Index if found or -1 if not found.\n * @since 3.0.0\n */\n findIndex (array, fn) {\n let index = -1\n if (!array) {\n return index\n }\n array.forEach(function (record, i) {\n if (fn(record)) {\n index = i\n return false\n }\n })\n return index\n },\n\n /**\n * Recursively iterate over a {@link Mapper}'s relations according to\n * `opts.with`.\n *\n * @method utils.forEachRelation\n * @param {Mapper} mapper Mapper.\n * @param {Object} opts Configuration options.\n * @param {Function} fn Callback function.\n * @param {*} thisArg Execution context for the callback function.\n * @since 3.0.0\n */\n forEachRelation (mapper, opts, fn, thisArg) {\n const relationList = mapper.relationList || []\n if (!relationList.length) {\n return\n }\n relationList.forEach(function (def) {\n utils._forRelation(opts, def, fn, thisArg)\n })\n },\n\n /**\n * Iterate over an object's own enumerable properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { b: 1, c: 4 }\n * let sum = 0\n * utils.forOwn(a, function (value, key) {\n * sum += value\n * })\n * console.log(sum) // 5\n *\n * @method utils.forOwn\n * @param {Object} object The object whose properties are to be enumerated.\n * @param {Function} fn Iteration function.\n * @param {Object} [thisArg] Content to which to bind `fn`.\n * @since 3.0.0\n */\n forOwn (obj, fn, thisArg) {\n const keys = Object.keys(obj)\n const len = keys.length\n let i\n for (i = 0; i < len; i++) {\n fn.call(thisArg, obj[keys[i]], keys[i], obj)\n }\n },\n\n /**\n * Proxy for `JSON.parse`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = utils.fromJson('{\"name\" : \"John\"}')\n * console.log(a) // { name: 'John' }\n *\n * @method utils.fromJson\n * @param {string} json JSON to parse.\n * @returns {Object} Parsed object.\n * @see utils.toJson\n * @since 3.0.0\n */\n fromJson (json) {\n return utils.isString(json) ? JSON.parse(json) : json\n },\n\n /**\n * Retrieve the specified property from the given object. Supports retrieving\n * nested properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * console.log(utils.get(a, 'beep')) // \"boop\"\n * console.log(utils.get(a, 'foo.bar')) // \"baz\"\n *\n * @method utils.get\n * @param {Object} object Object from which to retrieve a property's value.\n * @param {string} prop Property to retrieve.\n * @returns {*} Value of the specified property.\n * @see utils.set\n * @since 3.0.0\n */\n 'get': function (object, prop) {\n if (!prop) {\n return\n }\n const parts = prop.split('.')\n const last = parts.pop()\n\n while (prop = parts.shift()) { // eslint-disable-line\n object = object[prop]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n return object[last]\n },\n\n /**\n * Return the superclass for the given instance or subclass. If an instance is\n * provided, then finds the parent class of the instance's constructor.\n *\n * @example\n * import {utils} from 'js-data'\n * // using ES2015 classes\n * class Foo {}\n * class Bar extends Foo {}\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * // using Function constructor with utils.extend\n * function Foo () {}\n * Foo.extend = utils.extend\n * const Bar = Foo.extend()\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * @method utils.getSuper\n * @param {Object|Function} instance Instance or constructor.\n * @param {boolean} [isCtor=false] Whether `instance` is a constructor.\n * @returns {Constructor} The superclass (grandparent constructor).\n * @since 3.0.0\n */\n getSuper (instance, isCtor) {\n const ctor = isCtor ? instance : instance.constructor\n if (ctor.hasOwnProperty('__super__')) {\n return ctor.__super__\n }\n return Object.getPrototypeOf(ctor) || ctor.__proto__ // eslint-disable-line\n },\n\n /**\n * Return the intersection of two arrays.\n *\n * @example\n * import {utils} from 'js-data'\n * const arrA = ['green', 'red', 'blue', 'red']\n * const arrB = ['green', 'yellow', 'red']\n * const intersected = utils.intersection(arrA, arrB)\n *\n * console.log(intersected) // ['green', 'red'])\n *\n * @method utils.intersection\n * @param {Array} array1 First array.\n * @param {Array} array2 Second array.\n * @returns {Array} Array of elements common to both arrays.\n * @since 3.0.0\n */\n intersection (array1, array2) {\n if (!array1 || !array2) {\n return []\n }\n const result = []\n let item\n let i\n const len = array1.length\n for (i = 0; i < len; i++) {\n item = array1[i]\n if (result.indexOf(item) !== -1) {\n continue\n }\n if (array2.indexOf(item) !== -1) {\n result.push(item)\n }\n }\n return result\n },\n\n /**\n * Proxy for `Array.isArray`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = [1,2,3,4,5]\n * const b = { foo: \"bar\" }\n * console.log(utils.isArray(a)) // true\n * console.log(utils.isArray(b)) // false\n *\n * @method utils.isArray\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an array.\n * @since 3.0.0\n */\n isArray: Array.isArray,\n\n /**\n * Return whether `prop` is matched by any string or regular expression in\n * `blacklist`.\n *\n * @example\n * import {utils} from 'js-data'\n * const blacklist = [/^\\$hashKey/g, /^_/g, 'id']\n * console.log(utils.isBlacklisted(\"$hashKey\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"id\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"_myProp\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"my_id\", blacklist)) // false\n *\n * @method utils.isBlacklisted\n * @param {string} prop The name of a property to check.\n * @param {Array} blacklist Array of strings and regular expressions.\n * @returns {boolean} Whether `prop` was matched.\n * @since 3.0.0\n */\n isBlacklisted (prop, blacklist) {\n if (!blacklist || !blacklist.length) {\n return false\n }\n let matches\n for (var i = 0; i < blacklist.length; i++) {\n if ((toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) || blacklist[i] === prop) {\n matches = prop\n return !!matches\n }\n }\n return !!matches\n },\n\n /**\n * Return whether the provided value is a boolean.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = true\n * const b = { foo: \"bar\" }\n * console.log(utils.isBoolean(a)) // true\n * console.log(utils.isBoolean(b)) // false\n *\n * @method utils.isBoolean\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a boolean.\n * @since 3.0.0\n */\n isBoolean (value) {\n return toStr(value) === BOOL_TAG\n },\n\n /**\n * Return whether the provided value is a date.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = new Date()\n * const b = { foo: \"bar\" }\n * console.log(utils.isDate(a)) // true\n * console.log(utils.isDate(b)) // false\n *\n * @method utils.isDate\n * @param {*} value The value to test.\n * @returns {Date} Whether the provided value is a date.\n * @since 3.0.0\n */\n isDate (value) {\n return (value && typeof value === 'object' && toStr(value) === DATE_TAG)\n },\n\n /**\n * Return whether the provided value is a function.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = function (){ console.log('foo bar')}\n * const b = { foo: \"bar\" }\n * console.log(utils.isFunction(a)) // true\n * console.log(utils.isFunction(b)) // false\n *\n * @method utils.isFunction\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a function.\n * @since 3.0.0\n */\n isFunction (value) {\n return typeof value === 'function' || (value && toStr(value) === FUNC_TAG)\n },\n\n /**\n * Return whether the provided value is an integer.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = 1.25\n * const c = '1'\n * console.log(utils.isInteger(a)) // true\n * console.log(utils.isInteger(b)) // false\n * console.log(utils.isInteger(c)) // false\n *\n * @method utils.isInteger\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an integer.\n * @since 3.0.0\n */\n isInteger (value) {\n return toStr(value) === NUMBER_TAG && value == toInteger(value) // eslint-disable-line\n },\n\n /**\n * Return whether the provided value is `null`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = null\n * const b = { foo: \"bar\" }\n * console.log(utils.isNull(a)) // true\n * console.log(utils.isNull(b)) // false\n *\n * @method utils.isNull\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is `null`.\n * @since 3.0.0\n */\n isNull (value) {\n return value === null\n },\n\n /**\n * Return whether the provided value is a number.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = -1.25\n * const c = '1'\n * console.log(utils.isNumber(a)) // true\n * console.log(utils.isNumber(b)) // true\n * console.log(utils.isNumber(c)) // false\n *\n * @method utils.isNumber\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a number.\n * @since 3.0.0\n */\n isNumber (value) {\n const type = typeof value\n return type === 'number' || (value && type === 'object' && toStr(value) === NUMBER_TAG)\n },\n\n /**\n * Return whether the provided value is an object.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\" }\n * const b = 'foo bar'\n * console.log(utils.isObject(a)) // true\n * console.log(utils.isObject(b)) // false\n *\n * @method utils.isObject\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an object.\n * @since 3.0.0\n */\n isObject (value) {\n return toStr(value) === OBJECT_TAG\n },\n\n /**\n * Return whether the provided value is a regular expression.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = /^\\$.+$/ig\n * const b = new RegExp('^\\$.+$', 'ig')\n * const c = { foo: \"bar\" }\n * console.log(utils.isRegExp(a)) // true\n * console.log(utils.isRegExp(b)) // true\n * console.log(utils.isRegExp(c)) // false\n *\n * @method utils.isRegExp\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a regular expression.\n * @since 3.0.0\n */\n isRegExp (value) {\n return toStr(value) === REGEXP_TAG\n },\n\n /**\n * Return whether the provided value is a string or a number.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isSorN('')) // true\n * console.log(utils.isSorN(-1.65)) // true\n * console.log(utils.isSorN('my string')) // true\n * console.log(utils.isSorN({})) // false\n * console.log(utils.isSorN([1,2,4])) // false\n *\n * @method utils.isSorN\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string or a number.\n * @since 3.0.0\n */\n isSorN (value) {\n return utils.isString(value) || utils.isNumber(value)\n },\n\n /**\n * Return whether the provided value is a string.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('')) // true\n * console.log(utils.isString('my string')) // true\n * console.log(utils.isString(100)) // false\n * console.log(utils.isString([1,2,4])) // false\n *\n * @method utils.isString\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string.\n * @since 3.0.0\n */\n isString (value) {\n return typeof value === 'string' || (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n },\n\n /**\n * Return whether the provided value is a `undefined`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = undefined\n * const b = { foo: \"bar\"}\n * console.log(utils.isUndefined(a)) // true\n * console.log(utils.isUndefined(b.baz)) // true\n * console.log(utils.isUndefined(b)) // false\n * console.log(utils.isUndefined(b.foo)) // false\n *\n * @method utils.isUndefined\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a `undefined`.\n * @since 3.0.0\n */\n isUndefined (value) {\n return value === undefined\n },\n\n /**\n * Mix in logging capabilities to the target.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\"}\n *\n * // Add standard logging to an object\n * utils.logify(a)\n * a.log('info', 'test log info') // output 'test log info' to console.\n *\n * // Toggle debug output of an object\n * a.dbg('test debug output') // does not output because debug is off.\n * a.debug = true\n * a.dbg('test debug output') // output 'test debug output' to console.\n *\n * @method utils.logify\n * @param {*} target The target.\n * @since 3.0.0\n */\n logify (target) {\n utils.addHiddenPropsToTarget(target, {\n dbg (...args) {\n if (utils.isFunction(this.log)) {\n this.log('debug', ...args)\n }\n },\n log (level, ...args) {\n if (level && !args.length) {\n args.push(level)\n level = 'debug'\n }\n if (level === 'debug' && !this.debug) {\n return\n }\n const prefix = `${level.toUpperCase()}: (${this.name || this.constructor.name})`\n if (utils.isFunction(console[level])) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n }\n })\n },\n\n /**\n * Adds the given record to the provided array only if it's not already in the\n * array.\n *\n * @example\n * import {utils} from 'js-data'\n * const colors = ['red', 'green', 'yellow']\n *\n * console.log(colors.length) // 3\n * utils.noDupeAdd(colors, 'red')\n * console.log(colors.length) // 3, red already exists\n *\n * utils.noDupeAdd(colors, 'blue')\n * console.log(colors.length) // 4, blue was added\n *\n * @method utils.noDupeAdd\n * @param {Array} array The array.\n * @param {*} record The value to add.\n * @param {Function} fn Callback function passed to {@link utils.findIndex}.\n * @since 3.0.0\n */\n noDupeAdd (array, record, fn) {\n if (!array) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index < 0) {\n array.push(record)\n }\n },\n\n /**\n * Return a shallow copy of the provided object, minus the properties\n * specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.omit(a, ['$hashKey'])\n * console.log(b) // { name: 'John' }\n *\n * @method utils.omit\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to skip.\n * @returns {Object} Shallow copy of `props`, minus `keys`.\n * @since 3.0.0\n */\n omit (props, keys) {\n const _props = {}\n utils.forOwn(props, function (value, key) {\n if (keys.indexOf(key) === -1) {\n _props[key] = value\n }\n })\n return _props\n },\n\n /**\n * Return a shallow copy of the provided object, but only include the\n * properties specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.pick(a, ['$hashKey'])\n * console.log(b) // { $hashKey: 1214910 }\n *\n * @method utils.pick\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to keep.\n * @returns {Object} Shallow copy of `props`, but only including `keys`.\n * @since 3.0.0\n */\n pick (props, keys) {\n const _props = {}\n utils.forOwn(props, function (value, key) {\n if (keys.indexOf(key) !== -1) {\n _props[key] = value\n }\n })\n return _props\n },\n\n /**\n * Return a plain copy of the given value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John' }\n * let b = utils.plainCopy(a)\n * console.log(a === b) // false\n *\n * @method utils.plainCopy\n * @param {*} value The value to copy.\n * @returns {*} Plain copy of `value`.\n * @see utils.copy\n * @since 3.0.0\n */\n plainCopy (value) {\n return utils.copy(value, undefined, undefined, undefined, undefined, true)\n },\n\n /**\n * Shortcut for `utils.Promise.reject(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.reject(\"Testing static reject\").then(function(data) {\n * // not called\n * }).catch(function(reason) {\n * console.log(reason); // \"Testing static reject\"\n * })\n *\n * @method utils.reject\n * @param {*} [value] Value with which to reject the Promise.\n * @returns {Promise} Promise reject with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n reject (value) {\n return utils.Promise.reject(value)\n },\n\n /**\n * Remove the last item found in array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const colors = ['red', 'green', 'yellow', 'red']\n * utils.remove(colors, (color) => color === 'red')\n * console.log(colors) // ['red', 'green', 'yellow']\n *\n * @method utils.remove\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n */\n remove (array, fn) {\n if (!array || !array.length) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index >= 0) {\n array.splice(index, 1) // todo should this be recursive?\n }\n },\n\n /**\n * Shortcut for `utils.Promise.resolve(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.resolve(\"Testing static resolve\").then(function(data) {\n * console.log(data); // \"Testing static resolve\"\n * }).catch(function(reason) {\n * // not called\n * })\n *\n * @param {*} [value] Value with which to resolve the Promise.\n * @returns {Promise} Promise resolved with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n resolve (value) {\n return utils.Promise.resolve(value)\n },\n\n /**\n * Set the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n * // set value by key\n * utils.set(john, 'id', 98)\n * console.log(john.id) // 98\n *\n * // set value by path\n * utils.set(john, 'parent.id', 20)\n * console.log(john.parent.id) // 20\n *\n * // set value by path/value map\n * utils.set(john, {\n * 'id': 1098,\n * 'parent': { id: 1020 },\n * 'parent.age': '55'\n * })\n * console.log(john.id) // 1098\n * console.log(john.parent.id) // 1020\n * console.log(john.parent.age) // 55\n *\n * @method utils.set\n * @param {Object} object The object on which to set a property.\n * @param {(string|Object)} path The key or path to the property. Can also\n * pass in an object of path/value pairs, which will all be set on the target\n * object.\n * @param {*} [value] The value to set.\n */\n set: function (object, path, value) {\n if (utils.isObject(path)) {\n utils.forOwn(path, function (value, _path) {\n utils.set(object, _path, value)\n })\n } else {\n const parts = PATH.exec(path)\n if (parts) {\n mkdirP(object, parts[1])[parts[2]] = value\n } else {\n object[path] = value\n }\n }\n },\n\n /**\n * Check whether the two provided objects are deeply equal.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const objA = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * const objB = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * console.log(utils.deepEqual(a,b)) // true\n * objB.nested.colors.add('yellow') // make a change to a nested object's array\n * console.log(utils.deepEqual(a,b)) // false\n *\n * @method utils.deepEqual\n * @param {Object} a First object in the comparison.\n * @param {Object} b Second object in the comparison.\n * @returns {boolean} Whether the two provided objects are deeply equal.\n * @see utils.equal\n * @since 3.0.0\n */\n deepEqual (a, b) {\n if (a === b) {\n return true\n }\n let _equal = true\n if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n _equal = _equal && utils.deepEqual(value, b[key])\n })\n if (!_equal) {\n return _equal\n }\n utils.forOwn(b, function (value, key) {\n _equal = _equal && utils.deepEqual(value, a[key])\n })\n } else if (utils.isArray(a) && utils.isArray(b)) {\n a.forEach(function (value, i) {\n _equal = _equal && utils.deepEqual(value, b[i])\n if (!_equal) {\n return false\n }\n })\n } else {\n return false\n }\n return _equal\n },\n\n /**\n * Proxy for `JSON.stringify`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = { name: 'John' }\n * let jsonVal = utils.toJson(a)\n * console.log(jsonVal) // '{\"name\" : \"John\"}'\n *\n * @method utils.toJson\n * @param {*} value Value to serialize to JSON.\n * @returns {string} JSON string.\n * @see utils.fromJson\n * @since 3.0.0\n */\n toJson: JSON.stringify,\n\n /**\n * Unset the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n *\n * utils.unset(john, age)\n * utils.unset(john, parent.age)\n *\n * console.log(john.age) // null\n * console.log(john.parent.age) // null\n *\n * @method utils.unset\n * @param {Object} object The object from which to delete the property.\n * @param {string} path The key or path to the property.\n * @see utils.set\n * @since 3.0.0\n */\n unset (object, path) {\n const parts = path.split('.')\n const last = parts.pop()\n\n while (path = parts.shift()) { // eslint-disable-line\n object = object[path]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n object[last] = undefined\n },\n\n}\n\nexport const safeSetProp = function (record, field, value) {\n if (record && record._set) {\n record._set(`props.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport const safeSetLink = function (record, field, value) {\n if (record && record._set) {\n record._set(`links.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport default utils\n","import utils from './utils'\n\n/**\n * A base class which gives instances private properties.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Settable.extend} for an example of using {@link Settable} as a\n * base class.\n *\n *```javascript\n * import {Settable} from 'js-data'\n * ```\n *\n * @class Settable\n * @returns {Settable} A new {@link Settable} instance.\n * @since 3.0.0\n */\nexport default function Settable () {\n const _props = {}\n Object.defineProperties(this, {\n /**\n * Get a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method Settable#_get\n * @param {string} key The property to retrieve.\n * @returns {*} The value of the property.\n * @since 3.0.0\n */\n _get: { value (key) { return utils.get(_props, key) } },\n\n /**\n * Set a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_set\n * @param {(string|Object)} key The key or path to the property. Can also\n * pass in an object of key/value pairs, which will all be set on the instance.\n * @param {*} [value] The value to set.\n * @since 3.0.0\n */\n _set: { value (key, value) { return utils.set(_props, key, value) } },\n\n /**\n * Unset a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_unset\n * @param {string} key The property to unset.\n * @since 3.0.0\n */\n _unset: { value (key) { return utils.unset(_props, key) } }\n })\n}\n\n/**\n * Create a subclass of this Settable:\n *\n * @example Settable.extend\n * // Normally you would do: import {Settable} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Settable} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSettableClass extends Settable {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSettable = new CustomSettableClass()\n * console.log(customSettable.foo())\n * console.log(CustomSettableClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSettableClass = Settable.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSettable = new OtherSettableClass()\n * console.log(otherSettable.foo())\n * console.log(OtherSettableClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSettableClass () {\n * Settable.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Settable.extend({\n * constructor: AnotherSettableClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSettable = new AnotherSettableClass()\n * console.log(anotherSettable.created_at)\n * console.log(anotherSettable.foo())\n * console.log(AnotherSettableClass.beep())\n *\n * @method Settable.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Settable class.\n * @since 3.0.0\n */\nSettable.extend = utils.extend\n","import utils from './utils'\nimport Settable from './Settable'\n\n/**\n * The base class from which all JSData components inherit some basic\n * functionality.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Component.extend} for an example of using {@link Component} as a\n * base class.\n *\n *```javascript\n * import {Component} from 'js-data'\n * ```\n *\n * @class Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @returns {Component} A new {@link Component} instance.\n * @since 3.0.0\n */\nfunction Component (opts) {\n Settable.call(this)\n opts || (opts = {})\n\n /**\n * Whether to enable debug-level logs for this component. Anything that\n * extends `Component` inherits this option and the corresponding logging\n * functionality.\n *\n * @example Component#debug\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const component = new Component()\n * component.log('debug', 'some message') // nothing gets logged\n * // Display debug logs:\n * component.debug = true\n * component.log('debug', 'other message') // this DOES get logged\n *\n * @default false\n * @name Component#debug\n * @since 3.0.0\n * @type {boolean}\n */\n this.debug = opts.hasOwnProperty('debug') ? !!opts.debug : false\n\n /**\n * Event listeners attached to this Component. __Do not modify.__ Use\n * {@link Component#on} and {@link Component#off} instead.\n *\n * @name Component#_listeners\n * @instance\n * @since 3.0.0\n * @type {Object}\n */\n Object.defineProperty(this, '_listeners', { value: {}, writable: true })\n}\n\nexport default Settable.extend({\n constructor: Component\n})\n\n/**\n * Create a subclass of this Component:\n *\n * @example Component.extend\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomComponentClass extends Component {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customComponent = new CustomComponentClass()\n * console.log(customComponent.foo())\n * console.log(CustomComponentClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherComponentClass = Component.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherComponent = new OtherComponentClass()\n * console.log(otherComponent.foo())\n * console.log(OtherComponentClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherComponentClass () {\n * Component.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Component.extend({\n * constructor: AnotherComponentClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherComponent = new AnotherComponentClass()\n * console.log(anotherComponent.created_at)\n * console.log(anotherComponent.foo())\n * console.log(AnotherComponentClass.beep())\n *\n * @method Component.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Component class.\n * @since 3.0.0\n */\nComponent.extend = utils.extend\n\n/**\n * Log the provided values at the \"debug\" level. Debug-level logs are only\n * logged if {@link Component#debug} is `true`.\n *\n * `.dbg(...)` is shorthand for `.log('debug', ...)`.\n *\n * @method Component#dbg\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\n/**\n * Log the provided values. By default sends values to `console[level]`.\n * Debug-level logs are only logged if {@link Component#debug} is `true`.\n *\n * Will attempt to use appropriate `console` methods if they are available.\n *\n * @method Component#log\n * @param {string} level Log level.\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\nutils.logify(Component.prototype)\n\n/**\n * Register a new event listener on this Component.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a DataStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * collection.on('add', (records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * post.on('change', (record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method Component#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n/**\n * Remove an event listener from this Component. If no listener is provided,\n * then all listeners for the specified event will be removed. If no event is\n * specified then all listeners for all events will be removed.\n *\n * @example\n * // Remove a particular listener for a particular event\n * collection.off('add', handler)\n *\n * @example\n * // Remove all listeners for a particular event\n * record.off('change')\n *\n * @example\n * // Remove all listeners to all events\n * store.off()\n *\n * @method Component#off\n * @param {string} [event] Name of event to unsubsribe to.\n * @param {Function} [listener] Listener to remove.\n * @since 3.0.0\n */\n/**\n * Trigger an event on this Component.\n *\n * @example Component#emit\n * // import {Collection, DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, DataStore} = JSData\n *\n * const collection = new Collection()\n * collection.on('foo', function (msg) {\n * console.log(msg)\n * })\n * collection.emit('foo', 'bar')\n *\n * const store = new DataStore()\n * store.on('beep', function (msg) {\n * console.log(msg)\n * })\n * store.emit('beep', 'boop')\n *\n * @method Component#emit\n * @param {string} event Name of event to emit.\n * @param {...*} [args] Arguments to pass to any listeners.\n * @since 3.0.0\n */\nutils.eventify(\n Component.prototype,\n function () {\n return this._listeners\n },\n function (value) {\n this._listeners = value\n }\n)\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Query'\nconst INDEX_ERR = 'Index inaccessible after first operation'\n\n// Reserved words used by JSData's Query Syntax\nconst reserved = {\n limit: '',\n offset: '',\n orderBy: '',\n skip: '',\n sort: '',\n where: ''\n}\n\n// Used by our JavaScript implementation of the LIKE operator\nconst escapeRegExp = /([.*+?^=!:${}()|[\\]\\/\\\\])/g\nconst percentRegExp = /%/g\nconst underscoreRegExp = /_/g\nconst escape = function (pattern) {\n return pattern.replace(escapeRegExp, '\\\\$1')\n}\n\n/**\n * A class used by the {@link Collection} class to build queries to be executed\n * against the collection's data. An instance of `Query` is returned by\n * {@link Collection#query}. Query instances are typically short-lived, and you\n * shouldn't have to create them yourself. Just use {@link Collection#query}.\n *\n * ```javascript\n * import {Query} from 'js-data'\n * ```\n *\n * @example\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const drafts = store.query('post').filter({ status: 'draft' }).limit(2).run()\n * console.log(drafts)\n *\n * @class Query\n * @extends Component\n * @param {Collection} collection The collection on which this query operates.\n * @since 3.0.0\n */\nfunction Query (collection) {\n utils.classCallCheck(this, Query)\n\n /**\n * The {@link Collection} on which this query operates.\n *\n * @name Query#collection\n * @since 3.0.0\n * @type {Collection}\n */\n this.collection = collection\n\n /**\n * The current data result of this query.\n *\n * @name Query#data\n * @since 3.0.0\n * @type {Array}\n */\n this.data = null\n}\n\nexport default Component.extend({\n constructor: Query,\n\n _applyWhereFromObject (where) {\n const fields = []\n const ops = []\n const predicates = []\n utils.forOwn(where, (clause, field) => {\n if (!utils.isObject(clause)) {\n clause = {\n '==': clause\n }\n }\n utils.forOwn(clause, (expr, op) => {\n fields.push(field)\n ops.push(op)\n predicates.push(expr)\n })\n })\n return {\n fields,\n ops,\n predicates\n }\n },\n\n _applyWhereFromArray (where) {\n const groups = []\n where.forEach((_where, i) => {\n if (utils.isString(_where)) {\n return\n }\n const prev = where[i - 1]\n const parser = utils.isArray(_where) ? this._applyWhereFromArray : this._applyWhereFromObject\n const group = parser.call(this, _where)\n if (prev === 'or') {\n group.isOr = true\n }\n groups.push(group)\n })\n groups.isArray = true\n return groups\n },\n\n _testObjectGroup (keep, first, group, item) {\n let i\n const fields = group.fields\n const ops = group.ops\n const predicates = group.predicates\n const len = ops.length\n for (i = 0; i < len; i++) {\n let op = ops[i]\n const isOr = op.charAt(0) === '|'\n op = isOr ? op.substr(1) : op\n const expr = this.evaluate(utils.get(item, fields[i]), op, predicates[i])\n if (expr !== undefined) {\n keep = first ? expr : (isOr ? keep || expr : keep && expr)\n }\n first = false\n }\n return { keep, first }\n },\n\n _testArrayGroup (keep, first, groups, item) {\n let i\n const len = groups.length\n for (i = 0; i < len; i++) {\n const group = groups[i]\n const parser = group.isArray ? this._testArrayGroup : this._testObjectGroup\n const result = parser.call(this, true, true, group, item)\n if (groups[i - 1]) {\n if (group.isOr) {\n keep = keep || result.keep\n } else {\n keep = keep && result.keep\n }\n } else {\n keep = result.keep\n }\n first = result.first\n }\n return { keep, first }\n },\n\n /**\n * Find all entities between two boundaries.\n *\n * @example Get the users ages 18 to 30.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between(18, 30, { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @example Same as above.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between([18], [30], { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @method Query#between\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#between`)(500, 'Cannot access index')\n }\n this.data = this.collection.getIndex(opts.index).between(leftKeys, rightKeys, opts)\n return this\n },\n\n /**\n * The comparison function used by the {@link Query} class.\n *\n * @method Query#compare\n * @param {Array} orderBy An orderBy clause used for sorting and sub-sorting.\n * @param {number} index The index of the current orderBy clause being used.\n * @param {*} a The first item in the comparison.\n * @param {*} b The second item in the comparison.\n * @returns {number} -1 if `b` should preceed `a`. 0 if `a` and `b` are equal.\n * 1 if `a` should preceed `b`.\n * @since 3.0.0\n */\n compare (orderBy, index, a, b) {\n const def = orderBy[index]\n let cA = utils.get(a, def[0])\n let cB = utils.get(b, def[0])\n if (cA && utils.isString(cA)) {\n cA = cA.toUpperCase()\n }\n if (cB && utils.isString(cB)) {\n cB = cB.toUpperCase()\n }\n if (a === undefined) {\n a = null\n }\n if (b === undefined) {\n b = null\n }\n if (def[1].toUpperCase() === 'DESC') {\n const temp = cB\n cB = cA\n cA = temp\n }\n if (cA < cB) {\n return -1\n } else if (cA > cB) {\n return 1\n } else {\n if (index < orderBy.length - 1) {\n return this.compare(orderBy, index + 1, a, b)\n } else {\n return 0\n }\n }\n },\n\n /**\n * Predicate evaluation function used by the {@link Query} class.\n *\n * @method Query#evaluate\n * @param {*} value The value to evaluate.\n * @param {string} op The operator to use in this evaluation.\n * @param {*} predicate The predicate to use in this evaluation.\n * @returns {boolean} Whether the value passed the evaluation or not.\n * @since 3.0.0\n */\n evaluate (value, op, predicate) {\n const ops = this.constructor.ops\n if (ops[op]) {\n return ops[op](value, predicate)\n }\n if (op.indexOf('like') === 0) {\n return this.like(predicate, op.substr(4)).exec(value) !== null\n } else if (op.indexOf('notLike') === 0) {\n return this.like(predicate, op.substr(7)).exec(value) === null\n }\n },\n\n /**\n * Find the record or records that match the provided query or are accepted by\n * the provided filter function.\n *\n * @example Get the draft posts by authors younger than 30\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * let results = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * }).run()\n * console.log(results)\n *\n * @example Use a custom filter function\n * const posts = query.filter(function (post) {\n * return post.isReady()\n * }).run()\n *\n * @method Query#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Function} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n filter (query, thisArg) {\n /**\n * Selection query as defined by JSData's [Query Syntax][querysyntax].\n *\n * [querysyntax]: http://www.js-data.io/v3.0/docs/query-syntax\n *\n * @example Empty \"findAll\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @example Empty \"filter\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = store.filter('post')\n * console.log(posts) // [...]\n *\n * @example Complex \"filter\" query\n * const PAGE_SIZE = 2\n * let currentPage = 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * // Retrieve a filtered page of blog posts\n * // Would typically replace filter with findAll\n * store.filter('post', {\n * where: {\n * status: {\n * // WHERE status = 'published'\n * '==': 'published'\n * },\n * author: {\n * // AND author IN ('bob', 'alice')\n * 'in': ['bob', 'alice'],\n * // OR author IN ('karen')\n * '|in': ['karen']\n * }\n * },\n * orderBy: [\n * // ORDER BY date_published DESC,\n * ['date_published', 'DESC'],\n * // ORDER BY title ASC\n * ['title', 'ASC']\n * ],\n * // LIMIT 2\n * limit: PAGE_SIZE,\n * // SKIP 4\n * offset: PAGE_SIZE * (currentPage - 1)\n * })\n *\n * @namespace query\n * @property {number} [limit] See {@link query.limit}.\n * @property {number} [offset] See {@link query.offset}.\n * @property {string|Array[]} [orderBy] See {@link query.orderBy}.\n * @property {number} [skip] Alias for {@link query.offset}.\n * @property {string|Array[]} [sort] Alias for {@link query.orderBy}.\n * @property {Object} [where] See {@link query.where}.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/query-syntax\",\"JSData's Query Syntax\"]\n */\n query || (query = {})\n this.getData()\n if (utils.isObject(query)) {\n let where = {}\n\n /**\n * Filtering criteria. Records that do not meet this criteria will be exluded\n * from the result.\n *\n * @example Return posts where author is at least 32 years old\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * where: {\n * age: {\n * '>=': 30\n * }\n * }\n * })\n * console.log(results)\n *\n * @name query.where\n * @type {Object}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isObject(query.where) || utils.isArray(query.where)) {\n where = query.where\n }\n utils.forOwn(query, function (value, key) {\n if (!(key in reserved) && !(key in where)) {\n where[key] = {\n '==': value\n }\n }\n })\n let groups\n\n // Apply filter for each field\n if (utils.isObject(where) && Object.keys(where).length !== 0) {\n groups = this._applyWhereFromArray([where])\n } else if (utils.isArray(where)) {\n groups = this._applyWhereFromArray(where)\n }\n\n if (groups) {\n this.data = this.data.filter((item, i) => this._testArrayGroup(true, true, groups, item).keep)\n }\n\n // Sort\n let orderBy = query.orderBy || query.sort\n\n if (utils.isString(orderBy)) {\n orderBy = [\n [orderBy, 'ASC']\n ]\n }\n if (!utils.isArray(orderBy)) {\n orderBy = null\n }\n\n /**\n * Determines how records should be ordered in the result.\n *\n * @example Order posts by `author` then by `id` descending \n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * orderBy:[['author','ASC'],['id','DESC']]\n * })\n * console.log(results)\n *\n * @name query.orderBy\n * @type {string|Array[]}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (orderBy) {\n let index = 0\n orderBy.forEach(function (def, i) {\n if (utils.isString(def)) {\n orderBy[i] = [def, 'ASC']\n }\n })\n this.data.sort((a, b) => this.compare(orderBy, index, a, b))\n }\n\n /**\n * Number of records to skip.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n *\n * @name query.offset\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.skip)) {\n this.skip(query.skip)\n } else if (utils.isNumber(query.offset)) {\n this.skip(query.offset)\n }\n\n /**\n * Maximum number of records to retrieve.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n * @name query.limit\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.limit)) {\n this.limit(query.limit)\n }\n } else if (utils.isFunction(query)) {\n this.data = this.data.filter(query, thisArg)\n }\n return this\n },\n\n /**\n * Iterate over all entities.\n *\n * @method Query#forEach\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n forEach (forEachFn, thisArg) {\n this.getData().forEach(forEachFn, thisArg)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided key.\n *\n * @example Get the entity whose primary key is 25.\n * const entities = query.get(25).run()\n *\n * @example Same as above.\n * const entities = query.get([25]).run()\n *\n * @example Get all users who are active and have the \"admin\" role.\n * const activeAdmins = query.get(['active', 'admin'], {\n * index: 'activityAndRoles'\n * }).run()\n *\n * @example Get all entities that match a certain weather condition.\n * const niceDays = query.get(['sunny', 'humid', 'calm'], {\n * index: 'weatherConditions'\n * }).run()\n *\n * @method Query#get\n * @param {Array} keyList Key(s) defining the entity to retrieve. If\n * `keyList` is not an array (i.e. for a single-value key), it will be\n * wrapped in an array.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.string] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n get (keyList, opts) {\n keyList || (keyList = [])\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#get`)(500, INDEX_ERR)\n }\n if (keyList && !utils.isArray(keyList)) {\n keyList = [keyList]\n }\n if (!keyList.length) {\n this.getData()\n return this\n }\n this.data = this.collection.getIndex(opts.index).get(keyList)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided keyLists.\n *\n * @example Get the posts where \"status\" is \"draft\" or \"inReview\".\n * const posts = query.getAll('draft', 'inReview', { index: 'status' }).run()\n *\n * @example Same as above.\n * const posts = query.getAll(['draft'], ['inReview'], { index: 'status' }).run()\n *\n * @method Query#getAll\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * entities matching each keyList will be retrieved. If no keyLists are\n * provided, all entities will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n getAll (...args) {\n let opts = {}\n if (this.data) {\n throw utils.err(`${DOMAIN}#getAll`)(500, INDEX_ERR)\n }\n if (!args.length || args.length === 1 && utils.isObject(args[0])) {\n this.getData()\n return this\n } else if (args.length && utils.isObject(args[args.length - 1])) {\n opts = args[args.length - 1]\n args.pop()\n }\n const collection = this.collection\n const index = collection.getIndex(opts.index)\n this.data = []\n args.forEach((keyList) => {\n this.data = this.data.concat(index.get(keyList))\n })\n return this\n },\n\n /**\n * Return the current data result of this query.\n *\n * @method Query#getData\n * @returns {Array} The data in this query.\n * @since 3.0.0\n */\n getData () {\n if (!this.data) {\n this.data = this.collection.index.getAll()\n }\n return this.data\n },\n\n /**\n * Implementation used by the `like` operator. Takes a pattern and flags and\n * returns a `RegExp` instance that can test strings.\n *\n * @method Query#like\n * @param {string} pattern Testing pattern.\n * @param {string} flags Flags for the regular expression.\n * @returns {RegExp} Regular expression for testing strings.\n * @since 3.0.0\n */\n like (pattern, flags) {\n return new RegExp(`^${(escape(pattern).replace(percentRegExp, '.*').replace(underscoreRegExp, '.'))}$`, flags)\n },\n\n /**\n * Limit the result.\n *\n * @example Get only the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').limit(2).run()\n * console.log(results)\n *\n * @method Query#limit\n * @param {number} num The maximum number of entities to keep in the result.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n limit (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#limit`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n this.data = data.slice(0, Math.min(data.length, num))\n return this\n },\n\n /**\n * Apply a mapping function to the result data.\n *\n * @example\n * // Return the age of all users\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const ages = store.query('user').map((user) => {\n * return user.age\n * }).run()\n * console.log(ages)\n *\n * @method Query#map\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n map (mapFn, thisArg) {\n this.data = this.getData().map(mapFn, thisArg)\n return this\n },\n\n /**\n * Return the result of calling the specified function on each item in this\n * collection's main index.\n *\n * @example\n * const stringAges = UserCollection.query().mapCall('toString').run()\n *\n * @method Query#mapCall\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n mapCall (funcName, ...args) {\n this.data = this.getData().map(function (item) {\n return item[funcName](...args)\n })\n return this\n },\n\n /**\n * Complete the execution of the query and return the resulting data.\n *\n * @method Query#run\n * @returns {Array} The result of executing this query.\n * @since 3.0.0\n */\n run () {\n const data = this.data\n this.data = null\n return data\n },\n\n /**\n * Skip a number of results.\n *\n * @example Get all but the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').skip(2).run()\n * console.log(results)\n *\n * @method Query#skip\n * @param {number} num The number of entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n skip (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#skip`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n if (num < data.length) {\n this.data = data.slice(num)\n } else {\n this.data = []\n }\n return this\n }\n}, {\n /**\n * The filtering operators supported by {@link Query#filter}, and which are\n * implemented by adapters (for the most part).\n *\n * @example Variant 1\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n *\n * @example Variant 2\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n * @example Variant 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * status: 'published'\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Variant 4\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Multiple operators\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const myPublishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * },\n * user_id: {\n * '==': currentUser.id\n * }\n * }\n * })\n *\n * console.log(myPublishedPosts)\n *\n * @name Query.ops\n * @property {Function} == Equality operator.\n * @property {Function} != Inequality operator.\n * @property {Function} > Greater than operator.\n * @property {Function} >= Greater than (inclusive) operator.\n * @property {Function} < Less than operator.\n * @property {Function} <= Less than (inclusive) operator.\n * @property {Function} isectEmpty Operator that asserts that the intersection\n * between two arrays is empty.\n * @property {Function} isectNotEmpty Operator that asserts that the\n * intersection between two arrays is __not__ empty.\n * @property {Function} in Operator that asserts whether a value is in an\n * array.\n * @property {Function} notIn Operator that asserts whether a value is __not__\n * in an array.\n * @property {Function} contains Operator that asserts whether an array\n * contains a value.\n * @property {Function} notContains Operator that asserts whether an array\n * does __not__ contain a value.\n * @since 3.0.0\n * @type {Object}\n */\n ops: {\n '=': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '==': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '===': function (value, predicate) {\n return value === predicate\n },\n '!=': function (value, predicate) {\n return value != predicate // eslint-disable-line\n },\n '!==': function (value, predicate) {\n return value !== predicate\n },\n '>': function (value, predicate) {\n return value > predicate\n },\n '>=': function (value, predicate) {\n return value >= predicate\n },\n '<': function (value, predicate) {\n return value < predicate\n },\n '<=': function (value, predicate) {\n return value <= predicate\n },\n 'isectEmpty': function (value, predicate) {\n return !utils.intersection((value || []), (predicate || [])).length\n },\n 'isectNotEmpty': function (value, predicate) {\n return utils.intersection((value || []), (predicate || [])).length\n },\n 'in': function (value, predicate) {\n return predicate.indexOf(value) !== -1\n },\n 'notIn': function (value, predicate) {\n return predicate.indexOf(value) === -1\n },\n 'contains': function (value, predicate) {\n return (value || []).indexOf(predicate) !== -1\n },\n 'notContains': function (value, predicate) {\n return (value || []).indexOf(predicate) === -1\n }\n }\n})\n\n/**\n * Create a subclass of this Query:\n * @example Query.extend\n * // Normally you would do: import {Query} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Query} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomQueryClass extends Query {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customQuery = new CustomQueryClass()\n * console.log(customQuery.foo())\n * console.log(CustomQueryClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherQueryClass = Query.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherQuery = new OtherQueryClass()\n * console.log(otherQuery.foo())\n * console.log(OtherQueryClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherQueryClass (collection) {\n * Query.call(this, collection)\n * this.created_at = new Date().getTime()\n * }\n * Query.extend({\n * constructor: AnotherQueryClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherQuery = new AnotherQueryClass()\n * console.log(anotherQuery.created_at)\n * console.log(anotherQuery.foo())\n * console.log(AnotherQueryClass.beep())\n *\n * @method Query.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Query class.\n * @since 3.0.0\n */\n","export function sort (a, b, hashCode) {\n // Short-circuit comparison if a and b are strictly equal\n // This is absolutely necessary for indexed objects that\n // don't have the idAttribute field\n if (a === b) {\n return 0\n }\n if (hashCode) {\n a = hashCode(a)\n b = hashCode(b)\n }\n if ((a === null && b === null) || (a === undefined && b === undefined)) {\n return -1\n }\n\n if (a === null || a === undefined) {\n return -1\n }\n\n if (b === null || b === undefined) {\n return 1\n }\n\n if (a < b) {\n return -1\n }\n\n if (a > b) {\n return 1\n }\n\n return 0\n}\n\nexport function insertAt (array, index, value) {\n array.splice(index, 0, value)\n return array\n}\n\nexport function removeAt (array, index) {\n array.splice(index, 1)\n return array\n}\n\nexport function binarySearch (array, value, field) {\n let lo = 0\n let hi = array.length\n let compared\n let mid\n\n while (lo < hi) {\n mid = ((lo + hi) / 2) | 0\n compared = sort(value, array[mid], field)\n if (compared === 0) {\n return {\n found: true,\n index: mid\n }\n } else if (compared < 0) {\n hi = mid\n } else {\n lo = mid + 1\n }\n }\n\n return {\n found: false,\n index: hi\n }\n}\n","// Copyright (c) 2015, InternalFX.\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose with or\n// without fee is hereby granted, provided that the above copyright notice and this permission\n// notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO\n// THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT\n// SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR\n// ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE\n// USE OR PERFORMANCE OF THIS SOFTWARE.\n\n// Modifications\n// Copyright 2015-2016 Jason Dobry\n//\n// Summary of modifications:\n// Reworked dependencies so as to re-use code already in js-data\n// Removed unused code\nimport utils from '../../src/utils'\nimport {binarySearch, insertAt, removeAt} from './_utils'\n\nexport default function Index (fieldList, opts) {\n utils.classCallCheck(this, Index)\n fieldList || (fieldList = [])\n\n if (!utils.isArray(fieldList)) {\n throw new Error('fieldList must be an array.')\n }\n\n opts || (opts = {})\n this.fieldList = fieldList\n this.fieldGetter = opts.fieldGetter\n this.hashCode = opts.hashCode\n this.isIndex = true\n this.keys = []\n this.values = []\n}\n\nutils.addHiddenPropsToTarget(Index.prototype, {\n 'set' (keyList, value) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n let dataLocation = binarySearch(this.values[pos.index], value, this.hashCode)\n if (!dataLocation.found) {\n insertAt(this.values[pos.index], dataLocation.index, value)\n }\n } else {\n insertAt(this.keys, pos.index, key)\n insertAt(this.values, pos.index, [value])\n }\n } else {\n if (pos.found) {\n this.values[pos.index].set(keyList, value)\n } else {\n insertAt(this.keys, pos.index, key)\n let newIndex = new Index([], { hashCode: this.hashCode })\n newIndex.set(keyList, value)\n insertAt(this.values, pos.index, newIndex)\n }\n }\n },\n\n 'get' (keyList) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n if (this.values[pos.index].isIndex) {\n return this.values[pos.index].getAll()\n } else {\n return this.values[pos.index].slice()\n }\n } else {\n return []\n }\n } else {\n if (pos.found) {\n return this.values[pos.index].get(keyList)\n } else {\n return []\n }\n }\n },\n\n getAll (opts) {\n opts || (opts = {})\n let results = []\n const values = this.values\n if (opts.order === 'desc') {\n for (let i = values.length - 1; i >= 0; i--) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n } else {\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n }\n return results\n },\n\n visitAll (cb, thisArg) {\n this.values.forEach(function (value) {\n if (value.isIndex) {\n value.visitAll(cb, thisArg)\n } else {\n value.forEach(cb, thisArg)\n }\n })\n },\n\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (!utils.isArray(leftKeys)) {\n leftKeys = [leftKeys]\n }\n if (!utils.isArray(rightKeys)) {\n rightKeys = [rightKeys]\n }\n utils.fillIn(opts, {\n leftInclusive: true,\n rightInclusive: false,\n limit: undefined,\n offset: 0\n })\n\n let results = this._between(leftKeys, rightKeys, opts)\n\n if (opts.limit) {\n return results.slice(opts.offset, opts.limit + opts.offset)\n } else {\n return results.slice(opts.offset)\n }\n },\n\n _between (leftKeys, rightKeys, opts) {\n let results = []\n\n let leftKey = leftKeys.shift()\n let rightKey = rightKeys.shift()\n\n let pos\n\n if (leftKey !== undefined) {\n pos = binarySearch(this.keys, leftKey)\n } else {\n pos = {\n found: false,\n index: 0\n }\n }\n\n if (leftKeys.length === 0) {\n if (pos.found && opts.leftInclusive === false) {\n pos.index += 1\n }\n\n for (let i = pos.index; i < this.keys.length; i += 1) {\n if (rightKey !== undefined) {\n if (opts.rightInclusive) {\n if (this.keys[i] > rightKey) { break }\n } else {\n if (this.keys[i] >= rightKey) { break }\n }\n }\n\n if (this.values[i].isIndex) {\n results = results.concat(this.values[i].getAll())\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n } else {\n for (let i = pos.index; i < this.keys.length; i += 1) {\n let currKey = this.keys[i]\n if (currKey > rightKey) { break }\n\n if (this.values[i].isIndex) {\n if (currKey === leftKey) {\n results = results.concat(this.values[i]._between(utils.copy(leftKeys), rightKeys.map(function () { return undefined }), opts))\n } else if (currKey === rightKey) {\n results = results.concat(this.values[i]._between(leftKeys.map(function () { return undefined }), utils.copy(rightKeys), opts))\n } else {\n results = results.concat(this.values[i].getAll())\n }\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n }\n\n if (opts.limit) {\n return results.slice(0, opts.limit + opts.offset)\n } else {\n return results\n }\n },\n\n peek () {\n if (this.values.length) {\n if (this.values[0].isIndex) {\n return this.values[0].peek()\n } else {\n return this.values[0]\n }\n }\n return []\n },\n\n clear () {\n this.keys = []\n this.values = []\n },\n\n insertRecord (data) {\n let keyList = this.fieldList.map(function (field) {\n if (utils.isFunction(field)) {\n return field(data) || undefined\n } else {\n return data[field] || undefined\n }\n })\n this.set(keyList, data)\n },\n\n removeRecord (data) {\n let removed\n const isUnique = this.hashCode(data) !== undefined\n this.values.forEach((value, i) => {\n if (value.isIndex) {\n if (value.removeRecord(data)) {\n if (value.keys.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n } else {\n let dataLocation = {}\n if (this.keys[i] === undefined || !isUnique) {\n for (let j = value.length - 1; j >= 0; j--) {\n if (value[j] === data) {\n dataLocation = {\n found: true,\n index: j\n }\n break\n }\n }\n } else if (isUnique) {\n dataLocation = binarySearch(value, data, this.hashCode)\n }\n if (dataLocation.found) {\n removeAt(value, dataLocation.index)\n if (value.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n }\n })\n return removed ? data : undefined\n },\n\n updateRecord (data) {\n const removed = this.removeRecord(data)\n if (removed !== undefined) {\n this.insertRecord(data)\n }\n }\n})\n","import utils from './utils'\nimport Component from './Component'\nimport Query from './Query'\nimport Index from '../lib/mindex/index'\n\nconst DOMAIN = 'Collection'\n\nconst COLLECTION_DEFAULTS = {\n /**\n * Whether to call {@link Record#commit} on records that are added to the\n * collection and already exist in the collection.\n *\n * @name Collection#commitOnMerge\n * @type {boolean}\n * @default true\n */\n commitOnMerge: true,\n\n /**\n * Field to be used as the unique identifier for records in this collection.\n * Defaults to `\"id\"` unless {@link Collection#mapper} is set, in which case\n * this will default to {@link Mapper#idAttribute}.\n *\n * @name Collection#idAttribute\n * @type {string}\n * @default \"id\"\n */\n idAttribute: 'id',\n\n /**\n * What to do when inserting a record into this Collection that shares a\n * primary key with a record already in this Collection.\n *\n * Possible values:\n * merge\n * replace\n *\n * Merge:\n *\n * Recursively shallow copy properties from the new record onto the existing\n * record.\n *\n * Replace:\n *\n * Shallow copy top-level properties from the new record onto the existing\n * record. Any top-level own properties of the existing record that are _not_\n * on the new record will be removed.\n *\n * @name Collection#onConflict\n * @type {string}\n * @default \"merge\"\n */\n onConflict: 'merge'\n}\n\n/**\n * An ordered set of {@link Record} instances.\n *\n * @example Collection#constructor\n * // import {Collection, Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const user1 = new Record({ id: 1 })\n * const user2 = new Record({ id: 2 })\n * const UserCollection = new Collection([user1, user2])\n * console.log(UserCollection.get(1) === user1)\n *\n * @class Collection\n * @extends Component\n * @param {Array} [records] Initial set of records to insert into the\n * collection.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.commitOnMerge] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.idAttribute] See {@link Collection#idAttribute}.\n * @param {string} [opts.onConflict=\"merge\"] See {@link Collection#onConflict}.\n * @param {string} [opts.mapper] See {@link Collection#mapper}.\n * @since 3.0.0\n */\nfunction Collection (records, opts) {\n utils.classCallCheck(this, Collection)\n Component.call(this, opts)\n\n if (records && !utils.isArray(records)) {\n opts = records\n records = []\n }\n if (utils.isString(opts)) {\n opts = { idAttribute: opts }\n }\n\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * Default Mapper for this collection. Optional. If a Mapper is provided, then\n * the collection will use the {@link Mapper#idAttribute} setting, and will\n * wrap records in {@link Mapper#recordClass}.\n *\n * @example Collection#mapper\n * // Normally you would do: import {Collection, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const myMapper = new MyMapperClass({ name: 'myMapper' })\n * const collection = new Collection(null, { mapper: myMapper })\n *\n * @name Collection#mapper\n * @type {Mapper}\n * @default null\n * @since 3.0.0\n */\n mapper: {\n value: undefined,\n writable: true\n },\n // Query class used by this collection\n queryClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(COLLECTION_DEFAULTS))\n\n if (!this.queryClass) {\n this.queryClass = Query\n }\n\n const idAttribute = this.recordId()\n\n Object.defineProperties(this, {\n /**\n * The main index, which uses @{link Collection#recordId} as the key.\n *\n * @name Collection#index\n * @type {Index}\n */\n index: {\n value: new Index([idAttribute], {\n hashCode (obj) {\n return utils.get(obj, idAttribute)\n }\n })\n },\n\n /**\n * Object that holds the secondary indexes of this collection.\n *\n * @name Collection#indexes\n * @type {Object.}\n */\n indexes: {\n value: {}\n }\n })\n\n // Insert initial data into the collection\n if (utils.isObject(records) || (utils.isArray(records) && records.length)) {\n this.add(records)\n }\n}\n\nexport default Component.extend({\n constructor: Collection,\n\n /**\n * Used to bind to events emitted by records in this Collection.\n *\n * @method Collection#_onRecordEvent\n * @since 3.0.0\n * @private\n * @param {...*} [arg] Args passed to {@link Collection#emit}.\n */\n _onRecordEvent (...args) {\n this.emit(...args)\n },\n\n /**\n * Insert the provided record or records.\n *\n * If a record is already in the collection then the provided record will\n * either merge with or replace the existing record based on the value of the\n * `onConflict` option.\n *\n * The collection's secondary indexes will be updated as each record is\n * visited.\n *\n * @method Collection#add\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} data The record or records to insert.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.commitOnMerge=true] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.onConflict] See {@link Collection#onConflict}.\n * @returns {(Object|Object[]|Record|Record[])} The added record or records.\n */\n add (records, opts) {\n // Default values for arguments\n opts || (opts = {})\n\n // Fill in \"opts\" with the Collection's configuration\n utils._(opts, this)\n records = this.beforeAdd(records, opts) || records\n\n // Track whether just one record or an array of records is being inserted\n let singular = false\n const idAttribute = this.recordId()\n if (!utils.isArray(records)) {\n if (utils.isObject(records)) {\n records = [records]\n singular = true\n } else {\n throw utils.err(`${DOMAIN}#add`, 'records')(400, 'object or array', records)\n }\n }\n\n // Map the provided records to existing records.\n // New records will be inserted. If any records map to existing records,\n // they will be merged into the existing records according to the onConflict\n // option.\n records = records.map((record) => {\n let id = this.recordId(record)\n // Grab existing record if there is one\n const existing = id === undefined ? id : this.get(id)\n // If the currently visited record is just a reference to an existing\n // record, then there is nothing to be done. Exit early.\n if (record === existing) {\n return existing\n }\n\n if (existing) {\n // Here, the currently visited record corresponds to a record already\n // in the collection, so we need to merge them\n const onConflict = opts.onConflict || this.onConflict\n if (onConflict === 'merge') {\n utils.deepMixIn(existing, record)\n } else if (onConflict === 'replace') {\n utils.forOwn(existing, (value, key) => {\n if (key !== idAttribute && record[key] === undefined) {\n existing[key] = undefined\n }\n })\n existing.set(record)\n } else {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(400, 'one of (merge, replace)', onConflict, true)\n }\n record = existing\n if (opts.commitOnMerge && utils.isFunction(record.commit)) {\n record.commit()\n }\n // Update all indexes in the collection\n this.updateIndexes(record)\n } else {\n // Here, the currently visted record does not correspond to any record\n // in the collection, so (optionally) instantiate this record and insert\n // it into the collection\n record = this.mapper ? this.mapper.createRecord(record, opts) : record\n this.index.insertRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.insertRecord(record)\n })\n if (record && utils.isFunction(record.on)) {\n record.on('all', this._onRecordEvent, this)\n }\n }\n return record\n })\n // Finally, return the inserted data\n const result = singular ? records[0] : records\n this.emit('add', result)\n return this.afterAdd(records, opts, result) || result\n },\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then {@link Collection#add} will return that same value.\n *\n * @method Collection#method\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} result The record or records\n * that were added to this Collection by {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n afterAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}. If this method returns\n * a value then {@link Collection#remove} will return that same value.\n *\n * @method Collection#afterRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n * @param {Object} record The result that will be returned by {@link Collection#remove}.\n */\n afterRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}. If this method\n * returns a value then {@link Collection#removeAll} will return that same\n * value.\n *\n * @method Collection#afterRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n * @param {Object} records The result that will be returned by {@link Collection#removeAll}.\n */\n afterRemoveAll () {},\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then the `records` argument in {@link Collection#add} will be\n * re-assigned to the returned value.\n *\n * @method Collection#beforeAdd\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} records The `records` argument passed to {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n beforeAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}.\n *\n * @method Collection#beforeRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n */\n beforeRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}.\n *\n * @method Collection#beforeRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n */\n beforeRemoveAll () {},\n\n /**\n * Find all records between two boundaries.\n *\n * Shortcut for `collection.query().between(18, 30, { index: 'age' }).run()`\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = collection.between(18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = collection.between([18], [30], { index: 'age' })\n *\n * @method Collection#between\n * @since 3.0.0\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting records to skip.\n * @returns {Object[]|Record[]} The result.\n */\n between (leftKeys, rightKeys, opts) {\n return this.query().between(leftKeys, rightKeys, opts).run()\n },\n\n /**\n * Create a new secondary index on the contents of the collection.\n *\n * @example\n * // Index users by age\n * collection.createIndex('age')\n *\n * @example\n * // Index users by status and role\n * collection.createIndex('statusAndRole', ['status', 'role'])\n *\n * @method Collection#createIndex\n * @since 3.0.0\n * @param {string} name The name of the new secondary index.\n * @param {string[]} [fieldList] Array of field names to use as the key or\n * compound key of the new secondary index. If no fieldList is provided, then\n * the name will also be the field that is used to index the collection.\n */\n createIndex (name, fieldList, opts) {\n if (utils.isString(name) && fieldList === undefined) {\n fieldList = [name]\n }\n opts || (opts = {})\n opts.hashCode || (opts.hashCode = (obj) => this.recordId(obj))\n const index = this.indexes[name] = new Index(fieldList, opts)\n this.index.visitAll(index.insertRecord, index)\n },\n\n /**\n * Find the record or records that match the provided query or pass the\n * provided filter function.\n *\n * Shortcut for `collection.query().filter(queryOrFn[, thisArg]).run()`\n *\n * @example Collection#filter\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const collection = new Collection([\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = collection.filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = collection.filter(function (post) {\n * return post.id % 2 === 0\n * })\n *\n * @method Collection#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Object} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Array} The result.\n * @see query\n * @since 3.0.0\n */\n filter (query, thisArg) {\n return this.query().filter(query, thisArg).run()\n },\n\n /**\n * Iterate over all records.\n *\n * @example\n * collection.forEach(function (record) {\n * // do something\n * })\n *\n * @method Collection#forEach\n * @since 3.0.0\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Array} The result.\n */\n forEach (cb, thisArg) {\n this.index.visitAll(cb, thisArg)\n },\n\n /**\n * Get the record with the given id.\n *\n * @method Collection#get\n * @since 3.0.0\n * @param {(string|number)} id The primary key of the record to get.\n * @returns {(Object|Record)} The record with the given id.\n */\n get (id) {\n const instances = this.query().get(id).run()\n return instances.length ? instances[0] : undefined\n },\n\n /**\n * Find the record or records that match the provided keyLists.\n *\n * Shortcut for `collection.query().getAll(keyList1, keyList2, ...).run()`\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = collection.getAll('draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = collection.getAll(['draft'], ['inReview'], { index: 'status' })\n *\n * @method Collection#getAll\n * @since 3.0.0\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * records matching each keyList will be retrieved. If no keyLists are\n * provided, all records will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Array} The result.\n */\n getAll (...args) {\n return this.query().getAll(...args).run()\n },\n\n /**\n * Return the index with the given name. If no name is provided, return the\n * main index. Throws an error if the specified index does not exist.\n *\n * @method Collection#getIndex\n * @since 3.0.0\n * @param {string} [name] The name of the index to retrieve.\n */\n getIndex (name) {\n const index = name ? this.indexes[name] : this.index\n if (!index) {\n throw utils.err(`${DOMAIN}#getIndex`, name)(404, 'index')\n }\n return index\n },\n\n /**\n * Limit the result.\n *\n * Shortcut for `collection.query().limit(maximumNumber).run()`\n *\n * @example\n * const posts = collection.limit(10)\n *\n * @method Collection#limit\n * @since 3.0.0\n * @param {number} num The maximum number of records to keep in the result.\n * @returns {Array} The result.\n */\n limit (num) {\n return this.query().limit(num).run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map(function (user) {\n * return user.name\n * })\n *\n * @method Collection#map\n * @since 3.0.0\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Array} The result of the mapping.\n */\n map (cb, thisArg) {\n const data = []\n this.index.visitAll(function (value) {\n data.push(cb.call(thisArg, value))\n })\n return data\n },\n\n /**\n * Return the result of calling the specified function on each record in this\n * collection's main index.\n *\n * @method Collection#mapCall\n * @since 3.0.0\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Array} The result.\n */\n mapCall (funcName, ...args) {\n const data = []\n this.index.visitAll(function (record) {\n data.push(record[funcName](...args))\n })\n return data\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#prune\n * @param {Object} [opts] Configuration options, passed to {@link Collection#removeAll}.\n * @since 3.0.0\n * @returns {Array} The removed records, if any.\n */\n prune (opts) {\n return this.removeAll(this.unsaved(), opts)\n },\n\n /**\n * Create a new query to be executed against the contents of the collection.\n * The result will be all or a subset of the contents of the collection.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * collection.query()\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method Collection#query\n * @since 3.0.0\n * @returns {Query} New query object.\n */\n query () {\n const Ctor = this.queryClass\n return new Ctor(this)\n },\n\n /**\n * Return the primary key of the given, or if no record is provided, return the\n * name of the field that holds the primary key of records in this Collection.\n *\n * @method Collection#recordId\n * @since 3.0.0\n * @param {(Object|Record)} [record] The record whose primary key is to be\n * returned.\n * @returns {(string|number)} Primary key or name of field that holds primary\n * key.\n */\n recordId (record) {\n if (record) {\n return utils.get(record, this.recordId())\n }\n return this.mapper ? this.mapper.idAttribute : this.idAttribute\n },\n\n /**\n * Reduce the data in the collection to a single value and return the result.\n *\n * @example\n * const totalVotes = collection.reduce(function (prev, record) {\n * return prev + record.upVotes + record.downVotes\n * }, 0)\n *\n * @method Collection#reduce\n * @since 3.0.0\n * @param {Function} cb Reduction callback.\n * @param {*} initialValue Initial value of the reduction.\n * @returns {*} The result.\n */\n reduce (cb, initialValue) {\n const data = this.getAll()\n return data.reduce(cb, initialValue)\n },\n\n /**\n * Remove the record with the given id from this Collection.\n *\n * @method Collection#remove\n * @since 3.0.0\n * @param {(string|number|object|Record)} idOrRecord The primary key of the\n * record to be removed, or a reference to the record that is to be removed.\n * @param {Object} [opts] Configuration options.\n * @returns {Object|Record} The removed record, if any.\n */\n remove (idOrRecord, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemove(idOrRecord, opts)\n let record = utils.isSorN(idOrRecord) ? this.get(idOrRecord) : idOrRecord\n\n // The record is in the collection, remove it\n if (utils.isObject(record)) {\n record = this.index.removeRecord(record)\n if (record) {\n utils.forOwn(this.indexes, function (index, name) {\n index.removeRecord(record)\n })\n if (utils.isFunction(record.off)) {\n record.off('all', this._onRecordEvent, this)\n if (!opts.silent) {\n this.emit('remove', record)\n }\n }\n }\n }\n return this.afterRemove(idOrRecord, opts, record) || record\n },\n\n /**\n * Remove from this collection the given records or the records selected by\n * the given \"query\".\n *\n * @method Collection#removeAll\n * @since 3.0.0\n * @param {Object|Object[]|Record[]} [queryOrRecords={}] Records to be removed or selection query. See {@link query}.\n * @param {Object} [queryOrRecords.where] See {@link query.where}.\n * @param {number} [queryOrRecords.offset] See {@link query.offset}.\n * @param {number} [queryOrRecords.limit] See {@link query.limit}.\n * @param {string|Array[]} [queryOrRecords.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object[]|Record[])} The removed records, if any.\n */\n removeAll (queryOrRecords, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemoveAll(queryOrRecords, opts)\n let records = utils.isArray(queryOrRecords) ? queryOrRecords.slice() : this.filter(queryOrRecords)\n\n // Remove each selected record from the collection\n const optsCopy = utils.plainCopy(opts)\n optsCopy.silent = true\n records = records\n .map((record) => this.remove(record, optsCopy))\n .filter((record) => record)\n if (!opts.silent) {\n this.emit('remove', records)\n }\n return this.afterRemoveAll(queryOrRecords, opts, records) || records\n },\n\n /**\n * Skip a number of results.\n *\n * Shortcut for `collection.query().skip(numberToSkip).run()`\n *\n * @example\n * const posts = collection.skip(10)\n *\n * @method Collection#skip\n * @since 3.0.0\n * @param {number} num The number of records to skip.\n * @returns {Array} The result.\n */\n skip (num) {\n return this.query().skip(num).run()\n },\n\n /**\n * Return the plain JSON representation of all items in this collection.\n * Assumes records in this collection have a toJSON method.\n *\n * @method Collection#toJSON\n * @since 3.0.0\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation.\n * @returns {Array} The records.\n */\n toJSON (opts) {\n return this.mapCall('toJSON', opts)\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#unsaved\n * @since 3.0.0\n * @returns {Array} The unsaved records, if any.\n */\n unsaved (opts) {\n return this.index.get()\n },\n\n /**\n * Update a record's position in a single index of this collection. See\n * {@link Collection#updateIndexes} to update a record's position in all\n * indexes at once.\n *\n * @method Collection#updateIndex\n * @since 3.0.0\n * @param {Object} record The record to update.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] The index in which to update the record's\n * position. If you don't specify an index then the record will be updated\n * in the main index.\n */\n updateIndex (record, opts) {\n opts || (opts = {})\n this.getIndex(opts.index).updateRecord(record)\n },\n\n /**\n * Updates all indexes in this collection for the provided record. Has no\n * effect if the record is not in the collection.\n *\n * @method Collection#updateIndexes\n * @since 3.0.0\n * @param {Object} record TODO\n */\n updateIndexes (record) {\n this.index.updateRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.updateRecord(record)\n })\n }\n})\n\n/**\n * Fired when a record changes. Only works for records that have tracked changes.\n * See {@link Collection~changeListener} on how to listen for this event.\n *\n * @event Collection#change\n * @see Collection~changeListener\n */\n\n/**\n * Callback signature for the {@link Collection#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * collection.on('change', onChange)\n *\n * @callback Collection~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Collection#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the Collection. See\n * {@link Collection~addListener} on how to listen for this event.\n *\n * @event Collection#add\n * @see Collection~addListener\n * @see Collection#event:add\n * @see Collection#add\n */\n\n/**\n * Callback signature for the {@link Collection#event:add} event.\n *\n * @example\n * function onAdd (recordOrRecords) {\n * // do something\n * }\n * collection.on('add', onAdd)\n *\n * @callback Collection~addListener\n * @param {Record|Record[]} The Record or Records that were added.\n * @see Collection#event:add\n * @see Collection#add\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the Collection. See\n * {@link Collection~removeListener} for how to listen for this event.\n *\n * @event Collection#remove\n * @see Collection~removeListener\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n */\n\n/**\n * Callback signature for the {@link Collection#event:remove} event.\n *\n * @example\n * function onRemove (recordsOrRecords) {\n * // do something\n * }\n * collection.on('remove', onRemove)\n *\n * @callback Collection~removeListener\n * @param {Record|Record[]} Record or Records that were removed.\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Collection:\n * @example Collection.extend\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomCollectionClass extends Collection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customCollection = new CustomCollectionClass()\n * console.log(customCollection.foo())\n * console.log(CustomCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherCollectionClass = Collection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherCollection = new OtherCollectionClass()\n * console.log(otherCollection.foo())\n * console.log(OtherCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherCollectionClass () {\n * Collection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Collection.extend({\n * constructor: AnotherCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherCollection = new AnotherCollectionClass()\n * console.log(anotherCollection.created_at)\n * console.log(anotherCollection.foo())\n * console.log(AnotherCollectionClass.beep())\n *\n * @method Collection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Collection class.\n * @since 3.0.0\n */\n","import utils from './utils'\n\n// TODO: remove this when the rest of the project is cleaned\nexport const belongsToType = 'belongsTo'\nexport const hasManyType = 'hasMany'\nexport const hasOneType = 'hasOne'\n\nconst DOMAIN = 'Relation'\n\nexport function Relation (relatedMapper, options = {}) {\n utils.classCallCheck(this, Relation)\n\n options.type = this.constructor.TYPE_NAME\n this.validateOptions(relatedMapper, options)\n\n if (typeof relatedMapper === 'object') {\n Object.defineProperty(this, 'relatedMapper', { value: relatedMapper })\n }\n\n Object.defineProperty(this, 'inverse', { writable: true })\n utils.fillIn(this, options)\n}\n\nRelation.extend = utils.extend\n\nutils.addHiddenPropsToTarget(Relation.prototype, {\n get canAutoAddLinks () {\n return this.add === undefined || !!this.add\n },\n\n get relatedCollection () {\n return this.mapper.datastore.getCollection(this.relation)\n },\n\n validateOptions (related, opts) {\n const DOMAIN_ERR = `new ${DOMAIN}`\n\n const localField = opts.localField\n if (!localField) {\n throw utils.err(DOMAIN_ERR, 'opts.localField')(400, 'string', localField)\n }\n\n const foreignKey = opts.foreignKey = opts.foreignKey || opts.localKey\n if (!foreignKey && (opts.type === belongsToType || opts.type === hasOneType)) {\n throw utils.err(DOMAIN_ERR, 'opts.foreignKey')(400, 'string', foreignKey)\n }\n\n if (utils.isString(related)) {\n opts.relation = related\n if (!utils.isFunction(opts.getRelation)) {\n throw utils.err(DOMAIN_ERR, 'opts.getRelation')(400, 'function', opts.getRelation)\n }\n } else if (related) {\n opts.relation = related.name\n } else {\n throw utils.err(DOMAIN_ERR, 'related')(400, 'Mapper or string', related)\n }\n },\n\n assignTo (mapper) {\n this.name = mapper.name\n Object.defineProperty(this, 'mapper', { value: mapper })\n\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n mapper.relationFields || Object.defineProperty(mapper, 'relationFields', { value: [] })\n mapper.relationList.push(this)\n mapper.relationFields.push(this.localField)\n },\n\n canFindLinkFor () {\n return !!(this.foreignKey || this.localKey)\n },\n\n getRelation () {\n return this.relatedMapper\n },\n\n getForeignKey (record) {\n return utils.get(record, this.mapper.idAttribute)\n },\n\n setForeignKey (record, relatedRecord) {\n if (!record || !relatedRecord) {\n return\n }\n\n this._setForeignKey(record, relatedRecord)\n },\n\n _setForeignKey (record, relatedRecords) {\n const idAttribute = this.mapper.idAttribute\n\n if (!utils.isArray(relatedRecords)) {\n relatedRecords = [relatedRecords]\n }\n\n relatedRecords.forEach((relatedRecord) => {\n utils.set(relatedRecord, this.foreignKey, utils.get(record, idAttribute))\n })\n },\n\n getLocalField (record) {\n return utils.get(record, this.localField)\n },\n\n setLocalField (record, relatedData) {\n return utils.set(record, this.localField, relatedData)\n },\n\n getInverse (mapper) {\n if (!this.inverse) {\n this.findInverseRelation(mapper)\n }\n\n return this.inverse\n },\n\n findInverseRelation (mapper) {\n this.getRelation().relationList.forEach((def) => {\n if (def.getRelation() === mapper && this.isInversedTo(def)) {\n this.inverse = def\n return true\n }\n })\n },\n\n isInversedTo (def) {\n return !def.foreignKey || def.foreignKey === this.foreignKey\n },\n\n addLinkedRecords (records) {\n const datastore = this.mapper.datastore\n\n records.forEach((record) => {\n let relatedData = this.getLocalField(record)\n\n if (utils.isFunction(this.add)) {\n relatedData = this.add(datastore, this, record)\n } else if (relatedData) {\n relatedData = this.linkRecord(record, relatedData)\n }\n\n const isEmptyLinks = !relatedData || utils.isArray(relatedData) && !relatedData.length\n\n if (isEmptyLinks && this.canFindLinkFor(record)) {\n relatedData = this.findExistingLinksFor(record)\n }\n\n if (relatedData) {\n this.setLocalField(record, relatedData)\n }\n })\n },\n\n removeLinkedRecords (relatedMapper, records) {\n const localField = this.localField\n records.forEach((record) => {\n utils.set(record, localField, undefined)\n })\n },\n\n linkRecord (record, relatedRecord) {\n const relatedId = utils.get(relatedRecord, this.mapper.idAttribute)\n\n if (relatedId === undefined) {\n const unsaved = this.relatedCollection.unsaved()\n if (unsaved.indexOf(relatedRecord) === -1) {\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n } else {\n if (relatedRecord !== this.relatedCollection.get(relatedId)) {\n this.setForeignKey(record, relatedRecord)\n\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n }\n\n return relatedRecord\n },\n\n // e.g. user hasMany post via \"foreignKey\", so find all posts of user\n findExistingLinksByForeignKey (id) {\n if (id === undefined || id === null) {\n return\n }\n return this.relatedCollection.filter({\n [this.foreignKey]: id\n })\n }\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const BelongsToRelation = Relation.extend({\n getForeignKey (record) {\n return utils.get(record, this.foreignKey)\n },\n\n _setForeignKey (record, relatedRecord) {\n utils.set(record, this.foreignKey, utils.get(relatedRecord, this.getRelation().idAttribute))\n },\n\n findExistingLinksFor (record) {\n // console.log('\\tBelongsTo#findExistingLinksFor', record)\n if (!record) {\n return\n }\n const relatedId = utils.get(record, this.foreignKey)\n if (relatedId !== undefined && relatedId !== null) {\n return this.relatedCollection.get(relatedId)\n }\n }\n}, {\n TYPE_NAME: 'belongsTo'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasManyRelation = Relation.extend({\n validateOptions (related, opts) {\n Relation.prototype.validateOptions.call(this, related, opts)\n\n const { localKeys, foreignKeys, foreignKey } = opts\n\n if (!foreignKey && !localKeys && !foreignKeys) {\n throw utils.err('new Relation', 'opts.')(400, 'string', foreignKey)\n }\n },\n\n canFindLinkFor (record) {\n const hasForeignKeys = this.foreignKey || this.foreignKeys\n return !!(hasForeignKeys || (this.localKeys && utils.get(record, this.localKeys)))\n },\n\n linkRecord (record, relatedRecords) {\n const relatedCollection = this.relatedCollection\n const canAutoAddLinks = this.canAutoAddLinks\n const foreignKey = this.foreignKey\n const unsaved = this.relatedCollection.unsaved()\n\n return relatedRecords.map((relatedRecord) => {\n const relatedId = relatedCollection.recordId(relatedRecord)\n\n if ((relatedId === undefined && unsaved.indexOf(relatedRecord) === -1) || relatedRecord !== relatedCollection.get(relatedId)) {\n if (foreignKey) {\n // TODO: slow, could be optimized? But user loses hook\n this.setForeignKey(record, relatedRecord)\n }\n if (canAutoAddLinks) {\n relatedRecord = relatedCollection.add(relatedRecord)\n }\n }\n\n return relatedRecord\n })\n },\n\n findExistingLinksFor (record) {\n const id = utils.get(record, this.mapper.idAttribute)\n const ids = this.localKeys ? utils.get(record, this.localKeys) : null\n let records\n\n if (id !== undefined && this.foreignKey) {\n records = this.findExistingLinksByForeignKey(id)\n } else if (this.localKeys && ids) {\n records = this.findExistingLinksByLocalKeys(ids)\n } else if (id !== undefined && this.foreignKeys) {\n records = this.findExistingLinksByForeignKeys(id)\n }\n\n if (records && records.length) {\n return records\n }\n },\n\n // e.g. user hasMany group via \"foreignKeys\", so find all users of a group\n findExistingLinksByLocalKeys (ids) {\n return this.relatedCollection.filter({\n where: {\n [this.mapper.idAttribute]: {\n 'in': ids\n }\n }\n })\n },\n\n // e.g. group hasMany user via \"localKeys\", so find all groups that own a user\n findExistingLinksByForeignKeys (id) {\n return this.relatedCollection.filter({\n where: {\n [this.foreignKeys]: {\n 'contains': id\n }\n }\n })\n }\n}, {\n TYPE_NAME: 'hasMany'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasOneRelation = Relation.extend({\n findExistingLinksFor (relatedMapper, record) {\n const recordId = utils.get(record, relatedMapper.idAttribute)\n const records = this.findExistingLinksByForeignKey(recordId)\n\n if (records && records.length) {\n return records[0]\n }\n }\n}, {\n TYPE_NAME: 'hasOne'\n})\n","import { Relation } from './Relation'\nimport { BelongsToRelation } from './Relation/BelongsTo'\nimport { HasManyRelation } from './Relation/HasMany'\nimport { HasOneRelation } from './Relation/HasOne'\n\n[BelongsToRelation, HasManyRelation, HasOneRelation].forEach(function (RelationType) {\n Relation[RelationType.TYPE_NAME] = function (related, options) {\n return new RelationType(related, options)\n }\n})\n\nexport { belongsToType, hasManyType, hasOneType, Relation } from './Relation'\n","import { Relation } from './relations'\n\nexport { belongsToType, hasManyType, hasOneType } from './relations'\n/**\n * BelongsTo relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.belongsTo\n * @method\n * @param {Mapper} related The relation the target belongs to.\n * @param {Object} opts Configuration options.\n * @param {string} opts.foreignKey The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const belongsTo = function (related, opts) {\n return function (mapper) {\n Relation.belongsTo(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasMany relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasMany\n * @method\n * @param {Mapper} related The relation of which the target has many.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasMany = function (related, opts) {\n return function (mapper) {\n Relation.hasMany(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasOne relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasOne\n * @method\n * @param {Mapper} related The relation of which the target has one.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasOne = function (related, opts) {\n return function (mapper) {\n Relation.hasOne(related, opts).assignTo(mapper)\n }\n}\n","import utils, { safeSetLink } from './utils'\nimport Component from './Component'\nimport Settable from './Settable'\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Record'\n\nconst superMethod = function (mapper, name) {\n const store = mapper.datastore\n if (store && store[name]) {\n return function (...args) {\n return store[name](mapper.name, ...args)\n }\n }\n return mapper[name].bind(mapper)\n}\n\n// Cache these strings\nconst creatingPath = 'creating'\nconst noValidatePath = 'noValidate'\nconst keepChangeHistoryPath = 'keepChangeHistory'\nconst previousPath = 'previous'\n\n/**\n * js-data's Record class. An instance of `Record` corresponds to an in-memory\n * representation of a single row or document in a database, Firebase,\n * localstorage, etc. Basically, a `Record` instance represents whatever kind of\n * entity in your persistence layer that has a primary key.\n *\n * ```javascript\n * import {Record} from 'js-data'\n * ```\n *\n * @example Record#constructor\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a plain record\n * let record = new Record()\n * console.log('record: ' + JSON.stringify(record))\n *\n * // You can supply properties on instantiation\n * record = new Record({ name: 'John' })\n * console.log('record: ' + JSON.stringify(record))\n *\n * @example Record#constructor2\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a record that's associated with a Mapper:\n * const UserMapper = new Mapper({ name: 'user' })\n * const User = UserMapper.recordClass\n * const user = UserMapper.createRecord({ name: 'John' })\n * const user2 = new User({ name: 'Sally' })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user2: ' + JSON.stringify(user2))\n *\n * @example Record#constructor3\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n *\n * // Instantiate a record that's associated with a store's Mapper\n * const user = store.createRecord('user', { name: 'John' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor4\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Validate on instantiation\n * const user = store.createRecord('user', { name: 1234 })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor5\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Skip validation on instantiation\n * const user = store.createRecord('user', { name: 1234 }, { noValidate: true })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user.isValid(): ' + user.isValid())\n *\n * @class Record\n * @extends Component\n * @param {Object} [props] The initial properties of the new Record instance.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate=false] Whether to skip validation on the\n * initial properties.\n * @since 3.0.0\n */\nfunction Record (props, opts) {\n utils.classCallCheck(this, Record)\n Settable.call(this)\n props || (props = {})\n opts || (opts = {})\n const _set = this._set\n _set(creatingPath, true)\n if (opts.noValidate) {\n _set(noValidatePath, opts.noValidate === undefined ? true : opts.noValidate)\n }\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\n const mapper = this.constructor.mapper\n const id = mapper ? utils.get(props, mapper.idAttribute) : undefined\n if (id !== undefined) {\n utils.set(this, mapper.idAttribute, id)\n }\n\n utils.fillIn(this, props)\n _set(creatingPath, false)\n const validateOnSet = opts.validateOnSet === undefined ? (mapper ? mapper.validateOnSet : true) : opts.validateOnSet\n _set(noValidatePath, !validateOnSet)\n _set(previousPath, mapper ? mapper.toJSON(props) : utils.plainCopy(props))\n}\n\nexport default Component.extend({\n constructor: Record,\n\n /**\n * Returns the {@link Mapper} paired with this record's class, if any.\n *\n * @method Record#_mapper\n * @returns {Mapper} The {@link Mapper} paired with this record's class, if any.\n * @since 3.0.0\n */\n _mapper () {\n const mapper = this.constructor.mapper\n if (!mapper) {\n throw utils.err(`${DOMAIN}#_mapper`, '')(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Lifecycle hook.\n *\n * @method Record#afterLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n afterLoadRelations () {},\n\n /**\n * Lifecycle hook.\n *\n * @method Record#beforeLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n beforeLoadRelations () {},\n\n /**\n * Return the change history of this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @method Record#changeHistory\n * @since 3.0.0\n */\n changeHistory () {\n return (this._get('history') || []).slice()\n },\n\n /**\n * Return changes to this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#changes\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n * user.name = 'John'\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n *\n * @method Record#changes\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} Object describing the changes to this record since it was\n * instantiated or its {@link Record#commit} method was last called.\n * @since 3.0.0\n */\n changes (opts) {\n opts || (opts = {})\n return utils.diffObjects(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Make the record's current in-memory state it's only state, with any\n * previous property values being set to current values.\n *\n * @example Record#commit\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#commit\n * @param {Object} [opts] Configuration options. Passed to {@link Record#toJSON}.\n * @since 3.0.0\n */\n commit (opts) {\n this._set('changed') // unset\n this._set('history', []) // clear history\n this._set('previous', this.toJSON(opts))\n },\n\n /**\n * Call {@link Mapper#destroy} using this record's primary key.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user')\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Destroy this user from the database\n * return user.destroy()\n * })\n *\n * @method Record#destroy\n * @param {Object} [opts] Configuration options passed to {@link Mapper#destroy}.\n * @returns {Promise} The result of calling {@link Mapper#destroy} with the\n * primary key of this record.\n * @since 3.0.0\n */\n destroy (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n return superMethod(mapper, 'destroy')(utils.get(this, mapper.idAttribute), opts)\n },\n\n /**\n * Return the value at the given path for this instance.\n *\n * @example Record#get\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', { name: 'Bob' })\n * console.log('user.get(\"name\"): ' + user.get('name'))\n *\n * @method Record#get\n * @param {string} key Path of value to retrieve.\n * @returns {*} Value at path.\n * @since 3.0.0\n */\n 'get' (key) {\n return utils.get(this, key)\n },\n\n /**\n * Return whether this record has changed since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#hasChanges\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#hasChanges\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Return whether the record has changed since it was\n * instantiated or since its {@link Record#commit} method was called.\n * @since 3.0.0\n */\n hasChanges (opts) {\n const quickHasChanges = !!(this._get('changed') || []).length\n return quickHasChanges || utils.areDifferent(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Return whether the record is unsaved. Records that have primary keys are\n * considered \"saved\". Records without primary keys are considered \"unsaved\".\n *\n * @example Record#isNew\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * id: 1234\n * })\n * const user2 = store.createRecord('user')\n * console.log('user isNew: ' + user.isNew()) // false\n * console.log('user2 isNew: ' + user2.isNew()) // true\n *\n * @method Record#isNew\n * @returns {boolean} Whether the record is unsaved.\n * @since 3.0.0\n */\n isNew (opts) {\n return utils.get(this, this._mapper().idAttribute) === undefined\n },\n\n /**\n * Return whether the record in its current state passes validation.\n *\n * @example Record#isValid\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user isValid: ' + user.isValid())\n * user.name = 'John'\n * console.log('user isValid: ' + user.isValid())\n *\n * @method Record#isValid\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {boolean} Whether the record in its current state passes\n * validation.\n * @since 3.0.0\n */\n isValid (opts) {\n return !this._mapper().validate(this, opts)\n },\n\n removeInverseRelation(currentParent, id, inverseDef, idAttribute) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n // e.g. remove comment from otherPost.comments\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n setupInverseRelation(record, id, inverseDef, idAttribute) {\n // Update (set) inverse relation\n if (inverseDef.type === hasOneType) {\n // e.g. someUser.profile = profile\n safeSetLink(record, inverseDef.localField, this)\n } else if (inverseDef.type === hasManyType) {\n // e.g. add comment to somePost.comments\n const children = utils.get(record, inverseDef.localField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n /**\n * Lazy load relations of this record, to be attached to the record once their\n * loaded.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user', {\n * relations: {\n * hasMany: {\n * post: {\n * localField: 'posts',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.defineMapper('post', {\n * relations: {\n * belongsTo: {\n * user: {\n * localField: 'user',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Load the user's post relations\n * return user.loadRelations(['post'])\n * }).then((user) => {\n * console.log(user.posts) // [{...}, {...}, ...]\n * })\n *\n * @method Record#loadRelations\n * @param {string[]} [relations] List of relations to load. Can use localField\n * names or Mapper names to pick relations.\n * @param {Object} [opts] Configuration options.\n * @returns {Promise} Resolves with the record, with the loaded relations now\n * attached.\n * @since 3.0.0\n */\n loadRelations (relations, opts) {\n let op\n const mapper = this._mapper()\n\n // Default values for arguments\n relations || (relations = [])\n if (utils.isString(relations)) {\n relations = [relations]\n }\n opts || (opts = {})\n opts.with = relations\n\n // Fill in \"opts\" with the Model's configuration\n utils._(opts, mapper)\n opts.adapter = mapper.getAdapterName(opts)\n\n // beforeLoadRelations lifecycle hook\n op = opts.op = 'beforeLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'loadRelations'\n mapper.dbg(op, this, relations, opts)\n let tasks = []\n let task\n utils.forEachRelation(mapper, opts, (def, optsCopy) => {\n const relatedMapper = def.getRelation()\n optsCopy.raw = false\n if (utils.isFunction(def.load)) {\n task = def.load(mapper, def, this, opts)\n } else if (def.type === 'hasMany' || def.type === 'hasOne') {\n if (def.foreignKey) {\n task = superMethod(relatedMapper, 'findAll')({\n [def.foreignKey]: utils.get(this, mapper.idAttribute)\n }, optsCopy).then(function (relatedData) {\n if (def.type === 'hasOne') {\n return relatedData.length ? relatedData[0] : undefined\n }\n return relatedData\n })\n } else if (def.localKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [relatedMapper.idAttribute]: {\n 'in': utils.get(this, def.localKeys)\n }\n }\n })\n } else if (def.foreignKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [def.foreignKeys]: {\n 'contains': utils.get(this, mapper.idAttribute)\n }\n }\n }, opts)\n }\n } else if (def.type === 'belongsTo') {\n const key = utils.get(this, def.foreignKey)\n if (utils.isSorN(key)) {\n task = superMethod(relatedMapper, 'find')(key, optsCopy)\n }\n }\n if (task) {\n task = task.then((relatedData) => {\n def.setLocalField(this, relatedData)\n })\n tasks.push(task)\n }\n })\n return Promise.all(tasks)\n }).then(() => {\n // afterLoadRelations lifecycle hook\n op = opts.op = 'afterLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => this)\n })\n },\n\n /**\n * Return the properties with which this record was instantiated.\n *\n * @example Record#previous\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.name = 'Bob'\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.commit()\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n *\n * @method Record#previous\n * @param {string} [key] If specified, return just the initial value of the\n * given key.\n * @returns {Object} The initial properties of this record.\n * @since 3.0.0\n */\n previous (key) {\n if (key) {\n return this._get(`previous.${key}`)\n }\n return this._get('previous')\n },\n\n /**\n * Revert changes to this record back to the properties it had when it was\n * instantiated.\n *\n * @example Record#revert\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user: ' + JSON.stringify(user))\n * user.name = 'Bob'\n * console.log('user: ' + JSON.stringify(user))\n * user.revert()\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#revert\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.preserve] Array of strings or Regular Expressions\n * denoting properties that should not be reverted.\n * @since 3.0.0\n */\n revert (opts) {\n const previous = this._get('previous')\n opts || (opts = {})\n opts.preserve || (opts.preserve = [])\n utils.forOwn(this, (value, key) => {\n if (key !== this._mapper().idAttribute && !previous.hasOwnProperty(key) && this.hasOwnProperty(key) && opts.preserve.indexOf(key) === -1) {\n delete this[key]\n }\n })\n utils.forOwn(previous, (value, key) => {\n if (opts.preserve.indexOf(key) === -1) {\n this[key] = value\n }\n })\n this.commit()\n },\n\n /**\n * Delegates to {@link Mapper#create} or {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('session')\n * const session = store.createRecord('session', { topic: 'Node.js' })\n *\n * // Create a new record in the database\n * session.save().then(() => {\n * console.log(session.id) // 1234\n *\n * session.skill_level = 'beginner'\n *\n * // Update the record in the database\n * return user.save()\n * })\n *\n * @method Record#save\n * @param {Object} [opts] Configuration options. See {@link Mapper#create} and\n * {@link Mapper#update}.\n * @param {boolean} [opts.changesOnly] Equality function. Default uses `===`.\n * @param {Function} [opts.equalsFn] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @param {Array} [opts.ignore] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @returns {Promise} The result of calling {@link Mapper#create} or\n * {@link Mapper#update}.\n * @since 3.0.0\n */\n save (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n const id = utils.get(this, mapper.idAttribute)\n let props = this\n\n const postProcess = (result) => {\n const record = opts.raw ? result.data : result\n if (record) {\n utils.deepMixIn(this, record)\n this.commit()\n }\n return result\n }\n\n if (id === undefined) {\n return superMethod(mapper, 'create')(props, opts).then(postProcess)\n }\n if (opts.changesOnly) {\n const changes = this.changes(opts)\n props = {}\n utils.fillIn(props, changes.added)\n utils.fillIn(props, changes.changed)\n }\n return superMethod(mapper, 'update')(id, props, opts).then(postProcess)\n },\n\n /**\n * Set the value for a given key, or the values for the given keys if \"key\" is\n * an object. Triggers change events on those properties that have `track: true`\n * in {@link Mapper#schema}.\n *\n * @example Record#set\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set('name', 'Bob')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set({ age: 30, role: 'admin' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @fires Record#change\n * @method Record#set\n * @param {(string|Object)} key Key to set or hash of key-value pairs to set.\n * @param {*} [value] Value to set for the given key.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n 'set' (key, value, opts) {\n if (utils.isObject(key)) {\n opts = value\n }\n opts || (opts = {})\n if (opts.silent) {\n this._set('silent', true)\n }\n utils.set(this, key, value)\n if (!this._get('eventId')) {\n this._set('silent') // unset\n }\n },\n\n /**\n * Return a plain object representation of this record. If the class from\n * which this record was created has a Mapper, then {@link Mapper#toJSON} will\n * be called with this record instead.\n *\n * @example Record#toJSON\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * const user = store.createRecord('user', {\n * name: 'John',\n * $$hashKey: '1234'\n * })\n * console.log('user: ' + JSON.stringify(user.toJSON()))\n * console.log('user: ' + JSON.stringify(user.toJSON({ strict: true })))\n *\n * @method Record#toJSON\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation. Only available as an option if the class\n * from which this record was created has a Mapper and this record resides in\n * an instance of {@link DataStore}.\n * @returns {Object} Plain object representation of this record.\n * @since 3.0.0\n */\n toJSON (opts) {\n const mapper = this.constructor.mapper\n if (mapper) {\n return mapper.toJSON(this, opts)\n } else {\n const json = {}\n utils.forOwn(this, function (prop, key) {\n json[key] = utils.plainCopy(prop)\n })\n return json\n }\n },\n\n /**\n * Unset the value for a given key. Triggers change events on those properties\n * that have `track: true` in {@link Mapper#schema}.\n *\n * @example Record#unset\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', {\n * name: 'John'\n * })\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.unset('name')\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#unset\n * @param {string} key Key to unset.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n unset (key, opts) {\n this.set(key, undefined, opts)\n },\n\n /**\n * Validate this record based on its current properties.\n *\n * @example Record#validate\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user validation: ' + JSON.stringify(user.validate()))\n * user.name = 'John'\n * console.log('user validation: ' + user.validate())\n *\n * @method Record#validate\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {*} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (opts) {\n return this._mapper().validate(this, opts)\n }\n})\n\n/**\n * Allow records to emit events.\n *\n * An record's registered listeners are stored in the record's private data.\n */\nutils.eventify(\n Record.prototype,\n function () {\n return this._get('events')\n },\n function (value) {\n this._set('events', value)\n }\n)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link Record~changeListener} on how to listen for this event.\n *\n * @event Record#change\n * @see Record~changeListener\n */\n\n/**\n * Callback signature for the {@link Record#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * record.on('change', onChange)\n *\n * @callback Record~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Record#event:change\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Record:\n * @example Record.extend\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomRecordClass extends Record {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customRecord = new CustomRecordClass()\n * console.log(customRecord.foo())\n * console.log(CustomRecordClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherRecordClass = Record.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherRecord = new OtherRecordClass()\n * console.log(otherRecord.foo())\n * console.log(OtherRecordClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherRecordClass () {\n * Record.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Record.extend({\n * constructor: AnotherRecordClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherRecord = new AnotherRecordClass()\n * console.log(anotherRecord.created_at)\n * console.log(anotherRecord.foo())\n * console.log(AnotherRecordClass.beep())\n *\n * @method Record.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Record class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Schema'\n\n/**\n * A function map for each of the seven primitive JSON types defined by the core specification.\n * Each function will check a given value and return true or false if the value is an instance of that type.\n * ```\n * types.integer(1) // returns true\n * types.string({}) // returns false\n * ```\n * http://json-schema.org/latest/json-schema-core.html#anchor8\n * @name Schema.types\n * @type {Object}\n */\nconst types = {\n array: utils.isArray,\n boolean: utils.isBoolean,\n integer: utils.isInteger,\n 'null': utils.isNull,\n number: utils.isNumber,\n object: utils.isObject,\n string: utils.isString\n}\n\n/**\n * @ignore\n */\nconst segmentToString = function (segment, prev) {\n let str = ''\n if (segment) {\n if (utils.isNumber(segment)) {\n str += `[${segment}]`\n } else if (prev) {\n str += `.${segment}`\n } else {\n str += `${segment}`\n }\n }\n return str\n}\n\n/**\n * @ignore\n */\nconst makePath = function (opts) {\n opts || (opts = {})\n let path = ''\n const segments = opts.path || []\n segments.forEach(function (segment) {\n path += segmentToString(segment, path)\n })\n path += segmentToString(opts.prop, path)\n return path\n}\n\n/**\n * @ignore\n */\nconst makeError = function (actual, expected, opts) {\n return {\n expected,\n actual: '' + actual,\n path: makePath(opts)\n }\n}\n\n/**\n * @ignore\n */\nconst addError = function (actual, expected, opts, errors) {\n errors.push(makeError(actual, expected, opts))\n}\n\n/**\n * @ignore\n */\nconst maxLengthCommon = function (keyword, value, schema, opts) {\n const max = schema[keyword]\n if (value.length > max) {\n return makeError(value.length, `length no more than ${max}`, opts)\n }\n}\n\n/**\n * @ignore\n */\nconst minLengthCommon = function (keyword, value, schema, opts) {\n const min = schema[keyword]\n if (value.length < min) {\n return makeError(value.length, `length no less than ${min}`, opts)\n }\n}\n\n/**\n * A map of all object member validation functions for each keyword defined in the JSON Schema.\n * @name Schema.validationKeywords\n * @type {Object}\n */\nconst validationKeywords = {\n /**\n * Validates the provided value against all schemas defined in the Schemas `allOf` keyword.\n * The instance is valid against if and only if it is valid against all the schemas declared in the Schema's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be a valid JSON Schema.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor82\n *\n * @name Schema.validationKeywords.allOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `allOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n allOf (value, schema, opts) {\n let allErrors = []\n schema.allOf.forEach(function (_schema) {\n allErrors = allErrors.concat(validate(value, _schema, opts) || [])\n })\n return allErrors.length ? allErrors : undefined\n },\n\n /**\n * Validates the provided value against all schemas defined in the Schemas `anyOf` keyword.\n * The instance is valid against this keyword if and only if it is valid against\n * at least one of the schemas in this keyword's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor85\n *\n * @name Schema.validationKeywords.anyOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `anyOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n anyOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.anyOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * http://json-schema.org/latest/json-schema-validation.html#anchor70\n *\n * @name Schema.validationKeywords.dependencies\n * @method\n * @param {*} value TODO\n * @param {Object} schema TODO\n * @param {Object} opts TODO\n */\n dependencies (value, schema, opts) {\n // TODO\n },\n\n /**\n * Validates the provided value against an array of possible values defined by the Schema's `enum` keyword\n * Validation succeeds if the value is deeply equal to one of the values in the array.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor76\n *\n * @name Schema.validationKeywords.enum\n * @method\n * @param {*} value Value to validate\n * @param {Object} schema Schema containing the `enum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n enum (value, schema, opts) {\n const possibleValues = schema['enum']\n if (utils.findIndex(possibleValues, (item) => utils.deepEqual(item, value)) === -1) {\n return makeError(value, `one of (${possibleValues.join(', ')})`, opts)\n }\n },\n\n /**\n * Validates each of the provided array values against a schema or an array of schemas defined by the Schema's `items` keyword\n * see http://json-schema.org/latest/json-schema-validation.html#anchor37 for validation rules.\n *\n * @name Schema.validationKeywords.items\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the items keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n items (value, schema, opts) {\n opts || (opts = {})\n // TODO: additionalItems\n let items = schema.items\n let errors = []\n const checkingTuple = utils.isArray(items)\n const length = value.length\n for (var prop = 0; prop < length; prop++) {\n if (checkingTuple) {\n // Validating a tuple, instead of just checking each item against the\n // same schema\n items = schema.items[prop]\n }\n opts.prop = prop\n errors = errors.concat(validate(value[prop], items, opts) || [])\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided number against a maximum value defined by the Schema's `maximum` keyword\n * Validation succeeds if the value is a number, and is less than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor17\n *\n * @name Schema.validationKeywords.maximum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `maximum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maximum (value, schema, opts) {\n // Must be a number\n const maximum = schema.maximum\n // Must be a boolean\n // Depends on maximum\n // default: false\n const exclusiveMaximum = schema.exclusiveMaximum\n if (typeof value === typeof maximum && !(exclusiveMaximum ? maximum > value : maximum >= value)) {\n return exclusiveMaximum\n ? makeError(value, `no more than nor equal to ${maximum}`, opts)\n : makeError(value, `no more than ${maximum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a maximum value defined by the Schema's `maxItems` keyword.\n * Validation succeeds if the length of the array is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor42\n *\n * @name Schema.validationKeywords.maxItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `maxItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return maxLengthCommon('maxItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a maximum value defined in the Schema's `maxLength` keyword.\n * Validation succeeds if the length of the string is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor26\n *\n * @name Schema.validationKeywords.maxLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `maxLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxLength (value, schema, opts) {\n return maxLengthCommon('maxLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a maximum value defined in the Schema's `maxProperties` keyword.\n * Validation succeeds if the object's property count is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor54\n *\n * @name Schema.validationKeywords.maxProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `maxProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const maxProperties = schema.maxProperties\n const length = Object.keys(value).length\n if (length > maxProperties) {\n return makeError(length, `no more than ${maxProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided value against a minimum value defined by the Schema's `minimum` keyword\n * Validation succeeds if the value is a number and is greater than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor21\n *\n * @name Schema.validationKeywords.minimum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `minimum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minimum (value, schema, opts) {\n // Must be a number\n const minimum = schema.minimum\n // Must be a boolean\n // Depends on minimum\n // default: false\n const exclusiveMinimum = schema.exclusiveMinimum\n if (typeof value === typeof minimum && !(exclusiveMinimum ? value > minimum : value >= minimum)) {\n return exclusiveMinimum\n ? makeError(value, `no less than nor equal to ${minimum}`, opts)\n : makeError(value, `no less than ${minimum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a minimum value defined by the Schema's `minItems` keyword.\n * Validation succeeds if the length of the array is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor45\n *\n * @name Schema.validationKeywords.minItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `minItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return minLengthCommon('minItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a minimum value defined in the Schema's `minLength` keyword.\n * Validation succeeds if the length of the string is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor29\n *\n * @name Schema.validationKeywords.minLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `minLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minLength (value, schema, opts) {\n return minLengthCommon('minLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a minimum value defined in the Schema's `minProperties` keyword.\n * Validation succeeds if the object's property count is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor57\n *\n * @name Schema.validationKeywords.minProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `minProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const minProperties = schema.minProperties\n const length = Object.keys(value).length\n if (length < minProperties) {\n return makeError(length, `no more than ${minProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided number is a multiple of the number defined in the Schema's `multipleOf` keyword.\n * Validation succeeds if the number can be divided equally into the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor14\n *\n * @name Schema.validationKeywords.multipleOf\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing the `multipleOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n multipleOf (value, schema, opts) {\n const multipleOf = schema.multipleOf\n if (utils.isNumber(value)) {\n if ((value / multipleOf) % 1 !== 0) {\n return makeError(value, `multipleOf ${multipleOf}`, opts)\n }\n }\n },\n\n /**\n * Validates the provided value is not valid with any of the schemas defined in the Schema's `not` keyword.\n * An instance is valid against this keyword if and only if it is NOT valid against the schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor91\n * @name Schema.validationKeywords.not\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the not keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n not (value, schema, opts) {\n if (!validate(value, schema.not, opts)) {\n // TODO: better messaging\n return makeError('succeeded', 'should have failed', opts)\n }\n },\n\n /**\n * Validates the provided value is valid with one and only one of the schemas defined in the Schema's `oneOf` keyword.\n * An instance is valid against this keyword if and only if it is valid against a single schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor88\n * @name Schema.validationKeywords.oneOf\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the `oneOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n oneOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.oneOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else if (validated) {\n allErrors = [makeError('valid against more than one', 'valid against only one', opts)]\n validated = false\n return false\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * Validates the provided string matches a pattern defined in the Schema's `pattern` keyword.\n * Validation succeeds if the string is a match of the regex value of this keyword.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor33\n * @name Schema.validationKeywords.pattern\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `pattern` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n pattern (value, schema, opts) {\n const pattern = schema.pattern\n if (utils.isString(value) && !value.match(pattern)) {\n return makeError(value, pattern, opts)\n }\n },\n\n /**\n * Validates the provided object's properties against a map of values defined in the Schema's `properties` keyword.\n * Validation succeeds if the object's property are valid with each of the schema's in the provided map.\n * Validation also depends on the additionalProperties and or patternProperties.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor64 for more info.\n *\n * @name Schema.validationKeywords.properties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `properties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n properties (value, schema, opts) {\n opts || (opts = {})\n // Can be a boolean or an object\n // Technically the default is an \"empty schema\", but here \"true\" is\n // functionally the same\n const additionalProperties = schema.additionalProperties === undefined ? true : schema.additionalProperties\n // \"s\": The property set of the instance to validate.\n const toValidate = {}\n // \"p\": The property set from \"properties\".\n // Default is an object\n const properties = schema.properties || {}\n // \"pp\": The property set from \"patternProperties\".\n // Default is an object\n const patternProperties = schema.patternProperties || {}\n let errors = []\n\n // Collect set \"s\"\n utils.forOwn(value, function (_value, prop) {\n toValidate[prop] = undefined\n })\n // Remove from \"s\" all elements of \"p\", if any.\n utils.forOwn(properties || {}, function (_schema, prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n delete toValidate[prop]\n })\n // For each regex in \"pp\", remove all elements of \"s\" which this regex\n // matches.\n utils.forOwn(patternProperties, function (_schema, pattern) {\n utils.forOwn(toValidate, function (undef, prop) {\n if (prop.match(pattern)) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n delete toValidate[prop]\n }\n })\n })\n const keys = Object.keys(toValidate)\n // If \"s\" is not empty, validation fails\n if (additionalProperties === false) {\n if (keys.length) {\n const origProp = opts.prop\n opts.prop = ''\n addError(`extra fields: ${keys.join(', ')}`, 'no extra fields', opts, errors)\n opts.prop = origProp\n }\n } else if (utils.isObject(additionalProperties)) {\n // Otherwise, validate according to provided schema\n keys.forEach(function (prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], additionalProperties, opts) || [])\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided object's has all properties listed in the Schema's `properties` keyword array.\n * Validation succeeds if the object contains all properties provided in the array value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor61\n *\n * @name Schema.validationKeywords.required\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `required` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n required (value, schema, opts) {\n opts || (opts = {})\n const required = schema.required\n let errors = []\n if (!opts.existingOnly) {\n required.forEach(function (prop) {\n if (utils.get(value, prop) === undefined) {\n const prevProp = opts.prop\n opts.prop = prop\n addError(undefined, 'a value', opts, errors)\n opts.prop = prevProp\n }\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided value's type is equal to the type, or array of types, defined in the Schema's `type` keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor79\n *\n * @name Schema.validationKeywords.type\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `type` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n type (value, schema, opts) {\n let type = schema.type\n let validType\n // Can be one of several types\n if (utils.isString(type)) {\n type = [type]\n }\n // Try to match the value against an expected type\n type.forEach(function (_type) {\n // TODO: throw an error if type is not defined\n if (types[_type](value, schema, opts)) {\n // Matched a type\n validType = _type\n return false\n }\n })\n // Value did not match any expected type\n if (!validType) {\n return makeError(value !== undefined && value !== null ? typeof value : '' + value, `one of (${type.join(', ')})`, opts)\n }\n // Run keyword validators for matched type\n // http://json-schema.org/latest/json-schema-validation.html#anchor12\n const validator = typeGroupValidators[validType]\n if (validator) {\n return validator(value, schema, opts)\n }\n },\n\n /**\n * Validates the provided array values are unique.\n * Validation succeeds if the items in the array are unique, but only if the value of this keyword is true\n * see http://json-schema.org/latest/json-schema-validation.html#anchor49\n *\n * @name Schema.validationKeywords.uniqueItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `uniqueItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n uniqueItems (value, schema, opts) {\n if (value && value.length && schema.uniqueItems) {\n const length = value.length\n let item, i, j\n // Check n - 1 items\n for (i = length - 1; i > 0; i--) {\n item = value[i]\n // Only compare against unchecked items\n for (j = i - 1; j >= 0; j--) {\n // Found a duplicate\n if (utils.deepEqual(item, value[j])) {\n return makeError(item, 'no duplicates', opts)\n }\n }\n }\n }\n }\n}\n\n/**\n * @ignore\n */\nconst runOps = function (ops, value, schema, opts) {\n let errors = []\n ops.forEach(function (op) {\n if (schema[op] !== undefined) {\n errors = errors.concat(validationKeywords[op](value, schema, opts) || [])\n }\n })\n return errors.length ? errors : undefined\n}\n\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\nconst STRING_OPS = ['maxLength', 'minLength', 'pattern']\n\n/**\n * http://json-schema.org/latest/json-schema-validation.html#anchor75\n * @ignore\n */\nconst validateAny = function (value, schema, opts) {\n return runOps(ANY_OPS, value, schema, opts)\n}\n\n/**\n * Validates the provided value against a given Schema according to the http://json-schema.org/ v4 specification.\n *\n * @name Schema.validate\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Valid Schema according to the http://json-schema.org/ v4 specification.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\nconst validate = function (value, schema, opts) {\n let errors = []\n opts || (opts = {})\n opts.ctx || (opts.ctx = { value, schema })\n let shouldPop\n let prevProp = opts.prop\n if (schema === undefined) {\n return\n }\n if (!utils.isObject(schema)) {\n throw utils.err(`${DOMAIN}#validate`)(500, `Invalid schema at path: \"${opts.path}\"`)\n }\n if (opts.path === undefined) {\n opts.path = []\n }\n // Track our location as we recurse\n if (opts.prop !== undefined) {\n shouldPop = true\n opts.path.push(opts.prop)\n opts.prop = undefined\n }\n // Validate against parent schema\n if (schema['extends']) {\n // opts.path = path\n // opts.prop = prop\n if (utils.isFunction(schema['extends'].validate)) {\n errors = errors.concat(schema['extends'].validate(value, opts) || [])\n } else {\n errors = errors.concat(validate(value, schema['extends'], opts) || [])\n }\n }\n if (value === undefined) {\n // Check if property is required\n if (schema.required === true && !opts.existingOnly) {\n addError(value, 'a value', opts, errors)\n }\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n }\n\n errors = errors.concat(validateAny(value, schema, opts) || [])\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n}\n\n// These strings are cached for optimal performance of the change detection\n// boolean - Whether a Record is changing in the current execution frame\nconst changingPath = 'changing'\n// string[] - Properties that have changed in the current execution frame\nconst changedPath = 'changed'\n// Object[] - History of change records\nconst changeHistoryPath = 'history'\n// boolean - Whether a Record is currently being instantiated\nconst creatingPath = 'creating'\n// number - The setTimeout change event id of a Record, if any\nconst eventIdPath = 'eventId'\n// boolean - Whether to skip validation for a Record's currently changing property\nconst noValidatePath = 'noValidate'\n// boolean - Whether to preserve Change History for a Record\nconst keepChangeHistoryPath = 'keepChangeHistory'\n// boolean - Whether to skip change notification for a Record's currently\n// changing property\nconst silentPath = 'silent'\nconst validationFailureMsg = 'validation failed'\n\n/**\n * Assemble a property descriptor which will be added to the prototype of\n * {@link Mapper#recordClass}. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @ignore\n */\nconst makeDescriptor = function (prop, schema, opts) {\n const descriptor = {\n // Better to allow configurability, but at the user's own risk\n configurable: true,\n // These properties are enumerable by default, but regardless of their\n // enumerability, they won't be \"own\" properties of individual records\n enumerable: schema.enumerable === undefined ? true : !!schema.enumerable\n }\n // Cache a few strings for optimal performance\n const keyPath = `props.${prop}`\n const previousPath = `previous.${prop}`\n const getter = opts.getter\n const setter = opts.setter\n const unsetter = opts.unsetter\n const track = utils.isBoolean(opts.track) ? opts.track : schema.track\n\n descriptor.get = function () {\n return this._get(keyPath)\n }\n\n if (utils.isFunction(schema.get)) {\n const originalGet = descriptor.get\n descriptor.get = function () {\n return schema.get.call(this, originalGet)\n }\n }\n\n descriptor.set = function (value) {\n // These are accessed a lot\n const _get = this[getter]\n const _set = this[setter]\n const _unset = this[unsetter]\n // Optionally check that the new value passes validation\n if (!_get(noValidatePath)) {\n const errors = schema.validate(value, { path: [prop] })\n if (errors) {\n // Immediately throw an error, preventing the record from getting into\n // an invalid state\n const error = new Error(validationFailureMsg)\n error.errors = errors\n throw error\n }\n }\n // TODO: Make it so tracking can be turned on for all properties instead of\n // only per-property\n if (track && !_get(creatingPath)) {\n // previous is versioned on database commit\n // props are versioned on set()\n const previous = _get(previousPath)\n const current = _get(keyPath)\n let changing = _get(changingPath)\n let changed = _get(changedPath)\n\n if (!changing) {\n // Track properties that are changing in the current event loop\n changed = []\n }\n\n // Add changing properties to this array once at most\n const index = changed.indexOf(prop)\n if (current !== value && index === -1) {\n changed.push(prop)\n }\n if (previous === value) {\n if (index >= 0) {\n changed.splice(index, 1)\n }\n }\n // No changes in current event loop\n if (!changed.length) {\n changing = false\n _unset(changingPath)\n _unset(changedPath)\n // Cancel pending change event\n if (_get(eventIdPath)) {\n clearTimeout(_get(eventIdPath))\n _unset(eventIdPath)\n }\n }\n // Changes detected in current event loop\n if (!changing && changed.length) {\n _set(changedPath, changed)\n _set(changingPath, true)\n // Saving the timeout id allows us to batch all changes in the same\n // event loop into a single \"change\"\n // TODO: Optimize\n _set(eventIdPath, setTimeout(() => {\n // Previous event loop where changes were gathered has ended, so\n // notify any listeners of those changes and prepare for any new\n // changes\n _unset(changedPath)\n _unset(eventIdPath)\n _unset(changingPath)\n // TODO: Optimize\n if (!_get(silentPath)) {\n let i\n for (i = 0; i < changed.length; i++) {\n this.emit('change:' + changed[i], this, utils.get(this, changed[i]))\n }\n\n const changes = utils.diffObjects({ [prop] : value }, { [prop] : current })\n\n if (_get(keepChangeHistoryPath)) {\n const changeRecord = utils.plainCopy(changes)\n changeRecord.timestamp = new Date().getTime()\n let changeHistory = _get(changeHistoryPath)\n !changeHistory && _set(changeHistoryPath, (changeHistory = []))\n changeHistory.push(changeRecord)\n }\n this.emit('change', this, changes)\n }\n _unset(silentPath)\n }, 0))\n }\n }\n _set(keyPath, value)\n return value\n }\n\n if (utils.isFunction(schema.set)) {\n const originalSet = descriptor.set\n descriptor.set = function (value) {\n return schema.set.call(this, value, originalSet)\n }\n }\n\n return descriptor\n}\n\n/**\n * A map of validation functions grouped by type.\n *\n * @name Schema.typeGroupValidators\n * @type {Object}\n */\nconst typeGroupValidators = {\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an array.\n * The validation keywords for the type `array` are:\n *```\n * ['items', 'maxItems', 'minItems', 'uniqueItems']\n *```\n * see http://json-schema.org/latest/json-schema-validation.html#anchor25\n *\n * @name Schema.typeGroupValidators.array\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing at least one array keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n array: function (value, schema, opts) {\n return runOps(ARRAY_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an integer.\n * The validation keywords for the type `integer` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.integer\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `integer` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n integer: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an number.\n * The validation keywords for the type `number` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.number\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `number` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n number: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of a number or integer.\n * The validation keywords for the type `numeric` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor13.\n *\n * @name Schema.typeGroupValidators.numeric\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `numeric` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n numeric: function (value, schema, opts) {\n return runOps(NUMERIC_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an object.\n * The validation keywords for the type `object` are:\n *```\n * ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor53.\n *\n * @name Schema.typeGroupValidators.object\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing at least one `object` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n object: function (value, schema, opts) {\n return runOps(OBJECT_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an string.\n * The validation keywords for the type `string` are:\n *```\n * ['maxLength', 'minLength', 'pattern']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor25.\n *\n * @name Schema.typeGroupValidators.string\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing at least one `string` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n string: function (value, schema, opts) {\n return runOps(STRING_OPS, value, schema, opts)\n }\n}\n\n/**\n * js-data's Schema class.\n *\n * @example Schema#constructor\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const PostSchema = new Schema({\n * type: 'object',\n * properties: {\n * title: { type: 'string' }\n * }\n * })\n * PostSchema.validate({ title: 1234 })\n *\n * @class Schema\n * @extends Component\n * @param {Object} definition Schema definition according to json-schema.org\n */\nfunction Schema (definition) {\n definition || (definition = {})\n // TODO: schema validation\n utils.fillIn(this, definition)\n\n if (this.type === 'object' && this.properties) {\n utils.forOwn(this.properties, (_definition, prop) => {\n if (!(_definition instanceof Schema)) {\n this.properties[prop] = new Schema(_definition)\n }\n })\n } else if (this.type === 'array' && this.items && !(this.items instanceof Schema)) {\n this.items = new Schema(this.items)\n }\n if (this.extends && !(this.extends instanceof Schema)) {\n this.extends = new Schema(this.extends)\n }\n ['allOf', 'anyOf', 'oneOf'].forEach((validationKeyword) => {\n if (this[validationKeyword]) {\n this[validationKeyword].forEach((_definition, i) => {\n if (!(_definition instanceof Schema)) {\n this[validationKeyword][i] = new Schema(_definition)\n }\n })\n }\n })\n}\n\nexport default Component.extend({\n constructor: Schema,\n\n /**\n * This adds ES5 getters/setters to the target based on the \"properties\" in\n * this Schema, which makes possible change tracking and validation on\n * property assignment.\n *\n * @name Schema#validate\n * @method\n * @param {Object} target The prototype to which to apply this schema.\n */\n apply (target, opts) {\n opts || (opts = {})\n opts.getter || (opts.getter = '_get')\n opts.setter || (opts.setter = '_set')\n opts.unsetter || (opts.unsetter = '_unset')\n opts.track || (opts.track = this.track)\n const properties = this.properties || {}\n utils.forOwn(properties, function (schema, prop) {\n Object.defineProperty(\n target,\n prop,\n makeDescriptor(prop, schema, opts)\n )\n })\n },\n\n /**\n * Apply default values to the target object for missing values.\n *\n * @name Schema#applyDefaults\n * @method\n * @param {Object} target The target to which to apply values for missing values.\n */\n applyDefaults (target) {\n if (!target) {\n return\n }\n const properties = this.properties || {}\n const hasSet = utils.isFunction(target.set) || utils.isFunction(target._set)\n utils.forOwn(properties, function (schema, prop) {\n if (schema.hasOwnProperty('default') && utils.get(target, prop) === undefined) {\n if (hasSet) {\n target.set(prop, utils.plainCopy(schema['default']), { silent: true })\n } else {\n utils.set(target, prop, utils.plainCopy(schema['default']))\n }\n }\n if (schema.type === 'object' && schema.properties) {\n if (hasSet) {\n const orig = target._get('noValidate')\n target._set('noValidate', true)\n utils.set(target, prop, utils.get(target, prop) || {}, { silent: true })\n target._set('noValidate', orig)\n } else {\n utils.set(target, prop, utils.get(target, prop) || {})\n }\n schema.applyDefaults(utils.get(target, prop))\n }\n })\n },\n\n /**\n * Create a copy of the given value that contains only the properties defined\n * in this schema.\n *\n * @name Schema#pick\n * @method\n * @param {*} value The value to copy.\n * @returns {*} The copy.\n */\n pick (value) {\n if (this.type === 'object') {\n value || (value = {})\n let copy = {}\n if (this.properties) {\n utils.forOwn(this.properties, (_definition, prop) => {\n copy[prop] = _definition.pick(value[prop])\n })\n }\n if (this.extends) {\n utils.fillIn(copy, this.extends.pick(value))\n }\n return copy\n } else if (this.type === 'array') {\n value || (value = [])\n return value.map((item) => {\n const _copy = this.items ? this.items.pick(item) : {}\n if (this.extends) {\n utils.fillIn(_copy, this.extends.pick(item))\n }\n return _copy\n })\n }\n return utils.plainCopy(value)\n },\n\n /**\n * Validate the provided value against this schema.\n *\n * @name Schema#validate\n * @method\n * @param {*} value Value to validate.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n validate (value, opts) {\n return validate(value, this, opts)\n }\n}, {\n ANY_OPS,\n ARRAY_OPS,\n NUMERIC_OPS,\n OBJECT_OPS,\n STRING_OPS,\n typeGroupValidators,\n types,\n validate,\n validationKeywords\n})\n\n/**\n * Create a subclass of this Schema:\n * @example Schema.extend\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSchemaClass extends Schema {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSchema = new CustomSchemaClass()\n * console.log(customSchema.foo())\n * console.log(CustomSchemaClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSchemaClass = Schema.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSchema = new OtherSchemaClass()\n * console.log(otherSchema.foo())\n * console.log(OtherSchemaClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSchemaClass () {\n * Schema.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Schema.extend({\n * constructor: AnotherSchemaClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSchema = new AnotherSchemaClass()\n * console.log(anotherSchema.created_at)\n * console.log(anotherSchema.foo())\n * console.log(AnotherSchemaClass.beep())\n *\n * @method Schema.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Schema class.\n * @since 3.0.0\n */\n\n","import utils from './utils'\nimport Component from './Component'\nimport Record from './Record'\nimport Schema from './Schema'\nimport { Relation } from './relations'\nimport {\n belongsTo,\n belongsToType,\n hasMany,\n hasManyType,\n hasOne,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Mapper'\nconst applyDefaultsHooks = [\n 'beforeCreate',\n 'beforeCreateMany'\n]\nconst validatingHooks = [\n 'beforeCreate',\n 'beforeCreateMany',\n 'beforeUpdate',\n 'beforeUpdateAll',\n 'beforeUpdateMany'\n]\nconst makeNotify = function (num) {\n return function (...args) {\n const opts = args[args.length - num]\n const op = opts.op\n this.dbg(op, ...args)\n\n if (applyDefaultsHooks.indexOf(op) !== -1 && opts.applyDefaults !== false) {\n const schema = this.getSchema()\n if (schema && schema.applyDefaults) {\n let toProcess = args[0]\n if (!utils.isArray(toProcess)) {\n toProcess = [toProcess]\n }\n toProcess.forEach((record) => {\n schema.applyDefaults(record)\n })\n }\n }\n\n // Automatic validation\n if (validatingHooks.indexOf(op) !== -1 && !opts.noValidate) {\n // Save current value of option\n const originalExistingOnly = opts.existingOnly\n\n // For updates, ignore required fields if they aren't present\n if (op.indexOf('beforeUpdate') === 0 && opts.existingOnly === undefined) {\n opts.existingOnly = true\n }\n const errors = this.validate(args[op === 'beforeUpdate' ? 1 : 0], utils.pick(opts, ['existingOnly']))\n\n // Restore option\n opts.existingOnly = originalExistingOnly\n\n // Abort lifecycle due to validation errors\n if (errors) {\n const err = new Error('validation failed')\n err.errors = errors\n return utils.reject(err)\n }\n }\n\n // Emit lifecycle event\n if (opts.notify || (opts.notify === undefined && this.notify)) {\n setTimeout(() => {\n this.emit(op, ...args)\n })\n }\n }\n}\n\n// These are the default implementations of all of the lifecycle hooks\nconst notify = makeNotify(1)\nconst notify2 = makeNotify(2)\n\n// This object provides meta information used by Mapper#crud to actually\n// execute each lifecycle method\nconst LIFECYCLE_METHODS = {\n count: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroy: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroyAll: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n find: {\n defaults: [undefined, {}],\n types: []\n },\n findAll: {\n defaults: [{}, {}],\n types: []\n },\n sum: {\n defaults: [undefined, {}, {}],\n skip: true,\n types: []\n },\n update: {\n adapterArgs (mapper, id, props, opts) {\n return [id, mapper.toJSON(props, opts), opts]\n },\n beforeAssign: 1,\n defaults: [undefined, {}, {}],\n types: []\n },\n updateAll: {\n adapterArgs (mapper, props, query, opts) {\n return [mapper.toJSON(props, opts), query, opts]\n },\n beforeAssign: 0,\n defaults: [{}, {}, {}],\n types: []\n },\n updateMany: {\n adapterArgs (mapper, records, opts) {\n return [records.map((record) => mapper.toJSON(record, opts)), opts]\n },\n beforeAssign: 0,\n defaults: [[], {}],\n types: []\n }\n}\n\nconst MAPPER_DEFAULTS = {\n /**\n * Hash of registered adapters. Don't modify directly. Use\n * {@link Mapper#registerAdapter} instead.\n *\n * @default {}\n * @name Mapper#_adapters\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n _adapters: {},\n\n /**\n * Whether {@link Mapper#beforeCreate} and {@link Mapper#beforeCreateMany}\n * should automatically receive default values according to the Mapper's schema.\n *\n * @default true\n * @name Mapper#applyDefaults\n * @since 3.0.0\n * @type {boolean}\n */\n applyDefaults: true,\n\n /**\n * Whether to augment {@link Mapper#recordClass} with ES5 getters and setters\n * according to the properties defined in {@link Mapper#schema}. This makes\n * possible validation and change tracking on individual properties\n * when using the dot (e.g. `user.name = \"Bob\"`) operator to modify a\n * property, and is `true` by default.\n *\n * @default true\n * @name Mapper#applySchema\n * @since 3.0.0\n * @type {boolean}\n */\n applySchema: true,\n\n /**\n * The name of the registered adapter that this Mapper should used by default.\n *\n * @default \"http\"\n * @name Mapper#defaultAdapter\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n * @type {string}\n */\n defaultAdapter: 'http',\n\n /**\n * The field used as the unique identifier on records handled by this Mapper.\n *\n * @default id\n * @name Mapper#idAttribute\n * @since 3.0.0\n * @type {string}\n */\n idAttribute: 'id',\n\n /**\n * Whether records created from this mapper keep changeHistory on property changes.\n *\n * @default true\n * @name Mapper#keepChangeHistory\n * @since 3.0.0\n * @type {boolean}\n */\n keepChangeHistory: true,\n\n /**\n * Whether this Mapper should emit operational events.\n *\n * @default true\n * @name Mapper#notify\n * @since 3.0.0\n * @type {boolean}\n */\n notify: true,\n\n /**\n * Whether to skip validation when the Record instances are created.\n *\n * @default false\n * @name Mapper#noValidate\n * @since 3.0.0\n * @type {boolean}\n */\n noValidate: false,\n\n /**\n * Whether {@link Mapper#create}, {@link Mapper#createMany},\n * {@link Mapper#update}, {@link Mapper#updateAll}, {@link Mapper#updateMany},\n * {@link Mapper#find}, {@link Mapper#findAll}, {@link Mapper#destroy},\n * {@link Mapper#destroyAll}, {@link Mapper#count}, and {@link Mapper#sum}\n * should return a raw result object that contains both the instance data\n * returned by the adapter _and_ metadata about the operation.\n *\n * The default is to NOT return the result object, and instead return just the\n * instance data.\n *\n * @default false\n * @name Mapper#raw\n * @since 3.0.0\n * @type {boolean}\n */\n raw: false,\n\n /**\n * Whether records created from this mapper automatically validate their properties\n * when their properties are modified.\n *\n * @default true\n * @name Mapper#validateOnSet\n * @since 3.0.0\n * @type {boolean}\n */\n validateOnSet: true\n}\n\n/**\n * The core of JSData's [ORM/ODM][orm] implementation. Given a minimum amout of\n * meta information about a resource, a Mapper can perform generic CRUD\n * operations against that resource. Apart from its configuration, a Mapper is\n * stateless. The particulars of various persistence layers have been abstracted\n * into adapters, which a Mapper uses to perform its operations.\n *\n * The term \"Mapper\" comes from the [Data Mapper Pattern][pattern] described in\n * Martin Fowler's [Patterns of Enterprise Application Architecture][book]. A\n * Data Mapper moves data between [in-memory object instances][record] and a\n * relational or document-based database. JSData's Mapper can work with any\n * persistence layer you can write an adapter for.\n *\n * _(\"Model\" is a heavily overloaded term and is avoided in this documentation\n * to prevent confusion.)_\n *\n * [orm]: https://en.wikipedia.org/wiki/Object-relational_mapping\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\n *\n * @example\n * // Import and instantiate\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @example\n * // Define a Mapper using the Container component\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @class Mapper\n * @extends Component\n * @param {Object} opts Configuration options.\n * @param {boolean} [opts.applySchema=true] See {@link Mapper#applySchema}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {string} [opts.defaultAdapter=http] See {@link Mapper#defaultAdapter}.\n * @param {string} [opts.idAttribute=id] See {@link Mapper#idAttribute}.\n * @param {Object} [opts.methods] See {@link Mapper#methods}.\n * @param {string} opts.name See {@link Mapper#name}.\n * @param {boolean} [opts.notify] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw=false] See {@link Mapper#raw}.\n * @param {Function|boolean} [opts.recordClass] See {@link Mapper#recordClass}.\n * @param {Object|Schema} [opts.schema] See {@link Mapper#schema}.\n * @returns {Mapper} A new {@link Mapper} instance.\n * @see http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n */\nfunction Mapper (opts) {\n utils.classCallCheck(this, Mapper)\n Component.call(this)\n opts || (opts = {})\n\n // Prepare certain properties to be non-enumerable\n Object.defineProperties(this, {\n _adapters: {\n value: undefined,\n writable: true\n },\n\n /**\n * The {@link Container} that holds this Mapper. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n datastore: {\n value: undefined,\n writable: true\n },\n\n /**\n * The meta information describing this Mapper's available lifecycle\n * methods. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n lifecycleMethods: {\n value: LIFECYCLE_METHODS\n },\n\n /**\n * Set to `false` to force the Mapper to work with POJO objects only.\n *\n * @example\n * // Use POJOs only.\n * import {Mapper, Record} from 'js-data'\n * const UserMapper = new Mapper({ recordClass: false })\n * UserMapper.recordClass // false\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n *\n * @example\n * // Set to a custom class to have records wrapped in your custom class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User {\n * constructor (props = {}) {\n * for (var key in props) {\n * if (props.hasOwnProperty(key)) {\n * this[key] = props[key]\n * }\n * }\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n * user instanceof User // true\n *\n *\n * @example\n * // Extend the {@link Record} class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User extends Record {\n * constructor () {\n * super(props)\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // true\n * user instanceof User // true\n *\n * @name Mapper#recordClass\n * @default {@link Record}\n * @see Record\n * @since 3.0.0\n */\n recordClass: {\n value: undefined,\n writable: true\n },\n\n /**\n * This Mapper's {@link Schema}.\n *\n * @example Mapper#schema\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const UserMapper = new Mapper({\n * name: 'user',\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * first: { type: 'string', track: true },\n * last: { type: 'string', track: true },\n * role: { type: 'string', track: true, required: true },\n * age: { type: 'integer', track: true },\n * is_active: { type: 'number' }\n * }\n * }\n * })\n * const user = UserMapper.createRecord({\n * id: 1,\n * name: 'John',\n * role: 'admin'\n * })\n * user.on('change', function (user, changes) {\n * console.log(changes)\n * })\n * user.on('change:role', function (user, value) {\n * console.log('change:role - ' + value)\n * })\n * user.role = 'owner'\n *\n * @name Mapper#schema\n * @see Schema\n * @since 3.0.0\n * @type {Schema}\n */\n schema: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(MAPPER_DEFAULTS))\n\n /**\n * The name for this Mapper. This is the minimum amount of meta information\n * required for a Mapper to be able to execute CRUD operations for a\n * Resource.\n *\n * @name Mapper#name\n * @since 3.0.0\n * @type {string}\n */\n if (!this.name) {\n throw utils.err(`new ${DOMAIN}`, 'opts.name')(400, 'string', this.name)\n }\n\n // Setup schema, with an empty default schema if necessary\n if (this.schema) {\n this.schema.type || (this.schema.type = 'object')\n }\n if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\n\n // Create a subclass of Record that's tied to this Mapper\n if (this.recordClass === undefined) {\n const superClass = Record\n this.recordClass = superClass.extend({\n constructor: (function Record () {\n var subClass = function Record (props, opts) {\n utils.classCallCheck(this, subClass)\n superClass.call(this, props, opts)\n }\n return subClass\n })()\n })\n }\n\n if (this.recordClass) {\n this.recordClass.mapper = this\n\n /**\n * Functions that should be added to the prototype of {@link Mapper#recordClass}.\n *\n * @name Mapper#methods\n * @since 3.0.0\n * @type {Object}\n */\n if (utils.isObject(this.methods)) {\n utils.addHiddenPropsToTarget(this.recordClass.prototype, this.methods)\n }\n\n // We can only apply the schema to the prototype of this.recordClass if the\n // class extends Record\n if (Record.prototype.isPrototypeOf(Object.create(this.recordClass.prototype)) && this.schema && this.schema.apply && this.applySchema) {\n this.schema.apply(this.recordClass.prototype)\n }\n }\n}\n\nexport default Component.extend({\n constructor: Mapper,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCount: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroy: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroyAll\n * @param {*} data The `data` returned by the adapter.\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroyAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFind: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFindAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterSum\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterSum: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @since 3.0.0\n */\n beforeCreate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @since 3.0.0\n */\n beforeCreateMany: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @since 3.0.0\n */\n beforeCount: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @since 3.0.0\n */\n beforeDestroy: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroyAll\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @since 3.0.0\n */\n beforeDestroyAll: notify,\n\n /**\n * Mappers lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @since 3.0.0\n */\n beforeFind: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @since 3.0.0\n */\n beforeFindAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeSum\n * @param {string} field The `field` argument passed to {@link Mapper#sum}.\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @since 3.0.0\n */\n beforeSum: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @since 3.0.0\n */\n beforeUpdate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @since 3.0.0\n */\n beforeUpdateAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @since 3.0.0\n */\n beforeUpdateMany: notify,\n\n /**\n * This method is called at the end of most lifecycle methods. It does the\n * following:\n *\n * 1. If `opts.raw` is `true`, add this Mapper's configuration to the `opts`\n * argument as metadata for the operation.\n * 2. Wrap the result data appropriately using {@link Mapper#wrap}, which\n * calls {@link Mapper#createRecord}.\n *\n * @method Mapper#_end\n * @private\n * @since 3.0.0\n */\n _end (result, opts, skip) {\n if (opts.raw) {\n utils._(result, opts)\n }\n if (skip) {\n return result\n }\n let _data = opts.raw ? result.data : result\n if (_data && utils.isFunction(this.wrap)) {\n _data = this.wrap(_data, opts)\n if (opts.raw) {\n result.data = _data\n } else {\n result = _data\n }\n }\n return result\n },\n\n /**\n * Define a belongsTo relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * PostMapper.belongsTo(UserMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to post records at \"post.user\"\n * localField: 'user'\n * })\n *\n * CommentMapper.belongsTo(UserMapper, {\n * // comment.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to comment records at \"comment.user\"\n * localField: 'user'\n * })\n * CommentMapper.belongsTo(PostMapper, {\n * // comment.post_id points to post.id\n * foreignKey: 'post_id'\n * // post records will be attached to comment records at \"comment.post\"\n * localField: 'post'\n * })\n *\n * @method Mapper#belongsTo\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n belongsTo (relatedMapper, opts) {\n return belongsTo(relatedMapper, opts)(this)\n },\n\n /**\n * Select records according to the `query` argument and return the count.\n *\n * {@link Mapper#beforeCount} will be called before calling the adapter.\n * {@link Mapper#afterCount} will be called after calling the adapter.\n *\n * @example\n * // Get the number of published blog posts\n * PostMapper.count({ status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Mapper#count\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `count` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the count of the selected records.\n * @since 3.0.0\n */\n count (query, opts) {\n return this.crud('count', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~beforeCreateListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreate\n * @see Mapper~beforeCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Mapper~beforeCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeCreate}.\n * @see Mapper#event:beforeCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~afterCreateListener} for how to listen for this event.\n *\n * @event Mapper#afterCreate\n * @see Mapper~afterCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Mapper~afterCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterCreate}.\n * @see Mapper#event:afterCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Create and save a new the record using the provided `props`.\n *\n * {@link Mapper#beforeCreate} will be called before calling the adapter.\n * {@link Mapper#afterCreate} will be called after calling the adapter.\n *\n * @example\n * // Create and save a new blog post\n * PostMapper.create({\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#create\n * @param {Object} props The properties for the new record.\n * @param {Object} [opts] Configuration options. Refer to the `create` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `props` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#create}\n * or {@link Mapper#createMany} call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created record.\n * @since 3.0.0\n */\n create (props, opts) {\n let op, adapter\n // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n const originalRecord = props\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return utils.resolve(this[op](props, opts)).then((_props) => {\n // Allow for re-assignment from lifecycle hook\n props = _props === undefined ? props : _props\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n const relatedMapper = def.getRelation()\n const relatedIdAttribute = relatedMapper.idAttribute\n optsCopy.raw = false\n if (!relationData) {\n return\n }\n if (def.type === belongsToType) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(relatedMapper.create(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n def.setForeignKey(props, data)\n }))\n } else if (def.type === hasManyType && def.localKeys) {\n // Create his hasMany relation first because it uses localKeys\n tasks.push(relatedMapper.createMany(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n utils.set(props, def.localKeys, data.map((record) => utils.get(record, relatedIdAttribute)))\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter for the main create\n op = opts.op = 'create'\n this.dbg(op, props, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, this.toJSON(props, { with: opts.pass || [] }), opts))\n }).then((result) => {\n const createdRecordData = opts.raw ? result.data : result\n\n // Deep post-create hasMany and hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n if (!relationData) {\n return\n }\n optsCopy.raw = false\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType && def.foreignKey) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === hasOneType) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().create(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === belongsToType && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n } else if (def.type === hasManyType && def.localKeys && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n if (opts.raw) {\n result.data = originalRecord\n } else {\n result = originalRecord\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return utils.resolve(this[op](props, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Use {@link Mapper#createRecord} instead.\n * @deprecated\n * @method Mapper#createInstance\n * @param {Object|Array} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Object|Array} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n createInstance (props, opts) {\n return this.createRecord(props, opts)\n },\n\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreateMany\n * @see Mapper~beforeCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Mapper~beforeCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Mapper#event:beforeCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~afterCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterCreateMany\n * @see Mapper~afterCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Mapper~afterCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Mapper#event:afterCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Given an array of records, batch create them via an adapter.\n *\n * {@link Mapper#beforeCreateMany} will be called before calling the adapter.\n * {@link Mapper#afterCreateMany} will be called after calling the adapter.\n *\n * @example\n * // Create and save several new blog posts\n * PostMapper.createMany([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#createMany\n * @param {Record[]} records Array of records to be created in one batch.\n * @param {Object} [opts] Configuration options. Refer to the `createMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `records` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#createMany}\n * call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created records.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n createMany (records, opts) {\n let op, adapter\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n const originalRecords = records\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return utils.resolve(this[op](records, opts)).then((_records) => {\n // Allow for re-assignment from lifecycle hook\n records = _records === undefined ? records : _records\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (def.type === belongsToType && relationData.length === records.length) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(def.getRelation().createMany(relationData, optsCopy).then((data) => {\n const relatedRecords = optsCopy.raw ? data.data : data\n def.setLocalField(belongsToRelationData, relatedRecords)\n records.forEach((record, i) => {\n def.setForeignKey(record, relatedRecords[i])\n })\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'createMany'\n const json = records.map((record) => this.toJSON(record, { with: opts.pass || [] }))\n this.dbg(op, records, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, json, opts))\n }).then((result) => {\n const createdRecordsData = opts.raw ? result.data : result\n\n // Deep post-create hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (relationData.length !== records.length) {\n return\n }\n const belongsToData = def.getLocalField(belongsToRelationData)\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType) {\n // Not supported\n this.log('warn', 'deep createMany of hasMany type not supported!')\n } else if (def.type === hasOneType) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setForeignKey(createdRecordData, relationData[i])\n })\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n const relatedData = opts.raw ? result.data : result\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, relatedData[i])\n })\n })\n } else if (def.type === belongsToType && belongsToData && belongsToData.length === createdRecordsData.length) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, belongsToData[i])\n })\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n createdRecordsData.forEach((createdRecordData, i) => {\n const originalRecord = originalRecords[i]\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n })\n if (opts.raw) {\n result.data = originalRecords\n } else {\n result = originalRecords\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return utils.resolve(this[op](records, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Create an unsaved, uncached instance of this Mapper's\n * {@link Mapper#recordClass}.\n *\n * Returns `props` if `props` is already an instance of\n * {@link Mapper#recordClass}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * const post = PostMapper.createRecord()\n *\n * @example\n * // Create an unsaved record instance with inital properties\n * const post = PostMapper.createRecord({\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create a record instance that corresponds to a saved record\n * const post = PostMapper.createRecord({\n * // JSData thinks this record has been saved if it has a primary key\n * id: 1234,\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create record instances from an array\n * const posts = PostMapper.createRecord([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }])\n *\n * @example\n * // Records are validated by default\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * try {\n * const post = PostMapper.createRecord({\n * title: 1234,\n * })\n * } catch (err) {\n * console.log(err.errors) // [{ expected: 'one of (string)', actual: 'number', path: 'title' }]\n * }\n *\n * @example\n * // Skip validation\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * const post = PostMapper.createRecord({\n * title: 1234,\n * }, { noValidate: true })\n * console.log(post.isValid()) // false\n *\n * @method Mapper#createRecord\n * @param {Object|Object[]} props The properties for the Record instance or an\n * array of property objects for the Record instances.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @returns {Record|Record[]} The Record instance or Record instances.\n * @since 3.0.0\n */\n createRecord (props, opts) {\n props || (props = {})\n if (utils.isArray(props)) {\n return props.map((_props) => this.createRecord(_props, opts))\n }\n if (!utils.isObject(props)) {\n throw utils.err(`${DOMAIN}#createRecord`, 'props')(400, 'array or object', props)\n }\n const RecordCtor = this.recordClass\n const relationList = this.relationList || []\n relationList.forEach((def) => {\n const relatedMapper = def.getRelation()\n const relationData = def.getLocalField(props)\n if (relationData && !relatedMapper.is(relationData)) {\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n utils.set(props, def.localField, relatedMapper.createRecord(relationData, opts))\n }\n })\n // Check to make sure \"props\" is not already an instance of this Mapper.\n if (RecordCtor && (!(props instanceof RecordCtor))) {\n return new RecordCtor(props, opts)\n }\n return props\n },\n\n /**\n * Lifecycle invocation method. You probably won't call this method directly.\n *\n * @method Mapper#crud\n * @param {string} method Name of the lifecycle method to invoke.\n * @param {...*} args Arguments to pass to the lifecycle method.\n * @returns {Promise}\n * @since 3.0.0\n */\n crud (method, ...args) {\n const config = this.lifecycleMethods[method]\n if (!config) {\n throw utils.err(`${DOMAIN}#crud`, method)(404, 'method')\n }\n\n const upper = `${method.charAt(0).toUpperCase()}${method.substr(1)}`\n const before = `before${upper}`\n const after = `after${upper}`\n\n let op, adapter\n\n // Default values for arguments\n config.defaults.forEach((value, i) => {\n if (args[i] === undefined) {\n args[i] = utils.copy(value)\n }\n })\n\n const opts = args[args.length - 1]\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // before lifecycle hook\n op = opts.op = before\n return utils.resolve(this[op](...args)).then((_value) => {\n if (args[config.beforeAssign] !== undefined) {\n // Allow for re-assignment from lifecycle hook\n args[config.beforeAssign] = _value === undefined ? args[config.beforeAssign] : _value\n }\n // Now delegate to the adapter\n op = opts.op = method\n args = config.adapterArgs ? config.adapterArgs(this, ...args) : args\n this.dbg(op, ...args)\n return utils.resolve(this.getAdapter(adapter)[op](this, ...args))\n }).then((result) => {\n result = this._end(result, opts, !!config.skip)\n args.push(result)\n // after lifecycle hook\n op = opts.op = after\n return utils.resolve(this[op](...args)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~beforeDestroyListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroy\n * @see Mapper~beforeDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Mapper~beforeDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroy}.\n * @see Mapper#event:beforeDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~afterDestroyListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroy\n * @see Mapper~afterDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Mapper~afterDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroy}.\n * @see Mapper#event:afterDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Using an adapter, destroy the record with the given primary key.\n *\n * {@link Mapper#beforeDestroy} will be called before destroying the record.\n * {@link Mapper#afterDestroy} will be called after destroying the record.\n *\n * @example\n * // Destroy a specific blog post\n * PostMapper.destroy(1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @example\n * // Get full response\n * PostMapper.destroy(1234, { raw: true }).then((result) => {\n * console.log(result.deleted) e.g. 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroy\n * @fires Mapper#afterDestroy\n * @method Mapper#destroy\n * @param {(string|number)} id The primary key of the record to destroy.\n * @param {Object} [opts] Configuration options. Refer to the `destroy` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the record has been destroyed. Resolves\n * even if no record was found to be destroyed.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroy (id, opts) {\n return this.crud('destroy', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroyAll\n * @see Mapper~beforeDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Mapper~beforeDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroyAll}.\n * @see Mapper#event:beforeDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroyAll\n * @see Mapper~afterDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Mapper~afterDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroyAll}.\n * @see Mapper#event:afterDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Destroy the records selected by `query` via an adapter. If no `query` is\n * provided then all records will be destroyed.\n *\n * {@link Mapper#beforeDestroyAll} will be called before destroying the records.\n * {@link Mapper#afterDestroyAll} will be called after destroying the records.\n *\n * @example\n * // Destroy all blog posts\n * PostMapper.destroyAll().then(() => {\n * // All blog posts have been destroyed\n * })\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * PostMapper.destroyAll({ status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @example\n * // Get full response\n * const query = null\n * const options = { raw: true }\n * PostMapper.destroyAll(query, options).then((result) => {\n * console.log(result.deleted) e.g. 14\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroyAll\n * @fires Mapper#afterDestroyAll\n * @method Mapper#destroyAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `destroyAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the records have been destroyed. Resolves\n * even if no records were found to be destroyed.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroyAll (query, opts) {\n return this.crud('destroyAll', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~beforeFindListener} for how to listen for this event.\n *\n * @event Mapper#beforeFind\n * @see Mapper~beforeFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Mapper~beforeFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFind}.\n * @see Mapper#event:beforeFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~afterFindListener} for how to listen for this event.\n *\n * @event Mapper#afterFind\n * @see Mapper~afterFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFind} event.\n *\n * @example\n * function onAfterFind (id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Mapper~afterFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFind}.\n * @see Mapper#event:afterFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Retrieve via an adapter the record with the given primary key.\n *\n * {@link Mapper#beforeFind} will be called before calling the adapter.\n * {@link Mapper#afterFind} will be called after calling the adapter.\n *\n * @example\n * PostMapper.find(1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @example\n * // Get full response\n * PostMapper.find(1, { raw: true }).then((result) => {\n * console.log(result.data) // { id: 1, ...}\n * console.log(result.found) // 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFind\n * @fires Mapper#afterFind\n * @method Mapper#find\n * @param {(string|number)} id The primary key of the record to retrieve.\n * @param {Object} [opts] Configuration options. Refer to the `find` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found record. Resolves with\n * `undefined` if no record was found.\n * @see http://www.js-data.io/v3.0/docs/reading-data\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n find (id, opts) {\n return this.crud('find', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~beforeFindAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeFindAll\n * @see Mapper~beforeFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Mapper~beforeFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFindAll}.\n * @see Mapper#event:beforeFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~afterFindAllListener} for how to listen for this event.\n *\n * @event Mapper#afterFindAll\n * @see Mapper~afterFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Mapper~afterFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFindAll}.\n * @see Mapper#event:afterFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, select records to retrieve via an adapter.\n *\n * {@link Mapper#beforeFindAll} will be called before calling the adapter.\n * {@link Mapper#afterFindAll} will be called after calling the adapter.\n *\n * @example\n * // Find all \"published\" blog posts\n * PostMapper.findAll({ status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, status: 'published', ...}, ...]\n * })\n *\n * @example\n * // Get full response\n * PostMapper.findAll({ status: 'published' }, { raw: true }).then((result) => {\n * console.log(result.data) // [{ id: 1, status: 'published', ...}, ...]\n * console.log(result.found) // e.g. 13\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFindAll\n * @fires Mapper#afterFindAll\n * @method Mapper#findAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `findAll` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n findAll (query, opts) {\n return this.crud('findAll', query, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Mapper#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapter (name) {\n this.dbg('getAdapter', 'name:', name)\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Mapper#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || opts.defaultAdapter\n },\n\n /**\n * Get the object of registered adapters for this Mapper.\n *\n * @method Mapper#getAdapters\n * @returns {Object} {@link Mapper#_adapters}\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Returns this Mapper's {@link Schema}.\n *\n * @method Mapper#getSchema\n * @returns {Schema} This Mapper's {@link Schema}.\n * @see Mapper#schema\n * @since 3.0.0\n */\n getSchema () {\n return this.schema\n },\n\n /**\n * Defines a hasMany relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * UserMapper.hasMany(PostMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // post records will be attached to user records at \"user.posts\"\n * localField: 'posts'\n * })\n *\n * @method Mapper#hasMany\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasMany (relatedMapper, opts) {\n return hasMany(relatedMapper, opts)(this)\n },\n\n /**\n * Defines a hasOne relationship. Only useful if you're managing your Mappers\n * manually and not using a {@link Container} or {@link DataStore} component.\n *\n * @example\n * UserMapper.hasOne(ProfileMapper, {\n * // profile.user_id points to user.id\n * foreignKey: 'user_id'\n * // profile records will be attached to user records at \"user.profile\"\n * localField: 'profile'\n * })\n *\n * @method Mapper#hasOne\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasOne (relatedMapper, opts) {\n return hasOne(relatedMapper, opts)(this)\n },\n\n /**\n * Return whether `record` is an instance of this Mapper's recordClass.\n *\n * @example\n * const post = PostMapper.createRecord()\n *\n * console.log(PostMapper.is(post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof PostMapper.recordClass) // true\n *\n * @method Mapper#is\n * @param {Object|Record} record The record to check.\n * @returns {boolean} Whether `record` is an instance of this Mapper's\n * {@link Mapper#recordClass}.\n * @since 3.0.0\n */\n is (record) {\n const recordClass = this.recordClass\n return recordClass ? record instanceof recordClass : false\n },\n\n /**\n * Register an adapter on this Mapper under the given name.\n *\n * @method Mapper#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for this Mapper.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.defaultAdapter = name\n }\n },\n\n /**\n * Select records according to the `query` argument, and aggregate the sum\n * value of the property specified by `field`.\n *\n * {@link Mapper#beforeSum} will be called before calling the adapter.\n * {@link Mapper#afterSum} will be called after calling the adapter.\n *\n * @example\n * PurchaseOrderMapper.sum('amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Mapper#sum\n * @param {string} field The field to sum.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `sum` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the aggregated sum.\n * @since 3.0.0\n */\n sum (field, query, opts) {\n return this.crud('sum', field, query, opts)\n },\n\n /**\n * Return a plain object representation of the given record. Relations can\n * be optionally be included. Non-schema properties can be excluded.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = PersonMapper.createRecord({ id: 1, name: 'John', foo: 'bar' })\n * console.log(PersonMapper.toJSON(person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(PersonMapper.toJSON(person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Mapper#toJSON\n * @param {Record|Record[]} records Record or records from which to create a\n * POJO representation.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the POJO representation.\n * @param {boolean} [opts.withAll] Whether to simply include all relations in\n * the representation. Overrides `opts.with`.\n * @returns {Object|Object[]} POJO representation of the record or records.\n * @since 3.0.0\n */\n toJSON (records, opts) {\n let record\n opts || (opts = {})\n if (utils.isArray(records)) {\n return records.map((record) => this.toJSON(record, opts))\n } else {\n record = records\n }\n const relationFields = (this ? this.relationFields : []) || []\n let json = {}\n let properties\n\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n properties = this.schema.properties\n }\n properties || (properties = {})\n\n // Optionally copy properties not defined in the schema\n if (!opts.strict) {\n for (var key in record) {\n if (!properties[key] && relationFields.indexOf(key) === -1) {\n json[key] = utils.plainCopy(record[key])\n }\n }\n }\n\n // The user wants to include relations in the resulting plain object representation\n if (this && opts.withAll) {\n opts.with = relationFields.slice()\n }\n if (this && opts.with) {\n if (utils.isString(opts.with)) {\n opts.with = [opts.with]\n }\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(record)\n if (relationData) {\n // The actual recursion\n if (utils.isArray(relationData)) {\n def.setLocalField(json, relationData.map((item) => {\n return def.getRelation().toJSON(item, optsCopy)\n }))\n } else {\n def.setLocalField(json, def.getRelation().toJSON(relationData, optsCopy))\n }\n }\n })\n }\n return json\n },\n\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~beforeUpdateListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdate\n * @see Mapper~beforeUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Mapper~beforeUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeUpdate}.\n * @see Mapper#event:beforeUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~afterUpdateListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdate\n * @see Mapper~afterUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Mapper~afterUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterUpdate}.\n * @see Mapper#event:afterUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Using an adapter, update the record with the primary key specified by the\n * `id` argument.\n *\n * {@link Mapper#beforeUpdate} will be called before updating the record.\n * {@link Mapper#afterUpdate} will be called after updating the record.\n *\n * @example\n * // Update a specific post\n * PostMapper.update(1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Mapper#beforeUpdate\n * @fires Mapper#afterUpdate\n * @method Mapper#update\n * @param {(string|number)} id The primary key of the record to update.\n * @param {Object} props The update to apply to the record.\n * @param {Object} [opts] Configuration options. Refer to the `update` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * transaction.\n * @returns {Promise} Resolves with the updated record. Rejects if the record\n * could not be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n update (id, props, opts) {\n return this.crud('update', id, props, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateAll\n * @see Mapper~beforeUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Mapper~beforeUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Mapper#event:beforeUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateAll\n * @see Mapper~afterUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Mapper~afterUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Mapper#event:afterUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, perform the a single updated to the selected\n * records.\n *\n * {@link Mapper#beforeUpdateAll} will be called before making the update.\n * {@link Mapper#afterUpdateAll} will be called after making the update.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * PostMapper.updateAll(update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateAll\n * @fires Mapper#afterUpdateAll\n * @method Mapper#updateAll\n * @param {Object} props Update to apply to selected records.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `updateAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the update records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateAll (props, query, opts) {\n return this.crud('updateAll', props, query, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateMany\n * @see Mapper~beforeUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Mapper~beforeUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Mapper#event:beforeUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateMany\n * @see Mapper~afterUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Mapper~afterUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Mapper#event:afterUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Given an array of updates, perform each of the updates via an adapter. Each\n * \"update\" is a hash of properties with which to update an record. Each\n * update must contain the primary key of the record to be updated.\n *\n * {@link Mapper#beforeUpdateMany} will be called before making the update.\n * {@link Mapper#afterUpdateMany} will be called after making the update.\n *\n * @example\n * PostMapper.updateMany([\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateMany\n * @fires Mapper#afterUpdateMany\n * @method Mapper#updateMany\n * @param {Record[]} records Array up record updates.\n * @param {Object} [opts] Configuration options. Refer to the `updateMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the updated records. Rejects if any of the\n * records could be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateMany (records, opts) {\n return this.crud('updateMany', records, opts)\n },\n\n /**\n * Validate the given record or records according to this Mapper's\n * {@link Schema}. If there are no validation errors then the return value\n * will be `undefined`.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonSchema = new Schema({\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * })\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: PersonSchema\n * })\n * let errors = PersonMapper.validate({ name: 'John' })\n * console.log(errors) // undefined\n * errors = PersonMapper.validate({ name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Mapper#validate\n * @param {Object|Object[]} record The record or records to validate.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Schema#validate}.\n * @returns {Object[]} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (record, opts) {\n opts || (opts = {})\n const schema = this.getSchema()\n const _opts = utils.pick(opts, ['existingOnly'])\n if (utils.isArray(record)) {\n const errors = record.map((_record) => schema.validate(_record, utils.pick(_opts, ['existingOnly'])))\n const foundErrors = errors.filter((err) => err)\n if (foundErrors.length) {\n return errors\n }\n return undefined\n }\n return schema.validate(record, _opts)\n },\n\n /**\n * Method used to wrap data returned by an adapter with this Mapper's\n * {@link Mapper#recordClass}. This method is used by all of a Mapper's CRUD\n * methods. The provided implementation of this method assumes that the `data`\n * passed to it is a record or records that need to be wrapped with\n * {@link Mapper#createRecord}. Override with care.\n *\n * Provided implementation of {@link Mapper#wrap}:\n *\n * ```\n * function (data, opts) {\n * return this.createRecord(data, opts)\n * }\n * ```\n *\n * @example\n * const PostMapper = new Mapper({\n * name: 'post',\n * // Override to customize behavior\n * wrap (data, opts) {\n * const originalWrap = this.constructor.prototype.wrap\n * // Let's say \"GET /post\" doesn't return JSON quite like JSData expects,\n * // but the actual post records are nested under a \"posts\" field. So,\n * // we override Mapper#wrap to handle this special case.\n * if (opts.op === 'findAll') {\n * return originalWrap.call(this, data.posts, opts)\n * }\n * // Otherwise perform original behavior\n * return originalWrap.call(this, data, opts)\n * }\n * })\n *\n * @method Mapper#wrap\n * @param {Object|Object[]} data The record or records to be wrapped.\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#createRecord}.\n * @returns {Record|Record[]} The wrapped record or records.\n * @since 3.0.0\n */\n wrap (data, opts) {\n return this.createRecord(data, opts)\n },\n\n /**\n * @ignore\n */\n defineRelations () {\n // Setup the mapper's relations, including generating Mapper#relationList\n // and Mapper#relationFields\n utils.forOwn(this.relations, (group, type) => {\n utils.forOwn(group, (relations, _name) => {\n if (utils.isObject(relations)) {\n relations = [relations]\n }\n relations.forEach((def) => {\n const relatedMapper = this.datastore.getMapperByName(_name) || _name\n def.getRelation = () => this.datastore.getMapper(_name)\n\n if (typeof Relation[type] !== 'function') {\n throw utils.err(DOMAIN, 'defineRelations')(400, 'relation type (hasOne, hasMany, etc)', type, true)\n }\n\n this[type](relatedMapper, def)\n })\n })\n })\n }\n})\n\n/**\n * Create a subclass of this Mapper:\n *\n * @example Mapper.extend\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomMapperClass extends Mapper {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customMapper = new CustomMapperClass()\n * console.log(customMapper.foo())\n * console.log(CustomMapperClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherMapperClass = Mapper.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherMapper = new OtherMapperClass()\n * console.log(otherMapper.foo())\n * console.log(OtherMapperClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherMapperClass () {\n * Mapper.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Mapper.extend({\n * constructor: AnotherMapperClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherMapper = new AnotherMapperClass()\n * console.log(anotherMapper.created_at)\n * console.log(anotherMapper.foo())\n * console.log(AnotherMapperClass.beep())\n *\n * @method Mapper.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Mapper class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\nimport Mapper from './Mapper'\n\nconst DOMAIN = 'Container'\n\nexport const proxiedMapperMethods = [\n /**\n * Wrapper for {@link Mapper#count}.\n *\n * @example\n * // Get the number of published blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.count('post', { status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Container#count\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#count}.\n * @param {Object} [opts] See {@link Mapper#count}.\n * @returns {Promise} See {@link Mapper#count}.\n * @see Mapper#count\n * @since 3.0.0\n */\n 'count',\n\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~beforeCreateListener} for how to listen for this event.\n *\n * @event Container#beforeCreate\n * @see Container~beforeCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Container~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see Container#event:beforeCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~afterCreateListener} for how to listen for this event.\n *\n * @event Container#afterCreate\n * @see Container~afterCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Container~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see Container#event:afterCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}.\n *\n * @example\n * // Create and save a new blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.create('post', {\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreate\n * @fires Container#afterCreate\n * @method Container#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props See {@link Mapper#create}.\n * @param {Object} [opts] See {@link Mapper#create}.\n * @returns {Promise} See {@link Mapper#create}.\n * @see Mapper#create\n * @since 3.0.0\n */\n 'create',\n\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Container#beforeCreateMany\n * @see Container~beforeCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Container~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Container#event:beforeCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~afterCreateManyListener} for how to listen for this event.\n *\n * @event Container#afterCreateMany\n * @see Container~afterCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Container~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Container#event:afterCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}.\n *\n * @example\n * // Create and save several new blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.createMany('post', [{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreateMany\n * @fires Container#afterCreateMany\n * @method Container#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record[]} records See {@link Mapper#createMany}.\n * @param {Object} [opts] See {@link Mapper#createMany}.\n * @returns {Promise} See {@link Mapper#createMany}.\n * @see Mapper#createMany\n * @since 3.0.0\n */\n 'createMany',\n\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = PostMapper.createRecord()\n *\n * @method Container#createRecord\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Object[]} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Promise} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n 'createRecord',\n\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~beforeDestroyListener} for how to listen for this event.\n *\n * @event Container#beforeDestroy\n * @see Container~beforeDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Container~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see Container#event:beforeDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~afterDestroyListener} for how to listen for this event.\n *\n * @event Container#afterDestroy\n * @see Container~afterDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Container~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see Container#event:afterDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}.\n *\n * @example\n * // Destroy a specific blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroy('post', 1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @fires Container#beforeDestroy\n * @fires Container#afterDestroy\n * @method Container#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#destroy}.\n * @param {Object} [opts] See {@link Mapper#destroy}.\n * @returns {Promise} See {@link Mapper#destroy}.\n * @see Mapper#destroy\n * @since 3.0.0\n */\n 'destroy',\n\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Container#beforeDestroyAll\n * @see Container~beforeDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Container~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see Container#event:beforeDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Container#afterDestroyAll\n * @see Container~afterDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Container~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see Container#event:afterDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}.\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroyAll('post', { status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @fires Container#beforeDestroyAll\n * @fires Container#afterDestroyAll\n * @method Container#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#destroyAll}.\n * @param {Object} [opts] See {@link Mapper#destroyAll}.\n * @returns {Promise} See {@link Mapper#destroyAll}.\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n 'destroyAll',\n\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~beforeFindListener} for how to listen for this event.\n *\n * @event Container#beforeFind\n * @see Container~beforeFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Container~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see Container#event:beforeFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~afterFindListener} for how to listen for this event.\n *\n * @event Container#afterFind\n * @see Container~afterFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Container~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see Container#event:afterFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.find('post', 1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @fires Container#beforeFind\n * @fires Container#afterFind\n * @method Container#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#find}.\n * @param {Object} [opts] See {@link Mapper#find}.\n * @returns {Promise} See {@link Mapper#find}.\n * @see Mapper#find\n * @since 3.0.0\n */\n 'find',\n\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~beforeFindAllListener} for how to listen for this event.\n *\n * @event Container#beforeFindAll\n * @see Container~beforeFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Container~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see Container#event:beforeFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~afterFindAllListener} for how to listen for this event.\n *\n * @event Container#afterFindAll\n * @see Container~afterFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Container~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see Container#event:afterFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * @example\n * // Find all \"published\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.findAll('post', { status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, ...}, ...]\n * })\n *\n * @fires Container#beforeFindAll\n * @fires Container#afterFindAll\n * @method Container#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#findAll}.\n * @param {Object} [opts] See {@link Mapper#findAll}.\n * @returns {Promise} See {@link Mapper#findAll}.\n * @see Mapper#findAll\n * @since 3.0.0\n */\n 'findAll',\n\n /**\n * Wrapper for {@link Mapper#getSchema}.\n *\n * @method Container#getSchema\n * @param {string} name Name of the {@link Mapper} to target.\n * @returns {Schema} See {@link Mapper#getSchema}.\n * @see Mapper#getSchema\n * @since 3.0.0\n */\n 'getSchema',\n\n /**\n * Wrapper for {@link Mapper#is}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = store.createRecord()\n *\n * console.log(store.is('post', post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof store.getMapper('post').recordClass) // true\n *\n * @method Container#is\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Record} record See {@link Mapper#is}.\n * @returns {boolean} See {@link Mapper#is}.\n * @see Mapper#is\n * @since 3.0.0\n */\n 'is',\n\n /**\n * Wrapper for {@link Mapper#sum}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('purchase_order')\n *\n * store.sum('purchase_order', 'amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Container#sum\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {string} field See {@link Mapper#sum}.\n * @param {Object} [query] See {@link Mapper#sum}.\n * @param {Object} [opts] See {@link Mapper#sum}.\n * @returns {Promise} See {@link Mapper#sum}.\n * @see Mapper#sum\n * @since 3.0.0\n */\n 'sum',\n\n /**\n * Wrapper for {@link Mapper#toJSON}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('person', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = store.createRecord('person', { id: 1, name: 'John', foo: 'bar' })\n * console.log(store.toJSON('person', person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(store.toJSON('person', person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Container#toJSON\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record|Record[]} records See {@link Mapper#toJSON}.\n * @param {Object} [opts] See {@link Mapper#toJSON}.\n * @returns {Object|Object[]} See {@link Mapper#toJSON}.\n * @see Mapper#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~beforeUpdateListener} for how to listen for this event.\n *\n * @event Container#beforeUpdate\n * @see Container~beforeUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Container~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see Container#event:beforeUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~afterUpdateListener} for how to listen for this event.\n *\n * @event Container#afterUpdate\n * @see Container~afterUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Container~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see Container#event:afterUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.update('post', 1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Container#beforeUpdate\n * @fires Container#afterUpdate\n * @method Container#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#update}.\n * @param {Object} record See {@link Mapper#update}.\n * @param {Object} [opts] See {@link Mapper#update}.\n * @returns {Promise} See {@link Mapper#update}.\n * @see Mapper#update\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n 'update',\n\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateAll\n * @see Container~beforeUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Container~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Container#event:beforeUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Container#afterUpdateAll\n * @see Container~afterUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Container~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Container#event:afterUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * store.updateAll('post', update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateAll\n * @fires Container#afterUpdateAll\n * @method Container#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} update See {@link Mapper#updateAll}.\n * @param {Object} [query] See {@link Mapper#updateAll}.\n * @param {Object} [opts] See {@link Mapper#updateAll}.\n * @returns {Promise} See {@link Mapper#updateAll}.\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n 'updateAll',\n\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateMany\n * @see Container~beforeUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Container~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Container#event:beforeUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Container#afterUpdateMany\n * @see Container~afterUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Container~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Container#event:afterUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.updateMany('post', [\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateMany\n * @fires Container#afterUpdateMany\n * @method Container#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#updateMany}.\n * @param {Object} [opts] See {@link Mapper#updateMany}.\n * @returns {Promise} See {@link Mapper#updateMany}.\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n 'updateMany',\n\n /**\n * Wrapper for {@link Mapper#validate}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * let errors = store.validate('post', { name: 'John' })\n * console.log(errors) // undefined\n * errors = store.validate('post', { name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Container#validate\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#validate}.\n * @param {Object} [opts] See {@link Mapper#validate}.\n * @returns {Promise} See {@link Mapper#validate}.\n * @see Mapper#validate\n * @since 3.0.0\n */\n 'validate'\n]\n\n/**\n * The `Container` class is a place to define and store {@link Mapper} instances.\n *\n * `Container` makes it easy to manage your Mappers. Without a container, you\n * need to manage Mappers yourself, including resolving circular dependencies\n * among relations. All Mappers in a container share the same adapters, so you\n * don't have to register adapters for every single Mapper.\n *\n * @example Container#constructor\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n *\n * @class Container\n * @extends Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {Constructor} [opts.mapperClass] See {@link Container#mapperClass}.\n * @param {Object} [opts.mapperDefaults] See {@link Container#mapperDefaults}.\n * @since 3.0.0\n */\nexport function Container (opts) {\n utils.classCallCheck(this, Container)\n Component.call(this)\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * The adapters registered with this Container, which are also shared by all\n * Mappers in this Container.\n *\n * @name Container#_adapters\n * @see Container#registerAdapter\n * @since 3.0.0\n * @type {Object}\n */\n _adapters: {\n value: {}\n },\n\n /**\n * The the mappers in this container\n *\n * @name Container#_mappers\n * @see Mapper\n * @since 3.0.0\n * @type {Object}\n */\n _mappers: {\n value: {}\n },\n\n /**\n * Constructor function to use in {@link Container#defineMapper} to create new\n * {@link Mapper} instances. {@link Container#mapperClass} should extend\n * {@link Mapper}. By default {@link Mapper} is used to instantiate Mappers.\n *\n * @example Container#mapperClass\n * // import {Container, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const store = new Container({\n * mapperClass: MyMapperClass\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').foo())\n *\n * @name Container#mapperClass\n * @see Mapper\n * @since 3.0.0\n * @type {Constructor}\n */\n mapperClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply options provided by the user\n utils.fillIn(this, opts)\n\n /**\n * Defaults options to pass to {@link Container#mapperClass} when creating a\n * new {@link Mapper}.\n *\n * @example Container#mapperDefaults\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: {\n * idAttribute: '_id'\n * }\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').idAttribute)\n *\n * @default {}\n * @name Container#mapperDefaults\n * @since 3.0.0\n * @type {Object}\n */\n this.mapperDefaults = this.mapperDefaults || {}\n\n // Use the Mapper class if the user didn't provide a mapperClass\n this.mapperClass || (this.mapperClass = Mapper)\n}\n\nconst props = {\n constructor: Container,\n\n /**\n * Register a new event listener on this Container.\n *\n * Proxy for {@link Component#on}. If an event was emitted by a {@link Mapper}\n * in the Container, then the name of the {@link Mapper} will be prepended to\n * the arugments passed to the listener.\n *\n * @example Container#on\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.on('foo', function (...args) { console.log(args.join(':')) })\n * store.defineMapper('user')\n * store.emit('foo', 'arg1', 'arg2')\n * store.getMapper('user').emit('foo', 'arg1', 'arg2')\n *\n * @method Container#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n\n /**\n * Used to bind to events emitted by mappers in this container.\n *\n * @method Container#_onMapperEvent\n * @param {string} name Name of the mapper that emitted the event.\n * @param {...*} [args] Args See {@link Mapper#emit}.\n * @private\n * @since 3.0.0\n */\n _onMapperEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * Return a container scoped to a particular mapper.\n *\n * @example Container#as\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method Container#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} A container scoped to a particular mapper.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n proxiedMapperMethods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Create a new mapper and register it in this container.\n *\n * @example Container#defineMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: { foo: 'bar' }\n * })\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(UserMapper.foo)\n *\n * @method Container#defineMapper\n * @param {string} name Name under which to register the new {@link Mapper}.\n * {@link Mapper#name} will be set to this value.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Container#mapperClass} when creating the new {@link Mapper}.\n * @returns {Mapper} The newly created instance of {@link Mapper}.\n * @see Container#as\n * @since 3.0.0\n */\n defineMapper (name, opts) {\n // For backwards compatibility with defineResource\n if (utils.isObject(name)) {\n opts = name\n name = opts.name\n }\n if (!utils.isString(name)) {\n throw utils.err(`${DOMAIN}#defineMapper`, 'name')(400, 'string', name)\n }\n\n // Default values for arguments\n opts || (opts = {})\n // Set Mapper#name\n opts.name = name\n opts.relations || (opts.relations = {})\n\n // Check if the user is overriding the datastore's default mapperClass\n const mapperClass = opts.mapperClass || this.mapperClass\n delete opts.mapperClass\n\n // Apply the datastore's defaults to the options going into the mapper\n utils.fillIn(opts, this.mapperDefaults)\n\n // Instantiate a mapper\n const mapper = this._mappers[name] = new mapperClass(opts) // eslint-disable-line\n mapper.relations || (mapper.relations = {})\n // Make sure the mapper's name is set\n mapper.name = name\n // All mappers in this datastore will share adapters\n mapper._adapters = this.getAdapters()\n\n mapper.datastore = this\n\n mapper.on('all', (...args) => this._onMapperEvent(name, ...args))\n mapper.defineRelations()\n\n return mapper\n },\n\n defineResource (name, opts) {\n console.warn('DEPRECATED: defineResource is deprecated, use defineMapper instead')\n return this.defineMapper(name, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Container#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n */\n getAdapter (name) {\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Container#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || this.mapperDefaults.defaultAdapter\n },\n\n /**\n * Return the registered adapters of this container.\n *\n * @method Container#getAdapters\n * @returns {Adapter}\n * @since 3.0.0\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Return the mapper registered under the specified name.\n *\n * @example Container#getMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * store.getMapper('profile') // throws Error, there is no mapper with name \"profile\"\n *\n * @method Container#getMapper\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapper (name) {\n const mapper = this.getMapperByName(name)\n if (!mapper) {\n throw utils.err(`${DOMAIN}#getMapper`, name)(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Return the mapper registered under the specified name.\n * Doesn't throw error if mapper doesn't exist.\n *\n * @example Container#getMapperByName\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(store.getMapper('profile')) // Does NOT throw an error\n *\n * @method Container#getMapperByName\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapperByName (name) {\n return this._mappers[name]\n },\n\n /**\n * Register an adapter on this container under the given name. Adapters\n * registered on a container are shared by all mappers in the container.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n *\n * @method Container#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for all Mappers in this container.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.mapperDefaults.defaultAdapter = name\n utils.forOwn(this._mappers, function (mapper) {\n mapper.defaultAdapter = name\n })\n }\n }\n}\n\nproxiedMapperMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getMapper(name)[method](...args)\n }\n})\n\nComponent.extend(props)\n\n/**\n * Create a subclass of this Container:\n * @example Container.extend\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomContainerClass extends Container {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customContainer = new CustomContainerClass()\n * console.log(customContainer.foo())\n * console.log(CustomContainerClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherContainerClass = Container.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherContainer = new OtherContainerClass()\n * console.log(otherContainer.foo())\n * console.log(OtherContainerClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherContainerClass () {\n * Container.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Container.extend({\n * constructor: AnotherContainerClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherContainer = new AnotherContainerClass()\n * console.log(anotherContainer.created_at)\n * console.log(anotherContainer.foo())\n * console.log(AnotherContainerClass.beep())\n *\n * @method Container.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Container class.\n * @since 3.0.0\n */\n","import utils, { safeSetLink, safeSetProp } from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport {proxiedMapperMethods, Container} from './Container'\nimport Collection from './Collection'\n\nconst DOMAIN = 'SimpleStore'\nconst proxiedCollectionMethods = [\n /**\n * Wrapper for {@link Collection#add}.\n *\n * @example SimpleStore#add\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n *\n * // Add one book to the in-memory store:\n * store.add('book', { id: 1, title: 'Respect your Data' })\n * // Add multiple books to the in-memory store:\n * store.add('book', [\n * { id: 2, title: 'Easy data recipes' },\n * { id: 3, title: 'Active Record 101' }\n * ])\n *\n * @fires SimpleStore#add\n * @method SimpleStore#add\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Object[]|Record|Record[])} data See {@link Collection#add}.\n * @param {Object} [opts] Configuration options. See {@link Collection#add}.\n * @returns {(Object|Object[]|Record|Record[])} See {@link Collection#add}.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n 'add',\n\n /**\n * Wrapper for {@link Collection#between}.\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = store.between('user', 18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = store.between('user', [18], [30], { index: 'age' })\n *\n * @method SimpleStore#between\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Array} leftKeys See {@link Collection#between}.\n * @param {Array} rightKeys See {@link Collection#between}.\n * @param {Object} [opts] Configuration options. See {@link Collection#between}.\n * @returns {Object[]|Record[]} See {@link Collection#between}.\n * @see Collection#between\n * @see Collection#between\n * @since 3.0.0\n */\n 'between',\n\n /**\n * Wrapper for {@link Collection#createIndex}.\n *\n * @example\n * // Index users by age\n * store.createIndex('user', 'age')\n *\n * @example\n * // Index users by status and role\n * store.createIndex('user', 'statusAndRole', ['status', 'role'])\n *\n * @method SimpleStore#createIndex\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {string} name See {@link Collection#createIndex}.\n * @param {string[]} [fieldList] See {@link Collection#createIndex}.\n * @see Collection#createIndex\n * @see Collection#createIndex\n * @since 3.0.0\n */\n 'createIndex',\n\n /**\n * Wrapper for {@link Collection#filter}.\n *\n * @example SimpleStore#filter\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = store.filter('post', function (post) { return post.id % 2 === 0 })\n *\n * @method SimpleStore#filter\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Function)} [queryOrFn={}] See {@link Collection#filter}.\n * @param {Object} [thisArg] See {@link Collection#filter}.\n * @returns {Array} See {@link Collection#filter}.\n * @see Collection#filter\n * @see Collection#filter\n * @since 3.0.0\n */\n 'filter',\n\n /**\n * Wrapper for {@link Collection#get}.\n *\n * @example SimpleStore#get\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * console.log(store.get('post', 1)) // {...}\n * console.log(store.get('post', 2)) // undefined\n *\n * @method SimpleStore#get\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Collection#get}.\n * @returns {(Object|Record)} See {@link Collection#get}.\n * @see Collection#get\n * @see Collection#get\n * @since 3.0.0\n */\n 'get',\n\n /**\n * Wrapper for {@link Collection#getAll}.\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = store.getAll('post', 'draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = store.getAll('post', ['draft'], ['inReview'], { index: 'status' })\n *\n * @method SimpleStore#getAll\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {...Array} [keyList] See {@link Collection#getAll}.\n * @param {Object} [opts] See {@link Collection#getAll}.\n * @returns {Array} See {@link Collection#getAll}.\n * @see Collection#getAll\n * @see Collection#getAll\n * @since 3.0.0\n */\n 'getAll',\n\n /**\n * Wrapper for {@link Collection#prune}.\n *\n * @method SimpleStore#prune\n * @param {Object} [opts] See {@link Collection#prune}.\n * @returns {Array} See {@link Collection#prune}.\n * @see Collection#prune\n * @see Collection#prune\n * @since 3.0.0\n */\n 'prune',\n\n /**\n * Wrapper for {@link Collection#query}.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * store.query('user')\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method SimpleStore#query\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @returns {Query} See {@link Collection#query}.\n * @see Collection#query\n * @see Collection#query\n * @since 3.0.0\n */\n 'query',\n\n /**\n * Wrapper for {@link Collection#toJSON}.\n *\n * @example\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * title: { type: 'string' }\n * }\n * }\n * })\n * store.add('post', [\n * { id: 1, status: 'published', title: 'Respect your Data' },\n * { id: 2, status: 'draft', title: 'Connecting to a data source' }\n * ])\n * console.log(store.toJSON('post'))\n * const draftsJSON = store.query('post')\n * .filter({ status: 'draft' })\n * .mapCall('toJSON')\n * .run()\n *\n * @method SimpleStore#toJSON\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Object} [opts] See {@link Collection#toJSON}.\n * @returns {Array} See {@link Collection#toJSON}.\n * @see Collection#toJSON\n * @see Collection#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Wrapper for {@link Collection#unsaved}.\n *\n * @method SimpleStore#unsaved\n * @returns {Array} See {@link Collection#unsaved}.\n * @see Collection#unsaved\n * @see Collection#unsaved\n * @since 3.0.0\n */\n 'unsaved'\n]\nconst ownMethodsForScoping = [\n 'addToCache',\n 'cachedFind',\n 'cachedFindAll',\n 'cacheFind',\n 'cacheFindAll',\n 'hashQuery'\n]\n\nconst cachedFn = function (name, hashOrId, opts) {\n const cached = this._completedQueries[name][hashOrId]\n if (utils.isFunction(cached)) {\n return cached(name, hashOrId, opts)\n }\n return cached\n}\n\nconst SIMPLESTORE_DEFAULTS = {\n /**\n * Whether to use the pending query if a `find` request for the specified\n * record is currently underway. Can be set to `true`, `false`, or to a\n * function that returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFind\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFind: true,\n\n /**\n * Whether to use the pending query if a `findAll` request for the given query\n * is currently underway. Can be set to `true`, `false`, or to a function that\n * returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFindAll\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFindAll: true\n}\n\n/**\n * The `SimpleStore` class is an extension of {@link Container}. Not only does\n * `SimpleStore` manage mappers, but also collections. `SimpleStore` implements the\n * asynchronous {@link Mapper} methods, such as {@link Mapper#find} and\n * {@link Mapper#create}. If you use the asynchronous `SimpleStore` methods\n * instead of calling them directly on the mappers, then the results of the\n * method calls will be inserted into the store's collections. You can think of\n * a `SimpleStore` as an [Identity Map](https://en.wikipedia.org/wiki/Identity_map_pattern)\n * for the [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping)\n * (the Mappers).\n *\n * ```javascript\n * import {SimpleStore} from 'js-data'\n * ```\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new SimpleStore()\n *\n * // SimpleStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // SimpleStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful SimpleStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class SimpleStore\n * @extends Container\n * @param {Object} [opts] Configuration options. See {@link Container}.\n * @param {boolean} [opts.collectionClass={@link Collection}] See {@link SimpleStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link SimpleStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link SimpleStore#usePendingFindAll}.\n * @returns {SimpleStore}\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-SimpleStore\",\"Working with the SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction SimpleStore (opts) {\n utils.classCallCheck(this, SimpleStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, SIMPLESTORE_DEFAULTS)\n Container.call(this, opts)\n\n this.collectionClass = this.collectionClass || Collection\n this._collections = {}\n this._pendingQueries = {}\n this._completedQueries = {}\n}\n\nconst props = {\n constructor: SimpleStore,\n\n /**\n * Internal method used to handle Mapper responses.\n *\n * @method SimpleStore#_end\n * @private\n * @param {string} name Name of the {@link Collection} to which to\n * add the data.\n * @param {Object} result The result from a Mapper.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object|Array)} Result.\n */\n _end (name, result, opts) {\n let data = opts.raw ? result.data : result\n if (data && utils.isFunction(this.addToCache)) {\n data = this.addToCache(name, data, opts)\n if (opts.raw) {\n result.data = data\n } else {\n result = data\n }\n }\n return result\n },\n\n /**\n * Register a new event listener on this SimpleStore.\n *\n * Proxy for {@link Container#on}. If an event was emitted by a Mapper or\n * Collection in the SimpleStore, then the name of the Mapper or Collection will\n * be prepended to the arugments passed to the provided event handler.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a SimpleStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * store.on('add', (mapperName, records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * store.on('change', (mapperName, record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method SimpleStore#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n */\n\n /**\n * Used to bind to events emitted by collections in this store.\n *\n * @method SimpleStore#_onCollectionEvent\n * @private\n * @param {string} name Name of the collection that emitted the event.\n * @param {...*} [args] Args passed to {@link Collection#emit}.\n */\n _onCollectionEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * This method takes the data received from {@link SimpleStore#find},\n * {@link SimpleStore#findAll}, {@link SimpleStore#update}, etc., and adds the\n * data to the store. _You don't need to call this method directly._\n *\n * If you're using the http adapter and your response data is in an unexpected\n * format, you may need to override this method so the right data gets added\n * to the store.\n *\n * @example\n * const store = new SimpleStore({\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return SimpleStore.prototype.addToCache.call(this, mapperName, data, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return super.addToCache(mapperName, data, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#addToCache\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {*} data Data from which data should be selected for add.\n * @param {Object} [opts] Configuration options.\n */\n addToCache (name, data, opts) {\n return this.getCollection(name).add(data, opts)\n },\n\n /**\n * Return the store scoped to a particular mapper/collection pair.\n *\n * @example SimpleStore.as\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method SimpleStore#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} The store, scoped to a particular Mapper/Collection pair.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n const methods = ownMethodsForScoping\n .concat(proxiedMapperMethods)\n .concat(proxiedCollectionMethods)\n\n methods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n props.getCollection = {\n writable: true,\n value () {\n return original.getCollection(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Retrieve a cached `find` result, if any. This method is called during\n * {@link SimpleStore#find} to determine if {@link Mapper#find} needs to be\n * called. If this method returns `undefined` then {@link Mapper#find} will\n * be called. Otherwise {@link SimpleStore#find} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFind.call(this, mapperName, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cachedFind(mapperName, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cachedFind: cachedFn,\n\n /**\n * Retrieve a cached `findAll` result, if any. This method is called during\n * {@link SimpleStore#findAll} to determine if {@link Mapper#findAll} needs to be\n * called. If this method returns `undefined` then {@link Mapper#findAll} will\n * be called. Otherwise {@link SimpleStore#findAll} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return super.cachedFindAll(mapperName, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cachedFindAll: cachedFn,\n\n /**\n * Mark a {@link Mapper#find} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `find` entry is\n * added it means subsequent calls to the same Resource with the same `id`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#get} instead of delegating to {@link Mapper#find}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cacheFind.call(this, mapperName, data, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cacheFind(mapperName, data, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {*} data The result to cache.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cacheFind (name, data, id, opts) {\n this._completedQueries[name][id] = (name, id, opts) => this.get(name, id)\n },\n\n /**\n * Mark a {@link Mapper#findAll} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `findAll` entry is\n * added it means subsequent calls to the same Resource with the same `query`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#filter} instead of delegating to {@link Mapper#findAll}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, data, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return super.cachedFindAll(mapperName, data, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {*} data The result to cache.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cacheFindAll (name, data, hash, opts) {\n this._completedQueries[name][hash] = (name, hash, opts) => this.filter(name, utils.fromJson(hash))\n },\n\n /**\n * Remove __all__ records from the in-memory store and reset\n * {@link SimpleStore#_completedQueries}.\n *\n * @method SimpleStore#clear\n * @returns {Object} Object containing all records that were in the store.\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n clear () {\n const removed = {}\n utils.forOwn(this._collections, (collection, name) => {\n removed[name] = collection.removeAll()\n this._completedQueries[name] = {}\n })\n return removed\n },\n\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~beforeCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreate\n * @see SimpleStore~beforeCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback SimpleStore~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see SimpleStore#event:beforeCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~afterCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreate\n * @see SimpleStore~afterCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback SimpleStore~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see SimpleStore#event:afterCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}. Adds the created record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book {\"author_id\":1234,...}\n * store.create('book', {\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }).then((book) => {\n * console.log(book.id) // 120392\n * console.log(book.title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreate\n * @fires SimpleStore#afterCreate\n * @fires SimpleStore#add\n * @method SimpleStore#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} record Passed to {@link Mapper#create}.\n * @param {Object} [opts] Passed to {@link Mapper#create}. See\n * {@link Mapper#create} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n create (name, record, opts) {\n opts || (opts = {})\n return Container.prototype.create.call(this, name, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~beforeCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreateMany\n * @see SimpleStore~beforeCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback SimpleStore~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see SimpleStore#event:beforeCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~afterCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreateMany\n * @see SimpleStore~afterCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback SimpleStore~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see SimpleStore#event:afterCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}. Adds the created records to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book [{\"author_id\":1234,...},{...}]\n * store.createMany('book', [{\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }, {\n * author_id: 1234,\n * edition: 'Second Edition',\n * title: 'Respect your Data'\n * }]).then((books) => {\n * console.log(books[0].id) // 142394\n * console.log(books[0].title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreateMany\n * @fires SimpleStore#afterCreateMany\n * @fires SimpleStore#add\n * @method SimpleStore#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Array} records Passed to {@link Mapper#createMany}.\n * @param {Object} [opts] Passed to {@link Mapper#createMany}. See\n * {@link Mapper#createMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n createMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.createMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n defineMapper (name, opts) {\n const self = this\n const mapper = Container.prototype.defineMapper.call(self, name, opts)\n self._pendingQueries[name] = {}\n self._completedQueries[name] = {}\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, { // eslint-disable-line\n // Make sure the collection has somewhere to store \"added\" timestamps\n _added: {},\n // Give the collection a reference to this SimpleStore\n datastore: self,\n // The mapper tied to the collection\n mapper\n })\n\n const schema = mapper.schema || {}\n const properties = schema.properties || {}\n // TODO: Make it possible index nested properties?\n utils.forOwn(properties, function (opts, prop) {\n if (opts.indexed) {\n collection.createIndex(prop)\n }\n })\n\n // Create a secondary index on the \"added\" timestamps of records in the\n // collection\n collection.createIndex('addedTimestamps', ['$'], {\n fieldGetter (obj) {\n return collection._added[collection.recordId(obj)]\n }\n })\n\n collection.on('all', function (...args) {\n self._onCollectionEvent(name, ...args)\n })\n\n return mapper\n },\n\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~beforeDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroy\n * @see SimpleStore~beforeDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback SimpleStore~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see SimpleStore#event:beforeDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~afterDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroy\n * @see SimpleStore~afterDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback SimpleStore~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see SimpleStore#event:afterDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}. Removes any destroyed record from the\n * in-memory store. Clears out any {@link SimpleStore#_completedQueries} entries\n * associated with the provided `id`.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is no longer in the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n *\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroy\n * @fires SimpleStore#afterDestroy\n * @fires SimpleStore#remove\n * @method SimpleStore#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#destroy}.\n * @param {Object} [opts] Passed to {@link Mapper#destroy}. See\n * {@link Mapper#destroy} for more configuration options.\n * @returns {Promise} Resolves when the destroy operation completes.\n * @since 3.0.0\n */\n destroy (name, id, opts) {\n opts || (opts = {})\n return Container.prototype.destroy.call(this, name, id, opts).then((result) => {\n const record = this.getCollection(name).remove(id, opts)\n\n if (opts.raw) {\n result.data = record\n } else {\n result = record\n }\n delete this._pendingQueries[name][id]\n delete this._completedQueries[name][id]\n return result\n })\n },\n\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroyAll\n * @see SimpleStore~beforeDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback SimpleStore~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see SimpleStore#event:beforeDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~afterDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroyAll\n * @see SimpleStore~afterDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback SimpleStore~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see SimpleStore#event:afterDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}. Removes any destroyed records from\n * the in-memory store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is gone from the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroyAll\n * @fires SimpleStore#afterDestroyAll\n * @fires SimpleStore#remove\n * @method SimpleStore#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper#destroyAll}.\n * @param {Object} [opts] Passed to {@link Mapper#destroyAll}. See\n * {@link Mapper#destroyAll} for more configuration options.\n * @returns {Promise} Resolves when the delete completes.\n * @since 3.0.0\n */\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return Container.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n const records = this.getCollection(name).removeAll(query, opts)\n\n if (opts.raw) {\n result.data = records\n } else {\n result = records\n }\n const hash = this.hashQuery(name, query, opts)\n delete this._pendingQueries[name][hash]\n delete this._completedQueries[name][hash]\n return result\n })\n },\n\n eject (name, id, opts) {\n console.warn('DEPRECATED: \"eject\" is deprecated, use \"remove\" instead')\n return this.remove(name, id, opts)\n },\n\n ejectAll (name, query, opts) {\n console.warn('DEPRECATED: \"ejectAll\" is deprecated, use \"removeAll\" instead')\n return this.removeAll(name, query, opts)\n },\n\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~beforeFindListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFind\n * @see SimpleStore~beforeFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback SimpleStore~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see SimpleStore#event:beforeFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~afterFindListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFind\n * @see SimpleStore~afterFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback SimpleStore~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see SimpleStore#event:afterFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}. Adds any found record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /book/1234\n * store.find('book', 1234).then((book) => {\n * // The book record is now in the in-memory store\n * console.log(store.get('book', 1234) === book) // true\n * })\n *\n * @fires SimpleStore#beforeFind\n * @fires SimpleStore#afterFind\n * @fires SimpleStore#add\n * @method SimpleStore#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#find}.\n * @param {Object} [opts] Passed to {@link Mapper#find}.\n * @param {boolean|Function} [opts.usePendingFind] See {@link SimpleStore#usePendingFind}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n find (name, id, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const pendingQuery = this._pendingQueries[name][id]\n const usePendingFind = opts.usePendingFind === undefined ? this.usePendingFind : opts.usePendingFind\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFind) ? usePendingFind.call(this, name, id, opts) : usePendingFind)) {\n return pendingQuery\n }\n const item = this.cachedFind(name, id, opts)\n let promise\n\n if (opts.force || !item) {\n promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts).then((result) => {\n delete this._pendingQueries[name][id]\n result = this._end(name, result, opts)\n this.cacheFind(name, result, id, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][id]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(item)\n }\n return promise\n },\n\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~beforeFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFindAll\n * @see SimpleStore~beforeFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback SimpleStore~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see SimpleStore#event:beforeFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~afterFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFindAll\n * @see SimpleStore~afterFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback SimpleStore~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see SimpleStore#event:afterFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#findAll}. Adds any found records to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('movie')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /movie?rating=PG\n * store.find('movie', { rating: 'PG' }).then((movies) => {\n * // The movie records are now in the in-memory store\n * console.log(store.filter('movie'))\n * })\n *\n * @fires SimpleStore#beforeFindAll\n * @fires SimpleStore#afterFindAll\n * @fires SimpleStore#add\n * @method SimpleStore#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper.findAll}.\n * @param {Object} [opts] Passed to {@link Mapper.findAll}.\n * @param {boolean|Function} [opts.usePendingFindAll] See {@link SimpleStore#usePendingFindAll}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n findAll (name, query, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const hash = this.hashQuery(name, query, opts)\n const pendingQuery = this._pendingQueries[name][hash]\n const usePendingFindAll = opts.usePendingFindAll === undefined ? this.usePendingFindAll : opts.usePendingFindAll\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFindAll) ? usePendingFindAll.call(this, name, query, opts) : usePendingFindAll)) {\n return pendingQuery\n }\n\n const items = this.cachedFindAll(name, hash, opts)\n let promise\n\n if (opts.force || !items) {\n promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts).then((result) => {\n delete this._pendingQueries[name][hash]\n result = this._end(name, result, opts)\n this.cacheFindAll(name, result, hash, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][hash]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(items)\n }\n return promise\n },\n\n /**\n * Return the {@link Collection} with the given name, if for some\n * reason you need a direct reference to the collection.\n *\n * @method SimpleStore#getCollection\n * @param {string} name Name of the {@link Collection} to retrieve.\n * @returns {Collection}\n * @since 3.0.0\n * @throws {Error} Thrown if the specified {@link Collection} does not\n * exist.\n */\n getCollection (name) {\n const collection = this._collections[name]\n if (!collection) {\n throw utils.err(`${DOMAIN}#getCollection`, name)(404, 'collection')\n }\n return collection\n },\n\n /**\n * Hashing function used to cache {@link SimpleStore#find} and\n * {@link SimpleStore#findAll} requests. This method simply JSONifies the\n * `query` argument passed to {@link SimpleStore#find} or\n * {@link SimpleStore#findAll}.\n *\n * Override this method for custom hashing behavior.\n * @method SimpleStore#hashQuery\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @param {Object} query The `query` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @returns {string} The JSONified `query`.\n * @since 3.0.0\n */\n hashQuery (name, query, opts) {\n return utils.toJson(query)\n },\n\n inject (name, records, opts) {\n console.warn('DEPRECATED: \"inject\" is deprecated, use \"add\" instead')\n return this.add(name, records, opts)\n },\n\n /**\n * Wrapper for {@link Collection#remove}. Removes the specified\n * {@link Record} from the store.\n *\n * @example SimpleStore#remove\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n * console.log(store.getAll('book').length)\n * store.add('book', { id: 1234 })\n * console.log(store.getAll('book').length)\n * store.remove('book', 1234)\n * console.log(store.getAll('book').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#remove\n * @param {string} name The name of the {@link Collection} to target.\n * @param {string|number} id The primary key of the {@link Record} to remove.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n remove (name, id, opts) {\n const record = this.getCollection(name).remove(id, opts)\n if (record) {\n this.removeRelated(name, [record], opts)\n }\n return record\n },\n\n /**\n * Wrapper for {@link Collection#removeAll}. Removes the selected\n * {@link Record}s from the store.\n *\n * @example SimpleStore#removeAll\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('movie')\n * console.log(store.getAll('movie').length)\n * store.add('movie', [{ id: 3, rating: 'R' }, { id: 4, rating: 'PG-13' })\n * console.log(store.getAll('movie').length)\n * store.removeAll('movie', { rating: 'R' })\n * console.log(store.getAll('movie').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeAll\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}s, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n removeAll (name, query, opts) {\n const records = this.getCollection(name).removeAll(query, opts)\n if (records.length) {\n this.removeRelated(name, records, opts)\n }\n return records\n },\n\n /**\n * Remove from the store {@link Record}s that are related to the provided\n * {@link Record}(s).\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeRelated\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Record|Record[]} records {@link Record}s whose relations are to be\n * removed.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record}(s) to remove\n * from the store.\n * @since 3.0.0\n */\n removeRelated (name, records, opts) {\n if (!utils.isArray(records)) {\n records = [records]\n }\n utils.forEachRelation(this.getMapper(name), opts, (def, optsCopy) => {\n records.forEach((record) => {\n let relatedData\n let query\n if (def.foreignKey && (def.type === hasOneType || def.type === hasManyType)) {\n query = { [def.foreignKey]: def.getForeignKey(record) }\n } else if (def.type === hasManyType && def.localKeys) {\n query = {\n where: {\n [def.getRelation().idAttribute]: {\n 'in': utils.get(record, def.localKeys)\n }\n }\n }\n } else if (def.type === hasManyType && def.foreignKeys) {\n query = {\n where: {\n [def.foreignKeys]: {\n 'contains': def.getForeignKey(record)\n }\n }\n }\n } else if (def.type === belongsToType) {\n relatedData = this.remove(def.relation, def.getForeignKey(record), optsCopy)\n }\n if (query) {\n relatedData = this.removeAll(def.relation, query, optsCopy)\n }\n if (relatedData) {\n if (utils.isArray(relatedData) && !relatedData.length) {\n return\n }\n if (def.type === hasOneType) {\n relatedData = relatedData[0]\n }\n def.setLocalField(record, relatedData)\n }\n })\n })\n },\n\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~beforeUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdate\n * @see SimpleStore~beforeUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback SimpleStore~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see SimpleStore#event:beforeUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~afterUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdate\n * @see SimpleStore~afterUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback SimpleStore~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see SimpleStore#event:afterUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}. Adds the updated {@link Record} to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post/1234 {\"status\":\"published\"}\n * store.update('post', 1, { status: 'published' }).then((post) => {\n * // The post record has also been updated in the in-memory store\n * console.log(store.get('post', 1234))\n * })\n *\n * @fires SimpleStore#beforeUpdate\n * @fires SimpleStore#afterUpdate\n * @fires SimpleStore#add\n * @method SimpleStore#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#update}.\n * @param {Object} record Passed to {@link Mapper#update}.\n * @param {Object} [opts] Passed to {@link Mapper#update}. See\n * {@link Mapper#update} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n update (name, id, record, opts) {\n opts || (opts = {})\n return Container.prototype.update.call(this, name, id, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateAll\n * @see SimpleStore~beforeUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback SimpleStore~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see SimpleStore#event:beforeUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~afterUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateAll\n * @see SimpleStore~afterUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback SimpleStore~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see SimpleStore#event:afterUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post?author_id=1234 {\"status\":\"published\"}\n * store.updateAll('post', { author_id: 1234 }, { status: 'published' }).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.filter('posts', { author_id: 1234 }))\n * })\n *\n * @fires SimpleStore#beforeUpdateAll\n * @fires SimpleStore#afterUpdateAll\n * @fires SimpleStore#add\n * @method SimpleStore#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props Passed to {@link Mapper#updateAll}.\n * @param {Object} [query] Passed to {@link Mapper#updateAll}.\n * @param {Object} [opts] Passed to {@link Mapper#updateAll}. See\n * {@link Mapper#updateAll} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateAll (name, props, query, opts) {\n opts || (opts = {})\n return Container.prototype.updateAll.call(this, name, query, props, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateMany\n * @see SimpleStore~beforeUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback SimpleStore~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see SimpleStore#event:beforeUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~afterUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateMany\n * @see SimpleStore~afterUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback SimpleStore~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see SimpleStore#event:afterUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post [{\"id\":3,status\":\"published\"},{\"id\":4,status\":\"published\"}]\n * store.updateMany('post', [\n * { id: 3, status: 'published' },\n * { id: 4, status: 'published' }\n * ]).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.getAll('post', 3, 4))\n * })\n *\n * @fires SimpleStore#beforeUpdateMany\n * @fires SimpleStore#afterUpdateMany\n * @fires SimpleStore#add\n * @method SimpleStore#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records Passed to {@link Mapper#updateMany}.\n * @param {Object} [opts] Passed to {@link Mapper#updateMany}. See\n * {@link Mapper#updateMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.updateMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n }\n}\n\nproxiedCollectionMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getCollection(name)[method](...args)\n }\n})\n\nexport default Container.extend(props)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link SimpleStore~changeListener} on how to listen for this event.\n *\n * @event SimpleStore#change\n * @see SimpleStore~changeListener\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:change} event.\n *\n * @example\n * function onChange (mapperName, record, changes) {\n * // do something\n * }\n * store.on('change', onChange)\n *\n * @callback SimpleStore~changeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record} record The Record that changed.\n * @param {Object} changes The changes.\n * @see SimpleStore#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the in-memory store. See\n * {@link SimpleStore~addListener} on how to listen for this event.\n *\n * @event SimpleStore#add\n * @see SimpleStore~addListener\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:add} event.\n *\n * @example\n * function onAdd (mapperName, recordOrRecords) {\n * // do something\n * }\n * store.on('add', onAdd)\n *\n * @callback SimpleStore~addListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} The Record or Records that were added.\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the in-memory store. See\n * {@link SimpleStore~removeListener} for how to listen for this event.\n *\n * @event SimpleStore#remove\n * @see SimpleStore~removeListener\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:remove} event.\n *\n * @example\n * function onRemove (mapperName, recordsOrRecords) {\n * // do something\n * }\n * store.on('remove', onRemove)\n *\n * @callback SimpleStore~removeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} Record or Records that were removed.\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this SimpleStore:\n * @example SimpleStore.extend\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSimpleStoreClass extends SimpleStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSimpleStore = new CustomSimpleStoreClass()\n * console.log(customSimpleStore.foo())\n * console.log(CustomSimpleStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSimpleStoreClass = SimpleStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSimpleStore = new OtherSimpleStoreClass()\n * console.log(otherSimpleStore.foo())\n * console.log(OtherSimpleStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSimpleStoreClass () {\n * SimpleStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * SimpleStore.extend({\n * constructor: AnotherSimpleStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSimpleStore = new AnotherSimpleStoreClass()\n * console.log(anotherSimpleStore.created_at)\n * console.log(anotherSimpleStore.foo())\n * console.log(AnotherSimpleStoreClass.beep())\n *\n * @method SimpleStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this SimpleStore class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport './decorators'\nimport Collection from './Collection'\n\nconst DOMAIN = 'LinkedCollection'\n\n/**\n * Extends {@link Collection}. Used by a {@link DataStore} to implement an\n * Identity Map.\n *\n * ```javascript\n * import {LinkedCollection} from 'js-data'\n * ```\n *\n * @class LinkedCollection\n * @extends Collection\n * @param {Array} [records] Initial set of records to insert into the\n * collection. See {@link Collection}.\n * @param {Object} [opts] Configuration options. See {@link Collection}.\n * @returns {Mapper}\n */\nfunction LinkedCollection (records, opts) {\n utils.classCallCheck(this, LinkedCollection)\n // Make sure this collection has somewhere to store \"added\" timestamps\n Object.defineProperties(this, {\n _added: {\n value: {}\n },\n datastore: {\n writable: true,\n value: undefined\n }\n })\n\n Collection.call(this, records, opts)\n\n // Make sure this collection has a reference to a datastore\n if (!this.datastore) {\n throw utils.err(`new ${DOMAIN}`, 'opts.datastore')(400, 'DataStore', this.datastore)\n }\n}\n\nexport default Collection.extend({\n constructor: LinkedCollection,\n\n _addMeta (record, timestamp) {\n // Track when this record was added\n this._added[this.recordId(record)] = timestamp\n\n if (utils.isFunction(record._set)) {\n record._set('$', timestamp)\n }\n },\n\n _clearMeta (record) {\n delete this._added[this.recordId(record)]\n if (utils.isFunction(record._set)) {\n record._set('$') // unset\n }\n },\n\n _onRecordEvent (...args) {\n Collection.prototype._onRecordEvent.apply(this, args)\n const event = args[0]\n // This is a very brute force method\n // Lots of room for optimization\n if (utils.isString(event) && event.indexOf('change') === 0) {\n this.updateIndexes(args[1])\n }\n },\n\n add (records, opts) {\n const mapper = this.mapper\n const timestamp = new Date().getTime()\n const singular = utils.isObject(records) && !utils.isArray(records)\n\n if (singular) {\n records = [records]\n }\n records = Collection.prototype.add.call(this, records, opts)\n\n if (mapper.relationList.length && records.length) {\n // Check the currently visited record for relations that need to be\n // inserted into their respective collections.\n mapper.relationList.forEach(function (def) {\n def.addLinkedRecords(records)\n })\n }\n\n records.forEach((record) => this._addMeta(record, timestamp))\n\n return singular ? records[0] : records\n },\n\n remove (idOrRecord, opts) {\n const mapper = this.mapper\n const record = Collection.prototype.remove.call(this, idOrRecord, opts)\n if (record) {\n this._clearMeta(record)\n }\n\n if (mapper.relationList.length && record) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, [record])\n })\n }\n\n return record\n },\n\n removeAll (query, opts) {\n const mapper = this.mapper\n const records = Collection.prototype.removeAll.call(this, query, opts)\n records.forEach(this._clearMeta, this)\n\n if (mapper.relationList.length && records.length) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, records)\n })\n }\n\n return records\n }\n})\n\n/**\n * Create a subclass of this LinkedCollection:\n *\n * @example LinkedCollection.extend\n * // Normally you would do: import {LinkedCollection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {LinkedCollection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomLinkedCollectionClass extends LinkedCollection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customLinkedCollection = new CustomLinkedCollectionClass()\n * console.log(customLinkedCollection.foo())\n * console.log(CustomLinkedCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherLinkedCollectionClass = LinkedCollection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherLinkedCollection = new OtherLinkedCollectionClass()\n * console.log(otherLinkedCollection.foo())\n * console.log(OtherLinkedCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherLinkedCollectionClass () {\n * LinkedCollection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * LinkedCollection.extend({\n * constructor: AnotherLinkedCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherLinkedCollection = new AnotherLinkedCollectionClass()\n * console.log(anotherLinkedCollection.created_at)\n * console.log(anotherLinkedCollection.foo())\n * console.log(AnotherLinkedCollectionClass.beep())\n *\n * @method LinkedCollection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this LinkedCollection class.\n * @since 3.0.0\n */\n","import utils, { safeSetLink, safeSetProp } from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport SimpleStore from './SimpleStore'\nimport LinkedCollection from './LinkedCollection'\n\nconst DOMAIN = 'DataStore'\n\nconst DATASTORE_DEFAULTS = {\n /**\n * Whether in-memory relations should be unlinked from records after they are\n * destroyed.\n *\n * @default true\n * @name DataStore#unlinkOnDestroy\n * @since 3.0.0\n * @type {boolean}\n */\n unlinkOnDestroy: true\n}\n\n/**\n * The `DataStore` class is an extension of {@link SimpleStore}. Not only does\n * `DataStore` manage mappers and store data in collections, it uses the\n * {@link LinkedCollection} class to link related records together in memory.\n *\n * ```javascript\n * import {DataStore} from 'js-data'\n * ```\n *\n * @example\n * import {DataStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new DataStore()\n *\n * // DataStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // DataStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful DataStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class DataStore\n * @extends SimpleStore\n * @param {Object} [opts] Configuration options. See {@link SimpleStore}.\n * @param {boolean} [opts.collectionClass={@link LinkedCollection}] See {@link DataStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean} [opts.unlinkOnDestroy=true] See {@link DataStore#unlinkOnDestroy}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link DataStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link DataStore#usePendingFindAll}.\n * @returns {DataStore}\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-datastore\",\"Working with the DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction DataStore (opts) {\n utils.classCallCheck(this, DataStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, DATASTORE_DEFAULTS)\n opts.collectionClass || (opts.collectionClass = LinkedCollection)\n SimpleStore.call(this, opts)\n}\n\nconst props = {\n constructor: DataStore,\n\n defineMapper (name, opts) {\n // Complexity of this method is beyond simply using => functions to bind context\n const self = this\n const mapper = SimpleStore.prototype.defineMapper.call(self, name, opts)\n const idAttribute = mapper.idAttribute\n const collection = this.getCollection(name)\n\n mapper.relationList.forEach(function (def) {\n const relation = def.relation\n const localField = def.localField\n const path = `links.${localField}`\n const foreignKey = def.foreignKey\n const type = def.type\n const updateOpts = { index: foreignKey }\n let descriptor\n\n const getter = function () { return this._get(path) }\n\n if (type === belongsToType) {\n if (!collection.indexes[foreignKey]) {\n collection.createIndex(foreignKey)\n }\n\n descriptor = {\n get: getter,\n // e.g. profile.user = someUser\n // or comment.post = somePost\n set (record) {\n // e.g. const otherUser = profile.user\n const currentParent = this._get(path)\n // e.g. profile.user === someUser\n if (record === currentParent) {\n return currentParent\n }\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n\n // e.g. profile.user !== someUser\n // or comment.post !== somePost\n if (currentParent && inverseDef) {\n this.removeInverseRelation(currentParent, id, inverseDef, idAttribute)\n }\n if (record) {\n // e.g. profile.user = someUser\n const relatedIdAttribute = def.getRelation().idAttribute\n const relatedId = utils.get(record, relatedIdAttribute)\n\n // Prefer store record\n if (relatedId !== undefined && this._get('$')) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n // e.g. profile.user = someUser\n // or comment.post = somePost\n safeSetLink(this, localField, record)\n safeSetProp(this, foreignKey, relatedId)\n collection.updateIndex(this, updateOpts)\n\n if (inverseDef) {\n this.setupInverseRelation(record, id, inverseDef, idAttribute)\n }\n } else {\n // Unset in-memory link only\n // e.g. profile.user = undefined\n // or comment.post = undefined\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n\n let foreignKeyDescriptor = Object.getOwnPropertyDescriptor(mapper.recordClass.prototype, foreignKey)\n if (!foreignKeyDescriptor) {\n foreignKeyDescriptor = {\n enumerable: true\n }\n }\n const originalGet = foreignKeyDescriptor.get\n foreignKeyDescriptor.get = function () {\n if (originalGet) {\n return originalGet.call(this)\n }\n return this._get(`props.${foreignKey}`)\n }\n const originalSet = foreignKeyDescriptor.set\n foreignKeyDescriptor.set = function (value) {\n if (originalSet) {\n originalSet.call(this, value)\n }\n const currentParent = utils.get(this, localField)\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n const currentParentId = currentParent ? utils.get(currentParent, def.getRelation().idAttribute) : undefined\n\n if (currentParent && currentParentId !== undefined && currentParentId !== value) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n }\n\n safeSetProp(this, foreignKey, value)\n collection.updateIndex(this, updateOpts)\n\n if ((value === undefined || value === null)) {\n if (currentParentId !== undefined) {\n // Unset locals\n utils.set(this, localField, undefined)\n }\n } else if (this._get('$')) {\n const storeRecord = self.get(relation, value)\n if (storeRecord) {\n utils.set(this, localField, storeRecord)\n }\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, foreignKey, foreignKeyDescriptor)\n } else if (type === hasManyType) {\n const localKeys = def.localKeys\n const foreignKeys = def.foreignKeys\n\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n\n descriptor = {\n get () {\n let current = getter.call(this)\n if (!current) {\n this._set(path, [])\n }\n return getter.call(this)\n },\n // e.g. post.comments = someComments\n // or user.groups = someGroups\n // or group.users = someUsers\n set (records) {\n if (records && !utils.isArray(records)) {\n records = [records]\n }\n const id = utils.get(this, idAttribute)\n const relatedIdAttribute = def.getRelation().idAttribute\n const inverseDef = def.getInverse(mapper)\n const inverseLocalField = inverseDef.localField\n const current = this._get(path) || []\n const toLink = []\n const toLinkIds = {}\n\n if (records) {\n records.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n const currentParent = utils.get(record, inverseLocalField)\n if (currentParent && currentParent !== this) {\n const currentChildrenOfParent = utils.get(currentParent, localField)\n // e.g. somePost.comments.remove(comment)\n if (relatedId === undefined) {\n utils.remove(currentChildrenOfParent, (child) => child === record)\n } else {\n utils.remove(currentChildrenOfParent, (child) => child === record || relatedId === utils.get(child, relatedIdAttribute))\n }\n }\n if (relatedId !== undefined) {\n if (this._get('$')) {\n // Prefer store record\n record = self.get(relation, relatedId) || record\n }\n // e.g. toLinkIds[comment.id] = comment\n toLinkIds[relatedId] = record\n }\n toLink.push(record)\n })\n }\n\n // e.g. post.comments = someComments\n if (foreignKey) {\n current.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(record) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update (unset) inverse relation\n if (records) {\n // e.g. comment.post_id = undefined\n safeSetProp(record, foreignKey, undefined)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n }\n // e.g. comment.post = undefined\n safeSetLink(record, inverseLocalField, undefined)\n }\n })\n toLink.forEach((record) => {\n // Update (set) inverse relation\n // e.g. comment.post_id = post.id\n safeSetProp(record, foreignKey, id)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n // e.g. comment.post = post\n safeSetLink(record, inverseLocalField, this)\n })\n } else if (localKeys) {\n // Update locals\n // e.g. group.users = someUsers\n // Update (set) inverse relation\n const ids = toLink.map((child) => utils.get(child, relatedIdAttribute)).filter((id) => id !== undefined)\n // e.g. group.user_ids = [1,2,3,...]\n utils.set(this, localKeys, ids)\n // Update (unset) inverse relation\n if (inverseDef.foreignKeys) {\n current.forEach((child) => {\n const relatedId = utils.get(child, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(child) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update inverse relation\n // safeSetLink(child, inverseLocalField, undefined)\n const parents = utils.get(child, inverseLocalField) || []\n // e.g. someUser.groups.remove(group)\n if (id === undefined) {\n utils.remove(parents, (parent) => parent === this)\n } else {\n utils.remove(parents, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n }\n })\n toLink.forEach((child) => {\n // Update (set) inverse relation\n const parents = utils.get(child, inverseLocalField)\n // e.g. someUser.groups.push(group)\n if (id === undefined) {\n utils.noDupeAdd(parents, this, (parent) => parent === this)\n } else {\n utils.noDupeAdd(parents, this, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n })\n }\n } else if (foreignKeys) {\n // e.g. user.groups = someGroups\n // Update (unset) inverse relation\n current.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n // e.g. someGroup.user_ids.remove(user.id)\n utils.remove(ids, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n // e.g. someGroup.users.remove(user)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n // Update (set) inverse relation\n toLink.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n utils.noDupeAdd(ids, id, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n }\n\n this._set(path, toLink)\n return toLink\n }\n }\n } else if (type === hasOneType) {\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n descriptor = {\n get: getter,\n // e.g. user.profile = someProfile\n set (record) {\n const current = this._get(path)\n if (record === current) {\n return current\n }\n const inverseLocalField = def.getInverse(mapper).localField\n // Update (unset) inverse relation\n if (current) {\n safeSetProp(current, foreignKey, undefined)\n self.getCollection(relation).updateIndex(current, updateOpts)\n safeSetLink(current, inverseLocalField, undefined)\n }\n if (record) {\n const relatedId = utils.get(record, def.getRelation().idAttribute)\n // Prefer store record\n if (relatedId !== undefined) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n safeSetLink(this, localField, record)\n\n // Update (set) inverse relation\n safeSetProp(record, foreignKey, utils.get(this, idAttribute))\n self.getCollection(relation).updateIndex(record, updateOpts)\n safeSetLink(record, inverseLocalField, this)\n } else {\n // Unset locals\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n }\n\n if (descriptor) {\n descriptor.enumerable = def.enumerable === undefined ? false : def.enumerable\n if (def.get) {\n let origGet = descriptor.get\n descriptor.get = function () {\n return def.get(def, this, (...args) => origGet.apply(this, args))\n }\n }\n if (def.set) {\n let origSet = descriptor.set\n descriptor.set = function (related) {\n return def.set(def, this, related, (value) => origSet.call(this, value === undefined ? related : value))\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, localField, descriptor)\n }\n })\n\n return mapper\n },\n\n destroy (name, id, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroy.call(this, name, id, opts).then((result) => {\n let record\n if (opts.raw) {\n record = result.data\n } else {\n record = result\n }\n\n if (record && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n utils.set(record, def.localField, undefined)\n })\n }\n return result\n })\n },\n\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n let records\n if (opts.raw) {\n records = result.data\n } else {\n records = result\n }\n\n if (records && records.length && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n records.forEach((record) => {\n utils.set(record, def.localField, undefined)\n })\n })\n }\n return result\n })\n }\n}\n\nexport default SimpleStore.extend(props)\n\n/**\n * Create a subclass of this DataStore:\n * @example DataStore.extend\n * // Normally you would do: import {DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {DataStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomDataStoreClass extends DataStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customDataStore = new CustomDataStoreClass()\n * console.log(customDataStore.foo())\n * console.log(CustomDataStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherDataStoreClass = DataStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherDataStore = new OtherDataStoreClass()\n * console.log(otherDataStore.foo())\n * console.log(OtherDataStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherDataStoreClass () {\n * DataStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * DataStore.extend({\n * constructor: AnotherDataStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherDataStore = new AnotherDataStoreClass()\n * console.log(anotherDataStore.created_at)\n * console.log(anotherDataStore.foo())\n * console.log(AnotherDataStoreClass.beep())\n *\n * @method DataStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this DataStore class.\n * @since 3.0.0\n */\n","/**\n * Registered as `js-data` in NPM and Bower.\n *\n * Also available from CDN.JS and JSDelivr.\n *\n * @module js-data\n *\n * @example Install from NPM\n * npm i --save js-data@beta\n * @example Install from Bower\n * bower i --save js-data@3.0.0-beta.1\n * @example Install from CDN.JS\n * \n * @example Install from JSDelivr\n * \n * @example Load into your app via script tag\n * \n * \n * @example Load into your app via CommonJS\n * var JSData = require('js-data');\n * @example Load into your app via ES2015 Modules\n * import * as JSData from 'js-data';\n * @example Load into your app via AMD\n * define('myApp', ['js-data'], function (JSData) { ... })\n */\n\n/**\n * Describes the version of this `JSData` object.\n *\n * @example\n * console.log(JSData.version.full) // \"3.0.0-beta.1\"\n *\n * @name version\n * @memberof module:js-data\n * @property {string} full The full semver value.\n * @property {number} major The major version number.\n * @property {number} minor The minor version number.\n * @property {number} patch The patch version number.\n * @property {(string|boolean)} alpha The alpha version value, otherwise `false`\n * if the current version is not alpha.\n * @property {(string|boolean)} beta The beta version value, otherwise `false`\n * if the current version is not beta.\n * @since 2.0.0\n * @type {Object}\n */\nexport const version = '<%= version %>'\n\n/**\n * JSData's utility methods.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @name module:js-data.utils\n * @property {Function} Promise See {@link utils.Promise}.\n * @see utils\n * @since 3.0.0\n * @type {Object}\n */\nimport utils from './utils'\n\n/**\n * JSData's {@link Collection} class.\n *\n * @example\n * import {Collection} from 'js-data'\n * const collection = new Collection()\n *\n * @name module:js-data.Collection\n * @see Collection\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#collection\",\"Components of JSData: Collection\"]\n * @type {Constructor}\n */\nimport Collection from './Collection'\n\n/**\n * JSData's {@link Component} class. Most components in JSData extend this\n * class.\n *\n * @example\n * import {Component} from 'js-data'\n * // Make a custom component.\n * const MyComponent = Component.extend({\n * myMethod (someArg) { ... }\n * })\n *\n * @name module:js-data.Component\n * @see Component\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Component from './Component'\n\n/**\n * JSData's {@link Container} class. Defines and manages {@link Mapper}s. Used\n * in Node.js and in the browser, though in the browser you may want to use\n * {@link DataStore} instead.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n *\n * @name module:js-data.Container\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#container\",\"Components of JSData: Container\"]\n * @type {Constructor}\n */\nimport {Container} from './Container'\n\n/**\n * JSData's {@link DataStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {DataStore} from 'js-data'\n * const store = new DataStore()\n *\n * @name module:js-data.DataStore\n * @see DataStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @type {Constructor}\n */\nimport DataStore from './DataStore'\n\n/**\n * JSData's {@link Index} class, based on [mindex]{@link https://github.com/internalfx/mindex}.\n *\n * @name module:js-data.Index\n * @see Index\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Index from '../lib/mindex/index'\n\n/**\n * JSData's {@link LinkedCollection} class. Used by the {@link DataStore}\n * component. If you need to create a collection manually, you should probably\n * use the {@link Collection} class.\n *\n * @name module:js-data.LinkedCollection\n * @see DataStore\n * @see LinkedCollection\n * @since 3.0.0\n * @type {Constructor}\n */\nimport LinkedCollection from './LinkedCollection'\n\n/**\n * JSData's {@link Mapper} class. The core of the ORM.\n *\n * @example Recommended use\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @example Create Mapper manually\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @name module:js-data.Mapper\n * @see Container\n * @see Mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @type {Constructor}\n */\nimport Mapper from './Mapper'\n\n/**\n * JSData's {@link Query} class. Used by the {@link Collection} component.\n *\n * @name module:js-data.Query\n * @see Query\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Query from './Query'\n\n/**\n * JSData's {@link Record} class.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n *\n * @name module:js-data.Record\n * @see Record\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#record\",\"Components of JSData: Record\"]\n * @type {Constructor}\n */\nimport Record from './Record'\n\n/**\n * JSData's {@link Schema} class. Implements http://json-schema.org/draft-04.\n *\n * @example\n * import {Container, Schema} from 'js-data'\n * const userSchema = new Schema({\n * properties: {\n * id: { type: 'string' },\n * name: { type: 'string' }\n * }\n * })\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: userSchema\n * })\n *\n * @name module:js-data.Schema\n * @see Schema\n * @see http://json-schema.org/\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#schema\",\"Components of JSData: schema\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/schemas\",\"JSData's Schema Syntax\"]\n * @type {Constructor}\n */\nimport Schema from './Schema'\n\n/**\n * JSData's {@link Settable} class.\n *\n * @example\n * import {Settable} from 'js-data'\n * const obj = new Settable()\n * obj.set('secret', 'value')\n * console.log(JSON.stringify(obj)) // {}\n *\n * @name module:js-data.Settable\n * @see Settable\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Settable from './Settable'\n\n/**\n * JSData's {@link SimpleStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * const store = new SimpleStore()\n *\n * @name module:js-data.SimpleStore\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @type {Constructor}\n */\nimport SimpleStore from './SimpleStore'\n\nexport * from './decorators'\n\nexport {\n Collection,\n Component,\n Container,\n DataStore,\n Index,\n LinkedCollection,\n Mapper,\n Query,\n Record,\n Schema,\n Settable,\n SimpleStore,\n utils\n}\n"],"names":["DOMAIN","Component","Query","belongsTo","hasMany","hasOne","creatingPath","noValidatePath","keepChangeHistoryPath","Schema","Record","_belongsTo","_hasMany","_hasOne","Mapper","Collection","props","LinkedCollection","SimpleStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA,IAAM,SAAS,OAAf;;AAEA,IAAM,WAAW,IAAI,CAArB;AACA,IAAM,cA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AO,IAAjB;OADF,MAEO;kBACK,MAAV;;;UAGE,WAAW,QAAQ,MAAnB,IAA6B,OAAK,eAAtC,EAAuD;YAC/C,QAAQ,MAAM,SAAN,CAAgB,IAAhB,CAAd;cACM,OAAN,GAAgB,IAAhB;cACM,eAAN,CAAsB,OAAK,SAAL,CAAe,IAAf,CAAtB,EAA4C,KAA5C,EAAmD,UAAC,GAAD,EAAS;kBAClD,OAAR,CAAgB,UAAC,MAAD,EAAY;kBACpB,GAAN,CAAU,MAAV,EAAkB,IAAI,UAAtB,EAAkC,SAAlC;WADF;SADF;;aAMK,MAAP;KAjBK,CAAP;;CA5WJ;;AAkYA,kBAAeA,cAAY,MAAZ,CAAmBF,OAAnB,CAAf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtdA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,AAAO,IAAM,UAAU,gBAAhB;;;;;;;;;;;;;;;AAeP,AAEA;;;;;;;;;;;;;AAaA,AAEA;;;;;;;;;;;;;;;;AAgBA,AAEA;;;;;;;;;;;;;;;AAeA,AAEA;;;;;;;;;;;;;;AAcA,AAEA;;;;;;;;AAQA,AAEA;;;;;;;;;;;AAWA,AAEA;;;;;;;;;;;;;;;;;;;;AAoBA,AAEA;;;;;;;;AAQA,AAEA;;;;;;;;;;;;;;;AAeA,AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,AAEA;;;;;;;;;;;;;;AAcA,AAEA;;;;;;;;;;;;;GAcA,AAEA,AAEA;;"} \ No newline at end of file +{"version":3,"file":"js-data.es2015.js","sources":["../src/utils.js","../src/Settable.js","../src/Component.js","../src/Query.js","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.js","../src/Relation.js","../src/Relation/BelongsTo.js","../src/Relation/HasMany.js","../src/Relation/HasOne.js","../src/relations.js","../src/decorators.js","../src/Record.js","../src/Schema.js","../src/Mapper.js","../src/Container.js","../src/SimpleStore.js","../src/LinkedCollection.js","../src/DataStore.js","../src/index.js"],"sourcesContent":["/**\n * Utility methods used by JSData.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @namespace utils\n * @type {Object}\n */\n\nconst DOMAIN = 'utils'\n\nconst INFINITY = 1 / 0\nconst MAX_INTEGER = 1.7976931348623157e+308\nconst BOOL_TAG = '[object Boolean]'\nconst DATE_TAG = '[object Date]'\nconst FUNC_TAG = '[object Function]'\nconst NUMBER_TAG = '[object Number]'\nconst OBJECT_TAG = '[object Object]'\nconst REGEXP_TAG = '[object RegExp]'\nconst STRING_TAG = '[object String]'\nconst objToString = Object.prototype.toString\nconst PATH = /^(.+)\\.(.+)$/\n\nconst ERRORS = {\n '400' () { return `expected: ${arguments[0]}, found: ${arguments[2] ? arguments[1] : typeof arguments[1]}` },\n '404' () { return `${arguments[0]} not found` }\n}\n\nconst toInteger = function (value) {\n if (!value) {\n return 0\n }\n // Coerce to number\n value = +value\n if (value === INFINITY || value === -INFINITY) {\n const sign = (value < 0 ? -1 : 1)\n return sign * MAX_INTEGER\n }\n const remainder = value % 1\n return value === value ? (remainder ? value - remainder : value) : 0 // eslint-disable-line\n}\n\nconst toStr = function (value) {\n return objToString.call(value)\n}\n\nconst isPlainObject = function (value) {\n return (!!value && typeof value === 'object' && value.constructor === Object)\n}\n\nconst mkdirP = function (object, path) {\n if (!path) {\n return object\n }\n const parts = path.split('.')\n parts.forEach(function (key) {\n if (!object[key]) {\n object[key] = {}\n }\n object = object[key]\n })\n return object\n}\n\nconst utils = {\n /**\n * Reference to the Promise constructor used by JSData. Defaults to\n * `window.Promise` or `global.Promise`.\n *\n * @example Make JSData use a different `Promise` constructor\n * import Promise from 'bluebird'\n * import {utils} from 'js-data'\n * utils.Promise = Promise\n *\n * @name utils.Promise\n * @since 3.0.0\n * @type {Function}\n */\n Promise: Promise,\n\n /**\n * Shallow copy properties that meet the following criteria from `src` to\n * `dest`:\n *\n * - own enumerable\n * - not a function\n * - does not start with \"_\"\n *\n * @method utils._\n * @param {Object} dest Destination object.\n * @param {Object} src Source object.\n * @private\n * @since 3.0.0\n */\n _ (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (key && dest[key] === undefined && !utils.isFunction(value) && key.indexOf('_') !== 0) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Recursively iterates over relations found in `opts.with`.\n *\n * @method utils._forRelation\n * @param {Object} opts Configuration options.\n * @param {Relation} def Relation definition.\n * @param {Function} fn Callback function.\n * @param {*} [thisArg] Execution context for the callback function.\n * @private\n * @since 3.0.0\n */\n _forRelation (opts, def, fn, thisArg) {\n const relationName = def.relation\n let containedName = null\n let index\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n if ((index = utils._getIndex(opts.with, relationName)) >= 0) {\n containedName = relationName\n } else if ((index = utils._getIndex(opts.with, def.localField)) >= 0) {\n containedName = def.localField\n }\n\n if (opts.withAll) {\n fn.call(thisArg, def, {})\n return\n } else if (!containedName) {\n return\n }\n let optsCopy = {}\n utils.fillIn(optsCopy, def.getRelation())\n utils.fillIn(optsCopy, opts)\n optsCopy.with = opts.with.slice()\n optsCopy._activeWith = optsCopy.with.splice(index, 1)[0]\n optsCopy.with.forEach(function (relation, i) {\n if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {\n optsCopy.with[i] = relation.substr(containedName.length + 1)\n } else {\n optsCopy.with[i] = ''\n }\n })\n fn.call(thisArg, def, optsCopy)\n },\n\n /**\n * Find the index of a relation in the given list\n *\n * @method utils._getIndex\n * @param {string[]} list List to search.\n * @param {string} relation Relation to find.\n * @private\n * @returns {number}\n */\n _getIndex (list, relation) {\n let index = -1\n list.forEach(function (_relation, i) {\n if (_relation === relation) {\n index = i\n return false\n } else if (utils.isObject(_relation)) {\n if (_relation.relation === relation) {\n index = i\n return false\n }\n }\n })\n return index\n },\n\n /**\n * Define hidden (non-enumerable), writable properties on `target` from the\n * provided `props`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {}\n * utils.addHiddenPropsToTarget(Cat.prototype, {\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat.say() // \"meow\"\n *\n * @method utils.addHiddenPropsToTarget\n * @param {Object} target That to which `props` should be added.\n * @param {Object} props Properties to be added to `target`.\n * @since 3.0.0\n */\n addHiddenPropsToTarget (target, props) {\n const map = {}\n Object.keys(props).forEach(function (propName) {\n const descriptor = Object.getOwnPropertyDescriptor(props, propName)\n\n descriptor.enumerable = false\n map[propName] = descriptor\n })\n Object.defineProperties(target, map)\n },\n\n /**\n * Return whether the two objects are deeply different.\n *\n * @example\n * import {utils} from 'js-data'\n * utils.areDifferent({}, {}) // false\n * utils.areDifferent({ a: 1 }, { a: 1 }) // false\n * utils.areDifferent({ foo: 'bar' }, {}) // true\n *\n * @method utils.areDifferent\n * @param {Object} a Base object.\n * @param {Object} b Comparison object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Whether the two objects are deeply different.\n * @see utils.diffObjects\n * @since 3.0.0\n */\n areDifferent (newObject, oldObject, opts) {\n opts || (opts = {})\n const diff = utils.diffObjects(newObject, oldObject, opts)\n const diffCount = Object.keys(diff.added).length +\n Object.keys(diff.removed).length +\n Object.keys(diff.changed).length\n return diffCount > 0\n },\n\n /**\n * Verified that the given constructor is being invoked via `new`, as opposed\n * to just being called like a normal function.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {\n * utils.classCallCheck(this, Cat)\n * }\n * const cat = new Cat() // this is ok\n * Cat() // this throws an error\n *\n * @method utils.classCallCheck\n * @param {*} instance Instance that is being constructed.\n * @param {Constructor} ctor Constructor function used to construct the\n * instance.\n * @since 3.0.0\n * @throws {Error} Throws an error if the constructor is being improperly\n * invoked.\n */\n classCallCheck (instance, ctor) {\n if (!(instance instanceof ctor)) {\n throw utils.err(`${ctor.name}`)(500, 'Cannot call a class as a function')\n }\n },\n\n /**\n * Deep copy a value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' } }\n * const b = utils.copy(a)\n * a === b // false\n * utils.areDifferent(a, b) // false\n *\n * @param {*} from Value to deep copy.\n * @param {*} [to] Destination object for the copy operation.\n * @param {*} [stackFrom] For internal use.\n * @param {*} [stackTo] For internal use.\n * @param {string[]|RegExp[]} [blacklist] List of strings or RegExp of\n * properties to skip.\n * @param {boolean} [plain] Whether to make a plain copy (don't try to use\n * original prototype).\n * @returns {*} Deep copy of `from`.\n * @since 3.0.0\n */\n copy (from, to, stackFrom, stackTo, blacklist, plain) {\n if (!to) {\n to = from\n if (from) {\n if (utils.isArray(from)) {\n to = utils.copy(from, [], stackFrom, stackTo, blacklist, plain)\n } else if (utils.isDate(from)) {\n to = new Date(from.getTime())\n } else if (utils.isRegExp(from)) {\n to = new RegExp(from.source, from.toString().match(/[^/]*$/)[0])\n to.lastIndex = from.lastIndex\n } else if (utils.isObject(from)) {\n if (plain) {\n to = utils.copy(from, {}, stackFrom, stackTo, blacklist, plain)\n } else {\n to = utils.copy(from, Object.create(Object.getPrototypeOf(from)), stackFrom, stackTo, blacklist, plain)\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(500, 'Cannot copy! Source and destination are identical.')\n }\n\n stackFrom = stackFrom || []\n stackTo = stackTo || []\n\n if (utils.isObject(from)) {\n let index = stackFrom.indexOf(from)\n if (index !== -1) {\n return stackTo[index]\n }\n\n stackFrom.push(from)\n stackTo.push(to)\n }\n\n let result\n if (utils.isArray(from)) {\n let i\n to.length = 0\n for (i = 0; i < from.length; i++) {\n result = utils.copy(from[i], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[i])) {\n stackFrom.push(from[i])\n stackTo.push(result)\n }\n to.push(result)\n }\n } else {\n if (utils.isArray(to)) {\n to.length = 0\n } else {\n utils.forOwn(to, function (value, key) {\n delete to[key]\n })\n }\n for (var key in from) {\n if (from.hasOwnProperty(key)) {\n if (utils.isBlacklisted(key, blacklist)) {\n continue\n }\n result = utils.copy(from[key], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[key])) {\n stackFrom.push(from[key])\n stackTo.push(result)\n }\n to[key] = result\n }\n }\n }\n }\n return to\n },\n\n /**\n * Recursively shallow fill in own enumerable properties from `source` to\n * `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"bip\"}\n *\n * @method utils.deepFillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n deepFillIn (dest, source) {\n if (source) {\n utils.forOwn(source, function (value, key) {\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepFillIn(existing, value)\n } else if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n }\n return dest\n },\n\n /**\n * Recursively shallow copy enumerable properties from `source` to `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"boop\"}\n *\n * @method utils.deepMixIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepFillIn\n * @since 3.0.0\n */\n deepMixIn (dest, source) {\n if (source) {\n for (var key in source) {\n const value = source[key]\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepMixIn(existing, value)\n } else {\n dest[key] = value\n }\n }\n }\n return dest\n },\n\n /**\n * Return a diff of the base object to the comparison object.\n *\n * @example\n * import {utils} from 'js-data'\n * const oldObject = { foo: 'bar', a: 1234 }\n * const newObject = { beep: 'boop', a: 5678 }\n * const diff = utils.diffObjects(oldObject, newObject)\n * console.log(diff.added) // {\"beep\":\"boop\"}\n * console.log(diff.changed) // {\"a\":5678}\n * console.log(diff.removed) // {\"foo\":undefined}\n *\n * @method utils.diffObjects\n * @param {Object} newObject Comparison object.\n * @param {Object} oldObject Base object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} The diff from the base object to the comparison object.\n * @see utils.areDifferent\n * @since 3.0.0\n */\n diffObjects (newObject, oldObject, opts) {\n opts || (opts = {})\n let equalsFn = opts.equalsFn\n let blacklist = opts.ignore\n const diff = {\n added: {},\n changed: {},\n removed: {}\n }\n if (!utils.isFunction(equalsFn)) {\n equalsFn = utils.deepEqual\n }\n\n const newKeys = Object.keys(newObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n const oldKeys = Object.keys(oldObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n\n // Check for properties that were added or changed\n newKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (equalsFn(oldValue, newValue)) {\n return\n }\n if (oldValue === undefined) {\n diff.added[key] = newValue\n } else {\n diff.changed[key] = newValue\n }\n })\n\n // Check for properties that were removed\n oldKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (newValue === undefined && oldValue !== undefined) {\n diff.removed[key] = undefined\n }\n })\n\n return diff\n },\n\n /**\n * Return whether the two values are equal according to the `==` operator.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.equal(1,1)) // true\n * console.log(utils.equal(1,'1')) // true\n * console.log(utils.equal(93, 66)) // false\n *\n * @method utils.equal\n * @param {*} a First value in the comparison.\n * @param {*} b Second value in the comparison.\n * @returns {boolean} Whether the two values are equal according to `==`.\n * @since 3.0.0\n */\n equal (a, b) {\n return a == b // eslint-disable-line\n },\n\n /**\n * Produce a factory function for making Error objects with the provided\n * metadata. Used throughout the various js-data components.\n *\n * @example\n * import {utils} from 'js-data'\n * const errorFactory = utils.err('domain', 'target')\n * const error400 = errorFactory(400, 'expected type', 'actual type')\n * console.log(error400) // [Error: [domain:target] expected: expected type, found: string\nhttp://www.js-data.io/v3.0/docs/errors#400]\n * @method utils.err\n * @param {string} domain Namespace.\n * @param {string} target Target.\n * @returns {Function} Factory function.\n * @since 3.0.0\n */\n err (domain, target) {\n return function (code) {\n const prefix = `[${domain}:${target}] `\n let message = ERRORS[code].apply(null, Array.prototype.slice.call(arguments, 1))\n message = `${prefix}${message}\nhttp://www.js-data.io/v3.0/docs/errors#${code}`\n return new Error(message)\n }\n },\n\n /**\n * Add eventing capabilities into the target object.\n *\n * @example\n * import {utils} from 'js-data'\n * const user = { name: 'John' }\n * utils.eventify(user)\n * user.on('foo', () => console.log(arguments))\n * user.emit('foo', 1, 'bar') // should log to console values (1, \"bar\")\n *\n * @method utils.eventify\n * @param {Object} target Target object.\n * @param {Function} [getter] Custom getter for retrieving the object's event\n * listeners.\n * @param {Function} [setter] Custom setter for setting the object's event\n * listeners.\n * @since 3.0.0\n */\n eventify (target, getter, setter) {\n target = target || this\n let _events = {}\n if (!getter && !setter) {\n getter = function () { return _events }\n setter = function (value) { _events = value }\n }\n Object.defineProperties(target, {\n emit: {\n value (...args) {\n const events = getter.call(this) || {}\n const type = args.shift()\n let listeners = events[type] || []\n let i\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n listeners = events.all || []\n args.unshift(type)\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n }\n },\n off: {\n value (type, func) {\n const events = getter.call(this)\n const listeners = events[type]\n if (!listeners) {\n setter.call(this, {})\n } else if (func) {\n for (let i = 0; i < listeners.length; i++) {\n if (listeners[i].f === func) {\n listeners.splice(i, 1)\n break\n }\n }\n } else {\n listeners.splice(0, listeners.length)\n }\n }\n },\n on: {\n value (type, func, thisArg) {\n if (!getter.call(this)) {\n setter.call(this, {})\n }\n const events = getter.call(this)\n events[type] = events[type] || []\n events[type].push({\n c: thisArg,\n f: func\n })\n }\n }\n })\n },\n\n /**\n * Used for sublcassing. Invoke this method in the context of a superclass to\n * to produce a subclass based on `props` and `classProps`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Animal () {}\n * Animal.extend = utils.extend\n * const Cat = Animal.extend({\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat instanceof Animal // true\n * cat instanceof Cat // true\n * cat.say() // \"meow\"\n *\n * @method utils.extend\n * @param {Object} props Instance properties for the subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to use as the subclass.\n * @param {Object} props Static properties for the subclass.\n * @returns {Constructor} A new subclass.\n * @since 3.0.0\n */\n extend (props, classProps) {\n const superClass = this\n let subClass\n\n props || (props = {})\n classProps || (classProps = {})\n\n if (props.hasOwnProperty('constructor')) {\n subClass = props.constructor\n delete props.constructor\n } else {\n subClass = function (...args) {\n utils.classCallCheck(this, subClass)\n superClass.apply(this, args)\n }\n }\n\n // Setup inheritance of instance members\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n configurable: true,\n enumerable: false,\n value: subClass,\n writable: true\n }\n })\n\n const obj = Object\n // Setup inheritance of static members\n if (obj.setPrototypeOf) {\n obj.setPrototypeOf(subClass, superClass)\n } else if (classProps.strictEs6Class) {\n subClass.__proto__ = superClass // eslint-disable-line\n } else {\n utils.forOwn(superClass, function (value, key) {\n subClass[key] = value\n })\n }\n if (!subClass.hasOwnProperty('__super__')) {\n Object.defineProperty(subClass, '__super__', {\n configurable: true,\n value: superClass\n })\n }\n\n utils.addHiddenPropsToTarget(subClass.prototype, props)\n utils.fillIn(subClass, classProps)\n\n return subClass\n },\n\n /**\n * Shallow copy own enumerable properties from `src` to `dest` that are on\n * `src` but are missing from `dest.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: 'bar', beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.fillIn(b, a)\n * console.log(b) // {\"foo\":\"bar\",\"beep\":\"bip\"}\n *\n * @method utils.fillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.deepFillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n fillIn (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Find the last index of an item in an array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = { name: 'John', age: 20 }\n * const sara = { name: 'Sara', age: 25 }\n * const dan = { name: 'Dan', age: 20 }\n * const users = [john, sara, dan]\n *\n * console.log(utils.findIndex(users, (user) => user.age === 25)) // 1\n * console.log(utils.findIndex(users, (user) => user.age > 19)) // 2\n * console.log(utils.findIndex(users, (user) => user.name === 'John')) // 0\n * console.log(utils.findIndex(users, (user) => user.name === 'Jimmy')) // -1\n *\n * @method utils.findIndex\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n * @returns {number} Index if found or -1 if not found.\n * @since 3.0.0\n */\n findIndex (array, fn) {\n let index = -1\n if (!array) {\n return index\n }\n array.forEach(function (record, i) {\n if (fn(record)) {\n index = i\n return false\n }\n })\n return index\n },\n\n /**\n * Recursively iterate over a {@link Mapper}'s relations according to\n * `opts.with`.\n *\n * @method utils.forEachRelation\n * @param {Mapper} mapper Mapper.\n * @param {Object} opts Configuration options.\n * @param {Function} fn Callback function.\n * @param {*} thisArg Execution context for the callback function.\n * @since 3.0.0\n */\n forEachRelation (mapper, opts, fn, thisArg) {\n const relationList = mapper.relationList || []\n if (!relationList.length) {\n return\n }\n relationList.forEach(function (def) {\n utils._forRelation(opts, def, fn, thisArg)\n })\n },\n\n /**\n * Iterate over an object's own enumerable properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { b: 1, c: 4 }\n * let sum = 0\n * utils.forOwn(a, function (value, key) {\n * sum += value\n * })\n * console.log(sum) // 5\n *\n * @method utils.forOwn\n * @param {Object} object The object whose properties are to be enumerated.\n * @param {Function} fn Iteration function.\n * @param {Object} [thisArg] Content to which to bind `fn`.\n * @since 3.0.0\n */\n forOwn (obj, fn, thisArg) {\n const keys = Object.keys(obj)\n const len = keys.length\n let i\n for (i = 0; i < len; i++) {\n fn.call(thisArg, obj[keys[i]], keys[i], obj)\n }\n },\n\n /**\n * Proxy for `JSON.parse`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = utils.fromJson('{\"name\" : \"John\"}')\n * console.log(a) // { name: 'John' }\n *\n * @method utils.fromJson\n * @param {string} json JSON to parse.\n * @returns {Object} Parsed object.\n * @see utils.toJson\n * @since 3.0.0\n */\n fromJson (json) {\n return utils.isString(json) ? JSON.parse(json) : json\n },\n\n /**\n * Retrieve the specified property from the given object. Supports retrieving\n * nested properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * console.log(utils.get(a, 'beep')) // \"boop\"\n * console.log(utils.get(a, 'foo.bar')) // \"baz\"\n *\n * @method utils.get\n * @param {Object} object Object from which to retrieve a property's value.\n * @param {string} prop Property to retrieve.\n * @returns {*} Value of the specified property.\n * @see utils.set\n * @since 3.0.0\n */\n 'get': function (object, prop) {\n if (!prop) {\n return\n }\n const parts = prop.split('.')\n const last = parts.pop()\n\n while (prop = parts.shift()) { // eslint-disable-line\n object = object[prop]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n return object[last]\n },\n\n /**\n * Return the superclass for the given instance or subclass. If an instance is\n * provided, then finds the parent class of the instance's constructor.\n *\n * @example\n * import {utils} from 'js-data'\n * // using ES2015 classes\n * class Foo {}\n * class Bar extends Foo {}\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * // using Function constructor with utils.extend\n * function Foo () {}\n * Foo.extend = utils.extend\n * const Bar = Foo.extend()\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * @method utils.getSuper\n * @param {Object|Function} instance Instance or constructor.\n * @param {boolean} [isCtor=false] Whether `instance` is a constructor.\n * @returns {Constructor} The superclass (grandparent constructor).\n * @since 3.0.0\n */\n getSuper (instance, isCtor) {\n const ctor = isCtor ? instance : instance.constructor\n if (ctor.hasOwnProperty('__super__')) {\n return ctor.__super__\n }\n return Object.getPrototypeOf(ctor) || ctor.__proto__ // eslint-disable-line\n },\n\n /**\n * Return the intersection of two arrays.\n *\n * @example\n * import {utils} from 'js-data'\n * const arrA = ['green', 'red', 'blue', 'red']\n * const arrB = ['green', 'yellow', 'red']\n * const intersected = utils.intersection(arrA, arrB)\n *\n * console.log(intersected) // ['green', 'red'])\n *\n * @method utils.intersection\n * @param {Array} array1 First array.\n * @param {Array} array2 Second array.\n * @returns {Array} Array of elements common to both arrays.\n * @since 3.0.0\n */\n intersection (array1, array2) {\n if (!array1 || !array2) {\n return []\n }\n const result = []\n let item\n let i\n const len = array1.length\n for (i = 0; i < len; i++) {\n item = array1[i]\n if (result.indexOf(item) !== -1) {\n continue\n }\n if (array2.indexOf(item) !== -1) {\n result.push(item)\n }\n }\n return result\n },\n\n /**\n * Proxy for `Array.isArray`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = [1,2,3,4,5]\n * const b = { foo: \"bar\" }\n * console.log(utils.isArray(a)) // true\n * console.log(utils.isArray(b)) // false\n *\n * @method utils.isArray\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an array.\n * @since 3.0.0\n */\n isArray: Array.isArray,\n\n /**\n * Return whether `prop` is matched by any string or regular expression in\n * `blacklist`.\n *\n * @example\n * import {utils} from 'js-data'\n * const blacklist = [/^\\$hashKey/g, /^_/g, 'id']\n * console.log(utils.isBlacklisted(\"$hashKey\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"id\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"_myProp\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"my_id\", blacklist)) // false\n *\n * @method utils.isBlacklisted\n * @param {string} prop The name of a property to check.\n * @param {Array} blacklist Array of strings and regular expressions.\n * @returns {boolean} Whether `prop` was matched.\n * @since 3.0.0\n */\n isBlacklisted (prop, blacklist) {\n if (!blacklist || !blacklist.length) {\n return false\n }\n let matches\n for (var i = 0; i < blacklist.length; i++) {\n if ((toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) || blacklist[i] === prop) {\n matches = prop\n return !!matches\n }\n }\n return !!matches\n },\n\n /**\n * Return whether the provided value is a boolean.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = true\n * const b = { foo: \"bar\" }\n * console.log(utils.isBoolean(a)) // true\n * console.log(utils.isBoolean(b)) // false\n *\n * @method utils.isBoolean\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a boolean.\n * @since 3.0.0\n */\n isBoolean (value) {\n return toStr(value) === BOOL_TAG\n },\n\n /**\n * Return whether the provided value is a date.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = new Date()\n * const b = { foo: \"bar\" }\n * console.log(utils.isDate(a)) // true\n * console.log(utils.isDate(b)) // false\n *\n * @method utils.isDate\n * @param {*} value The value to test.\n * @returns {Date} Whether the provided value is a date.\n * @since 3.0.0\n */\n isDate (value) {\n return (value && typeof value === 'object' && toStr(value) === DATE_TAG)\n },\n\n /**\n * Return whether the provided value is a function.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = function (){ console.log('foo bar')}\n * const b = { foo: \"bar\" }\n * console.log(utils.isFunction(a)) // true\n * console.log(utils.isFunction(b)) // false\n *\n * @method utils.isFunction\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a function.\n * @since 3.0.0\n */\n isFunction (value) {\n return typeof value === 'function' || (value && toStr(value) === FUNC_TAG)\n },\n\n /**\n * Return whether the provided value is an integer.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = 1.25\n * const c = '1'\n * console.log(utils.isInteger(a)) // true\n * console.log(utils.isInteger(b)) // false\n * console.log(utils.isInteger(c)) // false\n *\n * @method utils.isInteger\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an integer.\n * @since 3.0.0\n */\n isInteger (value) {\n return toStr(value) === NUMBER_TAG && value == toInteger(value) // eslint-disable-line\n },\n\n /**\n * Return whether the provided value is `null`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = null\n * const b = { foo: \"bar\" }\n * console.log(utils.isNull(a)) // true\n * console.log(utils.isNull(b)) // false\n *\n * @method utils.isNull\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is `null`.\n * @since 3.0.0\n */\n isNull (value) {\n return value === null\n },\n\n /**\n * Return whether the provided value is a number.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = -1.25\n * const c = '1'\n * console.log(utils.isNumber(a)) // true\n * console.log(utils.isNumber(b)) // true\n * console.log(utils.isNumber(c)) // false\n *\n * @method utils.isNumber\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a number.\n * @since 3.0.0\n */\n isNumber (value) {\n const type = typeof value\n return type === 'number' || (value && type === 'object' && toStr(value) === NUMBER_TAG)\n },\n\n /**\n * Return whether the provided value is an object.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\" }\n * const b = 'foo bar'\n * console.log(utils.isObject(a)) // true\n * console.log(utils.isObject(b)) // false\n *\n * @method utils.isObject\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an object.\n * @since 3.0.0\n */\n isObject (value) {\n return toStr(value) === OBJECT_TAG\n },\n\n /**\n * Return whether the provided value is a regular expression.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = /^\\$.+$/ig\n * const b = new RegExp('^\\$.+$', 'ig')\n * const c = { foo: \"bar\" }\n * console.log(utils.isRegExp(a)) // true\n * console.log(utils.isRegExp(b)) // true\n * console.log(utils.isRegExp(c)) // false\n *\n * @method utils.isRegExp\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a regular expression.\n * @since 3.0.0\n */\n isRegExp (value) {\n return toStr(value) === REGEXP_TAG\n },\n\n /**\n * Return whether the provided value is a string or a number.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isSorN('')) // true\n * console.log(utils.isSorN(-1.65)) // true\n * console.log(utils.isSorN('my string')) // true\n * console.log(utils.isSorN({})) // false\n * console.log(utils.isSorN([1,2,4])) // false\n *\n * @method utils.isSorN\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string or a number.\n * @since 3.0.0\n */\n isSorN (value) {\n return utils.isString(value) || utils.isNumber(value)\n },\n\n /**\n * Return whether the provided value is a string.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('')) // true\n * console.log(utils.isString('my string')) // true\n * console.log(utils.isString(100)) // false\n * console.log(utils.isString([1,2,4])) // false\n *\n * @method utils.isString\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string.\n * @since 3.0.0\n */\n isString (value) {\n return typeof value === 'string' || (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n },\n\n /**\n * Return whether the provided value is a `undefined`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = undefined\n * const b = { foo: \"bar\"}\n * console.log(utils.isUndefined(a)) // true\n * console.log(utils.isUndefined(b.baz)) // true\n * console.log(utils.isUndefined(b)) // false\n * console.log(utils.isUndefined(b.foo)) // false\n *\n * @method utils.isUndefined\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a `undefined`.\n * @since 3.0.0\n */\n isUndefined (value) {\n return value === undefined\n },\n\n /**\n * Mix in logging capabilities to the target.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\"}\n *\n * // Add standard logging to an object\n * utils.logify(a)\n * a.log('info', 'test log info') // output 'test log info' to console.\n *\n * // Toggle debug output of an object\n * a.dbg('test debug output') // does not output because debug is off.\n * a.debug = true\n * a.dbg('test debug output') // output 'test debug output' to console.\n *\n * @method utils.logify\n * @param {*} target The target.\n * @since 3.0.0\n */\n logify (target) {\n utils.addHiddenPropsToTarget(target, {\n dbg (...args) {\n if (utils.isFunction(this.log)) {\n this.log('debug', ...args)\n }\n },\n log (level, ...args) {\n if (level && !args.length) {\n args.push(level)\n level = 'debug'\n }\n if (level === 'debug' && !this.debug) {\n return\n }\n const prefix = `${level.toUpperCase()}: (${this.name || this.constructor.name})`\n if (utils.isFunction(console[level])) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n }\n })\n },\n\n /**\n * Adds the given record to the provided array only if it's not already in the\n * array.\n *\n * @example\n * import {utils} from 'js-data'\n * const colors = ['red', 'green', 'yellow']\n *\n * console.log(colors.length) // 3\n * utils.noDupeAdd(colors, 'red')\n * console.log(colors.length) // 3, red already exists\n *\n * utils.noDupeAdd(colors, 'blue')\n * console.log(colors.length) // 4, blue was added\n *\n * @method utils.noDupeAdd\n * @param {Array} array The array.\n * @param {*} record The value to add.\n * @param {Function} fn Callback function passed to {@link utils.findIndex}.\n * @since 3.0.0\n */\n noDupeAdd (array, record, fn) {\n if (!array) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index < 0) {\n array.push(record)\n }\n },\n\n /**\n * Return a shallow copy of the provided object, minus the properties\n * specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.omit(a, ['$hashKey'])\n * console.log(b) // { name: 'John' }\n *\n * @method utils.omit\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to skip.\n * @returns {Object} Shallow copy of `props`, minus `keys`.\n * @since 3.0.0\n */\n omit (props, keys) {\n const _props = {}\n utils.forOwn(props, function (value, key) {\n if (keys.indexOf(key) === -1) {\n _props[key] = value\n }\n })\n return _props\n },\n\n /**\n * Return a shallow copy of the provided object, but only include the\n * properties specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.pick(a, ['$hashKey'])\n * console.log(b) // { $hashKey: 1214910 }\n *\n * @method utils.pick\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to keep.\n * @returns {Object} Shallow copy of `props`, but only including `keys`.\n * @since 3.0.0\n */\n pick (props, keys) {\n return keys.reduce((map, key) => {\n map[key] = props[key]\n return map\n }, {})\n },\n\n /**\n * Return a plain copy of the given value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John' }\n * let b = utils.plainCopy(a)\n * console.log(a === b) // false\n *\n * @method utils.plainCopy\n * @param {*} value The value to copy.\n * @returns {*} Plain copy of `value`.\n * @see utils.copy\n * @since 3.0.0\n */\n plainCopy (value) {\n return utils.copy(value, undefined, undefined, undefined, undefined, true)\n },\n\n /**\n * Shortcut for `utils.Promise.reject(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.reject(\"Testing static reject\").then(function(data) {\n * // not called\n * }).catch(function(reason) {\n * console.log(reason); // \"Testing static reject\"\n * })\n *\n * @method utils.reject\n * @param {*} [value] Value with which to reject the Promise.\n * @returns {Promise} Promise reject with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n reject (value) {\n return utils.Promise.reject(value)\n },\n\n /**\n * Remove the last item found in array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const colors = ['red', 'green', 'yellow', 'red']\n * utils.remove(colors, (color) => color === 'red')\n * console.log(colors) // ['red', 'green', 'yellow']\n *\n * @method utils.remove\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n */\n remove (array, fn) {\n if (!array || !array.length) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index >= 0) {\n array.splice(index, 1) // todo should this be recursive?\n }\n },\n\n /**\n * Shortcut for `utils.Promise.resolve(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.resolve(\"Testing static resolve\").then(function(data) {\n * console.log(data); // \"Testing static resolve\"\n * }).catch(function(reason) {\n * // not called\n * })\n *\n * @param {*} [value] Value with which to resolve the Promise.\n * @returns {Promise} Promise resolved with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n resolve (value) {\n return utils.Promise.resolve(value)\n },\n\n /**\n * Set the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n * // set value by key\n * utils.set(john, 'id', 98)\n * console.log(john.id) // 98\n *\n * // set value by path\n * utils.set(john, 'parent.id', 20)\n * console.log(john.parent.id) // 20\n *\n * // set value by path/value map\n * utils.set(john, {\n * 'id': 1098,\n * 'parent': { id: 1020 },\n * 'parent.age': '55'\n * })\n * console.log(john.id) // 1098\n * console.log(john.parent.id) // 1020\n * console.log(john.parent.age) // 55\n *\n * @method utils.set\n * @param {Object} object The object on which to set a property.\n * @param {(string|Object)} path The key or path to the property. Can also\n * pass in an object of path/value pairs, which will all be set on the target\n * object.\n * @param {*} [value] The value to set.\n */\n set: function (object, path, value) {\n if (utils.isObject(path)) {\n utils.forOwn(path, function (value, _path) {\n utils.set(object, _path, value)\n })\n } else {\n const parts = PATH.exec(path)\n if (parts) {\n mkdirP(object, parts[1])[parts[2]] = value\n } else {\n object[path] = value\n }\n }\n },\n\n /**\n * Check whether the two provided objects are deeply equal.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const objA = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * const objB = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * console.log(utils.deepEqual(a,b)) // true\n * objB.nested.colors.add('yellow') // make a change to a nested object's array\n * console.log(utils.deepEqual(a,b)) // false\n *\n * @method utils.deepEqual\n * @param {Object} a First object in the comparison.\n * @param {Object} b Second object in the comparison.\n * @returns {boolean} Whether the two provided objects are deeply equal.\n * @see utils.equal\n * @since 3.0.0\n */\n deepEqual (a, b) {\n if (a === b) {\n return true\n }\n let _equal = true\n if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n _equal = _equal && utils.deepEqual(value, b[key])\n })\n if (!_equal) {\n return _equal\n }\n utils.forOwn(b, function (value, key) {\n _equal = _equal && utils.deepEqual(value, a[key])\n })\n } else if (utils.isArray(a) && utils.isArray(b)) {\n a.forEach(function (value, i) {\n _equal = _equal && utils.deepEqual(value, b[i])\n if (!_equal) {\n return false\n }\n })\n } else {\n return false\n }\n return _equal\n },\n\n /**\n * Proxy for `JSON.stringify`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = { name: 'John' }\n * let jsonVal = utils.toJson(a)\n * console.log(jsonVal) // '{\"name\" : \"John\"}'\n *\n * @method utils.toJson\n * @param {*} value Value to serialize to JSON.\n * @returns {string} JSON string.\n * @see utils.fromJson\n * @since 3.0.0\n */\n toJson: JSON.stringify,\n\n /**\n * Unset the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n *\n * utils.unset(john, age)\n * utils.unset(john, parent.age)\n *\n * console.log(john.age) // null\n * console.log(john.parent.age) // null\n *\n * @method utils.unset\n * @param {Object} object The object from which to delete the property.\n * @param {string} path The key or path to the property.\n * @see utils.set\n * @since 3.0.0\n */\n unset (object, path) {\n const parts = path.split('.')\n const last = parts.pop()\n\n while (path = parts.shift()) { // eslint-disable-line\n object = object[path]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n object[last] = undefined\n }\n}\n\nexport const safeSetProp = function (record, field, value) {\n if (record && record._set) {\n record._set(`props.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport const safeSetLink = function (record, field, value) {\n if (record && record._set) {\n record._set(`links.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport default utils\n","import utils from './utils'\n\n/**\n * A base class which gives instances private properties.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Settable.extend} for an example of using {@link Settable} as a\n * base class.\n *\n *```javascript\n * import {Settable} from 'js-data'\n * ```\n *\n * @class Settable\n * @returns {Settable} A new {@link Settable} instance.\n * @since 3.0.0\n */\nexport default function Settable () {\n const _props = {}\n Object.defineProperties(this, {\n /**\n * Get a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method Settable#_get\n * @param {string} key The property to retrieve.\n * @returns {*} The value of the property.\n * @since 3.0.0\n */\n _get: { value (key) { return utils.get(_props, key) } },\n\n /**\n * Set a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_set\n * @param {(string|Object)} key The key or path to the property. Can also\n * pass in an object of key/value pairs, which will all be set on the instance.\n * @param {*} [value] The value to set.\n * @since 3.0.0\n */\n _set: { value (key, value) { return utils.set(_props, key, value) } },\n\n /**\n * Unset a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_unset\n * @param {string} key The property to unset.\n * @since 3.0.0\n */\n _unset: { value (key) { return utils.unset(_props, key) } }\n })\n}\n\n/**\n * Create a subclass of this Settable:\n *\n * @example Settable.extend\n * // Normally you would do: import {Settable} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Settable} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSettableClass extends Settable {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSettable = new CustomSettableClass()\n * console.log(customSettable.foo())\n * console.log(CustomSettableClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSettableClass = Settable.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSettable = new OtherSettableClass()\n * console.log(otherSettable.foo())\n * console.log(OtherSettableClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSettableClass () {\n * Settable.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Settable.extend({\n * constructor: AnotherSettableClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSettable = new AnotherSettableClass()\n * console.log(anotherSettable.created_at)\n * console.log(anotherSettable.foo())\n * console.log(AnotherSettableClass.beep())\n *\n * @method Settable.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Settable class.\n * @since 3.0.0\n */\nSettable.extend = utils.extend\n","import utils from './utils'\nimport Settable from './Settable'\n\n/**\n * The base class from which all JSData components inherit some basic\n * functionality.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Component.extend} for an example of using {@link Component} as a\n * base class.\n *\n *```javascript\n * import {Component} from 'js-data'\n * ```\n *\n * @class Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @returns {Component} A new {@link Component} instance.\n * @since 3.0.0\n */\nfunction Component (opts) {\n Settable.call(this)\n opts || (opts = {})\n\n /**\n * Whether to enable debug-level logs for this component. Anything that\n * extends `Component` inherits this option and the corresponding logging\n * functionality.\n *\n * @example Component#debug\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const component = new Component()\n * component.log('debug', 'some message') // nothing gets logged\n * // Display debug logs:\n * component.debug = true\n * component.log('debug', 'other message') // this DOES get logged\n *\n * @default false\n * @name Component#debug\n * @since 3.0.0\n * @type {boolean}\n */\n this.debug = opts.hasOwnProperty('debug') ? !!opts.debug : false\n\n /**\n * Event listeners attached to this Component. __Do not modify.__ Use\n * {@link Component#on} and {@link Component#off} instead.\n *\n * @name Component#_listeners\n * @instance\n * @since 3.0.0\n * @type {Object}\n */\n Object.defineProperty(this, '_listeners', { value: {}, writable: true })\n}\n\nexport default Settable.extend({\n constructor: Component\n})\n\n/**\n * Create a subclass of this Component:\n *\n * @example Component.extend\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomComponentClass extends Component {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customComponent = new CustomComponentClass()\n * console.log(customComponent.foo())\n * console.log(CustomComponentClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherComponentClass = Component.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherComponent = new OtherComponentClass()\n * console.log(otherComponent.foo())\n * console.log(OtherComponentClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherComponentClass () {\n * Component.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Component.extend({\n * constructor: AnotherComponentClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherComponent = new AnotherComponentClass()\n * console.log(anotherComponent.created_at)\n * console.log(anotherComponent.foo())\n * console.log(AnotherComponentClass.beep())\n *\n * @method Component.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Component class.\n * @since 3.0.0\n */\nComponent.extend = utils.extend\n\n/**\n * Log the provided values at the \"debug\" level. Debug-level logs are only\n * logged if {@link Component#debug} is `true`.\n *\n * `.dbg(...)` is shorthand for `.log('debug', ...)`.\n *\n * @method Component#dbg\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\n/**\n * Log the provided values. By default sends values to `console[level]`.\n * Debug-level logs are only logged if {@link Component#debug} is `true`.\n *\n * Will attempt to use appropriate `console` methods if they are available.\n *\n * @method Component#log\n * @param {string} level Log level.\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\nutils.logify(Component.prototype)\n\n/**\n * Register a new event listener on this Component.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a DataStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * collection.on('add', (records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * post.on('change', (record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method Component#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n/**\n * Remove an event listener from this Component. If no listener is provided,\n * then all listeners for the specified event will be removed. If no event is\n * specified then all listeners for all events will be removed.\n *\n * @example\n * // Remove a particular listener for a particular event\n * collection.off('add', handler)\n *\n * @example\n * // Remove all listeners for a particular event\n * record.off('change')\n *\n * @example\n * // Remove all listeners to all events\n * store.off()\n *\n * @method Component#off\n * @param {string} [event] Name of event to unsubsribe to.\n * @param {Function} [listener] Listener to remove.\n * @since 3.0.0\n */\n/**\n * Trigger an event on this Component.\n *\n * @example Component#emit\n * // import {Collection, DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, DataStore} = JSData\n *\n * const collection = new Collection()\n * collection.on('foo', function (msg) {\n * console.log(msg)\n * })\n * collection.emit('foo', 'bar')\n *\n * const store = new DataStore()\n * store.on('beep', function (msg) {\n * console.log(msg)\n * })\n * store.emit('beep', 'boop')\n *\n * @method Component#emit\n * @param {string} event Name of event to emit.\n * @param {...*} [args] Arguments to pass to any listeners.\n * @since 3.0.0\n */\nutils.eventify(\n Component.prototype,\n function () {\n return this._listeners\n },\n function (value) {\n this._listeners = value\n }\n)\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Query'\nconst INDEX_ERR = 'Index inaccessible after first operation'\n\n// Reserved words used by JSData's Query Syntax\nconst reserved = {\n limit: '',\n offset: '',\n orderBy: '',\n skip: '',\n sort: '',\n where: ''\n}\n\n// Used by our JavaScript implementation of the LIKE operator\nconst escapeRegExp = /([.*+?^=!:${}()|[\\]/\\\\])/g\nconst percentRegExp = /%/g\nconst underscoreRegExp = /_/g\nconst escape = function (pattern) {\n return pattern.replace(escapeRegExp, '\\\\$1')\n}\n\n/**\n * A class used by the {@link Collection} class to build queries to be executed\n * against the collection's data. An instance of `Query` is returned by\n * {@link Collection#query}. Query instances are typically short-lived, and you\n * shouldn't have to create them yourself. Just use {@link Collection#query}.\n *\n * ```javascript\n * import {Query} from 'js-data'\n * ```\n *\n * @example\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const drafts = store.query('post').filter({ status: 'draft' }).limit(2).run()\n * console.log(drafts)\n *\n * @class Query\n * @extends Component\n * @param {Collection} collection The collection on which this query operates.\n * @since 3.0.0\n */\nfunction Query (collection) {\n utils.classCallCheck(this, Query)\n\n /**\n * The {@link Collection} on which this query operates.\n *\n * @name Query#collection\n * @since 3.0.0\n * @type {Collection}\n */\n this.collection = collection\n\n /**\n * The current data result of this query.\n *\n * @name Query#data\n * @since 3.0.0\n * @type {Array}\n */\n this.data = null\n}\n\nexport default Component.extend({\n constructor: Query,\n\n _applyWhereFromObject (where) {\n const fields = []\n const ops = []\n const predicates = []\n utils.forOwn(where, (clause, field) => {\n if (!utils.isObject(clause)) {\n clause = {\n '==': clause\n }\n }\n utils.forOwn(clause, (expr, op) => {\n fields.push(field)\n ops.push(op)\n predicates.push(expr)\n })\n })\n return {\n fields,\n ops,\n predicates\n }\n },\n\n _applyWhereFromArray (where) {\n const groups = []\n where.forEach((_where, i) => {\n if (utils.isString(_where)) {\n return\n }\n const prev = where[i - 1]\n const parser = utils.isArray(_where) ? this._applyWhereFromArray : this._applyWhereFromObject\n const group = parser.call(this, _where)\n if (prev === 'or') {\n group.isOr = true\n }\n groups.push(group)\n })\n groups.isArray = true\n return groups\n },\n\n _testObjectGroup (keep, first, group, item) {\n let i\n const fields = group.fields\n const ops = group.ops\n const predicates = group.predicates\n const len = ops.length\n for (i = 0; i < len; i++) {\n let op = ops[i]\n const isOr = op.charAt(0) === '|'\n op = isOr ? op.substr(1) : op\n const expr = this.evaluate(utils.get(item, fields[i]), op, predicates[i])\n if (expr !== undefined) {\n keep = first ? expr : (isOr ? keep || expr : keep && expr)\n }\n first = false\n }\n return { keep, first }\n },\n\n _testArrayGroup (keep, first, groups, item) {\n let i\n const len = groups.length\n for (i = 0; i < len; i++) {\n const group = groups[i]\n const parser = group.isArray ? this._testArrayGroup : this._testObjectGroup\n const result = parser.call(this, true, true, group, item)\n if (groups[i - 1]) {\n if (group.isOr) {\n keep = keep || result.keep\n } else {\n keep = keep && result.keep\n }\n } else {\n keep = result.keep\n }\n first = result.first\n }\n return { keep, first }\n },\n\n /**\n * Find all entities between two boundaries.\n *\n * @example Get the users ages 18 to 30.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between(18, 30, { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @example Same as above.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between([18], [30], { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @method Query#between\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#between`)(500, 'Cannot access index')\n }\n this.data = this.collection.getIndex(opts.index).between(leftKeys, rightKeys, opts)\n return this\n },\n\n /**\n * The comparison function used by the {@link Query} class.\n *\n * @method Query#compare\n * @param {Array} orderBy An orderBy clause used for sorting and sub-sorting.\n * @param {number} index The index of the current orderBy clause being used.\n * @param {*} a The first item in the comparison.\n * @param {*} b The second item in the comparison.\n * @returns {number} -1 if `b` should preceed `a`. 0 if `a` and `b` are equal.\n * 1 if `a` should preceed `b`.\n * @since 3.0.0\n */\n compare (orderBy, index, a, b) {\n const def = orderBy[index]\n let cA = utils.get(a, def[0])\n let cB = utils.get(b, def[0])\n if (cA && utils.isString(cA)) {\n cA = cA.toUpperCase()\n }\n if (cB && utils.isString(cB)) {\n cB = cB.toUpperCase()\n }\n if (a === undefined) {\n a = null\n }\n if (b === undefined) {\n b = null\n }\n if (def[1].toUpperCase() === 'DESC') {\n const temp = cB\n cB = cA\n cA = temp\n }\n if (cA < cB) {\n return -1\n } else if (cA > cB) {\n return 1\n } else {\n if (index < orderBy.length - 1) {\n return this.compare(orderBy, index + 1, a, b)\n } else {\n return 0\n }\n }\n },\n\n /**\n * Predicate evaluation function used by the {@link Query} class.\n *\n * @method Query#evaluate\n * @param {*} value The value to evaluate.\n * @param {string} op The operator to use in this evaluation.\n * @param {*} predicate The predicate to use in this evaluation.\n * @returns {boolean} Whether the value passed the evaluation or not.\n * @since 3.0.0\n */\n evaluate (value, op, predicate) {\n const ops = this.constructor.ops\n if (ops[op]) {\n return ops[op](value, predicate)\n }\n if (op.indexOf('like') === 0) {\n return this.like(predicate, op.substr(4)).exec(value) !== null\n } else if (op.indexOf('notLike') === 0) {\n return this.like(predicate, op.substr(7)).exec(value) === null\n }\n },\n\n /**\n * Find the record or records that match the provided query or are accepted by\n * the provided filter function.\n *\n * @example Get the draft posts by authors younger than 30\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * let results = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * }).run()\n * console.log(results)\n *\n * @example Use a custom filter function\n * const posts = query.filter(function (post) {\n * return post.isReady()\n * }).run()\n *\n * @method Query#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Function} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n filter (query, thisArg) {\n /**\n * Selection query as defined by JSData's [Query Syntax][querysyntax].\n *\n * [querysyntax]: http://www.js-data.io/v3.0/docs/query-syntax\n *\n * @example Empty \"findAll\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @example Empty \"filter\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = store.filter('post')\n * console.log(posts) // [...]\n *\n * @example Complex \"filter\" query\n * const PAGE_SIZE = 2\n * let currentPage = 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * // Retrieve a filtered page of blog posts\n * // Would typically replace filter with findAll\n * store.filter('post', {\n * where: {\n * status: {\n * // WHERE status = 'published'\n * '==': 'published'\n * },\n * author: {\n * // AND author IN ('bob', 'alice')\n * 'in': ['bob', 'alice'],\n * // OR author IN ('karen')\n * '|in': ['karen']\n * }\n * },\n * orderBy: [\n * // ORDER BY date_published DESC,\n * ['date_published', 'DESC'],\n * // ORDER BY title ASC\n * ['title', 'ASC']\n * ],\n * // LIMIT 2\n * limit: PAGE_SIZE,\n * // SKIP 4\n * offset: PAGE_SIZE * (currentPage - 1)\n * })\n *\n * @namespace query\n * @property {number} [limit] See {@link query.limit}.\n * @property {number} [offset] See {@link query.offset}.\n * @property {string|Array[]} [orderBy] See {@link query.orderBy}.\n * @property {number} [skip] Alias for {@link query.offset}.\n * @property {string|Array[]} [sort] Alias for {@link query.orderBy}.\n * @property {Object} [where] See {@link query.where}.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/query-syntax\",\"JSData's Query Syntax\"]\n */\n query || (query = {})\n this.getData()\n if (utils.isObject(query)) {\n let where = {}\n\n /**\n * Filtering criteria. Records that do not meet this criteria will be exluded\n * from the result.\n *\n * @example Return posts where author is at least 32 years old\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * where: {\n * age: {\n * '>=': 30\n * }\n * }\n * })\n * console.log(results)\n *\n * @name query.where\n * @type {Object}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isObject(query.where) || utils.isArray(query.where)) {\n where = query.where\n }\n utils.forOwn(query, function (value, key) {\n if (!(key in reserved) && !(key in where)) {\n where[key] = {\n '==': value\n }\n }\n })\n let groups\n\n // Apply filter for each field\n if (utils.isObject(where) && Object.keys(where).length !== 0) {\n groups = this._applyWhereFromArray([where])\n } else if (utils.isArray(where)) {\n groups = this._applyWhereFromArray(where)\n }\n\n if (groups) {\n this.data = this.data.filter((item, i) => this._testArrayGroup(true, true, groups, item).keep)\n }\n\n // Sort\n let orderBy = query.orderBy || query.sort\n\n if (utils.isString(orderBy)) {\n orderBy = [\n [orderBy, 'ASC']\n ]\n }\n if (!utils.isArray(orderBy)) {\n orderBy = null\n }\n\n /**\n * Determines how records should be ordered in the result.\n *\n * @example Order posts by `author` then by `id` descending \n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * orderBy:[['author','ASC'],['id','DESC']]\n * })\n * console.log(results)\n *\n * @name query.orderBy\n * @type {string|Array[]}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (orderBy) {\n let index = 0\n orderBy.forEach(function (def, i) {\n if (utils.isString(def)) {\n orderBy[i] = [def, 'ASC']\n }\n })\n this.data.sort((a, b) => this.compare(orderBy, index, a, b))\n }\n\n /**\n * Number of records to skip.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n *\n * @name query.offset\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.skip)) {\n this.skip(query.skip)\n } else if (utils.isNumber(query.offset)) {\n this.skip(query.offset)\n }\n\n /**\n * Maximum number of records to retrieve.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n * @name query.limit\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.limit)) {\n this.limit(query.limit)\n }\n } else if (utils.isFunction(query)) {\n this.data = this.data.filter(query, thisArg)\n }\n return this\n },\n\n /**\n * Iterate over all entities.\n *\n * @method Query#forEach\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n forEach (forEachFn, thisArg) {\n this.getData().forEach(forEachFn, thisArg)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided key.\n *\n * @example Get the entity whose primary key is 25.\n * const entities = query.get(25).run()\n *\n * @example Same as above.\n * const entities = query.get([25]).run()\n *\n * @example Get all users who are active and have the \"admin\" role.\n * const activeAdmins = query.get(['active', 'admin'], {\n * index: 'activityAndRoles'\n * }).run()\n *\n * @example Get all entities that match a certain weather condition.\n * const niceDays = query.get(['sunny', 'humid', 'calm'], {\n * index: 'weatherConditions'\n * }).run()\n *\n * @method Query#get\n * @param {Array} keyList Key(s) defining the entity to retrieve. If\n * `keyList` is not an array (i.e. for a single-value key), it will be\n * wrapped in an array.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.string] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n get (keyList, opts) {\n keyList || (keyList = [])\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#get`)(500, INDEX_ERR)\n }\n if (keyList && !utils.isArray(keyList)) {\n keyList = [keyList]\n }\n if (!keyList.length) {\n this.getData()\n return this\n }\n this.data = this.collection.getIndex(opts.index).get(keyList)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided keyLists.\n *\n * @example Get the posts where \"status\" is \"draft\" or \"inReview\".\n * const posts = query.getAll('draft', 'inReview', { index: 'status' }).run()\n *\n * @example Same as above.\n * const posts = query.getAll(['draft'], ['inReview'], { index: 'status' }).run()\n *\n * @method Query#getAll\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * entities matching each keyList will be retrieved. If no keyLists are\n * provided, all entities will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n getAll (...args) {\n let opts = {}\n if (this.data) {\n throw utils.err(`${DOMAIN}#getAll`)(500, INDEX_ERR)\n }\n if (!args.length || args.length === 1 && utils.isObject(args[0])) {\n this.getData()\n return this\n } else if (args.length && utils.isObject(args[args.length - 1])) {\n opts = args[args.length - 1]\n args.pop()\n }\n const collection = this.collection\n const index = collection.getIndex(opts.index)\n this.data = []\n args.forEach((keyList) => {\n this.data = this.data.concat(index.get(keyList))\n })\n return this\n },\n\n /**\n * Return the current data result of this query.\n *\n * @method Query#getData\n * @returns {Array} The data in this query.\n * @since 3.0.0\n */\n getData () {\n if (!this.data) {\n this.data = this.collection.index.getAll()\n }\n return this.data\n },\n\n /**\n * Implementation used by the `like` operator. Takes a pattern and flags and\n * returns a `RegExp` instance that can test strings.\n *\n * @method Query#like\n * @param {string} pattern Testing pattern.\n * @param {string} flags Flags for the regular expression.\n * @returns {RegExp} Regular expression for testing strings.\n * @since 3.0.0\n */\n like (pattern, flags) {\n return new RegExp(`^${(escape(pattern).replace(percentRegExp, '.*').replace(underscoreRegExp, '.'))}$`, flags)\n },\n\n /**\n * Limit the result.\n *\n * @example Get only the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').limit(2).run()\n * console.log(results)\n *\n * @method Query#limit\n * @param {number} num The maximum number of entities to keep in the result.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n limit (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#limit`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n this.data = data.slice(0, Math.min(data.length, num))\n return this\n },\n\n /**\n * Apply a mapping function to the result data.\n *\n * @example\n * // Return the age of all users\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const ages = store.query('user').map((user) => {\n * return user.age\n * }).run()\n * console.log(ages)\n *\n * @method Query#map\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n map (mapFn, thisArg) {\n this.data = this.getData().map(mapFn, thisArg)\n return this\n },\n\n /**\n * Return the result of calling the specified function on each item in this\n * collection's main index.\n *\n * @example\n * const stringAges = UserCollection.query().mapCall('toString').run()\n *\n * @method Query#mapCall\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n mapCall (funcName, ...args) {\n this.data = this.getData().map(function (item) {\n return item[funcName](...args)\n })\n return this\n },\n\n /**\n * Complete the execution of the query and return the resulting data.\n *\n * @method Query#run\n * @returns {Array} The result of executing this query.\n * @since 3.0.0\n */\n run () {\n const data = this.data\n this.data = null\n return data\n },\n\n /**\n * Skip a number of results.\n *\n * @example Get all but the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').skip(2).run()\n * console.log(results)\n *\n * @method Query#skip\n * @param {number} num The number of entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n skip (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#skip`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n if (num < data.length) {\n this.data = data.slice(num)\n } else {\n this.data = []\n }\n return this\n }\n}, {\n /**\n * The filtering operators supported by {@link Query#filter}, and which are\n * implemented by adapters (for the most part).\n *\n * @example Variant 1\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n *\n * @example Variant 2\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n * @example Variant 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * status: 'published'\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Variant 4\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Multiple operators\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const myPublishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * },\n * user_id: {\n * '==': currentUser.id\n * }\n * }\n * })\n *\n * console.log(myPublishedPosts)\n *\n * @name Query.ops\n * @property {Function} == Equality operator.\n * @property {Function} != Inequality operator.\n * @property {Function} > Greater than operator.\n * @property {Function} >= Greater than (inclusive) operator.\n * @property {Function} < Less than operator.\n * @property {Function} <= Less than (inclusive) operator.\n * @property {Function} isectEmpty Operator that asserts that the intersection\n * between two arrays is empty.\n * @property {Function} isectNotEmpty Operator that asserts that the\n * intersection between two arrays is __not__ empty.\n * @property {Function} in Operator that asserts whether a value is in an\n * array.\n * @property {Function} notIn Operator that asserts whether a value is __not__\n * in an array.\n * @property {Function} contains Operator that asserts whether an array\n * contains a value.\n * @property {Function} notContains Operator that asserts whether an array\n * does __not__ contain a value.\n * @since 3.0.0\n * @type {Object}\n */\n ops: {\n '=': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '==': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '===': function (value, predicate) {\n return value === predicate\n },\n '!=': function (value, predicate) {\n return value != predicate // eslint-disable-line\n },\n '!==': function (value, predicate) {\n return value !== predicate\n },\n '>': function (value, predicate) {\n return value > predicate\n },\n '>=': function (value, predicate) {\n return value >= predicate\n },\n '<': function (value, predicate) {\n return value < predicate\n },\n '<=': function (value, predicate) {\n return value <= predicate\n },\n 'isectEmpty': function (value, predicate) {\n return !utils.intersection((value || []), (predicate || [])).length\n },\n 'isectNotEmpty': function (value, predicate) {\n return utils.intersection((value || []), (predicate || [])).length\n },\n 'in': function (value, predicate) {\n return predicate.indexOf(value) !== -1\n },\n 'notIn': function (value, predicate) {\n return predicate.indexOf(value) === -1\n },\n 'contains': function (value, predicate) {\n return (value || []).indexOf(predicate) !== -1\n },\n 'notContains': function (value, predicate) {\n return (value || []).indexOf(predicate) === -1\n }\n }\n})\n\n/**\n * Create a subclass of this Query:\n * @example Query.extend\n * // Normally you would do: import {Query} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Query} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomQueryClass extends Query {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customQuery = new CustomQueryClass()\n * console.log(customQuery.foo())\n * console.log(CustomQueryClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherQueryClass = Query.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherQuery = new OtherQueryClass()\n * console.log(otherQuery.foo())\n * console.log(OtherQueryClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherQueryClass (collection) {\n * Query.call(this, collection)\n * this.created_at = new Date().getTime()\n * }\n * Query.extend({\n * constructor: AnotherQueryClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherQuery = new AnotherQueryClass()\n * console.log(anotherQuery.created_at)\n * console.log(anotherQuery.foo())\n * console.log(AnotherQueryClass.beep())\n *\n * @method Query.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Query class.\n * @since 3.0.0\n */\n","export function sort (a, b, hashCode) {\n // Short-circuit comparison if a and b are strictly equal\n // This is absolutely necessary for indexed objects that\n // don't have the idAttribute field\n if (a === b) {\n return 0\n }\n if (hashCode) {\n a = hashCode(a)\n b = hashCode(b)\n }\n if ((a === null && b === null) || (a === undefined && b === undefined)) {\n return -1\n }\n\n if (a === null || a === undefined) {\n return -1\n }\n\n if (b === null || b === undefined) {\n return 1\n }\n\n if (a < b) {\n return -1\n }\n\n if (a > b) {\n return 1\n }\n\n return 0\n}\n\nexport function insertAt (array, index, value) {\n array.splice(index, 0, value)\n return array\n}\n\nexport function removeAt (array, index) {\n array.splice(index, 1)\n return array\n}\n\nexport function binarySearch (array, value, field) {\n let lo = 0\n let hi = array.length\n let compared\n let mid\n\n while (lo < hi) {\n mid = ((lo + hi) / 2) | 0\n compared = sort(value, array[mid], field)\n if (compared === 0) {\n return {\n found: true,\n index: mid\n }\n } else if (compared < 0) {\n hi = mid\n } else {\n lo = mid + 1\n }\n }\n\n return {\n found: false,\n index: hi\n }\n}\n","// Copyright (c) 2015, InternalFX.\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose with or\n// without fee is hereby granted, provided that the above copyright notice and this permission\n// notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO\n// THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT\n// SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR\n// ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE\n// USE OR PERFORMANCE OF THIS SOFTWARE.\n\n// Modifications\n// Copyright 2015-2016 Jason Dobry\n//\n// Summary of modifications:\n// Reworked dependencies so as to re-use code already in js-data\n// Removed unused code\nimport utils from '../../src/utils'\nimport {binarySearch, insertAt, removeAt} from './_utils'\n\nexport default function Index (fieldList, opts) {\n utils.classCallCheck(this, Index)\n fieldList || (fieldList = [])\n\n if (!utils.isArray(fieldList)) {\n throw new Error('fieldList must be an array.')\n }\n\n opts || (opts = {})\n this.fieldList = fieldList\n this.fieldGetter = opts.fieldGetter\n this.hashCode = opts.hashCode\n this.isIndex = true\n this.keys = []\n this.values = []\n}\n\nutils.addHiddenPropsToTarget(Index.prototype, {\n 'set' (keyList, value) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n let dataLocation = binarySearch(this.values[pos.index], value, this.hashCode)\n if (!dataLocation.found) {\n insertAt(this.values[pos.index], dataLocation.index, value)\n }\n } else {\n insertAt(this.keys, pos.index, key)\n insertAt(this.values, pos.index, [value])\n }\n } else {\n if (pos.found) {\n this.values[pos.index].set(keyList, value)\n } else {\n insertAt(this.keys, pos.index, key)\n let newIndex = new Index([], { hashCode: this.hashCode })\n newIndex.set(keyList, value)\n insertAt(this.values, pos.index, newIndex)\n }\n }\n },\n\n 'get' (keyList) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n if (this.values[pos.index].isIndex) {\n return this.values[pos.index].getAll()\n } else {\n return this.values[pos.index].slice()\n }\n } else {\n return []\n }\n } else {\n if (pos.found) {\n return this.values[pos.index].get(keyList)\n } else {\n return []\n }\n }\n },\n\n getAll (opts) {\n opts || (opts = {})\n let results = []\n const values = this.values\n if (opts.order === 'desc') {\n for (let i = values.length - 1; i >= 0; i--) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n } else {\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n }\n return results\n },\n\n visitAll (cb, thisArg) {\n this.values.forEach(function (value) {\n if (value.isIndex) {\n value.visitAll(cb, thisArg)\n } else {\n value.forEach(cb, thisArg)\n }\n })\n },\n\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (!utils.isArray(leftKeys)) {\n leftKeys = [leftKeys]\n }\n if (!utils.isArray(rightKeys)) {\n rightKeys = [rightKeys]\n }\n utils.fillIn(opts, {\n leftInclusive: true,\n rightInclusive: false,\n limit: undefined,\n offset: 0\n })\n\n let results = this._between(leftKeys, rightKeys, opts)\n\n if (opts.limit) {\n return results.slice(opts.offset, opts.limit + opts.offset)\n } else {\n return results.slice(opts.offset)\n }\n },\n\n _between (leftKeys, rightKeys, opts) {\n let results = []\n\n let leftKey = leftKeys.shift()\n let rightKey = rightKeys.shift()\n\n let pos\n\n if (leftKey !== undefined) {\n pos = binarySearch(this.keys, leftKey)\n } else {\n pos = {\n found: false,\n index: 0\n }\n }\n\n if (leftKeys.length === 0) {\n if (pos.found && opts.leftInclusive === false) {\n pos.index += 1\n }\n\n for (let i = pos.index; i < this.keys.length; i += 1) {\n if (rightKey !== undefined) {\n if (opts.rightInclusive) {\n if (this.keys[i] > rightKey) { break }\n } else {\n if (this.keys[i] >= rightKey) { break }\n }\n }\n\n if (this.values[i].isIndex) {\n results = results.concat(this.values[i].getAll())\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n } else {\n for (let i = pos.index; i < this.keys.length; i += 1) {\n let currKey = this.keys[i]\n if (currKey > rightKey) { break }\n\n if (this.values[i].isIndex) {\n if (currKey === leftKey) {\n results = results.concat(this.values[i]._between(utils.copy(leftKeys), rightKeys.map(function () { return undefined }), opts))\n } else if (currKey === rightKey) {\n results = results.concat(this.values[i]._between(leftKeys.map(function () { return undefined }), utils.copy(rightKeys), opts))\n } else {\n results = results.concat(this.values[i].getAll())\n }\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n }\n\n if (opts.limit) {\n return results.slice(0, opts.limit + opts.offset)\n } else {\n return results\n }\n },\n\n peek () {\n if (this.values.length) {\n if (this.values[0].isIndex) {\n return this.values[0].peek()\n } else {\n return this.values[0]\n }\n }\n return []\n },\n\n clear () {\n this.keys = []\n this.values = []\n },\n\n insertRecord (data) {\n let keyList = this.fieldList.map(function (field) {\n if (utils.isFunction(field)) {\n return field(data) || undefined\n } else {\n return data[field] || undefined\n }\n })\n this.set(keyList, data)\n },\n\n removeRecord (data) {\n let removed\n const isUnique = this.hashCode(data) !== undefined\n this.values.forEach((value, i) => {\n if (value.isIndex) {\n if (value.removeRecord(data)) {\n if (value.keys.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n } else {\n let dataLocation = {}\n if (this.keys[i] === undefined || !isUnique) {\n for (let j = value.length - 1; j >= 0; j--) {\n if (value[j] === data) {\n dataLocation = {\n found: true,\n index: j\n }\n break\n }\n }\n } else if (isUnique) {\n dataLocation = binarySearch(value, data, this.hashCode)\n }\n if (dataLocation.found) {\n removeAt(value, dataLocation.index)\n if (value.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n }\n })\n return removed ? data : undefined\n },\n\n updateRecord (data) {\n const removed = this.removeRecord(data)\n if (removed !== undefined) {\n this.insertRecord(data)\n }\n }\n})\n","import utils from './utils'\nimport Component from './Component'\nimport Query from './Query'\nimport Index from '../lib/mindex/index'\n\nconst DOMAIN = 'Collection'\n\nconst COLLECTION_DEFAULTS = {\n /**\n * Whether to call {@link Record#commit} on records that are added to the\n * collection and already exist in the collection.\n *\n * @name Collection#commitOnMerge\n * @type {boolean}\n * @default true\n */\n commitOnMerge: true,\n\n /**\n * Whether record events should bubble up and be emitted by the collection.\n *\n * @name Collection#emitRecordEvents\n * @type {boolean}\n * @default true\n */\n emitRecordEvents: true,\n\n /**\n * Field to be used as the unique identifier for records in this collection.\n * Defaults to `\"id\"` unless {@link Collection#mapper} is set, in which case\n * this will default to {@link Mapper#idAttribute}.\n *\n * @name Collection#idAttribute\n * @type {string}\n * @default \"id\"\n */\n idAttribute: 'id',\n\n /**\n * What to do when inserting a record into this Collection that shares a\n * primary key with a record already in this Collection.\n *\n * Possible values:\n * merge\n * replace\n *\n * Merge:\n *\n * Recursively shallow copy properties from the new record onto the existing\n * record.\n *\n * Replace:\n *\n * Shallow copy top-level properties from the new record onto the existing\n * record. Any top-level own properties of the existing record that are _not_\n * on the new record will be removed.\n *\n * @name Collection#onConflict\n * @type {string}\n * @default \"merge\"\n */\n onConflict: 'merge'\n}\n\n/**\n * An ordered set of {@link Record} instances.\n *\n * @example Collection#constructor\n * // import {Collection, Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const user1 = new Record({ id: 1 })\n * const user2 = new Record({ id: 2 })\n * const UserCollection = new Collection([user1, user2])\n * console.log(UserCollection.get(1) === user1)\n *\n * @class Collection\n * @extends Component\n * @param {Array} [records] Initial set of records to insert into the\n * collection.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.commitOnMerge] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.idAttribute] See {@link Collection#idAttribute}.\n * @param {string} [opts.onConflict=\"merge\"] See {@link Collection#onConflict}.\n * @param {string} [opts.mapper] See {@link Collection#mapper}.\n * @since 3.0.0\n */\nfunction Collection (records, opts) {\n utils.classCallCheck(this, Collection)\n Component.call(this, opts)\n\n if (records && !utils.isArray(records)) {\n opts = records\n records = []\n }\n if (utils.isString(opts)) {\n opts = { idAttribute: opts }\n }\n\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * Default Mapper for this collection. Optional. If a Mapper is provided, then\n * the collection will use the {@link Mapper#idAttribute} setting, and will\n * wrap records in {@link Mapper#recordClass}.\n *\n * @example Collection#mapper\n * // Normally you would do: import {Collection, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const myMapper = new MyMapperClass({ name: 'myMapper' })\n * const collection = new Collection(null, { mapper: myMapper })\n *\n * @name Collection#mapper\n * @type {Mapper}\n * @default null\n * @since 3.0.0\n */\n mapper: {\n value: undefined,\n writable: true\n },\n // Query class used by this collection\n queryClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(COLLECTION_DEFAULTS))\n\n if (!this.queryClass) {\n this.queryClass = Query\n }\n\n const idAttribute = this.recordId()\n\n Object.defineProperties(this, {\n /**\n * The main index, which uses @{link Collection#recordId} as the key.\n *\n * @name Collection#index\n * @type {Index}\n */\n index: {\n value: new Index([idAttribute], {\n hashCode (obj) {\n return utils.get(obj, idAttribute)\n }\n })\n },\n\n /**\n * Object that holds the secondary indexes of this collection.\n *\n * @name Collection#indexes\n * @type {Object.}\n */\n indexes: {\n value: {}\n }\n })\n\n // Insert initial data into the collection\n if (utils.isObject(records) || (utils.isArray(records) && records.length)) {\n this.add(records)\n }\n}\n\nexport default Component.extend({\n constructor: Collection,\n\n /**\n * Used to bind to events emitted by records in this Collection.\n *\n * @method Collection#_onRecordEvent\n * @since 3.0.0\n * @private\n * @param {...*} [arg] Args passed to {@link Collection#emit}.\n */\n _onRecordEvent (...args) {\n if (this.emitRecordEvents) {\n this.emit(...args)\n }\n },\n\n /**\n * Insert the provided record or records.\n *\n * If a record is already in the collection then the provided record will\n * either merge with or replace the existing record based on the value of the\n * `onConflict` option.\n *\n * The collection's secondary indexes will be updated as each record is\n * visited.\n *\n * @method Collection#add\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} data The record or records to insert.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.commitOnMerge=true] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.onConflict] See {@link Collection#onConflict}.\n * @returns {(Object|Object[]|Record|Record[])} The added record or records.\n */\n add (records, opts) {\n // Default values for arguments\n opts || (opts = {})\n\n // Fill in \"opts\" with the Collection's configuration\n utils._(opts, this)\n records = this.beforeAdd(records, opts) || records\n\n // Track whether just one record or an array of records is being inserted\n let singular = false\n const idAttribute = this.recordId()\n if (!utils.isArray(records)) {\n if (utils.isObject(records)) {\n records = [records]\n singular = true\n } else {\n throw utils.err(`${DOMAIN}#add`, 'records')(400, 'object or array', records)\n }\n }\n\n // Map the provided records to existing records.\n // New records will be inserted. If any records map to existing records,\n // they will be merged into the existing records according to the onConflict\n // option.\n records = records.map((record) => {\n let id = this.recordId(record)\n // Grab existing record if there is one\n const existing = id === undefined ? id : this.get(id)\n // If the currently visited record is just a reference to an existing\n // record, then there is nothing to be done. Exit early.\n if (record === existing) {\n return existing\n }\n\n if (existing) {\n // Here, the currently visited record corresponds to a record already\n // in the collection, so we need to merge them\n const onConflict = opts.onConflict || this.onConflict\n if (onConflict === 'merge') {\n utils.deepMixIn(existing, record)\n } else if (onConflict === 'replace') {\n utils.forOwn(existing, (value, key) => {\n if (key !== idAttribute && record[key] === undefined) {\n existing[key] = undefined\n }\n })\n existing.set(record)\n } else {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(400, 'one of (merge, replace)', onConflict, true)\n }\n record = existing\n if (opts.commitOnMerge && utils.isFunction(record.commit)) {\n record.commit()\n }\n // Update all indexes in the collection\n this.updateIndexes(record)\n } else {\n // Here, the currently visted record does not correspond to any record\n // in the collection, so (optionally) instantiate this record and insert\n // it into the collection\n record = this.mapper ? this.mapper.createRecord(record, opts) : record\n this.index.insertRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.insertRecord(record)\n })\n if (record && utils.isFunction(record.on)) {\n record.on('all', this._onRecordEvent, this)\n }\n }\n return record\n })\n // Finally, return the inserted data\n const result = singular ? records[0] : records\n if (!opts.silent) {\n this.emit('add', result)\n }\n return this.afterAdd(records, opts, result) || result\n },\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then {@link Collection#add} will return that same value.\n *\n * @method Collection#method\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} result The record or records\n * that were added to this Collection by {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n afterAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}. If this method returns\n * a value then {@link Collection#remove} will return that same value.\n *\n * @method Collection#afterRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n * @param {Object} record The result that will be returned by {@link Collection#remove}.\n */\n afterRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}. If this method\n * returns a value then {@link Collection#removeAll} will return that same\n * value.\n *\n * @method Collection#afterRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n * @param {Object} records The result that will be returned by {@link Collection#removeAll}.\n */\n afterRemoveAll () {},\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then the `records` argument in {@link Collection#add} will be\n * re-assigned to the returned value.\n *\n * @method Collection#beforeAdd\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} records The `records` argument passed to {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n beforeAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}.\n *\n * @method Collection#beforeRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n */\n beforeRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}.\n *\n * @method Collection#beforeRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n */\n beforeRemoveAll () {},\n\n /**\n * Find all records between two boundaries.\n *\n * Shortcut for `collection.query().between(18, 30, { index: 'age' }).run()`\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = collection.between(18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = collection.between([18], [30], { index: 'age' })\n *\n * @method Collection#between\n * @since 3.0.0\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting records to skip.\n * @returns {Object[]|Record[]} The result.\n */\n between (leftKeys, rightKeys, opts) {\n return this.query().between(leftKeys, rightKeys, opts).run()\n },\n\n /**\n * Create a new secondary index on the contents of the collection.\n *\n * @example\n * // Index users by age\n * collection.createIndex('age')\n *\n * @example\n * // Index users by status and role\n * collection.createIndex('statusAndRole', ['status', 'role'])\n *\n * @method Collection#createIndex\n * @since 3.0.0\n * @param {string} name The name of the new secondary index.\n * @param {string[]} [fieldList] Array of field names to use as the key or\n * compound key of the new secondary index. If no fieldList is provided, then\n * the name will also be the field that is used to index the collection.\n */\n createIndex (name, fieldList, opts) {\n if (utils.isString(name) && fieldList === undefined) {\n fieldList = [name]\n }\n opts || (opts = {})\n opts.hashCode || (opts.hashCode = (obj) => this.recordId(obj))\n const index = this.indexes[name] = new Index(fieldList, opts)\n this.index.visitAll(index.insertRecord, index)\n },\n\n /**\n * Find the record or records that match the provided query or pass the\n * provided filter function.\n *\n * Shortcut for `collection.query().filter(queryOrFn[, thisArg]).run()`\n *\n * @example Collection#filter\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const collection = new Collection([\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = collection.filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = collection.filter(function (post) {\n * return post.id % 2 === 0\n * })\n *\n * @method Collection#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Object} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Array} The result.\n * @see query\n * @since 3.0.0\n */\n filter (query, thisArg) {\n return this.query().filter(query, thisArg).run()\n },\n\n /**\n * Iterate over all records.\n *\n * @example\n * collection.forEach(function (record) {\n * // do something\n * })\n *\n * @method Collection#forEach\n * @since 3.0.0\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Array} The result.\n */\n forEach (cb, thisArg) {\n this.index.visitAll(cb, thisArg)\n },\n\n /**\n * Get the record with the given id.\n *\n * @method Collection#get\n * @since 3.0.0\n * @param {(string|number)} id The primary key of the record to get.\n * @returns {(Object|Record)} The record with the given id.\n */\n get (id) {\n const instances = this.query().get(id).run()\n return instances.length ? instances[0] : undefined\n },\n\n /**\n * Find the record or records that match the provided keyLists.\n *\n * Shortcut for `collection.query().getAll(keyList1, keyList2, ...).run()`\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = collection.getAll('draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = collection.getAll(['draft'], ['inReview'], { index: 'status' })\n *\n * @method Collection#getAll\n * @since 3.0.0\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * records matching each keyList will be retrieved. If no keyLists are\n * provided, all records will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Array} The result.\n */\n getAll (...args) {\n return this.query().getAll(...args).run()\n },\n\n /**\n * Return the index with the given name. If no name is provided, return the\n * main index. Throws an error if the specified index does not exist.\n *\n * @method Collection#getIndex\n * @since 3.0.0\n * @param {string} [name] The name of the index to retrieve.\n */\n getIndex (name) {\n const index = name ? this.indexes[name] : this.index\n if (!index) {\n throw utils.err(`${DOMAIN}#getIndex`, name)(404, 'index')\n }\n return index\n },\n\n /**\n * Limit the result.\n *\n * Shortcut for `collection.query().limit(maximumNumber).run()`\n *\n * @example\n * const posts = collection.limit(10)\n *\n * @method Collection#limit\n * @since 3.0.0\n * @param {number} num The maximum number of records to keep in the result.\n * @returns {Array} The result.\n */\n limit (num) {\n return this.query().limit(num).run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map(function (user) {\n * return user.name\n * })\n *\n * @method Collection#map\n * @since 3.0.0\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Array} The result of the mapping.\n */\n map (cb, thisArg) {\n const data = []\n this.index.visitAll(function (value) {\n data.push(cb.call(thisArg, value))\n })\n return data\n },\n\n /**\n * Return the result of calling the specified function on each record in this\n * collection's main index.\n *\n * @method Collection#mapCall\n * @since 3.0.0\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Array} The result.\n */\n mapCall (funcName, ...args) {\n const data = []\n this.index.visitAll(function (record) {\n data.push(record[funcName](...args))\n })\n return data\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#prune\n * @param {Object} [opts] Configuration options, passed to {@link Collection#removeAll}.\n * @since 3.0.0\n * @returns {Array} The removed records, if any.\n */\n prune (opts) {\n return this.removeAll(this.unsaved(), opts)\n },\n\n /**\n * Create a new query to be executed against the contents of the collection.\n * The result will be all or a subset of the contents of the collection.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * collection.query()\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method Collection#query\n * @since 3.0.0\n * @returns {Query} New query object.\n */\n query () {\n const Ctor = this.queryClass\n return new Ctor(this)\n },\n\n /**\n * Return the primary key of the given, or if no record is provided, return the\n * name of the field that holds the primary key of records in this Collection.\n *\n * @method Collection#recordId\n * @since 3.0.0\n * @param {(Object|Record)} [record] The record whose primary key is to be\n * returned.\n * @returns {(string|number)} Primary key or name of field that holds primary\n * key.\n */\n recordId (record) {\n if (record) {\n return utils.get(record, this.recordId())\n }\n return this.mapper ? this.mapper.idAttribute : this.idAttribute\n },\n\n /**\n * Reduce the data in the collection to a single value and return the result.\n *\n * @example\n * const totalVotes = collection.reduce(function (prev, record) {\n * return prev + record.upVotes + record.downVotes\n * }, 0)\n *\n * @method Collection#reduce\n * @since 3.0.0\n * @param {Function} cb Reduction callback.\n * @param {*} initialValue Initial value of the reduction.\n * @returns {*} The result.\n */\n reduce (cb, initialValue) {\n const data = this.getAll()\n return data.reduce(cb, initialValue)\n },\n\n /**\n * Remove the record with the given id from this Collection.\n *\n * @method Collection#remove\n * @since 3.0.0\n * @param {(string|number|object|Record)} idOrRecord The primary key of the\n * record to be removed, or a reference to the record that is to be removed.\n * @param {Object} [opts] Configuration options.\n * @returns {Object|Record} The removed record, if any.\n */\n remove (idOrRecord, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemove(idOrRecord, opts)\n let record = utils.isSorN(idOrRecord) ? this.get(idOrRecord) : idOrRecord\n\n // The record is in the collection, remove it\n if (utils.isObject(record)) {\n record = this.index.removeRecord(record)\n if (record) {\n utils.forOwn(this.indexes, function (index, name) {\n index.removeRecord(record)\n })\n if (utils.isFunction(record.off)) {\n record.off('all', this._onRecordEvent, this)\n if (!opts.silent) {\n this.emit('remove', record)\n }\n }\n }\n }\n return this.afterRemove(idOrRecord, opts, record) || record\n },\n\n /**\n * Remove from this collection the given records or the records selected by\n * the given \"query\".\n *\n * @method Collection#removeAll\n * @since 3.0.0\n * @param {Object|Object[]|Record[]} [queryOrRecords={}] Records to be removed or selection query. See {@link query}.\n * @param {Object} [queryOrRecords.where] See {@link query.where}.\n * @param {number} [queryOrRecords.offset] See {@link query.offset}.\n * @param {number} [queryOrRecords.limit] See {@link query.limit}.\n * @param {string|Array[]} [queryOrRecords.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object[]|Record[])} The removed records, if any.\n */\n removeAll (queryOrRecords, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemoveAll(queryOrRecords, opts)\n let records = utils.isArray(queryOrRecords) ? queryOrRecords.slice() : this.filter(queryOrRecords)\n\n // Remove each selected record from the collection\n const optsCopy = utils.plainCopy(opts)\n optsCopy.silent = true\n records = records\n .map((record) => this.remove(record, optsCopy))\n .filter((record) => record)\n if (!opts.silent) {\n this.emit('remove', records)\n }\n return this.afterRemoveAll(queryOrRecords, opts, records) || records\n },\n\n /**\n * Skip a number of results.\n *\n * Shortcut for `collection.query().skip(numberToSkip).run()`\n *\n * @example\n * const posts = collection.skip(10)\n *\n * @method Collection#skip\n * @since 3.0.0\n * @param {number} num The number of records to skip.\n * @returns {Array} The result.\n */\n skip (num) {\n return this.query().skip(num).run()\n },\n\n /**\n * Return the plain JSON representation of all items in this collection.\n * Assumes records in this collection have a toJSON method.\n *\n * @method Collection#toJSON\n * @since 3.0.0\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation.\n * @returns {Array} The records.\n */\n toJSON (opts) {\n return this.mapCall('toJSON', opts)\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#unsaved\n * @since 3.0.0\n * @returns {Array} The unsaved records, if any.\n */\n unsaved (opts) {\n return this.index.get()\n },\n\n /**\n * Update a record's position in a single index of this collection. See\n * {@link Collection#updateIndexes} to update a record's position in all\n * indexes at once.\n *\n * @method Collection#updateIndex\n * @since 3.0.0\n * @param {Object} record The record to update.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] The index in which to update the record's\n * position. If you don't specify an index then the record will be updated\n * in the main index.\n */\n updateIndex (record, opts) {\n opts || (opts = {})\n this.getIndex(opts.index).updateRecord(record)\n },\n\n /**\n * Updates all indexes in this collection for the provided record. Has no\n * effect if the record is not in the collection.\n *\n * @method Collection#updateIndexes\n * @since 3.0.0\n * @param {Object} record TODO\n */\n updateIndexes (record) {\n this.index.updateRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.updateRecord(record)\n })\n }\n})\n\n/**\n * Fired when a record changes. Only works for records that have tracked changes.\n * See {@link Collection~changeListener} on how to listen for this event.\n *\n * @event Collection#change\n * @see Collection~changeListener\n */\n\n/**\n * Callback signature for the {@link Collection#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * collection.on('change', onChange)\n *\n * @callback Collection~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Collection#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the Collection. See\n * {@link Collection~addListener} on how to listen for this event.\n *\n * @event Collection#add\n * @see Collection~addListener\n * @see Collection#event:add\n * @see Collection#add\n */\n\n/**\n * Callback signature for the {@link Collection#event:add} event.\n *\n * @example\n * function onAdd (recordOrRecords) {\n * // do something\n * }\n * collection.on('add', onAdd)\n *\n * @callback Collection~addListener\n * @param {Record|Record[]} The Record or Records that were added.\n * @see Collection#event:add\n * @see Collection#add\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the Collection. See\n * {@link Collection~removeListener} for how to listen for this event.\n *\n * @event Collection#remove\n * @see Collection~removeListener\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n */\n\n/**\n * Callback signature for the {@link Collection#event:remove} event.\n *\n * @example\n * function onRemove (recordsOrRecords) {\n * // do something\n * }\n * collection.on('remove', onRemove)\n *\n * @callback Collection~removeListener\n * @param {Record|Record[]} Record or Records that were removed.\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Collection:\n * @example Collection.extend\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomCollectionClass extends Collection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customCollection = new CustomCollectionClass()\n * console.log(customCollection.foo())\n * console.log(CustomCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherCollectionClass = Collection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherCollection = new OtherCollectionClass()\n * console.log(otherCollection.foo())\n * console.log(OtherCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherCollectionClass () {\n * Collection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Collection.extend({\n * constructor: AnotherCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherCollection = new AnotherCollectionClass()\n * console.log(anotherCollection.created_at)\n * console.log(anotherCollection.foo())\n * console.log(AnotherCollectionClass.beep())\n *\n * @method Collection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Collection class.\n * @since 3.0.0\n */\n","import utils from './utils'\n\n// TODO: remove this when the rest of the project is cleaned\nexport const belongsToType = 'belongsTo'\nexport const hasManyType = 'hasMany'\nexport const hasOneType = 'hasOne'\n\nconst DOMAIN = 'Relation'\n\nexport function Relation (relatedMapper, options = {}) {\n utils.classCallCheck(this, Relation)\n\n options.type = this.constructor.TYPE_NAME\n this.validateOptions(relatedMapper, options)\n\n if (typeof relatedMapper === 'object') {\n Object.defineProperty(this, 'relatedMapper', { value: relatedMapper })\n }\n\n Object.defineProperty(this, 'inverse', { writable: true })\n utils.fillIn(this, options)\n}\n\nRelation.extend = utils.extend\n\nutils.addHiddenPropsToTarget(Relation.prototype, {\n get canAutoAddLinks () {\n return this.add === undefined || !!this.add\n },\n\n get relatedCollection () {\n return this.mapper.datastore.getCollection(this.relation)\n },\n\n validateOptions (related, opts) {\n const DOMAIN_ERR = `new ${DOMAIN}`\n\n const localField = opts.localField\n if (!localField) {\n throw utils.err(DOMAIN_ERR, 'opts.localField')(400, 'string', localField)\n }\n\n const foreignKey = opts.foreignKey = opts.foreignKey || opts.localKey\n if (!foreignKey && (opts.type === belongsToType || opts.type === hasOneType)) {\n throw utils.err(DOMAIN_ERR, 'opts.foreignKey')(400, 'string', foreignKey)\n }\n\n if (utils.isString(related)) {\n opts.relation = related\n if (!utils.isFunction(opts.getRelation)) {\n throw utils.err(DOMAIN_ERR, 'opts.getRelation')(400, 'function', opts.getRelation)\n }\n } else if (related) {\n opts.relation = related.name\n } else {\n throw utils.err(DOMAIN_ERR, 'related')(400, 'Mapper or string', related)\n }\n },\n\n assignTo (mapper) {\n this.name = mapper.name\n Object.defineProperty(this, 'mapper', { value: mapper })\n\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n mapper.relationFields || Object.defineProperty(mapper, 'relationFields', { value: [] })\n mapper.relationList.push(this)\n mapper.relationFields.push(this.localField)\n },\n\n canFindLinkFor () {\n return !!(this.foreignKey || this.localKey)\n },\n\n getRelation () {\n return this.relatedMapper\n },\n\n getForeignKey (record) {\n return utils.get(record, this.mapper.idAttribute)\n },\n\n setForeignKey (record, relatedRecord) {\n if (!record || !relatedRecord) {\n return\n }\n\n this._setForeignKey(record, relatedRecord)\n },\n\n _setForeignKey (record, relatedRecords) {\n const idAttribute = this.mapper.idAttribute\n\n if (!utils.isArray(relatedRecords)) {\n relatedRecords = [relatedRecords]\n }\n\n relatedRecords.forEach((relatedRecord) => {\n utils.set(relatedRecord, this.foreignKey, utils.get(record, idAttribute))\n })\n },\n\n getLocalField (record) {\n return utils.get(record, this.localField)\n },\n\n setLocalField (record, relatedData) {\n return utils.set(record, this.localField, relatedData)\n },\n\n getInverse (mapper) {\n if (!this.inverse) {\n this.findInverseRelation(mapper)\n }\n\n return this.inverse\n },\n\n findInverseRelation (mapper) {\n this.getRelation().relationList.forEach((def) => {\n if (def.getRelation() === mapper && this.isInversedTo(def)) {\n this.inverse = def\n return true\n }\n })\n },\n\n isInversedTo (def) {\n return !def.foreignKey || def.foreignKey === this.foreignKey\n },\n\n addLinkedRecords (records) {\n const datastore = this.mapper.datastore\n\n records.forEach((record) => {\n let relatedData = this.getLocalField(record)\n\n if (utils.isFunction(this.add)) {\n relatedData = this.add(datastore, this, record)\n } else if (relatedData) {\n relatedData = this.linkRecord(record, relatedData)\n }\n\n const isEmptyLinks = !relatedData || utils.isArray(relatedData) && !relatedData.length\n\n if (isEmptyLinks && this.canFindLinkFor(record)) {\n relatedData = this.findExistingLinksFor(record)\n }\n\n if (relatedData) {\n this.setLocalField(record, relatedData)\n }\n })\n },\n\n removeLinkedRecords (relatedMapper, records) {\n const localField = this.localField\n records.forEach((record) => {\n utils.set(record, localField, undefined)\n })\n },\n\n linkRecord (record, relatedRecord) {\n const relatedId = utils.get(relatedRecord, this.mapper.idAttribute)\n\n if (relatedId === undefined) {\n const unsaved = this.relatedCollection.unsaved()\n if (unsaved.indexOf(relatedRecord) === -1) {\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n } else {\n if (relatedRecord !== this.relatedCollection.get(relatedId)) {\n this.setForeignKey(record, relatedRecord)\n\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n }\n\n return relatedRecord\n },\n\n // e.g. user hasMany post via \"foreignKey\", so find all posts of user\n findExistingLinksByForeignKey (id) {\n if (id === undefined || id === null) {\n return\n }\n return this.relatedCollection.filter({\n [this.foreignKey]: id\n })\n }\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const BelongsToRelation = Relation.extend({\n getForeignKey (record) {\n return utils.get(record, this.foreignKey)\n },\n\n _setForeignKey (record, relatedRecord) {\n utils.set(record, this.foreignKey, utils.get(relatedRecord, this.getRelation().idAttribute))\n },\n\n findExistingLinksFor (record) {\n // console.log('\\tBelongsTo#findExistingLinksFor', record)\n if (!record) {\n return\n }\n const relatedId = utils.get(record, this.foreignKey)\n if (relatedId !== undefined && relatedId !== null) {\n return this.relatedCollection.get(relatedId)\n }\n }\n}, {\n TYPE_NAME: 'belongsTo'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasManyRelation = Relation.extend({\n validateOptions (related, opts) {\n Relation.prototype.validateOptions.call(this, related, opts)\n\n const { localKeys, foreignKeys, foreignKey } = opts\n\n if (!foreignKey && !localKeys && !foreignKeys) {\n throw utils.err('new Relation', 'opts.')(400, 'string', foreignKey)\n }\n },\n\n canFindLinkFor (record) {\n const hasForeignKeys = this.foreignKey || this.foreignKeys\n return !!(hasForeignKeys || (this.localKeys && utils.get(record, this.localKeys)))\n },\n\n linkRecord (record, relatedRecords) {\n const relatedCollection = this.relatedCollection\n const canAutoAddLinks = this.canAutoAddLinks\n const foreignKey = this.foreignKey\n const unsaved = this.relatedCollection.unsaved()\n\n return relatedRecords.map((relatedRecord) => {\n const relatedId = relatedCollection.recordId(relatedRecord)\n\n if ((relatedId === undefined && unsaved.indexOf(relatedRecord) === -1) || relatedRecord !== relatedCollection.get(relatedId)) {\n if (foreignKey) {\n // TODO: slow, could be optimized? But user loses hook\n this.setForeignKey(record, relatedRecord)\n }\n if (canAutoAddLinks) {\n relatedRecord = relatedCollection.add(relatedRecord)\n }\n }\n\n return relatedRecord\n })\n },\n\n findExistingLinksFor (record) {\n const id = utils.get(record, this.mapper.idAttribute)\n const ids = this.localKeys ? utils.get(record, this.localKeys) : null\n let records\n\n if (id !== undefined && this.foreignKey) {\n records = this.findExistingLinksByForeignKey(id)\n } else if (this.localKeys && ids) {\n records = this.findExistingLinksByLocalKeys(ids)\n } else if (id !== undefined && this.foreignKeys) {\n records = this.findExistingLinksByForeignKeys(id)\n }\n\n if (records && records.length) {\n return records\n }\n },\n\n // e.g. user hasMany group via \"foreignKeys\", so find all users of a group\n findExistingLinksByLocalKeys (ids) {\n return this.relatedCollection.filter({\n where: {\n [this.mapper.idAttribute]: {\n 'in': ids\n }\n }\n })\n },\n\n // e.g. group hasMany user via \"localKeys\", so find all groups that own a user\n findExistingLinksByForeignKeys (id) {\n return this.relatedCollection.filter({\n where: {\n [this.foreignKeys]: {\n 'contains': id\n }\n }\n })\n }\n}, {\n TYPE_NAME: 'hasMany'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasOneRelation = Relation.extend({\n findExistingLinksFor (relatedMapper, record) {\n const recordId = utils.get(record, relatedMapper.idAttribute)\n const records = this.findExistingLinksByForeignKey(recordId)\n\n if (records && records.length) {\n return records[0]\n }\n }\n}, {\n TYPE_NAME: 'hasOne'\n})\n","import { Relation } from './Relation'\nimport { BelongsToRelation } from './Relation/BelongsTo'\nimport { HasManyRelation } from './Relation/HasMany'\nimport { HasOneRelation } from './Relation/HasOne'\n\n[BelongsToRelation, HasManyRelation, HasOneRelation].forEach(function (RelationType) {\n Relation[RelationType.TYPE_NAME] = function (related, options) {\n return new RelationType(related, options)\n }\n})\n\nexport { belongsToType, hasManyType, hasOneType, Relation } from './Relation'\n","import { Relation } from './relations'\n\nexport { belongsToType, hasManyType, hasOneType } from './relations'\n/**\n * BelongsTo relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.belongsTo\n * @method\n * @param {Mapper} related The relation the target belongs to.\n * @param {Object} opts Configuration options.\n * @param {string} opts.foreignKey The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const belongsTo = function (related, opts) {\n return function (mapper) {\n Relation.belongsTo(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasMany relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasMany\n * @method\n * @param {Mapper} related The relation of which the target has many.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasMany = function (related, opts) {\n return function (mapper) {\n Relation.hasMany(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasOne relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasOne\n * @method\n * @param {Mapper} related The relation of which the target has one.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasOne = function (related, opts) {\n return function (mapper) {\n Relation.hasOne(related, opts).assignTo(mapper)\n }\n}\n","import utils, { safeSetLink } from './utils'\nimport Component from './Component'\nimport Settable from './Settable'\nimport {\n hasManyType,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Record'\n\nconst superMethod = function (mapper, name) {\n const store = mapper.datastore\n if (store && store[name]) {\n return function (...args) {\n return store[name](mapper.name, ...args)\n }\n }\n return mapper[name].bind(mapper)\n}\n\n// Cache these strings\nconst creatingPath = 'creating'\nconst noValidatePath = 'noValidate'\nconst keepChangeHistoryPath = 'keepChangeHistory'\nconst previousPath = 'previous'\n\n/**\n * js-data's Record class. An instance of `Record` corresponds to an in-memory\n * representation of a single row or document in a database, Firebase,\n * localstorage, etc. Basically, a `Record` instance represents whatever kind of\n * entity in your persistence layer that has a primary key.\n *\n * ```javascript\n * import {Record} from 'js-data'\n * ```\n *\n * @example Record#constructor\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a plain record\n * let record = new Record()\n * console.log('record: ' + JSON.stringify(record))\n *\n * // You can supply properties on instantiation\n * record = new Record({ name: 'John' })\n * console.log('record: ' + JSON.stringify(record))\n *\n * @example Record#constructor2\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a record that's associated with a Mapper:\n * const UserMapper = new Mapper({ name: 'user' })\n * const User = UserMapper.recordClass\n * const user = UserMapper.createRecord({ name: 'John' })\n * const user2 = new User({ name: 'Sally' })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user2: ' + JSON.stringify(user2))\n *\n * @example Record#constructor3\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n *\n * // Instantiate a record that's associated with a store's Mapper\n * const user = store.createRecord('user', { name: 'John' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor4\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Validate on instantiation\n * const user = store.createRecord('user', { name: 1234 })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor5\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Skip validation on instantiation\n * const user = store.createRecord('user', { name: 1234 }, { noValidate: true })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user.isValid(): ' + user.isValid())\n *\n * @class Record\n * @extends Component\n * @param {Object} [props] The initial properties of the new Record instance.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate=false] Whether to skip validation on the\n * initial properties.\n * @since 3.0.0\n */\nfunction Record (props, opts) {\n utils.classCallCheck(this, Record)\n Settable.call(this)\n props || (props = {})\n opts || (opts = {})\n const _set = this._set\n _set(creatingPath, true)\n if (opts.noValidate) {\n _set(noValidatePath, opts.noValidate === undefined ? true : opts.noValidate)\n }\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\n const mapper = this.constructor.mapper\n const id = mapper ? utils.get(props, mapper.idAttribute) : undefined\n if (id !== undefined) {\n utils.set(this, mapper.idAttribute, id)\n }\n\n utils.fillIn(this, props)\n _set(creatingPath, false)\n const validateOnSet = opts.validateOnSet === undefined ? (mapper ? mapper.validateOnSet : true) : opts.validateOnSet\n _set(noValidatePath, !validateOnSet)\n _set(previousPath, mapper ? mapper.toJSON(props) : utils.plainCopy(props))\n}\n\nexport default Component.extend({\n constructor: Record,\n\n /**\n * Returns the {@link Mapper} paired with this record's class, if any.\n *\n * @method Record#_mapper\n * @returns {Mapper} The {@link Mapper} paired with this record's class, if any.\n * @since 3.0.0\n */\n _mapper () {\n const mapper = this.constructor.mapper\n if (!mapper) {\n throw utils.err(`${DOMAIN}#_mapper`, '')(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Lifecycle hook.\n *\n * @method Record#afterLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n afterLoadRelations () {},\n\n /**\n * Lifecycle hook.\n *\n * @method Record#beforeLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n beforeLoadRelations () {},\n\n /**\n * Return the change history of this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @method Record#changeHistory\n * @since 3.0.0\n */\n changeHistory () {\n return (this._get('history') || []).slice()\n },\n\n /**\n * Return changes to this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#changes\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n * user.name = 'John'\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n *\n * @method Record#changes\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} Object describing the changes to this record since it was\n * instantiated or its {@link Record#commit} method was last called.\n * @since 3.0.0\n */\n changes (opts) {\n opts || (opts = {})\n return utils.diffObjects(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Make the record's current in-memory state it's only state, with any\n * previous property values being set to current values.\n *\n * @example Record#commit\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#commit\n * @param {Object} [opts] Configuration options. Passed to {@link Record#toJSON}.\n * @since 3.0.0\n */\n commit (opts) {\n this._set('changed') // unset\n this._set('history', []) // clear history\n this._set('previous', this.toJSON(opts))\n },\n\n /**\n * Call {@link Mapper#destroy} using this record's primary key.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user')\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Destroy this user from the database\n * return user.destroy()\n * })\n *\n * @method Record#destroy\n * @param {Object} [opts] Configuration options passed to {@link Mapper#destroy}.\n * @returns {Promise} The result of calling {@link Mapper#destroy} with the\n * primary key of this record.\n * @since 3.0.0\n */\n destroy (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n return superMethod(mapper, 'destroy')(utils.get(this, mapper.idAttribute), opts)\n },\n\n /**\n * Return the value at the given path for this instance.\n *\n * @example Record#get\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', { name: 'Bob' })\n * console.log('user.get(\"name\"): ' + user.get('name'))\n *\n * @method Record#get\n * @param {string} key Path of value to retrieve.\n * @returns {*} Value at path.\n * @since 3.0.0\n */\n 'get' (key) {\n return utils.get(this, key)\n },\n\n /**\n * Return whether this record has changed since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#hasChanges\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#hasChanges\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Return whether the record has changed since it was\n * instantiated or since its {@link Record#commit} method was called.\n * @since 3.0.0\n */\n hasChanges (opts) {\n const quickHasChanges = !!(this._get('changed') || []).length\n return quickHasChanges || utils.areDifferent(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Return whether the record is unsaved. Records that have primary keys are\n * considered \"saved\". Records without primary keys are considered \"unsaved\".\n *\n * @example Record#isNew\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * id: 1234\n * })\n * const user2 = store.createRecord('user')\n * console.log('user isNew: ' + user.isNew()) // false\n * console.log('user2 isNew: ' + user2.isNew()) // true\n *\n * @method Record#isNew\n * @returns {boolean} Whether the record is unsaved.\n * @since 3.0.0\n */\n isNew (opts) {\n return utils.get(this, this._mapper().idAttribute) === undefined\n },\n\n /**\n * Return whether the record in its current state passes validation.\n *\n * @example Record#isValid\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user isValid: ' + user.isValid())\n * user.name = 'John'\n * console.log('user isValid: ' + user.isValid())\n *\n * @method Record#isValid\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {boolean} Whether the record in its current state passes\n * validation.\n * @since 3.0.0\n */\n isValid (opts) {\n return !this._mapper().validate(this, opts)\n },\n\n removeInverseRelation (currentParent, id, inverseDef, idAttribute) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n // e.g. remove comment from otherPost.comments\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n setupInverseRelation (record, id, inverseDef, idAttribute) {\n // Update (set) inverse relation\n if (inverseDef.type === hasOneType) {\n // e.g. someUser.profile = profile\n safeSetLink(record, inverseDef.localField, this)\n } else if (inverseDef.type === hasManyType) {\n // e.g. add comment to somePost.comments\n const children = utils.get(record, inverseDef.localField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n /**\n * Lazy load relations of this record, to be attached to the record once their\n * loaded.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user', {\n * relations: {\n * hasMany: {\n * post: {\n * localField: 'posts',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.defineMapper('post', {\n * relations: {\n * belongsTo: {\n * user: {\n * localField: 'user',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Load the user's post relations\n * return user.loadRelations(['post'])\n * }).then((user) => {\n * console.log(user.posts) // [{...}, {...}, ...]\n * })\n *\n * @method Record#loadRelations\n * @param {string[]} [relations] List of relations to load. Can use localField\n * names or Mapper names to pick relations.\n * @param {Object} [opts] Configuration options.\n * @returns {Promise} Resolves with the record, with the loaded relations now\n * attached.\n * @since 3.0.0\n */\n loadRelations (relations, opts) {\n let op\n const mapper = this._mapper()\n\n // Default values for arguments\n relations || (relations = [])\n if (utils.isString(relations)) {\n relations = [relations]\n }\n opts || (opts = {})\n opts.with = relations\n\n // Fill in \"opts\" with the Model's configuration\n utils._(opts, mapper)\n opts.adapter = mapper.getAdapterName(opts)\n\n // beforeLoadRelations lifecycle hook\n op = opts.op = 'beforeLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'loadRelations'\n mapper.dbg(op, this, relations, opts)\n let tasks = []\n let task\n utils.forEachRelation(mapper, opts, (def, optsCopy) => {\n const relatedMapper = def.getRelation()\n optsCopy.raw = false\n if (utils.isFunction(def.load)) {\n task = def.load(mapper, def, this, opts)\n } else if (def.type === 'hasMany' || def.type === 'hasOne') {\n if (def.foreignKey) {\n task = superMethod(relatedMapper, 'findAll')({\n [def.foreignKey]: utils.get(this, mapper.idAttribute)\n }, optsCopy).then(function (relatedData) {\n if (def.type === 'hasOne') {\n return relatedData.length ? relatedData[0] : undefined\n }\n return relatedData\n })\n } else if (def.localKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [relatedMapper.idAttribute]: {\n 'in': utils.get(this, def.localKeys)\n }\n }\n })\n } else if (def.foreignKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [def.foreignKeys]: {\n 'contains': utils.get(this, mapper.idAttribute)\n }\n }\n }, opts)\n }\n } else if (def.type === 'belongsTo') {\n const key = utils.get(this, def.foreignKey)\n if (utils.isSorN(key)) {\n task = superMethod(relatedMapper, 'find')(key, optsCopy)\n }\n }\n if (task) {\n task = task.then((relatedData) => {\n def.setLocalField(this, relatedData)\n })\n tasks.push(task)\n }\n })\n return Promise.all(tasks)\n }).then(() => {\n // afterLoadRelations lifecycle hook\n op = opts.op = 'afterLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => this)\n })\n },\n\n /**\n * Return the properties with which this record was instantiated.\n *\n * @example Record#previous\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.name = 'Bob'\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.commit()\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n *\n * @method Record#previous\n * @param {string} [key] If specified, return just the initial value of the\n * given key.\n * @returns {Object} The initial properties of this record.\n * @since 3.0.0\n */\n previous (key) {\n if (key) {\n return this._get(`previous.${key}`)\n }\n return this._get('previous')\n },\n\n /**\n * Revert changes to this record back to the properties it had when it was\n * instantiated.\n *\n * @example Record#revert\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user: ' + JSON.stringify(user))\n * user.name = 'Bob'\n * console.log('user: ' + JSON.stringify(user))\n * user.revert()\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#revert\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.preserve] Array of strings or Regular Expressions\n * denoting properties that should not be reverted.\n * @since 3.0.0\n */\n revert (opts) {\n const previous = this._get('previous')\n opts || (opts = {})\n opts.preserve || (opts.preserve = [])\n utils.forOwn(this, (value, key) => {\n if (key !== this._mapper().idAttribute && !previous.hasOwnProperty(key) && this.hasOwnProperty(key) && opts.preserve.indexOf(key) === -1) {\n delete this[key]\n }\n })\n utils.forOwn(previous, (value, key) => {\n if (opts.preserve.indexOf(key) === -1) {\n this[key] = value\n }\n })\n this.commit()\n },\n\n /**\n * Delegates to {@link Mapper#create} or {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('session')\n * const session = store.createRecord('session', { topic: 'Node.js' })\n *\n * // Create a new record in the database\n * session.save().then(() => {\n * console.log(session.id) // 1234\n *\n * session.skill_level = 'beginner'\n *\n * // Update the record in the database\n * return session.save()\n * })\n *\n * @method Record#save\n * @param {Object} [opts] Configuration options. See {@link Mapper#create} and\n * {@link Mapper#update}.\n * @param {boolean} [opts.changesOnly] Equality function. Default uses `===`.\n * @param {Function} [opts.equalsFn] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @param {Array} [opts.ignore] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @returns {Promise} The result of calling {@link Mapper#create} or\n * {@link Mapper#update}.\n * @since 3.0.0\n */\n save (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n const id = utils.get(this, mapper.idAttribute)\n let props = this\n\n const postProcess = (result) => {\n const record = opts.raw ? result.data : result\n if (record) {\n utils.deepMixIn(this, record)\n this.commit()\n }\n return result\n }\n\n if (id === undefined) {\n return superMethod(mapper, 'create')(props, opts).then(postProcess)\n }\n if (opts.changesOnly) {\n const changes = this.changes(opts)\n props = {}\n utils.fillIn(props, changes.added)\n utils.fillIn(props, changes.changed)\n }\n return superMethod(mapper, 'update')(id, props, opts).then(postProcess)\n },\n\n /**\n * Set the value for a given key, or the values for the given keys if \"key\" is\n * an object. Triggers change events on those properties that have `track: true`\n * in {@link Mapper#schema}.\n *\n * @example Record#set\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set('name', 'Bob')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set({ age: 30, role: 'admin' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @fires Record#change\n * @method Record#set\n * @param {(string|Object)} key Key to set or hash of key-value pairs to set.\n * @param {*} [value] Value to set for the given key.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n 'set' (key, value, opts) {\n if (utils.isObject(key)) {\n opts = value\n }\n opts || (opts = {})\n if (opts.silent) {\n this._set('silent', true)\n }\n utils.set(this, key, value)\n if (!this._get('eventId')) {\n this._set('silent') // unset\n }\n },\n\n /**\n * Return a plain object representation of this record. If the class from\n * which this record was created has a Mapper, then {@link Mapper#toJSON} will\n * be called with this record instead.\n *\n * @example Record#toJSON\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * const user = store.createRecord('user', {\n * name: 'John',\n * $$hashKey: '1234'\n * })\n * console.log('user: ' + JSON.stringify(user.toJSON()))\n * console.log('user: ' + JSON.stringify(user.toJSON({ strict: true })))\n *\n * @method Record#toJSON\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation. Only available as an option if the class\n * from which this record was created has a Mapper and this record resides in\n * an instance of {@link DataStore}.\n * @returns {Object} Plain object representation of this record.\n * @since 3.0.0\n */\n toJSON (opts) {\n const mapper = this.constructor.mapper\n if (mapper) {\n return mapper.toJSON(this, opts)\n } else {\n const json = {}\n utils.forOwn(this, function (prop, key) {\n json[key] = utils.plainCopy(prop)\n })\n return json\n }\n },\n\n /**\n * Unset the value for a given key. Triggers change events on those properties\n * that have `track: true` in {@link Mapper#schema}.\n *\n * @example Record#unset\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', {\n * name: 'John'\n * })\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.unset('name')\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#unset\n * @param {string} key Key to unset.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n unset (key, opts) {\n this.set(key, undefined, opts)\n },\n\n /**\n * Validate this record based on its current properties.\n *\n * @example Record#validate\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user validation: ' + JSON.stringify(user.validate()))\n * user.name = 'John'\n * console.log('user validation: ' + user.validate())\n *\n * @method Record#validate\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {*} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (opts) {\n return this._mapper().validate(this, opts)\n }\n})\n\n/**\n * Allow records to emit events.\n *\n * An record's registered listeners are stored in the record's private data.\n */\nutils.eventify(\n Record.prototype,\n function () {\n return this._get('events')\n },\n function (value) {\n this._set('events', value)\n }\n)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link Record~changeListener} on how to listen for this event.\n *\n * @event Record#change\n * @see Record~changeListener\n */\n\n/**\n * Callback signature for the {@link Record#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * record.on('change', onChange)\n *\n * @callback Record~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Record#event:change\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Record:\n * @example Record.extend\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomRecordClass extends Record {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customRecord = new CustomRecordClass()\n * console.log(customRecord.foo())\n * console.log(CustomRecordClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherRecordClass = Record.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherRecord = new OtherRecordClass()\n * console.log(otherRecord.foo())\n * console.log(OtherRecordClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherRecordClass () {\n * Record.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Record.extend({\n * constructor: AnotherRecordClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherRecord = new AnotherRecordClass()\n * console.log(anotherRecord.created_at)\n * console.log(anotherRecord.foo())\n * console.log(AnotherRecordClass.beep())\n *\n * @method Record.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Record class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Schema'\n\n/**\n * A function map for each of the seven primitive JSON types defined by the core specification.\n * Each function will check a given value and return true or false if the value is an instance of that type.\n * ```\n * types.integer(1) // returns true\n * types.string({}) // returns false\n * ```\n * http://json-schema.org/latest/json-schema-core.html#anchor8\n * @name Schema.types\n * @type {Object}\n */\nconst types = {\n array: utils.isArray,\n boolean: utils.isBoolean,\n integer: utils.isInteger,\n 'null': utils.isNull,\n number: utils.isNumber,\n object: utils.isObject,\n string: utils.isString\n}\n\n/**\n * @ignore\n */\nconst segmentToString = function (segment, prev) {\n let str = ''\n if (segment) {\n if (utils.isNumber(segment)) {\n str += `[${segment}]`\n } else if (prev) {\n str += `.${segment}`\n } else {\n str += `${segment}`\n }\n }\n return str\n}\n\n/**\n * @ignore\n */\nconst makePath = function (opts) {\n opts || (opts = {})\n let path = ''\n const segments = opts.path || []\n segments.forEach(function (segment) {\n path += segmentToString(segment, path)\n })\n path += segmentToString(opts.prop, path)\n return path\n}\n\n/**\n * @ignore\n */\nconst makeError = function (actual, expected, opts) {\n return {\n expected,\n actual: '' + actual,\n path: makePath(opts)\n }\n}\n\n/**\n * @ignore\n */\nconst addError = function (actual, expected, opts, errors) {\n errors.push(makeError(actual, expected, opts))\n}\n\n/**\n * @ignore\n */\nconst maxLengthCommon = function (keyword, value, schema, opts) {\n const max = schema[keyword]\n if (value.length > max) {\n return makeError(value.length, `length no more than ${max}`, opts)\n }\n}\n\n/**\n * @ignore\n */\nconst minLengthCommon = function (keyword, value, schema, opts) {\n const min = schema[keyword]\n if (value.length < min) {\n return makeError(value.length, `length no less than ${min}`, opts)\n }\n}\n\n/**\n * A map of all object member validation functions for each keyword defined in the JSON Schema.\n * @name Schema.validationKeywords\n * @type {Object}\n */\nconst validationKeywords = {\n /**\n * Validates the provided value against all schemas defined in the Schemas `allOf` keyword.\n * The instance is valid against if and only if it is valid against all the schemas declared in the Schema's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be a valid JSON Schema.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor82\n *\n * @name Schema.validationKeywords.allOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `allOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n allOf (value, schema, opts) {\n let allErrors = []\n schema.allOf.forEach(function (_schema) {\n allErrors = allErrors.concat(validate(value, _schema, opts) || [])\n })\n return allErrors.length ? allErrors : undefined\n },\n\n /**\n * Validates the provided value against all schemas defined in the Schemas `anyOf` keyword.\n * The instance is valid against this keyword if and only if it is valid against\n * at least one of the schemas in this keyword's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor85\n *\n * @name Schema.validationKeywords.anyOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `anyOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n anyOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.anyOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * http://json-schema.org/latest/json-schema-validation.html#anchor70\n *\n * @name Schema.validationKeywords.dependencies\n * @method\n * @param {*} value TODO\n * @param {Object} schema TODO\n * @param {Object} opts TODO\n */\n dependencies (value, schema, opts) {\n // TODO\n },\n\n /**\n * Validates the provided value against an array of possible values defined by the Schema's `enum` keyword\n * Validation succeeds if the value is deeply equal to one of the values in the array.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor76\n *\n * @name Schema.validationKeywords.enum\n * @method\n * @param {*} value Value to validate\n * @param {Object} schema Schema containing the `enum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n enum (value, schema, opts) {\n const possibleValues = schema['enum']\n if (utils.findIndex(possibleValues, (item) => utils.deepEqual(item, value)) === -1) {\n return makeError(value, `one of (${possibleValues.join(', ')})`, opts)\n }\n },\n\n /**\n * Validates each of the provided array values against a schema or an array of schemas defined by the Schema's `items` keyword\n * see http://json-schema.org/latest/json-schema-validation.html#anchor37 for validation rules.\n *\n * @name Schema.validationKeywords.items\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the items keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n items (value, schema, opts) {\n opts || (opts = {})\n // TODO: additionalItems\n let items = schema.items\n let errors = []\n const checkingTuple = utils.isArray(items)\n const length = value.length\n for (var prop = 0; prop < length; prop++) {\n if (checkingTuple) {\n // Validating a tuple, instead of just checking each item against the\n // same schema\n items = schema.items[prop]\n }\n opts.prop = prop\n errors = errors.concat(validate(value[prop], items, opts) || [])\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided number against a maximum value defined by the Schema's `maximum` keyword\n * Validation succeeds if the value is a number, and is less than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor17\n *\n * @name Schema.validationKeywords.maximum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `maximum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maximum (value, schema, opts) {\n // Must be a number\n const maximum = schema.maximum\n // Must be a boolean\n // Depends on maximum\n // default: false\n const exclusiveMaximum = schema.exclusiveMaximum\n if (typeof value === typeof maximum && !(exclusiveMaximum ? maximum > value : maximum >= value)) {\n return exclusiveMaximum\n ? makeError(value, `no more than nor equal to ${maximum}`, opts)\n : makeError(value, `no more than ${maximum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a maximum value defined by the Schema's `maxItems` keyword.\n * Validation succeeds if the length of the array is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor42\n *\n * @name Schema.validationKeywords.maxItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `maxItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return maxLengthCommon('maxItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a maximum value defined in the Schema's `maxLength` keyword.\n * Validation succeeds if the length of the string is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor26\n *\n * @name Schema.validationKeywords.maxLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `maxLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxLength (value, schema, opts) {\n return maxLengthCommon('maxLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a maximum value defined in the Schema's `maxProperties` keyword.\n * Validation succeeds if the object's property count is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor54\n *\n * @name Schema.validationKeywords.maxProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `maxProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const maxProperties = schema.maxProperties\n const length = Object.keys(value).length\n if (length > maxProperties) {\n return makeError(length, `no more than ${maxProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided value against a minimum value defined by the Schema's `minimum` keyword\n * Validation succeeds if the value is a number and is greater than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor21\n *\n * @name Schema.validationKeywords.minimum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `minimum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minimum (value, schema, opts) {\n // Must be a number\n const minimum = schema.minimum\n // Must be a boolean\n // Depends on minimum\n // default: false\n const exclusiveMinimum = schema.exclusiveMinimum\n if (typeof value === typeof minimum && !(exclusiveMinimum ? value > minimum : value >= minimum)) {\n return exclusiveMinimum\n ? makeError(value, `no less than nor equal to ${minimum}`, opts)\n : makeError(value, `no less than ${minimum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a minimum value defined by the Schema's `minItems` keyword.\n * Validation succeeds if the length of the array is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor45\n *\n * @name Schema.validationKeywords.minItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `minItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return minLengthCommon('minItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a minimum value defined in the Schema's `minLength` keyword.\n * Validation succeeds if the length of the string is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor29\n *\n * @name Schema.validationKeywords.minLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `minLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minLength (value, schema, opts) {\n return minLengthCommon('minLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a minimum value defined in the Schema's `minProperties` keyword.\n * Validation succeeds if the object's property count is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor57\n *\n * @name Schema.validationKeywords.minProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `minProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const minProperties = schema.minProperties\n const length = Object.keys(value).length\n if (length < minProperties) {\n return makeError(length, `no more than ${minProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided number is a multiple of the number defined in the Schema's `multipleOf` keyword.\n * Validation succeeds if the number can be divided equally into the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor14\n *\n * @name Schema.validationKeywords.multipleOf\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing the `multipleOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n multipleOf (value, schema, opts) {\n const multipleOf = schema.multipleOf\n if (utils.isNumber(value)) {\n if ((value / multipleOf) % 1 !== 0) {\n return makeError(value, `multipleOf ${multipleOf}`, opts)\n }\n }\n },\n\n /**\n * Validates the provided value is not valid with any of the schemas defined in the Schema's `not` keyword.\n * An instance is valid against this keyword if and only if it is NOT valid against the schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor91\n * @name Schema.validationKeywords.not\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the not keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n not (value, schema, opts) {\n if (!validate(value, schema.not, opts)) {\n // TODO: better messaging\n return makeError('succeeded', 'should have failed', opts)\n }\n },\n\n /**\n * Validates the provided value is valid with one and only one of the schemas defined in the Schema's `oneOf` keyword.\n * An instance is valid against this keyword if and only if it is valid against a single schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor88\n * @name Schema.validationKeywords.oneOf\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the `oneOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n oneOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.oneOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else if (validated) {\n allErrors = [makeError('valid against more than one', 'valid against only one', opts)]\n validated = false\n return false\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * Validates the provided string matches a pattern defined in the Schema's `pattern` keyword.\n * Validation succeeds if the string is a match of the regex value of this keyword.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor33\n * @name Schema.validationKeywords.pattern\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `pattern` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n pattern (value, schema, opts) {\n const pattern = schema.pattern\n if (utils.isString(value) && !value.match(pattern)) {\n return makeError(value, pattern, opts)\n }\n },\n\n /**\n * Validates the provided object's properties against a map of values defined in the Schema's `properties` keyword.\n * Validation succeeds if the object's property are valid with each of the schema's in the provided map.\n * Validation also depends on the additionalProperties and or patternProperties.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor64 for more info.\n *\n * @name Schema.validationKeywords.properties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `properties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n properties (value, schema, opts) {\n opts || (opts = {})\n\n if (utils.isArray(value)) {\n return\n }\n\n // Can be a boolean or an object\n // Technically the default is an \"empty schema\", but here \"true\" is\n // functionally the same\n const additionalProperties = schema.additionalProperties === undefined ? true : schema.additionalProperties\n const validated = []\n // \"p\": The property set from \"properties\".\n // Default is an object\n const properties = schema.properties || {}\n // \"pp\": The property set from \"patternProperties\".\n // Default is an object\n const patternProperties = schema.patternProperties || {}\n let errors = []\n\n utils.forOwn(properties, function (_schema, prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n validated.push(prop)\n })\n\n const toValidate = utils.omit(value, validated)\n utils.forOwn(patternProperties, function (_schema, pattern) {\n utils.forOwn(toValidate, function (undef, prop) {\n if (prop.match(pattern)) {\n opts.prop = prop\n // console.log(_schema)\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n validated.push(prop)\n }\n })\n })\n const keys = Object.keys(utils.omit(value, validated))\n // If \"s\" is not empty, validation fails\n if (additionalProperties === false) {\n if (keys.length) {\n const origProp = opts.prop\n opts.prop = ''\n addError(`extra fields: ${keys.join(', ')}`, 'no extra fields', opts, errors)\n opts.prop = origProp\n }\n } else if (utils.isObject(additionalProperties)) {\n // Otherwise, validate according to provided schema\n keys.forEach(function (prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], additionalProperties, opts) || [])\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided object's has all properties listed in the Schema's `properties` keyword array.\n * Validation succeeds if the object contains all properties provided in the array value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor61\n *\n * @name Schema.validationKeywords.required\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `required` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n required (value, schema, opts) {\n opts || (opts = {})\n const required = schema.required\n let errors = []\n if (!opts.existingOnly) {\n required.forEach(function (prop) {\n if (utils.get(value, prop) === undefined) {\n const prevProp = opts.prop\n opts.prop = prop\n addError(undefined, 'a value', opts, errors)\n opts.prop = prevProp\n }\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided value's type is equal to the type, or array of types, defined in the Schema's `type` keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor79\n *\n * @name Schema.validationKeywords.type\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `type` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n type (value, schema, opts) {\n let type = schema.type\n let validType\n // Can be one of several types\n if (utils.isString(type)) {\n type = [type]\n }\n // Try to match the value against an expected type\n type.forEach(function (_type) {\n // TODO: throw an error if type is not defined\n if (types[_type](value, schema, opts)) {\n // Matched a type\n validType = _type\n return false\n }\n })\n // Value did not match any expected type\n if (!validType) {\n return makeError(value !== undefined && value !== null ? typeof value : '' + value, `one of (${type.join(', ')})`, opts)\n }\n // Run keyword validators for matched type\n // http://json-schema.org/latest/json-schema-validation.html#anchor12\n const validator = typeGroupValidators[validType]\n if (validator) {\n return validator(value, schema, opts)\n }\n },\n\n /**\n * Validates the provided array values are unique.\n * Validation succeeds if the items in the array are unique, but only if the value of this keyword is true\n * see http://json-schema.org/latest/json-schema-validation.html#anchor49\n *\n * @name Schema.validationKeywords.uniqueItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `uniqueItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n uniqueItems (value, schema, opts) {\n if (value && value.length && schema.uniqueItems) {\n const length = value.length\n let item, i, j\n // Check n - 1 items\n for (i = length - 1; i > 0; i--) {\n item = value[i]\n // Only compare against unchecked items\n for (j = i - 1; j >= 0; j--) {\n // Found a duplicate\n if (utils.deepEqual(item, value[j])) {\n return makeError(item, 'no duplicates', opts)\n }\n }\n }\n }\n }\n}\n\n/**\n * @ignore\n */\nconst runOps = function (ops, value, schema, opts) {\n let errors = []\n ops.forEach(function (op) {\n if (schema[op] !== undefined) {\n errors = errors.concat(validationKeywords[op](value, schema, opts) || [])\n }\n })\n return errors.length ? errors : undefined\n}\n\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\nconst STRING_OPS = ['maxLength', 'minLength', 'pattern']\n\n/**\n * http://json-schema.org/latest/json-schema-validation.html#anchor75\n * @ignore\n */\nconst validateAny = function (value, schema, opts) {\n return runOps(ANY_OPS, value, schema, opts)\n}\n\n/**\n * Validates the provided value against a given Schema according to the http://json-schema.org/ v4 specification.\n *\n * @name Schema.validate\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Valid Schema according to the http://json-schema.org/ v4 specification.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\nconst validate = function (value, schema, opts) {\n let errors = []\n opts || (opts = {})\n opts.ctx || (opts.ctx = { value, schema })\n let shouldPop\n let prevProp = opts.prop\n if (schema === undefined) {\n return\n }\n if (!utils.isObject(schema)) {\n throw utils.err(`${DOMAIN}#validate`)(500, `Invalid schema at path: \"${opts.path}\"`)\n }\n if (opts.path === undefined) {\n opts.path = []\n }\n // Track our location as we recurse\n if (opts.prop !== undefined) {\n shouldPop = true\n opts.path.push(opts.prop)\n opts.prop = undefined\n }\n // Validate against parent schema\n if (schema['extends']) {\n // opts.path = path\n // opts.prop = prop\n if (utils.isFunction(schema['extends'].validate)) {\n errors = errors.concat(schema['extends'].validate(value, opts) || [])\n } else {\n errors = errors.concat(validate(value, schema['extends'], opts) || [])\n }\n }\n if (value === undefined) {\n // Check if property is required\n if (schema.required === true && !opts.existingOnly) {\n addError(value, 'a value', opts, errors)\n }\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n }\n\n errors = errors.concat(validateAny(value, schema, opts) || [])\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n}\n\n// These strings are cached for optimal performance of the change detection\n// boolean - Whether a Record is changing in the current execution frame\nconst changingPath = 'changing'\n// string[] - Properties that have changed in the current execution frame\nconst changedPath = 'changed'\n// Object[] - History of change records\nconst changeHistoryPath = 'history'\n// boolean - Whether a Record is currently being instantiated\nconst creatingPath = 'creating'\n// number - The setTimeout change event id of a Record, if any\nconst eventIdPath = 'eventId'\n// boolean - Whether to skip validation for a Record's currently changing property\nconst noValidatePath = 'noValidate'\n// boolean - Whether to preserve Change History for a Record\nconst keepChangeHistoryPath = 'keepChangeHistory'\n// boolean - Whether to skip change notification for a Record's currently\n// changing property\nconst silentPath = 'silent'\nconst validationFailureMsg = 'validation failed'\n\n/**\n * Assemble a property descriptor which will be added to the prototype of\n * {@link Mapper#recordClass}. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @ignore\n */\nconst makeDescriptor = function (prop, schema, opts) {\n const descriptor = {\n // Better to allow configurability, but at the user's own risk\n configurable: true,\n // These properties are enumerable by default, but regardless of their\n // enumerability, they won't be \"own\" properties of individual records\n enumerable: schema.enumerable === undefined ? true : !!schema.enumerable\n }\n // Cache a few strings for optimal performance\n const keyPath = `props.${prop}`\n const previousPath = `previous.${prop}`\n const getter = opts.getter\n const setter = opts.setter\n const unsetter = opts.unsetter\n const track = utils.isBoolean(opts.track) ? opts.track : schema.track\n\n descriptor.get = function () {\n return this._get(keyPath)\n }\n\n if (utils.isFunction(schema.get)) {\n const originalGet = descriptor.get\n descriptor.get = function () {\n return schema.get.call(this, originalGet)\n }\n }\n\n descriptor.set = function (value) {\n // These are accessed a lot\n const _get = this[getter]\n const _set = this[setter]\n const _unset = this[unsetter]\n // Optionally check that the new value passes validation\n if (!_get(noValidatePath)) {\n const errors = schema.validate(value, { path: [prop] })\n if (errors) {\n // Immediately throw an error, preventing the record from getting into\n // an invalid state\n const error = new Error(validationFailureMsg)\n error.errors = errors\n throw error\n }\n }\n // TODO: Make it so tracking can be turned on for all properties instead of\n // only per-property\n if (track && !_get(creatingPath)) {\n // previous is versioned on database commit\n // props are versioned on set()\n const previous = _get(previousPath)\n const current = _get(keyPath)\n let changing = _get(changingPath)\n let changed = _get(changedPath)\n\n if (!changing) {\n // Track properties that are changing in the current event loop\n changed = []\n }\n\n // Add changing properties to this array once at most\n const index = changed.indexOf(prop)\n if (current !== value && index === -1) {\n changed.push(prop)\n }\n if (previous === value) {\n if (index >= 0) {\n changed.splice(index, 1)\n }\n }\n // No changes in current event loop\n if (!changed.length) {\n changing = false\n _unset(changingPath)\n _unset(changedPath)\n // Cancel pending change event\n if (_get(eventIdPath)) {\n clearTimeout(_get(eventIdPath))\n _unset(eventIdPath)\n }\n }\n // Changes detected in current event loop\n if (!changing && changed.length) {\n _set(changedPath, changed)\n _set(changingPath, true)\n // Saving the timeout id allows us to batch all changes in the same\n // event loop into a single \"change\"\n // TODO: Optimize\n _set(eventIdPath, setTimeout(() => {\n // Previous event loop where changes were gathered has ended, so\n // notify any listeners of those changes and prepare for any new\n // changes\n _unset(changedPath)\n _unset(eventIdPath)\n _unset(changingPath)\n // TODO: Optimize\n if (!_get(silentPath)) {\n let i\n for (i = 0; i < changed.length; i++) {\n this.emit('change:' + changed[i], this, utils.get(this, changed[i]))\n }\n\n const changes = utils.diffObjects({ [prop]: value }, { [prop]: current })\n\n if (_get(keepChangeHistoryPath)) {\n const changeRecord = utils.plainCopy(changes)\n changeRecord.timestamp = new Date().getTime()\n let changeHistory = _get(changeHistoryPath)\n !changeHistory && _set(changeHistoryPath, (changeHistory = []))\n changeHistory.push(changeRecord)\n }\n this.emit('change', this, changes)\n }\n _unset(silentPath)\n }, 0))\n }\n }\n _set(keyPath, value)\n return value\n }\n\n if (utils.isFunction(schema.set)) {\n const originalSet = descriptor.set\n descriptor.set = function (value) {\n return schema.set.call(this, value, originalSet)\n }\n }\n\n return descriptor\n}\n\n/**\n * A map of validation functions grouped by type.\n *\n * @name Schema.typeGroupValidators\n * @type {Object}\n */\nconst typeGroupValidators = {\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an array.\n * The validation keywords for the type `array` are:\n *```\n * ['items', 'maxItems', 'minItems', 'uniqueItems']\n *```\n * see http://json-schema.org/latest/json-schema-validation.html#anchor25\n *\n * @name Schema.typeGroupValidators.array\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing at least one array keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n array: function (value, schema, opts) {\n return runOps(ARRAY_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an integer.\n * The validation keywords for the type `integer` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.integer\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `integer` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n integer: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an number.\n * The validation keywords for the type `number` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.number\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `number` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n number: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of a number or integer.\n * The validation keywords for the type `numeric` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor13.\n *\n * @name Schema.typeGroupValidators.numeric\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `numeric` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n numeric: function (value, schema, opts) {\n return runOps(NUMERIC_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an object.\n * The validation keywords for the type `object` are:\n *```\n * ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor53.\n *\n * @name Schema.typeGroupValidators.object\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing at least one `object` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n object: function (value, schema, opts) {\n return runOps(OBJECT_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an string.\n * The validation keywords for the type `string` are:\n *```\n * ['maxLength', 'minLength', 'pattern']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor25.\n *\n * @name Schema.typeGroupValidators.string\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing at least one `string` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n string: function (value, schema, opts) {\n return runOps(STRING_OPS, value, schema, opts)\n }\n}\n\n/**\n * js-data's Schema class.\n *\n * @example Schema#constructor\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const PostSchema = new Schema({\n * type: 'object',\n * properties: {\n * title: { type: 'string' }\n * }\n * })\n * PostSchema.validate({ title: 1234 })\n *\n * @class Schema\n * @extends Component\n * @param {Object} definition Schema definition according to json-schema.org\n */\nfunction Schema (definition) {\n definition || (definition = {})\n // TODO: schema validation\n utils.fillIn(this, definition)\n\n if (this.type === 'object') {\n this.properties = this.properties || {}\n utils.forOwn(this.properties, (_definition, prop) => {\n if (!(_definition instanceof Schema)) {\n this.properties[prop] = new Schema(_definition)\n }\n })\n } else if (this.type === 'array' && this.items && !(this.items instanceof Schema)) {\n this.items = new Schema(this.items)\n }\n if (this.extends && !(this.extends instanceof Schema)) {\n this.extends = new Schema(this.extends)\n }\n ['allOf', 'anyOf', 'oneOf'].forEach((validationKeyword) => {\n if (this[validationKeyword]) {\n this[validationKeyword].forEach((_definition, i) => {\n if (!(_definition instanceof Schema)) {\n this[validationKeyword][i] = new Schema(_definition)\n }\n })\n }\n })\n}\n\nexport default Component.extend({\n constructor: Schema,\n\n /**\n * This adds ES5 getters/setters to the target based on the \"properties\" in\n * this Schema, which makes possible change tracking and validation on\n * property assignment.\n *\n * @name Schema#validate\n * @method\n * @param {Object} target The prototype to which to apply this schema.\n */\n apply (target, opts) {\n opts || (opts = {})\n opts.getter || (opts.getter = '_get')\n opts.setter || (opts.setter = '_set')\n opts.unsetter || (opts.unsetter = '_unset')\n opts.track || (opts.track = this.track)\n const properties = this.properties || {}\n utils.forOwn(properties, function (schema, prop) {\n Object.defineProperty(\n target,\n prop,\n makeDescriptor(prop, schema, opts)\n )\n })\n },\n\n /**\n * Apply default values to the target object for missing values.\n *\n * @name Schema#applyDefaults\n * @method\n * @param {Object} target The target to which to apply values for missing values.\n */\n applyDefaults (target) {\n if (!target) {\n return\n }\n const properties = this.properties || {}\n const hasSet = utils.isFunction(target.set) || utils.isFunction(target._set)\n utils.forOwn(properties, function (schema, prop) {\n if (schema.hasOwnProperty('default') && utils.get(target, prop) === undefined) {\n if (hasSet) {\n target.set(prop, utils.plainCopy(schema['default']), { silent: true })\n } else {\n utils.set(target, prop, utils.plainCopy(schema['default']))\n }\n }\n if (schema.type === 'object' && schema.properties) {\n if (hasSet) {\n const orig = target._get('noValidate')\n target._set('noValidate', true)\n utils.set(target, prop, utils.get(target, prop) || {}, { silent: true })\n target._set('noValidate', orig)\n } else {\n utils.set(target, prop, utils.get(target, prop) || {})\n }\n schema.applyDefaults(utils.get(target, prop))\n }\n })\n },\n\n /**\n * Create a copy of the given value that contains only the properties defined\n * in this schema.\n *\n * @name Schema#pick\n * @method\n * @param {*} value The value to copy.\n * @returns {*} The copy.\n */\n pick (value) {\n if (this.type === 'object') {\n value || (value = {})\n let copy = {}\n if (this.properties) {\n utils.forOwn(this.properties, (_definition, prop) => {\n copy[prop] = _definition.pick(value[prop])\n })\n }\n if (this.extends) {\n utils.fillIn(copy, this.extends.pick(value))\n }\n return copy\n } else if (this.type === 'array') {\n value || (value = [])\n return value.map((item) => {\n const _copy = this.items ? this.items.pick(item) : {}\n if (this.extends) {\n utils.fillIn(_copy, this.extends.pick(item))\n }\n return _copy\n })\n }\n return utils.plainCopy(value)\n },\n\n /**\n * Validate the provided value against this schema.\n *\n * @name Schema#validate\n * @method\n * @param {*} value Value to validate.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n validate (value, opts) {\n return validate(value, this, opts)\n }\n}, {\n ANY_OPS,\n ARRAY_OPS,\n NUMERIC_OPS,\n OBJECT_OPS,\n STRING_OPS,\n typeGroupValidators,\n types,\n validate,\n validationKeywords\n})\n\n/**\n * Create a subclass of this Schema:\n * @example Schema.extend\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSchemaClass extends Schema {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSchema = new CustomSchemaClass()\n * console.log(customSchema.foo())\n * console.log(CustomSchemaClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSchemaClass = Schema.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSchema = new OtherSchemaClass()\n * console.log(otherSchema.foo())\n * console.log(OtherSchemaClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSchemaClass () {\n * Schema.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Schema.extend({\n * constructor: AnotherSchemaClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSchema = new AnotherSchemaClass()\n * console.log(anotherSchema.created_at)\n * console.log(anotherSchema.foo())\n * console.log(AnotherSchemaClass.beep())\n *\n * @method Schema.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Schema class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\nimport Record from './Record'\nimport Schema from './Schema'\nimport { Relation } from './relations'\nimport {\n belongsTo,\n belongsToType,\n hasMany,\n hasManyType,\n hasOne,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Mapper'\nconst applyDefaultsHooks = [\n 'beforeCreate',\n 'beforeCreateMany'\n]\nconst validatingHooks = [\n 'beforeCreate',\n 'beforeCreateMany',\n 'beforeUpdate',\n 'beforeUpdateAll',\n 'beforeUpdateMany'\n]\nconst makeNotify = function (num) {\n return function (...args) {\n const opts = args[args.length - num]\n const op = opts.op\n this.dbg(op, ...args)\n\n if (applyDefaultsHooks.indexOf(op) !== -1 && opts.applyDefaults !== false) {\n const schema = this.getSchema()\n if (schema && schema.applyDefaults) {\n let toProcess = args[0]\n if (!utils.isArray(toProcess)) {\n toProcess = [toProcess]\n }\n toProcess.forEach((record) => {\n schema.applyDefaults(record)\n })\n }\n }\n\n // Automatic validation\n if (validatingHooks.indexOf(op) !== -1 && !opts.noValidate) {\n // Save current value of option\n const originalExistingOnly = opts.existingOnly\n\n // For updates, ignore required fields if they aren't present\n if (op.indexOf('beforeUpdate') === 0 && opts.existingOnly === undefined) {\n opts.existingOnly = true\n }\n const errors = this.validate(args[op === 'beforeUpdate' ? 1 : 0], utils.pick(opts, ['existingOnly']))\n\n // Restore option\n opts.existingOnly = originalExistingOnly\n\n // Abort lifecycle due to validation errors\n if (errors) {\n const err = new Error('validation failed')\n err.errors = errors\n return utils.reject(err)\n }\n }\n\n // Emit lifecycle event\n if (opts.notify || (opts.notify === undefined && this.notify)) {\n setTimeout(() => {\n this.emit(op, ...args)\n })\n }\n }\n}\n\n// These are the default implementations of all of the lifecycle hooks\nconst notify = makeNotify(1)\nconst notify2 = makeNotify(2)\n\n// This object provides meta information used by Mapper#crud to actually\n// execute each lifecycle method\nconst LIFECYCLE_METHODS = {\n count: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroy: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroyAll: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n find: {\n defaults: [undefined, {}],\n types: []\n },\n findAll: {\n defaults: [{}, {}],\n types: []\n },\n sum: {\n defaults: [undefined, {}, {}],\n skip: true,\n types: []\n },\n update: {\n adapterArgs (mapper, id, props, opts) {\n return [id, mapper.toJSON(props, opts), opts]\n },\n beforeAssign: 1,\n defaults: [undefined, {}, {}],\n types: []\n },\n updateAll: {\n adapterArgs (mapper, props, query, opts) {\n return [mapper.toJSON(props, opts), query, opts]\n },\n beforeAssign: 0,\n defaults: [{}, {}, {}],\n types: []\n },\n updateMany: {\n adapterArgs (mapper, records, opts) {\n return [records.map((record) => mapper.toJSON(record, opts)), opts]\n },\n beforeAssign: 0,\n defaults: [[], {}],\n types: []\n }\n}\n\nconst MAPPER_DEFAULTS = {\n /**\n * Hash of registered adapters. Don't modify directly. Use\n * {@link Mapper#registerAdapter} instead.\n *\n * @default {}\n * @name Mapper#_adapters\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n _adapters: {},\n\n /**\n * Whether {@link Mapper#beforeCreate} and {@link Mapper#beforeCreateMany}\n * should automatically receive default values according to the Mapper's schema.\n *\n * @default true\n * @name Mapper#applyDefaults\n * @since 3.0.0\n * @type {boolean}\n */\n applyDefaults: true,\n\n /**\n * Whether to augment {@link Mapper#recordClass} with ES5 getters and setters\n * according to the properties defined in {@link Mapper#schema}. This makes\n * possible validation and change tracking on individual properties\n * when using the dot (e.g. `user.name = \"Bob\"`) operator to modify a\n * property, and is `true` by default.\n *\n * @default true\n * @name Mapper#applySchema\n * @since 3.0.0\n * @type {boolean}\n */\n applySchema: true,\n\n /**\n * The name of the registered adapter that this Mapper should used by default.\n *\n * @default \"http\"\n * @name Mapper#defaultAdapter\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n * @type {string}\n */\n defaultAdapter: 'http',\n\n /**\n * The field used as the unique identifier on records handled by this Mapper.\n *\n * @default id\n * @name Mapper#idAttribute\n * @since 3.0.0\n * @type {string}\n */\n idAttribute: 'id',\n\n /**\n * Whether records created from this mapper keep changeHistory on property changes.\n *\n * @default true\n * @name Mapper#keepChangeHistory\n * @since 3.0.0\n * @type {boolean}\n */\n keepChangeHistory: true,\n\n /**\n * Whether this Mapper should emit operational events.\n *\n * @default true\n * @name Mapper#notify\n * @since 3.0.0\n * @type {boolean}\n */\n notify: true,\n\n /**\n * Whether to skip validation when the Record instances are created.\n *\n * @default false\n * @name Mapper#noValidate\n * @since 3.0.0\n * @type {boolean}\n */\n noValidate: false,\n\n /**\n * Whether {@link Mapper#create}, {@link Mapper#createMany},\n * {@link Mapper#update}, {@link Mapper#updateAll}, {@link Mapper#updateMany},\n * {@link Mapper#find}, {@link Mapper#findAll}, {@link Mapper#destroy},\n * {@link Mapper#destroyAll}, {@link Mapper#count}, and {@link Mapper#sum}\n * should return a raw result object that contains both the instance data\n * returned by the adapter _and_ metadata about the operation.\n *\n * The default is to NOT return the result object, and instead return just the\n * instance data.\n *\n * @default false\n * @name Mapper#raw\n * @since 3.0.0\n * @type {boolean}\n */\n raw: false,\n\n /**\n * Whether records created from this mapper automatically validate their properties\n * when their properties are modified.\n *\n * @default true\n * @name Mapper#validateOnSet\n * @since 3.0.0\n * @type {boolean}\n */\n validateOnSet: true\n}\n\n/**\n * The core of JSData's [ORM/ODM][orm] implementation. Given a minimum amout of\n * meta information about a resource, a Mapper can perform generic CRUD\n * operations against that resource. Apart from its configuration, a Mapper is\n * stateless. The particulars of various persistence layers have been abstracted\n * into adapters, which a Mapper uses to perform its operations.\n *\n * The term \"Mapper\" comes from the [Data Mapper Pattern][pattern] described in\n * Martin Fowler's [Patterns of Enterprise Application Architecture][book]. A\n * Data Mapper moves data between [in-memory object instances][record] and a\n * relational or document-based database. JSData's Mapper can work with any\n * persistence layer you can write an adapter for.\n *\n * _(\"Model\" is a heavily overloaded term and is avoided in this documentation\n * to prevent confusion.)_\n *\n * [orm]: https://en.wikipedia.org/wiki/Object-relational_mapping\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\n *\n * @example\n * // Import and instantiate\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @example\n * // Define a Mapper using the Container component\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @class Mapper\n * @extends Component\n * @param {Object} opts Configuration options.\n * @param {boolean} [opts.applySchema=true] See {@link Mapper#applySchema}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {string} [opts.defaultAdapter=http] See {@link Mapper#defaultAdapter}.\n * @param {string} [opts.idAttribute=id] See {@link Mapper#idAttribute}.\n * @param {Object} [opts.methods] See {@link Mapper#methods}.\n * @param {string} opts.name See {@link Mapper#name}.\n * @param {boolean} [opts.notify] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw=false] See {@link Mapper#raw}.\n * @param {Function|boolean} [opts.recordClass] See {@link Mapper#recordClass}.\n * @param {Object|Schema} [opts.schema] See {@link Mapper#schema}.\n * @returns {Mapper} A new {@link Mapper} instance.\n * @see http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n */\nfunction Mapper (opts) {\n utils.classCallCheck(this, Mapper)\n Component.call(this)\n opts || (opts = {})\n\n // Prepare certain properties to be non-enumerable\n Object.defineProperties(this, {\n _adapters: {\n value: undefined,\n writable: true\n },\n\n /**\n * The {@link Container} that holds this Mapper. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n datastore: {\n value: undefined,\n writable: true\n },\n\n /**\n * The meta information describing this Mapper's available lifecycle\n * methods. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n lifecycleMethods: {\n value: LIFECYCLE_METHODS\n },\n\n /**\n * Set to `false` to force the Mapper to work with POJO objects only.\n *\n * @example\n * // Use POJOs only.\n * import {Mapper, Record} from 'js-data'\n * const UserMapper = new Mapper({ recordClass: false })\n * UserMapper.recordClass // false\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n *\n * @example\n * // Set to a custom class to have records wrapped in your custom class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User {\n * constructor (props = {}) {\n * for (var key in props) {\n * if (props.hasOwnProperty(key)) {\n * this[key] = props[key]\n * }\n * }\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n * user instanceof User // true\n *\n *\n * @example\n * // Extend the {@link Record} class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User extends Record {\n * constructor () {\n * super(props)\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // true\n * user instanceof User // true\n *\n * @name Mapper#recordClass\n * @default {@link Record}\n * @see Record\n * @since 3.0.0\n */\n recordClass: {\n value: undefined,\n writable: true\n },\n\n /**\n * This Mapper's {@link Schema}.\n *\n * @example Mapper#schema\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const UserMapper = new Mapper({\n * name: 'user',\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * first: { type: 'string', track: true },\n * last: { type: 'string', track: true },\n * role: { type: 'string', track: true, required: true },\n * age: { type: 'integer', track: true },\n * is_active: { type: 'number' }\n * }\n * }\n * })\n * const user = UserMapper.createRecord({\n * id: 1,\n * name: 'John',\n * role: 'admin'\n * })\n * user.on('change', function (user, changes) {\n * console.log(changes)\n * })\n * user.on('change:role', function (user, value) {\n * console.log('change:role - ' + value)\n * })\n * user.role = 'owner'\n *\n * @name Mapper#schema\n * @see Schema\n * @since 3.0.0\n * @type {Schema}\n */\n schema: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(MAPPER_DEFAULTS))\n\n /**\n * The name for this Mapper. This is the minimum amount of meta information\n * required for a Mapper to be able to execute CRUD operations for a\n * Resource.\n *\n * @name Mapper#name\n * @since 3.0.0\n * @type {string}\n */\n if (!this.name) {\n throw utils.err(`new ${DOMAIN}`, 'opts.name')(400, 'string', this.name)\n }\n\n // Setup schema, with an empty default schema if necessary\n if (this.schema) {\n this.schema.type || (this.schema.type = 'object')\n }\n if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\n\n // Create a subclass of Record that's tied to this Mapper\n if (this.recordClass === undefined) {\n const superClass = Record\n this.recordClass = superClass.extend({\n constructor: (function Record () {\n var subClass = function Record (props, opts) {\n utils.classCallCheck(this, subClass)\n superClass.call(this, props, opts)\n }\n return subClass\n })()\n })\n }\n\n if (this.recordClass) {\n this.recordClass.mapper = this\n\n /**\n * Functions that should be added to the prototype of {@link Mapper#recordClass}.\n *\n * @name Mapper#methods\n * @since 3.0.0\n * @type {Object}\n */\n if (utils.isObject(this.methods)) {\n utils.addHiddenPropsToTarget(this.recordClass.prototype, this.methods)\n }\n\n // We can only apply the schema to the prototype of this.recordClass if the\n // class extends Record\n if (Record.prototype.isPrototypeOf(Object.create(this.recordClass.prototype)) && this.schema && this.schema.apply && this.applySchema) {\n this.schema.apply(this.recordClass.prototype)\n }\n }\n}\n\nexport default Component.extend({\n constructor: Mapper,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCount: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroy: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroyAll\n * @param {*} data The `data` returned by the adapter.\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroyAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFind: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFindAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterSum\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterSum: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @since 3.0.0\n */\n beforeCreate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @since 3.0.0\n */\n beforeCreateMany: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @since 3.0.0\n */\n beforeCount: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @since 3.0.0\n */\n beforeDestroy: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroyAll\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @since 3.0.0\n */\n beforeDestroyAll: notify,\n\n /**\n * Mappers lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @since 3.0.0\n */\n beforeFind: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @since 3.0.0\n */\n beforeFindAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeSum\n * @param {string} field The `field` argument passed to {@link Mapper#sum}.\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @since 3.0.0\n */\n beforeSum: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @since 3.0.0\n */\n beforeUpdate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @since 3.0.0\n */\n beforeUpdateAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @since 3.0.0\n */\n beforeUpdateMany: notify,\n\n /**\n * This method is called at the end of most lifecycle methods. It does the\n * following:\n *\n * 1. If `opts.raw` is `true`, add this Mapper's configuration to the `opts`\n * argument as metadata for the operation.\n * 2. Wrap the result data appropriately using {@link Mapper#wrap}, which\n * calls {@link Mapper#createRecord}.\n *\n * @method Mapper#_end\n * @private\n * @since 3.0.0\n */\n _end (result, opts, skip) {\n if (opts.raw) {\n utils._(result, opts)\n }\n if (skip) {\n return result\n }\n let _data = opts.raw ? result.data : result\n if (_data && utils.isFunction(this.wrap)) {\n _data = this.wrap(_data, opts)\n if (opts.raw) {\n result.data = _data\n } else {\n result = _data\n }\n }\n return result\n },\n\n /**\n * Define a belongsTo relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * PostMapper.belongsTo(UserMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to post records at \"post.user\"\n * localField: 'user'\n * })\n *\n * CommentMapper.belongsTo(UserMapper, {\n * // comment.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to comment records at \"comment.user\"\n * localField: 'user'\n * })\n * CommentMapper.belongsTo(PostMapper, {\n * // comment.post_id points to post.id\n * foreignKey: 'post_id'\n * // post records will be attached to comment records at \"comment.post\"\n * localField: 'post'\n * })\n *\n * @method Mapper#belongsTo\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n belongsTo (relatedMapper, opts) {\n return belongsTo(relatedMapper, opts)(this)\n },\n\n /**\n * Select records according to the `query` argument and return the count.\n *\n * {@link Mapper#beforeCount} will be called before calling the adapter.\n * {@link Mapper#afterCount} will be called after calling the adapter.\n *\n * @example\n * // Get the number of published blog posts\n * PostMapper.count({ status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Mapper#count\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `count` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the count of the selected records.\n * @since 3.0.0\n */\n count (query, opts) {\n return this.crud('count', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~beforeCreateListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreate\n * @see Mapper~beforeCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Mapper~beforeCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeCreate}.\n * @see Mapper#event:beforeCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~afterCreateListener} for how to listen for this event.\n *\n * @event Mapper#afterCreate\n * @see Mapper~afterCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Mapper~afterCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterCreate}.\n * @see Mapper#event:afterCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Create and save a new the record using the provided `props`.\n *\n * {@link Mapper#beforeCreate} will be called before calling the adapter.\n * {@link Mapper#afterCreate} will be called after calling the adapter.\n *\n * @example\n * // Create and save a new blog post\n * PostMapper.create({\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#create\n * @param {Object} props The properties for the new record.\n * @param {Object} [opts] Configuration options. Refer to the `create` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `props` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#create}\n * or {@link Mapper#createMany} call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created record.\n * @since 3.0.0\n */\n create (props, opts) {\n let op, adapter\n // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n const originalRecord = props\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return utils.resolve(this[op](props, opts)).then((_props) => {\n // Allow for re-assignment from lifecycle hook\n props = _props === undefined ? props : _props\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n const relatedMapper = def.getRelation()\n const relatedIdAttribute = relatedMapper.idAttribute\n optsCopy.raw = false\n if (!relationData) {\n return\n }\n if (def.type === belongsToType) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(relatedMapper.create(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n def.setForeignKey(props, data)\n }))\n } else if (def.type === hasManyType && def.localKeys) {\n // Create his hasMany relation first because it uses localKeys\n tasks.push(relatedMapper.createMany(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n utils.set(props, def.localKeys, data.map((record) => utils.get(record, relatedIdAttribute)))\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter for the main create\n op = opts.op = 'create'\n this.dbg(op, props, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, this.toJSON(props, { with: opts.pass || [] }), opts))\n }).then((result) => {\n const createdRecordData = opts.raw ? result.data : result\n\n // Deep post-create hasMany and hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n if (!relationData) {\n return\n }\n optsCopy.raw = false\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType && def.foreignKey) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === hasOneType) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().create(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === belongsToType && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n } else if (def.type === hasManyType && def.localKeys && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n if (opts.raw) {\n result.data = originalRecord\n } else {\n result = originalRecord\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return utils.resolve(this[op](props, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Use {@link Mapper#createRecord} instead.\n * @deprecated\n * @method Mapper#createInstance\n * @param {Object|Array} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Object|Array} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n createInstance (props, opts) {\n return this.createRecord(props, opts)\n },\n\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreateMany\n * @see Mapper~beforeCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Mapper~beforeCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Mapper#event:beforeCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~afterCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterCreateMany\n * @see Mapper~afterCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Mapper~afterCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Mapper#event:afterCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Given an array of records, batch create them via an adapter.\n *\n * {@link Mapper#beforeCreateMany} will be called before calling the adapter.\n * {@link Mapper#afterCreateMany} will be called after calling the adapter.\n *\n * @example\n * // Create and save several new blog posts\n * PostMapper.createMany([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#createMany\n * @param {Record[]} records Array of records to be created in one batch.\n * @param {Object} [opts] Configuration options. Refer to the `createMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `records` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#createMany}\n * call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created records.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n createMany (records, opts) {\n let op, adapter\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n const originalRecords = records\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return utils.resolve(this[op](records, opts)).then((_records) => {\n // Allow for re-assignment from lifecycle hook\n records = _records === undefined ? records : _records\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (def.type === belongsToType && relationData.length === records.length) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(def.getRelation().createMany(relationData, optsCopy).then((data) => {\n const relatedRecords = optsCopy.raw ? data.data : data\n def.setLocalField(belongsToRelationData, relatedRecords)\n records.forEach((record, i) => {\n def.setForeignKey(record, relatedRecords[i])\n })\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'createMany'\n const json = records.map((record) => this.toJSON(record, { with: opts.pass || [] }))\n this.dbg(op, records, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, json, opts))\n }).then((result) => {\n const createdRecordsData = opts.raw ? result.data : result\n\n // Deep post-create hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (relationData.length !== records.length) {\n return\n }\n const belongsToData = def.getLocalField(belongsToRelationData)\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType) {\n // Not supported\n this.log('warn', 'deep createMany of hasMany type not supported!')\n } else if (def.type === hasOneType) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setForeignKey(createdRecordData, relationData[i])\n })\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n const relatedData = opts.raw ? result.data : result\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, relatedData[i])\n })\n })\n } else if (def.type === belongsToType && belongsToData && belongsToData.length === createdRecordsData.length) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, belongsToData[i])\n })\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n createdRecordsData.forEach((createdRecordData, i) => {\n const originalRecord = originalRecords[i]\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n })\n if (opts.raw) {\n result.data = originalRecords\n } else {\n result = originalRecords\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return utils.resolve(this[op](records, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Create an unsaved, uncached instance of this Mapper's\n * {@link Mapper#recordClass}.\n *\n * Returns `props` if `props` is already an instance of\n * {@link Mapper#recordClass}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * const post = PostMapper.createRecord()\n *\n * @example\n * // Create an unsaved record instance with inital properties\n * const post = PostMapper.createRecord({\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create a record instance that corresponds to a saved record\n * const post = PostMapper.createRecord({\n * // JSData thinks this record has been saved if it has a primary key\n * id: 1234,\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create record instances from an array\n * const posts = PostMapper.createRecord([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }])\n *\n * @example\n * // Records are validated by default\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * try {\n * const post = PostMapper.createRecord({\n * title: 1234,\n * })\n * } catch (err) {\n * console.log(err.errors) // [{ expected: 'one of (string)', actual: 'number', path: 'title' }]\n * }\n *\n * @example\n * // Skip validation\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * const post = PostMapper.createRecord({\n * title: 1234,\n * }, { noValidate: true })\n * console.log(post.isValid()) // false\n *\n * @method Mapper#createRecord\n * @param {Object|Object[]} props The properties for the Record instance or an\n * array of property objects for the Record instances.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @returns {Record|Record[]} The Record instance or Record instances.\n * @since 3.0.0\n */\n createRecord (props, opts) {\n props || (props = {})\n if (utils.isArray(props)) {\n return props.map((_props) => this.createRecord(_props, opts))\n }\n if (!utils.isObject(props)) {\n throw utils.err(`${DOMAIN}#createRecord`, 'props')(400, 'array or object', props)\n }\n const RecordCtor = this.recordClass\n const relationList = this.relationList || []\n relationList.forEach((def) => {\n const relatedMapper = def.getRelation()\n const relationData = def.getLocalField(props)\n if (relationData && !relatedMapper.is(relationData)) {\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n utils.set(props, def.localField, relatedMapper.createRecord(relationData, opts))\n }\n })\n // Check to make sure \"props\" is not already an instance of this Mapper.\n if (RecordCtor && (!(props instanceof RecordCtor))) {\n return new RecordCtor(props, opts)\n }\n return props\n },\n\n /**\n * Lifecycle invocation method. You probably won't call this method directly.\n *\n * @method Mapper#crud\n * @param {string} method Name of the lifecycle method to invoke.\n * @param {...*} args Arguments to pass to the lifecycle method.\n * @returns {Promise}\n * @since 3.0.0\n */\n crud (method, ...args) {\n const config = this.lifecycleMethods[method]\n if (!config) {\n throw utils.err(`${DOMAIN}#crud`, method)(404, 'method')\n }\n\n const upper = `${method.charAt(0).toUpperCase()}${method.substr(1)}`\n const before = `before${upper}`\n const after = `after${upper}`\n\n let op, adapter\n\n // Default values for arguments\n config.defaults.forEach((value, i) => {\n if (args[i] === undefined) {\n args[i] = utils.copy(value)\n }\n })\n\n const opts = args[args.length - 1]\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // before lifecycle hook\n op = opts.op = before\n return utils.resolve(this[op](...args)).then((_value) => {\n if (args[config.beforeAssign] !== undefined) {\n // Allow for re-assignment from lifecycle hook\n args[config.beforeAssign] = _value === undefined ? args[config.beforeAssign] : _value\n }\n // Now delegate to the adapter\n op = opts.op = method\n args = config.adapterArgs ? config.adapterArgs(this, ...args) : args\n this.dbg(op, ...args)\n return utils.resolve(this.getAdapter(adapter)[op](this, ...args))\n }).then((result) => {\n result = this._end(result, opts, !!config.skip)\n args.push(result)\n // after lifecycle hook\n op = opts.op = after\n return utils.resolve(this[op](...args)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~beforeDestroyListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroy\n * @see Mapper~beforeDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Mapper~beforeDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroy}.\n * @see Mapper#event:beforeDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~afterDestroyListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroy\n * @see Mapper~afterDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Mapper~afterDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroy}.\n * @see Mapper#event:afterDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Using an adapter, destroy the record with the given primary key.\n *\n * {@link Mapper#beforeDestroy} will be called before destroying the record.\n * {@link Mapper#afterDestroy} will be called after destroying the record.\n *\n * @example\n * // Destroy a specific blog post\n * PostMapper.destroy(1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @example\n * // Get full response\n * PostMapper.destroy(1234, { raw: true }).then((result) => {\n * console.log(result.deleted) e.g. 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroy\n * @fires Mapper#afterDestroy\n * @method Mapper#destroy\n * @param {(string|number)} id The primary key of the record to destroy.\n * @param {Object} [opts] Configuration options. Refer to the `destroy` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the record has been destroyed. Resolves\n * even if no record was found to be destroyed.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroy (id, opts) {\n return this.crud('destroy', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroyAll\n * @see Mapper~beforeDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Mapper~beforeDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroyAll}.\n * @see Mapper#event:beforeDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroyAll\n * @see Mapper~afterDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Mapper~afterDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroyAll}.\n * @see Mapper#event:afterDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Destroy the records selected by `query` via an adapter. If no `query` is\n * provided then all records will be destroyed.\n *\n * {@link Mapper#beforeDestroyAll} will be called before destroying the records.\n * {@link Mapper#afterDestroyAll} will be called after destroying the records.\n *\n * @example\n * // Destroy all blog posts\n * PostMapper.destroyAll().then(() => {\n * // All blog posts have been destroyed\n * })\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * PostMapper.destroyAll({ status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @example\n * // Get full response\n * const query = null\n * const options = { raw: true }\n * PostMapper.destroyAll(query, options).then((result) => {\n * console.log(result.deleted) e.g. 14\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroyAll\n * @fires Mapper#afterDestroyAll\n * @method Mapper#destroyAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `destroyAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the records have been destroyed. Resolves\n * even if no records were found to be destroyed.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroyAll (query, opts) {\n return this.crud('destroyAll', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~beforeFindListener} for how to listen for this event.\n *\n * @event Mapper#beforeFind\n * @see Mapper~beforeFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Mapper~beforeFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFind}.\n * @see Mapper#event:beforeFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~afterFindListener} for how to listen for this event.\n *\n * @event Mapper#afterFind\n * @see Mapper~afterFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFind} event.\n *\n * @example\n * function onAfterFind (id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Mapper~afterFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFind}.\n * @see Mapper#event:afterFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Retrieve via an adapter the record with the given primary key.\n *\n * {@link Mapper#beforeFind} will be called before calling the adapter.\n * {@link Mapper#afterFind} will be called after calling the adapter.\n *\n * @example\n * PostMapper.find(1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @example\n * // Get full response\n * PostMapper.find(1, { raw: true }).then((result) => {\n * console.log(result.data) // { id: 1, ...}\n * console.log(result.found) // 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFind\n * @fires Mapper#afterFind\n * @method Mapper#find\n * @param {(string|number)} id The primary key of the record to retrieve.\n * @param {Object} [opts] Configuration options. Refer to the `find` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found record. Resolves with\n * `undefined` if no record was found.\n * @see http://www.js-data.io/v3.0/docs/reading-data\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n find (id, opts) {\n return this.crud('find', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~beforeFindAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeFindAll\n * @see Mapper~beforeFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Mapper~beforeFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFindAll}.\n * @see Mapper#event:beforeFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~afterFindAllListener} for how to listen for this event.\n *\n * @event Mapper#afterFindAll\n * @see Mapper~afterFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Mapper~afterFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFindAll}.\n * @see Mapper#event:afterFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, select records to retrieve via an adapter.\n *\n * {@link Mapper#beforeFindAll} will be called before calling the adapter.\n * {@link Mapper#afterFindAll} will be called after calling the adapter.\n *\n * @example\n * // Find all \"published\" blog posts\n * PostMapper.findAll({ status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, status: 'published', ...}, ...]\n * })\n *\n * @example\n * // Get full response\n * PostMapper.findAll({ status: 'published' }, { raw: true }).then((result) => {\n * console.log(result.data) // [{ id: 1, status: 'published', ...}, ...]\n * console.log(result.found) // e.g. 13\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFindAll\n * @fires Mapper#afterFindAll\n * @method Mapper#findAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `findAll` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n findAll (query, opts) {\n return this.crud('findAll', query, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Mapper#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapter (name) {\n this.dbg('getAdapter', 'name:', name)\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Mapper#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || opts.defaultAdapter\n },\n\n /**\n * Get the object of registered adapters for this Mapper.\n *\n * @method Mapper#getAdapters\n * @returns {Object} {@link Mapper#_adapters}\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Returns this Mapper's {@link Schema}.\n *\n * @method Mapper#getSchema\n * @returns {Schema} This Mapper's {@link Schema}.\n * @see Mapper#schema\n * @since 3.0.0\n */\n getSchema () {\n return this.schema\n },\n\n /**\n * Defines a hasMany relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * UserMapper.hasMany(PostMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // post records will be attached to user records at \"user.posts\"\n * localField: 'posts'\n * })\n *\n * @method Mapper#hasMany\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasMany (relatedMapper, opts) {\n return hasMany(relatedMapper, opts)(this)\n },\n\n /**\n * Defines a hasOne relationship. Only useful if you're managing your Mappers\n * manually and not using a {@link Container} or {@link DataStore} component.\n *\n * @example\n * UserMapper.hasOne(ProfileMapper, {\n * // profile.user_id points to user.id\n * foreignKey: 'user_id'\n * // profile records will be attached to user records at \"user.profile\"\n * localField: 'profile'\n * })\n *\n * @method Mapper#hasOne\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasOne (relatedMapper, opts) {\n return hasOne(relatedMapper, opts)(this)\n },\n\n /**\n * Return whether `record` is an instance of this Mapper's recordClass.\n *\n * @example\n * const post = PostMapper.createRecord()\n *\n * console.log(PostMapper.is(post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof PostMapper.recordClass) // true\n *\n * @method Mapper#is\n * @param {Object|Record} record The record to check.\n * @returns {boolean} Whether `record` is an instance of this Mapper's\n * {@link Mapper#recordClass}.\n * @since 3.0.0\n */\n is (record) {\n const recordClass = this.recordClass\n return recordClass ? record instanceof recordClass : false\n },\n\n /**\n * Register an adapter on this Mapper under the given name.\n *\n * @method Mapper#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for this Mapper.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.defaultAdapter = name\n }\n },\n\n /**\n * Select records according to the `query` argument, and aggregate the sum\n * value of the property specified by `field`.\n *\n * {@link Mapper#beforeSum} will be called before calling the adapter.\n * {@link Mapper#afterSum} will be called after calling the adapter.\n *\n * @example\n * PurchaseOrderMapper.sum('amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Mapper#sum\n * @param {string} field The field to sum.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `sum` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the aggregated sum.\n * @since 3.0.0\n */\n sum (field, query, opts) {\n return this.crud('sum', field, query, opts)\n },\n\n /**\n * Return a plain object representation of the given record. Relations can\n * be optionally be included. Non-schema properties can be excluded.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = PersonMapper.createRecord({ id: 1, name: 'John', foo: 'bar' })\n * console.log(PersonMapper.toJSON(person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(PersonMapper.toJSON(person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Mapper#toJSON\n * @param {Record|Record[]} records Record or records from which to create a\n * POJO representation.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the POJO representation.\n * @param {boolean} [opts.withAll] Whether to simply include all relations in\n * the representation. Overrides `opts.with`.\n * @returns {Object|Object[]} POJO representation of the record or records.\n * @since 3.0.0\n */\n toJSON (records, opts) {\n let record\n opts || (opts = {})\n if (utils.isArray(records)) {\n return records.map((record) => this.toJSON(record, opts))\n } else {\n record = records\n }\n const relationFields = (this ? this.relationFields : []) || []\n let json = {}\n let properties\n\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n properties = this.schema.properties\n }\n properties || (properties = {})\n\n // Optionally copy properties not defined in the schema\n if (!opts.strict) {\n for (var key in record) {\n if (!properties[key] && relationFields.indexOf(key) === -1) {\n json[key] = utils.plainCopy(record[key])\n }\n }\n }\n\n // The user wants to include relations in the resulting plain object representation\n if (this && opts.withAll) {\n opts.with = relationFields.slice()\n }\n if (this && opts.with) {\n if (utils.isString(opts.with)) {\n opts.with = [opts.with]\n }\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(record)\n if (relationData) {\n // The actual recursion\n if (utils.isArray(relationData)) {\n def.setLocalField(json, relationData.map((item) => {\n return def.getRelation().toJSON(item, optsCopy)\n }))\n } else {\n def.setLocalField(json, def.getRelation().toJSON(relationData, optsCopy))\n }\n }\n })\n }\n return json\n },\n\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~beforeUpdateListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdate\n * @see Mapper~beforeUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Mapper~beforeUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeUpdate}.\n * @see Mapper#event:beforeUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~afterUpdateListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdate\n * @see Mapper~afterUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Mapper~afterUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterUpdate}.\n * @see Mapper#event:afterUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Using an adapter, update the record with the primary key specified by the\n * `id` argument.\n *\n * {@link Mapper#beforeUpdate} will be called before updating the record.\n * {@link Mapper#afterUpdate} will be called after updating the record.\n *\n * @example\n * // Update a specific post\n * PostMapper.update(1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Mapper#beforeUpdate\n * @fires Mapper#afterUpdate\n * @method Mapper#update\n * @param {(string|number)} id The primary key of the record to update.\n * @param {Object} props The update to apply to the record.\n * @param {Object} [opts] Configuration options. Refer to the `update` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * transaction.\n * @returns {Promise} Resolves with the updated record. Rejects if the record\n * could not be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n update (id, props, opts) {\n return this.crud('update', id, props, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateAll\n * @see Mapper~beforeUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Mapper~beforeUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Mapper#event:beforeUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateAll\n * @see Mapper~afterUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Mapper~afterUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Mapper#event:afterUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, perform the a single updated to the selected\n * records.\n *\n * {@link Mapper#beforeUpdateAll} will be called before making the update.\n * {@link Mapper#afterUpdateAll} will be called after making the update.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * PostMapper.updateAll(update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateAll\n * @fires Mapper#afterUpdateAll\n * @method Mapper#updateAll\n * @param {Object} props Update to apply to selected records.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `updateAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the update records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateAll (props, query, opts) {\n return this.crud('updateAll', props, query, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateMany\n * @see Mapper~beforeUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Mapper~beforeUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Mapper#event:beforeUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateMany\n * @see Mapper~afterUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Mapper~afterUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Mapper#event:afterUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Given an array of updates, perform each of the updates via an adapter. Each\n * \"update\" is a hash of properties with which to update an record. Each\n * update must contain the primary key of the record to be updated.\n *\n * {@link Mapper#beforeUpdateMany} will be called before making the update.\n * {@link Mapper#afterUpdateMany} will be called after making the update.\n *\n * @example\n * PostMapper.updateMany([\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateMany\n * @fires Mapper#afterUpdateMany\n * @method Mapper#updateMany\n * @param {Record[]} records Array up record updates.\n * @param {Object} [opts] Configuration options. Refer to the `updateMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the updated records. Rejects if any of the\n * records could be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateMany (records, opts) {\n return this.crud('updateMany', records, opts)\n },\n\n /**\n * Validate the given record or records according to this Mapper's\n * {@link Schema}. If there are no validation errors then the return value\n * will be `undefined`.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonSchema = new Schema({\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * })\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: PersonSchema\n * })\n * let errors = PersonMapper.validate({ name: 'John' })\n * console.log(errors) // undefined\n * errors = PersonMapper.validate({ name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Mapper#validate\n * @param {Object|Object[]} record The record or records to validate.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Schema#validate}.\n * @returns {Object[]} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (record, opts) {\n opts || (opts = {})\n const schema = this.getSchema()\n const _opts = utils.pick(opts, ['existingOnly'])\n if (utils.isArray(record)) {\n const errors = record.map((_record) => schema.validate(_record, utils.pick(_opts, ['existingOnly'])))\n const foundErrors = errors.filter((err) => err)\n if (foundErrors.length) {\n return errors\n }\n return undefined\n }\n return schema.validate(record, _opts)\n },\n\n /**\n * Method used to wrap data returned by an adapter with this Mapper's\n * {@link Mapper#recordClass}. This method is used by all of a Mapper's CRUD\n * methods. The provided implementation of this method assumes that the `data`\n * passed to it is a record or records that need to be wrapped with\n * {@link Mapper#createRecord}. Override with care.\n *\n * Provided implementation of {@link Mapper#wrap}:\n *\n * ```\n * function (data, opts) {\n * return this.createRecord(data, opts)\n * }\n * ```\n *\n * @example\n * const PostMapper = new Mapper({\n * name: 'post',\n * // Override to customize behavior\n * wrap (data, opts) {\n * const originalWrap = this.constructor.prototype.wrap\n * // Let's say \"GET /post\" doesn't return JSON quite like JSData expects,\n * // but the actual post records are nested under a \"posts\" field. So,\n * // we override Mapper#wrap to handle this special case.\n * if (opts.op === 'findAll') {\n * return originalWrap.call(this, data.posts, opts)\n * }\n * // Otherwise perform original behavior\n * return originalWrap.call(this, data, opts)\n * }\n * })\n *\n * @method Mapper#wrap\n * @param {Object|Object[]} data The record or records to be wrapped.\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#createRecord}.\n * @returns {Record|Record[]} The wrapped record or records.\n * @since 3.0.0\n */\n wrap (data, opts) {\n return this.createRecord(data, opts)\n },\n\n /**\n * @ignore\n */\n defineRelations () {\n // Setup the mapper's relations, including generating Mapper#relationList\n // and Mapper#relationFields\n utils.forOwn(this.relations, (group, type) => {\n utils.forOwn(group, (relations, _name) => {\n if (utils.isObject(relations)) {\n relations = [relations]\n }\n relations.forEach((def) => {\n const relatedMapper = this.datastore.getMapperByName(_name) || _name\n def.getRelation = () => this.datastore.getMapper(_name)\n\n if (typeof Relation[type] !== 'function') {\n throw utils.err(DOMAIN, 'defineRelations')(400, 'relation type (hasOne, hasMany, etc)', type, true)\n }\n\n this[type](relatedMapper, def)\n })\n })\n })\n }\n})\n\n/**\n * Create a subclass of this Mapper:\n *\n * @example Mapper.extend\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomMapperClass extends Mapper {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customMapper = new CustomMapperClass()\n * console.log(customMapper.foo())\n * console.log(CustomMapperClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherMapperClass = Mapper.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherMapper = new OtherMapperClass()\n * console.log(otherMapper.foo())\n * console.log(OtherMapperClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherMapperClass () {\n * Mapper.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Mapper.extend({\n * constructor: AnotherMapperClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherMapper = new AnotherMapperClass()\n * console.log(anotherMapper.created_at)\n * console.log(anotherMapper.foo())\n * console.log(AnotherMapperClass.beep())\n *\n * @method Mapper.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Mapper class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\nimport Mapper from './Mapper'\n\nconst DOMAIN = 'Container'\n\nexport const proxiedMapperMethods = [\n /**\n * Wrapper for {@link Mapper#count}.\n *\n * @example\n * // Get the number of published blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.count('post', { status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Container#count\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#count}.\n * @param {Object} [opts] See {@link Mapper#count}.\n * @returns {Promise} See {@link Mapper#count}.\n * @see Mapper#count\n * @since 3.0.0\n */\n 'count',\n\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~beforeCreateListener} for how to listen for this event.\n *\n * @event Container#beforeCreate\n * @see Container~beforeCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Container~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see Container#event:beforeCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~afterCreateListener} for how to listen for this event.\n *\n * @event Container#afterCreate\n * @see Container~afterCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Container~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see Container#event:afterCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}.\n *\n * @example\n * // Create and save a new blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.create('post', {\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreate\n * @fires Container#afterCreate\n * @method Container#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props See {@link Mapper#create}.\n * @param {Object} [opts] See {@link Mapper#create}.\n * @returns {Promise} See {@link Mapper#create}.\n * @see Mapper#create\n * @since 3.0.0\n */\n 'create',\n\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Container#beforeCreateMany\n * @see Container~beforeCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Container~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Container#event:beforeCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~afterCreateManyListener} for how to listen for this event.\n *\n * @event Container#afterCreateMany\n * @see Container~afterCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Container~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Container#event:afterCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}.\n *\n * @example\n * // Create and save several new blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.createMany('post', [{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreateMany\n * @fires Container#afterCreateMany\n * @method Container#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record[]} records See {@link Mapper#createMany}.\n * @param {Object} [opts] See {@link Mapper#createMany}.\n * @returns {Promise} See {@link Mapper#createMany}.\n * @see Mapper#createMany\n * @since 3.0.0\n */\n 'createMany',\n\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = PostMapper.createRecord()\n *\n * @method Container#createRecord\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Object[]} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Promise} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n 'createRecord',\n\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~beforeDestroyListener} for how to listen for this event.\n *\n * @event Container#beforeDestroy\n * @see Container~beforeDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Container~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see Container#event:beforeDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~afterDestroyListener} for how to listen for this event.\n *\n * @event Container#afterDestroy\n * @see Container~afterDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Container~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see Container#event:afterDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}.\n *\n * @example\n * // Destroy a specific blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroy('post', 1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @fires Container#beforeDestroy\n * @fires Container#afterDestroy\n * @method Container#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#destroy}.\n * @param {Object} [opts] See {@link Mapper#destroy}.\n * @returns {Promise} See {@link Mapper#destroy}.\n * @see Mapper#destroy\n * @since 3.0.0\n */\n 'destroy',\n\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Container#beforeDestroyAll\n * @see Container~beforeDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Container~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see Container#event:beforeDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Container#afterDestroyAll\n * @see Container~afterDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Container~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see Container#event:afterDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}.\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroyAll('post', { status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @fires Container#beforeDestroyAll\n * @fires Container#afterDestroyAll\n * @method Container#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#destroyAll}.\n * @param {Object} [opts] See {@link Mapper#destroyAll}.\n * @returns {Promise} See {@link Mapper#destroyAll}.\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n 'destroyAll',\n\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~beforeFindListener} for how to listen for this event.\n *\n * @event Container#beforeFind\n * @see Container~beforeFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Container~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see Container#event:beforeFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~afterFindListener} for how to listen for this event.\n *\n * @event Container#afterFind\n * @see Container~afterFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Container~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see Container#event:afterFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.find('post', 1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @fires Container#beforeFind\n * @fires Container#afterFind\n * @method Container#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#find}.\n * @param {Object} [opts] See {@link Mapper#find}.\n * @returns {Promise} See {@link Mapper#find}.\n * @see Mapper#find\n * @since 3.0.0\n */\n 'find',\n\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~beforeFindAllListener} for how to listen for this event.\n *\n * @event Container#beforeFindAll\n * @see Container~beforeFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Container~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see Container#event:beforeFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~afterFindAllListener} for how to listen for this event.\n *\n * @event Container#afterFindAll\n * @see Container~afterFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Container~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see Container#event:afterFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * @example\n * // Find all \"published\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.findAll('post', { status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, ...}, ...]\n * })\n *\n * @fires Container#beforeFindAll\n * @fires Container#afterFindAll\n * @method Container#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#findAll}.\n * @param {Object} [opts] See {@link Mapper#findAll}.\n * @returns {Promise} See {@link Mapper#findAll}.\n * @see Mapper#findAll\n * @since 3.0.0\n */\n 'findAll',\n\n /**\n * Wrapper for {@link Mapper#getSchema}.\n *\n * @method Container#getSchema\n * @param {string} name Name of the {@link Mapper} to target.\n * @returns {Schema} See {@link Mapper#getSchema}.\n * @see Mapper#getSchema\n * @since 3.0.0\n */\n 'getSchema',\n\n /**\n * Wrapper for {@link Mapper#is}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = store.createRecord()\n *\n * console.log(store.is('post', post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof store.getMapper('post').recordClass) // true\n *\n * @method Container#is\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Record} record See {@link Mapper#is}.\n * @returns {boolean} See {@link Mapper#is}.\n * @see Mapper#is\n * @since 3.0.0\n */\n 'is',\n\n /**\n * Wrapper for {@link Mapper#sum}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('purchase_order')\n *\n * store.sum('purchase_order', 'amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Container#sum\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {string} field See {@link Mapper#sum}.\n * @param {Object} [query] See {@link Mapper#sum}.\n * @param {Object} [opts] See {@link Mapper#sum}.\n * @returns {Promise} See {@link Mapper#sum}.\n * @see Mapper#sum\n * @since 3.0.0\n */\n 'sum',\n\n /**\n * Wrapper for {@link Mapper#toJSON}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('person', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = store.createRecord('person', { id: 1, name: 'John', foo: 'bar' })\n * console.log(store.toJSON('person', person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(store.toJSON('person', person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Container#toJSON\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record|Record[]} records See {@link Mapper#toJSON}.\n * @param {Object} [opts] See {@link Mapper#toJSON}.\n * @returns {Object|Object[]} See {@link Mapper#toJSON}.\n * @see Mapper#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~beforeUpdateListener} for how to listen for this event.\n *\n * @event Container#beforeUpdate\n * @see Container~beforeUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Container~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see Container#event:beforeUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~afterUpdateListener} for how to listen for this event.\n *\n * @event Container#afterUpdate\n * @see Container~afterUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Container~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see Container#event:afterUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.update('post', 1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Container#beforeUpdate\n * @fires Container#afterUpdate\n * @method Container#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#update}.\n * @param {Object} record See {@link Mapper#update}.\n * @param {Object} [opts] See {@link Mapper#update}.\n * @returns {Promise} See {@link Mapper#update}.\n * @see Mapper#update\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n 'update',\n\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateAll\n * @see Container~beforeUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Container~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Container#event:beforeUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Container#afterUpdateAll\n * @see Container~afterUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Container~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Container#event:afterUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * store.updateAll('post', update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateAll\n * @fires Container#afterUpdateAll\n * @method Container#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} update See {@link Mapper#updateAll}.\n * @param {Object} [query] See {@link Mapper#updateAll}.\n * @param {Object} [opts] See {@link Mapper#updateAll}.\n * @returns {Promise} See {@link Mapper#updateAll}.\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n 'updateAll',\n\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateMany\n * @see Container~beforeUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Container~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Container#event:beforeUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Container#afterUpdateMany\n * @see Container~afterUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Container~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Container#event:afterUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.updateMany('post', [\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateMany\n * @fires Container#afterUpdateMany\n * @method Container#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#updateMany}.\n * @param {Object} [opts] See {@link Mapper#updateMany}.\n * @returns {Promise} See {@link Mapper#updateMany}.\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n 'updateMany',\n\n /**\n * Wrapper for {@link Mapper#validate}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * let errors = store.validate('post', { name: 'John' })\n * console.log(errors) // undefined\n * errors = store.validate('post', { name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Container#validate\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#validate}.\n * @param {Object} [opts] See {@link Mapper#validate}.\n * @returns {Promise} See {@link Mapper#validate}.\n * @see Mapper#validate\n * @since 3.0.0\n */\n 'validate'\n]\n\n/**\n * The `Container` class is a place to define and store {@link Mapper} instances.\n *\n * `Container` makes it easy to manage your Mappers. Without a container, you\n * need to manage Mappers yourself, including resolving circular dependencies\n * among relations. All Mappers in a container share the same adapters, so you\n * don't have to register adapters for every single Mapper.\n *\n * @example Container#constructor\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n *\n * @class Container\n * @extends Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {Constructor} [opts.mapperClass] See {@link Container#mapperClass}.\n * @param {Object} [opts.mapperDefaults] See {@link Container#mapperDefaults}.\n * @since 3.0.0\n */\nexport function Container (opts) {\n utils.classCallCheck(this, Container)\n Component.call(this)\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * The adapters registered with this Container, which are also shared by all\n * Mappers in this Container.\n *\n * @name Container#_adapters\n * @see Container#registerAdapter\n * @since 3.0.0\n * @type {Object}\n */\n _adapters: {\n value: {}\n },\n\n /**\n * The the mappers in this container\n *\n * @name Container#_mappers\n * @see Mapper\n * @since 3.0.0\n * @type {Object}\n */\n _mappers: {\n value: {}\n },\n\n /**\n * Constructor function to use in {@link Container#defineMapper} to create new\n * {@link Mapper} instances. {@link Container#mapperClass} should extend\n * {@link Mapper}. By default {@link Mapper} is used to instantiate Mappers.\n *\n * @example Container#mapperClass\n * // import {Container, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const store = new Container({\n * mapperClass: MyMapperClass\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').foo())\n *\n * @name Container#mapperClass\n * @see Mapper\n * @since 3.0.0\n * @type {Constructor}\n */\n mapperClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply options provided by the user\n utils.fillIn(this, opts)\n\n /**\n * Defaults options to pass to {@link Container#mapperClass} when creating a\n * new {@link Mapper}.\n *\n * @example Container#mapperDefaults\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: {\n * idAttribute: '_id'\n * }\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').idAttribute)\n *\n * @default {}\n * @name Container#mapperDefaults\n * @since 3.0.0\n * @type {Object}\n */\n this.mapperDefaults = this.mapperDefaults || {}\n\n // Use the Mapper class if the user didn't provide a mapperClass\n this.mapperClass || (this.mapperClass = Mapper)\n}\n\nconst props = {\n constructor: Container,\n\n /**\n * Register a new event listener on this Container.\n *\n * Proxy for {@link Component#on}. If an event was emitted by a {@link Mapper}\n * in the Container, then the name of the {@link Mapper} will be prepended to\n * the arugments passed to the listener.\n *\n * @example Container#on\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.on('foo', function (...args) { console.log(args.join(':')) })\n * store.defineMapper('user')\n * store.emit('foo', 'arg1', 'arg2')\n * store.getMapper('user').emit('foo', 'arg1', 'arg2')\n *\n * @method Container#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n\n /**\n * Used to bind to events emitted by mappers in this container.\n *\n * @method Container#_onMapperEvent\n * @param {string} name Name of the mapper that emitted the event.\n * @param {...*} [args] Args See {@link Mapper#emit}.\n * @private\n * @since 3.0.0\n */\n _onMapperEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * Return a container scoped to a particular mapper.\n *\n * @example Container#as\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method Container#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} A container scoped to a particular mapper.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n proxiedMapperMethods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Create a new mapper and register it in this container.\n *\n * @example Container#defineMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: { foo: 'bar' }\n * })\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(UserMapper.foo)\n *\n * @method Container#defineMapper\n * @param {string} name Name under which to register the new {@link Mapper}.\n * {@link Mapper#name} will be set to this value.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Container#mapperClass} when creating the new {@link Mapper}.\n * @returns {Mapper} The newly created instance of {@link Mapper}.\n * @see Container#as\n * @since 3.0.0\n */\n defineMapper (name, opts) {\n // For backwards compatibility with defineResource\n if (utils.isObject(name)) {\n opts = name\n name = opts.name\n }\n if (!utils.isString(name)) {\n throw utils.err(`${DOMAIN}#defineMapper`, 'name')(400, 'string', name)\n }\n\n // Default values for arguments\n opts || (opts = {})\n // Set Mapper#name\n opts.name = name\n opts.relations || (opts.relations = {})\n\n // Check if the user is overriding the datastore's default mapperClass\n const mapperClass = opts.mapperClass || this.mapperClass\n delete opts.mapperClass\n\n // Apply the datastore's defaults to the options going into the mapper\n utils.fillIn(opts, this.mapperDefaults)\n\n // Instantiate a mapper\n const mapper = this._mappers[name] = new mapperClass(opts) // eslint-disable-line\n mapper.relations || (mapper.relations = {})\n // Make sure the mapper's name is set\n mapper.name = name\n // All mappers in this datastore will share adapters\n mapper._adapters = this.getAdapters()\n\n mapper.datastore = this\n\n mapper.on('all', (...args) => this._onMapperEvent(name, ...args))\n mapper.defineRelations()\n\n return mapper\n },\n\n defineResource (name, opts) {\n console.warn('DEPRECATED: defineResource is deprecated, use defineMapper instead')\n return this.defineMapper(name, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Container#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n */\n getAdapter (name) {\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Container#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || this.mapperDefaults.defaultAdapter\n },\n\n /**\n * Return the registered adapters of this container.\n *\n * @method Container#getAdapters\n * @returns {Adapter}\n * @since 3.0.0\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Return the mapper registered under the specified name.\n *\n * @example Container#getMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * store.getMapper('profile') // throws Error, there is no mapper with name \"profile\"\n *\n * @method Container#getMapper\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapper (name) {\n const mapper = this.getMapperByName(name)\n if (!mapper) {\n throw utils.err(`${DOMAIN}#getMapper`, name)(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Return the mapper registered under the specified name.\n * Doesn't throw error if mapper doesn't exist.\n *\n * @example Container#getMapperByName\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(store.getMapper('profile')) // Does NOT throw an error\n *\n * @method Container#getMapperByName\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapperByName (name) {\n return this._mappers[name]\n },\n\n /**\n * Register an adapter on this container under the given name. Adapters\n * registered on a container are shared by all mappers in the container.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n *\n * @method Container#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for all Mappers in this container.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.mapperDefaults.defaultAdapter = name\n utils.forOwn(this._mappers, function (mapper) {\n mapper.defaultAdapter = name\n })\n }\n }\n}\n\nproxiedMapperMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getMapper(name)[method](...args)\n }\n})\n\nComponent.extend(props)\n\n/**\n * Create a subclass of this Container:\n * @example Container.extend\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomContainerClass extends Container {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customContainer = new CustomContainerClass()\n * console.log(customContainer.foo())\n * console.log(CustomContainerClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherContainerClass = Container.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherContainer = new OtherContainerClass()\n * console.log(otherContainer.foo())\n * console.log(OtherContainerClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherContainerClass () {\n * Container.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Container.extend({\n * constructor: AnotherContainerClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherContainer = new AnotherContainerClass()\n * console.log(anotherContainer.created_at)\n * console.log(anotherContainer.foo())\n * console.log(AnotherContainerClass.beep())\n *\n * @method Container.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Container class.\n * @since 3.0.0\n */\n","import utils from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport {proxiedMapperMethods, Container} from './Container'\nimport Collection from './Collection'\n\nconst DOMAIN = 'SimpleStore'\nconst proxiedCollectionMethods = [\n /**\n * Wrapper for {@link Collection#add}.\n *\n * @example SimpleStore#add\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n *\n * // Add one book to the in-memory store:\n * store.add('book', { id: 1, title: 'Respect your Data' })\n * // Add multiple books to the in-memory store:\n * store.add('book', [\n * { id: 2, title: 'Easy data recipes' },\n * { id: 3, title: 'Active Record 101' }\n * ])\n *\n * @fires SimpleStore#add\n * @method SimpleStore#add\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Object[]|Record|Record[])} data See {@link Collection#add}.\n * @param {Object} [opts] Configuration options. See {@link Collection#add}.\n * @returns {(Object|Object[]|Record|Record[])} See {@link Collection#add}.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n 'add',\n\n /**\n * Wrapper for {@link Collection#between}.\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = store.between('user', 18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = store.between('user', [18], [30], { index: 'age' })\n *\n * @method SimpleStore#between\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Array} leftKeys See {@link Collection#between}.\n * @param {Array} rightKeys See {@link Collection#between}.\n * @param {Object} [opts] Configuration options. See {@link Collection#between}.\n * @returns {Object[]|Record[]} See {@link Collection#between}.\n * @see Collection#between\n * @see Collection#between\n * @since 3.0.0\n */\n 'between',\n\n /**\n * Wrapper for {@link Collection#createIndex}.\n *\n * @example\n * // Index users by age\n * store.createIndex('user', 'age')\n *\n * @example\n * // Index users by status and role\n * store.createIndex('user', 'statusAndRole', ['status', 'role'])\n *\n * @method SimpleStore#createIndex\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {string} name See {@link Collection#createIndex}.\n * @param {string[]} [fieldList] See {@link Collection#createIndex}.\n * @see Collection#createIndex\n * @see Collection#createIndex\n * @since 3.0.0\n */\n 'createIndex',\n\n /**\n * Wrapper for {@link Collection#filter}.\n *\n * @example SimpleStore#filter\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = store.filter('post', function (post) { return post.id % 2 === 0 })\n *\n * @method SimpleStore#filter\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Function)} [queryOrFn={}] See {@link Collection#filter}.\n * @param {Object} [thisArg] See {@link Collection#filter}.\n * @returns {Array} See {@link Collection#filter}.\n * @see Collection#filter\n * @see Collection#filter\n * @since 3.0.0\n */\n 'filter',\n\n /**\n * Wrapper for {@link Collection#get}.\n *\n * @example SimpleStore#get\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * console.log(store.get('post', 1)) // {...}\n * console.log(store.get('post', 2)) // undefined\n *\n * @method SimpleStore#get\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Collection#get}.\n * @returns {(Object|Record)} See {@link Collection#get}.\n * @see Collection#get\n * @see Collection#get\n * @since 3.0.0\n */\n 'get',\n\n /**\n * Wrapper for {@link Collection#getAll}.\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = store.getAll('post', 'draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = store.getAll('post', ['draft'], ['inReview'], { index: 'status' })\n *\n * @method SimpleStore#getAll\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {...Array} [keyList] See {@link Collection#getAll}.\n * @param {Object} [opts] See {@link Collection#getAll}.\n * @returns {Array} See {@link Collection#getAll}.\n * @see Collection#getAll\n * @see Collection#getAll\n * @since 3.0.0\n */\n 'getAll',\n\n /**\n * Wrapper for {@link Collection#prune}.\n *\n * @method SimpleStore#prune\n * @param {Object} [opts] See {@link Collection#prune}.\n * @returns {Array} See {@link Collection#prune}.\n * @see Collection#prune\n * @see Collection#prune\n * @since 3.0.0\n */\n 'prune',\n\n /**\n * Wrapper for {@link Collection#query}.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * store.query('user')\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method SimpleStore#query\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @returns {Query} See {@link Collection#query}.\n * @see Collection#query\n * @see Collection#query\n * @since 3.0.0\n */\n 'query',\n\n /**\n * Wrapper for {@link Collection#toJSON}.\n *\n * @example\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * title: { type: 'string' }\n * }\n * }\n * })\n * store.add('post', [\n * { id: 1, status: 'published', title: 'Respect your Data' },\n * { id: 2, status: 'draft', title: 'Connecting to a data source' }\n * ])\n * console.log(store.toJSON('post'))\n * const draftsJSON = store.query('post')\n * .filter({ status: 'draft' })\n * .mapCall('toJSON')\n * .run()\n *\n * @method SimpleStore#toJSON\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Object} [opts] See {@link Collection#toJSON}.\n * @returns {Array} See {@link Collection#toJSON}.\n * @see Collection#toJSON\n * @see Collection#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Wrapper for {@link Collection#unsaved}.\n *\n * @method SimpleStore#unsaved\n * @returns {Array} See {@link Collection#unsaved}.\n * @see Collection#unsaved\n * @see Collection#unsaved\n * @since 3.0.0\n */\n 'unsaved'\n]\nconst ownMethodsForScoping = [\n 'addToCache',\n 'cachedFind',\n 'cachedFindAll',\n 'cacheFind',\n 'cacheFindAll',\n 'hashQuery'\n]\n\nconst cachedFn = function (name, hashOrId, opts) {\n const cached = this._completedQueries[name][hashOrId]\n if (utils.isFunction(cached)) {\n return cached(name, hashOrId, opts)\n }\n return cached\n}\n\nconst SIMPLESTORE_DEFAULTS = {\n /**\n * Whether to use the pending query if a `find` request for the specified\n * record is currently underway. Can be set to `true`, `false`, or to a\n * function that returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFind\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFind: true,\n\n /**\n * Whether to use the pending query if a `findAll` request for the given query\n * is currently underway. Can be set to `true`, `false`, or to a function that\n * returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFindAll\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFindAll: true\n}\n\n/**\n * The `SimpleStore` class is an extension of {@link Container}. Not only does\n * `SimpleStore` manage mappers, but also collections. `SimpleStore` implements the\n * asynchronous {@link Mapper} methods, such as {@link Mapper#find} and\n * {@link Mapper#create}. If you use the asynchronous `SimpleStore` methods\n * instead of calling them directly on the mappers, then the results of the\n * method calls will be inserted into the store's collections. You can think of\n * a `SimpleStore` as an [Identity Map](https://en.wikipedia.org/wiki/Identity_map_pattern)\n * for the [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping)\n * (the Mappers).\n *\n * ```javascript\n * import {SimpleStore} from 'js-data'\n * ```\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new SimpleStore()\n *\n * // SimpleStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // SimpleStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful SimpleStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class SimpleStore\n * @extends Container\n * @param {Object} [opts] Configuration options. See {@link Container}.\n * @param {boolean} [opts.collectionClass={@link Collection}] See {@link SimpleStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link SimpleStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link SimpleStore#usePendingFindAll}.\n * @returns {SimpleStore}\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-SimpleStore\",\"Working with the SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction SimpleStore (opts) {\n utils.classCallCheck(this, SimpleStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, SIMPLESTORE_DEFAULTS)\n Container.call(this, opts)\n\n this.collectionClass = this.collectionClass || Collection\n this._collections = {}\n this._pendingQueries = {}\n this._completedQueries = {}\n}\n\nconst props = {\n constructor: SimpleStore,\n\n /**\n * Internal method used to handle Mapper responses.\n *\n * @method SimpleStore#_end\n * @private\n * @param {string} name Name of the {@link Collection} to which to\n * add the data.\n * @param {Object} result The result from a Mapper.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object|Array)} Result.\n */\n _end (name, result, opts) {\n let data = opts.raw ? result.data : result\n if (data && utils.isFunction(this.addToCache)) {\n data = this.addToCache(name, data, opts)\n if (opts.raw) {\n result.data = data\n } else {\n result = data\n }\n }\n return result\n },\n\n /**\n * Register a new event listener on this SimpleStore.\n *\n * Proxy for {@link Container#on}. If an event was emitted by a Mapper or\n * Collection in the SimpleStore, then the name of the Mapper or Collection will\n * be prepended to the arugments passed to the provided event handler.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a SimpleStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * store.on('add', (mapperName, records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * store.on('change', (mapperName, record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method SimpleStore#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n */\n\n /**\n * Used to bind to events emitted by collections in this store.\n *\n * @method SimpleStore#_onCollectionEvent\n * @private\n * @param {string} name Name of the collection that emitted the event.\n * @param {...*} [args] Args passed to {@link Collection#emit}.\n */\n _onCollectionEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * This method takes the data received from {@link SimpleStore#find},\n * {@link SimpleStore#findAll}, {@link SimpleStore#update}, etc., and adds the\n * data to the store. _You don't need to call this method directly._\n *\n * If you're using the http adapter and your response data is in an unexpected\n * format, you may need to override this method so the right data gets added\n * to the store.\n *\n * @example\n * const store = new SimpleStore({\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return SimpleStore.prototype.addToCache.call(this, mapperName, data, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return super.addToCache(mapperName, data, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#addToCache\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {*} data Data from which data should be selected for add.\n * @param {Object} [opts] Configuration options.\n */\n addToCache (name, data, opts) {\n return this.getCollection(name).add(data, opts)\n },\n\n /**\n * Return the store scoped to a particular mapper/collection pair.\n *\n * @example SimpleStore.as\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method SimpleStore#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} The store, scoped to a particular Mapper/Collection pair.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n const methods = ownMethodsForScoping\n .concat(proxiedMapperMethods)\n .concat(proxiedCollectionMethods)\n\n methods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n props.getCollection = {\n writable: true,\n value () {\n return original.getCollection(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Retrieve a cached `find` result, if any. This method is called during\n * {@link SimpleStore#find} to determine if {@link Mapper#find} needs to be\n * called. If this method returns `undefined` then {@link Mapper#find} will\n * be called. Otherwise {@link SimpleStore#find} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFind.call(this, mapperName, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cachedFind(mapperName, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cachedFind: cachedFn,\n\n /**\n * Retrieve a cached `findAll` result, if any. This method is called during\n * {@link SimpleStore#findAll} to determine if {@link Mapper#findAll} needs to be\n * called. If this method returns `undefined` then {@link Mapper#findAll} will\n * be called. Otherwise {@link SimpleStore#findAll} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return super.cachedFindAll(mapperName, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cachedFindAll: cachedFn,\n\n /**\n * Mark a {@link Mapper#find} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `find` entry is\n * added it means subsequent calls to the same Resource with the same `id`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#get} instead of delegating to {@link Mapper#find}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cacheFind.call(this, mapperName, data, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cacheFind(mapperName, data, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {*} data The result to cache.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cacheFind (name, data, id, opts) {\n this._completedQueries[name][id] = (name, id, opts) => this.get(name, id)\n },\n\n /**\n * Mark a {@link Mapper#findAll} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `findAll` entry is\n * added it means subsequent calls to the same Resource with the same `query`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#filter} instead of delegating to {@link Mapper#findAll}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, data, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return super.cachedFindAll(mapperName, data, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {*} data The result to cache.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cacheFindAll (name, data, hash, opts) {\n this._completedQueries[name][hash] = (name, hash, opts) => this.filter(name, utils.fromJson(hash))\n },\n\n /**\n * Remove __all__ records from the in-memory store and reset\n * {@link SimpleStore#_completedQueries}.\n *\n * @method SimpleStore#clear\n * @returns {Object} Object containing all records that were in the store.\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n clear () {\n const removed = {}\n utils.forOwn(this._collections, (collection, name) => {\n removed[name] = collection.removeAll()\n this._completedQueries[name] = {}\n })\n return removed\n },\n\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~beforeCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreate\n * @see SimpleStore~beforeCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback SimpleStore~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see SimpleStore#event:beforeCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~afterCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreate\n * @see SimpleStore~afterCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback SimpleStore~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see SimpleStore#event:afterCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}. Adds the created record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book {\"author_id\":1234,...}\n * store.create('book', {\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }).then((book) => {\n * console.log(book.id) // 120392\n * console.log(book.title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreate\n * @fires SimpleStore#afterCreate\n * @fires SimpleStore#add\n * @method SimpleStore#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} record Passed to {@link Mapper#create}.\n * @param {Object} [opts] Passed to {@link Mapper#create}. See\n * {@link Mapper#create} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n create (name, record, opts) {\n opts || (opts = {})\n return Container.prototype.create.call(this, name, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~beforeCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreateMany\n * @see SimpleStore~beforeCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback SimpleStore~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see SimpleStore#event:beforeCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~afterCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreateMany\n * @see SimpleStore~afterCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback SimpleStore~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see SimpleStore#event:afterCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}. Adds the created records to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book [{\"author_id\":1234,...},{...}]\n * store.createMany('book', [{\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }, {\n * author_id: 1234,\n * edition: 'Second Edition',\n * title: 'Respect your Data'\n * }]).then((books) => {\n * console.log(books[0].id) // 142394\n * console.log(books[0].title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreateMany\n * @fires SimpleStore#afterCreateMany\n * @fires SimpleStore#add\n * @method SimpleStore#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Array} records Passed to {@link Mapper#createMany}.\n * @param {Object} [opts] Passed to {@link Mapper#createMany}. See\n * {@link Mapper#createMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n createMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.createMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n defineMapper (name, opts) {\n const self = this\n const mapper = Container.prototype.defineMapper.call(self, name, opts)\n self._pendingQueries[name] = {}\n self._completedQueries[name] = {}\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, { // eslint-disable-line\n // Make sure the collection has somewhere to store \"added\" timestamps\n _added: {},\n // Give the collection a reference to this SimpleStore\n datastore: self,\n // The mapper tied to the collection\n mapper\n })\n\n const schema = mapper.schema || {}\n const properties = schema.properties || {}\n // TODO: Make it possible index nested properties?\n utils.forOwn(properties, function (opts, prop) {\n if (opts.indexed) {\n collection.createIndex(prop)\n }\n })\n\n // Create a secondary index on the \"added\" timestamps of records in the\n // collection\n collection.createIndex('addedTimestamps', ['$'], {\n fieldGetter (obj) {\n return collection._added[collection.recordId(obj)]\n }\n })\n\n collection.on('all', function (...args) {\n self._onCollectionEvent(name, ...args)\n })\n\n return mapper\n },\n\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~beforeDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroy\n * @see SimpleStore~beforeDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback SimpleStore~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see SimpleStore#event:beforeDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~afterDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroy\n * @see SimpleStore~afterDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback SimpleStore~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see SimpleStore#event:afterDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}. Removes any destroyed record from the\n * in-memory store. Clears out any {@link SimpleStore#_completedQueries} entries\n * associated with the provided `id`.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is no longer in the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n *\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroy\n * @fires SimpleStore#afterDestroy\n * @fires SimpleStore#remove\n * @method SimpleStore#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#destroy}.\n * @param {Object} [opts] Passed to {@link Mapper#destroy}. See\n * {@link Mapper#destroy} for more configuration options.\n * @returns {Promise} Resolves when the destroy operation completes.\n * @since 3.0.0\n */\n destroy (name, id, opts) {\n opts || (opts = {})\n return Container.prototype.destroy.call(this, name, id, opts).then((result) => {\n const record = this.getCollection(name).remove(id, opts)\n\n if (opts.raw) {\n result.data = record\n } else {\n result = record\n }\n delete this._pendingQueries[name][id]\n delete this._completedQueries[name][id]\n return result\n })\n },\n\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroyAll\n * @see SimpleStore~beforeDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback SimpleStore~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see SimpleStore#event:beforeDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~afterDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroyAll\n * @see SimpleStore~afterDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback SimpleStore~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see SimpleStore#event:afterDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}. Removes any destroyed records from\n * the in-memory store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is gone from the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroyAll\n * @fires SimpleStore#afterDestroyAll\n * @fires SimpleStore#remove\n * @method SimpleStore#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper#destroyAll}.\n * @param {Object} [opts] Passed to {@link Mapper#destroyAll}. See\n * {@link Mapper#destroyAll} for more configuration options.\n * @returns {Promise} Resolves when the delete completes.\n * @since 3.0.0\n */\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return Container.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n const records = this.getCollection(name).removeAll(query, opts)\n\n if (opts.raw) {\n result.data = records\n } else {\n result = records\n }\n const hash = this.hashQuery(name, query, opts)\n delete this._pendingQueries[name][hash]\n delete this._completedQueries[name][hash]\n return result\n })\n },\n\n eject (name, id, opts) {\n console.warn('DEPRECATED: \"eject\" is deprecated, use \"remove\" instead')\n return this.remove(name, id, opts)\n },\n\n ejectAll (name, query, opts) {\n console.warn('DEPRECATED: \"ejectAll\" is deprecated, use \"removeAll\" instead')\n return this.removeAll(name, query, opts)\n },\n\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~beforeFindListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFind\n * @see SimpleStore~beforeFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback SimpleStore~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see SimpleStore#event:beforeFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~afterFindListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFind\n * @see SimpleStore~afterFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback SimpleStore~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see SimpleStore#event:afterFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}. Adds any found record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /book/1234\n * store.find('book', 1234).then((book) => {\n * // The book record is now in the in-memory store\n * console.log(store.get('book', 1234) === book) // true\n * })\n *\n * @fires SimpleStore#beforeFind\n * @fires SimpleStore#afterFind\n * @fires SimpleStore#add\n * @method SimpleStore#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#find}.\n * @param {Object} [opts] Passed to {@link Mapper#find}.\n * @param {boolean} [opts.force] Bypass cacheFind\n * @param {boolean|Function} [opts.usePendingFind] See {@link SimpleStore#usePendingFind}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n find (name, id, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const pendingQuery = this._pendingQueries[name][id]\n const usePendingFind = opts.usePendingFind === undefined ? this.usePendingFind : opts.usePendingFind\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFind) ? usePendingFind.call(this, name, id, opts) : usePendingFind)) {\n return pendingQuery\n }\n const item = this.cachedFind(name, id, opts)\n let promise\n\n if (opts.force || !item) {\n promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts).then((result) => {\n delete this._pendingQueries[name][id]\n result = this._end(name, result, opts)\n this.cacheFind(name, result, id, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][id]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(item)\n }\n return promise\n },\n\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~beforeFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFindAll\n * @see SimpleStore~beforeFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback SimpleStore~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see SimpleStore#event:beforeFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~afterFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFindAll\n * @see SimpleStore~afterFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback SimpleStore~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see SimpleStore#event:afterFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#findAll}. Adds any found records to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('movie')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /movie?rating=PG\n * store.find('movie', { rating: 'PG' }).then((movies) => {\n * // The movie records are now in the in-memory store\n * console.log(store.filter('movie'))\n * })\n *\n * @fires SimpleStore#beforeFindAll\n * @fires SimpleStore#afterFindAll\n * @fires SimpleStore#add\n * @method SimpleStore#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper.findAll}.\n * @param {Object} [opts] Passed to {@link Mapper.findAll}.\n * @param {boolean} [opts.force] Bypass cacheFindAll\n * @param {boolean|Function} [opts.usePendingFindAll] See {@link SimpleStore#usePendingFindAll}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n findAll (name, query, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const hash = this.hashQuery(name, query, opts)\n const pendingQuery = this._pendingQueries[name][hash]\n const usePendingFindAll = opts.usePendingFindAll === undefined ? this.usePendingFindAll : opts.usePendingFindAll\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFindAll) ? usePendingFindAll.call(this, name, query, opts) : usePendingFindAll)) {\n return pendingQuery\n }\n\n const items = this.cachedFindAll(name, hash, opts)\n let promise\n\n if (opts.force || !items) {\n promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts).then((result) => {\n delete this._pendingQueries[name][hash]\n result = this._end(name, result, opts)\n this.cacheFindAll(name, result, hash, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][hash]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(items)\n }\n return promise\n },\n\n /**\n * Return the {@link Collection} with the given name, if for some\n * reason you need a direct reference to the collection.\n *\n * @method SimpleStore#getCollection\n * @param {string} name Name of the {@link Collection} to retrieve.\n * @returns {Collection}\n * @since 3.0.0\n * @throws {Error} Thrown if the specified {@link Collection} does not\n * exist.\n */\n getCollection (name) {\n const collection = this._collections[name]\n if (!collection) {\n throw utils.err(`${DOMAIN}#getCollection`, name)(404, 'collection')\n }\n return collection\n },\n\n /**\n * Hashing function used to cache {@link SimpleStore#find} and\n * {@link SimpleStore#findAll} requests. This method simply JSONifies the\n * `query` argument passed to {@link SimpleStore#find} or\n * {@link SimpleStore#findAll}.\n *\n * Override this method for custom hashing behavior.\n * @method SimpleStore#hashQuery\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @param {Object} query The `query` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @returns {string} The JSONified `query`.\n * @since 3.0.0\n */\n hashQuery (name, query, opts) {\n return utils.toJson(query)\n },\n\n inject (name, records, opts) {\n console.warn('DEPRECATED: \"inject\" is deprecated, use \"add\" instead')\n return this.add(name, records, opts)\n },\n\n /**\n * Wrapper for {@link Collection#remove}. Removes the specified\n * {@link Record} from the store.\n *\n * @example SimpleStore#remove\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n * console.log(store.getAll('book').length)\n * store.add('book', { id: 1234 })\n * console.log(store.getAll('book').length)\n * store.remove('book', 1234)\n * console.log(store.getAll('book').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#remove\n * @param {string} name The name of the {@link Collection} to target.\n * @param {string|number} id The primary key of the {@link Record} to remove.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n remove (name, id, opts) {\n const record = this.getCollection(name).remove(id, opts)\n if (record) {\n this.removeRelated(name, [record], opts)\n }\n return record\n },\n\n /**\n * Wrapper for {@link Collection#removeAll}. Removes the selected\n * {@link Record}s from the store.\n *\n * @example SimpleStore#removeAll\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('movie')\n * console.log(store.getAll('movie').length)\n * store.add('movie', [{ id: 3, rating: 'R' }, { id: 4, rating: 'PG-13' })\n * console.log(store.getAll('movie').length)\n * store.removeAll('movie', { rating: 'R' })\n * console.log(store.getAll('movie').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeAll\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}s, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n removeAll (name, query, opts) {\n const records = this.getCollection(name).removeAll(query, opts)\n if (records.length) {\n this.removeRelated(name, records, opts)\n }\n return records\n },\n\n /**\n * Remove from the store {@link Record}s that are related to the provided\n * {@link Record}(s).\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeRelated\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Record|Record[]} records {@link Record}s whose relations are to be\n * removed.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record}(s) to remove\n * from the store.\n * @since 3.0.0\n */\n removeRelated (name, records, opts) {\n if (!utils.isArray(records)) {\n records = [records]\n }\n utils.forEachRelation(this.getMapper(name), opts, (def, optsCopy) => {\n records.forEach((record) => {\n let relatedData\n let query\n if (def.foreignKey && (def.type === hasOneType || def.type === hasManyType)) {\n query = { [def.foreignKey]: def.getForeignKey(record) }\n } else if (def.type === hasManyType && def.localKeys) {\n query = {\n where: {\n [def.getRelation().idAttribute]: {\n 'in': utils.get(record, def.localKeys)\n }\n }\n }\n } else if (def.type === hasManyType && def.foreignKeys) {\n query = {\n where: {\n [def.foreignKeys]: {\n 'contains': def.getForeignKey(record)\n }\n }\n }\n } else if (def.type === belongsToType) {\n relatedData = this.remove(def.relation, def.getForeignKey(record), optsCopy)\n }\n if (query) {\n relatedData = this.removeAll(def.relation, query, optsCopy)\n }\n if (relatedData) {\n if (utils.isArray(relatedData) && !relatedData.length) {\n return\n }\n if (def.type === hasOneType) {\n relatedData = relatedData[0]\n }\n def.setLocalField(record, relatedData)\n }\n })\n })\n },\n\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~beforeUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdate\n * @see SimpleStore~beforeUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback SimpleStore~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see SimpleStore#event:beforeUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~afterUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdate\n * @see SimpleStore~afterUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback SimpleStore~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see SimpleStore#event:afterUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}. Adds the updated {@link Record} to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post/1234 {\"status\":\"published\"}\n * store.update('post', 1, { status: 'published' }).then((post) => {\n * // The post record has also been updated in the in-memory store\n * console.log(store.get('post', 1234))\n * })\n *\n * @fires SimpleStore#beforeUpdate\n * @fires SimpleStore#afterUpdate\n * @fires SimpleStore#add\n * @method SimpleStore#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#update}.\n * @param {Object} record Passed to {@link Mapper#update}.\n * @param {Object} [opts] Passed to {@link Mapper#update}. See\n * {@link Mapper#update} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n update (name, id, record, opts) {\n opts || (opts = {})\n return Container.prototype.update.call(this, name, id, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateAll\n * @see SimpleStore~beforeUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback SimpleStore~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see SimpleStore#event:beforeUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~afterUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateAll\n * @see SimpleStore~afterUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback SimpleStore~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see SimpleStore#event:afterUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post?author_id=1234 {\"status\":\"published\"}\n * store.updateAll('post', { author_id: 1234 }, { status: 'published' }).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.filter('posts', { author_id: 1234 }))\n * })\n *\n * @fires SimpleStore#beforeUpdateAll\n * @fires SimpleStore#afterUpdateAll\n * @fires SimpleStore#add\n * @method SimpleStore#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props Passed to {@link Mapper#updateAll}.\n * @param {Object} [query] Passed to {@link Mapper#updateAll}.\n * @param {Object} [opts] Passed to {@link Mapper#updateAll}. See\n * {@link Mapper#updateAll} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateAll (name, props, query, opts) {\n opts || (opts = {})\n return Container.prototype.updateAll.call(this, name, props, query, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateMany\n * @see SimpleStore~beforeUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback SimpleStore~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see SimpleStore#event:beforeUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~afterUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateMany\n * @see SimpleStore~afterUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback SimpleStore~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see SimpleStore#event:afterUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post [{\"id\":3,status\":\"published\"},{\"id\":4,status\":\"published\"}]\n * store.updateMany('post', [\n * { id: 3, status: 'published' },\n * { id: 4, status: 'published' }\n * ]).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.getAll('post', 3, 4))\n * })\n *\n * @fires SimpleStore#beforeUpdateMany\n * @fires SimpleStore#afterUpdateMany\n * @fires SimpleStore#add\n * @method SimpleStore#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records Passed to {@link Mapper#updateMany}.\n * @param {Object} [opts] Passed to {@link Mapper#updateMany}. See\n * {@link Mapper#updateMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.updateMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n }\n}\n\nproxiedCollectionMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getCollection(name)[method](...args)\n }\n})\n\nexport default Container.extend(props)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link SimpleStore~changeListener} on how to listen for this event.\n *\n * @event SimpleStore#change\n * @see SimpleStore~changeListener\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:change} event.\n *\n * @example\n * function onChange (mapperName, record, changes) {\n * // do something\n * }\n * store.on('change', onChange)\n *\n * @callback SimpleStore~changeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record} record The Record that changed.\n * @param {Object} changes The changes.\n * @see SimpleStore#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the in-memory store. See\n * {@link SimpleStore~addListener} on how to listen for this event.\n *\n * @event SimpleStore#add\n * @see SimpleStore~addListener\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:add} event.\n *\n * @example\n * function onAdd (mapperName, recordOrRecords) {\n * // do something\n * }\n * store.on('add', onAdd)\n *\n * @callback SimpleStore~addListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} The Record or Records that were added.\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the in-memory store. See\n * {@link SimpleStore~removeListener} for how to listen for this event.\n *\n * @event SimpleStore#remove\n * @see SimpleStore~removeListener\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:remove} event.\n *\n * @example\n * function onRemove (mapperName, recordsOrRecords) {\n * // do something\n * }\n * store.on('remove', onRemove)\n *\n * @callback SimpleStore~removeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} Record or Records that were removed.\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this SimpleStore:\n * @example SimpleStore.extend\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSimpleStoreClass extends SimpleStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSimpleStore = new CustomSimpleStoreClass()\n * console.log(customSimpleStore.foo())\n * console.log(CustomSimpleStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSimpleStoreClass = SimpleStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSimpleStore = new OtherSimpleStoreClass()\n * console.log(otherSimpleStore.foo())\n * console.log(OtherSimpleStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSimpleStoreClass () {\n * SimpleStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * SimpleStore.extend({\n * constructor: AnotherSimpleStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSimpleStore = new AnotherSimpleStoreClass()\n * console.log(anotherSimpleStore.created_at)\n * console.log(anotherSimpleStore.foo())\n * console.log(AnotherSimpleStoreClass.beep())\n *\n * @method SimpleStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this SimpleStore class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport './decorators'\nimport Collection from './Collection'\n\nconst DOMAIN = 'LinkedCollection'\n\n/**\n * Extends {@link Collection}. Used by a {@link DataStore} to implement an\n * Identity Map.\n *\n * ```javascript\n * import {LinkedCollection} from 'js-data'\n * ```\n *\n * @class LinkedCollection\n * @extends Collection\n * @param {Array} [records] Initial set of records to insert into the\n * collection. See {@link Collection}.\n * @param {Object} [opts] Configuration options. See {@link Collection}.\n * @returns {Mapper}\n */\nfunction LinkedCollection (records, opts) {\n utils.classCallCheck(this, LinkedCollection)\n // Make sure this collection has somewhere to store \"added\" timestamps\n Object.defineProperties(this, {\n _added: {\n value: {}\n },\n datastore: {\n writable: true,\n value: undefined\n }\n })\n\n Collection.call(this, records, opts)\n\n // Make sure this collection has a reference to a datastore\n if (!this.datastore) {\n throw utils.err(`new ${DOMAIN}`, 'opts.datastore')(400, 'DataStore', this.datastore)\n }\n}\n\nexport default Collection.extend({\n constructor: LinkedCollection,\n\n _addMeta (record, timestamp) {\n // Track when this record was added\n this._added[this.recordId(record)] = timestamp\n\n if (utils.isFunction(record._set)) {\n record._set('$', timestamp)\n }\n },\n\n _clearMeta (record) {\n delete this._added[this.recordId(record)]\n if (utils.isFunction(record._set)) {\n record._set('$') // unset\n }\n },\n\n _onRecordEvent (...args) {\n Collection.prototype._onRecordEvent.apply(this, args)\n const event = args[0]\n // This is a very brute force method\n // Lots of room for optimization\n if (utils.isString(event) && event.indexOf('change') === 0) {\n this.updateIndexes(args[1])\n }\n },\n\n add (records, opts) {\n const mapper = this.mapper\n const timestamp = new Date().getTime()\n const singular = utils.isObject(records) && !utils.isArray(records)\n\n if (singular) {\n records = [records]\n }\n records = Collection.prototype.add.call(this, records, opts)\n\n if (mapper.relationList.length && records.length) {\n // Check the currently visited record for relations that need to be\n // inserted into their respective collections.\n mapper.relationList.forEach(function (def) {\n def.addLinkedRecords(records)\n })\n }\n\n records.forEach((record) => this._addMeta(record, timestamp))\n\n return singular ? records[0] : records\n },\n\n remove (idOrRecord, opts) {\n const mapper = this.mapper\n const record = Collection.prototype.remove.call(this, idOrRecord, opts)\n if (record) {\n this._clearMeta(record)\n }\n\n if (mapper.relationList.length && record) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, [record])\n })\n }\n\n return record\n },\n\n removeAll (query, opts) {\n const mapper = this.mapper\n const records = Collection.prototype.removeAll.call(this, query, opts)\n records.forEach(this._clearMeta, this)\n\n if (mapper.relationList.length && records.length) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, records)\n })\n }\n\n return records\n }\n})\n\n/**\n * Create a subclass of this LinkedCollection:\n *\n * @example LinkedCollection.extend\n * // Normally you would do: import {LinkedCollection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {LinkedCollection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomLinkedCollectionClass extends LinkedCollection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customLinkedCollection = new CustomLinkedCollectionClass()\n * console.log(customLinkedCollection.foo())\n * console.log(CustomLinkedCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherLinkedCollectionClass = LinkedCollection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherLinkedCollection = new OtherLinkedCollectionClass()\n * console.log(otherLinkedCollection.foo())\n * console.log(OtherLinkedCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherLinkedCollectionClass () {\n * LinkedCollection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * LinkedCollection.extend({\n * constructor: AnotherLinkedCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherLinkedCollection = new AnotherLinkedCollectionClass()\n * console.log(anotherLinkedCollection.created_at)\n * console.log(anotherLinkedCollection.foo())\n * console.log(AnotherLinkedCollectionClass.beep())\n *\n * @method LinkedCollection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this LinkedCollection class.\n * @since 3.0.0\n */\n","import utils, { safeSetLink, safeSetProp } from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport SimpleStore from './SimpleStore'\nimport LinkedCollection from './LinkedCollection'\n\nconst DATASTORE_DEFAULTS = {\n /**\n * Whether in-memory relations should be unlinked from records after they are\n * destroyed.\n *\n * @default true\n * @name DataStore#unlinkOnDestroy\n * @since 3.0.0\n * @type {boolean}\n */\n unlinkOnDestroy: true\n}\n\n/**\n * The `DataStore` class is an extension of {@link SimpleStore}. Not only does\n * `DataStore` manage mappers and store data in collections, it uses the\n * {@link LinkedCollection} class to link related records together in memory.\n *\n * ```javascript\n * import {DataStore} from 'js-data'\n * ```\n *\n * @example\n * import {DataStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new DataStore()\n *\n * // DataStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // DataStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful DataStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class DataStore\n * @extends SimpleStore\n * @param {Object} [opts] Configuration options. See {@link SimpleStore}.\n * @param {boolean} [opts.collectionClass={@link LinkedCollection}] See {@link DataStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean} [opts.unlinkOnDestroy=true] See {@link DataStore#unlinkOnDestroy}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link DataStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link DataStore#usePendingFindAll}.\n * @returns {DataStore}\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-datastore\",\"Working with the DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction DataStore (opts) {\n utils.classCallCheck(this, DataStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, DATASTORE_DEFAULTS)\n opts.collectionClass || (opts.collectionClass = LinkedCollection)\n SimpleStore.call(this, opts)\n}\n\nconst props = {\n constructor: DataStore,\n\n defineMapper (name, opts) {\n // Complexity of this method is beyond simply using => functions to bind context\n const self = this\n const mapper = SimpleStore.prototype.defineMapper.call(self, name, opts)\n const idAttribute = mapper.idAttribute\n const collection = this.getCollection(name)\n\n mapper.relationList.forEach(function (def) {\n const relation = def.relation\n const localField = def.localField\n const path = `links.${localField}`\n const foreignKey = def.foreignKey\n const type = def.type\n const updateOpts = { index: foreignKey }\n let descriptor\n\n const getter = function () { return this._get(path) }\n\n if (type === belongsToType) {\n if (!collection.indexes[foreignKey]) {\n collection.createIndex(foreignKey)\n }\n\n descriptor = {\n get: getter,\n // e.g. profile.user = someUser\n // or comment.post = somePost\n set (record) {\n // e.g. const otherUser = profile.user\n const currentParent = this._get(path)\n // e.g. profile.user === someUser\n if (record === currentParent) {\n return currentParent\n }\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n\n // e.g. profile.user !== someUser\n // or comment.post !== somePost\n if (currentParent && inverseDef) {\n this.removeInverseRelation(currentParent, id, inverseDef, idAttribute)\n }\n if (record) {\n // e.g. profile.user = someUser\n const relatedIdAttribute = def.getRelation().idAttribute\n const relatedId = utils.get(record, relatedIdAttribute)\n\n // Prefer store record\n if (relatedId !== undefined && this._get('$')) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n // e.g. profile.user = someUser\n // or comment.post = somePost\n safeSetLink(this, localField, record)\n safeSetProp(this, foreignKey, relatedId)\n collection.updateIndex(this, updateOpts)\n\n if (inverseDef) {\n this.setupInverseRelation(record, id, inverseDef, idAttribute)\n }\n } else {\n // Unset in-memory link only\n // e.g. profile.user = undefined\n // or comment.post = undefined\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n\n let foreignKeyDescriptor = Object.getOwnPropertyDescriptor(mapper.recordClass.prototype, foreignKey)\n if (!foreignKeyDescriptor) {\n foreignKeyDescriptor = {\n enumerable: true\n }\n }\n const originalGet = foreignKeyDescriptor.get\n foreignKeyDescriptor.get = function () {\n if (originalGet) {\n return originalGet.call(this)\n }\n return this._get(`props.${foreignKey}`)\n }\n const originalSet = foreignKeyDescriptor.set\n foreignKeyDescriptor.set = function (value) {\n if (originalSet) {\n originalSet.call(this, value)\n }\n const currentParent = utils.get(this, localField)\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n const currentParentId = currentParent ? utils.get(currentParent, def.getRelation().idAttribute) : undefined\n\n if (currentParent && currentParentId !== undefined && currentParentId !== value) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n }\n\n safeSetProp(this, foreignKey, value)\n collection.updateIndex(this, updateOpts)\n\n if ((value === undefined || value === null)) {\n if (currentParentId !== undefined) {\n // Unset locals\n utils.set(this, localField, undefined)\n }\n } else if (this._get('$')) {\n const storeRecord = self.get(relation, value)\n if (storeRecord) {\n utils.set(this, localField, storeRecord)\n }\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, foreignKey, foreignKeyDescriptor)\n } else if (type === hasManyType) {\n const localKeys = def.localKeys\n const foreignKeys = def.foreignKeys\n\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n\n descriptor = {\n get () {\n let current = getter.call(this)\n if (!current) {\n this._set(path, [])\n }\n return getter.call(this)\n },\n // e.g. post.comments = someComments\n // or user.groups = someGroups\n // or group.users = someUsers\n set (records) {\n if (records && !utils.isArray(records)) {\n records = [records]\n }\n const id = utils.get(this, idAttribute)\n const relatedIdAttribute = def.getRelation().idAttribute\n const inverseDef = def.getInverse(mapper)\n const inverseLocalField = inverseDef.localField\n const current = this._get(path) || []\n const toLink = []\n const toLinkIds = {}\n\n if (records) {\n records.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n const currentParent = utils.get(record, inverseLocalField)\n if (currentParent && currentParent !== this) {\n const currentChildrenOfParent = utils.get(currentParent, localField)\n // e.g. somePost.comments.remove(comment)\n if (relatedId === undefined) {\n utils.remove(currentChildrenOfParent, (child) => child === record)\n } else {\n utils.remove(currentChildrenOfParent, (child) => child === record || relatedId === utils.get(child, relatedIdAttribute))\n }\n }\n if (relatedId !== undefined) {\n if (this._get('$')) {\n // Prefer store record\n record = self.get(relation, relatedId) || record\n }\n // e.g. toLinkIds[comment.id] = comment\n toLinkIds[relatedId] = record\n }\n toLink.push(record)\n })\n }\n\n // e.g. post.comments = someComments\n if (foreignKey) {\n current.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(record) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update (unset) inverse relation\n if (records) {\n // e.g. comment.post_id = undefined\n safeSetProp(record, foreignKey, undefined)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n }\n // e.g. comment.post = undefined\n safeSetLink(record, inverseLocalField, undefined)\n }\n })\n toLink.forEach((record) => {\n // Update (set) inverse relation\n // e.g. comment.post_id = post.id\n safeSetProp(record, foreignKey, id)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n // e.g. comment.post = post\n safeSetLink(record, inverseLocalField, this)\n })\n } else if (localKeys) {\n // Update locals\n // e.g. group.users = someUsers\n // Update (set) inverse relation\n const ids = toLink.map((child) => utils.get(child, relatedIdAttribute)).filter((id) => id !== undefined)\n // e.g. group.user_ids = [1,2,3,...]\n utils.set(this, localKeys, ids)\n // Update (unset) inverse relation\n if (inverseDef.foreignKeys) {\n current.forEach((child) => {\n const relatedId = utils.get(child, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(child) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update inverse relation\n // safeSetLink(child, inverseLocalField, undefined)\n const parents = utils.get(child, inverseLocalField) || []\n // e.g. someUser.groups.remove(group)\n if (id === undefined) {\n utils.remove(parents, (parent) => parent === this)\n } else {\n utils.remove(parents, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n }\n })\n toLink.forEach((child) => {\n // Update (set) inverse relation\n const parents = utils.get(child, inverseLocalField)\n // e.g. someUser.groups.push(group)\n if (id === undefined) {\n utils.noDupeAdd(parents, this, (parent) => parent === this)\n } else {\n utils.noDupeAdd(parents, this, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n })\n }\n } else if (foreignKeys) {\n // e.g. user.groups = someGroups\n // Update (unset) inverse relation\n current.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n // e.g. someGroup.user_ids.remove(user.id)\n utils.remove(ids, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n // e.g. someGroup.users.remove(user)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n // Update (set) inverse relation\n toLink.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n utils.noDupeAdd(ids, id, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n }\n\n this._set(path, toLink)\n return toLink\n }\n }\n } else if (type === hasOneType) {\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n descriptor = {\n get: getter,\n // e.g. user.profile = someProfile\n set (record) {\n const current = this._get(path)\n if (record === current) {\n return current\n }\n const inverseLocalField = def.getInverse(mapper).localField\n // Update (unset) inverse relation\n if (current) {\n safeSetProp(current, foreignKey, undefined)\n self.getCollection(relation).updateIndex(current, updateOpts)\n safeSetLink(current, inverseLocalField, undefined)\n }\n if (record) {\n const relatedId = utils.get(record, def.getRelation().idAttribute)\n // Prefer store record\n if (relatedId !== undefined) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n safeSetLink(this, localField, record)\n\n // Update (set) inverse relation\n safeSetProp(record, foreignKey, utils.get(this, idAttribute))\n self.getCollection(relation).updateIndex(record, updateOpts)\n safeSetLink(record, inverseLocalField, this)\n } else {\n // Unset locals\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n }\n\n if (descriptor) {\n descriptor.enumerable = def.enumerable === undefined ? false : def.enumerable\n if (def.get) {\n let origGet = descriptor.get\n descriptor.get = function () {\n return def.get(def, this, (...args) => origGet.apply(this, args))\n }\n }\n if (def.set) {\n let origSet = descriptor.set\n descriptor.set = function (related) {\n return def.set(def, this, related, (value) => origSet.call(this, value === undefined ? related : value))\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, localField, descriptor)\n }\n })\n\n return mapper\n },\n\n destroy (name, id, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroy.call(this, name, id, opts).then((result) => {\n let record\n if (opts.raw) {\n record = result.data\n } else {\n record = result\n }\n\n if (record && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n utils.set(record, def.localField, undefined)\n })\n }\n return result\n })\n },\n\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n let records\n if (opts.raw) {\n records = result.data\n } else {\n records = result\n }\n\n if (records && records.length && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n records.forEach((record) => {\n utils.set(record, def.localField, undefined)\n })\n })\n }\n return result\n })\n }\n}\n\nexport default SimpleStore.extend(props)\n\n/**\n * Create a subclass of this DataStore:\n * @example DataStore.extend\n * // Normally you would do: import {DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {DataStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomDataStoreClass extends DataStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customDataStore = new CustomDataStoreClass()\n * console.log(customDataStore.foo())\n * console.log(CustomDataStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherDataStoreClass = DataStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherDataStore = new OtherDataStoreClass()\n * console.log(otherDataStore.foo())\n * console.log(OtherDataStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherDataStoreClass () {\n * DataStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * DataStore.extend({\n * constructor: AnotherDataStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherDataStore = new AnotherDataStoreClass()\n * console.log(anotherDataStore.created_at)\n * console.log(anotherDataStore.foo())\n * console.log(AnotherDataStoreClass.beep())\n *\n * @method DataStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this DataStore class.\n * @since 3.0.0\n */\n","/**\n * Registered as `js-data` in NPM and Bower.\n *\n * Also available from CDN.JS and JSDelivr.\n *\n * @module js-data\n *\n * @example Install from NPM\n * npm i --save js-data@beta\n * @example Install from Bower\n * bower i --save js-data@3.0.0-beta.1\n * @example Install from CDN.JS\n * \n * @example Install from JSDelivr\n * \n * @example Load into your app via script tag\n * \n * \n * @example Load into your app via CommonJS\n * var JSData = require('js-data');\n * @example Load into your app via ES2015 Modules\n * import * as JSData from 'js-data';\n * @example Load into your app via AMD\n * define('myApp', ['js-data'], function (JSData) { ... })\n */\n\n/**\n * Describes the version of this `JSData` object.\n *\n * @example\n * console.log(JSData.version.full) // \"3.0.0-beta.1\"\n *\n * @name version\n * @memberof module:js-data\n * @property {string} full The full semver value.\n * @property {number} major The major version number.\n * @property {number} minor The minor version number.\n * @property {number} patch The patch version number.\n * @property {(string|boolean)} alpha The alpha version value, otherwise `false`\n * if the current version is not alpha.\n * @property {(string|boolean)} beta The beta version value, otherwise `false`\n * if the current version is not beta.\n * @since 2.0.0\n * @type {Object}\n */\nexport const version = '<%= version %>'\n\n/**\n * JSData's utility methods.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @name module:js-data.utils\n * @property {Function} Promise See {@link utils.Promise}.\n * @see utils\n * @since 3.0.0\n * @type {Object}\n */\nimport utils from './utils'\n\n/**\n * JSData's {@link Collection} class.\n *\n * @example\n * import {Collection} from 'js-data'\n * const collection = new Collection()\n *\n * @name module:js-data.Collection\n * @see Collection\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#collection\",\"Components of JSData: Collection\"]\n * @type {Constructor}\n */\nimport Collection from './Collection'\n\n/**\n * JSData's {@link Component} class. Most components in JSData extend this\n * class.\n *\n * @example\n * import {Component} from 'js-data'\n * // Make a custom component.\n * const MyComponent = Component.extend({\n * myMethod (someArg) { ... }\n * })\n *\n * @name module:js-data.Component\n * @see Component\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Component from './Component'\n\n/**\n * JSData's {@link Container} class. Defines and manages {@link Mapper}s. Used\n * in Node.js and in the browser, though in the browser you may want to use\n * {@link DataStore} instead.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n *\n * @name module:js-data.Container\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#container\",\"Components of JSData: Container\"]\n * @type {Constructor}\n */\nimport {Container} from './Container'\n\n/**\n * JSData's {@link DataStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {DataStore} from 'js-data'\n * const store = new DataStore()\n *\n * @name module:js-data.DataStore\n * @see DataStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @type {Constructor}\n */\nimport DataStore from './DataStore'\n\n/**\n * JSData's {@link Index} class, based on [mindex]{@link https://github.com/internalfx/mindex}.\n *\n * @name module:js-data.Index\n * @see Index\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Index from '../lib/mindex/index'\n\n/**\n * JSData's {@link LinkedCollection} class. Used by the {@link DataStore}\n * component. If you need to create a collection manually, you should probably\n * use the {@link Collection} class.\n *\n * @name module:js-data.LinkedCollection\n * @see DataStore\n * @see LinkedCollection\n * @since 3.0.0\n * @type {Constructor}\n */\nimport LinkedCollection from './LinkedCollection'\n\n/**\n * JSData's {@link Mapper} class. The core of the ORM.\n *\n * @example Recommended use\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @example Create Mapper manually\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @name module:js-data.Mapper\n * @see Container\n * @see Mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @type {Constructor}\n */\nimport Mapper from './Mapper'\n\n/**\n * JSData's {@link Query} class. Used by the {@link Collection} component.\n *\n * @name module:js-data.Query\n * @see Query\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Query from './Query'\n\n/**\n * JSData's {@link Record} class.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n *\n * @name module:js-data.Record\n * @see Record\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#record\",\"Components of JSData: Record\"]\n * @type {Constructor}\n */\nimport Record from './Record'\n\n/**\n * JSData's {@link Schema} class. Implements http://json-schema.org/draft-04.\n *\n * @example\n * import {Container, Schema} from 'js-data'\n * const userSchema = new Schema({\n * properties: {\n * id: { type: 'string' },\n * name: { type: 'string' }\n * }\n * })\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: userSchema\n * })\n *\n * @name module:js-data.Schema\n * @see Schema\n * @see http://json-schema.org/\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#schema\",\"Components of JSData: schema\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/schemas\",\"JSData's Schema Syntax\"]\n * @type {Constructor}\n */\nimport Schema from './Schema'\n\n/**\n * JSData's {@link Settable} class.\n *\n * @example\n * import {Settable} from 'js-data'\n * const obj = new Settable()\n * obj.set('secret', 'value')\n * console.log(JSON.stringify(obj)) // {}\n *\n * @name module:js-data.Settable\n * @see Settable\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Settable from './Settable'\n\n/**\n * JSData's {@link SimpleStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * const store = new SimpleStore()\n *\n * @name module:js-data.SimpleStore\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @type {Constructor}\n */\nimport SimpleStore from './SimpleStore'\n\nexport * from './decorators'\n\nexport {\n Collection,\n Component,\n Container,\n DataStore,\n Index,\n LinkedCollection,\n Mapper,\n Query,\n Record,\n Schema,\n Settable,\n SimpleStore,\n utils\n}\n"],"names":["DOMAIN","INFINITY","MAX_INTEGER","BOOL_TAG","DATE_TAG","FUNC_TAG","NUMBER_TAG","OBJECT_TAG","REGEXP_TAG","STRING_TAG","objToString","Object","prototype","toString","PATH","ERRORS","arguments","toInteger","value","sign","remainder","toStr","call","isPlainObject","constructor","mkdirP","object","path","parts","split","forEach","key","utils","Promise","dest","src","forOwn","undefined","isFunction","indexOf","opts","def","fn","thisArg","relationName","relation","containedName","index","with","_getIndex","localField","withAll","optsCopy","fillIn","getRelation","slice","_activeWith","splice","i","length","substr","list","_relation","isObject","target","props","map","keys","propName","descriptor","getOwnPropertyDescriptor","enumerable","defineProperties","newObject","oldObject","diff","diffObjects","diffCount","added","removed","changed","instance","ctor","err","name","from","to","stackFrom","stackTo","blacklist","plain","isArray","copy","isDate","Date","getTime","isRegExp","RegExp","source","match","lastIndex","create","getPrototypeOf","push","result","hasOwnProperty","isBlacklisted","existing","deepFillIn","deepMixIn","equalsFn","ignore","deepEqual","newKeys","filter","oldKeys","oldValue","newValue","a","b","domain","code","prefix","message","apply","Array","Error","getter","setter","_events","events","args","type","shift","listeners","f","c","all","unshift","func","classProps","superClass","subClass","classCallCheck","obj","setPrototypeOf","strictEs6Class","__proto__","defineProperty","addHiddenPropsToTarget","array","record","mapper","relationList","_forRelation","len","json","isString","JSON","parse","prop","last","pop","isCtor","__super__","array1","array2","item","matches","test","isNumber","log","level","debug","toUpperCase","console","findIndex","_props","reduce","reject","resolve","_path","set","exec","_equal","stringify","safeSetProp","field","_set","safeSetLink","Settable","get","unset","extend","Component","writable","logify","eventify","_listeners","INDEX_ERR","reserved","escapeRegExp","percentRegExp","underscoreRegExp","escape","pattern","replace","Query","collection","data","where","fields","ops","predicates","clause","expr","op","groups","_where","prev","parser","_applyWhereFromArray","_applyWhereFromObject","group","isOr","keep","first","charAt","evaluate","_testArrayGroup","_testObjectGroup","leftKeys","rightKeys","getIndex","between","orderBy","cA","cB","temp","compare","predicate","like","query","getData","sort","skip","offset","limit","forEachFn","keyList","concat","getAll","flags","num","Math","min","mapFn","funcName","intersection","hashCode","insertAt","removeAt","binarySearch","lo","hi","compared","mid","Index","fieldList","fieldGetter","isIndex","values","pos","found","dataLocation","newIndex","results","order","cb","visitAll","_between","leftKey","rightKey","leftInclusive","rightInclusive","currKey","peek","isUnique","removeRecord","j","insertRecord","COLLECTION_DEFAULTS","Collection","records","idAttribute","queryClass","recordId","add","emitRecordEvents","emit","_","beforeAdd","singular","id","onConflict","commitOnMerge","commit","updateIndexes","createRecord","indexes","on","_onRecordEvent","silent","afterAdd","run","instances","removeAll","unsaved","Ctor","initialValue","idOrRecord","beforeRemove","isSorN","off","afterRemove","queryOrRecords","beforeRemoveAll","plainCopy","remove","afterRemoveAll","mapCall","updateRecord","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","relationFields","relatedRecord","_setForeignKey","relatedRecords","relatedData","inverse","findInverseRelation","isInversedTo","getLocalField","linkRecord","isEmptyLinks","canFindLinkFor","findExistingLinksFor","setLocalField","relatedId","setForeignKey","BelongsToRelation","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","ids","findExistingLinksByForeignKey","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","HasOneRelation","RelationType","belongsTo","assignTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","_get","_mapper","quickHasChanges","areDifferent","validate","currentParent","inverseDef","children","child","noDupeAdd","relations","adapter","getAdapterName","then","dbg","tasks","task","forEachRelation","raw","load","previous","preserve","postProcess","changesOnly","changes","types","isBoolean","isInteger","isNull","segmentToString","segment","str","makePath","segments","makeError","actual","expected","addError","errors","maxLengthCommon","keyword","schema","max","minLengthCommon","validationKeywords","allErrors","allOf","_schema","validated","anyOf","possibleValues","join","items","checkingTuple","maximum","exclusiveMaximum","maxProperties","minimum","exclusiveMinimum","minProperties","multipleOf","not","oneOf","additionalProperties","properties","patternProperties","toValidate","omit","undef","origProp","required","existingOnly","prevProp","validType","_type","validator","typeGroupValidators","uniqueItems","runOps","ANY_OPS","ARRAY_OPS","NUMERIC_OPS","OBJECT_OPS","STRING_OPS","validateAny","ctx","shouldPop","changingPath","changedPath","changeHistoryPath","eventIdPath","silentPath","validationFailureMsg","makeDescriptor","keyPath","unsetter","track","originalGet","_unset","error","current","changing","setTimeout","changeRecord","timestamp","changeHistory","originalSet","numeric","Schema","definition","_definition","extends","validationKeyword","hasSet","orig","applyDefaults","pick","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","MAPPER_DEFAULTS","Mapper","recordClass","methods","isPrototypeOf","applySchema","_data","wrap","crud","originalRecord","belongsToRelationData","relationData","relatedIdAttribute","createMany","getAdapter","pass","createdRecordData","_end","_result","originalRecords","_records","createdRecordsData","belongsToData","RecordCtor","is","method","config","lifecycleMethods","upper","before","after","defaults","_value","beforeAssign","adapterArgs","getAdapters","defaultAdapter","_adapters","default","strict","_opts","_record","foundErrors","_name","getMapperByName","getMapper","proxiedMapperMethods","Container","mapperDefaults","mapperClass","original","_mappers","_onMapperEvent","defineRelations","warn","defineMapper","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","_completedQueries","SIMPLESTORE_DEFAULTS","SimpleStore","collectionClass","_collections","_pendingQueries","addToCache","hash","fromJson","self","indexed","createIndex","_added","_onCollectionEvent","destroy","destroyAll","hashQuery","pendingQuery","usePendingFind","cachedFind","promise","force","find","cacheFind","usePendingFindAll","cachedFindAll","findAll","cacheFindAll","toJson","removeRelated","getForeignKey","update","updateAll","updateMany","LinkedCollection","event","addLinkedRecords","_addMeta","_clearMeta","removeLinkedRecords","DATASTORE_DEFAULTS","DataStore","updateOpts","getInverse","removeInverseRelation","updateIndex","setupInverseRelation","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","parent","_key","origGet","origSet","unlinkOnDestroy","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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* @version 3.0.0-rc.6 - Homepage +* @version 3.0.0-rc.7 - Homepage * @author js-data project authors * @copyright (c) 2014-2016 js-data project authors * @license MIT @@ -8,15 +8,15 @@ * @overview js-data is a framework-agnostic, datastore-agnostic ORM/ODM for Node.js and the Browser. */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define('js-data', ['exports'], factory) : - (factory((global.JSData = global.JSData || {}))); + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define('js-data', ['exports'], factory) : + (factory((global.JSData = global.JSData || {}))); }(this, (function (exports) { 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; @@ -31,6 +31,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol + + + + + + var defineProperty = function (obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { @@ -46,31 +52,6 @@ var defineProperty = function (obj, key, value) { return obj; }; -var get$1 = function get$1(object, property, receiver) { - if (object === null) object = Function.prototype; - var desc = Object.getOwnPropertyDescriptor(object, property); - - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - - if (parent === null) { - return undefined; - } else { - return get$1(parent, property, receiver); - } - } else if ("value" in desc) { - return desc.value; - } else { - var getter = desc.get; - - if (getter === undefined) { - return undefined; - } - - return getter.call(receiver); - } -}; - @@ -87,27 +68,9 @@ var get$1 = function get$1(object, property, receiver) { -var set$1 = function set$1(object, property, value, receiver) { - var desc = Object.getOwnPropertyDescriptor(object, property); - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - if (parent !== null) { - set$1(parent, property, value, receiver); - } - } else if ("value" in desc && desc.writable) { - desc.value = value; - } else { - var setter = desc.set; - if (setter !== undefined) { - setter.call(receiver, value); - } - } - - return value; -}; @@ -393,7 +356,7 @@ var utils = { * @throws {Error} Throws an error if the constructor is being improperly * invoked. */ - classCallCheck: function classCallCheck(instance, ctor) { + classCallCheck: function classCallCheck$$1(instance, ctor) { if (!(instance instanceof ctor)) { throw utils.err('' + ctor.name)(500, 'Cannot call a class as a function'); } @@ -430,7 +393,7 @@ var utils = { } else if (utils.isDate(from)) { to = new Date(from.getTime()); } else if (utils.isRegExp(from)) { - to = new RegExp(from.source, from.toString().match(/[^\/]*$/)[0]); + to = new RegExp(from.source, from.toString().match(/[^/]*$/)[0]); to.lastIndex = from.lastIndex; } else if (utils.isObject(from)) { if (plain) { @@ -998,7 +961,7 @@ var utils = { * @see utils.set * @since 3.0.0 */ - 'get': function get(object, prop) { + 'get': function get$$1(object, prop) { if (!prop) { return; } @@ -1507,13 +1470,10 @@ var utils = { * @since 3.0.0 */ pick: function pick(props, keys) { - var _props = {}; - utils.forOwn(props, function (value, key) { - if (keys.indexOf(key) !== -1) { - _props[key] = value; - } - }); - return _props; + return keys.reduce(function (map, key) { + map[key] = props[key]; + return map; + }, {}); }, @@ -1646,7 +1606,7 @@ var utils = { * object. * @param {*} [value] The value to set. */ - set: function set(object, path, value) { + set: function set$$1(object, path, value) { if (utils.isObject(path)) { utils.forOwn(path, function (value, _path) { utils.set(object, _path, value); @@ -2170,7 +2130,7 @@ var reserved = { }; // Used by our JavaScript implementation of the LIKE operator -var escapeRegExp = /([.*+?^=!:${}()|[\]\/\\])/g; +var escapeRegExp = /([.*+?^=!:${}()|[\]/\\])/g; var percentRegExp = /%/g; var underscoreRegExp = /_/g; var escape = function escape(pattern) { @@ -3677,6 +3637,15 @@ var COLLECTION_DEFAULTS = { */ commitOnMerge: true, + /** + * Whether record events should bubble up and be emitted by the collection. + * + * @name Collection#emitRecordEvents + * @type {boolean} + * @default true + */ + emitRecordEvents: true, + /** * Field to be used as the unique identifier for records in this collection. * Defaults to `"id"` unless {@link Collection#mapper} is set, in which case @@ -3844,7 +3813,9 @@ var Collection$1 = Component$1.extend({ * @param {...*} [arg] Args passed to {@link Collection#emit}. */ _onRecordEvent: function _onRecordEvent() { - this.emit.apply(this, arguments); + if (this.emitRecordEvents) { + this.emit.apply(this, arguments); + } }, @@ -3941,7 +3912,9 @@ var Collection$1 = Component$1.extend({ }); // Finally, return the inserted data var result = singular ? records[0] : records; - this.emit('add', result); + if (!opts.silent) { + this.emit('add', result); + } return this.afterAdd(records, opts, result) || result; }, @@ -4645,7 +4618,7 @@ var hasOneType = 'hasOne'; var DOMAIN$6 = 'Relation'; function Relation(relatedMapper) { - var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; utils.classCallCheck(this, Relation); @@ -4848,9 +4821,9 @@ var HasManyRelation = Relation.extend({ validateOptions: function validateOptions(related, opts) { Relation.prototype.validateOptions.call(this, related, opts); - var localKeys = opts.localKeys; - var foreignKeys = opts.foreignKeys; - var foreignKey = opts.foreignKey; + var localKeys = opts.localKeys, + foreignKeys = opts.foreignKeys, + foreignKey = opts.foreignKey; if (!foreignKey && !localKeys && !foreignKeys) { @@ -4959,7 +4932,7 @@ var HasOneRelation = Relation.extend({ * @returns {Function} Invocation function, which accepts the target as the only * parameter. */ -var belongsTo$1 = function belongsTo$1(related, opts) { +var belongsTo = function belongsTo(related, opts) { return function (mapper) { Relation.belongsTo(related, opts).assignTo(mapper); }; @@ -4979,7 +4952,7 @@ var belongsTo$1 = function belongsTo$1(related, opts) { * @returns {Function} Invocation function, which accepts the target as the only * parameter. */ -var hasMany$1 = function hasMany$1(related, opts) { +var hasMany = function hasMany(related, opts) { return function (mapper) { Relation.hasMany(related, opts).assignTo(mapper); }; @@ -4999,7 +4972,7 @@ var hasMany$1 = function hasMany$1(related, opts) { * @returns {Function} Invocation function, which accepts the target as the only * parameter. */ -var hasOne$1 = function hasOne$1(related, opts) { +var hasOne = function hasOne(related, opts) { return function (mapper) { Relation.hasOne(related, opts).assignTo(mapper); }; @@ -5314,7 +5287,7 @@ var Record$1 = Component$1.extend({ * @returns {*} Value at path. * @since 3.0.0 */ - 'get': function get(key) { + 'get': function get$$1(key) { return utils.get(this, key); }, @@ -5675,7 +5648,7 @@ var Record$1 = Component$1.extend({ * session.skill_level = 'beginner' * * // Update the record in the database - * return user.save() + * return session.save() * }) * * @method Record#save @@ -5750,7 +5723,7 @@ var Record$1 = Component$1.extend({ * @param {boolean} [opts.silent=false] Whether to trigger change events. * @since 3.0.0 */ - 'set': function set(key, value, opts) { + 'set': function set$$1(key, value, opts) { if (utils.isObject(key)) { opts = value; } @@ -6476,12 +6449,16 @@ var validationKeywords = { */ properties: function properties(value, schema, opts) { opts || (opts = {}); + + if (utils.isArray(value)) { + return; + } + // Can be a boolean or an object // Technically the default is an "empty schema", but here "true" is // functionally the same var additionalProperties = schema.additionalProperties === undefined ? true : schema.additionalProperties; - // "s": The property set of the instance to validate. - var toValidate = {}; + var validated = []; // "p": The property set from "properties". // Default is an object var properties = schema.properties || {}; @@ -6490,28 +6467,24 @@ var validationKeywords = { var patternProperties = schema.patternProperties || {}; var errors = []; - // Collect set "s" - utils.forOwn(value, function (_value, prop) { - toValidate[prop] = undefined; - }); - // Remove from "s" all elements of "p", if any. - utils.forOwn(properties || {}, function (_schema, prop) { + utils.forOwn(properties, function (_schema, prop) { opts.prop = prop; errors = errors.concat(_validate(value[prop], _schema, opts) || []); - delete toValidate[prop]; + validated.push(prop); }); - // For each regex in "pp", remove all elements of "s" which this regex - // matches. + + var toValidate = utils.omit(value, validated); utils.forOwn(patternProperties, function (_schema, pattern) { utils.forOwn(toValidate, function (undef, prop) { if (prop.match(pattern)) { opts.prop = prop; + // console.log(_schema) errors = errors.concat(_validate(value[prop], _schema, opts) || []); - delete toValidate[prop]; + validated.push(prop); } }); }); - var keys = Object.keys(toValidate); + var keys = Object.keys(utils.omit(value, validated)); // If "s" is not empty, validation fails if (additionalProperties === false) { if (keys.length) { @@ -7034,7 +7007,8 @@ function Schema(definition) { // TODO: schema validation utils.fillIn(this, definition); - if (this.type === 'object' && this.properties) { + if (this.type === 'object') { + this.properties = this.properties || {}; utils.forOwn(this.properties, function (_definition, prop) { if (!(_definition instanceof Schema)) { _this2.properties[prop] = new Schema(_definition); @@ -7706,8 +7680,8 @@ function Mapper(opts) { (function () { var superClass = Record$1; _this2.recordClass = superClass.extend({ - constructor: function Record$1() { - var subClass = function Record$1(props, opts) { + constructor: function Record() { + var subClass = function Record(props, opts) { utils.classCallCheck(this, subClass); superClass.call(this, props, opts); }; @@ -8085,8 +8059,8 @@ var Mapper$1 = Component$1.extend({ * @see http://www.js-data.io/v3.0/docs/relations * @since 3.0.0 */ - belongsTo: function belongsTo(relatedMapper, opts) { - return belongsTo$1(relatedMapper, opts)(this); + belongsTo: function belongsTo$$1(relatedMapper, opts) { + return belongsTo(relatedMapper, opts)(this); }, @@ -9170,8 +9144,8 @@ var Mapper$1 = Component$1.extend({ * @see http://www.js-data.io/v3.0/docs/relations * @since 3.0.0 */ - hasMany: function hasMany(relatedMapper, opts) { - return hasMany$1(relatedMapper, opts)(this); + hasMany: function hasMany$$1(relatedMapper, opts) { + return hasMany(relatedMapper, opts)(this); }, @@ -9191,8 +9165,8 @@ var Mapper$1 = Component$1.extend({ * @see http://www.js-data.io/v3.0/docs/relations * @since 3.0.0 */ - hasOne: function hasOne(relatedMapper, opts) { - return hasOne$1(relatedMapper, opts)(this); + hasOne: function hasOne$$1(relatedMapper, opts) { + return hasOne(relatedMapper, opts)(this); }, @@ -11201,7 +11175,7 @@ Component$1.extend(props); * @since 3.0.0 */ -var DOMAIN$9 = 'SimpleStore'; +var DOMAIN$8 = 'SimpleStore'; var proxiedCollectionMethods = [ /** * Wrapper for {@link Collection#add}. @@ -12507,6 +12481,7 @@ var props$2 = { * @param {string} name Name of the {@link Mapper} to target. * @param {(string|number)} id Passed to {@link Mapper#find}. * @param {Object} [opts] Passed to {@link Mapper#find}. + * @param {boolean} [opts.force] Bypass cacheFind * @param {boolean|Function} [opts.usePendingFind] See {@link SimpleStore#usePendingFind} * @returns {Promise} Resolves with the result, if any. * @since 3.0.0 @@ -12621,6 +12596,7 @@ var props$2 = { * @param {string} name Name of the {@link Mapper} to target. * @param {Object} [query] Passed to {@link Mapper.findAll}. * @param {Object} [opts] Passed to {@link Mapper.findAll}. + * @param {boolean} [opts.force] Bypass cacheFindAll * @param {boolean|Function} [opts.usePendingFindAll] See {@link SimpleStore#usePendingFindAll} * @returns {Promise} Resolves with the result, if any. * @since 3.0.0 @@ -12673,7 +12649,7 @@ var props$2 = { getCollection: function getCollection(name) { var collection = this._collections[name]; if (!collection) { - throw utils.err(DOMAIN$9 + '#getCollection', name)(404, 'collection'); + throw utils.err(DOMAIN$8 + '#getCollection', name)(404, 'collection'); } return collection; }, @@ -13029,7 +13005,7 @@ var props$2 = { var _this12 = this; opts || (opts = {}); - return Container.prototype.updateAll.call(this, name, query, props, opts).then(function (result) { + return Container.prototype.updateAll.call(this, name, props, query, opts).then(function (result) { return _this12._end(name, result, opts); }); }, @@ -13299,7 +13275,7 @@ var SimpleStore$1 = Container.extend(props$2); * @since 3.0.0 */ -var DOMAIN$10 = 'LinkedCollection'; +var DOMAIN$9 = 'LinkedCollection'; /** * Extends {@link Collection}. Used by a {@link DataStore} to implement an @@ -13333,7 +13309,7 @@ function LinkedCollection(records, opts) { // Make sure this collection has a reference to a datastore if (!this.datastore) { - throw utils.err('new ' + DOMAIN$10, 'opts.datastore')(400, 'DataStore', this.datastore); + throw utils.err('new ' + DOMAIN$9, 'opts.datastore')(400, 'DataStore', this.datastore); } } @@ -14099,7 +14075,7 @@ var DataStore$1 = SimpleStore$1.extend(props$1); * @type {Object} */ var version = { - full: '3.0.0-rc.6', + full: '3.0.0-rc.7', major: 3, minor: 0, patch: 0 @@ -14305,9 +14281,9 @@ exports.Schema = Schema$1; exports.Settable = Settable; exports.SimpleStore = SimpleStore$1; exports.utils = utils; -exports.belongsTo = belongsTo$1; -exports.hasMany = hasMany$1; -exports.hasOne = hasOne$1; +exports.belongsTo = belongsTo; +exports.hasMany = hasMany; +exports.hasOne = hasOne; exports.belongsToType = belongsToType; exports.hasManyType = hasManyType; exports.hasOneType = hasOneType; diff --git a/dist/js-data.js.map b/dist/js-data.js.map index 340e8ea0..4d6fd2ad 100644 --- a/dist/js-data.js.map +++ b/dist/js-data.js.map @@ -1 +1 @@ -{"version":3,"file":null,"sources":["../src/utils.js","../src/Settable.js","../src/Component.js","../src/Query.js","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.js","../src/Relation.js","../src/Relation/BelongsTo.js","../src/Relation/HasMany.js","../src/Relation/HasOne.js","../src/relations.js","../src/decorators.js","../src/Record.js","../src/Schema.js","../src/Mapper.js","../src/Container.js","../src/SimpleStore.js","../src/LinkedCollection.js","../src/DataStore.js","../src/index.js"],"sourcesContent":["/**\n * Utility methods used by JSData.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @namespace utils\n * @type {Object}\n */\n\nconst DOMAIN = 'utils'\n\nconst INFINITY = 1 / 0\nconst MAX_INTEGER = 1.7976931348623157e+308\nconst BOOL_TAG = '[object Boolean]'\nconst DATE_TAG = '[object Date]'\nconst FUNC_TAG = '[object Function]'\nconst NUMBER_TAG = '[object Number]'\nconst OBJECT_TAG = '[object Object]'\nconst REGEXP_TAG = '[object RegExp]'\nconst STRING_TAG = '[object String]'\nconst objToString = Object.prototype.toString\nconst PATH = /^(.+)\\.(.+)$/\n\nconst ERRORS = {\n '400' () { return `expected: ${arguments[0]}, found: ${arguments[2] ? arguments[1] : typeof arguments[1]}` },\n '404' () { return `${arguments[0]} not found` }\n}\n\nconst toInteger = function (value) {\n if (!value) {\n return 0\n }\n // Coerce to number\n value = +value\n if (value === INFINITY || value === -INFINITY) {\n const sign = (value < 0 ? -1 : 1)\n return sign * MAX_INTEGER\n }\n const remainder = value % 1\n return value === value ? (remainder ? value - remainder : value) : 0 // eslint-disable-line\n}\n\nconst toStr = function (value) {\n return objToString.call(value)\n}\n\nconst isPlainObject = function (value) {\n return (!!value && typeof value === 'object' && value.constructor === Object)\n}\n\nconst mkdirP = function (object, path) {\n if (!path) {\n return object\n }\n const parts = path.split('.')\n parts.forEach(function (key) {\n if (!object[key]) {\n object[key] = {}\n }\n object = object[key]\n })\n return object\n}\n\nconst utils = {\n /**\n * Reference to the Promise constructor used by JSData. Defaults to\n * `window.Promise` or `global.Promise`.\n *\n * @example Make JSData use a different `Promise` constructor\n * import Promise from 'bluebird'\n * import {utils} from 'js-data'\n * utils.Promise = Promise\n *\n * @name utils.Promise\n * @since 3.0.0\n * @type {Function}\n */\n Promise: Promise,\n\n /**\n * Shallow copy properties that meet the following criteria from `src` to\n * `dest`:\n *\n * - own enumerable\n * - not a function\n * - does not start with \"_\"\n *\n * @method utils._\n * @param {Object} dest Destination object.\n * @param {Object} src Source object.\n * @private\n * @since 3.0.0\n */\n _ (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (key && dest[key] === undefined && !utils.isFunction(value) && key.indexOf('_') !== 0) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Recursively iterates over relations found in `opts.with`.\n *\n * @method utils._forRelation\n * @param {Object} opts Configuration options.\n * @param {Relation} def Relation definition.\n * @param {Function} fn Callback function.\n * @param {*} [thisArg] Execution context for the callback function.\n * @private\n * @since 3.0.0\n */\n _forRelation (opts, def, fn, thisArg) {\n const relationName = def.relation\n let containedName = null\n let index\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n if ((index = utils._getIndex(opts.with, relationName)) >= 0) {\n containedName = relationName\n } else if ((index = utils._getIndex(opts.with, def.localField)) >= 0) {\n containedName = def.localField\n }\n\n if (opts.withAll) {\n fn.call(thisArg, def, {})\n return\n } else if (!containedName) {\n return\n }\n let optsCopy = {}\n utils.fillIn(optsCopy, def.getRelation())\n utils.fillIn(optsCopy, opts)\n optsCopy.with = opts.with.slice()\n optsCopy._activeWith = optsCopy.with.splice(index, 1)[0]\n optsCopy.with.forEach(function (relation, i) {\n if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {\n optsCopy.with[i] = relation.substr(containedName.length + 1)\n } else {\n optsCopy.with[i] = ''\n }\n })\n fn.call(thisArg, def, optsCopy)\n },\n\n /**\n * Find the index of a relation in the given list\n *\n * @method utils._getIndex\n * @param {string[]} list List to search.\n * @param {string} relation Relation to find.\n * @private\n * @returns {number}\n */\n _getIndex (list, relation) {\n let index = -1\n list.forEach(function (_relation, i) {\n if (_relation === relation) {\n index = i\n return false\n } else if (utils.isObject(_relation)) {\n if (_relation.relation === relation) {\n index = i\n return false\n }\n }\n })\n return index\n },\n\n /**\n * Define hidden (non-enumerable), writable properties on `target` from the\n * provided `props`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {}\n * utils.addHiddenPropsToTarget(Cat.prototype, {\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat.say() // \"meow\"\n *\n * @method utils.addHiddenPropsToTarget\n * @param {Object} target That to which `props` should be added.\n * @param {Object} props Properties to be added to `target`.\n * @since 3.0.0\n */\n addHiddenPropsToTarget (target, props) {\n const map = {}\n Object.keys(props).forEach(function (propName) {\n const descriptor = Object.getOwnPropertyDescriptor(props, propName)\n\n descriptor.enumerable = false\n map[propName] = descriptor\n })\n Object.defineProperties(target, map)\n },\n\n /**\n * Return whether the two objects are deeply different.\n *\n * @example\n * import {utils} from 'js-data'\n * utils.areDifferent({}, {}) // false\n * utils.areDifferent({ a: 1 }, { a: 1 }) // false\n * utils.areDifferent({ foo: 'bar' }, {}) // true\n *\n * @method utils.areDifferent\n * @param {Object} a Base object.\n * @param {Object} b Comparison object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Whether the two objects are deeply different.\n * @see utils.diffObjects\n * @since 3.0.0\n */\n areDifferent (newObject, oldObject, opts) {\n opts || (opts = {})\n const diff = utils.diffObjects(newObject, oldObject, opts)\n const diffCount = Object.keys(diff.added).length +\n Object.keys(diff.removed).length +\n Object.keys(diff.changed).length\n return diffCount > 0\n },\n\n /**\n * Verified that the given constructor is being invoked via `new`, as opposed\n * to just being called like a normal function.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {\n * utils.classCallCheck(this, Cat)\n * }\n * const cat = new Cat() // this is ok\n * Cat() // this throws an error\n *\n * @method utils.classCallCheck\n * @param {*} instance Instance that is being constructed.\n * @param {Constructor} ctor Constructor function used to construct the\n * instance.\n * @since 3.0.0\n * @throws {Error} Throws an error if the constructor is being improperly\n * invoked.\n */\n classCallCheck (instance, ctor) {\n if (!(instance instanceof ctor)) {\n throw utils.err(`${ctor.name}`)(500, 'Cannot call a class as a function')\n }\n },\n\n /**\n * Deep copy a value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' } }\n * const b = utils.copy(a)\n * a === b // false\n * utils.areDifferent(a, b) // false\n *\n * @param {*} from Value to deep copy.\n * @param {*} [to] Destination object for the copy operation.\n * @param {*} [stackFrom] For internal use.\n * @param {*} [stackTo] For internal use.\n * @param {string[]|RegExp[]} [blacklist] List of strings or RegExp of\n * properties to skip.\n * @param {boolean} [plain] Whether to make a plain copy (don't try to use\n * original prototype).\n * @returns {*} Deep copy of `from`.\n * @since 3.0.0\n */\n copy (from, to, stackFrom, stackTo, blacklist, plain) {\n if (!to) {\n to = from\n if (from) {\n if (utils.isArray(from)) {\n to = utils.copy(from, [], stackFrom, stackTo, blacklist, plain)\n } else if (utils.isDate(from)) {\n to = new Date(from.getTime())\n } else if (utils.isRegExp(from)) {\n to = new RegExp(from.source, from.toString().match(/[^\\/]*$/)[0])\n to.lastIndex = from.lastIndex\n } else if (utils.isObject(from)) {\n if (plain) {\n to = utils.copy(from, {}, stackFrom, stackTo, blacklist, plain)\n } else {\n to = utils.copy(from, Object.create(Object.getPrototypeOf(from)), stackFrom, stackTo, blacklist, plain)\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(500, 'Cannot copy! Source and destination are identical.')\n }\n\n stackFrom = stackFrom || []\n stackTo = stackTo || []\n\n if (utils.isObject(from)) {\n let index = stackFrom.indexOf(from)\n if (index !== -1) {\n return stackTo[index]\n }\n\n stackFrom.push(from)\n stackTo.push(to)\n }\n\n let result\n if (utils.isArray(from)) {\n let i\n to.length = 0\n for (i = 0; i < from.length; i++) {\n result = utils.copy(from[i], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[i])) {\n stackFrom.push(from[i])\n stackTo.push(result)\n }\n to.push(result)\n }\n } else {\n if (utils.isArray(to)) {\n to.length = 0\n } else {\n utils.forOwn(to, function (value, key) {\n delete to[key]\n })\n }\n for (var key in from) {\n if (from.hasOwnProperty(key)) {\n if (utils.isBlacklisted(key, blacklist)) {\n continue\n }\n result = utils.copy(from[key], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[key])) {\n stackFrom.push(from[key])\n stackTo.push(result)\n }\n to[key] = result\n }\n }\n }\n }\n return to\n },\n\n /**\n * Recursively shallow fill in own enumerable properties from `source` to\n * `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"bip\"}\n *\n * @method utils.deepFillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n deepFillIn (dest, source) {\n if (source) {\n utils.forOwn(source, function (value, key) {\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepFillIn(existing, value)\n } else if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n }\n return dest\n },\n\n /**\n * Recursively shallow copy enumerable properties from `source` to `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"boop\"}\n *\n * @method utils.deepMixIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepFillIn\n * @since 3.0.0\n */\n deepMixIn (dest, source) {\n if (source) {\n for (var key in source) {\n const value = source[key]\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepMixIn(existing, value)\n } else {\n dest[key] = value\n }\n }\n }\n return dest\n },\n\n /**\n * Return a diff of the base object to the comparison object.\n *\n * @example\n * import {utils} from 'js-data'\n * const oldObject = { foo: 'bar', a: 1234 }\n * const newObject = { beep: 'boop', a: 5678 }\n * const diff = utils.diffObjects(oldObject, newObject)\n * console.log(diff.added) // {\"beep\":\"boop\"}\n * console.log(diff.changed) // {\"a\":5678}\n * console.log(diff.removed) // {\"foo\":undefined}\n *\n * @method utils.diffObjects\n * @param {Object} newObject Comparison object.\n * @param {Object} oldObject Base object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} The diff from the base object to the comparison object.\n * @see utils.areDifferent\n * @since 3.0.0\n */\n diffObjects (newObject, oldObject, opts) {\n opts || (opts = {})\n let equalsFn = opts.equalsFn\n let blacklist = opts.ignore\n const diff = {\n added: {},\n changed: {},\n removed: {}\n }\n if (!utils.isFunction(equalsFn)) {\n equalsFn = utils.deepEqual\n }\n\n const newKeys = Object.keys(newObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n const oldKeys = Object.keys(oldObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n\n // Check for properties that were added or changed\n newKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (equalsFn(oldValue, newValue)) {\n return\n }\n if (oldValue === undefined) {\n diff.added[key] = newValue\n } else {\n diff.changed[key] = newValue\n }\n })\n\n // Check for properties that were removed\n oldKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (newValue === undefined && oldValue !== undefined) {\n diff.removed[key] = undefined\n }\n })\n\n return diff\n },\n\n /**\n * Return whether the two values are equal according to the `==` operator.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.equal(1,1)) // true\n * console.log(utils.equal(1,'1')) // true\n * console.log(utils.equal(93, 66)) // false\n *\n * @method utils.equal\n * @param {*} a First value in the comparison.\n * @param {*} b Second value in the comparison.\n * @returns {boolean} Whether the two values are equal according to `==`.\n * @since 3.0.0\n */\n equal (a, b) {\n return a == b // eslint-disable-line\n },\n\n /**\n * Produce a factory function for making Error objects with the provided\n * metadata. Used throughout the various js-data components.\n *\n * @example\n * import {utils} from 'js-data'\n * const errorFactory = utils.err('domain', 'target')\n * const error400 = errorFactory(400, 'expected type', 'actual type')\n * console.log(error400) // [Error: [domain:target] expected: expected type, found: string\nhttp://www.js-data.io/v3.0/docs/errors#400]\n * @method utils.err\n * @param {string} domain Namespace.\n * @param {string} target Target.\n * @returns {Function} Factory function.\n * @since 3.0.0\n */\n err (domain, target) {\n return function (code) {\n const prefix = `[${domain}:${target}] `\n let message = ERRORS[code].apply(null, Array.prototype.slice.call(arguments, 1))\n message = `${prefix}${message}\nhttp://www.js-data.io/v3.0/docs/errors#${code}`\n return new Error(message)\n }\n },\n\n /**\n * Add eventing capabilities into the target object.\n *\n * @example\n * import {utils} from 'js-data'\n * const user = { name: 'John' }\n * utils.eventify(user)\n * user.on('foo', () => console.log(arguments))\n * user.emit('foo', 1, 'bar') // should log to console values (1, \"bar\")\n *\n * @method utils.eventify\n * @param {Object} target Target object.\n * @param {Function} [getter] Custom getter for retrieving the object's event\n * listeners.\n * @param {Function} [setter] Custom setter for setting the object's event\n * listeners.\n * @since 3.0.0\n */\n eventify (target, getter, setter) {\n target = target || this\n let _events = {}\n if (!getter && !setter) {\n getter = function () { return _events }\n setter = function (value) { _events = value }\n }\n Object.defineProperties(target, {\n emit: {\n value (...args) {\n const events = getter.call(this) || {}\n const type = args.shift()\n let listeners = events[type] || []\n let i\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n listeners = events.all || []\n args.unshift(type)\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n }\n },\n off: {\n value (type, func) {\n const events = getter.call(this)\n const listeners = events[type]\n if (!listeners) {\n setter.call(this, {})\n } else if (func) {\n for (let i = 0; i < listeners.length; i++) {\n if (listeners[i].f === func) {\n listeners.splice(i, 1)\n break\n }\n }\n } else {\n listeners.splice(0, listeners.length)\n }\n }\n },\n on: {\n value (type, func, thisArg) {\n if (!getter.call(this)) {\n setter.call(this, {})\n }\n const events = getter.call(this)\n events[type] = events[type] || []\n events[type].push({\n c: thisArg,\n f: func\n })\n }\n }\n })\n },\n\n /**\n * Used for sublcassing. Invoke this method in the context of a superclass to\n * to produce a subclass based on `props` and `classProps`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Animal () {}\n * Animal.extend = utils.extend\n * const Cat = Animal.extend({\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat instanceof Animal // true\n * cat instanceof Cat // true\n * cat.say() // \"meow\"\n *\n * @method utils.extend\n * @param {Object} props Instance properties for the subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to use as the subclass.\n * @param {Object} props Static properties for the subclass.\n * @returns {Constructor} A new subclass.\n * @since 3.0.0\n */\n extend (props, classProps) {\n const superClass = this\n let subClass\n\n props || (props = {})\n classProps || (classProps = {})\n\n if (props.hasOwnProperty('constructor')) {\n subClass = props.constructor\n delete props.constructor\n } else {\n subClass = function (...args) {\n utils.classCallCheck(this, subClass)\n superClass.apply(this, args)\n }\n }\n\n // Setup inheritance of instance members\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n configurable: true,\n enumerable: false,\n value: subClass,\n writable: true\n }\n })\n\n const obj = Object\n // Setup inheritance of static members\n if (obj.setPrototypeOf) {\n obj.setPrototypeOf(subClass, superClass)\n } else if (classProps.strictEs6Class) {\n subClass.__proto__ = superClass // eslint-disable-line\n } else {\n utils.forOwn(superClass, function (value, key) {\n subClass[key] = value\n })\n }\n if (!subClass.hasOwnProperty('__super__')) {\n Object.defineProperty(subClass, '__super__', {\n configurable: true,\n value: superClass\n })\n }\n\n utils.addHiddenPropsToTarget(subClass.prototype, props)\n utils.fillIn(subClass, classProps)\n\n return subClass\n },\n\n /**\n * Shallow copy own enumerable properties from `src` to `dest` that are on\n * `src` but are missing from `dest.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: 'bar', beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.fillIn(b, a)\n * console.log(b) // {\"foo\":\"bar\",\"beep\":\"bip\"}\n *\n * @method utils.fillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.deepFillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n fillIn (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Find the last index of an item in an array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = { name: 'John', age: 20 }\n * const sara = { name: 'Sara', age: 25 }\n * const dan = { name: 'Dan', age: 20 }\n * const users = [john, sara, dan]\n *\n * console.log(utils.findIndex(users, (user) => user.age === 25)) // 1\n * console.log(utils.findIndex(users, (user) => user.age > 19)) // 2\n * console.log(utils.findIndex(users, (user) => user.name === 'John')) // 0\n * console.log(utils.findIndex(users, (user) => user.name === 'Jimmy')) // -1\n *\n * @method utils.findIndex\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n * @returns {number} Index if found or -1 if not found.\n * @since 3.0.0\n */\n findIndex (array, fn) {\n let index = -1\n if (!array) {\n return index\n }\n array.forEach(function (record, i) {\n if (fn(record)) {\n index = i\n return false\n }\n })\n return index\n },\n\n /**\n * Recursively iterate over a {@link Mapper}'s relations according to\n * `opts.with`.\n *\n * @method utils.forEachRelation\n * @param {Mapper} mapper Mapper.\n * @param {Object} opts Configuration options.\n * @param {Function} fn Callback function.\n * @param {*} thisArg Execution context for the callback function.\n * @since 3.0.0\n */\n forEachRelation (mapper, opts, fn, thisArg) {\n const relationList = mapper.relationList || []\n if (!relationList.length) {\n return\n }\n relationList.forEach(function (def) {\n utils._forRelation(opts, def, fn, thisArg)\n })\n },\n\n /**\n * Iterate over an object's own enumerable properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { b: 1, c: 4 }\n * let sum = 0\n * utils.forOwn(a, function (value, key) {\n * sum += value\n * })\n * console.log(sum) // 5\n *\n * @method utils.forOwn\n * @param {Object} object The object whose properties are to be enumerated.\n * @param {Function} fn Iteration function.\n * @param {Object} [thisArg] Content to which to bind `fn`.\n * @since 3.0.0\n */\n forOwn (obj, fn, thisArg) {\n const keys = Object.keys(obj)\n const len = keys.length\n let i\n for (i = 0; i < len; i++) {\n fn.call(thisArg, obj[keys[i]], keys[i], obj)\n }\n },\n\n /**\n * Proxy for `JSON.parse`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = utils.fromJson('{\"name\" : \"John\"}')\n * console.log(a) // { name: 'John' }\n *\n * @method utils.fromJson\n * @param {string} json JSON to parse.\n * @returns {Object} Parsed object.\n * @see utils.toJson\n * @since 3.0.0\n */\n fromJson (json) {\n return utils.isString(json) ? JSON.parse(json) : json\n },\n\n /**\n * Retrieve the specified property from the given object. Supports retrieving\n * nested properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * console.log(utils.get(a, 'beep')) // \"boop\"\n * console.log(utils.get(a, 'foo.bar')) // \"baz\"\n *\n * @method utils.get\n * @param {Object} object Object from which to retrieve a property's value.\n * @param {string} prop Property to retrieve.\n * @returns {*} Value of the specified property.\n * @see utils.set\n * @since 3.0.0\n */\n 'get': function (object, prop) {\n if (!prop) {\n return\n }\n const parts = prop.split('.')\n const last = parts.pop()\n\n while (prop = parts.shift()) { // eslint-disable-line\n object = object[prop]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n return object[last]\n },\n\n /**\n * Return the superclass for the given instance or subclass. If an instance is\n * provided, then finds the parent class of the instance's constructor.\n *\n * @example\n * import {utils} from 'js-data'\n * // using ES2015 classes\n * class Foo {}\n * class Bar extends Foo {}\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * // using Function constructor with utils.extend\n * function Foo () {}\n * Foo.extend = utils.extend\n * const Bar = Foo.extend()\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * @method utils.getSuper\n * @param {Object|Function} instance Instance or constructor.\n * @param {boolean} [isCtor=false] Whether `instance` is a constructor.\n * @returns {Constructor} The superclass (grandparent constructor).\n * @since 3.0.0\n */\n getSuper (instance, isCtor) {\n const ctor = isCtor ? instance : instance.constructor\n if (ctor.hasOwnProperty('__super__')) {\n return ctor.__super__\n }\n return Object.getPrototypeOf(ctor) || ctor.__proto__ // eslint-disable-line\n },\n\n /**\n * Return the intersection of two arrays.\n *\n * @example\n * import {utils} from 'js-data'\n * const arrA = ['green', 'red', 'blue', 'red']\n * const arrB = ['green', 'yellow', 'red']\n * const intersected = utils.intersection(arrA, arrB)\n *\n * console.log(intersected) // ['green', 'red'])\n *\n * @method utils.intersection\n * @param {Array} array1 First array.\n * @param {Array} array2 Second array.\n * @returns {Array} Array of elements common to both arrays.\n * @since 3.0.0\n */\n intersection (array1, array2) {\n if (!array1 || !array2) {\n return []\n }\n const result = []\n let item\n let i\n const len = array1.length\n for (i = 0; i < len; i++) {\n item = array1[i]\n if (result.indexOf(item) !== -1) {\n continue\n }\n if (array2.indexOf(item) !== -1) {\n result.push(item)\n }\n }\n return result\n },\n\n /**\n * Proxy for `Array.isArray`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = [1,2,3,4,5]\n * const b = { foo: \"bar\" }\n * console.log(utils.isArray(a)) // true\n * console.log(utils.isArray(b)) // false\n *\n * @method utils.isArray\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an array.\n * @since 3.0.0\n */\n isArray: Array.isArray,\n\n /**\n * Return whether `prop` is matched by any string or regular expression in\n * `blacklist`.\n *\n * @example\n * import {utils} from 'js-data'\n * const blacklist = [/^\\$hashKey/g, /^_/g, 'id']\n * console.log(utils.isBlacklisted(\"$hashKey\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"id\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"_myProp\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"my_id\", blacklist)) // false\n *\n * @method utils.isBlacklisted\n * @param {string} prop The name of a property to check.\n * @param {Array} blacklist Array of strings and regular expressions.\n * @returns {boolean} Whether `prop` was matched.\n * @since 3.0.0\n */\n isBlacklisted (prop, blacklist) {\n if (!blacklist || !blacklist.length) {\n return false\n }\n let matches\n for (var i = 0; i < blacklist.length; i++) {\n if ((toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) || blacklist[i] === prop) {\n matches = prop\n return !!matches\n }\n }\n return !!matches\n },\n\n /**\n * Return whether the provided value is a boolean.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = true\n * const b = { foo: \"bar\" }\n * console.log(utils.isBoolean(a)) // true\n * console.log(utils.isBoolean(b)) // false\n *\n * @method utils.isBoolean\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a boolean.\n * @since 3.0.0\n */\n isBoolean (value) {\n return toStr(value) === BOOL_TAG\n },\n\n /**\n * Return whether the provided value is a date.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = new Date()\n * const b = { foo: \"bar\" }\n * console.log(utils.isDate(a)) // true\n * console.log(utils.isDate(b)) // false\n *\n * @method utils.isDate\n * @param {*} value The value to test.\n * @returns {Date} Whether the provided value is a date.\n * @since 3.0.0\n */\n isDate (value) {\n return (value && typeof value === 'object' && toStr(value) === DATE_TAG)\n },\n\n /**\n * Return whether the provided value is a function.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = function (){ console.log('foo bar')}\n * const b = { foo: \"bar\" }\n * console.log(utils.isFunction(a)) // true\n * console.log(utils.isFunction(b)) // false\n *\n * @method utils.isFunction\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a function.\n * @since 3.0.0\n */\n isFunction (value) {\n return typeof value === 'function' || (value && toStr(value) === FUNC_TAG)\n },\n\n /**\n * Return whether the provided value is an integer.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = 1.25\n * const c = '1'\n * console.log(utils.isInteger(a)) // true\n * console.log(utils.isInteger(b)) // false\n * console.log(utils.isInteger(c)) // false\n *\n * @method utils.isInteger\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an integer.\n * @since 3.0.0\n */\n isInteger (value) {\n return toStr(value) === NUMBER_TAG && value == toInteger(value) // eslint-disable-line\n },\n\n /**\n * Return whether the provided value is `null`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = null\n * const b = { foo: \"bar\" }\n * console.log(utils.isNull(a)) // true\n * console.log(utils.isNull(b)) // false\n *\n * @method utils.isNull\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is `null`.\n * @since 3.0.0\n */\n isNull (value) {\n return value === null\n },\n\n /**\n * Return whether the provided value is a number.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = -1.25\n * const c = '1'\n * console.log(utils.isNumber(a)) // true\n * console.log(utils.isNumber(b)) // true\n * console.log(utils.isNumber(c)) // false\n *\n * @method utils.isNumber\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a number.\n * @since 3.0.0\n */\n isNumber (value) {\n const type = typeof value\n return type === 'number' || (value && type === 'object' && toStr(value) === NUMBER_TAG)\n },\n\n /**\n * Return whether the provided value is an object.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\" }\n * const b = 'foo bar'\n * console.log(utils.isObject(a)) // true\n * console.log(utils.isObject(b)) // false\n *\n * @method utils.isObject\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an object.\n * @since 3.0.0\n */\n isObject (value) {\n return toStr(value) === OBJECT_TAG\n },\n\n /**\n * Return whether the provided value is a regular expression.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = /^\\$.+$/ig\n * const b = new RegExp('^\\$.+$', 'ig')\n * const c = { foo: \"bar\" }\n * console.log(utils.isRegExp(a)) // true\n * console.log(utils.isRegExp(b)) // true\n * console.log(utils.isRegExp(c)) // false\n *\n * @method utils.isRegExp\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a regular expression.\n * @since 3.0.0\n */\n isRegExp (value) {\n return toStr(value) === REGEXP_TAG\n },\n\n /**\n * Return whether the provided value is a string or a number.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isSorN('')) // true\n * console.log(utils.isSorN(-1.65)) // true\n * console.log(utils.isSorN('my string')) // true\n * console.log(utils.isSorN({})) // false\n * console.log(utils.isSorN([1,2,4])) // false\n *\n * @method utils.isSorN\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string or a number.\n * @since 3.0.0\n */\n isSorN (value) {\n return utils.isString(value) || utils.isNumber(value)\n },\n\n /**\n * Return whether the provided value is a string.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('')) // true\n * console.log(utils.isString('my string')) // true\n * console.log(utils.isString(100)) // false\n * console.log(utils.isString([1,2,4])) // false\n *\n * @method utils.isString\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string.\n * @since 3.0.0\n */\n isString (value) {\n return typeof value === 'string' || (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n },\n\n /**\n * Return whether the provided value is a `undefined`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = undefined\n * const b = { foo: \"bar\"}\n * console.log(utils.isUndefined(a)) // true\n * console.log(utils.isUndefined(b.baz)) // true\n * console.log(utils.isUndefined(b)) // false\n * console.log(utils.isUndefined(b.foo)) // false\n *\n * @method utils.isUndefined\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a `undefined`.\n * @since 3.0.0\n */\n isUndefined (value) {\n return value === undefined\n },\n\n /**\n * Mix in logging capabilities to the target.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\"}\n *\n * // Add standard logging to an object\n * utils.logify(a)\n * a.log('info', 'test log info') // output 'test log info' to console.\n *\n * // Toggle debug output of an object\n * a.dbg('test debug output') // does not output because debug is off.\n * a.debug = true\n * a.dbg('test debug output') // output 'test debug output' to console.\n *\n * @method utils.logify\n * @param {*} target The target.\n * @since 3.0.0\n */\n logify (target) {\n utils.addHiddenPropsToTarget(target, {\n dbg (...args) {\n if (utils.isFunction(this.log)) {\n this.log('debug', ...args)\n }\n },\n log (level, ...args) {\n if (level && !args.length) {\n args.push(level)\n level = 'debug'\n }\n if (level === 'debug' && !this.debug) {\n return\n }\n const prefix = `${level.toUpperCase()}: (${this.name || this.constructor.name})`\n if (utils.isFunction(console[level])) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n }\n })\n },\n\n /**\n * Adds the given record to the provided array only if it's not already in the\n * array.\n *\n * @example\n * import {utils} from 'js-data'\n * const colors = ['red', 'green', 'yellow']\n *\n * console.log(colors.length) // 3\n * utils.noDupeAdd(colors, 'red')\n * console.log(colors.length) // 3, red already exists\n *\n * utils.noDupeAdd(colors, 'blue')\n * console.log(colors.length) // 4, blue was added\n *\n * @method utils.noDupeAdd\n * @param {Array} array The array.\n * @param {*} record The value to add.\n * @param {Function} fn Callback function passed to {@link utils.findIndex}.\n * @since 3.0.0\n */\n noDupeAdd (array, record, fn) {\n if (!array) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index < 0) {\n array.push(record)\n }\n },\n\n /**\n * Return a shallow copy of the provided object, minus the properties\n * specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.omit(a, ['$hashKey'])\n * console.log(b) // { name: 'John' }\n *\n * @method utils.omit\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to skip.\n * @returns {Object} Shallow copy of `props`, minus `keys`.\n * @since 3.0.0\n */\n omit (props, keys) {\n const _props = {}\n utils.forOwn(props, function (value, key) {\n if (keys.indexOf(key) === -1) {\n _props[key] = value\n }\n })\n return _props\n },\n\n /**\n * Return a shallow copy of the provided object, but only include the\n * properties specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.pick(a, ['$hashKey'])\n * console.log(b) // { $hashKey: 1214910 }\n *\n * @method utils.pick\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to keep.\n * @returns {Object} Shallow copy of `props`, but only including `keys`.\n * @since 3.0.0\n */\n pick (props, keys) {\n const _props = {}\n utils.forOwn(props, function (value, key) {\n if (keys.indexOf(key) !== -1) {\n _props[key] = value\n }\n })\n return _props\n },\n\n /**\n * Return a plain copy of the given value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John' }\n * let b = utils.plainCopy(a)\n * console.log(a === b) // false\n *\n * @method utils.plainCopy\n * @param {*} value The value to copy.\n * @returns {*} Plain copy of `value`.\n * @see utils.copy\n * @since 3.0.0\n */\n plainCopy (value) {\n return utils.copy(value, undefined, undefined, undefined, undefined, true)\n },\n\n /**\n * Shortcut for `utils.Promise.reject(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.reject(\"Testing static reject\").then(function(data) {\n * // not called\n * }).catch(function(reason) {\n * console.log(reason); // \"Testing static reject\"\n * })\n *\n * @method utils.reject\n * @param {*} [value] Value with which to reject the Promise.\n * @returns {Promise} Promise reject with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n reject (value) {\n return utils.Promise.reject(value)\n },\n\n /**\n * Remove the last item found in array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const colors = ['red', 'green', 'yellow', 'red']\n * utils.remove(colors, (color) => color === 'red')\n * console.log(colors) // ['red', 'green', 'yellow']\n *\n * @method utils.remove\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n */\n remove (array, fn) {\n if (!array || !array.length) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index >= 0) {\n array.splice(index, 1) // todo should this be recursive?\n }\n },\n\n /**\n * Shortcut for `utils.Promise.resolve(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.resolve(\"Testing static resolve\").then(function(data) {\n * console.log(data); // \"Testing static resolve\"\n * }).catch(function(reason) {\n * // not called\n * })\n *\n * @param {*} [value] Value with which to resolve the Promise.\n * @returns {Promise} Promise resolved with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n resolve (value) {\n return utils.Promise.resolve(value)\n },\n\n /**\n * Set the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n * // set value by key\n * utils.set(john, 'id', 98)\n * console.log(john.id) // 98\n *\n * // set value by path\n * utils.set(john, 'parent.id', 20)\n * console.log(john.parent.id) // 20\n *\n * // set value by path/value map\n * utils.set(john, {\n * 'id': 1098,\n * 'parent': { id: 1020 },\n * 'parent.age': '55'\n * })\n * console.log(john.id) // 1098\n * console.log(john.parent.id) // 1020\n * console.log(john.parent.age) // 55\n *\n * @method utils.set\n * @param {Object} object The object on which to set a property.\n * @param {(string|Object)} path The key or path to the property. Can also\n * pass in an object of path/value pairs, which will all be set on the target\n * object.\n * @param {*} [value] The value to set.\n */\n set: function (object, path, value) {\n if (utils.isObject(path)) {\n utils.forOwn(path, function (value, _path) {\n utils.set(object, _path, value)\n })\n } else {\n const parts = PATH.exec(path)\n if (parts) {\n mkdirP(object, parts[1])[parts[2]] = value\n } else {\n object[path] = value\n }\n }\n },\n\n /**\n * Check whether the two provided objects are deeply equal.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const objA = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * const objB = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * console.log(utils.deepEqual(a,b)) // true\n * objB.nested.colors.add('yellow') // make a change to a nested object's array\n * console.log(utils.deepEqual(a,b)) // false\n *\n * @method utils.deepEqual\n * @param {Object} a First object in the comparison.\n * @param {Object} b Second object in the comparison.\n * @returns {boolean} Whether the two provided objects are deeply equal.\n * @see utils.equal\n * @since 3.0.0\n */\n deepEqual (a, b) {\n if (a === b) {\n return true\n }\n let _equal = true\n if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n _equal = _equal && utils.deepEqual(value, b[key])\n })\n if (!_equal) {\n return _equal\n }\n utils.forOwn(b, function (value, key) {\n _equal = _equal && utils.deepEqual(value, a[key])\n })\n } else if (utils.isArray(a) && utils.isArray(b)) {\n a.forEach(function (value, i) {\n _equal = _equal && utils.deepEqual(value, b[i])\n if (!_equal) {\n return false\n }\n })\n } else {\n return false\n }\n return _equal\n },\n\n /**\n * Proxy for `JSON.stringify`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = { name: 'John' }\n * let jsonVal = utils.toJson(a)\n * console.log(jsonVal) // '{\"name\" : \"John\"}'\n *\n * @method utils.toJson\n * @param {*} value Value to serialize to JSON.\n * @returns {string} JSON string.\n * @see utils.fromJson\n * @since 3.0.0\n */\n toJson: JSON.stringify,\n\n /**\n * Unset the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n *\n * utils.unset(john, age)\n * utils.unset(john, parent.age)\n *\n * console.log(john.age) // null\n * console.log(john.parent.age) // null\n *\n * @method utils.unset\n * @param {Object} object The object from which to delete the property.\n * @param {string} path The key or path to the property.\n * @see utils.set\n * @since 3.0.0\n */\n unset (object, path) {\n const parts = path.split('.')\n const last = parts.pop()\n\n while (path = parts.shift()) { // eslint-disable-line\n object = object[path]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n object[last] = undefined\n },\n\n}\n\nexport const safeSetProp = function (record, field, value) {\n if (record && record._set) {\n record._set(`props.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport const safeSetLink = function (record, field, value) {\n if (record && record._set) {\n record._set(`links.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport default utils\n","import utils from './utils'\n\n/**\n * A base class which gives instances private properties.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Settable.extend} for an example of using {@link Settable} as a\n * base class.\n *\n *```javascript\n * import {Settable} from 'js-data'\n * ```\n *\n * @class Settable\n * @returns {Settable} A new {@link Settable} instance.\n * @since 3.0.0\n */\nexport default function Settable () {\n const _props = {}\n Object.defineProperties(this, {\n /**\n * Get a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method Settable#_get\n * @param {string} key The property to retrieve.\n * @returns {*} The value of the property.\n * @since 3.0.0\n */\n _get: { value (key) { return utils.get(_props, key) } },\n\n /**\n * Set a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_set\n * @param {(string|Object)} key The key or path to the property. Can also\n * pass in an object of key/value pairs, which will all be set on the instance.\n * @param {*} [value] The value to set.\n * @since 3.0.0\n */\n _set: { value (key, value) { return utils.set(_props, key, value) } },\n\n /**\n * Unset a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_unset\n * @param {string} key The property to unset.\n * @since 3.0.0\n */\n _unset: { value (key) { return utils.unset(_props, key) } }\n })\n}\n\n/**\n * Create a subclass of this Settable:\n *\n * @example Settable.extend\n * // Normally you would do: import {Settable} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Settable} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSettableClass extends Settable {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSettable = new CustomSettableClass()\n * console.log(customSettable.foo())\n * console.log(CustomSettableClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSettableClass = Settable.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSettable = new OtherSettableClass()\n * console.log(otherSettable.foo())\n * console.log(OtherSettableClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSettableClass () {\n * Settable.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Settable.extend({\n * constructor: AnotherSettableClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSettable = new AnotherSettableClass()\n * console.log(anotherSettable.created_at)\n * console.log(anotherSettable.foo())\n * console.log(AnotherSettableClass.beep())\n *\n * @method Settable.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Settable class.\n * @since 3.0.0\n */\nSettable.extend = utils.extend\n","import utils from './utils'\nimport Settable from './Settable'\n\n/**\n * The base class from which all JSData components inherit some basic\n * functionality.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Component.extend} for an example of using {@link Component} as a\n * base class.\n *\n *```javascript\n * import {Component} from 'js-data'\n * ```\n *\n * @class Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @returns {Component} A new {@link Component} instance.\n * @since 3.0.0\n */\nfunction Component (opts) {\n Settable.call(this)\n opts || (opts = {})\n\n /**\n * Whether to enable debug-level logs for this component. Anything that\n * extends `Component` inherits this option and the corresponding logging\n * functionality.\n *\n * @example Component#debug\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const component = new Component()\n * component.log('debug', 'some message') // nothing gets logged\n * // Display debug logs:\n * component.debug = true\n * component.log('debug', 'other message') // this DOES get logged\n *\n * @default false\n * @name Component#debug\n * @since 3.0.0\n * @type {boolean}\n */\n this.debug = opts.hasOwnProperty('debug') ? !!opts.debug : false\n\n /**\n * Event listeners attached to this Component. __Do not modify.__ Use\n * {@link Component#on} and {@link Component#off} instead.\n *\n * @name Component#_listeners\n * @instance\n * @since 3.0.0\n * @type {Object}\n */\n Object.defineProperty(this, '_listeners', { value: {}, writable: true })\n}\n\nexport default Settable.extend({\n constructor: Component\n})\n\n/**\n * Create a subclass of this Component:\n *\n * @example Component.extend\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomComponentClass extends Component {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customComponent = new CustomComponentClass()\n * console.log(customComponent.foo())\n * console.log(CustomComponentClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherComponentClass = Component.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherComponent = new OtherComponentClass()\n * console.log(otherComponent.foo())\n * console.log(OtherComponentClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherComponentClass () {\n * Component.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Component.extend({\n * constructor: AnotherComponentClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherComponent = new AnotherComponentClass()\n * console.log(anotherComponent.created_at)\n * console.log(anotherComponent.foo())\n * console.log(AnotherComponentClass.beep())\n *\n * @method Component.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Component class.\n * @since 3.0.0\n */\nComponent.extend = utils.extend\n\n/**\n * Log the provided values at the \"debug\" level. Debug-level logs are only\n * logged if {@link Component#debug} is `true`.\n *\n * `.dbg(...)` is shorthand for `.log('debug', ...)`.\n *\n * @method Component#dbg\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\n/**\n * Log the provided values. By default sends values to `console[level]`.\n * Debug-level logs are only logged if {@link Component#debug} is `true`.\n *\n * Will attempt to use appropriate `console` methods if they are available.\n *\n * @method Component#log\n * @param {string} level Log level.\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\nutils.logify(Component.prototype)\n\n/**\n * Register a new event listener on this Component.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a DataStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * collection.on('add', (records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * post.on('change', (record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method Component#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n/**\n * Remove an event listener from this Component. If no listener is provided,\n * then all listeners for the specified event will be removed. If no event is\n * specified then all listeners for all events will be removed.\n *\n * @example\n * // Remove a particular listener for a particular event\n * collection.off('add', handler)\n *\n * @example\n * // Remove all listeners for a particular event\n * record.off('change')\n *\n * @example\n * // Remove all listeners to all events\n * store.off()\n *\n * @method Component#off\n * @param {string} [event] Name of event to unsubsribe to.\n * @param {Function} [listener] Listener to remove.\n * @since 3.0.0\n */\n/**\n * Trigger an event on this Component.\n *\n * @example Component#emit\n * // import {Collection, DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, DataStore} = JSData\n *\n * const collection = new Collection()\n * collection.on('foo', function (msg) {\n * console.log(msg)\n * })\n * collection.emit('foo', 'bar')\n *\n * const store = new DataStore()\n * store.on('beep', function (msg) {\n * console.log(msg)\n * })\n * store.emit('beep', 'boop')\n *\n * @method Component#emit\n * @param {string} event Name of event to emit.\n * @param {...*} [args] Arguments to pass to any listeners.\n * @since 3.0.0\n */\nutils.eventify(\n Component.prototype,\n function () {\n return this._listeners\n },\n function (value) {\n this._listeners = value\n }\n)\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Query'\nconst INDEX_ERR = 'Index inaccessible after first operation'\n\n// Reserved words used by JSData's Query Syntax\nconst reserved = {\n limit: '',\n offset: '',\n orderBy: '',\n skip: '',\n sort: '',\n where: ''\n}\n\n// Used by our JavaScript implementation of the LIKE operator\nconst escapeRegExp = /([.*+?^=!:${}()|[\\]\\/\\\\])/g\nconst percentRegExp = /%/g\nconst underscoreRegExp = /_/g\nconst escape = function (pattern) {\n return pattern.replace(escapeRegExp, '\\\\$1')\n}\n\n/**\n * A class used by the {@link Collection} class to build queries to be executed\n * against the collection's data. An instance of `Query` is returned by\n * {@link Collection#query}. Query instances are typically short-lived, and you\n * shouldn't have to create them yourself. Just use {@link Collection#query}.\n *\n * ```javascript\n * import {Query} from 'js-data'\n * ```\n *\n * @example\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const drafts = store.query('post').filter({ status: 'draft' }).limit(2).run()\n * console.log(drafts)\n *\n * @class Query\n * @extends Component\n * @param {Collection} collection The collection on which this query operates.\n * @since 3.0.0\n */\nfunction Query (collection) {\n utils.classCallCheck(this, Query)\n\n /**\n * The {@link Collection} on which this query operates.\n *\n * @name Query#collection\n * @since 3.0.0\n * @type {Collection}\n */\n this.collection = collection\n\n /**\n * The current data result of this query.\n *\n * @name Query#data\n * @since 3.0.0\n * @type {Array}\n */\n this.data = null\n}\n\nexport default Component.extend({\n constructor: Query,\n\n _applyWhereFromObject (where) {\n const fields = []\n const ops = []\n const predicates = []\n utils.forOwn(where, (clause, field) => {\n if (!utils.isObject(clause)) {\n clause = {\n '==': clause\n }\n }\n utils.forOwn(clause, (expr, op) => {\n fields.push(field)\n ops.push(op)\n predicates.push(expr)\n })\n })\n return {\n fields,\n ops,\n predicates\n }\n },\n\n _applyWhereFromArray (where) {\n const groups = []\n where.forEach((_where, i) => {\n if (utils.isString(_where)) {\n return\n }\n const prev = where[i - 1]\n const parser = utils.isArray(_where) ? this._applyWhereFromArray : this._applyWhereFromObject\n const group = parser.call(this, _where)\n if (prev === 'or') {\n group.isOr = true\n }\n groups.push(group)\n })\n groups.isArray = true\n return groups\n },\n\n _testObjectGroup (keep, first, group, item) {\n let i\n const fields = group.fields\n const ops = group.ops\n const predicates = group.predicates\n const len = ops.length\n for (i = 0; i < len; i++) {\n let op = ops[i]\n const isOr = op.charAt(0) === '|'\n op = isOr ? op.substr(1) : op\n const expr = this.evaluate(utils.get(item, fields[i]), op, predicates[i])\n if (expr !== undefined) {\n keep = first ? expr : (isOr ? keep || expr : keep && expr)\n }\n first = false\n }\n return { keep, first }\n },\n\n _testArrayGroup (keep, first, groups, item) {\n let i\n const len = groups.length\n for (i = 0; i < len; i++) {\n const group = groups[i]\n const parser = group.isArray ? this._testArrayGroup : this._testObjectGroup\n const result = parser.call(this, true, true, group, item)\n if (groups[i - 1]) {\n if (group.isOr) {\n keep = keep || result.keep\n } else {\n keep = keep && result.keep\n }\n } else {\n keep = result.keep\n }\n first = result.first\n }\n return { keep, first }\n },\n\n /**\n * Find all entities between two boundaries.\n *\n * @example Get the users ages 18 to 30.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between(18, 30, { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @example Same as above.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between([18], [30], { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @method Query#between\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#between`)(500, 'Cannot access index')\n }\n this.data = this.collection.getIndex(opts.index).between(leftKeys, rightKeys, opts)\n return this\n },\n\n /**\n * The comparison function used by the {@link Query} class.\n *\n * @method Query#compare\n * @param {Array} orderBy An orderBy clause used for sorting and sub-sorting.\n * @param {number} index The index of the current orderBy clause being used.\n * @param {*} a The first item in the comparison.\n * @param {*} b The second item in the comparison.\n * @returns {number} -1 if `b` should preceed `a`. 0 if `a` and `b` are equal.\n * 1 if `a` should preceed `b`.\n * @since 3.0.0\n */\n compare (orderBy, index, a, b) {\n const def = orderBy[index]\n let cA = utils.get(a, def[0])\n let cB = utils.get(b, def[0])\n if (cA && utils.isString(cA)) {\n cA = cA.toUpperCase()\n }\n if (cB && utils.isString(cB)) {\n cB = cB.toUpperCase()\n }\n if (a === undefined) {\n a = null\n }\n if (b === undefined) {\n b = null\n }\n if (def[1].toUpperCase() === 'DESC') {\n const temp = cB\n cB = cA\n cA = temp\n }\n if (cA < cB) {\n return -1\n } else if (cA > cB) {\n return 1\n } else {\n if (index < orderBy.length - 1) {\n return this.compare(orderBy, index + 1, a, b)\n } else {\n return 0\n }\n }\n },\n\n /**\n * Predicate evaluation function used by the {@link Query} class.\n *\n * @method Query#evaluate\n * @param {*} value The value to evaluate.\n * @param {string} op The operator to use in this evaluation.\n * @param {*} predicate The predicate to use in this evaluation.\n * @returns {boolean} Whether the value passed the evaluation or not.\n * @since 3.0.0\n */\n evaluate (value, op, predicate) {\n const ops = this.constructor.ops\n if (ops[op]) {\n return ops[op](value, predicate)\n }\n if (op.indexOf('like') === 0) {\n return this.like(predicate, op.substr(4)).exec(value) !== null\n } else if (op.indexOf('notLike') === 0) {\n return this.like(predicate, op.substr(7)).exec(value) === null\n }\n },\n\n /**\n * Find the record or records that match the provided query or are accepted by\n * the provided filter function.\n *\n * @example Get the draft posts by authors younger than 30\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * let results = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * }).run()\n * console.log(results)\n *\n * @example Use a custom filter function\n * const posts = query.filter(function (post) {\n * return post.isReady()\n * }).run()\n *\n * @method Query#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Function} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n filter (query, thisArg) {\n /**\n * Selection query as defined by JSData's [Query Syntax][querysyntax].\n *\n * [querysyntax]: http://www.js-data.io/v3.0/docs/query-syntax\n *\n * @example Empty \"findAll\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @example Empty \"filter\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = store.filter('post')\n * console.log(posts) // [...]\n *\n * @example Complex \"filter\" query\n * const PAGE_SIZE = 2\n * let currentPage = 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * // Retrieve a filtered page of blog posts\n * // Would typically replace filter with findAll\n * store.filter('post', {\n * where: {\n * status: {\n * // WHERE status = 'published'\n * '==': 'published'\n * },\n * author: {\n * // AND author IN ('bob', 'alice')\n * 'in': ['bob', 'alice'],\n * // OR author IN ('karen')\n * '|in': ['karen']\n * }\n * },\n * orderBy: [\n * // ORDER BY date_published DESC,\n * ['date_published', 'DESC'],\n * // ORDER BY title ASC\n * ['title', 'ASC']\n * ],\n * // LIMIT 2\n * limit: PAGE_SIZE,\n * // SKIP 4\n * offset: PAGE_SIZE * (currentPage - 1)\n * })\n *\n * @namespace query\n * @property {number} [limit] See {@link query.limit}.\n * @property {number} [offset] See {@link query.offset}.\n * @property {string|Array[]} [orderBy] See {@link query.orderBy}.\n * @property {number} [skip] Alias for {@link query.offset}.\n * @property {string|Array[]} [sort] Alias for {@link query.orderBy}.\n * @property {Object} [where] See {@link query.where}.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/query-syntax\",\"JSData's Query Syntax\"]\n */\n query || (query = {})\n this.getData()\n if (utils.isObject(query)) {\n let where = {}\n\n /**\n * Filtering criteria. Records that do not meet this criteria will be exluded\n * from the result.\n *\n * @example Return posts where author is at least 32 years old\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * where: {\n * age: {\n * '>=': 30\n * }\n * }\n * })\n * console.log(results)\n *\n * @name query.where\n * @type {Object}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isObject(query.where) || utils.isArray(query.where)) {\n where = query.where\n }\n utils.forOwn(query, function (value, key) {\n if (!(key in reserved) && !(key in where)) {\n where[key] = {\n '==': value\n }\n }\n })\n let groups\n\n // Apply filter for each field\n if (utils.isObject(where) && Object.keys(where).length !== 0) {\n groups = this._applyWhereFromArray([where])\n } else if (utils.isArray(where)) {\n groups = this._applyWhereFromArray(where)\n }\n\n if (groups) {\n this.data = this.data.filter((item, i) => this._testArrayGroup(true, true, groups, item).keep)\n }\n\n // Sort\n let orderBy = query.orderBy || query.sort\n\n if (utils.isString(orderBy)) {\n orderBy = [\n [orderBy, 'ASC']\n ]\n }\n if (!utils.isArray(orderBy)) {\n orderBy = null\n }\n\n /**\n * Determines how records should be ordered in the result.\n *\n * @example Order posts by `author` then by `id` descending \n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * orderBy:[['author','ASC'],['id','DESC']]\n * })\n * console.log(results)\n *\n * @name query.orderBy\n * @type {string|Array[]}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (orderBy) {\n let index = 0\n orderBy.forEach(function (def, i) {\n if (utils.isString(def)) {\n orderBy[i] = [def, 'ASC']\n }\n })\n this.data.sort((a, b) => this.compare(orderBy, index, a, b))\n }\n\n /**\n * Number of records to skip.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n *\n * @name query.offset\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.skip)) {\n this.skip(query.skip)\n } else if (utils.isNumber(query.offset)) {\n this.skip(query.offset)\n }\n\n /**\n * Maximum number of records to retrieve.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n * @name query.limit\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.limit)) {\n this.limit(query.limit)\n }\n } else if (utils.isFunction(query)) {\n this.data = this.data.filter(query, thisArg)\n }\n return this\n },\n\n /**\n * Iterate over all entities.\n *\n * @method Query#forEach\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n forEach (forEachFn, thisArg) {\n this.getData().forEach(forEachFn, thisArg)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided key.\n *\n * @example Get the entity whose primary key is 25.\n * const entities = query.get(25).run()\n *\n * @example Same as above.\n * const entities = query.get([25]).run()\n *\n * @example Get all users who are active and have the \"admin\" role.\n * const activeAdmins = query.get(['active', 'admin'], {\n * index: 'activityAndRoles'\n * }).run()\n *\n * @example Get all entities that match a certain weather condition.\n * const niceDays = query.get(['sunny', 'humid', 'calm'], {\n * index: 'weatherConditions'\n * }).run()\n *\n * @method Query#get\n * @param {Array} keyList Key(s) defining the entity to retrieve. If\n * `keyList` is not an array (i.e. for a single-value key), it will be\n * wrapped in an array.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.string] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n get (keyList, opts) {\n keyList || (keyList = [])\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#get`)(500, INDEX_ERR)\n }\n if (keyList && !utils.isArray(keyList)) {\n keyList = [keyList]\n }\n if (!keyList.length) {\n this.getData()\n return this\n }\n this.data = this.collection.getIndex(opts.index).get(keyList)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided keyLists.\n *\n * @example Get the posts where \"status\" is \"draft\" or \"inReview\".\n * const posts = query.getAll('draft', 'inReview', { index: 'status' }).run()\n *\n * @example Same as above.\n * const posts = query.getAll(['draft'], ['inReview'], { index: 'status' }).run()\n *\n * @method Query#getAll\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * entities matching each keyList will be retrieved. If no keyLists are\n * provided, all entities will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n getAll (...args) {\n let opts = {}\n if (this.data) {\n throw utils.err(`${DOMAIN}#getAll`)(500, INDEX_ERR)\n }\n if (!args.length || args.length === 1 && utils.isObject(args[0])) {\n this.getData()\n return this\n } else if (args.length && utils.isObject(args[args.length - 1])) {\n opts = args[args.length - 1]\n args.pop()\n }\n const collection = this.collection\n const index = collection.getIndex(opts.index)\n this.data = []\n args.forEach((keyList) => {\n this.data = this.data.concat(index.get(keyList))\n })\n return this\n },\n\n /**\n * Return the current data result of this query.\n *\n * @method Query#getData\n * @returns {Array} The data in this query.\n * @since 3.0.0\n */\n getData () {\n if (!this.data) {\n this.data = this.collection.index.getAll()\n }\n return this.data\n },\n\n /**\n * Implementation used by the `like` operator. Takes a pattern and flags and\n * returns a `RegExp` instance that can test strings.\n *\n * @method Query#like\n * @param {string} pattern Testing pattern.\n * @param {string} flags Flags for the regular expression.\n * @returns {RegExp} Regular expression for testing strings.\n * @since 3.0.0\n */\n like (pattern, flags) {\n return new RegExp(`^${(escape(pattern).replace(percentRegExp, '.*').replace(underscoreRegExp, '.'))}$`, flags)\n },\n\n /**\n * Limit the result.\n *\n * @example Get only the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').limit(2).run()\n * console.log(results)\n *\n * @method Query#limit\n * @param {number} num The maximum number of entities to keep in the result.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n limit (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#limit`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n this.data = data.slice(0, Math.min(data.length, num))\n return this\n },\n\n /**\n * Apply a mapping function to the result data.\n *\n * @example\n * // Return the age of all users\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const ages = store.query('user').map((user) => {\n * return user.age\n * }).run()\n * console.log(ages)\n *\n * @method Query#map\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n map (mapFn, thisArg) {\n this.data = this.getData().map(mapFn, thisArg)\n return this\n },\n\n /**\n * Return the result of calling the specified function on each item in this\n * collection's main index.\n *\n * @example\n * const stringAges = UserCollection.query().mapCall('toString').run()\n *\n * @method Query#mapCall\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n mapCall (funcName, ...args) {\n this.data = this.getData().map(function (item) {\n return item[funcName](...args)\n })\n return this\n },\n\n /**\n * Complete the execution of the query and return the resulting data.\n *\n * @method Query#run\n * @returns {Array} The result of executing this query.\n * @since 3.0.0\n */\n run () {\n const data = this.data\n this.data = null\n return data\n },\n\n /**\n * Skip a number of results.\n *\n * @example Get all but the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').skip(2).run()\n * console.log(results)\n *\n * @method Query#skip\n * @param {number} num The number of entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n skip (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#skip`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n if (num < data.length) {\n this.data = data.slice(num)\n } else {\n this.data = []\n }\n return this\n }\n}, {\n /**\n * The filtering operators supported by {@link Query#filter}, and which are\n * implemented by adapters (for the most part).\n *\n * @example Variant 1\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n *\n * @example Variant 2\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n * @example Variant 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * status: 'published'\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Variant 4\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Multiple operators\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const myPublishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * },\n * user_id: {\n * '==': currentUser.id\n * }\n * }\n * })\n *\n * console.log(myPublishedPosts)\n *\n * @name Query.ops\n * @property {Function} == Equality operator.\n * @property {Function} != Inequality operator.\n * @property {Function} > Greater than operator.\n * @property {Function} >= Greater than (inclusive) operator.\n * @property {Function} < Less than operator.\n * @property {Function} <= Less than (inclusive) operator.\n * @property {Function} isectEmpty Operator that asserts that the intersection\n * between two arrays is empty.\n * @property {Function} isectNotEmpty Operator that asserts that the\n * intersection between two arrays is __not__ empty.\n * @property {Function} in Operator that asserts whether a value is in an\n * array.\n * @property {Function} notIn Operator that asserts whether a value is __not__\n * in an array.\n * @property {Function} contains Operator that asserts whether an array\n * contains a value.\n * @property {Function} notContains Operator that asserts whether an array\n * does __not__ contain a value.\n * @since 3.0.0\n * @type {Object}\n */\n ops: {\n '=': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '==': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '===': function (value, predicate) {\n return value === predicate\n },\n '!=': function (value, predicate) {\n return value != predicate // eslint-disable-line\n },\n '!==': function (value, predicate) {\n return value !== predicate\n },\n '>': function (value, predicate) {\n return value > predicate\n },\n '>=': function (value, predicate) {\n return value >= predicate\n },\n '<': function (value, predicate) {\n return value < predicate\n },\n '<=': function (value, predicate) {\n return value <= predicate\n },\n 'isectEmpty': function (value, predicate) {\n return !utils.intersection((value || []), (predicate || [])).length\n },\n 'isectNotEmpty': function (value, predicate) {\n return utils.intersection((value || []), (predicate || [])).length\n },\n 'in': function (value, predicate) {\n return predicate.indexOf(value) !== -1\n },\n 'notIn': function (value, predicate) {\n return predicate.indexOf(value) === -1\n },\n 'contains': function (value, predicate) {\n return (value || []).indexOf(predicate) !== -1\n },\n 'notContains': function (value, predicate) {\n return (value || []).indexOf(predicate) === -1\n }\n }\n})\n\n/**\n * Create a subclass of this Query:\n * @example Query.extend\n * // Normally you would do: import {Query} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Query} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomQueryClass extends Query {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customQuery = new CustomQueryClass()\n * console.log(customQuery.foo())\n * console.log(CustomQueryClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherQueryClass = Query.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherQuery = new OtherQueryClass()\n * console.log(otherQuery.foo())\n * console.log(OtherQueryClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherQueryClass (collection) {\n * Query.call(this, collection)\n * this.created_at = new Date().getTime()\n * }\n * Query.extend({\n * constructor: AnotherQueryClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherQuery = new AnotherQueryClass()\n * console.log(anotherQuery.created_at)\n * console.log(anotherQuery.foo())\n * console.log(AnotherQueryClass.beep())\n *\n * @method Query.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Query class.\n * @since 3.0.0\n */\n","export function sort (a, b, hashCode) {\n // Short-circuit comparison if a and b are strictly equal\n // This is absolutely necessary for indexed objects that\n // don't have the idAttribute field\n if (a === b) {\n return 0\n }\n if (hashCode) {\n a = hashCode(a)\n b = hashCode(b)\n }\n if ((a === null && b === null) || (a === undefined && b === undefined)) {\n return -1\n }\n\n if (a === null || a === undefined) {\n return -1\n }\n\n if (b === null || b === undefined) {\n return 1\n }\n\n if (a < b) {\n return -1\n }\n\n if (a > b) {\n return 1\n }\n\n return 0\n}\n\nexport function insertAt (array, index, value) {\n array.splice(index, 0, value)\n return array\n}\n\nexport function removeAt (array, index) {\n array.splice(index, 1)\n return array\n}\n\nexport function binarySearch (array, value, field) {\n let lo = 0\n let hi = array.length\n let compared\n let mid\n\n while (lo < hi) {\n mid = ((lo + hi) / 2) | 0\n compared = sort(value, array[mid], field)\n if (compared === 0) {\n return {\n found: true,\n index: mid\n }\n } else if (compared < 0) {\n hi = mid\n } else {\n lo = mid + 1\n }\n }\n\n return {\n found: false,\n index: hi\n }\n}\n","// Copyright (c) 2015, InternalFX.\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose with or\n// without fee is hereby granted, provided that the above copyright notice and this permission\n// notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO\n// THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT\n// SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR\n// ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE\n// USE OR PERFORMANCE OF THIS SOFTWARE.\n\n// Modifications\n// Copyright 2015-2016 Jason Dobry\n//\n// Summary of modifications:\n// Reworked dependencies so as to re-use code already in js-data\n// Removed unused code\nimport utils from '../../src/utils'\nimport {binarySearch, insertAt, removeAt} from './_utils'\n\nexport default function Index (fieldList, opts) {\n utils.classCallCheck(this, Index)\n fieldList || (fieldList = [])\n\n if (!utils.isArray(fieldList)) {\n throw new Error('fieldList must be an array.')\n }\n\n opts || (opts = {})\n this.fieldList = fieldList\n this.fieldGetter = opts.fieldGetter\n this.hashCode = opts.hashCode\n this.isIndex = true\n this.keys = []\n this.values = []\n}\n\nutils.addHiddenPropsToTarget(Index.prototype, {\n 'set' (keyList, value) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n let dataLocation = binarySearch(this.values[pos.index], value, this.hashCode)\n if (!dataLocation.found) {\n insertAt(this.values[pos.index], dataLocation.index, value)\n }\n } else {\n insertAt(this.keys, pos.index, key)\n insertAt(this.values, pos.index, [value])\n }\n } else {\n if (pos.found) {\n this.values[pos.index].set(keyList, value)\n } else {\n insertAt(this.keys, pos.index, key)\n let newIndex = new Index([], { hashCode: this.hashCode })\n newIndex.set(keyList, value)\n insertAt(this.values, pos.index, newIndex)\n }\n }\n },\n\n 'get' (keyList) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n if (this.values[pos.index].isIndex) {\n return this.values[pos.index].getAll()\n } else {\n return this.values[pos.index].slice()\n }\n } else {\n return []\n }\n } else {\n if (pos.found) {\n return this.values[pos.index].get(keyList)\n } else {\n return []\n }\n }\n },\n\n getAll (opts) {\n opts || (opts = {})\n let results = []\n const values = this.values\n if (opts.order === 'desc') {\n for (let i = values.length - 1; i >= 0; i--) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n } else {\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n }\n return results\n },\n\n visitAll (cb, thisArg) {\n this.values.forEach(function (value) {\n if (value.isIndex) {\n value.visitAll(cb, thisArg)\n } else {\n value.forEach(cb, thisArg)\n }\n })\n },\n\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (!utils.isArray(leftKeys)) {\n leftKeys = [leftKeys]\n }\n if (!utils.isArray(rightKeys)) {\n rightKeys = [rightKeys]\n }\n utils.fillIn(opts, {\n leftInclusive: true,\n rightInclusive: false,\n limit: undefined,\n offset: 0\n })\n\n let results = this._between(leftKeys, rightKeys, opts)\n\n if (opts.limit) {\n return results.slice(opts.offset, opts.limit + opts.offset)\n } else {\n return results.slice(opts.offset)\n }\n },\n\n _between (leftKeys, rightKeys, opts) {\n let results = []\n\n let leftKey = leftKeys.shift()\n let rightKey = rightKeys.shift()\n\n let pos\n\n if (leftKey !== undefined) {\n pos = binarySearch(this.keys, leftKey)\n } else {\n pos = {\n found: false,\n index: 0\n }\n }\n\n if (leftKeys.length === 0) {\n if (pos.found && opts.leftInclusive === false) {\n pos.index += 1\n }\n\n for (let i = pos.index; i < this.keys.length; i += 1) {\n if (rightKey !== undefined) {\n if (opts.rightInclusive) {\n if (this.keys[i] > rightKey) { break }\n } else {\n if (this.keys[i] >= rightKey) { break }\n }\n }\n\n if (this.values[i].isIndex) {\n results = results.concat(this.values[i].getAll())\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n } else {\n for (let i = pos.index; i < this.keys.length; i += 1) {\n let currKey = this.keys[i]\n if (currKey > rightKey) { break }\n\n if (this.values[i].isIndex) {\n if (currKey === leftKey) {\n results = results.concat(this.values[i]._between(utils.copy(leftKeys), rightKeys.map(function () { return undefined }), opts))\n } else if (currKey === rightKey) {\n results = results.concat(this.values[i]._between(leftKeys.map(function () { return undefined }), utils.copy(rightKeys), opts))\n } else {\n results = results.concat(this.values[i].getAll())\n }\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n }\n\n if (opts.limit) {\n return results.slice(0, opts.limit + opts.offset)\n } else {\n return results\n }\n },\n\n peek () {\n if (this.values.length) {\n if (this.values[0].isIndex) {\n return this.values[0].peek()\n } else {\n return this.values[0]\n }\n }\n return []\n },\n\n clear () {\n this.keys = []\n this.values = []\n },\n\n insertRecord (data) {\n let keyList = this.fieldList.map(function (field) {\n if (utils.isFunction(field)) {\n return field(data) || undefined\n } else {\n return data[field] || undefined\n }\n })\n this.set(keyList, data)\n },\n\n removeRecord (data) {\n let removed\n const isUnique = this.hashCode(data) !== undefined\n this.values.forEach((value, i) => {\n if (value.isIndex) {\n if (value.removeRecord(data)) {\n if (value.keys.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n } else {\n let dataLocation = {}\n if (this.keys[i] === undefined || !isUnique) {\n for (let j = value.length - 1; j >= 0; j--) {\n if (value[j] === data) {\n dataLocation = {\n found: true,\n index: j\n }\n break\n }\n }\n } else if (isUnique) {\n dataLocation = binarySearch(value, data, this.hashCode)\n }\n if (dataLocation.found) {\n removeAt(value, dataLocation.index)\n if (value.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n }\n })\n return removed ? data : undefined\n },\n\n updateRecord (data) {\n const removed = this.removeRecord(data)\n if (removed !== undefined) {\n this.insertRecord(data)\n }\n }\n})\n","import utils from './utils'\nimport Component from './Component'\nimport Query from './Query'\nimport Index from '../lib/mindex/index'\n\nconst DOMAIN = 'Collection'\n\nconst COLLECTION_DEFAULTS = {\n /**\n * Whether to call {@link Record#commit} on records that are added to the\n * collection and already exist in the collection.\n *\n * @name Collection#commitOnMerge\n * @type {boolean}\n * @default true\n */\n commitOnMerge: true,\n\n /**\n * Field to be used as the unique identifier for records in this collection.\n * Defaults to `\"id\"` unless {@link Collection#mapper} is set, in which case\n * this will default to {@link Mapper#idAttribute}.\n *\n * @name Collection#idAttribute\n * @type {string}\n * @default \"id\"\n */\n idAttribute: 'id',\n\n /**\n * What to do when inserting a record into this Collection that shares a\n * primary key with a record already in this Collection.\n *\n * Possible values:\n * merge\n * replace\n *\n * Merge:\n *\n * Recursively shallow copy properties from the new record onto the existing\n * record.\n *\n * Replace:\n *\n * Shallow copy top-level properties from the new record onto the existing\n * record. Any top-level own properties of the existing record that are _not_\n * on the new record will be removed.\n *\n * @name Collection#onConflict\n * @type {string}\n * @default \"merge\"\n */\n onConflict: 'merge'\n}\n\n/**\n * An ordered set of {@link Record} instances.\n *\n * @example Collection#constructor\n * // import {Collection, Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const user1 = new Record({ id: 1 })\n * const user2 = new Record({ id: 2 })\n * const UserCollection = new Collection([user1, user2])\n * console.log(UserCollection.get(1) === user1)\n *\n * @class Collection\n * @extends Component\n * @param {Array} [records] Initial set of records to insert into the\n * collection.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.commitOnMerge] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.idAttribute] See {@link Collection#idAttribute}.\n * @param {string} [opts.onConflict=\"merge\"] See {@link Collection#onConflict}.\n * @param {string} [opts.mapper] See {@link Collection#mapper}.\n * @since 3.0.0\n */\nfunction Collection (records, opts) {\n utils.classCallCheck(this, Collection)\n Component.call(this, opts)\n\n if (records && !utils.isArray(records)) {\n opts = records\n records = []\n }\n if (utils.isString(opts)) {\n opts = { idAttribute: opts }\n }\n\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * Default Mapper for this collection. Optional. If a Mapper is provided, then\n * the collection will use the {@link Mapper#idAttribute} setting, and will\n * wrap records in {@link Mapper#recordClass}.\n *\n * @example Collection#mapper\n * // Normally you would do: import {Collection, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const myMapper = new MyMapperClass({ name: 'myMapper' })\n * const collection = new Collection(null, { mapper: myMapper })\n *\n * @name Collection#mapper\n * @type {Mapper}\n * @default null\n * @since 3.0.0\n */\n mapper: {\n value: undefined,\n writable: true\n },\n // Query class used by this collection\n queryClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(COLLECTION_DEFAULTS))\n\n if (!this.queryClass) {\n this.queryClass = Query\n }\n\n const idAttribute = this.recordId()\n\n Object.defineProperties(this, {\n /**\n * The main index, which uses @{link Collection#recordId} as the key.\n *\n * @name Collection#index\n * @type {Index}\n */\n index: {\n value: new Index([idAttribute], {\n hashCode (obj) {\n return utils.get(obj, idAttribute)\n }\n })\n },\n\n /**\n * Object that holds the secondary indexes of this collection.\n *\n * @name Collection#indexes\n * @type {Object.}\n */\n indexes: {\n value: {}\n }\n })\n\n // Insert initial data into the collection\n if (utils.isObject(records) || (utils.isArray(records) && records.length)) {\n this.add(records)\n }\n}\n\nexport default Component.extend({\n constructor: Collection,\n\n /**\n * Used to bind to events emitted by records in this Collection.\n *\n * @method Collection#_onRecordEvent\n * @since 3.0.0\n * @private\n * @param {...*} [arg] Args passed to {@link Collection#emit}.\n */\n _onRecordEvent (...args) {\n this.emit(...args)\n },\n\n /**\n * Insert the provided record or records.\n *\n * If a record is already in the collection then the provided record will\n * either merge with or replace the existing record based on the value of the\n * `onConflict` option.\n *\n * The collection's secondary indexes will be updated as each record is\n * visited.\n *\n * @method Collection#add\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} data The record or records to insert.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.commitOnMerge=true] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.onConflict] See {@link Collection#onConflict}.\n * @returns {(Object|Object[]|Record|Record[])} The added record or records.\n */\n add (records, opts) {\n // Default values for arguments\n opts || (opts = {})\n\n // Fill in \"opts\" with the Collection's configuration\n utils._(opts, this)\n records = this.beforeAdd(records, opts) || records\n\n // Track whether just one record or an array of records is being inserted\n let singular = false\n const idAttribute = this.recordId()\n if (!utils.isArray(records)) {\n if (utils.isObject(records)) {\n records = [records]\n singular = true\n } else {\n throw utils.err(`${DOMAIN}#add`, 'records')(400, 'object or array', records)\n }\n }\n\n // Map the provided records to existing records.\n // New records will be inserted. If any records map to existing records,\n // they will be merged into the existing records according to the onConflict\n // option.\n records = records.map((record) => {\n let id = this.recordId(record)\n // Grab existing record if there is one\n const existing = id === undefined ? id : this.get(id)\n // If the currently visited record is just a reference to an existing\n // record, then there is nothing to be done. Exit early.\n if (record === existing) {\n return existing\n }\n\n if (existing) {\n // Here, the currently visited record corresponds to a record already\n // in the collection, so we need to merge them\n const onConflict = opts.onConflict || this.onConflict\n if (onConflict === 'merge') {\n utils.deepMixIn(existing, record)\n } else if (onConflict === 'replace') {\n utils.forOwn(existing, (value, key) => {\n if (key !== idAttribute && record[key] === undefined) {\n existing[key] = undefined\n }\n })\n existing.set(record)\n } else {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(400, 'one of (merge, replace)', onConflict, true)\n }\n record = existing\n if (opts.commitOnMerge && utils.isFunction(record.commit)) {\n record.commit()\n }\n // Update all indexes in the collection\n this.updateIndexes(record)\n } else {\n // Here, the currently visted record does not correspond to any record\n // in the collection, so (optionally) instantiate this record and insert\n // it into the collection\n record = this.mapper ? this.mapper.createRecord(record, opts) : record\n this.index.insertRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.insertRecord(record)\n })\n if (record && utils.isFunction(record.on)) {\n record.on('all', this._onRecordEvent, this)\n }\n }\n return record\n })\n // Finally, return the inserted data\n const result = singular ? records[0] : records\n this.emit('add', result)\n return this.afterAdd(records, opts, result) || result\n },\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then {@link Collection#add} will return that same value.\n *\n * @method Collection#method\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} result The record or records\n * that were added to this Collection by {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n afterAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}. If this method returns\n * a value then {@link Collection#remove} will return that same value.\n *\n * @method Collection#afterRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n * @param {Object} record The result that will be returned by {@link Collection#remove}.\n */\n afterRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}. If this method\n * returns a value then {@link Collection#removeAll} will return that same\n * value.\n *\n * @method Collection#afterRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n * @param {Object} records The result that will be returned by {@link Collection#removeAll}.\n */\n afterRemoveAll () {},\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then the `records` argument in {@link Collection#add} will be\n * re-assigned to the returned value.\n *\n * @method Collection#beforeAdd\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} records The `records` argument passed to {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n beforeAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}.\n *\n * @method Collection#beforeRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n */\n beforeRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}.\n *\n * @method Collection#beforeRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n */\n beforeRemoveAll () {},\n\n /**\n * Find all records between two boundaries.\n *\n * Shortcut for `collection.query().between(18, 30, { index: 'age' }).run()`\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = collection.between(18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = collection.between([18], [30], { index: 'age' })\n *\n * @method Collection#between\n * @since 3.0.0\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting records to skip.\n * @returns {Object[]|Record[]} The result.\n */\n between (leftKeys, rightKeys, opts) {\n return this.query().between(leftKeys, rightKeys, opts).run()\n },\n\n /**\n * Create a new secondary index on the contents of the collection.\n *\n * @example\n * // Index users by age\n * collection.createIndex('age')\n *\n * @example\n * // Index users by status and role\n * collection.createIndex('statusAndRole', ['status', 'role'])\n *\n * @method Collection#createIndex\n * @since 3.0.0\n * @param {string} name The name of the new secondary index.\n * @param {string[]} [fieldList] Array of field names to use as the key or\n * compound key of the new secondary index. If no fieldList is provided, then\n * the name will also be the field that is used to index the collection.\n */\n createIndex (name, fieldList, opts) {\n if (utils.isString(name) && fieldList === undefined) {\n fieldList = [name]\n }\n opts || (opts = {})\n opts.hashCode || (opts.hashCode = (obj) => this.recordId(obj))\n const index = this.indexes[name] = new Index(fieldList, opts)\n this.index.visitAll(index.insertRecord, index)\n },\n\n /**\n * Find the record or records that match the provided query or pass the\n * provided filter function.\n *\n * Shortcut for `collection.query().filter(queryOrFn[, thisArg]).run()`\n *\n * @example Collection#filter\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const collection = new Collection([\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = collection.filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = collection.filter(function (post) {\n * return post.id % 2 === 0\n * })\n *\n * @method Collection#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Object} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Array} The result.\n * @see query\n * @since 3.0.0\n */\n filter (query, thisArg) {\n return this.query().filter(query, thisArg).run()\n },\n\n /**\n * Iterate over all records.\n *\n * @example\n * collection.forEach(function (record) {\n * // do something\n * })\n *\n * @method Collection#forEach\n * @since 3.0.0\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Array} The result.\n */\n forEach (cb, thisArg) {\n this.index.visitAll(cb, thisArg)\n },\n\n /**\n * Get the record with the given id.\n *\n * @method Collection#get\n * @since 3.0.0\n * @param {(string|number)} id The primary key of the record to get.\n * @returns {(Object|Record)} The record with the given id.\n */\n get (id) {\n const instances = this.query().get(id).run()\n return instances.length ? instances[0] : undefined\n },\n\n /**\n * Find the record or records that match the provided keyLists.\n *\n * Shortcut for `collection.query().getAll(keyList1, keyList2, ...).run()`\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = collection.getAll('draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = collection.getAll(['draft'], ['inReview'], { index: 'status' })\n *\n * @method Collection#getAll\n * @since 3.0.0\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * records matching each keyList will be retrieved. If no keyLists are\n * provided, all records will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Array} The result.\n */\n getAll (...args) {\n return this.query().getAll(...args).run()\n },\n\n /**\n * Return the index with the given name. If no name is provided, return the\n * main index. Throws an error if the specified index does not exist.\n *\n * @method Collection#getIndex\n * @since 3.0.0\n * @param {string} [name] The name of the index to retrieve.\n */\n getIndex (name) {\n const index = name ? this.indexes[name] : this.index\n if (!index) {\n throw utils.err(`${DOMAIN}#getIndex`, name)(404, 'index')\n }\n return index\n },\n\n /**\n * Limit the result.\n *\n * Shortcut for `collection.query().limit(maximumNumber).run()`\n *\n * @example\n * const posts = collection.limit(10)\n *\n * @method Collection#limit\n * @since 3.0.0\n * @param {number} num The maximum number of records to keep in the result.\n * @returns {Array} The result.\n */\n limit (num) {\n return this.query().limit(num).run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map(function (user) {\n * return user.name\n * })\n *\n * @method Collection#map\n * @since 3.0.0\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Array} The result of the mapping.\n */\n map (cb, thisArg) {\n const data = []\n this.index.visitAll(function (value) {\n data.push(cb.call(thisArg, value))\n })\n return data\n },\n\n /**\n * Return the result of calling the specified function on each record in this\n * collection's main index.\n *\n * @method Collection#mapCall\n * @since 3.0.0\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Array} The result.\n */\n mapCall (funcName, ...args) {\n const data = []\n this.index.visitAll(function (record) {\n data.push(record[funcName](...args))\n })\n return data\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#prune\n * @param {Object} [opts] Configuration options, passed to {@link Collection#removeAll}.\n * @since 3.0.0\n * @returns {Array} The removed records, if any.\n */\n prune (opts) {\n return this.removeAll(this.unsaved(), opts)\n },\n\n /**\n * Create a new query to be executed against the contents of the collection.\n * The result will be all or a subset of the contents of the collection.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * collection.query()\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method Collection#query\n * @since 3.0.0\n * @returns {Query} New query object.\n */\n query () {\n const Ctor = this.queryClass\n return new Ctor(this)\n },\n\n /**\n * Return the primary key of the given, or if no record is provided, return the\n * name of the field that holds the primary key of records in this Collection.\n *\n * @method Collection#recordId\n * @since 3.0.0\n * @param {(Object|Record)} [record] The record whose primary key is to be\n * returned.\n * @returns {(string|number)} Primary key or name of field that holds primary\n * key.\n */\n recordId (record) {\n if (record) {\n return utils.get(record, this.recordId())\n }\n return this.mapper ? this.mapper.idAttribute : this.idAttribute\n },\n\n /**\n * Reduce the data in the collection to a single value and return the result.\n *\n * @example\n * const totalVotes = collection.reduce(function (prev, record) {\n * return prev + record.upVotes + record.downVotes\n * }, 0)\n *\n * @method Collection#reduce\n * @since 3.0.0\n * @param {Function} cb Reduction callback.\n * @param {*} initialValue Initial value of the reduction.\n * @returns {*} The result.\n */\n reduce (cb, initialValue) {\n const data = this.getAll()\n return data.reduce(cb, initialValue)\n },\n\n /**\n * Remove the record with the given id from this Collection.\n *\n * @method Collection#remove\n * @since 3.0.0\n * @param {(string|number|object|Record)} idOrRecord The primary key of the\n * record to be removed, or a reference to the record that is to be removed.\n * @param {Object} [opts] Configuration options.\n * @returns {Object|Record} The removed record, if any.\n */\n remove (idOrRecord, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemove(idOrRecord, opts)\n let record = utils.isSorN(idOrRecord) ? this.get(idOrRecord) : idOrRecord\n\n // The record is in the collection, remove it\n if (utils.isObject(record)) {\n record = this.index.removeRecord(record)\n if (record) {\n utils.forOwn(this.indexes, function (index, name) {\n index.removeRecord(record)\n })\n if (utils.isFunction(record.off)) {\n record.off('all', this._onRecordEvent, this)\n if (!opts.silent) {\n this.emit('remove', record)\n }\n }\n }\n }\n return this.afterRemove(idOrRecord, opts, record) || record\n },\n\n /**\n * Remove from this collection the given records or the records selected by\n * the given \"query\".\n *\n * @method Collection#removeAll\n * @since 3.0.0\n * @param {Object|Object[]|Record[]} [queryOrRecords={}] Records to be removed or selection query. See {@link query}.\n * @param {Object} [queryOrRecords.where] See {@link query.where}.\n * @param {number} [queryOrRecords.offset] See {@link query.offset}.\n * @param {number} [queryOrRecords.limit] See {@link query.limit}.\n * @param {string|Array[]} [queryOrRecords.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object[]|Record[])} The removed records, if any.\n */\n removeAll (queryOrRecords, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemoveAll(queryOrRecords, opts)\n let records = utils.isArray(queryOrRecords) ? queryOrRecords.slice() : this.filter(queryOrRecords)\n\n // Remove each selected record from the collection\n const optsCopy = utils.plainCopy(opts)\n optsCopy.silent = true\n records = records\n .map((record) => this.remove(record, optsCopy))\n .filter((record) => record)\n if (!opts.silent) {\n this.emit('remove', records)\n }\n return this.afterRemoveAll(queryOrRecords, opts, records) || records\n },\n\n /**\n * Skip a number of results.\n *\n * Shortcut for `collection.query().skip(numberToSkip).run()`\n *\n * @example\n * const posts = collection.skip(10)\n *\n * @method Collection#skip\n * @since 3.0.0\n * @param {number} num The number of records to skip.\n * @returns {Array} The result.\n */\n skip (num) {\n return this.query().skip(num).run()\n },\n\n /**\n * Return the plain JSON representation of all items in this collection.\n * Assumes records in this collection have a toJSON method.\n *\n * @method Collection#toJSON\n * @since 3.0.0\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation.\n * @returns {Array} The records.\n */\n toJSON (opts) {\n return this.mapCall('toJSON', opts)\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#unsaved\n * @since 3.0.0\n * @returns {Array} The unsaved records, if any.\n */\n unsaved (opts) {\n return this.index.get()\n },\n\n /**\n * Update a record's position in a single index of this collection. See\n * {@link Collection#updateIndexes} to update a record's position in all\n * indexes at once.\n *\n * @method Collection#updateIndex\n * @since 3.0.0\n * @param {Object} record The record to update.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] The index in which to update the record's\n * position. If you don't specify an index then the record will be updated\n * in the main index.\n */\n updateIndex (record, opts) {\n opts || (opts = {})\n this.getIndex(opts.index).updateRecord(record)\n },\n\n /**\n * Updates all indexes in this collection for the provided record. Has no\n * effect if the record is not in the collection.\n *\n * @method Collection#updateIndexes\n * @since 3.0.0\n * @param {Object} record TODO\n */\n updateIndexes (record) {\n this.index.updateRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.updateRecord(record)\n })\n }\n})\n\n/**\n * Fired when a record changes. Only works for records that have tracked changes.\n * See {@link Collection~changeListener} on how to listen for this event.\n *\n * @event Collection#change\n * @see Collection~changeListener\n */\n\n/**\n * Callback signature for the {@link Collection#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * collection.on('change', onChange)\n *\n * @callback Collection~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Collection#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the Collection. See\n * {@link Collection~addListener} on how to listen for this event.\n *\n * @event Collection#add\n * @see Collection~addListener\n * @see Collection#event:add\n * @see Collection#add\n */\n\n/**\n * Callback signature for the {@link Collection#event:add} event.\n *\n * @example\n * function onAdd (recordOrRecords) {\n * // do something\n * }\n * collection.on('add', onAdd)\n *\n * @callback Collection~addListener\n * @param {Record|Record[]} The Record or Records that were added.\n * @see Collection#event:add\n * @see Collection#add\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the Collection. See\n * {@link Collection~removeListener} for how to listen for this event.\n *\n * @event Collection#remove\n * @see Collection~removeListener\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n */\n\n/**\n * Callback signature for the {@link Collection#event:remove} event.\n *\n * @example\n * function onRemove (recordsOrRecords) {\n * // do something\n * }\n * collection.on('remove', onRemove)\n *\n * @callback Collection~removeListener\n * @param {Record|Record[]} Record or Records that were removed.\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Collection:\n * @example Collection.extend\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomCollectionClass extends Collection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customCollection = new CustomCollectionClass()\n * console.log(customCollection.foo())\n * console.log(CustomCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherCollectionClass = Collection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherCollection = new OtherCollectionClass()\n * console.log(otherCollection.foo())\n * console.log(OtherCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherCollectionClass () {\n * Collection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Collection.extend({\n * constructor: AnotherCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherCollection = new AnotherCollectionClass()\n * console.log(anotherCollection.created_at)\n * console.log(anotherCollection.foo())\n * console.log(AnotherCollectionClass.beep())\n *\n * @method Collection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Collection class.\n * @since 3.0.0\n */\n","import utils from './utils'\n\n// TODO: remove this when the rest of the project is cleaned\nexport const belongsToType = 'belongsTo'\nexport const hasManyType = 'hasMany'\nexport const hasOneType = 'hasOne'\n\nconst DOMAIN = 'Relation'\n\nexport function Relation (relatedMapper, options = {}) {\n utils.classCallCheck(this, Relation)\n\n options.type = this.constructor.TYPE_NAME\n this.validateOptions(relatedMapper, options)\n\n if (typeof relatedMapper === 'object') {\n Object.defineProperty(this, 'relatedMapper', { value: relatedMapper })\n }\n\n Object.defineProperty(this, 'inverse', { writable: true })\n utils.fillIn(this, options)\n}\n\nRelation.extend = utils.extend\n\nutils.addHiddenPropsToTarget(Relation.prototype, {\n get canAutoAddLinks () {\n return this.add === undefined || !!this.add\n },\n\n get relatedCollection () {\n return this.mapper.datastore.getCollection(this.relation)\n },\n\n validateOptions (related, opts) {\n const DOMAIN_ERR = `new ${DOMAIN}`\n\n const localField = opts.localField\n if (!localField) {\n throw utils.err(DOMAIN_ERR, 'opts.localField')(400, 'string', localField)\n }\n\n const foreignKey = opts.foreignKey = opts.foreignKey || opts.localKey\n if (!foreignKey && (opts.type === belongsToType || opts.type === hasOneType)) {\n throw utils.err(DOMAIN_ERR, 'opts.foreignKey')(400, 'string', foreignKey)\n }\n\n if (utils.isString(related)) {\n opts.relation = related\n if (!utils.isFunction(opts.getRelation)) {\n throw utils.err(DOMAIN_ERR, 'opts.getRelation')(400, 'function', opts.getRelation)\n }\n } else if (related) {\n opts.relation = related.name\n } else {\n throw utils.err(DOMAIN_ERR, 'related')(400, 'Mapper or string', related)\n }\n },\n\n assignTo (mapper) {\n this.name = mapper.name\n Object.defineProperty(this, 'mapper', { value: mapper })\n\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n mapper.relationFields || Object.defineProperty(mapper, 'relationFields', { value: [] })\n mapper.relationList.push(this)\n mapper.relationFields.push(this.localField)\n },\n\n canFindLinkFor () {\n return !!(this.foreignKey || this.localKey)\n },\n\n getRelation () {\n return this.relatedMapper\n },\n\n getForeignKey (record) {\n return utils.get(record, this.mapper.idAttribute)\n },\n\n setForeignKey (record, relatedRecord) {\n if (!record || !relatedRecord) {\n return\n }\n\n this._setForeignKey(record, relatedRecord)\n },\n\n _setForeignKey (record, relatedRecords) {\n const idAttribute = this.mapper.idAttribute\n\n if (!utils.isArray(relatedRecords)) {\n relatedRecords = [relatedRecords]\n }\n\n relatedRecords.forEach((relatedRecord) => {\n utils.set(relatedRecord, this.foreignKey, utils.get(record, idAttribute))\n })\n },\n\n getLocalField (record) {\n return utils.get(record, this.localField)\n },\n\n setLocalField (record, relatedData) {\n return utils.set(record, this.localField, relatedData)\n },\n\n getInverse (mapper) {\n if (!this.inverse) {\n this.findInverseRelation(mapper)\n }\n\n return this.inverse\n },\n\n findInverseRelation (mapper) {\n this.getRelation().relationList.forEach((def) => {\n if (def.getRelation() === mapper && this.isInversedTo(def)) {\n this.inverse = def\n return true\n }\n })\n },\n\n isInversedTo (def) {\n return !def.foreignKey || def.foreignKey === this.foreignKey\n },\n\n addLinkedRecords (records) {\n const datastore = this.mapper.datastore\n\n records.forEach((record) => {\n let relatedData = this.getLocalField(record)\n\n if (utils.isFunction(this.add)) {\n relatedData = this.add(datastore, this, record)\n } else if (relatedData) {\n relatedData = this.linkRecord(record, relatedData)\n }\n\n const isEmptyLinks = !relatedData || utils.isArray(relatedData) && !relatedData.length\n\n if (isEmptyLinks && this.canFindLinkFor(record)) {\n relatedData = this.findExistingLinksFor(record)\n }\n\n if (relatedData) {\n this.setLocalField(record, relatedData)\n }\n })\n },\n\n removeLinkedRecords (relatedMapper, records) {\n const localField = this.localField\n records.forEach((record) => {\n utils.set(record, localField, undefined)\n })\n },\n\n linkRecord (record, relatedRecord) {\n const relatedId = utils.get(relatedRecord, this.mapper.idAttribute)\n\n if (relatedId === undefined) {\n const unsaved = this.relatedCollection.unsaved()\n if (unsaved.indexOf(relatedRecord) === -1) {\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n } else {\n if (relatedRecord !== this.relatedCollection.get(relatedId)) {\n this.setForeignKey(record, relatedRecord)\n\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n }\n\n return relatedRecord\n },\n\n // e.g. user hasMany post via \"foreignKey\", so find all posts of user\n findExistingLinksByForeignKey (id) {\n if (id === undefined || id === null) {\n return\n }\n return this.relatedCollection.filter({\n [this.foreignKey]: id\n })\n }\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const BelongsToRelation = Relation.extend({\n getForeignKey (record) {\n return utils.get(record, this.foreignKey)\n },\n\n _setForeignKey (record, relatedRecord) {\n utils.set(record, this.foreignKey, utils.get(relatedRecord, this.getRelation().idAttribute))\n },\n\n findExistingLinksFor (record) {\n // console.log('\\tBelongsTo#findExistingLinksFor', record)\n if (!record) {\n return\n }\n const relatedId = utils.get(record, this.foreignKey)\n if (relatedId !== undefined && relatedId !== null) {\n return this.relatedCollection.get(relatedId)\n }\n }\n}, {\n TYPE_NAME: 'belongsTo'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasManyRelation = Relation.extend({\n validateOptions (related, opts) {\n Relation.prototype.validateOptions.call(this, related, opts)\n\n const { localKeys, foreignKeys, foreignKey } = opts\n\n if (!foreignKey && !localKeys && !foreignKeys) {\n throw utils.err('new Relation', 'opts.')(400, 'string', foreignKey)\n }\n },\n\n canFindLinkFor (record) {\n const hasForeignKeys = this.foreignKey || this.foreignKeys\n return !!(hasForeignKeys || (this.localKeys && utils.get(record, this.localKeys)))\n },\n\n linkRecord (record, relatedRecords) {\n const relatedCollection = this.relatedCollection\n const canAutoAddLinks = this.canAutoAddLinks\n const foreignKey = this.foreignKey\n const unsaved = this.relatedCollection.unsaved()\n\n return relatedRecords.map((relatedRecord) => {\n const relatedId = relatedCollection.recordId(relatedRecord)\n\n if ((relatedId === undefined && unsaved.indexOf(relatedRecord) === -1) || relatedRecord !== relatedCollection.get(relatedId)) {\n if (foreignKey) {\n // TODO: slow, could be optimized? But user loses hook\n this.setForeignKey(record, relatedRecord)\n }\n if (canAutoAddLinks) {\n relatedRecord = relatedCollection.add(relatedRecord)\n }\n }\n\n return relatedRecord\n })\n },\n\n findExistingLinksFor (record) {\n const id = utils.get(record, this.mapper.idAttribute)\n const ids = this.localKeys ? utils.get(record, this.localKeys) : null\n let records\n\n if (id !== undefined && this.foreignKey) {\n records = this.findExistingLinksByForeignKey(id)\n } else if (this.localKeys && ids) {\n records = this.findExistingLinksByLocalKeys(ids)\n } else if (id !== undefined && this.foreignKeys) {\n records = this.findExistingLinksByForeignKeys(id)\n }\n\n if (records && records.length) {\n return records\n }\n },\n\n // e.g. user hasMany group via \"foreignKeys\", so find all users of a group\n findExistingLinksByLocalKeys (ids) {\n return this.relatedCollection.filter({\n where: {\n [this.mapper.idAttribute]: {\n 'in': ids\n }\n }\n })\n },\n\n // e.g. group hasMany user via \"localKeys\", so find all groups that own a user\n findExistingLinksByForeignKeys (id) {\n return this.relatedCollection.filter({\n where: {\n [this.foreignKeys]: {\n 'contains': id\n }\n }\n })\n }\n}, {\n TYPE_NAME: 'hasMany'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasOneRelation = Relation.extend({\n findExistingLinksFor (relatedMapper, record) {\n const recordId = utils.get(record, relatedMapper.idAttribute)\n const records = this.findExistingLinksByForeignKey(recordId)\n\n if (records && records.length) {\n return records[0]\n }\n }\n}, {\n TYPE_NAME: 'hasOne'\n})\n","import { Relation } from './Relation'\nimport { BelongsToRelation } from './Relation/BelongsTo'\nimport { HasManyRelation } from './Relation/HasMany'\nimport { HasOneRelation } from './Relation/HasOne'\n\n[BelongsToRelation, HasManyRelation, HasOneRelation].forEach(function (RelationType) {\n Relation[RelationType.TYPE_NAME] = function (related, options) {\n return new RelationType(related, options)\n }\n})\n\nexport { belongsToType, hasManyType, hasOneType, Relation } from './Relation'\n","import { Relation } from './relations'\n\nexport { belongsToType, hasManyType, hasOneType } from './relations'\n/**\n * BelongsTo relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.belongsTo\n * @method\n * @param {Mapper} related The relation the target belongs to.\n * @param {Object} opts Configuration options.\n * @param {string} opts.foreignKey The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const belongsTo = function (related, opts) {\n return function (mapper) {\n Relation.belongsTo(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasMany relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasMany\n * @method\n * @param {Mapper} related The relation of which the target has many.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasMany = function (related, opts) {\n return function (mapper) {\n Relation.hasMany(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasOne relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasOne\n * @method\n * @param {Mapper} related The relation of which the target has one.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasOne = function (related, opts) {\n return function (mapper) {\n Relation.hasOne(related, opts).assignTo(mapper)\n }\n}\n","import utils, { safeSetLink } from './utils'\nimport Component from './Component'\nimport Settable from './Settable'\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Record'\n\nconst superMethod = function (mapper, name) {\n const store = mapper.datastore\n if (store && store[name]) {\n return function (...args) {\n return store[name](mapper.name, ...args)\n }\n }\n return mapper[name].bind(mapper)\n}\n\n// Cache these strings\nconst creatingPath = 'creating'\nconst noValidatePath = 'noValidate'\nconst keepChangeHistoryPath = 'keepChangeHistory'\nconst previousPath = 'previous'\n\n/**\n * js-data's Record class. An instance of `Record` corresponds to an in-memory\n * representation of a single row or document in a database, Firebase,\n * localstorage, etc. Basically, a `Record` instance represents whatever kind of\n * entity in your persistence layer that has a primary key.\n *\n * ```javascript\n * import {Record} from 'js-data'\n * ```\n *\n * @example Record#constructor\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a plain record\n * let record = new Record()\n * console.log('record: ' + JSON.stringify(record))\n *\n * // You can supply properties on instantiation\n * record = new Record({ name: 'John' })\n * console.log('record: ' + JSON.stringify(record))\n *\n * @example Record#constructor2\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a record that's associated with a Mapper:\n * const UserMapper = new Mapper({ name: 'user' })\n * const User = UserMapper.recordClass\n * const user = UserMapper.createRecord({ name: 'John' })\n * const user2 = new User({ name: 'Sally' })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user2: ' + JSON.stringify(user2))\n *\n * @example Record#constructor3\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n *\n * // Instantiate a record that's associated with a store's Mapper\n * const user = store.createRecord('user', { name: 'John' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor4\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Validate on instantiation\n * const user = store.createRecord('user', { name: 1234 })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor5\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Skip validation on instantiation\n * const user = store.createRecord('user', { name: 1234 }, { noValidate: true })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user.isValid(): ' + user.isValid())\n *\n * @class Record\n * @extends Component\n * @param {Object} [props] The initial properties of the new Record instance.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate=false] Whether to skip validation on the\n * initial properties.\n * @since 3.0.0\n */\nfunction Record (props, opts) {\n utils.classCallCheck(this, Record)\n Settable.call(this)\n props || (props = {})\n opts || (opts = {})\n const _set = this._set\n _set(creatingPath, true)\n if (opts.noValidate) {\n _set(noValidatePath, opts.noValidate === undefined ? true : opts.noValidate)\n }\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\n const mapper = this.constructor.mapper\n const id = mapper ? utils.get(props, mapper.idAttribute) : undefined\n if (id !== undefined) {\n utils.set(this, mapper.idAttribute, id)\n }\n\n utils.fillIn(this, props)\n _set(creatingPath, false)\n const validateOnSet = opts.validateOnSet === undefined ? (mapper ? mapper.validateOnSet : true) : opts.validateOnSet\n _set(noValidatePath, !validateOnSet)\n _set(previousPath, mapper ? mapper.toJSON(props) : utils.plainCopy(props))\n}\n\nexport default Component.extend({\n constructor: Record,\n\n /**\n * Returns the {@link Mapper} paired with this record's class, if any.\n *\n * @method Record#_mapper\n * @returns {Mapper} The {@link Mapper} paired with this record's class, if any.\n * @since 3.0.0\n */\n _mapper () {\n const mapper = this.constructor.mapper\n if (!mapper) {\n throw utils.err(`${DOMAIN}#_mapper`, '')(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Lifecycle hook.\n *\n * @method Record#afterLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n afterLoadRelations () {},\n\n /**\n * Lifecycle hook.\n *\n * @method Record#beforeLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n beforeLoadRelations () {},\n\n /**\n * Return the change history of this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @method Record#changeHistory\n * @since 3.0.0\n */\n changeHistory () {\n return (this._get('history') || []).slice()\n },\n\n /**\n * Return changes to this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#changes\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n * user.name = 'John'\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n *\n * @method Record#changes\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} Object describing the changes to this record since it was\n * instantiated or its {@link Record#commit} method was last called.\n * @since 3.0.0\n */\n changes (opts) {\n opts || (opts = {})\n return utils.diffObjects(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Make the record's current in-memory state it's only state, with any\n * previous property values being set to current values.\n *\n * @example Record#commit\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#commit\n * @param {Object} [opts] Configuration options. Passed to {@link Record#toJSON}.\n * @since 3.0.0\n */\n commit (opts) {\n this._set('changed') // unset\n this._set('history', []) // clear history\n this._set('previous', this.toJSON(opts))\n },\n\n /**\n * Call {@link Mapper#destroy} using this record's primary key.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user')\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Destroy this user from the database\n * return user.destroy()\n * })\n *\n * @method Record#destroy\n * @param {Object} [opts] Configuration options passed to {@link Mapper#destroy}.\n * @returns {Promise} The result of calling {@link Mapper#destroy} with the\n * primary key of this record.\n * @since 3.0.0\n */\n destroy (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n return superMethod(mapper, 'destroy')(utils.get(this, mapper.idAttribute), opts)\n },\n\n /**\n * Return the value at the given path for this instance.\n *\n * @example Record#get\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', { name: 'Bob' })\n * console.log('user.get(\"name\"): ' + user.get('name'))\n *\n * @method Record#get\n * @param {string} key Path of value to retrieve.\n * @returns {*} Value at path.\n * @since 3.0.0\n */\n 'get' (key) {\n return utils.get(this, key)\n },\n\n /**\n * Return whether this record has changed since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#hasChanges\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#hasChanges\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Return whether the record has changed since it was\n * instantiated or since its {@link Record#commit} method was called.\n * @since 3.0.0\n */\n hasChanges (opts) {\n const quickHasChanges = !!(this._get('changed') || []).length\n return quickHasChanges || utils.areDifferent(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Return whether the record is unsaved. Records that have primary keys are\n * considered \"saved\". Records without primary keys are considered \"unsaved\".\n *\n * @example Record#isNew\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * id: 1234\n * })\n * const user2 = store.createRecord('user')\n * console.log('user isNew: ' + user.isNew()) // false\n * console.log('user2 isNew: ' + user2.isNew()) // true\n *\n * @method Record#isNew\n * @returns {boolean} Whether the record is unsaved.\n * @since 3.0.0\n */\n isNew (opts) {\n return utils.get(this, this._mapper().idAttribute) === undefined\n },\n\n /**\n * Return whether the record in its current state passes validation.\n *\n * @example Record#isValid\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user isValid: ' + user.isValid())\n * user.name = 'John'\n * console.log('user isValid: ' + user.isValid())\n *\n * @method Record#isValid\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {boolean} Whether the record in its current state passes\n * validation.\n * @since 3.0.0\n */\n isValid (opts) {\n return !this._mapper().validate(this, opts)\n },\n\n removeInverseRelation(currentParent, id, inverseDef, idAttribute) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n // e.g. remove comment from otherPost.comments\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n setupInverseRelation(record, id, inverseDef, idAttribute) {\n // Update (set) inverse relation\n if (inverseDef.type === hasOneType) {\n // e.g. someUser.profile = profile\n safeSetLink(record, inverseDef.localField, this)\n } else if (inverseDef.type === hasManyType) {\n // e.g. add comment to somePost.comments\n const children = utils.get(record, inverseDef.localField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n /**\n * Lazy load relations of this record, to be attached to the record once their\n * loaded.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user', {\n * relations: {\n * hasMany: {\n * post: {\n * localField: 'posts',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.defineMapper('post', {\n * relations: {\n * belongsTo: {\n * user: {\n * localField: 'user',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Load the user's post relations\n * return user.loadRelations(['post'])\n * }).then((user) => {\n * console.log(user.posts) // [{...}, {...}, ...]\n * })\n *\n * @method Record#loadRelations\n * @param {string[]} [relations] List of relations to load. Can use localField\n * names or Mapper names to pick relations.\n * @param {Object} [opts] Configuration options.\n * @returns {Promise} Resolves with the record, with the loaded relations now\n * attached.\n * @since 3.0.0\n */\n loadRelations (relations, opts) {\n let op\n const mapper = this._mapper()\n\n // Default values for arguments\n relations || (relations = [])\n if (utils.isString(relations)) {\n relations = [relations]\n }\n opts || (opts = {})\n opts.with = relations\n\n // Fill in \"opts\" with the Model's configuration\n utils._(opts, mapper)\n opts.adapter = mapper.getAdapterName(opts)\n\n // beforeLoadRelations lifecycle hook\n op = opts.op = 'beforeLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'loadRelations'\n mapper.dbg(op, this, relations, opts)\n let tasks = []\n let task\n utils.forEachRelation(mapper, opts, (def, optsCopy) => {\n const relatedMapper = def.getRelation()\n optsCopy.raw = false\n if (utils.isFunction(def.load)) {\n task = def.load(mapper, def, this, opts)\n } else if (def.type === 'hasMany' || def.type === 'hasOne') {\n if (def.foreignKey) {\n task = superMethod(relatedMapper, 'findAll')({\n [def.foreignKey]: utils.get(this, mapper.idAttribute)\n }, optsCopy).then(function (relatedData) {\n if (def.type === 'hasOne') {\n return relatedData.length ? relatedData[0] : undefined\n }\n return relatedData\n })\n } else if (def.localKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [relatedMapper.idAttribute]: {\n 'in': utils.get(this, def.localKeys)\n }\n }\n })\n } else if (def.foreignKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [def.foreignKeys]: {\n 'contains': utils.get(this, mapper.idAttribute)\n }\n }\n }, opts)\n }\n } else if (def.type === 'belongsTo') {\n const key = utils.get(this, def.foreignKey)\n if (utils.isSorN(key)) {\n task = superMethod(relatedMapper, 'find')(key, optsCopy)\n }\n }\n if (task) {\n task = task.then((relatedData) => {\n def.setLocalField(this, relatedData)\n })\n tasks.push(task)\n }\n })\n return Promise.all(tasks)\n }).then(() => {\n // afterLoadRelations lifecycle hook\n op = opts.op = 'afterLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => this)\n })\n },\n\n /**\n * Return the properties with which this record was instantiated.\n *\n * @example Record#previous\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.name = 'Bob'\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.commit()\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n *\n * @method Record#previous\n * @param {string} [key] If specified, return just the initial value of the\n * given key.\n * @returns {Object} The initial properties of this record.\n * @since 3.0.0\n */\n previous (key) {\n if (key) {\n return this._get(`previous.${key}`)\n }\n return this._get('previous')\n },\n\n /**\n * Revert changes to this record back to the properties it had when it was\n * instantiated.\n *\n * @example Record#revert\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user: ' + JSON.stringify(user))\n * user.name = 'Bob'\n * console.log('user: ' + JSON.stringify(user))\n * user.revert()\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#revert\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.preserve] Array of strings or Regular Expressions\n * denoting properties that should not be reverted.\n * @since 3.0.0\n */\n revert (opts) {\n const previous = this._get('previous')\n opts || (opts = {})\n opts.preserve || (opts.preserve = [])\n utils.forOwn(this, (value, key) => {\n if (key !== this._mapper().idAttribute && !previous.hasOwnProperty(key) && this.hasOwnProperty(key) && opts.preserve.indexOf(key) === -1) {\n delete this[key]\n }\n })\n utils.forOwn(previous, (value, key) => {\n if (opts.preserve.indexOf(key) === -1) {\n this[key] = value\n }\n })\n this.commit()\n },\n\n /**\n * Delegates to {@link Mapper#create} or {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('session')\n * const session = store.createRecord('session', { topic: 'Node.js' })\n *\n * // Create a new record in the database\n * session.save().then(() => {\n * console.log(session.id) // 1234\n *\n * session.skill_level = 'beginner'\n *\n * // Update the record in the database\n * return user.save()\n * })\n *\n * @method Record#save\n * @param {Object} [opts] Configuration options. See {@link Mapper#create} and\n * {@link Mapper#update}.\n * @param {boolean} [opts.changesOnly] Equality function. Default uses `===`.\n * @param {Function} [opts.equalsFn] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @param {Array} [opts.ignore] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @returns {Promise} The result of calling {@link Mapper#create} or\n * {@link Mapper#update}.\n * @since 3.0.0\n */\n save (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n const id = utils.get(this, mapper.idAttribute)\n let props = this\n\n const postProcess = (result) => {\n const record = opts.raw ? result.data : result\n if (record) {\n utils.deepMixIn(this, record)\n this.commit()\n }\n return result\n }\n\n if (id === undefined) {\n return superMethod(mapper, 'create')(props, opts).then(postProcess)\n }\n if (opts.changesOnly) {\n const changes = this.changes(opts)\n props = {}\n utils.fillIn(props, changes.added)\n utils.fillIn(props, changes.changed)\n }\n return superMethod(mapper, 'update')(id, props, opts).then(postProcess)\n },\n\n /**\n * Set the value for a given key, or the values for the given keys if \"key\" is\n * an object. Triggers change events on those properties that have `track: true`\n * in {@link Mapper#schema}.\n *\n * @example Record#set\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set('name', 'Bob')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set({ age: 30, role: 'admin' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @fires Record#change\n * @method Record#set\n * @param {(string|Object)} key Key to set or hash of key-value pairs to set.\n * @param {*} [value] Value to set for the given key.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n 'set' (key, value, opts) {\n if (utils.isObject(key)) {\n opts = value\n }\n opts || (opts = {})\n if (opts.silent) {\n this._set('silent', true)\n }\n utils.set(this, key, value)\n if (!this._get('eventId')) {\n this._set('silent') // unset\n }\n },\n\n /**\n * Return a plain object representation of this record. If the class from\n * which this record was created has a Mapper, then {@link Mapper#toJSON} will\n * be called with this record instead.\n *\n * @example Record#toJSON\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * const user = store.createRecord('user', {\n * name: 'John',\n * $$hashKey: '1234'\n * })\n * console.log('user: ' + JSON.stringify(user.toJSON()))\n * console.log('user: ' + JSON.stringify(user.toJSON({ strict: true })))\n *\n * @method Record#toJSON\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation. Only available as an option if the class\n * from which this record was created has a Mapper and this record resides in\n * an instance of {@link DataStore}.\n * @returns {Object} Plain object representation of this record.\n * @since 3.0.0\n */\n toJSON (opts) {\n const mapper = this.constructor.mapper\n if (mapper) {\n return mapper.toJSON(this, opts)\n } else {\n const json = {}\n utils.forOwn(this, function (prop, key) {\n json[key] = utils.plainCopy(prop)\n })\n return json\n }\n },\n\n /**\n * Unset the value for a given key. Triggers change events on those properties\n * that have `track: true` in {@link Mapper#schema}.\n *\n * @example Record#unset\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', {\n * name: 'John'\n * })\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.unset('name')\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#unset\n * @param {string} key Key to unset.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n unset (key, opts) {\n this.set(key, undefined, opts)\n },\n\n /**\n * Validate this record based on its current properties.\n *\n * @example Record#validate\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user validation: ' + JSON.stringify(user.validate()))\n * user.name = 'John'\n * console.log('user validation: ' + user.validate())\n *\n * @method Record#validate\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {*} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (opts) {\n return this._mapper().validate(this, opts)\n }\n})\n\n/**\n * Allow records to emit events.\n *\n * An record's registered listeners are stored in the record's private data.\n */\nutils.eventify(\n Record.prototype,\n function () {\n return this._get('events')\n },\n function (value) {\n this._set('events', value)\n }\n)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link Record~changeListener} on how to listen for this event.\n *\n * @event Record#change\n * @see Record~changeListener\n */\n\n/**\n * Callback signature for the {@link Record#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * record.on('change', onChange)\n *\n * @callback Record~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Record#event:change\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Record:\n * @example Record.extend\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomRecordClass extends Record {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customRecord = new CustomRecordClass()\n * console.log(customRecord.foo())\n * console.log(CustomRecordClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherRecordClass = Record.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherRecord = new OtherRecordClass()\n * console.log(otherRecord.foo())\n * console.log(OtherRecordClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherRecordClass () {\n * Record.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Record.extend({\n * constructor: AnotherRecordClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherRecord = new AnotherRecordClass()\n * console.log(anotherRecord.created_at)\n * console.log(anotherRecord.foo())\n * console.log(AnotherRecordClass.beep())\n *\n * @method Record.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Record class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Schema'\n\n/**\n * A function map for each of the seven primitive JSON types defined by the core specification.\n * Each function will check a given value and return true or false if the value is an instance of that type.\n * ```\n * types.integer(1) // returns true\n * types.string({}) // returns false\n * ```\n * http://json-schema.org/latest/json-schema-core.html#anchor8\n * @name Schema.types\n * @type {Object}\n */\nconst types = {\n array: utils.isArray,\n boolean: utils.isBoolean,\n integer: utils.isInteger,\n 'null': utils.isNull,\n number: utils.isNumber,\n object: utils.isObject,\n string: utils.isString\n}\n\n/**\n * @ignore\n */\nconst segmentToString = function (segment, prev) {\n let str = ''\n if (segment) {\n if (utils.isNumber(segment)) {\n str += `[${segment}]`\n } else if (prev) {\n str += `.${segment}`\n } else {\n str += `${segment}`\n }\n }\n return str\n}\n\n/**\n * @ignore\n */\nconst makePath = function (opts) {\n opts || (opts = {})\n let path = ''\n const segments = opts.path || []\n segments.forEach(function (segment) {\n path += segmentToString(segment, path)\n })\n path += segmentToString(opts.prop, path)\n return path\n}\n\n/**\n * @ignore\n */\nconst makeError = function (actual, expected, opts) {\n return {\n expected,\n actual: '' + actual,\n path: makePath(opts)\n }\n}\n\n/**\n * @ignore\n */\nconst addError = function (actual, expected, opts, errors) {\n errors.push(makeError(actual, expected, opts))\n}\n\n/**\n * @ignore\n */\nconst maxLengthCommon = function (keyword, value, schema, opts) {\n const max = schema[keyword]\n if (value.length > max) {\n return makeError(value.length, `length no more than ${max}`, opts)\n }\n}\n\n/**\n * @ignore\n */\nconst minLengthCommon = function (keyword, value, schema, opts) {\n const min = schema[keyword]\n if (value.length < min) {\n return makeError(value.length, `length no less than ${min}`, opts)\n }\n}\n\n/**\n * A map of all object member validation functions for each keyword defined in the JSON Schema.\n * @name Schema.validationKeywords\n * @type {Object}\n */\nconst validationKeywords = {\n /**\n * Validates the provided value against all schemas defined in the Schemas `allOf` keyword.\n * The instance is valid against if and only if it is valid against all the schemas declared in the Schema's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be a valid JSON Schema.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor82\n *\n * @name Schema.validationKeywords.allOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `allOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n allOf (value, schema, opts) {\n let allErrors = []\n schema.allOf.forEach(function (_schema) {\n allErrors = allErrors.concat(validate(value, _schema, opts) || [])\n })\n return allErrors.length ? allErrors : undefined\n },\n\n /**\n * Validates the provided value against all schemas defined in the Schemas `anyOf` keyword.\n * The instance is valid against this keyword if and only if it is valid against\n * at least one of the schemas in this keyword's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor85\n *\n * @name Schema.validationKeywords.anyOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `anyOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n anyOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.anyOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * http://json-schema.org/latest/json-schema-validation.html#anchor70\n *\n * @name Schema.validationKeywords.dependencies\n * @method\n * @param {*} value TODO\n * @param {Object} schema TODO\n * @param {Object} opts TODO\n */\n dependencies (value, schema, opts) {\n // TODO\n },\n\n /**\n * Validates the provided value against an array of possible values defined by the Schema's `enum` keyword\n * Validation succeeds if the value is deeply equal to one of the values in the array.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor76\n *\n * @name Schema.validationKeywords.enum\n * @method\n * @param {*} value Value to validate\n * @param {Object} schema Schema containing the `enum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n enum (value, schema, opts) {\n const possibleValues = schema['enum']\n if (utils.findIndex(possibleValues, (item) => utils.deepEqual(item, value)) === -1) {\n return makeError(value, `one of (${possibleValues.join(', ')})`, opts)\n }\n },\n\n /**\n * Validates each of the provided array values against a schema or an array of schemas defined by the Schema's `items` keyword\n * see http://json-schema.org/latest/json-schema-validation.html#anchor37 for validation rules.\n *\n * @name Schema.validationKeywords.items\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the items keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n items (value, schema, opts) {\n opts || (opts = {})\n // TODO: additionalItems\n let items = schema.items\n let errors = []\n const checkingTuple = utils.isArray(items)\n const length = value.length\n for (var prop = 0; prop < length; prop++) {\n if (checkingTuple) {\n // Validating a tuple, instead of just checking each item against the\n // same schema\n items = schema.items[prop]\n }\n opts.prop = prop\n errors = errors.concat(validate(value[prop], items, opts) || [])\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided number against a maximum value defined by the Schema's `maximum` keyword\n * Validation succeeds if the value is a number, and is less than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor17\n *\n * @name Schema.validationKeywords.maximum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `maximum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maximum (value, schema, opts) {\n // Must be a number\n const maximum = schema.maximum\n // Must be a boolean\n // Depends on maximum\n // default: false\n const exclusiveMaximum = schema.exclusiveMaximum\n if (typeof value === typeof maximum && !(exclusiveMaximum ? maximum > value : maximum >= value)) {\n return exclusiveMaximum\n ? makeError(value, `no more than nor equal to ${maximum}`, opts)\n : makeError(value, `no more than ${maximum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a maximum value defined by the Schema's `maxItems` keyword.\n * Validation succeeds if the length of the array is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor42\n *\n * @name Schema.validationKeywords.maxItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `maxItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return maxLengthCommon('maxItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a maximum value defined in the Schema's `maxLength` keyword.\n * Validation succeeds if the length of the string is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor26\n *\n * @name Schema.validationKeywords.maxLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `maxLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxLength (value, schema, opts) {\n return maxLengthCommon('maxLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a maximum value defined in the Schema's `maxProperties` keyword.\n * Validation succeeds if the object's property count is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor54\n *\n * @name Schema.validationKeywords.maxProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `maxProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const maxProperties = schema.maxProperties\n const length = Object.keys(value).length\n if (length > maxProperties) {\n return makeError(length, `no more than ${maxProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided value against a minimum value defined by the Schema's `minimum` keyword\n * Validation succeeds if the value is a number and is greater than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor21\n *\n * @name Schema.validationKeywords.minimum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `minimum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minimum (value, schema, opts) {\n // Must be a number\n const minimum = schema.minimum\n // Must be a boolean\n // Depends on minimum\n // default: false\n const exclusiveMinimum = schema.exclusiveMinimum\n if (typeof value === typeof minimum && !(exclusiveMinimum ? value > minimum : value >= minimum)) {\n return exclusiveMinimum\n ? makeError(value, `no less than nor equal to ${minimum}`, opts)\n : makeError(value, `no less than ${minimum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a minimum value defined by the Schema's `minItems` keyword.\n * Validation succeeds if the length of the array is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor45\n *\n * @name Schema.validationKeywords.minItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `minItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return minLengthCommon('minItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a minimum value defined in the Schema's `minLength` keyword.\n * Validation succeeds if the length of the string is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor29\n *\n * @name Schema.validationKeywords.minLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `minLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minLength (value, schema, opts) {\n return minLengthCommon('minLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a minimum value defined in the Schema's `minProperties` keyword.\n * Validation succeeds if the object's property count is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor57\n *\n * @name Schema.validationKeywords.minProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `minProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const minProperties = schema.minProperties\n const length = Object.keys(value).length\n if (length < minProperties) {\n return makeError(length, `no more than ${minProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided number is a multiple of the number defined in the Schema's `multipleOf` keyword.\n * Validation succeeds if the number can be divided equally into the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor14\n *\n * @name Schema.validationKeywords.multipleOf\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing the `multipleOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n multipleOf (value, schema, opts) {\n const multipleOf = schema.multipleOf\n if (utils.isNumber(value)) {\n if ((value / multipleOf) % 1 !== 0) {\n return makeError(value, `multipleOf ${multipleOf}`, opts)\n }\n }\n },\n\n /**\n * Validates the provided value is not valid with any of the schemas defined in the Schema's `not` keyword.\n * An instance is valid against this keyword if and only if it is NOT valid against the schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor91\n * @name Schema.validationKeywords.not\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the not keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n not (value, schema, opts) {\n if (!validate(value, schema.not, opts)) {\n // TODO: better messaging\n return makeError('succeeded', 'should have failed', opts)\n }\n },\n\n /**\n * Validates the provided value is valid with one and only one of the schemas defined in the Schema's `oneOf` keyword.\n * An instance is valid against this keyword if and only if it is valid against a single schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor88\n * @name Schema.validationKeywords.oneOf\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the `oneOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n oneOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.oneOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else if (validated) {\n allErrors = [makeError('valid against more than one', 'valid against only one', opts)]\n validated = false\n return false\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * Validates the provided string matches a pattern defined in the Schema's `pattern` keyword.\n * Validation succeeds if the string is a match of the regex value of this keyword.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor33\n * @name Schema.validationKeywords.pattern\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `pattern` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n pattern (value, schema, opts) {\n const pattern = schema.pattern\n if (utils.isString(value) && !value.match(pattern)) {\n return makeError(value, pattern, opts)\n }\n },\n\n /**\n * Validates the provided object's properties against a map of values defined in the Schema's `properties` keyword.\n * Validation succeeds if the object's property are valid with each of the schema's in the provided map.\n * Validation also depends on the additionalProperties and or patternProperties.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor64 for more info.\n *\n * @name Schema.validationKeywords.properties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `properties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n properties (value, schema, opts) {\n opts || (opts = {})\n // Can be a boolean or an object\n // Technically the default is an \"empty schema\", but here \"true\" is\n // functionally the same\n const additionalProperties = schema.additionalProperties === undefined ? true : schema.additionalProperties\n // \"s\": The property set of the instance to validate.\n const toValidate = {}\n // \"p\": The property set from \"properties\".\n // Default is an object\n const properties = schema.properties || {}\n // \"pp\": The property set from \"patternProperties\".\n // Default is an object\n const patternProperties = schema.patternProperties || {}\n let errors = []\n\n // Collect set \"s\"\n utils.forOwn(value, function (_value, prop) {\n toValidate[prop] = undefined\n })\n // Remove from \"s\" all elements of \"p\", if any.\n utils.forOwn(properties || {}, function (_schema, prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n delete toValidate[prop]\n })\n // For each regex in \"pp\", remove all elements of \"s\" which this regex\n // matches.\n utils.forOwn(patternProperties, function (_schema, pattern) {\n utils.forOwn(toValidate, function (undef, prop) {\n if (prop.match(pattern)) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n delete toValidate[prop]\n }\n })\n })\n const keys = Object.keys(toValidate)\n // If \"s\" is not empty, validation fails\n if (additionalProperties === false) {\n if (keys.length) {\n const origProp = opts.prop\n opts.prop = ''\n addError(`extra fields: ${keys.join(', ')}`, 'no extra fields', opts, errors)\n opts.prop = origProp\n }\n } else if (utils.isObject(additionalProperties)) {\n // Otherwise, validate according to provided schema\n keys.forEach(function (prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], additionalProperties, opts) || [])\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided object's has all properties listed in the Schema's `properties` keyword array.\n * Validation succeeds if the object contains all properties provided in the array value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor61\n *\n * @name Schema.validationKeywords.required\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `required` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n required (value, schema, opts) {\n opts || (opts = {})\n const required = schema.required\n let errors = []\n if (!opts.existingOnly) {\n required.forEach(function (prop) {\n if (utils.get(value, prop) === undefined) {\n const prevProp = opts.prop\n opts.prop = prop\n addError(undefined, 'a value', opts, errors)\n opts.prop = prevProp\n }\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided value's type is equal to the type, or array of types, defined in the Schema's `type` keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor79\n *\n * @name Schema.validationKeywords.type\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `type` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n type (value, schema, opts) {\n let type = schema.type\n let validType\n // Can be one of several types\n if (utils.isString(type)) {\n type = [type]\n }\n // Try to match the value against an expected type\n type.forEach(function (_type) {\n // TODO: throw an error if type is not defined\n if (types[_type](value, schema, opts)) {\n // Matched a type\n validType = _type\n return false\n }\n })\n // Value did not match any expected type\n if (!validType) {\n return makeError(value !== undefined && value !== null ? typeof value : '' + value, `one of (${type.join(', ')})`, opts)\n }\n // Run keyword validators for matched type\n // http://json-schema.org/latest/json-schema-validation.html#anchor12\n const validator = typeGroupValidators[validType]\n if (validator) {\n return validator(value, schema, opts)\n }\n },\n\n /**\n * Validates the provided array values are unique.\n * Validation succeeds if the items in the array are unique, but only if the value of this keyword is true\n * see http://json-schema.org/latest/json-schema-validation.html#anchor49\n *\n * @name Schema.validationKeywords.uniqueItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `uniqueItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n uniqueItems (value, schema, opts) {\n if (value && value.length && schema.uniqueItems) {\n const length = value.length\n let item, i, j\n // Check n - 1 items\n for (i = length - 1; i > 0; i--) {\n item = value[i]\n // Only compare against unchecked items\n for (j = i - 1; j >= 0; j--) {\n // Found a duplicate\n if (utils.deepEqual(item, value[j])) {\n return makeError(item, 'no duplicates', opts)\n }\n }\n }\n }\n }\n}\n\n/**\n * @ignore\n */\nconst runOps = function (ops, value, schema, opts) {\n let errors = []\n ops.forEach(function (op) {\n if (schema[op] !== undefined) {\n errors = errors.concat(validationKeywords[op](value, schema, opts) || [])\n }\n })\n return errors.length ? errors : undefined\n}\n\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\nconst STRING_OPS = ['maxLength', 'minLength', 'pattern']\n\n/**\n * http://json-schema.org/latest/json-schema-validation.html#anchor75\n * @ignore\n */\nconst validateAny = function (value, schema, opts) {\n return runOps(ANY_OPS, value, schema, opts)\n}\n\n/**\n * Validates the provided value against a given Schema according to the http://json-schema.org/ v4 specification.\n *\n * @name Schema.validate\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Valid Schema according to the http://json-schema.org/ v4 specification.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\nconst validate = function (value, schema, opts) {\n let errors = []\n opts || (opts = {})\n opts.ctx || (opts.ctx = { value, schema })\n let shouldPop\n let prevProp = opts.prop\n if (schema === undefined) {\n return\n }\n if (!utils.isObject(schema)) {\n throw utils.err(`${DOMAIN}#validate`)(500, `Invalid schema at path: \"${opts.path}\"`)\n }\n if (opts.path === undefined) {\n opts.path = []\n }\n // Track our location as we recurse\n if (opts.prop !== undefined) {\n shouldPop = true\n opts.path.push(opts.prop)\n opts.prop = undefined\n }\n // Validate against parent schema\n if (schema['extends']) {\n // opts.path = path\n // opts.prop = prop\n if (utils.isFunction(schema['extends'].validate)) {\n errors = errors.concat(schema['extends'].validate(value, opts) || [])\n } else {\n errors = errors.concat(validate(value, schema['extends'], opts) || [])\n }\n }\n if (value === undefined) {\n // Check if property is required\n if (schema.required === true && !opts.existingOnly) {\n addError(value, 'a value', opts, errors)\n }\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n }\n\n errors = errors.concat(validateAny(value, schema, opts) || [])\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n}\n\n// These strings are cached for optimal performance of the change detection\n// boolean - Whether a Record is changing in the current execution frame\nconst changingPath = 'changing'\n// string[] - Properties that have changed in the current execution frame\nconst changedPath = 'changed'\n// Object[] - History of change records\nconst changeHistoryPath = 'history'\n// boolean - Whether a Record is currently being instantiated\nconst creatingPath = 'creating'\n// number - The setTimeout change event id of a Record, if any\nconst eventIdPath = 'eventId'\n// boolean - Whether to skip validation for a Record's currently changing property\nconst noValidatePath = 'noValidate'\n// boolean - Whether to preserve Change History for a Record\nconst keepChangeHistoryPath = 'keepChangeHistory'\n// boolean - Whether to skip change notification for a Record's currently\n// changing property\nconst silentPath = 'silent'\nconst validationFailureMsg = 'validation failed'\n\n/**\n * Assemble a property descriptor which will be added to the prototype of\n * {@link Mapper#recordClass}. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @ignore\n */\nconst makeDescriptor = function (prop, schema, opts) {\n const descriptor = {\n // Better to allow configurability, but at the user's own risk\n configurable: true,\n // These properties are enumerable by default, but regardless of their\n // enumerability, they won't be \"own\" properties of individual records\n enumerable: schema.enumerable === undefined ? true : !!schema.enumerable\n }\n // Cache a few strings for optimal performance\n const keyPath = `props.${prop}`\n const previousPath = `previous.${prop}`\n const getter = opts.getter\n const setter = opts.setter\n const unsetter = opts.unsetter\n const track = utils.isBoolean(opts.track) ? opts.track : schema.track\n\n descriptor.get = function () {\n return this._get(keyPath)\n }\n\n if (utils.isFunction(schema.get)) {\n const originalGet = descriptor.get\n descriptor.get = function () {\n return schema.get.call(this, originalGet)\n }\n }\n\n descriptor.set = function (value) {\n // These are accessed a lot\n const _get = this[getter]\n const _set = this[setter]\n const _unset = this[unsetter]\n // Optionally check that the new value passes validation\n if (!_get(noValidatePath)) {\n const errors = schema.validate(value, { path: [prop] })\n if (errors) {\n // Immediately throw an error, preventing the record from getting into\n // an invalid state\n const error = new Error(validationFailureMsg)\n error.errors = errors\n throw error\n }\n }\n // TODO: Make it so tracking can be turned on for all properties instead of\n // only per-property\n if (track && !_get(creatingPath)) {\n // previous is versioned on database commit\n // props are versioned on set()\n const previous = _get(previousPath)\n const current = _get(keyPath)\n let changing = _get(changingPath)\n let changed = _get(changedPath)\n\n if (!changing) {\n // Track properties that are changing in the current event loop\n changed = []\n }\n\n // Add changing properties to this array once at most\n const index = changed.indexOf(prop)\n if (current !== value && index === -1) {\n changed.push(prop)\n }\n if (previous === value) {\n if (index >= 0) {\n changed.splice(index, 1)\n }\n }\n // No changes in current event loop\n if (!changed.length) {\n changing = false\n _unset(changingPath)\n _unset(changedPath)\n // Cancel pending change event\n if (_get(eventIdPath)) {\n clearTimeout(_get(eventIdPath))\n _unset(eventIdPath)\n }\n }\n // Changes detected in current event loop\n if (!changing && changed.length) {\n _set(changedPath, changed)\n _set(changingPath, true)\n // Saving the timeout id allows us to batch all changes in the same\n // event loop into a single \"change\"\n // TODO: Optimize\n _set(eventIdPath, setTimeout(() => {\n // Previous event loop where changes were gathered has ended, so\n // notify any listeners of those changes and prepare for any new\n // changes\n _unset(changedPath)\n _unset(eventIdPath)\n _unset(changingPath)\n // TODO: Optimize\n if (!_get(silentPath)) {\n let i\n for (i = 0; i < changed.length; i++) {\n this.emit('change:' + changed[i], this, utils.get(this, changed[i]))\n }\n\n const changes = utils.diffObjects({ [prop] : value }, { [prop] : current })\n\n if (_get(keepChangeHistoryPath)) {\n const changeRecord = utils.plainCopy(changes)\n changeRecord.timestamp = new Date().getTime()\n let changeHistory = _get(changeHistoryPath)\n !changeHistory && _set(changeHistoryPath, (changeHistory = []))\n changeHistory.push(changeRecord)\n }\n this.emit('change', this, changes)\n }\n _unset(silentPath)\n }, 0))\n }\n }\n _set(keyPath, value)\n return value\n }\n\n if (utils.isFunction(schema.set)) {\n const originalSet = descriptor.set\n descriptor.set = function (value) {\n return schema.set.call(this, value, originalSet)\n }\n }\n\n return descriptor\n}\n\n/**\n * A map of validation functions grouped by type.\n *\n * @name Schema.typeGroupValidators\n * @type {Object}\n */\nconst typeGroupValidators = {\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an array.\n * The validation keywords for the type `array` are:\n *```\n * ['items', 'maxItems', 'minItems', 'uniqueItems']\n *```\n * see http://json-schema.org/latest/json-schema-validation.html#anchor25\n *\n * @name Schema.typeGroupValidators.array\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing at least one array keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n array: function (value, schema, opts) {\n return runOps(ARRAY_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an integer.\n * The validation keywords for the type `integer` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.integer\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `integer` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n integer: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an number.\n * The validation keywords for the type `number` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.number\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `number` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n number: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of a number or integer.\n * The validation keywords for the type `numeric` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor13.\n *\n * @name Schema.typeGroupValidators.numeric\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `numeric` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n numeric: function (value, schema, opts) {\n return runOps(NUMERIC_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an object.\n * The validation keywords for the type `object` are:\n *```\n * ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor53.\n *\n * @name Schema.typeGroupValidators.object\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing at least one `object` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n object: function (value, schema, opts) {\n return runOps(OBJECT_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an string.\n * The validation keywords for the type `string` are:\n *```\n * ['maxLength', 'minLength', 'pattern']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor25.\n *\n * @name Schema.typeGroupValidators.string\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing at least one `string` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n string: function (value, schema, opts) {\n return runOps(STRING_OPS, value, schema, opts)\n }\n}\n\n/**\n * js-data's Schema class.\n *\n * @example Schema#constructor\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const PostSchema = new Schema({\n * type: 'object',\n * properties: {\n * title: { type: 'string' }\n * }\n * })\n * PostSchema.validate({ title: 1234 })\n *\n * @class Schema\n * @extends Component\n * @param {Object} definition Schema definition according to json-schema.org\n */\nfunction Schema (definition) {\n definition || (definition = {})\n // TODO: schema validation\n utils.fillIn(this, definition)\n\n if (this.type === 'object' && this.properties) {\n utils.forOwn(this.properties, (_definition, prop) => {\n if (!(_definition instanceof Schema)) {\n this.properties[prop] = new Schema(_definition)\n }\n })\n } else if (this.type === 'array' && this.items && !(this.items instanceof Schema)) {\n this.items = new Schema(this.items)\n }\n if (this.extends && !(this.extends instanceof Schema)) {\n this.extends = new Schema(this.extends)\n }\n ['allOf', 'anyOf', 'oneOf'].forEach((validationKeyword) => {\n if (this[validationKeyword]) {\n this[validationKeyword].forEach((_definition, i) => {\n if (!(_definition instanceof Schema)) {\n this[validationKeyword][i] = new Schema(_definition)\n }\n })\n }\n })\n}\n\nexport default Component.extend({\n constructor: Schema,\n\n /**\n * This adds ES5 getters/setters to the target based on the \"properties\" in\n * this Schema, which makes possible change tracking and validation on\n * property assignment.\n *\n * @name Schema#validate\n * @method\n * @param {Object} target The prototype to which to apply this schema.\n */\n apply (target, opts) {\n opts || (opts = {})\n opts.getter || (opts.getter = '_get')\n opts.setter || (opts.setter = '_set')\n opts.unsetter || (opts.unsetter = '_unset')\n opts.track || (opts.track = this.track)\n const properties = this.properties || {}\n utils.forOwn(properties, function (schema, prop) {\n Object.defineProperty(\n target,\n prop,\n makeDescriptor(prop, schema, opts)\n )\n })\n },\n\n /**\n * Apply default values to the target object for missing values.\n *\n * @name Schema#applyDefaults\n * @method\n * @param {Object} target The target to which to apply values for missing values.\n */\n applyDefaults (target) {\n if (!target) {\n return\n }\n const properties = this.properties || {}\n const hasSet = utils.isFunction(target.set) || utils.isFunction(target._set)\n utils.forOwn(properties, function (schema, prop) {\n if (schema.hasOwnProperty('default') && utils.get(target, prop) === undefined) {\n if (hasSet) {\n target.set(prop, utils.plainCopy(schema['default']), { silent: true })\n } else {\n utils.set(target, prop, utils.plainCopy(schema['default']))\n }\n }\n if (schema.type === 'object' && schema.properties) {\n if (hasSet) {\n const orig = target._get('noValidate')\n target._set('noValidate', true)\n utils.set(target, prop, utils.get(target, prop) || {}, { silent: true })\n target._set('noValidate', orig)\n } else {\n utils.set(target, prop, utils.get(target, prop) || {})\n }\n schema.applyDefaults(utils.get(target, prop))\n }\n })\n },\n\n /**\n * Create a copy of the given value that contains only the properties defined\n * in this schema.\n *\n * @name Schema#pick\n * @method\n * @param {*} value The value to copy.\n * @returns {*} The copy.\n */\n pick (value) {\n if (this.type === 'object') {\n value || (value = {})\n let copy = {}\n if (this.properties) {\n utils.forOwn(this.properties, (_definition, prop) => {\n copy[prop] = _definition.pick(value[prop])\n })\n }\n if (this.extends) {\n utils.fillIn(copy, this.extends.pick(value))\n }\n return copy\n } else if (this.type === 'array') {\n value || (value = [])\n return value.map((item) => {\n const _copy = this.items ? this.items.pick(item) : {}\n if (this.extends) {\n utils.fillIn(_copy, this.extends.pick(item))\n }\n return _copy\n })\n }\n return utils.plainCopy(value)\n },\n\n /**\n * Validate the provided value against this schema.\n *\n * @name Schema#validate\n * @method\n * @param {*} value Value to validate.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n validate (value, opts) {\n return validate(value, this, opts)\n }\n}, {\n ANY_OPS,\n ARRAY_OPS,\n NUMERIC_OPS,\n OBJECT_OPS,\n STRING_OPS,\n typeGroupValidators,\n types,\n validate,\n validationKeywords\n})\n\n/**\n * Create a subclass of this Schema:\n * @example Schema.extend\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSchemaClass extends Schema {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSchema = new CustomSchemaClass()\n * console.log(customSchema.foo())\n * console.log(CustomSchemaClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSchemaClass = Schema.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSchema = new OtherSchemaClass()\n * console.log(otherSchema.foo())\n * console.log(OtherSchemaClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSchemaClass () {\n * Schema.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Schema.extend({\n * constructor: AnotherSchemaClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSchema = new AnotherSchemaClass()\n * console.log(anotherSchema.created_at)\n * console.log(anotherSchema.foo())\n * console.log(AnotherSchemaClass.beep())\n *\n * @method Schema.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Schema class.\n * @since 3.0.0\n */\n\n","import utils from './utils'\nimport Component from './Component'\nimport Record from './Record'\nimport Schema from './Schema'\nimport { Relation } from './relations'\nimport {\n belongsTo,\n belongsToType,\n hasMany,\n hasManyType,\n hasOne,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Mapper'\nconst applyDefaultsHooks = [\n 'beforeCreate',\n 'beforeCreateMany'\n]\nconst validatingHooks = [\n 'beforeCreate',\n 'beforeCreateMany',\n 'beforeUpdate',\n 'beforeUpdateAll',\n 'beforeUpdateMany'\n]\nconst makeNotify = function (num) {\n return function (...args) {\n const opts = args[args.length - num]\n const op = opts.op\n this.dbg(op, ...args)\n\n if (applyDefaultsHooks.indexOf(op) !== -1 && opts.applyDefaults !== false) {\n const schema = this.getSchema()\n if (schema && schema.applyDefaults) {\n let toProcess = args[0]\n if (!utils.isArray(toProcess)) {\n toProcess = [toProcess]\n }\n toProcess.forEach((record) => {\n schema.applyDefaults(record)\n })\n }\n }\n\n // Automatic validation\n if (validatingHooks.indexOf(op) !== -1 && !opts.noValidate) {\n // Save current value of option\n const originalExistingOnly = opts.existingOnly\n\n // For updates, ignore required fields if they aren't present\n if (op.indexOf('beforeUpdate') === 0 && opts.existingOnly === undefined) {\n opts.existingOnly = true\n }\n const errors = this.validate(args[op === 'beforeUpdate' ? 1 : 0], utils.pick(opts, ['existingOnly']))\n\n // Restore option\n opts.existingOnly = originalExistingOnly\n\n // Abort lifecycle due to validation errors\n if (errors) {\n const err = new Error('validation failed')\n err.errors = errors\n return utils.reject(err)\n }\n }\n\n // Emit lifecycle event\n if (opts.notify || (opts.notify === undefined && this.notify)) {\n setTimeout(() => {\n this.emit(op, ...args)\n })\n }\n }\n}\n\n// These are the default implementations of all of the lifecycle hooks\nconst notify = makeNotify(1)\nconst notify2 = makeNotify(2)\n\n// This object provides meta information used by Mapper#crud to actually\n// execute each lifecycle method\nconst LIFECYCLE_METHODS = {\n count: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroy: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroyAll: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n find: {\n defaults: [undefined, {}],\n types: []\n },\n findAll: {\n defaults: [{}, {}],\n types: []\n },\n sum: {\n defaults: [undefined, {}, {}],\n skip: true,\n types: []\n },\n update: {\n adapterArgs (mapper, id, props, opts) {\n return [id, mapper.toJSON(props, opts), opts]\n },\n beforeAssign: 1,\n defaults: [undefined, {}, {}],\n types: []\n },\n updateAll: {\n adapterArgs (mapper, props, query, opts) {\n return [mapper.toJSON(props, opts), query, opts]\n },\n beforeAssign: 0,\n defaults: [{}, {}, {}],\n types: []\n },\n updateMany: {\n adapterArgs (mapper, records, opts) {\n return [records.map((record) => mapper.toJSON(record, opts)), opts]\n },\n beforeAssign: 0,\n defaults: [[], {}],\n types: []\n }\n}\n\nconst MAPPER_DEFAULTS = {\n /**\n * Hash of registered adapters. Don't modify directly. Use\n * {@link Mapper#registerAdapter} instead.\n *\n * @default {}\n * @name Mapper#_adapters\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n _adapters: {},\n\n /**\n * Whether {@link Mapper#beforeCreate} and {@link Mapper#beforeCreateMany}\n * should automatically receive default values according to the Mapper's schema.\n *\n * @default true\n * @name Mapper#applyDefaults\n * @since 3.0.0\n * @type {boolean}\n */\n applyDefaults: true,\n\n /**\n * Whether to augment {@link Mapper#recordClass} with ES5 getters and setters\n * according to the properties defined in {@link Mapper#schema}. This makes\n * possible validation and change tracking on individual properties\n * when using the dot (e.g. `user.name = \"Bob\"`) operator to modify a\n * property, and is `true` by default.\n *\n * @default true\n * @name Mapper#applySchema\n * @since 3.0.0\n * @type {boolean}\n */\n applySchema: true,\n\n /**\n * The name of the registered adapter that this Mapper should used by default.\n *\n * @default \"http\"\n * @name Mapper#defaultAdapter\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n * @type {string}\n */\n defaultAdapter: 'http',\n\n /**\n * The field used as the unique identifier on records handled by this Mapper.\n *\n * @default id\n * @name Mapper#idAttribute\n * @since 3.0.0\n * @type {string}\n */\n idAttribute: 'id',\n\n /**\n * Whether records created from this mapper keep changeHistory on property changes.\n *\n * @default true\n * @name Mapper#keepChangeHistory\n * @since 3.0.0\n * @type {boolean}\n */\n keepChangeHistory: true,\n\n /**\n * Whether this Mapper should emit operational events.\n *\n * @default true\n * @name Mapper#notify\n * @since 3.0.0\n * @type {boolean}\n */\n notify: true,\n\n /**\n * Whether to skip validation when the Record instances are created.\n *\n * @default false\n * @name Mapper#noValidate\n * @since 3.0.0\n * @type {boolean}\n */\n noValidate: false,\n\n /**\n * Whether {@link Mapper#create}, {@link Mapper#createMany},\n * {@link Mapper#update}, {@link Mapper#updateAll}, {@link Mapper#updateMany},\n * {@link Mapper#find}, {@link Mapper#findAll}, {@link Mapper#destroy},\n * {@link Mapper#destroyAll}, {@link Mapper#count}, and {@link Mapper#sum}\n * should return a raw result object that contains both the instance data\n * returned by the adapter _and_ metadata about the operation.\n *\n * The default is to NOT return the result object, and instead return just the\n * instance data.\n *\n * @default false\n * @name Mapper#raw\n * @since 3.0.0\n * @type {boolean}\n */\n raw: false,\n\n /**\n * Whether records created from this mapper automatically validate their properties\n * when their properties are modified.\n *\n * @default true\n * @name Mapper#validateOnSet\n * @since 3.0.0\n * @type {boolean}\n */\n validateOnSet: true\n}\n\n/**\n * The core of JSData's [ORM/ODM][orm] implementation. Given a minimum amout of\n * meta information about a resource, a Mapper can perform generic CRUD\n * operations against that resource. Apart from its configuration, a Mapper is\n * stateless. The particulars of various persistence layers have been abstracted\n * into adapters, which a Mapper uses to perform its operations.\n *\n * The term \"Mapper\" comes from the [Data Mapper Pattern][pattern] described in\n * Martin Fowler's [Patterns of Enterprise Application Architecture][book]. A\n * Data Mapper moves data between [in-memory object instances][record] and a\n * relational or document-based database. JSData's Mapper can work with any\n * persistence layer you can write an adapter for.\n *\n * _(\"Model\" is a heavily overloaded term and is avoided in this documentation\n * to prevent confusion.)_\n *\n * [orm]: https://en.wikipedia.org/wiki/Object-relational_mapping\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\n *\n * @example\n * // Import and instantiate\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @example\n * // Define a Mapper using the Container component\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @class Mapper\n * @extends Component\n * @param {Object} opts Configuration options.\n * @param {boolean} [opts.applySchema=true] See {@link Mapper#applySchema}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {string} [opts.defaultAdapter=http] See {@link Mapper#defaultAdapter}.\n * @param {string} [opts.idAttribute=id] See {@link Mapper#idAttribute}.\n * @param {Object} [opts.methods] See {@link Mapper#methods}.\n * @param {string} opts.name See {@link Mapper#name}.\n * @param {boolean} [opts.notify] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw=false] See {@link Mapper#raw}.\n * @param {Function|boolean} [opts.recordClass] See {@link Mapper#recordClass}.\n * @param {Object|Schema} [opts.schema] See {@link Mapper#schema}.\n * @returns {Mapper} A new {@link Mapper} instance.\n * @see http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n */\nfunction Mapper (opts) {\n utils.classCallCheck(this, Mapper)\n Component.call(this)\n opts || (opts = {})\n\n // Prepare certain properties to be non-enumerable\n Object.defineProperties(this, {\n _adapters: {\n value: undefined,\n writable: true\n },\n\n /**\n * The {@link Container} that holds this Mapper. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n datastore: {\n value: undefined,\n writable: true\n },\n\n /**\n * The meta information describing this Mapper's available lifecycle\n * methods. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n lifecycleMethods: {\n value: LIFECYCLE_METHODS\n },\n\n /**\n * Set to `false` to force the Mapper to work with POJO objects only.\n *\n * @example\n * // Use POJOs only.\n * import {Mapper, Record} from 'js-data'\n * const UserMapper = new Mapper({ recordClass: false })\n * UserMapper.recordClass // false\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n *\n * @example\n * // Set to a custom class to have records wrapped in your custom class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User {\n * constructor (props = {}) {\n * for (var key in props) {\n * if (props.hasOwnProperty(key)) {\n * this[key] = props[key]\n * }\n * }\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n * user instanceof User // true\n *\n *\n * @example\n * // Extend the {@link Record} class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User extends Record {\n * constructor () {\n * super(props)\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // true\n * user instanceof User // true\n *\n * @name Mapper#recordClass\n * @default {@link Record}\n * @see Record\n * @since 3.0.0\n */\n recordClass: {\n value: undefined,\n writable: true\n },\n\n /**\n * This Mapper's {@link Schema}.\n *\n * @example Mapper#schema\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const UserMapper = new Mapper({\n * name: 'user',\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * first: { type: 'string', track: true },\n * last: { type: 'string', track: true },\n * role: { type: 'string', track: true, required: true },\n * age: { type: 'integer', track: true },\n * is_active: { type: 'number' }\n * }\n * }\n * })\n * const user = UserMapper.createRecord({\n * id: 1,\n * name: 'John',\n * role: 'admin'\n * })\n * user.on('change', function (user, changes) {\n * console.log(changes)\n * })\n * user.on('change:role', function (user, value) {\n * console.log('change:role - ' + value)\n * })\n * user.role = 'owner'\n *\n * @name Mapper#schema\n * @see Schema\n * @since 3.0.0\n * @type {Schema}\n */\n schema: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(MAPPER_DEFAULTS))\n\n /**\n * The name for this Mapper. This is the minimum amount of meta information\n * required for a Mapper to be able to execute CRUD operations for a\n * Resource.\n *\n * @name Mapper#name\n * @since 3.0.0\n * @type {string}\n */\n if (!this.name) {\n throw utils.err(`new ${DOMAIN}`, 'opts.name')(400, 'string', this.name)\n }\n\n // Setup schema, with an empty default schema if necessary\n if (this.schema) {\n this.schema.type || (this.schema.type = 'object')\n }\n if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\n\n // Create a subclass of Record that's tied to this Mapper\n if (this.recordClass === undefined) {\n const superClass = Record\n this.recordClass = superClass.extend({\n constructor: (function Record () {\n var subClass = function Record (props, opts) {\n utils.classCallCheck(this, subClass)\n superClass.call(this, props, opts)\n }\n return subClass\n })()\n })\n }\n\n if (this.recordClass) {\n this.recordClass.mapper = this\n\n /**\n * Functions that should be added to the prototype of {@link Mapper#recordClass}.\n *\n * @name Mapper#methods\n * @since 3.0.0\n * @type {Object}\n */\n if (utils.isObject(this.methods)) {\n utils.addHiddenPropsToTarget(this.recordClass.prototype, this.methods)\n }\n\n // We can only apply the schema to the prototype of this.recordClass if the\n // class extends Record\n if (Record.prototype.isPrototypeOf(Object.create(this.recordClass.prototype)) && this.schema && this.schema.apply && this.applySchema) {\n this.schema.apply(this.recordClass.prototype)\n }\n }\n}\n\nexport default Component.extend({\n constructor: Mapper,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCount: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroy: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroyAll\n * @param {*} data The `data` returned by the adapter.\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroyAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFind: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFindAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterSum\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterSum: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @since 3.0.0\n */\n beforeCreate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @since 3.0.0\n */\n beforeCreateMany: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @since 3.0.0\n */\n beforeCount: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @since 3.0.0\n */\n beforeDestroy: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroyAll\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @since 3.0.0\n */\n beforeDestroyAll: notify,\n\n /**\n * Mappers lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @since 3.0.0\n */\n beforeFind: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @since 3.0.0\n */\n beforeFindAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeSum\n * @param {string} field The `field` argument passed to {@link Mapper#sum}.\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @since 3.0.0\n */\n beforeSum: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @since 3.0.0\n */\n beforeUpdate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @since 3.0.0\n */\n beforeUpdateAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @since 3.0.0\n */\n beforeUpdateMany: notify,\n\n /**\n * This method is called at the end of most lifecycle methods. It does the\n * following:\n *\n * 1. If `opts.raw` is `true`, add this Mapper's configuration to the `opts`\n * argument as metadata for the operation.\n * 2. Wrap the result data appropriately using {@link Mapper#wrap}, which\n * calls {@link Mapper#createRecord}.\n *\n * @method Mapper#_end\n * @private\n * @since 3.0.0\n */\n _end (result, opts, skip) {\n if (opts.raw) {\n utils._(result, opts)\n }\n if (skip) {\n return result\n }\n let _data = opts.raw ? result.data : result\n if (_data && utils.isFunction(this.wrap)) {\n _data = this.wrap(_data, opts)\n if (opts.raw) {\n result.data = _data\n } else {\n result = _data\n }\n }\n return result\n },\n\n /**\n * Define a belongsTo relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * PostMapper.belongsTo(UserMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to post records at \"post.user\"\n * localField: 'user'\n * })\n *\n * CommentMapper.belongsTo(UserMapper, {\n * // comment.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to comment records at \"comment.user\"\n * localField: 'user'\n * })\n * CommentMapper.belongsTo(PostMapper, {\n * // comment.post_id points to post.id\n * foreignKey: 'post_id'\n * // post records will be attached to comment records at \"comment.post\"\n * localField: 'post'\n * })\n *\n * @method Mapper#belongsTo\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n belongsTo (relatedMapper, opts) {\n return belongsTo(relatedMapper, opts)(this)\n },\n\n /**\n * Select records according to the `query` argument and return the count.\n *\n * {@link Mapper#beforeCount} will be called before calling the adapter.\n * {@link Mapper#afterCount} will be called after calling the adapter.\n *\n * @example\n * // Get the number of published blog posts\n * PostMapper.count({ status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Mapper#count\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `count` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the count of the selected records.\n * @since 3.0.0\n */\n count (query, opts) {\n return this.crud('count', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~beforeCreateListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreate\n * @see Mapper~beforeCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Mapper~beforeCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeCreate}.\n * @see Mapper#event:beforeCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~afterCreateListener} for how to listen for this event.\n *\n * @event Mapper#afterCreate\n * @see Mapper~afterCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Mapper~afterCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterCreate}.\n * @see Mapper#event:afterCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Create and save a new the record using the provided `props`.\n *\n * {@link Mapper#beforeCreate} will be called before calling the adapter.\n * {@link Mapper#afterCreate} will be called after calling the adapter.\n *\n * @example\n * // Create and save a new blog post\n * PostMapper.create({\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#create\n * @param {Object} props The properties for the new record.\n * @param {Object} [opts] Configuration options. Refer to the `create` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `props` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#create}\n * or {@link Mapper#createMany} call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created record.\n * @since 3.0.0\n */\n create (props, opts) {\n let op, adapter\n // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n const originalRecord = props\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return utils.resolve(this[op](props, opts)).then((_props) => {\n // Allow for re-assignment from lifecycle hook\n props = _props === undefined ? props : _props\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n const relatedMapper = def.getRelation()\n const relatedIdAttribute = relatedMapper.idAttribute\n optsCopy.raw = false\n if (!relationData) {\n return\n }\n if (def.type === belongsToType) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(relatedMapper.create(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n def.setForeignKey(props, data)\n }))\n } else if (def.type === hasManyType && def.localKeys) {\n // Create his hasMany relation first because it uses localKeys\n tasks.push(relatedMapper.createMany(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n utils.set(props, def.localKeys, data.map((record) => utils.get(record, relatedIdAttribute)))\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter for the main create\n op = opts.op = 'create'\n this.dbg(op, props, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, this.toJSON(props, { with: opts.pass || [] }), opts))\n }).then((result) => {\n const createdRecordData = opts.raw ? result.data : result\n\n // Deep post-create hasMany and hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n if (!relationData) {\n return\n }\n optsCopy.raw = false\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType && def.foreignKey) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === hasOneType) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().create(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === belongsToType && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n } else if (def.type === hasManyType && def.localKeys && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n if (opts.raw) {\n result.data = originalRecord\n } else {\n result = originalRecord\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return utils.resolve(this[op](props, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Use {@link Mapper#createRecord} instead.\n * @deprecated\n * @method Mapper#createInstance\n * @param {Object|Array} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Object|Array} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n createInstance (props, opts) {\n return this.createRecord(props, opts)\n },\n\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreateMany\n * @see Mapper~beforeCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Mapper~beforeCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Mapper#event:beforeCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~afterCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterCreateMany\n * @see Mapper~afterCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Mapper~afterCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Mapper#event:afterCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Given an array of records, batch create them via an adapter.\n *\n * {@link Mapper#beforeCreateMany} will be called before calling the adapter.\n * {@link Mapper#afterCreateMany} will be called after calling the adapter.\n *\n * @example\n * // Create and save several new blog posts\n * PostMapper.createMany([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#createMany\n * @param {Record[]} records Array of records to be created in one batch.\n * @param {Object} [opts] Configuration options. Refer to the `createMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `records` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#createMany}\n * call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created records.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n createMany (records, opts) {\n let op, adapter\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n const originalRecords = records\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return utils.resolve(this[op](records, opts)).then((_records) => {\n // Allow for re-assignment from lifecycle hook\n records = _records === undefined ? records : _records\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (def.type === belongsToType && relationData.length === records.length) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(def.getRelation().createMany(relationData, optsCopy).then((data) => {\n const relatedRecords = optsCopy.raw ? data.data : data\n def.setLocalField(belongsToRelationData, relatedRecords)\n records.forEach((record, i) => {\n def.setForeignKey(record, relatedRecords[i])\n })\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'createMany'\n const json = records.map((record) => this.toJSON(record, { with: opts.pass || [] }))\n this.dbg(op, records, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, json, opts))\n }).then((result) => {\n const createdRecordsData = opts.raw ? result.data : result\n\n // Deep post-create hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (relationData.length !== records.length) {\n return\n }\n const belongsToData = def.getLocalField(belongsToRelationData)\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType) {\n // Not supported\n this.log('warn', 'deep createMany of hasMany type not supported!')\n } else if (def.type === hasOneType) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setForeignKey(createdRecordData, relationData[i])\n })\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n const relatedData = opts.raw ? result.data : result\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, relatedData[i])\n })\n })\n } else if (def.type === belongsToType && belongsToData && belongsToData.length === createdRecordsData.length) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, belongsToData[i])\n })\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n createdRecordsData.forEach((createdRecordData, i) => {\n const originalRecord = originalRecords[i]\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n })\n if (opts.raw) {\n result.data = originalRecords\n } else {\n result = originalRecords\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return utils.resolve(this[op](records, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Create an unsaved, uncached instance of this Mapper's\n * {@link Mapper#recordClass}.\n *\n * Returns `props` if `props` is already an instance of\n * {@link Mapper#recordClass}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * const post = PostMapper.createRecord()\n *\n * @example\n * // Create an unsaved record instance with inital properties\n * const post = PostMapper.createRecord({\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create a record instance that corresponds to a saved record\n * const post = PostMapper.createRecord({\n * // JSData thinks this record has been saved if it has a primary key\n * id: 1234,\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create record instances from an array\n * const posts = PostMapper.createRecord([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }])\n *\n * @example\n * // Records are validated by default\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * try {\n * const post = PostMapper.createRecord({\n * title: 1234,\n * })\n * } catch (err) {\n * console.log(err.errors) // [{ expected: 'one of (string)', actual: 'number', path: 'title' }]\n * }\n *\n * @example\n * // Skip validation\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * const post = PostMapper.createRecord({\n * title: 1234,\n * }, { noValidate: true })\n * console.log(post.isValid()) // false\n *\n * @method Mapper#createRecord\n * @param {Object|Object[]} props The properties for the Record instance or an\n * array of property objects for the Record instances.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @returns {Record|Record[]} The Record instance or Record instances.\n * @since 3.0.0\n */\n createRecord (props, opts) {\n props || (props = {})\n if (utils.isArray(props)) {\n return props.map((_props) => this.createRecord(_props, opts))\n }\n if (!utils.isObject(props)) {\n throw utils.err(`${DOMAIN}#createRecord`, 'props')(400, 'array or object', props)\n }\n const RecordCtor = this.recordClass\n const relationList = this.relationList || []\n relationList.forEach((def) => {\n const relatedMapper = def.getRelation()\n const relationData = def.getLocalField(props)\n if (relationData && !relatedMapper.is(relationData)) {\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n utils.set(props, def.localField, relatedMapper.createRecord(relationData, opts))\n }\n })\n // Check to make sure \"props\" is not already an instance of this Mapper.\n if (RecordCtor && (!(props instanceof RecordCtor))) {\n return new RecordCtor(props, opts)\n }\n return props\n },\n\n /**\n * Lifecycle invocation method. You probably won't call this method directly.\n *\n * @method Mapper#crud\n * @param {string} method Name of the lifecycle method to invoke.\n * @param {...*} args Arguments to pass to the lifecycle method.\n * @returns {Promise}\n * @since 3.0.0\n */\n crud (method, ...args) {\n const config = this.lifecycleMethods[method]\n if (!config) {\n throw utils.err(`${DOMAIN}#crud`, method)(404, 'method')\n }\n\n const upper = `${method.charAt(0).toUpperCase()}${method.substr(1)}`\n const before = `before${upper}`\n const after = `after${upper}`\n\n let op, adapter\n\n // Default values for arguments\n config.defaults.forEach((value, i) => {\n if (args[i] === undefined) {\n args[i] = utils.copy(value)\n }\n })\n\n const opts = args[args.length - 1]\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // before lifecycle hook\n op = opts.op = before\n return utils.resolve(this[op](...args)).then((_value) => {\n if (args[config.beforeAssign] !== undefined) {\n // Allow for re-assignment from lifecycle hook\n args[config.beforeAssign] = _value === undefined ? args[config.beforeAssign] : _value\n }\n // Now delegate to the adapter\n op = opts.op = method\n args = config.adapterArgs ? config.adapterArgs(this, ...args) : args\n this.dbg(op, ...args)\n return utils.resolve(this.getAdapter(adapter)[op](this, ...args))\n }).then((result) => {\n result = this._end(result, opts, !!config.skip)\n args.push(result)\n // after lifecycle hook\n op = opts.op = after\n return utils.resolve(this[op](...args)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~beforeDestroyListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroy\n * @see Mapper~beforeDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Mapper~beforeDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroy}.\n * @see Mapper#event:beforeDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~afterDestroyListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroy\n * @see Mapper~afterDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Mapper~afterDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroy}.\n * @see Mapper#event:afterDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Using an adapter, destroy the record with the given primary key.\n *\n * {@link Mapper#beforeDestroy} will be called before destroying the record.\n * {@link Mapper#afterDestroy} will be called after destroying the record.\n *\n * @example\n * // Destroy a specific blog post\n * PostMapper.destroy(1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @example\n * // Get full response\n * PostMapper.destroy(1234, { raw: true }).then((result) => {\n * console.log(result.deleted) e.g. 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroy\n * @fires Mapper#afterDestroy\n * @method Mapper#destroy\n * @param {(string|number)} id The primary key of the record to destroy.\n * @param {Object} [opts] Configuration options. Refer to the `destroy` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the record has been destroyed. Resolves\n * even if no record was found to be destroyed.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroy (id, opts) {\n return this.crud('destroy', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroyAll\n * @see Mapper~beforeDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Mapper~beforeDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroyAll}.\n * @see Mapper#event:beforeDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroyAll\n * @see Mapper~afterDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Mapper~afterDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroyAll}.\n * @see Mapper#event:afterDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Destroy the records selected by `query` via an adapter. If no `query` is\n * provided then all records will be destroyed.\n *\n * {@link Mapper#beforeDestroyAll} will be called before destroying the records.\n * {@link Mapper#afterDestroyAll} will be called after destroying the records.\n *\n * @example\n * // Destroy all blog posts\n * PostMapper.destroyAll().then(() => {\n * // All blog posts have been destroyed\n * })\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * PostMapper.destroyAll({ status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @example\n * // Get full response\n * const query = null\n * const options = { raw: true }\n * PostMapper.destroyAll(query, options).then((result) => {\n * console.log(result.deleted) e.g. 14\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroyAll\n * @fires Mapper#afterDestroyAll\n * @method Mapper#destroyAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `destroyAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the records have been destroyed. Resolves\n * even if no records were found to be destroyed.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroyAll (query, opts) {\n return this.crud('destroyAll', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~beforeFindListener} for how to listen for this event.\n *\n * @event Mapper#beforeFind\n * @see Mapper~beforeFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Mapper~beforeFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFind}.\n * @see Mapper#event:beforeFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~afterFindListener} for how to listen for this event.\n *\n * @event Mapper#afterFind\n * @see Mapper~afterFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFind} event.\n *\n * @example\n * function onAfterFind (id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Mapper~afterFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFind}.\n * @see Mapper#event:afterFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Retrieve via an adapter the record with the given primary key.\n *\n * {@link Mapper#beforeFind} will be called before calling the adapter.\n * {@link Mapper#afterFind} will be called after calling the adapter.\n *\n * @example\n * PostMapper.find(1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @example\n * // Get full response\n * PostMapper.find(1, { raw: true }).then((result) => {\n * console.log(result.data) // { id: 1, ...}\n * console.log(result.found) // 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFind\n * @fires Mapper#afterFind\n * @method Mapper#find\n * @param {(string|number)} id The primary key of the record to retrieve.\n * @param {Object} [opts] Configuration options. Refer to the `find` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found record. Resolves with\n * `undefined` if no record was found.\n * @see http://www.js-data.io/v3.0/docs/reading-data\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n find (id, opts) {\n return this.crud('find', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~beforeFindAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeFindAll\n * @see Mapper~beforeFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Mapper~beforeFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFindAll}.\n * @see Mapper#event:beforeFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~afterFindAllListener} for how to listen for this event.\n *\n * @event Mapper#afterFindAll\n * @see Mapper~afterFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Mapper~afterFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFindAll}.\n * @see Mapper#event:afterFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, select records to retrieve via an adapter.\n *\n * {@link Mapper#beforeFindAll} will be called before calling the adapter.\n * {@link Mapper#afterFindAll} will be called after calling the adapter.\n *\n * @example\n * // Find all \"published\" blog posts\n * PostMapper.findAll({ status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, status: 'published', ...}, ...]\n * })\n *\n * @example\n * // Get full response\n * PostMapper.findAll({ status: 'published' }, { raw: true }).then((result) => {\n * console.log(result.data) // [{ id: 1, status: 'published', ...}, ...]\n * console.log(result.found) // e.g. 13\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFindAll\n * @fires Mapper#afterFindAll\n * @method Mapper#findAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `findAll` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n findAll (query, opts) {\n return this.crud('findAll', query, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Mapper#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapter (name) {\n this.dbg('getAdapter', 'name:', name)\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Mapper#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || opts.defaultAdapter\n },\n\n /**\n * Get the object of registered adapters for this Mapper.\n *\n * @method Mapper#getAdapters\n * @returns {Object} {@link Mapper#_adapters}\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Returns this Mapper's {@link Schema}.\n *\n * @method Mapper#getSchema\n * @returns {Schema} This Mapper's {@link Schema}.\n * @see Mapper#schema\n * @since 3.0.0\n */\n getSchema () {\n return this.schema\n },\n\n /**\n * Defines a hasMany relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * UserMapper.hasMany(PostMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // post records will be attached to user records at \"user.posts\"\n * localField: 'posts'\n * })\n *\n * @method Mapper#hasMany\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasMany (relatedMapper, opts) {\n return hasMany(relatedMapper, opts)(this)\n },\n\n /**\n * Defines a hasOne relationship. Only useful if you're managing your Mappers\n * manually and not using a {@link Container} or {@link DataStore} component.\n *\n * @example\n * UserMapper.hasOne(ProfileMapper, {\n * // profile.user_id points to user.id\n * foreignKey: 'user_id'\n * // profile records will be attached to user records at \"user.profile\"\n * localField: 'profile'\n * })\n *\n * @method Mapper#hasOne\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasOne (relatedMapper, opts) {\n return hasOne(relatedMapper, opts)(this)\n },\n\n /**\n * Return whether `record` is an instance of this Mapper's recordClass.\n *\n * @example\n * const post = PostMapper.createRecord()\n *\n * console.log(PostMapper.is(post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof PostMapper.recordClass) // true\n *\n * @method Mapper#is\n * @param {Object|Record} record The record to check.\n * @returns {boolean} Whether `record` is an instance of this Mapper's\n * {@link Mapper#recordClass}.\n * @since 3.0.0\n */\n is (record) {\n const recordClass = this.recordClass\n return recordClass ? record instanceof recordClass : false\n },\n\n /**\n * Register an adapter on this Mapper under the given name.\n *\n * @method Mapper#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for this Mapper.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.defaultAdapter = name\n }\n },\n\n /**\n * Select records according to the `query` argument, and aggregate the sum\n * value of the property specified by `field`.\n *\n * {@link Mapper#beforeSum} will be called before calling the adapter.\n * {@link Mapper#afterSum} will be called after calling the adapter.\n *\n * @example\n * PurchaseOrderMapper.sum('amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Mapper#sum\n * @param {string} field The field to sum.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `sum` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the aggregated sum.\n * @since 3.0.0\n */\n sum (field, query, opts) {\n return this.crud('sum', field, query, opts)\n },\n\n /**\n * Return a plain object representation of the given record. Relations can\n * be optionally be included. Non-schema properties can be excluded.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = PersonMapper.createRecord({ id: 1, name: 'John', foo: 'bar' })\n * console.log(PersonMapper.toJSON(person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(PersonMapper.toJSON(person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Mapper#toJSON\n * @param {Record|Record[]} records Record or records from which to create a\n * POJO representation.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the POJO representation.\n * @param {boolean} [opts.withAll] Whether to simply include all relations in\n * the representation. Overrides `opts.with`.\n * @returns {Object|Object[]} POJO representation of the record or records.\n * @since 3.0.0\n */\n toJSON (records, opts) {\n let record\n opts || (opts = {})\n if (utils.isArray(records)) {\n return records.map((record) => this.toJSON(record, opts))\n } else {\n record = records\n }\n const relationFields = (this ? this.relationFields : []) || []\n let json = {}\n let properties\n\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n properties = this.schema.properties\n }\n properties || (properties = {})\n\n // Optionally copy properties not defined in the schema\n if (!opts.strict) {\n for (var key in record) {\n if (!properties[key] && relationFields.indexOf(key) === -1) {\n json[key] = utils.plainCopy(record[key])\n }\n }\n }\n\n // The user wants to include relations in the resulting plain object representation\n if (this && opts.withAll) {\n opts.with = relationFields.slice()\n }\n if (this && opts.with) {\n if (utils.isString(opts.with)) {\n opts.with = [opts.with]\n }\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(record)\n if (relationData) {\n // The actual recursion\n if (utils.isArray(relationData)) {\n def.setLocalField(json, relationData.map((item) => {\n return def.getRelation().toJSON(item, optsCopy)\n }))\n } else {\n def.setLocalField(json, def.getRelation().toJSON(relationData, optsCopy))\n }\n }\n })\n }\n return json\n },\n\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~beforeUpdateListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdate\n * @see Mapper~beforeUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Mapper~beforeUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeUpdate}.\n * @see Mapper#event:beforeUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~afterUpdateListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdate\n * @see Mapper~afterUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Mapper~afterUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterUpdate}.\n * @see Mapper#event:afterUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Using an adapter, update the record with the primary key specified by the\n * `id` argument.\n *\n * {@link Mapper#beforeUpdate} will be called before updating the record.\n * {@link Mapper#afterUpdate} will be called after updating the record.\n *\n * @example\n * // Update a specific post\n * PostMapper.update(1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Mapper#beforeUpdate\n * @fires Mapper#afterUpdate\n * @method Mapper#update\n * @param {(string|number)} id The primary key of the record to update.\n * @param {Object} props The update to apply to the record.\n * @param {Object} [opts] Configuration options. Refer to the `update` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * transaction.\n * @returns {Promise} Resolves with the updated record. Rejects if the record\n * could not be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n update (id, props, opts) {\n return this.crud('update', id, props, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateAll\n * @see Mapper~beforeUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Mapper~beforeUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Mapper#event:beforeUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateAll\n * @see Mapper~afterUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Mapper~afterUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Mapper#event:afterUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, perform the a single updated to the selected\n * records.\n *\n * {@link Mapper#beforeUpdateAll} will be called before making the update.\n * {@link Mapper#afterUpdateAll} will be called after making the update.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * PostMapper.updateAll(update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateAll\n * @fires Mapper#afterUpdateAll\n * @method Mapper#updateAll\n * @param {Object} props Update to apply to selected records.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `updateAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the update records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateAll (props, query, opts) {\n return this.crud('updateAll', props, query, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateMany\n * @see Mapper~beforeUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Mapper~beforeUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Mapper#event:beforeUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateMany\n * @see Mapper~afterUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Mapper~afterUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Mapper#event:afterUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Given an array of updates, perform each of the updates via an adapter. Each\n * \"update\" is a hash of properties with which to update an record. Each\n * update must contain the primary key of the record to be updated.\n *\n * {@link Mapper#beforeUpdateMany} will be called before making the update.\n * {@link Mapper#afterUpdateMany} will be called after making the update.\n *\n * @example\n * PostMapper.updateMany([\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateMany\n * @fires Mapper#afterUpdateMany\n * @method Mapper#updateMany\n * @param {Record[]} records Array up record updates.\n * @param {Object} [opts] Configuration options. Refer to the `updateMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the updated records. Rejects if any of the\n * records could be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateMany (records, opts) {\n return this.crud('updateMany', records, opts)\n },\n\n /**\n * Validate the given record or records according to this Mapper's\n * {@link Schema}. If there are no validation errors then the return value\n * will be `undefined`.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonSchema = new Schema({\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * })\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: PersonSchema\n * })\n * let errors = PersonMapper.validate({ name: 'John' })\n * console.log(errors) // undefined\n * errors = PersonMapper.validate({ name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Mapper#validate\n * @param {Object|Object[]} record The record or records to validate.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Schema#validate}.\n * @returns {Object[]} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (record, opts) {\n opts || (opts = {})\n const schema = this.getSchema()\n const _opts = utils.pick(opts, ['existingOnly'])\n if (utils.isArray(record)) {\n const errors = record.map((_record) => schema.validate(_record, utils.pick(_opts, ['existingOnly'])))\n const foundErrors = errors.filter((err) => err)\n if (foundErrors.length) {\n return errors\n }\n return undefined\n }\n return schema.validate(record, _opts)\n },\n\n /**\n * Method used to wrap data returned by an adapter with this Mapper's\n * {@link Mapper#recordClass}. This method is used by all of a Mapper's CRUD\n * methods. The provided implementation of this method assumes that the `data`\n * passed to it is a record or records that need to be wrapped with\n * {@link Mapper#createRecord}. Override with care.\n *\n * Provided implementation of {@link Mapper#wrap}:\n *\n * ```\n * function (data, opts) {\n * return this.createRecord(data, opts)\n * }\n * ```\n *\n * @example\n * const PostMapper = new Mapper({\n * name: 'post',\n * // Override to customize behavior\n * wrap (data, opts) {\n * const originalWrap = this.constructor.prototype.wrap\n * // Let's say \"GET /post\" doesn't return JSON quite like JSData expects,\n * // but the actual post records are nested under a \"posts\" field. So,\n * // we override Mapper#wrap to handle this special case.\n * if (opts.op === 'findAll') {\n * return originalWrap.call(this, data.posts, opts)\n * }\n * // Otherwise perform original behavior\n * return originalWrap.call(this, data, opts)\n * }\n * })\n *\n * @method Mapper#wrap\n * @param {Object|Object[]} data The record or records to be wrapped.\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#createRecord}.\n * @returns {Record|Record[]} The wrapped record or records.\n * @since 3.0.0\n */\n wrap (data, opts) {\n return this.createRecord(data, opts)\n },\n\n /**\n * @ignore\n */\n defineRelations () {\n // Setup the mapper's relations, including generating Mapper#relationList\n // and Mapper#relationFields\n utils.forOwn(this.relations, (group, type) => {\n utils.forOwn(group, (relations, _name) => {\n if (utils.isObject(relations)) {\n relations = [relations]\n }\n relations.forEach((def) => {\n const relatedMapper = this.datastore.getMapperByName(_name) || _name\n def.getRelation = () => this.datastore.getMapper(_name)\n\n if (typeof Relation[type] !== 'function') {\n throw utils.err(DOMAIN, 'defineRelations')(400, 'relation type (hasOne, hasMany, etc)', type, true)\n }\n\n this[type](relatedMapper, def)\n })\n })\n })\n }\n})\n\n/**\n * Create a subclass of this Mapper:\n *\n * @example Mapper.extend\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomMapperClass extends Mapper {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customMapper = new CustomMapperClass()\n * console.log(customMapper.foo())\n * console.log(CustomMapperClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherMapperClass = Mapper.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherMapper = new OtherMapperClass()\n * console.log(otherMapper.foo())\n * console.log(OtherMapperClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherMapperClass () {\n * Mapper.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Mapper.extend({\n * constructor: AnotherMapperClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherMapper = new AnotherMapperClass()\n * console.log(anotherMapper.created_at)\n * console.log(anotherMapper.foo())\n * console.log(AnotherMapperClass.beep())\n *\n * @method Mapper.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Mapper class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\nimport Mapper from './Mapper'\n\nconst DOMAIN = 'Container'\n\nexport const proxiedMapperMethods = [\n /**\n * Wrapper for {@link Mapper#count}.\n *\n * @example\n * // Get the number of published blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.count('post', { status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Container#count\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#count}.\n * @param {Object} [opts] See {@link Mapper#count}.\n * @returns {Promise} See {@link Mapper#count}.\n * @see Mapper#count\n * @since 3.0.0\n */\n 'count',\n\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~beforeCreateListener} for how to listen for this event.\n *\n * @event Container#beforeCreate\n * @see Container~beforeCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Container~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see Container#event:beforeCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~afterCreateListener} for how to listen for this event.\n *\n * @event Container#afterCreate\n * @see Container~afterCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Container~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see Container#event:afterCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}.\n *\n * @example\n * // Create and save a new blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.create('post', {\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreate\n * @fires Container#afterCreate\n * @method Container#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props See {@link Mapper#create}.\n * @param {Object} [opts] See {@link Mapper#create}.\n * @returns {Promise} See {@link Mapper#create}.\n * @see Mapper#create\n * @since 3.0.0\n */\n 'create',\n\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Container#beforeCreateMany\n * @see Container~beforeCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Container~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Container#event:beforeCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~afterCreateManyListener} for how to listen for this event.\n *\n * @event Container#afterCreateMany\n * @see Container~afterCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Container~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Container#event:afterCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}.\n *\n * @example\n * // Create and save several new blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.createMany('post', [{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreateMany\n * @fires Container#afterCreateMany\n * @method Container#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record[]} records See {@link Mapper#createMany}.\n * @param {Object} [opts] See {@link Mapper#createMany}.\n * @returns {Promise} See {@link Mapper#createMany}.\n * @see Mapper#createMany\n * @since 3.0.0\n */\n 'createMany',\n\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = PostMapper.createRecord()\n *\n * @method Container#createRecord\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Object[]} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Promise} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n 'createRecord',\n\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~beforeDestroyListener} for how to listen for this event.\n *\n * @event Container#beforeDestroy\n * @see Container~beforeDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Container~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see Container#event:beforeDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~afterDestroyListener} for how to listen for this event.\n *\n * @event Container#afterDestroy\n * @see Container~afterDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Container~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see Container#event:afterDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}.\n *\n * @example\n * // Destroy a specific blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroy('post', 1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @fires Container#beforeDestroy\n * @fires Container#afterDestroy\n * @method Container#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#destroy}.\n * @param {Object} [opts] See {@link Mapper#destroy}.\n * @returns {Promise} See {@link Mapper#destroy}.\n * @see Mapper#destroy\n * @since 3.0.0\n */\n 'destroy',\n\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Container#beforeDestroyAll\n * @see Container~beforeDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Container~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see Container#event:beforeDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Container#afterDestroyAll\n * @see Container~afterDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Container~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see Container#event:afterDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}.\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroyAll('post', { status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @fires Container#beforeDestroyAll\n * @fires Container#afterDestroyAll\n * @method Container#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#destroyAll}.\n * @param {Object} [opts] See {@link Mapper#destroyAll}.\n * @returns {Promise} See {@link Mapper#destroyAll}.\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n 'destroyAll',\n\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~beforeFindListener} for how to listen for this event.\n *\n * @event Container#beforeFind\n * @see Container~beforeFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Container~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see Container#event:beforeFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~afterFindListener} for how to listen for this event.\n *\n * @event Container#afterFind\n * @see Container~afterFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Container~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see Container#event:afterFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.find('post', 1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @fires Container#beforeFind\n * @fires Container#afterFind\n * @method Container#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#find}.\n * @param {Object} [opts] See {@link Mapper#find}.\n * @returns {Promise} See {@link Mapper#find}.\n * @see Mapper#find\n * @since 3.0.0\n */\n 'find',\n\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~beforeFindAllListener} for how to listen for this event.\n *\n * @event Container#beforeFindAll\n * @see Container~beforeFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Container~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see Container#event:beforeFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~afterFindAllListener} for how to listen for this event.\n *\n * @event Container#afterFindAll\n * @see Container~afterFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Container~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see Container#event:afterFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * @example\n * // Find all \"published\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.findAll('post', { status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, ...}, ...]\n * })\n *\n * @fires Container#beforeFindAll\n * @fires Container#afterFindAll\n * @method Container#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#findAll}.\n * @param {Object} [opts] See {@link Mapper#findAll}.\n * @returns {Promise} See {@link Mapper#findAll}.\n * @see Mapper#findAll\n * @since 3.0.0\n */\n 'findAll',\n\n /**\n * Wrapper for {@link Mapper#getSchema}.\n *\n * @method Container#getSchema\n * @param {string} name Name of the {@link Mapper} to target.\n * @returns {Schema} See {@link Mapper#getSchema}.\n * @see Mapper#getSchema\n * @since 3.0.0\n */\n 'getSchema',\n\n /**\n * Wrapper for {@link Mapper#is}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = store.createRecord()\n *\n * console.log(store.is('post', post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof store.getMapper('post').recordClass) // true\n *\n * @method Container#is\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Record} record See {@link Mapper#is}.\n * @returns {boolean} See {@link Mapper#is}.\n * @see Mapper#is\n * @since 3.0.0\n */\n 'is',\n\n /**\n * Wrapper for {@link Mapper#sum}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('purchase_order')\n *\n * store.sum('purchase_order', 'amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Container#sum\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {string} field See {@link Mapper#sum}.\n * @param {Object} [query] See {@link Mapper#sum}.\n * @param {Object} [opts] See {@link Mapper#sum}.\n * @returns {Promise} See {@link Mapper#sum}.\n * @see Mapper#sum\n * @since 3.0.0\n */\n 'sum',\n\n /**\n * Wrapper for {@link Mapper#toJSON}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('person', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = store.createRecord('person', { id: 1, name: 'John', foo: 'bar' })\n * console.log(store.toJSON('person', person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(store.toJSON('person', person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Container#toJSON\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record|Record[]} records See {@link Mapper#toJSON}.\n * @param {Object} [opts] See {@link Mapper#toJSON}.\n * @returns {Object|Object[]} See {@link Mapper#toJSON}.\n * @see Mapper#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~beforeUpdateListener} for how to listen for this event.\n *\n * @event Container#beforeUpdate\n * @see Container~beforeUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Container~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see Container#event:beforeUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~afterUpdateListener} for how to listen for this event.\n *\n * @event Container#afterUpdate\n * @see Container~afterUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Container~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see Container#event:afterUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.update('post', 1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Container#beforeUpdate\n * @fires Container#afterUpdate\n * @method Container#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#update}.\n * @param {Object} record See {@link Mapper#update}.\n * @param {Object} [opts] See {@link Mapper#update}.\n * @returns {Promise} See {@link Mapper#update}.\n * @see Mapper#update\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n 'update',\n\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateAll\n * @see Container~beforeUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Container~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Container#event:beforeUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Container#afterUpdateAll\n * @see Container~afterUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Container~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Container#event:afterUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * store.updateAll('post', update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateAll\n * @fires Container#afterUpdateAll\n * @method Container#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} update See {@link Mapper#updateAll}.\n * @param {Object} [query] See {@link Mapper#updateAll}.\n * @param {Object} [opts] See {@link Mapper#updateAll}.\n * @returns {Promise} See {@link Mapper#updateAll}.\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n 'updateAll',\n\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateMany\n * @see Container~beforeUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Container~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Container#event:beforeUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Container#afterUpdateMany\n * @see Container~afterUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Container~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Container#event:afterUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.updateMany('post', [\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateMany\n * @fires Container#afterUpdateMany\n * @method Container#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#updateMany}.\n * @param {Object} [opts] See {@link Mapper#updateMany}.\n * @returns {Promise} See {@link Mapper#updateMany}.\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n 'updateMany',\n\n /**\n * Wrapper for {@link Mapper#validate}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * let errors = store.validate('post', { name: 'John' })\n * console.log(errors) // undefined\n * errors = store.validate('post', { name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Container#validate\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#validate}.\n * @param {Object} [opts] See {@link Mapper#validate}.\n * @returns {Promise} See {@link Mapper#validate}.\n * @see Mapper#validate\n * @since 3.0.0\n */\n 'validate'\n]\n\n/**\n * The `Container` class is a place to define and store {@link Mapper} instances.\n *\n * `Container` makes it easy to manage your Mappers. Without a container, you\n * need to manage Mappers yourself, including resolving circular dependencies\n * among relations. All Mappers in a container share the same adapters, so you\n * don't have to register adapters for every single Mapper.\n *\n * @example Container#constructor\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n *\n * @class Container\n * @extends Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {Constructor} [opts.mapperClass] See {@link Container#mapperClass}.\n * @param {Object} [opts.mapperDefaults] See {@link Container#mapperDefaults}.\n * @since 3.0.0\n */\nexport function Container (opts) {\n utils.classCallCheck(this, Container)\n Component.call(this)\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * The adapters registered with this Container, which are also shared by all\n * Mappers in this Container.\n *\n * @name Container#_adapters\n * @see Container#registerAdapter\n * @since 3.0.0\n * @type {Object}\n */\n _adapters: {\n value: {}\n },\n\n /**\n * The the mappers in this container\n *\n * @name Container#_mappers\n * @see Mapper\n * @since 3.0.0\n * @type {Object}\n */\n _mappers: {\n value: {}\n },\n\n /**\n * Constructor function to use in {@link Container#defineMapper} to create new\n * {@link Mapper} instances. {@link Container#mapperClass} should extend\n * {@link Mapper}. By default {@link Mapper} is used to instantiate Mappers.\n *\n * @example Container#mapperClass\n * // import {Container, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const store = new Container({\n * mapperClass: MyMapperClass\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').foo())\n *\n * @name Container#mapperClass\n * @see Mapper\n * @since 3.0.0\n * @type {Constructor}\n */\n mapperClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply options provided by the user\n utils.fillIn(this, opts)\n\n /**\n * Defaults options to pass to {@link Container#mapperClass} when creating a\n * new {@link Mapper}.\n *\n * @example Container#mapperDefaults\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: {\n * idAttribute: '_id'\n * }\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').idAttribute)\n *\n * @default {}\n * @name Container#mapperDefaults\n * @since 3.0.0\n * @type {Object}\n */\n this.mapperDefaults = this.mapperDefaults || {}\n\n // Use the Mapper class if the user didn't provide a mapperClass\n this.mapperClass || (this.mapperClass = Mapper)\n}\n\nconst props = {\n constructor: Container,\n\n /**\n * Register a new event listener on this Container.\n *\n * Proxy for {@link Component#on}. If an event was emitted by a {@link Mapper}\n * in the Container, then the name of the {@link Mapper} will be prepended to\n * the arugments passed to the listener.\n *\n * @example Container#on\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.on('foo', function (...args) { console.log(args.join(':')) })\n * store.defineMapper('user')\n * store.emit('foo', 'arg1', 'arg2')\n * store.getMapper('user').emit('foo', 'arg1', 'arg2')\n *\n * @method Container#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n\n /**\n * Used to bind to events emitted by mappers in this container.\n *\n * @method Container#_onMapperEvent\n * @param {string} name Name of the mapper that emitted the event.\n * @param {...*} [args] Args See {@link Mapper#emit}.\n * @private\n * @since 3.0.0\n */\n _onMapperEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * Return a container scoped to a particular mapper.\n *\n * @example Container#as\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method Container#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} A container scoped to a particular mapper.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n proxiedMapperMethods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Create a new mapper and register it in this container.\n *\n * @example Container#defineMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: { foo: 'bar' }\n * })\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(UserMapper.foo)\n *\n * @method Container#defineMapper\n * @param {string} name Name under which to register the new {@link Mapper}.\n * {@link Mapper#name} will be set to this value.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Container#mapperClass} when creating the new {@link Mapper}.\n * @returns {Mapper} The newly created instance of {@link Mapper}.\n * @see Container#as\n * @since 3.0.0\n */\n defineMapper (name, opts) {\n // For backwards compatibility with defineResource\n if (utils.isObject(name)) {\n opts = name\n name = opts.name\n }\n if (!utils.isString(name)) {\n throw utils.err(`${DOMAIN}#defineMapper`, 'name')(400, 'string', name)\n }\n\n // Default values for arguments\n opts || (opts = {})\n // Set Mapper#name\n opts.name = name\n opts.relations || (opts.relations = {})\n\n // Check if the user is overriding the datastore's default mapperClass\n const mapperClass = opts.mapperClass || this.mapperClass\n delete opts.mapperClass\n\n // Apply the datastore's defaults to the options going into the mapper\n utils.fillIn(opts, this.mapperDefaults)\n\n // Instantiate a mapper\n const mapper = this._mappers[name] = new mapperClass(opts) // eslint-disable-line\n mapper.relations || (mapper.relations = {})\n // Make sure the mapper's name is set\n mapper.name = name\n // All mappers in this datastore will share adapters\n mapper._adapters = this.getAdapters()\n\n mapper.datastore = this\n\n mapper.on('all', (...args) => this._onMapperEvent(name, ...args))\n mapper.defineRelations()\n\n return mapper\n },\n\n defineResource (name, opts) {\n console.warn('DEPRECATED: defineResource is deprecated, use defineMapper instead')\n return this.defineMapper(name, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Container#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n */\n getAdapter (name) {\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Container#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || this.mapperDefaults.defaultAdapter\n },\n\n /**\n * Return the registered adapters of this container.\n *\n * @method Container#getAdapters\n * @returns {Adapter}\n * @since 3.0.0\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Return the mapper registered under the specified name.\n *\n * @example Container#getMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * store.getMapper('profile') // throws Error, there is no mapper with name \"profile\"\n *\n * @method Container#getMapper\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapper (name) {\n const mapper = this.getMapperByName(name)\n if (!mapper) {\n throw utils.err(`${DOMAIN}#getMapper`, name)(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Return the mapper registered under the specified name.\n * Doesn't throw error if mapper doesn't exist.\n *\n * @example Container#getMapperByName\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(store.getMapper('profile')) // Does NOT throw an error\n *\n * @method Container#getMapperByName\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapperByName (name) {\n return this._mappers[name]\n },\n\n /**\n * Register an adapter on this container under the given name. Adapters\n * registered on a container are shared by all mappers in the container.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n *\n * @method Container#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for all Mappers in this container.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.mapperDefaults.defaultAdapter = name\n utils.forOwn(this._mappers, function (mapper) {\n mapper.defaultAdapter = name\n })\n }\n }\n}\n\nproxiedMapperMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getMapper(name)[method](...args)\n }\n})\n\nComponent.extend(props)\n\n/**\n * Create a subclass of this Container:\n * @example Container.extend\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomContainerClass extends Container {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customContainer = new CustomContainerClass()\n * console.log(customContainer.foo())\n * console.log(CustomContainerClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherContainerClass = Container.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherContainer = new OtherContainerClass()\n * console.log(otherContainer.foo())\n * console.log(OtherContainerClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherContainerClass () {\n * Container.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Container.extend({\n * constructor: AnotherContainerClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherContainer = new AnotherContainerClass()\n * console.log(anotherContainer.created_at)\n * console.log(anotherContainer.foo())\n * console.log(AnotherContainerClass.beep())\n *\n * @method Container.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Container class.\n * @since 3.0.0\n */\n","import utils, { safeSetLink, safeSetProp } from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport {proxiedMapperMethods, Container} from './Container'\nimport Collection from './Collection'\n\nconst DOMAIN = 'SimpleStore'\nconst proxiedCollectionMethods = [\n /**\n * Wrapper for {@link Collection#add}.\n *\n * @example SimpleStore#add\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n *\n * // Add one book to the in-memory store:\n * store.add('book', { id: 1, title: 'Respect your Data' })\n * // Add multiple books to the in-memory store:\n * store.add('book', [\n * { id: 2, title: 'Easy data recipes' },\n * { id: 3, title: 'Active Record 101' }\n * ])\n *\n * @fires SimpleStore#add\n * @method SimpleStore#add\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Object[]|Record|Record[])} data See {@link Collection#add}.\n * @param {Object} [opts] Configuration options. See {@link Collection#add}.\n * @returns {(Object|Object[]|Record|Record[])} See {@link Collection#add}.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n 'add',\n\n /**\n * Wrapper for {@link Collection#between}.\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = store.between('user', 18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = store.between('user', [18], [30], { index: 'age' })\n *\n * @method SimpleStore#between\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Array} leftKeys See {@link Collection#between}.\n * @param {Array} rightKeys See {@link Collection#between}.\n * @param {Object} [opts] Configuration options. See {@link Collection#between}.\n * @returns {Object[]|Record[]} See {@link Collection#between}.\n * @see Collection#between\n * @see Collection#between\n * @since 3.0.0\n */\n 'between',\n\n /**\n * Wrapper for {@link Collection#createIndex}.\n *\n * @example\n * // Index users by age\n * store.createIndex('user', 'age')\n *\n * @example\n * // Index users by status and role\n * store.createIndex('user', 'statusAndRole', ['status', 'role'])\n *\n * @method SimpleStore#createIndex\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {string} name See {@link Collection#createIndex}.\n * @param {string[]} [fieldList] See {@link Collection#createIndex}.\n * @see Collection#createIndex\n * @see Collection#createIndex\n * @since 3.0.0\n */\n 'createIndex',\n\n /**\n * Wrapper for {@link Collection#filter}.\n *\n * @example SimpleStore#filter\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = store.filter('post', function (post) { return post.id % 2 === 0 })\n *\n * @method SimpleStore#filter\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Function)} [queryOrFn={}] See {@link Collection#filter}.\n * @param {Object} [thisArg] See {@link Collection#filter}.\n * @returns {Array} See {@link Collection#filter}.\n * @see Collection#filter\n * @see Collection#filter\n * @since 3.0.0\n */\n 'filter',\n\n /**\n * Wrapper for {@link Collection#get}.\n *\n * @example SimpleStore#get\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * console.log(store.get('post', 1)) // {...}\n * console.log(store.get('post', 2)) // undefined\n *\n * @method SimpleStore#get\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Collection#get}.\n * @returns {(Object|Record)} See {@link Collection#get}.\n * @see Collection#get\n * @see Collection#get\n * @since 3.0.0\n */\n 'get',\n\n /**\n * Wrapper for {@link Collection#getAll}.\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = store.getAll('post', 'draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = store.getAll('post', ['draft'], ['inReview'], { index: 'status' })\n *\n * @method SimpleStore#getAll\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {...Array} [keyList] See {@link Collection#getAll}.\n * @param {Object} [opts] See {@link Collection#getAll}.\n * @returns {Array} See {@link Collection#getAll}.\n * @see Collection#getAll\n * @see Collection#getAll\n * @since 3.0.0\n */\n 'getAll',\n\n /**\n * Wrapper for {@link Collection#prune}.\n *\n * @method SimpleStore#prune\n * @param {Object} [opts] See {@link Collection#prune}.\n * @returns {Array} See {@link Collection#prune}.\n * @see Collection#prune\n * @see Collection#prune\n * @since 3.0.0\n */\n 'prune',\n\n /**\n * Wrapper for {@link Collection#query}.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * store.query('user')\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method SimpleStore#query\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @returns {Query} See {@link Collection#query}.\n * @see Collection#query\n * @see Collection#query\n * @since 3.0.0\n */\n 'query',\n\n /**\n * Wrapper for {@link Collection#toJSON}.\n *\n * @example\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * title: { type: 'string' }\n * }\n * }\n * })\n * store.add('post', [\n * { id: 1, status: 'published', title: 'Respect your Data' },\n * { id: 2, status: 'draft', title: 'Connecting to a data source' }\n * ])\n * console.log(store.toJSON('post'))\n * const draftsJSON = store.query('post')\n * .filter({ status: 'draft' })\n * .mapCall('toJSON')\n * .run()\n *\n * @method SimpleStore#toJSON\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Object} [opts] See {@link Collection#toJSON}.\n * @returns {Array} See {@link Collection#toJSON}.\n * @see Collection#toJSON\n * @see Collection#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Wrapper for {@link Collection#unsaved}.\n *\n * @method SimpleStore#unsaved\n * @returns {Array} See {@link Collection#unsaved}.\n * @see Collection#unsaved\n * @see Collection#unsaved\n * @since 3.0.0\n */\n 'unsaved'\n]\nconst ownMethodsForScoping = [\n 'addToCache',\n 'cachedFind',\n 'cachedFindAll',\n 'cacheFind',\n 'cacheFindAll',\n 'hashQuery'\n]\n\nconst cachedFn = function (name, hashOrId, opts) {\n const cached = this._completedQueries[name][hashOrId]\n if (utils.isFunction(cached)) {\n return cached(name, hashOrId, opts)\n }\n return cached\n}\n\nconst SIMPLESTORE_DEFAULTS = {\n /**\n * Whether to use the pending query if a `find` request for the specified\n * record is currently underway. Can be set to `true`, `false`, or to a\n * function that returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFind\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFind: true,\n\n /**\n * Whether to use the pending query if a `findAll` request for the given query\n * is currently underway. Can be set to `true`, `false`, or to a function that\n * returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFindAll\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFindAll: true\n}\n\n/**\n * The `SimpleStore` class is an extension of {@link Container}. Not only does\n * `SimpleStore` manage mappers, but also collections. `SimpleStore` implements the\n * asynchronous {@link Mapper} methods, such as {@link Mapper#find} and\n * {@link Mapper#create}. If you use the asynchronous `SimpleStore` methods\n * instead of calling them directly on the mappers, then the results of the\n * method calls will be inserted into the store's collections. You can think of\n * a `SimpleStore` as an [Identity Map](https://en.wikipedia.org/wiki/Identity_map_pattern)\n * for the [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping)\n * (the Mappers).\n *\n * ```javascript\n * import {SimpleStore} from 'js-data'\n * ```\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new SimpleStore()\n *\n * // SimpleStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // SimpleStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful SimpleStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class SimpleStore\n * @extends Container\n * @param {Object} [opts] Configuration options. See {@link Container}.\n * @param {boolean} [opts.collectionClass={@link Collection}] See {@link SimpleStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link SimpleStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link SimpleStore#usePendingFindAll}.\n * @returns {SimpleStore}\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-SimpleStore\",\"Working with the SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction SimpleStore (opts) {\n utils.classCallCheck(this, SimpleStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, SIMPLESTORE_DEFAULTS)\n Container.call(this, opts)\n\n this.collectionClass = this.collectionClass || Collection\n this._collections = {}\n this._pendingQueries = {}\n this._completedQueries = {}\n}\n\nconst props = {\n constructor: SimpleStore,\n\n /**\n * Internal method used to handle Mapper responses.\n *\n * @method SimpleStore#_end\n * @private\n * @param {string} name Name of the {@link Collection} to which to\n * add the data.\n * @param {Object} result The result from a Mapper.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object|Array)} Result.\n */\n _end (name, result, opts) {\n let data = opts.raw ? result.data : result\n if (data && utils.isFunction(this.addToCache)) {\n data = this.addToCache(name, data, opts)\n if (opts.raw) {\n result.data = data\n } else {\n result = data\n }\n }\n return result\n },\n\n /**\n * Register a new event listener on this SimpleStore.\n *\n * Proxy for {@link Container#on}. If an event was emitted by a Mapper or\n * Collection in the SimpleStore, then the name of the Mapper or Collection will\n * be prepended to the arugments passed to the provided event handler.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a SimpleStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * store.on('add', (mapperName, records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * store.on('change', (mapperName, record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method SimpleStore#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n */\n\n /**\n * Used to bind to events emitted by collections in this store.\n *\n * @method SimpleStore#_onCollectionEvent\n * @private\n * @param {string} name Name of the collection that emitted the event.\n * @param {...*} [args] Args passed to {@link Collection#emit}.\n */\n _onCollectionEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * This method takes the data received from {@link SimpleStore#find},\n * {@link SimpleStore#findAll}, {@link SimpleStore#update}, etc., and adds the\n * data to the store. _You don't need to call this method directly._\n *\n * If you're using the http adapter and your response data is in an unexpected\n * format, you may need to override this method so the right data gets added\n * to the store.\n *\n * @example\n * const store = new SimpleStore({\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return SimpleStore.prototype.addToCache.call(this, mapperName, data, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return super.addToCache(mapperName, data, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#addToCache\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {*} data Data from which data should be selected for add.\n * @param {Object} [opts] Configuration options.\n */\n addToCache (name, data, opts) {\n return this.getCollection(name).add(data, opts)\n },\n\n /**\n * Return the store scoped to a particular mapper/collection pair.\n *\n * @example SimpleStore.as\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method SimpleStore#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} The store, scoped to a particular Mapper/Collection pair.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n const methods = ownMethodsForScoping\n .concat(proxiedMapperMethods)\n .concat(proxiedCollectionMethods)\n\n methods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n props.getCollection = {\n writable: true,\n value () {\n return original.getCollection(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Retrieve a cached `find` result, if any. This method is called during\n * {@link SimpleStore#find} to determine if {@link Mapper#find} needs to be\n * called. If this method returns `undefined` then {@link Mapper#find} will\n * be called. Otherwise {@link SimpleStore#find} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFind.call(this, mapperName, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cachedFind(mapperName, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cachedFind: cachedFn,\n\n /**\n * Retrieve a cached `findAll` result, if any. This method is called during\n * {@link SimpleStore#findAll} to determine if {@link Mapper#findAll} needs to be\n * called. If this method returns `undefined` then {@link Mapper#findAll} will\n * be called. Otherwise {@link SimpleStore#findAll} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return super.cachedFindAll(mapperName, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cachedFindAll: cachedFn,\n\n /**\n * Mark a {@link Mapper#find} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `find` entry is\n * added it means subsequent calls to the same Resource with the same `id`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#get} instead of delegating to {@link Mapper#find}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cacheFind.call(this, mapperName, data, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cacheFind(mapperName, data, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {*} data The result to cache.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cacheFind (name, data, id, opts) {\n this._completedQueries[name][id] = (name, id, opts) => this.get(name, id)\n },\n\n /**\n * Mark a {@link Mapper#findAll} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `findAll` entry is\n * added it means subsequent calls to the same Resource with the same `query`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#filter} instead of delegating to {@link Mapper#findAll}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, data, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return super.cachedFindAll(mapperName, data, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {*} data The result to cache.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cacheFindAll (name, data, hash, opts) {\n this._completedQueries[name][hash] = (name, hash, opts) => this.filter(name, utils.fromJson(hash))\n },\n\n /**\n * Remove __all__ records from the in-memory store and reset\n * {@link SimpleStore#_completedQueries}.\n *\n * @method SimpleStore#clear\n * @returns {Object} Object containing all records that were in the store.\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n clear () {\n const removed = {}\n utils.forOwn(this._collections, (collection, name) => {\n removed[name] = collection.removeAll()\n this._completedQueries[name] = {}\n })\n return removed\n },\n\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~beforeCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreate\n * @see SimpleStore~beforeCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback SimpleStore~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see SimpleStore#event:beforeCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~afterCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreate\n * @see SimpleStore~afterCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback SimpleStore~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see SimpleStore#event:afterCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}. Adds the created record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book {\"author_id\":1234,...}\n * store.create('book', {\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }).then((book) => {\n * console.log(book.id) // 120392\n * console.log(book.title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreate\n * @fires SimpleStore#afterCreate\n * @fires SimpleStore#add\n * @method SimpleStore#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} record Passed to {@link Mapper#create}.\n * @param {Object} [opts] Passed to {@link Mapper#create}. See\n * {@link Mapper#create} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n create (name, record, opts) {\n opts || (opts = {})\n return Container.prototype.create.call(this, name, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~beforeCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreateMany\n * @see SimpleStore~beforeCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback SimpleStore~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see SimpleStore#event:beforeCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~afterCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreateMany\n * @see SimpleStore~afterCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback SimpleStore~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see SimpleStore#event:afterCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}. Adds the created records to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book [{\"author_id\":1234,...},{...}]\n * store.createMany('book', [{\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }, {\n * author_id: 1234,\n * edition: 'Second Edition',\n * title: 'Respect your Data'\n * }]).then((books) => {\n * console.log(books[0].id) // 142394\n * console.log(books[0].title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreateMany\n * @fires SimpleStore#afterCreateMany\n * @fires SimpleStore#add\n * @method SimpleStore#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Array} records Passed to {@link Mapper#createMany}.\n * @param {Object} [opts] Passed to {@link Mapper#createMany}. See\n * {@link Mapper#createMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n createMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.createMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n defineMapper (name, opts) {\n const self = this\n const mapper = Container.prototype.defineMapper.call(self, name, opts)\n self._pendingQueries[name] = {}\n self._completedQueries[name] = {}\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, { // eslint-disable-line\n // Make sure the collection has somewhere to store \"added\" timestamps\n _added: {},\n // Give the collection a reference to this SimpleStore\n datastore: self,\n // The mapper tied to the collection\n mapper\n })\n\n const schema = mapper.schema || {}\n const properties = schema.properties || {}\n // TODO: Make it possible index nested properties?\n utils.forOwn(properties, function (opts, prop) {\n if (opts.indexed) {\n collection.createIndex(prop)\n }\n })\n\n // Create a secondary index on the \"added\" timestamps of records in the\n // collection\n collection.createIndex('addedTimestamps', ['$'], {\n fieldGetter (obj) {\n return collection._added[collection.recordId(obj)]\n }\n })\n\n collection.on('all', function (...args) {\n self._onCollectionEvent(name, ...args)\n })\n\n return mapper\n },\n\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~beforeDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroy\n * @see SimpleStore~beforeDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback SimpleStore~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see SimpleStore#event:beforeDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~afterDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroy\n * @see SimpleStore~afterDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback SimpleStore~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see SimpleStore#event:afterDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}. Removes any destroyed record from the\n * in-memory store. Clears out any {@link SimpleStore#_completedQueries} entries\n * associated with the provided `id`.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is no longer in the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n *\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroy\n * @fires SimpleStore#afterDestroy\n * @fires SimpleStore#remove\n * @method SimpleStore#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#destroy}.\n * @param {Object} [opts] Passed to {@link Mapper#destroy}. See\n * {@link Mapper#destroy} for more configuration options.\n * @returns {Promise} Resolves when the destroy operation completes.\n * @since 3.0.0\n */\n destroy (name, id, opts) {\n opts || (opts = {})\n return Container.prototype.destroy.call(this, name, id, opts).then((result) => {\n const record = this.getCollection(name).remove(id, opts)\n\n if (opts.raw) {\n result.data = record\n } else {\n result = record\n }\n delete this._pendingQueries[name][id]\n delete this._completedQueries[name][id]\n return result\n })\n },\n\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroyAll\n * @see SimpleStore~beforeDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback SimpleStore~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see SimpleStore#event:beforeDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~afterDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroyAll\n * @see SimpleStore~afterDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback SimpleStore~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see SimpleStore#event:afterDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}. Removes any destroyed records from\n * the in-memory store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is gone from the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroyAll\n * @fires SimpleStore#afterDestroyAll\n * @fires SimpleStore#remove\n * @method SimpleStore#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper#destroyAll}.\n * @param {Object} [opts] Passed to {@link Mapper#destroyAll}. See\n * {@link Mapper#destroyAll} for more configuration options.\n * @returns {Promise} Resolves when the delete completes.\n * @since 3.0.0\n */\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return Container.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n const records = this.getCollection(name).removeAll(query, opts)\n\n if (opts.raw) {\n result.data = records\n } else {\n result = records\n }\n const hash = this.hashQuery(name, query, opts)\n delete this._pendingQueries[name][hash]\n delete this._completedQueries[name][hash]\n return result\n })\n },\n\n eject (name, id, opts) {\n console.warn('DEPRECATED: \"eject\" is deprecated, use \"remove\" instead')\n return this.remove(name, id, opts)\n },\n\n ejectAll (name, query, opts) {\n console.warn('DEPRECATED: \"ejectAll\" is deprecated, use \"removeAll\" instead')\n return this.removeAll(name, query, opts)\n },\n\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~beforeFindListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFind\n * @see SimpleStore~beforeFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback SimpleStore~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see SimpleStore#event:beforeFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~afterFindListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFind\n * @see SimpleStore~afterFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback SimpleStore~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see SimpleStore#event:afterFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}. Adds any found record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /book/1234\n * store.find('book', 1234).then((book) => {\n * // The book record is now in the in-memory store\n * console.log(store.get('book', 1234) === book) // true\n * })\n *\n * @fires SimpleStore#beforeFind\n * @fires SimpleStore#afterFind\n * @fires SimpleStore#add\n * @method SimpleStore#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#find}.\n * @param {Object} [opts] Passed to {@link Mapper#find}.\n * @param {boolean|Function} [opts.usePendingFind] See {@link SimpleStore#usePendingFind}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n find (name, id, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const pendingQuery = this._pendingQueries[name][id]\n const usePendingFind = opts.usePendingFind === undefined ? this.usePendingFind : opts.usePendingFind\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFind) ? usePendingFind.call(this, name, id, opts) : usePendingFind)) {\n return pendingQuery\n }\n const item = this.cachedFind(name, id, opts)\n let promise\n\n if (opts.force || !item) {\n promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts).then((result) => {\n delete this._pendingQueries[name][id]\n result = this._end(name, result, opts)\n this.cacheFind(name, result, id, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][id]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(item)\n }\n return promise\n },\n\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~beforeFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFindAll\n * @see SimpleStore~beforeFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback SimpleStore~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see SimpleStore#event:beforeFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~afterFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFindAll\n * @see SimpleStore~afterFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback SimpleStore~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see SimpleStore#event:afterFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#findAll}. Adds any found records to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('movie')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /movie?rating=PG\n * store.find('movie', { rating: 'PG' }).then((movies) => {\n * // The movie records are now in the in-memory store\n * console.log(store.filter('movie'))\n * })\n *\n * @fires SimpleStore#beforeFindAll\n * @fires SimpleStore#afterFindAll\n * @fires SimpleStore#add\n * @method SimpleStore#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper.findAll}.\n * @param {Object} [opts] Passed to {@link Mapper.findAll}.\n * @param {boolean|Function} [opts.usePendingFindAll] See {@link SimpleStore#usePendingFindAll}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n findAll (name, query, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const hash = this.hashQuery(name, query, opts)\n const pendingQuery = this._pendingQueries[name][hash]\n const usePendingFindAll = opts.usePendingFindAll === undefined ? this.usePendingFindAll : opts.usePendingFindAll\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFindAll) ? usePendingFindAll.call(this, name, query, opts) : usePendingFindAll)) {\n return pendingQuery\n }\n\n const items = this.cachedFindAll(name, hash, opts)\n let promise\n\n if (opts.force || !items) {\n promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts).then((result) => {\n delete this._pendingQueries[name][hash]\n result = this._end(name, result, opts)\n this.cacheFindAll(name, result, hash, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][hash]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(items)\n }\n return promise\n },\n\n /**\n * Return the {@link Collection} with the given name, if for some\n * reason you need a direct reference to the collection.\n *\n * @method SimpleStore#getCollection\n * @param {string} name Name of the {@link Collection} to retrieve.\n * @returns {Collection}\n * @since 3.0.0\n * @throws {Error} Thrown if the specified {@link Collection} does not\n * exist.\n */\n getCollection (name) {\n const collection = this._collections[name]\n if (!collection) {\n throw utils.err(`${DOMAIN}#getCollection`, name)(404, 'collection')\n }\n return collection\n },\n\n /**\n * Hashing function used to cache {@link SimpleStore#find} and\n * {@link SimpleStore#findAll} requests. This method simply JSONifies the\n * `query` argument passed to {@link SimpleStore#find} or\n * {@link SimpleStore#findAll}.\n *\n * Override this method for custom hashing behavior.\n * @method SimpleStore#hashQuery\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @param {Object} query The `query` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @returns {string} The JSONified `query`.\n * @since 3.0.0\n */\n hashQuery (name, query, opts) {\n return utils.toJson(query)\n },\n\n inject (name, records, opts) {\n console.warn('DEPRECATED: \"inject\" is deprecated, use \"add\" instead')\n return this.add(name, records, opts)\n },\n\n /**\n * Wrapper for {@link Collection#remove}. Removes the specified\n * {@link Record} from the store.\n *\n * @example SimpleStore#remove\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n * console.log(store.getAll('book').length)\n * store.add('book', { id: 1234 })\n * console.log(store.getAll('book').length)\n * store.remove('book', 1234)\n * console.log(store.getAll('book').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#remove\n * @param {string} name The name of the {@link Collection} to target.\n * @param {string|number} id The primary key of the {@link Record} to remove.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n remove (name, id, opts) {\n const record = this.getCollection(name).remove(id, opts)\n if (record) {\n this.removeRelated(name, [record], opts)\n }\n return record\n },\n\n /**\n * Wrapper for {@link Collection#removeAll}. Removes the selected\n * {@link Record}s from the store.\n *\n * @example SimpleStore#removeAll\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('movie')\n * console.log(store.getAll('movie').length)\n * store.add('movie', [{ id: 3, rating: 'R' }, { id: 4, rating: 'PG-13' })\n * console.log(store.getAll('movie').length)\n * store.removeAll('movie', { rating: 'R' })\n * console.log(store.getAll('movie').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeAll\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}s, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n removeAll (name, query, opts) {\n const records = this.getCollection(name).removeAll(query, opts)\n if (records.length) {\n this.removeRelated(name, records, opts)\n }\n return records\n },\n\n /**\n * Remove from the store {@link Record}s that are related to the provided\n * {@link Record}(s).\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeRelated\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Record|Record[]} records {@link Record}s whose relations are to be\n * removed.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record}(s) to remove\n * from the store.\n * @since 3.0.0\n */\n removeRelated (name, records, opts) {\n if (!utils.isArray(records)) {\n records = [records]\n }\n utils.forEachRelation(this.getMapper(name), opts, (def, optsCopy) => {\n records.forEach((record) => {\n let relatedData\n let query\n if (def.foreignKey && (def.type === hasOneType || def.type === hasManyType)) {\n query = { [def.foreignKey]: def.getForeignKey(record) }\n } else if (def.type === hasManyType && def.localKeys) {\n query = {\n where: {\n [def.getRelation().idAttribute]: {\n 'in': utils.get(record, def.localKeys)\n }\n }\n }\n } else if (def.type === hasManyType && def.foreignKeys) {\n query = {\n where: {\n [def.foreignKeys]: {\n 'contains': def.getForeignKey(record)\n }\n }\n }\n } else if (def.type === belongsToType) {\n relatedData = this.remove(def.relation, def.getForeignKey(record), optsCopy)\n }\n if (query) {\n relatedData = this.removeAll(def.relation, query, optsCopy)\n }\n if (relatedData) {\n if (utils.isArray(relatedData) && !relatedData.length) {\n return\n }\n if (def.type === hasOneType) {\n relatedData = relatedData[0]\n }\n def.setLocalField(record, relatedData)\n }\n })\n })\n },\n\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~beforeUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdate\n * @see SimpleStore~beforeUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback SimpleStore~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see SimpleStore#event:beforeUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~afterUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdate\n * @see SimpleStore~afterUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback SimpleStore~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see SimpleStore#event:afterUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}. Adds the updated {@link Record} to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post/1234 {\"status\":\"published\"}\n * store.update('post', 1, { status: 'published' }).then((post) => {\n * // The post record has also been updated in the in-memory store\n * console.log(store.get('post', 1234))\n * })\n *\n * @fires SimpleStore#beforeUpdate\n * @fires SimpleStore#afterUpdate\n * @fires SimpleStore#add\n * @method SimpleStore#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#update}.\n * @param {Object} record Passed to {@link Mapper#update}.\n * @param {Object} [opts] Passed to {@link Mapper#update}. See\n * {@link Mapper#update} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n update (name, id, record, opts) {\n opts || (opts = {})\n return Container.prototype.update.call(this, name, id, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateAll\n * @see SimpleStore~beforeUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback SimpleStore~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see SimpleStore#event:beforeUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~afterUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateAll\n * @see SimpleStore~afterUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback SimpleStore~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see SimpleStore#event:afterUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post?author_id=1234 {\"status\":\"published\"}\n * store.updateAll('post', { author_id: 1234 }, { status: 'published' }).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.filter('posts', { author_id: 1234 }))\n * })\n *\n * @fires SimpleStore#beforeUpdateAll\n * @fires SimpleStore#afterUpdateAll\n * @fires SimpleStore#add\n * @method SimpleStore#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props Passed to {@link Mapper#updateAll}.\n * @param {Object} [query] Passed to {@link Mapper#updateAll}.\n * @param {Object} [opts] Passed to {@link Mapper#updateAll}. See\n * {@link Mapper#updateAll} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateAll (name, props, query, opts) {\n opts || (opts = {})\n return Container.prototype.updateAll.call(this, name, query, props, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateMany\n * @see SimpleStore~beforeUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback SimpleStore~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see SimpleStore#event:beforeUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~afterUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateMany\n * @see SimpleStore~afterUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback SimpleStore~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see SimpleStore#event:afterUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post [{\"id\":3,status\":\"published\"},{\"id\":4,status\":\"published\"}]\n * store.updateMany('post', [\n * { id: 3, status: 'published' },\n * { id: 4, status: 'published' }\n * ]).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.getAll('post', 3, 4))\n * })\n *\n * @fires SimpleStore#beforeUpdateMany\n * @fires SimpleStore#afterUpdateMany\n * @fires SimpleStore#add\n * @method SimpleStore#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records Passed to {@link Mapper#updateMany}.\n * @param {Object} [opts] Passed to {@link Mapper#updateMany}. See\n * {@link Mapper#updateMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.updateMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n }\n}\n\nproxiedCollectionMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getCollection(name)[method](...args)\n }\n})\n\nexport default Container.extend(props)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link SimpleStore~changeListener} on how to listen for this event.\n *\n * @event SimpleStore#change\n * @see SimpleStore~changeListener\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:change} event.\n *\n * @example\n * function onChange (mapperName, record, changes) {\n * // do something\n * }\n * store.on('change', onChange)\n *\n * @callback SimpleStore~changeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record} record The Record that changed.\n * @param {Object} changes The changes.\n * @see SimpleStore#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the in-memory store. See\n * {@link SimpleStore~addListener} on how to listen for this event.\n *\n * @event SimpleStore#add\n * @see SimpleStore~addListener\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:add} event.\n *\n * @example\n * function onAdd (mapperName, recordOrRecords) {\n * // do something\n * }\n * store.on('add', onAdd)\n *\n * @callback SimpleStore~addListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} The Record or Records that were added.\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the in-memory store. See\n * {@link SimpleStore~removeListener} for how to listen for this event.\n *\n * @event SimpleStore#remove\n * @see SimpleStore~removeListener\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:remove} event.\n *\n * @example\n * function onRemove (mapperName, recordsOrRecords) {\n * // do something\n * }\n * store.on('remove', onRemove)\n *\n * @callback SimpleStore~removeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} Record or Records that were removed.\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this SimpleStore:\n * @example SimpleStore.extend\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSimpleStoreClass extends SimpleStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSimpleStore = new CustomSimpleStoreClass()\n * console.log(customSimpleStore.foo())\n * console.log(CustomSimpleStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSimpleStoreClass = SimpleStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSimpleStore = new OtherSimpleStoreClass()\n * console.log(otherSimpleStore.foo())\n * console.log(OtherSimpleStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSimpleStoreClass () {\n * SimpleStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * SimpleStore.extend({\n * constructor: AnotherSimpleStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSimpleStore = new AnotherSimpleStoreClass()\n * console.log(anotherSimpleStore.created_at)\n * console.log(anotherSimpleStore.foo())\n * console.log(AnotherSimpleStoreClass.beep())\n *\n * @method SimpleStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this SimpleStore class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport './decorators'\nimport Collection from './Collection'\n\nconst DOMAIN = 'LinkedCollection'\n\n/**\n * Extends {@link Collection}. Used by a {@link DataStore} to implement an\n * Identity Map.\n *\n * ```javascript\n * import {LinkedCollection} from 'js-data'\n * ```\n *\n * @class LinkedCollection\n * @extends Collection\n * @param {Array} [records] Initial set of records to insert into the\n * collection. See {@link Collection}.\n * @param {Object} [opts] Configuration options. See {@link Collection}.\n * @returns {Mapper}\n */\nfunction LinkedCollection (records, opts) {\n utils.classCallCheck(this, LinkedCollection)\n // Make sure this collection has somewhere to store \"added\" timestamps\n Object.defineProperties(this, {\n _added: {\n value: {}\n },\n datastore: {\n writable: true,\n value: undefined\n }\n })\n\n Collection.call(this, records, opts)\n\n // Make sure this collection has a reference to a datastore\n if (!this.datastore) {\n throw utils.err(`new ${DOMAIN}`, 'opts.datastore')(400, 'DataStore', this.datastore)\n }\n}\n\nexport default Collection.extend({\n constructor: LinkedCollection,\n\n _addMeta (record, timestamp) {\n // Track when this record was added\n this._added[this.recordId(record)] = timestamp\n\n if (utils.isFunction(record._set)) {\n record._set('$', timestamp)\n }\n },\n\n _clearMeta (record) {\n delete this._added[this.recordId(record)]\n if (utils.isFunction(record._set)) {\n record._set('$') // unset\n }\n },\n\n _onRecordEvent (...args) {\n Collection.prototype._onRecordEvent.apply(this, args)\n const event = args[0]\n // This is a very brute force method\n // Lots of room for optimization\n if (utils.isString(event) && event.indexOf('change') === 0) {\n this.updateIndexes(args[1])\n }\n },\n\n add (records, opts) {\n const mapper = this.mapper\n const timestamp = new Date().getTime()\n const singular = utils.isObject(records) && !utils.isArray(records)\n\n if (singular) {\n records = [records]\n }\n records = Collection.prototype.add.call(this, records, opts)\n\n if (mapper.relationList.length && records.length) {\n // Check the currently visited record for relations that need to be\n // inserted into their respective collections.\n mapper.relationList.forEach(function (def) {\n def.addLinkedRecords(records)\n })\n }\n\n records.forEach((record) => this._addMeta(record, timestamp))\n\n return singular ? records[0] : records\n },\n\n remove (idOrRecord, opts) {\n const mapper = this.mapper\n const record = Collection.prototype.remove.call(this, idOrRecord, opts)\n if (record) {\n this._clearMeta(record)\n }\n\n if (mapper.relationList.length && record) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, [record])\n })\n }\n\n return record\n },\n\n removeAll (query, opts) {\n const mapper = this.mapper\n const records = Collection.prototype.removeAll.call(this, query, opts)\n records.forEach(this._clearMeta, this)\n\n if (mapper.relationList.length && records.length) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, records)\n })\n }\n\n return records\n }\n})\n\n/**\n * Create a subclass of this LinkedCollection:\n *\n * @example LinkedCollection.extend\n * // Normally you would do: import {LinkedCollection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {LinkedCollection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomLinkedCollectionClass extends LinkedCollection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customLinkedCollection = new CustomLinkedCollectionClass()\n * console.log(customLinkedCollection.foo())\n * console.log(CustomLinkedCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherLinkedCollectionClass = LinkedCollection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherLinkedCollection = new OtherLinkedCollectionClass()\n * console.log(otherLinkedCollection.foo())\n * console.log(OtherLinkedCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherLinkedCollectionClass () {\n * LinkedCollection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * LinkedCollection.extend({\n * constructor: AnotherLinkedCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherLinkedCollection = new AnotherLinkedCollectionClass()\n * console.log(anotherLinkedCollection.created_at)\n * console.log(anotherLinkedCollection.foo())\n * console.log(AnotherLinkedCollectionClass.beep())\n *\n * @method LinkedCollection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this LinkedCollection class.\n * @since 3.0.0\n */\n","import utils, { safeSetLink, safeSetProp } from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport SimpleStore from './SimpleStore'\nimport LinkedCollection from './LinkedCollection'\n\nconst DOMAIN = 'DataStore'\n\nconst DATASTORE_DEFAULTS = {\n /**\n * Whether in-memory relations should be unlinked from records after they are\n * destroyed.\n *\n * @default true\n * @name DataStore#unlinkOnDestroy\n * @since 3.0.0\n * @type {boolean}\n */\n unlinkOnDestroy: true\n}\n\n/**\n * The `DataStore` class is an extension of {@link SimpleStore}. Not only does\n * `DataStore` manage mappers and store data in collections, it uses the\n * {@link LinkedCollection} class to link related records together in memory.\n *\n * ```javascript\n * import {DataStore} from 'js-data'\n * ```\n *\n * @example\n * import {DataStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new DataStore()\n *\n * // DataStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // DataStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful DataStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class DataStore\n * @extends SimpleStore\n * @param {Object} [opts] Configuration options. See {@link SimpleStore}.\n * @param {boolean} [opts.collectionClass={@link LinkedCollection}] See {@link DataStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean} [opts.unlinkOnDestroy=true] See {@link DataStore#unlinkOnDestroy}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link DataStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link DataStore#usePendingFindAll}.\n * @returns {DataStore}\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-datastore\",\"Working with the DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction DataStore (opts) {\n utils.classCallCheck(this, DataStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, DATASTORE_DEFAULTS)\n opts.collectionClass || (opts.collectionClass = LinkedCollection)\n SimpleStore.call(this, opts)\n}\n\nconst props = {\n constructor: DataStore,\n\n defineMapper (name, opts) {\n // Complexity of this method is beyond simply using => functions to bind context\n const self = this\n const mapper = SimpleStore.prototype.defineMapper.call(self, name, opts)\n const idAttribute = mapper.idAttribute\n const collection = this.getCollection(name)\n\n mapper.relationList.forEach(function (def) {\n const relation = def.relation\n const localField = def.localField\n const path = `links.${localField}`\n const foreignKey = def.foreignKey\n const type = def.type\n const updateOpts = { index: foreignKey }\n let descriptor\n\n const getter = function () { return this._get(path) }\n\n if (type === belongsToType) {\n if (!collection.indexes[foreignKey]) {\n collection.createIndex(foreignKey)\n }\n\n descriptor = {\n get: getter,\n // e.g. profile.user = someUser\n // or comment.post = somePost\n set (record) {\n // e.g. const otherUser = profile.user\n const currentParent = this._get(path)\n // e.g. profile.user === someUser\n if (record === currentParent) {\n return currentParent\n }\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n\n // e.g. profile.user !== someUser\n // or comment.post !== somePost\n if (currentParent && inverseDef) {\n this.removeInverseRelation(currentParent, id, inverseDef, idAttribute)\n }\n if (record) {\n // e.g. profile.user = someUser\n const relatedIdAttribute = def.getRelation().idAttribute\n const relatedId = utils.get(record, relatedIdAttribute)\n\n // Prefer store record\n if (relatedId !== undefined && this._get('$')) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n // e.g. profile.user = someUser\n // or comment.post = somePost\n safeSetLink(this, localField, record)\n safeSetProp(this, foreignKey, relatedId)\n collection.updateIndex(this, updateOpts)\n\n if (inverseDef) {\n this.setupInverseRelation(record, id, inverseDef, idAttribute)\n }\n } else {\n // Unset in-memory link only\n // e.g. profile.user = undefined\n // or comment.post = undefined\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n\n let foreignKeyDescriptor = Object.getOwnPropertyDescriptor(mapper.recordClass.prototype, foreignKey)\n if (!foreignKeyDescriptor) {\n foreignKeyDescriptor = {\n enumerable: true\n }\n }\n const originalGet = foreignKeyDescriptor.get\n foreignKeyDescriptor.get = function () {\n if (originalGet) {\n return originalGet.call(this)\n }\n return this._get(`props.${foreignKey}`)\n }\n const originalSet = foreignKeyDescriptor.set\n foreignKeyDescriptor.set = function (value) {\n if (originalSet) {\n originalSet.call(this, value)\n }\n const currentParent = utils.get(this, localField)\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n const currentParentId = currentParent ? utils.get(currentParent, def.getRelation().idAttribute) : undefined\n\n if (currentParent && currentParentId !== undefined && currentParentId !== value) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n }\n\n safeSetProp(this, foreignKey, value)\n collection.updateIndex(this, updateOpts)\n\n if ((value === undefined || value === null)) {\n if (currentParentId !== undefined) {\n // Unset locals\n utils.set(this, localField, undefined)\n }\n } else if (this._get('$')) {\n const storeRecord = self.get(relation, value)\n if (storeRecord) {\n utils.set(this, localField, storeRecord)\n }\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, foreignKey, foreignKeyDescriptor)\n } else if (type === hasManyType) {\n const localKeys = def.localKeys\n const foreignKeys = def.foreignKeys\n\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n\n descriptor = {\n get () {\n let current = getter.call(this)\n if (!current) {\n this._set(path, [])\n }\n return getter.call(this)\n },\n // e.g. post.comments = someComments\n // or user.groups = someGroups\n // or group.users = someUsers\n set (records) {\n if (records && !utils.isArray(records)) {\n records = [records]\n }\n const id = utils.get(this, idAttribute)\n const relatedIdAttribute = def.getRelation().idAttribute\n const inverseDef = def.getInverse(mapper)\n const inverseLocalField = inverseDef.localField\n const current = this._get(path) || []\n const toLink = []\n const toLinkIds = {}\n\n if (records) {\n records.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n const currentParent = utils.get(record, inverseLocalField)\n if (currentParent && currentParent !== this) {\n const currentChildrenOfParent = utils.get(currentParent, localField)\n // e.g. somePost.comments.remove(comment)\n if (relatedId === undefined) {\n utils.remove(currentChildrenOfParent, (child) => child === record)\n } else {\n utils.remove(currentChildrenOfParent, (child) => child === record || relatedId === utils.get(child, relatedIdAttribute))\n }\n }\n if (relatedId !== undefined) {\n if (this._get('$')) {\n // Prefer store record\n record = self.get(relation, relatedId) || record\n }\n // e.g. toLinkIds[comment.id] = comment\n toLinkIds[relatedId] = record\n }\n toLink.push(record)\n })\n }\n\n // e.g. post.comments = someComments\n if (foreignKey) {\n current.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(record) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update (unset) inverse relation\n if (records) {\n // e.g. comment.post_id = undefined\n safeSetProp(record, foreignKey, undefined)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n }\n // e.g. comment.post = undefined\n safeSetLink(record, inverseLocalField, undefined)\n }\n })\n toLink.forEach((record) => {\n // Update (set) inverse relation\n // e.g. comment.post_id = post.id\n safeSetProp(record, foreignKey, id)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n // e.g. comment.post = post\n safeSetLink(record, inverseLocalField, this)\n })\n } else if (localKeys) {\n // Update locals\n // e.g. group.users = someUsers\n // Update (set) inverse relation\n const ids = toLink.map((child) => utils.get(child, relatedIdAttribute)).filter((id) => id !== undefined)\n // e.g. group.user_ids = [1,2,3,...]\n utils.set(this, localKeys, ids)\n // Update (unset) inverse relation\n if (inverseDef.foreignKeys) {\n current.forEach((child) => {\n const relatedId = utils.get(child, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(child) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update inverse relation\n // safeSetLink(child, inverseLocalField, undefined)\n const parents = utils.get(child, inverseLocalField) || []\n // e.g. someUser.groups.remove(group)\n if (id === undefined) {\n utils.remove(parents, (parent) => parent === this)\n } else {\n utils.remove(parents, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n }\n })\n toLink.forEach((child) => {\n // Update (set) inverse relation\n const parents = utils.get(child, inverseLocalField)\n // e.g. someUser.groups.push(group)\n if (id === undefined) {\n utils.noDupeAdd(parents, this, (parent) => parent === this)\n } else {\n utils.noDupeAdd(parents, this, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n })\n }\n } else if (foreignKeys) {\n // e.g. user.groups = someGroups\n // Update (unset) inverse relation\n current.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n // e.g. someGroup.user_ids.remove(user.id)\n utils.remove(ids, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n // e.g. someGroup.users.remove(user)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n // Update (set) inverse relation\n toLink.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n utils.noDupeAdd(ids, id, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n }\n\n this._set(path, toLink)\n return toLink\n }\n }\n } else if (type === hasOneType) {\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n descriptor = {\n get: getter,\n // e.g. user.profile = someProfile\n set (record) {\n const current = this._get(path)\n if (record === current) {\n return current\n }\n const inverseLocalField = def.getInverse(mapper).localField\n // Update (unset) inverse relation\n if (current) {\n safeSetProp(current, foreignKey, undefined)\n self.getCollection(relation).updateIndex(current, updateOpts)\n safeSetLink(current, inverseLocalField, undefined)\n }\n if (record) {\n const relatedId = utils.get(record, def.getRelation().idAttribute)\n // Prefer store record\n if (relatedId !== undefined) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n safeSetLink(this, localField, record)\n\n // Update (set) inverse relation\n safeSetProp(record, foreignKey, utils.get(this, idAttribute))\n self.getCollection(relation).updateIndex(record, updateOpts)\n safeSetLink(record, inverseLocalField, this)\n } else {\n // Unset locals\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n }\n\n if (descriptor) {\n descriptor.enumerable = def.enumerable === undefined ? false : def.enumerable\n if (def.get) {\n let origGet = descriptor.get\n descriptor.get = function () {\n return def.get(def, this, (...args) => origGet.apply(this, args))\n }\n }\n if (def.set) {\n let origSet = descriptor.set\n descriptor.set = function (related) {\n return def.set(def, this, related, (value) => origSet.call(this, value === undefined ? related : value))\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, localField, descriptor)\n }\n })\n\n return mapper\n },\n\n destroy (name, id, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroy.call(this, name, id, opts).then((result) => {\n let record\n if (opts.raw) {\n record = result.data\n } else {\n record = result\n }\n\n if (record && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n utils.set(record, def.localField, undefined)\n })\n }\n return result\n })\n },\n\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n let records\n if (opts.raw) {\n records = result.data\n } else {\n records = result\n }\n\n if (records && records.length && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n records.forEach((record) => {\n utils.set(record, def.localField, undefined)\n })\n })\n }\n return result\n })\n }\n}\n\nexport default SimpleStore.extend(props)\n\n/**\n * Create a subclass of this DataStore:\n * @example DataStore.extend\n * // Normally you would do: import {DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {DataStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomDataStoreClass extends DataStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customDataStore = new CustomDataStoreClass()\n * console.log(customDataStore.foo())\n * console.log(CustomDataStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherDataStoreClass = DataStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherDataStore = new OtherDataStoreClass()\n * console.log(otherDataStore.foo())\n * console.log(OtherDataStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherDataStoreClass () {\n * DataStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * DataStore.extend({\n * constructor: AnotherDataStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherDataStore = new AnotherDataStoreClass()\n * console.log(anotherDataStore.created_at)\n * console.log(anotherDataStore.foo())\n * console.log(AnotherDataStoreClass.beep())\n *\n * @method DataStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this DataStore class.\n * @since 3.0.0\n */\n","/**\n * Registered as `js-data` in NPM and Bower.\n *\n * Also available from CDN.JS and JSDelivr.\n *\n * @module js-data\n *\n * @example Install from NPM\n * npm i --save js-data@beta\n * @example Install from Bower\n * bower i --save js-data@3.0.0-beta.1\n * @example Install from CDN.JS\n * \n * @example Install from JSDelivr\n * \n * @example Load into your app via script tag\n * \n * \n * @example Load into your app via CommonJS\n * var JSData = require('js-data');\n * @example Load into your app via ES2015 Modules\n * import * as JSData from 'js-data';\n * @example Load into your app via AMD\n * define('myApp', ['js-data'], function (JSData) { ... })\n */\n\n/**\n * Describes the version of this `JSData` object.\n *\n * @example\n * console.log(JSData.version.full) // \"3.0.0-beta.1\"\n *\n * @name version\n * @memberof module:js-data\n * @property {string} full The full semver value.\n * @property {number} major The major version number.\n * @property {number} minor The minor version number.\n * @property {number} patch The patch version number.\n * @property {(string|boolean)} alpha The alpha version value, otherwise `false`\n * if the current version is not alpha.\n * @property {(string|boolean)} beta The beta version value, otherwise `false`\n * if the current version is not beta.\n * @since 2.0.0\n * @type {Object}\n */\nexport const version = '<%= version %>'\n\n/**\n * JSData's utility methods.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @name module:js-data.utils\n * @property {Function} Promise See {@link utils.Promise}.\n * @see utils\n * @since 3.0.0\n * @type {Object}\n */\nimport utils from './utils'\n\n/**\n * JSData's {@link Collection} class.\n *\n * @example\n * import {Collection} from 'js-data'\n * const collection = new Collection()\n *\n * @name module:js-data.Collection\n * @see Collection\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#collection\",\"Components of JSData: Collection\"]\n * @type {Constructor}\n */\nimport Collection from './Collection'\n\n/**\n * JSData's {@link Component} class. Most components in JSData extend this\n * class.\n *\n * @example\n * import {Component} from 'js-data'\n * // Make a custom component.\n * const MyComponent = Component.extend({\n * myMethod (someArg) { ... }\n * })\n *\n * @name module:js-data.Component\n * @see Component\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Component from './Component'\n\n/**\n * JSData's {@link Container} class. Defines and manages {@link Mapper}s. Used\n * in Node.js and in the browser, though in the browser you may want to use\n * {@link DataStore} instead.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n *\n * @name module:js-data.Container\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#container\",\"Components of JSData: Container\"]\n * @type {Constructor}\n */\nimport {Container} from './Container'\n\n/**\n * JSData's {@link DataStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {DataStore} from 'js-data'\n * const store = new DataStore()\n *\n * @name module:js-data.DataStore\n * @see DataStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @type {Constructor}\n */\nimport DataStore from './DataStore'\n\n/**\n * JSData's {@link Index} class, based on [mindex]{@link https://github.com/internalfx/mindex}.\n *\n * @name module:js-data.Index\n * @see Index\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Index from '../lib/mindex/index'\n\n/**\n * JSData's {@link LinkedCollection} class. Used by the {@link DataStore}\n * component. If you need to create a collection manually, you should probably\n * use the {@link Collection} class.\n *\n * @name module:js-data.LinkedCollection\n * @see DataStore\n * @see LinkedCollection\n * @since 3.0.0\n * @type {Constructor}\n */\nimport LinkedCollection from './LinkedCollection'\n\n/**\n * JSData's {@link Mapper} class. The core of the ORM.\n *\n * @example Recommended use\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @example Create Mapper manually\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @name module:js-data.Mapper\n * @see Container\n * @see Mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @type {Constructor}\n */\nimport Mapper from './Mapper'\n\n/**\n * JSData's {@link Query} class. Used by the {@link Collection} component.\n *\n * @name module:js-data.Query\n * @see Query\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Query from './Query'\n\n/**\n * JSData's {@link Record} class.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n *\n * @name module:js-data.Record\n * @see Record\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#record\",\"Components of JSData: Record\"]\n * @type {Constructor}\n */\nimport Record from './Record'\n\n/**\n * JSData's {@link Schema} class. Implements http://json-schema.org/draft-04.\n *\n * @example\n * import {Container, Schema} from 'js-data'\n * const userSchema = new Schema({\n * properties: {\n * id: { type: 'string' },\n * name: { type: 'string' }\n * }\n * })\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: userSchema\n * })\n *\n * @name module:js-data.Schema\n * @see Schema\n * @see http://json-schema.org/\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#schema\",\"Components of JSData: schema\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/schemas\",\"JSData's Schema Syntax\"]\n * @type {Constructor}\n */\nimport Schema from './Schema'\n\n/**\n * JSData's {@link Settable} class.\n *\n * @example\n * import {Settable} from 'js-data'\n * const obj = new Settable()\n * obj.set('secret', 'value')\n * console.log(JSON.stringify(obj)) // {}\n *\n * @name module:js-data.Settable\n * @see Settable\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Settable from './Settable'\n\n/**\n * JSData's {@link SimpleStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * const store = new SimpleStore()\n *\n * @name module:js-data.SimpleStore\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @type {Constructor}\n */\nimport SimpleStore from './SimpleStore'\n\nexport * from './decorators'\n\nexport {\n Collection,\n Component,\n Container,\n DataStore,\n Index,\n LinkedCollection,\n Mapper,\n Query,\n Record,\n Schema,\n Settable,\n SimpleStore,\n utils\n}\n"],"names":["DOMAIN","Component","Query","belongsTo","hasMany","hasOne","creatingPath","noValidatePath","keepChangeHistoryPath","Schema","Record","_belongsTo","_hasMany","_hasOne","Mapper","Collection","props","LinkedCollection","SimpleStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA,IAAM,SAAS,OAAf;;AAEA,IAAM,WAAW,IAAI,CAArB;AACA,IAAM,cAAc,uBAApB;AACA,IAAM,WAAW,kBAAjB;AACA,IAAM,WAAW,eAAjB;AACA,IAAM,WAAW,mBAAjB;AACA,IAAM,aAAa,iBAAnB;AACA,IAAM,aAAa,iBAAnB;AACA,IAAM,aAAa,iBAAnB;AACA,IAAM,aAAa,iBAAnB;AACA,IAAM,cAAc,OAAO,SAAP,CAAiB,QAArC;AACA,IAAM,OAAO,cAAb;;AAEA,IAAM,SAAS;OAAA,eACJ;0BAAsB,UAAU,CAAV,CAApB,kBAA4C,UAAU,CAAV,IAAe,UAAU,CAAV,CAAf,WAAqC,UAAU,CAAV,CAArC,CAA5C;GADE;OAAA,eAEJ;WAAY,UAAU,CAAV,CAAV;;CAFb;;AAKA,IAAM,YAAY,SAAZ,SAAY,CAAU,KAAV,EAAiB;MAC7B,CAAC,KAAL,EAAY;WACH,CAAP;;;UAGM,CAAC,KAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,AAAO,IAAM,UAAU,gBAAhB;;;;;;;;;;;;;;;AAeP,AAEA;;;;;;;;;;;;;AAaA,AAEA;;;;;;;;;;;;;;;;AAgBA,AAEA;;;;;;;;;;;;;;;AAeA,AAEA;;;;;;;;;;;;;;AAcA,AAEA;;;;;;;;AAQA,AAEA;;;;;;;;;;;AAWA,AAEA;;;;;;;;;;;;;;;;;;;;AAoBA,AAEA;;;;;;;;AAQA,AAEA;;;;;;;;;;;;;;;AAeA,AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,AAEA;;;;;;;;;;;;;;AAcA,AAEA;;;;;;;;;;;;;GAcA,AAEA,AAEA;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"js-data.js","sources":["../src/utils.js","../src/Settable.js","../src/Component.js","../src/Query.js","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.js","../src/Relation.js","../src/Relation/BelongsTo.js","../src/Relation/HasMany.js","../src/Relation/HasOne.js","../src/relations.js","../src/decorators.js","../src/Record.js","../src/Schema.js","../src/Mapper.js","../src/Container.js","../src/SimpleStore.js","../src/LinkedCollection.js","../src/DataStore.js","../src/index.js"],"sourcesContent":["/**\n * Utility methods used by JSData.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @namespace utils\n * @type {Object}\n */\n\nconst DOMAIN = 'utils'\n\nconst INFINITY = 1 / 0\nconst MAX_INTEGER = 1.7976931348623157e+308\nconst BOOL_TAG = '[object Boolean]'\nconst DATE_TAG = '[object Date]'\nconst FUNC_TAG = '[object Function]'\nconst NUMBER_TAG = '[object Number]'\nconst OBJECT_TAG = '[object Object]'\nconst REGEXP_TAG = '[object RegExp]'\nconst STRING_TAG = '[object String]'\nconst objToString = Object.prototype.toString\nconst PATH = /^(.+)\\.(.+)$/\n\nconst ERRORS = {\n '400' () { return `expected: ${arguments[0]}, found: ${arguments[2] ? arguments[1] : typeof arguments[1]}` },\n '404' () { return `${arguments[0]} not found` }\n}\n\nconst toInteger = function (value) {\n if (!value) {\n return 0\n }\n // Coerce to number\n value = +value\n if (value === INFINITY || value === -INFINITY) {\n const sign = (value < 0 ? -1 : 1)\n return sign * MAX_INTEGER\n }\n const remainder = value % 1\n return value === value ? (remainder ? value - remainder : value) : 0 // eslint-disable-line\n}\n\nconst toStr = function (value) {\n return objToString.call(value)\n}\n\nconst isPlainObject = function (value) {\n return (!!value && typeof value === 'object' && value.constructor === Object)\n}\n\nconst mkdirP = function (object, path) {\n if (!path) {\n return object\n }\n const parts = path.split('.')\n parts.forEach(function (key) {\n if (!object[key]) {\n object[key] = {}\n }\n object = object[key]\n })\n return object\n}\n\nconst utils = {\n /**\n * Reference to the Promise constructor used by JSData. Defaults to\n * `window.Promise` or `global.Promise`.\n *\n * @example Make JSData use a different `Promise` constructor\n * import Promise from 'bluebird'\n * import {utils} from 'js-data'\n * utils.Promise = Promise\n *\n * @name utils.Promise\n * @since 3.0.0\n * @type {Function}\n */\n Promise: Promise,\n\n /**\n * Shallow copy properties that meet the following criteria from `src` to\n * `dest`:\n *\n * - own enumerable\n * - not a function\n * - does not start with \"_\"\n *\n * @method utils._\n * @param {Object} dest Destination object.\n * @param {Object} src Source object.\n * @private\n * @since 3.0.0\n */\n _ (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (key && dest[key] === undefined && !utils.isFunction(value) && key.indexOf('_') !== 0) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Recursively iterates over relations found in `opts.with`.\n *\n * @method utils._forRelation\n * @param {Object} opts Configuration options.\n * @param {Relation} def Relation definition.\n * @param {Function} fn Callback function.\n * @param {*} [thisArg] Execution context for the callback function.\n * @private\n * @since 3.0.0\n */\n _forRelation (opts, def, fn, thisArg) {\n const relationName = def.relation\n let containedName = null\n let index\n opts || (opts = {})\n opts.with || (opts.with = [])\n\n if ((index = utils._getIndex(opts.with, relationName)) >= 0) {\n containedName = relationName\n } else if ((index = utils._getIndex(opts.with, def.localField)) >= 0) {\n containedName = def.localField\n }\n\n if (opts.withAll) {\n fn.call(thisArg, def, {})\n return\n } else if (!containedName) {\n return\n }\n let optsCopy = {}\n utils.fillIn(optsCopy, def.getRelation())\n utils.fillIn(optsCopy, opts)\n optsCopy.with = opts.with.slice()\n optsCopy._activeWith = optsCopy.with.splice(index, 1)[0]\n optsCopy.with.forEach(function (relation, i) {\n if (relation && relation.indexOf(containedName) === 0 && relation.length >= containedName.length && relation[containedName.length] === '.') {\n optsCopy.with[i] = relation.substr(containedName.length + 1)\n } else {\n optsCopy.with[i] = ''\n }\n })\n fn.call(thisArg, def, optsCopy)\n },\n\n /**\n * Find the index of a relation in the given list\n *\n * @method utils._getIndex\n * @param {string[]} list List to search.\n * @param {string} relation Relation to find.\n * @private\n * @returns {number}\n */\n _getIndex (list, relation) {\n let index = -1\n list.forEach(function (_relation, i) {\n if (_relation === relation) {\n index = i\n return false\n } else if (utils.isObject(_relation)) {\n if (_relation.relation === relation) {\n index = i\n return false\n }\n }\n })\n return index\n },\n\n /**\n * Define hidden (non-enumerable), writable properties on `target` from the\n * provided `props`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {}\n * utils.addHiddenPropsToTarget(Cat.prototype, {\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat.say() // \"meow\"\n *\n * @method utils.addHiddenPropsToTarget\n * @param {Object} target That to which `props` should be added.\n * @param {Object} props Properties to be added to `target`.\n * @since 3.0.0\n */\n addHiddenPropsToTarget (target, props) {\n const map = {}\n Object.keys(props).forEach(function (propName) {\n const descriptor = Object.getOwnPropertyDescriptor(props, propName)\n\n descriptor.enumerable = false\n map[propName] = descriptor\n })\n Object.defineProperties(target, map)\n },\n\n /**\n * Return whether the two objects are deeply different.\n *\n * @example\n * import {utils} from 'js-data'\n * utils.areDifferent({}, {}) // false\n * utils.areDifferent({ a: 1 }, { a: 1 }) // false\n * utils.areDifferent({ foo: 'bar' }, {}) // true\n *\n * @method utils.areDifferent\n * @param {Object} a Base object.\n * @param {Object} b Comparison object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Whether the two objects are deeply different.\n * @see utils.diffObjects\n * @since 3.0.0\n */\n areDifferent (newObject, oldObject, opts) {\n opts || (opts = {})\n const diff = utils.diffObjects(newObject, oldObject, opts)\n const diffCount = Object.keys(diff.added).length +\n Object.keys(diff.removed).length +\n Object.keys(diff.changed).length\n return diffCount > 0\n },\n\n /**\n * Verified that the given constructor is being invoked via `new`, as opposed\n * to just being called like a normal function.\n *\n * @example\n * import {utils} from 'js-data'\n * function Cat () {\n * utils.classCallCheck(this, Cat)\n * }\n * const cat = new Cat() // this is ok\n * Cat() // this throws an error\n *\n * @method utils.classCallCheck\n * @param {*} instance Instance that is being constructed.\n * @param {Constructor} ctor Constructor function used to construct the\n * instance.\n * @since 3.0.0\n * @throws {Error} Throws an error if the constructor is being improperly\n * invoked.\n */\n classCallCheck (instance, ctor) {\n if (!(instance instanceof ctor)) {\n throw utils.err(`${ctor.name}`)(500, 'Cannot call a class as a function')\n }\n },\n\n /**\n * Deep copy a value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' } }\n * const b = utils.copy(a)\n * a === b // false\n * utils.areDifferent(a, b) // false\n *\n * @param {*} from Value to deep copy.\n * @param {*} [to] Destination object for the copy operation.\n * @param {*} [stackFrom] For internal use.\n * @param {*} [stackTo] For internal use.\n * @param {string[]|RegExp[]} [blacklist] List of strings or RegExp of\n * properties to skip.\n * @param {boolean} [plain] Whether to make a plain copy (don't try to use\n * original prototype).\n * @returns {*} Deep copy of `from`.\n * @since 3.0.0\n */\n copy (from, to, stackFrom, stackTo, blacklist, plain) {\n if (!to) {\n to = from\n if (from) {\n if (utils.isArray(from)) {\n to = utils.copy(from, [], stackFrom, stackTo, blacklist, plain)\n } else if (utils.isDate(from)) {\n to = new Date(from.getTime())\n } else if (utils.isRegExp(from)) {\n to = new RegExp(from.source, from.toString().match(/[^/]*$/)[0])\n to.lastIndex = from.lastIndex\n } else if (utils.isObject(from)) {\n if (plain) {\n to = utils.copy(from, {}, stackFrom, stackTo, blacklist, plain)\n } else {\n to = utils.copy(from, Object.create(Object.getPrototypeOf(from)), stackFrom, stackTo, blacklist, plain)\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(500, 'Cannot copy! Source and destination are identical.')\n }\n\n stackFrom = stackFrom || []\n stackTo = stackTo || []\n\n if (utils.isObject(from)) {\n let index = stackFrom.indexOf(from)\n if (index !== -1) {\n return stackTo[index]\n }\n\n stackFrom.push(from)\n stackTo.push(to)\n }\n\n let result\n if (utils.isArray(from)) {\n let i\n to.length = 0\n for (i = 0; i < from.length; i++) {\n result = utils.copy(from[i], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[i])) {\n stackFrom.push(from[i])\n stackTo.push(result)\n }\n to.push(result)\n }\n } else {\n if (utils.isArray(to)) {\n to.length = 0\n } else {\n utils.forOwn(to, function (value, key) {\n delete to[key]\n })\n }\n for (var key in from) {\n if (from.hasOwnProperty(key)) {\n if (utils.isBlacklisted(key, blacklist)) {\n continue\n }\n result = utils.copy(from[key], null, stackFrom, stackTo, blacklist, plain)\n if (utils.isObject(from[key])) {\n stackFrom.push(from[key])\n stackTo.push(result)\n }\n to[key] = result\n }\n }\n }\n }\n return to\n },\n\n /**\n * Recursively shallow fill in own enumerable properties from `source` to\n * `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"bip\"}\n *\n * @method utils.deepFillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n deepFillIn (dest, source) {\n if (source) {\n utils.forOwn(source, function (value, key) {\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepFillIn(existing, value)\n } else if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n }\n return dest\n },\n\n /**\n * Recursively shallow copy enumerable properties from `source` to `dest`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.deepFillIn(b, a)\n * console.log(b) // {\"foo\":{\"bar\":\"baz\"},\"beep\":\"boop\"}\n *\n * @method utils.deepMixIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.fillIn\n * @see utils.deepFillIn\n * @since 3.0.0\n */\n deepMixIn (dest, source) {\n if (source) {\n for (var key in source) {\n const value = source[key]\n const existing = dest[key]\n if (isPlainObject(value) && isPlainObject(existing)) {\n utils.deepMixIn(existing, value)\n } else {\n dest[key] = value\n }\n }\n }\n return dest\n },\n\n /**\n * Return a diff of the base object to the comparison object.\n *\n * @example\n * import {utils} from 'js-data'\n * const oldObject = { foo: 'bar', a: 1234 }\n * const newObject = { beep: 'boop', a: 5678 }\n * const diff = utils.diffObjects(oldObject, newObject)\n * console.log(diff.added) // {\"beep\":\"boop\"}\n * console.log(diff.changed) // {\"a\":5678}\n * console.log(diff.removed) // {\"foo\":undefined}\n *\n * @method utils.diffObjects\n * @param {Object} newObject Comparison object.\n * @param {Object} oldObject Base object.\n * @param {Object} [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} The diff from the base object to the comparison object.\n * @see utils.areDifferent\n * @since 3.0.0\n */\n diffObjects (newObject, oldObject, opts) {\n opts || (opts = {})\n let equalsFn = opts.equalsFn\n let blacklist = opts.ignore\n const diff = {\n added: {},\n changed: {},\n removed: {}\n }\n if (!utils.isFunction(equalsFn)) {\n equalsFn = utils.deepEqual\n }\n\n const newKeys = Object.keys(newObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n const oldKeys = Object.keys(oldObject).filter(function (key) {\n return !utils.isBlacklisted(key, blacklist)\n })\n\n // Check for properties that were added or changed\n newKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (equalsFn(oldValue, newValue)) {\n return\n }\n if (oldValue === undefined) {\n diff.added[key] = newValue\n } else {\n diff.changed[key] = newValue\n }\n })\n\n // Check for properties that were removed\n oldKeys.forEach(function (key) {\n const oldValue = oldObject[key]\n const newValue = newObject[key]\n if (newValue === undefined && oldValue !== undefined) {\n diff.removed[key] = undefined\n }\n })\n\n return diff\n },\n\n /**\n * Return whether the two values are equal according to the `==` operator.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.equal(1,1)) // true\n * console.log(utils.equal(1,'1')) // true\n * console.log(utils.equal(93, 66)) // false\n *\n * @method utils.equal\n * @param {*} a First value in the comparison.\n * @param {*} b Second value in the comparison.\n * @returns {boolean} Whether the two values are equal according to `==`.\n * @since 3.0.0\n */\n equal (a, b) {\n return a == b // eslint-disable-line\n },\n\n /**\n * Produce a factory function for making Error objects with the provided\n * metadata. Used throughout the various js-data components.\n *\n * @example\n * import {utils} from 'js-data'\n * const errorFactory = utils.err('domain', 'target')\n * const error400 = errorFactory(400, 'expected type', 'actual type')\n * console.log(error400) // [Error: [domain:target] expected: expected type, found: string\nhttp://www.js-data.io/v3.0/docs/errors#400]\n * @method utils.err\n * @param {string} domain Namespace.\n * @param {string} target Target.\n * @returns {Function} Factory function.\n * @since 3.0.0\n */\n err (domain, target) {\n return function (code) {\n const prefix = `[${domain}:${target}] `\n let message = ERRORS[code].apply(null, Array.prototype.slice.call(arguments, 1))\n message = `${prefix}${message}\nhttp://www.js-data.io/v3.0/docs/errors#${code}`\n return new Error(message)\n }\n },\n\n /**\n * Add eventing capabilities into the target object.\n *\n * @example\n * import {utils} from 'js-data'\n * const user = { name: 'John' }\n * utils.eventify(user)\n * user.on('foo', () => console.log(arguments))\n * user.emit('foo', 1, 'bar') // should log to console values (1, \"bar\")\n *\n * @method utils.eventify\n * @param {Object} target Target object.\n * @param {Function} [getter] Custom getter for retrieving the object's event\n * listeners.\n * @param {Function} [setter] Custom setter for setting the object's event\n * listeners.\n * @since 3.0.0\n */\n eventify (target, getter, setter) {\n target = target || this\n let _events = {}\n if (!getter && !setter) {\n getter = function () { return _events }\n setter = function (value) { _events = value }\n }\n Object.defineProperties(target, {\n emit: {\n value (...args) {\n const events = getter.call(this) || {}\n const type = args.shift()\n let listeners = events[type] || []\n let i\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n listeners = events.all || []\n args.unshift(type)\n for (i = 0; i < listeners.length; i++) {\n listeners[i].f.apply(listeners[i].c, args)\n }\n }\n },\n off: {\n value (type, func) {\n const events = getter.call(this)\n const listeners = events[type]\n if (!listeners) {\n setter.call(this, {})\n } else if (func) {\n for (let i = 0; i < listeners.length; i++) {\n if (listeners[i].f === func) {\n listeners.splice(i, 1)\n break\n }\n }\n } else {\n listeners.splice(0, listeners.length)\n }\n }\n },\n on: {\n value (type, func, thisArg) {\n if (!getter.call(this)) {\n setter.call(this, {})\n }\n const events = getter.call(this)\n events[type] = events[type] || []\n events[type].push({\n c: thisArg,\n f: func\n })\n }\n }\n })\n },\n\n /**\n * Used for sublcassing. Invoke this method in the context of a superclass to\n * to produce a subclass based on `props` and `classProps`.\n *\n * @example\n * import {utils} from 'js-data'\n * function Animal () {}\n * Animal.extend = utils.extend\n * const Cat = Animal.extend({\n * say () {\n * console.log('meow')\n * }\n * })\n * const cat = new Cat()\n * cat instanceof Animal // true\n * cat instanceof Cat // true\n * cat.say() // \"meow\"\n *\n * @method utils.extend\n * @param {Object} props Instance properties for the subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to use as the subclass.\n * @param {Object} props Static properties for the subclass.\n * @returns {Constructor} A new subclass.\n * @since 3.0.0\n */\n extend (props, classProps) {\n const superClass = this\n let subClass\n\n props || (props = {})\n classProps || (classProps = {})\n\n if (props.hasOwnProperty('constructor')) {\n subClass = props.constructor\n delete props.constructor\n } else {\n subClass = function (...args) {\n utils.classCallCheck(this, subClass)\n superClass.apply(this, args)\n }\n }\n\n // Setup inheritance of instance members\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n configurable: true,\n enumerable: false,\n value: subClass,\n writable: true\n }\n })\n\n const obj = Object\n // Setup inheritance of static members\n if (obj.setPrototypeOf) {\n obj.setPrototypeOf(subClass, superClass)\n } else if (classProps.strictEs6Class) {\n subClass.__proto__ = superClass // eslint-disable-line\n } else {\n utils.forOwn(superClass, function (value, key) {\n subClass[key] = value\n })\n }\n if (!subClass.hasOwnProperty('__super__')) {\n Object.defineProperty(subClass, '__super__', {\n configurable: true,\n value: superClass\n })\n }\n\n utils.addHiddenPropsToTarget(subClass.prototype, props)\n utils.fillIn(subClass, classProps)\n\n return subClass\n },\n\n /**\n * Shallow copy own enumerable properties from `src` to `dest` that are on\n * `src` but are missing from `dest.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: 'bar', beep: 'boop' }\n * const b = { beep: 'bip' }\n * utils.fillIn(b, a)\n * console.log(b) // {\"foo\":\"bar\",\"beep\":\"bip\"}\n *\n * @method utils.fillIn\n * @param {Object} dest The destination object.\n * @param {Object} source The source object.\n * @see utils.deepFillIn\n * @see utils.deepMixIn\n * @since 3.0.0\n */\n fillIn (dest, src) {\n utils.forOwn(src, function (value, key) {\n if (!dest.hasOwnProperty(key) || dest[key] === undefined) {\n dest[key] = value\n }\n })\n },\n\n /**\n * Find the last index of an item in an array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = { name: 'John', age: 20 }\n * const sara = { name: 'Sara', age: 25 }\n * const dan = { name: 'Dan', age: 20 }\n * const users = [john, sara, dan]\n *\n * console.log(utils.findIndex(users, (user) => user.age === 25)) // 1\n * console.log(utils.findIndex(users, (user) => user.age > 19)) // 2\n * console.log(utils.findIndex(users, (user) => user.name === 'John')) // 0\n * console.log(utils.findIndex(users, (user) => user.name === 'Jimmy')) // -1\n *\n * @method utils.findIndex\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n * @returns {number} Index if found or -1 if not found.\n * @since 3.0.0\n */\n findIndex (array, fn) {\n let index = -1\n if (!array) {\n return index\n }\n array.forEach(function (record, i) {\n if (fn(record)) {\n index = i\n return false\n }\n })\n return index\n },\n\n /**\n * Recursively iterate over a {@link Mapper}'s relations according to\n * `opts.with`.\n *\n * @method utils.forEachRelation\n * @param {Mapper} mapper Mapper.\n * @param {Object} opts Configuration options.\n * @param {Function} fn Callback function.\n * @param {*} thisArg Execution context for the callback function.\n * @since 3.0.0\n */\n forEachRelation (mapper, opts, fn, thisArg) {\n const relationList = mapper.relationList || []\n if (!relationList.length) {\n return\n }\n relationList.forEach(function (def) {\n utils._forRelation(opts, def, fn, thisArg)\n })\n },\n\n /**\n * Iterate over an object's own enumerable properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { b: 1, c: 4 }\n * let sum = 0\n * utils.forOwn(a, function (value, key) {\n * sum += value\n * })\n * console.log(sum) // 5\n *\n * @method utils.forOwn\n * @param {Object} object The object whose properties are to be enumerated.\n * @param {Function} fn Iteration function.\n * @param {Object} [thisArg] Content to which to bind `fn`.\n * @since 3.0.0\n */\n forOwn (obj, fn, thisArg) {\n const keys = Object.keys(obj)\n const len = keys.length\n let i\n for (i = 0; i < len; i++) {\n fn.call(thisArg, obj[keys[i]], keys[i], obj)\n }\n },\n\n /**\n * Proxy for `JSON.parse`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = utils.fromJson('{\"name\" : \"John\"}')\n * console.log(a) // { name: 'John' }\n *\n * @method utils.fromJson\n * @param {string} json JSON to parse.\n * @returns {Object} Parsed object.\n * @see utils.toJson\n * @since 3.0.0\n */\n fromJson (json) {\n return utils.isString(json) ? JSON.parse(json) : json\n },\n\n /**\n * Retrieve the specified property from the given object. Supports retrieving\n * nested properties.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: { bar: 'baz' }, beep: 'boop' }\n * console.log(utils.get(a, 'beep')) // \"boop\"\n * console.log(utils.get(a, 'foo.bar')) // \"baz\"\n *\n * @method utils.get\n * @param {Object} object Object from which to retrieve a property's value.\n * @param {string} prop Property to retrieve.\n * @returns {*} Value of the specified property.\n * @see utils.set\n * @since 3.0.0\n */\n 'get': function (object, prop) {\n if (!prop) {\n return\n }\n const parts = prop.split('.')\n const last = parts.pop()\n\n while (prop = parts.shift()) { // eslint-disable-line\n object = object[prop]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n return object[last]\n },\n\n /**\n * Return the superclass for the given instance or subclass. If an instance is\n * provided, then finds the parent class of the instance's constructor.\n *\n * @example\n * import {utils} from 'js-data'\n * // using ES2015 classes\n * class Foo {}\n * class Bar extends Foo {}\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * // using Function constructor with utils.extend\n * function Foo () {}\n * Foo.extend = utils.extend\n * const Bar = Foo.extend()\n * const barInstance = new Bar()\n * let baseType = utils.getSuper(barInstance)\n * console.log(Foo === baseType) // true\n *\n * @method utils.getSuper\n * @param {Object|Function} instance Instance or constructor.\n * @param {boolean} [isCtor=false] Whether `instance` is a constructor.\n * @returns {Constructor} The superclass (grandparent constructor).\n * @since 3.0.0\n */\n getSuper (instance, isCtor) {\n const ctor = isCtor ? instance : instance.constructor\n if (ctor.hasOwnProperty('__super__')) {\n return ctor.__super__\n }\n return Object.getPrototypeOf(ctor) || ctor.__proto__ // eslint-disable-line\n },\n\n /**\n * Return the intersection of two arrays.\n *\n * @example\n * import {utils} from 'js-data'\n * const arrA = ['green', 'red', 'blue', 'red']\n * const arrB = ['green', 'yellow', 'red']\n * const intersected = utils.intersection(arrA, arrB)\n *\n * console.log(intersected) // ['green', 'red'])\n *\n * @method utils.intersection\n * @param {Array} array1 First array.\n * @param {Array} array2 Second array.\n * @returns {Array} Array of elements common to both arrays.\n * @since 3.0.0\n */\n intersection (array1, array2) {\n if (!array1 || !array2) {\n return []\n }\n const result = []\n let item\n let i\n const len = array1.length\n for (i = 0; i < len; i++) {\n item = array1[i]\n if (result.indexOf(item) !== -1) {\n continue\n }\n if (array2.indexOf(item) !== -1) {\n result.push(item)\n }\n }\n return result\n },\n\n /**\n * Proxy for `Array.isArray`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = [1,2,3,4,5]\n * const b = { foo: \"bar\" }\n * console.log(utils.isArray(a)) // true\n * console.log(utils.isArray(b)) // false\n *\n * @method utils.isArray\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an array.\n * @since 3.0.0\n */\n isArray: Array.isArray,\n\n /**\n * Return whether `prop` is matched by any string or regular expression in\n * `blacklist`.\n *\n * @example\n * import {utils} from 'js-data'\n * const blacklist = [/^\\$hashKey/g, /^_/g, 'id']\n * console.log(utils.isBlacklisted(\"$hashKey\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"id\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"_myProp\", blacklist)) // true\n * console.log(utils.isBlacklisted(\"my_id\", blacklist)) // false\n *\n * @method utils.isBlacklisted\n * @param {string} prop The name of a property to check.\n * @param {Array} blacklist Array of strings and regular expressions.\n * @returns {boolean} Whether `prop` was matched.\n * @since 3.0.0\n */\n isBlacklisted (prop, blacklist) {\n if (!blacklist || !blacklist.length) {\n return false\n }\n let matches\n for (var i = 0; i < blacklist.length; i++) {\n if ((toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) || blacklist[i] === prop) {\n matches = prop\n return !!matches\n }\n }\n return !!matches\n },\n\n /**\n * Return whether the provided value is a boolean.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = true\n * const b = { foo: \"bar\" }\n * console.log(utils.isBoolean(a)) // true\n * console.log(utils.isBoolean(b)) // false\n *\n * @method utils.isBoolean\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a boolean.\n * @since 3.0.0\n */\n isBoolean (value) {\n return toStr(value) === BOOL_TAG\n },\n\n /**\n * Return whether the provided value is a date.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = new Date()\n * const b = { foo: \"bar\" }\n * console.log(utils.isDate(a)) // true\n * console.log(utils.isDate(b)) // false\n *\n * @method utils.isDate\n * @param {*} value The value to test.\n * @returns {Date} Whether the provided value is a date.\n * @since 3.0.0\n */\n isDate (value) {\n return (value && typeof value === 'object' && toStr(value) === DATE_TAG)\n },\n\n /**\n * Return whether the provided value is a function.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = function (){ console.log('foo bar')}\n * const b = { foo: \"bar\" }\n * console.log(utils.isFunction(a)) // true\n * console.log(utils.isFunction(b)) // false\n *\n * @method utils.isFunction\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a function.\n * @since 3.0.0\n */\n isFunction (value) {\n return typeof value === 'function' || (value && toStr(value) === FUNC_TAG)\n },\n\n /**\n * Return whether the provided value is an integer.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = 1.25\n * const c = '1'\n * console.log(utils.isInteger(a)) // true\n * console.log(utils.isInteger(b)) // false\n * console.log(utils.isInteger(c)) // false\n *\n * @method utils.isInteger\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an integer.\n * @since 3.0.0\n */\n isInteger (value) {\n return toStr(value) === NUMBER_TAG && value == toInteger(value) // eslint-disable-line\n },\n\n /**\n * Return whether the provided value is `null`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = null\n * const b = { foo: \"bar\" }\n * console.log(utils.isNull(a)) // true\n * console.log(utils.isNull(b)) // false\n *\n * @method utils.isNull\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is `null`.\n * @since 3.0.0\n */\n isNull (value) {\n return value === null\n },\n\n /**\n * Return whether the provided value is a number.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = 1\n * const b = -1.25\n * const c = '1'\n * console.log(utils.isNumber(a)) // true\n * console.log(utils.isNumber(b)) // true\n * console.log(utils.isNumber(c)) // false\n *\n * @method utils.isNumber\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a number.\n * @since 3.0.0\n */\n isNumber (value) {\n const type = typeof value\n return type === 'number' || (value && type === 'object' && toStr(value) === NUMBER_TAG)\n },\n\n /**\n * Return whether the provided value is an object.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\" }\n * const b = 'foo bar'\n * console.log(utils.isObject(a)) // true\n * console.log(utils.isObject(b)) // false\n *\n * @method utils.isObject\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is an object.\n * @since 3.0.0\n */\n isObject (value) {\n return toStr(value) === OBJECT_TAG\n },\n\n /**\n * Return whether the provided value is a regular expression.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = /^\\$.+$/ig\n * const b = new RegExp('^\\$.+$', 'ig')\n * const c = { foo: \"bar\" }\n * console.log(utils.isRegExp(a)) // true\n * console.log(utils.isRegExp(b)) // true\n * console.log(utils.isRegExp(c)) // false\n *\n * @method utils.isRegExp\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a regular expression.\n * @since 3.0.0\n */\n isRegExp (value) {\n return toStr(value) === REGEXP_TAG\n },\n\n /**\n * Return whether the provided value is a string or a number.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isSorN('')) // true\n * console.log(utils.isSorN(-1.65)) // true\n * console.log(utils.isSorN('my string')) // true\n * console.log(utils.isSorN({})) // false\n * console.log(utils.isSorN([1,2,4])) // false\n *\n * @method utils.isSorN\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string or a number.\n * @since 3.0.0\n */\n isSorN (value) {\n return utils.isString(value) || utils.isNumber(value)\n },\n\n /**\n * Return whether the provided value is a string.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('')) // true\n * console.log(utils.isString('my string')) // true\n * console.log(utils.isString(100)) // false\n * console.log(utils.isString([1,2,4])) // false\n *\n * @method utils.isString\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a string.\n * @since 3.0.0\n */\n isString (value) {\n return typeof value === 'string' || (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n },\n\n /**\n * Return whether the provided value is a `undefined`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = undefined\n * const b = { foo: \"bar\"}\n * console.log(utils.isUndefined(a)) // true\n * console.log(utils.isUndefined(b.baz)) // true\n * console.log(utils.isUndefined(b)) // false\n * console.log(utils.isUndefined(b.foo)) // false\n *\n * @method utils.isUndefined\n * @param {*} value The value to test.\n * @returns {boolean} Whether the provided value is a `undefined`.\n * @since 3.0.0\n */\n isUndefined (value) {\n return value === undefined\n },\n\n /**\n * Mix in logging capabilities to the target.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { foo: \"bar\"}\n *\n * // Add standard logging to an object\n * utils.logify(a)\n * a.log('info', 'test log info') // output 'test log info' to console.\n *\n * // Toggle debug output of an object\n * a.dbg('test debug output') // does not output because debug is off.\n * a.debug = true\n * a.dbg('test debug output') // output 'test debug output' to console.\n *\n * @method utils.logify\n * @param {*} target The target.\n * @since 3.0.0\n */\n logify (target) {\n utils.addHiddenPropsToTarget(target, {\n dbg (...args) {\n if (utils.isFunction(this.log)) {\n this.log('debug', ...args)\n }\n },\n log (level, ...args) {\n if (level && !args.length) {\n args.push(level)\n level = 'debug'\n }\n if (level === 'debug' && !this.debug) {\n return\n }\n const prefix = `${level.toUpperCase()}: (${this.name || this.constructor.name})`\n if (utils.isFunction(console[level])) {\n console[level](prefix, ...args)\n } else {\n console.log(prefix, ...args)\n }\n }\n })\n },\n\n /**\n * Adds the given record to the provided array only if it's not already in the\n * array.\n *\n * @example\n * import {utils} from 'js-data'\n * const colors = ['red', 'green', 'yellow']\n *\n * console.log(colors.length) // 3\n * utils.noDupeAdd(colors, 'red')\n * console.log(colors.length) // 3, red already exists\n *\n * utils.noDupeAdd(colors, 'blue')\n * console.log(colors.length) // 4, blue was added\n *\n * @method utils.noDupeAdd\n * @param {Array} array The array.\n * @param {*} record The value to add.\n * @param {Function} fn Callback function passed to {@link utils.findIndex}.\n * @since 3.0.0\n */\n noDupeAdd (array, record, fn) {\n if (!array) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index < 0) {\n array.push(record)\n }\n },\n\n /**\n * Return a shallow copy of the provided object, minus the properties\n * specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.omit(a, ['$hashKey'])\n * console.log(b) // { name: 'John' }\n *\n * @method utils.omit\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to skip.\n * @returns {Object} Shallow copy of `props`, minus `keys`.\n * @since 3.0.0\n */\n omit (props, keys) {\n const _props = {}\n utils.forOwn(props, function (value, key) {\n if (keys.indexOf(key) === -1) {\n _props[key] = value\n }\n })\n return _props\n },\n\n /**\n * Return a shallow copy of the provided object, but only include the\n * properties specified in `keys`.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John', $hashKey: 1214910 }\n *\n * let b = utils.pick(a, ['$hashKey'])\n * console.log(b) // { $hashKey: 1214910 }\n *\n * @method utils.pick\n * @param {Object} props The object to copy.\n * @param {string[]} keys Array of strings, representing properties to keep.\n * @returns {Object} Shallow copy of `props`, but only including `keys`.\n * @since 3.0.0\n */\n pick (props, keys) {\n return keys.reduce((map, key) => {\n map[key] = props[key]\n return map\n }, {})\n },\n\n /**\n * Return a plain copy of the given value.\n *\n * @example\n * import {utils} from 'js-data'\n * const a = { name: 'John' }\n * let b = utils.plainCopy(a)\n * console.log(a === b) // false\n *\n * @method utils.plainCopy\n * @param {*} value The value to copy.\n * @returns {*} Plain copy of `value`.\n * @see utils.copy\n * @since 3.0.0\n */\n plainCopy (value) {\n return utils.copy(value, undefined, undefined, undefined, undefined, true)\n },\n\n /**\n * Shortcut for `utils.Promise.reject(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.reject(\"Testing static reject\").then(function(data) {\n * // not called\n * }).catch(function(reason) {\n * console.log(reason); // \"Testing static reject\"\n * })\n *\n * @method utils.reject\n * @param {*} [value] Value with which to reject the Promise.\n * @returns {Promise} Promise reject with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n reject (value) {\n return utils.Promise.reject(value)\n },\n\n /**\n * Remove the last item found in array according to the given checker function.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const colors = ['red', 'green', 'yellow', 'red']\n * utils.remove(colors, (color) => color === 'red')\n * console.log(colors) // ['red', 'green', 'yellow']\n *\n * @method utils.remove\n * @param {Array} array The array to search.\n * @param {Function} fn Checker function.\n */\n remove (array, fn) {\n if (!array || !array.length) {\n return\n }\n const index = this.findIndex(array, fn)\n if (index >= 0) {\n array.splice(index, 1) // todo should this be recursive?\n }\n },\n\n /**\n * Shortcut for `utils.Promise.resolve(value)`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * utils.resolve(\"Testing static resolve\").then(function(data) {\n * console.log(data); // \"Testing static resolve\"\n * }).catch(function(reason) {\n * // not called\n * })\n *\n * @param {*} [value] Value with which to resolve the Promise.\n * @returns {Promise} Promise resolved with `value`.\n * @see utils.Promise\n * @since 3.0.0\n */\n resolve (value) {\n return utils.Promise.resolve(value)\n },\n\n /**\n * Set the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n * // set value by key\n * utils.set(john, 'id', 98)\n * console.log(john.id) // 98\n *\n * // set value by path\n * utils.set(john, 'parent.id', 20)\n * console.log(john.parent.id) // 20\n *\n * // set value by path/value map\n * utils.set(john, {\n * 'id': 1098,\n * 'parent': { id: 1020 },\n * 'parent.age': '55'\n * })\n * console.log(john.id) // 1098\n * console.log(john.parent.id) // 1020\n * console.log(john.parent.age) // 55\n *\n * @method utils.set\n * @param {Object} object The object on which to set a property.\n * @param {(string|Object)} path The key or path to the property. Can also\n * pass in an object of path/value pairs, which will all be set on the target\n * object.\n * @param {*} [value] The value to set.\n */\n set: function (object, path, value) {\n if (utils.isObject(path)) {\n utils.forOwn(path, function (value, _path) {\n utils.set(object, _path, value)\n })\n } else {\n const parts = PATH.exec(path)\n if (parts) {\n mkdirP(object, parts[1])[parts[2]] = value\n } else {\n object[path] = value\n }\n }\n },\n\n /**\n * Check whether the two provided objects are deeply equal.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const objA = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * const objB = {\n * name: 'John',\n * id: 27,\n * nested: {\n * item: 'item 1',\n * colors: ['red', 'green', 'blue']\n * }\n * }\n *\n * console.log(utils.deepEqual(a,b)) // true\n * objB.nested.colors.add('yellow') // make a change to a nested object's array\n * console.log(utils.deepEqual(a,b)) // false\n *\n * @method utils.deepEqual\n * @param {Object} a First object in the comparison.\n * @param {Object} b Second object in the comparison.\n * @returns {boolean} Whether the two provided objects are deeply equal.\n * @see utils.equal\n * @since 3.0.0\n */\n deepEqual (a, b) {\n if (a === b) {\n return true\n }\n let _equal = true\n if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n _equal = _equal && utils.deepEqual(value, b[key])\n })\n if (!_equal) {\n return _equal\n }\n utils.forOwn(b, function (value, key) {\n _equal = _equal && utils.deepEqual(value, a[key])\n })\n } else if (utils.isArray(a) && utils.isArray(b)) {\n a.forEach(function (value, i) {\n _equal = _equal && utils.deepEqual(value, b[i])\n if (!_equal) {\n return false\n }\n })\n } else {\n return false\n }\n return _equal\n },\n\n /**\n * Proxy for `JSON.stringify`.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const a = { name: 'John' }\n * let jsonVal = utils.toJson(a)\n * console.log(jsonVal) // '{\"name\" : \"John\"}'\n *\n * @method utils.toJson\n * @param {*} value Value to serialize to JSON.\n * @returns {string} JSON string.\n * @see utils.fromJson\n * @since 3.0.0\n */\n toJson: JSON.stringify,\n\n /**\n * Unset the value at the provided key or path.\n *\n * @example\n * import {utils} from 'js-data'\n *\n * const john = {\n * name: 'John',\n * age: 25,\n * parent: {\n * name: 'John's Mom',\n * age: 50\n * }\n * }\n *\n * utils.unset(john, age)\n * utils.unset(john, parent.age)\n *\n * console.log(john.age) // null\n * console.log(john.parent.age) // null\n *\n * @method utils.unset\n * @param {Object} object The object from which to delete the property.\n * @param {string} path The key or path to the property.\n * @see utils.set\n * @since 3.0.0\n */\n unset (object, path) {\n const parts = path.split('.')\n const last = parts.pop()\n\n while (path = parts.shift()) { // eslint-disable-line\n object = object[path]\n if (object == null) { // eslint-disable-line\n return\n }\n }\n\n object[last] = undefined\n }\n}\n\nexport const safeSetProp = function (record, field, value) {\n if (record && record._set) {\n record._set(`props.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport const safeSetLink = function (record, field, value) {\n if (record && record._set) {\n record._set(`links.${field}`, value)\n } else {\n utils.set(record, field, value)\n }\n}\n\nexport default utils\n","import utils from './utils'\n\n/**\n * A base class which gives instances private properties.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Settable.extend} for an example of using {@link Settable} as a\n * base class.\n *\n *```javascript\n * import {Settable} from 'js-data'\n * ```\n *\n * @class Settable\n * @returns {Settable} A new {@link Settable} instance.\n * @since 3.0.0\n */\nexport default function Settable () {\n const _props = {}\n Object.defineProperties(this, {\n /**\n * Get a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method Settable#_get\n * @param {string} key The property to retrieve.\n * @returns {*} The value of the property.\n * @since 3.0.0\n */\n _get: { value (key) { return utils.get(_props, key) } },\n\n /**\n * Set a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_set\n * @param {(string|Object)} key The key or path to the property. Can also\n * pass in an object of key/value pairs, which will all be set on the instance.\n * @param {*} [value] The value to set.\n * @since 3.0.0\n */\n _set: { value (key, value) { return utils.set(_props, key, value) } },\n\n /**\n * Unset a private property of this instance.\n *\n * __Don't use the method unless you know what you're doing.__\n *\n * @method __Don't use the method unless you know what you're doing.__#_unset\n * @param {string} key The property to unset.\n * @since 3.0.0\n */\n _unset: { value (key) { return utils.unset(_props, key) } }\n })\n}\n\n/**\n * Create a subclass of this Settable:\n *\n * @example Settable.extend\n * // Normally you would do: import {Settable} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Settable} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSettableClass extends Settable {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSettable = new CustomSettableClass()\n * console.log(customSettable.foo())\n * console.log(CustomSettableClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSettableClass = Settable.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSettable = new OtherSettableClass()\n * console.log(otherSettable.foo())\n * console.log(OtherSettableClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSettableClass () {\n * Settable.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Settable.extend({\n * constructor: AnotherSettableClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSettable = new AnotherSettableClass()\n * console.log(anotherSettable.created_at)\n * console.log(anotherSettable.foo())\n * console.log(AnotherSettableClass.beep())\n *\n * @method Settable.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Settable class.\n * @since 3.0.0\n */\nSettable.extend = utils.extend\n","import utils from './utils'\nimport Settable from './Settable'\n\n/**\n * The base class from which all JSData components inherit some basic\n * functionality.\n *\n * Typically you won't instantiate this class directly, but you may find it\n * useful as an abstract class for your own components.\n *\n * See {@link Component.extend} for an example of using {@link Component} as a\n * base class.\n *\n *```javascript\n * import {Component} from 'js-data'\n * ```\n *\n * @class Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @returns {Component} A new {@link Component} instance.\n * @since 3.0.0\n */\nfunction Component (opts) {\n Settable.call(this)\n opts || (opts = {})\n\n /**\n * Whether to enable debug-level logs for this component. Anything that\n * extends `Component` inherits this option and the corresponding logging\n * functionality.\n *\n * @example Component#debug\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const component = new Component()\n * component.log('debug', 'some message') // nothing gets logged\n * // Display debug logs:\n * component.debug = true\n * component.log('debug', 'other message') // this DOES get logged\n *\n * @default false\n * @name Component#debug\n * @since 3.0.0\n * @type {boolean}\n */\n this.debug = opts.hasOwnProperty('debug') ? !!opts.debug : false\n\n /**\n * Event listeners attached to this Component. __Do not modify.__ Use\n * {@link Component#on} and {@link Component#off} instead.\n *\n * @name Component#_listeners\n * @instance\n * @since 3.0.0\n * @type {Object}\n */\n Object.defineProperty(this, '_listeners', { value: {}, writable: true })\n}\n\nexport default Settable.extend({\n constructor: Component\n})\n\n/**\n * Create a subclass of this Component:\n *\n * @example Component.extend\n * // Normally you would do: import {Component} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Component} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomComponentClass extends Component {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customComponent = new CustomComponentClass()\n * console.log(customComponent.foo())\n * console.log(CustomComponentClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherComponentClass = Component.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherComponent = new OtherComponentClass()\n * console.log(otherComponent.foo())\n * console.log(OtherComponentClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherComponentClass () {\n * Component.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Component.extend({\n * constructor: AnotherComponentClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherComponent = new AnotherComponentClass()\n * console.log(anotherComponent.created_at)\n * console.log(anotherComponent.foo())\n * console.log(AnotherComponentClass.beep())\n *\n * @method Component.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Component class.\n * @since 3.0.0\n */\nComponent.extend = utils.extend\n\n/**\n * Log the provided values at the \"debug\" level. Debug-level logs are only\n * logged if {@link Component#debug} is `true`.\n *\n * `.dbg(...)` is shorthand for `.log('debug', ...)`.\n *\n * @method Component#dbg\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\n/**\n * Log the provided values. By default sends values to `console[level]`.\n * Debug-level logs are only logged if {@link Component#debug} is `true`.\n *\n * Will attempt to use appropriate `console` methods if they are available.\n *\n * @method Component#log\n * @param {string} level Log level.\n * @param {...*} [args] Values to log.\n * @since 3.0.0\n */\nutils.logify(Component.prototype)\n\n/**\n * Register a new event listener on this Component.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a DataStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * collection.on('add', (records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * post.on('change', (record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method Component#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n/**\n * Remove an event listener from this Component. If no listener is provided,\n * then all listeners for the specified event will be removed. If no event is\n * specified then all listeners for all events will be removed.\n *\n * @example\n * // Remove a particular listener for a particular event\n * collection.off('add', handler)\n *\n * @example\n * // Remove all listeners for a particular event\n * record.off('change')\n *\n * @example\n * // Remove all listeners to all events\n * store.off()\n *\n * @method Component#off\n * @param {string} [event] Name of event to unsubsribe to.\n * @param {Function} [listener] Listener to remove.\n * @since 3.0.0\n */\n/**\n * Trigger an event on this Component.\n *\n * @example Component#emit\n * // import {Collection, DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, DataStore} = JSData\n *\n * const collection = new Collection()\n * collection.on('foo', function (msg) {\n * console.log(msg)\n * })\n * collection.emit('foo', 'bar')\n *\n * const store = new DataStore()\n * store.on('beep', function (msg) {\n * console.log(msg)\n * })\n * store.emit('beep', 'boop')\n *\n * @method Component#emit\n * @param {string} event Name of event to emit.\n * @param {...*} [args] Arguments to pass to any listeners.\n * @since 3.0.0\n */\nutils.eventify(\n Component.prototype,\n function () {\n return this._listeners\n },\n function (value) {\n this._listeners = value\n }\n)\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Query'\nconst INDEX_ERR = 'Index inaccessible after first operation'\n\n// Reserved words used by JSData's Query Syntax\nconst reserved = {\n limit: '',\n offset: '',\n orderBy: '',\n skip: '',\n sort: '',\n where: ''\n}\n\n// Used by our JavaScript implementation of the LIKE operator\nconst escapeRegExp = /([.*+?^=!:${}()|[\\]/\\\\])/g\nconst percentRegExp = /%/g\nconst underscoreRegExp = /_/g\nconst escape = function (pattern) {\n return pattern.replace(escapeRegExp, '\\\\$1')\n}\n\n/**\n * A class used by the {@link Collection} class to build queries to be executed\n * against the collection's data. An instance of `Query` is returned by\n * {@link Collection#query}. Query instances are typically short-lived, and you\n * shouldn't have to create them yourself. Just use {@link Collection#query}.\n *\n * ```javascript\n * import {Query} from 'js-data'\n * ```\n *\n * @example\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const drafts = store.query('post').filter({ status: 'draft' }).limit(2).run()\n * console.log(drafts)\n *\n * @class Query\n * @extends Component\n * @param {Collection} collection The collection on which this query operates.\n * @since 3.0.0\n */\nfunction Query (collection) {\n utils.classCallCheck(this, Query)\n\n /**\n * The {@link Collection} on which this query operates.\n *\n * @name Query#collection\n * @since 3.0.0\n * @type {Collection}\n */\n this.collection = collection\n\n /**\n * The current data result of this query.\n *\n * @name Query#data\n * @since 3.0.0\n * @type {Array}\n */\n this.data = null\n}\n\nexport default Component.extend({\n constructor: Query,\n\n _applyWhereFromObject (where) {\n const fields = []\n const ops = []\n const predicates = []\n utils.forOwn(where, (clause, field) => {\n if (!utils.isObject(clause)) {\n clause = {\n '==': clause\n }\n }\n utils.forOwn(clause, (expr, op) => {\n fields.push(field)\n ops.push(op)\n predicates.push(expr)\n })\n })\n return {\n fields,\n ops,\n predicates\n }\n },\n\n _applyWhereFromArray (where) {\n const groups = []\n where.forEach((_where, i) => {\n if (utils.isString(_where)) {\n return\n }\n const prev = where[i - 1]\n const parser = utils.isArray(_where) ? this._applyWhereFromArray : this._applyWhereFromObject\n const group = parser.call(this, _where)\n if (prev === 'or') {\n group.isOr = true\n }\n groups.push(group)\n })\n groups.isArray = true\n return groups\n },\n\n _testObjectGroup (keep, first, group, item) {\n let i\n const fields = group.fields\n const ops = group.ops\n const predicates = group.predicates\n const len = ops.length\n for (i = 0; i < len; i++) {\n let op = ops[i]\n const isOr = op.charAt(0) === '|'\n op = isOr ? op.substr(1) : op\n const expr = this.evaluate(utils.get(item, fields[i]), op, predicates[i])\n if (expr !== undefined) {\n keep = first ? expr : (isOr ? keep || expr : keep && expr)\n }\n first = false\n }\n return { keep, first }\n },\n\n _testArrayGroup (keep, first, groups, item) {\n let i\n const len = groups.length\n for (i = 0; i < len; i++) {\n const group = groups[i]\n const parser = group.isArray ? this._testArrayGroup : this._testObjectGroup\n const result = parser.call(this, true, true, group, item)\n if (groups[i - 1]) {\n if (group.isOr) {\n keep = keep || result.keep\n } else {\n keep = keep && result.keep\n }\n } else {\n keep = result.keep\n }\n first = result.first\n }\n return { keep, first }\n },\n\n /**\n * Find all entities between two boundaries.\n *\n * @example Get the users ages 18 to 30.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between(18, 30, { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @example Same as above.\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const filteredUsers = store.query('user').between([18], [30], { index: 'age' }).run()\n * console.log(filteredUsers)\n *\n * @method Query#between\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include entities\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#between`)(500, 'Cannot access index')\n }\n this.data = this.collection.getIndex(opts.index).between(leftKeys, rightKeys, opts)\n return this\n },\n\n /**\n * The comparison function used by the {@link Query} class.\n *\n * @method Query#compare\n * @param {Array} orderBy An orderBy clause used for sorting and sub-sorting.\n * @param {number} index The index of the current orderBy clause being used.\n * @param {*} a The first item in the comparison.\n * @param {*} b The second item in the comparison.\n * @returns {number} -1 if `b` should preceed `a`. 0 if `a` and `b` are equal.\n * 1 if `a` should preceed `b`.\n * @since 3.0.0\n */\n compare (orderBy, index, a, b) {\n const def = orderBy[index]\n let cA = utils.get(a, def[0])\n let cB = utils.get(b, def[0])\n if (cA && utils.isString(cA)) {\n cA = cA.toUpperCase()\n }\n if (cB && utils.isString(cB)) {\n cB = cB.toUpperCase()\n }\n if (a === undefined) {\n a = null\n }\n if (b === undefined) {\n b = null\n }\n if (def[1].toUpperCase() === 'DESC') {\n const temp = cB\n cB = cA\n cA = temp\n }\n if (cA < cB) {\n return -1\n } else if (cA > cB) {\n return 1\n } else {\n if (index < orderBy.length - 1) {\n return this.compare(orderBy, index + 1, a, b)\n } else {\n return 0\n }\n }\n },\n\n /**\n * Predicate evaluation function used by the {@link Query} class.\n *\n * @method Query#evaluate\n * @param {*} value The value to evaluate.\n * @param {string} op The operator to use in this evaluation.\n * @param {*} predicate The predicate to use in this evaluation.\n * @returns {boolean} Whether the value passed the evaluation or not.\n * @since 3.0.0\n */\n evaluate (value, op, predicate) {\n const ops = this.constructor.ops\n if (ops[op]) {\n return ops[op](value, predicate)\n }\n if (op.indexOf('like') === 0) {\n return this.like(predicate, op.substr(4)).exec(value) !== null\n } else if (op.indexOf('notLike') === 0) {\n return this.like(predicate, op.substr(7)).exec(value) === null\n }\n },\n\n /**\n * Find the record or records that match the provided query or are accepted by\n * the provided filter function.\n *\n * @example Get the draft posts by authors younger than 30\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * let results = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * }).run()\n * console.log(results)\n *\n * @example Use a custom filter function\n * const posts = query.filter(function (post) {\n * return post.isReady()\n * }).run()\n *\n * @method Query#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Function} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n filter (query, thisArg) {\n /**\n * Selection query as defined by JSData's [Query Syntax][querysyntax].\n *\n * [querysyntax]: http://www.js-data.io/v3.0/docs/query-syntax\n *\n * @example Empty \"findAll\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @example Empty \"filter\" query\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = store.filter('post')\n * console.log(posts) // [...]\n *\n * @example Complex \"filter\" query\n * const PAGE_SIZE = 2\n * let currentPage = 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * { author: 'Peter', age: 25, status: 'deleted', id: 6 },\n * { author: 'Sally', age: 21, status: 'draft', id: 7 },\n * { author: 'Jim', age: 27, status: 'draft', id: 8 },\n * { author: 'Jim', age: 27, status: 'published', id: 9 },\n * { author: 'Jason', age: 55, status: 'published', id: 10 }\n * ]\n * store.add('post', posts)\n * // Retrieve a filtered page of blog posts\n * // Would typically replace filter with findAll\n * store.filter('post', {\n * where: {\n * status: {\n * // WHERE status = 'published'\n * '==': 'published'\n * },\n * author: {\n * // AND author IN ('bob', 'alice')\n * 'in': ['bob', 'alice'],\n * // OR author IN ('karen')\n * '|in': ['karen']\n * }\n * },\n * orderBy: [\n * // ORDER BY date_published DESC,\n * ['date_published', 'DESC'],\n * // ORDER BY title ASC\n * ['title', 'ASC']\n * ],\n * // LIMIT 2\n * limit: PAGE_SIZE,\n * // SKIP 4\n * offset: PAGE_SIZE * (currentPage - 1)\n * })\n *\n * @namespace query\n * @property {number} [limit] See {@link query.limit}.\n * @property {number} [offset] See {@link query.offset}.\n * @property {string|Array[]} [orderBy] See {@link query.orderBy}.\n * @property {number} [skip] Alias for {@link query.offset}.\n * @property {string|Array[]} [sort] Alias for {@link query.orderBy}.\n * @property {Object} [where] See {@link query.where}.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/query-syntax\",\"JSData's Query Syntax\"]\n */\n query || (query = {})\n this.getData()\n if (utils.isObject(query)) {\n let where = {}\n\n /**\n * Filtering criteria. Records that do not meet this criteria will be exluded\n * from the result.\n *\n * @example Return posts where author is at least 32 years old\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * where: {\n * age: {\n * '>=': 30\n * }\n * }\n * })\n * console.log(results)\n *\n * @name query.where\n * @type {Object}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isObject(query.where) || utils.isArray(query.where)) {\n where = query.where\n }\n utils.forOwn(query, function (value, key) {\n if (!(key in reserved) && !(key in where)) {\n where[key] = {\n '==': value\n }\n }\n })\n let groups\n\n // Apply filter for each field\n if (utils.isObject(where) && Object.keys(where).length !== 0) {\n groups = this._applyWhereFromArray([where])\n } else if (utils.isArray(where)) {\n groups = this._applyWhereFromArray(where)\n }\n\n if (groups) {\n this.data = this.data.filter((item, i) => this._testArrayGroup(true, true, groups, item).keep)\n }\n\n // Sort\n let orderBy = query.orderBy || query.sort\n\n if (utils.isString(orderBy)) {\n orderBy = [\n [orderBy, 'ASC']\n ]\n }\n if (!utils.isArray(orderBy)) {\n orderBy = null\n }\n\n /**\n * Determines how records should be ordered in the result.\n *\n * @example Order posts by `author` then by `id` descending \n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 5 },\n * { author: 'Sally', age: 31, id: 6 },\n * { author: 'Mike', age: 32, id: 7 },\n * { author: 'Adam', age: 33, id: 8 },\n * { author: 'Adam', age: 33, id: 9 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * orderBy:[['author','ASC'],['id','DESC']]\n * })\n * console.log(results)\n *\n * @name query.orderBy\n * @type {string|Array[]}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (orderBy) {\n let index = 0\n orderBy.forEach(function (def, i) {\n if (utils.isString(def)) {\n orderBy[i] = [def, 'ASC']\n }\n })\n this.data.sort((a, b) => this.compare(orderBy, index, a, b))\n }\n\n /**\n * Number of records to skip.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n *\n * @name query.offset\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.skip)) {\n this.skip(query.skip)\n } else if (utils.isNumber(query.offset)) {\n this.skip(query.offset)\n }\n\n /**\n * Maximum number of records to retrieve.\n *\n * @example Retrieve the first \"page\" of blog posts using findAll\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * PostMapper.findAll({\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * @example Retrieve the last \"page\" of blog posts using filter\n * const PAGE_SIZE = 5\n * let currentPage = 2\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, id: 1 },\n * { author: 'Sally', age: 31, id: 2 },\n * { author: 'Mike', age: 32, id: 3 },\n * { author: 'Adam', age: 33, id: 4 },\n * { author: 'Adam', age: 33, id: 5 },\n * { author: 'Peter', age: 25, id: 6 },\n * { author: 'Sally', age: 21, id: 7 },\n * { author: 'Jim', age: 27, id: 8 },\n * { author: 'Jim', age: 27, id: 9 },\n * { author: 'Jason', age: 55, id: 10 }\n * ]\n * store.add('post', posts)\n * store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * })\n *\n * console.log(results)\n * @name query.limit\n * @type {number}\n * @see http://www.js-data.io/v3.0/docs/query-syntax\n * @since 3.0.0\n */\n if (utils.isNumber(query.limit)) {\n this.limit(query.limit)\n }\n } else if (utils.isFunction(query)) {\n this.data = this.data.filter(query, thisArg)\n }\n return this\n },\n\n /**\n * Iterate over all entities.\n *\n * @method Query#forEach\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n forEach (forEachFn, thisArg) {\n this.getData().forEach(forEachFn, thisArg)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided key.\n *\n * @example Get the entity whose primary key is 25.\n * const entities = query.get(25).run()\n *\n * @example Same as above.\n * const entities = query.get([25]).run()\n *\n * @example Get all users who are active and have the \"admin\" role.\n * const activeAdmins = query.get(['active', 'admin'], {\n * index: 'activityAndRoles'\n * }).run()\n *\n * @example Get all entities that match a certain weather condition.\n * const niceDays = query.get(['sunny', 'humid', 'calm'], {\n * index: 'weatherConditions'\n * }).run()\n *\n * @method Query#get\n * @param {Array} keyList Key(s) defining the entity to retrieve. If\n * `keyList` is not an array (i.e. for a single-value key), it will be\n * wrapped in an array.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.string] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n get (keyList, opts) {\n keyList || (keyList = [])\n opts || (opts = {})\n if (this.data) {\n throw utils.err(`${DOMAIN}#get`)(500, INDEX_ERR)\n }\n if (keyList && !utils.isArray(keyList)) {\n keyList = [keyList]\n }\n if (!keyList.length) {\n this.getData()\n return this\n }\n this.data = this.collection.getIndex(opts.index).get(keyList)\n return this\n },\n\n /**\n * Find the entity or entities that match the provided keyLists.\n *\n * @example Get the posts where \"status\" is \"draft\" or \"inReview\".\n * const posts = query.getAll('draft', 'inReview', { index: 'status' }).run()\n *\n * @example Same as above.\n * const posts = query.getAll(['draft'], ['inReview'], { index: 'status' }).run()\n *\n * @method Query#getAll\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * entities matching each keyList will be retrieved. If no keyLists are\n * provided, all entities will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n getAll (...args) {\n let opts = {}\n if (this.data) {\n throw utils.err(`${DOMAIN}#getAll`)(500, INDEX_ERR)\n }\n if (!args.length || args.length === 1 && utils.isObject(args[0])) {\n this.getData()\n return this\n } else if (args.length && utils.isObject(args[args.length - 1])) {\n opts = args[args.length - 1]\n args.pop()\n }\n const collection = this.collection\n const index = collection.getIndex(opts.index)\n this.data = []\n args.forEach((keyList) => {\n this.data = this.data.concat(index.get(keyList))\n })\n return this\n },\n\n /**\n * Return the current data result of this query.\n *\n * @method Query#getData\n * @returns {Array} The data in this query.\n * @since 3.0.0\n */\n getData () {\n if (!this.data) {\n this.data = this.collection.index.getAll()\n }\n return this.data\n },\n\n /**\n * Implementation used by the `like` operator. Takes a pattern and flags and\n * returns a `RegExp` instance that can test strings.\n *\n * @method Query#like\n * @param {string} pattern Testing pattern.\n * @param {string} flags Flags for the regular expression.\n * @returns {RegExp} Regular expression for testing strings.\n * @since 3.0.0\n */\n like (pattern, flags) {\n return new RegExp(`^${(escape(pattern).replace(percentRegExp, '.*').replace(underscoreRegExp, '.'))}$`, flags)\n },\n\n /**\n * Limit the result.\n *\n * @example Get only the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').limit(2).run()\n * console.log(results)\n *\n * @method Query#limit\n * @param {number} num The maximum number of entities to keep in the result.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n limit (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#limit`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n this.data = data.slice(0, Math.min(data.length, num))\n return this\n },\n\n /**\n * Apply a mapping function to the result data.\n *\n * @example\n * // Return the age of all users\n * const store = new JSData.DataStore()\n * store.defineMapper('user')\n * const users = [\n * { name: 'Peter', age: 25, id: 1 },\n * { name: 'Jim', age: 19, id: 2 },\n * { name: 'Mike', age: 17, id: 3 },\n * { name: 'Alan', age: 29, id: 4 },\n * { name: 'Katie', age: 33, id: 5 }\n * ]\n * store.add('post', posts)\n * const ages = store.query('user').map((user) => {\n * return user.age\n * }).run()\n * console.log(ages)\n *\n * @method Query#map\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n map (mapFn, thisArg) {\n this.data = this.getData().map(mapFn, thisArg)\n return this\n },\n\n /**\n * Return the result of calling the specified function on each item in this\n * collection's main index.\n *\n * @example\n * const stringAges = UserCollection.query().mapCall('toString').run()\n *\n * @method Query#mapCall\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n mapCall (funcName, ...args) {\n this.data = this.getData().map(function (item) {\n return item[funcName](...args)\n })\n return this\n },\n\n /**\n * Complete the execution of the query and return the resulting data.\n *\n * @method Query#run\n * @returns {Array} The result of executing this query.\n * @since 3.0.0\n */\n run () {\n const data = this.data\n this.data = null\n return data\n },\n\n /**\n * Skip a number of results.\n *\n * @example Get all but the first 2 posts.\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'draft', id: 2 },\n * { author: 'Mike', age: 32, status: 'draft', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'draft', id: 5 }\n * ]\n * store.add('post', posts)\n * const results = store.query('post').skip(2).run()\n * console.log(results)\n *\n * @method Query#skip\n * @param {number} num The number of entities to skip.\n * @returns {Query} A reference to itself for chaining.\n * @since 3.0.0\n */\n skip (num) {\n if (!utils.isNumber(num)) {\n throw utils.err(`${DOMAIN}#skip`, 'num')(400, 'number', num)\n }\n const data = this.getData()\n if (num < data.length) {\n this.data = data.slice(num)\n } else {\n this.data = []\n }\n return this\n }\n}, {\n /**\n * The filtering operators supported by {@link Query#filter}, and which are\n * implemented by adapters (for the most part).\n *\n * @example Variant 1\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n *\n * @example Variant 2\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * })\n *\n * console.log(publishedPosts)\n *\n * @example Variant 3\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * status: 'published'\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Variant 4\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const publishedPosts = store.query('post').filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * }).limit(2).run()\n *\n * console.log(publishedPosts)\n *\n * @example Multiple operators\n *\n * const store = new JSData.DataStore()\n * store.defineMapper('post')\n * const posts = [\n * { author: 'John', age: 30, status: 'published', id: 1 },\n * { author: 'Sally', age: 31, status: 'published', id: 2 },\n * { author: 'Mike', age: 32, status: 'published', id: 3 },\n * { author: 'Adam', age: 33, status: 'deleted', id: 4 },\n * { author: 'Adam', age: 33, status: 'published', id: 5 }\n * ]\n * store.add('post', posts)\n *\n * const myPublishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * },\n * user_id: {\n * '==': currentUser.id\n * }\n * }\n * })\n *\n * console.log(myPublishedPosts)\n *\n * @name Query.ops\n * @property {Function} == Equality operator.\n * @property {Function} != Inequality operator.\n * @property {Function} > Greater than operator.\n * @property {Function} >= Greater than (inclusive) operator.\n * @property {Function} < Less than operator.\n * @property {Function} <= Less than (inclusive) operator.\n * @property {Function} isectEmpty Operator that asserts that the intersection\n * between two arrays is empty.\n * @property {Function} isectNotEmpty Operator that asserts that the\n * intersection between two arrays is __not__ empty.\n * @property {Function} in Operator that asserts whether a value is in an\n * array.\n * @property {Function} notIn Operator that asserts whether a value is __not__\n * in an array.\n * @property {Function} contains Operator that asserts whether an array\n * contains a value.\n * @property {Function} notContains Operator that asserts whether an array\n * does __not__ contain a value.\n * @since 3.0.0\n * @type {Object}\n */\n ops: {\n '=': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '==': function (value, predicate) {\n return value == predicate // eslint-disable-line\n },\n '===': function (value, predicate) {\n return value === predicate\n },\n '!=': function (value, predicate) {\n return value != predicate // eslint-disable-line\n },\n '!==': function (value, predicate) {\n return value !== predicate\n },\n '>': function (value, predicate) {\n return value > predicate\n },\n '>=': function (value, predicate) {\n return value >= predicate\n },\n '<': function (value, predicate) {\n return value < predicate\n },\n '<=': function (value, predicate) {\n return value <= predicate\n },\n 'isectEmpty': function (value, predicate) {\n return !utils.intersection((value || []), (predicate || [])).length\n },\n 'isectNotEmpty': function (value, predicate) {\n return utils.intersection((value || []), (predicate || [])).length\n },\n 'in': function (value, predicate) {\n return predicate.indexOf(value) !== -1\n },\n 'notIn': function (value, predicate) {\n return predicate.indexOf(value) === -1\n },\n 'contains': function (value, predicate) {\n return (value || []).indexOf(predicate) !== -1\n },\n 'notContains': function (value, predicate) {\n return (value || []).indexOf(predicate) === -1\n }\n }\n})\n\n/**\n * Create a subclass of this Query:\n * @example Query.extend\n * // Normally you would do: import {Query} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Query} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomQueryClass extends Query {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customQuery = new CustomQueryClass()\n * console.log(customQuery.foo())\n * console.log(CustomQueryClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherQueryClass = Query.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherQuery = new OtherQueryClass()\n * console.log(otherQuery.foo())\n * console.log(OtherQueryClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherQueryClass (collection) {\n * Query.call(this, collection)\n * this.created_at = new Date().getTime()\n * }\n * Query.extend({\n * constructor: AnotherQueryClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherQuery = new AnotherQueryClass()\n * console.log(anotherQuery.created_at)\n * console.log(anotherQuery.foo())\n * console.log(AnotherQueryClass.beep())\n *\n * @method Query.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Query class.\n * @since 3.0.0\n */\n","export function sort (a, b, hashCode) {\n // Short-circuit comparison if a and b are strictly equal\n // This is absolutely necessary for indexed objects that\n // don't have the idAttribute field\n if (a === b) {\n return 0\n }\n if (hashCode) {\n a = hashCode(a)\n b = hashCode(b)\n }\n if ((a === null && b === null) || (a === undefined && b === undefined)) {\n return -1\n }\n\n if (a === null || a === undefined) {\n return -1\n }\n\n if (b === null || b === undefined) {\n return 1\n }\n\n if (a < b) {\n return -1\n }\n\n if (a > b) {\n return 1\n }\n\n return 0\n}\n\nexport function insertAt (array, index, value) {\n array.splice(index, 0, value)\n return array\n}\n\nexport function removeAt (array, index) {\n array.splice(index, 1)\n return array\n}\n\nexport function binarySearch (array, value, field) {\n let lo = 0\n let hi = array.length\n let compared\n let mid\n\n while (lo < hi) {\n mid = ((lo + hi) / 2) | 0\n compared = sort(value, array[mid], field)\n if (compared === 0) {\n return {\n found: true,\n index: mid\n }\n } else if (compared < 0) {\n hi = mid\n } else {\n lo = mid + 1\n }\n }\n\n return {\n found: false,\n index: hi\n }\n}\n","// Copyright (c) 2015, InternalFX.\n\n// Permission to use, copy, modify, and/or distribute this software for any purpose with or\n// without fee is hereby granted, provided that the above copyright notice and this permission\n// notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO\n// THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT\n// SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR\n// ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE\n// USE OR PERFORMANCE OF THIS SOFTWARE.\n\n// Modifications\n// Copyright 2015-2016 Jason Dobry\n//\n// Summary of modifications:\n// Reworked dependencies so as to re-use code already in js-data\n// Removed unused code\nimport utils from '../../src/utils'\nimport {binarySearch, insertAt, removeAt} from './_utils'\n\nexport default function Index (fieldList, opts) {\n utils.classCallCheck(this, Index)\n fieldList || (fieldList = [])\n\n if (!utils.isArray(fieldList)) {\n throw new Error('fieldList must be an array.')\n }\n\n opts || (opts = {})\n this.fieldList = fieldList\n this.fieldGetter = opts.fieldGetter\n this.hashCode = opts.hashCode\n this.isIndex = true\n this.keys = []\n this.values = []\n}\n\nutils.addHiddenPropsToTarget(Index.prototype, {\n 'set' (keyList, value) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n let dataLocation = binarySearch(this.values[pos.index], value, this.hashCode)\n if (!dataLocation.found) {\n insertAt(this.values[pos.index], dataLocation.index, value)\n }\n } else {\n insertAt(this.keys, pos.index, key)\n insertAt(this.values, pos.index, [value])\n }\n } else {\n if (pos.found) {\n this.values[pos.index].set(keyList, value)\n } else {\n insertAt(this.keys, pos.index, key)\n let newIndex = new Index([], { hashCode: this.hashCode })\n newIndex.set(keyList, value)\n insertAt(this.values, pos.index, newIndex)\n }\n }\n },\n\n 'get' (keyList) {\n if (!utils.isArray(keyList)) {\n keyList = [keyList]\n }\n\n let key = keyList.shift() || undefined\n let pos = binarySearch(this.keys, key)\n\n if (keyList.length === 0) {\n if (pos.found) {\n if (this.values[pos.index].isIndex) {\n return this.values[pos.index].getAll()\n } else {\n return this.values[pos.index].slice()\n }\n } else {\n return []\n }\n } else {\n if (pos.found) {\n return this.values[pos.index].get(keyList)\n } else {\n return []\n }\n }\n },\n\n getAll (opts) {\n opts || (opts = {})\n let results = []\n const values = this.values\n if (opts.order === 'desc') {\n for (let i = values.length - 1; i >= 0; i--) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n } else {\n for (let i = 0; i < values.length; i++) {\n const value = values[i]\n if (value.isIndex) {\n results = results.concat(value.getAll(opts))\n } else {\n results = results.concat(value)\n }\n }\n }\n return results\n },\n\n visitAll (cb, thisArg) {\n this.values.forEach(function (value) {\n if (value.isIndex) {\n value.visitAll(cb, thisArg)\n } else {\n value.forEach(cb, thisArg)\n }\n })\n },\n\n between (leftKeys, rightKeys, opts) {\n opts || (opts = {})\n if (!utils.isArray(leftKeys)) {\n leftKeys = [leftKeys]\n }\n if (!utils.isArray(rightKeys)) {\n rightKeys = [rightKeys]\n }\n utils.fillIn(opts, {\n leftInclusive: true,\n rightInclusive: false,\n limit: undefined,\n offset: 0\n })\n\n let results = this._between(leftKeys, rightKeys, opts)\n\n if (opts.limit) {\n return results.slice(opts.offset, opts.limit + opts.offset)\n } else {\n return results.slice(opts.offset)\n }\n },\n\n _between (leftKeys, rightKeys, opts) {\n let results = []\n\n let leftKey = leftKeys.shift()\n let rightKey = rightKeys.shift()\n\n let pos\n\n if (leftKey !== undefined) {\n pos = binarySearch(this.keys, leftKey)\n } else {\n pos = {\n found: false,\n index: 0\n }\n }\n\n if (leftKeys.length === 0) {\n if (pos.found && opts.leftInclusive === false) {\n pos.index += 1\n }\n\n for (let i = pos.index; i < this.keys.length; i += 1) {\n if (rightKey !== undefined) {\n if (opts.rightInclusive) {\n if (this.keys[i] > rightKey) { break }\n } else {\n if (this.keys[i] >= rightKey) { break }\n }\n }\n\n if (this.values[i].isIndex) {\n results = results.concat(this.values[i].getAll())\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n } else {\n for (let i = pos.index; i < this.keys.length; i += 1) {\n let currKey = this.keys[i]\n if (currKey > rightKey) { break }\n\n if (this.values[i].isIndex) {\n if (currKey === leftKey) {\n results = results.concat(this.values[i]._between(utils.copy(leftKeys), rightKeys.map(function () { return undefined }), opts))\n } else if (currKey === rightKey) {\n results = results.concat(this.values[i]._between(leftKeys.map(function () { return undefined }), utils.copy(rightKeys), opts))\n } else {\n results = results.concat(this.values[i].getAll())\n }\n } else {\n results = results.concat(this.values[i])\n }\n\n if (opts.limit) {\n if (results.length >= (opts.limit + opts.offset)) {\n break\n }\n }\n }\n }\n\n if (opts.limit) {\n return results.slice(0, opts.limit + opts.offset)\n } else {\n return results\n }\n },\n\n peek () {\n if (this.values.length) {\n if (this.values[0].isIndex) {\n return this.values[0].peek()\n } else {\n return this.values[0]\n }\n }\n return []\n },\n\n clear () {\n this.keys = []\n this.values = []\n },\n\n insertRecord (data) {\n let keyList = this.fieldList.map(function (field) {\n if (utils.isFunction(field)) {\n return field(data) || undefined\n } else {\n return data[field] || undefined\n }\n })\n this.set(keyList, data)\n },\n\n removeRecord (data) {\n let removed\n const isUnique = this.hashCode(data) !== undefined\n this.values.forEach((value, i) => {\n if (value.isIndex) {\n if (value.removeRecord(data)) {\n if (value.keys.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n } else {\n let dataLocation = {}\n if (this.keys[i] === undefined || !isUnique) {\n for (let j = value.length - 1; j >= 0; j--) {\n if (value[j] === data) {\n dataLocation = {\n found: true,\n index: j\n }\n break\n }\n }\n } else if (isUnique) {\n dataLocation = binarySearch(value, data, this.hashCode)\n }\n if (dataLocation.found) {\n removeAt(value, dataLocation.index)\n if (value.length === 0) {\n removeAt(this.keys, i)\n removeAt(this.values, i)\n }\n removed = true\n return false\n }\n }\n })\n return removed ? data : undefined\n },\n\n updateRecord (data) {\n const removed = this.removeRecord(data)\n if (removed !== undefined) {\n this.insertRecord(data)\n }\n }\n})\n","import utils from './utils'\nimport Component from './Component'\nimport Query from './Query'\nimport Index from '../lib/mindex/index'\n\nconst DOMAIN = 'Collection'\n\nconst COLLECTION_DEFAULTS = {\n /**\n * Whether to call {@link Record#commit} on records that are added to the\n * collection and already exist in the collection.\n *\n * @name Collection#commitOnMerge\n * @type {boolean}\n * @default true\n */\n commitOnMerge: true,\n\n /**\n * Whether record events should bubble up and be emitted by the collection.\n *\n * @name Collection#emitRecordEvents\n * @type {boolean}\n * @default true\n */\n emitRecordEvents: true,\n\n /**\n * Field to be used as the unique identifier for records in this collection.\n * Defaults to `\"id\"` unless {@link Collection#mapper} is set, in which case\n * this will default to {@link Mapper#idAttribute}.\n *\n * @name Collection#idAttribute\n * @type {string}\n * @default \"id\"\n */\n idAttribute: 'id',\n\n /**\n * What to do when inserting a record into this Collection that shares a\n * primary key with a record already in this Collection.\n *\n * Possible values:\n * merge\n * replace\n *\n * Merge:\n *\n * Recursively shallow copy properties from the new record onto the existing\n * record.\n *\n * Replace:\n *\n * Shallow copy top-level properties from the new record onto the existing\n * record. Any top-level own properties of the existing record that are _not_\n * on the new record will be removed.\n *\n * @name Collection#onConflict\n * @type {string}\n * @default \"merge\"\n */\n onConflict: 'merge'\n}\n\n/**\n * An ordered set of {@link Record} instances.\n *\n * @example Collection#constructor\n * // import {Collection, Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const user1 = new Record({ id: 1 })\n * const user2 = new Record({ id: 2 })\n * const UserCollection = new Collection([user1, user2])\n * console.log(UserCollection.get(1) === user1)\n *\n * @class Collection\n * @extends Component\n * @param {Array} [records] Initial set of records to insert into the\n * collection.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.commitOnMerge] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.idAttribute] See {@link Collection#idAttribute}.\n * @param {string} [opts.onConflict=\"merge\"] See {@link Collection#onConflict}.\n * @param {string} [opts.mapper] See {@link Collection#mapper}.\n * @since 3.0.0\n */\nfunction Collection (records, opts) {\n utils.classCallCheck(this, Collection)\n Component.call(this, opts)\n\n if (records && !utils.isArray(records)) {\n opts = records\n records = []\n }\n if (utils.isString(opts)) {\n opts = { idAttribute: opts }\n }\n\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * Default Mapper for this collection. Optional. If a Mapper is provided, then\n * the collection will use the {@link Mapper#idAttribute} setting, and will\n * wrap records in {@link Mapper#recordClass}.\n *\n * @example Collection#mapper\n * // Normally you would do: import {Collection, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection, Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const myMapper = new MyMapperClass({ name: 'myMapper' })\n * const collection = new Collection(null, { mapper: myMapper })\n *\n * @name Collection#mapper\n * @type {Mapper}\n * @default null\n * @since 3.0.0\n */\n mapper: {\n value: undefined,\n writable: true\n },\n // Query class used by this collection\n queryClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(COLLECTION_DEFAULTS))\n\n if (!this.queryClass) {\n this.queryClass = Query\n }\n\n const idAttribute = this.recordId()\n\n Object.defineProperties(this, {\n /**\n * The main index, which uses @{link Collection#recordId} as the key.\n *\n * @name Collection#index\n * @type {Index}\n */\n index: {\n value: new Index([idAttribute], {\n hashCode (obj) {\n return utils.get(obj, idAttribute)\n }\n })\n },\n\n /**\n * Object that holds the secondary indexes of this collection.\n *\n * @name Collection#indexes\n * @type {Object.}\n */\n indexes: {\n value: {}\n }\n })\n\n // Insert initial data into the collection\n if (utils.isObject(records) || (utils.isArray(records) && records.length)) {\n this.add(records)\n }\n}\n\nexport default Component.extend({\n constructor: Collection,\n\n /**\n * Used to bind to events emitted by records in this Collection.\n *\n * @method Collection#_onRecordEvent\n * @since 3.0.0\n * @private\n * @param {...*} [arg] Args passed to {@link Collection#emit}.\n */\n _onRecordEvent (...args) {\n if (this.emitRecordEvents) {\n this.emit(...args)\n }\n },\n\n /**\n * Insert the provided record or records.\n *\n * If a record is already in the collection then the provided record will\n * either merge with or replace the existing record based on the value of the\n * `onConflict` option.\n *\n * The collection's secondary indexes will be updated as each record is\n * visited.\n *\n * @method Collection#add\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} data The record or records to insert.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.commitOnMerge=true] See {@link Collection#commitOnMerge}.\n * @param {string} [opts.onConflict] See {@link Collection#onConflict}.\n * @returns {(Object|Object[]|Record|Record[])} The added record or records.\n */\n add (records, opts) {\n // Default values for arguments\n opts || (opts = {})\n\n // Fill in \"opts\" with the Collection's configuration\n utils._(opts, this)\n records = this.beforeAdd(records, opts) || records\n\n // Track whether just one record or an array of records is being inserted\n let singular = false\n const idAttribute = this.recordId()\n if (!utils.isArray(records)) {\n if (utils.isObject(records)) {\n records = [records]\n singular = true\n } else {\n throw utils.err(`${DOMAIN}#add`, 'records')(400, 'object or array', records)\n }\n }\n\n // Map the provided records to existing records.\n // New records will be inserted. If any records map to existing records,\n // they will be merged into the existing records according to the onConflict\n // option.\n records = records.map((record) => {\n let id = this.recordId(record)\n // Grab existing record if there is one\n const existing = id === undefined ? id : this.get(id)\n // If the currently visited record is just a reference to an existing\n // record, then there is nothing to be done. Exit early.\n if (record === existing) {\n return existing\n }\n\n if (existing) {\n // Here, the currently visited record corresponds to a record already\n // in the collection, so we need to merge them\n const onConflict = opts.onConflict || this.onConflict\n if (onConflict === 'merge') {\n utils.deepMixIn(existing, record)\n } else if (onConflict === 'replace') {\n utils.forOwn(existing, (value, key) => {\n if (key !== idAttribute && record[key] === undefined) {\n existing[key] = undefined\n }\n })\n existing.set(record)\n } else {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(400, 'one of (merge, replace)', onConflict, true)\n }\n record = existing\n if (opts.commitOnMerge && utils.isFunction(record.commit)) {\n record.commit()\n }\n // Update all indexes in the collection\n this.updateIndexes(record)\n } else {\n // Here, the currently visted record does not correspond to any record\n // in the collection, so (optionally) instantiate this record and insert\n // it into the collection\n record = this.mapper ? this.mapper.createRecord(record, opts) : record\n this.index.insertRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.insertRecord(record)\n })\n if (record && utils.isFunction(record.on)) {\n record.on('all', this._onRecordEvent, this)\n }\n }\n return record\n })\n // Finally, return the inserted data\n const result = singular ? records[0] : records\n if (!opts.silent) {\n this.emit('add', result)\n }\n return this.afterAdd(records, opts, result) || result\n },\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then {@link Collection#add} will return that same value.\n *\n * @method Collection#method\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} result The record or records\n * that were added to this Collection by {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n afterAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}. If this method returns\n * a value then {@link Collection#remove} will return that same value.\n *\n * @method Collection#afterRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n * @param {Object} record The result that will be returned by {@link Collection#remove}.\n */\n afterRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}. If this method\n * returns a value then {@link Collection#removeAll} will return that same\n * value.\n *\n * @method Collection#afterRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n * @param {Object} records The result that will be returned by {@link Collection#removeAll}.\n */\n afterRemoveAll () {},\n\n /**\n * Lifecycle hook called by {@link Collection#add}. If this method returns a\n * value then the `records` argument in {@link Collection#add} will be\n * re-assigned to the returned value.\n *\n * @method Collection#beforeAdd\n * @since 3.0.0\n * @param {(Object|Object[]|Record|Record[])} records The `records` argument passed to {@link Collection#add}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#add}.\n */\n beforeAdd () {},\n\n /**\n * Lifecycle hook called by {@link Collection#remove}.\n *\n * @method Collection#beforeRemove\n * @since 3.0.0\n * @param {(string|number)} id The `id` argument passed to {@link Collection#remove}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#remove}.\n */\n beforeRemove () {},\n\n /**\n * Lifecycle hook called by {@link Collection#removeAll}.\n *\n * @method Collection#beforeRemoveAll\n * @since 3.0.0\n * @param {Object} query The `query` argument passed to {@link Collection#removeAll}.\n * @param {Object} opts The `opts` argument passed to {@link Collection#removeAll}.\n */\n beforeRemoveAll () {},\n\n /**\n * Find all records between two boundaries.\n *\n * Shortcut for `collection.query().between(18, 30, { index: 'age' }).run()`\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = collection.between(18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = collection.between([18], [30], { index: 'age' })\n *\n * @method Collection#between\n * @since 3.0.0\n * @param {Array} leftKeys Keys defining the left boundary.\n * @param {Array} rightKeys Keys defining the right boundary.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @param {boolean} [opts.leftInclusive=true] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.rightInclusive=false] Whether to include records\n * on the left boundary.\n * @param {boolean} [opts.limit] Limit the result to a certain number.\n * @param {boolean} [opts.offset] The number of resulting records to skip.\n * @returns {Object[]|Record[]} The result.\n */\n between (leftKeys, rightKeys, opts) {\n return this.query().between(leftKeys, rightKeys, opts).run()\n },\n\n /**\n * Create a new secondary index on the contents of the collection.\n *\n * @example\n * // Index users by age\n * collection.createIndex('age')\n *\n * @example\n * // Index users by status and role\n * collection.createIndex('statusAndRole', ['status', 'role'])\n *\n * @method Collection#createIndex\n * @since 3.0.0\n * @param {string} name The name of the new secondary index.\n * @param {string[]} [fieldList] Array of field names to use as the key or\n * compound key of the new secondary index. If no fieldList is provided, then\n * the name will also be the field that is used to index the collection.\n */\n createIndex (name, fieldList, opts) {\n if (utils.isString(name) && fieldList === undefined) {\n fieldList = [name]\n }\n opts || (opts = {})\n opts.hashCode || (opts.hashCode = (obj) => this.recordId(obj))\n const index = this.indexes[name] = new Index(fieldList, opts)\n this.index.visitAll(index.insertRecord, index)\n },\n\n /**\n * Find the record or records that match the provided query or pass the\n * provided filter function.\n *\n * Shortcut for `collection.query().filter(queryOrFn[, thisArg]).run()`\n *\n * @example Collection#filter\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const collection = new Collection([\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = collection.filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = collection.filter(function (post) {\n * return post.id % 2 === 0\n * })\n *\n * @method Collection#filter\n * @param {(Object|Function)} [queryOrFn={}] Selection query or filter\n * function.\n * @param {Object} [thisArg] Context to which to bind `queryOrFn` if\n * `queryOrFn` is a function.\n * @returns {Array} The result.\n * @see query\n * @since 3.0.0\n */\n filter (query, thisArg) {\n return this.query().filter(query, thisArg).run()\n },\n\n /**\n * Iterate over all records.\n *\n * @example\n * collection.forEach(function (record) {\n * // do something\n * })\n *\n * @method Collection#forEach\n * @since 3.0.0\n * @param {Function} forEachFn Iteration function.\n * @param {*} [thisArg] Context to which to bind `forEachFn`.\n * @returns {Array} The result.\n */\n forEach (cb, thisArg) {\n this.index.visitAll(cb, thisArg)\n },\n\n /**\n * Get the record with the given id.\n *\n * @method Collection#get\n * @since 3.0.0\n * @param {(string|number)} id The primary key of the record to get.\n * @returns {(Object|Record)} The record with the given id.\n */\n get (id) {\n const instances = this.query().get(id).run()\n return instances.length ? instances[0] : undefined\n },\n\n /**\n * Find the record or records that match the provided keyLists.\n *\n * Shortcut for `collection.query().getAll(keyList1, keyList2, ...).run()`\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = collection.getAll('draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = collection.getAll(['draft'], ['inReview'], { index: 'status' })\n *\n * @method Collection#getAll\n * @since 3.0.0\n * @param {...Array} [keyList] Provide one or more keyLists, and all\n * records matching each keyList will be retrieved. If no keyLists are\n * provided, all records will be returned.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] Name of the secondary index to use in the\n * query. If no index is specified, the main index is used.\n * @returns {Array} The result.\n */\n getAll (...args) {\n return this.query().getAll(...args).run()\n },\n\n /**\n * Return the index with the given name. If no name is provided, return the\n * main index. Throws an error if the specified index does not exist.\n *\n * @method Collection#getIndex\n * @since 3.0.0\n * @param {string} [name] The name of the index to retrieve.\n */\n getIndex (name) {\n const index = name ? this.indexes[name] : this.index\n if (!index) {\n throw utils.err(`${DOMAIN}#getIndex`, name)(404, 'index')\n }\n return index\n },\n\n /**\n * Limit the result.\n *\n * Shortcut for `collection.query().limit(maximumNumber).run()`\n *\n * @example\n * const posts = collection.limit(10)\n *\n * @method Collection#limit\n * @since 3.0.0\n * @param {number} num The maximum number of records to keep in the result.\n * @returns {Array} The result.\n */\n limit (num) {\n return this.query().limit(num).run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map(function (user) {\n * return user.name\n * })\n *\n * @method Collection#map\n * @since 3.0.0\n * @param {Function} mapFn Mapping function.\n * @param {*} [thisArg] Context to which to bind `mapFn`.\n * @returns {Array} The result of the mapping.\n */\n map (cb, thisArg) {\n const data = []\n this.index.visitAll(function (value) {\n data.push(cb.call(thisArg, value))\n })\n return data\n },\n\n /**\n * Return the result of calling the specified function on each record in this\n * collection's main index.\n *\n * @method Collection#mapCall\n * @since 3.0.0\n * @param {string} funcName Name of function to call\n * @parama {...*} [args] Remaining arguments to be passed to the function.\n * @returns {Array} The result.\n */\n mapCall (funcName, ...args) {\n const data = []\n this.index.visitAll(function (record) {\n data.push(record[funcName](...args))\n })\n return data\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#prune\n * @param {Object} [opts] Configuration options, passed to {@link Collection#removeAll}.\n * @since 3.0.0\n * @returns {Array} The removed records, if any.\n */\n prune (opts) {\n return this.removeAll(this.unsaved(), opts)\n },\n\n /**\n * Create a new query to be executed against the contents of the collection.\n * The result will be all or a subset of the contents of the collection.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * collection.query()\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method Collection#query\n * @since 3.0.0\n * @returns {Query} New query object.\n */\n query () {\n const Ctor = this.queryClass\n return new Ctor(this)\n },\n\n /**\n * Return the primary key of the given, or if no record is provided, return the\n * name of the field that holds the primary key of records in this Collection.\n *\n * @method Collection#recordId\n * @since 3.0.0\n * @param {(Object|Record)} [record] The record whose primary key is to be\n * returned.\n * @returns {(string|number)} Primary key or name of field that holds primary\n * key.\n */\n recordId (record) {\n if (record) {\n return utils.get(record, this.recordId())\n }\n return this.mapper ? this.mapper.idAttribute : this.idAttribute\n },\n\n /**\n * Reduce the data in the collection to a single value and return the result.\n *\n * @example\n * const totalVotes = collection.reduce(function (prev, record) {\n * return prev + record.upVotes + record.downVotes\n * }, 0)\n *\n * @method Collection#reduce\n * @since 3.0.0\n * @param {Function} cb Reduction callback.\n * @param {*} initialValue Initial value of the reduction.\n * @returns {*} The result.\n */\n reduce (cb, initialValue) {\n const data = this.getAll()\n return data.reduce(cb, initialValue)\n },\n\n /**\n * Remove the record with the given id from this Collection.\n *\n * @method Collection#remove\n * @since 3.0.0\n * @param {(string|number|object|Record)} idOrRecord The primary key of the\n * record to be removed, or a reference to the record that is to be removed.\n * @param {Object} [opts] Configuration options.\n * @returns {Object|Record} The removed record, if any.\n */\n remove (idOrRecord, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemove(idOrRecord, opts)\n let record = utils.isSorN(idOrRecord) ? this.get(idOrRecord) : idOrRecord\n\n // The record is in the collection, remove it\n if (utils.isObject(record)) {\n record = this.index.removeRecord(record)\n if (record) {\n utils.forOwn(this.indexes, function (index, name) {\n index.removeRecord(record)\n })\n if (utils.isFunction(record.off)) {\n record.off('all', this._onRecordEvent, this)\n if (!opts.silent) {\n this.emit('remove', record)\n }\n }\n }\n }\n return this.afterRemove(idOrRecord, opts, record) || record\n },\n\n /**\n * Remove from this collection the given records or the records selected by\n * the given \"query\".\n *\n * @method Collection#removeAll\n * @since 3.0.0\n * @param {Object|Object[]|Record[]} [queryOrRecords={}] Records to be removed or selection query. See {@link query}.\n * @param {Object} [queryOrRecords.where] See {@link query.where}.\n * @param {number} [queryOrRecords.offset] See {@link query.offset}.\n * @param {number} [queryOrRecords.limit] See {@link query.limit}.\n * @param {string|Array[]} [queryOrRecords.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object[]|Record[])} The removed records, if any.\n */\n removeAll (queryOrRecords, opts) {\n // Default values for arguments\n opts || (opts = {})\n this.beforeRemoveAll(queryOrRecords, opts)\n let records = utils.isArray(queryOrRecords) ? queryOrRecords.slice() : this.filter(queryOrRecords)\n\n // Remove each selected record from the collection\n const optsCopy = utils.plainCopy(opts)\n optsCopy.silent = true\n records = records\n .map((record) => this.remove(record, optsCopy))\n .filter((record) => record)\n if (!opts.silent) {\n this.emit('remove', records)\n }\n return this.afterRemoveAll(queryOrRecords, opts, records) || records\n },\n\n /**\n * Skip a number of results.\n *\n * Shortcut for `collection.query().skip(numberToSkip).run()`\n *\n * @example\n * const posts = collection.skip(10)\n *\n * @method Collection#skip\n * @since 3.0.0\n * @param {number} num The number of records to skip.\n * @returns {Array} The result.\n */\n skip (num) {\n return this.query().skip(num).run()\n },\n\n /**\n * Return the plain JSON representation of all items in this collection.\n * Assumes records in this collection have a toJSON method.\n *\n * @method Collection#toJSON\n * @since 3.0.0\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation.\n * @returns {Array} The records.\n */\n toJSON (opts) {\n return this.mapCall('toJSON', opts)\n },\n\n /**\n * Return all \"unsaved\" (not uniquely identifiable) records in this colleciton.\n *\n * @method Collection#unsaved\n * @since 3.0.0\n * @returns {Array} The unsaved records, if any.\n */\n unsaved (opts) {\n return this.index.get()\n },\n\n /**\n * Update a record's position in a single index of this collection. See\n * {@link Collection#updateIndexes} to update a record's position in all\n * indexes at once.\n *\n * @method Collection#updateIndex\n * @since 3.0.0\n * @param {Object} record The record to update.\n * @param {Object} [opts] Configuration options.\n * @param {string} [opts.index] The index in which to update the record's\n * position. If you don't specify an index then the record will be updated\n * in the main index.\n */\n updateIndex (record, opts) {\n opts || (opts = {})\n this.getIndex(opts.index).updateRecord(record)\n },\n\n /**\n * Updates all indexes in this collection for the provided record. Has no\n * effect if the record is not in the collection.\n *\n * @method Collection#updateIndexes\n * @since 3.0.0\n * @param {Object} record TODO\n */\n updateIndexes (record) {\n this.index.updateRecord(record)\n utils.forOwn(this.indexes, function (index, name) {\n index.updateRecord(record)\n })\n }\n})\n\n/**\n * Fired when a record changes. Only works for records that have tracked changes.\n * See {@link Collection~changeListener} on how to listen for this event.\n *\n * @event Collection#change\n * @see Collection~changeListener\n */\n\n/**\n * Callback signature for the {@link Collection#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * collection.on('change', onChange)\n *\n * @callback Collection~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Collection#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the Collection. See\n * {@link Collection~addListener} on how to listen for this event.\n *\n * @event Collection#add\n * @see Collection~addListener\n * @see Collection#event:add\n * @see Collection#add\n */\n\n/**\n * Callback signature for the {@link Collection#event:add} event.\n *\n * @example\n * function onAdd (recordOrRecords) {\n * // do something\n * }\n * collection.on('add', onAdd)\n *\n * @callback Collection~addListener\n * @param {Record|Record[]} The Record or Records that were added.\n * @see Collection#event:add\n * @see Collection#add\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the Collection. See\n * {@link Collection~removeListener} for how to listen for this event.\n *\n * @event Collection#remove\n * @see Collection~removeListener\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n */\n\n/**\n * Callback signature for the {@link Collection#event:remove} event.\n *\n * @example\n * function onRemove (recordsOrRecords) {\n * // do something\n * }\n * collection.on('remove', onRemove)\n *\n * @callback Collection~removeListener\n * @param {Record|Record[]} Record or Records that were removed.\n * @see Collection#event:remove\n * @see Collection#remove\n * @see Collection#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Collection:\n * @example Collection.extend\n * // Normally you would do: import {Collection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Collection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomCollectionClass extends Collection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customCollection = new CustomCollectionClass()\n * console.log(customCollection.foo())\n * console.log(CustomCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherCollectionClass = Collection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherCollection = new OtherCollectionClass()\n * console.log(otherCollection.foo())\n * console.log(OtherCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherCollectionClass () {\n * Collection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Collection.extend({\n * constructor: AnotherCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherCollection = new AnotherCollectionClass()\n * console.log(anotherCollection.created_at)\n * console.log(anotherCollection.foo())\n * console.log(AnotherCollectionClass.beep())\n *\n * @method Collection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Collection class.\n * @since 3.0.0\n */\n","import utils from './utils'\n\n// TODO: remove this when the rest of the project is cleaned\nexport const belongsToType = 'belongsTo'\nexport const hasManyType = 'hasMany'\nexport const hasOneType = 'hasOne'\n\nconst DOMAIN = 'Relation'\n\nexport function Relation (relatedMapper, options = {}) {\n utils.classCallCheck(this, Relation)\n\n options.type = this.constructor.TYPE_NAME\n this.validateOptions(relatedMapper, options)\n\n if (typeof relatedMapper === 'object') {\n Object.defineProperty(this, 'relatedMapper', { value: relatedMapper })\n }\n\n Object.defineProperty(this, 'inverse', { writable: true })\n utils.fillIn(this, options)\n}\n\nRelation.extend = utils.extend\n\nutils.addHiddenPropsToTarget(Relation.prototype, {\n get canAutoAddLinks () {\n return this.add === undefined || !!this.add\n },\n\n get relatedCollection () {\n return this.mapper.datastore.getCollection(this.relation)\n },\n\n validateOptions (related, opts) {\n const DOMAIN_ERR = `new ${DOMAIN}`\n\n const localField = opts.localField\n if (!localField) {\n throw utils.err(DOMAIN_ERR, 'opts.localField')(400, 'string', localField)\n }\n\n const foreignKey = opts.foreignKey = opts.foreignKey || opts.localKey\n if (!foreignKey && (opts.type === belongsToType || opts.type === hasOneType)) {\n throw utils.err(DOMAIN_ERR, 'opts.foreignKey')(400, 'string', foreignKey)\n }\n\n if (utils.isString(related)) {\n opts.relation = related\n if (!utils.isFunction(opts.getRelation)) {\n throw utils.err(DOMAIN_ERR, 'opts.getRelation')(400, 'function', opts.getRelation)\n }\n } else if (related) {\n opts.relation = related.name\n } else {\n throw utils.err(DOMAIN_ERR, 'related')(400, 'Mapper or string', related)\n }\n },\n\n assignTo (mapper) {\n this.name = mapper.name\n Object.defineProperty(this, 'mapper', { value: mapper })\n\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n mapper.relationFields || Object.defineProperty(mapper, 'relationFields', { value: [] })\n mapper.relationList.push(this)\n mapper.relationFields.push(this.localField)\n },\n\n canFindLinkFor () {\n return !!(this.foreignKey || this.localKey)\n },\n\n getRelation () {\n return this.relatedMapper\n },\n\n getForeignKey (record) {\n return utils.get(record, this.mapper.idAttribute)\n },\n\n setForeignKey (record, relatedRecord) {\n if (!record || !relatedRecord) {\n return\n }\n\n this._setForeignKey(record, relatedRecord)\n },\n\n _setForeignKey (record, relatedRecords) {\n const idAttribute = this.mapper.idAttribute\n\n if (!utils.isArray(relatedRecords)) {\n relatedRecords = [relatedRecords]\n }\n\n relatedRecords.forEach((relatedRecord) => {\n utils.set(relatedRecord, this.foreignKey, utils.get(record, idAttribute))\n })\n },\n\n getLocalField (record) {\n return utils.get(record, this.localField)\n },\n\n setLocalField (record, relatedData) {\n return utils.set(record, this.localField, relatedData)\n },\n\n getInverse (mapper) {\n if (!this.inverse) {\n this.findInverseRelation(mapper)\n }\n\n return this.inverse\n },\n\n findInverseRelation (mapper) {\n this.getRelation().relationList.forEach((def) => {\n if (def.getRelation() === mapper && this.isInversedTo(def)) {\n this.inverse = def\n return true\n }\n })\n },\n\n isInversedTo (def) {\n return !def.foreignKey || def.foreignKey === this.foreignKey\n },\n\n addLinkedRecords (records) {\n const datastore = this.mapper.datastore\n\n records.forEach((record) => {\n let relatedData = this.getLocalField(record)\n\n if (utils.isFunction(this.add)) {\n relatedData = this.add(datastore, this, record)\n } else if (relatedData) {\n relatedData = this.linkRecord(record, relatedData)\n }\n\n const isEmptyLinks = !relatedData || utils.isArray(relatedData) && !relatedData.length\n\n if (isEmptyLinks && this.canFindLinkFor(record)) {\n relatedData = this.findExistingLinksFor(record)\n }\n\n if (relatedData) {\n this.setLocalField(record, relatedData)\n }\n })\n },\n\n removeLinkedRecords (relatedMapper, records) {\n const localField = this.localField\n records.forEach((record) => {\n utils.set(record, localField, undefined)\n })\n },\n\n linkRecord (record, relatedRecord) {\n const relatedId = utils.get(relatedRecord, this.mapper.idAttribute)\n\n if (relatedId === undefined) {\n const unsaved = this.relatedCollection.unsaved()\n if (unsaved.indexOf(relatedRecord) === -1) {\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n } else {\n if (relatedRecord !== this.relatedCollection.get(relatedId)) {\n this.setForeignKey(record, relatedRecord)\n\n if (this.canAutoAddLinks) {\n relatedRecord = this.relatedCollection.add(relatedRecord)\n }\n }\n }\n\n return relatedRecord\n },\n\n // e.g. user hasMany post via \"foreignKey\", so find all posts of user\n findExistingLinksByForeignKey (id) {\n if (id === undefined || id === null) {\n return\n }\n return this.relatedCollection.filter({\n [this.foreignKey]: id\n })\n }\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const BelongsToRelation = Relation.extend({\n getForeignKey (record) {\n return utils.get(record, this.foreignKey)\n },\n\n _setForeignKey (record, relatedRecord) {\n utils.set(record, this.foreignKey, utils.get(relatedRecord, this.getRelation().idAttribute))\n },\n\n findExistingLinksFor (record) {\n // console.log('\\tBelongsTo#findExistingLinksFor', record)\n if (!record) {\n return\n }\n const relatedId = utils.get(record, this.foreignKey)\n if (relatedId !== undefined && relatedId !== null) {\n return this.relatedCollection.get(relatedId)\n }\n }\n}, {\n TYPE_NAME: 'belongsTo'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasManyRelation = Relation.extend({\n validateOptions (related, opts) {\n Relation.prototype.validateOptions.call(this, related, opts)\n\n const { localKeys, foreignKeys, foreignKey } = opts\n\n if (!foreignKey && !localKeys && !foreignKeys) {\n throw utils.err('new Relation', 'opts.')(400, 'string', foreignKey)\n }\n },\n\n canFindLinkFor (record) {\n const hasForeignKeys = this.foreignKey || this.foreignKeys\n return !!(hasForeignKeys || (this.localKeys && utils.get(record, this.localKeys)))\n },\n\n linkRecord (record, relatedRecords) {\n const relatedCollection = this.relatedCollection\n const canAutoAddLinks = this.canAutoAddLinks\n const foreignKey = this.foreignKey\n const unsaved = this.relatedCollection.unsaved()\n\n return relatedRecords.map((relatedRecord) => {\n const relatedId = relatedCollection.recordId(relatedRecord)\n\n if ((relatedId === undefined && unsaved.indexOf(relatedRecord) === -1) || relatedRecord !== relatedCollection.get(relatedId)) {\n if (foreignKey) {\n // TODO: slow, could be optimized? But user loses hook\n this.setForeignKey(record, relatedRecord)\n }\n if (canAutoAddLinks) {\n relatedRecord = relatedCollection.add(relatedRecord)\n }\n }\n\n return relatedRecord\n })\n },\n\n findExistingLinksFor (record) {\n const id = utils.get(record, this.mapper.idAttribute)\n const ids = this.localKeys ? utils.get(record, this.localKeys) : null\n let records\n\n if (id !== undefined && this.foreignKey) {\n records = this.findExistingLinksByForeignKey(id)\n } else if (this.localKeys && ids) {\n records = this.findExistingLinksByLocalKeys(ids)\n } else if (id !== undefined && this.foreignKeys) {\n records = this.findExistingLinksByForeignKeys(id)\n }\n\n if (records && records.length) {\n return records\n }\n },\n\n // e.g. user hasMany group via \"foreignKeys\", so find all users of a group\n findExistingLinksByLocalKeys (ids) {\n return this.relatedCollection.filter({\n where: {\n [this.mapper.idAttribute]: {\n 'in': ids\n }\n }\n })\n },\n\n // e.g. group hasMany user via \"localKeys\", so find all groups that own a user\n findExistingLinksByForeignKeys (id) {\n return this.relatedCollection.filter({\n where: {\n [this.foreignKeys]: {\n 'contains': id\n }\n }\n })\n }\n}, {\n TYPE_NAME: 'hasMany'\n})\n","import utils from '../utils'\nimport { Relation } from '../Relation'\n\nexport const HasOneRelation = Relation.extend({\n findExistingLinksFor (relatedMapper, record) {\n const recordId = utils.get(record, relatedMapper.idAttribute)\n const records = this.findExistingLinksByForeignKey(recordId)\n\n if (records && records.length) {\n return records[0]\n }\n }\n}, {\n TYPE_NAME: 'hasOne'\n})\n","import { Relation } from './Relation'\nimport { BelongsToRelation } from './Relation/BelongsTo'\nimport { HasManyRelation } from './Relation/HasMany'\nimport { HasOneRelation } from './Relation/HasOne'\n\n[BelongsToRelation, HasManyRelation, HasOneRelation].forEach(function (RelationType) {\n Relation[RelationType.TYPE_NAME] = function (related, options) {\n return new RelationType(related, options)\n }\n})\n\nexport { belongsToType, hasManyType, hasOneType, Relation } from './Relation'\n","import { Relation } from './relations'\n\nexport { belongsToType, hasManyType, hasOneType } from './relations'\n/**\n * BelongsTo relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.belongsTo\n * @method\n * @param {Mapper} related The relation the target belongs to.\n * @param {Object} opts Configuration options.\n * @param {string} opts.foreignKey The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const belongsTo = function (related, opts) {\n return function (mapper) {\n Relation.belongsTo(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasMany relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasMany\n * @method\n * @param {Mapper} related The relation of which the target has many.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasMany = function (related, opts) {\n return function (mapper) {\n Relation.hasMany(related, opts).assignTo(mapper)\n }\n}\n\n/**\n * HasOne relation decorator. You probably won't use this directly.\n *\n * @name module:js-data.hasOne\n * @method\n * @param {Mapper} related The relation of which the target has one.\n * @param {Object} opts Configuration options.\n * @param {string} [opts.foreignKey] The field that holds the primary key of the\n * related record.\n * @param {string} opts.localField The field that holds a reference to the\n * related record object.\n * @returns {Function} Invocation function, which accepts the target as the only\n * parameter.\n */\nexport const hasOne = function (related, opts) {\n return function (mapper) {\n Relation.hasOne(related, opts).assignTo(mapper)\n }\n}\n","import utils, { safeSetLink } from './utils'\nimport Component from './Component'\nimport Settable from './Settable'\nimport {\n hasManyType,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Record'\n\nconst superMethod = function (mapper, name) {\n const store = mapper.datastore\n if (store && store[name]) {\n return function (...args) {\n return store[name](mapper.name, ...args)\n }\n }\n return mapper[name].bind(mapper)\n}\n\n// Cache these strings\nconst creatingPath = 'creating'\nconst noValidatePath = 'noValidate'\nconst keepChangeHistoryPath = 'keepChangeHistory'\nconst previousPath = 'previous'\n\n/**\n * js-data's Record class. An instance of `Record` corresponds to an in-memory\n * representation of a single row or document in a database, Firebase,\n * localstorage, etc. Basically, a `Record` instance represents whatever kind of\n * entity in your persistence layer that has a primary key.\n *\n * ```javascript\n * import {Record} from 'js-data'\n * ```\n *\n * @example Record#constructor\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a plain record\n * let record = new Record()\n * console.log('record: ' + JSON.stringify(record))\n *\n * // You can supply properties on instantiation\n * record = new Record({ name: 'John' })\n * console.log('record: ' + JSON.stringify(record))\n *\n * @example Record#constructor2\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Instantiate a record that's associated with a Mapper:\n * const UserMapper = new Mapper({ name: 'user' })\n * const User = UserMapper.recordClass\n * const user = UserMapper.createRecord({ name: 'John' })\n * const user2 = new User({ name: 'Sally' })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user2: ' + JSON.stringify(user2))\n *\n * @example Record#constructor3\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n *\n * // Instantiate a record that's associated with a store's Mapper\n * const user = store.createRecord('user', { name: 'John' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor4\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Validate on instantiation\n * const user = store.createRecord('user', { name: 1234 })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @example Record#constructor5\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * // Skip validation on instantiation\n * const user = store.createRecord('user', { name: 1234 }, { noValidate: true })\n * console.log('user: ' + JSON.stringify(user))\n * console.log('user.isValid(): ' + user.isValid())\n *\n * @class Record\n * @extends Component\n * @param {Object} [props] The initial properties of the new Record instance.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate=false] Whether to skip validation on the\n * initial properties.\n * @since 3.0.0\n */\nfunction Record (props, opts) {\n utils.classCallCheck(this, Record)\n Settable.call(this)\n props || (props = {})\n opts || (opts = {})\n const _set = this._set\n _set(creatingPath, true)\n if (opts.noValidate) {\n _set(noValidatePath, opts.noValidate === undefined ? true : opts.noValidate)\n }\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\n const mapper = this.constructor.mapper\n const id = mapper ? utils.get(props, mapper.idAttribute) : undefined\n if (id !== undefined) {\n utils.set(this, mapper.idAttribute, id)\n }\n\n utils.fillIn(this, props)\n _set(creatingPath, false)\n const validateOnSet = opts.validateOnSet === undefined ? (mapper ? mapper.validateOnSet : true) : opts.validateOnSet\n _set(noValidatePath, !validateOnSet)\n _set(previousPath, mapper ? mapper.toJSON(props) : utils.plainCopy(props))\n}\n\nexport default Component.extend({\n constructor: Record,\n\n /**\n * Returns the {@link Mapper} paired with this record's class, if any.\n *\n * @method Record#_mapper\n * @returns {Mapper} The {@link Mapper} paired with this record's class, if any.\n * @since 3.0.0\n */\n _mapper () {\n const mapper = this.constructor.mapper\n if (!mapper) {\n throw utils.err(`${DOMAIN}#_mapper`, '')(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Lifecycle hook.\n *\n * @method Record#afterLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n afterLoadRelations () {},\n\n /**\n * Lifecycle hook.\n *\n * @method Record#beforeLoadRelations\n * @param {string[]} relations The `relations` argument passed to {@link Record#loadRelations}.\n * @param {Object} opts The `opts` argument passed to {@link Record#loadRelations}.\n * @since 3.0.0\n */\n beforeLoadRelations () {},\n\n /**\n * Return the change history of this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @method Record#changeHistory\n * @since 3.0.0\n */\n changeHistory () {\n return (this._get('history') || []).slice()\n },\n\n /**\n * Return changes to this record since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#changes\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n * user.name = 'John'\n * console.log('user changes: ' + JSON.stringify(user.changes()))\n *\n * @method Record#changes\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {Object} Object describing the changes to this record since it was\n * instantiated or its {@link Record#commit} method was last called.\n * @since 3.0.0\n */\n changes (opts) {\n opts || (opts = {})\n return utils.diffObjects(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Make the record's current in-memory state it's only state, with any\n * previous property values being set to current values.\n *\n * @example Record#commit\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#commit\n * @param {Object} [opts] Configuration options. Passed to {@link Record#toJSON}.\n * @since 3.0.0\n */\n commit (opts) {\n this._set('changed') // unset\n this._set('history', []) // clear history\n this._set('previous', this.toJSON(opts))\n },\n\n /**\n * Call {@link Mapper#destroy} using this record's primary key.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user')\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Destroy this user from the database\n * return user.destroy()\n * })\n *\n * @method Record#destroy\n * @param {Object} [opts] Configuration options passed to {@link Mapper#destroy}.\n * @returns {Promise} The result of calling {@link Mapper#destroy} with the\n * primary key of this record.\n * @since 3.0.0\n */\n destroy (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n return superMethod(mapper, 'destroy')(utils.get(this, mapper.idAttribute), opts)\n },\n\n /**\n * Return the value at the given path for this instance.\n *\n * @example Record#get\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', { name: 'Bob' })\n * console.log('user.get(\"name\"): ' + user.get('name'))\n *\n * @method Record#get\n * @param {string} key Path of value to retrieve.\n * @returns {*} Value at path.\n * @since 3.0.0\n */\n 'get' (key) {\n return utils.get(this, key)\n },\n\n /**\n * Return whether this record has changed since it was instantiated or\n * {@link Record#commit} was called.\n *\n * @example Record#hasChanges\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.name = 'John'\n * console.log('user hasChanges: ' + user.hasChanges())\n * user.commit()\n * console.log('user hasChanges: ' + user.hasChanges())\n *\n * @method Record#hasChanges\n * @param [opts] Configuration options.\n * @param {Function} [opts.equalsFn={@link utils.deepEqual}] Equality function.\n * @param {Array} [opts.ignore=[]] Array of strings or RegExp of fields to ignore.\n * @returns {boolean} Return whether the record has changed since it was\n * instantiated or since its {@link Record#commit} method was called.\n * @since 3.0.0\n */\n hasChanges (opts) {\n const quickHasChanges = !!(this._get('changed') || []).length\n return quickHasChanges || utils.areDifferent(typeof this.toJSON === 'function' ? this.toJSON(opts) : this, this._get('previous'), opts)\n },\n\n /**\n * Return whether the record is unsaved. Records that have primary keys are\n * considered \"saved\". Records without primary keys are considered \"unsaved\".\n *\n * @example Record#isNew\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * id: 1234\n * })\n * const user2 = store.createRecord('user')\n * console.log('user isNew: ' + user.isNew()) // false\n * console.log('user2 isNew: ' + user2.isNew()) // true\n *\n * @method Record#isNew\n * @returns {boolean} Whether the record is unsaved.\n * @since 3.0.0\n */\n isNew (opts) {\n return utils.get(this, this._mapper().idAttribute) === undefined\n },\n\n /**\n * Return whether the record in its current state passes validation.\n *\n * @example Record#isValid\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user isValid: ' + user.isValid())\n * user.name = 'John'\n * console.log('user isValid: ' + user.isValid())\n *\n * @method Record#isValid\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {boolean} Whether the record in its current state passes\n * validation.\n * @since 3.0.0\n */\n isValid (opts) {\n return !this._mapper().validate(this, opts)\n },\n\n removeInverseRelation (currentParent, id, inverseDef, idAttribute) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n // e.g. remove comment from otherPost.comments\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n setupInverseRelation (record, id, inverseDef, idAttribute) {\n // Update (set) inverse relation\n if (inverseDef.type === hasOneType) {\n // e.g. someUser.profile = profile\n safeSetLink(record, inverseDef.localField, this)\n } else if (inverseDef.type === hasManyType) {\n // e.g. add comment to somePost.comments\n const children = utils.get(record, inverseDef.localField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n },\n\n /**\n * Lazy load relations of this record, to be attached to the record once their\n * loaded.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('user', {\n * relations: {\n * hasMany: {\n * post: {\n * localField: 'posts',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.defineMapper('post', {\n * relations: {\n * belongsTo: {\n * user: {\n * localField: 'user',\n * foreignKey: 'user_id'\n * }\n * }\n * }\n * })\n * store.find('user', 1234).then((user) => {\n * console.log(user.id) // 1234\n *\n * // Load the user's post relations\n * return user.loadRelations(['post'])\n * }).then((user) => {\n * console.log(user.posts) // [{...}, {...}, ...]\n * })\n *\n * @method Record#loadRelations\n * @param {string[]} [relations] List of relations to load. Can use localField\n * names or Mapper names to pick relations.\n * @param {Object} [opts] Configuration options.\n * @returns {Promise} Resolves with the record, with the loaded relations now\n * attached.\n * @since 3.0.0\n */\n loadRelations (relations, opts) {\n let op\n const mapper = this._mapper()\n\n // Default values for arguments\n relations || (relations = [])\n if (utils.isString(relations)) {\n relations = [relations]\n }\n opts || (opts = {})\n opts.with = relations\n\n // Fill in \"opts\" with the Model's configuration\n utils._(opts, mapper)\n opts.adapter = mapper.getAdapterName(opts)\n\n // beforeLoadRelations lifecycle hook\n op = opts.op = 'beforeLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'loadRelations'\n mapper.dbg(op, this, relations, opts)\n let tasks = []\n let task\n utils.forEachRelation(mapper, opts, (def, optsCopy) => {\n const relatedMapper = def.getRelation()\n optsCopy.raw = false\n if (utils.isFunction(def.load)) {\n task = def.load(mapper, def, this, opts)\n } else if (def.type === 'hasMany' || def.type === 'hasOne') {\n if (def.foreignKey) {\n task = superMethod(relatedMapper, 'findAll')({\n [def.foreignKey]: utils.get(this, mapper.idAttribute)\n }, optsCopy).then(function (relatedData) {\n if (def.type === 'hasOne') {\n return relatedData.length ? relatedData[0] : undefined\n }\n return relatedData\n })\n } else if (def.localKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [relatedMapper.idAttribute]: {\n 'in': utils.get(this, def.localKeys)\n }\n }\n })\n } else if (def.foreignKeys) {\n task = superMethod(relatedMapper, 'findAll')({\n where: {\n [def.foreignKeys]: {\n 'contains': utils.get(this, mapper.idAttribute)\n }\n }\n }, opts)\n }\n } else if (def.type === 'belongsTo') {\n const key = utils.get(this, def.foreignKey)\n if (utils.isSorN(key)) {\n task = superMethod(relatedMapper, 'find')(key, optsCopy)\n }\n }\n if (task) {\n task = task.then((relatedData) => {\n def.setLocalField(this, relatedData)\n })\n tasks.push(task)\n }\n })\n return Promise.all(tasks)\n }).then(() => {\n // afterLoadRelations lifecycle hook\n op = opts.op = 'afterLoadRelations'\n return utils.resolve(this[op](relations, opts)).then(() => this)\n })\n },\n\n /**\n * Return the properties with which this record was instantiated.\n *\n * @example Record#previous\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.name = 'Bob'\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n * user.commit()\n * console.log('user previous: ' + JSON.stringify(user.previous()))\n *\n * @method Record#previous\n * @param {string} [key] If specified, return just the initial value of the\n * given key.\n * @returns {Object} The initial properties of this record.\n * @since 3.0.0\n */\n previous (key) {\n if (key) {\n return this._get(`previous.${key}`)\n }\n return this._get('previous')\n },\n\n /**\n * Revert changes to this record back to the properties it had when it was\n * instantiated.\n *\n * @example Record#revert\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user', {\n * name: 'William'\n * })\n * console.log('user: ' + JSON.stringify(user))\n * user.name = 'Bob'\n * console.log('user: ' + JSON.stringify(user))\n * user.revert()\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#revert\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.preserve] Array of strings or Regular Expressions\n * denoting properties that should not be reverted.\n * @since 3.0.0\n */\n revert (opts) {\n const previous = this._get('previous')\n opts || (opts = {})\n opts.preserve || (opts.preserve = [])\n utils.forOwn(this, (value, key) => {\n if (key !== this._mapper().idAttribute && !previous.hasOwnProperty(key) && this.hasOwnProperty(key) && opts.preserve.indexOf(key) === -1) {\n delete this[key]\n }\n })\n utils.forOwn(previous, (value, key) => {\n if (opts.preserve.indexOf(key) === -1) {\n this[key] = value\n }\n })\n this.commit()\n },\n\n /**\n * Delegates to {@link Mapper#create} or {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n *\n * const store = new Container()\n * store.registerAdapter('rethink', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('session')\n * const session = store.createRecord('session', { topic: 'Node.js' })\n *\n * // Create a new record in the database\n * session.save().then(() => {\n * console.log(session.id) // 1234\n *\n * session.skill_level = 'beginner'\n *\n * // Update the record in the database\n * return session.save()\n * })\n *\n * @method Record#save\n * @param {Object} [opts] Configuration options. See {@link Mapper#create} and\n * {@link Mapper#update}.\n * @param {boolean} [opts.changesOnly] Equality function. Default uses `===`.\n * @param {Function} [opts.equalsFn] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @param {Array} [opts.ignore] Passed to {@link Record#changes} when\n * `opts.changesOnly` is `true`.\n * @returns {Promise} The result of calling {@link Mapper#create} or\n * {@link Mapper#update}.\n * @since 3.0.0\n */\n save (opts) {\n opts || (opts = {})\n const mapper = this._mapper()\n const id = utils.get(this, mapper.idAttribute)\n let props = this\n\n const postProcess = (result) => {\n const record = opts.raw ? result.data : result\n if (record) {\n utils.deepMixIn(this, record)\n this.commit()\n }\n return result\n }\n\n if (id === undefined) {\n return superMethod(mapper, 'create')(props, opts).then(postProcess)\n }\n if (opts.changesOnly) {\n const changes = this.changes(opts)\n props = {}\n utils.fillIn(props, changes.added)\n utils.fillIn(props, changes.changed)\n }\n return superMethod(mapper, 'update')(id, props, opts).then(postProcess)\n },\n\n /**\n * Set the value for a given key, or the values for the given keys if \"key\" is\n * an object. Triggers change events on those properties that have `track: true`\n * in {@link Mapper#schema}.\n *\n * @example Record#set\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set('name', 'Bob')\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.set({ age: 30, role: 'admin' })\n * console.log('user: ' + JSON.stringify(user))\n *\n * @fires Record#change\n * @method Record#set\n * @param {(string|Object)} key Key to set or hash of key-value pairs to set.\n * @param {*} [value] Value to set for the given key.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n 'set' (key, value, opts) {\n if (utils.isObject(key)) {\n opts = value\n }\n opts || (opts = {})\n if (opts.silent) {\n this._set('silent', true)\n }\n utils.set(this, key, value)\n if (!this._get('eventId')) {\n this._set('silent') // unset\n }\n },\n\n /**\n * Return a plain object representation of this record. If the class from\n * which this record was created has a Mapper, then {@link Mapper#toJSON} will\n * be called with this record instead.\n *\n * @example Record#toJSON\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n *\n * const user = store.createRecord('user', {\n * name: 'John',\n * $$hashKey: '1234'\n * })\n * console.log('user: ' + JSON.stringify(user.toJSON()))\n * console.log('user: ' + JSON.stringify(user.toJSON({ strict: true })))\n *\n * @method Record#toJSON\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the representation. Only available as an option if the class\n * from which this record was created has a Mapper and this record resides in\n * an instance of {@link DataStore}.\n * @returns {Object} Plain object representation of this record.\n * @since 3.0.0\n */\n toJSON (opts) {\n const mapper = this.constructor.mapper\n if (mapper) {\n return mapper.toJSON(this, opts)\n } else {\n const json = {}\n utils.forOwn(this, function (prop, key) {\n json[key] = utils.plainCopy(prop)\n })\n return json\n }\n },\n\n /**\n * Unset the value for a given key. Triggers change events on those properties\n * that have `track: true` in {@link Mapper#schema}.\n *\n * @example Record#unset\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user')\n *\n * const user = store.createRecord('user', {\n * name: 'John'\n * })\n * console.log('user: ' + JSON.stringify(user))\n *\n * user.unset('name')\n * console.log('user: ' + JSON.stringify(user))\n *\n * @method Record#unset\n * @param {string} key Key to unset.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.silent=false] Whether to trigger change events.\n * @since 3.0.0\n */\n unset (key, opts) {\n this.set(key, undefined, opts)\n },\n\n /**\n * Validate this record based on its current properties.\n *\n * @example Record#validate\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: {\n * properties: {\n * name: { type: 'string' }\n * }\n * }\n * })\n * const user = store.createRecord('user', {\n * name: 1234\n * }, {\n * noValidate: true // this allows us to put the record into an invalid state\n * })\n * console.log('user validation: ' + JSON.stringify(user.validate()))\n * user.name = 'John'\n * console.log('user validation: ' + user.validate())\n *\n * @method Record#validate\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#validate}.\n * @returns {*} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (opts) {\n return this._mapper().validate(this, opts)\n }\n})\n\n/**\n * Allow records to emit events.\n *\n * An record's registered listeners are stored in the record's private data.\n */\nutils.eventify(\n Record.prototype,\n function () {\n return this._get('events')\n },\n function (value) {\n this._set('events', value)\n }\n)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link Record~changeListener} on how to listen for this event.\n *\n * @event Record#change\n * @see Record~changeListener\n */\n\n/**\n * Callback signature for the {@link Record#event:change} event.\n *\n * @example\n * function onChange (record, changes) {\n * // do something\n * }\n * record.on('change', onChange)\n *\n * @callback Record~changeListener\n * @param {Record} The Record that changed.\n * @param {Object} The changes.\n * @see Record#event:change\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this Record:\n * @example Record.extend\n * // Normally you would do: import {Record} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Record} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomRecordClass extends Record {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customRecord = new CustomRecordClass()\n * console.log(customRecord.foo())\n * console.log(CustomRecordClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherRecordClass = Record.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherRecord = new OtherRecordClass()\n * console.log(otherRecord.foo())\n * console.log(OtherRecordClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherRecordClass () {\n * Record.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Record.extend({\n * constructor: AnotherRecordClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherRecord = new AnotherRecordClass()\n * console.log(anotherRecord.created_at)\n * console.log(anotherRecord.foo())\n * console.log(AnotherRecordClass.beep())\n *\n * @method Record.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Record class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\n\nconst DOMAIN = 'Schema'\n\n/**\n * A function map for each of the seven primitive JSON types defined by the core specification.\n * Each function will check a given value and return true or false if the value is an instance of that type.\n * ```\n * types.integer(1) // returns true\n * types.string({}) // returns false\n * ```\n * http://json-schema.org/latest/json-schema-core.html#anchor8\n * @name Schema.types\n * @type {Object}\n */\nconst types = {\n array: utils.isArray,\n boolean: utils.isBoolean,\n integer: utils.isInteger,\n 'null': utils.isNull,\n number: utils.isNumber,\n object: utils.isObject,\n string: utils.isString\n}\n\n/**\n * @ignore\n */\nconst segmentToString = function (segment, prev) {\n let str = ''\n if (segment) {\n if (utils.isNumber(segment)) {\n str += `[${segment}]`\n } else if (prev) {\n str += `.${segment}`\n } else {\n str += `${segment}`\n }\n }\n return str\n}\n\n/**\n * @ignore\n */\nconst makePath = function (opts) {\n opts || (opts = {})\n let path = ''\n const segments = opts.path || []\n segments.forEach(function (segment) {\n path += segmentToString(segment, path)\n })\n path += segmentToString(opts.prop, path)\n return path\n}\n\n/**\n * @ignore\n */\nconst makeError = function (actual, expected, opts) {\n return {\n expected,\n actual: '' + actual,\n path: makePath(opts)\n }\n}\n\n/**\n * @ignore\n */\nconst addError = function (actual, expected, opts, errors) {\n errors.push(makeError(actual, expected, opts))\n}\n\n/**\n * @ignore\n */\nconst maxLengthCommon = function (keyword, value, schema, opts) {\n const max = schema[keyword]\n if (value.length > max) {\n return makeError(value.length, `length no more than ${max}`, opts)\n }\n}\n\n/**\n * @ignore\n */\nconst minLengthCommon = function (keyword, value, schema, opts) {\n const min = schema[keyword]\n if (value.length < min) {\n return makeError(value.length, `length no less than ${min}`, opts)\n }\n}\n\n/**\n * A map of all object member validation functions for each keyword defined in the JSON Schema.\n * @name Schema.validationKeywords\n * @type {Object}\n */\nconst validationKeywords = {\n /**\n * Validates the provided value against all schemas defined in the Schemas `allOf` keyword.\n * The instance is valid against if and only if it is valid against all the schemas declared in the Schema's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be a valid JSON Schema.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor82\n *\n * @name Schema.validationKeywords.allOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `allOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n allOf (value, schema, opts) {\n let allErrors = []\n schema.allOf.forEach(function (_schema) {\n allErrors = allErrors.concat(validate(value, _schema, opts) || [])\n })\n return allErrors.length ? allErrors : undefined\n },\n\n /**\n * Validates the provided value against all schemas defined in the Schemas `anyOf` keyword.\n * The instance is valid against this keyword if and only if it is valid against\n * at least one of the schemas in this keyword's value.\n *\n * The value of this keyword MUST be an array. This array MUST have at least one element.\n * Each element of this array MUST be an object, and each object MUST be a valid JSON Schema.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor85\n *\n * @name Schema.validationKeywords.anyOf\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `anyOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n anyOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.anyOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * http://json-schema.org/latest/json-schema-validation.html#anchor70\n *\n * @name Schema.validationKeywords.dependencies\n * @method\n * @param {*} value TODO\n * @param {Object} schema TODO\n * @param {Object} opts TODO\n */\n dependencies (value, schema, opts) {\n // TODO\n },\n\n /**\n * Validates the provided value against an array of possible values defined by the Schema's `enum` keyword\n * Validation succeeds if the value is deeply equal to one of the values in the array.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor76\n *\n * @name Schema.validationKeywords.enum\n * @method\n * @param {*} value Value to validate\n * @param {Object} schema Schema containing the `enum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n enum (value, schema, opts) {\n const possibleValues = schema['enum']\n if (utils.findIndex(possibleValues, (item) => utils.deepEqual(item, value)) === -1) {\n return makeError(value, `one of (${possibleValues.join(', ')})`, opts)\n }\n },\n\n /**\n * Validates each of the provided array values against a schema or an array of schemas defined by the Schema's `items` keyword\n * see http://json-schema.org/latest/json-schema-validation.html#anchor37 for validation rules.\n *\n * @name Schema.validationKeywords.items\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the items keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n items (value, schema, opts) {\n opts || (opts = {})\n // TODO: additionalItems\n let items = schema.items\n let errors = []\n const checkingTuple = utils.isArray(items)\n const length = value.length\n for (var prop = 0; prop < length; prop++) {\n if (checkingTuple) {\n // Validating a tuple, instead of just checking each item against the\n // same schema\n items = schema.items[prop]\n }\n opts.prop = prop\n errors = errors.concat(validate(value[prop], items, opts) || [])\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided number against a maximum value defined by the Schema's `maximum` keyword\n * Validation succeeds if the value is a number, and is less than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor17\n *\n * @name Schema.validationKeywords.maximum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `maximum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maximum (value, schema, opts) {\n // Must be a number\n const maximum = schema.maximum\n // Must be a boolean\n // Depends on maximum\n // default: false\n const exclusiveMaximum = schema.exclusiveMaximum\n if (typeof value === typeof maximum && !(exclusiveMaximum ? maximum > value : maximum >= value)) {\n return exclusiveMaximum\n ? makeError(value, `no more than nor equal to ${maximum}`, opts)\n : makeError(value, `no more than ${maximum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a maximum value defined by the Schema's `maxItems` keyword.\n * Validation succeeds if the length of the array is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor42\n *\n * @name Schema.validationKeywords.maxItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `maxItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return maxLengthCommon('maxItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a maximum value defined in the Schema's `maxLength` keyword.\n * Validation succeeds if the length of the string is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor26\n *\n * @name Schema.validationKeywords.maxLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `maxLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxLength (value, schema, opts) {\n return maxLengthCommon('maxLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a maximum value defined in the Schema's `maxProperties` keyword.\n * Validation succeeds if the object's property count is less than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor54\n *\n * @name Schema.validationKeywords.maxProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `maxProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n maxProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const maxProperties = schema.maxProperties\n const length = Object.keys(value).length\n if (length > maxProperties) {\n return makeError(length, `no more than ${maxProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided value against a minimum value defined by the Schema's `minimum` keyword\n * Validation succeeds if the value is a number and is greater than, or equal to, the value of this keyword.\n * http://json-schema.org/latest/json-schema-validation.html#anchor21\n *\n * @name Schema.validationKeywords.minimum\n * @method\n * @param {*} value Number to validate against the keyword.\n * @param {Object} schema Schema containing the `minimum` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minimum (value, schema, opts) {\n // Must be a number\n const minimum = schema.minimum\n // Must be a boolean\n // Depends on minimum\n // default: false\n const exclusiveMinimum = schema.exclusiveMinimum\n if (typeof value === typeof minimum && !(exclusiveMinimum ? value > minimum : value >= minimum)) {\n return exclusiveMinimum\n ? makeError(value, `no less than nor equal to ${minimum}`, opts)\n : makeError(value, `no less than ${minimum}`, opts)\n }\n },\n\n /**\n * Validates the length of the provided array against a minimum value defined by the Schema's `minItems` keyword.\n * Validation succeeds if the length of the array is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor45\n *\n * @name Schema.validationKeywords.minItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `minItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minItems (value, schema, opts) {\n if (utils.isArray(value)) {\n return minLengthCommon('minItems', value, schema, opts)\n }\n },\n\n /**\n * Validates the length of the provided string against a minimum value defined in the Schema's `minLength` keyword.\n * Validation succeeds if the length of the string is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor29\n *\n * @name Schema.validationKeywords.minLength\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `minLength` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minLength (value, schema, opts) {\n return minLengthCommon('minLength', value, schema, opts)\n },\n\n /**\n * Validates the count of the provided object's properties against a minimum value defined in the Schema's `minProperties` keyword.\n * Validation succeeds if the object's property count is greater than, or equal to the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor57\n *\n * @name Schema.validationKeywords.minProperties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `minProperties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n minProperties (value, schema, opts) {\n // validate only objects\n if (!utils.isObject(value)) return\n const minProperties = schema.minProperties\n const length = Object.keys(value).length\n if (length < minProperties) {\n return makeError(length, `no more than ${minProperties} properties`, opts)\n }\n },\n\n /**\n * Validates the provided number is a multiple of the number defined in the Schema's `multipleOf` keyword.\n * Validation succeeds if the number can be divided equally into the value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor14\n *\n * @name Schema.validationKeywords.multipleOf\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing the `multipleOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n multipleOf (value, schema, opts) {\n const multipleOf = schema.multipleOf\n if (utils.isNumber(value)) {\n if ((value / multipleOf) % 1 !== 0) {\n return makeError(value, `multipleOf ${multipleOf}`, opts)\n }\n }\n },\n\n /**\n * Validates the provided value is not valid with any of the schemas defined in the Schema's `not` keyword.\n * An instance is valid against this keyword if and only if it is NOT valid against the schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor91\n * @name Schema.validationKeywords.not\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the not keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n not (value, schema, opts) {\n if (!validate(value, schema.not, opts)) {\n // TODO: better messaging\n return makeError('succeeded', 'should have failed', opts)\n }\n },\n\n /**\n * Validates the provided value is valid with one and only one of the schemas defined in the Schema's `oneOf` keyword.\n * An instance is valid against this keyword if and only if it is valid against a single schemas in this keyword's value.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor88\n * @name Schema.validationKeywords.oneOf\n * @method\n * @param {*} value to be checked.\n * @param {Object} schema Schema containing the `oneOf` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n oneOf (value, schema, opts) {\n let validated = false\n let allErrors = []\n schema.oneOf.forEach(function (_schema) {\n const errors = validate(value, _schema, opts)\n if (errors) {\n allErrors = allErrors.concat(errors)\n } else if (validated) {\n allErrors = [makeError('valid against more than one', 'valid against only one', opts)]\n validated = false\n return false\n } else {\n validated = true\n }\n })\n return validated ? undefined : allErrors\n },\n\n /**\n * Validates the provided string matches a pattern defined in the Schema's `pattern` keyword.\n * Validation succeeds if the string is a match of the regex value of this keyword.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor33\n * @name Schema.validationKeywords.pattern\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing the `pattern` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n pattern (value, schema, opts) {\n const pattern = schema.pattern\n if (utils.isString(value) && !value.match(pattern)) {\n return makeError(value, pattern, opts)\n }\n },\n\n /**\n * Validates the provided object's properties against a map of values defined in the Schema's `properties` keyword.\n * Validation succeeds if the object's property are valid with each of the schema's in the provided map.\n * Validation also depends on the additionalProperties and or patternProperties.\n *\n * see http://json-schema.org/latest/json-schema-validation.html#anchor64 for more info.\n *\n * @name Schema.validationKeywords.properties\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `properties` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n properties (value, schema, opts) {\n opts || (opts = {})\n\n if (utils.isArray(value)) {\n return\n }\n\n // Can be a boolean or an object\n // Technically the default is an \"empty schema\", but here \"true\" is\n // functionally the same\n const additionalProperties = schema.additionalProperties === undefined ? true : schema.additionalProperties\n const validated = []\n // \"p\": The property set from \"properties\".\n // Default is an object\n const properties = schema.properties || {}\n // \"pp\": The property set from \"patternProperties\".\n // Default is an object\n const patternProperties = schema.patternProperties || {}\n let errors = []\n\n utils.forOwn(properties, function (_schema, prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n validated.push(prop)\n })\n\n const toValidate = utils.omit(value, validated)\n utils.forOwn(patternProperties, function (_schema, pattern) {\n utils.forOwn(toValidate, function (undef, prop) {\n if (prop.match(pattern)) {\n opts.prop = prop\n // console.log(_schema)\n errors = errors.concat(validate(value[prop], _schema, opts) || [])\n validated.push(prop)\n }\n })\n })\n const keys = Object.keys(utils.omit(value, validated))\n // If \"s\" is not empty, validation fails\n if (additionalProperties === false) {\n if (keys.length) {\n const origProp = opts.prop\n opts.prop = ''\n addError(`extra fields: ${keys.join(', ')}`, 'no extra fields', opts, errors)\n opts.prop = origProp\n }\n } else if (utils.isObject(additionalProperties)) {\n // Otherwise, validate according to provided schema\n keys.forEach(function (prop) {\n opts.prop = prop\n errors = errors.concat(validate(value[prop], additionalProperties, opts) || [])\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided object's has all properties listed in the Schema's `properties` keyword array.\n * Validation succeeds if the object contains all properties provided in the array value of this keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor61\n *\n * @name Schema.validationKeywords.required\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing the `required` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n required (value, schema, opts) {\n opts || (opts = {})\n const required = schema.required\n let errors = []\n if (!opts.existingOnly) {\n required.forEach(function (prop) {\n if (utils.get(value, prop) === undefined) {\n const prevProp = opts.prop\n opts.prop = prop\n addError(undefined, 'a value', opts, errors)\n opts.prop = prevProp\n }\n })\n }\n return errors.length ? errors : undefined\n },\n\n /**\n * Validates the provided value's type is equal to the type, or array of types, defined in the Schema's `type` keyword.\n * see http://json-schema.org/latest/json-schema-validation.html#anchor79\n *\n * @name Schema.validationKeywords.type\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Schema containing the `type` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n type (value, schema, opts) {\n let type = schema.type\n let validType\n // Can be one of several types\n if (utils.isString(type)) {\n type = [type]\n }\n // Try to match the value against an expected type\n type.forEach(function (_type) {\n // TODO: throw an error if type is not defined\n if (types[_type](value, schema, opts)) {\n // Matched a type\n validType = _type\n return false\n }\n })\n // Value did not match any expected type\n if (!validType) {\n return makeError(value !== undefined && value !== null ? typeof value : '' + value, `one of (${type.join(', ')})`, opts)\n }\n // Run keyword validators for matched type\n // http://json-schema.org/latest/json-schema-validation.html#anchor12\n const validator = typeGroupValidators[validType]\n if (validator) {\n return validator(value, schema, opts)\n }\n },\n\n /**\n * Validates the provided array values are unique.\n * Validation succeeds if the items in the array are unique, but only if the value of this keyword is true\n * see http://json-schema.org/latest/json-schema-validation.html#anchor49\n *\n * @name Schema.validationKeywords.uniqueItems\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing the `uniqueItems` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n uniqueItems (value, schema, opts) {\n if (value && value.length && schema.uniqueItems) {\n const length = value.length\n let item, i, j\n // Check n - 1 items\n for (i = length - 1; i > 0; i--) {\n item = value[i]\n // Only compare against unchecked items\n for (j = i - 1; j >= 0; j--) {\n // Found a duplicate\n if (utils.deepEqual(item, value[j])) {\n return makeError(item, 'no duplicates', opts)\n }\n }\n }\n }\n }\n}\n\n/**\n * @ignore\n */\nconst runOps = function (ops, value, schema, opts) {\n let errors = []\n ops.forEach(function (op) {\n if (schema[op] !== undefined) {\n errors = errors.concat(validationKeywords[op](value, schema, opts) || [])\n }\n })\n return errors.length ? errors : undefined\n}\n\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\nconst STRING_OPS = ['maxLength', 'minLength', 'pattern']\n\n/**\n * http://json-schema.org/latest/json-schema-validation.html#anchor75\n * @ignore\n */\nconst validateAny = function (value, schema, opts) {\n return runOps(ANY_OPS, value, schema, opts)\n}\n\n/**\n * Validates the provided value against a given Schema according to the http://json-schema.org/ v4 specification.\n *\n * @name Schema.validate\n * @method\n * @param {*} value Value to be validated.\n * @param {Object} schema Valid Schema according to the http://json-schema.org/ v4 specification.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\nconst validate = function (value, schema, opts) {\n let errors = []\n opts || (opts = {})\n opts.ctx || (opts.ctx = { value, schema })\n let shouldPop\n let prevProp = opts.prop\n if (schema === undefined) {\n return\n }\n if (!utils.isObject(schema)) {\n throw utils.err(`${DOMAIN}#validate`)(500, `Invalid schema at path: \"${opts.path}\"`)\n }\n if (opts.path === undefined) {\n opts.path = []\n }\n // Track our location as we recurse\n if (opts.prop !== undefined) {\n shouldPop = true\n opts.path.push(opts.prop)\n opts.prop = undefined\n }\n // Validate against parent schema\n if (schema['extends']) {\n // opts.path = path\n // opts.prop = prop\n if (utils.isFunction(schema['extends'].validate)) {\n errors = errors.concat(schema['extends'].validate(value, opts) || [])\n } else {\n errors = errors.concat(validate(value, schema['extends'], opts) || [])\n }\n }\n if (value === undefined) {\n // Check if property is required\n if (schema.required === true && !opts.existingOnly) {\n addError(value, 'a value', opts, errors)\n }\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n }\n\n errors = errors.concat(validateAny(value, schema, opts) || [])\n if (shouldPop) {\n opts.path.pop()\n opts.prop = prevProp\n }\n return errors.length ? errors : undefined\n}\n\n// These strings are cached for optimal performance of the change detection\n// boolean - Whether a Record is changing in the current execution frame\nconst changingPath = 'changing'\n// string[] - Properties that have changed in the current execution frame\nconst changedPath = 'changed'\n// Object[] - History of change records\nconst changeHistoryPath = 'history'\n// boolean - Whether a Record is currently being instantiated\nconst creatingPath = 'creating'\n// number - The setTimeout change event id of a Record, if any\nconst eventIdPath = 'eventId'\n// boolean - Whether to skip validation for a Record's currently changing property\nconst noValidatePath = 'noValidate'\n// boolean - Whether to preserve Change History for a Record\nconst keepChangeHistoryPath = 'keepChangeHistory'\n// boolean - Whether to skip change notification for a Record's currently\n// changing property\nconst silentPath = 'silent'\nconst validationFailureMsg = 'validation failed'\n\n/**\n * Assemble a property descriptor which will be added to the prototype of\n * {@link Mapper#recordClass}. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @ignore\n */\nconst makeDescriptor = function (prop, schema, opts) {\n const descriptor = {\n // Better to allow configurability, but at the user's own risk\n configurable: true,\n // These properties are enumerable by default, but regardless of their\n // enumerability, they won't be \"own\" properties of individual records\n enumerable: schema.enumerable === undefined ? true : !!schema.enumerable\n }\n // Cache a few strings for optimal performance\n const keyPath = `props.${prop}`\n const previousPath = `previous.${prop}`\n const getter = opts.getter\n const setter = opts.setter\n const unsetter = opts.unsetter\n const track = utils.isBoolean(opts.track) ? opts.track : schema.track\n\n descriptor.get = function () {\n return this._get(keyPath)\n }\n\n if (utils.isFunction(schema.get)) {\n const originalGet = descriptor.get\n descriptor.get = function () {\n return schema.get.call(this, originalGet)\n }\n }\n\n descriptor.set = function (value) {\n // These are accessed a lot\n const _get = this[getter]\n const _set = this[setter]\n const _unset = this[unsetter]\n // Optionally check that the new value passes validation\n if (!_get(noValidatePath)) {\n const errors = schema.validate(value, { path: [prop] })\n if (errors) {\n // Immediately throw an error, preventing the record from getting into\n // an invalid state\n const error = new Error(validationFailureMsg)\n error.errors = errors\n throw error\n }\n }\n // TODO: Make it so tracking can be turned on for all properties instead of\n // only per-property\n if (track && !_get(creatingPath)) {\n // previous is versioned on database commit\n // props are versioned on set()\n const previous = _get(previousPath)\n const current = _get(keyPath)\n let changing = _get(changingPath)\n let changed = _get(changedPath)\n\n if (!changing) {\n // Track properties that are changing in the current event loop\n changed = []\n }\n\n // Add changing properties to this array once at most\n const index = changed.indexOf(prop)\n if (current !== value && index === -1) {\n changed.push(prop)\n }\n if (previous === value) {\n if (index >= 0) {\n changed.splice(index, 1)\n }\n }\n // No changes in current event loop\n if (!changed.length) {\n changing = false\n _unset(changingPath)\n _unset(changedPath)\n // Cancel pending change event\n if (_get(eventIdPath)) {\n clearTimeout(_get(eventIdPath))\n _unset(eventIdPath)\n }\n }\n // Changes detected in current event loop\n if (!changing && changed.length) {\n _set(changedPath, changed)\n _set(changingPath, true)\n // Saving the timeout id allows us to batch all changes in the same\n // event loop into a single \"change\"\n // TODO: Optimize\n _set(eventIdPath, setTimeout(() => {\n // Previous event loop where changes were gathered has ended, so\n // notify any listeners of those changes and prepare for any new\n // changes\n _unset(changedPath)\n _unset(eventIdPath)\n _unset(changingPath)\n // TODO: Optimize\n if (!_get(silentPath)) {\n let i\n for (i = 0; i < changed.length; i++) {\n this.emit('change:' + changed[i], this, utils.get(this, changed[i]))\n }\n\n const changes = utils.diffObjects({ [prop]: value }, { [prop]: current })\n\n if (_get(keepChangeHistoryPath)) {\n const changeRecord = utils.plainCopy(changes)\n changeRecord.timestamp = new Date().getTime()\n let changeHistory = _get(changeHistoryPath)\n !changeHistory && _set(changeHistoryPath, (changeHistory = []))\n changeHistory.push(changeRecord)\n }\n this.emit('change', this, changes)\n }\n _unset(silentPath)\n }, 0))\n }\n }\n _set(keyPath, value)\n return value\n }\n\n if (utils.isFunction(schema.set)) {\n const originalSet = descriptor.set\n descriptor.set = function (value) {\n return schema.set.call(this, value, originalSet)\n }\n }\n\n return descriptor\n}\n\n/**\n * A map of validation functions grouped by type.\n *\n * @name Schema.typeGroupValidators\n * @type {Object}\n */\nconst typeGroupValidators = {\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an array.\n * The validation keywords for the type `array` are:\n *```\n * ['items', 'maxItems', 'minItems', 'uniqueItems']\n *```\n * see http://json-schema.org/latest/json-schema-validation.html#anchor25\n *\n * @name Schema.typeGroupValidators.array\n * @method\n * @param {*} value Array to be validated.\n * @param {Object} schema Schema containing at least one array keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n array: function (value, schema, opts) {\n return runOps(ARRAY_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an integer.\n * The validation keywords for the type `integer` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.integer\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `integer` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n integer: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an number.\n * The validation keywords for the type `number` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * @name Schema.typeGroupValidators.number\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `number` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n number: function (value, schema, opts) {\n // Additional validations for numerics are the same\n return typeGroupValidators.numeric(value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of a number or integer.\n * The validation keywords for the type `numeric` are:\n *```\n * ['multipleOf', 'maximum', 'minimum']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor13.\n *\n * @name Schema.typeGroupValidators.numeric\n * @method\n * @param {*} value Number to be validated.\n * @param {Object} schema Schema containing at least one `numeric` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n numeric: function (value, schema, opts) {\n return runOps(NUMERIC_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an object.\n * The validation keywords for the type `object` are:\n *```\n * ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor53.\n *\n * @name Schema.typeGroupValidators.object\n * @method\n * @param {*} value Object to be validated.\n * @param {Object} schema Schema containing at least one `object` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n object: function (value, schema, opts) {\n return runOps(OBJECT_OPS, value, schema, opts)\n },\n\n /**\n * Validates the provided value against the schema using all of the validation keywords specific to instances of an string.\n * The validation keywords for the type `string` are:\n *```\n * ['maxLength', 'minLength', 'pattern']\n *```\n * See http://json-schema.org/latest/json-schema-validation.html#anchor25.\n *\n * @name Schema.typeGroupValidators.string\n * @method\n * @param {*} value String to be validated.\n * @param {Object} schema Schema containing at least one `string` keyword.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n string: function (value, schema, opts) {\n return runOps(STRING_OPS, value, schema, opts)\n }\n}\n\n/**\n * js-data's Schema class.\n *\n * @example Schema#constructor\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const PostSchema = new Schema({\n * type: 'object',\n * properties: {\n * title: { type: 'string' }\n * }\n * })\n * PostSchema.validate({ title: 1234 })\n *\n * @class Schema\n * @extends Component\n * @param {Object} definition Schema definition according to json-schema.org\n */\nfunction Schema (definition) {\n definition || (definition = {})\n // TODO: schema validation\n utils.fillIn(this, definition)\n\n if (this.type === 'object') {\n this.properties = this.properties || {}\n utils.forOwn(this.properties, (_definition, prop) => {\n if (!(_definition instanceof Schema)) {\n this.properties[prop] = new Schema(_definition)\n }\n })\n } else if (this.type === 'array' && this.items && !(this.items instanceof Schema)) {\n this.items = new Schema(this.items)\n }\n if (this.extends && !(this.extends instanceof Schema)) {\n this.extends = new Schema(this.extends)\n }\n ['allOf', 'anyOf', 'oneOf'].forEach((validationKeyword) => {\n if (this[validationKeyword]) {\n this[validationKeyword].forEach((_definition, i) => {\n if (!(_definition instanceof Schema)) {\n this[validationKeyword][i] = new Schema(_definition)\n }\n })\n }\n })\n}\n\nexport default Component.extend({\n constructor: Schema,\n\n /**\n * This adds ES5 getters/setters to the target based on the \"properties\" in\n * this Schema, which makes possible change tracking and validation on\n * property assignment.\n *\n * @name Schema#validate\n * @method\n * @param {Object} target The prototype to which to apply this schema.\n */\n apply (target, opts) {\n opts || (opts = {})\n opts.getter || (opts.getter = '_get')\n opts.setter || (opts.setter = '_set')\n opts.unsetter || (opts.unsetter = '_unset')\n opts.track || (opts.track = this.track)\n const properties = this.properties || {}\n utils.forOwn(properties, function (schema, prop) {\n Object.defineProperty(\n target,\n prop,\n makeDescriptor(prop, schema, opts)\n )\n })\n },\n\n /**\n * Apply default values to the target object for missing values.\n *\n * @name Schema#applyDefaults\n * @method\n * @param {Object} target The target to which to apply values for missing values.\n */\n applyDefaults (target) {\n if (!target) {\n return\n }\n const properties = this.properties || {}\n const hasSet = utils.isFunction(target.set) || utils.isFunction(target._set)\n utils.forOwn(properties, function (schema, prop) {\n if (schema.hasOwnProperty('default') && utils.get(target, prop) === undefined) {\n if (hasSet) {\n target.set(prop, utils.plainCopy(schema['default']), { silent: true })\n } else {\n utils.set(target, prop, utils.plainCopy(schema['default']))\n }\n }\n if (schema.type === 'object' && schema.properties) {\n if (hasSet) {\n const orig = target._get('noValidate')\n target._set('noValidate', true)\n utils.set(target, prop, utils.get(target, prop) || {}, { silent: true })\n target._set('noValidate', orig)\n } else {\n utils.set(target, prop, utils.get(target, prop) || {})\n }\n schema.applyDefaults(utils.get(target, prop))\n }\n })\n },\n\n /**\n * Create a copy of the given value that contains only the properties defined\n * in this schema.\n *\n * @name Schema#pick\n * @method\n * @param {*} value The value to copy.\n * @returns {*} The copy.\n */\n pick (value) {\n if (this.type === 'object') {\n value || (value = {})\n let copy = {}\n if (this.properties) {\n utils.forOwn(this.properties, (_definition, prop) => {\n copy[prop] = _definition.pick(value[prop])\n })\n }\n if (this.extends) {\n utils.fillIn(copy, this.extends.pick(value))\n }\n return copy\n } else if (this.type === 'array') {\n value || (value = [])\n return value.map((item) => {\n const _copy = this.items ? this.items.pick(item) : {}\n if (this.extends) {\n utils.fillIn(_copy, this.extends.pick(item))\n }\n return _copy\n })\n }\n return utils.plainCopy(value)\n },\n\n /**\n * Validate the provided value against this schema.\n *\n * @name Schema#validate\n * @method\n * @param {*} value Value to validate.\n * @param {Object} [opts] Configuration options.\n * @returns {(array|undefined)} Array of errors or `undefined` if valid.\n */\n validate (value, opts) {\n return validate(value, this, opts)\n }\n}, {\n ANY_OPS,\n ARRAY_OPS,\n NUMERIC_OPS,\n OBJECT_OPS,\n STRING_OPS,\n typeGroupValidators,\n types,\n validate,\n validationKeywords\n})\n\n/**\n * Create a subclass of this Schema:\n * @example Schema.extend\n * // Normally you would do: import {Schema} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Schema} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSchemaClass extends Schema {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSchema = new CustomSchemaClass()\n * console.log(customSchema.foo())\n * console.log(CustomSchemaClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSchemaClass = Schema.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSchema = new OtherSchemaClass()\n * console.log(otherSchema.foo())\n * console.log(OtherSchemaClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSchemaClass () {\n * Schema.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Schema.extend({\n * constructor: AnotherSchemaClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSchema = new AnotherSchemaClass()\n * console.log(anotherSchema.created_at)\n * console.log(anotherSchema.foo())\n * console.log(AnotherSchemaClass.beep())\n *\n * @method Schema.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Schema class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\nimport Record from './Record'\nimport Schema from './Schema'\nimport { Relation } from './relations'\nimport {\n belongsTo,\n belongsToType,\n hasMany,\n hasManyType,\n hasOne,\n hasOneType\n} from './decorators'\n\nconst DOMAIN = 'Mapper'\nconst applyDefaultsHooks = [\n 'beforeCreate',\n 'beforeCreateMany'\n]\nconst validatingHooks = [\n 'beforeCreate',\n 'beforeCreateMany',\n 'beforeUpdate',\n 'beforeUpdateAll',\n 'beforeUpdateMany'\n]\nconst makeNotify = function (num) {\n return function (...args) {\n const opts = args[args.length - num]\n const op = opts.op\n this.dbg(op, ...args)\n\n if (applyDefaultsHooks.indexOf(op) !== -1 && opts.applyDefaults !== false) {\n const schema = this.getSchema()\n if (schema && schema.applyDefaults) {\n let toProcess = args[0]\n if (!utils.isArray(toProcess)) {\n toProcess = [toProcess]\n }\n toProcess.forEach((record) => {\n schema.applyDefaults(record)\n })\n }\n }\n\n // Automatic validation\n if (validatingHooks.indexOf(op) !== -1 && !opts.noValidate) {\n // Save current value of option\n const originalExistingOnly = opts.existingOnly\n\n // For updates, ignore required fields if they aren't present\n if (op.indexOf('beforeUpdate') === 0 && opts.existingOnly === undefined) {\n opts.existingOnly = true\n }\n const errors = this.validate(args[op === 'beforeUpdate' ? 1 : 0], utils.pick(opts, ['existingOnly']))\n\n // Restore option\n opts.existingOnly = originalExistingOnly\n\n // Abort lifecycle due to validation errors\n if (errors) {\n const err = new Error('validation failed')\n err.errors = errors\n return utils.reject(err)\n }\n }\n\n // Emit lifecycle event\n if (opts.notify || (opts.notify === undefined && this.notify)) {\n setTimeout(() => {\n this.emit(op, ...args)\n })\n }\n }\n}\n\n// These are the default implementations of all of the lifecycle hooks\nconst notify = makeNotify(1)\nconst notify2 = makeNotify(2)\n\n// This object provides meta information used by Mapper#crud to actually\n// execute each lifecycle method\nconst LIFECYCLE_METHODS = {\n count: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroy: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n destroyAll: {\n defaults: [{}, {}],\n skip: true,\n types: []\n },\n find: {\n defaults: [undefined, {}],\n types: []\n },\n findAll: {\n defaults: [{}, {}],\n types: []\n },\n sum: {\n defaults: [undefined, {}, {}],\n skip: true,\n types: []\n },\n update: {\n adapterArgs (mapper, id, props, opts) {\n return [id, mapper.toJSON(props, opts), opts]\n },\n beforeAssign: 1,\n defaults: [undefined, {}, {}],\n types: []\n },\n updateAll: {\n adapterArgs (mapper, props, query, opts) {\n return [mapper.toJSON(props, opts), query, opts]\n },\n beforeAssign: 0,\n defaults: [{}, {}, {}],\n types: []\n },\n updateMany: {\n adapterArgs (mapper, records, opts) {\n return [records.map((record) => mapper.toJSON(record, opts)), opts]\n },\n beforeAssign: 0,\n defaults: [[], {}],\n types: []\n }\n}\n\nconst MAPPER_DEFAULTS = {\n /**\n * Hash of registered adapters. Don't modify directly. Use\n * {@link Mapper#registerAdapter} instead.\n *\n * @default {}\n * @name Mapper#_adapters\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n _adapters: {},\n\n /**\n * Whether {@link Mapper#beforeCreate} and {@link Mapper#beforeCreateMany}\n * should automatically receive default values according to the Mapper's schema.\n *\n * @default true\n * @name Mapper#applyDefaults\n * @since 3.0.0\n * @type {boolean}\n */\n applyDefaults: true,\n\n /**\n * Whether to augment {@link Mapper#recordClass} with ES5 getters and setters\n * according to the properties defined in {@link Mapper#schema}. This makes\n * possible validation and change tracking on individual properties\n * when using the dot (e.g. `user.name = \"Bob\"`) operator to modify a\n * property, and is `true` by default.\n *\n * @default true\n * @name Mapper#applySchema\n * @since 3.0.0\n * @type {boolean}\n */\n applySchema: true,\n\n /**\n * The name of the registered adapter that this Mapper should used by default.\n *\n * @default \"http\"\n * @name Mapper#defaultAdapter\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n * @type {string}\n */\n defaultAdapter: 'http',\n\n /**\n * The field used as the unique identifier on records handled by this Mapper.\n *\n * @default id\n * @name Mapper#idAttribute\n * @since 3.0.0\n * @type {string}\n */\n idAttribute: 'id',\n\n /**\n * Whether records created from this mapper keep changeHistory on property changes.\n *\n * @default true\n * @name Mapper#keepChangeHistory\n * @since 3.0.0\n * @type {boolean}\n */\n keepChangeHistory: true,\n\n /**\n * Whether this Mapper should emit operational events.\n *\n * @default true\n * @name Mapper#notify\n * @since 3.0.0\n * @type {boolean}\n */\n notify: true,\n\n /**\n * Whether to skip validation when the Record instances are created.\n *\n * @default false\n * @name Mapper#noValidate\n * @since 3.0.0\n * @type {boolean}\n */\n noValidate: false,\n\n /**\n * Whether {@link Mapper#create}, {@link Mapper#createMany},\n * {@link Mapper#update}, {@link Mapper#updateAll}, {@link Mapper#updateMany},\n * {@link Mapper#find}, {@link Mapper#findAll}, {@link Mapper#destroy},\n * {@link Mapper#destroyAll}, {@link Mapper#count}, and {@link Mapper#sum}\n * should return a raw result object that contains both the instance data\n * returned by the adapter _and_ metadata about the operation.\n *\n * The default is to NOT return the result object, and instead return just the\n * instance data.\n *\n * @default false\n * @name Mapper#raw\n * @since 3.0.0\n * @type {boolean}\n */\n raw: false,\n\n /**\n * Whether records created from this mapper automatically validate their properties\n * when their properties are modified.\n *\n * @default true\n * @name Mapper#validateOnSet\n * @since 3.0.0\n * @type {boolean}\n */\n validateOnSet: true\n}\n\n/**\n * The core of JSData's [ORM/ODM][orm] implementation. Given a minimum amout of\n * meta information about a resource, a Mapper can perform generic CRUD\n * operations against that resource. Apart from its configuration, a Mapper is\n * stateless. The particulars of various persistence layers have been abstracted\n * into adapters, which a Mapper uses to perform its operations.\n *\n * The term \"Mapper\" comes from the [Data Mapper Pattern][pattern] described in\n * Martin Fowler's [Patterns of Enterprise Application Architecture][book]. A\n * Data Mapper moves data between [in-memory object instances][record] and a\n * relational or document-based database. JSData's Mapper can work with any\n * persistence layer you can write an adapter for.\n *\n * _(\"Model\" is a heavily overloaded term and is avoided in this documentation\n * to prevent confusion.)_\n *\n * [orm]: https://en.wikipedia.org/wiki/Object-relational_mapping\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\n *\n * @example\n * // Import and instantiate\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @example\n * // Define a Mapper using the Container component\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @class Mapper\n * @extends Component\n * @param {Object} opts Configuration options.\n * @param {boolean} [opts.applySchema=true] See {@link Mapper#applySchema}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {string} [opts.defaultAdapter=http] See {@link Mapper#defaultAdapter}.\n * @param {string} [opts.idAttribute=id] See {@link Mapper#idAttribute}.\n * @param {Object} [opts.methods] See {@link Mapper#methods}.\n * @param {string} opts.name See {@link Mapper#name}.\n * @param {boolean} [opts.notify] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw=false] See {@link Mapper#raw}.\n * @param {Function|boolean} [opts.recordClass] See {@link Mapper#recordClass}.\n * @param {Object|Schema} [opts.schema] See {@link Mapper#schema}.\n * @returns {Mapper} A new {@link Mapper} instance.\n * @see http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n */\nfunction Mapper (opts) {\n utils.classCallCheck(this, Mapper)\n Component.call(this)\n opts || (opts = {})\n\n // Prepare certain properties to be non-enumerable\n Object.defineProperties(this, {\n _adapters: {\n value: undefined,\n writable: true\n },\n\n /**\n * The {@link Container} that holds this Mapper. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n datastore: {\n value: undefined,\n writable: true\n },\n\n /**\n * The meta information describing this Mapper's available lifecycle\n * methods. __Do not modify.__\n *\n * @name Mapper#lifecycleMethods\n * @since 3.0.0\n * @type {Object}\n */\n lifecycleMethods: {\n value: LIFECYCLE_METHODS\n },\n\n /**\n * Set to `false` to force the Mapper to work with POJO objects only.\n *\n * @example\n * // Use POJOs only.\n * import {Mapper, Record} from 'js-data'\n * const UserMapper = new Mapper({ recordClass: false })\n * UserMapper.recordClass // false\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n *\n * @example\n * // Set to a custom class to have records wrapped in your custom class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User {\n * constructor (props = {}) {\n * for (var key in props) {\n * if (props.hasOwnProperty(key)) {\n * this[key] = props[key]\n * }\n * }\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // false\n * user instanceof User // true\n *\n *\n * @example\n * // Extend the {@link Record} class.\n * import {Mapper, Record} from 'js-data'\n * // Custom class\n * class User extends Record {\n * constructor () {\n * super(props)\n * }\n * }\n * const UserMapper = new Mapper({ recordClass: User })\n * UserMapper.recordClass // function User() {}\n * const user = UserMapper#createRecord()\n * user instanceof Record // true\n * user instanceof User // true\n *\n * @name Mapper#recordClass\n * @default {@link Record}\n * @see Record\n * @since 3.0.0\n */\n recordClass: {\n value: undefined,\n writable: true\n },\n\n /**\n * This Mapper's {@link Schema}.\n *\n * @example Mapper#schema\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const UserMapper = new Mapper({\n * name: 'user',\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * first: { type: 'string', track: true },\n * last: { type: 'string', track: true },\n * role: { type: 'string', track: true, required: true },\n * age: { type: 'integer', track: true },\n * is_active: { type: 'number' }\n * }\n * }\n * })\n * const user = UserMapper.createRecord({\n * id: 1,\n * name: 'John',\n * role: 'admin'\n * })\n * user.on('change', function (user, changes) {\n * console.log(changes)\n * })\n * user.on('change:role', function (user, value) {\n * console.log('change:role - ' + value)\n * })\n * user.role = 'owner'\n *\n * @name Mapper#schema\n * @see Schema\n * @since 3.0.0\n * @type {Schema}\n */\n schema: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply user-provided configuration\n utils.fillIn(this, opts)\n // Fill in any missing options with the defaults\n utils.fillIn(this, utils.copy(MAPPER_DEFAULTS))\n\n /**\n * The name for this Mapper. This is the minimum amount of meta information\n * required for a Mapper to be able to execute CRUD operations for a\n * Resource.\n *\n * @name Mapper#name\n * @since 3.0.0\n * @type {string}\n */\n if (!this.name) {\n throw utils.err(`new ${DOMAIN}`, 'opts.name')(400, 'string', this.name)\n }\n\n // Setup schema, with an empty default schema if necessary\n if (this.schema) {\n this.schema.type || (this.schema.type = 'object')\n }\n if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\n\n // Create a subclass of Record that's tied to this Mapper\n if (this.recordClass === undefined) {\n const superClass = Record\n this.recordClass = superClass.extend({\n constructor: (function Record () {\n var subClass = function Record (props, opts) {\n utils.classCallCheck(this, subClass)\n superClass.call(this, props, opts)\n }\n return subClass\n })()\n })\n }\n\n if (this.recordClass) {\n this.recordClass.mapper = this\n\n /**\n * Functions that should be added to the prototype of {@link Mapper#recordClass}.\n *\n * @name Mapper#methods\n * @since 3.0.0\n * @type {Object}\n */\n if (utils.isObject(this.methods)) {\n utils.addHiddenPropsToTarget(this.recordClass.prototype, this.methods)\n }\n\n // We can only apply the schema to the prototype of this.recordClass if the\n // class extends Record\n if (Record.prototype.isPrototypeOf(Object.create(this.recordClass.prototype)) && this.schema && this.schema.apply && this.applySchema) {\n this.schema.apply(this.recordClass.prototype)\n }\n }\n}\n\nexport default Component.extend({\n constructor: Mapper,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCount: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterCreateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroy: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterDestroyAll\n * @param {*} data The `data` returned by the adapter.\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterDestroyAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFind: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterFindAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterSum\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterSum: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdate: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateAll: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#afterUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @param {*} result The result, if any.\n * @since 3.0.0\n */\n afterUpdateMany: notify2,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#create}. If this method\n * returns a promise then {@link Mapper#create} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreate\n * @param {Object} props The `props` argument passed to {@link Mapper#create}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#create}.\n * @since 3.0.0\n */\n beforeCreate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#createMany}. If this method\n * returns a promise then {@link Mapper#createMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCreateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#createMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#createMany}.\n * @since 3.0.0\n */\n beforeCreateMany: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#count}. If this method\n * returns a promise then {@link Mapper#count} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeCount\n * @param {Object} query The `query` argument passed to {@link Mapper#count}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#count}.\n * @since 3.0.0\n */\n beforeCount: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroy}. If this method\n * returns a promise then {@link Mapper#destroy} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroy\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#destroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroy}.\n * @since 3.0.0\n */\n beforeDestroy: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#destroyAll}. If this method\n * returns a promise then {@link Mapper#destroyAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeDestroyAll\n * @param {query} query The `query` argument passed to {@link Mapper#destroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#destroyAll}.\n * @since 3.0.0\n */\n beforeDestroyAll: notify,\n\n /**\n * Mappers lifecycle hook called by {@link Mapper#find}. If this method\n * returns a promise then {@link Mapper#find} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFind\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#find}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#find}.\n * @since 3.0.0\n */\n beforeFind: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#findAll}. If this method\n * returns a promise then {@link Mapper#findAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeFindAll\n * @param {Object} query The `query` argument passed to {@link Mapper#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#findAll}.\n * @since 3.0.0\n */\n beforeFindAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#sum}. If this method\n * returns a promise then {@link Mapper#sum} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeSum\n * @param {string} field The `field` argument passed to {@link Mapper#sum}.\n * @param {Object} query The `query` argument passed to {@link Mapper#sum}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#sum}.\n * @since 3.0.0\n */\n beforeSum: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#update}. If this method\n * returns a promise then {@link Mapper#update} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdate\n * @param {(string|number)} id The `id` argument passed to {@link Mapper#update}.\n * @param {props} props The `props` argument passed to {@link Mapper#update}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#update}.\n * @since 3.0.0\n */\n beforeUpdate: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateAll}. If this method\n * returns a promise then {@link Mapper#updateAll} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateAll\n * @param {Object} props The `props` argument passed to {@link Mapper#updateAll}.\n * @param {Object} query The `query` argument passed to {@link Mapper#updateAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateAll}.\n * @since 3.0.0\n */\n beforeUpdateAll: notify,\n\n /**\n * Mapper lifecycle hook called by {@link Mapper#updateMany}. If this method\n * returns a promise then {@link Mapper#updateMany} will wait for the promise\n * to resolve before continuing.\n *\n * @method Mapper#beforeUpdateMany\n * @param {Array} records The `records` argument passed to {@link Mapper#updateMany}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#updateMany}.\n * @since 3.0.0\n */\n beforeUpdateMany: notify,\n\n /**\n * This method is called at the end of most lifecycle methods. It does the\n * following:\n *\n * 1. If `opts.raw` is `true`, add this Mapper's configuration to the `opts`\n * argument as metadata for the operation.\n * 2. Wrap the result data appropriately using {@link Mapper#wrap}, which\n * calls {@link Mapper#createRecord}.\n *\n * @method Mapper#_end\n * @private\n * @since 3.0.0\n */\n _end (result, opts, skip) {\n if (opts.raw) {\n utils._(result, opts)\n }\n if (skip) {\n return result\n }\n let _data = opts.raw ? result.data : result\n if (_data && utils.isFunction(this.wrap)) {\n _data = this.wrap(_data, opts)\n if (opts.raw) {\n result.data = _data\n } else {\n result = _data\n }\n }\n return result\n },\n\n /**\n * Define a belongsTo relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * PostMapper.belongsTo(UserMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to post records at \"post.user\"\n * localField: 'user'\n * })\n *\n * CommentMapper.belongsTo(UserMapper, {\n * // comment.user_id points to user.id\n * foreignKey: 'user_id'\n * // user records will be attached to comment records at \"comment.user\"\n * localField: 'user'\n * })\n * CommentMapper.belongsTo(PostMapper, {\n * // comment.post_id points to post.id\n * foreignKey: 'post_id'\n * // post records will be attached to comment records at \"comment.post\"\n * localField: 'post'\n * })\n *\n * @method Mapper#belongsTo\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n belongsTo (relatedMapper, opts) {\n return belongsTo(relatedMapper, opts)(this)\n },\n\n /**\n * Select records according to the `query` argument and return the count.\n *\n * {@link Mapper#beforeCount} will be called before calling the adapter.\n * {@link Mapper#afterCount} will be called after calling the adapter.\n *\n * @example\n * // Get the number of published blog posts\n * PostMapper.count({ status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Mapper#count\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `count` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the count of the selected records.\n * @since 3.0.0\n */\n count (query, opts) {\n return this.crud('count', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~beforeCreateListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreate\n * @see Mapper~beforeCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Mapper~beforeCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeCreate}.\n * @see Mapper#event:beforeCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#create}. See\n * {@link Mapper~afterCreateListener} for how to listen for this event.\n *\n * @event Mapper#afterCreate\n * @see Mapper~afterCreateListener\n * @see Mapper#create\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Mapper~afterCreateListener\n * @param {Object} props The `props` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterCreate}.\n * @see Mapper#event:afterCreate\n * @see Mapper#create\n * @since 3.0.0\n */\n /**\n * Create and save a new the record using the provided `props`.\n *\n * {@link Mapper#beforeCreate} will be called before calling the adapter.\n * {@link Mapper#afterCreate} will be called after calling the adapter.\n *\n * @example\n * // Create and save a new blog post\n * PostMapper.create({\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#create\n * @param {Object} props The properties for the new record.\n * @param {Object} [opts] Configuration options. Refer to the `create` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `props` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#create}\n * or {@link Mapper#createMany} call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created record.\n * @since 3.0.0\n */\n create (props, opts) {\n let op, adapter\n // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n const originalRecord = props\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreate lifecycle hook\n op = opts.op = 'beforeCreate'\n return utils.resolve(this[op](props, opts)).then((_props) => {\n // Allow for re-assignment from lifecycle hook\n props = _props === undefined ? props : _props\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n const relatedMapper = def.getRelation()\n const relatedIdAttribute = relatedMapper.idAttribute\n optsCopy.raw = false\n if (!relationData) {\n return\n }\n if (def.type === belongsToType) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(relatedMapper.create(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n def.setForeignKey(props, data)\n }))\n } else if (def.type === hasManyType && def.localKeys) {\n // Create his hasMany relation first because it uses localKeys\n tasks.push(relatedMapper.createMany(relationData, optsCopy).then((data) => {\n def.setLocalField(belongsToRelationData, data)\n utils.set(props, def.localKeys, data.map((record) => utils.get(record, relatedIdAttribute)))\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter for the main create\n op = opts.op = 'create'\n this.dbg(op, props, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, this.toJSON(props, { with: opts.pass || [] }), opts))\n }).then((result) => {\n const createdRecordData = opts.raw ? result.data : result\n\n // Deep post-create hasMany and hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(props)\n if (!relationData) {\n return\n }\n optsCopy.raw = false\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType && def.foreignKey) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === hasOneType) {\n def.setForeignKey(createdRecordData, relationData)\n task = def.getRelation().create(relationData, optsCopy).then((result) => {\n def.setLocalField(createdRecordData, result)\n })\n } else if (def.type === belongsToType && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n } else if (def.type === hasManyType && def.localKeys && def.getLocalField(belongsToRelationData)) {\n def.setLocalField(createdRecordData, def.getLocalField(belongsToRelationData))\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n if (opts.raw) {\n result.data = originalRecord\n } else {\n result = originalRecord\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreate lifecycle hook\n op = opts.op = 'afterCreate'\n return utils.resolve(this[op](props, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Use {@link Mapper#createRecord} instead.\n * @deprecated\n * @method Mapper#createInstance\n * @param {Object|Array} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Object|Array} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n createInstance (props, opts) {\n return this.createRecord(props, opts)\n },\n\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeCreateMany\n * @see Mapper~beforeCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Mapper~beforeCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Mapper#event:beforeCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#createMany}. See\n * {@link Mapper~afterCreateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterCreateMany\n * @see Mapper~afterCreateManyListener\n * @see Mapper#createMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Mapper~afterCreateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Mapper#event:afterCreateMany\n * @see Mapper#createMany\n * @since 3.0.0\n */\n /**\n * Given an array of records, batch create them via an adapter.\n *\n * {@link Mapper#beforeCreateMany} will be called before calling the adapter.\n * {@link Mapper#afterCreateMany} will be called after calling the adapter.\n *\n * @example\n * // Create and save several new blog posts\n * PostMapper.createMany([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Mapper#beforeCreate\n * @fires Mapper#afterCreate\n * @method Mapper#createMany\n * @param {Record[]} records Array of records to be created in one batch.\n * @param {Object} [opts] Configuration options. Refer to the `createMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to create in a cascading\n * create if `records` contains nested relations. NOT performed in a\n * transaction. Each nested create will result in another {@link Mapper#createMany}\n * call.\n * @param {string[]} [opts.pass=[]] Relations to send to the adapter as part\n * of the payload. Normally relations are not sent.\n * @returns {Promise} Resolves with the created records.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n createMany (records, opts) {\n let op, adapter\n // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n const originalRecords = records\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n op = opts.op = 'beforeCreateMany'\n return utils.resolve(this[op](records, opts)).then((_records) => {\n // Allow for re-assignment from lifecycle hook\n records = _records === undefined ? records : _records\n\n // Deep pre-create belongsTo relations\n const belongsToRelationData = {}\n opts.with || (opts.with = [])\n let tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (def.type === belongsToType && relationData.length === records.length) {\n // Create belongsTo relation first because we need a generated id to\n // attach to the child\n tasks.push(def.getRelation().createMany(relationData, optsCopy).then((data) => {\n const relatedRecords = optsCopy.raw ? data.data : data\n def.setLocalField(belongsToRelationData, relatedRecords)\n records.forEach((record, i) => {\n def.setForeignKey(record, relatedRecords[i])\n })\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n // Now delegate to the adapter\n op = opts.op = 'createMany'\n const json = records.map((record) => this.toJSON(record, { with: opts.pass || [] }))\n this.dbg(op, records, opts)\n return utils.resolve(this.getAdapter(adapter)[op](this, json, opts))\n }).then((result) => {\n const createdRecordsData = opts.raw ? result.data : result\n\n // Deep post-create hasOne relations\n tasks = []\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = records\n .map((record) => def.getLocalField(record))\n .filter((relatedRecord) => relatedRecord)\n if (relationData.length !== records.length) {\n return\n }\n const belongsToData = def.getLocalField(belongsToRelationData)\n let task\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.type === hasManyType) {\n // Not supported\n this.log('warn', 'deep createMany of hasMany type not supported!')\n } else if (def.type === hasOneType) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setForeignKey(createdRecordData, relationData[i])\n })\n task = def.getRelation().createMany(relationData, optsCopy).then((result) => {\n const relatedData = opts.raw ? result.data : result\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, relatedData[i])\n })\n })\n } else if (def.type === belongsToType && belongsToData && belongsToData.length === createdRecordsData.length) {\n createdRecordsData.forEach((createdRecordData, i) => {\n def.setLocalField(createdRecordData, belongsToData[i])\n })\n }\n if (task) {\n tasks.push(task)\n }\n })\n return utils.Promise.all(tasks).then(() => {\n createdRecordsData.forEach((createdRecordData, i) => {\n const originalRecord = originalRecords[i]\n utils.set(originalRecord, createdRecordData, { silent: true })\n if (utils.isFunction(originalRecord.commit)) {\n originalRecord.commit()\n }\n })\n if (opts.raw) {\n result.data = originalRecords\n } else {\n result = originalRecords\n }\n return result\n })\n })\n }).then((result) => {\n result = this._end(result, opts)\n // afterCreateMany lifecycle hook\n op = opts.op = 'afterCreateMany'\n return utils.resolve(this[op](records, opts, result)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Create an unsaved, uncached instance of this Mapper's\n * {@link Mapper#recordClass}.\n *\n * Returns `props` if `props` is already an instance of\n * {@link Mapper#recordClass}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * const post = PostMapper.createRecord()\n *\n * @example\n * // Create an unsaved record instance with inital properties\n * const post = PostMapper.createRecord({\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create a record instance that corresponds to a saved record\n * const post = PostMapper.createRecord({\n * // JSData thinks this record has been saved if it has a primary key\n * id: 1234,\n * title: 'Modeling your data',\n * status: 'draft'\n * })\n *\n * @example\n * // Create record instances from an array\n * const posts = PostMapper.createRecord([{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }])\n *\n * @example\n * // Records are validated by default\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * try {\n * const post = PostMapper.createRecord({\n * title: 1234,\n * })\n * } catch (err) {\n * console.log(err.errors) // [{ expected: 'one of (string)', actual: 'number', path: 'title' }]\n * }\n *\n * @example\n * // Skip validation\n * import {Mapper} from 'js-data'\n * const PostMapper = new Mapper({\n * name: 'post',\n * schema: { properties: { title: { type: 'string' } } }\n * })\n * const post = PostMapper.createRecord({\n * title: 1234,\n * }, { noValidate: true })\n * console.log(post.isValid()) // false\n *\n * @method Mapper#createRecord\n * @param {Object|Object[]} props The properties for the Record instance or an\n * array of property objects for the Record instances.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @returns {Record|Record[]} The Record instance or Record instances.\n * @since 3.0.0\n */\n createRecord (props, opts) {\n props || (props = {})\n if (utils.isArray(props)) {\n return props.map((_props) => this.createRecord(_props, opts))\n }\n if (!utils.isObject(props)) {\n throw utils.err(`${DOMAIN}#createRecord`, 'props')(400, 'array or object', props)\n }\n const RecordCtor = this.recordClass\n const relationList = this.relationList || []\n relationList.forEach((def) => {\n const relatedMapper = def.getRelation()\n const relationData = def.getLocalField(props)\n if (relationData && !relatedMapper.is(relationData)) {\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n utils.set(props, def.localField, relatedMapper.createRecord(relationData, opts))\n }\n })\n // Check to make sure \"props\" is not already an instance of this Mapper.\n if (RecordCtor && (!(props instanceof RecordCtor))) {\n return new RecordCtor(props, opts)\n }\n return props\n },\n\n /**\n * Lifecycle invocation method. You probably won't call this method directly.\n *\n * @method Mapper#crud\n * @param {string} method Name of the lifecycle method to invoke.\n * @param {...*} args Arguments to pass to the lifecycle method.\n * @returns {Promise}\n * @since 3.0.0\n */\n crud (method, ...args) {\n const config = this.lifecycleMethods[method]\n if (!config) {\n throw utils.err(`${DOMAIN}#crud`, method)(404, 'method')\n }\n\n const upper = `${method.charAt(0).toUpperCase()}${method.substr(1)}`\n const before = `before${upper}`\n const after = `after${upper}`\n\n let op, adapter\n\n // Default values for arguments\n config.defaults.forEach((value, i) => {\n if (args[i] === undefined) {\n args[i] = utils.copy(value)\n }\n })\n\n const opts = args[args.length - 1]\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n adapter = opts.adapter = this.getAdapterName(opts)\n\n // before lifecycle hook\n op = opts.op = before\n return utils.resolve(this[op](...args)).then((_value) => {\n if (args[config.beforeAssign] !== undefined) {\n // Allow for re-assignment from lifecycle hook\n args[config.beforeAssign] = _value === undefined ? args[config.beforeAssign] : _value\n }\n // Now delegate to the adapter\n op = opts.op = method\n args = config.adapterArgs ? config.adapterArgs(this, ...args) : args\n this.dbg(op, ...args)\n return utils.resolve(this.getAdapter(adapter)[op](this, ...args))\n }).then((result) => {\n result = this._end(result, opts, !!config.skip)\n args.push(result)\n // after lifecycle hook\n op = opts.op = after\n return utils.resolve(this[op](...args)).then((_result) => {\n // Allow for re-assignment from lifecycle hook\n return _result === undefined ? result : _result\n })\n })\n },\n\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~beforeDestroyListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroy\n * @see Mapper~beforeDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Mapper~beforeDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroy}.\n * @see Mapper#event:beforeDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroy}. See\n * {@link Mapper~afterDestroyListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroy\n * @see Mapper~afterDestroyListener\n * @see Mapper#destroy\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Mapper~afterDestroyListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroy}.\n * @see Mapper#event:afterDestroy\n * @see Mapper#destroy\n * @since 3.0.0\n */\n /**\n * Using an adapter, destroy the record with the given primary key.\n *\n * {@link Mapper#beforeDestroy} will be called before destroying the record.\n * {@link Mapper#afterDestroy} will be called after destroying the record.\n *\n * @example\n * // Destroy a specific blog post\n * PostMapper.destroy(1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @example\n * // Get full response\n * PostMapper.destroy(1234, { raw: true }).then((result) => {\n * console.log(result.deleted) e.g. 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroy\n * @fires Mapper#afterDestroy\n * @method Mapper#destroy\n * @param {(string|number)} id The primary key of the record to destroy.\n * @param {Object} [opts] Configuration options. Refer to the `destroy` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the record has been destroyed. Resolves\n * even if no record was found to be destroyed.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroy (id, opts) {\n return this.crud('destroy', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeDestroyAll\n * @see Mapper~beforeDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Mapper~beforeDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeDestroyAll}.\n * @see Mapper#event:beforeDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#destroyAll}. See\n * {@link Mapper~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Mapper#afterDestroyAll\n * @see Mapper~afterDestroyAllListener\n * @see Mapper#destroyAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Mapper~afterDestroyAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterDestroyAll}.\n * @see Mapper#event:afterDestroyAll\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n /**\n * Destroy the records selected by `query` via an adapter. If no `query` is\n * provided then all records will be destroyed.\n *\n * {@link Mapper#beforeDestroyAll} will be called before destroying the records.\n * {@link Mapper#afterDestroyAll} will be called after destroying the records.\n *\n * @example\n * // Destroy all blog posts\n * PostMapper.destroyAll().then(() => {\n * // All blog posts have been destroyed\n * })\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * PostMapper.destroyAll({ status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @example\n * // Get full response\n * const query = null\n * const options = { raw: true }\n * PostMapper.destroyAll(query, options).then((result) => {\n * console.log(result.deleted) e.g. 14\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeDestroyAll\n * @fires Mapper#afterDestroyAll\n * @method Mapper#destroyAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `destroyAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves when the records have been destroyed. Resolves\n * even if no records were found to be destroyed.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n destroyAll (query, opts) {\n return this.crud('destroyAll', query, opts)\n },\n\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~beforeFindListener} for how to listen for this event.\n *\n * @event Mapper#beforeFind\n * @see Mapper~beforeFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Mapper~beforeFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFind}.\n * @see Mapper#event:beforeFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#find}. See\n * {@link Mapper~afterFindListener} for how to listen for this event.\n *\n * @event Mapper#afterFind\n * @see Mapper~afterFindListener\n * @see Mapper#find\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFind} event.\n *\n * @example\n * function onAfterFind (id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Mapper~afterFindListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFind}.\n * @see Mapper#event:afterFind\n * @see Mapper#find\n * @since 3.0.0\n */\n /**\n * Retrieve via an adapter the record with the given primary key.\n *\n * {@link Mapper#beforeFind} will be called before calling the adapter.\n * {@link Mapper#afterFind} will be called after calling the adapter.\n *\n * @example\n * PostMapper.find(1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @example\n * // Get full response\n * PostMapper.find(1, { raw: true }).then((result) => {\n * console.log(result.data) // { id: 1, ...}\n * console.log(result.found) // 1\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFind\n * @fires Mapper#afterFind\n * @method Mapper#find\n * @param {(string|number)} id The primary key of the record to retrieve.\n * @param {Object} [opts] Configuration options. Refer to the `find` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found record. Resolves with\n * `undefined` if no record was found.\n * @see http://www.js-data.io/v3.0/docs/reading-data\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n find (id, opts) {\n return this.crud('find', id, opts)\n },\n\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~beforeFindAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeFindAll\n * @see Mapper~beforeFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Mapper~beforeFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeFindAll}.\n * @see Mapper#event:beforeFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#findAll}. See\n * {@link Mapper~afterFindAllListener} for how to listen for this event.\n *\n * @event Mapper#afterFindAll\n * @see Mapper~afterFindAllListener\n * @see Mapper#findAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Mapper~afterFindAllListener\n * @param {Object} query The `query` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterFindAll}.\n * @see Mapper#event:afterFindAll\n * @see Mapper#findAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, select records to retrieve via an adapter.\n *\n * {@link Mapper#beforeFindAll} will be called before calling the adapter.\n * {@link Mapper#afterFindAll} will be called after calling the adapter.\n *\n * @example\n * // Find all \"published\" blog posts\n * PostMapper.findAll({ status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, status: 'published', ...}, ...]\n * })\n *\n * @example\n * // Get full response\n * PostMapper.findAll({ status: 'published' }, { raw: true }).then((result) => {\n * console.log(result.data) // [{ id: 1, status: 'published', ...}, ...]\n * console.log(result.found) // e.g. 13\n * console.log(...) // etc., more metadata can be found on the result\n * })\n *\n * @fires Mapper#beforeFindAll\n * @fires Mapper#afterFindAll\n * @method Mapper#findAll\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `findAll` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @param {string[]} [opts.with=[]] Relations to eager load in the request.\n * @returns {Promise} Resolves with the found records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/reading-data\",\"Reading data\"]\n */\n findAll (query, opts) {\n return this.crud('findAll', query, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Mapper#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapter (name) {\n this.dbg('getAdapter', 'name:', name)\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Mapper#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || opts.defaultAdapter\n },\n\n /**\n * Get the object of registered adapters for this Mapper.\n *\n * @method Mapper#getAdapters\n * @returns {Object} {@link Mapper#_adapters}\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Returns this Mapper's {@link Schema}.\n *\n * @method Mapper#getSchema\n * @returns {Schema} This Mapper's {@link Schema}.\n * @see Mapper#schema\n * @since 3.0.0\n */\n getSchema () {\n return this.schema\n },\n\n /**\n * Defines a hasMany relationship. Only useful if you're managing your\n * Mappers manually and not using a Container or DataStore component.\n *\n * @example\n * UserMapper.hasMany(PostMapper, {\n * // post.user_id points to user.id\n * foreignKey: 'user_id'\n * // post records will be attached to user records at \"user.posts\"\n * localField: 'posts'\n * })\n *\n * @method Mapper#hasMany\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasMany (relatedMapper, opts) {\n return hasMany(relatedMapper, opts)(this)\n },\n\n /**\n * Defines a hasOne relationship. Only useful if you're managing your Mappers\n * manually and not using a {@link Container} or {@link DataStore} component.\n *\n * @example\n * UserMapper.hasOne(ProfileMapper, {\n * // profile.user_id points to user.id\n * foreignKey: 'user_id'\n * // profile records will be attached to user records at \"user.profile\"\n * localField: 'profile'\n * })\n *\n * @method Mapper#hasOne\n * @see http://www.js-data.io/v3.0/docs/relations\n * @since 3.0.0\n */\n hasOne (relatedMapper, opts) {\n return hasOne(relatedMapper, opts)(this)\n },\n\n /**\n * Return whether `record` is an instance of this Mapper's recordClass.\n *\n * @example\n * const post = PostMapper.createRecord()\n *\n * console.log(PostMapper.is(post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof PostMapper.recordClass) // true\n *\n * @method Mapper#is\n * @param {Object|Record} record The record to check.\n * @returns {boolean} Whether `record` is an instance of this Mapper's\n * {@link Mapper#recordClass}.\n * @since 3.0.0\n */\n is (record) {\n const recordClass = this.recordClass\n return recordClass ? record instanceof recordClass : false\n },\n\n /**\n * Register an adapter on this Mapper under the given name.\n *\n * @method Mapper#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for this Mapper.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.defaultAdapter = name\n }\n },\n\n /**\n * Select records according to the `query` argument, and aggregate the sum\n * value of the property specified by `field`.\n *\n * {@link Mapper#beforeSum} will be called before calling the adapter.\n * {@link Mapper#afterSum} will be called after calling the adapter.\n *\n * @example\n * PurchaseOrderMapper.sum('amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Mapper#sum\n * @param {string} field The field to sum.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `sum` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the aggregated sum.\n * @since 3.0.0\n */\n sum (field, query, opts) {\n return this.crud('sum', field, query, opts)\n },\n\n /**\n * Return a plain object representation of the given record. Relations can\n * be optionally be included. Non-schema properties can be excluded.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = PersonMapper.createRecord({ id: 1, name: 'John', foo: 'bar' })\n * console.log(PersonMapper.toJSON(person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(PersonMapper.toJSON(person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Mapper#toJSON\n * @param {Record|Record[]} records Record or records from which to create a\n * POJO representation.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.strict] Whether to exclude properties that are not\n * defined in {@link Mapper#schema}.\n * @param {string[]} [opts.with] Array of relation names or relation fields\n * to include in the POJO representation.\n * @param {boolean} [opts.withAll] Whether to simply include all relations in\n * the representation. Overrides `opts.with`.\n * @returns {Object|Object[]} POJO representation of the record or records.\n * @since 3.0.0\n */\n toJSON (records, opts) {\n let record\n opts || (opts = {})\n if (utils.isArray(records)) {\n return records.map((record) => this.toJSON(record, opts))\n } else {\n record = records\n }\n const relationFields = (this ? this.relationFields : []) || []\n let json = {}\n let properties\n\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n properties = this.schema.properties\n }\n properties || (properties = {})\n\n // Optionally copy properties not defined in the schema\n if (!opts.strict) {\n for (var key in record) {\n if (!properties[key] && relationFields.indexOf(key) === -1) {\n json[key] = utils.plainCopy(record[key])\n }\n }\n }\n\n // The user wants to include relations in the resulting plain object representation\n if (this && opts.withAll) {\n opts.with = relationFields.slice()\n }\n if (this && opts.with) {\n if (utils.isString(opts.with)) {\n opts.with = [opts.with]\n }\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n const relationData = def.getLocalField(record)\n if (relationData) {\n // The actual recursion\n if (utils.isArray(relationData)) {\n def.setLocalField(json, relationData.map((item) => {\n return def.getRelation().toJSON(item, optsCopy)\n }))\n } else {\n def.setLocalField(json, def.getRelation().toJSON(relationData, optsCopy))\n }\n }\n })\n }\n return json\n },\n\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~beforeUpdateListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdate\n * @see Mapper~beforeUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Mapper~beforeUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#beforeUpdate}.\n * @see Mapper#event:beforeUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#update}. See\n * {@link Mapper~afterUpdateListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdate\n * @see Mapper~afterUpdateListener\n * @see Mapper#update\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Mapper~afterUpdateListener\n * @param {string|number} id The `id` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument passed to {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument passed to {@link Mapper#afterUpdate}.\n * @see Mapper#event:afterUpdate\n * @see Mapper#update\n * @since 3.0.0\n */\n /**\n * Using an adapter, update the record with the primary key specified by the\n * `id` argument.\n *\n * {@link Mapper#beforeUpdate} will be called before updating the record.\n * {@link Mapper#afterUpdate} will be called after updating the record.\n *\n * @example\n * // Update a specific post\n * PostMapper.update(1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Mapper#beforeUpdate\n * @fires Mapper#afterUpdate\n * @method Mapper#update\n * @param {(string|number)} id The primary key of the record to update.\n * @param {Object} props The update to apply to the record.\n * @param {Object} [opts] Configuration options. Refer to the `update` method\n * of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * transaction.\n * @returns {Promise} Resolves with the updated record. Rejects if the record\n * could not be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n update (id, props, opts) {\n return this.crud('update', id, props, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateAll\n * @see Mapper~beforeUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Mapper~beforeUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Mapper#event:beforeUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateAll}. See\n * {@link Mapper~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateAll\n * @see Mapper~afterUpdateAllListener\n * @see Mapper#updateAll\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Mapper~afterUpdateAllListener\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Mapper#event:afterUpdateAll\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n /**\n * Using the `query` argument, perform the a single updated to the selected\n * records.\n *\n * {@link Mapper#beforeUpdateAll} will be called before making the update.\n * {@link Mapper#afterUpdateAll} will be called after making the update.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * PostMapper.updateAll(update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateAll\n * @fires Mapper#afterUpdateAll\n * @method Mapper#updateAll\n * @param {Object} props Update to apply to selected records.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options. Refer to the `updateAll`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the update records, if any.\n * @see query\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateAll (props, query, opts) {\n return this.crud('updateAll', props, query, opts)\n },\n\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#beforeUpdateMany\n * @see Mapper~beforeUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Mapper~beforeUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Mapper#event:beforeUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Mapper#updateMany}. See\n * {@link Mapper~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Mapper#afterUpdateMany\n * @see Mapper~afterUpdateManyListener\n * @see Mapper#updateMany\n */\n /**\n * Callback signature for the {@link Mapper#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Mapper~afterUpdateManyListener\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Mapper#event:afterUpdateMany\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n /**\n * Given an array of updates, perform each of the updates via an adapter. Each\n * \"update\" is a hash of properties with which to update an record. Each\n * update must contain the primary key of the record to be updated.\n *\n * {@link Mapper#beforeUpdateMany} will be called before making the update.\n * {@link Mapper#afterUpdateMany} will be called after making the update.\n *\n * @example\n * PostMapper.updateMany([\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Mapper#beforeUpdateMany\n * @fires Mapper#afterUpdateMany\n * @method Mapper#updateMany\n * @param {Record[]} records Array up record updates.\n * @param {Object} [opts] Configuration options. Refer to the `updateMany`\n * method of whatever adapter you're using for more configuration options.\n * @param {boolean} [opts.adapter={@link Mapper#defaultAdapter}] Name of the\n * adapter to use.\n * @param {boolean} [opts.notify={@link Mapper#notify}] See {@link Mapper#notify}.\n * @param {boolean} [opts.noValidate={@link Mapper#noValidate}] See {@link Mapper#noValidate}.\n * @param {boolean} [opts.raw={@link Mapper#raw}] See {@link Mapper#raw}.\n * @returns {Promise} Resolves with the updated records. Rejects if any of the\n * records could be found.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n updateMany (records, opts) {\n return this.crud('updateMany', records, opts)\n },\n\n /**\n * Validate the given record or records according to this Mapper's\n * {@link Schema}. If there are no validation errors then the return value\n * will be `undefined`.\n *\n * @example\n * import {Mapper, Schema} from 'js-data'\n * const PersonSchema = new Schema({\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * })\n * const PersonMapper = new Mapper({\n * name: 'person',\n * schema: PersonSchema\n * })\n * let errors = PersonMapper.validate({ name: 'John' })\n * console.log(errors) // undefined\n * errors = PersonMapper.validate({ name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Mapper#validate\n * @param {Object|Object[]} record The record or records to validate.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Schema#validate}.\n * @returns {Object[]} Array of errors or `undefined` if no errors.\n * @since 3.0.0\n */\n validate (record, opts) {\n opts || (opts = {})\n const schema = this.getSchema()\n const _opts = utils.pick(opts, ['existingOnly'])\n if (utils.isArray(record)) {\n const errors = record.map((_record) => schema.validate(_record, utils.pick(_opts, ['existingOnly'])))\n const foundErrors = errors.filter((err) => err)\n if (foundErrors.length) {\n return errors\n }\n return undefined\n }\n return schema.validate(record, _opts)\n },\n\n /**\n * Method used to wrap data returned by an adapter with this Mapper's\n * {@link Mapper#recordClass}. This method is used by all of a Mapper's CRUD\n * methods. The provided implementation of this method assumes that the `data`\n * passed to it is a record or records that need to be wrapped with\n * {@link Mapper#createRecord}. Override with care.\n *\n * Provided implementation of {@link Mapper#wrap}:\n *\n * ```\n * function (data, opts) {\n * return this.createRecord(data, opts)\n * }\n * ```\n *\n * @example\n * const PostMapper = new Mapper({\n * name: 'post',\n * // Override to customize behavior\n * wrap (data, opts) {\n * const originalWrap = this.constructor.prototype.wrap\n * // Let's say \"GET /post\" doesn't return JSON quite like JSData expects,\n * // but the actual post records are nested under a \"posts\" field. So,\n * // we override Mapper#wrap to handle this special case.\n * if (opts.op === 'findAll') {\n * return originalWrap.call(this, data.posts, opts)\n * }\n * // Otherwise perform original behavior\n * return originalWrap.call(this, data, opts)\n * }\n * })\n *\n * @method Mapper#wrap\n * @param {Object|Object[]} data The record or records to be wrapped.\n * @param {Object} [opts] Configuration options. Passed to {@link Mapper#createRecord}.\n * @returns {Record|Record[]} The wrapped record or records.\n * @since 3.0.0\n */\n wrap (data, opts) {\n return this.createRecord(data, opts)\n },\n\n /**\n * @ignore\n */\n defineRelations () {\n // Setup the mapper's relations, including generating Mapper#relationList\n // and Mapper#relationFields\n utils.forOwn(this.relations, (group, type) => {\n utils.forOwn(group, (relations, _name) => {\n if (utils.isObject(relations)) {\n relations = [relations]\n }\n relations.forEach((def) => {\n const relatedMapper = this.datastore.getMapperByName(_name) || _name\n def.getRelation = () => this.datastore.getMapper(_name)\n\n if (typeof Relation[type] !== 'function') {\n throw utils.err(DOMAIN, 'defineRelations')(400, 'relation type (hasOne, hasMany, etc)', type, true)\n }\n\n this[type](relatedMapper, def)\n })\n })\n })\n }\n})\n\n/**\n * Create a subclass of this Mapper:\n *\n * @example Mapper.extend\n * // Normally you would do: import {Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Mapper} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomMapperClass extends Mapper {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customMapper = new CustomMapperClass()\n * console.log(customMapper.foo())\n * console.log(CustomMapperClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherMapperClass = Mapper.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherMapper = new OtherMapperClass()\n * console.log(otherMapper.foo())\n * console.log(OtherMapperClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherMapperClass () {\n * Mapper.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Mapper.extend({\n * constructor: AnotherMapperClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherMapper = new AnotherMapperClass()\n * console.log(anotherMapper.created_at)\n * console.log(anotherMapper.foo())\n * console.log(AnotherMapperClass.beep())\n *\n * @method Mapper.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Mapper class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport Component from './Component'\nimport Mapper from './Mapper'\n\nconst DOMAIN = 'Container'\n\nexport const proxiedMapperMethods = [\n /**\n * Wrapper for {@link Mapper#count}.\n *\n * @example\n * // Get the number of published blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.count('post', { status: 'published' }).then((numPublished) => {\n * console.log(numPublished) // e.g. 45\n * })\n *\n * @method Container#count\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#count}.\n * @param {Object} [opts] See {@link Mapper#count}.\n * @returns {Promise} See {@link Mapper#count}.\n * @see Mapper#count\n * @since 3.0.0\n */\n 'count',\n\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~beforeCreateListener} for how to listen for this event.\n *\n * @event Container#beforeCreate\n * @see Container~beforeCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback Container~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see Container#event:beforeCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#create}. See\n * {@link Container~afterCreateListener} for how to listen for this event.\n *\n * @event Container#afterCreate\n * @see Container~afterCreateListener\n * @see Container#create\n */\n /**\n * Callback signature for the {@link Container#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback Container~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see Container#event:afterCreate\n * @see Container#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}.\n *\n * @example\n * // Create and save a new blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.create('post', {\n * title: 'Modeling your data',\n * status: 'draft'\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreate\n * @fires Container#afterCreate\n * @method Container#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props See {@link Mapper#create}.\n * @param {Object} [opts] See {@link Mapper#create}.\n * @returns {Promise} See {@link Mapper#create}.\n * @see Mapper#create\n * @since 3.0.0\n */\n 'create',\n\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~beforeCreateManyListener} for how to listen for this event.\n *\n * @event Container#beforeCreateMany\n * @see Container~beforeCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback Container~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see Container#event:beforeCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#createMany}. See\n * {@link Container~afterCreateManyListener} for how to listen for this event.\n *\n * @event Container#afterCreateMany\n * @see Container~afterCreateManyListener\n * @see Container#createMany\n */\n /**\n * Callback signature for the {@link Container#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback Container~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see Container#event:afterCreateMany\n * @see Container#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}.\n *\n * @example\n * // Create and save several new blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.createMany('post', [{\n * title: 'Modeling your data',\n * status: 'draft'\n * }, {\n * title: 'Reading data',\n * status: 'draft'\n * }]).then((posts) => {\n * console.log(posts[0]) // { id: 1234, status: 'draft', ... }\n * console.log(posts[1]) // { id: 1235, status: 'draft', ... }\n * })\n *\n * @fires Container#beforeCreateMany\n * @fires Container#afterCreateMany\n * @method Container#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record[]} records See {@link Mapper#createMany}.\n * @param {Object} [opts] See {@link Mapper#createMany}.\n * @returns {Promise} See {@link Mapper#createMany}.\n * @see Mapper#createMany\n * @since 3.0.0\n */\n 'createMany',\n\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * __Note:__ This method does __not__ interact with any adapter, and does\n * __not__ save any data. It only creates new objects in memory.\n *\n * @example\n * // Create empty unsaved record instance\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = PostMapper.createRecord()\n *\n * @method Container#createRecord\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Object[]} props See {@link Mapper#createRecord}.\n * @param {Object} [opts] See {@link Mapper#createRecord}.\n * @returns {Promise} See {@link Mapper#createRecord}.\n * @see Mapper#createRecord\n * @since 3.0.0\n */\n 'createRecord',\n\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~beforeDestroyListener} for how to listen for this event.\n *\n * @event Container#beforeDestroy\n * @see Container~beforeDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback Container~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see Container#event:beforeDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroy}. See\n * {@link Container~afterDestroyListener} for how to listen for this event.\n *\n * @event Container#afterDestroy\n * @see Container~afterDestroyListener\n * @see Container#destroy\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback Container~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see Container#event:afterDestroy\n * @see Container#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}.\n *\n * @example\n * // Destroy a specific blog post\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroy('post', 1234).then(() => {\n * // Blog post #1234 has been destroyed\n * })\n *\n * @fires Container#beforeDestroy\n * @fires Container#afterDestroy\n * @method Container#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#destroy}.\n * @param {Object} [opts] See {@link Mapper#destroy}.\n * @returns {Promise} See {@link Mapper#destroy}.\n * @see Mapper#destroy\n * @since 3.0.0\n */\n 'destroy',\n\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event Container#beforeDestroyAll\n * @see Container~beforeDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback Container~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see Container#event:beforeDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#destroyAll}. See\n * {@link Container~afterDestroyAllListener} for how to listen for this event.\n *\n * @event Container#afterDestroyAll\n * @see Container~afterDestroyAllListener\n * @see Container#destroyAll\n */\n /**\n * Callback signature for the {@link Container#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback Container~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see Container#event:afterDestroyAll\n * @see Container#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}.\n *\n * @example\n * // Destroy all \"draft\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.destroyAll('post', { status: 'draft' }).then(() => {\n * // All \"draft\" blog posts have been destroyed\n * })\n *\n * @fires Container#beforeDestroyAll\n * @fires Container#afterDestroyAll\n * @method Container#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#destroyAll}.\n * @param {Object} [opts] See {@link Mapper#destroyAll}.\n * @returns {Promise} See {@link Mapper#destroyAll}.\n * @see Mapper#destroyAll\n * @since 3.0.0\n */\n 'destroyAll',\n\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~beforeFindListener} for how to listen for this event.\n *\n * @event Container#beforeFind\n * @see Container~beforeFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback Container~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see Container#event:beforeFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#find}. See\n * {@link Container~afterFindListener} for how to listen for this event.\n *\n * @event Container#afterFind\n * @see Container~afterFindListener\n * @see Container#find\n */\n /**\n * Callback signature for the {@link Container#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback Container~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see Container#event:afterFind\n * @see Container#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.find('post', 1).then((post) => {\n * console.log(post) // { id: 1, ...}\n * })\n *\n * @fires Container#beforeFind\n * @fires Container#afterFind\n * @method Container#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#find}.\n * @param {Object} [opts] See {@link Mapper#find}.\n * @returns {Promise} See {@link Mapper#find}.\n * @see Mapper#find\n * @since 3.0.0\n */\n 'find',\n\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~beforeFindAllListener} for how to listen for this event.\n *\n * @event Container#beforeFindAll\n * @see Container~beforeFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback Container~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see Container#event:beforeFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#findAll}. See\n * {@link Container~afterFindAllListener} for how to listen for this event.\n *\n * @event Container#afterFindAll\n * @see Container~afterFindAllListener\n * @see Container#findAll\n */\n /**\n * Callback signature for the {@link Container#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback Container~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see Container#event:afterFindAll\n * @see Container#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createRecord}.\n *\n * @example\n * // Find all \"published\" blog posts\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.findAll('post', { status: 'published' }).then((posts) => {\n * console.log(posts) // [{ id: 1, ...}, ...]\n * })\n *\n * @fires Container#beforeFindAll\n * @fires Container#afterFindAll\n * @method Container#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] See {@link Mapper#findAll}.\n * @param {Object} [opts] See {@link Mapper#findAll}.\n * @returns {Promise} See {@link Mapper#findAll}.\n * @see Mapper#findAll\n * @since 3.0.0\n */\n 'findAll',\n\n /**\n * Wrapper for {@link Mapper#getSchema}.\n *\n * @method Container#getSchema\n * @param {string} name Name of the {@link Mapper} to target.\n * @returns {Schema} See {@link Mapper#getSchema}.\n * @see Mapper#getSchema\n * @since 3.0.0\n */\n 'getSchema',\n\n /**\n * Wrapper for {@link Mapper#is}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post')\n * const post = store.createRecord()\n *\n * console.log(store.is('post', post)) // true\n * // Equivalent to what's above\n * console.log(post instanceof store.getMapper('post').recordClass) // true\n *\n * @method Container#is\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object|Record} record See {@link Mapper#is}.\n * @returns {boolean} See {@link Mapper#is}.\n * @see Mapper#is\n * @since 3.0.0\n */\n 'is',\n\n /**\n * Wrapper for {@link Mapper#sum}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('purchase_order')\n *\n * store.sum('purchase_order', 'amount', { status: 'paid' }).then((amountPaid) => {\n * console.log(amountPaid) // e.g. 451125.34\n * })\n *\n * @method Container#sum\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {string} field See {@link Mapper#sum}.\n * @param {Object} [query] See {@link Mapper#sum}.\n * @param {Object} [opts] See {@link Mapper#sum}.\n * @returns {Promise} See {@link Mapper#sum}.\n * @see Mapper#sum\n * @since 3.0.0\n */\n 'sum',\n\n /**\n * Wrapper for {@link Mapper#toJSON}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('person', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * const person = store.createRecord('person', { id: 1, name: 'John', foo: 'bar' })\n * console.log(store.toJSON('person', person)) // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\n * console.log(store.toJSON('person', person), { strict: true }) // {\"id\":1,\"name\":\"John\"}\n *\n * @method Container#toJSON\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Record|Record[]} records See {@link Mapper#toJSON}.\n * @param {Object} [opts] See {@link Mapper#toJSON}.\n * @returns {Object|Object[]} See {@link Mapper#toJSON}.\n * @see Mapper#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~beforeUpdateListener} for how to listen for this event.\n *\n * @event Container#beforeUpdate\n * @see Container~beforeUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback Container~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see Container#event:beforeUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#update}. See\n * {@link Container~afterUpdateListener} for how to listen for this event.\n *\n * @event Container#afterUpdate\n * @see Container~afterUpdateListener\n * @see Container#update\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback Container~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see Container#event:afterUpdate\n * @see Container#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.update('post', 1234, {\n * status: 'published',\n * published_at: new Date()\n * }).then((post) => {\n * console.log(post) // { id: 1234, status: 'published', ... }\n * })\n *\n * @fires Container#beforeUpdate\n * @fires Container#afterUpdate\n * @method Container#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Mapper#update}.\n * @param {Object} record See {@link Mapper#update}.\n * @param {Object} [opts] See {@link Mapper#update}.\n * @returns {Promise} See {@link Mapper#update}.\n * @see Mapper#update\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/saving-data\",\"Saving data\"]\n */\n 'update',\n\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateAll\n * @see Container~beforeUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback Container~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see Container#event:beforeUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateAll}. See\n * {@link Container~afterUpdateAllListener} for how to listen for this event.\n *\n * @event Container#afterUpdateAll\n * @see Container~afterUpdateAllListener\n * @see Container#updateAll\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback Container~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see Container#event:afterUpdateAll\n * @see Container#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}.\n *\n * @example\n * // Turn all of John's blog posts into drafts.\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * const update = { status: draft: published_at: null }\n * const query = { userId: 1234 }\n * store.updateAll('post', update, query).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateAll\n * @fires Container#afterUpdateAll\n * @method Container#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} update See {@link Mapper#updateAll}.\n * @param {Object} [query] See {@link Mapper#updateAll}.\n * @param {Object} [opts] See {@link Mapper#updateAll}.\n * @returns {Promise} See {@link Mapper#updateAll}.\n * @see Mapper#updateAll\n * @since 3.0.0\n */\n 'updateAll',\n\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event Container#beforeUpdateMany\n * @see Container~beforeUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback Container~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see Container#event:beforeUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link Container#updateMany}. See\n * {@link Container~afterUpdateManyListener} for how to listen for this event.\n *\n * @event Container#afterUpdateMany\n * @see Container~afterUpdateManyListener\n * @see Container#updateMany\n */\n /**\n * Callback signature for the {@link Container#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback Container~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see Container#event:afterUpdateMany\n * @see Container#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}.\n *\n * @example\n * import {Container} from 'js-data'\n * import RethinkDBAdapter from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n * store.defineMapper('post')\n *\n * store.updateMany('post', [\n * { id: 1234, status: 'draft' },\n * { id: 2468, status: 'published', published_at: new Date() }\n * ]).then((posts) => {\n * console.log(posts) // [...]\n * })\n *\n * @fires Container#beforeUpdateMany\n * @fires Container#afterUpdateMany\n * @method Container#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#updateMany}.\n * @param {Object} [opts] See {@link Mapper#updateMany}.\n * @returns {Promise} See {@link Mapper#updateMany}.\n * @see Mapper#updateMany\n * @since 3.0.0\n */\n 'updateMany',\n\n /**\n * Wrapper for {@link Mapper#validate}.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * }\n * }\n * })\n * let errors = store.validate('post', { name: 'John' })\n * console.log(errors) // undefined\n * errors = store.validate('post', { name: 123 })\n * console.log(errors) // [{ expected: 'one of (string)', actual: 'number', path: 'name' }]\n *\n * @method Container#validate\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records See {@link Mapper#validate}.\n * @param {Object} [opts] See {@link Mapper#validate}.\n * @returns {Promise} See {@link Mapper#validate}.\n * @see Mapper#validate\n * @since 3.0.0\n */\n 'validate'\n]\n\n/**\n * The `Container` class is a place to define and store {@link Mapper} instances.\n *\n * `Container` makes it easy to manage your Mappers. Without a container, you\n * need to manage Mappers yourself, including resolving circular dependencies\n * among relations. All Mappers in a container share the same adapters, so you\n * don't have to register adapters for every single Mapper.\n *\n * @example Container#constructor\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n *\n * @class Container\n * @extends Component\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {Constructor} [opts.mapperClass] See {@link Container#mapperClass}.\n * @param {Object} [opts.mapperDefaults] See {@link Container#mapperDefaults}.\n * @since 3.0.0\n */\nexport function Container (opts) {\n utils.classCallCheck(this, Container)\n Component.call(this)\n opts || (opts = {})\n\n Object.defineProperties(this, {\n /**\n * The adapters registered with this Container, which are also shared by all\n * Mappers in this Container.\n *\n * @name Container#_adapters\n * @see Container#registerAdapter\n * @since 3.0.0\n * @type {Object}\n */\n _adapters: {\n value: {}\n },\n\n /**\n * The the mappers in this container\n *\n * @name Container#_mappers\n * @see Mapper\n * @since 3.0.0\n * @type {Object}\n */\n _mappers: {\n value: {}\n },\n\n /**\n * Constructor function to use in {@link Container#defineMapper} to create new\n * {@link Mapper} instances. {@link Container#mapperClass} should extend\n * {@link Mapper}. By default {@link Mapper} is used to instantiate Mappers.\n *\n * @example Container#mapperClass\n * // import {Container, Mapper} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * class MyMapperClass extends Mapper {\n * foo () { return 'bar' }\n * }\n * const store = new Container({\n * mapperClass: MyMapperClass\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').foo())\n *\n * @name Container#mapperClass\n * @see Mapper\n * @since 3.0.0\n * @type {Constructor}\n */\n mapperClass: {\n value: undefined,\n writable: true\n }\n })\n\n // Apply options provided by the user\n utils.fillIn(this, opts)\n\n /**\n * Defaults options to pass to {@link Container#mapperClass} when creating a\n * new {@link Mapper}.\n *\n * @example Container#mapperDefaults\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: {\n * idAttribute: '_id'\n * }\n * })\n * store.defineMapper('user')\n * console.log(store.getMapper('user').idAttribute)\n *\n * @default {}\n * @name Container#mapperDefaults\n * @since 3.0.0\n * @type {Object}\n */\n this.mapperDefaults = this.mapperDefaults || {}\n\n // Use the Mapper class if the user didn't provide a mapperClass\n this.mapperClass || (this.mapperClass = Mapper)\n}\n\nconst props = {\n constructor: Container,\n\n /**\n * Register a new event listener on this Container.\n *\n * Proxy for {@link Component#on}. If an event was emitted by a {@link Mapper}\n * in the Container, then the name of the {@link Mapper} will be prepended to\n * the arugments passed to the listener.\n *\n * @example Container#on\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * store.on('foo', function (...args) { console.log(args.join(':')) })\n * store.defineMapper('user')\n * store.emit('foo', 'arg1', 'arg2')\n * store.getMapper('user').emit('foo', 'arg1', 'arg2')\n *\n * @method Container#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n * @since 3.0.0\n */\n\n /**\n * Used to bind to events emitted by mappers in this container.\n *\n * @method Container#_onMapperEvent\n * @param {string} name Name of the mapper that emitted the event.\n * @param {...*} [args] Args See {@link Mapper#emit}.\n * @private\n * @since 3.0.0\n */\n _onMapperEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * Return a container scoped to a particular mapper.\n *\n * @example Container#as\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method Container#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} A container scoped to a particular mapper.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n proxiedMapperMethods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Create a new mapper and register it in this container.\n *\n * @example Container#defineMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container({\n * mapperDefaults: { foo: 'bar' }\n * })\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(UserMapper.foo)\n *\n * @method Container#defineMapper\n * @param {string} name Name under which to register the new {@link Mapper}.\n * {@link Mapper#name} will be set to this value.\n * @param {Object} [opts] Configuration options. Passed to\n * {@link Container#mapperClass} when creating the new {@link Mapper}.\n * @returns {Mapper} The newly created instance of {@link Mapper}.\n * @see Container#as\n * @since 3.0.0\n */\n defineMapper (name, opts) {\n // For backwards compatibility with defineResource\n if (utils.isObject(name)) {\n opts = name\n name = opts.name\n }\n if (!utils.isString(name)) {\n throw utils.err(`${DOMAIN}#defineMapper`, 'name')(400, 'string', name)\n }\n\n // Default values for arguments\n opts || (opts = {})\n // Set Mapper#name\n opts.name = name\n opts.relations || (opts.relations = {})\n\n // Check if the user is overriding the datastore's default mapperClass\n const mapperClass = opts.mapperClass || this.mapperClass\n delete opts.mapperClass\n\n // Apply the datastore's defaults to the options going into the mapper\n utils.fillIn(opts, this.mapperDefaults)\n\n // Instantiate a mapper\n const mapper = this._mappers[name] = new mapperClass(opts) // eslint-disable-line\n mapper.relations || (mapper.relations = {})\n // Make sure the mapper's name is set\n mapper.name = name\n // All mappers in this datastore will share adapters\n mapper._adapters = this.getAdapters()\n\n mapper.datastore = this\n\n mapper.on('all', (...args) => this._onMapperEvent(name, ...args))\n mapper.defineRelations()\n\n return mapper\n },\n\n defineResource (name, opts) {\n console.warn('DEPRECATED: defineResource is deprecated, use defineMapper instead')\n return this.defineMapper(name, opts)\n },\n\n /**\n * Return the registered adapter with the given name or the default adapter if\n * no name is provided.\n *\n * @method Container#getAdapter\n * @param {string} [name] The name of the adapter to retrieve.\n * @returns {Adapter} The adapter.\n * @since 3.0.0\n */\n getAdapter (name) {\n const adapter = this.getAdapterName(name)\n if (!adapter) {\n throw utils.err(`${DOMAIN}#getAdapter`, 'name')(400, 'string', name)\n }\n return this.getAdapters()[adapter]\n },\n\n /**\n * Return the name of a registered adapter based on the given name or options,\n * or the name of the default adapter if no name provided.\n *\n * @method Container#getAdapterName\n * @param {(Object|string)} [opts] The name of an adapter or options, if any.\n * @returns {string} The name of the adapter.\n * @since 3.0.0\n */\n getAdapterName (opts) {\n opts || (opts = {})\n if (utils.isString(opts)) {\n opts = { adapter: opts }\n }\n return opts.adapter || this.mapperDefaults.defaultAdapter\n },\n\n /**\n * Return the registered adapters of this container.\n *\n * @method Container#getAdapters\n * @returns {Adapter}\n * @since 3.0.0\n */\n getAdapters () {\n return this._adapters\n },\n\n /**\n * Return the mapper registered under the specified name.\n *\n * @example Container#getMapper\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * store.getMapper('profile') // throws Error, there is no mapper with name \"profile\"\n *\n * @method Container#getMapper\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapper (name) {\n const mapper = this.getMapperByName(name)\n if (!mapper) {\n throw utils.err(`${DOMAIN}#getMapper`, name)(404, 'mapper')\n }\n return mapper\n },\n\n /**\n * Return the mapper registered under the specified name.\n * Doesn't throw error if mapper doesn't exist.\n *\n * @example Container#getMapperByName\n * // import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new Container()\n * // Container#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n * console.log(UserMapper === store.getMapper('user'))\n * console.log(UserMapper === store.as('user').getMapper())\n * console.log(store.getMapper('profile')) // Does NOT throw an error\n *\n * @method Container#getMapperByName\n * @param {string} name {@link Mapper#name}.\n * @returns {Mapper}\n * @since 3.0.0\n */\n getMapperByName (name) {\n return this._mappers[name]\n },\n\n /**\n * Register an adapter on this container under the given name. Adapters\n * registered on a container are shared by all mappers in the container.\n *\n * @example\n * import {Container} from 'js-data'\n * import {RethinkDBAdapter} from 'js-data-rethinkdb'\n * const store = new Container()\n * store.registerAdapter('rethinkdb', new RethinkDBAdapter(), { default: true })\n *\n * @method Container#registerAdapter\n * @param {string} name The name of the adapter to register.\n * @param {Adapter} adapter The adapter to register.\n * @param {Object} [opts] Configuration options.\n * @param {boolean} [opts.default=false] Whether to make the adapter the\n * default adapter for all Mappers in this container.\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/connecting-to-a-data-source\",\"Connecting to a data source\"]\n */\n registerAdapter (name, adapter, opts) {\n opts || (opts = {})\n this.getAdapters()[name] = adapter\n // Optionally make it the default adapter for the target.\n if (opts === true || opts.default) {\n this.mapperDefaults.defaultAdapter = name\n utils.forOwn(this._mappers, function (mapper) {\n mapper.defaultAdapter = name\n })\n }\n }\n}\n\nproxiedMapperMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getMapper(name)[method](...args)\n }\n})\n\nComponent.extend(props)\n\n/**\n * Create a subclass of this Container:\n * @example Container.extend\n * // Normally you would do: import {Container} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {Container} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomContainerClass extends Container {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customContainer = new CustomContainerClass()\n * console.log(customContainer.foo())\n * console.log(CustomContainerClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherContainerClass = Container.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherContainer = new OtherContainerClass()\n * console.log(otherContainer.foo())\n * console.log(OtherContainerClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherContainerClass () {\n * Container.call(this)\n * this.created_at = new Date().getTime()\n * }\n * Container.extend({\n * constructor: AnotherContainerClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherContainer = new AnotherContainerClass()\n * console.log(anotherContainer.created_at)\n * console.log(anotherContainer.foo())\n * console.log(AnotherContainerClass.beep())\n *\n * @method Container.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this Container class.\n * @since 3.0.0\n */\n","import utils from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport {proxiedMapperMethods, Container} from './Container'\nimport Collection from './Collection'\n\nconst DOMAIN = 'SimpleStore'\nconst proxiedCollectionMethods = [\n /**\n * Wrapper for {@link Collection#add}.\n *\n * @example SimpleStore#add\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n *\n * // Add one book to the in-memory store:\n * store.add('book', { id: 1, title: 'Respect your Data' })\n * // Add multiple books to the in-memory store:\n * store.add('book', [\n * { id: 2, title: 'Easy data recipes' },\n * { id: 3, title: 'Active Record 101' }\n * ])\n *\n * @fires SimpleStore#add\n * @method SimpleStore#add\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Object[]|Record|Record[])} data See {@link Collection#add}.\n * @param {Object} [opts] Configuration options. See {@link Collection#add}.\n * @returns {(Object|Object[]|Record|Record[])} See {@link Collection#add}.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n 'add',\n\n /**\n * Wrapper for {@link Collection#between}.\n *\n * @example\n * // Get all users ages 18 to 30\n * const users = store.between('user', 18, 30, { index: 'age' })\n *\n * @example\n * // Same as above\n * const users = store.between('user', [18], [30], { index: 'age' })\n *\n * @method SimpleStore#between\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Array} leftKeys See {@link Collection#between}.\n * @param {Array} rightKeys See {@link Collection#between}.\n * @param {Object} [opts] Configuration options. See {@link Collection#between}.\n * @returns {Object[]|Record[]} See {@link Collection#between}.\n * @see Collection#between\n * @see Collection#between\n * @since 3.0.0\n */\n 'between',\n\n /**\n * Wrapper for {@link Collection#createIndex}.\n *\n * @example\n * // Index users by age\n * store.createIndex('user', 'age')\n *\n * @example\n * // Index users by status and role\n * store.createIndex('user', 'statusAndRole', ['status', 'role'])\n *\n * @method SimpleStore#createIndex\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {string} name See {@link Collection#createIndex}.\n * @param {string[]} [fieldList] See {@link Collection#createIndex}.\n * @see Collection#createIndex\n * @see Collection#createIndex\n * @since 3.0.0\n */\n 'createIndex',\n\n /**\n * Wrapper for {@link Collection#filter}.\n *\n * @example SimpleStore#filter\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * // Get the draft posts created less than three months ago\n * let posts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * created_at_timestamp: {\n * '>=': (new Date().getTime() - (1000 \\* 60 \\* 60 \\* 24 \\* 30 \\* 3)) // 3 months ago\n * }\n * }\n * })\n * console.log(posts)\n *\n * // Use a custom filter function\n * posts = store.filter('post', function (post) { return post.id % 2 === 0 })\n *\n * @method SimpleStore#filter\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(Object|Function)} [queryOrFn={}] See {@link Collection#filter}.\n * @param {Object} [thisArg] See {@link Collection#filter}.\n * @returns {Array} See {@link Collection#filter}.\n * @see Collection#filter\n * @see Collection#filter\n * @since 3.0.0\n */\n 'filter',\n\n /**\n * Wrapper for {@link Collection#get}.\n *\n * @example SimpleStore#get\n * // import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('post')\n * store.add('post', [\n * { id: 1, status: 'draft', created_at_timestamp: new Date().getTime() }\n * ])\n *\n * console.log(store.get('post', 1)) // {...}\n * console.log(store.get('post', 2)) // undefined\n *\n * @method SimpleStore#get\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id See {@link Collection#get}.\n * @returns {(Object|Record)} See {@link Collection#get}.\n * @see Collection#get\n * @see Collection#get\n * @since 3.0.0\n */\n 'get',\n\n /**\n * Wrapper for {@link Collection#getAll}.\n *\n * @example\n * // Get the posts where \"status\" is \"draft\" or \"inReview\"\n * const posts = store.getAll('post', 'draft', 'inReview', { index: 'status' })\n *\n * @example\n * // Same as above\n * const posts = store.getAll('post', ['draft'], ['inReview'], { index: 'status' })\n *\n * @method SimpleStore#getAll\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {...Array} [keyList] See {@link Collection#getAll}.\n * @param {Object} [opts] See {@link Collection#getAll}.\n * @returns {Array} See {@link Collection#getAll}.\n * @see Collection#getAll\n * @see Collection#getAll\n * @since 3.0.0\n */\n 'getAll',\n\n /**\n * Wrapper for {@link Collection#prune}.\n *\n * @method SimpleStore#prune\n * @param {Object} [opts] See {@link Collection#prune}.\n * @returns {Array} See {@link Collection#prune}.\n * @see Collection#prune\n * @see Collection#prune\n * @since 3.0.0\n */\n 'prune',\n\n /**\n * Wrapper for {@link Collection#query}.\n *\n * @example\n * // Grab page 2 of users between ages 18 and 30\n * store.query('user')\n * .between(18, 30, { index: 'age' }) // between ages 18 and 30\n * .skip(10) // second page\n * .limit(10) // page size\n * .run()\n *\n * @method SimpleStore#query\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @returns {Query} See {@link Collection#query}.\n * @see Collection#query\n * @see Collection#query\n * @since 3.0.0\n */\n 'query',\n\n /**\n * Wrapper for {@link Collection#toJSON}.\n *\n * @example\n * store.defineMapper('post', {\n * schema: {\n * properties: {\n * id: { type: 'number' },\n * title: { type: 'string' }\n * }\n * }\n * })\n * store.add('post', [\n * { id: 1, status: 'published', title: 'Respect your Data' },\n * { id: 2, status: 'draft', title: 'Connecting to a data source' }\n * ])\n * console.log(store.toJSON('post'))\n * const draftsJSON = store.query('post')\n * .filter({ status: 'draft' })\n * .mapCall('toJSON')\n * .run()\n *\n * @method SimpleStore#toJSON\n * @param {(string|number)} name Name of the {@link Mapper} to target.\n * @param {Object} [opts] See {@link Collection#toJSON}.\n * @returns {Array} See {@link Collection#toJSON}.\n * @see Collection#toJSON\n * @see Collection#toJSON\n * @since 3.0.0\n */\n 'toJSON',\n\n /**\n * Wrapper for {@link Collection#unsaved}.\n *\n * @method SimpleStore#unsaved\n * @returns {Array} See {@link Collection#unsaved}.\n * @see Collection#unsaved\n * @see Collection#unsaved\n * @since 3.0.0\n */\n 'unsaved'\n]\nconst ownMethodsForScoping = [\n 'addToCache',\n 'cachedFind',\n 'cachedFindAll',\n 'cacheFind',\n 'cacheFindAll',\n 'hashQuery'\n]\n\nconst cachedFn = function (name, hashOrId, opts) {\n const cached = this._completedQueries[name][hashOrId]\n if (utils.isFunction(cached)) {\n return cached(name, hashOrId, opts)\n }\n return cached\n}\n\nconst SIMPLESTORE_DEFAULTS = {\n /**\n * Whether to use the pending query if a `find` request for the specified\n * record is currently underway. Can be set to `true`, `false`, or to a\n * function that returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFind\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFind: true,\n\n /**\n * Whether to use the pending query if a `findAll` request for the given query\n * is currently underway. Can be set to `true`, `false`, or to a function that\n * returns `true` or `false`.\n *\n * @default true\n * @name SimpleStore#usePendingFindAll\n * @since 3.0.0\n * @type {boolean|Function}\n */\n usePendingFindAll: true\n}\n\n/**\n * The `SimpleStore` class is an extension of {@link Container}. Not only does\n * `SimpleStore` manage mappers, but also collections. `SimpleStore` implements the\n * asynchronous {@link Mapper} methods, such as {@link Mapper#find} and\n * {@link Mapper#create}. If you use the asynchronous `SimpleStore` methods\n * instead of calling them directly on the mappers, then the results of the\n * method calls will be inserted into the store's collections. You can think of\n * a `SimpleStore` as an [Identity Map](https://en.wikipedia.org/wiki/Identity_map_pattern)\n * for the [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping)\n * (the Mappers).\n *\n * ```javascript\n * import {SimpleStore} from 'js-data'\n * ```\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new SimpleStore()\n *\n * // SimpleStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // SimpleStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful SimpleStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class SimpleStore\n * @extends Container\n * @param {Object} [opts] Configuration options. See {@link Container}.\n * @param {boolean} [opts.collectionClass={@link Collection}] See {@link SimpleStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link SimpleStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link SimpleStore#usePendingFindAll}.\n * @returns {SimpleStore}\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-SimpleStore\",\"Working with the SimpleStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction SimpleStore (opts) {\n utils.classCallCheck(this, SimpleStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, SIMPLESTORE_DEFAULTS)\n Container.call(this, opts)\n\n this.collectionClass = this.collectionClass || Collection\n this._collections = {}\n this._pendingQueries = {}\n this._completedQueries = {}\n}\n\nconst props = {\n constructor: SimpleStore,\n\n /**\n * Internal method used to handle Mapper responses.\n *\n * @method SimpleStore#_end\n * @private\n * @param {string} name Name of the {@link Collection} to which to\n * add the data.\n * @param {Object} result The result from a Mapper.\n * @param {Object} [opts] Configuration options.\n * @returns {(Object|Array)} Result.\n */\n _end (name, result, opts) {\n let data = opts.raw ? result.data : result\n if (data && utils.isFunction(this.addToCache)) {\n data = this.addToCache(name, data, opts)\n if (opts.raw) {\n result.data = data\n } else {\n result = data\n }\n }\n return result\n },\n\n /**\n * Register a new event listener on this SimpleStore.\n *\n * Proxy for {@link Container#on}. If an event was emitted by a Mapper or\n * Collection in the SimpleStore, then the name of the Mapper or Collection will\n * be prepended to the arugments passed to the provided event handler.\n *\n * @example\n * // Listen for all \"afterCreate\" events in a SimpleStore\n * store.on('afterCreate', (mapperName, props, opts, result) => {\n * console.log(mapperName) // \"post\"\n * console.log(props.id) // undefined\n * console.log(result.id) // 1234\n * })\n * store.create('post', { title: 'Modeling your data' }).then((post) => {\n * console.log(post.id) // 1234\n * })\n *\n * @example\n * // Listen for the \"add\" event on a collection\n * store.on('add', (mapperName, records) => {\n * console.log(records) // [...]\n * })\n *\n * @example\n * // Listen for \"change\" events on a record\n * store.on('change', (mapperName, record, changes) => {\n * console.log(changes) // { changed: { title: 'Modeling your data' } }\n * })\n * post.title = 'Modeling your data'\n *\n * @method SimpleStore#on\n * @param {string} event Name of event to subsribe to.\n * @param {Function} listener Listener function to handle the event.\n * @param {*} [ctx] Optional content in which to invoke the listener.\n */\n\n /**\n * Used to bind to events emitted by collections in this store.\n *\n * @method SimpleStore#_onCollectionEvent\n * @private\n * @param {string} name Name of the collection that emitted the event.\n * @param {...*} [args] Args passed to {@link Collection#emit}.\n */\n _onCollectionEvent (name, ...args) {\n const type = args.shift()\n this.emit(type, name, ...args)\n },\n\n /**\n * This method takes the data received from {@link SimpleStore#find},\n * {@link SimpleStore#findAll}, {@link SimpleStore#update}, etc., and adds the\n * data to the store. _You don't need to call this method directly._\n *\n * If you're using the http adapter and your response data is in an unexpected\n * format, you may need to override this method so the right data gets added\n * to the store.\n *\n * @example\n * const store = new SimpleStore({\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return SimpleStore.prototype.addToCache.call(this, mapperName, data, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * addToCache (mapperName, data, opts) {\n * // Let's say for a particular Resource, response data is in a weird format\n * if (name === 'comment') {\n * // Re-assign the variable to add the correct records into the stores\n * data = data.items\n * }\n * // Now perform default behavior\n * return super.addToCache(mapperName, data, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#addToCache\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {*} data Data from which data should be selected for add.\n * @param {Object} [opts] Configuration options.\n */\n addToCache (name, data, opts) {\n return this.getCollection(name).add(data, opts)\n },\n\n /**\n * Return the store scoped to a particular mapper/collection pair.\n *\n * @example SimpleStore.as\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * const UserMapper = store.defineMapper('user')\n * const UserStore = store.as('user')\n *\n * const user1 = store.createRecord('user', { name: 'John' })\n * const user2 = UserStore.createRecord({ name: 'John' })\n * const user3 = UserMapper.createRecord({ name: 'John' })\n * console.log(user1 === user2)\n * console.log(user2 === user3)\n * console.log(user1 === user3)\n *\n * @method SimpleStore#as\n * @param {string} name Name of the {@link Mapper}.\n * @returns {Object} The store, scoped to a particular Mapper/Collection pair.\n * @since 3.0.0\n */\n as (name) {\n const props = {}\n const original = this\n const methods = ownMethodsForScoping\n .concat(proxiedMapperMethods)\n .concat(proxiedCollectionMethods)\n\n methods.forEach(function (method) {\n props[method] = {\n writable: true,\n value (...args) {\n return original[method](name, ...args)\n }\n }\n })\n props.getMapper = {\n writable: true,\n value () {\n return original.getMapper(name)\n }\n }\n props.getCollection = {\n writable: true,\n value () {\n return original.getCollection(name)\n }\n }\n return Object.create(this, props)\n },\n\n /**\n * Retrieve a cached `find` result, if any. This method is called during\n * {@link SimpleStore#find} to determine if {@link Mapper#find} needs to be\n * called. If this method returns `undefined` then {@link Mapper#find} will\n * be called. Otherwise {@link SimpleStore#find} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFind.call(this, mapperName, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFind (mapperName, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#find call\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cachedFind(mapperName, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cachedFind: cachedFn,\n\n /**\n * Retrieve a cached `findAll` result, if any. This method is called during\n * {@link SimpleStore#findAll} to determine if {@link Mapper#findAll} needs to be\n * called. If this method returns `undefined` then {@link Mapper#findAll} will\n * be called. Otherwise {@link SimpleStore#findAll} will immediately resolve with\n * the return value of this method.\n *\n * When using {@link SimpleStore} in the browser, you can override this method\n * to implement your own cache-busting strategy.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return undefined to trigger a Mapper#findAll call\n * return undefined\n * }\n * // Otherwise perform default behavior\n * return super.cachedFindAll(mapperName, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cachedFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cachedFindAll: cachedFn,\n\n /**\n * Mark a {@link Mapper#find} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `find` entry is\n * added it means subsequent calls to the same Resource with the same `id`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#get} instead of delegating to {@link Mapper#find}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return SimpleStore.prototype.cacheFind.call(this, mapperName, data, id, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cacheFind (mapperName, data, id, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior\n * return super.cacheFind(mapperName, data, id, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFind\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}.\n * @param {*} data The result to cache.\n * @param {(string|number)} id The `id` argument passed to {@link SimpleStore#find}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#find}.\n * @since 3.0.0\n */\n cacheFind (name, data, id, opts) {\n this._completedQueries[name][id] = (name, id, opts) => this.get(name, id)\n },\n\n /**\n * Mark a {@link Mapper#findAll} result as cached by adding an entry to\n * {@link SimpleStore#_completedQueries}. By default, once a `findAll` entry is\n * added it means subsequent calls to the same Resource with the same `query`\n * argument will immediately resolve with the result of calling\n * {@link SimpleStore#filter} instead of delegating to {@link Mapper#findAll}.\n *\n * As part of implementing your own caching strategy, you may choose to\n * override this method.\n *\n * @example\n * const store = new SimpleStore({\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return SimpleStore.prototype.cachedFindAll.call(this, mapperName, data, hash, opts)\n * }\n * })\n *\n * @example\n * // Extend using ES2015 class syntax.\n * class MyStore extends SimpleStore {\n * cachedFindAll (mapperName, data, hash, opts) {\n * // Let's say for a particular Resource, we always want to pull fresh from the server\n * if (mapperName === 'schedule') {\n * // Return without saving an entry to SimpleStore#_completedQueries\n * return\n * }\n * // Otherwise perform default behavior.\n * return super.cachedFindAll(mapperName, data, hash, opts)\n * }\n * }\n * const store = new MyStore()\n *\n * @method SimpleStore#cacheFindAll\n * @param {string} name The `name` argument passed to {@link SimpleStore#findAll}.\n * @param {*} data The result to cache.\n * @param {string} hash The result of calling {@link SimpleStore#hashQuery} on\n * the `query` argument passed to {@link SimpleStore#findAll}.\n * @param {Object} opts The `opts` argument passed to {@link SimpleStore#findAll}.\n * @since 3.0.0\n */\n cacheFindAll (name, data, hash, opts) {\n this._completedQueries[name][hash] = (name, hash, opts) => this.filter(name, utils.fromJson(hash))\n },\n\n /**\n * Remove __all__ records from the in-memory store and reset\n * {@link SimpleStore#_completedQueries}.\n *\n * @method SimpleStore#clear\n * @returns {Object} Object containing all records that were in the store.\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n clear () {\n const removed = {}\n utils.forOwn(this._collections, (collection, name) => {\n removed[name] = collection.removeAll()\n this._completedQueries[name] = {}\n })\n return removed\n },\n\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~beforeCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreate\n * @see SimpleStore~beforeCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreate} event.\n *\n * @example\n * function onBeforeCreate (mapperName, props, opts) {\n * // do something\n * }\n * store.on('beforeCreate', onBeforeCreate)\n *\n * @callback SimpleStore~beforeCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreate}.\n * @see SimpleStore#event:beforeCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#create}. See\n * {@link SimpleStore~afterCreateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreate\n * @see SimpleStore~afterCreateListener\n * @see SimpleStore#create\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreate} event.\n *\n * @example\n * function onAfterCreate (mapperName, props, opts, result) {\n * // do something\n * }\n * store.on('afterCreate', onAfterCreate)\n *\n * @callback SimpleStore~afterCreateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterCreate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreate}.\n * @see SimpleStore#event:afterCreate\n * @see SimpleStore#create\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#create}. Adds the created record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book {\"author_id\":1234,...}\n * store.create('book', {\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }).then((book) => {\n * console.log(book.id) // 120392\n * console.log(book.title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreate\n * @fires SimpleStore#afterCreate\n * @fires SimpleStore#add\n * @method SimpleStore#create\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} record Passed to {@link Mapper#create}.\n * @param {Object} [opts] Passed to {@link Mapper#create}. See\n * {@link Mapper#create} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n create (name, record, opts) {\n opts || (opts = {})\n return Container.prototype.create.call(this, name, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~beforeCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeCreateMany\n * @see SimpleStore~beforeCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeCreateMany} event.\n *\n * @example\n * function onBeforeCreateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeCreateMany', onBeforeCreateMany)\n *\n * @callback SimpleStore~beforeCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeCreateMany}.\n * @see SimpleStore#event:beforeCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#createMany}. See\n * {@link SimpleStore~afterCreateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterCreateMany\n * @see SimpleStore~afterCreateManyListener\n * @see SimpleStore#createMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterCreateMany} event.\n *\n * @example\n * function onAfterCreateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterCreateMany', onAfterCreateMany)\n *\n * @callback SimpleStore~afterCreateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterCreateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterCreateMany}.\n * @see SimpleStore#event:afterCreateMany\n * @see SimpleStore#createMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#createMany}. Adds the created records to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // POST /book [{\"author_id\":1234,...},{...}]\n * store.createMany('book', [{\n * author_id: 1234,\n * edition: 'First Edition',\n * title: 'Respect your Data'\n * }, {\n * author_id: 1234,\n * edition: 'Second Edition',\n * title: 'Respect your Data'\n * }]).then((books) => {\n * console.log(books[0].id) // 142394\n * console.log(books[0].title) // \"Respect your Data\"\n * })\n *\n * @fires SimpleStore#beforeCreateMany\n * @fires SimpleStore#afterCreateMany\n * @fires SimpleStore#add\n * @method SimpleStore#createMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Array} records Passed to {@link Mapper#createMany}.\n * @param {Object} [opts] Passed to {@link Mapper#createMany}. See\n * {@link Mapper#createMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the create.\n * @since 3.0.0\n */\n createMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.createMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n defineMapper (name, opts) {\n const self = this\n const mapper = Container.prototype.defineMapper.call(self, name, opts)\n self._pendingQueries[name] = {}\n self._completedQueries[name] = {}\n mapper.relationList || Object.defineProperty(mapper, 'relationList', { value: [] })\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, { // eslint-disable-line\n // Make sure the collection has somewhere to store \"added\" timestamps\n _added: {},\n // Give the collection a reference to this SimpleStore\n datastore: self,\n // The mapper tied to the collection\n mapper\n })\n\n const schema = mapper.schema || {}\n const properties = schema.properties || {}\n // TODO: Make it possible index nested properties?\n utils.forOwn(properties, function (opts, prop) {\n if (opts.indexed) {\n collection.createIndex(prop)\n }\n })\n\n // Create a secondary index on the \"added\" timestamps of records in the\n // collection\n collection.createIndex('addedTimestamps', ['$'], {\n fieldGetter (obj) {\n return collection._added[collection.recordId(obj)]\n }\n })\n\n collection.on('all', function (...args) {\n self._onCollectionEvent(name, ...args)\n })\n\n return mapper\n },\n\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~beforeDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroy\n * @see SimpleStore~beforeDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroy} event.\n *\n * @example\n * function onBeforeDestroy (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeDestroy', onBeforeDestroy)\n *\n * @callback SimpleStore~beforeDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroy}.\n * @see SimpleStore#event:beforeDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroy}. See\n * {@link SimpleStore~afterDestroyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroy\n * @see SimpleStore~afterDestroyListener\n * @see SimpleStore#destroy\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroy} event.\n *\n * @example\n * function onAfterDestroy (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterDestroy', onAfterDestroy)\n *\n * @callback SimpleStore~afterDestroyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroy}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroy}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroy}.\n * @see SimpleStore#event:afterDestroy\n * @see SimpleStore#destroy\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroy}. Removes any destroyed record from the\n * in-memory store. Clears out any {@link SimpleStore#_completedQueries} entries\n * associated with the provided `id`.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is no longer in the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n *\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroy\n * @fires SimpleStore#afterDestroy\n * @fires SimpleStore#remove\n * @method SimpleStore#destroy\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#destroy}.\n * @param {Object} [opts] Passed to {@link Mapper#destroy}. See\n * {@link Mapper#destroy} for more configuration options.\n * @returns {Promise} Resolves when the destroy operation completes.\n * @since 3.0.0\n */\n destroy (name, id, opts) {\n opts || (opts = {})\n return Container.prototype.destroy.call(this, name, id, opts).then((result) => {\n const record = this.getCollection(name).remove(id, opts)\n\n if (opts.raw) {\n result.data = record\n } else {\n result = record\n }\n delete this._pendingQueries[name][id]\n delete this._completedQueries[name][id]\n return result\n })\n },\n\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~beforeDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeDestroyAll\n * @see SimpleStore~beforeDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeDestroyAll} event.\n *\n * @example\n * function onBeforeDestroyAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeDestroyAll', onBeforeDestroyAll)\n *\n * @callback SimpleStore~beforeDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeDestroyAll}.\n * @see SimpleStore#event:beforeDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#destroyAll}. See\n * {@link SimpleStore~afterDestroyAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterDestroyAll\n * @see SimpleStore~afterDestroyAllListener\n * @see SimpleStore#destroyAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterDestroyAll} event.\n *\n * @example\n * function onAfterDestroyAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterDestroyAll', onAfterDestroyAll)\n *\n * @callback SimpleStore~afterDestroyAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterDestroyAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterDestroyAll}.\n * @see SimpleStore#event:afterDestroyAll\n * @see SimpleStore#destroyAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#destroyAll}. Removes any destroyed records from\n * the in-memory store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * store.add('book', { id: 1234, title: 'Data Management is Hard' })\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // DELETE /book/1234\n * store.destroy('book', 1234).then(() => {\n * // The book record is gone from the in-memory store\n * console.log(store.get('book', 1234)) // undefined\n * return store.find('book', 1234)\n * }).then((book) {\n * // The book was deleted from the database too\n * console.log(book) // undefined\n * })\n *\n * @fires SimpleStore#beforeDestroyAll\n * @fires SimpleStore#afterDestroyAll\n * @fires SimpleStore#remove\n * @method SimpleStore#destroyAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper#destroyAll}.\n * @param {Object} [opts] Passed to {@link Mapper#destroyAll}. See\n * {@link Mapper#destroyAll} for more configuration options.\n * @returns {Promise} Resolves when the delete completes.\n * @since 3.0.0\n */\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return Container.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n const records = this.getCollection(name).removeAll(query, opts)\n\n if (opts.raw) {\n result.data = records\n } else {\n result = records\n }\n const hash = this.hashQuery(name, query, opts)\n delete this._pendingQueries[name][hash]\n delete this._completedQueries[name][hash]\n return result\n })\n },\n\n eject (name, id, opts) {\n console.warn('DEPRECATED: \"eject\" is deprecated, use \"remove\" instead')\n return this.remove(name, id, opts)\n },\n\n ejectAll (name, query, opts) {\n console.warn('DEPRECATED: \"ejectAll\" is deprecated, use \"removeAll\" instead')\n return this.removeAll(name, query, opts)\n },\n\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~beforeFindListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFind\n * @see SimpleStore~beforeFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFind} event.\n *\n * @example\n * function onBeforeFind (mapperName, id, opts) {\n * // do something\n * }\n * store.on('beforeFind', onBeforeFind)\n *\n * @callback SimpleStore~beforeFindListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFind}.\n * @see SimpleStore#event:beforeFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#find}. See\n * {@link SimpleStore~afterFindListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFind\n * @see SimpleStore~afterFindListener\n * @see SimpleStore#find\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFind} event.\n *\n * @example\n * function onAfterFind (mapperName, id, opts, result) {\n * // do something\n * }\n * store.on('afterFind', onAfterFind)\n *\n * @callback SimpleStore~afterFindListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFind}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterFind}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFind}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFind}.\n * @see SimpleStore#event:afterFind\n * @see SimpleStore#find\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#find}. Adds any found record to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('book')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /book/1234\n * store.find('book', 1234).then((book) => {\n * // The book record is now in the in-memory store\n * console.log(store.get('book', 1234) === book) // true\n * })\n *\n * @fires SimpleStore#beforeFind\n * @fires SimpleStore#afterFind\n * @fires SimpleStore#add\n * @method SimpleStore#find\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#find}.\n * @param {Object} [opts] Passed to {@link Mapper#find}.\n * @param {boolean} [opts.force] Bypass cacheFind\n * @param {boolean|Function} [opts.usePendingFind] See {@link SimpleStore#usePendingFind}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n find (name, id, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const pendingQuery = this._pendingQueries[name][id]\n const usePendingFind = opts.usePendingFind === undefined ? this.usePendingFind : opts.usePendingFind\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFind) ? usePendingFind.call(this, name, id, opts) : usePendingFind)) {\n return pendingQuery\n }\n const item = this.cachedFind(name, id, opts)\n let promise\n\n if (opts.force || !item) {\n promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts).then((result) => {\n delete this._pendingQueries[name][id]\n result = this._end(name, result, opts)\n this.cacheFind(name, result, id, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][id]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(item)\n }\n return promise\n },\n\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~beforeFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeFindAll\n * @see SimpleStore~beforeFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeFindAll} event.\n *\n * @example\n * function onBeforeFindAll (mapperName, query, opts) {\n * // do something\n * }\n * store.on('beforeFindAll', onBeforeFindAll)\n *\n * @callback SimpleStore~beforeFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeFindAll}.\n * @see SimpleStore#event:beforeFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#findAll}. See\n * {@link SimpleStore~afterFindAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterFindAll\n * @see SimpleStore~afterFindAllListener\n * @see SimpleStore#findAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterFindAll} event.\n *\n * @example\n * function onAfterFindAll (mapperName, query, opts, result) {\n * // do something\n * }\n * store.on('afterFindAll', onAfterFindAll)\n *\n * @callback SimpleStore~afterFindAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterFindAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterFindAll}.\n * @see SimpleStore#event:afterFindAll\n * @see SimpleStore#findAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#findAll}. Adds any found records to the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('movie')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // GET /movie?rating=PG\n * store.find('movie', { rating: 'PG' }).then((movies) => {\n * // The movie records are now in the in-memory store\n * console.log(store.filter('movie'))\n * })\n *\n * @fires SimpleStore#beforeFindAll\n * @fires SimpleStore#afterFindAll\n * @fires SimpleStore#add\n * @method SimpleStore#findAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} [query] Passed to {@link Mapper.findAll}.\n * @param {Object} [opts] Passed to {@link Mapper.findAll}.\n * @param {boolean} [opts.force] Bypass cacheFindAll\n * @param {boolean|Function} [opts.usePendingFindAll] See {@link SimpleStore#usePendingFindAll}\n * @returns {Promise} Resolves with the result, if any.\n * @since 3.0.0\n */\n findAll (name, query, opts) {\n opts || (opts = {})\n const mapper = this.getMapper(name)\n const hash = this.hashQuery(name, query, opts)\n const pendingQuery = this._pendingQueries[name][hash]\n const usePendingFindAll = opts.usePendingFindAll === undefined ? this.usePendingFindAll : opts.usePendingFindAll\n utils._(opts, mapper)\n\n if (pendingQuery && (utils.isFunction(usePendingFindAll) ? usePendingFindAll.call(this, name, query, opts) : usePendingFindAll)) {\n return pendingQuery\n }\n\n const items = this.cachedFindAll(name, hash, opts)\n let promise\n\n if (opts.force || !items) {\n promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts).then((result) => {\n delete this._pendingQueries[name][hash]\n result = this._end(name, result, opts)\n this.cacheFindAll(name, result, hash, opts)\n return result\n }, (err) => {\n delete this._pendingQueries[name][hash]\n return utils.reject(err)\n })\n } else {\n promise = utils.resolve(items)\n }\n return promise\n },\n\n /**\n * Return the {@link Collection} with the given name, if for some\n * reason you need a direct reference to the collection.\n *\n * @method SimpleStore#getCollection\n * @param {string} name Name of the {@link Collection} to retrieve.\n * @returns {Collection}\n * @since 3.0.0\n * @throws {Error} Thrown if the specified {@link Collection} does not\n * exist.\n */\n getCollection (name) {\n const collection = this._collections[name]\n if (!collection) {\n throw utils.err(`${DOMAIN}#getCollection`, name)(404, 'collection')\n }\n return collection\n },\n\n /**\n * Hashing function used to cache {@link SimpleStore#find} and\n * {@link SimpleStore#findAll} requests. This method simply JSONifies the\n * `query` argument passed to {@link SimpleStore#find} or\n * {@link SimpleStore#findAll}.\n *\n * Override this method for custom hashing behavior.\n * @method SimpleStore#hashQuery\n * @param {string} name The `name` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @param {Object} query The `query` argument passed to {@link SimpleStore#find}\n * or {@link SimpleStore#findAll}.\n * @returns {string} The JSONified `query`.\n * @since 3.0.0\n */\n hashQuery (name, query, opts) {\n return utils.toJson(query)\n },\n\n inject (name, records, opts) {\n console.warn('DEPRECATED: \"inject\" is deprecated, use \"add\" instead')\n return this.add(name, records, opts)\n },\n\n /**\n * Wrapper for {@link Collection#remove}. Removes the specified\n * {@link Record} from the store.\n *\n * @example SimpleStore#remove\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('book')\n * console.log(store.getAll('book').length)\n * store.add('book', { id: 1234 })\n * console.log(store.getAll('book').length)\n * store.remove('book', 1234)\n * console.log(store.getAll('book').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#remove\n * @param {string} name The name of the {@link Collection} to target.\n * @param {string|number} id The primary key of the {@link Record} to remove.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n remove (name, id, opts) {\n const record = this.getCollection(name).remove(id, opts)\n if (record) {\n this.removeRelated(name, [record], opts)\n }\n return record\n },\n\n /**\n * Wrapper for {@link Collection#removeAll}. Removes the selected\n * {@link Record}s from the store.\n *\n * @example SimpleStore#removeAll\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * const store = new SimpleStore()\n * store.defineMapper('movie')\n * console.log(store.getAll('movie').length)\n * store.add('movie', [{ id: 3, rating: 'R' }, { id: 4, rating: 'PG-13' })\n * console.log(store.getAll('movie').length)\n * store.removeAll('movie', { rating: 'R' })\n * console.log(store.getAll('movie').length)\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeAll\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Object} [query={}] Selection query. See {@link query}.\n * @param {Object} [query.where] See {@link query.where}.\n * @param {number} [query.offset] See {@link query.offset}.\n * @param {number} [query.limit] See {@link query.limit}.\n * @param {string|Array[]} [query.orderBy] See {@link query.orderBy}.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record} to also\n * remove from the store.\n * @returns {Record} The removed {@link Record}s, if any.\n * @see Collection#add\n * @see Collection#add\n * @since 3.0.0\n */\n removeAll (name, query, opts) {\n const records = this.getCollection(name).removeAll(query, opts)\n if (records.length) {\n this.removeRelated(name, records, opts)\n }\n return records\n },\n\n /**\n * Remove from the store {@link Record}s that are related to the provided\n * {@link Record}(s).\n *\n * @fires SimpleStore#remove\n * @method SimpleStore#removeRelated\n * @param {string} name The name of the {@link Collection} to target.\n * @param {Record|Record[]} records {@link Record}s whose relations are to be\n * removed.\n * @param {Object} [opts] Configuration options.\n * @param {string[]} [opts.with] Relations of the {@link Record}(s) to remove\n * from the store.\n * @since 3.0.0\n */\n removeRelated (name, records, opts) {\n if (!utils.isArray(records)) {\n records = [records]\n }\n utils.forEachRelation(this.getMapper(name), opts, (def, optsCopy) => {\n records.forEach((record) => {\n let relatedData\n let query\n if (def.foreignKey && (def.type === hasOneType || def.type === hasManyType)) {\n query = { [def.foreignKey]: def.getForeignKey(record) }\n } else if (def.type === hasManyType && def.localKeys) {\n query = {\n where: {\n [def.getRelation().idAttribute]: {\n 'in': utils.get(record, def.localKeys)\n }\n }\n }\n } else if (def.type === hasManyType && def.foreignKeys) {\n query = {\n where: {\n [def.foreignKeys]: {\n 'contains': def.getForeignKey(record)\n }\n }\n }\n } else if (def.type === belongsToType) {\n relatedData = this.remove(def.relation, def.getForeignKey(record), optsCopy)\n }\n if (query) {\n relatedData = this.removeAll(def.relation, query, optsCopy)\n }\n if (relatedData) {\n if (utils.isArray(relatedData) && !relatedData.length) {\n return\n }\n if (def.type === hasOneType) {\n relatedData = relatedData[0]\n }\n def.setLocalField(record, relatedData)\n }\n })\n })\n },\n\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~beforeUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdate\n * @see SimpleStore~beforeUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdate} event.\n *\n * @example\n * function onBeforeUpdate (mapperName, id, props, opts) {\n * // do something\n * }\n * store.on('beforeUpdate', onBeforeUpdate)\n *\n * @callback SimpleStore~beforeUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdate}.\n * @see SimpleStore#event:beforeUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#update}. See\n * {@link SimpleStore~afterUpdateListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdate\n * @see SimpleStore~afterUpdateListener\n * @see SimpleStore#update\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdate} event.\n *\n * @example\n * function onAfterUpdate (mapperName, id, props, opts, result) {\n * // do something\n * }\n * store.on('afterUpdate', onAfterUpdate)\n *\n * @callback SimpleStore~afterUpdateListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdate}.\n * @param {string|number} id The `id` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdate}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdate}.\n * @see SimpleStore#event:afterUpdate\n * @see SimpleStore#update\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#update}. Adds the updated {@link Record} to the\n * store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post/1234 {\"status\":\"published\"}\n * store.update('post', 1, { status: 'published' }).then((post) => {\n * // The post record has also been updated in the in-memory store\n * console.log(store.get('post', 1234))\n * })\n *\n * @fires SimpleStore#beforeUpdate\n * @fires SimpleStore#afterUpdate\n * @fires SimpleStore#add\n * @method SimpleStore#update\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(string|number)} id Passed to {@link Mapper#update}.\n * @param {Object} record Passed to {@link Mapper#update}.\n * @param {Object} [opts] Passed to {@link Mapper#update}. See\n * {@link Mapper#update} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n update (name, id, record, opts) {\n opts || (opts = {})\n return Container.prototype.update.call(this, name, id, record, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~beforeUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateAll\n * @see SimpleStore~beforeUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateAll} event.\n *\n * @example\n * function onBeforeUpdateAll (mapperName, props, query, opts) {\n * // do something\n * }\n * store.on('beforeUpdateAll', onBeforeUpdateAll)\n *\n * @callback SimpleStore~beforeUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#beforeUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateAll}.\n * @see SimpleStore#event:beforeUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateAll}. See\n * {@link SimpleStore~afterUpdateAllListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateAll\n * @see SimpleStore~afterUpdateAllListener\n * @see SimpleStore#updateAll\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateAll} event.\n *\n * @example\n * function onAfterUpdateAll (mapperName, props, query, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateAll', onAfterUpdateAll)\n *\n * @callback SimpleStore~afterUpdateAllListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} props The `props` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} query The `query` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateAll}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateAll}.\n * @see SimpleStore#event:afterUpdateAll\n * @see SimpleStore#updateAll\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateAll}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post?author_id=1234 {\"status\":\"published\"}\n * store.updateAll('post', { author_id: 1234 }, { status: 'published' }).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.filter('posts', { author_id: 1234 }))\n * })\n *\n * @fires SimpleStore#beforeUpdateAll\n * @fires SimpleStore#afterUpdateAll\n * @fires SimpleStore#add\n * @method SimpleStore#updateAll\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {Object} props Passed to {@link Mapper#updateAll}.\n * @param {Object} [query] Passed to {@link Mapper#updateAll}.\n * @param {Object} [opts] Passed to {@link Mapper#updateAll}. See\n * {@link Mapper#updateAll} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateAll (name, props, query, opts) {\n opts || (opts = {})\n return Container.prototype.updateAll.call(this, name, props, query, opts)\n .then((result) => this._end(name, result, opts))\n },\n\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~beforeUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#beforeUpdateMany\n * @see SimpleStore~beforeUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:beforeUpdateMany} event.\n *\n * @example\n * function onBeforeUpdateMany (mapperName, records, opts) {\n * // do something\n * }\n * store.on('beforeUpdateMany', onBeforeUpdateMany)\n *\n * @callback SimpleStore~beforeUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#beforeUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#beforeUpdateMany}.\n * @see SimpleStore#event:beforeUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Fired during {@link SimpleStore#updateMany}. See\n * {@link SimpleStore~afterUpdateManyListener} for how to listen for this event.\n *\n * @event SimpleStore#afterUpdateMany\n * @see SimpleStore~afterUpdateManyListener\n * @see SimpleStore#updateMany\n */\n /**\n * Callback signature for the {@link SimpleStore#event:afterUpdateMany} event.\n *\n * @example\n * function onAfterUpdateMany (mapperName, records, opts, result) {\n * // do something\n * }\n * store.on('afterUpdateMany', onAfterUpdateMany)\n *\n * @callback SimpleStore~afterUpdateManyListener\n * @param {string} name The `name` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} records The `records` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} opts The `opts` argument received by {@link Mapper#afterUpdateMany}.\n * @param {Object} result The `result` argument received by {@link Mapper#afterUpdateMany}.\n * @see SimpleStore#event:afterUpdateMany\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n /**\n * Wrapper for {@link Mapper#updateMany}. Adds the updated {@link Record}s to\n * the store.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * import {HttpAdapter} from 'js-data-http'\n *\n * const store = new SimpleStore()\n * store.registerAdapter('http', new HttpAdapter(), { default: true })\n *\n * store.defineMapper('post')\n *\n * // Since this example uses the http adapter, we'll get something like:\n * //\n * // PUT /post [{\"id\":3,status\":\"published\"},{\"id\":4,status\":\"published\"}]\n * store.updateMany('post', [\n * { id: 3, status: 'published' },\n * { id: 4, status: 'published' }\n * ]).then((posts) => {\n * // The post records have also been updated in the in-memory store\n * console.log(store.getAll('post', 3, 4))\n * })\n *\n * @fires SimpleStore#beforeUpdateMany\n * @fires SimpleStore#afterUpdateMany\n * @fires SimpleStore#add\n * @method SimpleStore#updateMany\n * @param {string} name Name of the {@link Mapper} to target.\n * @param {(Object[]|Record[])} records Passed to {@link Mapper#updateMany}.\n * @param {Object} [opts] Passed to {@link Mapper#updateMany}. See\n * {@link Mapper#updateMany} for more configuration options.\n * @returns {Promise} Resolves with the result of the update.\n * @since 3.0.0\n */\n updateMany (name, records, opts) {\n opts || (opts = {})\n return Container.prototype.updateMany.call(this, name, records, opts)\n .then((result) => this._end(name, result, opts))\n }\n}\n\nproxiedCollectionMethods.forEach(function (method) {\n props[method] = function (name, ...args) {\n return this.getCollection(name)[method](...args)\n }\n})\n\nexport default Container.extend(props)\n\n/**\n * Fired when a record changes. Only works for records that have tracked fields.\n * See {@link SimpleStore~changeListener} on how to listen for this event.\n *\n * @event SimpleStore#change\n * @see SimpleStore~changeListener\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:change} event.\n *\n * @example\n * function onChange (mapperName, record, changes) {\n * // do something\n * }\n * store.on('change', onChange)\n *\n * @callback SimpleStore~changeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record} record The Record that changed.\n * @param {Object} changes The changes.\n * @see SimpleStore#event:change\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are added to the in-memory store. See\n * {@link SimpleStore~addListener} on how to listen for this event.\n *\n * @event SimpleStore#add\n * @see SimpleStore~addListener\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:add} event.\n *\n * @example\n * function onAdd (mapperName, recordOrRecords) {\n * // do something\n * }\n * store.on('add', onAdd)\n *\n * @callback SimpleStore~addListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} The Record or Records that were added.\n * @see SimpleStore#event:add\n * @see SimpleStore#add\n * @see SimpleStore#create\n * @see SimpleStore#createMany\n * @see SimpleStore#find\n * @see SimpleStore#findAll\n * @see SimpleStore#update\n * @see SimpleStore#updateAll\n * @see SimpleStore#updateMany\n * @since 3.0.0\n */\n\n/**\n * Fired when one or more records are removed from the in-memory store. See\n * {@link SimpleStore~removeListener} for how to listen for this event.\n *\n * @event SimpleStore#remove\n * @see SimpleStore~removeListener\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n */\n\n/**\n * Callback signature for the {@link SimpleStore#event:remove} event.\n *\n * @example\n * function onRemove (mapperName, recordsOrRecords) {\n * // do something\n * }\n * store.on('remove', onRemove)\n *\n * @callback SimpleStore~removeListener\n * @param {string} name The name of the associated {@link Mapper}.\n * @param {Record|Record[]} Record or Records that were removed.\n * @see SimpleStore#event:remove\n * @see SimpleStore#clear\n * @see SimpleStore#destroy\n * @see SimpleStore#destroyAll\n * @see SimpleStore#remove\n * @see SimpleStore#removeAll\n * @since 3.0.0\n */\n\n/**\n * Create a subclass of this SimpleStore:\n * @example SimpleStore.extend\n * // Normally you would do: import {SimpleStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {SimpleStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomSimpleStoreClass extends SimpleStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customSimpleStore = new CustomSimpleStoreClass()\n * console.log(customSimpleStore.foo())\n * console.log(CustomSimpleStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherSimpleStoreClass = SimpleStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherSimpleStore = new OtherSimpleStoreClass()\n * console.log(otherSimpleStore.foo())\n * console.log(OtherSimpleStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherSimpleStoreClass () {\n * SimpleStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * SimpleStore.extend({\n * constructor: AnotherSimpleStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherSimpleStore = new AnotherSimpleStoreClass()\n * console.log(anotherSimpleStore.created_at)\n * console.log(anotherSimpleStore.foo())\n * console.log(AnotherSimpleStoreClass.beep())\n *\n * @method SimpleStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this SimpleStore class.\n * @since 3.0.0\n */\n","import utils from './utils'\nimport './decorators'\nimport Collection from './Collection'\n\nconst DOMAIN = 'LinkedCollection'\n\n/**\n * Extends {@link Collection}. Used by a {@link DataStore} to implement an\n * Identity Map.\n *\n * ```javascript\n * import {LinkedCollection} from 'js-data'\n * ```\n *\n * @class LinkedCollection\n * @extends Collection\n * @param {Array} [records] Initial set of records to insert into the\n * collection. See {@link Collection}.\n * @param {Object} [opts] Configuration options. See {@link Collection}.\n * @returns {Mapper}\n */\nfunction LinkedCollection (records, opts) {\n utils.classCallCheck(this, LinkedCollection)\n // Make sure this collection has somewhere to store \"added\" timestamps\n Object.defineProperties(this, {\n _added: {\n value: {}\n },\n datastore: {\n writable: true,\n value: undefined\n }\n })\n\n Collection.call(this, records, opts)\n\n // Make sure this collection has a reference to a datastore\n if (!this.datastore) {\n throw utils.err(`new ${DOMAIN}`, 'opts.datastore')(400, 'DataStore', this.datastore)\n }\n}\n\nexport default Collection.extend({\n constructor: LinkedCollection,\n\n _addMeta (record, timestamp) {\n // Track when this record was added\n this._added[this.recordId(record)] = timestamp\n\n if (utils.isFunction(record._set)) {\n record._set('$', timestamp)\n }\n },\n\n _clearMeta (record) {\n delete this._added[this.recordId(record)]\n if (utils.isFunction(record._set)) {\n record._set('$') // unset\n }\n },\n\n _onRecordEvent (...args) {\n Collection.prototype._onRecordEvent.apply(this, args)\n const event = args[0]\n // This is a very brute force method\n // Lots of room for optimization\n if (utils.isString(event) && event.indexOf('change') === 0) {\n this.updateIndexes(args[1])\n }\n },\n\n add (records, opts) {\n const mapper = this.mapper\n const timestamp = new Date().getTime()\n const singular = utils.isObject(records) && !utils.isArray(records)\n\n if (singular) {\n records = [records]\n }\n records = Collection.prototype.add.call(this, records, opts)\n\n if (mapper.relationList.length && records.length) {\n // Check the currently visited record for relations that need to be\n // inserted into their respective collections.\n mapper.relationList.forEach(function (def) {\n def.addLinkedRecords(records)\n })\n }\n\n records.forEach((record) => this._addMeta(record, timestamp))\n\n return singular ? records[0] : records\n },\n\n remove (idOrRecord, opts) {\n const mapper = this.mapper\n const record = Collection.prototype.remove.call(this, idOrRecord, opts)\n if (record) {\n this._clearMeta(record)\n }\n\n if (mapper.relationList.length && record) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, [record])\n })\n }\n\n return record\n },\n\n removeAll (query, opts) {\n const mapper = this.mapper\n const records = Collection.prototype.removeAll.call(this, query, opts)\n records.forEach(this._clearMeta, this)\n\n if (mapper.relationList.length && records.length) {\n mapper.relationList.forEach(function (def) {\n def.removeLinkedRecords(mapper, records)\n })\n }\n\n return records\n }\n})\n\n/**\n * Create a subclass of this LinkedCollection:\n *\n * @example LinkedCollection.extend\n * // Normally you would do: import {LinkedCollection} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {LinkedCollection} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomLinkedCollectionClass extends LinkedCollection {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customLinkedCollection = new CustomLinkedCollectionClass()\n * console.log(customLinkedCollection.foo())\n * console.log(CustomLinkedCollectionClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherLinkedCollectionClass = LinkedCollection.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherLinkedCollection = new OtherLinkedCollectionClass()\n * console.log(otherLinkedCollection.foo())\n * console.log(OtherLinkedCollectionClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherLinkedCollectionClass () {\n * LinkedCollection.call(this)\n * this.created_at = new Date().getTime()\n * }\n * LinkedCollection.extend({\n * constructor: AnotherLinkedCollectionClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherLinkedCollection = new AnotherLinkedCollectionClass()\n * console.log(anotherLinkedCollection.created_at)\n * console.log(anotherLinkedCollection.foo())\n * console.log(AnotherLinkedCollectionClass.beep())\n *\n * @method LinkedCollection.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this LinkedCollection class.\n * @since 3.0.0\n */\n","import utils, { safeSetLink, safeSetProp } from './utils'\n\nimport {\n belongsToType,\n hasManyType,\n hasOneType\n} from './decorators'\nimport SimpleStore from './SimpleStore'\nimport LinkedCollection from './LinkedCollection'\n\nconst DATASTORE_DEFAULTS = {\n /**\n * Whether in-memory relations should be unlinked from records after they are\n * destroyed.\n *\n * @default true\n * @name DataStore#unlinkOnDestroy\n * @since 3.0.0\n * @type {boolean}\n */\n unlinkOnDestroy: true\n}\n\n/**\n * The `DataStore` class is an extension of {@link SimpleStore}. Not only does\n * `DataStore` manage mappers and store data in collections, it uses the\n * {@link LinkedCollection} class to link related records together in memory.\n *\n * ```javascript\n * import {DataStore} from 'js-data'\n * ```\n *\n * @example\n * import {DataStore} from 'js-data'\n * import HttpAdapter from 'js-data-http'\n * const store = new DataStore()\n *\n * // DataStore#defineMapper returns a direct reference to the newly created\n * // Mapper.\n * const UserMapper = store.defineMapper('user')\n *\n * // DataStore#as returns the store scoped to a particular Mapper.\n * const UserStore = store.as('user')\n *\n * // Call \"find\" on \"UserMapper\" (Stateless ORM)\n * UserMapper.find(1).then((user) => {\n * // retrieved a \"user\" record via the http adapter, but that's it\n *\n * // Call \"find\" on \"store\" targeting \"user\" (Stateful DataStore)\n * return store.find('user', 1) // same as \"UserStore.find(1)\"\n * }).then((user) => {\n * // not only was a \"user\" record retrieved, but it was added to the\n * // store's \"user\" collection\n * const cachedUser = store.getCollection('user').get(1)\n * console.log(user === cachedUser) // true\n * })\n *\n * @class DataStore\n * @extends SimpleStore\n * @param {Object} [opts] Configuration options. See {@link SimpleStore}.\n * @param {boolean} [opts.collectionClass={@link LinkedCollection}] See {@link DataStore#collectionClass}.\n * @param {boolean} [opts.debug=false] See {@link Component#debug}.\n * @param {boolean} [opts.unlinkOnDestroy=true] See {@link DataStore#unlinkOnDestroy}.\n * @param {boolean|Function} [opts.usePendingFind=true] See {@link DataStore#usePendingFind}.\n * @param {boolean|Function} [opts.usePendingFindAll=true] See {@link DataStore#usePendingFindAll}.\n * @returns {DataStore}\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/working-with-the-datastore\",\"Working with the DataStore\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/jsdata-and-the-browser\",\"Notes on using JSData in the Browser\"]\n */\nfunction DataStore (opts) {\n utils.classCallCheck(this, DataStore)\n\n opts || (opts = {})\n // Fill in any missing options with the defaults\n utils.fillIn(opts, DATASTORE_DEFAULTS)\n opts.collectionClass || (opts.collectionClass = LinkedCollection)\n SimpleStore.call(this, opts)\n}\n\nconst props = {\n constructor: DataStore,\n\n defineMapper (name, opts) {\n // Complexity of this method is beyond simply using => functions to bind context\n const self = this\n const mapper = SimpleStore.prototype.defineMapper.call(self, name, opts)\n const idAttribute = mapper.idAttribute\n const collection = this.getCollection(name)\n\n mapper.relationList.forEach(function (def) {\n const relation = def.relation\n const localField = def.localField\n const path = `links.${localField}`\n const foreignKey = def.foreignKey\n const type = def.type\n const updateOpts = { index: foreignKey }\n let descriptor\n\n const getter = function () { return this._get(path) }\n\n if (type === belongsToType) {\n if (!collection.indexes[foreignKey]) {\n collection.createIndex(foreignKey)\n }\n\n descriptor = {\n get: getter,\n // e.g. profile.user = someUser\n // or comment.post = somePost\n set (record) {\n // e.g. const otherUser = profile.user\n const currentParent = this._get(path)\n // e.g. profile.user === someUser\n if (record === currentParent) {\n return currentParent\n }\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n\n // e.g. profile.user !== someUser\n // or comment.post !== somePost\n if (currentParent && inverseDef) {\n this.removeInverseRelation(currentParent, id, inverseDef, idAttribute)\n }\n if (record) {\n // e.g. profile.user = someUser\n const relatedIdAttribute = def.getRelation().idAttribute\n const relatedId = utils.get(record, relatedIdAttribute)\n\n // Prefer store record\n if (relatedId !== undefined && this._get('$')) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n // e.g. profile.user = someUser\n // or comment.post = somePost\n safeSetLink(this, localField, record)\n safeSetProp(this, foreignKey, relatedId)\n collection.updateIndex(this, updateOpts)\n\n if (inverseDef) {\n this.setupInverseRelation(record, id, inverseDef, idAttribute)\n }\n } else {\n // Unset in-memory link only\n // e.g. profile.user = undefined\n // or comment.post = undefined\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n\n let foreignKeyDescriptor = Object.getOwnPropertyDescriptor(mapper.recordClass.prototype, foreignKey)\n if (!foreignKeyDescriptor) {\n foreignKeyDescriptor = {\n enumerable: true\n }\n }\n const originalGet = foreignKeyDescriptor.get\n foreignKeyDescriptor.get = function () {\n if (originalGet) {\n return originalGet.call(this)\n }\n return this._get(`props.${foreignKey}`)\n }\n const originalSet = foreignKeyDescriptor.set\n foreignKeyDescriptor.set = function (value) {\n if (originalSet) {\n originalSet.call(this, value)\n }\n const currentParent = utils.get(this, localField)\n const id = utils.get(this, idAttribute)\n const inverseDef = def.getInverse(mapper)\n const currentParentId = currentParent ? utils.get(currentParent, def.getRelation().idAttribute) : undefined\n\n if (currentParent && currentParentId !== undefined && currentParentId !== value) {\n if (inverseDef.type === hasOneType) {\n safeSetLink(currentParent, inverseDef.localField, undefined)\n } else if (inverseDef.type === hasManyType) {\n const children = utils.get(currentParent, inverseDef.localField)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n }\n }\n\n safeSetProp(this, foreignKey, value)\n collection.updateIndex(this, updateOpts)\n\n if ((value === undefined || value === null)) {\n if (currentParentId !== undefined) {\n // Unset locals\n utils.set(this, localField, undefined)\n }\n } else if (this._get('$')) {\n const storeRecord = self.get(relation, value)\n if (storeRecord) {\n utils.set(this, localField, storeRecord)\n }\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, foreignKey, foreignKeyDescriptor)\n } else if (type === hasManyType) {\n const localKeys = def.localKeys\n const foreignKeys = def.foreignKeys\n\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n\n descriptor = {\n get () {\n let current = getter.call(this)\n if (!current) {\n this._set(path, [])\n }\n return getter.call(this)\n },\n // e.g. post.comments = someComments\n // or user.groups = someGroups\n // or group.users = someUsers\n set (records) {\n if (records && !utils.isArray(records)) {\n records = [records]\n }\n const id = utils.get(this, idAttribute)\n const relatedIdAttribute = def.getRelation().idAttribute\n const inverseDef = def.getInverse(mapper)\n const inverseLocalField = inverseDef.localField\n const current = this._get(path) || []\n const toLink = []\n const toLinkIds = {}\n\n if (records) {\n records.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n const currentParent = utils.get(record, inverseLocalField)\n if (currentParent && currentParent !== this) {\n const currentChildrenOfParent = utils.get(currentParent, localField)\n // e.g. somePost.comments.remove(comment)\n if (relatedId === undefined) {\n utils.remove(currentChildrenOfParent, (child) => child === record)\n } else {\n utils.remove(currentChildrenOfParent, (child) => child === record || relatedId === utils.get(child, relatedIdAttribute))\n }\n }\n if (relatedId !== undefined) {\n if (this._get('$')) {\n // Prefer store record\n record = self.get(relation, relatedId) || record\n }\n // e.g. toLinkIds[comment.id] = comment\n toLinkIds[relatedId] = record\n }\n toLink.push(record)\n })\n }\n\n // e.g. post.comments = someComments\n if (foreignKey) {\n current.forEach((record) => {\n // e.g. comment.id\n const relatedId = utils.get(record, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(record) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update (unset) inverse relation\n if (records) {\n // e.g. comment.post_id = undefined\n safeSetProp(record, foreignKey, undefined)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n }\n // e.g. comment.post = undefined\n safeSetLink(record, inverseLocalField, undefined)\n }\n })\n toLink.forEach((record) => {\n // Update (set) inverse relation\n // e.g. comment.post_id = post.id\n safeSetProp(record, foreignKey, id)\n // e.g. CommentCollection.updateIndex(comment, { index: 'post_id' })\n self.getCollection(relation).updateIndex(record, updateOpts)\n // e.g. comment.post = post\n safeSetLink(record, inverseLocalField, this)\n })\n } else if (localKeys) {\n // Update locals\n // e.g. group.users = someUsers\n // Update (set) inverse relation\n const ids = toLink.map((child) => utils.get(child, relatedIdAttribute)).filter((id) => id !== undefined)\n // e.g. group.user_ids = [1,2,3,...]\n utils.set(this, localKeys, ids)\n // Update (unset) inverse relation\n if (inverseDef.foreignKeys) {\n current.forEach((child) => {\n const relatedId = utils.get(child, relatedIdAttribute)\n if ((relatedId === undefined && toLink.indexOf(child) === -1) || (relatedId !== undefined && !(relatedId in toLinkIds))) {\n // Update inverse relation\n // safeSetLink(child, inverseLocalField, undefined)\n const parents = utils.get(child, inverseLocalField) || []\n // e.g. someUser.groups.remove(group)\n if (id === undefined) {\n utils.remove(parents, (parent) => parent === this)\n } else {\n utils.remove(parents, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n }\n })\n toLink.forEach((child) => {\n // Update (set) inverse relation\n const parents = utils.get(child, inverseLocalField)\n // e.g. someUser.groups.push(group)\n if (id === undefined) {\n utils.noDupeAdd(parents, this, (parent) => parent === this)\n } else {\n utils.noDupeAdd(parents, this, (parent) => parent === this || id === utils.get(parent, idAttribute))\n }\n })\n }\n } else if (foreignKeys) {\n // e.g. user.groups = someGroups\n // Update (unset) inverse relation\n current.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n // e.g. someGroup.user_ids.remove(user.id)\n utils.remove(ids, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n // e.g. someGroup.users.remove(user)\n if (id === undefined) {\n utils.remove(children, (child) => child === this)\n } else {\n utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n // Update (set) inverse relation\n toLink.forEach((parent) => {\n const ids = utils.get(parent, foreignKeys) || []\n utils.noDupeAdd(ids, id, (_key) => id === _key)\n const children = utils.get(parent, inverseLocalField)\n if (id === undefined) {\n utils.noDupeAdd(children, this, (child) => child === this)\n } else {\n utils.noDupeAdd(children, this, (child) => child === this || id === utils.get(child, idAttribute))\n }\n })\n }\n\n this._set(path, toLink)\n return toLink\n }\n }\n } else if (type === hasOneType) {\n // TODO: Handle case when belongsTo relation isn't ever defined\n if (self._collections[relation] && foreignKey && !self.getCollection(relation).indexes[foreignKey]) {\n self.getCollection(relation).createIndex(foreignKey)\n }\n descriptor = {\n get: getter,\n // e.g. user.profile = someProfile\n set (record) {\n const current = this._get(path)\n if (record === current) {\n return current\n }\n const inverseLocalField = def.getInverse(mapper).localField\n // Update (unset) inverse relation\n if (current) {\n safeSetProp(current, foreignKey, undefined)\n self.getCollection(relation).updateIndex(current, updateOpts)\n safeSetLink(current, inverseLocalField, undefined)\n }\n if (record) {\n const relatedId = utils.get(record, def.getRelation().idAttribute)\n // Prefer store record\n if (relatedId !== undefined) {\n record = self.get(relation, relatedId) || record\n }\n\n // Set locals\n safeSetLink(this, localField, record)\n\n // Update (set) inverse relation\n safeSetProp(record, foreignKey, utils.get(this, idAttribute))\n self.getCollection(relation).updateIndex(record, updateOpts)\n safeSetLink(record, inverseLocalField, this)\n } else {\n // Unset locals\n safeSetLink(this, localField, undefined)\n }\n return record\n }\n }\n }\n\n if (descriptor) {\n descriptor.enumerable = def.enumerable === undefined ? false : def.enumerable\n if (def.get) {\n let origGet = descriptor.get\n descriptor.get = function () {\n return def.get(def, this, (...args) => origGet.apply(this, args))\n }\n }\n if (def.set) {\n let origSet = descriptor.set\n descriptor.set = function (related) {\n return def.set(def, this, related, (value) => origSet.call(this, value === undefined ? related : value))\n }\n }\n Object.defineProperty(mapper.recordClass.prototype, localField, descriptor)\n }\n })\n\n return mapper\n },\n\n destroy (name, id, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroy.call(this, name, id, opts).then((result) => {\n let record\n if (opts.raw) {\n record = result.data\n } else {\n record = result\n }\n\n if (record && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n utils.set(record, def.localField, undefined)\n })\n }\n return result\n })\n },\n\n destroyAll (name, query, opts) {\n opts || (opts = {})\n return SimpleStore.prototype.destroyAll.call(this, name, query, opts).then((result) => {\n let records\n if (opts.raw) {\n records = result.data\n } else {\n records = result\n }\n\n if (records && records.length && this.unlinkOnDestroy) {\n const _opts = utils.plainCopy(opts)\n _opts.withAll = true\n utils.forEachRelation(this.getMapper(name), _opts, (def) => {\n records.forEach((record) => {\n utils.set(record, def.localField, undefined)\n })\n })\n }\n return result\n })\n }\n}\n\nexport default SimpleStore.extend(props)\n\n/**\n * Create a subclass of this DataStore:\n * @example DataStore.extend\n * // Normally you would do: import {DataStore} from 'js-data'\n * const JSData = require('js-data@3.0.0-rc.4')\n * const {DataStore} = JSData\n * console.log('Using JSData v' + JSData.version.full)\n *\n * // Extend the class using ES2015 class syntax.\n * class CustomDataStoreClass extends DataStore {\n * foo () { return 'bar' }\n * static beep () { return 'boop' }\n * }\n * const customDataStore = new CustomDataStoreClass()\n * console.log(customDataStore.foo())\n * console.log(CustomDataStoreClass.beep())\n *\n * // Extend the class using alternate method.\n * const OtherDataStoreClass = DataStore.extend({\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const otherDataStore = new OtherDataStoreClass()\n * console.log(otherDataStore.foo())\n * console.log(OtherDataStoreClass.beep())\n *\n * // Extend the class, providing a custom constructor.\n * function AnotherDataStoreClass () {\n * DataStore.call(this)\n * this.created_at = new Date().getTime()\n * }\n * DataStore.extend({\n * constructor: AnotherDataStoreClass,\n * foo () { return 'bar' }\n * }, {\n * beep () { return 'boop' }\n * })\n * const anotherDataStore = new AnotherDataStoreClass()\n * console.log(anotherDataStore.created_at)\n * console.log(anotherDataStore.foo())\n * console.log(AnotherDataStoreClass.beep())\n *\n * @method DataStore.extend\n * @param {Object} [props={}] Properties to add to the prototype of the\n * subclass.\n * @param {Object} [props.constructor] Provide a custom constructor function\n * to be used as the subclass itself.\n * @param {Object} [classProps={}] Static properties to add to the subclass.\n * @returns {Constructor} Subclass of this DataStore class.\n * @since 3.0.0\n */\n","/**\n * Registered as `js-data` in NPM and Bower.\n *\n * Also available from CDN.JS and JSDelivr.\n *\n * @module js-data\n *\n * @example Install from NPM\n * npm i --save js-data@beta\n * @example Install from Bower\n * bower i --save js-data@3.0.0-beta.1\n * @example Install from CDN.JS\n * \n * @example Install from JSDelivr\n * \n * @example Load into your app via script tag\n * \n * \n * @example Load into your app via CommonJS\n * var JSData = require('js-data');\n * @example Load into your app via ES2015 Modules\n * import * as JSData from 'js-data';\n * @example Load into your app via AMD\n * define('myApp', ['js-data'], function (JSData) { ... })\n */\n\n/**\n * Describes the version of this `JSData` object.\n *\n * @example\n * console.log(JSData.version.full) // \"3.0.0-beta.1\"\n *\n * @name version\n * @memberof module:js-data\n * @property {string} full The full semver value.\n * @property {number} major The major version number.\n * @property {number} minor The minor version number.\n * @property {number} patch The patch version number.\n * @property {(string|boolean)} alpha The alpha version value, otherwise `false`\n * if the current version is not alpha.\n * @property {(string|boolean)} beta The beta version value, otherwise `false`\n * if the current version is not beta.\n * @since 2.0.0\n * @type {Object}\n */\nexport const version = '<%= version %>'\n\n/**\n * JSData's utility methods.\n *\n * @example\n * import {utils} from 'js-data'\n * console.log(utils.isString('foo')) // true\n *\n * @name module:js-data.utils\n * @property {Function} Promise See {@link utils.Promise}.\n * @see utils\n * @since 3.0.0\n * @type {Object}\n */\nimport utils from './utils'\n\n/**\n * JSData's {@link Collection} class.\n *\n * @example\n * import {Collection} from 'js-data'\n * const collection = new Collection()\n *\n * @name module:js-data.Collection\n * @see Collection\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#collection\",\"Components of JSData: Collection\"]\n * @type {Constructor}\n */\nimport Collection from './Collection'\n\n/**\n * JSData's {@link Component} class. Most components in JSData extend this\n * class.\n *\n * @example\n * import {Component} from 'js-data'\n * // Make a custom component.\n * const MyComponent = Component.extend({\n * myMethod (someArg) { ... }\n * })\n *\n * @name module:js-data.Component\n * @see Component\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Component from './Component'\n\n/**\n * JSData's {@link Container} class. Defines and manages {@link Mapper}s. Used\n * in Node.js and in the browser, though in the browser you may want to use\n * {@link DataStore} instead.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n *\n * @name module:js-data.Container\n * @see Container\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#container\",\"Components of JSData: Container\"]\n * @type {Constructor}\n */\nimport {Container} from './Container'\n\n/**\n * JSData's {@link DataStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {DataStore} from 'js-data'\n * const store = new DataStore()\n *\n * @name module:js-data.DataStore\n * @see DataStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#datastore\",\"Components of JSData: DataStore\"]\n * @type {Constructor}\n */\nimport DataStore from './DataStore'\n\n/**\n * JSData's {@link Index} class, based on [mindex]{@link https://github.com/internalfx/mindex}.\n *\n * @name module:js-data.Index\n * @see Index\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Index from '../lib/mindex/index'\n\n/**\n * JSData's {@link LinkedCollection} class. Used by the {@link DataStore}\n * component. If you need to create a collection manually, you should probably\n * use the {@link Collection} class.\n *\n * @name module:js-data.LinkedCollection\n * @see DataStore\n * @see LinkedCollection\n * @since 3.0.0\n * @type {Constructor}\n */\nimport LinkedCollection from './LinkedCollection'\n\n/**\n * JSData's {@link Mapper} class. The core of the ORM.\n *\n * @example Recommended use\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n *\n * @example Create Mapper manually\n * import {Mapper} from 'js-data'\n * const UserMapper = new Mapper({ name: 'user' })\n *\n * @name module:js-data.Mapper\n * @see Container\n * @see Mapper\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/modeling-your-data\",\"Modeling your data\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#mapper\",\"Components of JSData: Mapper\"]\n * @type {Constructor}\n */\nimport Mapper from './Mapper'\n\n/**\n * JSData's {@link Query} class. Used by the {@link Collection} component.\n *\n * @name module:js-data.Query\n * @see Query\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Query from './Query'\n\n/**\n * JSData's {@link Record} class.\n *\n * @example\n * import {Container} from 'js-data'\n * const store = new Container()\n * store.defineMapper('user')\n * const user = store.createRecord('user')\n *\n * @name module:js-data.Record\n * @see Record\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#record\",\"Components of JSData: Record\"]\n * @type {Constructor}\n */\nimport Record from './Record'\n\n/**\n * JSData's {@link Schema} class. Implements http://json-schema.org/draft-04.\n *\n * @example\n * import {Container, Schema} from 'js-data'\n * const userSchema = new Schema({\n * properties: {\n * id: { type: 'string' },\n * name: { type: 'string' }\n * }\n * })\n * const store = new Container()\n * store.defineMapper('user', {\n * schema: userSchema\n * })\n *\n * @name module:js-data.Schema\n * @see Schema\n * @see http://json-schema.org/\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#schema\",\"Components of JSData: schema\"]\n * @tutorial [\"http://www.js-data.io/v3.0/docs/schemas\",\"JSData's Schema Syntax\"]\n * @type {Constructor}\n */\nimport Schema from './Schema'\n\n/**\n * JSData's {@link Settable} class.\n *\n * @example\n * import {Settable} from 'js-data'\n * const obj = new Settable()\n * obj.set('secret', 'value')\n * console.log(JSON.stringify(obj)) // {}\n *\n * @name module:js-data.Settable\n * @see Settable\n * @since 3.0.0\n * @type {Constructor}\n */\nimport Settable from './Settable'\n\n/**\n * JSData's {@link SimpleStore} class. Primarily for use in the browser. In\n * Node.js you probably want to use {@link Container} instead.\n *\n * @example\n * import {SimpleStore} from 'js-data'\n * const store = new SimpleStore()\n *\n * @name module:js-data.SimpleStore\n * @see SimpleStore\n * @since 3.0.0\n * @tutorial [\"http://www.js-data.io/v3.0/docs/components-of-jsdata#SimpleStore\",\"Components of JSData: SimpleStore\"]\n * @type {Constructor}\n */\nimport SimpleStore from './SimpleStore'\n\nexport * from './decorators'\n\nexport {\n Collection,\n Component,\n Container,\n DataStore,\n Index,\n LinkedCollection,\n Mapper,\n Query,\n Record,\n Schema,\n Settable,\n SimpleStore,\n utils\n}\n"],"names":["DOMAIN","INFINITY","MAX_INTEGER","BOOL_TAG","DATE_TAG","FUNC_TAG","NUMBER_TAG","OBJECT_TAG","REGEXP_TAG","STRING_TAG","objToString","Object","prototype","toString","PATH","ERRORS","arguments","toInteger","value","sign","remainder","toStr","call","isPlainObject","constructor","mkdirP","object","path","parts","split","forEach","key","utils","Promise","dest","src","forOwn","undefined","isFunction","indexOf","opts","def","fn","thisArg","relationName","relation","containedName","index","with","_getIndex","localField","withAll","optsCopy","fillIn","getRelation","slice","_activeWith","splice","i","length","substr","list","_relation","isObject","target","props","map","keys","propName","descriptor","getOwnPropertyDescriptor","enumerable","defineProperties","newObject","oldObject","diff","diffObjects","diffCount","added","removed","changed","instance","ctor","err","name","from","to","stackFrom","stackTo","blacklist","plain","isArray","copy","isDate","Date","getTime","isRegExp","RegExp","source","match","lastIndex","create","getPrototypeOf","push","result","hasOwnProperty","isBlacklisted","existing","deepFillIn","deepMixIn","equalsFn","ignore","deepEqual","newKeys","filter","oldKeys","oldValue","newValue","a","b","domain","code","prefix","message","apply","Array","Error","getter","setter","_events","events","args","type","shift","listeners","f","c","all","unshift","func","classProps","superClass","subClass","classCallCheck","obj","setPrototypeOf","strictEs6Class","__proto__","defineProperty","addHiddenPropsToTarget","array","record","mapper","relationList","_forRelation","len","json","isString","JSON","parse","prop","last","pop","isCtor","__super__","array1","array2","item","matches","test","isNumber","log","level","debug","toUpperCase","console","findIndex","_props","reduce","reject","resolve","_path","set","exec","_equal","stringify","safeSetProp","field","_set","safeSetLink","Settable","get","unset","extend","Component","writable","logify","eventify","_listeners","INDEX_ERR","reserved","escapeRegExp","percentRegExp","underscoreRegExp","escape","pattern","replace","Query","collection","data","where","fields","ops","predicates","clause","expr","op","groups","_where","prev","parser","_applyWhereFromArray","_applyWhereFromObject","group","isOr","keep","first","charAt","evaluate","_testArrayGroup","_testObjectGroup","leftKeys","rightKeys","getIndex","between","orderBy","cA","cB","temp","compare","predicate","like","query","getData","sort","skip","offset","limit","forEachFn","keyList","concat","getAll","flags","num","Math","min","mapFn","funcName","intersection","hashCode","insertAt","removeAt","binarySearch","lo","hi","compared","mid","Index","fieldList","fieldGetter","isIndex","values","pos","found","dataLocation","newIndex","results","order","cb","visitAll","_between","leftKey","rightKey","leftInclusive","rightInclusive","currKey","peek","isUnique","removeRecord","j","insertRecord","COLLECTION_DEFAULTS","Collection","records","idAttribute","queryClass","recordId","add","emitRecordEvents","emit","_","beforeAdd","singular","id","onConflict","commitOnMerge","commit","updateIndexes","createRecord","indexes","on","_onRecordEvent","silent","afterAdd","run","instances","removeAll","unsaved","Ctor","initialValue","idOrRecord","beforeRemove","isSorN","off","afterRemove","queryOrRecords","beforeRemoveAll","plainCopy","remove","afterRemoveAll","mapCall","updateRecord","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","relationFields","relatedRecord","_setForeignKey","relatedRecords","relatedData","inverse","findInverseRelation","isInversedTo","getLocalField","linkRecord","isEmptyLinks","canFindLinkFor","findExistingLinksFor","setLocalField","relatedId","setForeignKey","BelongsToRelation","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","ids","findExistingLinksByForeignKey","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","HasOneRelation","RelationType","belongsTo","assignTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","_get","_mapper","quickHasChanges","areDifferent","validate","currentParent","inverseDef","children","child","noDupeAdd","relations","adapter","getAdapterName","then","dbg","tasks","task","forEachRelation","raw","load","previous","preserve","postProcess","changesOnly","changes","types","isBoolean","isInteger","isNull","segmentToString","segment","str","makePath","segments","makeError","actual","expected","addError","errors","maxLengthCommon","keyword","schema","max","minLengthCommon","validationKeywords","allErrors","allOf","_schema","validated","anyOf","possibleValues","join","items","checkingTuple","maximum","exclusiveMaximum","maxProperties","minimum","exclusiveMinimum","minProperties","multipleOf","not","oneOf","additionalProperties","properties","patternProperties","toValidate","omit","undef","origProp","required","existingOnly","prevProp","validType","_type","validator","typeGroupValidators","uniqueItems","runOps","ANY_OPS","ARRAY_OPS","NUMERIC_OPS","OBJECT_OPS","STRING_OPS","validateAny","ctx","shouldPop","changingPath","changedPath","changeHistoryPath","eventIdPath","silentPath","validationFailureMsg","makeDescriptor","keyPath","unsetter","track","originalGet","_unset","error","current","changing","setTimeout","changeRecord","timestamp","changeHistory","originalSet","numeric","Schema","definition","_definition","extends","validationKeyword","hasSet","orig","applyDefaults","pick","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","MAPPER_DEFAULTS","Mapper","recordClass","methods","isPrototypeOf","applySchema","_data","wrap","crud","originalRecord","belongsToRelationData","relationData","relatedIdAttribute","createMany","getAdapter","pass","createdRecordData","_end","_result","originalRecords","_records","createdRecordsData","belongsToData","RecordCtor","is","method","config","lifecycleMethods","upper","before","after","defaults","_value","beforeAssign","adapterArgs","getAdapters","defaultAdapter","_adapters","default","strict","_opts","_record","foundErrors","_name","getMapperByName","getMapper","proxiedMapperMethods","Container","mapperDefaults","mapperClass","original","_mappers","_onMapperEvent","defineRelations","warn","defineMapper","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","_completedQueries","SIMPLESTORE_DEFAULTS","SimpleStore","collectionClass","_collections","_pendingQueries","addToCache","hash","fromJson","self","indexed","createIndex","_added","_onCollectionEvent","destroy","destroyAll","hashQuery","pendingQuery","usePendingFind","cachedFind","promise","force","find","cacheFind","usePendingFindAll","cachedFindAll","findAll","cacheFindAll","toJson","removeRelated","getForeignKey","update","updateAll","updateMany","LinkedCollection","event","addLinkedRecords","_addMeta","_clearMeta","removeLinkedRecords","DATASTORE_DEFAULTS","DataStore","updateOpts","getInverse","removeInverseRelation","updateIndex","setupInverseRelation","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","parent","_key","origGet","origSet","unlinkOnDestroy","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA,IAAMA,SAAS,OAAf;;AAEA,IAAMC,WAAW,IAAI,CAArB;AACA,IAAMC,cAAc,uBAApB;AACA,IAAMC,WAAW,kBAAjB;AACA,IAAMC,WAAW,eAAjB;AACA,IAAMC,WAAW,mBAAjB;AACA,IAAMC,aAAa,iBAAnB;AACA,IAAMC,aAAa,iBAAnB;AACA,IAAMC,aAAa,iBAAnB;AACA,IAAMC,aAAa,iBAAnB;AACA,IAAMC,cAAcC,OAAOC,SAAP,CAAiBC,QAArC;AACA,IAAMC,OAAO,cAAb;;AAEA,IAAMC,SAAS;OAAA,eACJ;0BAAsBC,UAAU,CAAV,CAApB,kBAA4CA,UAAU,CAAV,IAAeA,UAAU,CAAV,CAAf,WAAqC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WJ;;AAkYA,kBAAe6d,cAAYpY,MAAZ,CAAmBhI,OAAnB,CAAf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpdA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,AAAO,IAAM8jB,UAAU,gBAAhB;;;;;;;;;;;;;;;AAeP,AAEA;;;;;;;;;;;;;AAaA,AAEA;;;;;;;;;;;;;;;;AAgBA,AAEA;;;;;;;;;;;;;;;AAeA,AAEA;;;;;;;;;;;;;;AAcA,AAEA;;;;;;;;AAQA,AAEA;;;;;;;;;;;AAWA,AAEA;;;;;;;;;;;;;;;;;;;;AAoBA,AAEA;;;;;;;;AAQA,AAEA;;;;;;;;;;;;;;;AAeA,AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,AAEA;;;;;;;;;;;;;;AAcA,AAEA;;;;;;;;;;;;;GAcA,AAEA,AAEA;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/js-data.min.js b/dist/js-data.min.js index 5cbfe3e8..773ad015 100644 --- a/dist/js-data.min.js +++ b/dist/js-data.min.js @@ -1,13 +1,13 @@ /*! * js-data -* @version 3.0.0-rc.6 - Homepage +* @version 3.0.0-rc.7 - Homepage * @author js-data project authors * @copyright (c) 2014-2016 js-data project authors * @license MIT * * @overview js-data is a framework-agnostic, datastore-agnostic ORM/ODM for Node.js and the Browser. */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("js-data",["exports"],t):t(e.JSData=e.JSData||{})}(this,function(e){"use strict";function Settable(){var e={};Object.defineProperties(this,{_get:{value:function value(t){return O.get(e,t)}},_set:{value:function value(t,n){return O.set(e,t,n)}},_unset:{value:function value(t){return O.unset(e,t)}}})}function Component(e){Settable.call(this),e||(e={}),this.debug=!!e.hasOwnProperty("debug")&&!!e.debug,Object.defineProperty(this,"_listeners",{value:{},writable:!0})}function Query(e){O.classCallCheck(this,Query),this.collection=e,this.data=null}function sort(e,t,n){return e===t?0:(n&&(e=n(e),t=n(t)),null===e&&null===t||void 0===e&&void 0===t?-1:null===e||void 0===e?-1:null===t||void 0===t?1:et?1:0)}function insertAt(e,t,n){return e.splice(t,0,n),e}function removeAt(e,t){return e.splice(t,1),e}function binarySearch(e,t,n){for(var i=0,r=e.length,o=void 0,a=void 0;i=0?o=r:(a=O._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(i,t,{});if(o){var s={};O.fillIn(s,t.getRelation()),O.fillIn(s,e),s.with=e.with.slice(),s._activeWith=s.with.splice(a,1)[0],s.with.forEach(function(e,t){e&&0===e.indexOf(o)&&e.length>=o.length&&"."===e[o.length]?s.with[t]=e.substr(o.length+1):s.with[t]=""}),n.call(i,t,s)}},_getIndex:function _getIndex(e,t){var n=-1;return e.forEach(function(e,i){return e===t?(n=i,!1):O.isObject(e)&&e.relation===t?(n=i,!1):void 0}),n},addHiddenPropsToTarget:function addHiddenPropsToTarget(e,t){var n={};Object.keys(t).forEach(function(e){var i=Object.getOwnPropertyDescriptor(t,e);i.enumerable=!1,n[e]=i}),Object.defineProperties(e,n)},areDifferent:function areDifferent(e,t,n){n||(n={});var i=O.diffObjects(e,t,n),r=Object.keys(i.added).length+Object.keys(i.removed).length+Object.keys(i.changed).length;return r>0},classCallCheck:function classCallCheck(e,t){if(!(e instanceof t))throw O.err(""+t.name)(500,"Cannot call a class as a function")},copy:function copy(e,t,n,i,o,a){if(t){if(e===t)throw O.err(r+".copy")(500,"Cannot copy! Source and destination are identical.");if(n=n||[],i=i||[],O.isObject(e)){var s=n.indexOf(e);if(s!==-1)return i[s];n.push(e),i.push(t)}var l=void 0;if(O.isArray(e)){var c=void 0;for(t.length=0,c=0;c1?t-1:0),i=1;i=0&&e.splice(n,1)}},resolve:function resolve(e){return O.Promise.resolve(e)},set:function set(e,t,n){if(O.isObject(t))O.forOwn(t,function(t,n){O.set(e,n,t)});else{var i=v.exec(t);i?A(e,i[1])[i[2]]=n:e[t]=n}},deepEqual:function deepEqual(e,t){if(e===t)return!0;var n=!0;if(O.isObject(e)&&O.isObject(t)){if(O.forOwn(e,function(e,i){n=n&&O.deepEqual(e,t[i])}),!n)return n;O.forOwn(t,function(t,i){n=n&&O.deepEqual(t,e[i])})}else{if(!O.isArray(e)||!O.isArray(t))return!1;e.forEach(function(e,i){if(n=n&&O.deepEqual(e,t[i]),!n)return!1})}return n},toJson:JSON.stringify,unset:function unset(e,t){for(var n=t.split("."),i=n.pop();t=n.shift();)if(e=e[t],null==e)return;e[i]=void 0}},x=function safeSetProp(e,t,n){e&&e._set?e._set("props."+t,n):O.set(e,t,n)},_=function safeSetLink(e,t,n){e&&e._set?e._set("links."+t,n):O.set(e,t,n)};Settable.extend=O.extend;var C=Settable.extend({constructor:Component});Component.extend=O.extend,O.logify(Component.prototype),O.eventify(Component.prototype,function(){return this._listeners},function(e){this._listeners=e});var w="Query",F="Index inaccessible after first operation",k={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},R=/([.*+?^=!:${}()|[\]\/\\])/g,E=/%/g,I=/_/g,j=function escape(e){return e.replace(R,"\\$1")},S=C.extend({constructor:Query,_applyWhereFromObject:function _applyWhereFromObject(e){var t=[],n=[],i=[];return O.forOwn(e,function(e,r){O.isObject(e)||(e={"==":e}),O.forOwn(e,function(e,o){t.push(r),n.push(o),i.push(e)})}),{fields:t,ops:n,predicates:i}},_applyWhereFromArray:function _applyWhereFromArray(e){var t=this,n=[];return e.forEach(function(i,r){if(!O.isString(i)){var o=e[r-1],a=O.isArray(i)?t._applyWhereFromArray:t._applyWhereFromObject,s=a.call(t,i);"or"===o&&(s.isOr=!0),n.push(s)}}),n.isArray=!0,n},_testObjectGroup:function _testObjectGroup(e,t,n,i){var r=void 0,o=n.fields,a=n.ops,s=n.predicates,l=a.length;for(r=0;ra?1:t1?t-1:0),i=1;i":function _(e,t){return e>t},">=":function _(e,t){return e>=t},"<":function _(e,t){return e=0;i--){var r=n[i];t=r.isIndex?t.concat(r.getAll(e)):t.concat(r)}else for(var o=0;oo)break}else if(this.keys[s]>=o)break;if(i=this.values[s].isIndex?i.concat(this.values[s].getAll()):i.concat(this.values[s]),n.limit&&i.length>=n.limit+n.offset)break}}else for(var l=a.index;lo)break;if(i=this.values[l].isIndex?c===r?i.concat(this.values[l]._between(O.copy(e),t.map(function(){}),n)):c===o?i.concat(this.values[l]._between(e.map(function(){}),O.copy(t),n)):i.concat(this.values[l].getAll()):i.concat(this.values[l]),n.limit&&i.length>=n.limit+n.offset)break}return n.limit?i.slice(0,n.limit+n.offset):i},peek:function peek(){return this.values.length?this.values[0].isIndex?this.values[0].peek():this.values[0]:[]},clear:function clear(){this.keys=[],this.values=[]},insertRecord:function insertRecord(e){var t=this.fieldList.map(function(t){return O.isFunction(t)?t(e)||void 0:e[t]||void 0});this.set(t,e)},removeRecord:function removeRecord(e){var t=this,n=void 0,i=void 0!==this.hashCode(e);return this.values.forEach(function(r,o){if(r.isIndex){if(r.removeRecord(e))return 0===r.keys.length&&(removeAt(t.keys,o),removeAt(t.values,o)),n=!0,!1}else{var a={};if(void 0!==t.keys[o]&&i)i&&(a=binarySearch(r,e,t.hashCode));else for(var s=r.length-1;s>=0;s--)if(r[s]===e){a={found:!0,index:s};break}if(a.found)return removeAt(r,a.index),0===r.length&&(removeAt(t.keys,o),removeAt(t.values,o)),n=!0,!1}}),n?e:void 0},updateRecord:function updateRecord(e){var t=this.removeRecord(e);void 0!==t&&this.insertRecord(e)}});var M="Collection",L={commitOnMerge:!0,idAttribute:"id",onConflict:"merge"},P=C.extend({constructor:Collection,_onRecordEvent:function _onRecordEvent(){this.emit.apply(this,arguments)},add:function add(e,t){var n=this;t||(t={}),O._(t,this),e=this.beforeAdd(e,t)||e;var i=!1,r=this.recordId();if(!O.isArray(e)){if(!O.isObject(e))throw O.err(M+"#add","records")(400,"object or array",e);e=[e],i=!0}e=e.map(function(e){var i=n.recordId(e),o=void 0===i?i:n.get(i);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;if("merge"===a)O.deepMixIn(o,e);else{if("replace"!==a)throw O.err(M+"#add","opts.onConflict")(400,"one of (merge, replace)",a,!0);O.forOwn(o,function(t,n){n!==r&&void 0===e[n]&&(o[n]=void 0)}),o.set(e)}e=o,t.commitOnMerge&&O.isFunction(e.commit)&&e.commit(),n.updateIndexes(e)}else e=n.mapper?n.mapper.createRecord(e,t):e,n.index.insertRecord(e),O.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&O.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=i?e[0]:e;return this.emit("add",o),this.afterAdd(e,t,o)||o},afterAdd:function afterAdd(){},afterRemove:function afterRemove(){},afterRemoveAll:function afterRemoveAll(){},beforeAdd:function beforeAdd(){},beforeRemove:function beforeRemove(){},beforeRemoveAll:function beforeRemoveAll(){},between:function between(e,t,n){return this.query().between(e,t,n).run()},createIndex:function createIndex(e,t,n){var i=this;O.isString(e)&&void 0===t&&(t=[e]),n||(n={}),n.hashCode||(n.hashCode=function(e){return i.recordId(e)});var r=this.indexes[e]=new Index(t,n);this.index.visitAll(r.insertRecord,r)},filter:function filter(e,t){return this.query().filter(e,t).run()},forEach:function forEach(e,t){this.index.visitAll(e,t)},get:function get(e){var t=this.query().get(e).run();return t.length?t[0]:void 0},getAll:function getAll(){var e;return(e=this.query()).getAll.apply(e,arguments).run()},getIndex:function getIndex(e){var t=e?this.indexes[e]:this.index;if(!t)throw O.err(M+"#getIndex",e)(404,"index");return t},limit:function limit(e){return this.query().limit(e).run()},map:function map(e,t){var n=[];return this.index.visitAll(function(i){n.push(e.call(t,i))}),n},mapCall:function mapCall(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i")(400,"string",r)},canFindLinkFor:function canFindLinkFor(e){var t=this.foreignKey||this.foreignKeys;return!!(t||this.localKeys&&O.get(e,this.localKeys))},linkRecord:function linkRecord(e,t){var n=this,i=this.relatedCollection,r=this.canAutoAddLinks,o=this.foreignKey,a=this.relatedCollection.unsaved();return t.map(function(t){var s=i.recordId(t);return(void 0===s&&a.indexOf(t)===-1||t!==i.get(s))&&(o&&n.setForeignKey(e,t),r&&(t=i.add(t))),t})},findExistingLinksFor:function findExistingLinksFor(e){var t=O.get(e,this.mapper.idAttribute),n=this.localKeys?O.get(e,this.localKeys):null,i=void 0;if(void 0!==t&&this.foreignKey?i=this.findExistingLinksByForeignKey(t):this.localKeys&&n?i=this.findExistingLinksByLocalKeys(n):void 0!==t&&this.foreignKeys&&(i=this.findExistingLinksByForeignKeys(t)),i&&i.length)return i},findExistingLinksByLocalKeys:function findExistingLinksByLocalKeys(e){return this.relatedCollection.filter({where:n({},this.mapper.idAttribute,{in:e})})},findExistingLinksByForeignKeys:function findExistingLinksByForeignKeys(e){return this.relatedCollection.filter({where:n({},this.foreignKeys,{contains:e})})}},{TYPE_NAME:"hasMany"}),Q=Relation.extend({findExistingLinksFor:function findExistingLinksFor(e,t){var n=O.get(t,e.idAttribute),i=this.findExistingLinksByForeignKey(n);if(i&&i.length)return i[0]}},{TYPE_NAME:"hasOne"});[q,J,Q].forEach(function(e){Relation[e.TYPE_NAME]=function(t,n){return new e(t,n)}});var B=function belongsTo$1(e,t){return function(n){Relation.belongsTo(e,t).assignTo(n)}},U=function hasMany$1(e,t){return function(n){Relation.hasMany(e,t).assignTo(n); -}},$=function hasOne$1(e,t){return function(n){Relation.hasOne(e,t).assignTo(n)}},H="Record",G=function superMethod(e,t){var n=e.datastore;return n&&n[t]?function(){for(var i=arguments.length,r=Array(i),o=0;or)return ie(t.length,"length no more than "+r,i)},ae=function minLengthCommon(e,t,n,i){var r=n[e];if(t.lengthe:maximum>=e))return r?ie(e,"no more than nor equal to "+maximum,i):ie(e,"no more than "+maximum,i)},maxItems:function maxItems(e,t,n){if(O.isArray(e))return oe("maxItems",e,t,n)},maxLength:function maxLength(e,t,n){return oe("maxLength",e,t,n)},maxProperties:function maxProperties(e,t,n){if(O.isObject(e)){var maxProperties=t.maxProperties,i=Object.keys(e).length;return i>maxProperties?ie(i,"no more than "+maxProperties+" properties",n):void 0}},minimum:function minimum(e,n,i){var minimum=n.minimum,r=n.exclusiveMinimum;if(("undefined"==typeof e?"undefined":t(e))===("undefined"==typeof minimum?"undefined":t(minimum))&&!(r?e>minimum:e>=minimum))return r?ie(e,"no less than nor equal to "+minimum,i):ie(e,"no less than "+minimum,i)},minItems:function minItems(e,t,n){if(O.isArray(e))return ae("minItems",e,t,n)},minLength:function minLength(e,t,n){return ae("minLength",e,t,n)},minProperties:function minProperties(e,t,n){if(O.isObject(e)){var minProperties=t.minProperties,i=Object.keys(e).length;return i0;o--)for(r=e[o],a=o-1;a>=0;a--)if(O.deepEqual(r,e[a]))return ie(r,"no duplicates",n)}}},le=function runOps(e,t,n,i){var r=[];return e.forEach(function(e){void 0!==n[e]&&(r=r.concat(se[e](t,n,i)||[]))}),r.length?r:void 0},ce=["enum","type","allOf","anyOf","oneOf","not"],ue=["items","maxItems","minItems","uniqueItems"],fe=["multipleOf","maximum","minimum"],de=["maxProperties","minProperties","required","properties","dependencies"],he=["maxLength","minLength","pattern"],pe=function validateAny(e,t,n){return le(ce,e,t,n)},ve=function _validate(e,t,n){var i=[];n||(n={}),n.ctx||(n.ctx={value:e,schema:t});var r=void 0,o=n.prop;if(void 0!==t){if(!O.isObject(t))throw O.err(Z+"#validate")(500,'Invalid schema at path: "'+n.path+'"');return void 0===n.path&&(n.path=[]),void 0!==n.prop&&(r=!0,n.path.push(n.prop),n.prop=void 0),t.extends&&(i=O.isFunction(t.extends.validate)?i.concat(t.extends.validate(e,n)||[]):i.concat(_validate(e,t.extends,n)||[])),void 0===e?(t.required!==!0||n.existingOnly||re(e,"a value",n,i),r&&(n.path.pop(),n.prop=o),i.length?i:void 0):(i=i.concat(pe(e,t,n)||[]),r&&(n.path.pop(),n.prop=o),i.length?i:void 0)}},ge="changing",ye="changed",me="history",be="creating",Ae="eventId",Oe="noValidate",xe="keepChangeHistory",_e="silent",Ce="validation failed",we=function makeDescriptor(e,t,i){var r={configurable:!0,enumerable:void 0===t.enumerable||!!t.enumerable},o="props."+e,a="previous."+e,s=i.getter,l=i.setter,c=i.unsetter,u=O.isBoolean(i.track)?i.track:t.track;return r.get=function(){return this._get(o)},O.isFunction(t.get)&&!function(){var e=r.get;r.get=function(){return t.get.call(this,e)}}(),r.set=function(i){var r=this,f=this[s],d=this[l],h=this[c];if(!f(Oe)){var p=t.validate(i,{path:[e]});if(p){var v=new Error(Ce);throw v.errors=p,v}}return u&&!f(be)&&!function(){var t=f(a),s=f(o),l=f(ge),c=f(ye);l||(c=[]);var u=c.indexOf(e);s!==i&&u===-1&&c.push(e),t===i&&u>=0&&c.splice(u,1),c.length||(l=!1,h(ge),h(ye),f(Ae)&&(clearTimeout(f(Ae)),h(Ae))),!l&&c.length&&(d(ye,c),d(ge,!0),d(Ae,setTimeout(function(){if(h(ye),h(Ae),h(ge),!f(_e)){var t=void 0;for(t=0;t1?n-1:0),o=1;o1?t-1:0),i=1;i1?i-1:0),o=1;o1?t-1:0),i=1;i1?i-1:0),o=1;ot?1:0)}function insertAt(e,t,n){return e.splice(t,0,n),e}function removeAt(e,t){return e.splice(t,1),e}function binarySearch(e,t,n){for(var i=0,r=e.length,o=void 0,a=void 0;i1&&void 0!==arguments[1]?arguments[1]:{};O.classCallCheck(this,Relation),n.type=this.constructor.TYPE_NAME,this.validateOptions(e,n),"object"===("undefined"==typeof e?"undefined":t(e))&&Object.defineProperty(this,"relatedMapper",{value:e}),Object.defineProperty(this,"inverse",{writable:!0}),O.fillIn(this,n)}function Record(e,t){O.classCallCheck(this,Record),Settable.call(this),e||(e={}),t||(t={});var n=this._set;n(V,!0),t.noValidate&&n(W,void 0===t.noValidate||t.noValidate),n(Y,void 0===t.keepChangeHistory?!i||i.keepChangeHistory:t.keepChangeHistory);var i=this.constructor.mapper,r=i?O.get(e,i.idAttribute):void 0;void 0!==r&&O.set(this,i.idAttribute,r),O.fillIn(this,e),n(V,!1);var o=void 0===t.validateOnSet?!i||i.validateOnSet:t.validateOnSet;n(W,!o),n(z,i?i.toJSON(e):O.plainCopy(e))}function Schema(e){var t=this;e||(e={}),O.fillIn(this,e),"object"===this.type?(this.properties=this.properties||{},O.forOwn(this.properties,function(e,n){e instanceof Schema||(t.properties[n]=new Schema(e))})):"array"!==this.type||!this.items||this.items instanceof Schema||(this.items=new Schema(this.items)),!this.extends||this.extends instanceof Schema||(this.extends=new Schema(this.extends)),["allOf","anyOf","oneOf"].forEach(function(e){t[e]&&t[e].forEach(function(n,i){n instanceof Schema||(t[e][i]=new Schema(n))})})}function Mapper(e){var t=this;if(O.classCallCheck(this,Mapper),C.call(this),e||(e={}),Object.defineProperties(this,{_adapters:{value:void 0,writable:!0},datastore:{value:void 0,writable:!0},lifecycleMethods:{value:Le},recordClass:{value:void 0,writable:!0},schema:{value:void 0,writable:!0}}),O.fillIn(this,e),O.fillIn(this,O.copy(Pe)),!this.name)throw O.err("new "+ke,"opts.name")(400,"string",this.name);this.schema&&(this.schema.type||(this.schema.type="object")),this.schema instanceof Re||(this.schema=new Re(this.schema||{type:"object"})),void 0===this.recordClass&&!function(){var e=X;t.recordClass=e.extend({constructor:function Record(){var t=function Record(n,i){O.classCallCheck(this,t),e.call(this,n,i)};return t}()})}(),this.recordClass&&(this.recordClass.mapper=this,O.isObject(this.methods)&&O.addHiddenPropsToTarget(this.recordClass.prototype,this.methods),X.prototype.isPrototypeOf(Object.create(this.recordClass.prototype))&&this.schema&&this.schema.apply&&this.applySchema&&this.schema.apply(this.recordClass.prototype))}function Container(e){O.classCallCheck(this,Container),C.call(this),e||(e={}),Object.defineProperties(this,{_adapters:{value:{}},_mappers:{value:{}},mapperClass:{value:void 0,writable:!0}}),O.fillIn(this,e),this.mapperDefaults=this.mapperDefaults||{},this.mapperClass||(this.mapperClass=Ke)}function SimpleStore(e){O.classCallCheck(this,SimpleStore),e||(e={}),O.fillIn(e,$e),Container.call(this,e),this.collectionClass=this.collectionClass||P,this._collections={},this._pendingQueries={},this._completedQueries={}}function LinkedCollection(e,t){if(O.classCallCheck(this,LinkedCollection),Object.defineProperties(this,{_added:{value:{}},datastore:{writable:!0,value:void 0}}),P.call(this,e,t),!this.datastore)throw O.err("new "+Ge,"opts.datastore")(400,"DataStore",this.datastore)}function DataStore(e){O.classCallCheck(this,DataStore),e||(e={}),O.fillIn(e,We),e.collectionClass||(e.collectionClass=Ve),He.call(this,e)}var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},i=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t=0?o=r:(a=O._getIndex(e.with,t.localField))>=0&&(o=t.localField),e.withAll)return void n.call(i,t,{});if(o){var s={};O.fillIn(s,t.getRelation()),O.fillIn(s,e),s.with=e.with.slice(),s._activeWith=s.with.splice(a,1)[0],s.with.forEach(function(e,t){e&&0===e.indexOf(o)&&e.length>=o.length&&"."===e[o.length]?s.with[t]=e.substr(o.length+1):s.with[t]=""}),n.call(i,t,s)}},_getIndex:function _getIndex(e,t){var n=-1;return e.forEach(function(e,i){return e===t?(n=i,!1):O.isObject(e)&&e.relation===t?(n=i,!1):void 0}),n},addHiddenPropsToTarget:function addHiddenPropsToTarget(e,t){var n={};Object.keys(t).forEach(function(e){var i=Object.getOwnPropertyDescriptor(t,e);i.enumerable=!1,n[e]=i}),Object.defineProperties(e,n)},areDifferent:function areDifferent(e,t,n){n||(n={});var i=O.diffObjects(e,t,n),r=Object.keys(i.added).length+Object.keys(i.removed).length+Object.keys(i.changed).length;return r>0},classCallCheck:function classCallCheck$$1(e,t){if(!(e instanceof t))throw O.err(""+t.name)(500,"Cannot call a class as a function")},copy:function copy(e,t,n,i,o,a){if(t){if(e===t)throw O.err(r+".copy")(500,"Cannot copy! Source and destination are identical.");if(n=n||[],i=i||[],O.isObject(e)){var s=n.indexOf(e);if(s!==-1)return i[s];n.push(e),i.push(t)}var c=void 0;if(O.isArray(e)){var l=void 0;for(t.length=0,l=0;l1?t-1:0),i=1;i=0&&e.splice(n,1)}},resolve:function resolve(e){return O.Promise.resolve(e)},set:function set$$1(e,t,n){if(O.isObject(t))O.forOwn(t,function(t,n){O.set(e,n,t)});else{var i=v.exec(t);i?A(e,i[1])[i[2]]=n:e[t]=n}},deepEqual:function deepEqual(e,t){if(e===t)return!0;var n=!0;if(O.isObject(e)&&O.isObject(t)){if(O.forOwn(e,function(e,i){n=n&&O.deepEqual(e,t[i])}),!n)return n;O.forOwn(t,function(t,i){n=n&&O.deepEqual(t,e[i])})}else{if(!O.isArray(e)||!O.isArray(t))return!1;e.forEach(function(e,i){if(n=n&&O.deepEqual(e,t[i]),!n)return!1})}return n},toJson:JSON.stringify,unset:function unset(e,t){for(var n=t.split("."),i=n.pop();t=n.shift();)if(e=e[t],null==e)return;e[i]=void 0}},x=function safeSetProp(e,t,n){e&&e._set?e._set("props."+t,n):O.set(e,t,n)},_=function safeSetLink(e,t,n){e&&e._set?e._set("links."+t,n):O.set(e,t,n)};Settable.extend=O.extend;var C=Settable.extend({constructor:Component});Component.extend=O.extend,O.logify(Component.prototype),O.eventify(Component.prototype,function(){return this._listeners},function(e){this._listeners=e});var w="Query",F="Index inaccessible after first operation",R={limit:"",offset:"",orderBy:"",skip:"",sort:"",where:""},k=/([.*+?^=!:${}()|[\]\/\\])/g,E=/%/g,I=/_/g,j=function escape(e){return e.replace(k,"\\$1")},S=C.extend({constructor:Query,_applyWhereFromObject:function _applyWhereFromObject(e){var t=[],n=[],i=[];return O.forOwn(e,function(e,r){O.isObject(e)||(e={"==":e}),O.forOwn(e,function(e,o){t.push(r),n.push(o),i.push(e)})}),{fields:t,ops:n,predicates:i}},_applyWhereFromArray:function _applyWhereFromArray(e){var t=this,n=[];return e.forEach(function(i,r){if(!O.isString(i)){var o=e[r-1],a=O.isArray(i)?t._applyWhereFromArray:t._applyWhereFromObject,s=a.call(t,i);"or"===o&&(s.isOr=!0),n.push(s)}}),n.isArray=!0,n},_testObjectGroup:function _testObjectGroup(e,t,n,i){var r=void 0,o=n.fields,a=n.ops,s=n.predicates,c=a.length;for(r=0;ra?1:t1?t-1:0),i=1;i":function _(e,t){return e>t},">=":function _(e,t){return e>=t},"<":function _(e,t){return e=0;i--){var r=n[i];t=r.isIndex?t.concat(r.getAll(e)):t.concat(r)}else for(var o=0;oo)break}else if(this.keys[s]>=o)break;if(i=this.values[s].isIndex?i.concat(this.values[s].getAll()):i.concat(this.values[s]),n.limit&&i.length>=n.limit+n.offset)break}}else for(var c=a.index;co)break;if(i=this.values[c].isIndex?l===r?i.concat(this.values[c]._between(O.copy(e),t.map(function(){}),n)):l===o?i.concat(this.values[c]._between(e.map(function(){}),O.copy(t),n)):i.concat(this.values[c].getAll()):i.concat(this.values[c]),n.limit&&i.length>=n.limit+n.offset)break}return n.limit?i.slice(0,n.limit+n.offset):i},peek:function peek(){return this.values.length?this.values[0].isIndex?this.values[0].peek():this.values[0]:[]},clear:function clear(){this.keys=[],this.values=[]},insertRecord:function insertRecord(e){var t=this.fieldList.map(function(t){return O.isFunction(t)?t(e)||void 0:e[t]||void 0});this.set(t,e)},removeRecord:function removeRecord(e){var t=this,n=void 0,i=void 0!==this.hashCode(e);return this.values.forEach(function(r,o){if(r.isIndex){if(r.removeRecord(e))return 0===r.keys.length&&(removeAt(t.keys,o),removeAt(t.values,o)),n=!0,!1}else{var a={};if(void 0!==t.keys[o]&&i)i&&(a=binarySearch(r,e,t.hashCode));else for(var s=r.length-1;s>=0;s--)if(r[s]===e){a={found:!0,index:s};break}if(a.found)return removeAt(r,a.index),0===r.length&&(removeAt(t.keys,o),removeAt(t.values,o)),n=!0,!1}}),n?e:void 0},updateRecord:function updateRecord(e){var t=this.removeRecord(e);void 0!==t&&this.insertRecord(e)}});var M="Collection",L={commitOnMerge:!0,emitRecordEvents:!0,idAttribute:"id",onConflict:"merge"},P=C.extend({constructor:Collection,_onRecordEvent:function _onRecordEvent(){this.emitRecordEvents&&this.emit.apply(this,arguments)},add:function add(e,t){var n=this;t||(t={}),O._(t,this),e=this.beforeAdd(e,t)||e;var i=!1,r=this.recordId();if(!O.isArray(e)){if(!O.isObject(e))throw O.err(M+"#add","records")(400,"object or array",e);e=[e],i=!0}e=e.map(function(e){var i=n.recordId(e),o=void 0===i?i:n.get(i);if(e===o)return o;if(o){var a=t.onConflict||n.onConflict;if("merge"===a)O.deepMixIn(o,e);else{if("replace"!==a)throw O.err(M+"#add","opts.onConflict")(400,"one of (merge, replace)",a,!0);O.forOwn(o,function(t,n){n!==r&&void 0===e[n]&&(o[n]=void 0)}),o.set(e)}e=o,t.commitOnMerge&&O.isFunction(e.commit)&&e.commit(),n.updateIndexes(e)}else e=n.mapper?n.mapper.createRecord(e,t):e,n.index.insertRecord(e),O.forOwn(n.indexes,function(t,n){t.insertRecord(e)}),e&&O.isFunction(e.on)&&e.on("all",n._onRecordEvent,n);return e});var o=i?e[0]:e;return t.silent||this.emit("add",o),this.afterAdd(e,t,o)||o},afterAdd:function afterAdd(){},afterRemove:function afterRemove(){},afterRemoveAll:function afterRemoveAll(){},beforeAdd:function beforeAdd(){},beforeRemove:function beforeRemove(){},beforeRemoveAll:function beforeRemoveAll(){},between:function between(e,t,n){return this.query().between(e,t,n).run()},createIndex:function createIndex(e,t,n){var i=this;O.isString(e)&&void 0===t&&(t=[e]),n||(n={}),n.hashCode||(n.hashCode=function(e){return i.recordId(e)});var r=this.indexes[e]=new Index(t,n);this.index.visitAll(r.insertRecord,r)},filter:function filter(e,t){return this.query().filter(e,t).run()},forEach:function forEach(e,t){this.index.visitAll(e,t)},get:function get(e){var t=this.query().get(e).run();return t.length?t[0]:void 0},getAll:function getAll(){var e;return(e=this.query()).getAll.apply(e,arguments).run()},getIndex:function getIndex(e){var t=e?this.indexes[e]:this.index;if(!t)throw O.err(M+"#getIndex",e)(404,"index");return t},limit:function limit(e){return this.query().limit(e).run()},map:function map(e,t){var n=[];return this.index.visitAll(function(i){n.push(e.call(t,i))}),n},mapCall:function mapCall(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i")(400,"string",r)},canFindLinkFor:function canFindLinkFor(e){var t=this.foreignKey||this.foreignKeys;return!!(t||this.localKeys&&O.get(e,this.localKeys))},linkRecord:function linkRecord(e,t){var n=this,i=this.relatedCollection,r=this.canAutoAddLinks,o=this.foreignKey,a=this.relatedCollection.unsaved();return t.map(function(t){var s=i.recordId(t);return(void 0===s&&a.indexOf(t)===-1||t!==i.get(s))&&(o&&n.setForeignKey(e,t),r&&(t=i.add(t))),t})},findExistingLinksFor:function findExistingLinksFor(e){var t=O.get(e,this.mapper.idAttribute),n=this.localKeys?O.get(e,this.localKeys):null,i=void 0;if(void 0!==t&&this.foreignKey?i=this.findExistingLinksByForeignKey(t):this.localKeys&&n?i=this.findExistingLinksByLocalKeys(n):void 0!==t&&this.foreignKeys&&(i=this.findExistingLinksByForeignKeys(t)),i&&i.length)return i},findExistingLinksByLocalKeys:function findExistingLinksByLocalKeys(e){return this.relatedCollection.filter({where:n({},this.mapper.idAttribute,{in:e})})},findExistingLinksByForeignKeys:function findExistingLinksByForeignKeys(e){return this.relatedCollection.filter({where:n({},this.foreignKeys,{contains:e})})}},{TYPE_NAME:"hasMany"}),Q=Relation.extend({findExistingLinksFor:function findExistingLinksFor(e,t){var n=O.get(t,e.idAttribute),i=this.findExistingLinksByForeignKey(n);if(i&&i.length)return i[0]}},{TYPE_NAME:"hasOne"});[q,J,Q].forEach(function(e){Relation[e.TYPE_NAME]=function(t,n){return new e(t,n)}});var B=function belongsTo(e,t){return function(n){Relation.belongsTo(e,t).assignTo(n)}; +},$=function hasMany(e,t){return function(n){Relation.hasMany(e,t).assignTo(n)}},U=function hasOne(e,t){return function(n){Relation.hasOne(e,t).assignTo(n)}},H="Record",G=function superMethod(e,t){var n=e.datastore;return n&&n[t]?function(){for(var i=arguments.length,r=Array(i),o=0;or)return ie(t.length,"length no more than "+r,i)},ae=function minLengthCommon(e,t,n,i){var r=n[e];if(t.lengthe:maximum>=e))return r?ie(e,"no more than nor equal to "+maximum,i):ie(e,"no more than "+maximum,i)},maxItems:function maxItems(e,t,n){if(O.isArray(e))return oe("maxItems",e,t,n)},maxLength:function maxLength(e,t,n){return oe("maxLength",e,t,n)},maxProperties:function maxProperties(e,t,n){if(O.isObject(e)){var maxProperties=t.maxProperties,i=Object.keys(e).length;return i>maxProperties?ie(i,"no more than "+maxProperties+" properties",n):void 0}},minimum:function minimum(e,n,i){var minimum=n.minimum,r=n.exclusiveMinimum;if(("undefined"==typeof e?"undefined":t(e))===("undefined"==typeof minimum?"undefined":t(minimum))&&!(r?e>minimum:e>=minimum))return r?ie(e,"no less than nor equal to "+minimum,i):ie(e,"no less than "+minimum,i)},minItems:function minItems(e,t,n){if(O.isArray(e))return ae("minItems",e,t,n)},minLength:function minLength(e,t,n){return ae("minLength",e,t,n)},minProperties:function minProperties(e,t,n){if(O.isObject(e)){var minProperties=t.minProperties,i=Object.keys(e).length;return i0;o--)for(r=e[o],a=o-1;a>=0;a--)if(O.deepEqual(r,e[a]))return ie(r,"no duplicates",n)}}},ce=function runOps(e,t,n,i){var r=[];return e.forEach(function(e){void 0!==n[e]&&(r=r.concat(se[e](t,n,i)||[]))}),r.length?r:void 0},le=["enum","type","allOf","anyOf","oneOf","not"],ue=["items","maxItems","minItems","uniqueItems"],fe=["multipleOf","maximum","minimum"],de=["maxProperties","minProperties","required","properties","dependencies"],he=["maxLength","minLength","pattern"],pe=function validateAny(e,t,n){return ce(le,e,t,n)},ve=function _validate(e,t,n){var i=[];n||(n={}),n.ctx||(n.ctx={value:e,schema:t});var r=void 0,o=n.prop;if(void 0!==t){if(!O.isObject(t))throw O.err(Z+"#validate")(500,'Invalid schema at path: "'+n.path+'"');return void 0===n.path&&(n.path=[]),void 0!==n.prop&&(r=!0,n.path.push(n.prop),n.prop=void 0),t.extends&&(i=O.isFunction(t.extends.validate)?i.concat(t.extends.validate(e,n)||[]):i.concat(_validate(e,t.extends,n)||[])),void 0===e?(t.required!==!0||n.existingOnly||re(e,"a value",n,i),r&&(n.path.pop(),n.prop=o),i.length?i:void 0):(i=i.concat(pe(e,t,n)||[]),r&&(n.path.pop(),n.prop=o),i.length?i:void 0)}},ge="changing",ye="changed",me="history",be="creating",Ae="eventId",Oe="noValidate",xe="keepChangeHistory",_e="silent",Ce="validation failed",we=function makeDescriptor(e,t,i){var r={configurable:!0,enumerable:void 0===t.enumerable||!!t.enumerable},o="props."+e,a="previous."+e,s=i.getter,c=i.setter,l=i.unsetter,u=O.isBoolean(i.track)?i.track:t.track;return r.get=function(){return this._get(o)},O.isFunction(t.get)&&!function(){var e=r.get;r.get=function(){return t.get.call(this,e)}}(),r.set=function(i){var r=this,f=this[s],d=this[c],h=this[l];if(!f(Oe)){var p=t.validate(i,{path:[e]});if(p){var v=new Error(Ce);throw v.errors=p,v}}return u&&!f(be)&&!function(){var t=f(a),s=f(o),c=f(ge),l=f(ye);c||(l=[]);var u=l.indexOf(e);s!==i&&u===-1&&l.push(e),t===i&&u>=0&&l.splice(u,1),l.length||(c=!1,h(ge),h(ye),f(Ae)&&(clearTimeout(f(Ae)),h(Ae))),!c&&l.length&&(d(ye,l),d(ge,!0),d(Ae,setTimeout(function(){if(h(ye),h(Ae),h(ge),!f(_e)){var t=void 0;for(t=0;t1?n-1:0),o=1;o1?t-1:0),i=1;i1?i-1:0),o=1;o1?t-1:0),i=1;i1?i-1:0),o=1;o",">=","<","<=","isectEmpty","isectNotEmpty","in","_in","notIn","contains","notContains","pos","dataLocation","newIndex","results","order","_i","visitAll","cb","leftInclusive","rightInclusive","_between","leftKey","rightKey","_i2","currKey","peek","clear","insertRecord","removeRecord","isUnique","j","updateRecord","DOMAIN$1","commitOnMerge","onConflict","_onRecordEvent","beforeAdd","singular","commit","updateIndexes","createRecord","afterAdd","afterRemove","afterRemoveAll","beforeRemove","beforeRemoveAll","createIndex","instances","_query","prune","removeAll","unsaved","Ctor","reduce","initialValue","idOrRecord","silent","queryOrRecords","updateIndex","belongsToType","hasManyType","hasOneType","DOMAIN$6","canAutoAddLinks","relatedCollection","getCollection","related","DOMAIN_ERR","foreignKey","localKey","assignTo","relationFields","canFindLinkFor","getForeignKey","setForeignKey","relatedRecord","_setForeignKey","relatedRecords","getLocalField","setLocalField","relatedData","getInverse","inverse","findInverseRelation","isInversedTo","addLinkedRecords","linkRecord","isEmptyLinks","findExistingLinksFor","removeLinkedRecords","relatedId","findExistingLinksByForeignKey","BelongsToRelation","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","ids","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","HasOneRelation","RelationType","belongsTo$1","belongsTo","hasMany$1","hasMany","hasOne$1","hasOne","DOMAIN$5","superMethod","store","bind","_mapper","afterLoadRelations","beforeLoadRelations","changeHistory","changes","destroy","hasChanges","quickHasChanges","isNew","isValid","validate","removeInverseRelation","currentParent","inverseDef","children","child","setupInverseRelation","loadRelations","relations","adapter","getAdapterName","then","tasks","task","raw","load","previous","revert","_this4","preserve","save","_this5","postProcess","changesOnly","_this6","_ret","v","DOMAIN$7","types","boolean","integer","null","number","string","segmentToString","segment","str","makePath","segments","makeError","actual","expected","addError","errors","maxLengthCommon","keyword","max","minLengthCommon","validationKeywords","allOf","allErrors","_schema","_validate","anyOf","validated","dependencies","enum","_enum","possibleValues","join","checkingTuple","maximum","exclusiveMaximum","maxItems","maxLength","maxProperties","minimum","exclusiveMinimum","minItems","minLength","minProperties","multipleOf","not","oneOf","additionalProperties","toValidate","patternProperties","undef","origProp","required","existingOnly","prevProp","validType","_type","validator","typeGroupValidators","uniqueItems","runOps","ANY_OPS","ARRAY_OPS","NUMERIC_OPS","OBJECT_OPS","STRING_OPS","validateAny","ctx","shouldPop","changingPath","changedPath","changeHistoryPath","creatingPath$1","eventIdPath","noValidatePath$1","keepChangeHistoryPath$1","silentPath","validationFailureMsg","makeDescriptor","keyPath","unsetter","track","originalGet","error","current","changing","clearTimeout","setTimeout","changeRecord","timestamp","originalSet","numeric","applyDefaults","hasSet","orig","_ret4","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","count","defaults","destroyAll","find","findAll","sum","update","adapterArgs","beforeAssign","updateAll","updateMany","defaultAdapter","afterCount","afterCreate","afterCreateMany","afterDestroy","afterDestroyAll","afterFind","afterFindAll","afterSum","afterUpdate","afterUpdateAll","afterUpdateMany","beforeCreate","beforeCreateMany","beforeCount","beforeDestroy","beforeDestroyAll","beforeFind","beforeFindAll","beforeSum","beforeUpdate","beforeUpdateAll","beforeUpdateMany","_end","_data","wrap","crud","originalRecord","belongsToRelationData","relationData","relatedIdAttribute","createMany","getAdapter","pass","createdRecordData","_result","createInstance","originalRecords","_records","createdRecordsData","belongsToData","RecordCtor","is","method","config","upper","before","after","_getAdapter","getAdapters","registerAdapter","default","_this7","strict","_opts","_record","foundErrors","defineRelations","_this8","_name","getMapperByName","getMapper","DOMAIN$3","proxiedMapperMethods","_onMapperEvent","as","original","defineMapper","defineResource","warn","_getMapper","DOMAIN$9","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","usePendingFind","usePendingFindAll","props$2","addToCache","_onCollectionEvent","cachedFind","cachedFindAll","cacheFind","cacheFindAll","hash","self","indexed","hashQuery","eject","ejectAll","pendingQuery","promise","force","_this9","inject","removeRelated","_this10","_this11","_this12","_this13","_getCollection","_addMeta","_clearMeta","event","unlinkOnDestroy","props$1","updateOpts","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","parent","origGet","origSet","DataStore$1","version","full","major","minor","patch"],"mappings":"CAAC,SAAUA,EAAQC,GACE,gBAAZC,UAA0C,mBAAXC,QAAyBF,EAAQC,SACrD,kBAAXE,SAAyBA,OAAOC,IAAMD,OAAO,WAAY,WAAYH,GAC3EA,EAASD,EAAOM,OAASN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Q0G,OAAS2B,GACjBrI,EAAQ2B,MAAQwC,EAChBnE,EAAQkF,OAASqC,EACjBvH,EAAQ8F,OAASuB,GACjBrH,EAAQM,SAAWA,SACnBN,EAAQsI,YAAca,GACtBnJ,EAAQa,MAAQA,EAChBb,EAAQsf,UAAYD,EACpBrf,EAAQwf,QAAUD,EAClBvf,EAAQ0f,OAASD,EACjBzf,EAAQ0c,cAAgBA,EACxB1c,EAAQ2c,YAAcA,EACtB3c,EAAQ4c,WAAaA,EAErBpc,OAAOiB,eAAezB,EAAS,cAAgBW,OAAO","file":"dist/js-data.min.js"} \ No newline at end of file +{"version":3,"sources":["dist/js-data.js"],"names":["global","factory","exports","module","define","amd","JSData","this","Settable","_props","Object","defineProperties","_get","value","key","utils","get","_set","_value","set","_unset","unset","Component","opts","call","debug","hasOwnProperty","defineProperty","writable","Query","collection","classCallCheck","data","sort","a","b","hashCode","undefined","insertAt","array","index","splice","removeAt","binarySearch","field","lo","hi","length","compared","mid","found","Index","fieldList","isArray","Error","fieldGetter","isIndex","keys","values","Collection","records","Component$1","isString","idAttribute","mapper","queryClass","fillIn","copy","COLLECTION_DEFAULTS","Query$1","recordId","obj","indexes","isObject","add","Relation","relatedMapper","options","arguments","type","constructor","TYPE_NAME","validateOptions","_typeof","Record","props","creatingPath","noValidate","noValidatePath","keepChangeHistoryPath","keepChangeHistory","id","validateOnSet","previousPath","toJSON","plainCopy","Schema","definition","_this2","properties","forOwn","_definition","prop","items","extends","forEach","validationKeyword","i","Mapper","_adapters","datastore","lifecycleMethods","LIFECYCLE_METHODS","recordClass","schema","MAPPER_DEFAULTS","name","err","DOMAIN$4","Schema$1","superClass","Record$1","extend","subClass","methods","addHiddenPropsToTarget","prototype","isPrototypeOf","create","apply","applySchema","Container","_mappers","mapperClass","mapperDefaults","Mapper$1","SimpleStore","SIMPLESTORE_DEFAULTS","collectionClass","Collection$1","_collections","_pendingQueries","_completedQueries","LinkedCollection","_added","DOMAIN$9","DataStore","DATASTORE_DEFAULTS","LinkedCollection$1","SimpleStore$1","Symbol","iterator","enumerable","configurable","toConsumableArray","arr","Array","arr2","from","DOMAIN","INFINITY","MAX_INTEGER","BOOL_TAG","DATE_TAG","FUNC_TAG","NUMBER_TAG","OBJECT_TAG","REGEXP_TAG","STRING_TAG","objToString","toString","PATH","ERRORS","400","_","404","toInteger","sign","remainder","toStr","isPlainObject","mkdirP","object","path","parts","split","Promise","dest","src","isFunction","indexOf","_forRelation","def","fn","thisArg","relationName","relation","containedName","with","_getIndex","localField","withAll","optsCopy","getRelation","slice","_activeWith","substr","list","_relation","target","map","propName","descriptor","getOwnPropertyDescriptor","areDifferent","newObject","oldObject","diff","diffObjects","diffCount","added","removed","changed","classCallCheck$$1","instance","ctor","to","stackFrom","stackTo","blacklist","plain","push","result","isBlacklisted","isDate","Date","getTime","isRegExp","RegExp","source","match","lastIndex","getPrototypeOf","deepFillIn","existing","deepMixIn","equalsFn","ignore","deepEqual","newKeys","filter","oldKeys","oldValue","newValue","equal","domain","code","prefix","message","eventify","getter","setter","_events","emit","events","_len","args","_key","shift","listeners","f","c","all","unshift","off","func","on","classProps","_subClass","_len2","_key2","setPrototypeOf","strictEs6Class","__proto__","findIndex","record","forEachRelation","relationList","len","fromJson","json","JSON","parse","get$$1","last","pop","getSuper","isCtor","__super__","intersection","array1","array2","item","matches","test","isBoolean","isInteger","isNull","isNumber","isSorN","isUndefined","logify","dbg","log","_len3","_key3","concat","level","_len4","_key4","toUpperCase","console","_console","_console2","noDupeAdd","omit","pick","reduce","reject","remove","resolve","set$$1","_path","exec","_equal","toJson","stringify","safeSetProp","safeSetLink","_listeners","DOMAIN$2","INDEX_ERR","reserved","limit","offset","orderBy","skip","where","escapeRegExp","percentRegExp","underscoreRegExp","escape","pattern","replace","_applyWhereFromObject","fields","ops","predicates","clause","==","expr","op","_applyWhereFromArray","_this","groups","_where","prev","parser","group","isOr","_testObjectGroup","keep","first","charAt","evaluate","_testArrayGroup","between","leftKeys","rightKeys","getIndex","compare","cA","cB","temp","predicate","like","query","getData","forEachFn","keyList","getAll","_this3","flags","num","Math","min","mapFn","mapCall","funcName","run","=","===","!=","!==",">",">=","<","<=","isectEmpty","isectNotEmpty","in","_in","notIn","contains","notContains","pos","dataLocation","newIndex","results","order","_i","visitAll","cb","leftInclusive","rightInclusive","_between","leftKey","rightKey","_i2","currKey","peek","clear","insertRecord","removeRecord","isUnique","j","updateRecord","DOMAIN$1","commitOnMerge","emitRecordEvents","onConflict","_onRecordEvent","beforeAdd","singular","commit","updateIndexes","createRecord","silent","afterAdd","afterRemove","afterRemoveAll","beforeRemove","beforeRemoveAll","createIndex","instances","_query","prune","removeAll","unsaved","Ctor","initialValue","idOrRecord","queryOrRecords","updateIndex","belongsToType","hasManyType","hasOneType","DOMAIN$6","canAutoAddLinks","relatedCollection","getCollection","related","DOMAIN_ERR","foreignKey","localKey","assignTo","relationFields","canFindLinkFor","getForeignKey","setForeignKey","relatedRecord","_setForeignKey","relatedRecords","getLocalField","setLocalField","relatedData","getInverse","inverse","findInverseRelation","isInversedTo","addLinkedRecords","linkRecord","isEmptyLinks","findExistingLinksFor","removeLinkedRecords","relatedId","findExistingLinksByForeignKey","BelongsToRelation","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","ids","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","HasOneRelation","RelationType","belongsTo","hasMany","hasOne","DOMAIN$5","superMethod","store","bind","_mapper","afterLoadRelations","beforeLoadRelations","changeHistory","changes","destroy","hasChanges","quickHasChanges","isNew","isValid","validate","removeInverseRelation","currentParent","inverseDef","children","child","setupInverseRelation","loadRelations","relations","adapter","getAdapterName","then","tasks","task","raw","load","previous","revert","_this4","preserve","save","_this5","postProcess","changesOnly","_this6","_ret","v","DOMAIN$7","types","boolean","integer","null","number","string","segmentToString","segment","str","makePath","segments","makeError","actual","expected","addError","errors","maxLengthCommon","keyword","max","minLengthCommon","validationKeywords","allOf","allErrors","_schema","_validate","anyOf","validated","dependencies","enum","_enum","possibleValues","join","checkingTuple","maximum","exclusiveMaximum","maxItems","maxLength","maxProperties","minimum","exclusiveMinimum","minItems","minLength","minProperties","multipleOf","not","oneOf","additionalProperties","patternProperties","toValidate","undef","origProp","required","existingOnly","prevProp","validType","_type","validator","typeGroupValidators","uniqueItems","runOps","ANY_OPS","ARRAY_OPS","NUMERIC_OPS","OBJECT_OPS","STRING_OPS","validateAny","ctx","shouldPop","changingPath","changedPath","changeHistoryPath","creatingPath$1","eventIdPath","noValidatePath$1","keepChangeHistoryPath$1","silentPath","validationFailureMsg","makeDescriptor","keyPath","unsetter","track","originalGet","error","current","changing","clearTimeout","setTimeout","changeRecord","timestamp","originalSet","numeric","applyDefaults","hasSet","orig","_ret4","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","count","defaults","destroyAll","find","findAll","sum","update","adapterArgs","beforeAssign","updateAll","updateMany","defaultAdapter","afterCount","afterCreate","afterCreateMany","afterDestroy","afterDestroyAll","afterFind","afterFindAll","afterSum","afterUpdate","afterUpdateAll","afterUpdateMany","beforeCreate","beforeCreateMany","beforeCount","beforeDestroy","beforeDestroyAll","beforeFind","beforeFindAll","beforeSum","beforeUpdate","beforeUpdateAll","beforeUpdateMany","_end","_data","wrap","belongsTo$$1","crud","originalRecord","belongsToRelationData","relationData","relatedIdAttribute","createMany","getAdapter","pass","createdRecordData","_result","createInstance","originalRecords","_records","createdRecordsData","belongsToData","RecordCtor","is","method","config","upper","before","after","_getAdapter","getAdapters","hasMany$$1","hasOne$$1","registerAdapter","default","_this7","strict","_opts","_record","foundErrors","defineRelations","_this8","_name","getMapperByName","getMapper","DOMAIN$3","proxiedMapperMethods","_onMapperEvent","as","original","defineMapper","defineResource","warn","_getMapper","DOMAIN$8","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","usePendingFind","usePendingFindAll","props$2","addToCache","_onCollectionEvent","cachedFind","cachedFindAll","cacheFind","cacheFindAll","hash","self","indexed","hashQuery","eject","ejectAll","pendingQuery","promise","force","_this9","inject","removeRelated","_this10","_this11","_this12","_this13","_getCollection","_addMeta","_clearMeta","event","unlinkOnDestroy","props$1","updateOpts","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","parent","origGet","origSet","DataStore$1","version","full","major","minor","patch"],"mappings":"CAAC,SAAUA,EAAQC,GACC,gBAAZC,UAA0C,mBAAXC,QAAyBF,EAAQC,SACrD,kBAAXE,SAAyBA,OAAOC,IAAMD,OAAO,WAAY,WAAYH,GAC3EA,EAASD,EAAOM,OAASN,EAAOM,aAChCC,KAAM,SAAWL,GAAW,YAyuD9B,SAASM,YACP,GAAIC,KACJC,QAAOC,iBAAiBJ,MAWtBK,MACEC,MAAO,QAASA,OAAMC,GACpB,MAAOC,GAAMC,IAAIP,EAAQK,KAe7BG,MACEJ,MAAO,QAASA,OAAMC,EAAKI,GACzB,MAAOH,GAAMI,IAAIV,EAAQK,EAAKI,KAalCE,QACEP,MAAO,QAASA,OAAMC,GACpB,MAAOC,GAAMM,MAAMZ,EAAQK,OAiFnC,QAASQ,WAAUC,GACjBf,SAASgB,KAAKjB,MACdgB,IAASA,MAwBThB,KAAKkB,QAAQF,EAAKG,eAAe,YAAaH,EAAKE,MAWnDf,OAAOiB,eAAepB,KAAM,cAAgBM,SAAWe,UAAU,IA6NnE,QAASC,OAAMC,GACbf,EAAMgB,eAAexB,KAAMsB,OAS3BtB,KAAKuB,WAAaA,EASlBvB,KAAKyB,KAAO,KAoiCd,QAASC,MAAKC,EAAGC,EAAGC,GAIlB,MAAIF,KAAMC,EACD,GAELC,IACFF,EAAIE,EAASF,GACbC,EAAIC,EAASD,IAEL,OAAND,GAAoB,OAANC,GAAoBE,SAANH,GAAyBG,SAANF,GAC1C,EAGC,OAAND,GAAoBG,SAANH,GACT,EAGC,OAANC,GAAoBE,SAANF,EACT,EAGLD,EAAIC,GACC,EAGLD,EAAIC,EACC,EAGF,GAGT,QAASG,UAASC,EAAOC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