@contember/binding-legacy 2.1.0-alpha.1 → 2.1.0-alpha.11

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.
Files changed (42) hide show
  1. package/dist/development/src/core/DataBinding.cjs +1 -2
  2. package/dist/development/src/core/DataBinding.cjs.map +1 -1
  3. package/dist/development/src/core/DataBinding.js +1 -2
  4. package/dist/development/src/core/DataBinding.js.map +1 -1
  5. package/dist/development/src/core/MutationGenerator.cjs +118 -107
  6. package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
  7. package/dist/development/src/core/MutationGenerator.js +118 -107
  8. package/dist/development/src/core/MutationGenerator.js.map +1 -1
  9. package/dist/development/src/core/TreeAugmenter.cjs +1 -1
  10. package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
  11. package/dist/development/src/core/TreeAugmenter.js +1 -1
  12. package/dist/development/src/core/TreeAugmenter.js.map +1 -1
  13. package/dist/production/src/core/DataBinding.cjs +1 -2
  14. package/dist/production/src/core/DataBinding.cjs.map +1 -1
  15. package/dist/production/src/core/DataBinding.js +1 -2
  16. package/dist/production/src/core/DataBinding.js.map +1 -1
  17. package/dist/production/src/core/MutationGenerator.cjs +118 -107
  18. package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
  19. package/dist/production/src/core/MutationGenerator.js +118 -107
  20. package/dist/production/src/core/MutationGenerator.js.map +1 -1
  21. package/dist/production/src/core/TreeAugmenter.cjs +1 -1
  22. package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
  23. package/dist/production/src/core/TreeAugmenter.js +1 -1
  24. package/dist/production/src/core/TreeAugmenter.js.map +1 -1
  25. package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -1
  26. package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +1 -1
  27. package/dist/types/accessors/FieldAccessorImpl.d.ts.map +1 -1
  28. package/dist/types/core/DataBinding.d.ts.map +1 -1
  29. package/dist/types/core/MutationGenerator.d.ts +5 -2
  30. package/dist/types/core/MutationGenerator.d.ts.map +1 -1
  31. package/dist/types/core/factories/createBatchUpdatesOptions.d.ts.map +1 -1
  32. package/dist/types/core/state/getEntityMarker.d.ts.map +1 -1
  33. package/dist/types/core/utils/getCombinedSignal.d.ts.map +1 -1
  34. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -1
  35. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -1
  37. package/dist/types/utils/generateEnumerabilityPreventingEntropy.d.ts.map +1 -1
  38. package/dist/types/utils/isEmptyObject.d.ts.map +1 -1
  39. package/package.json +4 -4
  40. package/src/core/DataBinding.ts +1 -2
  41. package/src/core/MutationGenerator.ts +117 -122
  42. package/src/core/TreeAugmenter.ts +1 -1
@@ -36,18 +36,22 @@ export type PersistMutationResult = {
36
36
  export class MutationGenerator {
37
37
 
38
38
  private aliasCounter = 1
39
+ private processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()
40
+ private processedDeletes = new Set<string>()
39
41
 
40
- public constructor(
42
+ private constructor(
41
43
  private readonly treeStore: TreeStore,
42
44
  private readonly qb: ContentQueryBuilder,
43
45
  ) {
44
46
  }
45
47
 
46
- public getPersistMutation(): PersistMutationResult {
48
+ public static getPersistMutation(treeStore: TreeStore, qb: ContentQueryBuilder): PersistMutationResult {
49
+ return new MutationGenerator(treeStore, qb).getPersistMutation()
50
+ }
51
+
52
+ private getPersistMutation(): PersistMutationResult {
47
53
  const mutations: Record<string, ContentMutation<any>> = {}
48
54
  const operations: SubMutationOperation[] = []
49
- const processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()
50
- const processedDeletes = new Set<string>()
51
55
 
52
56
  for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {
53
57
  for (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {
@@ -59,7 +63,6 @@ export class MutationGenerator {
59
63
  continue
60
64
  }
61
65
  const subMutation = this.createMutation(
62
- processedPlaceholdersByEntity,
63
66
  placeholderName,
64
67
  'single',
65
68
  subTreeState.entity.id.value,
@@ -79,7 +82,6 @@ export class MutationGenerator {
79
82
  continue
80
83
  }
81
84
  const subMutation = this.createMutation(
82
- processedPlaceholdersByEntity,
83
85
  placeholderName,
84
86
  'list',
85
87
  childState.entity.id.value,
@@ -97,10 +99,10 @@ export class MutationGenerator {
97
99
  }
98
100
  if (removalType === 'delete') {
99
101
  const key = `${subTreeState.entityName}#${removedId}`
100
- if (processedDeletes.has(key)) {
102
+ if (this.processedDeletes.has(key)) {
101
103
  continue
102
104
  }
103
- processedDeletes.add(key)
105
+ this.processedDeletes.add(key)
104
106
  const alias = this.createAlias()
105
107
  mutations[alias] = this.createDeleteMutation(
106
108
  subTreeState.entityName,
@@ -122,7 +124,6 @@ export class MutationGenerator {
122
124
  }
123
125
 
124
126
  private createMutation(
125
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
126
127
  subTreePlaceholder: PlaceholderName,
127
128
  subTreeType: 'list' | 'single',
128
129
  entityId: EntityId,
@@ -153,7 +154,6 @@ export class MutationGenerator {
153
154
  ]
154
155
  } else if (!realmState.entity.id.existsOnServer) {
155
156
  const builder = this.createCreateMutation(
156
- processedPlaceholdersByEntity,
157
157
  realmState,
158
158
  fieldMarkers,
159
159
  )
@@ -173,7 +173,6 @@ export class MutationGenerator {
173
173
  ]
174
174
  }
175
175
  const builder = this.createUpdateMutation(
176
- processedPlaceholdersByEntity,
177
176
  realmState,
178
177
  fieldMarkers,
179
178
  )
@@ -203,11 +202,10 @@ export class MutationGenerator {
203
202
  }
204
203
 
205
204
  private createUpdateMutation(
206
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
207
205
  entityRealm: EntityRealmState,
208
206
  fieldMarkers: EntityFieldMarkers,
209
207
  ): ContentMutation<any> | undefined {
210
- const input = this.getUpdateDataInput(processedPlaceholdersByEntity, entityRealm)
208
+ const input = this.getUpdateDataInput(entityRealm)
211
209
 
212
210
  if (input === undefined) {
213
211
  return undefined
@@ -228,14 +226,10 @@ export class MutationGenerator {
228
226
  }
229
227
 
230
228
  private createCreateMutation(
231
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
232
229
  entityRealm: EntityRealmState,
233
230
  fieldMarkers: EntityFieldMarkers,
234
231
  ): ContentMutation<any> | undefined {
235
- const input = this.getCreateDataInput(
236
- processedPlaceholdersByEntity,
237
- entityRealm,
238
- )
232
+ const input = this.getCreateDataInput(entityRealm)
239
233
  if (input === undefined) {
240
234
  return undefined
241
235
  }
@@ -246,13 +240,12 @@ export class MutationGenerator {
246
240
  }
247
241
 
248
242
  private getCreateDataInput(
249
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
250
243
  currentState: EntityRealmState | EntityRealmStateStub,
251
244
  ): Input.CreateDataInput | undefined {
252
- let processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)
245
+ let processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)
253
246
 
254
247
  if (processedPlaceholders === undefined) {
255
- processedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))
248
+ this.processedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))
256
249
  }
257
250
 
258
251
  if (currentState.type === 'entityRealmStub') {
@@ -318,7 +311,7 @@ export class MutationGenerator {
318
311
  })
319
312
  continue
320
313
  }
321
- const input = this.getCreateOneRelationInput(processedPlaceholdersByEntity, fieldState, marker)
314
+ const input = this.getCreateOneRelationInput(fieldState, marker)
322
315
  if (input !== undefined) {
323
316
  const current = result[marker.parameters.field]
324
317
  if (Array.isArray(input) && Array.isArray(current)) {
@@ -345,7 +338,7 @@ export class MutationGenerator {
345
338
  })
346
339
  continue
347
340
  }
348
- const input = this.getCreateManyRelationInput(processedPlaceholdersByEntity, fieldState)
341
+ const input = this.getCreateManyRelationInput(fieldState)
349
342
  if (input !== undefined) {
350
343
  const current = result[marker.parameters.field]
351
344
  if (Array.isArray(current)) {
@@ -375,7 +368,6 @@ export class MutationGenerator {
375
368
  }
376
369
  case 'hasOne': {
377
370
  const input = this.getCreateOneRelationInput(
378
- processedPlaceholdersByEntity,
379
371
  field.fieldState,
380
372
  field.marker,
381
373
  )
@@ -391,7 +383,6 @@ export class MutationGenerator {
391
383
  }
392
384
  case 'hasMany': {
393
385
  const input = this.getCreateManyRelationInput(
394
- processedPlaceholdersByEntity,
395
386
  field.fieldState,
396
387
  )
397
388
  if (input !== undefined) {
@@ -432,7 +423,6 @@ export class MutationGenerator {
432
423
  }
433
424
 
434
425
  private getCreateOneRelationInput(
435
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
436
426
  fieldState: EntityRealmState | EntityRealmStateStub,
437
427
  marker: HasOneRelationMarker,
438
428
  ): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {
@@ -440,11 +430,11 @@ export class MutationGenerator {
440
430
  const runtimeId = fieldState.entity.id
441
431
 
442
432
  if (reducedBy === undefined) {
443
- if (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {
433
+ if (this.shouldConnectInsteadOfCreate(fieldState)) {
444
434
  return { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }
445
435
  }
446
436
 
447
- const createData = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)
437
+ const createData = this.getCreateDataInput(fieldState)
448
438
  if (createData === undefined) {
449
439
  return undefined
450
440
  }
@@ -452,32 +442,29 @@ export class MutationGenerator {
452
442
  }
453
443
 
454
444
  const alias = MutationAlias.encodeEntityId(runtimeId)
455
- if (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {
445
+ if (this.shouldConnectInsteadOfCreate(fieldState)) {
456
446
  // TODO also potentially update
457
447
  return [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]
458
448
  }
459
- const createData = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)
449
+ const createData = this.getCreateDataInput(fieldState)
460
450
  if (createData === undefined) {
461
451
  return undefined
462
452
  }
463
453
  return [{ create: createData, alias }]
464
454
  }
465
455
 
466
- private getCreateManyRelationInput(
467
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
468
- fieldState: EntityListState,
469
- ): Input.CreateManyRelationInput | undefined {
456
+ private getCreateManyRelationInput(fieldState: EntityListState): Input.CreateManyRelationInput | undefined {
470
457
  const result: Input.CreateManyRelationInput = []
471
458
  for (const entityRealm of fieldState.children.values()) {
472
459
  const runtimeId = entityRealm.entity.id
473
460
  const alias = MutationAlias.encodeEntityId(runtimeId)
474
- if (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, entityRealm)) {
461
+ if (this.shouldConnectInsteadOfCreate(entityRealm)) {
475
462
  result.push({
476
463
  alias,
477
464
  connect: { [PRIMARY_KEY_NAME]: runtimeId.value },
478
465
  })
479
466
  } else {
480
- const createData = this.getCreateDataInput(processedPlaceholdersByEntity, entityRealm)
467
+ const createData = this.getCreateDataInput(entityRealm)
481
468
  if (createData === undefined) {
482
469
  continue
483
470
  }
@@ -490,24 +477,18 @@ export class MutationGenerator {
490
477
  return result.length === 0 ? undefined : result
491
478
  }
492
479
 
493
- private shouldConnectInsteadOfCreate(
494
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
495
- currentState: EntityRealmState | EntityRealmStateStub,
496
- ): boolean {
480
+ private shouldConnectInsteadOfCreate(currentState: EntityRealmState | EntityRealmStateStub): boolean {
497
481
  const runtimeId = currentState.entity.id
498
- const processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)
482
+ const processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)
499
483
 
500
484
  return runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))
501
485
  }
502
486
 
503
- private getUpdateDataInput(
504
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
505
- currentState: EntityRealmState,
506
- ): Input.UpdateDataInput | undefined {
507
- let processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)
487
+ private getUpdateDataInput(currentState: EntityRealmState): Input.UpdateDataInput | undefined {
488
+ let processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)
508
489
 
509
490
  if (processedPlaceholders === undefined) {
510
- processedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))
491
+ this.processedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))
511
492
  }
512
493
 
513
494
  const pathBack = this.treeStore.getPathBackToParent(currentState)
@@ -515,48 +496,75 @@ export class MutationGenerator {
515
496
 
516
497
  const result: Input.UpdateDataInput = {}
517
498
 
518
- for (const [placeholderName, fieldState] of currentState.children) {
519
- if (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {
520
- continue
521
- }
522
- if (processedPlaceholders.has(placeholderName)) {
523
- continue
524
- }
525
- processedPlaceholders.add(placeholderName)
499
+ for (const siblingState of StateIterator.eachSiblingRealm(currentState)) {
500
+ for (const [placeholderName, fieldState] of siblingState.children) {
501
+ if (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {
502
+ continue
503
+ }
504
+ if (processedPlaceholders.has(placeholderName)) {
505
+ continue
506
+ }
507
+ processedPlaceholders.add(placeholderName)
526
508
 
527
- switch (fieldState.type) {
528
- case 'field': {
529
- if (fieldState.persistedValue !== undefined) {
530
- const accessor = fieldState.getAccessor()
531
- const resolvedValue = accessor.value ?? accessor.defaultValue ?? null
532
- if (fieldState.persistedValue !== resolvedValue) {
533
- result[placeholderName] = resolvedValue
509
+ switch (fieldState.type) {
510
+ case 'field': {
511
+ if (fieldState.persistedValue !== undefined) {
512
+ const accessor = fieldState.getAccessor()
513
+ const resolvedValue = accessor.value ?? accessor.defaultValue ?? null
514
+ if (fieldState.persistedValue !== resolvedValue) {
515
+ result[placeholderName] = resolvedValue
516
+ }
534
517
  }
518
+ break
535
519
  }
536
- break
537
- }
538
- case 'entityRealmStub':
539
- case 'entityRealm': {
540
- const marker = getEntityMarker(fieldState)
541
- if (!(marker instanceof HasOneRelationMarker)) {
542
- throw new BindingError()
543
- }
544
- if (pathBack?.fieldBackToParent === marker.parameters.field) {
545
- continue
546
- }
547
- const reducedBy = marker.parameters.reducedBy
520
+ case 'entityRealmStub':
521
+ case 'entityRealm': {
522
+ const marker = getEntityMarker(fieldState)
523
+ if (!(marker instanceof HasOneRelationMarker)) {
524
+ throw new BindingError()
525
+ }
526
+ if (pathBack?.fieldBackToParent === marker.parameters.field) {
527
+ continue
528
+ }
529
+ const reducedBy = marker.parameters.reducedBy
548
530
 
549
- const persistedValue = entityData?.get?.(placeholderName)?.value
550
- if (reducedBy === undefined) {
531
+ const persistedValue = entityData?.get?.(placeholderName)?.value
532
+ if (reducedBy === undefined) {
551
533
 
552
- const relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName)
553
- if (relationData !== undefined) {
554
- result[marker.parameters.field] = relationData
555
- }
534
+ const relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName)
535
+ if (relationData !== undefined) {
536
+ result[marker.parameters.field] = relationData
537
+ }
556
538
 
557
539
 
558
- } else {
559
- const relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName, reducedBy)
540
+ } else {
541
+ const relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy)
542
+ if (relationData !== undefined) {
543
+ const current = result[marker.parameters.field]
544
+ if (Array.isArray(current)) {
545
+ current.push(...relationData)
546
+ } else {
547
+ result[marker.parameters.field] = relationData
548
+ }
549
+ }
550
+
551
+ }
552
+ break
553
+ }
554
+ case 'entityList': {
555
+ const marker = fieldState.blueprint.marker
556
+ if (!(marker instanceof HasManyRelationMarker)) {
557
+ throw new BindingError()
558
+ }
559
+ if (pathBack?.fieldBackToParent === marker.parameters.field) {
560
+ continue
561
+ }
562
+ const persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? new Set()
563
+
564
+ if (!(persistedEntityIds instanceof Set)) {
565
+ continue
566
+ }
567
+ const relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds)
560
568
  if (relationData !== undefined) {
561
569
  const current = result[marker.parameters.field]
562
570
  if (Array.isArray(current)) {
@@ -565,36 +573,11 @@ export class MutationGenerator {
565
573
  result[marker.parameters.field] = relationData
566
574
  }
567
575
  }
568
-
569
- }
570
- break
571
- }
572
- case 'entityList': {
573
- const marker = fieldState.blueprint.marker
574
- if (!(marker instanceof HasManyRelationMarker)) {
575
- throw new BindingError()
576
- }
577
- if (pathBack?.fieldBackToParent === marker.parameters.field) {
578
- continue
579
- }
580
- const persistedEntityIds = entityData?.get?.(placeholderName)?.value ?? new Set()
581
-
582
- if (!(persistedEntityIds instanceof Set)) {
583
- continue
584
- }
585
- const relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds, processedPlaceholdersByEntity)
586
- if (relationData !== undefined) {
587
- const current = result[marker.parameters.field]
588
- if (Array.isArray(current)) {
589
- current.push(...relationData)
590
- } else {
591
- result[marker.parameters.field] = relationData
592
- }
576
+ break
593
577
  }
594
- break
578
+ default:
579
+ return assertNever(fieldState)
595
580
  }
596
- default:
597
- return assertNever(fieldState)
598
581
  }
599
582
  }
600
583
 
@@ -605,7 +588,6 @@ export class MutationGenerator {
605
588
  currentState: EntityRealmState,
606
589
  fieldState: EntityRealmState | EntityRealmStateStub,
607
590
  persistedValue: EntityFieldPersistedValue | undefined,
608
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
609
591
  placeholderName: PlaceholderName,
610
592
  ): Input.UpdateOneRelationInput | undefined {
611
593
  const runtimeId = fieldState.entity.id
@@ -615,7 +597,7 @@ export class MutationGenerator {
615
597
  if (fieldState.type === 'entityRealmStub') {
616
598
  return undefined// …unless we're dealing with a stub. There cannot be any updates there.
617
599
  }
618
- const input = this.getUpdateDataInput(processedPlaceholdersByEntity, fieldState)
600
+ const input = this.getUpdateDataInput(fieldState)
619
601
  if (input === undefined) {
620
602
  return undefined
621
603
  }
@@ -628,6 +610,12 @@ export class MutationGenerator {
628
610
 
629
611
  const plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)
630
612
  if (plannedDeletion !== undefined) {
613
+ const key = `${persistedValue.entityName}#${persistedValue.value}`
614
+ if (this.processedDeletes.has(key)) {
615
+ return undefined
616
+ }
617
+ this.processedDeletes.add(key)
618
+
631
619
  // It's planned for deletion.
632
620
  // TODO also potentially do something about the current entity
633
621
  return {
@@ -643,7 +631,7 @@ export class MutationGenerator {
643
631
 
644
632
  }
645
633
  // The currently present entity doesn't exist on the server. Try if creating yields anything…
646
- const createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)
634
+ const createInput = this.getCreateDataInput(fieldState)
647
635
  if (createInput !== undefined) {
648
636
  return {
649
637
  create: createInput,
@@ -662,7 +650,7 @@ export class MutationGenerator {
662
650
  connect: { [PRIMARY_KEY_NAME]: runtimeId.value },
663
651
  }
664
652
  } else {
665
- const input = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)
653
+ const input = this.getCreateDataInput(fieldState)
666
654
  if (input === undefined) {
667
655
  return undefined
668
656
  }
@@ -676,7 +664,6 @@ export class MutationGenerator {
676
664
  currentState: EntityRealmState,
677
665
  fieldState: EntityRealmState | EntityRealmStateStub,
678
666
  persistedValue: EntityFieldPersistedValue | undefined,
679
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
680
667
  placeholderName: PlaceholderName,
681
668
  reducedBy: UniqueWhere,
682
669
  ): Input.UpdateManyRelationInput | undefined {
@@ -689,7 +676,7 @@ export class MutationGenerator {
689
676
  if (fieldState.type === 'entityRealmStub') {
690
677
  return undefined
691
678
  }
692
- const updateData = this.getUpdateDataInput(processedPlaceholdersByEntity, fieldState)
679
+ const updateData = this.getUpdateDataInput(fieldState)
693
680
  if (updateData === undefined) {
694
681
  return undefined
695
682
  }
@@ -703,7 +690,11 @@ export class MutationGenerator {
703
690
  }
704
691
  const plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)
705
692
  if (plannedDeletion !== undefined) {
706
- // TODO also potentially do something about the current entity
693
+ const key = `${persistedValue.entityName}#${persistedValue.value}`
694
+ if (this.processedDeletes.has(key)) {
695
+ return undefined
696
+ }
697
+ this.processedDeletes.add(key)
707
698
  return [{
708
699
  alias,
709
700
  delete: reducedBy,
@@ -723,7 +714,7 @@ export class MutationGenerator {
723
714
  },
724
715
  ]
725
716
  }
726
- const createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)
717
+ const createInput = this.getCreateDataInput(fieldState)
727
718
 
728
719
  if (createInput === undefined) {
729
720
  return [{
@@ -741,7 +732,7 @@ export class MutationGenerator {
741
732
  connect: { [PRIMARY_KEY_NAME]: runtimeId.value },
742
733
  }]
743
734
  } else {
744
- const createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)
735
+ const createInput = this.getCreateDataInput(fieldState)
745
736
  if (createInput === undefined) {
746
737
  return undefined
747
738
  }
@@ -755,7 +746,6 @@ export class MutationGenerator {
755
746
  private getUpdateManyRelationInput(
756
747
  fieldState: EntityListState,
757
748
  persistedEntityIds: Set<EntityId>,
758
- processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,
759
749
  ): Input.UpdateManyRelationInput | undefined {
760
750
 
761
751
  const input: Input.UpdateManyRelationInput = []
@@ -766,7 +756,7 @@ export class MutationGenerator {
766
756
  if (runtimeId.existsOnServer) {
767
757
  if (persistedEntityIds.has(runtimeId.value)) {
768
758
  if (childState.type !== 'entityRealmStub') {
769
- const dataInput = this.getUpdateDataInput(processedPlaceholdersByEntity, childState)
759
+ const dataInput = this.getUpdateDataInput(childState)
770
760
 
771
761
  if (dataInput !== undefined) {
772
762
  input.push({
@@ -785,7 +775,7 @@ export class MutationGenerator {
785
775
  })
786
776
  }
787
777
  } else {
788
- const dataInput = this.getCreateDataInput(processedPlaceholdersByEntity, childState)
778
+ const dataInput = this.getCreateDataInput(childState)
789
779
  if (dataInput !== undefined) {
790
780
  input.push({
791
781
  alias,
@@ -798,6 +788,11 @@ export class MutationGenerator {
798
788
  for (const [removedId, removalType] of fieldState.plannedRemovals) {
799
789
  const alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))
800
790
  if (removalType === 'delete') {
791
+ const key = `${fieldState.entityName}#${removedId}`
792
+ if (this.processedDeletes.has(key)) {
793
+ continue
794
+ }
795
+ this.processedDeletes.add(key)
801
796
 
802
797
  input.push({
803
798
  alias,
@@ -178,7 +178,7 @@ export class TreeAugmenter {
178
178
  }
179
179
 
180
180
  if (child.persistedValue !== childData) {
181
- const shouldChangeBothValues = child.persistedValue === child.value
181
+ const shouldChangeBothValues = (child.persistedValue ?? null) === child.value
182
182
 
183
183
  child.persistedValue = childData
184
184
  if (shouldChangeBothValues) {