@warp-drive/legacy 5.9.1 → 5.10.0-alpha.1
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/dist/{errors-BEEsrHbl.js → errors-CS110tMl.js} +9 -2
- package/dist/errors-CS110tMl.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +2 -2
- package/dist/model-62hn5_PD.d.ts.map +1 -1
- package/dist/{model-DcXZdNMu.js → model-DWH9f__L.js} +3 -3
- package/dist/{model-DcXZdNMu.js.map → model-DWH9f__L.js.map} +1 -1
- package/dist/model.js +2 -2
- package/dist/{schema-provider-H4zNXtry.js → schema-provider-DguGmQDS.js} +3 -7
- package/dist/schema-provider-DguGmQDS.js.map +1 -0
- package/dist/unpkg/dev/{compat-D48B8sXv.js → compat-BqmMZNci.js} +2 -2
- package/dist/unpkg/dev/{compat-D48B8sXv.js.map → compat-BqmMZNci.js.map} +1 -1
- package/dist/unpkg/dev/compat.js +1 -1
- package/dist/unpkg/dev/{errors-8GnRWcxo.js → errors-DnzvLM2A.js} +9 -2
- package/dist/unpkg/dev/errors-DnzvLM2A.js.map +1 -0
- package/dist/unpkg/dev/index.js +4 -2
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/dev/model/-private.js +1 -1
- package/dist/unpkg/dev/model/migration-support.js +2 -2
- package/dist/unpkg/dev/{model-LK7ethC5.js → model-BxPIR7m2.js} +3 -3
- package/dist/unpkg/dev/{model-LK7ethC5.js.map → model-BxPIR7m2.js.map} +1 -1
- package/dist/unpkg/dev/model.js +2 -2
- package/dist/unpkg/dev/{schema-provider-CRzoMoTO.js → schema-provider-CI_a48ja.js} +3 -7
- package/dist/unpkg/dev/schema-provider-CI_a48ja.js.map +1 -0
- package/dist/unpkg/dev-deprecated/{compat-DGSurLh7.js → compat-D_T7cGfd.js} +2 -2
- package/dist/unpkg/dev-deprecated/{compat-DGSurLh7.js.map → compat-D_T7cGfd.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/compat.js +1 -1
- package/dist/unpkg/dev-deprecated/{errors-0ydn94s0.js → errors-jHQESeNQ.js} +9 -2
- package/dist/unpkg/dev-deprecated/errors-jHQESeNQ.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +4 -2
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/model/migration-support.js +2 -2
- package/dist/unpkg/dev-deprecated/{model-C1ts6Mod.js → model-CdGKb7bA.js} +3 -3
- package/dist/unpkg/dev-deprecated/{model-C1ts6Mod.js.map → model-CdGKb7bA.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/model.js +2 -2
- package/dist/unpkg/dev-deprecated/{schema-provider-D2ESMsA8.js → schema-provider-C9wc6vGC.js} +3 -7
- package/dist/unpkg/dev-deprecated/schema-provider-C9wc6vGC.js.map +1 -0
- package/dist/unpkg/prod/{errors-CVXWrUjP.js → errors-DQDfNqVx.js} +9 -2
- package/dist/unpkg/prod/errors-DQDfNqVx.js.map +1 -0
- package/dist/unpkg/prod/index.js +3 -1
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod/model/-private.js +1 -1
- package/dist/unpkg/prod/model/migration-support.js +2 -2
- package/dist/unpkg/prod/{model-D3WMsNNE.js → model-CYMA-e_S.js} +3 -3
- package/dist/unpkg/prod/{model-D3WMsNNE.js.map → model-CYMA-e_S.js.map} +1 -1
- package/dist/unpkg/prod/model.js +2 -2
- package/dist/unpkg/prod/{schema-provider-_pimTZ3P.js → schema-provider-05U1H-Kl.js} +3 -7
- package/dist/unpkg/prod/schema-provider-05U1H-Kl.js.map +1 -0
- package/dist/unpkg/prod-deprecated/{errors-9LXqpfRd.js → errors-ii4L43_1.js} +9 -2
- package/dist/unpkg/prod-deprecated/errors-ii4L43_1.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +3 -1
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/model/migration-support.js +2 -2
- package/dist/unpkg/prod-deprecated/{model-aiVrr1fz.js → model-D3oCPHtM.js} +3 -3
- package/dist/unpkg/prod-deprecated/{model-aiVrr1fz.js.map → model-D3oCPHtM.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/model.js +2 -2
- package/dist/unpkg/prod-deprecated/{schema-provider-DyfSd9Cv.js → schema-provider-CKH_bnnS.js} +3 -7
- package/dist/unpkg/prod-deprecated/schema-provider-CKH_bnnS.js.map +1 -0
- package/package.json +7 -7
- package/dist/errors-BEEsrHbl.js.map +0 -1
- package/dist/schema-provider-H4zNXtry.js.map +0 -1
- package/dist/unpkg/dev/errors-8GnRWcxo.js.map +0 -1
- package/dist/unpkg/dev/schema-provider-CRzoMoTO.js.map +0 -1
- package/dist/unpkg/dev-deprecated/errors-0ydn94s0.js.map +0 -1
- package/dist/unpkg/dev-deprecated/schema-provider-D2ESMsA8.js.map +0 -1
- package/dist/unpkg/prod/errors-CVXWrUjP.js.map +0 -1
- package/dist/unpkg/prod/schema-provider-_pimTZ3P.js.map +0 -1
- package/dist/unpkg/prod-deprecated/errors-9LXqpfRd.js.map +0 -1
- package/dist/unpkg/prod-deprecated/schema-provider-DyfSd9Cv.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-D3WMsNNE.js","names":["computed","recordIdentifierFor","RecordStore","isElementDescriptor","_attr","type","options","undefined","meta","kind","isAttribute","sourceKey","key","get","isDestroyed","isDestroying","cache","getAttr","set","value","identifier","cacheKey","currentValue","setAttr","isValid","errors","remove","currentState","cleanErrorRequests","attr","desc","args","computed","assertPrivateStore","RecordStore","lookupLegacySupport","isElementDescriptor","normalizeModelName","_belongsTo","type","options","meta","kind","name","sourceKey","get","key","isDestroying","isDestroyed","support","getBelongsTo","set","value","_join","setDirtyBelongsTo","belongsTo","computed","assertPrivateStore","RecordStore","dasherize","singularize","lookupLegacySupport","isElementDescriptor","normalizeType","type","_hasMany","options","meta","kind","name","sourceKey","get","key","isDestroying","isDestroyed","getHasMany","set","records","support","manyArray","getManyArray","_join","splice","length","hasMany","getOwner","setOwner","assertPrivateStore","setRecordIdentifier","StoreMap","getModelFactory","normalizeModelName","recast","context","instantiateRecord","identifier","createRecordArgs","type","createOptions","_createProps","_secretInit","store","cb","secretInit","factory","class","create","teardownRecord","record","destroy","modelFor","modelName","maybeFactory","klass","ignoreType","isModel","_forceShim","set"],"sources":["../../../src/model/-private/attr.ts","../../../src/model/-private/belongs-to.ts","../../../src/model/-private/has-many.ts","../../../src/model/-private/hooks.ts"],"sourcesContent":["import { computed } from '@ember/object';\n\nimport { recordIdentifierFor } from '@warp-drive/core';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ArrayValue, ObjectValue, PrimitiveValue, Value } from '@warp-drive/core/types/json/raw';\nimport { RecordStore, type TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { Transform } from '../../serializer/transform.ts';\nimport type { Model } from './model.ts';\nimport type { DecoratorPropertyDescriptor } from './util.ts';\nimport { isElementDescriptor } from './util.ts';\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 */\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 */\n defaultValue?: DV extends PrimitiveValue ? DV : () => DV;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * attributes: {\n * 'first-name': 'Chris'\n * }\n * }\n * ```\n *\n * But the app desires to use `record.firstName; // 'Chris'`, then the\n * property should be named `firstName` and `sourceKey` should be set\n * to `'first-name'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\n};\n\nfunction _attr(type?: string | AttrOptions, options?: AttrOptions) {\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 sourceKey: options.sourceKey,\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 const cache = this[RecordStore].cache;\n return cache.getAttr(recordIdentifierFor(this), meta.sourceKey ?? 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 = this[RecordStore].cache;\n const cacheKey = meta.sourceKey ?? key;\n\n const currentValue = cache.getAttr(identifier, cacheKey);\n if (currentValue !== value) {\n cache.setAttr(identifier, cacheKey, value);\n\n if (!this.isValid) {\n const { errors } = this;\n\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 */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/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 */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/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 | LooseTransformInstance<V, string | null, T>\n | LooseTransformInstance<V, number | null, T>\n | LooseTransformInstance<V, boolean | null, T>\n | LooseTransformInstance<V, ObjectValue | null, T>\n | LooseTransformInstance<V, ArrayValue | null, T>;\n\n// see note on Explicit ANY above\n// oxlint-disable-next-line typescript/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 ExtractOptions<T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>> =\n Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>;\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 */\nexport type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;\n\n/**\n `attr` defines an attribute on a {@link 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 WarpDrive ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n {@link 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 ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/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 ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/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 ```js [app/models/post.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```js [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 @public\n @param type the attribute type\n @param options a hash of options\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 { warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\n\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor, normalizeModelName } from './util.ts';\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 linksMode?: true;\n resetOnRemoteUpdate?: boolean;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * relationships: {\n * 'best-friend': { data: { type: 'user', id: '1' } }\n * }\n * }\n * ```\n *\n * But the app desires to use `record.bestFriend`, then the property\n * should be named `bestFriend` and `sourceKey` should be set to\n * `'best-friend'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\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// oxlint-disable-next-line 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 options: options,\n kind: 'belongsTo',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\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 assert(`Cannot set belongsTo relationship ${key} on a destroyed record`, !this.isDestroying && !this.isDestroyed);\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\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 assertPrivateStore(this[RecordStore]);\n this[RecordStore]._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None\n relationships on a {@link 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 WarpDrive 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 @public\n @param type the name of the related resource\n @param options a hash of options\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","import { deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\nimport { dasherize, singularize } from '@warp-drive/utilities/string';\n\nimport type { NoNull, RelationshipDecorator, RelationshipOptions } from './belongs-to.ts';\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor } from './util.ts';\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: '4.13',\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 kind: 'hasMany',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\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\n assertPrivateStore(this[RecordStore]);\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 {@link 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 WarpDrive 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 @public\n @param type the name of the related resource\n @param options a hash of options\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","import { getOwner, setOwner } from '@ember/application';\n\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore, setRecordIdentifier, type Store, StoreMap } from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core/types/record';\n\nimport type { Model, ModelStore } from './model.ts';\nimport { getModelFactory } from './schema-provider.ts';\nimport { normalizeModelName } from './util.ts';\n\nfunction recast(context: Store): asserts context is ModelStore {}\n\n/**\n * The `instantiateRecord` hook implementation for use with `Model`. Pass\n * this to your store's `instantiateRecord` method when configuring the\n * store to use `Model` for schema/record instantiation.\n *\n * @public\n */\nexport function instantiateRecord(\n this: Store,\n identifier: ResourceKey,\n createRecordArgs?: { [key: string]: unknown }\n): Model {\n const type = identifier.type;\n\n recast(this);\n\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 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\n/**\n * The `teardownRecord` hook implementation for use with `Model`. Pass this\n * to your store's `teardownRecord` method when configuring the store to\n * use `Model` for schema/record instantiation.\n *\n * @public\n */\nexport function teardownRecord(record: Model): void {\n assert(\n `expected to receive an instance of Model from @warp-drive/legacy/model. If using a custom model make sure you implement teardownRecord`,\n 'destroy' in record\n );\n record.destroy();\n}\n\n/**\n * The `modelFor` implementation for use with `Model`, exposed on the store\n * as `store.modelFor(type)` when the store is configured to use `Model`.\n * Returns the `Model` subclass registered for the given type, if any.\n *\n * @public\n */\nexport function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;\n/**\n * Overload accepting a raw type string instead of a typed record instance.\n *\n * @public\n */\nexport function modelFor(type: string): typeof Model | void;\nexport function modelFor<T>(this: Store, modelName: TypeFromInstanceOrString<T>): typeof Model | void {\n assertPrivateStore(this);\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(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n}\n\nfunction secretInit(record: Model, identifier: ResourceKey, store: Store): void {\n setRecordIdentifier(record, identifier);\n StoreMap.set(record, store);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;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CAC9Eb,oBAAoBoB,QAAQb,UAAU;CACtCN,SAAS4B,IAAIT,QAAQP,KAAK;AAC5B"}
|
|
1
|
+
{"version":3,"file":"model-CYMA-e_S.js","names":["computed","recordIdentifierFor","RecordStore","isElementDescriptor","_attr","type","options","undefined","meta","kind","isAttribute","sourceKey","key","get","isDestroyed","isDestroying","cache","getAttr","set","value","identifier","cacheKey","currentValue","setAttr","isValid","errors","remove","currentState","cleanErrorRequests","attr","desc","args","computed","assertPrivateStore","RecordStore","lookupLegacySupport","isElementDescriptor","normalizeModelName","_belongsTo","type","options","meta","kind","name","sourceKey","get","key","isDestroying","isDestroyed","support","getBelongsTo","set","value","_join","setDirtyBelongsTo","belongsTo","computed","assertPrivateStore","RecordStore","dasherize","singularize","lookupLegacySupport","isElementDescriptor","normalizeType","type","_hasMany","options","meta","kind","name","sourceKey","get","key","isDestroying","isDestroyed","getHasMany","set","records","support","manyArray","getManyArray","_join","splice","length","hasMany","getOwner","setOwner","assertPrivateStore","setRecordIdentifier","StoreMap","getModelFactory","normalizeModelName","recast","context","instantiateRecord","identifier","createRecordArgs","type","createOptions","_createProps","_secretInit","store","cb","secretInit","factory","class","create","teardownRecord","record","destroy","modelFor","modelName","maybeFactory","klass","ignoreType","isModel","_forceShim","set"],"sources":["../../../src/model/-private/attr.ts","../../../src/model/-private/belongs-to.ts","../../../src/model/-private/has-many.ts","../../../src/model/-private/hooks.ts"],"sourcesContent":["import { computed } from '@ember/object';\n\nimport { recordIdentifierFor } from '@warp-drive/core';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { ArrayValue, ObjectValue, PrimitiveValue, Value } from '@warp-drive/core/types/json/raw';\nimport { RecordStore, type TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { Transform } from '../../serializer/transform.ts';\nimport type { Model } from './model.ts';\nimport type { DecoratorPropertyDescriptor } from './util.ts';\nimport { isElementDescriptor } from './util.ts';\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 */\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 */\n defaultValue?: DV extends PrimitiveValue ? DV : () => DV;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * attributes: {\n * 'first-name': 'Chris'\n * }\n * }\n * ```\n *\n * But the app desires to use `record.firstName; // 'Chris'`, then the\n * property should be named `firstName` and `sourceKey` should be set\n * to `'first-name'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\n};\n\nfunction _attr(type?: string | AttrOptions, options?: AttrOptions) {\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 sourceKey: options.sourceKey,\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 const cache = this[RecordStore].cache;\n return cache.getAttr(recordIdentifierFor(this), meta.sourceKey ?? 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 = this[RecordStore].cache;\n const cacheKey = meta.sourceKey ?? key;\n\n const currentValue = cache.getAttr(identifier, cacheKey);\n if (currentValue !== value) {\n cache.setAttr(identifier, cacheKey, value);\n\n if (!this.isValid) {\n const { errors } = this;\n\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 */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/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 */\n // see note on Explicit ANY above\n // oxlint-disable-next-line typescript/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 | LooseTransformInstance<V, string | null, T>\n | LooseTransformInstance<V, number | null, T>\n | LooseTransformInstance<V, boolean | null, T>\n | LooseTransformInstance<V, ObjectValue | null, T>\n | LooseTransformInstance<V, ArrayValue | null, T>;\n\n// see note on Explicit ANY above\n// oxlint-disable-next-line typescript/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 ExtractOptions<T extends TypedTransformInstance<GetMaybeDeserializeValue<T>, TypeFromInstance<T>>> =\n Parameters<T['deserialize']>[1] & Parameters<T['serialize']>[1] & AttrOptions<ReturnType<T['deserialize']>>;\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 */\nexport type DataDecorator = (target: object, key: string, desc?: DecoratorPropertyDescriptor) => void;\n\n/**\n `attr` defines an attribute on a {@link 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 WarpDrive ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n {@link 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 ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/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 ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/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 ```js [app/models/post.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```js [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 @public\n @param type the attribute type\n @param options a hash of options\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 { warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\n\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor, normalizeModelName } from './util.ts';\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 linksMode?: true;\n resetOnRemoteUpdate?: boolean;\n\n /**\n * The name of the field as returned by the API and inserted into the\n * cache if it differs from the name of the decorated property.\n *\n * For instance, if the API returns:\n *\n * ```ts\n * {\n * relationships: {\n * 'best-friend': { data: { type: 'user', id: '1' } }\n * }\n * }\n * ```\n *\n * But the app desires to use `record.bestFriend`, then the property\n * should be named `bestFriend` and `sourceKey` should be set to\n * `'best-friend'`.\n *\n * This option is only needed when the value differs from the property name.\n */\n sourceKey?: string;\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// oxlint-disable-next-line 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 options: options,\n kind: 'belongsTo',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\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 assert(`Cannot set belongsTo relationship ${key} on a destroyed record`, !this.isDestroying && !this.isDestroyed);\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\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 assertPrivateStore(this[RecordStore]);\n this[RecordStore]._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None\n relationships on a {@link 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 WarpDrive 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 @public\n @param type the name of the related resource\n @param options a hash of options\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","import { deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@warp-drive/core/build-config/deprecations';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { TypeFromInstance } from '@warp-drive/core/types/record';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\nimport { dasherize, singularize } from '@warp-drive/utilities/string';\n\nimport type { NoNull, RelationshipDecorator, RelationshipOptions } from './belongs-to.ts';\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\n// oxlint-disable-next-line no-unused-vars\nimport type { Model } from './model.ts';\nimport { isElementDescriptor } from './util.ts';\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: '4.13',\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 kind: 'hasMany',\n name: '<Unknown BelongsTo>',\n sourceKey: options.sourceKey,\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\n assertPrivateStore(this[RecordStore]);\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 {@link 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 WarpDrive 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 '@warp-drive/legacy/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 '@warp-drive/legacy/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 @public\n @param type the name of the related resource\n @param options a hash of options\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","import { getOwner, setOwner } from '@ember/application';\n\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore, setRecordIdentifier, type Store, StoreMap } from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { TypeFromInstance, TypeFromInstanceOrString } from '@warp-drive/core/types/record';\n\nimport type { Model, ModelStore } from './model.ts';\nimport { getModelFactory } from './schema-provider.ts';\nimport { normalizeModelName } from './util.ts';\n\nfunction recast(context: Store): asserts context is ModelStore {}\n\n/**\n * The `instantiateRecord` hook implementation for use with `Model`. Pass\n * this to your store's `instantiateRecord` method when configuring the\n * store to use `Model` for schema/record instantiation.\n *\n * @public\n */\nexport function instantiateRecord(\n this: Store,\n identifier: ResourceKey,\n createRecordArgs?: { [key: string]: unknown }\n): Model {\n const type = identifier.type;\n\n recast(this);\n\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 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\n/**\n * The `teardownRecord` hook implementation for use with `Model`. Pass this\n * to your store's `teardownRecord` method when configuring the store to\n * use `Model` for schema/record instantiation.\n *\n * @public\n */\nexport function teardownRecord(record: Model): void {\n assert(\n `expected to receive an instance of Model from @warp-drive/legacy/model. If using a custom model make sure you implement teardownRecord`,\n 'destroy' in record\n );\n record.destroy();\n}\n\n/**\n * The `modelFor` implementation for use with `Model`, exposed on the store\n * as `store.modelFor(type)` when the store is configured to use `Model`.\n * Returns the `Model` subclass registered for the given type, if any.\n *\n * @public\n */\nexport function modelFor<T>(type: TypeFromInstance<T>): typeof Model | void;\n/**\n * Overload accepting a raw type string instead of a typed record instance.\n *\n * @public\n */\nexport function modelFor(type: string): typeof Model | void;\nexport function modelFor<T>(this: Store, modelName: TypeFromInstanceOrString<T>): typeof Model | void {\n assertPrivateStore(this);\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(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n}\n\nfunction secretInit(record: Model, identifier: ResourceKey, store: Store): void {\n setRecordIdentifier(record, identifier);\n StoreMap.set(record, store);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,SAASI,MAAMC,MAA6BC,SAAuB;CACjE,IAAI,OAAOD,SAAS,UAAU;EAC5BC,UAAUD;EACVA,OAAOE;CACT,OACED,UAAUA,WAAW,CAAC;CAGxB,MAAME,OAAO;EACLH;EACNI,MAAM;EACNC,aAAa;EACJJ;EACTK,WAAWL,QAAQK;EACnBC,KAAK;CACP;CAEA,OAAOZ,SAAS;EACda,IAAiBD,KAAa;GAQ5B,IAAI,KAAKE,eAAe,KAAKC,cAC3B;GAGF,OADc,KAAKb,YAAY,CAACc,MACnBC,QAAQhB,oBAAoB,IAAI,GAAGO,KAAKG,aAAaC,GAAG;EACvE;EACAM,IAAiBN,KAAaO,OAAc;GAQ1C,MAAMC,aAAanB,oBAAoB,IAAI;GAK3C,MAAMe,QAAQ,KAAKd,YAAY,CAACc;GAChC,MAAMK,WAAWb,KAAKG,aAAaC;GAGnC,IADqBI,MAAMC,QAAQG,YAAYC,QAC3CC,MAAiBH,OAAO;IAC1BH,MAAMO,QAAQH,YAAYC,UAAUF,KAAK;IAEzC,IAAI,CAAC,KAAKK,SAAS;KACjB,MAAM,EAAEC,WAAW;KAEnB,IAAIA,OAAOZ,IAAID,GAAG,GAAG;MACnBa,OAAOC,OAAOd,GAAG;MACjB,KAAKe,aAAaC,mBAAmB;KACvC;IACF;GACF;GAEA,OAAOT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;;;;;;;AASA,SAAgBS,eAAeC,QAAqB;CAKlDA,OAAOC,QAAQ;AACjB;;;;;;;;;;;;;AAgBA,SAAgBC,SAAyBC,WAA6D;CACpGxB,mBAAmB,IAAI;CAYvB,MAAMU,OAAON,mBAAmBoB,SAAS;CACzC,MAAMC,eAAetB,gBAAgB,MAAMO,IAAI;CAC/C,MAAMgB,QAAQD,gBAAgBA,aAAaP,QAAQO,aAAaP,QAAQ;CAGxE,IAAI,EADe,CAACQ,SAAS,CAACA,MAAME,WAAW,KAAKC,aAElD,OAAOH;AAGX;AAEA,SAASV,WAAWK,QAAeb,YAAyBM,OAAoB;CAC9Eb,oBAAoBoB,QAAQb,UAAU;CACtCN,SAAS4B,IAAIT,QAAQP,KAAK;AAC5B"}
|
package/dist/unpkg/prod/model.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as belongsTo, i as hasMany, n as modelFor, o as attr, r as teardownRecord, t as instantiateRecord } from "./model-
|
|
2
|
-
import { i as restoreDeprecatedModelRequestBehaviors, r as Model, t as buildSchema } from "./schema-provider-
|
|
1
|
+
import { a as belongsTo, i as hasMany, n as modelFor, o as attr, r as teardownRecord, t as instantiateRecord } from "./model-CYMA-e_S.js";
|
|
2
|
+
import { i as restoreDeprecatedModelRequestBehaviors, r as Model, t as buildSchema } from "./schema-provider-05U1H-Kl.js";
|
|
3
3
|
|
|
4
4
|
export { Model, Model as default, attr, belongsTo, buildSchema, hasMany, instantiateRecord, modelFor, restoreDeprecatedModelRequestBehaviors, teardownRecord };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as FetchManager, t as upgradeStore } from "./-private-SfXkkHKd.js";
|
|
2
2
|
import { n as normalizeModelName } from "./util-dSKEgQDp.js";
|
|
3
|
-
import { n as LEGACY_SUPPORT, r as lookupLegacySupport, t as Errors } from "./errors-
|
|
3
|
+
import { i as releaseLegacySupport, n as LEGACY_SUPPORT, r as lookupLegacySupport, t as Errors } from "./errors-DQDfNqVx.js";
|
|
4
4
|
import { n as decorateMethodV2 } from "./runtime--fcdnjmJ-DMTJ0Kb3.js";
|
|
5
5
|
import { recordIdentifierFor, storeFor } from "@warp-drive/core";
|
|
6
6
|
import { getOwner } from "@ember/application";
|
|
@@ -508,11 +508,7 @@ var Model = class extends EmberObject {
|
|
|
508
508
|
const identifier = recordIdentifierFor(this);
|
|
509
509
|
this.___recordState?.destroy();
|
|
510
510
|
storeFor(this, false).notifications.unsubscribe(this.___private_notifications);
|
|
511
|
-
|
|
512
|
-
if (support) {
|
|
513
|
-
support.destroy();
|
|
514
|
-
LEGACY_SUPPORT.delete(identifier);
|
|
515
|
-
}
|
|
511
|
+
releaseLegacySupport(identifier);
|
|
516
512
|
super.destroy();
|
|
517
513
|
}
|
|
518
514
|
/**
|
|
@@ -1619,4 +1615,4 @@ function getModelFactory(store, type) {
|
|
|
1619
1615
|
|
|
1620
1616
|
//#endregion
|
|
1621
1617
|
export { save as _, RecordState as a, _save as c, createSnapshot as d, deleteRecord as f, rollbackAttributes as g, reload as h, restoreDeprecatedModelRequestBehaviors as i, belongsTo as l, hasMany as m, getModelFactory as n, _destroyRecord as o, destroyRecord as p, Model as r, _reload as s, buildSchema as t, changedAttributes as u, serialize as v, unloadRecord as y };
|
|
1622
|
-
//# sourceMappingURL=schema-provider-
|
|
1618
|
+
//# sourceMappingURL=schema-provider-05U1H-Kl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-provider-05U1H-Kl.js","names":["recordIdentifierFor","assertPrivateStore","RecordStore","FetchManager","upgradeStore","lookupLegacySupport","rollbackAttributes","currentState","isNew","store","_join","cache","rollbackAttrs","errors","clear","cleanErrorRequests","unloadRecord","isDestroyed","isDestroying","belongsTo","prop","referenceFor","hasMany","reload","options","message","Promise","reject","Error","_reload","isReloading","identifier","promise","request","op","data","record","cacheOptions","Symbol","for","then","finally","changedAttributes","changedAttrs","serialize","serializeRecord","deleteRecord","save","_save","isDeleted","resolve","saveRecord","destroyRecord","_destroyRecord","_","createSnapshot","_fetchManager","cacheFor","Context","notifyInternalSignal","peekInternalSignal","withSignalStore","LEGACY_SUPPORT","notifyChanges","identifier","value","key","record","store","notifyAttribute","eachAttribute","name","meta","constructor","relationshipsByName","get","notifyRelationship","eachRelationship","kind","notifyPropertyChange","support","manyArray","_manyArrayCache","hasPromise","_relationshipPromisesCache","signal","options","async","currentValue","cache","getAttr","storeFor","defineSignal","gate","memoized","notifyInternalSignal","peekInternalSignal","withSignalStore","recordIdentifierFor","n","SOURCE_POINTER_REGEXP","SOURCE_POINTER_PRIMARY_REGEXP","PRIMARY_ATTRIBUTE_KEY","isInvalidError","error","Error","isAdapterError","code","RecordState","constructor","record","store","identity","identifier","cache","pendingCount","fulfilledCount","rejectedCount","_errorRequests","_lastError","requests","getRequestStateService","notifications","handleRequest","req","type","state","isSaving","response","data","push","notifyErrorsStateChanged","notify","subscribeForRecord","lastRequest","getLastRequestForRecord","handler","subscribe","key","updateInvalidErrors","errors","destroy","unsubscribe","signals","signal","jsonApiErrors","getErrors","clear","i","length","source","pointer","keyMatch","match","search","errMsg","detail","title","add","cleanErrorRequests","isLoading","isLoaded","prototype","isNew","isEmpty","isSaved","rd","isDeleted","isDeletionCommitted","isValid","isDirty","hasChangedAttrs","isError","errorReq","adapterError","request","isPreloaded","stateName","dirtyType","EmberObject","recordIdentifierFor","storeFor","defineGate","entangleSignal","gate","memoized","withSignalStore","assertPrivateStore","coerceId","RecordStore","Errors","releaseLegacySupport","_destroyRecord","_reload","_save","belongsTo","changedAttributes","createSnapshot","deleteRecord","destroyRecord","hasMany","reload","rollbackAttributes","save","serialize","unloadRecord","notifyChanges","RecordState","n","computeOnce","target","propertyName","desc","cache","WeakMap","getter","get","meta","hasComputed","value","undefined","set","call","Model","init","options","createProps","_createProps","_secretInit","store","identity","identifier","cb","___recordState","setProperties","notifications","___private_notifications","subscribe","type","field","destroy","unsubscribe","isEmpty","currentState","prototype","isLoading","isLoaded","hasDirtyAttributes","isDirty","isSaving","isDeleted","isNew","isValid","dirtyType","isError","v","id","normalizedId","didChange","_instanceCache","setRecordId","notify","toString","constructor","modelName","_v","Error","errors","create","__record","updateInvalidErrors","adapterError","notifyPropertyChange","prop","signals","attr","eachRelationship","callback","binding","relationshipFor","name","relationshipsByName","inverseFor","eachAttribute","isModel","typeForRelationship","relationship","modelFor","inverseMap","Object","inverse","_findInverseFor","schemaExists","schema","hasResource","inverseField","fields","relationships","map","Map","forEach","has","push","relationshipNames","names","eachComputedProperty","isRelationshipSchema","kind","relatedTypes","types","rels","relationshipsObject","keys","i","length","includes","key","isAttributeSchema","eachRelatedType","relationshipTypes","determineRelationshipType","knownSide","knownKey","knownKind","otherKind","attributes","transformedAttributes","eachTransformedAttribute","_createSnapshot","console","warn","_isReloading","configurable","isLocal","restoreDeprecatedModelRequestBehaviors","ModelKlass","hasKind","getOwner","Model","modelForMixin","store","normalizedModelName","owner","MaybeMixin","factoryFor","mixin","class","ModelForMixin","extend","__isMixin","__mixin","register","getOwner","_modelForMixin","normalizeModelName","ModelSchemaProvider","constructor","store","_schemas","Map","_typeMisses","Set","resourceTypes","Array","from","keys","hasTrait","type","resourceHasTrait","resource","trait","transformation","field","derivation","hashFn","has","_loadModelSchema","get","schema","registerResources","schemas","registerResource","registerTransformation","transform","registerDerivation","registerHashFn","factory","getModelFactory","Error","modelClass","class","attributeMap","attributes","Object","create","forEach","meta","name","relationships","relationshipsObject","fields","attr","values","set","rel","legacy","identity","kind","cacheFields","cacheKey","sourceKey","internalSchema","hasResource","exists","add","buildSchema","_modelFactoryCache","cache","owner","factoryFor","klass","isModel","hasOwnModelNameSet","modelName","prototype","hasOwnProperty","call","defineProperty","value"],"sources":["../../../src/model/-private/model-methods.ts","../../../src/model/-private/notify-changes.ts","../../../src/model/-private/record-state.ts","../../../src/model/-private/model.ts","../../../src/model/-private/model-for-mixin.ts","../../../src/model/-private/schema-provider.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport type { Store } from '@warp-drive/core';\nimport { recordIdentifierFor } from '@warp-drive/core';\nimport { ENABLE_LEGACY_REQUEST_METHODS } from '@warp-drive/core/build-config/deprecations';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { assertPrivateStore } from '@warp-drive/core/store/-private';\nimport type { ChangedAttributesHash } from '@warp-drive/core/types/cache';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\n\nimport type { Snapshot } from '../../compat/-private.ts';\nimport { FetchManager, upgradeStore } from '../../compat/-private.ts';\nimport type { Errors } from './errors.ts';\nimport { lookupLegacySupport } from './legacy-relationships-support.ts';\nimport type RecordState from './record-state.ts';\nimport type BelongsToReference from './references/belongs-to.ts';\nimport type HasManyReference from './references/has-many.ts';\nimport type { MaybeBelongsToFields, MaybeHasManyFields } from './type-utils.ts';\n\nexport interface MinimalLegacyRecord {\n errors: Errors;\n /** @internal */\n ___recordState: RecordState;\n currentState: RecordState;\n isDestroyed: boolean;\n isDestroying: boolean;\n isReloading: boolean;\n isValid: boolean;\n /** @internal */\n [RecordStore]: Store;\n\n deleteRecord(): void;\n unloadRecord(): void;\n save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;\n destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;\n}\n\nexport function rollbackAttributes<T extends MinimalLegacyRecord>(this: T): void {\n const { currentState } = this;\n const { isNew } = currentState;\n const store = this[RecordStore];\n assertPrivateStore(store);\n\n store._join(() => {\n store.cache.rollbackAttrs(recordIdentifierFor(this));\n this.errors.clear();\n currentState.cleanErrorRequests();\n if (isNew) {\n this.unloadRecord();\n }\n });\n}\n\nexport function unloadRecord<T extends MinimalLegacyRecord>(this: T): void {\n if (this.currentState.isNew && (this.isDestroyed || this.isDestroying)) {\n return;\n }\n this[RecordStore].unloadRecord(this);\n}\n\nexport function belongsTo<T extends MinimalLegacyRecord, K extends MaybeBelongsToFields<T>>(\n this: T,\n prop: K\n): BelongsToReference<T, K> {\n return lookupLegacySupport(this).referenceFor('belongsTo', prop) as BelongsToReference<T, K>;\n}\n\nexport function hasMany<T extends MinimalLegacyRecord, K extends MaybeHasManyFields<T>>(\n this: T,\n prop: K\n): HasManyReference<T, K> {\n return lookupLegacySupport(this).referenceFor('hasMany', prop) as HasManyReference<T, K>;\n}\n\nexport function reload<T extends MinimalLegacyRecord>(this: T, options: Record<string, unknown> = {}): Promise<T> {\n if (!ENABLE_LEGACY_REQUEST_METHODS) {\n const message = `You cannot use reload() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`;\n assert(message, false);\n return Promise.reject(new Error(message));\n } else {\n deprecate(`record.reload is deprecated, please use store.request to initiate a request instead.`, false, {\n id: 'warp-drive:deprecate-legacy-request-methods',\n until: '6.0',\n for: '@warp-drive/core',\n url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',\n since: {\n enabled: '5.7',\n available: '5.7',\n },\n });\n\n return _reload.call(this, options) as Promise<T>;\n }\n}\n\nexport function _reload<T extends MinimalLegacyRecord>(this: T, options: Record<string, unknown> = {}): Promise<T> {\n options.isReloading = true;\n options.reload = true;\n\n const identifier = recordIdentifierFor(this);\n assert(`You cannot reload a record without an ID`, identifier.id);\n\n this.isReloading = true;\n const promise = this[RecordStore]\n .request({\n op: 'findRecord',\n data: {\n options,\n record: identifier,\n },\n cacheOptions: { [Symbol.for('wd:skip-cache')]: true },\n })\n .then(() => this)\n .finally(() => {\n this.isReloading = false;\n });\n\n return promise;\n}\n\nexport function changedAttributes<T extends MinimalLegacyRecord>(this: T): ChangedAttributesHash {\n return this[RecordStore].cache.changedAttrs(recordIdentifierFor(this));\n}\n\nexport function serialize<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): unknown {\n upgradeStore(this[RecordStore]);\n return this[RecordStore].serializeRecord(this, options);\n}\n\nexport function deleteRecord<T extends MinimalLegacyRecord>(this: T): void {\n // ensure we've populated currentState prior to deleting a new record\n if (this.currentState) {\n this[RecordStore].deleteRecord(this);\n }\n}\n\nexport function save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T> {\n if (!ENABLE_LEGACY_REQUEST_METHODS) {\n const message = `You cannot use save() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`;\n assert(message, false);\n return Promise.reject(new Error(message));\n } else {\n deprecate(`record.save is deprecated, please use store.request to initiate a request instead.`, false, {\n id: 'warp-drive:deprecate-legacy-request-methods',\n until: '6.0',\n for: '@warp-drive/core',\n url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',\n since: {\n enabled: '5.7',\n available: '5.7',\n },\n });\n\n return _save.call(this, options) as Promise<T>;\n }\n}\n\nexport function _save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T> {\n let promise: Promise<T>;\n\n if (this.currentState.isNew && this.currentState.isDeleted) {\n promise = Promise.resolve(this);\n } else {\n this.errors.clear();\n promise = this[RecordStore].saveRecord(this, options);\n }\n\n return promise;\n}\n\nexport function destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T> {\n if (!ENABLE_LEGACY_REQUEST_METHODS) {\n const message = `You cannot use destroyRecord() on a record when ENABLE_LEGACY_REQUEST_METHODS is false.`;\n assert(message, false);\n return Promise.reject(new Error(message));\n } else {\n deprecate(`record.destroyRecord is deprecated, please use store.request to initiate a request instead.`, false, {\n id: 'warp-drive:deprecate-legacy-request-methods',\n until: '6.0',\n for: '@warp-drive/core',\n url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',\n since: {\n enabled: '5.7',\n available: '5.7',\n },\n });\n\n return _destroyRecord.call(this, options) as Promise<T>;\n }\n}\n\nexport function _destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T> {\n const { isNew } = this.currentState;\n this.deleteRecord();\n if (isNew) {\n return Promise.resolve(this);\n }\n return this.save(options).then((_) => {\n this.unloadRecord();\n return this;\n });\n}\n\nexport function createSnapshot<T extends MinimalLegacyRecord>(this: T): Snapshot<T> {\n const store = this[RecordStore];\n\n upgradeStore(store);\n if (!store._fetchManager) {\n store._fetchManager = new FetchManager(store);\n }\n\n // @ts-expect-error Typescript isn't able to curry narrowed args that are divorced from each other.\n return store._fetchManager.createSnapshot<T>(recordIdentifierFor(this));\n}\n","import { cacheFor } from '@ember/object/internals';\n\nimport type { NotificationType, Store } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { Context } from '@warp-drive/core/reactive/-private';\nimport { notifyInternalSignal, peekInternalSignal, withSignalStore } from '@warp-drive/core/signals/-leaked';\nimport type { PrivateReactiveResourceArray } from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { LegacyRelationshipField as RelationshipSchema } from '@warp-drive/core/types/schema/fields';\n\nimport { LEGACY_SUPPORT } from './legacy-relationships-support.ts';\nimport type { Model } from './model.ts';\n\nexport default function notifyChanges(\n identifier: ResourceKey,\n value: NotificationType,\n key: string | undefined,\n record: Model,\n store: Store\n): void {\n switch (value) {\n case 'added':\n case 'attributes':\n if (key) {\n notifyAttribute(store, identifier, key, record);\n } else {\n record.eachAttribute((name) => {\n notifyAttribute(store, identifier, name, record);\n });\n }\n break;\n\n case 'relationships':\n if (key) {\n const meta = (record.constructor as typeof Model).relationshipsByName.get(key);\n assert(`Expected to find a relationship for ${key} on ${identifier.type}`, meta);\n notifyRelationship(identifier, key, record, meta);\n } else {\n record.eachRelationship((name, meta) => {\n notifyRelationship(identifier, name, record, meta);\n });\n }\n break;\n\n case 'identity':\n notifyInternalSignal(peekInternalSignal(withSignalStore(record), 'id'));\n break;\n }\n}\n\nfunction notifyRelationship(identifier: ResourceKey, key: string, record: Model, meta: RelationshipSchema) {\n if (meta.kind === 'belongsTo') {\n record.notifyPropertyChange(key);\n } else if (meta.kind === 'hasMany') {\n const support = LEGACY_SUPPORT.get(identifier);\n const manyArray = support && support._manyArrayCache[key];\n const hasPromise = support && support._relationshipPromisesCache[key];\n\n if (manyArray && hasPromise) {\n // do nothing, we will notify the ManyArray directly\n // once the fetch has completed.\n return;\n }\n\n if (manyArray) {\n notifyInternalSignal((manyArray as unknown as PrivateReactiveResourceArray)[Context].signal);\n\n //We need to notifyPropertyChange in the adding case because we need to make sure\n //we fetch the newly added record in case it is unloaded\n //TODO(Igor): Consider whether we could do this only if the record state is unloaded\n assert(`Expected options to exist on relationship meta`, meta.options);\n assert(`Expected async to exist on relationship meta options`, 'async' in meta.options);\n if (meta.options.async) {\n record.notifyPropertyChange(key);\n }\n }\n }\n}\n\nfunction notifyAttribute(store: Store, identifier: ResourceKey, key: string, record: Model) {\n const currentValue = cacheFor(record, key);\n const cache = store.cache;\n if (currentValue !== cache.getAttr(identifier, key)) {\n record.notifyPropertyChange(key);\n }\n}\n","import type { NotificationType, Store } from '@warp-drive/core';\nimport { storeFor } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport {\n defineSignal,\n gate,\n memoized,\n notifyInternalSignal,\n peekInternalSignal,\n withSignalStore,\n} from '@warp-drive/core/signals/-leaked';\nimport type { RequestCacheRequestState, RequestStateService } from '@warp-drive/core/store/-private';\nimport { recordIdentifierFor } from '@warp-drive/core/store/-private';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\n\nimport type { Errors } from './errors';\nimport type { MinimalLegacyRecord } from './model-methods';\n\nconst SOURCE_POINTER_REGEXP = /^\\/?data\\/(attributes|relationships)\\/(.*)/;\nconst SOURCE_POINTER_PRIMARY_REGEXP = /^\\/?data/;\nconst PRIMARY_ATTRIBUTE_KEY = 'base';\nfunction isInvalidError(error: unknown): error is Error & { isAdapterError: true; code: 'InvalidError' } {\n return (\n !!error &&\n error instanceof Error &&\n 'isAdapterError' in error &&\n error.isAdapterError === true &&\n 'code' in error &&\n error.code === 'InvalidError'\n );\n}\n\n/**\nHistorically WarpDrive managed a state machine\nfor each record, the localState for which\nwas reflected onto Model.\n\nThis implements the flags and stateName for backwards compat\nwith the state tree that used to be possible (listed below).\n\nstateName and dirtyType are candidates for deprecation.\n\nroot\n empty\n deleted // hidden from stateName\n preloaded // hidden from stateName\n\n loading\n empty // hidden from stateName\n preloaded // hidden from stateName\n\n loaded\n saved\n updated\n uncommitted\n invalid\n inFlight\n created\n uncommitted\n invalid\n inFlight\n\n deleted\n saved\n new // hidden from stateName\n uncommitted\n invalid\n inFlight\n\n @hideconstructor\n @private\n*/\nexport default class RecordState {\n /** @internal */\n declare private store: Store;\n /** @internal */\n declare private identifier: ResourceKey;\n /** @internal */\n declare private record: MinimalLegacyRecord;\n /** @internal */\n declare private rs: RequestStateService;\n\n /** @internal */\n declare private pendingCount: number;\n /** @internal */\n declare private fulfilledCount: number;\n /** @internal */\n declare private rejectedCount: number;\n /** @internal */\n declare private cache: Cache;\n /** @internal */\n declare private _errorRequests: RequestCacheRequestState[];\n /** @internal */\n declare private _lastError: RequestCacheRequestState | null;\n /** @internal */\n declare private handler: object;\n\n constructor(record: MinimalLegacyRecord) {\n const store = storeFor(record, false)!;\n const identity = recordIdentifierFor(record);\n\n this.identifier = identity;\n this.record = record;\n this.cache = store.cache;\n\n this.pendingCount = 0;\n this.fulfilledCount = 0;\n this.rejectedCount = 0;\n this._errorRequests = [];\n this._lastError = null;\n\n const requests = store.getRequestStateService();\n const notifications = store.notifications;\n\n const handleRequest = (req: RequestCacheRequestState) => {\n if (req.type === 'mutation') {\n switch (req.state) {\n case 'pending':\n this.isSaving = true;\n break;\n case 'rejected':\n this.isSaving = false;\n this._lastError = req;\n if (!(req.response && isInvalidError(req.response.data))) {\n this._errorRequests.push(req);\n }\n\n notifyErrorsStateChanged(this);\n break;\n case 'fulfilled':\n this._errorRequests = [];\n this._lastError = null;\n this.isSaving = false;\n this.notify('isDirty');\n notifyErrorsStateChanged(this);\n break;\n }\n } else {\n switch (req.state) {\n case 'pending':\n this.pendingCount++;\n this.notify('isLoading');\n break;\n case 'rejected':\n this.pendingCount--;\n this._lastError = req;\n if (!(req.response && isInvalidError(req.response.data))) {\n this._errorRequests.push(req);\n }\n this.notify('isLoading');\n notifyErrorsStateChanged(this);\n break;\n case 'fulfilled':\n this.pendingCount--;\n this.fulfilledCount++;\n this.notify('isLoading');\n this.notify('isDirty');\n notifyErrorsStateChanged(this);\n this._errorRequests = [];\n this._lastError = null;\n break;\n }\n }\n };\n\n requests.subscribeForRecord(identity, handleRequest);\n\n // we instantiate lazily\n // so we grab anything we don't have yet\n const lastRequest = requests.getLastRequestForRecord(identity);\n if (lastRequest) {\n handleRequest(lastRequest);\n }\n\n this.handler = notifications.subscribe(\n identity,\n (identifier: ResourceKey, type: NotificationType, key?: string) => {\n switch (type) {\n case 'state':\n this.notify('isSaved');\n this.notify('isNew');\n this.notify('isDeleted');\n this.notify('isDirty');\n break;\n case 'attributes':\n this.notify('isEmpty');\n this.notify('isDirty');\n break;\n case 'errors':\n this.updateInvalidErrors(this.record.errors);\n this.notify('isValid');\n break;\n }\n }\n );\n }\n\n /** @internal */\n destroy(): void {\n storeFor(this.record, false)!.notifications.unsubscribe(this.handler);\n }\n\n /** @internal */\n notify(key: keyof this & string): void {\n const signals = withSignalStore(this);\n const signal = peekInternalSignal(signals, key);\n if (signal) {\n notifyInternalSignal(signal);\n }\n }\n\n /** @internal */\n updateInvalidErrors(errors: Errors): void {\n assert(\n `Expected the Cache instance for ${this.identifier.lid} to implement getErrors(identifier)`,\n typeof this.cache.getErrors === 'function'\n );\n const jsonApiErrors = this.cache.getErrors(this.identifier);\n\n errors.clear();\n\n for (let i = 0; i < jsonApiErrors.length; i++) {\n const error = jsonApiErrors[i];\n\n if (error.source && error.source.pointer) {\n const keyMatch = error.source.pointer.match(SOURCE_POINTER_REGEXP);\n let key: string | undefined;\n\n if (keyMatch) {\n key = keyMatch[2];\n } else if (error.source.pointer.search(SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {\n key = PRIMARY_ATTRIBUTE_KEY;\n }\n\n if (key) {\n const errMsg = error.detail || error.title;\n assert(`Expected field error to have a detail or title to use as the message`, errMsg);\n errors.add(key, errMsg);\n }\n }\n }\n }\n\n /** @internal */\n cleanErrorRequests(): void {\n this.notify('isValid');\n this.notify('isError');\n this.notify('adapterError');\n this._errorRequests = [];\n this._lastError = null;\n }\n\n declare isSaving: boolean;\n\n @gate\n get isLoading(): boolean {\n return !this.isLoaded && this.pendingCount > 0 && this.fulfilledCount === 0;\n }\n\n @gate\n get isLoaded(): boolean {\n if (this.isNew) {\n return true;\n }\n return this.fulfilledCount > 0 || !this.isEmpty;\n }\n\n @gate\n get isSaved(): boolean {\n const rd = this.cache;\n if (this.isDeleted) {\n assert(`Expected Cache to implement isDeletionCommitted()`, typeof rd.isDeletionCommitted === 'function');\n return rd.isDeletionCommitted(this.identifier);\n }\n if (this.isNew || this.isEmpty || !this.isValid || this.isDirty || this.isLoading) {\n return false;\n }\n return true;\n }\n\n @gate\n get isEmpty(): boolean {\n const rd = this.cache;\n // TODO this is not actually an RFC'd concept. Determine the\n // correct heuristic to replace this with.\n assert(`Expected Cache to implement isEmpty()`, typeof rd.isEmpty === 'function');\n return !this.isNew && rd.isEmpty(this.identifier);\n }\n\n @gate\n get isNew(): boolean {\n const rd = this.cache;\n assert(`Expected Cache to implement isNew()`, typeof rd.isNew === 'function');\n return rd.isNew(this.identifier);\n }\n\n @gate\n get isDeleted(): boolean {\n const rd = this.cache;\n assert(`Expected Cache to implement isDeleted()`, typeof rd.isDeleted === 'function');\n return rd.isDeleted(this.identifier);\n }\n\n @gate\n get isValid(): boolean {\n return this.record.errors.length === 0;\n }\n\n @gate\n get isDirty(): boolean {\n const rd = this.cache;\n if (this.isEmpty || rd.isDeletionCommitted(this.identifier) || (this.isDeleted && this.isNew)) {\n return false;\n }\n return this.isDeleted || this.isNew || rd.hasChangedAttrs(this.identifier);\n }\n\n @gate\n get isError(): boolean {\n const errorReq = this._errorRequests[this._errorRequests.length - 1];\n if (!errorReq) {\n return false;\n } else {\n return true;\n }\n }\n\n @gate\n get adapterError(): unknown {\n const request = this._lastError;\n if (!request) {\n return null;\n }\n return request.state === 'rejected' && request.response!.data;\n }\n\n @memoized\n get isPreloaded(): boolean {\n return !this.isEmpty && this.isLoading;\n }\n\n @memoized\n get stateName():\n | 'root.loading'\n | 'root.empty'\n | 'root.deleted.inFlight'\n | 'root.deleted.saved'\n | 'root.deleted.invalid'\n | 'root.deleted.uncommitted'\n | 'root.loaded.created.inFlight'\n | 'root.loaded.created.invalid'\n | 'root.loaded.created.uncommitted'\n | 'root.loaded.updated.inFlight'\n | 'root.loaded.updated.invalid'\n | 'root.loaded.updated.uncommitted'\n | 'root.loaded.saved' {\n // we might be empty while loading so check this first\n if (this.isLoading) {\n return 'root.loading';\n\n // got nothing yet or were unloaded\n } else if (this.isEmpty) {\n return 'root.empty';\n\n // deleted substates\n } else if (this.isDeleted) {\n if (this.isSaving) {\n return 'root.deleted.inFlight';\n } else if (this.isSaved) {\n // TODO ensure isSaved isn't true from previous requests\n return 'root.deleted.saved';\n } else if (!this.isValid) {\n return 'root.deleted.invalid';\n } else {\n return 'root.deleted.uncommitted';\n }\n\n // loaded.created substates\n } else if (this.isNew) {\n if (this.isSaving) {\n return 'root.loaded.created.inFlight';\n } else if (!this.isValid) {\n return 'root.loaded.created.invalid';\n }\n return 'root.loaded.created.uncommitted';\n\n // loaded.updated substates\n } else if (this.isSaving) {\n return 'root.loaded.updated.inFlight';\n } else if (!this.isValid) {\n return 'root.loaded.updated.invalid';\n } else if (this.isDirty) {\n return 'root.loaded.updated.uncommitted';\n\n // if nothing remains, we are loaded saved!\n } else {\n return 'root.loaded.saved';\n }\n }\n\n @memoized\n get dirtyType(): '' | 'deleted' | 'created' | 'updated' {\n // we might be empty while loading so check this first\n if (this.isLoading || this.isEmpty) {\n return '';\n\n // deleted substates\n } else if (this.isDirty && this.isDeleted) {\n return 'deleted';\n\n // loaded.created substates\n } else if (this.isNew) {\n return 'created';\n\n // loaded.updated substates\n } else if (this.isSaving || !this.isValid || this.isDirty) {\n return 'updated';\n\n // if nothing remains, we are loaded saved!\n } else {\n return '';\n }\n }\n}\ndefineSignal(RecordState.prototype, 'isSaving', false);\n\nfunction notifyErrorsStateChanged(state: RecordState) {\n state.notify('isValid');\n state.notify('isError');\n state.notify('adapterError');\n}\n","import { deprecate } from '@ember/debug';\nimport EmberObject from '@ember/object';\n\nimport type { NotificationType, Store } from '@warp-drive/core';\nimport { recordIdentifierFor, storeFor } from '@warp-drive/core';\nimport { DEBUG } from '@warp-drive/core/build-config/env';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { defineGate, entangleSignal, gate, memoized, withSignalStore } from '@warp-drive/core/signals/-leaked';\nimport { assertPrivateStore, coerceId } from '@warp-drive/core/store/-private';\nimport type { ModelSchema, ResourceKey } from '@warp-drive/core/types';\nimport type { ChangedAttributesHash } from '@warp-drive/core/types/cache';\nimport type { LegacyAttributeField, LegacyRelationshipField } from '@warp-drive/core/types/schema/fields';\nimport { RecordStore } from '@warp-drive/core/types/symbols';\n\nimport type { Snapshot } from '../../compat/-private.ts';\nimport { Errors } from './errors.ts';\nimport { releaseLegacySupport } from './legacy-relationships-support.ts';\nimport type { MinimalLegacyRecord } from './model-methods.ts';\nimport {\n _destroyRecord,\n _reload,\n _save,\n belongsTo,\n changedAttributes,\n createSnapshot,\n deleteRecord,\n destroyRecord,\n hasMany,\n reload,\n rollbackAttributes,\n save,\n serialize,\n unloadRecord,\n} from './model-methods.ts';\nimport notifyChanges from './notify-changes.ts';\nimport RecordState from './record-state.ts';\nimport type BelongsToReference from './references/belongs-to.ts';\nimport type HasManyReference from './references/has-many.ts';\nimport type {\n _MaybeBelongsToFields,\n isSubClass,\n MaybeAttrFields,\n MaybeHasManyFields,\n MaybeRelationshipFields,\n} from './type-utils.ts';\n\nexport type ModelCreateArgs = {\n _createProps: Record<string, unknown>;\n // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for\n _secretInit: {\n identifier: ResourceKey;\n store: Store;\n cb: (record: Model, identifier: ResourceKey, store: Store) => void;\n };\n};\n\nexport type StaticModel = typeof Model & { create(options: ModelCreateArgs): Model };\nexport type ModelFactory = { class: StaticModel };\nexport type FactoryCache = Record<string, ModelFactory>;\n// we put this on the store for interop because it's used by modelFor and\n// instantiateRecord as well.\nexport type ModelStore = Store & { _modelFactoryCache: FactoryCache };\n\n/*\n * This decorator allows us to lazily compute\n * an expensive getter on first-access and thereafter\n * never recompute it.\n */\nfunction computeOnce(target: object, propertyName: string, desc: PropertyDescriptor) {\n const cache = new WeakMap<object, { hasComputed: boolean; value: unknown }>();\n // oxlint-disable-next-line typescript/unbound-method\n const getter = desc.get;\n desc.get = function () {\n let meta = cache.get(this);\n\n if (!meta) {\n meta = { hasComputed: false, value: undefined };\n cache.set(this, meta);\n }\n\n if (!meta.hasComputed) {\n meta.value = (getter as () => unknown).call(this);\n meta.hasComputed = true;\n }\n\n return meta.value;\n };\n return desc;\n}\n\ninterface Model {\n // set during create by the store\n /**\n * The store service instance which created this record instance\n */\n store: Store;\n /** @internal */\n ___recordState: RecordState;\n /** @internal */\n ___private_notifications: object;\n /** @internal */\n _isReloading: boolean;\n /** @internal */\n [RecordStore]: Store;\n\n /**\n Create a JSON representation of the record, using the serialization\n strategy of the store's adapter.\n\n `serialize` takes an optional hash as a parameter, currently\n supported options are:\n\n - `includeId`: `true` if the record's ID should be included in the\n JSON representation.\n\n @public\n @param {Object} options\n @return {Object} an object whose values are primitive JSON values only\n */\n serialize<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): unknown;\n\n /**\n Same as `deleteRecord`, but saves the record immediately.\n\n Example\n\n ```js\n import Component from '@glimmer/component';\n\n export default class extends Component {\n delete = () => {\n this.args.model.destroyRecord().then(function() {\n this.transitionToRoute('model.index');\n });\n }\n }\n ```\n\n If you pass an object on the `adapterOptions` property of the options\n argument it will be passed to your adapter via the snapshot\n\n ```js\n record.destroyRecord({ adapterOptions: { subscribe: false } });\n ```\n\n ```js [app/adapters/post.js]\n import MyCustomAdapter from './custom-adapter';\n\n export default class PostAdapter extends MyCustomAdapter {\n deleteRecord(store, type, snapshot) {\n if (snapshot.adapterOptions.subscribe) {\n // ...\n }\n // ...\n }\n }\n ```\n\n @public\n @param options\n @return a promise that will be resolved when the adapter returns\n successfully or rejected if the adapter returns with an error.\n */\n destroyRecord<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;\n\n /**\n Unloads the record from the store. This will not send a delete request\n to your server, it just unloads the record from memory.\n\n @public\n */\n unloadRecord<T extends MinimalLegacyRecord>(this: T): void;\n\n /**\n Returns an object, whose keys are changed properties, and value is\n an [oldProp, newProp] array.\n\n The array represents the diff of the canonical state with the local state\n of the model. Note: if the model is created locally, the canonical state is\n empty since the adapter hasn't acknowledged the attributes yet:\n\n Example\n\n ```js [app/models/mascot.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class MascotModel extends Model {\n @attr('string') name;\n @attr('boolean', {\n defaultValue: false\n })\n isAdmin;\n }\n ```\n\n ```javascript\n let mascot = store.createRecord('mascot');\n\n mascot.changedAttributes(); // {}\n\n mascot.set('name', 'Tomster');\n mascot.changedAttributes(); // { name: [undefined, 'Tomster'] }\n\n mascot.set('isAdmin', true);\n mascot.changedAttributes(); // { isAdmin: [undefined, true], name: [undefined, 'Tomster'] }\n\n mascot.save().then(function() {\n mascot.changedAttributes(); // {}\n\n mascot.set('isAdmin', false);\n mascot.changedAttributes(); // { isAdmin: [true, false] }\n });\n ```\n\n @public\n @return {Object} an object, whose keys are changed properties,\n and value is an [oldProp, newProp] array.\n */\n changedAttributes<T extends MinimalLegacyRecord>(this: T): ChangedAttributesHash;\n\n /**\n If the model `hasDirtyAttributes` this function will discard any unsaved\n changes. If the model `isNew` it will be removed from the store.\n\n Example\n\n ```javascript\n record.name; // 'Untitled Document'\n record.set('name', 'Doc 1');\n record.name; // 'Doc 1'\n record.rollbackAttributes();\n record.name; // 'Untitled Document'\n ```\n\n @since 1.13.0\n @public\n */\n rollbackAttributes<T extends MinimalLegacyRecord>(this: T): void;\n\n // TODO @deprecate in favor of a public API or examples of how to test successfully\n /**\n @private\n */\n _createSnapshot<T extends MinimalLegacyRecord>(this: T): Snapshot<T>;\n\n /**\n Save the record and persist any changes to the record to an\n external source via the adapter.\n\n Example\n\n ```javascript\n record.set('name', 'Tomster');\n record.save().then(function() {\n // Success callback\n }, function() {\n // Error callback\n });\n ```\n\n If you pass an object using the `adapterOptions` property of the options\n argument it will be passed to your adapter via the snapshot.\n\n ```js\n record.save({ adapterOptions: { subscribe: false } });\n ```\n\n ```js [app/adapters/post.js]\n import MyCustomAdapter from './custom-adapter';\n\n export default class PostAdapter extends MyCustomAdapter {\n updateRecord(store, type, snapshot) {\n if (snapshot.adapterOptions.subscribe) {\n // ...\n }\n // ...\n }\n }\n ```\n\n @deprecated use {@link Store.request} instead\n @public\n @return a promise that will be resolved when the adapter returns\n successfully or rejected if the adapter returns with an error.\n */\n save<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<this>;\n\n /**\n Reload the record from the adapter.\n\n This will only work if the record has already finished loading.\n\n Example\n\n ```js\n import Component from '@glimmer/component';\n\n export default class extends Component {\n async reload = () => {\n await this.args.model.reload();\n // do something with the reloaded model\n }\n }\n ```\n\n @public\n @param {Object} options optional, may include `adapterOptions` hash which will be passed to adapter request\n\n @return {Promise} a promise that will be resolved with the record when the\n adapter returns successfully or rejected if the adapter returns\n with an error.\n */\n\n reload<T extends MinimalLegacyRecord>(this: T, options?: Record<string, unknown>): Promise<T>;\n\n // belongsTo<T extends MinimalLegacyRecord, K extends MaybeBelongsToFields<T>>(\n // this: T,\n // prop: K\n // ): BelongsToReference<T, K>;\n\n /**\n Get the reference for the specified belongsTo relationship.\n\n For instance, given the following model\n\n ```js [app/models/blog-post.js]\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class BlogPost extends Model {\n @belongsTo('user', { async: true, inverse: null }) author;\n }\n ```\n\n Then the reference for the author relationship would be\n retrieved from a record instance like so:\n\n ```js\n blogPost.belongsTo('author');\n ```\n\n A `BelongsToReference` is a low-level API that allows access\n and manipulation of a belongsTo relationship.\n\n It is especially useful when you're dealing with `async` relationships\n as it allows synchronous access to the relationship data if loaded, as\n well as APIs for loading, reloading the data or accessing available\n information without triggering a load.\n\n It may also be useful when using `sync` relationships that need to be\n loaded/reloaded with more precise timing than marking the\n relationship as `async` and relying on autofetch would have allowed.\n\n However,keep in mind that marking a relationship as `async: false` will introduce\n bugs into your application if the data is not always guaranteed to be available\n by the time the relationship is accessed. Ergo, it is recommended when using this\n approach to utilize `links` for unloaded relationship state instead of identifiers.\n\n Reference APIs are entangled with the relationship's underlying state,\n thus any getters or cached properties that utilize these will properly\n invalidate if the relationship state changes.\n\n References are \"stable\", meaning that multiple calls to retrieve the reference\n for a given relationship will always return the same HasManyReference.\n\n @public\n @param prop - the name of the relationship\n @since 2.5.0\n @return reference for this relationship\n */\n belongsTo<T extends Model, K extends keyof T & string>(\n this: T,\n prop: K & (K extends _MaybeBelongsToFields<T> ? K : never)\n ): BelongsToReference<T, K>;\n\n /**\n Get the reference for the specified hasMany relationship.\n\n For instance, given the following model\n\n ```js [app/models/blog-post.js]\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class BlogPost extends Model {\n @hasMany('comment', { async: true, inverse: null }) comments;\n }\n ```\n\n Then the reference for the comments relationship would be\n retrieved from a record instance like so:\n\n ```js\n blogPost.hasMany('comments');\n ```\n\n A `HasManyReference` is a low-level API that allows access\n and manipulation of a hasMany relationship.\n\n It is especially useful when you are dealing with `async` relationships\n as it allows synchronous access to the relationship data if loaded, as\n well as APIs for loading, reloading the data or accessing available\n information without triggering a load.\n\n It may also be useful when using `sync` relationships with `@ember-data/model`\n that need to be loaded/reloaded with more precise timing than marking the\n relationship as `async` and relying on autofetch would have allowed.\n\n However,keep in mind that marking a relationship as `async: false` will introduce\n bugs into your application if the data is not always guaranteed to be available\n by the time the relationship is accessed. Ergo, it is recommended when using this\n approach to utilize `links` for unloaded relationship state instead of identifiers.\n\n Reference APIs are entangled with the relationship's underlying state,\n thus any getters or cached properties that utilize these will properly\n invalidate if the relationship state changes.\n\n References are \"stable\", meaning that multiple calls to retrieve the reference\n for a given relationship will always return the same HasManyReference.\n\n @public\n @param prop - the name of the relationship\n @since 2.5.0\n @return reference for this relationship\n */\n hasMany<T extends MinimalLegacyRecord, K extends MaybeHasManyFields<T>>(this: T, prop: K): HasManyReference<T, K>;\n\n /**\n Marks the record as deleted but does not save it. You must call\n `save` afterwards if you want to persist it. You might use this\n method if you want to allow the user to still `rollbackAttributes()`\n after a delete was made.\n\n Example\n\n ```js\n import Component from '@glimmer/component';\n\n export default class extends Component {\n softDelete = () => {\n this.args.model.deleteRecord();\n }\n\n confirm = () => {\n this.args.model.save();\n }\n\n undo = () => {\n this.args.model.rollbackAttributes();\n }\n }\n ```\n\n @public\n */\n deleteRecord<T extends MinimalLegacyRecord>(this: T): void;\n}\n\n/**\n * Base class from which Models can be defined.\n *\n * ::: code-group\n *\n * ```js [app/models/user.js]\n * import { Model, attr, belongsTo, hasMany } from '@warp-drive/legacy/model';\n *\n * export default class User extends Model {\n * @attr name;\n * @attr('number') age;\n * @hasMany('post', { async: true, inverse: null }) posts;\n * @belongsTo('group', { async: false, inverse: 'users' }) group;\n * }\n * ```\n *\n * ```ts [app/models/user.ts]\n * import { Model, attr, belongsTo, hasMany, type AsyncHasMany } from '@warp-drive/legacy/model';\n * import type { NumberTransform } from '@ember-data/serializer/transform';\n * import type Group from './group';\n * import type Post from './post';\n *\n * export default class User extends Model {\n * @attr declare name: string;\n *\n * @attr<NumberTransform>('number')\n * declare age: number;\n *\n * @hasMany('post', { async: true, inverse: null })\n * declare posts: AsyncHasMany<Post>;\n *\n * @belongsTo('group', { async: false, inverse: 'users' })\n * declare group: Group | null;\n * }\n * ```\n *\n * :::\n *\n * Models both define the schema for a resource type and provide\n * the class to use as the reactive object for data of resource\n * of that type.\n *\n * @public\n * @noInheritDoc\n * @hideconstructor\n * @legacy\n */\nclass Model extends EmberObject implements MinimalLegacyRecord {\n /** @internal */\n init(options: ModelCreateArgs): void {\n if (DEBUG) {\n if (!options?._secretInit && !options?._createProps) {\n throw new Error(\n 'You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.'\n );\n }\n }\n const createProps = options._createProps;\n const _secretInit = options._secretInit;\n (options as Record<string, unknown>)._createProps = null;\n (options as Record<string, unknown>)._secretInit = null;\n\n const store = (this.store = _secretInit.store);\n super.init(options);\n\n this[RecordStore] = store;\n\n const identity = _secretInit.identifier;\n _secretInit.cb(this, identity, _secretInit.store);\n\n this.___recordState = DEBUG ? new RecordState(this) : (null as unknown as RecordState);\n\n this.setProperties(createProps);\n\n const notifications = store.notifications;\n this.___private_notifications = notifications.subscribe(\n identity,\n (identifier: ResourceKey, type: NotificationType, field?: string): void => {\n notifyChanges(identifier, type, field, this, store);\n }\n );\n }\n\n /** @private */\n // @ts-expect-error destroy should not return a value, but ember's types force it to\n destroy(): this {\n const identifier = recordIdentifierFor(this);\n this.___recordState?.destroy();\n const store = storeFor(this, false)!;\n store.notifications.unsubscribe(this.___private_notifications);\n\n releaseLegacySupport(identifier);\n\n super.destroy();\n }\n\n /**\n If this property is `true` the record is in the `empty`\n state. Empty is the first state all records enter after they have\n been created. Most records created by the store will quickly\n transition to the `loading` state if data needs to be fetched from\n the server or the `created` state if the record is created on the\n client. A record can also enter the empty state if the adapter is\n unable to locate the record.\n\n @public\n */\n @memoized\n get isEmpty(): boolean {\n return this.currentState.isEmpty;\n }\n\n /**\n If this property is `true` the record is in the `loading` state. A\n record enters this state when the store asks the adapter for its\n data. It remains in this state until the adapter provides the\n requested data.\n\n @public\n */\n @memoized\n get isLoading(): boolean {\n return this.currentState.isLoading;\n }\n\n /**\n If this property is `true` the record is in the `loaded` state. A\n record enters this state when its data is populated. Most of a\n record's lifecycle is spent inside substates of the `loaded`\n state.\n\n Example\n\n ```javascript\n let record = store.createRecord('model');\n record.isLoaded; // true\n\n const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));\n model.isLoaded;\n ```\n\n @public\n */\n @memoized\n get isLoaded(): boolean {\n return this.currentState.isLoaded;\n }\n\n /**\n If this property is `true` the record is in the `dirty` state. The\n record has local changes that have not yet been saved by the\n adapter. This includes records that have been created (but not yet\n saved) or deleted.\n\n Example\n\n ```javascript\n let record = store.createRecord('model');\n record.hasDirtyAttributes; // true\n\n const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));\n\n model.hasDirtyAttributes; // false\n model.foo = 'some value';\n model.hasDirtyAttributes; // true\n ```\n\n @since 1.13.0\n @public\n */\n @memoized\n get hasDirtyAttributes(): boolean {\n return this.currentState.isDirty;\n }\n\n /**\n If this property is `true` the record is in the `saving` state. A\n record enters the saving state when `save` is called, but the\n adapter has not yet acknowledged that the changes have been\n persisted to the backend.\n\n Example\n\n ```javascript\n let record = store.createRecord('model');\n record.isSaving; // false\n let promise = record.save();\n record.isSaving; // true\n promise.then(function() {\n record.isSaving; // false\n });\n ```\n\n @public\n */\n @memoized\n get isSaving(): boolean {\n return this.currentState.isSaving;\n }\n\n /**\n If this property is `true` the record is in the `deleted` state\n and has been marked for deletion. When `isDeleted` is true and\n `hasDirtyAttributes` is true, the record is deleted locally but the deletion\n was not yet persisted. When `isSaving` is true, the change is\n in-flight. When both `hasDirtyAttributes` and `isSaving` are false, the\n change has persisted.\n\n Example\n\n ```javascript\n let record = store.createRecord('model');\n record.isDeleted; // false\n record.deleteRecord();\n\n // Locally deleted\n record.isDeleted; // true\n record.hasDirtyAttributes; // true\n record.isSaving; // false\n\n // Persisting the deletion\n let promise = record.save();\n record.isDeleted; // true\n record.isSaving; // true\n\n // Deletion Persisted\n promise.then(function() {\n record.isDeleted; // true\n record.isSaving; // false\n record.hasDirtyAttributes; // false\n });\n ```\n\n @public\n */\n @memoized\n get isDeleted(): boolean {\n return this.currentState.isDeleted;\n }\n\n /**\n If this property is `true` the record is in the `new` state. A\n record will be in the `new` state when it has been created on the\n client and the adapter has not yet report that it was successfully\n saved.\n\n Example\n\n ```javascript\n let record = store.createRecord('model');\n record.isNew; // true\n\n record.save().then(function(model) {\n model.isNew; // false\n });\n ```\n\n @public\n */\n @memoized\n get isNew(): boolean {\n return this.currentState.isNew;\n }\n\n /**\n If this property is `true` the record is in the `valid` state.\n\n A record will be in the `valid` state when the adapter did not report any\n server-side validation failures.\n\n @public\n */\n @memoized\n get isValid(): boolean {\n return this.currentState.isValid;\n }\n\n /**\n If the record is in the dirty state this property will report what\n kind of change has caused it to move into the dirty\n state. Possible values are:\n\n - `created` The record has been created by the client and not yet saved to the adapter.\n - `updated` The record has been updated by the client and not yet saved to the adapter.\n - `deleted` The record has been deleted by the client and not yet saved to the adapter.\n\n Example\n\n ```javascript\n let record = store.createRecord('model');\n record.dirtyType; // 'created'\n ```\n\n @public\n */\n @memoized\n get dirtyType(): 'created' | 'updated' | 'deleted' | '' {\n return this.currentState.dirtyType;\n }\n\n /**\n If `true` the adapter reported that it was unable to save local\n changes to the backend for any reason other than a server-side\n validation error.\n\n Example\n\n ```javascript\n record.isError; // false\n record.set('foo', 'valid value');\n record.save().then(null, function() {\n record.isError; // true\n });\n ```\n\n @public\n */\n @memoized\n get isError(): boolean {\n return this.currentState.isError;\n }\n /**\n * `isError` is read-only and cannot be set directly.\n */\n set isError(v) {\n if (DEBUG) {\n throw new Error(`isError is not directly settable`);\n }\n }\n\n /**\n If `true` the store is attempting to reload the record from the adapter.\n\n Example\n\n ```javascript\n record.isReloading; // false\n record.reload();\n record.isReloading; // true\n ```\n\n @public\n */\n declare isReloading: boolean;\n\n /**\n All ember models have an id property. This is an identifier\n managed by an external source. These are always coerced to be\n strings before being used internally. Note when declaring the\n attributes for a model it is an error to declare an id\n attribute.\n\n ```javascript\n let record = store.createRecord('model');\n record.id; // null\n\n const { content: { data: model } } = await store.request(findRecord({ type: 'model', id: '1' }));\n model.id; // '1'\n ```\n\n @public\n */\n @gate\n get id(): string | null {\n // this guard exists, because some dev-only deprecation code\n // (addListener via validatePropertyInjections) invokes toString before the\n // object is real.\n if (DEBUG) {\n try {\n return recordIdentifierFor(this).id;\n } catch {\n return null;\n }\n }\n return recordIdentifierFor(this).id;\n }\n /**\n * Assigns the resource's primary key. Typically only used internally\n * when a client-created record is assigned an id upon being saved.\n */\n set id(id) {\n const normalizedId = coerceId(id);\n const identifier = recordIdentifierFor(this);\n const didChange = normalizedId !== identifier.id;\n assertPrivateStore(this.store);\n assert(\n `Cannot set ${identifier.type} record's id to ${id}, because id is already ${identifier.id}`,\n !didChange || identifier.id === null\n );\n\n if (normalizedId !== null && didChange) {\n this.store._instanceCache.setRecordId(identifier, normalizedId);\n this.store.notifications.notify(identifier, 'identity', null);\n }\n }\n\n toString() {\n return `<model::${(this.constructor as unknown as { modelName: string }).modelName}:${this.id}>`;\n }\n\n /**\n @private\n */\n // TODO we can probably make this a computeOnce\n // we likely do not need to notify the currentState root anymore\n @gate\n get currentState(): RecordState {\n // descriptors are called with the wrong `this` context during mergeMixins\n // when using legacy/classic ember classes. Basically: lazy in prod and eager in dev.\n // so we do this to try to steer folks to the nicer \"dont user currentState\"\n // error.\n if (!DEBUG) {\n if (!this.___recordState) {\n this.___recordState = new RecordState(this);\n }\n }\n return this.___recordState;\n }\n /**\n * `currentState` is read-only and cannot be set directly.\n */\n set currentState(_v) {\n throw new Error('cannot set currentState');\n }\n\n /**\n The store service instance which created this record instance\n\n @public\n */\n declare store: Store;\n\n /**\n When the record is in the `invalid` state this object will contain\n any errors returned by the adapter. When present the errors hash\n contains keys corresponding to the invalid property names\n and values which are arrays of Javascript objects with two keys:\n\n - `message` A string containing the error message from the backend\n - `attribute` The name of the property associated with this error message\n\n ```javascript\n record.errors.length; // 0\n record.set('foo', 'invalid value');\n record.save().catch(function() {\n record.errors.foo;\n // [{message: 'foo should be a number.', attribute: 'foo'}]\n });\n ```\n\n The `errors` property is useful for displaying error messages to\n the user.\n\n ```handlebars\n <label>Username: <Input @value={{@model.username}} /> </label>\n {{#each @model.errors.username as |error|}}\n <div class=\"error\">\n {{error.message}}\n </div>\n {{/each}}\n <label>Email: <Input @value={{@model.email}} /> </label>\n {{#each @model.errors.email as |error|}}\n <div class=\"error\">\n {{error.message}}\n </div>\n {{/each}}\n ```\n\n\n You can also access the special `messages` property on the error\n object to get an array of all the error strings.\n\n ```handlebars\n {{#each @model.errors.messages as |message|}}\n <div class=\"error\">\n {{message}}\n </div>\n {{/each}}\n ```\n\n @public\n */\n @computeOnce\n get errors(): Errors {\n const errors = (Errors as unknown as { create(obj: object): Errors }).create({ __record: this });\n this.currentState.updateInvalidErrors(errors);\n return errors;\n }\n\n /**\n This property holds the `AdapterError` object with which\n last adapter operation was rejected.\n\n @public\n */\n @memoized\n get adapterError(): unknown {\n return this.currentState.adapterError;\n }\n /**\n * `adapterError` is read-only and cannot be set directly.\n */\n set adapterError(v) {\n throw new Error(`adapterError is not directly settable`);\n }\n\n /*\n We hook the default implementation to ensure\n our tagged properties are properly notified\n as well. We still super for everything because\n sync observers require a direct call occuring\n to trigger their flush. We wouldn't need to\n super in 4.0+ where sync observers are removed.\n */\n // @ts-expect-error no return is necessary, but Ember's types are forcing it\n notifyPropertyChange(prop: string): this {\n const signals = withSignalStore(this);\n entangleSignal(signals, this, prop, undefined);\n super.notifyPropertyChange(prop);\n }\n\n /** @internal */\n attr(): void {\n assert(\n 'The `attr` method is not available on Model, a Snapshot was probably expected. Are you passing a Model instead of a Snapshot to your serializer?',\n false\n );\n }\n\n /**\n Given a callback, iterates over each of the relationships in the model,\n invoking the callback with the name of each relationship and its relationship\n descriptor.\n\n\n The callback method you provide should have the following signature (all\n parameters are optional):\n\n ```javascript\n function(name, descriptor);\n ```\n\n - `name` the name of the current property in the iteration\n - `descriptor` the meta object that describes this relationship\n\n The relationship descriptor argument is an object with the following properties.\n\n - **name** <span class=\"type\">String</span> the name of this relationship on the Model\n - **kind** <span class=\"type\">String</span> \"hasMany\" or \"belongsTo\"\n - **options** <span class=\"type\">Object</span> the original options hash passed when the relationship was declared\n - **parentType** <span class=\"type\">Model</span> the type of the Model that owns this relationship\n - **type** <span class=\"type\">String</span> the type name of the related Model\n\n Note that in addition to a callback, you can also pass an optional target\n object that will be set as `this` on the context.\n\n Example\n\n ```js [app/serializers/application.js]\n import JSONSerializer from '@ember-data/serializer/json';\n\n export default class ApplicationSerializer extends JSONSerializer {\n serialize(record, options) {\n let json = {};\n\n record.eachRelationship(function(name, descriptor) {\n if (descriptor.kind === 'hasMany') {\n let serializedHasManyName = name.toUpperCase() + '_IDS';\n json[serializedHasManyName] = record.get(name).map(r => r.id);\n }\n });\n\n return json;\n }\n }\n ```\n\n @public\n @param callback the callback to invoke\n @param binding the value to which the callback's `this` should be bound\n */\n eachRelationship<T>(\n callback: (this: NoInfer<T> | undefined, key: MaybeRelationshipFields<this>, meta: LegacyRelationshipField) => void,\n binding?: T\n ): void {\n (this.constructor as typeof Model).eachRelationship<T, this>(callback, binding);\n }\n\n /**\n * Returns the relationship schema for the given relationship name, if any.\n */\n relationshipFor(name: string): LegacyRelationshipField | undefined {\n return (this.constructor as typeof Model).relationshipsByName.get(name);\n }\n\n /**\n * Returns the inverse relationship schema for the given relationship\n * name, if one exists. See {@link Model.inverseFor | the static inverseFor}.\n */\n inverseFor(name: string): LegacyRelationshipField | null {\n return (this.constructor as typeof Model).inverseFor(name, storeFor(this, false)!);\n }\n\n /**\n * Iterates over the attributes defined on this record's class, calling\n * `callback` for each one. See {@link Model.eachAttribute | the static eachAttribute}.\n *\n * @param callback the callback to invoke\n * @param binding the value to which the callback's `this` should be bound\n */\n eachAttribute<T>(\n callback: (\n this: NoInfer<T> | undefined,\n key: isSubClass<this> extends true ? MaybeAttrFields<this> : string,\n meta: LegacyAttributeField\n ) => void,\n binding?: T\n ): void {\n (this.constructor as typeof Model).eachAttribute<T, this>(callback, binding);\n }\n\n /**\n * @internal\n */\n static isModel = true;\n\n /**\n Represents the model's class name as a string. This can be used to look up the model's class name through\n `Store`'s modelFor method.\n\n `modelName` is generated for you by WarpDrive. It will be a lowercased, dasherized string.\n For example:\n\n ```javascript\n store.modelFor('post').modelName; // 'post'\n store.modelFor('blog-post').modelName; // 'blog-post'\n ```\n\n The most common place you'll want to access `modelName` is in your serializer's `payloadKeyFromModelName` method. For example, to change payload\n keys to underscore (instead of dasherized), you might use the following code:\n\n ```javascript\n import RESTSerializer from '@ember-data/serializer/rest';\n import { underscore } from '<app-name>/utils/string-utils';\n\n export default const PostSerializer = RESTSerializer.extend({\n payloadKeyFromModelName(modelName) {\n return underscore(modelName);\n }\n });\n ```\n\n @public\n */\n static modelName: string = null as unknown as string;\n\n /*\n These class methods below provide relationship\n introspection abilities about relationships.\n\n A note about the computed properties contained here:\n\n **These properties are effectively sealed once called for the first time.**\n To avoid repeatedly doing expensive iteration over a model's fields, these\n values are computed once and then cached for the remainder of the runtime of\n your application.\n\n If your application needs to modify a class after its initial definition\n (for example, using `reopen()` to add additional attributes), make sure you\n do it before using your model with the store, which uses these properties\n extensively.\n */\n\n /**\n For a given relationship name, returns the model type of the relationship.\n\n For example, if you define a model like this:\n\n ```js [app/models/post.js]\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @hasMany('comment') comments;\n }\n ```\n\n Calling `store.modelFor('post').typeForRelationship('comments', store)` will return `Comment`.\n\n @public\n @param name the name of the relationship\n @param store an instance of Store\n @return the type of the relationship, or undefined\n */\n static typeForRelationship(name: string, store: Store): ModelSchema | undefined {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const relationship = this.relationshipsByName.get(name);\n return relationship && store.modelFor(relationship.type);\n }\n\n /**\n * A cache of resolved inverse relationships by name, populated lazily by\n * {@link Model.inverseFor | inverseFor}.\n */\n @computeOnce\n static get inverseMap(): Record<string, LegacyRelationshipField | null> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n return Object.create(null) as Record<string, LegacyRelationshipField | null>;\n }\n\n /**\n Find the relationship which is the inverse of the one asked for.\n\n For example, if you define models like this:\n\n ```js [app/models/post.js]\n import { Model, hasMany } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @hasMany('message') comments;\n }\n ```\n\n ```js [app/models/message.js]\n import { Model, belongsTo } from '@warp-drive/legacy/model';\n\n export default class MessageModel extends Model {\n @belongsTo('post') owner;\n }\n ```\n\n ``` js\n store.modelFor('post').inverseFor('comments', store) // { type: 'message', name: 'owner', kind: 'belongsTo' }\n store.modelFor('message').inverseFor('owner', store) // { type: 'post', name: 'comments', kind: 'hasMany' }\n ```\n\n @public\n @param name the name of the relationship\n @param store\n @return the inverse relationship, or null\n */\n static inverseFor(name: string, store: Store): LegacyRelationshipField | null {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n const inverseMap = this.inverseMap;\n if (inverseMap[name]) {\n return inverseMap[name];\n } else {\n const inverse = this._findInverseFor(name, store);\n inverseMap[name] = inverse;\n return inverse;\n }\n }\n\n /**\n * @private\n */\n //Calculate the inverse, ignoring the cache\n static _findInverseFor(name: string, store: Store): LegacyRelationshipField | null {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const relationship = this.relationshipsByName.get(name)!;\n assert(`No relationship named '${name}' on '${this.modelName}' exists.`, relationship);\n\n if (!relationship) {\n return null;\n }\n\n const { options } = relationship;\n assert(\n `Expected the relationship ${name} on ${this.modelName} to define an inverse.`,\n options.inverse === null || (typeof options.inverse === 'string' && options.inverse.length > 0)\n );\n\n if (options.inverse === null) {\n return null;\n }\n\n const schemaExists = store.schema.hasResource(relationship);\n\n assert(\n `No associated schema found for '${relationship.type}' while calculating the inverse of ${name} on ${this.modelName}`,\n schemaExists\n );\n\n if (!schemaExists) {\n return null;\n }\n\n const inverseField = store.schema.fields(relationship).get(options.inverse);\n assert(\n `No inverse relationship found for '${name}' on '${this.modelName}'`,\n inverseField && (inverseField.kind === 'belongsTo' || inverseField.kind === 'hasMany')\n );\n\n return inverseField || null;\n }\n\n /**\n The model's relationships as a map, keyed on the type of the\n relationship. The value of each entry is an array containing a descriptor\n for each relationship with that type, describing the name of the relationship\n as well as the type.\n\n For example, given the following model definition:\n\n ```js [app/models/blog.js]\n import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';\n\n export default class BlogModel extends Model {\n @hasMany('user') users;\n @belongsTo('user') owner;\n @hasMany('post') posts;\n }\n ```\n\n This computed property would return a map describing these\n relationships, like this:\n\n ```javascript\n import Blog from 'app/models/blog';\n import User from 'app/models/user';\n import Post from 'app/models/post';\n\n let relationships = Blog.relationships;\n relationships.user;\n //=> [ { name: 'users', kind: 'hasMany' },\n // { name: 'owner', kind: 'belongsTo' } ]\n relationships.post;\n //=> [ { name: 'posts', kind: 'hasMany' } ]\n ```\n\n @public\n */\n @computeOnce\n static get relationships(): Map<string, LegacyRelationshipField[]> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const map = new Map<string, LegacyRelationshipField[]>();\n const relationshipsByName = this.relationshipsByName;\n\n // Loop through each computed property on the class\n relationshipsByName.forEach((desc) => {\n const { type } = desc;\n\n if (!map.has(type)) {\n map.set(type, []);\n }\n\n map.get(type)!.push(desc);\n });\n\n return map;\n }\n\n /**\n A hash containing lists of the model's relationships, grouped\n by the relationship kind. For example, given a model with this\n definition:\n\n ```js [app/models/blog.js]\n import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';\n\n export default class BlogModel extends Model {\n @hasMany('user') users;\n @belongsTo('user') owner;\n\n @hasMany('post') posts;\n }\n ```\n\n This property would contain the following:\n\n ```javascript\n import Blog from 'app/models/blog';\n\n let relationshipNames = Blog.relationshipNames;\n relationshipNames.hasMany;\n //=> ['users', 'posts']\n relationshipNames.belongsTo;\n //=> ['owner']\n ```\n\n @public\n */\n @computeOnce\n static get relationshipNames(): {\n /**\n * the names of the model's `hasMany` relationships\n */\n hasMany: string[];\n /**\n * the names of the model's `belongsTo` relationships\n */\n belongsTo: string[];\n } {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n const names: { hasMany: string[]; belongsTo: string[] } = {\n hasMany: [],\n belongsTo: [],\n };\n\n this.eachComputedProperty((name, meta) => {\n if (isRelationshipSchema(meta)) {\n names[meta.kind].push(name);\n }\n });\n\n return names;\n }\n\n /**\n An array of types directly related to a model. Each type will be\n included once, regardless of the number of relationships it has with\n the model.\n\n For example, given a model with this definition:\n\n ```js [app/models/blog.js]\n import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';\n\n export default class BlogModel extends Model {\n @hasMany('user') users;\n @belongsTo('user') owner;\n\n @hasMany('post') posts;\n }\n ```\n\n This property would contain the following:\n\n ```javascript\n import Blog from 'app/models/blog';\n\n let relatedTypes = Blog.relatedTypes');\n //=> ['user', 'post']\n ```\n\n @public\n */\n @computeOnce\n static get relatedTypes(): string[] {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const types: string[] = [];\n\n const rels = this.relationshipsObject;\n const relationships = Object.keys(rels);\n\n // create an array of the unique types involved\n // in relationships\n for (let i = 0; i < relationships.length; i++) {\n const name = relationships[i];\n const meta = rels[name];\n const modelName = meta.type;\n\n if (!types.includes(modelName)) {\n types.push(modelName);\n }\n }\n\n return types;\n }\n\n /**\n A map whose keys are the relationships of a model and whose values are\n relationship descriptors.\n\n For example, given a model with this\n definition:\n\n ```js [app/models/blog.js]\n import { Model, belongsTo, hasMany } from '@warp-drive/legacy/model';\n\n export default class BlogModel extends Model {\n @hasMany('user') users;\n @belongsTo('user') owner;\n\n @hasMany('post') posts;\n }\n ```\n\n This property would contain the following:\n\n ```javascript\n import Blog from 'app/models/blog';\n\n let relationshipsByName = Blog.relationshipsByName;\n relationshipsByName.users;\n //=> { name: 'users', kind: 'hasMany', type: 'user', options: Object }\n relationshipsByName.owner;\n //=> { name: 'owner', kind: 'belongsTo', type: 'user', options: Object }\n ```\n\n @public\n */\n @computeOnce\n static get relationshipsByName(): Map<string, LegacyRelationshipField> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n const map = new Map();\n const rels = this.relationshipsObject;\n const relationships = Object.keys(rels);\n\n for (let i = 0; i < relationships.length; i++) {\n const name = relationships[i];\n const value = rels[name];\n\n map.set(value.name, value);\n }\n\n return map;\n }\n\n /**\n * A hash of the model's relationship schemas keyed by relationship name.\n * See also {@link Model.relationshipsByName | relationshipsByName}, which\n * provides the same information as a `Map`.\n */\n @computeOnce\n static get relationshipsObject(): Record<string, LegacyRelationshipField> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const relationships = Object.create(null) as Record<string, LegacyRelationshipField>;\n const modelName = this.modelName;\n this.eachComputedProperty((name: string, meta: unknown) => {\n if (!isRelationshipSchema(meta)) {\n return;\n }\n // TODO deprecate key being here\n (meta as unknown as { key: string }).key = name;\n meta.name = name;\n relationships[name] = meta;\n\n assert(`Expected options in meta`, meta.options && typeof meta.options === 'object');\n assert(\n `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.`,\n !(meta.options.inverse === null && meta.options.as?.length)\n );\n });\n return relationships;\n }\n\n /**\n A map whose keys are the fields of the model and whose values are strings\n describing the kind of the field. A model's fields are the union of all of its\n attributes and relationships.\n\n For example:\n\n ```js [app/models/blog.js]\n import { Model, attr, belongsTo, hasMany } from '@warp-drive/legacy/model';\n\n export default class BlogModel extends Model {\n @hasMany('user') users;\n @belongsTo('user') owner;\n\n @hasMany('post') posts;\n\n @attr('string') title;\n }\n ```\n\n ```js\n import Blog from 'app/models/blog'\n\n let fields = Blog.fields;\n fields.forEach(function(kind, field) {\n // do thing\n });\n\n // prints:\n // users, hasMany\n // owner, belongsTo\n // posts, hasMany\n // title, attribute\n ```\n\n @public\n */\n @computeOnce\n static get fields(): Map<string, 'attribute' | 'belongsTo' | 'hasMany'> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n const map = new Map();\n\n this.eachComputedProperty((name, meta) => {\n if (isRelationshipSchema(meta)) {\n map.set(name, meta.kind);\n } else if (isAttributeSchema(meta)) {\n map.set(name, 'attribute');\n }\n });\n\n return map;\n }\n\n /**\n Given a callback, iterates over each of the relationships in the model,\n invoking the callback with the name of each relationship and its relationship\n descriptor.\n\n @public\n @param callback the callback to invoke\n @param binding the value to which the callback's `this` should be bound\n */\n static eachRelationship<T, Schema extends Model>(\n callback: (\n this: T | undefined,\n key: MaybeRelationshipFields<Schema>,\n relationship: LegacyRelationshipField\n ) => void,\n binding?: T\n ): void {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n this.relationshipsByName.forEach((relationship, name) => {\n callback.call(binding, name as MaybeRelationshipFields<Schema>, relationship);\n });\n }\n\n /**\n Given a callback, iterates over each of the types related to a model,\n invoking the callback with the related type's class. Each type will be\n returned just once, regardless of how many different relationships it has\n with a model.\n\n @public\n @param callback the callback to invoke\n @param binding the value to which the callback's `this` should be bound\n */\n static eachRelatedType<T>(callback: (this: T | undefined, type: string) => void, binding?: T): void {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const relationshipTypes = this.relatedTypes;\n\n for (let i = 0; i < relationshipTypes.length; i++) {\n const type = relationshipTypes[i];\n callback.call(binding, type);\n }\n }\n\n /**\n *\n * @private\n * @deprecated\n */\n static determineRelationshipType(\n knownSide: LegacyRelationshipField,\n store: Store\n ): 'oneToOne' | 'oneToMany' | 'manyToOne' | 'manyToMany' | 'oneToNone' | 'manyToNone' {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const knownKey = knownSide.name;\n const knownKind = knownSide.kind;\n const inverse = this.inverseFor(knownKey, store);\n // let key;\n\n if (!inverse) {\n return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone';\n }\n\n // key = inverse.name;\n const otherKind = inverse.kind;\n\n if (otherKind === 'belongsTo') {\n return knownKind === 'belongsTo' ? 'oneToOne' : 'manyToOne';\n } else {\n return knownKind === 'belongsTo' ? 'oneToMany' : 'manyToMany';\n }\n }\n\n /**\n A map whose keys are the attributes of the model (properties\n described by attr) and whose values are the meta object for the\n property.\n\n Example\n\n ```js [app/models/person.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PersonModel extends Model {\n @attr('string') firstName;\n @attr('string') lastName;\n @attr('date') birthday;\n }\n ```\n\n ```javascript\n import Person from 'app/models/person'\n\n let attributes = Person.attributes\n\n attributes.forEach(function(meta, name) {\n // do thing\n });\n\n // prints:\n // firstName {type: \"string\", kind: 'attribute', options: Object, parentType: function, name: \"firstName\"}\n // lastName {type: \"string\", kind: 'attribute', options: Object, parentType: function, name: \"lastName\"}\n // birthday {type: \"date\", kind: 'attribute', options: Object, parentType: function, name: \"birthday\"}\n ```\n\n @public\n */\n @computeOnce\n static get attributes(): Map<string, LegacyAttributeField> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const map = new Map<string, LegacyAttributeField>();\n\n this.eachComputedProperty((name, meta) => {\n if (isAttributeSchema(meta)) {\n assert(\n \"You may not set 'id' as an attribute on your model. Please remove any lines that look like: `id: attr('<type>')` from \" +\n this.toString(),\n name !== 'id'\n );\n\n // TODO deprecate key being here\n (meta as unknown as { key: string }).key = name;\n meta.name = name;\n map.set(name, meta);\n }\n });\n\n return map;\n }\n\n /**\n A map whose keys are the attributes of the model (properties\n described by attr) and whose values are type of transformation\n applied to each attribute. This map does not include any\n attributes that do not have an transformation type.\n\n Example\n\n ```js [app/models/person.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PersonModel extends Model {\n @attr firstName;\n @attr('string') lastName;\n @attr('date') birthday;\n }\n ```\n\n ```javascript\n import Person from 'app/models/person';\n\n let transformedAttributes = Person.transformedAttributes\n\n transformedAttributes.forEach(function(field, type) {\n // do thing\n });\n\n // prints:\n // lastName string\n // birthday date\n ```\n\n @public\n */\n @computeOnce\n static get transformedAttributes(): Map<string, string> {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n const map = new Map<string, string>();\n\n this.eachAttribute((name: string, meta: LegacyAttributeField) => {\n if (meta.type) {\n map.set(name, meta.type);\n }\n });\n\n return map;\n }\n\n /**\n Iterates through the attributes of the model, calling the passed function on each\n attribute.\n\n The callback method you provide should have the following signature (all\n parameters are optional):\n\n ```javascript\n function(name, meta);\n ```\n\n - `name` the name of the current property in the iteration\n - `meta` the meta object for the attribute property in the iteration\n\n Note that in addition to a callback, you can also pass an optional target\n object that will be set as `this` on the context.\n\n Example\n\n ```javascript\n import { Model, attr } from '@warp-drive/legacy/model';\n\n class PersonModel extends Model {\n @attr('string') firstName;\n @attr('string') lastName;\n @attr('date') birthday;\n }\n\n PersonModel.eachAttribute(function(name, meta) {\n // do thing\n });\n\n // prints:\n // firstName {type: \"string\", kind: 'attribute', options: Object, parentType: function, name: \"firstName\"}\n // lastName {type: \"string\", kind: 'attribute', options: Object, parentType: function, name: \"lastName\"}\n // birthday {type: \"date\", kind: 'attribute', options: Object, parentType: function, name: \"birthday\"}\n ```\n\n @public\n @param callback The callback to execute\n @param binding [optional] the value to which the callback's `this` should be bound\n */\n static eachAttribute<T, Schema extends Model>(\n callback: (this: T | undefined, key: MaybeAttrFields<Schema>, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n this.attributes.forEach((meta, name) => {\n callback.call(binding, name as MaybeAttrFields<Schema>, meta);\n });\n }\n\n /**\n Iterates through the transformedAttributes of the model, calling\n the passed function on each attribute. Note the callback will not be\n called for any attributes that do not have an transformation type.\n\n The callback method you provide should have the following signature (all\n parameters are optional):\n\n ```javascript\n function(name, type);\n ```\n\n - `name` the name of the current property in the iteration\n - `type` a string containing the name of the type of transformed\n applied to the attribute\n\n Note that in addition to a callback, you can also pass an optional target\n object that will be set as `this` on the context.\n\n Example\n\n ```javascript\n import { Model, attr } from '@warp-drive/legacy/model';\n\n let Person = Model.extend({\n firstName: attr(),\n lastName: attr('string'),\n birthday: attr('date')\n });\n\n Person.eachTransformedAttribute(function(name, type) {\n // do thing\n });\n\n // prints:\n // lastName string\n // birthday date\n ```\n\n @public\n @param callback The callback to execute\n @param binding [optional] the value to which the callback's `this` should be bound\n */\n static eachTransformedAttribute<T, Schema extends Model>(\n callback: (this: T | undefined, key: Exclude<keyof Schema & string, keyof Model & string>, type: string) => void,\n binding?: T\n ): void {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n this.transformedAttributes.forEach((type: string, name) => {\n callback.call(binding, name as Exclude<keyof Schema & string, keyof Model & string>, type);\n });\n }\n\n /**\n Returns the name of the model class.\n\n @public\n */\n static toString() {\n assert(\n `Accessing schema information on Models without looking up the model via the store is disallowed.`,\n this.modelName\n );\n\n return `model:${this.modelName}`;\n }\n}\n\n// @ts-expect-error TS doesn't know how to do `this` function overloads\nModel.prototype.save = save;\n// @ts-expect-error TS doesn't know how to do `this` function overloads\nModel.prototype.destroyRecord = destroyRecord;\nModel.prototype.unloadRecord = unloadRecord;\nModel.prototype.hasMany = hasMany;\nModel.prototype.belongsTo = belongsTo;\nModel.prototype.serialize = serialize;\nModel.prototype._createSnapshot = createSnapshot;\nModel.prototype.deleteRecord = deleteRecord;\nModel.prototype.changedAttributes = changedAttributes;\nModel.prototype.rollbackAttributes = rollbackAttributes;\nModel.prototype.reload = reload;\n\ndefineGate(Model.prototype, 'isReloading', {\n get(this: Model): boolean {\n deprecate(\n `record.isReloading is deprecated, please use store.request and either <Request> or getRequuestState to keep track of the request state instead.`,\n false,\n {\n id: 'warp-drive:deprecate-legacy-request-methods',\n until: '6.0',\n for: '@warp-drive/core',\n url: 'https://docs.warp-drive.io/api/@warp-drive/core/build-config/deprecations/variables/ENABLE_LEGACY_REQUEST_METHODS',\n since: {\n enabled: '5.7',\n available: '5.7',\n },\n }\n );\n return this._isReloading ?? false;\n },\n set(this: Model, v: boolean) {\n this._isReloading = v;\n },\n configurable: true,\n // @ts-expect-error specially handled prop\n isLocal: true,\n});\n\n/**\n * Restores the pre-`RequestManager` implementations of `save`,\n * `destroyRecord`, and `reload` onto the given `Model` subclass, for\n * apps that have not yet migrated off of the deprecated\n * `ENABLE_LEGACY_REQUEST_METHODS` behaviors.\n */\nexport function restoreDeprecatedModelRequestBehaviors(ModelKlass: typeof Model): void {\n // @ts-expect-error TS doesn't know how to do `this` function overloads\n ModelKlass.prototype.save = _save;\n // @ts-expect-error TS doesn't know how to do `this` function overloads\n ModelKlass.prototype.destroyRecord = _destroyRecord;\n ModelKlass.prototype.reload = _reload;\n\n defineGate(Model.prototype, 'isReloading', {\n get(this: Model): boolean {\n return this._isReloading ?? false;\n },\n set(this: Model, v: boolean) {\n this._isReloading = v;\n },\n // @ts-expect-error specially handled prop\n isLocal: true,\n });\n}\n\n// this is required to prevent `init` from passing\n// the values initialized during create to `setUnknownProperty`\n(Model.prototype as unknown as { _createProps: null })._createProps = null;\n(Model.prototype as unknown as { _secretInit: null })._secretInit = null;\n\nif (DEBUG) {\n const lookupDescriptor = function lookupDescriptor(obj: object, keyName: string) {\n let current: object = obj;\n do {\n const descriptor = Object.getOwnPropertyDescriptor(current, keyName);\n if (descriptor !== undefined) {\n return descriptor;\n }\n current = Object.getPrototypeOf(current) as object;\n } while (current !== null);\n return null;\n };\n\n // oxlint-disable-next-line typescript/unbound-method\n const init = Model.prototype.init;\n Model.prototype.init = function (createArgs: ModelCreateArgs) {\n init.call(this, createArgs);\n\n const ourDescriptor = lookupDescriptor(Model.prototype, 'currentState');\n const theirDescriptor = lookupDescriptor(this, 'currentState');\n\n if (!ourDescriptor || !theirDescriptor) {\n throw new Error(\n `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()}`\n );\n }\n\n const realState = this.___recordState;\n if (ourDescriptor.get !== theirDescriptor.get || realState !== this.currentState) {\n throw new Error(\n `'currentState' is a reserved property name on instances of classes extending Model. Please choose a different property name for ${this.constructor.toString()}`\n );\n }\n\n const ID_DESCRIPTOR = lookupDescriptor(Model.prototype, 'id');\n const idDesc = lookupDescriptor(this, 'id');\n\n if (!ID_DESCRIPTOR || !idDesc) {\n throw new Error(\n `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()}`\n );\n }\n\n if (idDesc.get !== ID_DESCRIPTOR.get) {\n throw new Error(\n `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()}`\n );\n }\n };\n\n delete (Model as unknown as { reopen: unknown }).reopen;\n delete (Model as unknown as { reopenClass: unknown }).reopenClass;\n}\n\nexport { Model };\n\nfunction isRelationshipSchema(meta: unknown): meta is LegacyRelationshipField {\n const hasKind = typeof meta === 'object' && meta !== null && 'kind' in meta && 'options' in meta;\n return hasKind && (meta.kind === 'hasMany' || meta.kind === 'belongsTo');\n}\n\nfunction isAttributeSchema(meta: unknown): meta is LegacyAttributeField {\n return typeof meta === 'object' && meta !== null && 'kind' in meta && meta.kind === 'attribute';\n}\n","import { getOwner } from '@ember/application';\n\nimport type { Store } from '@warp-drive/core';\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';\nimport { deprecate } from '@ember/debug';\n\nimport type { Store } from '@warp-drive/core';\nimport { ENABLE_LEGACY_SCHEMA_SERVICE } from '@warp-drive/core/build-config/deprecations';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { SchemaService } from '@warp-drive/core/types';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { ObjectValue } from '@warp-drive/core/types/json/raw';\nimport type { Derivation, HashFn, Transformation } from '@warp-drive/core/types/schema/concepts';\nimport type {\n ArrayField,\n CacheableFieldSchema,\n DerivedField,\n GenericField,\n HashField,\n IdentityField,\n LegacyAttributeField,\n LegacyField,\n LegacyRelationshipField,\n ObjectField,\n ObjectSchema,\n ResourceSchema,\n} from '@warp-drive/core/types/schema/fields';\n\nimport _modelForMixin from './model-for-mixin.ts';\nimport type { FactoryCache, ModelFactory, ModelStore } from './model.ts';\nimport { normalizeModelName } from './util.ts';\n\ntype AttributesSchema = ReturnType<Exclude<SchemaService['attributesDefinitionFor'], undefined>>;\ntype RelationshipsSchema = ReturnType<Exclude<SchemaService['relationshipsDefinitionFor'], undefined>>;\n\ntype InternalSchema = {\n schema: ResourceSchema;\n fields: Map<string, LegacyAttributeField | LegacyRelationshipField>;\n cacheFields: Map<string, Exclude<CacheableFieldSchema, IdentityField>>;\n attributes: Record<string, LegacyAttributeField>;\n relationships: Record<string, LegacyRelationshipField>;\n};\n\nexport interface ModelSchemaProvider {\n attributesDefinitionFor(resource: ResourceKey | { type: string }): AttributesSchema;\n\n relationshipsDefinitionFor(resource: ResourceKey | { type: string }): RelationshipsSchema;\n\n doesTypeExist(type: string): boolean;\n}\nexport class ModelSchemaProvider implements SchemaService {\n /** @internal */\n declare private store: ModelStore;\n /** @internal */\n declare private _schemas: Map<string, InternalSchema>;\n /** @internal */\n declare private _typeMisses: Set<string>;\n\n constructor(store: ModelStore) {\n this.store = store;\n this._schemas = new Map();\n this._typeMisses = new Set();\n }\n\n resourceTypes(): Readonly<string[]> {\n return Array.from(this._schemas.keys());\n }\n\n hasTrait(type: string): boolean {\n assert(`hasTrait is not available with @warp-drive/legacy/model's SchemaService`);\n return false;\n }\n resourceHasTrait(resource: ResourceKey | { type: string }, trait: string): boolean {\n assert(`resourceHasTrait is not available with @warp-drive/legacy/model's SchemaService`);\n return false;\n }\n transformation(field: GenericField | ObjectField | ArrayField | { type: string }): Transformation {\n assert(`transformation is not available with @warp-drive/legacy/model's SchemaService`);\n }\n derivation(field: DerivedField | { type: string }): Derivation {\n assert(`derivation is not available with @warp-drive/legacy/model's SchemaService`);\n }\n hashFn(field: HashField | { type: string }): HashFn {\n assert(`hashFn is not available with @warp-drive/legacy/model's SchemaService`);\n }\n resource(resource: ResourceKey | { type: string }): ResourceSchema | ObjectSchema {\n const type = normalizeModelName(resource.type);\n\n if (!this._schemas.has(type)) {\n this._loadModelSchema(type);\n }\n\n return this._schemas.get(type)!.schema;\n }\n registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void {\n assert(`registerResources is not available with @warp-drive/legacy/model's SchemaService`);\n }\n registerResource(schema: ResourceSchema | ObjectSchema): void {\n assert(`registerResource is not available with @warp-drive/legacy/model's SchemaService`);\n }\n registerTransformation(transform: Transformation): void {\n assert(`registerTransformation is not available with @warp-drive/legacy/model's SchemaService`);\n }\n registerDerivation<R, T, FM extends ObjectValue | null>(derivation: Derivation<R, T, FM>): void {\n assert(`registerDerivation is not available with @warp-drive/legacy/model's SchemaService`);\n }\n registerHashFn(hashFn: HashFn): void {\n assert(`registerHashFn is not available with @warp-drive/legacy/model's SchemaService`);\n }\n /** @internal */\n private _loadModelSchema(type: string): InternalSchema {\n const factory = getModelFactory(this.store, type);\n\n if (!factory) {\n throw new Error(`No model was found for '${type}'`);\n }\n\n const modelClass = factory.class;\n const attributeMap = modelClass.attributes;\n\n const attributes = Object.create(null) as AttributesSchema;\n attributeMap.forEach((meta, name) => (attributes[name] = meta));\n const relationships = modelClass.relationshipsObject || null;\n const fields = new Map<string, LegacyAttributeField | LegacyRelationshipField>();\n\n for (const attr of Object.values(attributes)) {\n fields.set(attr.name, attr);\n }\n\n for (const rel of Object.values(relationships)) {\n fields.set(rel.name, rel);\n }\n\n const schema: ResourceSchema = {\n legacy: true,\n identity: { name: 'id', kind: '@id' },\n type,\n fields: Array.from(fields.values()),\n };\n\n const cacheFields = new Map<string, Exclude<CacheableFieldSchema, IdentityField>>();\n for (const field of fields.values()) {\n const cacheKey = field.sourceKey ?? field.name;\n assert(\n `The sourceKey '${field.sourceKey}' for the field '${field.name}' on '${type}' is invalid because it matches the name of an existing field`,\n !field.sourceKey || field.sourceKey === field.name || !fields.has(field.sourceKey)\n );\n cacheFields.set(cacheKey, field);\n }\n\n const internalSchema: InternalSchema = {\n schema,\n attributes,\n relationships,\n fields,\n cacheFields,\n };\n\n this._schemas.set(type, internalSchema);\n\n return internalSchema;\n }\n\n fields(resource: ResourceKey | { type: string }): Map<string, LegacyField> {\n const type = normalizeModelName(resource.type);\n\n if (!this._schemas.has(type)) {\n this._loadModelSchema(type);\n }\n\n return this._schemas.get(type)!.fields;\n }\n\n cacheFields(resource: ResourceKey | { type: string }): Map<string, Exclude<CacheableFieldSchema, IdentityField>> {\n const type = normalizeModelName(resource.type);\n\n if (!this._schemas.has(type)) {\n this._loadModelSchema(type);\n }\n\n return this._schemas.get(type)!.cacheFields;\n }\n\n hasResource(resource: { type: string }): boolean {\n const type = normalizeModelName(resource.type);\n\n if (this._schemas.has(type)) {\n return true;\n }\n\n if (this._typeMisses.has(type)) {\n return false;\n }\n\n const factory = getModelFactory(this.store, type);\n const exists = factory !== null;\n\n if (!exists) {\n this._typeMisses.add(type);\n return false;\n }\n\n return true;\n }\n}\n\nif (ENABLE_LEGACY_SCHEMA_SERVICE) {\n ModelSchemaProvider.prototype.doesTypeExist = function (type: string): boolean {\n deprecate(`Use \\`schema.hasResource({ type })\\` instead of \\`schema.doesTypeExist(type)\\``, false, {\n id: 'ember-data:schema-service-updates',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.4',\n },\n });\n return this.hasResource({ type });\n };\n\n ModelSchemaProvider.prototype.attributesDefinitionFor = function (\n resource: ResourceKey | { type: string }\n ): AttributesSchema {\n deprecate(`Use \\`schema.fields({ type })\\` instead of \\`schema.attributesDefinitionFor({ type })\\``, false, {\n id: 'ember-data:schema-service-updates',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.4',\n },\n });\n const type = normalizeModelName(resource.type);\n\n // @ts-expect-error intentional use of internal API\n if (!this._schemas.has(type)) {\n // @ts-expect-error intentional use of internal API\n this._loadModelSchema(type);\n }\n\n // @ts-expect-error intentional use of internal API\n return this._schemas.get(type)!.attributes;\n };\n\n ModelSchemaProvider.prototype.relationshipsDefinitionFor = function (\n resource: ResourceKey | { type: string }\n ): RelationshipsSchema {\n deprecate(`Use \\`schema.fields({ type })\\` instead of \\`schema.relationshipsDefinitionFor({ type })\\``, false, {\n id: 'ember-data:schema-service-updates',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.4',\n },\n });\n const type = normalizeModelName(resource.type);\n\n // @ts-expect-error intentional use of internal API\n if (!this._schemas.has(type)) {\n // @ts-expect-error intentional use of internal API\n this._loadModelSchema(type);\n }\n\n // @ts-expect-error intentional use of internal API\n return this._schemas.get(type)!.relationships;\n };\n}\n\n/**\n * The `createSchemaService` implementation for use with `Model`. Pass\n * the result of this to your store's `createSchemaService` method when\n * configuring the store to use `Model` for schema information.\n *\n * @public\n */\nexport function buildSchema(store: Store): SchemaService {\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"],"mappings":";;;;;;;;;;;;;;AAqCA,SAAgBM,qBAAiE;CAC/E,MAAM,EAAEC,iBAAiB;CACzB,MAAM,EAAEC,UAAUD;CAClB,MAAME,QAAQ,KAAKP;CACnBD,mBAAmBQ,KAAK;CAExBA,MAAMC,YAAY;EAChBD,MAAME,MAAMC,cAAcZ,oBAAoB,IAAI,CAAC;EACnD,KAAKa,OAAOC,MAAM;EAClBP,aAAaQ,mBAAmB;EAChC,IAAIP,OACF,KAAKQ,aAAa;CAEtB,CAAC;AACH;AAEA,SAAgBA,eAA2D;CACzE,IAAI,KAAKT,aAAaC,UAAU,KAAKS,eAAe,KAAKC,eACvD;CAEF,KAAKhB,YAAY,CAACc,aAAa,IAAI;AACrC;AAEA,SAAgBG,UAEdC,MAC0B;CAC1B,OAAOf,oBAAoB,IAAI,CAAC,CAACgB,aAAa,aAAaD,IAAI;AACjE;AAEA,SAAgBE,QAEdF,MACwB;CACxB,OAAOf,oBAAoB,IAAI,CAAC,CAACgB,aAAa,WAAWD,IAAI;AA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AAI;EAE7C,IAAI,KAAKT,SAASiB,IAAIR,IAAI,GACxB,OAAO;EAGT,IAAI,KAAKP,YAAYe,IAAIR,IAAI,GAC3B,OAAO;EAMT,IAAI,EAHYoB,gBAAgB,KAAK9B,OAAOU,IAC7BmB,MAAY,OAEd;GACX,KAAK1B,YAAYsD,IAAI/C,IAAI;GACzB,OAAO;EACT;EAEA,OAAO;CACT;AACF;;;;;;;;AAwEA,SAAgBgD,YAAY1D,OAA6B;CACvD,OAAO,IAAIF,oBAAoBE,KAAmB;AACpD;AAEA,SAAgB8B,gBAAgB9B,OAAmBU,MAAmC;CACpF,IAAI,CAACV,MAAM2D,oBACT3D,MAAM2D,qBAAqBvB,OAAOC,OAAO,IAAI;CAE/C,MAAMuB,QAAQ5D,MAAM2D;CACpB,IAAI9B,UAAoC+B,MAAMlD;CAE9C,IAAI,CAACmB,SAAS;EAEZA,UADclC,SAASK,KACb6D,CAAK,CAACC,WAAW,SAASpD,MAAM;EAE1C,IAAI,CAACmB,SAEHA,UAAUjC,cAAeI,OAAOU,IAAI;EAGtC,IAAI,CAACmB,SAEH,OAAO;EAGT,MAAMkC,QAAQlC,QAAQI;EAEtB,IAAI8B,MAAMC,SAER;OAAI,EADuBD,MAAMG,aAAa9B,OAAO+B,UAAUC,eAAeC,KAAKN,OAAO,WAAW,IAEnG3B,OAAOkC,eAAeP,OAAO,aAAa,EAAEQ,OAAO7D,KAAK,CAAC;EAC3D;EAGFkD,MAAMlD,QAAQmB;CAChB;CAEA,OAAOA;AACT"}
|
|
@@ -1256,6 +1256,13 @@ defineNonEnumerableSignal(BelongsToReference.prototype, "_ref", 0);
|
|
|
1256
1256
|
//#endregion
|
|
1257
1257
|
//#region src/model/-private/legacy-relationships-support.ts
|
|
1258
1258
|
const LEGACY_SUPPORT = getOrSetGlobal("LEGACY_SUPPORT", /* @__PURE__ */ new Map());
|
|
1259
|
+
function releaseLegacySupport(identifier) {
|
|
1260
|
+
const support = LEGACY_SUPPORT.get(identifier);
|
|
1261
|
+
if (support) {
|
|
1262
|
+
support.destroy();
|
|
1263
|
+
LEGACY_SUPPORT.delete(identifier);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1259
1266
|
function lookupLegacySupport(record) {
|
|
1260
1267
|
const identifier = recordIdentifierFor(record);
|
|
1261
1268
|
let support = LEGACY_SUPPORT.get(identifier);
|
|
@@ -1974,5 +1981,5 @@ var Errors = class extends ArrayProxyWithCustomOverrides {
|
|
|
1974
1981
|
};
|
|
1975
1982
|
|
|
1976
1983
|
//#endregion
|
|
1977
|
-
export {
|
|
1978
|
-
//# sourceMappingURL=errors-
|
|
1984
|
+
export { PromiseManyArray as a, releaseLegacySupport as i, LEGACY_SUPPORT as n, PromiseBelongsTo as o, lookupLegacySupport as r, Errors as t };
|
|
1985
|
+
//# sourceMappingURL=errors-ii4L43_1.js.map
|