dist/globals/ember-data.prod.js in ember-data-source-2.14.11 vs dist/globals/ember-data.prod.js in ember-data-source-2.15.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.14.11 + * @version 2.15.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++) { @@ -347,63 +343,16 @@ })(this); define('ember-data/-debug', ['exports', 'ember'], function (exports, _ember) { 'use strict'; exports.__esModule = true; - exports.assert = assert; - exports.debug = debug; - exports.deprecate = deprecate; - exports.info = info; - exports.runInDebug = runInDebug; + exports.assertPolymorphicType = undefined; exports.instrument = instrument; - exports.warn = warn; - exports.debugSeal = debugSeal; - exports.assertPolymorphicType = assertPolymorphicType; - function assert() { - return _ember.default.assert.apply(_ember.default, arguments); - } - - function debug() { - return _ember.default.debug.apply(_ember.default, arguments); - } - - function deprecate() { - return _ember.default.deprecate.apply(_ember.default, arguments); - } - - function info() { - return _ember.default.info.apply(_ember.default, arguments); - } - - function runInDebug() { - return _ember.default.runInDebug.apply(_ember.default, arguments); - } - function instrument(method) { return method(); } - function warn() { - return _ember.default.warn.apply(_ember.default, arguments); - } - - function debugSeal() { - return _ember.default.debugSeal.apply(_ember.default, arguments); - } - - function checkPolymorphic(modelClass, addedModelClass) { - if (modelClass.__isMixin) { - //TODO Need to do this in order to support mixins, should convert to public api - //once it exists in Ember - return modelClass.__mixin.detect(addedModelClass.PrototypeMixin); - } - if (_ember.default.MODEL_FACTORY_INJECTIONS) { - modelClass = modelClass.superclass; - } - return modelClass.detect(addedModelClass); - } - /* Assert that `addedRecord` has a valid type so it can be added to the relationship of the `record`. The assert basically checks if the `addedRecord` can be added to the @@ -419,22 +368,40 @@ @param {RelationshipMeta} relationshipMeta retrieved via `record.relationshipFor(key)` @param {InternalModel} addedRecord record which should be added/set for the relationship */ - function assertPolymorphicType(parentInternalModel, relationshipMeta, addedInternalModel) { - var addedModelName = addedInternalModel.modelName; - var parentModelName = parentInternalModel.modelName; - var key = relationshipMeta.key; - var relationshipModelName = relationshipMeta.type; - var relationshipClass = parentInternalModel.store.modelFor(relationshipModelName); - var assertionMessage = 'You cannot add a record of modelClass \'' + addedModelName + '\' to the \'' + parentModelName + '.' + key + '\' relationship (only \'' + relationshipModelName + '\' allowed)'; + var assertPolymorphicType = void 0; - assert(assertionMessage, checkPolymorphic(relationshipClass, addedInternalModel.modelClass)); + if (false) { + var checkPolymorphic = function checkPolymorphic(modelClass, addedModelClass) { + if (modelClass.__isMixin) { + //TODO Need to do this in order to support mixins, should convert to public api + //once it exists in Ember + return modelClass.__mixin.detect(addedModelClass.PrototypeMixin); + } + if (_ember.default.MODEL_FACTORY_INJECTIONS) { + modelClass = modelClass.superclass; + } + return modelClass.detect(addedModelClass); + }; + + exports.assertPolymorphicType = assertPolymorphicType = function assertPolymorphicType(parentInternalModel, relationshipMeta, addedInternalModel) { + var addedModelName = addedInternalModel.modelName; + var parentModelName = parentInternalModel.modelName; + var key = relationshipMeta.key; + var relationshipModelName = relationshipMeta.type; + var relationshipClass = parentInternalModel.store.modelFor(relationshipModelName); + var assertionMessage = 'You cannot add a record of modelClass \'' + addedModelName + '\' to the \'' + parentModelName + '.' + key + '\' relationship (only \'' + relationshipModelName + '\' allowed)'; + + (false && _ember.default.assert(assertionMessage, checkPolymorphic(relationshipClass, addedInternalModel.modelClass))); + }; } + + exports.assertPolymorphicType = assertPolymorphicType; }); -define('ember-data/-private/adapters/build-url-mixin', ['exports', 'ember', 'ember-inflector'], function (exports, _ember, _emberInflector) { +define('ember-data/-private/adapters/build-url-mixin', ['exports', 'ember'], function (exports, _ember) { 'use strict'; exports.__esModule = true; @@ -830,25 +797,24 @@ ### 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 pluralize(decamelized); + return Ember.String.pluralize(decamelized); } }); ``` @method pathForType @param {String} modelName @return {String} path **/ pathForType: function (modelName) { var camelized = _ember.default.String.camelize(modelName); - return (0, _emberInflector.pluralize)(camelized); + return _ember.default.String.pluralize(camelized); } }); }); define('ember-data/-private/adapters/errors', ['exports', 'ember', 'ember-data/-private/features'], function (exports, _ember, _features) { 'use strict'; @@ -959,10 +925,12 @@ }; } function extend(ParentErrorClass, defaultMessage) { var ErrorClass = function (errors, message) { + (false && _ember.default.assert('`AdapterError` expects json-api formatted errors array.', Array.isArray(errors || []))); + ParentErrorClass.call(this, errors, message || defaultMessage); }; ErrorClass.prototype = Object.create(ParentErrorClass.prototype); if (extendedErrorsEnabled) { @@ -1813,12 +1781,12 @@ exports.__esModule = true; exports.default = diffArray; /** @namespace - @method diff-array - @for DS + @method diffArray + @private @param {Array} oldArray the old array @param {Array} newArray the new array @return {hash} { firstChangeIndex: <integer>, // null if no change addedCount: <integer>, // 0 if no change @@ -1973,16 +1941,23 @@ InternalModelMap.prototype.has = function has(id) { return !!this._idToModel[id]; }; InternalModelMap.prototype.set = function set(id, internalModel) { + (false && Ember.assert('You cannot index an internalModel by an empty id\'', id)); + (false && Ember.assert('You cannot set an index for an internalModel to something other than an internalModel', internalModel instanceof _internalModel.default)); + (false && Ember.assert('You cannot set an index for an internalModel that is not in the InternalModelMap', this.contains(internalModel))); + (false && Ember.assert('You cannot update the id index of an InternalModel once set. Attempted to update ' + id + '.', !this.has(id) || this.get(id) === internalModel)); + this._idToModel[id] = internalModel; }; InternalModelMap.prototype.add = function add(internalModel, id) { + (false && Ember.assert('You cannot re-add an already present InternalModel to the InternalModelMap.', !this.contains(internalModel))); + if (id) { this._idToModel[id] = internalModel; } this._models.push(internalModel); @@ -2024,10 +1999,15 @@ }; _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 () { @@ -2312,10 +2292,12 @@ */ createRecord: function (hash) { var store = get(this, 'store'); var type = get(this, 'type'); + (false && _ember.default.assert('You cannot add \'' + type.modelName + '\' records to this polymorphic relationship.', !get(this, 'isPolymorphic'))); + var record = store.createRecord(type.modelName, hash); this.pushObject(record); return record; } @@ -2421,11 +2403,16 @@ @param {Function} becameInvalid @param {Function} becameValid @deprecated */ registerHandlers: function (target, becameInvalid, becameValid) { + (false && !(false) && _ember.default.deprecate('Record errors will no longer be evented.', false, { + id: 'ds.errors.registerHandlers', + until: '3.0.0' + })); + this._registerHandlers(target, becameInvalid, becameValid); }, /** @@ -2537,11 +2524,15 @@ @param {String} attribute @param {(Array|String)} messages @deprecated */ add: function (attribute, messages) { + (false && _ember.default.warn('Interacting with a record errors object will no longer change the record state.', false, { + id: 'ds.errors.add' + })); + var wasEmpty = get(this, 'isEmpty'); this._add(attribute, messages); if (wasEmpty && !get(this, 'isEmpty')) { @@ -2618,11 +2609,15 @@ @method remove @param {String} attribute @deprecated */ remove: function (attribute) { + (false && _ember.default.warn('Interacting with a record errors object will no longer change the record state.', false, { + id: 'ds.errors.remove' + })); + if (get(this, 'isEmpty')) { return; } this._remove(attribute); @@ -2668,11 +2663,15 @@ ``` @method clear @deprecated */ clear: function () { + (false && _ember.default.warn('Interacting with a record errors object will no longer change the record state.', false, { + id: 'ds.errors.clear' + })); + if (get(this, 'isEmpty')) { return; } this._clear(); @@ -2806,18 +2805,10 @@ } } return true; } - function destroyRelationship(rel) { - if (rel._inverseIsAsync()) { - rel.removeInternalModelFromInverse(rel.inverseInternalModel); - rel.removeInverseRelationships(); - } else { - rel.removeCompletelyFromInverse(); - } - } // this (and all heimdall instrumentation) will be stripped by a babel transform // https://github.com/heimdalljs/babel5-plugin-strip-heimdall var InternalModelReferenceId = 1; @@ -3028,13 +3019,21 @@ internalModel.updateRecordArrays(); }); }; InternalModel.prototype._directlyRelatedInternalModels = function _directlyRelatedInternalModels() { + var _this = this; + var array = []; - this._relationships.forEach(function (name, rel) { - array = array.concat(rel.members.list, rel.canonicalMembers.list); + this.type.eachRelationship(function (key, relationship) { + if (_this._relationships.has(key)) { + var _relationship = _this._relationships.get(key); + var localRelationships = _relationship.members.toArray(); + var serverRelationships = _relationship.canonicalMembers.toArray(); + + array = array.concat(localRelationships, serverRelationships); + } }); return array; }; InternalModel.prototype._allRelatedInternalModels = function _allRelatedInternalModels() { @@ -3047,10 +3046,11 @@ var node = queue.shift(); array.push(node); var related = node._directlyRelatedInternalModels(); for (var i = 0; i < related.length; ++i) { var internalModel = related[i]; + (false && _ember.default.assert('Internal Error: seen a future bfs iteration', internalModel._bfsId <= bfsId)); if (internalModel._bfsId < bfsId) { queue.push(internalModel); internalModel._bfsId = bfsId; } @@ -3058,46 +3058,26 @@ } return array; }; InternalModel.prototype.unloadRecord = function unloadRecord() { - if (this.isDestroyed) { - return; - } this.send('unloadRecord'); this.dematerializeRecord(); - if (this._scheduledDestroy === null) { this._scheduledDestroy = run.schedule('destroy', this, '_checkForOrphanedInternalModels'); } }; - InternalModel.prototype.hasScheduledDestroy = function hasScheduledDestroy() { - return !!this._scheduledDestroy; - }; - InternalModel.prototype.cancelDestroy = function cancelDestroy() { + (false && _ember.default.assert('You cannot cancel the destruction of an InternalModel once it has already been destroyed', !this.isDestroyed)); + this._isDematerializing = false; run.cancel(this._scheduledDestroy); this._scheduledDestroy = null; }; - InternalModel.prototype.destroySync = function destroySync() { - if (this._isDematerializing) { - this.cancelDestroy(); - } - this._checkForOrphanedInternalModels(); - if (this.isDestroyed || this.isDestroying) { - return; - } - - // just in-case we are not one of the orphaned, we should still - // still destroy ourselves - this.destroy(); - }; - InternalModel.prototype._checkForOrphanedInternalModels = function _checkForOrphanedInternalModels() { this._isDematerializing = false; this._scheduledDestroy = null; if (this.isDestroyed) { return; @@ -3121,17 +3101,14 @@ InternalModel.prototype.eachRelationship = function eachRelationship(callback, binding) { return this.modelClass.eachRelationship(callback, binding); }; InternalModel.prototype.destroy = function destroy() { + (false && _ember.default.assert("Cannot destroy an internalModel while its record is materialized", !this._record || this._record.get('isDestroyed') || this._record.get('isDestroying'))); - this.store._internalModelDestroyed(this); - this._relationships.forEach(function (name, rel) { - return rel.destroy(); - }); - + this.store._internalModelDestroyed(this); this._isDestroyed = true; }; InternalModel.prototype.eachAttribute = function eachAttribute(callback, binding) { return this.modelClass.eachAttribute(callback, binding); @@ -3256,10 +3233,16 @@ if (this.hasRecord) { this._record.notifyHasManyAdded(key, record, idx); } }; + InternalModel.prototype.notifyHasManyRemoved = function notifyHasManyRemoved(key, record, idx) { + if (this.hasRecord) { + this._record.notifyHasManyRemoved(key, record, idx); + } + }; + InternalModel.prototype.notifyBelongsToChanged = function notifyBelongsToChanged(key, record) { if (this.hasRecord) { this._record.notifyBelongsToChanged(key, record); } }; @@ -3289,11 +3272,11 @@ //TODO: Should probably move this to the state machine somehow this.becameReady(); } if (this.isNew()) { - this.removeFromInverseRelationships(true); + this.clearRelationships(); } if (this.isValid()) { this._inFlightAttributes = null; } @@ -3405,61 +3388,51 @@ } triggers.length = 0; }; - InternalModel.prototype.removeFromInverseRelationships = function removeFromInverseRelationships() { - var isNew = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + InternalModel.prototype.clearRelationships = function clearRelationships() { + var _this2 = this; - this._relationships.forEach(function (name, rel) { - rel.removeCompletelyFromInverse(); - if (isNew === true) { + this.eachRelationship(function (name, relationship) { + if (_this2._relationships.has(name)) { + var rel = _this2._relationships.get(name); rel.clear(); + rel.removeInverseRelationships(); } }); - - var implicitRelationships = this._implicitRelationships; - this.__implicitRelationships = null; - - Object.keys(implicitRelationships).forEach(function (key) { - var rel = implicitRelationships[key]; - - rel.removeCompletelyFromInverse(); - if (isNew === true) { - rel.clear(); - } + Object.keys(this._implicitRelationships).forEach(function (key) { + _this2._implicitRelationships[key].clear(); + _this2._implicitRelationships[key].removeInverseRelationships(); }); }; InternalModel.prototype.destroyRelationships = function destroyRelationships() { - var relationships = this._relationships; - relationships.forEach(function (name, rel) { - return destroyRelationship(rel); - }); + var _this3 = this; - var implicitRelationships = this._implicitRelationships; - this.__implicitRelationships = null; - Object.keys(implicitRelationships).forEach(function (key) { - var rel = implicitRelationships[key]; - - destroyRelationship(rel); - - rel.destroy(); + this.eachRelationship(function (name, relationship) { + if (_this3._relationships.has(name)) { + var rel = _this3._relationships.get(name); + rel.removeInverseRelationships(); + } }); + Object.keys(this._implicitRelationships).forEach(function (key) { + _this3._implicitRelationships[key].removeInverseRelationships(); + }); }; InternalModel.prototype.preloadData = function preloadData(preload) { - var _this = this; + var _this4 = this; //TODO(Igor) consider the polymorphic case Object.keys(preload).forEach(function (key) { var preloadValue = get(preload, key); - var relationshipMeta = _this.modelClass.metaForProperty(key); + var relationshipMeta = _this4.modelClass.metaForProperty(key); if (relationshipMeta.isRelationship) { - _this._preloadRelationship(key, preloadValue); + _this4._preloadRelationship(key, preloadValue); } else { - _this._data[key] = preloadValue; + _this4._data[key] = preloadValue; } }); }; InternalModel.prototype._preloadRelationship = function _preloadRelationship(key, preloadValue) { @@ -3471,10 +3444,12 @@ this._preloadBelongsTo(key, preloadValue, modelClass); } }; InternalModel.prototype._preloadHasMany = function _preloadHasMany(key, preloadValue, modelClass) { + (false && _ember.default.assert("You need to pass in an array to set a hasMany property on a record", Array.isArray(preloadValue))); + var recordsToSet = new Array(preloadValue.length); for (var i = 0; i < preloadValue.length; i++) { var recordToPush = preloadValue[i]; recordsToSet[i] = this._convertStringOrNumberIntoInternalModel(recordToPush, modelClass); @@ -3506,10 +3481,12 @@ InternalModel.prototype.updateRecordArrays = function updateRecordArrays() { this.store.recordArrayManager.recordDidChange(this); }; InternalModel.prototype.setId = function setId(id) { + (false && _ember.default.assert('A record\'s id cannot be changed once it is in the loaded state', this.id === null || this.id === id || this.isNew())); + this.id = id; if (this._record.get('id') !== id) { this._record.set('id', id); } }; @@ -3659,17 +3636,24 @@ InternalModel.prototype.toString = function toString() { return '<' + this.modelName + ':' + this.id + '>'; }; InternalModel.prototype.referenceFor = function referenceFor(kind, name) { - var _this2 = this; - var reference = this.references[name]; if (!reference) { var relationship = this._relationships.get(name); + if (false) { + var modelName = this.modelName; + (false && _ember.default.assert('There is no ' + kind + ' relationship named \'' + name + '\' on a model of modelClass \'' + modelName + '\'', relationship)); + + + var actualRelationshipKind = relationship.relationshipMeta.kind; + (false && _ember.default.assert('You tried to get the \'' + name + '\' relationship on a \'' + modelName + '\' via record.' + kind + '(\'' + name + '\'), but the relationship is of kind \'' + actualRelationshipKind + '\'. Use record.' + actualRelationshipKind + '(\'' + name + '\') instead.', actualRelationshipKind === kind)); + } + if (kind === "belongsTo") { reference = new _references.BelongsToReference(this.store, this, relationship); } else if (kind === "hasMany") { reference = new _references.HasManyReference(this.store, this, relationship); } @@ -4299,11 +4283,13 @@ fn.apply(this, args); } this._super.apply(this, arguments); }, - attr: function () {}, + attr: function () { + (false && _ember.default.assert("The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false)); + }, belongsTo: function (name) { return this._internalModel.referenceFor('belongsTo', name); }, hasMany: function (name) { return this._internalModel.referenceFor('hasMany', name); @@ -4393,10 +4379,22 @@ get: function () { return this._internalModel._data; } }); + if (false) { + Model.reopen({ + init: function () { + this._super.apply(this, arguments); + + if (!this._internalModel) { + throw new _ember.default.Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.'); + } + } + }); + } + Model.reopenClass({ isModel: true, /** Override the class' `create()` method to raise an error. This @@ -4486,14 +4484,21 @@ //If inverse is specified manually, return the inverse if (options.inverse) { inverseName = options.inverse; inverse = _ember.default.get(inverseType, 'relationshipsByName').get(inverseName); + (false && _ember.default.assert("We found no inverse relationships by the name of '" + inverseName + "' on the '" + inverseType.modelName + "' model. This is most likely due to a missing attribute on your model definition.", !_ember.default.isNone(inverse))); + + 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) {} + 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, { + id: 'ds.model.reflexive-relationship-without-inverse' + })); + } var possibleRelationships = findPossibleInverses(this, inverseType, name); if (possibleRelationships.length === 0) { return null; @@ -4502,14 +4507,20 @@ 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)); + + 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)); + + inverseName = possibleRelationships[0].name; inverseKind = possibleRelationships[0].kind; } return { @@ -4771,11 +4782,13 @@ var map = Map.create(); this.eachComputedProperty(function (name, meta) { if (meta.isAttribute) { + (false && _ember.default.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + _this3.toString(), name !== 'id')); + meta.name = name; map.set(name, meta); } }); @@ -4844,11 +4857,13 @@ if (_ember.default.setOwner) { Object.defineProperty(Model.prototype, 'container', { configurable: true, enumerable: false, get: function () { + (false && !(false) && _ember.default.deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.', false, { id: 'ember-application.injected-container', until: '3.0.0' })); + return this.store.container; } }); } @@ -4860,10 +4875,32 @@ } } }); } + if (false) { + Model.reopen({ + willMergeMixin: function (props) { + var constructor = this.constructor; + (false && _ember.default.assert('`' + intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0] + '` is a reserved property name on DS.Model objects. Please choose a different property name for ' + constructor.toString(), !intersection(Object.keys(props), RESERVED_MODEL_PROPS)[0])); + (false && _ember.default.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from " + constructor.toString(), Object.keys(props).indexOf('id') === -1)); + }, + didDefineProperty: function (proto, key, value) { + // Check if the value being set is a computed property. + if (value instanceof _ember.default.ComputedProperty) { + + // 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(); + + meta.parentType = proto.constructor; + } + } + }); + } + exports.default = Model; }); define('ember-data/-private/system/model/states', ['exports'], function (exports) { 'use strict'; @@ -5278,11 +5315,13 @@ internalModel.triggerLater('didLoad'); }; createdState.uncommitted.propertyWasReset = function () {}; - function assertAgainstUnloadRecord(internalModel) {} + function assertAgainstUnloadRecord(internalModel) { + (false && Ember.assert("You can only unload a record which is not inFlight. `" + internalModel + "`", false)); + } updatedState.inFlight.unloadRecord = assertAgainstUnloadRecord; updatedState.uncommitted.deleteRecord = function (internalModel) { internalModel.transitionTo('deleted.uncommitted'); @@ -5484,11 +5523,11 @@ saved: { // FLAGS isDirty: false, setup: function (internalModel) { - internalModel.removeFromInverseRelationships(); + internalModel.clearRelationships(); }, invokeLifecycleCallbacks: function (internalModel) { internalModel.triggerLater('didDelete', internalModel); internalModel.triggerLater('didCommit', internalModel); }, @@ -5763,10 +5802,12 @@ }; } var PromiseManyArray = exports.PromiseManyArray = PromiseArray.extend({ reload: function () { + (false && _ember.default.assert('You are trying to reload an async manyArray before it has been created', get(this, 'content'))); + this.set('promise', this.get('content').reload()); return this; }, @@ -5787,22 +5828,24 @@ return PromiseManyArray.create({ promise: Promise.resolve(promise, label) }); } }); -define('ember-data/-private/system/record-array-manager', ['exports', 'ember', 'ember-data/-private/system/record-arrays'], function (exports, _ember, _recordArrays) { - 'use strict'; +define("ember-data/-private/system/record-array-manager", ["exports", "ember", "ember-data/-private/system/record-arrays", "ember-data/-private/system/clone-null"], function (exports, _ember, _recordArrays, _cloneNull) { + "use strict"; exports.__esModule = true; + exports.associateWithRecordArray = associateWithRecordArray; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var get = _ember.default.get, + set = _ember.default.set, emberRun = _ember.default.run; var RecordArrayManager = function () { function RecordArrayManager(options) { this.store = options.store; @@ -5870,69 +5913,28 @@ for (var i = 0; i < recordArrays.length; i++) { this.updateFilterRecordArray(recordArrays[i], modelName, internalModels); } } - // TODO: skip if it only changed - // process liveRecordArrays - if (this._liveRecordArrays[modelName]) { - this.updateLiveRecordArray(modelName, internalModels); + var array = this._liveRecordArrays[modelName]; + if (array) { + // TODO: skip if it only changed + // process liveRecordArrays + this.updateLiveRecordArray(array, internalModels); } // process adapterPopulatedRecordArrays if (modelsToRemove.length > 0) { - this.removeFromAdapterPopulatedRecordArrays(modelsToRemove); + removeFromAdapterPopulatedRecordArrays(modelsToRemove); } } }; - RecordArrayManager.prototype.updateLiveRecordArray = function updateLiveRecordArray(modelName, internalModels) { - var array = this.liveRecordArrayFor(modelName); - - var modelsToAdd = []; - var modelsToRemove = []; - - for (var i = 0; i < internalModels.length; i++) { - var internalModel = internalModels[i]; - var isDeleted = internalModel.isHiddenFromRecordArrays(); - var recordArrays = internalModel._recordArrays; - - if (!isDeleted && !internalModel.isEmpty()) { - if (!recordArrays.has(array)) { - modelsToAdd.push(internalModel); - recordArrays.add(array); - } - } - - if (isDeleted) { - modelsToRemove.push(internalModel); - recordArrays.delete(array); - } - } - - if (modelsToAdd.length > 0) { - array._pushInternalModels(modelsToAdd); - } - if (modelsToRemove.length > 0) { - array._removeInternalModels(modelsToRemove); - } + RecordArrayManager.prototype.updateLiveRecordArray = function updateLiveRecordArray(array, internalModels) { + return _updateLiveRecordArray(array, internalModels); }; - RecordArrayManager.prototype.removeFromAdapterPopulatedRecordArrays = function removeFromAdapterPopulatedRecordArrays(internalModels) { - for (var i = 0; i < internalModels.length; i++) { - var internalModel = internalModels[i]; - var list = internalModel._recordArrays.list; - - for (var j = 0; j < list.length; j++) { - // TODO: group by arrays, so we can batch remove - list[j]._removeInternalModels([internalModel]); - } - - internalModel._recordArrays.clear(); - } - }; - RecordArrayManager.prototype.updateFilterRecordArray = function updateFilterRecordArray(array, modelName, internalModels) { var filter = get(array, 'filterFunction'); var shouldBeInAdded = []; @@ -5959,75 +5961,118 @@ if (shouldBeRemoved.length > 0) { array._removeInternalModels(shouldBeRemoved); } }; - RecordArrayManager.prototype.syncLiveRecordArray = function syncLiveRecordArray(array, modelName) { + RecordArrayManager.prototype._syncLiveRecordArray = function _syncLiveRecordArray(array, modelName) { + (false && _ember.default.assert("recordArrayManger.syncLiveRecordArray expects modelName not modelClass as the second param", typeof modelName === 'string')); + var hasNoPotentialDeletions = Object.keys(this._pending).length === 0; var map = this.store._internalModelsFor(modelName); var hasNoInsertionsOrRemovals = get(map, 'length') === get(array, 'length'); /* Ideally the recordArrayManager has knowledge of the changes to be applied to liveRecordArrays, and is capable of strategically flushing those changes and applying small diffs if desired. However, until we've refactored recordArrayManager, this dirty check prevents us from unnecessarily wiping out live record arrays returned by peekAll. - */ + */ if (hasNoPotentialDeletions && hasNoInsertionsOrRemovals) { return; } - this.populateLiveRecordArray(array, map.models); - }; - - RecordArrayManager.prototype.populateLiveRecordArray = function populateLiveRecordArray(array, internalModels) { - + var internalModels = this._visibleInternalModelsByType(modelName); var modelsToAdd = []; for (var i = 0; i < internalModels.length; i++) { var internalModel = internalModels[i]; - - if (!internalModel.isHiddenFromRecordArrays()) { - var recordArrays = internalModel._recordArrays; - - if (!recordArrays.has(array)) { - modelsToAdd.push(internalModel); - recordArrays.add(array); - } + var recordArrays = internalModel._recordArrays; + if (recordArrays.has(array) === false) { + recordArrays.add(array); + modelsToAdd.push(internalModel); } } array._pushInternalModels(modelsToAdd); }; RecordArrayManager.prototype.updateFilter = function updateFilter(array, modelName, filter) { + (false && _ember.default.assert("recordArrayManger.updateFilter expects modelName not modelClass as the second param, received " + modelName, typeof modelName === 'string')); + var modelMap = this.store._internalModelsFor(modelName); var internalModels = modelMap.models; this.updateFilterRecordArray(array, filter, internalModels); }; + RecordArrayManager.prototype._didUpdateAll = function _didUpdateAll(modelName) { + var recordArray = this._liveRecordArrays[modelName]; + if (recordArray) { + set(recordArray, 'isUpdating', false); + } + }; + RecordArrayManager.prototype.liveRecordArrayFor = function liveRecordArrayFor(modelName) { + (false && _ember.default.assert("recordArrayManger.liveRecordArrayFor expects modelName not modelClass as the param", typeof modelName === 'string')); - return this._liveRecordArrays[modelName] || (this._liveRecordArrays[modelName] = this.createRecordArray(modelName)); + + var array = this._liveRecordArrays[modelName]; + + if (array) { + // if the array already exists, synchronize + this._syncLiveRecordArray(array, modelName); + } else { + // if the array is being newly created merely create it with its initial + // content already set. This prevents unneeded change events. + var internalModels = this._visibleInternalModelsByType(modelName); + array = this.createRecordArray(modelName, internalModels); + this._liveRecordArrays[modelName] = array; + } + + return array; }; + RecordArrayManager.prototype._visibleInternalModelsByType = function _visibleInternalModelsByType(modelName) { + var all = this.store._internalModelsFor(modelName)._models; + var visible = []; + for (var i = 0; i < all.length; i++) { + var model = all[i]; + if (model.isHiddenFromRecordArrays() === false) { + visible.push(model); + } + } + return visible; + }; + RecordArrayManager.prototype.filteredRecordArraysFor = function filteredRecordArraysFor(modelName) { + (false && _ember.default.assert("recordArrayManger.filteredRecordArraysFor expects modelName not modelClass as the param", typeof modelName === 'string')); + return this._filteredRecordArrays[modelName] || (this._filteredRecordArrays[modelName] = []); }; - RecordArrayManager.prototype.createRecordArray = function createRecordArray(modelName) { - return _recordArrays.RecordArray.create({ + RecordArrayManager.prototype.createRecordArray = function createRecordArray(modelName, content) { + (false && _ember.default.assert("recordArrayManger.createRecordArray expects modelName not modelClass as the param", typeof modelName === 'string')); + + + var array = _recordArrays.RecordArray.create({ modelName: modelName, - content: _ember.default.A(), + content: _ember.default.A(content || []), store: this.store, isLoaded: true, manager: this }); + + if (Array.isArray(content)) { + associateWithRecordArray(content, array); + } + + return array; }; RecordArrayManager.prototype.createFilteredRecordArray = function createFilteredRecordArray(modelName, filter, query) { + (false && _ember.default.assert("recordArrayManger.createFilteredRecordArray expects modelName not modelClass as the first param, received " + modelName, typeof modelName === 'string')); + var array = _recordArrays.FilteredRecordArray.create({ query: query, modelName: modelName, content: _ember.default.A(), store: this.store, @@ -6038,27 +6083,48 @@ this.registerFilteredRecordArray(array, modelName, filter); return array; }; - RecordArrayManager.prototype.createAdapterPopulatedRecordArray = function createAdapterPopulatedRecordArray(modelName, query) { + RecordArrayManager.prototype.createAdapterPopulatedRecordArray = function createAdapterPopulatedRecordArray(modelName, query, internalModels, payload) { + (false && _ember.default.assert("recordArrayManger.createAdapterPopulatedRecordArray expects modelName not modelClass as the first param, received " + modelName, typeof modelName === 'string')); - var array = _recordArrays.AdapterPopulatedRecordArray.create({ - modelName: modelName, - query: query, - content: _ember.default.A(), - store: this.store, - manager: this - }); + var array = void 0; + if (Array.isArray(internalModels)) { + array = _recordArrays.AdapterPopulatedRecordArray.create({ + modelName: modelName, + query: query, + content: _ember.default.A(internalModels), + store: this.store, + manager: this, + isLoaded: true, + isUpdating: false, + meta: (0, _cloneNull.default)(payload.meta), + links: (0, _cloneNull.default)(payload.links) + }); + + associateWithRecordArray(internalModels, array); + } else { + array = _recordArrays.AdapterPopulatedRecordArray.create({ + modelName: modelName, + query: query, + content: _ember.default.A(), + store: this.store, + manager: this + }); + } + this._adapterPopulatedRecordArrays.push(array); return array; }; RecordArrayManager.prototype.registerFilteredRecordArray = function registerFilteredRecordArray(array, modelName, filter) { + (false && _ember.default.assert("recordArrayManger.registerFilteredRecordArray expects modelName not modelClass as the second param, received " + modelName, typeof modelName === 'string')); + this.filteredRecordArraysFor(modelName).push(array); this.updateFilter(array, modelName, filter); }; RecordArrayManager.prototype.unregisterRecordArray = function unregisterRecordArray(array) { @@ -6131,21 +6197,72 @@ return true; } return false; } + + function _updateLiveRecordArray(array, internalModels) { + var modelsToAdd = []; + var modelsToRemove = []; + + for (var i = 0; i < internalModels.length; i++) { + var internalModel = internalModels[i]; + var isDeleted = internalModel.isHiddenFromRecordArrays(); + var recordArrays = internalModel._recordArrays; + + if (!isDeleted && !internalModel.isEmpty()) { + if (!recordArrays.has(array)) { + modelsToAdd.push(internalModel); + recordArrays.add(array); + } + } + + if (isDeleted) { + modelsToRemove.push(internalModel); + recordArrays.delete(array); + } + } + + if (modelsToAdd.length > 0) { + array._pushInternalModels(modelsToAdd); + } + if (modelsToRemove.length > 0) { + array._removeInternalModels(modelsToRemove); + } + } + + function removeFromAdapterPopulatedRecordArrays(internalModels) { + for (var i = 0; i < internalModels.length; i++) { + var internalModel = internalModels[i]; + var list = internalModel._recordArrays.list; + + for (var j = 0; j < list.length; j++) { + // TODO: group by arrays, so we can batch remove + list[j]._removeInternalModels([internalModel]); + } + + internalModel._recordArrays.clear(); + } + } + + function associateWithRecordArray(internalModels, array) { + for (var i = 0, l = internalModels.length; i < l; i++) { + var internalModel = internalModels[i]; + internalModel._recordArrays.add(array); + } + } }); define("ember-data/-private/system/record-arrays", ["exports", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/record-arrays/filtered-record-array", "ember-data/-private/system/record-arrays/adapter-populated-record-array"], function (exports, _recordArray, _filteredRecordArray, _adapterPopulatedRecordArray) { "use strict"; exports.__esModule = true; exports.AdapterPopulatedRecordArray = exports.FilteredRecordArray = exports.RecordArray = undefined; exports.RecordArray = _recordArray.default; exports.FilteredRecordArray = _filteredRecordArray.default; exports.AdapterPopulatedRecordArray = _adapterPopulatedRecordArray.default; }); -define("ember-data/-private/system/record-arrays/adapter-populated-record-array", ["exports", "ember", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/clone-null"], function (exports, _ember, _recordArray, _cloneNull) { +define("ember-data/-private/system/record-arrays/adapter-populated-record-array", ["exports", "ember", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/clone-null", "ember-data/-private/system/record-array-manager"], function (exports, _ember, _recordArray, _cloneNull, _recordArrayManager) { "use strict"; exports.__esModule = true; var get = _ember.default.get; exports.default = _recordArray.default.extend({ @@ -6186,16 +6303,12 @@ isUpdating: false, meta: (0, _cloneNull.default)(payload.meta), links: (0, _cloneNull.default)(payload.links) }); - for (var i = 0, l = internalModels.length; i < l; i++) { - var internalModel = internalModels[i]; + (0, _recordArrayManager.associateWithRecordArray)(internalModels, this); - internalModel._recordArrays.add(this); - } - // TODO: should triggering didLoad event be the last action of the runLoop? _ember.default.run.once(this, 'trigger', 'didLoad'); } }); }); @@ -6690,11 +6803,11 @@ userRef.meta() // { lastUpdated: 1458014400000 } ``` @method meta - @return {Object} The meta information for the belongs-oo relationship. + @return {Object} The meta information for the belongs-to relationship. */ BelongsToReference.prototype.meta = function () { return this.belongsToRelationship.meta; }; @@ -6747,11 +6860,16 @@ return _ember.default.RSVP.resolve(objectOrPromise).then(function (data) { var record = void 0; if (data instanceof _model.default) { - if ((0, _features.default)('ds-overhaul-references')) {} + if ((0, _features.default)('ds-overhaul-references')) { + (false && !(false) && _ember.default.deprecate("BelongsToReference#push(DS.Model) is deprecated. Update relationship via `model.set('relationshipName', value)` instead.", false, { + id: 'ds.references.belongs-to.push-record', + until: '3.0' + })); + } record = data; } else { record = _this.store.push(data); } @@ -7053,11 +7171,11 @@ let commentsRef = post.hasMany('comments'); commentsRef.ids(); // ['1'] ``` - @method remoteType + @method ids @return {Array} The ids in this has-many relationship */ HasManyReference.prototype.ids = function () { var members = this.hasManyRelationship.members.toArray(); @@ -7065,12 +7183,11 @@ return internalModel.id; }); }; /** - The link Ember Data will use to fetch or reload this has-many - relationship. + The meta data for the has-many relationship. Example ```app/models/post.js export default DS.Model.extend({ @@ -7156,18 +7273,28 @@ var _this = this; return resolve(objectOrPromise).then(function (payload) { var array = payload; - if ((0, _features.default)("ds-overhaul-references")) {} + if ((0, _features.default)("ds-overhaul-references")) { + (false && !(!Array.isArray(payload)) && _ember.default.deprecate("HasManyReference#push(array) is deprecated. Push a JSON-API document instead.", !Array.isArray(payload), { + id: 'ds.references.has-many.push-array', + until: '3.0' + })); + } var useLegacyArrayPush = true; if (typeof payload === "object" && payload.data) { array = payload.data; useLegacyArrayPush = array.length && array[0].data; - if ((0, _features.default)('ds-overhaul-references')) {} + if ((0, _features.default)('ds-overhaul-references')) { + (false && !(!useLegacyArrayPush) && _ember.default.deprecate("HasManyReference#push() expects a valid JSON-API document.", !useLegacyArrayPush, { + id: 'ds.references.has-many.push-invalid-json-api', + until: '3.0' + })); + } } if (!(0, _features.default)('ds-overhaul-references')) { useLegacyArrayPush = true; } @@ -7175,15 +7302,25 @@ var internalModels = void 0; if (useLegacyArrayPush) { internalModels = array.map(function (obj) { var record = _this.store.push(obj); + if (false) { + var relationshipMeta = _this.hasManyRelationship.relationshipMeta; + } + return record._internalModel; }); } else { var records = _this.store.push(payload); internalModels = _ember.default.A(records).mapBy('_internalModel'); + + if (false) { + internalModels.forEach(function (internalModel) { + var relationshipMeta = _this.hasManyRelationship.relationshipMeta; + }); + } } _this.hasManyRelationship.computeChanges(internalModels); return _this.hasManyRelationship.manyArray; @@ -7545,10 +7682,14 @@ 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'; @@ -7642,10 +7783,13 @@ if (typeof userEnteredModelName === 'string') { userEnteredModelName = (0, _normalizeModelName.default)(userEnteredModelName); } + (false && _ember.default.assert("The first argument to DS.belongsTo must be a string representing a model type key, not an instance of " + _ember.default.inspect(userEnteredModelName) + ". E.g., to define a relation to the Person model, use DS.belongsTo('person')", typeof userEnteredModelName === 'string' || typeof userEnteredModelName === 'undefined')); + + opts = opts || {}; var meta = { type: userEnteredModelName, isRelationship: true, @@ -7655,13 +7799,21 @@ key: null }; return _ember.default.computed({ get: function (key) { - if (opts.hasOwnProperty('serialize')) {} + 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, { + id: 'ds.model.serialize-option-in-belongs-to' + })); + } - if (opts.hasOwnProperty('embedded')) {} + 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, { + id: 'ds.model.embedded-option-in-belongs-to' + })); + } return this._internalModel._relationships.get(key).getRecord(); }, set: function (key, value) { if (value === undefined) { @@ -7735,11 +7887,16 @@ this.eachComputedProperty(function (name, meta) { if (meta.isRelationship) { meta.key = name; modelName = (0, _relationshipMeta.typeForRelationshipMeta)(meta); + (false && _ember.default.assert('You specified a hasMany (' + meta.type + ') on ' + meta.parentType + ' but ' + meta.type + ' was not found.', modelName)); + + if (!types.includes(modelName)) { + (false && _ember.default.assert('Trying to sideload ' + name + ' on ' + _this.toString() + ' but the type doesn\'t exist.', !!modelName)); + types.push(modelName); } } }); @@ -7879,10 +8036,13 @@ if (typeof type === 'object') { options = type; type = undefined; } + (false && _ember.default.assert('The first argument to DS.hasMany must be a string representing a model type key, not an instance of ' + _ember.default.inspect(type) + '. E.g., to define a relation to the Comment model, use DS.hasMany(\'comment\')', typeof type === 'string' || typeof type === 'undefined')); + + options = options || {}; if (typeof type === 'string') { type = (0, _normalizeModelName.default)(type); } @@ -7903,11 +8063,18 @@ return _ember.default.computed({ get: function (key) { return this._internalModel._relationships.get(key).getRecords(); }, set: function (key, records) { + (false && _ember.default.assert('You must pass an array of records to set a hasMany relationship', (0, _isArrayLike.default)(records))); + (false && _ember.default.assert('All elements of a hasMany relationship must be instances of DS.Model, you passed ' + _ember.default.inspect(records), function () { + return _ember.default.A(records).every(function (record) { + return record.hasOwnProperty('_internalModel') === true; + }); + }())); + var relationship = this._internalModel._relationships.get(key); relationship.clear(); relationship.addInternalModels(records.map(function (record) { return get(record, '_internalModel'); })); @@ -8174,10 +8341,12 @@ this._flushPending(); if (this._isLHS(modelName, relationshipName)) { return this._lhsPayloads[id]; } else { + (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._rhsPayloads[id]; } }; RelationshipPayloads.prototype.push = function push(modelName, id, relationshipName, relationshipData) { @@ -8188,10 +8357,12 @@ this._flushPending(); if (this._isLHS(modelName, relationshipName)) { delete this._lhsPayloads[id]; } else { + (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._rhsPayloads[id]; } }; RelationshipPayloads.prototype._isLHS = function _isLHS(modelName, relationshipName) { @@ -8233,10 +8404,12 @@ 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._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName))); + previousPayload = this._rhsPayloads[id]; idToPayloads = this._rhsPayloads; inverseIdToPayloads = this._lhsPayloads; inverseIsMany = this._lhsRelationshipIsMany; } @@ -8274,17 +8447,11 @@ // }] // // Then we will initially have set user:2 as having helicopter:1, which we // need to remove before adding helicopter:1 to user:4 // - // 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, inverseIdToPayloads); - } + this._removeInverse(id, previousPayload, inverseIdToPayloads); idToPayloads[id] = relationshipData; this._populateInverse(relationshipData, inverseRelationshipData, inverseIdToPayloads, inverseIsMany); } }; @@ -8491,23 +8658,10 @@ BelongsToRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() { this.notifyBelongsToChanged(); }; - BelongsToRelationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) { - _Relationship.prototype.removeCompletelyFromOwn.call(this, internalModel); - - if (this.canonicalState === internalModel) { - this.canonicalState = null; - } - - if (this.inverseInternalModel === internalModel) { - this.inverseInternalModel = null; - this.notifyBelongsToChanged(); - } - }; - BelongsToRelationship.prototype.flushCanonical = function flushCanonical() { //temporary fix to not remove newly created records if server returned null. //TODO remove once we have proper diffing if (this.inverseInternalModel && this.inverseInternalModel.isNew() && !this.canonicalState) { return; @@ -8534,10 +8688,11 @@ this.notifyBelongsToChanged(); }; BelongsToRelationship.prototype.setRecordPromise = function setRecordPromise(newPromise) { var content = newPromise.get && newPromise.get('content'); + (false && _ember.default.assert("You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call.", content !== undefined)); this.setInternalModel(content ? content._internalModel : content); }; BelongsToRelationship.prototype.removeInternalModelFromOwn = function removeInternalModelFromOwn(internalModel) { @@ -8605,10 +8760,11 @@ } else { if (this.inverseInternalModel === null) { return null; } var toReturn = this.inverseInternalModel.getRecord(); + (false && _ember.default.assert("You looked up the '" + this.key + "' relationship on a '" + this.internalModel.modelName + "' with id " + this.internalModel.id + " but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (`DS.belongsTo({ async: true })`)", toReturn === null || !toReturn.get('isEmpty'))); return toReturn; } }; @@ -8626,10 +8782,12 @@ return this.findRecord(); }; BelongsToRelationship.prototype.updateData = function updateData(data, initial) { + (false && _ember.default.assert('Ember Data expected the data for the ' + this.key + ' relationship on a ' + this.internalModel.toString() + ' to be in a JSON API format and include an `id` and `type` property but it found ' + _ember.default.inspect(data) + '. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.', data === null || data.id !== undefined && data.type !== undefined)); + var internalModel = this.store._pushResourceIdentifier(this, data); if (initial) { this.setInitialCanonicalInternalModel(internalModel); } else { this.setCanonicalInternalModel(internalModel); @@ -8682,11 +8840,13 @@ var inverseKey = void 0; var inverse = null; if (shouldFindInverse(relationshipMeta)) { inverse = internalModel.type.inverseFor(relationshipMeta.key, store); - } else {} + } else if (false) { + internalModel.type.typeForRelationship(relationshipMeta.key, store); + } if (inverse) { inverseKey = inverse.name; } @@ -8708,17 +8868,10 @@ Relationships.prototype.has = function has(key) { return !!this.initializedRelationships[key]; }; - Relationships.prototype.forEach = function forEach(cb) { - var rels = this.initializedRelationships; - Object.keys(rels).forEach(function (name) { - cb(name, rels[name]); - }); - }; - Relationships.prototype.get = function get(key) { var relationships = this.initializedRelationships; var relationship = relationships[key]; var internalModel = this.internalModel; @@ -8898,30 +9051,10 @@ this.canonicalState.splice(i, 1); } _Relationship.prototype.removeCanonicalInternalModelFromOwn.call(this, internalModel, idx); }; - ManyRelationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) { - _Relationship.prototype.removeCompletelyFromOwn.call(this, internalModel); - - var canonicalIndex = this.canonicalState.indexOf(internalModel); - - if (canonicalIndex !== -1) { - this.canonicalState.splice(canonicalIndex, 1); - } - - var manyArray = this._manyArray; - - if (manyArray) { - var idx = manyArray.currentState.indexOf(internalModel); - - if (idx !== -1) { - manyArray.internalReplace(idx, 1); - } - } - }; - ManyRelationship.prototype.flushCanonical = function flushCanonical() { if (this._manyArray) { this._manyArray.flushCanonical(); } _Relationship.prototype.flushCanonical.call(this); @@ -8994,40 +9127,37 @@ this.addCanonicalInternalModel(internalModel, i); } }; ManyRelationship.prototype.setInitialInternalModels = function setInitialInternalModels(internalModels) { - if (Array.isArray(internalModels) === false || internalModels.length === 0) { + var _this2 = this; + + if (!internalModels) { return; } - for (var i = 0; i < internalModels.length; i++) { - var internalModel = internalModels[i]; - if (this.canonicalMembers.has(internalModel)) { - continue; - } - - this.canonicalMembers.add(internalModel); - this.members.add(internalModel); - this.setupInverseRelationship(internalModel); - } - - this.canonicalState = this.canonicalMembers.toArray(); + var args = [0, this.canonicalState.length].concat(internalModels); + this.canonicalState.splice.apply(this.canonicalState, args); + internalModels.forEach(function (internalModel) { + _this2.canonicalMembers.add(internalModel); + _this2.members.add(internalModel); + _this2.setupInverseRelationship(internalModel); + }); }; ManyRelationship.prototype.fetchLink = function fetchLink() { - var _this2 = this; + var _this3 = this; return this.store.findHasMany(this.internalModel, this.link, this.relationshipMeta).then(function (records) { if (records.hasOwnProperty('meta')) { - _this2.updateMeta(records.meta); + _this3.updateMeta(records.meta); } - _this2.store._backburner.join(function () { - _this2.updateInternalModelsFromAdapter(records); - _this2.manyArray.set('isLoaded', true); + _this3.store._backburner.join(function () { + _this3.updateInternalModelsFromAdapter(records); + _this3.manyArray.set('isLoaded', true); }); - return _this2.manyArray; + return _this3.manyArray; }); }; ManyRelationship.prototype.findRecords = function findRecords() { var manyArray = this.manyArray; @@ -9046,30 +9176,32 @@ ManyRelationship.prototype.notifyHasManyChanged = function notifyHasManyChanged() { this.internalModel.notifyHasManyAdded(this.key); }; ManyRelationship.prototype.getRecords = function getRecords() { - var _this3 = this; + var _this4 = this; //TODO(Igor) sync server here, once our syncing is not stupid var manyArray = this.manyArray; if (this.isAsync) { var promise = void 0; if (this.link) { if (this.hasLoaded) { promise = this.findRecords(); } else { promise = this.findLink().then(function () { - return _this3.findRecords(); + return _this4.findRecords(); }); } } else { promise = this.findRecords(); } return this._updateLoadingPromise(promise, manyArray); } else { + (false && Ember.assert('You looked up the \'' + this.key + '\' relationship on a \'' + this.internalModel.type.modelName + '\' with id ' + this.internalModel.id + ' but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (\'DS.hasMany({ async: true })\')', manyArray.isEvery('isEmpty', false))); + //TODO(Igor) WTF DO I DO HERE? // TODO @runspired equal WTFs to Igor if (!manyArray.get('isDestroyed')) { manyArray.set('isLoaded', true); } @@ -9084,24 +9216,10 @@ } else { this.updateInternalModelsFromAdapter(internalModels); } }; - ManyRelationship.prototype.destroy = function destroy() { - _Relationship.prototype.destroy.call(this); - var manyArray = this._manyArray; - if (manyArray) { - manyArray.destroy(); - } - - var proxy = this.__loadingPromise; - - if (proxy) { - proxy.destroy(); - } - }; - _createClass(ManyRelationship, [{ key: '_loadingPromise', get: function () { return this.__loadingPromise; } @@ -9139,11 +9257,11 @@ } return set; } }); -define('ember-data/-private/system/relationships/state/relationship', ['exports', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/normalize-link', 'ember'], function (exports, _orderedSet, _normalizeLink2, _ember) { +define('ember-data/-private/system/relationships/state/relationship', ['exports', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/normalize-link'], function (exports, _orderedSet, _normalizeLink2) { 'use strict'; exports.__esModule = true; function _classCallCheck(instance, Constructor) { @@ -9168,12 +9286,10 @@ if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - var guidFor = _ember.default.guidFor; - var Relationship = function () { function Relationship(store, internalModel, inverseKey, relationshipMeta) { var async = relationshipMeta.options.async; var polymorphic = relationshipMeta.options.polymorphic; this.members = new _orderedSet.default(); @@ -9192,32 +9308,26 @@ this.meta = null; this.hasData = false; this.hasLoaded = false; } - Relationship.prototype._inverseIsAsync = function _inverseIsAsync() { - if (!this.inverseKey || !this.inverseInternalModel) { - return false; - } - return this.inverseInternalModel._relationships.get(this.inverseKey).isAsync; - }; - Relationship.prototype.removeInverseRelationships = function removeInverseRelationships() { + var _this = this; + if (!this.inverseKey) { return; } var allMembers = // we actually want a union of members and canonicalMembers // they should be disjoint but currently are not due to a bug - this.members.list.concat(this.canonicalMembers.list); + this.members.toArray().concat(this.canonicalMembers.toArray()); - for (var i = 0; i < allMembers.length; i++) { - var inverseInternalModel = allMembers[i]; - var relationship = inverseInternalModel._relationships.get(this.inverseKey); + allMembers.forEach(function (inverseInternalModel) { + var relationship = inverseInternalModel._relationships.get(_this.inverseKey); relationship.inverseDidDematerialize(); - } + }); }; Relationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {}; Relationship.prototype.updateMeta = function updateMeta(meta) { @@ -9238,22 +9348,22 @@ this.removeCanonicalInternalModel(_member); } }; Relationship.prototype.removeInternalModels = function removeInternalModels(internalModels) { - var _this = this; + var _this2 = this; internalModels.forEach(function (internalModel) { - return _this.removeInternalModel(internalModel); + return _this2.removeInternalModel(internalModel); }); }; Relationship.prototype.addInternalModels = function addInternalModels(internalModels, idx) { - var _this2 = this; + var _this3 = this; internalModels.forEach(function (internalModel) { - _this2.addInternalModel(internalModel, idx); + _this3.addInternalModel(internalModel, idx); if (idx !== undefined) { idx++; } }); }; @@ -9292,11 +9402,11 @@ } } else { var _relationships = internalModel._implicitRelationships; var _relationship = _relationships[this.inverseKeyForImplicit]; if (!_relationship) { - _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } }); + _relationship = _relationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: {} }); } _relationship.addCanonicalInternalModel(this.internalModel); } }; @@ -9330,11 +9440,11 @@ this.notifyRecordRelationshipAdded(internalModel, idx); if (this.inverseKey) { internalModel._relationships.get(this.inverseKey).addInternalModel(this.internalModel); } else { if (!internalModel._implicitRelationships[this.inverseKeyForImplicit]) { - internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: { async: this.isAsync } }); + internalModel._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, internalModel, this.key, { options: {} }); } internalModel._implicitRelationships[this.inverseKeyForImplicit].addInternalModel(this.internalModel); } this.internalModel.updateRecordArrays(); } @@ -9362,10 +9472,11 @@ } }; Relationship.prototype.removeInternalModelFromOwn = function removeInternalModelFromOwn(internalModel) { this.members.delete(internalModel); + this.notifyRecordRelationshipRemoved(internalModel); this.internalModel.updateRecordArrays(); }; Relationship.prototype.removeCanonicalInternalModelFromInverse = function removeCanonicalInternalModelFromInverse(internalModel) { var inverseRelationship = internalModel._relationships.get(this.inverseKey); @@ -9378,42 +9489,10 @@ Relationship.prototype.removeCanonicalInternalModelFromOwn = function removeCanonicalInternalModelFromOwn(internalModel) { this.canonicalMembers.delete(internalModel); this.flushCanonicalLater(); }; - Relationship.prototype.removeCompletelyFromInverse = function removeCompletelyFromInverse() { - var _this3 = this; - - if (!this.inverseKey) { - return; - } - - // we actually want a union of members and canonicalMembers - // they should be disjoint but currently are not due to a bug - var seen = Object.create(null); - var internalModel = this.internalModel; - - var unload = function (inverseInternalModel) { - var id = guidFor(inverseInternalModel); - - if (seen[id] === undefined) { - var relationship = inverseInternalModel._relationships.get(_this3.inverseKey); - relationship.removeCompletelyFromOwn(internalModel); - seen[id] = true; - } - }; - - this.members.forEach(unload); - this.canonicalMembers.forEach(unload); - }; - - Relationship.prototype.removeCompletelyFromOwn = function removeCompletelyFromOwn(internalModel) { - this.canonicalMembers.delete(internalModel); - this.members.delete(internalModel); - this.internalModel.updateRecordArrays(); - }; - Relationship.prototype.flushCanonical = function flushCanonical() { var list = this.members.list; this.willSync = false; //a hack for not removing new internalModels //TODO remove once we have proper diffing @@ -9437,18 +9516,20 @@ } this.willSync = true; this.store._updateRelationshipState(this); }; - Relationship.prototype.updateLink = function updateLink(link, initial) { + Relationship.prototype.updateLink = function updateLink(link) { + (false && Ember.warn('You pushed a record of type \'' + this.internalModel.modelName + '\' with a relationship \'' + this.key + '\' configured as \'async: false\'. You\'ve included a link but no primary data, this may be an error in your payload.', this.isAsync || this.hasData, { + id: 'ds.store.push-link-for-sync-relationship' + })); + (false && Ember.assert('You have pushed a record of type \'' + this.internalModel.modelName + '\' with \'' + this.key + '\' as a link, but the value of that link is not a string.', typeof link === 'string' || link === null)); + this.link = link; this.linkPromise = null; - - if (!initial) { - this.internalModel.notifyPropertyChange(this.key); - } + this.internalModel.notifyPropertyChange(this.key); }; Relationship.prototype.findLink = function findLink() { if (this.linkPromise) { return this.linkPromise; @@ -9467,10 +9548,12 @@ this.computeChanges(internalModels); }; Relationship.prototype.notifyRecordRelationshipAdded = function notifyRecordRelationshipAdded() {}; + Relationship.prototype.notifyRecordRelationshipRemoved = function notifyRecordRelationshipRemoved() {}; + Relationship.prototype.setHasData = function setHasData(value) { this.hasData = value; }; Relationship.prototype.setHasLoaded = function setHasLoaded(value) { @@ -9517,12 +9600,10 @@ } }; Relationship.prototype.updateData = function updateData() {}; - Relationship.prototype.destroy = function destroy() {}; - _createClass(Relationship, [{ key: 'parentType', get: function () { return this.internalModel.modelName; } @@ -10040,11 +10121,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()` or `store#findAll()`. This means any + `store#peekAll()`, `store#findAll()` or `store#filter()`. 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 @@ -10122,11 +10203,16 @@ @deprecated @param {DS.Model} record the record to serialize @param {Object} options an options hash */ serialize: function (record, options) { - if (true) {} + if (true) { + (false && !(false) && _ember.default.deprecate('Use of store.serialize is deprecated, use record.serialize instead.', false, { + id: 'ds.store.serialize', + until: '3.0' + })); + } var snapshot = record._internalModel.createSnapshot(); return snapshot.serialize(options); }, @@ -10143,10 +10229,13 @@ @return DS.Adapter */ defaultAdapter: computed('adapter', function () { var adapter = get(this, 'adapter'); + (false && _ember.default.assert('You tried to set `adapter` property to an instance of `DS.Adapter`, where it should be a name', typeof adapter === 'string')); + + return this.adapterFor(adapter); }), // ..................... // . CREATE NEW RECORD . @@ -10174,10 +10263,13 @@ @param {Object} inputProperties a hash of properties to set on the newly created record. @return {DS.Model} record */ createRecord: function (modelName, inputProperties) { + (false && _ember.default.assert('You need to pass a model name to the store\'s createRecord method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var properties = copy(inputProperties) || Object.create(null); // If the passed properties do not include a primary key, // give the adapter an opportunity to generate one. Typically, @@ -10195,13 +10287,11 @@ internalModel.loadedData(); var record = internalModel.getRecord(properties); // TODO @runspired this should also be coalesced into some form of internalModel.setState() internalModel.eachRelationship(function (key, descriptor) { - if (properties[key] !== undefined) { - internalModel._relationships.get(key).setHasData(true); - } + internalModel._relationships.get(key).setHasData(true); }); return record; }, @@ -10278,10 +10368,18 @@ */ find: function (modelName, id, options) { // The default `model` hook in Ember.Route calls `find(modelName, id)`, // that's why we have to keep this method around even though `findRecord` is // the public way to get a record by modelName and id. + (false && _ember.default.assert('Using store.find(type) has been removed. Use store.findAll(modelName) to retrieve all records for a given type.', arguments.length !== 1)); + (false && _ember.default.assert('Calling store.find(modelName, id, { preload: preload }) is no longer supported. Use store.findRecord(modelName, id, { preload: preload }) instead.', !options)); + (false && _ember.default.assert('You need to pass the model name and id to the store\'s find method', arguments.length === 2)); + (false && _ember.default.assert('You cannot pass \'' + id + '\' as id to the store\'s find method', typeof id === 'string' || typeof id === 'number')); + (false && _ember.default.assert('Calling store.find() with a query object is no longer supported. Use store.query() instead.', typeof id !== 'object')); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + + var normalizedModelName = (0, _normalizeModelName.default)(modelName); return this.findRecord(normalizedModelName, id); }, @@ -10458,11 +10556,15 @@ @param {(String|Integer)} id @param {Object} options @return {Promise} promise */ findRecord: function (modelName, id, options) { + (false && _ember.default.assert('You need to pass a model name to the store\'s findRecord method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + (false && _ember.default.assert(badIdFormatAssertion, typeof id === 'string' && id.length > 0 || typeof id === 'number' && !isNaN(id))); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var internalModel = this._internalModelForId(normalizedModelName, id); options = options || {}; @@ -10533,11 +10635,14 @@ @param {String} modelName @param {Array} ids @return {Promise} promise */ findByIds: function (modelName, ids) { + (false && _ember.default.assert('You need to pass a model name to the store\'s findByIds method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var promises = new Array(ids.length); var normalizedModelName = (0, _normalizeModelName.default)(modelName); for (var i = 0; i < ids.length; i++) { @@ -10559,10 +10664,14 @@ */ _fetchRecord: function (internalModel, options) { var modelName = internalModel.modelName; var adapter = this.adapterFor(modelName); + (false && _ember.default.assert('You tried to find a record but you have no adapter (for ' + modelName + ')', adapter)); + (false && _ember.default.assert('You tried to find a record but your adapter (for ' + modelName + ') does not implement \'findRecord\'', typeof adapter.findRecord === 'function')); + + return (0, _finders._find)(adapter, this, internalModel.type, internalModel.id, internalModel, options); }, _scheduleFetchMany: function (internalModels) { var fetches = new Array(internalModels.length); @@ -10651,10 +10760,16 @@ missingInternalModels.push(_internalModel3); } } if (missingInternalModels.length) { + (false && _ember.default.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + inspect(missingInternalModels.map(function (r) { + return r.id; + })), false, { + id: 'ds.store.missing-records-from-adapter' + })); + rejectInternalModels(missingInternalModels); } } function rejectInternalModels(internalModels, error) { @@ -10708,11 +10823,13 @@ }); })(groupedInternalModels); } else if (ids.length === 1) { var pair = seeking[groupedInternalModels[0].id]; _fetchRecord(pair); - } else {} + } else { + (false && _ember.default.assert("You cannot return an empty array from adapter's method groupRecordsForFindMany", false)); + } } } else { for (var _i6 = 0; _i6 < totalItems; _i6++) { _fetchRecord(pendingFetchItems[_i6]); } @@ -10771,10 +10888,13 @@ @param {String} modelName @param {String|Integer} id @return {DS.Model|null} record */ peekRecord: function (modelName, id) { + (false && _ember.default.assert('You need to pass a model name to the store\'s peekRecord method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); if (this.hasRecordForId(normalizedModelName, id)) { return this._internalModelForId(normalizedModelName, id).getRecord(); } else { @@ -10797,10 +10917,15 @@ var id = internalModel.id, modelName = internalModel.modelName; var adapter = this.adapterFor(modelName); + (false && _ember.default.assert('You cannot reload a record without an ID', id)); + (false && _ember.default.assert('You tried to reload a record but you have no adapter (for ' + modelName + ')', adapter)); + (false && _ember.default.assert('You tried to reload a record but your adapter does not implement \'findRecord\'', typeof adapter.findRecord === 'function' || typeof adapter.find === 'function')); + + return this._scheduleFetch(internalModel); }, /** @@ -10818,11 +10943,14 @@ @param {String} modelName @param {(String|Integer)} id @return {Boolean} */ hasRecordForId: function (modelName, id) { + (false && _ember.default.assert('You need to pass a model name to the store\'s hasRecordForId method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var trueId = (0, _coerceId.default)(id); var internalModel = this._internalModelsFor(normalizedModelName).get(trueId); @@ -10838,27 +10966,29 @@ @param {String} modelName @param {(String|Integer)} id @return {DS.Model} record */ recordForId: function (modelName, id) { + (false && _ember.default.assert('You need to pass a model name to the store\'s recordForId method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + return this._internalModelForId(modelName, id).getRecord(); }, _internalModelForId: function (modelName, id) { var trueId = (0, _coerceId.default)(id); var internalModel = this._internalModelsFor(modelName).get(trueId); - if (internalModel) { - if (internalModel.hasScheduledDestroy()) { - internalModel.destroySync(); - return this._buildInternalModel(modelName, trueId); - } else { - return internalModel; - } + if (!internalModel) { + internalModel = this._buildInternalModel(modelName, trueId); } else { - return this._buildInternalModel(modelName, trueId); + // if we already have an internalModel, we need to ensure any async teardown is cancelled + // since we want it again. + internalModel.cancelDestroy(); } + + return internalModel; }, _internalModelDidReceiveRelationshipData: function (modelName, id, relationshipData) { this._relationshipsPayloads.push(modelName, id, relationshipData); }, _internalModelDestroyed: function (internalModel) { @@ -10900,10 +11030,14 @@ @return {Promise} promise */ findHasMany: function (internalModel, link, relationship) { var adapter = this.adapterFor(internalModel.modelName); + (false && _ember.default.assert('You tried to load a hasMany relationship but you have no adapter (for ' + internalModel.modelName + ')', adapter)); + (false && _ember.default.assert('You tried to load a hasMany relationship from a specified \'link\' in the original payload but your adapter does not implement \'findHasMany\'', typeof adapter.findHasMany === 'function')); + + return (0, _finders._findHasMany)(adapter, this, internalModel, link, relationship); }, /** @@ -10915,10 +11049,14 @@ @return {Promise} promise */ findBelongsTo: function (internalModel, link, relationship) { var adapter = this.adapterFor(internalModel.modelName); + (false && _ember.default.assert('You tried to load a belongsTo relationship but you have no adapter (for ' + internalModel.modelName + ')', adapter)); + (false && _ember.default.assert('You tried to load a belongsTo relationship from a specified \'link\' in the original payload but your adapter does not implement \'findBelongsTo\'', typeof adapter.findBelongsTo === 'function')); + + return (0, _finders._findBelongsTo)(adapter, this, internalModel, link, relationship); }, /** @@ -10958,19 +11096,26 @@ @param {String} modelName @param {any} query an opaque query to be used by the adapter @return {Promise} promise */ query: function (modelName, query) { + (false && _ember.default.assert('You need to pass a model name to the store\'s query method', isPresent(modelName))); + (false && _ember.default.assert('You need to pass a query hash to the store\'s query method', query)); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); return this._query(normalizedModelName, query); }, _query: function (modelName, query, array) { + (false && _ember.default.assert('You need to pass a model name to the store\'s query method', isPresent(modelName))); + (false && _ember.default.assert('You need to pass a query hash to the store\'s query method', query)); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); - array = array || this.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query); - var adapter = this.adapterFor(modelName); + (false && _ember.default.assert('You tried to load a query but you have no adapter (for ' + modelName + ')', adapter)); + (false && _ember.default.assert('You tried to load a query but your adapter does not implement \'query\'', typeof adapter.query === 'function')); var pA = (0, _promiseProxies.promiseArray)((0, _finders._query)(adapter, this, modelName, query, array)); return pA; @@ -11054,15 +11199,23 @@ @param {String} modelName @param {any} query an opaque query to be used by the adapter @return {Promise} promise which resolves with the found record or `null` */ queryRecord: function (modelName, query) { + (false && _ember.default.assert('You need to pass a model name to the store\'s queryRecord method', isPresent(modelName))); + (false && _ember.default.assert('You need to pass a query hash to the store\'s queryRecord method', query)); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var adapter = this.adapterFor(normalizedModelName); + (false && _ember.default.assert('You tried to make a query but you have no adapter (for ' + normalizedModelName + ')', adapter)); + (false && _ember.default.assert('You tried to make a query but your adapter does not implement \'queryRecord\'', typeof adapter.queryRecord === 'function')); + + return (0, _promiseProxies.promiseObject)((0, _finders._queryRecord)(adapter, this, modelName, query).then(function (internalModel) { // the promise returned by store.queryRecord is expected to resolve with // an instance of DS.Model if (internalModel) { return internalModel.getRecord(); @@ -11222,10 +11375,13 @@ @param {String} modelName @param {Object} options @return {Promise} promise */ findAll: function (modelName, options) { + (false && _ember.default.assert('You need to pass a model name to the store\'s findAll method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var fetch = this._fetchAll(normalizedModelName, this.peekAll(normalizedModelName), options); return fetch; }, @@ -11242,10 +11398,14 @@ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var adapter = this.adapterFor(modelName); var sinceToken = this._internalModelsFor(modelName).metadata.since; + (false && _ember.default.assert('You tried to load all records but you have no adapter (for ' + modelName + ')', adapter)); + (false && _ember.default.assert('You tried to load all records but your adapter does not implement \'findAll\'', typeof adapter.findAll === 'function')); + + if (options.reload) { set(array, 'isUpdating', true); return (0, _promiseProxies.promiseArray)((0, _finders._findAll)(adapter, this, modelName, sinceToken, options)); } @@ -11273,15 +11433,15 @@ @method _didUpdateAll @param {String} modelName @private */ _didUpdateAll: function (modelName) { - var liveRecordArray = this.recordArrayManager.liveRecordArrayFor(modelName); - - set(liveRecordArray, 'isUpdating', false); + this.recordArrayManager._didUpdateAll(modelName); }, didUpdateAll: function (modelName) { + (false && !(false) && _ember.default.deprecate('didUpdateAll was documented as private and will be removed in the next version of Ember Data.', false, { id: 'ember-data.didUpdateAll', until: '2.17.0' })); + return this._didUpdateAll(modelName); }, /** @@ -11302,16 +11462,15 @@ @method peekAll @param {String} modelName @return {DS.RecordArray} */ peekAll: function (modelName) { - var normalizedModelName = (0, _normalizeModelName.default)(modelName); - var liveRecordArray = this.recordArrayManager.liveRecordArrayFor(normalizedModelName); + (false && _ember.default.assert('You need to pass a model name to the store\'s peekAll method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); - this.recordArrayManager.syncLiveRecordArray(liveRecordArray, normalizedModelName); - - return liveRecordArray; + var normalizedModelName = (0, _normalizeModelName.default)(modelName); + return this.recordArrayManager.liveRecordArrayFor(normalizedModelName); }, /** This method unloads all records in the store. @@ -11323,11 +11482,13 @@ ``` @method unloadAll @param {String} modelName */ unloadAll: function (modelName) { + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, !modelName || typeof modelName === 'string')); + if (arguments.length === 0) { this._identityMap.clear(); } else { var normalizedModelName = (0, _normalizeModelName.default)(modelName); this._internalModelsFor(normalizedModelName).clear(); @@ -11378,13 +11539,18 @@ @param {Function} filter @return {DS.PromiseArray} @deprecated */ filter: function (modelName, query, filter) { + (false && _ember.default.assert('You need to pass a model name to the store\'s filter method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); - if (!ENV.ENABLE_DS_FILTER) {} + if (!ENV.ENABLE_DS_FILTER) { + (false && _ember.default.assert('The filter API has been moved to a plugin. To enable store.filter using an environment flag, or to use an alternative, you can visit the ember-data-filter addon page. https://github.com/ember-data/ember-data-filter', false)); + } + var promise = void 0; var length = arguments.length; var array = void 0; var hasQuery = length === 3; @@ -11419,10 +11585,15 @@ @param {String} modelName @param {string} id @return {boolean} */ recordIsLoaded: function (modelName, id) { + (false && !(false) && _ember.default.deprecate('Use of recordIsLoaded is deprecated, use hasRecordForId instead.', false, { + id: 'ds.store.recordIsLoaded', + until: '3.0' + })); + return this.hasRecordForId(modelName, id); }, // .............. @@ -11468,12 +11639,11 @@ var internalModel = snapshot._internalModel; var adapter = this.adapterFor(internalModel.modelName); var operation = void 0; if (internalModel.currentState.stateName === 'root.deleted.saved') { - resolver.resolve(); - continue; + return resolver.resolve(); } else if (internalModel.isNew()) { operation = 'createRecord'; } else if (internalModel.isDeleted()) { operation = 'deleteRecord'; } else { @@ -11503,11 +11673,13 @@ } if (data) { // normalize relationship IDs into records this.updateId(internalModel, data); this._setupRelationshipsForModel(internalModel, data); - } else {} + } else { + (false && _ember.default.assert('Your ' + internalModel.modelName + ' record was saved to the server, but the response does not have an id and no id has been set client side. Records must have ids. Please update the server response to provide an id in the response or generate the id on the client side either before saving the record or while normalizing the response.', internalModel.id)); + } //We first make sure the primary data has been updated //TODO try to move notification to the user to the end of the runloop internalModel.adapterDidCommit(data); }, @@ -11554,23 +11726,25 @@ var oldId = internalModel.id; var modelName = internalModel.modelName; var id = (0, _coerceId.default)(data.id); // ID absolutely can't be missing if the oldID is empty (missing Id in response for a new record) + (false && _ember.default.assert('\'' + modelName + '\' was saved to the server, but the response does not have an id and your record does not either.', !(id === null && oldId === null))); - // ID absolutely can't be different than oldID if oldID is not null + (false && _ember.default.assert('\'' + modelName + ':' + oldId + '\' was saved to the server, but the response returned the new id \'' + id + '\'. The store cannot assign a new id to a record that already has an id.', !(oldId !== null && id !== oldId))); // ID can be null if oldID is not null (altered ID in response for a record) // however, this is more than likely a developer error. + if (oldId !== null && id === null) { + (false && _ember.default.warn('Your ' + modelName + ' record was saved to the server, but the response does not have an id.', !(oldId !== null && id === null))); + return; } - var existingInternalModel = this._existingInternalModelForId(modelName, id); - this._internalModelsFor(internalModel.modelName).set(id, internalModel); internalModel.setId(id); }, @@ -11662,11 +11836,14 @@ @method modelFor @param {String} modelName @return {DS.Model} */ modelFor: function (modelName) { + (false && _ember.default.assert('You need to pass a model name to the store\'s modelFor method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); return this._modelFor(normalizedModelName); }, @@ -11694,11 +11871,14 @@ } // interopt with the future var klass = (0, _utils.getOwner)(this).factoryFor ? factory.class : factory; + (false && _ember.default.assert('\'' + inspect(klass) + '\' does not appear to be an ember-data model', klass.isModel)); + // TODO: deprecate this + klass.modelName = klass.modelName || modelName; this._modelFactoryCache[modelName] = factory; } @@ -11708,11 +11888,14 @@ /* @private */ modelFactoryFor: function (modelName) { + (false && _ember.default.assert('You need to pass a model name to the store\'s modelFactoryFor method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var owner = (0, _utils.getOwner)(this); if (owner.factoryFor) { return owner.factoryFor('model:' + normalizedModelName); @@ -11906,10 +12089,13 @@ if (jsonApiDoc.data === null) { return null; } + (false && _ember.default.assert('Expected an object in the \'data\' property in a call to \'push\' for ' + jsonApiDoc.type + ', but was ' + typeOf(jsonApiDoc.data), typeOf(jsonApiDoc.data) === 'object')); + + return _this._pushInternalModel(jsonApiDoc.data); }); return internalModelOrModels; }, @@ -11922,15 +12108,39 @@ } else { return !!owner._lookupFactory('model:' + modelName); } }, _pushInternalModel: function (data) { - var _this2 = this; - var modelName = data.type; + (false && _ember.default.assert('You must include an \'id\' for ' + modelName + ' in an object passed to \'push\'', data.id !== null && data.id !== undefined && data.id !== '')); + (false && _ember.default.assert('You tried to push data with a type \'' + modelName + '\' but no model could be found with that name.', this._hasModelFor(modelName))); + if (false) { + // If ENV.DS_WARN_ON_UNKNOWN_KEYS is set to true and the payload + // contains unknown attributes or relationships, log a warning. + + if (ENV.DS_WARN_ON_UNKNOWN_KEYS) { + var modelClass = this._modelFor(modelName); + + // Check unknown attributes + var unknownAttributes = Object.keys(data.attributes || {}).filter(function (key) { + return !get(modelClass, 'fields').has(key); + }); + var unknownAttributesMessage = 'The payload for \'' + modelName + '\' contains these unknown attributes: ' + unknownAttributes + '. Make sure they\'ve been defined in your model.'; + (false && _ember.default.warn(unknownAttributesMessage, unknownAttributes.length === 0, { id: 'ds.store.unknown-keys-in-payload' })); + + // Check unknown relationships + + var unknownRelationships = Object.keys(data.relationships || {}).filter(function (key) { + return !get(modelClass, 'fields').has(key); + }); + var unknownRelationshipsMessage = 'The payload for \'' + modelName + '\' contains these unknown relationships: ' + unknownRelationships + '. Make sure they\'ve been defined in your model.'; + (false && _ember.default.warn(unknownRelationshipsMessage, unknownRelationships.length === 0, { id: 'ds.store.unknown-keys-in-payload' })); + } + } + // Actually load the record into the store. var internalModel = this._load(data); this._setupRelationshipsForModel(internalModel, data); @@ -12015,12 +12225,14 @@ var serializer = void 0; var payload = void 0; if (!inputPayload) { payload = modelName; serializer = defaultSerializer(this); + (false && _ember.default.assert('You cannot use \'store#pushPayload\' without a modelName unless your default serializer defines \'pushPayload\'', typeof serializer.pushPayload === 'function')); } else { payload = inputPayload; + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); var normalizedModelName = (0, _normalizeModelName.default)(modelName); serializer = this.serializerFor(normalizedModelName); } if ((0, _features.default)('ds-pushpayload-return')) { @@ -12046,10 +12258,13 @@ @param {String} modelName The name of the model type for this payload @param {Object} payload @return {Object} The normalized payload */ normalize: function (modelName, payload) { + (false && _ember.default.assert('You need to pass a model name to the store\'s normalize method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + inspect(modelName), typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); var serializer = this.serializerFor(normalizedModelName); var model = this._modelFor(normalizedModelName); return serializer.normalize(model, payload); }, @@ -12064,33 +12279,29 @@ @param {String} id @param {Object} data @return {InternalModel} internal model */ _buildInternalModel: function (modelName, id, data) { + (false && _ember.default.assert('You can no longer pass a modelClass as the first argument to store._buildInternalModel. Pass modelName instead.', typeof modelName === 'string')); - var existingInternalModel = this._existingInternalModelForId(modelName, id); + var recordMap = this._internalModelsFor(modelName); + + (false && _ember.default.assert('The id ' + id + ' has already been used with another record for modelClass \'' + modelName + '\'.', !id || !recordMap.get(id))); + // lookupFactory should really return an object that creates // instances with the injections applied + var internalModel = new _internalModel5.default(modelName, id, this, data); - this._internalModelsFor(modelName).add(internalModel, id); + recordMap.add(internalModel, id); return internalModel; }, - _existingInternalModelForId: function (modelName, id) { - var internalModel = this._internalModelsFor(modelName).get(id); - - if (internalModel && internalModel.hasScheduledDestroy()) { - // unloadRecord is async, if one attempts to unload + then sync create, - // we must ensure the unload is complete before starting the create - internalModel.destroySync(); - internalModel = null; - } - return internalModel; - }, buildInternalModel: function (modelName, id, data) { + (false && !(false) && _ember.default.deprecate('buildInternalModel was documented as private and will be removed in the next version of Ember Data.', false, { id: 'ember-data.buildInternalModel', until: '2.17.0' })); + return this._buildInternalModel(modelName, id, data); }, //Called by the state machine to notify the store that the record is ready to be interacted with @@ -12135,10 +12346,13 @@ @public @param {String} modelName @return DS.Adapter */ adapterFor: function (modelName) { + (false && _ember.default.assert('You need to pass a model name to the store\'s adapterFor method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store.adapterFor has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); return this._instanceCache.get('adapter', normalizedModelName); }, @@ -12163,18 +12377,31 @@ @public @param {String} modelName the record to serialize @return {DS.Serializer} */ serializerFor: function (modelName) { + (false && _ember.default.assert('You need to pass a model name to the store\'s serializerFor method', isPresent(modelName))); + (false && _ember.default.assert('Passing classes to store.serializerFor has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string')); + var normalizedModelName = (0, _normalizeModelName.default)(modelName); return this._instanceCache.get('serializer', normalizedModelName); }, lookupAdapter: function (name) { + (false && !(false) && _ember.default.deprecate('Use of lookupAdapter is deprecated, use adapterFor instead.', false, { + id: 'ds.store.lookupAdapter', + until: '3.0' + })); + return this.adapterFor(name); }, lookupSerializer: function (name) { + (false && !(false) && _ember.default.deprecate('Use of lookupSerializer is deprecated, use serializerFor instead.', false, { + id: 'ds.store.lookupSerializer', + until: '3.0' + })); + return this.serializerFor(name); }, willDestroy: function () { this._super.apply(this, arguments); this._pushedInternalModels = null; @@ -12182,18 +12409,18 @@ this._instanceCache.destroy(); this.unloadAll(); }, _updateRelationshipState: function (relationship) { - var _this3 = this; + var _this2 = this; if (this._updatedRelationships.push(relationship) !== 1) { return; } this._backburner.join(function () { - _this3._backburner.schedule('syncRelationships', _this3, _this3._flushUpdatedRelationships); + _this2._backburner.schedule('syncRelationships', _this2, _this2._flushUpdatedRelationships); }); }, _flushUpdatedRelationships: function () { var updated = this._updatedRelationships; @@ -12222,18 +12449,24 @@ _pushResourceIdentifier: function (relationship, resourceIdentifier) { if (isNone(resourceIdentifier)) { return; } + (false && _ember.default.assert('A ' + relationship.internalModel.modelName + ' record was pushed into the store with the value of ' + relationship.key + ' being ' + inspect(resourceIdentifier) + ', but ' + relationship.key + ' is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.', !Array.isArray(resourceIdentifier))); + //TODO:Better asserts + return this._internalModelForId(resourceIdentifier.type, resourceIdentifier.id); }, _pushResourceIdentifiers: function (relationship, resourceIdentifiers) { if (isNone(resourceIdentifiers)) { return; } + (false && _ember.default.assert('A ' + relationship.internalModel.modelName + ' record was pushed into the store with the value of ' + relationship.key + ' being \'' + inspect(resourceIdentifiers) + '\', but ' + relationship.key + ' is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.', Array.isArray(resourceIdentifiers))); + + var _internalModels = new Array(resourceIdentifiers.length); for (var i = 0; i < resourceIdentifiers.length; i++) { _internalModels[i] = this._pushResourceIdentifier(relationship, resourceIdentifiers[i]); } return _internalModels; @@ -12249,15 +12482,20 @@ function _commit(adapter, store, operation, snapshot) { var internalModel = snapshot._internalModel; var modelName = snapshot.modelName; var modelClass = store._modelFor(modelName); + (false && _ember.default.assert('You tried to update a record but you have no adapter (for ' + modelName + ')', adapter)); + (false && _ember.default.assert('You tried to update a record but your adapter (for ' + modelName + ') does not implement \'' + operation + '\'', typeof adapter[operation] === 'function')); var promise = adapter[operation](store, modelClass, snapshot); var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName); var label = 'DS: Extract and notify about ' + operation + ' completion of ' + internalModel; + (false && _ember.default.assert('Your adapter\'s \'' + operation + '\' method must return a value, but it returned \'undefined\'', promise !== undefined)); + + promise = Promise.resolve(promise, label); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store)); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, internalModel)); return promise.then(function (adapterPayload) { @@ -12346,14 +12584,34 @@ var relationshipRequiresNotification = relationships.has(relationshipName) || isInverseRelationshipInitialized(store, internalModel, data, relationshipName, modelNameToInverseMap); if (relationshipRequiresNotification) { var relationshipData = data.relationships[relationshipName]; - relationships.get(relationshipName).push(relationshipData, false); + relationships.get(relationshipName).push(relationshipData); } // in debug, assert payload validity eagerly + if (false) { + var relationshipMeta = get(internalModel.type, 'relationshipsByName').get(relationshipName); + var _relationshipData = data.relationships[relationshipName]; + if (!_relationshipData || !relationshipMeta) { + return; + } + + if (_relationshipData.links) { + var isAsync = relationshipMeta.options && relationshipMeta.options.async !== false; + (false && _ember.default.warn('You pushed a record of type \'' + internalModel.type.modelName + '\' with a relationship \'' + relationshipName + '\' configured as \'async: false\'. You\'ve included a link but no primary data, this may be an error in your payload.', isAsync || _relationshipData.data, { + id: 'ds.store.push-link-for-sync-relationship' + })); + } else if (_relationshipData.data) { + if (relationshipMeta.kind === 'belongsTo') { + (false && _ember.default.assert('A ' + internalModel.type.modelName + ' record was pushed into the store with the value of ' + relationshipName + ' being ' + inspect(_relationshipData.data) + ', but ' + relationshipName + ' is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.', !Array.isArray(_relationshipData.data))); + } else if (relationshipMeta.kind === 'hasMany') { + (false && _ember.default.assert('A ' + internalModel.type.modelName + ' record was pushed into the store with the value of ' + relationshipName + ' being \'' + inspect(_relationshipData.data) + '\', but ' + relationshipName + ' is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.', Array.isArray(_relationshipData.data))); + } + } + } }); } exports.Store = Store; exports.default = Store; @@ -12525,12 +12783,18 @@ promise = Promise.resolve(promise, label); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store)); return promise.then(function (adapterPayload) { + (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, { + id: 'ds.store.findRecord.id-mismatch' + })); return store._push(payload); }, function (error) { internalModel.notFound(); @@ -12554,10 +12818,12 @@ promise = Promise.resolve(promise, label); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store)); return promise.then(function (adapterPayload) { + (false && _ember.default.assert('You made a \'findMany\' request for \'' + modelName + '\' records with ids \'[' + ids + ']\', 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, null, 'findMany'); return store._push(payload); }, null, 'DS: Extract payload of ' + modelName); } @@ -12571,10 +12837,12 @@ promise = Promise.resolve(promise, label); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store)); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, internalModel)); return promise.then(function (adapterPayload) { + (false && _ember.default.assert('You made a \'findHasMany\' request for a ' + internalModel.modelName + '\'s \'' + relationship.key + '\' relationship, using link \'' + link + '\' , but the adapter\'s response did not have any data', payloadIsNotBlank(adapterPayload))); + var serializer = (0, _serializers.serializerForAdapter)(store, adapter, relationship.type); var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findHasMany'); var internalModelArray = store._push(payload); internalModelArray.meta = payload.meta; @@ -12613,10 +12881,12 @@ promise = Promise.resolve(promise, label); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store)); return promise.then(function (adapterPayload) { + (false && _ember.default.assert('You made a \'findAll\' request for \'' + modelName + '\' records, 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, null, 'findAll'); store._push(payload); store._didUpdateAll(modelName); @@ -12625,12 +12895,19 @@ }, null, 'DS: Extract payload of findAll ${modelName}'); } function _query(adapter, store, modelName, query, recordArray) { var modelClass = store.modelFor(modelName); // adapter.query needs the class - var promise = adapter.query(store, modelClass, query, recordArray); + var promise = void 0; + if (adapter.query.length > 3) { + recordArray = recordArray || store.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query); + promise = adapter.query(store, modelClass, query, recordArray); + } else { + promise = adapter.query(store, modelClass, query); + } + var label = 'DS: Handle Adapter#query of ' + modelClass; promise = Promise.resolve(promise, label); promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store)); @@ -12639,12 +12916,18 @@ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'query'); var internalModels = store._push(payload); - recordArray._setInternalModels(internalModels, payload); + (false && _ember.default.assert('The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or use `store.queryRecord` to query for a single record.', Array.isArray(internalModels))); + if (recordArray) { + recordArray._setInternalModels(internalModels, payload); + } else { + recordArray = store.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query, internalModels, payload); + } + return recordArray; }, null, 'DS: Extract payload of query ' + modelName); } function _queryRecord(adapter, store, modelName, query) { @@ -12657,10 +12940,15 @@ return promise.then(function (adapterPayload) { var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName); var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'queryRecord'); + (false && _ember.default.assert('Expected the primary data returned by the serializer for a \'queryRecord\' response to be a single object or null but instead it was an array.', !Array.isArray(payload.data), { + id: 'ds.store.queryRecord-array-response' + })); + + return store._push(payload); }, null, 'DS: Extract payload of queryRecord ' + modelName); } }); define('ember-data/-private/system/store/serializer-response', ['exports', 'ember'], function (exports, _ember) { @@ -12741,10 +13029,14 @@ @return {Object} JSON-API Document */ function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) { var normalizedResponse = serializer.normalizeResponse(store, modelClass, payload, id, requestType); var validationErrors = []; + if (false) { + validationErrors = validateDocumentStructure(normalizedResponse); + } + (false && _ember.default.assert('normalizeResponse must return a valid JSON API document:\n\t* ' + validationErrors.join('\n\t* '), _ember.default.isEmpty(validationErrors))); return normalizedResponse; } }); @@ -12846,11 +13138,11 @@ break; } } if (foundSep === false) { - continue; + break; } var field = header.substring(0, j).trim(); var value = header.substring(j + 1, header.length).trim(); @@ -13457,11 +13749,11 @@ get: function () { return _private.errorsArrayToHash; } }); }); -define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-inflector', 'ember-data/adapters/rest', 'ember-data/-private'], function (exports, _ember, _emberInflector, _rest, _private) { +define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters/rest', 'ember-data/-private'], function (exports, _ember, _rest, _private) { 'use strict'; exports.__esModule = true; @@ -13599,15 +13891,10 @@ @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); @@ -13682,11 +13969,11 @@ return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } }); } }, pathForType: function (modelName) { var dasherized = _ember.default.String.dasherize(modelName); - return (0, _emberInflector.pluralize)(dasherized); + return _ember.default.String.pluralize(dasherized); }, updateRecord: function (store, type, snapshot) { if ((0, _private.isEnabled)('ds-improved-ajax') && !this._hasCustomizedAjax()) { return this._super.apply(this, arguments); } else { @@ -13700,20 +13987,33 @@ return this.ajax(url, 'PATCH', { data: data }); } }, _hasCustomizedAjax: function () { if (this.ajax !== JSONAPIAdapter.prototype.ajax) { + (false && !(false) && _ember.default.deprecate('JSONAPIAdapter#ajax has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, { + id: 'ds.json-api-adapter.ajax', + until: '3.0.0' + })); + return true; } if (this.ajaxOptions !== JSONAPIAdapter.prototype.ajaxOptions) { + (false && !(false) && _ember.default.deprecate('JSONAPIAdapterr#ajaxOptions has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, { + id: 'ds.json-api-adapter.ajax-options', + until: '3.0.0' + })); + return true; } return false; } - }); + }); /* global heimdall */ + /** + @module ember-data + */ if ((0, _private.isEnabled)('ds-improved-ajax')) { JSONAPIAdapter.reopen({ methodForRequest: function (params) { @@ -14488,14 +14788,24 @@ return query; }, _hasCustomizedAjax: function () { if (this.ajax !== RESTAdapter.prototype.ajax) { + (false && !(false) && _ember.default.deprecate('RESTAdapter#ajax has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, { + id: 'ds.rest-adapter.ajax', + until: '3.0.0' + })); + return true; } if (this.ajaxOptions !== RESTAdapter.prototype.ajaxOptions) { + (false && !(false) && _ember.default.deprecate('RESTAdapter#ajaxOptions has been deprecated please use. `methodForRequest`, `urlForRequest`, `headersForRequest` or `dataForRequest` instead.', false, { + id: 'ds.rest-adapter.ajax-options', + until: '3.0.0' + })); + return true; } return false; } @@ -14693,10 +15003,17 @@ return response; } } function ajaxError(adapter, jqXHR, requestData, responseData) { + if (false) { + var message = 'The server returned an empty string for ' + requestData.method + ' ' + requestData.url + ', which cannot be parsed into a valid JSON. Return either null or {}.'; + var validJSONString = !(responseData.textStatus === "parsererror" && jqXHR.responseText === ""); + (false && _ember.default.warn(message, validJSONString, { + id: 'ds.adapter.returned-empty-string-as-JSON' + })); + } var error = void 0; if (responseData.errorThrown instanceof Error) { error = responseData.errorThrown; @@ -14740,10 +15057,14 @@ function getDefaultValue(record, options, key) { if (typeof options.defaultValue === 'function') { return options.defaultValue.apply(null, arguments); } else { var defaultValue = options.defaultValue; + (false && !(typeof defaultValue !== 'object' || defaultValue === null) && _ember.default.deprecate('Non primitive defaultValues are deprecated because they are shared between all instances. If you would like to use a complex object as a default value please provide a function that returns the complex object.', typeof defaultValue !== 'object' || defaultValue === null, { + id: 'ds.defaultValue.complex-object', + until: '3.0.0' + })); return defaultValue; } } @@ -14990,11 +15311,13 @@ }); Object.defineProperty(_private.global, 'DS', { configurable: true, get: function () { + (false && !(false) && _ember.default.deprecate('Using the global version of DS is deprecated. Please either import ' + 'the specific modules needed or `import DS from \'ember-data\';`.', false, { id: 'ember-data.global-ds', until: '3.0.0' })); + return _private.DS; } }); exports.default = _private.DS; @@ -15007,11 +15330,11 @@ name: 'data-adapter', before: 'store', initialize: function () {} }; }); -define('ember-data/initializers/ember-data', ['exports', 'ember-data/setup-container', 'ember-data'], function (exports, _setupContainer) { +define('ember-data/initializers/ember-data', ['exports', 'ember-data/setup-container', 'ember-data/index'], function (exports, _setupContainer) { 'use strict'; exports.__esModule = true; exports.default = { name: 'ember-data', @@ -15062,10 +15385,12 @@ exports.__esModule = true; exports.default = initializeStoreService; + var deprecateOldEmberDataInitializers = void 0; + /* Configures a registry for use with an Ember-Data store. @method initializeStoreService @@ -15077,44 +15402,53 @@ var container = instance.lookup ? instance : instance.container; // Eagerly generate the store so defaultStore is populated. container.lookup('service:store'); - // In Ember 2.4+ instance.base is the `Ember.Application` or `Ember.Engine` instance - // In Ember 1.11 - 2.3 we fallback to `instance.application` - var base = instance.base || instance.application; - deprecateOldEmberDataInitializers(base.constructor.initializers); + if (false) { + // In Ember 2.4+ instance.base is the `Ember.Application` or `Ember.Engine` instance + // In Ember 1.11 - 2.3 we fallback to `instance.application` + var base = instance.base || instance.application; + deprecateOldEmberDataInitializers(base.constructor.initializers); + } } - var DEPRECATED_INITIALIZER_NAMES = ['data-adapter', 'injectStore', 'transforms', 'store']; + if (false) { + var DEPRECATED_INITIALIZER_NAMES = ['data-adapter', 'injectStore', 'transforms', 'store']; - function matchesDeprecatedInititalizer(name) { - return DEPRECATED_INITIALIZER_NAMES.indexOf(name) !== -1; - } + var matchesDeprecatedInititalizer = function matchesDeprecatedInititalizer(name) { + return DEPRECATED_INITIALIZER_NAMES.indexOf(name) !== -1; + }; - function deprecateOldEmberDataInitializers(initializers) { - // collect all of the initializers - var keys = Object.keys(initializers); + var warnForDeprecatedInitializers = function warnForDeprecatedInitializers(initializer) { + var deprecatedBeforeInitializer = matchesDeprecatedInititalizer(initializer.before); + var deprecatedAfterInitializer = matchesDeprecatedInititalizer(initializer.after); + var deprecatedProp = deprecatedBeforeInitializer ? 'before' : 'after'; - for (var i = 0; i < keys.length; i++) { - var name = keys[i]; + (false && !(!(deprecatedBeforeInitializer || deprecatedAfterInitializer)) && Ember.deprecate('The initializer `' + initializer[deprecatedProp] + '` has been deprecated. Please update your `' + initializer.name + '` initializer to use use `' + deprecatedProp + ': \'ember-data\'` instead.', !(deprecatedBeforeInitializer || deprecatedAfterInitializer), { + id: 'ds.deprecated-initializers', + until: '3.0.0' + })); + }; - // filter out all of the Ember Data initializer. We have some - // deprecated initializers that depend on other deprecated - // initializers which may trigger the deprecation warning - // unintentionally. - if (!matchesDeprecatedInititalizer(name)) { - warnForDeprecatedInitializers(initializers[name]); + deprecateOldEmberDataInitializers = function deprecateOldEmberDataInitializers(initializers) { + // collect all of the initializers + var keys = Object.keys(initializers); + + for (var i = 0; i < keys.length; i++) { + var name = keys[i]; + + // filter out all of the Ember Data initializer. We have some + // deprecated initializers that depend on other deprecated + // initializers which may trigger the deprecation warning + // unintentionally. + if (!matchesDeprecatedInititalizer(name)) { + warnForDeprecatedInitializers(initializers[name]); + } } - } + }; } - - function warnForDeprecatedInitializers(initializer) { - var deprecatedBeforeInitializer = matchesDeprecatedInititalizer(initializer.before); - var deprecatedAfterInitializer = matchesDeprecatedInititalizer(initializer.after); - var deprecatedProp = deprecatedBeforeInitializer ? 'before' : 'after'; - } }); define('ember-data/model', ['exports', 'ember-data/-private'], function (exports, _private) { 'use strict'; exports.__esModule = true; @@ -15661,10 +15995,13 @@ var serializedKey = this._getMappedKey(relationship.key, snapshot.type); if (serializedKey === relationship.key && this.keyForRelationship) { serializedKey = this.keyForRelationship(relationship.key, relationship.kind, "serialize"); } + (false && _ember.default.warn('The embedded relationship \'' + serializedKey + '\' is undefined for \'' + snapshot.modelName + '\' with id \'' + snapshot.id + '\'. Please include it in your original payload.', _ember.default.typeOf(snapshot.hasMany(relationship.key)) !== 'undefined', { id: 'ds.serializer.embedded-relationship-undefined' })); + + json[serializedKey] = this._generateSerializedHasMany(snapshot, relationship); }, /* @@ -16029,11 +16366,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { var modelName = this.modelNameFromPayloadType(relationshipDataHash.type); var deprecatedModelNameLookup = this.modelNameFromPayloadKey(relationshipDataHash.type); if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + (false && !(false) && _ember.default.deprecate("You are using modelNameFromPayloadKey to normalize the type for a relationship. This has been deprecated in favor of modelNameFromPayloadType", false, { + id: 'ds.json-api-serializer.deprecated-model-name-for-relationship', + until: '3.0.0' + })); + modelName = deprecatedModelNameLookup; } relationshipDataHash.type = modelName; } else { @@ -16041,31 +16383,44 @@ } return relationshipDataHash; }, _normalizeResourceHelper: function (resourceHash) { + (false && _ember.default.assert(this.warnMessageForUndefinedType(), !_ember.default.isNone(resourceHash.type), { + id: 'ds.serializer.type-is-undefined' + })); + var modelName = void 0, usedLookup = void 0; if ((0, _private.isEnabled)("ds-payload-type-hooks")) { modelName = this.modelNameFromPayloadType(resourceHash.type); var deprecatedModelNameLookup = this.modelNameFromPayloadKey(resourceHash.type); usedLookup = 'modelNameFromPayloadType'; if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + (false && !(false) && _ember.default.deprecate("You are using modelNameFromPayloadKey to normalize the type for a resource. This has been deprecated in favor of modelNameFromPayloadType", false, { + id: 'ds.json-api-serializer.deprecated-model-name-for-resource', + until: '3.0.0' + })); + modelName = deprecatedModelNameLookup; usedLookup = 'modelNameFromPayloadKey'; } } else { modelName = this.modelNameFromPayloadKey(resourceHash.type); usedLookup = 'modelNameFromPayloadKey'; } if (!this.store._hasModelFor(modelName)) { + (false && _ember.default.warn(this.warnMessageNoModelForType(modelName, resourceHash.type, usedLookup), false, { + id: 'ds.serializer.model-for-type-missing' + })); + return null; } var modelClass = this.store._modelFor(modelName); var serializer = this.store.serializerFor(modelName); @@ -16088,10 +16443,15 @@ return normalizedPayload; }, normalizeQueryRecordResponse: function () { var normalized = this._super.apply(this, arguments); + (false && _ember.default.assert('Expected the primary data returned by the serializer for a `queryRecord` response to be a single object but instead it was an array.', !Array.isArray(normalized.data), { + id: 'ds.serializer.json-api.queryRecord-array-response' + })); + + return normalized; }, extractAttributes: function (modelClass, resourceHash) { var _this = this; @@ -16101,10 +16461,15 @@ modelClass.eachAttribute(function (key) { var attributeKey = _this.keyForAttribute(key, 'deserialize'); if (resourceHash.attributes[attributeKey] !== undefined) { attributes[key] = resourceHash.attributes[attributeKey]; } + if (false) { + if (resourceHash.attributes[attributeKey] === undefined && resourceHash.attributes[key] !== undefined) { + (false && _ember.default.assert('Your payload for \'' + modelClass.modelName + '\' contains \'' + key + '\', but your serializer is setup to look for \'' + attributeKey + '\'. This is most likely because Ember Data\'s JSON API serializer dasherizes attribute keys by default. You should subclass JSONAPISerializer and implement \'keyForAttribute(key) { return key; }\' to prevent Ember Data from customizing your attribute keys.', false)); + } + } }); } return attributes; }, @@ -16138,10 +16503,15 @@ if (resourceHash.relationships[relationshipKey] !== undefined) { var relationshipHash = resourceHash.relationships[relationshipKey]; relationships[key] = _this2.extractRelationship(relationshipHash); } + if (false) { + if (resourceHash.relationships[relationshipKey] === undefined && resourceHash.relationships[key] !== undefined) { + (false && _ember.default.assert('Your payload for \'' + modelClass.modelName + '\' contains \'' + key + '\', but your serializer is setup to look for \'' + relationshipKey + '\'. This is most likely because Ember Data\'s JSON API serializer dasherizes relationship keys by default. You should subclass JSONAPISerializer and implement \'keyForRelationship(key) { return key; }\' to prevent Ember Data from customizing your relationship keys.', false)); + } + } }); } return relationships; }, @@ -16149,11 +16519,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { var modelName = this.modelNameFromPayloadType(resourceHash.type); var deprecatedModelNameLookup = this.modelNameFromPayloadKey(resourceHash.type); if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + (false && !(false) && _ember.default.deprecate("You are using modelNameFromPayloadKey to normalize the type for a polymorphic relationship. This has been deprecated in favor of modelNameFromPayloadType", false, { + id: 'ds.json-api-serializer.deprecated-model-name-for-polymorphic-type', + until: '3.0.0' + })); + modelName = deprecatedModelNameLookup; } return modelName; } else { @@ -16199,11 +16574,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { payloadType = this.payloadTypeFromModelName(snapshot.modelName); var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(snapshot.modelName); if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) { + (false && !(false) && _ember.default.deprecate("You used payloadKeyFromModelName to customize how a type is serialized. Use payloadTypeFromModelName instead.", false, { + id: 'ds.json-api-serializer.deprecated-payload-type-for-model', + until: '3.0.0' + })); + payloadType = deprecatedPayloadTypeLookup; } } else { payloadType = this.payloadKeyFromModelName(snapshot.modelName); } @@ -16253,11 +16633,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { payloadType = this.payloadTypeFromModelName(belongsTo.modelName); var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(belongsTo.modelName); if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) { + (false && !(false) && _ember.default.deprecate("You used payloadKeyFromModelName to serialize type for belongs-to relationship. Use payloadTypeFromModelName instead.", false, { + id: 'ds.json-api-serializer.deprecated-payload-type-for-belongs-to', + until: '3.0.0' + })); + payloadType = deprecatedPayloadTypeLookup; } } else { payloadType = this.payloadKeyFromModelName(belongsTo.modelName); } @@ -16300,11 +16685,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { payloadType = this.payloadTypeFromModelName(item.modelName); var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(item.modelName); if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) { + (false && !(false) && _ember.default.deprecate("You used payloadKeyFromModelName to serialize type for belongs-to relationship. Use payloadTypeFromModelName instead.", false, { + id: 'ds.json-api-serializer.deprecated-payload-type-for-has-many', + until: '3.0.0' + })); + payloadType = deprecatedPayloadTypeLookup; } } else { payloadType = this.payloadKeyFromModelName(item.modelName); } @@ -16337,10 +16727,30 @@ return this.payloadKeyFromModelName !== JSONAPISerializer.prototype.payloadKeyFromModelName; } }); } + 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, { + 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' + })); + }, + warnMessageForUndefinedType: function () { + return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')'; + }, + warnMessageNoModelForType: function (modelName, originalType, usedLookup) { + return 'Encountered a resource object with type "' + originalType + '", but no model was found for model name "' + modelName + '" (resolved model name using \'' + this.constructor.toString() + '.' + usedLookup + '("' + originalType + '")\').'; + } + }); + } + exports.default = JSONAPISerializer; }); define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/serializer', 'ember-data/-private'], function (exports, _ember, _serializer, _private) { 'use strict'; @@ -16416,11 +16826,11 @@ The `JSONSerializer` normalization process follows these steps: - `normalizeResponse` - entry method to the serializer. - `normalizeCreateRecordResponse` - a `normalizeResponse` for a specific operation is called. - `normalizeSingleResponse`|`normalizeArrayResponse` - for methods like `createRecord` we expect - a single record back, while for methods like `findAll` we expect multiple methods back. + a single record back, while for methods like `findAll` we expect multiple records back. - `normalize` - `normalizeArray` iterates and calls `normalize` for each of its records while `normalizeSingle` calls it once. This is the method you most likely want to subclass. - `extractId` | `extractAttributes` | `extractRelationships` - `normalize` delegates to these methods to turn the record payload into the JSON API format. @@ -16587,10 +16997,12 @@ included: [] }; var meta = this.extractMeta(store, primaryModelClass, payload); if (meta) { + (false && _ember.default.assert('The `meta` returned from `extractMeta` has to be an object, not "' + _ember.default.typeOf(meta) + '".', _ember.default.typeOf(meta) === 'object')); + documentHash.meta = meta; } if (isSingle) { var _normalize = this.normalize(primaryModelClass, payload), @@ -16684,11 +17096,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { var modelName = this.modelNameFromPayloadType(relationshipHash.type); var deprecatedModelNameLookup = this.modelNameFromPayloadKey(relationshipHash.type); if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + (false && !(false) && _ember.default.deprecate("You used modelNameFromPayloadKey to customize how a type is normalized. Use modelNameFromPayloadType instead", false, { + id: 'ds.json-serializer.deprecated-type-for-polymorphic-relationship', + until: '3.0.0' + })); + modelName = deprecatedModelNameLookup; } relationshipHash.type = modelName; } else { @@ -16799,11 +17216,15 @@ } } } }, _getMappedKey: function (key, modelClass) { + (false && _ember.default.warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', get(modelClass, 'attributes').has(key) || get(modelClass, 'relationshipsByName').has(key), { + id: 'ds.serializer.no-mapped-attrs-key' + })); + var attrs = get(this, 'attrs'); var mappedKey = void 0; if (attrs && attrs[key]) { mappedKey = attrs[key]; //We need to account for both the { title: 'post_title' } and @@ -16827,11 +17248,16 @@ var attrs = get(this, 'attrs'); return attrs && attrs[key] && attrs[key].serialize === true; }, shouldSerializeHasMany: function (snapshot, key, relationship) { - if (this._shouldSerializeHasMany !== JSONSerializer.prototype._shouldSerializeHasMany) {} + if (this._shouldSerializeHasMany !== JSONSerializer.prototype._shouldSerializeHasMany) { + (false && !(false) && _ember.default.deprecate('The private method _shouldSerializeHasMany has been promoted to the public API. Please remove the underscore to use the public shouldSerializeHasMany method.', false, { + id: 'ds.serializer.private-should-serialize-has-many', + until: '3.0.0' + })); + } return this._shouldSerializeHasMany(snapshot, key, relationship); }, _shouldSerializeHasMany: function (snapshot, key, relationship) { var relationshipType = snapshot.type.determineRelationshipType(relationship, this.store); @@ -16986,10 +17412,13 @@ return key; }, transformFor: function (attributeType, skipAssertion) { var transform = (0, _private.getOwner)(this).lookup('transform:' + attributeType); + (false && _ember.default.assert("Unable to find transform for '" + attributeType + "'", skipAssertion || !!transform)); + + return transform; } }); if ((0, _private.isEnabled)("ds-payload-type-hooks")) { @@ -17086,10 +17515,15 @@ return relationshipKey + 'Type'; }, normalize: function (modelClass, resourceHash, prop) { if (this.normalizeHash && this.normalizeHash[prop]) { + (false && !(false) && _ember.default.deprecate('`RESTSerializer.normalizeHash` has been deprecated. Please use `serializer.normalize` to modify the payload of single resources.', false, { + id: 'ds.serializer.normalize-hash-deprecated', + until: '3.0.0' + })); + this.normalizeHash[prop](resourceHash); } return this._super(modelClass, resourceHash); }, _normalizeArray: function (store, modelName, arrayHash, prop) { @@ -17130,11 +17564,16 @@ if ((0, _private.isEnabled)("ds-payload-type-hooks")) { modelName = this.modelNameFromPayloadType(hash.type); var deprecatedModelNameLookup = this.modelNameFromPayloadKey(hash.type); if (modelName !== deprecatedModelNameLookup && !this._hasCustomModelNameFromPayloadType() && this._hasCustomModelNameFromPayloadKey()) { + (false && !(false) && _ember.default.deprecate("You are using modelNameFromPayloadKey to normalize the type for a polymorphic relationship. This is has been deprecated in favor of modelNameFromPayloadType", false, { + id: 'ds.rest-serializer.deprecated-model-name-for-polymorphic-type', + until: '3.0.0' + })); + modelName = deprecatedModelNameLookup; } } else { modelName = this.modelNameFromPayloadKey(hash.type); } @@ -17153,10 +17592,12 @@ included: [] }; var meta = this.extractMeta(store, primaryModelClass, payload); if (meta) { + (false && _ember.default.assert('The `meta` returned from `extractMeta` has to be an object, not "' + _ember.default.typeOf(meta) + '".', _ember.default.typeOf(meta) === 'object')); + documentHash.meta = meta; } var keys = Object.keys(payload); @@ -17187,20 +17628,34 @@ modelName = prop.substr(1); } var typeName = this.modelNameFromPayloadKey(modelName); if (!store.modelFactoryFor(typeName)) { + (false && _ember.default.warn(this.warnMessageNoModelForKey(modelName, typeName), false, { + id: 'ds.serializer.model-for-key-missing' + })); + continue; } var isPrimary = !forcedSecondary && this.isPrimaryType(store, typeName, primaryModelClass); var value = payload[prop]; if (value === null) { continue; } + if (false) { + var isQueryRecordAnArray = requestType === 'queryRecord' && isPrimary && Array.isArray(value); + var message = "The adapter returned an array for the primary data of a `queryRecord` response. This is deprecated as `queryRecord` should return a single record."; + + (false && !(!isQueryRecordAnArray) && _ember.default.deprecate(message, !isQueryRecordAnArray, { + id: 'ds.serializer.rest.queryRecord-array-response', + until: '3.0' + })); + } + /* Support primary data as an object instead of an array. Example ``` { @@ -17276,10 +17731,14 @@ }; for (var prop in payload) { var modelName = this.modelNameFromPayloadKey(prop); if (!store.modelFactoryFor(modelName)) { + (false && _ember.default.warn(this.warnMessageNoModelForKey(prop, modelName), false, { + id: 'ds.serializer.model-for-key-missing' + })); + continue; } var type = store.modelFor(modelName); var typeSerializer = store.serializerFor(type.modelName); @@ -17329,11 +17788,16 @@ // `keyForAttribute`, which is not correct. The next code checks if the old // way is used and if it differs from the new way of using // `keyForPolymorphicType`. If this is the case, a deprecation warning is // logged and the old way is restored (so nothing breaks). if (key !== typeKey && this.keyForPolymorphicType === RESTSerializer.prototype.keyForPolymorphicType) { + (false && !(false) && _ember.default.deprecate("The key to serialize the type of a polymorphic record is created via keyForAttribute which has been deprecated. Use the keyForPolymorphicType hook instead.", false, { + id: 'ds.rest-serializer.deprecated-key-for-polymorphic-type', + until: '3.0.0' + })); + typeKey = key; } if (_ember.default.isNone(belongsTo)) { json[typeKey] = null; @@ -17378,11 +17842,16 @@ var payloadType = resourceHash[typeProperty]; var type = this.modelNameFromPayloadType(payloadType); var deprecatedTypeLookup = this.modelNameFromPayloadKey(payloadType); if (payloadType !== deprecatedTypeLookup && !this._hasCustomModelNameFromPayloadType() && this._hasCustomModelNameFromPayloadKey()) { + (false && !(false) && _ember.default.deprecate("You are using modelNameFromPayloadKey to normalize the type for a polymorphic relationship. This has been deprecated in favor of modelNameFromPayloadType", false, { + id: 'ds.rest-serializer.deprecated-model-name-for-polymorphic-type', + until: '3.0.0' + })); + type = deprecatedTypeLookup; } return { id: relationshipHash, @@ -17424,10 +17893,18 @@ return this.payloadKeyFromModelName !== RESTSerializer.prototype.payloadKeyFromModelName; } }); } + if (false) { + RESTSerializer.reopen({ + warnMessageNoModelForKey: function (prop, typeKey) { + return 'Encountered "' + prop + '" in payload, but no model was found for model name "' + typeKey + '" (resolved model name using ' + this.constructor.toString() + '.modelNameFromPayloadKey("' + prop + '"))'; + } + }); + } + exports.default = RESTSerializer; }); define('ember-data/setup-container', ['exports', 'ember-data/-private', 'ember-data/serializers/json-api', 'ember-data/serializers/json', 'ember-data/serializers/rest', 'ember-data/adapters/json-api', 'ember-data/adapters/rest', 'ember-data/transforms/number', 'ember-data/transforms/date', 'ember-data/transforms/string', 'ember-data/transforms/boolean'], function (exports, _private, _jsonApi, _json, _rest, _jsonApi2, _rest2, _number, _date, _string, _boolean) { 'use strict'; @@ -17592,13 +18069,17 @@ @namespace Ember @static @deprecated */ _ember.default.Date.parse = function (date) { + (false && !(false) && _ember.default.deprecate('Ember.Date.parse is deprecated because Safari 5-, IE8-, and\n Firefox 3.6- are no longer supported (see\n https://github.com/csnover/js-iso8601 for the history of this issue).\n Please use Date.parse instead', false, { + id: 'ds.ember.date.parse-deprecate', + until: '3.0.0' + })); + return Date.parse(date); - // throw deprecation }; /** The `DS.DateTransform` class is used to serialize and deserialize date attributes on Ember Data record objects. This transform is used @@ -17627,10 +18108,15 @@ if (type === "string") { var offset = serialized.indexOf('+'); if (offset !== -1 && serialized.length - 3 === offset) { + (false && !(false) && _ember.default.deprecate('The ECMA2015 Spec for ISO 8601 dates does not allow for shorthand timezone offsets such as +00.\n Ember Data\'s normalization of date\'s allowing for this shorthand has been deprecated, please update your API to return\n UTC dates formatted with \xB1hh:mm timezone offsets or implement a custom UTC transform.', false, { + id: 'ds.attr.date.normalize-utc', + until: '3.0.0' + })); + return new Date(serialized + ':00'); // this is a phantom specific bug fix in which +0000 is not supported } else if (offset !== -1 && serialized.length - 5 === offset) { offset += 3; @@ -17794,10 +18280,10 @@ }); define("ember-data/version", ["exports"], function (exports) { "use strict"; exports.__esModule = true; - exports.default = "2.14.11"; + exports.default = "2.15.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;