@oimdb/core 1.1.0 → 1.2.1

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 CHANGED
@@ -366,6 +366,48 @@ const user = selectEntityByPk(users, 'user1');
366
366
  const teamUsers = useSelectEntitiesByPks(users, userIds);
367
367
  ```
368
368
 
369
+ ### With Redux (@oimdb/redux-adapter)
370
+
371
+ Migrate from Redux to OIMDB gradually or use both systems side-by-side with automatic two-way synchronization:
372
+
373
+ ```typescript
374
+ import { OIMDBAdapter } from '@oimdb/redux-adapter';
375
+ import { createStore, combineReducers, applyMiddleware } from 'redux';
376
+
377
+ // Create Redux adapter
378
+ const adapter = new OIMDBAdapter(queue);
379
+
380
+ // Create Redux reducer from OIMDB collection
381
+ const usersReducer = adapter.createCollectionReducer(users);
382
+
383
+ // Create middleware for automatic flushing
384
+ const middleware = adapter.createMiddleware();
385
+
386
+ // Use in existing Redux store
387
+ const store = createStore(
388
+ combineReducers({
389
+ users: usersReducer, // OIMDB-backed reducer
390
+ ui: uiReducer, // Existing Redux reducer
391
+ }),
392
+ applyMiddleware(middleware)
393
+ );
394
+
395
+ adapter.setStore(store);
396
+
397
+ // OIMDB changes automatically sync to Redux
398
+ // Redux actions automatically sync back to OIMDB with child reducers
399
+ // Middleware automatically flushes queue after each action - no manual flush needed!
400
+ ```
401
+
402
+ **Key Benefits:**
403
+ - **🔄 Gradual Migration**: Migrate one collection at a time without breaking changes
404
+ - **🔄 Two-Way Sync**: Automatic synchronization between OIMDB and Redux
405
+ - **⚡ Automatic Flushing**: Middleware automatically processes events after Redux actions
406
+ - **📦 Production Ready**: Battle-tested adapter optimized for large datasets
407
+ - **🎯 Flexible**: Works with any Redux state structure via custom mappers
408
+
409
+ [📖 See @oimdb/redux-adapter documentation](../redux-adapter/README.md) for complete migration guide and examples.
410
+
369
411
  ### Standalone Usage
370
412
 
371
413
  Use core classes directly for maximum control:
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  EOIMCollectionEventType: () => EOIMCollectionEventType,
24
+ EOIMEventQueueEventType: () => EOIMEventQueueEventType,
24
25
  EOIMEventQueueSchedulerEventType: () => EOIMEventQueueSchedulerEventType,
25
26
  EOIMIndexEventType: () => EOIMIndexEventType,
26
27
  EOIMUpdateEventCoalescerEventType: () => EOIMUpdateEventCoalescerEventType,
@@ -348,6 +349,8 @@ var OIMIndex = class {
348
349
  // src/enum/EOIMUpdateEventCoalescerEventType.ts
349
350
  var EOIMUpdateEventCoalescerEventType = /* @__PURE__ */ ((EOIMUpdateEventCoalescerEventType2) => {
350
351
  EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["HAS_CHANGES"] = 0] = "HAS_CHANGES";
352
+ EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["BEFORE_FLUSH"] = 1] = "BEFORE_FLUSH";
353
+ EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["AFTER_FLUSH"] = 2] = "AFTER_FLUSH";
351
354
  return EOIMUpdateEventCoalescerEventType2;
352
355
  })(EOIMUpdateEventCoalescerEventType || {});
353
356
 
@@ -584,8 +587,16 @@ var OIMUpdateEventCoalescer = class {
584
587
  * Clear all updated keys and reset the changed state
585
588
  */
586
589
  clearUpdatedKeys() {
590
+ this.emitter.emit(
591
+ 1 /* BEFORE_FLUSH */,
592
+ void 0
593
+ );
587
594
  this.updatedKeysIndex.setPks(OIMDBSettings.UPDATED_KEYS_INDEX_KEY, []);
588
595
  this.hasEmittedChanges = false;
596
+ this.emitter.emit(
597
+ 2 /* AFTER_FLUSH */,
598
+ void 0
599
+ );
589
600
  }
590
601
  /**
591
602
  * Add keys to the updated set and emit HAS_CHANGES event if needed
@@ -774,6 +785,14 @@ var OIMCollection = class {
774
785
  this.store.removeManyByPks(pks);
775
786
  this.emitter.emit(0 /* UPDATE */, { pks });
776
787
  }
788
+ removeOneByPk(pk) {
789
+ this.store.removeOneByPk(pk);
790
+ this.emitter.emit(0 /* UPDATE */, { pks: [pk] });
791
+ }
792
+ removeManyByPks(pks) {
793
+ this.store.removeManyByPks(pks);
794
+ this.emitter.emit(0 /* UPDATE */, { pks });
795
+ }
777
796
  clear() {
778
797
  this.store.clear();
779
798
  this.emitter.emit(0 /* UPDATE */, { pks: [] });
@@ -890,9 +909,17 @@ var OIMComparatorFactory = class {
890
909
  }
891
910
  };
892
911
 
912
+ // src/enum/EOIMEventQueueEventType.ts
913
+ var EOIMEventQueueEventType = /* @__PURE__ */ ((EOIMEventQueueEventType2) => {
914
+ EOIMEventQueueEventType2[EOIMEventQueueEventType2["AFTER_FLUSH"] = 0] = "AFTER_FLUSH";
915
+ EOIMEventQueueEventType2[EOIMEventQueueEventType2["BEFORE_FLUSH"] = 1] = "BEFORE_FLUSH";
916
+ return EOIMEventQueueEventType2;
917
+ })(EOIMEventQueueEventType || {});
918
+
893
919
  // src/core/OIMEventQueue.ts
894
920
  var OIMEventQueue = class {
895
921
  constructor(options = {}) {
922
+ this.emitter = new OIMEventEmitter();
896
923
  this.queue = [];
897
924
  this.scheduler = options.scheduler;
898
925
  if (this.scheduler) {
@@ -919,11 +946,13 @@ var OIMEventQueue = class {
919
946
  */
920
947
  flush() {
921
948
  if (this.queue.length === 0) return;
949
+ this.emitter.emit(1 /* BEFORE_FLUSH */, void 0);
922
950
  const currentQueue = this.queue.slice();
923
951
  this.queue.length = 0;
924
952
  for (let i = 0; i < currentQueue.length; i++) {
925
953
  currentQueue[i]();
926
954
  }
955
+ this.emitter.emit(0 /* AFTER_FLUSH */, void 0);
927
956
  }
928
957
  /**
929
958
  * Get the current number of queued functions.
@@ -1228,6 +1257,7 @@ var OIMEventQueueSchedulerFactory = class {
1228
1257
  // Annotate the CommonJS export names for ESM import in node:
1229
1258
  0 && (module.exports = {
1230
1259
  EOIMCollectionEventType,
1260
+ EOIMEventQueueEventType,
1231
1261
  EOIMEventQueueSchedulerEventType,
1232
1262
  EOIMIndexEventType,
1233
1263
  EOIMUpdateEventCoalescerEventType,
package/dist/index.d.cts CHANGED
@@ -193,6 +193,8 @@ declare class OIMDBSettings {
193
193
  declare abstract class OIMUpdateEventCoalescer<TKey extends TOIMPk> {
194
194
  readonly emitter: OIMEventEmitter<{
195
195
  0: void;
196
+ 1: void;
197
+ 2: void;
196
198
  }>;
197
199
  protected readonly updatedKeysIndex: OIMIndexManual<typeof OIMDBSettings.UPDATED_KEYS_INDEX_KEY, TKey>;
198
200
  private hasEmittedChanges;
@@ -227,10 +229,16 @@ type TOIMEventQueueOptions = {
227
229
  scheduler?: OIMEventQueueScheduler;
228
230
  };
229
231
 
232
+ declare enum EOIMEventQueueEventType {
233
+ AFTER_FLUSH = 0,
234
+ BEFORE_FLUSH = 1
235
+ }
236
+
230
237
  /**
231
238
  * Event queue that can optionally integrate with a scheduler for automatic flushing.
232
239
  */
233
240
  declare class OIMEventQueue {
241
+ readonly emitter: OIMEventEmitter<Record<EOIMEventQueueEventType, void>>;
234
242
  protected queue: (() => void)[];
235
243
  protected readonly scheduler?: OIMEventQueueScheduler;
236
244
  protected flushBound?: () => void;
@@ -378,6 +386,8 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
378
386
  upsertMany(entities: TEntity[]): void;
379
387
  removeOne(entity: TEntity): void;
380
388
  removeMany(entities: TEntity[]): void;
389
+ removeOneByPk(pk: TPk): void;
390
+ removeManyByPks(pks: readonly TPk[]): void;
381
391
  clear(): void;
382
392
  countAll(): number;
383
393
  getAll(): TEntity[];
@@ -598,7 +608,9 @@ declare class OIMEventQueueSchedulerFactory {
598
608
  /**
599
609
  * Event types for update coalescers */
600
610
  declare enum EOIMUpdateEventCoalescerEventType {
601
- HAS_CHANGES = 0
611
+ HAS_CHANGES = 0,
612
+ BEFORE_FLUSH = 1,
613
+ AFTER_FLUSH = 2
602
614
  }
603
615
 
604
616
  type TOIMIndexKey = string | number | bigint;
@@ -614,4 +626,4 @@ type TOIMUpdatePayload<TKey> = {
614
626
  keys: readonly TKey[];
615
627
  };
616
628
 
617
- export { EOIMCollectionEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMUpdateEventCoalescerEventType, type IOIMEventQueueSchedulerEvents, OIMCollection, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMDBSettings, 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 };
629
+ export { EOIMCollectionEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMUpdateEventCoalescerEventType, type IOIMEventQueueSchedulerEvents, OIMCollection, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMDBSettings, 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 };
package/dist/index.d.ts CHANGED
@@ -193,6 +193,8 @@ declare class OIMDBSettings {
193
193
  declare abstract class OIMUpdateEventCoalescer<TKey extends TOIMPk> {
194
194
  readonly emitter: OIMEventEmitter<{
195
195
  0: void;
196
+ 1: void;
197
+ 2: void;
196
198
  }>;
197
199
  protected readonly updatedKeysIndex: OIMIndexManual<typeof OIMDBSettings.UPDATED_KEYS_INDEX_KEY, TKey>;
198
200
  private hasEmittedChanges;
@@ -227,10 +229,16 @@ type TOIMEventQueueOptions = {
227
229
  scheduler?: OIMEventQueueScheduler;
228
230
  };
229
231
 
232
+ declare enum EOIMEventQueueEventType {
233
+ AFTER_FLUSH = 0,
234
+ BEFORE_FLUSH = 1
235
+ }
236
+
230
237
  /**
231
238
  * Event queue that can optionally integrate with a scheduler for automatic flushing.
232
239
  */
233
240
  declare class OIMEventQueue {
241
+ readonly emitter: OIMEventEmitter<Record<EOIMEventQueueEventType, void>>;
234
242
  protected queue: (() => void)[];
235
243
  protected readonly scheduler?: OIMEventQueueScheduler;
236
244
  protected flushBound?: () => void;
@@ -378,6 +386,8 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
378
386
  upsertMany(entities: TEntity[]): void;
379
387
  removeOne(entity: TEntity): void;
380
388
  removeMany(entities: TEntity[]): void;
389
+ removeOneByPk(pk: TPk): void;
390
+ removeManyByPks(pks: readonly TPk[]): void;
381
391
  clear(): void;
382
392
  countAll(): number;
383
393
  getAll(): TEntity[];
@@ -598,7 +608,9 @@ declare class OIMEventQueueSchedulerFactory {
598
608
  /**
599
609
  * Event types for update coalescers */
600
610
  declare enum EOIMUpdateEventCoalescerEventType {
601
- HAS_CHANGES = 0
611
+ HAS_CHANGES = 0,
612
+ BEFORE_FLUSH = 1,
613
+ AFTER_FLUSH = 2
602
614
  }
603
615
 
604
616
  type TOIMIndexKey = string | number | bigint;
@@ -614,4 +626,4 @@ type TOIMUpdatePayload<TKey> = {
614
626
  keys: readonly TKey[];
615
627
  };
616
628
 
617
- export { EOIMCollectionEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMUpdateEventCoalescerEventType, type IOIMEventQueueSchedulerEvents, OIMCollection, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMDBSettings, 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 };
629
+ export { EOIMCollectionEventType, EOIMEventQueueEventType, EOIMEventQueueSchedulerEventType, EOIMIndexEventType, EOIMUpdateEventCoalescerEventType, type IOIMEventQueueSchedulerEvents, OIMCollection, OIMCollectionStore, OIMCollectionStoreMapDriven, OIMComparatorFactory, OIMDBSettings, 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 };
package/dist/index.js CHANGED
@@ -292,6 +292,8 @@ var OIMIndex = class {
292
292
  // src/enum/EOIMUpdateEventCoalescerEventType.ts
293
293
  var EOIMUpdateEventCoalescerEventType = /* @__PURE__ */ ((EOIMUpdateEventCoalescerEventType2) => {
294
294
  EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["HAS_CHANGES"] = 0] = "HAS_CHANGES";
295
+ EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["BEFORE_FLUSH"] = 1] = "BEFORE_FLUSH";
296
+ EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["AFTER_FLUSH"] = 2] = "AFTER_FLUSH";
295
297
  return EOIMUpdateEventCoalescerEventType2;
296
298
  })(EOIMUpdateEventCoalescerEventType || {});
297
299
 
@@ -528,8 +530,16 @@ var OIMUpdateEventCoalescer = class {
528
530
  * Clear all updated keys and reset the changed state
529
531
  */
530
532
  clearUpdatedKeys() {
533
+ this.emitter.emit(
534
+ 1 /* BEFORE_FLUSH */,
535
+ void 0
536
+ );
531
537
  this.updatedKeysIndex.setPks(OIMDBSettings.UPDATED_KEYS_INDEX_KEY, []);
532
538
  this.hasEmittedChanges = false;
539
+ this.emitter.emit(
540
+ 2 /* AFTER_FLUSH */,
541
+ void 0
542
+ );
533
543
  }
534
544
  /**
535
545
  * Add keys to the updated set and emit HAS_CHANGES event if needed
@@ -718,6 +728,14 @@ var OIMCollection = class {
718
728
  this.store.removeManyByPks(pks);
719
729
  this.emitter.emit(0 /* UPDATE */, { pks });
720
730
  }
731
+ removeOneByPk(pk) {
732
+ this.store.removeOneByPk(pk);
733
+ this.emitter.emit(0 /* UPDATE */, { pks: [pk] });
734
+ }
735
+ removeManyByPks(pks) {
736
+ this.store.removeManyByPks(pks);
737
+ this.emitter.emit(0 /* UPDATE */, { pks });
738
+ }
721
739
  clear() {
722
740
  this.store.clear();
723
741
  this.emitter.emit(0 /* UPDATE */, { pks: [] });
@@ -834,9 +852,17 @@ var OIMComparatorFactory = class {
834
852
  }
835
853
  };
836
854
 
855
+ // src/enum/EOIMEventQueueEventType.ts
856
+ var EOIMEventQueueEventType = /* @__PURE__ */ ((EOIMEventQueueEventType2) => {
857
+ EOIMEventQueueEventType2[EOIMEventQueueEventType2["AFTER_FLUSH"] = 0] = "AFTER_FLUSH";
858
+ EOIMEventQueueEventType2[EOIMEventQueueEventType2["BEFORE_FLUSH"] = 1] = "BEFORE_FLUSH";
859
+ return EOIMEventQueueEventType2;
860
+ })(EOIMEventQueueEventType || {});
861
+
837
862
  // src/core/OIMEventQueue.ts
838
863
  var OIMEventQueue = class {
839
864
  constructor(options = {}) {
865
+ this.emitter = new OIMEventEmitter();
840
866
  this.queue = [];
841
867
  this.scheduler = options.scheduler;
842
868
  if (this.scheduler) {
@@ -863,11 +889,13 @@ var OIMEventQueue = class {
863
889
  */
864
890
  flush() {
865
891
  if (this.queue.length === 0) return;
892
+ this.emitter.emit(1 /* BEFORE_FLUSH */, void 0);
866
893
  const currentQueue = this.queue.slice();
867
894
  this.queue.length = 0;
868
895
  for (let i = 0; i < currentQueue.length; i++) {
869
896
  currentQueue[i]();
870
897
  }
898
+ this.emitter.emit(0 /* AFTER_FLUSH */, void 0);
871
899
  }
872
900
  /**
873
901
  * Get the current number of queued functions.
@@ -1171,6 +1199,7 @@ var OIMEventQueueSchedulerFactory = class {
1171
1199
  };
1172
1200
  export {
1173
1201
  EOIMCollectionEventType,
1202
+ EOIMEventQueueEventType,
1174
1203
  EOIMEventQueueSchedulerEventType,
1175
1204
  EOIMIndexEventType,
1176
1205
  EOIMUpdateEventCoalescerEventType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oimdb/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Core in-memory data library with type-safe indices, reactive subscriptions, and event processing",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",