@warp-drive/core 5.7.0-alpha.3 → 5.7.0-alpha.31
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/declarations/graph/-private/-diff.d.ts +7 -20
- package/declarations/graph/-private/-edge-definition.d.ts +3 -12
- package/declarations/graph/-private/-state.d.ts +2 -2
- package/declarations/graph/-private/-utils.d.ts +5 -5
- package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +3 -3
- package/declarations/graph/-private/edges/collection.d.ts +10 -10
- package/declarations/graph/-private/edges/implicit.d.ts +5 -5
- package/declarations/graph/-private/edges/resource.d.ts +6 -7
- package/declarations/graph/-private/graph.d.ts +17 -15
- package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -4
- package/declarations/graph/-private/operations/update-relationship.d.ts +3 -3
- package/declarations/index.d.ts +1 -1
- package/declarations/reactive/-private/default-mode.d.ts +73 -0
- package/declarations/reactive/-private/document.d.ts +11 -21
- package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
- package/declarations/reactive/-private/fields/managed-array.d.ts +7 -10
- package/declarations/reactive/-private/fields/managed-object.d.ts +7 -9
- package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
- package/declarations/reactive/-private/hooks.d.ts +2 -2
- package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
- package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
- package/declarations/reactive/-private/record.d.ts +44 -33
- package/declarations/reactive/-private/schema.d.ts +16 -72
- package/declarations/reactive/-private/symbols.d.ts +2 -7
- package/declarations/reactive/-private.d.ts +1 -1
- package/declarations/reactive.d.ts +278 -1
- package/declarations/request/-private/context.d.ts +3 -3
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +24 -28
- package/declarations/request/-private/types.d.ts +22 -23
- package/declarations/request/-private/utils.d.ts +44 -2
- package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
- package/declarations/store/-private/cache-handler/types.d.ts +10 -10
- package/declarations/store/-private/cache-handler/utils.d.ts +4 -4
- package/declarations/store/-private/caches/instance-cache.d.ts +21 -19
- package/declarations/store/-private/debug/utils.d.ts +1 -0
- package/declarations/store/-private/default-cache-policy.d.ts +25 -38
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +38 -52
- package/declarations/store/-private/managers/cache-manager.d.ts +47 -95
- package/declarations/store/-private/managers/notification-manager.d.ts +30 -42
- package/declarations/store/-private/managers/record-array-manager.d.ts +45 -41
- package/declarations/store/-private/network/request-cache.d.ts +21 -21
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
- package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +129 -22
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -123
- package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
- package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
- package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
- package/declarations/store/-private/record-arrays/resource-array.d.ts +75 -0
- package/declarations/store/-private/store-service.d.ts +156 -101
- package/declarations/store/-private.d.ts +12 -9
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
- package/declarations/store/-types/q/identifier.d.ts +9 -6
- package/declarations/store/-types/q/record-instance.d.ts +0 -1
- package/declarations/store/-types/q/schema-service.d.ts +28 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +12 -23
- package/declarations/store/deprecated/store.d.ts +11 -12
- package/declarations/types/-private.d.ts +1 -1
- package/declarations/types/cache/aliases.d.ts +2 -2
- package/declarations/types/cache/change.d.ts +2 -2
- package/declarations/types/cache/mutations.d.ts +13 -13
- package/declarations/types/cache/operations.d.ts +115 -32
- package/declarations/types/cache/relationship.d.ts +4 -4
- package/declarations/types/cache.d.ts +51 -113
- package/declarations/types/graph.d.ts +12 -12
- package/declarations/types/identifier.d.ts +52 -76
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +69 -42
- package/declarations/types/schema/concepts.d.ts +2 -2
- package/declarations/types/schema/fields.d.ts +378 -14
- package/declarations/types/spec/document.d.ts +6 -6
- package/declarations/types/spec/json-api-raw.d.ts +6 -8
- package/declarations/utils/string.d.ts +2 -2
- package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
- package/dist/configure.js +1 -1
- package/dist/{context-COmAnXUQ.js → context-Bh-MA_tH.js} +40 -6
- package/dist/graph/-private.js +137 -144
- package/dist/index.js +25 -14
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +203 -1413
- package/dist/{request-state-CejVJgdj.js → request-state-DGyt5EV8.js} +5674 -2812
- package/dist/request.js +1 -1
- package/dist/store/-private.js +2 -3
- package/dist/store.js +32 -44
- package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
- package/dist/types/-private.js +1 -1
- package/dist/types/identifier.js +19 -45
- package/dist/types/request.js +45 -3
- package/dist/types/schema/fields.js +23 -2
- package/dist/utils/string.js +2 -2
- package/package.json +10 -10
- package/declarations/reactive/-private/fields/compute.d.ts +0 -43
- package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
- package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
- package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
- package/dist/handler-D2jjnIA-.js +0 -339
package/dist/graph/-private.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { deprecate, warn } from '@ember/debug';
|
|
2
|
-
import { p as peekCache } from "../request-state-CejVJgdj.js";
|
|
3
|
-
import '../types/request.js';
|
|
4
2
|
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
5
|
-
import '../utils/string.js';
|
|
6
|
-
import "../configure-B48bFHOl.js";
|
|
7
3
|
import { getOrSetGlobal, peekTransient, setTransient } from '../types/-private.js';
|
|
8
4
|
function coerceId(id) {
|
|
9
5
|
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_ID)) {
|
|
@@ -121,12 +117,11 @@ function inspect(value) {
|
|
|
121
117
|
}
|
|
122
118
|
return 'object';
|
|
123
119
|
}
|
|
124
|
-
function
|
|
125
|
-
if (!
|
|
120
|
+
function checkIfNew(store, resourceKey) {
|
|
121
|
+
if (!resourceKey.id) {
|
|
126
122
|
return true;
|
|
127
123
|
}
|
|
128
|
-
|
|
129
|
-
return Boolean(cache?.isNew(identifier));
|
|
124
|
+
return store.cache.isNew(resourceKey);
|
|
130
125
|
}
|
|
131
126
|
function isBelongsTo(relationship) {
|
|
132
127
|
return relationship.definition.kind === 'belongsTo';
|
|
@@ -213,13 +208,13 @@ function notifyChange(graph, relationship) {
|
|
|
213
208
|
if (!relationship.accessed) {
|
|
214
209
|
return;
|
|
215
210
|
}
|
|
216
|
-
const
|
|
211
|
+
const resourceKey = relationship.identifier;
|
|
217
212
|
const key = relationship.definition.key;
|
|
218
|
-
if (
|
|
213
|
+
if (resourceKey === graph._removing) {
|
|
219
214
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
220
215
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
221
216
|
// eslint-disable-next-line no-console
|
|
222
|
-
console.log(`Graph: ignoring relationship change for removed identifier ${String(
|
|
217
|
+
console.log(`Graph: ignoring relationship change for removed identifier ${String(resourceKey)} ${key}`);
|
|
223
218
|
}
|
|
224
219
|
}
|
|
225
220
|
return;
|
|
@@ -227,37 +222,37 @@ function notifyChange(graph, relationship) {
|
|
|
227
222
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
228
223
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
229
224
|
// eslint-disable-next-line no-console
|
|
230
|
-
console.log(`Graph: notifying relationship change for ${String(
|
|
225
|
+
console.log(`Graph: notifying relationship change for ${String(resourceKey)} ${key}`);
|
|
231
226
|
}
|
|
232
227
|
}
|
|
233
|
-
graph.store.notifyChange(
|
|
228
|
+
graph.store.notifyChange(resourceKey, 'relationships', key);
|
|
234
229
|
}
|
|
235
|
-
function assertRelationshipData(store,
|
|
230
|
+
function assertRelationshipData(store, resourceKey, data, meta) {
|
|
236
231
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
237
232
|
if (!test) {
|
|
238
|
-
throw new Error(`A ${
|
|
233
|
+
throw new Error(`A ${resourceKey.type} record was pushed into the store with the value of ${meta.key} being '${JSON.stringify(data)}', but ${meta.key} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`);
|
|
239
234
|
}
|
|
240
235
|
})(!Array.isArray(data)) : {};
|
|
241
236
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
242
237
|
if (!test) {
|
|
243
|
-
throw new Error(`Encountered a relationship identifier without a type for the ${meta.kind} relationship '${meta.key}' on <${
|
|
238
|
+
throw new Error(`Encountered a relationship identifier without a type for the ${meta.kind} relationship '${meta.key}' on <${resourceKey.type}:${String(resourceKey.id)}>, expected an identifier with type '${meta.type}' but found\n\n'${JSON.stringify(data, null, 2)}'\n\nPlease check your serializer and make sure it is serializing the relationship payload into a JSON API format.`);
|
|
244
239
|
}
|
|
245
240
|
})(data === null || 'type' in data && typeof data.type === 'string' && data.type.length) : {};
|
|
246
241
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
247
242
|
if (!test) {
|
|
248
|
-
throw new Error(`Encountered a relationship identifier without an id for the ${meta.kind} relationship '${meta.key}' on <${
|
|
243
|
+
throw new Error(`Encountered a relationship identifier without an id for the ${meta.kind} relationship '${meta.key}' on <${resourceKey.type}:${String(resourceKey.id)}>, expected an identifier but found\n\n'${JSON.stringify(data, null, 2)}'\n\nPlease check your serializer and make sure it is serializing the relationship payload into a JSON API format.`);
|
|
249
244
|
}
|
|
250
245
|
})(data === null || !!coerceId(data.id)) : {};
|
|
251
246
|
if (data?.type === meta.type) {
|
|
252
247
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
253
248
|
if (!test) {
|
|
254
|
-
throw new Error(`Missing Schema: Encountered a relationship identifier { type: '${data.type}', id: '${String(data.id)}' } for the '${
|
|
249
|
+
throw new Error(`Missing Schema: Encountered a relationship identifier { type: '${data.type}', id: '${String(data.id)}' } for the '${resourceKey.type}.${meta.key}' ${meta.kind} relationship on <${resourceKey.type}:${String(resourceKey.id)}>, but no schema exists for that type.`);
|
|
255
250
|
}
|
|
256
251
|
})(store.schema.hasResource(data)) : {};
|
|
257
252
|
} else {
|
|
258
253
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
259
254
|
if (!test) {
|
|
260
|
-
throw new Error(`Missing Schema: Encountered a relationship identifier with type '${data.type}' for the ${meta.kind} relationship '${meta.key}' on <${
|
|
255
|
+
throw new Error(`Missing Schema: Encountered a relationship identifier with type '${data.type}' for the ${meta.kind} relationship '${meta.key}' on <${resourceKey.type}:${String(resourceKey.id)}>, Expected an identifier with type '${meta.type}'. No schema was found for '${data.type}'.`);
|
|
261
256
|
}
|
|
262
257
|
})(data === null || !data.type || store.schema.hasResource(data)) : {};
|
|
263
258
|
}
|
|
@@ -342,9 +337,7 @@ function temporaryConvertToLegacy(field) {
|
|
|
342
337
|
* }
|
|
343
338
|
* ```
|
|
344
339
|
*
|
|
345
|
-
*
|
|
346
|
-
* @class UpgradedMeta
|
|
347
|
-
* @internal
|
|
340
|
+
* @private
|
|
348
341
|
*/
|
|
349
342
|
|
|
350
343
|
const BOOL_LATER = null;
|
|
@@ -490,13 +483,13 @@ function isLHS(info, type, key) {
|
|
|
490
483
|
}
|
|
491
484
|
return false;
|
|
492
485
|
}
|
|
493
|
-
function upgradeDefinition(graph,
|
|
486
|
+
function upgradeDefinition(graph, key, propertyName, isImplicit = false) {
|
|
494
487
|
const cache = graph._definitionCache;
|
|
495
488
|
const storeWrapper = graph.store;
|
|
496
489
|
const polymorphicLookup = graph._potentialPolymorphicTypes;
|
|
497
490
|
const {
|
|
498
491
|
type
|
|
499
|
-
} =
|
|
492
|
+
} = key;
|
|
500
493
|
let cached = /*#__NOINLINE__*/expandingGet(cache, type, propertyName);
|
|
501
494
|
|
|
502
495
|
// CASE: We have a cached resolution (null if no relationship exists)
|
|
@@ -508,7 +501,7 @@ function upgradeDefinition(graph, identifier, propertyName, isImplicit = false)
|
|
|
508
501
|
throw new Error(`Expected to find relationship definition in the cache for the implicit relationship ${propertyName}`);
|
|
509
502
|
}
|
|
510
503
|
})(!isImplicit) : {};
|
|
511
|
-
const relationships = storeWrapper.schema.fields(
|
|
504
|
+
const relationships = storeWrapper.schema.fields(key);
|
|
512
505
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
513
506
|
if (!test) {
|
|
514
507
|
throw new Error(`Expected to have a relationship definition for ${type} but none was found.`);
|
|
@@ -560,7 +553,7 @@ function upgradeDefinition(graph, identifier, propertyName, isImplicit = false)
|
|
|
560
553
|
})(getStore(storeWrapper).modelFor(inverseType)) : {};
|
|
561
554
|
inverseDefinition = null;
|
|
562
555
|
} else {
|
|
563
|
-
inverseKey = /*#__NOINLINE__*/inverseForRelationship(getStore(storeWrapper),
|
|
556
|
+
inverseKey = /*#__NOINLINE__*/inverseForRelationship(getStore(storeWrapper), key, propertyName);
|
|
564
557
|
|
|
565
558
|
// CASE: If we are polymorphic, and we declared an inverse that is non-null
|
|
566
559
|
// we must assume that the lack of inverseKey means that there is no
|
|
@@ -716,8 +709,8 @@ function upgradeDefinition(graph, identifier, propertyName, isImplicit = false)
|
|
|
716
709
|
expandingSet(cache, inverseType, inverseKey, info);
|
|
717
710
|
return info;
|
|
718
711
|
}
|
|
719
|
-
function inverseForRelationship(store,
|
|
720
|
-
const definition = store.schema.fields(
|
|
712
|
+
function inverseForRelationship(store, resourceKey, key) {
|
|
713
|
+
const definition = store.schema.fields(resourceKey).get(key);
|
|
721
714
|
if (!definition) {
|
|
722
715
|
return null;
|
|
723
716
|
}
|
|
@@ -996,7 +989,7 @@ function replaceRelatedRecords(graph, op, isRemote) {
|
|
|
996
989
|
}
|
|
997
990
|
}
|
|
998
991
|
function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
999
|
-
const
|
|
992
|
+
const resourceKeys = op.value;
|
|
1000
993
|
const relationship = graph.get(op.record, op.field);
|
|
1001
994
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1002
995
|
if (!test) {
|
|
@@ -1022,48 +1015,48 @@ function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
|
1022
1015
|
count(`replaceRelatedRecordsLocal ${'type' in record ? record.type : '<document>'} ${op.field}`);
|
|
1023
1016
|
}
|
|
1024
1017
|
}
|
|
1025
|
-
const onAdd =
|
|
1018
|
+
const onAdd = resourceKey => {
|
|
1026
1019
|
// Since we are diffing against the remote state, we check
|
|
1027
|
-
// if our previous local state did not contain this
|
|
1028
|
-
const removalsHas = removals?.has(
|
|
1029
|
-
if (removalsHas || !additions?.has(
|
|
1030
|
-
if (type !==
|
|
1020
|
+
// if our previous local state did not contain this ResourceKey
|
|
1021
|
+
const removalsHas = removals?.has(resourceKey);
|
|
1022
|
+
if (removalsHas || !additions?.has(resourceKey)) {
|
|
1023
|
+
if (type !== resourceKey.type) {
|
|
1031
1024
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
1032
|
-
assertPolymorphicType(relationship.identifier, relationship.definition,
|
|
1025
|
+
assertPolymorphicType(relationship.identifier, relationship.definition, resourceKey, graph.store);
|
|
1033
1026
|
}
|
|
1034
|
-
graph.registerPolymorphicType(type,
|
|
1027
|
+
graph.registerPolymorphicType(type, resourceKey.type);
|
|
1035
1028
|
}
|
|
1036
1029
|
|
|
1037
1030
|
// we've added a record locally that wasn't in the local state before
|
|
1038
1031
|
localBecameDirty = true;
|
|
1039
|
-
addToInverse(graph,
|
|
1032
|
+
addToInverse(graph, resourceKey, inverseKey, op.record, isRemote);
|
|
1040
1033
|
if (removalsHas) {
|
|
1041
|
-
removals.delete(
|
|
1034
|
+
removals.delete(resourceKey);
|
|
1042
1035
|
}
|
|
1043
1036
|
}
|
|
1044
1037
|
};
|
|
1045
|
-
const onRemove =
|
|
1038
|
+
const onRemove = resourceKey => {
|
|
1046
1039
|
// Since we are diffing against the remote state, we check
|
|
1047
|
-
// if our previous local state had contained this
|
|
1048
|
-
const additionsHas = additions?.has(
|
|
1049
|
-
if (additionsHas || !removals?.has(
|
|
1040
|
+
// if our previous local state had contained this ResourceKey
|
|
1041
|
+
const additionsHas = additions?.has(resourceKey);
|
|
1042
|
+
if (additionsHas || !removals?.has(resourceKey)) {
|
|
1050
1043
|
// we've removed a record locally that was in the local state before
|
|
1051
1044
|
localBecameDirty = true;
|
|
1052
|
-
removeFromInverse(graph,
|
|
1045
|
+
removeFromInverse(graph, resourceKey, inverseKey, record, isRemote);
|
|
1053
1046
|
if (additionsHas) {
|
|
1054
|
-
additions.delete(
|
|
1047
|
+
additions.delete(resourceKey);
|
|
1055
1048
|
}
|
|
1056
1049
|
}
|
|
1057
1050
|
};
|
|
1058
|
-
const diff = diffCollection(
|
|
1051
|
+
const diff = diffCollection(resourceKeys, relationship, onAdd, onRemove);
|
|
1059
1052
|
|
|
1060
1053
|
// any additions no longer in the local state
|
|
1061
1054
|
// also need to be removed from the inverse
|
|
1062
1055
|
if (additions && additions.size > 0) {
|
|
1063
|
-
additions.forEach(
|
|
1064
|
-
if (!diff.add.has(
|
|
1056
|
+
additions.forEach(resourceKey => {
|
|
1057
|
+
if (!diff.add.has(resourceKey)) {
|
|
1065
1058
|
localBecameDirty = true;
|
|
1066
|
-
onRemove(
|
|
1059
|
+
onRemove(resourceKey);
|
|
1067
1060
|
}
|
|
1068
1061
|
});
|
|
1069
1062
|
}
|
|
@@ -1071,10 +1064,10 @@ function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
|
1071
1064
|
// any removals no longer in the local state
|
|
1072
1065
|
// also need to be added back to the inverse
|
|
1073
1066
|
if (removals && removals.size > 0) {
|
|
1074
|
-
removals.forEach(
|
|
1075
|
-
if (!diff.del.has(
|
|
1067
|
+
removals.forEach(resourceKey => {
|
|
1068
|
+
if (!diff.del.has(resourceKey)) {
|
|
1076
1069
|
localBecameDirty = true;
|
|
1077
|
-
onAdd(
|
|
1070
|
+
onAdd(resourceKey);
|
|
1078
1071
|
}
|
|
1079
1072
|
});
|
|
1080
1073
|
}
|
|
@@ -1090,7 +1083,7 @@ function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
|
1090
1083
|
}
|
|
1091
1084
|
}
|
|
1092
1085
|
function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
1093
|
-
const
|
|
1086
|
+
const resourceKeys = op.value;
|
|
1094
1087
|
const relationship = graph.get(op.record, op.field);
|
|
1095
1088
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_METRIC_COUNTS)) {
|
|
1096
1089
|
if (getGlobalConfig().WarpDrive.debug.LOG_METRIC_COUNTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_METRIC_COUNTS) {
|
|
@@ -1122,18 +1115,18 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1122
1115
|
const {
|
|
1123
1116
|
type
|
|
1124
1117
|
} = relationship.definition;
|
|
1125
|
-
const diff = diffCollection(
|
|
1126
|
-
if (type !==
|
|
1118
|
+
const diff = diffCollection(resourceKeys, relationship, resourceKey => {
|
|
1119
|
+
if (type !== resourceKey.type) {
|
|
1127
1120
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
1128
|
-
assertPolymorphicType(relationship.identifier, relationship.definition,
|
|
1121
|
+
assertPolymorphicType(relationship.identifier, relationship.definition, resourceKey, graph.store);
|
|
1129
1122
|
}
|
|
1130
|
-
graph.registerPolymorphicType(type,
|
|
1123
|
+
graph.registerPolymorphicType(type, resourceKey.type);
|
|
1131
1124
|
}
|
|
1132
1125
|
// commit additions
|
|
1133
1126
|
// TODO build this into the diff?
|
|
1134
1127
|
// because we are not dirty if this was a committed local addition
|
|
1135
|
-
if (relationship.additions?.has(
|
|
1136
|
-
relationship.additions.delete(
|
|
1128
|
+
if (relationship.additions?.has(resourceKey)) {
|
|
1129
|
+
relationship.additions.delete(resourceKey);
|
|
1137
1130
|
} else {
|
|
1138
1131
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.DEBUG_RELATIONSHIP_NOTIFICATIONS)) {
|
|
1139
1132
|
if (getGlobalConfig().WarpDrive.debug.DEBUG_RELATIONSHIP_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.DEBUG_RELATIONSHIP_NOTIFICATIONS) {
|
|
@@ -1144,13 +1137,13 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1144
1137
|
}
|
|
1145
1138
|
}
|
|
1146
1139
|
}
|
|
1147
|
-
addToInverse(graph,
|
|
1148
|
-
},
|
|
1140
|
+
addToInverse(graph, resourceKey, definition.inverseKey, op.record, isRemote);
|
|
1141
|
+
}, resourceKey => {
|
|
1149
1142
|
// commit removals
|
|
1150
1143
|
// TODO build this into the diff?
|
|
1151
1144
|
// because we are not dirty if this was a committed local addition
|
|
1152
|
-
if (relationship.removals?.has(
|
|
1153
|
-
relationship.removals.delete(
|
|
1145
|
+
if (relationship.removals?.has(resourceKey)) {
|
|
1146
|
+
relationship.removals.delete(resourceKey);
|
|
1154
1147
|
} else {
|
|
1155
1148
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.DEBUG_RELATIONSHIP_NOTIFICATIONS)) {
|
|
1156
1149
|
if (getGlobalConfig().WarpDrive.debug.DEBUG_RELATIONSHIP_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.DEBUG_RELATIONSHIP_NOTIFICATIONS) {
|
|
@@ -1161,7 +1154,7 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1161
1154
|
}
|
|
1162
1155
|
}
|
|
1163
1156
|
}
|
|
1164
|
-
removeFromInverse(graph,
|
|
1157
|
+
removeFromInverse(graph, resourceKey, definition.inverseKey, op.record, isRemote);
|
|
1165
1158
|
});
|
|
1166
1159
|
|
|
1167
1160
|
// replace existing state
|
|
@@ -1192,30 +1185,30 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1192
1185
|
};
|
|
1193
1186
|
if (relationship.removals) {
|
|
1194
1187
|
relationship.isDirty = true;
|
|
1195
|
-
relationship.removals.forEach(
|
|
1188
|
+
relationship.removals.forEach(resourceKey => {
|
|
1196
1189
|
deprecationInfo.triggered = true;
|
|
1197
|
-
deprecationInfo.removals.push(
|
|
1190
|
+
deprecationInfo.removals.push(resourceKey);
|
|
1198
1191
|
// reverse the removal
|
|
1199
1192
|
// if we are still in removals at this point then
|
|
1200
1193
|
// we were not "committed" which means we are present
|
|
1201
1194
|
// in the remoteMembers. So we "add back" on the inverse.
|
|
1202
|
-
addToInverse(graph,
|
|
1195
|
+
addToInverse(graph, resourceKey, definition.inverseKey, op.record, false);
|
|
1203
1196
|
});
|
|
1204
1197
|
relationship.removals = null;
|
|
1205
1198
|
}
|
|
1206
1199
|
if (relationship.additions) {
|
|
1207
|
-
relationship.additions.forEach(
|
|
1200
|
+
relationship.additions.forEach(resourceKey => {
|
|
1208
1201
|
// reverse the addition
|
|
1209
1202
|
// if we are still in additions at this point then
|
|
1210
1203
|
// we were not "committed" which means we are not present
|
|
1211
1204
|
// in the remoteMembers. So we "remove" from the inverse.
|
|
1212
1205
|
// however we only do this if we are not a "new" record.
|
|
1213
|
-
if (!
|
|
1206
|
+
if (!checkIfNew(graph._realStore, resourceKey)) {
|
|
1214
1207
|
deprecationInfo.triggered = true;
|
|
1215
|
-
deprecationInfo.additions.push(
|
|
1208
|
+
deprecationInfo.additions.push(resourceKey);
|
|
1216
1209
|
relationship.isDirty = true;
|
|
1217
|
-
relationship.additions.delete(
|
|
1218
|
-
removeFromInverse(graph,
|
|
1210
|
+
relationship.additions.delete(resourceKey);
|
|
1211
|
+
removeFromInverse(graph, resourceKey, definition.inverseKey, op.record, false);
|
|
1219
1212
|
}
|
|
1220
1213
|
});
|
|
1221
1214
|
if (relationship.additions.size === 0) {
|
|
@@ -1240,8 +1233,8 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1240
1233
|
flushCanonical(graph, relationship);
|
|
1241
1234
|
}
|
|
1242
1235
|
}
|
|
1243
|
-
function addToInverse(graph,
|
|
1244
|
-
const relationship = graph.get(
|
|
1236
|
+
function addToInverse(graph, resourceKey, key, value, isRemote) {
|
|
1237
|
+
const relationship = graph.get(resourceKey, key);
|
|
1245
1238
|
const {
|
|
1246
1239
|
type
|
|
1247
1240
|
} = relationship.definition;
|
|
@@ -1257,13 +1250,13 @@ function addToInverse(graph, identifier, key, value, isRemote) {
|
|
|
1257
1250
|
if (isRemote) {
|
|
1258
1251
|
graph._addToTransaction(relationship);
|
|
1259
1252
|
if (relationship.remoteState !== null) {
|
|
1260
|
-
removeFromInverse(graph, relationship.remoteState, relationship.definition.inverseKey,
|
|
1253
|
+
removeFromInverse(graph, relationship.remoteState, relationship.definition.inverseKey, resourceKey, isRemote);
|
|
1261
1254
|
}
|
|
1262
1255
|
relationship.remoteState = value;
|
|
1263
1256
|
}
|
|
1264
1257
|
if (relationship.localState !== value) {
|
|
1265
1258
|
if (!isRemote && relationship.localState) {
|
|
1266
|
-
removeFromInverse(graph, relationship.localState, relationship.definition.inverseKey,
|
|
1259
|
+
removeFromInverse(graph, relationship.localState, relationship.definition.inverseKey, resourceKey, isRemote);
|
|
1267
1260
|
}
|
|
1268
1261
|
relationship.localState = value;
|
|
1269
1262
|
notifyChange(graph, relationship);
|
|
@@ -1294,7 +1287,7 @@ function addToInverse(graph, identifier, key, value, isRemote) {
|
|
|
1294
1287
|
if (!relationship.isDirty && !relationship.localState) {
|
|
1295
1288
|
relationship.localState = [];
|
|
1296
1289
|
}
|
|
1297
|
-
if (_add(graph,
|
|
1290
|
+
if (_add(graph, resourceKey, relationship, value, null, isRemote)) {
|
|
1298
1291
|
notifyChange(graph, relationship);
|
|
1299
1292
|
}
|
|
1300
1293
|
}
|
|
@@ -1311,14 +1304,14 @@ function addToInverse(graph, identifier, key, value, isRemote) {
|
|
|
1311
1304
|
}
|
|
1312
1305
|
}
|
|
1313
1306
|
}
|
|
1314
|
-
function notifyInverseOfPotentialMaterialization(graph,
|
|
1315
|
-
const relationship = graph.get(
|
|
1307
|
+
function notifyInverseOfPotentialMaterialization(graph, resourceKey, key, value, isRemote) {
|
|
1308
|
+
const relationship = graph.get(resourceKey, key);
|
|
1316
1309
|
if (isHasMany(relationship) && isRemote && relationship.remoteMembers.has(value)) {
|
|
1317
1310
|
notifyChange(graph, relationship);
|
|
1318
1311
|
}
|
|
1319
1312
|
}
|
|
1320
|
-
function removeFromInverse(graph,
|
|
1321
|
-
const relationship = graph.get(
|
|
1313
|
+
function removeFromInverse(graph, resourceKey, key, value, isRemote) {
|
|
1314
|
+
const relationship = graph.get(resourceKey, key);
|
|
1322
1315
|
if (isBelongsTo(relationship)) {
|
|
1323
1316
|
relationship.state.isEmpty = true;
|
|
1324
1317
|
if (isRemote) {
|
|
@@ -1418,7 +1411,7 @@ function replaceRelatedRecord(graph, op, isRemote = false) {
|
|
|
1418
1411
|
localState
|
|
1419
1412
|
} = relationship;
|
|
1420
1413
|
// don't sync if localState is a new record and our remoteState is null
|
|
1421
|
-
if (localState &&
|
|
1414
|
+
if (localState && checkIfNew(graph._realStore, localState) && !existingState) {
|
|
1422
1415
|
return;
|
|
1423
1416
|
}
|
|
1424
1417
|
if (existingState && localState === existingState) {
|
|
@@ -1479,7 +1472,7 @@ function replaceRelatedRecord(graph, op, isRemote = false) {
|
|
|
1479
1472
|
localState,
|
|
1480
1473
|
remoteState
|
|
1481
1474
|
} = relationship;
|
|
1482
|
-
if (localState &&
|
|
1475
|
+
if (localState && checkIfNew(graph._realStore, localState) && !remoteState) {
|
|
1483
1476
|
return;
|
|
1484
1477
|
}
|
|
1485
1478
|
// when localState does not match the new remoteState and
|
|
@@ -2106,18 +2099,18 @@ function _removeRemote(relationship, value) {
|
|
|
2106
2099
|
})(relationship.localState || relationship.isDirty) : {};
|
|
2107
2100
|
return true;
|
|
2108
2101
|
}
|
|
2109
|
-
function rollbackRelationship(graph,
|
|
2102
|
+
function rollbackRelationship(graph, key, field, relationship) {
|
|
2110
2103
|
if (isBelongsTo(relationship)) {
|
|
2111
2104
|
replaceRelatedRecord(graph, {
|
|
2112
2105
|
op: 'replaceRelatedRecord',
|
|
2113
|
-
record:
|
|
2106
|
+
record: key,
|
|
2114
2107
|
field,
|
|
2115
2108
|
value: relationship.remoteState
|
|
2116
2109
|
}, false);
|
|
2117
2110
|
} else {
|
|
2118
2111
|
replaceRelatedRecords(graph, {
|
|
2119
2112
|
op: 'replaceRelatedRecords',
|
|
2120
|
-
record:
|
|
2113
|
+
record: key,
|
|
2121
2114
|
field,
|
|
2122
2115
|
value: relationship.remoteState.slice()
|
|
2123
2116
|
}, false);
|
|
@@ -2216,8 +2209,7 @@ function createImplicitEdge(definition, identifier) {
|
|
|
2216
2209
|
/**
|
|
2217
2210
|
* Stores the data for one side of a "single" resource relationship.
|
|
2218
2211
|
*
|
|
2219
|
-
* @
|
|
2220
|
-
* @internal
|
|
2212
|
+
* @private
|
|
2221
2213
|
*/
|
|
2222
2214
|
|
|
2223
2215
|
function createResourceEdge(definition, identifier) {
|
|
@@ -2482,7 +2474,7 @@ function updateRelationshipOperation(graph, op) {
|
|
|
2482
2474
|
throw new Error(`Expected an array`);
|
|
2483
2475
|
}
|
|
2484
2476
|
})(Array.isArray(payload.data)) : {};
|
|
2485
|
-
const cache = graph.store.
|
|
2477
|
+
const cache = graph.store.cacheKeyManager;
|
|
2486
2478
|
graph.update({
|
|
2487
2479
|
op: 'replaceRelatedRecords',
|
|
2488
2480
|
record: identifier,
|
|
@@ -2494,7 +2486,7 @@ function updateRelationshipOperation(graph, op) {
|
|
|
2494
2486
|
op: 'replaceRelatedRecord',
|
|
2495
2487
|
record: identifier,
|
|
2496
2488
|
field: op.field,
|
|
2497
|
-
value: payload.data ? graph.store.
|
|
2489
|
+
value: payload.data ? graph.store.cacheKeyManager.upgradeIdentifier(payload.data) : null
|
|
2498
2490
|
}, true);
|
|
2499
2491
|
}
|
|
2500
2492
|
} else if (definition.isAsync === false && !state.hasReceivedData) {
|
|
@@ -2616,6 +2608,7 @@ class Graph {
|
|
|
2616
2608
|
this._potentialPolymorphicTypes = Object.create(null);
|
|
2617
2609
|
this.identifiers = new Map();
|
|
2618
2610
|
this.store = store;
|
|
2611
|
+
this._realStore = store._store;
|
|
2619
2612
|
this.isDestroyed = false;
|
|
2620
2613
|
this._willSyncRemote = false;
|
|
2621
2614
|
this._willSyncLocal = false;
|
|
@@ -2629,21 +2622,21 @@ class Graph {
|
|
|
2629
2622
|
this._removing = null;
|
|
2630
2623
|
this.silenceNotifications = false;
|
|
2631
2624
|
}
|
|
2632
|
-
has(
|
|
2633
|
-
const relationships = this.identifiers.get(
|
|
2625
|
+
has(resourceKey, propertyName) {
|
|
2626
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2634
2627
|
if (!relationships) {
|
|
2635
2628
|
return false;
|
|
2636
2629
|
}
|
|
2637
2630
|
return relationships[propertyName] !== undefined;
|
|
2638
2631
|
}
|
|
2639
|
-
getDefinition(
|
|
2640
|
-
let defs = this._metaCache[
|
|
2632
|
+
getDefinition(resourceKey, propertyName) {
|
|
2633
|
+
let defs = this._metaCache[resourceKey.type];
|
|
2641
2634
|
let meta = defs?.[propertyName];
|
|
2642
2635
|
if (!meta) {
|
|
2643
|
-
const info = /*#__NOINLINE__*/upgradeDefinition(this,
|
|
2636
|
+
const info = /*#__NOINLINE__*/upgradeDefinition(this, resourceKey, propertyName);
|
|
2644
2637
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2645
2638
|
if (!test) {
|
|
2646
|
-
throw new Error(`Could not determine relationship information for ${
|
|
2639
|
+
throw new Error(`Could not determine relationship information for ${resourceKey.type}.${propertyName}`);
|
|
2647
2640
|
}
|
|
2648
2641
|
})(info !== null) : {};
|
|
2649
2642
|
|
|
@@ -2653,43 +2646,43 @@ class Graph {
|
|
|
2653
2646
|
// this.registerPolymorphicType(info.rhs_baseModelName, identifier.type);
|
|
2654
2647
|
// }
|
|
2655
2648
|
|
|
2656
|
-
meta = /*#__NOINLINE__*/isLHS(info,
|
|
2657
|
-
defs = this._metaCache[
|
|
2649
|
+
meta = /*#__NOINLINE__*/isLHS(info, resourceKey.type, propertyName) ? info.lhs_definition : info.rhs_definition;
|
|
2650
|
+
defs = this._metaCache[resourceKey.type] = defs || {};
|
|
2658
2651
|
defs[propertyName] = meta;
|
|
2659
2652
|
}
|
|
2660
2653
|
return meta;
|
|
2661
2654
|
}
|
|
2662
|
-
get(
|
|
2655
|
+
get(resourceKey, propertyName) {
|
|
2663
2656
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2664
2657
|
if (!test) {
|
|
2665
2658
|
throw new Error(`expected propertyName`);
|
|
2666
2659
|
}
|
|
2667
2660
|
})(propertyName) : {};
|
|
2668
|
-
let relationships = this.identifiers.get(
|
|
2661
|
+
let relationships = this.identifiers.get(resourceKey);
|
|
2669
2662
|
if (!relationships) {
|
|
2670
2663
|
relationships = Object.create(null);
|
|
2671
|
-
this.identifiers.set(
|
|
2664
|
+
this.identifiers.set(resourceKey, relationships);
|
|
2672
2665
|
}
|
|
2673
2666
|
let relationship = relationships[propertyName];
|
|
2674
2667
|
if (!relationship) {
|
|
2675
|
-
const meta = this.getDefinition(
|
|
2668
|
+
const meta = this.getDefinition(resourceKey, propertyName);
|
|
2676
2669
|
if (meta.kind === 'belongsTo') {
|
|
2677
|
-
relationship = relationships[propertyName] = createResourceEdge(meta,
|
|
2670
|
+
relationship = relationships[propertyName] = createResourceEdge(meta, resourceKey);
|
|
2678
2671
|
} else if (meta.kind === 'hasMany') {
|
|
2679
|
-
relationship = relationships[propertyName] = createCollectionEdge(meta,
|
|
2672
|
+
relationship = relationships[propertyName] = createCollectionEdge(meta, resourceKey);
|
|
2680
2673
|
} else {
|
|
2681
2674
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2682
2675
|
if (!test) {
|
|
2683
2676
|
throw new Error(`Expected kind to be implicit`);
|
|
2684
2677
|
}
|
|
2685
2678
|
})(meta.kind === 'implicit' && meta.isImplicit === true) : {};
|
|
2686
|
-
relationship = relationships[propertyName] = createImplicitEdge(meta,
|
|
2679
|
+
relationship = relationships[propertyName] = createImplicitEdge(meta, resourceKey);
|
|
2687
2680
|
}
|
|
2688
2681
|
}
|
|
2689
2682
|
return relationship;
|
|
2690
2683
|
}
|
|
2691
|
-
getData(
|
|
2692
|
-
const relationship = this.get(
|
|
2684
|
+
getData(resourceKey, propertyName) {
|
|
2685
|
+
const relationship = this.get(resourceKey, propertyName);
|
|
2693
2686
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2694
2687
|
if (!test) {
|
|
2695
2688
|
throw new Error(`Cannot getData() on an implicit relationship`);
|
|
@@ -2700,8 +2693,8 @@ class Graph {
|
|
|
2700
2693
|
}
|
|
2701
2694
|
return legacyGetCollectionRelationshipData(relationship, false);
|
|
2702
2695
|
}
|
|
2703
|
-
getRemoteData(
|
|
2704
|
-
const relationship = this.get(
|
|
2696
|
+
getRemoteData(resourceKey, propertyName) {
|
|
2697
|
+
const relationship = this.get(resourceKey, propertyName);
|
|
2705
2698
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2706
2699
|
if (!test) {
|
|
2707
2700
|
throw new Error(`Cannot getRemoteData() on an implicit relationship`);
|
|
@@ -2737,13 +2730,13 @@ class Graph {
|
|
|
2737
2730
|
}
|
|
2738
2731
|
t2[type1] = true;
|
|
2739
2732
|
}
|
|
2740
|
-
isReleasable(
|
|
2741
|
-
const relationships = this.identifiers.get(
|
|
2733
|
+
isReleasable(resourceKey) {
|
|
2734
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2742
2735
|
if (!relationships) {
|
|
2743
2736
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2744
2737
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2745
2738
|
// eslint-disable-next-line no-console
|
|
2746
|
-
console.log(`graph: RELEASABLE ${String(
|
|
2739
|
+
console.log(`graph: RELEASABLE ${String(resourceKey)}`);
|
|
2747
2740
|
}
|
|
2748
2741
|
}
|
|
2749
2742
|
return true;
|
|
@@ -2761,11 +2754,11 @@ class Graph {
|
|
|
2761
2754
|
throw new Error(`Expected a relationship`);
|
|
2762
2755
|
}
|
|
2763
2756
|
})(relationship) : {};
|
|
2764
|
-
if (relationship.definition.inverseIsAsync && !
|
|
2757
|
+
if (relationship.definition.inverseIsAsync && !checkIfNew(this._realStore, resourceKey)) {
|
|
2765
2758
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2766
2759
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2767
2760
|
// eslint-disable-next-line no-console
|
|
2768
|
-
console.log(`graph: <<NOT>> RELEASABLE ${String(
|
|
2761
|
+
console.log(`graph: <<NOT>> RELEASABLE ${String(resourceKey)}`);
|
|
2769
2762
|
}
|
|
2770
2763
|
}
|
|
2771
2764
|
return false;
|
|
@@ -2774,19 +2767,19 @@ class Graph {
|
|
|
2774
2767
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2775
2768
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2776
2769
|
// eslint-disable-next-line no-console
|
|
2777
|
-
console.log(`graph: RELEASABLE ${String(
|
|
2770
|
+
console.log(`graph: RELEASABLE ${String(resourceKey)}`);
|
|
2778
2771
|
}
|
|
2779
2772
|
}
|
|
2780
2773
|
return true;
|
|
2781
2774
|
}
|
|
2782
|
-
unload(
|
|
2775
|
+
unload(resourceKey, silenceNotifications) {
|
|
2783
2776
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2784
2777
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2785
2778
|
// eslint-disable-next-line no-console
|
|
2786
|
-
console.log(`graph: unload ${String(
|
|
2779
|
+
console.log(`graph: unload ${String(resourceKey)}`);
|
|
2787
2780
|
}
|
|
2788
2781
|
}
|
|
2789
|
-
const relationships = this.identifiers.get(
|
|
2782
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2790
2783
|
if (relationships) {
|
|
2791
2784
|
// cleans up the graph but retains some nodes
|
|
2792
2785
|
// to allow for rematerialization
|
|
@@ -2804,8 +2797,8 @@ class Graph {
|
|
|
2804
2797
|
});
|
|
2805
2798
|
}
|
|
2806
2799
|
}
|
|
2807
|
-
_isDirty(
|
|
2808
|
-
const relationships = this.identifiers.get(
|
|
2800
|
+
_isDirty(resourceKey, field) {
|
|
2801
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2809
2802
|
if (!relationships) {
|
|
2810
2803
|
return false;
|
|
2811
2804
|
}
|
|
@@ -2822,8 +2815,8 @@ class Graph {
|
|
|
2822
2815
|
}
|
|
2823
2816
|
return false;
|
|
2824
2817
|
}
|
|
2825
|
-
getChanged(
|
|
2826
|
-
const relationships = this.identifiers.get(
|
|
2818
|
+
getChanged(resourceKey) {
|
|
2819
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2827
2820
|
const changed = new Map();
|
|
2828
2821
|
if (!relationships) {
|
|
2829
2822
|
return changed;
|
|
@@ -2861,21 +2854,21 @@ class Graph {
|
|
|
2861
2854
|
}
|
|
2862
2855
|
return changed;
|
|
2863
2856
|
}
|
|
2864
|
-
hasChanged(
|
|
2865
|
-
const relationships = this.identifiers.get(
|
|
2857
|
+
hasChanged(resourceKey) {
|
|
2858
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2866
2859
|
if (!relationships) {
|
|
2867
2860
|
return false;
|
|
2868
2861
|
}
|
|
2869
2862
|
const keys = Object.keys(relationships);
|
|
2870
2863
|
for (let i = 0; i < keys.length; i++) {
|
|
2871
|
-
if (this._isDirty(
|
|
2864
|
+
if (this._isDirty(resourceKey, keys[i])) {
|
|
2872
2865
|
return true;
|
|
2873
2866
|
}
|
|
2874
2867
|
}
|
|
2875
2868
|
return false;
|
|
2876
2869
|
}
|
|
2877
|
-
rollback(
|
|
2878
|
-
const relationships = this.identifiers.get(
|
|
2870
|
+
rollback(resourceKey) {
|
|
2871
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2879
2872
|
const changed = [];
|
|
2880
2873
|
if (!relationships) {
|
|
2881
2874
|
return changed;
|
|
@@ -2887,28 +2880,28 @@ class Graph {
|
|
|
2887
2880
|
if (!relationship) {
|
|
2888
2881
|
continue;
|
|
2889
2882
|
}
|
|
2890
|
-
if (this._isDirty(
|
|
2891
|
-
rollbackRelationship(this,
|
|
2883
|
+
if (this._isDirty(resourceKey, field)) {
|
|
2884
|
+
rollbackRelationship(this, resourceKey, field, relationship);
|
|
2892
2885
|
changed.push(field);
|
|
2893
2886
|
}
|
|
2894
2887
|
}
|
|
2895
2888
|
return changed;
|
|
2896
2889
|
}
|
|
2897
|
-
remove(
|
|
2890
|
+
remove(resourceKey) {
|
|
2898
2891
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2899
2892
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2900
2893
|
// eslint-disable-next-line no-console
|
|
2901
|
-
console.log(`graph: remove ${String(
|
|
2894
|
+
console.log(`graph: remove ${String(resourceKey)}`);
|
|
2902
2895
|
}
|
|
2903
2896
|
}
|
|
2904
2897
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2905
2898
|
if (!test) {
|
|
2906
|
-
throw new Error(`Cannot remove ${String(
|
|
2899
|
+
throw new Error(`Cannot remove ${String(resourceKey)} while still removing ${String(this._removing)}`);
|
|
2907
2900
|
}
|
|
2908
2901
|
})(!this._removing) : {};
|
|
2909
|
-
this._removing =
|
|
2910
|
-
this.unload(
|
|
2911
|
-
this.identifiers.delete(
|
|
2902
|
+
this._removing = resourceKey;
|
|
2903
|
+
this.unload(resourceKey);
|
|
2904
|
+
this.identifiers.delete(resourceKey);
|
|
2912
2905
|
this._removing = null;
|
|
2913
2906
|
}
|
|
2914
2907
|
|
|
@@ -3126,11 +3119,11 @@ class Graph {
|
|
|
3126
3119
|
}
|
|
3127
3120
|
}
|
|
3128
3121
|
function flushPending(graph, ops) {
|
|
3129
|
-
ops.
|
|
3130
|
-
type.
|
|
3122
|
+
for (const type of ops.values()) {
|
|
3123
|
+
for (const opList of type.values()) {
|
|
3131
3124
|
flushPendingList(graph, opList);
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3134
3127
|
}
|
|
3135
3128
|
function flushPendingList(graph, opList) {
|
|
3136
3129
|
for (let i = 0; i < opList.length; i++) {
|
|
@@ -3180,7 +3173,7 @@ function destroyRelationship(graph, rel, silenceNotifications) {
|
|
|
3180
3173
|
}
|
|
3181
3174
|
}
|
|
3182
3175
|
}
|
|
3183
|
-
function notifyInverseOfDematerialization(graph, inverseIdentifier, inverseKey,
|
|
3176
|
+
function notifyInverseOfDematerialization(graph, inverseIdentifier, inverseKey, resourceKey, silenceNotifications) {
|
|
3184
3177
|
if (!graph.has(inverseIdentifier, inverseKey)) {
|
|
3185
3178
|
return;
|
|
3186
3179
|
}
|
|
@@ -3193,8 +3186,8 @@ function notifyInverseOfDematerialization(graph, inverseIdentifier, inverseKey,
|
|
|
3193
3186
|
|
|
3194
3187
|
// For remote members, it is possible that inverseRecordData has already been associated to
|
|
3195
3188
|
// to another record. For such cases, do not dematerialize the inverseRecordData
|
|
3196
|
-
if (!isBelongsTo(relationship) || !relationship.localState ||
|
|
3197
|
-
/*#__NOINLINE__*/removeDematerializedInverse(graph, relationship,
|
|
3189
|
+
if (!isBelongsTo(relationship) || !relationship.localState || resourceKey === relationship.localState) {
|
|
3190
|
+
/*#__NOINLINE__*/removeDematerializedInverse(graph, relationship, resourceKey, silenceNotifications);
|
|
3198
3191
|
}
|
|
3199
3192
|
}
|
|
3200
3193
|
function clearRelationship(relationship) {
|
|
@@ -3214,7 +3207,7 @@ function clearRelationship(relationship) {
|
|
|
3214
3207
|
function removeDematerializedInverse(graph, relationship, inverseIdentifier, silenceNotifications) {
|
|
3215
3208
|
if (isBelongsTo(relationship)) {
|
|
3216
3209
|
const localInverse = relationship.localState;
|
|
3217
|
-
if (!relationship.definition.isAsync || localInverse &&
|
|
3210
|
+
if (!relationship.definition.isAsync || localInverse && checkIfNew(graph._realStore, localInverse)) {
|
|
3218
3211
|
// unloading inverse of a sync relationship is treated as a client-side
|
|
3219
3212
|
// delete, so actually remove the models don't merely invalidate the cp
|
|
3220
3213
|
// cache.
|
|
@@ -3227,7 +3220,7 @@ function removeDematerializedInverse(graph, relationship, inverseIdentifier, sil
|
|
|
3227
3220
|
relationship.remoteState = null;
|
|
3228
3221
|
relationship.state.hasReceivedData = true;
|
|
3229
3222
|
relationship.state.isEmpty = true;
|
|
3230
|
-
if (relationship.localState && !
|
|
3223
|
+
if (relationship.localState && !checkIfNew(graph._realStore, relationship.localState)) {
|
|
3231
3224
|
relationship.localState = null;
|
|
3232
3225
|
}
|
|
3233
3226
|
}
|
|
@@ -3238,7 +3231,7 @@ function removeDematerializedInverse(graph, relationship, inverseIdentifier, sil
|
|
|
3238
3231
|
notifyChange(graph, relationship);
|
|
3239
3232
|
}
|
|
3240
3233
|
} else {
|
|
3241
|
-
if (!relationship.definition.isAsync || inverseIdentifier &&
|
|
3234
|
+
if (!relationship.definition.isAsync || inverseIdentifier && checkIfNew(graph._realStore, inverseIdentifier)) {
|
|
3242
3235
|
// unloading inverse of a sync relationship is treated as a client-side
|
|
3243
3236
|
// delete, so actually remove the models don't merely invalidate the cp
|
|
3244
3237
|
// cache.
|