dist/globals/ember-data.prod.js in ember-data-source-2.6.0 vs dist/globals/ember-data.prod.js in ember-data-source-2.6.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.6.0 + * @version 2.6.1 */ 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 = {}; @@ -2892,27 +2906,30 @@ return "<" + this.modelName + ":" + this.id + ">"; } } }; - InternalModel.prototype.referenceFor = function (type, name) { - var reference = this.references[name]; + if (true) { - if (!reference) { - var relationship = this._relationships.get(name); + InternalModel.prototype.referenceFor = function (type, name) { + var reference = this.references[name]; - if (type === "belongsTo") { - reference = new _emberDataPrivateSystemReferences.BelongsToReference(this.store, this, relationship); - } else if (type === "hasMany") { - reference = new _emberDataPrivateSystemReferences.HasManyReference(this.store, this, relationship); - } + if (!reference) { + var relationship = this._relationships.get(name); - this.references[name] = reference; - } + if (type === "belongsTo") { + reference = new _emberDataPrivateSystemReferences.BelongsToReference(this.store, this, relationship); + } else if (type === "hasMany") { + reference = new _emberDataPrivateSystemReferences.HasManyReference(this.store, this, relationship); + } - return reference; - }; + this.references[name] = reference; + } + + return reference; + }; + } }); define("ember-data/-private/system/model/model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/model/errors", "ember-data/-private/features", "ember-data/-private/system/debug/debug-info", "ember-data/-private/system/relationships/belongs-to", "ember-data/-private/system/relationships/has-many", "ember-data/-private/system/relationships/ext", "ember-data/-private/system/model/attr"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemModelErrors, _emberDataPrivateFeatures, _emberDataPrivateSystemDebugDebugInfo, _emberDataPrivateSystemRelationshipsBelongsTo, _emberDataPrivateSystemRelationshipsHasMany, _emberDataPrivateSystemRelationshipsExt, _emberDataPrivateSystemModelAttr) { /** @module ember-data @@ -3670,109 +3687,112 @@ return this.store.container; } }); } - Model.reopen({ + if (true) { - /** - Get the reference for the specified belongsTo relationship. - Example - ```javascript - // models/blog.js - export default DS.Model.extend({ - user: DS.belongsTo({ async: true }) - }); - var blog = store.push({ - type: 'blog', - id: 1, - relationships: { - user: { type: 'user', id: 1 } + Model.reopen({ + + /** + Get the reference for the specified belongsTo relationship. + Example + ```javascript + // models/blog.js + export default DS.Model.extend({ + user: DS.belongsTo({ async: true }) + }); + var blog = store.push({ + type: 'blog', + id: 1, + relationships: { + user: { type: 'user', id: 1 } + } + }); + var userRef = blog.belongsTo('user'); + // check if the user relationship is loaded + var isLoaded = userRef.value() !== null; + // get the record of the reference (null if not yet available) + var user = userRef.value(); + // get the identifier of the reference + if (userRef.remoteType() === "id") { + var id = userRef.id(); + } else if (userRef.remoteType() === "link") { + var link = userRef.link(); } - }); - var userRef = blog.belongsTo('user'); - // check if the user relationship is loaded - var isLoaded = userRef.value() !== null; - // get the record of the reference (null if not yet available) - var user = userRef.value(); - // get the identifier of the reference - if (userRef.remoteType() === "id") { - var id = userRef.id(); - } else if (userRef.remoteType() === "link") { - var link = userRef.link(); - } - // load user (via store.findRecord or store.findBelongsTo) - userRef.load().then(...) - // or trigger a reload - userRef.reload().then(...) - // provide data for reference - userRef.push({ - type: 'user', - id: 1, - attributes: { - username: "@user" - } - }).then(function(user) { - userRef.value() === user; - }); - ``` - @method belongsTo - @param {String} name of the relationship - @return {BelongsToReference} reference for this relationship - */ - belongsTo: function (name) { - return this._internalModel.referenceFor('belongsTo', name); - }, + // load user (via store.findRecord or store.findBelongsTo) + userRef.load().then(...) + // or trigger a reload + userRef.reload().then(...) + // provide data for reference + userRef.push({ + type: 'user', + id: 1, + attributes: { + username: "@user" + } + }).then(function(user) { + userRef.value() === user; + }); + ``` + @method belongsTo + @param {String} name of the relationship + @return {BelongsToReference} reference for this relationship + */ + belongsTo: function (name) { + return this._internalModel.referenceFor('belongsTo', name); + }, - /** - Get the reference for the specified hasMany relationship. - Example - ```javascript - // models/blog.js - export default DS.Model.extend({ - comments: DS.hasMany({ async: true }) - }); - var blog = store.push({ - type: 'blog', - id: 1, - relationships: { - comments: { - data: [ - { type: 'comment', id: 1 }, - { type: 'comment', id: 2 } - ] + /** + Get the reference for the specified hasMany relationship. + Example + ```javascript + // models/blog.js + export default DS.Model.extend({ + comments: DS.hasMany({ async: true }) + }); + var blog = store.push({ + type: 'blog', + id: 1, + relationships: { + comments: { + data: [ + { type: 'comment', id: 1 }, + { type: 'comment', id: 2 } + ] + } } + }); + var commentsRef = blog.hasMany('comments'); + // check if the comments are loaded already + var isLoaded = commentsRef.value() !== null; + // get the records of the reference (null if not yet available) + var comments = commentsRef.value(); + // get the identifier of the reference + if (commentsRef.remoteType() === "ids") { + var ids = commentsRef.ids(); + } else if (commentsRef.remoteType() === "link") { + var link = commentsRef.link(); } - }); - var commentsRef = blog.hasMany('comments'); - // check if the comments are loaded already - var isLoaded = commentsRef.value() !== null; - // get the records of the reference (null if not yet available) - var comments = commentsRef.value(); - // get the identifier of the reference - if (commentsRef.remoteType() === "ids") { - var ids = commentsRef.ids(); - } else if (commentsRef.remoteType() === "link") { - var link = commentsRef.link(); + // load comments (via store.findMany or store.findHasMany) + commentsRef.load().then(...) + // or trigger a reload + commentsRef.reload().then(...) + // provide data for reference + commentsRef.push([{ type: 'comment', id: 1 }, { type: 'comment', id: 2 }]).then(function(comments) { + commentsRef.value() === comments; + }); + ``` + @method hasMany + @param {String} name of the relationship + @return {HasManyReference} reference for this relationship + */ + hasMany: function (name) { + return this._internalModel.referenceFor('hasMany', name); } - // load comments (via store.findMany or store.findHasMany) - commentsRef.load().then(...) - // or trigger a reload - commentsRef.reload().then(...) - // provide data for reference - commentsRef.push([{ type: 'comment', id: 1 }, { type: 'comment', id: 2 }]).then(function(comments) { - commentsRef.value() === comments; - }); - ``` - @method hasMany - @param {String} name of the relationship - @return {HasManyReference} reference for this relationship - */ - hasMany: function (name) { - return this._internalModel.referenceFor('hasMany', name); - } - }); + }); + } Model.reopenClass(_emberDataPrivateSystemRelationshipsExt.RelationshipsClassMethodsMixin); Model.reopenClass(_emberDataPrivateSystemModelAttr.AttrClassMethodsMixin); exports.default = Model.extend(_emberDataPrivateSystemDebugDebugInfo.default, _emberDataPrivateSystemRelationshipsBelongsTo.BelongsToMixin, _emberDataPrivateSystemRelationshipsExt.DidDefinePropertyMixin, _emberDataPrivateSystemRelationshipsExt.RelationshipsInstanceMethodsMixin, _emberDataPrivateSystemRelationshipsHasMany.HasManyMixin, _emberDataPrivateSystemModelAttr.AttrInstanceMethodsMixin); @@ -5153,10 +5173,14 @@ isLoaded: true, isUpdating: false, meta: (0, _emberDataPrivateSystemCloneNull.default)(payload.meta) }); + if (false) { + this.set('links', (0, _emberDataPrivateSystemCloneNull.default)(payload.links)); + } + internalModels.forEach(function (record) { _this.manager.recordArraysForRecord(record).add(_this); }); // TODO: should triggering didLoad event be the last action of the runLoop? @@ -7343,11 +7367,13 @@ @property adapterOptions @type {Object} */ this.adapterOptions = options.adapterOptions; - this.include = options.include; + if (true) { + this.include = options.include; + } } /** Get snapshots of the underlying record array @method snapshots @@ -7406,11 +7432,13 @@ @property adapterOptions @type {Object} */ this.adapterOptions = options.adapterOptions; - this.include = options.include; + if (true) { + this.include = options.include; + } this._changedAttributes = record.changedAttributes(); } Snapshot.prototype = { @@ -9384,14 +9412,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. @@ -9571,42 +9604,45 @@ this.unloadAll(); } }); - Store.reopen({ - /** - Get the reference for the specified record. - Example - ```javascript - var userRef = store.getReference('user', 1); - // check if the user is loaded - var isLoaded = userRef.value() !== null; - // get the record of the reference (null if not yet available) - var user = userRef.value(); - // get the identifier of the reference - if (userRef.remoteType() === "id") { - var id = userRef.id(); + if (true) { + + Store.reopen({ + /** + Get the reference for the specified record. + Example + ```javascript + var userRef = store.getReference('user', 1); + // check if the user is loaded + var isLoaded = userRef.value() !== null; + // get the record of the reference (null if not yet available) + var user = userRef.value(); + // get the identifier of the reference + if (userRef.remoteType() === "id") { + var id = userRef.id(); + } + // load user (via store.find) + userRef.load().then(...) + // or trigger a reload + userRef.reload().then(...) + // provide data for reference + userRef.push({ id: 1, username: "@user" }).then(function(user) { + userRef.value() === user; + }); + ``` + @method getReference + @param {String} type + @param {String|Integer} id + @return {RecordReference} + */ + getReference: function (type, id) { + return this._internalModelForId(type, id).recordReference; } - // load user (via store.find) - userRef.load().then(...) - // or trigger a reload - userRef.reload().then(...) - // provide data for reference - userRef.push({ id: 1, username: "@user" }).then(function(user) { - userRef.value() === user; - }); - ``` - @method getReference - @param {String} type - @param {String|Integer} id - @return {RecordReference} - */ - getReference: function (type, id) { - return this._internalModelForId(type, id).recordReference; - } - }); + }); + } function deserializeRecordId(store, key, relationship, id) { if (isNone(id)) { return; } @@ -10193,10 +10229,18 @@ */ exports.default = _emberDataTransform.default.extend({ deserialize: function (serialized, options) { var type = typeof serialized; + if (true) { + if (false) { + if (isNone(serialized) && options.allowNull === true) { + return null; + } + } + } + if (type === "boolean") { return serialized; } else if (type === "string") { return serialized.match(/^true$|^t$|^1$/i) !== null; } else if (type === "number") { @@ -10205,10 +10249,17 @@ return false; } }, serialize: function (deserialized, options) { + if (true) { + if (false) { + if (isNone(deserialized) && options.allowNull === true) { + return null; + } + } + } return Boolean(deserialized); } }); }); @@ -11004,10 +11055,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]; @@ -11290,12 +11344,16 @@ @param {Array} ids @param {Array} snapshots @return {Promise} promise */ findMany: function (store, type, ids, snapshots) { - var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); - return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } }); + if (false) { + 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 @@ -11313,22 +11371,85 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ updateRecord: function (store, type, snapshot) { - var data = {}; - var serializer = store.serializerFor(type.modelName); + if (false) { + return this._super.apply(this, arguments); + } else { + var data = {}; + var serializer = store.serializerFor(type.modelName); - serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); - var id = snapshot.id; - var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); + var id = snapshot.id; + var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); - return this.ajax(url, 'PATCH', { data: data }); + return this.ajax(url, 'PATCH', { data: data }); + } } }); + if (false) { + + JSONAPIAdapter.reopen({ + + methodForRequest: function (params) { + if (params.requestType === 'updateRecord') { + return 'PATCH'; + } + + return this._super.apply(this, arguments); + }, + + dataForRequest: function (params) { + var requestType = params.requestType; + var ids = params.ids; + + if (requestType === 'findMany') { + return { + filter: { id: ids.join(',') } + }; + } + + if (requestType === 'updateRecord') { + var store = params.store; + var type = params.type; + var snapshot = params.snapshot; + + var data = {}; + var serializer = store.serializerFor(type.modelName); + + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + + 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 */ @@ -11691,14 +11812,23 @@ @param {String} id @param {DS.Snapshot} snapshot @return {Promise} promise */ findRecord: function (store, type, id, snapshot) { - var url = this.buildURL(type.modelName, id, snapshot, 'findRecord'); - var query = this.buildQuery(snapshot); + if (false) { + var request = this._requestFor({ + store: store, type: type, id: id, snapshot: snapshot, + requestType: 'findRecord' + }); - return this.ajax(url, 'GET', { data: query }); + 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. @@ -11712,17 +11842,27 @@ @return {Promise} promise */ findAll: function (store, type, sinceToken, snapshotRecordArray) { var query = this.buildQuery(snapshotRecordArray); - var url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll'); + if (false) { + var request = this._requestFor({ + store: store, type: type, sinceToken: sinceToken, query: query, + snapshots: snapshotRecordArray, + requestType: 'findAll' + }); - if (sinceToken) { - query.since = sinceToken; - } + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll'); - return this.ajax(url, 'GET', { data: query }); + 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. @@ -11736,17 +11876,26 @@ @param {DS.Model} type @param {Object} query @return {Promise} promise */ query: function (store, type, query) { - var url = this.buildURL(type.modelName, null, null, 'query', query); + if (false) { + var request = this._requestFor({ + store: store, type: type, query: query, + requestType: 'query' + }); - if (this.sortQueryParams) { - query = this.sortQueryParams(query); - } + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, null, null, 'query', query); - return this.ajax(url, 'GET', { data: 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. @@ -11760,17 +11909,26 @@ @param {DS.Model} type @param {Object} query @return {Promise} promise */ queryRecord: function (store, type, query) { - var url = this.buildURL(type.modelName, null, null, 'queryRecord', query); + if (false) { + var request = this._requestFor({ + store: store, type: type, query: query, + requestType: 'queryRecord' + }); - if (this.sortQueryParams) { - query = this.sortQueryParams(query); - } + return this._makeRequest(request); + } else { + var url = this.buildURL(type.modelName, null, null, 'queryRecord', query); - return this.ajax(url, 'GET', { data: 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: @@ -11796,12 +11954,21 @@ @param {Array} ids @param {Array} snapshots @return {Promise} promise */ findMany: function (store, type, ids, snapshots) { - var url = this.buildURL(type.modelName, ids, snapshots, 'findMany'); - return this.ajax(url, 'GET', { data: { ids: ids } }); + if (false) { + var request = this._requestFor({ + store: store, type: type, ids: ids, snapshots: snapshots, + requestType: 'findMany' + }); + + 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 @@ -11827,16 +11994,25 @@ @param {DS.Snapshot} snapshot @param {String} url @return {Promise} promise */ findHasMany: function (store, snapshot, url, relationship) { - var id = snapshot.id; - var type = snapshot.modelName; + if (false) { + var request = this._requestFor({ + store: store, snapshot: snapshot, url: url, relationship: relationship, + requestType: 'findHasMany' + }); - url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findHasMany')); + return this._makeRequest(request); + } else { + var id = snapshot.id; + var type = snapshot.modelName; - return this.ajax(url, 'GET'); + 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 @@ -11862,15 +12038,24 @@ @param {DS.Snapshot} snapshot @param {String} url @return {Promise} promise */ findBelongsTo: function (store, snapshot, url, relationship) { - var id = snapshot.id; - var type = snapshot.modelName; + if (false) { + var request = this._requestFor({ + store: store, snapshot: snapshot, url: url, relationship: relationship, + requestType: 'findBelongsTo' + }); - url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findBelongsTo')); - return this.ajax(url, 'GET'); + 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. @@ -11883,17 +12068,26 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ createRecord: function (store, type, snapshot) { - var data = {}; - var serializer = store.serializerFor(type.modelName); - var url = this.buildURL(type.modelName, null, snapshot, 'createRecord'); + if (false) { + var request = this._requestFor({ + store: store, type: type, snapshot: snapshot, + requestType: 'createRecord' + }); - serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + return this._makeRequest(request); + } else { + var data = {}; + var serializer = store.serializerFor(type.modelName); + var url = this.buildURL(type.modelName, null, snapshot, 'createRecord'); - return this.ajax(url, "POST", { data: data }); + 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. @@ -11906,19 +12100,28 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ updateRecord: function (store, type, snapshot) { - var data = {}; - var serializer = store.serializerFor(type.modelName); + if (false) { + var request = this._requestFor({ + store: store, type: type, snapshot: snapshot, + requestType: 'updateRecord' + }); - serializer.serializeIntoHash(data, type, snapshot); + return this._makeRequest(request); + } else { + var data = {}; + var serializer = store.serializerFor(type.modelName); - var id = snapshot.id; - var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord'); + serializer.serializeIntoHash(data, type, snapshot); - return this.ajax(url, "PUT", { data: data }); + 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`. @@ -11927,13 +12130,22 @@ @param {DS.Model} type @param {DS.Snapshot} snapshot @return {Promise} promise */ deleteRecord: function (store, type, snapshot) { - var id = snapshot.id; + if (false) { + var request = this._requestFor({ + store: store, type: type, snapshot: snapshot, + requestType: 'deleteRecord' + }); - return this.ajax(this.buildURL(type.modelName, id, snapshot, 'deleteRecord'), "DELETE"); + 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); @@ -12049,10 +12261,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 @@ -12248,22 +12477,277 @@ }, buildQuery: function (snapshot) { var query = {}; - if (snapshot) { - var include = snapshot.include; + if (true) { + if (snapshot) { + var include = snapshot.include; - if (include) { - query.include = include; + if (include) { + query.include = include; + } } } return query; } }); + if (false) { + + RESTAdapter.reopen({ + + /** + * 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; + + // type is not passed to findBelongsTo and findHasMany + type = type || snapshot && snapshot.type; + + var serializer = store.serializerFor(type.modelName); + var data = {}; + + switch (requestType) { + case 'createRecord': + serializer.serializeIntoHash(data, type, snapshot, { includeId: true }); + break; + + case 'updateRecord': + serializer.serializeIntoHash(data, type, snapshot); + break; + + case 'findRecord': + data = this.buildQuery(snapshot); + break; + + case 'findAll': + if (params.sinceToken) { + query = query || {}; + query.since = params.sinceToken; + } + data = query; + break; + + case 'query': + case 'queryRecord': + if (this.sortQueryParams) { + query = this.sortQueryParams(query); + } + data = query; + break; + + case 'findMany': + data = { ids: params.ids }; + break; + + default: + data = undefined; + break; + } + + return data; + }, + + /** + * Get the HTTP method for a request. + * + * @public + * @method methodForRequest + * @param {Object} params + * @return {String} HTTP method + */ + methodForRequest: function (params) { + var requestType = params.requestType; + + switch (requestType) { + case 'createRecord': + return 'POST'; + case 'updateRecord': + return 'PUT'; + case 'deleteRecord': + return 'DELETE'; + } + + return 'GET'; + }, + + /** + * 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; + + // 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; + + switch (requestType) { + case 'findAll': + return this.buildURL(type.modelName, null, snapshots, requestType); + + case 'query': + case 'queryRecord': + return this.buildURL(type.modelName, null, null, requestType, query); + + case 'findMany': + return this.buildURL(type.modelName, ids, snapshots, requestType); + + case 'findHasMany': + case 'findBelongsTo': + var url = this.buildURL(type.modelName, id, snapshot, requestType); + return this.urlPrefix(params.url, url); + } + + return this.buildURL(type.modelName, id, snapshot, requestType, query); + }, + + /** + * 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'); + }, + + /** + * 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); + + return { method: method, url: url, headers: headers, data: data }; + }, + + /** + * 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 = {}; + + 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]); + }); + }; + } + + 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); + + var method = request.method; + var url = request.url; + + var requestData = { method: method, url: url }; + + 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); + + 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) { + + 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); + } + + _ember.default.run.join(null, reject, error); + }; + + 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; } else { @@ -12274,82 +12758,10 @@ exports.default = RESTAdapter; }); /** @module ember-data */ - -/** - * Get the data (body or query params) for a request. - * - * @public - * @method dataForRequest - * @param {Object} params - * @return {Object} data - */ - -// type is not passed to findBelongsTo and findHasMany - -/** - * Get the HTTP method for a request. - * - * @public - * @method methodForRequest - * @param {Object} params - * @return {String} HTTP method - */ - -/** - * Get the URL for a request. - * - * @public - * @method urlForRequest - * @param {Object} params - * @return {String} URL - */ - -// type and id are not passed from updateRecord and deleteRecord, hence they -// are defined if not set - -/** - * 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 - */ - -/** - * Get an object which contains all properties for a request which should - * be made. - * - * @private - * @method _requestFor - * @param {Object} params - * @return {Object} request object - */ - -/** - * 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 - */ - -/** - * Make a request using `jQuery.ajax`. - * - * @private - * @method _makeRequest - * @param {Object} request - * @return {Promise} promise - */ define('ember-data/attr', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) { exports.default = attr; /** @module ember-data @@ -12544,10 +12956,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; @@ -13034,12 +13454,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); + } } } }, /** @@ -13433,12 +13855,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 @@ -13667,11 +14092,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) { @@ -13916,22 +14341,26 @@ */ applyTransforms: function (typeClass, data) { var _this = this; var attributes = undefined; + if (true) { + attributes = get(typeClass, 'attributes'); + } - attributes = get(typeClass, 'attributes'); - typeClass.eachTransformedAttribute(function (key, typeClass) { if (!(key in data)) { return; } var transform = _this.transformFor(typeClass); - - var transformMeta = attributes.get(key); - data[key] = transform.deserialize(data[key], transformMeta.options); + if (true) { + var transformMeta = attributes.get(key); + data[key] = transform.deserialize(data[key], transformMeta.options); + } else { + data[key] = transform.deserialize(data[key]); + } }); return data; }, @@ -14767,12 +15196,15 @@ if (this._canSerialize(key)) { var value = snapshot.attr(key); if (type) { var transform = this.transformFor(type); - - value = transform.serialize(value, attribute.options); + if (true) { + value = transform.serialize(value, attribute.options); + } else { + value = transform.serialize(value); + } } // if provided, use the mapping provided by `attrs` in // the serializer var payloadKey = this._getMappedKey(key, snapshot.type); @@ -15489,11 +15921,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 @@ -15900,10 +16336,10 @@ */ deserialize: null }); }); define("ember-data/version", ["exports"], function (exports) { - exports.default = "2.6.0"; + exports.default = "2.6.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;