@oimdb/core 3.3.0 → 3.5.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/README.md +30 -13
- package/dist/index.cjs +309 -63
- package/dist/index.d.cts +192 -24
- package/dist/index.d.ts +192 -24
- package/dist/index.js +305 -62
- package/llms.txt +33 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -627,7 +627,20 @@ declare class OIMIndexManualOrderedArrayBased<TKey extends TOIMPk, TItemKey exte
|
|
|
627
627
|
pushSlot(key: TKey, slot: TOIMAnyEntitySlot<TItemKey>): number;
|
|
628
628
|
insertSlotAt(key: TKey, index: number, slot: TOIMAnyEntitySlot<TItemKey>): number;
|
|
629
629
|
removeAt(key: TKey, index: number): TOIMAnyEntitySlot<TItemKey> | undefined;
|
|
630
|
+
/**
|
|
631
|
+
* Remove up to `count` consecutive slots starting at `index`.
|
|
632
|
+
* Returns the number actually removed (clamped to bounds; 0 if nothing).
|
|
633
|
+
*/
|
|
634
|
+
removeRange(key: TKey, index: number, count: number): number;
|
|
630
635
|
move(key: TKey, fromIndex: number, toIndex: number): TOIMAnyEntitySlot<TItemKey> | undefined;
|
|
636
|
+
/** Replace the slot at `index` in place. Returns the safe index, or -1. */
|
|
637
|
+
setSlotAt(key: TKey, index: number, slot: TOIMAnyEntitySlot<TItemKey>): number;
|
|
638
|
+
/**
|
|
639
|
+
* Move up to `count` consecutive slots from `from` to `to`. `to` is in the
|
|
640
|
+
* coordinate space *after* the block is extracted (same as single `move`).
|
|
641
|
+
* Returns the number actually moved (0 if a no-op / out of bounds).
|
|
642
|
+
*/
|
|
643
|
+
moveRange(key: TKey, from: number, to: number, count: number): number;
|
|
631
644
|
resetSlots(key: TKey, slots: readonly TOIMAnyEntitySlot<TItemKey>[]): void;
|
|
632
645
|
private getOrCreateList;
|
|
633
646
|
}
|
|
@@ -712,39 +725,79 @@ declare class OIMUpdateEventEmitter<TKey extends TOIMPk> {
|
|
|
712
725
|
unsubscribeFromKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): void;
|
|
713
726
|
}
|
|
714
727
|
|
|
715
|
-
|
|
728
|
+
/**
|
|
729
|
+
* Incremental command for an ordered per-key list, addressed by position.
|
|
730
|
+
*
|
|
731
|
+
* `item` is whatever the stream stores per element — the command stream uses the
|
|
732
|
+
* entity slot (`TOIMEntitySlot`), so a consumer reads `item.item` for the entity.
|
|
733
|
+
*
|
|
734
|
+
* - `insert` — a single element appears at `index`.
|
|
735
|
+
* - `remove` — `count` elements (default 1, may be > 1) disappear from `index`.
|
|
736
|
+
* - `move` — `count` elements (default 1) move from `from` to `to`.
|
|
737
|
+
* - `set` — the element at `index` is replaced in place.
|
|
738
|
+
* - `reset` — the whole list for the key is replaced by `items`.
|
|
739
|
+
*/
|
|
740
|
+
type TOIMOrderedListCommand<TItem> = {
|
|
716
741
|
type: 'insert';
|
|
717
|
-
pk: TPk;
|
|
718
|
-
slot: TOIMEntitySlot<TEntity, TPk>;
|
|
719
742
|
index: number;
|
|
743
|
+
item: TItem;
|
|
720
744
|
} | {
|
|
721
745
|
type: 'remove';
|
|
722
|
-
pk: TPk;
|
|
723
|
-
slot: TOIMEntitySlot<TEntity, TPk>;
|
|
724
746
|
index: number;
|
|
747
|
+
count?: number;
|
|
725
748
|
} | {
|
|
726
749
|
type: 'move';
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
toIndex: number;
|
|
750
|
+
from: number;
|
|
751
|
+
to: number;
|
|
752
|
+
count?: number;
|
|
731
753
|
} | {
|
|
732
|
-
/**
|
|
733
|
-
* Replace the whole list for this key (preferred name).
|
|
734
|
-
*/
|
|
735
754
|
type: 'set';
|
|
736
|
-
|
|
737
|
-
|
|
755
|
+
index: number;
|
|
756
|
+
item: TItem;
|
|
757
|
+
} | {
|
|
758
|
+
type: 'reset';
|
|
759
|
+
items: readonly TItem[];
|
|
738
760
|
};
|
|
739
761
|
|
|
762
|
+
/**
|
|
763
|
+
* Read/consume side of an ordered-list command stream, generic over the element
|
|
764
|
+
* type it carries.
|
|
765
|
+
*
|
|
766
|
+
* The concrete stream stores entity slots (`TItem = TOIMEntitySlot<...>`); a
|
|
767
|
+
* mapped source ({@link OIMOrderedListMappedCommandStream}) carries whatever the
|
|
768
|
+
* mapping produces. A consumer that depends on this interface works unchanged
|
|
769
|
+
* against either — raw or mapped.
|
|
770
|
+
*
|
|
771
|
+
* Consumption is pull-based and synchronous: the notification carries no
|
|
772
|
+
* payload, so `consumeCommands(key)` must be called inside the `handler`, before
|
|
773
|
+
* the buffer for that key is cleared.
|
|
774
|
+
*/
|
|
775
|
+
interface IOIMOrderedListCommandSource<TKey extends TOIMPk, TItem> {
|
|
776
|
+
/**
|
|
777
|
+
* Subscribe to per-key command notifications. The handler receives no
|
|
778
|
+
* payload — pull the commands with {@link consumeCommands} synchronously.
|
|
779
|
+
* Returns an unsubscribe function.
|
|
780
|
+
*/
|
|
781
|
+
subscribeCommands(key: TKey, handler: () => void): () => void;
|
|
782
|
+
/** Drain the commands buffered for `key` this delivery (a copy). */
|
|
783
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TItem>[];
|
|
784
|
+
/** Current ordered items for `key` — the initial state before any command. */
|
|
785
|
+
getItemsByKey(key: TKey): readonly TItem[];
|
|
786
|
+
}
|
|
787
|
+
|
|
740
788
|
/**
|
|
741
789
|
* Slot-first ordered-list command stream.
|
|
742
790
|
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
791
|
+
* Emits position-addressed {@link TOIMOrderedListCommand}s whose `item` is the
|
|
792
|
+
* entity slot. Use this when you already have slots and want incremental
|
|
793
|
+
* commands for an imperative renderer. For PK writes bound to a collection, use
|
|
745
794
|
* `OIMCollectionOrderedListCommandStream`.
|
|
795
|
+
*
|
|
796
|
+
* Implements {@link IOIMOrderedListCommandSource} (with the slot as the element)
|
|
797
|
+
* so it can be projected element-wise via
|
|
798
|
+
* `createOIMOrderedListMappedCommandStream`.
|
|
746
799
|
*/
|
|
747
|
-
declare class OIMOrderedListCommandStream<TKey extends TOIMPk, TPk extends TOIMPk, TEntity extends object = object> {
|
|
800
|
+
declare class OIMOrderedListCommandStream<TKey extends TOIMPk, TPk extends TOIMPk, TEntity extends object = object> implements IOIMOrderedListCommandSource<TKey, TOIMEntitySlot<TEntity, TPk>> {
|
|
748
801
|
readonly commandsEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
749
802
|
private readonly unsubscribeAfterFlush;
|
|
750
803
|
private readonly unsubscribeFromIndexEmitter;
|
|
@@ -755,24 +808,37 @@ declare class OIMOrderedListCommandStream<TKey extends TOIMPk, TPk extends TOIMP
|
|
|
755
808
|
constructor(queue: OIMEventQueue, index?: OIMIndexManualOrderedArrayBased<TKey, TPk>);
|
|
756
809
|
getPksByKey(key: TKey): readonly TPk[];
|
|
757
810
|
getSlotsByKey(key: TKey): readonly TOIMEntitySlot<TEntity, TPk>[];
|
|
811
|
+
/** {@link IOIMOrderedListCommandSource} — alias of {@link getSlotsByKey}. */
|
|
812
|
+
getItemsByKey(key: TKey): readonly TOIMEntitySlot<TEntity, TPk>[];
|
|
813
|
+
/** {@link IOIMOrderedListCommandSource} — per-key command subscription. */
|
|
814
|
+
subscribeCommands(key: TKey, handler: () => void): () => void;
|
|
758
815
|
getEntitiesByKey(key: TKey): (TEntity | undefined)[];
|
|
759
816
|
hasKey(key: TKey): boolean;
|
|
760
817
|
getKeys(): readonly TKey[];
|
|
761
818
|
pushSlot(key: TKey, slot: TOIMEntitySlot<TEntity, TPk>): void;
|
|
762
819
|
insertSlotAt(key: TKey, index: number, slot: TOIMEntitySlot<TEntity, TPk>): void;
|
|
820
|
+
/** Replace the slot at `index` in place. */
|
|
821
|
+
setSlotAt(key: TKey, index: number, slot: TOIMEntitySlot<TEntity, TPk>): void;
|
|
763
822
|
removeAt(key: TKey, index: number): void;
|
|
823
|
+
/** Remove `count` consecutive elements from `index`; emits `remove` with `count`. */
|
|
824
|
+
removeRange(key: TKey, index: number, count: number): void;
|
|
764
825
|
move(key: TKey, fromIndex: number, toIndex: number): void;
|
|
826
|
+
/**
|
|
827
|
+
* Move `count` consecutive elements from `from` to `to`; emits `move` with
|
|
828
|
+
* `count`. `to` is in the post-extraction coordinate space (as single `move`).
|
|
829
|
+
*/
|
|
830
|
+
moveRange(key: TKey, from: number, to: number, count: number): void;
|
|
765
831
|
setSlots(key: TKey, slots: readonly TOIMEntitySlot<TEntity, TPk>[]): void;
|
|
766
|
-
getBufferedCommands(key: TKey): readonly TOIMOrderedListCommand<
|
|
767
|
-
consumeCommands(key: TKey): TOIMOrderedListCommand<
|
|
832
|
+
getBufferedCommands(key: TKey): readonly TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>[];
|
|
833
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>[];
|
|
768
834
|
clear(key?: TKey): void;
|
|
769
835
|
destroy(): void;
|
|
770
836
|
private readonly onAfterFlush;
|
|
771
837
|
private readonly onIndexUpdate;
|
|
772
838
|
protected withWrite(fn: () => void): void;
|
|
773
|
-
protected appendCommand(key: TKey, cmd: TOIMOrderedListCommand<
|
|
774
|
-
protected
|
|
775
|
-
protected
|
|
839
|
+
protected appendCommand(key: TKey, cmd: TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>): void;
|
|
840
|
+
protected appendResetCommand(key: TKey, slots: readonly TOIMEntitySlot<TEntity, TPk>[]): void;
|
|
841
|
+
protected createResetCommand(slots: readonly TOIMEntitySlot<TEntity, TPk>[]): TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>;
|
|
776
842
|
}
|
|
777
843
|
|
|
778
844
|
/**
|
|
@@ -785,6 +851,8 @@ declare class OIMCollectionOrderedListCommandStream<TKey extends TOIMPk, TPk ext
|
|
|
785
851
|
constructor(queue: OIMEventQueue, opts: TOIMCollectionOrderedListCommandStreamOptions<TKey, TPk, TEntity>);
|
|
786
852
|
push(key: TKey, pk: TPk): void;
|
|
787
853
|
insertAt(key: TKey, index: number, pk: TPk): void;
|
|
854
|
+
/** Replace the element at `index` with the slot for `pk`, in place. */
|
|
855
|
+
setAt(key: TKey, index: number, pk: TPk): void;
|
|
788
856
|
set(key: TKey, pks: readonly TPk[]): void;
|
|
789
857
|
getSlotsByKey(key: TKey): readonly TOIMEntitySlot<TEntity, TPk>[];
|
|
790
858
|
getEntitiesByKey(key: TKey): (TEntity | undefined)[];
|
|
@@ -1149,6 +1217,18 @@ declare class OIMEntityUpdaterFactory<TEntity extends object> {
|
|
|
1149
1217
|
*/
|
|
1150
1218
|
declare function createInPlaceEntityUpdater<TEntity extends object>(): TOIMEntityUpdater<TEntity>;
|
|
1151
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* Default entity updater: shallow-merges the patch into a NEW object
|
|
1222
|
+
* (`{ ...prev, ...draft }`). Each update produces a fresh entity reference, which
|
|
1223
|
+
* reference-comparison bindings (React's `Object.is` / `useSyncExternalStore`,
|
|
1224
|
+
* `React.memo`, prev/next diffing, time-travel) need to detect a change.
|
|
1225
|
+
*
|
|
1226
|
+
* The new-object allocation is the biggest per-update data-layer cost; for
|
|
1227
|
+
* update-heavy, subscription-driven readers use {@link createInPlaceEntityUpdater}
|
|
1228
|
+
* instead.
|
|
1229
|
+
*/
|
|
1230
|
+
declare function createMergeEntityUpdater<TEntity extends object>(): TOIMEntityUpdater<TEntity>;
|
|
1231
|
+
|
|
1152
1232
|
/**
|
|
1153
1233
|
* Factory for creating index comparators.
|
|
1154
1234
|
* Provides common comparison strategies for primary key arrays.
|
|
@@ -1297,9 +1377,11 @@ declare class OIMCollectionChangedFields<TEntity extends object, TPk extends TOI
|
|
|
1297
1377
|
readonly collection: OIMCollection<TEntity, TPk>;
|
|
1298
1378
|
private readonly selectPk;
|
|
1299
1379
|
private readonly unsubscribeAfterFlush;
|
|
1300
|
-
private readonly unsubscribeFromCollectionEmitter
|
|
1380
|
+
private readonly unsubscribeFromCollectionEmitter?;
|
|
1381
|
+
private readonly detectExternalMutations;
|
|
1301
1382
|
private isInWrite;
|
|
1302
1383
|
private readonly lastEntitySnapshotByPk;
|
|
1384
|
+
private readonly writtenThroughThisFlush;
|
|
1303
1385
|
/**
|
|
1304
1386
|
* Emits updates scoped by PK. Subscribe, then read state via `getChangedFieldsByPk(...)`
|
|
1305
1387
|
* or drain via `consumeChangedFieldsByPk(...)`.
|
|
@@ -1318,6 +1400,18 @@ declare class OIMCollectionChangedFields<TEntity extends object, TPk extends TOI
|
|
|
1318
1400
|
* If not provided, only `upsertOneByPk(...)` should be used.
|
|
1319
1401
|
*/
|
|
1320
1402
|
selectPk?: (entity: TEntity | Partial<TEntity>) => TPk;
|
|
1403
|
+
/**
|
|
1404
|
+
* Detect writes that bypass this wrapper (direct collection
|
|
1405
|
+
* mutations) by diffing entity snapshots. Default `true`.
|
|
1406
|
+
*
|
|
1407
|
+
* Set to `false` when you always write through this wrapper: it
|
|
1408
|
+
* drops the per-write snapshot clone and the per-PK snapshot map
|
|
1409
|
+
* (~2x entity memory), since those exist only to power external
|
|
1410
|
+
* detection. The shallow diff also can't see deep in-place
|
|
1411
|
+
* mutations anyway — so if that's your model, opting out costs you
|
|
1412
|
+
* nothing it could have caught.
|
|
1413
|
+
*/
|
|
1414
|
+
detectExternalMutations?: boolean;
|
|
1321
1415
|
});
|
|
1322
1416
|
upsertOneByPk(pk: TPk, patch: Partial<TEntity>): TOIMEntitySlot<TEntity, TPk>;
|
|
1323
1417
|
upsertOne(entity: TEntity | Partial<TEntity>): TOIMEntitySlot<TEntity, TPk>;
|
|
@@ -1338,6 +1432,80 @@ declare class OIMCollectionChangedFields<TEntity extends object, TPk extends TOI
|
|
|
1338
1432
|
private trackPatch;
|
|
1339
1433
|
}
|
|
1340
1434
|
|
|
1435
|
+
/**
|
|
1436
|
+
* Options for {@link OIMOrderedListMappedCommandStream} — how a source element
|
|
1437
|
+
* (`TIn`) is projected to a downstream element (`TOut`) and torn down.
|
|
1438
|
+
*
|
|
1439
|
+
* `create` runs once per element when it enters the list (an `insert`, a `set`
|
|
1440
|
+
* replacement, or list build / `reset`). `destroy` runs when it leaves (a
|
|
1441
|
+
* `remove`, the replaced half of a `set`, every element on `reset`, and on
|
|
1442
|
+
* stream `destroy()`). A `move` reuses the same `TOut` — it is never recreated.
|
|
1443
|
+
*/
|
|
1444
|
+
type TOIMOrderedListMapOptions<TIn, TOut> = {
|
|
1445
|
+
create: (item: TIn) => TOut;
|
|
1446
|
+
destroy?: (mapped: TOut) => void;
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
/**
|
|
1450
|
+
* Projects an ordered-list command source element-wise, re-emitting the same
|
|
1451
|
+
* position-addressed commands with `item` replaced by the mapped value.
|
|
1452
|
+
*
|
|
1453
|
+
* It rides the source's batching: there is no queue and no independent
|
|
1454
|
+
* scheduling. On each source notification it pulls the source commands,
|
|
1455
|
+
* translates them (running `create` / `destroy` and updating a positional
|
|
1456
|
+
* mirror of the mapped elements), and notifies its own subscribers
|
|
1457
|
+
* synchronously — so the source's `after_flush` semantics carry through.
|
|
1458
|
+
*
|
|
1459
|
+
* Identity is positional: a `move` reorders the *same* mapped references in the
|
|
1460
|
+
* mirror, so the mapped element is preserved across moves and never recreated.
|
|
1461
|
+
* `create` runs on `insert` / `set` / `reset` / initial build; `destroy` on
|
|
1462
|
+
* `remove` / the replaced half of `set` / every element on `reset` / `destroy()`.
|
|
1463
|
+
*
|
|
1464
|
+
* Wiring to the source for a key is lazy (on first `subscribeCommands` or
|
|
1465
|
+
* `getItemsByKey`) and lives until `destroy()`; subscriber churn does not
|
|
1466
|
+
* create or tear down mapped elements.
|
|
1467
|
+
*
|
|
1468
|
+
* The output is itself an {@link IOIMOrderedListCommandSource}, so maps chain:
|
|
1469
|
+
* `source.map(...)` → `.map(...)`.
|
|
1470
|
+
*/
|
|
1471
|
+
declare class OIMOrderedListMappedCommandStream<TKey extends TOIMPk, TOut, TIn> implements IOIMOrderedListCommandSource<TKey, TOut> {
|
|
1472
|
+
private readonly source;
|
|
1473
|
+
private readonly create;
|
|
1474
|
+
private readonly destroyItem?;
|
|
1475
|
+
/** Per-key positional mirror of the mapped elements. */
|
|
1476
|
+
private readonly mirror;
|
|
1477
|
+
/** Mapped commands produced for the current delivery, per key. */
|
|
1478
|
+
private readonly buffer;
|
|
1479
|
+
private readonly subscribers;
|
|
1480
|
+
private readonly sourceUnsubscribers;
|
|
1481
|
+
constructor(source: IOIMOrderedListCommandSource<TKey, TIn>, opts: TOIMOrderedListMapOptions<TIn, TOut>);
|
|
1482
|
+
subscribeCommands(key: TKey, handler: () => void): () => void;
|
|
1483
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TOut>[];
|
|
1484
|
+
getItemsByKey(key: TKey): readonly TOut[];
|
|
1485
|
+
/** Map this source again, chaining the projection. */
|
|
1486
|
+
map<TNext>(opts: TOIMOrderedListMapOptions<TOut, TNext>): OIMOrderedListMappedCommandStream<TKey, TNext, TOut>;
|
|
1487
|
+
destroy(): void;
|
|
1488
|
+
/** Build the initial mirror and subscribe to the source once per key. */
|
|
1489
|
+
private ensureWired;
|
|
1490
|
+
private onSourceCommands;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* Map an ordered-list command source element-wise. The result is itself a
|
|
1495
|
+
* source, so it can be mapped again (or via its `.map()` method).
|
|
1496
|
+
*
|
|
1497
|
+
* ```ts
|
|
1498
|
+
* const nodes = createOIMOrderedListMappedCommandStream(stream, {
|
|
1499
|
+
* create: (slot) => engine.makeNode(slot.item),
|
|
1500
|
+
* destroy: (node) => engine.dropNode(node),
|
|
1501
|
+
* });
|
|
1502
|
+
* nodes.subscribeCommands(key, () =>
|
|
1503
|
+
* engine.apply(nodes.consumeCommands(key))
|
|
1504
|
+
* );
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
declare function createOIMOrderedListMappedCommandStream<TKey extends TOIMPk, TIn, TOut>(source: IOIMOrderedListCommandSource<TKey, TIn>, opts: TOIMOrderedListMapOptions<TIn, TOut>): OIMOrderedListMappedCommandStream<TKey, TOut, TIn>;
|
|
1508
|
+
|
|
1341
1509
|
/**
|
|
1342
1510
|
* Animation frame-based scheduler that executes flushes synchronized with the browser's repaint cycle.
|
|
1343
1511
|
* Ideal for UI-related updates that need to be synchronized with rendering.
|
|
@@ -1690,4 +1858,4 @@ declare class OIMEntitiesByIndexKeyArrayBasedSelector<TEntity extends object, TP
|
|
|
1690
1858
|
protected areEqual(prev: readonly (TEntity | undefined)[], next: readonly (TEntity | undefined)[]): boolean;
|
|
1691
1859
|
}
|
|
1692
1860
|
|
|
1693
|
-
export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, type IOIMCarrierResolver, type IOIMComputedEventSource, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, type IOIMIndexStore, type IOIMKeyedUpdateEmitter, type IOIMSubscribable, OIMCarrierKeyedEmitter, OIMCollection, OIMCollectionByPkSelector, OIMCollectionByPksSelector, OIMCollectionChangedFields, OIMCollectionIndexFactory, OIMCollectionIndexManualOrderedArrayBased, OIMCollectionOrderedListCommandStream, OIMCollectionSelectors, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMComputeRuntime, OIMComputed, OIMDBSettings, OIMDerivedCollectionIndexArrayBased, OIMDerivedCollectionIndexSetBased, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntitiesByIndexKeyArrayBasedSelector, OIMEntitiesByIndexKeySetBasedSelector, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerTimeout, OIMIndex, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexPksByKeyArrayBasedSelector, OIMIndexPksByKeySetBasedSelector, OIMIndexPksByKeysArrayBasedSelector, OIMIndexPksByKeysSetBasedSelector, OIMIndexSetBased, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMObjectValueByKeySelector, OIMObjectValuesByKeysSelector, OIMOrderedListCommandStream, OIMPkSelectorFactory, OIMReactiveCollection, OIMReactiveCollectionIndexManualArrayBased, OIMReactiveCollectionIndexManualSetBased, OIMReactiveIndex, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMSelector, type TOIMAnyEntitySlot, type TOIMCollectionEntitiesSelector, type TOIMCollectionEntitySelector, type TOIMCollectionIndexArrayBasedOptions, type TOIMCollectionIndexSetBasedOptions, type TOIMCollectionKit, type TOIMCollectionOptions, type TOIMCollectionOrderedIndexOptions, type TOIMCollectionOrderedListCommandStreamOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMDerivedCollectionIndexArrayBasedOptions, type TOIMDerivedCollectionIndexSetBasedOptions, type TOIMDerivedEntityComparator, type TOIMDerivedEntityOrderSelector, type TOIMDerivedEntityOrderValue, type TOIMDerivedIndexKeySelector, type TOIMEffectOptions, type TOIMEntitySlot, type TOIMEntitySlotResolver, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMPk, type TOIMPkSelector, type TOIMReactiveCollectionFactoryOptions, type TOIMRelationsArrayIndexOptions, type TOIMRelationsDerivedArrayIndexOptions, type TOIMRelationsDerivedSetIndexOptions, type TOIMRelationsOrderedListOptions, type TOIMRelationsSetIndexOptions, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdatePayload, createInPlaceEntityUpdater, createOIMCollectionIndexFactory, createOIMCollectionKit };
|
|
1861
|
+
export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, type IOIMCarrierResolver, type IOIMComputedEventSource, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, type IOIMIndexStore, type IOIMKeyedUpdateEmitter, type IOIMOrderedListCommandSource, type IOIMSubscribable, OIMCarrierKeyedEmitter, OIMCollection, OIMCollectionByPkSelector, OIMCollectionByPksSelector, OIMCollectionChangedFields, OIMCollectionIndexFactory, OIMCollectionIndexManualOrderedArrayBased, OIMCollectionOrderedListCommandStream, OIMCollectionSelectors, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMComputeRuntime, OIMComputed, OIMDBSettings, OIMDerivedCollectionIndexArrayBased, OIMDerivedCollectionIndexSetBased, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntitiesByIndexKeyArrayBasedSelector, OIMEntitiesByIndexKeySetBasedSelector, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerTimeout, OIMIndex, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexPksByKeyArrayBasedSelector, OIMIndexPksByKeySetBasedSelector, OIMIndexPksByKeysArrayBasedSelector, OIMIndexPksByKeysSetBasedSelector, OIMIndexSetBased, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMObjectValueByKeySelector, OIMObjectValuesByKeysSelector, OIMOrderedListCommandStream, OIMOrderedListMappedCommandStream, OIMPkSelectorFactory, OIMReactiveCollection, OIMReactiveCollectionIndexManualArrayBased, OIMReactiveCollectionIndexManualSetBased, OIMReactiveIndex, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMSelector, type TOIMAnyEntitySlot, type TOIMCollectionEntitiesSelector, type TOIMCollectionEntitySelector, type TOIMCollectionIndexArrayBasedOptions, type TOIMCollectionIndexSetBasedOptions, type TOIMCollectionKit, type TOIMCollectionOptions, type TOIMCollectionOrderedIndexOptions, type TOIMCollectionOrderedListCommandStreamOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMDerivedCollectionIndexArrayBasedOptions, type TOIMDerivedCollectionIndexSetBasedOptions, type TOIMDerivedEntityComparator, type TOIMDerivedEntityOrderSelector, type TOIMDerivedEntityOrderValue, type TOIMDerivedIndexKeySelector, type TOIMEffectOptions, type TOIMEntitySlot, type TOIMEntitySlotResolver, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMOrderedListMapOptions, type TOIMPk, type TOIMPkSelector, type TOIMReactiveCollectionFactoryOptions, type TOIMRelationsArrayIndexOptions, type TOIMRelationsDerivedArrayIndexOptions, type TOIMRelationsDerivedSetIndexOptions, type TOIMRelationsOrderedListOptions, type TOIMRelationsSetIndexOptions, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdatePayload, createInPlaceEntityUpdater, createMergeEntityUpdater, createOIMCollectionIndexFactory, createOIMCollectionKit, createOIMOrderedListMappedCommandStream };
|
package/dist/index.d.ts
CHANGED
|
@@ -627,7 +627,20 @@ declare class OIMIndexManualOrderedArrayBased<TKey extends TOIMPk, TItemKey exte
|
|
|
627
627
|
pushSlot(key: TKey, slot: TOIMAnyEntitySlot<TItemKey>): number;
|
|
628
628
|
insertSlotAt(key: TKey, index: number, slot: TOIMAnyEntitySlot<TItemKey>): number;
|
|
629
629
|
removeAt(key: TKey, index: number): TOIMAnyEntitySlot<TItemKey> | undefined;
|
|
630
|
+
/**
|
|
631
|
+
* Remove up to `count` consecutive slots starting at `index`.
|
|
632
|
+
* Returns the number actually removed (clamped to bounds; 0 if nothing).
|
|
633
|
+
*/
|
|
634
|
+
removeRange(key: TKey, index: number, count: number): number;
|
|
630
635
|
move(key: TKey, fromIndex: number, toIndex: number): TOIMAnyEntitySlot<TItemKey> | undefined;
|
|
636
|
+
/** Replace the slot at `index` in place. Returns the safe index, or -1. */
|
|
637
|
+
setSlotAt(key: TKey, index: number, slot: TOIMAnyEntitySlot<TItemKey>): number;
|
|
638
|
+
/**
|
|
639
|
+
* Move up to `count` consecutive slots from `from` to `to`. `to` is in the
|
|
640
|
+
* coordinate space *after* the block is extracted (same as single `move`).
|
|
641
|
+
* Returns the number actually moved (0 if a no-op / out of bounds).
|
|
642
|
+
*/
|
|
643
|
+
moveRange(key: TKey, from: number, to: number, count: number): number;
|
|
631
644
|
resetSlots(key: TKey, slots: readonly TOIMAnyEntitySlot<TItemKey>[]): void;
|
|
632
645
|
private getOrCreateList;
|
|
633
646
|
}
|
|
@@ -712,39 +725,79 @@ declare class OIMUpdateEventEmitter<TKey extends TOIMPk> {
|
|
|
712
725
|
unsubscribeFromKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): void;
|
|
713
726
|
}
|
|
714
727
|
|
|
715
|
-
|
|
728
|
+
/**
|
|
729
|
+
* Incremental command for an ordered per-key list, addressed by position.
|
|
730
|
+
*
|
|
731
|
+
* `item` is whatever the stream stores per element — the command stream uses the
|
|
732
|
+
* entity slot (`TOIMEntitySlot`), so a consumer reads `item.item` for the entity.
|
|
733
|
+
*
|
|
734
|
+
* - `insert` — a single element appears at `index`.
|
|
735
|
+
* - `remove` — `count` elements (default 1, may be > 1) disappear from `index`.
|
|
736
|
+
* - `move` — `count` elements (default 1) move from `from` to `to`.
|
|
737
|
+
* - `set` — the element at `index` is replaced in place.
|
|
738
|
+
* - `reset` — the whole list for the key is replaced by `items`.
|
|
739
|
+
*/
|
|
740
|
+
type TOIMOrderedListCommand<TItem> = {
|
|
716
741
|
type: 'insert';
|
|
717
|
-
pk: TPk;
|
|
718
|
-
slot: TOIMEntitySlot<TEntity, TPk>;
|
|
719
742
|
index: number;
|
|
743
|
+
item: TItem;
|
|
720
744
|
} | {
|
|
721
745
|
type: 'remove';
|
|
722
|
-
pk: TPk;
|
|
723
|
-
slot: TOIMEntitySlot<TEntity, TPk>;
|
|
724
746
|
index: number;
|
|
747
|
+
count?: number;
|
|
725
748
|
} | {
|
|
726
749
|
type: 'move';
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
toIndex: number;
|
|
750
|
+
from: number;
|
|
751
|
+
to: number;
|
|
752
|
+
count?: number;
|
|
731
753
|
} | {
|
|
732
|
-
/**
|
|
733
|
-
* Replace the whole list for this key (preferred name).
|
|
734
|
-
*/
|
|
735
754
|
type: 'set';
|
|
736
|
-
|
|
737
|
-
|
|
755
|
+
index: number;
|
|
756
|
+
item: TItem;
|
|
757
|
+
} | {
|
|
758
|
+
type: 'reset';
|
|
759
|
+
items: readonly TItem[];
|
|
738
760
|
};
|
|
739
761
|
|
|
762
|
+
/**
|
|
763
|
+
* Read/consume side of an ordered-list command stream, generic over the element
|
|
764
|
+
* type it carries.
|
|
765
|
+
*
|
|
766
|
+
* The concrete stream stores entity slots (`TItem = TOIMEntitySlot<...>`); a
|
|
767
|
+
* mapped source ({@link OIMOrderedListMappedCommandStream}) carries whatever the
|
|
768
|
+
* mapping produces. A consumer that depends on this interface works unchanged
|
|
769
|
+
* against either — raw or mapped.
|
|
770
|
+
*
|
|
771
|
+
* Consumption is pull-based and synchronous: the notification carries no
|
|
772
|
+
* payload, so `consumeCommands(key)` must be called inside the `handler`, before
|
|
773
|
+
* the buffer for that key is cleared.
|
|
774
|
+
*/
|
|
775
|
+
interface IOIMOrderedListCommandSource<TKey extends TOIMPk, TItem> {
|
|
776
|
+
/**
|
|
777
|
+
* Subscribe to per-key command notifications. The handler receives no
|
|
778
|
+
* payload — pull the commands with {@link consumeCommands} synchronously.
|
|
779
|
+
* Returns an unsubscribe function.
|
|
780
|
+
*/
|
|
781
|
+
subscribeCommands(key: TKey, handler: () => void): () => void;
|
|
782
|
+
/** Drain the commands buffered for `key` this delivery (a copy). */
|
|
783
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TItem>[];
|
|
784
|
+
/** Current ordered items for `key` — the initial state before any command. */
|
|
785
|
+
getItemsByKey(key: TKey): readonly TItem[];
|
|
786
|
+
}
|
|
787
|
+
|
|
740
788
|
/**
|
|
741
789
|
* Slot-first ordered-list command stream.
|
|
742
790
|
*
|
|
743
|
-
*
|
|
744
|
-
*
|
|
791
|
+
* Emits position-addressed {@link TOIMOrderedListCommand}s whose `item` is the
|
|
792
|
+
* entity slot. Use this when you already have slots and want incremental
|
|
793
|
+
* commands for an imperative renderer. For PK writes bound to a collection, use
|
|
745
794
|
* `OIMCollectionOrderedListCommandStream`.
|
|
795
|
+
*
|
|
796
|
+
* Implements {@link IOIMOrderedListCommandSource} (with the slot as the element)
|
|
797
|
+
* so it can be projected element-wise via
|
|
798
|
+
* `createOIMOrderedListMappedCommandStream`.
|
|
746
799
|
*/
|
|
747
|
-
declare class OIMOrderedListCommandStream<TKey extends TOIMPk, TPk extends TOIMPk, TEntity extends object = object> {
|
|
800
|
+
declare class OIMOrderedListCommandStream<TKey extends TOIMPk, TPk extends TOIMPk, TEntity extends object = object> implements IOIMOrderedListCommandSource<TKey, TOIMEntitySlot<TEntity, TPk>> {
|
|
748
801
|
readonly commandsEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
749
802
|
private readonly unsubscribeAfterFlush;
|
|
750
803
|
private readonly unsubscribeFromIndexEmitter;
|
|
@@ -755,24 +808,37 @@ declare class OIMOrderedListCommandStream<TKey extends TOIMPk, TPk extends TOIMP
|
|
|
755
808
|
constructor(queue: OIMEventQueue, index?: OIMIndexManualOrderedArrayBased<TKey, TPk>);
|
|
756
809
|
getPksByKey(key: TKey): readonly TPk[];
|
|
757
810
|
getSlotsByKey(key: TKey): readonly TOIMEntitySlot<TEntity, TPk>[];
|
|
811
|
+
/** {@link IOIMOrderedListCommandSource} — alias of {@link getSlotsByKey}. */
|
|
812
|
+
getItemsByKey(key: TKey): readonly TOIMEntitySlot<TEntity, TPk>[];
|
|
813
|
+
/** {@link IOIMOrderedListCommandSource} — per-key command subscription. */
|
|
814
|
+
subscribeCommands(key: TKey, handler: () => void): () => void;
|
|
758
815
|
getEntitiesByKey(key: TKey): (TEntity | undefined)[];
|
|
759
816
|
hasKey(key: TKey): boolean;
|
|
760
817
|
getKeys(): readonly TKey[];
|
|
761
818
|
pushSlot(key: TKey, slot: TOIMEntitySlot<TEntity, TPk>): void;
|
|
762
819
|
insertSlotAt(key: TKey, index: number, slot: TOIMEntitySlot<TEntity, TPk>): void;
|
|
820
|
+
/** Replace the slot at `index` in place. */
|
|
821
|
+
setSlotAt(key: TKey, index: number, slot: TOIMEntitySlot<TEntity, TPk>): void;
|
|
763
822
|
removeAt(key: TKey, index: number): void;
|
|
823
|
+
/** Remove `count` consecutive elements from `index`; emits `remove` with `count`. */
|
|
824
|
+
removeRange(key: TKey, index: number, count: number): void;
|
|
764
825
|
move(key: TKey, fromIndex: number, toIndex: number): void;
|
|
826
|
+
/**
|
|
827
|
+
* Move `count` consecutive elements from `from` to `to`; emits `move` with
|
|
828
|
+
* `count`. `to` is in the post-extraction coordinate space (as single `move`).
|
|
829
|
+
*/
|
|
830
|
+
moveRange(key: TKey, from: number, to: number, count: number): void;
|
|
765
831
|
setSlots(key: TKey, slots: readonly TOIMEntitySlot<TEntity, TPk>[]): void;
|
|
766
|
-
getBufferedCommands(key: TKey): readonly TOIMOrderedListCommand<
|
|
767
|
-
consumeCommands(key: TKey): TOIMOrderedListCommand<
|
|
832
|
+
getBufferedCommands(key: TKey): readonly TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>[];
|
|
833
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>[];
|
|
768
834
|
clear(key?: TKey): void;
|
|
769
835
|
destroy(): void;
|
|
770
836
|
private readonly onAfterFlush;
|
|
771
837
|
private readonly onIndexUpdate;
|
|
772
838
|
protected withWrite(fn: () => void): void;
|
|
773
|
-
protected appendCommand(key: TKey, cmd: TOIMOrderedListCommand<
|
|
774
|
-
protected
|
|
775
|
-
protected
|
|
839
|
+
protected appendCommand(key: TKey, cmd: TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>): void;
|
|
840
|
+
protected appendResetCommand(key: TKey, slots: readonly TOIMEntitySlot<TEntity, TPk>[]): void;
|
|
841
|
+
protected createResetCommand(slots: readonly TOIMEntitySlot<TEntity, TPk>[]): TOIMOrderedListCommand<TOIMEntitySlot<TEntity, TPk>>;
|
|
776
842
|
}
|
|
777
843
|
|
|
778
844
|
/**
|
|
@@ -785,6 +851,8 @@ declare class OIMCollectionOrderedListCommandStream<TKey extends TOIMPk, TPk ext
|
|
|
785
851
|
constructor(queue: OIMEventQueue, opts: TOIMCollectionOrderedListCommandStreamOptions<TKey, TPk, TEntity>);
|
|
786
852
|
push(key: TKey, pk: TPk): void;
|
|
787
853
|
insertAt(key: TKey, index: number, pk: TPk): void;
|
|
854
|
+
/** Replace the element at `index` with the slot for `pk`, in place. */
|
|
855
|
+
setAt(key: TKey, index: number, pk: TPk): void;
|
|
788
856
|
set(key: TKey, pks: readonly TPk[]): void;
|
|
789
857
|
getSlotsByKey(key: TKey): readonly TOIMEntitySlot<TEntity, TPk>[];
|
|
790
858
|
getEntitiesByKey(key: TKey): (TEntity | undefined)[];
|
|
@@ -1149,6 +1217,18 @@ declare class OIMEntityUpdaterFactory<TEntity extends object> {
|
|
|
1149
1217
|
*/
|
|
1150
1218
|
declare function createInPlaceEntityUpdater<TEntity extends object>(): TOIMEntityUpdater<TEntity>;
|
|
1151
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* Default entity updater: shallow-merges the patch into a NEW object
|
|
1222
|
+
* (`{ ...prev, ...draft }`). Each update produces a fresh entity reference, which
|
|
1223
|
+
* reference-comparison bindings (React's `Object.is` / `useSyncExternalStore`,
|
|
1224
|
+
* `React.memo`, prev/next diffing, time-travel) need to detect a change.
|
|
1225
|
+
*
|
|
1226
|
+
* The new-object allocation is the biggest per-update data-layer cost; for
|
|
1227
|
+
* update-heavy, subscription-driven readers use {@link createInPlaceEntityUpdater}
|
|
1228
|
+
* instead.
|
|
1229
|
+
*/
|
|
1230
|
+
declare function createMergeEntityUpdater<TEntity extends object>(): TOIMEntityUpdater<TEntity>;
|
|
1231
|
+
|
|
1152
1232
|
/**
|
|
1153
1233
|
* Factory for creating index comparators.
|
|
1154
1234
|
* Provides common comparison strategies for primary key arrays.
|
|
@@ -1297,9 +1377,11 @@ declare class OIMCollectionChangedFields<TEntity extends object, TPk extends TOI
|
|
|
1297
1377
|
readonly collection: OIMCollection<TEntity, TPk>;
|
|
1298
1378
|
private readonly selectPk;
|
|
1299
1379
|
private readonly unsubscribeAfterFlush;
|
|
1300
|
-
private readonly unsubscribeFromCollectionEmitter
|
|
1380
|
+
private readonly unsubscribeFromCollectionEmitter?;
|
|
1381
|
+
private readonly detectExternalMutations;
|
|
1301
1382
|
private isInWrite;
|
|
1302
1383
|
private readonly lastEntitySnapshotByPk;
|
|
1384
|
+
private readonly writtenThroughThisFlush;
|
|
1303
1385
|
/**
|
|
1304
1386
|
* Emits updates scoped by PK. Subscribe, then read state via `getChangedFieldsByPk(...)`
|
|
1305
1387
|
* or drain via `consumeChangedFieldsByPk(...)`.
|
|
@@ -1318,6 +1400,18 @@ declare class OIMCollectionChangedFields<TEntity extends object, TPk extends TOI
|
|
|
1318
1400
|
* If not provided, only `upsertOneByPk(...)` should be used.
|
|
1319
1401
|
*/
|
|
1320
1402
|
selectPk?: (entity: TEntity | Partial<TEntity>) => TPk;
|
|
1403
|
+
/**
|
|
1404
|
+
* Detect writes that bypass this wrapper (direct collection
|
|
1405
|
+
* mutations) by diffing entity snapshots. Default `true`.
|
|
1406
|
+
*
|
|
1407
|
+
* Set to `false` when you always write through this wrapper: it
|
|
1408
|
+
* drops the per-write snapshot clone and the per-PK snapshot map
|
|
1409
|
+
* (~2x entity memory), since those exist only to power external
|
|
1410
|
+
* detection. The shallow diff also can't see deep in-place
|
|
1411
|
+
* mutations anyway — so if that's your model, opting out costs you
|
|
1412
|
+
* nothing it could have caught.
|
|
1413
|
+
*/
|
|
1414
|
+
detectExternalMutations?: boolean;
|
|
1321
1415
|
});
|
|
1322
1416
|
upsertOneByPk(pk: TPk, patch: Partial<TEntity>): TOIMEntitySlot<TEntity, TPk>;
|
|
1323
1417
|
upsertOne(entity: TEntity | Partial<TEntity>): TOIMEntitySlot<TEntity, TPk>;
|
|
@@ -1338,6 +1432,80 @@ declare class OIMCollectionChangedFields<TEntity extends object, TPk extends TOI
|
|
|
1338
1432
|
private trackPatch;
|
|
1339
1433
|
}
|
|
1340
1434
|
|
|
1435
|
+
/**
|
|
1436
|
+
* Options for {@link OIMOrderedListMappedCommandStream} — how a source element
|
|
1437
|
+
* (`TIn`) is projected to a downstream element (`TOut`) and torn down.
|
|
1438
|
+
*
|
|
1439
|
+
* `create` runs once per element when it enters the list (an `insert`, a `set`
|
|
1440
|
+
* replacement, or list build / `reset`). `destroy` runs when it leaves (a
|
|
1441
|
+
* `remove`, the replaced half of a `set`, every element on `reset`, and on
|
|
1442
|
+
* stream `destroy()`). A `move` reuses the same `TOut` — it is never recreated.
|
|
1443
|
+
*/
|
|
1444
|
+
type TOIMOrderedListMapOptions<TIn, TOut> = {
|
|
1445
|
+
create: (item: TIn) => TOut;
|
|
1446
|
+
destroy?: (mapped: TOut) => void;
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
/**
|
|
1450
|
+
* Projects an ordered-list command source element-wise, re-emitting the same
|
|
1451
|
+
* position-addressed commands with `item` replaced by the mapped value.
|
|
1452
|
+
*
|
|
1453
|
+
* It rides the source's batching: there is no queue and no independent
|
|
1454
|
+
* scheduling. On each source notification it pulls the source commands,
|
|
1455
|
+
* translates them (running `create` / `destroy` and updating a positional
|
|
1456
|
+
* mirror of the mapped elements), and notifies its own subscribers
|
|
1457
|
+
* synchronously — so the source's `after_flush` semantics carry through.
|
|
1458
|
+
*
|
|
1459
|
+
* Identity is positional: a `move` reorders the *same* mapped references in the
|
|
1460
|
+
* mirror, so the mapped element is preserved across moves and never recreated.
|
|
1461
|
+
* `create` runs on `insert` / `set` / `reset` / initial build; `destroy` on
|
|
1462
|
+
* `remove` / the replaced half of `set` / every element on `reset` / `destroy()`.
|
|
1463
|
+
*
|
|
1464
|
+
* Wiring to the source for a key is lazy (on first `subscribeCommands` or
|
|
1465
|
+
* `getItemsByKey`) and lives until `destroy()`; subscriber churn does not
|
|
1466
|
+
* create or tear down mapped elements.
|
|
1467
|
+
*
|
|
1468
|
+
* The output is itself an {@link IOIMOrderedListCommandSource}, so maps chain:
|
|
1469
|
+
* `source.map(...)` → `.map(...)`.
|
|
1470
|
+
*/
|
|
1471
|
+
declare class OIMOrderedListMappedCommandStream<TKey extends TOIMPk, TOut, TIn> implements IOIMOrderedListCommandSource<TKey, TOut> {
|
|
1472
|
+
private readonly source;
|
|
1473
|
+
private readonly create;
|
|
1474
|
+
private readonly destroyItem?;
|
|
1475
|
+
/** Per-key positional mirror of the mapped elements. */
|
|
1476
|
+
private readonly mirror;
|
|
1477
|
+
/** Mapped commands produced for the current delivery, per key. */
|
|
1478
|
+
private readonly buffer;
|
|
1479
|
+
private readonly subscribers;
|
|
1480
|
+
private readonly sourceUnsubscribers;
|
|
1481
|
+
constructor(source: IOIMOrderedListCommandSource<TKey, TIn>, opts: TOIMOrderedListMapOptions<TIn, TOut>);
|
|
1482
|
+
subscribeCommands(key: TKey, handler: () => void): () => void;
|
|
1483
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TOut>[];
|
|
1484
|
+
getItemsByKey(key: TKey): readonly TOut[];
|
|
1485
|
+
/** Map this source again, chaining the projection. */
|
|
1486
|
+
map<TNext>(opts: TOIMOrderedListMapOptions<TOut, TNext>): OIMOrderedListMappedCommandStream<TKey, TNext, TOut>;
|
|
1487
|
+
destroy(): void;
|
|
1488
|
+
/** Build the initial mirror and subscribe to the source once per key. */
|
|
1489
|
+
private ensureWired;
|
|
1490
|
+
private onSourceCommands;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* Map an ordered-list command source element-wise. The result is itself a
|
|
1495
|
+
* source, so it can be mapped again (or via its `.map()` method).
|
|
1496
|
+
*
|
|
1497
|
+
* ```ts
|
|
1498
|
+
* const nodes = createOIMOrderedListMappedCommandStream(stream, {
|
|
1499
|
+
* create: (slot) => engine.makeNode(slot.item),
|
|
1500
|
+
* destroy: (node) => engine.dropNode(node),
|
|
1501
|
+
* });
|
|
1502
|
+
* nodes.subscribeCommands(key, () =>
|
|
1503
|
+
* engine.apply(nodes.consumeCommands(key))
|
|
1504
|
+
* );
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
declare function createOIMOrderedListMappedCommandStream<TKey extends TOIMPk, TIn, TOut>(source: IOIMOrderedListCommandSource<TKey, TIn>, opts: TOIMOrderedListMapOptions<TIn, TOut>): OIMOrderedListMappedCommandStream<TKey, TOut, TIn>;
|
|
1508
|
+
|
|
1341
1509
|
/**
|
|
1342
1510
|
* Animation frame-based scheduler that executes flushes synchronized with the browser's repaint cycle.
|
|
1343
1511
|
* Ideal for UI-related updates that need to be synchronized with rendering.
|
|
@@ -1690,4 +1858,4 @@ declare class OIMEntitiesByIndexKeyArrayBasedSelector<TEntity extends object, TP
|
|
|
1690
1858
|
protected areEqual(prev: readonly (TEntity | undefined)[], next: readonly (TEntity | undefined)[]): boolean;
|
|
1691
1859
|
}
|
|
1692
1860
|
|
|
1693
|
-
export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, type IOIMCarrierResolver, type IOIMComputedEventSource, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, type IOIMIndexStore, type IOIMKeyedUpdateEmitter, type IOIMSubscribable, OIMCarrierKeyedEmitter, OIMCollection, OIMCollectionByPkSelector, OIMCollectionByPksSelector, OIMCollectionChangedFields, OIMCollectionIndexFactory, OIMCollectionIndexManualOrderedArrayBased, OIMCollectionOrderedListCommandStream, OIMCollectionSelectors, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMComputeRuntime, OIMComputed, OIMDBSettings, OIMDerivedCollectionIndexArrayBased, OIMDerivedCollectionIndexSetBased, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntitiesByIndexKeyArrayBasedSelector, OIMEntitiesByIndexKeySetBasedSelector, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerTimeout, OIMIndex, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexPksByKeyArrayBasedSelector, OIMIndexPksByKeySetBasedSelector, OIMIndexPksByKeysArrayBasedSelector, OIMIndexPksByKeysSetBasedSelector, OIMIndexSetBased, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMObjectValueByKeySelector, OIMObjectValuesByKeysSelector, OIMOrderedListCommandStream, OIMPkSelectorFactory, OIMReactiveCollection, OIMReactiveCollectionIndexManualArrayBased, OIMReactiveCollectionIndexManualSetBased, OIMReactiveIndex, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMSelector, type TOIMAnyEntitySlot, type TOIMCollectionEntitiesSelector, type TOIMCollectionEntitySelector, type TOIMCollectionIndexArrayBasedOptions, type TOIMCollectionIndexSetBasedOptions, type TOIMCollectionKit, type TOIMCollectionOptions, type TOIMCollectionOrderedIndexOptions, type TOIMCollectionOrderedListCommandStreamOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMDerivedCollectionIndexArrayBasedOptions, type TOIMDerivedCollectionIndexSetBasedOptions, type TOIMDerivedEntityComparator, type TOIMDerivedEntityOrderSelector, type TOIMDerivedEntityOrderValue, type TOIMDerivedIndexKeySelector, type TOIMEffectOptions, type TOIMEntitySlot, type TOIMEntitySlotResolver, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMPk, type TOIMPkSelector, type TOIMReactiveCollectionFactoryOptions, type TOIMRelationsArrayIndexOptions, type TOIMRelationsDerivedArrayIndexOptions, type TOIMRelationsDerivedSetIndexOptions, type TOIMRelationsOrderedListOptions, type TOIMRelationsSetIndexOptions, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdatePayload, createInPlaceEntityUpdater, createOIMCollectionIndexFactory, createOIMCollectionKit };
|
|
1861
|
+
export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, type IOIMCarrierResolver, type IOIMComputedEventSource, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, type IOIMIndexStore, type IOIMKeyedUpdateEmitter, type IOIMOrderedListCommandSource, type IOIMSubscribable, OIMCarrierKeyedEmitter, OIMCollection, OIMCollectionByPkSelector, OIMCollectionByPksSelector, OIMCollectionChangedFields, OIMCollectionIndexFactory, OIMCollectionIndexManualOrderedArrayBased, OIMCollectionOrderedListCommandStream, OIMCollectionSelectors, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMComputeRuntime, OIMComputed, OIMDBSettings, OIMDerivedCollectionIndexArrayBased, OIMDerivedCollectionIndexSetBased, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntitiesByIndexKeyArrayBasedSelector, OIMEntitiesByIndexKeySetBasedSelector, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerTimeout, OIMIndex, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexPksByKeyArrayBasedSelector, OIMIndexPksByKeySetBasedSelector, OIMIndexPksByKeysArrayBasedSelector, OIMIndexPksByKeysSetBasedSelector, OIMIndexSetBased, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMObjectValueByKeySelector, OIMObjectValuesByKeysSelector, OIMOrderedListCommandStream, OIMOrderedListMappedCommandStream, OIMPkSelectorFactory, OIMReactiveCollection, OIMReactiveCollectionIndexManualArrayBased, OIMReactiveCollectionIndexManualSetBased, OIMReactiveIndex, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMSelector, type TOIMAnyEntitySlot, type TOIMCollectionEntitiesSelector, type TOIMCollectionEntitySelector, type TOIMCollectionIndexArrayBasedOptions, type TOIMCollectionIndexSetBasedOptions, type TOIMCollectionKit, type TOIMCollectionOptions, type TOIMCollectionOrderedIndexOptions, type TOIMCollectionOrderedListCommandStreamOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMDerivedCollectionIndexArrayBasedOptions, type TOIMDerivedCollectionIndexSetBasedOptions, type TOIMDerivedEntityComparator, type TOIMDerivedEntityOrderSelector, type TOIMDerivedEntityOrderValue, type TOIMDerivedIndexKeySelector, type TOIMEffectOptions, type TOIMEntitySlot, type TOIMEntitySlotResolver, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMOrderedListMapOptions, type TOIMPk, type TOIMPkSelector, type TOIMReactiveCollectionFactoryOptions, type TOIMRelationsArrayIndexOptions, type TOIMRelationsDerivedArrayIndexOptions, type TOIMRelationsDerivedSetIndexOptions, type TOIMRelationsOrderedListOptions, type TOIMRelationsSetIndexOptions, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdatePayload, createInPlaceEntityUpdater, createMergeEntityUpdater, createOIMCollectionIndexFactory, createOIMCollectionKit, createOIMOrderedListMappedCommandStream };
|