@oimdb/core 3.8.0 → 3.10.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 +23 -4
- package/dist/index.cjs +238 -251
- package/dist/index.d.cts +153 -183
- package/dist/index.d.ts +153 -183
- package/dist/index.js +236 -247
- package/llms.txt +43 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
EOIMEventQueueSchedulerEventType: () => EOIMEventQueueSchedulerEventType,
|
|
27
27
|
EOIMIndexEventType: () => EOIMIndexEventType,
|
|
28
28
|
EOIMObjectEventType: () => EOIMObjectEventType,
|
|
29
|
-
|
|
29
|
+
OIMBucketCarrierProvider: () => OIMBucketCarrierProvider,
|
|
30
30
|
OIMCarrierKeyedEmitter: () => OIMCarrierKeyedEmitter,
|
|
31
31
|
OIMCarrierSingleEmitter: () => OIMCarrierSingleEmitter,
|
|
32
32
|
OIMCollection: () => OIMCollection,
|
|
@@ -93,9 +93,7 @@ __export(index_exports, {
|
|
|
93
93
|
OIMIndexStoreSetBased: () => OIMIndexStoreSetBased,
|
|
94
94
|
OIMIndexStoreTrieDrivenArrayBased: () => OIMIndexStoreTrieDrivenArrayBased,
|
|
95
95
|
OIMIndexStoreTrieDrivenSetBased: () => OIMIndexStoreTrieDrivenSetBased,
|
|
96
|
-
|
|
97
|
-
OIMKeyDomainTrie: () => OIMKeyDomainTrie,
|
|
98
|
-
OIMKeyPathCarrierResolver: () => OIMKeyPathCarrierResolver,
|
|
96
|
+
OIMKeyPathCarrierProvider: () => OIMKeyPathCarrierProvider,
|
|
99
97
|
OIMKeyedBucketArrayBased: () => OIMKeyedBucketArrayBased,
|
|
100
98
|
OIMKeyedBucketSetBased: () => OIMKeyedBucketSetBased,
|
|
101
99
|
OIMMap2Keys: () => OIMMap2Keys,
|
|
@@ -697,7 +695,7 @@ var OIMIndexArrayBased = class extends OIMIndex {
|
|
|
697
695
|
|
|
698
696
|
// src/core/OIMCarrierKeyedEmitter.ts
|
|
699
697
|
var OIMCarrierKeyedEmitter = class {
|
|
700
|
-
constructor(queue,
|
|
698
|
+
constructor(queue, carrierProvider) {
|
|
701
699
|
// Carriers with at least one subscriber — for markAllUpdated / metrics.
|
|
702
700
|
this.subscribedCarriers = /* @__PURE__ */ new Set();
|
|
703
701
|
// Pending flush batch. A plain array + a `carrier.dirty` flag for dedup —
|
|
@@ -722,17 +720,17 @@ var OIMCarrierKeyedEmitter = class {
|
|
|
722
720
|
}
|
|
723
721
|
};
|
|
724
722
|
this.queue = queue;
|
|
725
|
-
this.
|
|
723
|
+
this.carrierProvider = carrierProvider;
|
|
726
724
|
}
|
|
727
725
|
subscribeOnKey(key, handler) {
|
|
728
|
-
const carrier = this.
|
|
726
|
+
const carrier = this.carrierProvider.getOrReserveCarrier(key);
|
|
729
727
|
this.addHandler(carrier, handler);
|
|
730
728
|
return () => this.removeHandler(carrier, handler);
|
|
731
729
|
}
|
|
732
730
|
subscribeOnKeys(keys, handler) {
|
|
733
731
|
const carriers = [];
|
|
734
732
|
for (let i = 0; i < keys.length; i++) {
|
|
735
|
-
const carrier = this.
|
|
733
|
+
const carrier = this.carrierProvider.getOrReserveCarrier(keys[i]);
|
|
736
734
|
this.addHandler(carrier, handler);
|
|
737
735
|
carriers.push(carrier);
|
|
738
736
|
}
|
|
@@ -743,7 +741,7 @@ var OIMCarrierKeyedEmitter = class {
|
|
|
743
741
|
};
|
|
744
742
|
}
|
|
745
743
|
unsubscribeFromKey(key, handler) {
|
|
746
|
-
const carrier = this.
|
|
744
|
+
const carrier = this.carrierProvider.findCarrier(key);
|
|
747
745
|
if (carrier) this.removeHandler(carrier, handler);
|
|
748
746
|
}
|
|
749
747
|
unsubscribeFromKeys(keys, handler) {
|
|
@@ -766,7 +764,7 @@ var OIMCarrierKeyedEmitter = class {
|
|
|
766
764
|
subscribers.delete(handler);
|
|
767
765
|
if (subscribers.size === 0) {
|
|
768
766
|
this.subscribedCarriers.delete(carrier);
|
|
769
|
-
this.
|
|
767
|
+
this.carrierProvider.onCarrierEmptied?.(carrier);
|
|
770
768
|
}
|
|
771
769
|
}
|
|
772
770
|
/** Fast path: the writer already holds the carrier. */
|
|
@@ -784,7 +782,7 @@ var OIMCarrierKeyedEmitter = class {
|
|
|
784
782
|
this.assertNotInFlush();
|
|
785
783
|
return;
|
|
786
784
|
}
|
|
787
|
-
const carrier = this.
|
|
785
|
+
const carrier = this.carrierProvider.findCarrier(key);
|
|
788
786
|
if (carrier) this.markUpdatedCarrier(carrier);
|
|
789
787
|
else this.assertNotInFlush();
|
|
790
788
|
}
|
|
@@ -809,7 +807,7 @@ var OIMCarrierKeyedEmitter = class {
|
|
|
809
807
|
return this.subscribedCarriers.size > 0;
|
|
810
808
|
}
|
|
811
809
|
getHandlerCount(key) {
|
|
812
|
-
return this.
|
|
810
|
+
return this.carrierProvider.findCarrier(key)?.subscribers?.size ?? 0;
|
|
813
811
|
}
|
|
814
812
|
getMetrics() {
|
|
815
813
|
let totalHandlers = 0;
|
|
@@ -869,8 +867,8 @@ var OIMCarrierKeyedEmitter = class {
|
|
|
869
867
|
}
|
|
870
868
|
};
|
|
871
869
|
|
|
872
|
-
// src/core/
|
|
873
|
-
var
|
|
870
|
+
// src/core/OIMKeyedCarrierProvider.ts
|
|
871
|
+
var OIMKeyedCarrierProvider = class {
|
|
874
872
|
constructor() {
|
|
875
873
|
this.carriers = /* @__PURE__ */ new Map();
|
|
876
874
|
}
|
|
@@ -892,8 +890,8 @@ var OIMKeyedCarrierResolver = class {
|
|
|
892
890
|
|
|
893
891
|
// src/abstract/OIMReactiveIndex.ts
|
|
894
892
|
var OIMReactiveIndex = class {
|
|
895
|
-
constructor(queue, createIndex,
|
|
896
|
-
this.updateEmitter = new OIMCarrierKeyedEmitter(queue,
|
|
893
|
+
constructor(queue, createIndex, createCarrierProvider = () => new OIMKeyedCarrierProvider()) {
|
|
894
|
+
this.updateEmitter = new OIMCarrierKeyedEmitter(queue, createCarrierProvider());
|
|
897
895
|
this.index = createIndex(this.updateEmitter);
|
|
898
896
|
}
|
|
899
897
|
getEntitiesByKey(key) {
|
|
@@ -949,8 +947,8 @@ var OIMReactiveIndex = class {
|
|
|
949
947
|
|
|
950
948
|
// src/abstract/OIMReactiveIndexSetBased.ts
|
|
951
949
|
var OIMReactiveIndexSetBased = class extends OIMReactiveIndex {
|
|
952
|
-
constructor(queue, createIndex,
|
|
953
|
-
super(queue, createIndex,
|
|
950
|
+
constructor(queue, createIndex, createCarrierProvider) {
|
|
951
|
+
super(queue, createIndex, createCarrierProvider);
|
|
954
952
|
}
|
|
955
953
|
getPksByKey(key) {
|
|
956
954
|
return this.index.getPksByKey(key);
|
|
@@ -968,8 +966,8 @@ var OIMReactiveIndexSetBased = class extends OIMReactiveIndex {
|
|
|
968
966
|
|
|
969
967
|
// src/abstract/OIMReactiveIndexArrayBased.ts
|
|
970
968
|
var OIMReactiveIndexArrayBased = class extends OIMReactiveIndex {
|
|
971
|
-
constructor(queue, createIndex,
|
|
972
|
-
super(queue, createIndex,
|
|
969
|
+
constructor(queue, createIndex, createCarrierProvider) {
|
|
970
|
+
super(queue, createIndex, createCarrierProvider);
|
|
973
971
|
}
|
|
974
972
|
getPksByKey(key) {
|
|
975
973
|
return this.index.getPksByKey(key);
|
|
@@ -1244,24 +1242,10 @@ var OIMPkSelectorFactory = class {
|
|
|
1244
1242
|
}
|
|
1245
1243
|
};
|
|
1246
1244
|
|
|
1247
|
-
// src/core/OIMKeyDomainNative.ts
|
|
1248
|
-
var OIMKeyDomainNative = class {
|
|
1249
|
-
createMap() {
|
|
1250
|
-
return /* @__PURE__ */ new Map();
|
|
1251
|
-
}
|
|
1252
|
-
createSet() {
|
|
1253
|
-
return /* @__PURE__ */ new Set();
|
|
1254
|
-
}
|
|
1255
|
-
canonicalize(key) {
|
|
1256
|
-
return key;
|
|
1257
|
-
}
|
|
1258
|
-
};
|
|
1259
|
-
|
|
1260
1245
|
// src/core/OIMCollectionStoreMapDriven.ts
|
|
1261
1246
|
var OIMCollectionStoreMapDriven = class extends OIMCollectionStore {
|
|
1262
1247
|
constructor() {
|
|
1263
1248
|
super(...arguments);
|
|
1264
|
-
this.keyDomain = new OIMKeyDomainNative();
|
|
1265
1249
|
this.slots = /* @__PURE__ */ new Map();
|
|
1266
1250
|
// Slots reserved by indexes for PKs whose entity has not arrived yet.
|
|
1267
1251
|
// They carry `item: undefined` and live apart from `slots` so they do not
|
|
@@ -1434,10 +1418,6 @@ var OIMCollection = class {
|
|
|
1434
1418
|
this.store = opts?.store ?? new OIMCollectionStoreMapDriven();
|
|
1435
1419
|
this.updateEntity = opts?.updateEntity ?? new OIMEntityUpdaterFactory().createMergeEntityUpdater();
|
|
1436
1420
|
}
|
|
1437
|
-
/** The collection's PK keying strategy — read by indexes and wrappers. */
|
|
1438
|
-
get keyDomain() {
|
|
1439
|
-
return this.store.keyDomain;
|
|
1440
|
-
}
|
|
1441
1421
|
getOneByPk(pk) {
|
|
1442
1422
|
return this.store.getOneByPk(pk);
|
|
1443
1423
|
}
|
|
@@ -1450,6 +1430,14 @@ var OIMCollection = class {
|
|
|
1450
1430
|
getOrReserveSlotByPk(pk) {
|
|
1451
1431
|
return this.store.getOrReserveSlotByPk(pk);
|
|
1452
1432
|
}
|
|
1433
|
+
/**
|
|
1434
|
+
* The existing slot for `pk` (live or reserved) WITHOUT creating one — used
|
|
1435
|
+
* by indexes to resolve a pk to its canonical slot for removal (delete by
|
|
1436
|
+
* reference), with no side effect for a pk that is not present.
|
|
1437
|
+
*/
|
|
1438
|
+
findSlotByPk(pk) {
|
|
1439
|
+
return this.store.findSlotByPk(pk);
|
|
1440
|
+
}
|
|
1453
1441
|
getSlotsByPks(pks) {
|
|
1454
1442
|
return this.store.getSlotsByPks(pks);
|
|
1455
1443
|
}
|
|
@@ -1536,7 +1524,9 @@ var OIMReactiveCollection = class extends OIMCollection {
|
|
|
1536
1524
|
constructor(queue, opts) {
|
|
1537
1525
|
super(opts);
|
|
1538
1526
|
this.anyUpdateHandlers = /* @__PURE__ */ new Set();
|
|
1539
|
-
|
|
1527
|
+
// Only ever holds `slot.pk` (one canonical reference per logical key), so a
|
|
1528
|
+
// native `Set` dedups correctly by reference even for composite pks.
|
|
1529
|
+
this.pendingAnyUpdatePks = /* @__PURE__ */ new Set();
|
|
1540
1530
|
this.isAnyUpdateClearPending = false;
|
|
1541
1531
|
this.isAnyUpdateScheduled = false;
|
|
1542
1532
|
this.runAnyUpdate = () => {
|
|
@@ -1812,16 +1802,16 @@ var OIMIndexManualOrderedArrayBased = class extends OIMIndexArrayBased {
|
|
|
1812
1802
|
var OIMCollectionIndexManualOrderedArrayBased = class extends OIMIndexManualOrderedArrayBased {
|
|
1813
1803
|
constructor(opts) {
|
|
1814
1804
|
super();
|
|
1815
|
-
this.
|
|
1805
|
+
this.getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getSlotByPk(pk) : opts.getSlot;
|
|
1816
1806
|
}
|
|
1817
1807
|
push(key, pk) {
|
|
1818
|
-
return this.pushSlot(key, this.
|
|
1808
|
+
return this.pushSlot(key, this.getRequiredSlot(pk));
|
|
1819
1809
|
}
|
|
1820
1810
|
insertAt(key, index, pk) {
|
|
1821
|
-
return this.insertSlotAt(key, index, this.
|
|
1811
|
+
return this.insertSlotAt(key, index, this.getRequiredSlot(pk));
|
|
1822
1812
|
}
|
|
1823
1813
|
reset(key, pks) {
|
|
1824
|
-
this.resetSlots(key, this.
|
|
1814
|
+
this.resetSlots(key, this.getRequiredSlots(pks));
|
|
1825
1815
|
}
|
|
1826
1816
|
getEntitiesByKey(key) {
|
|
1827
1817
|
return super.getEntitiesByKey(key);
|
|
@@ -1829,32 +1819,32 @@ var OIMCollectionIndexManualOrderedArrayBased = class extends OIMIndexManualOrde
|
|
|
1829
1819
|
getEntitiesByKeys(keys) {
|
|
1830
1820
|
return super.getEntitiesByKeys(keys);
|
|
1831
1821
|
}
|
|
1832
|
-
|
|
1833
|
-
|
|
1822
|
+
// Gets the slot for a pk, throwing if the (custom) getter has none — this
|
|
1823
|
+
// ordered index requires a real slot to place in order.
|
|
1824
|
+
getRequiredSlot(pk) {
|
|
1825
|
+
const slot = this.getSlot(pk);
|
|
1826
|
+
if (!slot) {
|
|
1827
|
+
throw new Error(
|
|
1828
|
+
`[OIMCollectionIndexManualOrderedArrayBased]: no slot for PK "${String(pk)}".`
|
|
1829
|
+
);
|
|
1830
|
+
}
|
|
1831
|
+
return slot;
|
|
1834
1832
|
}
|
|
1835
|
-
|
|
1833
|
+
getRequiredSlots(pks) {
|
|
1836
1834
|
const slots = [];
|
|
1837
1835
|
slots.length = pks.length;
|
|
1838
1836
|
for (let i = 0; i < pks.length; i++) {
|
|
1839
|
-
slots[i] = this.
|
|
1837
|
+
slots[i] = this.getRequiredSlot(pks[i]);
|
|
1840
1838
|
}
|
|
1841
1839
|
return slots;
|
|
1842
1840
|
}
|
|
1843
|
-
resolveRequiredSlot(pk) {
|
|
1844
|
-
const slot = this.resolveSlot(pk);
|
|
1845
|
-
if (!slot) {
|
|
1846
|
-
throw new Error(
|
|
1847
|
-
`[OIMCollectionIndexManualOrderedArrayBased]: Unable to resolve slot for PK "${String(pk)}".`
|
|
1848
|
-
);
|
|
1849
|
-
}
|
|
1850
|
-
return slot;
|
|
1851
|
-
}
|
|
1852
1841
|
};
|
|
1853
1842
|
|
|
1854
1843
|
// src/enums/EOIMEventQueueEventType.ts
|
|
1855
1844
|
var EOIMEventQueueEventType = /* @__PURE__ */ ((EOIMEventQueueEventType2) => {
|
|
1856
1845
|
EOIMEventQueueEventType2[EOIMEventQueueEventType2["AFTER_FLUSH"] = 0] = "AFTER_FLUSH";
|
|
1857
1846
|
EOIMEventQueueEventType2[EOIMEventQueueEventType2["BEFORE_FLUSH"] = 1] = "BEFORE_FLUSH";
|
|
1847
|
+
EOIMEventQueueEventType2[EOIMEventQueueEventType2["FLUSH_ERROR"] = 2] = "FLUSH_ERROR";
|
|
1858
1848
|
return EOIMEventQueueEventType2;
|
|
1859
1849
|
})(EOIMEventQueueEventType || {});
|
|
1860
1850
|
|
|
@@ -2267,18 +2257,18 @@ var OIMOrderedListCommandStream = class extends OIMOrderedListCommandBuffer {
|
|
|
2267
2257
|
var OIMCollectionOrderedListCommandStream = class extends OIMOrderedListCommandStream {
|
|
2268
2258
|
constructor(queue, opts) {
|
|
2269
2259
|
const index = opts.index ?? new OIMCollectionIndexManualOrderedArrayBased(
|
|
2270
|
-
opts.collection !== void 0 ? { collection: opts.collection } : {
|
|
2260
|
+
opts.collection !== void 0 ? { collection: opts.collection } : { getSlot: opts.getSlot }
|
|
2271
2261
|
);
|
|
2272
2262
|
super(queue, index);
|
|
2273
2263
|
this.index = index;
|
|
2274
2264
|
}
|
|
2275
2265
|
push(key, pk) {
|
|
2276
|
-
const slot = this.
|
|
2266
|
+
const slot = this.getRequiredSlot(pk);
|
|
2277
2267
|
const index = this.index.pushSlot(key, slot);
|
|
2278
2268
|
this.appendCommand(key, { type: "insert", index, item: slot });
|
|
2279
2269
|
}
|
|
2280
2270
|
insertAt(key, index, pk) {
|
|
2281
|
-
const slot = this.
|
|
2271
|
+
const slot = this.getRequiredSlot(pk);
|
|
2282
2272
|
const safeIndex = this.index.insertSlotAt(key, index, slot);
|
|
2283
2273
|
this.appendCommand(key, {
|
|
2284
2274
|
type: "insert",
|
|
@@ -2288,7 +2278,7 @@ var OIMCollectionOrderedListCommandStream = class extends OIMOrderedListCommandS
|
|
|
2288
2278
|
}
|
|
2289
2279
|
/** Replace the element at `index` with the slot for `pk`, in place. */
|
|
2290
2280
|
setAt(key, index, pk) {
|
|
2291
|
-
const slot = this.
|
|
2281
|
+
const slot = this.getRequiredSlot(pk);
|
|
2292
2282
|
const safeIndex = this.index.setSlotAt(key, index, slot);
|
|
2293
2283
|
if (safeIndex < 0) return;
|
|
2294
2284
|
this.appendCommand(key, {
|
|
@@ -2298,7 +2288,7 @@ var OIMCollectionOrderedListCommandStream = class extends OIMOrderedListCommandS
|
|
|
2298
2288
|
});
|
|
2299
2289
|
}
|
|
2300
2290
|
set(key, pks) {
|
|
2301
|
-
const slots = pks.map((pk) => this.
|
|
2291
|
+
const slots = pks.map((pk) => this.getRequiredSlot(pk));
|
|
2302
2292
|
this.index.resetSlots(key, slots);
|
|
2303
2293
|
this.appendResetCommand(key, slots);
|
|
2304
2294
|
}
|
|
@@ -2310,8 +2300,8 @@ var OIMCollectionOrderedListCommandStream = class extends OIMOrderedListCommandS
|
|
|
2310
2300
|
getEntitiesByKey(key) {
|
|
2311
2301
|
return this.index.getEntitiesByKey(key);
|
|
2312
2302
|
}
|
|
2313
|
-
|
|
2314
|
-
return this.index.
|
|
2303
|
+
getRequiredSlot(pk) {
|
|
2304
|
+
return this.index.getRequiredSlot(
|
|
2315
2305
|
pk
|
|
2316
2306
|
);
|
|
2317
2307
|
}
|
|
@@ -2371,8 +2361,8 @@ var OIMIndexManualArrayBased = class extends OIMIndexArrayBased {
|
|
|
2371
2361
|
}
|
|
2372
2362
|
};
|
|
2373
2363
|
|
|
2374
|
-
// src/core/
|
|
2375
|
-
var
|
|
2364
|
+
// src/core/OIMBucketCarrierProvider.ts
|
|
2365
|
+
var OIMBucketCarrierProvider = class {
|
|
2376
2366
|
constructor(store) {
|
|
2377
2367
|
this.store = store;
|
|
2378
2368
|
}
|
|
@@ -2413,7 +2403,7 @@ var OIMReactiveIndexManualArrayBased = class extends OIMReactiveIndexArrayBased
|
|
|
2413
2403
|
comparePks: opts?.indexOptions?.comparePks,
|
|
2414
2404
|
store
|
|
2415
2405
|
}),
|
|
2416
|
-
() => new
|
|
2406
|
+
() => new OIMBucketCarrierProvider(store)
|
|
2417
2407
|
);
|
|
2418
2408
|
}
|
|
2419
2409
|
setSlots(key, slots) {
|
|
@@ -2430,52 +2420,61 @@ var OIMReactiveIndexManualArrayBased = class extends OIMReactiveIndexArrayBased
|
|
|
2430
2420
|
// src/core/OIMReactiveCollectionIndexManualArrayBased.ts
|
|
2431
2421
|
var OIMReactiveCollectionIndexManualArrayBased = class extends OIMReactiveIndexManualArrayBased {
|
|
2432
2422
|
constructor(queue, opts) {
|
|
2433
|
-
const
|
|
2434
|
-
const pkDomain = opts.collection?.keyDomain ?? new OIMKeyDomainNative();
|
|
2423
|
+
const getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getOrReserveSlotByPk(pk) : opts.getSlot;
|
|
2435
2424
|
super(queue, {
|
|
2436
2425
|
indexOptions: opts.indexOptions
|
|
2437
2426
|
});
|
|
2438
|
-
// Persistent per-key
|
|
2439
|
-
//
|
|
2440
|
-
|
|
2441
|
-
this.
|
|
2442
|
-
this.
|
|
2427
|
+
// Persistent per-key membership for O(1) `addPks` dedup, keyed by the
|
|
2428
|
+
// canonical slot reference (correct for composite pks with a native Set — no
|
|
2429
|
+
// content-addressing needed, since slots are one reference per logical key).
|
|
2430
|
+
this.slotsByKey = /* @__PURE__ */ new Map();
|
|
2431
|
+
this.getSlot = getSlot;
|
|
2432
|
+
this.findSlotForRemoval = opts.collection !== void 0 ? (pk) => opts.collection.findSlotByPk(pk) : opts.getSlot;
|
|
2443
2433
|
}
|
|
2444
2434
|
setPks(key, pks) {
|
|
2445
|
-
const
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
super.setSlots(key, this.resolveSlots(pks));
|
|
2435
|
+
const slots = this.getSlotsOrTransient(pks);
|
|
2436
|
+
this.slotsByKey.set(key, new Set(slots));
|
|
2437
|
+
super.setSlots(key, slots);
|
|
2449
2438
|
}
|
|
2450
2439
|
addPks(key, pks) {
|
|
2451
2440
|
if (pks.length === 0) return;
|
|
2452
|
-
const
|
|
2441
|
+
const slotSet = this.membershipOf(key);
|
|
2453
2442
|
const newSlots = [];
|
|
2454
2443
|
for (const pk of pks) {
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2444
|
+
const slot = this.getSlotOrTransient(pk);
|
|
2445
|
+
if (slotSet.has(slot)) continue;
|
|
2446
|
+
slotSet.add(slot);
|
|
2447
|
+
newSlots.push(slot);
|
|
2458
2448
|
}
|
|
2459
2449
|
if (newSlots.length > 0) this.appendSlots(key, newSlots);
|
|
2460
2450
|
}
|
|
2461
2451
|
removePks(key, pks) {
|
|
2462
2452
|
if (pks.length === 0) return;
|
|
2463
|
-
const
|
|
2453
|
+
const slotsToRemove = /* @__PURE__ */ new Set();
|
|
2454
|
+
const pksToRemove = /* @__PURE__ */ new Set();
|
|
2455
|
+
for (let i = 0; i < pks.length; i++) {
|
|
2456
|
+
const slot = this.findSlotForRemoval(pks[i]);
|
|
2457
|
+
if (slot) slotsToRemove.add(slot);
|
|
2458
|
+
else pksToRemove.add(pks[i]);
|
|
2459
|
+
}
|
|
2464
2460
|
const existingSlots = this.index.getSlotsByKey(key);
|
|
2465
|
-
const
|
|
2466
|
-
|
|
2467
|
-
)
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2461
|
+
const slotSet = this.slotsByKey.get(key);
|
|
2462
|
+
const nextSlots = [];
|
|
2463
|
+
for (let i = 0; i < existingSlots.length; i++) {
|
|
2464
|
+
const slot = existingSlots[i];
|
|
2465
|
+
if (slotsToRemove.has(slot) || pksToRemove.has(slot.pk)) {
|
|
2466
|
+
slotSet?.delete(slot);
|
|
2467
|
+
} else {
|
|
2468
|
+
nextSlots.push(slot);
|
|
2469
|
+
}
|
|
2472
2470
|
}
|
|
2471
|
+
if (nextSlots.length === existingSlots.length) return;
|
|
2473
2472
|
if (nextSlots.length === 0) this.clear(key);
|
|
2474
2473
|
else super.setSlots(key, nextSlots);
|
|
2475
2474
|
}
|
|
2476
2475
|
clear(key) {
|
|
2477
|
-
if (key === void 0) this.
|
|
2478
|
-
else this.
|
|
2476
|
+
if (key === void 0) this.slotsByKey.clear();
|
|
2477
|
+
else this.slotsByKey.delete(key);
|
|
2479
2478
|
super.clear(key);
|
|
2480
2479
|
}
|
|
2481
2480
|
/**
|
|
@@ -2483,16 +2482,12 @@ var OIMReactiveCollectionIndexManualArrayBased = class extends OIMReactiveIndexM
|
|
|
2483
2482
|
* stays correct even if slots were set through a lower-level path.
|
|
2484
2483
|
*/
|
|
2485
2484
|
membershipOf(key) {
|
|
2486
|
-
let
|
|
2487
|
-
if (!
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
for (let i = 0; i < existing.length; i++) {
|
|
2491
|
-
pkSet.add(existing[i].pk);
|
|
2492
|
-
}
|
|
2493
|
-
this.pksByKey.set(key, pkSet);
|
|
2485
|
+
let slotSet = this.slotsByKey.get(key);
|
|
2486
|
+
if (!slotSet) {
|
|
2487
|
+
slotSet = new Set(this.index.getSlotsByKey(key));
|
|
2488
|
+
this.slotsByKey.set(key, slotSet);
|
|
2494
2489
|
}
|
|
2495
|
-
return
|
|
2490
|
+
return slotSet;
|
|
2496
2491
|
}
|
|
2497
2492
|
getEntitiesByKey(key) {
|
|
2498
2493
|
return super.getEntitiesByKey(key);
|
|
@@ -2500,16 +2495,16 @@ var OIMReactiveCollectionIndexManualArrayBased = class extends OIMReactiveIndexM
|
|
|
2500
2495
|
getEntitiesByKeys(keys) {
|
|
2501
2496
|
return super.getEntitiesByKeys(keys);
|
|
2502
2497
|
}
|
|
2503
|
-
|
|
2498
|
+
getSlotsOrTransient(pks) {
|
|
2504
2499
|
const slots = [];
|
|
2505
2500
|
slots.length = pks.length;
|
|
2506
2501
|
for (let i = 0; i < pks.length; i++) {
|
|
2507
|
-
slots[i] = this.
|
|
2502
|
+
slots[i] = this.getSlotOrTransient(pks[i]);
|
|
2508
2503
|
}
|
|
2509
2504
|
return slots;
|
|
2510
2505
|
}
|
|
2511
|
-
|
|
2512
|
-
const slot = this.
|
|
2506
|
+
getSlotOrTransient(pk) {
|
|
2507
|
+
const slot = this.getSlot(pk);
|
|
2513
2508
|
if (!slot) return { pk, item: void 0 };
|
|
2514
2509
|
return slot;
|
|
2515
2510
|
}
|
|
@@ -2519,7 +2514,6 @@ var OIMReactiveCollectionIndexManualArrayBased = class extends OIMReactiveIndexM
|
|
|
2519
2514
|
var OIMIndexManualSetBased = class extends OIMIndexSetBased {
|
|
2520
2515
|
constructor(options = {}) {
|
|
2521
2516
|
super(options);
|
|
2522
|
-
this.pkDomain = options.pkDomain ?? new OIMKeyDomainNative();
|
|
2523
2517
|
}
|
|
2524
2518
|
setSlots(key, slots) {
|
|
2525
2519
|
const bucket = this.setStore.getOrReserveBucket(key);
|
|
@@ -2528,27 +2522,28 @@ var OIMIndexManualSetBased = class extends OIMIndexSetBased {
|
|
|
2528
2522
|
// --- pk-oriented writes: resolve the bucket ONCE and use its own membership
|
|
2529
2523
|
// (pk → slot) for dedup/removal, so a composite (trie) key is walked a single
|
|
2530
2524
|
// time instead of once for the bucket and once for a separate membership map.
|
|
2531
|
-
setPks(key, pks,
|
|
2525
|
+
setPks(key, pks, getSlot) {
|
|
2532
2526
|
const bucket = this.setStore.getOrReserveBucket(key);
|
|
2533
2527
|
const slots = [];
|
|
2534
|
-
for (let i = 0; i < pks.length; i++) slots.push(
|
|
2528
|
+
for (let i = 0; i < pks.length; i++) slots.push(getSlot(pks[i]));
|
|
2535
2529
|
this.replaceBucketContents(bucket, slots);
|
|
2536
|
-
const membership = bucket.membership ?? (bucket.membership =
|
|
2530
|
+
const membership = bucket.membership ?? (bucket.membership = /* @__PURE__ */ new Map());
|
|
2537
2531
|
membership.clear();
|
|
2538
|
-
for (let i = 0; i <
|
|
2539
|
-
if (!membership.has(
|
|
2532
|
+
for (let i = 0; i < slots.length; i++) {
|
|
2533
|
+
if (!membership.has(slots[i].pk)) {
|
|
2534
|
+
membership.set(slots[i].pk, slots[i]);
|
|
2535
|
+
}
|
|
2540
2536
|
}
|
|
2541
2537
|
}
|
|
2542
|
-
addPks(key, pks,
|
|
2538
|
+
addPks(key, pks, getSlot) {
|
|
2543
2539
|
if (pks.length === 0) return;
|
|
2544
2540
|
const bucket = this.setStore.getOrReserveBucket(key);
|
|
2545
2541
|
const membership = this.membershipOf(bucket);
|
|
2546
2542
|
let changed = false;
|
|
2547
2543
|
for (let i = 0; i < pks.length; i++) {
|
|
2548
|
-
const
|
|
2549
|
-
if (membership.has(pk)) continue;
|
|
2550
|
-
|
|
2551
|
-
membership.set(pk, slot);
|
|
2544
|
+
const slot = getSlot(pks[i]);
|
|
2545
|
+
if (membership.has(slot.pk)) continue;
|
|
2546
|
+
membership.set(slot.pk, slot);
|
|
2552
2547
|
if (!bucket.has(slot)) {
|
|
2553
2548
|
bucket.add(slot);
|
|
2554
2549
|
changed = true;
|
|
@@ -2558,6 +2553,11 @@ var OIMIndexManualSetBased = class extends OIMIndexSetBased {
|
|
|
2558
2553
|
this.setStore.retainBucket(bucket);
|
|
2559
2554
|
this.emitBucketChanged(bucket);
|
|
2560
2555
|
}
|
|
2556
|
+
/**
|
|
2557
|
+
* Removes by pk. `pks` must be canonical `slot.pk` references (membership is
|
|
2558
|
+
* keyed by them): for primitive pks that is just the pk; a collection-bound
|
|
2559
|
+
* composite index canonicalizes raw pks to `slot.pk` before calling this.
|
|
2560
|
+
*/
|
|
2561
2561
|
removePks(key, pks) {
|
|
2562
2562
|
if (pks.length === 0) return;
|
|
2563
2563
|
const bucket = this.setStore.findBucket(key);
|
|
@@ -2583,7 +2583,7 @@ var OIMIndexManualSetBased = class extends OIMIndexSetBased {
|
|
|
2583
2583
|
membershipOf(bucket) {
|
|
2584
2584
|
let membership = bucket.membership;
|
|
2585
2585
|
if (!membership) {
|
|
2586
|
-
membership =
|
|
2586
|
+
membership = /* @__PURE__ */ new Map();
|
|
2587
2587
|
bucket.membership = membership;
|
|
2588
2588
|
}
|
|
2589
2589
|
if (membership.size === 0 && bucket.size > 0) {
|
|
@@ -2692,10 +2692,9 @@ var OIMReactiveIndexManualSetBased = class extends OIMReactiveIndexSetBased {
|
|
|
2692
2692
|
queue,
|
|
2693
2693
|
(updateEmitter) => new OIMIndexManualSetBasedReactive(updateEmitter, {
|
|
2694
2694
|
comparePks: opts?.indexOptions?.comparePks,
|
|
2695
|
-
store
|
|
2696
|
-
pkDomain: opts?.pkDomain
|
|
2695
|
+
store
|
|
2697
2696
|
}),
|
|
2698
|
-
() => new
|
|
2697
|
+
() => new OIMBucketCarrierProvider(store)
|
|
2699
2698
|
);
|
|
2700
2699
|
}
|
|
2701
2700
|
setSlots(key, slots) {
|
|
@@ -2715,28 +2714,33 @@ var OIMReactiveIndexManualSetBased = class extends OIMReactiveIndexSetBased {
|
|
|
2715
2714
|
// src/core/OIMReactiveCollectionIndexManualSetBased.ts
|
|
2716
2715
|
var OIMReactiveCollectionIndexManualSetBased = class extends OIMReactiveIndexManualSetBased {
|
|
2717
2716
|
constructor(queue, opts) {
|
|
2718
|
-
const
|
|
2717
|
+
const getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getOrReserveSlotByPk(pk) : opts.getSlot;
|
|
2719
2718
|
super(queue, {
|
|
2720
|
-
indexOptions: opts.indexOptions
|
|
2721
|
-
pkDomain: opts.collection?.keyDomain
|
|
2719
|
+
indexOptions: opts.indexOptions
|
|
2722
2720
|
});
|
|
2723
2721
|
// Bound once so the hot pk-write path passes a stable function (no per-call
|
|
2724
2722
|
// closure allocation).
|
|
2725
|
-
this.
|
|
2726
|
-
const slot = this.
|
|
2723
|
+
this.getSlotOrTransient = (pk) => {
|
|
2724
|
+
const slot = this.getSlot(pk);
|
|
2727
2725
|
if (!slot) return { pk, item: void 0 };
|
|
2728
2726
|
return slot;
|
|
2729
2727
|
};
|
|
2730
|
-
this.
|
|
2728
|
+
this.getSlot = getSlot;
|
|
2729
|
+
this.findSlotForRemoval = opts.collection !== void 0 ? (pk) => opts.collection.findSlotByPk(pk) : opts.getSlot;
|
|
2731
2730
|
}
|
|
2732
2731
|
setPks(key, pks) {
|
|
2733
|
-
this.index.setPks(key, pks, this.
|
|
2732
|
+
this.index.setPks(key, pks, this.getSlotOrTransient);
|
|
2734
2733
|
}
|
|
2735
2734
|
addPks(key, pks) {
|
|
2736
|
-
this.index.addPks(key, pks, this.
|
|
2735
|
+
this.index.addPks(key, pks, this.getSlotOrTransient);
|
|
2737
2736
|
}
|
|
2738
2737
|
removePks(key, pks) {
|
|
2739
|
-
|
|
2738
|
+
const canonical = [];
|
|
2739
|
+
for (let i = 0; i < pks.length; i++) {
|
|
2740
|
+
const slot = this.findSlotForRemoval(pks[i]);
|
|
2741
|
+
canonical.push(slot ? slot.pk : pks[i]);
|
|
2742
|
+
}
|
|
2743
|
+
this.index.removePks(key, canonical);
|
|
2740
2744
|
}
|
|
2741
2745
|
getEntitiesByKey(key) {
|
|
2742
2746
|
return super.getEntitiesByKey(key);
|
|
@@ -2945,29 +2949,34 @@ var OIMIndexStoreTrieDrivenSetBased = class extends OIMIndexStoreSetBased {
|
|
|
2945
2949
|
// src/core/OIMReactiveCollectionIndexCompositeTrieSetBased.ts
|
|
2946
2950
|
var OIMReactiveCollectionIndexCompositeTrieSetBased = class extends OIMReactiveIndexManualSetBased {
|
|
2947
2951
|
constructor(queue, opts) {
|
|
2948
|
-
const
|
|
2952
|
+
const getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getOrReserveSlotByPk(pk) : opts.getSlot;
|
|
2949
2953
|
super(queue, {
|
|
2950
2954
|
indexOptions: {
|
|
2951
2955
|
comparePks: opts.indexOptions?.comparePks,
|
|
2952
2956
|
store: opts.indexOptions?.store ?? new OIMIndexStoreTrieDrivenSetBased()
|
|
2953
|
-
}
|
|
2954
|
-
pkDomain: opts.collection?.keyDomain
|
|
2957
|
+
}
|
|
2955
2958
|
});
|
|
2956
|
-
this.
|
|
2957
|
-
const slot = this.
|
|
2959
|
+
this.getSlotOrTransient = (pk) => {
|
|
2960
|
+
const slot = this.getSlot(pk);
|
|
2958
2961
|
if (!slot) return { pk, item: void 0 };
|
|
2959
2962
|
return slot;
|
|
2960
2963
|
};
|
|
2961
|
-
this.
|
|
2964
|
+
this.getSlot = getSlot;
|
|
2965
|
+
this.findSlotForRemoval = opts.collection !== void 0 ? (pk) => opts.collection.findSlotByPk(pk) : opts.getSlot;
|
|
2962
2966
|
}
|
|
2963
2967
|
setPks(key, pks) {
|
|
2964
|
-
this.index.setPks(key, pks, this.
|
|
2968
|
+
this.index.setPks(key, pks, this.getSlotOrTransient);
|
|
2965
2969
|
}
|
|
2966
2970
|
addPks(key, pks) {
|
|
2967
|
-
this.index.addPks(key, pks, this.
|
|
2971
|
+
this.index.addPks(key, pks, this.getSlotOrTransient);
|
|
2968
2972
|
}
|
|
2969
2973
|
removePks(key, pks) {
|
|
2970
|
-
|
|
2974
|
+
const canonical = [];
|
|
2975
|
+
for (let i = 0; i < pks.length; i++) {
|
|
2976
|
+
const slot = this.findSlotForRemoval(pks[i]);
|
|
2977
|
+
canonical.push(slot ? slot.pk : pks[i]);
|
|
2978
|
+
}
|
|
2979
|
+
this.index.removePks(key, canonical);
|
|
2971
2980
|
}
|
|
2972
2981
|
getEntitiesByKey(key) {
|
|
2973
2982
|
return super.getEntitiesByKey(key);
|
|
@@ -3074,7 +3083,7 @@ var OIMIndexStoreTrieDrivenArrayBased = class extends OIMIndexStoreArrayBased {
|
|
|
3074
3083
|
// src/core/OIMReactiveCollectionIndexCompositeTrieArrayBased.ts
|
|
3075
3084
|
var OIMReactiveCollectionIndexCompositeTrieArrayBased = class extends OIMReactiveIndexManualArrayBased {
|
|
3076
3085
|
constructor(queue, opts) {
|
|
3077
|
-
const
|
|
3086
|
+
const getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getOrReserveSlotByPk(pk) : opts.getSlot;
|
|
3078
3087
|
super(queue, {
|
|
3079
3088
|
indexOptions: {
|
|
3080
3089
|
comparePks: opts.indexOptions?.comparePks,
|
|
@@ -3084,13 +3093,13 @@ var OIMReactiveCollectionIndexCompositeTrieArrayBased = class extends OIMReactiv
|
|
|
3084
3093
|
// Persistent per-key-path pk membership for O(1) `addPks` dedup. Trie-keyed
|
|
3085
3094
|
// so a rebuilt key path matches by content.
|
|
3086
3095
|
this.pksByKey = new OIMTrieMap();
|
|
3087
|
-
this.
|
|
3096
|
+
this.getSlot = getSlot;
|
|
3088
3097
|
}
|
|
3089
3098
|
setPks(key, pks) {
|
|
3090
3099
|
const pkSet = /* @__PURE__ */ new Set();
|
|
3091
3100
|
for (let i = 0; i < pks.length; i++) pkSet.add(pks[i]);
|
|
3092
3101
|
this.pksByKey.set(key, pkSet);
|
|
3093
|
-
super.setSlots(key, this.
|
|
3102
|
+
super.setSlots(key, this.getSlotsOrTransient(pks));
|
|
3094
3103
|
}
|
|
3095
3104
|
addPks(key, pks) {
|
|
3096
3105
|
if (pks.length === 0) return;
|
|
@@ -3099,7 +3108,7 @@ var OIMReactiveCollectionIndexCompositeTrieArrayBased = class extends OIMReactiv
|
|
|
3099
3108
|
for (const pk of pks) {
|
|
3100
3109
|
if (pkSet.has(pk)) continue;
|
|
3101
3110
|
pkSet.add(pk);
|
|
3102
|
-
newSlots.push(this.
|
|
3111
|
+
newSlots.push(this.getSlotOrTransient(pk));
|
|
3103
3112
|
}
|
|
3104
3113
|
if (newSlots.length > 0) this.appendSlots(key, newSlots);
|
|
3105
3114
|
}
|
|
@@ -3145,16 +3154,16 @@ var OIMReactiveCollectionIndexCompositeTrieArrayBased = class extends OIMReactiv
|
|
|
3145
3154
|
getEntitiesByKeys(keys) {
|
|
3146
3155
|
return super.getEntitiesByKeys(keys);
|
|
3147
3156
|
}
|
|
3148
|
-
|
|
3157
|
+
getSlotsOrTransient(pks) {
|
|
3149
3158
|
const slots = [];
|
|
3150
3159
|
slots.length = pks.length;
|
|
3151
3160
|
for (let i = 0; i < pks.length; i++) {
|
|
3152
|
-
slots[i] = this.
|
|
3161
|
+
slots[i] = this.getSlotOrTransient(pks[i]);
|
|
3153
3162
|
}
|
|
3154
3163
|
return slots;
|
|
3155
3164
|
}
|
|
3156
|
-
|
|
3157
|
-
const slot = this.
|
|
3165
|
+
getSlotOrTransient(pk) {
|
|
3166
|
+
const slot = this.getSlot(pk);
|
|
3158
3167
|
if (!slot) return { pk, item: void 0 };
|
|
3159
3168
|
return slot;
|
|
3160
3169
|
}
|
|
@@ -3467,20 +3476,20 @@ var OIMReactiveGlobalIndexManualArrayBased = class extends OIMReactiveGlobalInde
|
|
|
3467
3476
|
// src/core/OIMReactiveCollectionGlobalIndexManualArrayBased.ts
|
|
3468
3477
|
var OIMReactiveCollectionGlobalIndexManualArrayBased = class extends OIMReactiveGlobalIndexManualArrayBased {
|
|
3469
3478
|
constructor(queue, opts) {
|
|
3470
|
-
const
|
|
3479
|
+
const getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getOrReserveSlotByPk(pk) : opts.getSlot;
|
|
3471
3480
|
super(queue, { indexOptions: opts.indexOptions });
|
|
3472
3481
|
// Single pk membership set for O(1) `addPks` dedup. Lazily seeded from the
|
|
3473
3482
|
// bucket so it stays correct even after a raw `setSlots` (e.g. derived
|
|
3474
3483
|
// rebuild), matching the keyed index's `membershipOf`.
|
|
3475
3484
|
this.membership = /* @__PURE__ */ new Set();
|
|
3476
3485
|
this.membershipSeeded = false;
|
|
3477
|
-
this.
|
|
3486
|
+
this.getSlot = getSlot;
|
|
3478
3487
|
}
|
|
3479
3488
|
setPks(pks) {
|
|
3480
3489
|
this.membership.clear();
|
|
3481
3490
|
for (let i = 0; i < pks.length; i++) this.membership.add(pks[i]);
|
|
3482
3491
|
this.membershipSeeded = true;
|
|
3483
|
-
super.setSlots(this.
|
|
3492
|
+
super.setSlots(this.getSlotsOrTransient(pks));
|
|
3484
3493
|
}
|
|
3485
3494
|
addPks(pks) {
|
|
3486
3495
|
if (pks.length === 0) return;
|
|
@@ -3489,7 +3498,7 @@ var OIMReactiveCollectionGlobalIndexManualArrayBased = class extends OIMReactive
|
|
|
3489
3498
|
for (const pk of pks) {
|
|
3490
3499
|
if (membership.has(pk)) continue;
|
|
3491
3500
|
membership.add(pk);
|
|
3492
|
-
newSlots.push(this.
|
|
3501
|
+
newSlots.push(this.getSlotOrTransient(pk));
|
|
3493
3502
|
}
|
|
3494
3503
|
if (newSlots.length > 0) super.appendSlots(newSlots);
|
|
3495
3504
|
}
|
|
@@ -3526,16 +3535,16 @@ var OIMReactiveCollectionGlobalIndexManualArrayBased = class extends OIMReactive
|
|
|
3526
3535
|
getEntities() {
|
|
3527
3536
|
return super.getEntities();
|
|
3528
3537
|
}
|
|
3529
|
-
|
|
3538
|
+
getSlotsOrTransient(pks) {
|
|
3530
3539
|
const slots = [];
|
|
3531
3540
|
slots.length = pks.length;
|
|
3532
3541
|
for (let i = 0; i < pks.length; i++) {
|
|
3533
|
-
slots[i] = this.
|
|
3542
|
+
slots[i] = this.getSlotOrTransient(pks[i]);
|
|
3534
3543
|
}
|
|
3535
3544
|
return slots;
|
|
3536
3545
|
}
|
|
3537
|
-
|
|
3538
|
-
const slot = this.
|
|
3546
|
+
getSlotOrTransient(pk) {
|
|
3547
|
+
const slot = this.getSlot(pk);
|
|
3539
3548
|
if (!slot) return { pk, item: void 0 };
|
|
3540
3549
|
return slot;
|
|
3541
3550
|
}
|
|
@@ -3615,18 +3624,18 @@ var OIMReactiveGlobalIndexManualSetBased = class extends OIMReactiveGlobalIndexS
|
|
|
3615
3624
|
// src/core/OIMReactiveCollectionGlobalIndexManualSetBased.ts
|
|
3616
3625
|
var OIMReactiveCollectionGlobalIndexManualSetBased = class extends OIMReactiveGlobalIndexManualSetBased {
|
|
3617
3626
|
constructor(queue, opts) {
|
|
3618
|
-
const
|
|
3627
|
+
const getSlot = opts.collection !== void 0 ? (pk) => opts.collection.getOrReserveSlotByPk(pk) : opts.getSlot;
|
|
3619
3628
|
super(queue, { indexOptions: opts.indexOptions });
|
|
3620
3629
|
this.membership = /* @__PURE__ */ new Map();
|
|
3621
3630
|
this.membershipSeeded = false;
|
|
3622
|
-
this.
|
|
3631
|
+
this.getSlot = getSlot;
|
|
3623
3632
|
}
|
|
3624
3633
|
setPks(pks) {
|
|
3625
3634
|
this.membership.clear();
|
|
3626
3635
|
const slots = [];
|
|
3627
3636
|
for (let i = 0; i < pks.length; i++) {
|
|
3628
3637
|
const pk = pks[i];
|
|
3629
|
-
const slot = this.
|
|
3638
|
+
const slot = this.getSlotOrTransient(pk);
|
|
3630
3639
|
if (!this.membership.has(pk)) this.membership.set(pk, slot);
|
|
3631
3640
|
slots.push(slot);
|
|
3632
3641
|
}
|
|
@@ -3639,7 +3648,7 @@ var OIMReactiveCollectionGlobalIndexManualSetBased = class extends OIMReactiveGl
|
|
|
3639
3648
|
const newSlots = [];
|
|
3640
3649
|
for (const pk of pks) {
|
|
3641
3650
|
if (membership.has(pk)) continue;
|
|
3642
|
-
const slot = this.
|
|
3651
|
+
const slot = this.getSlotOrTransient(pk);
|
|
3643
3652
|
membership.set(pk, slot);
|
|
3644
3653
|
newSlots.push(slot);
|
|
3645
3654
|
}
|
|
@@ -3678,8 +3687,8 @@ var OIMReactiveCollectionGlobalIndexManualSetBased = class extends OIMReactiveGl
|
|
|
3678
3687
|
getEntities() {
|
|
3679
3688
|
return super.getEntities();
|
|
3680
3689
|
}
|
|
3681
|
-
|
|
3682
|
-
const slot = this.
|
|
3690
|
+
getSlotOrTransient(pk) {
|
|
3691
|
+
const slot = this.getSlot(pk);
|
|
3683
3692
|
if (!slot) return { pk, item: void 0 };
|
|
3684
3693
|
return slot;
|
|
3685
3694
|
}
|
|
@@ -4088,7 +4097,7 @@ var OIMObject = class {
|
|
|
4088
4097
|
var OIMReactiveObject = class extends OIMObject {
|
|
4089
4098
|
constructor(queue, opts) {
|
|
4090
4099
|
super(opts);
|
|
4091
|
-
this.updateEmitter = new OIMCarrierKeyedEmitter(queue, new
|
|
4100
|
+
this.updateEmitter = new OIMCarrierKeyedEmitter(queue, new OIMKeyedCarrierProvider());
|
|
4092
4101
|
}
|
|
4093
4102
|
/**
|
|
4094
4103
|
* Mark the written key(s) on the keyed emitter directly — no general-event
|
|
@@ -4130,57 +4139,10 @@ var OIMReactiveObject = class extends OIMObject {
|
|
|
4130
4139
|
}
|
|
4131
4140
|
};
|
|
4132
4141
|
|
|
4133
|
-
// src/core/OIMTrieSet.ts
|
|
4134
|
-
var OIMTrieSet = class {
|
|
4135
|
-
constructor() {
|
|
4136
|
-
this.map = new OIMTrieMap();
|
|
4137
|
-
}
|
|
4138
|
-
get size() {
|
|
4139
|
-
return this.map.size;
|
|
4140
|
-
}
|
|
4141
|
-
add(key) {
|
|
4142
|
-
this.map.set(key, true);
|
|
4143
|
-
}
|
|
4144
|
-
has(key) {
|
|
4145
|
-
return this.map.has(key);
|
|
4146
|
-
}
|
|
4147
|
-
delete(key) {
|
|
4148
|
-
return this.map.delete(key);
|
|
4149
|
-
}
|
|
4150
|
-
*values() {
|
|
4151
|
-
yield* this.map.keys();
|
|
4152
|
-
}
|
|
4153
|
-
clear() {
|
|
4154
|
-
this.map.clear();
|
|
4155
|
-
}
|
|
4156
|
-
};
|
|
4157
|
-
|
|
4158
|
-
// src/core/OIMKeyDomainTrie.ts
|
|
4159
|
-
var OIMKeyDomainTrie = class {
|
|
4160
|
-
constructor() {
|
|
4161
|
-
// Interning pool: logical key (by content) → the one canonical reference.
|
|
4162
|
-
this.pool = new OIMTrieMap();
|
|
4163
|
-
}
|
|
4164
|
-
createMap() {
|
|
4165
|
-
return new OIMTrieMap();
|
|
4166
|
-
}
|
|
4167
|
-
createSet() {
|
|
4168
|
-
return new OIMTrieSet();
|
|
4169
|
-
}
|
|
4170
|
-
canonicalize(key) {
|
|
4171
|
-
const existing = this.pool.get(key);
|
|
4172
|
-
if (existing !== void 0) return existing;
|
|
4173
|
-
const canonical = Object.freeze(key.slice());
|
|
4174
|
-
this.pool.set(canonical, canonical);
|
|
4175
|
-
return canonical;
|
|
4176
|
-
}
|
|
4177
|
-
};
|
|
4178
|
-
|
|
4179
4142
|
// src/core/OIMCollectionStoreTrieDriven.ts
|
|
4180
4143
|
var OIMCollectionStoreTrieDriven = class extends OIMCollectionStore {
|
|
4181
|
-
constructor(
|
|
4182
|
-
super();
|
|
4183
|
-
this.keyDomain = keyDomain;
|
|
4144
|
+
constructor() {
|
|
4145
|
+
super(...arguments);
|
|
4184
4146
|
this.slots = new OIMTrieMap();
|
|
4185
4147
|
this.reservedSlots = new OIMTrieMap();
|
|
4186
4148
|
}
|
|
@@ -4198,7 +4160,7 @@ var OIMCollectionStoreTrieDriven = class extends OIMCollectionStore {
|
|
|
4198
4160
|
return reserved;
|
|
4199
4161
|
}
|
|
4200
4162
|
const nextSlot = {
|
|
4201
|
-
pk
|
|
4163
|
+
pk,
|
|
4202
4164
|
item: entity
|
|
4203
4165
|
};
|
|
4204
4166
|
this.slots.set(pk, nextSlot);
|
|
@@ -4209,7 +4171,7 @@ var OIMCollectionStoreTrieDriven = class extends OIMCollectionStore {
|
|
|
4209
4171
|
if (slot) return slot;
|
|
4210
4172
|
let reserved = this.reservedSlots.get(pk);
|
|
4211
4173
|
if (!reserved) {
|
|
4212
|
-
reserved = { pk
|
|
4174
|
+
reserved = { pk, item: void 0 };
|
|
4213
4175
|
this.reservedSlots.set(pk, reserved);
|
|
4214
4176
|
}
|
|
4215
4177
|
return reserved;
|
|
@@ -4366,8 +4328,8 @@ var OIMObjectStoreMapDriven = class extends OIMObjectStore {
|
|
|
4366
4328
|
}
|
|
4367
4329
|
};
|
|
4368
4330
|
|
|
4369
|
-
// src/core/
|
|
4370
|
-
var
|
|
4331
|
+
// src/core/OIMKeyPathCarrierProvider.ts
|
|
4332
|
+
var OIMKeyPathCarrierProvider = class {
|
|
4371
4333
|
constructor() {
|
|
4372
4334
|
this.carriers = new OIMTrieMap();
|
|
4373
4335
|
}
|
|
@@ -4420,6 +4382,7 @@ var OIMEventQueue = class {
|
|
|
4420
4382
|
this.tasksSpare = /* @__PURE__ */ new Set();
|
|
4421
4383
|
this.isFlushing = false;
|
|
4422
4384
|
this.scheduler = options.scheduler;
|
|
4385
|
+
this.onError = options.onError;
|
|
4423
4386
|
if (this.scheduler) {
|
|
4424
4387
|
this.flushBound = () => this.flush();
|
|
4425
4388
|
this.scheduler.on(
|
|
@@ -4459,12 +4422,34 @@ var OIMEventQueue = class {
|
|
|
4459
4422
|
const flushing = this.tasks;
|
|
4460
4423
|
this.tasks = this.tasksSpare;
|
|
4461
4424
|
this.flushing = flushing;
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4425
|
+
let errors;
|
|
4426
|
+
try {
|
|
4427
|
+
for (const task of flushing) {
|
|
4428
|
+
try {
|
|
4429
|
+
task();
|
|
4430
|
+
} catch (error) {
|
|
4431
|
+
(errors ?? (errors = [])).push(error);
|
|
4432
|
+
this.emitter.emit(2 /* FLUSH_ERROR */, {
|
|
4433
|
+
error
|
|
4434
|
+
});
|
|
4435
|
+
this.onError?.(error);
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
} finally {
|
|
4439
|
+
flushing.clear();
|
|
4440
|
+
this.tasksSpare = flushing;
|
|
4441
|
+
this.flushing = void 0;
|
|
4442
|
+
this.isFlushing = false;
|
|
4443
|
+
}
|
|
4467
4444
|
this.emitter.emit(0 /* AFTER_FLUSH */, void 0);
|
|
4445
|
+
if (errors && this.onError === void 0) {
|
|
4446
|
+
if (errors.length === 1) throw errors[0];
|
|
4447
|
+
const AggregateErrorCtor = globalThis.AggregateError;
|
|
4448
|
+
throw AggregateErrorCtor ? new AggregateErrorCtor(
|
|
4449
|
+
errors,
|
|
4450
|
+
"Errors thrown during queue flush"
|
|
4451
|
+
) : errors[0];
|
|
4452
|
+
}
|
|
4468
4453
|
}
|
|
4469
4454
|
/**
|
|
4470
4455
|
* Get the current number of queued functions.
|
|
@@ -4667,6 +4652,31 @@ function createOIMDisposeScope() {
|
|
|
4667
4652
|
return new OIMDisposeScope();
|
|
4668
4653
|
}
|
|
4669
4654
|
|
|
4655
|
+
// src/core/OIMTrieSet.ts
|
|
4656
|
+
var OIMTrieSet = class {
|
|
4657
|
+
constructor() {
|
|
4658
|
+
this.map = new OIMTrieMap();
|
|
4659
|
+
}
|
|
4660
|
+
get size() {
|
|
4661
|
+
return this.map.size;
|
|
4662
|
+
}
|
|
4663
|
+
add(key) {
|
|
4664
|
+
this.map.set(key, true);
|
|
4665
|
+
}
|
|
4666
|
+
has(key) {
|
|
4667
|
+
return this.map.has(key);
|
|
4668
|
+
}
|
|
4669
|
+
delete(key) {
|
|
4670
|
+
return this.map.delete(key);
|
|
4671
|
+
}
|
|
4672
|
+
*values() {
|
|
4673
|
+
yield* this.map.keys();
|
|
4674
|
+
}
|
|
4675
|
+
clear() {
|
|
4676
|
+
this.map.clear();
|
|
4677
|
+
}
|
|
4678
|
+
};
|
|
4679
|
+
|
|
4670
4680
|
// src/core/OIMPkCodecKeyPath.ts
|
|
4671
4681
|
var OIMPkCodecKeyPath = class {
|
|
4672
4682
|
encode(pk) {
|
|
@@ -6314,35 +6324,20 @@ var OIMComputed = class {
|
|
|
6314
6324
|
};
|
|
6315
6325
|
|
|
6316
6326
|
// src/modules/effect/core/OIMEffectDependencyKeyed.ts
|
|
6317
|
-
function isReadonlyArray(value) {
|
|
6318
|
-
return Array.isArray(value);
|
|
6319
|
-
}
|
|
6320
6327
|
var OIMEffectDependencyKeyed = class {
|
|
6321
|
-
constructor(source,
|
|
6328
|
+
constructor(source, key) {
|
|
6322
6329
|
this.source = source;
|
|
6323
|
-
|
|
6324
|
-
this.keys = keyOrKeys;
|
|
6325
|
-
} else {
|
|
6326
|
-
this.key = keyOrKeys;
|
|
6327
|
-
}
|
|
6330
|
+
this.key = key;
|
|
6328
6331
|
}
|
|
6329
6332
|
subscribe(onUpdate) {
|
|
6330
|
-
if (this.keys !== void 0) {
|
|
6331
|
-
return this.source.subscribeOnKeys(this.keys, onUpdate);
|
|
6332
|
-
}
|
|
6333
|
-
if (this.key === void 0) return () => {
|
|
6334
|
-
};
|
|
6335
6333
|
return this.source.subscribeOnKey(this.key, onUpdate);
|
|
6336
6334
|
}
|
|
6337
6335
|
};
|
|
6338
6336
|
|
|
6339
6337
|
// src/modules/effect/core/OIMEffectDependencyKeyedObject.ts
|
|
6340
6338
|
var OIMEffectDependencyKeyedObject = class {
|
|
6341
|
-
constructor(object,
|
|
6342
|
-
this.dep = new OIMEffectDependencyKeyed(
|
|
6343
|
-
object,
|
|
6344
|
-
keyOrKeys
|
|
6345
|
-
);
|
|
6339
|
+
constructor(object, key) {
|
|
6340
|
+
this.dep = new OIMEffectDependencyKeyed(object, key);
|
|
6346
6341
|
}
|
|
6347
6342
|
get source() {
|
|
6348
6343
|
return this.dep.source;
|
|
@@ -6354,11 +6349,8 @@ var OIMEffectDependencyKeyedObject = class {
|
|
|
6354
6349
|
|
|
6355
6350
|
// src/modules/effect/core/OIMEffectDependencyKeyedCollection.ts
|
|
6356
6351
|
var OIMEffectDependencyKeyedCollection = class {
|
|
6357
|
-
constructor(collection,
|
|
6358
|
-
this.dep = new OIMEffectDependencyKeyed(
|
|
6359
|
-
collection,
|
|
6360
|
-
pkOrPks
|
|
6361
|
-
);
|
|
6352
|
+
constructor(collection, pk) {
|
|
6353
|
+
this.dep = new OIMEffectDependencyKeyed(collection, pk);
|
|
6362
6354
|
}
|
|
6363
6355
|
get source() {
|
|
6364
6356
|
return this.dep.source;
|
|
@@ -6370,11 +6362,8 @@ var OIMEffectDependencyKeyedCollection = class {
|
|
|
6370
6362
|
|
|
6371
6363
|
// src/modules/effect/core/OIMEffectDependencyKeyedIndex.ts
|
|
6372
6364
|
var OIMEffectDependencyKeyedIndex = class {
|
|
6373
|
-
constructor(index,
|
|
6374
|
-
this.dep = new OIMEffectDependencyKeyed(
|
|
6375
|
-
index,
|
|
6376
|
-
keyOrKeys
|
|
6377
|
-
);
|
|
6365
|
+
constructor(index, key) {
|
|
6366
|
+
this.dep = new OIMEffectDependencyKeyed(index, key);
|
|
6378
6367
|
}
|
|
6379
6368
|
get source() {
|
|
6380
6369
|
return this.dep.source;
|
|
@@ -6522,7 +6511,7 @@ var OIMIndexPksByKeysArrayBasedSelector = class extends OIMSelector {
|
|
|
6522
6511
|
EOIMEventQueueSchedulerEventType,
|
|
6523
6512
|
EOIMIndexEventType,
|
|
6524
6513
|
EOIMObjectEventType,
|
|
6525
|
-
|
|
6514
|
+
OIMBucketCarrierProvider,
|
|
6526
6515
|
OIMCarrierKeyedEmitter,
|
|
6527
6516
|
OIMCarrierSingleEmitter,
|
|
6528
6517
|
OIMCollection,
|
|
@@ -6589,9 +6578,7 @@ var OIMIndexPksByKeysArrayBasedSelector = class extends OIMSelector {
|
|
|
6589
6578
|
OIMIndexStoreSetBased,
|
|
6590
6579
|
OIMIndexStoreTrieDrivenArrayBased,
|
|
6591
6580
|
OIMIndexStoreTrieDrivenSetBased,
|
|
6592
|
-
|
|
6593
|
-
OIMKeyDomainTrie,
|
|
6594
|
-
OIMKeyPathCarrierResolver,
|
|
6581
|
+
OIMKeyPathCarrierProvider,
|
|
6595
6582
|
OIMKeyedBucketArrayBased,
|
|
6596
6583
|
OIMKeyedBucketSetBased,
|
|
6597
6584
|
OIMMap2Keys,
|