@ember-data/model 5.4.0-alpha.1 → 5.4.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/-private.js +2 -2
- package/addon/{has-many-0759b264.js → has-many-665b8730.js} +1 -1
- package/addon/{has-many-0759b264.js.map → has-many-665b8730.js.map} +1 -1
- package/addon/{hooks-0482f3cc.js → hooks-7a58334b.js} +1 -1
- package/addon/hooks-7a58334b.js.map +1 -0
- package/addon/hooks.js +1 -1
- package/addon/index.js +3 -3
- package/addon/{model-48ae96f9.js → model-520a761c.js} +7 -5
- package/addon/model-520a761c.js.map +1 -0
- package/package.json +28 -22
- package/addon/hooks-0482f3cc.js.map +0 -1
- package/addon/model-48ae96f9.js.map +0 -1
- package/blueprints/model-test/mocha-files/__root__/__path__/__test__.js +0 -18
- package/blueprints/model-test/mocha-rfc-232-files/__root__/__path__/__test__.js +0 -15
package/addon/-private.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a as attr, b as belongsTo, h as hasMany } from "./has-many-
|
|
2
|
-
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, M as Model, P as PromiseBelongsTo, a as PromiseManyArray } from "./model-
|
|
1
|
+
export { a as attr, b as belongsTo, h as hasMany } from "./has-many-665b8730";
|
|
2
|
+
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, M as Model, P as PromiseBelongsTo, a as PromiseManyArray } from "./model-520a761c";
|
|
@@ -3,7 +3,7 @@ import { assert, warn, deprecate } from '@ember/debug';
|
|
|
3
3
|
import { computed } from '@ember/object';
|
|
4
4
|
import { recordIdentifierFor } from '@ember-data/store';
|
|
5
5
|
import { peekCache } from '@ember-data/store/-private';
|
|
6
|
-
import { c as computedMacroWithOptionalParams, n as normalizeModelName, l as lookupLegacySupport } from "./model-
|
|
6
|
+
import { c as computedMacroWithOptionalParams, n as normalizeModelName, l as lookupLegacySupport } from "./model-520a761c";
|
|
7
7
|
import { A } from '@ember/array';
|
|
8
8
|
import { dasherize } from '@ember/string';
|
|
9
9
|
import { singularize } from 'ember-inflector';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-many-0759b264.js","sources":["../src/-private/attr.js","../src/-private/belongs-to.js","../src/-private/has-many.js"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@ember-data/env';\nimport { recordIdentifierFor } from '@ember-data/store';\nimport { peekCache } from '@ember-data/store/-private';\n\nimport { computedMacroWithOptionalParams } from './util';\n\n/**\n @module @ember-data/model\n*/\n\n/**\n `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).\n By default, attributes are passed through as-is, however you can specify an\n optional type to have the value automatically transformed.\n Ember Data ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n [Transform](/ember-data/release/classes/Transform).\n\n Note that you cannot use `attr` to define an attribute of `id`.\n\n `attr` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `defaultValue`: Pass a string or a function to be called to set the attribute\n to a default value if and only if the key is absent from the payload response.\n\n Example\n\n ```app/models/user.js\n import Model, { attr } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n @attr('boolean', { defaultValue: false }) verified;\n }\n ```\n\n Default value can also be a function. This is useful it you want to return\n a new object for each attribute.\n\n ```app/models/user.js\n import Model, { attr } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n\n @attr({\n defaultValue() {\n return {};\n }\n })\n settings;\n }\n ```\n\n The `options` hash is passed as second argument to a transforms'\n `serialize` and `deserialize` method. This allows to configure a\n transformation and adapt the corresponding value, based on the config:\n\n ```app/models/post.js\n import Model, { attr } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```app/transforms/text.js\n export default class TextTransform {\n serialize(value, options) {\n if (options.uppercase) {\n return value.toUpperCase();\n }\n\n return value;\n }\n\n deserialize(value) {\n return value;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @method attr\n @public\n @static\n @for @ember-data/model\n @param {String|Object} type the attribute type\n @param {Object} options a hash of options\n @return {Attribute}\n*/\nfunction attr(type, options) {\n if (typeof type === 'object') {\n options = type;\n type = undefined;\n } else {\n options = options || {};\n }\n\n let meta = {\n type: type,\n isAttribute: true,\n options: options,\n };\n\n return computed({\n get(key) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n return peekCache(this).getAttr(recordIdentifierFor(this), key);\n },\n set(key, value) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n assert(\n `Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`,\n !this.currentState.isDeleted\n );\n const identifier = recordIdentifierFor(this);\n const cache = peekCache(this);\n\n let currentValue = cache.getAttr(identifier, key);\n if (currentValue !== value) {\n cache.setAttr(identifier, key, value);\n\n if (!this.isValid) {\n const { errors } = this;\n if (errors.get(key)) {\n errors.remove(key);\n this.currentState.cleanErrorRequests();\n }\n }\n }\n\n return value;\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(attr);\n","import { assert, warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@ember-data/env';\n\nimport { lookupLegacySupport } from './model';\nimport { computedMacroWithOptionalParams, normalizeModelName } from './util';\n\n/**\n @module @ember-data/model\n*/\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many\n relationships on a [Model](/ember-data/release/classes/Model).\n\n\n `belongsTo` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.\n - `inverse`: A string used to identify the inverse property on a\n related model in a One-To-Many relationship. See [Explicit Inverses](#explicit-inverses)\n - `polymorphic` A boolean value to mark the relationship as polymorphic\n\n #### One-To-One\n To declare a one-to-one relationship between two models, use\n `belongsTo`:\n\n ```app/models/user.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @belongsTo('profile') profile;\n }\n ```\n\n ```app/models/profile.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class ProfileModel extends Model {\n @belongsTo('user') user;\n }\n ```\n\n #### One-To-Many\n\n To declare a one-to-many relationship between two models, use\n `belongsTo` in combination with `hasMany`, like this:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n ```\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n ```\n\n #### Sync relationships\n\n Ember Data resolves sync relationships with the related resources\n available in its local store, hence it is expected these resources\n to be loaded before or along-side the primary resource.\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post', {\n async: false,\n inverse: null\n })\n post;\n }\n ```\n\n In contrast to async relationship, accessing a sync relationship\n will always return the record (Model instance) for the existing\n local resource, or null. But it will error on access when\n a related resource is known to exist and it has not been loaded.\n\n ```\n let post = comment.post;\n\n ```\n\n @method belongsTo\n @public\n @static\n @for @ember-data/model\n @param {String} modelName (optional) type of the relationship\n @param {Object} options (optional) a hash of options\n @return {Ember.computed} relationship\n*/\nfunction belongsTo(modelName, options) {\n let opts = options;\n let userEnteredModelName = modelName;\n\n assert(\n `Expected options.async from @belongsTo('${userEnteredModelName}', options) to be a boolean`,\n opts && typeof opts.async === 'boolean'\n );\n assert(\n `Expected options.inverse from @belongsTo('${userEnteredModelName}', options) to be either null or the string type of the related resource.`,\n opts.inverse === null || (typeof opts.inverse === 'string' && opts.inverse.length > 0)\n );\n\n let meta = {\n type: normalizeModelName(userEnteredModelName),\n isRelationship: true,\n options: opts,\n kind: 'belongsTo',\n name: 'Belongs To',\n key: null,\n };\n\n return computed({\n get(key) {\n // this is a legacy behavior we may not carry into a new model setup\n // it's better to error on disconnected records so users find errors\n // in their logic.\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n if (Object.prototype.hasOwnProperty.call(opts, 'serialize')) {\n warn(\n `You provided a serialize option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See Serializer and it's implementations https://api.emberjs.com/ember-data/release/classes/Serializer`,\n false,\n {\n id: 'ds.model.serialize-option-in-belongs-to',\n }\n );\n }\n\n if (Object.prototype.hasOwnProperty.call(opts, 'embedded')) {\n warn(\n `You provided an embedded option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See EmbeddedRecordsMixin https://api.emberjs.com/ember-data/release/classes/EmbeddedRecordsMixin`,\n false,\n {\n id: 'ds.model.embedded-option-in-belongs-to',\n }\n );\n }\n }\n\n return support.getBelongsTo(key);\n },\n set(key, value) {\n const support = lookupLegacySupport(this);\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n }\n this.store._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(belongsTo);\n","/**\n @module @ember-data/model\n*/\nimport { A } from '@ember/array';\nimport { assert, deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\nimport { dasherize } from '@ember/string';\n\nimport { singularize } from 'ember-inflector';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@ember-data/deprecations';\nimport { DEBUG } from '@ember-data/env';\n\nimport { lookupLegacySupport } from './model';\nimport { computedMacroWithOptionalParams } from './util';\n\nfunction normalizeType(type) {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = singularize(dasherize(type));\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '5.3',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n\n/**\n `hasMany` is used to define One-To-Many and Many-To-Many\n relationships on a [Model](/ember-data/release/classes/Model).\n\n `hasMany` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.\n - `inverse`: A string used to identify the inverse property on a related model.\n - `polymorphic` A boolean value to mark the relationship as polymorphic\n\n #### One-To-Many\n To declare a one-to-many relationship between two models, use\n `belongsTo` in combination with `hasMany`, like this:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment') comments;\n }\n ```\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post') post;\n }\n ```\n\n #### Many-To-Many\n To declare a many-to-many relationship between two models, use\n `hasMany`:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('tag') tags;\n }\n ```\n\n ```app/models/tag.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class TagModel extends Model {\n @hasMany('post') posts;\n }\n ```\n\n You can avoid passing a string as the first parameter. In that case Ember Data\n will infer the type from the singularized key name.\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany tags;\n }\n ```\n\n will lookup for a Tag type.\n\n #### Explicit Inverses\n\n Ember Data will do its best to discover which relationships map to\n one another. In the one-to-many code above, for example, Ember Data\n can figure out that changing the `comments` relationship should update\n the `post` relationship on the inverse because post is the only\n relationship to that model.\n\n However, sometimes you may have multiple `belongsTo`/`hasMany` for the\n same type. You can specify which property on the related model is\n the inverse using `hasMany`'s `inverse` option:\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post') onePost;\n @belongsTo('post') twoPost\n @belongsTo('post') redPost;\n @belongsTo('post') bluePost;\n }\n ```\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', {\n inverse: 'redPost'\n })\n comments;\n }\n ```\n\n You can also specify an inverse on a `belongsTo`, which works how\n you'd expect.\n\n #### Sync relationships\n\n Ember Data resolves sync relationships with the related resources\n available in its local store, hence it is expected these resources\n to be loaded before or along-side the primary resource.\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', {\n async: false\n })\n comments;\n }\n ```\n\n In contrast to async relationship, accessing a sync relationship\n will always return a [ManyArray](/ember-data/release/classes/ManyArray) instance\n containing the existing local resources. But it will error on access\n when any of the known related resources have not been loaded.\n\n ```\n post.comments.forEach((comment) => {\n\n });\n\n ```\n\n If you are using `links` with sync relationships, you have to use\n `ref.reload` to fetch the resources.\n\n @method hasMany\n @public\n @static\n @for @ember-data/model\n @param {String} type (optional) type of the relationship\n @param {Object} options (optional) a hash of options\n @return {Ember.computed} relationship\n*/\nfunction hasMany(type, options) {\n assert(`Expected hasMany options.async to be a boolean`, options && typeof options.async === 'boolean');\n\n // Metadata about relationships is stored on the meta of\n // the relationship. This is used for introspection and\n // serialization. Note that `key` is populated lazily\n // the first time the CP is called.\n let meta = {\n type: normalizeType(type),\n options,\n isRelationship: true,\n kind: 'hasMany',\n name: 'Has Many',\n key: null,\n };\n\n return computed({\n get(key) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroying || this.isDestroyed) {\n return A();\n }\n return lookupLegacySupport(this).getHasMany(key);\n },\n set(key, records) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n const support = lookupLegacySupport(this);\n const manyArray = support.getManyArray(key);\n assert(`You must pass an array of records to set a hasMany relationship`, Array.isArray(records));\n this.store._join(() => {\n manyArray.splice(0, manyArray.length, ...records);\n });\n\n return support.getHasMany(key);\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(hasMany);\n"],"names":["attr","type","options","undefined","meta","isAttribute","computed","get","key","macroCondition","getOwnConfig","env","DEBUG","indexOf","Error","constructor","toString","isDestroyed","isDestroying","peekCache","getAttr","recordIdentifierFor","set","value","assert","currentState","isDeleted","identifier","cache","currentValue","setAttr","isValid","errors","remove","cleanErrorRequests","computedMacroWithOptionalParams","belongsTo","modelName","opts","userEnteredModelName","async","inverse","length","normalizeModelName","isRelationship","kind","name","support","lookupLegacySupport","Object","prototype","hasOwnProperty","call","warn","id","getBelongsTo","store","_join","setDirtyBelongsTo","normalizeType","deprecations","DEPRECATE_NON_STRICT_TYPES","result","singularize","dasherize","deprecate","until","for","since","available","enabled","hasMany","A","getHasMany","records","manyArray","getManyArray","Array","isArray","splice"],"mappings":";;;;;;;;;;AASA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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d,KAAA;AACF,GAAC,CAAC,CAACnB,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;AAEA,aAAe+B,+BAA+B,CAACnC,IAAI,CAAC;;AC5JpD;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASoC,SAASA,CAACC,SAAS,EAAEnC,OAAO,EAAE;EACrC,IAAIoC,IAAI,GAAGpC,OAAO,CAAA;EAClB,IAAIqC,oBAAoB,GAAGF,SAAS,CAAA;AAEpCb,EAAAA,MAAM,CACH,CAAA,wCAAA,EAA0Ce,oBAAqB,CAAA,2BAAA,CAA4B,EAC5FD,IAAI,IAAI,OAAOA,IAAI,CAACE,KAAK,KAAK,SAChC,CAAC,CAAA;EACDhB,MAAM,CACH,CAA4Ce,0CAAAA,EAAAA,oBAAqB,CAA0E,yEAAA,CAAA,EAC5ID,IAAI,CAACG,OAAO,KAAK,IAAI,IAAK,OAAOH,IAAI,CAACG,OAAO,KAAK,QAAQ,IAAIH,IAAI,CAACG,OAAO,CAACC,MAAM,GAAG,CACtF,CAAC,CAAA;AAED,EAAA,IAAItC,IAAI,GAAG;AACTH,IAAAA,IAAI,EAAE0C,kBAAkB,CAACJ,oBAAoB,CAAC;AAC9CK,IAAAA,cAAc,EAAE,IAAI;AACpB1C,IAAAA,OAAO,EAAEoC,IAAI;AACbO,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CAAA,EAAA,CAAG,EACtH6D,MAAM,KAAK7D,IAAI,EACf;AACEqD,MAAAA,EAAE,EAAE,uCAAuC;AAC3CY,MAAAA,KAAK,EAAE,KAAK;AACZC,MAAAA,GAAG,EAAE,YAAY;AACjBC,MAAAA,KAAK,EAAE;AACLC,QAAAA,SAAS,EAAE,KAAK;AAChBC,QAAAA,OAAO,EAAE,KAAA;AACX,OAAA;AACF,KACF,CAAC,CAAA;AAED,IAAA,OAAOR,MAAM,CAAA;AACf,GAAA;AAEA,EAAA,OAAO7D,IAAI,CAAA;AACb,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASsE,OAAOA,CAACtE,IAAI,EAAEC,OAAO,EAAE;EAC9BsB,MAAM,CAAE,CAA+C,8CAAA,CAAA,EAAEtB,OAAO,IAAI,OAAOA,OAAO,CAACsC,KAAK,KAAK,SAAS,CAAC,CAAA;;AAEvG;AACA;AACA;AACA;AACA,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,IAAI,CAAC,CAAA;AACzC,MAAA,MAAM2B,SAAS,GAAG5B,OAAO,CAAC6B,YAAY,CAACpE,GAAG,CAAC,CAAA;MAC3CgB,MAAM,CAAE,iEAAgE,EAAEqD,KAAK,CAACC,OAAO,CAACJ,OAAO,CAAC,CAAC,CAAA;AACjG,MAAA,IAAI,CAAClB,KAAK,CAACC,KAAK,CAAC,MAAM;QACrBkB,SAAS,CAACI,MAAM,CAAC,CAAC,EAAEJ,SAAS,CAACjC,MAAM,EAAE,GAAGgC,OAAO,CAAC,CAAA;AACnD,OAAC,CAAC,CAAA;AAEF,MAAA,OAAO3B,OAAO,CAAC0B,UAAU,CAACjE,GAAG,CAAC,CAAA;AAChC,KAAA;AACF,GAAC,CAAC,CAACJ,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;AAEA,gBAAe+B,+BAA+B,CAACoC,OAAO,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"has-many-665b8730.js","sources":["../src/-private/attr.js","../src/-private/belongs-to.js","../src/-private/has-many.js"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@ember-data/env';\nimport { recordIdentifierFor } from '@ember-data/store';\nimport { peekCache } from '@ember-data/store/-private';\n\nimport { computedMacroWithOptionalParams } from './util';\n\n/**\n @module @ember-data/model\n*/\n\n/**\n `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).\n By default, attributes are passed through as-is, however you can specify an\n optional type to have the value automatically transformed.\n Ember Data ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n [Transform](/ember-data/release/classes/Transform).\n\n Note that you cannot use `attr` to define an attribute of `id`.\n\n `attr` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `defaultValue`: Pass a string or a function to be called to set the attribute\n to a default value if and only if the key is absent from the payload response.\n\n Example\n\n ```app/models/user.js\n import Model, { attr } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n @attr('boolean', { defaultValue: false }) verified;\n }\n ```\n\n Default value can also be a function. This is useful it you want to return\n a new object for each attribute.\n\n ```app/models/user.js\n import Model, { attr } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n\n @attr({\n defaultValue() {\n return {};\n }\n })\n settings;\n }\n ```\n\n The `options` hash is passed as second argument to a transforms'\n `serialize` and `deserialize` method. This allows to configure a\n transformation and adapt the corresponding value, based on the config:\n\n ```app/models/post.js\n import Model, { attr } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```app/transforms/text.js\n export default class TextTransform {\n serialize(value, options) {\n if (options.uppercase) {\n return value.toUpperCase();\n }\n\n return value;\n }\n\n deserialize(value) {\n return value;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @method attr\n @public\n @static\n @for @ember-data/model\n @param {String|Object} type the attribute type\n @param {Object} options a hash of options\n @return {Attribute}\n*/\nfunction attr(type, options) {\n if (typeof type === 'object') {\n options = type;\n type = undefined;\n } else {\n options = options || {};\n }\n\n let meta = {\n type: type,\n isAttribute: true,\n options: options,\n };\n\n return computed({\n get(key) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n return peekCache(this).getAttr(recordIdentifierFor(this), key);\n },\n set(key, value) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n assert(\n `Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`,\n !this.currentState.isDeleted\n );\n const identifier = recordIdentifierFor(this);\n const cache = peekCache(this);\n\n let currentValue = cache.getAttr(identifier, key);\n if (currentValue !== value) {\n cache.setAttr(identifier, key, value);\n\n if (!this.isValid) {\n const { errors } = this;\n if (errors.get(key)) {\n errors.remove(key);\n this.currentState.cleanErrorRequests();\n }\n }\n }\n\n return value;\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(attr);\n","import { assert, warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@ember-data/env';\n\nimport { lookupLegacySupport } from './model';\nimport { computedMacroWithOptionalParams, normalizeModelName } from './util';\n\n/**\n @module @ember-data/model\n*/\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many\n relationships on a [Model](/ember-data/release/classes/Model).\n\n\n `belongsTo` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.\n - `inverse`: A string used to identify the inverse property on a\n related model in a One-To-Many relationship. See [Explicit Inverses](#explicit-inverses)\n - `polymorphic` A boolean value to mark the relationship as polymorphic\n\n #### One-To-One\n To declare a one-to-one relationship between two models, use\n `belongsTo`:\n\n ```app/models/user.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @belongsTo('profile') profile;\n }\n ```\n\n ```app/models/profile.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class ProfileModel extends Model {\n @belongsTo('user') user;\n }\n ```\n\n #### One-To-Many\n\n To declare a one-to-many relationship between two models, use\n `belongsTo` in combination with `hasMany`, like this:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n ```\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n ```\n\n #### Sync relationships\n\n Ember Data resolves sync relationships with the related resources\n available in its local store, hence it is expected these resources\n to be loaded before or along-side the primary resource.\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post', {\n async: false,\n inverse: null\n })\n post;\n }\n ```\n\n In contrast to async relationship, accessing a sync relationship\n will always return the record (Model instance) for the existing\n local resource, or null. But it will error on access when\n a related resource is known to exist and it has not been loaded.\n\n ```\n let post = comment.post;\n\n ```\n\n @method belongsTo\n @public\n @static\n @for @ember-data/model\n @param {String} modelName (optional) type of the relationship\n @param {Object} options (optional) a hash of options\n @return {Ember.computed} relationship\n*/\nfunction belongsTo(modelName, options) {\n let opts = options;\n let userEnteredModelName = modelName;\n\n assert(\n `Expected options.async from @belongsTo('${userEnteredModelName}', options) to be a boolean`,\n opts && typeof opts.async === 'boolean'\n );\n assert(\n `Expected options.inverse from @belongsTo('${userEnteredModelName}', options) to be either null or the string type of the related resource.`,\n opts.inverse === null || (typeof opts.inverse === 'string' && opts.inverse.length > 0)\n );\n\n let meta = {\n type: normalizeModelName(userEnteredModelName),\n isRelationship: true,\n options: opts,\n kind: 'belongsTo',\n name: 'Belongs To',\n key: null,\n };\n\n return computed({\n get(key) {\n // this is a legacy behavior we may not carry into a new model setup\n // it's better to error on disconnected records so users find errors\n // in their logic.\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n if (Object.prototype.hasOwnProperty.call(opts, 'serialize')) {\n warn(\n `You provided a serialize option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See Serializer and it's implementations https://api.emberjs.com/ember-data/release/classes/Serializer`,\n false,\n {\n id: 'ds.model.serialize-option-in-belongs-to',\n }\n );\n }\n\n if (Object.prototype.hasOwnProperty.call(opts, 'embedded')) {\n warn(\n `You provided an embedded option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See EmbeddedRecordsMixin https://api.emberjs.com/ember-data/release/classes/EmbeddedRecordsMixin`,\n false,\n {\n id: 'ds.model.embedded-option-in-belongs-to',\n }\n );\n }\n }\n\n return support.getBelongsTo(key);\n },\n set(key, value) {\n const support = lookupLegacySupport(this);\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n }\n this.store._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(belongsTo);\n","/**\n @module @ember-data/model\n*/\nimport { A } from '@ember/array';\nimport { assert, deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\nimport { dasherize } from '@ember/string';\n\nimport { singularize } from 'ember-inflector';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@ember-data/deprecations';\nimport { DEBUG } from '@ember-data/env';\n\nimport { lookupLegacySupport } from './model';\nimport { computedMacroWithOptionalParams } from './util';\n\nfunction normalizeType(type) {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = singularize(dasherize(type));\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '5.3',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n\n/**\n `hasMany` is used to define One-To-Many and Many-To-Many\n relationships on a [Model](/ember-data/release/classes/Model).\n\n `hasMany` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.\n - `inverse`: A string used to identify the inverse property on a related model.\n - `polymorphic` A boolean value to mark the relationship as polymorphic\n\n #### One-To-Many\n To declare a one-to-many relationship between two models, use\n `belongsTo` in combination with `hasMany`, like this:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment') comments;\n }\n ```\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post') post;\n }\n ```\n\n #### Many-To-Many\n To declare a many-to-many relationship between two models, use\n `hasMany`:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('tag') tags;\n }\n ```\n\n ```app/models/tag.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class TagModel extends Model {\n @hasMany('post') posts;\n }\n ```\n\n You can avoid passing a string as the first parameter. In that case Ember Data\n will infer the type from the singularized key name.\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany tags;\n }\n ```\n\n will lookup for a Tag type.\n\n #### Explicit Inverses\n\n Ember Data will do its best to discover which relationships map to\n one another. In the one-to-many code above, for example, Ember Data\n can figure out that changing the `comments` relationship should update\n the `post` relationship on the inverse because post is the only\n relationship to that model.\n\n However, sometimes you may have multiple `belongsTo`/`hasMany` for the\n same type. You can specify which property on the related model is\n the inverse using `hasMany`'s `inverse` option:\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post') onePost;\n @belongsTo('post') twoPost\n @belongsTo('post') redPost;\n @belongsTo('post') bluePost;\n }\n ```\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', {\n inverse: 'redPost'\n })\n comments;\n }\n ```\n\n You can also specify an inverse on a `belongsTo`, which works how\n you'd expect.\n\n #### Sync relationships\n\n Ember Data resolves sync relationships with the related resources\n available in its local store, hence it is expected these resources\n to be loaded before or along-side the primary resource.\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', {\n async: false\n })\n comments;\n }\n ```\n\n In contrast to async relationship, accessing a sync relationship\n will always return a [ManyArray](/ember-data/release/classes/ManyArray) instance\n containing the existing local resources. But it will error on access\n when any of the known related resources have not been loaded.\n\n ```\n post.comments.forEach((comment) => {\n\n });\n\n ```\n\n If you are using `links` with sync relationships, you have to use\n `ref.reload` to fetch the resources.\n\n @method hasMany\n @public\n @static\n @for @ember-data/model\n @param {String} type (optional) type of the relationship\n @param {Object} options (optional) a hash of options\n @return {Ember.computed} relationship\n*/\nfunction hasMany(type, options) {\n assert(`Expected hasMany options.async to be a boolean`, options && typeof options.async === 'boolean');\n\n // Metadata about relationships is stored on the meta of\n // the relationship. This is used for introspection and\n // serialization. Note that `key` is populated lazily\n // the first time the CP is called.\n let meta = {\n type: normalizeType(type),\n options,\n isRelationship: true,\n kind: 'hasMany',\n name: 'Has Many',\n key: null,\n };\n\n return computed({\n get(key) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroying || this.isDestroyed) {\n return A();\n }\n return lookupLegacySupport(this).getHasMany(key);\n },\n set(key, records) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n const support = lookupLegacySupport(this);\n const manyArray = support.getManyArray(key);\n assert(`You must pass an array of records to set a hasMany relationship`, Array.isArray(records));\n this.store._join(() => {\n manyArray.splice(0, manyArray.length, ...records);\n });\n\n return support.getHasMany(key);\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(hasMany);\n"],"names":["attr","type","options","undefined","meta","isAttribute","computed","get","key","macroCondition","getOwnConfig","env","DEBUG","indexOf","Error","constructor","toString","isDestroyed","isDestroying","peekCache","getAttr","recordIdentifierFor","set","value","assert","currentState","isDeleted","identifier","cache","currentValue","setAttr","isValid","errors","remove","cleanErrorRequests","computedMacroWithOptionalParams","belongsTo","modelName","opts","userEnteredModelName","async","inverse","length","normalizeModelName","isRelationship","kind","name","support","lookupLegacySupport","Object","prototype","hasOwnProperty","call","warn","id","getBelongsTo","store","_join","setDirtyBelongsTo","normalizeType","deprecations","DEPRECATE_NON_STRICT_TYPES","result","singularize","dasherize","deprecate","until","for","since","available","enabled","hasMany","A","getHasMany","records","manyArray","getManyArray","Array","isArray","splice"],"mappings":";;;;;;;;;;AASA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,IAAIA,CAACC,IAAI,EAAEC,OAAO,EAAE;AAC3B,EAAA,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;AAC5BC,IAAAA,OAAO,GAAGD,IAAI,CAAA;AACdA,IAAAA,IAAI,GAAGE,SAAS,CAAA;AAClB,GAAC,MAAM;AACLD,IAAAA,OAAO,GAAGA,OAAO,IAAI,EAAE,CAAA;AACzB,GAAA;AAEA,EAAA,IAAIE,IAAI,GAAG;AACTH,IAAAA,IAAI,EAAEA,IAAI;AACVI,IAAAA,WAAW,EAAE,IAAI;AACjBH,IAAAA,OAAO,EAAEA,OAAAA;GACV,CAAA;AAED,EAAA,OAAOI,QAAQ,CAAC;IACdC,GAAGA,CAACC,GAAG,EAAE;AACP,MAAA,IAAAC,cAAA,CAAAC,YAAA,GAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;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Y,KAAKN,KAAK,EAAE;QAC1BK,KAAK,CAACE,OAAO,CAACH,UAAU,EAAEnB,GAAG,EAAEe,KAAK,CAAC,CAAA;AAErC,QAAA,IAAI,CAAC,IAAI,CAACQ,OAAO,EAAE;UACjB,MAAM;AAAEC,YAAAA,MAAAA;AAAO,WAAC,GAAG,IAAI,CAAA;AACvB,UAAA,IAAIA,MAAM,CAACzB,GAAG,CAACC,GAAG,CAAC,EAAE;AACnBwB,YAAAA,MAAM,CAACC,MAAM,CAACzB,GAAG,CAAC,CAAA;AAClB,YAAA,IAAI,CAACiB,YAAY,CAACS,kBAAkB,EAAE,CAAA;AACxC,WAAA;AACF,SAAA;AACF,OAAA;AAEA,MAAA,OAAOX,KAAK,CAAA;AACd,KAAA;AACF,GAAC,CAAC,CAACnB,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;AAEA,aAAe+B,+BAA+B,CAACnC,IAAI,CAAC;;AC5JpD;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASoC,SAASA,CAACC,SAAS,EAAEnC,OAAO,EAAE;EACrC,IAAIoC,IAAI,GAAGpC,OAAO,CAAA;EAClB,IAAIqC,oBAAoB,GAAGF,SAAS,CAAA;AAEpCb,EAAAA,MAAM,CACH,CAAA,wCAAA,EAA0Ce,oBAAqB,CAAA,2BAA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/C,GAAG,CAAC,CAAA;AAClC,KAAA;AACF,GAAC,CAAC,CAACJ,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;AAEA,kBAAe+B,+BAA+B,CAACC,SAAS,CAAC;;ACrKzD,SAASuB,aAAaA,CAAC1D,IAAI,EAAE;AAC3B,EAAA,IAAAQ,cAAA,CAAAC,YAAA,GAAAkD,YAAA,CAAAC,0BAAA,CAAgC,EAAA;IAC9B,MAAMC,MAAM,GAAGC,WAAW,CAACC,SAAS,CAAC/D,IAAI,CAAC,CAAC,CAAA;AAE3CgE,IAAAA,SAAS,CACN,CAAA,mBAAA,EAAqBhE,IAAK,CAAA,0DAAA,EAA4D6D,MAAO,CAAA,cAAA,EAAgB7D,IAAK,CAAA,EAAA,CAAG,EACtH6D,MAAM,KAAK7D,IAAI,EACf;AACEqD,MAAAA,EAAE,EAAE,uCAAuC;AAC3CY,MAAAA,KAAK,EAAE,KAAK;AACZC,MAAAA,GAAG,EAAE,YAAY;AACjBC,MAAAA,KAAK,EAAE;AACLC,QAAAA,SAAS,EAAE,KAAK;AAChBC,QAAAA,OAAO,EAAE,KAAA;AACX,OAAA;AACF,KACF,CAAC,CAAA;AAED,IAAA,OAAOR,MAAM,CAAA;AACf,GAAA;AAEA,EAAA,OAAO7D,IAAI,CAAA;AACb,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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,UAAU,CAACjE,GAAG,CAAC,CAAA;KACjD;AACDc,IAAAA,GAAGA,CAACd,GAAG,EAAEkE,OAAO,EAAE;AAChB,MAAA,IAAAjE,cAAA,CAAAC,YAAA,GAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;QACT,IAAI,CAAC,cAAc,CAAC,CAACC,OAAO,CAACL,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;AACxC,UAAA,MAAM,IAAIM,KAAK,CACZ,CAAA,CAAA,EAAGN,GAAI,CAAqI,mIAAA,EAAA,IAAI,CAACO,WAAW,CAACC,QAAQ,EAAG,EAC3K,CAAC,CAAA;AACH,SAAA;AACF,OAAA;AACA,MAAA,MAAM+B,OAAO,GAAGC,mBAAmB,CAAC,IAAI,CAAC,CAAA;AACzC,MAAA,MAAM2B,SAAS,GAAG5B,OAAO,CAAC6B,YAAY,CAACpE,GAAG,CAAC,CAAA;MAC3CgB,MAAM,CAAE,iEAAgE,EAAEqD,KAAK,CAACC,OAAO,CAACJ,OAAO,CAAC,CAAC,CAAA;AACjG,MAAA,IAAI,CAAClB,KAAK,CAACC,KAAK,CAAC,MAAM;QACrBkB,SAAS,CAACI,MAAM,CAAC,CAAC,EAAEJ,SAAS,CAACjC,MAAM,EAAE,GAAGgC,OAAO,CAAC,CAAA;AACnD,OAAC,CAAC,CAAA;AAEF,MAAA,OAAO3B,OAAO,CAAC0B,UAAU,CAACjE,GAAG,CAAC,CAAA;AAChC,KAAA;AACF,GAAC,CAAC,CAACJ,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;AAEA,gBAAe+B,+BAA+B,CAACoC,OAAO,CAAC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getOwner, setOwner } from '@ember/application';
|
|
2
2
|
import { assert } from '@ember/debug';
|
|
3
3
|
import { setRecordIdentifier, StoreMap, setCacheFor } from '@ember-data/store/-private';
|
|
4
|
-
import { M as Model, n as normalizeModelName } from "./model-
|
|
4
|
+
import { M as Model, n as normalizeModelName } from "./model-520a761c";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
In case someone defined a relationship to a mixin, for example:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-7a58334b.js","sources":["../src/-private/model-for-mixin.ts","../src/-private/schema-provider.ts","../src/-private/hooks.ts"],"sourcesContent":["import { getOwner } from '@ember/application';\n\nimport type Store from '@ember-data/store';\n\nimport Model, { type ModelFactory } from './model';\n\n/*\n In case someone defined a relationship to a mixin, for example:\n ```\n import Model, { belongsTo, hasMany } from '@ember-data/model';\n import Mixin from '@ember/object/mixin';\n\n class CommentModel extends Model {\n @belongsTo('commentable', { polymorphic: true }) owner;\n }\n\n let Commentable = Mixin.create({\n @hasMany('comment') comments;\n });\n ```\n we want to look up a Commentable class which has all the necessary\n relationship meta data. Thus, we look up the mixin and create a mock\n Model, so we can access the relationship CPs of the mixin (`comments`)\n in this case\n */\nexport default function modelForMixin(store: Store, normalizedModelName: string): ModelFactory | undefined {\n let owner: any = getOwner(store);\n let MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);\n let mixin = MaybeMixin && MaybeMixin.class;\n if (mixin) {\n let ModelForMixin = Model.extend(mixin);\n ModelForMixin.__isMixin = true;\n ModelForMixin.__mixin = mixin;\n //Cache the class as a model\n owner.register('model:' + normalizedModelName, ModelForMixin);\n }\n return owner.factoryFor(`model:${normalizedModelName}`);\n}\n","import { getOwner } from '@ember/application';\n\nimport type Store from '@ember-data/store';\nimport type { RecordIdentifier } from '@ember-data/types/q/identifier';\nimport type { AttributesSchema, RelationshipsSchema } from '@ember-data/types/q/record-data-schemas';\n\nimport type { FactoryCache, ModelFactory, ModelStore } from './model';\nimport Model from './model';\nimport _modelForMixin from './model-for-mixin';\nimport { normalizeModelName } from './util';\n\nexport class ModelSchemaProvider {\n declare store: ModelStore;\n declare _relationshipsDefCache: Record<string, RelationshipsSchema>;\n declare _attributesDefCache: Record<string, AttributesSchema>;\n\n constructor(store: ModelStore) {\n this.store = store;\n this._relationshipsDefCache = Object.create(null) as Record<string, RelationshipsSchema>;\n this._attributesDefCache = Object.create(null) as Record<string, AttributesSchema>;\n }\n\n // Following the existing RD implementation\n attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {\n const { type } = identifier;\n let attributes: AttributesSchema;\n\n attributes = this._attributesDefCache[type];\n\n if (attributes === undefined) {\n let modelClass = this.store.modelFor(type);\n let attributeMap = modelClass.attributes;\n\n attributes = Object.create(null) as AttributesSchema;\n attributeMap.forEach((meta, name) => (attributes[name] = meta));\n this._attributesDefCache[type] = attributes;\n }\n\n return attributes;\n }\n\n // Following the existing RD implementation\n relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {\n const { type } = identifier;\n let relationships: RelationshipsSchema;\n\n relationships = this._relationshipsDefCache[type];\n\n if (relationships === undefined) {\n let modelClass = this.store.modelFor(type) as typeof Model;\n relationships = modelClass.relationshipsObject || null;\n this._relationshipsDefCache[type] = relationships;\n }\n\n return relationships;\n }\n\n doesTypeExist(modelName: string): boolean {\n const type = normalizeModelName(modelName);\n const factory = getModelFactory(this.store, type);\n\n return factory !== null;\n }\n}\n\nexport function buildSchema(store: Store) {\n return new ModelSchemaProvider(store as ModelStore);\n}\n\nexport function getModelFactory(store: ModelStore, type: string): ModelFactory | null {\n if (!store._modelFactoryCache) {\n store._modelFactoryCache = Object.create(null) as FactoryCache;\n }\n const cache = store._modelFactoryCache;\n let factory: ModelFactory | undefined = cache[type];\n\n if (!factory) {\n const owner = getOwner(store)!;\n factory = owner.factoryFor(`model:${type}`) as ModelFactory | undefined;\n\n if (!factory) {\n //Support looking up mixins as base types for polymorphic relationships\n factory = _modelForMixin(store, type);\n }\n\n if (!factory) {\n // we don't cache misses in case someone wants to register a missing model\n return null;\n }\n\n let klass = factory.class;\n\n if (klass.isModel) {\n let hasOwnModelNameSet = klass.modelName && Object.prototype.hasOwnProperty.call(klass, 'modelName');\n if (!hasOwnModelNameSet) {\n Object.defineProperty(klass, 'modelName', { value: type });\n }\n }\n\n cache[type] = factory;\n }\n\n return factory;\n}\n","import { getOwner, setOwner } from '@ember/application';\nimport { assert } from '@ember/debug';\n\nimport { setCacheFor, setRecordIdentifier, type Store, StoreMap } from '@ember-data/store/-private';\nimport type { Cache } from '@ember-data/types/cache/cache';\nimport type { StableRecordIdentifier } from '@ember-data/types/q/identifier';\n\nimport type { ModelStore } from './model';\nimport Model from './model';\nimport { getModelFactory } from './schema-provider';\nimport { normalizeModelName } from './util';\n\nfunction recast(context: Store): asserts context is ModelStore {}\n\nexport function instantiateRecord(\n this: Store,\n identifier: StableRecordIdentifier,\n createRecordArgs: { [key: string]: unknown }\n): Model {\n const type = identifier.type;\n\n recast(this);\n\n const cache = this.cache;\n // TODO deprecate allowing unknown args setting\n const createOptions = {\n _createProps: createRecordArgs,\n // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for\n _secretInit: {\n identifier,\n cache,\n store: this,\n cb: secretInit,\n },\n };\n\n // ensure that `getOwner(this)` works inside a model instance\n setOwner(createOptions, getOwner(this)!);\n const factory = getModelFactory(this, type);\n\n assert(`No model was found for '${type}'`, factory);\n return factory.class.create(createOptions);\n}\n\nexport function teardownRecord(record: Model): void {\n assert(\n `expected to receive an instance of Model from @ember-data/model. If using a custom model make sure you implement teardownRecord`,\n 'destroy' in record\n );\n record.destroy();\n}\n\nexport function modelFor(this: Store, modelName: string): typeof Model | void {\n assert(`You need to pass a model name to the store's modelFor method`, modelName);\n assert(\n `Please pass a proper model name to the store's modelFor method`,\n typeof modelName === 'string' && modelName.length\n );\n recast(this);\n\n const type = normalizeModelName(modelName);\n const maybeFactory = getModelFactory(this, type);\n const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;\n\n const ignoreType = !klass || !klass.isModel || this._forceShim;\n if (!ignoreType) {\n return klass;\n }\n assert(\n `No model was found for '${type}' and no schema handles the type`,\n this.getSchemaDefinitionService().doesTypeExist(type)\n );\n}\n\nfunction secretInit(record: Model, cache: Cache, identifier: StableRecordIdentifier, store: Store): void {\n setRecordIdentifier(record, identifier);\n StoreMap.set(record, store);\n setCacheFor(record, cache);\n}\n"],"names":["modelForMixin","store","normalizedModelName","owner","getOwner","MaybeMixin","factoryFor","mixin","class","ModelForMixin","Model","extend","__isMixin","__mixin","register","ModelSchemaProvider","constructor","_relationshipsDefCache","Object","create","_attributesDefCache","attributesDefinitionFor","identifier","type","attributes","undefined","modelClass","modelFor","attributeMap","forEach","meta","name","relationshipsDefinitionFor","relationships","relationshipsObject","doesTypeExist","modelName","normalizeModelName","factory","getModelFactory","buildSchema","_modelFactoryCache","cache","_modelForMixin","klass","isModel","hasOwnModelNameSet","prototype","hasOwnProperty","call","defineProperty","value","instantiateRecord","createRecordArgs","createOptions","_createProps","_secretInit","cb","secretInit","setOwner","assert","teardownRecord","record","destroy","length","maybeFactory","ignoreType","_forceShim","getSchemaDefinitionService","setRecordIdentifier","StoreMap","set","setCacheFor"],"mappings":";;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAaA,CAACC,KAAY,EAAEC,mBAA2B,EAA4B;AACzG,EAAA,IAAIC,KAAU,GAAGC,QAAQ,CAACH,KAAK,CAAC,CAAA;EAChC,IAAII,UAAU,GAAGF,KAAK,CAACG,UAAU,CAAE,CAAA,MAAA,EAAQJ,mBAAoB,CAAA,CAAC,CAAC,CAAA;AACjE,EAAA,IAAIK,KAAK,GAAGF,UAAU,IAAIA,UAAU,CAACG,KAAK,CAAA;AAC1C,EAAA,IAAID,KAAK,EAAE;AACT,IAAA,IAAIE,aAAa,GAAGC,KAAK,CAACC,MAAM,CAACJ,KAAK,CAAC,CAAA;IACvCE,aAAa,CAACG,SAAS,GAAG,IAAI,CAAA;IAC9BH,aAAa,CAACI,OAAO,GAAGN,KAAK,CAAA;AAC7B;IACAJ,KAAK,CAACW,QAAQ,CAAC,QA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AA,EAA0BrC,IAAK,CAAA,gCAAA,CAAiC,EACjE,IAAI,CAAC6C,0BAA0B,EAAE,CAACjC,aAAa,CAACZ,IAAI,CACtD,CAAC,CAAA;AACH,CAAA;AAEA,SAASmC,UAAUA,CAACI,MAAa,EAAEpB,KAAY,EAAEpB,UAAkC,EAAErB,KAAY,EAAQ;AACvGoE,EAAAA,mBAAmB,CAACP,MAAM,EAAExC,UAAU,CAAC,CAAA;AACvCgD,EAAAA,QAAQ,CAACC,GAAG,CAACT,MAAM,EAAE7D,KAAK,CAAC,CAAA;AAC3BuE,EAAAA,WAAW,CAACV,MAAM,EAAEpB,KAAK,CAAC,CAAA;AAC5B;;;;"}
|
package/addon/hooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { b as buildSchema, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-
|
|
1
|
+
export { b as buildSchema, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-7a58334b";
|
package/addon/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { a as attr, b as belongsTo, h as hasMany } from "./has-many-
|
|
2
|
-
export { M as default } from "./model-
|
|
3
|
-
export { M as ModelSchemaProvider, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-
|
|
1
|
+
export { a as attr, b as belongsTo, h as hasMany } from "./has-many-665b8730";
|
|
2
|
+
export { M as default } from "./model-520a761c";
|
|
3
|
+
export { M as ModelSchemaProvider, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-7a58334b";
|
|
@@ -1900,8 +1900,8 @@ let HasManyReference = (_class$2 = class HasManyReference {
|
|
|
1900
1900
|
if (!hasRelationshipDataProperty) {
|
|
1901
1901
|
return false;
|
|
1902
1902
|
}
|
|
1903
|
-
|
|
1904
|
-
return
|
|
1903
|
+
const relationship = this.graph.getData(this.hasManyRelationship.identifier, this.key);
|
|
1904
|
+
return relationship.data?.every(identifier => {
|
|
1905
1905
|
return this.store._instanceCache.recordIsLoaded(identifier, true) === true;
|
|
1906
1906
|
});
|
|
1907
1907
|
}
|
|
@@ -2572,9 +2572,11 @@ function extractIdentifierFromRecord(record) {
|
|
|
2572
2572
|
return recordIdentifierFor(record);
|
|
2573
2573
|
}
|
|
2574
2574
|
function anyUnloaded(store, relationship) {
|
|
2575
|
-
|
|
2575
|
+
const graph = store._graph;
|
|
2576
|
+
const relationshipData = graph.getData(relationship.identifier, relationship.definition.key);
|
|
2577
|
+
const state = relationshipData.data;
|
|
2576
2578
|
const cache = store._instanceCache;
|
|
2577
|
-
const unloaded = state
|
|
2579
|
+
const unloaded = state?.find(s => {
|
|
2578
2580
|
let isLoaded = cache.recordIsLoaded(s, true);
|
|
2579
2581
|
return !isLoaded;
|
|
2580
2582
|
});
|
|
@@ -2883,7 +2885,7 @@ let RecordState = (_class3 = class RecordState {
|
|
|
2883
2885
|
getTag(this, key).notify();
|
|
2884
2886
|
}
|
|
2885
2887
|
updateInvalidErrors(errors) {
|
|
2886
|
-
assert(`Expected the Cache instance for ${this.identifier} to implement getErrors(identifier)`, typeof this.cache.getErrors === 'function');
|
|
2888
|
+
assert(`Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`, typeof this.cache.getErrors === 'function');
|
|
2887
2889
|
let jsonApiErrors = this.cache.getErrors(this.identifier);
|
|
2888
2890
|
errors.clear();
|
|
2889
2891
|
for (let i = 0; i < jsonApiErrors.length; i++) {
|