@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
|
@@ -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-CWr5WQOT.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-Bzidntpi.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-ZwO5_fZw.js";
|
|
9
|
+
export { i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-DVXhMW14.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({
|
|
@@ -57,7 +58,7 @@ function _attr(type, options) {
|
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
60
|
const cache = this[RecordStore].cache;
|
|
60
|
-
return cache.getAttr(recordIdentifierFor(this), key);
|
|
61
|
+
return cache.getAttr(recordIdentifierFor(this), meta.sourceKey ?? key);
|
|
61
62
|
},
|
|
62
63
|
set(key, value) {
|
|
63
64
|
{
|
|
@@ -72,9 +73,10 @@ function _attr(type, options) {
|
|
|
72
73
|
}
|
|
73
74
|
})(!this.currentState.isDeleted);
|
|
74
75
|
const cache = this[RecordStore].cache;
|
|
75
|
-
const
|
|
76
|
+
const cacheKey = meta.sourceKey ?? key;
|
|
77
|
+
const currentValue = cache.getAttr(identifier, cacheKey);
|
|
76
78
|
if (currentValue !== value) {
|
|
77
|
-
cache.setAttr(identifier,
|
|
79
|
+
cache.setAttr(identifier, cacheKey, value);
|
|
78
80
|
if (!this.isValid) {
|
|
79
81
|
const {
|
|
80
82
|
errors
|
|
@@ -226,7 +228,8 @@ function _belongsTo(type, options) {
|
|
|
226
228
|
type: normalizeModelName(type),
|
|
227
229
|
options: options,
|
|
228
230
|
kind: 'belongsTo',
|
|
229
|
-
name: '<Unknown BelongsTo>'
|
|
231
|
+
name: '<Unknown BelongsTo>',
|
|
232
|
+
sourceKey: options.sourceKey
|
|
230
233
|
};
|
|
231
234
|
return computed({
|
|
232
235
|
get(key) {
|
|
@@ -471,7 +474,8 @@ function _hasMany(type, options) {
|
|
|
471
474
|
type: normalizeType(type),
|
|
472
475
|
options,
|
|
473
476
|
kind: 'hasMany',
|
|
474
|
-
name: '<Unknown BelongsTo>'
|
|
477
|
+
name: '<Unknown BelongsTo>',
|
|
478
|
+
sourceKey: options.sourceKey
|
|
475
479
|
};
|
|
476
480
|
return computed({
|
|
477
481
|
get(key) {
|
package/dist/unpkg/dev-deprecated/{schema-provider-BP6_8N-V.js → schema-provider-ZwO5_fZw.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-Bzidntpi.js";
|
|
8
8
|
import { u as upgradeStore, F as FetchManager } from "./-private-DtjBbEgy.js";
|
|
9
9
|
import { cacheFor } from '@ember/object/internals';
|
|
10
10
|
import { Context } from '@warp-drive/core/reactive/-private';
|
|
@@ -930,6 +930,9 @@ class Model extends EmberObject {
|
|
|
930
930
|
get isError() {
|
|
931
931
|
return this.currentState.isError;
|
|
932
932
|
}
|
|
933
|
+
/**
|
|
934
|
+
* `isError` is read-only and cannot be set directly.
|
|
935
|
+
*/
|
|
933
936
|
static {
|
|
934
937
|
decorateMethodV2(this.prototype, "isError", [memoized]);
|
|
935
938
|
}
|
|
@@ -977,6 +980,10 @@ class Model extends EmberObject {
|
|
|
977
980
|
}
|
|
978
981
|
return recordIdentifierFor(this).id;
|
|
979
982
|
}
|
|
983
|
+
/**
|
|
984
|
+
* Assigns the resource's primary key. Typically only used internally
|
|
985
|
+
* when a client-created record is assigned an id upon being saved.
|
|
986
|
+
*/
|
|
980
987
|
static {
|
|
981
988
|
decorateMethodV2(this.prototype, "id", [gate]);
|
|
982
989
|
}
|
|
@@ -1012,6 +1019,9 @@ class Model extends EmberObject {
|
|
|
1012
1019
|
|
|
1013
1020
|
return this.___recordState;
|
|
1014
1021
|
}
|
|
1022
|
+
/**
|
|
1023
|
+
* `currentState` is read-only and cannot be set directly.
|
|
1024
|
+
*/
|
|
1015
1025
|
static {
|
|
1016
1026
|
decorateMethodV2(this.prototype, "currentState", [gate]);
|
|
1017
1027
|
}
|
|
@@ -1085,6 +1095,9 @@ class Model extends EmberObject {
|
|
|
1085
1095
|
get adapterError() {
|
|
1086
1096
|
return this.currentState.adapterError;
|
|
1087
1097
|
}
|
|
1098
|
+
/**
|
|
1099
|
+
* `adapterError` is read-only and cannot be set directly.
|
|
1100
|
+
*/
|
|
1088
1101
|
static {
|
|
1089
1102
|
decorateMethodV2(this.prototype, "adapterError", [memoized]);
|
|
1090
1103
|
}
|
|
@@ -1158,12 +1171,29 @@ class Model extends EmberObject {
|
|
|
1158
1171
|
eachRelationship(callback, binding) {
|
|
1159
1172
|
this.constructor.eachRelationship(callback, binding);
|
|
1160
1173
|
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* Returns the relationship schema for the given relationship name, if any.
|
|
1177
|
+
*/
|
|
1161
1178
|
relationshipFor(name) {
|
|
1162
1179
|
return this.constructor.relationshipsByName.get(name);
|
|
1163
1180
|
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* Returns the inverse relationship schema for the given relationship
|
|
1184
|
+
* name, if one exists. See {@link Model.inverseFor | the static inverseFor}.
|
|
1185
|
+
*/
|
|
1164
1186
|
inverseFor(name) {
|
|
1165
1187
|
return this.constructor.inverseFor(name, storeFor(this, false));
|
|
1166
1188
|
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Iterates over the attributes defined on this record's class, calling
|
|
1192
|
+
* `callback` for each one. See {@link Model.eachAttribute | the static eachAttribute}.
|
|
1193
|
+
*
|
|
1194
|
+
* @param callback the callback to invoke
|
|
1195
|
+
* @param binding the value to which the callback's `this` should be bound
|
|
1196
|
+
*/
|
|
1167
1197
|
eachAttribute(callback, binding) {
|
|
1168
1198
|
this.constructor.eachAttribute(callback, binding);
|
|
1169
1199
|
}
|
|
@@ -1235,6 +1265,11 @@ class Model extends EmberObject {
|
|
|
1235
1265
|
const relationship = this.relationshipsByName.get(name);
|
|
1236
1266
|
return relationship && store.modelFor(relationship.type);
|
|
1237
1267
|
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* A cache of resolved inverse relationships by name, populated lazily by
|
|
1271
|
+
* {@link Model.inverseFor | inverseFor}.
|
|
1272
|
+
*/
|
|
1238
1273
|
static get inverseMap() {
|
|
1239
1274
|
(test => {
|
|
1240
1275
|
if (!test) {
|
|
@@ -1287,6 +1322,9 @@ class Model extends EmberObject {
|
|
|
1287
1322
|
}
|
|
1288
1323
|
}
|
|
1289
1324
|
|
|
1325
|
+
/**
|
|
1326
|
+
* @private
|
|
1327
|
+
*/
|
|
1290
1328
|
//Calculate the inverse, ignoring the cache
|
|
1291
1329
|
static _findInverseFor(name, store) {
|
|
1292
1330
|
(test => {
|
|
@@ -1517,6 +1555,12 @@ class Model extends EmberObject {
|
|
|
1517
1555
|
}
|
|
1518
1556
|
return map;
|
|
1519
1557
|
}
|
|
1558
|
+
|
|
1559
|
+
/**
|
|
1560
|
+
* A hash of the model's relationship schemas keyed by relationship name.
|
|
1561
|
+
* See also {@link Model.relationshipsByName | relationshipsByName}, which
|
|
1562
|
+
* provides the same information as a `Map`.
|
|
1563
|
+
*/
|
|
1520
1564
|
static {
|
|
1521
1565
|
decorateMethodV2(this, "relationshipsByName", [computeOnce]);
|
|
1522
1566
|
}
|
|
@@ -1894,6 +1938,13 @@ defineGate(Model.prototype, 'isReloading', {
|
|
|
1894
1938
|
// @ts-expect-error specially handled prop
|
|
1895
1939
|
isLocal: true
|
|
1896
1940
|
});
|
|
1941
|
+
|
|
1942
|
+
/**
|
|
1943
|
+
* Restores the pre-`RequestManager` implementations of `save`,
|
|
1944
|
+
* `destroyRecord`, and `reload` onto the given `Model` subclass, for
|
|
1945
|
+
* apps that have not yet migrated off of the deprecated
|
|
1946
|
+
* `ENABLE_LEGACY_REQUEST_METHODS` behaviors.
|
|
1947
|
+
*/
|
|
1897
1948
|
function restoreDeprecatedModelRequestBehaviors(ModelKlass) {
|
|
1898
1949
|
// @ts-expect-error TS doesn't know how to do `this` function overloads
|
|
1899
1950
|
ModelKlass.prototype.save = _save;
|
|
@@ -2087,7 +2138,11 @@ class ModelSchemaProvider {
|
|
|
2087
2138
|
}
|
|
2088
2139
|
/** @internal */
|
|
2089
2140
|
_loadModelSchema(type) {
|
|
2090
|
-
const
|
|
2141
|
+
const factory = getModelFactory(this.store, type);
|
|
2142
|
+
if (!factory) {
|
|
2143
|
+
throw new Error(`No model was found for '${type}'`);
|
|
2144
|
+
}
|
|
2145
|
+
const modelClass = factory.class;
|
|
2091
2146
|
const attributeMap = modelClass.attributes;
|
|
2092
2147
|
const attributes = Object.create(null);
|
|
2093
2148
|
attributeMap.forEach((meta, name) => attributes[name] = meta);
|
|
@@ -2108,11 +2163,22 @@ class ModelSchemaProvider {
|
|
|
2108
2163
|
type,
|
|
2109
2164
|
fields: Array.from(fields.values())
|
|
2110
2165
|
};
|
|
2166
|
+
const cacheFields = new Map();
|
|
2167
|
+
for (const field of fields.values()) {
|
|
2168
|
+
const cacheKey = field.sourceKey ?? field.name;
|
|
2169
|
+
(test => {
|
|
2170
|
+
if (!test) {
|
|
2171
|
+
throw new Error(`The sourceKey '${field.sourceKey}' for the field '${field.name}' on '${type}' is invalid because it matches the name of an existing field`);
|
|
2172
|
+
}
|
|
2173
|
+
})(!field.sourceKey || field.sourceKey === field.name || !fields.has(field.sourceKey));
|
|
2174
|
+
cacheFields.set(cacheKey, field);
|
|
2175
|
+
}
|
|
2111
2176
|
const internalSchema = {
|
|
2112
2177
|
schema,
|
|
2113
2178
|
attributes,
|
|
2114
2179
|
relationships,
|
|
2115
|
-
fields
|
|
2180
|
+
fields,
|
|
2181
|
+
cacheFields
|
|
2116
2182
|
};
|
|
2117
2183
|
this._schemas.set(type, internalSchema);
|
|
2118
2184
|
return internalSchema;
|
|
@@ -2124,6 +2190,13 @@ class ModelSchemaProvider {
|
|
|
2124
2190
|
}
|
|
2125
2191
|
return this._schemas.get(type).fields;
|
|
2126
2192
|
}
|
|
2193
|
+
cacheFields(resource) {
|
|
2194
|
+
const type = normalizeModelName(resource.type);
|
|
2195
|
+
if (!this._schemas.has(type)) {
|
|
2196
|
+
this._loadModelSchema(type);
|
|
2197
|
+
}
|
|
2198
|
+
return this._schemas.get(type).cacheFields;
|
|
2199
|
+
}
|
|
2127
2200
|
hasResource(resource) {
|
|
2128
2201
|
const type = normalizeModelName(resource.type);
|
|
2129
2202
|
if (this._schemas.has(type)) {
|
|
@@ -2175,6 +2248,14 @@ class ModelSchemaProvider {
|
|
|
2175
2248
|
return this._schemas.get(type).relationships;
|
|
2176
2249
|
};
|
|
2177
2250
|
}
|
|
2251
|
+
|
|
2252
|
+
/**
|
|
2253
|
+
* The `createSchemaService` implementation for use with `Model`. Pass
|
|
2254
|
+
* the result of this to your store's `createSchemaService` method when
|
|
2255
|
+
* configuring the store to use `Model` for schema information.
|
|
2256
|
+
*
|
|
2257
|
+
* @public
|
|
2258
|
+
*/
|
|
2178
2259
|
function buildSchema(store) {
|
|
2179
2260
|
return new ModelSchemaProvider(store);
|
|
2180
2261
|
}
|
|
@@ -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-K2Y9z6MN.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-Cu1LNgmQ.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') {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { camelize, dasherize, singularize } from '@warp-drive/utilities/string';
|
|
2
|
-
import { J as JSONSerializer, c as coerceId } from "../json-
|
|
2
|
+
import { i as inverseForRelationship, J as JSONSerializer, c as coerceId } from "../json-K2Y9z6MN.js";
|
|
3
3
|
import Mixin from '@ember/object/mixin';
|
|
4
4
|
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
@@ -420,8 +420,7 @@ const EmbeddedRecordsMixin = Mixin.create({
|
|
|
420
420
|
*/
|
|
421
421
|
removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json) {
|
|
422
422
|
if (relationship.kind === 'belongsTo') {
|
|
423
|
-
const
|
|
424
|
-
const parentRecord = schema.inverseFor(relationship.name, this.store);
|
|
423
|
+
const parentRecord = inverseForRelationship(this.store, snapshot.modelName, relationship.name);
|
|
425
424
|
if (parentRecord) {
|
|
426
425
|
const name = parentRecord.name;
|
|
427
426
|
const embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
|
|
@@ -1024,7 +1023,7 @@ const RESTSerializer = JSONSerializer.extend({
|
|
|
1024
1023
|
`serialize` takes an options hash with a single option:
|
|
1025
1024
|
`includeId`. If this option is `true`, `serialize` will,
|
|
1026
1025
|
by default include the ID in the JSON object it builds.
|
|
1027
|
-
The
|
|
1026
|
+
The RESTAdapter passes in `includeId: true` when serializing
|
|
1028
1027
|
a record for `createRecord`, but not for `updateRecord`.
|
|
1029
1028
|
## Customization
|
|
1030
1029
|
Your server may expect a different JSON format than the
|
|
@@ -116,6 +116,10 @@ const Transform = EmberObject;
|
|
|
116
116
|
@public
|
|
117
117
|
*/
|
|
118
118
|
class BooleanTransform {
|
|
119
|
+
/**
|
|
120
|
+
* Converts a serialized (raw payload) value into a `boolean` (or `null`
|
|
121
|
+
* when `allowNull` is set and the value is nullish).
|
|
122
|
+
*/
|
|
119
123
|
deserialize(serialized, options) {
|
|
120
124
|
if ((serialized === null || serialized === undefined) && options?.allowNull === true) {
|
|
121
125
|
return null;
|
|
@@ -130,12 +134,20 @@ class BooleanTransform {
|
|
|
130
134
|
return false;
|
|
131
135
|
}
|
|
132
136
|
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Converts a `boolean` attribute value into its serialized (raw payload) form.
|
|
140
|
+
*/
|
|
133
141
|
serialize(deserialized, options) {
|
|
134
142
|
if ((deserialized === null || deserialized === undefined) && options?.allowNull === true) {
|
|
135
143
|
return null;
|
|
136
144
|
}
|
|
137
145
|
return Boolean(deserialized);
|
|
138
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates a new instance of this transform.
|
|
150
|
+
*/
|
|
139
151
|
static create() {
|
|
140
152
|
return new this();
|
|
141
153
|
}
|
|
@@ -151,7 +163,7 @@ class BooleanTransform {
|
|
|
151
163
|
standard.
|
|
152
164
|
|
|
153
165
|
```js [app/models/score.js]
|
|
154
|
-
import Model, { attr, belongsTo } from '@
|
|
166
|
+
import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
|
|
155
167
|
|
|
156
168
|
export default class ScoreModel extends Model {
|
|
157
169
|
@attr('number') value;
|
|
@@ -164,6 +176,10 @@ class BooleanTransform {
|
|
|
164
176
|
*/
|
|
165
177
|
|
|
166
178
|
class DateTransform {
|
|
179
|
+
/**
|
|
180
|
+
* Converts a serialized (raw payload) `ISO 8601` string, epoch number,
|
|
181
|
+
* or nullish value into a `Date` (or `null`/`undefined`).
|
|
182
|
+
*/
|
|
167
183
|
deserialize(serialized, _options) {
|
|
168
184
|
if (typeof serialized === 'string') {
|
|
169
185
|
let offset = serialized.indexOf('+');
|
|
@@ -182,6 +198,11 @@ class DateTransform {
|
|
|
182
198
|
return null;
|
|
183
199
|
}
|
|
184
200
|
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Converts a `Date` attribute value into an `ISO 8601` string, or `null`
|
|
204
|
+
* if the value is not a valid `Date`.
|
|
205
|
+
*/
|
|
185
206
|
serialize(date, _options) {
|
|
186
207
|
// @ts-expect-error isNaN accepts date as it is coercible
|
|
187
208
|
if (date instanceof Date && !isNaN(date)) {
|
|
@@ -190,6 +211,10 @@ class DateTransform {
|
|
|
190
211
|
return null;
|
|
191
212
|
}
|
|
192
213
|
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Creates a new instance of this transform.
|
|
217
|
+
*/
|
|
193
218
|
static create() {
|
|
194
219
|
return new this();
|
|
195
220
|
}
|
|
@@ -209,7 +234,7 @@ function isNumber(value) {
|
|
|
209
234
|
Usage
|
|
210
235
|
|
|
211
236
|
```js [app/models/score.js]
|
|
212
|
-
import Model, { attr, belongsTo } from '@
|
|
237
|
+
import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
|
|
213
238
|
|
|
214
239
|
export default class ScoreModel extends Model {
|
|
215
240
|
@attr('number') value;
|
|
@@ -221,6 +246,10 @@ function isNumber(value) {
|
|
|
221
246
|
@public
|
|
222
247
|
*/
|
|
223
248
|
class NumberTransform {
|
|
249
|
+
/**
|
|
250
|
+
* Converts a serialized (raw payload) value into a `number`, or `null`
|
|
251
|
+
* if the value is empty, nullish, or not a valid number.
|
|
252
|
+
*/
|
|
224
253
|
deserialize(serialized, _options) {
|
|
225
254
|
if (serialized === '' || serialized === null || serialized === undefined) {
|
|
226
255
|
return null;
|
|
@@ -229,6 +258,10 @@ class NumberTransform {
|
|
|
229
258
|
return isNumber(transformed) ? transformed : null;
|
|
230
259
|
}
|
|
231
260
|
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Converts a `number` attribute value into its serialized (raw payload) form.
|
|
264
|
+
*/
|
|
232
265
|
serialize(deserialized, _options) {
|
|
233
266
|
if (deserialized === '' || deserialized === null || deserialized === undefined) {
|
|
234
267
|
return null;
|
|
@@ -237,6 +270,10 @@ class NumberTransform {
|
|
|
237
270
|
return isNumber(transformed) ? transformed : null;
|
|
238
271
|
}
|
|
239
272
|
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Creates a new instance of this transform.
|
|
276
|
+
*/
|
|
240
277
|
static create() {
|
|
241
278
|
return new this();
|
|
242
279
|
}
|
|
@@ -253,7 +290,7 @@ class NumberTransform {
|
|
|
253
290
|
Usage
|
|
254
291
|
|
|
255
292
|
```js [app/models/user.js]
|
|
256
|
-
import Model, { attr, belongsTo } from '@
|
|
293
|
+
import Model, { attr, belongsTo } from '@warp-drive/legacy/model';
|
|
257
294
|
|
|
258
295
|
export default class UserModel extends Model {
|
|
259
296
|
@attr('boolean') isAdmin;
|
|
@@ -265,12 +302,23 @@ class NumberTransform {
|
|
|
265
302
|
@public
|
|
266
303
|
*/
|
|
267
304
|
class StringTransform {
|
|
305
|
+
/**
|
|
306
|
+
* Converts a serialized (raw payload) value into a `string`, or `null`
|
|
307
|
+
* if the value is falsy (and not an empty string).
|
|
308
|
+
*/
|
|
268
309
|
deserialize(serialized, _options) {
|
|
269
310
|
return !serialized && serialized !== '' ? null : String(serialized);
|
|
270
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Converts a `string` attribute value into its serialized (raw payload) form.
|
|
314
|
+
*/
|
|
271
315
|
serialize(deserialized, _options) {
|
|
272
316
|
return !deserialized && deserialized !== '' ? null : String(deserialized);
|
|
273
317
|
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Creates a new instance of this transform.
|
|
321
|
+
*/
|
|
274
322
|
static create() {
|
|
275
323
|
return new this();
|
|
276
324
|
}
|
|
@@ -149,11 +149,8 @@ class Serializer extends EmberObject {
|
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
151
|
```
|
|
152
|
-
@
|
|
153
|
-
@type {Store}
|
|
154
|
-
@public
|
|
152
|
+
@public
|
|
155
153
|
*/
|
|
156
|
-
|
|
157
154
|
/**
|
|
158
155
|
The `normalizeResponse` method is used to normalize a payload from the
|
|
159
156
|
server to a JSON-API Document.
|
|
@@ -237,9 +234,9 @@ class Serializer extends EmberObject {
|
|
|
237
234
|
})
|
|
238
235
|
```
|
|
239
236
|
@public
|
|
240
|
-
@param
|
|
241
|
-
@param
|
|
242
|
-
@return
|
|
237
|
+
@param _typeClass - the model class the hash is being normalized for
|
|
238
|
+
@param hash - the raw payload hash to normalize
|
|
239
|
+
@return the normalized resource document
|
|
243
240
|
*/
|
|
244
241
|
normalize(_typeClass, hash) {
|
|
245
242
|
return hash;
|
|
@@ -108,12 +108,11 @@ function resourceIsFullyDeleted(instanceCache, identifier) {
|
|
|
108
108
|
class RecordReference {
|
|
109
109
|
/** @internal */
|
|
110
110
|
|
|
111
|
-
/** @internal */
|
|
112
111
|
// unsubscribe token given to us by the notification manager
|
|
112
|
+
/** @internal */
|
|
113
113
|
___token;
|
|
114
114
|
/** @internal */
|
|
115
115
|
___identifier;
|
|
116
|
-
|
|
117
116
|
/** @internal */
|
|
118
117
|
|
|
119
118
|
constructor(store, identifier) {
|
|
@@ -144,7 +143,7 @@ class RecordReference {
|
|
|
144
143
|
userRef.id(); // '1'
|
|
145
144
|
```
|
|
146
145
|
@public
|
|
147
|
-
|
|
146
|
+
@return The id of the record.
|
|
148
147
|
*/
|
|
149
148
|
id() {
|
|
150
149
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
@@ -162,7 +161,7 @@ class RecordReference {
|
|
|
162
161
|
userRef.identifier(); // '1'
|
|
163
162
|
```
|
|
164
163
|
@public
|
|
165
|
-
|
|
164
|
+
@return The identifier of the record.
|
|
166
165
|
*/
|
|
167
166
|
identifier() {
|
|
168
167
|
return this.___identifier;
|
|
@@ -188,7 +187,7 @@ class RecordReference {
|
|
|
188
187
|
simplest usage of this API is similar to `store.push`: you provide a
|
|
189
188
|
normalized hash of data and the object represented by the reference
|
|
190
189
|
will update.
|
|
191
|
-
If you pass a promise to `push`,
|
|
190
|
+
If you pass a promise to `push`, WarpDrive will not ask the adapter
|
|
192
191
|
for the data if another attempt to fetch it is made in the
|
|
193
192
|
interim. When the promise resolves, the underlying object is updated
|
|
194
193
|
with the new data, and the promise returned by *this function* is resolved
|
|
@@ -232,7 +231,7 @@ class RecordReference {
|
|
|
232
231
|
userRef.value(); // user
|
|
233
232
|
```
|
|
234
233
|
@public
|
|
235
|
-
|
|
234
|
+
@return the record for this RecordReference
|
|
236
235
|
*/
|
|
237
236
|
value() {
|
|
238
237
|
return this.store.peekRecord(this.___identifier);
|
|
@@ -377,6 +376,14 @@ class ShimModelClass {
|
|
|
377
376
|
});
|
|
378
377
|
}
|
|
379
378
|
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Restores the deprecated `findRecord`/`findAll`/`query`/`queryRecord`/
|
|
382
|
+
* `findBelongsTo`/`findHasMany`/`createRecord`/`deleteRecord`/`saveRecord`
|
|
383
|
+
* legacy-network-layer implementations of these methods onto the given
|
|
384
|
+
* `Store` subclass, for apps that have not yet migrated to the
|
|
385
|
+
* `RequestManager`-based equivalents.
|
|
386
|
+
*/
|
|
380
387
|
function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
381
388
|
StoreKlass.prototype.findRecord = function (resource, id, options) {
|
|
382
389
|
(test => {
|
|
@@ -527,7 +534,14 @@ function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
|
527
534
|
};
|
|
528
535
|
|
|
529
536
|
// do not put a ts-expect-error here, because typedoc will fail to
|
|
530
|
-
// build due to this error only occurring when references are in use in the editor
|
|
537
|
+
// build due to this error only occurring when references are in use in the editor.
|
|
538
|
+
// The return statement below casts to `PrivateStore['getReference']`'s return
|
|
539
|
+
// type rather than annotating this function `: RecordReference` directly,
|
|
540
|
+
// since this package's `RecordReference` and core's `deprecated/-private.ts`
|
|
541
|
+
// copy are structurally identical but nominally distinct classes (TS treats
|
|
542
|
+
// their private fields as separate brands); casting only the return value
|
|
543
|
+
// (instead of the whole function) keeps `this` contextually typed from the
|
|
544
|
+
// assignment target below.
|
|
531
545
|
StoreKlass.prototype.getReference = function (resource, id) {
|
|
532
546
|
(test => {
|
|
533
547
|
if (!test) {
|