@oimdb/core 4.1.0 → 4.2.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,
@@ -48,6 +47,7 @@ __export(index_exports, {
48
47
  OIMSingleComputedService: () => OIMSingleComputedService,
49
48
  OIMSingleSlotService: () => OIMSingleSlotService,
50
49
  OIMSingleSlotStoreService: () => OIMSingleSlotStoreService,
50
+ OIMSingleSourceTrackingComputedService: () => OIMSingleSourceTrackingComputedService,
51
51
  OIMSlotAfterIdleReleasePolicy: () => OIMSlotAfterIdleReleasePolicy,
52
52
  OIMSlotAfterUnholdReleasePolicy: () => OIMSlotAfterUnholdReleasePolicy,
53
53
  OIMSlotAfterWriteReleasePolicy: () => OIMSlotAfterWriteReleasePolicy,
@@ -58,6 +58,7 @@ __export(index_exports, {
58
58
  OIMSlotCollectionSortedArrayIndexService: () => OIMSlotCollectionSortedArrayIndexService,
59
59
  OIMSlotContentArrayBucketService: () => OIMSlotContentArrayBucketService,
60
60
  OIMSlotContentBucketService: () => OIMSlotContentBucketService,
61
+ OIMSlotContentChangeListenerService: () => OIMSlotContentChangeListenerService,
61
62
  OIMSlotContentEntityService: () => OIMSlotContentEntityService,
62
63
  OIMSlotContentPositionalArrayBucketService: () => OIMSlotContentPositionalArrayBucketService,
63
64
  OIMSlotContentSetBucketService: () => OIMSlotContentSetBucketService,
@@ -73,6 +74,7 @@ __export(index_exports, {
73
74
  OIMSlotTreeStoreService: () => OIMSlotTreeStoreService,
74
75
  OIMSlotWheel: () => OIMSlotWheel,
75
76
  OIMSortedComputedService: () => OIMSortedComputedService,
77
+ OIMSourceTrackingComputedService: () => OIMSourceTrackingComputedService,
76
78
  OIMThrowAtOnceErrorPolicy: () => OIMThrowAtOnceErrorPolicy,
77
79
  OIMUnusedSlotCollectorService: () => OIMUnusedSlotCollectorService,
78
80
  OIMWritableSingleSlotService: () => OIMWritableSingleSlotService,
@@ -86,17 +88,22 @@ __export(index_exports, {
86
88
  createOIMChannelSlot: () => createOIMChannelSlot,
87
89
  createOIMCollectorSlot: () => createOIMCollectorSlot,
88
90
  createOIMComputedService: () => createOIMComputedService,
89
- createOIMEntityWriterInPlace: () => createOIMEntityWriterInPlace,
90
- createOIMEntityWriterReplacing: () => createOIMEntityWriterReplacing,
91
+ createOIMInPlaceEntityWriter: () => createOIMInPlaceEntityWriter,
92
+ createOIMReplacingEntityWriter: () => createOIMReplacingEntityWriter,
91
93
  createOIMSingleComputedService: () => createOIMSingleComputedService,
92
94
  createOIMSingleSlotService: () => createOIMSingleSlotService,
95
+ createOIMSingleSourceTrackingComputedService: () => createOIMSingleSourceTrackingComputedService,
93
96
  createOIMSlotCollectionIndexService: () => createOIMSlotCollectionIndexService,
94
97
  createOIMSlotCollectionService: () => createOIMSlotCollectionService,
95
98
  createOIMSlotCollectionSortedArrayIndexService: () => createOIMSlotCollectionSortedArrayIndexService,
96
99
  createOIMSlotContentEntityService: () => createOIMSlotContentEntityService,
97
100
  createOIMSortedComputedService: () => createOIMSortedComputedService,
101
+ createOIMSourceTrackingComputedService: () => createOIMSourceTrackingComputedService,
98
102
  createOIMUnusedSlotCollectorSlot: () => createOIMUnusedSlotCollectorSlot,
99
103
  oimColumnsComparator: () => oimColumnsComparator,
104
+ oimGuardedPatchEntityColumn: () => oimGuardedPatchEntityColumn,
105
+ oimGuardedPatchEntityColumns: () => oimGuardedPatchEntityColumns,
106
+ oimGuardedPutEntityColumns: () => oimGuardedPutEntityColumns,
100
107
  oimHoldSlots: () => oimHoldSlots,
101
108
  oimInsertEntityWithCopy: () => oimInsertEntityWithCopy,
102
109
  oimInsertEntityWithSanitizedCopy: () => oimInsertEntityWithSanitizedCopy,
@@ -109,11 +116,8 @@ __export(index_exports, {
109
116
  oimMintAfterWriteSlotReleaseWheel: () => oimMintAfterWriteSlotReleaseWheel,
110
117
  oimOrderedListCommandsOfTransition: () => oimOrderedListCommandsOfTransition,
111
118
  oimPatchEntityColumn: () => oimPatchEntityColumn,
112
- oimPatchEntityColumnGuarded: () => oimPatchEntityColumnGuarded,
113
119
  oimPatchEntityColumns: () => oimPatchEntityColumns,
114
- oimPatchEntityColumnsGuarded: () => oimPatchEntityColumnsGuarded,
115
120
  oimPutEntityColumns: () => oimPutEntityColumns,
116
- oimPutEntityColumnsGuarded: () => oimPutEntityColumnsGuarded,
117
121
  oimRefreshSourceComputeds: () => oimRefreshSourceComputeds,
118
122
  oimSameKeySequence: () => oimSameKeySequence,
119
123
  oimSameSlotSequence: () => oimSameSlotSequence,
@@ -123,7 +127,7 @@ __export(index_exports, {
123
127
  });
124
128
  module.exports = __toCommonJS(index_exports);
125
129
 
126
- // src/engine/schedule/OIMFlushSchedulerService.ts
130
+ // src/schedule/OIMFlushSchedulerService.ts
127
131
  var _OIMFlushSchedulerService = class _OIMFlushSchedulerService {
128
132
  isScheduled(flushSchedulerSlot) {
129
133
  return flushSchedulerSlot.scheduledCallback !== void 0;
@@ -158,15 +162,15 @@ var _OIMFlushSchedulerService = class _OIMFlushSchedulerService {
158
162
  _OIMFlushSchedulerService.INSTANCE = new _OIMFlushSchedulerService();
159
163
  var OIMFlushSchedulerService = _OIMFlushSchedulerService;
160
164
 
161
- // src/engine/slot/constants/OIM_SLOT_FLAG_RELEASED.ts
165
+ // src/slot/constants/OIM_SLOT_FLAG_RELEASED.ts
162
166
  var OIM_SLOT_FLAG_RELEASED = 2;
163
167
 
164
- // src/engine/slot/utils/oimUnholdSlotIfAlive.ts
168
+ // src/slot/utils/oimUnholdSlotIfAlive.ts
165
169
  function oimUnholdSlotIfAlive(slot) {
166
170
  if ((slot.slotFlags & OIM_SLOT_FLAG_RELEASED) === 0) slot.owner.unholdSlot(slot);
167
171
  }
168
172
 
169
- // src/engine/collector/OIMUnusedSlotCollectorService.ts
173
+ // src/collector/OIMUnusedSlotCollectorService.ts
170
174
  var _OIMUnusedSlotCollectorService = class _OIMUnusedSlotCollectorService {
171
175
  holdSlotUntilFlush(unusedSlotCollectorSlot, slot) {
172
176
  slot.owner.holdSlot(slot);
@@ -212,16 +216,16 @@ var _OIMUnusedSlotCollectorService = class _OIMUnusedSlotCollectorService {
212
216
  _OIMUnusedSlotCollectorService.INSTANCE = new _OIMUnusedSlotCollectorService();
213
217
  var OIMUnusedSlotCollectorService = _OIMUnusedSlotCollectorService;
214
218
 
215
- // src/engine/channel/constants/OIM_REVISIONS_PER_EPOCH.ts
219
+ // src/channel/constants/OIM_REVISIONS_PER_EPOCH.ts
216
220
  var OIM_REVISIONS_PER_EPOCH = 2 ** 30;
217
221
 
218
- // src/engine/channel/utils/oimIsRevisionAfter.ts
222
+ // src/channel/utils/oimIsRevisionAfter.ts
219
223
  function oimIsRevisionAfter(revision, epoch, sinceRevision, sinceEpoch) {
220
- if (epoch !== sinceEpoch) return epoch > sinceEpoch;
224
+ if (epoch !== sinceEpoch) return (epoch - sinceEpoch | 0) > 0;
221
225
  return revision > sinceRevision;
222
226
  }
223
227
 
224
- // src/engine/channel/OIMChannelService.ts
228
+ // src/channel/OIMChannelService.ts
225
229
  var _OIMChannelService = class _OIMChannelService {
226
230
  scheduleEffectRun(channelSlot, effect) {
227
231
  channelSlot.effectChannelQueue.enqueueEntry(effect);
@@ -281,24 +285,24 @@ var _OIMChannelService = class _OIMChannelService {
281
285
  const clock = channelSlot.clock;
282
286
  if (clock.revision >= OIM_REVISIONS_PER_EPOCH - 1) {
283
287
  clock.revision = 0;
284
- clock.epoch++;
288
+ clock.epoch = clock.epoch + 1 | 0;
285
289
  } else {
286
290
  clock.revision++;
287
291
  }
288
- const dependents = slot.effects;
289
- const slotEditable = slot;
292
+ const effects = slot.effects;
293
+ const editableSlot = slot;
290
294
  const effectChannelQueue = channelSlot.effectChannelQueue;
291
295
  let owesAFrame = false;
292
- if (dependents !== void 0 && dependents.length !== 0 && !this.isChangedInCurrentFrame(channelSlot, slot)) {
293
- const owed = dependents.length;
296
+ if (effects !== void 0 && effects.length !== 0 && !this.isChangedInCurrentFrame(channelSlot, slot)) {
297
+ const owed = effects.length;
294
298
  for (let i = 0; i < owed; i++) {
295
- const dependent = dependents[i];
296
- if (dependent.effectService.markEffectRunScheduled(dependent, false)) effectChannelQueue.enqueueEntry(dependent);
299
+ const effect = effects[i];
300
+ if (effect.effectService.markEffectRunScheduled(effect, false)) effectChannelQueue.enqueueEntry(effect);
297
301
  }
298
302
  owesAFrame = true;
299
303
  }
300
- slotEditable.changedAtRevision = clock.revision;
301
- slotEditable.changedAtEpoch = clock.epoch;
304
+ editableSlot.changedAtRevision = clock.revision;
305
+ editableSlot.changedAtEpoch = clock.epoch;
302
306
  if (!owesAFrame && (channelSlot.flushRequested || channelSlot.frame.afterEachFrame.size === 0 && effectChannelQueue.getEntryCount() === 0)) return;
303
307
  if (channelSlot.timer === void 0) return;
304
308
  this.requestFlush(channelSlot);
@@ -423,7 +427,7 @@ var _OIMChannelService = class _OIMChannelService {
423
427
  _OIMChannelService.INSTANCE = new _OIMChannelService();
424
428
  var OIMChannelService = _OIMChannelService;
425
429
 
426
- // src/engine/channel/OIMChannelQueue.ts
430
+ // src/channel/OIMChannelQueue.ts
427
431
  var OIMChannelQueue = class {
428
432
  constructor() {
429
433
  this.entries = [];
@@ -457,7 +461,7 @@ var OIMChannelQueue = class {
457
461
  }
458
462
  };
459
463
 
460
- // src/engine/channel/utils/createOIMChannelSlot.ts
464
+ // src/channel/utils/createOIMChannelSlot.ts
461
465
  function createOIMChannelSlot(options) {
462
466
  return {
463
467
  timer: options.timer,
@@ -479,12 +483,12 @@ function createOIMChannelSlot(options) {
479
483
  };
480
484
  }
481
485
 
482
- // src/engine/collector/utils/createOIMUnusedSlotCollectorSlot.ts
486
+ // src/collector/utils/createOIMUnusedSlotCollectorSlot.ts
483
487
  function createOIMUnusedSlotCollectorSlot() {
484
488
  return { unusedSlotChannelQueue: new OIMChannelQueue(), openDepth: 0, isFlushing: false };
485
489
  }
486
490
 
487
- // src/engine/collector/utils/createOIMCollectorSlot.ts
491
+ // src/collector/utils/createOIMCollectorSlot.ts
488
492
  function createOIMCollectorSlot(options) {
489
493
  return {
490
494
  unusedSlotCollectorSlot: createOIMUnusedSlotCollectorSlot(),
@@ -495,18 +499,18 @@ function createOIMCollectorSlot(options) {
495
499
  };
496
500
  }
497
501
 
498
- // src/engine/schedule/constants/OIM_NOTHING_TO_DISPOSE.ts
502
+ // src/schedule/constants/OIM_NOTHING_TO_DISPOSE.ts
499
503
  var OIM_NOTHING_TO_DISPOSE = () => {
500
504
  return;
501
505
  };
502
506
 
503
- // src/engine/schedule/utils/oimTimerOfChannelScheduler.ts
507
+ // src/schedule/utils/oimTimerOfChannelScheduler.ts
504
508
  var oimTimerOfChannelScheduler = (scheduler) => (run) => {
505
509
  scheduler(run);
506
510
  return OIM_NOTHING_TO_DISPOSE;
507
511
  };
508
512
 
509
- // src/engine/schedule/constants/OIM_TIMER_ON_TIMEOUT.ts
513
+ // src/schedule/constants/OIM_TIMER_ON_TIMEOUT.ts
510
514
  var OIM_TIMER_ON_TIMEOUT = (run, inMs) => {
511
515
  const handle = setTimeout(run, inMs);
512
516
  handle.unref?.();
@@ -515,7 +519,7 @@ var OIM_TIMER_ON_TIMEOUT = (run, inMs) => {
515
519
  };
516
520
  };
517
521
 
518
- // src/engine/error/OIMLogAndContinueErrorPolicy.ts
522
+ // src/error/OIMLogAndContinueErrorPolicy.ts
519
523
  var _OIMLogAndContinueErrorPolicy = class _OIMLogAndContinueErrorPolicy {
520
524
  constructor(options) {
521
525
  this.onError = options?.onError;
@@ -528,7 +532,7 @@ var _OIMLogAndContinueErrorPolicy = class _OIMLogAndContinueErrorPolicy {
528
532
  _OIMLogAndContinueErrorPolicy.INSTANCE = new _OIMLogAndContinueErrorPolicy();
529
533
  var OIMLogAndContinueErrorPolicy = _OIMLogAndContinueErrorPolicy;
530
534
 
531
- // src/factories/OIMDB.ts
535
+ // src/db/OIMDB.ts
532
536
  var OIMDB = class {
533
537
  constructor(options) {
534
538
  this.clock = { revision: 0, epoch: 0 };
@@ -546,17 +550,13 @@ var OIMDB = class {
546
550
  timer: channelScheduler === void 0 ? void 0 : oimTimerOfChannelScheduler(channelScheduler),
547
551
  onBeforeFlush: options?.onBeforeFlush
548
552
  });
549
- this.entityWriter = options?.entityWriter;
550
- this.slotStamp = options?.slotStamp;
551
- this.slotReleasePolicy = options?.slotReleasePolicy;
552
- this.indexKeysService = options?.indexKeysService;
553
553
  }
554
554
  flush() {
555
555
  OIMChannelService.INSTANCE.flush(this.defaultChannelSlot);
556
556
  }
557
557
  };
558
558
 
559
- // src/factories/defaults/oimRegisterCoreInstance.ts
559
+ // src/db/utils/oimRegisterCoreInstance.ts
560
560
  var OIM_CORE_INSTANCE_KEY = Symbol.for("@oimdb/core");
561
561
  function oimRegisterCoreInstance(coreInstance) {
562
562
  const globalThisRecord = globalThis;
@@ -567,11 +567,11 @@ function oimRegisterCoreInstance(coreInstance) {
567
567
  }
568
568
  if (registeredCoreInstance === coreInstance) return;
569
569
  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."
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 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
571
  );
572
572
  }
573
573
 
574
- // src/engine/slot/OIMNoStoreSlotListener.ts
574
+ // src/slot/OIMNoStoreSlotListener.ts
575
575
  var _OIMNoStoreSlotListener = class _OIMNoStoreSlotListener {
576
576
  onStoreSlotCreated() {
577
577
  return;
@@ -580,7 +580,7 @@ var _OIMNoStoreSlotListener = class _OIMNoStoreSlotListener {
580
580
  _OIMNoStoreSlotListener.INSTANCE = new _OIMNoStoreSlotListener();
581
581
  var OIMNoStoreSlotListener = _OIMNoStoreSlotListener;
582
582
 
583
- // src/engine/slot/OIMNoSlotSubscriptionListener.ts
583
+ // src/slot/OIMNoSlotSubscriptionListener.ts
584
584
  var _OIMNoSlotSubscriptionListener = class _OIMNoSlotSubscriptionListener {
585
585
  onSlotFirstSubscribed() {
586
586
  return;
@@ -592,20 +592,20 @@ var _OIMNoSlotSubscriptionListener = class _OIMNoSlotSubscriptionListener {
592
592
  _OIMNoSlotSubscriptionListener.INSTANCE = new _OIMNoSlotSubscriptionListener();
593
593
  var OIMNoSlotSubscriptionListener = _OIMNoSlotSubscriptionListener;
594
594
 
595
- // src/engine/slot/constants/OIM_SLOT_FLAG_EMPTY.ts
595
+ // src/slot/constants/OIM_SLOT_FLAG_EMPTY.ts
596
596
  var OIM_SLOT_FLAG_EMPTY = 1;
597
597
 
598
- // src/engine/slot/utils/oimIsSlotEmpty.ts
598
+ // src/slot/utils/oimIsSlotEmpty.ts
599
599
  function oimIsSlotEmpty(slot) {
600
600
  return (slot.slotFlags & OIM_SLOT_FLAG_EMPTY) !== 0;
601
601
  }
602
602
 
603
- // src/engine/slot/utils/oimIsSlotReleased.ts
603
+ // src/slot/utils/oimIsSlotReleased.ts
604
604
  function oimIsSlotReleased(slot) {
605
605
  return (slot.slotFlags & OIM_SLOT_FLAG_RELEASED) !== 0;
606
606
  }
607
607
 
608
- // src/engine/slot/utils/oimAssertSlotNotReleased.ts
608
+ // src/slot/utils/oimAssertSlotNotReleased.ts
609
609
  var oimAssertSlotNotReleased = (slot) => {
610
610
  if ((slot.slotFlags & OIM_SLOT_FLAG_RELEASED) === 0) return;
611
611
  throw new Error(
@@ -613,7 +613,7 @@ var oimAssertSlotNotReleased = (slot) => {
613
613
  );
614
614
  };
615
615
 
616
- // src/engine/slot/OIMSlotOwner.ts
616
+ // src/slot/OIMSlotOwner.ts
617
617
  var OIMSlotOwner = class {
618
618
  holdSlot(slot) {
619
619
  this.assertNotReleased(slot);
@@ -633,10 +633,10 @@ var OIMSlotOwner = class {
633
633
  }
634
634
  subscribeToSlot(slot, effect, edge) {
635
635
  this.holdSlot(slot);
636
- const slotEditable = slot;
637
- const subscribers = slotEditable.effects ?? (slotEditable.effects = []);
636
+ const editableSlot = slot;
637
+ const subscribers = editableSlot.effects ?? (editableSlot.effects = []);
638
638
  subscribers.push(effect);
639
- (slotEditable.effectEdges ?? (slotEditable.effectEdges = [])).push(edge);
639
+ (editableSlot.effectEdges ?? (editableSlot.effectEdges = [])).push(edge);
640
640
  if (subscribers.length === 1) this.onSlotFirstSubscribed(slot);
641
641
  return subscribers.length - 1;
642
642
  }
@@ -683,30 +683,30 @@ var OIMSlotOwner = class {
683
683
  }
684
684
  };
685
685
 
686
- // src/engine/column/constants/OIM_COLUMN_GROUP_KEY_SEPARATOR.ts
686
+ // src/column/constants/OIM_COLUMN_GROUP_KEY_SEPARATOR.ts
687
687
  var OIM_COLUMN_GROUP_KEY_SEPARATOR = "\0";
688
688
 
689
- // src/engine/column/utils/oimColumnGroupKeyOfColumnNames.ts
689
+ // src/column/utils/oimColumnGroupKeyOfColumnNames.ts
690
690
  function oimColumnGroupKeyOfColumnNames(sortedColumnNames) {
691
691
  return `${OIM_COLUMN_GROUP_KEY_SEPARATOR}${sortedColumnNames.join(OIM_COLUMN_GROUP_KEY_SEPARATOR)}`;
692
692
  }
693
693
 
694
- // src/engine/column/constants/OIM_ANY_COLUMN_KEY.ts
694
+ // src/column/constants/OIM_ANY_COLUMN_KEY.ts
695
695
  var OIM_ANY_COLUMN_KEY = OIM_COLUMN_GROUP_KEY_SEPARATOR;
696
696
 
697
- // src/engine/column/utils/oimColumnNamesOfKey.ts
697
+ // src/column/utils/oimColumnNamesOfKey.ts
698
698
  function oimColumnNamesOfKey(columnKey) {
699
699
  if (!columnKey.startsWith(OIM_COLUMN_GROUP_KEY_SEPARATOR)) return [columnKey];
700
700
  const joinedColumnNames = columnKey.slice(OIM_COLUMN_GROUP_KEY_SEPARATOR.length);
701
701
  return joinedColumnNames === "" ? [] : joinedColumnNames.split(OIM_COLUMN_GROUP_KEY_SEPARATOR);
702
702
  }
703
703
 
704
- // src/engine/slot/utils/oimMarkSlotReleased.ts
704
+ // src/slot/utils/oimMarkSlotReleased.ts
705
705
  function oimMarkSlotReleased(slot) {
706
706
  slot.slotFlags |= OIM_SLOT_FLAG_RELEASED;
707
707
  }
708
708
 
709
- // src/engine/column/OIMColumnSlotOwner.ts
709
+ // src/column/OIMColumnSlotOwner.ts
710
710
  var OIMColumnSlotOwner = class extends OIMSlotOwner {
711
711
  constructor(columnSlotStoreService) {
712
712
  super();
@@ -811,8 +811,8 @@ var OIMColumnSlotOwner = class extends OIMSlotOwner {
811
811
  }
812
812
  fileColumnSlot(carrierSlot, key) {
813
813
  const columnSlotStoreService = this.columnSlotStoreService;
814
- const carrierSlotEditable = carrierSlot;
815
- const columnSlotStore = carrierSlotEditable.columnSlotStore ?? (carrierSlotEditable.columnSlotStore = columnSlotStoreService.createStore());
814
+ const editableCarrierSlot = carrierSlot;
815
+ const columnSlotStore = editableCarrierSlot.columnSlotStore ?? (editableCarrierSlot.columnSlotStore = columnSlotStoreService.createStore());
816
816
  const columnSlot = this.createColumnSlot(carrierSlot, key);
817
817
  columnSlotStoreService.set(columnSlotStore, key, columnSlot);
818
818
  return columnSlot;
@@ -870,7 +870,7 @@ function forgetColumnReadersIfUnread(storeSlot, columnName, columnReaders) {
870
870
  storeSlot.columnReadersByColumnName.delete(columnName);
871
871
  }
872
872
 
873
- // src/engine/column/OIMColumnSlotOrdinalStoreService.ts
873
+ // src/column/OIMColumnSlotOrdinalStoreService.ts
874
874
  var OIMColumnSlotOrdinalStoreService = class {
875
875
  constructor(options) {
876
876
  this.ordinalsByColumnName = /* @__PURE__ */ new Map();
@@ -936,19 +936,19 @@ var OIMColumnSlotOrdinalStoreService = class {
936
936
  }
937
937
  };
938
938
 
939
- // src/engine/column/utils/oimColumnSlotStoreServiceOfColumnOwnerOptions.ts
940
- function oimColumnSlotStoreServiceOfColumnOwnerOptions(columnSlotOwnerOptions) {
939
+ // src/column/utils/oimColumnSlotStoreServiceOfColumnSlotOwnerOptions.ts
940
+ function oimColumnSlotStoreServiceOfColumnSlotOwnerOptions(columnSlotOwnerOptions) {
941
941
  if (columnSlotOwnerOptions.columnNames !== void 0) {
942
942
  return new OIMColumnSlotOrdinalStoreService({ columnNames: columnSlotOwnerOptions.columnNames });
943
943
  }
944
944
  return columnSlotOwnerOptions.columnSlotStoreService;
945
945
  }
946
946
 
947
- // src/engine/computed/constants/OIM_FROZEN_EMPTY_COMPUTED_SLOTS.ts
947
+ // src/computed/constants/OIM_FROZEN_EMPTY_COMPUTED_SLOTS.ts
948
948
  var OIM_FROZEN_EMPTY_COMPUTED_SLOTS = Object.freeze([]);
949
949
 
950
- // src/engine/computed/utils/createOIMComputedSlot.ts
951
- function createOIMComputedSlot(key, owner, computedValueService, initialValue, storeSlot = void 0) {
950
+ // src/computed/utils/createOIMComputedSlot.ts
951
+ function createOIMComputedSlot(key, owner, computedValueService, initialValue, storeSlot, sourceTracker) {
952
952
  return {
953
953
  effects: void 0,
954
954
  changedAtRevision: 0,
@@ -973,11 +973,12 @@ function createOIMComputedSlot(key, owner, computedValueService, initialValue, s
973
973
  checkedAtRevision: -1,
974
974
  checkedAtEpoch: -1,
975
975
  isDeriving: false,
976
- allRootSlots: void 0
976
+ allRootSlots: void 0,
977
+ sourceTracker
977
978
  };
978
979
  }
979
980
 
980
- // src/engine/computed/utils/oimRefreshSourceComputeds.ts
981
+ // src/computed/utils/oimRefreshSourceComputeds.ts
981
982
  function oimRefreshSourceComputeds(sourceComputeds) {
982
983
  for (let i = 0; i < sourceComputeds.length; i++) {
983
984
  const sourceComputedSlot = sourceComputeds[i];
@@ -985,7 +986,7 @@ function oimRefreshSourceComputeds(sourceComputeds) {
985
986
  }
986
987
  }
987
988
 
988
- // src/engine/channel/utils/oimIsAnySlotChangedAfter.ts
989
+ // src/channel/utils/oimIsAnySlotChangedAfter.ts
989
990
  function oimIsAnySlotChangedAfter(slots, revision, epoch) {
990
991
  for (let i = 0; i < slots.length; i++) {
991
992
  const slot = slots[i];
@@ -994,52 +995,67 @@ function oimIsAnySlotChangedAfter(slots, revision, epoch) {
994
995
  return false;
995
996
  }
996
997
 
997
- // src/engine/computed/utils/oimHasSourceChangedSinceLastRun.ts
998
+ // src/computed/utils/oimHasSourceChangedSinceLastRun.ts
998
999
  function oimHasSourceChangedSinceLastRun(derivation) {
999
1000
  return oimIsAnySlotChangedAfter(derivation.sourceComputeds, derivation.ranAtRevision, derivation.ranAtEpoch) || oimIsAnySlotChangedAfter(derivation.sourceSlots, derivation.ranAtRevision, derivation.ranAtEpoch);
1000
1001
  }
1001
1002
 
1002
- // src/engine/computed/utils/oimRefreshComputedSlot.ts
1003
- function oimRefreshComputedSlot(computedSlot, derive, sameValueGuard, channelClock) {
1003
+ // src/computed/utils/oimRefreshComputedSlot.ts
1004
+ function oimRefreshComputedSlot(computedSlot, derive, sameValueGuard, releaseValue, channelClock) {
1004
1005
  if (computedSlot.isDeriving) return;
1005
1006
  if (computedSlot.checkedAtRevision === channelClock.revision && computedSlot.checkedAtEpoch === channelClock.epoch) return;
1006
- const computedSlotEditable = computedSlot;
1007
+ const editableComputedSlot = computedSlot;
1007
1008
  oimRefreshSourceComputeds(computedSlot.sourceComputeds);
1008
1009
  if (computedSlot.ranAtRevision !== -1 && !oimHasSourceChangedSinceLastRun(computedSlot)) {
1009
- computedSlotEditable.checkedAtRevision = channelClock.revision;
1010
- computedSlotEditable.checkedAtEpoch = channelClock.epoch;
1010
+ editableComputedSlot.checkedAtRevision = channelClock.revision;
1011
+ editableComputedSlot.checkedAtEpoch = channelClock.epoch;
1011
1012
  return;
1012
1013
  }
1013
- computedSlotEditable.isDeriving = true;
1014
+ const hasDerived = computedSlot.ranAtRevision !== -1;
1015
+ editableComputedSlot.isDeriving = true;
1014
1016
  let next;
1015
1017
  try {
1016
1018
  next = derive(computedSlot);
1017
1019
  } 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;
1020
+ editableComputedSlot.isDeriving = false;
1021
+ }
1022
+ if ((computedSlot.slotFlags & OIM_SLOT_FLAG_RELEASED) !== 0) {
1023
+ releaseValue(next);
1024
+ return;
1025
+ }
1026
+ const prevValue = computedSlot.value;
1027
+ const isSameValue = sameValueGuard(prevValue, next);
1028
+ editableComputedSlot.ranAtRevision = channelClock.revision;
1029
+ editableComputedSlot.ranAtEpoch = channelClock.epoch;
1030
+ editableComputedSlot.checkedAtRevision = channelClock.revision;
1031
+ editableComputedSlot.checkedAtEpoch = channelClock.epoch;
1032
+ if (isSameValue) {
1033
+ if (next !== prevValue) releaseValue(next);
1034
+ return;
1035
+ }
1036
+ editableComputedSlot.value = next;
1037
+ if (hasDerived) releaseValue(prevValue);
1027
1038
  const sourceSlots = computedSlot.sourceSlots;
1028
1039
  const sourceComputeds = computedSlot.sourceComputeds;
1029
1040
  const sourceCount = sourceSlots.length + sourceComputeds.length;
1030
1041
  let newestSourceRevision = -1;
1031
1042
  let newestSourceEpoch = -1;
1032
1043
  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;
1044
+ const sourceSlot = i < sourceSlots.length ? sourceSlots[i] : sourceComputeds[i - sourceSlots.length];
1045
+ if (!oimIsRevisionAfter(sourceSlot.changedAtRevision, sourceSlot.changedAtEpoch, newestSourceRevision, newestSourceEpoch)) continue;
1046
+ newestSourceRevision = sourceSlot.changedAtRevision;
1047
+ newestSourceEpoch = sourceSlot.changedAtEpoch;
1037
1048
  }
1038
- computedSlotEditable.changedAtRevision = sourceCount === 0 ? channelClock.revision : newestSourceRevision;
1039
- computedSlotEditable.changedAtEpoch = sourceCount === 0 ? channelClock.epoch : newestSourceEpoch;
1049
+ editableComputedSlot.changedAtRevision = sourceCount === 0 ? channelClock.revision : newestSourceRevision;
1050
+ editableComputedSlot.changedAtEpoch = sourceCount === 0 ? channelClock.epoch : newestSourceEpoch;
1051
+ }
1052
+
1053
+ // src/computed/utils/oimReleaseNoValue.ts
1054
+ function oimReleaseNoValue() {
1055
+ return;
1040
1056
  }
1041
1057
 
1042
- // src/engine/column/OIMPullColumnSlotOwner.ts
1058
+ // src/column/OIMPullColumnSlotOwner.ts
1043
1059
  var columnValueOf = (value, columnName) => typeof value === "object" && value !== null ? value[columnName] : void 0;
1044
1060
  var isSameColumnValues = (prevColumnValues, nextColumnValues) => {
1045
1061
  if (!Array.isArray(prevColumnValues) || !Array.isArray(nextColumnValues)) return false;
@@ -1051,7 +1067,7 @@ var isSameColumnValues = (prevColumnValues, nextColumnValues) => {
1051
1067
  };
1052
1068
  var OIMPullColumnSlotOwner = class extends OIMColumnSlotOwner {
1053
1069
  constructor(options) {
1054
- super(oimColumnSlotStoreServiceOfColumnOwnerOptions(options));
1070
+ super(oimColumnSlotStoreServiceOfColumnSlotOwnerOptions(options));
1055
1071
  this.deriveColumnSlotValue = (columnSlot) => {
1056
1072
  const columnGroup = this.getColumnGroupsByKeyOf(this.carrierSlotOf(columnSlot))?.get(columnSlot.key);
1057
1073
  return columnGroup === void 0 ? this.deriveColumnValue(columnSlot) : this.deriveColumnValues(columnSlot, columnGroup.columnNames);
@@ -1060,17 +1076,18 @@ var OIMPullColumnSlotOwner = class extends OIMColumnSlotOwner {
1060
1076
  getValueForSlot(computedSlot) {
1061
1077
  this.assertNotReleased(computedSlot);
1062
1078
  const columnSlot = computedSlot;
1063
- const carrierStoreSlot = this.carrierSlotOf(columnSlot).storeSlot;
1079
+ const carrierStoreSlot = columnSlot.storeSlot;
1064
1080
  oimRefreshComputedSlot(
1065
1081
  columnSlot,
1066
1082
  this.deriveColumnSlotValue,
1067
1083
  carrierStoreSlot.columnGroupsByKey?.has(columnSlot.key) === true ? isSameColumnValues : Object.is,
1084
+ oimReleaseNoValue,
1068
1085
  carrierStoreSlot.channelSlot.clock
1069
1086
  );
1070
1087
  return columnSlot.value;
1071
1088
  }
1072
1089
  createColumnSlot(carrierSlot, key) {
1073
- const columnSlot = createOIMComputedSlot(key, this, this, void 0);
1090
+ const columnSlot = createOIMComputedSlot(key, this, this, void 0, carrierSlot.storeSlot, void 0);
1074
1091
  columnSlot.sourceComputeds = [carrierSlot];
1075
1092
  this.getValueForSlot(columnSlot);
1076
1093
  return columnSlot;
@@ -1090,19 +1107,19 @@ var OIMPullColumnSlotOwner = class extends OIMColumnSlotOwner {
1090
1107
  }
1091
1108
  };
1092
1109
 
1093
- // src/engine/slot/utils/oimSameValueZeroGuard.ts
1110
+ // src/slot/utils/oimSameValueZeroGuard.ts
1094
1111
  function oimSameValueZeroGuard(prevValue, nextValue) {
1095
1112
  return prevValue === nextValue || prevValue !== prevValue && nextValue !== nextValue;
1096
1113
  }
1097
1114
 
1098
- // src/engine/bucket/utils/oimSameSlotSequence.ts
1115
+ // src/bucket/utils/oimSameSlotSequence.ts
1099
1116
  function oimSameSlotSequence(prev, next) {
1100
1117
  if (prev.length !== next.length) return false;
1101
1118
  for (let i = 0; i < prev.length; i++) if (prev[i] !== next[i]) return false;
1102
1119
  return true;
1103
1120
  }
1104
1121
 
1105
- // src/engine/key/utils/oimSameKeySequence.ts
1122
+ // src/key/utils/oimSameKeySequence.ts
1106
1123
  function oimSameKeySequence(keys, otherKeys) {
1107
1124
  if (keys === otherKeys) return true;
1108
1125
  if (keys.length !== otherKeys.length) return false;
@@ -1112,25 +1129,25 @@ function oimSameKeySequence(keys, otherKeys) {
1112
1129
  return true;
1113
1130
  }
1114
1131
 
1115
- // src/engine/slot/utils/oimHoldSlots.ts
1132
+ // src/slot/utils/oimHoldSlots.ts
1116
1133
  function oimHoldSlots(slots) {
1117
1134
  for (let i = 0; i < slots.length; i++) slots[i].owner.holdSlot(slots[i]);
1118
1135
  }
1119
1136
 
1120
- // src/engine/slot/utils/oimUnholdSlotsIfAlive.ts
1137
+ // src/slot/utils/oimUnholdSlotsIfAlive.ts
1121
1138
  function oimUnholdSlotsIfAlive(slots) {
1122
1139
  for (let i = 0; i < slots.length; i++) oimUnholdSlotIfAlive(slots[i]);
1123
1140
  }
1124
1141
 
1125
- // src/engine/error/OIMThrowAtOnceErrorPolicy.ts
1142
+ // src/error/OIMThrowAtOnceErrorPolicy.ts
1126
1143
  var OIMThrowAtOnceErrorPolicy = class {
1127
1144
  onErrorCaught(error) {
1128
1145
  throw error;
1129
1146
  }
1130
1147
  };
1131
1148
 
1132
- // src/engine/computed/OIMEffectSourceList.ts
1133
- var OIMEffectSourceList = class {
1149
+ // src/computed/OIMSourceList.ts
1150
+ var OIMSourceList = class {
1134
1151
  constructor() {
1135
1152
  this.committedSources = [];
1136
1153
  this.trackedSources = [];
@@ -1179,6 +1196,9 @@ var OIMEffectSourceList = class {
1179
1196
  this.isTrackedSourcesChanged = true;
1180
1197
  return true;
1181
1198
  }
1199
+ getCommittedSources() {
1200
+ return this.committedSources;
1201
+ }
1182
1202
  getTrackedSources() {
1183
1203
  return this.isTrackedSourcesChanged ? this.trackedSources : this.committedSources;
1184
1204
  }
@@ -1197,7 +1217,7 @@ var OIMEffectSourceList = class {
1197
1217
  }
1198
1218
  };
1199
1219
 
1200
- // src/engine/computed/utils/oimMergeRootSlots.ts
1220
+ // src/computed/utils/oimMergeRootSlots.ts
1201
1221
  var scannedRootSlotLimit = 16;
1202
1222
  function oimMergeRootSlots(sourceSlots, sourceComputeds) {
1203
1223
  if (sourceComputeds.length === 0) return sourceSlots;
@@ -1227,7 +1247,7 @@ function pushIfAbsent(mergedRootSlots, distinctRootSlots, rootSlot) {
1227
1247
  return mergedRootSlots.length > scannedRootSlotLimit ? new Set(mergedRootSlots) : void 0;
1228
1248
  }
1229
1249
 
1230
- // src/engine/computed/utils/oimGetAllRootSlots.ts
1250
+ // src/computed/utils/oimGetAllRootSlots.ts
1231
1251
  function oimGetAllRootSlots(computedSlot) {
1232
1252
  const allRootSlots = computedSlot.allRootSlots;
1233
1253
  if (allRootSlots !== void 0) return allRootSlots;
@@ -1236,62 +1256,85 @@ function oimGetAllRootSlots(computedSlot) {
1236
1256
  return mergedRootSlots;
1237
1257
  }
1238
1258
 
1239
- // src/engine/computed/OIMEffectSourceTracker.ts
1240
- var OIMEffectSourceTracker = class {
1259
+ // src/computed/OIMSourceTracker.ts
1260
+ var OIMSourceTracker = class {
1241
1261
  constructor() {
1242
- this.slotEffectSourceList = new OIMEffectSourceList();
1243
- this.computedEffectSourceList = void 0;
1262
+ this.slotSourceList = new OIMSourceList();
1263
+ this.computedSourceList = void 0;
1244
1264
  this.committedAllRootSlots = [];
1245
1265
  this.trackedAllRootSlots = [];
1246
1266
  this.isTrackedAllRootSlotsChanged = false;
1267
+ this.committedComputedRootSlots = [];
1268
+ this.trackedComputedRootSlots = [];
1247
1269
  }
1248
1270
  readSourceSlot(slot) {
1249
- this.slotEffectSourceList.trackSource(slot);
1271
+ this.slotSourceList.trackSource(slot);
1250
1272
  return slot;
1251
1273
  }
1252
1274
  readSourceComputedValue(computedSlot) {
1253
1275
  const value = computedSlot.computedValueService.getValueForSlot(computedSlot);
1254
- (this.computedEffectSourceList ?? (this.computedEffectSourceList = new OIMEffectSourceList())).trackSource(computedSlot);
1276
+ (this.computedSourceList ?? (this.computedSourceList = new OIMSourceList())).trackSource(computedSlot);
1255
1277
  return value;
1256
1278
  }
1257
1279
  openSourceTracking() {
1258
- this.slotEffectSourceList.openSourceTracking();
1259
- this.computedEffectSourceList?.openSourceTracking();
1280
+ this.slotSourceList.openSourceTracking();
1281
+ this.computedSourceList?.openSourceTracking();
1260
1282
  this.isTrackedAllRootSlotsChanged = false;
1261
1283
  }
1262
1284
  closeSourceTracking() {
1263
- const isSourceSlotsChanged = this.slotEffectSourceList.closeSourceTracking();
1264
- const isSourceComputedsChanged = this.computedEffectSourceList?.closeSourceTracking() ?? false;
1265
- if (!isSourceSlotsChanged && !isSourceComputedsChanged) return false;
1285
+ const isSourceSlotsChanged = this.slotSourceList.closeSourceTracking();
1286
+ const isSourceComputedsChanged = this.computedSourceList?.closeSourceTracking() ?? false;
1287
+ if (!isSourceSlotsChanged && !isSourceComputedsChanged && !this.isAnyComputedRootSlotsReplaced()) return false;
1288
+ this.trackAllRootSlots();
1289
+ return true;
1290
+ }
1291
+ isAnyComputedRootSlotsReplaced() {
1292
+ const computedSourceList = this.computedSourceList;
1293
+ if (computedSourceList === void 0) return false;
1294
+ const committedSourceComputeds = computedSourceList.getCommittedSources();
1295
+ const committedComputedRootSlots = this.committedComputedRootSlots;
1296
+ for (let i = 0; i < committedSourceComputeds.length; i++) {
1297
+ if (oimGetAllRootSlots(committedSourceComputeds[i]) !== committedComputedRootSlots[i]) return true;
1298
+ }
1299
+ return false;
1300
+ }
1301
+ trackReplacedRootSlots() {
1302
+ if (!this.isAnyComputedRootSlotsReplaced()) return false;
1266
1303
  this.trackAllRootSlots();
1267
1304
  return true;
1268
1305
  }
1269
1306
  getTrackedSourceSlots() {
1270
- return this.slotEffectSourceList.getTrackedSources();
1307
+ return this.slotSourceList.getTrackedSources();
1271
1308
  }
1272
1309
  getTrackedSourceComputeds() {
1273
- return this.computedEffectSourceList?.getTrackedSources() ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
1310
+ return this.computedSourceList?.getTrackedSources() ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
1274
1311
  }
1275
1312
  getTrackedAllRootSlots() {
1276
1313
  return this.isTrackedAllRootSlotsChanged ? this.trackedAllRootSlots : this.committedAllRootSlots;
1277
1314
  }
1278
1315
  commitTrackedSources() {
1279
- this.slotEffectSourceList.commitTrackedSources();
1280
- this.computedEffectSourceList?.commitTrackedSources();
1316
+ this.slotSourceList.commitTrackedSources();
1317
+ this.computedSourceList?.commitTrackedSources();
1281
1318
  if (!this.isTrackedAllRootSlotsChanged) return;
1282
1319
  const committedAllRootSlots = this.committedAllRootSlots;
1283
1320
  this.committedAllRootSlots = this.trackedAllRootSlots;
1284
1321
  this.trackedAllRootSlots = committedAllRootSlots;
1322
+ const committedComputedRootSlots = this.committedComputedRootSlots;
1323
+ this.committedComputedRootSlots = this.trackedComputedRootSlots;
1324
+ this.trackedComputedRootSlots = committedComputedRootSlots;
1285
1325
  this.isTrackedAllRootSlotsChanged = false;
1286
1326
  }
1287
1327
  trackAllRootSlots() {
1288
- const sourceSlots = this.slotEffectSourceList.getTrackedSources();
1328
+ const sourceSlots = this.slotSourceList.getTrackedSources();
1289
1329
  const sourceComputeds = this.getTrackedSourceComputeds();
1290
1330
  const trackedAllRootSlots = this.trackedAllRootSlots;
1331
+ const trackedComputedRootSlots = this.trackedComputedRootSlots;
1332
+ if (trackedComputedRootSlots.length !== sourceComputeds.length) trackedComputedRootSlots.length = sourceComputeds.length;
1291
1333
  let rootSlotCount = 0;
1292
1334
  for (let i = 0; i < sourceSlots.length; i++) trackedAllRootSlots[rootSlotCount++] = sourceSlots[i];
1293
1335
  for (let i = 0; i < sourceComputeds.length; i++) {
1294
1336
  const computedRootSlots = oimGetAllRootSlots(sourceComputeds[i]);
1337
+ trackedComputedRootSlots[i] = computedRootSlots;
1295
1338
  for (let j = 0; j < computedRootSlots.length; j++) trackedAllRootSlots[rootSlotCount++] = computedRootSlots[j];
1296
1339
  }
1297
1340
  if (trackedAllRootSlots.length !== rootSlotCount) trackedAllRootSlots.length = rootSlotCount;
@@ -1299,23 +1342,26 @@ var OIMEffectSourceTracker = class {
1299
1342
  }
1300
1343
  };
1301
1344
 
1302
- // src/engine/computed/constants/OIM_EFFECT_FLAG_DISPOSED.ts
1345
+ // src/effect/constants/OIM_EFFECT_FLAG_DISPOSED.ts
1303
1346
  var OIM_EFFECT_FLAG_DISPOSED = 2;
1304
1347
 
1305
- // src/engine/computed/utils/oimIsEffectDisposed.ts
1348
+ // src/effect/utils/oimIsEffectDisposed.ts
1306
1349
  function oimIsEffectDisposed(effect) {
1307
1350
  return (effect.effectFlags & OIM_EFFECT_FLAG_DISPOSED) !== 0;
1308
1351
  }
1309
1352
 
1310
- // src/engine/computed/constants/OIM_EFFECT_FLAG_RUN_SCHEDULED.ts
1353
+ // src/effect/constants/OIM_EFFECT_FLAG_RUN_SCHEDULED.ts
1311
1354
  var OIM_EFFECT_FLAG_RUN_SCHEDULED = 1;
1312
1355
 
1313
- // src/engine/computed/constants/OIM_EFFECT_FLAG_SOURCE_CHECK_OWED.ts
1356
+ // src/effect/constants/OIM_EFFECT_FLAG_SOURCE_CHECK_OWED.ts
1314
1357
  var OIM_EFFECT_FLAG_SOURCE_CHECK_OWED = 4;
1315
1358
 
1316
- // src/engine/computed/OIMEffectService.ts
1359
+ // src/effect/OIMEffectService.ts
1317
1360
  var _OIMEffectService = class _OIMEffectService {
1318
- createEffect(channelMap, sourceSlots, sourceComputeds, body) {
1361
+ createEffect(channelMap, body, sourceSlots = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceTrackingComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS) {
1362
+ if (sourceTrackingComputeds.length !== 0) {
1363
+ return this.createEffectOverSourceTrackingComputeds(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds);
1364
+ }
1319
1365
  let distinctSourceComputeds = sourceComputeds;
1320
1366
  if (sourceComputeds.length > 1) {
1321
1367
  const distinctSourceComputedSet = new Set(sourceComputeds);
@@ -1336,7 +1382,8 @@ var _OIMEffectService = class _OIMEffectService {
1336
1382
  ranAtEpoch: clock.epoch,
1337
1383
  effectFlags: 0,
1338
1384
  body,
1339
- cleanup: void 0
1385
+ cleanup: void 0,
1386
+ sourceTracker: void 0
1340
1387
  };
1341
1388
  try {
1342
1389
  for (let i = 0; i < allRootSlots.length; i++) {
@@ -1352,20 +1399,17 @@ var _OIMEffectService = class _OIMEffectService {
1352
1399
  this.disposeEffect(effect);
1353
1400
  throw failure;
1354
1401
  }
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
- }
1402
+ this.scheduleEffectRunIfWrittenSinceFrameOpened(effect);
1359
1403
  return effect;
1360
1404
  }
1361
- subscribeEffect(channelMap, sourceSlots, sourceComputeds, body) {
1362
- const effect = this.createEffect(channelMap, sourceSlots, sourceComputeds, body);
1405
+ subscribeEffect(channelMap, body, sourceSlots = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceTrackingComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS) {
1406
+ const effect = this.createEffect(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds);
1363
1407
  return () => {
1364
1408
  this.disposeEffect(effect);
1365
1409
  };
1366
1410
  }
1367
- createEffectImmediate(channelMap, sourceSlots, sourceComputeds, body) {
1368
- const effect = this.createEffect(channelMap, sourceSlots, sourceComputeds, body);
1411
+ createAndRunEffect(channelMap, body, sourceSlots = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS, sourceTrackingComputeds = OIM_FROZEN_EMPTY_COMPUTED_SLOTS) {
1412
+ const effect = this.createEffect(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds);
1369
1413
  try {
1370
1414
  this.runEffect(effect);
1371
1415
  } catch (refusal) {
@@ -1374,31 +1418,63 @@ var _OIMEffectService = class _OIMEffectService {
1374
1418
  }
1375
1419
  return effect;
1376
1420
  }
1377
- createEffectWithSourceTracking(channelMap, effectBodyWithSourceTracking) {
1378
- const effectSourceTracker = new OIMEffectSourceTracker();
1421
+ createSourceTrackingEffect(channelMap, sourceTrackingEffectBody) {
1422
+ const sourceTracker = new OIMSourceTracker();
1423
+ const effect = this.createEffectOverSourceTracker(
1424
+ channelMap,
1425
+ sourceTracker,
1426
+ () => this.runSourceTrackingEffectBody(effect, sourceTracker, sourceTrackingEffectBody)
1427
+ );
1428
+ try {
1429
+ this.runEffect(effect);
1430
+ } catch (failure) {
1431
+ this.disposeEffect(effect);
1432
+ throw failure;
1433
+ }
1434
+ return effect;
1435
+ }
1436
+ createEffectOverSourceTrackingComputeds(channelMap, body, sourceSlots, sourceComputeds, sourceTrackingComputeds) {
1437
+ const sourceTracker = new OIMSourceTracker();
1438
+ const effect = this.createEffectOverSourceTracker(channelMap, sourceTracker, body);
1439
+ try {
1440
+ sourceTracker.openSourceTracking();
1441
+ for (let i = 0; i < sourceSlots.length; i++) sourceTracker.readSourceSlot(sourceSlots[i]);
1442
+ for (let i = 0; i < sourceComputeds.length; i++) sourceTracker.readSourceComputedValue(sourceComputeds[i]);
1443
+ for (let i = 0; i < sourceTrackingComputeds.length; i++) sourceTracker.readSourceComputedValue(sourceTrackingComputeds[i]);
1444
+ if (sourceTracker.closeSourceTracking()) this.resubscribeToTrackedSources(effect, sourceTracker);
1445
+ } catch (failure) {
1446
+ this.disposeEffect(effect);
1447
+ throw failure;
1448
+ }
1449
+ this.scheduleEffectRunIfWrittenSinceFrameOpened(effect);
1450
+ return effect;
1451
+ }
1452
+ createEffectOverSourceTracker(channelMap, sourceTracker, body) {
1379
1453
  const channelSlot = channelMap.defaultChannelSlot;
1380
1454
  const clock = channelSlot.clock;
1381
- const effect = {
1455
+ return {
1382
1456
  effectService: this,
1383
1457
  channelSlot,
1384
- sourceSlots: effectSourceTracker.getTrackedSourceSlots(),
1385
- sourceComputeds: effectSourceTracker.getTrackedSourceComputeds(),
1386
- allRootSlots: effectSourceTracker.getTrackedAllRootSlots(),
1458
+ sourceSlots: sourceTracker.getTrackedSourceSlots(),
1459
+ sourceComputeds: sourceTracker.getTrackedSourceComputeds(),
1460
+ allRootSlots: sourceTracker.getTrackedAllRootSlots(),
1387
1461
  positionInFirstSubscribedSlot: -1,
1388
1462
  positionsInOtherSubscribedSlots: void 0,
1389
1463
  ranAtRevision: clock.revision,
1390
1464
  ranAtEpoch: clock.epoch,
1391
1465
  effectFlags: 0,
1392
- body: () => this.runEffectBodyWithSourceTracking(effect, effectSourceTracker, effectBodyWithSourceTracking),
1393
- cleanup: void 0
1466
+ body,
1467
+ cleanup: void 0,
1468
+ sourceTracker
1394
1469
  };
1395
- try {
1396
- this.runEffect(effect);
1397
- } catch (failure) {
1398
- this.disposeEffect(effect);
1399
- throw failure;
1470
+ }
1471
+ scheduleEffectRunIfWrittenSinceFrameOpened(effect) {
1472
+ const channelSlot = effect.channelSlot;
1473
+ const clock = channelSlot.clock;
1474
+ const frame = channelSlot.frame;
1475
+ if (!frame.isRunning && oimIsRevisionAfter(clock.revision, clock.epoch, frame.openedAtRevision, frame.openedAtEpoch) && this.markEffectRunScheduled(effect, true)) {
1476
+ OIMChannelService.INSTANCE.scheduleEffectRun(channelSlot, effect);
1400
1477
  }
1401
- return effect;
1402
1478
  }
1403
1479
  markEffectRunScheduled(effect, isSourceCheckOwed) {
1404
1480
  const effectFlags = effect.effectFlags;
@@ -1422,8 +1498,11 @@ var _OIMEffectService = class _OIMEffectService {
1422
1498
  }
1423
1499
  runEffectIfSourcesChanged(effect) {
1424
1500
  oimRefreshSourceComputeds(effect.sourceComputeds);
1425
- if (!oimHasSourceChangedSinceLastRun(effect)) return;
1426
- this.runEffect(effect);
1501
+ if (oimHasSourceChangedSinceLastRun(effect)) this.runEffect(effect);
1502
+ const sourceTracker = effect.sourceTracker;
1503
+ if (sourceTracker !== void 0 && !oimIsEffectDisposed(effect) && sourceTracker.trackReplacedRootSlots()) {
1504
+ this.resubscribeToTrackedSources(effect, sourceTracker);
1505
+ }
1427
1506
  }
1428
1507
  runEffect(effect) {
1429
1508
  const channelClock = effect.channelSlot.clock;
@@ -1465,11 +1544,11 @@ var _OIMEffectService = class _OIMEffectService {
1465
1544
  }
1466
1545
  (effect.positionsInOtherSubscribedSlots ?? (effect.positionsInOtherSubscribedSlots = []))[edge - 1] = positionInSlot;
1467
1546
  }
1468
- runEffectBodyWithSourceTracking(effect, effectSourceTracker, effectBodyWithSourceTracking) {
1469
- effectSourceTracker.openSourceTracking();
1470
- const undo = effectBodyWithSourceTracking(effectSourceTracker);
1547
+ runSourceTrackingEffectBody(effect, sourceTracker, sourceTrackingEffectBody) {
1548
+ sourceTracker.openSourceTracking();
1549
+ const undo = sourceTrackingEffectBody(sourceTracker);
1471
1550
  try {
1472
- if (effectSourceTracker.closeSourceTracking()) this.resubscribeToTrackedSources(effect, effectSourceTracker);
1551
+ if (sourceTracker.closeSourceTracking()) this.resubscribeToTrackedSources(effect, sourceTracker);
1473
1552
  } catch (failure) {
1474
1553
  this.disposeEffect(effect);
1475
1554
  if (typeof undo === "function") undo();
@@ -1477,11 +1556,11 @@ var _OIMEffectService = class _OIMEffectService {
1477
1556
  }
1478
1557
  return undo;
1479
1558
  }
1480
- resubscribeToTrackedSources(effect, effectSourceTracker) {
1559
+ resubscribeToTrackedSources(effect, sourceTracker) {
1481
1560
  const committedAllRootSlots = effect.allRootSlots;
1482
1561
  const committedSourceComputeds = effect.sourceComputeds;
1483
- const trackedAllRootSlots = effectSourceTracker.getTrackedAllRootSlots();
1484
- const trackedSourceComputeds = effectSourceTracker.getTrackedSourceComputeds();
1562
+ const trackedAllRootSlots = sourceTracker.getTrackedAllRootSlots();
1563
+ const trackedSourceComputeds = sourceTracker.getTrackedSourceComputeds();
1485
1564
  const committedEdgeCount = committedAllRootSlots.length + committedSourceComputeds.length;
1486
1565
  const trackedEdgeCount = trackedAllRootSlots.length + trackedSourceComputeds.length;
1487
1566
  const sharedEdgeCount = committedEdgeCount < trackedEdgeCount ? committedEdgeCount : trackedEdgeCount;
@@ -1506,11 +1585,11 @@ var _OIMEffectService = class _OIMEffectService {
1506
1585
  if (positionsInOtherSubscribedSlots !== void 0 && positionsInOtherSubscribedSlots.length > otherEdgeCount) {
1507
1586
  positionsInOtherSubscribedSlots.length = otherEdgeCount;
1508
1587
  }
1509
- const effectEditable = effect;
1510
- effectEditable.sourceSlots = effectSourceTracker.getTrackedSourceSlots();
1511
- effectEditable.sourceComputeds = trackedSourceComputeds;
1512
- effectEditable.allRootSlots = trackedAllRootSlots;
1513
- effectSourceTracker.commitTrackedSources();
1588
+ const editableEffect = effect;
1589
+ editableEffect.sourceSlots = sourceTracker.getTrackedSourceSlots();
1590
+ editableEffect.sourceComputeds = trackedSourceComputeds;
1591
+ editableEffect.allRootSlots = trackedAllRootSlots;
1592
+ sourceTracker.commitTrackedSources();
1514
1593
  const channelSlot = effect.channelSlot;
1515
1594
  const isFrameRunning = channelSlot.frame.isRunning;
1516
1595
  for (let edge = firstChangedEdge; edge < trackedEdgeCount; edge++) {
@@ -1545,11 +1624,12 @@ var _OIMEffectService = class _OIMEffectService {
1545
1624
  _OIMEffectService.INSTANCE = new _OIMEffectService();
1546
1625
  var OIMEffectService = _OIMEffectService;
1547
1626
 
1548
- // src/engine/computed/OIMComputedValueService.ts
1627
+ // src/computed/OIMComputedValueService.ts
1549
1628
  var OIMComputedValueService = class {
1550
1629
  constructor(options) {
1551
1630
  this.derive = options.derive;
1552
1631
  this.sameValueGuard = options.sameValueGuard ?? Object.is;
1632
+ this.releaseValue = options.releaseValue ?? oimReleaseNoValue;
1553
1633
  }
1554
1634
  getValueForSlot(computedSlot) {
1555
1635
  oimAssertSlotNotReleased(computedSlot);
@@ -1559,22 +1639,26 @@ var OIMComputedValueService = class {
1559
1639
  computedSlot,
1560
1640
  derive,
1561
1641
  this.sameValueGuard,
1642
+ this.releaseValue,
1562
1643
  computedStoreSlot.channelSlot.clock
1563
1644
  );
1564
1645
  return computedSlot.value;
1565
1646
  }
1647
+ releaseSlotValue(computedSlot) {
1648
+ if (computedSlot.ranAtRevision !== -1) this.releaseValue(computedSlot.value);
1649
+ }
1566
1650
  };
1567
1651
 
1568
- // src/engine/slot/OIMContentChangeListenerService.ts
1569
- var _OIMContentChangeListenerService = class _OIMContentChangeListenerService {
1652
+ // src/slot/OIMSlotContentChangeListenerService.ts
1653
+ var _OIMSlotContentChangeListenerService = class _OIMSlotContentChangeListenerService {
1570
1654
  addContentChangeListener(storeSlot, listener, readColumnNames) {
1571
- const storeSlotEditable = storeSlot;
1572
- if (storeSlotEditable.contentChangeListeners === void 0) {
1573
- storeSlotEditable.contentChangeListeners = [];
1574
- storeSlotEditable.contentChangeListenerReadColumnNames = [];
1655
+ const editableStoreSlot = storeSlot;
1656
+ if (editableStoreSlot.contentChangeListeners === void 0) {
1657
+ editableStoreSlot.contentChangeListeners = [];
1658
+ editableStoreSlot.contentChangeListenerReadColumnNames = [];
1575
1659
  }
1576
- storeSlotEditable.contentChangeListeners.push(listener);
1577
- storeSlotEditable.contentChangeListenerReadColumnNames.push(readColumnNames);
1660
+ editableStoreSlot.contentChangeListeners.push(listener);
1661
+ editableStoreSlot.contentChangeListenerReadColumnNames.push(readColumnNames);
1578
1662
  if (readColumnNames === void 0) this.addReadAnyColumn(storeSlot);
1579
1663
  else for (let i = 0; i < readColumnNames.length; i++) this.addReadColumn(storeSlot, readColumnNames[i]);
1580
1664
  }
@@ -1610,15 +1694,15 @@ var _OIMContentChangeListenerService = class _OIMContentChangeListenerService {
1610
1694
  if (storeSlot.allColumnsListenerCount !== 0) storeSlot.allColumnsListenerCount--;
1611
1695
  }
1612
1696
  };
1613
- _OIMContentChangeListenerService.INSTANCE = new _OIMContentChangeListenerService();
1614
- var OIMContentChangeListenerService = _OIMContentChangeListenerService;
1697
+ _OIMSlotContentChangeListenerService.INSTANCE = new _OIMSlotContentChangeListenerService();
1698
+ var OIMSlotContentChangeListenerService = _OIMSlotContentChangeListenerService;
1615
1699
 
1616
- // src/engine/slot/utils/oimGetChannelSlot.ts
1700
+ // src/slot/utils/oimGetChannelSlot.ts
1617
1701
  function oimGetChannelSlot(slot) {
1618
1702
  return slot.storeSlot.channelSlot;
1619
1703
  }
1620
1704
 
1621
- // src/facade/column/OIMColumnSlotService.ts
1705
+ // src/column/OIMColumnSlotService.ts
1622
1706
  var OIMColumnSlotService = class {
1623
1707
  constructor(columnSlotOwner) {
1624
1708
  this.columnSlotOwner = columnSlotOwner;
@@ -1646,8 +1730,11 @@ var OIMColumnSlotService = class {
1646
1730
  }
1647
1731
  };
1648
1732
 
1649
- // src/engine/slot/OIMContentChangeDeliveryService.ts
1650
- var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1733
+ // src/slot/constants/OIM_SLOT_FLAG_QUEUED_IN_BATCH.ts
1734
+ var OIM_SLOT_FLAG_QUEUED_IN_BATCH = 32;
1735
+
1736
+ // src/slot/OIMSlotContentChangeDeliveryService.ts
1737
+ var _OIMSlotContentChangeDeliveryService = class _OIMSlotContentChangeDeliveryService {
1651
1738
  isBatchOpen(storeSlot) {
1652
1739
  return storeSlot.batchDepth > 0;
1653
1740
  }
@@ -1655,23 +1742,23 @@ var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1655
1742
  storeSlot.batchDepth++;
1656
1743
  }
1657
1744
  closeBatch(storeSlot) {
1658
- const storeSlotEditable = storeSlot;
1659
- if (--storeSlotEditable.batchDepth > 0) return;
1745
+ const editableStoreSlot = storeSlot;
1746
+ if (editableStoreSlot.batchDepth === 0) {
1747
+ throw new Error(
1748
+ "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."
1749
+ );
1750
+ }
1751
+ if (--editableStoreSlot.batchDepth > 0) return;
1660
1752
  const batchSlotChannelQueue = storeSlot.batchSlotChannelQueue;
1661
1753
  if (batchSlotChannelQueue === void 0 || batchSlotChannelQueue.getEntryCount() === 0) return;
1662
1754
  this.deliverBatch(storeSlot, batchSlotChannelQueue);
1663
1755
  }
1664
1756
  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;
1757
+ const editableStoreSlot = storeSlot;
1758
+ (editableStoreSlot.batchSlotChannelQueue ?? (editableStoreSlot.batchSlotChannelQueue = new OIMChannelQueue())).enqueueEntry(slot);
1759
+ slot.slotFlags |= OIM_SLOT_FLAG_QUEUED_IN_BATCH;
1760
+ (editableStoreSlot.batchPatchChannelQueue ?? (editableStoreSlot.batchPatchChannelQueue = new OIMChannelQueue())).enqueueEntry(patch);
1761
+ (editableStoreSlot.batchChangedColumnsChannelQueue ?? (editableStoreSlot.batchChangedColumnsChannelQueue = new OIMChannelQueue())).enqueueEntry(changedColumns === void 0 ? void 0 : changedColumns.slice());
1675
1762
  }
1676
1763
  deliverBatch(storeSlot, batchSlotChannelQueue) {
1677
1764
  const batchPatchChannelQueue = storeSlot.batchPatchChannelQueue;
@@ -1686,10 +1773,13 @@ var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1686
1773
  for (let i = 0; i < listeners.length; i++) listeners[i].onContentChanged(slot, patch, changedColumns);
1687
1774
  } else {
1688
1775
  for (let i = 0; i < listeners.length; i++) {
1689
- listeners[i].onContentChangedMany(batchSlotChannelQueue, batchPatchChannelQueue, batchChangedColumnsChannelQueue);
1776
+ listeners[i].onManyContentsChanged(batchSlotChannelQueue, batchPatchChannelQueue, batchChangedColumnsChannelQueue);
1690
1777
  }
1691
1778
  }
1692
1779
  } finally {
1780
+ for (let i = 0; i < batchSlotChannelQueue.getEntryCount(); i++) {
1781
+ batchSlotChannelQueue.getEntryAt(i).slotFlags &= ~OIM_SLOT_FLAG_QUEUED_IN_BATCH;
1782
+ }
1693
1783
  try {
1694
1784
  for (let i = 0; i < batchSlotChannelQueue.getEntryCount(); i++) {
1695
1785
  const slot = batchSlotChannelQueue.getEntryAt(i);
@@ -1703,10 +1793,10 @@ var _OIMContentChangeDeliveryService = class _OIMContentChangeDeliveryService {
1703
1793
  }
1704
1794
  }
1705
1795
  };
1706
- _OIMContentChangeDeliveryService.INSTANCE = new _OIMContentChangeDeliveryService();
1707
- var OIMContentChangeDeliveryService = _OIMContentChangeDeliveryService;
1796
+ _OIMSlotContentChangeDeliveryService.INSTANCE = new _OIMSlotContentChangeDeliveryService();
1797
+ var OIMSlotContentChangeDeliveryService = _OIMSlotContentChangeDeliveryService;
1708
1798
 
1709
- // src/engine/collector/OIMSlotAtEmptyReleasePolicy.ts
1799
+ // src/collector/OIMSlotAtEmptyReleasePolicy.ts
1710
1800
  var _OIMSlotAtEmptyReleasePolicy = class _OIMSlotAtEmptyReleasePolicy {
1711
1801
  constructor() {
1712
1802
  this.releasesWrittenSlots = false;
@@ -1734,7 +1824,7 @@ var _OIMSlotAtEmptyReleasePolicy = class _OIMSlotAtEmptyReleasePolicy {
1734
1824
  _OIMSlotAtEmptyReleasePolicy.INSTANCE = new _OIMSlotAtEmptyReleasePolicy();
1735
1825
  var OIMSlotAtEmptyReleasePolicy = _OIMSlotAtEmptyReleasePolicy;
1736
1826
 
1737
- // src/engine/slot/OIMSlotOwnerService.ts
1827
+ // src/slot/OIMSlotOwnerService.ts
1738
1828
  var OIMSlotOwnerService = class extends OIMSlotOwner {
1739
1829
  constructor(options) {
1740
1830
  super();
@@ -1756,26 +1846,22 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1756
1846
  return slot.columnSlotStore !== void 0;
1757
1847
  }
1758
1848
  hasContentChangeListeners(slot) {
1759
- const storeSlot = slot.storeSlot;
1760
- if (storeSlot === void 0) return false;
1761
- const listeners = storeSlot.contentChangeListeners;
1849
+ const listeners = slot.storeSlot.contentChangeListeners;
1762
1850
  return listeners !== void 0 && listeners.length !== 0;
1763
1851
  }
1764
1852
  dispatchContentChange(slot, patch, changedColumns) {
1765
1853
  const storeSlot = slot.storeSlot;
1766
- if (storeSlot === void 0) return;
1767
1854
  const listeners = storeSlot.contentChangeListeners;
1768
1855
  if (listeners === void 0 || listeners.length === 0) return;
1769
1856
  if (changedColumns !== void 0 && !this.isAnyColumnRead(storeSlot, changedColumns)) return;
1770
1857
  if (storeSlot.batchDepth > 0) {
1771
- OIMContentChangeDeliveryService.INSTANCE.enqueueContentChange(storeSlot, slot, patch, changedColumns);
1858
+ OIMSlotContentChangeDeliveryService.INSTANCE.enqueueContentChange(storeSlot, slot, patch, changedColumns);
1772
1859
  return;
1773
1860
  }
1774
1861
  for (let i = 0; i < listeners.length; i++) listeners[i].onContentChanged(slot, patch, changedColumns);
1775
1862
  }
1776
1863
  isAnyColumnReferenced(slot, changedColumns) {
1777
1864
  const storeSlot = slot.storeSlot;
1778
- if (storeSlot === void 0) return false;
1779
1865
  return slot.columnSlotStore !== void 0 && this.columnSlotOwner.isAnyColumnReferenced(storeSlot, changedColumns) || this.isAnyColumnRead(storeSlot, changedColumns);
1780
1866
  }
1781
1867
  isAnyColumnRead(storeSlot, changedColumns) {
@@ -1794,8 +1880,7 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1794
1880
  return changedColumnNames;
1795
1881
  }
1796
1882
  releaseSlotIfUnheldAfterListeners(slot) {
1797
- const storeSlot = slot.storeSlot;
1798
- if (storeSlot !== void 0 && storeSlot.batchDepth > 0 && OIMContentChangeDeliveryService.INSTANCE.isLastEnqueuedSlot(storeSlot, slot)) return;
1883
+ if ((slot.slotFlags & OIM_SLOT_FLAG_QUEUED_IN_BATCH) !== 0) return;
1799
1884
  this.releaseSlotIfUnheld(slot);
1800
1885
  }
1801
1886
  releaseWrittenSlotIfUnheld(slot) {
@@ -1834,7 +1919,7 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1834
1919
  }
1835
1920
  onSlotIdle(slot) {
1836
1921
  if (oimIsSlotEmpty(slot)) return;
1837
- if (this.slotReleasePolicy.onSlotIdle(slot)) this.releaseSlotIfUnheld(slot);
1922
+ this.slotReleasePolicy.onSlotIdle(slot);
1838
1923
  }
1839
1924
  onSlotFirstSubscribed(slot) {
1840
1925
  this.slotSubscriptionListener.onSlotFirstSubscribed(slot);
@@ -1853,14 +1938,7 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1853
1938
  if (!isEmpty && !this.releasesWrittenSlots) return;
1854
1939
  if (!this.isReleasable(ownSlot)) return;
1855
1940
  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);
1941
+ this.releaseSlot(ownSlot);
1864
1942
  }
1865
1943
  isReleasable(slot) {
1866
1944
  if (slot.holdCount > 0) return false;
@@ -1868,18 +1946,16 @@ var OIMSlotOwnerService = class extends OIMSlotOwner {
1868
1946
  if (slot.columnSlotStore !== void 0) return false;
1869
1947
  return !this.slotContentService.hasReference(slot);
1870
1948
  }
1871
- releaseSlot(slot, isEmpty) {
1872
- if (!isEmpty) this.assertWritable(slot);
1873
- this.slotContentService.releaseSlotContent(slot, this);
1949
+ releaseSlot(slot) {
1950
+ this.slotContentService.releaseSlotContent(slot);
1874
1951
  slot.slotFlags |= OIM_SLOT_FLAG_EMPTY;
1875
1952
  this.slotReleasePolicy.cancelSlotRelease(slot);
1876
- const storeSlot = slot.storeSlot;
1877
- if (storeSlot !== void 0) this.slotFilingService.unfileSlot(storeSlot.store, slot);
1953
+ this.slotFilingService.unfileSlot(slot.storeSlot.store, slot);
1878
1954
  oimMarkSlotReleased(slot);
1879
1955
  }
1880
1956
  };
1881
1957
 
1882
- // src/engine/slot/utils/createOIMStoreSlot.ts
1958
+ // src/slot/utils/createOIMStoreSlot.ts
1883
1959
  function createOIMStoreSlot(store, channelSlot, slotService, sourceStoreSlot) {
1884
1960
  return {
1885
1961
  store,
@@ -1916,7 +1992,7 @@ function createOIMStoreSlot(store, channelSlot, slotService, sourceStoreSlot) {
1916
1992
  };
1917
1993
  }
1918
1994
 
1919
- // src/facade/slot/OIMSlotCollectionService.ts
1995
+ // src/slot/OIMSlotCollectionService.ts
1920
1996
  var OIMSlotCollectionService = class {
1921
1997
  constructor(options) {
1922
1998
  const slotOwnerService = new OIMSlotOwnerService({ ...options, slotFilingService: options.slotStoreService });
@@ -1932,17 +2008,17 @@ var OIMSlotCollectionService = class {
1932
2008
  }
1933
2009
  createStoreSlot(channelMap) {
1934
2010
  const channelSlot = channelMap.defaultChannelSlot;
1935
- return this.createStoreSlotWith((store) => createOIMStoreSlot(store, channelSlot, this));
2011
+ return this.createStoreSlotOverNewStore((store) => createOIMStoreSlot(store, channelSlot, this));
1936
2012
  }
1937
2013
  createStoreSlotFrom(sourceStoreSlot) {
1938
- return this.createStoreSlotWith((store) => createOIMStoreSlot(
2014
+ return this.createStoreSlotOverNewStore((store) => createOIMStoreSlot(
1939
2015
  store,
1940
2016
  sourceStoreSlot.channelSlot,
1941
2017
  this,
1942
2018
  sourceStoreSlot
1943
2019
  ));
1944
2020
  }
1945
- createStoreSlotWith(createStoreSlotLiteral) {
2021
+ createStoreSlotOverNewStore(createStoreSlotLiteral) {
1946
2022
  const storeSlot = createStoreSlotLiteral(this.slotStoreService.createStore());
1947
2023
  if (this.storeSlotListener !== void 0) this.storeSlotListener.onStoreSlotCreated(storeSlot);
1948
2024
  return storeSlot;
@@ -1976,13 +2052,13 @@ var OIMSlotCollectionService = class {
1976
2052
  return this.slotStoreService.isSameKey(key, otherKey);
1977
2053
  }
1978
2054
  openBatch(storeSlot) {
1979
- OIMContentChangeDeliveryService.INSTANCE.openBatch(storeSlot);
2055
+ OIMSlotContentChangeDeliveryService.INSTANCE.openBatch(storeSlot);
1980
2056
  }
1981
2057
  closeBatch(storeSlot) {
1982
- OIMContentChangeDeliveryService.INSTANCE.closeBatch(storeSlot);
2058
+ OIMSlotContentChangeDeliveryService.INSTANCE.closeBatch(storeSlot);
1983
2059
  }
1984
2060
  writeInBatch(storeSlot, write) {
1985
- const contentChangeDeliveryService = OIMContentChangeDeliveryService.INSTANCE;
2061
+ const contentChangeDeliveryService = OIMSlotContentChangeDeliveryService.INSTANCE;
1986
2062
  contentChangeDeliveryService.openBatch(storeSlot);
1987
2063
  try {
1988
2064
  return write();
@@ -2003,7 +2079,7 @@ var OIMSlotCollectionService = class {
2003
2079
  }
2004
2080
  };
2005
2081
 
2006
- // src/facade/slot/OIMWritableSlotCollectionService.ts
2082
+ // src/slot/OIMWritableSlotCollectionService.ts
2007
2083
  var OIMWritableSlotCollectionService = class extends OIMSlotCollectionService {
2008
2084
  writeSlotContentByKey(storeSlot, key, content, changedSlots) {
2009
2085
  const filed = this.slotStoreService.get(storeSlot.store, key);
@@ -2017,7 +2093,7 @@ var OIMWritableSlotCollectionService = class extends OIMSlotCollectionService {
2017
2093
  }
2018
2094
  };
2019
2095
 
2020
- // src/facade/slot/OIMSingleSlotService.ts
2096
+ // src/slot/OIMSingleSlotService.ts
2021
2097
  var OIMSingleSlotService = class {
2022
2098
  constructor(options) {
2023
2099
  const slotOwnerService = new OIMSlotOwnerService({ ...options, slotFilingService: options.slotStoreService });
@@ -2068,7 +2144,7 @@ var OIMSingleSlotService = class {
2068
2144
  }
2069
2145
  };
2070
2146
 
2071
- // src/facade/slot/OIMWritableSingleSlotService.ts
2147
+ // src/slot/OIMWritableSingleSlotService.ts
2072
2148
  var OIMWritableSingleSlotService = class extends OIMSingleSlotService {
2073
2149
  writeSingleSlotContent(storeSlot, content, changedSlots) {
2074
2150
  const filed = this.slotStoreService.getSingleSlot(storeSlot.store);
@@ -2086,7 +2162,7 @@ var OIMWritableSingleSlotService = class extends OIMSingleSlotService {
2086
2162
  }
2087
2163
  };
2088
2164
 
2089
- // src/engine/entity/OIMSlotEntityPresenceEmptinessPolicy.ts
2165
+ // src/entity/OIMSlotEntityPresenceEmptinessPolicy.ts
2090
2166
  var _OIMSlotEntityPresenceEmptinessPolicy = class _OIMSlotEntityPresenceEmptinessPolicy {
2091
2167
  isEmpty(entitySlot) {
2092
2168
  return entitySlot.entity === void 0;
@@ -2095,8 +2171,8 @@ var _OIMSlotEntityPresenceEmptinessPolicy = class _OIMSlotEntityPresenceEmptines
2095
2171
  _OIMSlotEntityPresenceEmptinessPolicy.INSTANCE = new _OIMSlotEntityPresenceEmptinessPolicy();
2096
2172
  var OIMSlotEntityPresenceEmptinessPolicy = _OIMSlotEntityPresenceEmptinessPolicy;
2097
2173
 
2098
- // src/engine/entity/utils/createOIMEntitySlot.ts
2099
- function createOIMEntitySlot(key, owner, storeSlot = void 0) {
2174
+ // src/entity/utils/createOIMEntitySlot.ts
2175
+ function createOIMEntitySlot(key, owner, storeSlot) {
2100
2176
  return {
2101
2177
  effects: void 0,
2102
2178
  changedAtRevision: 0,
@@ -2117,8 +2193,8 @@ function createOIMEntitySlot(key, owner, storeSlot = void 0) {
2117
2193
  };
2118
2194
  }
2119
2195
 
2120
- // src/engine/entity/utils/createOIMSingleEntitySlot.ts
2121
- function createOIMSingleEntitySlot(owner, storeSlot) {
2196
+ // src/entity/utils/createOIMEntityContentSlot.ts
2197
+ function createOIMEntityContentSlot(owner, storeSlot) {
2122
2198
  const singleEntitySlot = {
2123
2199
  effects: void 0,
2124
2200
  changedAtRevision: 0,
@@ -2140,7 +2216,15 @@ function createOIMSingleEntitySlot(owner, storeSlot) {
2140
2216
  return singleEntitySlot;
2141
2217
  }
2142
2218
 
2143
- // src/engine/entity/OIMSlotContentEntityService.ts
2219
+ // src/slot/utils/oimAssertSlotUnheld.ts
2220
+ var oimAssertSlotUnheld = (slot) => {
2221
+ if (slot.holdCount === 0) return;
2222
+ throw new Error(
2223
+ "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."
2224
+ );
2225
+ };
2226
+
2227
+ // src/entity/OIMSlotContentEntityService.ts
2144
2228
  var OIMSlotContentEntityService = class {
2145
2229
  constructor(options) {
2146
2230
  this.entityWriter = options.entityWriter;
@@ -2151,7 +2235,7 @@ var OIMSlotContentEntityService = class {
2151
2235
  return createOIMEntitySlot(key, slotOwner, storeSlot);
2152
2236
  }
2153
2237
  createSingleSlot(storeSlot, slotOwner) {
2154
- return createOIMSingleEntitySlot(slotOwner, storeSlot);
2238
+ return createOIMEntityContentSlot(slotOwner, storeSlot);
2155
2239
  }
2156
2240
  isSlotEmpty(entitySlot) {
2157
2241
  return this.slotEmptinessPolicy.isEmpty(entitySlot);
@@ -2293,7 +2377,7 @@ var OIMSlotContentEntityService = class {
2293
2377
  slotOwnerService.assertWritable(entitySlot);
2294
2378
  const channelSlot = oimGetChannelSlot(entitySlot);
2295
2379
  if (!this.isOnFastPath(entitySlot)) {
2296
- this.releaseSlotContent(entitySlot);
2380
+ this.clearEntityAndMarkColumns(entitySlot);
2297
2381
  slotOwnerService.settleEmptiness(entitySlot, this.slotEmptinessPolicy.isEmpty(entitySlot));
2298
2382
  slotOwnerService.dispatchContentChange(entitySlot);
2299
2383
  slotOwnerService.releaseSlotIfUnheldAfterListeners(entitySlot);
@@ -2356,9 +2440,12 @@ var OIMSlotContentEntityService = class {
2356
2440
  slotOwnerService.releaseSlotIfUnheldAfterListeners(entitySlot);
2357
2441
  }
2358
2442
  releaseSlotContent(entitySlot) {
2443
+ oimAssertSlotUnheld(entitySlot);
2444
+ this.clearEntityAndMarkColumns(entitySlot);
2445
+ }
2446
+ clearEntityAndMarkColumns(entitySlot) {
2359
2447
  const entity = entitySlot.entity;
2360
2448
  if (entity === void 0) return;
2361
- this.slotOwnerServiceOf(entitySlot).assertWritable(entitySlot);
2362
2449
  this.entityWriter.clearEntity(entitySlot);
2363
2450
  this.dispatchColumnsChanged(entitySlot, entity, void 0);
2364
2451
  }
@@ -2390,34 +2477,21 @@ var OIMSlotContentEntityService = class {
2390
2477
  }
2391
2478
  };
2392
2479
 
2393
- // src/factories/defaults/OIMDefaultValue.ts
2480
+ // src/db/OIMDefaultValue.ts
2394
2481
  var OIMDefaultValue = class {
2395
- constructor(name, createValue) {
2482
+ constructor(createValue) {
2396
2483
  this.defaultValue = void 0;
2397
- this.isHandedOut = false;
2398
- this.name = name;
2399
2484
  this.createValue = createValue;
2400
2485
  }
2401
2486
  getValue() {
2402
- this.isHandedOut = true;
2403
2487
  return this.defaultValue ?? (this.defaultValue = this.createValue());
2404
2488
  }
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
2489
  };
2416
2490
 
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);
2491
+ // src/db/constants/OIM_DEFAULT_STORE_SLOT_LISTENER.ts
2492
+ var OIM_DEFAULT_STORE_SLOT_LISTENER = /* @__PURE__ */ new OIMDefaultValue(() => OIMNoStoreSlotListener.INSTANCE);
2419
2493
 
2420
- // src/engine/store/OIMSlotMapStoreService.ts
2494
+ // src/store/OIMSlotMapStoreService.ts
2421
2495
  var _OIMSlotMapStoreService = class _OIMSlotMapStoreService {
2422
2496
  createStore() {
2423
2497
  return /* @__PURE__ */ new Map();
@@ -2453,16 +2527,32 @@ var _OIMSlotMapStoreService = class _OIMSlotMapStoreService {
2453
2527
  _OIMSlotMapStoreService.INSTANCE = new _OIMSlotMapStoreService();
2454
2528
  var OIMSlotMapStoreService = _OIMSlotMapStoreService;
2455
2529
 
2456
- // src/factories/utils/oimSlotStoreServiceWithDefault.ts
2457
- function oimSlotStoreServiceWithDefault(slotStoreService) {
2530
+ // src/store/utils/oimResolveSlotStoreService.ts
2531
+ function oimResolveSlotStoreService(slotStoreService) {
2458
2532
  return slotStoreService ?? OIMSlotMapStoreService.INSTANCE;
2459
2533
  }
2460
2534
 
2461
- // src/engine/column/OIMPushColumnSlotOwner.ts
2535
+ // src/db/OIMDefaults.ts
2536
+ var _OIMDefaults = class _OIMDefaults {
2537
+ constructor(options = {}) {
2538
+ this.slotStamp = options.slotStamp;
2539
+ this.slotReleasePolicy = options.slotReleasePolicy;
2540
+ this.entityWriter = options.entityWriter;
2541
+ this.entitySlotEmptinessPolicy = options.entitySlotEmptinessPolicy;
2542
+ this.indexKeysService = options.indexKeysService;
2543
+ this.columnSlotStoreService = options.columnSlotStoreService;
2544
+ this.computedColumnSlotStoreService = options.computedColumnSlotStoreService;
2545
+ this.storeSlotListener = options.storeSlotListener;
2546
+ }
2547
+ };
2548
+ _OIMDefaults.INSTANCE = new _OIMDefaults();
2549
+ var OIMDefaults = _OIMDefaults;
2550
+
2551
+ // src/column/OIMPushColumnSlotOwner.ts
2462
2552
  var hasValueColumn = (value, columnName) => Object.prototype.hasOwnProperty.call(value, columnName) && value[columnName] !== void 0;
2463
2553
  var OIMPushColumnSlotOwner = class extends OIMColumnSlotOwner {
2464
2554
  constructor(options) {
2465
- super(oimColumnSlotStoreServiceOfColumnOwnerOptions(options));
2555
+ super(oimColumnSlotStoreServiceOfColumnSlotOwnerOptions(options));
2466
2556
  }
2467
2557
  createColumnSlot(carrierSlot, key) {
2468
2558
  return {
@@ -2476,7 +2566,7 @@ var OIMPushColumnSlotOwner = class extends OIMColumnSlotOwner {
2476
2566
  releaseDueAfterUnholdMs: -1,
2477
2567
  slotFlags: OIM_SLOT_FLAG_EMPTY,
2478
2568
  columnSlotStore: void 0,
2479
- storeSlot: void 0,
2569
+ storeSlot: carrierSlot.storeSlot,
2480
2570
  owner: this,
2481
2571
  key,
2482
2572
  carrierSlot
@@ -2545,51 +2635,51 @@ var OIMPushColumnSlotOwner = class extends OIMColumnSlotOwner {
2545
2635
  }
2546
2636
  };
2547
2637
 
2548
- // src/engine/column/utils/createOIMPushColumnSlotOwner.ts
2638
+ // src/column/utils/createOIMPushColumnSlotOwner.ts
2549
2639
  var createOIMPushColumnSlotOwner = (columnSlotOwnerOptions) => new OIMPushColumnSlotOwner(columnSlotOwnerOptions);
2550
2640
 
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);
2641
+ // src/db/constants/OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.ts
2642
+ var OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE = /* @__PURE__ */ new OIMDefaultValue(() => OIMSlotMapStoreService.INSTANCE);
2553
2643
 
2554
- // src/engine/column/utils/oimColumnOwnerOptions.ts
2555
- function oimColumnOwnerOptions(columnSlotOwnerOptions) {
2644
+ // src/column/utils/oimColumnSlotOwnerOptions.ts
2645
+ function oimColumnSlotOwnerOptions(columnSlotOwnerOptions) {
2556
2646
  return columnSlotOwnerOptions.columnNames !== void 0 ? { columnNames: columnSlotOwnerOptions.columnNames } : { columnSlotStoreService: columnSlotOwnerOptions.columnSlotStoreService };
2557
2647
  }
2558
2648
 
2559
- // src/factories/utils/oimColumnOwnerOptionsWithDefault.ts
2560
- function oimColumnOwnerOptionsWithDefault(columnSlotStoreService, columnNames, defaultColumnSlotStoreService) {
2561
- return oimColumnOwnerOptions({ columnNames, columnSlotStoreService: columnSlotStoreService ?? defaultColumnSlotStoreService });
2649
+ // src/column/utils/oimResolveColumnSlotOwnerOptions.ts
2650
+ function oimResolveColumnSlotOwnerOptions(columnSlotStoreService, columnNames, defaultColumnSlotStoreService) {
2651
+ return oimColumnSlotOwnerOptions({ columnNames, columnSlotStoreService: columnSlotStoreService ?? defaultColumnSlotStoreService });
2562
2652
  }
2563
2653
 
2564
- // src/factories/utils/oimSlotOwnerOptionsWithDefault.ts
2565
- function oimSlotOwnerOptionsWithDefault(db, options) {
2654
+ // src/slot/utils/oimResolveSlotOwnerServiceOptions.ts
2655
+ function oimResolveSlotOwnerServiceOptions(defaults, options) {
2566
2656
  return {
2567
- slotStamp: db.slotStamp,
2568
- slotReleasePolicy: options.slotReleasePolicy ?? db.slotReleasePolicy,
2657
+ slotStamp: defaults.slotStamp,
2658
+ slotReleasePolicy: options.slotReleasePolicy ?? defaults.slotReleasePolicy,
2569
2659
  slotSubscriptionListener: options.slotSubscriptionListener,
2570
- columnSlotOwnerOptions: oimColumnOwnerOptionsWithDefault(
2660
+ columnSlotOwnerOptions: oimResolveColumnSlotOwnerOptions(
2571
2661
  options.columnSlotStoreService,
2572
2662
  options.columnNames,
2573
- OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.getValue()
2663
+ defaults.columnSlotStoreService ?? OIM_DEFAULT_COLUMN_SLOT_STORE_SERVICE.getValue()
2574
2664
  ),
2575
2665
  createColumnSlotOwner: createOIMPushColumnSlotOwner
2576
2666
  };
2577
2667
  }
2578
2668
 
2579
- // src/factories/createOIMSlotCollectionService.ts
2580
- function createOIMSlotCollectionService(db, options) {
2669
+ // src/slot/createOIMSlotCollectionService.ts
2670
+ function createOIMSlotCollectionService(options) {
2581
2671
  return new OIMWritableSlotCollectionService({
2582
- ...oimSlotOwnerOptionsWithDefault(db, options),
2583
- slotStoreService: oimSlotStoreServiceWithDefault(options.slotStoreService),
2672
+ ...oimResolveSlotOwnerServiceOptions(options.defaults ?? OIMDefaults.INSTANCE, options),
2673
+ slotStoreService: oimResolveSlotStoreService(options.slotStoreService),
2584
2674
  slotContentService: options.slotContentService,
2585
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2675
+ storeSlotListener: options.defaults?.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2586
2676
  });
2587
2677
  }
2588
2678
 
2589
- // src/engine/slot/constants/OIM_FROZEN_EMPTY_SLOTS.ts
2679
+ // src/slot/constants/OIM_FROZEN_EMPTY_SLOTS.ts
2590
2680
  var OIM_FROZEN_EMPTY_SLOTS = Object.freeze([]);
2591
2681
 
2592
- // src/engine/store/OIMSingleSlotStoreService.ts
2682
+ // src/store/OIMSingleSlotStoreService.ts
2593
2683
  var _OIMSingleSlotStoreService = class _OIMSingleSlotStoreService {
2594
2684
  createStore() {
2595
2685
  return { slot: void 0 };
@@ -2614,36 +2704,36 @@ var _OIMSingleSlotStoreService = class _OIMSingleSlotStoreService {
2614
2704
  _OIMSingleSlotStoreService.INSTANCE = new _OIMSingleSlotStoreService();
2615
2705
  var OIMSingleSlotStoreService = _OIMSingleSlotStoreService;
2616
2706
 
2617
- // src/factories/createOIMSingleSlotService.ts
2618
- function createOIMSingleSlotService(db, options) {
2707
+ // src/slot/createOIMSingleSlotService.ts
2708
+ function createOIMSingleSlotService(options) {
2619
2709
  return new OIMWritableSingleSlotService({
2620
- ...oimSlotOwnerOptionsWithDefault(db, options),
2710
+ ...oimResolveSlotOwnerServiceOptions(options.defaults ?? OIMDefaults.INSTANCE, options),
2621
2711
  slotStoreService: OIMSingleSlotStoreService.INSTANCE,
2622
2712
  slotContentService: options.slotContentService,
2623
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2713
+ storeSlotListener: options.defaults?.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
2624
2714
  });
2625
2715
  }
2626
2716
 
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);
2717
+ // src/db/constants/OIM_DEFAULT_ENTITY_SLOT_EMPTINESS_POLICY.ts
2718
+ var OIM_DEFAULT_ENTITY_SLOT_EMPTINESS_POLICY = /* @__PURE__ */ new OIMDefaultValue(() => OIMSlotEntityPresenceEmptinessPolicy.INSTANCE);
2629
2719
 
2630
- // src/engine/entity/utils/oimClearEntity.ts
2720
+ // src/entity/utils/oimClearEntity.ts
2631
2721
  function oimClearEntity(entitySlot) {
2632
2722
  entitySlot.entity = void 0;
2633
2723
  }
2634
2724
 
2635
- // src/engine/entity/constants/OIM_FROZEN_EMPTY_COLUMN_NAMES.ts
2725
+ // src/entity/constants/OIM_FROZEN_EMPTY_COLUMN_NAMES.ts
2636
2726
  var OIM_FROZEN_EMPTY_COLUMN_NAMES = Object.freeze([]);
2637
2727
 
2638
- // src/engine/entity/constants/OIM_PROTO_KEY.ts
2728
+ // src/entity/constants/OIM_PROTO_KEY.ts
2639
2729
  var OIM_PROTO_KEY = "__proto__";
2640
2730
 
2641
- // src/engine/entity/utils/oimIsProtoKey.ts
2731
+ // src/entity/utils/oimIsProtoKey.ts
2642
2732
  function oimIsProtoKey(name) {
2643
2733
  return name === OIM_PROTO_KEY;
2644
2734
  }
2645
2735
 
2646
- // src/engine/entity/utils/oimOwnedColumnNames.ts
2736
+ // src/entity/utils/oimOwnedColumnNames.ts
2647
2737
  function oimOwnedColumnNames(slot, names) {
2648
2738
  const entity = slot.entity;
2649
2739
  if (entity === void 0) return void 0;
@@ -2657,12 +2747,12 @@ function oimOwnedColumnNames(slot, names) {
2657
2747
  return owned;
2658
2748
  }
2659
2749
 
2660
- // src/engine/entity/utils/oimInsertEntityWithoutCopy.ts
2750
+ // src/entity/utils/oimInsertEntityWithoutCopy.ts
2661
2751
  function oimInsertEntityWithoutCopy(slot, entity) {
2662
2752
  slot.entity = entity;
2663
2753
  }
2664
2754
 
2665
- // src/engine/entity/utils/oimPatchEntityColumns.ts
2755
+ // src/entity/utils/oimPatchEntityColumns.ts
2666
2756
  function oimPatchEntityColumns(slot, patch, sameValueGuard, changedColumnNames, targetOf) {
2667
2757
  const entity = slot.entity;
2668
2758
  if (entity === void 0) return void 0;
@@ -2676,7 +2766,7 @@ function oimPatchEntityColumns(slot, patch, sameValueGuard, changedColumnNames,
2676
2766
  return target;
2677
2767
  }
2678
2768
 
2679
- // src/engine/entity/utils/oimPatchEntityColumn.ts
2769
+ // src/entity/utils/oimPatchEntityColumn.ts
2680
2770
  function oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, targetOf) {
2681
2771
  const entity = slot.entity;
2682
2772
  if (entity === void 0) return void 0;
@@ -2687,7 +2777,7 @@ function oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedCo
2687
2777
  return target;
2688
2778
  }
2689
2779
 
2690
- // src/engine/entity/utils/oimClearDepartedEntityColumns.ts
2780
+ // src/entity/utils/oimClearDepartedEntityColumns.ts
2691
2781
  function oimClearDepartedEntityColumns(prevColumns, prevEntity, entity, patchedTarget, changedColumnNames, targetOf) {
2692
2782
  let target = patchedTarget;
2693
2783
  for (const name in prevColumns) {
@@ -2699,7 +2789,7 @@ function oimClearDepartedEntityColumns(prevColumns, prevEntity, entity, patchedT
2699
2789
  return target;
2700
2790
  }
2701
2791
 
2702
- // src/engine/entity/utils/oimPutEntityColumns.ts
2792
+ // src/entity/utils/oimPutEntityColumns.ts
2703
2793
  function oimPutEntityColumns(slot, entity, sameValueGuard, changedColumnNames, targetOf) {
2704
2794
  const prevEntity = slot.entity;
2705
2795
  if (prevEntity === void 0) return void 0;
@@ -2707,8 +2797,8 @@ function oimPutEntityColumns(slot, entity, sameValueGuard, changedColumnNames, t
2707
2797
  return oimClearDepartedEntityColumns(prevEntity, prevEntity, entity, target, changedColumnNames, targetOf);
2708
2798
  }
2709
2799
 
2710
- // src/factories/utils/oimEntityWriterOptionsWithDefault.ts
2711
- function oimEntityWriterOptionsWithDefault(options) {
2800
+ // src/entity/utils/oimResolveEntityWriterOptions.ts
2801
+ function oimResolveEntityWriterOptions(options) {
2712
2802
  return {
2713
2803
  sameValueGuard: options?.sameValueGuard ?? oimSameValueZeroGuard,
2714
2804
  entityInserter: options?.entityInserter ?? oimInsertEntityWithoutCopy,
@@ -2718,7 +2808,7 @@ function oimEntityWriterOptionsWithDefault(options) {
2718
2808
  };
2719
2809
  }
2720
2810
 
2721
- // src/factories/createOIMEntityWriterInPlace.ts
2811
+ // src/entity/createOIMInPlaceEntityWriter.ts
2722
2812
  var theEntityItself = (entity) => entity;
2723
2813
  function deleteColumnsInPlace(slot, names) {
2724
2814
  const deleted = oimOwnedColumnNames(slot, names);
@@ -2727,14 +2817,14 @@ function deleteColumnsInPlace(slot, names) {
2727
2817
  for (let i = 0; i < deleted.length; i++) entity[deleted[i]] = void 0;
2728
2818
  return deleted;
2729
2819
  }
2730
- function createOIMEntityWriterInPlace(options) {
2820
+ function createOIMInPlaceEntityWriter(options) {
2731
2821
  const {
2732
2822
  sameValueGuard,
2733
2823
  entityInserter,
2734
2824
  putEntityColumns,
2735
2825
  patchEntityColumns,
2736
2826
  patchEntityColumn
2737
- } = oimEntityWriterOptionsWithDefault(options);
2827
+ } = oimResolveEntityWriterOptions(options);
2738
2828
  return {
2739
2829
  fillEntity: entityInserter,
2740
2830
  clearEntity: oimClearEntity,
@@ -2745,19 +2835,20 @@ function createOIMEntityWriterInPlace(options) {
2745
2835
  };
2746
2836
  }
2747
2837
 
2748
- // src/factories/defaults/OIM_DEFAULT_ENTITY_WRITER.ts
2749
- var OIM_DEFAULT_ENTITY_WRITER = /* @__PURE__ */ new OIMDefaultValue("ENTITY_WRITER", () => createOIMEntityWriterInPlace());
2838
+ // src/db/constants/OIM_DEFAULT_ENTITY_WRITER.ts
2839
+ var OIM_DEFAULT_ENTITY_WRITER = /* @__PURE__ */ new OIMDefaultValue(() => createOIMInPlaceEntityWriter());
2750
2840
 
2751
- // src/factories/createOIMSlotContentEntityService.ts
2752
- function createOIMSlotContentEntityService(db, options = {}) {
2841
+ // src/entity/createOIMSlotContentEntityService.ts
2842
+ function createOIMSlotContentEntityService(options = {}) {
2843
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
2753
2844
  return new OIMSlotContentEntityService({
2754
- entityWriter: options.entityWriter ?? db.entityWriter ?? OIM_DEFAULT_ENTITY_WRITER.getValue(),
2755
- slotEmptinessPolicy: options.slotEmptinessPolicy ?? OIM_DEFAULT_ENTITY_SLOT_EMPTINESS.getValue()
2845
+ entityWriter: options.entityWriter ?? defaults.entityWriter ?? OIM_DEFAULT_ENTITY_WRITER.getValue(),
2846
+ slotEmptinessPolicy: options.slotEmptinessPolicy ?? defaults.entitySlotEmptinessPolicy ?? OIM_DEFAULT_ENTITY_SLOT_EMPTINESS_POLICY.getValue()
2756
2847
  });
2757
2848
  }
2758
2849
 
2759
- // src/engine/bucket/utils/createOIMSingleBucketSlot.ts
2760
- function createOIMSingleBucketSlot(owner, bucketSlotsStore, storeSlot) {
2850
+ // src/bucket/utils/createOIMBucketContentSlot.ts
2851
+ function createOIMBucketContentSlot(owner, bucketSlotsStore, storeSlot) {
2761
2852
  const singleBucketSlot = {
2762
2853
  effects: void 0,
2763
2854
  changedAtRevision: 0,
@@ -2782,7 +2873,7 @@ function createOIMSingleBucketSlot(owner, bucketSlotsStore, storeSlot) {
2782
2873
  return singleBucketSlot;
2783
2874
  }
2784
2875
 
2785
- // src/engine/bucket/commands/OIMNoBucketCommands.ts
2876
+ // src/bucket/commands/OIMNoBucketCommands.ts
2786
2877
  var _OIMNoBucketCommands = class _OIMNoBucketCommands {
2787
2878
  recordInsert() {
2788
2879
  return;
@@ -2800,13 +2891,13 @@ var _OIMNoBucketCommands = class _OIMNoBucketCommands {
2800
2891
  _OIMNoBucketCommands.INSTANCE = new _OIMNoBucketCommands();
2801
2892
  var OIMNoBucketCommands = _OIMNoBucketCommands;
2802
2893
 
2803
- // src/engine/bucket/constants/OIM_NOTHING_WAS_REMOVED.ts
2894
+ // src/bucket/constants/OIM_NOTHING_WAS_REMOVED.ts
2804
2895
  var OIM_NOTHING_WAS_REMOVED = -1;
2805
2896
 
2806
- // src/engine/bucket/constants/OIM_REMOVED_WITHOUT_A_POSITION.ts
2897
+ // src/bucket/constants/OIM_REMOVED_WITHOUT_A_POSITION.ts
2807
2898
  var OIM_REMOVED_WITHOUT_A_POSITION = -2;
2808
2899
 
2809
- // src/engine/bucket/utils/createOIMBucketSlot.ts
2900
+ // src/bucket/utils/createOIMBucketSlot.ts
2810
2901
  function createOIMBucketSlot(key, owner, bucketSlotsStore, storeSlot) {
2811
2902
  return {
2812
2903
  effects: void 0,
@@ -2831,16 +2922,16 @@ function createOIMBucketSlot(key, owner, bucketSlotsStore, storeSlot) {
2831
2922
  };
2832
2923
  }
2833
2924
 
2834
- // src/engine/channel/utils/oimGetChannelQueueAtDepth.ts
2925
+ // src/channel/utils/oimGetChannelQueueAtDepth.ts
2835
2926
  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;
2927
+ const existingChannelQueue = channelQueues[depth];
2928
+ if (existingChannelQueue !== void 0) return existingChannelQueue;
2929
+ const channelQueue = new OIMChannelQueue();
2930
+ channelQueues[depth] = channelQueue;
2931
+ return channelQueue;
2841
2932
  }
2842
2933
 
2843
- // src/facade/bucket/OIMSlotContentBucketService.ts
2934
+ // src/bucket/OIMSlotContentBucketService.ts
2844
2935
  var OIMSlotContentBucketService = class {
2845
2936
  constructor(options) {
2846
2937
  this.bucketCommands = options.bucketCommands ?? OIMNoBucketCommands.INSTANCE;
@@ -2862,7 +2953,7 @@ var OIMSlotContentBucketService = class {
2862
2953
  );
2863
2954
  }
2864
2955
  createSingleSlot(storeSlot, slotOwner) {
2865
- return createOIMSingleBucketSlot(
2956
+ return createOIMBucketContentSlot(
2866
2957
  slotOwner,
2867
2958
  this.createBucketMemberSlotsStore(),
2868
2959
  storeSlot
@@ -2874,11 +2965,9 @@ var OIMSlotContentBucketService = class {
2874
2965
  hasReference() {
2875
2966
  return false;
2876
2967
  }
2877
- releaseSlotContent(bucketSlot, slotOwnerService) {
2878
- if (this.getBucketMemberSlotCount(bucketSlot) === 0) return;
2879
- slotOwnerService.assertWritable(bucketSlot);
2968
+ releaseSlotContent(bucketSlot) {
2969
+ oimAssertSlotUnheld(bucketSlot);
2880
2970
  this.unholdAllBucketMemberSlots(bucketSlot);
2881
- slotOwnerService.dispatchContentChange(bucketSlot);
2882
2971
  }
2883
2972
  markContentChanged(bucketSlot) {
2884
2973
  bucketSlot.owner.assertWritable(bucketSlot);
@@ -2917,10 +3006,10 @@ var OIMSlotContentBucketService = class {
2917
3006
  removeBucketMemberSlots(bucketSlot, bucketMemberSlots) {
2918
3007
  const slotOwnerService = bucketSlot.owner;
2919
3008
  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);
3009
+ const editableStoreSlot = bucketSlot.storeSlot;
3010
+ const writeDepth = editableStoreSlot.writeDepth++;
3011
+ const removedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.departedBucketMemberSlotChannelQueues ?? (editableStoreSlot.departedBucketMemberSlotChannelQueues = []), writeDepth);
3012
+ const removedAtChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.removedAtChannelQueues ?? (editableStoreSlot.removedAtChannelQueues = []), writeDepth);
2924
3013
  try {
2925
3014
  this.removeSlots(bucketSlot, bucketMemberSlots, removedChannelQueue, removedAtChannelQueue);
2926
3015
  const removedCount = removedChannelQueue.getEntryCount();
@@ -2931,7 +3020,7 @@ var OIMSlotContentBucketService = class {
2931
3020
  } finally {
2932
3021
  removedChannelQueue.keepFirstEntries(0);
2933
3022
  removedAtChannelQueue.keepFirstEntries(0);
2934
- storeSlotEditable.writeDepth = writeDepth;
3023
+ editableStoreSlot.writeDepth = writeDepth;
2935
3024
  }
2936
3025
  }
2937
3026
  insertSlotContent(bucketSlot, bucketMemberSlots, changedBucketSlots) {
@@ -3004,10 +3093,10 @@ var OIMSlotContentBucketService = class {
3004
3093
  }
3005
3094
  reconcileBucketMemberSlots(bucketSlot, bucketMemberSlots) {
3006
3095
  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);
3096
+ const editableStoreSlot = bucketSlot.storeSlot;
3097
+ const writeDepth = editableStoreSlot.writeDepth++;
3098
+ const arrivedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.arrivedBucketMemberSlotChannelQueues ?? (editableStoreSlot.arrivedBucketMemberSlotChannelQueues = []), writeDepth);
3099
+ const departedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.departedBucketMemberSlotChannelQueues ?? (editableStoreSlot.departedBucketMemberSlotChannelQueues = []), writeDepth);
3011
3100
  try {
3012
3101
  this.reconcileSlots(bucketSlot, bucketMemberSlots, arrivedChannelQueue, departedChannelQueue);
3013
3102
  const arrivedCount = arrivedChannelQueue.getEntryCount();
@@ -3023,7 +3112,7 @@ var OIMSlotContentBucketService = class {
3023
3112
  } finally {
3024
3113
  arrivedChannelQueue.keepFirstEntries(0);
3025
3114
  departedChannelQueue.keepFirstEntries(0);
3026
- storeSlotEditable.writeDepth = writeDepth;
3115
+ editableStoreSlot.writeDepth = writeDepth;
3027
3116
  }
3028
3117
  }
3029
3118
  drainBucketMemberSlots(bucketSlot) {
@@ -3033,9 +3122,9 @@ var OIMSlotContentBucketService = class {
3033
3122
  return true;
3034
3123
  }
3035
3124
  unholdAllBucketMemberSlots(bucketSlot) {
3036
- const storeSlotEditable = bucketSlot.storeSlot;
3037
- const writeDepth = storeSlotEditable.writeDepth++;
3038
- const departedChannelQueue = oimGetChannelQueueAtDepth(storeSlotEditable.departedBucketMemberSlotChannelQueues ?? (storeSlotEditable.departedBucketMemberSlotChannelQueues = []), writeDepth);
3125
+ const editableStoreSlot = bucketSlot.storeSlot;
3126
+ const writeDepth = editableStoreSlot.writeDepth++;
3127
+ const departedChannelQueue = oimGetChannelQueueAtDepth(editableStoreSlot.departedBucketMemberSlotChannelQueues ?? (editableStoreSlot.departedBucketMemberSlotChannelQueues = []), writeDepth);
3039
3128
  try {
3040
3129
  this.drainSlots(bucketSlot, departedChannelQueue);
3041
3130
  const drainedCount = departedChannelQueue.getEntryCount();
@@ -3043,12 +3132,12 @@ var OIMSlotContentBucketService = class {
3043
3132
  return drainedCount;
3044
3133
  } finally {
3045
3134
  departedChannelQueue.keepFirstEntries(0);
3046
- storeSlotEditable.writeDepth = writeDepth;
3135
+ editableStoreSlot.writeDepth = writeDepth;
3047
3136
  }
3048
3137
  }
3049
3138
  };
3050
3139
 
3051
- // src/facade/bucket/OIMSlotContentSetBucketService.ts
3140
+ // src/bucket/OIMSlotContentSetBucketService.ts
3052
3141
  var OIMSlotContentSetBucketService = class extends OIMSlotContentBucketService {
3053
3142
  constructor(options = {}) {
3054
3143
  super(options);
@@ -3103,7 +3192,7 @@ var OIMSlotContentSetBucketService = class extends OIMSlotContentBucketService {
3103
3192
  }
3104
3193
  };
3105
3194
 
3106
- // src/engine/bucket/array/OIMBucketMemberSlotsArrayService.ts
3195
+ // src/bucket/array/OIMBucketMemberSlotsArrayService.ts
3107
3196
  var insertionTailLimit = 8;
3108
3197
  var _OIMBucketMemberSlotsArrayService = class _OIMBucketMemberSlotsArrayService {
3109
3198
  createBucketSlotsArrayStore() {
@@ -3232,7 +3321,7 @@ function reverseRange(bucketMemberSlots, first, last) {
3232
3321
  }
3233
3322
  }
3234
3323
 
3235
- // src/facade/bucket/OIMSlotContentArrayBucketService.ts
3324
+ // src/bucket/OIMSlotContentArrayBucketService.ts
3236
3325
  var OIMSlotContentArrayBucketService = class extends OIMSlotContentBucketService {
3237
3326
  constructor(options) {
3238
3327
  super(options);
@@ -3293,10 +3382,10 @@ var OIMSlotContentArrayBucketService = class extends OIMSlotContentBucketService
3293
3382
  }
3294
3383
  };
3295
3384
 
3296
- // src/engine/bucket/constants/OIM_NOTHING_WAS_INSERTED.ts
3385
+ // src/bucket/constants/OIM_NOTHING_WAS_INSERTED.ts
3297
3386
  var OIM_NOTHING_WAS_INSERTED = -1;
3298
3387
 
3299
- // src/engine/bucket/array/utils/oimAssertWholePosition.ts
3388
+ // src/bucket/array/utils/oimAssertWholePosition.ts
3300
3389
  function oimAssertWholePosition(position) {
3301
3390
  if (position === Math.trunc(position)) return;
3302
3391
  throw new Error(
@@ -3304,7 +3393,7 @@ function oimAssertWholePosition(position) {
3304
3393
  );
3305
3394
  }
3306
3395
 
3307
- // src/facade/bucket/OIMSlotContentPositionalArrayBucketService.ts
3396
+ // src/bucket/OIMSlotContentPositionalArrayBucketService.ts
3308
3397
  var OIMSlotContentPositionalArrayBucketService = class extends OIMSlotContentArrayBucketService {
3309
3398
  constructor(options = {}) {
3310
3399
  super(options);
@@ -3377,7 +3466,7 @@ var OIMSlotContentPositionalArrayBucketService = class extends OIMSlotContentArr
3377
3466
  }
3378
3467
  };
3379
3468
 
3380
- // src/engine/bucket/utils/oimSameUniqueSlotSequence.ts
3469
+ // src/bucket/utils/oimSameUniqueSlotSequence.ts
3381
3470
  function oimSameUniqueSlotSequence(heldBucketMemberSlots, bucketMemberSlots) {
3382
3471
  const seenBucketMemberSlots = /* @__PURE__ */ new Set();
3383
3472
  let at = 0;
@@ -3391,7 +3480,7 @@ function oimSameUniqueSlotSequence(heldBucketMemberSlots, bucketMemberSlots) {
3391
3480
  return at === heldBucketMemberSlots.length;
3392
3481
  }
3393
3482
 
3394
- // src/engine/bucket/array/OIMBucketUniqueMemberSlotsArrayService.ts
3483
+ // src/bucket/array/OIMBucketUniqueMemberSlotsArrayService.ts
3395
3484
  var _OIMBucketUniqueMemberSlotsArrayService = class _OIMBucketUniqueMemberSlotsArrayService extends OIMBucketMemberSlotsArrayService {
3396
3485
  createBucketSlotsArrayStore() {
3397
3486
  return { bucketMemberSlots: [], uniqueBucketMemberSlots: /* @__PURE__ */ new Set(), sortedCount: 0 };
@@ -3450,7 +3539,7 @@ function uniqueBucketMemberSlotsOf(bucketSlotsArrayStore) {
3450
3539
  return bucketSlotsArrayStore.uniqueBucketMemberSlots;
3451
3540
  }
3452
3541
 
3453
- // src/facade/bucket/OIMSlotContentSortedArrayBucketService.ts
3542
+ // src/bucket/OIMSlotContentSortedArrayBucketService.ts
3454
3543
  var OIMSlotContentSortedArrayBucketService = class extends OIMSlotContentArrayBucketService {
3455
3544
  constructor(options) {
3456
3545
  super(options);
@@ -3480,169 +3569,7 @@ var OIMSlotContentSortedArrayBucketService = class extends OIMSlotContentArrayBu
3480
3569
  }
3481
3570
  };
3482
3571
 
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
3572
+ // src/computed/OIMComputedSourcesService.ts
3646
3573
  var _OIMComputedSourcesService = class _OIMComputedSourcesService {
3647
3574
  holdSources(derivation) {
3648
3575
  oimHoldSlots(derivation.sourceSlots);
@@ -3658,8 +3585,8 @@ var _OIMComputedSourcesService = class _OIMComputedSourcesService {
3658
3585
  _OIMComputedSourcesService.INSTANCE = new _OIMComputedSourcesService();
3659
3586
  var OIMComputedSourcesService = _OIMComputedSourcesService;
3660
3587
 
3661
- // src/engine/computed/utils/createOIMSingleComputedSlot.ts
3662
- function createOIMSingleComputedSlot(owner, computedValueService, initialValue, storeSlot) {
3588
+ // src/computed/utils/createOIMComputedContentSlot.ts
3589
+ function createOIMComputedContentSlot(owner, computedValueService, initialValue, storeSlot, sourceTracker) {
3663
3590
  const singleComputedSlot = {
3664
3591
  effects: void 0,
3665
3592
  changedAtRevision: 0,
@@ -3684,12 +3611,13 @@ function createOIMSingleComputedSlot(owner, computedValueService, initialValue,
3684
3611
  checkedAtRevision: -1,
3685
3612
  checkedAtEpoch: -1,
3686
3613
  isDeriving: false,
3687
- allRootSlots: void 0
3614
+ allRootSlots: void 0,
3615
+ sourceTracker
3688
3616
  };
3689
3617
  return singleComputedSlot;
3690
3618
  }
3691
3619
 
3692
- // src/engine/computed/OIMSlotContentComputedService.ts
3620
+ // src/computed/OIMSlotContentComputedService.ts
3693
3621
  var OIMSlotContentComputedService = class {
3694
3622
  constructor(options) {
3695
3623
  this.computedValueService = options.computedValueService;
@@ -3702,13 +3630,20 @@ var OIMSlotContentComputedService = class {
3702
3630
  slotOwner,
3703
3631
  this.computedValueService,
3704
3632
  this.initialValue,
3705
- storeSlot
3633
+ storeSlot,
3634
+ this.createSourceTracker()
3706
3635
  );
3707
3636
  this.attachSources(computedSlot, storeSlot);
3708
3637
  return computedSlot;
3709
3638
  }
3710
3639
  createSingleSlot(storeSlot, slotOwner) {
3711
- const computedSlot = createOIMSingleComputedSlot(slotOwner, this.computedValueService, this.initialValue, storeSlot);
3640
+ const computedSlot = createOIMComputedContentSlot(
3641
+ slotOwner,
3642
+ this.computedValueService,
3643
+ this.initialValue,
3644
+ storeSlot,
3645
+ this.createSourceTracker()
3646
+ );
3712
3647
  this.attachSources(computedSlot, storeSlot);
3713
3648
  return computedSlot;
3714
3649
  }
@@ -3716,56 +3651,67 @@ var OIMSlotContentComputedService = class {
3716
3651
  return false;
3717
3652
  }
3718
3653
  releaseSlotContent(computedSlot) {
3654
+ oimAssertSlotUnheld(computedSlot);
3719
3655
  OIMComputedSourcesService.INSTANCE.unholdSources(computedSlot);
3656
+ this.computedValueService.releaseSlotValue(computedSlot);
3720
3657
  }
3721
3658
  hasReference() {
3722
3659
  return false;
3723
3660
  }
3661
+ createSourceTracker() {
3662
+ return void 0;
3663
+ }
3724
3664
  attachSources(computedSlot, storeSlot) {
3725
3665
  const createSources = storeSlot.createSources ?? this.createSources;
3726
3666
  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;
3667
+ const editableComputedSlot = computedSlot;
3668
+ editableComputedSlot.sourceSlots = computedSources.sourceSlots ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
3669
+ editableComputedSlot.sourceComputeds = computedSources.sourceComputeds ?? OIM_FROZEN_EMPTY_COMPUTED_SLOTS;
3730
3670
  OIMComputedSourcesService.INSTANCE.holdSources(computedSlot);
3731
3671
  }
3732
3672
  };
3733
3673
 
3734
- // src/facade/computed/utils/createOIMComputedCollectionService.ts
3735
- function createOIMComputedCollectionService(options) {
3674
+ // src/column/utils/createOIMPullColumnSlotOwner.ts
3675
+ var createOIMPullColumnSlotOwner = (columnSlotOwnerOptions) => new OIMPullColumnSlotOwner(columnSlotOwnerOptions);
3676
+
3677
+ // src/computed/utils/createOIMComputedSlotCollectionService.ts
3678
+ function createOIMComputedSlotCollectionService(options) {
3736
3679
  return new OIMSlotCollectionService({
3737
3680
  slotReleasePolicy: options.slotReleasePolicy,
3738
3681
  slotStoreService: options.computedSlotStoreService,
3739
- slotContentService: new OIMSlotContentComputedService(options),
3682
+ slotContentService: options.slotContentService,
3740
3683
  columnSlotOwnerOptions: options.columnSlotOwnerOptions,
3741
3684
  createColumnSlotOwner: createOIMPullColumnSlotOwner,
3742
3685
  storeSlotListener: options.storeSlotListener
3743
3686
  });
3744
3687
  }
3745
3688
 
3746
- // src/facade/computed/utils/oimAttachComputedDerivation.ts
3689
+ // src/computed/utils/oimAttachComputedDerivation.ts
3747
3690
  function oimAttachComputedDerivation(computedStoreSlot, hasServiceDerive, hasServiceCreateSources, derive, createSources) {
3748
3691
  if (derive === void 0 && !hasServiceDerive || createSources === void 0 && !hasServiceCreateSources) {
3749
3692
  throw new Error(
3750
3693
  "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
3694
  );
3752
3695
  }
3753
- const computedStoreSlotEditable = computedStoreSlot;
3754
- computedStoreSlotEditable.derive = derive;
3755
- computedStoreSlotEditable.createSources = createSources;
3696
+ const editableComputedStoreSlot = computedStoreSlot;
3697
+ editableComputedStoreSlot.derive = derive;
3698
+ editableComputedStoreSlot.createSources = createSources;
3756
3699
  return computedStoreSlot;
3757
3700
  }
3758
3701
 
3759
- // src/facade/computed/OIMComputedService.ts
3702
+ // src/computed/OIMComputedService.ts
3760
3703
  var OIMComputedService = class {
3761
3704
  constructor(options) {
3762
- this.computedCollectionService = createOIMComputedCollectionService({
3763
- computedValueService: new OIMComputedValueService({
3764
- derive: options.derive,
3765
- sameValueGuard: options.sameValueGuard
3705
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
3706
+ slotContentService: new OIMSlotContentComputedService({
3707
+ computedValueService: new OIMComputedValueService({
3708
+ derive: options.derive,
3709
+ sameValueGuard: options.sameValueGuard,
3710
+ releaseValue: options.releaseValue
3711
+ }),
3712
+ createSources: options.createSources,
3713
+ initialValue: options.initialValue
3766
3714
  }),
3767
- createSources: options.createSources,
3768
- initialValue: options.initialValue,
3769
3715
  slotReleasePolicy: options.slotReleasePolicy,
3770
3716
  computedSlotStoreService: options.computedSlotStoreService,
3771
3717
  columnSlotOwnerOptions: options.columnSlotOwnerOptions,
@@ -3785,7 +3731,7 @@ var OIMComputedService = class {
3785
3731
  }
3786
3732
  };
3787
3733
 
3788
- // src/engine/collector/OIMSlotAtUnholdReleasePolicy.ts
3734
+ // src/collector/OIMSlotAtUnholdReleasePolicy.ts
3789
3735
  var _OIMSlotAtUnholdReleasePolicy = class _OIMSlotAtUnholdReleasePolicy {
3790
3736
  constructor() {
3791
3737
  this.releasesWrittenSlots = true;
@@ -3813,25 +3759,37 @@ var _OIMSlotAtUnholdReleasePolicy = class _OIMSlotAtUnholdReleasePolicy {
3813
3759
  _OIMSlotAtUnholdReleasePolicy.INSTANCE = new _OIMSlotAtUnholdReleasePolicy();
3814
3760
  var OIMSlotAtUnholdReleasePolicy = _OIMSlotAtUnholdReleasePolicy;
3815
3761
 
3816
- // src/factories/createOIMComputedService.ts
3817
- function createOIMComputedService(options) {
3818
- return new OIMComputedService({
3819
- computedSlotStoreService: oimSlotStoreServiceWithDefault(options.computedSlotStoreService),
3820
- columnSlotOwnerOptions: oimColumnOwnerOptionsWithDefault(
3762
+ // src/db/constants/OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.ts
3763
+ var OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE = /* @__PURE__ */ new OIMDefaultValue(() => OIMSlotMapStoreService.INSTANCE);
3764
+
3765
+ // src/computed/utils/oimResolveComputedDerivationOptions.ts
3766
+ function oimResolveComputedDerivationOptions(options) {
3767
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
3768
+ return {
3769
+ columnSlotOwnerOptions: oimResolveColumnSlotOwnerOptions(
3821
3770
  options.columnSlotStoreService,
3822
3771
  options.columnNames,
3823
- OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue()
3772
+ defaults.computedColumnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue()
3824
3773
  ),
3825
3774
  slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
3826
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
3827
- createSources: options.createSources,
3828
- derive: options.derive,
3775
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
3829
3776
  sameValueGuard: options.sameValueGuard,
3777
+ releaseValue: options.releaseValue,
3830
3778
  initialValue: options.initialValue
3779
+ };
3780
+ }
3781
+
3782
+ // src/computed/createOIMComputedService.ts
3783
+ function createOIMComputedService(options) {
3784
+ return new OIMComputedService({
3785
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
3786
+ ...oimResolveComputedDerivationOptions(options),
3787
+ createSources: options.createSources,
3788
+ derive: options.derive
3831
3789
  });
3832
3790
  }
3833
3791
 
3834
- // src/facade/computed/OIMSingleComputedService.ts
3792
+ // src/computed/OIMSingleComputedService.ts
3835
3793
  var OIMSingleComputedService = class {
3836
3794
  constructor(options) {
3837
3795
  this.computedSingleSlotService = new OIMSingleSlotService({
@@ -3840,7 +3798,8 @@ var OIMSingleComputedService = class {
3840
3798
  slotContentService: new OIMSlotContentComputedService({
3841
3799
  computedValueService: new OIMComputedValueService({
3842
3800
  derive: options.derive,
3843
- sameValueGuard: options.sameValueGuard
3801
+ sameValueGuard: options.sameValueGuard,
3802
+ releaseValue: options.releaseValue
3844
3803
  }),
3845
3804
  createSources: options.createSources,
3846
3805
  initialValue: options.initialValue
@@ -3863,30 +3822,133 @@ var OIMSingleComputedService = class {
3863
3822
  }
3864
3823
  };
3865
3824
 
3866
- // src/factories/createOIMSingleComputedService.ts
3825
+ // src/computed/createOIMSingleComputedService.ts
3867
3826
  function createOIMSingleComputedService(options = {}) {
3868
3827
  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(),
3828
+ ...oimResolveComputedDerivationOptions(options),
3876
3829
  createSources: options.createSources,
3877
- derive: options.derive,
3878
- sameValueGuard: options.sameValueGuard,
3879
- initialValue: options.initialValue
3830
+ derive: options.derive
3880
3831
  });
3881
3832
  }
3882
3833
 
3883
- // src/facade/computed/utils/oimColumnsComparator.ts
3834
+ // src/computed/OIMSourceTrackingComputedValueService.ts
3835
+ var OIMSourceTrackingComputedValueService = class extends OIMComputedValueService {
3836
+ constructor(options) {
3837
+ super({ sameValueGuard: options.sameValueGuard, releaseValue: options.releaseValue });
3838
+ this.deriveTrackingSources = (computedSlot) => {
3839
+ const sourceTracker = computedSlot.sourceTracker;
3840
+ sourceTracker.openSourceTracking();
3841
+ const value = this.sourceTrackingDerive(computedSlot, sourceTracker);
3842
+ if (sourceTracker.closeSourceTracking() && !oimIsSlotReleased(computedSlot)) this.replaceSources(computedSlot, sourceTracker);
3843
+ return value;
3844
+ };
3845
+ this.sourceTrackingDerive = options.derive;
3846
+ }
3847
+ getValueForSlot(computedSlot) {
3848
+ oimAssertSlotNotReleased(computedSlot);
3849
+ const sourceTracker = computedSlot.sourceTracker;
3850
+ oimRefreshComputedSlot(computedSlot, this.deriveTrackingSources, this.sameValueGuard, this.releaseValue, computedSlot.storeSlot.channelSlot.clock);
3851
+ if (sourceTracker.trackReplacedRootSlots()) {
3852
+ sourceTracker.commitTrackedSources();
3853
+ computedSlot.allRootSlots = void 0;
3854
+ }
3855
+ return computedSlot.value;
3856
+ }
3857
+ replaceSources(computedSlot, sourceTracker) {
3858
+ const trackedSourceSlots = sourceTracker.getTrackedSourceSlots().slice();
3859
+ const trackedSourceComputeds = sourceTracker.getTrackedSourceComputeds().slice();
3860
+ oimHoldSlots(trackedSourceSlots);
3861
+ oimHoldSlots(trackedSourceComputeds);
3862
+ OIMComputedSourcesService.INSTANCE.unholdSources(computedSlot);
3863
+ const editableComputedSlot = computedSlot;
3864
+ editableComputedSlot.sourceSlots = trackedSourceSlots;
3865
+ editableComputedSlot.sourceComputeds = trackedSourceComputeds;
3866
+ editableComputedSlot.allRootSlots = void 0;
3867
+ sourceTracker.commitTrackedSources();
3868
+ }
3869
+ };
3870
+
3871
+ // src/computed/OIMSlotContentSourceTrackingComputedService.ts
3872
+ var OIMSlotContentSourceTrackingComputedService = class extends OIMSlotContentComputedService {
3873
+ createSourceTracker() {
3874
+ return new OIMSourceTracker();
3875
+ }
3876
+ attachSources() {
3877
+ return;
3878
+ }
3879
+ };
3880
+
3881
+ // src/computed/OIMSourceTrackingComputedService.ts
3882
+ var OIMSourceTrackingComputedService = class {
3883
+ constructor(options) {
3884
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
3885
+ slotContentService: new OIMSlotContentSourceTrackingComputedService({
3886
+ computedValueService: new OIMSourceTrackingComputedValueService({
3887
+ derive: options.derive,
3888
+ sameValueGuard: options.sameValueGuard,
3889
+ releaseValue: options.releaseValue
3890
+ }),
3891
+ initialValue: options.initialValue
3892
+ }),
3893
+ slotReleasePolicy: options.slotReleasePolicy,
3894
+ computedSlotStoreService: options.computedSlotStoreService,
3895
+ columnSlotOwnerOptions: options.columnSlotOwnerOptions,
3896
+ storeSlotListener: options.storeSlotListener
3897
+ });
3898
+ }
3899
+ createComputedStoreSlot(channelMap) {
3900
+ return this.computedCollectionService.createStoreSlot(channelMap);
3901
+ }
3902
+ };
3903
+
3904
+ // src/computed/OIMSingleSourceTrackingComputedService.ts
3905
+ var OIMSingleSourceTrackingComputedService = class {
3906
+ constructor(options) {
3907
+ this.computedSingleSlotService = new OIMSingleSlotService({
3908
+ slotReleasePolicy: options.slotReleasePolicy,
3909
+ slotStoreService: OIMSingleSlotStoreService.INSTANCE,
3910
+ slotContentService: new OIMSlotContentSourceTrackingComputedService({
3911
+ computedValueService: new OIMSourceTrackingComputedValueService({
3912
+ derive: options.derive,
3913
+ sameValueGuard: options.sameValueGuard,
3914
+ releaseValue: options.releaseValue
3915
+ }),
3916
+ initialValue: options.initialValue
3917
+ }),
3918
+ columnSlotOwnerOptions: options.columnSlotOwnerOptions,
3919
+ createColumnSlotOwner: createOIMPullColumnSlotOwner,
3920
+ storeSlotListener: options.storeSlotListener
3921
+ });
3922
+ }
3923
+ createComputedStoreSlot(channelMap) {
3924
+ return this.computedSingleSlotService.createStoreSlot(channelMap);
3925
+ }
3926
+ };
3927
+
3928
+ // src/computed/createOIMSourceTrackingComputedService.ts
3929
+ function createOIMSourceTrackingComputedService(options) {
3930
+ return new OIMSourceTrackingComputedService({
3931
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
3932
+ ...oimResolveComputedDerivationOptions(options),
3933
+ derive: options.derive
3934
+ });
3935
+ }
3936
+
3937
+ // src/computed/createOIMSingleSourceTrackingComputedService.ts
3938
+ function createOIMSingleSourceTrackingComputedService(options) {
3939
+ return new OIMSingleSourceTrackingComputedService({
3940
+ ...oimResolveComputedDerivationOptions(options),
3941
+ derive: options.derive
3942
+ });
3943
+ }
3944
+
3945
+ // src/computed/utils/oimColumnsComparator.ts
3884
3946
  function oimColumnsComparator(columns) {
3885
3947
  return (left, right) => {
3886
3948
  for (let i = 0; i < columns.length; i++) {
3887
- const column = columns[i].column;
3888
- const leftValue = left[column];
3889
- const rightValue = right[column];
3949
+ const columnName = columns[i].columnName;
3950
+ const leftValue = left[columnName];
3951
+ const rightValue = right[columnName];
3890
3952
  if (leftValue === rightValue) continue;
3891
3953
  const isLeftMissing = leftValue === void 0 || leftValue === null || leftValue !== leftValue;
3892
3954
  const isRightMissing = rightValue === void 0 || rightValue === null || rightValue !== rightValue;
@@ -3900,7 +3962,7 @@ function oimColumnsComparator(columns) {
3900
3962
  };
3901
3963
  }
3902
3964
 
3903
- // src/facade/computed/utils/oimEntitySlotsComparator.ts
3965
+ // src/computed/utils/oimEntitySlotsComparator.ts
3904
3966
  function oimEntitySlotsComparator(compareEntities) {
3905
3967
  return (leftEntitySlot, rightEntitySlot) => {
3906
3968
  const leftEntity = leftEntitySlot.entity;
@@ -3911,7 +3973,7 @@ function oimEntitySlotsComparator(compareEntities) {
3911
3973
  };
3912
3974
  }
3913
3975
 
3914
- // src/facade/computed/OIMSortedComputedService.ts
3976
+ // src/computed/OIMSortedComputedService.ts
3915
3977
  var OIMSortedComputedService = class {
3916
3978
  constructor(options) {
3917
3979
  const indexService = options.indexService;
@@ -3925,16 +3987,18 @@ var OIMSortedComputedService = class {
3925
3987
  derive: (computedSlot) => sortBucketMemberSlots(computedSlot, bucketContentService, compareEntitySlots),
3926
3988
  sameValueGuard: oimSameSlotSequence
3927
3989
  });
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,
3990
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
3991
+ slotContentService: new OIMSlotContentComputedService({
3992
+ computedValueService,
3993
+ createSources: (computedSlot) => createSortedComputedSources(
3994
+ computedSlot.key,
3995
+ computedSlot.storeSlot,
3996
+ indexService,
3997
+ sortColumns,
3998
+ hasComparator
3999
+ ),
4000
+ initialValue: OIM_FROZEN_EMPTY_SLOTS
4001
+ }),
3938
4002
  slotReleasePolicy: options.slotReleasePolicy,
3939
4003
  computedSlotStoreService: options.computedSlotStoreService,
3940
4004
  columnSlotOwnerOptions: { columnSlotStoreService: options.columnSlotStoreService },
@@ -3948,12 +4012,12 @@ var OIMSortedComputedService = class {
3948
4012
  function compareNothing() {
3949
4013
  return 0;
3950
4014
  }
3951
- function createSortedSources(key, storeSlot, indexService, sortColumns, hasComparator) {
4015
+ function createSortedComputedSources(key, storeSlot, indexService, sortColumns, hasComparator) {
3952
4016
  const indexStoreSlot = storeSlot.sourceStoreSlot;
3953
4017
  const sourceSlots = [indexService.getSlotByKey(indexStoreSlot, key)];
3954
4018
  if (sortColumns !== void 0) {
3955
4019
  for (let i = 0; i < sortColumns.length; i++) {
3956
- sourceSlots.push(indexService.getBucketColumnByKey(indexStoreSlot, key, sortColumns[i].column));
4020
+ sourceSlots.push(indexService.getBucketColumnByKey(indexStoreSlot, key, sortColumns[i].columnName));
3957
4021
  }
3958
4022
  } else if (hasComparator) {
3959
4023
  sourceSlots.push(indexService.getAnyBucketColumnByKey(indexStoreSlot, key));
@@ -4018,20 +4082,21 @@ function reconcileArrayWithEveryBucketMemberSlot(entitySlots, bucketMemberSlots)
4018
4082
  return next;
4019
4083
  }
4020
4084
 
4021
- // src/factories/createOIMSortedComputedService.ts
4085
+ // src/computed/createOIMSortedComputedService.ts
4022
4086
  function createOIMSortedComputedService(options) {
4087
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
4023
4088
  return new OIMSortedComputedService({
4024
4089
  indexService: options.indexService,
4025
- computedSlotStoreService: oimSlotStoreServiceWithDefault(options.computedSlotStoreService),
4026
- columnSlotStoreService: options.columnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4090
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
4091
+ columnSlotStoreService: options.columnSlotStoreService ?? defaults.computedColumnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4027
4092
  sortColumns: options.sortColumns,
4028
4093
  comparator: options.comparator,
4029
4094
  slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
4030
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4095
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4031
4096
  });
4032
4097
  }
4033
4098
 
4034
- // src/facade/computed/OIMBucketMemoComputedService.ts
4099
+ // src/computed/OIMBucketMemoComputedService.ts
4035
4100
  var OIMBucketMemoComputedService = class {
4036
4101
  constructor(options) {
4037
4102
  const bucketCollectionService = options.bucketCollectionService;
@@ -4040,10 +4105,12 @@ var OIMBucketMemoComputedService = class {
4040
4105
  derive: (computedSlot) => deriveBucketMemo(computedSlot, bucketContentService),
4041
4106
  sameValueGuard: oimSameSlotSequence
4042
4107
  });
4043
- this.computedCollectionService = createOIMComputedCollectionService({
4044
- computedValueService,
4045
- createSources: (computedSlot) => createBucketMemoSources(computedSlot.key, computedSlot.storeSlot, bucketCollectionService),
4046
- initialValue: OIM_FROZEN_EMPTY_SLOTS,
4108
+ this.computedCollectionService = createOIMComputedSlotCollectionService({
4109
+ slotContentService: new OIMSlotContentComputedService({
4110
+ computedValueService,
4111
+ createSources: (computedSlot) => createBucketMemoComputedSources(computedSlot.key, computedSlot.storeSlot, bucketCollectionService),
4112
+ initialValue: OIM_FROZEN_EMPTY_SLOTS
4113
+ }),
4047
4114
  slotReleasePolicy: options.slotReleasePolicy,
4048
4115
  computedSlotStoreService: options.computedSlotStoreService,
4049
4116
  columnSlotOwnerOptions: { columnSlotStoreService: options.columnSlotStoreService },
@@ -4057,26 +4124,27 @@ var OIMBucketMemoComputedService = class {
4057
4124
  function deriveBucketMemo(computedSlot, bucketContentService) {
4058
4125
  return Array.from(bucketContentService.getBucketMemberSlots(computedSlot.sourceSlots[0]));
4059
4126
  }
4060
- function createBucketMemoSources(key, storeSlot, bucketCollectionService) {
4127
+ function createBucketMemoComputedSources(key, storeSlot, bucketCollectionService) {
4061
4128
  const bucketStoreSlot = storeSlot.sourceStoreSlot;
4062
4129
  return { sourceSlots: [bucketCollectionService.getSlotByKey(bucketStoreSlot, key)] };
4063
4130
  }
4064
4131
 
4065
- // src/factories/createOIMBucketMemoComputedService.ts
4132
+ // src/computed/createOIMBucketMemoComputedService.ts
4066
4133
  function createOIMBucketMemoComputedService(options) {
4134
+ const defaults = options.defaults ?? OIMDefaults.INSTANCE;
4067
4135
  return new OIMBucketMemoComputedService({
4068
4136
  bucketCollectionService: options.bucketCollectionService,
4069
- computedSlotStoreService: oimSlotStoreServiceWithDefault(options.computedSlotStoreService),
4070
- columnSlotStoreService: options.columnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4137
+ computedSlotStoreService: oimResolveSlotStoreService(options.computedSlotStoreService),
4138
+ columnSlotStoreService: options.columnSlotStoreService ?? defaults.computedColumnSlotStoreService ?? OIM_DEFAULT_COMPUTED_COLUMN_SLOT_STORE_SERVICE.getValue(),
4071
4139
  slotReleasePolicy: options.slotReleasePolicy ?? OIMSlotAtUnholdReleasePolicy.INSTANCE,
4072
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4140
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue()
4073
4141
  });
4074
4142
  }
4075
4143
 
4076
- // src/engine/bucket/commands/constants/OIM_MAX_COMMANDS_PER_SLOT.ts
4144
+ // src/bucket/commands/constants/OIM_MAX_COMMANDS_PER_SLOT.ts
4077
4145
  var OIM_MAX_COMMANDS_PER_SLOT = 1;
4078
4146
 
4079
- // src/facade/bucket/OIMBucketCommands.ts
4147
+ // src/bucket/OIMBucketCommands.ts
4080
4148
  var OIMBucketCommands = class {
4081
4149
  constructor(options) {
4082
4150
  this.maxCommandsPerSlot = options.maxCommandsPerSlot ?? OIM_MAX_COMMANDS_PER_SLOT;
@@ -4091,40 +4159,40 @@ var OIMBucketCommands = class {
4091
4159
  this.recordCommand(bucketSlot, { type: "move", from, to }, bucketMemberSlotCount);
4092
4160
  }
4093
4161
  recordWholeList(bucketSlot) {
4094
- const bucketSlotEditable = enlistInFlush(bucketSlot);
4095
- const commands = bucketSlotEditable.commands;
4162
+ const editableBucketSlot = enlistInFlush(bucketSlot);
4163
+ const commands = editableBucketSlot.commands;
4096
4164
  if (commands !== void 0 && commands.length !== 0) commands.length = 0;
4097
- bucketSlotEditable.isWholeListRecorded = true;
4165
+ editableBucketSlot.isWholeListRecorded = true;
4098
4166
  }
4099
4167
  recordCommand(bucketSlot, orderedListCommand, bucketMemberSlotCount) {
4100
- const bucketSlotEditable = enlistInFlush(bucketSlot);
4101
- if (bucketSlotEditable.isWholeListRecorded) return;
4102
- const commands = bucketSlotEditable.commands ?? (bucketSlotEditable.commands = []);
4168
+ const editableBucketSlot = enlistInFlush(bucketSlot);
4169
+ if (editableBucketSlot.isWholeListRecorded) return;
4170
+ const commands = editableBucketSlot.commands ?? (editableBucketSlot.commands = []);
4103
4171
  commands.push(orderedListCommand);
4104
4172
  if (commands.length > this.maxCommandsPerSlot * bucketMemberSlotCount) {
4105
4173
  commands.length = 0;
4106
- bucketSlotEditable.isWholeListRecorded = true;
4174
+ editableBucketSlot.isWholeListRecorded = true;
4107
4175
  }
4108
4176
  }
4109
4177
  };
4110
4178
  function enlistInFlush(bucketSlot) {
4111
- const bucketSlotEditable = bucketSlot;
4179
+ const editableBucketSlot = bucketSlot;
4112
4180
  const storeSlot = bucketSlot.storeSlot;
4113
4181
  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;
4182
+ const commands = editableBucketSlot.commands;
4183
+ const hasScript = commands !== void 0 && commands.length > 0 || editableBucketSlot.isWholeListRecorded;
4184
+ if (hasScript && !isScriptStale(channelSlot, editableBucketSlot)) return editableBucketSlot;
4117
4185
  if (hasScript) {
4118
- clearScript(bucketSlotEditable);
4186
+ clearScript(editableBucketSlot);
4119
4187
  } else {
4120
4188
  const commandsBucketSlotChannelQueue = storeSlot.commandsBucketSlotChannelQueue ?? (storeSlot.commandsBucketSlotChannelQueue = new OIMChannelQueue());
4121
4189
  if (commandsBucketSlotChannelQueue.getEntryCount() === 0) getCommandsStoreSlotChannelQueue(channelSlot).enqueueEntry(storeSlot);
4122
- commandsBucketSlotChannelQueue.enqueueEntry(bucketSlotEditable);
4190
+ commandsBucketSlotChannelQueue.enqueueEntry(editableBucketSlot);
4123
4191
  }
4124
4192
  const clock = channelSlot.clock;
4125
- bucketSlotEditable.commandsStartedAtRevision = clock.revision;
4126
- bucketSlotEditable.commandsStartedAtEpoch = clock.epoch;
4127
- return bucketSlotEditable;
4193
+ editableBucketSlot.commandsStartedAtRevision = clock.revision;
4194
+ editableBucketSlot.commandsStartedAtEpoch = clock.epoch;
4195
+ return editableBucketSlot;
4128
4196
  }
4129
4197
  function getCommandsStoreSlotChannelQueue(channelSlot) {
4130
4198
  const commandsStoreSlotChannelQueue = channelSlot.commandsStoreSlotChannelQueue;
@@ -4145,10 +4213,10 @@ function isScriptStale(channelSlot, bucketSlot) {
4145
4213
  bucketSlot.commandsStartedAtEpoch
4146
4214
  );
4147
4215
  }
4148
- function clearScript(bucketSlotEditable) {
4149
- const commands = bucketSlotEditable.commands;
4216
+ function clearScript(editableBucketSlot) {
4217
+ const commands = editableBucketSlot.commands;
4150
4218
  if (commands !== void 0 && commands.length !== 0) commands.length = 0;
4151
- bucketSlotEditable.isWholeListRecorded = false;
4219
+ editableBucketSlot.isWholeListRecorded = false;
4152
4220
  }
4153
4221
  function clearStaleScripts(channelSlot, commandsStoreSlotChannelQueue) {
4154
4222
  let keptStoreSlotCount = 0;
@@ -4157,12 +4225,12 @@ function clearStaleScripts(channelSlot, commandsStoreSlotChannelQueue) {
4157
4225
  const commandsBucketSlotChannelQueue = storeSlot.commandsBucketSlotChannelQueue;
4158
4226
  let keptBucketSlotCount = 0;
4159
4227
  for (let j = 0; j < commandsBucketSlotChannelQueue.getEntryCount(); j++) {
4160
- const bucketSlotEditable = commandsBucketSlotChannelQueue.getEntryAt(j);
4161
- if (!isScriptStale(channelSlot, bucketSlotEditable)) {
4162
- commandsBucketSlotChannelQueue.setEntryAt(keptBucketSlotCount++, bucketSlotEditable);
4228
+ const editableBucketSlot = commandsBucketSlotChannelQueue.getEntryAt(j);
4229
+ if (!isScriptStale(channelSlot, editableBucketSlot)) {
4230
+ commandsBucketSlotChannelQueue.setEntryAt(keptBucketSlotCount++, editableBucketSlot);
4163
4231
  continue;
4164
4232
  }
4165
- clearScript(bucketSlotEditable);
4233
+ clearScript(editableBucketSlot);
4166
4234
  }
4167
4235
  commandsBucketSlotChannelQueue.keepFirstEntries(keptBucketSlotCount);
4168
4236
  if (keptBucketSlotCount !== 0) commandsStoreSlotChannelQueue.setEntryAt(keptStoreSlotCount++, storeSlot);
@@ -4170,7 +4238,7 @@ function clearStaleScripts(channelSlot, commandsStoreSlotChannelQueue) {
4170
4238
  commandsStoreSlotChannelQueue.keepFirstEntries(keptStoreSlotCount);
4171
4239
  }
4172
4240
 
4173
- // src/engine/index/utils/createOIMIndexStoreSlot.ts
4241
+ // src/index/utils/createOIMIndexStoreSlot.ts
4174
4242
  function createOIMIndexStoreSlot(store, slotService, sourceStoreSlot, contentChangeListener) {
4175
4243
  return {
4176
4244
  ...createOIMStoreSlot(store, sourceStoreSlot.channelSlot, slotService),
@@ -4184,7 +4252,7 @@ function createOIMIndexStoreSlot(store, slotService, sourceStoreSlot, contentCha
4184
4252
  };
4185
4253
  }
4186
4254
 
4187
- // src/facade/index/OIMSlotCollectionIndexService.ts
4255
+ // src/index/OIMSlotCollectionIndexService.ts
4188
4256
  var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4189
4257
  constructor(options) {
4190
4258
  super(options);
@@ -4199,26 +4267,26 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4199
4267
  onContentChanged: (entitySlot, patch, changedColumns) => {
4200
4268
  this.updateIndexKeyForSlot(indexStoreSlot, entitySlot, patch, changedColumns);
4201
4269
  },
4202
- onContentChangedMany: (entitySlotChannelQueue, patchChannelQueue, changedColumnsChannelQueue) => {
4270
+ onManyContentsChanged: (entitySlotChannelQueue, patchChannelQueue, changedColumnsChannelQueue) => {
4203
4271
  this.updateIndexKeysForSlots(indexStoreSlot, entitySlotChannelQueue, patchChannelQueue, changedColumnsChannelQueue);
4204
4272
  }
4205
4273
  };
4206
- const indexStoreSlot = this.createStoreSlotWith((store) => createOIMIndexStoreSlot(store, this, sourceStoreSlot, contentChangeListener));
4274
+ const indexStoreSlot = this.createStoreSlotOverNewStore((store) => createOIMIndexStoreSlot(store, this, sourceStoreSlot, contentChangeListener));
4207
4275
  const indexKeysService = this.indexKeysService;
4208
4276
  const indexKeysPositions = sourceStoreSlot.indexKeysPositions ?? (sourceStoreSlot.indexKeysPositions = indexKeysService.createPositions());
4209
4277
  indexStoreSlot.indexKeysPosition = indexKeysService.allocatePosition(indexKeysPositions);
4210
- OIMContentChangeListenerService.INSTANCE.addContentChangeListener(sourceStoreSlot, contentChangeListener, this.keyColumns);
4278
+ OIMSlotContentChangeListenerService.INSTANCE.addContentChangeListener(sourceStoreSlot, contentChangeListener, this.keyColumns);
4211
4279
  return indexStoreSlot;
4212
4280
  }
4213
4281
  disposeIndexStoreSlot(indexStoreSlot) {
4214
4282
  this.assertNotDisposed(indexStoreSlot);
4215
4283
  OIMChannelService.INSTANCE.assertNotFlushing(indexStoreSlot.channelSlot);
4216
4284
  const sourceStoreSlot = indexStoreSlot.sourceStoreSlot;
4217
- OIMContentChangeListenerService.INSTANCE.removeContentChangeListener(sourceStoreSlot, indexStoreSlot.contentChangeListener);
4285
+ OIMSlotContentChangeListenerService.INSTANCE.removeContentChangeListener(sourceStoreSlot, indexStoreSlot.contentChangeListener);
4218
4286
  for (const bucketColumnName of indexStoreSlot.bucketColumnNames) {
4219
- OIMContentChangeListenerService.INSTANCE.removeReadColumn(sourceStoreSlot, bucketColumnName);
4287
+ OIMSlotContentChangeListenerService.INSTANCE.removeReadColumn(sourceStoreSlot, bucketColumnName);
4220
4288
  }
4221
- if (indexStoreSlot.isAnyBucketColumnRead) OIMContentChangeListenerService.INSTANCE.removeReadAnyColumn(sourceStoreSlot);
4289
+ if (indexStoreSlot.isAnyBucketColumnRead) OIMSlotContentChangeListenerService.INSTANCE.removeReadAnyColumn(sourceStoreSlot);
4222
4290
  const indexKeysPositions = sourceStoreSlot.indexKeysPositions;
4223
4291
  if (indexKeysPositions !== void 0) {
4224
4292
  this.indexKeysService.releasePosition(
@@ -4265,10 +4333,10 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4265
4333
  }
4266
4334
  walkSlotsByKeys(indexStoreSlot, keys, takeFoundSlot, slotByKeyDoor) {
4267
4335
  this.assertNotDisposed(indexStoreSlot);
4268
- const indexStoreSlotEditable = indexStoreSlot;
4336
+ const editableIndexStoreSlot = indexStoreSlot;
4269
4337
  const bucketSlots = [];
4270
4338
  let entitySlotsByMintedBucketSlot;
4271
- indexStoreSlotEditable.requestedKeys = keys;
4339
+ editableIndexStoreSlot.requestedKeys = keys;
4272
4340
  try {
4273
4341
  for (let i = 0; i < keys.length; i++) {
4274
4342
  const foundBucketSlot = this.findSlotByKey(indexStoreSlot, keys[i]);
@@ -4282,7 +4350,7 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4282
4350
  bucketSlots.push(bucketSlot);
4283
4351
  }
4284
4352
  } finally {
4285
- indexStoreSlotEditable.requestedKeys = void 0;
4353
+ editableIndexStoreSlot.requestedKeys = void 0;
4286
4354
  if (entitySlotsByMintedBucketSlot !== void 0) this.fillMintedBucketSlots(indexStoreSlot, entitySlotsByMintedBucketSlot);
4287
4355
  }
4288
4356
  return bucketSlots;
@@ -4314,18 +4382,14 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4314
4382
  const bucketColumnNames = indexStoreSlot.bucketColumnNames;
4315
4383
  if (bucketColumnNames.has(columnName)) return;
4316
4384
  bucketColumnNames.add(columnName);
4317
- OIMContentChangeListenerService.INSTANCE.addReadColumn(indexStoreSlot.sourceStoreSlot, columnName);
4385
+ OIMSlotContentChangeListenerService.INSTANCE.addReadColumn(indexStoreSlot.sourceStoreSlot, columnName);
4318
4386
  }
4319
4387
  onBucketColumnsChanged(_indexStoreSlot, _bucketSlot, _entitySlot, _changedColumns) {
4320
4388
  return;
4321
4389
  }
4322
4390
  onSlotMinted(indexStoreSlot, bucketSlot) {
4323
4391
  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
- );
4392
+ this.fillBucketSlotWithSourceSlots(indexStoreSlot, bucketSlot, this.collectSourceSlotsForKey(indexStoreSlot, bucketSlot.key));
4329
4393
  }
4330
4394
  assertNotDisposed(storeSlot) {
4331
4395
  if (!storeSlot.isDisposed) return;
@@ -4336,7 +4400,7 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4336
4400
  addAnyBucketColumnRead(indexStoreSlot) {
4337
4401
  if (indexStoreSlot.isAnyBucketColumnRead) return;
4338
4402
  indexStoreSlot.isAnyBucketColumnRead = true;
4339
- OIMContentChangeListenerService.INSTANCE.addReadAnyColumn(indexStoreSlot.sourceStoreSlot);
4403
+ OIMSlotContentChangeListenerService.INSTANCE.addReadAnyColumn(indexStoreSlot.sourceStoreSlot);
4340
4404
  }
4341
4405
  fillMintedBucketSlots(indexStoreSlot, entitySlotsByMintedBucketSlot) {
4342
4406
  for (const entitySlot of this.sourceSlotCollectionService.getSlots(indexStoreSlot.sourceStoreSlot)) {
@@ -4348,7 +4412,7 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4348
4412
  const slotContentService = this.slotContentBucketService;
4349
4413
  const slotOwnerService = this.slotOwnerService;
4350
4414
  for (const [bucketSlot, entitySlots] of entitySlotsByMintedBucketSlot) {
4351
- slotContentService.fillBucketMemberSlots(bucketSlot, this.setIndexKeyForSlots(indexStoreSlot, entitySlots, bucketSlot.key));
4415
+ this.fillBucketSlotWithSourceSlots(indexStoreSlot, bucketSlot, entitySlots);
4352
4416
  slotOwnerService.settleEmptiness(bucketSlot, slotContentService.isSlotEmpty(bucketSlot));
4353
4417
  }
4354
4418
  }
@@ -4488,40 +4552,42 @@ var OIMSlotCollectionIndexService = class extends OIMSlotCollectionService {
4488
4552
  }
4489
4553
  return matchingEntitySlots;
4490
4554
  }
4491
- setIndexKeyForSlots(indexStoreSlot, entitySlots, key) {
4555
+ fillBucketSlotWithSourceSlots(indexStoreSlot, bucketSlot, entitySlots) {
4492
4556
  const indexKeysService = this.indexKeysService;
4493
4557
  const indexKeysPosition = indexStoreSlot.indexKeysPosition;
4494
- const channelSlot = indexStoreSlot.channelSlot;
4495
- const isRefusingWrites = OIMChannelService.INSTANCE.isRefusingWrites(channelSlot);
4496
- let movableEntitySlots;
4558
+ const key = bucketSlot.key;
4559
+ const isRefusingWrites = OIMChannelService.INSTANCE.isRefusingWrites(indexStoreSlot.channelSlot);
4560
+ const fillingEntitySlots = [];
4561
+ const prevKeys = [];
4562
+ const movingEntitySlots = [];
4497
4563
  for (let i = 0; i < entitySlots.length; i++) {
4498
4564
  const entitySlot = entitySlots[i];
4499
4565
  const prevKey = indexKeysService.get(entitySlot, indexKeysPosition);
4500
4566
  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);
4567
+ if (isMoving && isRefusingWrites) continue;
4568
+ fillingEntitySlots.push(entitySlot);
4506
4569
  indexKeysService.set(entitySlot, indexKeysPosition, key);
4507
4570
  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);
4571
+ prevKeys.push(prevKey);
4572
+ movingEntitySlots.push(entitySlot);
4573
+ }
4574
+ this.slotContentBucketService.fillBucketMemberSlots(bucketSlot, fillingEntitySlots);
4575
+ for (let i = 0; i < movingEntitySlots.length; i++) {
4576
+ const prevBucketSlot = this.findSlotByKey(indexStoreSlot, prevKeys[i]);
4577
+ if (prevBucketSlot !== void 0) this.slotContentBucketService.removeBucketMemberSlot(prevBucketSlot, movingEntitySlots[i]);
4511
4578
  }
4512
- return movableEntitySlots ?? entitySlots;
4513
4579
  }
4514
4580
  };
4515
4581
  function takeNothing() {
4516
4582
  return;
4517
4583
  }
4518
4584
 
4519
- // src/facade/index/OIMSlotCollectionSortedArrayIndexService.ts
4585
+ // src/index/OIMSlotCollectionSortedArrayIndexService.ts
4520
4586
  var OIMSlotCollectionSortedArrayIndexService = class extends OIMSlotCollectionIndexService {
4521
4587
  constructor(options) {
4522
4588
  super(options);
4523
4589
  const sortColumnNames = /* @__PURE__ */ new Set();
4524
- for (let i = 0; i < options.sortColumns.length; i++) sortColumnNames.add(options.sortColumns[i].column);
4590
+ for (let i = 0; i < options.sortColumns.length; i++) sortColumnNames.add(options.sortColumns[i].columnName);
4525
4591
  this.sortColumnNames = sortColumnNames;
4526
4592
  }
4527
4593
  createIndexStoreSlot(sourceStoreSlot) {
@@ -4543,7 +4609,51 @@ var OIMSlotCollectionSortedArrayIndexService = class extends OIMSlotCollectionIn
4543
4609
  }
4544
4610
  };
4545
4611
 
4546
- // src/factories/utils/oimKeyOfColumns.ts
4612
+ // src/index/OIMIndexKeysService.ts
4613
+ var OIMIndexKeysService = class {
4614
+ createPositions() {
4615
+ return { nextPosition: 0, freePositions: [] };
4616
+ }
4617
+ get(slot, position) {
4618
+ const indexKeys = slot.indexKeys;
4619
+ return indexKeys === void 0 || position >= indexKeys.length ? void 0 : indexKeys[position];
4620
+ }
4621
+ set(slot, position, indexKey) {
4622
+ const indexKeys = slot.indexKeys;
4623
+ if (indexKeys !== void 0) {
4624
+ if (position < indexKeys.length) {
4625
+ indexKeys[position] = indexKey;
4626
+ return;
4627
+ }
4628
+ if (indexKey === void 0) return;
4629
+ while (indexKeys.length < position) indexKeys.push(void 0);
4630
+ indexKeys.push(indexKey);
4631
+ return;
4632
+ }
4633
+ if (indexKey === void 0) return;
4634
+ const created = [];
4635
+ while (created.length < position) created.push(void 0);
4636
+ created.push(indexKey);
4637
+ slot.indexKeys = created;
4638
+ }
4639
+ };
4640
+
4641
+ // src/index/OIMAppendingIndexKeysService.ts
4642
+ var _OIMAppendingIndexKeysService = class _OIMAppendingIndexKeysService extends OIMIndexKeysService {
4643
+ allocatePosition(positions) {
4644
+ return positions.nextPosition++;
4645
+ }
4646
+ releasePosition() {
4647
+ return;
4648
+ }
4649
+ };
4650
+ _OIMAppendingIndexKeysService.INSTANCE = new _OIMAppendingIndexKeysService();
4651
+ var OIMAppendingIndexKeysService = _OIMAppendingIndexKeysService;
4652
+
4653
+ // src/db/constants/OIM_DEFAULT_INDEX_KEYS_SERVICE.ts
4654
+ var OIM_DEFAULT_INDEX_KEYS_SERVICE = /* @__PURE__ */ new OIMDefaultValue(() => OIMAppendingIndexKeysService.INSTANCE);
4655
+
4656
+ // src/index/utils/oimKeyOfColumns.ts
4547
4657
  function oimKeyOfColumns(columns) {
4548
4658
  if (columns.length === 1) {
4549
4659
  const column = columns[0];
@@ -4556,47 +4666,47 @@ function oimKeyOfColumns(columns) {
4556
4666
  };
4557
4667
  }
4558
4668
 
4559
- // src/factories/utils/oimSlotCollectionIndexServiceOptionsWithDefault.ts
4560
- function oimSlotCollectionIndexServiceOptionsWithDefault(db, options, slotStoreService, slotContentService) {
4669
+ // src/index/utils/oimResolveSlotCollectionIndexServiceOptions.ts
4670
+ function oimResolveSlotCollectionIndexServiceOptions(defaults, options, slotStoreService, slotContentService) {
4561
4671
  return {
4562
- ...oimSlotOwnerOptionsWithDefault(db, options),
4672
+ ...oimResolveSlotOwnerServiceOptions(defaults, options),
4563
4673
  slotStoreService,
4564
4674
  slotContentService,
4565
- storeSlotListener: OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
4675
+ storeSlotListener: defaults.storeSlotListener ?? OIM_DEFAULT_STORE_SLOT_LISTENER.getValue(),
4566
4676
  keyOf: options.keyOf ?? oimKeyOfColumns(options.columns),
4567
4677
  columns: options.columns,
4568
4678
  sourceSlotCollectionService: options.entityService,
4569
- indexKeysService: db.indexKeysService ?? OIM_DEFAULT_INDEX_KEYS_SERVICE.getValue()
4679
+ indexKeysService: defaults.indexKeysService ?? OIM_DEFAULT_INDEX_KEYS_SERVICE.getValue()
4570
4680
  };
4571
4681
  }
4572
4682
 
4573
- // src/factories/createOIMSlotCollectionIndexService.ts
4574
- function createOIMSlotCollectionIndexService(db, options) {
4575
- return new OIMSlotCollectionIndexService(oimSlotCollectionIndexServiceOptionsWithDefault(
4576
- db,
4683
+ // src/index/createOIMSlotCollectionIndexService.ts
4684
+ function createOIMSlotCollectionIndexService(options) {
4685
+ return new OIMSlotCollectionIndexService(oimResolveSlotCollectionIndexServiceOptions(
4686
+ options.defaults ?? OIMDefaults.INSTANCE,
4577
4687
  options,
4578
- oimSlotStoreServiceWithDefault(options.bucketSlotStoreService),
4688
+ oimResolveSlotStoreService(options.bucketSlotStoreService),
4579
4689
  options.slotContentService ?? new OIMSlotContentPositionalArrayBucketService()
4580
4690
  ));
4581
4691
  }
4582
4692
 
4583
- // src/factories/createOIMSlotCollectionSortedArrayIndexService.ts
4584
- function createOIMSlotCollectionSortedArrayIndexService(db, options) {
4693
+ // src/index/createOIMSlotCollectionSortedArrayIndexService.ts
4694
+ function createOIMSlotCollectionSortedArrayIndexService(options) {
4585
4695
  const slotContentService = new OIMSlotContentSortedArrayBucketService({
4586
4696
  compareBucketMemberSlots: oimEntitySlotsComparator(oimColumnsComparator(options.sortColumns))
4587
4697
  });
4588
4698
  return new OIMSlotCollectionSortedArrayIndexService({
4589
- ...oimSlotCollectionIndexServiceOptionsWithDefault(
4590
- db,
4699
+ ...oimResolveSlotCollectionIndexServiceOptions(
4700
+ options.defaults ?? OIMDefaults.INSTANCE,
4591
4701
  options,
4592
- oimSlotStoreServiceWithDefault(options.bucketSlotStoreService),
4702
+ oimResolveSlotStoreService(options.bucketSlotStoreService),
4593
4703
  slotContentService
4594
4704
  ),
4595
4705
  sortColumns: options.sortColumns
4596
4706
  });
4597
4707
  }
4598
4708
 
4599
- // src/engine/index/OIMReclaimingIndexKeysService.ts
4709
+ // src/index/OIMReclaimingIndexKeysService.ts
4600
4710
  var OIMReclaimingIndexKeysService = class extends OIMIndexKeysService {
4601
4711
  allocatePosition(positions) {
4602
4712
  const freePosition = positions.freePositions.pop();
@@ -4611,18 +4721,18 @@ var OIMReclaimingIndexKeysService = class extends OIMIndexKeysService {
4611
4721
  }
4612
4722
  };
4613
4723
 
4614
- // src/engine/entity/utils/oimCopyEntity.ts
4724
+ // src/entity/utils/oimCopyEntity.ts
4615
4725
  function oimCopyEntity(entity) {
4616
4726
  return { ...entity };
4617
4727
  }
4618
4728
 
4619
- // src/factories/createOIMEntityWriterReplacing.ts
4729
+ // src/entity/createOIMReplacingEntityWriter.ts
4620
4730
  function storeReplacement(slot, next) {
4621
4731
  if (next === void 0) return false;
4622
4732
  slot.entity = next;
4623
4733
  return true;
4624
4734
  }
4625
- function deleteColumnsReplacing(slot, names) {
4735
+ function deleteColumnsInCopy(slot, names) {
4626
4736
  const deleted = oimOwnedColumnNames(slot, names);
4627
4737
  if (deleted === void 0) return OIM_FROZEN_EMPTY_COLUMN_NAMES;
4628
4738
  const next = oimCopyEntity(slot.entity);
@@ -4630,61 +4740,61 @@ function deleteColumnsReplacing(slot, names) {
4630
4740
  slot.entity = next;
4631
4741
  return deleted;
4632
4742
  }
4633
- function createOIMEntityWriterReplacing(options) {
4743
+ function createOIMReplacingEntityWriter(options) {
4634
4744
  const {
4635
4745
  sameValueGuard,
4636
4746
  entityInserter,
4637
4747
  putEntityColumns,
4638
4748
  patchEntityColumns,
4639
4749
  patchEntityColumn
4640
- } = oimEntityWriterOptionsWithDefault(options);
4750
+ } = oimResolveEntityWriterOptions(options);
4641
4751
  return {
4642
4752
  fillEntity: entityInserter,
4643
4753
  clearEntity: oimClearEntity,
4644
4754
  putEntity: (slot, entity, changedColumnNames) => storeReplacement(slot, putEntityColumns(slot, entity, sameValueGuard, changedColumnNames, oimCopyEntity)),
4645
4755
  patchEntity: (slot, patch, changedColumnNames) => storeReplacement(slot, patchEntityColumns(slot, patch, sameValueGuard, changedColumnNames, oimCopyEntity)),
4646
4756
  patchColumn: (slot, columnName, value, changedColumnNames) => storeReplacement(slot, patchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, oimCopyEntity)),
4647
- deleteColumns: deleteColumnsReplacing
4757
+ deleteColumns: deleteColumnsInCopy
4648
4758
  };
4649
4759
  }
4650
4760
 
4651
- // src/engine/entity/utils/oimInsertEntityWithCopy.ts
4761
+ // src/entity/utils/oimInsertEntityWithCopy.ts
4652
4762
  function oimInsertEntityWithCopy(slot, entity) {
4653
4763
  slot.entity = oimCopyEntity(entity);
4654
4764
  }
4655
4765
 
4656
- // src/engine/entity/utils/oimCopyEntitySanitized.ts
4657
- function oimCopyEntitySanitized(entity) {
4766
+ // src/entity/utils/oimSanitizedCopyEntity.ts
4767
+ function oimSanitizedCopyEntity(entity) {
4658
4768
  const copy = { ...entity };
4659
4769
  if (Object.hasOwn(copy, OIM_PROTO_KEY)) delete copy[OIM_PROTO_KEY];
4660
4770
  return copy;
4661
4771
  }
4662
4772
 
4663
- // src/engine/entity/utils/oimInsertEntityWithSanitizedCopy.ts
4773
+ // src/entity/utils/oimInsertEntityWithSanitizedCopy.ts
4664
4774
  function oimInsertEntityWithSanitizedCopy(slot, entity) {
4665
- slot.entity = oimCopyEntitySanitized(entity);
4775
+ slot.entity = oimSanitizedCopyEntity(entity);
4666
4776
  }
4667
4777
 
4668
- // src/engine/entity/utils/oimIsPlain.ts
4669
- function oimIsPlain(source) {
4778
+ // src/entity/utils/oimIsPlainObject.ts
4779
+ function oimIsPlainObject(source) {
4670
4780
  const proto = Object.getPrototypeOf(source);
4671
4781
  return proto === Object.prototype || proto === null;
4672
4782
  }
4673
4783
 
4674
- // src/engine/entity/utils/oimOwnEntityColumns.ts
4784
+ // src/entity/utils/oimOwnEntityColumns.ts
4675
4785
  function oimOwnEntityColumns(entity) {
4676
- if (oimIsPlain(entity) && !Object.hasOwn(entity, OIM_PROTO_KEY)) return entity;
4677
- return oimCopyEntitySanitized(entity);
4786
+ if (oimIsPlainObject(entity) && !Object.hasOwn(entity, OIM_PROTO_KEY)) return entity;
4787
+ return oimSanitizedCopyEntity(entity);
4678
4788
  }
4679
4789
 
4680
- // src/engine/entity/utils/oimPatchEntityColumnsGuarded.ts
4681
- var oimPatchEntityColumnsGuarded = (slot, patch, sameValueGuard, changedColumnNames, targetOf) => oimPatchEntityColumns(slot, oimOwnEntityColumns(patch), sameValueGuard, changedColumnNames, targetOf);
4790
+ // src/entity/utils/oimGuardedPatchEntityColumns.ts
4791
+ var oimGuardedPatchEntityColumns = (slot, patch, sameValueGuard, changedColumnNames, targetOf) => oimPatchEntityColumns(slot, oimOwnEntityColumns(patch), sameValueGuard, changedColumnNames, targetOf);
4682
4792
 
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);
4793
+ // src/entity/utils/oimGuardedPatchEntityColumn.ts
4794
+ var oimGuardedPatchEntityColumn = (slot, columnName, value, sameValueGuard, changedColumnNames, targetOf) => oimIsProtoKey(columnName) ? void 0 : oimPatchEntityColumn(slot, columnName, value, sameValueGuard, changedColumnNames, targetOf);
4685
4795
 
4686
- // src/engine/entity/utils/oimPutEntityColumnsGuarded.ts
4687
- var oimPutEntityColumnsGuarded = (slot, entity, sameValueGuard, changedColumnNames, targetOf) => {
4796
+ // src/entity/utils/oimGuardedPutEntityColumns.ts
4797
+ var oimGuardedPutEntityColumns = (slot, entity, sameValueGuard, changedColumnNames, targetOf) => {
4688
4798
  const prevEntity = slot.entity;
4689
4799
  if (prevEntity === void 0) return void 0;
4690
4800
  const ownColumns = oimOwnEntityColumns(entity);
@@ -4699,13 +4809,13 @@ var oimPutEntityColumnsGuarded = (slot, entity, sameValueGuard, changedColumnNam
4699
4809
  );
4700
4810
  };
4701
4811
 
4702
- // src/engine/collector/constants/OIM_SLICE_LENGTH_MS.ts
4812
+ // src/collector/constants/OIM_SLICE_LENGTH_MS.ts
4703
4813
  var OIM_SLICE_LENGTH_MS = 1024;
4704
4814
 
4705
- // src/engine/collector/utils/oimSliceOfMs.ts
4815
+ // src/collector/utils/oimSliceOfMs.ts
4706
4816
  var oimSliceOfMs = (ms) => Math.floor(ms / OIM_SLICE_LENGTH_MS);
4707
4817
 
4708
- // src/engine/collector/OIMSlotWheel.ts
4818
+ // src/collector/OIMSlotWheel.ts
4709
4819
  var OIMSlotWheel = class {
4710
4820
  constructor(options) {
4711
4821
  this.scheduledCallback = void 0;
@@ -4843,7 +4953,7 @@ var OIMSlotWheel = class {
4843
4953
  }
4844
4954
  };
4845
4955
 
4846
- // src/engine/collector/OIMSlotReleaseWheel.ts
4956
+ // src/collector/OIMSlotReleaseWheel.ts
4847
4957
  var OIMSlotReleaseWheel = class extends OIMSlotWheel {
4848
4958
  constructor(options) {
4849
4959
  super(options);
@@ -4904,20 +5014,20 @@ var OIMSlotReleaseWheel = class extends OIMSlotWheel {
4904
5014
  }
4905
5015
  };
4906
5016
 
4907
- // src/engine/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_WRITE.ts
5017
+ // src/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_WRITE.ts
4908
5018
  var OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_WRITE = 8;
4909
5019
 
4910
- // src/engine/slot/utils/oimGetReleaseDueAfterWriteMs.ts
5020
+ // src/slot/utils/oimGetReleaseDueAfterWriteMs.ts
4911
5021
  function oimGetReleaseDueAfterWriteMs(slot) {
4912
5022
  return slot.releaseDueAfterWriteMs;
4913
5023
  }
4914
5024
 
4915
- // src/engine/slot/utils/oimSetReleaseDueAfterWriteMs.ts
5025
+ // src/slot/utils/oimSetReleaseDueAfterWriteMs.ts
4916
5026
  function oimSetReleaseDueAfterWriteMs(slot, releaseDueMs) {
4917
5027
  slot.releaseDueAfterWriteMs = releaseDueMs;
4918
5028
  }
4919
5029
 
4920
- // src/engine/collector/utils/oimMintAfterWriteSlotReleaseWheel.ts
5030
+ // src/collector/utils/oimMintAfterWriteSlotReleaseWheel.ts
4921
5031
  function oimMintAfterWriteSlotReleaseWheel(collectorSlot) {
4922
5032
  return collectorSlot.afterWriteSlotReleaseWheel ?? (collectorSlot.afterWriteSlotReleaseWheel = new OIMSlotReleaseWheel({
4923
5033
  ...collectorSlot.slotWheelOptions,
@@ -4927,20 +5037,20 @@ function oimMintAfterWriteSlotReleaseWheel(collectorSlot) {
4927
5037
  }));
4928
5038
  }
4929
5039
 
4930
- // src/engine/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_IDLE.ts
5040
+ // src/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_IDLE.ts
4931
5041
  var OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_IDLE = 4;
4932
5042
 
4933
- // src/engine/slot/utils/oimGetReleaseDueAfterIdleMs.ts
5043
+ // src/slot/utils/oimGetReleaseDueAfterIdleMs.ts
4934
5044
  function oimGetReleaseDueAfterIdleMs(slot) {
4935
5045
  return slot.releaseDueAfterIdleMs;
4936
5046
  }
4937
5047
 
4938
- // src/engine/slot/utils/oimSetReleaseDueAfterIdleMs.ts
5048
+ // src/slot/utils/oimSetReleaseDueAfterIdleMs.ts
4939
5049
  function oimSetReleaseDueAfterIdleMs(slot, releaseDueMs) {
4940
5050
  slot.releaseDueAfterIdleMs = releaseDueMs;
4941
5051
  }
4942
5052
 
4943
- // src/engine/collector/utils/oimMintAfterIdleSlotReleaseWheel.ts
5053
+ // src/collector/utils/oimMintAfterIdleSlotReleaseWheel.ts
4944
5054
  function oimMintAfterIdleSlotReleaseWheel(collectorSlot) {
4945
5055
  return collectorSlot.afterIdleSlotReleaseWheel ?? (collectorSlot.afterIdleSlotReleaseWheel = new OIMSlotReleaseWheel({
4946
5056
  ...collectorSlot.slotWheelOptions,
@@ -4950,20 +5060,20 @@ function oimMintAfterIdleSlotReleaseWheel(collectorSlot) {
4950
5060
  }));
4951
5061
  }
4952
5062
 
4953
- // src/engine/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_UNHOLD.ts
5063
+ // src/collector/constants/OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_UNHOLD.ts
4954
5064
  var OIM_SLOT_FLAG_RELEASE_SCHEDULED_AFTER_UNHOLD = 16;
4955
5065
 
4956
- // src/engine/slot/utils/oimGetReleaseDueAfterUnholdMs.ts
5066
+ // src/slot/utils/oimGetReleaseDueAfterUnholdMs.ts
4957
5067
  function oimGetReleaseDueAfterUnholdMs(slot) {
4958
5068
  return slot.releaseDueAfterUnholdMs;
4959
5069
  }
4960
5070
 
4961
- // src/engine/slot/utils/oimSetReleaseDueAfterUnholdMs.ts
5071
+ // src/slot/utils/oimSetReleaseDueAfterUnholdMs.ts
4962
5072
  function oimSetReleaseDueAfterUnholdMs(slot, releaseDueMs) {
4963
5073
  slot.releaseDueAfterUnholdMs = releaseDueMs;
4964
5074
  }
4965
5075
 
4966
- // src/engine/collector/utils/oimMintAfterUnholdSlotReleaseWheel.ts
5076
+ // src/collector/utils/oimMintAfterUnholdSlotReleaseWheel.ts
4967
5077
  function oimMintAfterUnholdSlotReleaseWheel(collectorSlot) {
4968
5078
  return collectorSlot.afterUnholdSlotReleaseWheel ?? (collectorSlot.afterUnholdSlotReleaseWheel = new OIMSlotReleaseWheel({
4969
5079
  ...collectorSlot.slotWheelOptions,
@@ -4973,7 +5083,7 @@ function oimMintAfterUnholdSlotReleaseWheel(collectorSlot) {
4973
5083
  }));
4974
5084
  }
4975
5085
 
4976
- // src/engine/collector/OIMSlotRefetchWheel.ts
5086
+ // src/collector/OIMSlotRefetchWheel.ts
4977
5087
  var OIMSlotRefetchWheel = class extends OIMSlotWheel {
4978
5088
  constructor(options) {
4979
5089
  super({
@@ -5007,7 +5117,7 @@ var OIMSlotRefetchWheel = class extends OIMSlotWheel {
5007
5117
  }
5008
5118
  };
5009
5119
 
5010
- // src/engine/collector/OIMSlotReleaseAutoDueFramePolicy.ts
5120
+ // src/collector/OIMSlotReleaseAutoDueFramePolicy.ts
5011
5121
  var _OIMSlotReleaseAutoDueFramePolicy = class _OIMSlotReleaseAutoDueFramePolicy {
5012
5122
  isSlotReleaseDueFrameOpen() {
5013
5123
  return true;
@@ -5016,7 +5126,7 @@ var _OIMSlotReleaseAutoDueFramePolicy = class _OIMSlotReleaseAutoDueFramePolicy
5016
5126
  _OIMSlotReleaseAutoDueFramePolicy.INSTANCE = new _OIMSlotReleaseAutoDueFramePolicy();
5017
5127
  var OIMSlotReleaseAutoDueFramePolicy = _OIMSlotReleaseAutoDueFramePolicy;
5018
5128
 
5019
- // src/engine/collector/OIMSlotAfterWriteReleasePolicy.ts
5129
+ // src/collector/OIMSlotAfterWriteReleasePolicy.ts
5020
5130
  var OIMSlotAfterWriteReleasePolicy = class {
5021
5131
  constructor(options) {
5022
5132
  this.releasesWrittenSlots = true;
@@ -5045,7 +5155,7 @@ var OIMSlotAfterWriteReleasePolicy = class {
5045
5155
  }
5046
5156
  };
5047
5157
 
5048
- // src/engine/collector/OIMSlotReleaseManualDueFramePolicy.ts
5158
+ // src/collector/OIMSlotReleaseManualDueFramePolicy.ts
5049
5159
  var OIMSlotReleaseManualDueFramePolicy = class {
5050
5160
  constructor() {
5051
5161
  this.slotReleaseDueFrameDepth = 0;
@@ -5074,7 +5184,7 @@ var OIMSlotReleaseManualDueFramePolicy = class {
5074
5184
  }
5075
5185
  };
5076
5186
 
5077
- // src/engine/collector/OIMSlotAfterIdleReleasePolicy.ts
5187
+ // src/collector/OIMSlotAfterIdleReleasePolicy.ts
5078
5188
  var OIMSlotAfterIdleReleasePolicy = class {
5079
5189
  constructor(options) {
5080
5190
  this.releasesWrittenSlots = true;
@@ -5105,7 +5215,7 @@ var OIMSlotAfterIdleReleasePolicy = class {
5105
5215
  }
5106
5216
  };
5107
5217
 
5108
- // src/engine/collector/OIMSlotNeverReleasePolicy.ts
5218
+ // src/collector/OIMSlotNeverReleasePolicy.ts
5109
5219
  var _OIMSlotNeverReleasePolicy = class _OIMSlotNeverReleasePolicy {
5110
5220
  constructor() {
5111
5221
  this.releasesWrittenSlots = false;
@@ -5133,7 +5243,7 @@ var _OIMSlotNeverReleasePolicy = class _OIMSlotNeverReleasePolicy {
5133
5243
  _OIMSlotNeverReleasePolicy.INSTANCE = new _OIMSlotNeverReleasePolicy();
5134
5244
  var OIMSlotNeverReleasePolicy = _OIMSlotNeverReleasePolicy;
5135
5245
 
5136
- // src/engine/collector/OIMSlotAfterUnholdReleasePolicy.ts
5246
+ // src/collector/OIMSlotAfterUnholdReleasePolicy.ts
5137
5247
  var OIMSlotAfterUnholdReleasePolicy = class {
5138
5248
  constructor(options) {
5139
5249
  this.releasesWrittenSlots = true;
@@ -5160,7 +5270,7 @@ var OIMSlotAfterUnholdReleasePolicy = class {
5160
5270
  }
5161
5271
  };
5162
5272
 
5163
- // src/engine/collector/OIMSlotEarliestReleasePolicy.ts
5273
+ // src/collector/OIMSlotEarliestReleasePolicy.ts
5164
5274
  var askOnSlotIdle = (slotReleasePolicy, slot) => slotReleasePolicy.onSlotIdle(slot);
5165
5275
  var askIsSlotReleasable = (slotReleasePolicy, slot) => slotReleasePolicy.isSlotReleasable(slot);
5166
5276
  var askIsEmptySlotReleasable = (slotReleasePolicy, slot) => slotReleasePolicy.isEmptySlotReleasable(slot);
@@ -5207,13 +5317,13 @@ var OIMSlotEarliestReleasePolicy = class {
5207
5317
  }
5208
5318
  };
5209
5319
 
5210
- // src/engine/store/OIMSlotTreeStoreService.ts
5320
+ // src/store/OIMSlotTreeStoreService.ts
5211
5321
  var OIMSlotTreeStoreService = class {
5212
5322
  constructor(keyTreeWalk) {
5213
5323
  this.keyTreeWalk = keyTreeWalk;
5214
5324
  }
5215
5325
  createStore() {
5216
- return { root: { childNodes: void 0, atThisKey: void 0 }, slots: /* @__PURE__ */ new Set() };
5326
+ return { rootCompositeKeyNode: { childNodes: void 0, atThisKey: void 0 }, slots: /* @__PURE__ */ new Set() };
5217
5327
  }
5218
5328
  ownKey(compositeKey) {
5219
5329
  return compositeKey.slice();
@@ -5222,17 +5332,17 @@ var OIMSlotTreeStoreService = class {
5222
5332
  return oimSameKeySequence(compositeKey, otherCompositeKey);
5223
5333
  }
5224
5334
  get(slotStoreTree, compositeKey) {
5225
- return this.keyTreeWalk.nodeAt(slotStoreTree.root, compositeKey)?.atThisKey;
5335
+ return this.keyTreeWalk.nodeAt(slotStoreTree.rootCompositeKeyNode, compositeKey)?.atThisKey;
5226
5336
  }
5227
5337
  set(slotStoreTree, compositeKey, slot) {
5228
- const compositeKeyNode = this.keyTreeWalk.mintNodeAt(slotStoreTree.root, compositeKey);
5338
+ const compositeKeyNode = this.keyTreeWalk.mintNodeAt(slotStoreTree.rootCompositeKeyNode, compositeKey);
5229
5339
  const filedSlot = compositeKeyNode.atThisKey;
5230
5340
  if (filedSlot !== void 0 && filedSlot !== slot) slotStoreTree.slots.delete(filedSlot);
5231
5341
  compositeKeyNode.atThisKey = slot;
5232
5342
  slotStoreTree.slots.add(slot);
5233
5343
  }
5234
5344
  remove(slotStoreTree, compositeKey) {
5235
- const slot = this.keyTreeWalk.deleteKey(slotStoreTree.root, compositeKey);
5345
+ const slot = this.keyTreeWalk.deleteKey(slotStoreTree.rootCompositeKeyNode, compositeKey);
5236
5346
  if (slot !== void 0) slotStoreTree.slots.delete(slot);
5237
5347
  }
5238
5348
  fileSlot(slotStoreTree, slot) {
@@ -5249,10 +5359,100 @@ var OIMSlotTreeStoreService = class {
5249
5359
  }
5250
5360
  };
5251
5361
 
5252
- // src/engine/bucket/commands/constants/OIM_MAX_DIFF_SCRATCH_SLOTS.ts
5362
+ // src/key/OIMKeyTreeWalk.ts
5363
+ var OIMKeyTreeWalk = class {
5364
+ mintNodeAt(rootCompositeKeyNode, compositeKey) {
5365
+ if (compositeKey.length === 0) throw new Error("OIMKeyTreeWalk: an empty key is not a key.");
5366
+ let compositeKeyNode = rootCompositeKeyNode;
5367
+ let firstMintedDepth = -1;
5368
+ let parentOfFirstMintedCompositeKeyNode = rootCompositeKeyNode;
5369
+ for (let i = 0; i < compositeKey.length; i++) {
5370
+ const compositeKeyPart = compositeKey[i];
5371
+ let nextCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKeyPart);
5372
+ if (nextCompositeKeyNode === void 0) {
5373
+ try {
5374
+ this.holdCompositeKeyPart(compositeKeyPart);
5375
+ } catch (failure) {
5376
+ if (firstMintedDepth >= 0) {
5377
+ parentOfFirstMintedCompositeKeyNode.childNodes?.delete(compositeKey[firstMintedDepth]);
5378
+ for (let j = i - 1; j >= firstMintedDepth; j--) this.unholdCompositeKeyPart(compositeKey[j]);
5379
+ }
5380
+ throw failure;
5381
+ }
5382
+ nextCompositeKeyNode = { childNodes: void 0, atThisKey: void 0 };
5383
+ (compositeKeyNode.childNodes ?? (compositeKeyNode.childNodes = /* @__PURE__ */ new Map())).set(compositeKeyPart, nextCompositeKeyNode);
5384
+ if (firstMintedDepth < 0) {
5385
+ firstMintedDepth = i;
5386
+ parentOfFirstMintedCompositeKeyNode = compositeKeyNode;
5387
+ }
5388
+ }
5389
+ compositeKeyNode = nextCompositeKeyNode;
5390
+ }
5391
+ return compositeKeyNode;
5392
+ }
5393
+ nodeAt(rootCompositeKeyNode, compositeKey) {
5394
+ let compositeKeyNode = rootCompositeKeyNode;
5395
+ for (let i = 0; i < compositeKey.length; i++) {
5396
+ compositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[i]);
5397
+ if (compositeKeyNode === void 0) return void 0;
5398
+ }
5399
+ return compositeKeyNode;
5400
+ }
5401
+ deleteKey(rootCompositeKeyNode, compositeKey) {
5402
+ const lastDepth = compositeKey.length - 1;
5403
+ if (lastDepth < 0) return void 0;
5404
+ let compositeKeyNode = rootCompositeKeyNode;
5405
+ let keptCompositeKeyNode = rootCompositeKeyNode;
5406
+ let firstUnlinkedDepth = 0;
5407
+ for (let i = 0; i < lastDepth; i++) {
5408
+ const nextCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[i]);
5409
+ if (nextCompositeKeyNode === void 0) return void 0;
5410
+ compositeKeyNode = nextCompositeKeyNode;
5411
+ if (compositeKeyNode.atThisKey !== void 0 || (compositeKeyNode.childNodes?.size ?? 0) > 1) {
5412
+ keptCompositeKeyNode = compositeKeyNode;
5413
+ firstUnlinkedDepth = i + 1;
5414
+ }
5415
+ }
5416
+ const lastCompositeKeyNode = compositeKeyNode.childNodes?.get(compositeKey[lastDepth]);
5417
+ if (lastCompositeKeyNode === void 0) return void 0;
5418
+ const deletedAtKey = lastCompositeKeyNode.atThisKey;
5419
+ if (deletedAtKey === void 0) return void 0;
5420
+ lastCompositeKeyNode.atThisKey = void 0;
5421
+ if ((lastCompositeKeyNode.childNodes?.size ?? 0) > 0) return deletedAtKey;
5422
+ keptCompositeKeyNode.childNodes?.delete(compositeKey[firstUnlinkedDepth]);
5423
+ for (let i = lastDepth; i >= firstUnlinkedDepth; i--) this.unholdCompositeKeyPart(compositeKey[i]);
5424
+ return deletedAtKey;
5425
+ }
5426
+ };
5427
+
5428
+ // src/key/OIMCompositeKeyTreeWalk.ts
5429
+ var _OIMCompositeKeyTreeWalk = class _OIMCompositeKeyTreeWalk extends OIMKeyTreeWalk {
5430
+ holdCompositeKeyPart(entitySlot) {
5431
+ entitySlot.owner.holdSlot(entitySlot);
5432
+ }
5433
+ unholdCompositeKeyPart(entitySlot) {
5434
+ oimUnholdSlotIfAlive(entitySlot);
5435
+ }
5436
+ };
5437
+ _OIMCompositeKeyTreeWalk.INSTANCE = new _OIMCompositeKeyTreeWalk();
5438
+ var OIMCompositeKeyTreeWalk = _OIMCompositeKeyTreeWalk;
5439
+
5440
+ // src/key/OIMScalarKeyTreeWalk.ts
5441
+ var _OIMScalarKeyTreeWalk = class _OIMScalarKeyTreeWalk extends OIMKeyTreeWalk {
5442
+ holdCompositeKeyPart() {
5443
+ return;
5444
+ }
5445
+ unholdCompositeKeyPart() {
5446
+ return;
5447
+ }
5448
+ };
5449
+ _OIMScalarKeyTreeWalk.INSTANCE = new _OIMScalarKeyTreeWalk();
5450
+ var OIMScalarKeyTreeWalk = _OIMScalarKeyTreeWalk;
5451
+
5452
+ // src/bucket/commands/constants/OIM_MAX_DIFF_SCRATCH_SLOTS.ts
5253
5453
  var OIM_MAX_DIFF_SCRATCH_SLOTS = 4096;
5254
5454
 
5255
- // src/engine/bucket/commands/utils/oimOrderedListCommandsOfTransition.ts
5455
+ // src/bucket/commands/utils/oimOrderedListCommandsOfTransition.ts
5256
5456
  var indexInNext = /* @__PURE__ */ new Map();
5257
5457
  var occurrenceAfter = new Int32Array(0);
5258
5458
  var removedPrevIndices = new Int32Array(0);
@@ -5365,7 +5565,6 @@ oimRegisterCoreInstance(OIMDB);
5365
5565
  OIMCompositeKeyTreeWalk,
5366
5566
  OIMComputedService,
5367
5567
  OIMComputedValueService,
5368
- OIMContentChangeListenerService,
5369
5568
  OIMDB,
5370
5569
  OIMDefaultValue,
5371
5570
  OIMDefaults,
@@ -5382,6 +5581,7 @@ oimRegisterCoreInstance(OIMDB);
5382
5581
  OIMSingleComputedService,
5383
5582
  OIMSingleSlotService,
5384
5583
  OIMSingleSlotStoreService,
5584
+ OIMSingleSourceTrackingComputedService,
5385
5585
  OIMSlotAfterIdleReleasePolicy,
5386
5586
  OIMSlotAfterUnholdReleasePolicy,
5387
5587
  OIMSlotAfterWriteReleasePolicy,
@@ -5392,6 +5592,7 @@ oimRegisterCoreInstance(OIMDB);
5392
5592
  OIMSlotCollectionSortedArrayIndexService,
5393
5593
  OIMSlotContentArrayBucketService,
5394
5594
  OIMSlotContentBucketService,
5595
+ OIMSlotContentChangeListenerService,
5395
5596
  OIMSlotContentEntityService,
5396
5597
  OIMSlotContentPositionalArrayBucketService,
5397
5598
  OIMSlotContentSetBucketService,
@@ -5407,6 +5608,7 @@ oimRegisterCoreInstance(OIMDB);
5407
5608
  OIMSlotTreeStoreService,
5408
5609
  OIMSlotWheel,
5409
5610
  OIMSortedComputedService,
5611
+ OIMSourceTrackingComputedService,
5410
5612
  OIMThrowAtOnceErrorPolicy,
5411
5613
  OIMUnusedSlotCollectorService,
5412
5614
  OIMWritableSingleSlotService,
@@ -5420,17 +5622,22 @@ oimRegisterCoreInstance(OIMDB);
5420
5622
  createOIMChannelSlot,
5421
5623
  createOIMCollectorSlot,
5422
5624
  createOIMComputedService,
5423
- createOIMEntityWriterInPlace,
5424
- createOIMEntityWriterReplacing,
5625
+ createOIMInPlaceEntityWriter,
5626
+ createOIMReplacingEntityWriter,
5425
5627
  createOIMSingleComputedService,
5426
5628
  createOIMSingleSlotService,
5629
+ createOIMSingleSourceTrackingComputedService,
5427
5630
  createOIMSlotCollectionIndexService,
5428
5631
  createOIMSlotCollectionService,
5429
5632
  createOIMSlotCollectionSortedArrayIndexService,
5430
5633
  createOIMSlotContentEntityService,
5431
5634
  createOIMSortedComputedService,
5635
+ createOIMSourceTrackingComputedService,
5432
5636
  createOIMUnusedSlotCollectorSlot,
5433
5637
  oimColumnsComparator,
5638
+ oimGuardedPatchEntityColumn,
5639
+ oimGuardedPatchEntityColumns,
5640
+ oimGuardedPutEntityColumns,
5434
5641
  oimHoldSlots,
5435
5642
  oimInsertEntityWithCopy,
5436
5643
  oimInsertEntityWithSanitizedCopy,
@@ -5443,11 +5650,8 @@ oimRegisterCoreInstance(OIMDB);
5443
5650
  oimMintAfterWriteSlotReleaseWheel,
5444
5651
  oimOrderedListCommandsOfTransition,
5445
5652
  oimPatchEntityColumn,
5446
- oimPatchEntityColumnGuarded,
5447
5653
  oimPatchEntityColumns,
5448
- oimPatchEntityColumnsGuarded,
5449
5654
  oimPutEntityColumns,
5450
- oimPutEntityColumnsGuarded,
5451
5655
  oimRefreshSourceComputeds,
5452
5656
  oimSameKeySequence,
5453
5657
  oimSameSlotSequence,