dist/globals/ember-data.prod.js in ember-data-source-2.13.0.beta.2 vs dist/globals/ember-data.prod.js in ember-data-source-2.13.0.beta.3
- old
+ new
@@ -1,17 +1,343 @@
(function(){
"use strict";
-define("ember-data/-private/adapters", ["exports", "ember-data/adapters/json-api", "ember-data/adapters/rest"], function (exports, _emberDataAdaptersJsonApi, _emberDataAdaptersRest) {
- exports.JSONAPIAdapter = _emberDataAdaptersJsonApi.default;
- exports.RESTAdapter = _emberDataAdaptersRest.default;
+/*!
+ * @overview Ember Data
+ * @copyright Copyright 2011-2017 Tilde Inc. and contributors.
+ * Portions Copyright 2011 LivingSocial Inc.
+ * @license Licensed under MIT license (see license.js)
+ * @version 2.13.0-beta.3
+ */
+
+var loader, define, requireModule, require, requirejs;
+
+(function (global) {
+ 'use strict';
+
+ var heimdall = global.heimdall;
+
+ function dict() {
+ var obj = Object.create(null);
+ obj['__'] = undefined;
+ delete obj['__'];
+ return obj;
+ }
+
+ // Save off the original values of these globals, so we can restore them if someone asks us to
+ var oldGlobals = {
+ loader: loader,
+ define: define,
+ requireModule: requireModule,
+ require: require,
+ requirejs: requirejs
+ };
+
+ requirejs = require = requireModule = function (name) {
+ var pending = [];
+ var mod = findModule(name, '(require)', pending);
+
+ for (var i = pending.length - 1; i >= 0; i--) {
+ pending[i].exports();
+ }
+
+ return mod.module.exports;
+ };
+
+ loader = {
+ noConflict: function (aliases) {
+ var oldName, newName;
+
+ for (oldName in aliases) {
+ if (aliases.hasOwnProperty(oldName)) {
+ if (oldGlobals.hasOwnProperty(oldName)) {
+ newName = aliases[oldName];
+
+ global[newName] = global[oldName];
+ global[oldName] = oldGlobals[oldName];
+ }
+ }
+ }
+ }
+ };
+
+ var _isArray;
+ if (!Array.isArray) {
+ _isArray = function (x) {
+ return Object.prototype.toString.call(x) === '[object Array]';
+ };
+ } else {
+ _isArray = Array.isArray;
+ }
+
+ var registry = dict();
+ var seen = dict();
+
+ var uuid = 0;
+
+ function unsupportedModule(length) {
+ throw new Error('an unsupported module was defined, expected `define(name, deps, module)` instead got: `' + length + '` arguments to define`');
+ }
+
+ var defaultDeps = ['require', 'exports', 'module'];
+
+ function Module(name, deps, callback, alias) {
+ this.id = uuid++;
+ this.name = name;
+ this.deps = !deps.length && callback.length ? defaultDeps : deps;
+ this.module = { exports: {} };
+ this.callback = callback;
+ this.hasExportsAsDep = false;
+ this.isAlias = alias;
+ this.reified = new Array(deps.length);
+
+ /*
+ Each module normally passes through these states, in order:
+ new : initial state
+ pending : this module is scheduled to be executed
+ reifying : this module's dependencies are being executed
+ reified : this module's dependencies finished executing successfully
+ errored : this module's dependencies failed to execute
+ finalized : this module executed successfully
+ */
+ this.state = 'new';
+ }
+
+ Module.prototype.makeDefaultExport = function () {
+ var exports = this.module.exports;
+ if (exports !== null && (typeof exports === 'object' || typeof exports === 'function') && exports['default'] === undefined && Object.isExtensible(exports)) {
+ exports['default'] = exports;
+ }
+ };
+
+ Module.prototype.exports = function () {
+ // if finalized, there is no work to do. If reifying, there is a
+ // circular dependency so we must return our (partial) exports.
+ if (this.state === 'finalized' || this.state === 'reifying') {
+ return this.module.exports;
+ }
+
+ if (loader.wrapModules) {
+ this.callback = loader.wrapModules(this.name, this.callback);
+ }
+
+ this.reify();
+
+ var result = this.callback.apply(this, this.reified);
+ this.state = 'finalized';
+
+ if (!(this.hasExportsAsDep && result === undefined)) {
+ this.module.exports = result;
+ }
+ this.makeDefaultExport();
+ return this.module.exports;
+ };
+
+ Module.prototype.unsee = function () {
+ this.state = 'new';
+ this.module = { exports: {} };
+ };
+
+ Module.prototype.reify = function () {
+ if (this.state === 'reified') {
+ return;
+ }
+ this.state = 'reifying';
+ try {
+ this.reified = this._reify();
+ this.state = 'reified';
+ } finally {
+ if (this.state === 'reifying') {
+ this.state = 'errored';
+ }
+ }
+ };
+
+ Module.prototype._reify = function () {
+ var reified = this.reified.slice();
+ for (var i = 0; i < reified.length; i++) {
+ var mod = reified[i];
+ reified[i] = mod.exports ? mod.exports : mod.module.exports();
+ }
+ return reified;
+ };
+
+ Module.prototype.findDeps = function (pending) {
+ if (this.state !== 'new') {
+ return;
+ }
+
+ this.state = 'pending';
+
+ var deps = this.deps;
+
+ for (var i = 0; i < deps.length; i++) {
+ var dep = deps[i];
+ var entry = this.reified[i] = { exports: undefined, module: undefined };
+ if (dep === 'exports') {
+ this.hasExportsAsDep = true;
+ entry.exports = this.module.exports;
+ } else if (dep === 'require') {
+ entry.exports = this.makeRequire();
+ } else if (dep === 'module') {
+ entry.exports = this.module;
+ } else {
+ entry.module = findModule(resolve(dep, this.name), this.name, pending);
+ }
+ }
+ };
+
+ Module.prototype.makeRequire = function () {
+ var name = this.name;
+ var r = function (dep) {
+ return require(resolve(dep, name));
+ };
+ r['default'] = r;
+ r.has = function (dep) {
+ return has(resolve(dep, name));
+ };
+ return r;
+ };
+
+ define = function (name, deps, callback) {
+ var module = registry[name];
+
+ // If a module for this name has already been defined and is in any state
+ // other than `new` (meaning it has been or is currently being required),
+ // then we return early to avoid redefinition.
+ if (module && module.state !== 'new') {
+ return;
+ }
+
+ if (arguments.length < 2) {
+ unsupportedModule(arguments.length);
+ }
+
+ if (!_isArray(deps)) {
+ callback = deps;
+ deps = [];
+ }
+
+ if (callback instanceof Alias) {
+ registry[name] = new Module(callback.name, deps, callback, true);
+ } else {
+ registry[name] = new Module(name, deps, callback, false);
+ }
+ };
+
+ // we don't support all of AMD
+ // define.amd = {};
+
+ function Alias(path) {
+ this.name = path;
+ }
+
+ define.alias = function (path) {
+ return new Alias(path);
+ };
+
+ function missingModule(name, referrer) {
+ throw new Error('Could not find module `' + name + '` imported from `' + referrer + '`');
+ }
+
+ function findModule(name, referrer, pending) {
+ var mod = registry[name] || registry[name + '/index'];
+
+ while (mod && mod.isAlias) {
+ mod = registry[mod.name];
+ }
+
+ if (!mod) {
+ missingModule(name, referrer);
+ }
+
+ if (pending && mod.state !== 'pending' && mod.state !== 'finalized') {
+ mod.findDeps(pending);
+ pending.push(mod);
+ }
+ return mod;
+ }
+
+ function resolve(child, name) {
+ if (child.charAt(0) !== '.') {
+ return child;
+ }
+
+ var parts = child.split('/');
+ var nameParts = name.split('/');
+ var parentBase = nameParts.slice(0, -1);
+
+ for (var i = 0, l = parts.length; i < l; i++) {
+ var part = parts[i];
+
+ if (part === '..') {
+ if (parentBase.length === 0) {
+ throw new Error('Cannot access parent module of root');
+ }
+ parentBase.pop();
+ } else if (part === '.') {
+ continue;
+ } else {
+ parentBase.push(part);
+ }
+ }
+
+ return parentBase.join('/');
+ }
+
+ function has(name) {
+ return !!(registry[name] || registry[name + '/index']);
+ }
+
+ requirejs.entries = requirejs._eak_seen = registry;
+ requirejs.has = has;
+ requirejs.unsee = function (moduleName) {
+ findModule(moduleName, '(unsee)', false).unsee();
+ };
+
+ requirejs.clear = function () {
+ requirejs.entries = requirejs._eak_seen = registry = dict();
+ seen = dict();
+ };
+
+ // This code primes the JS engine for good performance by warming the
+ // JIT compiler for these functions.
+ define('foo', function () {});
+ define('foo/bar', [], function () {});
+ define('foo/asdf', ['module', 'exports', 'require'], function (module, exports, require) {
+ if (require.has('foo/bar')) {
+ require('foo/bar');
+ }
+ });
+ define('foo/baz', [], define.alias('foo'));
+ define('foo/quz', define.alias('foo'));
+ define('foo/bar', ['foo', './quz', './baz', './asdf', './bar', '../foo'], function () {});
+ define('foo/main', ['foo/bar'], function () {});
+
+ require('foo/main');
+ require.unsee('foo/bar');
+
+ requirejs.clear();
+
+ if (typeof exports === 'object' && typeof module === 'object' && module.exports) {
+ module.exports = { require: require, define: define };
+ }
+})(this);
+define("ember-data/-private/adapters", ["exports", "ember-data/adapters/json-api", "ember-data/adapters/rest"], function (exports, _jsonApi, _rest) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.RESTAdapter = exports.JSONAPIAdapter = undefined;
+ exports.JSONAPIAdapter = _jsonApi.default;
+ exports.RESTAdapter = _rest.default;
});
-/**
- @module ember-data
-*/
define('ember-data/-private/adapters/build-url-mixin', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+ exports.__esModule = true;
+
+
var get = _ember.default.get;
/**
WARNING: This interface is likely to change in order to accomodate https://github.com/emberjs/rfcs/pull/4
@@ -82,19 +408,20 @@
default:
return this._buildURL(modelName, id);
}
},
+
/**
@method _buildURL
@private
@param {String} modelName
@param {String} id
@return {String} url
*/
_buildURL: function (modelName, id) {
- var path = undefined;
+ var path = void 0;
var url = [];
var host = get(this, 'host');
var prefix = this.urlPrefix();
if (modelName) {
@@ -117,10 +444,11 @@
}
return url;
},
+
/**
Builds a URL for a `store.findRecord(type, id)` call.
Example:
```app/adapters/user.js
import DS from 'ember-data';
@@ -139,10 +467,11 @@
*/
urlForFindRecord: function (id, modelName, snapshot) {
return this._buildURL(modelName, id);
},
+
/**
Builds a URL for a `store.findAll(type)` call.
Example:
```app/adapters/comment.js
import DS from 'ember-data';
@@ -159,10 +488,11 @@
*/
urlForFindAll: function (modelName, snapshot) {
return this._buildURL(modelName);
},
+
/**
Builds a URL for a `store.query(type, query)` call.
Example:
```app/adapters/application.js
import DS from 'ember-data';
@@ -185,10 +515,11 @@
*/
urlForQuery: function (query, modelName) {
return this._buildURL(modelName);
},
+
/**
Builds a URL for a `store.queryRecord(type, query)` call.
Example:
```app/adapters/application.js
import DS from 'ember-data';
@@ -206,10 +537,11 @@
*/
urlForQueryRecord: function (query, modelName) {
return this._buildURL(modelName);
},
+
/**
Builds a URL for coalesceing multiple `store.findRecord(type, id)
records into 1 request when the adapter's `coalesceFindRequests`
property is true.
Example:
@@ -230,10 +562,11 @@
*/
urlForFindMany: function (ids, modelName, snapshots) {
return this._buildURL(modelName);
},
+
/**
Builds a URL for fetching a async hasMany relationship when a url
is not provided by the server.
Example:
```app/adapters/application.js
@@ -253,10 +586,11 @@
*/
urlForFindHasMany: function (id, modelName, snapshot) {
return this._buildURL(modelName, id);
},
+
/**
Builds a URL for fetching a async belongsTo relationship when a url
is not provided by the server.
Example:
```app/adapters/application.js
@@ -276,10 +610,11 @@
*/
urlForFindBelongsTo: function (id, modelName, snapshot) {
return this._buildURL(modelName, id);
},
+
/**
Builds a URL for a `record.save()` call when the record was created
locally using `store.createRecord()`.
Example:
```app/adapters/application.js
@@ -297,10 +632,11 @@
*/
urlForCreateRecord: function (modelName, snapshot) {
return this._buildURL(modelName);
},
+
/**
Builds a URL for a `record.save()` call when the record has been update locally.
Example:
```app/adapters/application.js
import DS from 'ember-data';
@@ -318,10 +654,11 @@
*/
urlForUpdateRecord: function (id, modelName, snapshot) {
return this._buildURL(modelName, id);
},
+
/**
Builds a URL for a `record.save()` call when the record has been deleted locally.
Example:
```app/adapters/application.js
import DS from 'ember-data';
@@ -339,10 +676,11 @@
*/
urlForDeleteRecord: function (id, modelName, snapshot) {
return this._buildURL(modelName, id);
},
+
/**
@method urlPrefix
@private
@param {String} path
@param {String} parentURL
@@ -362,15 +700,15 @@
// Do nothing, the full host is already included.
return path;
// Absolute path
} else if (path.charAt(0) === '/') {
- return '' + host + path;
- // Relative path
- } else {
- return parentURL + '/' + path;
- }
+ return '' + host + path;
+ // Relative path
+ } else {
+ return parentURL + '/' + path;
+ }
}
// No path provided
var url = [];
if (host) {
@@ -380,10 +718,11 @@
url.push(namespace);
}
return url.join('/');
},
+
/**
Determines the pathname for a given type.
By default, it pluralizes the type's name (for example,
'post' becomes 'posts' and 'person' becomes 'people').
### Pathname customization
@@ -406,12 +745,16 @@
var camelized = _ember.default.String.camelize(modelName);
return _ember.default.String.pluralize(camelized);
}
});
});
-define('ember-data/-private/core', ['exports', 'ember', 'ember-data/version'], function (exports, _ember, _emberDataVersion) {
+define('ember-data/-private/core', ['exports', 'ember', 'ember-data/version'], function (exports, _ember, _version) {
+ 'use strict';
+ exports.__esModule = true;
+
+
/**
@module ember-data
*/
/**
@@ -425,31 +768,33 @@
@property VERSION
@type String
@static
*/
var DS = _ember.default.Namespace.create({
- VERSION: _emberDataVersion.default,
+ VERSION: _version.default,
name: "DS"
});
if (_ember.default.libraries) {
_ember.default.libraries.registerCoreLibrary('Ember Data', DS.VERSION);
}
exports.default = DS;
});
define('ember-data/-private/debug', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.assert = assert;
exports.debug = debug;
exports.deprecate = deprecate;
exports.info = info;
exports.runInDebug = runInDebug;
exports.instrument = instrument;
exports.warn = warn;
exports.debugSeal = debugSeal;
exports.assertPolymorphicType = assertPolymorphicType;
-
function assert() {
return _ember.default.assert.apply(_ember.default, arguments);
}
function debug() {
@@ -509,11 +854,10 @@
@param {RelationshipMeta} relationshipMeta retrieved via
`record.relationshipFor(key)`
@param {InternalModel} addedRecord record which
should be added/set for the relationship
*/
-
function assertPolymorphicType(parentInternalModel, relationshipMeta, addedInternalModel) {
var addedModelName = addedInternalModel.modelName;
var parentModelName = parentInternalModel.modelName;
var key = relationshipMeta.key;
var relationshipModelName = relationshipMeta.type;
@@ -521,12 +865,17 @@
var assertionMessage = 'You cannot add a record of modelClass \'' + addedModelName + '\' to the \'' + parentModelName + '.' + key + '\' relationship (only \'' + relationshipModelName + '\' allowed)';
assert(assertionMessage, checkPolymorphic(relationshipClass, addedInternalModel.modelClass));
}
});
-define('ember-data/-private/ext/date', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
+define('ember-data/-private/ext/date', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _debug) {
+ 'use strict';
+ exports.__esModule = true;
+ exports.parseDate = undefined;
+
+
/**
Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
© 2011 Colin Snover <http://zetafleet.com>
@@ -535,27 +884,31 @@
@class Date
@namespace Ember
@static
@deprecated
*/
+ /**
+ @module ember-data
+ */
+
_ember.default.Date = _ember.default.Date || {};
var origParse = Date.parse;
var numericKeys = [1, 4, 5, 6, 7, 10, 11];
- var parseDate = function (date) {
- var timestamp = undefined,
- struct = undefined;
+ var parseDate = exports.parseDate = function (date) {
+ var timestamp = void 0,
+ struct = void 0;
var minutesOffset = 0;
// ES5 §15.9.4.2 states that the string should attempt to be parsed as a Date Time String Format string
// before falling back to any implementation-specific date parsing, so that’s what we do, even if native
// implementations could be faster
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
if (struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2}):?(?:(\d{2}))?)?)?$/.exec(date)) {
// avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
- for (var i = 0, k = undefined; k = numericKeys[i]; ++i) {
+ for (var i = 0, k; k = numericKeys[i]; ++i) {
struct[k] = +struct[k] || 0;
}
// allow undefined days and months
struct[2] = (+struct[2] || 1) - 1;
@@ -575,35 +928,35 @@
}
return timestamp;
};
- exports.parseDate = parseDate;
_ember.default.Date.parse = function (date) {
return parseDate(date);
-
// throw deprecation
};
if (_ember.default.EXTEND_PROTOTYPES === true || _ember.default.EXTEND_PROTOTYPES.Date) {
Date.parse = parseDate;
}
});
-/**
- @module ember-data
-*/
define('ember-data/-private/features', ['exports', 'ember'], function (exports, _ember) {
- exports.default = isEnabled;
+ 'use strict';
+ exports.__esModule = true;
+ exports.default = isEnabled;
function isEnabled() {
var _Ember$FEATURES;
return (_Ember$FEATURES = _ember.default.FEATURES).isEnabled.apply(_Ember$FEATURES, arguments);
}
});
define('ember-data/-private/global', ['exports'], function (exports) {
+ 'use strict';
+
+ exports.__esModule = true;
/* globals global, window, self */
// originally from https://github.com/emberjs/ember.js/blob/c0bd26639f50efd6a03ee5b87035fd200e313b8e/packages/ember-environment/lib/global.js
// from lodash to catch fake globals
@@ -616,49 +969,57 @@
return value && value.nodeType === undefined ? value : undefined;
}
// export real global
exports.default = checkGlobal(checkElementIdShadowing(typeof global === 'object' && global)) || checkGlobal(typeof self === 'object' && self) || checkGlobal(typeof window === 'object' && window) || new Function('return this')();
- // eval outside of strict mode
});
-define("ember-data/-private/initializers/data-adapter", ["exports", "ember-data/-private/system/debug/debug-adapter"], function (exports, _emberDataPrivateSystemDebugDebugAdapter) {
+define("ember-data/-private/initializers/data-adapter", ["exports", "ember-data/-private/system/debug/debug-adapter"], function (exports, _debugAdapter) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = initializeDebugAdapter;
+
/*
Configures a registry with injections on Ember applications
for the Ember-Data store. Accepts an optional namespace argument.
@method initializeDebugAdapter
@param {Ember.Registry} registry
*/
-
function initializeDebugAdapter(registry) {
- registry.register('data-adapter:main', _emberDataPrivateSystemDebugDebugAdapter.default);
+ registry.register('data-adapter:main', _debugAdapter.default);
}
});
define('ember-data/-private/initializers/store-injections', ['exports'], function (exports) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = initializeStoreInjections;
/*
Configures a registry with injections on Ember applications
for the Ember-Data store. Accepts an optional namespace argument.
@method initializeStoreInjections
@param {Ember.Registry} registry
*/
-
function initializeStoreInjections(registry) {
// registry.injection for Ember < 2.1.0
// application.inject for Ember 2.1.0+
var inject = registry.inject || registry.injection;
inject.call(registry, 'controller', 'store', 'service:store');
inject.call(registry, 'route', 'store', 'service:store');
inject.call(registry, 'data-adapter', 'store', 'service:store');
}
});
-define("ember-data/-private/initializers/store", ["exports", "ember-data/-private/system/store", "ember-data/-private/serializers", "ember-data/-private/adapters"], function (exports, _emberDataPrivateSystemStore, _emberDataPrivateSerializers, _emberDataPrivateAdapters) {
+define("ember-data/-private/initializers/store", ["exports", "ember-data/-private/system/store", "ember-data/-private/serializers", "ember-data/-private/adapters"], function (exports, _store, _serializers, _adapters) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = initializeStore;
+
function has(applicationOrRegistry, fullName) {
if (applicationOrRegistry.has) {
// < 2.1.0
return applicationOrRegistry.has(fullName);
} else {
@@ -672,59 +1033,63 @@
store. Accepts an optional namespace argument.
@method initializeStore
@param {Ember.Registry} registry
*/
-
function initializeStore(registry) {
// registry.optionsForType for Ember < 2.1.0
// application.registerOptionsForType for Ember 2.1.0+
var registerOptionsForType = registry.registerOptionsForType || registry.optionsForType;
registerOptionsForType.call(registry, 'serializer', { singleton: false });
registerOptionsForType.call(registry, 'adapter', { singleton: false });
- registry.register('serializer:-default', _emberDataPrivateSerializers.JSONSerializer);
- registry.register('serializer:-rest', _emberDataPrivateSerializers.RESTSerializer);
- registry.register('adapter:-rest', _emberDataPrivateAdapters.RESTAdapter);
+ registry.register('serializer:-default', _serializers.JSONSerializer);
+ registry.register('serializer:-rest', _serializers.RESTSerializer);
+ registry.register('adapter:-rest', _adapters.RESTAdapter);
- registry.register('adapter:-json-api', _emberDataPrivateAdapters.JSONAPIAdapter);
- registry.register('serializer:-json-api', _emberDataPrivateSerializers.JSONAPISerializer);
+ registry.register('adapter:-json-api', _adapters.JSONAPIAdapter);
+ registry.register('serializer:-json-api', _serializers.JSONAPISerializer);
if (!has(registry, 'service:store')) {
- registry.register('service:store', _emberDataPrivateSystemStore.default);
+ registry.register('service:store', _store.default);
}
}
});
-define('ember-data/-private/initializers/transforms', ['exports', 'ember-data/-private/transforms'], function (exports, _emberDataPrivateTransforms) {
+define('ember-data/-private/initializers/transforms', ['exports', 'ember-data/-private/transforms'], function (exports, _transforms) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = initializeTransforms;
+
/*
Configures a registry for use with Ember-Data
transforms.
@method initializeTransforms
@param {Ember.Registry} registry
*/
-
function initializeTransforms(registry) {
- registry.register('transform:boolean', _emberDataPrivateTransforms.BooleanTransform);
- registry.register('transform:date', _emberDataPrivateTransforms.DateTransform);
- registry.register('transform:number', _emberDataPrivateTransforms.NumberTransform);
- registry.register('transform:string', _emberDataPrivateTransforms.StringTransform);
+ registry.register('transform:boolean', _transforms.BooleanTransform);
+ registry.register('transform:date', _transforms.DateTransform);
+ registry.register('transform:number', _transforms.NumberTransform);
+ registry.register('transform:string', _transforms.StringTransform);
}
});
-define('ember-data/-private/instance-initializers/initialize-store-service', ['exports', 'ember-data/-private/debug'], function (exports, _emberDataPrivateDebug) {
+define('ember-data/-private/instance-initializers/initialize-store-service', ['exports', 'ember-data/-private/debug'], function (exports, _debug) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = initializeStoreService;
/*
Configures a registry for use with an Ember-Data
store.
@method initializeStoreService
@param {Ember.ApplicationInstance} applicationOrRegistry
*/
-
function initializeStoreService(application) {
var container = application.lookup ? application : application.container;
// Eagerly generate the store so defaultStore is populated.
container.lookup('service:store');
@@ -759,71 +1124,71 @@
var deprecatedBeforeInitializer = matchesDeprecatedInititalizer(initializer.before);
var deprecatedAfterInitializer = matchesDeprecatedInititalizer(initializer.after);
var deprecatedProp = deprecatedBeforeInitializer ? 'before' : 'after';
}
});
-define("ember-data/-private/serializers", ["exports", "ember-data/serializers/json-api", "ember-data/serializers/json", "ember-data/serializers/rest"], function (exports, _emberDataSerializersJsonApi, _emberDataSerializersJson, _emberDataSerializersRest) {
- exports.JSONAPISerializer = _emberDataSerializersJsonApi.default;
- exports.JSONSerializer = _emberDataSerializersJson.default;
- exports.RESTSerializer = _emberDataSerializersRest.default;
+define("ember-data/-private/serializers", ["exports", "ember-data/serializers/json-api", "ember-data/serializers/json", "ember-data/serializers/rest"], function (exports, _jsonApi, _json, _rest) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.RESTSerializer = exports.JSONSerializer = exports.JSONAPISerializer = undefined;
+ exports.JSONAPISerializer = _jsonApi.default;
+ exports.JSONSerializer = _json.default;
+ exports.RESTSerializer = _rest.default;
});
-/**
- @module ember-data
-*/
-define("ember-data/-private/system/clone-null", ["exports", "ember-data/-private/system/empty-object"], function (exports, _emberDataPrivateSystemEmptyObject) {
- exports.default = cloneNull;
+define("ember-data/-private/system/clone-null", ["exports", "ember-data/-private/system/empty-object"], function (exports, _emptyObject) {
+ "use strict";
+ exports.__esModule = true;
+ exports.default = cloneNull;
function cloneNull(source) {
- var clone = new _emberDataPrivateSystemEmptyObject.default();
+ var clone = new _emptyObject.default();
for (var key in source) {
clone[key] = source[key];
}
return clone;
}
});
define('ember-data/-private/system/coerce-id', ['exports'], function (exports) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = coerceId;
// Used by the store to normalize IDs entering the store. Despite the fact
// that developers may provide IDs as numbers (e.g., `store.findRecord('person', 1)`),
// it is important that internally we use strings, since IDs may be serialized
// and lose type information. For example, Ember's router may put a record's
// ID into the URL, and if we later try to deserialize that URL and find the
// corresponding record, we will not know if it is a string or a number.
-
function coerceId(id) {
return id === null || id === undefined || id === '' ? null : id + '';
}
});
-define("ember-data/-private/system/debug", ["exports", "ember-data/-private/system/debug/debug-adapter"], function (exports, _emberDataPrivateSystemDebugDebugAdapter) {
- exports.default = _emberDataPrivateSystemDebugDebugAdapter.default;
+define("ember-data/-private/system/debug", ["exports", "ember-data/-private/system/debug/debug-adapter"], function (exports, _debugAdapter) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.default = _debugAdapter.default;
});
-/**
- @module ember-data
-*/
-define('ember-data/-private/system/debug/debug-adapter', ['exports', 'ember', 'ember-data/model'], function (exports, _ember, _emberDataModel) {
- var capitalize = _ember.default.String.capitalize;
- var underscore = _ember.default.String.underscore;
- var assert = _ember.default.assert;
- var get = _ember.default.get;
+define('ember-data/-private/system/debug/debug-adapter', ['exports', 'ember', 'ember-data/model'], function (exports, _ember, _model) {
+ 'use strict';
- /*
- Extend `Ember.DataAdapter` with ED specific code.
-
- @class DebugAdapter
- @namespace DS
- @extends Ember.DataAdapter
- @private
+ exports.__esModule = true;
+ /**
+ @module ember-data
*/
+ var capitalize = _ember.default.String.capitalize;
+ var underscore = _ember.default.String.underscore;
+ var assert = _ember.default.assert,
+ get = _ember.default.get;
exports.default = _ember.default.DataAdapter.extend({
getFilters: function () {
return [{ name: 'isNew', desc: 'New' }, { name: 'isModified', desc: 'Modified' }, { name: 'isClean', desc: 'Clean' }];
},
-
detect: function (typeClass) {
- return typeClass !== _emberDataModel.default && _emberDataModel.default.detect(typeClass);
+ return typeClass !== _model.default && _model.default.detect(typeClass);
},
-
columnsForType: function (typeClass) {
var columns = [{
name: 'id',
desc: 'Id'
}];
@@ -836,11 +1201,10 @@
var desc = capitalize(underscore(name).replace('_', ' '));
columns.push({ name: name, desc: desc });
});
return columns;
},
-
getRecords: function (modelClass, modelName) {
if (arguments.length < 2) {
// Legacy Ember.js < 1.13 support
var containerKey = modelClass._debugContainerKey;
if (containerKey) {
@@ -851,11 +1215,10 @@
}
}
assert("Cannot find model name. Please upgrade to Ember.js >= 1.13 for Ember Inspector support", !!modelName);
return this.get('store').peekAll(modelName);
},
-
getRecordColumnValues: function (record) {
var _this = this;
var count = 0;
var columnValues = { id: get(record, 'id') };
@@ -866,11 +1229,10 @@
}
columnValues[key] = get(record, key);
});
return columnValues;
},
-
getRecordKeywords: function (record) {
var keywords = [];
var keys = _ember.default.A(['id']);
record.eachAttribute(function (key) {
return keys.push(key);
@@ -878,29 +1240,26 @@
keys.forEach(function (key) {
return keywords.push(get(record, key));
});
return keywords;
},
-
getRecordFilterValues: function (record) {
return {
isNew: record.get('isNew'),
isModified: record.get('hasDirtyAttributes') && !record.get('isNew'),
isClean: !record.get('hasDirtyAttributes')
};
},
-
getRecordColor: function (record) {
var color = 'black';
if (record.get('isNew')) {
color = 'green';
} else if (record.get('hasDirtyAttributes')) {
color = 'blue';
}
return color;
},
-
observeRecord: function (record, recordUpdated) {
var releaseMethods = _ember.default.A();
var keysToObserve = _ember.default.A(['id', 'isNew', 'hasDirtyAttributes']);
record.eachAttribute(function (key) {
@@ -926,14 +1285,14 @@
return release;
}
});
});
-/**
- @module ember-data
-*/
define("ember-data/-private/system/diff-array", ["exports"], function (exports) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = diffArray;
/**
@namespace
@method diff-array
@for DS
@@ -943,11 +1302,10 @@
firstChangeIndex: <integer>, // null if no change
addedCount: <integer>, // 0 if no change
removedCount: <integer> // 0 if no change
}
*/
-
function diffArray(oldArray, newArray) {
var oldLength = oldArray.length;
var newLength = newArray.length;
var shortestLength = Math.min(oldLength, newLength);
@@ -973,14 +1331,14 @@
var removedCount = 0;
if (firstChangeIndex !== null) {
// we found a change, find the end of the change
var unchangedEndBlockLength = shortestLength - firstChangeIndex;
// walk back from the end of both arrays until we find a change
- for (var i = 1; i <= shortestLength; i++) {
+ for (var _i = 1; _i <= shortestLength; _i++) {
// compare each item in the array
- if (oldArray[oldLength - i] !== newArray[newLength - i]) {
- unchangedEndBlockLength = i - 1;
+ if (oldArray[oldLength - _i] !== newArray[newLength - _i]) {
+ unchangedEndBlockLength = _i - 1;
break;
}
}
addedCount = newLength - unchangedEndBlockLength - firstChangeIndex;
removedCount = oldLength - unchangedEndBlockLength - firstChangeIndex;
@@ -992,10 +1350,13 @@
removedCount: removedCount
};
}
});
define("ember-data/-private/system/empty-object", ["exports"], function (exports) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = EmptyObject;
// This exists because `Object.create(null)` is absurdly slow compared
// to `new EmptyObject()`. In either case, you want a null prototype
// when you're treating the object instances as arbitrary dictionaries
// and don't want your keys colliding with build-in methods on the
@@ -1009,27 +1370,24 @@
writable: true
}
});
function EmptyObject() {}
-
EmptyObject.prototype = proto;
});
-define('ember-data/-private/system/identity-map', ['exports', 'ember-data/-private/system/internal-model-map'], function (exports, _emberDataPrivateSystemInternalModelMap) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define('ember-data/-private/system/identity-map', ['exports', 'ember-data/-private/system/internal-model-map'], function (exports, _internalModelMap) {
+ 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ exports.__esModule = true;
- /**
- `IdentityMap` is a custom storage map for records by modelName
- used by `DS.Store`.
-
- @class IdentityMap
- @private
- */
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- var IdentityMap = (function () {
+ var IdentityMap = function () {
function IdentityMap() {
this._map = Object.create(null);
}
/**
@@ -1039,62 +1397,66 @@
@method retrieve
@param modelName a previously normalized modelName
@returns {InternalModelMap} the InternalModelMap for the given modelName
*/
- _createClass(IdentityMap, [{
- key: 'retrieve',
- value: function retrieve(modelName) {
- var map = this._map[modelName];
- if (!map) {
- map = this._map[modelName] = new _emberDataPrivateSystemInternalModelMap.default(modelName);
- }
+ IdentityMap.prototype.retrieve = function retrieve(modelName) {
+ var map = this._map[modelName];
- return map;
+ if (!map) {
+ map = this._map[modelName] = new _internalModelMap.default(modelName);
}
- /**
- Clears the contents of all known `RecordMaps`, but does
- not remove the InternalModelMap instances.
- @method clear
- */
- }, {
- key: 'clear',
- value: function clear() {
- var map = this._map;
- var keys = Object.keys(map);
+ return map;
+ };
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- map[key].clear();
- }
+ IdentityMap.prototype.clear = function clear() {
+ var map = this._map;
+ var keys = Object.keys(map);
+
+ for (var i = 0; i < keys.length; i++) {
+ var key = keys[i];
+ map[key].clear();
}
- }]);
+ };
return IdentityMap;
- })();
+ }();
exports.default = IdentityMap;
});
-define('ember-data/-private/system/internal-model-map', ['exports', 'ember-data/-private/debug', 'ember-data/-private/system/model/internal-model'], function (exports, _emberDataPrivateDebug, _emberDataPrivateSystemModelInternalModel) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define('ember-data/-private/system/internal-model-map', ['exports', 'ember-data/-private/debug', 'ember-data/-private/system/model/internal-model'], function (exports, _debug, _internalModel) {
+ 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ exports.__esModule = true;
- /**
- `InternalModelMap` is a custom storage map for internalModels of a given modelName
- used by `IdentityMap`.
-
- It was extracted from an implicit pojo based "internalModel map" and preserves
- that interface while we work towards a more official API.
-
- @class InternalModelMap
- @private
- */
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- var InternalModelMap = (function () {
+ var _createClass = function () {
+ function defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
+ }
+
+ return function (Constructor, protoProps, staticProps) {
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) defineProperties(Constructor, staticProps);
+ return Constructor;
+ };
+ }();
+
+ var InternalModelMap = function () {
function InternalModelMap(modelName) {
this.modelName = modelName;
this._idToModel = Object.create(null);
this._models = [];
this._metadata = null;
@@ -1102,92 +1464,70 @@
/**
A "map" of records based on their ID for this modelName
*/
- _createClass(InternalModelMap, [{
- key: 'get',
- /**
- *
- * @param id
- * @returns {InternalModel}
- */
- value: function get(id) {
- var r = this._idToModel[id];
- return r;
- }
- }, {
- key: 'has',
- value: function has(id) {
- return !!this._idToModel[id];
- }
- }, {
- key: 'set',
- value: function set(id, internalModel) {
+ InternalModelMap.prototype.get = function get(id) {
+ var r = this._idToModel[id];
+ return r;
+ };
+ InternalModelMap.prototype.has = function has(id) {
+ return !!this._idToModel[id];
+ };
+
+ InternalModelMap.prototype.set = function set(id, internalModel) {
+
+ this._idToModel[id] = internalModel;
+ };
+
+ InternalModelMap.prototype.add = function add(internalModel, id) {
+
+ if (id) {
this._idToModel[id] = internalModel;
}
- }, {
- key: 'add',
- value: function add(internalModel, id) {
- if (id) {
- this._idToModel[id] = internalModel;
- }
+ this._models.push(internalModel);
+ };
- this._models.push(internalModel);
+ InternalModelMap.prototype.remove = function remove(internalModel, id) {
+ if (id) {
+ delete this._idToModel[id];
}
- }, {
- key: 'remove',
- value: function remove(internalModel, id) {
- if (id) {
- delete this._idToModel[id];
- }
- var loc = this._models.indexOf(internalModel);
+ var loc = this._models.indexOf(internalModel);
- if (loc !== -1) {
- this._models.splice(loc, 1);
- }
+ if (loc !== -1) {
+ this._models.splice(loc, 1);
}
- }, {
- key: 'contains',
- value: function contains(internalModel) {
- return this._models.indexOf(internalModel) !== -1;
- }
+ };
- /**
- An array of all models of this modelName
- */
- }, {
- key: 'clear',
+ InternalModelMap.prototype.contains = function contains(internalModel) {
+ return this._models.indexOf(internalModel) !== -1;
+ };
- /**
- Destroy all models in the internalModelTest and wipe metadata.
- @method clear
- */
- value: function clear() {
- if (this._models) {
- var models = this._models;
- this._models = [];
+ InternalModelMap.prototype.clear = function clear() {
+ if (this._models) {
+ var models = this._models;
+ this._models = [];
- for (var i = 0; i < models.length; i++) {
- var model = models[i];
- model.unloadRecord();
- }
+ for (var i = 0; i < models.length; i++) {
+ var model = models[i];
+ model.unloadRecord();
}
-
- this._metadata = null;
}
- }, {
- key: 'destroy',
- value: function destroy() {
- this._store = null;
- this._modelClass = null;
- }
- }, {
+
+ this._metadata = null;
+ };
+
+ InternalModelMap.prototype.destroy = function destroy() {
+ this._store = null;
+ this._modelClass = null;
+ };
+
+ _createClass(InternalModelMap, [{
key: 'idToRecord',
get: function () {
return this._idToModel;
}
}, {
@@ -1198,50 +1538,44 @@
}, {
key: 'models',
get: function () {
return this._models;
}
-
- /**
- * meta information about internalModels
- */
}, {
key: 'metadata',
get: function () {
return this._metadata || (this._metadata = Object.create(null));
}
-
- /**
- deprecated (and unsupported) way of accessing modelClass
- @deprecated
- */
}, {
key: 'type',
get: function () {
throw new Error('InternalModelMap.type is no longer available');
}
}]);
return InternalModelMap;
- })();
+ }();
exports.default = InternalModelMap;
});
define('ember-data/-private/system/is-array-like', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = isArrayLike;
+
/*
We're using this to detect arrays and "array-like" objects.
This is a copy of the `isArray` method found in `ember-runtime/utils` as we're
currently unable to import non-exposed modules.
This method was previously exposed as `Ember.isArray` but since
https://github.com/emberjs/ember.js/pull/11463 `Ember.isArray` is an alias of
`Array.isArray` hence removing the "array-like" part.
*/
-
function isArrayLike(obj) {
if (!obj || obj.setInterval) {
return false;
}
if (Array.isArray(obj)) {
@@ -1259,57 +1593,16 @@
return true;
}
return false;
}
});
-define("ember-data/-private/system/many-array", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/store/common", "ember-data/-private/system/diff-array"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemStoreCommon, _emberDataPrivateSystemDiffArray) {
- var get = _ember.default.get;
- var set = _ember.default.set;
+define("ember-data/-private/system/many-array", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/store/common", "ember-data/-private/system/diff-array"], function (exports, _ember, _debug, _promiseProxies, _common, _diffArray) {
+ "use strict";
- /**
- A `ManyArray` is a `MutableArray` that represents the contents of a has-many
- relationship.
-
- The `ManyArray` is instantiated lazily the first time the relationship is
- requested.
-
- ### Inverses
-
- Often, the relationships in Ember Data applications will have
- an inverse. For example, imagine the following models are
- defined:
-
- ```app/models/post.js
- import DS from 'ember-data';
-
- export default DS.Model.extend({
- comments: DS.hasMany('comment')
- });
- ```
-
- ```app/models/comment.js
- import DS from 'ember-data';
-
- export default DS.Model.extend({
- post: DS.belongsTo('post')
- });
- ```
-
- If you created a new instance of `App.Post` and added
- a `App.Comment` record to its `comments` has-many
- relationship, you would expect the comment's `post`
- property to be set to the post that contained
- the has-many.
-
- We call the record to which a relationship belongs the
- relationship's _owner_.
-
- @class ManyArray
- @namespace DS
- @extends Ember.Object
- @uses Ember.MutableArray, Ember.Evented
- */
+ exports.__esModule = true;
+ var get = _ember.default.get,
+ set = _ember.default.set;
exports.default = _ember.default.Object.extend(_ember.default.MutableArray, _ember.default.Evented, {
init: function () {
this._super.apply(this, arguments);
/**
@@ -1374,26 +1667,24 @@
this.relationship = this.relationship || null;
this.currentState = [];
this.flushCanonical(false);
},
-
objectAt: function (index) {
var object = this.currentState[index];
//Ember observers such as 'firstObject', 'lastObject' might do out of bounds accesses
if (object === undefined) {
return;
}
return object.getRecord();
},
-
flushCanonical: function () {
- var isInitialized = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
+ var isInitialized = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
// It’s possible the parent side of the relationship may have been unloaded by this point
- if (!(0, _emberDataPrivateSystemStoreCommon._objectIsAlive)(this)) {
+ if (!(0, _common._objectIsAlive)(this)) {
return;
}
var toSet = this.canonicalState;
//a hack for not removing new records
@@ -1406,11 +1697,11 @@
return internalModel.isNew() && toSet.indexOf(internalModel) === -1;
});
toSet = toSet.concat(newRecords);
// diff to find changes
- var diff = (0, _emberDataPrivateSystemDiffArray.default)(this.currentState, toSet);
+ var diff = (0, _diffArray.default)(this.currentState, toSet);
if (diff.firstChangeIndex !== null) {
// it's null if no change found
// we found a change
this.arrayContentWillChange(diff.firstChangeIndex, diff.removedCount, diff.addedCount);
@@ -1422,39 +1713,39 @@
//TODO only notify if unloaded
this.relationship.notifyHasManyChanged();
}
}
},
-
internalReplace: function (idx, amt, objects) {
if (!objects) {
objects = [];
}
this.arrayContentWillChange(idx, amt, objects.length);
this.currentState.splice.apply(this.currentState, [idx, amt].concat(objects));
this.set('length', this.currentState.length);
this.arrayContentDidChange(idx, amt, objects.length);
},
+
//TODO(Igor) optimize
internalRemoveRecords: function (records) {
for (var i = 0; i < records.length; i++) {
var index = this.currentState.indexOf(records[i]);
this.internalReplace(index, 1);
}
},
+
//TODO(Igor) optimize
internalAddRecords: function (records, idx) {
if (idx === undefined) {
idx = this.currentState.length;
}
this.internalReplace(idx, 0, records);
},
-
replace: function (idx, amt, objects) {
- var records = undefined;
+ var records = void 0;
if (amt > 0) {
records = this.currentState.slice(idx, idx + amt);
this.get('relationship').removeRecords(records);
}
if (objects) {
@@ -1462,19 +1753,21 @@
return obj._internalModel;
}), idx);
}
},
+
/**
@method loadingRecordsCount
@param {Number} count
@private
*/
loadingRecordsCount: function (count) {
this._loadingRecordsCount = count;
},
+
/**
@method loadedRecord
@private
*/
loadedRecord: function () {
@@ -1483,10 +1776,11 @@
set(this, 'isLoaded', true);
this.trigger('didLoad');
}
},
+
/**
Reloads all of the records in the manyArray. If the manyArray
holds a relationship that was originally fetched using a links url
Ember Data will revisit the original links url to repopulate the
relationship.
@@ -1506,10 +1800,11 @@
*/
reload: function () {
return this.relationship.reload();
},
+
/**
Saves all of the records in the `ManyArray`.
Example
```javascript
store.findRecord('inbox', 1).then(function(inbox) {
@@ -1529,13 +1824,14 @@
var promiseLabel = 'DS: ManyArray#save ' + get(this, 'type');
var promise = _ember.default.RSVP.all(this.invoke("save"), promiseLabel).then(function () {
return manyArray;
}, null, 'DS: ManyArray#save return ManyArray');
- return _emberDataPrivateSystemPromiseProxies.PromiseArray.create({ promise: promise });
+ return _promiseProxies.PromiseArray.create({ promise: promise });
},
+
/**
Create a child record within the owner
@method createRecord
@private
@param {Object} hash
@@ -1550,24 +1846,26 @@
return record;
}
});
});
-/**
- @module ember-data
-*/
-define("ember-data/-private/system/model", ["exports", "ember-data/-private/system/model/model", "ember-data/attr", "ember-data/-private/system/model/states", "ember-data/-private/system/model/errors"], function (exports, _emberDataPrivateSystemModelModel, _emberDataAttr, _emberDataPrivateSystemModelStates, _emberDataPrivateSystemModelErrors) {
- exports.RootState = _emberDataPrivateSystemModelStates.default;
- exports.attr = _emberDataAttr.default;
- exports.Errors = _emberDataPrivateSystemModelErrors.default;
- exports.default = _emberDataPrivateSystemModelModel.default;
+define("ember-data/-private/system/model", ["exports", "ember-data/-private/system/model/model", "ember-data/attr", "ember-data/-private/system/model/states", "ember-data/-private/system/model/errors"], function (exports, _model, _attr, _states, _errors) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.Errors = exports.attr = exports.RootState = undefined;
+ exports.RootState = _states.default;
+ exports.attr = _attr.default;
+ exports.Errors = _errors.default;
+ exports.default = _model.default;
});
-/**
- @module ember-data
-*/
-define('ember-data/-private/system/model/errors', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
+define('ember-data/-private/system/model/errors', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _debug) {
+ 'use strict';
+ exports.__esModule = true;
+
+
var get = _ember.default.get;
var set = _ember.default.set;
var isEmpty = _ember.default.isEmpty;
var makeArray = _ember.default.makeArray;
@@ -1664,20 +1962,22 @@
registerHandlers: function (target, becameInvalid, becameValid) {
this._registerHandlers(target, becameInvalid, becameValid);
},
+
/**
Register with target handler
@method _registerHandlers
@private
*/
_registerHandlers: function (target, becameInvalid, becameValid) {
this.on('becameInvalid', target, becameInvalid);
this.on('becameValid', target, becameValid);
},
+
/**
@property errorsByAttributeName
@type {Ember.MapWithDefault}
@private
*/
@@ -1707,10 +2007,11 @@
*/
errorsFor: function (attribute) {
return get(this, 'errorsByAttributeName').get(attribute);
},
+
/**
An array containing all of the error messages for this
record. This is useful for displaying all errors to the user.
```handlebars
{{#each model.errors.messages as |message|}}
@@ -1743,10 +2044,11 @@
return null;
}
return errors;
},
+
/**
Total number of errors.
@property length
@type {Number}
@readOnly
@@ -1782,10 +2084,11 @@
if (wasEmpty && !get(this, 'isEmpty')) {
this.trigger('becameInvalid');
}
},
+
/**
Adds error messages to a given attribute without sending event.
@method _add
@private
*/
@@ -1795,10 +2098,11 @@
get(this, 'errorsByAttributeName').get(attribute).addObjects(messages);
this.notifyPropertyChange(attribute);
},
+
/**
@method _findOrCreateMessages
@private
*/
_findOrCreateMessages: function (attribute, messages) {
@@ -1820,10 +2124,11 @@
}
return _messages;
},
+
/**
Removes all error messages from the given attribute and sends
`becameValid` event to the record if there no more errors left.
Example:
```app/models/user.js
@@ -1862,10 +2167,11 @@
if (get(this, 'isEmpty')) {
this.trigger('becameValid');
}
},
+
/**
Removes all error messages from the given attribute without sending event.
@method _remove
@private
*/
@@ -1879,10 +2185,11 @@
get(this, 'errorsByAttributeName').delete(attribute);
this.notifyPropertyChange(attribute);
},
+
/**
Removes all error messages and sends `becameValid` event
to the record.
Example:
```app/routes/user/edit.js
@@ -1907,10 +2214,11 @@
this._clear();
this.trigger('becameValid');
},
+
/**
Removes all error messages.
to the record.
@method _clear
@private
@@ -1933,10 +2241,11 @@
}, this);
_ember.default.ArrayProxy.prototype.clear.call(this);
},
+
/**
Checks if there is error messages for the given attribute.
```app/routes/user/edit.js
import Ember from 'ember';
export default Ember.Route.extend({
@@ -1957,26 +2266,51 @@
has: function (attribute) {
return !isEmpty(this.errorsFor(attribute));
}
});
});
-define("ember-data/-private/system/model/internal-model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/model/states", "ember-data/-private/system/relationships/state/create", "ember-data/-private/system/snapshot", "ember-data/-private/system/empty-object", "ember-data/-private/features", "ember-data/-private/system/ordered-set", "ember-data/-private/utils", "ember-data/-private/system/references"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemModelStates, _emberDataPrivateSystemRelationshipsStateCreate, _emberDataPrivateSystemSnapshot, _emberDataPrivateSystemEmptyObject, _emberDataPrivateFeatures, _emberDataPrivateSystemOrderedSet, _emberDataPrivateUtils, _emberDataPrivateSystemReferences) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define("ember-data/-private/system/model/internal-model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/model/states", "ember-data/-private/system/relationships/state/create", "ember-data/-private/system/snapshot", "ember-data/-private/system/empty-object", "ember-data/-private/features", "ember-data/-private/system/ordered-set", "ember-data/-private/utils", "ember-data/-private/system/references"], function (exports, _ember, _debug, _states, _create, _snapshot, _emptyObject, _features, _orderedSet, _utils, _references) {
+ "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+ exports.__esModule = true;
- var get = _ember.default.get;
- var set = _ember.default.set;
- var copy = _ember.default.copy;
- var EmberError = _ember.default.Error;
- var inspect = _ember.default.inspect;
- var isEmpty = _ember.default.isEmpty;
- var isEqual = _ember.default.isEqual;
- var setOwner = _ember.default.setOwner;
- var RSVP = _ember.default.RSVP;
- var Promise = _ember.default.RSVP.Promise;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+ var _createClass = function () {
+ function defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
+ }
+
+ return function (Constructor, protoProps, staticProps) {
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) defineProperties(Constructor, staticProps);
+ return Constructor;
+ };
+ }();
+
+ var get = _ember.default.get,
+ set = _ember.default.set,
+ copy = _ember.default.copy,
+ EmberError = _ember.default.Error,
+ inspect = _ember.default.inspect,
+ isEmpty = _ember.default.isEmpty,
+ isEqual = _ember.default.isEqual,
+ setOwner = _ember.default.setOwner,
+ RSVP = _ember.default.RSVP,
+ Promise = _ember.default.RSVP.Promise;
+
+
var assign = _ember.default.assign || _ember.default.merge;
/*
The TransitionChainMap caches the `state.enters`, `state.setups`, and final state reached
when transitioning from one state to another, so that future transitions can replay the
@@ -1985,14 +2319,14 @@
A future optimization would be to build a single chained method out of the collected enters
and setups. It may also be faster to do a two level cache (from: { to }) instead of caching based
on a key that adds the two together.
*/
- var TransitionChainMap = new _emberDataPrivateSystemEmptyObject.default();
+ var TransitionChainMap = new _emptyObject.default();
- var _extractPivotNameCache = new _emberDataPrivateSystemEmptyObject.default();
- var _splitOnDotCache = new _emberDataPrivateSystemEmptyObject.default();
+ var _extractPivotNameCache = new _emptyObject.default();
+ var _splitOnDotCache = new _emptyObject.default();
function splitOnDot(name) {
return _splitOnDotCache[name] || (_splitOnDotCache[name] = name.split('.'));
}
@@ -2011,10 +2345,11 @@
}
// this (and all heimdall instrumentation) will be stripped by a babel transform
// https://github.com/heimdalljs/babel5-plugin-strip-heimdall
+
var InternalModelReferenceId = 1;
var nextBfsId = 1;
/*
`InternalModel` is the Model class that we use internally inside Ember Data to represent models.
@@ -2031,11 +2366,11 @@
@private
@class InternalModel
*/
- var InternalModel = (function () {
+ var InternalModel = function () {
function InternalModel(modelName, id, store, data) {
this.id = id;
this._internalId = InternalModelReferenceId++;
this.store = store;
this.modelName = modelName;
@@ -2070,985 +2405,747 @@
// Used during the mark phase of unloading to avoid checking the same internal
// model twice in the same scan
this._bfsId = 0;
}
- _createClass(InternalModel, [{
- key: "isEmpty",
- value: function isEmpty() {
- return this.currentState.isEmpty;
- }
- }, {
- key: "isLoading",
- value: function isLoading() {
- return this.currentState.isLoading;
- }
- }, {
- key: "isLoaded",
- value: function isLoaded() {
- return this.currentState.isLoaded;
- }
- }, {
- key: "hasDirtyAttributes",
- value: function hasDirtyAttributes() {
- return this.currentState.hasDirtyAttributes;
- }
- }, {
- key: "isSaving",
- value: function isSaving() {
- return this.currentState.isSaving;
- }
- }, {
- key: "isDeleted",
- value: function isDeleted() {
- return this.currentState.isDeleted;
- }
- }, {
- key: "isNew",
- value: function isNew() {
- return this.currentState.isNew;
- }
- }, {
- key: "isValid",
- value: function isValid() {
- return this.currentState.isValid;
- }
- }, {
- key: "dirtyType",
- value: function dirtyType() {
- return this.currentState.dirtyType;
- }
- }, {
- key: "getRecord",
- value: function getRecord() {
- if (!this._record && !this._isDematerializing) {
+ InternalModel.prototype.isEmpty = function isEmpty() {
+ return this.currentState.isEmpty;
+ };
- // lookupFactory should really return an object that creates
- // instances with the injections applied
- var createOptions = {
- store: this.store,
- _internalModel: this,
- id: this.id,
- currentState: this.currentState,
- isError: this.isError,
- adapterError: this.error
- };
+ InternalModel.prototype.isLoading = function isLoading() {
+ return this.currentState.isLoading;
+ };
- if (setOwner) {
- // ensure that `getOwner(this)` works inside a model instance
- setOwner(createOptions, (0, _emberDataPrivateUtils.getOwner)(this.store));
- } else {
- createOptions.container = this.store.container;
- }
+ InternalModel.prototype.isLoaded = function isLoaded() {
+ return this.currentState.isLoaded;
+ };
- this._record = this.store.modelFactoryFor(this.modelName).create(createOptions);
+ InternalModel.prototype.hasDirtyAttributes = function hasDirtyAttributes() {
+ return this.currentState.hasDirtyAttributes;
+ };
- this._triggerDeferredTriggers();
+ InternalModel.prototype.isSaving = function isSaving() {
+ return this.currentState.isSaving;
+ };
+
+ InternalModel.prototype.isDeleted = function isDeleted() {
+ return this.currentState.isDeleted;
+ };
+
+ InternalModel.prototype.isNew = function isNew() {
+ return this.currentState.isNew;
+ };
+
+ InternalModel.prototype.isValid = function isValid() {
+ return this.currentState.isValid;
+ };
+
+ InternalModel.prototype.dirtyType = function dirtyType() {
+ return this.currentState.dirtyType;
+ };
+
+ InternalModel.prototype.getRecord = function getRecord() {
+ if (!this._record && !this._isDematerializing) {
+
+ // lookupFactory should really return an object that creates
+ // instances with the injections applied
+ var createOptions = {
+ store: this.store,
+ _internalModel: this,
+ id: this.id,
+ currentState: this.currentState,
+ isError: this.isError,
+ adapterError: this.error
+ };
+
+ if (setOwner) {
+ // ensure that `getOwner(this)` works inside a model instance
+ setOwner(createOptions, (0, _utils.getOwner)(this.store));
+ } else {
+ createOptions.container = this.store.container;
}
- return this._record;
+ this._record = this.store.modelFactoryFor(this.modelName).create(createOptions);
+
+ this._triggerDeferredTriggers();
}
- }, {
- key: "resetRecord",
- value: function resetRecord() {
- this._record = null;
- this.dataHasInitialized = false;
- this.isReloading = false;
- this.error = null;
- this.currentState = _emberDataPrivateSystemModelStates.default.empty;
- this.__attributes = null;
- this.__inFlightAttributes = null;
- this._data = null;
+
+ return this._record;
+ };
+
+ InternalModel.prototype.resetRecord = function resetRecord() {
+ this._record = null;
+ this.dataHasInitialized = false;
+ this.isReloading = false;
+ this.error = null;
+ this.currentState = _states.default.empty;
+ this.__attributes = null;
+ this.__inFlightAttributes = null;
+ this._data = null;
+ };
+
+ InternalModel.prototype.dematerializeRecord = function dematerializeRecord() {
+ if (this.record) {
+ this._isDematerializing = true;
+ this.record.destroy();
+ this.destroyRelationships();
+ this.updateRecordArrays();
+ this.resetRecord();
}
- }, {
- key: "dematerializeRecord",
- value: function dematerializeRecord() {
- if (this.record) {
- this._isDematerializing = true;
- this.record.destroy();
- this.destroyRelationships();
- this.updateRecordArrays();
- this.resetRecord();
- }
- }
- }, {
- key: "deleteRecord",
- value: function deleteRecord() {
- this.send('deleteRecord');
- }
- }, {
- key: "save",
- value: function save(options) {
- var promiseLabel = "DS: Model#save " + this;
- var resolver = RSVP.defer(promiseLabel);
+ };
- this.store.scheduleSave(this, resolver, options);
- return resolver.promise;
+ InternalModel.prototype.deleteRecord = function deleteRecord() {
+ this.send('deleteRecord');
+ };
+
+ InternalModel.prototype.save = function save(options) {
+ var promiseLabel = "DS: Model#save " + this;
+ var resolver = RSVP.defer(promiseLabel);
+
+ this.store.scheduleSave(this, resolver, options);
+ return resolver.promise;
+ };
+
+ InternalModel.prototype.startedReloading = function startedReloading() {
+ this.isReloading = true;
+ if (this.hasRecord) {
+ set(this.record, 'isReloading', true);
}
- }, {
- key: "startedReloading",
- value: function startedReloading() {
- this.isReloading = true;
- if (this.hasRecord) {
- set(this.record, 'isReloading', true);
- }
- }
- }, {
- key: "finishedReloading",
- value: function finishedReloading() {
- this.isReloading = false;
- if (this.hasRecord) {
- set(this.record, 'isReloading', false);
- }
- }
- }, {
- key: "reload",
- value: function reload() {
- this.startedReloading();
- var internalModel = this;
- var promiseLabel = "DS: Model#reload of " + this;
+ };
- return new Promise(function (resolve) {
- internalModel.send('reloadRecord', resolve);
- }, promiseLabel).then(function () {
- internalModel.didCleanError();
- return internalModel;
- }, function (error) {
- internalModel.didError(error);
- throw error;
- }, "DS: Model#reload complete, update flags").finally(function () {
- internalModel.finishedReloading();
- internalModel.updateRecordArrays();
- });
+ InternalModel.prototype.finishedReloading = function finishedReloading() {
+ this.isReloading = false;
+ if (this.hasRecord) {
+ set(this.record, 'isReloading', false);
}
+ };
- /**
- Computes the set of internal models reachable from `this` across exactly one
- relationship.
- @return {Array} An array containing the internal models that `this` belongs
- to or has many.
- */
- }, {
- key: "_directlyRelatedInternalModels",
- value: function _directlyRelatedInternalModels() {
- var _this = this;
+ InternalModel.prototype.reload = function reload() {
+ this.startedReloading();
+ var internalModel = this;
+ var promiseLabel = "DS: Model#reload of " + this;
- var array = [];
- this.type.eachRelationship(function (key, relationship) {
- if (_this._relationships.has(key)) {
- var _relationship = _this._relationships.get(key);
- var localRelationships = _relationship.members.toArray();
- var serverRelationships = _relationship.canonicalMembers.toArray();
+ return new Promise(function (resolve) {
+ internalModel.send('reloadRecord', resolve);
+ }, promiseLabel).then(function () {
+ internalModel.didCleanError();
+ return internalModel;
+ }, function (error) {
+ internalModel.didError(error);
+ throw error;
+ }, "DS: Model#reload complete, update flags").finally(function () {
+ internalModel.finishedReloading();
+ internalModel.updateRecordArrays();
+ });
+ };
- array = array.concat(localRelationships, serverRelationships);
- }
- });
- return array;
- }
+ InternalModel.prototype._directlyRelatedInternalModels = function _directlyRelatedInternalModels() {
+ var _this = this;
- /**
- Computes the set of internal models reachable from this internal model.
- Reachability is determined over the relationship graph (ie a graph where
- nodes are internal models and edges are belongs to or has many
- relationships).
- @return {Array} An array including `this` and all internal models reachable
- from `this`.
- */
- }, {
- key: "_allRelatedInternalModels",
- value: function _allRelatedInternalModels() {
- var array = [];
- var queue = [];
- var bfsId = nextBfsId++;
- queue.push(this);
- this._bfsId = bfsId;
- while (queue.length > 0) {
- var node = queue.shift();
- array.push(node);
- var related = node._directlyRelatedInternalModels();
- for (var i = 0; i < related.length; ++i) {
- var internalModel = related[i];
+ var array = [];
+ this.type.eachRelationship(function (key, relationship) {
+ if (_this._relationships.has(key)) {
+ var _relationship = _this._relationships.get(key);
+ var localRelationships = _relationship.members.toArray();
+ var serverRelationships = _relationship.canonicalMembers.toArray();
- if (internalModel._bfsId < bfsId) {
- queue.push(internalModel);
- internalModel._bfsId = bfsId;
- }
+ array = array.concat(localRelationships, serverRelationships);
+ }
+ });
+ return array;
+ };
+
+ InternalModel.prototype._allRelatedInternalModels = function _allRelatedInternalModels() {
+ var array = [];
+ var queue = [];
+ var bfsId = nextBfsId++;
+ queue.push(this);
+ this._bfsId = bfsId;
+ while (queue.length > 0) {
+ var node = queue.shift();
+ array.push(node);
+ var related = node._directlyRelatedInternalModels();
+ for (var i = 0; i < related.length; ++i) {
+ var internalModel = related[i];
+
+ if (internalModel._bfsId < bfsId) {
+ queue.push(internalModel);
+ internalModel._bfsId = bfsId;
}
}
- return array;
}
+ return array;
+ };
- /**
- Unload the record for this internal model. This will cause the record to be
- destroyed and freed up for garbage collection. It will also do a check
- for cleaning up internal models.
- This check is performed by first computing the set of related internal
- models. If all records in this set are unloaded, then the entire set is
- destroyed. Otherwise, nothing in the set is destroyed.
- This means that this internal model will be freed up for garbage collection
- once all models that refer to it via some relationship are also unloaded.
- */
- }, {
- key: "unloadRecord",
- value: function unloadRecord() {
- this.send('unloadRecord');
- this.dematerializeRecord();
- _ember.default.run.schedule('destroy', this, '_checkForOrphanedInternalModels');
- }
- }, {
- key: "_checkForOrphanedInternalModels",
- value: function _checkForOrphanedInternalModels() {
- this._isDematerializing = false;
- if (this.isDestroyed) {
- return;
- }
+ InternalModel.prototype.unloadRecord = function unloadRecord() {
+ this.send('unloadRecord');
+ this.dematerializeRecord();
+ _ember.default.run.schedule('destroy', this, '_checkForOrphanedInternalModels');
+ };
- this._cleanupOrphanedInternalModels();
+ InternalModel.prototype._checkForOrphanedInternalModels = function _checkForOrphanedInternalModels() {
+ this._isDematerializing = false;
+ if (this.isDestroyed) {
+ return;
}
- }, {
- key: "_cleanupOrphanedInternalModels",
- value: function _cleanupOrphanedInternalModels() {
- var relatedInternalModels = this._allRelatedInternalModels();
- if (areAllModelsUnloaded(relatedInternalModels)) {
- for (var i = 0; i < relatedInternalModels.length; ++i) {
- var internalModel = relatedInternalModels[i];
- if (!internalModel.isDestroyed) {
- internalModel.destroy();
- }
+
+ this._cleanupOrphanedInternalModels();
+ };
+
+ InternalModel.prototype._cleanupOrphanedInternalModels = function _cleanupOrphanedInternalModels() {
+ var relatedInternalModels = this._allRelatedInternalModels();
+ if (areAllModelsUnloaded(relatedInternalModels)) {
+ for (var i = 0; i < relatedInternalModels.length; ++i) {
+ var internalModel = relatedInternalModels[i];
+ if (!internalModel.isDestroyed) {
+ internalModel.destroy();
}
}
}
- }, {
- key: "eachRelationship",
- value: function eachRelationship(callback, binding) {
- return this.modelClass.eachRelationship(callback, binding);
- }
- }, {
- key: "destroy",
- value: function destroy() {
+ };
- this.store._removeFromIdMap(this);
- this._isDestroyed = true;
- }
- }, {
- key: "eachAttribute",
- value: function eachAttribute(callback, binding) {
- return this.modelClass.eachAttribute(callback, binding);
- }
- }, {
- key: "inverseFor",
- value: function inverseFor(key) {
- return this.modelClass.inverseFor(key);
- }
- }, {
- key: "setupData",
- value: function setupData(data) {
- var changedKeys = undefined;
+ InternalModel.prototype.eachRelationship = function eachRelationship(callback, binding) {
+ return this.modelClass.eachRelationship(callback, binding);
+ };
- if (this.hasRecord) {
- changedKeys = this._changedKeys(data.attributes);
- }
+ InternalModel.prototype.destroy = function destroy() {
- assign(this._data, data.attributes);
- this.pushedData();
+ this.store._removeFromIdMap(this);
+ this._isDestroyed = true;
+ };
- if (this.hasRecord) {
- this.record._notifyProperties(changedKeys);
- }
- this.didInitializeData();
- }
- }, {
- key: "becameReady",
- value: function becameReady() {
- this.store.recordArrayManager.recordWasLoaded(this);
- }
- }, {
- key: "didInitializeData",
- value: function didInitializeData() {
- if (!this.dataHasInitialized) {
- this.becameReady();
- this.dataHasInitialized = true;
- }
- }
- }, {
- key: "createSnapshot",
+ InternalModel.prototype.eachAttribute = function eachAttribute(callback, binding) {
+ return this.modelClass.eachAttribute(callback, binding);
+ };
- /*
- @method createSnapshot
- @private
- */
- value: function createSnapshot(options) {
- return new _emberDataPrivateSystemSnapshot.default(this, options);
+ InternalModel.prototype.inverseFor = function inverseFor(key) {
+ return this.modelClass.inverseFor(key);
+ };
+
+ InternalModel.prototype.setupData = function setupData(data) {
+ var changedKeys = void 0;
+
+ if (this.hasRecord) {
+ changedKeys = this._changedKeys(data.attributes);
}
- /*
- @method loadingData
- @private
- @param {Promise} promise
- */
- }, {
- key: "loadingData",
- value: function loadingData(promise) {
- this.send('loadingData', promise);
+ assign(this._data, data.attributes);
+ this.pushedData();
+
+ if (this.hasRecord) {
+ this.record._notifyProperties(changedKeys);
}
+ this.didInitializeData();
+ };
- /*
- @method loadedData
- @private
- */
- }, {
- key: "loadedData",
- value: function loadedData() {
- this.send('loadedData');
- this.didInitializeData();
+ InternalModel.prototype.becameReady = function becameReady() {
+ this.store.recordArrayManager.recordWasLoaded(this);
+ };
+
+ InternalModel.prototype.didInitializeData = function didInitializeData() {
+ if (!this.dataHasInitialized) {
+ this.becameReady();
+ this.dataHasInitialized = true;
}
+ };
- /*
- @method notFound
- @private
- */
- }, {
- key: "notFound",
- value: function notFound() {
- this.send('notFound');
+ InternalModel.prototype.createSnapshot = function createSnapshot(options) {
+ return new _snapshot.default(this, options);
+ };
+
+ InternalModel.prototype.loadingData = function loadingData(promise) {
+ this.send('loadingData', promise);
+ };
+
+ InternalModel.prototype.loadedData = function loadedData() {
+ this.send('loadedData');
+ this.didInitializeData();
+ };
+
+ InternalModel.prototype.notFound = function notFound() {
+ this.send('notFound');
+ };
+
+ InternalModel.prototype.pushedData = function pushedData() {
+ this.send('pushedData');
+ };
+
+ InternalModel.prototype.flushChangedAttributes = function flushChangedAttributes() {
+ this._inFlightAttributes = this._attributes;
+ this._attributes = new _emptyObject.default();
+ };
+
+ InternalModel.prototype.hasChangedAttributes = function hasChangedAttributes() {
+ return Object.keys(this._attributes).length > 0;
+ };
+
+ InternalModel.prototype.updateChangedAttributes = function updateChangedAttributes() {
+ var changedAttributes = this.changedAttributes();
+ var changedAttributeNames = Object.keys(changedAttributes);
+ var attrs = this._attributes;
+
+ for (var i = 0, length = changedAttributeNames.length; i < length; i++) {
+ var attribute = changedAttributeNames[i];
+ var data = changedAttributes[attribute];
+ var oldData = data[0];
+ var newData = data[1];
+
+ if (oldData === newData) {
+ delete attrs[attribute];
+ }
}
+ };
- /*
- @method pushedData
- @private
- */
- }, {
- key: "pushedData",
- value: function pushedData() {
- this.send('pushedData');
+ InternalModel.prototype.changedAttributes = function changedAttributes() {
+ var oldData = this._data;
+ var currentData = this._attributes;
+ var inFlightData = this._inFlightAttributes;
+ var newData = assign(copy(inFlightData), currentData);
+ var diffData = new _emptyObject.default();
+ var newDataKeys = Object.keys(newData);
+
+ for (var i = 0, length = newDataKeys.length; i < length; i++) {
+ var key = newDataKeys[i];
+ diffData[key] = [oldData[key], newData[key]];
}
- }, {
- key: "flushChangedAttributes",
- value: function flushChangedAttributes() {
- this._inFlightAttributes = this._attributes;
- this._attributes = new _emberDataPrivateSystemEmptyObject.default();
- }
- }, {
- key: "hasChangedAttributes",
- value: function hasChangedAttributes() {
- return Object.keys(this._attributes).length > 0;
- }
- /*
- Checks if the attributes which are considered as changed are still
- different to the state which is acknowledged by the server.
- This method is needed when data for the internal model is pushed and the
- pushed data might acknowledge dirty attributes as confirmed.
- @method updateChangedAttributes
- @private
- */
- }, {
- key: "updateChangedAttributes",
- value: function updateChangedAttributes() {
- var changedAttributes = this.changedAttributes();
- var changedAttributeNames = Object.keys(changedAttributes);
- var attrs = this._attributes;
+ return diffData;
+ };
- for (var i = 0, _length = changedAttributeNames.length; i < _length; i++) {
- var attribute = changedAttributeNames[i];
- var data = changedAttributes[attribute];
- var oldData = data[0];
- var newData = data[1];
+ InternalModel.prototype.adapterWillCommit = function adapterWillCommit() {
+ this.send('willCommit');
+ };
- if (oldData === newData) {
- delete attrs[attribute];
- }
- }
+ InternalModel.prototype.adapterDidDirty = function adapterDidDirty() {
+ this.send('becomeDirty');
+ this.updateRecordArrays();
+ };
+
+ InternalModel.prototype.send = function send(name, context) {
+ var currentState = this.currentState;
+
+ if (!currentState[name]) {
+ this._unhandledEvent(currentState, name, context);
}
- /*
- Returns an object, whose keys are changed properties, and value is an
- [oldProp, newProp] array.
- @method changedAttributes
- @private
- */
- }, {
- key: "changedAttributes",
- value: function changedAttributes() {
- var oldData = this._data;
- var currentData = this._attributes;
- var inFlightData = this._inFlightAttributes;
- var newData = assign(copy(inFlightData), currentData);
- var diffData = new _emberDataPrivateSystemEmptyObject.default();
- var newDataKeys = Object.keys(newData);
+ return currentState[name](this, context);
+ };
- for (var i = 0, _length2 = newDataKeys.length; i < _length2; i++) {
- var key = newDataKeys[i];
- diffData[key] = [oldData[key], newData[key]];
- }
+ InternalModel.prototype.notifyHasManyAdded = function notifyHasManyAdded(key, record, idx) {
+ if (this.hasRecord) {
+ this.record.notifyHasManyAdded(key, record, idx);
+ }
+ };
- return diffData;
+ InternalModel.prototype.notifyHasManyRemoved = function notifyHasManyRemoved(key, record, idx) {
+ if (this.hasRecord) {
+ this.record.notifyHasManyRemoved(key, record, idx);
}
+ };
- /*
- @method adapterWillCommit
- @private
- */
- }, {
- key: "adapterWillCommit",
- value: function adapterWillCommit() {
- this.send('willCommit');
+ InternalModel.prototype.notifyBelongsToChanged = function notifyBelongsToChanged(key, record) {
+ if (this.hasRecord) {
+ this.record.notifyBelongsToChanged(key, record);
}
+ };
- /*
- @method adapterDidDirty
- @private
- */
- }, {
- key: "adapterDidDirty",
- value: function adapterDidDirty() {
- this.send('becomeDirty');
- this.updateRecordArrays();
+ InternalModel.prototype.notifyPropertyChange = function notifyPropertyChange(key) {
+ if (this.hasRecord) {
+ this.record.notifyPropertyChange(key);
}
+ };
- /*
- @method send
- @private
- @param {String} name
- @param {Object} context
- */
- }, {
- key: "send",
- value: function send(name, context) {
- var currentState = this.currentState;
+ InternalModel.prototype.rollbackAttributes = function rollbackAttributes() {
+ var dirtyKeys = Object.keys(this._attributes);
- if (!currentState[name]) {
- this._unhandledEvent(currentState, name, context);
- }
+ this._attributes = new _emptyObject.default();
- return currentState[name](this, context);
+ if (get(this, 'isError')) {
+ this._inFlightAttributes = new _emptyObject.default();
+ this.didCleanError();
}
- }, {
- key: "notifyHasManyAdded",
- value: function notifyHasManyAdded(key, record, idx) {
- if (this.hasRecord) {
- this.record.notifyHasManyAdded(key, record, idx);
- }
+
+ //Eventually rollback will always work for relationships
+ //For now we support it only out of deleted state, because we
+ //have an explicit way of knowing when the server acked the relationship change
+ if (this.isDeleted()) {
+ //TODO: Should probably move this to the state machine somehow
+ this.becameReady();
}
- }, {
- key: "notifyHasManyRemoved",
- value: function notifyHasManyRemoved(key, record, idx) {
- if (this.hasRecord) {
- this.record.notifyHasManyRemoved(key, record, idx);
- }
+
+ if (this.isNew()) {
+ this.clearRelationships();
}
- }, {
- key: "notifyBelongsToChanged",
- value: function notifyBelongsToChanged(key, record) {
- if (this.hasRecord) {
- this.record.notifyBelongsToChanged(key, record);
- }
+
+ if (this.isValid()) {
+ this._inFlightAttributes = new _emptyObject.default();
}
- }, {
- key: "notifyPropertyChange",
- value: function notifyPropertyChange(key) {
- if (this.hasRecord) {
- this.record.notifyPropertyChange(key);
- }
- }
- }, {
- key: "rollbackAttributes",
- value: function rollbackAttributes() {
- var dirtyKeys = Object.keys(this._attributes);
- this._attributes = new _emberDataPrivateSystemEmptyObject.default();
+ this.send('rolledBack');
- if (get(this, 'isError')) {
- this._inFlightAttributes = new _emberDataPrivateSystemEmptyObject.default();
- this.didCleanError();
- }
+ this.record._notifyProperties(dirtyKeys);
+ };
- //Eventually rollback will always work for relationships
- //For now we support it only out of deleted state, because we
- //have an explicit way of knowing when the server acked the relationship change
- if (this.isDeleted()) {
- //TODO: Should probably move this to the state machine somehow
- this.becameReady();
- }
+ InternalModel.prototype.transitionTo = function transitionTo(name) {
+ // POSSIBLE TODO: Remove this code and replace with
+ // always having direct reference to state objects
- if (this.isNew()) {
- this.clearRelationships();
- }
+ var pivotName = extractPivotName(name);
+ var state = this.currentState;
+ var transitionMapId = state.stateName + "->" + name;
- if (this.isValid()) {
- this._inFlightAttributes = new _emberDataPrivateSystemEmptyObject.default();
+ do {
+ if (state.exit) {
+ state.exit(this);
}
+ state = state.parentState;
+ } while (!state[pivotName]);
- this.send('rolledBack');
+ var setups = void 0;
+ var enters = void 0;
+ var i = void 0;
+ var l = void 0;
+ var map = TransitionChainMap[transitionMapId];
- this.record._notifyProperties(dirtyKeys);
- }
+ if (map) {
+ setups = map.setups;
+ enters = map.enters;
+ state = map.state;
+ } else {
+ setups = [];
+ enters = [];
- /*
- @method transitionTo
- @private
- @param {String} name
- */
- }, {
- key: "transitionTo",
- value: function transitionTo(name) {
- // POSSIBLE TODO: Remove this code and replace with
- // always having direct reference to state objects
+ var path = splitOnDot(name);
- var pivotName = extractPivotName(name);
- var state = this.currentState;
- var transitionMapId = state.stateName + "->" + name;
+ for (i = 0, l = path.length; i < l; i++) {
+ state = state[path[i]];
- do {
- if (state.exit) {
- state.exit(this);
+ if (state.enter) {
+ enters.push(state);
}
- state = state.parentState;
- } while (!state[pivotName]);
+ if (state.setup) {
+ setups.push(state);
+ }
+ }
- var setups = undefined;
- var enters = undefined;
- var i = undefined;
- var l = undefined;
- var map = TransitionChainMap[transitionMapId];
+ TransitionChainMap[transitionMapId] = { setups: setups, enters: enters, state: state };
+ }
- if (map) {
- setups = map.setups;
- enters = map.enters;
- state = map.state;
- } else {
- setups = [];
- enters = [];
+ for (i = 0, l = enters.length; i < l; i++) {
+ enters[i].enter(this);
+ }
- var path = splitOnDot(name);
+ this.currentState = state;
+ if (this.hasRecord) {
+ set(this.record, 'currentState', state);
+ }
- for (i = 0, l = path.length; i < l; i++) {
- state = state[path[i]];
+ for (i = 0, l = setups.length; i < l; i++) {
+ setups[i].setup(this);
+ }
- if (state.enter) {
- enters.push(state);
- }
- if (state.setup) {
- setups.push(state);
- }
- }
+ this.updateRecordArrays();
+ };
- TransitionChainMap[transitionMapId] = { setups: setups, enters: enters, state: state };
- }
+ InternalModel.prototype._unhandledEvent = function _unhandledEvent(state, name, context) {
+ var errorMessage = "Attempted to handle event `" + name + "` ";
+ errorMessage += "on " + String(this) + " while in state ";
+ errorMessage += state.stateName + ". ";
- for (i = 0, l = enters.length; i < l; i++) {
- enters[i].enter(this);
- }
+ if (context !== undefined) {
+ errorMessage += "Called with " + inspect(context) + ".";
+ }
- this.currentState = state;
- if (this.hasRecord) {
- set(this.record, 'currentState', state);
- }
+ throw new EmberError(errorMessage);
+ };
- for (i = 0, l = setups.length; i < l; i++) {
- setups[i].setup(this);
- }
+ InternalModel.prototype.triggerLater = function triggerLater() {
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
+ args[_key] = arguments[_key];
+ }
- this.updateRecordArrays();
+ if (this._deferredTriggers.push(args) !== 1) {
+ return;
}
- }, {
- key: "_unhandledEvent",
- value: function _unhandledEvent(state, name, context) {
- var errorMessage = "Attempted to handle event `" + name + "` ";
- errorMessage += "on " + String(this) + " while in state ";
- errorMessage += state.stateName + ". ";
- if (context !== undefined) {
- errorMessage += "Called with " + inspect(context) + ".";
- }
+ this.store._updateInternalModel(this);
+ };
- throw new EmberError(errorMessage);
+ InternalModel.prototype._triggerDeferredTriggers = function _triggerDeferredTriggers() {
+ //TODO: Before 1.0 we want to remove all the events that happen on the pre materialized record,
+ //but for now, we queue up all the events triggered before the record was materialized, and flush
+ //them once we have the record
+ if (!this.hasRecord) {
+ return;
}
- }, {
- key: "triggerLater",
- value: function triggerLater() {
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
+ for (var i = 0, l = this._deferredTriggers.length; i < l; i++) {
+ this.record.trigger.apply(this.record, this._deferredTriggers[i]);
+ }
+
+ this._deferredTriggers.length = 0;
+ };
+
+ InternalModel.prototype.clearRelationships = function clearRelationships() {
+ var _this2 = this;
+
+ this.eachRelationship(function (name, relationship) {
+ if (_this2._relationships.has(name)) {
+ var rel = _this2._relationships.get(name);
+ rel.clear();
+ rel.destroy();
}
+ });
+ Object.keys(this._implicitRelationships).forEach(function (key) {
+ _this2._implicitRelationships[key].clear();
+ _this2._implicitRelationships[key].destroy();
+ });
+ };
- if (this._deferredTriggers.push(args) !== 1) {
- return;
+ InternalModel.prototype.destroyRelationships = function destroyRelationships() {
+ var _this3 = this;
+
+ this.eachRelationship(function (name, relationship) {
+ if (_this3._relationships.has(name)) {
+ var rel = _this3._relationships.get(name);
+ rel.destroy();
}
+ });
+ Object.keys(this._implicitRelationships).forEach(function (key) {
+ _this3._implicitRelationships[key].destroy();
+ });
+ };
- this.store._updateInternalModel(this);
- }
- }, {
- key: "_triggerDeferredTriggers",
- value: function _triggerDeferredTriggers() {
- //TODO: Before 1.0 we want to remove all the events that happen on the pre materialized record,
- //but for now, we queue up all the events triggered before the record was materialized, and flush
- //them once we have the record
- if (!this.hasRecord) {
- return;
+ InternalModel.prototype.preloadData = function preloadData(preload) {
+ var _this4 = this;
+
+ //TODO(Igor) consider the polymorphic case
+ Object.keys(preload).forEach(function (key) {
+ var preloadValue = get(preload, key);
+ var relationshipMeta = _this4.modelClass.metaForProperty(key);
+ if (relationshipMeta.isRelationship) {
+ _this4._preloadRelationship(key, preloadValue);
+ } else {
+ _this4._data[key] = preloadValue;
}
- for (var i = 0, l = this._deferredTriggers.length; i < l; i++) {
- this.record.trigger.apply(this.record, this._deferredTriggers[i]);
- }
+ });
+ };
- this._deferredTriggers.length = 0;
+ InternalModel.prototype._preloadRelationship = function _preloadRelationship(key, preloadValue) {
+ var relationshipMeta = this.modelClass.metaForProperty(key);
+ var modelClass = relationshipMeta.type;
+ if (relationshipMeta.kind === 'hasMany') {
+ this._preloadHasMany(key, preloadValue, modelClass);
+ } else {
+ this._preloadBelongsTo(key, preloadValue, modelClass);
}
+ };
- /*
- @method clearRelationships
- @private
- */
- }, {
- key: "clearRelationships",
- value: function clearRelationships() {
- var _this2 = this;
+ InternalModel.prototype._preloadHasMany = function _preloadHasMany(key, preloadValue, modelClass) {
+ var recordsToSet = new Array(preloadValue.length);
- this.eachRelationship(function (name, relationship) {
- if (_this2._relationships.has(name)) {
- var rel = _this2._relationships.get(name);
- rel.clear();
- rel.destroy();
- }
- });
- Object.keys(this._implicitRelationships).forEach(function (key) {
- _this2._implicitRelationships[key].clear();
- _this2._implicitRelationships[key].destroy();
- });
+ for (var i = 0; i < preloadValue.length; i++) {
+ var recordToPush = preloadValue[i];
+ recordsToSet[i] = this._convertStringOrNumberIntoInternalModel(recordToPush, modelClass);
}
- }, {
- key: "destroyRelationships",
- value: function destroyRelationships() {
- var _this3 = this;
- this.eachRelationship(function (name, relationship) {
- if (_this3._relationships.has(name)) {
- var rel = _this3._relationships.get(name);
- rel.destroy();
- }
- });
- Object.keys(this._implicitRelationships).forEach(function (key) {
- _this3._implicitRelationships[key].destroy();
- });
- }
+ //We use the pathway of setting the hasMany as if it came from the adapter
+ //because the user told us that they know this relationships exists already
+ this._relationships.get(key).updateRecordsFromAdapter(recordsToSet);
+ };
- /*
- When a find request is triggered on the store, the user can optionally pass in
- attributes and relationships to be preloaded. These are meant to behave as if they
- came back from the server, except the user obtained them out of band and is informing
- the store of their existence. The most common use case is for supporting client side
- nested URLs, such as `/posts/1/comments/2` so the user can do
- `store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.
- Preloaded data can be attributes and relationships passed in either as IDs or as actual
- models.
- @method preloadData
- @private
- @param {Object} preload
- */
- }, {
- key: "preloadData",
- value: function preloadData(preload) {
- var _this4 = this;
+ InternalModel.prototype._preloadBelongsTo = function _preloadBelongsTo(key, preloadValue, modelClass) {
+ var recordToSet = this._convertStringOrNumberIntoInternalModel(preloadValue, modelClass);
- //TODO(Igor) consider the polymorphic case
- Object.keys(preload).forEach(function (key) {
- var preloadValue = get(preload, key);
- var relationshipMeta = _this4.modelClass.metaForProperty(key);
- if (relationshipMeta.isRelationship) {
- _this4._preloadRelationship(key, preloadValue);
- } else {
- _this4._data[key] = preloadValue;
- }
- });
+ //We use the pathway of setting the hasMany as if it came from the adapter
+ //because the user told us that they know this relationships exists already
+ this._relationships.get(key).setRecord(recordToSet);
+ };
+
+ InternalModel.prototype._convertStringOrNumberIntoInternalModel = function _convertStringOrNumberIntoInternalModel(value, modelClass) {
+ if (typeof value === 'string' || typeof value === 'number') {
+ return this.store._internalModelForId(modelClass, value);
}
- }, {
- key: "_preloadRelationship",
- value: function _preloadRelationship(key, preloadValue) {
- var relationshipMeta = this.modelClass.metaForProperty(key);
- var modelClass = relationshipMeta.type;
- if (relationshipMeta.kind === 'hasMany') {
- this._preloadHasMany(key, preloadValue, modelClass);
- } else {
- this._preloadBelongsTo(key, preloadValue, modelClass);
- }
+ if (value._internalModel) {
+ return value._internalModel;
}
- }, {
- key: "_preloadHasMany",
- value: function _preloadHasMany(key, preloadValue, modelClass) {
- var recordsToSet = new Array(preloadValue.length);
+ return value;
+ };
- for (var i = 0; i < preloadValue.length; i++) {
- var recordToPush = preloadValue[i];
- recordsToSet[i] = this._convertStringOrNumberIntoInternalModel(recordToPush, modelClass);
- }
+ InternalModel.prototype.updateRecordArrays = function updateRecordArrays() {
+ if (this._isUpdatingRecordArrays) {
+ return;
+ }
+ this._isUpdatingRecordArrays = true;
+ this.store.recordArrayManager.recordDidChange(this);
+ };
- //We use the pathway of setting the hasMany as if it came from the adapter
- //because the user told us that they know this relationships exists already
- this._relationships.get(key).updateRecordsFromAdapter(recordsToSet);
+ InternalModel.prototype.setId = function setId(id) {
+ this.id = id;
+ if (this.record.get('id') !== id) {
+ this.record.set('id', id);
}
- }, {
- key: "_preloadBelongsTo",
- value: function _preloadBelongsTo(key, preloadValue, modelClass) {
- var recordToSet = this._convertStringOrNumberIntoInternalModel(preloadValue, modelClass);
+ };
- //We use the pathway of setting the hasMany as if it came from the adapter
- //because the user told us that they know this relationships exists already
- this._relationships.get(key).setRecord(recordToSet);
+ InternalModel.prototype.didError = function didError(error) {
+ this.error = error;
+ this.isError = true;
+
+ if (this.hasRecord) {
+ this.record.setProperties({
+ isError: true,
+ adapterError: error
+ });
}
- }, {
- key: "_convertStringOrNumberIntoInternalModel",
- value: function _convertStringOrNumberIntoInternalModel(value, modelClass) {
- if (typeof value === 'string' || typeof value === 'number') {
- return this.store._internalModelForId(modelClass, value);
- }
- if (value._internalModel) {
- return value._internalModel;
- }
- return value;
- }
+ };
- /*
- @method updateRecordArrays
- @private
- */
- }, {
- key: "updateRecordArrays",
- value: function updateRecordArrays() {
- if (this._isUpdatingRecordArrays) {
- return;
- }
- this._isUpdatingRecordArrays = true;
- this.store.recordArrayManager.recordDidChange(this);
+ InternalModel.prototype.didCleanError = function didCleanError() {
+ this.error = null;
+ this.isError = false;
+
+ if (this.hasRecord) {
+ this.record.setProperties({
+ isError: false,
+ adapterError: null
+ });
}
- }, {
- key: "setId",
- value: function setId(id) {
- this.id = id;
- if (this.record.get('id') !== id) {
- this.record.set('id', id);
- }
- }
- }, {
- key: "didError",
- value: function didError(error) {
- this.error = error;
- this.isError = true;
+ };
- if (this.hasRecord) {
- this.record.setProperties({
- isError: true,
- adapterError: error
- });
- }
+ InternalModel.prototype.adapterDidCommit = function adapterDidCommit(data) {
+ if (data) {
+ data = data.attributes;
}
- }, {
- key: "didCleanError",
- value: function didCleanError() {
- this.error = null;
- this.isError = false;
- if (this.hasRecord) {
- this.record.setProperties({
- isError: false,
- adapterError: null
- });
- }
+ this.didCleanError();
+ var changedKeys = this._changedKeys(data);
+
+ assign(this._data, this._inFlightAttributes);
+ if (data) {
+ assign(this._data, data);
}
- /*
- If the adapter did not return a hash in response to a commit,
- merge the changed attributes and relationships into the existing
- saved data.
- @method adapterDidCommit
- */
- }, {
- key: "adapterDidCommit",
- value: function adapterDidCommit(data) {
- if (data) {
- data = data.attributes;
- }
+ this._inFlightAttributes = new _emptyObject.default();
- this.didCleanError();
- var changedKeys = this._changedKeys(data);
+ this.send('didCommit');
+ this.updateRecordArrays();
- assign(this._data, this._inFlightAttributes);
- if (data) {
- assign(this._data, data);
- }
+ if (!data) {
+ return;
+ }
- this._inFlightAttributes = new _emberDataPrivateSystemEmptyObject.default();
+ this.record._notifyProperties(changedKeys);
+ };
- this.send('didCommit');
- this.updateRecordArrays();
+ InternalModel.prototype.addErrorMessageToAttribute = function addErrorMessageToAttribute(attribute, message) {
+ get(this.getRecord(), 'errors')._add(attribute, message);
+ };
- if (!data) {
- return;
- }
+ InternalModel.prototype.removeErrorMessageFromAttribute = function removeErrorMessageFromAttribute(attribute) {
+ get(this.getRecord(), 'errors')._remove(attribute);
+ };
- this.record._notifyProperties(changedKeys);
- }
- }, {
- key: "addErrorMessageToAttribute",
- value: function addErrorMessageToAttribute(attribute, message) {
- get(this.getRecord(), 'errors')._add(attribute, message);
- }
- }, {
- key: "removeErrorMessageFromAttribute",
- value: function removeErrorMessageFromAttribute(attribute) {
- get(this.getRecord(), 'errors')._remove(attribute);
- }
- }, {
- key: "clearErrorMessages",
- value: function clearErrorMessages() {
- get(this.getRecord(), 'errors')._clear();
- }
- }, {
- key: "hasErrors",
- value: function hasErrors() {
- var errors = get(this.getRecord(), 'errors');
+ InternalModel.prototype.clearErrorMessages = function clearErrorMessages() {
+ get(this.getRecord(), 'errors')._clear();
+ };
- return !isEmpty(errors);
- }
+ InternalModel.prototype.hasErrors = function hasErrors() {
+ var errors = get(this.getRecord(), 'errors');
- // FOR USE DURING COMMIT PROCESS
+ return !isEmpty(errors);
+ };
- /*
- @method adapterDidInvalidate
- @private
- */
- }, {
- key: "adapterDidInvalidate",
- value: function adapterDidInvalidate(errors) {
- var attribute = undefined;
+ InternalModel.prototype.adapterDidInvalidate = function adapterDidInvalidate(errors) {
+ var attribute = void 0;
- for (attribute in errors) {
- if (errors.hasOwnProperty(attribute)) {
- this.addErrorMessageToAttribute(attribute, errors[attribute]);
- }
+ for (attribute in errors) {
+ if (errors.hasOwnProperty(attribute)) {
+ this.addErrorMessageToAttribute(attribute, errors[attribute]);
}
+ }
- this.send('becameInvalid');
+ this.send('becameInvalid');
- this._saveWasRejected();
- }
+ this._saveWasRejected();
+ };
- /*
- @method adapterDidError
- @private
- */
- }, {
- key: "adapterDidError",
- value: function adapterDidError(error) {
- this.send('becameError');
- this.didError(error);
- this._saveWasRejected();
- }
- }, {
- key: "_saveWasRejected",
- value: function _saveWasRejected() {
- var keys = Object.keys(this._inFlightAttributes);
- var attrs = this._attributes;
- for (var i = 0; i < keys.length; i++) {
- if (attrs[keys[i]] === undefined) {
- attrs[keys[i]] = this._inFlightAttributes[keys[i]];
- }
+ InternalModel.prototype.adapterDidError = function adapterDidError(error) {
+ this.send('becameError');
+ this.didError(error);
+ this._saveWasRejected();
+ };
+
+ InternalModel.prototype._saveWasRejected = function _saveWasRejected() {
+ var keys = Object.keys(this._inFlightAttributes);
+ var attrs = this._attributes;
+ for (var i = 0; i < keys.length; i++) {
+ if (attrs[keys[i]] === undefined) {
+ attrs[keys[i]] = this._inFlightAttributes[keys[i]];
}
- this._inFlightAttributes = new _emberDataPrivateSystemEmptyObject.default();
}
+ this._inFlightAttributes = new _emptyObject.default();
+ };
- /*
- Ember Data has 3 buckets for storing the value of an attribute on an internalModel.
- `_data` holds all of the attributes that have been acknowledged by
- a backend via the adapter. When rollbackAttributes is called on a model all
- attributes will revert to the record's state in `_data`.
- `_attributes` holds any change the user has made to an attribute
- that has not been acknowledged by the adapter. Any values in
- `_attributes` are have priority over values in `_data`.
- `_inFlightAttributes`. When a record is being synced with the
- backend the values in `_attributes` are copied to
- `_inFlightAttributes`. This way if the backend acknowledges the
- save but does not return the new state Ember Data can copy the
- values from `_inFlightAttributes` to `_data`. Without having to
- worry about changes made to `_attributes` while the save was
- happenign.
- Changed keys builds a list of all of the values that may have been
- changed by the backend after a successful save.
- It does this by iterating over each key, value pair in the payload
- returned from the server after a save. If the `key` is found in
- `_attributes` then the user has a local changed to the attribute
- that has not been synced with the server and the key is not
- included in the list of changed keys.
-
- If the value, for a key differs from the value in what Ember Data
- believes to be the truth about the backend state (A merger of the
- `_data` and `_inFlightAttributes` objects where
- `_inFlightAttributes` has priority) then that means the backend
- has updated the value and the key is added to the list of changed
- keys.
- @method _changedKeys
- @private
- */
- }, {
- key: "_changedKeys",
- value: function _changedKeys(updates) {
- var changedKeys = [];
+ InternalModel.prototype._changedKeys = function _changedKeys(updates) {
+ var changedKeys = [];
- if (updates) {
- var original = undefined,
- i = undefined,
- value = undefined,
- key = undefined;
- var keys = Object.keys(updates);
- var _length3 = keys.length;
- var attrs = this._attributes;
+ if (updates) {
+ var original = void 0,
+ i = void 0,
+ value = void 0,
+ key = void 0;
+ var keys = Object.keys(updates);
+ var length = keys.length;
+ var attrs = this._attributes;
- original = assign(new _emberDataPrivateSystemEmptyObject.default(), this._data);
- original = assign(original, this._inFlightAttributes);
+ original = assign(new _emptyObject.default(), this._data);
+ original = assign(original, this._inFlightAttributes);
- for (i = 0; i < _length3; i++) {
- key = keys[i];
- value = updates[key];
+ for (i = 0; i < length; i++) {
+ key = keys[i];
+ value = updates[key];
- // A value in _attributes means the user has a local change to
- // this attributes. We never override this value when merging
- // updates from the backend so we should not sent a change
- // notification if the server value differs from the original.
- if (attrs[key] !== undefined) {
- continue;
- }
+ // A value in _attributes means the user has a local change to
+ // this attributes. We never override this value when merging
+ // updates from the backend so we should not sent a change
+ // notification if the server value differs from the original.
+ if (attrs[key] !== undefined) {
+ continue;
+ }
- if (!isEqual(original[key], value)) {
- changedKeys.push(key);
- }
+ if (!isEqual(original[key], value)) {
+ changedKeys.push(key);
}
}
-
- return changedKeys;
}
- }, {
- key: "toString",
- value: function toString() {
- return "<" + this.modelName + ":" + this.id + ">";
- }
- }, {
- key: "referenceFor",
- value: function referenceFor(kind, name) {
- var reference = this.references[name];
- if (!reference) {
- var relationship = this._relationships.get(name);
+ return changedKeys;
+ };
- if (kind === "belongsTo") {
- reference = new _emberDataPrivateSystemReferences.BelongsToReference(this.store, this, relationship);
- } else if (kind === "hasMany") {
- reference = new _emberDataPrivateSystemReferences.HasManyReference(this.store, this, relationship);
- }
+ InternalModel.prototype.toString = function toString() {
+ return "<" + this.modelName + ":" + this.id + ">";
+ };
- this.references[name] = reference;
+ InternalModel.prototype.referenceFor = function referenceFor(kind, name) {
+ var _this5 = this;
+
+ var reference = this.references[name];
+
+ if (!reference) {
+ var relationship = this._relationships.get(name);
+
+ if (kind === "belongsTo") {
+ reference = new _references.BelongsToReference(this.store, this, relationship);
+ } else if (kind === "hasMany") {
+ reference = new _references.HasManyReference(this.store, this, relationship);
}
- return reference;
+ this.references[name] = reference;
}
- }, {
+
+ return reference;
+ };
+
+ _createClass(InternalModel, [{
key: "modelClass",
get: function () {
return this._modelClass || (this._modelClass = this.store._modelFor(this.modelName));
}
}, {
@@ -3058,27 +3155,27 @@
}
}, {
key: "recordReference",
get: function () {
if (this._recordReference === null) {
- this._recordReference = new _emberDataPrivateSystemReferences.RecordReference(this.store, this);
+ this._recordReference = new _references.RecordReference(this.store, this);
}
return this._recordReference;
}
}, {
key: "_recordArrays",
get: function () {
if (this.__recordArrays === null) {
- this.__recordArrays = _emberDataPrivateSystemOrderedSet.default.create();
+ this.__recordArrays = _orderedSet.default.create();
}
return this.__recordArrays;
}
}, {
key: "references",
get: function () {
if (this._references === null) {
- this._references = new _emberDataPrivateSystemEmptyObject.default();
+ this._references = new _emptyObject.default();
}
return this._references;
}
}, {
key: "_deferredTriggers",
@@ -3090,75 +3187,53 @@
}
}, {
key: "_attributes",
get: function () {
if (this.__attributes === null) {
- this.__attributes = new _emberDataPrivateSystemEmptyObject.default();
+ this.__attributes = new _emptyObject.default();
}
return this.__attributes;
},
set: function (v) {
this.__attributes = v;
}
}, {
key: "_relationships",
get: function () {
if (this.__relationships === null) {
- this.__relationships = new _emberDataPrivateSystemRelationshipsStateCreate.default(this);
+ this.__relationships = new _create.default(this);
}
return this.__relationships;
}
}, {
key: "_inFlightAttributes",
get: function () {
if (this.__inFlightAttributes === null) {
- this.__inFlightAttributes = new _emberDataPrivateSystemEmptyObject.default();
+ this.__inFlightAttributes = new _emptyObject.default();
}
return this.__inFlightAttributes;
},
set: function (v) {
this.__inFlightAttributes = v;
}
}, {
key: "_data",
get: function () {
if (this.__data === null) {
- this.__data = new _emberDataPrivateSystemEmptyObject.default();
+ this.__data = new _emptyObject.default();
}
return this.__data;
},
set: function (v) {
this.__data = v;
}
-
- /*
- implicit relationships are relationship which have not been declared but the inverse side exists on
- another record somewhere
- For example if there was
- ```app/models/comment.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- name: DS.attr()
- })
- ```
- but there is also
- ```app/models/post.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- name: DS.attr(),
- comments: DS.hasMany('comment')
- })
- ```
- would have a implicit post relationship in order to be do things like remove ourselves from the post
- when we are deleted
- */
}, {
key: "_implicitRelationships",
get: function () {
if (this.__implicitRelationships === null) {
- this.__implicitRelationships = new _emberDataPrivateSystemEmptyObject.default();
+ this.__implicitRelationships = new _emptyObject.default();
}
return this.__implicitRelationships;
}
}, {
key: "record",
@@ -3176,15 +3251,16 @@
return !!this._record;
}
}]);
return InternalModel;
- })();
+ }();
exports.default = InternalModel;
- if ((0, _emberDataPrivateFeatures.default)('ds-rollback-attribute')) {
+
+ if ((0, _features.default)('ds-rollback-attribute')) {
/*
Returns the latest truth for an attribute - the canonical value, or the
in-flight value.
@method lastAcknowledgedValue
@private
@@ -3196,15 +3272,19 @@
return this._data[key];
}
};
}
});
-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/model/states", "ember-data/-private/system/empty-object", "ember-data/-private/system/relationships/ext"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemModelErrors, _emberDataPrivateFeatures, _emberDataPrivateSystemModelStates, _emberDataPrivateSystemEmptyObject, _emberDataPrivateSystemRelationshipsExt) {
- var get = _ember.default.get;
- var computed = _ember.default.computed;
- var Map = _ember.default.Map;
+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/model/states", "ember-data/-private/system/empty-object", "ember-data/-private/system/relationships/ext"], function (exports, _ember, _debug, _promiseProxies, _errors, _features, _states, _emptyObject, _ext) {
+ "use strict";
+ exports.__esModule = true;
+ var get = _ember.default.get,
+ computed = _ember.default.computed,
+ Map = _ember.default.Map;
+
+
/**
@module ember-data
*/
function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
@@ -3485,11 +3565,11 @@
/**
@property currentState
@private
@type {Object}
*/
- currentState: _emberDataPrivateSystemModelStates.default.empty,
+ currentState: _states.default.empty,
/**
When the record is in the `invalid` state this object will contain
any errors returned by the adapter. When present the errors hash
contains keys corresponding to the invalid property names
@@ -3531,11 +3611,11 @@
```
@property errors
@type {DS.Errors}
*/
errors: computed(function () {
- var errors = _emberDataPrivateSystemModelErrors.default.create();
+ var errors = _errors.default.create();
errors._registerHandlers(this._internalModel, function () {
this.send('becameInvalid');
}, function () {
this.send('becameValid');
@@ -3549,373 +3629,86 @@
@property adapterError
@type {DS.AdapterError}
*/
adapterError: null,
- /**
- Create a JSON representation of the record, using the serialization
- strategy of the store's adapter.
- `serialize` takes an optional hash as a parameter, currently
- supported options are:
- - `includeId`: `true` if the record's ID should be included in the
- JSON representation.
- @method serialize
- @param {Object} options
- @return {Object} an object whose values are primitive JSON values only
- */
serialize: function (options) {
return this._internalModel.createSnapshot().serialize(options);
},
-
- /**
- Use [DS.JSONSerializer](DS.JSONSerializer.html) to
- get the JSON representation of a record.
- `toJSON` takes an optional hash as a parameter, currently
- supported options are:
- - `includeId`: `true` if the record's ID should be included in the
- JSON representation.
- @method toJSON
- @param {Object} options
- @return {Object} A JSON representation of the object.
- */
toJSON: function (options) {
// container is for lazy transform lookups
var serializer = this.store.serializerFor('-default');
var snapshot = this._internalModel.createSnapshot();
return serializer.serialize(snapshot, options);
},
-
- /**
- Fired when the record is ready to be interacted with,
- that is either loaded from the server or created locally.
- @event ready
- */
ready: function () {},
-
- /**
- Fired when the record is loaded from the server.
- @event didLoad
- */
didLoad: function () {},
-
- /**
- Fired when the record is updated.
- @event didUpdate
- */
didUpdate: function () {},
-
- /**
- Fired when a new record is commited to the server.
- @event didCreate
- */
didCreate: function () {},
-
- /**
- Fired when the record is deleted.
- @event didDelete
- */
didDelete: function () {},
-
- /**
- Fired when the record becomes invalid.
- @event becameInvalid
- */
becameInvalid: function () {},
-
- /**
- Fired when the record enters the error state.
- @event becameError
- */
becameError: function () {},
-
- /**
- Fired when the record is rolled back.
- @event rolledBack
- */
rolledBack: function () {},
-
- //TODO Do we want to deprecate these?
- /**
- @method send
- @private
- @param {String} name
- @param {Object} context
- */
send: function (name, context) {
return this._internalModel.send(name, context);
},
-
- /**
- @method transitionTo
- @private
- @param {String} name
- */
transitionTo: function (name) {
return this._internalModel.transitionTo(name);
},
-
- /**
- Marks the record as deleted but does not save it. You must call
- `save` afterwards if you want to persist it. You might use this
- method if you want to allow the user to still `rollbackAttributes()`
- after a delete was made.
- Example
- ```app/routes/model/delete.js
- import Ember from 'ember';
- export default Ember.Route.extend({
- actions: {
- softDelete: function() {
- this.controller.get('model').deleteRecord();
- },
- confirm: function() {
- this.controller.get('model').save();
- },
- undo: function() {
- this.controller.get('model').rollbackAttributes();
- }
- }
- });
- ```
- @method deleteRecord
- */
deleteRecord: function () {
this._internalModel.deleteRecord();
},
-
- /**
- Same as `deleteRecord`, but saves the record immediately.
- Example
- ```app/routes/model/delete.js
- import Ember from 'ember';
- export default Ember.Route.extend({
- actions: {
- delete: function() {
- let controller = this.controller;
- controller.get('model').destroyRecord().then(function() {
- controller.transitionToRoute('model.index');
- });
- }
- }
- });
- ```
- If you pass an object on the `adapterOptions` property of the options
- argument it will be passed to your adapter via the snapshot
- ```js
- record.destroyRecord({ adapterOptions: { subscribe: false } });
- ```
- ```app/adapters/post.js
- import MyCustomAdapter from './custom-adapter';
- export default MyCustomAdapter.extend({
- deleteRecord: function(store, type, snapshot) {
- if (snapshot.adapterOptions.subscribe) {
- // ...
- }
- // ...
- }
- });
- ```
- @method destroyRecord
- @param {Object} options
- @return {Promise} a promise that will be resolved when the adapter returns
- successfully or rejected if the adapter returns with an error.
- */
destroyRecord: function (options) {
this.deleteRecord();
return this.save(options);
},
-
- /**
- Unloads the record from the store. This will cause the record to be destroyed and freed up for garbage collection.
- @method unloadRecord
- */
unloadRecord: function () {
if (this.isDestroyed) {
return;
}
this._internalModel.unloadRecord();
},
-
- /**
- @method _notifyProperties
- @private
- */
_notifyProperties: function (keys) {
_ember.default.beginPropertyChanges();
- var key = undefined;
- for (var i = 0, _length = keys.length; i < _length; i++) {
+ var key = void 0;
+ for (var i = 0, length = keys.length; i < length; i++) {
key = keys[i];
this.notifyPropertyChange(key);
}
_ember.default.endPropertyChanges();
},
-
- /**
- Returns an object, whose keys are changed properties, and value is
- an [oldProp, newProp] array.
- The array represents the diff of the canonical state with the local state
- of the model. Note: if the model is created locally, the canonical state is
- empty since the adapter hasn't acknowledged the attributes yet:
- Example
- ```app/models/mascot.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- name: DS.attr('string'),
- isAdmin: DS.attr('boolean', {
- defaultValue: false
- })
- });
- ```
- ```javascript
- let mascot = store.createRecord('mascot');
- mascot.changedAttributes(); // {}
- mascot.set('name', 'Tomster');
- mascot.changedAttributes(); // { name: [undefined, 'Tomster'] }
- mascot.set('isAdmin', true);
- mascot.changedAttributes(); // { isAdmin: [undefined, true], name: [undefined, 'Tomster'] }
- mascot.save().then(function() {
- mascot.changedAttributes(); // {}
- mascot.set('isAdmin', false);
- mascot.changedAttributes(); // { isAdmin: [true, false] }
- });
- ```
- @method changedAttributes
- @return {Object} an object, whose keys are changed properties,
- and value is an [oldProp, newProp] array.
- */
changedAttributes: function () {
return this._internalModel.changedAttributes();
},
-
- //TODO discuss with tomhuda about events/hooks
- //Bring back as hooks?
- /**
- @method adapterWillCommit
- @private
- adapterWillCommit: function() {
- this.send('willCommit');
- },
- /**
- @method adapterDidDirty
- @private
- adapterDidDirty: function() {
- this.send('becomeDirty');
- this.updateRecordArraysLater();
- },
- */
-
- /**
- If the model `hasDirtyAttributes` this function will discard any unsaved
- changes. If the model `isNew` it will be removed from the store.
- Example
- ```javascript
- record.get('name'); // 'Untitled Document'
- record.set('name', 'Doc 1');
- record.get('name'); // 'Doc 1'
- record.rollbackAttributes();
- record.get('name'); // 'Untitled Document'
- ```
- @since 1.13.0
- @method rollbackAttributes
- */
rollbackAttributes: function () {
this._internalModel.rollbackAttributes();
},
-
- /*
- @method _createSnapshot
- @private
- */
_createSnapshot: function () {
return this._internalModel.createSnapshot();
},
-
toStringExtension: function () {
return get(this, 'id');
},
-
- /**
- Save the record and persist any changes to the record to an
- external source via the adapter.
- Example
- ```javascript
- record.set('name', 'Tomster');
- record.save().then(function() {
- // Success callback
- }, function() {
- // Error callback
- });
- ```
- If you pass an object on the `adapterOptions` property of the options
- argument it will be passed to you adapter via the snapshot
- ```js
- record.save({ adapterOptions: { subscribe: false } });
- ```
- ```app/adapters/post.js
- import MyCustomAdapter from './custom-adapter';
- export default MyCustomAdapter.extend({
- updateRecord: function(store, type, snapshot) {
- if (snapshot.adapterOptions.subscribe) {
- // ...
- }
- // ...
- }
- });
- ```
- @method save
- @param {Object} options
- @return {Promise} a promise that will be resolved when the adapter returns
- successfully or rejected if the adapter returns with an error.
- */
save: function (options) {
var _this = this;
- return _emberDataPrivateSystemPromiseProxies.PromiseObject.create({
+ return _promiseProxies.PromiseObject.create({
promise: this._internalModel.save(options).then(function () {
return _this;
})
});
},
-
- /**
- Reload the record from the adapter.
- This will only work if the record has already finished loading.
- Example
- ```app/routes/model/view.js
- import Ember from 'ember';
- export default Ember.Route.extend({
- actions: {
- reload: function() {
- this.controller.get('model').reload().then(function(model) {
- // do something with the reloaded model
- });
- }
- }
- });
- ```
- @method reload
- @return {Promise} a promise that will be resolved with the record when the
- adapter returns successfully or rejected if the adapter returns
- with an error.
- */
reload: function () {
var _this2 = this;
- return _emberDataPrivateSystemPromiseProxies.PromiseObject.create({
+ return _promiseProxies.PromiseObject.create({
promise: this._internalModel.reload().then(function () {
return _this2;
})
});
},
-
- /**
- Override the default event firing from Ember.Evented to
- also call methods with the given name.
- @method trigger
- @private
- @param {String} name
- */
trigger: function (name) {
var length = arguments.length;
var args = new Array(length - 1);
for (var i = 1; i < length; i++) {
@@ -3923,142 +3716,26 @@
}
_ember.default.tryInvoke(this, name, args);
this._super.apply(this, arguments);
},
-
- // This is a temporary solution until we refactor DS.Model to not
- // rely on the data property.
willMergeMixin: function (props) {
var constructor = this.constructor;
},
-
attr: function () {},
-
- /**
- Get the reference for the specified belongsTo relationship.
- Example
- ```app/models/blog.js
- export default DS.Model.extend({
- user: DS.belongsTo({ async: true })
- });
- ```
- ```javascript
- let blog = store.push({
- data: {
- type: 'blog',
- id: 1,
- relationships: {
- user: {
- data: { type: 'user', id: 1 }
- }
- }
- }
- });
- let userRef = blog.belongsTo('user');
- // check if the user relationship is loaded
- let isLoaded = userRef.value() !== null;
- // get the record of the reference (null if not yet available)
- let user = userRef.value();
- // get the identifier of the reference
- if (userRef.remoteType() === "id") {
- let id = userRef.id();
- } else if (userRef.remoteType() === "link") {
- let 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
- @since 2.5.0
- @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 })
- });
- let blog = store.push({
- data: {
- type: 'blog',
- id: 1,
- relationships: {
- comments: {
- data: [
- { type: 'comment', id: 1 },
- { type: 'comment', id: 2 }
- ]
- }
- }
- }
- });
- let commentsRef = blog.hasMany('comments');
- // check if the comments are loaded already
- let isLoaded = commentsRef.value() !== null;
- // get the records of the reference (null if not yet available)
- let comments = commentsRef.value();
- // get the identifier of the reference
- if (commentsRef.remoteType() === "ids") {
- let ids = commentsRef.ids();
- } else if (commentsRef.remoteType() === "link") {
- let 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
- @since 2.5.0
- @return {HasManyReference} reference for this relationship
- */
hasMany: function (name) {
return this._internalModel.referenceFor('hasMany', name);
},
+
setId: _ember.default.observer('id', function () {
this._internalModel.setId(this.get('id'));
}),
- /**
- Provides info about the model for debugging purposes
- by grouping the properties into more semantic groups.
- Meant to be used by debugging tools such as the Chrome Ember Extension.
- - Groups all attributes in "Attributes" group.
- - Groups all belongsTo relationships in "Belongs To" group.
- - Groups all hasMany relationships in "Has Many" group.
- - Groups all flags in "Flags" group.
- - Flags relationship CPs as expensive properties.
- @method _debugInfo
- @for DS.Model
- @private
- */
_debugInfo: function () {
var attributes = ['id'];
var relationships = {};
var expensiveProperties = [];
@@ -4100,36 +3777,13 @@
// don't pre-calculate unless cached
expensiveProperties: expensiveProperties
}
};
},
-
notifyBelongsToChanged: function (key) {
this.notifyPropertyChange(key);
},
-
- /**
- This Ember.js hook allows an object to be notified when a property
- is defined.
- In this case, we use it to be notified when an Ember Data user defines a
- belongs-to relationship. In that case, we need to set up observers for
- each one, allowing us to track relationship changes and automatically
- reflect changes in the inverse has-many array.
- This hook passes the class being set up, as well as the key and value
- being defined. So, for example, when the user does this:
- ```javascript
- DS.Model.extend({
- parent: DS.belongsTo('user')
- });
- ```
- This hook would be called with "parent" as the key and the computed
- property returned by `DS.belongsTo` as the value.
- @method didDefineProperty
- @param {Object} proto
- @param {String} key
- @param {Ember.ComputedProperty} value
- */
didDefineProperty: function (proto, key, value) {
// Check if the value being set is a computed property.
if (value instanceof _ember.default.ComputedProperty) {
// If it is, get the metadata for the relationship. This is
@@ -4138,71 +3792,27 @@
var meta = value.meta();
meta.parentType = proto.constructor;
}
},
-
- /**
- Given a callback, iterates over each of the relationships in the model,
- invoking the callback with the name of each relationship and its relationship
- descriptor.
- The callback method you provide should have the following signature (all
- parameters are optional):
- ```javascript
- function(name, descriptor);
- ```
- - `name` the name of the current property in the iteration
- - `descriptor` the meta object that describes this relationship
- The relationship descriptor argument is an object with the following properties.
- - **key** <span class="type">String</span> the name of this relationship on the Model
- - **kind** <span class="type">String</span> "hasMany" or "belongsTo"
- - **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
- - **parentType** <span class="type">DS.Model</span> the type of the Model that owns this relationship
- - **type** <span class="type">String</span> the type name of the related Model
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context.
- Example
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serialize: function(record, options) {
- let json = {};
- record.eachRelationship(function(name, descriptor) {
- if (descriptor.kind === 'hasMany') {
- let serializedHasManyName = name.toUpperCase() + '_IDS';
- json[serializedHasManyName] = record.get(name).mapBy('id');
- }
- });
- return json;
- }
- });
- ```
- @method eachRelationship
- @param {Function} callback the callback to invoke
- @param {any} binding the value to which the callback's `this` should be bound
- */
eachRelationship: function (callback, binding) {
this.constructor.eachRelationship(callback, binding);
},
-
relationshipFor: function (name) {
return get(this.constructor, 'relationshipsByName').get(name);
},
-
inverseFor: function (key) {
return this.constructor.inverseFor(key, this.store);
},
-
notifyHasManyAdded: function (key) {
//We need to notifyPropertyChange in the adding case because we need to make sure
//we fetch the newly added record in case it is unloaded
//TODO(Igor): Consider whether we could do this only if the record state is unloaded
//Goes away once hasMany is double promisified
this.notifyPropertyChange(key);
},
-
eachAttribute: function (callback, binding) {
this.constructor.eachAttribute(callback, binding);
}
});
@@ -4253,86 +3863,30 @@
@readonly
@static
*/
modelName: null,
- /*
- These class methods below provide relationship
- introspection abilities about relationships.
- A note about the computed properties contained here:
- **These properties are effectively sealed once called for the first time.**
- To avoid repeatedly doing expensive iteration over a model's fields, these
- values are computed once and then cached for the remainder of the runtime of
- your application.
- If your application needs to modify a class after its initial definition
- (for example, using `reopen()` to add additional attributes), make sure you
- do it before using your model with the store, which uses these properties
- extensively.
- */
-
- /**
- For a given relationship name, returns the model type of the relationship.
- For example, if you define a model like this:
- ```app/models/post.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- comments: DS.hasMany('comment')
- });
- ```
- Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.
- @method typeForRelationship
- @static
- @param {String} name the name of the relationship
- @param {store} store an instance of DS.Store
- @return {DS.Model} the type of the relationship, or undefined
- */
typeForRelationship: function (name, store) {
var relationship = get(this, 'relationshipsByName').get(name);
return relationship && store.modelFor(relationship.type);
},
+
inverseMap: _ember.default.computed(function () {
- return new _emberDataPrivateSystemEmptyObject.default();
+ return new _emptyObject.default();
}),
- /**
- Find the relationship which is the inverse of the one asked for.
- For example, if you define models like this:
- ```app/models/post.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- comments: DS.hasMany('message')
- });
- ```
- ```app/models/message.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- owner: DS.belongsTo('post')
- });
- ```
- ``` js
- store.modelFor('post').inverseFor('comments', store) // { type: App.Message, name: 'owner', kind: 'belongsTo' }
- store.modelFor('message').inverseFor('owner', store) // { type: App.Post, name: 'comments', kind: 'hasMany' }
- ```
- @method inverseFor
- @static
- @param {String} name the name of the relationship
- @param {DS.Store} store
- @return {Object} the inverse relationship, or null
- */
inverseFor: function (name, store) {
var inverseMap = get(this, 'inverseMap');
if (inverseMap[name]) {
return inverseMap[name];
} else {
var inverse = this._findInverseFor(name, store);
inverseMap[name] = inverse;
return inverse;
}
},
-
- //Calculate the inverse, ignoring the cache
_findInverseFor: function (name, store) {
var inverseType = this.typeForRelationship(name, store);
if (!inverseType) {
return null;
@@ -4343,13 +3897,13 @@
var options = propertyMeta.options;
if (options.inverse === null) {
return null;
}
- var inverseName = undefined,
- inverseKind = undefined,
- inverse = undefined;
+ var inverseName = void 0,
+ inverseKind = void 0,
+ inverse = void 0;
//If inverse is specified manually, return the inverse
if (options.inverse) {
inverseName = options.inverse;
inverse = _ember.default.get(inverseType, 'relationshipsByName').get(inverseName);
@@ -4383,10 +3937,11 @@
name: inverseName,
kind: inverseKind
};
},
+
/**
The model's relationships as a map, keyed on the type of the
relationship. The value of each entry is an array containing a descriptor
for each relationship with that type, describing the name of the relationship
as well as the type.
@@ -4417,11 +3972,11 @@
@static
@type Ember.Map
@readOnly
*/
- relationships: _emberDataPrivateSystemRelationshipsExt.relationshipsDescriptor,
+ relationships: _ext.relationshipsDescriptor,
/**
A hash containing lists of the model's relationships, grouped
by the relationship kind. For example, given a model with this
definition:
@@ -4486,11 +4041,11 @@
@property relatedTypes
@static
@type Ember.Array
@readOnly
*/
- relatedTypes: _emberDataPrivateSystemRelationshipsExt.relatedTypesDescriptor,
+ relatedTypes: _ext.relatedTypesDescriptor,
/**
A map whose keys are the relationships of a model and whose values are
relationship descriptors.
For example, given a model with this
@@ -4516,11 +4071,11 @@
@property relationshipsByName
@static
@type Ember.Map
@readOnly
*/
- relationshipsByName: _emberDataPrivateSystemRelationshipsExt.relationshipsByNameDescriptor,
+ relationshipsByName: _ext.relationshipsByNameDescriptor,
/**
A map whose keys are the fields of the model and whose values are strings
describing the kind of the field. A model's fields are the union of all of its
attributes and relationships.
@@ -4564,50 +4119,29 @@
});
return map;
}).readOnly(),
- /**
- Given a callback, iterates over each of the relationships in the model,
- invoking the callback with the name of each relationship and its relationship
- descriptor.
- @method eachRelationship
- @static
- @param {Function} callback the callback to invoke
- @param {any} binding the value to which the callback's `this` should be bound
- */
eachRelationship: function (callback, binding) {
get(this, 'relationshipsByName').forEach(function (relationship, name) {
callback.call(binding, name, relationship);
});
},
-
- /**
- Given a callback, iterates over each of the types related to a model,
- invoking the callback with the related type's class. Each type will be
- returned just once, regardless of how many different relationships it has
- with a model.
- @method eachRelatedType
- @static
- @param {Function} callback the callback to invoke
- @param {any} binding the value to which the callback's `this` should be bound
- */
eachRelatedType: function (callback, binding) {
var relationshipTypes = get(this, 'relatedTypes');
for (var i = 0; i < relationshipTypes.length; i++) {
var type = relationshipTypes[i];
callback.call(binding, type);
}
},
-
determineRelationshipType: function (knownSide, store) {
var knownKey = knownSide.key;
var knownKind = knownSide.kind;
var inverse = this.inverseFor(knownKey, store);
// let key;
- var otherKind = undefined;
+ var otherKind = void 0;
if (!inverse) {
return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone';
}
@@ -4619,10 +4153,11 @@
} else {
return knownKind === 'belongsTo' ? 'oneToMany' : 'manyToMany';
}
},
+
/**
A map whose keys are the attributes of the model (properties
described by DS.attr) and whose values are the meta object for the
property.
Example
@@ -4650,10 +4185,12 @@
@static
@type {Ember.Map}
@readOnly
*/
attributes: _ember.default.computed(function () {
+ var _this3 = this;
+
var map = Map.create();
this.eachComputedProperty(function (name, meta) {
if (meta.isAttribute) {
@@ -4705,83 +4242,15 @@
});
return map;
}).readOnly(),
- /**
- Iterates through the attributes of the model, calling the passed function on each
- attribute.
- The callback method you provide should have the following signature (all
- parameters are optional):
- ```javascript
- function(name, meta);
- ```
- - `name` the name of the current property in the iteration
- - `meta` the meta object for the attribute property in the iteration
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context.
- Example
- ```javascript
- import DS from 'ember-data';
- let Person = DS.Model.extend({
- firstName: DS.attr('string'),
- lastName: DS.attr('string'),
- birthday: DS.attr('date')
- });
- Person.eachAttribute(function(name, meta) {
- console.log(name, meta);
- });
- // prints:
- // firstName {type: "string", isAttribute: true, options: Object, parentType: function, name: "firstName"}
- // lastName {type: "string", isAttribute: true, options: Object, parentType: function, name: "lastName"}
- // birthday {type: "date", isAttribute: true, options: Object, parentType: function, name: "birthday"}
- ```
- @method eachAttribute
- @param {Function} callback The callback to execute
- @param {Object} [binding] the value to which the callback's `this` should be bound
- @static
- */
eachAttribute: function (callback, binding) {
get(this, 'attributes').forEach(function (meta, name) {
callback.call(binding, name, meta);
});
},
-
- /**
- Iterates through the transformedAttributes of the model, calling
- the passed function on each attribute. Note the callback will not be
- called for any attributes that do not have an transformation type.
- The callback method you provide should have the following signature (all
- parameters are optional):
- ```javascript
- function(name, type);
- ```
- - `name` the name of the current property in the iteration
- - `type` a string containing the name of the type of transformed
- applied to the attribute
- Note that in addition to a callback, you can also pass an optional target
- object that will be set as `this` on the context.
- Example
- ```javascript
- import DS from 'ember-data';
- let Person = DS.Model.extend({
- firstName: DS.attr(),
- lastName: DS.attr('string'),
- birthday: DS.attr('date')
- });
- Person.eachTransformedAttribute(function(name, type) {
- console.log(name, type);
- });
- // prints:
- // lastName string
- // birthday date
- ```
- @method eachTransformedAttribute
- @param {Function} callback The callback to execute
- @param {Object} [binding] the value to which the callback's `this` should be bound
- @static
- */
eachTransformedAttribute: function (callback, binding) {
get(this, 'transformedAttributes').forEach(function (type, name) {
callback.call(binding, name, type);
});
}
@@ -4801,36 +4270,28 @@
return this.store.container;
}
});
}
- if ((0, _emberDataPrivateFeatures.default)('ds-rollback-attribute')) {
+ if ((0, _features.default)('ds-rollback-attribute')) {
Model.reopen({
- /**
- Discards any unsaved changes to the given attribute. This feature is not enabled by default. You must enable `ds-rollback-attribute` and be running a canary build.
- Example
- ```javascript
- record.get('name'); // 'Untitled Document'
- record.set('name', 'Doc 1');
- record.get('name'); // 'Doc 1'
- record.rollbackAttribute('name');
- record.get('name'); // 'Untitled Document'
- ```
- @method rollbackAttribute
- */
rollbackAttribute: function (attributeName) {
if (attributeName in this._internalModel._attributes) {
this.set(attributeName, this._internalModel.lastAcknowledgedValue(attributeName));
}
}
});
}
exports.default = Model;
});
-define('ember-data/-private/system/model/states', ['exports', 'ember-data/-private/debug'], function (exports, _emberDataPrivateDebug) {
+define('ember-data/-private/system/model/states', ['exports', 'ember-data/-private/debug'], function (exports, _debug) {
+ 'use strict';
+ exports.__esModule = true;
+
+
/*
This file encapsulates the various states that a record can transition
through during its lifecycle.
*/
/**
@@ -5046,10 +4507,13 @@
// to be saved.
// `inFlight`: the store has handed off the record to be saved,
// but the adapter has not yet acknowledged success.
// `invalid`: the record has invalid information and cannot be
// sent to the adapter yet.
+ /**
+ @module ember-data
+ */
var DirtyState = {
initialState: 'uncommitted',
// FLAGS
isDirty: true,
@@ -5061,46 +4525,36 @@
// have not yet begun to be saved, and are not invalid.
uncommitted: {
// EVENTS
didSetProperty: didSetProperty,
- //TODO(Igor) reloading now triggers a
- //loadingData event, though it seems fine?
loadingData: function () {},
-
propertyWasReset: function (internalModel, name) {
if (!internalModel.hasChangedAttributes()) {
internalModel.send('rolledBack');
}
},
-
pushedData: function (internalModel) {
internalModel.updateChangedAttributes();
if (!internalModel.hasChangedAttributes()) {
internalModel.transitionTo('loaded.saved');
}
},
-
becomeDirty: function () {},
-
willCommit: function (internalModel) {
internalModel.transitionTo('inFlight');
},
-
reloadRecord: function (internalModel, resolve) {
resolve(internalModel.store._reloadRecord(internalModel));
},
-
rolledBack: function (internalModel) {
internalModel.transitionTo('loaded.saved');
},
-
becameInvalid: function (internalModel) {
internalModel.transitionTo('invalid');
},
-
rollback: function (internalModel) {
internalModel.rollbackAttributes();
internalModel.triggerLater('ready');
}
},
@@ -5115,25 +4569,22 @@
// EVENTS
didSetProperty: didSetProperty,
becomeDirty: function () {},
pushedData: function () {},
+
unloadRecord: assertAgainstUnloadRecord,
- // TODO: More robust semantics around save-while-in-flight
willCommit: function () {},
-
didCommit: function (internalModel) {
internalModel.transitionTo('saved');
internalModel.send('invokeLifecycleCallbacks', this.dirtyType);
},
-
becameInvalid: function (internalModel) {
internalModel.transitionTo('invalid');
internalModel.send('invokeLifecycleCallbacks');
},
-
becameError: function (internalModel) {
internalModel.transitionTo('uncommitted');
internalModel.triggerLater('becameError', internalModel);
}
},
@@ -5142,44 +4593,37 @@
// the the record failed server-side invalidations.
invalid: {
// FLAGS
isValid: false,
- // EVENTS
deleteRecord: function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
},
-
didSetProperty: function (internalModel, context) {
internalModel.removeErrorMessageFromAttribute(context.name);
didSetProperty(internalModel, context);
if (!internalModel.hasErrors()) {
this.becameValid(internalModel);
}
},
-
becameInvalid: function () {},
becomeDirty: function () {},
pushedData: function () {},
-
willCommit: function (internalModel) {
internalModel.clearErrorMessages();
internalModel.transitionTo('inFlight');
},
-
rolledBack: function (internalModel) {
internalModel.clearErrorMessages();
internalModel.transitionTo('loaded.saved');
internalModel.triggerLater('ready');
},
-
becameValid: function (internalModel) {
internalModel.transitionTo('uncommitted');
},
-
invokeLifecycleCallbacks: function (internalModel) {
internalModel.triggerLater('becameInvalid', internalModel);
}
}
};
@@ -5188,11 +4632,11 @@
// chart so we can reopen their substates and add mixins as
// necessary.
function deepClone(object) {
var clone = {};
- var value = undefined;
+ var value = void 0;
for (var prop in object) {
value = object[prop];
if (value && typeof value === 'object') {
clone[prop] = deepClone(value);
@@ -5273,42 +4717,33 @@
isSaving: false,
isDeleted: false,
isNew: false,
isValid: true,
- // DEFAULT EVENTS
-
- // Trying to roll back if you're not in the dirty state
- // doesn't change your state. For example, if you're in the
- // in-flight state, rolling back the record doesn't move
- // you out of the in-flight state.
rolledBack: function () {},
unloadRecord: function (internalModel) {},
-
propertyWasReset: function () {},
+
// SUBSTATES
// A record begins its lifecycle in the `empty` state.
// If its data will come from the adapter, it will
// transition into the `loading` state. Otherwise, if
// the record is being created on the client, it will
// transition into the `created` state.
empty: {
isEmpty: true,
- // EVENTS
loadingData: function (internalModel, promise) {
internalModel._loadingPromise = promise;
internalModel.transitionTo('loading');
},
-
loadedData: function (internalModel) {
internalModel.transitionTo('loaded.created.uncommitted');
internalModel.triggerLater('ready');
},
-
pushedData: function (internalModel) {
internalModel.transitionTo('loaded.saved');
internalModel.triggerLater('didLoad');
internalModel.triggerLater('ready');
}
@@ -5325,24 +4760,20 @@
isLoading: true,
exit: function (internalModel) {
internalModel._loadingPromise = null;
},
-
- // EVENTS
pushedData: function (internalModel) {
internalModel.transitionTo('loaded.saved');
internalModel.triggerLater('didLoad');
internalModel.triggerLater('ready');
//TODO this seems out of place here
internalModel.didCleanError();
},
-
becameError: function (internalModel) {
internalModel.triggerLater('becameError', internalModel);
},
-
notFound: function (internalModel) {
internalModel.transitionTo('empty');
}
},
@@ -5353,14 +4784,13 @@
initialState: 'saved',
// FLAGS
isLoaded: true,
- //TODO(Igor) Reloading now triggers a loadingData event,
- //but it should be ok?
loadingData: function () {},
+
// SUBSTATES
// If there are no local changes to a record, it remains
// in the `saved` state.
saved: {
@@ -5368,37 +4798,29 @@
if (internalModel.hasChangedAttributes()) {
internalModel.adapterDidDirty();
}
},
+
// EVENTS
didSetProperty: didSetProperty,
pushedData: function () {},
-
becomeDirty: function (internalModel) {
internalModel.transitionTo('updated.uncommitted');
},
-
willCommit: function (internalModel) {
internalModel.transitionTo('updated.inFlight');
},
-
reloadRecord: function (internalModel, resolve) {
resolve(internalModel.store._reloadRecord(internalModel));
},
-
deleteRecord: function (internalModel) {
internalModel.transitionTo('deleted.uncommitted');
},
-
unloadRecord: function (internalModel) {},
-
didCommit: function () {},
-
- // loaded.saved.notFound would be triggered by a failed
- // `reload()` on an unchanged record
notFound: function () {}
},
// A record is in this state after it has been locally
// created but before the adapter has indicated that
@@ -5419,37 +4841,31 @@
// FLAGS
isDeleted: true,
isLoaded: true,
isDirty: true,
- // TRANSITIONS
setup: function (internalModel) {
internalModel.updateRecordArrays();
},
+
// SUBSTATES
// When a record is deleted, it enters the `start`
// state. It will exit this state when the record
// starts to commit.
uncommitted: {
-
- // EVENTS
-
willCommit: function (internalModel) {
internalModel.transitionTo('inFlight');
},
-
rollback: function (internalModel) {
internalModel.rollbackAttributes();
internalModel.triggerLater('ready');
},
-
pushedData: function () {},
becomeDirty: function () {},
deleteRecord: function () {},
-
rolledBack: function (internalModel) {
internalModel.transitionTo('loaded.saved');
internalModel.triggerLater('ready');
}
},
@@ -5464,23 +4880,20 @@
// EVENTS
unloadRecord: assertAgainstUnloadRecord,
- // TODO: More robust semantics around save-while-in-flight
willCommit: function () {},
didCommit: function (internalModel) {
internalModel.transitionTo('saved');
internalModel.send('invokeLifecycleCallbacks');
},
-
becameError: function (internalModel) {
internalModel.transitionTo('uncommitted');
internalModel.triggerLater('becameError', internalModel);
},
-
becameInvalid: function (internalModel) {
internalModel.transitionTo('invalid');
internalModel.triggerLater('becameInvalid', internalModel);
}
},
@@ -5493,16 +4906,14 @@
isDirty: false,
setup: function (internalModel) {
internalModel.clearRelationships();
},
-
invokeLifecycleCallbacks: function (internalModel) {
internalModel.triggerLater('didDelete', internalModel);
internalModel.triggerLater('didCommit', internalModel);
},
-
willCommit: function () {},
didCommit: function () {}
},
invalid: {
@@ -5515,26 +4926,22 @@
if (!internalModel.hasErrors()) {
this.becameValid(internalModel);
}
},
-
becameInvalid: function () {},
becomeDirty: function () {},
deleteRecord: function () {},
willCommit: function () {},
-
rolledBack: function (internalModel) {
internalModel.clearErrorMessages();
internalModel.transitionTo('loaded.saved');
internalModel.triggerLater('ready');
},
-
becameValid: function (internalModel) {
internalModel.transitionTo('uncommitted');
}
-
}
},
invokeLifecycleCallbacks: function (internalModel, dirtyType) {
if (dirtyType === 'created') {
@@ -5565,14 +4972,14 @@
return object;
}
exports.default = wireState(RootState, null, 'root');
});
-/**
- @module ember-data
-*/
define('ember-data/-private/system/normalize-link', ['exports'], function (exports) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = _normalizeLink;
/*
This method normalizes a link to an "links object". If the passed link is
already an object it's returned without any modifications.
@@ -5582,11 +4989,10 @@
@private
@param {String} link
@return {Object|null}
@for DS
*/
-
function _normalizeLink(link) {
switch (typeof link) {
case 'object':
return link;
case 'string':
@@ -5594,12 +5000,16 @@
}
return null;
}
});
define('ember-data/-private/system/normalize-model-name', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = normalizeModelName;
+
// All modelNames are dasherized internally. Changing this function may
// require changes to other normalization hooks (such as typeForRoot).
/**
This method normalizes a modelName into the format Ember Data uses
@@ -5609,18 +5019,21 @@
@public
@param {String} modelName
@return {String} normalizedModelName
@for DS
*/
-
function normalizeModelName(modelName) {
return _ember.default.String.dasherize(modelName);
}
});
define('ember-data/-private/system/ordered-set', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = OrderedSet;
+
var EmberOrderedSet = _ember.default.OrderedSet;
var guidFor = _ember.default.guidFor;
function OrderedSet() {
this._super$constructor();
@@ -5655,18 +5068,23 @@
this.size += 1;
return this;
};
});
-define('ember-data/-private/system/promise-proxies', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
+define('ember-data/-private/system/promise-proxies', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _debug) {
+ 'use strict';
+
+ exports.__esModule = true;
+ exports.PromiseManyArray = exports.PromiseObject = exports.PromiseArray = undefined;
exports.promiseObject = promiseObject;
exports.promiseArray = promiseArray;
exports.proxyToContent = proxyToContent;
exports.promiseManyArray = promiseManyArray;
- var get = _ember.default.get;
- var Promise = _ember.default.RSVP.Promise;
+ var get = _ember.default.get,
+ Promise = _ember.default.RSVP.Promise;
+
/**
A `PromiseArray` is an object that acts like both an `Ember.Array`
and a promise. When the promise is resolved the resulting value
will be set to the `PromiseArray`'s `content` property. This makes
it easy to create data bindings with the `PromiseArray` that will be
@@ -5692,13 +5110,12 @@
@class PromiseArray
@namespace DS
@extends Ember.ArrayProxy
@uses Ember.PromiseProxyMixin
*/
- var PromiseArray = _ember.default.ArrayProxy.extend(_ember.default.PromiseProxyMixin);
+ var PromiseArray = exports.PromiseArray = _ember.default.ArrayProxy.extend(_ember.default.PromiseProxyMixin);
- exports.PromiseArray = PromiseArray;
/**
A `PromiseObject` is an object that acts like both an `Ember.Object`
and a promise. When the promise is resolved, then the resulting value
will be set to the `PromiseObject`'s `content` property. This makes
it easy to create data bindings with the `PromiseObject` that will
@@ -5724,14 +5141,12 @@
@class PromiseObject
@namespace DS
@extends Ember.ObjectProxy
@uses Ember.PromiseProxyMixin
*/
- var PromiseObject = _ember.default.ObjectProxy.extend(_ember.default.PromiseProxyMixin);
+ var PromiseObject = exports.PromiseObject = _ember.default.ObjectProxy.extend(_ember.default.PromiseProxyMixin);
- exports.PromiseObject = PromiseObject;
-
function promiseObject(promise, label) {
return PromiseObject.create({
promise: Promise.resolve(promise, label)
});
}
@@ -5766,16 +5181,17 @@
return (_get = get(this, 'content'))[method].apply(_get, arguments);
};
}
- var PromiseManyArray = PromiseArray.extend({
+ var PromiseManyArray = exports.PromiseManyArray = PromiseArray.extend({
reload: function () {
this.set('promise', this.get('content').reload());
return this;
},
+
createRecord: proxyToContent('createRecord'),
on: proxyToContent('on'),
one: proxyToContent('one'),
@@ -5785,34 +5201,32 @@
off: proxyToContent('off'),
has: proxyToContent('has')
});
- exports.PromiseManyArray = PromiseManyArray;
-
function promiseManyArray(promise, label) {
return PromiseManyArray.create({
promise: Promise.resolve(promise, label)
});
}
});
-define('ember-data/-private/system/record-array-manager', ['exports', 'ember', 'ember-data/-private/system/record-arrays', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateSystemRecordArrays, _emberDataPrivateDebug) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define('ember-data/-private/system/record-array-manager', ['exports', 'ember', 'ember-data/-private/system/record-arrays', 'ember-data/-private/debug'], function (exports, _ember, _recordArrays, _debug) {
+ 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ exports.__esModule = true;
- var get = _ember.default.get;
- var MapWithDefault = _ember.default.MapWithDefault;
- var emberRun = _ember.default.run;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- /**
- @class RecordArrayManager
- @namespace DS
- @private
- */
+ var get = _ember.default.get,
+ MapWithDefault = _ember.default.MapWithDefault,
+ emberRun = _ember.default.run;
- var RecordArrayManager = (function () {
+ var RecordArrayManager = function () {
function RecordArrayManager(options) {
var _this = this;
this.store = options.store;
this.isDestroying = false;
@@ -5832,365 +5246,264 @@
this.changedRecords = [];
this.loadedRecords = [];
this._adapterPopulatedRecordArrays = [];
}
- _createClass(RecordArrayManager, [{
- key: 'recordDidChange',
- value: function recordDidChange(internalModel) {
- if (this.changedRecords.push(internalModel) !== 1) {
- return;
- }
-
- emberRun.schedule('actions', this, this.updateRecordArrays);
+ RecordArrayManager.prototype.recordDidChange = function recordDidChange(internalModel) {
+ if (this.changedRecords.push(internalModel) !== 1) {
+ return;
}
- }, {
- key: 'recordArraysForRecord',
- value: function recordArraysForRecord(internalModel) {
- return internalModel._recordArrays;
- }
+ emberRun.schedule('actions', this, this.updateRecordArrays);
+ };
- /**
- This method is invoked whenever data is loaded into the store by the
- adapter or updated by the adapter, or when a record has changed.
- It updates all record arrays that a record belongs to.
- To avoid thrashing, it only runs at most once per run loop.
- @method updateRecordArrays
- */
- }, {
- key: 'updateRecordArrays',
- value: function updateRecordArrays() {
- var updated = this.changedRecords;
+ RecordArrayManager.prototype.recordArraysForRecord = function recordArraysForRecord(internalModel) {
- for (var i = 0, l = updated.length; i < l; i++) {
- var internalModel = updated[i];
+ return internalModel._recordArrays;
+ };
- // During dematerialization we don't want to rematerialize the record.
- // recordWasDeleted can cause other records to rematerialize because it
- // removes the internal model from the array and Ember arrays will always
- // `objectAt(0)` and `objectAt(len -1)` to check whether `firstObject` or
- // `lastObject` have changed. When this happens we don't want those
- // models to rematerialize their records.
- if (internalModel._isDematerializing || internalModel.isDestroyed || internalModel.currentState.stateName === 'root.deleted.saved') {
- this._recordWasDeleted(internalModel);
- } else {
- this._recordWasChanged(internalModel);
- }
+ RecordArrayManager.prototype.updateRecordArrays = function updateRecordArrays() {
+ var updated = this.changedRecords;
- internalModel._isUpdatingRecordArrays = false;
+ for (var i = 0, l = updated.length; i < l; i++) {
+ var internalModel = updated[i];
+
+ // During dematerialization we don't want to rematerialize the record.
+ // recordWasDeleted can cause other records to rematerialize because it
+ // removes the internal model from the array and Ember arrays will always
+ // `objectAt(0)` and `objectAt(len -1)` to check whether `firstObject` or
+ // `lastObject` have changed. When this happens we don't want those
+ // models to rematerialize their records.
+ if (internalModel._isDematerializing || internalModel.isDestroyed || internalModel.currentState.stateName === 'root.deleted.saved') {
+ this._recordWasDeleted(internalModel);
+ } else {
+ this._recordWasChanged(internalModel);
}
- updated.length = 0;
+ internalModel._isUpdatingRecordArrays = false;
}
- }, {
- key: '_recordWasDeleted',
- value: function _recordWasDeleted(internalModel) {
- var recordArrays = internalModel.__recordArrays;
- if (!recordArrays) {
- return;
- }
+ updated.length = 0;
+ };
- recordArrays.forEach(function (array) {
- return array._removeInternalModels([internalModel]);
- });
+ RecordArrayManager.prototype._recordWasDeleted = function _recordWasDeleted(internalModel) {
+ var recordArrays = internalModel.__recordArrays;
- internalModel.__recordArrays = null;
+ if (!recordArrays) {
+ return;
}
- }, {
- key: '_recordWasChanged',
- value: function _recordWasChanged(internalModel) {
- var _this2 = this;
- var modelName = internalModel.modelName;
- var recordArrays = this.filteredRecordArrays.get(modelName);
- var filter = undefined;
- recordArrays.forEach(function (array) {
- filter = get(array, 'filterFunction');
- _this2.updateFilterRecordArray(array, filter, modelName, internalModel);
- });
- }
+ recordArrays.forEach(function (array) {
+ return array._removeInternalModels([internalModel]);
+ });
- //Need to update live arrays on loading
- }, {
- key: 'recordWasLoaded',
- value: function recordWasLoaded(internalModel) {
- if (this.loadedRecords.push(internalModel) !== 1) {
- return;
- }
+ internalModel.__recordArrays = null;
+ };
- emberRun.schedule('actions', this, this._flushLoadedRecords);
+ RecordArrayManager.prototype._recordWasChanged = function _recordWasChanged(internalModel) {
+ var _this2 = this;
+
+ var modelName = internalModel.modelName;
+ var recordArrays = this.filteredRecordArrays.get(modelName);
+ var filter = void 0;
+ recordArrays.forEach(function (array) {
+ filter = get(array, 'filterFunction');
+ _this2.updateFilterRecordArray(array, filter, modelName, internalModel);
+ });
+ };
+
+ RecordArrayManager.prototype.recordWasLoaded = function recordWasLoaded(internalModel) {
+ if (this.loadedRecords.push(internalModel) !== 1) {
+ return;
}
- }, {
- key: '_flushLoadedRecords',
- value: function _flushLoadedRecords() {
- var internalModels = this.loadedRecords;
- for (var i = 0, l = internalModels.length; i < l; i++) {
- var internalModel = internalModels[i];
- var modelName = internalModel.modelName;
+ emberRun.schedule('actions', this, this._flushLoadedRecords);
+ };
- var recordArrays = this.filteredRecordArrays.get(modelName);
- var filter = undefined;
+ RecordArrayManager.prototype._flushLoadedRecords = function _flushLoadedRecords() {
+ var internalModels = this.loadedRecords;
- for (var j = 0, rL = recordArrays.length; j < rL; j++) {
- var array = recordArrays[j];
- filter = get(array, 'filterFunction');
- this.updateFilterRecordArray(array, filter, modelName, internalModel);
- }
+ for (var i = 0, l = internalModels.length; i < l; i++) {
+ var internalModel = internalModels[i];
+ var modelName = internalModel.modelName;
- if (this.liveRecordArrays.has(modelName)) {
- var liveRecordArray = this.liveRecordArrays.get(modelName);
- this._addInternalModelToRecordArray(liveRecordArray, internalModel);
- }
+ var recordArrays = this.filteredRecordArrays.get(modelName);
+ var filter = void 0;
+
+ for (var j = 0, rL = recordArrays.length; j < rL; j++) {
+ var array = recordArrays[j];
+ filter = get(array, 'filterFunction');
+ this.updateFilterRecordArray(array, filter, modelName, internalModel);
}
- this.loadedRecords.length = 0;
+ if (this.liveRecordArrays.has(modelName)) {
+ var liveRecordArray = this.liveRecordArrays.get(modelName);
+ this._addInternalModelToRecordArray(liveRecordArray, internalModel);
+ }
}
- /**
- Update an individual filter.
- @method updateFilterRecordArray
- @param {DS.FilteredRecordArray} array
- @param {Function} filter
- @param {String} modelName
- @param {InternalModel} internalModel
- */
- }, {
- key: 'updateFilterRecordArray',
- value: function updateFilterRecordArray(array, filter, modelName, internalModel) {
- var shouldBeInArray = filter(internalModel.getRecord());
- var recordArrays = this.recordArraysForRecord(internalModel);
- if (shouldBeInArray) {
- this._addInternalModelToRecordArray(array, internalModel);
- } else {
- recordArrays.delete(array);
- array._removeInternalModels([internalModel]);
- }
+ this.loadedRecords.length = 0;
+ };
+
+ RecordArrayManager.prototype.updateFilterRecordArray = function updateFilterRecordArray(array, filter, modelName, internalModel) {
+ var shouldBeInArray = filter(internalModel.getRecord());
+ var recordArrays = this.recordArraysForRecord(internalModel);
+ if (shouldBeInArray) {
+ this._addInternalModelToRecordArray(array, internalModel);
+ } else {
+ recordArrays.delete(array);
+ array._removeInternalModels([internalModel]);
}
- }, {
- key: '_addInternalModelToRecordArray',
- value: function _addInternalModelToRecordArray(array, internalModel) {
- var recordArrays = this.recordArraysForRecord(internalModel);
- if (!recordArrays.has(array)) {
- array._pushInternalModels([internalModel]);
- recordArrays.add(array);
- }
+ };
+
+ RecordArrayManager.prototype._addInternalModelToRecordArray = function _addInternalModelToRecordArray(array, internalModel) {
+ var recordArrays = this.recordArraysForRecord(internalModel);
+ if (!recordArrays.has(array)) {
+ array._pushInternalModels([internalModel]);
+ recordArrays.add(array);
}
- }, {
- key: 'syncLiveRecordArray',
- value: function syncLiveRecordArray(array, modelName) {
- var hasNoPotentialDeletions = this.changedRecords.length === 0;
- var map = this.store._internalModelsFor(modelName);
- var hasNoInsertionsOrRemovals = map.length === array.length;
+ };
- /*
- Ideally the recordArrayManager has knowledge of the changes to be applied to
- liveRecordArrays, and is capable of strategically flushing those changes and applying
- small diffs if desired. However, until we've refactored recordArrayManager, this dirty
- check prevents us from unnecessarily wiping out live record arrays returned by peekAll.
- */
- if (hasNoPotentialDeletions && hasNoInsertionsOrRemovals) {
- return;
- }
+ RecordArrayManager.prototype.syncLiveRecordArray = function syncLiveRecordArray(array, modelName) {
+ var hasNoPotentialDeletions = this.changedRecords.length === 0;
+ var map = this.store._internalModelsFor(modelName);
+ var hasNoInsertionsOrRemovals = map.length === array.length;
- this.populateLiveRecordArray(array, modelName);
+ /*
+ Ideally the recordArrayManager has knowledge of the changes to be applied to
+ liveRecordArrays, and is capable of strategically flushing those changes and applying
+ small diffs if desired. However, until we've refactored recordArrayManager, this dirty
+ check prevents us from unnecessarily wiping out live record arrays returned by peekAll.
+ */
+ if (hasNoPotentialDeletions && hasNoInsertionsOrRemovals) {
+ return;
}
- }, {
- key: 'populateLiveRecordArray',
- value: function populateLiveRecordArray(array, modelName) {
- var modelMap = this.store._internalModelsFor(modelName);
- var internalModels = modelMap.models;
- for (var i = 0; i < internalModels.length; i++) {
- var internalModel = internalModels[i];
+ this.populateLiveRecordArray(array, modelName);
+ };
- if (!internalModel.isDeleted() && !internalModel.isEmpty()) {
- this._addInternalModelToRecordArray(array, internalModel);
- }
+ RecordArrayManager.prototype.populateLiveRecordArray = function populateLiveRecordArray(array, modelName) {
+ var modelMap = this.store._internalModelsFor(modelName);
+ var internalModels = modelMap.models;
+
+ for (var i = 0; i < internalModels.length; i++) {
+ var internalModel = internalModels[i];
+
+ if (!internalModel.isDeleted() && !internalModel.isEmpty()) {
+ this._addInternalModelToRecordArray(array, internalModel);
}
}
+ };
- /**
- This method is invoked if the `filterFunction` property is
- changed on a `DS.FilteredRecordArray`.
- It essentially re-runs the filter from scratch. This same
- method is invoked when the filter is created in th first place.
- @method updateFilter
- @param {Array} array
- @param {String} modelName
- @param {Function} filter
- */
- }, {
- key: 'updateFilter',
- value: function updateFilter(array, modelName, filter) {
- var modelMap = this.store._internalModelsFor(modelName);
- var internalModels = modelMap.models;
+ RecordArrayManager.prototype.updateFilter = function updateFilter(array, modelName, filter) {
+ var modelMap = this.store._internalModelsFor(modelName);
+ var internalModels = modelMap.models;
- for (var i = 0; i < internalModels.length; i++) {
- var internalModel = internalModels[i];
+ for (var i = 0; i < internalModels.length; i++) {
+ var internalModel = internalModels[i];
- if (!internalModel.isDeleted() && !internalModel.isEmpty()) {
- this.updateFilterRecordArray(array, filter, modelName, internalModel);
- }
+ if (!internalModel.isDeleted() && !internalModel.isEmpty()) {
+ this.updateFilterRecordArray(array, filter, modelName, internalModel);
}
}
+ };
- /**
- Get the `DS.RecordArray` for a modelName, which contains all loaded records of
- given modelName.
- @method liveRecordArrayFor
- @param {String} modelName
- @return {DS.RecordArray}
- */
- }, {
- key: 'liveRecordArrayFor',
- value: function liveRecordArrayFor(modelName) {
- return this.liveRecordArrays.get(modelName);
- }
+ RecordArrayManager.prototype.liveRecordArrayFor = function liveRecordArrayFor(modelName) {
+ return this.liveRecordArrays.get(modelName);
+ };
- /**
- Create a `DS.RecordArray` for a modelName.
- @method createRecordArray
- @param {String} modelName
- @return {DS.RecordArray}
- */
- }, {
- key: 'createRecordArray',
- value: function createRecordArray(modelName) {
- return _emberDataPrivateSystemRecordArrays.RecordArray.create({
- modelName: modelName,
- content: _ember.default.A(),
- store: this.store,
- isLoaded: true,
- manager: this
- });
- }
+ RecordArrayManager.prototype.createRecordArray = function createRecordArray(modelName) {
+ return _recordArrays.RecordArray.create({
+ modelName: modelName,
+ content: _ember.default.A(),
+ store: this.store,
+ isLoaded: true,
+ manager: this
+ });
+ };
- /**
- Create a `DS.FilteredRecordArray` for a modelName and register it for updates.
- @method createFilteredRecordArray
- @param {String} modelName
- @param {Function} filter
- @param {Object} query (optional
- @return {DS.FilteredRecordArray}
- */
- }, {
- key: 'createFilteredRecordArray',
- value: function createFilteredRecordArray(modelName, filter, query) {
- var array = _emberDataPrivateSystemRecordArrays.FilteredRecordArray.create({
- query: query,
- modelName: modelName,
- content: _ember.default.A(),
- store: this.store,
- manager: this,
- filterFunction: filter
- });
+ RecordArrayManager.prototype.createFilteredRecordArray = function createFilteredRecordArray(modelName, filter, query) {
+ var array = _recordArrays.FilteredRecordArray.create({
+ query: query,
+ modelName: modelName,
+ content: _ember.default.A(),
+ store: this.store,
+ manager: this,
+ filterFunction: filter
+ });
- this.registerFilteredRecordArray(array, modelName, filter);
+ this.registerFilteredRecordArray(array, modelName, filter);
- return array;
- }
+ return array;
+ };
- /**
- Create a `DS.AdapterPopulatedRecordArray` for a modelName with given query.
- @method createAdapterPopulatedRecordArray
- @param {String} modelName
- @param {Object} query
- @return {DS.AdapterPopulatedRecordArray}
- */
- }, {
- key: 'createAdapterPopulatedRecordArray',
- value: function createAdapterPopulatedRecordArray(modelName, query) {
+ RecordArrayManager.prototype.createAdapterPopulatedRecordArray = function createAdapterPopulatedRecordArray(modelName, query) {
- var array = _emberDataPrivateSystemRecordArrays.AdapterPopulatedRecordArray.create({
- modelName: modelName,
- query: query,
- content: _ember.default.A(),
- store: this.store,
- manager: this
- });
+ var array = _recordArrays.AdapterPopulatedRecordArray.create({
+ modelName: modelName,
+ query: query,
+ content: _ember.default.A(),
+ store: this.store,
+ manager: this
+ });
- this._adapterPopulatedRecordArrays.push(array);
+ this._adapterPopulatedRecordArrays.push(array);
- return array;
- }
+ return array;
+ };
- /**
- Register a RecordArray for a given modelName to be backed by
- a filter function. This will cause the array to update
- automatically when records of that modelName change attribute
- values or states.
- @method registerFilteredRecordArray
- @param {DS.RecordArray} array
- @param {String} modelName
- @param {Function} filter
- */
- }, {
- key: 'registerFilteredRecordArray',
- value: function registerFilteredRecordArray(array, modelName, filter) {
+ RecordArrayManager.prototype.registerFilteredRecordArray = function registerFilteredRecordArray(array, modelName, filter) {
- var recordArrays = this.filteredRecordArrays.get(modelName);
- recordArrays.push(array);
+ var recordArrays = this.filteredRecordArrays.get(modelName);
+ recordArrays.push(array);
- this.updateFilter(array, modelName, filter);
- }
+ this.updateFilter(array, modelName, filter);
+ };
- /**
- Unregister a RecordArray.
- So manager will not update this array.
- @method unregisterRecordArray
- @param {DS.RecordArray} array
- */
- }, {
- key: 'unregisterRecordArray',
- value: function unregisterRecordArray(array) {
+ RecordArrayManager.prototype.unregisterRecordArray = function unregisterRecordArray(array) {
- var modelName = array.modelName;
+ var modelName = array.modelName;
- // unregister filtered record array
- var recordArrays = this.filteredRecordArrays.get(modelName);
- var removedFromFiltered = remove(recordArrays, array);
+ // unregister filtered record array
+ var recordArrays = this.filteredRecordArrays.get(modelName);
+ var removedFromFiltered = remove(recordArrays, array);
- // remove from adapter populated record array
- var removedFromAdapterPopulated = remove(this._adapterPopulatedRecordArrays, array);
+ // remove from adapter populated record array
+ var removedFromAdapterPopulated = remove(this._adapterPopulatedRecordArrays, array);
- if (!removedFromFiltered && !removedFromAdapterPopulated) {
+ if (!removedFromFiltered && !removedFromAdapterPopulated) {
- // unregister live record array
- if (this.liveRecordArrays.has(modelName)) {
- var liveRecordArrayForType = this.liveRecordArrayFor(modelName);
- if (array === liveRecordArrayForType) {
- this.liveRecordArrays.delete(modelName);
- }
+ // unregister live record array
+ if (this.liveRecordArrays.has(modelName)) {
+ var liveRecordArrayForType = this.liveRecordArrayFor(modelName);
+ if (array === liveRecordArrayForType) {
+ this.liveRecordArrays.delete(modelName);
}
}
}
- }, {
- key: 'willDestroy',
- value: function willDestroy() {
- this.filteredRecordArrays.forEach(function (value) {
- return flatten(value).forEach(destroy);
- });
- this.liveRecordArrays.forEach(destroy);
- this._adapterPopulatedRecordArrays.forEach(destroy);
- this.isDestroyed = true;
- }
- }, {
- key: 'destroy',
- value: function destroy() {
- this.isDestroying = true;
- _ember.default.run.schedule('actions', this, this.willDestroy);
- }
- }]);
+ };
+ RecordArrayManager.prototype.willDestroy = function willDestroy() {
+ this.filteredRecordArrays.forEach(function (value) {
+ return flatten(value).forEach(destroy);
+ });
+ this.liveRecordArrays.forEach(destroy);
+ this._adapterPopulatedRecordArrays.forEach(destroy);
+ this.isDestroyed = true;
+ };
+
+ RecordArrayManager.prototype.destroy = function destroy() {
+ this.isDestroying = true;
+ _ember.default.run.schedule('actions', this, this.willDestroy);
+ };
+
return RecordArrayManager;
- })();
+ }();
exports.default = RecordArrayManager;
+
function destroy(entry) {
entry.destroy();
}
function flatten(list) {
@@ -6213,87 +5526,44 @@
}
return false;
}
});
-/**
- @module ember-data
-*/
-define("ember-data/-private/system/record-arrays", ["exports", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/record-arrays/filtered-record-array", "ember-data/-private/system/record-arrays/adapter-populated-record-array"], function (exports, _emberDataPrivateSystemRecordArraysRecordArray, _emberDataPrivateSystemRecordArraysFilteredRecordArray, _emberDataPrivateSystemRecordArraysAdapterPopulatedRecordArray) {
- exports.RecordArray = _emberDataPrivateSystemRecordArraysRecordArray.default;
- exports.FilteredRecordArray = _emberDataPrivateSystemRecordArraysFilteredRecordArray.default;
- exports.AdapterPopulatedRecordArray = _emberDataPrivateSystemRecordArraysAdapterPopulatedRecordArray.default;
+define("ember-data/-private/system/record-arrays", ["exports", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/record-arrays/filtered-record-array", "ember-data/-private/system/record-arrays/adapter-populated-record-array"], function (exports, _recordArray, _filteredRecordArray, _adapterPopulatedRecordArray) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.AdapterPopulatedRecordArray = exports.FilteredRecordArray = exports.RecordArray = undefined;
+ exports.RecordArray = _recordArray.default;
+ exports.FilteredRecordArray = _filteredRecordArray.default;
+ exports.AdapterPopulatedRecordArray = _adapterPopulatedRecordArray.default;
});
-/**
- @module ember-data
-*/
-define("ember-data/-private/system/record-arrays/adapter-populated-record-array", ["exports", "ember", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/clone-null"], function (exports, _ember, _emberDataPrivateSystemRecordArraysRecordArray, _emberDataPrivateSystemCloneNull) {
+define("ember-data/-private/system/record-arrays/adapter-populated-record-array", ["exports", "ember", "ember-data/-private/system/record-arrays/record-array", "ember-data/-private/system/clone-null"], function (exports, _ember, _recordArray, _cloneNull) {
+ "use strict";
- /**
- @module ember-data
- */
-
+ exports.__esModule = true;
var get = _ember.default.get;
-
- /**
- Represents an ordered list of records whose order and membership is
- determined by the adapter. For example, a query sent to the adapter
- may trigger a search on the server, whose results would be loaded
- into an instance of the `AdapterPopulatedRecordArray`.
-
- ---
-
- If you want to update the array and get the latest records from the
- adapter, you can invoke [`update()`](#method_update):
-
- Example
-
- ```javascript
- // GET /users?isAdmin=true
- var admins = store.query('user', { isAdmin: true });
-
- admins.then(function() {
- console.log(admins.get("length")); // 42
- });
-
- // somewhere later in the app code, when new admins have been created
- // in the meantime
- //
- // GET /users?isAdmin=true
- admins.update().then(function() {
- admins.get('isUpdating'); // false
- console.log(admins.get("length")); // 123
- });
-
- admins.get('isUpdating'); // true
- ```
-
- @class AdapterPopulatedRecordArray
- @namespace DS
- @extends DS.RecordArray
- */
- exports.default = _emberDataPrivateSystemRecordArraysRecordArray.default.extend({
+ exports.default = _recordArray.default.extend({
init: function () {
// yes we are touching `this` before super, but ArrayProxy has a bug that requires this.
this.set('content', this.get('content') || _ember.default.A());
this._super.apply(this, arguments);
this.query = this.query || null;
this.links = null;
},
-
replace: function () {
throw new Error("The result of a server query (on " + this.modelName + ") is immutable.");
},
-
_update: function () {
var store = get(this, 'store');
var query = get(this, 'query');
return store._query(this.modelName, query, this);
},
+
/**
@method _setInternalModels
@param {Array} internalModels
@param {Object} payload normalized payload
@private
@@ -6306,12 +5576,12 @@
this.get('content').setObjects(internalModels);
this.setProperties({
isLoaded: true,
isUpdating: false,
- meta: (0, _emberDataPrivateSystemCloneNull.default)(payload.meta),
- links: (0, _emberDataPrivateSystemCloneNull.default)(payload.links)
+ meta: (0, _cloneNull.default)(payload.meta),
+ links: (0, _cloneNull.default)(payload.links)
});
for (var i = 0, l = internalModels.length; i < l; i++) {
var internalModel = internalModels[i];
this.manager.recordArraysForRecord(internalModel).add(this);
@@ -6320,35 +5590,23 @@
// TODO: should triggering didLoad event be the last action of the runLoop?
_ember.default.run.once(this, 'trigger', 'didLoad');
}
});
});
-define('ember-data/-private/system/record-arrays/filtered-record-array', ['exports', 'ember', 'ember-data/-private/system/record-arrays/record-array'], function (exports, _ember, _emberDataPrivateSystemRecordArraysRecordArray) {
+define('ember-data/-private/system/record-arrays/filtered-record-array', ['exports', 'ember', 'ember-data/-private/system/record-arrays/record-array'], function (exports, _ember, _recordArray) {
+ 'use strict';
- /**
- @module ember-data
- */
-
+ exports.__esModule = true;
var get = _ember.default.get;
-
- /**
- Represents a list of records whose membership is determined by the
- store. As records are created, loaded, or modified, the store
- evaluates them to determine if they should be part of the record
- array.
-
- @class FilteredRecordArray
- @namespace DS
- @extends DS.RecordArray
- */
- exports.default = _emberDataPrivateSystemRecordArraysRecordArray.default.extend({
+ exports.default = _recordArray.default.extend({
init: function () {
this._super.apply(this, arguments);
this.set('filterFunction', this.get('filterFunction') || null);
this.isLoaded = true;
},
+
/**
The filterFunction is a function used to test records from the store to
determine if they should be part of the record array.
Example
```javascript
@@ -6371,10 +5629,11 @@
replace: function () {
throw new Error('The result of a client-side filter (on ' + this.modelName + ') is immutable.');
},
+
/**
@method updateFilter
@private
*/
_updateFilter: function () {
@@ -6382,34 +5641,24 @@
return;
}
get(this, 'manager').updateFilter(this, this.modelName, get(this, 'filterFunction'));
},
+
updateFilter: _ember.default.observer('filterFunction', function () {
_ember.default.run.once(this, this._updateFilter);
})
});
});
-define("ember-data/-private/system/record-arrays/record-array", ["exports", "ember", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/snapshot-record-array"], function (exports, _ember, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemSnapshotRecordArray) {
- var computed = _ember.default.computed;
- var get = _ember.default.get;
- var set = _ember.default.set;
- var Promise = _ember.default.RSVP.Promise;
+define("ember-data/-private/system/record-arrays/record-array", ["exports", "ember", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/snapshot-record-array"], function (exports, _ember, _promiseProxies, _snapshotRecordArray) {
+ "use strict";
- /**
- A record array is an array that contains records of a certain modelName. The record
- array materializes records as needed when they are retrieved for the first
- time. You should not create record arrays yourself. Instead, an instance of
- `DS.RecordArray` or its subclasses will be returned by your application's store
- in response to queries.
-
- @class RecordArray
- @namespace DS
- @extends Ember.ArrayProxy
- @uses Ember.Evented
- */
-
+ exports.__esModule = true;
+ var computed = _ember.default.computed,
+ get = _ember.default.get,
+ set = _ember.default.set,
+ Promise = _ember.default.RSVP.Promise;
exports.default = _ember.default.ArrayProxy.extend(_ember.default.Evented, {
init: function () {
this._super.apply(this, arguments);
/**
@@ -6455,15 +5704,15 @@
@type DS.Store
*/
this.store = this.store || null;
this._updatingPromise = null;
},
-
replace: function () {
throw new Error("The result of a server query (for all " + this.modelName + " types) is immutable. To modify contents, use toArray()");
},
+
/**
The modelClass represented by this record array.
@property type
@type DS.Model
*/
@@ -6484,10 +5733,11 @@
objectAtContent: function (index) {
var internalModel = get(this, 'content').objectAt(index);
return internalModel && internalModel.getRecord();
},
+
/**
Used to get the latest version of all of the records in this array
from the adapter.
Example
```javascript
@@ -6520,18 +5770,20 @@
this._updatingPromise = updatingPromise;
return updatingPromise;
},
+
/*
Update this RecordArray and return a promise which resolves once the update
is finished.
*/
_update: function () {
return this.store.findAll(this.modelName, { reload: true });
},
+
/**
Adds an internal model to the `RecordArray` without duplicates
@method addInternalModel
@private
@param {InternalModel} internalModel
@@ -6541,20 +5793,22 @@
// consulted for inclusion, so addObject and its on .contains call is not
// required.
get(this, 'content').pushObjects(internalModels);
},
+
/**
Removes an internalModel to the `RecordArray`.
@method removeInternalModel
@private
@param {InternalModel} internalModel
*/
_removeInternalModels: function (internalModels) {
get(this, 'content').removeObjects(internalModels);
},
+
/**
Saves all of the records in the `RecordArray`.
Example
```javascript
var messages = store.peekAll('message');
@@ -6572,13 +5826,12 @@
var promiseLabel = "DS: RecordArray#save " + this.modelName;
var promise = Promise.all(this.invoke('save'), promiseLabel).then(function () {
return _this2;
}, null, 'DS: RecordArray#save return RecordArray');
- return _emberDataPrivateSystemPromiseProxies.PromiseArray.create({ promise: promise });
+ return _promiseProxies.PromiseArray.create({ promise: promise });
},
-
_dissociateFromOwnRecords: function () {
var _this3 = this;
this.get('content').forEach(function (internalModel) {
var recordArrays = internalModel.__recordArrays;
@@ -6587,18 +5840,18 @@
recordArrays.delete(_this3);
}
});
},
+
/**
@method _unregisterFromManager
@private
*/
_unregisterFromManager: function () {
this.manager.unregisterRecordArray(this);
},
-
willDestroy: function () {
this._unregisterFromManager();
this._dissociateFromOwnRecords();
// TODO: we should not do work during destroy:
// * when objects are destroyed, they should simply be left to do
@@ -6610,19 +5863,21 @@
set(this, 'content', null);
set(this, 'length', 0);
this._super.apply(this, arguments);
},
+
/*
@method _createSnapshot
@private
*/
_createSnapshot: function (options) {
// this is private for users, but public for ember-data internals
- return new _emberDataPrivateSystemSnapshotRecordArray.default(this, this.get('meta'), options);
+ return new _snapshotRecordArray.default(this, this.get('meta'), options);
},
+
/*
@method _takeSnapshot
@private
*/
_takeSnapshot: function () {
@@ -6630,20 +5885,25 @@
return internalModel.createSnapshot();
});
}
});
});
-/**
- @module ember-data
-*/
-define('ember-data/-private/system/references', ['exports', 'ember-data/-private/system/references/record', 'ember-data/-private/system/references/belongs-to', 'ember-data/-private/system/references/has-many'], function (exports, _emberDataPrivateSystemReferencesRecord, _emberDataPrivateSystemReferencesBelongsTo, _emberDataPrivateSystemReferencesHasMany) {
- exports.RecordReference = _emberDataPrivateSystemReferencesRecord.default;
- exports.BelongsToReference = _emberDataPrivateSystemReferencesBelongsTo.default;
- exports.HasManyReference = _emberDataPrivateSystemReferencesHasMany.default;
+define('ember-data/-private/system/references', ['exports', 'ember-data/-private/system/references/record', 'ember-data/-private/system/references/belongs-to', 'ember-data/-private/system/references/has-many'], function (exports, _record, _belongsTo, _hasMany) {
+ 'use strict';
+
+ exports.__esModule = true;
+ exports.HasManyReference = exports.BelongsToReference = exports.RecordReference = undefined;
+ exports.RecordReference = _record.default;
+ exports.BelongsToReference = _belongsTo.default;
+ exports.HasManyReference = _hasMany.default;
});
-define('ember-data/-private/system/references/belongs-to', ['exports', 'ember-data/model', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/features', 'ember-data/-private/debug'], function (exports, _emberDataModel, _ember, _emberDataPrivateSystemReferencesReference, _emberDataPrivateFeatures, _emberDataPrivateDebug) {
+define('ember-data/-private/system/references/belongs-to', ['exports', 'ember-data/model', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/features', 'ember-data/-private/debug'], function (exports, _model, _ember, _reference, _features, _debug) {
+ 'use strict';
+ exports.__esModule = true;
+
+
/**
A BelongsToReference is a low level API that allows users and
addon author to perform meta-operations on a belongs-to
relationship.
@@ -6658,13 +5918,13 @@
this.parent = parentInternalModel.recordReference;
// TODO inverse
};
- BelongsToReference.prototype = Object.create(_emberDataPrivateSystemReferencesReference.default.prototype);
+ BelongsToReference.prototype = Object.create(_reference.default.prototype);
BelongsToReference.prototype.constructor = BelongsToReference;
- BelongsToReference.prototype._super$constructor = _emberDataPrivateSystemReferencesReference.default;
+ BelongsToReference.prototype._super$constructor = _reference.default;
/**
This returns a string that represents how the reference will be
looked up when it is loaded. If the relationship has a link it will
use the "link" otherwise it defaults to "id".
@@ -6877,14 +6137,14 @@
*/
BelongsToReference.prototype.push = function (objectOrPromise) {
var _this = this;
return _ember.default.RSVP.resolve(objectOrPromise).then(function (data) {
- var record = undefined;
+ var record = void 0;
- if (data instanceof _emberDataModel.default) {
- if ((0, _emberDataPrivateFeatures.default)('ds-overhaul-references')) {}
+ if (data instanceof _model.default) {
+ if ((0, _features.default)('ds-overhaul-references')) {}
record = data;
} else {
record = _this.store.push(data);
}
@@ -7043,14 +6303,18 @@
});
};
exports.default = BelongsToReference;
});
-define('ember-data/-private/system/references/has-many', ['exports', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/debug', 'ember-data/-private/features'], function (exports, _ember, _emberDataPrivateSystemReferencesReference, _emberDataPrivateDebug, _emberDataPrivateFeatures) {
- var resolve = _ember.default.RSVP.resolve;
- var get = _ember.default.get;
+define('ember-data/-private/system/references/has-many', ['exports', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/debug', 'ember-data/-private/features'], function (exports, _ember, _reference, _debug, _features) {
+ 'use strict';
+ exports.__esModule = true;
+ var resolve = _ember.default.RSVP.resolve,
+ get = _ember.default.get;
+
+
/**
A HasManyReference is a low level API that allows users and addon
author to perform meta-operations on a has-many relationship.
@class HasManyReference
@@ -7063,13 +6327,13 @@
this.parent = parentInternalModel.recordReference;
// TODO inverse
};
- HasManyReference.prototype = Object.create(_emberDataPrivateSystemReferencesReference.default.prototype);
+ HasManyReference.prototype = Object.create(_reference.default.prototype);
HasManyReference.prototype.constructor = HasManyReference;
- HasManyReference.prototype._super$constructor = _emberDataPrivateSystemReferencesReference.default;
+ HasManyReference.prototype._super$constructor = _reference.default;
/**
This returns a string that represents how the reference will be
looked up when it is loaded. If the relationship has a link it will
use the "link" otherwise it defaults to "id".
@@ -7285,25 +6549,25 @@
var _this = this;
return resolve(objectOrPromise).then(function (payload) {
var array = payload;
- if ((0, _emberDataPrivateFeatures.default)("ds-overhaul-references")) {}
+ if ((0, _features.default)("ds-overhaul-references")) {}
var useLegacyArrayPush = true;
if (typeof payload === "object" && payload.data) {
array = payload.data;
useLegacyArrayPush = array.length && array[0].data;
- if ((0, _emberDataPrivateFeatures.default)('ds-overhaul-references')) {}
+ if ((0, _features.default)('ds-overhaul-references')) {}
}
- if (!(0, _emberDataPrivateFeatures.default)('ds-overhaul-references')) {
+ if (!(0, _features.default)('ds-overhaul-references')) {
useLegacyArrayPush = true;
}
- var internalModels = undefined;
+ var internalModels = void 0;
if (useLegacyArrayPush) {
internalModels = array.map(function (obj) {
var record = _this.store.push(obj);
return record._internalModel;
@@ -7461,12 +6725,16 @@
return this.hasManyRelationship.reload();
};
exports.default = HasManyReference;
});
-define('ember-data/-private/system/references/record', ['exports', 'ember', 'ember-data/-private/system/references/reference'], function (exports, _ember, _emberDataPrivateSystemReferencesReference) {
+define('ember-data/-private/system/references/record', ['exports', 'ember', 'ember-data/-private/system/references/reference'], function (exports, _ember, _reference) {
+ 'use strict';
+ exports.__esModule = true;
+
+
/**
An RecordReference is a low level API that allows users and
addon author to perform meta-operations on a record.
@class RecordReference
@@ -7476,13 +6744,13 @@
this._super$constructor(store, internalModel);
this.type = internalModel.modelName;
this._id = internalModel.id;
};
- RecordReference.prototype = Object.create(_emberDataPrivateSystemReferencesReference.default.prototype);
+ RecordReference.prototype = Object.create(_reference.default.prototype);
RecordReference.prototype.constructor = RecordReference;
- RecordReference.prototype._super$constructor = _emberDataPrivateSystemReferencesReference.default;
+ RecordReference.prototype._super$constructor = _reference.default;
/**
The `id` of the record that this reference refers to.
Together, the `type` and `id` properties form a composite key for
@@ -7627,10 +6895,13 @@
};
exports.default = RecordReference;
});
define("ember-data/-private/system/references/reference", ["exports"], function (exports) {
+ "use strict";
+
+ exports.__esModule = true;
var Reference = function (store, internalModel) {
this.store = store;
this.internalModel = internalModel;
};
@@ -7638,20 +6909,22 @@
constructor: Reference
};
exports.default = Reference;
});
-define('ember-data/-private/system/relationship-meta', ['exports', 'ember-inflector', 'ember-data/-private/system/normalize-model-name'], function (exports, _emberInflector, _emberDataPrivateSystemNormalizeModelName) {
+define('ember-data/-private/system/relationship-meta', ['exports', 'ember-inflector', 'ember-data/-private/system/normalize-model-name'], function (exports, _emberInflector, _normalizeModelName) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.typeForRelationshipMeta = typeForRelationshipMeta;
exports.relationshipFromMeta = relationshipFromMeta;
-
function typeForRelationshipMeta(meta) {
- var modelName = undefined;
+ var modelName = void 0;
modelName = meta.type || meta.key;
if (meta.kind === 'hasMany') {
- modelName = (0, _emberInflector.singularize)((0, _emberDataPrivateSystemNormalizeModelName.default)(modelName));
+ modelName = (0, _emberInflector.singularize)((0, _normalizeModelName.default)(modelName));
}
return modelName;
}
function relationshipFromMeta(meta) {
@@ -7664,13 +6937,17 @@
parentType: meta.parentType,
isRelationship: true
};
}
});
-define("ember-data/-private/system/relationships/belongs-to", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/normalize-model-name"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemNormalizeModelName) {
+define("ember-data/-private/system/relationships/belongs-to", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/normalize-model-name"], function (exports, _ember, _debug, _normalizeModelName) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = belongsTo;
+
/**
`DS.belongsTo` is used to define One-To-One and One-To-Many
relationships on a [DS.Model](/api/data/classes/DS.Model.html).
@@ -7739,24 +7016,23 @@
@for DS
@param {String} modelName (optional) type of the relationship
@param {Object} options (optional) a hash of options
@return {Ember.computed} relationship
*/
-
function belongsTo(modelName, options) {
- var opts = undefined,
- userEnteredModelName = undefined;
+ var opts = void 0,
+ userEnteredModelName = void 0;
if (typeof modelName === 'object') {
opts = modelName;
userEnteredModelName = undefined;
} else {
opts = options;
userEnteredModelName = modelName;
}
if (typeof userEnteredModelName === 'string') {
- userEnteredModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(userEnteredModelName);
+ userEnteredModelName = (0, _normalizeModelName.default)(userEnteredModelName);
}
opts = opts || {};
var meta = {
@@ -7791,16 +7067,21 @@
return this._internalModel._relationships.get(key).getRecord();
}
}).meta(meta);
}
});
-define("ember-data/-private/system/relationships/ext", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/relationship-meta"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemRelationshipMeta) {
+define("ember-data/-private/system/relationships/ext", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/relationship-meta"], function (exports, _ember, _debug, _relationshipMeta) {
+ "use strict";
+ exports.__esModule = true;
+ exports.relationshipsByNameDescriptor = exports.relatedTypesDescriptor = exports.relationshipsDescriptor = undefined;
+
+
var Map = _ember.default.Map;
var MapWithDefault = _ember.default.MapWithDefault;
- var relationshipsDescriptor = _ember.default.computed(function () {
+ var relationshipsDescriptor = exports.relationshipsDescriptor = _ember.default.computed(function () {
if (_ember.default.testing === true && relationshipsDescriptor._cacheable === true) {
relationshipsDescriptor._cacheable = false;
}
var map = new MapWithDefault({
@@ -7813,11 +7094,11 @@
this.eachComputedProperty(function (name, meta) {
// If the computed property is a relationship, add
// it to the map.
if (meta.isRelationship) {
meta.key = name;
- var relationshipsForType = map.get((0, _emberDataPrivateSystemRelationshipMeta.typeForRelationshipMeta)(meta));
+ var relationshipsForType = map.get((0, _relationshipMeta.typeForRelationshipMeta)(meta));
relationshipsForType.push({
name: name,
kind: meta.kind
});
@@ -7825,61 +7106,64 @@
});
return map;
}).readOnly();
- exports.relationshipsDescriptor = relationshipsDescriptor;
- var relatedTypesDescriptor = _ember.default.computed(function () {
+ var relatedTypesDescriptor = exports.relatedTypesDescriptor = _ember.default.computed(function () {
+ var _this = this;
+
if (_ember.default.testing === true && relatedTypesDescriptor._cacheable === true) {
relatedTypesDescriptor._cacheable = false;
}
- var modelName = undefined;
+ var modelName = void 0;
var types = _ember.default.A();
// Loop through each computed property on the class,
// and create an array of the unique types involved
// in relationships
this.eachComputedProperty(function (name, meta) {
if (meta.isRelationship) {
meta.key = name;
- modelName = (0, _emberDataPrivateSystemRelationshipMeta.typeForRelationshipMeta)(meta);
+ modelName = (0, _relationshipMeta.typeForRelationshipMeta)(meta);
if (!types.includes(modelName)) {
types.push(modelName);
}
}
});
return types;
}).readOnly();
- exports.relatedTypesDescriptor = relatedTypesDescriptor;
- var relationshipsByNameDescriptor = _ember.default.computed(function () {
+ var relationshipsByNameDescriptor = exports.relationshipsByNameDescriptor = _ember.default.computed(function () {
if (_ember.default.testing === true && relationshipsByNameDescriptor._cacheable === true) {
relationshipsByNameDescriptor._cacheable = false;
}
var map = Map.create();
this.eachComputedProperty(function (name, meta) {
if (meta.isRelationship) {
meta.key = name;
- var relationship = (0, _emberDataPrivateSystemRelationshipMeta.relationshipFromMeta)(meta);
- relationship.type = (0, _emberDataPrivateSystemRelationshipMeta.typeForRelationshipMeta)(meta);
+ var relationship = (0, _relationshipMeta.relationshipFromMeta)(meta);
+ relationship.type = (0, _relationshipMeta.typeForRelationshipMeta)(meta);
map.set(name, relationship);
}
});
return map;
}).readOnly();
- exports.relationshipsByNameDescriptor = relationshipsByNameDescriptor;
});
-define("ember-data/-private/system/relationships/has-many", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/is-array-like"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateSystemIsArrayLike) {
+define("ember-data/-private/system/relationships/has-many", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/is-array-like"], function (exports, _ember, _debug, _normalizeModelName, _isArrayLike) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = hasMany;
var get = _ember.default.get;
+
/**
`DS.hasMany` is used to define One-To-Many and Many-To-Many
relationships on a [DS.Model](/api/data/classes/DS.Model.html).
`DS.hasMany` takes an optional hash as a second parameter, currently
@@ -7982,21 +7266,20 @@
@for DS
@param {String} type (optional) type of the relationship
@param {Object} options (optional) a hash of options
@return {Ember.computed} relationship
*/
-
function hasMany(type, options) {
if (typeof type === 'object') {
options = type;
type = undefined;
}
options = options || {};
if (typeof type === 'string') {
- type = (0, _emberDataPrivateSystemNormalizeModelName.default)(type);
+ type = (0, _normalizeModelName.default)(type);
}
// Metadata about relationships is stored on the meta of
// the relationship. This is used for introspection and
// serialization. Note that `key` is populated lazily
@@ -8024,231 +7307,264 @@
return relationship.getRecords();
}
}).meta(meta);
}
});
-/**
- @module ember-data
-*/
-define("ember-data/-private/system/relationships/state/belongs-to", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/relationships/state/relationship"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemRelationshipsStateRelationship) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define("ember-data/-private/system/relationships/state/belongs-to", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/relationships/state/relationship"], function (exports, _ember, _debug, _promiseProxies, _relationship) {
+ "use strict";
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
+ exports.__esModule = true;
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
+ function _possibleConstructorReturn(self, call) {
+ if (!self) {
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
+ }
- var BelongsToRelationship = (function (_Relationship) {
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
+ }
+
+ function _inherits(subClass, superClass) {
+ if (typeof superClass !== "function" && superClass !== null) {
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
+ }
+
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
+ constructor: {
+ value: subClass,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
+ }
+
+ var BelongsToRelationship = function (_Relationship) {
_inherits(BelongsToRelationship, _Relationship);
function BelongsToRelationship(store, internalModel, inverseKey, relationshipMeta) {
- _get(Object.getPrototypeOf(BelongsToRelationship.prototype), "constructor", this).call(this, store, internalModel, inverseKey, relationshipMeta);
- this.internalModel = internalModel;
- this.key = relationshipMeta.key;
- this.inverseRecord = null;
- this.canonicalState = null;
+ var _this = _possibleConstructorReturn(this, _Relationship.call(this, store, internalModel, inverseKey, relationshipMeta));
+
+ _this.internalModel = internalModel;
+ _this.key = relationshipMeta.key;
+ _this.inverseRecord = null;
+ _this.canonicalState = null;
+ return _this;
}
- _createClass(BelongsToRelationship, [{
- key: "setRecord",
- value: function setRecord(newRecord) {
- if (newRecord) {
- this.addRecord(newRecord);
- } else if (this.inverseRecord) {
- this.removeRecord(this.inverseRecord);
- }
- this.setHasData(true);
- this.setHasLoaded(true);
+ BelongsToRelationship.prototype.setRecord = function setRecord(newRecord) {
+ if (newRecord) {
+ this.addRecord(newRecord);
+ } else if (this.inverseRecord) {
+ this.removeRecord(this.inverseRecord);
}
- }, {
- key: "setCanonicalRecord",
- value: function setCanonicalRecord(newRecord) {
- if (newRecord) {
- this.addCanonicalRecord(newRecord);
- } else if (this.canonicalState) {
- this.removeCanonicalRecord(this.canonicalState);
- }
- this.flushCanonicalLater();
+ this.setHasData(true);
+ this.setHasLoaded(true);
+ };
+
+ BelongsToRelationship.prototype.setCanonicalRecord = function setCanonicalRecord(newRecord) {
+ if (newRecord) {
+ this.addCanonicalRecord(newRecord);
+ } else if (this.canonicalState) {
+ this.removeCanonicalRecord(this.canonicalState);
}
- }, {
- key: "addCanonicalRecord",
- value: function addCanonicalRecord(newRecord) {
- if (this.canonicalMembers.has(newRecord)) {
- return;
- }
+ this.flushCanonicalLater();
+ };
- if (this.canonicalState) {
- this.removeCanonicalRecord(this.canonicalState);
- }
-
- this.canonicalState = newRecord;
- _get(Object.getPrototypeOf(BelongsToRelationship.prototype), "addCanonicalRecord", this).call(this, newRecord);
+ BelongsToRelationship.prototype.addCanonicalRecord = function addCanonicalRecord(newRecord) {
+ if (this.canonicalMembers.has(newRecord)) {
+ return;
}
- }, {
- key: "inverseDidDematerialize",
- value: function inverseDidDematerialize() {
- this.notifyBelongsToChanged();
- }
- }, {
- key: "flushCanonical",
- value: function flushCanonical() {
- //temporary fix to not remove newly created records if server returned null.
- //TODO remove once we have proper diffing
- if (this.inverseRecord && this.inverseRecord.isNew() && !this.canonicalState) {
- return;
- }
- if (this.inverseRecord !== this.canonicalState) {
- this.inverseRecord = this.canonicalState;
- this.notifyBelongsToChanged();
- }
- _get(Object.getPrototypeOf(BelongsToRelationship.prototype), "flushCanonical", this).call(this);
+ if (this.canonicalState) {
+ this.removeCanonicalRecord(this.canonicalState);
}
- }, {
- key: "addRecord",
- value: function addRecord(newRecord) {
- if (this.members.has(newRecord)) {
- return;
- }
- if (this.inverseRecord) {
- this.removeRecord(this.inverseRecord);
- }
+ this.canonicalState = newRecord;
+ _Relationship.prototype.addCanonicalRecord.call(this, newRecord);
+ };
- this.inverseRecord = newRecord;
- _get(Object.getPrototypeOf(BelongsToRelationship.prototype), "addRecord", this).call(this, newRecord);
- this.notifyBelongsToChanged();
- }
- }, {
- key: "setRecordPromise",
- value: function setRecordPromise(newPromise) {
- var content = newPromise.get && newPromise.get('content');
+ BelongsToRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
+ this.notifyBelongsToChanged();
+ };
- this.setRecord(content ? content._internalModel : content);
+ BelongsToRelationship.prototype.flushCanonical = function flushCanonical() {
+ //temporary fix to not remove newly created records if server returned null.
+ //TODO remove once we have proper diffing
+ if (this.inverseRecord && this.inverseRecord.isNew() && !this.canonicalState) {
+ return;
}
- }, {
- key: "removeRecordFromOwn",
- value: function removeRecordFromOwn(record) {
- if (!this.members.has(record)) {
- return;
- }
- this.inverseRecord = null;
- _get(Object.getPrototypeOf(BelongsToRelationship.prototype), "removeRecordFromOwn", this).call(this, record);
+ if (this.inverseRecord !== this.canonicalState) {
+ this.inverseRecord = this.canonicalState;
this.notifyBelongsToChanged();
}
- }, {
- key: "notifyBelongsToChanged",
- value: function notifyBelongsToChanged() {
- this.internalModel.notifyBelongsToChanged(this.key);
+
+ _Relationship.prototype.flushCanonical.call(this);
+ };
+
+ BelongsToRelationship.prototype.addRecord = function addRecord(newRecord) {
+ if (this.members.has(newRecord)) {
+ return;
}
- }, {
- key: "removeCanonicalRecordFromOwn",
- value: function removeCanonicalRecordFromOwn(record) {
- if (!this.canonicalMembers.has(record)) {
- return;
- }
- this.canonicalState = null;
- _get(Object.getPrototypeOf(BelongsToRelationship.prototype), "removeCanonicalRecordFromOwn", this).call(this, record);
+
+ if (this.inverseRecord) {
+ this.removeRecord(this.inverseRecord);
}
- }, {
- key: "findRecord",
- value: function findRecord() {
- if (this.inverseRecord) {
- return this.store._findByInternalModel(this.inverseRecord);
- } else {
- return _ember.default.RSVP.Promise.resolve(null);
- }
+
+ this.inverseRecord = newRecord;
+ _Relationship.prototype.addRecord.call(this, newRecord);
+ this.notifyBelongsToChanged();
+ };
+
+ BelongsToRelationship.prototype.setRecordPromise = function setRecordPromise(newPromise) {
+ var content = newPromise.get && newPromise.get('content');
+
+ this.setRecord(content ? content._internalModel : content);
+ };
+
+ BelongsToRelationship.prototype.removeRecordFromOwn = function removeRecordFromOwn(record) {
+ if (!this.members.has(record)) {
+ return;
}
- }, {
- key: "fetchLink",
- value: function fetchLink() {
- var _this = this;
+ this.inverseRecord = null;
+ _Relationship.prototype.removeRecordFromOwn.call(this, record);
+ this.notifyBelongsToChanged();
+ };
- return this.store.findBelongsTo(this.internalModel, this.link, this.relationshipMeta).then(function (record) {
- if (record) {
- _this.addRecord(record);
- }
- return record;
- });
+ BelongsToRelationship.prototype.notifyBelongsToChanged = function notifyBelongsToChanged() {
+ this.internalModel.notifyBelongsToChanged(this.key);
+ };
+
+ BelongsToRelationship.prototype.removeCanonicalRecordFromOwn = function removeCanonicalRecordFromOwn(record) {
+ if (!this.canonicalMembers.has(record)) {
+ return;
}
- }, {
- key: "getRecord",
- value: function getRecord() {
- var _this2 = this;
+ this.canonicalState = null;
+ _Relationship.prototype.removeCanonicalRecordFromOwn.call(this, record);
+ };
- //TODO(Igor) flushCanonical here once our syncing is not stupid
- if (this.isAsync) {
- var promise = undefined;
- if (this.link) {
- if (this.hasLoaded) {
- promise = this.findRecord();
- } else {
- promise = this.findLink().then(function () {
- return _this2.findRecord();
- });
- }
- } else {
- promise = this.findRecord();
- }
+ BelongsToRelationship.prototype.findRecord = function findRecord() {
+ if (this.inverseRecord) {
+ return this.store._findByInternalModel(this.inverseRecord);
+ } else {
+ return _ember.default.RSVP.Promise.resolve(null);
+ }
+ };
- return _emberDataPrivateSystemPromiseProxies.PromiseObject.create({
- promise: promise,
- content: this.inverseRecord ? this.inverseRecord.getRecord() : null
- });
- } else {
- if (this.inverseRecord === null) {
- return null;
- }
- var toReturn = this.inverseRecord.getRecord();
+ BelongsToRelationship.prototype.fetchLink = function fetchLink() {
+ var _this2 = this;
- return toReturn;
+ return this.store.findBelongsTo(this.internalModel, this.link, this.relationshipMeta).then(function (record) {
+ if (record) {
+ _this2.addRecord(record);
}
- }
- }, {
- key: "reload",
- value: function reload() {
- // TODO handle case when reload() is triggered multiple times
+ return record;
+ });
+ };
+ BelongsToRelationship.prototype.getRecord = function getRecord() {
+ var _this3 = this;
+
+ //TODO(Igor) flushCanonical here once our syncing is not stupid
+ if (this.isAsync) {
+ var promise = void 0;
if (this.link) {
- return this.fetchLink();
+ if (this.hasLoaded) {
+ promise = this.findRecord();
+ } else {
+ promise = this.findLink().then(function () {
+ return _this3.findRecord();
+ });
+ }
+ } else {
+ promise = this.findRecord();
}
- // reload record, if it is already loaded
- if (this.inverseRecord && this.inverseRecord.hasRecord) {
- return this.inverseRecord.record.reload();
+ return _promiseProxies.PromiseObject.create({
+ promise: promise,
+ content: this.inverseRecord ? this.inverseRecord.getRecord() : null
+ });
+ } else {
+ if (this.inverseRecord === null) {
+ return null;
}
+ var toReturn = this.inverseRecord.getRecord();
- return this.findRecord();
+ return toReturn;
}
- }, {
- key: "updateData",
- value: function updateData(data) {
- var internalModel = this.store._pushResourceIdentifier(this, data);
- this.setCanonicalRecord(internalModel);
+ };
+
+ BelongsToRelationship.prototype.reload = function reload() {
+ // TODO handle case when reload() is triggered multiple times
+
+ if (this.link) {
+ return this.fetchLink();
}
- }]);
+ // reload record, if it is already loaded
+ if (this.inverseRecord && this.inverseRecord.hasRecord) {
+ return this.inverseRecord.record.reload();
+ }
+
+ return this.findRecord();
+ };
+
+ BelongsToRelationship.prototype.updateData = function updateData(data) {
+ var internalModel = this.store._pushResourceIdentifier(this, data);
+ this.setCanonicalRecord(internalModel);
+ };
+
return BelongsToRelationship;
- })(_emberDataPrivateSystemRelationshipsStateRelationship.default);
+ }(_relationship.default);
exports.default = BelongsToRelationship;
});
-define("ember-data/-private/system/relationships/state/create", ["exports", "ember", "ember-data/-private/system/relationships/state/has-many", "ember-data/-private/system/relationships/state/belongs-to", "ember-data/-private/system/empty-object", "ember-data/-private/debug"], function (exports, _ember, _emberDataPrivateSystemRelationshipsStateHasMany, _emberDataPrivateSystemRelationshipsStateBelongsTo, _emberDataPrivateSystemEmptyObject, _emberDataPrivateDebug) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define("ember-data/-private/system/relationships/state/create", ["exports", "ember", "ember-data/-private/system/relationships/state/has-many", "ember-data/-private/system/relationships/state/belongs-to", "ember-data/-private/system/empty-object", "ember-data/-private/debug"], function (exports, _ember, _hasMany, _belongsTo, _emptyObject, _debug) {
+ "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+ exports.__esModule = true;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+
+ var _createClass = function () {
+ function defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
+ }
+
+ return function (Constructor, protoProps, staticProps) {
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) defineProperties(Constructor, staticProps);
+ return Constructor;
+ };
+ }();
+
var _get = _ember.default.get;
+
function shouldFindInverse(relationshipMeta) {
var options = relationshipMeta.options;
return !(options && options.inverse === null);
}
function createRelationshipFor(internalModel, relationshipMeta, store) {
- var inverseKey = undefined;
+ var inverseKey = void 0;
var inverse = null;
if (shouldFindInverse(relationshipMeta)) {
inverse = internalModel.type.inverseFor(relationshipMeta.key, store);
} else {}
@@ -8256,327 +7572,355 @@
if (inverse) {
inverseKey = inverse.name;
}
if (relationshipMeta.kind === 'hasMany') {
- return new _emberDataPrivateSystemRelationshipsStateHasMany.default(store, internalModel, inverseKey, relationshipMeta);
+ return new _hasMany.default(store, internalModel, inverseKey, relationshipMeta);
} else {
- return new _emberDataPrivateSystemRelationshipsStateBelongsTo.default(store, internalModel, inverseKey, relationshipMeta);
+ return new _belongsTo.default(store, internalModel, inverseKey, relationshipMeta);
}
}
- var Relationships = (function () {
+ var Relationships = function () {
function Relationships(internalModel) {
this.internalModel = internalModel;
- this.initializedRelationships = new _emberDataPrivateSystemEmptyObject.default();
+ this.initializedRelationships = new _emptyObject.default();
}
// TODO @runspired deprecate this as it was never truly a record instance
- _createClass(Relationships, [{
- key: "has",
- value: function has(key) {
- return !!this.initializedRelationships[key];
- }
- }, {
- key: "get",
- value: function get(key) {
- var relationships = this.initializedRelationships;
- var relationship = relationships[key];
- if (!relationship) {
- var internalModel = this.internalModel;
- var relationshipsByName = _get(internalModel.type, 'relationshipsByName');
- var rel = relationshipsByName.get(key);
+ Relationships.prototype.has = function has(key) {
+ return !!this.initializedRelationships[key];
+ };
- if (rel) {
- relationship = relationships[key] = createRelationshipFor(internalModel, rel, internalModel.store);
- }
- }
+ Relationships.prototype.get = function get(key) {
+ var relationships = this.initializedRelationships;
+ var relationship = relationships[key];
- return relationship;
+ if (!relationship) {
+ var internalModel = this.internalModel;
+ var relationshipsByName = _get(internalModel.type, 'relationshipsByName');
+ var rel = relationshipsByName.get(key);
+
+ if (rel) {
+ relationship = relationships[key] = createRelationshipFor(internalModel, rel, internalModel.store);
+ }
}
- }, {
+
+ return relationship;
+ };
+
+ _createClass(Relationships, [{
key: "record",
get: function () {
return this.internalModel;
}
}]);
return Relationships;
- })();
+ }();
exports.default = Relationships;
});
-define('ember-data/-private/system/relationships/state/has-many', ['exports', 'ember-data/-private/debug', 'ember-data/-private/system/promise-proxies', 'ember-data/-private/system/relationships/state/relationship', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/many-array'], function (exports, _emberDataPrivateDebug, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemRelationshipsStateRelationship, _emberDataPrivateSystemOrderedSet, _emberDataPrivateSystemManyArray) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define('ember-data/-private/system/relationships/state/has-many', ['exports', 'ember-data/-private/debug', 'ember-data/-private/system/promise-proxies', 'ember-data/-private/system/relationships/state/relationship', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/many-array'], function (exports, _debug, _promiseProxies, _relationship, _orderedSet, _manyArray) {
+ 'use strict';
- var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
+ exports.__esModule = true;
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
- function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
+ var _createClass = function () {
+ function defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
+ }
- var ManyRelationship = (function (_Relationship) {
+ return function (Constructor, protoProps, staticProps) {
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) defineProperties(Constructor, staticProps);
+ return Constructor;
+ };
+ }();
+
+ function _possibleConstructorReturn(self, call) {
+ if (!self) {
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
+ }
+
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
+ }
+
+ function _inherits(subClass, superClass) {
+ if (typeof superClass !== "function" && superClass !== null) {
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
+ }
+
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
+ constructor: {
+ value: subClass,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
+ }
+
+ var ManyRelationship = function (_Relationship) {
_inherits(ManyRelationship, _Relationship);
function ManyRelationship(store, record, inverseKey, relationshipMeta) {
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'constructor', this).call(this, store, record, inverseKey, relationshipMeta);
- this.belongsToType = relationshipMeta.type;
- this.canonicalState = [];
- this.isPolymorphic = relationshipMeta.options.polymorphic;
- this._manyArray = null;
- this.__loadingPromise = null;
+ var _this = _possibleConstructorReturn(this, _Relationship.call(this, store, record, inverseKey, relationshipMeta));
+
+ _this.belongsToType = relationshipMeta.type;
+ _this.canonicalState = [];
+ _this.isPolymorphic = relationshipMeta.options.polymorphic;
+ _this._manyArray = null;
+ _this.__loadingPromise = null;
+ return _this;
}
- _createClass(ManyRelationship, [{
- key: '_updateLoadingPromise',
- value: function _updateLoadingPromise(promise, content) {
- if (this.__loadingPromise) {
- if (content) {
- this.__loadingPromise.set('content', content);
- }
- this.__loadingPromise.set('promise', promise);
- } else {
- this.__loadingPromise = new _emberDataPrivateSystemPromiseProxies.PromiseManyArray({
- promise: promise,
- content: content
- });
+ ManyRelationship.prototype._updateLoadingPromise = function _updateLoadingPromise(promise, content) {
+ if (this.__loadingPromise) {
+ if (content) {
+ this.__loadingPromise.set('content', content);
}
+ this.__loadingPromise.set('promise', promise);
+ } else {
+ this.__loadingPromise = new _promiseProxies.PromiseManyArray({
+ promise: promise,
+ content: content
+ });
+ }
- return this.__loadingPromise;
+ return this.__loadingPromise;
+ };
+
+ ManyRelationship.prototype.destroy = function destroy() {
+ _Relationship.prototype.destroy.call(this);
+ if (this._manyArray) {
+ this._manyArray.destroy();
+ this._manyArray = null;
}
- }, {
- key: 'destroy',
- value: function destroy() {
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'destroy', this).call(this);
- if (this._manyArray) {
- this._manyArray.destroy();
- this._manyArray = null;
- }
- if (this._loadingPromise) {
- this._loadingPromise.destroy();
- }
+ if (this._loadingPromise) {
+ this._loadingPromise.destroy();
}
- }, {
- key: 'updateMeta',
- value: function updateMeta(meta) {
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'updateMeta', this).call(this, meta);
- if (this._manyArray) {
- this._manyArray.set('meta', meta);
- }
+ };
+
+ ManyRelationship.prototype.updateMeta = function updateMeta(meta) {
+ _Relationship.prototype.updateMeta.call(this, meta);
+ if (this._manyArray) {
+ this._manyArray.set('meta', meta);
}
- }, {
- key: 'addCanonicalRecord',
- value: function addCanonicalRecord(record, idx) {
- if (this.canonicalMembers.has(record)) {
- return;
- }
- if (idx !== undefined) {
- this.canonicalState.splice(idx, 0, record);
- } else {
- this.canonicalState.push(record);
- }
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'addCanonicalRecord', this).call(this, record, idx);
+ };
+
+ ManyRelationship.prototype.addCanonicalRecord = function addCanonicalRecord(record, idx) {
+ if (this.canonicalMembers.has(record)) {
+ return;
}
- }, {
- key: 'inverseDidDematerialize',
- value: function inverseDidDematerialize() {
- if (this._manyArray) {
- this._manyArray.destroy();
- this._manyArray = null;
- }
- this.notifyHasManyChanged();
+ if (idx !== undefined) {
+ this.canonicalState.splice(idx, 0, record);
+ } else {
+ this.canonicalState.push(record);
}
- }, {
- key: 'addRecord',
- value: function addRecord(record, idx) {
- if (this.members.has(record)) {
- return;
- }
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'addRecord', this).call(this, record, idx);
- // make lazy later
- this.manyArray.internalAddRecords([record], idx);
+ _Relationship.prototype.addCanonicalRecord.call(this, record, idx);
+ };
+
+ ManyRelationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {
+ if (this._manyArray) {
+ this._manyArray.destroy();
+ this._manyArray = null;
}
- }, {
- key: 'removeCanonicalRecordFromOwn',
- value: function removeCanonicalRecordFromOwn(record, idx) {
- var i = idx;
- if (!this.canonicalMembers.has(record)) {
- return;
- }
- if (i === undefined) {
- i = this.canonicalState.indexOf(record);
- }
- if (i > -1) {
- this.canonicalState.splice(i, 1);
- }
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'removeCanonicalRecordFromOwn', this).call(this, record, idx);
+ this.notifyHasManyChanged();
+ };
+
+ ManyRelationship.prototype.addRecord = function addRecord(record, idx) {
+ if (this.members.has(record)) {
+ return;
}
- }, {
- key: 'flushCanonical',
- value: function flushCanonical() {
- if (this._manyArray) {
- this._manyArray.flushCanonical();
- }
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'flushCanonical', this).call(this);
+ _Relationship.prototype.addRecord.call(this, record, idx);
+ // make lazy later
+ this.manyArray.internalAddRecords([record], idx);
+ };
+
+ ManyRelationship.prototype.removeCanonicalRecordFromOwn = function removeCanonicalRecordFromOwn(record, idx) {
+ var i = idx;
+ if (!this.canonicalMembers.has(record)) {
+ return;
}
- }, {
- key: 'removeRecordFromOwn',
- value: function removeRecordFromOwn(record, idx) {
- if (!this.members.has(record)) {
- return;
+ if (i === undefined) {
+ i = this.canonicalState.indexOf(record);
+ }
+ if (i > -1) {
+ this.canonicalState.splice(i, 1);
+ }
+ _Relationship.prototype.removeCanonicalRecordFromOwn.call(this, record, idx);
+ };
+
+ ManyRelationship.prototype.flushCanonical = function flushCanonical() {
+ if (this._manyArray) {
+ this._manyArray.flushCanonical();
+ }
+ _Relationship.prototype.flushCanonical.call(this);
+ };
+
+ ManyRelationship.prototype.removeRecordFromOwn = function removeRecordFromOwn(record, idx) {
+ if (!this.members.has(record)) {
+ return;
+ }
+ _Relationship.prototype.removeRecordFromOwn.call(this, record, idx);
+ var manyArray = this.manyArray;
+ if (idx !== undefined) {
+ //TODO(Igor) not used currently, fix
+ manyArray.currentState.removeAt(idx);
+ } else {
+ manyArray.internalRemoveRecords([record]);
+ }
+ };
+
+ ManyRelationship.prototype.notifyRecordRelationshipAdded = function notifyRecordRelationshipAdded(record, idx) {
+
+ this.record.notifyHasManyAdded(this.key, record, idx);
+ };
+
+ ManyRelationship.prototype.reload = function reload() {
+ var manyArray = this.manyArray;
+ var manyArrayLoadedState = manyArray.get('isLoaded');
+
+ if (this._loadingPromise) {
+ if (this._loadingPromise.get('isPending')) {
+ return this._loadingPromise;
}
- _get(Object.getPrototypeOf(ManyRelationship.prototype), 'removeRecordFromOwn', this).call(this, record, idx);
- var manyArray = this.manyArray;
- if (idx !== undefined) {
- //TODO(Igor) not used currently, fix
- manyArray.currentState.removeAt(idx);
- } else {
- manyArray.internalRemoveRecords([record]);
+ if (this._loadingPromise.get('isRejected')) {
+ manyArray.set('isLoaded', manyArrayLoadedState);
}
}
- }, {
- key: 'notifyRecordRelationshipAdded',
- value: function notifyRecordRelationshipAdded(record, idx) {
- this.record.notifyHasManyAdded(this.key, record, idx);
+ var promise = void 0;
+ if (this.link) {
+ promise = this.fetchLink();
+ } else {
+ promise = this.store._scheduleFetchMany(manyArray.currentState).then(function () {
+ return manyArray;
+ });
}
- }, {
- key: 'reload',
- value: function reload() {
- var manyArray = this.manyArray;
- var manyArrayLoadedState = manyArray.get('isLoaded');
- if (this._loadingPromise) {
- if (this._loadingPromise.get('isPending')) {
- return this._loadingPromise;
- }
- if (this._loadingPromise.get('isRejected')) {
- manyArray.set('isLoaded', manyArrayLoadedState);
- }
- }
+ this._updateLoadingPromise(promise);
+ return this._loadingPromise;
+ };
- var promise = undefined;
- if (this.link) {
- promise = this.fetchLink();
- } else {
- promise = this.store._scheduleFetchMany(manyArray.currentState).then(function () {
- return manyArray;
- });
+ ManyRelationship.prototype.computeChanges = function computeChanges(records) {
+ var members = this.canonicalMembers;
+ var recordsToRemove = [];
+ var recordSet = setForArray(records);
+
+ members.forEach(function (member) {
+ if (recordSet.has(member)) {
+ return;
}
- this._updateLoadingPromise(promise);
- return this._loadingPromise;
+ recordsToRemove.push(member);
+ });
+
+ this.removeCanonicalRecords(recordsToRemove);
+
+ for (var i = 0, l = records.length; i < l; i++) {
+ var record = records[i];
+ this.removeCanonicalRecord(record);
+ this.addCanonicalRecord(record, i);
}
- }, {
- key: 'computeChanges',
- value: function computeChanges(records) {
- var members = this.canonicalMembers;
- var recordsToRemove = [];
- var recordSet = setForArray(records);
+ };
- members.forEach(function (member) {
- if (recordSet.has(member)) {
- return;
- }
+ ManyRelationship.prototype.fetchLink = function fetchLink() {
+ var _this2 = this;
- recordsToRemove.push(member);
+ return this.store.findHasMany(this.record, this.link, this.relationshipMeta).then(function (records) {
+ if (records.hasOwnProperty('meta')) {
+ _this2.updateMeta(records.meta);
+ }
+ _this2.store._backburner.join(function () {
+ _this2.updateRecordsFromAdapter(records);
+ _this2.manyArray.set('isLoaded', true);
});
+ return _this2.manyArray;
+ });
+ };
- this.removeCanonicalRecords(recordsToRemove);
+ ManyRelationship.prototype.findRecords = function findRecords() {
+ var manyArray = this.manyArray;
+ var internalModels = manyArray.currentState;
- for (var i = 0, l = records.length; i < l; i++) {
- var record = records[i];
- this.removeCanonicalRecord(record);
- this.addCanonicalRecord(record, i);
+ //TODO CLEANUP
+ return this.store.findMany(internalModels).then(function () {
+ if (!manyArray.get('isDestroyed')) {
+ //Goes away after the manyArray refactor
+ manyArray.set('isLoaded', true);
}
- }
- }, {
- key: 'fetchLink',
- value: function fetchLink() {
- var _this = this;
+ return manyArray;
+ });
+ };
- return this.store.findHasMany(this.record, this.link, this.relationshipMeta).then(function (records) {
- if (records.hasOwnProperty('meta')) {
- _this.updateMeta(records.meta);
- }
- _this.store._backburner.join(function () {
- _this.updateRecordsFromAdapter(records);
- _this.manyArray.set('isLoaded', true);
- });
- return _this.manyArray;
- });
- }
- }, {
- key: 'findRecords',
- value: function findRecords() {
- var manyArray = this.manyArray;
- var internalModels = manyArray.currentState;
+ ManyRelationship.prototype.notifyHasManyChanged = function notifyHasManyChanged() {
+ this.record.notifyHasManyAdded(this.key);
+ };
- //TODO CLEANUP
- return this.store.findMany(internalModels).then(function () {
- if (!manyArray.get('isDestroyed')) {
- //Goes away after the manyArray refactor
- manyArray.set('isLoaded', true);
- }
- return manyArray;
- });
- }
- }, {
- key: 'notifyHasManyChanged',
- value: function notifyHasManyChanged() {
- this.record.notifyHasManyAdded(this.key);
- }
- }, {
- key: 'getRecords',
- value: function getRecords() {
- var _this2 = this;
+ ManyRelationship.prototype.getRecords = function getRecords() {
+ var _this3 = this;
- //TODO(Igor) sync server here, once our syncing is not stupid
- var manyArray = this.manyArray;
- if (this.isAsync) {
- var promise = undefined;
- if (this.link) {
- if (this.hasLoaded) {
- promise = this.findRecords();
- } else {
- promise = this.findLink().then(function () {
- return _this2.findRecords();
- });
- }
- } else {
+ //TODO(Igor) sync server here, once our syncing is not stupid
+ var manyArray = this.manyArray;
+ if (this.isAsync) {
+ var promise = void 0;
+ if (this.link) {
+ if (this.hasLoaded) {
promise = this.findRecords();
+ } else {
+ promise = this.findLink().then(function () {
+ return _this3.findRecords();
+ });
}
- return this._updateLoadingPromise(promise, manyArray);
} else {
+ promise = this.findRecords();
+ }
+ return this._updateLoadingPromise(promise, manyArray);
+ } else {
- //TODO(Igor) WTF DO I DO HERE?
- // TODO @runspired equal WTFs to Igor
- if (!manyArray.get('isDestroyed')) {
- manyArray.set('isLoaded', true);
- }
- return manyArray;
+ //TODO(Igor) WTF DO I DO HERE?
+ // TODO @runspired equal WTFs to Igor
+ if (!manyArray.get('isDestroyed')) {
+ manyArray.set('isLoaded', true);
}
+ return manyArray;
}
- }, {
- key: 'updateData',
- value: function updateData(data) {
- var internalModels = this.store._pushResourceIdentifiers(this, data);
- this.updateRecordsFromAdapter(internalModels);
- }
- }, {
+ };
+
+ ManyRelationship.prototype.updateData = function updateData(data) {
+ var internalModels = this.store._pushResourceIdentifiers(this, data);
+ this.updateRecordsFromAdapter(internalModels);
+ };
+
+ _createClass(ManyRelationship, [{
key: '_loadingPromise',
get: function () {
return this.__loadingPromise;
}
}, {
key: 'manyArray',
get: function () {
if (!this._manyArray) {
- this._manyArray = _emberDataPrivateSystemManyArray.default.create({
+ this._manyArray = _manyArray.default.create({
canonicalState: this.canonicalState,
store: this.store,
relationship: this,
type: this.store.modelFor(this.belongsToType),
record: this.record,
@@ -8587,36 +7931,61 @@
return this._manyArray;
}
}]);
return ManyRelationship;
- })(_emberDataPrivateSystemRelationshipsStateRelationship.default);
+ }(_relationship.default);
exports.default = ManyRelationship;
+
function setForArray(array) {
- var set = new _emberDataPrivateSystemOrderedSet.default();
+ var set = new _orderedSet.default();
if (array) {
for (var i = 0, l = array.length; i < l; i++) {
set.add(array[i]);
}
}
return set;
}
});
-define('ember-data/-private/system/relationships/state/relationship', ['exports', 'ember-data/-private/debug', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/normalize-link'], function (exports, _emberDataPrivateDebug, _emberDataPrivateSystemOrderedSet, _emberDataPrivateSystemNormalizeLink) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define('ember-data/-private/system/relationships/state/relationship', ['exports', 'ember-data/-private/debug', 'ember-data/-private/system/ordered-set', 'ember-data/-private/system/normalize-link'], function (exports, _debug, _orderedSet, _normalizeLink2) {
+ 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ exports.__esModule = true;
- var Relationship = (function () {
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+
+ var _createClass = function () {
+ function defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
+ }
+
+ return function (Constructor, protoProps, staticProps) {
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) defineProperties(Constructor, staticProps);
+ return Constructor;
+ };
+ }();
+
+ var Relationship = function () {
function Relationship(store, internalModel, inverseKey, relationshipMeta) {
var async = relationshipMeta.options.async;
- this.members = new _emberDataPrivateSystemOrderedSet.default();
- this.canonicalMembers = new _emberDataPrivateSystemOrderedSet.default();
+ this.members = new _orderedSet.default();
+ this.canonicalMembers = new _orderedSet.default();
this.store = store;
this.key = relationshipMeta.key;
this.inverseKey = inverseKey;
this.internalModel = internalModel;
this.isAsync = typeof async === 'undefined' ? true : async;
@@ -8630,341 +7999,288 @@
this.hasLoaded = false;
}
// TODO @runspired deprecate this as it was never truly a record instance
- _createClass(Relationship, [{
- key: 'destroy',
- value: function destroy() {
- var _this = this;
- if (!this.inverseKey) {
- return;
- }
+ Relationship.prototype.destroy = function destroy() {
+ var _this = this;
- var allMembers =
- // we actually want a union of members and canonicalMembers
- // they should be disjoint but currently are not due to a bug
- this.members.toArray().concat(this.canonicalMembers.toArray());
-
- allMembers.forEach(function (inverseInternalModel) {
- var relationship = inverseInternalModel._relationships.get(_this.inverseKey);
- // TODO: there is always a relationship in this case; this guard exists
- // because there are tests that fail in teardown after putting things in
- // invalid state
- if (relationship) {
- relationship.inverseDidDematerialize();
- }
- });
+ if (!this.inverseKey) {
+ return;
}
- }, {
- key: 'inverseDidDematerialize',
- value: function inverseDidDematerialize() {}
- }, {
- key: 'updateMeta',
- value: function updateMeta(meta) {
- this.meta = meta;
- }
- }, {
- key: 'clear',
- value: function clear() {
- var members = this.members.list;
- while (members.length > 0) {
- var member = members[0];
- this.removeRecord(member);
- }
+ var allMembers =
+ // we actually want a union of members and canonicalMembers
+ // they should be disjoint but currently are not due to a bug
+ this.members.toArray().concat(this.canonicalMembers.toArray());
- var canonicalMembers = this.canonicalMembers.list;
- while (canonicalMembers.length > 0) {
- var member = canonicalMembers[0];
- this.removeCanonicalRecord(member);
+ allMembers.forEach(function (inverseInternalModel) {
+ var relationship = inverseInternalModel._relationships.get(_this.inverseKey);
+ // TODO: there is always a relationship in this case; this guard exists
+ // because there are tests that fail in teardown after putting things in
+ // invalid state
+ if (relationship) {
+ relationship.inverseDidDematerialize();
}
- }
- }, {
- key: 'removeRecords',
- value: function removeRecords(records) {
- var _this2 = this;
+ });
+ };
- records.forEach(function (record) {
- return _this2.removeRecord(record);
- });
+ Relationship.prototype.inverseDidDematerialize = function inverseDidDematerialize() {};
+
+ Relationship.prototype.updateMeta = function updateMeta(meta) {
+ this.meta = meta;
+ };
+
+ Relationship.prototype.clear = function clear() {
+
+ var members = this.members.list;
+ while (members.length > 0) {
+ var member = members[0];
+ this.removeRecord(member);
}
- }, {
- key: 'addRecords',
- value: function addRecords(records, idx) {
- var _this3 = this;
- records.forEach(function (record) {
- _this3.addRecord(record, idx);
- if (idx !== undefined) {
- idx++;
- }
- });
+ var canonicalMembers = this.canonicalMembers.list;
+ while (canonicalMembers.length > 0) {
+ var _member = canonicalMembers[0];
+ this.removeCanonicalRecord(_member);
}
- }, {
- key: 'addCanonicalRecords',
- value: function addCanonicalRecords(records, idx) {
- for (var i = 0; i < records.length; i++) {
- if (idx !== undefined) {
- this.addCanonicalRecord(records[i], i + idx);
- } else {
- this.addCanonicalRecord(records[i]);
- }
+ };
+
+ Relationship.prototype.removeRecords = function removeRecords(records) {
+ var _this2 = this;
+
+ records.forEach(function (record) {
+ return _this2.removeRecord(record);
+ });
+ };
+
+ Relationship.prototype.addRecords = function addRecords(records, idx) {
+ var _this3 = this;
+
+ records.forEach(function (record) {
+ _this3.addRecord(record, idx);
+ if (idx !== undefined) {
+ idx++;
}
- }
- }, {
- key: 'addCanonicalRecord',
- value: function addCanonicalRecord(record, idx) {
- if (!this.canonicalMembers.has(record)) {
- this.canonicalMembers.add(record);
- if (this.inverseKey) {
- record._relationships.get(this.inverseKey).addCanonicalRecord(this.record);
- } else {
- if (!record._implicitRelationships[this.inverseKeyForImplicit]) {
- record._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, record, this.key, { options: {} });
- }
- record._implicitRelationships[this.inverseKeyForImplicit].addCanonicalRecord(this.record);
- }
+ });
+ };
+
+ Relationship.prototype.addCanonicalRecords = function addCanonicalRecords(records, idx) {
+ for (var i = 0; i < records.length; i++) {
+ if (idx !== undefined) {
+ this.addCanonicalRecord(records[i], i + idx);
+ } else {
+ this.addCanonicalRecord(records[i]);
}
- this.flushCanonicalLater();
- this.setHasData(true);
}
- }, {
- key: 'removeCanonicalRecords',
- value: function removeCanonicalRecords(records, idx) {
- for (var i = 0; i < records.length; i++) {
- if (idx !== undefined) {
- this.removeCanonicalRecord(records[i], i + idx);
- } else {
- this.removeCanonicalRecord(records[i]);
+ };
+
+ Relationship.prototype.addCanonicalRecord = function addCanonicalRecord(record, idx) {
+ if (!this.canonicalMembers.has(record)) {
+ this.canonicalMembers.add(record);
+ if (this.inverseKey) {
+ record._relationships.get(this.inverseKey).addCanonicalRecord(this.record);
+ } else {
+ if (!record._implicitRelationships[this.inverseKeyForImplicit]) {
+ record._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, record, this.key, { options: {} });
}
+ record._implicitRelationships[this.inverseKeyForImplicit].addCanonicalRecord(this.record);
}
}
- }, {
- key: 'removeCanonicalRecord',
- value: function removeCanonicalRecord(record, idx) {
- if (this.canonicalMembers.has(record)) {
- this.removeCanonicalRecordFromOwn(record);
- if (this.inverseKey) {
- this.removeCanonicalRecordFromInverse(record);
- } else {
- if (record._implicitRelationships[this.inverseKeyForImplicit]) {
- record._implicitRelationships[this.inverseKeyForImplicit].removeCanonicalRecord(this.record);
- }
- }
+ this.flushCanonicalLater();
+ this.setHasData(true);
+ };
+
+ Relationship.prototype.removeCanonicalRecords = function removeCanonicalRecords(records, idx) {
+ for (var i = 0; i < records.length; i++) {
+ if (idx !== undefined) {
+ this.removeCanonicalRecord(records[i], i + idx);
+ } else {
+ this.removeCanonicalRecord(records[i]);
}
- this.flushCanonicalLater();
}
- }, {
- key: 'addRecord',
- value: function addRecord(record, idx) {
- if (!this.members.has(record)) {
- this.members.addWithIndex(record, idx);
- this.notifyRecordRelationshipAdded(record, idx);
- if (this.inverseKey) {
- record._relationships.get(this.inverseKey).addRecord(this.record);
- } else {
- if (!record._implicitRelationships[this.inverseKeyForImplicit]) {
- record._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, record, this.key, { options: {} });
- }
- record._implicitRelationships[this.inverseKeyForImplicit].addRecord(this.record);
+ };
+
+ Relationship.prototype.removeCanonicalRecord = function removeCanonicalRecord(record, idx) {
+ if (this.canonicalMembers.has(record)) {
+ this.removeCanonicalRecordFromOwn(record);
+ if (this.inverseKey) {
+ this.removeCanonicalRecordFromInverse(record);
+ } else {
+ if (record._implicitRelationships[this.inverseKeyForImplicit]) {
+ record._implicitRelationships[this.inverseKeyForImplicit].removeCanonicalRecord(this.record);
}
- this.record.updateRecordArrays();
}
- this.setHasData(true);
}
- }, {
- key: 'removeRecord',
- value: function removeRecord(record) {
- if (this.members.has(record)) {
- this.removeRecordFromOwn(record);
- if (this.inverseKey) {
- this.removeRecordFromInverse(record);
- } else {
- if (record._implicitRelationships[this.inverseKeyForImplicit]) {
- record._implicitRelationships[this.inverseKeyForImplicit].removeRecord(this.record);
- }
+ this.flushCanonicalLater();
+ };
+
+ Relationship.prototype.addRecord = function addRecord(record, idx) {
+ if (!this.members.has(record)) {
+ this.members.addWithIndex(record, idx);
+ this.notifyRecordRelationshipAdded(record, idx);
+ if (this.inverseKey) {
+ record._relationships.get(this.inverseKey).addRecord(this.record);
+ } else {
+ if (!record._implicitRelationships[this.inverseKeyForImplicit]) {
+ record._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, record, this.key, { options: {} });
}
+ record._implicitRelationships[this.inverseKeyForImplicit].addRecord(this.record);
}
- }
- }, {
- key: 'removeRecordFromInverse',
- value: function removeRecordFromInverse(record) {
- var inverseRelationship = record._relationships.get(this.inverseKey);
- //Need to check for existence, as the record might unloading at the moment
- if (inverseRelationship) {
- inverseRelationship.removeRecordFromOwn(this.record);
- }
- }
- }, {
- key: 'removeRecordFromOwn',
- value: function removeRecordFromOwn(record) {
- this.members.delete(record);
- this.notifyRecordRelationshipRemoved(record);
this.record.updateRecordArrays();
}
- }, {
- key: 'removeCanonicalRecordFromInverse',
- value: function removeCanonicalRecordFromInverse(record) {
- var inverseRelationship = record._relationships.get(this.inverseKey);
- //Need to check for existence, as the record might unloading at the moment
- if (inverseRelationship) {
- inverseRelationship.removeCanonicalRecordFromOwn(this.record);
+ this.setHasData(true);
+ };
+
+ Relationship.prototype.removeRecord = function removeRecord(record) {
+ if (this.members.has(record)) {
+ this.removeRecordFromOwn(record);
+ if (this.inverseKey) {
+ this.removeRecordFromInverse(record);
+ } else {
+ if (record._implicitRelationships[this.inverseKeyForImplicit]) {
+ record._implicitRelationships[this.inverseKeyForImplicit].removeRecord(this.record);
+ }
}
}
- }, {
- key: 'removeCanonicalRecordFromOwn',
- value: function removeCanonicalRecordFromOwn(record) {
- this.canonicalMembers.delete(record);
- this.flushCanonicalLater();
+ };
+
+ Relationship.prototype.removeRecordFromInverse = function removeRecordFromInverse(record) {
+ var inverseRelationship = record._relationships.get(this.inverseKey);
+ //Need to check for existence, as the record might unloading at the moment
+ if (inverseRelationship) {
+ inverseRelationship.removeRecordFromOwn(this.record);
}
- }, {
- key: 'flushCanonical',
- value: function flushCanonical() {
- var list = this.members.list;
- this.willSync = false;
- //a hack for not removing new records
- //TODO remove once we have proper diffing
- var newRecords = [];
- for (var i = 0; i < list.length; i++) {
- if (list[i].isNew()) {
- newRecords.push(list[i]);
- }
- }
+ };
- //TODO(Igor) make this less abysmally slow
- this.members = this.canonicalMembers.copy();
- for (var i = 0; i < newRecords.length; i++) {
- this.members.add(newRecords[i]);
- }
+ Relationship.prototype.removeRecordFromOwn = function removeRecordFromOwn(record) {
+ this.members.delete(record);
+ this.notifyRecordRelationshipRemoved(record);
+ this.record.updateRecordArrays();
+ };
+
+ Relationship.prototype.removeCanonicalRecordFromInverse = function removeCanonicalRecordFromInverse(record) {
+ var inverseRelationship = record._relationships.get(this.inverseKey);
+ //Need to check for existence, as the record might unloading at the moment
+ if (inverseRelationship) {
+ inverseRelationship.removeCanonicalRecordFromOwn(this.record);
}
- }, {
- key: 'flushCanonicalLater',
- value: function flushCanonicalLater() {
- if (this.willSync) {
- return;
+ };
+
+ Relationship.prototype.removeCanonicalRecordFromOwn = function removeCanonicalRecordFromOwn(record) {
+ this.canonicalMembers.delete(record);
+ this.flushCanonicalLater();
+ };
+
+ Relationship.prototype.flushCanonical = function flushCanonical() {
+ var list = this.members.list;
+ this.willSync = false;
+ //a hack for not removing new records
+ //TODO remove once we have proper diffing
+ var newRecords = [];
+ for (var i = 0; i < list.length; i++) {
+ if (list[i].isNew()) {
+ newRecords.push(list[i]);
}
- this.willSync = true;
- this.store._updateRelationshipState(this);
}
- }, {
- key: 'updateLink',
- value: function updateLink(link) {
- this.link = link;
- this.linkPromise = null;
- this.record.notifyPropertyChange(this.key);
+ //TODO(Igor) make this less abysmally slow
+ this.members = this.canonicalMembers.copy();
+ for (var _i = 0; _i < newRecords.length; _i++) {
+ this.members.add(newRecords[_i]);
}
- }, {
- key: 'findLink',
- value: function findLink() {
- if (this.linkPromise) {
- return this.linkPromise;
- } else {
- var promise = this.fetchLink();
- this.linkPromise = promise;
- return promise.then(function (result) {
- return result;
- });
- }
- }
- }, {
- key: 'updateRecordsFromAdapter',
- value: function updateRecordsFromAdapter(records) {
- //TODO(Igor) move this to a proper place
- //TODO Once we have adapter support, we need to handle updated and canonical changes
- this.computeChanges(records);
- }
- }, {
- key: 'notifyRecordRelationshipAdded',
- value: function notifyRecordRelationshipAdded() {}
- }, {
- key: 'notifyRecordRelationshipRemoved',
- value: function notifyRecordRelationshipRemoved() {}
+ };
- /*
- `hasData` for a relationship is a flag to indicate if we consider the
- content of this relationship "known". Snapshots uses this to tell the
- difference between unknown (`undefined`) or empty (`null`). The reason for
- this is that we wouldn't want to serialize unknown relationships as `null`
- as that might overwrite remote state.
- All relationships for a newly created (`store.createRecord()`) are
- considered known (`hasData === true`).
- */
- }, {
- key: 'setHasData',
- value: function setHasData(value) {
- this.hasData = value;
+ Relationship.prototype.flushCanonicalLater = function flushCanonicalLater() {
+ if (this.willSync) {
+ return;
}
+ this.willSync = true;
+ this.store._updateRelationshipState(this);
+ };
- /*
- `hasLoaded` is a flag to indicate if we have gotten data from the adapter or
- not when the relationship has a link.
- This is used to be able to tell when to fetch the link and when to return
- the local data in scenarios where the local state is considered known
- (`hasData === true`).
- Updating the link will automatically set `hasLoaded` to `false`.
- */
- }, {
- key: 'setHasLoaded',
- value: function setHasLoaded(value) {
- this.hasLoaded = value;
+ Relationship.prototype.updateLink = function updateLink(link) {
+
+ this.link = link;
+ this.linkPromise = null;
+ this.record.notifyPropertyChange(this.key);
+ };
+
+ Relationship.prototype.findLink = function findLink() {
+ if (this.linkPromise) {
+ return this.linkPromise;
+ } else {
+ var promise = this.fetchLink();
+ this.linkPromise = promise;
+ return promise.then(function (result) {
+ return result;
+ });
}
+ };
- /*
- `push` for a relationship allows the store to push a JSON API Relationship
- Object onto the relationship. The relationship will then extract and set the
- meta, data and links of that relationship.
- `push` use `updateMeta`, `updateData` and `updateLink` to update the state
- of the relationship.
- */
- }, {
- key: 'push',
- value: function push(payload) {
+ Relationship.prototype.updateRecordsFromAdapter = function updateRecordsFromAdapter(records) {
+ //TODO(Igor) move this to a proper place
+ //TODO Once we have adapter support, we need to handle updated and canonical changes
+ this.computeChanges(records);
+ };
- var hasData = false;
- var hasLink = false;
+ Relationship.prototype.notifyRecordRelationshipAdded = function notifyRecordRelationshipAdded() {};
- if (payload.meta) {
- this.updateMeta(payload.meta);
- }
+ Relationship.prototype.notifyRecordRelationshipRemoved = function notifyRecordRelationshipRemoved() {};
- if (payload.data !== undefined) {
- hasData = true;
- this.updateData(payload.data);
- }
+ Relationship.prototype.setHasData = function setHasData(value) {
+ this.hasData = value;
+ };
- if (payload.links && payload.links.related) {
- var relatedLink = (0, _emberDataPrivateSystemNormalizeLink.default)(payload.links.related);
- if (relatedLink && relatedLink.href && relatedLink.href !== this.link) {
- hasLink = true;
- this.updateLink(relatedLink.href);
- }
- }
+ Relationship.prototype.setHasLoaded = function setHasLoaded(value) {
+ this.hasLoaded = value;
+ };
- /*
- Data being pushed into the relationship might contain only data or links,
- or a combination of both.
- If we got data we want to set both hasData and hasLoaded to true since
- this would indicate that we should prefer the local state instead of
- trying to fetch the link or call findRecord().
- If we have no data but a link is present we want to set hasLoaded to false
- without modifying the hasData flag. This will ensure we fetch the updated
- link next time the relationship is accessed.
- */
- if (hasData) {
- this.setHasData(true);
- this.setHasLoaded(true);
- } else if (hasLink) {
- this.setHasLoaded(false);
+ Relationship.prototype.push = function push(payload) {
+
+ var hasData = false;
+ var hasLink = false;
+
+ if (payload.meta) {
+ this.updateMeta(payload.meta);
+ }
+
+ if (payload.data !== undefined) {
+ hasData = true;
+ this.updateData(payload.data);
+ }
+
+ if (payload.links && payload.links.related) {
+ var relatedLink = (0, _normalizeLink2.default)(payload.links.related);
+ if (relatedLink && relatedLink.href && relatedLink.href !== this.link) {
+ hasLink = true;
+ this.updateLink(relatedLink.href);
}
}
- }, {
- key: 'updateData',
- value: function updateData() {}
- }, {
+
+ /*
+ Data being pushed into the relationship might contain only data or links,
+ or a combination of both.
+ If we got data we want to set both hasData and hasLoaded to true since
+ this would indicate that we should prefer the local state instead of
+ trying to fetch the link or call findRecord().
+ If we have no data but a link is present we want to set hasLoaded to false
+ without modifying the hasData flag. This will ensure we fetch the updated
+ link next time the relationship is accessed.
+ */
+ if (hasData) {
+ this.setHasData(true);
+ this.setHasLoaded(true);
+ } else if (hasLink) {
+ this.setHasLoaded(false);
+ }
+ };
+
+ Relationship.prototype.updateData = function updateData() {};
+
+ _createClass(Relationship, [{
key: 'record',
get: function () {
return this.internalModel;
}
}, {
@@ -8973,16 +8289,18 @@
return this.internalModel.modelName;
}
}]);
return Relationship;
- })();
+ }();
exports.default = Relationship;
});
-/* global heimdall */
define('ember-data/-private/system/snapshot-record-array', ['exports'], function (exports) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = SnapshotRecordArray;
/**
@module ember-data
*/
@@ -8992,13 +8310,12 @@
@private
@constructor
@param {Array} snapshots An array of snapshots
@param {Object} meta
*/
-
function SnapshotRecordArray(recordArray, meta) {
- var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
/**
An array of snapshots
@private
@property _snapshots
@@ -9125,36 +8442,34 @@
this._snapshots = this._recordArray._takeSnapshot();
return this._snapshots;
};
});
-define("ember-data/-private/system/snapshot", ["exports", "ember", "ember-data/-private/system/empty-object"], function (exports, _ember, _emberDataPrivateSystemEmptyObject) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define("ember-data/-private/system/snapshot", ["exports", "ember", "ember-data/-private/system/empty-object"], function (exports, _ember, _emptyObject) {
+ "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+ exports.__esModule = true;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+
var get = _ember.default.get;
- /**
- @class Snapshot
- @namespace DS
- @private
- @constructor
- @param {DS.Model} internalModel The model to create a snapshot from
- */
-
- var Snapshot = (function () {
+ var Snapshot = function () {
function Snapshot(internalModel) {
var _this = this;
- var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- this._attributes = new _emberDataPrivateSystemEmptyObject.default();
- this._belongsToRelationships = new _emberDataPrivateSystemEmptyObject.default();
- this._belongsToIds = new _emberDataPrivateSystemEmptyObject.default();
- this._hasManyRelationships = new _emberDataPrivateSystemEmptyObject.default();
- this._hasManyIds = new _emberDataPrivateSystemEmptyObject.default();
+ this._attributes = new _emptyObject.default();
+ this._belongsToRelationships = new _emptyObject.default();
+ this._belongsToIds = new _emptyObject.default();
+ this._hasManyRelationships = new _emptyObject.default();
+ this._hasManyIds = new _emptyObject.default();
this._internalModel = internalModel;
var record = internalModel.getRecord();
/**
@@ -9224,309 +8539,182 @@
@method attr
@param {String} keyName
@return {Object} The attribute value or undefined
*/
- _createClass(Snapshot, [{
- key: "attr",
- value: function attr(keyName) {
- if (keyName in this._attributes) {
- return this._attributes[keyName];
- }
- throw new _ember.default.Error("Model '" + _ember.default.inspect(this.record) + "' has no attribute named '" + keyName + "' defined.");
- }
- /**
- Returns all attributes and their corresponding values.
- Example
- ```javascript
- // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
- postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }
- ```
- @method attributes
- @return {Object} All attributes of the current snapshot
- */
- }, {
- key: "attributes",
- value: function attributes() {
- return _ember.default.copy(this._attributes);
+ Snapshot.prototype.attr = function attr(keyName) {
+ if (keyName in this._attributes) {
+ return this._attributes[keyName];
}
+ throw new _ember.default.Error("Model '" + _ember.default.inspect(this.record) + "' has no attribute named '" + keyName + "' defined.");
+ };
- /**
- Returns all changed attributes and their old and new values.
- Example
- ```javascript
- // store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
- postModel.set('title', 'Ember.js rocks!');
- postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }
- ```
- @method changedAttributes
- @return {Object} All changed attributes of the current snapshot
- */
- }, {
- key: "changedAttributes",
- value: function changedAttributes() {
- var changedAttributes = new _emberDataPrivateSystemEmptyObject.default();
- var changedAttributeKeys = Object.keys(this._changedAttributes);
+ Snapshot.prototype.attributes = function attributes() {
+ return _ember.default.copy(this._attributes);
+ };
- for (var i = 0, _length = changedAttributeKeys.length; i < _length; i++) {
- var key = changedAttributeKeys[i];
- changedAttributes[key] = _ember.default.copy(this._changedAttributes[key]);
- }
+ Snapshot.prototype.changedAttributes = function changedAttributes() {
+ var changedAttributes = new _emptyObject.default();
+ var changedAttributeKeys = Object.keys(this._changedAttributes);
- return changedAttributes;
+ for (var i = 0, length = changedAttributeKeys.length; i < length; i++) {
+ var key = changedAttributeKeys[i];
+ changedAttributes[key] = _ember.default.copy(this._changedAttributes[key]);
}
- /**
- Returns the current value of a belongsTo relationship.
- `belongsTo` takes an optional hash of options as a second parameter,
- currently supported options are:
- - `id`: set to `true` if you only want the ID of the related record to be
- returned.
- Example
- ```javascript
- // store.push('post', { id: 1, title: 'Hello World' });
- // store.createRecord('comment', { body: 'Lorem ipsum', post: post });
- commentSnapshot.belongsTo('post'); // => DS.Snapshot
- commentSnapshot.belongsTo('post', { id: true }); // => '1'
- // store.push('comment', { id: 1, body: 'Lorem ipsum' });
- commentSnapshot.belongsTo('post'); // => undefined
- ```
- Calling `belongsTo` will return a new Snapshot as long as there's any known
- data for the relationship available, such as an ID. If the relationship is
- known but unset, `belongsTo` will return `null`. If the contents of the
- relationship is unknown `belongsTo` will return `undefined`.
- Note: Relationships are loaded lazily and cached upon first access.
- @method belongsTo
- @param {String} keyName
- @param {Object} [options]
- @return {(DS.Snapshot|String|null|undefined)} A snapshot or ID of a known
- relationship or null if the relationship is known but unset. undefined
- will be returned if the contents of the relationship is unknown.
- */
- }, {
- key: "belongsTo",
- value: function belongsTo(keyName, options) {
- var id = options && options.id;
- var relationship = undefined,
- inverseRecord = undefined,
- hasData = undefined;
- var result = undefined;
+ return changedAttributes;
+ };
- if (id && keyName in this._belongsToIds) {
- return this._belongsToIds[keyName];
- }
+ Snapshot.prototype.belongsTo = function belongsTo(keyName, options) {
+ var id = options && options.id;
+ var relationship = void 0,
+ inverseRecord = void 0,
+ hasData = void 0;
+ var result = void 0;
- if (!id && keyName in this._belongsToRelationships) {
- return this._belongsToRelationships[keyName];
- }
+ if (id && keyName in this._belongsToIds) {
+ return this._belongsToIds[keyName];
+ }
- relationship = this._internalModel._relationships.get(keyName);
- if (!(relationship && relationship.relationshipMeta.kind === 'belongsTo')) {
- throw new _ember.default.Error("Model '" + _ember.default.inspect(this.record) + "' has no belongsTo relationship named '" + keyName + "' defined.");
- }
+ if (!id && keyName in this._belongsToRelationships) {
+ return this._belongsToRelationships[keyName];
+ }
- hasData = get(relationship, 'hasData');
- inverseRecord = get(relationship, 'inverseRecord');
+ relationship = this._internalModel._relationships.get(keyName);
+ if (!(relationship && relationship.relationshipMeta.kind === 'belongsTo')) {
+ throw new _ember.default.Error("Model '" + _ember.default.inspect(this.record) + "' has no belongsTo relationship named '" + keyName + "' defined.");
+ }
- if (hasData) {
- if (inverseRecord && !inverseRecord.isDeleted()) {
- if (id) {
- result = get(inverseRecord, 'id');
- } else {
- result = inverseRecord.createSnapshot();
- }
+ hasData = get(relationship, 'hasData');
+ inverseRecord = get(relationship, 'inverseRecord');
+
+ if (hasData) {
+ if (inverseRecord && !inverseRecord.isDeleted()) {
+ if (id) {
+ result = get(inverseRecord, 'id');
} else {
- result = null;
+ result = inverseRecord.createSnapshot();
}
- }
-
- if (id) {
- this._belongsToIds[keyName] = result;
} else {
- this._belongsToRelationships[keyName] = result;
+ result = null;
}
+ }
- return result;
+ if (id) {
+ this._belongsToIds[keyName] = result;
+ } else {
+ this._belongsToRelationships[keyName] = result;
}
- /**
- Returns the current value of a hasMany relationship.
- `hasMany` takes an optional hash of options as a second parameter,
- currently supported options are:
- - `ids`: set to `true` if you only want the IDs of the related records to be
- returned.
- Example
- ```javascript
- // store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
- postSnapshot.hasMany('comments'); // => [DS.Snapshot, DS.Snapshot]
- postSnapshot.hasMany('comments', { ids: true }); // => ['2', '3']
- // store.push('post', { id: 1, title: 'Hello World' });
- postSnapshot.hasMany('comments'); // => undefined
- ```
- Note: Relationships are loaded lazily and cached upon first access.
- @method hasMany
- @param {String} keyName
- @param {Object} [options]
- @return {(Array|undefined)} An array of snapshots or IDs of a known
- relationship or an empty array if the relationship is known but unset.
- undefined will be returned if the contents of the relationship is unknown.
- */
- }, {
- key: "hasMany",
- value: function hasMany(keyName, options) {
- var ids = options && options.ids;
- var relationship = undefined,
- members = undefined,
- hasData = undefined;
- var results = undefined;
+ return result;
+ };
- if (ids && keyName in this._hasManyIds) {
- return this._hasManyIds[keyName];
- }
+ Snapshot.prototype.hasMany = function hasMany(keyName, options) {
+ var ids = options && options.ids;
+ var relationship = void 0,
+ members = void 0,
+ hasData = void 0;
+ var results = void 0;
- if (!ids && keyName in this._hasManyRelationships) {
- return this._hasManyRelationships[keyName];
- }
-
- relationship = this._internalModel._relationships.get(keyName);
- if (!(relationship && relationship.relationshipMeta.kind === 'hasMany')) {
- throw new _ember.default.Error("Model '" + _ember.default.inspect(this.record) + "' has no hasMany relationship named '" + keyName + "' defined.");
- }
-
- hasData = get(relationship, 'hasData');
- members = get(relationship, 'members');
-
- if (hasData) {
- results = [];
- members.forEach(function (member) {
- if (!member.isDeleted()) {
- if (ids) {
- results.push(member.id);
- } else {
- results.push(member.createSnapshot());
- }
- }
- });
- }
-
- if (ids) {
- this._hasManyIds[keyName] = results;
- } else {
- this._hasManyRelationships[keyName] = results;
- }
-
- return results;
+ if (ids && keyName in this._hasManyIds) {
+ return this._hasManyIds[keyName];
}
- /**
- Iterates through all the attributes of the model, calling the passed
- function on each attribute.
- Example
- ```javascript
- snapshot.eachAttribute(function(name, meta) {
- // ...
- });
- ```
- @method eachAttribute
- @param {Function} callback the callback to execute
- @param {Object} [binding] the value to which the callback's `this` should be bound
- */
- }, {
- key: "eachAttribute",
- value: function eachAttribute(callback, binding) {
- this.record.eachAttribute(callback, binding);
+ if (!ids && keyName in this._hasManyRelationships) {
+ return this._hasManyRelationships[keyName];
}
- /**
- Iterates through all the relationships of the model, calling the passed
- function on each relationship.
- Example
- ```javascript
- snapshot.eachRelationship(function(name, relationship) {
- // ...
- });
- ```
- @method eachRelationship
- @param {Function} callback the callback to execute
- @param {Object} [binding] the value to which the callback's `this` should be bound
- */
- }, {
- key: "eachRelationship",
- value: function eachRelationship(callback, binding) {
- this.record.eachRelationship(callback, binding);
+ relationship = this._internalModel._relationships.get(keyName);
+ if (!(relationship && relationship.relationshipMeta.kind === 'hasMany')) {
+ throw new _ember.default.Error("Model '" + _ember.default.inspect(this.record) + "' has no hasMany relationship named '" + keyName + "' defined.");
}
- /**
- Serializes the snapshot using the serializer for the model.
- Example
- ```app/adapters/application.js
- import DS from 'ember-data';
- export default DS.Adapter.extend({
- createRecord(store, type, snapshot) {
- var data = snapshot.serialize({ includeId: true });
- var url = `/${type.modelName}`;
- return fetch(url, {
- method: 'POST',
- body: data,
- }).then((response) => response.json())
+ hasData = get(relationship, 'hasData');
+ members = get(relationship, 'members');
+
+ if (hasData) {
+ results = [];
+ members.forEach(function (member) {
+ if (!member.isDeleted()) {
+ if (ids) {
+ results.push(member.id);
+ } else {
+ results.push(member.createSnapshot());
+ }
}
});
- ```
- @method serialize
- @param {Object} options
- @return {Object} an object whose values are primitive JSON values only
- */
- }, {
- key: "serialize",
- value: function serialize(options) {
- return this.record.store.serializerFor(this.modelName).serialize(this, options);
}
- }]);
+ if (ids) {
+ this._hasManyIds[keyName] = results;
+ } else {
+ this._hasManyRelationships[keyName] = results;
+ }
+
+ return results;
+ };
+
+ Snapshot.prototype.eachAttribute = function eachAttribute(callback, binding) {
+ this.record.eachAttribute(callback, binding);
+ };
+
+ Snapshot.prototype.eachRelationship = function eachRelationship(callback, binding) {
+ this.record.eachRelationship(callback, binding);
+ };
+
+ Snapshot.prototype.serialize = function serialize(options) {
+ return this.record.store.serializerFor(this.modelName).serialize(this, options);
+ };
+
return Snapshot;
- })();
+ }();
exports.default = Snapshot;
});
-/**
- @module ember-data
-*/
-define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/-private/debug', 'ember-data/model', 'ember-data/-private/system/normalize-model-name', 'ember-data/adapters/errors', 'ember-data/-private/system/identity-map', 'ember-data/-private/system/promise-proxies', 'ember-data/-private/system/store/common', 'ember-data/-private/system/store/serializer-response', 'ember-data/-private/system/store/serializers', 'ember-data/-private/system/store/finders', 'ember-data/-private/utils', 'ember-data/-private/system/coerce-id', 'ember-data/-private/system/record-array-manager', 'ember-data/-private/system/store/container-instance-cache', 'ember-data/-private/system/model/internal-model', 'ember-data/-private/system/empty-object', 'ember-data/-private/features'], function (exports, _ember, _emberDataPrivateDebug, _emberDataModel, _emberDataPrivateSystemNormalizeModelName, _emberDataAdaptersErrors, _emberDataPrivateSystemIdentityMap, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemStoreCommon, _emberDataPrivateSystemStoreSerializerResponse, _emberDataPrivateSystemStoreSerializers, _emberDataPrivateSystemStoreFinders, _emberDataPrivateUtils, _emberDataPrivateSystemCoerceId, _emberDataPrivateSystemRecordArrayManager, _emberDataPrivateSystemStoreContainerInstanceCache, _emberDataPrivateSystemModelInternalModel, _emberDataPrivateSystemEmptyObject, _emberDataPrivateFeatures) {
- var badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number';
+define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/-private/debug', 'ember-data/model', 'ember-data/-private/system/normalize-model-name', 'ember-data/adapters/errors', 'ember-data/-private/system/identity-map', 'ember-data/-private/system/promise-proxies', 'ember-data/-private/system/store/common', 'ember-data/-private/system/store/serializer-response', 'ember-data/-private/system/store/serializers', 'ember-data/-private/system/store/finders', 'ember-data/-private/utils', 'ember-data/-private/system/coerce-id', 'ember-data/-private/system/record-array-manager', 'ember-data/-private/system/store/container-instance-cache', 'ember-data/-private/system/model/internal-model', 'ember-data/-private/system/empty-object', 'ember-data/-private/features'], function (exports, _ember, _debug, _model, _normalizeModelName, _errors, _identityMap, _promiseProxies, _common, _serializerResponse, _serializers, _finders, _utils, _coerceId, _recordArrayManager, _containerInstanceCache, _internalModel5, _emptyObject, _features) {
+ 'use strict';
- exports.badIdFormatAssertion = badIdFormatAssertion;
- var A = _ember.default.A;
- var Backburner = _ember.default._Backburner;
- var computed = _ember.default.computed;
- var copy = _ember.default.copy;
- var ENV = _ember.default.ENV;
- var EmberError = _ember.default.Error;
- var get = _ember.default.get;
- var inspect = _ember.default.inspect;
- var isNone = _ember.default.isNone;
- var isPresent = _ember.default.isPresent;
- var MapWithDefault = _ember.default.MapWithDefault;
- var emberRun = _ember.default.run;
- var set = _ember.default.set;
- var RSVP = _ember.default.RSVP;
- var Service = _ember.default.Service;
- var typeOf = _ember.default.typeOf;
+ exports.__esModule = true;
+ exports.Store = exports.badIdFormatAssertion = undefined;
+ /**
+ @module ember-data
+ */
+
+ var badIdFormatAssertion = exports.badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number';
+
+ var A = _ember.default.A,
+ Backburner = _ember.default._Backburner,
+ computed = _ember.default.computed,
+ copy = _ember.default.copy,
+ ENV = _ember.default.ENV,
+ EmberError = _ember.default.Error,
+ get = _ember.default.get,
+ inspect = _ember.default.inspect,
+ isNone = _ember.default.isNone,
+ isPresent = _ember.default.isPresent,
+ MapWithDefault = _ember.default.MapWithDefault,
+ emberRun = _ember.default.run,
+ set = _ember.default.set,
+ RSVP = _ember.default.RSVP,
+ Service = _ember.default.Service,
+ typeOf = _ember.default.typeOf;
var Promise = RSVP.Promise;
+
//Get the materialized model from the internalModel/promise that returns
//an internal model and return it in a promiseObject. Useful for returning
//from find methods
function promiseRecord(internalModelPromise, label) {
var toReturn = internalModelPromise.then(function (internalModel) {
return internalModel.getRecord();
});
- return (0, _emberDataPrivateSystemPromiseProxies.promiseObject)(toReturn, label);
+ return (0, _promiseProxies.promiseObject)(toReturn, label);
}
- var Store = undefined;
+ var Store = void 0;
// Implementors Note:
//
// The variables in this file are consistently named according to the following
// scheme:
@@ -9622,15 +8810,15 @@
*/
init: function () {
this._super.apply(this, arguments);
this._backburner = new Backburner(['normalizeRelationships', 'syncRelationships', 'finished']);
// internal bookkeeping; not observable
- this.recordArrayManager = new _emberDataPrivateSystemRecordArrayManager.default({ store: this });
- this._identityMap = new _emberDataPrivateSystemIdentityMap.default();
+ this.recordArrayManager = new _recordArrayManager.default({ store: this });
+ this._identityMap = new _identityMap.default();
this._pendingSave = [];
- this._instanceCache = new _emberDataPrivateSystemStoreContainerInstanceCache.default((0, _emberDataPrivateUtils.getOwner)(this), this);
- this._modelFactoryCache = new _emberDataPrivateSystemEmptyObject.default();
+ this._instanceCache = new _containerInstanceCache.default((0, _utils.getOwner)(this), this);
+ this._modelFactoryCache = new _emptyObject.default();
/*
Ember Data uses several specialized micro-queues for organizing
and coalescing similar async work.
These queues are currently controlled by a flush scheduled into
@@ -9644,17 +8832,20 @@
this._pushedInternalModels = [];
// used for coalescing internal model updates
this._updatedInternalModels = [];
// used to keep track of all the find requests that need to be coalesced
- this._pendingFetch = MapWithDefault.create({ defaultValue: function () {
+ this._pendingFetch = MapWithDefault.create({
+ defaultValue: function () {
return [];
- } });
+ }
+ });
- this._instanceCache = new _emberDataPrivateSystemStoreContainerInstanceCache.default((0, _emberDataPrivateUtils.getOwner)(this), this);
+ this._instanceCache = new _containerInstanceCache.default((0, _utils.getOwner)(this), this);
},
+
/**
The default adapter to use to communicate to a backend server or
other persistence layer. This will be overridden by an application
adapter if present.
If you want to specify `app/adapters/custom.js` as a string, do:
@@ -9686,10 +8877,11 @@
if (true) {}
var snapshot = record._internalModel.createSnapshot();
return snapshot.serialize(options);
},
+
/**
This property returns the adapter, after resolving a possible
string key.
If the supplied `adapter` was a class, or a String property
path resolved to a class, this property will instantiate the
@@ -9732,12 +8924,12 @@
@param {Object} inputProperties a hash of properties to set on the
newly created record.
@return {DS.Model} record
*/
createRecord: function (modelName, inputProperties) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
- var properties = copy(inputProperties) || new _emberDataPrivateSystemEmptyObject.default();
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
+ var properties = copy(inputProperties) || new _emptyObject.default();
// If the passed properties do not include a primary key,
// give the adapter an opportunity to generate one. Typically,
// client-side ID generators will use something like uuid.js
// to avoid conflicts.
@@ -9745,11 +8937,11 @@
if (isNone(properties.id)) {
properties.id = this._generateId(normalizedModelName, properties);
}
// Coerce ID to a string
- properties.id = (0, _emberDataPrivateSystemCoerceId.default)(properties.id);
+ properties.id = (0, _coerceId.default)(properties.id);
var internalModel = this.buildInternalModel(normalizedModelName, properties.id);
var record = internalModel.getRecord();
// Move the record out of its initial `empty` state into
@@ -9767,10 +8959,11 @@
});
return record;
},
+
/**
If possible, this method asks the adapter to generate an ID for
a newly created record.
@method _generateId
@private
@@ -9786,10 +8979,11 @@
}
return null;
},
+
// .................
// . DELETE RECORD .
// .................
/**
@@ -9806,10 +9000,11 @@
*/
deleteRecord: function (record) {
record.deleteRecord();
},
+
/**
For symmetry, a record can be unloaded via the store.
This will cause the record to be destroyed and freed up for garbage collection.
Example
```javascript
@@ -9822,10 +9017,11 @@
*/
unloadRecord: function (record) {
record.unloadRecord();
},
+
// ................
// . FIND RECORDS .
// ................
/**
@@ -9838,16 +9034,16 @@
*/
find: function (modelName, id, options) {
// The default `model` hook in Ember.Route calls `find(modelName, id)`,
// that's why we have to keep this method around even though `findRecord` is
// the public way to get a record by modelName and id.
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
-
return this.findRecord(normalizedModelName, id);
},
+
/**
This method returns a record for a given type and id combination.
The `findRecord` method will always resolve its promise with the same
object for a given type and `id`.
The `findRecord` method will always return a **promise** that will be
@@ -10019,11 +9215,11 @@
@param {Object} options
@return {Promise} promise
*/
findRecord: function (modelName, id, options) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
var internalModel = this._internalModelForId(normalizedModelName, id);
options = options || {};
if (!this.hasRecordForId(normalizedModelName, id)) {
@@ -10032,11 +9228,10 @@
var fetchedInternalModel = this._findRecord(internalModel, options);
return promiseRecord(fetchedInternalModel, 'DS: Store#findRecord ' + normalizedModelName + ' with id: ' + id);
},
-
_findRecord: function (internalModel, options) {
// Refetch if the reload option is passed
if (options.reload) {
return this._scheduleFetch(internalModel, options);
}
@@ -10059,23 +9254,21 @@
}
// Return the cached record
return Promise.resolve(internalModel);
},
-
_findByInternalModel: function (internalModel) {
- var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (options.preload) {
internalModel.preloadData(options.preload);
}
var fetchedInternalModel = this._findEmptyInternalModel(internalModel, options);
return promiseRecord(fetchedInternalModel, 'DS: Store#findRecord ' + internalModel.modelName + ' with id: ' + internalModel.id);
},
-
_findEmptyInternalModel: function (internalModel, options) {
if (internalModel.isEmpty()) {
return this._scheduleFetch(internalModel, options);
}
@@ -10085,10 +9278,11 @@
}
return Promise.resolve(internalModel);
},
+
/**
This method makes a series of requests to the adapter's `find` method
and returns a promise that resolves once they are all loaded.
@private
@method findByIds
@@ -10098,19 +9292,20 @@
*/
findByIds: function (modelName, ids) {
var promises = new Array(ids.length);
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
for (var i = 0; i < ids.length; i++) {
promises[i] = this.findRecord(normalizedModelName, ids[i]);
}
- return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)(RSVP.all(promises).then(A, null, 'DS: Store#findByIds of ' + normalizedModelName + ' complete'));
+ return (0, _promiseProxies.promiseArray)(RSVP.all(promises).then(A, null, 'DS: Store#findByIds of ' + normalizedModelName + ' complete'));
},
+
/**
This method is called by `findRecord` if it discovers that a particular
type/id pair hasn't been loaded yet to kick off a request to the
adapter.
@method _fetchRecord
@@ -10120,30 +9315,28 @@
*/
_fetchRecord: function (internalModel, options) {
var modelName = internalModel.modelName;
var adapter = this.adapterFor(modelName);
- return (0, _emberDataPrivateSystemStoreFinders._find)(adapter, this, internalModel.type, internalModel.id, internalModel, options);
+ return (0, _finders._find)(adapter, this, internalModel.type, internalModel.id, internalModel, options);
},
-
_scheduleFetchMany: function (internalModels) {
var fetches = new Array(internalModels.length);
for (var i = 0; i < internalModels.length; i++) {
fetches[i] = this._scheduleFetch(internalModels[i]);
}
return Promise.all(fetches);
},
-
_scheduleFetch: function (internalModel, options) {
if (internalModel._loadingPromise) {
return internalModel._loadingPromise;
}
- var id = internalModel.id;
- var modelName = internalModel.modelName;
+ var id = internalModel.id,
+ modelName = internalModel.modelName;
var resolver = RSVP.defer('Fetching ' + modelName + '\' with id: ' + id);
var pendingFetchItem = {
internalModel: internalModel,
resolver: resolver,
@@ -10159,27 +9352,25 @@
this._pendingFetch.get(modelName).push(pendingFetchItem);
return promise;
},
-
flushAllPendingFetches: function () {
if (this.isDestroyed || this.isDestroying) {
return;
}
this._pendingFetch.forEach(this._flushPendingFetchForType, this);
this._pendingFetch.clear();
},
-
_flushPendingFetchForType: function (pendingFetchItems, modelName) {
var store = this;
var adapter = store.adapterFor(modelName);
var shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests;
var totalItems = pendingFetchItems.length;
var internalModels = new Array(totalItems);
- var seeking = new _emberDataPrivateSystemEmptyObject.default();
+ var seeking = new _emptyObject.default();
for (var i = 0; i < totalItems; i++) {
var pendingItem = pendingFetchItems[i];
var internalModel = pendingItem.internalModel;
internalModels[i] = internalModel;
@@ -10192,45 +9383,45 @@
recordResolverPair.resolver.resolve(recordFetch);
}
function handleFoundRecords(foundInternalModels, expectedInternalModels) {
// resolve found records
- var found = new _emberDataPrivateSystemEmptyObject.default();
- for (var i = 0, l = foundInternalModels.length; i < l; i++) {
- var internalModel = foundInternalModels[i];
- var pair = seeking[internalModel.id];
- found[internalModel.id] = internalModel;
+ var found = new _emptyObject.default();
+ for (var _i = 0, l = foundInternalModels.length; _i < l; _i++) {
+ var _internalModel = foundInternalModels[_i];
+ var pair = seeking[_internalModel.id];
+ found[_internalModel.id] = _internalModel;
if (pair) {
var resolver = pair.resolver;
- resolver.resolve(internalModel);
+ resolver.resolve(_internalModel);
}
}
// reject missing records
var missingInternalModels = [];
- for (var i = 0, l = expectedInternalModels.length; i < l; i++) {
- var internalModel = expectedInternalModels[i];
+ for (var _i2 = 0, _l = expectedInternalModels.length; _i2 < _l; _i2++) {
+ var _internalModel2 = expectedInternalModels[_i2];
- if (!found[internalModel.id]) {
- missingInternalModels.push(internalModel);
+ if (!found[_internalModel2.id]) {
+ missingInternalModels.push(_internalModel2);
}
}
if (missingInternalModels.length) {
rejectInternalModels(missingInternalModels);
}
}
function rejectInternalModels(internalModels, error) {
- for (var i = 0, l = internalModels.length; i < l; i++) {
- var internalModel = internalModels[i];
- var pair = seeking[internalModel.id];
+ for (var _i3 = 0, l = internalModels.length; _i3 < l; _i3++) {
+ var _internalModel3 = internalModels[_i3];
+ var pair = seeking[_internalModel3.id];
if (pair) {
- pair.resolver.reject(error || new Error('Expected: \'' + internalModel + '\' to be present in the adapter provided payload, but it was not found.'));
+ pair.resolver.reject(error || new Error('Expected: \'' + _internalModel3 + '\' to be present in the adapter provided payload, but it was not found.'));
}
}
}
if (shouldCoalesce) {
@@ -10243,51 +9434,52 @@
//
// But since the _findMany() finder is a store method we need to get the
// records from the grouped snapshots even though the _findMany() finder
// will once again convert the records to snapshots for adapter.findMany()
var snapshots = new Array(totalItems);
- for (var i = 0; i < totalItems; i++) {
- snapshots[i] = internalModels[i].createSnapshot();
+ for (var _i4 = 0; _i4 < totalItems; _i4++) {
+ snapshots[_i4] = internalModels[_i4].createSnapshot();
}
var groups = adapter.groupRecordsForFindMany(this, snapshots);
- var _loop = function (i, l) {
- var group = groups[i];
- var totalInGroup = groups[i].length;
+ var _loop = function (l, _i5) {
+ var group = groups[_i5];
+ var totalInGroup = groups[_i5].length;
var ids = new Array(totalInGroup);
var groupedInternalModels = new Array(totalInGroup);
for (var j = 0; j < totalInGroup; j++) {
- var internalModel = group[j]._internalModel;
+ var _internalModel4 = group[j]._internalModel;
- groupedInternalModels[j] = internalModel;
- ids[j] = internalModel.id;
+ groupedInternalModels[j] = _internalModel4;
+ ids[j] = _internalModel4.id;
}
if (totalInGroup > 1) {
- (0, _emberDataPrivateSystemStoreFinders._findMany)(adapter, store, modelName, ids, groupedInternalModels).then(function (foundInternalModels) {
+ (0, _finders._findMany)(adapter, store, modelName, ids, groupedInternalModels).then(function (foundInternalModels) {
handleFoundRecords(foundInternalModels, groupedInternalModels);
}).catch(function (error) {
rejectInternalModels(groupedInternalModels, error);
});
} else if (ids.length === 1) {
var pair = seeking[groupedInternalModels[0].id];
_fetchRecord(pair);
} else {}
};
- for (var i = 0, l = groups.length; i < l; i++) {
- _loop(i, l);
+ for (var _i5 = 0, l = groups.length; _i5 < l; _i5++) {
+ _loop(l, _i5);
}
} else {
- for (var i = 0; i < totalItems; i++) {
- _fetchRecord(pendingFetchItems[i]);
+ for (var _i6 = 0; _i6 < totalItems; _i6++) {
+ _fetchRecord(pendingFetchItems[_i6]);
}
}
},
+
/**
Get the reference for the specified record.
Example
```javascript
let userRef = store.getReference('user', 1);
@@ -10313,15 +9505,16 @@
@param {String|Integer} id
@since 2.5.0
@return {RecordReference}
*/
getReference: function (modelName, id) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
return this._internalModelForId(normalizedModelName, id).recordReference;
},
+
/**
Get a record by a given type and ID without triggering a fetch.
This method will synchronously return the record if it is available in the store,
otherwise it will return `null`. A record is available if it has been fetched earlier, or
pushed manually into the store.
@@ -10335,19 +9528,20 @@
@param {String} modelName
@param {String|Integer} id
@return {DS.Model|null} record
*/
peekRecord: function (modelName, id) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
if (this.hasRecordForId(normalizedModelName, id)) {
return this._internalModelForId(normalizedModelName, id).getRecord();
} else {
return null;
}
},
+
/**
This method is called by the record's `reload` method.
This method calls the adapter's `find` method, which returns a promise. When
**that** promise resolves, `reloadRecord` will resolve the promise returned
by the record's `reload`.
@@ -10355,18 +9549,19 @@
@private
@param {DS.Model} internalModel
@return {Promise} promise
*/
_reloadRecord: function (internalModel) {
- var id = internalModel.id;
- var modelName = internalModel.modelName;
+ var id = internalModel.id,
+ modelName = internalModel.modelName;
var adapter = this.adapterFor(modelName);
return this._scheduleFetch(internalModel);
},
+
/**
This method returns true if a record for a given modelName and id is already
loaded in the store. Use this function to know beforehand if a findRecord()
will result in a request or that it will be a cache hit.
Example
@@ -10381,18 +9576,19 @@
@param {(String|Integer)} id
@return {Boolean}
*/
hasRecordForId: function (modelName, id) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
- var trueId = (0, _emberDataPrivateSystemCoerceId.default)(id);
+ var trueId = (0, _coerceId.default)(id);
var internalModel = this._internalModelsFor(normalizedModelName).get(trueId);
return !!internalModel && internalModel.isLoaded();
},
+
/**
Returns id record for a given type and ID. If one isn't already loaded,
it builds a new record and leaves it in the `empty` state.
@method recordForId
@private
@@ -10402,22 +9598,22 @@
*/
recordForId: function (modelName, id) {
return this._internalModelForId(modelName, id).getRecord();
},
-
_internalModelForId: function (modelName, id) {
- var trueId = (0, _emberDataPrivateSystemCoerceId.default)(id);
+ var trueId = (0, _coerceId.default)(id);
var internalModel = this._internalModelsFor(modelName).get(trueId);
if (!internalModel) {
internalModel = this.buildInternalModel(modelName, trueId);
}
return internalModel;
},
+
/**
@method findMany
@private
@param {Array} internalModels
@return {Promise} promise
@@ -10430,10 +9626,11 @@
}
return Promise.all(finds);
},
+
/**
If a relationship was originally populated by the adapter as a link
(as opposed to a list of IDs), this method is called when the
relationship is fetched.
The link (which is usually a URL) is passed through unchanged, so the
@@ -10448,13 +9645,14 @@
@return {Promise} promise
*/
findHasMany: function (internalModel, link, relationship) {
var adapter = this.adapterFor(internalModel.modelName);
- return (0, _emberDataPrivateSystemStoreFinders._findHasMany)(adapter, this, internalModel, link, relationship);
+ return (0, _finders._findHasMany)(adapter, this, internalModel, link, relationship);
},
+
/**
@method findBelongsTo
@private
@param {InternalModel} internalModel
@param {any} link
@@ -10462,13 +9660,14 @@
@return {Promise} promise
*/
findBelongsTo: function (internalModel, link, relationship) {
var adapter = this.adapterFor(internalModel.modelName);
- return (0, _emberDataPrivateSystemStoreFinders._findBelongsTo)(adapter, this, internalModel, link, relationship);
+ return (0, _finders._findBelongsTo)(adapter, this, internalModel, link, relationship);
},
+
/**
This method delegates a query to the adapter. This is the one place where
adapter-level semantics are exposed to the application.
Each time this method is called a new request is made through the adapter.
Exposing queries this way seems preferable to creating an abstract query
@@ -10505,25 +9704,26 @@
@param {any} query an opaque query to be used by the adapter
@return {Promise} promise
*/
query: function (modelName, query) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
return this._query(normalizedModelName, query);
},
-
_query: function (modelName, query, array) {
array = array || this.recordArrayManager.createAdapterPopulatedRecordArray(modelName, query);
var adapter = this.adapterFor(modelName);
- var pA = (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._query)(adapter, this, modelName, query, array));
+ var pA = (0, _promiseProxies.promiseArray)((0, _finders._query)(adapter, this, modelName, query, array));
+
return pA;
},
+
/**
This method makes a request for one record, where the `id` is not known
beforehand (if the `id` is known, use [`findRecord`](#method_findRecord)
instead).
This method can be used when it is certain that the server will return a
@@ -10599,25 +9799,26 @@
@param {any} query an opaque query to be used by the adapter
@return {Promise} promise which resolves with the found record or `null`
*/
queryRecord: function (modelName, query) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
var adapter = this.adapterFor(normalizedModelName);
- return (0, _emberDataPrivateSystemPromiseProxies.promiseObject)((0, _emberDataPrivateSystemStoreFinders._queryRecord)(adapter, this, modelName, query).then(function (internalModel) {
+ return (0, _promiseProxies.promiseObject)((0, _finders._queryRecord)(adapter, this, modelName, query).then(function (internalModel) {
// the promise returned by store.queryRecord is expected to resolve with
// an instance of DS.Model
if (internalModel) {
return internalModel.getRecord();
}
return null;
}));
},
+
/**
`findAll` asks the adapter's `findAll` method to find the records for the
given type, and returns a promise which will resolve with all records of
this type present in the store, even if the adapter only returns a subset
of them.
@@ -10765,53 +9966,55 @@
@param {String} modelName
@param {Object} options
@return {Promise} promise
*/
findAll: function (modelName, options) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
var fetch = this._fetchAll(normalizedModelName, this.peekAll(normalizedModelName), options);
return fetch;
},
+
/**
@method _fetchAll
@private
@param {DS.Model} modelName
@param {DS.RecordArray} array
@return {Promise} promise
*/
_fetchAll: function (modelName, array) {
- var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var adapter = this.adapterFor(modelName);
var sinceToken = this._internalModelsFor(modelName).metadata.since;
if (options.reload) {
set(array, 'isUpdating', true);
- return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._findAll)(adapter, this, modelName, sinceToken, options));
+ return (0, _promiseProxies.promiseArray)((0, _finders._findAll)(adapter, this, modelName, sinceToken, options));
}
var snapshotArray = array._createSnapshot(options);
if (adapter.shouldReloadAll(this, snapshotArray)) {
set(array, 'isUpdating', true);
- return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._findAll)(adapter, this, modelName, sinceToken, options));
+ return (0, _promiseProxies.promiseArray)((0, _finders._findAll)(adapter, this, modelName, sinceToken, options));
}
if (options.backgroundReload === false) {
- return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)(Promise.resolve(array));
+ return (0, _promiseProxies.promiseArray)(Promise.resolve(array));
}
if (options.backgroundReload || adapter.shouldBackgroundReloadAll(this, snapshotArray)) {
set(array, 'isUpdating', true);
- (0, _emberDataPrivateSystemStoreFinders._findAll)(adapter, this, modelName, sinceToken, options);
+ (0, _finders._findAll)(adapter, this, modelName, sinceToken, options);
}
- return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)(Promise.resolve(array));
+ return (0, _promiseProxies.promiseArray)(Promise.resolve(array));
},
+
/**
@method didUpdateAll
@param {String} modelName
@private
*/
@@ -10819,10 +10022,11 @@
var liveRecordArray = this.recordArrayManager.liveRecordArrayFor(modelName);
set(liveRecordArray, 'isUpdating', false);
},
+
/**
This method returns a filtered array that contains all of the
known records for a given type in the store.
Note that because it's just a filter, the result will contain any
locally created records of the type, however, it will not make a
@@ -10839,18 +10043,19 @@
@method peekAll
@param {String} modelName
@return {DS.RecordArray}
*/
peekAll: function (modelName) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
var liveRecordArray = this.recordArrayManager.liveRecordArrayFor(normalizedModelName);
this.recordArrayManager.syncLiveRecordArray(liveRecordArray, normalizedModelName);
return liveRecordArray;
},
+
/**
This method unloads all records in the store.
It schedules unloading to happen during the next run loop.
Optionally you can pass a type which unload all records for a given type.
```javascript
@@ -10863,15 +10068,16 @@
unloadAll: function (modelName) {
if (arguments.length === 0) {
this._identityMap.clear();
} else {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
this._internalModelsFor(normalizedModelName).clear();
}
},
+
/**
Takes a type and filter function, and returns a live RecordArray that
remains up to date as new records are loaded into the store or created
locally.
The filter function takes a materialized record, and returns true
@@ -10916,16 +10122,16 @@
*/
filter: function (modelName, query, filter) {
if (!ENV.ENABLE_DS_FILTER) {}
- var promise = undefined;
+ var promise = void 0;
var length = arguments.length;
- var array = undefined;
+ var array = void 0;
var hasQuery = length === 3;
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
// allow an optional server query
if (hasQuery) {
promise = this.query(normalizedModelName, query);
} else if (arguments.length === 2) {
@@ -10938,15 +10144,16 @@
array = this.recordArrayManager.createFilteredRecordArray(normalizedModelName, filter);
}
promise = promise || Promise.resolve(array);
- return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)(promise.then(function () {
+ return (0, _promiseProxies.promiseArray)(promise.then(function () {
return array;
}, null, 'DS: Store#filter of ' + normalizedModelName));
},
+
/**
This method has been deprecated and is an alias for store.hasRecordForId, which should
be used instead.
@deprecated
@method recordIsLoaded
@@ -10956,10 +10163,11 @@
*/
recordIsLoaded: function (modelName, id) {
return this.hasRecordForId(modelName, id);
},
+
// ..............
// . PERSISTING .
// ..............
/**
@@ -10981,10 +10189,11 @@
resolver: resolver
});
emberRun.once(this, this.flushPendingSave);
},
+
/**
This method is called at the end of the run loop, and
flushes any records passed into `scheduleSave`
@method flushPendingSave
@private
@@ -10997,11 +10206,11 @@
var pendingItem = pending[i];
var snapshot = pendingItem.snapshot;
var resolver = pendingItem.resolver;
var internalModel = snapshot._internalModel;
var adapter = this.adapterFor(internalModel.modelName);
- var operation = undefined;
+ var operation = void 0;
if (internalModel.currentState.stateName === 'root.deleted.saved') {
return resolver.resolve();
} else if (internalModel.isNew()) {
operation = 'createRecord';
@@ -11013,10 +10222,11 @@
resolver.resolve(_commit(adapter, this, operation, snapshot));
}
},
+
/**
This method is called once the promise returned by an
adapter's `createRecord`, `updateRecord` or `deleteRecord`
is resolved.
If the data provides a server-generated ID, it will
@@ -11025,11 +10235,11 @@
@private
@param {InternalModel} internalModel the in-flight internal model
@param {Object} data optional data (see above)
*/
didSaveRecord: function (internalModel, dataArg) {
- var data = undefined;
+ var data = void 0;
if (dataArg) {
data = dataArg.data;
}
if (data) {
// normalize relationship IDs into records
@@ -11040,10 +10250,11 @@
//We first make sure the primary data has been updated
//TODO try to move notification to the user to the end of the runloop
internalModel.adapterDidCommit(data);
},
+
/**
This method is called once the promise returned by an
adapter's `createRecord`, `updateRecord` or `deleteRecord`
is rejected with a `DS.InvalidError`.
@method recordWasInvalid
@@ -11053,10 +10264,11 @@
*/
recordWasInvalid: function (internalModel, errors) {
internalModel.adapterDidInvalidate(errors);
},
+
/**
This method is called once the promise returned by an
adapter's `createRecord`, `updateRecord` or `deleteRecord`
is rejected (with anything other than a `DS.InvalidError`).
@method recordWasError
@@ -11066,10 +10278,11 @@
*/
recordWasError: function (internalModel, error) {
internalModel.adapterDidError(error);
},
+
/**
When an adapter's `createRecord`, `updateRecord` or `deleteRecord`
resolves with data, this method extracts the ID from the supplied
data.
@method updateId
@@ -11078,16 +10291,18 @@
@param {Object} data
*/
updateId: function (internalModel, data) {
var oldId = internalModel.id;
var modelName = internalModel.modelName;
- var id = (0, _emberDataPrivateSystemCoerceId.default)(data.id);
+ var id = (0, _coerceId.default)(data.id);
// ID absolutely can't be missing if the oldID is empty (missing Id in response for a new record)
+
// ID absolutely can't be different than oldID if oldID is not null
+
// ID can be null if oldID is not null (altered ID in response for a record)
// however, this is more than likely a developer error.
if (oldId !== null && id === null) {
return;
}
@@ -11095,10 +10310,11 @@
this._internalModelsFor(internalModel.modelName).set(id, internalModel);
internalModel.setId(id);
},
+
/**
Returns a map of IDs to client IDs for a given modelName.
@method _internalModelsFor
@private
@param {String} modelName
@@ -11106,10 +10322,11 @@
*/
_internalModelsFor: function (modelName) {
return this._identityMap.retrieve(modelName);
},
+
// ................
// . LOADING DATA .
// ................
/**
@@ -11126,10 +10343,11 @@
this.recordArrayManager.recordDidChange(internalModel);
return internalModel;
},
+
/*
In case someone defined a relationship to a mixin, for example:
```
let Comment = DS.Model.extend({
owner: belongsTo('commentable'. { polymorphic: true })
@@ -11146,22 +10364,22 @@
*/
_modelForMixin: function (normalizedModelName) {
// container.registry = 2.1
// container._registry = 1.11 - 2.0
// container = < 1.11
- var owner = (0, _emberDataPrivateUtils.getOwner)(this);
- var mixin = undefined;
+ var owner = (0, _utils.getOwner)(this);
+ var mixin = void 0;
if (owner.factoryFor) {
var MaybeMixin = owner.factoryFor('mixin:' + normalizedModelName);
mixin = MaybeMixin && MaybeMixin.class;
} else {
mixin = owner._lookupFactory('mixin:' + normalizedModelName);
}
if (mixin) {
- var ModelForMixin = _emberDataModel.default.extend(mixin);
+ var ModelForMixin = _model.default.extend(mixin);
ModelForMixin.reopenClass({
__isMixin: true,
__mixin: mixin
});
@@ -11170,10 +10388,11 @@
}
return this.modelFactoryFor(normalizedModelName);
},
+
/**
Returns the model class for the particular `modelName`.
The class of a model might be useful if you want to get a list of all the
relationship names of the model, see
[`relationshipNames`](http://emberjs.com/api/data/classes/DS.Model.html#property_relationshipNames)
@@ -11182,24 +10401,24 @@
@param {String} modelName
@return {DS.Model}
*/
modelFor: function (modelName) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
return this._modelFor(normalizedModelName);
},
+
/*
@private
*/
_modelFor: function (modelName) {
var maybeFactory = this._modelFactoryFor(modelName);
// for factorFor factory/class split
return maybeFactory.class ? maybeFactory.class : maybeFactory;
},
-
_modelFactoryFor: function (modelName) {
var factory = this._modelFactoryCache[modelName];
if (!factory) {
factory = this.modelFactoryFor(modelName);
@@ -11211,36 +10430,38 @@
if (!factory) {
throw new EmberError('No model was found for \'' + modelName + '\'');
}
// interopt with the future
- var klass = (0, _emberDataPrivateUtils.getOwner)(this).factoryFor ? factory.class : factory;
+ var klass = (0, _utils.getOwner)(this).factoryFor ? factory.class : factory;
// TODO: deprecate this
klass.modelName = klass.modelName || modelName;
this._modelFactoryCache[modelName] = factory;
}
return factory;
},
+
/*
@private
*/
modelFactoryFor: function (modelName) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
- var owner = (0, _emberDataPrivateUtils.getOwner)(this);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
+ var owner = (0, _utils.getOwner)(this);
if (owner.factoryFor) {
return owner.factoryFor('model:' + normalizedModelName);
} else {
return owner._lookupFactory('model:' + normalizedModelName);
}
},
+
/**
Push some data for a given type into the store.
This method expects normalized [JSON API](http://jsonapi.org/) document. This means you have to follow [JSON API specification](http://jsonapi.org/format/) with few minor adjustments:
- record's `type` should always be in singular, dasherized form
- members (properties) should be camelCased
@@ -11386,10 +10607,11 @@
var record = pushed.getRecord();
return record;
},
+
/*
Push some data in the form of a json-api document into the store,
without creating materialized records.
@method _push
@private
@@ -11399,12 +10621,12 @@
_push: function (jsonApiDoc) {
var _this = this;
var internalModelOrModels = this._backburner.join(function () {
var included = jsonApiDoc.included;
- var i = undefined,
- length = undefined;
+ var i = void 0,
+ length = void 0;
if (included) {
for (i = 0, length = included.length; i < length; i++) {
_this._pushInternalModel(included[i]);
}
@@ -11427,41 +10649,40 @@
return _this._pushInternalModel(jsonApiDoc.data);
});
return internalModelOrModels;
},
-
_hasModelFor: function (modelName) {
- var owner = (0, _emberDataPrivateUtils.getOwner)(this);
- modelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var owner = (0, _utils.getOwner)(this);
+ modelName = (0, _normalizeModelName.default)(modelName);
if (owner.factoryFor) {
return !!owner.factoryFor('model:' + modelName);
} else {
return !!owner._lookupFactory('model:' + modelName);
}
},
-
_pushInternalModel: function (data) {
+ var _this2 = this;
+
var modelName = data.type;
+
// Actually load the record into the store.
var internalModel = this._load(data);
this._setupRelationshipsForModel(internalModel, data);
return internalModel;
},
-
_setupRelationshipsForModel: function (internalModel, data) {
if (this._pushedInternalModels.push(internalModel, data) !== 2) {
return;
}
this._backburner.schedule('normalizeRelationships', this, this._setupRelationships);
},
-
_setupRelationships: function () {
var pushed = this._pushedInternalModels;
for (var i = 0, l = pushed.length; i < l; i += 2) {
// This will convert relationships specified as IDs into DS.Model instances
@@ -11473,10 +10694,11 @@
}
pushed.length = 0;
},
+
/**
Push some raw data into the store.
This method can be used both to push in brand new
records, as well as to update existing records. You
can push in more than one type of object at once.
@@ -11516,28 +10738,29 @@
@method pushPayload
@param {String} modelName Optionally, a model type used to determine which serializer will be used
@param {Object} inputPayload
*/
pushPayload: function (modelName, inputPayload) {
- var serializer = undefined;
- var payload = undefined;
+ var serializer = void 0;
+ var payload = void 0;
if (!inputPayload) {
payload = modelName;
serializer = defaultSerializer(this);
} else {
payload = inputPayload;
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
serializer = this.serializerFor(normalizedModelName);
}
- if ((0, _emberDataPrivateFeatures.default)('ds-pushpayload-return')) {
+ if ((0, _features.default)('ds-pushpayload-return')) {
return serializer.pushPayload(this, payload);
} else {
serializer.pushPayload(this, payload);
}
},
+
/**
`normalize` converts a json payload into the normalized form that
[push](#method_push) expects.
Example
```js
@@ -11551,16 +10774,17 @@
@param {String} modelName The name of the model type for this payload
@param {Object} payload
@return {Object} The normalized payload
*/
normalize: function (modelName, payload) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
var serializer = this.serializerFor(normalizedModelName);
var model = this._modelFor(normalizedModelName);
return serializer.normalize(model, payload);
},
+
/**
Build a brand new record for a given type, ID, and
initial data.
@method buildRecord
@private
@@ -11573,22 +10797,24 @@
var recordMap = this._internalModelsFor(modelName);
// lookupFactory should really return an object that creates
// instances with the injections applied
- var internalModel = new _emberDataPrivateSystemModelInternalModel.default(modelName, id, this, data);
+ var internalModel = new _internalModel5.default(modelName, id, this, data);
recordMap.add(internalModel, id);
return internalModel;
},
+
//Called by the state machine to notify the store that the record is ready to be interacted with
recordWasLoaded: function (record) {
this.recordArrayManager.recordWasLoaded(record);
},
+
// ...............
// . DESTRUCTION .
// ...............
/**
@@ -11603,10 +10829,11 @@
var id = internalModel.id;
recordMap.remove(internalModel, id);
},
+
// ......................
// . PER-TYPE ADAPTERS
// ......................
/**
@@ -11622,15 +10849,16 @@
@public
@param {String} modelName
@return DS.Adapter
*/
adapterFor: function (modelName) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
return this._instanceCache.get('adapter', normalizedModelName);
},
+
// ..............................
// . RECORD CHANGE NOTIFICATION .
// ..............................
/**
@@ -11649,81 +10877,72 @@
@public
@param {String} modelName the record to serialize
@return {DS.Serializer}
*/
serializerFor: function (modelName) {
- var normalizedModelName = (0, _emberDataPrivateSystemNormalizeModelName.default)(modelName);
+ var normalizedModelName = (0, _normalizeModelName.default)(modelName);
return this._instanceCache.get('serializer', normalizedModelName);
},
-
lookupAdapter: function (name) {
return this.adapterFor(name);
},
-
lookupSerializer: function (name) {
return this.serializerFor(name);
},
-
willDestroy: function () {
this._super.apply(this, arguments);
this._pushedInternalModels = null;
this.recordArrayManager.destroy();
this._instanceCache.destroy();
this.unloadAll();
},
-
_updateRelationshipState: function (relationship) {
- var _this2 = this;
+ var _this3 = this;
if (this._updatedRelationships.push(relationship) !== 1) {
return;
}
this._backburner.join(function () {
- _this2._backburner.schedule('syncRelationships', _this2, _this2._flushUpdatedRelationships);
+ _this3._backburner.schedule('syncRelationships', _this3, _this3._flushUpdatedRelationships);
});
},
-
_flushUpdatedRelationships: function () {
var updated = this._updatedRelationships;
for (var i = 0, l = updated.length; i < l; i++) {
updated[i].flushCanonical();
}
updated.length = 0;
},
-
_updateInternalModel: function (internalModel) {
if (this._updatedInternalModels.push(internalModel) !== 1) {
return;
}
emberRun.schedule('actions', this, this._flushUpdatedInternalModels);
},
-
_flushUpdatedInternalModels: function () {
var updated = this._updatedInternalModels;
for (var i = 0, l = updated.length; i < l; i++) {
updated[i]._triggerDeferredTriggers();
}
updated.length = 0;
},
-
_pushResourceIdentifier: function (relationship, resourceIdentifier) {
if (isNone(resourceIdentifier)) {
return;
}
//TODO:Better asserts
return this._internalModelForId(resourceIdentifier.type, resourceIdentifier.id);
},
-
_pushResourceIdentifiers: function (relationship, resourceIdentifiers) {
if (isNone(resourceIdentifiers)) {
return;
}
@@ -11735,26 +10954,27 @@
}
});
// Delegation to the adapter and promise management
+
function defaultSerializer(store) {
return store.serializerFor('application');
}
function _commit(adapter, store, operation, snapshot) {
var internalModel = snapshot._internalModel;
var modelName = snapshot.modelName;
var modelClass = store._modelFor(modelName);
var promise = adapter[operation](store, modelClass, snapshot);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, modelName);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName);
var label = 'DS: Extract and notify about ' + operation + ' completion of ' + internalModel;
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, internalModel));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, internalModel));
return promise.then(function (adapterPayload) {
/*
Note to future spelunkers hoping to optimize.
We rely on this `run` to create a run loop if needed
@@ -11762,25 +10982,25 @@
We use `join` because it is often the case that we
have an outer run loop available still from the first
call to `store._push`;
*/
store._backburner.join(function () {
- var payload = undefined,
- data = undefined;
+ var payload = void 0,
+ data = void 0;
if (adapterPayload) {
- payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, snapshot.id, operation);
+ payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, snapshot.id, operation);
if (payload.included) {
store._push({ data: null, included: payload.included });
}
data = payload.data;
}
store.didSaveRecord(internalModel, { data: data });
});
return internalModel;
}, function (error) {
- if (error instanceof _emberDataAdaptersErrors.InvalidError) {
+ if (error instanceof _errors.InvalidError) {
var errors = serializer.extractErrors(store, modelClass, error, snapshot.id);
store.recordWasInvalid(internalModel, errors);
} else {
store.recordWasError(internalModel, error);
@@ -11806,26 +11026,18 @@
}
exports.Store = Store;
exports.default = Store;
});
-/**
- @module ember-data
-*/
-
-// If ENV.DS_WARN_ON_UNKNOWN_KEYS is set to true and the payload
-// contains unknown attributes or relationships, log a warning.
-
-// Check unknown attributes
-
-// Check unknown relationships
define('ember-data/-private/system/store/common', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+
+ exports.__esModule = true;
exports._bind = _bind;
exports._guard = _guard;
exports._objectIsAlive = _objectIsAlive;
var get = _ember.default.get;
-
function _bind(fn) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
@@ -11846,149 +11058,127 @@
function _objectIsAlive(object) {
return !(get(object, "isDestroyed") || get(object, "isDestroying"));
}
});
-define('ember-data/-private/system/store/container-instance-cache', ['exports', 'ember', 'ember-data/-private/system/empty-object'], function (exports, _ember, _emberDataPrivateSystemEmptyObject) {
- var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+define('ember-data/-private/system/store/container-instance-cache', ['exports', 'ember', 'ember-data/-private/system/empty-object'], function (exports, _ember, _emptyObject) {
+ 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+ exports.__esModule = true;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+
var set = _ember.default.set;
- /*
- * The `ContainerInstanceCache` serves as a lazy cache for looking up
- * instances of serializers and adapters. It has some additional logic for
- * finding the 'fallback' adapter or serializer.
- *
- * The 'fallback' adapter or serializer is an adapter or serializer that is looked up
- * when the preferred lookup fails. For example, say you try to look up `adapter:post`,
- * but there is no entry (app/adapters/post.js in EmberCLI) for `adapter:post` in the registry.
- *
- * When an adapter or serializer is unfound, getFallbacks will be invoked with the current namespace
- * ('adapter' or 'serializer') and the 'preferredKey' (usually a modelName). The method should return
- * an array of keys to check against.
- *
- * The first entry in the fallbacks array that exists in the container will then be cached for
- * `adapter:post`. So, the next time you look up `adapter:post`, you'll get the `adapter:application`
- * instance (or whatever the fallback was if `adapter:application` doesn't exist).
- *
- * @private
- * @class ContainerInstanceCache
- *
- */
-
- var ContainerInstanceCache = (function () {
+ var ContainerInstanceCache = function () {
function ContainerInstanceCache(owner, store) {
this._owner = owner;
this._store = store;
this._namespaces = {
- adapter: new _emberDataPrivateSystemEmptyObject.default(),
- serializer: new _emberDataPrivateSystemEmptyObject.default()
+ adapter: new _emptyObject.default(),
+ serializer: new _emptyObject.default()
};
}
- _createClass(ContainerInstanceCache, [{
- key: 'get',
- value: function get(namespace, preferredKey) {
- var cache = this._namespaces[namespace];
+ ContainerInstanceCache.prototype.get = function get(namespace, preferredKey) {
+ var cache = this._namespaces[namespace];
- if (cache[preferredKey]) {
- return cache[preferredKey];
- }
+ if (cache[preferredKey]) {
+ return cache[preferredKey];
+ }
- var preferredLookupKey = namespace + ':' + preferredKey;
+ var preferredLookupKey = namespace + ':' + preferredKey;
- var instance = this._instanceFor(preferredLookupKey) || this._findInstance(namespace, this._fallbacksFor(namespace, preferredKey));
- if (instance) {
- cache[preferredKey] = instance;
- set(instance, 'store', this._store);
- }
-
- return cache[preferredKey];
+ var instance = this._instanceFor(preferredLookupKey) || this._findInstance(namespace, this._fallbacksFor(namespace, preferredKey));
+ if (instance) {
+ cache[preferredKey] = instance;
+ set(instance, 'store', this._store);
}
- }, {
- key: '_fallbacksFor',
- value: function _fallbacksFor(namespace, preferredKey) {
- if (namespace === 'adapter') {
- return ['application', this._store.get('adapter'), '-json-api'];
- }
- // serializer
- return ['application', this.get('adapter', preferredKey).get('defaultSerializer'), '-default'];
+ return cache[preferredKey];
+ };
+
+ ContainerInstanceCache.prototype._fallbacksFor = function _fallbacksFor(namespace, preferredKey) {
+ if (namespace === 'adapter') {
+ return ['application', this._store.get('adapter'), '-json-api'];
}
- }, {
- key: '_findInstance',
- value: function _findInstance(namespace, fallbacks) {
- var cache = this._namespaces[namespace];
- for (var i = 0, _length = fallbacks.length; i < _length; i++) {
- var fallback = fallbacks[i];
+ // serializer
+ return ['application', this.get('adapter', preferredKey).get('defaultSerializer'), '-default'];
+ };
- if (cache[fallback]) {
- return cache[fallback];
- }
+ ContainerInstanceCache.prototype._findInstance = function _findInstance(namespace, fallbacks) {
+ var cache = this._namespaces[namespace];
- var lookupKey = namespace + ':' + fallback;
- var instance = this._instanceFor(lookupKey);
+ for (var i = 0, length = fallbacks.length; i < length; i++) {
+ var fallback = fallbacks[i];
- if (instance) {
- cache[fallback] = instance;
- return instance;
- }
+ if (cache[fallback]) {
+ return cache[fallback];
}
+
+ var lookupKey = namespace + ':' + fallback;
+ var instance = this._instanceFor(lookupKey);
+
+ if (instance) {
+ cache[fallback] = instance;
+ return instance;
+ }
}
- }, {
- key: '_instanceFor',
- value: function _instanceFor(key) {
- return this._owner.lookup(key);
- }
- }, {
- key: 'destroyCache',
- value: function destroyCache(cache) {
- var cacheEntries = Object.keys(cache);
+ };
- for (var i = 0, _length2 = cacheEntries.length; i < _length2; i++) {
- var cacheKey = cacheEntries[i];
- var cacheEntry = cache[cacheKey];
- if (cacheEntry) {
- cacheEntry.destroy();
- }
+ ContainerInstanceCache.prototype._instanceFor = function _instanceFor(key) {
+ return this._owner.lookup(key);
+ };
+
+ ContainerInstanceCache.prototype.destroyCache = function destroyCache(cache) {
+ var cacheEntries = Object.keys(cache);
+
+ for (var i = 0, length = cacheEntries.length; i < length; i++) {
+ var cacheKey = cacheEntries[i];
+ var cacheEntry = cache[cacheKey];
+ if (cacheEntry) {
+ cacheEntry.destroy();
}
}
- }, {
- key: 'destroy',
- value: function destroy() {
- this.destroyCache(this._namespaces.adapter);
- this.destroyCache(this._namespaces.serializer);
- this._namespaces = null;
- this._store = null;
- this._owner = null;
- }
- }, {
- key: 'toString',
- value: function toString() {
- return 'ContainerInstanceCache';
- }
- }]);
+ };
+ ContainerInstanceCache.prototype.destroy = function destroy() {
+ this.destroyCache(this._namespaces.adapter);
+ this.destroyCache(this._namespaces.serializer);
+ this._namespaces = null;
+ this._store = null;
+ this._owner = null;
+ };
+
+ ContainerInstanceCache.prototype.toString = function toString() {
+ return 'ContainerInstanceCache';
+ };
+
return ContainerInstanceCache;
- })();
+ }();
exports.default = ContainerInstanceCache;
});
-/* global heimdall */
-define("ember-data/-private/system/store/finders", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/store/common", "ember-data/-private/system/store/serializer-response", "ember-data/-private/system/store/serializers"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemStoreCommon, _emberDataPrivateSystemStoreSerializerResponse, _emberDataPrivateSystemStoreSerializers) {
+define("ember-data/-private/system/store/finders", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/store/common", "ember-data/-private/system/store/serializer-response", "ember-data/-private/system/store/serializers"], function (exports, _ember, _debug, _common, _serializerResponse, _serializers) {
+ "use strict";
+
+ exports.__esModule = true;
exports._find = _find;
exports._findMany = _findMany;
exports._findHasMany = _findHasMany;
exports._findBelongsTo = _findBelongsTo;
exports._findAll = _findAll;
exports._query = _query;
exports._queryRecord = _queryRecord;
var Promise = _ember.default.RSVP.Promise;
+
function payloadIsNotBlank(adapterPayload) {
if (Array.isArray(adapterPayload)) {
return true;
} else {
return Object.keys(adapterPayload || {}).length;
@@ -11998,19 +11188,20 @@
function _find(adapter, store, modelClass, id, internalModel, options) {
var snapshot = internalModel.createSnapshot(options);
var modelName = internalModel.modelName;
var promise = adapter.findRecord(store, modelClass, id, snapshot);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, modelName);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName);
var label = "DS: Handle Adapter#findRecord of '" + modelName + "' with id: '" + id + "'";
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, id, 'findRecord');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, id, 'findRecord');
+
return store._push(payload);
}, function (error) {
internalModel.notFound();
if (internalModel.isEmpty()) {
internalModel.unloadRecord();
@@ -12022,39 +11213,39 @@
function _findMany(adapter, store, modelName, ids, internalModels) {
var snapshots = _ember.default.A(internalModels).invoke('createSnapshot');
var modelClass = store.modelFor(modelName); // `adapter.findMany` gets the modelClass still
var promise = adapter.findMany(store, modelClass, ids, snapshots);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, modelName);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName);
var label = "DS: Handle Adapter#findMany of '" + modelName + "'";
if (promise === undefined) {
throw new Error('adapter.findMany returned undefined, this was very likely a mistake');
}
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findMany');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findMany');
return store._push(payload);
}, null, "DS: Extract payload of " + modelName);
}
function _findHasMany(adapter, store, internalModel, link, relationship) {
var snapshot = internalModel.createSnapshot();
var modelClass = store.modelFor(relationship.type);
var promise = adapter.findHasMany(store, snapshot, link, relationship);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, relationship.type);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, relationship.type);
var label = "DS: Handle Adapter#findHasMany of '" + internalModel.modelName + "' : '" + relationship.type + "'";
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, internalModel));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, internalModel));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findHasMany');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findHasMany');
var internalModelArray = store._push(payload);
internalModelArray.meta = payload.meta;
return internalModelArray;
}, null, "DS: Extract payload of '" + internalModel.modelName + "' : hasMany '" + relationship.type + "'");
@@ -12062,19 +11253,19 @@
function _findBelongsTo(adapter, store, internalModel, link, relationship) {
var snapshot = internalModel.createSnapshot();
var modelClass = store.modelFor(relationship.type);
var promise = adapter.findBelongsTo(store, snapshot, link, relationship);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, relationship.type);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, relationship.type);
var label = "DS: Handle Adapter#findBelongsTo of " + internalModel.modelName + " : " + relationship.type;
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, internalModel));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, internalModel));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findBelongsTo');
if (!payload.data) {
return null;
}
@@ -12085,18 +11276,18 @@
function _findAll(adapter, store, modelName, sinceToken, options) {
var modelClass = store.modelFor(modelName); // adapter.findAll depends on the class
var recordArray = store.peekAll(modelName);
var snapshotArray = recordArray._createSnapshot(options);
var promise = adapter.findAll(store, modelClass, sinceToken, snapshotArray);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, modelName);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName);
var label = "DS: Handle Adapter#findAll of " + modelClass;
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findAll');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'findAll');
store._push(payload);
store.didUpdateAll(modelName);
return store.peekAll(modelName);
@@ -12105,19 +11296,19 @@
function _query(adapter, store, modelName, query, recordArray) {
var modelClass = store.modelFor(modelName); // adapter.query needs the class
var promise = adapter.query(store, modelClass, query, recordArray);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, modelName);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName);
var label = "DS: Handle Adapter#query of " + modelClass;
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'query');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'query');
var internalModels = store._push(payload);
recordArray._setInternalModels(internalModels, payload);
@@ -12126,38 +11317,41 @@
}
function _queryRecord(adapter, store, modelName, query) {
var modelClass = store.modelFor(modelName); // adapter.queryRecord needs the class
var promise = adapter.queryRecord(store, modelClass, query);
- var serializer = (0, _emberDataPrivateSystemStoreSerializers.serializerForAdapter)(store, adapter, modelName);
+ var serializer = (0, _serializers.serializerForAdapter)(store, adapter, modelName);
var label = "DS: Handle Adapter#queryRecord of " + modelName;
promise = Promise.resolve(promise, label);
- promise = (0, _emberDataPrivateSystemStoreCommon._guard)(promise, (0, _emberDataPrivateSystemStoreCommon._bind)(_emberDataPrivateSystemStoreCommon._objectIsAlive, store));
+ promise = (0, _common._guard)(promise, (0, _common._bind)(_common._objectIsAlive, store));
return promise.then(function (adapterPayload) {
- var payload = (0, _emberDataPrivateSystemStoreSerializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'queryRecord');
+ var payload = (0, _serializerResponse.normalizeResponseHelper)(serializer, store, modelClass, adapterPayload, null, 'queryRecord');
return store._push(payload);
}, null, "DS: Extract payload of queryRecord " + modelName);
}
});
-define('ember-data/-private/system/store/serializer-response', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
+define('ember-data/-private/system/store/serializer-response', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _debug) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.validateDocumentStructure = validateDocumentStructure;
exports.normalizeResponseHelper = normalizeResponseHelper;
+
/*
This is a helper method that validates a JSON API top-level document
The format of a document is described here:
http://jsonapi.org/format/#document-top-level
@method validateDocumentStructure
@param {Object} doc JSON API document
@return {array} An array of errors found in the document structure
*/
-
function validateDocumentStructure(doc) {
var errors = [];
if (!doc || typeof doc !== 'object') {
errors.push('Top level of a JSON API document must be an object');
} else {
@@ -12213,21 +11407,23 @@
@param {Object} payload
@param {String|Number} id
@param {String} requestType
@return {Object} JSON-API Document
*/
-
function normalizeResponseHelper(serializer, store, modelClass, payload, id, requestType) {
var normalizedResponse = serializer.normalizeResponse(store, modelClass, payload, id, requestType);
var validationErrors = [];
+
return normalizedResponse;
}
});
define("ember-data/-private/system/store/serializers", ["exports"], function (exports) {
- exports.serializerForAdapter = serializerForAdapter;
+ "use strict";
+ exports.__esModule = true;
+ exports.serializerForAdapter = serializerForAdapter;
function serializerForAdapter(store, adapter, modelName) {
var serializer = adapter.serializer;
if (serializer === undefined) {
serializer = store.serializerFor(modelName);
@@ -12242,57 +11438,27 @@
}
return serializer;
}
});
-define("ember-data/-private/transforms", ["exports", "ember-data/transform", "ember-data/-private/transforms/number", "ember-data/-private/transforms/date", "ember-data/-private/transforms/string", "ember-data/-private/transforms/boolean"], function (exports, _emberDataTransform, _emberDataPrivateTransformsNumber, _emberDataPrivateTransformsDate, _emberDataPrivateTransformsString, _emberDataPrivateTransformsBoolean) {
- exports.Transform = _emberDataTransform.default;
- exports.NumberTransform = _emberDataPrivateTransformsNumber.default;
- exports.DateTransform = _emberDataPrivateTransformsDate.default;
- exports.StringTransform = _emberDataPrivateTransformsString.default;
- exports.BooleanTransform = _emberDataPrivateTransformsBoolean.default;
+define("ember-data/-private/transforms", ["exports", "ember-data/transform", "ember-data/-private/transforms/number", "ember-data/-private/transforms/date", "ember-data/-private/transforms/string", "ember-data/-private/transforms/boolean"], function (exports, _transform, _number, _date, _string, _boolean) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.BooleanTransform = exports.StringTransform = exports.DateTransform = exports.NumberTransform = exports.Transform = undefined;
+ exports.Transform = _transform.default;
+ exports.NumberTransform = _number.default;
+ exports.DateTransform = _date.default;
+ exports.StringTransform = _string.default;
+ exports.BooleanTransform = _boolean.default;
});
-define("ember-data/-private/transforms/boolean", ["exports", "ember", "ember-data/transform"], function (exports, _ember, _emberDataTransform) {
- var isNone = _ember.default.isNone;
+define("ember-data/-private/transforms/boolean", ["exports", "ember", "ember-data/transform"], function (exports, _ember, _transform) {
+ "use strict";
- /**
- The `DS.BooleanTransform` class is used to serialize and deserialize
- boolean attributes on Ember Data record objects. This transform is
- used when `boolean` is passed as the type parameter to the
- [DS.attr](../../data#method_attr) function.
-
- Usage
-
- ```app/models/user.js
- import DS from 'ember-data';
-
- export default DS.Model.extend({
- isAdmin: DS.attr('boolean'),
- name: DS.attr('string'),
- email: DS.attr('string')
- });
- ```
-
- By default the boolean transform only allows for values of `true` or
- `false`. You can opt into allowing `null` values for
- boolean attributes via `DS.attr('boolean', { allowNull: true })`
-
- ```app/models/user.js
- import DS from 'ember-data';
-
- export default DS.Model.extend({
- email: DS.attr('string'),
- username: DS.attr('string'),
- wantsWeeklyEmail: DS.attr('boolean', { allowNull: true })
- });
- ```
-
- @class BooleanTransform
- @extends DS.Transform
- @namespace DS
- */
- exports.default = _emberDataTransform.default.extend({
+ exports.__esModule = true;
+ var isNone = _ember.default.isNone;
+ exports.default = _transform.default.extend({
deserialize: function (serialized, options) {
var type = typeof serialized;
if (isNone(serialized) && options.allowNull === true) {
return null;
@@ -12306,71 +11472,54 @@
return serialized === 1;
} else {
return false;
}
},
-
serialize: function (deserialized, options) {
if (isNone(deserialized) && options.allowNull === true) {
return null;
}
return Boolean(deserialized);
}
});
});
-define("ember-data/-private/transforms/date", ["exports", "ember-data/-private/ext/date", "ember-data/transform"], function (exports, _emberDataPrivateExtDate, _emberDataTransform) {
- exports.default = _emberDataTransform.default.extend({
+define("ember-data/-private/transforms/date", ["exports", "ember-data/-private/ext/date", "ember-data/transform"], function (exports, _date, _transform) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.default = _transform.default.extend({
deserialize: function (serialized) {
var type = typeof serialized;
if (type === "string") {
- return new Date((0, _emberDataPrivateExtDate.parseDate)(serialized));
+ return new Date((0, _date.parseDate)(serialized));
} else if (type === "number") {
return new Date(serialized);
} else if (serialized === null || serialized === undefined) {
// if the value is null return null
// if the value is not present in the data return undefined
return serialized;
} else {
return null;
}
},
-
serialize: function (date) {
if (date instanceof Date && !isNaN(date)) {
return date.toISOString();
} else {
return null;
}
}
});
});
+define("ember-data/-private/transforms/number", ["exports", "ember", "ember-data/transform"], function (exports, _ember, _transform) {
+ "use strict";
-/**
- The `DS.DateTransform` class is used to serialize and deserialize
- date attributes on Ember Data record objects. This transform is used
- when `date` is passed as the type parameter to the
- [DS.attr](../../data#method_attr) function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601)
- standard.
+ exports.__esModule = true;
- ```app/models/score.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- value: DS.attr('number'),
- player: DS.belongsTo('player'),
- date: DS.attr('date')
- });
- ```
-
- @class DateTransform
- @extends DS.Transform
- @namespace DS
- */
-define("ember-data/-private/transforms/number", ["exports", "ember", "ember-data/transform"], function (exports, _ember, _emberDataTransform) {
-
var empty = _ember.default.isEmpty;
function isNumber(value) {
return value === value && value !== Infinity && value !== -Infinity;
}
@@ -12395,25 +11544,24 @@
@class NumberTransform
@extends DS.Transform
@namespace DS
*/
- exports.default = _emberDataTransform.default.extend({
+ exports.default = _transform.default.extend({
deserialize: function (serialized) {
- var transformed = undefined;
+ var transformed = void 0;
if (empty(serialized)) {
return null;
} else {
transformed = Number(serialized);
return isNumber(transformed) ? transformed : null;
}
},
-
serialize: function (deserialized) {
- var transformed = undefined;
+ var transformed = void 0;
if (empty(deserialized)) {
return null;
} else {
transformed = Number(deserialized);
@@ -12421,12 +11569,16 @@
return isNumber(transformed) ? transformed : null;
}
}
});
});
-define("ember-data/-private/transforms/string", ["exports", "ember", "ember-data/transform"], function (exports, _ember, _emberDataTransform) {
+define("ember-data/-private/transforms/string", ["exports", "ember", "ember-data/transform"], function (exports, _ember, _transform) {
+ "use strict";
+ exports.__esModule = true;
+
+
var none = _ember.default.isNone;
/**
The `DS.StringTransform` class is used to serialize and deserialize
string attributes on Ember Data record objects. This transform is
@@ -12447,21 +11599,26 @@
@class StringTransform
@extends DS.Transform
@namespace DS
*/
- exports.default = _emberDataTransform.default.extend({
+ exports.default = _transform.default.extend({
deserialize: function (serialized) {
return none(serialized) ? null : String(serialized);
},
serialize: function (deserialized) {
return none(deserialized) ? null : String(deserialized);
}
});
});
define('ember-data/-private/utils', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+ exports.__esModule = true;
+ exports.getOwner = exports.modelHasAttributeOrRelationshipNamedType = undefined;
+
+
var get = _ember.default.get;
/*
Check if the passed model has a `type` attribute or a relationship named `type`.
@@ -12476,11 +11633,11 @@
ember-container-inject-owner is a new feature in Ember 2.3 that finally provides a public
API for looking items up. This function serves as a super simple polyfill to avoid
triggering deprecations.
*/
function getOwner(context) {
- var owner = undefined;
+ var owner = void 0;
if (_ember.default.getOwner) {
owner = _ember.default.getOwner(context);
} else if (context.container) {
owner = context.container;
@@ -12500,35 +11657,37 @@
}
exports.modelHasAttributeOrRelationshipNamedType = modelHasAttributeOrRelationshipNamedType;
exports.getOwner = getOwner;
});
-define('ember-data/-private/utils/parse-response-headers', ['exports', 'ember-data/-private/system/empty-object'], function (exports, _emberDataPrivateSystemEmptyObject) {
+define('ember-data/-private/utils/parse-response-headers', ['exports', 'ember-data/-private/system/empty-object'], function (exports, _emptyObject) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = parseResponseHeaders;
- function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
+ function _toArray(arr) {
+ return Array.isArray(arr) ? arr : Array.from(arr);
+ }
var CLRF = '\u000d\u000a';
function parseResponseHeaders(headersString) {
- var headers = new _emberDataPrivateSystemEmptyObject.default();
+ var headers = new _emptyObject.default();
if (!headersString) {
return headers;
}
var headerPairs = headersString.split(CLRF);
headerPairs.forEach(function (header) {
- var _header$split = header.split(':');
+ var _header$split = header.split(':'),
+ _header$split2 = _toArray(_header$split),
+ field = _header$split2[0],
+ value = _header$split2.slice(1);
- var _header$split2 = _toArray(_header$split);
-
- var field = _header$split2[0];
-
- var value = _header$split2.slice(1);
-
field = field.trim();
value = value.join(':').trim();
if (value) {
headers[field] = value;
@@ -12537,67 +11696,13 @@
return headers;
}
});
define('ember-data/adapter', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /**
- An adapter is an object that receives requests from a store and
- translates them into the appropriate action to take against your
- persistence layer. The persistence layer is usually an HTTP API, but
- may be anything, such as the browser's local storage. Typically the
- adapter is not invoked directly instead its functionality is accessed
- through the `store`.
-
- ### Creating an Adapter
-
- Create a new subclass of `DS.Adapter` in the `app/adapters` folder:
-
- ```app/adapters/application.js
- import DS from 'ember-data';
-
- export default DS.Adapter.extend({
- // ...your code here
- });
- ```
-
- Model-specific adapters can be created by putting your adapter
- class in an `app/adapters/` + `model-name` + `.js` file of the application.
-
- ```app/adapters/post.js
- import DS from 'ember-data';
-
- export default DS.Adapter.extend({
- // ...Post-specific adapter code goes here
- });
- ```
-
- `DS.Adapter` is an abstract base class that you should override in your
- application to customize it for your backend. The minimum set of methods
- that you should implement is:
-
- * `findRecord()`
- * `createRecord()`
- * `updateRecord()`
- * `deleteRecord()`
- * `findAll()`
- * `query()`
-
- To improve the network performance of your application, you can optimize
- your adapter by overriding these lower-level methods:
-
- * `findMany()`
-
-
- For an example implementation, see `DS.RESTAdapter`, the
- included REST adapter.
-
- @class Adapter
- @namespace DS
- @extends Ember.Object
- */
-
+ exports.__esModule = true;
exports.default = _ember.default.Object.extend({
/**
If you would like your adapter to use a custom serializer you can
set the `defaultSerializer` property to be the name of the custom
@@ -12782,10 +11887,11 @@
*/
serialize: function (snapshot, options) {
return snapshot.serialize(options);
},
+
/**
Implement this method in a subclass to handle the creation of
new records.
Serializes the record and sends it to the server.
Example
@@ -12956,10 +12062,11 @@
*/
groupRecordsForFindMany: function (store, snapshots) {
return [snapshots];
},
+
/**
This method is used by the store to determine if the store should
reload a record from the adapter when a record is requested by
`store.findRecord`.
If this method returns `true`, the store will re-fetch a record from
@@ -12998,10 +12105,11 @@
*/
shouldReloadRecord: function (store, snapshot) {
return false;
},
+
/**
This method is used by the store to determine if the store should
reload all records from the adapter when records are requested by
`store.findAll`.
If this method returns `true`, the store will re-fetch all records from
@@ -13044,10 +12152,11 @@
*/
shouldReloadAll: function (store, snapshotRecordArray) {
return !snapshotRecordArray.length;
},
+
/**
This method is used by the store to determine if the store should
reload a record after the `store.findRecord` method resolves a
cached record.
This method is *only* checked by the store when the store is
@@ -13077,10 +12186,11 @@
*/
shouldBackgroundReloadRecord: function (store, snapshot) {
return true;
},
+
/**
This method is used by the store to determine if the store should
reload a record array after the `store.findAll` method resolves
with a cached record array.
This method is *only* checked by the store when the store is
@@ -13111,18 +12221,20 @@
shouldBackgroundReloadAll: function (store, snapshotRecordArray) {
return true;
}
});
});
-/**
- @module ember-data
-*/
-define('ember-data/adapters/errors', ['exports', 'ember', 'ember-data/-private/debug', 'ember-data/-private/features'], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateFeatures) {
+define('ember-data/adapters/errors', ['exports', 'ember', 'ember-data/-private/debug', 'ember-data/-private/features'], function (exports, _ember, _debug, _features) {
+ 'use strict';
+
+ exports.__esModule = true;
+ exports.ServerError = exports.ConflictError = exports.NotFoundError = exports.ForbiddenError = exports.UnauthorizedError = exports.AbortError = exports.TimeoutError = exports.InvalidError = undefined;
exports.AdapterError = AdapterError;
exports.errorsHashToArray = errorsHashToArray;
exports.errorsArrayToHash = errorsArrayToHash;
+
var EmberError = _ember.default.Error;
var SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
var SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
var PRIMARY_ATTRIBUTE_KEY = 'base';
@@ -13192,13 +12304,12 @@
```
@class AdapterError
@namespace DS
*/
-
function AdapterError(errors) {
- var message = arguments.length <= 1 || arguments[1] === undefined ? 'Adapter operation failed' : arguments[1];
+ var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Adapter operation failed';
this.isAdapterError = true;
EmberError.call(this, message);
this.errors = errors || [{
@@ -13212,14 +12323,13 @@
extendedErrorsEnabled = true;
}
function extendFn(ErrorClass) {
return function () {
- var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
+ defaultMessage = _ref.message;
- var defaultMessage = _ref.message;
-
return extend(ErrorClass, defaultMessage);
};
}
function extend(ParentErrorClass, defaultMessage) {
@@ -13297,13 +12407,12 @@
wrap the error payload unaltered.
@class InvalidError
@namespace DS
*/
- var InvalidError = extend(AdapterError, 'The adapter rejected the commit because it was invalid');
+ var InvalidError = exports.InvalidError = extend(AdapterError, 'The adapter rejected the commit because it was invalid');
- exports.InvalidError = InvalidError;
/**
A `DS.TimeoutError` is used by an adapter to signal that a request
to the external API has timed out. I.e. no response was received from
the external API within an allowed time period.
@@ -13332,25 +12441,23 @@
```
@class TimeoutError
@namespace DS
*/
- var TimeoutError = extend(AdapterError, 'The adapter operation timed out');
+ var TimeoutError = exports.TimeoutError = extend(AdapterError, 'The adapter operation timed out');
- exports.TimeoutError = TimeoutError;
/**
A `DS.AbortError` is used by an adapter to signal that a request to
the external API was aborted. For example, this can occur if the user
navigates away from the current page after a request to the external API
has been initiated but before a response has been received.
@class AbortError
@namespace DS
*/
- var AbortError = extend(AdapterError, 'The adapter operation was aborted');
+ var AbortError = exports.AbortError = extend(AdapterError, 'The adapter operation was aborted');
- exports.AbortError = AbortError;
/**
A `DS.UnauthorizedError` equates to a HTTP `401 Unauthorized` response
status. It is used by an adapter to signal that a request to the external
API was rejected because authorization is required and has failed or has not
yet been provided.
@@ -13380,26 +12487,24 @@
```
@class UnauthorizedError
@namespace DS
*/
- var UnauthorizedError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation is unauthorized') : null;
+ var UnauthorizedError = exports.UnauthorizedError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation is unauthorized') : null;
- exports.UnauthorizedError = UnauthorizedError;
/**
A `DS.ForbiddenError` equates to a HTTP `403 Forbidden` response status.
It is used by an adapter to signal that a request to the external API was
valid but the server is refusing to respond to it. If authorization was
provided and is valid, then the authenticated user does not have the
necessary permissions for the request.
@class ForbiddenError
@namespace DS
*/
- var ForbiddenError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation is forbidden') : null;
+ var ForbiddenError = exports.ForbiddenError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation is forbidden') : null;
- exports.ForbiddenError = ForbiddenError;
/**
A `DS.NotFoundError` equates to a HTTP `404 Not Found` response status.
It is used by an adapter to signal that a request to the external API
was rejected because the resource could not be found on the API.
@@ -13432,37 +12537,34 @@
```
@class NotFoundError
@namespace DS
*/
- var NotFoundError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter could not find the resource') : null;
+ var NotFoundError = exports.NotFoundError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter could not find the resource') : null;
- exports.NotFoundError = NotFoundError;
/**
A `DS.ConflictError` equates to a HTTP `409 Conflict` response status.
It is used by an adapter to indicate that the request could not be processed
because of a conflict in the request. An example scenario would be when
creating a record with a client generated id but that id is already known
to the external API.
@class ConflictError
@namespace DS
*/
- var ConflictError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation failed due to a conflict') : null;
+ var ConflictError = exports.ConflictError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation failed due to a conflict') : null;
- exports.ConflictError = ConflictError;
/**
A `DS.ServerError` equates to a HTTP `500 Internal Server Error` response
status. It is used by the adapter to indicate that a request has failed
because of an error in the external API.
@class ServerError
@namespace DS
*/
- var ServerError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation failed due to a server error') : null;
+ var ServerError = exports.ServerError = extendedErrorsEnabled ? extend(AdapterError, 'The adapter operation failed due to a server error') : null;
- exports.ServerError = ServerError;
/**
Convert an hash of errors into an array with errors in JSON-API format.
```javascript
import DS from 'ember-data';
@@ -13505,11 +12607,10 @@
@namespace
@for DS
@param {Object} errors hash with errors as properties
@return {Array} array of errors in JSON-API format
*/
-
function errorsHashToArray(errors) {
var out = [];
if (_ember.default.isPresent(errors)) {
Object.keys(errors).forEach(function (key) {
@@ -13573,11 +12674,10 @@
@namespace
@for DS
@param {Array} errors array of errors in JSON-API format
@return {Object}
*/
-
function errorsArrayToHash(errors) {
var out = {};
if (_ember.default.isPresent(errors)) {
errors.forEach(function (error) {
@@ -13599,12 +12699,16 @@
}
return out;
}
});
-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) {
+define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters/rest', 'ember-data/-private/features', 'ember-data/-private/debug'], function (exports, _ember, _rest, _features, _debug) {
+ 'use strict';
+ exports.__esModule = true;
+
+
/**
The `JSONAPIAdapter` is the default adapter used by Ember Data. It
is responsible for transforming the store's requests into HTTP
requests that follow the [JSON API](http://jsonapi.org/format/)
format.
@@ -13737,21 +12841,18 @@
@class JSONAPIAdapter
@constructor
@namespace DS
@extends DS.RESTAdapter
*/
- var JSONAPIAdapter = _emberDataAdaptersRest.default.extend({
+ /* global heimdall */
+ /**
+ @module ember-data
+ */
+
+ var JSONAPIAdapter = _rest.default.extend({
defaultSerializer: '-json-api',
- /**
- @method ajaxOptions
- @private
- @param {String} url
- @param {String} type The request type GET, POST, PUT, DELETE etc.
- @param {Object} options
- @return {Object}
- */
ajaxOptions: function (url, type, options) {
var hash = this._super.apply(this, arguments);
if (hash.contentType) {
hash.contentType = 'application/vnd.api+json';
@@ -13766,10 +12867,11 @@
};
return hash;
},
+
/**
By default the JSONAPIAdapter will send each find request coming from a `store.find`
or from accessing a relationship separately to the server. If your server supports passing
ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests
within a single runloop.
@@ -13813,26 +12915,23 @@
@type {boolean}
*/
coalesceFindRequests: false,
findMany: function (store, type, ids, snapshots) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !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(',') } } });
}
},
-
pathForType: function (modelName) {
var dasherized = _ember.default.String.dasherize(modelName);
return _ember.default.String.pluralize(dasherized);
},
-
- // TODO: Remove this once we have a better way to override HTTP verbs.
updateRecord: function (store, type, snapshot) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
return this._super.apply(this, arguments);
} else {
var data = {};
var serializer = store.serializerFor(type.modelName);
@@ -13841,11 +12940,10 @@
var url = this.buildURL(type.modelName, snapshot.id, snapshot, 'updateRecord');
return this.ajax(url, 'PATCH', { data: data });
}
},
-
_hasCustomizedAjax: function () {
if (this.ajax !== JSONAPIAdapter.prototype.ajax) {
return true;
}
@@ -13855,36 +12953,35 @@
return false;
}
});
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax')) {
+ if ((0, _features.default)('ds-improved-ajax')) {
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;
+ var requestType = params.requestType,
+ 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 store = params.store,
+ type = params.type,
+ snapshot = params.snapshot;
var data = {};
var serializer = store.serializerFor(type.modelName);
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
@@ -13892,42 +12989,39 @@
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;
});
-/* global heimdall */
-/**
- @module ember-data
-*/
-define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'ember-data/adapters/errors', 'ember-data/-private/adapters/build-url-mixin', 'ember-data/-private/features', 'ember-data/-private/debug', 'ember-data/-private/utils/parse-response-headers'], function (exports, _ember, _emberDataAdapter, _emberDataAdaptersErrors, _emberDataPrivateAdaptersBuildUrlMixin, _emberDataPrivateFeatures, _emberDataPrivateDebug, _emberDataPrivateUtilsParseResponseHeaders) {
- var MapWithDefault = _ember.default.MapWithDefault;
- var get = _ember.default.get;
+define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'ember-data/adapters/errors', 'ember-data/-private/adapters/build-url-mixin', 'ember-data/-private/features', 'ember-data/-private/debug', 'ember-data/-private/utils/parse-response-headers'], function (exports, _ember, _adapter, _errors, _buildUrlMixin, _features, _debug, _parseResponseHeaders) {
+ 'use strict';
+ exports.__esModule = true;
+ var MapWithDefault = _ember.default.MapWithDefault,
+ get = _ember.default.get;
+
+
var Promise = _ember.default.RSVP.Promise;
/**
The REST adapter allows your store to communicate with an HTTP server by
transmitting JSON via XHR. Most Ember.js apps that consume a JSON API
@@ -14181,44 +13275,13 @@
@constructor
@namespace DS
@extends DS.Adapter
@uses DS.BuildURLMixin
*/
- var RESTAdapter = _emberDataAdapter.default.extend(_emberDataPrivateAdaptersBuildUrlMixin.default, {
+ var RESTAdapter = _adapter.default.extend(_buildUrlMixin.default, {
defaultSerializer: '-rest',
- /**
- By default, the RESTAdapter will send the query params sorted alphabetically to the
- server.
- For example:
- ```js
- store.query('posts', { sort: 'price', category: 'pets' });
- ```
- will generate a requests like this `/posts?category=pets&sort=price`, even if the
- parameters were specified in a different order.
- That way the generated URL will be deterministic and that simplifies caching mechanisms
- in the backend.
- Setting `sortQueryParams` to a falsey value will respect the original order.
- In case you want to sort the query parameters with a different criteria, set
- `sortQueryParams` to your custom sort function.
- ```app/adapters/application.js
- import DS from 'ember-data';
- export default DS.RESTAdapter.extend({
- sortQueryParams(params) {
- let sortedKeys = Object.keys(params).sort().reverse();
- let len = sortedKeys.length, newParams = {};
- for (let i = 0; i < len; i++) {
- newParams[sortedKeys[i]] = params[sortedKeys[i]];
- }
- return newParams;
- }
- });
- ```
- @method sortQueryParams
- @param {Object} obj
- @return {Object}
- */
sortQueryParams: function (obj) {
var keys = Object.keys(obj);
var len = keys.length;
if (len < 2) {
return obj;
@@ -14230,10 +13293,11 @@
newQueryParams[sortedKeys[i]] = obj[sortedKeys[i]];
}
return newQueryParams;
},
+
/**
By default the RESTAdapter will send each find request coming from a `store.find`
or from accessing a relationship separately to the server. If your server supports passing
ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests
within a single runloop.
@@ -14268,72 +13332,12 @@
@property coalesceFindRequests
@type {boolean}
*/
coalesceFindRequests: false,
- /**
- Endpoint paths can be prefixed with a `namespace` by setting the namespace
- property on the adapter:
- ```app/adapters/application.js
- import DS from 'ember-data';
- export default DS.RESTAdapter.extend({
- namespace: 'api/1'
- });
- ```
- Requests for the `Post` model would now target `/api/1/post/`.
- @property namespace
- @type {String}
- */
-
- /**
- An adapter can target other hosts by setting the `host` property.
- ```app/adapters/application.js
- import DS from 'ember-data';
- export default DS.RESTAdapter.extend({
- host: 'https://api.example.com'
- });
- ```
- Requests for the `Post` model would now target `https://api.example.com/post/`.
- @property host
- @type {String}
- */
-
- /**
- Some APIs require HTTP headers, e.g. to provide an API
- key. Arbitrary headers can be set as key/value pairs on the
- `RESTAdapter`'s `headers` object and Ember Data will send them
- along with each ajax request. For dynamic headers see [headers
- customization](/api/data/classes/DS.RESTAdapter.html#toc_headers-customization).
- ```app/adapters/application.js
- import DS from 'ember-data';
- export default DS.RESTAdapter.extend({
- headers: {
- 'API_KEY': 'secret key',
- 'ANOTHER_HEADER': 'Some header value'
- }
- });
- ```
- @property headers
- @type {Object}
- */
-
- /**
- Called by the store in order to fetch the JSON for a given
- type and ID.
- The `findRecord` method makes an Ajax request to a URL computed by
- `buildURL`, and returns a promise for the resulting payload.
- This method performs an HTTP `GET` request with the id provided as part of the query string.
- @since 1.13.0
- @method findRecord
- @param {DS.Store} store
- @param {DS.Model} type
- @param {String} id
- @param {DS.Snapshot} snapshot
- @return {Promise} promise
- */
findRecord: function (store, type, id, snapshot) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, id: id, snapshot: snapshot,
requestType: 'findRecord'
});
@@ -14343,27 +13347,14 @@
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.
- The `findAll` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
- promise for the resulting payload.
- @method findAll
- @param {DS.Store} store
- @param {DS.Model} type
- @param {String} sinceToken
- @param {DS.SnapshotRecordArray} snapshotRecordArray
- @return {Promise} promise
- */
findAll: function (store, type, sinceToken, snapshotRecordArray) {
var query = this.buildQuery(snapshotRecordArray);
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, sinceToken: sinceToken, query: query,
snapshots: snapshotRecordArray,
requestType: 'findAll'
});
@@ -14377,27 +13368,12 @@
}
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.
- The `query` method makes an Ajax (HTTP GET) request to a URL
- computed by `buildURL`, and returns a promise for the resulting
- payload.
- The `query` argument is a simple JavaScript object that will be passed directly
- to the server as parameters.
- @method query
- @param {DS.Store} store
- @param {DS.Model} type
- @param {Object} query
- @return {Promise} promise
- */
query: function (store, type, query) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, query: query,
requestType: 'query'
});
@@ -14410,28 +13386,12 @@
}
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.
- The `queryRecord` method makes an Ajax (HTTP GET) request to a URL
- computed by `buildURL`, and returns a promise for the resulting
- payload.
- The `query` argument is a simple JavaScript object that will be passed directly
- to the server as parameters.
- @since 1.13.0
- @method queryRecord
- @param {DS.Store} store
- @param {DS.Model} type
- @param {Object} query
- @return {Promise} promise
- */
queryRecord: function (store, type, query) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, query: query,
requestType: 'queryRecord'
});
@@ -14444,39 +13404,12 @@
}
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:
- ```js
- {
- "id": 1,
- "title": "Rails is omakase",
- "comments": [ 1, 2, 3 ]
- }
- ```
- The IDs will be passed as a URL-encoded Array of IDs, in this form:
- ```
- ids[]=1&ids[]=2&ids[]=3
- ```
- Many servers, such as Rails and PHP, will automatically convert this URL-encoded array
- into an Array for you on the server-side. If you want to encode the
- IDs, differently, just override this (one-line) method.
- The `findMany` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a
- promise for the resulting payload.
- @method findMany
- @param {DS.Store} store
- @param {DS.Model} type
- @param {Array} ids
- @param {Array} snapshots
- @return {Promise} promise
- */
findMany: function (store, type, ids, snapshots) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, ids: ids, snapshots: snapshots,
requestType: 'findMany'
});
@@ -14484,40 +13417,12 @@
} 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
- specified as a URL (inside of `links`).
- For example, if your original payload looks like this:
- ```js
- {
- "post": {
- "id": 1,
- "title": "Rails is omakase",
- "links": { "comments": "/posts/1/comments" }
- }
- }
- ```
- This method will be called with the parent record and `/posts/1/comments`.
- The `findHasMany` method will make an Ajax (HTTP GET) request to the originally specified URL.
- The format of your `links` value will influence the final request URL via the `urlPrefix` method:
- * Links beginning with `//`, `http://`, `https://`, will be used as is, with no further manipulation.
- * Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
- * Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
- @method findHasMany
- @param {DS.Store} store
- @param {DS.Snapshot} snapshot
- @param {Object} relationship meta object describing the relationship
- @param {String} url
- @return {Promise} promise
- */
findHasMany: function (store, snapshot, url, relationship) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, snapshot: snapshot, url: url, relationship: relationship,
requestType: 'findHasMany'
});
@@ -14529,39 +13434,12 @@
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
- `links`).
- For example, if your original payload looks like this:
- ```js
- {
- "person": {
- "id": 1,
- "name": "Tom Dale",
- "links": { "group": "/people/1/group" }
- }
- }
- ```
- This method will be called with the parent record and `/people/1/group`.
- The `findBelongsTo` method will make an Ajax (HTTP GET) request to the originally specified URL.
- The format of your `links` value will influence the final request URL via the `urlPrefix` method:
- * Links beginning with `//`, `http://`, `https://`, will be used as is, with no further manipulation.
- * Links beginning with a single `/` will have the current adapter's `host` value prepended to it.
- * Links with no beginning `/` will have a parentURL prepended to it, via the current adapter's `buildURL`.
- @method findBelongsTo
- @param {DS.Store} store
- @param {DS.Snapshot} snapshot
- @param {String} url
- @return {Promise} promise
- */
findBelongsTo: function (store, snapshot, url, relationship) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, snapshot: snapshot, url: url, relationship: relationship,
requestType: 'findBelongsTo'
});
@@ -14572,26 +13450,12 @@
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.
- The `createRecord` method serializes the record and makes an Ajax (HTTP POST) request
- to a URL computed by `buildURL`.
- See `serialize` for information on how to customize the serialized form
- of a record.
- @method createRecord
- @param {DS.Store} store
- @param {DS.Model} type
- @param {DS.Snapshot} snapshot
- @return {Promise} promise
- */
createRecord: function (store, type, snapshot) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, snapshot: snapshot,
requestType: 'createRecord'
});
@@ -14604,26 +13468,12 @@
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.
- The `updateRecord` method serializes the record and makes an Ajax (HTTP PUT) request
- to a URL computed by `buildURL`.
- See `serialize` for information on how to customize the serialized form
- of a record.
- @method updateRecord
- @param {DS.Store} store
- @param {DS.Model} type
- @param {DS.Snapshot} snapshot
- @return {Promise} promise
- */
updateRecord: function (store, type, snapshot) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, snapshot: snapshot,
requestType: 'updateRecord'
});
@@ -14638,22 +13488,12 @@
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`.
- @method deleteRecord
- @param {DS.Store} store
- @param {DS.Model} type
- @param {DS.Snapshot} snapshot
- @return {Promise} promise
- */
deleteRecord: function (store, type, snapshot) {
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
+ if ((0, _features.default)('ds-improved-ajax') && !this._hasCustomizedAjax()) {
var request = this._requestFor({
store: store, type: type, snapshot: snapshot,
requestType: 'deleteRecord'
});
@@ -14662,11 +13502,10 @@
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);
var expandedURL = url.split('/');
// Case when the url is of the format ...something/:id
@@ -14684,35 +13523,20 @@
}
return expandedURL.join('/');
},
+
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
maxURLLength: 2048,
- /**
- Organize records into groups, each of which is to be passed to separate
- calls to `findMany`.
- This implementation groups together records that have the same base URL but
- differing ids. For example `/comments/1` and `/comments/2` will be grouped together
- because we know findMany can coalesce them together as `/comments?ids[]=1&ids[]=2`
- It also supports urls where ids are passed as a query param, such as `/comments?id=1`
- but not those where there is more than 1 query param such as `/comments?id=2&name=David`
- Currently only the query param of `id` is supported. If you need to support others, please
- override this or the `_stripIDFromURL` method.
- It does not group records that have differing base urls, such as for example: `/posts/1/comments/2`
- and `/posts/2/comments/3`
- @method groupRecordsForFindMany
- @param {DS.Store} store
- @param {Array} snapshots
- @return {Array} an array of arrays of records, each of which is to be
- loaded separately by `findMany`.
- */
groupRecordsForFindMany: function (store, snapshots) {
- var groups = MapWithDefault.create({ defaultValue: function () {
+ var groups = MapWithDefault.create({
+ defaultValue: function () {
return [];
- } });
+ }
+ });
var adapter = this;
var maxURLLength = this.maxURLLength;
snapshots.forEach(function (snapshot) {
var baseUrl = adapter._stripIDFromURL(store, snapshot);
@@ -14750,113 +13574,45 @@
});
});
return groupsArray;
},
-
- /**
- Takes an ajax response, and returns the json payload or an error.
- By default this hook just returns the json payload passed to it.
- You might want to override it in two cases:
- 1. Your API might return useful results in the response headers.
- Response headers are passed in as the second argument.
- 2. Your API might return errors as successful responses with status code
- 200 and an Errors text or object. You can return a `DS.InvalidError` or a
- `DS.AdapterError` (or a sub class) from this hook and it will automatically
- reject the promise and put your record into the invalid or error state.
- Returning a `DS.InvalidError` from this method will cause the
- record to transition into the `invalid` state and make the
- `errors` object available on the record. When returning an
- `DS.InvalidError` the store will attempt to normalize the error data
- returned from the server using the serializer's `extractErrors`
- method.
- @since 1.13.0
- @method handleResponse
- @param {Number} status
- @param {Object} headers
- @param {Object} payload
- @param {Object} requestData - the original request information
- @return {Object | DS.AdapterError} response
- */
handleResponse: function (status, headers, payload, requestData) {
if (this.isSuccess(status, headers, payload)) {
return payload;
} else if (this.isInvalid(status, headers, payload)) {
- return new _emberDataAdaptersErrors.InvalidError(payload.errors);
+ return new _errors.InvalidError(payload.errors);
}
var errors = this.normalizeErrorResponse(status, headers, payload);
var detailedMessage = this.generatedDetailedMessage(status, headers, payload, requestData);
if (true) {
switch (status) {
case 401:
- return new _emberDataAdaptersErrors.UnauthorizedError(errors, detailedMessage);
+ return new _errors.UnauthorizedError(errors, detailedMessage);
case 403:
- return new _emberDataAdaptersErrors.ForbiddenError(errors, detailedMessage);
+ return new _errors.ForbiddenError(errors, detailedMessage);
case 404:
- return new _emberDataAdaptersErrors.NotFoundError(errors, detailedMessage);
+ return new _errors.NotFoundError(errors, detailedMessage);
case 409:
- return new _emberDataAdaptersErrors.ConflictError(errors, detailedMessage);
+ return new _errors.ConflictError(errors, detailedMessage);
default:
if (status >= 500) {
- return new _emberDataAdaptersErrors.ServerError(errors, detailedMessage);
+ return new _errors.ServerError(errors, detailedMessage);
}
}
}
- return new _emberDataAdaptersErrors.AdapterError(errors, detailedMessage);
+ return new _errors.AdapterError(errors, detailedMessage);
},
-
- /**
- Default `handleResponse` implementation uses this hook to decide if the
- response is a success.
- @since 1.13.0
- @method isSuccess
- @param {Number} status
- @param {Object} headers
- @param {Object} payload
- @return {Boolean}
- */
isSuccess: function (status, headers, payload) {
return status >= 200 && status < 300 || status === 304;
},
-
- /**
- Default `handleResponse` implementation uses this hook to decide if the
- response is an invalid error.
- @since 1.13.0
- @method isInvalid
- @param {Number} status
- @param {Object} headers
- @param {Object} payload
- @return {Boolean}
- */
isInvalid: function (status, headers, payload) {
return status === 422;
},
-
- /**
- Takes a URL, an HTTP method and a hash of data, and makes an
- HTTP request.
- When the server responds with a payload, Ember Data will call into `extractSingle`
- or `extractArray` (depending on whether the original query was for one record or
- many records).
- By default, `ajax` method has the following behavior:
- * It sets the response `dataType` to `"json"`
- * If the HTTP method is not `"GET"`, it sets the `Content-Type` to be
- `application/json; charset=utf-8`
- * If the HTTP method is not `"GET"`, it stringifies the data passed in. The
- data is the serialized record in the case of a save.
- * Registers success and failure handlers.
- @method ajax
- @private
- @param {String} url
- @param {String} type The request type GET, POST, PUT, DELETE etc.
- @param {Object} options
- @return {Promise} promise
- */
ajax: function (url, type, options) {
var adapter = this;
var requestData = {
url: url,
@@ -14881,28 +13637,13 @@
};
adapter._ajaxRequest(hash);
}, 'DS: RESTAdapter#ajax ' + type + ' to ' + url);
},
-
- /**
- @method _ajaxRequest
- @private
- @param {Object} options jQuery ajax options to be used for the ajax request
- */
_ajaxRequest: function (options) {
_ember.default.$.ajax(options);
},
-
- /**
- @method ajaxOptions
- @private
- @param {String} url
- @param {String} type The request type GET, POST, PUT, DELETE etc.
- @param {Object} options
- @return {Object}
- */
ajaxOptions: function (url, type, options) {
var hash = options || {};
hash.url = url;
hash.type = type;
hash.dataType = 'json';
@@ -14922,17 +13663,10 @@
};
}
return hash;
},
-
- /**
- @method parseErrorResponse
- @private
- @param {String} responseText
- @return {Object}
- */
parseErrorResponse: function (responseText) {
var json = responseText;
try {
json = _ember.default.$.parseJSON(responseText);
@@ -14940,19 +13674,10 @@
// ignored
}
return json;
},
-
- /**
- @method normalizeErrorResponse
- @private
- @param {Number} status
- @param {Object} headers
- @param {Object} payload
- @return {Array} errors payload
- */
normalizeErrorResponse: function (status, headers, payload) {
if (payload && typeof payload === 'object' && payload.errors) {
return payload.errors;
} else {
return [{
@@ -14961,10 +13686,11 @@
detail: '' + payload
}];
}
},
+
/**
Generates a detailed ("friendly") error message, with plenty
of information for debugging (good luck!)
@method generatedDetailedMessage
@private
@@ -14973,11 +13699,11 @@
@param {Object} payload
@param {Object} requestData
@return {String} detailed error message
*/
generatedDetailedMessage: function (status, headers, payload, requestData) {
- var shortenedPayload = undefined;
+ var shortenedPayload = void 0;
var payloadContentType = headers["Content-Type"] || "Empty Content-Type";
if (payloadContentType === "text/html" && payload.length > 250) {
shortenedPayload = "[Omitted Lengthy HTML]";
} else {
@@ -14988,25 +13714,24 @@
var payloadDescription = 'Payload (' + payloadContentType + ')';
return ['Ember Data Request ' + requestDescription + ' returned a ' + status, payloadDescription, shortenedPayload].join('\n');
},
- // @since 2.5.0
buildQuery: function (snapshot) {
var query = {};
if (snapshot) {
var include = snapshot.include;
+
if (include) {
query.include = include;
}
}
return query;
},
-
_hasCustomizedAjax: function () {
if (this.ajax !== RESTAdapter.prototype.ajax) {
return true;
}
@@ -15016,29 +13741,21 @@
return false;
}
});
- if ((0, _emberDataPrivateFeatures.default)('ds-improved-ajax')) {
+ if ((0, _features.default)('ds-improved-ajax')) {
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;
+ var store = params.store,
+ type = params.type,
+ snapshot = params.snapshot,
+ requestType = params.requestType,
+ query = params.query;
+
// type is not passed to findBelongsTo and findHasMany
type = type || snapshot && snapshot.type;
var serializer = store.serializerFor(type.modelName);
var data = {};
@@ -15081,22 +13798,14 @@
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';
@@ -15104,28 +13813,20 @@
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;
+ var type = params.type,
+ id = params.id,
+ ids = params.ids,
+ snapshot = params.snapshot,
+ snapshots = params.snapshots,
+ requestType = params.requestType,
+ 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;
@@ -15148,52 +13849,21 @@
}
}
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;
@@ -15218,25 +13888,16 @@
};
}
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 method = request.method,
+ url = request.url;
var requestData = { method: method, url: url };
return new _ember.default.RSVP.Promise(function (resolve, reject) {
@@ -15259,13 +13920,13 @@
}
});
}
function ajaxSuccess(adapter, jqXHR, payload, requestData) {
- var response = undefined;
+ var response = void 0;
try {
- response = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), payload, requestData);
+ response = adapter.handleResponse(jqXHR.status, (0, _parseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), payload, requestData);
} catch (error) {
return Promise.reject(error);
}
if (response && response.isAdapterError) {
@@ -15275,21 +13936,21 @@
}
}
function ajaxError(adapter, jqXHR, requestData, responseData) {
- var error = undefined;
+ var error = void 0;
if (responseData.errorThrown instanceof Error) {
error = responseData.errorThrown;
} else if (responseData.textStatus === 'timeout') {
- error = new _emberDataAdaptersErrors.TimeoutError();
+ error = new _errors.TimeoutError();
} else if (responseData.textStatus === 'abort' || jqXHR.status === 0) {
- error = new _emberDataAdaptersErrors.AbortError();
+ error = new _errors.AbortError();
} else {
try {
- error = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), adapter.parseErrorResponse(jqXHR.responseText) || responseData.errorThrown, requestData);
+ error = adapter.handleResponse(jqXHR.status, (0, _parseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), adapter.parseErrorResponse(jqXHR.responseText) || responseData.errorThrown, requestData);
} catch (e) {
error = e;
}
}
@@ -15305,17 +13966,17 @@
}
}
exports.default = RESTAdapter;
});
-/* global heimdall */
-/**
- @module ember-data
-*/
-define('ember-data/attr', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
+define('ember-data/attr', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _debug) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = attr;
+
/**
@module ember-data
*/
function getDefaultValue(record, options, key) {
@@ -15451,11 +14112,11 @@
}
},
set: function (key, value) {
var internalModel = this._internalModel;
var oldValue = getValue(internalModel, key);
- var originalValue = undefined;
+ var originalValue = void 0;
if (value !== oldValue) {
// Add the new value to the changed attributes hash; it will get deleted by
// the 'didSetProperty' handler if it is no different from the original value
internalModel._attributes[key] = value;
@@ -15477,244 +14138,187 @@
return value;
}
}).meta(meta);
}
});
-define("ember-data", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/features", "ember-data/-private/global", "ember-data/-private/core", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/model/internal-model", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/store", "ember-data/-private/system/model", "ember-data/model", "ember-data/-private/system/snapshot", "ember-data/adapter", "ember-data/serializer", "ember-data/adapters/errors", "ember-data/-private/system/record-arrays", "ember-data/-private/system/many-array", "ember-data/-private/system/record-array-manager", "ember-data/-private/adapters", "ember-data/-private/adapters/build-url-mixin", "ember-data/-private/serializers", "ember-inflector", "ember-data/serializers/embedded-records-mixin", "ember-data/-private/transforms", "ember-data/relationships", "ember-data/setup-container", "ember-data/-private/instance-initializers/initialize-store-service", "ember-data/-private/system/relationships/state/relationship"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateFeatures, _emberDataPrivateGlobal, _emberDataPrivateCore, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateSystemModelInternalModel, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemStore, _emberDataPrivateSystemModel, _emberDataModel, _emberDataPrivateSystemSnapshot, _emberDataAdapter, _emberDataSerializer, _emberDataAdaptersErrors, _emberDataPrivateSystemRecordArrays, _emberDataPrivateSystemManyArray, _emberDataPrivateSystemRecordArrayManager, _emberDataPrivateAdapters, _emberDataPrivateAdaptersBuildUrlMixin, _emberDataPrivateSerializers, _emberInflector, _emberDataSerializersEmbeddedRecordsMixin, _emberDataPrivateTransforms, _emberDataRelationships, _emberDataSetupContainer, _emberDataPrivateInstanceInitializersInitializeStoreService, _emberDataPrivateSystemRelationshipsStateRelationship) {
+define("ember-data", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/features", "ember-data/-private/global", "ember-data/-private/core", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/model/internal-model", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/store", "ember-data/-private/system/model", "ember-data/model", "ember-data/-private/system/snapshot", "ember-data/adapter", "ember-data/serializer", "ember-data/adapters/errors", "ember-data/-private/system/record-arrays", "ember-data/-private/system/many-array", "ember-data/-private/system/record-array-manager", "ember-data/-private/adapters", "ember-data/-private/adapters/build-url-mixin", "ember-data/-private/serializers", "ember-data/serializers/embedded-records-mixin", "ember-data/-private/transforms", "ember-data/relationships", "ember-data/setup-container", "ember-data/-private/instance-initializers/initialize-store-service", "ember-data/-private/system/relationships/state/relationship", "ember-inflector"], function (exports, _ember, _debug, _features, _global, _core, _normalizeModelName, _internalModel, _promiseProxies, _store, _model, _model2, _snapshot, _adapter, _serializer, _errors, _recordArrays, _manyArray, _recordArrayManager, _adapters, _buildUrlMixin, _serializers, _embeddedRecordsMixin, _transforms, _relationships, _setupContainer, _initializeStoreService, _relationship) {
+ "use strict";
+ exports.__esModule = true;
+
+
/**
Ember Data
@module ember-data
@main ember-data
*/
if (_ember.default.VERSION.match(/^1\.([0-9]|1[0-2])\./)) {
throw new _ember.default.Error("Ember Data requires at least Ember 1.13.0, but you have " + _ember.default.VERSION + ". Please upgrade your version of Ember, then upgrade Ember Data.");
}
- _emberDataPrivateCore.default.Store = _emberDataPrivateSystemStore.Store;
- _emberDataPrivateCore.default.PromiseArray = _emberDataPrivateSystemPromiseProxies.PromiseArray;
- _emberDataPrivateCore.default.PromiseObject = _emberDataPrivateSystemPromiseProxies.PromiseObject;
+ _core.default.Store = _store.Store;
+ _core.default.PromiseArray = _promiseProxies.PromiseArray;
+ _core.default.PromiseObject = _promiseProxies.PromiseObject;
- _emberDataPrivateCore.default.PromiseManyArray = _emberDataPrivateSystemPromiseProxies.PromiseManyArray;
+ _core.default.PromiseManyArray = _promiseProxies.PromiseManyArray;
- _emberDataPrivateCore.default.Model = _emberDataModel.default;
- _emberDataPrivateCore.default.RootState = _emberDataPrivateSystemModel.RootState;
- _emberDataPrivateCore.default.attr = _emberDataPrivateSystemModel.attr;
- _emberDataPrivateCore.default.Errors = _emberDataPrivateSystemModel.Errors;
+ _core.default.Model = _model2.default;
+ _core.default.RootState = _model.RootState;
+ _core.default.attr = _model.attr;
+ _core.default.Errors = _model.Errors;
- _emberDataPrivateCore.default.InternalModel = _emberDataPrivateSystemModelInternalModel.default;
- _emberDataPrivateCore.default.Snapshot = _emberDataPrivateSystemSnapshot.default;
+ _core.default.InternalModel = _internalModel.default;
+ _core.default.Snapshot = _snapshot.default;
- _emberDataPrivateCore.default.Adapter = _emberDataAdapter.default;
+ _core.default.Adapter = _adapter.default;
- _emberDataPrivateCore.default.AdapterError = _emberDataAdaptersErrors.AdapterError;
- _emberDataPrivateCore.default.InvalidError = _emberDataAdaptersErrors.InvalidError;
- _emberDataPrivateCore.default.TimeoutError = _emberDataAdaptersErrors.TimeoutError;
- _emberDataPrivateCore.default.AbortError = _emberDataAdaptersErrors.AbortError;
+ _core.default.AdapterError = _errors.AdapterError;
+ _core.default.InvalidError = _errors.InvalidError;
+ _core.default.TimeoutError = _errors.TimeoutError;
+ _core.default.AbortError = _errors.AbortError;
if (true) {
- _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;
+ _core.default.UnauthorizedError = _errors.UnauthorizedError;
+ _core.default.ForbiddenError = _errors.ForbiddenError;
+ _core.default.NotFoundError = _errors.NotFoundError;
+ _core.default.ConflictError = _errors.ConflictError;
+ _core.default.ServerError = _errors.ServerError;
}
- _emberDataPrivateCore.default.errorsHashToArray = _emberDataAdaptersErrors.errorsHashToArray;
- _emberDataPrivateCore.default.errorsArrayToHash = _emberDataAdaptersErrors.errorsArrayToHash;
+ _core.default.errorsHashToArray = _errors.errorsHashToArray;
+ _core.default.errorsArrayToHash = _errors.errorsArrayToHash;
- _emberDataPrivateCore.default.Serializer = _emberDataSerializer.default;
+ _core.default.Serializer = _serializer.default;
- _emberDataPrivateCore.default.DebugAdapter = _emberDataPrivateDebug.default;
+ _core.default.DebugAdapter = _debug.default;
- _emberDataPrivateCore.default.RecordArray = _emberDataPrivateSystemRecordArrays.RecordArray;
- _emberDataPrivateCore.default.FilteredRecordArray = _emberDataPrivateSystemRecordArrays.FilteredRecordArray;
- _emberDataPrivateCore.default.AdapterPopulatedRecordArray = _emberDataPrivateSystemRecordArrays.AdapterPopulatedRecordArray;
- _emberDataPrivateCore.default.ManyArray = _emberDataPrivateSystemManyArray.default;
+ _core.default.RecordArray = _recordArrays.RecordArray;
+ _core.default.FilteredRecordArray = _recordArrays.FilteredRecordArray;
+ _core.default.AdapterPopulatedRecordArray = _recordArrays.AdapterPopulatedRecordArray;
+ _core.default.ManyArray = _manyArray.default;
- _emberDataPrivateCore.default.RecordArrayManager = _emberDataPrivateSystemRecordArrayManager.default;
+ _core.default.RecordArrayManager = _recordArrayManager.default;
- _emberDataPrivateCore.default.RESTAdapter = _emberDataPrivateAdapters.RESTAdapter;
- _emberDataPrivateCore.default.BuildURLMixin = _emberDataPrivateAdaptersBuildUrlMixin.default;
+ _core.default.RESTAdapter = _adapters.RESTAdapter;
+ _core.default.BuildURLMixin = _buildUrlMixin.default;
- _emberDataPrivateCore.default.RESTSerializer = _emberDataPrivateSerializers.RESTSerializer;
- _emberDataPrivateCore.default.JSONSerializer = _emberDataPrivateSerializers.JSONSerializer;
+ _core.default.RESTSerializer = _serializers.RESTSerializer;
+ _core.default.JSONSerializer = _serializers.JSONSerializer;
- _emberDataPrivateCore.default.JSONAPIAdapter = _emberDataPrivateAdapters.JSONAPIAdapter;
- _emberDataPrivateCore.default.JSONAPISerializer = _emberDataPrivateSerializers.JSONAPISerializer;
+ _core.default.JSONAPIAdapter = _adapters.JSONAPIAdapter;
+ _core.default.JSONAPISerializer = _serializers.JSONAPISerializer;
- _emberDataPrivateCore.default.Transform = _emberDataPrivateTransforms.Transform;
- _emberDataPrivateCore.default.DateTransform = _emberDataPrivateTransforms.DateTransform;
- _emberDataPrivateCore.default.StringTransform = _emberDataPrivateTransforms.StringTransform;
- _emberDataPrivateCore.default.NumberTransform = _emberDataPrivateTransforms.NumberTransform;
- _emberDataPrivateCore.default.BooleanTransform = _emberDataPrivateTransforms.BooleanTransform;
+ _core.default.Transform = _transforms.Transform;
+ _core.default.DateTransform = _transforms.DateTransform;
+ _core.default.StringTransform = _transforms.StringTransform;
+ _core.default.NumberTransform = _transforms.NumberTransform;
+ _core.default.BooleanTransform = _transforms.BooleanTransform;
- _emberDataPrivateCore.default.EmbeddedRecordsMixin = _emberDataSerializersEmbeddedRecordsMixin.default;
+ _core.default.EmbeddedRecordsMixin = _embeddedRecordsMixin.default;
- _emberDataPrivateCore.default.belongsTo = _emberDataRelationships.belongsTo;
- _emberDataPrivateCore.default.hasMany = _emberDataRelationships.hasMany;
+ _core.default.belongsTo = _relationships.belongsTo;
+ _core.default.hasMany = _relationships.hasMany;
- _emberDataPrivateCore.default.Relationship = _emberDataPrivateSystemRelationshipsStateRelationship.default;
+ _core.default.Relationship = _relationship.default;
- _emberDataPrivateCore.default._setupContainer = _emberDataSetupContainer.default;
- _emberDataPrivateCore.default._initializeStoreService = _emberDataPrivateInstanceInitializersInitializeStoreService.default;
+ _core.default._setupContainer = _setupContainer.default;
+ _core.default._initializeStoreService = _initializeStoreService.default;
- Object.defineProperty(_emberDataPrivateCore.default, 'normalizeModelName', {
+ Object.defineProperty(_core.default, 'normalizeModelName', {
enumerable: true,
writable: false,
configurable: false,
- value: _emberDataPrivateSystemNormalizeModelName.default
+ value: _normalizeModelName.default
});
- Object.defineProperty(_emberDataPrivateGlobal.default, 'DS', {
+ Object.defineProperty(_global.default, 'DS', {
configurable: true,
get: function () {
- return _emberDataPrivateCore.default;
+ return _core.default;
}
});
- exports.default = _emberDataPrivateCore.default;
+ exports.default = _core.default;
});
define('ember-data/initializers/data-adapter', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /*
- This initializer is here to keep backwards compatibility with code depending
- on the `data-adapter` initializer (before Ember Data was an addon).
-
- Should be removed for Ember Data 3.x
- */
-
+ exports.__esModule = true;
exports.default = {
name: 'data-adapter',
before: 'store',
initialize: function () {}
};
});
-define('ember-data/initializers/ember-data', ['exports', 'ember-data/setup-container', 'ember-data/index'], function (exports, _emberDataSetupContainer, _emberDataIndex) {
+define('ember-data/initializers/ember-data', ['exports', 'ember-data/setup-container', 'ember-data/index'], function (exports, _setupContainer) {
+ 'use strict';
- /*
-
- This code initializes Ember-Data onto an Ember application.
-
- If an Ember.js developer defines a subclass of DS.Store on their application,
- as `App.StoreService` (or via a module system that resolves to `service:store`)
- this code will automatically instantiate it and make it available on the
- router.
-
- Additionally, after an application's controllers have been injected, they will
- each have the store made available to them.
-
- For example, imagine an Ember.js application with the following classes:
-
- App.StoreService = DS.Store.extend({
- adapter: 'custom'
- });
-
- App.PostsController = Ember.Controller.extend({
- // ...
- });
-
- When the application is initialized, `App.ApplicationStore` will automatically be
- instantiated, and the instance of `App.PostsController` will have its `store`
- property set to that instance.
-
- Note that this code will only be run if the `ember-application` package is
- loaded. If Ember Data is being used in an environment other than a
- typical application (e.g., node.js where only `ember-runtime` is available),
- this code will be ignored.
- */
-
+ exports.__esModule = true;
exports.default = {
name: 'ember-data',
- initialize: _emberDataSetupContainer.default
+ initialize: _setupContainer.default
};
});
define('ember-data/initializers/injectStore', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /*
- This initializer is here to keep backwards compatibility with code depending
- on the `injectStore` initializer (before Ember Data was an addon).
-
- Should be removed for Ember Data 3.x
- */
-
+ exports.__esModule = true;
exports.default = {
name: 'injectStore',
before: 'store',
initialize: function () {}
};
});
define('ember-data/initializers/store', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /*
- This initializer is here to keep backwards compatibility with code depending
- on the `store` initializer (before Ember Data was an addon).
-
- Should be removed for Ember Data 3.x
- */
-
+ exports.__esModule = true;
exports.default = {
name: 'store',
after: 'ember-data',
initialize: function () {}
};
});
define('ember-data/initializers/transforms', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /*
- This initializer is here to keep backwards compatibility with code depending
- on the `transforms` initializer (before Ember Data was an addon).
-
- Should be removed for Ember Data 3.x
- */
-
+ exports.__esModule = true;
exports.default = {
name: 'transforms',
before: 'store',
initialize: function () {}
};
});
-define("ember-data/instance-initializers/ember-data", ["exports", "ember-data/-private/instance-initializers/initialize-store-service"], function (exports, _emberDataPrivateInstanceInitializersInitializeStoreService) {
+define("ember-data/instance-initializers/ember-data", ["exports", "ember-data/-private/instance-initializers/initialize-store-service"], function (exports, _initializeStoreService) {
+ "use strict";
+
+ exports.__esModule = true;
exports.default = {
name: "ember-data",
- initialize: _emberDataPrivateInstanceInitializersInitializeStoreService.default
+ initialize: _initializeStoreService.default
};
});
-define("ember-data/model", ["exports", "ember-data/-private/system/model"], function (exports, _emberDataPrivateSystemModel) {
- exports.default = _emberDataPrivateSystemModel.default;
+define("ember-data/model", ["exports", "ember-data/-private/system/model"], function (exports, _model) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.default = _model.default;
});
-define("ember-data/relationships", ["exports", "ember-data/-private/system/relationships/belongs-to", "ember-data/-private/system/relationships/has-many"], function (exports, _emberDataPrivateSystemRelationshipsBelongsTo, _emberDataPrivateSystemRelationshipsHasMany) {
- exports.belongsTo = _emberDataPrivateSystemRelationshipsBelongsTo.default;
- exports.hasMany = _emberDataPrivateSystemRelationshipsHasMany.default;
+define("ember-data/relationships", ["exports", "ember-data/-private/system/relationships/belongs-to", "ember-data/-private/system/relationships/has-many"], function (exports, _belongsTo, _hasMany) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.hasMany = exports.belongsTo = undefined;
+ exports.belongsTo = _belongsTo.default;
+ exports.hasMany = _hasMany.default;
});
-/**
- @module ember-data
-*/
define('ember-data/serializer', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /**
- `DS.Serializer` is an abstract base class that you should override in your
- application to customize it for your backend. The minimum set of methods
- that you should implement is:
-
- * `normalizeResponse()`
- * `serialize()`
-
- And you can optionally override the following methods:
-
- * `normalize()`
-
- For an example implementation, see
- [DS.JSONSerializer](DS.JSONSerializer.html), the included JSON serializer.
-
- @class Serializer
- @namespace DS
- @extends Ember.Object
- */
-
+ exports.__esModule = true;
exports.default = _ember.default.Object.extend({
/**
The `store` property is the application's `store` that contains
all records. It can be used to look up serializers for other model
@@ -15824,19 +14428,29 @@
@return {Object}
*/
normalize: function (typeClass, hash) {
return hash;
}
-
});
});
-/**
- @module ember-data
-*/
-define('ember-data/serializers/embedded-records-mixin', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
- 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); } }
+define('ember-data/serializers/embedded-records-mixin', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _debug) {
+ 'use strict';
+ exports.__esModule = true;
+
+ 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 set = _ember.default.set;
var camelize = _ember.default.String.camelize;
/**
@@ -15960,19 +14574,19 @@
**/
normalize: function (typeClass, hash, prop) {
var normalizedHash = this._super(typeClass, hash, prop);
return this._extractEmbeddedRecords(this, this.store, typeClass, normalizedHash);
},
-
keyForRelationship: function (key, typeClass, method) {
if (method === 'serialize' && this.hasSerializeRecordsOption(key) || method === 'deserialize' && this.hasDeserializeRecordsOption(key)) {
return this.keyForAttribute(key, method);
} else {
return this._super(key, typeClass, method) || key;
}
},
+
/**
Serialize `belongsTo` relationship when it is configured as an embedded object.
This example of an author model belongs to a post model:
```js
Post = DS.Model.extend({
@@ -16039,11 +14653,10 @@
}
} else if (includeRecords) {
this._serializeEmbeddedBelongsTo(snapshot, json, relationship);
}
},
-
_serializeEmbeddedBelongsTo: function (snapshot, json, relationship) {
var embeddedSnapshot = snapshot.belongsTo(relationship.key);
var serializedKey = this._getMappedKey(relationship.key, snapshot.type);
if (serializedKey === relationship.key && this.keyForRelationship) {
serializedKey = this.keyForRelationship(relationship.key, relationship.kind, "serialize");
@@ -16059,10 +14672,11 @@
this.serializePolymorphicType(snapshot, json, relationship);
}
}
},
+
/**
Serializes `hasMany` relationships when it is configured as embedded objects.
This example of a post model has many comments:
```js
Post = DS.Model.extend({
@@ -16192,10 +14806,11 @@
this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
}
}
},
+
/*
Serializes a hasMany relationship as an array of objects containing only `id` and `type`
keys.
This has its use case on polymorphic hasMany relationships where the server is not storing
all records in the same table using STI, and therefore the `id` is not enough information
@@ -16211,20 +14826,20 @@
// type too, and the modelName has to be normalized somehow.
//
return { id: recordSnapshot.id, type: recordSnapshot.modelName };
});
},
-
_serializeEmbeddedHasMany: function (snapshot, json, relationship) {
var serializedKey = this._getMappedKey(relationship.key, snapshot.type);
if (serializedKey === relationship.key && this.keyForRelationship) {
serializedKey = this.keyForRelationship(relationship.key, relationship.kind, "serialize");
}
json[serializedKey] = this._generateSerializedHasMany(snapshot, relationship);
},
+
/*
Returns an array of embedded records serialized to JSON
*/
_generateSerializedHasMany: function (snapshot, relationship) {
var hasMany = snapshot.hasMany(relationship.key);
@@ -16239,10 +14854,11 @@
}
return ret;
},
+
/**
When serializing an embedded record, modify the property (in the json payload)
that refers to the parent record (foreign key for relationship).
Serializing a `belongsTo` relationship removes the property that refers to the
parent record
@@ -16256,67 +14872,73 @@
*/
removeEmbeddedForeignKey: function (snapshot, embeddedSnapshot, relationship, json) {
if (relationship.kind === 'belongsTo') {
var parentRecord = snapshot.type.inverseFor(relationship.key, this.store);
if (parentRecord) {
- var _name = parentRecord.name;
+ var name = parentRecord.name;
var embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
- var parentKey = embeddedSerializer.keyForRelationship(_name, parentRecord.kind, 'deserialize');
+ var parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind, 'deserialize');
if (parentKey) {
delete json[parentKey];
}
}
} /*else if (relationship.kind === 'hasMany') {
return;
}*/
},
+
// checks config for attrs option to embedded (always) - serialize and deserialize
hasEmbeddedAlwaysOption: function (attr) {
var option = this.attrsOption(attr);
return option && option.embedded === 'always';
},
+
// checks config for attrs option to serialize ids
hasSerializeRecordsOption: function (attr) {
var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
var option = this.attrsOption(attr);
return alwaysEmbed || option && option.serialize === 'records';
},
+
// checks config for attrs option to serialize records
hasSerializeIdsOption: function (attr) {
var option = this.attrsOption(attr);
return option && (option.serialize === 'ids' || option.serialize === 'id');
},
+
// checks config for attrs option to serialize records as objects containing id and types
hasSerializeIdsAndTypesOption: function (attr) {
var option = this.attrsOption(attr);
return option && (option.serialize === 'ids-and-types' || option.serialize === 'id-and-type');
},
+
// checks config for attrs option to serialize records
noSerializeOptionSpecified: function (attr) {
var option = this.attrsOption(attr);
return !(option && (option.serialize || option.embedded));
},
+
// checks config for attrs option to deserialize records
// a defined option object for a resource is treated the same as
// `deserialize: 'records'`
hasDeserializeRecordsOption: function (attr) {
var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr);
var option = this.attrsOption(attr);
return alwaysEmbed || option && option.deserialize === 'records';
},
-
attrsOption: function (attr) {
var attrs = this.get('attrs');
return attrs && (attrs[camelize(attr)] || attrs[attr]);
},
+
/**
@method _extractEmbeddedRecords
@private
*/
_extractEmbeddedRecords: function (serializer, store, typeClass, partial) {
@@ -16333,10 +14955,11 @@
}
});
return partial;
},
+
/**
@method _extractEmbeddedHasMany
@private
*/
_extractEmbeddedHasMany: function (store, key, hash, relationshipMeta) {
@@ -16349,15 +14972,14 @@
var hasMany = new Array(relationshipHash.length);
for (var i = 0; i < relationshipHash.length; i++) {
var item = relationshipHash[i];
- var _normalizeEmbeddedRelationship = this._normalizeEmbeddedRelationship(store, relationshipMeta, item);
+ var _normalizeEmbeddedRel = this._normalizeEmbeddedRelationship(store, relationshipMeta, item),
+ data = _normalizeEmbeddedRel.data,
+ included = _normalizeEmbeddedRel.included;
- var data = _normalizeEmbeddedRelationship.data;
- var included = _normalizeEmbeddedRelationship.included;
-
hash.included = hash.included || [];
hash.included.push(data);
if (included) {
var _hash$included;
@@ -16369,25 +14991,25 @@
var relationship = { data: hasMany };
set(hash, 'data.relationships.' + key, relationship);
},
+
/**
@method _extractEmbeddedBelongsTo
@private
*/
_extractEmbeddedBelongsTo: function (store, key, hash, relationshipMeta) {
var relationshipHash = get(hash, 'data.relationships.' + key + '.data');
if (!relationshipHash) {
return;
}
- var _normalizeEmbeddedRelationship2 = this._normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash);
+ var _normalizeEmbeddedRel2 = this._normalizeEmbeddedRelationship(store, relationshipMeta, relationshipHash),
+ data = _normalizeEmbeddedRel2.data,
+ included = _normalizeEmbeddedRel2.included;
- var data = _normalizeEmbeddedRelationship2.data;
- var included = _normalizeEmbeddedRelationship2.included;
-
hash.included = hash.included || [];
hash.included.push(data);
if (included) {
var _hash$included2;
@@ -16398,10 +15020,11 @@
var relationship = { data: belongsTo };
set(hash, 'data.relationships.' + key, relationship);
},
+
/**
@method _normalizeEmbeddedRelationship
@private
*/
_normalizeEmbeddedRelationship: function (store, relationshipMeta, relationshipHash) {
@@ -16412,15 +15035,22 @@
var modelClass = store.modelFor(modelName);
var serializer = store.serializerFor(modelName);
return serializer.normalize(modelClass, relationshipHash, null);
},
+
isEmbeddedRecordsMixin: true
});
});
-define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-inflector', 'ember-data/-private/debug', 'ember-data/serializers/json', 'ember-data/-private/system/normalize-model-name', 'ember-data/-private/features'], function (exports, _ember, _emberInflector, _emberDataPrivateDebug, _emberDataSerializersJson, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateFeatures) {
+define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-inflector', 'ember-data/-private/debug', 'ember-data/serializers/json', 'ember-data/-private/system/normalize-model-name', 'ember-data/-private/features'], function (exports, _ember, _emberInflector, _debug, _json, _normalizeModelName, _features) {
+ 'use strict';
+ exports.__esModule = true;
+ /**
+ @module ember-data
+ */
+
var dasherize = _ember.default.String.dasherize;
/**
Ember Data 2.0 Serializer:
@@ -16535,18 +15165,11 @@
@since 1.13.0
@class JSONAPISerializer
@namespace DS
@extends DS.JSONSerializer
*/
- var JSONAPISerializer = _emberDataSerializersJson.default.extend({
-
- /**
- @method _normalizeDocumentHelper
- @param {Object} documentHash
- @return {Object}
- @private
- */
+ var JSONAPISerializer = _json.default.extend({
_normalizeDocumentHelper: function (documentHash) {
if (_ember.default.typeOf(documentHash.data) === 'object') {
documentHash.data = this._normalizeResourceHelper(documentHash.data);
} else if (Array.isArray(documentHash.data)) {
@@ -16559,31 +15182,24 @@
documentHash.data = ret;
}
if (Array.isArray(documentHash.included)) {
- var ret = new Array(documentHash.included.length);
+ var _ret = new Array(documentHash.included.length);
- for (var i = 0; i < documentHash.included.length; i++) {
- var included = documentHash.included[i];
- ret[i] = this._normalizeResourceHelper(included);
+ for (var _i = 0; _i < documentHash.included.length; _i++) {
+ var included = documentHash.included[_i];
+ _ret[_i] = this._normalizeResourceHelper(included);
}
- documentHash.included = ret;
+ documentHash.included = _ret;
}
return documentHash;
},
-
- /**
- @method _normalizeRelationshipDataHelper
- @param {Object} relationshipDataHash
- @return {Object}
- @private
- */
_normalizeRelationshipDataHelper: function (relationshipDataHash) {
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
var modelName = this.modelNameFromPayloadType(relationshipDataHash.type);
var deprecatedModelNameLookup = this.modelNameFromPayloadKey(relationshipDataHash.type);
if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) {
@@ -16595,23 +15211,16 @@
relationshipDataHash.type = this.modelNameFromPayloadKey(relationshipDataHash.type);
}
return relationshipDataHash;
},
-
- /**
- @method _normalizeResourceHelper
- @param {Object} resourceHash
- @return {Object}
- @private
- */
_normalizeResourceHelper: function (resourceHash) {
- var modelName = undefined,
- usedLookup = undefined;
+ var modelName = void 0,
+ usedLookup = void 0;
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
modelName = this.modelNameFromPayloadType(resourceHash.type);
var deprecatedModelNameLookup = this.modelNameFromPayloadKey(resourceHash.type);
usedLookup = 'modelNameFromPayloadType';
@@ -16630,53 +15239,32 @@
}
var modelClass = this.store._modelFor(modelName);
var serializer = this.store.serializerFor(modelName);
- var _serializer$normalize = serializer.normalize(modelClass, resourceHash);
+ var _serializer$normalize = serializer.normalize(modelClass, resourceHash),
+ data = _serializer$normalize.data;
- var data = _serializer$normalize.data;
-
return data;
},
-
- /**
- @method pushPayload
- @param {DS.Store} store
- @param {Object} payload
- */
pushPayload: function (store, payload) {
var normalizedPayload = this._normalizeDocumentHelper(payload);
- if ((0, _emberDataPrivateFeatures.default)('ds-pushpayload-return')) {
+ if ((0, _features.default)('ds-pushpayload-return')) {
return store.push(normalizedPayload);
} else {
store.push(normalizedPayload);
}
},
-
- /**
- @method _normalizeResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @param {Boolean} isSingle
- @return {Object} JSON-API Document
- @private
- */
_normalizeResponse: function (store, primaryModelClass, payload, id, requestType, isSingle) {
var normalizedPayload = this._normalizeDocumentHelper(payload);
return normalizedPayload;
},
-
normalizeQueryRecordResponse: function () {
var normalized = this._super.apply(this, arguments);
return normalized;
},
-
extractAttributes: function (modelClass, resourceHash) {
var _this = this;
var attributes = {};
@@ -16689,11 +15277,10 @@
});
}
return attributes;
},
-
extractRelationship: function (relationshipHash) {
if (_ember.default.typeOf(relationshipHash.data) === 'object') {
relationshipHash.data = this._normalizeRelationshipDataHelper(relationshipHash.data);
}
@@ -16709,11 +15296,10 @@
relationshipHash.data = ret;
}
return relationshipHash;
},
-
extractRelationships: function (modelClass, resourceHash) {
var _this2 = this;
var relationships = {};
@@ -16728,20 +15314,12 @@
});
}
return relationships;
},
-
- /**
- @method _extractType
- @param {DS.Model} modelClass
- @param {Object} resourceHash
- @return {String}
- @private
- */
_extractType: function (modelClass, resourceHash) {
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
var modelName = this.modelNameFromPayloadType(resourceHash.type);
var deprecatedModelNameLookup = this.modelNameFromPayloadKey(resourceHash.type);
if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) {
@@ -16751,38 +15329,16 @@
return modelName;
} else {
return this.modelNameFromPayloadKey(resourceHash.type);
}
},
-
- /**
- Dasherizes and singularizes the model name in the payload to match
- the format Ember Data uses internally for the model name.
- For example the key `posts` would be converted to `post` and the
- key `studentAssesments` would be converted to `student-assesment`.
- @method modelNameFromPayloadKey
- @param {String} key
- @return {String} the model's modelName
- */
- // TODO @deprecated Use modelNameFromPayloadType instead
modelNameFromPayloadKey: function (key) {
- return (0, _emberInflector.singularize)((0, _emberDataPrivateSystemNormalizeModelName.default)(key));
+ return (0, _emberInflector.singularize)((0, _normalizeModelName.default)(key));
},
-
- /**
- Converts the model name to a pluralized version of the model name.
- For example `post` would be converted to `posts` and
- `student-assesment` would be converted to `student-assesments`.
- @method payloadKeyFromModelName
- @param {String} modelName
- @return {String}
- */
- // TODO @deprecated Use payloadTypeFromModelName instead
payloadKeyFromModelName: function (modelName) {
return (0, _emberInflector.pluralize)(modelName);
},
-
normalize: function (modelClass, resourceHash) {
if (resourceHash.attributes) {
this.normalizeUsingDeclaredMapping(modelClass, resourceHash.attributes);
}
@@ -16799,67 +15355,21 @@
this.applyTransforms(modelClass, data.attributes);
return { data: data };
},
-
- /**
- `keyForAttribute` can be used to define rules for how to convert an
- attribute name in your model to a key in your JSON.
- By default `JSONAPISerializer` follows the format used on the examples of
- http://jsonapi.org/format and uses dashes as the word separator in the JSON
- attribute keys.
- This behaviour can be easily customized by extending this method.
- Example
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.JSONAPISerializer.extend({
- keyForAttribute(attr, method) {
- return Ember.String.dasherize(attr).toUpperCase();
- }
- });
- ```
- @method keyForAttribute
- @param {String} key
- @param {String} method
- @return {String} normalized key
- */
keyForAttribute: function (key, method) {
return dasherize(key);
},
-
- /**
- `keyForRelationship` can be used to define a custom key when
- serializing and deserializing relationship properties.
- By default `JSONAPISerializer` follows the format used on the examples of
- http://jsonapi.org/format and uses dashes as word separators in
- relationship properties.
- This behaviour can be easily customized by extending this method.
- Example
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONAPISerializer.extend({
- keyForRelationship(key, relationship, method) {
- return Ember.String.underscore(key);
- }
- });
- ```
- @method keyForRelationship
- @param {String} key
- @param {String} typeClass
- @param {String} method
- @return {String} normalized key
- */
keyForRelationship: function (key, typeClass, method) {
return dasherize(key);
},
-
serialize: function (snapshot, options) {
var data = this._super.apply(this, arguments);
- var payloadType = undefined;
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ var payloadType = void 0;
+ if ((0, _features.default)("ds-payload-type-hooks")) {
payloadType = this.payloadTypeFromModelName(snapshot.modelName);
var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(snapshot.modelName);
if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) {
@@ -16870,11 +15380,10 @@
}
data.type = payloadType;
return { data: data };
},
-
serializeAttribute: function (snapshot, json, key, attribute) {
var type = attribute.type;
if (this._canSerialize(key)) {
json.attributes = json.attributes || {};
@@ -16892,11 +15401,10 @@
}
json.attributes[payloadKey] = value;
}
},
-
serializeBelongsTo: function (snapshot, json, relationship) {
var key = relationship.key;
if (this._canSerialize(key)) {
var belongsTo = snapshot.belongsTo(key);
@@ -16909,13 +15417,13 @@
payloadKey = this.keyForRelationship(key, 'belongsTo', 'serialize');
}
var data = null;
if (belongsTo) {
- var payloadType = undefined;
+ var payloadType = void 0;
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
payloadType = this.payloadTypeFromModelName(belongsTo.modelName);
var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(belongsTo.modelName);
if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) {
@@ -16933,11 +15441,10 @@
json.relationships[payloadKey] = { data: data };
}
}
},
-
serializeHasMany: function (snapshot, json, relationship) {
var key = relationship.key;
var shouldSerializeHasMany = '_shouldSerializeHasMany';
if (true) {
shouldSerializeHasMany = 'shouldSerializeHasMany';
@@ -16957,13 +15464,13 @@
var data = new Array(hasMany.length);
for (var i = 0; i < hasMany.length; i++) {
var item = hasMany[i];
- var payloadType = undefined;
+ var payloadType = void 0;
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
payloadType = this.payloadTypeFromModelName(item.modelName);
var deprecatedPayloadTypeLookup = this.payloadKeyFromModelName(item.modelName);
if (payloadType !== deprecatedPayloadTypeLookup && this._hasCustomPayloadKeyFromModelName()) {
@@ -16983,112 +15490,47 @@
}
}
}
});
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
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
- `post` model should be used:
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.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));
+ return (0, _emberInflector.singularize)((0, _normalizeModelName.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 DS from 'ember-data';
- 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
-*/
-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); } }
+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, _debug, _serializer, _coerceId, _normalizeModelName, _utils, _features, _errors) {
+ 'use strict';
+ exports.__esModule = true;
+
+ 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;
var assign = _ember.default.assign || _ember.default.merge;
/**
@@ -17155,11 +15597,11 @@
@class JSONSerializer
@namespace DS
@extends DS.Serializer
*/
- var JSONSerializer = _emberDataSerializer.default.extend({
+ var JSONSerializer = _serializer.default.extend({
/**
The `primaryKey` is used when serializing and deserializing
data. Ember Data always uses the `id` property to store the id of
the record. The external source may not always follow this
@@ -17228,22 +15670,10 @@
@property attrs
@type {Object}
*/
mergedProperties: ['attrs'],
- /**
- Given a subclass of `DS.Model` and a JSON object this method will
- iterate through each attribute of the `DS.Model` and invoke the
- `DS.Transform#deserialize` method on the matching property of the
- JSON object. This method is typically called after the
- serializer's `normalize` method.
- @method applyTransforms
- @private
- @param {DS.Model} typeClass
- @param {Object} data The data to transform
- @return {Object} data The transformed data object
- */
applyTransforms: function (typeClass, data) {
var _this = this;
var attributes = get(typeClass, 'attributes');
@@ -17257,39 +15687,10 @@
data[key] = transform.deserialize(data[key], transformMeta.options);
});
return data;
},
-
- /**
- The `normalizeResponse` method is used to normalize a payload from the
- server to a JSON-API Document.
- http://jsonapi.org/format/#document-structure
- This method delegates to a more specific normalize method based on
- the `requestType`.
- To override this method with a custom one, make sure to call
- `return this._super(store, primaryModelClass, payload, id, requestType)` with your
- pre-processed data.
- Here's an example of using `normalizeResponse` manually:
- ```javascript
- socket.on('message', function(message) {
- var data = message.data;
- var modelClass = store.modelFor(data.modelName);
- var serializer = store.serializerFor(data.modelName);
- var normalized = serializer.normalizeSingleResponse(store, modelClass, data, data.id);
- store.push(normalized);
- });
- ```
- @since 1.13.0
- @method normalizeResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeResponse: function (store, primaryModelClass, payload, id, requestType) {
switch (requestType) {
case 'findRecord':
return this.normalizeFindRecordResponse.apply(this, arguments);
case 'queryRecord':
@@ -17310,204 +15711,49 @@
return this.normalizeDeleteRecordResponse.apply(this, arguments);
case 'updateRecord':
return this.normalizeUpdateRecordResponse.apply(this, arguments);
}
},
-
- /**
- @since 1.13.0
- @method normalizeFindRecordResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeFindRecordResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSingleResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeQueryRecordResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeQueryRecordResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSingleResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeFindAllResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeFindAllResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeArrayResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeFindBelongsToResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeFindBelongsToResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSingleResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeFindHasManyResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeFindHasManyResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeArrayResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeFindManyResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeFindManyResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeArrayResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeQueryResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeQueryResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeArrayResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeCreateRecordResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeCreateRecordResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSaveResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeDeleteRecordResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeDeleteRecordResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSaveResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeUpdateRecordResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeUpdateRecordResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSaveResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeSaveResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeSaveResponse: function (store, primaryModelClass, payload, id, requestType) {
return this.normalizeSingleResponse.apply(this, arguments);
},
-
- /**
- @since 1.13.0
- @method normalizeSingleResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeSingleResponse: function (store, primaryModelClass, payload, id, requestType) {
return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, true);
},
-
- /**
- @since 1.13.0
- @method normalizeArrayResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @return {Object} JSON-API Document
- */
normalizeArrayResponse: function (store, primaryModelClass, payload, id, requestType) {
return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, false);
},
-
- /**
- @method _normalizeResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @param {Boolean} isSingle
- @return {Object} JSON-API Document
- @private
- */
_normalizeResponse: function (store, primaryModelClass, payload, id, requestType, isSingle) {
var documentHash = {
data: null,
included: []
};
@@ -17516,73 +15762,40 @@
if (meta) {
documentHash.meta = meta;
}
if (isSingle) {
- var _normalize = this.normalize(primaryModelClass, payload);
+ var _normalize = this.normalize(primaryModelClass, payload),
+ data = _normalize.data,
+ included = _normalize.included;
- var data = _normalize.data;
- var included = _normalize.included;
-
documentHash.data = data;
if (included) {
documentHash.included = included;
}
} else {
var ret = new Array(payload.length);
for (var i = 0, l = payload.length; i < l; i++) {
var item = payload[i];
- var _normalize2 = this.normalize(primaryModelClass, item);
+ var _normalize2 = this.normalize(primaryModelClass, item),
+ _data = _normalize2.data,
+ _included = _normalize2.included;
- var data = _normalize2.data;
- var included = _normalize2.included;
+ if (_included) {
+ var _documentHash$include;
- if (included) {
- var _documentHash$included;
-
- (_documentHash$included = documentHash.included).push.apply(_documentHash$included, _toConsumableArray(included));
+ (_documentHash$include = documentHash.included).push.apply(_documentHash$include, _toConsumableArray(_included));
}
- ret[i] = data;
+ ret[i] = _data;
}
documentHash.data = ret;
}
return documentHash;
},
-
- /**
- Normalizes a part of the JSON payload returned by
- the server. You should override this method, munge the hash
- and call super if you have generic normalization to do.
- It takes the type of the record that is being normalized
- (as a DS.Model class), the property where the hash was
- originally found, and the hash to normalize.
- You can use this method, for example, to normalize underscored keys to camelized
- or other general-purpose normalizations.
- Example
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- normalize(typeClass, hash) {
- var fields = Ember.get(typeClass, 'fields');
- fields.forEach(function(field) {
- var payloadField = Ember.String.underscore(field);
- if (field === payloadField) { return; }
- hash[field] = hash[payloadField];
- delete hash[payloadField];
- });
- return this._super.apply(this, arguments);
- }
- });
- ```
- @method normalize
- @param {DS.Model} typeClass
- @param {Object} hash
- @return {Object}
- */
normalize: function (modelClass, resourceHash) {
var data = null;
if (resourceHash) {
this.normalizeUsingDeclaredMapping(modelClass, resourceHash);
@@ -17600,36 +15813,19 @@
this.applyTransforms(modelClass, data.attributes);
}
return { data: data };
},
-
- /**
- Returns the resource's ID.
- @method extractId
- @param {Object} modelClass
- @param {Object} resourceHash
- @return {String}
- */
extractId: function (modelClass, resourceHash) {
var primaryKey = get(this, 'primaryKey');
var id = resourceHash[primaryKey];
- return (0, _emberDataPrivateSystemCoerceId.default)(id);
+ return (0, _coerceId.default)(id);
},
-
- /**
- Returns the resource's attributes formatted as a JSON-API "attributes object".
- http://jsonapi.org/format/#document-resource-object-attributes
- @method extractAttributes
- @param {Object} modelClass
- @param {Object} resourceHash
- @return {Object}
- */
extractAttributes: function (modelClass, resourceHash) {
var _this2 = this;
- var attributeKey = undefined;
+ var attributeKey = void 0;
var attributes = {};
modelClass.eachAttribute(function (key) {
attributeKey = _this2.keyForAttribute(key, 'deserialize');
if (resourceHash[attributeKey] !== undefined) {
@@ -17637,19 +15833,10 @@
}
});
return attributes;
},
-
- /**
- Returns a relationship formatted as a JSON-API "relationship object".
- http://jsonapi.org/format/#document-resource-object-relationships
- @method extractRelationship
- @param {Object} relationshipModelName
- @param {Object} relationshipHash
- @return {Object}
- */
extractRelationship: function (relationshipModelName, relationshipHash) {
if (_ember.default.isNone(relationshipHash)) {
return null;
}
/*
@@ -17657,17 +15844,17 @@
is polymorphic. It could however also be embedded resources that the
EmbeddedRecordsMixin has be able to process.
*/
if (_ember.default.typeOf(relationshipHash) === 'object') {
if (relationshipHash.id) {
- relationshipHash.id = (0, _emberDataPrivateSystemCoerceId.default)(relationshipHash.id);
+ relationshipHash.id = (0, _coerceId.default)(relationshipHash.id);
}
var modelClass = this.store.modelFor(relationshipModelName);
- if (relationshipHash.type && !(0, _emberDataPrivateUtils.modelHasAttributeOrRelationshipNamedType)(modelClass)) {
+ if (relationshipHash.type && !(0, _utils.modelHasAttributeOrRelationshipNamedType)(modelClass)) {
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
var modelName = this.modelNameFromPayloadType(relationshipHash.type);
var deprecatedModelNameLookup = this.modelNameFromPayloadKey(relationshipHash.type);
if (modelName !== deprecatedModelNameLookup && this._hasCustomModelNameFromPayloadKey()) {
@@ -17679,41 +15866,15 @@
relationshipHash.type = this.modelNameFromPayloadKey(relationshipHash.type);
}
}
return relationshipHash;
}
- return { id: (0, _emberDataPrivateSystemCoerceId.default)(relationshipHash), type: relationshipModelName };
+ return { id: (0, _coerceId.default)(relationshipHash), type: relationshipModelName };
},
-
- /**
- Returns a polymorphic relationship formatted as a JSON-API "relationship object".
- http://jsonapi.org/format/#document-resource-object-relationships
- `relationshipOptions` is a hash which contains more information about the
- polymorphic relationship which should be extracted:
- - `resourceHash` complete hash of the resource the relationship should be
- extracted from
- - `relationshipKey` key under which the value for the relationship is
- extracted from the resourceHash
- - `relationshipMeta` meta information about the relationship
- @method extractPolymorphicRelationship
- @param {Object} relationshipModelName
- @param {Object} relationshipHash
- @param {Object} relationshipOptions
- @return {Object}
- */
extractPolymorphicRelationship: function (relationshipModelName, relationshipHash, relationshipOptions) {
return this.extractRelationship(relationshipModelName, relationshipHash);
},
-
- /**
- Returns the resource's relationships formatted as a JSON-API "relationships object".
- http://jsonapi.org/format/#document-resource-object-relationships
- @method extractRelationships
- @param {Object} modelClass
- @param {Object} resourceHash
- @return {Object}
- */
extractRelationships: function (modelClass, resourceHash) {
var _this3 = this;
var relationships = {};
@@ -17757,29 +15918,17 @@
}
});
return relationships;
},
-
- /**
- @method modelNameFromPayloadKey
- @param {String} key
- @return {String} the model's modelName
- */
- // TODO @deprecated Use modelNameFromPayloadType instead
modelNameFromPayloadKey: function (key) {
- return (0, _emberDataPrivateSystemNormalizeModelName.default)(key);
+ return (0, _normalizeModelName.default)(key);
},
-
- /**
- @method normalizeRelationships
- @private
- */
normalizeRelationships: function (typeClass, hash) {
var _this4 = this;
- var payloadKey = undefined;
+ var payloadKey = void 0;
if (this.keyForRelationship) {
typeClass.eachRelationship(function (key, relationship) {
payloadKey = _this4.keyForRelationship(key, relationship.kind, 'deserialize');
if (key === payloadKey) {
@@ -17792,19 +15941,14 @@
hash[key] = hash[payloadKey];
delete hash[payloadKey];
});
}
},
-
- /**
- @method normalizeUsingDeclaredMapping
- @private
- */
normalizeUsingDeclaredMapping: function (modelClass, hash) {
var attrs = get(this, 'attrs');
- var normalizedKey = undefined;
- var payloadKey = undefined;
+ var normalizedKey = void 0;
+ var payloadKey = void 0;
if (attrs) {
for (var key in attrs) {
normalizedKey = payloadKey = this._getMappedKey(key, modelClass);
@@ -17825,23 +15969,14 @@
delete hash[payloadKey];
}
}
}
},
-
- /**
- Looks up the property key that was set by the custom `attr` mapping
- passed to the serializer.
- @method _getMappedKey
- @private
- @param {String} key
- @return {String} key
- */
_getMappedKey: function (key, modelClass) {
var attrs = get(this, 'attrs');
- var mappedKey = undefined;
+ var mappedKey = void 0;
if (attrs && attrs[key]) {
mappedKey = attrs[key];
//We need to account for both the { title: 'post_title' } and
//{ title: { key: 'post_title' }} forms
if (mappedKey.key) {
@@ -17852,193 +15987,39 @@
}
}
return key;
},
-
- /**
- Check attrs.key.serialize property to inform if the `key`
- can be serialized
- @method _canSerialize
- @private
- @param {String} key
- @return {boolean} true if the key can be serialized
- */
_canSerialize: function (key) {
var attrs = get(this, 'attrs');
return !attrs || !attrs[key] || attrs[key].serialize !== false;
},
-
- /**
- When attrs.key.serialize is set to true then
- it takes priority over the other checks and the related
- attribute/relationship will be serialized
- @method _mustSerialize
- @private
- @param {String} key
- @return {boolean} true if the key must be serialized
- */
_mustSerialize: function (key) {
var attrs = get(this, 'attrs');
return attrs && attrs[key] && attrs[key].serialize === true;
},
-
- /**
- Check if the given hasMany relationship should be serialized
- @method shouldSerializeHasMany
- @param {DS.Snapshot} snapshot
- @param {String} key
- @param {String} relationshipType
- @return {boolean} true if the hasMany relationship should be serialized
- */
-
shouldSerializeHasMany: function (snapshot, key, relationship) {
if (this._shouldSerializeHasMany !== JSONSerializer.prototype._shouldSerializeHasMany) {}
return this._shouldSerializeHasMany(snapshot, key, relationship);
},
-
- /**
- Check if the given hasMany relationship should be serialized
- @method _shouldSerializeHasMany
- @private
- @param {DS.Snapshot} snapshot
- @param {String} key
- @param {String} relationshipType
- @return {boolean} true if the hasMany relationship should be serialized
- */
_shouldSerializeHasMany: function (snapshot, key, relationship) {
var relationshipType = snapshot.type.determineRelationshipType(relationship, this.store);
if (this._mustSerialize(key)) {
return true;
}
return this._canSerialize(key) && (relationshipType === 'manyToNone' || relationshipType === 'manyToMany');
},
-
- // SERIALIZE
- /**
- Called when a record is saved in order to convert the
- record into JSON.
- By default, it creates a JSON object with a key for
- each attribute and belongsTo relationship.
- For example, consider this model:
- ```app/models/comment.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- title: DS.attr(),
- body: DS.attr(),
- author: DS.belongsTo('user')
- });
- ```
- The default serialization would create a JSON object like:
- ```javascript
- {
- "title": "Rails is unagi",
- "body": "Rails? Omakase? O_O",
- "author": 12
- }
- ```
- By default, attributes are passed through as-is, unless
- you specified an attribute type (`DS.attr('date')`). If
- you specify a transform, the JavaScript value will be
- serialized when inserted into the JSON hash.
- By default, belongs-to relationships are converted into
- IDs when inserted into the JSON hash.
- ## IDs
- `serialize` takes an options hash with a single option:
- `includeId`. If this option is `true`, `serialize` will,
- by default include the ID in the JSON object it builds.
- The adapter passes in `includeId: true` when serializing
- a record for `createRecord`, but not for `updateRecord`.
- ## Customization
- Your server may expect a different JSON format than the
- built-in serialization format.
- In that case, you can implement `serialize` yourself and
- return a JSON hash of your choosing.
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serialize(snapshot, options) {
- var json = {
- POST_TTL: snapshot.attr('title'),
- POST_BDY: snapshot.attr('body'),
- POST_CMS: snapshot.hasMany('comments', { ids: true })
- };
- if (options.includeId) {
- json.POST_ID_ = snapshot.id;
- }
- return json;
- }
- });
- ```
- ## Customizing an App-Wide Serializer
- If you want to define a serializer for your entire
- application, you'll probably want to use `eachAttribute`
- and `eachRelationship` on the record.
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serialize(snapshot, options) {
- var json = {};
- snapshot.eachAttribute(function(name) {
- json[serverAttributeName(name)] = snapshot.attr(name);
- });
- snapshot.eachRelationship(function(name, relationship) {
- if (relationship.kind === 'hasMany') {
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
- }
- });
- if (options.includeId) {
- json.ID_ = snapshot.id;
- }
- return json;
- }
- });
- function serverAttributeName(attribute) {
- return attribute.underscore().toUpperCase();
- }
- function serverHasManyName(name) {
- return serverAttributeName(name.singularize()) + "_IDS";
- }
- ```
- This serializer will generate JSON that looks like this:
- ```javascript
- {
- "TITLE": "Rails is omakase",
- "BODY": "Yep. Omakase.",
- "COMMENT_IDS": [ 1, 2, 3 ]
- }
- ```
- ## Tweaking the Default JSON
- If you just want to do some small tweaks on the default JSON,
- you can call super first and make the tweaks on the returned
- JSON.
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serialize(snapshot, options) {
- var json = this._super(...arguments);
- json.subject = json.title;
- delete json.title;
- return json;
- }
- });
- ```
- @method serialize
- @param {DS.Snapshot} snapshot
- @param {Object} options
- @return {Object} json
- */
serialize: function (snapshot, options) {
var _this5 = this;
var json = {};
if (options && options.includeId) {
- if ((0, _emberDataPrivateFeatures.default)('ds-serialize-id')) {
+ if ((0, _features.default)('ds-serialize-id')) {
this.serializeId(snapshot, json, get(this, 'primaryKey'));
} else {
var id = snapshot.id;
if (id) {
json[get(this, 'primaryKey')] = id;
@@ -18058,59 +16039,13 @@
}
});
return json;
},
-
- /**
- You can use this method to customize how a serialized record is added to the complete
- JSON hash to be sent to the server. By default the JSON Serializer does not namespace
- the payload and just sends the raw serialized JSON object.
- If your server expects namespaced keys, you should consider using the RESTSerializer.
- Otherwise you can override this method to customize how the record is added to the hash.
- The hash property should be modified by reference.
- For example, your server may expect underscored root objects.
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- serializeIntoHash(data, type, snapshot, options) {
- var root = Ember.String.decamelize(type.modelName);
- data[root] = this.serialize(snapshot, options);
- }
- });
- ```
- @method serializeIntoHash
- @param {Object} hash
- @param {DS.Model} typeClass
- @param {DS.Snapshot} snapshot
- @param {Object} options
- */
serializeIntoHash: function (hash, typeClass, snapshot, options) {
assign(hash, this.serialize(snapshot, options));
},
-
- /**
- `serializeAttribute` can be used to customize how `DS.attr`
- properties are serialized
- For example if you wanted to ensure all your attributes were always
- serialized as properties on an `attributes` object you could
- write:
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serializeAttribute(snapshot, json, key, attributes) {
- json.attributes = json.attributes || {};
- this._super(snapshot, json.attributes, key, attributes);
- }
- });
- ```
- @method serializeAttribute
- @param {DS.Snapshot} snapshot
- @param {Object} json
- @param {String} key
- @param {Object} attribute
- */
serializeAttribute: function (snapshot, json, key, attribute) {
if (this._canSerialize(key)) {
var type = attribute.type;
var value = snapshot.attr(key);
@@ -18128,31 +16063,10 @@
}
json[payloadKey] = value;
}
},
-
- /**
- `serializeBelongsTo` can be used to customize how `DS.belongsTo`
- properties are serialized.
- Example
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serializeBelongsTo(snapshot, json, relationship) {
- var key = relationship.key;
- var belongsTo = snapshot.belongsTo(key);
- key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
- json[key] = Ember.isNone(belongsTo) ? belongsTo : belongsTo.record.toJSON();
- }
- });
- ```
- @method serializeBelongsTo
- @param {DS.Snapshot} snapshot
- @param {Object} json
- @param {Object} relationship
- */
serializeBelongsTo: function (snapshot, json, relationship) {
var key = relationship.key;
if (this._canSerialize(key)) {
var belongsToId = snapshot.belongsTo(key, { id: true });
@@ -18174,33 +16088,10 @@
if (relationship.options.polymorphic) {
this.serializePolymorphicType(snapshot, json, relationship);
}
}
},
-
- /**
- `serializeHasMany` can be used to customize how `DS.hasMany`
- properties are serialized.
- Example
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serializeHasMany(snapshot, json, relationship) {
- var key = relationship.key;
- if (key === 'comments') {
- return;
- } else {
- this._super(...arguments);
- }
- }
- });
- ```
- @method serializeHasMany
- @param {DS.Snapshot} snapshot
- @param {Object} json
- @param {Object} relationship
- */
serializeHasMany: function (snapshot, json, relationship) {
var key = relationship.key;
var shouldSerializeHasMany = '_shouldSerializeHasMany';
if (true) {
shouldSerializeHasMany = 'shouldSerializeHasMany';
@@ -18219,147 +16110,23 @@
json[payloadKey] = hasMany;
// TODO support for polymorphic manyToNone and manyToMany relationships
}
}
},
-
- /**
- You can use this method to customize how polymorphic objects are
- serialized. Objects are considered to be polymorphic if
- `{ polymorphic: true }` is pass as the second argument to the
- `DS.belongsTo` function.
- Example
- ```app/serializers/comment.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serializePolymorphicType(snapshot, json, relationship) {
- var key = relationship.key;
- var belongsTo = snapshot.belongsTo(key);
- key = this.keyForAttribute ? this.keyForAttribute(key, 'serialize') : key;
- if (Ember.isNone(belongsTo)) {
- json[key + '_type'] = null;
- } else {
- json[key + '_type'] = belongsTo.modelName;
- }
- }
- });
- ```
- @method serializePolymorphicType
- @param {DS.Snapshot} snapshot
- @param {Object} json
- @param {Object} relationship
- */
serializePolymorphicType: function () {},
-
- /**
- `extractMeta` is used to deserialize any meta information in the
- adapter payload. By default Ember Data expects meta information to
- be located on the `meta` property of the payload object.
- Example
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- extractMeta(store, typeClass, payload) {
- if (payload && payload.hasOwnProperty('_pagination')) {
- let meta = payload._pagination;
- delete payload._pagination;
- return meta;
- }
- }
- });
- ```
- @method extractMeta
- @param {DS.Store} store
- @param {DS.Model} modelClass
- @param {Object} payload
- */
extractMeta: function (store, modelClass, payload) {
if (payload && payload['meta'] !== undefined) {
var meta = payload.meta;
delete payload.meta;
return meta;
}
},
-
- /**
- `extractErrors` is used to extract model errors when a call
- to `DS.Model#save` fails with an `InvalidError`. By default
- Ember Data expects error information to be located on the `errors`
- property of the payload object.
- This serializer expects this `errors` object to be an Array similar
- to the following, compliant with the JSON-API specification:
- ```js
- {
- "errors": [
- {
- "detail": "This username is already taken!",
- "source": {
- "pointer": "data/attributes/username"
- }
- }, {
- "detail": "Doesn't look like a valid email.",
- "source": {
- "pointer": "data/attributes/email"
- }
- }
- ]
- }
- ```
- The key `detail` provides a textual description of the problem.
- Alternatively, the key `title` can be used for the same purpose.
- The nested keys `source.pointer` detail which specific element
- of the request data was invalid.
- Note that JSON-API also allows for object-level errors to be placed
- in an object with pointer `data`, signifying that the problem
- cannot be traced to a specific attribute:
- ```javascript
- {
- "errors": [
- {
- "detail": "Some generic non property error message",
- "source": {
- "pointer": "data"
- }
- }
- ]
- }
- ```
- When turn into a `DS.Errors` object, you can read these errors
- through the property `base`:
- ```handlebars
- {{#each model.errors.base as |error|}}
- <div class="error">
- {{error.message}}
- </div>
- {{/each}}
- ```
- Example of alternative implementation, overriding the default
- behavior to deal with a different format of errors:
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- extractErrors(store, typeClass, payload, id) {
- if (payload && typeof payload === 'object' && payload._problems) {
- payload = payload._problems;
- this.normalizeErrors(typeClass, payload);
- }
- return payload;
- }
- });
- ```
- @method extractErrors
- @param {DS.Store} store
- @param {DS.Model} typeClass
- @param {Object} payload
- @param {(String|Number)} id
- @return {Object} json The deserialized errors
- */
extractErrors: function (store, typeClass, payload, id) {
var _this6 = this;
if (payload && typeof payload === 'object' && payload.errors) {
- payload = (0, _emberDataAdaptersErrors.errorsArrayToHash)(payload.errors);
+ payload = (0, _errors.errorsArrayToHash)(payload.errors);
this.normalizeUsingDeclaredMapping(typeClass, payload);
typeClass.eachAttribute(function (name) {
var key = _this6.keyForAttribute(name, 'deserialize');
@@ -18378,127 +16145,41 @@
});
}
return payload;
},
-
- /**
- `keyForAttribute` can be used to define rules for how to convert an
- attribute name in your model to a key in your JSON.
- Example
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- keyForAttribute(attr, method) {
- return Ember.String.underscore(attr).toUpperCase();
- }
- });
- ```
- @method keyForAttribute
- @param {String} key
- @param {String} method
- @return {String} normalized key
- */
keyForAttribute: function (key, method) {
return key;
},
-
- /**
- `keyForRelationship` can be used to define a custom key when
- serializing and deserializing relationship properties. By default
- `JSONSerializer` does not provide an implementation of this method.
- Example
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- keyForRelationship(key, relationship, method) {
- return 'rel_' + Ember.String.underscore(key);
- }
- });
- ```
- @method keyForRelationship
- @param {String} key
- @param {String} typeClass
- @param {String} method
- @return {String} normalized key
- */
keyForRelationship: function (key, typeClass, method) {
return key;
},
-
- /**
- `keyForLink` can be used to define a custom key when deserializing link
- properties.
- @method keyForLink
- @param {String} key
- @param {String} kind `belongsTo` or `hasMany`
- @return {String} normalized key
- */
keyForLink: function (key, kind) {
return key;
},
-
- // HELPERS
-
- /**
- @method transformFor
- @private
- @param {String} attributeType
- @param {Boolean} skipAssertion
- @return {DS.Transform} transform
- */
transformFor: function (attributeType, skipAssertion) {
- var transform = (0, _emberDataPrivateUtils.getOwner)(this).lookup('transform:' + attributeType);
+ var transform = (0, _utils.getOwner)(this).lookup('transform:' + attributeType);
return transform;
}
});
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
JSONSerializer.reopen({
-
- /**
- @method modelNameFromPayloadType
- @public
- @param {String} type
- @return {String} the model's modelName
- */
modelNameFromPayloadType: function (type) {
- return (0, _emberDataPrivateSystemNormalizeModelName.default)(type);
+ return (0, _normalizeModelName.default)(type);
},
-
_hasCustomModelNameFromPayloadKey: function () {
return this.modelNameFromPayloadKey !== JSONSerializer.prototype.modelNameFromPayloadKey;
}
-
});
}
- if ((0, _emberDataPrivateFeatures.default)("ds-serialize-id")) {
+ if ((0, _features.default)("ds-serialize-id")) {
JSONSerializer.reopen({
-
- /**
- serializeId can be used to customize how id is serialized
- For example, your server may expect integer datatype of id
- By default the snapshot's id (String) is set on the json hash via json[primaryKey] = snapshot.id.
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.JSONSerializer.extend({
- serializeId(snapshot, json, primaryKey) {
- var id = snapshot.id;
- json[primaryKey] = parseInt(id, 10);
- }
- });
- ```
- @method serializeId
- @public
- @param {DS.Snapshot} snapshot
- @param {Object} json
- @param {String} primaryKey
- */
serializeId: function (snapshot, json, primaryKey) {
var id = snapshot.id;
if (id) {
json[primaryKey] = id;
@@ -18507,13 +16188,27 @@
});
}
exports.default = JSONSerializer;
});
-define("ember-data/serializers/rest", ["exports", "ember", "ember-inflector", "ember-data/-private/debug", "ember-data/serializers/json", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/coerce-id", "ember-data/-private/utils", "ember-data/-private/features"], function (exports, _ember, _emberInflector, _emberDataPrivateDebug, _emberDataSerializersJson, _emberDataPrivateSystemNormalizeModelName, _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); } }
+define("ember-data/serializers/rest", ["exports", "ember", "ember-inflector", "ember-data/-private/debug", "ember-data/serializers/json", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/coerce-id", "ember-data/-private/utils", "ember-data/-private/features"], function (exports, _ember, _emberInflector, _debug, _json, _normalizeModelName, _coerceId, _utils, _features) {
+ "use strict";
+ exports.__esModule = true;
+
+ 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;
/**
Normally, applications will use the `RESTSerializer` by implementing
the `normalize` method.
@@ -18554,110 +16249,22 @@
@class RESTSerializer
@namespace DS
@extends DS.JSONSerializer
*/
- var RESTSerializer = _emberDataSerializersJson.default.extend({
-
- /**
- `keyForPolymorphicType` can be used to define a custom key when
- serializing and deserializing a polymorphic type. By default, the
- returned key is `${key}Type`.
- Example
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- keyForPolymorphicType(key, relationship) {
- var relationshipKey = this.keyForRelationship(key);
- return 'type-' + relationshipKey;
- }
- });
- ```
- @method keyForPolymorphicType
- @param {String} key
- @param {String} typeClass
- @param {String} method
- @return {String} normalized key
- */
+ var RESTSerializer = _json.default.extend({
keyForPolymorphicType: function (key, typeClass, method) {
var relationshipKey = this.keyForRelationship(key);
return relationshipKey + "Type";
},
-
- /**
- Normalizes a part of the JSON payload returned by
- the server. You should override this method, munge the hash
- and call super if you have generic normalization to do.
- It takes the type of the record that is being normalized
- (as a DS.Model class), the property where the hash was
- originally found, and the hash to normalize.
- For example, if you have a payload that looks like this:
- ```js
- {
- "post": {
- "id": 1,
- "title": "Rails is omakase",
- "comments": [ 1, 2 ]
- },
- "comments": [{
- "id": 1,
- "body": "FIRST"
- }, {
- "id": 2,
- "body": "Rails is unagi"
- }]
- }
- ```
- The `normalize` method will be called three times:
- * With `App.Post`, `"posts"` and `{ id: 1, title: "Rails is omakase", ... }`
- * With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }`
- * With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }`
- You can use this method, for example, to normalize underscored keys to camelized
- or other general-purpose normalizations. You will only need to implement
- `normalize` and manipulate the payload as desired.
- For example, if the `IDs` under `"comments"` are provided as `_id` instead of
- `id`, you can specify how to normalize just the comments:
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- normalize(model, hash, prop) {
- if (prop === 'comments') {
- hash.id = hash._id;
- delete hash._id;
- }
- return this._super(...arguments);
- }
- });
- ```
- On each call to the `normalize` method, the third parameter (`prop`) is always
- one of the keys that were in the original payload or in the result of another
- normalization as `normalizeResponse`.
- @method normalize
- @param {DS.Model} modelClass
- @param {Object} resourceHash
- @param {String} prop
- @return {Object}
- */
normalize: function (modelClass, resourceHash, prop) {
if (this.normalizeHash && this.normalizeHash[prop]) {
this.normalizeHash[prop](resourceHash);
}
return this._super(modelClass, resourceHash);
},
-
- /**
- Normalizes an array of resource payloads and returns a JSON-API Document
- with primary data and, if any, included data as `{ data, included }`.
- @method _normalizeArray
- @param {DS.Store} store
- @param {String} modelName
- @param {Object} arrayHash
- @param {String} prop
- @return {Object}
- @private
- */
_normalizeArray: function (store, modelName, arrayHash, prop) {
var _this = this;
var documentHash = {
data: [],
@@ -18666,36 +16273,34 @@
var modelClass = store.modelFor(modelName);
var serializer = store.serializerFor(modelName);
_ember.default.makeArray(arrayHash).forEach(function (hash) {
- var _normalizePolymorphicRecord = _this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer);
+ var _normalizePolymorphic = _this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer),
+ data = _normalizePolymorphic.data,
+ included = _normalizePolymorphic.included;
- var data = _normalizePolymorphicRecord.data;
- var included = _normalizePolymorphicRecord.included;
-
documentHash.data.push(data);
if (included) {
- var _documentHash$included;
+ var _documentHash$include;
- (_documentHash$included = documentHash.included).push.apply(_documentHash$included, _toConsumableArray(included));
+ (_documentHash$include = documentHash.included).push.apply(_documentHash$include, _toConsumableArray(included));
}
});
return documentHash;
},
-
_normalizePolymorphicRecord: function (store, hash, prop, primaryModelClass, primarySerializer) {
var serializer = primarySerializer;
var modelClass = primaryModelClass;
- var primaryHasTypeAttribute = (0, _emberDataPrivateUtils.modelHasAttributeOrRelationshipNamedType)(primaryModelClass);
+ var primaryHasTypeAttribute = (0, _utils.modelHasAttributeOrRelationshipNamedType)(primaryModelClass);
if (!primaryHasTypeAttribute && hash.type) {
// Support polymorphic records in async relationships
- var modelName = undefined;
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ var modelName = void 0;
+ if ((0, _features.default)("ds-payload-type-hooks")) {
modelName = this.modelNameFromPayloadType(hash.type);
var deprecatedModelNameLookup = this.modelNameFromPayloadKey(hash.type);
if (modelName !== deprecatedModelNameLookup && !this._hasCustomModelNameFromPayloadType() && this._hasCustomModelNameFromPayloadKey()) {
@@ -18711,22 +16316,10 @@
}
}
return serializer.normalize(modelClass, hash, prop);
},
-
- /*
- @method _normalizeResponse
- @param {DS.Store} store
- @param {DS.Model} primaryModelClass
- @param {Object} payload
- @param {String|Number} id
- @param {String} requestType
- @param {Boolean} isSingle
- @return {Object} JSON-API Document
- @private
- */
_normalizeResponse: function (store, primaryModelClass, payload, id, requestType, isSingle) {
var _this2 = this;
var documentHash = {
data: null,
@@ -18738,11 +16331,11 @@
documentHash.meta = meta;
}
var keys = Object.keys(payload);
- var _loop = function (i, _length) {
+ var _loop = function (i, length) {
var prop = keys[i];
var modelName = prop;
var forcedSecondary = false;
/*
@@ -18787,33 +16380,31 @@
user: { id: 1, title: 'Tom', manager: 3 }
}
```
*/
if (isPrimary && _ember.default.typeOf(value) !== 'array') {
- var _normalizePolymorphicRecord2 = _this2._normalizePolymorphicRecord(store, value, prop, primaryModelClass, _this2);
+ var _normalizePolymorphic2 = _this2._normalizePolymorphicRecord(store, value, prop, primaryModelClass, _this2),
+ _data = _normalizePolymorphic2.data,
+ _included = _normalizePolymorphic2.included;
- var _data = _normalizePolymorphicRecord2.data;
- var _included = _normalizePolymorphicRecord2.included;
-
documentHash.data = _data;
if (_included) {
- var _documentHash$included2;
+ var _documentHash$include2;
- (_documentHash$included2 = documentHash.included).push.apply(_documentHash$included2, _toConsumableArray(_included));
+ (_documentHash$include2 = documentHash.included).push.apply(_documentHash$include2, _toConsumableArray(_included));
}
return "continue";
}
- var _normalizeArray = _this2._normalizeArray(store, typeName, value, prop);
+ var _normalizeArray = _this2._normalizeArray(store, typeName, value, prop),
+ data = _normalizeArray.data,
+ included = _normalizeArray.included;
- var data = _normalizeArray.data;
- var included = _normalizeArray.included;
-
if (included) {
- var _documentHash$included3;
+ var _documentHash$include3;
- (_documentHash$included3 = documentHash.included).push.apply(_documentHash$included3, _toConsumableArray(included));
+ (_documentHash$include3 = documentHash.included).push.apply(_documentHash$include3, _toConsumableArray(included));
}
if (isSingle) {
data.forEach(function (resource) {
@@ -18822,11 +16413,11 @@
It's either:
1. The record with the same ID as the original request
2. If it's a newly created record without an ID, the first record
in the array
*/
- var isUpdatedRecord = isPrimary && (0, _emberDataPrivateSystemCoerceId.default)(resource.id) === id;
+ var isUpdatedRecord = isPrimary && (0, _coerceId.default)(resource.id) === id;
var isFirstCreatedRecord = isPrimary && !id && !documentHash.data;
if (isFirstCreatedRecord || isUpdatedRecord) {
documentHash.data = resource;
} else {
@@ -18836,349 +16427,84 @@
} else {
if (isPrimary) {
documentHash.data = data;
} else {
if (data) {
- var _documentHash$included4;
+ var _documentHash$include4;
- (_documentHash$included4 = documentHash.included).push.apply(_documentHash$included4, _toConsumableArray(data));
+ (_documentHash$include4 = documentHash.included).push.apply(_documentHash$include4, _toConsumableArray(data));
}
}
}
};
- for (var i = 0, _length = keys.length; i < _length; i++) {
- var _ret = _loop(i, _length);
+ for (var i = 0, length = keys.length; i < length; i++) {
+ var _ret = _loop(i, length);
if (_ret === "continue") continue;
}
return documentHash;
},
-
isPrimaryType: function (store, typeName, primaryTypeClass) {
return store.modelFor(typeName) === primaryTypeClass;
},
-
- /**
- This method allows you to push a payload containing top-level
- collections of records organized per type.
- ```js
- {
- "posts": [{
- "id": "1",
- "title": "Rails is omakase",
- "author", "1",
- "comments": [ "1" ]
- }],
- "comments": [{
- "id": "1",
- "body": "FIRST"
- }],
- "users": [{
- "id": "1",
- "name": "@d2h"
- }]
- }
- ```
- It will first normalize the payload, so you can use this to push
- in data streaming in from your server structured the same way
- that fetches and saves are structured.
- @method pushPayload
- @param {DS.Store} store
- @param {Object} payload
- */
pushPayload: function (store, payload) {
var _this3 = this;
var documentHash = {
data: [],
included: []
};
- var _loop2 = function (prop) {
- var modelName = _this3.modelNameFromPayloadKey(prop);
+ var _loop2 = function (_prop) {
+ var modelName = _this3.modelNameFromPayloadKey(_prop);
if (!store.modelFactoryFor(modelName)) {
return "continue";
}
var type = store.modelFor(modelName);
var typeSerializer = store.serializerFor(type.modelName);
- _ember.default.makeArray(payload[prop]).forEach(function (hash) {
- var _typeSerializer$normalize = typeSerializer.normalize(type, hash, prop);
+ _ember.default.makeArray(payload[_prop]).forEach(function (hash) {
+ var _typeSerializer$norma = typeSerializer.normalize(type, hash, _prop),
+ data = _typeSerializer$norma.data,
+ included = _typeSerializer$norma.included;
- var data = _typeSerializer$normalize.data;
- var included = _typeSerializer$normalize.included;
-
documentHash.data.push(data);
if (included) {
- var _documentHash$included5;
+ var _documentHash$include5;
- (_documentHash$included5 = documentHash.included).push.apply(_documentHash$included5, _toConsumableArray(included));
+ (_documentHash$include5 = documentHash.included).push.apply(_documentHash$include5, _toConsumableArray(included));
}
});
};
- for (var prop in payload) {
- var _ret2 = _loop2(prop);
+ for (var _prop in payload) {
+ var _ret2 = _loop2(_prop);
if (_ret2 === "continue") continue;
}
- if ((0, _emberDataPrivateFeatures.default)('ds-pushpayload-return')) {
+ if ((0, _features.default)('ds-pushpayload-return')) {
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
- that part of the payload.
- For example, your server may send a model name that does not correspond with
- the name of the model in your app. Let's take a look at an example model,
- and an example payload:
- ```app/models/post.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- });
- ```
- ```javascript
- {
- "blog/post": {
- "id": "1
- }
- }
- ```
- Ember Data is going to normalize the payload's root key for the modelName. As a result,
- it will try to look up the "blog/post" model. Since we don't have a model called "blog/post"
- (or a file called app/models/blog/post.js in ember-cli), Ember Data will throw an error
- because it cannot find the "blog/post" model.
- Since we want to remove this namespace, we can define a serializer for the application that will
- remove "blog/" from the payload key whenver it's encountered by Ember Data:
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- modelNameFromPayloadKey(payloadKey) {
- if (payloadKey === 'blog/post') {
- return this._super(payloadKey.replace('blog/', ''));
- } else {
- return this._super(payloadKey);
- }
- }
- });
- ```
- After refreshing, Ember Data will appropriately look up the "post" model.
- By default the modelName for a model is its
- name in dasherized form. This means that a payload key like "blogPost" would be
- normalized to "blog-post" when Ember Data looks up the model. Usually, Ember Data
- can use the correct inflection to do this for you. Most of the time, you won't
- need to override `modelNameFromPayloadKey` for this purpose.
- @method modelNameFromPayloadKey
- @param {String} key
- @return {String} the model's modelName
- */
modelNameFromPayloadKey: function (key) {
- return (0, _emberInflector.singularize)((0, _emberDataPrivateSystemNormalizeModelName.default)(key));
+ return (0, _emberInflector.singularize)((0, _normalizeModelName.default)(key));
},
-
- // SERIALIZE
-
- /**
- Called when a record is saved in order to convert the
- record into JSON.
- By default, it creates a JSON object with a key for
- each attribute and belongsTo relationship.
- For example, consider this model:
- ```app/models/comment.js
- import DS from 'ember-data';
- export default DS.Model.extend({
- title: DS.attr(),
- body: DS.attr(),
- author: DS.belongsTo('user')
- });
- ```
- The default serialization would create a JSON object like:
- ```js
- {
- "title": "Rails is unagi",
- "body": "Rails? Omakase? O_O",
- "author": 12
- }
- ```
- By default, attributes are passed through as-is, unless
- you specified an attribute type (`DS.attr('date')`). If
- you specify a transform, the JavaScript value will be
- serialized when inserted into the JSON hash.
- By default, belongs-to relationships are converted into
- IDs when inserted into the JSON hash.
- ## IDs
- `serialize` takes an options hash with a single option:
- `includeId`. If this option is `true`, `serialize` will,
- by default include the ID in the JSON object it builds.
- The adapter passes in `includeId: true` when serializing
- a record for `createRecord`, but not for `updateRecord`.
- ## Customization
- Your server may expect a different JSON format than the
- built-in serialization format.
- In that case, you can implement `serialize` yourself and
- return a JSON hash of your choosing.
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- serialize(snapshot, options) {
- var json = {
- POST_TTL: snapshot.attr('title'),
- POST_BDY: snapshot.attr('body'),
- POST_CMS: snapshot.hasMany('comments', { ids: true })
- };
- if (options.includeId) {
- json.POST_ID_ = snapshot.id;
- }
- return json;
- }
- });
- ```
- ## Customizing an App-Wide Serializer
- If you want to define a serializer for your entire
- application, you'll probably want to use `eachAttribute`
- and `eachRelationship` on the record.
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- serialize(snapshot, options) {
- var json = {};
- snapshot.eachAttribute(function(name) {
- json[serverAttributeName(name)] = snapshot.attr(name);
- });
- snapshot.eachRelationship(function(name, relationship) {
- if (relationship.kind === 'hasMany') {
- json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
- }
- });
- if (options.includeId) {
- json.ID_ = snapshot.id;
- }
- return json;
- }
- });
- function serverAttributeName(attribute) {
- return attribute.underscore().toUpperCase();
- }
- function serverHasManyName(name) {
- return serverAttributeName(name.singularize()) + "_IDS";
- }
- ```
- This serializer will generate JSON that looks like this:
- ```js
- {
- "TITLE": "Rails is omakase",
- "BODY": "Yep. Omakase.",
- "COMMENT_IDS": [ 1, 2, 3 ]
- }
- ```
- ## Tweaking the Default JSON
- If you just want to do some small tweaks on the default JSON,
- you can call super first and make the tweaks on the returned
- JSON.
- ```app/serializers/post.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- serialize(snapshot, options) {
- var json = this._super(snapshot, options);
- json.subject = json.title;
- delete json.title;
- return json;
- }
- });
- ```
- @method serialize
- @param {DS.Snapshot} snapshot
- @param {Object} options
- @return {Object} json
- */
serialize: function (snapshot, options) {
return this._super.apply(this, arguments);
},
-
- /**
- You can use this method to customize the root keys serialized into the JSON.
- The hash property should be modified by reference (possibly using something like _.extend)
- By default the REST Serializer sends the modelName of a model, which is a camelized
- version of the name.
- For example, your server may expect underscored root objects.
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- serializeIntoHash(data, type, record, options) {
- var root = Ember.String.decamelize(type.modelName);
- data[root] = this.serialize(record, options);
- }
- });
- ```
- @method serializeIntoHash
- @param {Object} hash
- @param {DS.Model} typeClass
- @param {DS.Snapshot} snapshot
- @param {Object} options
- */
serializeIntoHash: function (hash, typeClass, snapshot, options) {
var normalizedRootKey = this.payloadKeyFromModelName(typeClass.modelName);
hash[normalizedRootKey] = this.serialize(snapshot, options);
},
-
- /**
- You can use `payloadKeyFromModelName` to override the root key for an outgoing
- request. By default, the RESTSerializer returns a camelized version of the
- model's name.
- For a model called TacoParty, its `modelName` would be the string `taco-party`. The RESTSerializer
- will send it to the server with `tacoParty` as the root key in the JSON payload:
- ```js
- {
- "tacoParty": {
- "id": "1",
- "location": "Matthew Beale's House"
- }
- }
- ```
- For example, your server may expect dasherized root objects:
- ```app/serializers/application.js
- import DS from 'ember-data';
- export default DS.RESTSerializer.extend({
- payloadKeyFromModelName(modelName) {
- return Ember.String.dasherize(modelName);
- }
- });
- ```
- Given a `TacoParty` model, calling `save` on it would produce an outgoing
- request like:
- ```js
- {
- "taco-party": {
- "id": "1",
- "location": "Matthew Beale's House"
- }
- }
- ```
- @method payloadKeyFromModelName
- @param {String} modelName
- @return {String}
- */
payloadKeyFromModelName: function (modelName) {
return camelize(modelName);
},
-
- /**
- You can use this method to customize how polymorphic objects are serialized.
- By default the REST Serializer creates the key by appending `Type` to
- the attribute and value from the model's camelcased model name.
- @method serializePolymorphicType
- @param {DS.Snapshot} snapshot
- @param {Object} json
- @param {Object} relationship
- */
serializePolymorphicType: function (snapshot, json, relationship) {
var key = relationship.key;
var typeKey = this.keyForPolymorphicType(key, relationship.type, 'serialize');
var belongsTo = snapshot.belongsTo(key);
@@ -19197,32 +16523,23 @@
}
if (_ember.default.isNone(belongsTo)) {
json[typeKey] = null;
} else {
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
json[typeKey] = this.payloadTypeFromModelName(belongsTo.modelName);
} else {
json[typeKey] = camelize(belongsTo.modelName);
}
}
},
-
- /**
- You can use this method to customize how a polymorphic relationship should
- be extracted.
- @method extractPolymorphicRelationship
- @param {Object} relationshipType
- @param {Object} relationshipHash
- @param {Object} relationshipOptions
- @return {Object}
- */
extractPolymorphicRelationship: function (relationshipType, relationshipHash, relationshipOptions) {
- var key = relationshipOptions.key;
- var resourceHash = relationshipOptions.resourceHash;
- var relationshipMeta = relationshipOptions.relationshipMeta;
+ var key = relationshipOptions.key,
+ resourceHash = relationshipOptions.resourceHash,
+ relationshipMeta = relationshipOptions.relationshipMeta;
+
// A polymorphic belongsTo relationship can be present in the payload
// either in the form where the `id` and the `type` are given:
//
// {
// message: { id: 1, type: 'post' }
@@ -19241,231 +16558,87 @@
var isPolymorphic = relationshipMeta.options.polymorphic;
var typeProperty = this.keyForPolymorphicType(key, relationshipType, 'deserialize');
if (isPolymorphic && resourceHash[typeProperty] !== undefined && typeof relationshipHash !== 'object') {
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
var payloadType = resourceHash[typeProperty];
- var type = this.modelNameFromPayloadType(payloadType);
+ var _type = this.modelNameFromPayloadType(payloadType);
var deprecatedTypeLookup = this.modelNameFromPayloadKey(payloadType);
if (payloadType !== deprecatedTypeLookup && !this._hasCustomModelNameFromPayloadType() && this._hasCustomModelNameFromPayloadKey()) {
- type = deprecatedTypeLookup;
+ _type = deprecatedTypeLookup;
}
return {
id: relationshipHash,
- type: type
+ type: _type
};
} else {
- var type = this.modelNameFromPayloadKey(resourceHash[typeProperty]);
+ var _type2 = this.modelNameFromPayloadKey(resourceHash[typeProperty]);
return {
id: relationshipHash,
- type: type
+ type: _type2
};
}
}
return this._super.apply(this, arguments);
}
});
- if ((0, _emberDataPrivateFeatures.default)("ds-payload-type-hooks")) {
+ if ((0, _features.default)("ds-payload-type-hooks")) {
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 DS from 'ember-data';
- export default DS.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));
+ return (0, _emberInflector.singularize)((0, _normalizeModelName.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 DS from 'ember-data';
- export default DS.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
-*/
-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;
+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, _store, _transforms, _storeInjections, _dataAdapter) {
+ 'use strict';
+ exports.__esModule = true;
+ exports.default = setupContainer;
function setupContainer(application) {
- (0, _emberDataPrivateInitializersDataAdapter.default)(application);
- (0, _emberDataPrivateInitializersTransforms.default)(application);
- (0, _emberDataPrivateInitializersStoreInjections.default)(application);
- (0, _emberDataPrivateInitializersStore.default)(application);
+ (0, _dataAdapter.default)(application);
+ (0, _transforms.default)(application);
+ (0, _storeInjections.default)(application);
+ (0, _store.default)(application);
}
});
-define("ember-data/store", ["exports", "ember-data/-private/system/store"], function (exports, _emberDataPrivateSystemStore) {
- exports.default = _emberDataPrivateSystemStore.default;
+define("ember-data/store", ["exports", "ember-data/-private/system/store"], function (exports, _store) {
+ "use strict";
+
+ exports.__esModule = true;
+ exports.default = _store.default;
});
define('ember-data/transform', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
- /**
- The `DS.Transform` class is used to serialize and deserialize model
- attributes when they are saved or loaded from an
- adapter. Subclassing `DS.Transform` is useful for creating custom
- attributes. All subclasses of `DS.Transform` must implement a
- `serialize` and a `deserialize` method.
-
- Example
-
- ```app/transforms/temperature.js
- import DS from 'ember-data';
-
- // Converts centigrade in the JSON to fahrenheit in the app
- export default DS.Transform.extend({
- deserialize(serialized, options) {
- return (serialized * 1.8) + 32;
- },
-
- serialize(deserialized, options) {
- return (deserialized - 32) / 1.8;
- }
- });
- ```
-
- The options passed into the `DS.attr` function when the attribute is
- declared on the model is also available in the transform.
-
- ```app/models/post.js
- export default DS.Model.extend({
- title: DS.attr('string'),
- markdown: DS.attr('markdown', {
- markdown: {
- gfm: false,
- sanitize: true
- }
- })
- });
- ```
-
- ```app/transforms/markdown.js
- export default DS.Transform.extend({
- serialize(deserialized, options) {
- return deserialized.raw;
- },
-
- deserialize(serialized, options) {
- var markdownOptions = options.markdown || {};
-
- return marked(serialized, markdownOptions);
- }
- });
- ```
-
- Usage
-
- ```app/models/requirement.js
- import DS from 'ember-data';
-
- export default DS.Model.extend({
- name: DS.attr('string'),
- temperature: DS.attr('temperature')
- });
- ```
-
- @class Transform
- @namespace DS
- */
+ exports.__esModule = true;
exports.default = _ember.default.Object.extend({
/**
When given a deserialized value from a record attribute this
method must return the serialized value.
Example
@@ -19497,84 +16670,78 @@
*/
deserialize: null
});
});
define("ember-data/version", ["exports"], function (exports) {
- exports.default = "2.13.0-beta.2";
+ "use strict";
+
+ exports.__esModule = true;
+ exports.default = "2.13.0-beta.3";
});
-define("ember-inflector", ["exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (exports, _ember, _emberInflectorLibSystem, _emberInflectorLibExtString) {
+define("ember-inflector", ["module", "exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (module, exports, _ember, _system) {
+ "use strict";
- _emberInflectorLibSystem.Inflector.defaultRules = _emberInflectorLibSystem.defaultRules;
- _ember.default.Inflector = _emberInflectorLibSystem.Inflector;
+ exports.__esModule = true;
+ exports.defaultRules = exports.singularize = exports.pluralize = undefined;
+ /* global define, module */
- _ember.default.String.pluralize = _emberInflectorLibSystem.pluralize;
- _ember.default.String.singularize = _emberInflectorLibSystem.singularize;
+ _system.Inflector.defaultRules = _system.defaultRules;
+ _ember.default.Inflector = _system.Inflector;
- exports.default = _emberInflectorLibSystem.Inflector;
- exports.pluralize = _emberInflectorLibSystem.pluralize;
- exports.singularize = _emberInflectorLibSystem.singularize;
- exports.defaultRules = _emberInflectorLibSystem.defaultRules;
+ _ember.default.String.pluralize = _system.pluralize;
+ _ember.default.String.singularize = _system.singularize;
+ exports.default = _system.Inflector;
+ exports.pluralize = _system.pluralize;
+ exports.singularize = _system.singularize;
+ exports.defaultRules = _system.defaultRules;
+
+
if (typeof define !== 'undefined' && define.amd) {
define('ember-inflector', ['exports'], function (__exports__) {
- __exports__['default'] = _emberInflectorLibSystem.Inflector;
- __exports__.pluralize = _emberInflectorLibSystem.pluralize;
- __exports__.singularize = _emberInflectorLibSystem.singularize;
+ __exports__['default'] = _system.Inflector;
+ __exports__.pluralize = _system.pluralize;
+ __exports__.singularize = _system.singularize;
return __exports__;
});
} else if (typeof module !== 'undefined' && module['exports']) {
- module['exports'] = _emberInflectorLibSystem.Inflector;
- _emberInflectorLibSystem.Inflector.singularize = _emberInflectorLibSystem.singularize;
- _emberInflectorLibSystem.Inflector.pluralize = _emberInflectorLibSystem.pluralize;
+ module['exports'] = _system.Inflector;
+ _system.Inflector.singularize = _system.singularize;
+ _system.Inflector.pluralize = _system.pluralize;
}
});
-/* global define, module */
-define('ember-inflector/lib/ext/string', ['exports', 'ember', 'ember-inflector/lib/system/string'], function (exports, _ember, _emberInflectorLibSystemString) {
+define('ember-inflector/lib/ext/string', ['ember', 'ember-inflector/lib/system/string'], function (_ember, _string) {
+ 'use strict';
if (_ember.default.EXTEND_PROTOTYPES === true || _ember.default.EXTEND_PROTOTYPES.String) {
/**
See {{#crossLink "Ember.String/pluralize"}}{{/crossLink}}
@method pluralize
@for String
*/
String.prototype.pluralize = function () {
- return (0, _emberInflectorLibSystemString.pluralize)(this);
+ return (0, _string.pluralize)(this);
};
/**
See {{#crossLink "Ember.String/singularize"}}{{/crossLink}}
@method singularize
@for String
*/
String.prototype.singularize = function () {
- return (0, _emberInflectorLibSystemString.singularize)(this);
+ return (0, _string.singularize)(this);
};
}
});
-define('ember-inflector/lib/helpers/pluralize', ['exports', 'ember-inflector', 'ember-inflector/lib/utils/make-helper'], function (exports, _emberInflector, _emberInflectorLibUtilsMakeHelper) {
+define('ember-inflector/lib/helpers/pluralize', ['exports', 'ember-inflector', 'ember-inflector/lib/utils/make-helper'], function (exports, _emberInflector, _makeHelper) {
+ 'use strict';
- /**
- *
- * If you have Ember Inflector (such as if Ember Data is present),
- * pluralize a word. For example, turn "ox" into "oxen".
- *
- * Example:
- *
- * {{pluralize count myProperty}}
- * {{pluralize 1 "oxen"}}
- * {{pluralize myProperty}}
- * {{pluralize "ox"}}
- *
- * @for Ember.HTMLBars.helpers
- * @method pluralize
- * @param {Number|Property} [count] count of objects
- * @param {String|Property} word word to pluralize
- */
- exports.default = (0, _emberInflectorLibUtilsMakeHelper.default)(function (params) {
- var count = undefined,
- word = undefined;
+ exports.__esModule = true;
+ exports.default = (0, _makeHelper.default)(function (params) {
+ var count = void 0,
+ word = void 0;
if (params.length === 1) {
word = params[0];
return (0, _emberInflector.pluralize)(word);
} else {
@@ -19587,40 +16754,36 @@
return count + " " + word;
}
});
});
-define('ember-inflector/lib/helpers/singularize', ['exports', 'ember-inflector', 'ember-inflector/lib/utils/make-helper'], function (exports, _emberInflector, _emberInflectorLibUtilsMakeHelper) {
+define('ember-inflector/lib/helpers/singularize', ['exports', 'ember-inflector', 'ember-inflector/lib/utils/make-helper'], function (exports, _emberInflector, _makeHelper) {
+ 'use strict';
- /**
- *
- * If you have Ember Inflector (such as if Ember Data is present),
- * singularize a word. For example, turn "oxen" into "ox".
- *
- * Example:
- *
- * {{singularize myProperty}}
- * {{singularize "oxen"}}
- *
- * @for Ember.HTMLBars.helpers
- * @method singularize
- * @param {String|Property} word word to singularize
- */
- exports.default = (0, _emberInflectorLibUtilsMakeHelper.default)(function (params) {
+ exports.__esModule = true;
+ exports.default = (0, _makeHelper.default)(function (params) {
return (0, _emberInflector.singularize)(params[0]);
});
});
-define("ember-inflector/lib/system", ["exports", "ember-inflector/lib/system/inflector", "ember-inflector/lib/system/string", "ember-inflector/lib/system/inflections"], function (exports, _emberInflectorLibSystemInflector, _emberInflectorLibSystemString, _emberInflectorLibSystemInflections) {
+define("ember-inflector/lib/system", ["exports", "ember-inflector/lib/system/inflector", "ember-inflector/lib/system/string", "ember-inflector/lib/system/inflections"], function (exports, _inflector, _string, _inflections) {
+ "use strict";
- _emberInflectorLibSystemInflector.default.inflector = new _emberInflectorLibSystemInflector.default(_emberInflectorLibSystemInflections.default);
+ exports.__esModule = true;
+ exports.defaultRules = exports.pluralize = exports.singularize = exports.Inflector = undefined;
- exports.Inflector = _emberInflectorLibSystemInflector.default;
- exports.singularize = _emberInflectorLibSystemString.singularize;
- exports.pluralize = _emberInflectorLibSystemString.pluralize;
- exports.defaultRules = _emberInflectorLibSystemInflections.default;
+
+ _inflector.default.inflector = new _inflector.default(_inflections.default);
+
+ exports.Inflector = _inflector.default;
+ exports.singularize = _string.singularize;
+ exports.pluralize = _string.pluralize;
+ exports.defaultRules = _inflections.default;
});
define('ember-inflector/lib/system/inflections', ['exports'], function (exports) {
+ 'use strict';
+
+ exports.__esModule = true;
exports.default = {
plurals: [[/$/, 's'], [/s$/i, 's'], [/^(ax|test)is$/i, '$1es'], [/(octop|vir)us$/i, '$1i'], [/(octop|vir)i$/i, '$1i'], [/(alias|status|bonus)$/i, '$1es'], [/(bu)s$/i, '$1ses'], [/(buffal|tomat)o$/i, '$1oes'], [/([ti])um$/i, '$1a'], [/([ti])a$/i, '$1a'], [/sis$/i, 'ses'], [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'], [/(hive)$/i, '$1s'], [/([^aeiouy]|qu)y$/i, '$1ies'], [/(x|ch|ss|sh)$/i, '$1es'], [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'], [/^(m|l)ouse$/i, '$1ice'], [/^(m|l)ice$/i, '$1ice'], [/^(ox)$/i, '$1en'], [/^(oxen)$/i, '$1'], [/(quiz)$/i, '$1zes']],
singular: [[/s$/i, ''], [/(ss)$/i, '$1'], [/(n)ews$/i, '$1ews'], [/([ti])a$/i, '$1um'], [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'], [/(^analy)(sis|ses)$/i, '$1sis'], [/([^f])ves$/i, '$1fe'], [/(hive)s$/i, '$1'], [/(tive)s$/i, '$1'], [/([lr])ves$/i, '$1f'], [/([^aeiouy]|qu)ies$/i, '$1y'], [/(s)eries$/i, '$1eries'], [/(m)ovies$/i, '$1ovie'], [/(x|ch|ss|sh)es$/i, '$1'], [/^(m|l)ice$/i, '$1ouse'], [/(bus)(es)?$/i, '$1'], [/(o)es$/i, '$1'], [/(shoe)s$/i, '$1'], [/(cris|test)(is|es)$/i, '$1is'], [/^(a)x[ie]s$/i, '$1xis'], [/(octop|vir)(us|i)$/i, '$1us'], [/(alias|status|bonus)(es)?$/i, '$1'], [/^(ox)en/i, '$1'], [/(vert|ind)ices$/i, '$1ex'], [/(matr)ices$/i, '$1ix'], [/(quiz)zes$/i, '$1'], [/(database)s$/i, '$1']],
@@ -19628,11 +16791,15 @@
uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police']
};
});
define('ember-inflector/lib/system/inflector', ['exports', 'ember'], function (exports, _ember) {
+ 'use strict';
+ exports.__esModule = true;
+
+
var capitalize = _ember.default.String.capitalize;
var BLANK_REGEX = /^\s*$/;
var LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
var LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
@@ -19932,26 +17099,33 @@
}
};
exports.default = Inflector;
});
-define('ember-inflector/lib/system/string', ['exports', 'ember-inflector/lib/system/inflector'], function (exports, _emberInflectorLibSystemInflector) {
+define('ember-inflector/lib/system/string', ['exports', 'ember-inflector/lib/system/inflector'], function (exports, _inflector) {
+ 'use strict';
+ exports.__esModule = true;
+ exports.singularize = exports.pluralize = undefined;
+
+
function pluralize(word) {
- return _emberInflectorLibSystemInflector.default.inflector.pluralize(word);
+ return _inflector.default.inflector.pluralize(word);
}
function singularize(word) {
- return _emberInflectorLibSystemInflector.default.inflector.singularize(word);
+ return _inflector.default.inflector.singularize(word);
}
exports.pluralize = pluralize;
exports.singularize = singularize;
});
define('ember-inflector/lib/utils/make-helper', ['exports', 'ember'], function (exports, _ember) {
- exports.default = makeHelper;
+ 'use strict';
+ exports.__esModule = true;
+ exports.default = makeHelper;
function makeHelper(helperFunction) {
if (_ember.default.Helper) {
return _ember.default.Helper.helper(helperFunction);
}
if (_ember.default.HTMLBars) {
@@ -19959,34 +17133,14 @@
}
return _ember.default.Handlebars.makeBoundHelper(helperFunction);
}
});
define('ember-load-initializers', ['exports'], function (exports) {
- function resolveInitializer(moduleName) {
- var module = require(moduleName, null, null, true);
- if (!module) {
- throw new Error(moduleName + ' must export an initializer.');
- }
- var initializer = module['default'];
- if (!initializer.name) {
- initializer.name = moduleName.slice(moduleName.lastIndexOf('/') + 1);
- }
- return initializer;
- }
+ 'use strict';
- function registerInitializers(app, moduleNames) {
- for (var i = 0; i < moduleNames.length; i++) {
- app.initializer(resolveInitializer(moduleNames[i]));
- }
- }
+ exports.__esModule = true;
- function registerInstanceInitializers(app, moduleNames) {
- for (var i = 0; i < moduleNames.length; i++) {
- app.instanceInitializer(resolveInitializer(moduleNames[i]));
- }
- }
-
exports.default = function (app, prefix) {
var initializerPrefix = prefix + '/initializers/';
var instanceInitializerPrefix = prefix + '/instance-initializers/';
var initializers = [];
var instanceInitializers = [];
@@ -20002,338 +17156,41 @@
}
}
registerInitializers(app, initializers);
registerInstanceInitializers(app, instanceInitializers);
};
-});
-define('ember', [], function() {
- return {
- default: Ember
- };
-});
-
-/*!
- * @overview Ember Data
- * @copyright Copyright 2011-2017 Tilde Inc. and contributors.
- * Portions Copyright 2011 LivingSocial Inc.
- * @license Licensed under MIT license (see license.js)
- * @version 2.13.0-beta.2
- */
-
-var loader, define, requireModule, require, requirejs;
-
-(function (global) {
- 'use strict';
-
- var heimdall = global.heimdall;
-
- function dict() {
- var obj = Object.create(null);
- obj['__'] = undefined;
- delete obj['__'];
- return obj;
- }
-
- // Save off the original values of these globals, so we can restore them if someone asks us to
- var oldGlobals = {
- loader: loader,
- define: define,
- requireModule: requireModule,
- require: require,
- requirejs: requirejs
- };
-
- requirejs = require = requireModule = function (name) {
- var pending = [];
- var mod = findModule(name, '(require)', pending);
-
- for (var i = pending.length - 1; i >= 0; i--) {
- pending[i].exports();
+ function resolveInitializer(moduleName) {
+ var module = require(moduleName, null, null, true);
+ if (!module) {
+ throw new Error(moduleName + ' must export an initializer.');
}
-
- return mod.module.exports;
- };
-
- loader = {
- noConflict: function (aliases) {
- var oldName, newName;
-
- for (oldName in aliases) {
- if (aliases.hasOwnProperty(oldName)) {
- if (oldGlobals.hasOwnProperty(oldName)) {
- newName = aliases[oldName];
-
- global[newName] = global[oldName];
- global[oldName] = oldGlobals[oldName];
- }
- }
- }
+ var initializer = module['default'];
+ if (!initializer.name) {
+ initializer.name = moduleName.slice(moduleName.lastIndexOf('/') + 1);
}
- };
-
- var _isArray;
- if (!Array.isArray) {
- _isArray = function (x) {
- return Object.prototype.toString.call(x) === '[object Array]';
- };
- } else {
- _isArray = Array.isArray;
+ return initializer;
}
- var registry = dict();
- var seen = dict();
-
- var uuid = 0;
-
- function unsupportedModule(length) {
- throw new Error('an unsupported module was defined, expected `define(name, deps, module)` instead got: `' + length + '` arguments to define`');
- }
-
- var defaultDeps = ['require', 'exports', 'module'];
-
- function Module(name, deps, callback, alias) {
- this.id = uuid++;
- this.name = name;
- this.deps = !deps.length && callback.length ? defaultDeps : deps;
- this.module = { exports: {} };
- this.callback = callback;
- this.hasExportsAsDep = false;
- this.isAlias = alias;
- this.reified = new Array(deps.length);
-
- /*
- Each module normally passes through these states, in order:
- new : initial state
- pending : this module is scheduled to be executed
- reifying : this module's dependencies are being executed
- reified : this module's dependencies finished executing successfully
- errored : this module's dependencies failed to execute
- finalized : this module executed successfully
- */
- this.state = 'new';
- }
-
- Module.prototype.makeDefaultExport = function () {
- var exports = this.module.exports;
- if (exports !== null && (typeof exports === 'object' || typeof exports === 'function') && exports['default'] === undefined && Object.isExtensible(exports)) {
- exports['default'] = exports;
+ function registerInitializers(app, moduleNames) {
+ for (var i = 0; i < moduleNames.length; i++) {
+ app.initializer(resolveInitializer(moduleNames[i]));
}
- };
-
- Module.prototype.exports = function () {
- // if finalized, there is no work to do. If reifying, there is a
- // circular dependency so we must return our (partial) exports.
- if (this.state === 'finalized' || this.state === 'reifying') {
- return this.module.exports;
- }
-
- if (loader.wrapModules) {
- this.callback = loader.wrapModules(this.name, this.callback);
- }
-
- this.reify();
-
- var result = this.callback.apply(this, this.reified);
- this.state = 'finalized';
-
- if (!(this.hasExportsAsDep && result === undefined)) {
- this.module.exports = result;
- }
- this.makeDefaultExport();
- return this.module.exports;
- };
-
- Module.prototype.unsee = function () {
- this.state = 'new';
- this.module = { exports: {} };
- };
-
- Module.prototype.reify = function () {
- if (this.state === 'reified') {
- return;
- }
- this.state = 'reifying';
- try {
- this.reified = this._reify();
- this.state = 'reified';
- } finally {
- if (this.state === 'reifying') {
- this.state = 'errored';
- }
- }
- };
-
- Module.prototype._reify = function () {
- var reified = this.reified.slice();
- for (var i = 0; i < reified.length; i++) {
- var mod = reified[i];
- reified[i] = mod.exports ? mod.exports : mod.module.exports();
- }
- return reified;
- };
-
- Module.prototype.findDeps = function (pending) {
- if (this.state !== 'new') {
- return;
- }
-
- this.state = 'pending';
-
- var deps = this.deps;
-
- for (var i = 0; i < deps.length; i++) {
- var dep = deps[i];
- var entry = this.reified[i] = { exports: undefined, module: undefined };
- if (dep === 'exports') {
- this.hasExportsAsDep = true;
- entry.exports = this.module.exports;
- } else if (dep === 'require') {
- entry.exports = this.makeRequire();
- } else if (dep === 'module') {
- entry.exports = this.module;
- } else {
- entry.module = findModule(resolve(dep, this.name), this.name, pending);
- }
- }
- };
-
- Module.prototype.makeRequire = function () {
- var name = this.name;
- var r = function (dep) {
- return require(resolve(dep, name));
- };
- r['default'] = r;
- r.has = function (dep) {
- return has(resolve(dep, name));
- };
- return r;
- };
-
- define = function (name, deps, callback) {
- var module = registry[name];
-
- // If a module for this name has already been defined and is in any state
- // other than `new` (meaning it has been or is currently being required),
- // then we return early to avoid redefinition.
- if (module && module.state !== 'new') {
- return;
- }
-
- if (arguments.length < 2) {
- unsupportedModule(arguments.length);
- }
-
- if (!_isArray(deps)) {
- callback = deps;
- deps = [];
- }
-
- if (callback instanceof Alias) {
- registry[name] = new Module(callback.name, deps, callback, true);
- } else {
- registry[name] = new Module(name, deps, callback, false);
- }
- };
-
- // we don't support all of AMD
- // define.amd = {};
-
- function Alias(path) {
- this.name = path;
}
- define.alias = function (path) {
- return new Alias(path);
- };
-
- function missingModule(name, referrer) {
- throw new Error('Could not find module `' + name + '` imported from `' + referrer + '`');
- }
-
- function findModule(name, referrer, pending) {
- var mod = registry[name] || registry[name + '/index'];
-
- while (mod && mod.isAlias) {
- mod = registry[mod.name];
+ function registerInstanceInitializers(app, moduleNames) {
+ for (var i = 0; i < moduleNames.length; i++) {
+ app.instanceInitializer(resolveInitializer(moduleNames[i]));
}
-
- if (!mod) {
- missingModule(name, referrer);
- }
-
- if (pending && mod.state !== 'pending' && mod.state !== 'finalized') {
- mod.findDeps(pending);
- pending.push(mod);
- }
- return mod;
}
-
- function resolve(child, name) {
- if (child.charAt(0) !== '.') {
- return child;
- }
-
- var parts = child.split('/');
- var nameParts = name.split('/');
- var parentBase = nameParts.slice(0, -1);
-
- for (var i = 0, l = parts.length; i < l; i++) {
- var part = parts[i];
-
- if (part === '..') {
- if (parentBase.length === 0) {
- throw new Error('Cannot access parent module of root');
- }
- parentBase.pop();
- } else if (part === '.') {
- continue;
- } else {
- parentBase.push(part);
- }
- }
-
- return parentBase.join('/');
- }
-
- function has(name) {
- return !!(registry[name] || registry[name + '/index']);
- }
-
- requirejs.entries = requirejs._eak_seen = registry;
- requirejs.has = has;
- requirejs.unsee = function (moduleName) {
- findModule(moduleName, '(unsee)', false).unsee();
+});
+define('ember', [], function() {
+ return {
+ default: Ember
};
+});
- requirejs.clear = function () {
- requirejs.entries = requirejs._eak_seen = registry = dict();
- seen = dict();
- };
- // This code primes the JS engine for good performance by warming the
- // JIT compiler for these functions.
- define('foo', function () {});
- define('foo/bar', [], function () {});
- define('foo/asdf', ['module', 'exports', 'require'], function (module, exports, require) {
- if (require.has('foo/bar')) {
- require('foo/bar');
- }
- });
- define('foo/baz', [], define.alias('foo'));
- define('foo/quz', define.alias('foo'));
- define('foo/bar', ['foo', './quz', './baz', './asdf', './bar', '../foo'], function () {});
- define('foo/main', ['foo/bar'], function () {});
-
- require('foo/main');
- require.unsee('foo/bar');
-
- requirejs.clear();
-
- if (typeof exports === 'object' && typeof module === 'object' && module.exports) {
- module.exports = { require: require, define: define };
- }
-})(this);
require("ember-data");
require("ember-load-initializers")["default"](Ember.Application, "ember-data");
;(function() {
var global = require('ember-data/-private/global').default;