@oimdb/core 1.3.1 → 1.4.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 +148 -0
- package/dist/index.cjs +1018 -53
- package/dist/index.d.cts +426 -6
- package/dist/index.d.ts +426 -6
- package/dist/index.js +997 -53
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ declare abstract class OIMCollectionStore<TEntity extends object, TPk extends TO
|
|
|
10
10
|
abstract getAllPks(): TPk[];
|
|
11
11
|
abstract countAll(): number;
|
|
12
12
|
abstract clear(): void;
|
|
13
|
+
abstract destroy(): void;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
declare abstract class OIMIndexStoreSetBased<TKey extends TOIMPk, TPk extends TOIMPk> {
|
|
@@ -41,8 +42,13 @@ type TOIMEventHandler<T> = (payload: T) => void;
|
|
|
41
42
|
declare class OIMEventEmitter<T extends Record<string, unknown>> {
|
|
42
43
|
private buckets;
|
|
43
44
|
private getOrCreateBucket;
|
|
45
|
+
/**
|
|
46
|
+
* Compacts the handlers array by removing null entries (tombstones) left by handler removal.
|
|
47
|
+
* Rebuilds the indexByHandler map with updated indices and resets the tombstone count.
|
|
48
|
+
* This reduces array fragmentation and improves iteration performance.
|
|
49
|
+
*/
|
|
44
50
|
private compactBucket;
|
|
45
|
-
on<K extends keyof T>(event: K, handler: TOIMEventHandler<T[K]>): void;
|
|
51
|
+
on<K extends keyof T>(event: K, handler: TOIMEventHandler<T[K]>): () => void;
|
|
46
52
|
emit<K extends keyof T>(event: K, payload: T[K]): void;
|
|
47
53
|
off<K extends keyof T>(event: K, handler: TOIMEventHandler<T[K]>): void;
|
|
48
54
|
offAll<K extends keyof T>(event?: K): void;
|
|
@@ -262,6 +268,7 @@ declare class OIMDBSettings {
|
|
|
262
268
|
* This constant is exported so users can create their own indexes and pass them to coalescers.
|
|
263
269
|
*/
|
|
264
270
|
static readonly UPDATED_KEYS_INDEX_KEY: "__updatedKeys__";
|
|
271
|
+
static readonly FLUSHING_KEYS_INDEX_KEY: "__flushingKeys__";
|
|
265
272
|
}
|
|
266
273
|
|
|
267
274
|
/**
|
|
@@ -276,16 +283,20 @@ declare abstract class OIMUpdateEventCoalescer<TKey extends TOIMPk> {
|
|
|
276
283
|
2: void;
|
|
277
284
|
}>;
|
|
278
285
|
protected readonly updatedKeysIndex: OIMIndexManualSetBased<typeof OIMDBSettings.UPDATED_KEYS_INDEX_KEY, TKey>;
|
|
286
|
+
protected readonly flushingUpdatedKeysIndex: OIMIndexManualSetBased<typeof OIMDBSettings.FLUSHING_KEYS_INDEX_KEY, TKey>;
|
|
279
287
|
private hasEmittedChanges;
|
|
280
|
-
constructor(index?: OIMIndexManualSetBased<typeof OIMDBSettings.UPDATED_KEYS_INDEX_KEY, TKey>);
|
|
288
|
+
constructor(index?: OIMIndexManualSetBased<typeof OIMDBSettings.UPDATED_KEYS_INDEX_KEY, TKey>, flushingIndex?: OIMIndexManualSetBased<typeof OIMDBSettings.FLUSHING_KEYS_INDEX_KEY, TKey>);
|
|
281
289
|
/**
|
|
282
290
|
* Get the set of keys that have been updated since last clear
|
|
283
291
|
*/
|
|
284
292
|
getUpdatedKeys(): Set<TKey>;
|
|
293
|
+
getFlushingUpdatedKeys(): Set<TKey>;
|
|
294
|
+
markUpdatedKeysAsFlushing(): void;
|
|
285
295
|
/**
|
|
286
296
|
* Clear all updated keys and reset the changed state
|
|
287
297
|
*/
|
|
288
298
|
clearUpdatedKeys(): void;
|
|
299
|
+
clearFlushingUpdatedKeys(): void;
|
|
289
300
|
/**
|
|
290
301
|
* Add keys to the updated set and emit HAS_CHANGES event if needed
|
|
291
302
|
*/
|
|
@@ -321,6 +332,8 @@ declare class OIMEventQueue {
|
|
|
321
332
|
protected queue: (() => void)[];
|
|
322
333
|
protected readonly scheduler?: OIMEventQueueScheduler;
|
|
323
334
|
protected flushBound?: () => void;
|
|
335
|
+
protected isFlushing: boolean;
|
|
336
|
+
protected pendingSchedule: boolean;
|
|
324
337
|
constructor(options?: TOIMEventQueueOptions);
|
|
325
338
|
/**
|
|
326
339
|
* Add a function to the queue. If scheduler is configured and autoSchedule is enabled,
|
|
@@ -362,11 +375,23 @@ type TOIMUpdateEventEmitterOptions<TKey extends TOIMPk> = {
|
|
|
362
375
|
* Optimized for performance with adaptive algorithms and memory management.
|
|
363
376
|
*/
|
|
364
377
|
declare class OIMUpdateEventEmitter<TKey extends TOIMPk> {
|
|
378
|
+
protected keyHandlersBeforeFlush: Map<TKey, Set<TOIMEventHandler<void>>>;
|
|
365
379
|
protected keyHandlers: Map<TKey, Set<TOIMEventHandler<void>>>;
|
|
366
380
|
protected coalescer: OIMUpdateEventCoalescer<TKey>;
|
|
367
381
|
protected queue: OIMEventQueue;
|
|
382
|
+
private isDestroyed;
|
|
383
|
+
private isDispatching;
|
|
384
|
+
private isInPrePhase;
|
|
385
|
+
private hasPendingDuringPrePhase;
|
|
386
|
+
private isFlushEnqueued;
|
|
368
387
|
constructor(opts: TOIMUpdateEventEmitterOptions<TKey>);
|
|
369
388
|
protected handleHasChanges: () => void;
|
|
389
|
+
protected readonly onFlush: () => void;
|
|
390
|
+
/**
|
|
391
|
+
* Helps to run computed values etc.
|
|
392
|
+
*/
|
|
393
|
+
protected runPrePhaseDrain(makeHandlerSnapshot: (handlers: Set<TOIMEventHandler<void>>) => TOIMEventHandler<void>[]): Set<TKey>;
|
|
394
|
+
protected runHandlersPhase(allKeysForNormalPhase: ReadonlySet<TKey>, makeHandlerSnapshot: (handlers: Set<TOIMEventHandler<void>>) => TOIMEventHandler<void>[]): void;
|
|
370
395
|
destroy(): void;
|
|
371
396
|
/**
|
|
372
397
|
* Get performance metrics for monitoring and debugging
|
|
@@ -385,9 +410,13 @@ declare class OIMUpdateEventEmitter<TKey extends TOIMPk> {
|
|
|
385
410
|
* Get the number of handlers for a specific key
|
|
386
411
|
*/
|
|
387
412
|
getHandlerCount(key: TKey): number;
|
|
413
|
+
subscribeOnKeyBeforeFlush(key: TKey, handler: TOIMEventHandler<void>): () => void;
|
|
414
|
+
unsubscribeFromKeyBeforeFlush(key: TKey, handler: TOIMEventHandler<void>): void;
|
|
388
415
|
subscribeOnKey(key: TKey, handler: TOIMEventHandler<void>): () => void;
|
|
389
416
|
unsubscribeFromKey(key: TKey, handler: TOIMEventHandler<void>): void;
|
|
390
417
|
subscribeOnKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): () => void;
|
|
418
|
+
subscribeOnKeysBeforeFlush(keys: readonly TKey[], handler: TOIMEventHandler<void>): () => void;
|
|
419
|
+
unsubscribeFromKeysBeforeFlush(keys: readonly TKey[], handler: TOIMEventHandler<void>): void;
|
|
391
420
|
unsubscribeFromKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): void;
|
|
392
421
|
}
|
|
393
422
|
|
|
@@ -461,6 +490,20 @@ declare abstract class OIMReactiveIndexArrayBased<TKey extends TOIMPk, TPk exten
|
|
|
461
490
|
destroy(): void;
|
|
462
491
|
}
|
|
463
492
|
|
|
493
|
+
declare abstract class OIMObjectStore<TKey extends string | number | symbol, TValue> {
|
|
494
|
+
abstract setProperty(key: TKey, value: TValue): void;
|
|
495
|
+
abstract merge(draft: Partial<Record<TKey, TValue>>): void;
|
|
496
|
+
abstract delete(key: TKey): void;
|
|
497
|
+
abstract get(key: TKey): TValue | undefined;
|
|
498
|
+
abstract getAll(): Record<TKey, TValue>;
|
|
499
|
+
abstract clear(): void;
|
|
500
|
+
abstract count(): number;
|
|
501
|
+
abstract keys(): TKey[];
|
|
502
|
+
abstract values(): TValue[];
|
|
503
|
+
abstract entries(): [TKey, TValue][];
|
|
504
|
+
abstract destroy(): void;
|
|
505
|
+
}
|
|
506
|
+
|
|
464
507
|
type TOIMPkSelector<TEntity extends object, TPk extends TOIMPk> = (entity: TEntity) => TPk;
|
|
465
508
|
|
|
466
509
|
type TOIMEntityUpdater<TEntity extends object> = (draft: Partial<TEntity>, prevEntity: TEntity) => TEntity;
|
|
@@ -499,6 +542,7 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
499
542
|
getAllPks(): TPk[];
|
|
500
543
|
protected upsertOneWithoutNotifications(entity: TEntity | Partial<TEntity>): TPk;
|
|
501
544
|
protected upsertOneWithoutNotificationsByPk(pk: TPk, entity: Partial<TEntity> | TEntity): void;
|
|
545
|
+
destroy(): void;
|
|
502
546
|
}
|
|
503
547
|
|
|
504
548
|
declare enum EOIMCollectionEventType {
|
|
@@ -525,6 +569,64 @@ declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMPk>
|
|
|
525
569
|
readonly updateEventEmitter: OIMUpdateEventEmitter<TPk>;
|
|
526
570
|
readonly coalescer: OIMUpdateEventCoalescerCollection<TPk>;
|
|
527
571
|
constructor(queue: OIMEventQueue, opts?: TOIMCollectionOptions<TEntity, TPk>);
|
|
572
|
+
destroy(): void;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Payload type for update events that contain keys */
|
|
577
|
+
type TOIMUpdatePayload<TKey> = {
|
|
578
|
+
keys: readonly TKey[];
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
type TOIMObjectOptions<TKey extends string, TValue> = {
|
|
582
|
+
store?: OIMObjectStore<TKey, TValue>;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
/** It's like a store - but with event emitter */
|
|
586
|
+
declare class OIMObject<TKey extends string, TValue> {
|
|
587
|
+
readonly emitter: OIMEventEmitter<{
|
|
588
|
+
0: TOIMUpdatePayload<TKey>;
|
|
589
|
+
}>;
|
|
590
|
+
protected readonly store: OIMObjectStore<TKey, TValue>;
|
|
591
|
+
constructor(opts?: TOIMObjectOptions<TKey, TValue>);
|
|
592
|
+
setProperty(key: TKey, value: TValue): void;
|
|
593
|
+
merge(draft: Partial<Record<TKey, TValue>>): void;
|
|
594
|
+
delete(key: TKey): void;
|
|
595
|
+
get(key: TKey): TValue | undefined;
|
|
596
|
+
getAll(): Record<TKey, TValue>;
|
|
597
|
+
clear(): void;
|
|
598
|
+
count(): number;
|
|
599
|
+
keys(): TKey[];
|
|
600
|
+
values(): TValue[];
|
|
601
|
+
entries(): [TKey, TValue][];
|
|
602
|
+
destroy(): void;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
declare enum EOIMObjectEventType {
|
|
606
|
+
UPDATE = 0
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Object-specific coalescer that tracks property key updates and emits consolidated change events.
|
|
611
|
+
* Takes an event emitter directly instead of the whole object to avoid circular dependencies.
|
|
612
|
+
*/
|
|
613
|
+
declare class OIMUpdateEventCoalescerObject<TKey extends string> extends OIMUpdateEventCoalescer<TKey> {
|
|
614
|
+
private readonly objectEmitter;
|
|
615
|
+
constructor(objectEmitter: OIMEventEmitter<{
|
|
616
|
+
[EOIMObjectEventType.UPDATE]: TOIMUpdatePayload<TKey>;
|
|
617
|
+
}>);
|
|
618
|
+
destroy(): void;
|
|
619
|
+
/**
|
|
620
|
+
* When the object is updated, we keep track of the updated keys.
|
|
621
|
+
*/
|
|
622
|
+
private handleUpdate;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
declare class OIMReactiveObject<TKey extends string, TValue> extends OIMObject<TKey, TValue> {
|
|
626
|
+
readonly updateEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
627
|
+
readonly coalescer: OIMUpdateEventCoalescerObject<TKey>;
|
|
628
|
+
constructor(queue: OIMEventQueue, opts?: TOIMObjectOptions<TKey, TValue>);
|
|
629
|
+
destroy(): void;
|
|
528
630
|
}
|
|
529
631
|
|
|
530
632
|
declare class OIMReactiveIndexManualSetBased<TKey extends TOIMPk, TPk extends TOIMPk> extends OIMReactiveIndexSetBased<TKey, TPk, OIMIndexManualSetBased<TKey, TPk>> {
|
|
@@ -598,6 +700,44 @@ declare class OIMCollectionStoreMapDriven<TEntity extends object, TPk extends TO
|
|
|
598
700
|
countAll(): number;
|
|
599
701
|
clear(): void;
|
|
600
702
|
getAllPks(): TPk[];
|
|
703
|
+
destroy(): void;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
declare class OIMObjectStoreMapDriven<TKey extends TOIMPk, TValue> extends OIMObjectStore<TKey, TValue> {
|
|
707
|
+
protected readonly properties: Map<TKey, TValue>;
|
|
708
|
+
setProperty(key: TKey, value: TValue): void;
|
|
709
|
+
merge(draft: Partial<Record<TKey, TValue>>): void;
|
|
710
|
+
delete(key: TKey): void;
|
|
711
|
+
get(key: TKey): TValue | undefined;
|
|
712
|
+
getAll(): Record<TKey, TValue>;
|
|
713
|
+
clear(): void;
|
|
714
|
+
count(): number;
|
|
715
|
+
keys(): TKey[];
|
|
716
|
+
values(): TValue[];
|
|
717
|
+
entries(): [TKey, TValue][];
|
|
718
|
+
destroy(): void;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Record-driven store (plain object) for OIMObject.
|
|
723
|
+
*
|
|
724
|
+
* Note: object keys are strings at runtime, so this store is limited to string keys
|
|
725
|
+
* for type-safety and predictable semantics.
|
|
726
|
+
*/
|
|
727
|
+
declare class OIMObjectStoreRecordDriven<TKey extends string, TValue> extends OIMObjectStore<TKey, TValue> {
|
|
728
|
+
protected properties: Record<TKey, TValue>;
|
|
729
|
+
constructor(initial?: Partial<Record<TKey, TValue>>);
|
|
730
|
+
setProperty(key: TKey, value: TValue): void;
|
|
731
|
+
merge(draft: Partial<Record<TKey, TValue>>): void;
|
|
732
|
+
delete(key: TKey): void;
|
|
733
|
+
get(key: TKey): TValue | undefined;
|
|
734
|
+
getAll(): Record<TKey, TValue>;
|
|
735
|
+
clear(): void;
|
|
736
|
+
count(): number;
|
|
737
|
+
keys(): TKey[];
|
|
738
|
+
values(): TValue[];
|
|
739
|
+
entries(): [TKey, TValue][];
|
|
740
|
+
destroy(): void;
|
|
601
741
|
}
|
|
602
742
|
|
|
603
743
|
declare class OIMIndexStoreMapDrivenSetBased<TKey extends TOIMPk, TPk extends TOIMPk> extends OIMIndexStoreSetBased<TKey, TPk> {
|
|
@@ -680,6 +820,139 @@ declare class OIMPkSelectorFactory<TEntity extends object, TPk extends TOIMPk> {
|
|
|
680
820
|
}, TPk>;
|
|
681
821
|
}
|
|
682
822
|
|
|
823
|
+
/**
|
|
824
|
+
* Manual coalescer: you mark keys as updated explicitly.
|
|
825
|
+
*
|
|
826
|
+
* Useful for wrappers that maintain their own "derived" state (e.g. change-sets, command streams)
|
|
827
|
+
* and want to reuse `OIMUpdateEventEmitter` batching/reentrancy semantics without piggybacking
|
|
828
|
+
* on a collection/index/object emitter payload.
|
|
829
|
+
*/
|
|
830
|
+
declare class OIMUpdateEventCoalescerManual<TKey extends TOIMPk> extends OIMUpdateEventCoalescer<TKey> {
|
|
831
|
+
markUpdatedKeys(keys: readonly TKey[]): void;
|
|
832
|
+
destroy(): void;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
type TOIMFieldKey<TEntity extends object> = keyof TEntity & string;
|
|
836
|
+
/**
|
|
837
|
+
* Wrapper around `OIMReactiveCollection` that tracks "changed fields" per entity PK.
|
|
838
|
+
*
|
|
839
|
+
* Important: to get field-level info, you must perform writes through this wrapper.
|
|
840
|
+
* If you mutate the underlying collection directly, this wrapper will not be able
|
|
841
|
+
* to infer which fields changed (core update payloads carry only PKs).
|
|
842
|
+
*/
|
|
843
|
+
declare class OIMCollectionChangedFieldsWrapper<TEntity extends object, TPk extends TOIMPk> {
|
|
844
|
+
readonly collection: OIMReactiveCollection<TEntity, TPk>;
|
|
845
|
+
private readonly selectPk;
|
|
846
|
+
/**
|
|
847
|
+
* Emits updates scoped by PK. Subscribe, then read state via `getChangedFieldsByPk(...)`
|
|
848
|
+
* or drain via `consumeChangedFieldsByPk(...)`.
|
|
849
|
+
*/
|
|
850
|
+
readonly changedPksEventEmitter: OIMUpdateEventEmitter<TPk>;
|
|
851
|
+
/**
|
|
852
|
+
* Emits updates scoped by field name. Subscribe, then read state via
|
|
853
|
+
* `getChangedPksByField(...)` or drain via `consumeChangedPksByField(...)`.
|
|
854
|
+
*/
|
|
855
|
+
readonly changedFieldsEventEmitter: OIMUpdateEventEmitter<TOIMFieldKey<TEntity>>;
|
|
856
|
+
private readonly changedFieldsByPk;
|
|
857
|
+
private readonly changedPksByField;
|
|
858
|
+
private readonly changedPksCoalescer;
|
|
859
|
+
private readonly changedFieldsCoalescer;
|
|
860
|
+
constructor(queue: OIMEventQueue, collection: OIMReactiveCollection<TEntity, TPk>, opts?: {
|
|
861
|
+
/**
|
|
862
|
+
* Optional PK selector for convenience APIs like `upsertOne(...)`.
|
|
863
|
+
* If not provided, only `upsertOneByPk(...)` should be used.
|
|
864
|
+
*/
|
|
865
|
+
selectPk?: (entity: TEntity | Partial<TEntity>) => TPk;
|
|
866
|
+
});
|
|
867
|
+
upsertOneByPk(pk: TPk, patch: Partial<TEntity>): void;
|
|
868
|
+
upsertOne(entity: TEntity | Partial<TEntity>): void;
|
|
869
|
+
upsertMany(entities: (TEntity | Partial<TEntity>)[]): void;
|
|
870
|
+
getChangedFieldsByPk(pk: TPk): ReadonlySet<TOIMFieldKey<TEntity>>;
|
|
871
|
+
consumeChangedFieldsByPk(pk: TPk): Set<TOIMFieldKey<TEntity>>;
|
|
872
|
+
getChangedPksByField(field: TOIMFieldKey<TEntity>): ReadonlySet<TPk>;
|
|
873
|
+
consumeChangedPksByField(field: TOIMFieldKey<TEntity>): Set<TPk>;
|
|
874
|
+
clear(): void;
|
|
875
|
+
destroy(): void;
|
|
876
|
+
private trackPatch;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* Manual ordered Array-based index.
|
|
881
|
+
*
|
|
882
|
+
* Unlike `OIMIndexManualArrayBased.addPks/removePks`, this class is explicitly ordered:
|
|
883
|
+
* - preserves order
|
|
884
|
+
* - allows O(1) append (`push`)
|
|
885
|
+
* - supports `move` and `removeAt` without computing diffs
|
|
886
|
+
*
|
|
887
|
+
* It emits UPDATE events per key on every successful mutation.
|
|
888
|
+
*/
|
|
889
|
+
declare class OIMIndexManualOrderedArrayBased<TKey extends TOIMPk, TItemKey extends TOIMPk> extends OIMIndexArrayBased<TKey, TItemKey> {
|
|
890
|
+
clear(key?: TKey): void;
|
|
891
|
+
push(key: TKey, itemKey: TItemKey): number;
|
|
892
|
+
insertAt(key: TKey, index: number, itemKey: TItemKey): void;
|
|
893
|
+
removeAt(key: TKey, index: number): TItemKey | undefined;
|
|
894
|
+
move(key: TKey, fromIndex: number, toIndex: number): TItemKey | undefined;
|
|
895
|
+
reset(key: TKey, itemKeys: readonly TItemKey[]): void;
|
|
896
|
+
private getOrCreateList;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
type TOIMOrderedListCommand<TPk extends TOIMPk> = {
|
|
900
|
+
type: 'add';
|
|
901
|
+
key: TPk;
|
|
902
|
+
index: number;
|
|
903
|
+
} | {
|
|
904
|
+
type: 'remove';
|
|
905
|
+
key: TPk;
|
|
906
|
+
index: number;
|
|
907
|
+
} | {
|
|
908
|
+
type: 'move';
|
|
909
|
+
key: TPk;
|
|
910
|
+
fromIndex: number;
|
|
911
|
+
toIndex: number;
|
|
912
|
+
} | {
|
|
913
|
+
type: 'reset';
|
|
914
|
+
keys: readonly TPk[];
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Ordered-list wrapper that stores arrays per key and emits a per-key command stream.
|
|
919
|
+
*
|
|
920
|
+
* This is designed for imperative renderers: instead of diffing the full list on each update,
|
|
921
|
+
* you subscribe to `commandsEventEmitter` on a single list key and apply commands sequentially.
|
|
922
|
+
*
|
|
923
|
+
* Notes:
|
|
924
|
+
* - Commands are buffered per key and delivered batched per queue flush.
|
|
925
|
+
* - Order of commands is preserved.
|
|
926
|
+
* - A future optimizer can collapse the command buffer into `reset(...)` if needed.
|
|
927
|
+
*/
|
|
928
|
+
declare class OIMOrderedListIndexCommandStreamWrapper<TKey extends TOIMPk, TItemKey extends TOIMPk> {
|
|
929
|
+
readonly commandsEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
930
|
+
private readonly coalescer;
|
|
931
|
+
private readonly commandsByKey;
|
|
932
|
+
/** Underlying ordered index (source of truth for the list). */
|
|
933
|
+
readonly index: OIMIndexManualOrderedArrayBased<TKey, TItemKey>;
|
|
934
|
+
constructor(queue: OIMEventQueue, index?: OIMIndexManualOrderedArrayBased<TKey, TItemKey>);
|
|
935
|
+
getPksByKey(key: TKey): readonly TItemKey[];
|
|
936
|
+
hasKey(key: TKey): boolean;
|
|
937
|
+
getKeys(): readonly TKey[];
|
|
938
|
+
push(key: TKey, itemKey: TItemKey): void;
|
|
939
|
+
removeAt(key: TKey, index: number): void;
|
|
940
|
+
move(key: TKey, fromIndex: number, toIndex: number): void;
|
|
941
|
+
reset(key: TKey, keys: readonly TItemKey[]): void;
|
|
942
|
+
/**
|
|
943
|
+
* Read-only peek at buffered commands without clearing them.
|
|
944
|
+
*/
|
|
945
|
+
getBufferedCommands(key: TKey): readonly TOIMOrderedListCommand<TItemKey>[];
|
|
946
|
+
/**
|
|
947
|
+
* Drain buffered commands for a key, preserving order.
|
|
948
|
+
* Intended usage: call inside a `commandsEventEmitter.subscribeOnKey(key, ...)` handler.
|
|
949
|
+
*/
|
|
950
|
+
consumeCommands(key: TKey): TOIMOrderedListCommand<TItemKey>[];
|
|
951
|
+
clear(key?: TKey): void;
|
|
952
|
+
destroy(): void;
|
|
953
|
+
private appendCommand;
|
|
954
|
+
}
|
|
955
|
+
|
|
683
956
|
/**
|
|
684
957
|
* Animation frame-based scheduler that executes flushes synchronized with the browser's repaint cycle.
|
|
685
958
|
* Ideal for UI-related updates that need to be synchronized with rendering.
|
|
@@ -780,8 +1053,17 @@ declare class OIMEventQueueSchedulerFactory {
|
|
|
780
1053
|
/**
|
|
781
1054
|
* Event types for update coalescers */
|
|
782
1055
|
declare enum EOIMUpdateEventCoalescerEventType {
|
|
1056
|
+
/**
|
|
1057
|
+
* @description Emitted when there are any first changes to the updated keys
|
|
1058
|
+
*/
|
|
783
1059
|
HAS_CHANGES = 0,
|
|
1060
|
+
/**
|
|
1061
|
+
* @description Emitted before the flush of the updated keys
|
|
1062
|
+
*/
|
|
784
1063
|
BEFORE_FLUSH = 1,
|
|
1064
|
+
/**
|
|
1065
|
+
* @description Emitted after the flush of the updated keys
|
|
1066
|
+
*/
|
|
785
1067
|
AFTER_FLUSH = 2
|
|
786
1068
|
}
|
|
787
1069
|
|
|
@@ -809,10 +1091,148 @@ type TOIMIndexPksUpdatePayload<TKey extends TOIMPk, TPk extends TOIMPk> = {
|
|
|
809
1091
|
pks: readonly TPk[];
|
|
810
1092
|
};
|
|
811
1093
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1094
|
+
declare enum EOIMEffectPhase {
|
|
1095
|
+
PRE = "pre",
|
|
1096
|
+
HANDLERS = "handlers"
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
interface IOIMEffectDependency {
|
|
1100
|
+
subscribe(phase: EOIMEffectPhase, onInvalidate: () => void): () => void;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
type TOIMComputedOptions<TValue> = {
|
|
1104
|
+
compute: () => TValue;
|
|
1105
|
+
deps?: readonly IOIMEffectDependency[];
|
|
1106
|
+
compare?: (a: TValue, b: TValue) => boolean;
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
type TOIMComputedUpdatePayload<TKey extends TOIMPk> = {
|
|
815
1110
|
keys: readonly TKey[];
|
|
816
1111
|
};
|
|
817
1112
|
|
|
818
|
-
|
|
1113
|
+
declare enum EOIMComputedEventType {
|
|
1114
|
+
UPDATE = "update"
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
declare class OIMUpdateEventCoalescerComputed<TKey extends TOIMPk> extends OIMUpdateEventCoalescer<TKey> {
|
|
1118
|
+
private readonly computedEmitter;
|
|
1119
|
+
constructor(computedEmitter: OIMEventEmitter<{
|
|
1120
|
+
[EOIMComputedEventType.UPDATE]: TOIMComputedUpdatePayload<TKey>;
|
|
1121
|
+
}>);
|
|
1122
|
+
destroy(): void;
|
|
1123
|
+
private handleUpdate;
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
type TOIMComputedKey$2 = 'value';
|
|
1127
|
+
declare class OIMComputed<TValue> {
|
|
1128
|
+
readonly emitter: OIMEventEmitter<{
|
|
1129
|
+
update: TOIMComputedUpdatePayload<TOIMComputedKey$2>;
|
|
1130
|
+
}>;
|
|
1131
|
+
readonly coalescer: OIMUpdateEventCoalescerComputed<TOIMComputedKey$2>;
|
|
1132
|
+
readonly updateEventEmitter: OIMUpdateEventEmitter<TOIMComputedKey$2>;
|
|
1133
|
+
private readonly queue;
|
|
1134
|
+
private readonly compute;
|
|
1135
|
+
private readonly compare;
|
|
1136
|
+
private readonly deps;
|
|
1137
|
+
private value;
|
|
1138
|
+
private hasValue;
|
|
1139
|
+
private isDirty;
|
|
1140
|
+
private isInFlush;
|
|
1141
|
+
private hasRecomputedInThisFlush;
|
|
1142
|
+
private readonly effect;
|
|
1143
|
+
private readonly handleQueueBeforeFlush;
|
|
1144
|
+
private readonly handleQueueAfterFlush;
|
|
1145
|
+
constructor(queue: OIMEventQueue, opts: TOIMComputedOptions<TValue>);
|
|
1146
|
+
get(): TValue;
|
|
1147
|
+
getIfReady(): TValue | undefined;
|
|
1148
|
+
destroy(): void;
|
|
1149
|
+
private recomputeAndEmitIfChanged;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
type TOIMComputedKey$1 = 'value';
|
|
1153
|
+
interface IOIMComputedEventSource {
|
|
1154
|
+
emitter: OIMEventEmitter<{
|
|
1155
|
+
[EOIMComputedEventType.UPDATE]: TOIMComputedUpdatePayload<TOIMComputedKey$1>;
|
|
1156
|
+
}>;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
type TOIMEffectOptions = {
|
|
1160
|
+
deps?: readonly IOIMEffectDependency[];
|
|
1161
|
+
phase: EOIMEffectPhase;
|
|
1162
|
+
onInvalidate?: () => void;
|
|
1163
|
+
run: () => void;
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
declare class OIMEffect {
|
|
1167
|
+
private readonly queue;
|
|
1168
|
+
private readonly phase;
|
|
1169
|
+
private readonly onInvalidate?;
|
|
1170
|
+
private readonly run;
|
|
1171
|
+
private readonly deps;
|
|
1172
|
+
private unsubscribers;
|
|
1173
|
+
private isDestroyed;
|
|
1174
|
+
private isInFlush;
|
|
1175
|
+
private hasRunInThisFlush;
|
|
1176
|
+
private isScheduled;
|
|
1177
|
+
private readonly handleQueueBeforeFlush;
|
|
1178
|
+
private readonly handleQueueAfterFlush;
|
|
1179
|
+
private readonly runTask;
|
|
1180
|
+
constructor(queue: OIMEventQueue, opts: TOIMEffectOptions);
|
|
1181
|
+
destroy(): void;
|
|
1182
|
+
private invalidate;
|
|
1183
|
+
private runOnce;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
declare class OIMEffectDependencyKeyed<TKey extends TOIMPk> implements IOIMEffectDependency {
|
|
1187
|
+
private readonly updateEventEmitter;
|
|
1188
|
+
private readonly key;
|
|
1189
|
+
private readonly keys;
|
|
1190
|
+
constructor(updateEventEmitter: OIMUpdateEventEmitter<TKey>, keyOrKeys: TKey | readonly TKey[]);
|
|
1191
|
+
subscribe(phase: EOIMEffectPhase, onInvalidate: () => void): () => void;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
declare class OIMEffectDependencyKeyedObject<TKey extends string, TValue> implements IOIMEffectDependency {
|
|
1195
|
+
private readonly dep;
|
|
1196
|
+
constructor(object: OIMReactiveObject<TKey, TValue>, key: TKey);
|
|
1197
|
+
constructor(object: OIMReactiveObject<TKey, TValue>, keys: readonly TKey[]);
|
|
1198
|
+
subscribe(phase: EOIMEffectPhase, onInvalidate: () => void): () => void;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
declare class OIMEffectDependencyKeyedCollection<TEntity extends object, TPk extends TOIMPk> implements IOIMEffectDependency {
|
|
1202
|
+
private readonly dep;
|
|
1203
|
+
constructor(collection: OIMReactiveCollection<TEntity, TPk>, pk: TPk);
|
|
1204
|
+
constructor(collection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]);
|
|
1205
|
+
subscribe(phase: EOIMEffectPhase, onInvalidate: () => void): () => void;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
declare class OIMEffectDependencyKeyedIndex<TKey extends TOIMPk> implements IOIMEffectDependency {
|
|
1209
|
+
private readonly dep;
|
|
1210
|
+
constructor(index: {
|
|
1211
|
+
updateEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
1212
|
+
}, key: TKey);
|
|
1213
|
+
constructor(index: {
|
|
1214
|
+
updateEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
1215
|
+
}, keys: readonly TKey[]);
|
|
1216
|
+
subscribe(phase: EOIMEffectPhase, onInvalidate: () => void): () => void;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
type TOIMComputedKey = 'value';
|
|
1220
|
+
type TOIMComputedLike = {
|
|
1221
|
+
emitter: OIMEventEmitter<{
|
|
1222
|
+
update: TOIMComputedUpdatePayload<TOIMComputedKey>;
|
|
1223
|
+
}>;
|
|
1224
|
+
updateEventEmitter: OIMUpdateEventEmitter<TOIMComputedKey>;
|
|
1225
|
+
};
|
|
1226
|
+
/**
|
|
1227
|
+
* Effect dependency on a computed.
|
|
1228
|
+
*
|
|
1229
|
+
* - PRE: subscribe directly to computed.emitter for immediate invalidation during pre-drain.
|
|
1230
|
+
* - HANDLERS: subscribe via computed.updateEventEmitter (normal handlers) which is delivered through queue.
|
|
1231
|
+
*/
|
|
1232
|
+
declare class OIMEffectDependencyComputed implements IOIMEffectDependency {
|
|
1233
|
+
private readonly computed;
|
|
1234
|
+
constructor(computed: TOIMComputedLike);
|
|
1235
|
+
subscribe(phase: EOIMEffectPhase, onInvalidate: () => void): () => void;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
export { EOIMCollectionEventType, EOIMComputedEventType, EOIMEffectPhase, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMObjectEventType, EOIMUpdateEventCoalescerEventType, type IOIMComputedEventSource, type IOIMEffectDependency, type IOIMEventQueueSchedulerEvents, OIMCollection, OIMCollectionChangedFieldsWrapper, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMComputed, OIMDBSettings, OIMEffect, OIMEffectDependencyComputed, OIMEffectDependencyKeyed, OIMEffectDependencyKeyedCollection, OIMEffectDependencyKeyedIndex, OIMEffectDependencyKeyedObject, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerTimeout, OIMIndexArrayBased, OIMIndexComparatorFactory, OIMIndexManualArrayBased, OIMIndexManualOrderedArrayBased, OIMIndexManualSetBased, OIMIndexSetBased, OIMIndexStoreArrayBased, OIMIndexStoreMapDrivenArrayBased, OIMIndexStoreMapDrivenSetBased, OIMIndexStoreSetBased, OIMMap2Keys, OIMObject, OIMObjectStore, OIMObjectStoreMapDriven, OIMObjectStoreRecordDriven, OIMOrderedListIndexCommandStreamWrapper, OIMPkSelectorFactory, OIMRICollection, OIMReactiveCollection, OIMReactiveIndexArrayBased, OIMReactiveIndexManualArrayBased, OIMReactiveIndexManualSetBased, OIMReactiveIndexSetBased, OIMReactiveObject, OIMUpdateEventCoalescer, OIMUpdateEventCoalescerCollection, OIMUpdateEventCoalescerComputed, OIMUpdateEventCoalescerIndex, OIMUpdateEventCoalescerManual, OIMUpdateEventCoalescerObject, OIMUpdateEventEmitter, type TOIMCollectionOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMComputedOptions, type TOIMComputedUpdatePayload, type TOIMEffectOptions, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptions, type TOIMIndexOptionsArrayBased, type TOIMIndexOptionsSetBased, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMObjectOptions, type TOIMOrderedListCommand, type TOIMPk, type TOIMPkSelector, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdateEventEmitterOptions, type TOIMUpdatePayload };
|