@contember/binding-legacy 2.1.0-alpha.1 → 2.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/core/DataBinding.cjs +1 -2
- package/dist/development/src/core/DataBinding.cjs.map +1 -1
- package/dist/development/src/core/DataBinding.js +1 -2
- package/dist/development/src/core/DataBinding.js.map +1 -1
- package/dist/development/src/core/MutationGenerator.cjs +118 -107
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/src/core/MutationGenerator.js +118 -107
- package/dist/development/src/core/MutationGenerator.js.map +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/development/src/core/TreeAugmenter.js +1 -1
- package/dist/development/src/core/TreeAugmenter.js.map +1 -1
- package/dist/production/src/core/DataBinding.cjs +1 -2
- package/dist/production/src/core/DataBinding.cjs.map +1 -1
- package/dist/production/src/core/DataBinding.js +1 -2
- package/dist/production/src/core/DataBinding.js.map +1 -1
- package/dist/production/src/core/MutationGenerator.cjs +118 -107
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/src/core/MutationGenerator.js +118 -107
- package/dist/production/src/core/MutationGenerator.js.map +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/production/src/core/TreeAugmenter.js +1 -1
- package/dist/production/src/core/TreeAugmenter.js.map +1 -1
- package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +1 -1
- package/dist/types/accessors/FieldAccessorImpl.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts +5 -2
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +1 -1
- package/dist/types/core/state/getEntityMarker.d.ts.map +1 -1
- package/dist/types/core/utils/getCombinedSignal.d.ts.map +1 -1
- package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -1
- package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +1 -1
- package/dist/types/utils/isEmptyObject.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/DataBinding.ts +1 -2
- package/src/core/MutationGenerator.ts +117 -122
- package/src/core/TreeAugmenter.ts +1 -1
|
@@ -6,18 +6,21 @@ import { StateIterator } from "./state/StateIterator.js";
|
|
|
6
6
|
import { MutationAlias } from "./requestAliases/MutationAlias.js";
|
|
7
7
|
var __defProp = Object.defineProperty;
|
|
8
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
10
|
class MutationGenerator {
|
|
11
11
|
constructor(treeStore, qb) {
|
|
12
12
|
this.treeStore = treeStore;
|
|
13
13
|
this.qb = qb;
|
|
14
14
|
__publicField(this, "aliasCounter", 1);
|
|
15
|
+
__publicField(this, "processedPlaceholdersByEntity", /* @__PURE__ */ new Map());
|
|
16
|
+
__publicField(this, "processedDeletes", /* @__PURE__ */ new Set());
|
|
17
|
+
}
|
|
18
|
+
static getPersistMutation(treeStore, qb) {
|
|
19
|
+
return new MutationGenerator(treeStore, qb).getPersistMutation();
|
|
15
20
|
}
|
|
16
21
|
getPersistMutation() {
|
|
17
22
|
const mutations = {};
|
|
18
23
|
const operations = [];
|
|
19
|
-
const processedPlaceholdersByEntity = /* @__PURE__ */ new Map();
|
|
20
|
-
const processedDeletes = /* @__PURE__ */ new Set();
|
|
21
24
|
for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {
|
|
22
25
|
for (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {
|
|
23
26
|
if (subTreeState.unpersistedChangesCount <= 0) {
|
|
@@ -28,7 +31,6 @@ class MutationGenerator {
|
|
|
28
31
|
continue;
|
|
29
32
|
}
|
|
30
33
|
const subMutation = this.createMutation(
|
|
31
|
-
processedPlaceholdersByEntity,
|
|
32
34
|
placeholderName,
|
|
33
35
|
"single",
|
|
34
36
|
subTreeState.entity.id.value,
|
|
@@ -47,7 +49,6 @@ class MutationGenerator {
|
|
|
47
49
|
continue;
|
|
48
50
|
}
|
|
49
51
|
const subMutation = this.createMutation(
|
|
50
|
-
processedPlaceholdersByEntity,
|
|
51
52
|
placeholderName,
|
|
52
53
|
"list",
|
|
53
54
|
childState.entity.id.value,
|
|
@@ -65,10 +66,10 @@ class MutationGenerator {
|
|
|
65
66
|
}
|
|
66
67
|
if (removalType === "delete") {
|
|
67
68
|
const key = `${subTreeState.entityName}#${removedId}`;
|
|
68
|
-
if (processedDeletes.has(key)) {
|
|
69
|
+
if (this.processedDeletes.has(key)) {
|
|
69
70
|
continue;
|
|
70
71
|
}
|
|
71
|
-
processedDeletes.add(key);
|
|
72
|
+
this.processedDeletes.add(key);
|
|
72
73
|
const alias = this.createAlias();
|
|
73
74
|
mutations[alias] = this.createDeleteMutation(
|
|
74
75
|
subTreeState.entityName,
|
|
@@ -87,7 +88,7 @@ class MutationGenerator {
|
|
|
87
88
|
}
|
|
88
89
|
return { mutations, operations };
|
|
89
90
|
}
|
|
90
|
-
createMutation(
|
|
91
|
+
createMutation(subTreePlaceholder, subTreeType, entityId, realmState) {
|
|
91
92
|
if (realmState.unpersistedChangesCount === 0) {
|
|
92
93
|
return void 0;
|
|
93
94
|
}
|
|
@@ -110,7 +111,6 @@ class MutationGenerator {
|
|
|
110
111
|
];
|
|
111
112
|
} else if (!realmState.entity.id.existsOnServer) {
|
|
112
113
|
const builder2 = this.createCreateMutation(
|
|
113
|
-
processedPlaceholdersByEntity,
|
|
114
114
|
realmState,
|
|
115
115
|
fieldMarkers
|
|
116
116
|
);
|
|
@@ -130,7 +130,6 @@ class MutationGenerator {
|
|
|
130
130
|
];
|
|
131
131
|
}
|
|
132
132
|
const builder = this.createUpdateMutation(
|
|
133
|
-
processedPlaceholdersByEntity,
|
|
134
133
|
realmState,
|
|
135
134
|
fieldMarkers
|
|
136
135
|
);
|
|
@@ -154,8 +153,8 @@ class MutationGenerator {
|
|
|
154
153
|
by: { [PRIMARY_KEY_NAME]: deletedId }
|
|
155
154
|
}, (it) => it.$(PRIMARY_KEY_NAME).$("__typename"));
|
|
156
155
|
}
|
|
157
|
-
createUpdateMutation(
|
|
158
|
-
const input = this.getUpdateDataInput(
|
|
156
|
+
createUpdateMutation(entityRealm, fieldMarkers) {
|
|
157
|
+
const input = this.getUpdateDataInput(entityRealm);
|
|
159
158
|
if (input === void 0) {
|
|
160
159
|
return void 0;
|
|
161
160
|
}
|
|
@@ -170,11 +169,8 @@ class MutationGenerator {
|
|
|
170
169
|
data: input
|
|
171
170
|
}, (it) => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$("__typename"));
|
|
172
171
|
}
|
|
173
|
-
createCreateMutation(
|
|
174
|
-
const input = this.getCreateDataInput(
|
|
175
|
-
processedPlaceholdersByEntity,
|
|
176
|
-
entityRealm
|
|
177
|
-
);
|
|
172
|
+
createCreateMutation(entityRealm, fieldMarkers) {
|
|
173
|
+
const input = this.getCreateDataInput(entityRealm);
|
|
178
174
|
if (input === void 0) {
|
|
179
175
|
return void 0;
|
|
180
176
|
}
|
|
@@ -182,10 +178,10 @@ class MutationGenerator {
|
|
|
182
178
|
data: input
|
|
183
179
|
}, (it) => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$("__typename"));
|
|
184
180
|
}
|
|
185
|
-
getCreateDataInput(
|
|
186
|
-
let processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity);
|
|
181
|
+
getCreateDataInput(currentState) {
|
|
182
|
+
let processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity);
|
|
187
183
|
if (processedPlaceholders === void 0) {
|
|
188
|
-
processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = /* @__PURE__ */ new Set());
|
|
184
|
+
this.processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = /* @__PURE__ */ new Set());
|
|
189
185
|
}
|
|
190
186
|
if (currentState.type === "entityRealmStub") {
|
|
191
187
|
return void 0;
|
|
@@ -238,7 +234,7 @@ class MutationGenerator {
|
|
|
238
234
|
});
|
|
239
235
|
continue;
|
|
240
236
|
}
|
|
241
|
-
const input = this.getCreateOneRelationInput(
|
|
237
|
+
const input = this.getCreateOneRelationInput(fieldState, marker);
|
|
242
238
|
if (input !== void 0) {
|
|
243
239
|
const current = result[marker.parameters.field];
|
|
244
240
|
if (Array.isArray(input) && Array.isArray(current)) {
|
|
@@ -265,7 +261,7 @@ class MutationGenerator {
|
|
|
265
261
|
});
|
|
266
262
|
continue;
|
|
267
263
|
}
|
|
268
|
-
const input = this.getCreateManyRelationInput(
|
|
264
|
+
const input = this.getCreateManyRelationInput(fieldState);
|
|
269
265
|
if (input !== void 0) {
|
|
270
266
|
const current = result[marker.parameters.field];
|
|
271
267
|
if (Array.isArray(current)) {
|
|
@@ -294,7 +290,6 @@ class MutationGenerator {
|
|
|
294
290
|
}
|
|
295
291
|
case "hasOne": {
|
|
296
292
|
const input = this.getCreateOneRelationInput(
|
|
297
|
-
processedPlaceholdersByEntity,
|
|
298
293
|
field.fieldState,
|
|
299
294
|
field.marker
|
|
300
295
|
);
|
|
@@ -310,7 +305,6 @@ class MutationGenerator {
|
|
|
310
305
|
}
|
|
311
306
|
case "hasMany": {
|
|
312
307
|
const input = this.getCreateManyRelationInput(
|
|
313
|
-
processedPlaceholdersByEntity,
|
|
314
308
|
field.fieldState
|
|
315
309
|
);
|
|
316
310
|
if (input !== void 0) {
|
|
@@ -342,41 +336,41 @@ class MutationGenerator {
|
|
|
342
336
|
}
|
|
343
337
|
return isEmptyObject(result) ? void 0 : result;
|
|
344
338
|
}
|
|
345
|
-
getCreateOneRelationInput(
|
|
339
|
+
getCreateOneRelationInput(fieldState, marker) {
|
|
346
340
|
const reducedBy = marker.parameters.reducedBy;
|
|
347
341
|
const runtimeId = fieldState.entity.id;
|
|
348
342
|
if (reducedBy === void 0) {
|
|
349
|
-
if (this.shouldConnectInsteadOfCreate(
|
|
343
|
+
if (this.shouldConnectInsteadOfCreate(fieldState)) {
|
|
350
344
|
return { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } };
|
|
351
345
|
}
|
|
352
|
-
const createData2 = this.getCreateDataInput(
|
|
346
|
+
const createData2 = this.getCreateDataInput(fieldState);
|
|
353
347
|
if (createData2 === void 0) {
|
|
354
348
|
return void 0;
|
|
355
349
|
}
|
|
356
350
|
return { create: createData2 };
|
|
357
351
|
}
|
|
358
352
|
const alias = MutationAlias.encodeEntityId(runtimeId);
|
|
359
|
-
if (this.shouldConnectInsteadOfCreate(
|
|
353
|
+
if (this.shouldConnectInsteadOfCreate(fieldState)) {
|
|
360
354
|
return [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }];
|
|
361
355
|
}
|
|
362
|
-
const createData = this.getCreateDataInput(
|
|
356
|
+
const createData = this.getCreateDataInput(fieldState);
|
|
363
357
|
if (createData === void 0) {
|
|
364
358
|
return void 0;
|
|
365
359
|
}
|
|
366
360
|
return [{ create: createData, alias }];
|
|
367
361
|
}
|
|
368
|
-
getCreateManyRelationInput(
|
|
362
|
+
getCreateManyRelationInput(fieldState) {
|
|
369
363
|
const result = [];
|
|
370
364
|
for (const entityRealm of fieldState.children.values()) {
|
|
371
365
|
const runtimeId = entityRealm.entity.id;
|
|
372
366
|
const alias = MutationAlias.encodeEntityId(runtimeId);
|
|
373
|
-
if (this.shouldConnectInsteadOfCreate(
|
|
367
|
+
if (this.shouldConnectInsteadOfCreate(entityRealm)) {
|
|
374
368
|
result.push({
|
|
375
369
|
alias,
|
|
376
370
|
connect: { [PRIMARY_KEY_NAME]: runtimeId.value }
|
|
377
371
|
});
|
|
378
372
|
} else {
|
|
379
|
-
const createData = this.getCreateDataInput(
|
|
373
|
+
const createData = this.getCreateDataInput(entityRealm);
|
|
380
374
|
if (createData === void 0) {
|
|
381
375
|
continue;
|
|
382
376
|
}
|
|
@@ -388,56 +382,81 @@ class MutationGenerator {
|
|
|
388
382
|
}
|
|
389
383
|
return result.length === 0 ? void 0 : result;
|
|
390
384
|
}
|
|
391
|
-
shouldConnectInsteadOfCreate(
|
|
385
|
+
shouldConnectInsteadOfCreate(currentState) {
|
|
392
386
|
const runtimeId = currentState.entity.id;
|
|
393
|
-
const processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity);
|
|
387
|
+
const processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity);
|
|
394
388
|
return runtimeId.existsOnServer || runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false);
|
|
395
389
|
}
|
|
396
|
-
getUpdateDataInput(
|
|
397
|
-
let processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity);
|
|
390
|
+
getUpdateDataInput(currentState) {
|
|
391
|
+
let processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity);
|
|
398
392
|
if (processedPlaceholders === void 0) {
|
|
399
|
-
processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = /* @__PURE__ */ new Set());
|
|
393
|
+
this.processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = /* @__PURE__ */ new Set());
|
|
400
394
|
}
|
|
401
395
|
const pathBack = this.treeStore.getPathBackToParent(currentState);
|
|
402
396
|
const entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue);
|
|
403
397
|
const result = {};
|
|
404
|
-
for (const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
processedPlaceholders.add(placeholderName);
|
|
412
|
-
switch (fieldState.type) {
|
|
413
|
-
case "field": {
|
|
414
|
-
if (fieldState.persistedValue !== void 0) {
|
|
415
|
-
const accessor = fieldState.getAccessor();
|
|
416
|
-
const resolvedValue = accessor.value ?? accessor.defaultValue ?? null;
|
|
417
|
-
if (fieldState.persistedValue !== resolvedValue) {
|
|
418
|
-
result[placeholderName] = resolvedValue;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
break;
|
|
398
|
+
for (const siblingState of StateIterator.eachSiblingRealm(currentState)) {
|
|
399
|
+
for (const [placeholderName, fieldState] of siblingState.children) {
|
|
400
|
+
if (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
if (processedPlaceholders.has(placeholderName)) {
|
|
404
|
+
continue;
|
|
422
405
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
406
|
+
processedPlaceholders.add(placeholderName);
|
|
407
|
+
switch (fieldState.type) {
|
|
408
|
+
case "field": {
|
|
409
|
+
if (fieldState.persistedValue !== void 0) {
|
|
410
|
+
const accessor = fieldState.getAccessor();
|
|
411
|
+
const resolvedValue = accessor.value ?? accessor.defaultValue ?? null;
|
|
412
|
+
if (fieldState.persistedValue !== resolvedValue) {
|
|
413
|
+
result[placeholderName] = resolvedValue;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
428
417
|
}
|
|
429
|
-
|
|
430
|
-
|
|
418
|
+
case "entityRealmStub":
|
|
419
|
+
case "entityRealm": {
|
|
420
|
+
const marker = getEntityMarker(fieldState);
|
|
421
|
+
if (!(marker instanceof HasOneRelationMarker)) {
|
|
422
|
+
throw new BindingError();
|
|
423
|
+
}
|
|
424
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
const reducedBy = marker.parameters.reducedBy;
|
|
428
|
+
const persistedValue = entityData?.get?.(placeholderName)?.value;
|
|
429
|
+
if (reducedBy === void 0) {
|
|
430
|
+
const relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName);
|
|
431
|
+
if (relationData !== void 0) {
|
|
432
|
+
result[marker.parameters.field] = relationData;
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
const relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy);
|
|
436
|
+
if (relationData !== void 0) {
|
|
437
|
+
const current = result[marker.parameters.field];
|
|
438
|
+
if (Array.isArray(current)) {
|
|
439
|
+
current.push(...relationData);
|
|
440
|
+
} else {
|
|
441
|
+
result[marker.parameters.field] = relationData;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
break;
|
|
431
446
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (relationData !== void 0) {
|
|
437
|
-
result[marker.parameters.field] = relationData;
|
|
447
|
+
case "entityList": {
|
|
448
|
+
const marker = fieldState.blueprint.marker;
|
|
449
|
+
if (!(marker instanceof HasManyRelationMarker)) {
|
|
450
|
+
throw new BindingError();
|
|
438
451
|
}
|
|
439
|
-
|
|
440
|
-
|
|
452
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
const persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? /* @__PURE__ */ new Set();
|
|
456
|
+
if (!(persistedEntityIds instanceof Set)) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds);
|
|
441
460
|
if (relationData !== void 0) {
|
|
442
461
|
const current = result[marker.parameters.field];
|
|
443
462
|
if (Array.isArray(current)) {
|
|
@@ -446,46 +465,23 @@ class MutationGenerator {
|
|
|
446
465
|
result[marker.parameters.field] = relationData;
|
|
447
466
|
}
|
|
448
467
|
}
|
|
468
|
+
break;
|
|
449
469
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
case "entityList": {
|
|
453
|
-
const marker = fieldState.blueprint.marker;
|
|
454
|
-
if (!(marker instanceof HasManyRelationMarker)) {
|
|
455
|
-
throw new BindingError();
|
|
456
|
-
}
|
|
457
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
const persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? /* @__PURE__ */ new Set();
|
|
461
|
-
if (!(persistedEntityIds instanceof Set)) {
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
|
-
const relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds, processedPlaceholdersByEntity);
|
|
465
|
-
if (relationData !== void 0) {
|
|
466
|
-
const current = result[marker.parameters.field];
|
|
467
|
-
if (Array.isArray(current)) {
|
|
468
|
-
current.push(...relationData);
|
|
469
|
-
} else {
|
|
470
|
-
result[marker.parameters.field] = relationData;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
break;
|
|
470
|
+
default:
|
|
471
|
+
return assertNever(fieldState);
|
|
474
472
|
}
|
|
475
|
-
default:
|
|
476
|
-
return assertNever(fieldState);
|
|
477
473
|
}
|
|
478
474
|
}
|
|
479
475
|
return isEmptyObject(result) ? void 0 : result;
|
|
480
476
|
}
|
|
481
|
-
getUpdateOneRelationInput(currentState, fieldState, persistedValue,
|
|
477
|
+
getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName) {
|
|
482
478
|
const runtimeId = fieldState.entity.id;
|
|
483
479
|
if (persistedValue instanceof ServerId) {
|
|
484
480
|
if (persistedValue.value === runtimeId.value) {
|
|
485
481
|
if (fieldState.type === "entityRealmStub") {
|
|
486
482
|
return void 0;
|
|
487
483
|
}
|
|
488
|
-
const input = this.getUpdateDataInput(
|
|
484
|
+
const input = this.getUpdateDataInput(fieldState);
|
|
489
485
|
if (input === void 0) {
|
|
490
486
|
return void 0;
|
|
491
487
|
}
|
|
@@ -495,6 +491,11 @@ class MutationGenerator {
|
|
|
495
491
|
}
|
|
496
492
|
const plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName);
|
|
497
493
|
if (plannedDeletion !== void 0) {
|
|
494
|
+
const key = `${persistedValue.entityName}#${persistedValue.value}`;
|
|
495
|
+
if (this.processedDeletes.has(key)) {
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
this.processedDeletes.add(key);
|
|
498
499
|
return {
|
|
499
500
|
delete: true
|
|
500
501
|
};
|
|
@@ -504,7 +505,7 @@ class MutationGenerator {
|
|
|
504
505
|
connect: { [PRIMARY_KEY_NAME]: runtimeId.value }
|
|
505
506
|
};
|
|
506
507
|
}
|
|
507
|
-
const createInput = this.getCreateDataInput(
|
|
508
|
+
const createInput = this.getCreateDataInput(fieldState);
|
|
508
509
|
if (createInput !== void 0) {
|
|
509
510
|
return {
|
|
510
511
|
create: createInput
|
|
@@ -519,7 +520,7 @@ class MutationGenerator {
|
|
|
519
520
|
connect: { [PRIMARY_KEY_NAME]: runtimeId.value }
|
|
520
521
|
};
|
|
521
522
|
} else {
|
|
522
|
-
const input = this.getCreateDataInput(
|
|
523
|
+
const input = this.getCreateDataInput(fieldState);
|
|
523
524
|
if (input === void 0) {
|
|
524
525
|
return void 0;
|
|
525
526
|
}
|
|
@@ -528,7 +529,7 @@ class MutationGenerator {
|
|
|
528
529
|
};
|
|
529
530
|
}
|
|
530
531
|
}
|
|
531
|
-
getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue,
|
|
532
|
+
getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy) {
|
|
532
533
|
const runtimeId = fieldState.entity.id;
|
|
533
534
|
const alias = MutationAlias.encodeEntityId(runtimeId);
|
|
534
535
|
if (persistedValue instanceof ServerId) {
|
|
@@ -536,7 +537,7 @@ class MutationGenerator {
|
|
|
536
537
|
if (fieldState.type === "entityRealmStub") {
|
|
537
538
|
return void 0;
|
|
538
539
|
}
|
|
539
|
-
const updateData = this.getUpdateDataInput(
|
|
540
|
+
const updateData = this.getUpdateDataInput(fieldState);
|
|
540
541
|
if (updateData === void 0) {
|
|
541
542
|
return void 0;
|
|
542
543
|
}
|
|
@@ -550,6 +551,11 @@ class MutationGenerator {
|
|
|
550
551
|
}
|
|
551
552
|
const plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName);
|
|
552
553
|
if (plannedDeletion !== void 0) {
|
|
554
|
+
const key = `${persistedValue.entityName}#${persistedValue.value}`;
|
|
555
|
+
if (this.processedDeletes.has(key)) {
|
|
556
|
+
return void 0;
|
|
557
|
+
}
|
|
558
|
+
this.processedDeletes.add(key);
|
|
553
559
|
return [{
|
|
554
560
|
alias,
|
|
555
561
|
delete: reducedBy
|
|
@@ -567,7 +573,7 @@ class MutationGenerator {
|
|
|
567
573
|
}
|
|
568
574
|
];
|
|
569
575
|
}
|
|
570
|
-
const createInput = this.getCreateDataInput(
|
|
576
|
+
const createInput = this.getCreateDataInput(fieldState);
|
|
571
577
|
if (createInput === void 0) {
|
|
572
578
|
return [{
|
|
573
579
|
alias,
|
|
@@ -584,7 +590,7 @@ class MutationGenerator {
|
|
|
584
590
|
connect: { [PRIMARY_KEY_NAME]: runtimeId.value }
|
|
585
591
|
}];
|
|
586
592
|
} else {
|
|
587
|
-
const createInput = this.getCreateDataInput(
|
|
593
|
+
const createInput = this.getCreateDataInput(fieldState);
|
|
588
594
|
if (createInput === void 0) {
|
|
589
595
|
return void 0;
|
|
590
596
|
}
|
|
@@ -594,7 +600,7 @@ class MutationGenerator {
|
|
|
594
600
|
}];
|
|
595
601
|
}
|
|
596
602
|
}
|
|
597
|
-
getUpdateManyRelationInput(fieldState, persistedEntityIds
|
|
603
|
+
getUpdateManyRelationInput(fieldState, persistedEntityIds) {
|
|
598
604
|
const input = [];
|
|
599
605
|
for (const childState of fieldState.children.values()) {
|
|
600
606
|
const runtimeId = childState.entity.id;
|
|
@@ -602,7 +608,7 @@ class MutationGenerator {
|
|
|
602
608
|
if (runtimeId.existsOnServer) {
|
|
603
609
|
if (persistedEntityIds.has(runtimeId.value)) {
|
|
604
610
|
if (childState.type !== "entityRealmStub") {
|
|
605
|
-
const dataInput = this.getUpdateDataInput(
|
|
611
|
+
const dataInput = this.getUpdateDataInput(childState);
|
|
606
612
|
if (dataInput !== void 0) {
|
|
607
613
|
input.push({
|
|
608
614
|
alias,
|
|
@@ -620,7 +626,7 @@ class MutationGenerator {
|
|
|
620
626
|
});
|
|
621
627
|
}
|
|
622
628
|
} else {
|
|
623
|
-
const dataInput = this.getCreateDataInput(
|
|
629
|
+
const dataInput = this.getCreateDataInput(childState);
|
|
624
630
|
if (dataInput !== void 0) {
|
|
625
631
|
input.push({
|
|
626
632
|
alias,
|
|
@@ -633,6 +639,11 @@ class MutationGenerator {
|
|
|
633
639
|
for (const [removedId, removalType] of fieldState.plannedRemovals) {
|
|
634
640
|
const alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName));
|
|
635
641
|
if (removalType === "delete") {
|
|
642
|
+
const key = `${fieldState.entityName}#${removedId}`;
|
|
643
|
+
if (this.processedDeletes.has(key)) {
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
this.processedDeletes.add(key);
|
|
636
647
|
input.push({
|
|
637
648
|
alias,
|
|
638
649
|
delete: { [PRIMARY_KEY_NAME]: removedId }
|