dist/globals/ember-data.prod.js in ember-data-source-2.7.0.beta.1 vs dist/globals/ember-data.prod.js in ember-data-source-2.7.0.beta.2

- 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.7.0-beta.1 + * @version 2.7.0-beta.2 */ var loader, define, requireModule, require, requirejs; (function(global) { @@ -23,22 +23,28 @@ requirejs: requirejs }; requirejs = require = requireModule = function(name) { stats.require++; - return findModule(name, '(require)').module.exports; + var pending = []; + var mod = findModule(name, '(require)', pending); + + for (var i = pending.length - 1; i >= 0; i--) { + pending[i].exports(); + } + + return mod.module.exports; }; function resetStats() { stats = { define: 0, require: 0, reify: 0, - build: 0, + findDeps: 0, modules: 0, exports: 0, - ensureBuild: 0, resolve: 0, resolveRelative: 0, findModule: 0, }; requirejs._stats = stats; @@ -73,12 +79,10 @@ _isArray = Array.isArray; } var registry = {}; var seen = {}; - var FAILED = false; - var LOADED = true; var uuid = 0; function unsupportedModule(length) { throw new Error('an unsupported module was defined, expected `define(name, deps, module)` instead got: `' + @@ -92,15 +96,15 @@ this.id = uuid++; this.name = name; this.deps = !deps.length && callback.length ? defaultDeps : deps; this.module = { exports: {} }; this.callback = callback; - this.state = undefined; this.finalized = false; this.hasExportsAsDep = false; this.isAlias = alias; this.reified = new Array(deps.length); + this._foundDeps = false; } Module.prototype.makeDefaultExport = function() { var exports = this.module.exports; if (exports !== null && @@ -109,50 +113,67 @@ exports['default'] = exports; } }; Module.prototype.exports = function() { - stats.exports ++; - if (this.finalized) { - return this.module.exports; - } else { - if (loader.wrapModules) { - this.callback = loader.wrapModules(this.name, this.callback); - } - var result = this.callback.apply(this, this.reified); - if (!(this.hasExportsAsDep && result === undefined)) { - this.module.exports = result; - } - this.makeDefaultExport(); - this.finalized = true; - return this.module.exports; + if (this.finalized) { return this.module.exports; } + stats.exports++; + + this.finalized = true; + + if (loader.wrapModules) { + this.callback = loader.wrapModules(this.name, this.callback); } + + this.reify(); + + var result = this.callback.apply(this, this.reified); + + if (!(this.hasExportsAsDep && result === undefined)) { + this.module.exports = result; + } + this.makeDefaultExport(); + return this.module.exports; }; Module.prototype.unsee = function() { this.finalized = false; - this.state = undefined; + this._foundDeps = false; this.module = { exports: {}}; }; Module.prototype.reify = function() { stats.reify++; - var deps = this.deps; - var dep; var reified = this.reified; + for (var i = 0; i < reified.length; i++) { + var mod = reified[i]; + reified[i] = mod.exports ? mod.exports : mod.module.exports(); + } + }; + Module.prototype.findDeps = function(pending) { + if (this._foundDeps) { + return; + } + + stats.findDeps++; + this._foundDeps = true; + + var deps = this.deps; + for (var i = 0; i < deps.length; i++) { - dep = deps[i]; + var dep = deps[i]; + var entry = this.reified[i] = { exports: undefined, module: undefined }; if (dep === 'exports') { this.hasExportsAsDep = true; - reified[i] = this.module.exports; + entry.exports = this.module.exports; } else if (dep === 'require') { - reified[i] = this.makeRequire(); + entry.exports = this.makeRequire(); } else if (dep === 'module') { - reified[i] = this.module; + entry.exports = this.module; } else { - reified[i] = findModule(resolve(dep, this.name), this.name).module.exports; + entry.module = findModule(resolve(dep, this.name), this.name, pending); } } }; Module.prototype.makeRequire = function() { @@ -165,20 +186,10 @@ return has(resolve(dep, name)); } return r; }; - Module.prototype.build = function() { - stats.ensureBuild++; - if (this.state === FAILED || this.state === LOADED) { return; } - stats.build++; - this.state = FAILED; - this.reify() - this.exports(); - this.state = LOADED; - }; - define = function(name, deps, callback) { stats.define++; if (arguments.length < 2) { unsupportedModule(arguments.length); } @@ -210,21 +221,24 @@ function missingModule(name, referrer) { throw new Error('Could not find module `' + name + '` imported from `' + referrer + '`'); } - function findModule(name, referrer) { + function findModule(name, referrer, pending) { stats.findModule++; var mod = registry[name] || registry[name + '/index']; while (mod && mod.isAlias) { mod = registry[mod.name]; } if (!mod) { missingModule(name, referrer); } - mod.build(); + if (pending) { + mod.findDeps(pending); + pending.push(mod); + } return mod; } function resolve(child, name) { stats.resolve++; @@ -256,11 +270,11 @@ } requirejs.entries = requirejs._eak_seen = registry; requirejs.has = has; requirejs.unsee = function(moduleName) { - findModule(moduleName, '(unsee)').unsee(); + findModule(moduleName, '(unsee)', false).unsee(); }; requirejs.clear = function() { resetStats(); requirejs.entries = requirejs._eak_seen = registry = {}; @@ -5191,11 +5205,13 @@ isLoaded: true, isUpdating: false, meta: (0, _emberDataPrivateSystemCloneNull.default)(payload.meta) }); - this.set('links', (0, _emberDataPrivateSystemCloneNull.default)(payload.links)); + if (true) { + this.set('links', (0, _emberDataPrivateSystemCloneNull.default)(payload.links)); + } internalModels.forEach(function (record) { _this.manager.recordArraysForRecord(record).add(_this); }); @@ -5515,10 +5531,11 @@ return _ember.default.RSVP.resolve(objectOrPromise).then(function (data) { var record; if (data instanceof _emberDataModel.default) { + if (false) {} record = data; } else { record = _this.store.push(data); } @@ -5608,17 +5625,23 @@ var _this = this; return _ember.default.RSVP.resolve(objectOrPromise).then(function (payload) { var array = payload; + if (false) {} + var useLegacyArrayPush = true; if (typeof payload === "object" && payload.data) { array = payload.data; useLegacyArrayPush = array.length && array[0].data; + + if (false) {} } - useLegacyArrayPush = true; + if (!false) { + useLegacyArrayPush = true; + } var internalModels = undefined; if (useLegacyArrayPush) { internalModels = array.map(function (obj) { var record = _this.store.push(obj); @@ -8674,11 +8697,11 @@ return Ember.$.getJSON("/api/current_user"); } }); ``` Note: the primary use case for `store.queryRecord` is when a single record - is queried and the `id` is not kown beforehand. In all other cases + is queried and the `id` is not known beforehand. In all other cases `store.query` and using the first item of the array is likely the preferred way: ``` // GET /users?username=unique { @@ -9552,14 +9575,19 @@ } else { payload = inputPayload; serializer = this.serializerFor(modelName); } - - this._adapterRun(function () { - return serializer.pushPayload(_this3, payload); - }); + if (false) { + return this._adapterRun(function () { + return serializer.pushPayload(_this3, payload); + }); + } else { + this._adapterRun(function () { + return serializer.pushPayload(_this3, payload); + }); + } }, /** `normalize` converts a json payload into the normalized form that [push](#method_push) expects. @@ -10328,12 +10356,14 @@ */ exports.default = _emberDataTransform.default.extend({ deserialize: function (serialized, options) { var type = typeof serialized; - if (isNone(serialized) && options.allowNull === true) { - return null; + if (true) { + if (isNone(serialized) && options.allowNull === true) { + return null; + } } if (type === "boolean") { return serialized; } else if (type === "string") { @@ -10344,12 +10374,14 @@ return false; } }, serialize: function (deserialized, options) { - if (isNone(deserialized) && options.allowNull === true) { - return null; + if (true) { + if (isNone(deserialized) && options.allowNull === true) { + return null; + } } return Boolean(deserialized); } }); @@ -11146,10 +11178,13 @@ detail: message }]; } var extendedErrorsEnabled = false; + if (false) { + extendedErrorsEnabled = true; + } function extendFn(ErrorClass) { return function () { var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; @@ -11348,11 +11383,11 @@ } return out; } }); -define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters/rest', 'ember-data/-private/features'], function (exports, _ember, _emberDataAdaptersRest, _emberDataPrivateFeatures) { +define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters/rest', 'ember-data/-private/features', 'ember-data/-private/debug'], function (exports, _ember, _emberDataAdaptersRest, _emberDataPrivateFeatures, _emberDataPrivateDebug) { /** @class JSONAPIAdapter @constructor @namespace DS @@ -11432,11 +11467,16 @@ @param {Array} ids @param {Array} snapshots @return {Promise} promise */ findMany: function (store, type, ids, snapshots) { - return this._super.apply(this, arguments); + if (true && !this._hasCustomizedAjax()) { + return this._super.apply(this, arguments); + } else { + var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); + return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } }); + } }, /** @method pathForType @param {String} modelName @@ -11454,70 +11494,97 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ updateRecord: function (store, type, snapshot) { - return this._super.apply(this, arguments); - } - }); + if (true && !this._hasCustomizedAjax()) { + return this._super.apply(this, arguments); + } else { + var data = {}; + var serializer = store.serializerFor(type.modelName); - JSONAPIAdapter.reopen({ + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); - methodForRequest: function (params) { - if (params.requestType === 'updateRecord') { - return 'PATCH'; - } + var id = snapshot.id; + var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); - return this._super.apply(this, arguments); + return this.ajax(url, 'PATCH', { data: data }); + } }, - dataForRequest: function (params) { - var requestType = params.requestType; - var ids = params.ids; + _hasCustomizedAjax: function () { + if (this.ajax !== JSONAPIAdapter.prototype.ajax) { + return true; + } - if (requestType === 'findMany') { - return { - filter: { id: ids.join(',') } - }; + if (this.ajaxOptions !== JSONAPIAdapter.prototype.ajaxOptions) { + return true; } - if (requestType === 'updateRecord') { - var store = params.store; - var type = params.type; - var snapshot = params.snapshot; + return false; + } + }); - var data = {}; - var serializer = store.serializerFor(type.modelName); + if (true) { - serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + JSONAPIAdapter.reopen({ - return data; - } + methodForRequest: function (params) { + if (params.requestType === 'updateRecord') { + return 'PATCH'; + } - return this._super.apply(this, arguments); - }, + return this._super.apply(this, arguments); + }, - headersForRequest: function () { - var headers = this._super.apply(this, arguments) || {}; + dataForRequest: function (params) { + var requestType = params.requestType; + var ids = params.ids; - headers['Accept'] = 'application/vnd.api+json'; + if (requestType === 'findMany') { + return { + filter: { id: ids.join(',') } + }; + } - return headers; - }, + if (requestType === 'updateRecord') { + var store = params.store; + var type = params.type; + var snapshot = params.snapshot; - _requestToJQueryAjaxHash: function () { - var hash = this._super.apply(this, arguments); + var data = {}; + var serializer = store.serializerFor(type.modelName); - if (hash.contentType) { - hash.contentType = 'application/vnd.api+json'; - } + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); - return hash; - } + return data; + } - }); + return this._super.apply(this, arguments); + }, + headersForRequest: function () { + var headers = this._super.apply(this, arguments) || {}; + + headers['Accept'] = 'application/vnd.api+json'; + + return headers; + }, + + _requestToJQueryAjaxHash: function () { + var hash = this._super.apply(this, arguments); + + if (hash.contentType) { + hash.contentType = 'application/vnd.api+json'; + } + + return hash; + } + + }); + } + exports.default = JSONAPIAdapter; }); /** @module ember-data */ @@ -11880,16 +11947,23 @@ @param {String} id @param {DS.Snapshot} snapshot @return {Promise} promise */ findRecord: function (store, type, id, snapshot) { - var request = this._requestFor({ - store: store, type: type, id: id, snapshot: snapshot, - requestType: 'findRecord' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, id: id, snapshot: snapshot, + requestType: 'findRecord' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, id, snapshot, 'findRecord'); + var query = this.buildQuery(snapshot); + + return this.ajax(url, 'GET', { data: query }); + } }, /** Called by the store in order to fetch a JSON array for all of the records for a given type. @@ -11903,17 +11977,27 @@ @return {Promise} promise */ findAll: function (store, type, sinceToken, snapshotRecordArray) { var query = this.buildQuery(snapshotRecordArray); - var request = this._requestFor({ - store: store, type: type, sinceToken: sinceToken, query: query, - snapshots: snapshotRecordArray, - requestType: 'findAll' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, sinceToken: sinceToken, query: query, + snapshots: snapshotRecordArray, + requestType: 'findAll' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll'); + + if (sinceToken) { + query.since = sinceToken; + } + + return this.ajax(url, 'GET', { data: query }); + } }, /** Called by the store in order to fetch a JSON array for the records that match a particular query. @@ -11927,16 +12011,26 @@ @param {DS.Model} type @param {Object} query @return {Promise} promise */ query: function (store, type, query) { - var request = this._requestFor({ - store: store, type: type, query: query, - requestType: 'query' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, query: query, + requestType: 'query' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, null, null, 'query', query); + + if (this.sortQueryParams) { + query = this.sortQueryParams(query); + } + + return this.ajax(url, 'GET', { data: query }); + } }, /** Called by the store in order to fetch a JSON object for the record that matches a particular query. @@ -11950,16 +12044,26 @@ @param {DS.Model} type @param {Object} query @return {Promise} promise */ queryRecord: function (store, type, query) { - var request = this._requestFor({ - store: store, type: type, query: query, - requestType: 'queryRecord' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, query: query, + requestType: 'queryRecord' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, null, null, 'queryRecord', query); + + if (this.sortQueryParams) { + query = this.sortQueryParams(query); + } + + return this.ajax(url, 'GET', { data: query }); + } }, /** Called by the store in order to fetch several records together if `coalesceFindRequests` is true For example, if the original payload looks like: @@ -11985,16 +12089,21 @@ @param {Array} ids @param {Array} snapshots @return {Promise} promise */ findMany: function (store, type, ids, snapshots) { - var request = this._requestFor({ - store: store, type: type, ids: ids, snapshots: snapshots, - requestType: 'findMany' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, ids: ids, snapshots: snapshots, + requestType: 'findMany' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); + return this.ajax(url, 'GET', { data: { ids: ids } }); + } }, /** Called by the store in order to fetch a JSON array for the unloaded records in a has-many relationship that were originally @@ -12020,16 +12129,25 @@ @param {DS.Snapshot} snapshot @param {String} url @return {Promise} promise */ findHasMany: function (store, snapshot, url, relationship) { - var request = this._requestFor({ - store: store, snapshot: snapshot, url: url, relationship: relationship, - requestType: 'findHasMany' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, snapshot: snapshot, url: url, relationship: relationship, + requestType: 'findHasMany' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var id = snapshot.id; + var type = snapshot.modelName; + + url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findHasMany')); + + return this.ajax(url, 'GET'); + } }, /** Called by the store in order to fetch the JSON for the unloaded record in a belongs-to relationship that was originally specified as a URL (inside of @@ -12055,16 +12173,24 @@ @param {DS.Snapshot} snapshot @param {String} url @return {Promise} promise */ findBelongsTo: function (store, snapshot, url, relationship) { - var request = this._requestFor({ - store: store, snapshot: snapshot, url: url, relationship: relationship, - requestType: 'findBelongsTo' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, snapshot: snapshot, url: url, relationship: relationship, + requestType: 'findBelongsTo' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var id = snapshot.id; + var type = snapshot.modelName; + + url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findBelongsTo')); + return this.ajax(url, 'GET'); + } }, /** Called by the store when a newly created record is saved via the `save` method on a model record instance. @@ -12077,16 +12203,26 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ createRecord: function (store, type, snapshot) { - var request = this._requestFor({ - store: store, type: type, snapshot: snapshot, - requestType: 'createRecord' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, snapshot: snapshot, + requestType: 'createRecord' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var data = {}; + var serializer = store.serializerFor(type.modelName); + var url = this.buildURL(type.modelName, null, snapshot, 'createRecord'); + + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + + return this.ajax(url, "POST", { data: data }); + } }, /** Called by the store when an existing record is saved via the `save` method on a model record instance. @@ -12099,16 +12235,28 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ updateRecord: function (store, type, snapshot) { - var request = this._requestFor({ - store: store, type: type, snapshot: snapshot, - requestType: 'updateRecord' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, snapshot: snapshot, + requestType: 'updateRecord' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var data = {}; + var serializer = store.serializerFor(type.modelName); + + serializer.serializeIntoHash(data, type, snapshot); + + var id = snapshot.id; + var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); + + return this.ajax(url, "PUT", { data: data }); + } }, /** Called by the store when a record is deleted. The `deleteRecord` method makes an Ajax (HTTP DELETE) request to a URL computed by `buildURL`. @@ -12117,16 +12265,22 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ deleteRecord: function (store, type, snapshot) { - var request = this._requestFor({ - store: store, type: type, snapshot: snapshot, - requestType: 'deleteRecord' - }); + if (true && !this._hasCustomizedAjax()) { + var request = this._requestFor({ + store: store, type: type, snapshot: snapshot, + requestType: 'deleteRecord' + }); - return this._makeRequest(request); + return this._makeRequest(request); + } else { + var id = snapshot.id; + + return this.ajax(this.buildURL(type.modelName, id, snapshot, 'deleteRecord'), "DELETE"); + } }, _stripIDFromURL: function (store, snapshot) { var url = this.buildURL(snapshot.modelName, snapshot.id, snapshot); @@ -12246,10 +12400,27 @@ } var errors = this.normalizeErrorResponse(status, headers, payload); var detailedMessage = this.generatedDetailedMessage(status, headers, payload, requestData); + if (false) { + switch (status) { + case 401: + return new _emberDataAdaptersErrors.UnauthorizedError(errors, detailedMessage); + case 403: + return new _emberDataAdaptersErrors.ForbiddenError(errors, detailedMessage); + case 404: + return new _emberDataAdaptersErrors.NotFoundError(errors, detailedMessage); + case 409: + return new _emberDataAdaptersErrors.ConflictError(errors, detailedMessage); + default: + if (status >= 500) { + return new _emberDataAdaptersErrors.ServerError(errors, detailedMessage); + } + } + } + return new _emberDataAdaptersErrors.AdapterError(errors, detailedMessage); }, /** Default `handleResponse` implementation uses this hook to decide if the @@ -12456,264 +12627,279 @@ query.include = include; } } return query; + }, + + _hasCustomizedAjax: function () { + if (this.ajax !== RESTAdapter.prototype.ajax) { + return true; + } + + if (this.ajaxOptions !== RESTAdapter.prototype.ajaxOptions) { + return true; + } + + return false; } }); - RESTAdapter.reopen({ + if (true) { - /** - * Get the data (body or query params) for a request. - * - * @public - * @method dataForRequest - * @param {Object} params - * @return {Object} data - */ - dataForRequest: function (params) { - var store = params.store; - var type = params.type; - var snapshot = params.snapshot; - var requestType = params.requestType; - var query = params.query; + RESTAdapter.reopen({ - // type is not passed to findBelongsTo and findHasMany - type = type || snapshot && snapshot.type; + /** + * Get the data (body or query params) for a request. + * + * @public + * @method dataForRequest + * @param {Object} params + * @return {Object} data + */ + dataForRequest: function (params) { + var store = params.store; + var type = params.type; + var snapshot = params.snapshot; + var requestType = params.requestType; + var query = params.query; - var serializer = store.serializerFor(type.modelName); - var data = {}; + // type is not passed to findBelongsTo and findHasMany + type = type || snapshot && snapshot.type; - switch (requestType) { - case 'createRecord': - serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); - break; + var serializer = store.serializerFor(type.modelName); + var data = {}; - case 'updateRecord': - serializer.serializeIntoHash(data, type, snapshot); - break; + switch (requestType) { + case 'createRecord': + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + break; - case 'findRecord': - data = this.buildQuery(snapshot); - break; + case 'updateRecord': + serializer.serializeIntoHash(data, type, snapshot); + break; - case 'findAll': - if (params.sinceToken) { - query = query || {}; - query.since = params.sinceToken; - } - data = query; - break; + case 'findRecord': + data = this.buildQuery(snapshot); + break; - case 'query': - case 'queryRecord': - if (this.sortQueryParams) { - query = this.sortQueryParams(query); - } - data = query; - break; + case 'findAll': + if (params.sinceToken) { + query = query || {}; + query.since = params.sinceToken; + } + data = query; + break; - case 'findMany': - data = { ids: params.ids }; - break; + case 'query': + case 'queryRecord': + if (this.sortQueryParams) { + query = this.sortQueryParams(query); + } + data = query; + break; - default: - data = undefined; - break; - } + case 'findMany': + data = { ids: params.ids }; + break; - return data; - }, + default: + data = undefined; + break; + } - /** - * Get the HTTP method for a request. - * - * @public - * @method methodForRequest - * @param {Object} params - * @return {String} HTTP method - */ - methodForRequest: function (params) { - var requestType = params.requestType; + return data; + }, - switch (requestType) { - case 'createRecord': - return 'POST'; - case 'updateRecord': - return 'PUT'; - case 'deleteRecord': - return 'DELETE'; - } + /** + * Get the HTTP method for a request. + * + * @public + * @method methodForRequest + * @param {Object} params + * @return {String} HTTP method + */ + methodForRequest: function (params) { + var requestType = params.requestType; - return 'GET'; - }, + switch (requestType) { + case 'createRecord': + return 'POST'; + case 'updateRecord': + return 'PUT'; + case 'deleteRecord': + return 'DELETE'; + } - /** - * Get the URL for a request. - * - * @public - * @method urlForRequest - * @param {Object} params - * @return {String} URL - */ - urlForRequest: function (params) { - var type = params.type; - var id = params.id; - var ids = params.ids; - var snapshot = params.snapshot; - var snapshots = params.snapshots; - var requestType = params.requestType; - var query = params.query; + return 'GET'; + }, - // type and id are not passed from updateRecord and deleteRecord, hence they - // are defined if not set - type = type || snapshot && snapshot.type; - id = id || snapshot && snapshot.id; + /** + * Get the URL for a request. + * + * @public + * @method urlForRequest + * @param {Object} params + * @return {String} URL + */ + urlForRequest: function (params) { + var type = params.type; + var id = params.id; + var ids = params.ids; + var snapshot = params.snapshot; + var snapshots = params.snapshots; + var requestType = params.requestType; + var query = params.query; - switch (requestType) { - case 'findAll': - return this.buildURL(type.modelName, null, snapshots, requestType); + // type and id are not passed from updateRecord and deleteRecord, hence they + // are defined if not set + type = type || snapshot && snapshot.type; + id = id || snapshot && snapshot.id; - case 'query': - case 'queryRecord': - return this.buildURL(type.modelName, null, null, requestType, query); + switch (requestType) { + case 'findAll': + return this.buildURL(type.modelName, null, snapshots, requestType); - case 'findMany': - return this.buildURL(type.modelName, ids, snapshots, requestType); + case 'query': + case 'queryRecord': + return this.buildURL(type.modelName, null, null, requestType, query); - case 'findHasMany': - case 'findBelongsTo': - { - var url = this.buildURL(type.modelName, id, snapshot, requestType); - return this.urlPrefix(params.url, url); - } - } + case 'findMany': + return this.buildURL(type.modelName, ids, snapshots, requestType); - return this.buildURL(type.modelName, id, snapshot, requestType, query); - }, + case 'findHasMany': + case 'findBelongsTo': + { + var url = this.buildURL(type.modelName, id, snapshot, requestType); + return this.urlPrefix(params.url, url); + } + } - /** - * Get the headers for a request. - * - * By default the value of the `headers` property of the adapter is - * returned. - * - * @public - * @method headersForRequest - * @param {Object} params - * @return {Object} headers - */ - headersForRequest: function (params) { - return this.get('headers'); - }, + return this.buildURL(type.modelName, id, snapshot, requestType, query); + }, - /** - * Get an object which contains all properties for a request which should - * be made. - * - * @private - * @method _requestFor - * @param {Object} params - * @return {Object} request object - */ - _requestFor: function (params) { - var method = this.methodForRequest(params); - var url = this.urlForRequest(params); - var headers = this.headersForRequest(params); - var data = this.dataForRequest(params); + /** + * Get the headers for a request. + * + * By default the value of the `headers` property of the adapter is + * returned. + * + * @public + * @method headersForRequest + * @param {Object} params + * @return {Object} headers + */ + headersForRequest: function (params) { + return this.get('headers'); + }, - return { method: method, url: url, headers: headers, data: data }; - }, + /** + * Get an object which contains all properties for a request which should + * be made. + * + * @private + * @method _requestFor + * @param {Object} params + * @return {Object} request object + */ + _requestFor: function (params) { + var method = this.methodForRequest(params); + var url = this.urlForRequest(params); + var headers = this.headersForRequest(params); + var data = this.dataForRequest(params); - /** - * Convert a request object into a hash which can be passed to `jQuery.ajax`. - * - * @private - * @method _requestToJQueryAjaxHash - * @param {Object} request - * @return {Object} jQuery ajax hash - */ - _requestToJQueryAjaxHash: function (request) { - var hash = {}; + return { method: method, url: url, headers: headers, data: data }; + }, - hash.type = request.method; - hash.url = request.url; - hash.dataType = 'json'; - hash.context = this; + /** + * Convert a request object into a hash which can be passed to `jQuery.ajax`. + * + * @private + * @method _requestToJQueryAjaxHash + * @param {Object} request + * @return {Object} jQuery ajax hash + */ + _requestToJQueryAjaxHash: function (request) { + var hash = {}; - if (request.data) { - if (request.type !== 'GET') { - hash.contentType = 'application/json; charset=utf-8'; - hash.data = JSON.stringify(request.data); - } else { - hash.data = request.data; + hash.type = request.method; + hash.url = request.url; + hash.dataType = 'json'; + hash.context = this; + + if (request.data) { + if (request.type !== 'GET') { + hash.contentType = 'application/json; charset=utf-8'; + hash.data = JSON.stringify(request.data); + } else { + hash.data = request.data; + } } - } - var headers = request.headers; - if (headers !== undefined) { - hash.beforeSend = function (xhr) { - Object.keys(headers).forEach(function (key) { - return xhr.setRequestHeader(key, headers[key]); - }); - }; - } + var headers = request.headers; + if (headers !== undefined) { + hash.beforeSend = function (xhr) { + Object.keys(headers).forEach(function (key) { + return xhr.setRequestHeader(key, headers[key]); + }); + }; + } - return hash; - }, + return hash; + }, - /** - * Make a request using `jQuery.ajax`. - * - * @private - * @method _makeRequest - * @param {Object} request - * @return {Promise} promise - */ - _makeRequest: function (request) { - var adapter = this; - var hash = this._requestToJQueryAjaxHash(request); + /** + * Make a request using `jQuery.ajax`. + * + * @private + * @method _makeRequest + * @param {Object} request + * @return {Promise} promise + */ + _makeRequest: function (request) { + var adapter = this; + var hash = this._requestToJQueryAjaxHash(request); - var method = request.method; - var url = request.url; + var method = request.method; + var url = request.url; - var requestData = { method: method, url: url }; + var requestData = { method: method, url: url }; - return new _ember.default.RSVP.Promise(function (resolve, reject) { + return new _ember.default.RSVP.Promise(function (resolve, reject) { - hash.success = function (payload, textStatus, jqXHR) { - var response = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), payload, requestData); + hash.success = function (payload, textStatus, jqXHR) { + var response = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), payload, requestData); - if (response instanceof _emberDataAdaptersErrors.AdapterError) { - _ember.default.run.join(null, reject, response); - } else { - _ember.default.run.join(null, resolve, response); - } - }; + if (response instanceof _emberDataAdaptersErrors.AdapterError) { + _ember.default.run.join(null, reject, response); + } else { + _ember.default.run.join(null, resolve, response); + } + }; - hash.error = function (jqXHR, textStatus, errorThrown) { + hash.error = function (jqXHR, textStatus, errorThrown) { - var error = undefined; + var error = undefined; - if (errorThrown instanceof Error) { - error = errorThrown; - } else if (textStatus === 'timeout') { - error = new _emberDataAdaptersErrors.TimeoutError(); - } else if (textStatus === 'abort') { - error = new _emberDataAdaptersErrors.AbortError(); - } else { - error = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), adapter.parseErrorResponse(jqXHR.responseText) || errorThrown, requestData); - } + if (errorThrown instanceof Error) { + error = errorThrown; + } else if (textStatus === 'timeout') { + error = new _emberDataAdaptersErrors.TimeoutError(); + } else if (textStatus === 'abort') { + error = new _emberDataAdaptersErrors.AbortError(); + } else { + error = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), adapter.parseErrorResponse(jqXHR.responseText) || errorThrown, requestData); + } - _ember.default.run.join(null, reject, error); - }; + _ember.default.run.join(null, reject, error); + }; - adapter._ajaxRequest(hash); - }, 'DS: RESTAdapter#makeRequest: ' + method + ' ' + url); - } - }); + adapter._ajaxRequest(hash); + }, 'DS: RESTAdapter#makeRequest: ' + method + ' ' + url); + } + }); + } //From http://stackoverflow.com/questions/280634/endswith-in-javascript function endsWith(string, suffix) { if (typeof String.prototype.endsWith !== 'function') { return string.indexOf(suffix, string.length - suffix.length) !== -1; @@ -12920,10 +13106,18 @@ _emberDataPrivateCore.default.AdapterError = _emberDataAdaptersErrors.AdapterError; _emberDataPrivateCore.default.InvalidError = _emberDataAdaptersErrors.InvalidError; _emberDataPrivateCore.default.TimeoutError = _emberDataAdaptersErrors.TimeoutError; _emberDataPrivateCore.default.AbortError = _emberDataAdaptersErrors.AbortError; + if (false) { + _emberDataPrivateCore.default.UnauthorizedError = _emberDataAdaptersErrors.UnauthorizedError; + _emberDataPrivateCore.default.ForbiddenError = _emberDataAdaptersErrors.ForbiddenError; + _emberDataPrivateCore.default.NotFoundError = _emberDataAdaptersErrors.NotFoundError; + _emberDataPrivateCore.default.ConflictError = _emberDataAdaptersErrors.ConflictError; + _emberDataPrivateCore.default.ServerError = _emberDataAdaptersErrors.ServerError; + } + _emberDataPrivateCore.default.errorsHashToArray = _emberDataAdaptersErrors.errorsHashToArray; _emberDataPrivateCore.default.errorsArrayToHash = _emberDataAdaptersErrors.errorsArrayToHash; _emberDataPrivateCore.default.Serializer = _emberDataSerializer.default; @@ -13416,12 +13610,14 @@ var serializedKey = this.keyForRelationship(attr, relationship.kind, 'serialize'); json[serializedKey] = snapshot.hasMany(attr, { ids: true }); } else if (this.hasSerializeRecordsOption(attr)) { this._serializeEmbeddedHasMany(snapshot, json, relationship); } else { - if (this.hasSerializeIdsAndTypesOption(attr)) { - this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship); + if (true) { + if (this.hasSerializeIdsAndTypesOption(attr)) { + this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship); + } } } }, /** @@ -13779,13 +13975,25 @@ @param {Object} relationshipDataHash @return {Object} @private */ _normalizeRelationshipDataHelper: function (relationshipDataHash) { - var type = this.modelNameFromPayloadKey(relationshipDataHash.type); - relationshipDataHash.type = type; + if (false) { + var modelName = this.modelNameFromPayloadType(relationshipDataHash.type); + var deprecatedModelNameLookup = this.modelNameFromPayloadKey(relationshipDataHash.type); + if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + + modelName = deprecatedModelNameLookup; + } + + relationshipDataHash.type = modelName; + } else { + var type = this.modelNameFromPayloadKey(relationshipDataHash.type); + relationshipDataHash.type = type; + } + return relationshipDataHash; }, /** @method _normalizeResourceHelper @@ -13796,13 +14004,26 @@ _normalizeResourceHelper: function (resourceHash) { var modelName = undefined, usedLookup = undefined; - modelName = this.modelNameFromPayloadKey(resourceHash.type); - usedLookup = 'modelNameFromPayloadKey'; + if (false) { + modelName = this.modelNameFromPayloadType(resourceHash.type); + var deprecatedModelNameLookup = this.modelNameFromPayloadKey(resourceHash.type); + usedLookup = 'modelNameFromPayloadType'; + + if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + + modelName = deprecatedModelNameLookup; + usedLookup = 'modelNameFromPayloadKey'; + } + } else { + modelName = this.modelNameFromPayloadKey(resourceHash.type); + usedLookup = 'modelNameFromPayloadKey'; + } + if (!this.store._hasModelFor(modelName)) { return null; } var modelClass = this.store.modelFor(modelName); @@ -13820,12 +14041,15 @@ @param {DS.Store} store @param {Object} payload */ pushPayload: function (store, payload) { var normalizedPayload = this._normalizeDocumentHelper(payload); - - store.push(normalizedPayload); + if (false) { + return store.push(normalizedPayload); + } else { + store.push(normalizedPayload); + } }, /** @method _normalizeResponse @param {DS.Store} store @@ -13927,11 +14151,23 @@ @param {Object} resourceHash @return {String} @private */ _extractType: function (modelClass, resourceHash) { - return this.modelNameFromPayloadKey(resourceHash.type); + if (false) { + var modelName = this.modelNameFromPayloadType(resourceHash.type); + var deprecatedModelNameLookup = this.modelNameFromPayloadKey(resourceHash.type); + + if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + + modelName = deprecatedModelNameLookup; + } + + return modelName; + } else { + return this.modelNameFromPayloadKey(resourceHash.type); + } }, /** @method modelNameFromPayloadKey @param {String} key @@ -14038,13 +14274,22 @@ */ serialize: function (snapshot, options) { var data = this._super.apply(this, arguments); var payloadType = undefined; + if (false) { + payloadType = this.payloadTypeFromModelName(snapshot.modelName); + var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(snapshot.modelName); - payloadType = this.payloadKeyFromModelName(snapshot.modelName); + if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) { + payloadType = deprecatedPayloadTypeLookup; + } + } else { + payloadType = this.payloadKeyFromModelName(snapshot.modelName); + } + data.type = payloadType; return { data: data }; }, /** @@ -14061,11 +14306,11 @@ json.attributes = json.attributes || {}; var value = snapshot.attr(key); if (type) { var transform = this.transformFor(type); - value = transform.serialize(value); + value = transform.serialize(value, attribute.options); } var payloadKey = this._getMappedKey(key, snapshot.type); if (payloadKey === key) { @@ -14098,12 +14343,22 @@ var data = null; if (belongsTo) { var payloadType = undefined; - payloadType = this.payloadKeyFromModelName(belongsTo.modelName); + if (false) { + payloadType = this.payloadTypeFromModelName(belongsTo.modelName); + var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(belongsTo.modelName); + if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) { + + payloadType = deprecatedPayloadTypeLookup; + } + } else { + payloadType = this.payloadKeyFromModelName(belongsTo.modelName); + } + data = { type: payloadType, id: belongsTo.id }; } @@ -14120,10 +14375,13 @@ @param {Object} relationship */ serializeHasMany: function (snapshot, json, relationship) { var key = relationship.key; var shouldSerializeHasMany = '_shouldSerializeHasMany'; + if (false) { + shouldSerializeHasMany = 'shouldSerializeHasMany'; + } if (this[shouldSerializeHasMany](snapshot, key, relationship)) { var hasMany = snapshot.hasMany(key); if (hasMany !== undefined) { @@ -14139,12 +14397,22 @@ for (var i = 0; i < hasMany.length; i++) { var item = hasMany[i]; var payloadType = undefined; - payloadType = this.payloadKeyFromModelName(item.modelName); + if (false) { + payloadType = this.payloadTypeFromModelName(item.modelName); + var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(item.modelName); + if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) { + + payloadType = deprecatedPayloadTypeLookup; + } + } else { + payloadType = this.payloadKeyFromModelName(item.modelName); + } + data[i] = { type: payloadType, id: item.id }; } @@ -14153,88 +14421,109 @@ } } } }); + if (false) { + + JSONAPISerializer.reopen({ + + /** + `modelNameFromPayloadType` can be used to change the mapping for a DS model + name, taken from the value in the payload. + Say your API namespaces the type of a model and returns the following + payload for the `post` model: + ```javascript + // GET /api/posts/1 + { + "data": { + "id": 1, + "type: "api::v1::post" + } + } + ``` + By overwriting `modelNameFromPayloadType` you can specify that the + `posr` model should be used: + ```app/serializers/application.js + import JSONAPISerializer from "ember-data/serializers/json-api"; + export default JSONAPISerializer.extend({ + modelNameFromPayloadType(payloadType) { + return payloadType.replace('api::v1::', ''); + } + }); + ``` + By default the modelName for a model is its singularized name in dasherized + form. Usually, Ember Data can use the correct inflection to do this for + you. Most of the time, you won't need to override + `modelNameFromPayloadType` for this purpose. + Also take a look at + [payloadTypeFromModelName](#method_payloadTypeFromModelName) to customize + how the type of a record should be serialized. + @method modelNameFromPayloadType + @public + @param {String} payloadType type from payload + @return {String} modelName + */ + modelNameFromPayloadType: function (type) { + return (0, _emberInflector.singularize)((0, _emberDataPrivateSystemNormalizeModelName.default)(type)); + }, + + /** + `payloadTypeFromModelName` can be used to change the mapping for the type in + the payload, taken from the model name. + Say your API namespaces the type of a model and expects the following + payload when you update the `post` model: + ```javascript + // POST /api/posts/1 + { + "data": { + "id": 1, + "type": "api::v1::post" + } + } + ``` + By overwriting `payloadTypeFromModelName` you can specify that the + namespaces model name for the `post` should be used: + ```app/serializers/application.js + import JSONAPISerializer from "ember-data/serializers/json-api"; + export default JSONAPISerializer.extend({ + payloadTypeFromModelName(modelName) { + return "api::v1::" + modelName; + } + }); + ``` + By default the payload type is the pluralized model name. Usually, Ember + Data can use the correct inflection to do this for you. Most of the time, + you won't need to override `payloadTypeFromModelName` for this purpose. + Also take a look at + [modelNameFromPayloadType](#method_modelNameFromPayloadType) to customize + how the model name from should be mapped from the payload. + @method payloadTypeFromModelName + @public + @param {String} modelname modelName from the record + @return {String} payloadType + */ + payloadTypeFromModelName: function (modelName) { + return (0, _emberInflector.pluralize)(modelName); + }, + + _hasCustomModelNameFromPayloadKey: function () { + return this.modelNameFromPayloadKey !== JSONAPISerializer.prototype.modelNameFromPayloadKey; + }, + + _hasCustomPayloadKeyFromModelName: function () { + return this.payloadKeyFromModelName !== JSONAPISerializer.prototype.payloadKeyFromModelName; + } + + }); + } + exports.default = JSONAPISerializer; }); /** @module ember-data */ - -/** - `modelNameFromPayloadType` can be used to change the mapping for a DS model - name, taken from the value in the payload. - Say your API namespaces the type of a model and returns the following - payload for the `post` model: - ```javascript - // GET /api/posts/1 - { - "data": { - "id": 1, - "type: "api::v1::post" - } - } - ``` - By overwriting `modelNameFromPayloadType` you can specify that the - `posr` model should be used: - ```app/serializers/application.js - import JSONAPISerializer from "ember-data/serializers/json-api"; - export default JSONAPISerializer.extend({ - modelNameFromPayloadType(payloadType) { - return payloadType.replace('api::v1::', ''); - } - }); - ``` - By default the modelName for a model is its singularized name in dasherized - form. Usually, Ember Data can use the correct inflection to do this for - you. Most of the time, you won't need to override - `modelNameFromPayloadType` for this purpose. - Also take a look at - [payloadTypeFromModelName](#method_payloadTypeFromModelName) to customize - how the type of a record should be serialized. - @method modelNameFromPayloadType - @public - @param {String} payloadType type from payload - @return {String} modelName -*/ - -/** - `payloadTypeFromModelName` can be used to change the mapping for the type in - the payload, taken from the model name. - Say your API namespaces the type of a model and expects the following - payload when you update the `post` model: - ```javascript - // POST /api/posts/1 - { - "data": { - "id": 1, - "type": "api::v1::post" - } - } - ``` - By overwriting `payloadTypeFromModelName` you can specify that the - namespaces model name for the `post` should be used: - ```app/serializers/application.js - import JSONAPISerializer from "ember-data/serializers/json-api"; - export default JSONAPISerializer.extend({ - payloadTypeFromModelName(modelName) { - return "api::v1::" + modelName; - } - }); - ``` - By default the payload type is the pluralized model name. Usually, Ember - Data can use the correct inflection to do this for you. Most of the time, - you won't need to override `payloadTypeFromModelName` for this purpose. - Also take a look at - [modelNameFromPayloadType](#method_modelNameFromPayloadType) to customize - how the model name from should be mapped from the payload. - @method payloadTypeFromModelName - @public - @param {String} modelname modelName from the record - @return {String} payloadType -*/ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/debug', 'ember-data/serializer', 'ember-data/-private/system/coerce-id', 'ember-data/-private/system/normalize-model-name', 'ember-data/-private/utils', 'ember-data/-private/features', 'ember-data/adapters/errors'], function (exports, _ember, _emberDataPrivateDebug, _emberDataSerializer, _emberDataPrivateSystemCoerceId, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateUtils, _emberDataPrivateFeatures, _emberDataAdaptersErrors) { function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } var get = _ember.default.get; var isNone = _ember.default.isNone; @@ -14797,11 +15086,24 @@ relationshipHash.id = (0, _emberDataPrivateSystemCoerceId.default)(relationshipHash.id); } var modelClass = this.store.modelFor(relationshipModelName); if (relationshipHash.type && !(0, _emberDataPrivateUtils.modelHasAttributeOrRelationshipNamedType)(modelClass)) { - relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type); + + if (false) { + var modelName = this.modelNameFromPayloadType(relationshipHash.type); + var deprecatedModelNameLookup = this.modelNameFromPayloadKey(relationshipHash.type); + + if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) { + + modelName = deprecatedModelNameLookup; + } + + relationshipHash.type = modelName; + } else { + relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type); + } } return relationshipHash; } return { id: (0, _emberDataPrivateSystemCoerceId.default)(relationshipHash), type: relationshipModelName }; }, @@ -15343,10 +15645,13 @@ @param {Object} relationship */ serializeHasMany: function (snapshot, json, relationship) { var key = relationship.key; var shouldSerializeHasMany = '_shouldSerializeHasMany'; + if (false) { + shouldSerializeHasMany = 'shouldSerializeHasMany'; + } if (this[shouldSerializeHasMany](snapshot, key, relationship)) { var hasMany = snapshot.hasMany(key, { ids: true }); if (hasMany !== undefined) { // if provided, use the mapping provided by `attrs` in @@ -15591,19 +15896,33 @@ return transform; } }); + if (false) { + + JSONSerializer.reopen({ + + /** + @method modelNameFromPayloadType + @public + @param {String} type + @return {String} the model's modelName + */ + modelNameFromPayloadType: function (type) { + return (0, _emberDataPrivateSystemNormalizeModelName.default)(type); + }, + + _hasCustomModelNameFromPayloadKey: function () { + return this.modelNameFromPayloadKey !== JSONSerializer.prototype.modelNameFromPayloadKey; + } + + }); + } + exports.default = JSONSerializer; }); - -/** - @method modelNameFromPayloadType - @public - @param {String} type - @return {String} the model's modelName - */ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/debug", "ember-data/serializers/json", "ember-data/-private/system/normalize-model-name", "ember-inflector", "ember-data/-private/system/coerce-id", "ember-data/-private/utils", "ember-data/-private/features"], function (exports, _ember, _emberDataPrivateDebug, _emberDataSerializersJson, _emberDataPrivateSystemNormalizeModelName, _emberInflector, _emberDataPrivateSystemCoerceId, _emberDataPrivateUtils, _emberDataPrivateFeatures) { function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } var camelize = _ember.default.String.camelize; @@ -15784,13 +16103,22 @@ var primaryHasTypeAttribute = (0, _emberDataPrivateUtils.modelHasAttributeOrRelationshipNamedType)(primaryModelClass); if (!primaryHasTypeAttribute && hash.type) { // Support polymorphic records in async relationships var modelName = undefined; + if (false) { + modelName = this.modelNameFromPayloadType(hash.type); + var deprecatedModelNameLookup = this.modelNameFromPayloadKey(hash.type); - modelName = this.modelNameFromPayloadKey(hash.type); + if (modelName !== deprecatedModelNameLookup && !this._hasCustomModelNameFromPayloadType() && this._hasCustomModelNameFromPayloadKey()) { + modelName = deprecatedModelNameLookup; + } + } else { + modelName = this.modelNameFromPayloadKey(hash.type); + } + if (store._hasModelFor(modelName)) { serializer = store.serializerFor(modelName); modelClass = store.modelFor(modelName); } } @@ -15991,11 +16319,15 @@ (_documentHash$included5 = documentHash.included).push.apply(_documentHash$included5, _toConsumableArray(included)); } }); } - store.push(documentHash); + if (false) { + return store.push(documentHash); + } else { + store.push(documentHash); + } }, /** This method is used to convert each JSON root key in the payload into a modelName that it can use to look up the appropriate model for @@ -16262,11 +16594,15 @@ } if (_ember.default.isNone(belongsTo)) { json[typeKey] = null; } else { - json[typeKey] = camelize(belongsTo.modelName); + if (false) { + json[typeKey] = this.payloadTypeFromModelName(belongsTo.modelName); + } else { + json[typeKey] = camelize(belongsTo.modelName); + } } }, /** You can use this method to customize how a polymorphic relationship should @@ -16302,102 +16638,149 @@ var isPolymorphic = relationshipMeta.options.polymorphic; var typeProperty = this.keyForPolymorphicType(key, relationshipType, 'deserialize'); if (isPolymorphic && resourceHash[typeProperty] !== undefined && typeof relationshipHash !== 'object') { - var type = this.modelNameFromPayloadKey(resourceHash[typeProperty]); - return { - id: relationshipHash, - type: type - }; + if (false) { + + var payloadType = resourceHash[typeProperty]; + var type = this.modelNameFromPayloadType(payloadType); + var deprecatedTypeLookup = this.modelNameFromPayloadKey(payloadType); + + if (payloadType !== deprecatedTypeLookup && !this._hasCustomModelNameFromPayloadType() && this._hasCustomModelNameFromPayloadKey()) { + + type = deprecatedTypeLookup; + } + + return { + id: relationshipHash, + type: type + }; + } else { + + var type = this.modelNameFromPayloadKey(resourceHash[typeProperty]); + return { + id: relationshipHash, + type: type + }; + } } return this._super.apply(this, arguments); } }); + if (false) { + + RESTSerializer.reopen({ + + /** + `modelNameFromPayloadType` can be used to change the mapping for a DS model + name, taken from the value in the payload. + Say your API namespaces the type of a model and returns the following + payload for the `post` model, which has a polymorphic `user` relationship: + ```javascript + // GET /api/posts/1 + { + "post": { + "id": 1, + "user": 1, + "userType: "api::v1::administrator" + } + } + ``` + By overwriting `modelNameFromPayloadType` you can specify that the + `administrator` model should be used: + ```app/serializers/application.js + import RESTSerializer from "ember-data/serializers/rest"; + export default RESTSerializer.extend({ + modelNameFromPayloadType(payloadType) { + return payloadType.replace('api::v1::', ''); + } + }); + ``` + By default the modelName for a model is its name in dasherized form. + Usually, Ember Data can use the correct inflection to do this for you. Most + of the time, you won't need to override `modelNameFromPayloadType` for this + purpose. + Also take a look at + [payloadTypeFromModelName](#method_payloadTypeFromModelName) to customize + how the type of a record should be serialized. + @method modelNameFromPayloadType + @public + @param {String} payloadType type from payload + @return {String} modelName + */ + modelNameFromPayloadType: function (payloadType) { + return (0, _emberInflector.singularize)((0, _emberDataPrivateSystemNormalizeModelName.default)(payloadType)); + }, + + /** + `payloadTypeFromModelName` can be used to change the mapping for the type in + the payload, taken from the model name. + Say your API namespaces the type of a model and expects the following + payload when you update the `post` model, which has a polymorphic `user` + relationship: + ```javascript + // POST /api/posts/1 + { + "post": { + "id": 1, + "user": 1, + "userType": "api::v1::administrator" + } + } + ``` + By overwriting `payloadTypeFromModelName` you can specify that the + namespaces model name for the `administrator` should be used: + ```app/serializers/application.js + import RESTSerializer from "ember-data/serializers/rest"; + export default RESTSerializer.extend({ + payloadTypeFromModelName(modelName) { + return "api::v1::" + modelName; + } + }); + ``` + By default the payload type is the camelized model name. Usually, Ember + Data can use the correct inflection to do this for you. Most of the time, + you won't need to override `payloadTypeFromModelName` for this purpose. + Also take a look at + [modelNameFromPayloadType](#method_modelNameFromPayloadType) to customize + how the model name from should be mapped from the payload. + @method payloadTypeFromModelName + @public + @param {String} modelname modelName from the record + @return {String} payloadType + */ + payloadTypeFromModelName: function (modelName) { + return camelize(modelName); + }, + + _hasCustomModelNameFromPayloadKey: function () { + return this.modelNameFromPayloadKey !== RESTSerializer.prototype.modelNameFromPayloadKey; + }, + + _hasCustomModelNameFromPayloadType: function () { + return this.modelNameFromPayloadType !== RESTSerializer.prototype.modelNameFromPayloadType; + }, + + _hasCustomPayloadTypeFromModelName: function () { + return this.payloadTypeFromModelName !== RESTSerializer.prototype.payloadTypeFromModelName; + }, + + _hasCustomPayloadKeyFromModelName: function () { + return this.payloadKeyFromModelName !== RESTSerializer.prototype.payloadKeyFromModelName; + } + + }); + } + exports.default = RESTSerializer; }); /** @module ember-data */ - -/** - `modelNameFromPayloadType` can be used to change the mapping for a DS model - name, taken from the value in the payload. - Say your API namespaces the type of a model and returns the following - payload for the `post` model, which has a polymorphic `user` relationship: - ```javascript - // GET /api/posts/1 - { - "post": { - "id": 1, - "user": 1, - "userType: "api::v1::administrator" - } - } - ``` - By overwriting `modelNameFromPayloadType` you can specify that the - `administrator` model should be used: - ```app/serializers/application.js - import RESTSerializer from "ember-data/serializers/rest"; - export default RESTSerializer.extend({ - modelNameFromPayloadType(payloadType) { - return payloadType.replace('api::v1::', ''); - } - }); - ``` - By default the modelName for a model is its name in dasherized form. - Usually, Ember Data can use the correct inflection to do this for you. Most - of the time, you won't need to override `modelNameFromPayloadType` for this - purpose. - Also take a look at - [payloadTypeFromModelName](#method_payloadTypeFromModelName) to customize - how the type of a record should be serialized. - @method modelNameFromPayloadType - @public - @param {String} payloadType type from payload - @return {String} modelName -*/ - -/** - `payloadTypeFromModelName` can be used to change the mapping for the type in - the payload, taken from the model name. - Say your API namespaces the type of a model and expects the following - payload when you update the `post` model, which has a polymorphic `user` - relationship: - ```javascript - // POST /api/posts/1 - { - "post": { - "id": 1, - "user": 1, - "userType": "api::v1::administrator" - } - } - ``` - By overwriting `payloadTypeFromModelName` you can specify that the - namespaces model name for the `administrator` should be used: - ```app/serializers/application.js - import RESTSerializer from "ember-data/serializers/rest"; - export default RESTSerializer.extend({ - payloadTypeFromModelName(modelName) { - return "api::v1::" + modelName; - } - }); - ``` - By default the payload type is the camelized model name. Usually, Ember - Data can use the correct inflection to do this for you. Most of the time, - you won't need to override `payloadTypeFromModelName` for this purpose. - Also take a look at - [modelNameFromPayloadType](#method_modelNameFromPayloadType) to customize - how the model name from should be mapped from the payload. - @method payloadTypeFromModelName - @public - @param {String} modelname modelName from the record - @return {String} payloadType -*/ define('ember-data/setup-container', ['exports', 'ember-data/-private/initializers/store', 'ember-data/-private/initializers/transforms', 'ember-data/-private/initializers/store-injections', 'ember-data/-private/initializers/data-adapter'], function (exports, _emberDataPrivateInitializersStore, _emberDataPrivateInitializersTransforms, _emberDataPrivateInitializersStoreInjections, _emberDataPrivateInitializersDataAdapter) { exports.default = setupContainer; function setupContainer(application) { (0, _emberDataPrivateInitializersDataAdapter.default)(application); @@ -16481,10 +16864,10 @@ */ deserialize: null }); }); define("ember-data/version", ["exports"], function (exports) { - exports.default = "2.7.0-beta.1"; + exports.default = "2.7.0-beta.2"; }); 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;