dist/globals/ember-data.prod.js in ember-data-source-2.9.0 vs dist/globals/ember-data.prod.js in ember-data-source-2.10.0.beta.1

- old
+ new

@@ -4,11 +4,11 @@ /*! * @overview Ember Data * @copyright Copyright 2011-2016 Tilde Inc. and contributors. * Portions Copyright 2011 LivingSocial Inc. * @license Licensed under MIT license (see license.js) - * @version 2.9.0 + * @version 2.10.0-beta.1 */ var loader, define, requireModule, require, requirejs; (function(global) { @@ -429,106 +429,222 @@ return url; }, /** - * @method urlForFindRecord - * @param {String} id - * @param {String} modelName - * @param {DS.Snapshot} snapshot - * @return {String} url - */ + Builds a URL for a `store.findRecord(type, id)` call. + Example: + ```app/adapters/user.js + import DS from 'ember-data'; + export default DS.JSONAPIAdapter.extend({ + urlForFindRecord(id, modelName, snapshot) { + let baseUrl = this.buildURL(); + return `${baseUrl}/users/${snapshot.adapterOptions.user_id}/playlists/${id}`; + } + }); + ``` + @method urlForFindRecord + @param {String} id + @param {String} modelName + @param {DS.Snapshot} snapshot + @return {String} url + */ urlForFindRecord: function (id, modelName, snapshot) { return this._buildURL(modelName, id); }, /** - * @method urlForFindAll - * @param {String} modelName - * @param {DS.SnapshotRecordArray} snapshot - * @return {String} url + Builds a URL for a `store.findAll(type)` call. + Example: + ```app/adapters/comment.js + import DS from 'ember-data'; + export default DS.JSONAPIAdapter.extend({ + urlForFindAll(id, modelName, snapshot) { + return 'data/comments.json'; + } + }); + ``` + @method urlForFindAll + @param {String} modelName + @param {DS.SnapshotRecordArray} snapshot + @return {String} url */ urlForFindAll: function (modelName, snapshot) { return this._buildURL(modelName); }, /** - * @method urlForQuery - * @param {Object} query - * @param {String} modelName - * @return {String} url + Builds a URL for a `store.query(type, query)` call. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.RESTAdapter.extend({ + host: 'https://api.github.com', + urlForQuery (query, modelName) { + switch(modelName) { + case 'repo': + return `https://api.github.com/orgs/${query.orgId}/repos`; + default: + return this._super(...arguments); + } + } + }); + ``` + @method urlForQuery + @param {Object} query + @param {String} modelName + @return {String} url */ urlForQuery: function (query, modelName) { return this._buildURL(modelName); }, /** - * @method urlForQueryRecord - * @param {Object} query - * @param {String} modelName - * @return {String} url + Builds a URL for a `store.queryRecord(type, query)` call. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.RESTAdapter.extend({ + urlForQueryRecord({ slug }, modelName) { + let baseUrl = this.buildURL(); + return `${baseUrl}/${encodeURIComponent(slug)}`; + } + }); + ``` + @method urlForQueryRecord + @param {Object} query + @param {String} modelName + @return {String} url */ urlForQueryRecord: function (query, modelName) { return this._buildURL(modelName); }, /** - * @method urlForFindMany - * @param {Array} ids - * @param {String} modelName - * @param {Array} snapshots - * @return {String} url + Builds a URL for coalesceing multiple `store.findRecord(type, id) + records into 1 request when the adapter's `coalesceFindRequests` + property is true. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.RESTAdapter.extend({ + urlForFindMany(ids, modelName) { + let baseUrl = this.buildURL(); + return `${baseUrl}/coalesce`; + } + }); + ``` + @method urlForFindMany + @param {Array} ids + @param {String} modelName + @param {Array} snapshots + @return {String} url */ urlForFindMany: function (ids, modelName, snapshots) { return this._buildURL(modelName); }, /** - * @method urlForFindHasMany - * @param {String} id - * @param {String} modelName - * @param {DS.Snapshot} snapshot - * @return {String} url + Builds a URL for fetching a async hasMany relationship when a url + is not provided by the server. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.JSONAPIAdapter.extend({ + urlForFindHasMany(id, modelName, snapshot) { + let baseUrl = this.buildURL(id, modelName); + return `${baseUrl}/relationships`; + } + }); + ``` + @method urlForFindHasMany + @param {String} id + @param {String} modelName + @param {DS.Snapshot} snapshot + @return {String} url */ urlForFindHasMany: function (id, modelName, snapshot) { return this._buildURL(modelName, id); }, /** - * @method urlForFindBelongsTo - * @param {String} id - * @param {String} modelName - * @param {DS.Snapshot} snapshot - * @return {String} url + Builds a URL for fetching a async belongsTo relationship when a url + is not provided by the server. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.JSONAPIAdapter.extend({ + urlForFindBelongsTo(id, modelName, snapshot) { + let baseUrl = this.buildURL(id, modelName); + return `${baseUrl}/relationships`; + } + }); + ``` + @method urlForFindBelongsTo + @param {String} id + @param {String} modelName + @param {DS.Snapshot} snapshot + @return {String} url */ urlForFindBelongsTo: function (id, modelName, snapshot) { return this._buildURL(modelName, id); }, /** - * @method urlForCreateRecord - * @param {String} modelName - * @param {DS.Snapshot} snapshot - * @return {String} url + Builds a URL for a `record.save()` call when the record was created + locally using `store.createRecord()`. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.RESTAdapter.extend({ + urlForCreateRecord(modelName, snapshot) { + return this._super(...arguments) + '/new'; + } + }); + ``` + @method urlForCreateRecord + @param {String} modelName + @param {DS.Snapshot} snapshot + @return {String} url */ urlForCreateRecord: function (modelName, snapshot) { return this._buildURL(modelName); }, /** - * @method urlForUpdateRecord - * @param {String} id - * @param {String} modelName - * @param {DS.Snapshot} snapshot - * @return {String} url + Builds a URL for a `record.save()` call when the record has been update locally. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.RESTAdapter.extend({ + urlForUpdateRecord(id, modelName, snapshot) { + return `/${id}/feed?access_token=${snapshot.adapterOptions.token}`; + } + }); + ``` + @method urlForUpdateRecord + @param {String} id + @param {String} modelName + @param {DS.Snapshot} snapshot + @return {String} url */ urlForUpdateRecord: function (id, modelName, snapshot) { return this._buildURL(modelName, id); }, /** - * @method urlForDeleteRecord + Builds a URL for a `record.save()` call when the record has been deleted locally. + Example: + ```app/adapters/application.js + import DS from 'ember-data'; + export default DS.RESTAdapter.extend({ + urlForDeleteRecord(id, modelName, snapshot) { + return this._super(...arguments) + '/destroy'; + } + }); + ``` + * @method urlForDeleteRecord * @param {String} id * @param {String} modelName * @param {DS.Snapshot} snapshot * @return {String} url */ @@ -636,10 +752,11 @@ exports.assert = assert; exports.debug = debug; exports.deprecate = deprecate; exports.info = info; exports.runInDebug = runInDebug; + exports.instrument = instrument; exports.warn = warn; exports.debugSeal = debugSeal; exports.assertPolymorphicType = assertPolymorphicType; function assert() { @@ -660,10 +777,14 @@ 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() { @@ -2100,10 +2221,13 @@ return function () { return get(this.currentState, key); }; } + // this (and all heimdall instrumentation) will be stripped by a babel transform + // https://github.com/heimdalljs/babel5-plugin-strip-heimdall + /* `InternalModel` is the Model class that we use internally inside Ember Data to represent models. Internal ED methods should only deal with `InternalModel` objects. It is a fast, plain Javascript class. We expose `DS.Model` to application code, by materializing a `DS.Model` from `InternalModel` lazily, as @@ -2277,18 +2401,18 @@ assign(this._data, data.attributes); this.pushedData(); if (this.record) { this.record._notifyProperties(changedKeys); } - this.didInitalizeData(); + this.didInitializeData(); }, becameReady: function () { _ember.default.run.schedule('actions', this.store.recordArrayManager, this.store.recordArrayManager.recordWasLoaded, this); }, - didInitalizeData: function () { + didInitializeData: function () { if (!this.dataHasInitialized) { this.becameReady(); this.dataHasInitialized = true; } }, @@ -2320,11 +2444,11 @@ @method loadedData @private */ loadedData: function () { this.send('loadedData'); - this.didInitalizeData(); + this.didInitializeData(); }, /* @method notFound @private @@ -5365,10 +5489,15 @@ @private @type DS.Store */ store: null, + replace: function () { + var type = get(this, 'type').toString(); + throw new Error("The result of a server query (for all " + type + " types) is immutable. To modify contents, use toArray()"); + }, + /** Retrieves an object from the content by index. @method objectAtContent @private @param {Number} index @@ -7380,10 +7509,11 @@ setHasLoaded: function (value) { this.hasLoaded = value; } }; }); +/* global heimdall */ define('ember-data/-private/system/snapshot-record-array', ['exports'], function (exports) { exports.default = SnapshotRecordArray; /** @module ember-data */ @@ -7798,19 +7928,20 @@ return model.getRecord(); }); return (0, _emberDataPrivateSystemPromiseProxies.promiseObject)(toReturn, label); } - var get = _ember.default.get; - var set = _ember.default.set; var once = _ember.default.run.once; - var isNone = _ember.default.isNone; - var isPresent = _ember.default.isPresent; var Promise = _ember.default.RSVP.Promise; - var copy = _ember.default.copy; var Store; + var copy = _ember.default.copy; + var get = _ember.default.get; + var GUID_KEY = _ember.default.GUID_KEY; + var isNone = _ember.default.isNone; + var isPresent = _ember.default.isPresent; + var set = _ember.default.set; var Service = _ember.default.Service; // Implementors Note: // // The variables in this file are consistently named according to the following @@ -8679,11 +8810,13 @@ var typeClass = this.modelFor(modelName); array = array || this.recordArrayManager.createAdapterPopulatedRecordArray(typeClass, query); var adapter = this.adapterFor(modelName); - return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._query)(adapter, this, typeClass, query, array)); + var pA = (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._query)(adapter, this, typeClass, query, array)); + + return pA; }, /** This method makes a request for one record, where the `id` is not known beforehand (if the `id` is known, use `findRecord` instead). @@ -8887,13 +9020,16 @@ @param {String} modelName @param {Object} options @return {Promise} promise */ findAll: function (modelName, options) { + var typeClass = this.modelFor(modelName); - return this._fetchAll(typeClass, this.peekAll(modelName), options); + var fetch = this._fetchAll(typeClass, this.peekAll(modelName), options); + + return fetch; }, /** @method _fetchAll @private @@ -9194,11 +9330,11 @@ } if (data) { // normalize relationship IDs into records this._backburner.schedule('normalizeRelationships', this, '_setupRelationships', internalModel, data); this.updateId(internalModel, data); - } + } else {} //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); }, @@ -9240,10 +9376,20 @@ */ updateId: function (internalModel, data) { var oldId = internalModel.id; var id = (0, _emberDataPrivateSystemCoerceId.default)(data.id); + // ID absolutely can't be missing if the oldID is empty (missing Id in response for a new record) + + // ID absolutely can't be different than oldID if oldID is not null + + // 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) { + return; + } + this.typeMapFor(internalModel.type).idToRecord[id] = internalModel; internalModel.setId(id); }, @@ -9508,20 +9654,23 @@ length = data.data.length; var internalModels = new Array(length); for (i = 0; i < length; i++) { internalModels[i] = this._pushInternalModel(data.data[i]).getRecord(); } + return internalModels; } if (data.data === null) { return null; } var internalModel = this._pushInternalModel(data.data); - return internalModel.getRecord(); + var record = internalModel.getRecord(); + + return record; }, _hasModelFor: function (type) { return !!(0, _emberDataPrivateUtils.getOwner)(this)._lookupFactory('model:' + type); }, @@ -10049,10 +10198,11 @@ toString: function () { return 'ContainerInstanceCache'; } }); }); +/* global heimdall */ define("ember-data/-private/system/store/finders", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/store/common", "ember-data/-private/system/store/serializer-response", "ember-data/-private/system/store/serializers"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemStoreCommon, _emberDataPrivateSystemStoreSerializerResponse, _emberDataPrivateSystemStoreSerializers) { exports._find = _find; exports._findMany = _findMany; exports._findHasMany = _findHasMany; exports._findBelongsTo = _findBelongsTo; @@ -10217,10 +10367,11 @@ //TODO Optimize records = store.push(payload); }); recordArray.loadRecords(records, payload); + return recordArray; }, null, "DS: Extract payload of query " + typeClass); } function _queryRecord(adapter, store, typeClass, query) { @@ -11651,10 +11802,11 @@ }); } exports.default = JSONAPIAdapter; }); +/* global heimdall */ /** @module ember-data */ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'ember-data/adapters/errors', 'ember-data/-private/adapters/build-url-mixin', 'ember-data/-private/features', 'ember-data/-private/debug', 'ember-data/-private/utils/parse-response-headers'], function (exports, _ember, _emberDataAdapter, _emberDataAdaptersErrors, _emberDataPrivateAdaptersBuildUrlMixin, _emberDataPrivateFeatures, _emberDataPrivateDebug, _emberDataPrivateUtilsParseResponseHeaders) { var MapWithDefault = _ember.default.MapWithDefault; @@ -12993,10 +13145,11 @@ } } exports.default = RESTAdapter; }); +/* global heimdall */ /** @module ember-data */ define('ember-data/attr', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) { exports.default = attr; @@ -17101,10 +17254,10 @@ */ deserialize: null }); }); define("ember-data/version", ["exports"], function (exports) { - exports.default = "2.9.0"; + exports.default = "2.10.0-beta.1"; }); define("ember-inflector", ["exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (exports, _ember, _emberInflectorLibSystem, _emberInflectorLibExtString) { _emberInflectorLibSystem.Inflector.defaultRules = _emberInflectorLibSystem.defaultRules; _ember.default.Inflector = _emberInflectorLibSystem.Inflector;