@oimdb/core 1.0.6 → 1.2.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 +40 -16
- package/dist/index.cjs +234 -169
- package/dist/index.d.cts +79 -54
- package/dist/index.d.ts +79 -54
- package/dist/index.js +232 -169
- package/package.json +7 -2
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,
|
|
@@ -28,6 +29,7 @@ __export(index_exports, {
|
|
|
28
29
|
OIMCollectionStore: () => OIMCollectionStore,
|
|
29
30
|
OIMCollectionStoreMapDriven: () => OIMCollectionStoreMapDriven,
|
|
30
31
|
OIMComparatorFactory: () => OIMComparatorFactory,
|
|
32
|
+
OIMDBSettings: () => OIMDBSettings,
|
|
31
33
|
OIMEntityUpdaterFactory: () => OIMEntityUpdaterFactory,
|
|
32
34
|
OIMEventEmitter: () => OIMEventEmitter,
|
|
33
35
|
OIMEventQueue: () => OIMEventQueue,
|
|
@@ -182,18 +184,66 @@ var EOIMIndexEventType = /* @__PURE__ */ ((EOIMIndexEventType2) => {
|
|
|
182
184
|
return EOIMIndexEventType2;
|
|
183
185
|
})(EOIMIndexEventType || {});
|
|
184
186
|
|
|
187
|
+
// src/abstract/OIMIndexStore.ts
|
|
188
|
+
var OIMIndexStore = class {
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/core/OIMIndexStoreMapDriven.ts
|
|
192
|
+
var OIMIndexStoreMapDriven = class extends OIMIndexStore {
|
|
193
|
+
constructor() {
|
|
194
|
+
super(...arguments);
|
|
195
|
+
this.pks = /* @__PURE__ */ new Map();
|
|
196
|
+
}
|
|
197
|
+
setOneByKey(key, pks) {
|
|
198
|
+
this.pks.set(key, pks);
|
|
199
|
+
}
|
|
200
|
+
removeOneByKey(key) {
|
|
201
|
+
this.pks.delete(key);
|
|
202
|
+
}
|
|
203
|
+
removeManyByKeys(keys) {
|
|
204
|
+
for (const key of keys) {
|
|
205
|
+
this.pks.delete(key);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
getOneByKey(key) {
|
|
209
|
+
return this.pks.get(key);
|
|
210
|
+
}
|
|
211
|
+
getManyByKeys(keys) {
|
|
212
|
+
const result = /* @__PURE__ */ new Map();
|
|
213
|
+
for (const key of keys) {
|
|
214
|
+
const pks = this.getOneByKey(key);
|
|
215
|
+
if (pks !== void 0) {
|
|
216
|
+
result.set(key, pks);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
getAllKeys() {
|
|
222
|
+
return Array.from(this.pks.keys());
|
|
223
|
+
}
|
|
224
|
+
getAll() {
|
|
225
|
+
return new Map(this.pks);
|
|
226
|
+
}
|
|
227
|
+
countAll() {
|
|
228
|
+
return this.pks.size;
|
|
229
|
+
}
|
|
230
|
+
clear() {
|
|
231
|
+
this.pks.clear();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
185
235
|
// src/abstract/OIMIndex.ts
|
|
186
236
|
var OIMIndex = class {
|
|
187
237
|
constructor(options = {}) {
|
|
188
|
-
this.pks = /* @__PURE__ */ new Map();
|
|
189
238
|
this.emitter = new OIMEventEmitter();
|
|
190
239
|
this.comparePks = options.comparePks;
|
|
240
|
+
this.store = options.store ?? new OIMIndexStoreMapDriven();
|
|
191
241
|
}
|
|
192
242
|
/**
|
|
193
243
|
* Get primary keys for multiple index keys
|
|
194
244
|
*/
|
|
195
245
|
getPksByKeys(keys) {
|
|
196
|
-
return
|
|
246
|
+
return this.store.getManyByKeys(keys);
|
|
197
247
|
}
|
|
198
248
|
/**
|
|
199
249
|
* @deprecated Use getPksByKey instead
|
|
@@ -206,39 +256,39 @@ var OIMIndex = class {
|
|
|
206
256
|
* Get primary keys for a specific index key
|
|
207
257
|
*/
|
|
208
258
|
getPksByKey(key) {
|
|
209
|
-
const pksSet = this.
|
|
259
|
+
const pksSet = this.store.getOneByKey(key);
|
|
210
260
|
return pksSet ? pksSet : /* @__PURE__ */ new Set();
|
|
211
261
|
}
|
|
212
262
|
/**
|
|
213
263
|
* Check if an index key exists
|
|
214
264
|
*/
|
|
215
265
|
hasKey(key) {
|
|
216
|
-
return this.
|
|
266
|
+
return this.store.getOneByKey(key) !== void 0;
|
|
217
267
|
}
|
|
218
268
|
/**
|
|
219
269
|
* Get all index keys
|
|
220
270
|
*/
|
|
221
271
|
getKeys() {
|
|
222
|
-
return
|
|
272
|
+
return this.store.getAllKeys();
|
|
223
273
|
}
|
|
224
274
|
/**
|
|
225
275
|
* Get the number of primary keys for a specific index key
|
|
226
276
|
*/
|
|
227
277
|
getKeySize(key) {
|
|
228
|
-
const pksSet = this.
|
|
278
|
+
const pksSet = this.store.getOneByKey(key);
|
|
229
279
|
return pksSet ? pksSet.size : 0;
|
|
230
280
|
}
|
|
231
281
|
/**
|
|
232
282
|
* Get total number of index keys
|
|
233
283
|
*/
|
|
234
284
|
get size() {
|
|
235
|
-
return this.
|
|
285
|
+
return this.store.countAll();
|
|
236
286
|
}
|
|
237
287
|
/**
|
|
238
288
|
* Check if the index is empty
|
|
239
289
|
*/
|
|
240
290
|
get isEmpty() {
|
|
241
|
-
return this.
|
|
291
|
+
return this.store.countAll() === 0;
|
|
242
292
|
}
|
|
243
293
|
/**
|
|
244
294
|
* Get performance metrics for monitoring and debugging
|
|
@@ -247,15 +297,16 @@ var OIMIndex = class {
|
|
|
247
297
|
let totalPks = 0;
|
|
248
298
|
let maxBucketSize = 0;
|
|
249
299
|
let minBucketSize = Infinity;
|
|
250
|
-
|
|
300
|
+
const allPks = this.store.getAll();
|
|
301
|
+
for (const pksSet of allPks.values()) {
|
|
251
302
|
totalPks += pksSet.size;
|
|
252
303
|
maxBucketSize = Math.max(maxBucketSize, pksSet.size);
|
|
253
304
|
minBucketSize = Math.min(minBucketSize, pksSet.size);
|
|
254
305
|
}
|
|
255
306
|
return {
|
|
256
|
-
totalKeys:
|
|
307
|
+
totalKeys: allPks.size,
|
|
257
308
|
totalPks,
|
|
258
|
-
averagePksPerKey:
|
|
309
|
+
averagePksPerKey: allPks.size > 0 ? totalPks / allPks.size : 0,
|
|
259
310
|
maxBucketSize: maxBucketSize === -Infinity ? 0 : maxBucketSize,
|
|
260
311
|
minBucketSize: minBucketSize === Infinity ? 0 : minBucketSize
|
|
261
312
|
};
|
|
@@ -265,21 +316,26 @@ var OIMIndex = class {
|
|
|
265
316
|
*/
|
|
266
317
|
destroy() {
|
|
267
318
|
this.emitter.offAll();
|
|
268
|
-
this.
|
|
319
|
+
this.store.clear();
|
|
269
320
|
}
|
|
270
321
|
/**
|
|
271
322
|
* Set primary keys for a specific index key with optional comparison.
|
|
272
323
|
* If comparator is provided and returns true (no changes), skip the update.
|
|
273
324
|
*/
|
|
274
325
|
setPksWithComparison(key, newPks) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
326
|
+
if (this.comparePks) {
|
|
327
|
+
const existingPksSet = this.store.getOneByKey(key);
|
|
328
|
+
if (existingPksSet && existingPksSet.size === newPks.size) {
|
|
329
|
+
const existingPksArray = existingPksSet.size > 0 ? [...existingPksSet] : [];
|
|
330
|
+
const newPksArray = newPks.size > 0 ? [...newPks] : [];
|
|
331
|
+
if (this.comparePks(existingPksArray, newPksArray)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
} else if (!existingPksSet && newPks.size === 0) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
281
337
|
}
|
|
282
|
-
this.
|
|
338
|
+
this.store.setOneByKey(key, newPks);
|
|
283
339
|
return true;
|
|
284
340
|
}
|
|
285
341
|
/**
|
|
@@ -293,6 +349,8 @@ var OIMIndex = class {
|
|
|
293
349
|
// src/enum/EOIMUpdateEventCoalescerEventType.ts
|
|
294
350
|
var EOIMUpdateEventCoalescerEventType = /* @__PURE__ */ ((EOIMUpdateEventCoalescerEventType2) => {
|
|
295
351
|
EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["HAS_CHANGES"] = 0] = "HAS_CHANGES";
|
|
352
|
+
EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["BEFORE_FLUSH"] = 1] = "BEFORE_FLUSH";
|
|
353
|
+
EOIMUpdateEventCoalescerEventType2[EOIMUpdateEventCoalescerEventType2["AFTER_FLUSH"] = 2] = "AFTER_FLUSH";
|
|
296
354
|
return EOIMUpdateEventCoalescerEventType2;
|
|
297
355
|
})(EOIMUpdateEventCoalescerEventType || {});
|
|
298
356
|
|
|
@@ -414,35 +472,141 @@ var OIMUpdateEventEmitter = class {
|
|
|
414
472
|
}
|
|
415
473
|
};
|
|
416
474
|
|
|
475
|
+
// src/core/OIMIndexManual.ts
|
|
476
|
+
var OIMIndexManual = class extends OIMIndex {
|
|
477
|
+
constructor(options = {}) {
|
|
478
|
+
super(options);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Set primary keys for a specific index key, replacing any existing values.
|
|
482
|
+
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
483
|
+
*/
|
|
484
|
+
setPks(key, pks) {
|
|
485
|
+
const hasChanges = this.setPksWithComparison(key, new Set(pks));
|
|
486
|
+
if (hasChanges) {
|
|
487
|
+
this.emitUpdate([key]);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Add primary keys to a specific index key
|
|
492
|
+
*/
|
|
493
|
+
addPks(key, pks) {
|
|
494
|
+
if (pks.length === 0) return;
|
|
495
|
+
let pksSet = this.store.getOneByKey(key);
|
|
496
|
+
if (!pksSet) {
|
|
497
|
+
pksSet = /* @__PURE__ */ new Set();
|
|
498
|
+
this.store.setOneByKey(key, pksSet);
|
|
499
|
+
}
|
|
500
|
+
let hasChanges = false;
|
|
501
|
+
for (const pk of pks) {
|
|
502
|
+
if (!pksSet.has(pk)) {
|
|
503
|
+
pksSet.add(pk);
|
|
504
|
+
hasChanges = true;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (hasChanges) {
|
|
508
|
+
this.store.setOneByKey(key, pksSet);
|
|
509
|
+
this.emitUpdate([key]);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Remove primary keys from a specific index key
|
|
514
|
+
*/
|
|
515
|
+
removePks(key, pks) {
|
|
516
|
+
if (pks.length === 0) return;
|
|
517
|
+
const pksSet = this.store.getOneByKey(key);
|
|
518
|
+
if (!pksSet) return;
|
|
519
|
+
let hasChanges = false;
|
|
520
|
+
for (const pk of pks) {
|
|
521
|
+
if (pksSet.delete(pk)) {
|
|
522
|
+
hasChanges = true;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (pksSet.size === 0) {
|
|
526
|
+
this.store.removeOneByKey(key);
|
|
527
|
+
hasChanges = true;
|
|
528
|
+
} else if (hasChanges) {
|
|
529
|
+
this.store.setOneByKey(key, pksSet);
|
|
530
|
+
}
|
|
531
|
+
if (hasChanges) {
|
|
532
|
+
this.emitUpdate([key]);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Clear all primary keys for a specific index key, or all keys if no key specified
|
|
537
|
+
*/
|
|
538
|
+
clear(key) {
|
|
539
|
+
if (key === void 0) {
|
|
540
|
+
const allKeys = this.store.getAllKeys();
|
|
541
|
+
if (allKeys.length > 0) {
|
|
542
|
+
this.store.clear();
|
|
543
|
+
this.emitUpdate(allKeys);
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
if (this.store.getOneByKey(key) !== void 0) {
|
|
547
|
+
this.store.removeOneByKey(key);
|
|
548
|
+
this.emitUpdate([key]);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
// src/const/OIMDBSettings.ts
|
|
555
|
+
var OIMDBSettings = class {
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* Fixed key used in the manual index to store updated keys set in coalescers.
|
|
559
|
+
* This constant is exported so users can create their own indexes and pass them to coalescers.
|
|
560
|
+
*/
|
|
561
|
+
OIMDBSettings.UPDATED_KEYS_INDEX_KEY = "__updatedKeys__";
|
|
562
|
+
|
|
417
563
|
// src/core/OIMUpdateEventCoalescer.ts
|
|
418
564
|
var OIMUpdateEventCoalescer = class {
|
|
419
|
-
constructor() {
|
|
565
|
+
constructor(index) {
|
|
420
566
|
this.emitter = new OIMEventEmitter();
|
|
421
|
-
this.updatedKeys = /* @__PURE__ */ new Set();
|
|
422
567
|
this.hasEmittedChanges = false;
|
|
568
|
+
this.updatedKeysIndex = index ?? new OIMIndexManual({
|
|
569
|
+
store: new OIMIndexStoreMapDriven()
|
|
570
|
+
});
|
|
571
|
+
if (!this.updatedKeysIndex.hasKey(OIMDBSettings.UPDATED_KEYS_INDEX_KEY)) {
|
|
572
|
+
this.updatedKeysIndex.setPks(
|
|
573
|
+
OIMDBSettings.UPDATED_KEYS_INDEX_KEY,
|
|
574
|
+
[]
|
|
575
|
+
);
|
|
576
|
+
}
|
|
423
577
|
}
|
|
424
578
|
/**
|
|
425
579
|
* Get the set of keys that have been updated since last clear
|
|
426
580
|
*/
|
|
427
581
|
getUpdatedKeys() {
|
|
428
|
-
return this.
|
|
582
|
+
return this.updatedKeysIndex.getPksByKey(
|
|
583
|
+
OIMDBSettings.UPDATED_KEYS_INDEX_KEY
|
|
584
|
+
);
|
|
429
585
|
}
|
|
430
586
|
/**
|
|
431
587
|
* Clear all updated keys and reset the changed state
|
|
432
588
|
*/
|
|
433
589
|
clearUpdatedKeys() {
|
|
434
|
-
this.
|
|
590
|
+
this.emitter.emit(
|
|
591
|
+
1 /* BEFORE_FLUSH */,
|
|
592
|
+
void 0
|
|
593
|
+
);
|
|
594
|
+
this.updatedKeysIndex.setPks(OIMDBSettings.UPDATED_KEYS_INDEX_KEY, []);
|
|
435
595
|
this.hasEmittedChanges = false;
|
|
596
|
+
this.emitter.emit(
|
|
597
|
+
2 /* AFTER_FLUSH */,
|
|
598
|
+
void 0
|
|
599
|
+
);
|
|
436
600
|
}
|
|
437
601
|
/**
|
|
438
602
|
* Add keys to the updated set and emit HAS_CHANGES event if needed
|
|
439
603
|
*/
|
|
440
604
|
addUpdatedKeys(keys) {
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (!
|
|
605
|
+
this.updatedKeysIndex.addPks(
|
|
606
|
+
OIMDBSettings.UPDATED_KEYS_INDEX_KEY,
|
|
607
|
+
keys
|
|
608
|
+
);
|
|
609
|
+
if (!this.hasEmittedChanges) {
|
|
446
610
|
this.hasEmittedChanges = true;
|
|
447
611
|
this.emitter.emit(
|
|
448
612
|
0 /* HAS_CHANGES */,
|
|
@@ -461,23 +625,14 @@ var OIMUpdateEventCoalescerIndex = class extends OIMUpdateEventCoalescer {
|
|
|
461
625
|
* When the index is updated, we keep track of the updated keys.
|
|
462
626
|
*/
|
|
463
627
|
this.handleUpdate = (payload) => {
|
|
464
|
-
|
|
465
|
-
for (const key of payload.keys) {
|
|
466
|
-
this.updatedKeys.add(key);
|
|
467
|
-
}
|
|
468
|
-
if (!hadChanges && this.updatedKeys.size > 0) {
|
|
469
|
-
this.emitter.emit(
|
|
470
|
-
0 /* HAS_CHANGES */,
|
|
471
|
-
void 0
|
|
472
|
-
);
|
|
473
|
-
}
|
|
628
|
+
this.addUpdatedKeys(payload.keys);
|
|
474
629
|
};
|
|
475
630
|
this.indexEmitter.on(0 /* UPDATE */, this.handleUpdate);
|
|
476
631
|
}
|
|
477
632
|
destroy() {
|
|
478
633
|
this.indexEmitter.off(0 /* UPDATE */, this.handleUpdate);
|
|
479
634
|
this.emitter.offAll();
|
|
480
|
-
this.
|
|
635
|
+
this.clearUpdatedKeys();
|
|
481
636
|
}
|
|
482
637
|
};
|
|
483
638
|
|
|
@@ -548,14 +703,24 @@ var OIMCollectionStoreMapDriven = class extends OIMCollectionStore {
|
|
|
548
703
|
}
|
|
549
704
|
removeManyByPks(pks) {
|
|
550
705
|
for (const pk of pks) {
|
|
551
|
-
this.
|
|
706
|
+
this.entities.delete(pk);
|
|
552
707
|
}
|
|
553
708
|
}
|
|
554
709
|
getOneByPk(pk) {
|
|
555
710
|
return this.entities.get(pk);
|
|
556
711
|
}
|
|
557
712
|
getManyByPks(pks) {
|
|
558
|
-
|
|
713
|
+
const result = [];
|
|
714
|
+
result.length = pks.length;
|
|
715
|
+
let writeIndex = 0;
|
|
716
|
+
for (let i = 0; i < pks.length; i++) {
|
|
717
|
+
const entity = this.getOneByPk(pks[i]);
|
|
718
|
+
if (entity !== void 0) {
|
|
719
|
+
result[writeIndex++] = entity;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
result.length = writeIndex;
|
|
723
|
+
return result;
|
|
559
724
|
}
|
|
560
725
|
getAll() {
|
|
561
726
|
return Array.from(this.entities.values());
|
|
@@ -620,6 +785,14 @@ var OIMCollection = class {
|
|
|
620
785
|
this.store.removeManyByPks(pks);
|
|
621
786
|
this.emitter.emit(0 /* UPDATE */, { pks });
|
|
622
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
|
+
}
|
|
623
796
|
clear() {
|
|
624
797
|
this.store.clear();
|
|
625
798
|
this.emitter.emit(0 /* UPDATE */, { pks: [] });
|
|
@@ -657,16 +830,7 @@ var OIMUpdateEventCoalescerCollection = class extends OIMUpdateEventCoalescer {
|
|
|
657
830
|
* When the collection is updated, we keep track of the updated pks.
|
|
658
831
|
*/
|
|
659
832
|
this.handleUpdate = (payload) => {
|
|
660
|
-
|
|
661
|
-
for (const pk of payload.pks) {
|
|
662
|
-
this.updatedKeys.add(pk);
|
|
663
|
-
}
|
|
664
|
-
if (!hadChanges && this.updatedKeys.size > 0) {
|
|
665
|
-
this.emitter.emit(
|
|
666
|
-
0 /* HAS_CHANGES */,
|
|
667
|
-
void 0
|
|
668
|
-
);
|
|
669
|
-
}
|
|
833
|
+
this.addUpdatedKeys(payload.pks);
|
|
670
834
|
};
|
|
671
835
|
this.collectionEmitter.on(
|
|
672
836
|
0 /* UPDATE */,
|
|
@@ -679,129 +843,22 @@ var OIMUpdateEventCoalescerCollection = class extends OIMUpdateEventCoalescer {
|
|
|
679
843
|
this.handleUpdate
|
|
680
844
|
);
|
|
681
845
|
this.emitter.offAll();
|
|
682
|
-
this.
|
|
846
|
+
this.clearUpdatedKeys();
|
|
683
847
|
}
|
|
684
848
|
};
|
|
685
849
|
|
|
686
850
|
// src/core/OIMReactiveCollection.ts
|
|
687
|
-
var OIMReactiveCollection = class {
|
|
851
|
+
var OIMReactiveCollection = class extends OIMCollection {
|
|
688
852
|
constructor(queue, opts) {
|
|
689
|
-
|
|
853
|
+
super(opts);
|
|
690
854
|
this.coalescer = new OIMUpdateEventCoalescerCollection(
|
|
691
|
-
this.
|
|
855
|
+
this.emitter
|
|
692
856
|
);
|
|
693
857
|
this.updateEventEmitter = new OIMUpdateEventEmitter({
|
|
694
858
|
coalescer: this.coalescer,
|
|
695
859
|
queue
|
|
696
860
|
});
|
|
697
861
|
}
|
|
698
|
-
upsertMany(entities) {
|
|
699
|
-
this.collection.upsertMany(entities);
|
|
700
|
-
}
|
|
701
|
-
upsertOne(entity) {
|
|
702
|
-
this.collection.upsertOne(entity);
|
|
703
|
-
}
|
|
704
|
-
removeMany(entities) {
|
|
705
|
-
this.collection.removeMany(entities);
|
|
706
|
-
}
|
|
707
|
-
removeOne(entity) {
|
|
708
|
-
this.collection.removeOne(entity);
|
|
709
|
-
}
|
|
710
|
-
getOneByPk(pk) {
|
|
711
|
-
return this.collection.getOneByPk(pk);
|
|
712
|
-
}
|
|
713
|
-
getManyByPks(pks) {
|
|
714
|
-
return this.collection.getManyByPks(pks);
|
|
715
|
-
}
|
|
716
|
-
clear() {
|
|
717
|
-
this.collection.clear();
|
|
718
|
-
}
|
|
719
|
-
countAll() {
|
|
720
|
-
return this.collection.countAll();
|
|
721
|
-
}
|
|
722
|
-
getAll() {
|
|
723
|
-
return this.collection.getAll();
|
|
724
|
-
}
|
|
725
|
-
getAllPks() {
|
|
726
|
-
return this.collection.getAllPks();
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
|
|
730
|
-
// src/core/OIMIndexManual.ts
|
|
731
|
-
var OIMIndexManual = class extends OIMIndex {
|
|
732
|
-
constructor(options = {}) {
|
|
733
|
-
super(options);
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Set primary keys for a specific index key, replacing any existing values.
|
|
737
|
-
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
738
|
-
*/
|
|
739
|
-
setPks(key, pks) {
|
|
740
|
-
const hasChanges = this.setPksWithComparison(key, new Set(pks));
|
|
741
|
-
if (hasChanges) {
|
|
742
|
-
this.emitUpdate([key]);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* Add primary keys to a specific index key
|
|
747
|
-
*/
|
|
748
|
-
addPks(key, pks) {
|
|
749
|
-
if (pks.length === 0) return;
|
|
750
|
-
let pksSet = this.pks.get(key);
|
|
751
|
-
if (!pksSet) {
|
|
752
|
-
pksSet = /* @__PURE__ */ new Set();
|
|
753
|
-
this.pks.set(key, pksSet);
|
|
754
|
-
}
|
|
755
|
-
let hasChanges = false;
|
|
756
|
-
for (const pk of pks) {
|
|
757
|
-
const sizeBefore = pksSet.size;
|
|
758
|
-
pksSet.add(pk);
|
|
759
|
-
if (pksSet.size > sizeBefore) {
|
|
760
|
-
hasChanges = true;
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
if (hasChanges) {
|
|
764
|
-
this.emitUpdate([key]);
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Remove primary keys from a specific index key
|
|
769
|
-
*/
|
|
770
|
-
removePks(key, pks) {
|
|
771
|
-
if (pks.length === 0) return;
|
|
772
|
-
const pksSet = this.pks.get(key);
|
|
773
|
-
if (!pksSet) return;
|
|
774
|
-
let hasChanges = false;
|
|
775
|
-
for (const pk of pks) {
|
|
776
|
-
if (pksSet.delete(pk)) {
|
|
777
|
-
hasChanges = true;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
if (pksSet.size === 0) {
|
|
781
|
-
this.pks.delete(key);
|
|
782
|
-
hasChanges = true;
|
|
783
|
-
}
|
|
784
|
-
if (hasChanges) {
|
|
785
|
-
this.emitUpdate([key]);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Clear all primary keys for a specific index key, or all keys if no key specified
|
|
790
|
-
*/
|
|
791
|
-
clear(key) {
|
|
792
|
-
if (key === void 0) {
|
|
793
|
-
if (this.pks.size > 0) {
|
|
794
|
-
const allKeys = Array.from(this.pks.keys());
|
|
795
|
-
this.pks.clear();
|
|
796
|
-
this.emitUpdate(allKeys);
|
|
797
|
-
}
|
|
798
|
-
} else {
|
|
799
|
-
if (this.pks.has(key)) {
|
|
800
|
-
this.pks.delete(key);
|
|
801
|
-
this.emitUpdate([key]);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
862
|
};
|
|
806
863
|
|
|
807
864
|
// src/core/OIMReactiveIndexManual.ts
|
|
@@ -829,10 +886,8 @@ var OIMReactiveIndexManual = class extends OIMReactiveIndex {
|
|
|
829
886
|
// src/core/OIMRICollection.ts
|
|
830
887
|
var OIMRICollection = class extends OIMReactiveCollection {
|
|
831
888
|
constructor(queue, opts) {
|
|
832
|
-
super(queue,
|
|
833
|
-
|
|
834
|
-
});
|
|
835
|
-
this.indexes = opts.indexes || {};
|
|
889
|
+
super(queue, opts.collectionOpts);
|
|
890
|
+
this.indexes = opts.indexes;
|
|
836
891
|
}
|
|
837
892
|
};
|
|
838
893
|
|
|
@@ -854,9 +909,17 @@ var OIMComparatorFactory = class {
|
|
|
854
909
|
}
|
|
855
910
|
};
|
|
856
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
|
+
|
|
857
919
|
// src/core/OIMEventQueue.ts
|
|
858
920
|
var OIMEventQueue = class {
|
|
859
921
|
constructor(options = {}) {
|
|
922
|
+
this.emitter = new OIMEventEmitter();
|
|
860
923
|
this.queue = [];
|
|
861
924
|
this.scheduler = options.scheduler;
|
|
862
925
|
if (this.scheduler) {
|
|
@@ -883,11 +946,13 @@ var OIMEventQueue = class {
|
|
|
883
946
|
*/
|
|
884
947
|
flush() {
|
|
885
948
|
if (this.queue.length === 0) return;
|
|
949
|
+
this.emitter.emit(1 /* BEFORE_FLUSH */, void 0);
|
|
886
950
|
const currentQueue = this.queue.slice();
|
|
887
951
|
this.queue.length = 0;
|
|
888
952
|
for (let i = 0; i < currentQueue.length; i++) {
|
|
889
953
|
currentQueue[i]();
|
|
890
954
|
}
|
|
955
|
+
this.emitter.emit(0 /* AFTER_FLUSH */, void 0);
|
|
891
956
|
}
|
|
892
957
|
/**
|
|
893
958
|
* Get the current number of queued functions.
|
|
@@ -955,9 +1020,7 @@ var OIMIndexComparatorFactory = class {
|
|
|
955
1020
|
if (existingSet.size !== newSet.size || existingSet.size !== existingPks.length) {
|
|
956
1021
|
return false;
|
|
957
1022
|
}
|
|
958
|
-
const
|
|
959
|
-
for (let i = 0; i < setValues.length; i++) {
|
|
960
|
-
const pk = setValues[i];
|
|
1023
|
+
for (const pk of existingSet) {
|
|
961
1024
|
if (!newSet.has(pk)) {
|
|
962
1025
|
return false;
|
|
963
1026
|
}
|
|
@@ -1194,6 +1257,7 @@ var OIMEventQueueSchedulerFactory = class {
|
|
|
1194
1257
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1195
1258
|
0 && (module.exports = {
|
|
1196
1259
|
EOIMCollectionEventType,
|
|
1260
|
+
EOIMEventQueueEventType,
|
|
1197
1261
|
EOIMEventQueueSchedulerEventType,
|
|
1198
1262
|
EOIMIndexEventType,
|
|
1199
1263
|
EOIMUpdateEventCoalescerEventType,
|
|
@@ -1201,6 +1265,7 @@ var OIMEventQueueSchedulerFactory = class {
|
|
|
1201
1265
|
OIMCollectionStore,
|
|
1202
1266
|
OIMCollectionStoreMapDriven,
|
|
1203
1267
|
OIMComparatorFactory,
|
|
1268
|
+
OIMDBSettings,
|
|
1204
1269
|
OIMEntityUpdaterFactory,
|
|
1205
1270
|
OIMEventEmitter,
|
|
1206
1271
|
OIMEventQueue,
|