dist/globals/ember-data.prod.js in ember-data-source-2.15.4 vs dist/globals/ember-data.prod.js in ember-data-source-2.16.0.beta.1

- old
+ new

@@ -4,18 +4,20 @@ /*! * @overview Ember Data * @copyright Copyright 2011-2017 Tilde Inc. and contributors. * Portions Copyright 2011 LivingSocial Inc. * @license Licensed under MIT license (see license.js) - * @version 2.15.4 + * @version 2.16.0-beta.1 */ var loader, define, requireModule, require, requirejs; (function (global) { 'use strict'; + var heimdall = global.heimdall; + function dict() { var obj = Object.create(null); obj['__'] = undefined; delete obj['__']; return obj; @@ -53,13 +55,11 @@ global[newName] = global[oldName]; global[oldName] = oldGlobals[oldName]; } } } - }, - // Option to enable or disable the generation of default exports - makeDefaultExport: true + } }; var registry = dict(); var seen = dict(); @@ -105,11 +105,10 @@ // circular dependency so we must return our (partial) exports. if (this.state === 'finalized' || this.state === 'reifying') { return this.module.exports; } - if (loader.wrapModules) { this.callback = loader.wrapModules(this.id, this.callback); } this.reify(); @@ -119,13 +118,11 @@ this.state = 'finalized'; if (!(this.hasExportsAsDep && result === undefined)) { this.module.exports = result; } - if (loader.makeDefaultExport) { - this.makeDefaultExport(); - } + this.makeDefaultExport(); return this.module.exports; }; Module.prototype.unsee = function () { this.state = 'new'; @@ -279,11 +276,10 @@ function resolve(child, id) { if (child.charAt(0) !== '.') { return child; } - var parts = child.split('/'); var nameParts = id.split('/'); var parentBase = nameParts.slice(0, -1); for (var i = 0, l = parts.length; i < l; i++) { @@ -401,11 +397,11 @@ }; } exports.assertPolymorphicType = assertPolymorphicType; }); -define('ember-data/-private/adapters/build-url-mixin', ['exports', 'ember'], function (exports, _ember) { +define('ember-data/-private/adapters/build-url-mixin', ['exports', 'ember', 'ember-inflector'], function (exports, _ember, _emberInflector) { 'use strict'; exports.__esModule = true; @@ -801,24 +797,25 @@ ### Pathname customization For example if you have an object LineItem with an endpoint of "/line_items/". ```app/adapters/application.js import DS from 'ember-data'; + import { pluralize } from 'ember-inflector'; export default DS.RESTAdapter.extend({ pathForType: function(modelName) { var decamelized = Ember.String.decamelize(modelName); - return Ember.String.pluralize(decamelized); + return pluralize(decamelized); } }); ``` @method pathForType @param {String} modelName @return {String} path **/ pathForType: function (modelName) { var camelized = _ember.default.String.camelize(modelName); - return _ember.default.String.pluralize(camelized); + return (0, _emberInflector.pluralize)(camelized); } }); }); define('ember-data/-private/adapters/errors', ['exports', 'ember'], function (exports, _ember) { 'use strict'; @@ -1861,11 +1858,11 @@ IdentityMap.prototype.retrieve = function retrieve(modelName) { var map = this._map[modelName]; - if (!map) { + if (map === undefined) { map = this._map[modelName] = new _internalModelMap.default(modelName); } return map; }; @@ -1921,17 +1918,18 @@ this._models = []; this._metadata = null; } /** - A "map" of records based on their ID for this modelName + * + * @param id + * @returns {InternalModel} */ InternalModelMap.prototype.get = function get(id) { - var r = this._idToModel[id]; - return r; + return this._idToModel[id]; }; InternalModelMap.prototype.has = function has(id) { return !!this._idToModel[id]; }; @@ -1956,13 +1954,11 @@ this._models.push(internalModel); }; InternalModelMap.prototype.remove = function remove(internalModel, id) { - if (id) { - delete this._idToModel[id]; - } + delete this._idToModel[id]; var loc = this._models.indexOf(internalModel); if (loc !== -1) { this._models.splice(loc, 1); @@ -1972,39 +1968,22 @@ InternalModelMap.prototype.contains = function contains(internalModel) { return this._models.indexOf(internalModel) !== -1; }; InternalModelMap.prototype.clear = function clear() { - if (this._models) { - var models = this._models; - this._models = []; + var models = this._models; + this._models = []; - for (var i = 0; i < models.length; i++) { - var model = models[i]; - model.unloadRecord(); - } + for (var i = 0; i < models.length; i++) { + var model = models[i]; + model.unloadRecord(); } this._metadata = null; }; - InternalModelMap.prototype.destroy = function destroy() { - this._store = null; - this._modelClass = null; - }; - _createClass(InternalModelMap, [{ - key: 'idToRecord', - get: function () { - (false && !(false) && Ember.deprecate('Use of InternalModelMap.idToRecord is deprecated, use InternalModelMap.get(id) instead.', false, { - id: 'ds.record-map.idToRecord', - until: '2.13' - })); - - return this._idToModel; - } - }, { key: 'length', get: function () { return this._models.length; } }, { @@ -2299,98 +2278,15 @@ }); define('ember-data/-private/system/model/errors', ['exports', 'ember'], function (exports, _ember) { 'use strict'; exports.__esModule = true; - - - var get = _ember.default.get; - var set = _ember.default.set; - var isEmpty = _ember.default.isEmpty; - var makeArray = _ember.default.makeArray; - - var MapWithDefault = _ember.default.MapWithDefault; - - /** - @module ember-data - */ - - /** - Holds validation errors for a given record, organized by attribute names. - - Every `DS.Model` has an `errors` property that is an instance of - `DS.Errors`. This can be used to display validation error - messages returned from the server when a `record.save()` rejects. - - For Example, if you had a `User` model that looked like this: - - ```app/models/user.js - import DS from 'ember-data'; - - export default DS.Model.extend({ - username: DS.attr('string'), - email: DS.attr('string') - }); - ``` - And you attempted to save a record that did not validate on the backend: - - ```javascript - let user = store.createRecord('user', { - username: 'tomster', - email: 'invalidEmail' - }); - user.save(); - ``` - - Your backend would be expected to return an error response that described - the problem, so that error messages can be generated on the app. - - API responses will be translated into instances of `DS.Errors` differently, - depending on the specific combination of adapter and serializer used. You - may want to check the documentation or the source code of the libraries - that you are using, to know how they expect errors to be communicated. - - Errors can be displayed to the user by accessing their property name - to get an array of all the error objects for that property. Each - error object is a JavaScript object with two keys: - - - `message` A string containing the error message from the backend - - `attribute` The name of the property associated with this error message - - ```handlebars - <label>Username: {{input value=username}} </label> - {{#each model.errors.username as |error|}} - <div class="error"> - {{error.message}} - </div> - {{/each}} - - <label>Email: {{input value=email}} </label> - {{#each model.errors.email as |error|}} - <div class="error"> - {{error.message}} - </div> - {{/each}} - ``` - - You can also access the special `messages` property on the error - object to get an array of all the error strings. - - ```handlebars - {{#each model.errors.messages as |message|}} - <div class="error"> - {{message}} - </div> - {{/each}} - ``` - - @class Errors - @namespace DS - @extends Ember.Object - @uses Ember.Enumerable - @uses Ember.Evented - */ + var get = _ember.default.get, + set = _ember.default.set, + isEmpty = _ember.default.isEmpty, + makeArray = _ember.default.makeArray, + MapWithDefault = _ember.default.MapWithDefault; exports.default = _ember.default.ArrayProxy.extend(_ember.default.Evented, { /** Register with target handler @method registerHandlers @param {Object} target @@ -3058,11 +2954,15 @@ } this.send('unloadRecord'); this.dematerializeRecord(); if (this._scheduledDestroy === null) { - this._scheduledDestroy = run.schedule('destroy', this, '_checkForOrphanedInternalModels'); + // TODO: use run.schedule once we drop 1.13 + if (!_ember.default.run.currentRunLoop) { + (false && _ember.default.assert('You have turned on testing mode, which disabled the run-loop\'s autorun.\n You will need to wrap any code with asynchronous side-effects in a run', _ember.default.testing)); + } + this._scheduledDestroy = _ember.default.run.backburner.schedule('destroy', this, '_checkForOrphanedInternalModels'); } }; InternalModel.prototype.hasScheduledDestroy = function hasScheduledDestroy() { return !!this._scheduledDestroy; @@ -4494,11 +4394,11 @@ inverseKind = inverse.kind; } else { //No inverse was specified manually, we need to use a heuristic to guess one if (propertyMeta.parentType && propertyMeta.type === propertyMeta.parentType.modelName) { - (false && _ember.default.warn('Detected a reflexive relationship by the name of \'' + name + '\' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.', false, { + (false && _ember.default.warn('Detected a reflexive relationship by the name of \'' + name + '\' without an inverse option. Look at https://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.', false, { id: 'ds.model.reflexive-relationship-without-inverse' })); } var possibleRelationships = findPossibleInverses(this, inverseType, name); @@ -4510,18 +4410,18 @@ var filteredRelationships = possibleRelationships.filter(function (possibleRelationship) { var optionsForRelationship = inverseType.metaForProperty(possibleRelationship.name).options; return name === optionsForRelationship.inverse; }); - (false && _ember.default.assert("You defined the '" + name + "' relationship on " + this + ", but you defined the inverse relationships of type " + inverseType.toString() + " multiple times. Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses", filteredRelationships.length < 2)); + (false && _ember.default.assert("You defined the '" + name + "' relationship on " + this + ", but you defined the inverse relationships of type " + inverseType.toString() + " multiple times. Look at https://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses", filteredRelationships.length < 2)); if (filteredRelationships.length === 1) { possibleRelationships = filteredRelationships; } - (false && _ember.default.assert("You defined the '" + name + "' relationship on " + this + ", but multiple possible inverse relationships of type " + this + " were found on " + inverseType + ". Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses", possibleRelationships.length === 1)); + (false && _ember.default.assert("You defined the '" + name + "' relationship on " + this + ", but multiple possible inverse relationships of type " + this + " were found on " + inverseType + ". Look at https://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses", possibleRelationships.length === 1)); inverseName = possibleRelationships[0].name; inverseKind = possibleRelationships[0].kind; } @@ -4894,14 +4794,10 @@ // If it is, get the metadata for the relationship. This is // populated by the `DS.belongsTo` helper when it is creating // the computed property. var meta = value.meta(); - /* - This is buggy because if the parent has never been looked up - via `modelFor` it will not have `modelName` set. - */ meta.parentType = proto.constructor; } } }); } @@ -6170,11 +6066,11 @@ this.isDestroyed = true; }; RecordArrayManager.prototype.destroy = function destroy() { this.isDestroying = true; - _ember.default.run.schedule('actions', this, this.willDestroy); + emberRun.schedule('actions', this, this.willDestroy); }; return RecordArrayManager; }(); @@ -6973,10 +6869,11 @@ userRef.value(); // null userRef.load().then(function(user) { userRef.value() === user }); + ``` @method load @return {Promise} a promise that resolves with the record in this belongs-to relationship. */ BelongsToReference.prototype.load = function () { @@ -7021,10 +6918,11 @@ let userRef = blog.belongsTo('user'); userRef.reload().then(function(user) { userRef.value() === user }); + ``` @method reload @return {Promise} a promise that resolves with the record in this belongs-to relationship after the reload has completed. */ BelongsToReference.prototype.reload = function () { @@ -7346,11 +7244,11 @@ return internalModel.isLoaded() === true; }); }; /** - `value()` sycronously returns the current value of the has-many + `value()` synchronously returns the current value of the has-many relationship. Unlike `record.get('relationshipName')`, calling `value()` on a reference does not trigger a fetch if the async relationship is not yet loaded. If the relationship is not loaded it will always return `null`. @@ -7679,19 +7577,25 @@ } return modelName; } function relationshipFromMeta(meta) { - return { + var result = { key: meta.key, kind: meta.kind, type: typeForRelationshipMeta(meta), options: meta.options, name: meta.name, parentType: meta.parentType, isRelationship: true }; + + if (false) { + result.parentType = meta.parentType; + } + + return result; } }); define('ember-data/-private/system/relationships/belongs-to', ['exports', 'ember', 'ember-data/-private/system/normalize-model-name'], function (exports, _ember, _normalizeModelName) { 'use strict'; @@ -7801,17 +7705,17 @@ }; return _ember.default.computed({ get: function (key) { if (opts.hasOwnProperty('serialize')) { - (false && _ember.default.warn('You provided a serialize option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.Serializer and it\'s implementations http://emberjs.com/api/data/classes/DS.Serializer.html', false, { + (false && _ember.default.warn('You provided a serialize option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.Serializer and it\'s implementations https://emberjs.com/api/data/classes/DS.Serializer.html', false, { id: 'ds.model.serialize-option-in-belongs-to' })); } if (opts.hasOwnProperty('embedded')) { - (false && _ember.default.warn('You provided an embedded option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html', false, { + (false && _ember.default.warn('You provided an embedded option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin https://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html', false, { id: 'ds.model.embedded-option-in-belongs-to' })); } return this._internalModel._relationships.get(key).getRecord(); @@ -8093,12 +7997,11 @@ if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - var get = _ember.default.get; - var assert = _ember.default.assert; + var _get = _ember.default.get; /** Manages relationship payloads for a given store, for uninitialized relationships. Acts as a single source of truth (of payloads) for both sides of an uninitialized relationship so they can agree on the most up-to-date @@ -8155,11 +8058,10 @@ var RelationshipPayloadsManager = function () { function RelationshipPayloadsManager(store) { this._store = store; // cache of `RelationshipPayload`s this._cache = Object.create(null); - this._inverseLookupCache = new _relationshipPayloads.TypeCache(); } /** Find the payload for the given relationship of the given model. Returns the payload for the given relationship, whether raw or computed from @@ -8176,194 +8078,90 @@ @method */ RelationshipPayloadsManager.prototype.get = function get(modelName, id, relationshipName) { - var relationshipPayloads = this._getRelationshipPayloads(modelName, relationshipName, false); + var modelClass = this._store._modelFor(modelName); + var relationshipsByName = _get(modelClass, 'relationshipsByName'); + var relationshipPayloads = this._getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, false); return relationshipPayloads && relationshipPayloads.get(modelName, id, relationshipName); }; RelationshipPayloadsManager.prototype.push = function push(modelName, id, relationshipsData) { var _this = this; if (!relationshipsData) { return; } + var modelClass = this._store._modelFor(modelName); + var relationshipsByName = _get(modelClass, 'relationshipsByName'); Object.keys(relationshipsData).forEach(function (key) { - var relationshipPayloads = _this._getRelationshipPayloads(modelName, key, true); + var relationshipPayloads = _this._getRelationshipPayloads(modelName, key, modelClass, relationshipsByName, true); if (relationshipPayloads) { relationshipPayloads.push(modelName, id, key, relationshipsData[key]); } }); }; RelationshipPayloadsManager.prototype.unload = function unload(modelName, id) { var _this2 = this; var modelClass = this._store._modelFor(modelName); - var relationshipsByName = get(modelClass, 'relationshipsByName'); + var relationshipsByName = _get(modelClass, 'relationshipsByName'); relationshipsByName.forEach(function (_, relationshipName) { - var relationshipPayloads = _this2._getRelationshipPayloads(modelName, relationshipName, false); + var relationshipPayloads = _this2._getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, false); if (relationshipPayloads) { relationshipPayloads.unload(modelName, id, relationshipName); } }); }; - RelationshipPayloadsManager.prototype._getRelationshipPayloads = function _getRelationshipPayloads(modelName, relationshipName, init) { - var relInfo = this.getRelationshipInfo(modelName, relationshipName); - - if (relInfo === null) { + RelationshipPayloadsManager.prototype._getRelationshipPayloads = function _getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, init) { + if (!relationshipsByName.has(relationshipName)) { return; } - var cache = this._cache[relInfo.lhs_key]; - - if (!cache && init) { - return this._initializeRelationshipPayloads(relInfo); + var key = modelName + ':' + relationshipName; + if (!this._cache[key] && init) { + return this._initializeRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName); } - return cache; + return this._cache[key]; }; - RelationshipPayloadsManager.prototype.getRelationshipInfo = function getRelationshipInfo(modelName, relationshipName) { - var inverseCache = this._inverseLookupCache; - var store = this._store; - var cached = inverseCache.get(modelName, relationshipName); - - // CASE: We have a cached resolution (null if no relationship exists) - if (cached !== undefined) { - return cached; - } - - var modelClass = store._modelFor(modelName); - var relationshipsByName = get(modelClass, 'relationshipsByName'); - - // CASE: We don't have a relationship at all - if (!relationshipsByName.has(relationshipName)) { - inverseCache.set(modelName, relationshipName, null); - return null; - } - - var inverseMeta = modelClass.inverseFor(relationshipName, store); + RelationshipPayloadsManager.prototype._initializeRelationshipPayloads = function _initializeRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName) { var relationshipMeta = relationshipsByName.get(relationshipName); - var selfIsPolymorphic = relationshipMeta.options !== undefined && relationshipMeta.options.polymorphic === true; - var inverseBaseModelName = relationshipMeta.type; + var inverseMeta = modelClass.inverseFor(relationshipName, this._store); - // CASE: We have no inverse - if (!inverseMeta) { - var _info = { - lhs_key: modelName + ':' + relationshipName, - lhs_modelNames: [modelName], - lhs_baseModelName: modelName, - lhs_relationshipName: relationshipName, - lhs_relationshipMeta: relationshipMeta, - lhs_isPolymorphic: selfIsPolymorphic, - rhs_key: '', - rhs_modelNames: [], - rhs_baseModelName: inverseBaseModelName, - rhs_relationshipName: '', - rhs_relationshipMeta: null, - rhs_isPolymorphic: false, - hasInverse: false, - isSelfReferential: false, // modelName === inverseBaseModelName, - isReflexive: false - }; + var inverseModelName = void 0; + var inverseRelationshipName = void 0; + var inverseRelationshipMeta = void 0; - inverseCache.set(modelName, relationshipName, _info); - - return _info; + // figure out the inverse relationship; we need two things + // a) the inverse model name + //- b) the name of the inverse relationship + if (inverseMeta) { + inverseRelationshipName = inverseMeta.name; + inverseModelName = relationshipMeta.type; + inverseRelationshipMeta = _get(inverseMeta.type, 'relationshipsByName').get(inverseRelationshipName); + } else { + // relationship has no inverse + inverseModelName = inverseRelationshipName = ''; + inverseRelationshipMeta = null; } - // CASE: We do have an inverse + var lhsKey = modelName + ':' + relationshipName; + var rhsKey = inverseModelName + ':' + inverseRelationshipName; - var inverseRelationshipName = inverseMeta.name; - var inverseRelationshipMeta = get(inverseMeta.type, 'relationshipsByName').get(inverseRelationshipName); - var baseModelName = inverseRelationshipMeta.type; - var isSelfReferential = baseModelName === inverseBaseModelName; - - // TODO we want to assert this but this breaks all of our shoddily written tests - /* - if (DEBUG) { - let inverseDoubleCheck = inverseMeta.type.inverseFor(inverseRelationshipName, store); - assert(`The ${inverseBaseModelName}:${inverseRelationshipName} relationship declares 'inverse: null', but it was resolved as the inverse for ${baseModelName}:${relationshipName}.`, inverseDoubleCheck); - } - */ - - // CASE: We may have already discovered the inverse for the baseModelName - // CASE: We have already discovered the inverse - cached = inverseCache.get(baseModelName, relationshipName) || inverseCache.get(inverseBaseModelName, inverseRelationshipName); - if (cached) { - // TODO this assert can be removed if the above assert is enabled - assert('The ' + inverseBaseModelName + ':' + inverseRelationshipName + ' relationship declares \'inverse: null\', but it was resolved as the inverse for ' + baseModelName + ':' + relationshipName + '.', cached.hasInverse !== false); - - var isLHS = cached.lhs_baseModelName === baseModelName; - var modelNames = isLHS ? cached.lhs_modelNames : cached.rhs_modelNames; - // make this lookup easier in the future by caching the key - modelNames.push(modelName); - inverseCache.set(modelName, relationshipName, cached); - - return cached; - } - - var info = { - lhs_key: baseModelName + ':' + relationshipName, - lhs_modelNames: [modelName], - lhs_baseModelName: baseModelName, - lhs_relationshipName: relationshipName, - lhs_relationshipMeta: relationshipMeta, - lhs_isPolymorphic: selfIsPolymorphic, - rhs_key: inverseBaseModelName + ':' + inverseRelationshipName, - rhs_modelNames: [], - rhs_baseModelName: inverseBaseModelName, - rhs_relationshipName: inverseRelationshipName, - rhs_relationshipMeta: inverseRelationshipMeta, - rhs_isPolymorphic: inverseRelationshipMeta.options !== undefined && inverseRelationshipMeta.options.polymorphic === true, - hasInverse: true, - isSelfReferential: isSelfReferential, - isReflexive: isSelfReferential && relationshipName === inverseRelationshipName - }; - - // Create entries for the baseModelName as well as modelName to speed up - // inverse lookups - inverseCache.set(baseModelName, relationshipName, info); - inverseCache.set(modelName, relationshipName, info); - - // Greedily populate the inverse - inverseCache.set(inverseBaseModelName, inverseRelationshipName, info); - - return info; - }; - - RelationshipPayloadsManager.prototype._initializeRelationshipPayloads = function _initializeRelationshipPayloads(relInfo) { - var lhsKey = relInfo.lhs_key; - var rhsKey = relInfo.rhs_key; - var existingPayloads = this._cache[lhsKey]; - - if (relInfo.hasInverse === true && relInfo.rhs_isPolymorphic === true) { - existingPayloads = this._cache[rhsKey]; - - if (existingPayloads !== undefined) { - this._cache[lhsKey] = existingPayloads; - return existingPayloads; - } - } - // populate the cache for both sides of the relationship, as they both use // the same `RelationshipPayloads`. // // This works out better than creating a single common key, because to // compute that key we would need to do work to look up the inverse // - var cache = this._cache[lhsKey] = new _relationshipPayloads.default(relInfo); - - if (relInfo.hasInverse === true) { - this._cache[rhsKey] = cache; - } - - return cache; + return this._cache[lhsKey] = this._cache[rhsKey] = new _relationshipPayloads.default(this._store, modelName, relationshipName, relationshipMeta, inverseModelName, inverseRelationshipName, inverseRelationshipMeta); }; return RelationshipPayloadsManager; }(); @@ -8372,10 +8170,16 @@ define('ember-data/-private/system/relationships/relationship-payloads', ['exports'], function (exports) { 'use strict'; exports.__esModule = true; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; @@ -8390,87 +8194,65 @@ if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } + var RelationshipPayloads = function () { + function RelationshipPayloads(store, modelName, relationshipName, relationshipMeta, inverseModelName, inverseRelationshipName, inverseRelationshipMeta) { + this._store = store; - var TypeCache = exports.TypeCache = function () { - function TypeCache() { - this.types = Object.create(null); - } + this._lhsModelName = modelName; + this._lhsRelationshipName = relationshipName; + this._lhsRelationshipMeta = relationshipMeta; - TypeCache.prototype.get = function get(modelName, id) { - var types = this.types; + this._rhsModelName = inverseModelName; + this._rhsRelationshipName = inverseRelationshipName; + this._rhsRelationshipMeta = inverseRelationshipMeta; - - if (types[modelName] !== undefined) { - return types[modelName][id]; + // a map of id -> payloads for the left hand side of the relationship. + this._lhsPayloads = Object.create(null); + if (modelName !== inverseModelName || relationshipName !== inverseRelationshipName) { + // The common case of a non-reflexive relationship, or a reflexive + // relationship whose inverse is not itself + this._rhsPayloads = Object.create(null); + this._isReflexive = false; + } else { + // Edge case when we have a reflexive relationship to itself + // eg user hasMany friends inverse friends + // + // In this case there aren't really two sides to the relationship, but + // we set `_rhsPayloads = _lhsPayloads` to make things easier to reason + // about + this._rhsPayloads = this._lhsPayloads; + this._isReflexive = true; } - }; - TypeCache.prototype.set = function set(modelName, id, payload) { - var types = this.types; - - var typeMap = types[modelName]; - - if (typeMap === undefined) { - typeMap = types[modelName] = Object.create(null); - } - - typeMap[id] = payload; - }; - - TypeCache.prototype.delete = function _delete(modelName, id) { - var types = this.types; - - - if (types[modelName] !== undefined) { - delete types[modelName][id]; - } - }; - - return TypeCache; - }(); - - var RelationshipPayloads = function () { - function RelationshipPayloads(relInfo) { - this._relInfo = relInfo; - - // a map of id -> payloads for the left hand side of the relationship. - this.lhs_payloads = new TypeCache(); - this.rhs_payloads = relInfo.isReflexive ? this.lhs_payloads : new TypeCache(); - // When we push relationship payloads, just stash them in a queue until // somebody actually asks for one of them. // // This is a queue of the relationship payloads that have been pushed for // either side of this relationship this._pendingPayloads = []; } /** - Get the payload for the relationship of an individual record. - This might return the raw payload as pushed into the store, or one computed - from the payload of the inverse relationship. - @method - */ + Get the payload for the relationship of an individual record. + This might return the raw payload as pushed into the store, or one computed + from the payload of the inverse relationship. + @method + */ RelationshipPayloads.prototype.get = function get(modelName, id, relationshipName) { this._flushPending(); if (this._isLHS(modelName, relationshipName)) { - return this.lhs_payloads.get(modelName, id); + return this._lhsPayloads[id]; } else { - (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_key + '<->' + this._relInfo.rhs_key, this._isRHS(modelName, relationshipName))); + (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName))); - return this.rhs_payloads.get(modelName, id); + return this._rhsPayloads[id]; } }; RelationshipPayloads.prototype.push = function push(modelName, id, relationshipName, relationshipData) { this._pendingPayloads.push([modelName, id, relationshipName, relationshipData]); @@ -8478,44 +8260,24 @@ RelationshipPayloads.prototype.unload = function unload(modelName, id, relationshipName) { this._flushPending(); if (this._isLHS(modelName, relationshipName)) { - delete this.lhs_payloads.delete(modelName, id); + delete this._lhsPayloads[id]; } else { - (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_baseModelName + ':' + this._relInfo.lhs_relationshipName + '<->' + this._relInfo.rhs_baseModelName + ':' + this._relInfo.rhs_relationshipName, this._isRHS(modelName, relationshipName))); + (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName))); - delete this.rhs_payloads.delete(modelName, id); + delete this._rhsPayloads[id]; } }; RelationshipPayloads.prototype._isLHS = function _isLHS(modelName, relationshipName) { - var relInfo = this._relInfo; - var isSelfReferential = relInfo.isSelfReferential; - var isRelationship = relationshipName === relInfo.lhs_relationshipName; - - if (isRelationship === true) { - return isSelfReferential === true || // itself - modelName === relInfo.lhs_baseModelName || // base or non-polymorphic - relInfo.lhs_modelNames.indexOf(modelName) !== -1; // polymorphic - } - - return false; + return modelName === this._lhsModelName && relationshipName === this._lhsRelationshipName; }; RelationshipPayloads.prototype._isRHS = function _isRHS(modelName, relationshipName) { - var relInfo = this._relInfo; - var isSelfReferential = relInfo.isSelfReferential; - var isRelationship = relationshipName === relInfo.rhs_relationshipName; - - if (isRelationship === true) { - return isSelfReferential === true || // itself - modelName === relInfo.rhs_baseModelName || // base or non-polymorphic - relInfo.rhs_modelNames.indexOf(modelName) !== -1; // polymorphic - } - - return false; + return modelName === this._rhsModelName && relationshipName === this._rhsRelationshipName; }; RelationshipPayloads.prototype._flushPending = function _flushPending() { if (this._pendingPayloads.length === 0) { return; @@ -8532,32 +8294,30 @@ var inverseRelationshipData = { data: { id: id, type: modelName } - }; - // start flushing this individual payload. The logic is the same whether - // it's for the left hand side of the relationship or the right hand side, - // except the role of primary and inverse idToPayloads is reversed - // - var previousPayload = void 0; - var payloadMap = void 0; - var inversePayloadMap = void 0; + // start flushing this individual payload. The logic is the same whether + // it's for the left hand side of the relationship or the right hand side, + // except the role of primary and inverse idToPayloads is reversed + // + };var previousPayload = void 0; + var idToPayloads = void 0; + var inverseIdToPayloads = void 0; var inverseIsMany = void 0; - if (this._isLHS(modelName, relationshipName)) { - previousPayload = this.lhs_payloads.get(modelName, id); - payloadMap = this.lhs_payloads; - inversePayloadMap = this.rhs_payloads; + previousPayload = this._lhsPayloads[id]; + idToPayloads = this._lhsPayloads; + inverseIdToPayloads = this._rhsPayloads; inverseIsMany = this._rhsRelationshipIsMany; } else { - (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_key + '<->' + this._relInfo.rhs_key, this._isRHS(modelName, relationshipName))); + (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName))); - previousPayload = this.rhs_payloads.get(modelName, id); - payloadMap = this.rhs_payloads; - inversePayloadMap = this.lhs_payloads; + previousPayload = this._rhsPayloads[id]; + idToPayloads = this._rhsPayloads; + inverseIdToPayloads = this._lhsPayloads; inverseIsMany = this._lhsRelationshipIsMany; } // actually flush this individual payload // @@ -8597,69 +8357,67 @@ // only remove relationship information before adding if there is relationshipData.data // * null is considered new information "empty", and it should win // * undefined is NOT considered new information, we should keep original state // * anything else is considered new information, and it should win if (relationshipData.data !== undefined) { - this._removeInverse(id, previousPayload, inversePayloadMap); + this._removeInverse(id, previousPayload, inverseIdToPayloads); } - payloadMap.set(modelName, id, relationshipData); - this._populateInverse(relationshipData, inverseRelationshipData, inversePayloadMap, inverseIsMany); + idToPayloads[id] = relationshipData; + this._populateInverse(relationshipData, inverseRelationshipData, inverseIdToPayloads, inverseIsMany); } }; - RelationshipPayloads.prototype._populateInverse = function _populateInverse(relationshipData, inversePayload, inversePayloadMap, inverseIsMany) { + RelationshipPayloads.prototype._populateInverse = function _populateInverse(relationshipData, inversePayload, inverseIdToPayloads, inverseIsMany) { if (!relationshipData.data) { // This id doesn't have an inverse, eg a belongsTo with a payload // { data: null }, so there's nothing to populate return; } if (Array.isArray(relationshipData.data)) { for (var i = 0; i < relationshipData.data.length; ++i) { - var resourceIdentifier = relationshipData.data[i]; - this._addToInverse(inversePayload, resourceIdentifier, inversePayloadMap, inverseIsMany); + var inverseId = relationshipData.data[i].id; + this._addToInverse(inversePayload, inverseId, inverseIdToPayloads, inverseIsMany); } } else { - var _resourceIdentifier = relationshipData.data; - this._addToInverse(inversePayload, _resourceIdentifier, inversePayloadMap, inverseIsMany); + var _inverseId = relationshipData.data.id; + this._addToInverse(inversePayload, _inverseId, inverseIdToPayloads, inverseIsMany); } }; - RelationshipPayloads.prototype._addToInverse = function _addToInverse(inversePayload, resourceIdentifier, inversePayloadMap, inverseIsMany) { - var relInfo = this._relInfo; - - if (relInfo.isReflexive && inversePayload.data.id === resourceIdentifier.id) { + RelationshipPayloads.prototype._addToInverse = function _addToInverse(inversePayload, inverseId, inverseIdToPayloads, inverseIsMany) { + if (this._isReflexive && inversePayload.data.id === inverseId) { // eg <user:1>.friends = [{ id: 1, type: 'user' }] return; } - var existingPayload = inversePayloadMap.get(resourceIdentifier.type, resourceIdentifier.id); + var existingPayload = inverseIdToPayloads[inverseId]; var existingData = existingPayload && existingPayload.data; if (existingData) { // There already is an inverse, either add or overwrite depehnding on // whether the inverse is a many relationship or not // if (Array.isArray(existingData)) { existingData.push(inversePayload.data); } else { - inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, inversePayload); + inverseIdToPayloads[inverseId] = inversePayload; } } else { // first time we're populating the inverse side // if (inverseIsMany) { - inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, { + inverseIdToPayloads[inverseId] = { data: [inversePayload.data] - }); + }; } else { - inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, inversePayload); + inverseIdToPayloads[inverseId] = inversePayload; } } }; - RelationshipPayloads.prototype._removeInverse = function _removeInverse(id, previousPayload, inversePayloadMap) { + RelationshipPayloads.prototype._removeInverse = function _removeInverse(id, previousPayload, inverseIdToPayloads) { var data = previousPayload && previousPayload.data; if (!data) { // either this is the first time we've seen a payload for this id, or its // previous payload indicated that it had no inverse, eg a belongsTo // relationship with payload { data: null } @@ -8670,20 +8428,19 @@ } if (Array.isArray(data)) { // TODO: diff rather than removeall addall? for (var i = 0; i < data.length; ++i) { - var resourceIdentifier = data[i]; - this._removeFromInverse(id, resourceIdentifier, inversePayloadMap); + this._removeFromInverse(id, data[i].id, inverseIdToPayloads); } } else { - this._removeFromInverse(id, data, inversePayloadMap); + this._removeFromInverse(id, data.id, inverseIdToPayloads); } }; - RelationshipPayloads.prototype._removeFromInverse = function _removeFromInverse(id, resourceIdentifier, inversePayloads) { - var inversePayload = inversePayloads.get(resourceIdentifier.type, resourceIdentifier.id); + RelationshipPayloads.prototype._removeFromInverse = function _removeFromInverse(id, inverseId, inversePayloads) { + var inversePayload = inversePayloads[inverseId]; var data = inversePayload && inversePayload.data; if (!data) { return; } @@ -8691,27 +8448,25 @@ if (Array.isArray(data)) { inversePayload.data = data.filter(function (x) { return x.id !== id; }); } else { - inversePayloads.set(resourceIdentifier.type, resourceIdentifier.id, { + inversePayloads[inverseId] = { data: null - }); + }; } }; _createClass(RelationshipPayloads, [{ key: '_lhsRelationshipIsMany', get: function () { - var meta = this._relInfo.lhs_relationshipMeta; - return meta !== null && meta.kind === 'hasMany'; + return this._lhsRelationshipMeta && this._lhsRelationshipMeta.kind === 'hasMany'; } }, { key: '_rhsRelationshipIsMany', get: function () { - var meta = this._relInfo.rhs_relationshipMeta; - return meta !== null && meta.kind === 'hasMany'; + return this._rhsRelationshipMeta && this._rhsRelationshipMeta.kind === 'hasMany'; } }]); return RelationshipPayloads; }(); @@ -9155,11 +8910,11 @@ if (content) { this.__loadingPromise.set('content', content); } this.__loadingPromise.set('promise', promise); } else { - this.__loadingPromise = new _promiseProxies.PromiseManyArray({ + this.__loadingPromise = _promiseProxies.PromiseManyArray.create({ promise: promise, content: content }); } @@ -9351,10 +9106,11 @@ _this2.updateMeta(records.meta); } _this2.store._backburner.join(function () { _this2.updateInternalModelsFromAdapter(records); _this2.manyArray.set('isLoaded', true); + _this2.setHasData(true); }); return _this2.manyArray; }); }; @@ -9796,10 +9552,11 @@ }); } }; Relationship.prototype.updateInternalModelsFromAdapter = function updateInternalModelsFromAdapter(internalModels) { + this.setHasData(true); //TODO(Igor) move this to a proper place //TODO Once we have adapter support, we need to handle updated and canonical changes this.computeChanges(internalModels); }; @@ -10376,11 +10133,11 @@ `store#push` that will deserialize payloads if the Serializer implements a `pushPayload` method. Note: When creating a new record using any of the above methods Ember Data will update `DS.RecordArray`s such as those returned by - `store#peekAll()`, `store#findAll()` or `store#filter()`. This means any + `store#peekAll()` or `store#findAll()`. This means any data bindings or computed properties that depend on the RecordArray will automatically be synced to include the new or updated record values. @class Store @@ -10774,11 +10531,11 @@ }); ``` See [peekRecord](#method_peekRecord) to get the cached version of a record. ### Retrieving Related Model Records If you use an adapter such as Ember's default - [`JSONAPIAdapter`](http://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html) + [`JSONAPIAdapter`](https://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html) that supports the [JSON API specification](http://jsonapi.org/) and if your server endpoint supports the use of an ['include' query parameter](http://jsonapi.org/format/#fetching-includes), you can use `findRecord()` to automatically retrieve additional records related to the one you request by supplying an `include` parameter in the `options` object. @@ -11345,11 +11102,11 @@ Started GET "/api/v1/person?ids%5B%5D=1&ids%5B%5D=2&ids%5B%5D=3" Processing by Api::V1::PersonsController#index as HTML Parameters: { "ids" => ["1", "2", "3"] } ``` This method returns a promise, which is resolved with an - [`AdapterPopulatedRecordArray`](http://emberjs.com/api/data/classes/DS.AdapterPopulatedRecordArray.html) + [`AdapterPopulatedRecordArray`](https://emberjs.com/api/data/classes/DS.AdapterPopulatedRecordArray.html) once the server returns. @since 1.13.0 @method query @param {String} modelName @param {any} query an opaque query to be used by the adapter @@ -11596,11 +11353,11 @@ ``` See [peekAll](#method_peekAll) to get an array of current records in the store, without waiting until a reload is finished. ### Retrieving Related Model Records If you use an adapter such as Ember's default - [`JSONAPIAdapter`](http://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html) + [`JSONAPIAdapter`](https://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html) that supports the [JSON API specification](http://jsonapi.org/) and if your server endpoint supports the use of an ['include' query parameter](http://jsonapi.org/format/#fetching-includes), you can use `findAll()` to automatically retrieve additional records related to those requested by supplying an `include` parameter in the `options` object. @@ -11897,11 +11654,12 @@ var internalModel = snapshot._internalModel; var adapter = this.adapterFor(internalModel.modelName); var operation = void 0; if (internalModel.currentState.stateName === 'root.deleted.saved') { - return resolver.resolve(); + resolver.resolve(); + continue; } else if (internalModel.isNew()) { operation = 'createRecord'; } else if (internalModel.isDeleted()) { operation = 'deleteRecord'; } else { @@ -12098,11 +11856,11 @@ /** Returns the model class for the particular `modelName`. The class of a model might be useful if you want to get a list of all the relationship names of the model, see - [`relationshipNames`](http://emberjs.com/api/data/classes/DS.Model.html#property_relationshipNames) + [`relationshipNames`](https://emberjs.com/api/data/classes/DS.Model.html#property_relationshipNames) for example. @method modelFor @param {String} modelName @return {DS.Model} */ @@ -12431,13 +12189,14 @@ // Cache the inverse maps for each modelClass that we visit during this // payload push. In the common case where we are pushing many more // instances than types we want to minimize the cost of looking up the // inverse map and the overhead of Ember.get adds up. - var modelNameToInverseMap = Object.create(null); + var modelNameToInverseMap = void 0; for (var i = 0, l = pushed.length; i < l; i += 2) { + modelNameToInverseMap = modelNameToInverseMap || Object.create(null); // This will convert relationships specified as IDs into DS.Model instances // (possibly unloaded) and also create the data structures used to track // relationships. var internalModel = pushed[i]; var data = pushed[i + 1]; @@ -12853,17 +12612,12 @@ return _inverseInternalModel && _inverseInternalModel._relationships.has(inverseRelationshipName); } } function setupRelationships(store, internalModel, data, modelNameToInverseMap) { - var relationships = internalModel._relationships; - - internalModel.type.eachRelationship(function (relationshipName) { - if (!data.relationships[relationshipName]) { - return; - } - + Object.keys(data.relationships).forEach(function (relationshipName) { + var relationships = internalModel._relationships; var relationshipRequiresNotification = relationships.has(relationshipName) || isInverseRelationshipInitialized(store, internalModel, data, relationshipName, modelNameToInverseMap); if (relationshipRequiresNotification) { var relationshipData = data.relationships[relationshipName]; relationships.get(relationshipName).push(relationshipData, false); @@ -13068,11 +12822,11 @@ (false && _ember.default.assert('You made a \'findRecord\' request for a \'' + modelName + '\' with id \'' + id + '\', but the adapter\'s response did not have any data', payloadIsNotBlank(adapterPayload))); var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName); var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, id, 'findRecord'); (false && _ember.default.assert('Ember Data expected the primary data returned from a \'findRecord\' response to be an object but instead it found an array.', !Array.isArray(payload.data))); - (false && _ember.default.warn('You requested a record of type \'' + modelName + '\' with id \'' + id + '\' but the adapter returned a payload with primary data having an id of \'' + payload.data.id + '\'. Use \'store.findRecord()\' when the requested id is the same as the one returned by the adapter. In other cases use \'store.queryRecord()\' instead http://emberjs.com/api/data/classes/DS.Store.html#method_queryRecord', payload.data.id === id, { + (false && _ember.default.warn('You requested a record of type \'' + modelName + '\' with id \'' + id + '\' but the adapter returned a payload with primary data having an id of \'' + payload.data.id + '\'. Use \'store.findRecord()\' when the requested id is the same as the one returned by the adapter. In other cases use \'store.queryRecord()\' instead https://emberjs.com/api/data/classes/DS.Store.html#method_queryRecord', payload.data.id === id, { id: 'ds.store.findRecord.id-mismatch' })); return store._push(payload); @@ -13376,11 +13130,16 @@ owner = context.container; } if (owner && owner.lookupFactory && !owner._lookupFactory) { // `owner` is a container, we are just making this work - owner._lookupFactory = owner.lookupFactory; + owner._lookupFactory = function () { + var _owner; + + return (_owner = owner).lookupFactory.apply(_owner, arguments); + }; + owner.register = function () { var registry = owner.registry || owner._registry || owner; return registry.register.apply(registry, arguments); }; @@ -14029,11 +13788,11 @@ get: function () { return _private.errorsArrayToHash; } }); }); -define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters/rest', 'ember-data/-private'], function (exports, _ember, _rest, _private) { +define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-inflector', 'ember-data/adapters/rest', 'ember-data/-private'], function (exports, _ember, _emberInflector, _rest, _private) { 'use strict'; exports.__esModule = true; @@ -14171,10 +13930,15 @@ @class JSONAPIAdapter @constructor @namespace DS @extends DS.RESTAdapter */ + /* global heimdall */ + /** + @module ember-data + */ + var JSONAPIAdapter = _rest.default.extend({ defaultSerializer: '-json-api', ajaxOptions: function (url, type, options) { var hash = this._super.apply(this, arguments); @@ -14249,11 +14013,11 @@ return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } }); } }, pathForType: function (modelName) { var dasherized = _ember.default.String.dasherize(modelName); - return _ember.default.String.pluralize(dasherized); + return (0, _emberInflector.pluralize)(dasherized); }, updateRecord: function (store, type, snapshot) { if ((0, _private.isEnabled)('ds-improved-ajax') && !this._hasCustomizedAjax()) { return this._super.apply(this, arguments); } else { @@ -14286,14 +14050,11 @@ return true; } return false; } - }); /* global heimdall */ - /** - @module ember-data - */ + }); if ((0, _private.isEnabled)('ds-improved-ajax')) { JSONAPIAdapter.reopen({ methodForRequest: function (params) { @@ -14353,11 +14114,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'ember-data/-private'], function (exports, _ember, _adapter, _private) { 'use strict'; exports.__esModule = true; var MapWithDefault = _ember.default.MapWithDefault, - get = _ember.default.get; + get = _ember.default.get, + run = _ember.default.run; var Promise = _ember.default.RSVP.Promise; /** @@ -14958,20 +14720,20 @@ return new Promise(function (resolve, reject) { var hash = adapter.ajaxOptions(url, type, options); hash.success = function (payload, textStatus, jqXHR) { var response = ajaxSuccess(adapter, jqXHR, payload, requestData); - _ember.default.run.join(null, resolve, response); + run.join(null, resolve, response); }; hash.error = function (jqXHR, textStatus, errorThrown) { var responseData = { textStatus: textStatus, errorThrown: errorThrown }; var error = ajaxError(adapter, jqXHR, requestData, responseData); - _ember.default.run.join(null, reject, error); + run.join(null, reject, error); }; adapter._ajaxRequest(hash); }, 'DS: RESTAdapter#ajax ' + type + ' to ' + url); }, @@ -15243,24 +15005,24 @@ var method = request.method, url = request.url; var requestData = { method: method, url: url }; - return new _ember.default.RSVP.Promise(function (resolve, reject) { + return new Promise(function (resolve, reject) { hash.success = function (payload, textStatus, jqXHR) { var response = ajaxSuccess(adapter, jqXHR, payload, requestData); - _ember.default.run.join(null, resolve, response); + run.join(null, resolve, response); }; hash.error = function (jqXHR, textStatus, errorThrown) { var responseData = { textStatus: textStatus, errorThrown: errorThrown }; var error = ajaxError(adapter, jqXHR, requestData, responseData); - _ember.default.run.join(null, reject, error); + run.join(null, reject, error); }; adapter._ajaxRequest(hash); }, 'DS: RESTAdapter#makeRequest: ' + method + ' ' + url); } @@ -15886,106 +15648,13 @@ } else { return Array.from(arr); } } - var get = _ember.default.get; - var set = _ember.default.set; + var get = _ember.default.get, + set = _ember.default.set; var camelize = _ember.default.String.camelize; - - /** - ## Using Embedded Records - - `DS.EmbeddedRecordsMixin` supports serializing embedded records. - - To set up embedded records, include the mixin when extending a serializer, - then define and configure embedded (model) relationships. - - Note that embedded records will serialize with the serializer for their model instead of the serializer in which they are defined. - - Below is an example of a per-type serializer (`post` type). - - ```app/serializers/post.js - import DS from 'ember-data'; - - export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { - attrs: { - author: { embedded: 'always' }, - comments: { serialize: 'ids' } - } - }); - ``` - Note that this use of `{ embedded: 'always' }` is unrelated to - the `{ embedded: 'always' }` that is defined as an option on `DS.attr` as part of - defining a model while working with the `ActiveModelSerializer`. Nevertheless, - using `{ embedded: 'always' }` as an option to `DS.attr` is not a valid way to setup - embedded records. - - The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for: - - ```js - { - serialize: 'records', - deserialize: 'records' - } - ``` - - ### Configuring Attrs - - A resource's `attrs` option may be set to use `ids`, `records` or false for the - `serialize` and `deserialize` settings. - - The `attrs` property can be set on the `ApplicationSerializer` or a per-type - serializer. - - In the case where embedded JSON is expected while extracting a payload (reading) - the setting is `deserialize: 'records'`, there is no need to use `ids` when - extracting as that is the default behavior without this mixin if you are using - the vanilla `EmbeddedRecordsMixin`. Likewise, to embed JSON in the payload while - serializing `serialize: 'records'` is the setting to use. There is an option of - not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you - do not want the relationship sent at all, you can use `serialize: false`. - - - ### EmbeddedRecordsMixin defaults - If you do not overwrite `attrs` for a specific relationship, the `EmbeddedRecordsMixin` - will behave in the following way: - - BelongsTo: `{ serialize: 'id', deserialize: 'id' }` - HasMany: `{ serialize: false, deserialize: 'ids' }` - - ### Model Relationships - - Embedded records must have a model defined to be extracted and serialized. Note that - when defining any relationships on your model such as `belongsTo` and `hasMany`, you - should not both specify `async: true` and also indicate through the serializer's - `attrs` attribute that the related model should be embedded for deserialization. - If a model is declared embedded for deserialization (`embedded: 'always'` or `deserialize: 'records'`), - then do not use `async: true`. - - To successfully extract and serialize embedded records the model relationships - must be setup correcty. See the - [defining relationships](/guides/models/defining-models/#toc_defining-relationships) - section of the **Defining Models** guide page. - - Records without an `id` property are not considered embedded records, model - instances must have an `id` property to be used with Ember Data. - - ### Example JSON payloads, Models and Serializers - - **When customizing a serializer it is important to grok what the customizations - are. Please read the docs for the methods this mixin provides, in case you need - to modify it to fit your specific needs.** - - For example review the docs for each method of this mixin: - * [normalize](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_normalize) - * [serializeBelongsTo](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeBelongsTo) - * [serializeHasMany](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeHasMany) - - @class EmbeddedRecordsMixin - @namespace DS - */ exports.default = _ember.default.Mixin.create({ /** Normalize the record and recursively normalize/extract all the embedded records while pushing them into the store as they are encountered @@ -17007,11 +16676,11 @@ if (false) { JSONAPISerializer.reopen({ willMergeMixin: function (props) { var constructor = this.constructor; - (false && _ember.default.warn('You\'ve defined \'extractMeta\' in ' + constructor.toString() + ' which is not used for serializers extending JSONAPISerializer. Read more at http://emberjs.com/api/data/classes/DS.JSONAPISerializer.html#toc_customizing-meta on how to customize meta when using JSON API.', _ember.default.isNone(props.extractMeta) || props.extractMeta === _json.default.prototype.extractMeta, { + (false && _ember.default.warn('You\'ve defined \'extractMeta\' in ' + constructor.toString() + ' which is not used for serializers extending JSONAPISerializer. Read more at https://emberjs.com/api/data/classes/DS.JSONAPISerializer.html#toc_customizing-meta on how to customize meta when using JSON API.', _ember.default.isNone(props.extractMeta) || props.extractMeta === _json.default.prototype.extractMeta, { id: 'ds.serializer.json-api.extractMeta' })); (false && _ember.default.warn('The JSONAPISerializer does not work with the EmbeddedRecordsMixin because the JSON API spec does not describe how to format embedded resources.', !props.isEmbeddedRecordsMixin, { id: 'ds.serializer.embedded-records-mixin-not-supported' })); @@ -17741,10 +17410,11 @@ } } var camelize = _ember.default.String.camelize; + /** Normally, applications will use the `RESTSerializer` by implementing the `normalize` method. This allows you to do whatever kind of munging you need, and is @@ -18556,10 +18226,10 @@ }); define("ember-data/version", ["exports"], function (exports) { "use strict"; exports.__esModule = true; - exports.default = "2.15.4"; + exports.default = "2.16.0-beta.1"; }); define("ember-inflector", ["module", "exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (module, exports, _ember, _system) { "use strict"; exports.__esModule = true;