@oimdb/core 1.0.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 +562 -0
- package/dist/index.cjs +1186 -0
- package/dist/index.d.cts +588 -0
- package/dist/index.d.ts +588 -0
- package/dist/index.js +1130 -0
- package/package.json +39 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
type TOIMPk = string | number;
|
|
2
|
+
|
|
3
|
+
declare abstract class OIMCollectionStore<TEntity extends object, TPk extends TOIMPk> {
|
|
4
|
+
abstract setOneByPk(pk: TPk, entity: TEntity): void;
|
|
5
|
+
abstract removeOneByPk(pk: TPk): void;
|
|
6
|
+
abstract removeManyByPks(pks: readonly TPk[]): void;
|
|
7
|
+
abstract getOneByPk(pk: TPk): TEntity | undefined;
|
|
8
|
+
abstract getManyByPks(pks: readonly TPk[]): Map<TPk, TEntity | undefined>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type TOIMEventHandler<T> = (payload: T) => void;
|
|
12
|
+
|
|
13
|
+
declare class OIMEventEmitter<T extends Record<string, unknown>> {
|
|
14
|
+
private buckets;
|
|
15
|
+
private getOrCreateBucket;
|
|
16
|
+
private compactBucket;
|
|
17
|
+
on<K extends keyof T>(event: K, handler: TOIMEventHandler<T[K]>): void;
|
|
18
|
+
emit<K extends keyof T>(event: K, payload: T[K]): void;
|
|
19
|
+
off<K extends keyof T>(event: K, handler: TOIMEventHandler<T[K]>): void;
|
|
20
|
+
offAll<K extends keyof T>(event?: K): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare enum EOIMEventQueueSchedulerEventType {
|
|
24
|
+
FLUSH = 0
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Events that can be emitted by the scheduler. */
|
|
29
|
+
interface IOIMEventQueueSchedulerEvents extends Record<string, unknown> {
|
|
30
|
+
[EOIMEventQueueSchedulerEventType.FLUSH]: void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Abstract base class for event queue schedulers.
|
|
35
|
+
* Provides common event emission functionality while leaving scheduling strategy to subclasses.
|
|
36
|
+
*/
|
|
37
|
+
declare abstract class OIMEventQueueScheduler {
|
|
38
|
+
protected readonly emitter: OIMEventEmitter<IOIMEventQueueSchedulerEvents>;
|
|
39
|
+
abstract schedule(): void;
|
|
40
|
+
abstract cancel(): void;
|
|
41
|
+
on<K extends keyof IOIMEventQueueSchedulerEvents>(event: K, handler: TOIMEventHandler<IOIMEventQueueSchedulerEvents[K]>): void;
|
|
42
|
+
off<K extends keyof IOIMEventQueueSchedulerEvents>(event: K, handler: TOIMEventHandler<IOIMEventQueueSchedulerEvents[K]>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Trigger a flush event. Should be called by subclasses when they execute the scheduled flush.
|
|
45
|
+
*/
|
|
46
|
+
protected flush(): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Payload for index update events containing the keys that were modified */
|
|
51
|
+
interface TOIMIndexUpdatePayload<TKey> {
|
|
52
|
+
keys: readonly TKey[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Comparator function for index primary key arrays.
|
|
57
|
+
* Returns true if the arrays are considered equal, false if they differ. */
|
|
58
|
+
type TOIMIndexComparator<TPk extends TOIMPk> = (existingPks: readonly TPk[], newPks: readonly TPk[]) => boolean;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Configuration options for index instances */
|
|
62
|
+
type TOIMIndexOptions<TPk extends TOIMPk> = {
|
|
63
|
+
comparePks?: TOIMIndexComparator<TPk>;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Abstract base class for all index types.
|
|
68
|
+
* Provides common functionality and event system for key-to-PKs mappings.
|
|
69
|
+
*/
|
|
70
|
+
declare abstract class OIMIndex<TKey extends TOIMPk, TPk extends TOIMPk> {
|
|
71
|
+
protected readonly pks: Map<TKey, Set<TPk>>;
|
|
72
|
+
protected readonly comparePks?: TOIMIndexComparator<TPk>;
|
|
73
|
+
readonly emitter: OIMEventEmitter<{
|
|
74
|
+
0: TOIMIndexUpdatePayload<TKey>;
|
|
75
|
+
}>;
|
|
76
|
+
constructor(options?: TOIMIndexOptions<TPk>);
|
|
77
|
+
/**
|
|
78
|
+
* Get primary keys for multiple index keys
|
|
79
|
+
*/
|
|
80
|
+
getPksByKeys(keys: readonly TKey[]): Map<TKey, readonly TPk[]>;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use getPksByKey instead
|
|
83
|
+
* Get primary keys for a specific index key
|
|
84
|
+
*/
|
|
85
|
+
getPks(key: TKey): readonly TPk[];
|
|
86
|
+
/**
|
|
87
|
+
* Get primary keys for a specific index key
|
|
88
|
+
*/
|
|
89
|
+
getPksByKey(key: TKey): readonly TPk[];
|
|
90
|
+
/**
|
|
91
|
+
* Check if an index key exists
|
|
92
|
+
*/
|
|
93
|
+
hasKey(key: TKey): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Get all index keys
|
|
96
|
+
*/
|
|
97
|
+
getKeys(): readonly TKey[];
|
|
98
|
+
/**
|
|
99
|
+
* Get the number of primary keys for a specific index key
|
|
100
|
+
*/
|
|
101
|
+
getKeySize(key: TKey): number;
|
|
102
|
+
/**
|
|
103
|
+
* Get total number of index keys
|
|
104
|
+
*/
|
|
105
|
+
get size(): number;
|
|
106
|
+
/**
|
|
107
|
+
* Check if the index is empty
|
|
108
|
+
*/
|
|
109
|
+
get isEmpty(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Get performance metrics for monitoring and debugging
|
|
112
|
+
*/
|
|
113
|
+
getMetrics(): {
|
|
114
|
+
totalKeys: number;
|
|
115
|
+
totalPks: number;
|
|
116
|
+
averagePksPerKey: number;
|
|
117
|
+
maxBucketSize: number;
|
|
118
|
+
minBucketSize: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* Clean up event listeners when index is no longer needed
|
|
122
|
+
*/
|
|
123
|
+
destroy(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Set primary keys for a specific index key with optional comparison.
|
|
126
|
+
* If comparator is provided and returns true (no changes), skip the update.
|
|
127
|
+
*/
|
|
128
|
+
protected setPksWithComparison(key: TKey, newPks: readonly TPk[]): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Emit update event with changed keys
|
|
131
|
+
*/
|
|
132
|
+
protected emitUpdate(keys: TKey[]): void;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Base abstract coalescer that groups updates by keys and emits consolidated events.
|
|
137
|
+
* Designed to be extended for different entity types (collections, indexes, etc.).
|
|
138
|
+
*/
|
|
139
|
+
declare abstract class OIMUpdateEventCoalescer<TKey> {
|
|
140
|
+
readonly emitter: OIMEventEmitter<{
|
|
141
|
+
0: void;
|
|
142
|
+
}>;
|
|
143
|
+
protected updatedKeys: Set<TKey>;
|
|
144
|
+
private hasEmittedChanges;
|
|
145
|
+
/**
|
|
146
|
+
* Get the set of keys that have been updated since last clear
|
|
147
|
+
*/
|
|
148
|
+
getUpdatedKeys(): Set<TKey>;
|
|
149
|
+
/**
|
|
150
|
+
* Clear all updated keys and reset the changed state
|
|
151
|
+
*/
|
|
152
|
+
clearUpdatedKeys(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Add keys to the updated set and emit HAS_CHANGES event if needed
|
|
155
|
+
*/
|
|
156
|
+
protected addUpdatedKeys(keys: TKey[]): void;
|
|
157
|
+
/**
|
|
158
|
+
* Clean up event listeners when coalescer is no longer needed
|
|
159
|
+
*/
|
|
160
|
+
abstract destroy(): void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Configuration options for event queue initialization.
|
|
165
|
+
*/
|
|
166
|
+
type TOIMEventQueueOptions = {
|
|
167
|
+
/**
|
|
168
|
+
* Optional scheduler for automatic queue flushing.
|
|
169
|
+
* If provided, the queue will automatically schedule flush operations when items are enqueued.
|
|
170
|
+
* If not provided, flush() must be called manually.
|
|
171
|
+
*/
|
|
172
|
+
scheduler?: OIMEventQueueScheduler;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Event queue that can optionally integrate with a scheduler for automatic flushing.
|
|
177
|
+
*/
|
|
178
|
+
declare class OIMEventQueue {
|
|
179
|
+
protected queue: (() => void)[];
|
|
180
|
+
protected readonly scheduler?: OIMEventQueueScheduler;
|
|
181
|
+
protected flushBound?: () => void;
|
|
182
|
+
constructor(options?: TOIMEventQueueOptions);
|
|
183
|
+
/**
|
|
184
|
+
* Add a function to the queue. If scheduler is configured and autoSchedule is enabled,
|
|
185
|
+
* automatically schedules a flush operation.
|
|
186
|
+
*/
|
|
187
|
+
enqueue(fn: () => void): void;
|
|
188
|
+
/**
|
|
189
|
+
* Execute all queued functions and clear the queue.
|
|
190
|
+
* This method is safe to call multiple times and handles reentrancy.
|
|
191
|
+
*/
|
|
192
|
+
flush(): void;
|
|
193
|
+
/**
|
|
194
|
+
* Get the current number of queued functions.
|
|
195
|
+
*/
|
|
196
|
+
get length(): number;
|
|
197
|
+
/**
|
|
198
|
+
* Check if the queue is empty.
|
|
199
|
+
*/
|
|
200
|
+
get isEmpty(): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Clear the queue without executing functions and cancel any scheduled flush.
|
|
203
|
+
*/
|
|
204
|
+
clear(): void;
|
|
205
|
+
/**
|
|
206
|
+
* Clean up scheduler subscription when queue is no longer needed.
|
|
207
|
+
*/
|
|
208
|
+
destroy(): void;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Options for creating an update event emitter */
|
|
213
|
+
type TOIMUpdateEventEmitterOptions<TKey> = {
|
|
214
|
+
coalescer: OIMUpdateEventCoalescer<TKey>;
|
|
215
|
+
queue: OIMEventQueue;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Universal event emitter that handles subscriptions and notifications for any key type.
|
|
220
|
+
* Optimized for performance with adaptive algorithms and memory management.
|
|
221
|
+
*/
|
|
222
|
+
declare class OIMUpdateEventEmitter<TKey> {
|
|
223
|
+
protected keyHandlers: Map<TKey, Set<TOIMEventHandler<void>>>;
|
|
224
|
+
protected coalescer: OIMUpdateEventCoalescer<TKey>;
|
|
225
|
+
protected queue: OIMEventQueue;
|
|
226
|
+
constructor(opts: TOIMUpdateEventEmitterOptions<TKey>);
|
|
227
|
+
protected handleHasChanges: () => void;
|
|
228
|
+
destroy(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Get performance metrics for monitoring and debugging
|
|
231
|
+
*/
|
|
232
|
+
getMetrics(): {
|
|
233
|
+
totalKeys: number;
|
|
234
|
+
totalHandlers: number;
|
|
235
|
+
averageHandlersPerKey: number;
|
|
236
|
+
queueLength: number;
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Check if there are any active subscriptions
|
|
240
|
+
*/
|
|
241
|
+
hasSubscriptions(): boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Get the number of handlers for a specific key
|
|
244
|
+
*/
|
|
245
|
+
getHandlerCount(key: TKey): number;
|
|
246
|
+
subscribeOnKey(key: TKey, handler: TOIMEventHandler<void>): () => void;
|
|
247
|
+
unsubscribeFromKey(key: TKey, handler: TOIMEventHandler<void>): void;
|
|
248
|
+
subscribeOnKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): () => void;
|
|
249
|
+
unsubscribeFromKeys(keys: readonly TKey[], handler: TOIMEventHandler<void>): void;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare enum EOIMIndexEventType {
|
|
253
|
+
UPDATE = 0
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Index-specific coalescer that tracks index key updates and emits consolidated change events.
|
|
258
|
+
* Takes an event emitter directly instead of the whole index to avoid circular dependencies.
|
|
259
|
+
*/
|
|
260
|
+
declare class OIMUpdateEventCoalescerIndex<TIndexKey> extends OIMUpdateEventCoalescer<TIndexKey> {
|
|
261
|
+
private readonly indexEmitter;
|
|
262
|
+
constructor(indexEmitter: OIMEventEmitter<{
|
|
263
|
+
[EOIMIndexEventType.UPDATE]: TOIMIndexUpdatePayload<TIndexKey>;
|
|
264
|
+
}>);
|
|
265
|
+
destroy(): void;
|
|
266
|
+
/**
|
|
267
|
+
* When the index is updated, we keep track of the updated keys.
|
|
268
|
+
*/
|
|
269
|
+
private handleUpdate;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare abstract class OIMReactiveIndex<TKey extends TOIMPk, TPk extends TOIMPk, TIndex extends OIMIndex<TKey, TPk>> {
|
|
273
|
+
readonly index: TIndex;
|
|
274
|
+
readonly updateEventEmitter: OIMUpdateEventEmitter<TKey>;
|
|
275
|
+
readonly coalescer: OIMUpdateEventCoalescerIndex<TKey>;
|
|
276
|
+
constructor(queue: OIMEventQueue, opts?: {
|
|
277
|
+
index: TIndex;
|
|
278
|
+
});
|
|
279
|
+
protected abstract createDefaultIndex(): TIndex;
|
|
280
|
+
getPksByKey(key: TKey): readonly TPk[];
|
|
281
|
+
getPksByKeys(keys: readonly TKey[]): Map<TKey, readonly TPk[]>;
|
|
282
|
+
hasKey(key: TKey): boolean;
|
|
283
|
+
getKeys(): readonly TKey[];
|
|
284
|
+
getKeySize(key: TKey): number;
|
|
285
|
+
get size(): number;
|
|
286
|
+
get isEmpty(): boolean;
|
|
287
|
+
getMetrics(): {
|
|
288
|
+
totalKeys: number;
|
|
289
|
+
totalPks: number;
|
|
290
|
+
averagePksPerKey: number;
|
|
291
|
+
maxBucketSize: number;
|
|
292
|
+
minBucketSize: number;
|
|
293
|
+
};
|
|
294
|
+
destroy(): void;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
type TOIMPkSelector<TEntity extends object, TPk extends TOIMPk> = (entity: TEntity) => TPk;
|
|
298
|
+
|
|
299
|
+
type TOIMEntityUpdater<TEntity extends object> = (draft: Partial<TEntity>, prevEntity: TEntity) => TEntity;
|
|
300
|
+
|
|
301
|
+
type TOIMCollectionOptions<TEntity extends object, TPk extends TOIMPk> = {
|
|
302
|
+
selectPk?: TOIMPkSelector<TEntity, TPk>;
|
|
303
|
+
store?: OIMCollectionStore<TEntity, TPk>;
|
|
304
|
+
updateEntity?: TOIMEntityUpdater<TEntity>;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
type TOIMCollectionUpdatePayload<TPk extends TOIMPk> = {
|
|
308
|
+
pks: readonly TPk[];
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/** It's like a store - but with event emitter */
|
|
312
|
+
declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
313
|
+
readonly emitter: OIMEventEmitter<{
|
|
314
|
+
0: TOIMCollectionUpdatePayload<TPk>;
|
|
315
|
+
}>;
|
|
316
|
+
protected readonly selectPk: TOIMPkSelector<TEntity, TPk>;
|
|
317
|
+
protected readonly store: OIMCollectionStore<TEntity, TPk>;
|
|
318
|
+
protected readonly updateEntity: TOIMEntityUpdater<TEntity>;
|
|
319
|
+
constructor(opts?: TOIMCollectionOptions<TEntity, TPk>);
|
|
320
|
+
getOneByPk(pk: TPk): TEntity | undefined;
|
|
321
|
+
getManyByPks(pks: readonly TPk[]): Map<TPk, TEntity | undefined>;
|
|
322
|
+
upsertOne(entity: TEntity): void;
|
|
323
|
+
upsertMany(entities: TEntity[]): void;
|
|
324
|
+
removeOne(entity: TEntity): void;
|
|
325
|
+
removeMany(entities: TEntity[]): void;
|
|
326
|
+
protected upsertOneWithoutNotifications(entity: TEntity): TPk;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
declare enum EOIMCollectionEventType {
|
|
330
|
+
UPDATE = 0
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Collection-specific coalescer that tracks primary key updates and emits consolidated change events.
|
|
335
|
+
* Takes an event emitter directly instead of the whole collection to avoid circular dependencies.
|
|
336
|
+
*/
|
|
337
|
+
declare class OIMUpdateEventCoalescerCollection<TPk extends TOIMPk> extends OIMUpdateEventCoalescer<TPk> {
|
|
338
|
+
private readonly collectionEmitter;
|
|
339
|
+
constructor(collectionEmitter: OIMEventEmitter<{
|
|
340
|
+
[EOIMCollectionEventType.UPDATE]: TOIMCollectionUpdatePayload<TPk>;
|
|
341
|
+
}>);
|
|
342
|
+
destroy(): void;
|
|
343
|
+
/**
|
|
344
|
+
* When the collection is updated, we keep track of the updated pks.
|
|
345
|
+
*/
|
|
346
|
+
private handleUpdate;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
350
|
+
readonly collection: OIMCollection<TEntity, TPk>;
|
|
351
|
+
readonly updateEventEmitter: OIMUpdateEventEmitter<TPk>;
|
|
352
|
+
readonly coalescer: OIMUpdateEventCoalescerCollection<TPk>;
|
|
353
|
+
constructor(queue: OIMEventQueue, opts?: {
|
|
354
|
+
collectionOpts?: TOIMCollectionOptions<TEntity, TPk>;
|
|
355
|
+
});
|
|
356
|
+
upsertMany(entities: TEntity[]): void;
|
|
357
|
+
upsertOne(entity: TEntity): void;
|
|
358
|
+
removeMany(entities: TEntity[]): void;
|
|
359
|
+
removeOne(entity: TEntity): void;
|
|
360
|
+
getOneByPk(pk: TPk): TEntity | undefined;
|
|
361
|
+
getManyByPks(pks: readonly TPk[]): Map<TPk, TEntity | undefined>;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Manual index that allows direct manipulation of key-to-primary-keys mappings.
|
|
366
|
+
* Extends the abstract OIMIndex with manual control methods and optional comparison.
|
|
367
|
+
*/
|
|
368
|
+
declare class OIMIndexManual<TIndexKey extends TOIMPk, TPk extends TOIMPk> extends OIMIndex<TIndexKey, TPk> {
|
|
369
|
+
constructor(options?: TOIMIndexOptions<TPk>);
|
|
370
|
+
/**
|
|
371
|
+
* Set primary keys for a specific index key, replacing any existing values.
|
|
372
|
+
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
373
|
+
*/
|
|
374
|
+
setPks(key: TIndexKey, pks: readonly TPk[]): void;
|
|
375
|
+
/**
|
|
376
|
+
* Add primary keys to a specific index key
|
|
377
|
+
*/
|
|
378
|
+
addPks(key: TIndexKey, pks: readonly TPk[]): void;
|
|
379
|
+
/**
|
|
380
|
+
* Remove primary keys from a specific index key
|
|
381
|
+
*/
|
|
382
|
+
removePks(key: TIndexKey, pks: readonly TPk[]): void;
|
|
383
|
+
/**
|
|
384
|
+
* Clear all primary keys for a specific index key, or all keys if no key specified
|
|
385
|
+
*/
|
|
386
|
+
clear(key?: TIndexKey): void;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
declare class OIMReactiveIndexManual<TKey extends TOIMPk, TPk extends TOIMPk> extends OIMReactiveIndex<TKey, TPk, OIMIndexManual<TKey, TPk>> {
|
|
390
|
+
constructor(queue: OIMEventQueue, opts?: {
|
|
391
|
+
index: OIMIndexManual<TKey, TPk>;
|
|
392
|
+
});
|
|
393
|
+
protected createDefaultIndex(): OIMIndexManual<TKey, TPk>;
|
|
394
|
+
setPks(key: TKey, pks: readonly TPk[]): void;
|
|
395
|
+
addPks(key: TKey, pks: readonly TPk[]): void;
|
|
396
|
+
removePks(key: TKey, pks: readonly TPk[]): void;
|
|
397
|
+
clear(key?: TKey): void;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
declare class OIMRICollection<TEntity extends object, TPk extends TOIMPk, TIndexName extends string, TIndexKey extends TOIMPk, TIndex extends OIMIndex<TIndexKey, TPk>, TReactiveIndex extends OIMReactiveIndex<TIndexKey, TPk, TIndex>> extends OIMReactiveCollection<TEntity, TPk> {
|
|
401
|
+
readonly indexes: Record<TIndexName, TReactiveIndex>;
|
|
402
|
+
constructor(queue: OIMEventQueue, opts: {
|
|
403
|
+
collectionOpts?: TOIMCollectionOptions<TEntity, TPk>;
|
|
404
|
+
indexes: Record<TIndexName, TReactiveIndex>;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
declare class OIMCollectionStoreMapDriven<TEntity extends object, TPk extends TOIMPk> extends OIMCollectionStore<TEntity, TPk> {
|
|
409
|
+
protected readonly entities: Map<TPk, TEntity>;
|
|
410
|
+
setOneByPk(pk: TPk, entity: TEntity): void;
|
|
411
|
+
setManyByPks(pks: readonly TPk[], entities: TEntity[]): void;
|
|
412
|
+
removeOneByPk(pk: TPk): void;
|
|
413
|
+
removeManyByPks(pks: readonly TPk[]): void;
|
|
414
|
+
getOneByPk(pk: TPk): TEntity | undefined;
|
|
415
|
+
getManyByPks(pks: readonly TPk[]): Map<TPk, TEntity | undefined>;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
type TOIMComparator<TEntity extends object> = (a: TEntity, b: TEntity) => boolean;
|
|
419
|
+
|
|
420
|
+
declare class OIMComparatorFactory<TEntity extends object> {
|
|
421
|
+
createShallowComparator(): TOIMComparator<TEntity>;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
declare class OIMEntityUpdaterFactory<TEntity extends object> {
|
|
425
|
+
createMergeEntityUpdater(): TOIMEntityUpdater<TEntity>;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Factory for creating index comparators.
|
|
430
|
+
* Provides common comparison strategies for primary key arrays.
|
|
431
|
+
*/
|
|
432
|
+
declare class OIMIndexComparatorFactory {
|
|
433
|
+
/**
|
|
434
|
+
* Create an element-wise comparator that checks arrays for strict equality.
|
|
435
|
+
* Compares array lengths and each element using strict equality (===).
|
|
436
|
+
*/
|
|
437
|
+
static createElementWiseComparator<TPk extends TOIMPk>(): TOIMIndexComparator<TPk>;
|
|
438
|
+
/**
|
|
439
|
+
* Create a set-based comparator that checks if arrays contain the same elements.
|
|
440
|
+
* Order doesn't matter, only the presence of elements.
|
|
441
|
+
*/
|
|
442
|
+
static createSetBasedComparator<TPk extends TOIMPk>(): TOIMIndexComparator<TPk>;
|
|
443
|
+
/**
|
|
444
|
+
* Create a shallow comparator that only checks array references.
|
|
445
|
+
* Fastest but only works if you're reusing the same array instances.
|
|
446
|
+
*/
|
|
447
|
+
static createShallowComparator<TPk extends TOIMPk>(): TOIMIndexComparator<TPk>;
|
|
448
|
+
/**
|
|
449
|
+
* Create a no-comparison comparator that always returns false (always updates).
|
|
450
|
+
* Useful for disabling comparison while keeping the same interface.
|
|
451
|
+
*/
|
|
452
|
+
static createAlwaysUpdateComparator<TPk extends TOIMPk>(): TOIMIndexComparator<TPk>;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
declare class OIMMap2Keys<K1, K2, V> {
|
|
456
|
+
private map;
|
|
457
|
+
private _size;
|
|
458
|
+
get size(): number;
|
|
459
|
+
set(k1: K1, k2: K2, v: V): void;
|
|
460
|
+
get(k1: K1, k2: K2): V | undefined;
|
|
461
|
+
has(k1: K1, k2: K2): boolean | undefined;
|
|
462
|
+
delete(k1: K1, k2: K2): boolean;
|
|
463
|
+
clear(): void;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
declare class OIMPkSelectorFactory<TEntity extends object, TPk extends TOIMPk> {
|
|
467
|
+
createIdSelector(): TOIMPkSelector<TEntity & {
|
|
468
|
+
id: TPk;
|
|
469
|
+
}, TPk>;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Animation frame-based scheduler that executes flushes synchronized with the browser's repaint cycle.
|
|
474
|
+
* Ideal for UI-related updates that need to be synchronized with rendering.
|
|
475
|
+
* Falls back to setTimeout in non-browser environments.
|
|
476
|
+
*/
|
|
477
|
+
declare class OIMEventQueueSchedulerAnimationFrame extends OIMEventQueueScheduler {
|
|
478
|
+
protected frameId?: number;
|
|
479
|
+
protected readonly useRequestAnimationFrame: boolean;
|
|
480
|
+
constructor();
|
|
481
|
+
schedule(): void;
|
|
482
|
+
cancel(): void;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Available scheduler types for event queue configuration.
|
|
487
|
+
*/
|
|
488
|
+
type TOIMSchedulerType = 'microtask' | 'animationFrame' | 'timeout' | 'immediate';
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Configuration options for different scheduler types. */
|
|
492
|
+
type TOIMSchedulerOptions = {
|
|
493
|
+
microtask: never;
|
|
494
|
+
animationFrame: never;
|
|
495
|
+
timeout: {
|
|
496
|
+
delay?: number;
|
|
497
|
+
};
|
|
498
|
+
immediate: never;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Microtask-based scheduler that executes flushes in the next microtask.
|
|
503
|
+
* Ideal for batching synchronous operations while maintaining immediate execution.
|
|
504
|
+
*/
|
|
505
|
+
declare class OIMEventQueueSchedulerMicrotask extends OIMEventQueueScheduler {
|
|
506
|
+
protected scheduled: boolean;
|
|
507
|
+
schedule(): void;
|
|
508
|
+
cancel(): void;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Timeout-based scheduler that executes flushes after a specified delay.
|
|
513
|
+
* Useful for debouncing operations or creating custom timing strategies.
|
|
514
|
+
*/
|
|
515
|
+
declare class OIMEventQueueSchedulerTimeout extends OIMEventQueueScheduler {
|
|
516
|
+
protected timeoutId?: number;
|
|
517
|
+
protected readonly delay: number;
|
|
518
|
+
/**
|
|
519
|
+
* @param delay - Delay in milliseconds before executing the flush (default: 0)
|
|
520
|
+
*/
|
|
521
|
+
constructor(delay?: number);
|
|
522
|
+
schedule(): void;
|
|
523
|
+
cancel(): void;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Immediate-based scheduler that executes flushes using setImmediate or fallback mechanisms.
|
|
528
|
+
* Provides faster execution than setTimeout(0) in Node.js environments.
|
|
529
|
+
* Falls back to setTimeout(0) in browsers and MessageChannel in modern browsers for better performance.
|
|
530
|
+
*/
|
|
531
|
+
declare class OIMEventQueueSchedulerImmediate extends OIMEventQueueScheduler {
|
|
532
|
+
protected immediateId?: number;
|
|
533
|
+
protected readonly useSetImmediate: boolean;
|
|
534
|
+
protected readonly useMessageChannel: boolean;
|
|
535
|
+
protected messageChannel?: MessageChannel;
|
|
536
|
+
protected pendingCallback?: () => void;
|
|
537
|
+
constructor();
|
|
538
|
+
schedule(): void;
|
|
539
|
+
cancel(): void;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Factory for creating event queue schedulers.
|
|
544
|
+
* Provides a convenient way to create schedulers with type-safe configuration.
|
|
545
|
+
*/
|
|
546
|
+
declare class OIMEventQueueSchedulerFactory {
|
|
547
|
+
/**
|
|
548
|
+
* Create a scheduler of the specified type with optional configuration.
|
|
549
|
+
*/
|
|
550
|
+
static create<T extends TOIMSchedulerType>(type: T, ...args: TOIMSchedulerOptions[T] extends never ? [] : [TOIMSchedulerOptions[T]]): OIMEventQueueScheduler;
|
|
551
|
+
/**
|
|
552
|
+
* Create a microtask scheduler (most common for general use).
|
|
553
|
+
*/
|
|
554
|
+
static createMicrotask(): OIMEventQueueSchedulerMicrotask;
|
|
555
|
+
/**
|
|
556
|
+
* Create an animation frame scheduler (ideal for UI updates).
|
|
557
|
+
*/
|
|
558
|
+
static createAnimationFrame(): OIMEventQueueSchedulerAnimationFrame;
|
|
559
|
+
/**
|
|
560
|
+
* Create a timeout scheduler with optional delay.
|
|
561
|
+
*/
|
|
562
|
+
static createTimeout(delay?: number): OIMEventQueueSchedulerTimeout;
|
|
563
|
+
/**
|
|
564
|
+
* Create an immediate scheduler (fastest execution).
|
|
565
|
+
*/
|
|
566
|
+
static createImmediate(): OIMEventQueueSchedulerImmediate;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Event types for update coalescers */
|
|
571
|
+
declare enum EOIMUpdateEventCoalescerEventType {
|
|
572
|
+
HAS_CHANGES = 0
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
type TOIMIndexKey = string | number | bigint;
|
|
576
|
+
|
|
577
|
+
type TOIMIndexPksUpdatePayload<TKey extends TOIMPk, TPk extends TOIMPk> = {
|
|
578
|
+
key: TKey;
|
|
579
|
+
pks: readonly TPk[];
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Payload type for update events that contain keys */
|
|
584
|
+
type TOIMUpdatePayload<TKey> = {
|
|
585
|
+
keys: readonly TKey[];
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
export { EOIMCollectionEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMUpdateEventCoalescerEventType, type IOIMEventQueueSchedulerEvents, OIMCollection, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMEntityUpdaterFactory, OIMEventEmitter, OIMEventQueue, OIMEventQueueScheduler, OIMEventQueueSchedulerAnimationFrame, OIMEventQueueSchedulerFactory, OIMEventQueueSchedulerImmediate, OIMEventQueueSchedulerMicrotask, OIMEventQueueSchedulerTimeout, OIMIndex, OIMIndexComparatorFactory, OIMIndexManual, OIMMap2Keys, OIMPkSelectorFactory, OIMRICollection, OIMReactiveCollection, OIMReactiveIndex, OIMReactiveIndexManual, OIMUpdateEventCoalescer, OIMUpdateEventCoalescerCollection, OIMUpdateEventCoalescerIndex, OIMUpdateEventEmitter, type TOIMCollectionOptions, type TOIMCollectionUpdatePayload, type TOIMComparator, type TOIMEntityUpdater, type TOIMEventHandler, type TOIMEventQueueOptions, type TOIMIndexComparator, type TOIMIndexKey, type TOIMIndexOptions, type TOIMIndexPksUpdatePayload, type TOIMIndexUpdatePayload, type TOIMPk, type TOIMPkSelector, type TOIMSchedulerOptions, type TOIMSchedulerType, type TOIMUpdateEventEmitterOptions, type TOIMUpdatePayload };
|