@warp-drive/legacy 5.10.0-alpha.21 → 5.10.0-alpha.23
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/adapter/-private.d.ts +1 -1
- package/dist/adapter/json-api.d.ts +6 -1
- package/dist/adapter/json-api.d.ts.map +1 -1
- package/dist/adapter/rest.d.ts +1 -1
- package/dist/adapter/rest.js +2 -2
- package/dist/adapter.d.ts +218 -0
- package/dist/compat/builders.d.ts +12 -0
- package/dist/compat/builders.d.ts.map +1 -1
- package/dist/compat/extensions.d.ts +5 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/model/migration-support.js +1 -1
- package/dist/{model-Be-e84FX.js → model-EM9IS3kJ.js} +2 -2
- package/dist/{model-Be-e84FX.js.map → model-EM9IS3kJ.js.map} +1 -1
- package/dist/{unpkg/dev/model-fragments-DCHMDr5f.js → model-fragments-bM9vucwt.js} +2 -2
- package/dist/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
- package/dist/model-fragments.d.ts +5 -0
- package/dist/model-fragments.d.ts.map +1 -1
- package/dist/model-fragments.js +1 -1
- package/dist/model.d.ts +68 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -2
- package/dist/{rest-CmFneLJH.d.ts → rest-CzVG2wcS.d.ts} +2 -2
- package/dist/{rest-CmFneLJH.d.ts.map → rest-CzVG2wcS.d.ts.map} +1 -1
- package/dist/{schema-provider-BAB8DyMr.js → schema-provider-BsP-TyJN.js} +3 -3
- package/dist/{schema-provider-BAB8DyMr.js.map → schema-provider-BsP-TyJN.js.map} +1 -1
- package/dist/serializer/transform.d.ts +5 -0
- package/dist/serializer/transform.d.ts.map +1 -1
- package/dist/serializer.d.ts +143 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/{store-BLKEsJyw.js → store-09VISmB-.js} +2 -2
- package/dist/{store-BLKEsJyw.js.map → store-09VISmB-.js.map} +1 -1
- package/dist/store.d.ts +5 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +1 -1
- package/dist/unpkg/dev/adapter/rest.js +2 -2
- package/dist/unpkg/dev/index.js +3 -3
- package/dist/unpkg/dev/model/migration-support.js +1 -1
- package/dist/unpkg/dev/{model-QCZr8eec.js → model-BRhfRvm7.js} +2 -2
- package/dist/unpkg/dev/{model-QCZr8eec.js.map → model-BRhfRvm7.js.map} +1 -1
- package/dist/{model-fragments-DCHMDr5f.js → unpkg/dev/model-fragments-bM9vucwt.js} +2 -2
- package/dist/unpkg/dev/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
- package/dist/unpkg/dev/model-fragments.js +1 -1
- package/dist/unpkg/dev/model.js +2 -2
- package/dist/unpkg/dev/{schema-provider-IMFO9Kgw.js → schema-provider-KpRvBrnz.js} +3 -3
- package/dist/unpkg/dev/{schema-provider-IMFO9Kgw.js.map → schema-provider-KpRvBrnz.js.map} +1 -1
- package/dist/unpkg/dev/{store-BiXsLLAu.js → store-DwneLtlP.js} +2 -2
- package/dist/unpkg/{dev-deprecated/store-Ci8k7Lh6.js.map → dev/store-DwneLtlP.js.map} +1 -1
- package/dist/unpkg/dev/store.js +1 -1
- package/dist/unpkg/dev-deprecated/adapter/rest.js +2 -2
- package/dist/unpkg/dev-deprecated/index.js +3 -3
- package/dist/unpkg/dev-deprecated/model/migration-support.js +1 -1
- package/dist/unpkg/dev-deprecated/{model-B0ZNLaHO.js → model-C5LZIABq.js} +2 -2
- package/dist/unpkg/dev-deprecated/{model-B0ZNLaHO.js.map → model-C5LZIABq.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/{model-fragments-DCHMDr5f.js → model-fragments-bM9vucwt.js} +2 -2
- package/dist/unpkg/dev-deprecated/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/model-fragments.js +1 -1
- package/dist/unpkg/dev-deprecated/model.js +2 -2
- package/dist/unpkg/dev-deprecated/{schema-provider-DGWYnFno.js → schema-provider-BHW1XG6Q.js} +3 -3
- package/dist/unpkg/dev-deprecated/{schema-provider-DGWYnFno.js.map → schema-provider-BHW1XG6Q.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/{store-Ci8k7Lh6.js → store-CBtAELz5.js} +2 -2
- package/dist/unpkg/{dev/store-BiXsLLAu.js.map → dev-deprecated/store-CBtAELz5.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/store.js +1 -1
- package/dist/unpkg/prod/adapter/rest.js +2 -2
- package/dist/unpkg/prod/index.js +3 -3
- package/dist/unpkg/prod/model/migration-support.js +1 -1
- package/dist/unpkg/prod/{model-QtC0IWbE.js → model-QIzJrhcV.js} +2 -2
- package/dist/unpkg/prod/{model-QtC0IWbE.js.map → model-QIzJrhcV.js.map} +1 -1
- package/dist/unpkg/prod/model-fragments-bM9vucwt.js +348 -0
- package/dist/unpkg/prod/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
- package/dist/unpkg/prod/model-fragments.js +1 -1
- package/dist/unpkg/prod/model.js +2 -2
- package/dist/unpkg/prod/{schema-provider-DPOzTa8e.js → schema-provider-D_H0kna2.js} +3 -3
- package/dist/unpkg/prod/{schema-provider-DPOzTa8e.js.map → schema-provider-D_H0kna2.js.map} +1 -1
- package/dist/unpkg/prod/{store-BsSkzWgk.js → store-BB1Ab-3t.js} +2 -2
- package/dist/unpkg/{prod-deprecated/store-Dsw2f4s-.js.map → prod/store-BB1Ab-3t.js.map} +1 -1
- package/dist/unpkg/prod/store.js +1 -1
- package/dist/unpkg/prod-deprecated/adapter/rest.js +2 -2
- package/dist/unpkg/prod-deprecated/index.js +3 -3
- package/dist/unpkg/prod-deprecated/model/migration-support.js +1 -1
- package/dist/unpkg/prod-deprecated/{model-B946S2pl.js → model-Dik7yYTm.js} +2 -2
- package/dist/unpkg/prod-deprecated/{model-B946S2pl.js.map → model-Dik7yYTm.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/{model-fragments-DCHMDr5f.js → model-fragments-bM9vucwt.js} +2 -2
- package/dist/unpkg/prod-deprecated/{model-fragments-DCHMDr5f.js.map → model-fragments-bM9vucwt.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/model-fragments.js +1 -1
- package/dist/unpkg/prod-deprecated/model.js +2 -2
- package/dist/unpkg/prod-deprecated/{schema-provider-xcaytn9y.js → schema-provider-BKBnIcPE.js} +3 -3
- package/dist/unpkg/prod-deprecated/{schema-provider-xcaytn9y.js.map → schema-provider-BKBnIcPE.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/{store-Dsw2f4s-.js → store-Cp64p5ZC.js} +2 -2
- package/dist/unpkg/{prod/store-BsSkzWgk.js.map → prod-deprecated/store-Cp64p5ZC.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/store.js +1 -1
- package/package.json +8 -8
- package/dist/unpkg/prod/model-fragments-DCHMDr5f.js +0 -348
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as normalizeModelName } from "./util-CVu5_VeN.js";
|
|
2
1
|
import { t as isMaybeIdentifier } from "./utils-z1h-zTls.js";
|
|
2
|
+
import { n as normalizeModelName } from "./util-CVu5_VeN.js";
|
|
3
3
|
import { assertPrivateStore, constructResource, ensureStringId, recordIdentifierFor } from "@warp-drive/core/store/-private";
|
|
4
4
|
import { getOrSetGlobal } from "@warp-drive/core/types/-private";
|
|
5
5
|
import { defineSignal } from "@warp-drive/core/signals/-leaked";
|
|
@@ -395,4 +395,4 @@ function upgradeInstanceCaches(cache) {
|
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
export { restoreDeprecatedStoreBehaviors as t };
|
|
398
|
-
//# sourceMappingURL=store-
|
|
398
|
+
//# sourceMappingURL=store-Cp64p5ZC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-BsSkzWgk.js","names":["defineSignal","assertPrivateStore","ensureStringId","recordIdentifierFor","getOrSetGlobal","preloadData","store","identifier","preload","jsonPayload","schemas","schema","fields","Object","keys","forEach","key","preloadValue","field","get","kind","relationships","preloadRelationship","attributes","cache","hasRecord","Boolean","_instanceCache","peek","upsert","relatedType","type","data","map","value","_convertPreloadRelationshipToJSON","id","_resourceIsFullDeleted","isDeletionCommitted","isNew","isDeleted","resourceIsFullyDeleted","instanceCache","RecordReference","___token","___identifier","constructor","notifications","subscribe","_","bucket","notifiedKey","_ref","destroy","unsubscribe","remoteType","push","objectOrPromise","Promise","resolve","then","peekRecord","load","findRecord","reload","prototype","AvailableShims","WeakMap","getShimClass","modelName","shims","create","set","shim","undefined","ShimModelClass","__store","Map","fieldSchemas","attrs","relationshipsByName","rels","eachAttribute","callback","binding","call","eachRelationship","eachTransformedAttribute","assertPrivateStore","constructResource","ensureStringId","recordIdentifierFor","storeFor","SkipCache","isMaybeIdentifier","normalizeModelName","getShimClass","preloadData","RecordReference","resourceIsFullyDeleted","restoreDeprecatedStoreBehaviors","StoreKlass","prototype","findRecord","resource","id","options","type","normalizedId","identifier","cacheKeyManager","getOrCreateRecordIdentifier","preload","_instanceCache","recordIsLoaded","reload","_join","promise","request","op","data","record","cacheOptions","then","document","content","findAll","query","queryRecord","getReference","resourceIdentifier","arguments","length","cache","upgradeInstanceCaches","__instances","reference","get","set","modelFor","saveRecord","Promise","reject","Error","resolve","operation","isNew","isDeleted","records","withReferences","WeakMap"],"sources":["../../../src/store/-private.ts","../../../src/store.ts"],"sourcesContent":["import type { NotificationType } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { defineSignal } from '@warp-drive/core/signals/-leaked';\nimport {\n assertPrivateStore,\n ensureStringId,\n type InstanceCache,\n recordIdentifierFor,\n} from '@warp-drive/core/store/-private';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { NewResourceKey, ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n LegacyAttributeField,\n LegacyRelationshipField,\n LegacyRelationshipField as RelationshipSchema,\n} from '@warp-drive/core/types/schema/fields';\nimport type {\n ExistingResourceIdentifierObject,\n ExistingResourceObject,\n InnerRelationshipDocument,\n SingleResourceDocument,\n} from '@warp-drive/core/types/spec/json-api-raw';\n\nimport type { Store } from '../store.ts';\n\n/*\n When a find request is triggered on the store, the user can optionally pass in\n attributes and relationships to be preloaded. These are meant to behave as if they\n came back from the server, except the user obtained them out of band and is informing\n the store of their existence. The most common use case is for supporting client side\n nested URLs, such as `/posts/1/comments/2` so the user can do\n `store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.\n\n Preloaded data can be attributes and relationships passed in either as IDs or as actual\n models.\n */\ntype PreloadRelationshipValue = OpaqueRecordInstance | string;\nexport function preloadData(store: Store, identifier: NewResourceKey, preload: Record<string, Value>): void {\n const jsonPayload: Partial<ExistingResourceObject> = {};\n //TODO(Igor) consider the polymorphic case\n const schemas = store.schema;\n const fields = schemas.fields(identifier);\n Object.keys(preload).forEach((key) => {\n const preloadValue = preload[key];\n\n const field = fields.get(key);\n if (field && (field.kind === 'hasMany' || field.kind === 'belongsTo')) {\n if (!jsonPayload.relationships) {\n jsonPayload.relationships = {};\n }\n jsonPayload.relationships[key] = preloadRelationship(field, preloadValue);\n } else {\n if (!jsonPayload.attributes) {\n jsonPayload.attributes = {};\n }\n jsonPayload.attributes[key] = preloadValue;\n }\n });\n const cache = store.cache;\n assertPrivateStore(store);\n const hasRecord = Boolean(store._instanceCache.peek(identifier));\n cache.upsert(identifier, jsonPayload, hasRecord);\n}\n\nfunction preloadRelationship(\n schema: RelationshipSchema,\n preloadValue: PreloadRelationshipValue | null | Array<PreloadRelationshipValue>\n): InnerRelationshipDocument<ExistingResourceIdentifierObject> {\n const relatedType = schema.type;\n\n if (schema.kind === 'hasMany') {\n assert('You need to pass in an array to set a hasMany property on a record', Array.isArray(preloadValue));\n return { data: preloadValue.map((value) => _convertPreloadRelationshipToJSON(value, relatedType)) };\n }\n\n assert('You should not pass in an array to set a belongsTo property on a record', !Array.isArray(preloadValue));\n return { data: preloadValue ? _convertPreloadRelationshipToJSON(preloadValue, relatedType) : null };\n}\n\n/*\n findRecord('user', '1', { preload: { friends: ['1'] }});\n findRecord('user', '1', { preload: { friends: [record] }});\n*/\nfunction _convertPreloadRelationshipToJSON(\n value: OpaqueRecordInstance | string,\n type: string\n): ExistingResourceIdentifierObject {\n if (typeof value === 'string' || typeof value === 'number') {\n return { type, id: ensureStringId(value) };\n }\n // TODO if not a record instance assert it's an identifier\n // and allow identifiers to be used\n return recordIdentifierFor(value) as ExistingResourceIdentifierObject;\n}\n\nexport interface BaseFinderOptions {\n reload?: boolean;\n backgroundReload?: boolean;\n include?: string | string[];\n adapterOptions?: Record<string, unknown>;\n}\nexport interface FindRecordOptions extends BaseFinderOptions {\n /**\n * Data to preload into the store before the request is made.\n * This feature is *highly* discouraged and has no corresponding\n * feature when using builders and handlers.\n *\n * Excepting relationships: the data should be in the form of a\n * JSON object where the keys are fields on the record and the value\n * is the raw value to be added to the cache.\n *\n * Relationships can either be provided as string IDs from which\n * an identifier will be built base upon the relationship's expected\n * resource type, or be record instances from which the identifier\n * will be extracted.\n *\n */\n preload?: Record<string, Value>;\n}\n\nexport type QueryOptions = {\n [K in string | 'adapterOptions']?: K extends 'adapterOptions' ? Record<string, unknown> : unknown;\n};\n\nexport type FindAllOptions = BaseFinderOptions;\nexport type LegacyResourceQuery = {\n include?: string | string[];\n [key: string]: Value | undefined;\n};\n\nexport type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;\n\n/**\n * Minimum subset of static schema methods and properties on the\n * \"model\" class.\n *\n * Only used when using the legacy schema-service implementation\n * for @ember-data/model or when wrapping schema for legacy\n * Adapters/Serializers.\n *\n */\nexport interface ModelSchema<T = unknown> {\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n fields: Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>;\n attributes: Map<KeyOrString<T>, LegacyAttributeField>;\n relationshipsByName: Map<KeyOrString<T>, LegacyRelationshipField>;\n eachAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void;\n eachRelationship<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void;\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, type: string | null) => void,\n binding?: T\n ): void;\n}\n\nfunction _resourceIsFullDeleted(identifier: ResourceKey, cache: Cache): boolean {\n return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));\n}\n\nexport function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: ResourceKey): boolean {\n const cache = instanceCache.cache;\n return !cache || _resourceIsFullDeleted(identifier, cache);\n}\n\n/**\n A `RecordReference` is a low-level API that allows users and\n addon authors to perform meta-operations on a record.\n\n @hideconstructor\n @public\n*/\nexport class RecordReference {\n /** @internal */\n declare private store: Store;\n // unsubscribe token given to us by the notification manager\n /** @internal */\n private ___token!: object;\n /** @internal */\n private ___identifier: ResourceKey;\n /** @internal */\n declare private _ref: number;\n\n constructor(store: Store, identifier: ResourceKey) {\n this.store = store;\n this.___identifier = identifier;\n this.___token = store.notifications.subscribe(\n identifier,\n (_: ResourceKey, bucket: NotificationType, notifiedKey?: string) => {\n if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {\n this._ref++;\n }\n }\n );\n }\n\n /** @internal */\n destroy(): void {\n this.store.notifications.unsubscribe(this.___token);\n }\n\n get type(): string {\n return this.identifier().type;\n }\n\n /**\n The `id` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.id(); // '1'\n ```\n\n @public\n @return The id of the record.\n */\n id(): string | null {\n // oxlint-disable-next-line no-unused-expressions\n this._ref; // consume the tracked prop\n return this.___identifier.id;\n }\n\n /**\n The `identifier` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.identifier(); // '1'\n ```\n\n @public\n @return The identifier of the record.\n */\n identifier(): ResourceKey {\n return this.___identifier;\n }\n\n /**\n How the reference will be looked up when it is loaded. Currently\n this always returns `identity` to signify that a record will be\n loaded by its `type` and `id`.\n\n Example\n\n ```javascript\n const userRef = store.getReference('user', 1);\n\n userRef.remoteType(); // 'identity'\n ```\n\n @public\n */\n remoteType(): 'identity' {\n return 'identity';\n }\n\n /**\n This API allows you to provide a reference with new data. The\n simplest usage of this API is similar to `store.push`: you provide a\n normalized hash of data and the object represented by the reference\n will update.\n\n If you pass a promise to `push`, WarpDrive will not ask the adapter\n for the data if another attempt to fetch it is made in the\n interim. When the promise resolves, the underlying object is updated\n with the new data, and the promise returned by *this function* is resolved\n with that object.\n\n For example, `recordReference.push(promise)` will be resolved with a\n record.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // provide data for reference\n userRef.push({\n data: {\n id: \"1\",\n type: \"user\",\n attributes: {\n username: \"@user\"\n }\n }\n }).then(function(user) {\n userRef.value() === user;\n });\n ```\n\n @public\n @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one\n @return a promise for the value (record or relationship)\n */\n push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance> {\n // TODO @deprecate pushing unresolved payloads\n return Promise.resolve(objectOrPromise).then((data) => {\n return this.store.push(data);\n });\n }\n\n /**\n If the entity referred to by the reference is already loaded, it is\n present as `reference.value`. Otherwise the value returned by this function\n is `null`.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.value(); // user\n ```\n\n @public\n @return the record for this RecordReference\n */\n value(): OpaqueRecordInstance | null {\n return this.store.peekRecord(this.___identifier);\n }\n\n /**\n Triggers a fetch for the backing entity based on its `remoteType`\n (see `remoteType` definitions per reference type).\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // load user (via store.find)\n userRef.load().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n load(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id);\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n\n /**\n Reloads the record if it is already loaded. If the record is not\n loaded it will load the record via `store.findRecord`\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // or trigger a reload\n userRef.reload().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n reload(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id, { reload: true });\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n}\n\ndefineSignal(RecordReference.prototype, '_ref');\n\n// if modelFor turns out to be a bottleneck we should replace with a Map\n// and clear it during store teardown.\nconst AvailableShims = getOrSetGlobal('AvailableShims', new WeakMap<Store, Record<string, ShimModelClass>>());\n\nexport function getShimClass<T>(\n store: Store,\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n): ShimModelClass<T> {\n let shims = AvailableShims.get(store);\n\n if (!shims) {\n shims = Object.create(null) as Record<string, ShimModelClass>;\n AvailableShims.set(store, shims);\n }\n\n let shim = shims[modelName];\n if (shim === undefined) {\n shim = shims[modelName] = new ShimModelClass<unknown>(store, modelName);\n }\n\n return shim;\n}\n\n// Mimics the static apis of @ember-data/model\nexport class ShimModelClass<T = unknown> implements ModelSchema<T> {\n declare __store: Store;\n declare modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string) {\n this.__store = store;\n this.modelName = modelName;\n }\n\n get fields(): Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'> {\n const fields = new Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>();\n const fieldSchemas = this.__store.schema.fields({ type: this.modelName });\n\n fieldSchemas.forEach((schema, key) => {\n if (schema.kind === 'attribute' || schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n fields.set(key as KeyOrString<T>, schema.kind);\n }\n });\n\n return fields;\n }\n\n get attributes(): Map<KeyOrString<T>, LegacyAttributeField> {\n const attrs = new Map<KeyOrString<T>, LegacyAttributeField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n attrs.set(key as KeyOrString<T>, schema);\n }\n });\n\n return attrs;\n }\n\n get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField> {\n const rels = new Map<KeyOrString<T>, LegacyRelationshipField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n rels.set(key as KeyOrString<T>, schema);\n }\n });\n\n return rels;\n }\n\n eachAttribute<K extends KeyOrString<T>>(\n callback: (key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachRelationship<K extends KeyOrString<T>>(\n callback: (key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (key: K, type: string | null) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n const type = schema.type;\n if (type) callback.call(binding, key as K, type);\n }\n });\n }\n}\n","/**\n * @module\n * @summary Legacy `restoreDeprecatedStoreBehaviors`, which restores the adapter-based `findRecord`, `findAll`, `query`,\n * `saveRecord` and related methods onto a `Store` class.\n */\n\nimport type { Store } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { LegacyLiveArray, LegacyQueryArray, PrivateStore } from '@warp-drive/core/store/-private';\nimport {\n assertPrivateStore,\n constructResource,\n ensureStringId,\n recordIdentifierFor,\n storeFor,\n} from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport { SkipCache } from '@warp-drive/core/types/request';\nimport type { ResourceIdentifierObject } from '@warp-drive/core/types/spec/json-api-raw';\n\nimport { isMaybeIdentifier } from './compat/builders/utils.ts';\nimport { normalizeModelName } from './model/-private/util.ts';\nimport type {\n FindAllOptions,\n FindRecordOptions,\n LegacyResourceQuery,\n ModelSchema,\n QueryOptions,\n} from './store/-private.ts';\nimport { getShimClass, preloadData, RecordReference, resourceIsFullyDeleted } from './store/-private.ts';\n\n/**\n * Restores the deprecated `findRecord`/`findAll`/`query`/`queryRecord`/\n * `findBelongsTo`/`findHasMany`/`createRecord`/`deleteRecord`/`saveRecord`\n * legacy-network-layer implementations of these methods onto the given\n * `Store` subclass, for apps that have not yet migrated to the\n * `RequestManager`-based equivalents.\n *\n * @summary Legacy opt-in that restores the adapter-based `findRecord`, `findAll`, `query`, `saveRecord`, and related\n * methods onto a `Store` class.\n */\nexport function restoreDeprecatedStoreBehaviors(StoreKlass: typeof Store): void {\n StoreKlass.prototype.findRecord = function (\n resource: string | ResourceIdentifierObject,\n id?: string | number | FindRecordOptions,\n options?: FindRecordOptions\n ): Promise<unknown> {\n assert(\n `Attempted to call store.findRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n assert(\n `You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`,\n resource\n );\n if (isMaybeIdentifier(resource)) {\n options = id as FindRecordOptions;\n } else {\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`,\n typeof resource === 'string'\n );\n const type = normalizeModelName(resource);\n const normalizedId = ensureStringId(id as string | number);\n resource = constructResource(type, normalizedId);\n }\n\n const identifier = this.cacheKeyManager.getOrCreateRecordIdentifier(resource);\n options = options || {};\n assertPrivateStore(this);\n\n if (options.preload) {\n // force reload if we preload to ensure we don't resolve the promise\n // until we are complete, else we will end up background-reloading\n // even for initial load.\n if (!this._instanceCache.recordIsLoaded(identifier)) {\n options.reload = true;\n }\n this._join(() => {\n preloadData(this, identifier, options.preload!);\n });\n }\n\n const promise = this.request<OpaqueRecordInstance>({\n op: 'findRecord',\n data: {\n record: identifier,\n options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => {\n return document.content;\n });\n };\n\n StoreKlass.prototype.findAll = function <T>(\n type: TypeFromInstance<T> | string,\n options: FindAllOptions = {}\n ): Promise<LegacyLiveArray<T>> {\n assert(\n `Attempted to call store.findAll(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's findAll method`, type);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyLiveArray<T>>({\n op: 'findAll',\n data: {\n type: normalizeModelName(type),\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.query = function (\n type: string,\n query: LegacyResourceQuery,\n options: QueryOptions = {}\n ): Promise<LegacyQueryArray> {\n assert(\n `Attempted to call store.query(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's query method`, type);\n assert(`You need to pass a query hash to the store's query method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyQueryArray>({\n op: 'query',\n data: {\n type: normalizeModelName(type),\n query,\n options: options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.queryRecord = function (\n type: string,\n query: Record<string, unknown>,\n options?: QueryOptions\n ): Promise<OpaqueRecordInstance | null> {\n assert(\n `Attempted to call store.queryRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's queryRecord method`, type);\n assert(`You need to pass a query hash to the store's queryRecord method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<OpaqueRecordInstance | null>({\n op: 'queryRecord',\n data: {\n type: normalizeModelName(type),\n query,\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n // do not put a ts-expect-error here, because typedoc will fail to\n // build due to this error only occurring when references are in use in the editor.\n // The return statement below casts to `PrivateStore['getReference']`'s return\n // type rather than annotating this function `: RecordReference` directly,\n // since this package's `RecordReference` and core's `deprecated/-private.ts`\n // copy are structurally identical but nominally distinct classes (TS treats\n // their private fields as separate brands); casting only the return value\n // (instead of the whole function) keeps `this` contextually typed from the\n // assignment target below.\n StoreKlass.prototype.getReference = function (resource: string | ResourceIdentifierObject, id: string | number) {\n assert(\n `Attempted to call store.getReference(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n let resourceIdentifier: ResourceIdentifierObject;\n if (arguments.length === 1 && isMaybeIdentifier(resource)) {\n resourceIdentifier = resource;\n } else {\n const type = normalizeModelName(resource as string);\n const normalizedId = ensureStringId(id);\n resourceIdentifier = constructResource(type, normalizedId);\n }\n\n assert(\n 'getReference expected to receive either a resource identifier or type and id as arguments',\n isMaybeIdentifier(resourceIdentifier)\n );\n\n const identifier: ResourceKey = this.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);\n assertPrivateStore(this);\n\n const cache = upgradeInstanceCaches(this._instanceCache.__instances).reference;\n let reference = cache.get(identifier);\n\n if (!reference) {\n reference = new RecordReference(this, identifier);\n cache.set(identifier, reference);\n }\n return reference;\n };\n\n StoreKlass.prototype.modelFor = function <T>(\n type: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n ): ModelSchema<T> {\n assert(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`, !this.isDestroyed);\n assert(`You need to pass <type> to the store's modelFor method`, typeof type === 'string' && type.length);\n assert(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n\n return getShimClass<T>(this, type);\n };\n\n StoreKlass.prototype.saveRecord = function <T>(record: T, options: Record<string, unknown> = {}): Promise<T> {\n assert(\n `Attempted to call store.saveRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`Unable to initiate save for a record in a disconnected state`, storeFor(record, true));\n const identifier = recordIdentifierFor(record);\n const cache = this.cache;\n\n if (!identifier) {\n // this commonly means we're disconnected\n // but just in case we reject here to prevent bad things.\n return Promise.reject(new Error(`Record Is Disconnected`));\n }\n assertPrivateStore(this);\n assert(\n `Cannot initiate a save request for an unloaded record: ${identifier.lid}`,\n this._instanceCache.recordIsLoaded(identifier)\n );\n if (resourceIsFullyDeleted(this._instanceCache, identifier)) {\n return Promise.resolve(record);\n }\n\n if (!options) {\n options = {};\n }\n let operation: 'createRecord' | 'deleteRecord' | 'updateRecord' = 'updateRecord';\n\n if (cache.isNew(identifier)) {\n operation = 'createRecord';\n } else if (cache.isDeleted(identifier)) {\n operation = 'deleteRecord';\n }\n\n const request = {\n op: operation,\n data: {\n options,\n record: identifier,\n },\n records: [identifier],\n cacheOptions: { [SkipCache]: true },\n };\n\n return this.request<T>(request).then((document) => document.content);\n };\n}\n\nexport type { Store };\n\ntype Caches = PrivateStore['_instanceCache']['__instances'];\nfunction upgradeInstanceCaches(cache: Caches): Caches & { reference: WeakMap<ResourceKey, RecordReference> } {\n const withReferences = cache as Caches & { reference: WeakMap<ResourceKey, RecordReference> };\n if (!withReferences.reference) {\n withReferences.reference = new WeakMap();\n }\n\n return withReferences;\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgBK,YAAYC,OAAcC,YAA4BC,SAAsC;CAC1G,MAAMC,cAA+C,CAAC;CAGtD,MAAMG,SADUN,MAAMK,OACCC,OAAOL,UAAU;CACxCM,OAAOC,KAAKN,OAAO,CAAC,CAACO,SAASC,QAAQ;EACpC,MAAMC,eAAeT,QAAQQ;EAE7B,MAAME,QAAQN,OAAOO,IAAIH,GAAG;EAC5B,IAAIE,UAAUA,MAAME,SAAS,aAAaF,MAAME,SAAS,cAAc;GACrE,IAAI,CAACX,YAAYY,eACfZ,YAAYY,gBAAgB,CAAC;GAE/BZ,YAAYY,cAAcL,OAAOM,oBAAoBJ,OAAOD,YAAY;EAC1E,OAAO;GACL,IAAI,CAACR,YAAYc,YACfd,YAAYc,aAAa,CAAC;GAE5Bd,YAAYc,WAAWP,OAAOC;EAChC;CACF,CAAC;CACD,MAAMO,QAAQlB,MAAMkB;CACpBvB,mBAAmBK,KAAK;CACxB,MAAMmB,YAAYC,QAAQpB,MAAMqB,eAAeC,KAAKrB,UAAU,CAAC;CAC/DiB,MAAMK,OAAOtB,YAAYE,aAAagB,SAAS;AACjD;AAEA,SAASH,oBACPX,QACAM,cAC6D;CAC7D,MAAMa,cAAcnB,OAAOoB;CAE3B,IAAIpB,OAAOS,SAAS,WAElB,OAAO,EAAEY,MAAMf,aAAagB,KAAKC,UAAUC,kCAAkCD,OAAOJ,WAAW,CAAC,EAAE;CAIpG,OAAO,EAAEE,MAAMf,eAAekB,kCAAkClB,cAAca,WAAW,IAAI,KAAK;AACpG;AAMA,SAASK,kCACPD,OACAH,MACkC;CAClC,IAAI,OAAOG,UAAU,YAAY,OAAOA,UAAU,UAChD,OAAO;EAAEH;EAAMK,IAAIlC,eAAegC,KAAK;CAAE;CAI3C,OAA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U,GACxD,OAAOgC,QAAQG,QAAQvB,MAAM;EAG/B,IAAI,CAACf,SACHA,UAAU,CAAC;EAEb,IAAIuC,YAA8D;EAElE,IAAIZ,MAAMa,MAAMrC,UAAU,GACxBoC,YAAY;OACP,IAAIZ,MAAMc,UAAUtC,UAAU,GACnCoC,YAAY;EAGd,MAAM3B,UAAU;GACdC,IAAI0B;GACJzB,MAAM;IACJd;IACAe,QAAQZ;GACV;GACAuC,SAAS,CAACvC,UAAU;GACpBa,cAAc,GAAG7B,YAAY,KAAK;EACpC;EAEA,OAAO,KAAKyB,QAAWA,OAAO,CAAC,CAACK,MAAMC,aAAaA,SAASC,OAAO;CACrE;AACF;AAKA,SAASS,sBAAsBD,OAA8E;CAC3G,MAAMgB,iBAAiBhB;CACvB,IAAI,CAACgB,eAAeb,WAClBa,eAAeb,4BAAY,IAAIc,QAAQ;CAGzC,OAAOD;AACT"}
|
|
1
|
+
{"version":3,"file":"store-Cp64p5ZC.js","names":["defineSignal","assertPrivateStore","ensureStringId","recordIdentifierFor","getOrSetGlobal","preloadData","store","identifier","preload","jsonPayload","schemas","schema","fields","Object","keys","forEach","key","preloadValue","field","get","kind","relationships","preloadRelationship","attributes","cache","hasRecord","Boolean","_instanceCache","peek","upsert","relatedType","type","data","map","value","_convertPreloadRelationshipToJSON","id","_resourceIsFullDeleted","isDeletionCommitted","isNew","isDeleted","resourceIsFullyDeleted","instanceCache","RecordReference","___token","___identifier","constructor","notifications","subscribe","_","bucket","notifiedKey","_ref","destroy","unsubscribe","remoteType","push","objectOrPromise","Promise","resolve","then","peekRecord","load","findRecord","reload","prototype","AvailableShims","WeakMap","getShimClass","modelName","shims","create","set","shim","undefined","ShimModelClass","__store","Map","fieldSchemas","attrs","relationshipsByName","rels","eachAttribute","callback","binding","call","eachRelationship","eachTransformedAttribute","assertPrivateStore","constructResource","ensureStringId","recordIdentifierFor","storeFor","SkipCache","isMaybeIdentifier","normalizeModelName","getShimClass","preloadData","RecordReference","resourceIsFullyDeleted","restoreDeprecatedStoreBehaviors","StoreKlass","prototype","findRecord","resource","id","options","type","normalizedId","identifier","cacheKeyManager","getOrCreateRecordIdentifier","preload","_instanceCache","recordIsLoaded","reload","_join","promise","request","op","data","record","cacheOptions","then","document","content","findAll","query","queryRecord","getReference","resourceIdentifier","arguments","length","cache","upgradeInstanceCaches","__instances","reference","get","set","modelFor","saveRecord","Promise","reject","Error","resolve","operation","isNew","isDeleted","records","withReferences","WeakMap"],"sources":["../../../src/store/-private.ts","../../../src/store.ts"],"sourcesContent":["import type { NotificationType } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { defineSignal } from '@warp-drive/core/signals/-leaked';\nimport {\n assertPrivateStore,\n ensureStringId,\n type InstanceCache,\n recordIdentifierFor,\n} from '@warp-drive/core/store/-private';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { NewResourceKey, ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n LegacyAttributeField,\n LegacyRelationshipField,\n LegacyRelationshipField as RelationshipSchema,\n} from '@warp-drive/core/types/schema/fields';\nimport type {\n ExistingResourceIdentifierObject,\n ExistingResourceObject,\n InnerRelationshipDocument,\n SingleResourceDocument,\n} from '@warp-drive/core/types/spec/json-api-raw';\n\nimport type { Store } from '../store.ts';\n\n/*\n When a find request is triggered on the store, the user can optionally pass in\n attributes and relationships to be preloaded. These are meant to behave as if they\n came back from the server, except the user obtained them out of band and is informing\n the store of their existence. The most common use case is for supporting client side\n nested URLs, such as `/posts/1/comments/2` so the user can do\n `store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.\n\n Preloaded data can be attributes and relationships passed in either as IDs or as actual\n models.\n */\ntype PreloadRelationshipValue = OpaqueRecordInstance | string;\nexport function preloadData(store: Store, identifier: NewResourceKey, preload: Record<string, Value>): void {\n const jsonPayload: Partial<ExistingResourceObject> = {};\n //TODO(Igor) consider the polymorphic case\n const schemas = store.schema;\n const fields = schemas.fields(identifier);\n Object.keys(preload).forEach((key) => {\n const preloadValue = preload[key];\n\n const field = fields.get(key);\n if (field && (field.kind === 'hasMany' || field.kind === 'belongsTo')) {\n if (!jsonPayload.relationships) {\n jsonPayload.relationships = {};\n }\n jsonPayload.relationships[key] = preloadRelationship(field, preloadValue);\n } else {\n if (!jsonPayload.attributes) {\n jsonPayload.attributes = {};\n }\n jsonPayload.attributes[key] = preloadValue;\n }\n });\n const cache = store.cache;\n assertPrivateStore(store);\n const hasRecord = Boolean(store._instanceCache.peek(identifier));\n cache.upsert(identifier, jsonPayload, hasRecord);\n}\n\nfunction preloadRelationship(\n schema: RelationshipSchema,\n preloadValue: PreloadRelationshipValue | null | Array<PreloadRelationshipValue>\n): InnerRelationshipDocument<ExistingResourceIdentifierObject> {\n const relatedType = schema.type;\n\n if (schema.kind === 'hasMany') {\n assert('You need to pass in an array to set a hasMany property on a record', Array.isArray(preloadValue));\n return { data: preloadValue.map((value) => _convertPreloadRelationshipToJSON(value, relatedType)) };\n }\n\n assert('You should not pass in an array to set a belongsTo property on a record', !Array.isArray(preloadValue));\n return { data: preloadValue ? _convertPreloadRelationshipToJSON(preloadValue, relatedType) : null };\n}\n\n/*\n findRecord('user', '1', { preload: { friends: ['1'] }});\n findRecord('user', '1', { preload: { friends: [record] }});\n*/\nfunction _convertPreloadRelationshipToJSON(\n value: OpaqueRecordInstance | string,\n type: string\n): ExistingResourceIdentifierObject {\n if (typeof value === 'string' || typeof value === 'number') {\n return { type, id: ensureStringId(value) };\n }\n // TODO if not a record instance assert it's an identifier\n // and allow identifiers to be used\n return recordIdentifierFor(value) as ExistingResourceIdentifierObject;\n}\n\nexport interface BaseFinderOptions {\n reload?: boolean;\n backgroundReload?: boolean;\n include?: string | string[];\n adapterOptions?: Record<string, unknown>;\n}\nexport interface FindRecordOptions extends BaseFinderOptions {\n /**\n * Data to preload into the store before the request is made.\n * This feature is *highly* discouraged and has no corresponding\n * feature when using builders and handlers.\n *\n * Excepting relationships: the data should be in the form of a\n * JSON object where the keys are fields on the record and the value\n * is the raw value to be added to the cache.\n *\n * Relationships can either be provided as string IDs from which\n * an identifier will be built base upon the relationship's expected\n * resource type, or be record instances from which the identifier\n * will be extracted.\n *\n */\n preload?: Record<string, Value>;\n}\n\nexport type QueryOptions = {\n [K in string | 'adapterOptions']?: K extends 'adapterOptions' ? Record<string, unknown> : unknown;\n};\n\nexport type FindAllOptions = BaseFinderOptions;\nexport type LegacyResourceQuery = {\n include?: string | string[];\n [key: string]: Value | undefined;\n};\n\nexport type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;\n\n/**\n * Minimum subset of static schema methods and properties on the\n * \"model\" class.\n *\n * Only used when using the legacy schema-service implementation\n * for @ember-data/model or when wrapping schema for legacy\n * Adapters/Serializers.\n *\n */\nexport interface ModelSchema<T = unknown> {\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n fields: Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>;\n attributes: Map<KeyOrString<T>, LegacyAttributeField>;\n relationshipsByName: Map<KeyOrString<T>, LegacyRelationshipField>;\n eachAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void;\n eachRelationship<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void;\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, type: string | null) => void,\n binding?: T\n ): void;\n}\n\nfunction _resourceIsFullDeleted(identifier: ResourceKey, cache: Cache): boolean {\n return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));\n}\n\nexport function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: ResourceKey): boolean {\n const cache = instanceCache.cache;\n return !cache || _resourceIsFullDeleted(identifier, cache);\n}\n\n/**\n A `RecordReference` is a low-level API that allows users and\n addon authors to perform meta-operations on a record.\n\n @hideconstructor\n @public\n*/\nexport class RecordReference {\n /** @internal */\n declare private store: Store;\n // unsubscribe token given to us by the notification manager\n /** @internal */\n private ___token!: object;\n /** @internal */\n private ___identifier: ResourceKey;\n /** @internal */\n declare private _ref: number;\n\n constructor(store: Store, identifier: ResourceKey) {\n this.store = store;\n this.___identifier = identifier;\n this.___token = store.notifications.subscribe(\n identifier,\n (_: ResourceKey, bucket: NotificationType, notifiedKey?: string) => {\n if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {\n this._ref++;\n }\n }\n );\n }\n\n /** @internal */\n destroy(): void {\n this.store.notifications.unsubscribe(this.___token);\n }\n\n get type(): string {\n return this.identifier().type;\n }\n\n /**\n The `id` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.id(); // '1'\n ```\n\n @public\n @return The id of the record.\n */\n id(): string | null {\n // oxlint-disable-next-line no-unused-expressions\n this._ref; // consume the tracked prop\n return this.___identifier.id;\n }\n\n /**\n The `identifier` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.identifier(); // '1'\n ```\n\n @public\n @return The identifier of the record.\n */\n identifier(): ResourceKey {\n return this.___identifier;\n }\n\n /**\n How the reference will be looked up when it is loaded. Currently\n this always returns `identity` to signify that a record will be\n loaded by its `type` and `id`.\n\n Example\n\n ```javascript\n const userRef = store.getReference('user', 1);\n\n userRef.remoteType(); // 'identity'\n ```\n\n @public\n */\n remoteType(): 'identity' {\n return 'identity';\n }\n\n /**\n This API allows you to provide a reference with new data. The\n simplest usage of this API is similar to `store.push`: you provide a\n normalized hash of data and the object represented by the reference\n will update.\n\n If you pass a promise to `push`, WarpDrive will not ask the adapter\n for the data if another attempt to fetch it is made in the\n interim. When the promise resolves, the underlying object is updated\n with the new data, and the promise returned by *this function* is resolved\n with that object.\n\n For example, `recordReference.push(promise)` will be resolved with a\n record.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // provide data for reference\n userRef.push({\n data: {\n id: \"1\",\n type: \"user\",\n attributes: {\n username: \"@user\"\n }\n }\n }).then(function(user) {\n userRef.value() === user;\n });\n ```\n\n @public\n @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one\n @return a promise for the value (record or relationship)\n */\n push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance> {\n // TODO @deprecate pushing unresolved payloads\n return Promise.resolve(objectOrPromise).then((data) => {\n return this.store.push(data);\n });\n }\n\n /**\n If the entity referred to by the reference is already loaded, it is\n present as `reference.value`. Otherwise the value returned by this function\n is `null`.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.value(); // user\n ```\n\n @public\n @return the record for this RecordReference\n */\n value(): OpaqueRecordInstance | null {\n return this.store.peekRecord(this.___identifier);\n }\n\n /**\n Triggers a fetch for the backing entity based on its `remoteType`\n (see `remoteType` definitions per reference type).\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // load user (via store.find)\n userRef.load().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n load(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id);\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n\n /**\n Reloads the record if it is already loaded. If the record is not\n loaded it will load the record via `store.findRecord`\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // or trigger a reload\n userRef.reload().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n reload(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id, { reload: true });\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n}\n\ndefineSignal(RecordReference.prototype, '_ref');\n\n// if modelFor turns out to be a bottleneck we should replace with a Map\n// and clear it during store teardown.\nconst AvailableShims = getOrSetGlobal('AvailableShims', new WeakMap<Store, Record<string, ShimModelClass>>());\n\nexport function getShimClass<T>(\n store: Store,\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n): ShimModelClass<T> {\n let shims = AvailableShims.get(store);\n\n if (!shims) {\n shims = Object.create(null) as Record<string, ShimModelClass>;\n AvailableShims.set(store, shims);\n }\n\n let shim = shims[modelName];\n if (shim === undefined) {\n shim = shims[modelName] = new ShimModelClass<unknown>(store, modelName);\n }\n\n return shim;\n}\n\n// Mimics the static apis of @ember-data/model\nexport class ShimModelClass<T = unknown> implements ModelSchema<T> {\n declare __store: Store;\n declare modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string) {\n this.__store = store;\n this.modelName = modelName;\n }\n\n get fields(): Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'> {\n const fields = new Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>();\n const fieldSchemas = this.__store.schema.fields({ type: this.modelName });\n\n fieldSchemas.forEach((schema, key) => {\n if (schema.kind === 'attribute' || schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n fields.set(key as KeyOrString<T>, schema.kind);\n }\n });\n\n return fields;\n }\n\n get attributes(): Map<KeyOrString<T>, LegacyAttributeField> {\n const attrs = new Map<KeyOrString<T>, LegacyAttributeField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n attrs.set(key as KeyOrString<T>, schema);\n }\n });\n\n return attrs;\n }\n\n get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField> {\n const rels = new Map<KeyOrString<T>, LegacyRelationshipField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n rels.set(key as KeyOrString<T>, schema);\n }\n });\n\n return rels;\n }\n\n eachAttribute<K extends KeyOrString<T>>(\n callback: (key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachRelationship<K extends KeyOrString<T>>(\n callback: (key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (key: K, type: string | null) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n const type = schema.type;\n if (type) callback.call(binding, key as K, type);\n }\n });\n }\n}\n","/**\n * @module\n * @summary Legacy `restoreDeprecatedStoreBehaviors`, which restores the adapter-based `findRecord`, `findAll`, `query`,\n * `saveRecord` and related methods onto a `Store` class.\n */\n\nimport type { Store } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { LegacyLiveArray, LegacyQueryArray, PrivateStore } from '@warp-drive/core/store/-private';\nimport {\n assertPrivateStore,\n constructResource,\n ensureStringId,\n recordIdentifierFor,\n storeFor,\n} from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport { SkipCache } from '@warp-drive/core/types/request';\nimport type { ResourceIdentifierObject } from '@warp-drive/core/types/spec/json-api-raw';\n\nimport { isMaybeIdentifier } from './compat/builders/utils.ts';\nimport { normalizeModelName } from './model/-private/util.ts';\nimport type {\n FindAllOptions,\n FindRecordOptions,\n LegacyResourceQuery,\n ModelSchema,\n QueryOptions,\n} from './store/-private.ts';\nimport { getShimClass, preloadData, RecordReference, resourceIsFullyDeleted } from './store/-private.ts';\n\n/**\n * Restores the deprecated `findRecord`/`findAll`/`query`/`queryRecord`/\n * `findBelongsTo`/`findHasMany`/`createRecord`/`deleteRecord`/`saveRecord`\n * legacy-network-layer implementations of these methods onto the given\n * `Store` subclass, for apps that have not yet migrated to the\n * `RequestManager`-based equivalents.\n *\n * @summary Legacy opt-in that restores the adapter-based `findRecord`, `findAll`, `query`, `saveRecord`, and related\n * methods onto a `Store` class.\n */\nexport function restoreDeprecatedStoreBehaviors(StoreKlass: typeof Store): void {\n StoreKlass.prototype.findRecord = function (\n resource: string | ResourceIdentifierObject,\n id?: string | number | FindRecordOptions,\n options?: FindRecordOptions\n ): Promise<unknown> {\n assert(\n `Attempted to call store.findRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n assert(\n `You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`,\n resource\n );\n if (isMaybeIdentifier(resource)) {\n options = id as FindRecordOptions;\n } else {\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`,\n typeof resource === 'string'\n );\n const type = normalizeModelName(resource);\n const normalizedId = ensureStringId(id as string | number);\n resource = constructResource(type, normalizedId);\n }\n\n const identifier = this.cacheKeyManager.getOrCreateRecordIdentifier(resource);\n options = options || {};\n assertPrivateStore(this);\n\n if (options.preload) {\n // force reload if we preload to ensure we don't resolve the promise\n // until we are complete, else we will end up background-reloading\n // even for initial load.\n if (!this._instanceCache.recordIsLoaded(identifier)) {\n options.reload = true;\n }\n this._join(() => {\n preloadData(this, identifier, options.preload!);\n });\n }\n\n const promise = this.request<OpaqueRecordInstance>({\n op: 'findRecord',\n data: {\n record: identifier,\n options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => {\n return document.content;\n });\n };\n\n StoreKlass.prototype.findAll = function <T>(\n type: TypeFromInstance<T> | string,\n options: FindAllOptions = {}\n ): Promise<LegacyLiveArray<T>> {\n assert(\n `Attempted to call store.findAll(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's findAll method`, type);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyLiveArray<T>>({\n op: 'findAll',\n data: {\n type: normalizeModelName(type),\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.query = function (\n type: string,\n query: LegacyResourceQuery,\n options: QueryOptions = {}\n ): Promise<LegacyQueryArray> {\n assert(\n `Attempted to call store.query(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's query method`, type);\n assert(`You need to pass a query hash to the store's query method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyQueryArray>({\n op: 'query',\n data: {\n type: normalizeModelName(type),\n query,\n options: options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.queryRecord = function (\n type: string,\n query: Record<string, unknown>,\n options?: QueryOptions\n ): Promise<OpaqueRecordInstance | null> {\n assert(\n `Attempted to call store.queryRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's queryRecord method`, type);\n assert(`You need to pass a query hash to the store's queryRecord method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<OpaqueRecordInstance | null>({\n op: 'queryRecord',\n data: {\n type: normalizeModelName(type),\n query,\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n // do not put a ts-expect-error here, because typedoc will fail to\n // build due to this error only occurring when references are in use in the editor.\n // The return statement below casts to `PrivateStore['getReference']`'s return\n // type rather than annotating this function `: RecordReference` directly,\n // since this package's `RecordReference` and core's `deprecated/-private.ts`\n // copy are structurally identical but nominally distinct classes (TS treats\n // their private fields as separate brands); casting only the return value\n // (instead of the whole function) keeps `this` contextually typed from the\n // assignment target below.\n StoreKlass.prototype.getReference = function (resource: string | ResourceIdentifierObject, id: string | number) {\n assert(\n `Attempted to call store.getReference(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n let resourceIdentifier: ResourceIdentifierObject;\n if (arguments.length === 1 && isMaybeIdentifier(resource)) {\n resourceIdentifier = resource;\n } else {\n const type = normalizeModelName(resource as string);\n const normalizedId = ensureStringId(id);\n resourceIdentifier = constructResource(type, normalizedId);\n }\n\n assert(\n 'getReference expected to receive either a resource identifier or type and id as arguments',\n isMaybeIdentifier(resourceIdentifier)\n );\n\n const identifier: ResourceKey = this.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);\n assertPrivateStore(this);\n\n const cache = upgradeInstanceCaches(this._instanceCache.__instances).reference;\n let reference = cache.get(identifier);\n\n if (!reference) {\n reference = new RecordReference(this, identifier);\n cache.set(identifier, reference);\n }\n return reference;\n };\n\n StoreKlass.prototype.modelFor = function <T>(\n type: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n ): ModelSchema<T> {\n assert(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`, !this.isDestroyed);\n assert(`You need to pass <type> to the store's modelFor method`, typeof type === 'string' && type.length);\n assert(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n\n return getShimClass<T>(this, type);\n };\n\n StoreKlass.prototype.saveRecord = function <T>(record: T, options: Record<string, unknown> = {}): Promise<T> {\n assert(\n `Attempted to call store.saveRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`Unable to initiate save for a record in a disconnected state`, storeFor(record, true));\n const identifier = recordIdentifierFor(record);\n const cache = this.cache;\n\n if (!identifier) {\n // this commonly means we're disconnected\n // but just in case we reject here to prevent bad things.\n return Promise.reject(new Error(`Record Is Disconnected`));\n }\n assertPrivateStore(this);\n assert(\n `Cannot initiate a save request for an unloaded record: ${identifier.lid}`,\n this._instanceCache.recordIsLoaded(identifier)\n );\n if (resourceIsFullyDeleted(this._instanceCache, identifier)) {\n return Promise.resolve(record);\n }\n\n if (!options) {\n options = {};\n }\n let operation: 'createRecord' | 'deleteRecord' | 'updateRecord' = 'updateRecord';\n\n if (cache.isNew(identifier)) {\n operation = 'createRecord';\n } else if (cache.isDeleted(identifier)) {\n operation = 'deleteRecord';\n }\n\n const request = {\n op: operation,\n data: {\n options,\n record: identifier,\n },\n records: [identifier],\n cacheOptions: { [SkipCache]: true },\n };\n\n return this.request<T>(request).then((document) => document.content);\n };\n}\n\nexport type { Store };\n\ntype Caches = PrivateStore['_instanceCache']['__instances'];\nfunction upgradeInstanceCaches(cache: Caches): Caches & { reference: WeakMap<ResourceKey, RecordReference> } {\n const withReferences = cache as Caches & { reference: WeakMap<ResourceKey, RecordReference> };\n if (!withReferences.reference) {\n withReferences.reference = new WeakMap();\n }\n\n return withReferences;\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgBK,YAAYC,OAAcC,YAA4BC,SAAsC;CAC1G,MAAMC,cAA+C,CAAC;CAGtD,MAAMG,SADUN,MAAMK,OACCC,OAAOL,UAAU;CACxCM,OAAOC,KAAKN,OAAO,CAAC,CAACO,SAASC,QAAQ;EACpC,MAAMC,eAAeT,QAAQQ;EAE7B,MAAME,QAAQN,OAAOO,IAAIH,GAAG;EAC5B,IAAIE,UAAUA,MAAME,SAAS,aAAaF,MAAME,SAAS,cAAc;GACrE,IAAI,CAACX,YAAYY,eACfZ,YAAYY,gBAAgB,CAAC;GAE/BZ,YAAYY,cAAcL,OAAOM,oBAAoBJ,OAAOD,YAAY;EAC1E,OAAO;GACL,IAAI,CAACR,YAAYc,YACfd,Y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|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/legacy",
|
|
3
|
-
"version": "5.10.0-alpha.
|
|
3
|
+
"version": "5.10.0-alpha.23",
|
|
4
4
|
"description": "Opt-in support for features deprecated out of `@warp-drive/core`, such as Models, Adapters, Serializers and legacy store APIs, for apps that still need to migrate away from them.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -43,25 +43,25 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@warp-drive/core": "5.10.0-alpha.
|
|
47
|
-
"@warp-drive/utilities": "5.10.0-alpha.
|
|
46
|
+
"@warp-drive/core": "5.10.0-alpha.23",
|
|
47
|
+
"@warp-drive/utilities": "5.10.0-alpha.23"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@embroider/macros": "^1.21.4",
|
|
51
|
-
"warp-drive": "0.2.0-alpha.
|
|
51
|
+
"warp-drive": "0.2.0-alpha.99"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@babel/core": "^7.29.7",
|
|
55
55
|
"@babel/plugin-transform-typescript": "^7.29.9",
|
|
56
56
|
"@babel/preset-typescript": "^7.29.7",
|
|
57
57
|
"@types/jquery": "^4.0.1",
|
|
58
|
-
"@warp-drive/core": "5.10.0-alpha.
|
|
59
|
-
"@warp-drive/internal-config": "5.10.0-alpha.
|
|
60
|
-
"@warp-drive/utilities": "5.10.0-alpha.
|
|
58
|
+
"@warp-drive/core": "5.10.0-alpha.23",
|
|
59
|
+
"@warp-drive/internal-config": "5.10.0-alpha.23",
|
|
60
|
+
"@warp-drive/utilities": "5.10.0-alpha.23",
|
|
61
61
|
"decorator-transforms": "^2.4.0",
|
|
62
62
|
"ember-source": "~7.4.0",
|
|
63
63
|
"expect-type": "^1.4.0",
|
|
64
|
-
"tsdown": "^0.23.
|
|
64
|
+
"tsdown": "^0.23.4",
|
|
65
65
|
"typescript-7": "npm:typescript@7.1.0-beta"
|
|
66
66
|
},
|
|
67
67
|
"ember-addon": {
|
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { n as decorateMethodV2, r as initializeDeferredDecorator, t as decorateFieldV2 } from "./runtime--fcdnjmJ-5yaSpa-d.js";
|
|
2
|
-
import { withDefaults } from "./model/migration-support.js";
|
|
3
|
-
import { Context } from "@warp-drive/core/reactive/-private";
|
|
4
|
-
import { pluralize, singularize } from "@warp-drive/utilities/string";
|
|
5
|
-
import { cached, tracked } from "@glimmer/tracking";
|
|
6
|
-
|
|
7
|
-
// src/model-fragments/utilities/with-array-defaults.ts
|
|
8
|
-
function withArrayDefaults(arrayName, primitiveType) {
|
|
9
|
-
return {
|
|
10
|
-
kind: "array",
|
|
11
|
-
name: arrayName,
|
|
12
|
-
type: primitiveType ? `array:${primitiveType}` : "array",
|
|
13
|
-
options: { arrayExtensions: [
|
|
14
|
-
"ember-object",
|
|
15
|
-
"ember-array-like",
|
|
16
|
-
"fragment-array"
|
|
17
|
-
] }
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/model-fragments/utilities/with-fragment-defaults.ts
|
|
22
|
-
/**
|
|
23
|
-
* Used as a helper to setup the relevant parts of a fragment schema
|
|
24
|
-
* and add extensions etc.
|
|
25
|
-
*
|
|
26
|
-
* @summary Legacy ModelFragments migration helper that builds a `schema-object` field for a single `fragment:`
|
|
27
|
-
* type with the `ember-object` and `fragment` extensions.
|
|
28
|
-
* @param fragmentType The type of the fragment
|
|
29
|
-
* @param fragmentName The optional name of the fragment. If not provided, it will default to the fragmentType.
|
|
30
|
-
* @returns The schema for a fragment
|
|
31
|
-
*/
|
|
32
|
-
function withFragmentDefaults(fragmentType, fragmentName) {
|
|
33
|
-
return {
|
|
34
|
-
kind: "schema-object",
|
|
35
|
-
type: `fragment:${fragmentType}`,
|
|
36
|
-
name: fragmentName ?? fragmentType,
|
|
37
|
-
options: { objectExtensions: ["ember-object", "fragment"] }
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/model-fragments/utilities/with-fragment-array-defaults.ts
|
|
42
|
-
/**
|
|
43
|
-
* Used as a helper to setup the relevant parts of a fragment-array
|
|
44
|
-
* schema and add extensions etc.
|
|
45
|
-
*
|
|
46
|
-
* @summary Legacy ModelFragments migration helper that builds a `schema-array` field of `fragment:` items,
|
|
47
|
-
* defaulting to an empty array, with Ember and fragment-array extensions.
|
|
48
|
-
* @param fragmentArrayType The type of the fragment-array
|
|
49
|
-
* @param fragmentArrayName The name of the fragment-array
|
|
50
|
-
* @returns The schema for a fragment-array
|
|
51
|
-
*/
|
|
52
|
-
function withFragmentArrayDefaults(fragmentArrayType, fragmentArrayName) {
|
|
53
|
-
return {
|
|
54
|
-
kind: "schema-array",
|
|
55
|
-
type: `fragment:${singularize(fragmentArrayType)}`,
|
|
56
|
-
name: fragmentArrayName ?? pluralize(fragmentArrayType),
|
|
57
|
-
options: {
|
|
58
|
-
arrayExtensions: [
|
|
59
|
-
"ember-object",
|
|
60
|
-
"ember-array-like",
|
|
61
|
-
"fragment-array"
|
|
62
|
-
],
|
|
63
|
-
defaultValue: true
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// src/model-fragments/utilities/with-legacy.ts
|
|
69
|
-
/**
|
|
70
|
-
* Used as a helper to setup the relevant parts of a legacy resource schema
|
|
71
|
-
* migrated from `Model`, applying the `ember-object` and `fragment` object
|
|
72
|
-
* extensions and a default `@id` identity field.
|
|
73
|
-
*
|
|
74
|
-
* @summary Legacy ModelFragments migration helper that completes a legacy resource schema with an `id` identity,
|
|
75
|
-
* `Model` defaults, and the `ember-object` and `fragment` extensions.
|
|
76
|
-
* @param schema the partial legacy resource schema to complete
|
|
77
|
-
* @returns the completed resource schema
|
|
78
|
-
*/
|
|
79
|
-
function withLegacy(schema) {
|
|
80
|
-
return withDefaults({
|
|
81
|
-
...schema,
|
|
82
|
-
identity: {
|
|
83
|
-
kind: "@id",
|
|
84
|
-
name: "id"
|
|
85
|
-
},
|
|
86
|
-
objectExtensions: ["ember-object", "fragment"]
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// src/model-fragments/extensions/fragment-array.ts
|
|
91
|
-
/**
|
|
92
|
-
* The features added to an array resource by {@link FragmentArrayExtension}, providing
|
|
93
|
-
* a subset of the legacy `ModelFragments` fragment-array API for migrated resources.
|
|
94
|
-
*
|
|
95
|
-
* @summary Legacy `ModelFragments`-compatible array API, such as `addFragment`, `removeFragment`, and
|
|
96
|
-
* `rollbackAttributes`, for reactive arrays migrated off fragments.
|
|
97
|
-
*/
|
|
98
|
-
var FragmentArray = class {
|
|
99
|
-
static {
|
|
100
|
-
decorateFieldV2(this.prototype, "isDestroying", [tracked], function() {
|
|
101
|
-
return false;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
#isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0);
|
|
105
|
-
/**
|
|
106
|
-
* Whether this fragment array is in the process of being destroyed.
|
|
107
|
-
*/
|
|
108
|
-
static {
|
|
109
|
-
decorateFieldV2(this.prototype, "isDestroyed", [tracked], function() {
|
|
110
|
-
return false;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
#isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
|
|
114
|
-
/**
|
|
115
|
-
* Whether this fragment array has been destroyed.
|
|
116
|
-
*/
|
|
117
|
-
/**
|
|
118
|
-
* Whether this fragment array (or any of its members) has uncommitted changes.
|
|
119
|
-
*/
|
|
120
|
-
get hasDirtyAttributes() {
|
|
121
|
-
const { path, resourceKey, store } = this[Context];
|
|
122
|
-
const record = store.peekRecord(resourceKey);
|
|
123
|
-
if (record.hasDirtyAttributes && path) return path.at(0) in record.changedAttributes();
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Adds an existing fragment to this array, if one was given.
|
|
128
|
-
*/
|
|
129
|
-
static {
|
|
130
|
-
decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
|
|
131
|
-
}
|
|
132
|
-
addFragment(fragment) {
|
|
133
|
-
if (!fragment) return;
|
|
134
|
-
return this.addObject(fragment);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Appends a new fragment to the end of this array, if one was given.
|
|
138
|
-
*/
|
|
139
|
-
createFragment(fragment) {
|
|
140
|
-
if (!fragment) return;
|
|
141
|
-
return this.pushObject(fragment);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Removes the given fragment from this array, if present.
|
|
145
|
-
*/
|
|
146
|
-
removeFragment(fragment) {
|
|
147
|
-
if (!fragment) return;
|
|
148
|
-
const index = this.indexOf(fragment);
|
|
149
|
-
if (index !== -1) this.splice(index, 1);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Reverts each member fragment's attribute back to its last known remote value.
|
|
153
|
-
*/
|
|
154
|
-
rollbackAttributes() {
|
|
155
|
-
for (const fragment of this) fragment?.rollbackAttributes?.();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* A schema extension that adds the {@link FragmentArray} API to migrated
|
|
160
|
-
* `ModelFragments` array resources.
|
|
161
|
-
*
|
|
162
|
-
* @summary Legacy schema extension named `fragment-array` that adds the `FragmentArray` API to reactive arrays
|
|
163
|
-
* migrated from `ModelFragments`.
|
|
164
|
-
*/
|
|
165
|
-
const FragmentArrayExtension = {
|
|
166
|
-
kind: "array",
|
|
167
|
-
name: "fragment-array",
|
|
168
|
-
features: FragmentArray
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// src/model-fragments/extensions/fragment.ts
|
|
172
|
-
/**
|
|
173
|
-
* The features added to an object resource by {@link FragmentExtension}, providing
|
|
174
|
-
* a subset of the legacy `ModelFragments` fragment API for migrated resources.
|
|
175
|
-
*
|
|
176
|
-
* @summary Legacy `ModelFragments`-compatible object API, such as `hasDirtyAttributes`, `isFragment`, and
|
|
177
|
-
* `rollbackAttributes`, for reactive objects migrated off fragments.
|
|
178
|
-
*/
|
|
179
|
-
var Fragment = class {
|
|
180
|
-
static {
|
|
181
|
-
decorateFieldV2(this.prototype, "isDestroying", [tracked], function() {
|
|
182
|
-
return false;
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
#isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0);
|
|
186
|
-
/**
|
|
187
|
-
* Whether this fragment is in the process of being destroyed.
|
|
188
|
-
*/
|
|
189
|
-
static {
|
|
190
|
-
decorateFieldV2(this.prototype, "isDestroyed", [tracked], function() {
|
|
191
|
-
return false;
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
#isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
|
|
195
|
-
/**
|
|
196
|
-
* Whether this fragment has been destroyed.
|
|
197
|
-
*/
|
|
198
|
-
/**
|
|
199
|
-
* Whether this fragment (or the attribute it is rooted at) has uncommitted changes.
|
|
200
|
-
*/
|
|
201
|
-
get hasDirtyAttributes() {
|
|
202
|
-
const { path, resourceKey, store } = this[Context];
|
|
203
|
-
const record = store.peekRecord(resourceKey);
|
|
204
|
-
if (record.hasDirtyAttributes && path) return path.at(0) in record.changedAttributes();
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Always `true`. Used to distinguish fragments from other resources.
|
|
209
|
-
*/
|
|
210
|
-
static {
|
|
211
|
-
decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
|
|
212
|
-
}
|
|
213
|
-
get isFragment() {
|
|
214
|
-
return true;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* The resource type of this fragment, if known.
|
|
218
|
-
*/
|
|
219
|
-
get $type() {
|
|
220
|
-
const { field } = this[Context];
|
|
221
|
-
return field?.type;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Reverts this fragment's attribute back to its last known remote value.
|
|
225
|
-
*/
|
|
226
|
-
rollbackAttributes() {
|
|
227
|
-
const { path, resourceKey, store } = this[Context];
|
|
228
|
-
if (path) {
|
|
229
|
-
const oldValue = store.cache.getRemoteAttr(resourceKey, path);
|
|
230
|
-
store.cache.setAttr(resourceKey, path, oldValue);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* A schema extension that adds the {@link Fragment} API to migrated
|
|
236
|
-
* `ModelFragments` object resources.
|
|
237
|
-
*
|
|
238
|
-
* @summary Legacy schema extension named `fragment` that adds the `Fragment` API to reactive objects migrated from
|
|
239
|
-
* `ModelFragments`.
|
|
240
|
-
*/
|
|
241
|
-
const FragmentExtension = {
|
|
242
|
-
kind: "object",
|
|
243
|
-
name: "fragment",
|
|
244
|
-
features: Fragment
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// src/model-fragments/instance-initializers/fragment-extensions.ts
|
|
248
|
-
/**
|
|
249
|
-
* Registers the {@link FragmentExtension}/{@link FragmentArrayExtension} schema
|
|
250
|
-
* extensions on the given `SchemaService`, enabling ModelFragments migration support.
|
|
251
|
-
*
|
|
252
|
-
* @summary Legacy setup function that registers the fragment and fragment-array schema extensions on a
|
|
253
|
-
* `SchemaService` to support migrating off ModelFragments.
|
|
254
|
-
* @public
|
|
255
|
-
*/
|
|
256
|
-
function registerFragmentExtensions(schema) {
|
|
257
|
-
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentExtension);
|
|
258
|
-
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentArrayExtension);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// src/model-fragments/hooks/model-for.ts
|
|
262
|
-
const AvailableShims = /* @__PURE__ */ new WeakMap();
|
|
263
|
-
function getShimClass(store, modelName) {
|
|
264
|
-
let shims = AvailableShims.get(store);
|
|
265
|
-
if (!shims) {
|
|
266
|
-
shims = Object.create(null);
|
|
267
|
-
AvailableShims.set(store, shims);
|
|
268
|
-
}
|
|
269
|
-
let shim = shims[modelName];
|
|
270
|
-
if (shim === void 0) shim = shims[modelName] = new ShimModelClass(store, modelName);
|
|
271
|
-
return shim;
|
|
272
|
-
}
|
|
273
|
-
const AttributeKinds = [
|
|
274
|
-
"field",
|
|
275
|
-
"attribute",
|
|
276
|
-
"object",
|
|
277
|
-
"array",
|
|
278
|
-
"schema-object",
|
|
279
|
-
"schema-array"
|
|
280
|
-
];
|
|
281
|
-
var ShimModelClass = class {
|
|
282
|
-
constructor(store, modelName) {
|
|
283
|
-
this.__store = store;
|
|
284
|
-
this.modelName = modelName;
|
|
285
|
-
}
|
|
286
|
-
get fields() {
|
|
287
|
-
const fields = /* @__PURE__ */ new Map();
|
|
288
|
-
this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {
|
|
289
|
-
if (AttributeKinds.includes(schema.kind)) fields.set(key, "attribute");
|
|
290
|
-
else if (schema.kind === "belongsTo" || schema.kind === "hasMany") fields.set(key, schema.kind);
|
|
291
|
-
});
|
|
292
|
-
return fields;
|
|
293
|
-
}
|
|
294
|
-
get attributes() {
|
|
295
|
-
const attrs = /* @__PURE__ */ new Map();
|
|
296
|
-
this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {
|
|
297
|
-
if (schema.kind === "attribute") attrs.set(key, schema);
|
|
298
|
-
else if (AttributeKinds.includes(schema.kind)) attrs.set(key, {
|
|
299
|
-
kind: "attribute",
|
|
300
|
-
name: key,
|
|
301
|
-
type: null,
|
|
302
|
-
options: schema.options ?? {}
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
return attrs;
|
|
306
|
-
}
|
|
307
|
-
get relationshipsByName() {
|
|
308
|
-
const rels = /* @__PURE__ */ new Map();
|
|
309
|
-
this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {
|
|
310
|
-
if (schema.kind === "belongsTo" || schema.kind === "hasMany") rels.set(key, schema);
|
|
311
|
-
});
|
|
312
|
-
return rels;
|
|
313
|
-
}
|
|
314
|
-
eachAttribute(callback, binding) {
|
|
315
|
-
this.attributes.forEach((schema, key) => {
|
|
316
|
-
callback.call(binding, key, schema);
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
eachRelationship(callback, binding) {
|
|
320
|
-
this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {
|
|
321
|
-
if (schema.kind === "belongsTo" || schema.kind === "hasMany") callback.call(binding, key, schema);
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
eachTransformedAttribute(callback, binding) {
|
|
325
|
-
this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {
|
|
326
|
-
if (schema.kind === "attribute") {
|
|
327
|
-
const type = schema.type;
|
|
328
|
-
if (type) callback.call(binding, key, type);
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
function fragmentsModelFor(modelName) {
|
|
334
|
-
return getShimClass(this, modelName);
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* The `modelFor` fallback used to construct a `ShimModelClass` schema for a
|
|
338
|
-
* type when ModelFragments support is enabled and no real `Model` subclass
|
|
339
|
-
* is registered for that type.
|
|
340
|
-
*
|
|
341
|
-
* @summary Legacy `store.modelFor` fallback that returns a schema-backed `ShimModelClass` for a type when
|
|
342
|
-
* ModelFragments support is on and no `Model` class exists.
|
|
343
|
-
* @public
|
|
344
|
-
*/
|
|
345
|
-
const modelFor = fragmentsModelFor;
|
|
346
|
-
|
|
347
|
-
export { FragmentExtension as a, withLegacy as c, withArrayDefaults as d, Fragment as i, withFragmentArrayDefaults as l, modelFor as n, FragmentArray as o, registerFragmentExtensions as r, FragmentArrayExtension as s, fragmentsModelFor as t, withFragmentDefaults as u };
|
|
348
|
-
//# sourceMappingURL=model-fragments-DCHMDr5f.js.map
|