@warp-drive/legacy 5.9.0-alpha.2 → 5.9.0-alpha.21
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/README.md +6 -0
- package/declarations/adapter/-private/build-url-mixin.d.ts +156 -0
- package/declarations/adapter/error.d.ts +385 -169
- package/declarations/adapter/json-api.d.ts +12 -1
- package/declarations/adapter/rest.d.ts +74 -0
- package/declarations/adapter.d.ts +6 -0
- package/declarations/compat/builders/find-all.d.ts +0 -1
- package/declarations/compat/extensions.d.ts +40 -0
- package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +7 -0
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +4 -0
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +7 -0
- package/declarations/compat/utils.d.ts +11 -0
- package/declarations/compat.d.ts +32 -0
- package/declarations/index.d.ts +142 -0
- package/declarations/model/-private/attr.d.ts +21 -0
- package/declarations/model/-private/belongs-to.d.ts +21 -0
- package/declarations/model/-private/hooks.d.ts +26 -0
- package/declarations/model/-private/model.d.ts +55 -4
- package/declarations/model/-private/promise-many-array.d.ts +25 -1
- package/declarations/model/-private/schema-provider.d.ts +11 -1
- package/declarations/model/migration-support.d.ts +31 -5
- package/declarations/model-fragments/extensions/fragment-array.d.ts +38 -0
- package/declarations/model-fragments/extensions/fragment.d.ts +35 -0
- package/declarations/model-fragments/hooks/model-for.d.ts +7 -0
- package/declarations/model-fragments/index.d.ts +8 -0
- package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +6 -0
- package/declarations/model-fragments/utilities/with-array-defaults.d.ts +30 -0
- package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +18 -0
- package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +15 -0
- package/declarations/model-fragments/utilities/with-legacy.d.ts +8 -0
- package/declarations/serializer/-private/transforms/boolean.d.ts +13 -0
- package/declarations/serializer/-private/transforms/date.d.ts +15 -1
- package/declarations/serializer/-private/transforms/number.d.ts +14 -1
- package/declarations/serializer/-private/transforms/string.d.ts +14 -1
- package/declarations/serializer/-private/utils.d.ts +24 -0
- package/declarations/serializer/json-api.d.ts +1 -1
- package/declarations/serializer.d.ts +4 -6
- package/declarations/store/-private.d.ts +2 -2
- package/declarations/store.d.ts +7 -0
- package/dist/adapter/error.js +386 -241
- package/dist/adapter/json-api.js +12 -0
- package/dist/adapter/rest.js +39 -3
- package/dist/adapter.js +23 -26
- package/dist/compat/builders.js +0 -1
- package/dist/compat/extensions.js +80 -3
- package/dist/compat/utils.js +14 -0
- package/dist/compat.js +17 -0
- package/dist/{errors-Cz5KrzBk.js → errors-DZKA206g.js} +24 -1
- package/dist/{hooks-D6diaM34.js → hooks-BvOqJBei.js} +33 -2
- package/dist/index.js +168 -13
- package/dist/{json-ChdEfB0X.js → json-DU8m1pGf.js} +83 -6
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +15 -2
- package/dist/{unpkg/dev-deprecated/model-for-CqXsIKws.js → model-for-CXkJw59V.js} +77 -1
- package/dist/model-fragments.js +18 -2
- package/dist/model.js +12 -8
- package/dist/{schema-provider-DJCV_6AF.js → schema-provider-DtPOp0d7.js} +93 -6
- package/dist/serializer/json-api.js +8 -3
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +3 -4
- package/dist/serializer/transform.js +51 -3
- package/dist/serializer.js +4 -7
- package/dist/store.js +13 -7
- package/dist/unpkg/dev/adapter/error.js +386 -241
- package/dist/unpkg/dev/adapter/json-api.js +13 -1
- package/dist/unpkg/dev/adapter/rest.js +39 -3
- package/dist/unpkg/dev/adapter.js +23 -26
- package/dist/unpkg/dev/compat/builders.js +0 -1
- package/dist/unpkg/dev/compat/extensions.js +80 -3
- package/dist/unpkg/dev/compat/utils.js +14 -0
- package/dist/unpkg/dev/compat.js +34 -1
- package/dist/unpkg/dev/{errors-DmGGJr3T.js → errors-DngRU-If.js} +24 -1
- package/dist/unpkg/dev/{hooks-CkYiE6Ud.js → hooks-UuiLxWxS.js} +33 -2
- package/dist/unpkg/dev/index.js +171 -13
- package/dist/unpkg/dev/json-K2Y9z6MN.js +1333 -0
- package/dist/unpkg/dev/model/-private.js +1 -1
- package/dist/unpkg/dev/model/migration-support.js +16 -2
- package/dist/unpkg/{prod-deprecated/model-for-CqXsIKws.js → dev/model-for-CXkJw59V.js} +77 -1
- package/dist/unpkg/dev/model-fragments.js +18 -2
- package/dist/unpkg/dev/model.js +12 -8
- package/dist/unpkg/dev/{schema-provider-DDVYxmUV.js → schema-provider-0D7f-QOn.js} +92 -6
- package/dist/unpkg/dev/serializer/json-api.js +9 -4
- package/dist/unpkg/dev/serializer/json.js +1 -1
- package/dist/unpkg/dev/serializer/rest.js +3 -4
- package/dist/unpkg/dev/serializer/transform.js +51 -3
- package/dist/unpkg/dev/serializer.js +4 -7
- package/dist/unpkg/dev/store.js +21 -7
- package/dist/unpkg/dev-deprecated/adapter/error.js +386 -241
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +13 -1
- package/dist/unpkg/dev-deprecated/adapter/rest.js +39 -3
- package/dist/unpkg/dev-deprecated/adapter.js +23 -26
- package/dist/unpkg/dev-deprecated/compat/builders.js +0 -1
- package/dist/unpkg/dev-deprecated/compat/extensions.js +80 -3
- package/dist/unpkg/dev-deprecated/compat/utils.js +14 -0
- package/dist/unpkg/dev-deprecated/compat.js +34 -1
- package/dist/unpkg/dev-deprecated/{errors-Spt6ubMd.js → errors-Bzidntpi.js} +24 -1
- package/dist/unpkg/dev-deprecated/{hooks-DOXegvhL.js → hooks-DVXhMW14.js} +33 -2
- package/dist/unpkg/dev-deprecated/index.js +171 -13
- package/dist/unpkg/{prod-deprecated/json-BWrZ5546.js → dev-deprecated/json-K2Y9z6MN.js} +96 -6
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/model/migration-support.js +16 -2
- package/dist/unpkg/{dev/model-for-CqXsIKws.js → dev-deprecated/model-for-CXkJw59V.js} +77 -1
- package/dist/unpkg/dev-deprecated/model-fragments.js +18 -2
- package/dist/unpkg/dev-deprecated/model.js +12 -8
- package/dist/unpkg/dev-deprecated/{schema-provider-BP6_8N-V.js → schema-provider-ZwO5_fZw.js} +84 -3
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +9 -4
- package/dist/unpkg/dev-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/dev-deprecated/serializer/rest.js +3 -4
- package/dist/unpkg/dev-deprecated/serializer/transform.js +51 -3
- package/dist/unpkg/dev-deprecated/serializer.js +4 -7
- package/dist/unpkg/dev-deprecated/store.js +21 -7
- package/dist/unpkg/prod/adapter/error.js +386 -241
- package/dist/unpkg/prod/adapter/json-api.js +13 -1
- package/dist/unpkg/prod/adapter/rest.js +39 -3
- package/dist/unpkg/prod/adapter.js +23 -26
- package/dist/unpkg/prod/compat/builders.js +0 -1
- package/dist/unpkg/prod/compat/extensions.js +70 -3
- package/dist/unpkg/prod/compat/utils.js +14 -0
- package/dist/unpkg/prod/compat.js +17 -0
- package/dist/unpkg/prod/{errors-BGVFCBmi.js → errors-B-PWeYlW.js} +24 -1
- package/dist/unpkg/prod/{hooks-BztVA_x0.js → hooks-Bx-zBziU.js} +32 -1
- package/dist/unpkg/prod/index.js +171 -5
- package/dist/unpkg/{dev/json-Cu1LNgmQ.js → prod/json-Qewu-UN9.js} +63 -19
- package/dist/unpkg/prod/model/-private.js +1 -1
- package/dist/unpkg/prod/model/migration-support.js +16 -2
- package/dist/unpkg/prod/model-for-CXkJw59V.js +297 -0
- package/dist/unpkg/prod/model-fragments.js +18 -2
- package/dist/unpkg/prod/model.js +12 -8
- package/dist/unpkg/prod/{schema-provider-DJtD_8jZ.js → schema-provider-BgRqk8i9.js} +96 -6
- package/dist/unpkg/prod/serializer/json-api.js +9 -4
- package/dist/unpkg/prod/serializer/json.js +1 -1
- package/dist/unpkg/prod/serializer/rest.js +3 -4
- package/dist/unpkg/prod/serializer/transform.js +51 -3
- package/dist/unpkg/prod/serializer.js +4 -7
- package/dist/unpkg/prod/store.js +21 -7
- package/dist/unpkg/prod-deprecated/adapter/error.js +386 -241
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +13 -1
- package/dist/unpkg/prod-deprecated/adapter/rest.js +39 -3
- package/dist/unpkg/prod-deprecated/adapter.js +23 -26
- package/dist/unpkg/prod-deprecated/compat/builders.js +0 -1
- package/dist/unpkg/prod-deprecated/compat/extensions.js +70 -3
- package/dist/unpkg/prod-deprecated/compat/utils.js +14 -0
- package/dist/unpkg/prod-deprecated/compat.js +17 -0
- package/dist/unpkg/prod-deprecated/{errors-CdDaK81x.js → errors-Dl2J9d1D.js} +24 -1
- package/dist/unpkg/prod-deprecated/{hooks-yId87yyG.js → hooks-Cm60wWTf.js} +32 -1
- package/dist/unpkg/prod-deprecated/index.js +171 -5
- package/dist/unpkg/{dev-deprecated/json-Cu1LNgmQ.js → prod-deprecated/json-Qewu-UN9.js} +63 -19
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/model/migration-support.js +16 -2
- package/dist/{model-for-CqXsIKws.js → unpkg/prod-deprecated/model-for-CXkJw59V.js} +77 -1
- package/dist/unpkg/prod-deprecated/model-fragments.js +18 -2
- package/dist/unpkg/prod-deprecated/model.js +12 -8
- package/dist/unpkg/prod-deprecated/{schema-provider-CjX55uSY.js → schema-provider-Dh6tRqVI.js} +79 -3
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +9 -4
- package/dist/unpkg/prod-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/prod-deprecated/serializer/rest.js +3 -4
- package/dist/unpkg/prod-deprecated/serializer/transform.js +51 -3
- package/dist/unpkg/prod-deprecated/serializer.js +4 -7
- package/dist/unpkg/prod-deprecated/store.js +21 -7
- package/package.json +8 -8
- package/dist/unpkg/prod/json-BWrZ5546.js +0 -1243
- package/dist/unpkg/prod/model-for-CqXsIKws.js +0 -221
|
@@ -13,6 +13,58 @@ function coerceId(id) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
Given the name of a relationship on a resource `type`, determines the
|
|
18
|
+
inverse relationship field (if any) using only the schema service.
|
|
19
|
+
|
|
20
|
+
Unlike `Model.inverseFor`, this does not require `type` to be backed by
|
|
21
|
+
a `Model` class, so it works for both `Model`-based and schema-only
|
|
22
|
+
(e.g. `withDefaults` migration-support) resources.
|
|
23
|
+
|
|
24
|
+
@private
|
|
25
|
+
*/
|
|
26
|
+
function inverseForRelationship(store, type, name) {
|
|
27
|
+
const relationship = store.schema.fields({
|
|
28
|
+
type
|
|
29
|
+
}).get(name);
|
|
30
|
+
const {
|
|
31
|
+
options
|
|
32
|
+
} = relationship;
|
|
33
|
+
if (options.inverse === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const schemaExists = store.schema.hasResource(relationship);
|
|
37
|
+
if (!schemaExists) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const inverseField = store.schema.fields(relationship).get(options.inverse);
|
|
41
|
+
return inverseField ?? null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
Given a relationship field on a resource `type`, determines the
|
|
46
|
+
cardinality of the relationship using only the schema service.
|
|
47
|
+
|
|
48
|
+
Unlike `Model.determineRelationshipType`, this does not require `type`
|
|
49
|
+
to be backed by a `Model` class, so it works for both `Model`-based and
|
|
50
|
+
schema-only (e.g. `withDefaults` migration-support) resources.
|
|
51
|
+
|
|
52
|
+
@private
|
|
53
|
+
*/
|
|
54
|
+
function determineRelationshipType(store, type, knownSide) {
|
|
55
|
+
const knownKind = knownSide.kind;
|
|
56
|
+
const inverse = inverseForRelationship(store, type, knownSide.name);
|
|
57
|
+
if (!inverse) {
|
|
58
|
+
return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone';
|
|
59
|
+
}
|
|
60
|
+
const otherKind = inverse.kind;
|
|
61
|
+
if (otherKind === 'belongsTo') {
|
|
62
|
+
return knownKind === 'belongsTo' ? 'oneToOne' : 'manyToOne';
|
|
63
|
+
} else {
|
|
64
|
+
return knownKind === 'belongsTo' ? 'oneToMany' : 'manyToMany';
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
16
68
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
17
69
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
18
70
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
@@ -381,11 +433,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
381
433
|
};
|
|
382
434
|
const meta = this.extractMeta(store, primaryModelClass, payload);
|
|
383
435
|
if (meta) {
|
|
384
|
-
(test => {
|
|
385
|
-
if (!test) {
|
|
386
|
-
throw new Error('The `meta` returned from `extractMeta` has to be an object, not "' + typeof meta + '".');
|
|
387
|
-
}
|
|
388
|
-
})(typeof meta === 'object');
|
|
389
436
|
// @ts-expect-error untyped
|
|
390
437
|
documentHash.meta = meta;
|
|
391
438
|
}
|
|
@@ -691,9 +738,6 @@ const JSONSerializer = Serializer.extend({
|
|
|
691
738
|
@private
|
|
692
739
|
*/
|
|
693
740
|
_getMappedKey(key, modelClass) {
|
|
694
|
-
console.warn('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', modelClass.attributes.has(key) || modelClass.relationshipsByName.has(key), {
|
|
695
|
-
id: 'ds.serializer.no-mapped-attrs-key'
|
|
696
|
-
}); // @ts-expect-error attrs is dynamically injected
|
|
697
741
|
const attrs = this.attrs;
|
|
698
742
|
let mappedKey;
|
|
699
743
|
if (attrs && attrs[key]) {
|
|
@@ -741,9 +785,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
741
785
|
*/
|
|
742
786
|
shouldSerializeHasMany(snapshot, key, relationship) {
|
|
743
787
|
// @ts-expect-error store is dynamically injected
|
|
744
|
-
const
|
|
745
|
-
// @ts-expect-error store is dynamically injected
|
|
746
|
-
const relationshipType = schema.determineRelationshipType(relationship, this.store);
|
|
788
|
+
const relationshipType = determineRelationshipType(this.store, snapshot.modelName, relationship);
|
|
747
789
|
if (this._mustSerialize(key)) {
|
|
748
790
|
return true;
|
|
749
791
|
}
|
|
@@ -782,8 +824,15 @@ const JSONSerializer = Serializer.extend({
|
|
|
782
824
|
`serialize` takes an options hash with a single option:
|
|
783
825
|
`includeId`. If this option is `true`, `serialize` will,
|
|
784
826
|
by default include the ID in the JSON object it builds.
|
|
785
|
-
|
|
786
|
-
|
|
827
|
+
Whether `includeId` is `true` or `false` depends on the
|
|
828
|
+
adapter and the operation being performed, since it is the
|
|
829
|
+
adapter that invokes `serialize` and decides which options
|
|
830
|
+
to pass. For instance, `RESTAdapter` passes `includeId: true`
|
|
831
|
+
when serializing a record for `createRecord`, but not for
|
|
832
|
+
`updateRecord`, while `JSONAPIAdapter` passes `includeId: true`
|
|
833
|
+
for both `createRecord` and `updateRecord`. Refer to the
|
|
834
|
+
documentation for the adapter and serializer pairing you are
|
|
835
|
+
using for specifics.
|
|
787
836
|
## Customization
|
|
788
837
|
Your server may expect a different JSON format than the
|
|
789
838
|
built-in serialization format.
|
|
@@ -1245,12 +1294,7 @@ const JSONSerializer = Serializer.extend({
|
|
|
1245
1294
|
*/
|
|
1246
1295
|
transformFor(attributeType, skipAssertion) {
|
|
1247
1296
|
const transform = getOwner(this).lookup(`transform:${attributeType}`);
|
|
1248
|
-
(test => {
|
|
1249
|
-
if (!test) {
|
|
1250
|
-
throw new Error(`Unable to find the transform for \`attr('${attributeType}')\``);
|
|
1251
|
-
}
|
|
1252
|
-
})(skipAssertion || !!transform);
|
|
1253
1297
|
return transform;
|
|
1254
1298
|
}
|
|
1255
1299
|
});
|
|
1256
|
-
export { JSONSerializer as J, coerceId as c };
|
|
1300
|
+
export { JSONSerializer as J, coerceId as c, inverseForRelationship as i };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-
|
|
1
|
+
export { E as Errors, L as LEGACY_SUPPORT, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "../errors-Dl2J9d1D.js";
|
|
@@ -4,8 +4,8 @@ import { notifyInternalSignal } from '@warp-drive/core/signals/-leaked';
|
|
|
4
4
|
import { assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
5
5
|
import { getOrSetGlobal } from '@warp-drive/core/types/-private';
|
|
6
6
|
import { Type } from '@warp-drive/core/types/symbols';
|
|
7
|
-
import { l as lookupLegacySupport, E as Errors } from "../errors-
|
|
8
|
-
import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, i as deleteRecord, R as RecordState, j as changedAttributes, k as belongsTo, l as createSnapshot } from "../schema-provider-
|
|
7
|
+
import { l as lookupLegacySupport, E as Errors } from "../errors-Dl2J9d1D.js";
|
|
8
|
+
import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as save, r as rollbackAttributes, c as _reload, d as reload, h as hasMany, e as _destroyRecord, f as destroyRecord, i as deleteRecord, R as RecordState, j as changedAttributes, k as belongsTo, l as createSnapshot } from "../schema-provider-Dh6tRqVI.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* This module provides support for migrating away from @warp-drive/legacy/model
|
|
@@ -27,6 +27,12 @@ import { b as buildSchema, u as unloadRecord, s as serialize, _ as _save, a as s
|
|
|
27
27
|
* @module
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Adds the `Model`-style `belongsTo`/`hasMany` reference methods to a
|
|
32
|
+
* {@link TypedRecordInstance}, for use when migrating a resource from
|
|
33
|
+
* `Model` to a schema-based record while preserving these APIs.
|
|
34
|
+
*/
|
|
35
|
+
|
|
30
36
|
// 'isDestroying', 'isDestroyed'
|
|
31
37
|
const LegacyFields = ['_createSnapshot', 'adapterError', 'belongsTo', 'changedAttributes', 'constructor', 'currentState', 'deleteRecord', 'destroyRecord', 'dirtyType', 'errors', 'hasDirtyAttributes', 'hasMany', 'isDeleted', 'isEmpty', 'isError', 'isLoaded', 'isLoading', 'isNew', 'isSaving', 'isValid', 'reload', 'rollbackAttributes', 'save', 'serialize', 'unloadRecord'];
|
|
32
38
|
|
|
@@ -416,6 +422,9 @@ function registerDerivations(schema) {
|
|
|
416
422
|
* @public
|
|
417
423
|
*/
|
|
418
424
|
|
|
425
|
+
/**
|
|
426
|
+
* See the {@link DelegatingSchemaService | class documentation above} for usage.
|
|
427
|
+
*/
|
|
419
428
|
class DelegatingSchemaService {
|
|
420
429
|
/** @internal */
|
|
421
430
|
_preferred;
|
|
@@ -425,6 +434,11 @@ class DelegatingSchemaService {
|
|
|
425
434
|
this._preferred = schema;
|
|
426
435
|
this._secondary = buildSchema(store);
|
|
427
436
|
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Whether the given resource's schema is being served by the fallback
|
|
440
|
+
* (legacy Model-derived) schema service rather than the primary one.
|
|
441
|
+
*/
|
|
428
442
|
isDelegated(resource) {
|
|
429
443
|
return !this._preferred.hasResource(resource) && this._secondary.hasResource(resource);
|
|
430
444
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { tracked, cached } from '@glimmer/tracking';
|
|
2
2
|
import { Context } from '@warp-drive/core/reactive/-private';
|
|
3
3
|
import { a as decorateFieldV2, i as initializeDeferredDecorator, d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The features added to an object resource by {@link FragmentExtension}, providing
|
|
7
|
+
* a subset of the legacy `ModelFragments` fragment API for migrated resources.
|
|
8
|
+
*/
|
|
4
9
|
class Fragment {
|
|
5
10
|
static {
|
|
6
11
|
decorateFieldV2(this.prototype, "isDestroying", [tracked], function () {
|
|
@@ -8,12 +13,21 @@ class Fragment {
|
|
|
8
13
|
});
|
|
9
14
|
}
|
|
10
15
|
#isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0); // We might want to check the parent values once we move this code to warp-drive.
|
|
16
|
+
/**
|
|
17
|
+
* Whether this fragment is in the process of being destroyed.
|
|
18
|
+
*/
|
|
11
19
|
static {
|
|
12
20
|
decorateFieldV2(this.prototype, "isDestroyed", [tracked], function () {
|
|
13
21
|
return false;
|
|
14
22
|
});
|
|
15
23
|
}
|
|
16
24
|
#isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
|
|
25
|
+
/**
|
|
26
|
+
* Whether this fragment has been destroyed.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Whether this fragment (or the attribute it is rooted at) has uncommitted changes.
|
|
30
|
+
*/
|
|
17
31
|
get hasDirtyAttributes() {
|
|
18
32
|
const {
|
|
19
33
|
path,
|
|
@@ -27,18 +41,30 @@ class Fragment {
|
|
|
27
41
|
}
|
|
28
42
|
return false;
|
|
29
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Always `true`. Used to distinguish fragments from other resources.
|
|
47
|
+
*/
|
|
30
48
|
static {
|
|
31
49
|
decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
|
|
32
50
|
}
|
|
33
51
|
get isFragment() {
|
|
34
52
|
return true;
|
|
35
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The resource type of this fragment, if known.
|
|
57
|
+
*/
|
|
36
58
|
get $type() {
|
|
37
59
|
const {
|
|
38
60
|
field
|
|
39
61
|
} = this[Context];
|
|
40
62
|
return field?.type;
|
|
41
63
|
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Reverts this fragment's attribute back to its last known remote value.
|
|
67
|
+
*/
|
|
42
68
|
rollbackAttributes() {
|
|
43
69
|
const {
|
|
44
70
|
path,
|
|
@@ -51,11 +77,21 @@ class Fragment {
|
|
|
51
77
|
}
|
|
52
78
|
}
|
|
53
79
|
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A schema extension that adds the {@link Fragment} API to migrated
|
|
83
|
+
* `ModelFragments` object resources.
|
|
84
|
+
*/
|
|
54
85
|
const FragmentExtension = {
|
|
55
86
|
kind: 'object',
|
|
56
87
|
name: 'fragment',
|
|
57
88
|
features: Fragment
|
|
58
89
|
};
|
|
90
|
+
|
|
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
|
+
*/
|
|
59
95
|
class FragmentArray {
|
|
60
96
|
static {
|
|
61
97
|
decorateFieldV2(this.prototype, "isDestroying", [tracked], function () {
|
|
@@ -63,18 +99,29 @@ class FragmentArray {
|
|
|
63
99
|
});
|
|
64
100
|
}
|
|
65
101
|
#isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0); // We might want to check the parent values once we move this code to warp-drive.
|
|
102
|
+
/**
|
|
103
|
+
* Whether this fragment array is in the process of being destroyed.
|
|
104
|
+
*/
|
|
66
105
|
static {
|
|
67
106
|
decorateFieldV2(this.prototype, "isDestroyed", [tracked], function () {
|
|
68
107
|
return false;
|
|
69
108
|
});
|
|
70
109
|
}
|
|
71
110
|
#isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
|
|
111
|
+
/**
|
|
112
|
+
* Whether this fragment array has been destroyed.
|
|
113
|
+
*/
|
|
114
|
+
/**
|
|
115
|
+
* Whether this fragment array (or any of its members) has uncommitted changes.
|
|
116
|
+
*/
|
|
72
117
|
get hasDirtyAttributes() {
|
|
118
|
+
const array = this;
|
|
119
|
+
const context = array[Context];
|
|
73
120
|
const {
|
|
74
121
|
path,
|
|
75
122
|
resourceKey,
|
|
76
123
|
store
|
|
77
|
-
} =
|
|
124
|
+
} = context;
|
|
78
125
|
const record = store.peekRecord(resourceKey);
|
|
79
126
|
if (record.hasDirtyAttributes && path) {
|
|
80
127
|
const root = path.at(0);
|
|
@@ -82,6 +129,10 @@ class FragmentArray {
|
|
|
82
129
|
}
|
|
83
130
|
return false;
|
|
84
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Adds an existing fragment to this array, if one was given.
|
|
135
|
+
*/
|
|
85
136
|
static {
|
|
86
137
|
decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
|
|
87
138
|
}
|
|
@@ -91,12 +142,20 @@ class FragmentArray {
|
|
|
91
142
|
}
|
|
92
143
|
return this.addObject(fragment);
|
|
93
144
|
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Appends a new fragment to the end of this array, if one was given.
|
|
148
|
+
*/
|
|
94
149
|
createFragment(fragment) {
|
|
95
150
|
if (!fragment) {
|
|
96
151
|
return;
|
|
97
152
|
}
|
|
98
153
|
return this.pushObject(fragment);
|
|
99
154
|
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Removes the given fragment from this array, if present.
|
|
158
|
+
*/
|
|
100
159
|
removeFragment(fragment) {
|
|
101
160
|
if (!fragment) {
|
|
102
161
|
return;
|
|
@@ -106,6 +165,10 @@ class FragmentArray {
|
|
|
106
165
|
this.splice(index, 1);
|
|
107
166
|
}
|
|
108
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Reverts each member fragment's attribute back to its last known remote value.
|
|
171
|
+
*/
|
|
109
172
|
rollbackAttributes() {
|
|
110
173
|
for (const fragment of this) {
|
|
111
174
|
// @ts-expect-error TODO: fix these types
|
|
@@ -113,6 +176,11 @@ class FragmentArray {
|
|
|
113
176
|
}
|
|
114
177
|
}
|
|
115
178
|
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A schema extension that adds the {@link FragmentArray} API to migrated
|
|
182
|
+
* `ModelFragments` array resources.
|
|
183
|
+
*/
|
|
116
184
|
const FragmentArrayExtension = {
|
|
117
185
|
kind: 'array',
|
|
118
186
|
name: 'fragment-array',
|
|
@@ -217,5 +285,13 @@ class ShimModelClass {
|
|
|
217
285
|
function fragmentsModelFor(modelName) {
|
|
218
286
|
return getShimClass(this, modelName);
|
|
219
287
|
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The `modelFor` fallback used to construct a `ShimModelClass` schema for a
|
|
291
|
+
* type when ModelFragments support is enabled and no real `Model` subclass
|
|
292
|
+
* is registered for that type.
|
|
293
|
+
*
|
|
294
|
+
* @public
|
|
295
|
+
*/
|
|
220
296
|
const modelFor = fragmentsModelFor;
|
|
221
297
|
export { FragmentExtension as F, FragmentArrayExtension as a, FragmentArray as b, Fragment as c, fragmentsModelFor as f, modelFor as m };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pluralize, singularize } from '@warp-drive/utilities/string';
|
|
2
2
|
import { withDefaults } from './model/migration-support.js';
|
|
3
|
-
import { F as FragmentExtension, a as FragmentArrayExtension } from "./model-for-
|
|
4
|
-
export { c as Fragment, b as FragmentArray, m as modelFor } from "./model-for-
|
|
3
|
+
import { F as FragmentExtension, a as FragmentArrayExtension } from "./model-for-CXkJw59V.js";
|
|
4
|
+
export { c as Fragment, b as FragmentArray, m as modelFor } from "./model-for-CXkJw59V.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Used as a helper to setup the relevant parts of an array
|
|
@@ -62,6 +62,15 @@ function withFragmentArrayDefaults(fragmentArrayType, fragmentArrayName) {
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Used as a helper to setup the relevant parts of a legacy resource schema
|
|
68
|
+
* migrated from `Model`, applying the `ember-object` and `fragment` object
|
|
69
|
+
* extensions and a default `@id` identity field.
|
|
70
|
+
*
|
|
71
|
+
* @param schema the partial legacy resource schema to complete
|
|
72
|
+
* @returns the completed resource schema
|
|
73
|
+
*/
|
|
65
74
|
function withLegacy(schema) {
|
|
66
75
|
return withDefaults({
|
|
67
76
|
...schema,
|
|
@@ -72,6 +81,13 @@ function withLegacy(schema) {
|
|
|
72
81
|
objectExtensions: ['ember-object', 'fragment']
|
|
73
82
|
});
|
|
74
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Registers the {@link FragmentExtension}/{@link FragmentArrayExtension} schema
|
|
87
|
+
* extensions on the given `SchemaService`, enabling ModelFragments migration support.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
75
91
|
function registerFragmentExtensions(schema) {
|
|
76
92
|
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentExtension);
|
|
77
93
|
schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentArrayExtension);
|
|
@@ -3,10 +3,10 @@ import { recordIdentifierFor } from '@warp-drive/core';
|
|
|
3
3
|
import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
4
4
|
import { i as isElementDescriptor, n as normalizeModelName } from "./util-B6cn-i93.js";
|
|
5
5
|
import { assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
6
|
-
import { l as lookupLegacySupport } from "./errors-
|
|
6
|
+
import { l as lookupLegacySupport } from "./errors-Dl2J9d1D.js";
|
|
7
7
|
import { singularize, dasherize } from '@warp-drive/utilities/string';
|
|
8
|
-
export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-
|
|
9
|
-
export { i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-
|
|
8
|
+
export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-Dh6tRqVI.js";
|
|
9
|
+
export { i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-Cm60wWTf.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Options provided to the attr decorator are
|
|
@@ -44,6 +44,7 @@ function _attr(type, options) {
|
|
|
44
44
|
kind: 'attribute',
|
|
45
45
|
isAttribute: true,
|
|
46
46
|
options: options,
|
|
47
|
+
sourceKey: options.sourceKey,
|
|
47
48
|
key: null
|
|
48
49
|
};
|
|
49
50
|
return computed({
|
|
@@ -52,14 +53,15 @@ function _attr(type, options) {
|
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
const cache = this[RecordStore].cache;
|
|
55
|
-
return cache.getAttr(recordIdentifierFor(this), key);
|
|
56
|
+
return cache.getAttr(recordIdentifierFor(this), meta.sourceKey ?? key);
|
|
56
57
|
},
|
|
57
58
|
set(key, value) {
|
|
58
59
|
const identifier = recordIdentifierFor(this);
|
|
59
60
|
const cache = this[RecordStore].cache;
|
|
60
|
-
const
|
|
61
|
+
const cacheKey = meta.sourceKey ?? key;
|
|
62
|
+
const currentValue = cache.getAttr(identifier, cacheKey);
|
|
61
63
|
if (currentValue !== value) {
|
|
62
|
-
cache.setAttr(identifier,
|
|
64
|
+
cache.setAttr(identifier, cacheKey, value);
|
|
63
65
|
if (!this.isValid) {
|
|
64
66
|
const {
|
|
65
67
|
errors
|
|
@@ -201,7 +203,8 @@ function _belongsTo(type, options) {
|
|
|
201
203
|
type: normalizeModelName(type),
|
|
202
204
|
options: options,
|
|
203
205
|
kind: 'belongsTo',
|
|
204
|
-
name: '<Unknown BelongsTo>'
|
|
206
|
+
name: '<Unknown BelongsTo>',
|
|
207
|
+
sourceKey: options.sourceKey
|
|
205
208
|
};
|
|
206
209
|
return computed({
|
|
207
210
|
get(key) {
|
|
@@ -407,7 +410,8 @@ function _hasMany(type, options) {
|
|
|
407
410
|
type: normalizeType(type),
|
|
408
411
|
options,
|
|
409
412
|
kind: 'hasMany',
|
|
410
|
-
name: '<Unknown BelongsTo>'
|
|
413
|
+
name: '<Unknown BelongsTo>',
|
|
414
|
+
sourceKey: options.sourceKey
|
|
411
415
|
};
|
|
412
416
|
return computed({
|
|
413
417
|
get(key) {
|
package/dist/unpkg/prod-deprecated/{schema-provider-CjX55uSY.js → schema-provider-Dh6tRqVI.js}
RENAMED
|
@@ -4,7 +4,7 @@ import { recordIdentifierFor, storeFor } from '@warp-drive/core';
|
|
|
4
4
|
import { notifyInternalSignal, peekInternalSignal, withSignalStore, gate, memoized, defineSignal, entangleSignal, defineGate } from '@warp-drive/core/signals/-leaked';
|
|
5
5
|
import { assertPrivateStore, recordIdentifierFor as recordIdentifierFor$1, coerceId } from '@warp-drive/core/store/-private';
|
|
6
6
|
import { RecordStore } from '@warp-drive/core/types/symbols';
|
|
7
|
-
import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-
|
|
7
|
+
import { l as lookupLegacySupport, L as LEGACY_SUPPORT, E as Errors } from "./errors-Dl2J9d1D.js";
|
|
8
8
|
import { u as upgradeStore, F as FetchManager } from "./-private-BdyZaGEh.js";
|
|
9
9
|
import { cacheFor } from '@ember/object/internals';
|
|
10
10
|
import { Context } from '@warp-drive/core/reactive/-private';
|
|
@@ -866,6 +866,9 @@ class Model extends EmberObject {
|
|
|
866
866
|
get isError() {
|
|
867
867
|
return this.currentState.isError;
|
|
868
868
|
}
|
|
869
|
+
/**
|
|
870
|
+
* `isError` is read-only and cannot be set directly.
|
|
871
|
+
*/
|
|
869
872
|
static {
|
|
870
873
|
decorateMethodV2(this.prototype, "isError", [memoized]);
|
|
871
874
|
}
|
|
@@ -903,6 +906,10 @@ class Model extends EmberObject {
|
|
|
903
906
|
|
|
904
907
|
return recordIdentifierFor(this).id;
|
|
905
908
|
}
|
|
909
|
+
/**
|
|
910
|
+
* Assigns the resource's primary key. Typically only used internally
|
|
911
|
+
* when a client-created record is assigned an id upon being saved.
|
|
912
|
+
*/
|
|
906
913
|
static {
|
|
907
914
|
decorateMethodV2(this.prototype, "id", [gate]);
|
|
908
915
|
}
|
|
@@ -937,6 +944,9 @@ class Model extends EmberObject {
|
|
|
937
944
|
}
|
|
938
945
|
return this.___recordState;
|
|
939
946
|
}
|
|
947
|
+
/**
|
|
948
|
+
* `currentState` is read-only and cannot be set directly.
|
|
949
|
+
*/
|
|
940
950
|
static {
|
|
941
951
|
decorateMethodV2(this.prototype, "currentState", [gate]);
|
|
942
952
|
}
|
|
@@ -1010,6 +1020,9 @@ class Model extends EmberObject {
|
|
|
1010
1020
|
get adapterError() {
|
|
1011
1021
|
return this.currentState.adapterError;
|
|
1012
1022
|
}
|
|
1023
|
+
/**
|
|
1024
|
+
* `adapterError` is read-only and cannot be set directly.
|
|
1025
|
+
*/
|
|
1013
1026
|
static {
|
|
1014
1027
|
decorateMethodV2(this.prototype, "adapterError", [memoized]);
|
|
1015
1028
|
}
|
|
@@ -1077,12 +1090,29 @@ class Model extends EmberObject {
|
|
|
1077
1090
|
eachRelationship(callback, binding) {
|
|
1078
1091
|
this.constructor.eachRelationship(callback, binding);
|
|
1079
1092
|
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* Returns the relationship schema for the given relationship name, if any.
|
|
1096
|
+
*/
|
|
1080
1097
|
relationshipFor(name) {
|
|
1081
1098
|
return this.constructor.relationshipsByName.get(name);
|
|
1082
1099
|
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Returns the inverse relationship schema for the given relationship
|
|
1103
|
+
* name, if one exists. See {@link Model.inverseFor | the static inverseFor}.
|
|
1104
|
+
*/
|
|
1083
1105
|
inverseFor(name) {
|
|
1084
1106
|
return this.constructor.inverseFor(name, storeFor(this, false));
|
|
1085
1107
|
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Iterates over the attributes defined on this record's class, calling
|
|
1111
|
+
* `callback` for each one. See {@link Model.eachAttribute | the static eachAttribute}.
|
|
1112
|
+
*
|
|
1113
|
+
* @param callback the callback to invoke
|
|
1114
|
+
* @param binding the value to which the callback's `this` should be bound
|
|
1115
|
+
*/
|
|
1086
1116
|
eachAttribute(callback, binding) {
|
|
1087
1117
|
this.constructor.eachAttribute(callback, binding);
|
|
1088
1118
|
}
|
|
@@ -1149,6 +1179,11 @@ class Model extends EmberObject {
|
|
|
1149
1179
|
const relationship = this.relationshipsByName.get(name);
|
|
1150
1180
|
return relationship && store.modelFor(relationship.type);
|
|
1151
1181
|
}
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* A cache of resolved inverse relationships by name, populated lazily by
|
|
1185
|
+
* {@link Model.inverseFor | inverseFor}.
|
|
1186
|
+
*/
|
|
1152
1187
|
static get inverseMap() {
|
|
1153
1188
|
return Object.create(null);
|
|
1154
1189
|
}
|
|
@@ -1191,6 +1226,9 @@ class Model extends EmberObject {
|
|
|
1191
1226
|
}
|
|
1192
1227
|
}
|
|
1193
1228
|
|
|
1229
|
+
/**
|
|
1230
|
+
* @private
|
|
1231
|
+
*/
|
|
1194
1232
|
//Calculate the inverse, ignoring the cache
|
|
1195
1233
|
static _findInverseFor(name, store) {
|
|
1196
1234
|
const relationship = this.relationshipsByName.get(name);
|
|
@@ -1376,6 +1414,12 @@ class Model extends EmberObject {
|
|
|
1376
1414
|
}
|
|
1377
1415
|
return map;
|
|
1378
1416
|
}
|
|
1417
|
+
|
|
1418
|
+
/**
|
|
1419
|
+
* A hash of the model's relationship schemas keyed by relationship name.
|
|
1420
|
+
* See also {@link Model.relationshipsByName | relationshipsByName}, which
|
|
1421
|
+
* provides the same information as a `Map`.
|
|
1422
|
+
*/
|
|
1379
1423
|
static {
|
|
1380
1424
|
decorateMethodV2(this, "relationshipsByName", [computeOnce]);
|
|
1381
1425
|
}
|
|
@@ -1686,6 +1730,13 @@ defineGate(Model.prototype, 'isReloading', {
|
|
|
1686
1730
|
// @ts-expect-error specially handled prop
|
|
1687
1731
|
isLocal: true
|
|
1688
1732
|
});
|
|
1733
|
+
|
|
1734
|
+
/**
|
|
1735
|
+
* Restores the pre-`RequestManager` implementations of `save`,
|
|
1736
|
+
* `destroyRecord`, and `reload` onto the given `Model` subclass, for
|
|
1737
|
+
* apps that have not yet migrated off of the deprecated
|
|
1738
|
+
* `ENABLE_LEGACY_REQUEST_METHODS` behaviors.
|
|
1739
|
+
*/
|
|
1689
1740
|
function restoreDeprecatedModelRequestBehaviors(ModelKlass) {
|
|
1690
1741
|
// @ts-expect-error TS doesn't know how to do `this` function overloads
|
|
1691
1742
|
ModelKlass.prototype.save = _save;
|
|
@@ -1783,7 +1834,11 @@ class ModelSchemaProvider {
|
|
|
1783
1834
|
registerHashFn(hashFn) {}
|
|
1784
1835
|
/** @internal */
|
|
1785
1836
|
_loadModelSchema(type) {
|
|
1786
|
-
const
|
|
1837
|
+
const factory = getModelFactory(this.store, type);
|
|
1838
|
+
if (!factory) {
|
|
1839
|
+
throw new Error(`No model was found for '${type}'`);
|
|
1840
|
+
}
|
|
1841
|
+
const modelClass = factory.class;
|
|
1787
1842
|
const attributeMap = modelClass.attributes;
|
|
1788
1843
|
const attributes = Object.create(null);
|
|
1789
1844
|
attributeMap.forEach((meta, name) => attributes[name] = meta);
|
|
@@ -1804,11 +1859,17 @@ class ModelSchemaProvider {
|
|
|
1804
1859
|
type,
|
|
1805
1860
|
fields: Array.from(fields.values())
|
|
1806
1861
|
};
|
|
1862
|
+
const cacheFields = new Map();
|
|
1863
|
+
for (const field of fields.values()) {
|
|
1864
|
+
const cacheKey = field.sourceKey ?? field.name;
|
|
1865
|
+
cacheFields.set(cacheKey, field);
|
|
1866
|
+
}
|
|
1807
1867
|
const internalSchema = {
|
|
1808
1868
|
schema,
|
|
1809
1869
|
attributes,
|
|
1810
1870
|
relationships,
|
|
1811
|
-
fields
|
|
1871
|
+
fields,
|
|
1872
|
+
cacheFields
|
|
1812
1873
|
};
|
|
1813
1874
|
this._schemas.set(type, internalSchema);
|
|
1814
1875
|
return internalSchema;
|
|
@@ -1820,6 +1881,13 @@ class ModelSchemaProvider {
|
|
|
1820
1881
|
}
|
|
1821
1882
|
return this._schemas.get(type).fields;
|
|
1822
1883
|
}
|
|
1884
|
+
cacheFields(resource) {
|
|
1885
|
+
const type = normalizeModelName(resource.type);
|
|
1886
|
+
if (!this._schemas.has(type)) {
|
|
1887
|
+
this._loadModelSchema(type);
|
|
1888
|
+
}
|
|
1889
|
+
return this._schemas.get(type).cacheFields;
|
|
1890
|
+
}
|
|
1823
1891
|
hasResource(resource) {
|
|
1824
1892
|
const type = normalizeModelName(resource.type);
|
|
1825
1893
|
if (this._schemas.has(type)) {
|
|
@@ -1868,6 +1936,14 @@ class ModelSchemaProvider {
|
|
|
1868
1936
|
return this._schemas.get(type).relationships;
|
|
1869
1937
|
};
|
|
1870
1938
|
}
|
|
1939
|
+
|
|
1940
|
+
/**
|
|
1941
|
+
* The `createSchemaService` implementation for use with `Model`. Pass
|
|
1942
|
+
* the result of this to your store's `createSchemaService` method when
|
|
1943
|
+
* configuring the store to use `Model` for schema information.
|
|
1944
|
+
*
|
|
1945
|
+
* @public
|
|
1946
|
+
*/
|
|
1871
1947
|
function buildSchema(store) {
|
|
1872
1948
|
return new ModelSchemaProvider(store);
|
|
1873
1949
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { dasherize, pluralize, singularize } from '@warp-drive/utilities/string';
|
|
2
|
-
import { J as JSONSerializer } from "../json-
|
|
2
|
+
import { J as JSONSerializer } from "../json-Qewu-UN9.js";
|
|
3
3
|
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
@@ -102,7 +102,7 @@ import { J as JSONSerializer } from "../json-BWrZ5546.js";
|
|
|
102
102
|
`extractRelationship`.
|
|
103
103
|
|
|
104
104
|
```js [app/serializers/application.js]
|
|
105
|
-
import JSONAPISerializer from '@warp-drive/legacy/serializer/json-api';
|
|
105
|
+
import { JSONAPISerializer } from '@warp-drive/legacy/serializer/json-api';
|
|
106
106
|
|
|
107
107
|
export default class ApplicationSerializer extends JSONAPISerializer {
|
|
108
108
|
normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
|
|
@@ -136,10 +136,15 @@ const JSONAPISerializer = JSONSerializer.extend({
|
|
|
136
136
|
*/
|
|
137
137
|
_normalizeDocumentHelper(documentHash) {
|
|
138
138
|
if (Array.isArray(documentHash.data)) {
|
|
139
|
-
const ret =
|
|
139
|
+
const ret = [];
|
|
140
140
|
for (let i = 0; i < documentHash.data.length; i++) {
|
|
141
141
|
const data = documentHash.data[i];
|
|
142
|
-
|
|
142
|
+
const normalized = this._normalizeResourceHelper(data);
|
|
143
|
+
if (normalized !== null) {
|
|
144
|
+
// @ts-expect-error untyped
|
|
145
|
+
// can be null when unknown type is encountered
|
|
146
|
+
ret.push(normalized);
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
149
|
documentHash.data = ret;
|
|
145
150
|
} else if (documentHash.data && typeof documentHash.data === 'object') {
|