@warp-drive/core 5.7.0-alpha.2 → 5.7.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/declarations/graph/-private/-diff.d.ts +8 -8
- package/declarations/graph/-private/-edge-definition.d.ts +2 -2
- 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 +5 -5
- 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 +50 -25
- package/declarations/reactive/-private/schema.d.ts +18 -14
- 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 +2 -2
- package/declarations/request/-private/fetch.d.ts +2 -0
- package/declarations/request/-private/manager.d.ts +3 -6
- package/declarations/request/-private/types.d.ts +4 -4
- 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 +20 -18
- package/declarations/store/-private/default-cache-policy.d.ts +25 -38
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +13 -11
- package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +22 -19
- package/declarations/store/-private/managers/cache-manager.d.ts +46 -94
- package/declarations/store/-private/managers/notification-manager.d.ts +21 -25
- package/declarations/store/-private/managers/record-array-manager.d.ts +78 -27
- package/declarations/store/-private/network/request-cache.d.ts +11 -11
- package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
- package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +1 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +15 -22
- package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +4 -8
- package/declarations/store/-private/record-arrays/-utils.d.ts +82 -0
- package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +89 -0
- package/declarations/store/-private/record-arrays/{many-array.d.ts → legacy-many-array.d.ts} +43 -101
- package/declarations/store/-private/record-arrays/legacy-query.d.ts +103 -0
- package/declarations/store/-private/record-arrays/resource-array.d.ts +82 -0
- package/declarations/store/-private/store-service.d.ts +78 -35
- package/declarations/store/-private.d.ts +5 -5
- 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/schema-service.d.ts +28 -40
- package/declarations/store/-types/q/store.d.ts +6 -7
- package/declarations/store/deprecated/-private.d.ts +12 -12
- 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 +60 -76
- package/declarations/types/params.d.ts +2 -3
- package/declarations/types/request.d.ts +47 -35
- 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/dist/{context-COmAnXUQ.js → context-kQXhkeBj.js} +13 -0
- package/dist/graph/-private.js +135 -139
- package/dist/index.js +6 -3
- package/dist/reactive/-private.js +1 -1
- package/dist/reactive.js +193 -1409
- package/dist/{request-state-CejVJgdj.js → request-state-glkInb2R.js} +5139 -2758
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -2
- 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 +27 -0
- package/dist/types/schema/fields.js +23 -2
- package/package.json +3 -3
- 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/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
|
}
|
|
@@ -490,13 +485,13 @@ function isLHS(info, type, key) {
|
|
|
490
485
|
}
|
|
491
486
|
return false;
|
|
492
487
|
}
|
|
493
|
-
function upgradeDefinition(graph,
|
|
488
|
+
function upgradeDefinition(graph, key, propertyName, isImplicit = false) {
|
|
494
489
|
const cache = graph._definitionCache;
|
|
495
490
|
const storeWrapper = graph.store;
|
|
496
491
|
const polymorphicLookup = graph._potentialPolymorphicTypes;
|
|
497
492
|
const {
|
|
498
493
|
type
|
|
499
|
-
} =
|
|
494
|
+
} = key;
|
|
500
495
|
let cached = /*#__NOINLINE__*/expandingGet(cache, type, propertyName);
|
|
501
496
|
|
|
502
497
|
// CASE: We have a cached resolution (null if no relationship exists)
|
|
@@ -508,7 +503,7 @@ function upgradeDefinition(graph, identifier, propertyName, isImplicit = false)
|
|
|
508
503
|
throw new Error(`Expected to find relationship definition in the cache for the implicit relationship ${propertyName}`);
|
|
509
504
|
}
|
|
510
505
|
})(!isImplicit) : {};
|
|
511
|
-
const relationships = storeWrapper.schema.fields(
|
|
506
|
+
const relationships = storeWrapper.schema.fields(key);
|
|
512
507
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
513
508
|
if (!test) {
|
|
514
509
|
throw new Error(`Expected to have a relationship definition for ${type} but none was found.`);
|
|
@@ -560,7 +555,7 @@ function upgradeDefinition(graph, identifier, propertyName, isImplicit = false)
|
|
|
560
555
|
})(getStore(storeWrapper).modelFor(inverseType)) : {};
|
|
561
556
|
inverseDefinition = null;
|
|
562
557
|
} else {
|
|
563
|
-
inverseKey = /*#__NOINLINE__*/inverseForRelationship(getStore(storeWrapper),
|
|
558
|
+
inverseKey = /*#__NOINLINE__*/inverseForRelationship(getStore(storeWrapper), key, propertyName);
|
|
564
559
|
|
|
565
560
|
// CASE: If we are polymorphic, and we declared an inverse that is non-null
|
|
566
561
|
// we must assume that the lack of inverseKey means that there is no
|
|
@@ -716,8 +711,8 @@ function upgradeDefinition(graph, identifier, propertyName, isImplicit = false)
|
|
|
716
711
|
expandingSet(cache, inverseType, inverseKey, info);
|
|
717
712
|
return info;
|
|
718
713
|
}
|
|
719
|
-
function inverseForRelationship(store,
|
|
720
|
-
const definition = store.schema.fields(
|
|
714
|
+
function inverseForRelationship(store, resourceKey, key) {
|
|
715
|
+
const definition = store.schema.fields(resourceKey).get(key);
|
|
721
716
|
if (!definition) {
|
|
722
717
|
return null;
|
|
723
718
|
}
|
|
@@ -996,7 +991,7 @@ function replaceRelatedRecords(graph, op, isRemote) {
|
|
|
996
991
|
}
|
|
997
992
|
}
|
|
998
993
|
function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
999
|
-
const
|
|
994
|
+
const resourceKeys = op.value;
|
|
1000
995
|
const relationship = graph.get(op.record, op.field);
|
|
1001
996
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
1002
997
|
if (!test) {
|
|
@@ -1022,48 +1017,48 @@ function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
|
1022
1017
|
count(`replaceRelatedRecordsLocal ${'type' in record ? record.type : '<document>'} ${op.field}`);
|
|
1023
1018
|
}
|
|
1024
1019
|
}
|
|
1025
|
-
const onAdd =
|
|
1020
|
+
const onAdd = resourceKey => {
|
|
1026
1021
|
// 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 !==
|
|
1022
|
+
// if our previous local state did not contain this ResourceKey
|
|
1023
|
+
const removalsHas = removals?.has(resourceKey);
|
|
1024
|
+
if (removalsHas || !additions?.has(resourceKey)) {
|
|
1025
|
+
if (type !== resourceKey.type) {
|
|
1031
1026
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
1032
|
-
assertPolymorphicType(relationship.identifier, relationship.definition,
|
|
1027
|
+
assertPolymorphicType(relationship.identifier, relationship.definition, resourceKey, graph.store);
|
|
1033
1028
|
}
|
|
1034
|
-
graph.registerPolymorphicType(type,
|
|
1029
|
+
graph.registerPolymorphicType(type, resourceKey.type);
|
|
1035
1030
|
}
|
|
1036
1031
|
|
|
1037
1032
|
// we've added a record locally that wasn't in the local state before
|
|
1038
1033
|
localBecameDirty = true;
|
|
1039
|
-
addToInverse(graph,
|
|
1034
|
+
addToInverse(graph, resourceKey, inverseKey, op.record, isRemote);
|
|
1040
1035
|
if (removalsHas) {
|
|
1041
|
-
removals.delete(
|
|
1036
|
+
removals.delete(resourceKey);
|
|
1042
1037
|
}
|
|
1043
1038
|
}
|
|
1044
1039
|
};
|
|
1045
|
-
const onRemove =
|
|
1040
|
+
const onRemove = resourceKey => {
|
|
1046
1041
|
// 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(
|
|
1042
|
+
// if our previous local state had contained this ResourceKey
|
|
1043
|
+
const additionsHas = additions?.has(resourceKey);
|
|
1044
|
+
if (additionsHas || !removals?.has(resourceKey)) {
|
|
1050
1045
|
// we've removed a record locally that was in the local state before
|
|
1051
1046
|
localBecameDirty = true;
|
|
1052
|
-
removeFromInverse(graph,
|
|
1047
|
+
removeFromInverse(graph, resourceKey, inverseKey, record, isRemote);
|
|
1053
1048
|
if (additionsHas) {
|
|
1054
|
-
additions.delete(
|
|
1049
|
+
additions.delete(resourceKey);
|
|
1055
1050
|
}
|
|
1056
1051
|
}
|
|
1057
1052
|
};
|
|
1058
|
-
const diff = diffCollection(
|
|
1053
|
+
const diff = diffCollection(resourceKeys, relationship, onAdd, onRemove);
|
|
1059
1054
|
|
|
1060
1055
|
// any additions no longer in the local state
|
|
1061
1056
|
// also need to be removed from the inverse
|
|
1062
1057
|
if (additions && additions.size > 0) {
|
|
1063
|
-
additions.forEach(
|
|
1064
|
-
if (!diff.add.has(
|
|
1058
|
+
additions.forEach(resourceKey => {
|
|
1059
|
+
if (!diff.add.has(resourceKey)) {
|
|
1065
1060
|
localBecameDirty = true;
|
|
1066
|
-
onRemove(
|
|
1061
|
+
onRemove(resourceKey);
|
|
1067
1062
|
}
|
|
1068
1063
|
});
|
|
1069
1064
|
}
|
|
@@ -1071,10 +1066,10 @@ function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
|
1071
1066
|
// any removals no longer in the local state
|
|
1072
1067
|
// also need to be added back to the inverse
|
|
1073
1068
|
if (removals && removals.size > 0) {
|
|
1074
|
-
removals.forEach(
|
|
1075
|
-
if (!diff.del.has(
|
|
1069
|
+
removals.forEach(resourceKey => {
|
|
1070
|
+
if (!diff.del.has(resourceKey)) {
|
|
1076
1071
|
localBecameDirty = true;
|
|
1077
|
-
onAdd(
|
|
1072
|
+
onAdd(resourceKey);
|
|
1078
1073
|
}
|
|
1079
1074
|
});
|
|
1080
1075
|
}
|
|
@@ -1090,7 +1085,7 @@ function replaceRelatedRecordsLocal(graph, op, isRemote) {
|
|
|
1090
1085
|
}
|
|
1091
1086
|
}
|
|
1092
1087
|
function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
1093
|
-
const
|
|
1088
|
+
const resourceKeys = op.value;
|
|
1094
1089
|
const relationship = graph.get(op.record, op.field);
|
|
1095
1090
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_METRIC_COUNTS)) {
|
|
1096
1091
|
if (getGlobalConfig().WarpDrive.debug.LOG_METRIC_COUNTS || globalThis.getWarpDriveRuntimeConfig().debug.LOG_METRIC_COUNTS) {
|
|
@@ -1122,18 +1117,18 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1122
1117
|
const {
|
|
1123
1118
|
type
|
|
1124
1119
|
} = relationship.definition;
|
|
1125
|
-
const diff = diffCollection(
|
|
1126
|
-
if (type !==
|
|
1120
|
+
const diff = diffCollection(resourceKeys, relationship, resourceKey => {
|
|
1121
|
+
if (type !== resourceKey.type) {
|
|
1127
1122
|
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
1128
|
-
assertPolymorphicType(relationship.identifier, relationship.definition,
|
|
1123
|
+
assertPolymorphicType(relationship.identifier, relationship.definition, resourceKey, graph.store);
|
|
1129
1124
|
}
|
|
1130
|
-
graph.registerPolymorphicType(type,
|
|
1125
|
+
graph.registerPolymorphicType(type, resourceKey.type);
|
|
1131
1126
|
}
|
|
1132
1127
|
// commit additions
|
|
1133
1128
|
// TODO build this into the diff?
|
|
1134
1129
|
// because we are not dirty if this was a committed local addition
|
|
1135
|
-
if (relationship.additions?.has(
|
|
1136
|
-
relationship.additions.delete(
|
|
1130
|
+
if (relationship.additions?.has(resourceKey)) {
|
|
1131
|
+
relationship.additions.delete(resourceKey);
|
|
1137
1132
|
} else {
|
|
1138
1133
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.DEBUG_RELATIONSHIP_NOTIFICATIONS)) {
|
|
1139
1134
|
if (getGlobalConfig().WarpDrive.debug.DEBUG_RELATIONSHIP_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.DEBUG_RELATIONSHIP_NOTIFICATIONS) {
|
|
@@ -1144,13 +1139,13 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1144
1139
|
}
|
|
1145
1140
|
}
|
|
1146
1141
|
}
|
|
1147
|
-
addToInverse(graph,
|
|
1148
|
-
},
|
|
1142
|
+
addToInverse(graph, resourceKey, definition.inverseKey, op.record, isRemote);
|
|
1143
|
+
}, resourceKey => {
|
|
1149
1144
|
// commit removals
|
|
1150
1145
|
// TODO build this into the diff?
|
|
1151
1146
|
// because we are not dirty if this was a committed local addition
|
|
1152
|
-
if (relationship.removals?.has(
|
|
1153
|
-
relationship.removals.delete(
|
|
1147
|
+
if (relationship.removals?.has(resourceKey)) {
|
|
1148
|
+
relationship.removals.delete(resourceKey);
|
|
1154
1149
|
} else {
|
|
1155
1150
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.DEBUG_RELATIONSHIP_NOTIFICATIONS)) {
|
|
1156
1151
|
if (getGlobalConfig().WarpDrive.debug.DEBUG_RELATIONSHIP_NOTIFICATIONS || globalThis.getWarpDriveRuntimeConfig().debug.DEBUG_RELATIONSHIP_NOTIFICATIONS) {
|
|
@@ -1161,7 +1156,7 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1161
1156
|
}
|
|
1162
1157
|
}
|
|
1163
1158
|
}
|
|
1164
|
-
removeFromInverse(graph,
|
|
1159
|
+
removeFromInverse(graph, resourceKey, definition.inverseKey, op.record, isRemote);
|
|
1165
1160
|
});
|
|
1166
1161
|
|
|
1167
1162
|
// replace existing state
|
|
@@ -1192,30 +1187,30 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1192
1187
|
};
|
|
1193
1188
|
if (relationship.removals) {
|
|
1194
1189
|
relationship.isDirty = true;
|
|
1195
|
-
relationship.removals.forEach(
|
|
1190
|
+
relationship.removals.forEach(resourceKey => {
|
|
1196
1191
|
deprecationInfo.triggered = true;
|
|
1197
|
-
deprecationInfo.removals.push(
|
|
1192
|
+
deprecationInfo.removals.push(resourceKey);
|
|
1198
1193
|
// reverse the removal
|
|
1199
1194
|
// if we are still in removals at this point then
|
|
1200
1195
|
// we were not "committed" which means we are present
|
|
1201
1196
|
// in the remoteMembers. So we "add back" on the inverse.
|
|
1202
|
-
addToInverse(graph,
|
|
1197
|
+
addToInverse(graph, resourceKey, definition.inverseKey, op.record, false);
|
|
1203
1198
|
});
|
|
1204
1199
|
relationship.removals = null;
|
|
1205
1200
|
}
|
|
1206
1201
|
if (relationship.additions) {
|
|
1207
|
-
relationship.additions.forEach(
|
|
1202
|
+
relationship.additions.forEach(resourceKey => {
|
|
1208
1203
|
// reverse the addition
|
|
1209
1204
|
// if we are still in additions at this point then
|
|
1210
1205
|
// we were not "committed" which means we are not present
|
|
1211
1206
|
// in the remoteMembers. So we "remove" from the inverse.
|
|
1212
1207
|
// however we only do this if we are not a "new" record.
|
|
1213
|
-
if (!
|
|
1208
|
+
if (!checkIfNew(graph._realStore, resourceKey)) {
|
|
1214
1209
|
deprecationInfo.triggered = true;
|
|
1215
|
-
deprecationInfo.additions.push(
|
|
1210
|
+
deprecationInfo.additions.push(resourceKey);
|
|
1216
1211
|
relationship.isDirty = true;
|
|
1217
|
-
relationship.additions.delete(
|
|
1218
|
-
removeFromInverse(graph,
|
|
1212
|
+
relationship.additions.delete(resourceKey);
|
|
1213
|
+
removeFromInverse(graph, resourceKey, definition.inverseKey, op.record, false);
|
|
1219
1214
|
}
|
|
1220
1215
|
});
|
|
1221
1216
|
if (relationship.additions.size === 0) {
|
|
@@ -1240,8 +1235,8 @@ function replaceRelatedRecordsRemote(graph, op, isRemote) {
|
|
|
1240
1235
|
flushCanonical(graph, relationship);
|
|
1241
1236
|
}
|
|
1242
1237
|
}
|
|
1243
|
-
function addToInverse(graph,
|
|
1244
|
-
const relationship = graph.get(
|
|
1238
|
+
function addToInverse(graph, resourceKey, key, value, isRemote) {
|
|
1239
|
+
const relationship = graph.get(resourceKey, key);
|
|
1245
1240
|
const {
|
|
1246
1241
|
type
|
|
1247
1242
|
} = relationship.definition;
|
|
@@ -1257,13 +1252,13 @@ function addToInverse(graph, identifier, key, value, isRemote) {
|
|
|
1257
1252
|
if (isRemote) {
|
|
1258
1253
|
graph._addToTransaction(relationship);
|
|
1259
1254
|
if (relationship.remoteState !== null) {
|
|
1260
|
-
removeFromInverse(graph, relationship.remoteState, relationship.definition.inverseKey,
|
|
1255
|
+
removeFromInverse(graph, relationship.remoteState, relationship.definition.inverseKey, resourceKey, isRemote);
|
|
1261
1256
|
}
|
|
1262
1257
|
relationship.remoteState = value;
|
|
1263
1258
|
}
|
|
1264
1259
|
if (relationship.localState !== value) {
|
|
1265
1260
|
if (!isRemote && relationship.localState) {
|
|
1266
|
-
removeFromInverse(graph, relationship.localState, relationship.definition.inverseKey,
|
|
1261
|
+
removeFromInverse(graph, relationship.localState, relationship.definition.inverseKey, resourceKey, isRemote);
|
|
1267
1262
|
}
|
|
1268
1263
|
relationship.localState = value;
|
|
1269
1264
|
notifyChange(graph, relationship);
|
|
@@ -1294,7 +1289,7 @@ function addToInverse(graph, identifier, key, value, isRemote) {
|
|
|
1294
1289
|
if (!relationship.isDirty && !relationship.localState) {
|
|
1295
1290
|
relationship.localState = [];
|
|
1296
1291
|
}
|
|
1297
|
-
if (_add(graph,
|
|
1292
|
+
if (_add(graph, resourceKey, relationship, value, null, isRemote)) {
|
|
1298
1293
|
notifyChange(graph, relationship);
|
|
1299
1294
|
}
|
|
1300
1295
|
}
|
|
@@ -1311,14 +1306,14 @@ function addToInverse(graph, identifier, key, value, isRemote) {
|
|
|
1311
1306
|
}
|
|
1312
1307
|
}
|
|
1313
1308
|
}
|
|
1314
|
-
function notifyInverseOfPotentialMaterialization(graph,
|
|
1315
|
-
const relationship = graph.get(
|
|
1309
|
+
function notifyInverseOfPotentialMaterialization(graph, resourceKey, key, value, isRemote) {
|
|
1310
|
+
const relationship = graph.get(resourceKey, key);
|
|
1316
1311
|
if (isHasMany(relationship) && isRemote && relationship.remoteMembers.has(value)) {
|
|
1317
1312
|
notifyChange(graph, relationship);
|
|
1318
1313
|
}
|
|
1319
1314
|
}
|
|
1320
|
-
function removeFromInverse(graph,
|
|
1321
|
-
const relationship = graph.get(
|
|
1315
|
+
function removeFromInverse(graph, resourceKey, key, value, isRemote) {
|
|
1316
|
+
const relationship = graph.get(resourceKey, key);
|
|
1322
1317
|
if (isBelongsTo(relationship)) {
|
|
1323
1318
|
relationship.state.isEmpty = true;
|
|
1324
1319
|
if (isRemote) {
|
|
@@ -1418,7 +1413,7 @@ function replaceRelatedRecord(graph, op, isRemote = false) {
|
|
|
1418
1413
|
localState
|
|
1419
1414
|
} = relationship;
|
|
1420
1415
|
// don't sync if localState is a new record and our remoteState is null
|
|
1421
|
-
if (localState &&
|
|
1416
|
+
if (localState && checkIfNew(graph._realStore, localState) && !existingState) {
|
|
1422
1417
|
return;
|
|
1423
1418
|
}
|
|
1424
1419
|
if (existingState && localState === existingState) {
|
|
@@ -1479,7 +1474,7 @@ function replaceRelatedRecord(graph, op, isRemote = false) {
|
|
|
1479
1474
|
localState,
|
|
1480
1475
|
remoteState
|
|
1481
1476
|
} = relationship;
|
|
1482
|
-
if (localState &&
|
|
1477
|
+
if (localState && checkIfNew(graph._realStore, localState) && !remoteState) {
|
|
1483
1478
|
return;
|
|
1484
1479
|
}
|
|
1485
1480
|
// when localState does not match the new remoteState and
|
|
@@ -2106,18 +2101,18 @@ function _removeRemote(relationship, value) {
|
|
|
2106
2101
|
})(relationship.localState || relationship.isDirty) : {};
|
|
2107
2102
|
return true;
|
|
2108
2103
|
}
|
|
2109
|
-
function rollbackRelationship(graph,
|
|
2104
|
+
function rollbackRelationship(graph, key, field, relationship) {
|
|
2110
2105
|
if (isBelongsTo(relationship)) {
|
|
2111
2106
|
replaceRelatedRecord(graph, {
|
|
2112
2107
|
op: 'replaceRelatedRecord',
|
|
2113
|
-
record:
|
|
2108
|
+
record: key,
|
|
2114
2109
|
field,
|
|
2115
2110
|
value: relationship.remoteState
|
|
2116
2111
|
}, false);
|
|
2117
2112
|
} else {
|
|
2118
2113
|
replaceRelatedRecords(graph, {
|
|
2119
2114
|
op: 'replaceRelatedRecords',
|
|
2120
|
-
record:
|
|
2115
|
+
record: key,
|
|
2121
2116
|
field,
|
|
2122
2117
|
value: relationship.remoteState.slice()
|
|
2123
2118
|
}, false);
|
|
@@ -2482,7 +2477,7 @@ function updateRelationshipOperation(graph, op) {
|
|
|
2482
2477
|
throw new Error(`Expected an array`);
|
|
2483
2478
|
}
|
|
2484
2479
|
})(Array.isArray(payload.data)) : {};
|
|
2485
|
-
const cache = graph.store.
|
|
2480
|
+
const cache = graph.store.cacheKeyManager;
|
|
2486
2481
|
graph.update({
|
|
2487
2482
|
op: 'replaceRelatedRecords',
|
|
2488
2483
|
record: identifier,
|
|
@@ -2494,7 +2489,7 @@ function updateRelationshipOperation(graph, op) {
|
|
|
2494
2489
|
op: 'replaceRelatedRecord',
|
|
2495
2490
|
record: identifier,
|
|
2496
2491
|
field: op.field,
|
|
2497
|
-
value: payload.data ? graph.store.
|
|
2492
|
+
value: payload.data ? graph.store.cacheKeyManager.upgradeIdentifier(payload.data) : null
|
|
2498
2493
|
}, true);
|
|
2499
2494
|
}
|
|
2500
2495
|
} else if (definition.isAsync === false && !state.hasReceivedData) {
|
|
@@ -2616,6 +2611,7 @@ class Graph {
|
|
|
2616
2611
|
this._potentialPolymorphicTypes = Object.create(null);
|
|
2617
2612
|
this.identifiers = new Map();
|
|
2618
2613
|
this.store = store;
|
|
2614
|
+
this._realStore = store._store;
|
|
2619
2615
|
this.isDestroyed = false;
|
|
2620
2616
|
this._willSyncRemote = false;
|
|
2621
2617
|
this._willSyncLocal = false;
|
|
@@ -2629,21 +2625,21 @@ class Graph {
|
|
|
2629
2625
|
this._removing = null;
|
|
2630
2626
|
this.silenceNotifications = false;
|
|
2631
2627
|
}
|
|
2632
|
-
has(
|
|
2633
|
-
const relationships = this.identifiers.get(
|
|
2628
|
+
has(resourceKey, propertyName) {
|
|
2629
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2634
2630
|
if (!relationships) {
|
|
2635
2631
|
return false;
|
|
2636
2632
|
}
|
|
2637
2633
|
return relationships[propertyName] !== undefined;
|
|
2638
2634
|
}
|
|
2639
|
-
getDefinition(
|
|
2640
|
-
let defs = this._metaCache[
|
|
2635
|
+
getDefinition(resourceKey, propertyName) {
|
|
2636
|
+
let defs = this._metaCache[resourceKey.type];
|
|
2641
2637
|
let meta = defs?.[propertyName];
|
|
2642
2638
|
if (!meta) {
|
|
2643
|
-
const info = /*#__NOINLINE__*/upgradeDefinition(this,
|
|
2639
|
+
const info = /*#__NOINLINE__*/upgradeDefinition(this, resourceKey, propertyName);
|
|
2644
2640
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2645
2641
|
if (!test) {
|
|
2646
|
-
throw new Error(`Could not determine relationship information for ${
|
|
2642
|
+
throw new Error(`Could not determine relationship information for ${resourceKey.type}.${propertyName}`);
|
|
2647
2643
|
}
|
|
2648
2644
|
})(info !== null) : {};
|
|
2649
2645
|
|
|
@@ -2653,43 +2649,43 @@ class Graph {
|
|
|
2653
2649
|
// this.registerPolymorphicType(info.rhs_baseModelName, identifier.type);
|
|
2654
2650
|
// }
|
|
2655
2651
|
|
|
2656
|
-
meta = /*#__NOINLINE__*/isLHS(info,
|
|
2657
|
-
defs = this._metaCache[
|
|
2652
|
+
meta = /*#__NOINLINE__*/isLHS(info, resourceKey.type, propertyName) ? info.lhs_definition : info.rhs_definition;
|
|
2653
|
+
defs = this._metaCache[resourceKey.type] = defs || {};
|
|
2658
2654
|
defs[propertyName] = meta;
|
|
2659
2655
|
}
|
|
2660
2656
|
return meta;
|
|
2661
2657
|
}
|
|
2662
|
-
get(
|
|
2658
|
+
get(resourceKey, propertyName) {
|
|
2663
2659
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2664
2660
|
if (!test) {
|
|
2665
2661
|
throw new Error(`expected propertyName`);
|
|
2666
2662
|
}
|
|
2667
2663
|
})(propertyName) : {};
|
|
2668
|
-
let relationships = this.identifiers.get(
|
|
2664
|
+
let relationships = this.identifiers.get(resourceKey);
|
|
2669
2665
|
if (!relationships) {
|
|
2670
2666
|
relationships = Object.create(null);
|
|
2671
|
-
this.identifiers.set(
|
|
2667
|
+
this.identifiers.set(resourceKey, relationships);
|
|
2672
2668
|
}
|
|
2673
2669
|
let relationship = relationships[propertyName];
|
|
2674
2670
|
if (!relationship) {
|
|
2675
|
-
const meta = this.getDefinition(
|
|
2671
|
+
const meta = this.getDefinition(resourceKey, propertyName);
|
|
2676
2672
|
if (meta.kind === 'belongsTo') {
|
|
2677
|
-
relationship = relationships[propertyName] = createResourceEdge(meta,
|
|
2673
|
+
relationship = relationships[propertyName] = createResourceEdge(meta, resourceKey);
|
|
2678
2674
|
} else if (meta.kind === 'hasMany') {
|
|
2679
|
-
relationship = relationships[propertyName] = createCollectionEdge(meta,
|
|
2675
|
+
relationship = relationships[propertyName] = createCollectionEdge(meta, resourceKey);
|
|
2680
2676
|
} else {
|
|
2681
2677
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2682
2678
|
if (!test) {
|
|
2683
2679
|
throw new Error(`Expected kind to be implicit`);
|
|
2684
2680
|
}
|
|
2685
2681
|
})(meta.kind === 'implicit' && meta.isImplicit === true) : {};
|
|
2686
|
-
relationship = relationships[propertyName] = createImplicitEdge(meta,
|
|
2682
|
+
relationship = relationships[propertyName] = createImplicitEdge(meta, resourceKey);
|
|
2687
2683
|
}
|
|
2688
2684
|
}
|
|
2689
2685
|
return relationship;
|
|
2690
2686
|
}
|
|
2691
|
-
getData(
|
|
2692
|
-
const relationship = this.get(
|
|
2687
|
+
getData(resourceKey, propertyName) {
|
|
2688
|
+
const relationship = this.get(resourceKey, propertyName);
|
|
2693
2689
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2694
2690
|
if (!test) {
|
|
2695
2691
|
throw new Error(`Cannot getData() on an implicit relationship`);
|
|
@@ -2700,8 +2696,8 @@ class Graph {
|
|
|
2700
2696
|
}
|
|
2701
2697
|
return legacyGetCollectionRelationshipData(relationship, false);
|
|
2702
2698
|
}
|
|
2703
|
-
getRemoteData(
|
|
2704
|
-
const relationship = this.get(
|
|
2699
|
+
getRemoteData(resourceKey, propertyName) {
|
|
2700
|
+
const relationship = this.get(resourceKey, propertyName);
|
|
2705
2701
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2706
2702
|
if (!test) {
|
|
2707
2703
|
throw new Error(`Cannot getRemoteData() on an implicit relationship`);
|
|
@@ -2737,13 +2733,13 @@ class Graph {
|
|
|
2737
2733
|
}
|
|
2738
2734
|
t2[type1] = true;
|
|
2739
2735
|
}
|
|
2740
|
-
isReleasable(
|
|
2741
|
-
const relationships = this.identifiers.get(
|
|
2736
|
+
isReleasable(resourceKey) {
|
|
2737
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2742
2738
|
if (!relationships) {
|
|
2743
2739
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2744
2740
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2745
2741
|
// eslint-disable-next-line no-console
|
|
2746
|
-
console.log(`graph: RELEASABLE ${String(
|
|
2742
|
+
console.log(`graph: RELEASABLE ${String(resourceKey)}`);
|
|
2747
2743
|
}
|
|
2748
2744
|
}
|
|
2749
2745
|
return true;
|
|
@@ -2761,11 +2757,11 @@ class Graph {
|
|
|
2761
2757
|
throw new Error(`Expected a relationship`);
|
|
2762
2758
|
}
|
|
2763
2759
|
})(relationship) : {};
|
|
2764
|
-
if (relationship.definition.inverseIsAsync && !
|
|
2760
|
+
if (relationship.definition.inverseIsAsync && !checkIfNew(this._realStore, resourceKey)) {
|
|
2765
2761
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2766
2762
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2767
2763
|
// eslint-disable-next-line no-console
|
|
2768
|
-
console.log(`graph: <<NOT>> RELEASABLE ${String(
|
|
2764
|
+
console.log(`graph: <<NOT>> RELEASABLE ${String(resourceKey)}`);
|
|
2769
2765
|
}
|
|
2770
2766
|
}
|
|
2771
2767
|
return false;
|
|
@@ -2774,19 +2770,19 @@ class Graph {
|
|
|
2774
2770
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2775
2771
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2776
2772
|
// eslint-disable-next-line no-console
|
|
2777
|
-
console.log(`graph: RELEASABLE ${String(
|
|
2773
|
+
console.log(`graph: RELEASABLE ${String(resourceKey)}`);
|
|
2778
2774
|
}
|
|
2779
2775
|
}
|
|
2780
2776
|
return true;
|
|
2781
2777
|
}
|
|
2782
|
-
unload(
|
|
2778
|
+
unload(resourceKey, silenceNotifications) {
|
|
2783
2779
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2784
2780
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2785
2781
|
// eslint-disable-next-line no-console
|
|
2786
|
-
console.log(`graph: unload ${String(
|
|
2782
|
+
console.log(`graph: unload ${String(resourceKey)}`);
|
|
2787
2783
|
}
|
|
2788
2784
|
}
|
|
2789
|
-
const relationships = this.identifiers.get(
|
|
2785
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2790
2786
|
if (relationships) {
|
|
2791
2787
|
// cleans up the graph but retains some nodes
|
|
2792
2788
|
// to allow for rematerialization
|
|
@@ -2804,8 +2800,8 @@ class Graph {
|
|
|
2804
2800
|
});
|
|
2805
2801
|
}
|
|
2806
2802
|
}
|
|
2807
|
-
_isDirty(
|
|
2808
|
-
const relationships = this.identifiers.get(
|
|
2803
|
+
_isDirty(resourceKey, field) {
|
|
2804
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2809
2805
|
if (!relationships) {
|
|
2810
2806
|
return false;
|
|
2811
2807
|
}
|
|
@@ -2822,8 +2818,8 @@ class Graph {
|
|
|
2822
2818
|
}
|
|
2823
2819
|
return false;
|
|
2824
2820
|
}
|
|
2825
|
-
getChanged(
|
|
2826
|
-
const relationships = this.identifiers.get(
|
|
2821
|
+
getChanged(resourceKey) {
|
|
2822
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2827
2823
|
const changed = new Map();
|
|
2828
2824
|
if (!relationships) {
|
|
2829
2825
|
return changed;
|
|
@@ -2861,21 +2857,21 @@ class Graph {
|
|
|
2861
2857
|
}
|
|
2862
2858
|
return changed;
|
|
2863
2859
|
}
|
|
2864
|
-
hasChanged(
|
|
2865
|
-
const relationships = this.identifiers.get(
|
|
2860
|
+
hasChanged(resourceKey) {
|
|
2861
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2866
2862
|
if (!relationships) {
|
|
2867
2863
|
return false;
|
|
2868
2864
|
}
|
|
2869
2865
|
const keys = Object.keys(relationships);
|
|
2870
2866
|
for (let i = 0; i < keys.length; i++) {
|
|
2871
|
-
if (this._isDirty(
|
|
2867
|
+
if (this._isDirty(resourceKey, keys[i])) {
|
|
2872
2868
|
return true;
|
|
2873
2869
|
}
|
|
2874
2870
|
}
|
|
2875
2871
|
return false;
|
|
2876
2872
|
}
|
|
2877
|
-
rollback(
|
|
2878
|
-
const relationships = this.identifiers.get(
|
|
2873
|
+
rollback(resourceKey) {
|
|
2874
|
+
const relationships = this.identifiers.get(resourceKey);
|
|
2879
2875
|
const changed = [];
|
|
2880
2876
|
if (!relationships) {
|
|
2881
2877
|
return changed;
|
|
@@ -2887,28 +2883,28 @@ class Graph {
|
|
|
2887
2883
|
if (!relationship) {
|
|
2888
2884
|
continue;
|
|
2889
2885
|
}
|
|
2890
|
-
if (this._isDirty(
|
|
2891
|
-
rollbackRelationship(this,
|
|
2886
|
+
if (this._isDirty(resourceKey, field)) {
|
|
2887
|
+
rollbackRelationship(this, resourceKey, field, relationship);
|
|
2892
2888
|
changed.push(field);
|
|
2893
2889
|
}
|
|
2894
2890
|
}
|
|
2895
2891
|
return changed;
|
|
2896
2892
|
}
|
|
2897
|
-
remove(
|
|
2893
|
+
remove(resourceKey) {
|
|
2898
2894
|
if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_GRAPH)) {
|
|
2899
2895
|
if (getGlobalConfig().WarpDrive.debug.LOG_GRAPH || globalThis.getWarpDriveRuntimeConfig().debug.LOG_GRAPH) {
|
|
2900
2896
|
// eslint-disable-next-line no-console
|
|
2901
|
-
console.log(`graph: remove ${String(
|
|
2897
|
+
console.log(`graph: remove ${String(resourceKey)}`);
|
|
2902
2898
|
}
|
|
2903
2899
|
}
|
|
2904
2900
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
2905
2901
|
if (!test) {
|
|
2906
|
-
throw new Error(`Cannot remove ${String(
|
|
2902
|
+
throw new Error(`Cannot remove ${String(resourceKey)} while still removing ${String(this._removing)}`);
|
|
2907
2903
|
}
|
|
2908
2904
|
})(!this._removing) : {};
|
|
2909
|
-
this._removing =
|
|
2910
|
-
this.unload(
|
|
2911
|
-
this.identifiers.delete(
|
|
2905
|
+
this._removing = resourceKey;
|
|
2906
|
+
this.unload(resourceKey);
|
|
2907
|
+
this.identifiers.delete(resourceKey);
|
|
2912
2908
|
this._removing = null;
|
|
2913
2909
|
}
|
|
2914
2910
|
|
|
@@ -3126,11 +3122,11 @@ class Graph {
|
|
|
3126
3122
|
}
|
|
3127
3123
|
}
|
|
3128
3124
|
function flushPending(graph, ops) {
|
|
3129
|
-
ops.
|
|
3130
|
-
type.
|
|
3125
|
+
for (const type of ops.values()) {
|
|
3126
|
+
for (const opList of type.values()) {
|
|
3131
3127
|
flushPendingList(graph, opList);
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3134
3130
|
}
|
|
3135
3131
|
function flushPendingList(graph, opList) {
|
|
3136
3132
|
for (let i = 0; i < opList.length; i++) {
|
|
@@ -3180,7 +3176,7 @@ function destroyRelationship(graph, rel, silenceNotifications) {
|
|
|
3180
3176
|
}
|
|
3181
3177
|
}
|
|
3182
3178
|
}
|
|
3183
|
-
function notifyInverseOfDematerialization(graph, inverseIdentifier, inverseKey,
|
|
3179
|
+
function notifyInverseOfDematerialization(graph, inverseIdentifier, inverseKey, resourceKey, silenceNotifications) {
|
|
3184
3180
|
if (!graph.has(inverseIdentifier, inverseKey)) {
|
|
3185
3181
|
return;
|
|
3186
3182
|
}
|
|
@@ -3193,8 +3189,8 @@ function notifyInverseOfDematerialization(graph, inverseIdentifier, inverseKey,
|
|
|
3193
3189
|
|
|
3194
3190
|
// For remote members, it is possible that inverseRecordData has already been associated to
|
|
3195
3191
|
// to another record. For such cases, do not dematerialize the inverseRecordData
|
|
3196
|
-
if (!isBelongsTo(relationship) || !relationship.localState ||
|
|
3197
|
-
/*#__NOINLINE__*/removeDematerializedInverse(graph, relationship,
|
|
3192
|
+
if (!isBelongsTo(relationship) || !relationship.localState || resourceKey === relationship.localState) {
|
|
3193
|
+
/*#__NOINLINE__*/removeDematerializedInverse(graph, relationship, resourceKey, silenceNotifications);
|
|
3198
3194
|
}
|
|
3199
3195
|
}
|
|
3200
3196
|
function clearRelationship(relationship) {
|
|
@@ -3214,7 +3210,7 @@ function clearRelationship(relationship) {
|
|
|
3214
3210
|
function removeDematerializedInverse(graph, relationship, inverseIdentifier, silenceNotifications) {
|
|
3215
3211
|
if (isBelongsTo(relationship)) {
|
|
3216
3212
|
const localInverse = relationship.localState;
|
|
3217
|
-
if (!relationship.definition.isAsync || localInverse &&
|
|
3213
|
+
if (!relationship.definition.isAsync || localInverse && checkIfNew(graph._realStore, localInverse)) {
|
|
3218
3214
|
// unloading inverse of a sync relationship is treated as a client-side
|
|
3219
3215
|
// delete, so actually remove the models don't merely invalidate the cp
|
|
3220
3216
|
// cache.
|
|
@@ -3227,7 +3223,7 @@ function removeDematerializedInverse(graph, relationship, inverseIdentifier, sil
|
|
|
3227
3223
|
relationship.remoteState = null;
|
|
3228
3224
|
relationship.state.hasReceivedData = true;
|
|
3229
3225
|
relationship.state.isEmpty = true;
|
|
3230
|
-
if (relationship.localState && !
|
|
3226
|
+
if (relationship.localState && !checkIfNew(graph._realStore, relationship.localState)) {
|
|
3231
3227
|
relationship.localState = null;
|
|
3232
3228
|
}
|
|
3233
3229
|
}
|
|
@@ -3238,7 +3234,7 @@ function removeDematerializedInverse(graph, relationship, inverseIdentifier, sil
|
|
|
3238
3234
|
notifyChange(graph, relationship);
|
|
3239
3235
|
}
|
|
3240
3236
|
} else {
|
|
3241
|
-
if (!relationship.definition.isAsync || inverseIdentifier &&
|
|
3237
|
+
if (!relationship.definition.isAsync || inverseIdentifier && checkIfNew(graph._realStore, inverseIdentifier)) {
|
|
3242
3238
|
// unloading inverse of a sync relationship is treated as a client-side
|
|
3243
3239
|
// delete, so actually remove the models don't merely invalidate the cp
|
|
3244
3240
|
// cache.
|