From 49d398a3fea2b4a16cb156fb2772cca579739c3b Mon Sep 17 00:00:00 2001 From: Cory Date: Tue, 3 Sep 2019 17:47:10 -0700 Subject: [PATCH] chore(): release 3.0.8 --- CHANGELOG.md | 5 +++++ dist/js-data.es2015.js | 12 +++++------- dist/js-data.es2015.js.map | 2 +- dist/js-data.js | 12 +++++------- dist/js-data.js.map | 2 +- dist/js-data.min.js | 4 ++-- dist/js-data.min.js.map | 2 +- package.json | 2 +- src/Mapper.js | 6 ++---- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90142c93..34193f35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +##### 3.0.8 - 3 September 2019 + +###### Bug fixes +- Fix beforeCreate & beforeCreateMany lifecycle hook re-assignment of props + ##### 3.0.7 - 3 September 2019 ###### Bug fixes diff --git a/dist/js-data.es2015.js b/dist/js-data.es2015.js index a2849562..9668a8b8 100644 --- a/dist/js-data.es2015.js +++ b/dist/js-data.es2015.js @@ -1,6 +1,6 @@ /*! * js-data -* @version 3.0.6 - Homepage +* @version 3.0.7 - Homepage * @author js-data project authors * @copyright (c) 2014-2016 js-data project authors * @license MIT @@ -8019,7 +8019,6 @@ var Mapper$1 = Component$1.extend({ // Default values for arguments props || (props = {}); opts || (opts = {}); - var originalRecord = props; var parentRelationMap = {}; var adapterResponse = {}; @@ -8049,7 +8048,7 @@ var Mapper$1 = Component$1.extend({ originalProps: props }); }).then(function (createdProps) { - return _this2._commitChanges(originalRecord, createdProps); + return _this2._commitChanges(props, createdProps); }).then(function (record) { if (opts.raw) { adapterResponse.data = record; @@ -8264,7 +8263,6 @@ var Mapper$1 = Component$1.extend({ // Default values for arguments records || (records = []); opts || (opts = {}); - var originalRecords = records; var adapterResponse = void 0; // Fill in "opts" with the Mapper's configuration @@ -8342,7 +8340,7 @@ var Mapper$1 = Component$1.extend({ } }); return utils.Promise.all(tasks).then(function () { - return _this4._commitChanges(originalRecords, createdRecordsData); + return _this4._commitChanges(records, createdRecordsData); }); }); }).then(function (records) { @@ -13691,10 +13689,10 @@ var DataStore$1 = SimpleStore$1.extend(props$2); * @type {Object} */ var version = { - full: '3.0.6', + full: '3.0.7', major: 3, minor: 0, - patch: 6 + patch: 7 }; 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 }; diff --git a/dist/js-data.es2015.js.map b/dist/js-data.es2015.js.map index bb796057..9a04ed8d 100644 --- a/dist/js-data.es2015.js.map +++ b/dist/js-data.es2015.js.map @@ -1 +1 @@ -{"version":3,"file":"js-data.es2015.js","sources":["../src/utils.js","../src/Settable.js","../src/Component.js","../src/Query.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","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.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.7976931348623157e308\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' () {\n return `expected: ${arguments[0]}, found: ${\n arguments[2] ? arguments[1] : typeof arguments[1]\n }`\n },\n '404' () {\n return `${arguments[0]} not found`\n }\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 (\n key &&\n dest[key] === undefined &&\n !utils.isFunction(value) &&\n key.indexOf('_') !== 0\n ) {\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 (\n relation &&\n relation.indexOf(containedName) === 0 &&\n relation.length >= containedName.length &&\n relation[containedName.length] === '.'\n ) {\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 =\n 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(\n from,\n Object.create(Object.getPrototypeOf(from)),\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(\n 500,\n 'Cannot copy! Source and destination are identical.'\n )\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(\n from[i],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n from[key],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n null,\n Array.prototype.slice.call(arguments, 1)\n )\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 () {\n return _events\n }\n setter = function (value) {\n _events = value\n }\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 if (fn.call(thisArg, obj[keys[i]], keys[i], obj) === false) {\n break\n }\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())) {\n // eslint-disable-line\n object = object[prop]\n if (object == null) {\n // 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 array1 = Array.isArray(array1) ? array1 : [array1]\n array2 = Array.isArray(array2) ? array2 : [array2]\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 (\n (toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) ||\n blacklist[i] === prop\n ) {\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 (\n type === 'number' ||\n (value && type === 'object' && toStr(value) === NUMBER_TAG)\n )\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 (\n typeof value === 'string' ||\n (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n )\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 ||\n 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.isArray(a) && utils.isArray(b)) {\n if (a.length !== b.length) {\n return false\n }\n for (let i = a.length; i--;) {\n if (!utils.deepEqual(a[i], b[i])) {\n // Exit loop early\n return false\n }\n }\n } else if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n if (!(_equal = utils.deepEqual(value, b[key]))) {\n // Exit loop early\n return false\n }\n })\n if (_equal) {\n utils.forOwn(b, function (value, key) {\n if (!(_equal = utils.deepEqual(value, a[key]))) {\n // Exit loop early\n return false\n }\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())) {\n // eslint-disable-line\n object = object[path]\n if (object == null) {\n // 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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @private\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 * const JSData = require('js-data');\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');\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 Query intro\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between(18, 30, { index: 'age' })\n * .run();\n * console.log(filteredUsers);\n *\n * @example Same as above.\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between([18], [30], { index: 'age' })\n * .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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * })\n * .run();\n * console.log(results);\n *\n * @example Use a custom filter function\n * const posts = query\n * .filter(function (post) {\n * return post.isReady();\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts); // [...]\n * });\n *\n * @example Empty \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const posts = store.filter('post');\n * console.log(posts); // [...]\n *\n * @example Complex \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * const PAGE_SIZE = 2;\n * let currentPage = 3;\n *\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 * const results = 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 * console.log(results);\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const PAGE_SIZE = 10;\n * let currentPage = 1;\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5;\n * let currentPage = 2;\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n *\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5\n * let currentPage = 2\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * });\n * console.log(results)\n *\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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users);\n * const ages = store\n * .query('user')\n * .map(function (user) {\n * return user.age;\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n *\n * @example Variant 2\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n * @example Variant 3\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({ status: 'published' })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Variant 4\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Multiple operators\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\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","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) && this !== 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 ensureLinkedDataHasProperType (props, opts) {\n const relatedMapper = this.getRelation()\n const relationData = this.getLocalField(props)\n\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n\n if (relationData && !relatedMapper.is(relationData)) {\n utils.set(props, this.localField, relatedMapper.createRecord(relationData, opts))\n }\n },\n\n isRequiresParentId () {\n return false\n },\n\n isRequiresChildId () {\n return false\n },\n\n createChildRecord (props, relationData, opts) {\n this.setForeignKey(props, relationData)\n\n return this.createLinked(relationData, opts).then((result) => {\n this.setLocalField(props, result)\n })\n },\n\n createLinked (props, opts) {\n const create = utils.isArray(props) ? 'createMany' : 'create'\n\n return this.getRelation()[create](props, opts)\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 isRequiresParentId () {\n return true\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n\n return this.createLinked(relationData, opts).then((record) => {\n this.setForeignKey(props, record)\n })\n },\n\n createChildRecord () {\n throw new Error('\"BelongsTo\" relation does not support child creation as it cannot have children.')\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.relatedCollection.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 isRequiresParentId () {\n return !!this.localKeys && this.localKeys.length > 0\n },\n\n isRequiresChildId () {\n return !!this.foreignKey\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n const foreignIdField = this.getRelation().idAttribute\n\n return this.createLinked(relationData, opts).then((records) => {\n utils.set(props, this.localKeys, records.map((record) => utils.get(record, foreignIdField)))\n })\n },\n\n createLinked (props, opts) {\n return this.getRelation().createMany(props, opts)\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 isRequiresChildId () {\n return true\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @param {boolean} [opts.validateOnSet=true] Whether to enable setter\n * validation on properties after the Record has been initialized.\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 const mapper = this.constructor.mapper\n\n _set(creatingPath, true)\n _set(noValidatePath, !!opts.noValidate)\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\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 if (opts.validateOnSet !== undefined) {\n _set(noValidatePath, !opts.validateOnSet)\n } else if (mapper && mapper.validateOnSet !== undefined) {\n _set(noValidatePath, !mapper.validateOnSet)\n } else {\n _set(noValidatePath, false)\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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('changing', false)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 *\n * @method Record#toJSON\n * @param {object} [opts] Configuration options.\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, (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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 creatingPath,\n noValidatePath,\n keepChangeHistoryPath,\n previousPath\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 * const JSData = require('js-data');\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","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 Record from './Record'\nimport Index from '../lib/mindex/index'\n\nconst { noValidatePath } = Record\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 * skip\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 * Skip:\n *\n * Ignore new record, keep existing record.\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');\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 * const JSData = require('js-data');\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 {boolean} [opts.noValidate] See {@link Record#noValidate}.\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')(\n 400,\n 'object or array',\n records\n )\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 (\n onConflict !== 'merge' &&\n onConflict !== 'replace' &&\n onConflict !== 'skip'\n ) {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(\n 400,\n 'one of (merge, replace, skip)',\n onConflict,\n true\n )\n }\n const existingNoValidate = existing._get(noValidatePath)\n if (opts.noValidate) {\n // Disable validation\n existing._set(noValidatePath, true)\n }\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 if(onConflict === 'skip'){ do nothing }\n\n if (opts.noValidate) {\n // Restore previous `noValidate` value\n existing._set(noValidatePath, existingNoValidate)\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()\n .between(leftKeys, rightKeys, opts)\n .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 * const JSData = require('js-data');\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((post) => post.id % 2 === 0);\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()\n .filter(query, thisArg)\n .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 =\n id === undefined\n ? []\n : this.query()\n .get(id)\n .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()\n .getAll(...args)\n .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()\n .limit(num)\n .run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map((user) => user.name);\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((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 }\n if (!opts.silent) {\n this.emit('remove', record)\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)\n ? queryOrRecords.slice()\n : 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()\n .skip(num)\n .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 * const JSData = require('js-data');\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'\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 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\n/**\n * Validation keywords validated for any type:\n *\n * - `enum`\n * - `type`\n * - `allOf`\n * - `anyOf`\n * - `oneOf`\n * - `not`\n *\n * @name Schema.ANY_OPS\n * @type {string[]}\n */\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\n\n/**\n * Validation keywords validated for array types:\n *\n * - `items`\n * - `maxItems`\n * - `minItems`\n * - `uniqueItems`\n *\n * @name Schema.ARRAY_OPS\n * @type {string[]}\n */\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\n\n/**\n * Validation keywords validated for numeric (number and integer) types:\n *\n * - `multipleOf`\n * - `maximum`\n * - `minimum`\n *\n * @name Schema.NUMERIC_OPS\n * @type {string[]}\n */\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\n\n/**\n * Validation keywords validated for object types:\n *\n * - `maxProperties`\n * - `minProperties`\n * - `required`\n * - `properties`\n * - `dependencies`\n *\n * @name Schema.OBJECT_OPS\n * @type {string[]}\n */\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n\n/**\n * Validation keywords validated for string types:\n *\n * - `maxLength`\n * - `minLength`\n * - `pattern`\n *\n * @name Schema.STRING_OPS\n * @type {string[]}\n */\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 * 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 * const JSData = require('js-data');\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#apply\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, (schema, prop) => {\n Object.defineProperty(\n target,\n prop,\n this.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 * Assemble a property descriptor for tracking and validating changes to\n * a property according to the given schema. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @name Schema#makeDescriptor\n * @method\n * @param {string} prop The property name.\n * @param {(Schema|object)} schema The schema for the property.\n * @param {object} [opts] Optional configuration.\n * @param {function} [opts.getter] Custom getter function.\n * @param {function} [opts.setter] Custom setter function.\n * @param {function} [opts.track] Whether to track changes.\n * @returns {object} A property descriptor for the given schema.\n */\n makeDescriptor (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 * 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 (value === undefined) {\n return\n }\n if (this.type === 'object') {\n let copy = {}\n const properties = this.properties\n if (properties) {\n utils.forOwn(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 // Conditionally copy properties not defined in \"properties\"\n if (this.additionalProperties) {\n for (var key in value) {\n if (!properties[key]) {\n copy[key] = utils.plainCopy(value[key])\n }\n }\n }\n return copy\n } else if (this.type === 'array') {\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 * const JSData = require('js-data');\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 *\n * @example\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\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 * const JSData = require('js-data');\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 if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\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 // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n const originalRecord = props\n let parentRelationMap = {}\n let adapterResponse = {}\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n opts.op = 'beforeCreate'\n return this._runHook(opts.op, props, opts).then((_value) => {\n // Allow for re-assignment from lifecycle hook\n props = _value !== undefined ? _value : props\n opts.with || (opts.with = [])\n return this._createParentRecordIfRequired(props, opts)\n }).then((relationMap) => {\n parentRelationMap = relationMap\n }).then(() => {\n opts.op = 'create'\n return this._invokeAdapterMethod(opts.op, props, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdProps = opts.raw ? adapterResponse.data : adapterResponse\n\n return this._createOrAssignChildRecordIfRequired(createdProps, {\n opts,\n parentRelationMap,\n originalProps: props\n })\n }).then((createdProps) => {\n return this._commitChanges(originalRecord, createdProps)\n }).then((record) => {\n if (opts.raw) {\n adapterResponse.data = record\n } else {\n adapterResponse = record\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreate'\n return this._runHook(opts.op, props, opts, result)\n })\n },\n\n _commitChanges (recordOrRecords, newValues) {\n if (utils.isArray(recordOrRecords)) {\n return recordOrRecords.map((record, i) => this._commitChanges(record, newValues[i]))\n }\n\n utils.set(recordOrRecords, newValues, { silent: true })\n\n if (utils.isFunction(recordOrRecords.commit)) {\n recordOrRecords.commit()\n }\n\n return recordOrRecords\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 * Creates parent record for relation types like BelongsTo or HasMany with localKeys\n * in order to satisfy foreignKey dependency (so called child records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} opts See {@link Mapper#create}.\n * @returns {Object} cached parent records map\n * @see Mapper#create\n * @since 3.0.0\n */\n _createParentRecordIfRequired (props, opts) {\n const tasks = []\n const relations = []\n\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n if (!def.isRequiresParentId() || !def.getLocalField(props)) {\n return\n }\n\n optsCopy.raw = false\n relations.push(def)\n tasks.push(def.createParentRecord(props, optsCopy))\n })\n\n return utils.Promise.all(tasks).then(records => {\n return relations.reduce((map, relation, index) => {\n relation.setLocalField(map, records[index])\n return map\n }, {})\n })\n },\n\n /**\n * Creates child record for relation types like HasOne or HasMany with foreignKey\n * in order to satisfy foreignKey dependency (so called parent records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} context contains collected information.\n * @param {object} context.opts See {@link Mapper#create}.\n * @param {object} context.parentRelationMap contains parent records map\n * @param {object} context.originalProps contains data passed into {@link Mapper#create} method\n * @return {Promise} updated props\n * @see Mapper#create\n * @since 3.0.0\n */\n _createOrAssignChildRecordIfRequired (props, context) {\n const tasks = []\n\n utils.forEachRelation(this, context.opts, (def, optsCopy) => {\n const relationData = def.getLocalField(context.originalProps)\n\n if (!relationData) {\n return\n }\n\n optsCopy.raw = false\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.isRequiresChildId()) {\n tasks.push(def.createChildRecord(props, relationData, optsCopy))\n } else if (def.isRequiresParentId()) {\n const parent = def.getLocalField(context.parentRelationMap)\n\n if (parent) {\n def.setLocalField(props, parent)\n }\n }\n })\n\n return utils.Promise.all(tasks)\n .then(() => props)\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 // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n const originalRecords = records\n let adapterResponse\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n opts.op = 'beforeCreateMany'\n return this._runHook(opts.op, records, opts).then((_recordValues) => {\n // Allow for re-assignment from lifecycle hook\n records = _recordValues !== undefined ? _recordValues : records\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(Boolean)\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 optsCopy.raw = false\n tasks.push(def.createLinked(relationData, optsCopy).then((relatedRecords) => {\n records.forEach((record, i) => def.setForeignKey(record, relatedRecords[i]))\n }).then((relatedRecords) => {\n def.setLocalField(belongsToRelationData, relatedRecords)\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n opts.op = 'createMany'\n return this._invokeAdapterMethod(opts.op, records, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdRecordsData = opts.raw ? adapterResponse.data : adapterResponse\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(Boolean)\n if (relationData.length !== records.length) {\n return\n }\n\n optsCopy.raw = false\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((relatedData) => {\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 return this._commitChanges(originalRecords, createdRecordsData)\n })\n })\n }).then((records) => {\n if (opts.raw) {\n adapterResponse.data = records\n } else {\n adapterResponse = records\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreateMany'\n return this._runHook(opts.op, records, opts, result)\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\n if (this.relationList) {\n this.relationList.forEach(function (def) {\n def.ensureLinkedDataHasProperType(props, opts)\n })\n }\n const RecordCtor = this.recordClass\n\n return (!RecordCtor || props instanceof RecordCtor) ? props : new RecordCtor(props, opts)\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 // force noValidate on find/findAll\n const noValidate = /find/.test(op) || opts.noValidate\n const _opts = Object.assign({}, opts, { noValidate })\n\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 _runHook (hookName, ...hookArgs) {\n const defaultValueIndex = hookName.indexOf('after') === 0 ? hookArgs.length - 1 : 0\n\n return utils.resolve(this[hookName](...hookArgs))\n .then((overridenResult) => overridenResult === undefined ? hookArgs[defaultValueIndex] : overridenResult)\n },\n\n _invokeAdapterMethod (method, propsOrRecords, opts) {\n const conversionOptions = { with: opts.pass || [] }\n let object\n\n this.dbg(opts.op, propsOrRecords, opts)\n\n if (utils.isArray(propsOrRecords)) {\n object = propsOrRecords.map(record => this.toJSON(record, conversionOptions))\n } else {\n object = this.toJSON(propsOrRecords, conversionOptions)\n }\n\n return this.getAdapter(opts.adapter)[method](this, object, opts)\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 * // \"foo\" is stripped by toJSON()\n * console.log(PersonMapper.toJSON(person)); // {\"id\":1,\"name\":\"John\"}\n *\n * const PersonRelaxedMapper = new Mapper({\n * name: 'personRelaxed',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = PersonRelaxedMapper.createRecord({ id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(PersonRelaxedMapper.toJSON(person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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 {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\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n } else {\n for (var key in record) {\n if (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 if (!schema) {\n return\n }\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\n return errors.some(Boolean) ? errors : 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 * const JSData = require('js-data');\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 * // \"foo\" is stripped by toJSON()\n * console.log(store.toJSON('person', person)); // {\"id\":1,\"name\":\"John\"}\n *\n * store.defineMapper('personRelaxed', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = store.createRecord('personRelaxed', { id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(store.toJSON('personRelaxed', person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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');\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');\n * const { Container, Mapper } = 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');\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');\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');\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');\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');\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');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 let collectionOpts = {\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 if (opts && ('onConflict' in opts)) {\n collectionOpts.onConflict = opts.onConflict\n }\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, collectionOpts) // eslint-disable-line\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\n if (opts.force || !item) {\n const promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts)\n return promise\n .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 }\n\n return utils.resolve(item)\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\n if (opts.force || !items) {\n const promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts)\n return promise\n .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 }\n\n return utils.resolve(items)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 if (!query || !Object.keys(query).length) {\n this._completedQueries[name] = {}\n } else {\n this._completedQueries[name][this.hashQuery(name, query, opts)] = undefined\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 (inverseDef && 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 * const JSData = require('js-data');\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 * 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\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\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","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","add","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","relationFields","idAttribute","relatedRecord","_setForeignKey","relatedRecords","relatedData","inverse","findInverseRelation","isInversedTo","records","getLocalField","linkRecord","isEmptyLinks","canFindLinkFor","findExistingLinksFor","setLocalField","relatedId","unsaved","setForeignKey","id","relationData","is","createRecord","createLinked","then","BelongsToRelation","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","recordId","ids","findExistingLinksByForeignKey","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","foreignIdField","createMany","HasOneRelation","RelationType","belongsTo","assignTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","plainCopy","_get","_mapper","quickHasChanges","areDifferent","validate","currentParent","inverseDef","children","remove","child","noDupeAdd","relations","_","adapter","getAdapterName","dbg","tasks","task","forEachRelation","raw","load","isSorN","previous","preserve","commit","postProcess","changesOnly","changes","silent","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","queryClass","emitRecordEvents","emit","beforeAdd","singular","onConflict","existingNoValidate","commitOnMerge","updateIndexes","indexes","on","_onRecordEvent","afterAdd","run","instances","removeAll","Ctor","initialValue","idOrRecord","beforeRemove","off","afterRemove","queryOrRecords","beforeRemoveAll","afterRemoveAll","mapCall","updateRecord","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","numeric","Schema","definition","_definition","extends","validationKeyword","unsetter","track","makeDescriptor","hasSet","orig","applyDefaults","keyPath","originalGet","_unset","error","current","changing","setTimeout","changeRecord","timestamp","changeHistory","originalSet","pick","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","MAPPER_DEFAULTS","Mapper","recordClass","methods","isPrototypeOf","applySchema","_data","wrap","crud","originalRecord","parentRelationMap","adapterResponse","_runHook","_value","_createParentRecordIfRequired","relationMap","_invokeAdapterMethod","createdProps","_createOrAssignChildRecordIfRequired","_commitChanges","_end","recordOrRecords","newValues","isRequiresParentId","createParentRecord","context","originalProps","isRequiresChildId","createChildRecord","parent","originalRecords","_recordValues","belongsToRelationData","Boolean","createdRecordsData","belongsToData","createdRecordData","ensureLinkedDataHasProperType","RecordCtor","method","config","lifecycleMethods","upper","before","after","defaults","beforeAssign","adapterArgs","getAdapter","_opts","assign","_result","getAdapters","defaultAdapter","_adapters","default","hookName","hookArgs","defaultValueIndex","overridenResult","propsOrRecords","conversionOptions","pass","_record","some","_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","collectionOpts","indexed","createIndex","_added","_onCollectionEvent","destroy","destroyAll","hashQuery","pendingQuery","usePendingFind","cachedFind","force","promise","find","cacheFind","usePendingFindAll","cachedFindAll","findAll","cacheFindAll","toJson","removeRelated","getForeignKey","update","updateAll","updateMany","LinkedCollection","event","addLinkedRecords","_addMeta","_clearMeta","removeLinkedRecords","DATASTORE_DEFAULTS","DataStore","updateOpts","getInverse","removeInverseRelation","relatedIdAttribute","updateIndex","setupInverseRelation","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","_key","origGet","origSet","unlinkOnDestroy","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA,IAAMA,SAAS,OAAf;;AAEA,IAAMC,WAAW,IAAI,CAArB;AACA,IAAMC,cAAc,sBAApB;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,iBAAn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5C,EAAmD,UAACphB,GAAD,EAAS;kBAClDX,OAAR,CAAgB,UAACyH,MAAD,EAAY;kBACpB+B,GAAN,CAAU/B,MAAV,EAAkB9G,IAAIS,UAAtB,EAAkCb,SAAlC;WADF;SADF;;aAMKmE,MAAP;KAjBK,CAAP;;CA5WJ;;AAkYA,kBAAeyf,cAAYha,MAAZ,CAAmBhI,OAAnB,CAAf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpdA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkQA,IAAa2lB,UAAU,gBAAhB;;;;"} \ 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","../src/Relation.js","../src/Relation/BelongsTo.js","../src/Relation/HasMany.js","../src/Relation/HasOne.js","../src/relations.js","../src/decorators.js","../src/Record.js","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.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.7976931348623157e308\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' () {\n return `expected: ${arguments[0]}, found: ${\n arguments[2] ? arguments[1] : typeof arguments[1]\n }`\n },\n '404' () {\n return `${arguments[0]} not found`\n }\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 (\n key &&\n dest[key] === undefined &&\n !utils.isFunction(value) &&\n key.indexOf('_') !== 0\n ) {\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 (\n relation &&\n relation.indexOf(containedName) === 0 &&\n relation.length >= containedName.length &&\n relation[containedName.length] === '.'\n ) {\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 =\n 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(\n from,\n Object.create(Object.getPrototypeOf(from)),\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(\n 500,\n 'Cannot copy! Source and destination are identical.'\n )\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(\n from[i],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n from[key],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n null,\n Array.prototype.slice.call(arguments, 1)\n )\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 () {\n return _events\n }\n setter = function (value) {\n _events = value\n }\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 if (fn.call(thisArg, obj[keys[i]], keys[i], obj) === false) {\n break\n }\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())) {\n // eslint-disable-line\n object = object[prop]\n if (object == null) {\n // 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 array1 = Array.isArray(array1) ? array1 : [array1]\n array2 = Array.isArray(array2) ? array2 : [array2]\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 (\n (toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) ||\n blacklist[i] === prop\n ) {\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 (\n type === 'number' ||\n (value && type === 'object' && toStr(value) === NUMBER_TAG)\n )\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 (\n typeof value === 'string' ||\n (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n )\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 ||\n 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.isArray(a) && utils.isArray(b)) {\n if (a.length !== b.length) {\n return false\n }\n for (let i = a.length; i--;) {\n if (!utils.deepEqual(a[i], b[i])) {\n // Exit loop early\n return false\n }\n }\n } else if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n if (!(_equal = utils.deepEqual(value, b[key]))) {\n // Exit loop early\n return false\n }\n })\n if (_equal) {\n utils.forOwn(b, function (value, key) {\n if (!(_equal = utils.deepEqual(value, a[key]))) {\n // Exit loop early\n return false\n }\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())) {\n // eslint-disable-line\n object = object[path]\n if (object == null) {\n // 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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @private\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 * const JSData = require('js-data');\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');\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 Query intro\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between(18, 30, { index: 'age' })\n * .run();\n * console.log(filteredUsers);\n *\n * @example Same as above.\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between([18], [30], { index: 'age' })\n * .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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * })\n * .run();\n * console.log(results);\n *\n * @example Use a custom filter function\n * const posts = query\n * .filter(function (post) {\n * return post.isReady();\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts); // [...]\n * });\n *\n * @example Empty \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const posts = store.filter('post');\n * console.log(posts); // [...]\n *\n * @example Complex \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * const PAGE_SIZE = 2;\n * let currentPage = 3;\n *\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 * const results = 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 * console.log(results);\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const PAGE_SIZE = 10;\n * let currentPage = 1;\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5;\n * let currentPage = 2;\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n *\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5\n * let currentPage = 2\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * });\n * console.log(results)\n *\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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users);\n * const ages = store\n * .query('user')\n * .map(function (user) {\n * return user.age;\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n *\n * @example Variant 2\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n * @example Variant 3\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({ status: 'published' })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Variant 4\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Multiple operators\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\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","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) && this !== 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 ensureLinkedDataHasProperType (props, opts) {\n const relatedMapper = this.getRelation()\n const relationData = this.getLocalField(props)\n\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n\n if (relationData && !relatedMapper.is(relationData)) {\n utils.set(props, this.localField, relatedMapper.createRecord(relationData, opts))\n }\n },\n\n isRequiresParentId () {\n return false\n },\n\n isRequiresChildId () {\n return false\n },\n\n createChildRecord (props, relationData, opts) {\n this.setForeignKey(props, relationData)\n\n return this.createLinked(relationData, opts).then((result) => {\n this.setLocalField(props, result)\n })\n },\n\n createLinked (props, opts) {\n const create = utils.isArray(props) ? 'createMany' : 'create'\n\n return this.getRelation()[create](props, opts)\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 isRequiresParentId () {\n return true\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n\n return this.createLinked(relationData, opts).then((record) => {\n this.setForeignKey(props, record)\n })\n },\n\n createChildRecord () {\n throw new Error('\"BelongsTo\" relation does not support child creation as it cannot have children.')\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.relatedCollection.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 isRequiresParentId () {\n return !!this.localKeys && this.localKeys.length > 0\n },\n\n isRequiresChildId () {\n return !!this.foreignKey\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n const foreignIdField = this.getRelation().idAttribute\n\n return this.createLinked(relationData, opts).then((records) => {\n utils.set(props, this.localKeys, records.map((record) => utils.get(record, foreignIdField)))\n })\n },\n\n createLinked (props, opts) {\n return this.getRelation().createMany(props, opts)\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 isRequiresChildId () {\n return true\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @param {boolean} [opts.validateOnSet=true] Whether to enable setter\n * validation on properties after the Record has been initialized.\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 const mapper = this.constructor.mapper\n\n _set(creatingPath, true)\n _set(noValidatePath, !!opts.noValidate)\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\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 if (opts.validateOnSet !== undefined) {\n _set(noValidatePath, !opts.validateOnSet)\n } else if (mapper && mapper.validateOnSet !== undefined) {\n _set(noValidatePath, !mapper.validateOnSet)\n } else {\n _set(noValidatePath, false)\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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('changing', false)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 *\n * @method Record#toJSON\n * @param {object} [opts] Configuration options.\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, (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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 creatingPath,\n noValidatePath,\n keepChangeHistoryPath,\n previousPath\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 * const JSData = require('js-data');\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","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 Record from './Record'\nimport Index from '../lib/mindex/index'\n\nconst { noValidatePath } = Record\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 * skip\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 * Skip:\n *\n * Ignore new record, keep existing record.\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');\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 * const JSData = require('js-data');\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 {boolean} [opts.noValidate] See {@link Record#noValidate}.\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')(\n 400,\n 'object or array',\n records\n )\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 (\n onConflict !== 'merge' &&\n onConflict !== 'replace' &&\n onConflict !== 'skip'\n ) {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(\n 400,\n 'one of (merge, replace, skip)',\n onConflict,\n true\n )\n }\n const existingNoValidate = existing._get(noValidatePath)\n if (opts.noValidate) {\n // Disable validation\n existing._set(noValidatePath, true)\n }\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 if(onConflict === 'skip'){ do nothing }\n\n if (opts.noValidate) {\n // Restore previous `noValidate` value\n existing._set(noValidatePath, existingNoValidate)\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()\n .between(leftKeys, rightKeys, opts)\n .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 * const JSData = require('js-data');\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((post) => post.id % 2 === 0);\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()\n .filter(query, thisArg)\n .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 =\n id === undefined\n ? []\n : this.query()\n .get(id)\n .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()\n .getAll(...args)\n .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()\n .limit(num)\n .run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map((user) => user.name);\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((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 }\n if (!opts.silent) {\n this.emit('remove', record)\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)\n ? queryOrRecords.slice()\n : 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()\n .skip(num)\n .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 * const JSData = require('js-data');\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'\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 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\n/**\n * Validation keywords validated for any type:\n *\n * - `enum`\n * - `type`\n * - `allOf`\n * - `anyOf`\n * - `oneOf`\n * - `not`\n *\n * @name Schema.ANY_OPS\n * @type {string[]}\n */\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\n\n/**\n * Validation keywords validated for array types:\n *\n * - `items`\n * - `maxItems`\n * - `minItems`\n * - `uniqueItems`\n *\n * @name Schema.ARRAY_OPS\n * @type {string[]}\n */\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\n\n/**\n * Validation keywords validated for numeric (number and integer) types:\n *\n * - `multipleOf`\n * - `maximum`\n * - `minimum`\n *\n * @name Schema.NUMERIC_OPS\n * @type {string[]}\n */\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\n\n/**\n * Validation keywords validated for object types:\n *\n * - `maxProperties`\n * - `minProperties`\n * - `required`\n * - `properties`\n * - `dependencies`\n *\n * @name Schema.OBJECT_OPS\n * @type {string[]}\n */\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n\n/**\n * Validation keywords validated for string types:\n *\n * - `maxLength`\n * - `minLength`\n * - `pattern`\n *\n * @name Schema.STRING_OPS\n * @type {string[]}\n */\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 * 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 * const JSData = require('js-data');\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#apply\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, (schema, prop) => {\n Object.defineProperty(\n target,\n prop,\n this.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 * Assemble a property descriptor for tracking and validating changes to\n * a property according to the given schema. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @name Schema#makeDescriptor\n * @method\n * @param {string} prop The property name.\n * @param {(Schema|object)} schema The schema for the property.\n * @param {object} [opts] Optional configuration.\n * @param {function} [opts.getter] Custom getter function.\n * @param {function} [opts.setter] Custom setter function.\n * @param {function} [opts.track] Whether to track changes.\n * @returns {object} A property descriptor for the given schema.\n */\n makeDescriptor (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 * 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 (value === undefined) {\n return\n }\n if (this.type === 'object') {\n let copy = {}\n const properties = this.properties\n if (properties) {\n utils.forOwn(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 // Conditionally copy properties not defined in \"properties\"\n if (this.additionalProperties) {\n for (var key in value) {\n if (!properties[key]) {\n copy[key] = utils.plainCopy(value[key])\n }\n }\n }\n return copy\n } else if (this.type === 'array') {\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 * const JSData = require('js-data');\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 *\n * @example\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\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 * const JSData = require('js-data');\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 if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\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 // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n let parentRelationMap = {}\n let adapterResponse = {}\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n opts.op = 'beforeCreate'\n return this._runHook(opts.op, props, opts).then((_value) => {\n // Allow for re-assignment from lifecycle hook\n props = _value !== undefined ? _value : props\n opts.with || (opts.with = [])\n return this._createParentRecordIfRequired(props, opts)\n }).then((relationMap) => {\n parentRelationMap = relationMap\n }).then(() => {\n opts.op = 'create'\n return this._invokeAdapterMethod(opts.op, props, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdProps = opts.raw ? adapterResponse.data : adapterResponse\n\n return this._createOrAssignChildRecordIfRequired(createdProps, {\n opts,\n parentRelationMap,\n originalProps: props\n })\n }).then((createdProps) => {\n return this._commitChanges(props, createdProps)\n }).then((record) => {\n if (opts.raw) {\n adapterResponse.data = record\n } else {\n adapterResponse = record\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreate'\n return this._runHook(opts.op, props, opts, result)\n })\n },\n\n _commitChanges (recordOrRecords, newValues) {\n if (utils.isArray(recordOrRecords)) {\n return recordOrRecords.map((record, i) => this._commitChanges(record, newValues[i]))\n }\n\n utils.set(recordOrRecords, newValues, { silent: true })\n\n if (utils.isFunction(recordOrRecords.commit)) {\n recordOrRecords.commit()\n }\n\n return recordOrRecords\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 * Creates parent record for relation types like BelongsTo or HasMany with localKeys\n * in order to satisfy foreignKey dependency (so called child records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} opts See {@link Mapper#create}.\n * @returns {Object} cached parent records map\n * @see Mapper#create\n * @since 3.0.0\n */\n _createParentRecordIfRequired (props, opts) {\n const tasks = []\n const relations = []\n\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n if (!def.isRequiresParentId() || !def.getLocalField(props)) {\n return\n }\n\n optsCopy.raw = false\n relations.push(def)\n tasks.push(def.createParentRecord(props, optsCopy))\n })\n\n return utils.Promise.all(tasks).then(records => {\n return relations.reduce((map, relation, index) => {\n relation.setLocalField(map, records[index])\n return map\n }, {})\n })\n },\n\n /**\n * Creates child record for relation types like HasOne or HasMany with foreignKey\n * in order to satisfy foreignKey dependency (so called parent records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} context contains collected information.\n * @param {object} context.opts See {@link Mapper#create}.\n * @param {object} context.parentRelationMap contains parent records map\n * @param {object} context.originalProps contains data passed into {@link Mapper#create} method\n * @return {Promise} updated props\n * @see Mapper#create\n * @since 3.0.0\n */\n _createOrAssignChildRecordIfRequired (props, context) {\n const tasks = []\n\n utils.forEachRelation(this, context.opts, (def, optsCopy) => {\n const relationData = def.getLocalField(context.originalProps)\n\n if (!relationData) {\n return\n }\n\n optsCopy.raw = false\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.isRequiresChildId()) {\n tasks.push(def.createChildRecord(props, relationData, optsCopy))\n } else if (def.isRequiresParentId()) {\n const parent = def.getLocalField(context.parentRelationMap)\n\n if (parent) {\n def.setLocalField(props, parent)\n }\n }\n })\n\n return utils.Promise.all(tasks)\n .then(() => props)\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 // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n let adapterResponse\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n opts.op = 'beforeCreateMany'\n return this._runHook(opts.op, records, opts).then((_recordValues) => {\n // Allow for re-assignment from lifecycle hook\n records = _recordValues !== undefined ? _recordValues : records\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(Boolean)\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 optsCopy.raw = false\n tasks.push(def.createLinked(relationData, optsCopy).then((relatedRecords) => {\n records.forEach((record, i) => def.setForeignKey(record, relatedRecords[i]))\n }).then((relatedRecords) => {\n def.setLocalField(belongsToRelationData, relatedRecords)\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n opts.op = 'createMany'\n return this._invokeAdapterMethod(opts.op, records, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdRecordsData = opts.raw ? adapterResponse.data : adapterResponse\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(Boolean)\n if (relationData.length !== records.length) {\n return\n }\n\n optsCopy.raw = false\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((relatedData) => {\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 return this._commitChanges(records, createdRecordsData)\n })\n })\n }).then((records) => {\n if (opts.raw) {\n adapterResponse.data = records\n } else {\n adapterResponse = records\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreateMany'\n return this._runHook(opts.op, records, opts, result)\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\n if (this.relationList) {\n this.relationList.forEach(function (def) {\n def.ensureLinkedDataHasProperType(props, opts)\n })\n }\n const RecordCtor = this.recordClass\n\n return (!RecordCtor || props instanceof RecordCtor) ? props : new RecordCtor(props, opts)\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 // force noValidate on find/findAll\n const noValidate = /find/.test(op) || opts.noValidate\n const _opts = Object.assign({}, opts, { noValidate })\n\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 _runHook (hookName, ...hookArgs) {\n const defaultValueIndex = hookName.indexOf('after') === 0 ? hookArgs.length - 1 : 0\n\n return utils.resolve(this[hookName](...hookArgs))\n .then((overridenResult) => overridenResult === undefined ? hookArgs[defaultValueIndex] : overridenResult)\n },\n\n _invokeAdapterMethod (method, propsOrRecords, opts) {\n const conversionOptions = { with: opts.pass || [] }\n let object\n\n this.dbg(opts.op, propsOrRecords, opts)\n\n if (utils.isArray(propsOrRecords)) {\n object = propsOrRecords.map(record => this.toJSON(record, conversionOptions))\n } else {\n object = this.toJSON(propsOrRecords, conversionOptions)\n }\n\n return this.getAdapter(opts.adapter)[method](this, object, opts)\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 * // \"foo\" is stripped by toJSON()\n * console.log(PersonMapper.toJSON(person)); // {\"id\":1,\"name\":\"John\"}\n *\n * const PersonRelaxedMapper = new Mapper({\n * name: 'personRelaxed',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = PersonRelaxedMapper.createRecord({ id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(PersonRelaxedMapper.toJSON(person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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 {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\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n } else {\n for (var key in record) {\n if (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 if (!schema) {\n return\n }\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\n return errors.some(Boolean) ? errors : 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 * const JSData = require('js-data');\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 * // \"foo\" is stripped by toJSON()\n * console.log(store.toJSON('person', person)); // {\"id\":1,\"name\":\"John\"}\n *\n * store.defineMapper('personRelaxed', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = store.createRecord('personRelaxed', { id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(store.toJSON('personRelaxed', person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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');\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');\n * const { Container, Mapper } = 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');\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');\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');\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');\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');\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');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 let collectionOpts = {\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 if (opts && ('onConflict' in opts)) {\n collectionOpts.onConflict = opts.onConflict\n }\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, collectionOpts) // eslint-disable-line\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\n if (opts.force || !item) {\n const promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts)\n return promise\n .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 }\n\n return utils.resolve(item)\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\n if (opts.force || !items) {\n const promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts)\n return promise\n .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 }\n\n return utils.resolve(items)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 if (!query || !Object.keys(query).length) {\n this._completedQueries[name] = {}\n } else {\n this._completedQueries[name][this.hashQuery(name, query, opts)] = undefined\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 (inverseDef && 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 * const JSData = require('js-data');\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 * 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\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\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","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","add","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","relationFields","idAttribute","relatedRecord","_setForeignKey","relatedRecords","relatedData","inverse","findInverseRelation","isInversedTo","records","getLocalField","linkRecord","isEmptyLinks","canFindLinkFor","findExistingLinksFor","setLocalField","relatedId","unsaved","setForeignKey","id","relationData","is","createRecord","createLinked","then","BelongsToRelation","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","recordId","ids","findExistingLinksByForeignKey","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","foreignIdField","createMany","HasOneRelation","RelationType","belongsTo","assignTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","plainCopy","_get","_mapper","quickHasChanges","areDifferent","validate","currentParent","inverseDef","children","remove","child","noDupeAdd","relations","_","adapter","getAdapterName","dbg","tasks","task","forEachRelation","raw","load","isSorN","previous","preserve","commit","postProcess","changesOnly","changes","silent","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","queryClass","emitRecordEvents","emit","beforeAdd","singular","onConflict","existingNoValidate","commitOnMerge","updateIndexes","indexes","on","_onRecordEvent","afterAdd","run","instances","removeAll","Ctor","initialValue","idOrRecord","beforeRemove","off","afterRemove","queryOrRecords","beforeRemoveAll","afterRemoveAll","mapCall","updateRecord","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","numeric","Schema","definition","_definition","extends","validationKeyword","unsetter","track","makeDescriptor","hasSet","orig","applyDefaults","keyPath","originalGet","_unset","error","current","changing","setTimeout","changeRecord","timestamp","changeHistory","originalSet","pick","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","MAPPER_DEFAULTS","Mapper","recordClass","methods","isPrototypeOf","applySchema","_data","wrap","crud","parentRelationMap","adapterResponse","_runHook","_value","_createParentRecordIfRequired","relationMap","_invokeAdapterMethod","createdProps","_createOrAssignChildRecordIfRequired","_commitChanges","_end","recordOrRecords","newValues","isRequiresParentId","createParentRecord","context","originalProps","isRequiresChildId","createChildRecord","parent","_recordValues","belongsToRelationData","Boolean","createdRecordsData","belongsToData","createdRecordData","ensureLinkedDataHasProperType","RecordCtor","method","config","lifecycleMethods","upper","before","after","defaults","beforeAssign","adapterArgs","getAdapter","_opts","assign","_result","getAdapters","defaultAdapter","_adapters","default","hookName","hookArgs","defaultValueIndex","overridenResult","propsOrRecords","conversionOptions","pass","_record","some","_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","collectionOpts","indexed","createIndex","_added","_onCollectionEvent","destroy","destroyAll","hashQuery","pendingQuery","usePendingFind","cachedFind","force","promise","find","cacheFind","usePendingFindAll","cachedFindAll","findAll","cacheFindAll","toJson","removeRelated","getForeignKey","update","updateAll","updateMany","LinkedCollection","event","addLinkedRecords","_addMeta","_clearMeta","removeLinkedRecords","DATASTORE_DEFAULTS","DataStore","updateOpts","getInverse","removeInverseRelation","relatedIdAttribute","updateIndex","setupInverseRelation","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","_key","origGet","origSet","unlinkOnDestroy","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA,IAAMA,SAAS,OAAf;;AAEA,IAAMC,WAAW,IAAI,CAArB;AACA,IAAMC,cAAc,sBAApB;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;0BACaC,UAAU,CAAV,CA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kBAAeuf,cAAY9Z,MAAZ,CAAmBhI,OAAnB,CAAf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpdA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkQA,IAAaylB,UAAU,gBAAhB;;;;"} \ No newline at end of file diff --git a/dist/js-data.js b/dist/js-data.js index 20089b9e..2e42261b 100644 --- a/dist/js-data.js +++ b/dist/js-data.js @@ -1,6 +1,6 @@ /*! * js-data -* @version 3.0.6 - Homepage +* @version 3.0.7 - Homepage * @author js-data project authors * @copyright (c) 2014-2016 js-data project authors * @license MIT @@ -8025,7 +8025,6 @@ // Default values for arguments props || (props = {}); opts || (opts = {}); - var originalRecord = props; var parentRelationMap = {}; var adapterResponse = {}; @@ -8055,7 +8054,7 @@ originalProps: props }); }).then(function (createdProps) { - return _this2._commitChanges(originalRecord, createdProps); + return _this2._commitChanges(props, createdProps); }).then(function (record) { if (opts.raw) { adapterResponse.data = record; @@ -8270,7 +8269,6 @@ // Default values for arguments records || (records = []); opts || (opts = {}); - var originalRecords = records; var adapterResponse = void 0; // Fill in "opts" with the Mapper's configuration @@ -8348,7 +8346,7 @@ } }); return utils.Promise.all(tasks).then(function () { - return _this4._commitChanges(originalRecords, createdRecordsData); + return _this4._commitChanges(records, createdRecordsData); }); }); }).then(function (records) { @@ -13697,10 +13695,10 @@ * @type {Object} */ var version = { - full: '3.0.6', + full: '3.0.7', major: 3, minor: 0, - patch: 6 + patch: 7 }; exports.version = version; diff --git a/dist/js-data.js.map b/dist/js-data.js.map index c97d0997..b8bc0953 100644 --- a/dist/js-data.js.map +++ b/dist/js-data.js.map @@ -1 +1 @@ -{"version":3,"file":"js-data.js","sources":["../src/utils.js","../src/Settable.js","../src/Component.js","../src/Query.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","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.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.7976931348623157e308\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' () {\n return `expected: ${arguments[0]}, found: ${\n arguments[2] ? arguments[1] : typeof arguments[1]\n }`\n },\n '404' () {\n return `${arguments[0]} not found`\n }\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 (\n key &&\n dest[key] === undefined &&\n !utils.isFunction(value) &&\n key.indexOf('_') !== 0\n ) {\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 (\n relation &&\n relation.indexOf(containedName) === 0 &&\n relation.length >= containedName.length &&\n relation[containedName.length] === '.'\n ) {\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 =\n 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(\n from,\n Object.create(Object.getPrototypeOf(from)),\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(\n 500,\n 'Cannot copy! Source and destination are identical.'\n )\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(\n from[i],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n from[key],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n null,\n Array.prototype.slice.call(arguments, 1)\n )\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 () {\n return _events\n }\n setter = function (value) {\n _events = value\n }\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 if (fn.call(thisArg, obj[keys[i]], keys[i], obj) === false) {\n break\n }\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())) {\n // eslint-disable-line\n object = object[prop]\n if (object == null) {\n // 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 array1 = Array.isArray(array1) ? array1 : [array1]\n array2 = Array.isArray(array2) ? array2 : [array2]\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 (\n (toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) ||\n blacklist[i] === prop\n ) {\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 (\n type === 'number' ||\n (value && type === 'object' && toStr(value) === NUMBER_TAG)\n )\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 (\n typeof value === 'string' ||\n (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n )\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 ||\n 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.isArray(a) && utils.isArray(b)) {\n if (a.length !== b.length) {\n return false\n }\n for (let i = a.length; i--;) {\n if (!utils.deepEqual(a[i], b[i])) {\n // Exit loop early\n return false\n }\n }\n } else if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n if (!(_equal = utils.deepEqual(value, b[key]))) {\n // Exit loop early\n return false\n }\n })\n if (_equal) {\n utils.forOwn(b, function (value, key) {\n if (!(_equal = utils.deepEqual(value, a[key]))) {\n // Exit loop early\n return false\n }\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())) {\n // eslint-disable-line\n object = object[path]\n if (object == null) {\n // 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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @private\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 * const JSData = require('js-data');\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');\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 Query intro\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between(18, 30, { index: 'age' })\n * .run();\n * console.log(filteredUsers);\n *\n * @example Same as above.\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between([18], [30], { index: 'age' })\n * .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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * })\n * .run();\n * console.log(results);\n *\n * @example Use a custom filter function\n * const posts = query\n * .filter(function (post) {\n * return post.isReady();\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts); // [...]\n * });\n *\n * @example Empty \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const posts = store.filter('post');\n * console.log(posts); // [...]\n *\n * @example Complex \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * const PAGE_SIZE = 2;\n * let currentPage = 3;\n *\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 * const results = 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 * console.log(results);\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const PAGE_SIZE = 10;\n * let currentPage = 1;\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5;\n * let currentPage = 2;\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n *\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5\n * let currentPage = 2\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * });\n * console.log(results)\n *\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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users);\n * const ages = store\n * .query('user')\n * .map(function (user) {\n * return user.age;\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n *\n * @example Variant 2\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n * @example Variant 3\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({ status: 'published' })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Variant 4\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Multiple operators\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\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","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) && this !== 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 ensureLinkedDataHasProperType (props, opts) {\n const relatedMapper = this.getRelation()\n const relationData = this.getLocalField(props)\n\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n\n if (relationData && !relatedMapper.is(relationData)) {\n utils.set(props, this.localField, relatedMapper.createRecord(relationData, opts))\n }\n },\n\n isRequiresParentId () {\n return false\n },\n\n isRequiresChildId () {\n return false\n },\n\n createChildRecord (props, relationData, opts) {\n this.setForeignKey(props, relationData)\n\n return this.createLinked(relationData, opts).then((result) => {\n this.setLocalField(props, result)\n })\n },\n\n createLinked (props, opts) {\n const create = utils.isArray(props) ? 'createMany' : 'create'\n\n return this.getRelation()[create](props, opts)\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 isRequiresParentId () {\n return true\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n\n return this.createLinked(relationData, opts).then((record) => {\n this.setForeignKey(props, record)\n })\n },\n\n createChildRecord () {\n throw new Error('\"BelongsTo\" relation does not support child creation as it cannot have children.')\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.relatedCollection.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 isRequiresParentId () {\n return !!this.localKeys && this.localKeys.length > 0\n },\n\n isRequiresChildId () {\n return !!this.foreignKey\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n const foreignIdField = this.getRelation().idAttribute\n\n return this.createLinked(relationData, opts).then((records) => {\n utils.set(props, this.localKeys, records.map((record) => utils.get(record, foreignIdField)))\n })\n },\n\n createLinked (props, opts) {\n return this.getRelation().createMany(props, opts)\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 isRequiresChildId () {\n return true\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @param {boolean} [opts.validateOnSet=true] Whether to enable setter\n * validation on properties after the Record has been initialized.\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 const mapper = this.constructor.mapper\n\n _set(creatingPath, true)\n _set(noValidatePath, !!opts.noValidate)\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\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 if (opts.validateOnSet !== undefined) {\n _set(noValidatePath, !opts.validateOnSet)\n } else if (mapper && mapper.validateOnSet !== undefined) {\n _set(noValidatePath, !mapper.validateOnSet)\n } else {\n _set(noValidatePath, false)\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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('changing', false)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 *\n * @method Record#toJSON\n * @param {object} [opts] Configuration options.\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, (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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 creatingPath,\n noValidatePath,\n keepChangeHistoryPath,\n previousPath\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 * const JSData = require('js-data');\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","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 Record from './Record'\nimport Index from '../lib/mindex/index'\n\nconst { noValidatePath } = Record\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 * skip\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 * Skip:\n *\n * Ignore new record, keep existing record.\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');\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 * const JSData = require('js-data');\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 {boolean} [opts.noValidate] See {@link Record#noValidate}.\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')(\n 400,\n 'object or array',\n records\n )\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 (\n onConflict !== 'merge' &&\n onConflict !== 'replace' &&\n onConflict !== 'skip'\n ) {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(\n 400,\n 'one of (merge, replace, skip)',\n onConflict,\n true\n )\n }\n const existingNoValidate = existing._get(noValidatePath)\n if (opts.noValidate) {\n // Disable validation\n existing._set(noValidatePath, true)\n }\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 if(onConflict === 'skip'){ do nothing }\n\n if (opts.noValidate) {\n // Restore previous `noValidate` value\n existing._set(noValidatePath, existingNoValidate)\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()\n .between(leftKeys, rightKeys, opts)\n .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 * const JSData = require('js-data');\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((post) => post.id % 2 === 0);\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()\n .filter(query, thisArg)\n .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 =\n id === undefined\n ? []\n : this.query()\n .get(id)\n .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()\n .getAll(...args)\n .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()\n .limit(num)\n .run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map((user) => user.name);\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((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 }\n if (!opts.silent) {\n this.emit('remove', record)\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)\n ? queryOrRecords.slice()\n : 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()\n .skip(num)\n .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 * const JSData = require('js-data');\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'\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 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\n/**\n * Validation keywords validated for any type:\n *\n * - `enum`\n * - `type`\n * - `allOf`\n * - `anyOf`\n * - `oneOf`\n * - `not`\n *\n * @name Schema.ANY_OPS\n * @type {string[]}\n */\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\n\n/**\n * Validation keywords validated for array types:\n *\n * - `items`\n * - `maxItems`\n * - `minItems`\n * - `uniqueItems`\n *\n * @name Schema.ARRAY_OPS\n * @type {string[]}\n */\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\n\n/**\n * Validation keywords validated for numeric (number and integer) types:\n *\n * - `multipleOf`\n * - `maximum`\n * - `minimum`\n *\n * @name Schema.NUMERIC_OPS\n * @type {string[]}\n */\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\n\n/**\n * Validation keywords validated for object types:\n *\n * - `maxProperties`\n * - `minProperties`\n * - `required`\n * - `properties`\n * - `dependencies`\n *\n * @name Schema.OBJECT_OPS\n * @type {string[]}\n */\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n\n/**\n * Validation keywords validated for string types:\n *\n * - `maxLength`\n * - `minLength`\n * - `pattern`\n *\n * @name Schema.STRING_OPS\n * @type {string[]}\n */\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 * 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 * const JSData = require('js-data');\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#apply\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, (schema, prop) => {\n Object.defineProperty(\n target,\n prop,\n this.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 * Assemble a property descriptor for tracking and validating changes to\n * a property according to the given schema. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @name Schema#makeDescriptor\n * @method\n * @param {string} prop The property name.\n * @param {(Schema|object)} schema The schema for the property.\n * @param {object} [opts] Optional configuration.\n * @param {function} [opts.getter] Custom getter function.\n * @param {function} [opts.setter] Custom setter function.\n * @param {function} [opts.track] Whether to track changes.\n * @returns {object} A property descriptor for the given schema.\n */\n makeDescriptor (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 * 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 (value === undefined) {\n return\n }\n if (this.type === 'object') {\n let copy = {}\n const properties = this.properties\n if (properties) {\n utils.forOwn(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 // Conditionally copy properties not defined in \"properties\"\n if (this.additionalProperties) {\n for (var key in value) {\n if (!properties[key]) {\n copy[key] = utils.plainCopy(value[key])\n }\n }\n }\n return copy\n } else if (this.type === 'array') {\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 * const JSData = require('js-data');\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 *\n * @example\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\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 * const JSData = require('js-data');\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 if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\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 // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n const originalRecord = props\n let parentRelationMap = {}\n let adapterResponse = {}\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n opts.op = 'beforeCreate'\n return this._runHook(opts.op, props, opts).then((_value) => {\n // Allow for re-assignment from lifecycle hook\n props = _value !== undefined ? _value : props\n opts.with || (opts.with = [])\n return this._createParentRecordIfRequired(props, opts)\n }).then((relationMap) => {\n parentRelationMap = relationMap\n }).then(() => {\n opts.op = 'create'\n return this._invokeAdapterMethod(opts.op, props, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdProps = opts.raw ? adapterResponse.data : adapterResponse\n\n return this._createOrAssignChildRecordIfRequired(createdProps, {\n opts,\n parentRelationMap,\n originalProps: props\n })\n }).then((createdProps) => {\n return this._commitChanges(originalRecord, createdProps)\n }).then((record) => {\n if (opts.raw) {\n adapterResponse.data = record\n } else {\n adapterResponse = record\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreate'\n return this._runHook(opts.op, props, opts, result)\n })\n },\n\n _commitChanges (recordOrRecords, newValues) {\n if (utils.isArray(recordOrRecords)) {\n return recordOrRecords.map((record, i) => this._commitChanges(record, newValues[i]))\n }\n\n utils.set(recordOrRecords, newValues, { silent: true })\n\n if (utils.isFunction(recordOrRecords.commit)) {\n recordOrRecords.commit()\n }\n\n return recordOrRecords\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 * Creates parent record for relation types like BelongsTo or HasMany with localKeys\n * in order to satisfy foreignKey dependency (so called child records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} opts See {@link Mapper#create}.\n * @returns {Object} cached parent records map\n * @see Mapper#create\n * @since 3.0.0\n */\n _createParentRecordIfRequired (props, opts) {\n const tasks = []\n const relations = []\n\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n if (!def.isRequiresParentId() || !def.getLocalField(props)) {\n return\n }\n\n optsCopy.raw = false\n relations.push(def)\n tasks.push(def.createParentRecord(props, optsCopy))\n })\n\n return utils.Promise.all(tasks).then(records => {\n return relations.reduce((map, relation, index) => {\n relation.setLocalField(map, records[index])\n return map\n }, {})\n })\n },\n\n /**\n * Creates child record for relation types like HasOne or HasMany with foreignKey\n * in order to satisfy foreignKey dependency (so called parent records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} context contains collected information.\n * @param {object} context.opts See {@link Mapper#create}.\n * @param {object} context.parentRelationMap contains parent records map\n * @param {object} context.originalProps contains data passed into {@link Mapper#create} method\n * @return {Promise} updated props\n * @see Mapper#create\n * @since 3.0.0\n */\n _createOrAssignChildRecordIfRequired (props, context) {\n const tasks = []\n\n utils.forEachRelation(this, context.opts, (def, optsCopy) => {\n const relationData = def.getLocalField(context.originalProps)\n\n if (!relationData) {\n return\n }\n\n optsCopy.raw = false\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.isRequiresChildId()) {\n tasks.push(def.createChildRecord(props, relationData, optsCopy))\n } else if (def.isRequiresParentId()) {\n const parent = def.getLocalField(context.parentRelationMap)\n\n if (parent) {\n def.setLocalField(props, parent)\n }\n }\n })\n\n return utils.Promise.all(tasks)\n .then(() => props)\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 // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n const originalRecords = records\n let adapterResponse\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n opts.op = 'beforeCreateMany'\n return this._runHook(opts.op, records, opts).then((_recordValues) => {\n // Allow for re-assignment from lifecycle hook\n records = _recordValues !== undefined ? _recordValues : records\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(Boolean)\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 optsCopy.raw = false\n tasks.push(def.createLinked(relationData, optsCopy).then((relatedRecords) => {\n records.forEach((record, i) => def.setForeignKey(record, relatedRecords[i]))\n }).then((relatedRecords) => {\n def.setLocalField(belongsToRelationData, relatedRecords)\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n opts.op = 'createMany'\n return this._invokeAdapterMethod(opts.op, records, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdRecordsData = opts.raw ? adapterResponse.data : adapterResponse\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(Boolean)\n if (relationData.length !== records.length) {\n return\n }\n\n optsCopy.raw = false\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((relatedData) => {\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 return this._commitChanges(originalRecords, createdRecordsData)\n })\n })\n }).then((records) => {\n if (opts.raw) {\n adapterResponse.data = records\n } else {\n adapterResponse = records\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreateMany'\n return this._runHook(opts.op, records, opts, result)\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\n if (this.relationList) {\n this.relationList.forEach(function (def) {\n def.ensureLinkedDataHasProperType(props, opts)\n })\n }\n const RecordCtor = this.recordClass\n\n return (!RecordCtor || props instanceof RecordCtor) ? props : new RecordCtor(props, opts)\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 // force noValidate on find/findAll\n const noValidate = /find/.test(op) || opts.noValidate\n const _opts = Object.assign({}, opts, { noValidate })\n\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 _runHook (hookName, ...hookArgs) {\n const defaultValueIndex = hookName.indexOf('after') === 0 ? hookArgs.length - 1 : 0\n\n return utils.resolve(this[hookName](...hookArgs))\n .then((overridenResult) => overridenResult === undefined ? hookArgs[defaultValueIndex] : overridenResult)\n },\n\n _invokeAdapterMethod (method, propsOrRecords, opts) {\n const conversionOptions = { with: opts.pass || [] }\n let object\n\n this.dbg(opts.op, propsOrRecords, opts)\n\n if (utils.isArray(propsOrRecords)) {\n object = propsOrRecords.map(record => this.toJSON(record, conversionOptions))\n } else {\n object = this.toJSON(propsOrRecords, conversionOptions)\n }\n\n return this.getAdapter(opts.adapter)[method](this, object, opts)\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 * // \"foo\" is stripped by toJSON()\n * console.log(PersonMapper.toJSON(person)); // {\"id\":1,\"name\":\"John\"}\n *\n * const PersonRelaxedMapper = new Mapper({\n * name: 'personRelaxed',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = PersonRelaxedMapper.createRecord({ id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(PersonRelaxedMapper.toJSON(person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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 {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\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n } else {\n for (var key in record) {\n if (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 if (!schema) {\n return\n }\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\n return errors.some(Boolean) ? errors : 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 * const JSData = require('js-data');\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 * // \"foo\" is stripped by toJSON()\n * console.log(store.toJSON('person', person)); // {\"id\":1,\"name\":\"John\"}\n *\n * store.defineMapper('personRelaxed', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = store.createRecord('personRelaxed', { id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(store.toJSON('personRelaxed', person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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');\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');\n * const { Container, Mapper } = 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');\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');\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');\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');\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');\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');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 let collectionOpts = {\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 if (opts && ('onConflict' in opts)) {\n collectionOpts.onConflict = opts.onConflict\n }\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, collectionOpts) // eslint-disable-line\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\n if (opts.force || !item) {\n const promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts)\n return promise\n .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 }\n\n return utils.resolve(item)\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\n if (opts.force || !items) {\n const promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts)\n return promise\n .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 }\n\n return utils.resolve(items)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 if (!query || !Object.keys(query).length) {\n this._completedQueries[name] = {}\n } else {\n this._completedQueries[name][this.hashQuery(name, query, opts)] = undefined\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 (inverseDef && 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 * const JSData = require('js-data');\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 * 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\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\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","_forRelation","opts","def","fn","thisArg","relationName","relation","containedName","index","with","_getIndex","localField","withAll","optsCopy","fillIn","getRelation","slice","_activeWith","splice","i","length","substr","list","_relation","isObject","addHiddenPropsToTarget","target","props","map","keys","propName","descriptor","getOwnPropertyDescriptor","enumerable","defineProperties","areDifferent","newObject","oldObject","diff","diffObjects","diffCount","added","removed","changed","classCallCheck","instance","ctor","err","name","copy","from","to","stackFrom","stackTo","blacklist","plain","isArray","isDate","Date","getTime","isRegExp","RegExp","source","match","lastIndex","create","getPrototypeOf","push","result","hasOwnProperty","isBlacklisted","deepFillIn","existing","deepMixIn","equalsFn","ignore","deepEqual","newKeys","filter","oldKeys","oldValue","newValue","equal","a","b","domain","code","prefix","message","apply","Array","Error","eventify","getter","setter","_events","emit","events","args","type","shift","listeners","f","c","all","unshift","off","func","on","extend","classProps","superClass","subClass","configurable","writable","obj","setPrototypeOf","strictEs6Class","__proto__","defineProperty","findIndex","array","record","forEachRelation","mapper","relationList","len","fromJson","json","isString","JSON","parse","get","prop","last","pop","getSuper","isCtor","__super__","intersection","array1","array2","item","matches","test","isBoolean","isInteger","isNull","isNumber","isSorN","isUndefined","logify","dbg","log","level","debug","toUpperCase","console","noDupeAdd","omit","_props","pick","reduce","plainCopy","reject","remove","resolve","set","_path","exec","_equal","toJson","stringify","unset","safeSetProp","field","_set","safeSetLink","Settable","_get","_unset","Component","_listeners","INDEX_ERR","reserved","limit","offset","orderBy","skip","sort","where","escapeRegExp","percentRegExp","underscoreRegExp","escape","pattern","replace","Query","collection","data","_applyWhereFromObject","fields","ops","predicates","clause","expr","op","_applyWhereFromArray","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","concat","flags","num","Math","min","mapFn","mapCall","funcName","run","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","add","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","assignTo","relationFields","canFindLinkFor","getForeignKey","idAttribute","setForeignKey","relatedRecord","_setForeignKey","relatedRecords","getLocalField","setLocalField","relatedData","getInverse","inverse","findInverseRelation","isInversedTo","addLinkedRecords","records","linkRecord","isEmptyLinks","findExistingLinksFor","removeLinkedRecords","relatedId","unsaved","findExistingLinksByForeignKey","id","ensureLinkedDataHasProperType","relationData","is","createRecord","isRequiresParentId","isRequiresChildId","createChildRecord","createLinked","then","BelongsToRelation","createParentRecord","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","recordId","ids","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","foreignIdField","createMany","HasOneRelation","RelationType","belongsTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","_mapper","afterLoadRelations","beforeLoadRelations","changeHistory","changes","commit","destroy","hasChanges","quickHasChanges","isNew","isValid","validate","removeInverseRelation","currentParent","inverseDef","children","child","setupInverseRelation","loadRelations","relations","adapter","getAdapterName","tasks","task","raw","load","previous","revert","preserve","save","postProcess","changesOnly","silent","hashCode","insertAt","removeAt","binarySearch","lo","hi","compared","mid","found","Index","fieldList","fieldGetter","isIndex","values","pos","dataLocation","newIndex","results","order","visitAll","cb","leftInclusive","rightInclusive","_between","leftKey","rightKey","currKey","peek","clear","insertRecord","removeRecord","isUnique","j","updateRecord","COLLECTION_DEFAULTS","commitOnMerge","emitRecordEvents","onConflict","Collection","queryClass","indexes","_onRecordEvent","beforeAdd","singular","existingNoValidate","updateIndexes","afterAdd","afterRemove","afterRemoveAll","beforeRemove","beforeRemoveAll","createIndex","instances","prune","removeAll","Ctor","initialValue","idOrRecord","queryOrRecords","updateIndex","types","boolean","integer","number","string","segmentToString","segment","str","makePath","segments","makeError","actual","expected","addError","errors","maxLengthCommon","keyword","schema","max","minLengthCommon","validationKeywords","allOf","allErrors","_schema","anyOf","validated","dependencies","enum","possibleValues","join","items","checkingTuple","maximum","exclusiveMaximum","maxItems","maxLength","maxProperties","minimum","exclusiveMinimum","minItems","minLength","minProperties","multipleOf","not","oneOf","properties","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","eventIdPath","silentPath","validationFailureMsg","numeric","Schema","definition","_definition","extends","validationKeyword","unsetter","track","makeDescriptor","applyDefaults","hasSet","orig","keyPath","originalGet","error","current","changing","clearTimeout","setTimeout","changeRecord","timestamp","originalSet","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","count","defaults","destroyAll","find","findAll","sum","update","adapterArgs","beforeAssign","updateAll","updateMany","MAPPER_DEFAULTS","_adapters","applySchema","defaultAdapter","Mapper","lifecycleMethods","recordClass","methods","isPrototypeOf","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","parentRelationMap","adapterResponse","_runHook","_value","_createParentRecordIfRequired","relationMap","_invokeAdapterMethod","createdProps","_createOrAssignChildRecordIfRequired","originalProps","_commitChanges","recordOrRecords","newValues","createInstance","context","parent","originalRecords","_recordValues","belongsToRelationData","Boolean","createdRecordsData","belongsToData","createdRecordData","RecordCtor","method","config","upper","before","after","getAdapter","_opts","assign","_result","getAdapters","registerAdapter","default","hookName","hookArgs","defaultValueIndex","overridenResult","propsOrRecords","conversionOptions","pass","_record","some","defineRelations","_name","getMapperByName","getMapper","proxiedMapperMethods","Container","_mappers","mapperClass","mapperDefaults","_onMapperEvent","as","original","defineMapper","defineResource","warn","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","_completedQueries","SIMPLESTORE_DEFAULTS","usePendingFind","usePendingFindAll","SimpleStore","collectionClass","_collections","_pendingQueries","addToCache","_onCollectionEvent","cachedFind","cachedFindAll","cacheFind","cacheFindAll","hash","self","collectionOpts","_added","indexed","hashQuery","eject","ejectAll","pendingQuery","force","promise","inject","removeRelated","LinkedCollection","_addMeta","_clearMeta","event","DATASTORE_DEFAULTS","unlinkOnDestroy","DataStore","updateOpts","relatedIdAttribute","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","_key","origGet","origSet","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;EAWA,IAAMA,SAAS,OAAf;;EAEA,IAAMC,WAAW,IAAI,CAArB;EACA,IAAMC,cAAc,sBAApB;EACA,IAAMC,WAAW,kBAAjB;EACA,IAAMC,WAAW,eAAjB;EACA,IAAMC,WAAW,mBAAjB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,cAAcC,OAAOC,SAAP,CAAiBC,QAArC;EACA,IAAMC,OAAO,cAAb;;EAEA,IAAMC,SAAS;EACb,OADa,eACJ;EACP,0BAAoBC,UAAU,CAAV,CAApB,kBACEA,UAAU,CAAV,IAAeA,UAAU,CAAV,CAAf,WAAqCA,UAAU,CAAV,CAArC,CADF;EAGD,GALY;EAMb,OANa,eAMJ;EACP,WAAUA,UAAU,CAAV,CAAV;EACD;EARY,C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gf,SAAL,CAAe3jB,IAAf,CAAtB,EAA4CyiB,KAA5C,EAAmD,UAACvlB,GAAD,EAAS;EAC1DoR,kBAAQjS,OAAR,CAAgB,UAACqI,MAAD,EAAY;EAC1BnI,kBAAMgL,GAAN,CAAU7C,MAAV,EAAkBxH,IAAIS,UAAtB,EAAkCd,SAAlC;EACD,WAFD;EAGD,SAJD;EAKD;EACD,aAAOuE,MAAP;EACD,KAlBM,CAAP;EAmBD;EA/XW,CAAd;;AAkYA,oBAAe4jB,cAAYnhB,MAAZ,CAAmBlF,OAAnB,CAAf;;EAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECtdA;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+OA;;;;;;;;;;;;;;;;;;;AAmBA,MAAagpB,UAAU,gBAAhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ 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","../src/Relation.js","../src/Relation/BelongsTo.js","../src/Relation/HasMany.js","../src/Relation/HasOne.js","../src/relations.js","../src/decorators.js","../src/Record.js","../lib/mindex/_utils.js","../lib/mindex/index.js","../src/Collection.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.7976931348623157e308\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' () {\n return `expected: ${arguments[0]}, found: ${\n arguments[2] ? arguments[1] : typeof arguments[1]\n }`\n },\n '404' () {\n return `${arguments[0]} not found`\n }\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 (\n key &&\n dest[key] === undefined &&\n !utils.isFunction(value) &&\n key.indexOf('_') !== 0\n ) {\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 (\n relation &&\n relation.indexOf(containedName) === 0 &&\n relation.length >= containedName.length &&\n relation[containedName.length] === '.'\n ) {\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 =\n 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(\n from,\n Object.create(Object.getPrototypeOf(from)),\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\n }\n }\n }\n } else {\n if (from === to) {\n throw utils.err(`${DOMAIN}.copy`)(\n 500,\n 'Cannot copy! Source and destination are identical.'\n )\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(\n from[i],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n from[key],\n null,\n stackFrom,\n stackTo,\n blacklist,\n plain\n )\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(\n null,\n Array.prototype.slice.call(arguments, 1)\n )\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 () {\n return _events\n }\n setter = function (value) {\n _events = value\n }\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 if (fn.call(thisArg, obj[keys[i]], keys[i], obj) === false) {\n break\n }\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())) {\n // eslint-disable-line\n object = object[prop]\n if (object == null) {\n // 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 array1 = Array.isArray(array1) ? array1 : [array1]\n array2 = Array.isArray(array2) ? array2 : [array2]\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 (\n (toStr(blacklist[i]) === REGEXP_TAG && blacklist[i].test(prop)) ||\n blacklist[i] === prop\n ) {\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 (\n type === 'number' ||\n (value && type === 'object' && toStr(value) === NUMBER_TAG)\n )\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 (\n typeof value === 'string' ||\n (value && typeof value === 'object' && toStr(value) === STRING_TAG)\n )\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 ||\n 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.isArray(a) && utils.isArray(b)) {\n if (a.length !== b.length) {\n return false\n }\n for (let i = a.length; i--;) {\n if (!utils.deepEqual(a[i], b[i])) {\n // Exit loop early\n return false\n }\n }\n } else if (utils.isObject(a) && utils.isObject(b)) {\n utils.forOwn(a, function (value, key) {\n if (!(_equal = utils.deepEqual(value, b[key]))) {\n // Exit loop early\n return false\n }\n })\n if (_equal) {\n utils.forOwn(b, function (value, key) {\n if (!(_equal = utils.deepEqual(value, a[key]))) {\n // Exit loop early\n return false\n }\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())) {\n // eslint-disable-line\n object = object[path]\n if (object == null) {\n // 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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @private\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 * const JSData = require('js-data');\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');\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 Query intro\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between(18, 30, { index: 'age' })\n * .run();\n * console.log(filteredUsers);\n *\n * @example Same as above.\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users)\n * const filteredUsers = store\n * .query('user')\n * .between([18], [30], { index: 'age' })\n * .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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'draft'\n * },\n * age: {\n * '<': 30\n * }\n * }\n * })\n * .run();\n * console.log(results);\n *\n * @example Use a custom filter function\n * const posts = query\n * .filter(function (post) {\n * return post.isReady();\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post')\n * store.findAll('post').then((posts) => {\n * console.log(posts); // [...]\n * });\n *\n * @example Empty \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const posts = store.filter('post');\n * console.log(posts); // [...]\n *\n * @example Complex \"filter\" query\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * const PAGE_SIZE = 2;\n * let currentPage = 3;\n *\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 * const results = 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 * console.log(results);\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const results = 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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n * const PAGE_SIZE = 10;\n * let currentPage = 1;\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5;\n * let currentPage = 2;\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n * store.defineMapper('post');\n *\n * const PAGE_SIZE = 10\n * let currentPage = 1\n * store.findAll('post', {\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new DataStore();\n *\n * const PAGE_SIZE = 5\n * let currentPage = 2\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 * const results = store.filter('post', {\n * offset: PAGE_SIZE * (currentPage 1)\n * limit: PAGE_SIZE\n * });\n * console.log(results)\n *\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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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('user', users);\n * const ages = store\n * .query('user')\n * .map(function (user) {\n * return user.age;\n * })\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 JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * status: 'published',\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n *\n * @example Variant 2\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store.filter('post', {\n * where: {\n * status: {\n * '==': 'published'\n * }\n * },\n * limit: 2\n * });\n * console.log(publishedPosts);\n *\n * @example Variant 3\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({ status: 'published' })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Variant 4\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const publishedPosts = store\n * .query('post')\n * .filter({\n * where: {\n * status: {\n * '==': 'published'\n * }\n * }\n * })\n * .limit(2)\n * .run();\n * console.log(publishedPosts);\n *\n * @example Multiple operators\n * const JSData = require('js-data');\n * const { DataStore } = JSData;\n * console.log('Using JSData v' + JSData.version.full);\n *\n * const store = new 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 * const JSData = require('js-data');\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","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) && this !== 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 ensureLinkedDataHasProperType (props, opts) {\n const relatedMapper = this.getRelation()\n const relationData = this.getLocalField(props)\n\n if (utils.isArray(relationData) && (!relationData.length || relatedMapper.is(relationData[0]))) {\n return\n }\n\n if (relationData && !relatedMapper.is(relationData)) {\n utils.set(props, this.localField, relatedMapper.createRecord(relationData, opts))\n }\n },\n\n isRequiresParentId () {\n return false\n },\n\n isRequiresChildId () {\n return false\n },\n\n createChildRecord (props, relationData, opts) {\n this.setForeignKey(props, relationData)\n\n return this.createLinked(relationData, opts).then((result) => {\n this.setLocalField(props, result)\n })\n },\n\n createLinked (props, opts) {\n const create = utils.isArray(props) ? 'createMany' : 'create'\n\n return this.getRelation()[create](props, opts)\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 isRequiresParentId () {\n return true\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n\n return this.createLinked(relationData, opts).then((record) => {\n this.setForeignKey(props, record)\n })\n },\n\n createChildRecord () {\n throw new Error('\"BelongsTo\" relation does not support child creation as it cannot have children.')\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.relatedCollection.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 isRequiresParentId () {\n return !!this.localKeys && this.localKeys.length > 0\n },\n\n isRequiresChildId () {\n return !!this.foreignKey\n },\n\n createParentRecord (props, opts) {\n const relationData = this.getLocalField(props)\n const foreignIdField = this.getRelation().idAttribute\n\n return this.createLinked(relationData, opts).then((records) => {\n utils.set(props, this.localKeys, records.map((record) => utils.get(record, foreignIdField)))\n })\n },\n\n createLinked (props, opts) {\n return this.getRelation().createMany(props, opts)\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 isRequiresChildId () {\n return true\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * @param {boolean} [opts.validateOnSet=true] Whether to enable setter\n * validation on properties after the Record has been initialized.\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 const mapper = this.constructor.mapper\n\n _set(creatingPath, true)\n _set(noValidatePath, !!opts.noValidate)\n _set(keepChangeHistoryPath, opts.keepChangeHistory === undefined ? (mapper ? mapper.keepChangeHistory : true) : opts.keepChangeHistory)\n\n // Set the idAttribute value first, if it exists.\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 if (opts.validateOnSet !== undefined) {\n _set(noValidatePath, !opts.validateOnSet)\n } else if (mapper && mapper.validateOnSet !== undefined) {\n _set(noValidatePath, !mapper.validateOnSet)\n } else {\n _set(noValidatePath, false)\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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('changing', false)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 *\n * @method Record#toJSON\n * @param {object} [opts] Configuration options.\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, (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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 creatingPath,\n noValidatePath,\n keepChangeHistoryPath,\n previousPath\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 * const JSData = require('js-data');\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","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 Record from './Record'\nimport Index from '../lib/mindex/index'\n\nconst { noValidatePath } = Record\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 * skip\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 * Skip:\n *\n * Ignore new record, keep existing record.\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');\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 * const JSData = require('js-data');\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 {boolean} [opts.noValidate] See {@link Record#noValidate}.\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')(\n 400,\n 'object or array',\n records\n )\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 (\n onConflict !== 'merge' &&\n onConflict !== 'replace' &&\n onConflict !== 'skip'\n ) {\n throw utils.err(`${DOMAIN}#add`, 'opts.onConflict')(\n 400,\n 'one of (merge, replace, skip)',\n onConflict,\n true\n )\n }\n const existingNoValidate = existing._get(noValidatePath)\n if (opts.noValidate) {\n // Disable validation\n existing._set(noValidatePath, true)\n }\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 if(onConflict === 'skip'){ do nothing }\n\n if (opts.noValidate) {\n // Restore previous `noValidate` value\n existing._set(noValidatePath, existingNoValidate)\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()\n .between(leftKeys, rightKeys, opts)\n .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 * const JSData = require('js-data');\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((post) => post.id % 2 === 0);\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()\n .filter(query, thisArg)\n .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 =\n id === undefined\n ? []\n : this.query()\n .get(id)\n .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()\n .getAll(...args)\n .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()\n .limit(num)\n .run()\n },\n\n /**\n * Apply a mapping function to all records.\n *\n * @example\n * const names = collection.map((user) => user.name);\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((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 }\n if (!opts.silent) {\n this.emit('remove', record)\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)\n ? queryOrRecords.slice()\n : 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()\n .skip(num)\n .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 * const JSData = require('js-data');\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'\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 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\n/**\n * Validation keywords validated for any type:\n *\n * - `enum`\n * - `type`\n * - `allOf`\n * - `anyOf`\n * - `oneOf`\n * - `not`\n *\n * @name Schema.ANY_OPS\n * @type {string[]}\n */\nconst ANY_OPS = ['enum', 'type', 'allOf', 'anyOf', 'oneOf', 'not']\n\n/**\n * Validation keywords validated for array types:\n *\n * - `items`\n * - `maxItems`\n * - `minItems`\n * - `uniqueItems`\n *\n * @name Schema.ARRAY_OPS\n * @type {string[]}\n */\nconst ARRAY_OPS = ['items', 'maxItems', 'minItems', 'uniqueItems']\n\n/**\n * Validation keywords validated for numeric (number and integer) types:\n *\n * - `multipleOf`\n * - `maximum`\n * - `minimum`\n *\n * @name Schema.NUMERIC_OPS\n * @type {string[]}\n */\nconst NUMERIC_OPS = ['multipleOf', 'maximum', 'minimum']\n\n/**\n * Validation keywords validated for object types:\n *\n * - `maxProperties`\n * - `minProperties`\n * - `required`\n * - `properties`\n * - `dependencies`\n *\n * @name Schema.OBJECT_OPS\n * @type {string[]}\n */\nconst OBJECT_OPS = ['maxProperties', 'minProperties', 'required', 'properties', 'dependencies']\n\n/**\n * Validation keywords validated for string types:\n *\n * - `maxLength`\n * - `minLength`\n * - `pattern`\n *\n * @name Schema.STRING_OPS\n * @type {string[]}\n */\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 * 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 * const JSData = require('js-data');\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#apply\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, (schema, prop) => {\n Object.defineProperty(\n target,\n prop,\n this.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 * Assemble a property descriptor for tracking and validating changes to\n * a property according to the given schema. This method is called when\n * {@link Mapper#applySchema} is set to `true`.\n *\n * @name Schema#makeDescriptor\n * @method\n * @param {string} prop The property name.\n * @param {(Schema|object)} schema The schema for the property.\n * @param {object} [opts] Optional configuration.\n * @param {function} [opts.getter] Custom getter function.\n * @param {function} [opts.setter] Custom setter function.\n * @param {function} [opts.track] Whether to track changes.\n * @returns {object} A property descriptor for the given schema.\n */\n makeDescriptor (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 * 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 (value === undefined) {\n return\n }\n if (this.type === 'object') {\n let copy = {}\n const properties = this.properties\n if (properties) {\n utils.forOwn(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 // Conditionally copy properties not defined in \"properties\"\n if (this.additionalProperties) {\n for (var key in value) {\n if (!properties[key]) {\n copy[key] = utils.plainCopy(value[key])\n }\n }\n }\n return copy\n } else if (this.type === 'array') {\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 * const JSData = require('js-data');\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 *\n * @example\n * [pattern]: https://en.wikipedia.org/wiki/Data_mapper_pattern\n * [book]: http://martinfowler.com/books/eaa.html\n * [record]: Record.html\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 * const JSData = require('js-data');\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 if (!(this.schema instanceof Schema)) {\n this.schema = new Schema(this.schema || { type: 'object' })\n }\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 // Default values for arguments\n props || (props = {})\n opts || (opts = {})\n let parentRelationMap = {}\n let adapterResponse = {}\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n opts.op = 'beforeCreate'\n return this._runHook(opts.op, props, opts).then((_value) => {\n // Allow for re-assignment from lifecycle hook\n props = _value !== undefined ? _value : props\n opts.with || (opts.with = [])\n return this._createParentRecordIfRequired(props, opts)\n }).then((relationMap) => {\n parentRelationMap = relationMap\n }).then(() => {\n opts.op = 'create'\n return this._invokeAdapterMethod(opts.op, props, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdProps = opts.raw ? adapterResponse.data : adapterResponse\n\n return this._createOrAssignChildRecordIfRequired(createdProps, {\n opts,\n parentRelationMap,\n originalProps: props\n })\n }).then((createdProps) => {\n return this._commitChanges(props, createdProps)\n }).then((record) => {\n if (opts.raw) {\n adapterResponse.data = record\n } else {\n adapterResponse = record\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreate'\n return this._runHook(opts.op, props, opts, result)\n })\n },\n\n _commitChanges (recordOrRecords, newValues) {\n if (utils.isArray(recordOrRecords)) {\n return recordOrRecords.map((record, i) => this._commitChanges(record, newValues[i]))\n }\n\n utils.set(recordOrRecords, newValues, { silent: true })\n\n if (utils.isFunction(recordOrRecords.commit)) {\n recordOrRecords.commit()\n }\n\n return recordOrRecords\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 * Creates parent record for relation types like BelongsTo or HasMany with localKeys\n * in order to satisfy foreignKey dependency (so called child records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} opts See {@link Mapper#create}.\n * @returns {Object} cached parent records map\n * @see Mapper#create\n * @since 3.0.0\n */\n _createParentRecordIfRequired (props, opts) {\n const tasks = []\n const relations = []\n\n utils.forEachRelation(this, opts, (def, optsCopy) => {\n if (!def.isRequiresParentId() || !def.getLocalField(props)) {\n return\n }\n\n optsCopy.raw = false\n relations.push(def)\n tasks.push(def.createParentRecord(props, optsCopy))\n })\n\n return utils.Promise.all(tasks).then(records => {\n return relations.reduce((map, relation, index) => {\n relation.setLocalField(map, records[index])\n return map\n }, {})\n })\n },\n\n /**\n * Creates child record for relation types like HasOne or HasMany with foreignKey\n * in order to satisfy foreignKey dependency (so called parent records).\n * @param {object} props See {@link Mapper#create}.\n * @param {object} context contains collected information.\n * @param {object} context.opts See {@link Mapper#create}.\n * @param {object} context.parentRelationMap contains parent records map\n * @param {object} context.originalProps contains data passed into {@link Mapper#create} method\n * @return {Promise} updated props\n * @see Mapper#create\n * @since 3.0.0\n */\n _createOrAssignChildRecordIfRequired (props, context) {\n const tasks = []\n\n utils.forEachRelation(this, context.opts, (def, optsCopy) => {\n const relationData = def.getLocalField(context.originalProps)\n\n if (!relationData) {\n return\n }\n\n optsCopy.raw = false\n // Create hasMany and hasOne after the main create because we needed\n // a generated id to attach to these items\n if (def.isRequiresChildId()) {\n tasks.push(def.createChildRecord(props, relationData, optsCopy))\n } else if (def.isRequiresParentId()) {\n const parent = def.getLocalField(context.parentRelationMap)\n\n if (parent) {\n def.setLocalField(props, parent)\n }\n }\n })\n\n return utils.Promise.all(tasks)\n .then(() => props)\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 // Default values for arguments\n records || (records = [])\n opts || (opts = {})\n let adapterResponse\n\n // Fill in \"opts\" with the Mapper's configuration\n utils._(opts, this)\n opts.adapter = this.getAdapterName(opts)\n\n // beforeCreateMany lifecycle hook\n opts.op = 'beforeCreateMany'\n return this._runHook(opts.op, records, opts).then((_recordValues) => {\n // Allow for re-assignment from lifecycle hook\n records = _recordValues !== undefined ? _recordValues : records\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(Boolean)\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 optsCopy.raw = false\n tasks.push(def.createLinked(relationData, optsCopy).then((relatedRecords) => {\n records.forEach((record, i) => def.setForeignKey(record, relatedRecords[i]))\n }).then((relatedRecords) => {\n def.setLocalField(belongsToRelationData, relatedRecords)\n }))\n }\n })\n return utils.Promise.all(tasks).then(() => {\n opts.op = 'createMany'\n return this._invokeAdapterMethod(opts.op, records, opts)\n }).then((result) => {\n adapterResponse = result\n }).then(() => {\n const createdRecordsData = opts.raw ? adapterResponse.data : adapterResponse\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(Boolean)\n if (relationData.length !== records.length) {\n return\n }\n\n optsCopy.raw = false\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((relatedData) => {\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 return this._commitChanges(records, createdRecordsData)\n })\n })\n }).then((records) => {\n if (opts.raw) {\n adapterResponse.data = records\n } else {\n adapterResponse = records\n }\n const result = this._end(adapterResponse, opts)\n opts.op = 'afterCreateMany'\n return this._runHook(opts.op, records, opts, result)\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\n if (this.relationList) {\n this.relationList.forEach(function (def) {\n def.ensureLinkedDataHasProperType(props, opts)\n })\n }\n const RecordCtor = this.recordClass\n\n return (!RecordCtor || props instanceof RecordCtor) ? props : new RecordCtor(props, opts)\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 // force noValidate on find/findAll\n const noValidate = /find/.test(op) || opts.noValidate\n const _opts = Object.assign({}, opts, { noValidate })\n\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 _runHook (hookName, ...hookArgs) {\n const defaultValueIndex = hookName.indexOf('after') === 0 ? hookArgs.length - 1 : 0\n\n return utils.resolve(this[hookName](...hookArgs))\n .then((overridenResult) => overridenResult === undefined ? hookArgs[defaultValueIndex] : overridenResult)\n },\n\n _invokeAdapterMethod (method, propsOrRecords, opts) {\n const conversionOptions = { with: opts.pass || [] }\n let object\n\n this.dbg(opts.op, propsOrRecords, opts)\n\n if (utils.isArray(propsOrRecords)) {\n object = propsOrRecords.map(record => this.toJSON(record, conversionOptions))\n } else {\n object = this.toJSON(propsOrRecords, conversionOptions)\n }\n\n return this.getAdapter(opts.adapter)[method](this, object, opts)\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 * // \"foo\" is stripped by toJSON()\n * console.log(PersonMapper.toJSON(person)); // {\"id\":1,\"name\":\"John\"}\n *\n * const PersonRelaxedMapper = new Mapper({\n * name: 'personRelaxed',\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = PersonRelaxedMapper.createRecord({ id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(PersonRelaxedMapper.toJSON(person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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 {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\n // Copy properties defined in the schema\n if (this && this.schema) {\n json = this.schema.pick(record)\n } else {\n for (var key in record) {\n if (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 if (!schema) {\n return\n }\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\n return errors.some(Boolean) ? errors : 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 * const JSData = require('js-data');\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 * // \"foo\" is stripped by toJSON()\n * console.log(store.toJSON('person', person)); // {\"id\":1,\"name\":\"John\"}\n *\n * store.defineMapper('personRelaxed', {\n * schema: {\n * properties: {\n * name: { type: 'string' },\n * id: { type: 'string' }\n * },\n * additionalProperties: true\n * }\n * });\n * const person2 = store.createRecord('personRelaxed', { id: 1, name: 'John', foo: 'bar' });\n * // \"foo\" is not stripped by toJSON\n * console.log(store.toJSON('personRelaxed', person2)); // {\"id\":1,\"name\":\"John\",\"foo\":\"bar\"}\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');\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');\n * const { Container, Mapper } = 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');\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');\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');\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');\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');\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');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 let collectionOpts = {\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 if (opts && ('onConflict' in opts)) {\n collectionOpts.onConflict = opts.onConflict\n }\n\n // The SimpleStore uses a subclass of Collection that is \"SimpleStore-aware\"\n const collection = self._collections[name] = new self.collectionClass(null, collectionOpts) // eslint-disable-line\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\n if (opts.force || !item) {\n const promise = this._pendingQueries[name][id] = Container.prototype.find.call(this, name, id, opts)\n return promise\n .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 }\n\n return utils.resolve(item)\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\n if (opts.force || !items) {\n const promise = this._pendingQueries[name][hash] = Container.prototype.findAll.call(this, name, query, opts)\n return promise\n .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 }\n\n return utils.resolve(items)\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 if (!query || !Object.keys(query).length) {\n this._completedQueries[name] = {}\n } else {\n this._completedQueries[name][this.hashQuery(name, query, opts)] = undefined\n }\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 * const JSData = require('js-data');\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 * const JSData = require('js-data');\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 (inverseDef && 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 * const JSData = require('js-data');\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 * 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\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\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","_forRelation","opts","def","fn","thisArg","relationName","relation","containedName","index","with","_getIndex","localField","withAll","optsCopy","fillIn","getRelation","slice","_activeWith","splice","i","length","substr","list","_relation","isObject","addHiddenPropsToTarget","target","props","map","keys","propName","descriptor","getOwnPropertyDescriptor","enumerable","defineProperties","areDifferent","newObject","oldObject","diff","diffObjects","diffCount","added","removed","changed","classCallCheck","instance","ctor","err","name","copy","from","to","stackFrom","stackTo","blacklist","plain","isArray","isDate","Date","getTime","isRegExp","RegExp","source","match","lastIndex","create","getPrototypeOf","push","result","hasOwnProperty","isBlacklisted","deepFillIn","existing","deepMixIn","equalsFn","ignore","deepEqual","newKeys","filter","oldKeys","oldValue","newValue","equal","a","b","domain","code","prefix","message","apply","Array","Error","eventify","getter","setter","_events","emit","events","args","type","shift","listeners","f","c","all","unshift","off","func","on","extend","classProps","superClass","subClass","configurable","writable","obj","setPrototypeOf","strictEs6Class","__proto__","defineProperty","findIndex","array","record","forEachRelation","mapper","relationList","len","fromJson","json","isString","JSON","parse","get","prop","last","pop","getSuper","isCtor","__super__","intersection","array1","array2","item","matches","test","isBoolean","isInteger","isNull","isNumber","isSorN","isUndefined","logify","dbg","log","level","debug","toUpperCase","console","noDupeAdd","omit","_props","pick","reduce","plainCopy","reject","remove","resolve","set","_path","exec","_equal","toJson","stringify","unset","safeSetProp","field","_set","safeSetLink","Settable","_get","_unset","Component","_listeners","INDEX_ERR","reserved","limit","offset","orderBy","skip","sort","where","escapeRegExp","percentRegExp","underscoreRegExp","escape","pattern","replace","Query","collection","data","_applyWhereFromObject","fields","ops","predicates","clause","expr","op","_applyWhereFromArray","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","concat","flags","num","Math","min","mapFn","mapCall","funcName","run","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","add","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","assignTo","relationFields","canFindLinkFor","getForeignKey","idAttribute","setForeignKey","relatedRecord","_setForeignKey","relatedRecords","getLocalField","setLocalField","relatedData","getInverse","inverse","findInverseRelation","isInversedTo","addLinkedRecords","records","linkRecord","isEmptyLinks","findExistingLinksFor","removeLinkedRecords","relatedId","unsaved","findExistingLinksByForeignKey","id","ensureLinkedDataHasProperType","relationData","is","createRecord","isRequiresParentId","isRequiresChildId","createChildRecord","createLinked","then","BelongsToRelation","createParentRecord","HasManyRelation","localKeys","foreignKeys","hasForeignKeys","recordId","ids","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","foreignIdField","createMany","HasOneRelation","RelationType","belongsTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","_mapper","afterLoadRelations","beforeLoadRelations","changeHistory","changes","commit","destroy","hasChanges","quickHasChanges","isNew","isValid","validate","removeInverseRelation","currentParent","inverseDef","children","child","setupInverseRelation","loadRelations","relations","adapter","getAdapterName","tasks","task","raw","load","previous","revert","preserve","save","postProcess","changesOnly","silent","hashCode","insertAt","removeAt","binarySearch","lo","hi","compared","mid","found","Index","fieldList","fieldGetter","isIndex","values","pos","dataLocation","newIndex","results","order","visitAll","cb","leftInclusive","rightInclusive","_between","leftKey","rightKey","currKey","peek","clear","insertRecord","removeRecord","isUnique","j","updateRecord","COLLECTION_DEFAULTS","commitOnMerge","emitRecordEvents","onConflict","Collection","queryClass","indexes","_onRecordEvent","beforeAdd","singular","existingNoValidate","updateIndexes","afterAdd","afterRemove","afterRemoveAll","beforeRemove","beforeRemoveAll","createIndex","instances","prune","removeAll","Ctor","initialValue","idOrRecord","queryOrRecords","updateIndex","types","boolean","integer","number","string","segmentToString","segment","str","makePath","segments","makeError","actual","expected","addError","errors","maxLengthCommon","keyword","schema","max","minLengthCommon","validationKeywords","allOf","allErrors","_schema","anyOf","validated","dependencies","enum","possibleValues","join","items","checkingTuple","maximum","exclusiveMaximum","maxItems","maxLength","maxProperties","minimum","exclusiveMinimum","minItems","minLength","minProperties","multipleOf","not","oneOf","properties","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","eventIdPath","silentPath","validationFailureMsg","numeric","Schema","definition","_definition","extends","validationKeyword","unsetter","track","makeDescriptor","applyDefaults","hasSet","orig","keyPath","originalGet","error","current","changing","clearTimeout","setTimeout","changeRecord","timestamp","originalSet","_copy","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","count","defaults","destroyAll","find","findAll","sum","update","adapterArgs","beforeAssign","updateAll","updateMany","MAPPER_DEFAULTS","_adapters","applySchema","defaultAdapter","Mapper","lifecycleMethods","recordClass","methods","isPrototypeOf","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","parentRelationMap","adapterResponse","_runHook","_value","_createParentRecordIfRequired","relationMap","_invokeAdapterMethod","createdProps","_createOrAssignChildRecordIfRequired","originalProps","_commitChanges","recordOrRecords","newValues","createInstance","context","parent","_recordValues","belongsToRelationData","Boolean","createdRecordsData","belongsToData","createdRecordData","RecordCtor","method","config","upper","before","after","getAdapter","_opts","assign","_result","getAdapters","registerAdapter","default","hookName","hookArgs","defaultValueIndex","overridenResult","propsOrRecords","conversionOptions","pass","_record","some","defineRelations","_name","getMapperByName","getMapper","proxiedMapperMethods","Container","_mappers","mapperClass","mapperDefaults","_onMapperEvent","as","original","defineMapper","defineResource","warn","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","_completedQueries","SIMPLESTORE_DEFAULTS","usePendingFind","usePendingFindAll","SimpleStore","collectionClass","_collections","_pendingQueries","addToCache","_onCollectionEvent","cachedFind","cachedFindAll","cacheFind","cacheFindAll","hash","self","collectionOpts","_added","indexed","hashQuery","eject","ejectAll","pendingQuery","force","promise","inject","removeRelated","LinkedCollection","_addMeta","_clearMeta","event","DATASTORE_DEFAULTS","unlinkOnDestroy","DataStore","updateOpts","relatedIdAttribute","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","_key","origGet","origSet","version"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;EAWA,IAAMA,SAAS,OAAf;;EAEA,IAAMC,WAAW,IAAI,CAArB;EACA,IAAMC,cAAc,sBAApB;EACA,IAAMC,WAAW,kBAAjB;EACA,IAAMC,WAAW,eAAjB;EACA,IAAMC,WAAW,mBAAjB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,aAAa,iBAAnB;EACA,IAAMC,cAAcC,OAAOC,SAAP,CAAiBC,QAArC;EACA,IAAMC,OAAO,cAAb;;EAEA,IAAMC,SAAS;EACb,OADa,eACJ;EACP,0BAAoBC,UAAU,CAAV,CAApB,kBACEA,UAAU,CAAV,IAAeA,UAAU,CAAV,CAAf,WAAqCA,UAAU,CAAV,CAArC,CADF;EAGD,GALY;EAMb,OANa,eAMJ;EACP,WAAUA,UAAU,CAAV,CAAV;EACD;EARY,CAAf;;EAWA,IAAMC,YAAY,SAAZA,SAAY,CAAUC,KAAV,EAAiB;EACjC,MAAI,CAACA,KAAL,EAAY;EACV,WAAO,CAAP;EACD;EACD;EACAA,UAAQ,CAACA,KAAT;EACA,MAAIA,UAAUjB,QAAV,IAAsBiB,UAAU,CAACjB,QAArC,EAA+C;EAC7C,QAAMkB,OAAOD,QAAQ,CAAR,GAAY,CAAC,CAAb,GAAiB,CAA9B;EACA,WAAOC,OAAOjB,WAAd;EACD;EACD,MAAMkB,YAAYF,QAAQ,CAA1B;EACA,SAAOA,UAAUA,KAAV,GAAmBE,YAAYF,QAAQE,SAApB,GAAgCF,KAAnD,GAA4D,CAAnE,CAXiC;EAYlC,CAZD;;EAcA,IAAMG,QAAQ,SAARA,KAAQ,CAAUH,KAAV,EAAiB;EAC7B,SAAOR,YAAYY,IAAZ,CAAiBJ,KAA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a/dist/js-data.min.js +++ b/dist/js-data.min.js @@ -1,11 +1,11 @@ /*! * js-data -* @version 3.0.6 - Homepage +* @version 3.0.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={})}(this,function(e){"use strict";var o="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},b=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},f=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t=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,n){var i=-1;return e.forEach(function(e,t){return e===n?(i=t,!1):O.isObject(e)&&e.relation===n?(i=t,!1):void 0}),i},addHiddenPropsToTarget:function addHiddenPropsToTarget(e,n){var i={};Object.keys(n).forEach(function(e){var t=Object.getOwnPropertyDescriptor(n,e);t.enumerable=!1,i[e]=t}),Object.defineProperties(e,i)},areDifferent:function areDifferent(e,t,n){n||(n={});var i=O.diffObjects(e,t,n);return 0":function _(e,t){return t=":function _(e,t){return t<=e},"<":function _(e,t){return e")(400,"string",r)},canFindLinkFor:function canFindLinkFor(e){return!!(this.foreignKey||this.foreignKeys||this.localKeys&&O.get(e,this.localKeys))},linkRecord:function linkRecord(n,e){var i=this,r=this.relatedCollection,o=this.canAutoAddLinks,a=this.foreignKey,s=this.relatedCollection.unsaved();return e.map(function(e){var t=r.recordId(e);return(void 0===t&&-1===s.indexOf(e)||e!==r.get(t))&&(a&&i.setForeignKey(n,e),o&&(e=r.add(e))),e})},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:b({},this.relatedCollection.mapper.idAttribute,{in:e})})},findExistingLinksByForeignKeys:function findExistingLinksByForeignKeys(e){return this.relatedCollection.filter({where:b({},this.foreignKeys,{contains:e})})},isRequiresParentId:function isRequiresParentId(){return!!this.localKeys&&0o)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;c=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(t){var e=this.fieldList.map(function(e){return O.isFunction(e)?e(t)||void 0:t[e]||void 0});this.set(e,t)},removeRecord:function removeRecord(r){var o=this,a=void 0,s=void 0!==this.hashCode(r);return this.values.forEach(function(e,t){if(e.isIndex){if(e.removeRecord(r))return 0===e.keys.length&&(removeAt(o.keys,t),removeAt(o.values,t)),!(a=!0)}else{var n={};if(void 0!==o.keys[t]&&s)s&&(n=binarySearch(e,r,o.hashCode));else for(var i=e.length-1;0<=i;i--)if(e[i]===r){n={found:!0,index:i};break}if(n.found)return removeAt(e,n.index),0===e.length&&(removeAt(o.keys,t),removeAt(o.values,t)),!(a=!0)}}),a?r:void 0},updateRecord:function updateRecord(e){void 0!==this.removeRecord(e)&&this.insertRecord(e)}});var M=L.noValidatePath,K="Collection",N={commitOnMerge:!0,emitRecordEvents:!0,idAttribute:"id",onConflict:"merge"};var D=u.extend({constructor:function Collection(e,t){O.classCallCheck(this,Collection),u.call(this,t),e&&!O.isArray(e)&&(t=e,e=[]),O.isString(t)&&(t={idAttribute:t}),e||(e=[]),t||(t={}),Object.defineProperties(this,{mapper:{value:void 0,writable:!0},queryClass:{value:void 0,writable:!0}}),O.fillIn(this,t),O.fillIn(this,O.copy(N)),this.queryClass||(this.queryClass=y);var n=this.recordId();Object.defineProperties(this,{index:{value:new Index([n],{hashCode:function hashCode(e){return O.get(e,n)}})},indexes:{value:{}}}),(O.isObject(e)||O.isArray(e)&&e.length)&&this.add(e)},_onRecordEvent:function _onRecordEvent(){this.emitRecordEvents&&this.emit.apply(this,arguments)},add:function add(e,o){var a=this;o||(o={}),O._(o,this),e=this.beforeAdd(e,o)||e;var t=!1,s=this.recordId();if(!O.isArray(e)){if(!O.isObject(e))throw O.err(K+"#add","records")(400,"object or array",e);e=[e],t=!0}e=e.map(function(n){var e=a.recordId(n),i=void 0===e?e:a.get(e);if(n===i)return i;if(i){var t=o.onConflict||a.onConflict;if("merge"!==t&&"replace"!==t&&"skip"!==t)throw O.err(K+"#add","opts.onConflict")(400,"one of (merge, replace, skip)",t,!0);var r=i._get(M);o.noValidate&&i._set(M,!0),"merge"===t?O.deepMixIn(i,n):"replace"===t&&(O.forOwn(i,function(e,t){t!==s&&void 0===n[t]&&(i[t]=void 0)}),i.set(n)),o.noValidate&&i._set(M,r),n=i,o.commitOnMerge&&O.isFunction(n.commit)&&n.commit(),a.updateIndexes(n)}else n=a.mapper?a.mapper.createRecord(n,o):n,a.index.insertRecord(n),O.forOwn(a.indexes,function(e,t){e.insertRecord(n)}),n&&O.isFunction(n.on)&&n.on("all",a._onRecordEvent,a);return n});var n=t?e[0]:e;return o.silent||this.emit("add",n),this.afterAdd(e,o,n)||n},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$$1(e){var t=void 0===e?[]: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(K+"#getIndex",e)(404,"index");return t},limit:function limit(e){return this.query().limit(e).run()},map:function map(t,n){var i=[];return this.index.visitAll(function(e){i.push(t.call(n,e))}),i},mapCall:function mapCall(t){for(var e=arguments.length,n=Array(1r)return J(t.length,"length no more than "+r,i)},$=function minLengthCommon(e,t,n,i){var r=n[e];if(t.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,n){var i=-1;return e.forEach(function(e,t){return e===n?(i=t,!1):O.isObject(e)&&e.relation===n?(i=t,!1):void 0}),i},addHiddenPropsToTarget:function addHiddenPropsToTarget(e,n){var i={};Object.keys(n).forEach(function(e){var t=Object.getOwnPropertyDescriptor(n,e);t.enumerable=!1,i[e]=t}),Object.defineProperties(e,i)},areDifferent:function areDifferent(e,t,n){n||(n={});var i=O.diffObjects(e,t,n);return 0":function _(e,t){return t=":function _(e,t){return t<=e},"<":function _(e,t){return e")(400,"string",r)},canFindLinkFor:function canFindLinkFor(e){return!!(this.foreignKey||this.foreignKeys||this.localKeys&&O.get(e,this.localKeys))},linkRecord:function linkRecord(n,e){var i=this,r=this.relatedCollection,o=this.canAutoAddLinks,a=this.foreignKey,s=this.relatedCollection.unsaved();return e.map(function(e){var t=r.recordId(e);return(void 0===t&&-1===s.indexOf(e)||e!==r.get(t))&&(a&&i.setForeignKey(n,e),o&&(e=r.add(e))),e})},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:b({},this.relatedCollection.mapper.idAttribute,{in:e})})},findExistingLinksByForeignKeys:function findExistingLinksByForeignKeys(e){return this.relatedCollection.filter({where:b({},this.foreignKeys,{contains:e})})},isRequiresParentId:function isRequiresParentId(){return!!this.localKeys&&0o)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;c=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(t){var e=this.fieldList.map(function(e){return O.isFunction(e)?e(t)||void 0:t[e]||void 0});this.set(e,t)},removeRecord:function removeRecord(r){var o=this,a=void 0,s=void 0!==this.hashCode(r);return this.values.forEach(function(e,t){if(e.isIndex){if(e.removeRecord(r))return 0===e.keys.length&&(removeAt(o.keys,t),removeAt(o.values,t)),!(a=!0)}else{var n={};if(void 0!==o.keys[t]&&s)s&&(n=binarySearch(e,r,o.hashCode));else for(var i=e.length-1;0<=i;i--)if(e[i]===r){n={found:!0,index:i};break}if(n.found)return removeAt(e,n.index),0===e.length&&(removeAt(o.keys,t),removeAt(o.values,t)),!(a=!0)}}),a?r:void 0},updateRecord:function updateRecord(e){void 0!==this.removeRecord(e)&&this.insertRecord(e)}});var M=L.noValidatePath,K="Collection",N={commitOnMerge:!0,emitRecordEvents:!0,idAttribute:"id",onConflict:"merge"};var D=u.extend({constructor:function Collection(e,t){O.classCallCheck(this,Collection),u.call(this,t),e&&!O.isArray(e)&&(t=e,e=[]),O.isString(t)&&(t={idAttribute:t}),e||(e=[]),t||(t={}),Object.defineProperties(this,{mapper:{value:void 0,writable:!0},queryClass:{value:void 0,writable:!0}}),O.fillIn(this,t),O.fillIn(this,O.copy(N)),this.queryClass||(this.queryClass=y);var n=this.recordId();Object.defineProperties(this,{index:{value:new Index([n],{hashCode:function hashCode(e){return O.get(e,n)}})},indexes:{value:{}}}),(O.isObject(e)||O.isArray(e)&&e.length)&&this.add(e)},_onRecordEvent:function _onRecordEvent(){this.emitRecordEvents&&this.emit.apply(this,arguments)},add:function add(e,o){var a=this;o||(o={}),O._(o,this),e=this.beforeAdd(e,o)||e;var t=!1,s=this.recordId();if(!O.isArray(e)){if(!O.isObject(e))throw O.err(K+"#add","records")(400,"object or array",e);e=[e],t=!0}e=e.map(function(n){var e=a.recordId(n),i=void 0===e?e:a.get(e);if(n===i)return i;if(i){var t=o.onConflict||a.onConflict;if("merge"!==t&&"replace"!==t&&"skip"!==t)throw O.err(K+"#add","opts.onConflict")(400,"one of (merge, replace, skip)",t,!0);var r=i._get(M);o.noValidate&&i._set(M,!0),"merge"===t?O.deepMixIn(i,n):"replace"===t&&(O.forOwn(i,function(e,t){t!==s&&void 0===n[t]&&(i[t]=void 0)}),i.set(n)),o.noValidate&&i._set(M,r),n=i,o.commitOnMerge&&O.isFunction(n.commit)&&n.commit(),a.updateIndexes(n)}else n=a.mapper?a.mapper.createRecord(n,o):n,a.index.insertRecord(n),O.forOwn(a.indexes,function(e,t){e.insertRecord(n)}),n&&O.isFunction(n.on)&&n.on("all",a._onRecordEvent,a);return n});var n=t?e[0]:e;return o.silent||this.emit("add",n),this.afterAdd(e,o,n)||n},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$$1(e){var t=void 0===e?[]: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(K+"#getIndex",e)(404,"index");return t},limit:function limit(e){return this.query().limit(e).run()},map:function map(t,n){var i=[];return this.index.visitAll(function(e){i.push(t.call(n,e))}),i},mapCall:function mapCall(t){for(var e=arguments.length,n=Array(1r)return J(t.length,"length no more than "+r,i)},$=function minLengthCommon(e,t,n,i){var r=n[e];if(t.length",">=","<","<=","isectEmpty","isectNotEmpty","in","_in","notIn","contains","notContains","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","add","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","assignTo","relationFields","canFindLinkFor","getForeignKey","idAttribute","setForeignKey","relatedRecord","_setForeignKey","relatedRecords","getLocalField","setLocalField","relatedData","getInverse","inverse","findInverseRelation","isInversedTo","addLinkedRecords","records","linkRecord","findExistingLinksFor","removeLinkedRecords","relatedId","unsaved","findExistingLinksByForeignKey","id","ensureLinkedDataHasProperType","relationData","is","createRecord","isRequiresParentId","isRequiresChildId","createChildRecord","_this4","createLinked","then","createParentRecord","localKeys","foreignKeys","recordId","ids","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","foreignIdField","createMany","RelationType","belongsTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","Record$1","_mapper","DOMAIN$3","afterLoadRelations","beforeLoadRelations","changeHistory","changes","commit","destroy","hasChanges","isNew","isValid","validate","removeInverseRelation","currentParent","inverseDef","children","child","setupInverseRelation","loadRelations","relations","adapter","getAdapterName","tasks","task","raw","load","previous","revert","preserve","save","_this5","postProcess","changesOnly","silent","insertAt","removeAt","binarySearch","hashCode","lo","hi","compared","mid","found","Index","fieldList","fieldGetter","isIndex","values","pos","dataLocation","newIndex","results","order","_i","visitAll","cb","leftInclusive","rightInclusive","_between","leftKey","rightKey","_i2","currKey","peek","clear","insertRecord","removeRecord","isUnique","j","updateRecord","noValidatePath$1","DOMAIN$4","COLLECTION_DEFAULTS","commitOnMerge","emitRecordEvents","onConflict","Collection$1","Collection","queryClass","indexes","_onRecordEvent","beforeAdd","singular","existingNoValidate","updateIndexes","afterAdd","afterRemove","afterRemoveAll","beforeRemove","beforeRemoveAll","createIndex","instances","_query","prune","removeAll","initialValue","idOrRecord","queryOrRecords","updateIndex","types","boolean","integer","null","number","string","segmentToString","segment","str","makeError","actual","expected","makePath","addError","errors","maxLengthCommon","keyword","schema","max","minLengthCommon","validationKeywords","allOf","allErrors","_schema","_validate","anyOf","validated","dependencies","enum","_enum","possibleValues","join","items","checkingTuple","maximum","exclusiveMaximum","maxItems","maxLength","maxProperties","minimum","exclusiveMinimum","minItems","minLength","minProperties","multipleOf","not","oneOf","properties","additionalProperties","patternProperties","toValidate","undef","origProp","required","existingOnly","prevProp","validType","_type","validator","typeGroupValidators","uniqueItems","runOps","ANY_OPS","ARRAY_OPS","NUMERIC_OPS","OBJECT_OPS","STRING_OPS","ctx","shouldPop","DOMAIN$5","validateAny","changingPath","changedPath","changeHistoryPath","eventIdPath","numeric","Schema$1","Schema","definition","_definition","extends","validationKeyword","unsetter","track","makeDescriptor","applyDefaults","hasSet","orig","keyPath","originalGet","error","current","changing","clearTimeout","setTimeout","changeRecord","timestamp","originalSet","_copy","DOMAIN$6","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","count","defaults","destroyAll","find","findAll","sum","update","adapterArgs","beforeAssign","updateAll","updateMany","MAPPER_DEFAULTS","_adapters","applySchema","defaultAdapter","Mapper$1","Mapper","lifecycleMethods","recordClass","methods","isPrototypeOf","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","parentRelationMap","adapterResponse","_runHook","_createParentRecordIfRequired","relationMap","_invokeAdapterMethod","createdProps","_createOrAssignChildRecordIfRequired","originalProps","_commitChanges","recordOrRecords","newValues","createInstance","context","parent","originalRecords","_recordValues","belongsToRelationData","Boolean","createdRecordsData","belongsToData","createdRecordData","RecordCtor","method","_this6","config","upper","before","after","_getAdapter","getAdapter","_opts","assign","_result","getAdapters","hasMany$$1","hasOne$$1","registerAdapter","default","hookName","hookArgs","defaultValueIndex","overridenResult","propsOrRecords","_this7","conversionOptions","pass","_this8","_record","some","defineRelations","_this9","_name","getMapperByName","getMapper","DOMAIN$7","proxiedMapperMethods","Container","_mappers","mapperClass","mapperDefaults","_onMapperEvent","as","original","defineMapper","defineResource","warn","_getMapper","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","_completedQueries","SIMPLESTORE_DEFAULTS","usePendingFind","usePendingFindAll","props$1","SimpleStore","collectionClass","_collections","_pendingQueries","addToCache","_onCollectionEvent","cachedFind","cachedFindAll","cacheFind","cacheFindAll","hash","self","collectionOpts","_added","indexed","hashQuery","eject","ejectAll","pendingQuery","force","DOMAIN$8","inject","removeRelated","_this10","_this11","_this12","_this13","_getCollection","SimpleStore$1","DOMAIN$9","LinkedCollection$1","LinkedCollection","_addMeta","_clearMeta","event","DATASTORE_DEFAULTS","unlinkOnDestroy","props$2","DataStore","updateOpts","relatedIdAttribute","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","origGet","origSet","DataStore$1","version","full","major","minor","patch"],"mappings":"CAAC,SAAUA,EAAQC,GACE,iBAAZC,SAA0C,oBAAXC,OAAyBF,EAAQC,SACrD,mBAAXE,QAAyBA,OAAOC,IAAMD,OAAO,UAAW,CAAC,WAAYH,GAC3EA,EAASD,EAAOM,OAAS,IAH5B,CAIEC,KAAM,SAAWL,GAAW,aAE5B,IAAIM,EAA4B,mBAAXC,QAAoD,iBAApBA,OAAOC,SAAwB,SAAUC,GAC5F,cAAcA,GACZ,SAAUA,GACZ,OAAOA,GAAyB,mBAAXF,QAAyBE,EAAIC,cAAgBH,QAAUE,IAAQF,OAAOI,UAAY,gBAAkBF,GAGvHG,EAAiB,SAAUH,EAAKI,EAAKC,GAYvC,OAXID,KAAOJ,EACTM,OAAOH,eAAeH,EAAKI,EAAK,CAC9BC,MAAOA,EACPE,YAAY,EACZC,cAAc,EACdC,UAAU,IAGZT,EAAII,GAAOC,EAGNL,GAGLU,EAAoB,SAAUC,GAChC,GAAIC,MAAMC,QAAQF,GAAM,CACtB,IAAK,IAAIG,EAAI,EAAGC,EAAOH,MAAMD,EAAIK,QAASF,EAAIH,EAAIK,OAAQF,IAAKC,EAAKD,GAAKH,EAAIG,GAE7E,OAAOC,EAEP,OAAOH,MAAMK,KAAKN,IAsBlBO,EAAa,kBAEbC,EAAa,kBAEbC,EAAcd,OAAOJ,UAAUmB,SAC/BC,EAAO,eAEPC,EAAS,CACXC,IAAO,SAASC,IACd,MAAO,aAAeC,UAAU,GAAK,aAAeA,UAAU,GAAKA,UAAU,GAAK7B,EAAQ6B,UAAU,MAEtGC,IAAO,SAASF,IACd,OAAOC,UAAU,GAAK,eAkBtBE,EAAQ,SAASA,MAAMvB,GACzB,OAAOe,EAAYS,K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oB,EAAMxnB,SAAU,EAChBpB,EAAMgI,gBAAgBqgB,EAAO8B,UAAU7mB,GAAOslB,EAAO,SAAUloB,GAC7DsT,EAAQrS,QAAQ,SAAUoG,GACxB/H,EAAMyL,IAAI1D,EAAQrH,EAAIS,gBAAYd,OAIxC,OAAO0D,MAKT+qB,GAAcvB,GAAcpmB,OAAO6mB,IA4GvCxwB,EAAQuxB,QAPM,CACdC,KAAM,QACNC,MAAO,EACPC,MAAO,EACPC,MAAO,GAIP3xB,EAAQie,WAAaD,EACrBhe,EAAQmP,UAAYC,EACpBpP,EAAQ8sB,UAAYA,UACpB9sB,EAAQywB,UAAYa,GACpBtxB,EAAQ+b,MAAQA,MAChB/b,EAAQkwB,iBAAmBD,GAC3BjwB,EAAQonB,OAASD,GACjBnnB,EAAQmQ,MAAQD,EAChBlQ,EAAQ8Y,OAASK,EACjBnZ,EAAQokB,OAASD,GACjBnkB,EAAQ+O,SAAWA,SACnB/O,EAAQmuB,YAAc4B,GACtB/vB,EAAQwC,MAAQA,EAChBxC,EAAQoY,UAAYA,EACpBpY,EAAQqY,QAAUA,EAClBrY,EAAQsY,OAASA,EACjBtY,EAAQsU,cAAgBA,EACxBtU,EAAQuU,YAAcA,EACtBvU,EAAQwU,WAAaA,EAErBzT,OAAOH,eAAeZ,EAAS,aAAc,CAAEc,OAAO"} \ No newline at end of file +{"version":3,"sources":["dist/js-data.js"],"names":["global","factory","exports","module","define","amd","JSData","this","_typeof","Symbol","iterator","obj","constructor","prototype","defineProperty","key","value","Object","enumerable","configurable","writable","toConsumableArray","arr","Array","isArray","i","arr2","length","from","NUMBER_TAG","REGEXP_TAG","objToString","toString","PATH","ERRORS","400","_","arguments","404","toStr","call","isPlainObject","utils","Promise","dest","src","forOwn","undefined","isFunction","indexOf","_forRelation","opts","def","fn","thisArg","relationName","relation","containedName","index","with","_getIndex","localField","withAll","optsCopy","fillIn","getRelation","slice","_activeWith","splice","forEach","substr","list","_relation","isObject","addHiddenPropsToTarget","target","props","map","keys","propName","descriptor","getOwnPropertyDescriptor","defineProperties","areDifferent","newObject","oldObject","diff","diffObjects","added","removed","changed","classCallCheck","classCallCheck$$1","instance","ctor","err","name","copy","to","stackFrom","stackTo","blacklist","plain","DOMAIN","push","result","hasOwnProperty","isBlacklisted","isDate","Date","getTime","isRegExp","RegExp","source","match","lastIndex","create","getPrototypeOf","deepFillIn","existing","deepMixIn","equalsFn","ignore","deepEqual","newKeys","filter","oldKeys","oldValue","newValue","equal","a","b","domain","code","prefix","message","apply","Error","eventify","getter","setter","_events","emit","events","_len","args","_key","type","shift","listeners","f","c","all","unshift","off","func","on","extend","classProps","superClass","_subClass","subClass","_len2","_key2","setPrototypeOf","strictEs6Class","__proto__","findIndex","array","record","forEachRelation","mapper","relationList","len","fromJson","json","isString","JSON","parse","get","get$$1","object","prop","parts","split","last","pop","getSuper","isCtor","__super__","intersection","array1","array2","item","matches","test","isBoolean","isInteger","toInteger","remainder","isNull","isNumber","isSorN","isUndefined","logify","dbg","log","_len3","_key3","concat","level","_len4","_key4","debug","_console","_console2","toUpperCase","console","noDupeAdd","omit","_props","pick","reduce","plainCopy","reject","remove","resolve","set","set$$1","path","_path","exec","mkdirP","_equal","toJson","stringify","unset","safeSetProp","field","_set","safeSetLink","Settable","_get","_value","_unset","Component","Component$1","_listeners","DOMAIN$1","INDEX_ERR","reserved","limit","offset","orderBy","skip","sort","where","escapeRegExp","percentRegExp","underscoreRegExp","Query$1","Query","collection","data","_applyWhereFromObject","fields","ops","predicates","clause","==","expr","op","_applyWhereFromArray","_this","groups","_where","prev","group","isOr","_testObjectGroup","keep","first","charAt","evaluate","_testArrayGroup","between","leftKeys","rightKeys","getIndex","compare","cA","cB","temp","predicate","like","query","_this2","getData","forEachFn","keyList","getAll","_this3","pattern","flags","escape","replace","num","Math","min","mapFn","mapCall","funcName","run","=","===","!=","!==",">",">=","<","<=","isectEmpty","isectNotEmpty","in","_in","notIn","contains","notContains","belongsToType","hasManyType","hasOneType","Relation","relatedMapper","options","TYPE_NAME","validateOptions","canAutoAddLinks","add","relatedCollection","datastore","getCollection","related","DOMAIN_ERR","foreignKey","localKey","assignTo","relationFields","canFindLinkFor","getForeignKey","idAttribute","setForeignKey","relatedRecord","_setForeignKey","relatedRecords","getLocalField","setLocalField","relatedData","getInverse","inverse","findInverseRelation","isInversedTo","addLinkedRecords","records","linkRecord","findExistingLinksFor","removeLinkedRecords","relatedId","unsaved","findExistingLinksByForeignKey","id","ensureLinkedDataHasProperType","relationData","is","createRecord","isRequiresParentId","isRequiresChildId","createChildRecord","_this4","createLinked","then","createParentRecord","localKeys","foreignKeys","recordId","ids","findExistingLinksByLocalKeys","findExistingLinksByForeignKeys","foreignIdField","createMany","RelationType","belongsTo","hasMany","hasOne","superMethod","store","bind","creatingPath","noValidatePath","keepChangeHistoryPath","previousPath","Record","noValidate","keepChangeHistory","validateOnSet","toJSON","Record$1","_mapper","DOMAIN$3","afterLoadRelations","beforeLoadRelations","changeHistory","changes","commit","destroy","hasChanges","isNew","isValid","validate","removeInverseRelation","currentParent","inverseDef","children","child","setupInverseRelation","loadRelations","relations","adapter","getAdapterName","tasks","task","raw","load","previous","revert","preserve","save","_this5","postProcess","changesOnly","silent","insertAt","removeAt","binarySearch","hashCode","lo","hi","compared","mid","found","Index","fieldList","fieldGetter","isIndex","values","pos","dataLocation","newIndex","results","order","_i","visitAll","cb","leftInclusive","rightInclusive","_between","leftKey","rightKey","_i2","currKey","peek","clear","insertRecord","removeRecord","isUnique","j","updateRecord","noValidatePath$1","DOMAIN$4","COLLECTION_DEFAULTS","commitOnMerge","emitRecordEvents","onConflict","Collection$1","Collection","queryClass","indexes","_onRecordEvent","beforeAdd","singular","existingNoValidate","updateIndexes","afterAdd","afterRemove","afterRemoveAll","beforeRemove","beforeRemoveAll","createIndex","instances","_query","prune","removeAll","initialValue","idOrRecord","queryOrRecords","updateIndex","types","boolean","integer","null","number","string","segmentToString","segment","str","makeError","actual","expected","makePath","addError","errors","maxLengthCommon","keyword","schema","max","minLengthCommon","validationKeywords","allOf","allErrors","_schema","_validate","anyOf","validated","dependencies","enum","_enum","possibleValues","join","items","checkingTuple","maximum","exclusiveMaximum","maxItems","maxLength","maxProperties","minimum","exclusiveMinimum","minItems","minLength","minProperties","multipleOf","not","oneOf","properties","additionalProperties","patternProperties","toValidate","undef","origProp","required","existingOnly","prevProp","validType","_type","validator","typeGroupValidators","uniqueItems","runOps","ANY_OPS","ARRAY_OPS","NUMERIC_OPS","OBJECT_OPS","STRING_OPS","ctx","shouldPop","DOMAIN$5","validateAny","changingPath","changedPath","changeHistoryPath","eventIdPath","numeric","Schema$1","Schema","definition","_definition","extends","validationKeyword","unsetter","track","makeDescriptor","applyDefaults","hasSet","orig","keyPath","originalGet","error","current","changing","clearTimeout","setTimeout","changeRecord","timestamp","originalSet","_copy","DOMAIN$6","applyDefaultsHooks","validatingHooks","makeNotify","getSchema","toProcess","originalExistingOnly","notify","notify2","LIFECYCLE_METHODS","count","defaults","destroyAll","find","findAll","sum","update","adapterArgs","beforeAssign","updateAll","updateMany","MAPPER_DEFAULTS","_adapters","applySchema","defaultAdapter","Mapper$1","Mapper","lifecycleMethods","recordClass","methods","isPrototypeOf","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","parentRelationMap","adapterResponse","_runHook","_createParentRecordIfRequired","relationMap","_invokeAdapterMethod","createdProps","_createOrAssignChildRecordIfRequired","originalProps","_commitChanges","recordOrRecords","newValues","createInstance","context","parent","_recordValues","belongsToRelationData","Boolean","createdRecordsData","belongsToData","createdRecordData","RecordCtor","method","_this6","config","upper","before","after","_getAdapter","getAdapter","_opts","assign","_result","getAdapters","hasMany$$1","hasOne$$1","registerAdapter","default","hookName","hookArgs","defaultValueIndex","overridenResult","propsOrRecords","_this7","conversionOptions","pass","_this8","_record","some","defineRelations","_this9","_name","getMapperByName","getMapper","DOMAIN$7","proxiedMapperMethods","Container","_mappers","mapperClass","mapperDefaults","_onMapperEvent","as","original","defineMapper","defineResource","warn","_getMapper","proxiedCollectionMethods","ownMethodsForScoping","cachedFn","hashOrId","cached","_completedQueries","SIMPLESTORE_DEFAULTS","usePendingFind","usePendingFindAll","props$1","SimpleStore","collectionClass","_collections","_pendingQueries","addToCache","_onCollectionEvent","cachedFind","cachedFindAll","cacheFind","cacheFindAll","hash","self","collectionOpts","_added","indexed","hashQuery","eject","ejectAll","pendingQuery","force","DOMAIN$8","inject","removeRelated","_this10","_this11","_this12","_this13","_getCollection","SimpleStore$1","DOMAIN$9","LinkedCollection$1","LinkedCollection","_addMeta","_clearMeta","event","DATASTORE_DEFAULTS","unlinkOnDestroy","props$2","DataStore","updateOpts","relatedIdAttribute","foreignKeyDescriptor","currentParentId","storeRecord","inverseLocalField","toLink","toLinkIds","currentChildrenOfParent","parents","origGet","origSet","DataStore$1","version","full","major","minor","patch"],"mappings":"CAAC,SAAUA,EAAQC,GACE,iBAAZC,SAA0C,oBAAXC,OAAyBF,EAAQC,SACrD,mBAAXE,QAAyBA,OAAOC,IAAMD,OAAO,UAAW,CAAC,WAAYH,GAC3EA,EAASD,EAAOM,OAAS,IAH5B,CAIEC,KAAM,SAAWL,GAAW,aAE5B,IAAIM,EAA4B,mBAAXC,QAAoD,iBAApBA,OAAOC,SAAwB,SAAUC,GAC5F,cAAcA,GACZ,SAAUA,GACZ,OAAOA,GAAyB,mBAAXF,QAAyBE,EAAIC,cAAgBH,QAAUE,IAAQF,OAAOI,UAAY,gBAAkBF,GAGvHG,EAAiB,SAAUH,EAAKI,EAAKC,GAYvC,OAXID,KAAOJ,EACTM,OAAOH,eAAeH,EAAKI,EAAK,CAC9BC,MAAOA,EACPE,YAAY,EACZC,cAAc,EACdC,UAAU,IAGZT,EAAII,GAAOC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AAQuU,YAAcA,EACtBvU,EAAQwU,WAAaA,EAErBzT,OAAOH,eAAeZ,EAAS,aAAc,CAAEc,OAAO"} \ No newline at end of file diff --git a/package.json b/package.json index fa2ff42e..1b0b6eab 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "js-data", "description": "Robust, framework-agnostic in-memory data store.", - "version": "3.0.7", + "version": "3.0.8", "homepage": "http://www.js-data.io", "repository": { "type": "git", diff --git a/src/Mapper.js b/src/Mapper.js index a7ab1ee6..45fc8df1 100644 --- a/src/Mapper.js +++ b/src/Mapper.js @@ -971,7 +971,6 @@ export default Component.extend({ // Default values for arguments props || (props = {}) opts || (opts = {}) - const originalRecord = props let parentRelationMap = {} let adapterResponse = {} @@ -1001,7 +1000,7 @@ export default Component.extend({ originalProps: props }) }).then((createdProps) => { - return this._commitChanges(originalRecord, createdProps) + return this._commitChanges(props, createdProps) }).then((record) => { if (opts.raw) { adapterResponse.data = record @@ -1206,7 +1205,6 @@ export default Component.extend({ // Default values for arguments records || (records = []) opts || (opts = {}) - const originalRecords = records let adapterResponse // Fill in "opts" with the Mapper's configuration @@ -1282,7 +1280,7 @@ export default Component.extend({ } }) return utils.Promise.all(tasks).then(() => { - return this._commitChanges(originalRecords, createdRecordsData) + return this._commitChanges(records, createdRecordsData) }) }) }).then((records) => {