@ember-data/model 5.4.0-alpha.55 → 5.4.0-alpha.57
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-pLEGkRYp.js → has-many-BuTJfT5a.js} +1 -4
- package/addon/has-many-BuTJfT5a.js.map +1 -0
- package/addon/{hooks-BAZ34YZ_.js → hooks-BMoEt0SI.js} +1 -1
- package/addon/hooks-BMoEt0SI.js.map +1 -0
- package/addon/hooks.js +1 -1
- package/addon/index.js +3 -3
- package/addon/migration-support.js +1 -1
- package/addon/{model-8t1PguwE.js → model-DJ9C4aZ-.js} +82 -194
- package/addon/model-DJ9C4aZ-.js.map +1 -0
- package/addon/util-CSYkrwfb.js.map +1 -1
- package/package.json +21 -21
- package/unstable-preview-types/-private/attr.d.ts.map +1 -1
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -1
- package/unstable-preview-types/-private/many-array.d.ts.map +1 -1
- package/unstable-preview-types/-private/model-methods.d.ts +4 -4
- package/unstable-preview-types/-private/model-methods.d.ts.map +1 -1
- package/unstable-preview-types/-private/model.d.ts +1291 -96
- package/unstable-preview-types/-private/model.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -1
- package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -1
- package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -1
- package/addon/has-many-pLEGkRYp.js.map +0 -1
- package/addon/hooks-BAZ34YZ_.js.map +0 -1
- package/addon/model-8t1PguwE.js.map +0 -1
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, l as lookupLegacySupport } from "./model-
|
|
1
|
+
export { a as attr, b as belongsTo, h as hasMany } from "./has-many-BuTJfT5a";
|
|
2
|
+
export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, M as Model, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "./model-DJ9C4aZ-";
|
|
@@ -5,7 +5,7 @@ import { peekCache } from '@ember-data/store/-private';
|
|
|
5
5
|
import { i as isElementDescriptor, n as normalizeModelName } from "./util-CSYkrwfb";
|
|
6
6
|
import { macroCondition, getOwnConfig } from '@embroider/macros';
|
|
7
7
|
import { RecordStore } from '@warp-drive/core-types/symbols';
|
|
8
|
-
import { l as lookupLegacySupport } from "./model-
|
|
8
|
+
import { l as lookupLegacySupport } from "./model-DJ9C4aZ-";
|
|
9
9
|
import { dasherize } from '@ember/string';
|
|
10
10
|
import { singularize } from 'ember-inflector';
|
|
11
11
|
|
|
@@ -51,13 +51,10 @@ function _attr(type, options) {
|
|
|
51
51
|
if (currentValue !== value) {
|
|
52
52
|
cache.setAttr(identifier, key, value);
|
|
53
53
|
if (!this.isValid) {
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
55
54
|
const {
|
|
56
55
|
errors
|
|
57
56
|
} = this;
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
59
57
|
if (errors.get(key)) {
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
61
58
|
errors.remove(key);
|
|
62
59
|
this.currentState.cleanErrorRequests();
|
|
63
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-many-BuTJfT5a.js","sources":["../src/-private/attr.ts","../src/-private/belongs-to.ts","../src/-private/has-many.ts"],"sourcesContent":["/**\n @module @ember-data/model\n*/\nimport { assert } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { recordIdentifierFor } from '@ember-data/store';\nimport { peekCache } from '@ember-data/store/-private';\nimport { DEBUG } from '@warp-drive/build-config/env';\nimport type { ArrayValue, ObjectValue, PrimitiveValue, Value } from '@warp-drive/core-types/json/raw';\nimport type { TransformName } from '@warp-drive/core-types/symbols';\n\nimport type { Model } from './model';\nimport type { DecoratorPropertyDescriptor } from './util';\nimport { isElementDescriptor } from './util';\n\n/**\n * Options provided to the attr decorator are\n * supplied to the associated transform. Any\n * key-value pair is valid; however, it is highly\n * recommended to only use statically defined values\n * that could be serialized to JSON.\n *\n * If no transform is provided, the only valid\n * option is `defaultValue`.\n *\n * Examples:\n *\n * ```ts\n * class User extends Model {\n * @attr('string', { defaultValue: 'Anonymous' }) name;\n * @attr('date', { defaultValue: () => new Date() }) createdAt;\n * @attr({ defaultValue: () => ({}) }) preferences;\n * @attr('boolean') hasVerifiedEmail;\n * @attr address;\n * }\n *\n * @class NOTATHING\n * @typedoc\n */\nexport type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {\n /**\n * The default value for this attribute.\n *\n * Default values can be provided as a value or a function that will be\n * executed to generate the default value.\n *\n * Default values *should not* be stateful (object, arrays, etc.) as\n * they will be shared across all instances of the record.\n *\n * @typedoc\n */\n defaultValue?: DV extends PrimitiveValue ? DV : () => DV;\n};\n\nfunction _attr(type?: string | AttrOptions, options?: AttrOptions & object) {\n if (typeof type === 'object') {\n options = type;\n type = undefined;\n } else {\n options = options || {};\n }\n\n const meta = {\n type: type,\n kind: 'attribute',\n isAttribute: true,\n options: options,\n key: null,\n };\n\n return computed({\n get(this: Model, key: string) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\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(this: Model, key: string, value: Value) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\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 const identifier = recordIdentifierFor(this);\n assert(\n `Attempted to set '${key}' on the deleted record ${identifier.type}:${identifier.id} (${identifier.lid})`,\n !this.currentState.isDeleted\n );\n const cache = peekCache(this);\n\n const 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\n// NOTE: Usage of Explicit ANY\n// -------------------------------------------------------------------\n// any is required here because we are the maximal not the minimal\n// subset of options allowed. If we used unknown, object, or\n// Record<string, unknown> we would get type errors when we try to\n// assert against a more specific implementation with precise options.\n// -------------------------------------------------------------------\n\ntype LooseTransformInstance<V, Raw, Name extends string> = {\n /**\n * value type must match the return type of the deserialize method\n *\n * @typedoc\n */\n // see note on Explicit ANY above\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n serialize: (value: V, options: any) => Raw;\n /**\n * defaultValue type must match the return type of the deserialize method\n *\n * @typedoc\n */\n // see note on Explicit ANY above\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n deserialize: (value: Raw, options: any) => V;\n\n [TransformName]: Name;\n};\nexport type TransformHasType = { [TransformName]: string };\n\nexport type TypedTransformInstance<V, T extends string> =\n | LooseTransformInstance<V, string, T>\n | LooseTransformInstance<V, number, T>\n | LooseTransformInstance<V, boolean, T>\n | LooseTransformInstance<V, null, T>\n | LooseTransformInstance<V, ObjectValue, T>\n | LooseTransformInstance<V, ArrayValue, T>;\n\n// see note on Explicit ANY above\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type GetMaybeDeserializeValue<T> = T extends { deserialize: (...args: any[]) => unknown }\n ? ReturnType<T['deserialize']>\n : never;\n\nexport type TypeFromInstance<T> = T extends TransformHasType ? T[typeof TransformName] : never;\nexport type OptionsFromInstance<T> =\n TypeFromInstance<T> extends never\n ? never\n : GetMaybeDeserializeValue<T> extends never\n ? never\n : T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>\n ? Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>\n : never;\n\n/**\n * The return type of `void` is a lie to appease TypeScript. The actual return type\n * is a descriptor, but typescript incorrectly insists that decorator functions return\n * `void` or `any`.\n *\n * @typedoc\n */\nexport type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;\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 EmberData 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*/\nexport function attr(): DataDecorator;\nexport function attr<T>(type: TypeFromInstance<T>): DataDecorator;\nexport function attr(type: string): DataDecorator;\nexport function attr(options: AttrOptions): DataDecorator;\nexport function attr<T>(type: TypeFromInstance<T>, options?: OptionsFromInstance<T>): DataDecorator;\nexport function attr(type: string, options?: AttrOptions & object): DataDecorator;\nexport function attr(target: object, key: string | symbol, desc?: PropertyDescriptor): void; // see note on DataDecorator for why void\nexport function attr(\n type?: string | AttrOptions | object,\n options?: (AttrOptions & object) | string | symbol,\n desc?: PropertyDescriptor\n): DataDecorator | void {\n const args = [type, options, desc];\n // see note on DataDecorator for why void\n return isElementDescriptor(args) ? (_attr()(...args) as void) : _attr(type, options as object);\n}\n","import { assert, warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@warp-drive/build-config/env';\nimport type { TypeFromInstance } from '@warp-drive/core-types/record';\nimport { RecordStore } from '@warp-drive/core-types/symbols';\n\nimport { lookupLegacySupport } from './legacy-relationships-support';\nimport type { MinimalLegacyRecord } from './model-methods';\nimport { isElementDescriptor, normalizeModelName } from './util';\n/**\n @module @ember-data/model\n*/\n\nexport type IsUnknown<T> = unknown extends T ? true : false;\n\nexport type RelationshipOptions<T, Async extends boolean> = {\n async: Async;\n inverse: null | (IsUnknown<T> extends true ? string : keyof NoNull<T> & string);\n polymorphic?: boolean;\n as?: string;\n resetOnRemoteUpdate?: boolean;\n};\n\nexport type NoNull<T> = Exclude<T, null>;\n// type BelongsToDecoratorObject<getT> = {\n// get: () => getT;\n// // set: (value: Awaited<getT>) => void;\n// set: (value: getT) => void;\n// // init: () => getT;\n// };\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void; // BelongsToDecoratorObject<getT>;\n\nfunction _belongsTo<T, Async extends boolean>(\n type: string,\n options: RelationshipOptions<T, Async>\n): RelationshipDecorator<T> {\n assert(\n `Expected options.async from @belongsTo('${type}', options) to be a boolean`,\n options && typeof options.async === 'boolean'\n );\n assert(\n `Expected options.inverse from @belongsTo('${type}', options) to be either null or the string type of the related resource.`,\n options.inverse === null || (typeof options.inverse === 'string' && options.inverse.length > 0)\n );\n\n const meta = {\n type: normalizeModelName(type),\n isRelationship: true,\n options: options,\n kind: 'belongsTo',\n name: '<Unknown BelongsTo>',\n key: null,\n };\n\n return computed({\n get<R extends MinimalLegacyRecord>(this: R, key: string) {\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'].includes(key)) {\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(options, '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(options, '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<R extends MinimalLegacyRecord>(this: R, key: string, value: unknown) {\n const support = lookupLegacySupport(this);\n if (DEBUG) {\n if (['currentState'].includes(key)) {\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[RecordStore]._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta) as RelationshipDecorator<T>;\n}\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None\n relationships on a [Model](/ember-data/release/classes/Model).\n\n `belongsTo` takes a configuration hash as a second parameter, currently\n supported options are:\n\n - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.\n - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.\n - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic\n - `as`: (*optional*) A string used to declare the abstract type \"this\" record satisfies for polymorphism.\n\n ### Examples\n\n To declare a **one-to-many** (or many-to-many) relationship, use\n `belongsTo` in combination with `hasMany`:\n\n ```js\n // app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Comment extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n ```\n\n To declare a **one-to-one** relationship with managed inverses, use `belongsTo` for both sides:\n\n ```js\n // app/models/author.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Author extends Model {\n @belongsTo('address', { async: true, inverse: 'owner' }) address;\n }\n\n // app/models/address.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Address extends Model {\n @belongsTo('author', { async: true, inverse: 'address' }) owner;\n }\n ```\n\n To declare a **one-to-one** relationship without managed inverses, use `belongsTo` for both sides\n with `null` as the inverse:\n\n ```js\n // app/models/author.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Author extends Model {\n @belongsTo('address', { async: true, inverse: null }) address;\n }\n\n // app/models/address.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Address extends Model {\n @belongsTo('author', { async: true, inverse: null }) owner;\n }\n ```\n\n To declare a one-to-none relationship between two models, use\n `belongsTo` with inverse set to `null` on just one side::\n\n ```js\n // app/models/person.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Person extends Model {\n @belongsTo('person', { async: false, inverse: null }) bestFriend;\n }\n ```\n\n #### Sync vs Async Relationships\n\n EmberData fulfills relationships using resource data available in\n the cache.\n\n Sync relationships point directly to the known related resources.\n\n When a relationship is declared as async, if any of the known related\n resources have not been loaded, they will be fetched. The property\n on the record when accessed provides a promise that resolves once\n all resources are loaded.\n\n Async relationships may take advantage of links. On access, if the related\n link has not been loaded, or if any known resources are not available in\n the cache, the fresh state will be fetched using the link.\n\n In contrast to async relationship, accessing a sync relationship\n will error on access when any of the known related resources have\n not been loaded.\n\n If you are using `links` with sync relationships, you have to use\n the BelongsTo reference API to fetch or refresh related resources\n that aren't loaded. For instance, for a `bestFriend` relationship:\n\n ```js\n person.belongsTo('bestFriend').reload();\n ```\n\n #### Polymorphic Relationships\n\n To declare a polymorphic relationship, use `hasMany` with the `polymorphic`\n option set to `true`:\n\n ```js\n // app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Comment extends Model {\n @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;\n }\n ```\n\n `'commentable'` here is referred to as the \"abstract type\" for the polymorphic\n relationship.\n\n Polymorphic relationships with `inverse: null` will accept any type of record as their content.\n Polymorphic relationships with `inverse` set to a string will only accept records with a matching\n inverse relationships declaring itself as satisfying the abstract type.\n\n Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'\n for this relationship.\n\n ```js\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;\n }\n ```\n\n Note: every Model that declares an inverse to a polymorphic relationship must\n declare itself exactly the same. This is because polymorphism is based on structural\n traits.\n\n Polymorphic to polymorphic relationships are supported. Both sides of the relationship\n must be declared as polymorphic, and the `as` option must be used to declare the abstract\n type each record satisfies on both sides.\n\n @method belongsTo\n @public\n @static\n @for @ember-data/model\n @param {string} type (optional) the name of the related resource\n @param {object} options (optional) a hash of options\n @return {PropertyDescriptor} relationship\n*/\n\nexport function belongsTo(): never;\nexport function belongsTo(type: string): never;\nexport function belongsTo<T>(\n type: TypeFromInstance<NoNull<T>>,\n options: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T>;\n// export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(\n// type: TypeFromInstance<NoNull<T>>,\n// options: RelationshipOptions<T, true>\n// ): RelationshipDecorator<K>;\nexport function belongsTo(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;\nexport function belongsTo<T>(\n type?: TypeFromInstance<NoNull<T>>,\n options?: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T> {\n if (DEBUG) {\n assert(\n `belongsTo must be invoked with a type and options. Did you mean \\`@belongsTo(${type}, { async: false, inverse: null })\\`?`,\n !isElementDescriptor(arguments as unknown as unknown[])\n );\n }\n return _belongsTo(type!, options!);\n}\n","/**\n @module @ember-data/model\n*/\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 '@warp-drive/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/build-config/env';\nimport type { TypeFromInstance } from '@warp-drive/core-types/record';\nimport { RecordStore } from '@warp-drive/core-types/symbols';\n\nimport type { NoNull, RelationshipDecorator, RelationshipOptions } from './belongs-to';\nimport { lookupLegacySupport } from './legacy-relationships-support';\nimport type { MinimalLegacyRecord } from './model-methods';\nimport { isElementDescriptor } from './util';\n\nfunction normalizeType(type: string) {\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\nfunction _hasMany<T, Async extends boolean>(\n type: string,\n options: RelationshipOptions<T, Async>\n): RelationshipDecorator<T> {\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 const meta = {\n type: normalizeType(type),\n options,\n isRelationship: true,\n kind: 'hasMany',\n name: '<Unknown BelongsTo>',\n key: null,\n };\n\n return computed({\n get<R extends MinimalLegacyRecord>(this: R, key: string) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\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 [];\n }\n return lookupLegacySupport(this).getHasMany(key);\n },\n set<R extends MinimalLegacyRecord>(this: R, key: string, records: T[]) {\n if (DEBUG) {\n if (['currentState'].includes(key)) {\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[RecordStore]._join(() => {\n manyArray.splice(0, manyArray.length, ...records);\n });\n\n return support.getHasMany(key);\n },\n }).meta(meta);\n}\n\n/**\n `hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None\n relationships on a [Model](/ember-data/release/classes/Model).\n\n `hasMany` takes a configuration hash as a second parameter, currently\n supported options are:\n\n - `async`: (*required*) A boolean value used to declare whether this is a sync (false) or async (true) relationship.\n - `inverse`: (*required*) A string used to identify the inverse property on a related model, or `null`.\n - `polymorphic`: (*optional*) A boolean value to mark the relationship as polymorphic\n - `as`: (*optional*) A string used to declare the abstract type \"this\" record satisfies for polymorphism.\n\n ### Examples\n\n To declare a **many-to-one** (or one-to-many) relationship, use\n `belongsTo` in combination with `hasMany`:\n\n ```js\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post 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 Comment extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n ```\n\n To declare a **many-to-many** relationship with managed inverses, use `hasMany` for both sides:\n\n ```js\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post extends Model {\n @hasMany('tag', { async: true, inverse: 'posts' }) tags;\n }\n\n // app/models/tag.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Tag extends Model {\n @hasMany('post', { async: true, inverse: 'tags' }) posts;\n }\n ```\n\n To declare a **many-to-many** relationship without managed inverses, use `hasMany` for both sides\n with `null` as the inverse:\n\n ```js\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post extends Model {\n @hasMany('tag', { async: true, inverse: null }) tags;\n }\n\n // app/models/tag.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Tag extends Model {\n @hasMany('post', { async: true, inverse: null }) posts;\n }\n ```\n\n To declare a many-to-none relationship between two models, use\n `hasMany` with inverse set to `null` on just one side::\n\n ```js\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post extends Model {\n @hasMany('category', { async: true, inverse: null }) categories;\n }\n ```\n\n #### Sync vs Async Relationships\n\n EmberData fulfills relationships using resource data available in\n the cache.\n\n Sync relationships point directly to the known related resources.\n\n When a relationship is declared as async, if any of the known related\n resources have not been loaded, they will be fetched. The property\n on the record when accessed provides a promise that resolves once\n all resources are loaded.\n\n Async relationships may take advantage of links. On access, if the related\n link has not been loaded, or if any known resources are not available in\n the cache, the fresh state will be fetched using the link.\n\n In contrast to async relationship, accessing a sync relationship\n will error on access when any of the known related resources have\n not been loaded.\n\n If you are using `links` with sync relationships, you have to use\n the HasMany reference API to fetch or refresh related resources\n that aren't loaded. For instance, for a `comments` relationship:\n\n ```js\n post.hasMany('comments').reload();\n ```\n\n #### Polymorphic Relationships\n\n To declare a polymorphic relationship, use `hasMany` with the `polymorphic`\n option set to `true`:\n\n ```js\n // app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class Comment extends Model {\n @belongsTo('commentable', { async: false, inverse: 'comments', polymorphic: true }) parent;\n }\n ```\n\n `'commentable'` here is referred to as the \"abstract type\" for the polymorphic\n relationship.\n\n Polymorphic relationships with `inverse: null` will accept any type of record as their content.\n Polymorphic relationships with `inverse` set to a string will only accept records with a matching\n inverse relationships declaring itself as satisfying the abstract type.\n\n Below, 'as' is used to declare the that 'post' record satisfies the abstract type 'commentable'\n for this relationship.\n\n ```js\n // app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class Post extends Model {\n @hasMany('comment', { async: false, inverse: 'parent', as: 'commentable' }) comments;\n }\n ```\n\n Note: every Model that declares an inverse to a polymorphic relationship must\n declare itself exactly the same. This is because polymorphism is based on structural\n traits.\n\n Polymorphic to polymorphic relationships are supported. Both sides of the relationship\n must be declared as polymorphic, and the `as` option must be used to declare the abstract\n type each record satisfies on both sides.\n\n @method hasMany\n @public\n @static\n @for @ember-data/model\n @param {string} type (optional) the name of the related resource\n @param {object} options (optional) a hash of options\n @return {PropertyDescriptor} relationship\n*/\nexport function hasMany(): never;\nexport function hasMany(type: string): never;\nexport function hasMany<T>(\n type: TypeFromInstance<NoNull<T>>,\n options: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T>;\n// export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(\n// type: TypeFromInstance<NoNull<T>>,\n// options: RelationshipOptions<T, true>\n// ): RelationshipDecorator<K>;\nexport function hasMany(type: string, options: RelationshipOptions<unknown, boolean>): RelationshipDecorator<unknown>;\nexport function hasMany<T>(\n type?: TypeFromInstance<NoNull<T>>,\n options?: RelationshipOptions<T, boolean>\n): RelationshipDecorator<T> {\n if (DEBUG) {\n assert(\n `hasMany must be invoked with a type and options. Did you mean \\`@hasMany(${type}, { async: false, inverse: null })\\`?`,\n !isElementDescriptor(arguments as unknown as unknown[])\n );\n }\n return _hasMany(type!, options!);\n}\n"],"names":["_attr","type","options","undefined","meta","kind","isAttribute","key","computed","get","macroCondition","getOwnConfig","env","DEBUG","includes","Error","constructor","toString","isDestroyed","isDestroying","peekCache","getAttr","recordIdentifierFor","set","value","identifier","assert","id","lid","currentState","isDeleted","cache","currentValue","setAttr","isValid","errors","remove","cleanErrorRequests","attr","desc","args","isElementDescriptor","_belongsTo","async","inverse","length","normalizeModelName","isRelationship","name","support","lookupLegacySupport","Object","prototype","hasOwnProperty","call","warn","getBelongsTo","RecordStore","_join","setDirtyBelongsTo","belongsTo","arguments","normalizeType","deprecations","DEPRECATE_NON_STRICT_TYPES","result","singularize","dasherize","deprecate","until","for","since","available","enabled","_hasMany","getHasMany","records","manyArray","getManyArray","Array","isArray","splice","hasMany"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AAqDA,SAASA,KAAKA,CAACC,IAA2B,EAAEC,OAA8B,EAAE;AAC1E,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,MAAME,IAAI,GAAG;AACXH,IAAAA,IAAI,EAAEA,IAAI;AACVI,IAAAA,IAAI,EAAE,WAAW;AACjBC,IAAAA,WAAW,EAAE,IAAI;AACjBJ,IAAAA,OAAO,EAAEA,OAAO;AAChBK,IAAAA,GAAG,EAAE,IAAA;GACN,CAAA;AAED,EAAA,OAAOC,QAAQ,CAAC;IACdC,GAAGA,CAAcF,GAAW,EAAE;AAC5B,MAAA,IAAAG,cAAA,CAAAC,YAAA,GAAAC,GAAA,CAA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AAG,CAAC,CAAA;MACnD,IAAIyB,YAAY,KAAKR,KAAK,EAAE;QAC1BO,KAAK,CAACE,OAAO,CAACR,UAAU,EAAElB,GAAG,EAAEiB,KAAK,CAAC,CAAA;AAErC,QAAA,IAAI,CAAC,IAAI,CAACU,OAAO,EAAE;UACjB,MAAM;AAAEC,YAAAA,MAAAA;AAAO,WAAC,GAAG,IAAI,CAAA;AACvB,UAAA,IAAIA,MAAM,CAAC1B,GAAG,CAACF,GAAG,CAAC,EAAE;AACnB4B,YAAAA,MAAM,CAACC,MAAM,CAAC7B,GAAG,CAAC,CAAA;AAClB,YAAA,IAAI,CAACsB,YAAY,CAACQ,kBAAkB,EAAE,CAAA;AACxC,WAAA;AACF,SAAA;AACF,OAAA;AAEA,MAAA,OAAOb,KAAK,CAAA;AACd,KAAA;AACF,GAAC,CAAC,CAACpB,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgCA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAO6F;AACtF,SAASkC,IAAIA,CAClBrC,IAAoC,EACpCC,OAAkD,EAClDqC,IAAyB,EACH;EACtB,MAAMC,IAAI,GAAG,CAACvC,IAAI,EAAEC,OAAO,EAAEqC,I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Q,KAAK,CACZ,CAAA,CAAA,EAAGR,GAAI,CAAuI,qIAAA,EAAA,IAAI,CAACS,WAAW,CAACC,QAAQ,EAAG,EAC7K,CAAC,CAAA;AACH,SAAA;AACF,OAAA;AACA,MAAA,IAAI,CAACwC,WAAW,CAAC,CAACC,KAAK,CAAC,MAAM;AAC5BT,QAAAA,OAAO,CAACU,iBAAiB,CAACpD,GAAG,EAAEiB,KAAK,CAAC,CAAA;AACvC,OAAC,CAAC,CAAA;AAEF,MAAA,OAAOyB,OAAO,CAACO,YAAY,CAACjD,GAAG,CAAC,CAAA;AAClC,KAAA;AACF,GAAC,CAAC,CAACH,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;;AA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AAM2B,SAAS,GAAG5B,OAAO,CAAC6B,YAAY,CAACvE,GAAG,CAAC,CAAA;MAC3CmB,MAAM,CAAE,iEAAgE,EAAEqD,KAAK,CAACC,OAAO,CAACJ,OAAO,CAAC,CAAC,CAAA;AACjG,MAAA,IAAI,CAACnB,WAAW,CAAC,CAACC,KAAK,CAAC,MAAM;QAC5BmB,SAAS,CAACI,MAAM,CAAC,CAAC,EAAEJ,SAAS,CAAChC,MAAM,EAAE,GAAG+B,OAAO,CAAC,CAAA;AACnD,OAAC,CAAC,CAAA;AAEF,MAAA,OAAO3B,OAAO,CAAC0B,UAAU,CAACpE,GAAG,CAAC,CAAA;AAChC,KAAA;AACF,GAAC,CAAC,CAACH,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA;;AAEO,SAAS8E,OAAOA,CACrBjF,IAAkC,EAClCC,OAAyC,EACf;AAC1B,EAAA,IAAAQ,cAAA,CAAAC,YAAA,GAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;IACTa,MAAM,CACH,CAA2EzB,yEAAAA,EAAAA,IAAK,CAAsC,qCAAA,CAAA,EACvH,CAACwC,mBAAmB,CAACoB,SAAiC,CACxD,CAAC,CAAA;AACH,GAAA;AACA,EAAA,OAAOa,QAAQ,CAACzE,IAAI,EAAGC,OAAQ,CAAC,CAAA;AAClC;;;;"}
|
|
@@ -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 } from "./model-
|
|
4
|
+
import { M as Model } from "./model-DJ9C4aZ-";
|
|
5
5
|
import { n as normalizeModelName } from "./util-CSYkrwfb";
|
|
6
6
|
|
|
7
7
|
/*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-BMoEt0SI.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 ```ts\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 const owner = getOwner(store)!;\n const MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);\n const mixin = MaybeMixin && MaybeMixin.class;\n if (mixin) {\n const ModelForMixin = Model.extend(mixin) as unknown as { __isMixin: boolean; __mixin: typeof 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}`) as ModelFactory | undefined;\n}\n","import { getOwner } from '@ember/application';\n\nimport type Store from '@ember-data/store';\nimport type { FieldSchema } from '@ember-data/store/-types/q/schema-service';\nimport type { RecordIdentifier } from '@warp-drive/core-types/identifier';\nimport type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema';\n\nimport type { FactoryCache, Model, ModelFactory, ModelStore } 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 declare _fieldsDefCache: Record<string, Map<string, FieldSchema>>;\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 this._fieldsDefCache = Object.create(null) as Record<string, Map<string, FieldSchema>>;\n }\n\n fields(identifier: RecordIdentifier | { type: string }): Map<string, FieldSchema> {\n const { type } = identifier;\n let fieldDefs: Map<string, FieldSchema> | undefined = this._fieldsDefCache[type];\n\n if (fieldDefs === undefined) {\n fieldDefs = new Map();\n this._fieldsDefCache[type] = fieldDefs;\n\n const attributes = this.attributesDefinitionFor(identifier);\n const relationships = this.relationshipsDefinitionFor(identifier);\n\n for (const attr of Object.values(attributes)) {\n fieldDefs.set(attr.name, attr);\n }\n\n for (const rel of Object.values(relationships)) {\n fieldDefs.set(rel.name, rel);\n }\n }\n\n return fieldDefs;\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 const modelClass = this.store.modelFor(type);\n const 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 const 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 const klass = factory.class;\n\n if (klass.isModel) {\n const 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 { StableRecordIdentifier } from '@warp-drive/core-types';\nimport type { Cache } from '@warp-drive/core-types/cache';\nimport type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core-types/record';\n\nimport type { Model, ModelStore } 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<T>(type: TypeFromInstance<T>): typeof Model | void;\nexport function modelFor(type: string): typeof Model | void;\nexport function modelFor<T>(this: Store, modelName: TypeFromInstanceOrString<T>): typeof Model | void {\n assert(\n `Attempted to call store.modelFor(), but the store instance has already been destroyed.`,\n !this.isDestroyed && !this.isDestroying\n );\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","_fieldsDefCache","fields","identifier","type","fieldDefs","undefined","Map","attributes","attributesDefinitionFor","relationships","relationshipsDefinitionFor","attr","values","set","name","rel","modelClass","modelFor","attributeMap","forEach","meta","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","isDestroyed","isDestroying","length","maybeFactory","ignoreType","_forceShim","getSchemaDefinitionService","setRecordIdentifier","StoreMap","setCacheFor"],"mappings":";;;;;;AAMA;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,MAAMC,KAAK,GAAGC,QAAQ,CAACH,KAAK,CAAE,CAAA;EAC9B,MAAMI,UAAU,GAAGF,KAAK,CAACG,UAAU,CAAE,CAAA,MAAA,EAAQJ,mBAAoB,CAAA,CAAC,CAAC,CAAA;AACnE,EAAA,MAAMK,KAAK,GAAGF,UAAU,IAAIA,UAAU,CAACG,KAAK,CAAA;AAC5C,EAAA,IAAID,KAAK,EAAE;AACT,IAAA,MAAME,aAAa,GAAGC,KAAK,CAACC,MAAM,CAACJ,KAAK,CAA6D,CAAA;IACrGE,aAAa,CAACG,SAAS,GAAG,IAAI,CAAA;IAC9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0BAA0B,EAAE,CAACnC,aAAa,CAACnB,IAAI,CACtD,CAAC,CAAA;AACH,CAAA;AAEA,SAAS0C,UAAUA,CAACI,MAAa,EAAEpB,KAAY,EAAE3B,UAAkC,EAAEtB,KAAY,EAAQ;AACvG8E,EAAAA,mBAAmB,CAACT,MAAM,EAAE/C,UAAU,CAAC,CAAA;AACvCyD,EAAAA,QAAQ,CAAC9C,GAAG,CAACoC,MAAM,EAAErE,KAAK,CAAC,CAAA;AAC3BgF,EAAAA,WAAW,CAACX,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-BMoEt0SI";
|
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-BuTJfT5a";
|
|
2
|
+
export { M as default } from "./model-DJ9C4aZ-";
|
|
3
|
+
export { M as ModelSchemaProvider, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-BMoEt0SI";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert } from '@ember/debug';
|
|
2
2
|
import { recordIdentifierFor } from '@ember-data/store';
|
|
3
|
-
import { u as unloadRecord, s as serialize, b as save, r as rollbackAttributes, c as reload, h as hasMany, E as Errors, d as destroyRecord, e as deleteRecord, f as RecordState, g as changedAttributes, i as belongsTo, j as createSnapshot } from "./model-
|
|
3
|
+
import { u as unloadRecord, s as serialize, b as save, r as rollbackAttributes, c as reload, h as hasMany, E as Errors, d as destroyRecord, e as deleteRecord, f as RecordState, g as changedAttributes, i as belongsTo, j as createSnapshot } from "./model-DJ9C4aZ-";
|
|
4
4
|
// 'isDestroying', 'isDestroyed'
|
|
5
5
|
const LegacyFields = ['_createSnapshot', 'adapterError', 'belongsTo', 'changedAttributes', 'constructor', 'currentState', 'deleteRecord', 'destroyRecord', 'dirtyType', 'errors', 'hasDirtyAttributes', 'hasMany', 'isDeleted', 'isEmpty', 'isError', 'isLoaded', 'isLoading', 'isNew', 'isSaving', 'isValid', 'reload', 'rollbackAttributes', 'save', 'serialize', 'unloadRecord'];
|
|
6
6
|
const LegacySupport = new WeakMap();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, deprecate
|
|
1
|
+
import { assert, deprecate } from '@ember/debug';
|
|
2
2
|
import EmberObject, { computed, get } from '@ember/object';
|
|
3
3
|
import { recordIdentifierFor as recordIdentifierFor$1, storeFor as storeFor$1 } from '@ember-data/store';
|
|
4
4
|
import { RecordArray, MUTATE, SOURCE, recordIdentifierFor, ARRAY_SIGNAL, notifyArray, isStableIdentifier, storeFor, peekCache, fastPush, coerceId } from '@ember-data/store/-private';
|
|
@@ -3366,31 +3366,7 @@ function notifyErrorsStateChanged(state) {
|
|
|
3366
3366
|
state.notify('adapterError');
|
|
3367
3367
|
}
|
|
3368
3368
|
var _class, _Model;
|
|
3369
|
-
|
|
3370
|
-
const possibleRelationships = relationshipsSoFar || [];
|
|
3371
|
-
const relationshipMap = inverseType.relationships;
|
|
3372
|
-
if (!relationshipMap) {
|
|
3373
|
-
return possibleRelationships;
|
|
3374
|
-
}
|
|
3375
|
-
const relationshipsForType = relationshipMap.get(type.modelName);
|
|
3376
|
-
const relationships = Array.isArray(relationshipsForType) ? relationshipsForType.filter(relationship => {
|
|
3377
|
-
const optionsForRelationship = relationship.options;
|
|
3378
|
-
if (!optionsForRelationship.inverse && optionsForRelationship.inverse !== null) {
|
|
3379
|
-
return true;
|
|
3380
|
-
}
|
|
3381
|
-
return name === optionsForRelationship.inverse;
|
|
3382
|
-
}) : null;
|
|
3383
|
-
if (relationships) {
|
|
3384
|
-
possibleRelationships.push.apply(possibleRelationships, relationships);
|
|
3385
|
-
}
|
|
3386
|
-
|
|
3387
|
-
//Recurse to support polymorphism
|
|
3388
|
-
if (type.superclass) {
|
|
3389
|
-
findPossibleInverses(type.superclass, inverseType, name, possibleRelationships);
|
|
3390
|
-
}
|
|
3391
|
-
return possibleRelationships;
|
|
3392
|
-
}
|
|
3393
|
-
|
|
3369
|
+
// instantiateRecord as well.
|
|
3394
3370
|
/*
|
|
3395
3371
|
* This decorator allows us to lazily compute
|
|
3396
3372
|
* an expensive getter on first-access and thereafter
|
|
@@ -3398,6 +3374,7 @@ function findPossibleInverses(type, inverseType, name, relationshipsSoFar) {
|
|
|
3398
3374
|
*/
|
|
3399
3375
|
function computeOnce(target, propertyName, desc) {
|
|
3400
3376
|
const cache = new WeakMap();
|
|
3377
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
3401
3378
|
const getter = desc.get;
|
|
3402
3379
|
desc.get = function () {
|
|
3403
3380
|
let meta = cache.get(this);
|
|
@@ -3437,13 +3414,11 @@ function computeOnce(target, propertyName, desc) {
|
|
|
3437
3414
|
@extends Ember.EmberObject
|
|
3438
3415
|
*/
|
|
3439
3416
|
let Model = (_class = (_Model = class Model extends EmberObject {
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
}
|
|
3444
|
-
init(options = {}) {
|
|
3417
|
+
// set during create by the store
|
|
3418
|
+
|
|
3419
|
+
init(options) {
|
|
3445
3420
|
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
3446
|
-
if (!options
|
|
3421
|
+
if (!options?._secretInit && !options?._createProps) {
|
|
3447
3422
|
throw new Error('You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.');
|
|
3448
3423
|
}
|
|
3449
3424
|
}
|
|
@@ -3463,6 +3438,8 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
3463
3438
|
notifyChanges(identifier, type, field, this, store);
|
|
3464
3439
|
});
|
|
3465
3440
|
}
|
|
3441
|
+
|
|
3442
|
+
// @ts-expect-error destroy should not return a value
|
|
3466
3443
|
destroy() {
|
|
3467
3444
|
const identifier = recordIdentifierFor$1(this);
|
|
3468
3445
|
this.___recordState?.destroy();
|
|
@@ -3745,7 +3722,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
3745
3722
|
try {
|
|
3746
3723
|
return recordIdentifierFor$1(this).id;
|
|
3747
3724
|
} catch {
|
|
3748
|
-
return
|
|
3725
|
+
return null;
|
|
3749
3726
|
}
|
|
3750
3727
|
}
|
|
3751
3728
|
return recordIdentifierFor$1(this).id;
|
|
@@ -3880,6 +3857,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
3880
3857
|
to trigger their flush. We wouldn't need to
|
|
3881
3858
|
super in 4.0+ where sync observers are removed.
|
|
3882
3859
|
*/
|
|
3860
|
+
// @ts-expect-error no return is necessary
|
|
3883
3861
|
notifyPropertyChange(prop) {
|
|
3884
3862
|
notifySignal(this, prop);
|
|
3885
3863
|
super.notifyPropertyChange(prop);
|
|
@@ -4008,6 +3986,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4008
3986
|
@method _createSnapshot
|
|
4009
3987
|
@private
|
|
4010
3988
|
*/
|
|
3989
|
+
|
|
4011
3990
|
// TODO @deprecate in favor of a public API or examples of how to test successfully
|
|
4012
3991
|
|
|
4013
3992
|
/**
|
|
@@ -4184,7 +4163,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4184
4163
|
}
|
|
4185
4164
|
```
|
|
4186
4165
|
@method eachRelationship
|
|
4187
|
-
|
|
4166
|
+
@public
|
|
4188
4167
|
@param {Function} callback the callback to invoke
|
|
4189
4168
|
@param {any} binding the value to which the callback's `this` should be bound
|
|
4190
4169
|
*/
|
|
@@ -4257,8 +4236,8 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4257
4236
|
}
|
|
4258
4237
|
```
|
|
4259
4238
|
``` js
|
|
4260
|
-
store.modelFor('post').inverseFor('comments', store) // { type:
|
|
4261
|
-
store.modelFor('message').inverseFor('owner', store) // { type:
|
|
4239
|
+
store.modelFor('post').inverseFor('comments', store) // { type: 'message', name: 'owner', kind: 'belongsTo' }
|
|
4240
|
+
store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }
|
|
4262
4241
|
```
|
|
4263
4242
|
@method inverseFor
|
|
4264
4243
|
@public
|
|
@@ -4283,81 +4262,28 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4283
4262
|
static _findInverseFor(name, store) {
|
|
4284
4263
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4285
4264
|
const relationship = this.relationshipsByName.get(name);
|
|
4265
|
+
assert(`No relationship named '${name}' on '${this.modelName}' exists.`, relationship);
|
|
4266
|
+
if (!relationship) {
|
|
4267
|
+
return null;
|
|
4268
|
+
}
|
|
4286
4269
|
const {
|
|
4287
4270
|
options
|
|
4288
4271
|
} = relationship;
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
//If inverse is manually specified to be null, like `comments: hasMany('message', { inverse: null })`
|
|
4292
|
-
const isExplicitInverseNull = options.inverse === null;
|
|
4293
|
-
const isAbstractType = !isExplicitInverseNull && isPolymorphic && !store.getSchemaDefinitionService().doesTypeExist(relationship.type);
|
|
4294
|
-
if (isExplicitInverseNull || isAbstractType) {
|
|
4295
|
-
assert(`No schema for the abstract type '${relationship.type}' for the polymorphic relationship '${name}' on '${this.modelName}' was provided by the SchemaDefinitionService.`, !isPolymorphic || isExplicitInverseNull);
|
|
4272
|
+
assert(`Expected the relationship ${name} on ${this.modelName} to define an inverse.`, options.inverse === null || typeof options.inverse === 'string' && options.inverse.length > 0);
|
|
4273
|
+
if (options.inverse === null) {
|
|
4296
4274
|
return null;
|
|
4297
4275
|
}
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
//If inverse is specified manually, return the inverse
|
|
4303
|
-
if (options.inverse !== undefined) {
|
|
4304
|
-
fieldOnInverse = options.inverse;
|
|
4305
|
-
inverseRelationship = inverseSchema && inverseSchema.relationshipsByName.get(fieldOnInverse);
|
|
4306
|
-
assert(`We found no field named '${fieldOnInverse}' on the schema for '${inverseSchema.modelName}' to be the inverse of the '${name}' relationship on '${this.modelName}'. This is most likely due to a missing field on your model definition.`, inverseRelationship);
|
|
4307
|
-
|
|
4308
|
-
// TODO probably just return the whole inverse here
|
|
4309
|
-
inverseKind = inverseRelationship.kind;
|
|
4310
|
-
inverseOptions = inverseRelationship.options;
|
|
4311
|
-
} else {
|
|
4312
|
-
//No inverse was specified manually, we need to use a heuristic to guess one
|
|
4313
|
-
if (relationship.type === relationship.parentModelName) {
|
|
4314
|
-
warn(`Detected a reflexive relationship named '${name}' on the schema for '${relationship.type}' without an inverse option. Look at https://guides.emberjs.com/current/models/relationships/#toc_reflexive-relations for how to explicitly specify inverses.`, false, {
|
|
4315
|
-
id: 'ds.model.reflexive-relationship-without-inverse'
|
|
4316
|
-
});
|
|
4317
|
-
}
|
|
4318
|
-
let possibleRelationships = findPossibleInverses(this, inverseSchema, name);
|
|
4319
|
-
if (possibleRelationships.length === 0) {
|
|
4320
|
-
return null;
|
|
4321
|
-
}
|
|
4322
|
-
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
4323
|
-
const filteredRelationships = possibleRelationships.filter(possibleRelationship => {
|
|
4324
|
-
const optionsForRelationship = possibleRelationship.options;
|
|
4325
|
-
return name === optionsForRelationship.inverse;
|
|
4326
|
-
});
|
|
4327
|
-
assert("You defined the '" + name + "' relationship on " + this + ', but you defined the inverse relationships of type ' + inverseSchema.toString() + ' multiple times. Look at https://guides.emberjs.com/current/models/relationships/#toc_explicit-inverses for how to explicitly specify inverses', filteredRelationships.length < 2);
|
|
4328
|
-
}
|
|
4329
|
-
const explicitRelationship = possibleRelationships.find(relationship => relationship.options.inverse === name);
|
|
4330
|
-
if (explicitRelationship) {
|
|
4331
|
-
possibleRelationships = [explicitRelationship];
|
|
4332
|
-
}
|
|
4333
|
-
assert("You defined the '" + name + "' relationship on " + this + ', but multiple possible inverse relationships of type ' + this + ' were found on ' + inverseSchema + '. Look at https://guides.emberjs.com/current/models/relationships/#toc_explicit-inverses for how to explicitly specify inverses', possibleRelationships.length === 1);
|
|
4334
|
-
fieldOnInverse = possibleRelationships[0].name;
|
|
4335
|
-
inverseKind = possibleRelationships[0].kind;
|
|
4336
|
-
inverseOptions = possibleRelationships[0].options;
|
|
4337
|
-
}
|
|
4338
|
-
|
|
4339
|
-
// ensure inverse is properly configured
|
|
4340
|
-
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
4341
|
-
if (isPolymorphic) {
|
|
4342
|
-
assert(`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${fieldOnInverse}' on type '${inverseSchema.modelName}' is misconfigured.`, inverseOptions.as);
|
|
4343
|
-
assert(`options.as should match the expected type of the polymorphic relationship. Expected field '${fieldOnInverse}' on type '${inverseSchema.modelName}' to specify '${relationship.type}' but found '${inverseOptions.as}'`, !!inverseOptions.as && relationship.type === inverseOptions.as);
|
|
4344
|
-
}
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
// ensure we are properly configured
|
|
4348
|
-
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
4349
|
-
if (inverseOptions.polymorphic) {
|
|
4350
|
-
assert(`Relationships that satisfy polymorphic relationships MUST define which abstract-type they are satisfying using 'as'. The field '${name}' on type '${this.modelName}' is misconfigured.`, options.as);
|
|
4351
|
-
assert(`options.as should match the expected type of the polymorphic relationship. Expected field '${name}' on type '${this.modelName}' to specify '${inverseRelationship.type}' but found '${options.as}'`, !!options.as && inverseRelationship.type === options.as);
|
|
4352
|
-
}
|
|
4276
|
+
const schemaExists = store.schema.doesTypeExist(relationship.type);
|
|
4277
|
+
assert(`No associated schema found for '${relationship.type}' while calculating the inverse of ${name} on ${this.modelName}`, schemaExists);
|
|
4278
|
+
if (!schemaExists) {
|
|
4279
|
+
return null;
|
|
4353
4280
|
}
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
};
|
|
4281
|
+
const inverseSchemas = store.schema.relationshipsDefinitionFor({
|
|
4282
|
+
type: relationship.type
|
|
4283
|
+
});
|
|
4284
|
+
const inverseSchema = inverseSchemas[options.inverse];
|
|
4285
|
+
assert(`No inverse relationship found for '${name}' on '${this.modelName}'`, inverseSchema !== undefined);
|
|
4286
|
+
return inverseSchema || null;
|
|
4361
4287
|
}
|
|
4362
4288
|
|
|
4363
4289
|
/**
|
|
@@ -4446,7 +4372,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4446
4372
|
belongsTo: []
|
|
4447
4373
|
};
|
|
4448
4374
|
this.eachComputedProperty((name, meta) => {
|
|
4449
|
-
if (meta
|
|
4375
|
+
if (isRelationshipSchema(meta)) {
|
|
4450
4376
|
names[meta.kind].push(name);
|
|
4451
4377
|
}
|
|
4452
4378
|
});
|
|
@@ -4490,7 +4416,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4490
4416
|
const name = relationships[i];
|
|
4491
4417
|
const meta = rels[name];
|
|
4492
4418
|
const modelName = meta.type;
|
|
4493
|
-
if (types.
|
|
4419
|
+
if (!types.includes(modelName)) {
|
|
4494
4420
|
types.push(modelName);
|
|
4495
4421
|
}
|
|
4496
4422
|
}
|
|
@@ -4542,14 +4468,16 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4542
4468
|
const relationships = Object.create(null);
|
|
4543
4469
|
const modelName = this.modelName;
|
|
4544
4470
|
this.eachComputedProperty((name, meta) => {
|
|
4545
|
-
if (meta
|
|
4546
|
-
|
|
4547
|
-
meta.key = name;
|
|
4548
|
-
meta.name = name;
|
|
4549
|
-
meta.parentModelName = modelName;
|
|
4550
|
-
relationships[name] = meta;
|
|
4551
|
-
assert(`You should not specify both options.as and options.inverse as null on ${modelName}.${meta.name}, as if there is no inverse field there is no abstract type to conform to. You may have intended for this relationship to be polymorphic, or you may have mistakenly set inverse to null.`, !(meta.options.inverse === null && meta.options.as?.length > 0));
|
|
4471
|
+
if (!isRelationshipSchema(meta)) {
|
|
4472
|
+
return;
|
|
4552
4473
|
}
|
|
4474
|
+
// TODO deprecate key being here
|
|
4475
|
+
meta.key = name;
|
|
4476
|
+
meta.name = name;
|
|
4477
|
+
meta.parentModelName = modelName;
|
|
4478
|
+
relationships[name] = meta;
|
|
4479
|
+
assert(`Expected options in meta`, meta.options && typeof meta.options === 'object');
|
|
4480
|
+
assert(`You should not specify both options.as and options.inverse as null on ${modelName}.${meta.name}, as if there is no inverse field there is no abstract type to conform to. You may have intended for this relationship to be polymorphic, or you may have mistakenly set inverse to null.`, !(meta.options.inverse === null && meta.options.as?.length));
|
|
4553
4481
|
});
|
|
4554
4482
|
return relationships;
|
|
4555
4483
|
}
|
|
@@ -4590,9 +4518,9 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4590
4518
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4591
4519
|
const map = new Map();
|
|
4592
4520
|
this.eachComputedProperty((name, meta) => {
|
|
4593
|
-
if (meta
|
|
4521
|
+
if (isRelationshipSchema(meta)) {
|
|
4594
4522
|
map.set(name, meta.kind);
|
|
4595
|
-
} else if (meta
|
|
4523
|
+
} else if (isAttributeSchema(meta)) {
|
|
4596
4524
|
map.set(name, 'attribute');
|
|
4597
4525
|
}
|
|
4598
4526
|
});
|
|
@@ -4635,6 +4563,13 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4635
4563
|
callback.call(binding, type);
|
|
4636
4564
|
}
|
|
4637
4565
|
}
|
|
4566
|
+
|
|
4567
|
+
/**
|
|
4568
|
+
*
|
|
4569
|
+
* @method determineRelationshipType
|
|
4570
|
+
* @private
|
|
4571
|
+
* @deprecated
|
|
4572
|
+
*/
|
|
4638
4573
|
static determineRelationshipType(knownSide, store) {
|
|
4639
4574
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4640
4575
|
const knownKey = knownSide.name;
|
|
@@ -4689,7 +4624,7 @@ let Model = (_class = (_Model = class Model extends EmberObject {
|
|
|
4689
4624
|
assert(`Accessing schema information on Models without looking up the model via the store is disallowed.`, this.modelName);
|
|
4690
4625
|
const map = new Map();
|
|
4691
4626
|
this.eachComputedProperty((name, meta) => {
|
|
4692
|
-
if (meta
|
|
4627
|
+
if (isAttributeSchema(meta)) {
|
|
4693
4628
|
assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from " + this.toString(), name !== 'id');
|
|
4694
4629
|
|
|
4695
4630
|
// TODO deprecate key being here
|
|
@@ -4853,63 +4788,6 @@ defineSignal(Model.prototype, 'isReloading', false);
|
|
|
4853
4788
|
// the values initialized during create to `setUnknownProperty`
|
|
4854
4789
|
Model.prototype._createProps = null;
|
|
4855
4790
|
Model.prototype._secretInit = null;
|
|
4856
|
-
if (macroCondition(getOwnConfig().includeDataAdapter)) {
|
|
4857
|
-
/**
|
|
4858
|
-
Provides info about the model for debugging purposes
|
|
4859
|
-
by grouping the properties into more semantic groups.
|
|
4860
|
-
Meant to be used by debugging tools such as the Chrome Ember Extension.
|
|
4861
|
-
- Groups all attributes in "Attributes" group.
|
|
4862
|
-
- Groups all belongsTo relationships in "Belongs To" group.
|
|
4863
|
-
- Groups all hasMany relationships in "Has Many" group.
|
|
4864
|
-
- Groups all flags in "Flags" group.
|
|
4865
|
-
- Flags relationship CPs as expensive properties.
|
|
4866
|
-
@method _debugInfo
|
|
4867
|
-
@for Model
|
|
4868
|
-
@private
|
|
4869
|
-
*/
|
|
4870
|
-
Model.prototype._debugInfo = function () {
|
|
4871
|
-
const relationships = {};
|
|
4872
|
-
const expensiveProperties = [];
|
|
4873
|
-
const identifier = recordIdentifierFor$1(this);
|
|
4874
|
-
const schema = this.store.getSchemaDefinitionService();
|
|
4875
|
-
const attrDefs = schema.attributesDefinitionFor(identifier);
|
|
4876
|
-
const relDefs = schema.relationshipsDefinitionFor(identifier);
|
|
4877
|
-
const attributes = Object.keys(attrDefs);
|
|
4878
|
-
attributes.unshift('id');
|
|
4879
|
-
const groups = [{
|
|
4880
|
-
name: 'Attributes',
|
|
4881
|
-
properties: attributes,
|
|
4882
|
-
expand: true
|
|
4883
|
-
}];
|
|
4884
|
-
Object.keys(relDefs).forEach(name => {
|
|
4885
|
-
const relationship = relDefs[name];
|
|
4886
|
-
let properties = relationships[relationship.kind];
|
|
4887
|
-
if (properties === undefined) {
|
|
4888
|
-
properties = relationships[relationship.kind] = [];
|
|
4889
|
-
groups.push({
|
|
4890
|
-
name: relationship.kind,
|
|
4891
|
-
properties,
|
|
4892
|
-
expand: true
|
|
4893
|
-
});
|
|
4894
|
-
}
|
|
4895
|
-
properties.push(name);
|
|
4896
|
-
expensiveProperties.push(name);
|
|
4897
|
-
});
|
|
4898
|
-
groups.push({
|
|
4899
|
-
name: 'Flags',
|
|
4900
|
-
properties: ['isLoaded', 'hasDirtyAttributes', 'isSaving', 'isDeleted', 'isError', 'isNew', 'isValid']
|
|
4901
|
-
});
|
|
4902
|
-
return {
|
|
4903
|
-
propertyInfo: {
|
|
4904
|
-
// include all other mixins / properties (not just the grouped ones)
|
|
4905
|
-
includeOtherProperties: true,
|
|
4906
|
-
groups: groups,
|
|
4907
|
-
// don't pre-calculate unless cached
|
|
4908
|
-
expensiveProperties: expensiveProperties
|
|
4909
|
-
}
|
|
4910
|
-
};
|
|
4911
|
-
};
|
|
4912
|
-
}
|
|
4913
4791
|
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
4914
4792
|
const lookupDescriptor = function lookupDescriptor(obj, keyName) {
|
|
4915
4793
|
let current = obj;
|
|
@@ -4922,27 +4800,37 @@ if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
|
4922
4800
|
} while (current !== null);
|
|
4923
4801
|
return null;
|
|
4924
4802
|
};
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
}
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4803
|
+
|
|
4804
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
4805
|
+
const init = Model.prototype.init;
|
|
4806
|
+
Model.prototype.init = function (createArgs) {
|
|
4807
|
+
init.call(this, createArgs);
|
|
4808
|
+
const ourDescriptor = lookupDescriptor(Model.prototype, 'currentState');
|
|
4809
|
+
const theirDescriptor = lookupDescriptor(this, 'currentState');
|
|
4810
|
+
if (!ourDescriptor || !theirDescriptor) {
|
|
4811
|
+
throw new Error(`Unable to determine if 'currentState' is a reserved property name on instances of classes extending Model. Please ensure that 'currentState' is not defined as a property on ${this.constructor.toString()}`);
|
|
4812
|
+
}
|
|
4813
|
+
const realState = this.___recordState;
|
|
4814
|
+
if (ourDescriptor.get !== theirDescriptor.get || realState !== this.currentState) {
|
|
4815
|
+
throw new Error(`'currentState' is a reserved property name on instances of classes extending Model. Please choose a different property name for ${this.constructor.toString()}`);
|
|
4816
|
+
}
|
|
4817
|
+
const ID_DESCRIPTOR = lookupDescriptor(Model.prototype, 'id');
|
|
4818
|
+
const idDesc = lookupDescriptor(this, 'id');
|
|
4819
|
+
if (!ID_DESCRIPTOR || !idDesc) {
|
|
4820
|
+
throw new Error(`Unable to determine if 'id' is a reserved property name on instances of classes extending Model. Please ensure that 'id' is not defined as a property on ${this.constructor.toString()}`);
|
|
4821
|
+
}
|
|
4822
|
+
if (idDesc.get !== ID_DESCRIPTOR.get) {
|
|
4823
|
+
throw new Error(`You may not set 'id' as an attribute on your model. Please remove any lines that look like: \`id: attr('<type>')\` from ${this.constructor.toString()}`);
|
|
4939
4824
|
}
|
|
4940
|
-
});
|
|
4941
|
-
Model.reopen = function deprecatedReopen() {
|
|
4942
|
-
assert(`Model.reopen is deprecated. Use \`class Foo extends Model {}\` to extend your class instead.`);
|
|
4943
|
-
};
|
|
4944
|
-
Model.reopenClass = function deprecatedReopenClass() {
|
|
4945
|
-
assert(`Model.reopenClass is deprecated. Use \`class Foo extends Model {}\` to add static methods and properties to your class instead.`);
|
|
4946
4825
|
};
|
|
4826
|
+
delete Model.reopen;
|
|
4827
|
+
delete Model.reopenClass;
|
|
4828
|
+
}
|
|
4829
|
+
function isRelationshipSchema(meta) {
|
|
4830
|
+
const hasKind = typeof meta === 'object' && meta !== null && 'kind' in meta && 'options' in meta;
|
|
4831
|
+
return hasKind && (meta.kind === 'hasMany' || meta.kind === 'belongsTo');
|
|
4832
|
+
}
|
|
4833
|
+
function isAttributeSchema(meta) {
|
|
4834
|
+
return typeof meta === 'object' && meta !== null && 'kind' in meta && meta.kind === 'attribute';
|
|
4947
4835
|
}
|
|
4948
4836
|
export { Errors as E, LEGACY_SUPPORT as L, Model as M, PromiseBelongsTo as P, RelatedCollection as R, PromiseManyArray as a, save as b, reload as c, destroyRecord as d, deleteRecord as e, RecordState as f, changedAttributes as g, hasMany as h, belongsTo as i, createSnapshot as j, lookupLegacySupport as l, rollbackAttributes as r, serialize as s, unloadRecord as u };
|