@contember/bindx 0.1.52 → 0.1.53

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 (49) hide show
  1. package/dist/core/ActionDispatcher.d.ts.map +1 -1
  2. package/dist/core/EntityLoader.d.ts +7 -0
  3. package/dist/core/EntityLoader.d.ts.map +1 -1
  4. package/dist/core/actions.d.ts +1 -2
  5. package/dist/core/actions.d.ts.map +1 -1
  6. package/dist/dataview/types.d.ts +6 -6
  7. package/dist/dataview/types.d.ts.map +1 -1
  8. package/dist/handles/EntityHandle.d.ts.map +1 -1
  9. package/dist/handles/HasManyListHandle.d.ts +8 -0
  10. package/dist/handles/HasManyListHandle.d.ts.map +1 -1
  11. package/dist/handles/HasOneHandle.d.ts.map +1 -1
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/store/HasManyStore.d.ts +94 -78
  15. package/dist/store/HasManyStore.d.ts.map +1 -1
  16. package/dist/store/RelationStore.d.ts +21 -12
  17. package/dist/store/RelationStore.d.ts.map +1 -1
  18. package/dist/store/ResponseOccurrenceIndex.d.ts +65 -0
  19. package/dist/store/ResponseOccurrenceIndex.d.ts.map +1 -0
  20. package/dist/store/SnapshotStore.d.ts +49 -14
  21. package/dist/store/SnapshotStore.d.ts.map +1 -1
  22. package/dist/store/hasManyState.d.ts +164 -0
  23. package/dist/store/hasManyState.d.ts.map +1 -0
  24. package/dist/store/relationKey.d.ts +11 -0
  25. package/dist/store/relationKey.d.ts.map +1 -1
  26. package/dist/undo/UndoJournal.d.ts.map +1 -1
  27. package/dist/undo/rekeyJournalEntry.d.ts +4 -4
  28. package/dist/undo/rekeyJournalEntry.d.ts.map +1 -1
  29. package/dist/utils/aliasGenerator.d.ts +1 -1
  30. package/dist/utils/aliasGenerator.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/core/ActionDispatcher.ts +0 -1
  33. package/src/core/EntityLoader.ts +7 -0
  34. package/src/core/actions.ts +1 -3
  35. package/src/dataview/types.ts +6 -6
  36. package/src/handles/EntityHandle.ts +11 -0
  37. package/src/handles/HasManyListHandle.ts +15 -17
  38. package/src/handles/HasOneHandle.ts +4 -2
  39. package/src/index.ts +6 -0
  40. package/src/store/HasManyStore.ts +312 -488
  41. package/src/store/RelationStore.ts +60 -24
  42. package/src/store/ResponseOccurrenceIndex.ts +224 -0
  43. package/src/store/SnapshotStore.ts +144 -73
  44. package/src/store/hasManyState.ts +408 -0
  45. package/src/store/relationKey.ts +17 -0
  46. package/src/undo/UndoJournal.ts +3 -1
  47. package/src/undo/UndoManager.ts +1 -1
  48. package/src/undo/rekeyJournalEntry.ts +31 -43
  49. package/src/utils/aliasGenerator.ts +1 -1
@@ -284,7 +284,8 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
284
284
  * Only called when parent's embedded data has changed (re-fetch detected).
285
285
  */
286
286
  private ensureItemSnapshots(listData: Array<Record<string, unknown>>): void {
287
- for (const itemData of listData) {
287
+ for (const embeddedItem of listData) {
288
+ const itemData = this.store.resolveServerOccurrence(embeddedItem)
288
289
  const itemId = itemData['id'] as string
289
290
  if (!itemId) continue
290
291
 
@@ -406,23 +407,18 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
406
407
 
407
408
  /**
408
409
  * Checks if the list is dirty (items added/removed/moved/connected/disconnected).
410
+ *
411
+ * Pending writes belong to the relation, not to this view, so a sibling view's
412
+ * unsaved change reports here too — persisting either view sends the whole
413
+ * relation, and a view claiming to be clean while pushing its sibling's writes
414
+ * would be incoherent. Only the manual ordering is this view's own.
409
415
  */
410
416
  get isDirty(): boolean {
411
417
  this.materializeEmbeddedItems()
412
418
 
413
- const state = this.store.getHasMany(
414
- this.entityType,
415
- this.entityId,
416
- this.fieldName,
417
- this.alias,
418
- )
419
-
420
- if (!state) return false
421
-
422
419
  return (
423
- state.plannedRemovals.size > 0 ||
424
- state.plannedAdditions.size > 0 ||
425
- state.orderedIds !== null
420
+ this.store.hasPendingHasManyWrites(this.entityType, this.entityId, this.fieldName)
421
+ || this.store.hasExplicitHasManyOrder(this.entityType, this.entityId, this.fieldName, this.alias)
426
422
  )
427
423
  }
428
424
 
@@ -452,7 +448,7 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
452
448
  disconnect(itemId: string): void {
453
449
  this.materializeEmbeddedItems()
454
450
  this.dispatcher.dispatch(
455
- removeFromList(this.entityType, this.entityId, this.fieldName, itemId, 'disconnect', this.alias),
451
+ removeFromList(this.entityType, this.entityId, this.fieldName, itemId, 'disconnect'),
456
452
  )
457
453
  }
458
454
 
@@ -464,7 +460,7 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
464
460
  delete(itemId: string): void {
465
461
  this.materializeEmbeddedItems()
466
462
  this.dispatcher.dispatch(
467
- removeFromList(this.entityType, this.entityId, this.fieldName, itemId, 'delete', this.alias),
463
+ removeFromList(this.entityType, this.entityId, this.fieldName, itemId, 'delete'),
468
464
  )
469
465
  }
470
466
 
@@ -503,7 +499,7 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
503
499
  remove(itemId: string): void {
504
500
  this.materializeEmbeddedItems()
505
501
  this.dispatcher.dispatch(
506
- removeFromList(this.entityType, this.entityId, this.fieldName, itemId, this.resolveRemovalType(), this.alias),
502
+ removeFromList(this.entityType, this.entityId, this.fieldName, itemId, this.resolveRemovalType()),
507
503
  )
508
504
  }
509
505
 
@@ -541,6 +537,9 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
541
537
  /**
542
538
  * Resets the has-many relation to server state.
543
539
  * Clears all planned connections and removals.
540
+ *
541
+ * Relation-level, like {@link isDirty}: planned removals carry no view, so a
542
+ * per-view reset could not know which of them to drop.
544
543
  */
545
544
  reset(): void {
546
545
  this.materializeEmbeddedItems()
@@ -548,7 +547,6 @@ export class HasManyListHandle<TEntity extends object = object, TSelected = TEnt
548
547
  this.entityType,
549
548
  this.entityId,
550
549
  this.fieldName,
551
- this.alias,
552
550
  )
553
551
  }
554
552
 
@@ -418,11 +418,13 @@ export class HasOneHandle<TEntity extends object = object, TSelected = TEntity>
418
418
  return
419
419
  }
420
420
 
421
+ const occurrence = this.store.resolveServerOccurrence(embeddedData as Record<string, unknown>)
422
+
421
423
  // Skip if embedded data values match existing serverData — avoids overwriting
422
424
  // unpersisted local mutations when a re-fetch returns the same server data
423
425
  // (e.g. polling). A new reference with identical values means no actual change.
424
426
  const existing = this.store.getEntitySnapshot(this.targetType, id)
425
- if (existing?.serverData && embeddedDataMatchesSnapshot(embeddedData as Record<string, unknown>, existing.serverData as Record<string, unknown>)) {
427
+ if (existing?.serverData && embeddedDataMatchesSnapshot(occurrence, existing.serverData as Record<string, unknown>)) {
426
428
  this.store.markEmbeddedDataPropagated(this.entityType, this.entityId, this.dataFieldName, embeddedData)
427
429
  return
428
430
  }
@@ -435,7 +437,7 @@ export class HasOneHandle<TEntity extends object = object, TSelected = TEntity>
435
437
  this.store.refreshServerData(
436
438
  this.targetType,
437
439
  id,
438
- embeddedData as Record<string, unknown>,
440
+ occurrence,
439
441
  true, // skipNotify - called during render, data already exists embedded in parent
440
442
  )
441
443
  this.store.markEmbeddedDataPropagated(this.entityType, this.entityId, this.dataFieldName, embeddedData)
package/src/index.ts CHANGED
@@ -250,6 +250,12 @@ export type {
250
250
  export type {
251
251
  StoredRelationState,
252
252
  StoredHasManyState,
253
+ HasManyView,
254
+ HasManyViewMembership,
255
+ PlannedHasManyAddition,
256
+ HasManyAdditionKind,
257
+ HasManyRelationProjection,
258
+ HasManyViewProjection,
253
259
  EntityMeta,
254
260
  } from './store/SnapshotStore.js'
255
261