@oimdb/core 1.0.0 → 1.0.2
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/dist/index.cjs +16 -7
- package/dist/index.d.cts +16 -12
- package/dist/index.d.ts +16 -12
- package/dist/index.js +16 -7
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -207,7 +207,7 @@ var OIMIndex = class {
|
|
|
207
207
|
*/
|
|
208
208
|
getPksByKey(key) {
|
|
209
209
|
const pksSet = this.pks.get(key);
|
|
210
|
-
return pksSet ?
|
|
210
|
+
return pksSet ? pksSet : /* @__PURE__ */ new Set();
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
213
|
* Check if an index key exists
|
|
@@ -272,11 +272,14 @@ var OIMIndex = class {
|
|
|
272
272
|
* If comparator is provided and returns true (no changes), skip the update.
|
|
273
273
|
*/
|
|
274
274
|
setPksWithComparison(key, newPks) {
|
|
275
|
-
const existingPks = this.getPks(key);
|
|
276
|
-
if (this.comparePks && this.comparePks(
|
|
275
|
+
const existingPks = this.getPks(key).values();
|
|
276
|
+
if (this.comparePks && this.comparePks(
|
|
277
|
+
Array.from(existingPks),
|
|
278
|
+
Array.from(newPks.values())
|
|
279
|
+
)) {
|
|
277
280
|
return false;
|
|
278
281
|
}
|
|
279
|
-
this.pks.set(key,
|
|
282
|
+
this.pks.set(key, newPks);
|
|
280
283
|
return true;
|
|
281
284
|
}
|
|
282
285
|
/**
|
|
@@ -305,7 +308,7 @@ var OIMUpdateEventEmitter = class {
|
|
|
305
308
|
return;
|
|
306
309
|
}
|
|
307
310
|
if (updatedKeys.size * 2 < this.keyHandlers.size) {
|
|
308
|
-
for (const key of updatedKeys) {
|
|
311
|
+
for (const key of updatedKeys.values()) {
|
|
309
312
|
const handlers = this.keyHandlers.get(key);
|
|
310
313
|
if (handlers) {
|
|
311
314
|
for (const handler of handlers) {
|
|
@@ -552,7 +555,13 @@ var OIMCollectionStoreMapDriven = class extends OIMCollectionStore {
|
|
|
552
555
|
return this.entities.get(pk);
|
|
553
556
|
}
|
|
554
557
|
getManyByPks(pks) {
|
|
555
|
-
return
|
|
558
|
+
return pks.map((pk) => this.getOneByPk(pk)).filter(Boolean);
|
|
559
|
+
}
|
|
560
|
+
getAll() {
|
|
561
|
+
return Array.from(this.entities.values());
|
|
562
|
+
}
|
|
563
|
+
countAll() {
|
|
564
|
+
return this.entities.size;
|
|
556
565
|
}
|
|
557
566
|
};
|
|
558
567
|
|
|
@@ -697,7 +706,7 @@ var OIMIndexManual = class extends OIMIndex {
|
|
|
697
706
|
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
698
707
|
*/
|
|
699
708
|
setPks(key, pks) {
|
|
700
|
-
const hasChanges = this.setPksWithComparison(key, pks);
|
|
709
|
+
const hasChanges = this.setPksWithComparison(key, new Set(pks));
|
|
701
710
|
if (hasChanges) {
|
|
702
711
|
this.emitUpdate([key]);
|
|
703
712
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,9 @@ declare abstract class OIMCollectionStore<TEntity extends object, TPk extends TO
|
|
|
5
5
|
abstract removeOneByPk(pk: TPk): void;
|
|
6
6
|
abstract removeManyByPks(pks: readonly TPk[]): void;
|
|
7
7
|
abstract getOneByPk(pk: TPk): TEntity | undefined;
|
|
8
|
-
abstract getManyByPks(pks: readonly TPk[]):
|
|
8
|
+
abstract getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
9
|
+
abstract getAll(): TEntity[];
|
|
10
|
+
abstract countAll(): number;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
type TOIMEventHandler<T> = (payload: T) => void;
|
|
@@ -77,16 +79,16 @@ declare abstract class OIMIndex<TKey extends TOIMPk, TPk extends TOIMPk> {
|
|
|
77
79
|
/**
|
|
78
80
|
* Get primary keys for multiple index keys
|
|
79
81
|
*/
|
|
80
|
-
getPksByKeys(keys: readonly TKey[]): Map<TKey,
|
|
82
|
+
getPksByKeys(keys: readonly TKey[]): Map<TKey, Set<TPk>>;
|
|
81
83
|
/**
|
|
82
84
|
* @deprecated Use getPksByKey instead
|
|
83
85
|
* Get primary keys for a specific index key
|
|
84
86
|
*/
|
|
85
|
-
getPks(key: TKey):
|
|
87
|
+
getPks(key: TKey): Set<TPk>;
|
|
86
88
|
/**
|
|
87
89
|
* Get primary keys for a specific index key
|
|
88
90
|
*/
|
|
89
|
-
getPksByKey(key: TKey):
|
|
91
|
+
getPksByKey(key: TKey): Set<TPk>;
|
|
90
92
|
/**
|
|
91
93
|
* Check if an index key exists
|
|
92
94
|
*/
|
|
@@ -125,7 +127,7 @@ declare abstract class OIMIndex<TKey extends TOIMPk, TPk extends TOIMPk> {
|
|
|
125
127
|
* Set primary keys for a specific index key with optional comparison.
|
|
126
128
|
* If comparator is provided and returns true (no changes), skip the update.
|
|
127
129
|
*/
|
|
128
|
-
protected setPksWithComparison(key: TKey, newPks:
|
|
130
|
+
protected setPksWithComparison(key: TKey, newPks: Set<TPk>): boolean;
|
|
129
131
|
/**
|
|
130
132
|
* Emit update event with changed keys
|
|
131
133
|
*/
|
|
@@ -277,8 +279,8 @@ declare abstract class OIMReactiveIndex<TKey extends TOIMPk, TPk extends TOIMPk,
|
|
|
277
279
|
index: TIndex;
|
|
278
280
|
});
|
|
279
281
|
protected abstract createDefaultIndex(): TIndex;
|
|
280
|
-
getPksByKey(key: TKey):
|
|
281
|
-
getPksByKeys(keys: readonly TKey[]): Map<TKey,
|
|
282
|
+
getPksByKey(key: TKey): Set<TPk>;
|
|
283
|
+
getPksByKeys(keys: readonly TKey[]): Map<TKey, Set<TPk>>;
|
|
282
284
|
hasKey(key: TKey): boolean;
|
|
283
285
|
getKeys(): readonly TKey[];
|
|
284
286
|
getKeySize(key: TKey): number;
|
|
@@ -318,7 +320,7 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
318
320
|
protected readonly updateEntity: TOIMEntityUpdater<TEntity>;
|
|
319
321
|
constructor(opts?: TOIMCollectionOptions<TEntity, TPk>);
|
|
320
322
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
321
|
-
getManyByPks(pks: readonly TPk[]):
|
|
323
|
+
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
322
324
|
upsertOne(entity: TEntity): void;
|
|
323
325
|
upsertMany(entities: TEntity[]): void;
|
|
324
326
|
removeOne(entity: TEntity): void;
|
|
@@ -358,7 +360,7 @@ declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMPk>
|
|
|
358
360
|
removeMany(entities: TEntity[]): void;
|
|
359
361
|
removeOne(entity: TEntity): void;
|
|
360
362
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
361
|
-
getManyByPks(pks: readonly TPk[]):
|
|
363
|
+
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
362
364
|
}
|
|
363
365
|
|
|
364
366
|
/**
|
|
@@ -371,7 +373,7 @@ declare class OIMIndexManual<TIndexKey extends TOIMPk, TPk extends TOIMPk> exten
|
|
|
371
373
|
* Set primary keys for a specific index key, replacing any existing values.
|
|
372
374
|
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
373
375
|
*/
|
|
374
|
-
setPks(key: TIndexKey, pks:
|
|
376
|
+
setPks(key: TIndexKey, pks: TPk[]): void;
|
|
375
377
|
/**
|
|
376
378
|
* Add primary keys to a specific index key
|
|
377
379
|
*/
|
|
@@ -391,7 +393,7 @@ declare class OIMReactiveIndexManual<TKey extends TOIMPk, TPk extends TOIMPk> ex
|
|
|
391
393
|
index: OIMIndexManual<TKey, TPk>;
|
|
392
394
|
});
|
|
393
395
|
protected createDefaultIndex(): OIMIndexManual<TKey, TPk>;
|
|
394
|
-
setPks(key: TKey, pks:
|
|
396
|
+
setPks(key: TKey, pks: TPk[]): void;
|
|
395
397
|
addPks(key: TKey, pks: readonly TPk[]): void;
|
|
396
398
|
removePks(key: TKey, pks: readonly TPk[]): void;
|
|
397
399
|
clear(key?: TKey): void;
|
|
@@ -412,7 +414,9 @@ declare class OIMCollectionStoreMapDriven<TEntity extends object, TPk extends TO
|
|
|
412
414
|
removeOneByPk(pk: TPk): void;
|
|
413
415
|
removeManyByPks(pks: readonly TPk[]): void;
|
|
414
416
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
415
|
-
getManyByPks(pks: readonly TPk[]):
|
|
417
|
+
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
418
|
+
getAll(): TEntity[];
|
|
419
|
+
countAll(): number;
|
|
416
420
|
}
|
|
417
421
|
|
|
418
422
|
type TOIMComparator<TEntity extends object> = (a: TEntity, b: TEntity) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ declare abstract class OIMCollectionStore<TEntity extends object, TPk extends TO
|
|
|
5
5
|
abstract removeOneByPk(pk: TPk): void;
|
|
6
6
|
abstract removeManyByPks(pks: readonly TPk[]): void;
|
|
7
7
|
abstract getOneByPk(pk: TPk): TEntity | undefined;
|
|
8
|
-
abstract getManyByPks(pks: readonly TPk[]):
|
|
8
|
+
abstract getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
9
|
+
abstract getAll(): TEntity[];
|
|
10
|
+
abstract countAll(): number;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
type TOIMEventHandler<T> = (payload: T) => void;
|
|
@@ -77,16 +79,16 @@ declare abstract class OIMIndex<TKey extends TOIMPk, TPk extends TOIMPk> {
|
|
|
77
79
|
/**
|
|
78
80
|
* Get primary keys for multiple index keys
|
|
79
81
|
*/
|
|
80
|
-
getPksByKeys(keys: readonly TKey[]): Map<TKey,
|
|
82
|
+
getPksByKeys(keys: readonly TKey[]): Map<TKey, Set<TPk>>;
|
|
81
83
|
/**
|
|
82
84
|
* @deprecated Use getPksByKey instead
|
|
83
85
|
* Get primary keys for a specific index key
|
|
84
86
|
*/
|
|
85
|
-
getPks(key: TKey):
|
|
87
|
+
getPks(key: TKey): Set<TPk>;
|
|
86
88
|
/**
|
|
87
89
|
* Get primary keys for a specific index key
|
|
88
90
|
*/
|
|
89
|
-
getPksByKey(key: TKey):
|
|
91
|
+
getPksByKey(key: TKey): Set<TPk>;
|
|
90
92
|
/**
|
|
91
93
|
* Check if an index key exists
|
|
92
94
|
*/
|
|
@@ -125,7 +127,7 @@ declare abstract class OIMIndex<TKey extends TOIMPk, TPk extends TOIMPk> {
|
|
|
125
127
|
* Set primary keys for a specific index key with optional comparison.
|
|
126
128
|
* If comparator is provided and returns true (no changes), skip the update.
|
|
127
129
|
*/
|
|
128
|
-
protected setPksWithComparison(key: TKey, newPks:
|
|
130
|
+
protected setPksWithComparison(key: TKey, newPks: Set<TPk>): boolean;
|
|
129
131
|
/**
|
|
130
132
|
* Emit update event with changed keys
|
|
131
133
|
*/
|
|
@@ -277,8 +279,8 @@ declare abstract class OIMReactiveIndex<TKey extends TOIMPk, TPk extends TOIMPk,
|
|
|
277
279
|
index: TIndex;
|
|
278
280
|
});
|
|
279
281
|
protected abstract createDefaultIndex(): TIndex;
|
|
280
|
-
getPksByKey(key: TKey):
|
|
281
|
-
getPksByKeys(keys: readonly TKey[]): Map<TKey,
|
|
282
|
+
getPksByKey(key: TKey): Set<TPk>;
|
|
283
|
+
getPksByKeys(keys: readonly TKey[]): Map<TKey, Set<TPk>>;
|
|
282
284
|
hasKey(key: TKey): boolean;
|
|
283
285
|
getKeys(): readonly TKey[];
|
|
284
286
|
getKeySize(key: TKey): number;
|
|
@@ -318,7 +320,7 @@ declare class OIMCollection<TEntity extends object, TPk extends TOIMPk> {
|
|
|
318
320
|
protected readonly updateEntity: TOIMEntityUpdater<TEntity>;
|
|
319
321
|
constructor(opts?: TOIMCollectionOptions<TEntity, TPk>);
|
|
320
322
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
321
|
-
getManyByPks(pks: readonly TPk[]):
|
|
323
|
+
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
322
324
|
upsertOne(entity: TEntity): void;
|
|
323
325
|
upsertMany(entities: TEntity[]): void;
|
|
324
326
|
removeOne(entity: TEntity): void;
|
|
@@ -358,7 +360,7 @@ declare class OIMReactiveCollection<TEntity extends object, TPk extends TOIMPk>
|
|
|
358
360
|
removeMany(entities: TEntity[]): void;
|
|
359
361
|
removeOne(entity: TEntity): void;
|
|
360
362
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
361
|
-
getManyByPks(pks: readonly TPk[]):
|
|
363
|
+
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
362
364
|
}
|
|
363
365
|
|
|
364
366
|
/**
|
|
@@ -371,7 +373,7 @@ declare class OIMIndexManual<TIndexKey extends TOIMPk, TPk extends TOIMPk> exten
|
|
|
371
373
|
* Set primary keys for a specific index key, replacing any existing values.
|
|
372
374
|
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
373
375
|
*/
|
|
374
|
-
setPks(key: TIndexKey, pks:
|
|
376
|
+
setPks(key: TIndexKey, pks: TPk[]): void;
|
|
375
377
|
/**
|
|
376
378
|
* Add primary keys to a specific index key
|
|
377
379
|
*/
|
|
@@ -391,7 +393,7 @@ declare class OIMReactiveIndexManual<TKey extends TOIMPk, TPk extends TOIMPk> ex
|
|
|
391
393
|
index: OIMIndexManual<TKey, TPk>;
|
|
392
394
|
});
|
|
393
395
|
protected createDefaultIndex(): OIMIndexManual<TKey, TPk>;
|
|
394
|
-
setPks(key: TKey, pks:
|
|
396
|
+
setPks(key: TKey, pks: TPk[]): void;
|
|
395
397
|
addPks(key: TKey, pks: readonly TPk[]): void;
|
|
396
398
|
removePks(key: TKey, pks: readonly TPk[]): void;
|
|
397
399
|
clear(key?: TKey): void;
|
|
@@ -412,7 +414,9 @@ declare class OIMCollectionStoreMapDriven<TEntity extends object, TPk extends TO
|
|
|
412
414
|
removeOneByPk(pk: TPk): void;
|
|
413
415
|
removeManyByPks(pks: readonly TPk[]): void;
|
|
414
416
|
getOneByPk(pk: TPk): TEntity | undefined;
|
|
415
|
-
getManyByPks(pks: readonly TPk[]):
|
|
417
|
+
getManyByPks(pks: readonly TPk[]): TEntity[];
|
|
418
|
+
getAll(): TEntity[];
|
|
419
|
+
countAll(): number;
|
|
416
420
|
}
|
|
417
421
|
|
|
418
422
|
type TOIMComparator<TEntity extends object> = (a: TEntity, b: TEntity) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -152,7 +152,7 @@ var OIMIndex = class {
|
|
|
152
152
|
*/
|
|
153
153
|
getPksByKey(key) {
|
|
154
154
|
const pksSet = this.pks.get(key);
|
|
155
|
-
return pksSet ?
|
|
155
|
+
return pksSet ? pksSet : /* @__PURE__ */ new Set();
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Check if an index key exists
|
|
@@ -217,11 +217,14 @@ var OIMIndex = class {
|
|
|
217
217
|
* If comparator is provided and returns true (no changes), skip the update.
|
|
218
218
|
*/
|
|
219
219
|
setPksWithComparison(key, newPks) {
|
|
220
|
-
const existingPks = this.getPks(key);
|
|
221
|
-
if (this.comparePks && this.comparePks(
|
|
220
|
+
const existingPks = this.getPks(key).values();
|
|
221
|
+
if (this.comparePks && this.comparePks(
|
|
222
|
+
Array.from(existingPks),
|
|
223
|
+
Array.from(newPks.values())
|
|
224
|
+
)) {
|
|
222
225
|
return false;
|
|
223
226
|
}
|
|
224
|
-
this.pks.set(key,
|
|
227
|
+
this.pks.set(key, newPks);
|
|
225
228
|
return true;
|
|
226
229
|
}
|
|
227
230
|
/**
|
|
@@ -250,7 +253,7 @@ var OIMUpdateEventEmitter = class {
|
|
|
250
253
|
return;
|
|
251
254
|
}
|
|
252
255
|
if (updatedKeys.size * 2 < this.keyHandlers.size) {
|
|
253
|
-
for (const key of updatedKeys) {
|
|
256
|
+
for (const key of updatedKeys.values()) {
|
|
254
257
|
const handlers = this.keyHandlers.get(key);
|
|
255
258
|
if (handlers) {
|
|
256
259
|
for (const handler of handlers) {
|
|
@@ -497,7 +500,13 @@ var OIMCollectionStoreMapDriven = class extends OIMCollectionStore {
|
|
|
497
500
|
return this.entities.get(pk);
|
|
498
501
|
}
|
|
499
502
|
getManyByPks(pks) {
|
|
500
|
-
return
|
|
503
|
+
return pks.map((pk) => this.getOneByPk(pk)).filter(Boolean);
|
|
504
|
+
}
|
|
505
|
+
getAll() {
|
|
506
|
+
return Array.from(this.entities.values());
|
|
507
|
+
}
|
|
508
|
+
countAll() {
|
|
509
|
+
return this.entities.size;
|
|
501
510
|
}
|
|
502
511
|
};
|
|
503
512
|
|
|
@@ -642,7 +651,7 @@ var OIMIndexManual = class extends OIMIndex {
|
|
|
642
651
|
* Uses optional comparator to skip updates if PKs haven't actually changed.
|
|
643
652
|
*/
|
|
644
653
|
setPks(key, pks) {
|
|
645
|
-
const hasChanges = this.setPksWithComparison(key, pks);
|
|
654
|
+
const hasChanges = this.setPksWithComparison(key, new Set(pks));
|
|
646
655
|
if (hasChanges) {
|
|
647
656
|
this.emitUpdate([key]);
|
|
648
657
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oimdb/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|
|
@@ -17,14 +17,15 @@
|
|
|
17
17
|
"homepage": "https://github.com/abaikov/oimdb#readme",
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
20
21
|
"import": "./dist/index.js",
|
|
21
|
-
"require": "./dist/index.cjs"
|
|
22
|
-
"types": "./dist/index.d.ts"
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsup src/index.ts --dts --format esm,cjs",
|
|
27
|
-
"clean": "rimraf dist"
|
|
27
|
+
"clean": "rimraf dist",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"dist"
|