@oimdb/core 3.10.0 → 3.11.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.d.ts CHANGED
@@ -90,9 +90,9 @@ declare class OIMEventEmitter<T extends Record<string, unknown>> {
90
90
 
91
91
  /**
92
92
  * Payload for index update events containing the keys that were modified */
93
- interface TOIMIndexUpdatePayload<TKey> {
93
+ type TOIMIndexUpdatePayload<TKey> = {
94
94
  keys: readonly TKey[];
95
- }
95
+ };
96
96
 
97
97
  /**
98
98
  * Comparator function for index primary key arrays.
@@ -297,6 +297,19 @@ declare abstract class OIMEventQueueScheduler {
297
297
  * Trigger a flush event. Should be called by subclasses when they execute the scheduled flush.
298
298
  */
299
299
  protected flush(): void;
300
+ /**
301
+ * Detach a Node timer handle from the event loop, returning it unchanged.
302
+ *
303
+ * A pending flush must never be a reason for a process to stay alive: if
304
+ * nothing else is running there is no UI left to update, and the flush is
305
+ * moot. Without this a scheduled-but-not-yet-run flush keeps Node awake —
306
+ * which is why a test suite that leaves a queue scheduled reports
307
+ * "a worker process has failed to exit gracefully".
308
+ *
309
+ * In the browser `setTimeout` returns a number, which has no `unref`, so the
310
+ * call is guarded and the handle passes straight through.
311
+ */
312
+ protected unref<THandle>(handle: THandle): THandle;
300
313
  }
301
314
 
302
315
  declare abstract class OIMIndexSetBased<TKey extends TOIMKey, TPk extends TOIMKey> extends OIMIndex<TKey, TPk, Set<TOIMAnyEntitySlot<TPk>>> {
@@ -430,10 +443,14 @@ declare class OIMEventQueue {
430
443
  cancel(fn: () => void): void;
431
444
  get isInFlush(): boolean;
432
445
  /**
433
- * Execute all pending tasks.
446
+ * Execute the tasks pending at the moment the flush starts — a single pass,
447
+ * not a drain-to-empty.
434
448
  *
435
- * This flush drains until the queue is empty. If tasks enqueue more tasks, they will be
436
- * executed within the same flush.
449
+ * The pending set is swapped out for an empty spare up front and the flush
450
+ * iterates that captured set. Tasks enqueued during the flush land in the
451
+ * fresh set and run on the NEXT flush, not this one. (Contrast
452
+ * `OIMComputeRuntime.flush()`, which re-reads its bucket per level and so
453
+ * does drain same-level tasks scheduled mid-flush.)
437
454
  */
438
455
  flush(): void;
439
456
  /**
@@ -492,6 +509,8 @@ declare class OIMCarrierKeyedEmitter<TKey extends TOIMKey, TCarrier extends IOIM
492
509
  private readonly subscribedCarriers;
493
510
  private dirtyCarriers;
494
511
  private isFlushEnqueued;
512
+ private multiCarrierSubscriptions;
513
+ private deliveredPool?;
495
514
  constructor(queue: OIMEventQueue, carrierProvider: IOIMCarrierProvider<TKey, TCarrier>);
496
515
  subscribeOnKey(key: TKey, handler: TOIMEventHandler<void>): () => void;
497
516
  subscribeOnKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): () => void;
@@ -787,7 +806,6 @@ declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMKey>
787
806
  protected readonly updateEmitter: OIMCarrierKeyedEmitter<TPk, TOIMEntitySlot<TEntity, TPk>>;
788
807
  private readonly anyUpdateHandlers;
789
808
  private readonly pendingAnyUpdatePks;
790
- private isAnyUpdateClearPending;
791
809
  private isAnyUpdateScheduled;
792
810
  constructor(queue: OIMEventQueue, opts?: TOIMCollectionOptions<TEntity, TPk>);
793
811
  subscribeOnKey(pk: TPk, handler: TOIMEventHandler<void>): () => void;
@@ -804,8 +822,8 @@ declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMKey>
804
822
  queueLength: number;
805
823
  };
806
824
  subscribeOnAnyUpdate(handler: (pks: readonly TPk[]) => void): () => void;
807
- private notifyLegacy;
808
- private notifyLegacyMany;
825
+ private notifyBatch;
826
+ private notifyBatchMany;
809
827
  upsertOneByPk(pk: TPk, entity: Partial<TEntity>): TOIMEntitySlot<TEntity, TPk>;
810
828
  upsertOne(entity: TEntity | Partial<TEntity>): TOIMEntitySlot<TEntity, TPk>;
811
829
  upsertMany(entities: (TEntity | Partial<TEntity>)[]): TOIMEntitySlot<TEntity, TPk>[];
@@ -816,7 +834,6 @@ declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMKey>
816
834
  clear(): void;
817
835
  private trackAnyUpdatePk;
818
836
  private trackAnyUpdatePks;
819
- private trackAnyUpdateClear;
820
837
  private ensureAnyUpdateEnqueued;
821
838
  private readonly runAnyUpdate;
822
839
  destroy(): void;
@@ -1151,6 +1168,7 @@ declare abstract class OIMOrderedListCommandBuffer<TKey extends TOIMKey, TItem>
1151
1168
  readonly commandsEventEmitter: OIMUpdateEventEmitter<TKey>;
1152
1169
  private readonly unsubscribeAfterFlush;
1153
1170
  protected readonly commandsByKey: Map<TKey, TOIMOrderedListCommand<TItem>[]>;
1171
+ private readonly staleResetKeys;
1154
1172
  constructor(queue: OIMEventQueue);
1155
1173
  /** Current ordered items for `key` (the driver's backing order). */
1156
1174
  abstract getItemsByKey(key: TKey): readonly TItem[];
@@ -1159,6 +1177,13 @@ declare abstract class OIMOrderedListCommandBuffer<TKey extends TOIMKey, TItem>
1159
1177
  consumeCommands(key: TKey): TOIMOrderedListCommand<TItem>[];
1160
1178
  destroy(): void;
1161
1179
  private readonly onAfterFlush;
1180
+ /**
1181
+ * Rebuild a deferred leading `reset` from the current order, once, at read
1182
+ * time. All the post-reset edits that were folded in are already reflected
1183
+ * in the driver's backing order, so a single rebuild here is equivalent to
1184
+ * having recomputed the reset on each of those edits.
1185
+ */
1186
+ private materializeStaleReset;
1162
1187
  protected appendCommand(key: TKey, cmd: TOIMOrderedListCommand<TItem>): void;
1163
1188
  protected appendResetCommand(key: TKey, items: readonly TItem[]): void;
1164
1189
  protected createResetCommand(items: readonly TItem[]): TOIMOrderedListCommand<TItem>;
@@ -1741,6 +1766,45 @@ declare class OIMCollectionIndexFactory<TEntity extends object, TPk extends TOIM
1741
1766
  }
1742
1767
  declare function createOIMCollectionIndexFactory<TEntity extends object, TPk extends TOIMKey>(queue: OIMEventQueue, collection: OIMReactiveCollection<TEntity, TPk>): OIMCollectionIndexFactory<TEntity, TPk>;
1743
1768
 
1769
+ type TOIMDerivedCollectionOptions<TDerived extends object, TPk extends TOIMKey> = {
1770
+ /**
1771
+ * Skip a downstream update when a source change leaves the re-derived entity
1772
+ * equal. Default `Object.is` (a fresh object each derive → always different,
1773
+ * so it propagates every source change; pass a shallow/field compare to
1774
+ * memoize finer).
1775
+ */
1776
+ compare?: (a: TDerived, b: TDerived) => boolean;
1777
+ /** Custom store — pass a trie-driven store when the source PK is composite. */
1778
+ store?: OIMCollectionStore<TDerived, TPk>;
1779
+ /** Build from the source's current contents at construction (default true). */
1780
+ buildInitial?: boolean;
1781
+ };
1782
+ /**
1783
+ * A reactive collection whose entities are derived one-to-one from a source
1784
+ * collection: `derived[pk] = derive(source[pk])`, keyed by the SOURCE pk. It
1785
+ * listens to the source and keeps itself in sync — add / update / remove.
1786
+ *
1787
+ * It is a first-class `OIMReactiveCollection`, so it can be indexed, selected,
1788
+ * and derived-from again (join → join). Maintenance runs on the source's
1789
+ * synchronous UPDATE channel, so a chain of derivations stays consistent within
1790
+ * the same flush; delivery to keyed subscribers is batched on flush as usual.
1791
+ *
1792
+ * Parallels `OIMDerivedCollectionIndex*`: the source stays the single source of
1793
+ * truth, and this needs no compute runtime — it is driven purely by the source's
1794
+ * update events.
1795
+ */
1796
+ declare class OIMDerivedCollection<TSource extends object, TDerived extends object, TPk extends TOIMKey> extends OIMReactiveCollection<TDerived, TPk> {
1797
+ private readonly source;
1798
+ private readonly derive;
1799
+ private readonly compareDerived;
1800
+ private readonly unsubscribeFromSource;
1801
+ constructor(queue: OIMEventQueue, source: OIMReactiveCollection<TSource, TPk>, derive: (entity: TSource, pk: TPk) => TDerived, opts?: TOIMDerivedCollectionOptions<TDerived, TPk>);
1802
+ rebuildFromSource(): void;
1803
+ destroy(): void;
1804
+ private readonly onSourceUpdate;
1805
+ private syncPk;
1806
+ }
1807
+
1744
1808
  /**
1745
1809
  * Payload type for update events that contain keys */
1746
1810
  type TOIMUpdatePayload<TKey> = {
@@ -2301,9 +2365,18 @@ declare class OIMPkSelectorFactory<TEntity extends object, TPk extends TOIMKey>
2301
2365
  }, TPk>;
2302
2366
  }
2303
2367
 
2368
+ interface IOIMEffectDependency {
2369
+ subscribe(onUpdate: () => void): () => void;
2370
+ }
2371
+
2304
2372
  /**
2305
2373
  * Computative runtime that schedules derived computations by levels and runs them
2306
2374
  * on `queue.flush()` boundary (AFTER_FLUSH).
2375
+ *
2376
+ * Buckets are held in an array indexed by topological level (levels are dense
2377
+ * small non-negative ints), not a `Map` — so the hot schedule/drain path indexes
2378
+ * directly with no hashing. The per-level `Set`s are POOLED: kept in their slot
2379
+ * and `.clear()`ed between flushes rather than re-allocated.
2307
2380
  */
2308
2381
  declare class OIMComputeRuntime {
2309
2382
  readonly queue: OIMEventQueue;
@@ -2313,7 +2386,36 @@ declare class OIMComputeRuntime {
2313
2386
  private maxLevel;
2314
2387
  private readonly dirtyByLevel;
2315
2388
  private readonly afterFlushTasks;
2389
+ private readonly levelByComputed;
2390
+ private readonly unsubscribeFromQueue;
2391
+ private _isDestroyed;
2316
2392
  constructor(queue: OIMEventQueue);
2393
+ /**
2394
+ * Whether {@link destroy} has run. A destroyed runtime is detached from its
2395
+ * queue and must not be reused — `getOIMComputeRuntime` reads this to hand
2396
+ * out a fresh runtime instead of a dead one.
2397
+ */
2398
+ get isDestroyed(): boolean;
2399
+ /**
2400
+ * Detach from the queue and drop everything pending.
2401
+ *
2402
+ * Without this the AFTER_FLUSH subscription lives as long as the queue does,
2403
+ * even once every computed / effect on this runtime is gone — harmless (the
2404
+ * handler early-returns) but impossible to unwind. Destroying does NOT
2405
+ * destroy the nodes scheduled on it; destroy them first, then the runtime.
2406
+ * Idempotent.
2407
+ */
2408
+ destroy(): void;
2409
+ /**
2410
+ * Topological depth for a node with these dependencies: one above the deepest
2411
+ * computed dependency (source-only → 0). The engine owns this — callers pass
2412
+ * their dependencies and get back a level, they never compute it themselves.
2413
+ */
2414
+ computeLevel(deps: readonly IOIMEffectDependency[]): number;
2415
+ /** Record a computed's depth so its dependents can look it up. */
2416
+ registerLevel(computed: object, level: number): void;
2417
+ /** The recorded topological depth of a computed (0 if unknown). Introspection. */
2418
+ getLevel(computed: object): number;
2317
2419
  /**
2318
2420
  * Schedule a one-shot task to run on the next `queue.flush()` (AFTER_FLUSH),
2319
2421
  * ordered by `level` ascending.
@@ -2325,6 +2427,7 @@ declare class OIMComputeRuntime {
2325
2427
  */
2326
2428
  scheduleAfterFlush(task: () => void): () => void;
2327
2429
  private flush;
2430
+ private recomputePendingRange;
2328
2431
  }
2329
2432
 
2330
2433
  interface IOIMSelectorComputedDependency {
@@ -2393,12 +2496,160 @@ declare class OIMCollectionSelectors<TEntity extends object, TPk extends TOIMKey
2393
2496
  entitiesBySetGlobalIndex<TIndex extends OIMGlobalIndexSetBased<TPk>>(index: OIMReactiveGlobalIndexSetBased<TPk, TIndex>): TOIMCollectionEntitiesSelector<TEntity>;
2394
2497
  }
2395
2498
 
2499
+ type TOIMComputedOptions<TValue> = {
2500
+ compute: () => TValue;
2501
+ deps?: readonly IOIMEffectDependency[];
2502
+ compare?: (a: TValue, b: TValue) => boolean;
2503
+ };
2504
+
2505
+ type TOIMComputedUpdatePayload<TKey extends TOIMKey> = {
2506
+ keys: readonly TKey[];
2507
+ };
2508
+
2509
+ type TOIMComputedKey$2 = 'value';
2510
+ declare class OIMComputed<TValue> {
2511
+ readonly emitter: OIMEventEmitter<{
2512
+ update: TOIMComputedUpdatePayload<TOIMComputedKey$2>;
2513
+ }>;
2514
+ readonly updateEventEmitter: OIMUpdateEventEmitter<TOIMComputedKey$2>;
2515
+ private readonly runtime;
2516
+ private readonly compute;
2517
+ private readonly compare;
2518
+ private readonly _deps;
2519
+ private value;
2520
+ private hasValue;
2521
+ private isDirty;
2522
+ private readonly effect;
2523
+ constructor(runtime: OIMComputeRuntime, opts: TOIMComputedOptions<TValue>);
2524
+ get needsRecompute(): boolean;
2525
+ get isReady(): boolean;
2526
+ get deps(): readonly IOIMEffectDependency[];
2527
+ get(): TValue;
2528
+ getIfReady(): TValue | undefined;
2529
+ destroy(): void;
2530
+ private recomputeAndEmitIfChanged;
2531
+ }
2532
+
2533
+ declare class OIMEffectDependencyKeyedCollection<TEntity extends object, TPk extends TOIMKey> implements IOIMEffectDependency {
2534
+ private readonly dep;
2535
+ constructor(collection: OIMReactiveCollection<TEntity, TPk>, pk: TPk);
2536
+ get source(): OIMReactiveCollection<TEntity, TPk>;
2537
+ subscribe(onUpdate: () => void): () => void;
2538
+ }
2539
+
2540
+ declare class OIMEffectDependencyKeyedIndex<TKey extends TOIMKey> implements IOIMEffectDependency {
2541
+ private readonly dep;
2542
+ constructor(index: IOIMKeyedSubscription<TKey>, key: TKey);
2543
+ get source(): IOIMKeyedSubscription<TKey>;
2544
+ subscribe(onUpdate: () => void): () => void;
2545
+ }
2546
+
2547
+ declare class OIMEffectDependencyKeyedObject<TKey extends string, TValue> implements IOIMEffectDependency {
2548
+ private readonly dep;
2549
+ constructor(object: OIMReactiveObject<TKey, TValue>, key: TKey);
2550
+ get source(): OIMReactiveObject<TKey, TValue>;
2551
+ subscribe(onUpdate: () => void): () => void;
2552
+ }
2553
+
2554
+ type TOIMComputedKey$1 = 'value';
2555
+ type TOIMComputedLike = {
2556
+ emitter: OIMEventEmitter<{
2557
+ update: TOIMComputedUpdatePayload<TOIMComputedKey$1>;
2558
+ }>;
2559
+ updateEventEmitter: OIMUpdateEventEmitter<TOIMComputedKey$1>;
2560
+ };
2561
+ /**
2562
+ * Effect dependency on a computed. Carries the computed itself (`source`) so the
2563
+ * runtime can look up its topological depth — the level lives in the runtime,
2564
+ * not on this dependency.
2565
+ */
2566
+ declare class OIMEffectDependencyComputed implements IOIMEffectDependency {
2567
+ readonly source: TOIMComputedLike;
2568
+ constructor(source: TOIMComputedLike);
2569
+ subscribe(onUpdate: () => void): () => void;
2570
+ }
2571
+
2572
+ /**
2573
+ * Dependency builders for `computed` / `effect`. They pick the right wrapper for
2574
+ * each source type so you never instantiate `OIMEffectDependency…` by hand:
2575
+ *
2576
+ * ```ts
2577
+ * kit.computed(
2578
+ * [on.collection(users, 'u1'), on.index(byRole, 'admin'), on.computed(orderCount)],
2579
+ * () => …,
2580
+ * );
2581
+ * ```
2582
+ */
2583
+ declare const on: {
2584
+ /** Depend on one PK of a collection. */
2585
+ collection: <TEntity extends object, TPk extends TOIMKey>(collection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => OIMEffectDependencyKeyedCollection<TEntity, TPk>;
2586
+ /** Depend on one key of an index. */
2587
+ index: <TKey extends TOIMKey>(index: IOIMKeyedSubscription<TKey>, key: TKey) => OIMEffectDependencyKeyedIndex<TKey>;
2588
+ /** Depend on one key of a reactive object. */
2589
+ object: <TKey extends string, TValue>(object: OIMReactiveObject<TKey, TValue>, key: TKey) => OIMEffectDependencyKeyedObject<TKey, TValue>;
2590
+ /** Depend on another computed. */
2591
+ computed: <TValue>(computed: OIMComputed<TValue>) => OIMEffectDependencyComputed;
2592
+ };
2593
+
2594
+ type TOIMEffectOptions = {
2595
+ deps?: readonly IOIMEffectDependency[];
2596
+ onUpdate?: () => void;
2597
+ run: () => void;
2598
+ };
2599
+
2600
+ declare class OIMEffect {
2601
+ private readonly runtime;
2602
+ private readonly onUpdate?;
2603
+ private readonly run;
2604
+ private readonly deps;
2605
+ /**
2606
+ * Topological depth, owned by the runtime — one above the deepest computed
2607
+ * dependency (source-only effects are `0`). Passed to `runtime.schedule` so
2608
+ * this node runs only after everything it depends on. Internal: nodes never
2609
+ * expose their own level.
2610
+ */
2611
+ private readonly level;
2612
+ private readonly sourceDeps;
2613
+ private readonly computedDeps;
2614
+ private sourceUnsubscribers;
2615
+ private computedUnsubscribers;
2616
+ private dequeueResubscribe?;
2617
+ private isResubscribeEnqueued;
2618
+ private isTemporarilyUnsubscribedForFlush;
2619
+ private isScheduled;
2620
+ private dequeueScheduled?;
2621
+ private readonly runTask;
2622
+ constructor(runtime: OIMComputeRuntime, opts: TOIMEffectOptions, level?: number);
2623
+ destroy(): void;
2624
+ private onSourceInvalidate;
2625
+ private onComputedInvalidate;
2626
+ private runOnce;
2627
+ private subscribeToDeps;
2628
+ private unsubscribeFromSourceDeps;
2629
+ private unsubscribeFromAllDeps;
2630
+ private ensureResubscribeAfterFlush;
2631
+ private readonly onAfterFlush;
2632
+ }
2633
+
2396
2634
  type TOIMReactiveCollectionFactoryOptions<TEntity extends object, TPk extends TOIMKey> = TOIMCollectionOptions<TEntity, TPk>;
2397
2635
  type TOIMCollectionKit<TEntity extends object, TPk extends TOIMKey> = {
2398
2636
  queue: OIMEventQueue;
2399
2637
  collection: OIMReactiveCollection<TEntity, TPk>;
2400
2638
  indexFactory: OIMCollectionIndexFactory<TEntity, TPk>;
2401
2639
  select: OIMCollectionSelectors<TEntity, TPk>;
2640
+ /** Dependency builders for `computed` / `effect` (no manual wrapper classes). */
2641
+ on: typeof on;
2642
+ /**
2643
+ * Create a computed on the queue's shared runtime and add it to `scope`.
2644
+ * Deps come from `on.*` and may reference any source sharing the queue.
2645
+ */
2646
+ computed: <TValue>(deps: readonly IOIMEffectDependency[], compute: () => TValue, options?: {
2647
+ compare?: (a: TValue, b: TValue) => boolean;
2648
+ }) => OIMComputed<TValue>;
2649
+ /** Create an effect on the queue's shared runtime and add it to `scope`. */
2650
+ effect: (deps: readonly IOIMEffectDependency[], run: () => void, options?: {
2651
+ onUpdate?: () => void;
2652
+ }) => OIMEffect;
2402
2653
  /**
2403
2654
  * Dispose scope owning the kit's collection. `add()` indexes/streams/
2404
2655
  * subscriptions you create off the kit, then `destroy()` tears them all down
@@ -2412,6 +2663,51 @@ type TOIMCollectionKit<TEntity extends object, TPk extends TOIMKey> = {
2412
2663
 
2413
2664
  declare function createOIMCollectionKit<TEntity extends object, TPk extends TOIMKey>(queue: OIMEventQueue, opts?: TOIMReactiveCollectionFactoryOptions<TEntity, TPk>): TOIMCollectionKit<TEntity, TPk>;
2414
2665
 
2666
+ /**
2667
+ * The ONE compute runtime for a queue. Every computed / effect / selector that
2668
+ * shares a queue must share a runtime — they form one dependency graph, and
2669
+ * levels + scheduling live per-runtime. Created lazily on first use and cached
2670
+ * (per queue, garbage-collected with it), so cross-collection computeds all
2671
+ * schedule on the same topological pass.
2672
+ *
2673
+ * A runtime that was destroyed is replaced rather than handed back: it is
2674
+ * detached from the queue and would never drain again.
2675
+ *
2676
+ * See `peekOIMComputeRuntime` to read without creating, and
2677
+ * `setOIMComputeRuntime` to install your own.
2678
+ */
2679
+ declare function getOIMComputeRuntime(queue: OIMEventQueue): OIMComputeRuntime;
2680
+
2681
+ /**
2682
+ * The runtime already attached to `queue`, or `undefined` — WITHOUT creating one.
2683
+ *
2684
+ * The read-only counterpart of `getOIMComputeRuntime`, for code that must not
2685
+ * change what it observes: devtools asking "does this queue even have a compute
2686
+ * graph", teardown checking whether there is anything to destroy, assertions in
2687
+ * tests. A runtime that has been destroyed reads as `undefined`, matching what
2688
+ * `getOIMComputeRuntime` would then replace — so a caller cannot get hold of a
2689
+ * detached runtime through this door either.
2690
+ */
2691
+ declare function peekOIMComputeRuntime(queue: OIMEventQueue): OIMComputeRuntime | undefined;
2692
+
2693
+ /**
2694
+ * Install `runtime` as the one runtime for `queue`, replacing whatever was there.
2695
+ *
2696
+ * The injection seam for a subclassed runtime — an instrumented one that records
2697
+ * levels and drain order, a profiling one, a test double. Call it BEFORE anything
2698
+ * touches the queue's compute graph: nodes capture their runtime at construction,
2699
+ * so swapping afterwards leaves the existing ones on the old instance and splits
2700
+ * the dependency graph in two, which is exactly the glitch the one-runtime-per-
2701
+ * queue rule exists to prevent.
2702
+ *
2703
+ * `runtime.queue` must be `queue` — a runtime drains on its own queue's
2704
+ * AFTER_FLUSH, so a mismatched pair would never run.
2705
+ *
2706
+ * Replacing does NOT destroy the previous runtime: whoever installs a replacement
2707
+ * decides whether the old one still has live nodes on it.
2708
+ */
2709
+ declare function setOIMComputeRuntime(queue: OIMEventQueue, runtime: OIMComputeRuntime): void;
2710
+
2415
2711
  type TOIMFieldKey<TEntity extends object> = keyof TEntity & string;
2416
2712
  /**
2417
2713
  * Tracks changed fields per entity PK for an `OIMCollection`.
@@ -2959,88 +3255,17 @@ declare class OIMDBSettings {
2959
3255
  static readonly FLUSHING_KEYS_INDEX_KEY: "__flushingKeys__";
2960
3256
  }
2961
3257
 
2962
- interface IOIMEffectDependency {
2963
- subscribe(onUpdate: () => void): () => void;
2964
- }
2965
-
2966
- type TOIMComputedOptions<TValue> = {
2967
- compute: () => TValue;
2968
- deps?: readonly IOIMEffectDependency[];
2969
- compare?: (a: TValue, b: TValue) => boolean;
2970
- };
2971
-
2972
- type TOIMComputedUpdatePayload<TKey extends TOIMKey> = {
2973
- keys: readonly TKey[];
2974
- };
2975
-
2976
- type TOIMComputedKey$2 = 'value';
2977
- declare class OIMComputed<TValue> {
2978
- readonly emitter: OIMEventEmitter<{
2979
- update: TOIMComputedUpdatePayload<TOIMComputedKey$2>;
2980
- }>;
2981
- readonly updateEventEmitter: OIMUpdateEventEmitter<TOIMComputedKey$2>;
2982
- private readonly runtime;
2983
- private readonly compute;
2984
- private readonly compare;
2985
- private readonly _deps;
2986
- private value;
2987
- private hasValue;
2988
- private isDirty;
2989
- private readonly effect;
2990
- constructor(runtime: OIMComputeRuntime, opts: TOIMComputedOptions<TValue>);
2991
- get needsRecompute(): boolean;
2992
- get isReady(): boolean;
2993
- get deps(): readonly IOIMEffectDependency[];
2994
- get(): TValue;
2995
- getIfReady(): TValue | undefined;
2996
- destroy(): void;
2997
- private recomputeAndEmitIfChanged;
2998
- }
2999
-
3000
3258
  declare enum EOIMComputedEventType {
3001
3259
  UPDATE = "update"
3002
3260
  }
3003
3261
 
3004
- type TOIMComputedKey$1 = 'value';
3262
+ type TOIMComputedKey = 'value';
3005
3263
  interface IOIMComputedEventSource {
3006
3264
  emitter: OIMEventEmitter<{
3007
- [EOIMComputedEventType.UPDATE]: TOIMComputedUpdatePayload<TOIMComputedKey$1>;
3265
+ [EOIMComputedEventType.UPDATE]: TOIMComputedUpdatePayload<TOIMComputedKey>;
3008
3266
  }>;
3009
3267
  }
3010
3268
 
3011
- type TOIMEffectOptions = {
3012
- deps?: readonly IOIMEffectDependency[];
3013
- onUpdate?: () => void;
3014
- run: () => void;
3015
- };
3016
-
3017
- declare class OIMEffect {
3018
- private readonly runtime;
3019
- private readonly onUpdate?;
3020
- private readonly run;
3021
- private readonly deps;
3022
- private readonly sourceDeps;
3023
- private readonly computedDeps;
3024
- private sourceUnsubscribers;
3025
- private computedUnsubscribers;
3026
- private dequeueResubscribe?;
3027
- private isResubscribeEnqueued;
3028
- private isTemporarilyUnsubscribedForFlush;
3029
- private isScheduled;
3030
- private dequeueScheduled?;
3031
- private readonly runTask;
3032
- constructor(runtime: OIMComputeRuntime, opts: TOIMEffectOptions);
3033
- destroy(): void;
3034
- private onSourceInvalidate;
3035
- private onComputedInvalidate;
3036
- private runOnce;
3037
- private subscribeToDeps;
3038
- private unsubscribeFromSourceDeps;
3039
- private unsubscribeFromAllDeps;
3040
- private ensureResubscribeAfterFlush;
3041
- private readonly onAfterFlush;
3042
- }
3043
-
3044
3269
  /**
3045
3270
  * Depends on updates to ONE key of a keyed source. The key argument is the whole
3046
3271
  * key — a composite key `[a, b]` is one key, never split — so there is no
@@ -3054,43 +3279,6 @@ declare class OIMEffectDependencyKeyed<TKey extends TOIMKey> implements IOIMEffe
3054
3279
  subscribe(onUpdate: () => void): () => void;
3055
3280
  }
3056
3281
 
3057
- declare class OIMEffectDependencyKeyedObject<TKey extends string, TValue> implements IOIMEffectDependency {
3058
- private readonly dep;
3059
- constructor(object: OIMReactiveObject<TKey, TValue>, key: TKey);
3060
- get source(): OIMReactiveObject<TKey, TValue>;
3061
- subscribe(onUpdate: () => void): () => void;
3062
- }
3063
-
3064
- declare class OIMEffectDependencyKeyedCollection<TEntity extends object, TPk extends TOIMKey> implements IOIMEffectDependency {
3065
- private readonly dep;
3066
- constructor(collection: OIMReactiveCollection<TEntity, TPk>, pk: TPk);
3067
- get source(): OIMReactiveCollection<TEntity, TPk>;
3068
- subscribe(onUpdate: () => void): () => void;
3069
- }
3070
-
3071
- declare class OIMEffectDependencyKeyedIndex<TKey extends TOIMKey> implements IOIMEffectDependency {
3072
- private readonly dep;
3073
- constructor(index: IOIMKeyedSubscription<TKey>, key: TKey);
3074
- get source(): IOIMKeyedSubscription<TKey>;
3075
- subscribe(onUpdate: () => void): () => void;
3076
- }
3077
-
3078
- type TOIMComputedKey = 'value';
3079
- type TOIMComputedLike = {
3080
- emitter: OIMEventEmitter<{
3081
- update: TOIMComputedUpdatePayload<TOIMComputedKey>;
3082
- }>;
3083
- updateEventEmitter: OIMUpdateEventEmitter<TOIMComputedKey>;
3084
- };
3085
- /**
3086
- * Effect dependency on a computed.
3087
- */
3088
- declare class OIMEffectDependencyComputed implements IOIMEffectDependency {
3089
- readonly source: TOIMComputedLike;
3090
- constructor(source: TOIMComputedLike);
3091
- subscribe(onUpdate: () => void): () => void;
3092
- }
3093
-
3094
3282
  declare class OIMCollectionByPkSelector<TEntity extends object, TPk extends TOIMKey> extends OIMSelector<TEntity | undefined> {
3095
3283
  private readonly collection;
3096
3284
  private readonly pk;
@@ -3186,4 +3374,4 @@ declare class OIMEntitiesByGlobalIndexArrayBasedSelector<TEntity extends object,
3186
3374
  protected areEqual(prev: readonly (TEntity | undefined)[], next: readonly (TEntity | undefined)[]): boolean;
3187
3375
  }
3188
3376
 
3189
- export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, type IOIMCarrierBucketStore, type IOIMCarrierProvider, type IOIMComputedEventSource, type IOIMDisposable, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, type IOIMGlobalIndexSlotSource, type IOIMIndexSlotSource, type IOIMIndexStore, type IOIMKeyedMap, type IOIMKeyedSet, type IOIMKeyedUpdateEmitter, type IOIMOrderedListCommandSource, type IOIMPkCodec, type IOIMSingleUpdateEmitter, type IOIMSubscribable, type IOIMSubscription, OIMBucketCarrierProvider, OIMCarrierKeyedEmitter, OIMCarrierSingleEmitter, OIMCollection, OIMCollectionByPkSelector, OIMCollectionByPksSelector, OIMCollectionChangedFields, OIMCollectionIndexFactory, OIMCollectionIndexManualOrderedArrayBased, OIMCollectionOrderedListCommandStream, OIMCollectionSelectors, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMCollectionStoreTrieDriven, OIMComparatorFactory, OIMComputeRuntime, OIMComputed, OIMDBSettings, OIMDerivedCollectionGlobalIndexArrayBased, OIMDerivedCollectionGlobalIndexSetBased, OIMDerivedCollectionIndexArrayBased, OIMDerivedCollectionIndexSetBased, OIMDisposeScope, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntitiesByGlobalIndexArrayBasedSelector, OIMEntitiesByGlobalIndexSetBasedSelector, OIMEntitiesByIndexKeyArrayBasedSelector, OIMEntitiesByIndexKeySetBasedSelector, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerSync, OIMEventQueueSchedulerTimeout, OIMGlobalIndex, OIMGlobalIndexArrayBased, OIMGlobalIndexManualArrayBased, OIMGlobalIndexManualSetBased, OIMGlobalIndexSetBased, OIMGlobalIndexSlotMap, OIMIndex, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexPksByKeyArrayBasedSelector, OIMIndexPksByKeySetBasedSelector, OIMIndexPksByKeysArrayBasedSelector, OIMIndexPksByKeysSetBasedSelector, OIMIndexSetBased, OIMIndexSlotMap, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMIndexStoreTrieDrivenArrayBased, OIMIndexStoreTrieDrivenSetBased, OIMKeyPathCarrierProvider, OIMKeyedBucketArrayBased, OIMKeyedBucketSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMObjectValueByKeySelector, OIMObjectValuesByKeysSelector, OIMOrderedListCommandBuffer, OIMOrderedListCommandStream, OIMOrderedListCommandStreamDiffDriven, OIMOrderedListMappedCommandStream, OIMPkCodecKeyPath, OIMPkSelectorFactory, OIMReactiveCollection, OIMReactiveCollectionGlobalIndexManualArrayBased, OIMReactiveCollectionGlobalIndexManualSetBased, OIMReactiveCollectionIndexCompositeTrieArrayBased, OIMReactiveCollectionIndexCompositeTrieSetBased, OIMReactiveCollectionIndexManualArrayBased, OIMReactiveCollectionIndexManualSetBased, OIMReactiveGlobalIndex, OIMReactiveGlobalIndexArrayBased, OIMReactiveGlobalIndexManualArrayBased, OIMReactiveGlobalIndexManualSetBased, OIMReactiveGlobalIndexSetBased, OIMReactiveIndex, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMSelector, OIMTrieMap, OIMTrieSet, type TOIMAnyEntitySlot, type TOIMCollectionEntitiesSelector, type TOIMCollectionEntitySelector, type TOIMCollectionGlobalIndexArrayBasedOptions, type TOIMCollectionGlobalIndexSetBasedOptions, type TOIMCollectionIndexArrayBasedOptions, type TOIMCollectionIndexCompositeArrayBasedOptions, type TOIMCollectionIndexCompositeSetBasedOptions, type TOIMCollectionIndexSetBasedOptions, type TOIMCollectionKit, type TOIMCollectionOptions, type TOIMCollectionOrderedIndexOptions, type TOIMCollectionOrderedListCommandStreamOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMDerivedCollectionGlobalIndexArrayBasedOptions, type TOIMDerivedCollectionGlobalIndexSetBasedOptions, type TOIMDerivedCollectionIndexArrayBasedOptions, type TOIMDerivedCollectionIndexSetBasedOptions, type TOIMDerivedEntityComparator, type TOIMDerivedEntityOrderSelector, type TOIMDerivedEntityOrderValue, type TOIMDerivedIndexKeySelector, type TOIMDisposable, type TOIMEffectOptions, type TOIMEntitySlot, type TOIMEntitySlotGetter, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMFlushError, type TOIMGlobalIndexFilter, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMKey, type TOIMKeyPath, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMOrderedListDiffOptions, type TOIMPk, type TOIMPkSelector, type TOIMReactiveCollectionFactoryOptions, type TOIMRelationsArrayIndexOptions, type TOIMRelationsCompositeArrayIndexOptions, type TOIMRelationsCompositeSetIndexOptions, type TOIMRelationsDerivedArrayIndexOptions, type TOIMRelationsDerivedGlobalArrayIndexOptions, type TOIMRelationsDerivedGlobalSetIndexOptions, type TOIMRelationsDerivedSetIndexOptions, type TOIMRelationsGlobalArrayIndexOptions, type TOIMRelationsGlobalSetIndexOptions, type TOIMRelationsOrderedListOptions, type TOIMRelationsSetIndexOptions, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdatePayload, createInPlaceEntityUpdater, createMergeEntityUpdater, createOIMCollectionIndexFactory, createOIMCollectionKit, createOIMDisposeScope, createOIMGlobalIndexSlotMap, createOIMIndexSlotMap, createOIMOrderedListCommandStreamDiffDriven, createOIMOrderedListMappedCommandStream, diffOrderedListByPk };
3377
+ export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, type IOIMCarrierBucketStore, type IOIMCarrierProvider, type IOIMComputedEventSource, type IOIMDisposable, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, type IOIMGlobalIndexSlotSource, type IOIMIndexSlotSource, type IOIMIndexStore, type IOIMKeyedMap, type IOIMKeyedSet, type IOIMKeyedUpdateEmitter, type IOIMOrderedListCommandSource, type IOIMPkCodec, type IOIMSingleUpdateEmitter, type IOIMSubscribable, type IOIMSubscription, OIMBucketCarrierProvider, OIMCarrierKeyedEmitter, OIMCarrierSingleEmitter, OIMCollection, OIMCollectionByPkSelector, OIMCollectionByPksSelector, OIMCollectionChangedFields, OIMCollectionIndexFactory, OIMCollectionIndexManualOrderedArrayBased, OIMCollectionOrderedListCommandStream, OIMCollectionSelectors, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMCollectionStoreTrieDriven, OIMComparatorFactory, OIMComputeRuntime, OIMComputed, OIMDBSettings, OIMDerivedCollection, OIMDerivedCollectionGlobalIndexArrayBased, OIMDerivedCollectionGlobalIndexSetBased, OIMDerivedCollectionIndexArrayBased, OIMDerivedCollectionIndexSetBased, OIMDisposeScope, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntitiesByGlobalIndexArrayBasedSelector, OIMEntitiesByGlobalIndexSetBasedSelector, OIMEntitiesByIndexKeyArrayBasedSelector, OIMEntitiesByIndexKeySetBasedSelector, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerSync, OIMEventQueueSchedulerTimeout, OIMGlobalIndex, OIMGlobalIndexArrayBased, OIMGlobalIndexManualArrayBased, OIMGlobalIndexManualSetBased, OIMGlobalIndexSetBased, OIMGlobalIndexSlotMap, OIMIndex, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexPksByKeyArrayBasedSelector, OIMIndexPksByKeySetBasedSelector, OIMIndexPksByKeysArrayBasedSelector, OIMIndexPksByKeysSetBasedSelector, OIMIndexSetBased, OIMIndexSlotMap, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMIndexStoreTrieDrivenArrayBased, OIMIndexStoreTrieDrivenSetBased, OIMKeyPathCarrierProvider, OIMKeyedBucketArrayBased, OIMKeyedBucketSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMObjectValueByKeySelector, OIMObjectValuesByKeysSelector, OIMOrderedListCommandBuffer, OIMOrderedListCommandStream, OIMOrderedListCommandStreamDiffDriven, OIMOrderedListMappedCommandStream, OIMPkCodecKeyPath, OIMPkSelectorFactory, OIMReactiveCollection, OIMReactiveCollectionGlobalIndexManualArrayBased, OIMReactiveCollectionGlobalIndexManualSetBased, OIMReactiveCollectionIndexCompositeTrieArrayBased, OIMReactiveCollectionIndexCompositeTrieSetBased, OIMReactiveCollectionIndexManualArrayBased, OIMReactiveCollectionIndexManualSetBased, OIMReactiveGlobalIndex, OIMReactiveGlobalIndexArrayBased, OIMReactiveGlobalIndexManualArrayBased, OIMReactiveGlobalIndexManualSetBased, OIMReactiveGlobalIndexSetBased, OIMReactiveIndex, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMSelector, OIMTrieMap, OIMTrieSet, type TOIMAnyEntitySlot, type TOIMCollectionEntitiesSelector, type TOIMCollectionEntitySelector, type TOIMCollectionGlobalIndexArrayBasedOptions, type TOIMCollectionGlobalIndexSetBasedOptions, type TOIMCollectionIndexArrayBasedOptions, type TOIMCollectionIndexCompositeArrayBasedOptions, type TOIMCollectionIndexCompositeSetBasedOptions, type TOIMCollectionIndexSetBasedOptions, type TOIMCollectionKit, type TOIMCollectionOptions, type TOIMCollectionOrderedIndexOptions, type TOIMCollectionOrderedListCommandStreamOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMDerivedCollectionGlobalIndexArrayBasedOptions, type TOIMDerivedCollectionGlobalIndexSetBasedOptions, type TOIMDerivedCollectionIndexArrayBasedOptions, type TOIMDerivedCollectionIndexSetBasedOptions, type TOIMDerivedCollectionOptions, type TOIMDerivedEntityComparator, type TOIMDerivedEntityOrderSelector, type TOIMDerivedEntityOrderValue, type TOIMDerivedIndexKeySelector, type TOIMDisposable, type TOIMEffectOptions, type TOIMEntitySlot, type TOIMEntitySlotGetter, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMFlushError, type TOIMGlobalIndexFilter, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMKey, type TOIMKeyPath, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMOrderedListDiffOptions, type TOIMPk, type TOIMPkSelector, type TOIMReactiveCollectionFactoryOptions, type TOIMRelationsArrayIndexOptions, type TOIMRelationsCompositeArrayIndexOptions, type TOIMRelationsCompositeSetIndexOptions, type TOIMRelationsDerivedArrayIndexOptions, type TOIMRelationsDerivedGlobalArrayIndexOptions, type TOIMRelationsDerivedGlobalSetIndexOptions, type TOIMRelationsDerivedSetIndexOptions, type TOIMRelationsGlobalArrayIndexOptions, type TOIMRelationsGlobalSetIndexOptions, type TOIMRelationsOrderedListOptions, type TOIMRelationsSetIndexOptions, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdatePayload, createInPlaceEntityUpdater, createMergeEntityUpdater, createOIMCollectionIndexFactory, createOIMCollectionKit, createOIMDisposeScope, createOIMGlobalIndexSlotMap, createOIMIndexSlotMap, createOIMOrderedListCommandStreamDiffDriven, createOIMOrderedListMappedCommandStream, diffOrderedListByPk, getOIMComputeRuntime, on, peekOIMComputeRuntime, setOIMComputeRuntime };