@oimdb/core 3.8.0 → 3.9.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 +209 -246
- package/dist/index.d.cts +120 -178
- package/dist/index.d.ts +120 -178
- package/dist/index.js +207 -242
- package/llms.txt +40 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -185,6 +185,25 @@ const multipleUsers = users.getManyByPks(['user1', 'user2']);
|
|
|
185
185
|
const userSlot = users.getSlotByPk('user1');
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
+
#### Composite primary key
|
|
189
|
+
|
|
190
|
+
Instead of a primitive PK, a collection can be keyed by a **composite key path** — an arbitrary-length tuple of primitive segments. Pass a trie-backed store:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { OIMReactiveCollection, OIMCollectionStoreTrieDriven, TOIMKeyPath } from '@oimdb/core';
|
|
194
|
+
|
|
195
|
+
const memberships = new OIMReactiveCollection<Membership, TOIMKeyPath>(queue, {
|
|
196
|
+
selectPk: (m) => [m.userId, m.projectId],
|
|
197
|
+
store: new OIMCollectionStoreTrieDriven<Membership>(),
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
memberships.getOneByPk([1, 10]); // matched by content — a fresh array works
|
|
201
|
+
memberships.subscribeOnKey([1, 10], render);
|
|
202
|
+
memberships.removeOneByPk([1, 10]);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Key paths match **by content** (the store interns each logical PK to one canonical `slot.pk`). Indexes work over such a collection too (`indexFactory.setBasedIndex()` indexes composite PKs). Primitive-PK collections keep the native-`Map` store untouched. At serialization boundaries a composite PK needs an `IOIMPkCodec` (`OIMPkCodecKeyPath`) — `@oimdb/persist`/`@oimdb/snapshot-manager` need none; `@oimdb/redux-adapter` takes it.
|
|
206
|
+
|
|
188
207
|
### Creating a Reactive Index
|
|
189
208
|
|
|
190
209
|
OIMDB provides two types of indexes optimized for different use cases:
|
|
@@ -1424,7 +1443,7 @@ new OIMReactiveCollectionIndexManualSetBased(queue: OIMEventQueue, opts: {
|
|
|
1424
1443
|
store?: OIMIndexStoreSetBased<TKey, TPk>;
|
|
1425
1444
|
};
|
|
1426
1445
|
} | {
|
|
1427
|
-
|
|
1446
|
+
getSlot: TOIMEntitySlotGetter<TPk>;
|
|
1428
1447
|
indexOptions?: {
|
|
1429
1448
|
comparePks?: TOIMIndexComparator<TPk>;
|
|
1430
1449
|
store?: OIMIndexStoreSetBased<TKey, TPk>;
|
|
@@ -1432,7 +1451,7 @@ new OIMReactiveCollectionIndexManualSetBased(queue: OIMEventQueue, opts: {
|
|
|
1432
1451
|
})
|
|
1433
1452
|
```
|
|
1434
1453
|
|
|
1435
|
-
Pass exactly one binding: `collection` for normal collection-bound indexes, or `
|
|
1454
|
+
Pass exactly one binding: `collection` for normal collection-bound indexes, or `getSlot` for custom slot lookup.
|
|
1436
1455
|
|
|
1437
1456
|
**Methods:**
|
|
1438
1457
|
- `setPks(key: TKey, pks: readonly TPk[]): void` - Set primary keys for index key
|
|
@@ -1522,7 +1541,7 @@ new OIMReactiveCollectionIndexManualArrayBased(queue: OIMEventQueue, opts: {
|
|
|
1522
1541
|
store?: OIMIndexStoreArrayBased<TKey, TPk>;
|
|
1523
1542
|
};
|
|
1524
1543
|
} | {
|
|
1525
|
-
|
|
1544
|
+
getSlot: TOIMEntitySlotGetter<TPk>;
|
|
1526
1545
|
indexOptions?: {
|
|
1527
1546
|
comparePks?: TOIMIndexComparator<TPk>;
|
|
1528
1547
|
store?: OIMIndexStoreArrayBased<TKey, TPk>;
|
|
@@ -1530,7 +1549,7 @@ new OIMReactiveCollectionIndexManualArrayBased(queue: OIMEventQueue, opts: {
|
|
|
1530
1549
|
})
|
|
1531
1550
|
```
|
|
1532
1551
|
|
|
1533
|
-
Pass exactly one binding: `collection` for normal collection-bound indexes, or `
|
|
1552
|
+
Pass exactly one binding: `collection` for normal collection-bound indexes, or `getSlot` for custom slot lookup.
|
|
1534
1553
|
|
|
1535
1554
|
**Methods:**
|
|
1536
1555
|
- `setPks(key: TKey, pks: readonly TPk[]): void` - Set primary keys for index key
|