@oimdb/core 4.1.0 → 4.3.0

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/index.cjs CHANGED
@@ -31,7 +31,6 @@ __export(index_exports, {
31
31
  OIMCompositeKeyTreeWalk: () => OIMCompositeKeyTreeWalk,
32
32
  OIMComputedService: () => OIMComputedService,
33
33
  OIMComputedValueService: () => OIMComputedValueService,
34
- OIMContentChangeListenerService: () => OIMContentChangeListenerService,
35
34
  OIMDB: () => OIMDB,
36
35
  OIMDefaultValue: () => OIMDefaultValue,
37
36
  OIMDefaults: () => OIMDefaults,
@@ -47,17 +46,22 @@ __export(index_exports, {
47
46
  OIMScalarKeyTreeWalk: () => OIMScalarKeyTreeWalk,
48
47
  OIMSingleComputedService: () => OIMSingleComputedService,
49
48
  OIMSingleSlotService: () => OIMSingleSlotService,
49
+ OIMSingleSlotStoreAggregate: () => OIMSingleSlotStoreAggregate,
50
50
  OIMSingleSlotStoreService: () => OIMSingleSlotStoreService,
51
+ OIMSingleSourceTrackingComputedService: () => OIMSingleSourceTrackingComputedService,
51
52
  OIMSlotAfterIdleReleasePolicy: () => OIMSlotAfterIdleReleasePolicy,
52
53
  OIMSlotAfterUnholdReleasePolicy: () => OIMSlotAfterUnholdReleasePolicy,
53
54
  OIMSlotAfterWriteReleasePolicy: () => OIMSlotAfterWriteReleasePolicy,
54
55
  OIMSlotAtEmptyReleasePolicy: () => OIMSlotAtEmptyReleasePolicy,
55
56
  OIMSlotAtUnholdReleasePolicy: () => OIMSlotAtUnholdReleasePolicy,
56
57
  OIMSlotCollectionIndexService: () => OIMSlotCollectionIndexService,
58
+ OIMSlotCollectionIndexStoreAggregate: () => OIMSlotCollectionIndexStoreAggregate,
57
59
  OIMSlotCollectionService: () => OIMSlotCollectionService,
58
60
  OIMSlotCollectionSortedArrayIndexService: () => OIMSlotCollectionSortedArrayIndexService,
61
+ OIMSlotCollectionStoreAggregate: () => OIMSlotCollectionStoreAggregate,
59
62
  OIMSlotContentArrayBucketService: () => OIMSlotContentArrayBucketService,
60
63
  OIMSlotContentBucketService: () => OIMSlotContentBucketService,
64
+ OIMSlotContentChangeListenerService: () => OIMSlotContentChangeListenerService,
61
65
  OIMSlotContentEntityService: () => OIMSlotContentEntityService,
62
66
  OIMSlotContentPositionalArrayBucketService: () => OIMSlotContentPositionalArrayBucketService,
63
67
  OIMSlotContentSetBucketService: () => OIMSlotContentSetBucketService,
@@ -73,10 +77,13 @@ __export(index_exports, {
73
77
  OIMSlotTreeStoreService: () => OIMSlotTreeStoreService,
74
78
  OIMSlotWheel: () => OIMSlotWheel,
75
79
  OIMSortedComputedService: () => OIMSortedComputedService,
80
+ OIMSourceTrackingComputedService: () => OIMSourceTrackingComputedService,
76
81
  OIMThrowAtOnceErrorPolicy: () => OIMThrowAtOnceErrorPolicy,
77
82
  OIMUnusedSlotCollectorService: () => OIMUnusedSlotCollectorService,
78
83
  OIMWritableSingleSlotService: () => OIMWritableSingleSlotService,
84
+ OIMWritableSingleSlotStoreAggregate: () => OIMWritableSingleSlotStoreAggregate,
79
85
  OIMWritableSlotCollectionService: () => OIMWritableSlotCollectionService,
86
+ OIMWritableSlotCollectionStoreAggregate: () => OIMWritableSlotCollectionStoreAggregate,
80
87
  OIM_FROZEN_EMPTY_SLOTS: () => OIM_FROZEN_EMPTY_SLOTS,
81
88
  OIM_NOTHING_WAS_INSERTED: () => OIM_NOTHING_WAS_INSERTED,
82
89
  OIM_NOTHING_WAS_REMOVED: () => OIM_NOTHING_WAS_REMOVED,
@@ -86,17 +93,24 @@ __export(index_exports, {
86
93
  createOIMChannelSlot: () => createOIMChannelSlot,
87
94
  createOIMCollectorSlot: () => createOIMCollectorSlot,
88
95
  createOIMComputedService: () => createOIMComputedService,
89
- createOIMEntityWriterInPlace: () => createOIMEntityWriterInPlace,
90
- createOIMEntityWriterReplacing: () => createOIMEntityWriterReplacing,
96
+ createOIMInPlaceEntityWriter: () => createOIMInPlaceEntityWriter,
97
+ createOIMReplacingEntityWriter: () => createOIMReplacingEntityWriter,
91
98
  createOIMSingleComputedService: () => createOIMSingleComputedService,
92
99
  createOIMSingleSlotService: () => createOIMSingleSlotService,
100
+ createOIMSingleSlotStoreAggregate: () => createOIMSingleSlotStoreAggregate,
101
+ createOIMSingleSourceTrackingComputedService: () => createOIMSingleSourceTrackingComputedService,
93
102
  createOIMSlotCollectionIndexService: () => createOIMSlotCollectionIndexService,
94
103
  createOIMSlotCollectionService: () => createOIMSlotCollectionService,
95
104
  createOIMSlotCollectionSortedArrayIndexService: () => createOIMSlotCollectionSortedArrayIndexService,
105
+ createOIMSlotCollectionStoreAggregate: () => createOIMSlotCollectionStoreAggregate,
96
106
  createOIMSlotContentEntityService: () => createOIMSlotContentEntityService,
97
107
  createOIMSortedComputedService: () => createOIMSortedComputedService,
108
+ createOIMSourceTrackingComputedService: () => createOIMSourceTrackingComputedService,
98
109
  createOIMUnusedSlotCollectorSlot: () => createOIMUnusedSlotCollectorSlot,
99
110
  oimColumnsComparator: () => oimColumnsComparator,
111
+ oimGuardedPatchEntityColumn: () => oimGuardedPatchEntityColumn,
112
+ oimGuardedPatchEntityColumns: () => oimGuardedPatchEntityColumns,
113
+ oimGuardedPutEntityColumns: () => oimGuardedPutEntityColumns,
100
114
  oimHoldSlots: () => oimHoldSlots,
101
115
  oimInsertEntityWithCopy: () => oimInsertEntityWithCopy,
102
116
  oimInsertEntityWithSanitizedCopy: () => oimInsertEntityWithSanitizedCopy,
@@ -109,11 +123,8 @@ __export(index_exports, {
109
123
  oimMintAfterWriteSlotReleaseWheel: () => oimMintAfterWriteSlotReleaseWheel,
110
124
  oimOrderedListCommandsOfTransition: () => oimOrderedListCommandsOfTransition,
111
125
  oimPatchEntityColumn: () => oimPatchEntityColumn,
112
- oimPatchEntityColumnGuarded: () => oimPatchEntityColumnGuarded,
113
126
  oimPatchEntityColumns: () => oimPatchEntityColumns,
114
- oimPatchEntityColumnsGuarded: () => oimPatchEntityColumnsGuarded,
115
127
  oimPutEntityColumns: () => oimPutEntityColumns,
116
- oimPutEntityColumnsGuarded: () => oimPutEntityColumnsGuarded,
117
128
  oimRefreshSourceComputeds: () => oimRefreshSourceComputeds,
118
129
  oimSameKeySequence: () => oimSameKeySequence,
119
130
  oimSameSlotSequence: () => oimSameSlotSequence,
@@ -123,7 +134,7 @@ __export(index_exports, {
123
134
  });
124
135
  module.exports = __toCommonJS(index_exports);
125
136
 
126
- // src/engine/schedule/OIMFlushSchedulerService.ts
137
+ // src/schedule/OIMFlushSchedulerService.ts
127
138
  var _OIMFlushSchedulerService = class _OIMFlushSchedulerService {
128
139
  isScheduled(flushSchedulerSlot) {
129
140
  return flushSchedulerSlot.scheduledCallback !== void 0;
@@ -158,15 +169,15 @@ var _OIMFlushSchedulerService = class _OIMFlushSchedulerService {
158
169
  _OIMFlushSchedulerService.INSTANCE = new _OIMFlushSchedulerService();
159
170
  var OIMFlushSchedulerService = _OIMFlushSchedulerService;
160
171
 
161
- // src/engine/slot/constants/OIM_SLOT_FLAG_RELEASED.ts
172
+ // src/slot/constants/OIM_SLOT_FLAG_RELEASED.ts
162
173
  var OIM_SLOT_FLAG_RELEASED = 2;
163
174
 
164
- // src/engine/slot/utils/oimUnholdSlotIfAlive.ts
175
+ // src/slot/utils/oimUnholdSlotIfAlive.ts
165
176
  function oimUnholdSlotIfAlive(slot) {
166
177
  if ((slot.slotFlags & OIM_SLOT_FLAG_RELEASED) === 0) slot.owner.unholdSlot(slot);
167
178
  }
168
179
 
169
- // src/engine/collector/OIMUnusedSlotCollectorService.ts
180
+ // src/collector/OIMUnusedSlotCollectorService.ts
170
181
  var _OIMUnusedSlotCollectorService = class _OIMUnusedSlotCollectorService {
171
182
  holdSlotUntilFlush(unusedSlotCollectorSlot, slot) {
172
183
  slot.owner.holdSlot(slot);
@@ -212,16 +223,16 @@ var _OIMUnusedSlotCollectorService = class _OIMUnusedSlotCollectorService {
212
223
  _OIMUnusedSlotCollectorService.INSTANCE = new _OIMUnusedSlotCollectorService();
213
224
  var OIMUnusedSlotCollectorService = _OIMUnusedSlotCollectorService;
214
225
 
215
- // src/engine/channel/constants/OIM_REVISIONS_PER_EPOCH.ts
226
+ // src/channel/constants/OIM_REVISIONS_PER_EPOCH.ts
216
227
  var OIM_REVISIONS_PER_EPOCH = 2 ** 30;
217
228
 
218
- // src/engine/channel/utils/oimIsRevisionAfter.ts
229
+ // src/channel/utils/oimIsRevisionAfter.ts
219
230
  function oimIsRevisionAfter(revision, epoch, sinceRevision, sinceEpoch) {
220
- if (epoch !== sinceEpoch) return epoch > sinceEpoch;
231
+ if (epoch !== sinceEpoch) return (epoch - sinceEpoch | 0) > 0;
221
232
  return revision > sinceRevision;
222
233
  }
223
234
 
224
- // src/engine/channel/OIMChannelService.ts
235
+ // src/channel/OIMChannelService.ts
225
236
  var _OIMChannelService = class _OIMChannelService {
226
237
  scheduleEffectRun(channelSlot, effect) {
227
238
  channelSlot.effectChannelQueue.enqueueEntry(effect);
@@ -281,24 +292,24 @@ var _OIMChannelService = class _OIMChannelService {
281
292
  const clock = channelSlot.clock;
282
293
  if (clock.revision >= OIM_REVISIONS_PER_EPOCH - 1) {
283
294
  clock.revision = 0;
284
- clock.epoch++;
295
+ clock.epoch = clock.epoch + 1 | 0;
285
296
  } else {
286
297
  clock.revision++;
287
298
  }
288
- const dependents = slot.effects;
289
- const slotEditable = slot;
299
+ const effects = slot.effects;
300
+ const editableSlot = slot;
290
301
  const effectChannelQueue = channelSlot.effectChannelQueue;
291
302
  let owesAFrame = false;
292
- if (dependents !== void 0 && dependents.length !== 0 && !this.isChangedInCurrentFrame(channelSlot, slot)) {
293
- const owed = dependents.length;
303
+ if (effects !== void 0 && effects.length !== 0 && !this.isChangedInCurrentFrame(channelSlot, slot)) {
304
+ const owed = effects.length;
294
305
  for (let i = 0; i < owed; i++) {
295
- const dependent = dependents[i];
296
- if (dependent.effectService.markEffectRunScheduled(dependent, false)) effectChannelQueue.enqueueEntry(dependent);
306
+ const effect = effects[i];
307
+ if (effect.effectService.markEffectRunScheduled(effect, false)) effectChannelQueue.enqueueEntry(effect);
297
308
  }
298
309
  owesAFrame = true;
299
310
  }
300
- slotEditable.changedAtRevision = clock.revision;
301
- slotEditable.changedAtEpoch = clock.epoch;
311
+ editableSlot.changedAtRevision = clock.revision;
312
+ editableSlot.changedAtEpoch = clock.epoch;
302
313
  if (!owesAFrame && (channelSlot.flushRequested || channelSlot.frame.afterEachFrame.size === 0 && effectChannelQueue.getEntryCount() === 0)) return;
303
314
  if (channelSlot.timer === void 0) return;
304
315
  this.requestFlush(channelSlot);
@@ -423,7 +434,7 @@ var _OIMChannelService = class _OIMChannelService {
423
434
  _OIMChannelService.INSTANCE = new _OIMChannelService();
424
435
  var OIMChannelService = _OIMChannelService;
425
436
 
426
- // src/engine/channel/OIMChannelQueue.ts
437
+ // src/channel/OIMChannelQueue.ts
427
438
  var OIMChannelQueue = class {
428
439
  constructor() {
429
440
  this.entries = [];
@@ -457,7 +468,7 @@ var OIMChannelQueue = class {
457
468
  }
458
469
  };
459
470
 
460
- // src/engine/channel/utils/createOIMChannelSlot.ts
471
+ // src/channel/utils/createOIMChannelSlot.ts
461
472
  function createOIMChannelSlot(options) {
462
473
  return {
463
474
  timer: options.timer,
@@ -479,12 +490,12 @@ function createOIMChannelSlot(options) {
479
490
  };
480
491
  }
481
492
 
482
- // src/engine/collector/utils/createOIMUnusedSlotCollectorSlot.ts
493
+ // src/collector/utils/createOIMUnusedSlotCollectorSlot.ts
483
494
  function createOIMUnusedSlotCollectorSlot() {
484
495
  return { unusedSlotChannelQueue: new OIMChannelQueue(), openDepth: 0, isFlushing: false };
485
496
  }
486
497
 
487
- // src/engine/collector/utils/createOIMCollectorSlot.ts
498
+ // src/collector/utils/createOIMCollectorSlot.ts
488
499
  function createOIMCollectorSlot(options) {
489
500
  return {
490
501
  unusedSlotCollectorSlot: createOIMUnusedSlotCollectorSlot(),
@@ -495,18 +506,18 @@ function createOIMCollectorSlot(options) {
495
506
  };
496
507
  }
497
508
 
498
- // src/engine/schedule/constants/OIM_NOTHING_TO_DISPOSE.ts
509
+ // src/schedule/constants/OIM_NOTHING_TO_DISPOSE.ts
499
510
  var OIM_NOTHING_TO_DISPOSE = () => {
500
511
  return;
501
512
  };
502
513
 
503
- // src/engine/schedule/utils/oimTimerOfChannelScheduler.ts
514
+ // src/schedule/utils/oimTimerOfChannelScheduler.ts
504
515
  var oimTimerOfChannelScheduler = (scheduler) => (run) => {
505
516
  scheduler(run);
506
517
  return OIM_NOTHING_TO_DISPOSE;
507
518
  };
508
519
 
509
- // src/engine/schedule/constants/OIM_TIMER_ON_TIMEOUT.ts
520
+ // src/schedule/constants/OIM_TIMER_ON_TIMEOUT.ts
510
521
  var OIM_TIMER_ON_TIMEOUT = (run, inMs) => {
511
522
  const handle = setTimeout(run, inMs);
512
523
  handle.unref?.();
@@ -515,7 +526,7 @@ var OIM_TIMER_ON_TIMEOUT = (run, inMs) => {
515
526
  };
516
527
  };
517
528
 
518
- // src/engine/error/OIMLogAndContinueErrorPolicy.ts
529
+ // src/error/OIMLogAndContinueErrorPolicy.ts
519
530
  var _OIMLogAndContinueErrorPolicy = class _OIMLogAndContinueErrorPolicy {
520
531
  constructor(options) {
521
532
  this.onError = options?.onError;
@@ -528,7 +539,7 @@ var _OIMLogAndContinueErrorPolicy = class _OIMLogAndContinueErrorPolicy {
528
539
  _OIMLogAndContinueErrorPolicy.INSTANCE = new _OIMLogAndContinueErrorPolicy();
529
540
  var OIMLogAndContinueErrorPolicy = _OIMLogAndContinueErrorPolicy;
530
541
 
531
- // src/factories/OIMDB.ts
542
+ // src/db/OIMDB.ts
532
543
  var OIMDB = class {
533
544
  constructor(options) {
534
545
  this.clock = { revision: 0, epoch: 0 };
@@ -546,17 +557,13 @@ var OIMDB = class {
546
557
  timer: channelScheduler === void 0 ? void 0 : oimTimerOfChannelScheduler(channelScheduler),
547
558
  onBeforeFlush: options?.onBeforeFlush
548
559
  });
549
- this.entityWriter = options?.entityWriter;
550
- this.slotStamp = options?.slotStamp;
551
- this.slotReleasePolicy = options?.slotReleasePolicy;
552
- this.indexKeysService = options?.indexKeysService;
553
560
  }
554
561
  flush() {
555
562
  OIMChannelService.INSTANCE.flush(this.defaultChannelSlot);
556
563
  }
557
564
  };
558
565
 
559
- // src/factories/defaults/oimRegisterCoreInstance.ts
566
+ // src/db/utils/oimRegisterCoreInstance.ts
560
567
  var OIM_CORE_INSTANCE_KEY = Symbol.for("@oimdb/core");
561
568
  function oimRegisterCoreInstance(coreInstance) {
562
569
  const globalThisRecord = globalThis;
@@ -567,11 +574,11 @@ function oimRegisterCoreInstance(coreInstance) {
567
574
  }
568
575
  if (registeredCoreInstance === coreInstance) return;
569
576
  throw new Error(
570
- "@oimdb/core is loaded twice in this process \u2014 usually `import` in one place and `require` in another, or two installed copies. Each copy keeps its own OIMDefaults, so a default set through one never reaches collections built by the other. Load @oimdb/core one way everywhere, including inside every @oimdb package."
577
+ "@oimdb/core is loaded twice in this process \u2014 usually `import` in one place and `require` in another, or two installed copies. Each copy keeps its own built-in defaults and its own classes, so services built by the two copies share nothing. Load @oimdb/core one way everywhere, including inside every @oimdb package."
571
578
  );
572
579
  }
573
580
 
574
- // src/engine/slot/OIMNoStoreSlotListener.ts
581
+ // src/slot/OIMNoStoreSlotListener.ts
575
582
  var _OIMNoStoreSlotListener = class _OIMNoStoreSlotListener {
576
583
  onStoreSlotCreated() {
577
584
  return;
@@ -580,7 +587,7 @@ var _OIMNoStoreSlotListener = class _OIMNoStoreSlotListener {
580
587
  _OIMNoStoreSlotListener.INSTANCE = new _OIMNoStoreSlotListener();
581
588
  var OIMNoStoreSlotListener = _OIMNoStoreSlotListener;
582
589
 
583
- // src/engine/slot/OIMNoSlotSubscriptionListener.ts
590
+ // src/slot/OIMNoSlotSubscriptionListener.ts
584
591
  var _OIMNoSlotSubscriptionListener = class _OIMNoSlotSubscriptionListener {
585
592
  onSlotFirstSubscribed() {
586
593
  return;
@@ -592,20 +599,20 @@ var _OIMNoSlotSubscriptionListener = class _OIMNoSlotSubscriptionListener {
592
599
  _OIMNoSlotSubscriptionListener.INSTANCE = new _OIMNoSlotSubscriptionListener();
593
600
  var OIMNoSlotSubscriptionListener = _OIMNoSlotSubscriptionListener;
594
601
 
595
- // src/engine/slot/constants/OIM_SLOT_FLAG_EMPTY.ts
602
+ // src/slot/constants/OIM_SLOT_FLAG_EMPTY.ts
596
603
  var OIM_SLOT_FLAG_EMPTY = 1;
597
604
 
598
- // src/engine/slot/utils/oimIsSlotEmpty.ts
605
+ // src/slot/utils/oimIsSlotEmpty.ts
599
606
  function oimIsSlotEmpty(slot) {
600
607
  return (slot.slotFlags & OIM_SLOT_FLAG_EMPTY) !== 0;
601
608
  }
602
609
 
603
- // src/engine/slot/utils/oimIsSlotReleased.ts
610
+ // src/slot/utils/oimIsSlotReleased.ts
604
611
  function oimIsSlotReleased(slot) {
605
612
  return (slot.slotFlags & OIM_SLOT_FLAG_RELEASED) !== 0;
606
613
  }
607
614
 
608
- // src/engine/slot/utils/oimAssertSlotNotReleased.ts
615
+ // src/slot/utils/oimAssertSlotNotReleased.ts
609
616
  var oimAssertSlotNotReleased = (slot) => {
610
617
  if ((slot.slotFlags & OIM_SLOT_FLAG_RELEASED) === 0) return;
611
618
  throw new Error(
@@ -613,7 +620,7 @@ var oimAssertSlotNotReleased = (slot) => {
613
620
  );
614
621
  };
615
622
 
616
- // src/engine/slot/OIMSlotOwner.ts
623
+ // src/slot/OIMSlotOwner.ts
617
624
  var OIMSlotOwner = class {
618
625
  holdSlot(slot) {
619
626
  this.assertNotReleased(slot);
@@ -633,10 +640,10 @@ var OIMSlotOwner = class {
633
640
  }
634
641
  subscribeToSlot(slot, effect, edge) {
635
642
  this.holdSlot(slot);
636
- const slotEditable = slot;
637
- const subscribers = slotEditable.effects ?? (slotEditable.effects = []);
643
+ const editableSlot = slot;
644
+ const subscribers = editableSlot.effects ?? (editableSlot.effects = []);
638
645
  subscribers.push(effect);
639
- (slotEditable.effectEdges ?? (slotEditable.effectEdges = [])).push(edge);
646
+ (editableSlot.effectEdges ?? (editableSlot.effectEdges = [])).push(edge);
640
647
  if (subscribers.length === 1) this.onSlotFirstSubscribed(slot);
641
648
  return subscribers.length - 1;
642
649
  }
@@ -683,30 +690,30 @@ var OIMSlotOwner = class {
683
690
  }
684
691
  };
685
692
 
686
- // src/engine/column/constants/OIM_COLUMN_GROUP_KEY_SEPARATOR.ts
693
+ // src/column/constants/OIM_COLUMN_GROUP_KEY_SEPARATOR.ts
687
694
  var OIM_COLUMN_GROUP_KEY_SEPARATOR = "\0";
688
695
 
689
- // src/engine/column/utils/oimColumnGroupKeyOfColumnNames.ts
696
+ // src/column/utils/oimColumnGroupKeyOfColumnNames.ts
690
697
  function oimColumnGroupKeyOfColumnNames(sortedColumnNames) {
691
698
  return `${OIM_COLUMN_GROUP_KEY_SEPARATOR}${sortedColumnNames.join(OIM_COLUMN_GROUP_KEY_SEPARATOR)}`;
692
699
  }
693
700
 
694
- // src/engine/column/constants/OIM_ANY_COLUMN_KEY.ts
701
+ // src/column/constants/OIM_ANY_COLUMN_KEY.ts
695
702
  var OIM_ANY_COLUMN_KEY = OIM_COLUMN_GROUP_KEY_SEPARATOR;
696
703
 
697
- // src/engine/column/utils/oimColumnNamesOfKey.ts
704
+ // src/column/utils/oimColumnNamesOfKey.ts
698
705
  function oimColumnNamesOfKey(columnKey) {
699
706
  if (!columnKey.startsWith(OIM_COLUMN_GROUP_KEY_SEPARATOR)) return [columnKey];
700
707
  const joinedColumnNames = columnKey.slice(OIM_COLUMN_GROUP_KEY_SEPARATOR.length);
701
708
  return joinedColumnNames === "" ? [] : joinedColumnNames.split(OIM_COLUMN_GROUP_KEY_SEPARATOR);
702
709
  }
703
710
 
704
- // src/engine/slot/utils/oimMarkSlotReleased.ts
711
+ // src/slot/utils/oimMarkSlotReleased.ts
705
712
  function oimMarkSlotReleased(slot) {
706
713
  slot.slotFlags |= OIM_SLOT_FLAG_RELEASED;
707
714
  }
708
715
 
709
- // src/engine/column/OIMColumnSlotOwner.ts
716
+ // src/column/OIMColumnSlotOwner.ts
710
717
  var OIMColumnSlotOwner = class extends OIMSlotOwner {
711
718
  constructor(columnSlotStoreService) {
712
719
  super();
@@ -811,8 +818,8 @@ var OIMColumnSlotOwner = class extends OIMSlotOwner {
811
818
  }
812
819
  fileColumnSlot(carrierSlot, key) {
813
820
  const columnSlotStoreService = this.columnSlotStoreService;
814
- const carrierSlotEditable = carrierSlot;
815
- const columnSlotStore = carrierSlotEditable.columnSlotStore ?? (carrierSlotEditable.columnSlotStore = columnSlotStoreService.createStore());
821
+ const editableCarrierSlot = carrierSlot;
822
+ const columnSlotStore = editableCarrierSlot.columnSlotStore ?? (editableCarrierSlot.columnSlotStore = columnSlotStoreService.createStore());
816
823
  const columnSlot = this.createColumnSlot(carrierSlot, key);
817
824
  columnSlotStoreService.set(columnSlotStore, key, columnSlot);
818
825
  return columnSlot;
@@ -870,7 +877,7 @@ function forgetColumnReadersIfUnread(storeSlot, columnName, columnReaders) {
870
877
  storeSlot.columnReadersByColumnName.delete(columnName);
871
878
  }
872
879
 
873
- // src/engine/column/OIMColumnSlotOrdinalStoreService.ts
880
+ // src/column/OIMColumnSlotOrdinalStoreService.ts
874
881
  var OIMColumnSlotOrdinalStoreService = class {
875
882
  constructor(options) {
876
883
  this.ordinalsByColumnName = /* @__PURE__ */ new Map();
@@ -936,19 +943,19 @@ var OIMColumnSlotOrdinalStoreService = class {
936
943
  }
937
944
  };
938
945
 
939
- // src/engine/column/utils/oimColumnSlotStoreServiceOfColumnOwnerOptions.ts
940
- function oimColumnSlotStoreServiceOfColumnOwnerOptions(columnSlotOwnerOptions) {
946
+ // src/column/utils/oimColumnSlotStoreServiceOfColumnSlotOwnerOptions.ts
947
+ function oimColumnSlotStoreServiceOfColumnSlotOwnerOptions(columnSlotOwnerOptions) {
941
948
  if (columnSlotOwnerOptions.columnNames !== void 0) {
942
949
  return new OIMColumnSlotOrdinalStoreService({ columnNames: columnSlotOwnerOptions.columnNames });
943
950
  }
944
951
  return columnSlotOwnerOptions.columnSlotStoreService;
945
952
  }
946
953
 
947
- // src/engine/computed/constants/OIM_FROZEN_EMPTY_COMPUTED_SLOTS.ts
954
+ // src/computed/constants/OIM_FROZEN_EMPTY_COMPUTED_SLOTS.ts
948
955
  var OIM_FROZEN_EMPTY_COMPUTED_SLOTS = Object.freeze([]);
949
956
 
950
- // src/engine/computed/utils/createOIMComputedSlot.ts
951
- function createOIMComputedSlot(key, owner, computedValueService, initialValue, storeSlot = void 0) {
957
+ // src/computed/utils/createOIMComputedSlot.ts
958
+ function createOIMComputedSlot(key, owner, computedValueService, initialValue, storeSlot, sourceTracker) {
952
959
  return {
953
960
  effects: void 0,
954
961
  changedAtRevision: 0,
@@ -973,11 +980,12 @@ function createOIMComputedSlot(key, owner, computedValueService, initialValue, s
973
980
  checkedAtRevision: -1,
974
981
  checkedAtEpoch: -1,
975
982
  isDeriving: false,
976
- allRootSlots: void 0
983
+ allRootSlots: void 0,
984
+ sourceTracker
977
985
  };
978
986
  }
979
987
 
980
- // src/engine/computed/utils/oimRefreshSourceComputeds.ts
988
+ // src/computed/utils/oimRefreshSourceComputeds.ts
981
989
  function oimRefreshSourceComputeds(sourceComputeds) {
982
990
  for (let i = 0; i < sourceComputeds.length; i++) {
983
991
  const sourceComputedSlot = sourceComputeds[i];
@@ -985,7 +993,7 @@ function oimRefreshSourceComputeds(sourceComputeds) {
985
993
  }
986
994
  }
987
995
 
988
- // src/engine/channel/utils/oimIsAnySlotChangedAfter.ts
996
+ // src/channel/utils/oimIsAnySlotChangedAfter.ts
989
997
  function oimIsAnySlotChangedAfter(slots, revision, epoch) {
990
998
  for (let i = 0; i < slots.length; i++) {
991
999
  const slot = slots[i];
@@ -994,52 +1002,67 @@ function oimIsAnySlotChangedAfter(slots, revision, epoch) {
994
1002
  return false;
995
1003
  }
996
1004
 
997
- // src/engine/computed/utils/oimHasSourceChangedSinceLastRun.ts
1005
+ // src/computed/utils/oimHasSourceChangedSinceLastRun.ts
998
1006
  function oimHasSourceChangedSinceLastRun(derivation) {
999
1007
  return oimIsAnySlotChangedAfter(derivation.sourceComputeds, derivation.ranAtRevision, derivation.ranAtEpoch) || oimIsAnySlotChangedAfter(derivation.sourceSlots, derivation.ranAtRevision, derivation.ranAtEpoch);
1000
1008
  }
1001
1009
 
1002
- // src/engine/computed/utils/oimRefreshComputedSlot.ts
1003
- function oimRefreshComputedSlot(computedSlot, derive, sameValueGuard, channelClock) {
1010
+ // src/computed/utils/oimRefreshComputedSlot.ts
1011
+ function oimRefreshComputedSlot(computedSlot, derive, sameValueGuard, releaseValue, channelClock) {
1004
1012
  if (computedSlot.isDeriving) return;
1005
1013
  if (computedSlot.checkedAtRevision === channelClock.revision && computedSlot.checkedAtEpoch === channelClock.epoch) return;
1006
- const computedSlotEditable = computedSlot;
1014
+ const editableComputedSlot = computedSlot;
1007
1015
  oimRefreshSourceComputeds(computedSlot.sourceComputeds);
1008
1016
  if (computedSlot.ranAtRevision !== -1 && !oimHasSourceChangedSinceLastRun(computedSlot)) {
1009
- computedSlotEditable.checkedAtRevision = channelClock.revision;
1010
- computedSlotEditable.checkedAtEpoch = channelClock.epoch;
1017
+ editableComputedSlot.checkedAtRevision = channelClock.revision;
1018
+ editableComputedSlot.checkedAtEpoch = channelClock.epoch;
1011
1019
  return;
1012
1020
  }
1013
- computedSlotEditable.isDeriving = true;
1021
+ const hasDerived = computedSlot.ranAtRevision !== -1;
1022
+ editableComputedSlot.isDeriving = true;
1014
1023
  let next;
1015
1024
  try {
1016
1025
  next = derive(computedSlot);
1017
1026
  } finally {
1018
- computedSlotEditable.isDeriving = false;
1019
- }
1020
- const isSameValue = sameValueGuard(computedSlot.value, next);
1021
- computedSlotEditable.ranAtRevision = channelClock.revision;
1022
- computedSlotEditable.ranAtEpoch = channelClock.epoch;
1023
- computedSlotEditable.checkedAtRevision = channelClock.revision;
1024
- computedSlotEditable.checkedAtEpoch = channelClock.epoch;
1025
- if (isSameValue) return;
1026
- computedSlotEditable.value = next;
1027
+ editableComputedSlot.isDeriving = false;
1028
+ }
1029
+ if ((computedSlot.slotFlags & OIM_SLOT_FLAG_RELEASED) !== 0) {
1030
+ releaseValue(next);
1031
+ return;
1032
+ }
1033
+ const prevValue = computedSlot.value;
1034
+ const isSameValue = sameValueGuard(prevValue, next);
1035
+ editableComputedSlot.ranAtRevision = channelClock.revision;
1036
+ editableComputedSlot.ranAtEpoch = channelClock.epoch;
1037
+ editableComputedSlot.checkedAtRevision = channelClock.revision;
1038
+ editableComputedSlot.checkedAtEpoch = channelClock.epoch;
1039
+ if (isSameValue) {
1040
+ if (next !== prevValue) releaseValue(next);
1041
+ return;
1042
+ }
1043
+ editableComputedSlot.value = next;
1044
+ if (hasDerived) releaseValue(prevValue);
1027
1045
  const sourceSlots = computedSlot.sourceSlots;
1028
1046
  const sourceComputeds = computedSlot.sourceComputeds;
1029
1047
  const sourceCount = sourceSlots.length + sourceComputeds.length;
1030
1048
  let newestSourceRevision = -1;
1031
1049
  let newestSourceEpoch = -1;
1032
1050
  for (let i = 0; i < sourceCount; i++) {
1033
- const source = i < sourceSlots.length ? sourceSlots[i] : sourceComputeds[i - sourceSlots.length];
1034
- if (!oimIsRevisionAfter(source.changedAtRevision, source.changedAtEpoch, newestSourceRevision, newestSourceEpoch)) continue;
1035
- newestSourceRevision = source.changedAtRevision;
1036
- newestSourceEpoch = source.changedAtEpoch;
1051
+ const sourceSlot = i < sourceSlots.length ? sourceSlots[i] : sourceComputeds[i - sourceSlots.length];
1052
+ if (!oimIsRevisionAfter(sourceSlot.changedAtRevision, sourceSlot.changedAtEpoch, newestSourceRevision, newestSourceEpoch)) continue;
1053
+ newestSourceRevision = sourceSlot.changedAtRevision;
1054
+ newestSourceEpoch = sourceSlot.changedAtEpoch;
1037
1055
  }
1038
- computedSlotEditable.changedAtRevision = sourceCount === 0 ? channelClock.revision : newestSourceRevision;
1039
- computedSlotEditable.changedAtEpoch = sourceCount === 0 ? channelClock.epoch : newestSourceEpoch;
1056
+ editableComputedSlot.changedAtRevision = sourceCount === 0 ? channelClock.revision : newestSourceRevision;
1057
+ editableComputedSlot.changedAtEpoch = sourceCount === 0 ? channelClock.epoch : newestSourceEpoch;
1058
+ }
1059
+
1060
+ // src/computed/utils/oimReleaseNoValue.ts
1061
+ function oimReleaseNoValue() {
1062
+ return;
1040
1063
  }
1041
1064
 
1042
- // src/engine/column/OIMPullColumnSlotOwner.ts
1065
+ // src/column/OIMPullColumnSlotOwner.ts
1043
1066
  var columnValueOf = (value, columnName) => typeof value === "object" && value !== null ? value[columnName] : void 0;
1044
1067
  var isSameColumnValues = (prevColumnValues, nextColumnValues) => {
1045
1068
  if (!Array.isArray(prevColumnValues) || !Array.isArray(nextColumnValues)) return false;
@@ -1051,7 +1074,7 @@ var isSameColumnValues = (prevColumnValues, nextColumnValues) => {
1051
1074
  };
1052
1075
  var OIMPullColumnSlotOwner = class extends OIMColumnSlotOwner {
1053
1076
  constructor(options) {
1054
- super(oimColumnSlotStoreServiceOfColumnOwnerOptions(options));
1077
+ super(oimColumnSlotStoreServiceOfColumnSlotOwnerOptions(options));
1055
1078
  this.deriveColumnSlotValue = (columnSlot) => {
1056
1079
  const columnGroup = this.getColumnGroupsByKeyOf(this.carrierSlotOf(columnSlot))?.get(columnSlot.key);
1057
1080
  return columnGroup === void 0 ? this.deriveColumnValue(columnSlot) : this.deriveColumnValues(columnSlot, columnGroup.columnNames);
@@ -1060,17 +1083,18 @@ var OIMPullColumnSlotOwner = class extends OIMColumnSlotOwner {
1060
1083
  getValueForSlot(computedSlot) {
1061
1084
  this.assertNotReleased(computedSlot);
1062
1085
  const columnSlot = computedSlot;
1063
- const carrierStoreSlot = this.carrierSlotOf(columnSlot).storeSlot;
1086
+ const carrierStoreSlot = columnSlot.storeSlot;
1064
1087
  oimRefreshComputedSlot(
1065
1088
  columnSlot,
1066
1089
  this.deriveColumnSlotValue,
1067
1090
  carrierStoreSlot.columnGroupsByKey?.has(columnSlot.key) === true ? isSameColumnValues : Object.is,
1091
+ oimReleaseNoValue,
1068
1092
  carrierStoreSlot.channelSlot.clock
1069
1093
  );
1070
1094
  return columnSlot.value;
1071
1095
  }
1072
1096
  createColumnSlot(carrierSlot, key) {
1073
- const columnSlot = createOIMComputedSlot(key, this, this, void 0);
1097
+ const columnSlot = createOIMComputedSlot(key, this, this, void 0, carrierSlot.storeSlot, void 0);
1074
1098
  columnSlot.sourceComputeds = [carrierSlot];
1075
1099
  this.getValueForSlot(columnSlot);
1076
1100
  return columnSlot;
@@ -1090,19 +1114,19 @@ var OIMPullColumnSlotOwner = class extends OIMColumnSlotOwner {
1090
1114
  }
1091
1115
  };
1092
1116
 
1093
- // src/engine/slot/utils/oimSameValueZeroGuard.ts
1117
+ // src/slot/utils/oimSameValueZeroGuard.ts
1094
1118
  function oimSameValueZeroGuard(prevValue, nextValue) {
1095
1119
  return prevValue === nextValue || prevValue !== prevValue && nextValue !== nextValue;
1096
1120
  }
1097
1121
 
1098
- // src/engine/bucket/utils/oimSameSlotSequence.ts
1122
+ // src/bucket/utils/oimSameSlotSequence.ts
1099
1123
  function oimSameSlotSequence(prev, next) {
1100
1124
  if (prev.length !== next.length) return false;
1101
1125
  for (let i = 0; i < prev.length; i++) if (prev[i] !== next[i]) return false;
1102
1126
  return true;
1103
1127
  }
1104
1128
 
1105
- // src/engine/key/utils/oimSameKeySequence.ts
1129
+ // src/key/utils/oimSameKeySequence.ts
1106
1130
  function oimSameKeySequence(keys, otherKeys) {
1107
1131
  if (keys === otherKeys) return true;
1108
1132
  if (keys.length !== otherKeys.length) return false;
@@ -1112,25 +1136,25 @@ function oimSameKeySequence(keys, otherKeys) {
1112
1136
  return true;
1113
1137
  }
1114
1138
 
1115
- // src/engine/slot/utils/oimHoldSlots.ts
1139
+ // src/slot/utils/oimHoldSlots.ts
1116
1140
  function oimHoldSlots(slots) {
1117
1141
  for (let i = 0; i < slots.length; i++) slots[i].owner.holdSlot(slots[i]);
1118
1142
  }
1119
1143
 
1120
- // src/engine/slot/utils/oimUnholdSlotsIfAlive.ts
1144
+ // src/slot/utils/oimUnholdSlotsIfAlive.ts
1121
1145
  function oimUnholdSlotsIfAlive(slots) {
1122
1146
  for (let i = 0; i < slots.length; i++) oimUnholdSlotIfAlive(slots[i]);
1123
1147
  }
1124
1148
 
1125
- // src/engine/error/OIMThrowAtOnceErrorPolicy.ts
1149
+ // src/error/OIMThrowAtOnceErrorPolicy.ts
1126
1150
  var OIMThrowAtOnceErrorPolicy = class {
1127
1151
  onErrorCaught(error) {
1128
1152
  throw error;
1129
1153
  }
1130
1154
  };
1131
1155
 
1132
- // src/engine/computed/OIMEffectSourceList.ts
1133
- var OIMEffectSourceList = class {
1156
+ // src/computed/OIMSourceList.ts
1157
+ var OIMSourceList = class {
1134
1158
  constructor() {
1135
1159
  this.committedSources = [];
1136
1160
  this.trackedSources = [];
@@ -1179,6 +1203,9 @@ var OIMEffectSourceList = class {
1179
1203
  this.isTrackedSourcesChanged = true;
1180
1204
  return true;
1181
1205
  }
1206
+ getCommittedSources() {
1207
+ return this.committedSources;
1208
+ }
1182
1209
  getTrackedSources() {
1183
1210
  return this.isTrackedSourcesChanged ? this.trackedSources : this.committedSources;
1184
1211
  }
@@ -1197,7 +1224,7 @@ var OIMEffectSourceList = class {
1197
1224
  }
1198
1225
  };
1199
1226
 
1200
- // src/engine/computed/utils/oimMergeRootSlots.ts
1227
+ // src/computed/utils/oimMergeRootSlots.ts
1201
1228
  var scannedRootSlotLimit = 16;
1202
1229
  function oimMergeRootSlots(sourceSlots, sourceComputeds) {
1203
1230
  if (sourceComputeds.length === 0) return sourceSlots;
@@ -1227,7 +1254,7 @@ function pushIfAbsent(mergedRootSlots, distinctRootSlots, rootSlot) {
1227
1254
  return mergedRootSlots.length > scannedRootSlotLimit ? new Set(mergedRootSlots) : void 0;
1228
1255
  }
1229
1256
 
1230
- // src/engine/computed/utils/oimGetAllRootSlots.ts
1257
+ // src/computed/utils/oimGetAllRootSlots.ts
1231
1258
  function oimGetAllRootSlots(computedSlot) {
1232
1259
  const allRootSlots = computedSlot.allRootSlots;
1233
1260
  if (allRootSlots !== void 0) return allRootSlots;
@@ -1236,62 +1263,85 @@ function oimGetAllRootSlots(computedSlot) {
1236
1263
  return mergedRootSlots;
1237
1264
  }
1238
1265
 
1239
- // src/engine/computed/OIMEffectSourceTracker.ts
1240
- var OIMEffectSourceTracker = class {
1266
+ // src/computed/OIMSourceTracker.ts
1267
+ var OIMSourceTracker = class {
1241
1268
  constructor() {
1242
- this.slotEffectSourceList = new OIMEffectSourceList();
1243
- this.computedEffectSourceList = void 0;
1269
+ this.slotSourceList = new OIMSourceList();
1270
+ this.computedSourceList = void 0;
1244
1271
  this.committedAllRootSlots = [];
1245
1272
  this.trackedAllRootSlots = [];
1246
1273
  this.isTrackedAllRootSlotsChanged = false;
1274
+ this.committedComputedRootSlots = [];
1275
+ this.trackedComputedRootSlots = [];
1247
1276
  }
1248
1277
  readSourceSlot(slot) {
1249
- this.slotEffectSourceList.trackSource(slot);
1278
+ this.slotSourceList.trackSource(slot);
1250
1279
  return slot;
1251
1280
  }
1252
1281
  readSourceComputedValue(computedSlot) {
1253
1282
  const value = computedSlot.computedValueService.getValueForSlot(computedSlot);
1254
- (this.computedEffectSourceList ?? (this.computedEffectSourceList = new OIMEffectSourceList())).trackSource(computedSlot);
1283
+ (this.computedSourceList ?? (this.computedSourceList = new OIMSourceList())).trackSource(computedSlot);
1255
1284
  return value;
1256
1285
  }
1257
1286
  openSourceTracking() {
1258
- this.slotEffectSourceList.openSourceTracking();
1259
- this.computedEffectSourceList?.openSourceTracking();
1287
+ this.slotSourceList.openSourceTracking();
1288
+ this.computedSourceList?.openSourceTracking();
1260
1289
  this.isTrackedAllRootSlotsChanged = false;
1261
1290
  }
1262
1291
  closeSourceTracking() {
1263
- const isSourceSlotsChanged = this.slotEffectSourceList.closeSourceTracking();
1264
- const isSourceComputedsChanged = this.computedEffectSourceList?.closeSourceTracking() ?? false;
1265
- if (!isSourceSlotsChanged && !isSourceComputedsChanged) return false;
1292
+ const isSourceSlotsChanged = this.slotSourceList.closeSourceTracking();
1293
+ const isSourceComputedsChanged = this.computedSourceList?.closeSourceTracking() ?? false;
1294
+ if (!isSourceSlotsChanged && !isSourceComputedsChanged && !this.isAnyComputedRootSlotsReplaced()) return false;
1295
+ this.trackAllRootSlots();
1296
+ return true;
1297
+ }
1298
+ isAnyComputedRootSlotsReplaced() {
1299
+ const computedSourceList = this.computedSourceList;
1300
+ if (computedSourceList === void 0) return false;
1301
+ const committedSourceComputeds = computedSourceList.getCommittedSources();
1302
+ const committedComputedRootSlots = this.committedComputedRootSlots;
1303
+ for (let i = 0; i < committedSourceComputeds.length; i++) {
1304
+ if (oimGetAllRootSlots(committedSourceComputeds[i]) !== committedComputedRootSlots[i]) return true;
1305
+ }
1306
+ return false;
1307
+ }
1308
+ trackReplacedRootSlots() {
1309
+ if (!this.isAnyComputedRootSlotsReplaced()) return false;
1266
1310
  this.trackAllRootSlots();
1267
1311
  return true;
1268
1312
  }
1269
1313
  getTrackedSourceSlots() {
1270
- return this.slotEffectSourceList.getTrackedSources();
1314
+ return this.slotSourceList.getTrackedSources();
1271
1315
  }
1272
1316
  getTrackedSourceComputeds() {
1273
- return this.computedEffectSourceList?.getTrackedSources() ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
1317
+ return this.computedSourceList?.getTrackedSources() ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
1274
1318
  }
1275
1319
  getTrackedAllRootSlots() {
1276
1320
  return this.isTrackedAllRootSlotsChanged ? this.trackedAllRootSlots : this.committedAllRootSlots;
1277
1321
  }
1278
1322
  commitTrackedSources() {
1279
- this.slotEffectSourceList.commitTrackedSources();
1280
- this.computedEffectSourceList?.commitTrackedSources();
1323
+ this.slotSourceList.commitTrackedSources();
1324
+ this.computedSourceList?.commitTrackedSources();
1281
1325
  if (!this.isTrackedAllRootSlotsChanged) return;
1282
1326
  const committedAllRootSlots = this.committedAllRootSlots;
1283
1327
  this.committedAllRootSlots = this.trackedAllRootSlots;
1284
1328
  this.trackedAllRootSlots = committedAllRootSlots;
1329
+ const committedComputedRootSlots = this.committedComputedRootSlots;
1330
+ this.committedComputedRootSlots = this.trackedComputedRootSlots;
1331
+ this.trackedComputedRootSlots = committedComputedRootSlots;
1285
1332
  this.isTrackedAllRootSlotsChanged = false;
1286
1333
  }
1287
1334
  trackAllRootSlots() {
1288
- const sourceSlots = this.slotEffectSourceList.getTrackedSources();
1335
+ const sourceSlots = this.slotSourceList.getTrackedSources();
1289
1336
  const sourceComputeds = this.getTrackedSourceComputeds();
1290
1337
  const trackedAllRootSlots = this.trackedAllRootSlots;
1338
+ const trackedComputedRootSlots = this.trackedComputedRootSlots;
1339
+ if (trackedComputedRootSlots.length !== sourceComputeds.length) trackedComputedRootSlots.length = sourceComputeds.length;
1291
1340
  let rootSlotCount = 0;
1292
1341
  for (let i = 0; i < sourceSlots.length; i++) trackedAllRootSlots[rootSlotCount++] = sourceSlots[i];
1293
1342
  for (let i = 0; i < sourceComputeds.length; i++) {
1294
1343
  const computedRootSlots = oimGetAllRootSlots(sourceComputeds[i]);
1344
+ trackedComputedRootSlots[i] = computedRootSlots;
1295
1345
  for (let j = 0; j < computedRootSlots.length; j++) trackedAllRootSlots[rootSlotCount++] = computedRootSlots[j];
1296
1346
  }
1297
1347
  if (trackedAllRootSlots.length !== rootSlotCount) trackedAllRootSlots.length = rootSlotCount;
@@ -1299,23 +1349,26 @@ var OIMEffectSourceTracker = class {
1299
1349
  }
1300
1350
  };
1301
1351
 
1302
- // src/engine/computed/constants/OIM_EFFECT_FLAG_DISPOSED.ts
1352
+ // src/effect/constants/OIM_EFFECT_FLAG_DISPOSED.ts
1303
1353
  var OIM_EFFECT_FLAG_DISPOSED = 2;
1304
1354
 
1305
- // src/engine/computed/utils/oimIsEffectDisposed.ts
1355
+ // src/effect/utils/oimIsEffectDisposed.ts
1306
1356
  function oimIsEffectDisposed(effect) {
1307
1357
  return (effect.effectFlags & OIM_EFFECT_FLAG_DISPOSED) !== 0;
1308
1358
  }
1309
1359
 
1310
- // src/engine/computed/constants/OIM_EFFECT_FLAG_RUN_SCHEDULED.ts
1360
+ // src/effect/constants/OIM_EFFECT_FLAG_RUN_SCHEDULED.ts
1311
1361
  var OIM_EFFECT_FLAG_RUN_SCHEDULED = 1;
1312
1362
 
1313
- // src/engine/computed/constants/OIM_EFFECT_FLAG_SOURCE_CHECK_OWED.ts
1363
+ // src/effect/constants/OIM_EFFECT_FLAG_SOURCE_CHECK_OWED.ts
1314
1364
  var OIM_EFFECT_FLAG_SOURCE_CHECK_OWED = 4;
1315
1365
 
1316
- // src/engine/computed/OIMEffectService.ts
1366
+ // src/effect/OIMEffectService.ts
1317
1367
  var _OIMEffectService = class _OIMEffectService {
1318
- createEffect(channelMap, sourceSlots, sourceComputeds, body) {
1368
+ createEffect(channelMap, body, sourceSlots = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceTrackingComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS) {
1369
+ if (sourceTrackingComputeds.length !== 0) {
1370
+ return this.createEffectOverSourceTrackingComputeds(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds);
1371
+ }
1319
1372
  let distinctSourceComputeds = sourceComputeds;
1320
1373
  if (sourceComputeds.length > 1) {
1321
1374
  const distinctSourceComputedSet = new Set(sourceComputeds);
@@ -1336,7 +1389,8 @@ var _OIMEffectService = class _OIMEffectService {
1336
1389
  ranAtEpoch: clock.epoch,
1337
1390
  effectFlags: 0,
1338
1391
  body,
1339
- cleanup: void 0
1392
+ cleanup: void 0,
1393
+ sourceTracker: void 0
1340
1394
  };
1341
1395
  try {
1342
1396
  for (let i = 0; i < allRootSlots.length; i++) {
@@ -1352,20 +1406,17 @@ var _OIMEffectService = class _OIMEffectService {
1352
1406
  this.disposeEffect(effect);
1353
1407
  throw failure;
1354
1408
  }
1355
- const frame = channelSlot.frame;
1356
- if (!frame.isRunning && oimIsRevisionAfter(clock.revision, clock.epoch, frame.openedAtRevision, frame.openedAtEpoch) && this.markEffectRunScheduled(effect, true)) {
1357
- OIMChannelService.INSTANCE.scheduleEffectRun(channelSlot, effect);
1358
- }
1409
+ this.scheduleEffectRunIfWrittenSinceFrameOpened(effect);
1359
1410
  return effect;
1360
1411
  }
1361
- subscribeEffect(channelMap, sourceSlots, sourceComputeds, body) {
1362
- const effect = this.createEffect(channelMap, sourceSlots, sourceComputeds, body);
1412
+ subscribeEffect(channelMap, body, sourceSlots = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceTrackingComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS) {
1413
+ const effect = this.createEffect(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds);
1363
1414
  return () => {
1364
1415
  this.disposeEffect(effect);
1365
1416
  };
1366
1417
  }
1367
- createEffectImmediate(channelMap, sourceSlots, sourceComputeds, body) {
1368
- const effect = this.createEffect(channelMap, sourceSlots, sourceComputeds, body);
1418
+ createAndRunEffect(channelMap, body, sourceSlots = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceTrackingComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS) {
1419
+ const effect = this.createEffect(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds);
1369
1420
  try {
1370
1421
  this.runEffect(effect);
1371
1422
  } catch (refusal) {
@@ -1374,31 +1425,63 @@ var _OIMEffectService = class _OIMEffectService {
1374
1425
  }
1375
1426
  return effect;
1376
1427
  }
1377
- createEffectWithSourceTracking(channelMap, effectBodyWithSourceTracking) {
1378
- const effectSourceTracker = new OIMEffectSourceTracker();
1428
+ createSourceTrackingEffect(channelMap, sourceTrackingEffectBody) {
1429
+ const sourceTracker = new OIMSourceTracker();
1430
+ const effect = this.createEffectOverSourceTracker(
1431
+ channelMap,
1432
+ sourceTracker,
1433
+ () => this.runSourceTrackingEffectBody(effect, sourceTracker, sourceTrackingEffectBody)
1434
+ );
1435
+ try {
1436
+ this.runEffect(effect);
1437
+ } catch (failure) {
1438
+ this.disposeEffect(effect);
1439
+ throw failure;
1440
+ }
1441
+ return effect;
1442
+ }
1443
+ createEffectOverSourceTrackingComputeds(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds) {
1444
+ const sourceTracker = new OIMSourceTracker();
1445
+ const effect = this.createEffectOverSourceTracker(channelMap, sourceTracker, body);
1446
+ try {
1447
+ sourceTracker.openSourceTracking();
1448
+ for (let i = 0; i < sourceSlots.length; i++) sourceTracker.readSourceSlot(sourceSlots[i]);
1449
+ for (let i = 0; i < sourceComputeds.length; i++) sourceTracker.readSourceComputedValue(sourceComputeds[i]);
1450
+ for (let i = 0; i < sourceTrackingComputeds.length; i++) sourceTracker.readSourceComputedValue(sourceTrackingComputeds[i]);
1451
+ if (sourceTracker.closeSourceTracking()) this.resubscribeToTrackedSources(effect, sourceTracker);
1452
+ } catch (failure) {
1453
+ this.disposeEffect(effect);
1454
+ throw failure;
1455
+ }
1456
+ this.scheduleEffectRunIfWrittenSinceFrameOpened(effect);
1457
+ return effect;
1458
+ }
1459
+ createEffectOverSourceTracker(channelMap, sourceTracker, body) {
1379
1460
  const channelSlot = channelMap.defaultChannelSlot;
1380
1461
  const clock = channelSlot.clock;
1381
- const effect = {
1462
+ return {
1382
1463
  effectService: this,
1383
1464
  channelSlot,
1384
- sourceSlots: effectSourceTracker.getTrackedSourceSlots(),
1385
- sourceComputeds: effectSourceTracker.getTrackedSourceComputeds(),
1386
- allRootSlots: effectSourceTracker.getTrackedAllRootSlots(),
1465
+ sourceSlots: sourceTracker.getTrackedSourceSlots(),
1466
+ sourceComputeds: sourceTracker.getTrackedSourceComputeds(),
1467
+ allRootSlots: sourceTracker.getTrackedAllRootSlots(),
1387
1468
  positionInFirstSubscribedSlot: -1,
1388
1469
  positionsInOtherSubscribedSlots: void 0,
1389
1470
  ranAtRevision: clock.revision,
1390
1471
  ranAtEpoch: clock.epoch,
1391
1472
  effectFlags: 0,
1392
- body: () => this.runEffectBodyWithSourceTracking(effect, effectSourceTracker, effectBodyWithSourceTracking),
1393
- cleanup: void 0
1473
+ body,
1474
+ cleanup: void 0,
1475
+ sourceTracker
1394
1476
  };
1395
- try {
1396
- this.runEffect(effect);
1397
- } catch (failure) {
1398
- this.disposeEffect(effect);
1399
- throw failure;
1477
+ }
1478
+ scheduleEffectRunIfWrittenSinceFrameOpened(effect) {
1479
+ const channelSlot = effect.channelSlot;
1480
+ const clock = channelSlot.clock;
1481
+ const frame = channelSlot.frame;
1482
+ if (!frame.isRunning && oimIsRevisionAfter(clock.revision, clock.epoch, frame.openedAtRevision, frame.openedAtEpoch) && this.markEffectRunScheduled(effect, true)) {
1483
+ OIMChannelService.INSTANCE.scheduleEffectRun(channelSlot, effect);
1400
1484
  }
1401
- return effect;
1402
1485
  }
1403
1486
  markEffectRunScheduled(effect, isSourceCheckOwed) {
1404
1487
  const effectFlags = effect.effectFlags;
@@ -1422,8 +1505,11 @@ var _OIMEffectService = class _OIMEffectService {
1422
1505
  }
1423
1506
  runEffectIfSourcesChanged(effect) {
1424
1507
  oimRefreshSourceComputeds(effect.sourceComputeds);
1425
- if (!oimHasSourceChangedSinceLastRun(effect)) return;
1426
- this.runEffect(effect);
1508
+ if (oimHasSourceChangedSinceLastRun(effect)) this.runEffect(effect);
1509
+ const sourceTracker = effect.sourceTracker;
1510
+ if (sourceTracker !== void 0 && !oimIsEffectDisposed(effect) && sourceTracker.trackReplacedRootSlots()) {
1511
+ this.resubscribeToTrackedSources(effect, sourceTracker);
1512
+ }
1427
1513
  }
1428
1514
  runEffect(effect) {
1429
1515
  const channelClock = effect.channelSlot.clock;
@@ -1465,11 +1551,11 @@ var _OIMEffectService = class _OIMEffectService {
1465
1551
  }
1466
1552
  (effect.positionsInOtherSubscribedSlots ?? (effect.positionsInOtherSubscribedSlots = []))[edge - 1] = positionInSlot;
1467
1553
  }
1468
- runEffectBodyWithSourceTracking(effect, effectSourceTracker, effectBodyWithSourceTracking) {
1469
- effectSourceTracker.openSourceTracking();
1470
- const undo = effectBodyWithSourceTracking(effectSourceTracker);
1554
+ runSourceTrackingEffectBody(effect, sourceTracker, sourceTrackingEffectBody) {
1555
+ sourceTracker.openSourceTracking();
1556
+ const undo = sourceTrackingEffectBody(sourceTracker);
1471
1557
  try {
1472
- if (effectSourceTracker.closeSourceTracking()) this.resubscribeToTrackedSources(effect, effectSourceTracker);
1558
+ if (sourceTracker.closeSourceTracking()) this.resubscribeToTrackedSources(effect, sourceTracker);
1473
1559
  } catch (failure) {
1474
1560
  this.disposeEffect(effect);
1475
1561
  if (typeof undo === "function") undo();
@@ -1477,11 +1563,11 @@ var _OIMEffectService = class _OIMEffectService {
1477
1563
  }
1478
1564
  return undo;
1479
1565
  }
1480
- resubscribeToTrackedSources(effect, effectSourceTracker) {
1566
+ resubscribeToTrackedSources(effect, sourceTracker) {
1481
1567
  const committedAllRootSlots = effect.allRootSlots;
1482
1568
  const committedSourceComputeds = effect.sourceComputeds;
1483
- const trackedAllRootSlots = effectSourceTracker.getTrackedAllRootSlots();
1484
- const trackedSourceComputeds = effectSourceTracker.getTrackedSourceComputeds();
1569
+ const trackedAllRootSlots = sourceTracker.getTrackedAllRootSlots();
1570
+ const trackedSourceComputeds = sourceTracker.getTrackedSourceComputeds();
1485
1571
  const committedEdgeCount = committedAllRootSlots.length + committedSourceComputeds.length;
1486
1572
  const trackedEdgeCount = trackedAllRootSlots.length + trackedSourceComputeds.length;
1487
1573
  const sharedEdgeCount = committedEdgeCount < trackedEdgeCount ? committedEdgeCount : trackedEdgeCount;
@@ -1506,11 +1592,11 @@ var _OIMEffectService = class _OIMEffectService {
1506
1592
  if (positionsInOtherSubscribedSlots !== void 0 && positionsInOtherSubscribedSlots.length > otherEdgeCount) {
1507
1593
  positionsInOtherSubscribedSlots.length = otherEdgeCount;
1508
1594
  }
1509
- const effectEditable = effect;
1510
- effectEditable.sourceSlots = effectSourceTracker.getTrackedSourceSlots();
1511
- effectEditable.sourceComputeds = trackedSourceComputeds;
1512
- effectEditable.allRootSlots = trackedAllRootSlots;
1513
- effectSourceTracker.commitTrackedSources();
1595
+ const editableEffect = effect;
1596
+ editableEffect.sourceSlots = sourceTracker.getTrackedSourceSlots();
1597
+ editableEffect.sourceComputeds = trackedSourceComputeds;
1598
+ editableEffect.allRootSlots = trackedAllRootSlots;
1599
+ sourceTracker.commitTrackedSources();
1514
1600
  const channelSlot = effect.channelSlot;
1515
1601
  const isFrameRunning = channelSlot.frame.isRunning;
1516
1602
  for (let edge = firstChangedEdge; edge < trackedEdgeCount; edge++) {
@@ -1545,11 +1631,12 @@ var _OIMEffectService = class _OIMEffectService {
1545
1631
  _OIMEffectService.INSTANCE = new _OIMEffectService();
1546
1632
  var OIMEffectService = _OIMEffectService;
1547
1633
 
1548
- // src/engine/computed/OIMComputedValueService.ts
1634
+ // src/computed/OIMComputedValueService.ts
1549
1635
  var OIMComputedValueService = class {
1550
1636
  constructor(options) {
1551
1637
  this.derive = options.derive;
1552
1638
  this.sameValueGuard = options.sameValueGuard ?? Object.is;
1639
+ this.releaseValue = options.releaseValue ?? oimReleaseNoValue;
1553
1640
  }
1554
1641
  getValueForSlot(computedSlot) {
1555
1642
  oimAssertSlotNotReleased(computedSlot);
@@ -1559,22 +1646,26 @@ var OIMComputedValueService = class {
1559
1646
  computedSlot,
1560
1647
  derive,
1561
1648
  this.sameValueGuard,
1649
+ this.releaseValue,
1562
1650
  computedStoreSlot.channelSlot.clock
1563
1651
  );
1564
1652
  return computedSlot.value;
1565
1653
  }
1654
+ releaseSlotValue(computedSlot) {
1655
+ if (computedSlot.ranAtRevision !== -1) this.releaseValue(computedSlot.value);
1656
+ }
1566
1657
  };
1567
1658
 
1568
- // src/engine/slot/OIMContentChangeListenerService.ts
1569
- var _OIMContentChangeListenerService = class _OIMContentChangeListenerService {
1659
+ // src/slot/OIMSlotContentChangeListenerService.ts
1660
+ var _OIMSlotContentChangeListenerService = class _OIMSlotContentChangeListenerService {
1570
1661
  addContentChangeListener(storeSlot, listener, readColumnNames) {
1571
- const storeSlotEditable = storeSlot;
1572
- if (storeSlotEditable.contentChangeListeners === void 0) {
1573
- storeSlotEditable.contentChangeListeners = [];
1574
- storeSlotEditable.contentChangeListenerReadColumnNames = [];
1662
+ const editableStoreSlot = storeSlot;
1663
+ if (editableStoreSlot.contentChangeListeners === void 0) {
1664
+ editableStoreSlot.contentChangeListeners = [];
1665
+ editableStoreSlot.contentChangeListenerReadColumnNames = [];
1575
1666
  }
1576
- storeSlotEditable.contentChangeListeners.push(listener);
1577
- storeSlotEditable.contentChangeListenerReadColumnNames.push(readColumnNames);
1667
+ editableStoreSlot.contentChangeListeners.push(listener);
1668
+ editableStoreSlot.contentChangeListenerReadColumnNames.push(readColumnNames);
1578
1669
  if (readColumnNames === void 0) this.addReadAnyColumn(storeSlot);
1579
1670
  else for (let i = 0; i < readColumnNames.length; i++) this.addReadColumn(storeSlot, readColumnNames[i]);
1580
1671
  }
@@ -1610,15 +1701,15 @@ var _OIMContentChangeListenerService = class _OIMContentChangeListenerService {
1610
1701
  if (storeSlot.allColumnsListenerCount !== 0) storeSlot.allColumnsListenerCount--;
1611
1702
  }
1612
1703
  };
1613
- _OIMContentChangeListenerService.INSTANCE = new _OIMContentChangeListenerService();
1614
- var OIMContentChangeListenerService = _OIMContentChangeListenerService;
1704
+ _OIMSlotContentChangeListenerService.INSTANCE = new _OIMSlotContentChangeListenerService();
1705
+ var OIMSlotContentChangeListenerService = _OIMSlotContentChangeListenerService;
1615
1706
 
1616
- // src/engine/slot/utils/oimGetChannelSlot.ts
1707
+ // src/slot/utils/oimGetChannelSlot.ts
1617
1708
  function oimGetChannelSlot(slot) {
1618
1709
  return slot.storeSlot.channelSlot;
1619
1710
  }
1620
1711
 
1621
- // src/facade/column/OIMColumnSlotService.ts
1712
+ // src/column/OIMColumnSlotService.ts
1622
1713
  var OIMColumnSlotService = class {
1623
1714
  constructor(columnSlotOwner) {
1624
1715
  this.columnSlotOwner = columnSlotOwner;
@@ -1646,8 +1737,11 @@ var OIMColumnSlotService = class {
1646
1737
  }
1647
1738
  };
1648
1739
 
1649
- // src/engine/slot/OIMContentChangeDeliveryService.ts
1650
- var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1740
+ // src/slot/constants/OIM_SLOT_FLAG_QUEUED_IN_BATCH.ts
1741
+ var OIM_SLOT_FLAG_QUEUED_IN_BATCH = 32;
1742
+
1743
+ // src/slot/OIMSlotContentChangeDeliveryService.ts
1744
+ var _OIMSlotContentChangeDeliveryService = class _OIMSlotContentChangeDeliveryService {
1651
1745
  isBatchOpen(storeSlot) {
1652
1746
  return storeSlot.batchDepth > 0;
1653
1747
  }
@@ -1655,23 +1749,23 @@ var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1655
1749
  storeSlot.batchDepth++;
1656
1750
  }
1657
1751
  closeBatch(storeSlot) {
1658
- const storeSlotEditable = storeSlot;
1659
- if (--storeSlotEditable.batchDepth > 0) return;
1752
+ const editableStoreSlot = storeSlot;
1753
+ if (editableStoreSlot.batchDepth === 0) {
1754
+ throw new Error(
1755
+ "OIMSlotContentChangeDeliveryService.closeBatch: no batch is open on this store slot, so there is nothing to close. A close without its open would leave the next batch delivering every write at once."
1756
+ );
1757
+ }
1758
+ if (--editableStoreSlot.batchDepth > 0) return;
1660
1759
  const batchSlotChannelQueue = storeSlot.batchSlotChannelQueue;
1661
1760
  if (batchSlotChannelQueue === void 0 || batchSlotChannelQueue.getEntryCount() === 0) return;
1662
1761
  this.deliverBatch(storeSlot, batchSlotChannelQueue);
1663
1762
  }
1664
1763
  enqueueContentChange(storeSlot, slot, patch, changedColumns) {
1665
- const storeSlotEditable = storeSlot;
1666
- (storeSlotEditable.batchSlotChannelQueue ?? (storeSlotEditable.batchSlotChannelQueue = new OIMChannelQueue())).enqueueEntry(slot);
1667
- (storeSlotEditable.batchPatchChannelQueue ?? (storeSlotEditable.batchPatchChannelQueue = new OIMChannelQueue())).enqueueEntry(patch);
1668
- (storeSlotEditable.batchChangedColumnsChannelQueue ?? (storeSlotEditable.batchChangedColumnsChannelQueue = new OIMChannelQueue())).enqueueEntry(changedColumns === void 0 ? void 0 : changedColumns.slice());
1669
- }
1670
- isLastEnqueuedSlot(storeSlot, slot) {
1671
- const batchSlotChannelQueue = storeSlot.batchSlotChannelQueue;
1672
- if (batchSlotChannelQueue === void 0) return false;
1673
- const batchSlotCount = batchSlotChannelQueue.getEntryCount();
1674
- return batchSlotCount !== 0 && batchSlotChannelQueue.getEntryAt(batchSlotCount - 1) === slot;
1764
+ const editableStoreSlot = storeSlot;
1765
+ (editableStoreSlot.batchSlotChannelQueue ?? (editableStoreSlot.batchSlotChannelQueue = new OIMChannelQueue())).enqueueEntry(slot);
1766
+ slot.slotFlags |= OIM_SLOT_FLAG_QUEUED_IN_BATCH;
1767
+ (editableStoreSlot.batchPatchChannelQueue ?? (editableStoreSlot.batchPatchChannelQueue = new OIMChannelQueue())).enqueueEntry(patch);
1768
+ (editableStoreSlot.batchChangedColumnsChannelQueue ?? (editableStoreSlot.batchChangedColumnsChannelQueue = new OIMChannelQueue())).enqueueEntry(changedColumns === void 0 ? void 0 : changedColumns.slice());
1675
1769
  }
1676
1770
  deliverBatch(storeSlot, batchSlotChannelQueue) {
1677
1771
  const batchPatchChannelQueue = storeSlot.batchPatchChannelQueue;
@@ -1686,10 +1780,13 @@ var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1686
1780
  for (let i = 0; i < listeners.length; i++) listeners[i].onContentChanged(slot, patch, changedColumns);
1687
1781
  } else {
1688
1782
  for (let i = 0; i < listeners.length; i++) {
1689
- listeners[i].onContentChangedMany(batchSlotChannelQueue, batchPatchChannelQueue, batchChangedColumnsChannelQueue);
1783
+ listeners[i].onManyContentsChanged(batchSlotChannelQueue, batchPatchChannelQueue, batchChangedColumnsChannelQueue);
1690
1784
  }
1691
1785
  }
1692
1786
  } finally {
1787
+ for (let i = 0; i < batchSlotChannelQueue.getEntryCount(); i++) {
1788
+ batchSlotChannelQueue.getEntryAt(i).slotFlags &= ~OIM_SLOT_FLAG_QUEUED_IN_BATCH;
1789
+ }
1693
1790
  try {
1694
1791
  for (let i = 0; i < batchSlotChannelQueue.getEntryCount(); i++) {
1695
1792
  const slot = batchSlotChannelQueue.getEntryAt(i);
@@ -1703,10 +1800,10 @@ var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1703
1800
  }
1704
1801
  }
1705
1802
  };
1706
- _OIMContentChangeDeliveryService.INSTANCE = new _OIMContentChangeDeliveryService();
1707
- var OIMContentChangeDeliveryService = _OIMContentChangeDeliveryService;
1803
+ _OIMSlotContentChangeDeliveryService.INSTANCE = new _OIMSlotContentChangeDeliveryService();
1804
+ var OIMSlotContentChangeDeliveryService = _OIMSlotContentChangeDeliveryService;
1708
1805
 
1709
- // src/engine/collector/OIMSlotAtEmptyReleasePolicy.ts
1806
+ // src/collector/OIMSlotAtEmptyReleasePolicy.ts
1710
1807
  var _OIMSlotAtEmptyReleasePolicy = class _OIMSlotAtEmptyReleasePolicy {
1711
1808
  constructor() {
1712
1809
  this.releasesWrittenSlots = false;
@@ -1734,7 +1831,7 @@ var _OIMSlotAtEmptyReleasePolicy = class _OIMSlotAtEmptyReleasePolicy {
1734
1831
  _OIMSlotAtEmptyReleasePolicy.INSTANCE = new _OIMSlotAtEmptyReleasePolicy();
1735
1832
  var OIMSlotAtEmptyReleasePolicy = _OIMSlotAtEmptyReleasePolicy;
1736
1833
 
1737
- // src/engine/slot/OIMSlotOwnerService.ts
1834
+ // src/slot/OIMSlotOwnerService.ts
1738
1835
  var OIMSlotOwnerService = class extends OIMSlotOwner {
1739
1836
  constructor(options) {
1740
1837
  super();
@@ -1756,26 +1853,22 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1756
1853
  return slot.columnSlotStore !== void 0;
1757
1854
  }
1758
1855
  hasContentChangeListeners(slot) {
1759
- const storeSlot = slot.storeSlot;
1760
- if (storeSlot === void 0) return false;
1761
- const listeners = storeSlot.contentChangeListeners;
1856
+ const listeners = slot.storeSlot.contentChangeListeners;
1762
1857
  return listeners !== void 0 && listeners.length !== 0;
1763
1858
  }
1764
1859
  dispatchContentChange(slot, patch, changedColumns) {
1765
1860
  const storeSlot = slot.storeSlot;
1766
- if (storeSlot === void 0) return;
1767
1861
  const listeners = storeSlot.contentChangeListeners;
1768
1862
  if (listeners === void 0 || listeners.length === 0) return;
1769
1863
  if (changedColumns !== void 0 && !this.isAnyColumnRead(storeSlot, changedColumns)) return;
1770
1864
  if (storeSlot.batchDepth > 0) {
1771
- OIMContentChangeDeliveryService.INSTANCE.enqueueContentChange(storeSlot, slot, patch, changedColumns);
1865
+ OIMSlotContentChangeDeliveryService.INSTANCE.enqueueContentChange(storeSlot, slot, patch, changedColumns);
1772
1866
  return;
1773
1867
  }
1774
1868
  for (let i = 0; i < listeners.length; i++) listeners[i].onContentChanged(slot, patch, changedColumns);
1775
1869
  }
1776
1870
  isAnyColumnReferenced(slot, changedColumns) {
1777
1871
  const storeSlot = slot.storeSlot;
1778
- if (storeSlot === void 0) return false;
1779
1872
  return slot.columnSlotStore !== void 0 && this.columnSlotOwner.isAnyColumnReferenced(storeSlot, changedColumns) || this.isAnyColumnRead(storeSlot, changedColumns);
1780
1873
  }
1781
1874
  isAnyColumnRead(storeSlot, changedColumns) {
@@ -1794,8 +1887,7 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1794
1887
  return changedColumnNames;
1795
1888
  }
1796
1889
  releaseSlotIfUnheldAfterListeners(slot) {
1797
- const storeSlot = slot.storeSlot;
1798
- if (storeSlot !== void 0 && storeSlot.batchDepth > 0 && OIMContentChangeDeliveryService.INSTANCE.isLastEnqueuedSlot(storeSlot, slot)) return;
1890
+ if ((slot.slotFlags & OIM_SLOT_FLAG_QUEUED_IN_BATCH) !== 0) return;
1799
1891
  this.releaseSlotIfUnheld(slot);
1800
1892
  }
1801
1893
  releaseWrittenSlotIfUnheld(slot) {
@@ -1834,7 +1926,7 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1834
1926
  }
1835
1927
  onSlotIdle(slot) {
1836
1928
  if (oimIsSlotEmpty(slot)) return;
1837
- if (this.slotReleasePolicy.onSlotIdle(slot)) this.releaseSlotIfUnheld(slot);
1929
+ this.slotReleasePolicy.onSlotIdle(slot);
1838
1930
  }
1839
1931
  onSlotFirstSubscribed(slot) {
1840
1932
  this.slotSubscriptionListener.onSlotFirstSubscribed(slot);
@@ -1853,14 +1945,7 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1853
1945
  if (!isEmpty && !this.releasesWrittenSlots) return;
1854
1946
  if (!this.isReleasable(ownSlot)) return;
1855
1947
  if (isEmpty ? !this.slotReleasePolicy.isEmptySlotReleasable(ownSlot) : !this.slotReleasePolicy.isSlotReleasable(ownSlot)) return;
1856
- if (!isEmpty) {
1857
- const channelSlot = oimGetChannelSlot(ownSlot);
1858
- if (OIMChannelService.INSTANCE.isRefusingWrites(channelSlot)) {
1859
- OIMUnusedSlotCollectorService.INSTANCE.holdSlotUntilFlush(channelSlot.collectorSlot.unusedSlotCollectorSlot, ownSlot);
1860
- return;
1861
- }
1862
- }
1863
- this.releaseSlot(ownSlot, isEmpty);
1948
+ this.releaseSlot(ownSlot);
1864
1949
  }
1865
1950
  isReleasable(slot) {
1866
1951
  if (slot.holdCount > 0) return false;
@@ -1868,18 +1953,16 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1868
1953
  if (slot.columnSlotStore !== void 0) return false;
1869
1954
  return !this.slotContentService.hasReference(slot);
1870
1955
  }
1871
- releaseSlot(slot, isEmpty) {
1872
- if (!isEmpty) this.assertWritable(slot);
1873
- this.slotContentService.releaseSlotContent(slot, this);
1956
+ releaseSlot(slot) {
1957
+ this.slotContentService.releaseSlotContent(slot);
1874
1958
  slot.slotFlags |= OIM_SLOT_FLAG_EMPTY;
1875
1959
  this.slotReleasePolicy.cancelSlotRelease(slot);
1876
- const storeSlot = slot.storeSlot;
1877
- if (storeSlot !== void 0) this.slotFilingService.unfileSlot(storeSlot.store, slot);
1960
+ this.slotFilingService.unfileSlot(slot.storeSlot.store, slot);
1878
1961
  oimMarkSlotReleased(slot);
1879
1962
  }
1880
1963
  };
1881
1964
 
1882
- // src/engine/slot/utils/createOIMStoreSlot.ts
1965
+ // src/slot/utils/createOIMStoreSlot.ts
1883
1966
  function createOIMStoreSlot(store, channelSlot, slotService, sourceStoreSlot) {
1884
1967
  return {
1885
1968
  store,
@@ -1916,7 +1999,45 @@ function createOIMStoreSlot(store, channelSlot, slotService, sourceStoreSlot) {
1916
1999
  };
1917
2000
  }
1918
2001
 
1919
- // src/facade/slot/OIMSlotCollectionService.ts
2002
+ // src/slot/OIMSlotCollectionStoreAggregate.ts
2003
+ var OIMSlotCollectionStoreAggregate = class {
2004
+ constructor(slotService, storeSlot) {
2005
+ this.slotService = slotService;
2006
+ this.storeSlot = storeSlot;
2007
+ }
2008
+ get slotContentService() {
2009
+ return this.slotService.slotContentService;
2010
+ }
2011
+ findSlotByKey(key) {
2012
+ return this.slotService.findSlotByKey(this.storeSlot, key);
2013
+ }
2014
+ hasSlotContentByKey(key) {
2015
+ return this.slotService.hasSlotContentByKey(this.storeSlot, key);
2016
+ }
2017
+ getSlotByKey(key) {
2018
+ return this.slotService.getSlotByKey(this.storeSlot, key);
2019
+ }
2020
+ holdSlotByKey(key) {
2021
+ return this.slotService.holdSlotByKey(this.storeSlot, key);
2022
+ }
2023
+ getSlots() {
2024
+ return this.slotService.getSlots(this.storeSlot);
2025
+ }
2026
+ getSlotCount() {
2027
+ return this.slotService.getSlotCount(this.storeSlot);
2028
+ }
2029
+ openBatch() {
2030
+ this.slotService.openBatch(this.storeSlot);
2031
+ }
2032
+ closeBatch() {
2033
+ this.slotService.closeBatch(this.storeSlot);
2034
+ }
2035
+ writeInBatch(write) {
2036
+ return this.slotService.writeInBatch(this.storeSlot, write);
2037
+ }
2038
+ };
2039
+
2040
+ // src/slot/OIMSlotCollectionService.ts
1920
2041
  var OIMSlotCollectionService = class {
1921
2042
  constructor(options) {
1922
2043
  const slotOwnerService = new OIMSlotOwnerService({ ...options, slotFilingService: options.slotStoreService });
@@ -1932,17 +2053,20 @@ var OIMSlotCollectionService = class {
1932
2053
  }
1933
2054
  createStoreSlot(channelMap) {
1934
2055
  const channelSlot = channelMap.defaultChannelSlot;
1935
- return this.createStoreSlotWith((store) => createOIMStoreSlot(store, channelSlot, this));
2056
+ return this.createStoreSlotOverNewStore((store) => createOIMStoreSlot(store, channelSlot, this));
1936
2057
  }
1937
2058
  createStoreSlotFrom(sourceStoreSlot) {
1938
- return this.createStoreSlotWith((store) => createOIMStoreSlot(
2059
+ return this.createStoreSlotOverNewStore((store) => createOIMStoreSlot(
1939
2060
  store,
1940
2061
  sourceStoreSlot.channelSlot,
1941
2062
  this,
1942
2063
  sourceStoreSlot
1943
2064
  ));
1944
2065
  }
1945
- createStoreSlotWith(createStoreSlotLiteral) {
2066
+ createStoreAggregate(storeSlot) {
2067
+ return new OIMSlotCollectionStoreAggregate(this, storeSlot);
2068
+ }
2069
+ createStoreSlotOverNewStore(createStoreSlotLiteral) {
1946
2070
  const storeSlot = createStoreSlotLiteral(this.slotStoreService.createStore());
1947
2071
  if (this.storeSlotListener !== void 0) this.storeSlotListener.onStoreSlotCreated(storeSlot);
1948
2072
  return storeSlot;
@@ -1976,13 +2100,13 @@ var OIMSlotCollectionService = class {
1976
2100
  return this.slotStoreService.isSameKey(key, otherKey);
1977
2101
  }
1978
2102
  openBatch(storeSlot) {
1979
- OIMContentChangeDeliveryService.INSTANCE.openBatch(storeSlot);
2103
+ OIMSlotContentChangeDeliveryService.INSTANCE.openBatch(storeSlot);
1980
2104
  }
1981
2105
  closeBatch(storeSlot) {
1982
- OIMContentChangeDeliveryService.INSTANCE.closeBatch(storeSlot);
2106
+ OIMSlotContentChangeDeliveryService.INSTANCE.closeBatch(storeSlot);
1983
2107
  }
1984
2108
  writeInBatch(storeSlot, write) {
1985
- const contentChangeDeliveryService = OIMContentChangeDeliveryService.INSTANCE;
2109
+ const contentChangeDeliveryService = OIMSlotContentChangeDeliveryService.INSTANCE;
1986
2110
  contentChangeDeliveryService.openBatch(storeSlot);
1987
2111
  try {
1988
2112
  return write();
@@ -2003,8 +2127,18 @@ var OIMSlotCollectionService = class {
2003
2127
  }
2004
2128
  };
2005
2129
 
2006
- // src/facade/slot/OIMWritableSlotCollectionService.ts
2130
+ // src/slot/OIMWritableSlotCollectionStoreAggregate.ts
2131
+ var OIMWritableSlotCollectionStoreAggregate = class extends OIMSlotCollectionStoreAggregate {
2132
+ writeSlotContentByKey(key, content, changedSlots) {
2133
+ return this.slotService.writeSlotContentByKey(this.storeSlot, key, content, changedSlots);
2134
+ }
2135
+ };
2136
+
2137
+ // src/slot/OIMWritableSlotCollectionService.ts
2007
2138
  var OIMWritableSlotCollectionService = class extends OIMSlotCollectionService {
2139
+ createStoreAggregate(storeSlot) {
2140
+ return new OIMWritableSlotCollectionStoreAggregate(this, storeSlot);
2141
+ }
2008
2142
  writeSlotContentByKey(storeSlot, key, content, changedSlots) {
2009
2143
  const filed = this.slotStoreService.get(storeSlot.store, key);
2010
2144
  if (filed !== void 0) {
@@ -2017,7 +2151,30 @@ var OIMWritableSlotCollectionService = class extends OIMSlotCollectionService {
2017
2151
  }
2018
2152
  };
2019
2153
 
2020
- // src/facade/slot/OIMSingleSlotService.ts
2154
+ // src/slot/OIMSingleSlotStoreAggregate.ts
2155
+ var OIMSingleSlotStoreAggregate = class {
2156
+ constructor(slotService, storeSlot) {
2157
+ this.slotService = slotService;
2158
+ this.storeSlot = storeSlot;
2159
+ }
2160
+ get slotContentService() {
2161
+ return this.slotService.slotContentService;
2162
+ }
2163
+ findSingleSlot() {
2164
+ return this.slotService.findSingleSlot(this.storeSlot);
2165
+ }
2166
+ hasSingleSlotContent() {
2167
+ return this.slotService.hasSingleSlotContent(this.storeSlot);
2168
+ }
2169
+ getSingleSlot() {
2170
+ return this.slotService.getSingleSlot(this.storeSlot);
2171
+ }
2172
+ holdSingleSlot() {
2173
+ return this.slotService.holdSingleSlot(this.storeSlot);
2174
+ }
2175
+ };
2176
+
2177
+ // src/slot/OIMSingleSlotService.ts
2021
2178
  var OIMSingleSlotService = class {
2022
2179
  constructor(options) {
2023
2180
  const slotOwnerService = new OIMSlotOwnerService({ ...options, slotFilingService: options.slotStoreService });
@@ -2040,6 +2197,9 @@ var OIMSingleSlotService = class {
2040
2197
  if (this.storeSlotListener !== void 0) this.storeSlotListener.onStoreSlotCreated(storeSlot);
2041
2198
  return storeSlot;
2042
2199
  }
2200
+ createStoreAggregate(storeSlot) {
2201
+ return new OIMSingleSlotStoreAggregate(this, storeSlot);
2202
+ }
2043
2203
  findSingleSlot(storeSlot) {
2044
2204
  return this.slotStoreService.getSingleSlot(storeSlot.store);
2045
2205
  }
@@ -2068,8 +2228,21 @@ var OIMSingleSlotService = class {
2068
2228
  }
2069
2229
  };
2070
2230
 
2071
- // src/facade/slot/OIMWritableSingleSlotService.ts
2231
+ // src/slot/OIMWritableSingleSlotStoreAggregate.ts
2232
+ var OIMWritableSingleSlotStoreAggregate = class extends OIMSingleSlotStoreAggregate {
2233
+ writeSingleSlotContent(content, changedSlots) {
2234
+ return this.slotService.writeSingleSlotContent(this.storeSlot, content, changedSlots);
2235
+ }
2236
+ clearSingleSlotContent() {
2237
+ this.slotService.clearSingleSlotContent(this.storeSlot);
2238
+ }
2239
+ };
2240
+
2241
+ // src/slot/OIMWritableSingleSlotService.ts
2072
2242
  var OIMWritableSingleSlotService = class extends OIMSingleSlotService {
2243
+ createStoreAggregate(storeSlot) {
2244
+ return new OIMWritableSingleSlotStoreAggregate(this, storeSlot);
2245
+ }
2073
2246
  writeSingleSlotContent(storeSlot, content, changedSlots) {
2074
2247
  const filed = this.slotStoreService.getSingleSlot(storeSlot.store);
2075
2248
  if (filed !== void 0) {
@@ -2086,7 +2259,7 @@ var OIMWritableSingleSlotService = class extends OIMSingleSlotService {
2086
2259
  }
2087
2260
  };
2088
2261
 
2089
- // src/engine/entity/OIMSlotEntityPresenceEmptinessPolicy.ts
2262
+ // src/entity/OIMSlotEntityPresenceEmptinessPolicy.ts
2090
2263
  var _OIMSlotEntityPresenceEmptinessPolicy = class _OIMSlotEntityPresenceEmptinessPolicy {
2091
2264
  isEmpty(entitySlot) {
2092
2265
  return entitySlot.entity === void 0;
@@ -2095,8 +2268,8 @@ var _OIMSlotEntityPresenceEmptinessPolicy = class _OIMSlotEntityPresenceEmptines
2095
2268
  _OIMSlotEntityPresenceEmptinessPolicy.INSTANCE = new _OIMSlotEntityPresenceEmptinessPolicy();
2096
2269
  var OIMSlotEntityPresenceEmptinessPolicy = _OIMSlotEntityPresenceEmptinessPolicy;
2097
2270
 
2098
- // src/engine/entity/utils/createOIMEntitySlot.ts
2099
- function createOIMEntitySlot(key, owner, storeSlot = void 0) {
2271
+ // src/entity/utils/createOIMEntitySlot.ts
2272
+ function createOIMEntitySlot(key, owner, storeSlot) {
2100
2273
  return {
2101
2274
  effects: void 0,
2102
2275
  changedAtRevision: 0,
@@ -2117,8 +2290,8 @@ function createOIMEntitySlot(key, owner, storeSlot = void 0) {
2117
2290
  };
2118
2291
  }
2119
2292
 
2120
- // src/engine/entity/utils/createOIMSingleEntitySlot.ts
2121
- function createOIMSingleEntitySlot(owner, storeSlot) {
2293
+ // src/entity/utils/createOIMEntityContentSlot.ts
2294
+ function createOIMEntityContentSlot(owner, storeSlot) {
2122
2295
  const singleEntitySlot = {
2123
2296
  effects: void 0,
2124
2297
  changedAtRevision: 0,
@@ -2140,7 +2313,15 @@ function createOIMSingleEntitySlot(owner, storeSlot) {
2140
2313
  return singleEntitySlot;
2141
2314
  }
2142
2315
 
2143
- // src/engine/entity/OIMSlotContentEntityService.ts
2316
+ // src/slot/utils/oimAssertSlotUnheld.ts
2317
+ var oimAssertSlotUnheld = (slot) => {
2318
+ if (slot.holdCount === 0) return;
2319
+ throw new Error(
2320
+ "releaseSlotContent: this slot is still held, so its identity is not going. The slot owner calls releaseSlotContent when it releases a slot nothing holds; to empty a held slot, use clearSlotContent."
2321
+ );
2322
+ };
2323
+
2324
+ // src/entity/OIMSlotContentEntityService.ts
2144
2325
  var OIMSlotContentEntityService = class {
2145
2326
  constructor(options) {
2146
2327
  this.entityWriter = options.entityWriter;
@@ -2151,7 +2332,7 @@ var OIMSlotContentEntityService = class {
2151
2332
  return createOIMEntitySlot(key, slotOwner, storeSlot);
2152
2333
  }
2153
2334
  createSingleSlot(storeSlot, slotOwner) {
2154
- return createOIMSingleEntitySlot(slotOwner, storeSlot);
2335
+ return createOIMEntityContentSlot(slotOwner, storeSlot);
2155
2336
  }
2156
2337
  isSlotEmpty(entitySlot) {
2157
2338
  return this.slotEmptinessPolicy.isEmpty(entitySlot);
@@ -2293,7 +2474,7 @@ var OIMSlotContentEntityService = class {
2293
2474
  slotOwnerService.assertWritable(entitySlot);
2294
2475
  const channelSlot = oimGetChannelSlot(entitySlot);
2295
2476
  if (!this.isOnFastPath(entitySlot)) {
2296
- this.releaseSlotContent(entitySlot);
2477
+ this.clearEntityAndMarkColumns(entitySlot);
2297
2478
  slotOwnerService.settleEmptiness(entitySlot, this.slotEmptinessPolicy.isEmpty(entitySlot));
2298
2479
  slotOwnerService.dispatchContentChange(entitySlot);
2299
2480
  slotOwnerService.releaseSlotIfUnheldAfterListeners(entitySlot);
@@ -2356,9 +2537,12 @@ var OIMSlotContentEntityService = class {
2356
2537
  slotOwnerService.releaseSlotIfUnheldAfterListeners(entitySlot);
2357
2538
  }
2358
2539
  releaseSlotContent(entitySlot) {
2540
+ oimAssertSlotUnheld(entitySlot);
2541
+ this.clearEntityAndMarkColumns(entitySlot);
2542
+ }
2543
+ clearEntityAndMarkColumns(entitySlot) {
2359
2544
  const entity = entitySlot.entity;
2360
2545
  if (entity === void 0) return;
2361
- this.slotOwnerServiceOf(entitySlot).assertWritable(entitySlot);
2362
2546
  this.entityWriter.clearEntity(entitySlot);
2363
2547
  this.dispatchColumnsChanged(entitySlot, entity, void 0);
2364
2548
  }
@@ -2390,34 +2574,21 @@ var OIMSlotContentEntityService = class {
2390
2574
  }
2391
2575
  };
2392
2576
 
2393
- // src/factories/defaults/OIMDefaultValue.ts
2577
+ // src/db/OIMDefaultValue.ts
2394
2578
  var OIMDefaultValue = class {
2395
- constructor(name, createValue) {
2579
+ constructor(createValue) {
2396
2580
  this.defaultValue = void 0;
2397
- this.isHandedOut = false;
2398
- this.name = name;
2399
2581
  this.createValue = createValue;
2400
2582
  }
2401
2583
  getValue() {
2402
- this.isHandedOut = true;
2403
2584
  return this.defaultValue ?? (this.defaultValue = this.createValue());
2404
2585
  }
2405
- setValue(value) {
2406
- this.assertNoLateOverride();
2407
- this.defaultValue = value;
2408
- }
2409
- assertNoLateOverride() {
2410
- if (!this.isHandedOut) return;
2411
- throw new Error(
2412
- `OIMDefaults.${this.name} has already been handed out, and whoever took it keeps it \u2014 so replacing it now leaves two implementations live in one process, the older one inside every object built before this call. Set it at startup, before anything reads it.`
2413
- );
2414
- }
2415
2586
  };
2416
2587
 
2417
- // src/factories/defaults/OIM_DEFAULT_STORE_SLOT_LISTENER.ts
2418
- var OIM_DEFAULT_STORE_SLOT_LISTENER = /* @__PURE__ */ new OIMDefaultValue("STORE_SLOT_LISTENER", () => OIMNoStoreSlotListener.INSTANCE);
2588
+ // src/db/constants/OIM_DEFAULT_STORE_SLOT_LISTENER.ts
2589
+ var OIM_DEFAULT_STORE_SLOT_LISTENER = /* @__PURE__ */ new OIMDefaultValue(() => OIMNoStoreSlotListener.INSTANCE);
2419
2590
 
2420
- // src/engine/store/OIMSlotMapStoreService.ts
2591
+ // src/store/OIMSlotMapStoreService.ts
2421
2592
  var _OIMSlotMapStoreService = class _OIMSlotMapStoreService {
2422
2593
  createStore() {
2423
2594
  return /* @__PURE__ */ new Map();
@@ -2453,16 +2624,32 @@ var _OIMSlotMapStoreService = class _OIMSlotMapStoreService {
2453
2624
  _OIMSlotMapStoreService.INSTANCE = new _OIMSlotMapStoreService();
2454
2625
  var OIMSlotMapStoreService = _OIMSlotMapStoreService;
2455
2626
 
2456
- // src/factories/utils/oimSlotStoreServiceWithDefault.ts
2457
- function oimSlotStoreServiceWithDefault(slotStoreService) {
2627
+ // src/store/utils/oimResolveSlotStoreService.ts
2628
+ function oimResolveSlotStoreService(slotStoreService) {
2458
2629
  return slotStoreService ?? OIMSlotMapStoreService.INSTANCE;
2459
2630
  }
2460
2631
 
2461
- // src/engine/column/OIMPushColumnSlotOwner.ts
2632
+ // src/db/OIMDefaults.ts
2633
+ var _OIMDefaults = class _OIMDefaults {
2634
+ constructor(options = {}) {
2635
+ this.slotStamp = options.slotStamp;
2636
+ this.slotReleasePolicy = options.slotReleasePolicy;
2637
+ this.entityWriter = options.entityWriter;
2638
+ this.entitySlotEmptinessPolicy = options.entitySlotEmptinessPolicy;
2639
+ this.indexKeysService = options.indexKeysService;
2640
+ this.columnSlotStoreService = options.columnSlotStoreService;
2641
+ this.computedColumnSlotStoreService = options.computedColumnSlotStoreService;
2642
+ this.storeSlotListener = options.storeSlotListener;
2643
+ }
2644
+ };
2645
+ _OIMDefaults.INSTANCE = new _OIMDefaults();
2646
+ var OIMDefaults = _OIMDefaults;
2647
+
2648
+ // src/column/OIMPushColumnSlotOwner.ts
2462
2649
  var hasValueColumn = (value, columnName) => Object.prototype.hasOwnProperty.call(value, columnName) && value[columnName] !== void 0;
2463
2650
  var OIMPushColumnSlotOwner = class extends OIMColumnSlotOwner {
2464
2651
  constructor(options) {
2465
- super(oimColumnSlotStoreServiceOfColumnOwnerOptions(options));
2652
+ super(oimColumnSlotStoreServiceOfColumnSlotOwnerOptions(options));
2466
2653
  }
2467
2654
  createColumnSlot(carrierSlot, key) {
2468
2655
  return {
@@ -2476,7 +2663,7 @@ var OIMPushColumnSlotOwner = class extends OIMColumnSlotOwner {
2476
2663
  releaseDueAfterUnholdMs: -1,
2477
2664
  slotFlags: OIM_SLOT_FLAG_EMPTY,
2478
2665
  columnSlotStore: void 0,
2479
- storeSlot: void 0,
2666
+ storeSlot: carrierSlot.storeSlot,
2480
2667
  owner: this,
2481
2668
  key,
2482
2669
  carrierSlot
@@ -2545,51 +2732,51 @@ var OIMPushColumnSlotOwner = class extends OIMColumnSlotOwner {
2545
2732
  }
2546
2733
  };
2547
2734
 
2548
- // src/engine/column/utils/createOIMPushColumnSlotOwner.ts
2735
+ // src/column/utils/createOIMPushColumnSlotOwner.ts
2549
2736
  var createOIMPushColumnSlotOwner = (columnSlotOwnerOptions) => new OIMPushColumnSlotOwner(columnSlotOwnerOptions);
2550
2737
 
2551
- // src/factories/defaults/OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.ts
2552
- var OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE = /* @__PURE__ */ new OIMDefaultValue("COLUMN_SLOT_STORE_SERVICE", () => OIMSlotMapStoreService.INSTANCE);
2738
+ // src/db/constants/OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.ts
2739
+ var OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE = /* @__PURE__ */ new OIMDefaultValue(() => OIMSlotMapStoreService.INSTANCE);
2553
2740
 
2554
- // src/engine/column/utils/oimColumnOwnerOptions.ts
2555
- function oimColumnOwnerOptions(columnSlotOwnerOptions) {
2741
+ // src/column/utils/oimColumnSlotOwnerOptions.ts
2742
+ function oimColumnSlotOwnerOptions(columnSlotOwnerOptions) {
2556
2743
  return columnSlotOwnerOptions.columnNames !== void 0 ? { columnNames: columnSlotOwnerOptions.columnNames } : { columnSlotStoreService: columnSlotOwnerOptions.columnSlotStoreService };
2557
2744
  }
2558
2745
 
2559
- // src/factories/utils/oimColumnOwnerOptionsWithDefault.ts
2560
- function oimColumnOwnerOptionsWithDefault(columnSlotStoreService, columnNames, defaultColumnSlotStoreService) {
2561
- return oimColumnOwnerOptions({ columnNames, columnSlotStoreService: columnSlotStoreService ?? defaultColumnSlotStoreService });
2746
+ // src/column/utils/oimResolveColumnSlotOwnerOptions.ts
2747
+ function oimResolveColumnSlotOwnerOptions(columnSlotStoreService, columnNames, defaultColumnSlotStoreService) {
2748
+ return oimColumnSlotOwnerOptions({ columnNames, columnSlotStoreService: columnSlotStoreService ?? defaultColumnSlotStoreService });
2562
2749
  }
2563
2750
 
2564
- // src/factories/utils/oimSlotOwnerOptionsWithDefault.ts
2565
- function oimSlotOwnerOptionsWithDefault(db, options) {
2751
+ // src/slot/utils/oimResolveSlotOwnerServiceOptions.ts
2752
+ function oimResolveSlotOwnerServiceOptions(defaults, options) {
2566
2753
  return {
2567
- slotStamp: db.slotStamp,
2568
- slotReleasePolicy: options.slotReleasePolicy ?? db.slotReleasePolicy,
2754
+ slotStamp: defaults.slotStamp,
2755
+ slotReleasePolicy: options.slotReleasePolicy ?? defaults.slotReleasePolicy,
2569
2756
  slotSubscriptionListener: options.slotSubscriptionListener,
2570
- columnSlotOwnerOptions: oimColumnOwnerOptionsWithDefault(
2757
+ columnSlotOwnerOptions: oimResolveColumnSlotOwnerOptions(
2571
2758
  options.columnSlotStoreService,
2572
2759
  options.columnNames,
2573
- OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.getValue()
2760
+ defaults.columnSlotStoreService ?? OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.getValue()
2574
2761
  ),
2575
2762
  createColumnSlotOwner: createOIMPushColumnSlotOwner
2576
2763
  };
2577
2764
  }
2578
2765
 
2579
- // src/factories/createOIMSlotCollectionService.ts
2580
- function createOIMSlotCollectionService(db, options) {
2766
+ // src/slot/createOIMSlotCollectionService.ts
2767
+ function createOIMSlotCollectionService(options) {
2581
2768
  return new OIMWritableSlotCollectionService({
2582
- ...oimSlotOwnerOptionsWithDefault(db, options),
2583
- slotStoreService: oimSlotStoreServiceWithDefault(options.slotStoreService),
2769
+ ...oimResolveSlotOwnerServiceOptions(options.defaults ?? OIMDefaults.INSTANCE, options),
2770
+ slotStoreService: oimResolveSlotStoreService(options.slotStoreService),
2584
2771
  slotContentService: options.slotContentService,
2585
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2772
+ storeSlotListener: options.defaults?.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2586
2773
  });
2587
2774
  }
2588
2775
 
2589
- // src/engine/slot/constants/OIM_FROZEN_EMPTY_SLOTS.ts
2776
+ // src/slot/constants/OIM_FROZEN_EMPTY_SLOTS.ts
2590
2777
  var OIM_FROZEN_EMPTY_SLOTS = Object.freeze([]);
2591
2778
 
2592
- // src/engine/store/OIMSingleSlotStoreService.ts
2779
+ // src/store/OIMSingleSlotStoreService.ts
2593
2780
  var _OIMSingleSlotStoreService = class _OIMSingleSlotStoreService {
2594
2781
  createStore() {
2595
2782
  return { slot: void 0 };
@@ -2614,36 +2801,48 @@ var _OIMSingleSlotStoreService = class _OIMSingleSlotStoreService {
2614
2801
  _OIMSingleSlotStoreService.INSTANCE = new _OIMSingleSlotStoreService();
2615
2802
  var OIMSingleSlotStoreService = _OIMSingleSlotStoreService;
2616
2803
 
2617
- // src/factories/createOIMSingleSlotService.ts
2618
- function createOIMSingleSlotService(db, options) {
2804
+ // src/slot/createOIMSingleSlotService.ts
2805
+ function createOIMSingleSlotService(options) {
2619
2806
  return new OIMWritableSingleSlotService({
2620
- ...oimSlotOwnerOptionsWithDefault(db, options),
2807
+ ...oimResolveSlotOwnerServiceOptions(options.defaults ?? OIMDefaults.INSTANCE, options),
2621
2808
  slotStoreService: OIMSingleSlotStoreService.INSTANCE,
2622
2809
  slotContentService: options.slotContentService,
2623
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2810
+ storeSlotListener: options.defaults?.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2624
2811
  });
2625
2812
  }
2626
2813
 
2627
- // src/factories/defaults/OIM_DEFAULT_ENTITY_SLOT_EMPTINESS.ts
2628
- var OIM_DEFAULT_ENTITY_SLOT_EMPTINESS = /* @__PURE__ */ new OIMDefaultValue("ENTITY_SLOT_EMPTINESS", () => OIMSlotEntityPresenceEmptinessPolicy.INSTANCE);
2814
+ // src/slot/createOIMSlotCollectionStoreAggregate.ts
2815
+ function createOIMSlotCollectionStoreAggregate(channelMap, options) {
2816
+ const slotCollectionService = createOIMSlotCollectionService(options);
2817
+ return slotCollectionService.createStoreAggregate(slotCollectionService.createStoreSlot(channelMap));
2818
+ }
2819
+
2820
+ // src/slot/createOIMSingleSlotStoreAggregate.ts
2821
+ function createOIMSingleSlotStoreAggregate(channelMap, options) {
2822
+ const singleSlotService = createOIMSingleSlotService(options);
2823
+ return singleSlotService.createStoreAggregate(singleSlotService.createStoreSlot(channelMap));
2824
+ }
2825
+
2826
+ // src/db/constants/OIM_DEFAULT_ENTITY_SLOT_EMPTINESS_POLICY.ts
2827
+ var OIM_DEFAULT_ENTITY_SLOT_EMPTINESS_POLICY = /* @__PURE__ */ new OIMDefaultValue(() => OIMSlotEntityPresenceEmptinessPolicy.INSTANCE);
2629
2828
 
2630
- // src/engine/entity/utils/oimClearEntity.ts
2829
+ // src/entity/utils/oimClearEntity.ts
2631
2830
  function oimClearEntity(entitySlot) {
2632
2831
  entitySlot.entity = void 0;
2633
2832
  }
2634
2833
 
2635
- // src/engine/entity/constants/OIM_FROZEN_EMPTY_COLUMN_NAMES.ts
2834
+ // src/entity/constants/OIM_FROZEN_EMPTY_COLUMN_NAMES.ts
2636
2835
  var OIM_FROZEN_EMPTY_COLUMN_NAMES = Object.freeze([]);
2637
2836
 
2638
- // src/engine/entity/constants/OIM_PROTO_KEY.ts
2837
+ // src/entity/constants/OIM_PROTO_KEY.ts
2639
2838
  var OIM_PROTO_KEY = "__proto__";
2640
2839
 
2641
- // src/engine/entity/utils/oimIsProtoKey.ts
2840
+ // src/entity/utils/oimIsProtoKey.ts
2642
2841
  function oimIsProtoKey(name) {
2643
2842
  return name === OIM_PROTO_KEY;
2644
2843
  }
2645
2844
 
2646
- // src/engine/entity/utils/oimOwnedColumnNames.ts
2845
+ // src/entity/utils/oimOwnedColumnNames.ts
2647
2846
  function oimOwnedColumnNames(slot, names) {
2648
2847
  const entity = slot.entity;
2649
2848
  if (entity === void 0) return void 0;
@@ -2657,12 +2856,12 @@ function oimOwnedColumnNames(slot, names) {
2657
2856
  return owned;
2658
2857
  }
2659
2858
 
2660
- // src/engine/entity/utils/oimInsertEntityWithoutCopy.ts
2859
+ // src/entity/utils/oimInsertEntityWithoutCopy.ts
2661
2860
  function oimInsertEntityWithoutCopy(slot, entity) {
2662
2861
  slot.entity = entity;
2663
2862
  }
2664
2863
 
2665
- // src/engine/entity/utils/oimPatchEntityColumns.ts
2864
+ // src/entity/utils/oimPatchEntityColumns.ts
2666
2865
  function oimPatchEntityColumns(slot, patch, sameValueGuard, changedColumnNames, targetOf) {
2667
2866
  const entity = slot.entity;
2668
2867
  if (entity === void 0) return void 0;
@@ -2676,7 +2875,7 @@ function oimPatchEntityColumns(slot, patch, sameValueGuard, changedColumnNames,
2676
2875
  return target;
2677
2876
  }
2678
2877
 
2679
- // src/engine/entity/utils/oimPatchEntityColumn.ts
2878
+ // src/entity/utils/oimPatchEntityColumn.ts
2680
2879
  function oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, targetOf) {
2681
2880
  const entity = slot.entity;
2682
2881
  if (entity === void 0) return void 0;
@@ -2687,7 +2886,7 @@ function oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedCo
2687
2886
  return target;
2688
2887
  }
2689
2888
 
2690
- // src/engine/entity/utils/oimClearDepartedEntityColumns.ts
2889
+ // src/entity/utils/oimClearDepartedEntityColumns.ts
2691
2890
  function oimClearDepartedEntityColumns(prevColumns, prevEntity, entity, patchedTarget, changedColumnNames, targetOf) {
2692
2891
  let target = patchedTarget;
2693
2892
  for (const name in prevColumns) {
@@ -2699,7 +2898,7 @@ function oimClearDepartedEntityColumns(prevColumns, prevEntity, entity, patchedT
2699
2898
  return target;
2700
2899
  }
2701
2900
 
2702
- // src/engine/entity/utils/oimPutEntityColumns.ts
2901
+ // src/entity/utils/oimPutEntityColumns.ts
2703
2902
  function oimPutEntityColumns(slot, entity, sameValueGuard, changedColumnNames, targetOf) {
2704
2903
  const prevEntity = slot.entity;
2705
2904
  if (prevEntity === void 0) return void 0;
@@ -2707,8 +2906,8 @@ function oimPutEntityColumns(slot, entity, sameValueGuard, changedColumnNames, t
2707
2906
  return oimClearDepartedEntityColumns(prevEntity, prevEntity, entity, target, changedColumnNames, targetOf);
2708
2907
  }
2709
2908
 
2710
- // src/factories/utils/oimEntityWriterOptionsWithDefault.ts
2711
- function oimEntityWriterOptionsWithDefault(options) {
2909
+ // src/entity/utils/oimResolveEntityWriterOptions.ts
2910
+ function oimResolveEntityWriterOptions(options) {
2712
2911
  return {
2713
2912
  sameValueGuard: options?.sameValueGuard ?? oimSameValueZeroGuard,
2714
2913
  entityInserter: options?.entityInserter ?? oimInsertEntityWithoutCopy,
@@ -2718,7 +2917,7 @@ function oimEntityWriterOptionsWithDefault(options) {
2718
2917
  };
2719
2918
  }
2720
2919
 
2721
- // src/factories/createOIMEntityWriterInPlace.ts
2920
+ // src/entity/createOIMInPlaceEntityWriter.ts
2722
2921
  var theEntityItself = (entity) => entity;
2723
2922
  function deleteColumnsInPlace(slot, names) {
2724
2923
  const deleted = oimOwnedColumnNames(slot, names);
@@ -2727,14 +2926,14 @@ function deleteColumnsInPlace(slot, names) {
2727
2926
  for (let i = 0; i < deleted.length; i++) entity[deleted[i]] = void 0;
2728
2927
  return deleted;
2729
2928
  }
2730
- function createOIMEntityWriterInPlace(options) {
2929
+ function createOIMInPlaceEntityWriter(options) {
2731
2930
  const {
2732
2931
  sameValueGuard,
2733
2932
  entityInserter,
2734
2933
  putEntityColumns,
2735
2934
  patchEntityColumns,
2736
2935
  patchEntityColumn
2737
- } = oimEntityWriterOptionsWithDefault(options);
2936
+ } = oimResolveEntityWriterOptions(options);
2738
2937
  return {
2739
2938
  fillEntity: entityInserter,
2740
2939
  clearEntity: oimClearEntity,
@@ -2745,19 +2944,20 @@ function createOIMEntityWriterInPlace(options) {
2745
2944
  };
2746
2945
  }
2747
2946
 
2748
- // src/factories/defaults/OIM_DEFAULT_ENTITY_WRITER.ts
2749
- var OIM_DEFAULT_ENTITY_WRITER = /* @__PURE__ */ new OIMDefaultValue("ENTITY_WRITER", () => createOIMEntityWriterInPlace());
2947
+ // src/db/constants/OIM_DEFAULT_ENTITY_WRITER.ts
2948
+ var OIM_DEFAULT_ENTITY_WRITER = /* @__PURE__ */ new OIMDefaultValue(() => createOIMInPlaceEntityWriter());
2750
2949
 
2751
- // src/factories/createOIMSlotContentEntityService.ts
2752
- function createOIMSlotContentEntityService(db, options = {}) {
2950
+ // src/entity/createOIMSlotContentEntityService.ts
2951
+ function createOIMSlotContentEntityService(options = {}) {
2952
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
2753
2953
  return new OIMSlotContentEntityService({
2754
- entityWriter: options.entityWriter ?? db.entityWriter ?? OIM_DEFAULT_ENTITY_WRITER.getValue(),
2755
- slotEmptinessPolicy: options.slotEmptinessPolicy ?? OIM_DEFAULT_ENTITY_SLOT_EMPTINESS.getValue()
2954
+ entityWriter: options.entityWriter ?? defaults.entityWriter ?? OIM_DEFAULT_ENTITY_WRITER.getValue(),
2955
+ slotEmptinessPolicy: options.slotEmptinessPolicy ?? defaults.entitySlotEmptinessPolicy ?? OIM_DEFAULT_ENTITY_SLOT_EMPTINESS_POLICY.getValue()
2756
2956
  });
2757
2957
  }
2758
2958
 
2759
- // src/engine/bucket/utils/createOIMSingleBucketSlot.ts
2760
- function createOIMSingleBucketSlot(owner, bucketSlotsStore, storeSlot) {
2959
+ // src/bucket/utils/createOIMBucketContentSlot.ts
2960
+ function createOIMBucketContentSlot(owner, bucketSlotsStore, storeSlot) {
2761
2961
  const singleBucketSlot = {
2762
2962
  effects: void 0,
2763
2963
  changedAtRevision: 0,
@@ -2782,7 +2982,7 @@ function createOIMSingleBucketSlot(owner, bucketSlotsStore, storeSlot) {
2782
2982
  return singleBucketSlot;
2783
2983
  }
2784
2984
 
2785
- // src/engine/bucket/commands/OIMNoBucketCommands.ts
2985
+ // src/bucket/commands/OIMNoBucketCommands.ts
2786
2986
  var _OIMNoBucketCommands = class _OIMNoBucketCommands {
2787
2987
  recordInsert() {
2788
2988
  return;
@@ -2800,13 +3000,13 @@ var _OIMNoBucketCommands = class _OIMNoBucketCommands {
2800
3000
  _OIMNoBucketCommands.INSTANCE = new _OIMNoBucketCommands();
2801
3001
  var OIMNoBucketCommands = _OIMNoBucketCommands;
2802
3002
 
2803
- // src/engine/bucket/constants/OIM_NOTHING_WAS_REMOVED.ts
3003
+ // src/bucket/constants/OIM_NOTHING_WAS_REMOVED.ts
2804
3004
  var OIM_NOTHING_WAS_REMOVED = -1;
2805
3005
 
2806
- // src/engine/bucket/constants/OIM_REMOVED_WITHOUT_A_POSITION.ts
3006
+ // src/bucket/constants/OIM_REMOVED_WITHOUT_A_POSITION.ts
2807
3007
  var OIM_REMOVED_WITHOUT_A_POSITION = -2;
2808
3008
 
2809
- // src/engine/bucket/utils/createOIMBucketSlot.ts
3009
+ // src/bucket/utils/createOIMBucketSlot.ts
2810
3010
  function createOIMBucketSlot(key, owner, bucketSlotsStore, storeSlot) {
2811
3011
  return {
2812
3012
  effects: void 0,
@@ -2831,16 +3031,16 @@ function createOIMBucketSlot(key, owner, bucketSlotsStore, storeSlot) {
2831
3031
  };
2832
3032
  }
2833
3033
 
2834
- // src/engine/channel/utils/oimGetChannelQueueAtDepth.ts
3034
+ // src/channel/utils/oimGetChannelQueueAtDepth.ts
2835
3035
  function oimGetChannelQueueAtDepth(channelQueues, depth) {
2836
- const found = channelQueues[depth];
2837
- if (found !== void 0) return found;
2838
- const made = new OIMChannelQueue();
2839
- channelQueues[depth] = made;
2840
- return made;
3036
+ const existingChannelQueue = channelQueues[depth];
3037
+ if (existingChannelQueue !== void 0) return existingChannelQueue;
3038
+ const channelQueue = new OIMChannelQueue();
3039
+ channelQueues[depth] = channelQueue;
3040
+ return channelQueue;
2841
3041
  }
2842
3042
 
2843
- // src/facade/bucket/OIMSlotContentBucketService.ts
3043
+ // src/bucket/OIMSlotContentBucketService.ts
2844
3044
  var OIMSlotContentBucketService = class {
2845
3045
  constructor(options) {
2846
3046
  this.bucketCommands = options.bucketCommands ?? OIMNoBucketCommands.INSTANCE;
@@ -2862,7 +3062,7 @@ var OIMSlotContentBucketService = class {
2862
3062
  );
2863
3063
  }
2864
3064
  createSingleSlot(storeSlot, slotOwner) {
2865
- return createOIMSingleBucketSlot(
3065
+ return createOIMBucketContentSlot(
2866
3066
  slotOwner,
2867
3067
  this.createBucketMemberSlotsStore(),
2868
3068
  storeSlot
@@ -2874,11 +3074,9 @@ var OIMSlotContentBucketService = class {
2874
3074
  hasReference() {
2875
3075
  return false;
2876
3076
  }
2877
- releaseSlotContent(bucketSlot, slotOwnerService) {
2878
- if (this.getBucketMemberSlotCount(bucketSlot) === 0) return;
2879
- slotOwnerService.assertWritable(bucketSlot);
3077
+ releaseSlotContent(bucketSlot) {
3078
+ oimAssertSlotUnheld(bucketSlot);
2880
3079
  this.unholdAllBucketMemberSlots(bucketSlot);
2881
- slotOwnerService.dispatchContentChange(bucketSlot);
2882
3080
  }
2883
3081
  markContentChanged(bucketSlot) {
2884
3082
  bucketSlot.owner.assertWritable(bucketSlot);
@@ -2917,10 +3115,10 @@ var OIMSlotContentBucketService = class {
2917
3115
  removeBucketMemberSlots(bucketSlot, bucketMemberSlots) {
2918
3116
  const slotOwnerService = bucketSlot.owner;
2919
3117
  slotOwnerService.assertWritable(bucketSlot);
2920
- const storeSlotEditable = bucketSlot.storeSlot;
2921
- const writeDepth = storeSlotEditable.writeDepth++;
2922
- const removedChannelQueue = oimGetChannelQueueAtDepth(storeSlotEditable.departedBucketMemberSlotChannelQueues ?? (storeSlotEditable.departedBucketMemberSlotChannelQueues = []), writeDepth);
2923
- const removedAtChannelQueue = oimGetChannelQueueAtDepth(storeSlotEditable.removedAtChannelQueues ?? (storeSlotEditable.removedAtChannelQueues = []), writeDepth);
3118
+ const editableStoreSlot = bucketSlot.storeSlot;
3119
+ const writeDepth = editableStoreSlot.writeDepth++;
3120
+ const removedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.departedBucketMemberSlotChannelQueues ?? (editableStoreSlot.departedBucketMemberSlotChannelQueues = []), writeDepth);
3121
+ const removedAtChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.removedAtChannelQueues ?? (editableStoreSlot.removedAtChannelQueues = []), writeDepth);
2924
3122
  try {
2925
3123
  this.removeSlots(bucketSlot, bucketMemberSlots, removedChannelQueue, removedAtChannelQueue);
2926
3124
  const removedCount = removedChannelQueue.getEntryCount();
@@ -2931,7 +3129,7 @@ var OIMSlotContentBucketService = class {
2931
3129
  } finally {
2932
3130
  removedChannelQueue.keepFirstEntries(0);
2933
3131
  removedAtChannelQueue.keepFirstEntries(0);
2934
- storeSlotEditable.writeDepth = writeDepth;
3132
+ editableStoreSlot.writeDepth = writeDepth;
2935
3133
  }
2936
3134
  }
2937
3135
  insertSlotContent(bucketSlot, bucketMemberSlots, changedBucketSlots) {
@@ -3004,10 +3202,10 @@ var OIMSlotContentBucketService = class {
3004
3202
  }
3005
3203
  reconcileBucketMemberSlots(bucketSlot, bucketMemberSlots) {
3006
3204
  this.assertBucketMemberSlotsNotReleased(bucketMemberSlots);
3007
- const storeSlotEditable = bucketSlot.storeSlot;
3008
- const writeDepth = storeSlotEditable.writeDepth++;
3009
- const arrivedChannelQueue = oimGetChannelQueueAtDepth(storeSlotEditable.arrivedBucketMemberSlotChannelQueues ?? (storeSlotEditable.arrivedBucketMemberSlotChannelQueues = []), writeDepth);
3010
- const departedChannelQueue = oimGetChannelQueueAtDepth(storeSlotEditable.departedBucketMemberSlotChannelQueues ?? (storeSlotEditable.departedBucketMemberSlotChannelQueues = []), writeDepth);
3205
+ const editableStoreSlot = bucketSlot.storeSlot;
3206
+ const writeDepth = editableStoreSlot.writeDepth++;
3207
+ const arrivedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.arrivedBucketMemberSlotChannelQueues ?? (editableStoreSlot.arrivedBucketMemberSlotChannelQueues = []), writeDepth);
3208
+ const departedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.departedBucketMemberSlotChannelQueues ?? (editableStoreSlot.departedBucketMemberSlotChannelQueues = []), writeDepth);
3011
3209
  try {
3012
3210
  this.reconcileSlots(bucketSlot, bucketMemberSlots, arrivedChannelQueue, departedChannelQueue);
3013
3211
  const arrivedCount = arrivedChannelQueue.getEntryCount();
@@ -3023,7 +3221,7 @@ var OIMSlotContentBucketService = class {
3023
3221
  } finally {
3024
3222
  arrivedChannelQueue.keepFirstEntries(0);
3025
3223
  departedChannelQueue.keepFirstEntries(0);
3026
- storeSlotEditable.writeDepth = writeDepth;
3224
+ editableStoreSlot.writeDepth = writeDepth;
3027
3225
  }
3028
3226
  }
3029
3227
  drainBucketMemberSlots(bucketSlot) {
@@ -3033,9 +3231,9 @@ var OIMSlotContentBucketService = class {
3033
3231
  return true;
3034
3232
  }
3035
3233
  unholdAllBucketMemberSlots(bucketSlot) {
3036
- const storeSlotEditable = bucketSlot.storeSlot;
3037
- const writeDepth = storeSlotEditable.writeDepth++;
3038
- const departedChannelQueue = oimGetChannelQueueAtDepth(storeSlotEditable.departedBucketMemberSlotChannelQueues ?? (storeSlotEditable.departedBucketMemberSlotChannelQueues = []), writeDepth);
3234
+ const editableStoreSlot = bucketSlot.storeSlot;
3235
+ const writeDepth = editableStoreSlot.writeDepth++;
3236
+ const departedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.departedBucketMemberSlotChannelQueues ?? (editableStoreSlot.departedBucketMemberSlotChannelQueues = []), writeDepth);
3039
3237
  try {
3040
3238
  this.drainSlots(bucketSlot, departedChannelQueue);
3041
3239
  const drainedCount = departedChannelQueue.getEntryCount();
@@ -3043,12 +3241,12 @@ var OIMSlotContentBucketService = class {
3043
3241
  return drainedCount;
3044
3242
  } finally {
3045
3243
  departedChannelQueue.keepFirstEntries(0);
3046
- storeSlotEditable.writeDepth = writeDepth;
3244
+ editableStoreSlot.writeDepth = writeDepth;
3047
3245
  }
3048
3246
  }
3049
3247
  };
3050
3248
 
3051
- // src/facade/bucket/OIMSlotContentSetBucketService.ts
3249
+ // src/bucket/OIMSlotContentSetBucketService.ts
3052
3250
  var OIMSlotContentSetBucketService = class extends OIMSlotContentBucketService {
3053
3251
  constructor(options = {}) {
3054
3252
  super(options);
@@ -3103,7 +3301,7 @@ var OIMSlotContentSetBucketService = class extends OIMSlotContentBucketService {
3103
3301
  }
3104
3302
  };
3105
3303
 
3106
- // src/engine/bucket/array/OIMBucketMemberSlotsArrayService.ts
3304
+ // src/bucket/array/OIMBucketMemberSlotsArrayService.ts
3107
3305
  var insertionTailLimit = 8;
3108
3306
  var _OIMBucketMemberSlotsArrayService = class _OIMBucketMemberSlotsArrayService {
3109
3307
  createBucketSlotsArrayStore() {
@@ -3232,7 +3430,7 @@ function reverseRange(bucketMemberSlots, first, last) {
3232
3430
  }
3233
3431
  }
3234
3432
 
3235
- // src/facade/bucket/OIMSlotContentArrayBucketService.ts
3433
+ // src/bucket/OIMSlotContentArrayBucketService.ts
3236
3434
  var OIMSlotContentArrayBucketService = class extends OIMSlotContentBucketService {
3237
3435
  constructor(options) {
3238
3436
  super(options);
@@ -3293,10 +3491,10 @@ var OIMSlotContentArrayBucketService = class extends OIMSlotContentBucketService
3293
3491
  }
3294
3492
  };
3295
3493
 
3296
- // src/engine/bucket/constants/OIM_NOTHING_WAS_INSERTED.ts
3494
+ // src/bucket/constants/OIM_NOTHING_WAS_INSERTED.ts
3297
3495
  var OIM_NOTHING_WAS_INSERTED = -1;
3298
3496
 
3299
- // src/engine/bucket/array/utils/oimAssertWholePosition.ts
3497
+ // src/bucket/array/utils/oimAssertWholePosition.ts
3300
3498
  function oimAssertWholePosition(position) {
3301
3499
  if (position === Math.trunc(position)) return;
3302
3500
  throw new Error(
@@ -3304,7 +3502,7 @@ function oimAssertWholePosition(position) {
3304
3502
  );
3305
3503
  }
3306
3504
 
3307
- // src/facade/bucket/OIMSlotContentPositionalArrayBucketService.ts
3505
+ // src/bucket/OIMSlotContentPositionalArrayBucketService.ts
3308
3506
  var OIMSlotContentPositionalArrayBucketService = class extends OIMSlotContentArrayBucketService {
3309
3507
  constructor(options = {}) {
3310
3508
  super(options);
@@ -3377,7 +3575,7 @@ var OIMSlotContentPositionalArrayBucketService = class extends OIMSlotContentArr
3377
3575
  }
3378
3576
  };
3379
3577
 
3380
- // src/engine/bucket/utils/oimSameUniqueSlotSequence.ts
3578
+ // src/bucket/utils/oimSameUniqueSlotSequence.ts
3381
3579
  function oimSameUniqueSlotSequence(heldBucketMemberSlots, bucketMemberSlots) {
3382
3580
  const seenBucketMemberSlots = /* @__PURE__ */ new Set();
3383
3581
  let at = 0;
@@ -3391,7 +3589,7 @@ function oimSameUniqueSlotSequence(heldBucketMemberSlots, bucketMemberSlots) {
3391
3589
  return at === heldBucketMemberSlots.length;
3392
3590
  }
3393
3591
 
3394
- // src/engine/bucket/array/OIMBucketUniqueMemberSlotsArrayService.ts
3592
+ // src/bucket/array/OIMBucketUniqueMemberSlotsArrayService.ts
3395
3593
  var _OIMBucketUniqueMemberSlotsArrayService = class _OIMBucketUniqueMemberSlotsArrayService extends OIMBucketMemberSlotsArrayService {
3396
3594
  createBucketSlotsArrayStore() {
3397
3595
  return { bucketMemberSlots: [], uniqueBucketMemberSlots: /* @__PURE__ */ new Set(), sortedCount: 0 };
@@ -3450,7 +3648,7 @@ function uniqueBucketMemberSlotsOf(bucketSlotsArrayStore) {
3450
3648
  return bucketSlotsArrayStore.uniqueBucketMemberSlots;
3451
3649
  }
3452
3650
 
3453
- // src/facade/bucket/OIMSlotContentSortedArrayBucketService.ts
3651
+ // src/bucket/OIMSlotContentSortedArrayBucketService.ts
3454
3652
  var OIMSlotContentSortedArrayBucketService = class extends OIMSlotContentArrayBucketService {
3455
3653
  constructor(options) {
3456
3654
  super(options);
@@ -3480,169 +3678,7 @@ var OIMSlotContentSortedArrayBucketService = class extends OIMSlotContentArrayBu
3480
3678
  }
3481
3679
  };
3482
3680
 
3483
- // src/factories/defaults/OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.ts
3484
- var OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE = /* @__PURE__ */ new OIMDefaultValue("COMPUTED_COLUMN_SLOT_STORE_SERVICE", () => OIMSlotMapStoreService.INSTANCE);
3485
-
3486
- // src/engine/index/OIMIndexKeysService.ts
3487
- var OIMIndexKeysService = class {
3488
- createPositions() {
3489
- return { nextPosition: 0, freePositions: [] };
3490
- }
3491
- get(slot, position) {
3492
- const indexKeys = slot.indexKeys;
3493
- return indexKeys === void 0 || position >= indexKeys.length ? void 0 : indexKeys[position];
3494
- }
3495
- set(slot, position, indexKey) {
3496
- const indexKeys = slot.indexKeys;
3497
- if (indexKeys !== void 0) {
3498
- if (position < indexKeys.length) {
3499
- indexKeys[position] = indexKey;
3500
- return;
3501
- }
3502
- if (indexKey === void 0) return;
3503
- while (indexKeys.length < position) indexKeys.push(void 0);
3504
- indexKeys.push(indexKey);
3505
- return;
3506
- }
3507
- if (indexKey === void 0) return;
3508
- const created = [];
3509
- while (created.length < position) created.push(void 0);
3510
- created.push(indexKey);
3511
- slot.indexKeys = created;
3512
- }
3513
- };
3514
-
3515
- // src/engine/index/OIMAppendingIndexKeysService.ts
3516
- var _OIMAppendingIndexKeysService = class _OIMAppendingIndexKeysService extends OIMIndexKeysService {
3517
- allocatePosition(positions) {
3518
- return positions.nextPosition++;
3519
- }
3520
- releasePosition() {
3521
- return;
3522
- }
3523
- };
3524
- _OIMAppendingIndexKeysService.INSTANCE = new _OIMAppendingIndexKeysService();
3525
- var OIMAppendingIndexKeysService = _OIMAppendingIndexKeysService;
3526
-
3527
- // src/factories/defaults/OIM_DEFAULT_INDEX_KEYS_SERVICE.ts
3528
- var OIM_DEFAULT_INDEX_KEYS_SERVICE = /* @__PURE__ */ new OIMDefaultValue("INDEX_KEYS_SERVICE", () => OIMAppendingIndexKeysService.INSTANCE);
3529
-
3530
- // src/engine/key/OIMKeyTreeWalk.ts
3531
- var OIMKeyTreeWalk = class {
3532
- mintNodeAt(rootCompositeKeyNode, compositeKey) {
3533
- if (compositeKey.length === 0) throw new Error("OIMKeyTreeWalk: an empty key is not a key.");
3534
- let compositeKeyNode = rootCompositeKeyNode;
3535
- let firstMintedDepth = -1;
3536
- let parentOfFirstMintedCompositeKeyNode = rootCompositeKeyNode;
3537
- for (let i = 0; i < compositeKey.length; i++) {
3538
- const compositeKeyPart = compositeKey[i];
3539
- let nextCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKeyPart);
3540
- if (nextCompositeKeyNode === void 0) {
3541
- try {
3542
- this.holdCompositeKeyPart(compositeKeyPart);
3543
- } catch (failure) {
3544
- if (firstMintedDepth >= 0) {
3545
- parentOfFirstMintedCompositeKeyNode.childNodes?.delete(compositeKey[firstMintedDepth]);
3546
- for (let j = i - 1; j >= firstMintedDepth; j--) this.unholdCompositeKeyPart(compositeKey[j]);
3547
- }
3548
- throw failure;
3549
- }
3550
- nextCompositeKeyNode = { childNodes: void 0, atThisKey: void 0 };
3551
- (compositeKeyNode.childNodes ?? (compositeKeyNode.childNodes = /* @__PURE__ */ new Map())).set(compositeKeyPart, nextCompositeKeyNode);
3552
- if (firstMintedDepth < 0) {
3553
- firstMintedDepth = i;
3554
- parentOfFirstMintedCompositeKeyNode = compositeKeyNode;
3555
- }
3556
- }
3557
- compositeKeyNode = nextCompositeKeyNode;
3558
- }
3559
- return compositeKeyNode;
3560
- }
3561
- nodeAt(rootCompositeKeyNode, compositeKey) {
3562
- let compositeKeyNode = rootCompositeKeyNode;
3563
- for (let i = 0; i < compositeKey.length; i++) {
3564
- compositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[i]);
3565
- if (compositeKeyNode === void 0) return void 0;
3566
- }
3567
- return compositeKeyNode;
3568
- }
3569
- deleteKey(rootCompositeKeyNode, compositeKey) {
3570
- const lastDepth = compositeKey.length - 1;
3571
- if (lastDepth < 0) return void 0;
3572
- let compositeKeyNode = rootCompositeKeyNode;
3573
- let keptCompositeKeyNode = rootCompositeKeyNode;
3574
- let firstUnlinkedDepth = 0;
3575
- for (let i = 0; i < lastDepth; i++) {
3576
- const nextCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[i]);
3577
- if (nextCompositeKeyNode === void 0) return void 0;
3578
- compositeKeyNode = nextCompositeKeyNode;
3579
- if (compositeKeyNode.atThisKey !== void 0 || (compositeKeyNode.childNodes?.size ?? 0) > 1) {
3580
- keptCompositeKeyNode = compositeKeyNode;
3581
- firstUnlinkedDepth = i + 1;
3582
- }
3583
- }
3584
- const lastCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[lastDepth]);
3585
- if (lastCompositeKeyNode === void 0) return void 0;
3586
- const deletedAtKey = lastCompositeKeyNode.atThisKey;
3587
- if (deletedAtKey === void 0) return void 0;
3588
- lastCompositeKeyNode.atThisKey = void 0;
3589
- if ((lastCompositeKeyNode.childNodes?.size ?? 0) > 0) return deletedAtKey;
3590
- keptCompositeKeyNode.childNodes?.delete(compositeKey[firstUnlinkedDepth]);
3591
- for (let i = lastDepth; i >= firstUnlinkedDepth; i--) this.unholdCompositeKeyPart(compositeKey[i]);
3592
- return deletedAtKey;
3593
- }
3594
- };
3595
-
3596
- // src/engine/key/OIMCompositeKeyTreeWalk.ts
3597
- var _OIMCompositeKeyTreeWalk = class _OIMCompositeKeyTreeWalk extends OIMKeyTreeWalk {
3598
- holdCompositeKeyPart(entitySlot) {
3599
- entitySlot.owner.holdSlot(entitySlot);
3600
- }
3601
- unholdCompositeKeyPart(entitySlot) {
3602
- oimUnholdSlotIfAlive(entitySlot);
3603
- }
3604
- };
3605
- _OIMCompositeKeyTreeWalk.INSTANCE = new _OIMCompositeKeyTreeWalk();
3606
- var OIMCompositeKeyTreeWalk = _OIMCompositeKeyTreeWalk;
3607
-
3608
- // src/factories/defaults/OIM_DEFAULT_KEY_TREE_WALK_COMPOSITE.ts
3609
- var OIM_DEFAULT_KEY_TREE_WALK_COMPOSITE = /* @__PURE__ */ new OIMDefaultValue("KEY_TREE_WALK_COMPOSITE", () => OIMCompositeKeyTreeWalk.INSTANCE);
3610
-
3611
- // src/engine/key/OIMScalarKeyTreeWalk.ts
3612
- var _OIMScalarKeyTreeWalk = class _OIMScalarKeyTreeWalk extends OIMKeyTreeWalk {
3613
- holdCompositeKeyPart() {
3614
- return;
3615
- }
3616
- unholdCompositeKeyPart() {
3617
- return;
3618
- }
3619
- };
3620
- _OIMScalarKeyTreeWalk.INSTANCE = new _OIMScalarKeyTreeWalk();
3621
- var OIMScalarKeyTreeWalk = _OIMScalarKeyTreeWalk;
3622
-
3623
- // src/factories/defaults/OIM_DEFAULT_KEY_TREE_WALK_SCALAR.ts
3624
- var OIM_DEFAULT_KEY_TREE_WALK_SCALAR = /* @__PURE__ */ new OIMDefaultValue("KEY_TREE_WALK_SCALAR", () => OIMScalarKeyTreeWalk.INSTANCE);
3625
-
3626
- // src/factories/defaults/OIM_DEFAULT_STANDALONE_SLOT_OWNER.ts
3627
- var OIM_DEFAULT_STANDALONE_SLOT_OWNER = /* @__PURE__ */ new OIMDefaultValue("STANDALONE_SLOT_OWNER", () => new OIMSlotOwner());
3628
-
3629
- // src/factories/OIMDefaults.ts
3630
- var OIMDefaults = class {
3631
- };
3632
- OIMDefaults.COLUMN_SLOT_STORE_SERVICE = OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE;
3633
- OIMDefaults.COMPUTED_COLUMN_SLOT_STORE_SERVICE = OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE;
3634
- OIMDefaults.KEY_TREE_WALK_SCALAR = OIM_DEFAULT_KEY_TREE_WALK_SCALAR;
3635
- OIMDefaults.KEY_TREE_WALK_COMPOSITE = OIM_DEFAULT_KEY_TREE_WALK_COMPOSITE;
3636
- OIMDefaults.STANDALONE_SLOT_OWNER = OIM_DEFAULT_STANDALONE_SLOT_OWNER;
3637
- OIMDefaults.ENTITY_WRITER = OIM_DEFAULT_ENTITY_WRITER;
3638
- OIMDefaults.ENTITY_SLOT_EMPTINESS = OIM_DEFAULT_ENTITY_SLOT_EMPTINESS;
3639
- OIMDefaults.INDEX_KEYS_SERVICE = OIM_DEFAULT_INDEX_KEYS_SERVICE;
3640
- OIMDefaults.STORE_SLOT_LISTENER = OIM_DEFAULT_STORE_SLOT_LISTENER;
3641
-
3642
- // src/engine/column/utils/createOIMPullColumnSlotOwner.ts
3643
- var createOIMPullColumnSlotOwner = (columnSlotOwnerOptions) => new OIMPullColumnSlotOwner(columnSlotOwnerOptions);
3644
-
3645
- // src/engine/computed/OIMComputedSourcesService.ts
3681
+ // src/computed/OIMComputedSourcesService.ts
3646
3682
  var _OIMComputedSourcesService = class _OIMComputedSourcesService {
3647
3683
  holdSources(derivation) {
3648
3684
  oimHoldSlots(derivation.sourceSlots);
@@ -3658,8 +3694,8 @@ var _OIMComputedSourcesService = class _OIMComputedSourcesService {
3658
3694
  _OIMComputedSourcesService.INSTANCE = new _OIMComputedSourcesService();
3659
3695
  var OIMComputedSourcesService = _OIMComputedSourcesService;
3660
3696
 
3661
- // src/engine/computed/utils/createOIMSingleComputedSlot.ts
3662
- function createOIMSingleComputedSlot(owner, computedValueService, initialValue, storeSlot) {
3697
+ // src/computed/utils/createOIMComputedContentSlot.ts
3698
+ function createOIMComputedContentSlot(owner, computedValueService, initialValue, storeSlot, sourceTracker) {
3663
3699
  const singleComputedSlot = {
3664
3700
  effects: void 0,
3665
3701
  changedAtRevision: 0,
@@ -3684,12 +3720,13 @@ function createOIMSingleComputedSlot(owner, computedValueService, initialValue,
3684
3720
  checkedAtRevision: -1,
3685
3721
  checkedAtEpoch: -1,
3686
3722
  isDeriving: false,
3687
- allRootSlots: void 0
3723
+ allRootSlots: void 0,
3724
+ sourceTracker
3688
3725
  };
3689
3726
  return singleComputedSlot;
3690
3727
  }
3691
3728
 
3692
- // src/engine/computed/OIMSlotContentComputedService.ts
3729
+ // src/computed/OIMSlotContentComputedService.ts
3693
3730
  var OIMSlotContentComputedService = class {
3694
3731
  constructor(options) {
3695
3732
  this.computedValueService = options.computedValueService;
@@ -3702,13 +3739,20 @@ var OIMSlotContentComputedService = class {
3702
3739
  slotOwner,
3703
3740
  this.computedValueService,
3704
3741
  this.initialValue,
3705
- storeSlot
3742
+ storeSlot,
3743
+ this.createSourceTracker()
3706
3744
  );
3707
3745
  this.attachSources(computedSlot, storeSlot);
3708
3746
  return computedSlot;
3709
3747
  }
3710
3748
  createSingleSlot(storeSlot, slotOwner) {
3711
- const computedSlot = createOIMSingleComputedSlot(slotOwner, this.computedValueService, this.initialValue, storeSlot);
3749
+ const computedSlot = createOIMComputedContentSlot(
3750
+ slotOwner,
3751
+ this.computedValueService,
3752
+ this.initialValue,
3753
+ storeSlot,
3754
+ this.createSourceTracker()
3755
+ );
3712
3756
  this.attachSources(computedSlot, storeSlot);
3713
3757
  return computedSlot;
3714
3758
  }
@@ -3716,56 +3760,67 @@ var OIMSlotContentComputedService = class {
3716
3760
  return false;
3717
3761
  }
3718
3762
  releaseSlotContent(computedSlot) {
3763
+ oimAssertSlotUnheld(computedSlot);
3719
3764
  OIMComputedSourcesService.INSTANCE.unholdSources(computedSlot);
3765
+ this.computedValueService.releaseSlotValue(computedSlot);
3720
3766
  }
3721
3767
  hasReference() {
3722
3768
  return false;
3723
3769
  }
3770
+ createSourceTracker() {
3771
+ return void 0;
3772
+ }
3724
3773
  attachSources(computedSlot, storeSlot) {
3725
3774
  const createSources = storeSlot.createSources ?? this.createSources;
3726
3775
  const computedSources = createSources(computedSlot);
3727
- const computedSlotEditable = computedSlot;
3728
- computedSlotEditable.sourceSlots = computedSources.sourceSlots ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
3729
- computedSlotEditable.sourceComputeds = computedSources.sourceComputeds ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
3776
+ const editableComputedSlot = computedSlot;
3777
+ editableComputedSlot.sourceSlots = computedSources.sourceSlots ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
3778
+ editableComputedSlot.sourceComputeds = computedSources.sourceComputeds ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
3730
3779
  OIMComputedSourcesService.INSTANCE.holdSources(computedSlot);
3731
3780
  }
3732
3781
  };
3733
3782
 
3734
- // src/facade/computed/utils/createOIMComputedCollectionService.ts
3735
- function createOIMComputedCollectionService(options) {
3783
+ // src/column/utils/createOIMPullColumnSlotOwner.ts
3784
+ var createOIMPullColumnSlotOwner = (columnSlotOwnerOptions) => new OIMPullColumnSlotOwner(columnSlotOwnerOptions);
3785
+
3786
+ // src/computed/utils/createOIMComputedSlotCollectionService.ts
3787
+ function createOIMComputedSlotCollectionService(options) {
3736
3788
  return new OIMSlotCollectionService({
3737
3789
  slotReleasePolicy: options.slotReleasePolicy,
3738
3790
  slotStoreService: options.computedSlotStoreService,
3739
- slotContentService: new OIMSlotContentComputedService(options),
3791
+ slotContentService: options.slotContentService,
3740
3792
  columnSlotOwnerOptions: options.columnSlotOwnerOptions,
3741
3793
  createColumnSlotOwner: createOIMPullColumnSlotOwner,
3742
3794
  storeSlotListener: options.storeSlotListener
3743
3795
  });
3744
3796
  }
3745
3797
 
3746
- // src/facade/computed/utils/oimAttachComputedDerivation.ts
3798
+ // src/computed/utils/oimAttachComputedDerivation.ts
3747
3799
  function oimAttachComputedDerivation(computedStoreSlot, hasServiceDerive, hasServiceCreateSources, derive, createSources) {
3748
3800
  if (derive === void 0 && !hasServiceDerive || createSources === void 0 && !hasServiceCreateSources) {
3749
3801
  throw new Error(
3750
3802
  "A computed store slot needs a derive and a createSources, from the store slot or from the service options. Pass the missing one when creating the store slot or to the service."
3751
3803
  );
3752
3804
  }
3753
- const computedStoreSlotEditable = computedStoreSlot;
3754
- computedStoreSlotEditable.derive = derive;
3755
- computedStoreSlotEditable.createSources = createSources;
3805
+ const editableComputedStoreSlot = computedStoreSlot;
3806
+ editableComputedStoreSlot.derive = derive;
3807
+ editableComputedStoreSlot.createSources = createSources;
3756
3808
  return computedStoreSlot;
3757
3809
  }
3758
3810
 
3759
- // src/facade/computed/OIMComputedService.ts
3811
+ // src/computed/OIMComputedService.ts
3760
3812
  var OIMComputedService = class {
3761
3813
  constructor(options) {
3762
- this.computedCollectionService = createOIMComputedCollectionService({
3763
- computedValueService: new OIMComputedValueService({
3764
- derive: options.derive,
3765
- sameValueGuard: options.sameValueGuard
3814
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
3815
+ slotContentService: new OIMSlotContentComputedService({
3816
+ computedValueService: new OIMComputedValueService({
3817
+ derive: options.derive,
3818
+ sameValueGuard: options.sameValueGuard,
3819
+ releaseValue: options.releaseValue
3820
+ }),
3821
+ createSources: options.createSources,
3822
+ initialValue: options.initialValue
3766
3823
  }),
3767
- createSources: options.createSources,
3768
- initialValue: options.initialValue,
3769
3824
  slotReleasePolicy: options.slotReleasePolicy,
3770
3825
  computedSlotStoreService: options.computedSlotStoreService,
3771
3826
  columnSlotOwnerOptions: options.columnSlotOwnerOptions,
@@ -3785,7 +3840,7 @@ var OIMComputedService = class {
3785
3840
  }
3786
3841
  };
3787
3842
 
3788
- // src/engine/collector/OIMSlotAtUnholdReleasePolicy.ts
3843
+ // src/collector/OIMSlotAtUnholdReleasePolicy.ts
3789
3844
  var _OIMSlotAtUnholdReleasePolicy = class _OIMSlotAtUnholdReleasePolicy {
3790
3845
  constructor() {
3791
3846
  this.releasesWrittenSlots = true;
@@ -3813,25 +3868,37 @@ var _OIMSlotAtUnholdReleasePolicy = class _OIMSlotAtUnholdReleasePolicy {
3813
3868
  _OIMSlotAtUnholdReleasePolicy.INSTANCE = new _OIMSlotAtUnholdReleasePolicy();
3814
3869
  var OIMSlotAtUnholdReleasePolicy = _OIMSlotAtUnholdReleasePolicy;
3815
3870
 
3816
- // src/factories/createOIMComputedService.ts
3817
- function createOIMComputedService(options) {
3818
- return new OIMComputedService({
3819
- computedSlotStoreService: oimSlotStoreServiceWithDefault(options.computedSlotStoreService),
3820
- columnSlotOwnerOptions: oimColumnOwnerOptionsWithDefault(
3871
+ // src/db/constants/OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.ts
3872
+ var OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE = /* @__PURE__ */ new OIMDefaultValue(() => OIMSlotMapStoreService.INSTANCE);
3873
+
3874
+ // src/computed/utils/oimResolveComputedDerivationOptions.ts
3875
+ function oimResolveComputedDerivationOptions(options) {
3876
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
3877
+ return {
3878
+ columnSlotOwnerOptions: oimResolveColumnSlotOwnerOptions(
3821
3879
  options.columnSlotStoreService,
3822
3880
  options.columnNames,
3823
- OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue()
3881
+ defaults.computedColumnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue()
3824
3882
  ),
3825
3883
  slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
3826
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
3827
- createSources: options.createSources,
3828
- derive: options.derive,
3884
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
3829
3885
  sameValueGuard: options.sameValueGuard,
3886
+ releaseValue: options.releaseValue,
3830
3887
  initialValue: options.initialValue
3888
+ };
3889
+ }
3890
+
3891
+ // src/computed/createOIMComputedService.ts
3892
+ function createOIMComputedService(options) {
3893
+ return new OIMComputedService({
3894
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
3895
+ ...oimResolveComputedDerivationOptions(options),
3896
+ createSources: options.createSources,
3897
+ derive: options.derive
3831
3898
  });
3832
3899
  }
3833
3900
 
3834
- // src/facade/computed/OIMSingleComputedService.ts
3901
+ // src/computed/OIMSingleComputedService.ts
3835
3902
  var OIMSingleComputedService = class {
3836
3903
  constructor(options) {
3837
3904
  this.computedSingleSlotService = new OIMSingleSlotService({
@@ -3840,7 +3907,8 @@ var OIMSingleComputedService = class {
3840
3907
  slotContentService: new OIMSlotContentComputedService({
3841
3908
  computedValueService: new OIMComputedValueService({
3842
3909
  derive: options.derive,
3843
- sameValueGuard: options.sameValueGuard
3910
+ sameValueGuard: options.sameValueGuard,
3911
+ releaseValue: options.releaseValue
3844
3912
  }),
3845
3913
  createSources: options.createSources,
3846
3914
  initialValue: options.initialValue
@@ -3863,30 +3931,133 @@ var OIMSingleComputedService = class {
3863
3931
  }
3864
3932
  };
3865
3933
 
3866
- // src/factories/createOIMSingleComputedService.ts
3934
+ // src/computed/createOIMSingleComputedService.ts
3867
3935
  function createOIMSingleComputedService(options = {}) {
3868
3936
  return new OIMSingleComputedService({
3869
- columnSlotOwnerOptions: oimColumnOwnerOptionsWithDefault(
3870
- options.columnSlotStoreService,
3871
- options.columnNames,
3872
- OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue()
3873
- ),
3874
- slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
3875
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
3937
+ ...oimResolveComputedDerivationOptions(options),
3876
3938
  createSources: options.createSources,
3877
- derive: options.derive,
3878
- sameValueGuard: options.sameValueGuard,
3879
- initialValue: options.initialValue
3939
+ derive: options.derive
3940
+ });
3941
+ }
3942
+
3943
+ // src/computed/OIMSourceTrackingComputedValueService.ts
3944
+ var OIMSourceTrackingComputedValueService = class extends OIMComputedValueService {
3945
+ constructor(options) {
3946
+ super({ sameValueGuard: options.sameValueGuard, releaseValue: options.releaseValue });
3947
+ this.deriveTrackingSources = (computedSlot) => {
3948
+ const sourceTracker = computedSlot.sourceTracker;
3949
+ sourceTracker.openSourceTracking();
3950
+ const value = this.sourceTrackingDerive(computedSlot, sourceTracker);
3951
+ if (sourceTracker.closeSourceTracking() && !oimIsSlotReleased(computedSlot)) this.replaceSources(computedSlot, sourceTracker);
3952
+ return value;
3953
+ };
3954
+ this.sourceTrackingDerive = options.derive;
3955
+ }
3956
+ getValueForSlot(computedSlot) {
3957
+ oimAssertSlotNotReleased(computedSlot);
3958
+ const sourceTracker = computedSlot.sourceTracker;
3959
+ oimRefreshComputedSlot(computedSlot, this.deriveTrackingSources, this.sameValueGuard, this.releaseValue, computedSlot.storeSlot.channelSlot.clock);
3960
+ if (sourceTracker.trackReplacedRootSlots()) {
3961
+ sourceTracker.commitTrackedSources();
3962
+ computedSlot.allRootSlots = void 0;
3963
+ }
3964
+ return computedSlot.value;
3965
+ }
3966
+ replaceSources(computedSlot, sourceTracker) {
3967
+ const trackedSourceSlots = sourceTracker.getTrackedSourceSlots().slice();
3968
+ const trackedSourceComputeds = sourceTracker.getTrackedSourceComputeds().slice();
3969
+ oimHoldSlots(trackedSourceSlots);
3970
+ oimHoldSlots(trackedSourceComputeds);
3971
+ OIMComputedSourcesService.INSTANCE.unholdSources(computedSlot);
3972
+ const editableComputedSlot = computedSlot;
3973
+ editableComputedSlot.sourceSlots = trackedSourceSlots;
3974
+ editableComputedSlot.sourceComputeds = trackedSourceComputeds;
3975
+ editableComputedSlot.allRootSlots = void 0;
3976
+ sourceTracker.commitTrackedSources();
3977
+ }
3978
+ };
3979
+
3980
+ // src/computed/OIMSlotContentSourceTrackingComputedService.ts
3981
+ var OIMSlotContentSourceTrackingComputedService = class extends OIMSlotContentComputedService {
3982
+ createSourceTracker() {
3983
+ return new OIMSourceTracker();
3984
+ }
3985
+ attachSources() {
3986
+ return;
3987
+ }
3988
+ };
3989
+
3990
+ // src/computed/OIMSourceTrackingComputedService.ts
3991
+ var OIMSourceTrackingComputedService = class {
3992
+ constructor(options) {
3993
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
3994
+ slotContentService: new OIMSlotContentSourceTrackingComputedService({
3995
+ computedValueService: new OIMSourceTrackingComputedValueService({
3996
+ derive: options.derive,
3997
+ sameValueGuard: options.sameValueGuard,
3998
+ releaseValue: options.releaseValue
3999
+ }),
4000
+ initialValue: options.initialValue
4001
+ }),
4002
+ slotReleasePolicy: options.slotReleasePolicy,
4003
+ computedSlotStoreService: options.computedSlotStoreService,
4004
+ columnSlotOwnerOptions: options.columnSlotOwnerOptions,
4005
+ storeSlotListener: options.storeSlotListener
4006
+ });
4007
+ }
4008
+ createComputedStoreSlot(channelMap) {
4009
+ return this.computedCollectionService.createStoreSlot(channelMap);
4010
+ }
4011
+ };
4012
+
4013
+ // src/computed/OIMSingleSourceTrackingComputedService.ts
4014
+ var OIMSingleSourceTrackingComputedService = class {
4015
+ constructor(options) {
4016
+ this.computedSingleSlotService = new OIMSingleSlotService({
4017
+ slotReleasePolicy: options.slotReleasePolicy,
4018
+ slotStoreService: OIMSingleSlotStoreService.INSTANCE,
4019
+ slotContentService: new OIMSlotContentSourceTrackingComputedService({
4020
+ computedValueService: new OIMSourceTrackingComputedValueService({
4021
+ derive: options.derive,
4022
+ sameValueGuard: options.sameValueGuard,
4023
+ releaseValue: options.releaseValue
4024
+ }),
4025
+ initialValue: options.initialValue
4026
+ }),
4027
+ columnSlotOwnerOptions: options.columnSlotOwnerOptions,
4028
+ createColumnSlotOwner: createOIMPullColumnSlotOwner,
4029
+ storeSlotListener: options.storeSlotListener
4030
+ });
4031
+ }
4032
+ createComputedStoreSlot(channelMap) {
4033
+ return this.computedSingleSlotService.createStoreSlot(channelMap);
4034
+ }
4035
+ };
4036
+
4037
+ // src/computed/createOIMSourceTrackingComputedService.ts
4038
+ function createOIMSourceTrackingComputedService(options) {
4039
+ return new OIMSourceTrackingComputedService({
4040
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
4041
+ ...oimResolveComputedDerivationOptions(options),
4042
+ derive: options.derive
4043
+ });
4044
+ }
4045
+
4046
+ // src/computed/createOIMSingleSourceTrackingComputedService.ts
4047
+ function createOIMSingleSourceTrackingComputedService(options) {
4048
+ return new OIMSingleSourceTrackingComputedService({
4049
+ ...oimResolveComputedDerivationOptions(options),
4050
+ derive: options.derive
3880
4051
  });
3881
4052
  }
3882
4053
 
3883
- // src/facade/computed/utils/oimColumnsComparator.ts
4054
+ // src/computed/utils/oimColumnsComparator.ts
3884
4055
  function oimColumnsComparator(columns) {
3885
4056
  return (left, right) => {
3886
4057
  for (let i = 0; i < columns.length; i++) {
3887
- const column = columns[i].column;
3888
- const leftValue = left[column];
3889
- const rightValue = right[column];
4058
+ const columnName = columns[i].columnName;
4059
+ const leftValue = left[columnName];
4060
+ const rightValue = right[columnName];
3890
4061
  if (leftValue === rightValue) continue;
3891
4062
  const isLeftMissing = leftValue === void 0 || leftValue === null || leftValue !== leftValue;
3892
4063
  const isRightMissing = rightValue === void 0 || rightValue === null || rightValue !== rightValue;
@@ -3900,7 +4071,7 @@ function oimColumnsComparator(columns) {
3900
4071
  };
3901
4072
  }
3902
4073
 
3903
- // src/facade/computed/utils/oimEntitySlotsComparator.ts
4074
+ // src/computed/utils/oimEntitySlotsComparator.ts
3904
4075
  function oimEntitySlotsComparator(compareEntities) {
3905
4076
  return (leftEntitySlot, rightEntitySlot) => {
3906
4077
  const leftEntity = leftEntitySlot.entity;
@@ -3911,7 +4082,7 @@ function oimEntitySlotsComparator(compareEntities) {
3911
4082
  };
3912
4083
  }
3913
4084
 
3914
- // src/facade/computed/OIMSortedComputedService.ts
4085
+ // src/computed/OIMSortedComputedService.ts
3915
4086
  var OIMSortedComputedService = class {
3916
4087
  constructor(options) {
3917
4088
  const indexService = options.indexService;
@@ -3925,16 +4096,18 @@ var OIMSortedComputedService = class {
3925
4096
  derive: (computedSlot) => sortBucketMemberSlots(computedSlot, bucketContentService, compareEntitySlots),
3926
4097
  sameValueGuard: oimSameSlotSequence
3927
4098
  });
3928
- this.computedCollectionService = createOIMComputedCollectionService({
3929
- computedValueService,
3930
- createSources: (computedSlot) => createSortedSources(
3931
- computedSlot.key,
3932
- computedSlot.storeSlot,
3933
- indexService,
3934
- sortColumns,
3935
- hasComparator
3936
- ),
3937
- initialValue: OIM_FROZEN_EMPTY_SLOTS,
4099
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
4100
+ slotContentService: new OIMSlotContentComputedService({
4101
+ computedValueService,
4102
+ createSources: (computedSlot) => createSortedComputedSources(
4103
+ computedSlot.key,
4104
+ computedSlot.storeSlot,
4105
+ indexService,
4106
+ sortColumns,
4107
+ hasComparator
4108
+ ),
4109
+ initialValue: OIM_FROZEN_EMPTY_SLOTS
4110
+ }),
3938
4111
  slotReleasePolicy: options.slotReleasePolicy,
3939
4112
  computedSlotStoreService: options.computedSlotStoreService,
3940
4113
  columnSlotOwnerOptions: { columnSlotStoreService: options.columnSlotStoreService },
@@ -3948,12 +4121,12 @@ var OIMSortedComputedService = class {
3948
4121
  function compareNothing() {
3949
4122
  return 0;
3950
4123
  }
3951
- function createSortedSources(key, storeSlot, indexService, sortColumns, hasComparator) {
4124
+ function createSortedComputedSources(key, storeSlot, indexService, sortColumns, hasComparator) {
3952
4125
  const indexStoreSlot = storeSlot.sourceStoreSlot;
3953
4126
  const sourceSlots = [indexService.getSlotByKey(indexStoreSlot, key)];
3954
4127
  if (sortColumns !== void 0) {
3955
4128
  for (let i = 0; i < sortColumns.length; i++) {
3956
- sourceSlots.push(indexService.getBucketColumnByKey(indexStoreSlot, key, sortColumns[i].column));
4129
+ sourceSlots.push(indexService.getBucketColumnByKey(indexStoreSlot, key, sortColumns[i].columnName));
3957
4130
  }
3958
4131
  } else if (hasComparator) {
3959
4132
  sourceSlots.push(indexService.getAnyBucketColumnByKey(indexStoreSlot, key));
@@ -4018,20 +4191,21 @@ function reconcileArrayWithEveryBucketMemberSlot(entitySlots, bucketMemberSlots)
4018
4191
  return next;
4019
4192
  }
4020
4193
 
4021
- // src/factories/createOIMSortedComputedService.ts
4194
+ // src/computed/createOIMSortedComputedService.ts
4022
4195
  function createOIMSortedComputedService(options) {
4196
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
4023
4197
  return new OIMSortedComputedService({
4024
4198
  indexService: options.indexService,
4025
- computedSlotStoreService: oimSlotStoreServiceWithDefault(options.computedSlotStoreService),
4026
- columnSlotStoreService: options.columnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4199
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
4200
+ columnSlotStoreService: options.columnSlotStoreService ?? defaults.computedColumnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4027
4201
  sortColumns: options.sortColumns,
4028
4202
  comparator: options.comparator,
4029
4203
  slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
4030
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4204
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4031
4205
  });
4032
4206
  }
4033
4207
 
4034
- // src/facade/computed/OIMBucketMemoComputedService.ts
4208
+ // src/computed/OIMBucketMemoComputedService.ts
4035
4209
  var OIMBucketMemoComputedService = class {
4036
4210
  constructor(options) {
4037
4211
  const bucketCollectionService = options.bucketCollectionService;
@@ -4040,10 +4214,12 @@ var OIMBucketMemoComputedService = class {
4040
4214
  derive: (computedSlot) => deriveBucketMemo(computedSlot, bucketContentService),
4041
4215
  sameValueGuard: oimSameSlotSequence
4042
4216
  });
4043
- this.computedCollectionService = createOIMComputedCollectionService({
4044
- computedValueService,
4045
- createSources: (computedSlot) => createBucketMemoSources(computedSlot.key, computedSlot.storeSlot, bucketCollectionService),
4046
- initialValue: OIM_FROZEN_EMPTY_SLOTS,
4217
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
4218
+ slotContentService: new OIMSlotContentComputedService({
4219
+ computedValueService,
4220
+ createSources: (computedSlot) => createBucketMemoComputedSources(computedSlot.key, computedSlot.storeSlot, bucketCollectionService),
4221
+ initialValue: OIM_FROZEN_EMPTY_SLOTS
4222
+ }),
4047
4223
  slotReleasePolicy: options.slotReleasePolicy,
4048
4224
  computedSlotStoreService: options.computedSlotStoreService,
4049
4225
  columnSlotOwnerOptions: { columnSlotStoreService: options.columnSlotStoreService },
@@ -4057,26 +4233,27 @@ var OIMBucketMemoComputedService = class {
4057
4233
  function deriveBucketMemo(computedSlot, bucketContentService) {
4058
4234
  return Array.from(bucketContentService.getBucketMemberSlots(computedSlot.sourceSlots[0]));
4059
4235
  }
4060
- function createBucketMemoSources(key, storeSlot, bucketCollectionService) {
4236
+ function createBucketMemoComputedSources(key, storeSlot, bucketCollectionService) {
4061
4237
  const bucketStoreSlot = storeSlot.sourceStoreSlot;
4062
4238
  return { sourceSlots: [bucketCollectionService.getSlotByKey(bucketStoreSlot, key)] };
4063
4239
  }
4064
4240
 
4065
- // src/factories/createOIMBucketMemoComputedService.ts
4241
+ // src/computed/createOIMBucketMemoComputedService.ts
4066
4242
  function createOIMBucketMemoComputedService(options) {
4243
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
4067
4244
  return new OIMBucketMemoComputedService({
4068
4245
  bucketCollectionService: options.bucketCollectionService,
4069
- computedSlotStoreService: oimSlotStoreServiceWithDefault(options.computedSlotStoreService),
4070
- columnSlotStoreService: options.columnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4246
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
4247
+ columnSlotStoreService: options.columnSlotStoreService ?? defaults.computedColumnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4071
4248
  slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
4072
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4249
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4073
4250
  });
4074
4251
  }
4075
4252
 
4076
- // src/engine/bucket/commands/constants/OIM_MAX_COMMANDS_PER_SLOT.ts
4253
+ // src/bucket/commands/constants/OIM_MAX_COMMANDS_PER_SLOT.ts
4077
4254
  var OIM_MAX_COMMANDS_PER_SLOT = 1;
4078
4255
 
4079
- // src/facade/bucket/OIMBucketCommands.ts
4256
+ // src/bucket/OIMBucketCommands.ts
4080
4257
  var OIMBucketCommands = class {
4081
4258
  constructor(options) {
4082
4259
  this.maxCommandsPerSlot = options.maxCommandsPerSlot ?? OIM_MAX_COMMANDS_PER_SLOT;
@@ -4091,40 +4268,40 @@ var OIMBucketCommands = class {
4091
4268
  this.recordCommand(bucketSlot, { type: "move", from, to }, bucketMemberSlotCount);
4092
4269
  }
4093
4270
  recordWholeList(bucketSlot) {
4094
- const bucketSlotEditable = enlistInFlush(bucketSlot);
4095
- const commands = bucketSlotEditable.commands;
4271
+ const editableBucketSlot = enlistInFlush(bucketSlot);
4272
+ const commands = editableBucketSlot.commands;
4096
4273
  if (commands !== void 0 && commands.length !== 0) commands.length = 0;
4097
- bucketSlotEditable.isWholeListRecorded = true;
4274
+ editableBucketSlot.isWholeListRecorded = true;
4098
4275
  }
4099
4276
  recordCommand(bucketSlot, orderedListCommand, bucketMemberSlotCount) {
4100
- const bucketSlotEditable = enlistInFlush(bucketSlot);
4101
- if (bucketSlotEditable.isWholeListRecorded) return;
4102
- const commands = bucketSlotEditable.commands ?? (bucketSlotEditable.commands = []);
4277
+ const editableBucketSlot = enlistInFlush(bucketSlot);
4278
+ if (editableBucketSlot.isWholeListRecorded) return;
4279
+ const commands = editableBucketSlot.commands ?? (editableBucketSlot.commands = []);
4103
4280
  commands.push(orderedListCommand);
4104
4281
  if (commands.length > this.maxCommandsPerSlot * bucketMemberSlotCount) {
4105
4282
  commands.length = 0;
4106
- bucketSlotEditable.isWholeListRecorded = true;
4283
+ editableBucketSlot.isWholeListRecorded = true;
4107
4284
  }
4108
4285
  }
4109
4286
  };
4110
4287
  function enlistInFlush(bucketSlot) {
4111
- const bucketSlotEditable = bucketSlot;
4288
+ const editableBucketSlot = bucketSlot;
4112
4289
  const storeSlot = bucketSlot.storeSlot;
4113
4290
  const channelSlot = storeSlot.channelSlot;
4114
- const commands = bucketSlotEditable.commands;
4115
- const hasScript = commands !== void 0 && commands.length > 0 || bucketSlotEditable.isWholeListRecorded;
4116
- if (hasScript && !isScriptStale(channelSlot, bucketSlotEditable)) return bucketSlotEditable;
4291
+ const commands = editableBucketSlot.commands;
4292
+ const hasScript = commands !== void 0 && commands.length > 0 || editableBucketSlot.isWholeListRecorded;
4293
+ if (hasScript && !isScriptStale(channelSlot, editableBucketSlot)) return editableBucketSlot;
4117
4294
  if (hasScript) {
4118
- clearScript(bucketSlotEditable);
4295
+ clearScript(editableBucketSlot);
4119
4296
  } else {
4120
4297
  const commandsBucketSlotChannelQueue = storeSlot.commandsBucketSlotChannelQueue ?? (storeSlot.commandsBucketSlotChannelQueue = new OIMChannelQueue());
4121
4298
  if (commandsBucketSlotChannelQueue.getEntryCount() === 0) getCommandsStoreSlotChannelQueue(channelSlot).enqueueEntry(storeSlot);
4122
- commandsBucketSlotChannelQueue.enqueueEntry(bucketSlotEditable);
4299
+ commandsBucketSlotChannelQueue.enqueueEntry(editableBucketSlot);
4123
4300
  }
4124
4301
  const clock = channelSlot.clock;
4125
- bucketSlotEditable.commandsStartedAtRevision = clock.revision;
4126
- bucketSlotEditable.commandsStartedAtEpoch = clock.epoch;
4127
- return bucketSlotEditable;
4302
+ editableBucketSlot.commandsStartedAtRevision = clock.revision;
4303
+ editableBucketSlot.commandsStartedAtEpoch = clock.epoch;
4304
+ return editableBucketSlot;
4128
4305
  }
4129
4306
  function getCommandsStoreSlotChannelQueue(channelSlot) {
4130
4307
  const commandsStoreSlotChannelQueue = channelSlot.commandsStoreSlotChannelQueue;
@@ -4145,10 +4322,10 @@ function isScriptStale(channelSlot, bucketSlot) {
4145
4322
  bucketSlot.commandsStartedAtEpoch
4146
4323
  );
4147
4324
  }
4148
- function clearScript(bucketSlotEditable) {
4149
- const commands = bucketSlotEditable.commands;
4325
+ function clearScript(editableBucketSlot) {
4326
+ const commands = editableBucketSlot.commands;
4150
4327
  if (commands !== void 0 && commands.length !== 0) commands.length = 0;
4151
- bucketSlotEditable.isWholeListRecorded = false;
4328
+ editableBucketSlot.isWholeListRecorded = false;
4152
4329
  }
4153
4330
  function clearStaleScripts(channelSlot, commandsStoreSlotChannelQueue) {
4154
4331
  let keptStoreSlotCount = 0;
@@ -4157,12 +4334,12 @@ function clearStaleScripts(channelSlot, commandsStoreSlotChannelQueue) {
4157
4334
  const commandsBucketSlotChannelQueue = storeSlot.commandsBucketSlotChannelQueue;
4158
4335
  let keptBucketSlotCount = 0;
4159
4336
  for (let j = 0; j < commandsBucketSlotChannelQueue.getEntryCount(); j++) {
4160
- const bucketSlotEditable = commandsBucketSlotChannelQueue.getEntryAt(j);
4161
- if (!isScriptStale(channelSlot, bucketSlotEditable)) {
4162
- commandsBucketSlotChannelQueue.setEntryAt(keptBucketSlotCount++, bucketSlotEditable);
4337
+ const editableBucketSlot = commandsBucketSlotChannelQueue.getEntryAt(j);
4338
+ if (!isScriptStale(channelSlot, editableBucketSlot)) {
4339
+ commandsBucketSlotChannelQueue.setEntryAt(keptBucketSlotCount++, editableBucketSlot);
4163
4340
  continue;
4164
4341
  }
4165
- clearScript(bucketSlotEditable);
4342
+ clearScript(editableBucketSlot);
4166
4343
  }
4167
4344
  commandsBucketSlotChannelQueue.keepFirstEntries(keptBucketSlotCount);
4168
4345
  if (keptBucketSlotCount !== 0) commandsStoreSlotChannelQueue.setEntryAt(keptStoreSlotCount++, storeSlot);
@@ -4170,7 +4347,7 @@ function clearStaleScripts(channelSlot, commandsStoreSlotChannelQueue) {
4170
4347
  commandsStoreSlotChannelQueue.keepFirstEntries(keptStoreSlotCount);
4171
4348
  }
4172
4349
 
4173
- // src/engine/index/utils/createOIMIndexStoreSlot.ts
4350
+ // src/index/utils/createOIMIndexStoreSlot.ts
4174
4351
  function createOIMIndexStoreSlot(store, slotService, sourceStoreSlot, contentChangeListener) {
4175
4352
  return {
4176
4353
  ...createOIMStoreSlot(store, sourceStoreSlot.channelSlot, slotService),
@@ -4184,7 +4361,35 @@ function createOIMIndexStoreSlot(store, slotService, sourceStoreSlot, contentCha
4184
4361
  };
4185
4362
  }
4186
4363
 
4187
- // src/facade/index/OIMSlotCollectionIndexService.ts
4364
+ // src/index/OIMSlotCollectionIndexStoreAggregate.ts
4365
+ var OIMSlotCollectionIndexStoreAggregate = class extends OIMSlotCollectionStoreAggregate {
4366
+ getEntitiesByKey(key) {
4367
+ return this.slotService.getEntitiesByKey(this.storeSlot, key);
4368
+ }
4369
+ getSlotsByKeys(keys) {
4370
+ return this.slotService.getSlotsByKeys(this.storeSlot, keys);
4371
+ }
4372
+ holdSlotsByKeys(keys) {
4373
+ return this.slotService.holdSlotsByKeys(this.storeSlot, keys);
4374
+ }
4375
+ getAnyBucketColumnByKey(key) {
4376
+ return this.slotService.getAnyBucketColumnByKey(this.storeSlot, key);
4377
+ }
4378
+ holdAnyBucketColumnByKey(key) {
4379
+ return this.slotService.holdAnyBucketColumnByKey(this.storeSlot, key);
4380
+ }
4381
+ getBucketColumnByKey(key, columnName) {
4382
+ return this.slotService.getBucketColumnByKey(this.storeSlot, key, columnName);
4383
+ }
4384
+ holdBucketColumnByKey(key, columnName) {
4385
+ return this.slotService.holdBucketColumnByKey(this.storeSlot, key, columnName);
4386
+ }
4387
+ disposeIndexStoreSlot() {
4388
+ this.slotService.disposeIndexStoreSlot(this.storeSlot);
4389
+ }
4390
+ };
4391
+
4392
+ // src/index/OIMSlotCollectionIndexService.ts
4188
4393
  var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4189
4394
  constructor(options) {
4190
4395
  super(options);
@@ -4199,26 +4404,29 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4199
4404
  onContentChanged: (entitySlot, patch, changedColumns) => {
4200
4405
  this.updateIndexKeyForSlot(indexStoreSlot, entitySlot, patch, changedColumns);
4201
4406
  },
4202
- onContentChangedMany: (entitySlotChannelQueue, patchChannelQueue, changedColumnsChannelQueue) => {
4407
+ onManyContentsChanged: (entitySlotChannelQueue, patchChannelQueue, changedColumnsChannelQueue) => {
4203
4408
  this.updateIndexKeysForSlots(indexStoreSlot, entitySlotChannelQueue, patchChannelQueue, changedColumnsChannelQueue);
4204
4409
  }
4205
4410
  };
4206
- const indexStoreSlot = this.createStoreSlotWith((store) => createOIMIndexStoreSlot(store, this, sourceStoreSlot, contentChangeListener));
4411
+ const indexStoreSlot = this.createStoreSlotOverNewStore((store) => createOIMIndexStoreSlot(store, this, sourceStoreSlot, contentChangeListener));
4207
4412
  const indexKeysService = this.indexKeysService;
4208
4413
  const indexKeysPositions = sourceStoreSlot.indexKeysPositions ?? (sourceStoreSlot.indexKeysPositions = indexKeysService.createPositions());
4209
4414
  indexStoreSlot.indexKeysPosition = indexKeysService.allocatePosition(indexKeysPositions);
4210
- OIMContentChangeListenerService.INSTANCE.addContentChangeListener(sourceStoreSlot, contentChangeListener, this.keyColumns);
4415
+ OIMSlotContentChangeListenerService.INSTANCE.addContentChangeListener(sourceStoreSlot, contentChangeListener, this.keyColumns);
4211
4416
  return indexStoreSlot;
4212
4417
  }
4418
+ createStoreAggregate(indexStoreSlot) {
4419
+ return new OIMSlotCollectionIndexStoreAggregate(this, indexStoreSlot);
4420
+ }
4213
4421
  disposeIndexStoreSlot(indexStoreSlot) {
4214
4422
  this.assertNotDisposed(indexStoreSlot);
4215
4423
  OIMChannelService.INSTANCE.assertNotFlushing(indexStoreSlot.channelSlot);
4216
4424
  const sourceStoreSlot = indexStoreSlot.sourceStoreSlot;
4217
- OIMContentChangeListenerService.INSTANCE.removeContentChangeListener(sourceStoreSlot, indexStoreSlot.contentChangeListener);
4425
+ OIMSlotContentChangeListenerService.INSTANCE.removeContentChangeListener(sourceStoreSlot, indexStoreSlot.contentChangeListener);
4218
4426
  for (const bucketColumnName of indexStoreSlot.bucketColumnNames) {
4219
- OIMContentChangeListenerService.INSTANCE.removeReadColumn(sourceStoreSlot, bucketColumnName);
4427
+ OIMSlotContentChangeListenerService.INSTANCE.removeReadColumn(sourceStoreSlot, bucketColumnName);
4220
4428
  }
4221
- if (indexStoreSlot.isAnyBucketColumnRead) OIMContentChangeListenerService.INSTANCE.removeReadAnyColumn(sourceStoreSlot);
4429
+ if (indexStoreSlot.isAnyBucketColumnRead) OIMSlotContentChangeListenerService.INSTANCE.removeReadAnyColumn(sourceStoreSlot);
4222
4430
  const indexKeysPositions = sourceStoreSlot.indexKeysPositions;
4223
4431
  if (indexKeysPositions !== void 0) {
4224
4432
  this.indexKeysService.releasePosition(
@@ -4265,10 +4473,10 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4265
4473
  }
4266
4474
  walkSlotsByKeys(indexStoreSlot, keys, takeFoundSlot, slotByKeyDoor) {
4267
4475
  this.assertNotDisposed(indexStoreSlot);
4268
- const indexStoreSlotEditable = indexStoreSlot;
4476
+ const editableIndexStoreSlot = indexStoreSlot;
4269
4477
  const bucketSlots = [];
4270
4478
  let entitySlotsByMintedBucketSlot;
4271
- indexStoreSlotEditable.requestedKeys = keys;
4479
+ editableIndexStoreSlot.requestedKeys = keys;
4272
4480
  try {
4273
4481
  for (let i = 0; i < keys.length; i++) {
4274
4482
  const foundBucketSlot = this.findSlotByKey(indexStoreSlot, keys[i]);
@@ -4282,7 +4490,7 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4282
4490
  bucketSlots.push(bucketSlot);
4283
4491
  }
4284
4492
  } finally {
4285
- indexStoreSlotEditable.requestedKeys = void 0;
4493
+ editableIndexStoreSlot.requestedKeys = void 0;
4286
4494
  if (entitySlotsByMintedBucketSlot !== void 0) this.fillMintedBucketSlots(indexStoreSlot, entitySlotsByMintedBucketSlot);
4287
4495
  }
4288
4496
  return bucketSlots;
@@ -4314,18 +4522,14 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4314
4522
  const bucketColumnNames = indexStoreSlot.bucketColumnNames;
4315
4523
  if (bucketColumnNames.has(columnName)) return;
4316
4524
  bucketColumnNames.add(columnName);
4317
- OIMContentChangeListenerService.INSTANCE.addReadColumn(indexStoreSlot.sourceStoreSlot, columnName);
4525
+ OIMSlotContentChangeListenerService.INSTANCE.addReadColumn(indexStoreSlot.sourceStoreSlot, columnName);
4318
4526
  }
4319
4527
  onBucketColumnsChanged(_indexStoreSlot, _bucketSlot, _entitySlot, _changedColumns) {
4320
4528
  return;
4321
4529
  }
4322
4530
  onSlotMinted(indexStoreSlot, bucketSlot) {
4323
4531
  if (indexStoreSlot.requestedKeys !== void 0) return;
4324
- const key = bucketSlot.key;
4325
- this.slotContentBucketService.fillBucketMemberSlots(
4326
- bucketSlot,
4327
- this.setIndexKeyForSlots(indexStoreSlot, this.collectSourceSlotsForKey(indexStoreSlot, key), key)
4328
- );
4532
+ this.fillBucketSlotWithSourceSlots(indexStoreSlot, bucketSlot, this.collectSourceSlotsForKey(indexStoreSlot, bucketSlot.key));
4329
4533
  }
4330
4534
  assertNotDisposed(storeSlot) {
4331
4535
  if (!storeSlot.isDisposed) return;
@@ -4336,7 +4540,7 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4336
4540
  addAnyBucketColumnRead(indexStoreSlot) {
4337
4541
  if (indexStoreSlot.isAnyBucketColumnRead) return;
4338
4542
  indexStoreSlot.isAnyBucketColumnRead = true;
4339
- OIMContentChangeListenerService.INSTANCE.addReadAnyColumn(indexStoreSlot.sourceStoreSlot);
4543
+ OIMSlotContentChangeListenerService.INSTANCE.addReadAnyColumn(indexStoreSlot.sourceStoreSlot);
4340
4544
  }
4341
4545
  fillMintedBucketSlots(indexStoreSlot, entitySlotsByMintedBucketSlot) {
4342
4546
  for (const entitySlot of this.sourceSlotCollectionService.getSlots(indexStoreSlot.sourceStoreSlot)) {
@@ -4348,7 +4552,7 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4348
4552
  const slotContentService = this.slotContentBucketService;
4349
4553
  const slotOwnerService = this.slotOwnerService;
4350
4554
  for (const [bucketSlot, entitySlots] of entitySlotsByMintedBucketSlot) {
4351
- slotContentService.fillBucketMemberSlots(bucketSlot, this.setIndexKeyForSlots(indexStoreSlot, entitySlots, bucketSlot.key));
4555
+ this.fillBucketSlotWithSourceSlots(indexStoreSlot, bucketSlot, entitySlots);
4352
4556
  slotOwnerService.settleEmptiness(bucketSlot, slotContentService.isSlotEmpty(bucketSlot));
4353
4557
  }
4354
4558
  }
@@ -4488,40 +4692,42 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4488
4692
  }
4489
4693
  return matchingEntitySlots;
4490
4694
  }
4491
- setIndexKeyForSlots(indexStoreSlot, entitySlots, key) {
4695
+ fillBucketSlotWithSourceSlots(indexStoreSlot, bucketSlot, entitySlots) {
4492
4696
  const indexKeysService = this.indexKeysService;
4493
4697
  const indexKeysPosition = indexStoreSlot.indexKeysPosition;
4494
- const channelSlot = indexStoreSlot.channelSlot;
4495
- const isRefusingWrites = OIMChannelService.INSTANCE.isRefusingWrites(channelSlot);
4496
- let movableEntitySlots;
4698
+ const key = bucketSlot.key;
4699
+ const isRefusingWrites = OIMChannelService.INSTANCE.isRefusingWrites(indexStoreSlot.channelSlot);
4700
+ const fillingEntitySlots = [];
4701
+ const prevKeys = [];
4702
+ const movingEntitySlots = [];
4497
4703
  for (let i = 0; i < entitySlots.length; i++) {
4498
4704
  const entitySlot = entitySlots[i];
4499
4705
  const prevKey = indexKeysService.get(entitySlot, indexKeysPosition);
4500
4706
  const isMoving = prevKey !== void 0 && !this.isSameKey(prevKey, key);
4501
- if (isMoving && isRefusingWrites) {
4502
- movableEntitySlots ?? (movableEntitySlots = entitySlots.slice(0, i));
4503
- continue;
4504
- }
4505
- movableEntitySlots?.push(entitySlot);
4707
+ if (isMoving && isRefusingWrites) continue;
4708
+ fillingEntitySlots.push(entitySlot);
4506
4709
  indexKeysService.set(entitySlot, indexKeysPosition, key);
4507
4710
  if (!isMoving) continue;
4508
- OIMUnusedSlotCollectorService.INSTANCE.holdSlotUntilFlush(channelSlot.collectorSlot.unusedSlotCollectorSlot, entitySlot);
4509
- const prevBucketSlot = this.findSlotByKey(indexStoreSlot, prevKey);
4510
- if (prevBucketSlot !== void 0) this.slotContentBucketService.removeBucketMemberSlot(prevBucketSlot, entitySlot);
4711
+ prevKeys.push(prevKey);
4712
+ movingEntitySlots.push(entitySlot);
4713
+ }
4714
+ this.slotContentBucketService.fillBucketMemberSlots(bucketSlot, fillingEntitySlots);
4715
+ for (let i = 0; i < movingEntitySlots.length; i++) {
4716
+ const prevBucketSlot = this.findSlotByKey(indexStoreSlot, prevKeys[i]);
4717
+ if (prevBucketSlot !== void 0) this.slotContentBucketService.removeBucketMemberSlot(prevBucketSlot, movingEntitySlots[i]);
4511
4718
  }
4512
- return movableEntitySlots ?? entitySlots;
4513
4719
  }
4514
4720
  };
4515
4721
  function takeNothing() {
4516
4722
  return;
4517
4723
  }
4518
4724
 
4519
- // src/facade/index/OIMSlotCollectionSortedArrayIndexService.ts
4725
+ // src/index/OIMSlotCollectionSortedArrayIndexService.ts
4520
4726
  var OIMSlotCollectionSortedArrayIndexService = class extends OIMSlotCollectionIndexService {
4521
4727
  constructor(options) {
4522
4728
  super(options);
4523
4729
  const sortColumnNames = /* @__PURE__ */ new Set();
4524
- for (let i = 0; i < options.sortColumns.length; i++) sortColumnNames.add(options.sortColumns[i].column);
4730
+ for (let i = 0; i < options.sortColumns.length; i++) sortColumnNames.add(options.sortColumns[i].columnName);
4525
4731
  this.sortColumnNames = sortColumnNames;
4526
4732
  }
4527
4733
  createIndexStoreSlot(sourceStoreSlot) {
@@ -4543,7 +4749,51 @@ var OIMSlotCollectionSortedArrayIndexService = class extends OIMSlotCollectionIn
4543
4749
  }
4544
4750
  };
4545
4751
 
4546
- // src/factories/utils/oimKeyOfColumns.ts
4752
+ // src/index/OIMIndexKeysService.ts
4753
+ var OIMIndexKeysService = class {
4754
+ createPositions() {
4755
+ return { nextPosition: 0, freePositions: [] };
4756
+ }
4757
+ get(slot, position) {
4758
+ const indexKeys = slot.indexKeys;
4759
+ return indexKeys === void 0 || position >= indexKeys.length ? void 0 : indexKeys[position];
4760
+ }
4761
+ set(slot, position, indexKey) {
4762
+ const indexKeys = slot.indexKeys;
4763
+ if (indexKeys !== void 0) {
4764
+ if (position < indexKeys.length) {
4765
+ indexKeys[position] = indexKey;
4766
+ return;
4767
+ }
4768
+ if (indexKey === void 0) return;
4769
+ while (indexKeys.length < position) indexKeys.push(void 0);
4770
+ indexKeys.push(indexKey);
4771
+ return;
4772
+ }
4773
+ if (indexKey === void 0) return;
4774
+ const created = [];
4775
+ while (created.length < position) created.push(void 0);
4776
+ created.push(indexKey);
4777
+ slot.indexKeys = created;
4778
+ }
4779
+ };
4780
+
4781
+ // src/index/OIMAppendingIndexKeysService.ts
4782
+ var _OIMAppendingIndexKeysService = class _OIMAppendingIndexKeysService extends OIMIndexKeysService {
4783
+ allocatePosition(positions) {
4784
+ return positions.nextPosition++;
4785
+ }
4786
+ releasePosition() {
4787
+ return;
4788
+ }
4789
+ };
4790
+ _OIMAppendingIndexKeysService.INSTANCE = new _OIMAppendingIndexKeysService();
4791
+ var OIMAppendingIndexKeysService = _OIMAppendingIndexKeysService;
4792
+
4793
+ // src/db/constants/OIM_DEFAULT_INDEX_KEYS_SERVICE.ts
4794
+ var OIM_DEFAULT_INDEX_KEYS_SERVICE = /* @__PURE__ */ new OIMDefaultValue(() => OIMAppendingIndexKeysService.INSTANCE);
4795
+
4796
+ // src/index/utils/oimKeyOfColumns.ts
4547
4797
  function oimKeyOfColumns(columns) {
4548
4798
  if (columns.length === 1) {
4549
4799
  const column = columns[0];
@@ -4556,47 +4806,47 @@ function oimKeyOfColumns(columns) {
4556
4806
  };
4557
4807
  }
4558
4808
 
4559
- // src/factories/utils/oimSlotCollectionIndexServiceOptionsWithDefault.ts
4560
- function oimSlotCollectionIndexServiceOptionsWithDefault(db, options, slotStoreService, slotContentService) {
4809
+ // src/index/utils/oimResolveSlotCollectionIndexServiceOptions.ts
4810
+ function oimResolveSlotCollectionIndexServiceOptions(defaults, options, slotStoreService, slotContentService) {
4561
4811
  return {
4562
- ...oimSlotOwnerOptionsWithDefault(db, options),
4812
+ ...oimResolveSlotOwnerServiceOptions(defaults, options),
4563
4813
  slotStoreService,
4564
4814
  slotContentService,
4565
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
4815
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
4566
4816
  keyOf: options.keyOf ?? oimKeyOfColumns(options.columns),
4567
4817
  columns: options.columns,
4568
4818
  sourceSlotCollectionService: options.entityService,
4569
- indexKeysService: db.indexKeysService ?? OIM_DEFAULT_INDEX_KEYS_SERVICE.getValue()
4819
+ indexKeysService: defaults.indexKeysService ?? OIM_DEFAULT_INDEX_KEYS_SERVICE.getValue()
4570
4820
  };
4571
4821
  }
4572
4822
 
4573
- // src/factories/createOIMSlotCollectionIndexService.ts
4574
- function createOIMSlotCollectionIndexService(db, options) {
4575
- return new OIMSlotCollectionIndexService(oimSlotCollectionIndexServiceOptionsWithDefault(
4576
- db,
4823
+ // src/index/createOIMSlotCollectionIndexService.ts
4824
+ function createOIMSlotCollectionIndexService(options) {
4825
+ return new OIMSlotCollectionIndexService(oimResolveSlotCollectionIndexServiceOptions(
4826
+ options.defaults ?? OIMDefaults.INSTANCE,
4577
4827
  options,
4578
- oimSlotStoreServiceWithDefault(options.bucketSlotStoreService),
4828
+ oimResolveSlotStoreService(options.bucketSlotStoreService),
4579
4829
  options.slotContentService ?? new OIMSlotContentPositionalArrayBucketService()
4580
4830
  ));
4581
4831
  }
4582
4832
 
4583
- // src/factories/createOIMSlotCollectionSortedArrayIndexService.ts
4584
- function createOIMSlotCollectionSortedArrayIndexService(db, options) {
4833
+ // src/index/createOIMSlotCollectionSortedArrayIndexService.ts
4834
+ function createOIMSlotCollectionSortedArrayIndexService(options) {
4585
4835
  const slotContentService = new OIMSlotContentSortedArrayBucketService({
4586
4836
  compareBucketMemberSlots: oimEntitySlotsComparator(oimColumnsComparator(options.sortColumns))
4587
4837
  });
4588
4838
  return new OIMSlotCollectionSortedArrayIndexService({
4589
- ...oimSlotCollectionIndexServiceOptionsWithDefault(
4590
- db,
4839
+ ...oimResolveSlotCollectionIndexServiceOptions(
4840
+ options.defaults ?? OIMDefaults.INSTANCE,
4591
4841
  options,
4592
- oimSlotStoreServiceWithDefault(options.bucketSlotStoreService),
4842
+ oimResolveSlotStoreService(options.bucketSlotStoreService),
4593
4843
  slotContentService
4594
4844
  ),
4595
4845
  sortColumns: options.sortColumns
4596
4846
  });
4597
4847
  }
4598
4848
 
4599
- // src/engine/index/OIMReclaimingIndexKeysService.ts
4849
+ // src/index/OIMReclaimingIndexKeysService.ts
4600
4850
  var OIMReclaimingIndexKeysService = class extends OIMIndexKeysService {
4601
4851
  allocatePosition(positions) {
4602
4852
  const freePosition = positions.freePositions.pop();
@@ -4611,18 +4861,18 @@ var OIMReclaimingIndexKeysService = class extends OIMIndexKeysService {
4611
4861
  }
4612
4862
  };
4613
4863
 
4614
- // src/engine/entity/utils/oimCopyEntity.ts
4864
+ // src/entity/utils/oimCopyEntity.ts
4615
4865
  function oimCopyEntity(entity) {
4616
4866
  return { ...entity };
4617
4867
  }
4618
4868
 
4619
- // src/factories/createOIMEntityWriterReplacing.ts
4869
+ // src/entity/createOIMReplacingEntityWriter.ts
4620
4870
  function storeReplacement(slot, next) {
4621
4871
  if (next === void 0) return false;
4622
4872
  slot.entity = next;
4623
4873
  return true;
4624
4874
  }
4625
- function deleteColumnsReplacing(slot, names) {
4875
+ function deleteColumnsInCopy(slot, names) {
4626
4876
  const deleted = oimOwnedColumnNames(slot, names);
4627
4877
  if (deleted === void 0) return OIM_FROZEN_EMPTY_COLUMN_NAMES;
4628
4878
  const next = oimCopyEntity(slot.entity);
@@ -4630,61 +4880,61 @@ function deleteColumnsReplacing(slot, names) {
4630
4880
  slot.entity = next;
4631
4881
  return deleted;
4632
4882
  }
4633
- function createOIMEntityWriterReplacing(options) {
4883
+ function createOIMReplacingEntityWriter(options) {
4634
4884
  const {
4635
4885
  sameValueGuard,
4636
4886
  entityInserter,
4637
4887
  putEntityColumns,
4638
4888
  patchEntityColumns,
4639
4889
  patchEntityColumn
4640
- } = oimEntityWriterOptionsWithDefault(options);
4890
+ } = oimResolveEntityWriterOptions(options);
4641
4891
  return {
4642
4892
  fillEntity: entityInserter,
4643
4893
  clearEntity: oimClearEntity,
4644
4894
  putEntity: (slot, entity, changedColumnNames) => storeReplacement(slot, putEntityColumns(slot, entity, sameValueGuard, changedColumnNames, oimCopyEntity)),
4645
4895
  patchEntity: (slot, patch, changedColumnNames) => storeReplacement(slot, patchEntityColumns(slot, patch, sameValueGuard, changedColumnNames, oimCopyEntity)),
4646
4896
  patchColumn: (slot, columnName, value, changedColumnNames) => storeReplacement(slot, patchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, oimCopyEntity)),
4647
- deleteColumns: deleteColumnsReplacing
4897
+ deleteColumns: deleteColumnsInCopy
4648
4898
  };
4649
4899
  }
4650
4900
 
4651
- // src/engine/entity/utils/oimInsertEntityWithCopy.ts
4901
+ // src/entity/utils/oimInsertEntityWithCopy.ts
4652
4902
  function oimInsertEntityWithCopy(slot, entity) {
4653
4903
  slot.entity = oimCopyEntity(entity);
4654
4904
  }
4655
4905
 
4656
- // src/engine/entity/utils/oimCopyEntitySanitized.ts
4657
- function oimCopyEntitySanitized(entity) {
4906
+ // src/entity/utils/oimSanitizedCopyEntity.ts
4907
+ function oimSanitizedCopyEntity(entity) {
4658
4908
  const copy = { ...entity };
4659
4909
  if (Object.hasOwn(copy, OIM_PROTO_KEY)) delete copy[OIM_PROTO_KEY];
4660
4910
  return copy;
4661
4911
  }
4662
4912
 
4663
- // src/engine/entity/utils/oimInsertEntityWithSanitizedCopy.ts
4913
+ // src/entity/utils/oimInsertEntityWithSanitizedCopy.ts
4664
4914
  function oimInsertEntityWithSanitizedCopy(slot, entity) {
4665
- slot.entity = oimCopyEntitySanitized(entity);
4915
+ slot.entity = oimSanitizedCopyEntity(entity);
4666
4916
  }
4667
4917
 
4668
- // src/engine/entity/utils/oimIsPlain.ts
4669
- function oimIsPlain(source) {
4918
+ // src/entity/utils/oimIsPlainObject.ts
4919
+ function oimIsPlainObject(source) {
4670
4920
  const proto = Object.getPrototypeOf(source);
4671
4921
  return proto === Object.prototype || proto === null;
4672
4922
  }
4673
4923
 
4674
- // src/engine/entity/utils/oimOwnEntityColumns.ts
4924
+ // src/entity/utils/oimOwnEntityColumns.ts
4675
4925
  function oimOwnEntityColumns(entity) {
4676
- if (oimIsPlain(entity) && !Object.hasOwn(entity, OIM_PROTO_KEY)) return entity;
4677
- return oimCopyEntitySanitized(entity);
4926
+ if (oimIsPlainObject(entity) && !Object.hasOwn(entity, OIM_PROTO_KEY)) return entity;
4927
+ return oimSanitizedCopyEntity(entity);
4678
4928
  }
4679
4929
 
4680
- // src/engine/entity/utils/oimPatchEntityColumnsGuarded.ts
4681
- var oimPatchEntityColumnsGuarded = (slot, patch, sameValueGuard, changedColumnNames, targetOf) => oimPatchEntityColumns(slot, oimOwnEntityColumns(patch), sameValueGuard, changedColumnNames, targetOf);
4930
+ // src/entity/utils/oimGuardedPatchEntityColumns.ts
4931
+ var oimGuardedPatchEntityColumns = (slot, patch, sameValueGuard, changedColumnNames, targetOf) => oimPatchEntityColumns(slot, oimOwnEntityColumns(patch), sameValueGuard, changedColumnNames, targetOf);
4682
4932
 
4683
- // src/engine/entity/utils/oimPatchEntityColumnGuarded.ts
4684
- var oimPatchEntityColumnGuarded = (slot, columnName, value, sameValueGuard, changedColumnNames, targetOf) => oimIsProtoKey(columnName) ? void 0 : oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, targetOf);
4933
+ // src/entity/utils/oimGuardedPatchEntityColumn.ts
4934
+ var oimGuardedPatchEntityColumn = (slot, columnName, value, sameValueGuard, changedColumnNames, targetOf) => oimIsProtoKey(columnName) ? void 0 : oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, targetOf);
4685
4935
 
4686
- // src/engine/entity/utils/oimPutEntityColumnsGuarded.ts
4687
- var oimPutEntityColumnsGuarded = (slot, entity, sameValueGuard, changedColumnNames, targetOf) => {
4936
+ // src/entity/utils/oimGuardedPutEntityColumns.ts
4937
+ var oimGuardedPutEntityColumns = (slot, entity, sameValueGuard, changedColumnNames, targetOf) => {
4688
4938
  const prevEntity = slot.entity;
4689
4939
  if (prevEntity === void 0) return void 0;
4690
4940
  const ownColumns = oimOwnEntityColumns(entity);
@@ -4699,13 +4949,13 @@ var oimPutEntityColumnsGuarded = (slot, entity, sameValueGuard, changedColumnNam
4699
4949
  );
4700
4950
  };
4701
4951
 
4702
- // src/engine/collector/constants/OIM_SLICE_LENGTH_MS.ts
4952
+ // src/collector/constants/OIM_SLICE_LENGTH_MS.ts
4703
4953
  var OIM_SLICE_LENGTH_MS = 1024;
4704
4954
 
4705
- // src/engine/collector/utils/oimSliceOfMs.ts
4955
+ // src/collector/utils/oimSliceOfMs.ts
4706
4956
  var oimSliceOfMs = (ms) => Math.floor(ms / OIM_SLICE_LENGTH_MS);
4707
4957
 
4708
- // src/engine/collector/OIMSlotWheel.ts
4958
+ // src/collector/OIMSlotWheel.ts
4709
4959
  var OIMSlotWheel = class {
4710
4960
  constructor(options) {
4711
4961
  this.scheduledCallback = void 0;
@@ -4843,7 +5093,7 @@ var OIMSlotWheel = class {
4843
5093
  }
4844
5094
  };
4845
5095
 
4846
- // src/engine/collector/OIMSlotReleaseWheel.ts
5096
+ // src/collector/OIMSlotReleaseWheel.ts
4847
5097
  var OIMSlotReleaseWheel = class extends OIMSlotWheel {
4848
5098
  constructor(options) {
4849
5099
  super(options);
@@ -4904,20 +5154,20 @@ var OIMSlotReleaseWheel = class extends OIMSlotWheel {
4904
5154
  }
4905
5155
  };
4906
5156
 
4907
- // src/engine/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_WRITE.ts
5157
+ // src/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_WRITE.ts
4908
5158
  var OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_WRITE = 8;
4909
5159
 
4910
- // src/engine/slot/utils/oimGetReleaseDueAfterWriteMs.ts
5160
+ // src/slot/utils/oimGetReleaseDueAfterWriteMs.ts
4911
5161
  function oimGetReleaseDueAfterWriteMs(slot) {
4912
5162
  return slot.releaseDueAfterWriteMs;
4913
5163
  }
4914
5164
 
4915
- // src/engine/slot/utils/oimSetReleaseDueAfterWriteMs.ts
5165
+ // src/slot/utils/oimSetReleaseDueAfterWriteMs.ts
4916
5166
  function oimSetReleaseDueAfterWriteMs(slot, releaseDueMs) {
4917
5167
  slot.releaseDueAfterWriteMs = releaseDueMs;
4918
5168
  }
4919
5169
 
4920
- // src/engine/collector/utils/oimMintAfterWriteSlotReleaseWheel.ts
5170
+ // src/collector/utils/oimMintAfterWriteSlotReleaseWheel.ts
4921
5171
  function oimMintAfterWriteSlotReleaseWheel(collectorSlot) {
4922
5172
  return collectorSlot.afterWriteSlotReleaseWheel ?? (collectorSlot.afterWriteSlotReleaseWheel = new OIMSlotReleaseWheel({
4923
5173
  ...collectorSlot.slotWheelOptions,
@@ -4927,20 +5177,20 @@ function oimMintAfterWriteSlotReleaseWheel(collectorSlot) {
4927
5177
  }));
4928
5178
  }
4929
5179
 
4930
- // src/engine/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_IDLE.ts
5180
+ // src/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_IDLE.ts
4931
5181
  var OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_IDLE = 4;
4932
5182
 
4933
- // src/engine/slot/utils/oimGetReleaseDueAfterIdleMs.ts
5183
+ // src/slot/utils/oimGetReleaseDueAfterIdleMs.ts
4934
5184
  function oimGetReleaseDueAfterIdleMs(slot) {
4935
5185
  return slot.releaseDueAfterIdleMs;
4936
5186
  }
4937
5187
 
4938
- // src/engine/slot/utils/oimSetReleaseDueAfterIdleMs.ts
5188
+ // src/slot/utils/oimSetReleaseDueAfterIdleMs.ts
4939
5189
  function oimSetReleaseDueAfterIdleMs(slot, releaseDueMs) {
4940
5190
  slot.releaseDueAfterIdleMs = releaseDueMs;
4941
5191
  }
4942
5192
 
4943
- // src/engine/collector/utils/oimMintAfterIdleSlotReleaseWheel.ts
5193
+ // src/collector/utils/oimMintAfterIdleSlotReleaseWheel.ts
4944
5194
  function oimMintAfterIdleSlotReleaseWheel(collectorSlot) {
4945
5195
  return collectorSlot.afterIdleSlotReleaseWheel ?? (collectorSlot.afterIdleSlotReleaseWheel = new OIMSlotReleaseWheel({
4946
5196
  ...collectorSlot.slotWheelOptions,
@@ -4950,20 +5200,20 @@ function oimMintAfterIdleSlotReleaseWheel(collectorSlot) {
4950
5200
  }));
4951
5201
  }
4952
5202
 
4953
- // src/engine/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_UNHOLD.ts
5203
+ // src/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_UNHOLD.ts
4954
5204
  var OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_UNHOLD = 16;
4955
5205
 
4956
- // src/engine/slot/utils/oimGetReleaseDueAfterUnholdMs.ts
5206
+ // src/slot/utils/oimGetReleaseDueAfterUnholdMs.ts
4957
5207
  function oimGetReleaseDueAfterUnholdMs(slot) {
4958
5208
  return slot.releaseDueAfterUnholdMs;
4959
5209
  }
4960
5210
 
4961
- // src/engine/slot/utils/oimSetReleaseDueAfterUnholdMs.ts
5211
+ // src/slot/utils/oimSetReleaseDueAfterUnholdMs.ts
4962
5212
  function oimSetReleaseDueAfterUnholdMs(slot, releaseDueMs) {
4963
5213
  slot.releaseDueAfterUnholdMs = releaseDueMs;
4964
5214
  }
4965
5215
 
4966
- // src/engine/collector/utils/oimMintAfterUnholdSlotReleaseWheel.ts
5216
+ // src/collector/utils/oimMintAfterUnholdSlotReleaseWheel.ts
4967
5217
  function oimMintAfterUnholdSlotReleaseWheel(collectorSlot) {
4968
5218
  return collectorSlot.afterUnholdSlotReleaseWheel ?? (collectorSlot.afterUnholdSlotReleaseWheel = new OIMSlotReleaseWheel({
4969
5219
  ...collectorSlot.slotWheelOptions,
@@ -4973,7 +5223,7 @@ function oimMintAfterUnholdSlotReleaseWheel(collectorSlot) {
4973
5223
  }));
4974
5224
  }
4975
5225
 
4976
- // src/engine/collector/OIMSlotRefetchWheel.ts
5226
+ // src/collector/OIMSlotRefetchWheel.ts
4977
5227
  var OIMSlotRefetchWheel = class extends OIMSlotWheel {
4978
5228
  constructor(options) {
4979
5229
  super({
@@ -5007,7 +5257,7 @@ var OIMSlotRefetchWheel = class extends OIMSlotWheel {
5007
5257
  }
5008
5258
  };
5009
5259
 
5010
- // src/engine/collector/OIMSlotReleaseAutoDueFramePolicy.ts
5260
+ // src/collector/OIMSlotReleaseAutoDueFramePolicy.ts
5011
5261
  var _OIMSlotReleaseAutoDueFramePolicy = class _OIMSlotReleaseAutoDueFramePolicy {
5012
5262
  isSlotReleaseDueFrameOpen() {
5013
5263
  return true;
@@ -5016,7 +5266,7 @@ var _OIMSlotReleaseAutoDueFramePolicy = class _OIMSlotReleaseAutoDueFramePolicy
5016
5266
  _OIMSlotReleaseAutoDueFramePolicy.INSTANCE = new _OIMSlotReleaseAutoDueFramePolicy();
5017
5267
  var OIMSlotReleaseAutoDueFramePolicy = _OIMSlotReleaseAutoDueFramePolicy;
5018
5268
 
5019
- // src/engine/collector/OIMSlotAfterWriteReleasePolicy.ts
5269
+ // src/collector/OIMSlotAfterWriteReleasePolicy.ts
5020
5270
  var OIMSlotAfterWriteReleasePolicy = class {
5021
5271
  constructor(options) {
5022
5272
  this.releasesWrittenSlots = true;
@@ -5045,7 +5295,7 @@ var OIMSlotAfterWriteReleasePolicy = class {
5045
5295
  }
5046
5296
  };
5047
5297
 
5048
- // src/engine/collector/OIMSlotReleaseManualDueFramePolicy.ts
5298
+ // src/collector/OIMSlotReleaseManualDueFramePolicy.ts
5049
5299
  var OIMSlotReleaseManualDueFramePolicy = class {
5050
5300
  constructor() {
5051
5301
  this.slotReleaseDueFrameDepth = 0;
@@ -5074,7 +5324,7 @@ var OIMSlotReleaseManualDueFramePolicy = class {
5074
5324
  }
5075
5325
  };
5076
5326
 
5077
- // src/engine/collector/OIMSlotAfterIdleReleasePolicy.ts
5327
+ // src/collector/OIMSlotAfterIdleReleasePolicy.ts
5078
5328
  var OIMSlotAfterIdleReleasePolicy = class {
5079
5329
  constructor(options) {
5080
5330
  this.releasesWrittenSlots = true;
@@ -5105,7 +5355,7 @@ var OIMSlotAfterIdleReleasePolicy = class {
5105
5355
  }
5106
5356
  };
5107
5357
 
5108
- // src/engine/collector/OIMSlotNeverReleasePolicy.ts
5358
+ // src/collector/OIMSlotNeverReleasePolicy.ts
5109
5359
  var _OIMSlotNeverReleasePolicy = class _OIMSlotNeverReleasePolicy {
5110
5360
  constructor() {
5111
5361
  this.releasesWrittenSlots = false;
@@ -5133,7 +5383,7 @@ var _OIMSlotNeverReleasePolicy = class _OIMSlotNeverReleasePolicy {
5133
5383
  _OIMSlotNeverReleasePolicy.INSTANCE = new _OIMSlotNeverReleasePolicy();
5134
5384
  var OIMSlotNeverReleasePolicy = _OIMSlotNeverReleasePolicy;
5135
5385
 
5136
- // src/engine/collector/OIMSlotAfterUnholdReleasePolicy.ts
5386
+ // src/collector/OIMSlotAfterUnholdReleasePolicy.ts
5137
5387
  var OIMSlotAfterUnholdReleasePolicy = class {
5138
5388
  constructor(options) {
5139
5389
  this.releasesWrittenSlots = true;
@@ -5160,7 +5410,7 @@ var OIMSlotAfterUnholdReleasePolicy = class {
5160
5410
  }
5161
5411
  };
5162
5412
 
5163
- // src/engine/collector/OIMSlotEarliestReleasePolicy.ts
5413
+ // src/collector/OIMSlotEarliestReleasePolicy.ts
5164
5414
  var askOnSlotIdle = (slotReleasePolicy, slot) => slotReleasePolicy.onSlotIdle(slot);
5165
5415
  var askIsSlotReleasable = (slotReleasePolicy, slot) => slotReleasePolicy.isSlotReleasable(slot);
5166
5416
  var askIsEmptySlotReleasable = (slotReleasePolicy, slot) => slotReleasePolicy.isEmptySlotReleasable(slot);
@@ -5207,13 +5457,13 @@ var OIMSlotEarliestReleasePolicy = class {
5207
5457
  }
5208
5458
  };
5209
5459
 
5210
- // src/engine/store/OIMSlotTreeStoreService.ts
5460
+ // src/store/OIMSlotTreeStoreService.ts
5211
5461
  var OIMSlotTreeStoreService = class {
5212
5462
  constructor(keyTreeWalk) {
5213
5463
  this.keyTreeWalk = keyTreeWalk;
5214
5464
  }
5215
5465
  createStore() {
5216
- return { root: { childNodes: void 0, atThisKey: void 0 }, slots: /* @__PURE__ */ new Set() };
5466
+ return { rootCompositeKeyNode: { childNodes: void 0, atThisKey: void 0 }, slots: /* @__PURE__ */ new Set() };
5217
5467
  }
5218
5468
  ownKey(compositeKey) {
5219
5469
  return compositeKey.slice();
@@ -5222,17 +5472,17 @@ var OIMSlotTreeStoreService = class {
5222
5472
  return oimSameKeySequence(compositeKey, otherCompositeKey);
5223
5473
  }
5224
5474
  get(slotStoreTree, compositeKey) {
5225
- return this.keyTreeWalk.nodeAt(slotStoreTree.root, compositeKey)?.atThisKey;
5475
+ return this.keyTreeWalk.nodeAt(slotStoreTree.rootCompositeKeyNode, compositeKey)?.atThisKey;
5226
5476
  }
5227
5477
  set(slotStoreTree, compositeKey, slot) {
5228
- const compositeKeyNode = this.keyTreeWalk.mintNodeAt(slotStoreTree.root, compositeKey);
5478
+ const compositeKeyNode = this.keyTreeWalk.mintNodeAt(slotStoreTree.rootCompositeKeyNode, compositeKey);
5229
5479
  const filedSlot = compositeKeyNode.atThisKey;
5230
5480
  if (filedSlot !== void 0 && filedSlot !== slot) slotStoreTree.slots.delete(filedSlot);
5231
5481
  compositeKeyNode.atThisKey = slot;
5232
5482
  slotStoreTree.slots.add(slot);
5233
5483
  }
5234
5484
  remove(slotStoreTree, compositeKey) {
5235
- const slot = this.keyTreeWalk.deleteKey(slotStoreTree.root, compositeKey);
5485
+ const slot = this.keyTreeWalk.deleteKey(slotStoreTree.rootCompositeKeyNode, compositeKey);
5236
5486
  if (slot !== void 0) slotStoreTree.slots.delete(slot);
5237
5487
  }
5238
5488
  fileSlot(slotStoreTree, slot) {
@@ -5249,10 +5499,100 @@ var OIMSlotTreeStoreService = class {
5249
5499
  }
5250
5500
  };
5251
5501
 
5252
- // src/engine/bucket/commands/constants/OIM_MAX_DIFF_SCRATCH_SLOTS.ts
5502
+ // src/key/OIMKeyTreeWalk.ts
5503
+ var OIMKeyTreeWalk = class {
5504
+ mintNodeAt(rootCompositeKeyNode, compositeKey) {
5505
+ if (compositeKey.length === 0) throw new Error("OIMKeyTreeWalk: an empty key is not a key.");
5506
+ let compositeKeyNode = rootCompositeKeyNode;
5507
+ let firstMintedDepth = -1;
5508
+ let parentOfFirstMintedCompositeKeyNode = rootCompositeKeyNode;
5509
+ for (let i = 0; i < compositeKey.length; i++) {
5510
+ const compositeKeyPart = compositeKey[i];
5511
+ let nextCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKeyPart);
5512
+ if (nextCompositeKeyNode === void 0) {
5513
+ try {
5514
+ this.holdCompositeKeyPart(compositeKeyPart);
5515
+ } catch (failure) {
5516
+ if (firstMintedDepth >= 0) {
5517
+ parentOfFirstMintedCompositeKeyNode.childNodes?.delete(compositeKey[firstMintedDepth]);
5518
+ for (let j = i - 1; j >= firstMintedDepth; j--) this.unholdCompositeKeyPart(compositeKey[j]);
5519
+ }
5520
+ throw failure;
5521
+ }
5522
+ nextCompositeKeyNode = { childNodes: void 0, atThisKey: void 0 };
5523
+ (compositeKeyNode.childNodes ?? (compositeKeyNode.childNodes = /* @__PURE__ */ new Map())).set(compositeKeyPart, nextCompositeKeyNode);
5524
+ if (firstMintedDepth < 0) {
5525
+ firstMintedDepth = i;
5526
+ parentOfFirstMintedCompositeKeyNode = compositeKeyNode;
5527
+ }
5528
+ }
5529
+ compositeKeyNode = nextCompositeKeyNode;
5530
+ }
5531
+ return compositeKeyNode;
5532
+ }
5533
+ nodeAt(rootCompositeKeyNode, compositeKey) {
5534
+ let compositeKeyNode = rootCompositeKeyNode;
5535
+ for (let i = 0; i < compositeKey.length; i++) {
5536
+ compositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[i]);
5537
+ if (compositeKeyNode === void 0) return void 0;
5538
+ }
5539
+ return compositeKeyNode;
5540
+ }
5541
+ deleteKey(rootCompositeKeyNode, compositeKey) {
5542
+ const lastDepth = compositeKey.length - 1;
5543
+ if (lastDepth < 0) return void 0;
5544
+ let compositeKeyNode = rootCompositeKeyNode;
5545
+ let keptCompositeKeyNode = rootCompositeKeyNode;
5546
+ let firstUnlinkedDepth = 0;
5547
+ for (let i = 0; i < lastDepth; i++) {
5548
+ const nextCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[i]);
5549
+ if (nextCompositeKeyNode === void 0) return void 0;
5550
+ compositeKeyNode = nextCompositeKeyNode;
5551
+ if (compositeKeyNode.atThisKey !== void 0 || (compositeKeyNode.childNodes?.size ?? 0) > 1) {
5552
+ keptCompositeKeyNode = compositeKeyNode;
5553
+ firstUnlinkedDepth = i + 1;
5554
+ }
5555
+ }
5556
+ const lastCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[lastDepth]);
5557
+ if (lastCompositeKeyNode === void 0) return void 0;
5558
+ const deletedAtKey = lastCompositeKeyNode.atThisKey;
5559
+ if (deletedAtKey === void 0) return void 0;
5560
+ lastCompositeKeyNode.atThisKey = void 0;
5561
+ if ((lastCompositeKeyNode.childNodes?.size ?? 0) > 0) return deletedAtKey;
5562
+ keptCompositeKeyNode.childNodes?.delete(compositeKey[firstUnlinkedDepth]);
5563
+ for (let i = lastDepth; i >= firstUnlinkedDepth; i--) this.unholdCompositeKeyPart(compositeKey[i]);
5564
+ return deletedAtKey;
5565
+ }
5566
+ };
5567
+
5568
+ // src/key/OIMCompositeKeyTreeWalk.ts
5569
+ var _OIMCompositeKeyTreeWalk = class _OIMCompositeKeyTreeWalk extends OIMKeyTreeWalk {
5570
+ holdCompositeKeyPart(entitySlot) {
5571
+ entitySlot.owner.holdSlot(entitySlot);
5572
+ }
5573
+ unholdCompositeKeyPart(entitySlot) {
5574
+ oimUnholdSlotIfAlive(entitySlot);
5575
+ }
5576
+ };
5577
+ _OIMCompositeKeyTreeWalk.INSTANCE = new _OIMCompositeKeyTreeWalk();
5578
+ var OIMCompositeKeyTreeWalk = _OIMCompositeKeyTreeWalk;
5579
+
5580
+ // src/key/OIMScalarKeyTreeWalk.ts
5581
+ var _OIMScalarKeyTreeWalk = class _OIMScalarKeyTreeWalk extends OIMKeyTreeWalk {
5582
+ holdCompositeKeyPart() {
5583
+ return;
5584
+ }
5585
+ unholdCompositeKeyPart() {
5586
+ return;
5587
+ }
5588
+ };
5589
+ _OIMScalarKeyTreeWalk.INSTANCE = new _OIMScalarKeyTreeWalk();
5590
+ var OIMScalarKeyTreeWalk = _OIMScalarKeyTreeWalk;
5591
+
5592
+ // src/bucket/commands/constants/OIM_MAX_DIFF_SCRATCH_SLOTS.ts
5253
5593
  var OIM_MAX_DIFF_SCRATCH_SLOTS = 4096;
5254
5594
 
5255
- // src/engine/bucket/commands/utils/oimOrderedListCommandsOfTransition.ts
5595
+ // src/bucket/commands/utils/oimOrderedListCommandsOfTransition.ts
5256
5596
  var indexInNext = /* @__PURE__ */ new Map();
5257
5597
  var occurrenceAfter = new Int32Array(0);
5258
5598
  var removedPrevIndices = new Int32Array(0);
@@ -5365,7 +5705,6 @@ oimRegisterCoreInstance(OIMDB);
5365
5705
  OIMCompositeKeyTreeWalk,
5366
5706
  OIMComputedService,
5367
5707
  OIMComputedValueService,
5368
- OIMContentChangeListenerService,
5369
5708
  OIMDB,
5370
5709
  OIMDefaultValue,
5371
5710
  OIMDefaults,
@@ -5381,17 +5720,22 @@ oimRegisterCoreInstance(OIMDB);
5381
5720
  OIMScalarKeyTreeWalk,
5382
5721
  OIMSingleComputedService,
5383
5722
  OIMSingleSlotService,
5723
+ OIMSingleSlotStoreAggregate,
5384
5724
  OIMSingleSlotStoreService,
5725
+ OIMSingleSourceTrackingComputedService,
5385
5726
  OIMSlotAfterIdleReleasePolicy,
5386
5727
  OIMSlotAfterUnholdReleasePolicy,
5387
5728
  OIMSlotAfterWriteReleasePolicy,
5388
5729
  OIMSlotAtEmptyReleasePolicy,
5389
5730
  OIMSlotAtUnholdReleasePolicy,
5390
5731
  OIMSlotCollectionIndexService,
5732
+ OIMSlotCollectionIndexStoreAggregate,
5391
5733
  OIMSlotCollectionService,
5392
5734
  OIMSlotCollectionSortedArrayIndexService,
5735
+ OIMSlotCollectionStoreAggregate,
5393
5736
  OIMSlotContentArrayBucketService,
5394
5737
  OIMSlotContentBucketService,
5738
+ OIMSlotContentChangeListenerService,
5395
5739
  OIMSlotContentEntityService,
5396
5740
  OIMSlotContentPositionalArrayBucketService,
5397
5741
  OIMSlotContentSetBucketService,
@@ -5407,10 +5751,13 @@ oimRegisterCoreInstance(OIMDB);
5407
5751
  OIMSlotTreeStoreService,
5408
5752
  OIMSlotWheel,
5409
5753
  OIMSortedComputedService,
5754
+ OIMSourceTrackingComputedService,
5410
5755
  OIMThrowAtOnceErrorPolicy,
5411
5756
  OIMUnusedSlotCollectorService,
5412
5757
  OIMWritableSingleSlotService,
5758
+ OIMWritableSingleSlotStoreAggregate,
5413
5759
  OIMWritableSlotCollectionService,
5760
+ OIMWritableSlotCollectionStoreAggregate,
5414
5761
  OIM_FROZEN_EMPTY_SLOTS,
5415
5762
  OIM_NOTHING_WAS_INSERTED,
5416
5763
  OIM_NOTHING_WAS_REMOVED,
@@ -5420,17 +5767,24 @@ oimRegisterCoreInstance(OIMDB);
5420
5767
  createOIMChannelSlot,
5421
5768
  createOIMCollectorSlot,
5422
5769
  createOIMComputedService,
5423
- createOIMEntityWriterInPlace,
5424
- createOIMEntityWriterReplacing,
5770
+ createOIMInPlaceEntityWriter,
5771
+ createOIMReplacingEntityWriter,
5425
5772
  createOIMSingleComputedService,
5426
5773
  createOIMSingleSlotService,
5774
+ createOIMSingleSlotStoreAggregate,
5775
+ createOIMSingleSourceTrackingComputedService,
5427
5776
  createOIMSlotCollectionIndexService,
5428
5777
  createOIMSlotCollectionService,
5429
5778
  createOIMSlotCollectionSortedArrayIndexService,
5779
+ createOIMSlotCollectionStoreAggregate,
5430
5780
  createOIMSlotContentEntityService,
5431
5781
  createOIMSortedComputedService,
5782
+ createOIMSourceTrackingComputedService,
5432
5783
  createOIMUnusedSlotCollectorSlot,
5433
5784
  oimColumnsComparator,
5785
+ oimGuardedPatchEntityColumn,
5786
+ oimGuardedPatchEntityColumns,
5787
+ oimGuardedPutEntityColumns,
5434
5788
  oimHoldSlots,
5435
5789
  oimInsertEntityWithCopy,
5436
5790
  oimInsertEntityWithSanitizedCopy,
@@ -5443,11 +5797,8 @@ oimRegisterCoreInstance(OIMDB);
5443
5797
  oimMintAfterWriteSlotReleaseWheel,
5444
5798
  oimOrderedListCommandsOfTransition,
5445
5799
  oimPatchEntityColumn,
5446
- oimPatchEntityColumnGuarded,
5447
5800
  oimPatchEntityColumns,
5448
- oimPatchEntityColumnsGuarded,
5449
5801
  oimPutEntityColumns,
5450
- oimPutEntityColumnsGuarded,
5451
5802
  oimRefreshSourceComputeds,
5452
5803
  oimSameKeySequence,
5453
5804
  oimSameSlotSequence,