@contember/bindx 0.1.49 → 0.1.50

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 (44) hide show
  1. package/dist/core/actions.d.ts +3 -3
  2. package/dist/core/actions.d.ts.map +1 -1
  3. package/dist/errors/index.d.ts +1 -1
  4. package/dist/errors/index.d.ts.map +1 -1
  5. package/dist/errors/types.d.ts +11 -0
  6. package/dist/errors/types.d.ts.map +1 -1
  7. package/dist/handles/FieldHandle.d.ts +3 -3
  8. package/dist/handles/FieldHandle.d.ts.map +1 -1
  9. package/dist/handles/types.d.ts +9 -8
  10. package/dist/handles/types.d.ts.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/persistence/BatchPersister.d.ts +6 -0
  14. package/dist/persistence/BatchPersister.d.ts.map +1 -1
  15. package/dist/store/ErrorStore.d.ts +3 -3
  16. package/dist/store/ErrorStore.d.ts.map +1 -1
  17. package/dist/store/HasManyStore.d.ts +10 -0
  18. package/dist/store/HasManyStore.d.ts.map +1 -1
  19. package/dist/store/HasOneStore.d.ts +10 -0
  20. package/dist/store/HasOneStore.d.ts.map +1 -1
  21. package/dist/store/PlannedDeleteIndex.d.ts +19 -0
  22. package/dist/store/PlannedDeleteIndex.d.ts.map +1 -0
  23. package/dist/store/RelationOwnerIndex.d.ts +8 -0
  24. package/dist/store/RelationOwnerIndex.d.ts.map +1 -0
  25. package/dist/store/RelationStore.d.ts +7 -0
  26. package/dist/store/RelationStore.d.ts.map +1 -1
  27. package/dist/store/SnapshotStore.d.ts +8 -2
  28. package/dist/store/SnapshotStore.d.ts.map +1 -1
  29. package/package.json +2 -2
  30. package/src/core/ActionDispatcher.ts +1 -1
  31. package/src/core/actions.ts +4 -4
  32. package/src/errors/index.ts +2 -0
  33. package/src/errors/types.ts +17 -0
  34. package/src/handles/FieldHandle.ts +4 -4
  35. package/src/handles/types.ts +18 -15
  36. package/src/index.ts +2 -0
  37. package/src/persistence/BatchPersister.ts +48 -0
  38. package/src/store/ErrorStore.ts +15 -12
  39. package/src/store/HasManyStore.ts +39 -3
  40. package/src/store/HasOneStore.ts +41 -3
  41. package/src/store/PlannedDeleteIndex.ts +33 -0
  42. package/src/store/RelationOwnerIndex.ts +31 -0
  43. package/src/store/RelationStore.ts +10 -0
  44. package/src/store/SnapshotStore.ts +12 -3
@@ -0,0 +1,31 @@
1
+ import { parentKeyFromRelationKey } from './relationKey.js'
2
+
3
+ export class RelationOwnerIndex {
4
+ private readonly keysByOwner = new Map<string, Set<string>>()
5
+
6
+ add(key: string): void {
7
+ const owner = parentKeyFromRelationKey(key)
8
+ let keys = this.keysByOwner.get(owner)
9
+ if (!keys) {
10
+ keys = new Set()
11
+ this.keysByOwner.set(owner, keys)
12
+ }
13
+ keys.add(key)
14
+ }
15
+
16
+ delete(key: string): void {
17
+ const owner = parentKeyFromRelationKey(key)
18
+ const keys = this.keysByOwner.get(owner)
19
+ if (!keys) return
20
+ keys.delete(key)
21
+ if (keys.size === 0) this.keysByOwner.delete(owner)
22
+ }
23
+
24
+ get(owner: string): Iterable<string> {
25
+ return this.keysByOwner.get(owner) ?? []
26
+ }
27
+
28
+ clear(): void {
29
+ this.keysByOwner.clear()
30
+ }
31
+ }
@@ -158,6 +158,16 @@ export class RelationStore implements Rekeyable {
158
158
  return this.hasMany.getHasManyOrderedIds(key)
159
159
  }
160
160
 
161
+ /**
162
+ * Whether some relation plans to delete {@link childId} through its parent's
163
+ * mutation — a has-many `delete` removal or a has-one target marked `deleted`.
164
+ * Such a row goes away with the parent's update, so the child must not be
165
+ * written on its own (see issue #91).
166
+ */
167
+ isPlannedForDeleteByParent(childId: string): boolean {
168
+ return this.hasOne.isPlannedForDelete(childId) || this.hasMany.isPlannedForDelete(childId)
169
+ }
170
+
161
171
  // ==================== Reachability / Reverse Lookup ====================
162
172
 
163
173
  /**
@@ -1,6 +1,6 @@
1
1
  import type { EntitySnapshot, LoadStatus } from './snapshots.js'
2
2
  import { createEntitySnapshot } from './snapshots.js'
3
- import type { FieldError } from '../errors/types.js'
3
+ import type { FieldError, FieldErrorFilter } from '../errors/types.js'
4
4
  import { SubscriptionManager, type SnapshotVersionBumper } from './SubscriptionManager.js'
5
5
  import { ErrorStore } from './ErrorStore.js'
6
6
  import {
@@ -577,6 +577,15 @@ export class SnapshotStore implements SnapshotVersionBumper, JournalTarget {
577
577
  return this.relations.getHasMany(key)?.plannedRemovals
578
578
  }
579
579
 
580
+ /**
581
+ * Whether some relation plans to delete {@link entityId} through its parent, i.e.
582
+ * the row goes away with the parent's update rather than with a mutation of its
583
+ * own (see issue #91).
584
+ */
585
+ isPlannedForDeleteByParent(entityId: string): boolean {
586
+ return this.relations.isPlannedForDeleteByParent(entityId)
587
+ }
588
+
580
589
  planHasManyConnection(
581
590
  parentType: string,
582
591
  parentId: string,
@@ -814,10 +823,10 @@ export class SnapshotStore implements SnapshotVersionBumper, JournalTarget {
814
823
  entityType: string,
815
824
  id: string,
816
825
  fieldName: string,
817
- source?: 'client' | 'server',
826
+ filter?: FieldErrorFilter,
818
827
  ): void {
819
828
  const key = this.getRelationKey(entityType, id, fieldName)
820
- this.errors.clearFieldErrors(key, source)
829
+ this.errors.clearFieldErrors(key, filter)
821
830
  this.notifyEntitySubscribers(this.getEntityKey(entityType, id))
822
831
  }
823
832