@evolu/common 6.0.1-preview.8 → 7.0.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 +2 -2
- package/dist/src/Array.d.ts +256 -12
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +215 -9
- package/dist/src/Assert.d.ts +0 -13
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +0 -15
- package/dist/src/Brand.d.ts +75 -0
- package/dist/src/Brand.d.ts.map +1 -0
- package/dist/src/Brand.js +1 -0
- package/dist/src/Buffer.d.ts +1 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +8 -7
- package/dist/src/Cache.d.ts +44 -0
- package/dist/src/Cache.d.ts.map +1 -0
- package/dist/src/Cache.js +52 -0
- package/dist/src/Callbacks.d.ts +45 -12
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +14 -7
- package/dist/src/Console.d.ts +31 -6
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +72 -9
- package/dist/src/Crypto.d.ts +56 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +40 -53
- package/dist/src/Evolu/Db.d.ts +162 -74
- package/dist/src/Evolu/Db.d.ts.map +1 -1
- package/dist/src/Evolu/Db.js +284 -702
- package/dist/src/Evolu/Diff.d.ts +3 -3
- package/dist/src/Evolu/Diff.d.ts.map +1 -1
- package/dist/src/Evolu/Diff.js +7 -5
- package/dist/src/Evolu/Evolu.d.ts +214 -134
- package/dist/src/Evolu/Evolu.d.ts.map +1 -1
- package/dist/src/Evolu/Evolu.js +189 -180
- package/dist/src/Evolu/Internal.d.ts +0 -2
- package/dist/src/Evolu/Internal.d.ts.map +1 -1
- package/dist/src/Evolu/Internal.js +0 -2
- package/dist/src/Evolu/LocalAuth.d.ts +150 -0
- package/dist/src/Evolu/LocalAuth.d.ts.map +1 -0
- package/dist/src/Evolu/LocalAuth.js +174 -0
- package/dist/src/Evolu/Owner.d.ts +273 -120
- package/dist/src/Evolu/Owner.d.ts.map +1 -1
- package/dist/src/Evolu/Owner.js +130 -104
- package/dist/src/Evolu/Platform.d.ts +9 -7
- package/dist/src/Evolu/Platform.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.d.ts +268 -240
- package/dist/src/Evolu/Protocol.d.ts.map +1 -1
- package/dist/src/Evolu/Protocol.js +600 -454
- package/dist/src/Evolu/Public.d.ts +6 -8
- package/dist/src/Evolu/Public.d.ts.map +1 -1
- package/dist/src/Evolu/Public.js +2 -3
- package/dist/src/Evolu/PublicKysely.d.ts.map +1 -1
- package/dist/src/Evolu/PublicKysely.js +3 -4
- package/dist/src/Evolu/Query.d.ts +2 -1
- package/dist/src/Evolu/Query.d.ts.map +1 -1
- package/dist/src/Evolu/Query.js +1 -1
- package/dist/src/Evolu/Relay.d.ts +91 -8
- package/dist/src/Evolu/Relay.d.ts.map +1 -1
- package/dist/src/Evolu/Relay.js +214 -88
- package/dist/src/Evolu/Schema.d.ts +125 -47
- package/dist/src/Evolu/Schema.d.ts.map +1 -1
- package/dist/src/Evolu/Schema.js +175 -31
- package/dist/src/Evolu/Storage.d.ts +249 -27
- package/dist/src/Evolu/Storage.d.ts.map +1 -1
- package/dist/src/Evolu/Storage.js +198 -92
- package/dist/src/Evolu/Sync.d.ts +68 -13
- package/dist/src/Evolu/Sync.d.ts.map +1 -1
- package/dist/src/Evolu/Sync.js +469 -20
- package/dist/src/Evolu/Timestamp.d.ts +83 -30
- package/dist/src/Evolu/Timestamp.d.ts.map +1 -1
- package/dist/src/Evolu/Timestamp.js +79 -34
- package/dist/src/Identicon.d.ts +35 -0
- package/dist/src/Identicon.d.ts.map +1 -0
- package/dist/src/Identicon.js +143 -0
- package/dist/src/Instances.d.ts +34 -0
- package/dist/src/Instances.d.ts.map +1 -0
- package/dist/src/Instances.js +44 -0
- package/dist/src/Number.d.ts +4 -3
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +5 -4
- package/dist/src/Object.d.ts +10 -4
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +9 -3
- package/dist/src/Platform.d.ts +20 -0
- package/dist/src/Platform.d.ts.map +1 -0
- package/dist/src/Platform.js +22 -0
- package/dist/src/Random.d.ts +3 -2
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Relation.d.ts +79 -0
- package/dist/src/Relation.d.ts.map +1 -0
- package/dist/src/Relation.js +127 -0
- package/dist/src/Resources.d.ts +118 -0
- package/dist/src/Resources.d.ts.map +1 -0
- package/dist/src/Resources.js +197 -0
- package/dist/src/Result.d.ts +184 -52
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +30 -241
- package/dist/src/Skiplist.js +2 -1
- package/dist/src/Sqlite.d.ts +89 -5
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +136 -9
- package/dist/src/Task.d.ts +586 -0
- package/dist/src/Task.d.ts.map +1 -0
- package/dist/src/Task.js +469 -0
- package/dist/src/Time.d.ts +66 -1
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +99 -5
- package/dist/src/Type.d.ts +676 -343
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +718 -467
- package/dist/src/Types.d.ts +1 -75
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/WebSocket.d.ts +5 -2
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +12 -18
- package/dist/src/Worker.d.ts +39 -11
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +22 -4
- package/dist/src/index.d.ts +8 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -3
- package/package.json +15 -14
- package/src/Array.ts +301 -19
- package/src/Assert.ts +0 -21
- package/src/Brand.ts +75 -0
- package/src/Buffer.ts +7 -7
- package/src/Cache.ts +85 -0
- package/src/Callbacks.ts +62 -22
- package/src/Console.ts +91 -11
- package/src/Crypto.ts +94 -90
- package/src/Evolu/Db.ts +519 -1026
- package/src/Evolu/Diff.ts +7 -5
- package/src/Evolu/Evolu.ts +477 -361
- package/src/Evolu/Internal.ts +0 -2
- package/src/Evolu/LocalAuth.ts +463 -0
- package/src/Evolu/Owner.ts +355 -228
- package/src/Evolu/Platform.ts +9 -9
- package/src/Evolu/Protocol.ts +842 -742
- package/src/Evolu/Public.ts +7 -14
- package/src/Evolu/PublicKysely.ts +4 -5
- package/src/Evolu/Query.ts +3 -2
- package/src/Evolu/Relay.ts +406 -103
- package/src/Evolu/Schema.ts +323 -91
- package/src/Evolu/Storage.ts +559 -137
- package/src/Evolu/Sync.ts +819 -36
- package/src/Evolu/Timestamp.ts +90 -58
- package/src/Identicon.ts +197 -0
- package/src/Instances.ts +90 -0
- package/src/Number.ts +6 -10
- package/src/Object.ts +13 -5
- package/src/Platform.ts +26 -0
- package/src/Random.ts +3 -2
- package/src/Relation.ts +234 -0
- package/src/Resources.ts +367 -0
- package/src/Result.ts +191 -54
- package/src/Skiplist.ts +1 -1
- package/src/Sqlite.ts +152 -17
- package/src/Task.ts +901 -0
- package/src/Time.ts +180 -5
- package/src/Type.ts +1135 -730
- package/src/Types.ts +1 -77
- package/src/WebSocket.ts +27 -25
- package/src/Worker.ts +72 -23
- package/src/index.ts +8 -3
- package/dist/src/Evolu/Config.d.ts +0 -69
- package/dist/src/Evolu/Config.d.ts.map +0 -1
- package/dist/src/Evolu/Config.js +0 -9
- package/dist/src/Evolu/Kysely.d.ts +0 -6
- package/dist/src/Evolu/Kysely.d.ts.map +0 -1
- package/dist/src/Evolu/Kysely.js +0 -21
- package/dist/src/ManyToManyMap.d.ts +0 -26
- package/dist/src/ManyToManyMap.d.ts.map +0 -1
- package/dist/src/ManyToManyMap.js +0 -92
- package/dist/src/NanoId.d.ts +0 -27
- package/dist/src/NanoId.d.ts.map +0 -1
- package/dist/src/NanoId.js +0 -6
- package/dist/src/Promise.d.ts +0 -180
- package/dist/src/Promise.d.ts.map +0 -1
- package/dist/src/Promise.js +0 -176
- package/src/Evolu/Config.ts +0 -83
- package/src/Evolu/Kysely.ts +0 -38
- package/src/ManyToManyMap.ts +0 -140
- package/src/NanoId.ts +0 -39
- package/src/Promise.ts +0 -295
package/dist/src/Number.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NonEmptyReadonlyArray } from "./Array.js";
|
|
2
2
|
import { Result } from "./Result.js";
|
|
3
3
|
import { NonNegativeInt, PositiveInt } from "./Type.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Predicate, WidenLiteral } from "./Types.js";
|
|
5
|
+
import { IsBranded } from "./Brand.js";
|
|
5
6
|
export declare const increment: (n: number) => number;
|
|
6
7
|
export declare const decrement: (n: number) => number;
|
|
7
8
|
/** Clamps a number within a given range. */
|
|
@@ -36,7 +37,7 @@ export declare const max: <T extends number>(...values: [T, ...ReadonlyArray<T>]
|
|
|
36
37
|
*/
|
|
37
38
|
export declare const computeBalancedBuckets: (numberOfItems: NonNegativeInt,
|
|
38
39
|
/** Default: 16 */
|
|
39
|
-
numberOfBuckets?:
|
|
40
|
+
numberOfBuckets?: number & import("./Brand.js").Brand<"Int"> & import("./Brand.js").Brand<"NonNegative"> & import("./Brand.js").Brand<"Positive">,
|
|
40
41
|
/** Default: 2 */
|
|
41
|
-
minNumberOfItemsPerBucket?:
|
|
42
|
+
minNumberOfItemsPerBucket?: number & import("./Brand.js").Brand<"Int"> & import("./Brand.js").Brand<"NonNegative"> & import("./Brand.js").Brand<"Positive">) => Result<NonEmptyReadonlyArray<PositiveInt>, PositiveInt>;
|
|
42
43
|
//# sourceMappingURL=Number.d.ts.map
|
package/dist/src/Number.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../../src/Number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEn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AAC,GAAG,YAAY,CAAC,CAAC,CACa,CAAC;AAE/D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GACjC,eAAe,cAAc;AAE7B,kBAAkB;AAClB,iJAAyC;AAEzC,iBAAiB;AACjB,2JAAkD,KACjD,MAAM,CAAC,qBAAqB,CAAC,WAAW,CAAC,EAAE,WAAW,CAoBxD,CAAC"}
|
package/dist/src/Number.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertNonEmptyReadonlyArray } from "./Assert.js";
|
|
2
2
|
import { err, ok } from "./Result.js";
|
|
3
|
+
import { PositiveInt } from "./Type.js";
|
|
3
4
|
export const increment = (n) => n + 1;
|
|
4
5
|
export const decrement = (n) => n - 1;
|
|
5
6
|
/** Clamps a number within a given range. */
|
|
@@ -34,12 +35,12 @@ export const max = (...values) => values.reduce((a, b) => (a > b ? a : b));
|
|
|
34
35
|
*/
|
|
35
36
|
export const computeBalancedBuckets = (numberOfItems,
|
|
36
37
|
/** Default: 16 */
|
|
37
|
-
numberOfBuckets = 16,
|
|
38
|
+
numberOfBuckets = PositiveInt.orThrow(16),
|
|
38
39
|
/** Default: 2 */
|
|
39
|
-
minNumberOfItemsPerBucket = 2) => {
|
|
40
|
+
minNumberOfItemsPerBucket = PositiveInt.orThrow(2)) => {
|
|
40
41
|
const minRequiredItems = numberOfBuckets * minNumberOfItemsPerBucket;
|
|
41
42
|
if (numberOfItems < minRequiredItems)
|
|
42
|
-
return err(minRequiredItems);
|
|
43
|
+
return err(PositiveInt.orThrow(minRequiredItems));
|
|
43
44
|
const indexes = [];
|
|
44
45
|
const itemsPerBucket = Math.floor(numberOfItems / numberOfBuckets);
|
|
45
46
|
const extraItems = numberOfItems % numberOfBuckets;
|
|
@@ -48,7 +49,7 @@ minNumberOfItemsPerBucket = 2) => {
|
|
|
48
49
|
const hasExtraItem = i < extraItems;
|
|
49
50
|
const itemsInThisBucket = itemsPerBucket + (hasExtraItem ? 1 : 0);
|
|
50
51
|
bucketBoundary += itemsInThisBucket;
|
|
51
|
-
indexes.push(bucketBoundary);
|
|
52
|
+
indexes.push(PositiveInt.orThrow(bucketBoundary));
|
|
52
53
|
}
|
|
53
54
|
assertNonEmptyReadonlyArray(indexes);
|
|
54
55
|
return ok(indexes);
|
package/dist/src/Object.d.ts
CHANGED
|
@@ -18,11 +18,17 @@ export declare const isPlainObject: (value: unknown) => value is Record<string,
|
|
|
18
18
|
export type ReadonlyRecord<K extends keyof any, V> = Readonly<Record<K, V>>;
|
|
19
19
|
type StringKeyOf<T> = Extract<keyof T, string>;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Like `Object.entries` but preserves branded keys.
|
|
22
|
+
*
|
|
23
|
+
* ### Example
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* type UserId = string & { readonly __brand: "UserId" };
|
|
27
|
+
* const users: Record<UserId, string> = {};
|
|
28
|
+
* const entries = objectToEntries(users); // [UserId, string][]
|
|
29
|
+
* ```
|
|
24
30
|
*/
|
|
25
|
-
export declare const objectToEntries: <T extends Record<string, any>>(record: T) =>
|
|
31
|
+
export declare const objectToEntries: <T extends Record<string, any>>(record: T) => ReadonlyArray<[StringKeyOf<T>, T[StringKeyOf<T>]]>;
|
|
26
32
|
/**
|
|
27
33
|
* Maps a `ReadonlyRecord<K, V>` to a new `ReadonlyRecord<K, U>`, preserving
|
|
28
34
|
* branded key types (e.g., `type Id = 'id' & string`) lost by `Object.entries`.
|
package/dist/src/Object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Object.d.ts","sourceRoot":"","sources":["../../src/Object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,OAAO,KACb,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAC2B,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,cA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C7D,KAAK,CAAC,EACN,MAAM,CAAC,EACP,YAAY,OAAO,KAClB,OAAO,SAAS,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAM/C,CAAC"}
|
package/dist/src/Object.js
CHANGED
|
@@ -12,9 +12,15 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export const isPlainObject = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Like `Object.entries` but preserves branded keys.
|
|
16
|
+
*
|
|
17
|
+
* ### Example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* type UserId = string & { readonly __brand: "UserId" };
|
|
21
|
+
* const users: Record<UserId, string> = {};
|
|
22
|
+
* const entries = objectToEntries(users); // [UserId, string][]
|
|
23
|
+
* ```
|
|
18
24
|
*/
|
|
19
25
|
export const objectToEntries = (record) => Object.entries(record);
|
|
20
26
|
/**
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform detection utilities for Evolu.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Detects if the code is running in React Native environment. */
|
|
7
|
+
export declare const isReactNative: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Detects if Node.js Buffer is available and should be used.
|
|
10
|
+
*
|
|
11
|
+
* React Native apps often polyfill Node.js APIs like Buffer, but we want to use
|
|
12
|
+
* native methods when available for better performance.
|
|
13
|
+
*
|
|
14
|
+
* Returns false in React Native even if Buffer is polyfilled, as we prefer
|
|
15
|
+
* native methods in that environment.
|
|
16
|
+
*
|
|
17
|
+
* @see https://github.com/craftzdog/react-native-quick-base64#installation
|
|
18
|
+
*/
|
|
19
|
+
export declare const hasNodeBuffer: boolean;
|
|
20
|
+
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,eAAO,MAAM,aAAa,SAIoB,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,SACkC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform detection utilities for Evolu.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Detects if the code is running in React Native environment. */
|
|
7
|
+
export const isReactNative = typeof navigator !== "undefined" &&
|
|
8
|
+
"product" in navigator &&
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
10
|
+
navigator.product === "ReactNative";
|
|
11
|
+
/**
|
|
12
|
+
* Detects if Node.js Buffer is available and should be used.
|
|
13
|
+
*
|
|
14
|
+
* React Native apps often polyfill Node.js APIs like Buffer, but we want to use
|
|
15
|
+
* native methods when available for better performance.
|
|
16
|
+
*
|
|
17
|
+
* Returns false in React Native even if Buffer is polyfilled, as we prefer
|
|
18
|
+
* native methods in that environment.
|
|
19
|
+
*
|
|
20
|
+
* @see https://github.com/craftzdog/react-native-quick-base64#installation
|
|
21
|
+
*/
|
|
22
|
+
export const hasNodeBuffer = !isReactNative && typeof globalThis.Buffer !== "undefined";
|
package/dist/src/Random.d.ts
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Random as RandomLib } from "random";
|
|
7
7
|
/**
|
|
8
|
-
* A simple wrapper around Math.random().
|
|
9
|
-
*
|
|
8
|
+
* A simple wrapper around Math.random().
|
|
9
|
+
*
|
|
10
|
+
* For more complex needs check {@link RandomLibDep}.
|
|
10
11
|
*
|
|
11
12
|
* ### Example
|
|
12
13
|
*
|
package/dist/src/Random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Random.d.ts","sourceRoot":"","sources":["../../src/Random.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE7C
|
|
1
|
+
{"version":3,"file":"Random.d.ts","sourceRoot":"","sources":["../../src/Random.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,QAAQ,CAAC;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,MAAM;IACrB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,oDAAoD;AACpD,eAAO,MAAM,YAAY,QAAO,MAE9B,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,MAAM,KAAG,MAKnD,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,4DAA4D;AAC5D,eAAO,MAAM,eAAe,QAAO,SAA4B,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,YAErD,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bidirectional relation between two types.
|
|
3
|
+
*
|
|
4
|
+
* Why useful:
|
|
5
|
+
*
|
|
6
|
+
* - Provides O(1) (amortized) lookup in both directions (A → B and B → A) without
|
|
7
|
+
* maintaining two maps manually and risking them diverging.
|
|
8
|
+
* - Natural fit for symmetric associations such as ownerId ↔ WebSocket, tag ↔
|
|
9
|
+
* item, user ↔ role, entity ↔ subscription where both directions are
|
|
10
|
+
* frequently queried.
|
|
11
|
+
* - Supports fast membership tests via `has`, `hasA`, and `hasB`.
|
|
12
|
+
* - Iteration helpers (`forEach`, iterator) allow treating the structure as a set
|
|
13
|
+
* of pairs when needed.
|
|
14
|
+
*
|
|
15
|
+
* Complexity:
|
|
16
|
+
*
|
|
17
|
+
* - `add` / `remove` / `has*` / `get*` each perform a constant number of Map/Set
|
|
18
|
+
* operations (O(1) expected).
|
|
19
|
+
* - `deleteA` and `deleteB` are O(d) where d is the number of associated elements
|
|
20
|
+
* (the degree). This is optimal because every associated pair must be touched
|
|
21
|
+
* once.
|
|
22
|
+
*
|
|
23
|
+
* Object identity:
|
|
24
|
+
*
|
|
25
|
+
* - Elements are compared by reference (standard Map / Set semantics). Structural
|
|
26
|
+
* hashing of objects in JavaScript is non-trivial, can be expensive, and
|
|
27
|
+
* collision-prone if done naively. Prefer using stable primitive identifiers
|
|
28
|
+
* (ids, strings) instead of attempting to hash full object structures.
|
|
29
|
+
* - If structural equivalence is truly required, wrap objects in an adapter that
|
|
30
|
+
* supplies a canonical hash/id and stores/retrieves the original objects
|
|
31
|
+
* separately. This is a rare need; avoid unless you have clear requirements.
|
|
32
|
+
*/
|
|
33
|
+
export interface Relation<A, B> {
|
|
34
|
+
/**
|
|
35
|
+
* Adds a pair to the relation. Returns true if the pair was newly added,
|
|
36
|
+
* false if it already existed.
|
|
37
|
+
*/
|
|
38
|
+
readonly add: (a: A, b: B) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Removes a specific pair from the relation. Returns true if the pair existed
|
|
41
|
+
* and was removed, false if it was not present.
|
|
42
|
+
*/
|
|
43
|
+
readonly remove: (a: A, b: B) => boolean;
|
|
44
|
+
/** Gets all B elements related to an A element. */
|
|
45
|
+
readonly getB: (a: A) => ReadonlySet<B> | undefined;
|
|
46
|
+
/** Gets all A elements related to a B element. */
|
|
47
|
+
readonly getA: (b: B) => ReadonlySet<A> | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Iterates over each pair in the relation (in insertion order of A elements,
|
|
50
|
+
* then B elements per A).
|
|
51
|
+
*/
|
|
52
|
+
readonly forEach: (callback: (a: A, b: B) => void) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Iterator over all pairs enabling for..of and spread. Yields readonly [a, b]
|
|
55
|
+
* tuples.
|
|
56
|
+
*/
|
|
57
|
+
readonly [Symbol.iterator]: () => IterableIterator<readonly [A, B]>;
|
|
58
|
+
/** Checks if a specific pair exists in the relation. */
|
|
59
|
+
readonly has: (a: A, b: B) => boolean;
|
|
60
|
+
/** Checks if an A element exists in the relation. */
|
|
61
|
+
readonly hasA: (a: A) => boolean;
|
|
62
|
+
/** Checks if a B element exists in the relation. */
|
|
63
|
+
readonly hasB: (b: B) => boolean;
|
|
64
|
+
/** Deletes all pairs containing the given A element. */
|
|
65
|
+
readonly deleteA: (a: A) => boolean;
|
|
66
|
+
/** Deletes all pairs containing the given B element. */
|
|
67
|
+
readonly deleteB: (b: B) => boolean;
|
|
68
|
+
/** Clears all pairs from the relation. */
|
|
69
|
+
readonly clear: () => void;
|
|
70
|
+
/** Number of distinct A elements currently present. */
|
|
71
|
+
readonly aCount: () => number;
|
|
72
|
+
/** Number of distinct B elements currently present. */
|
|
73
|
+
readonly bCount: () => number;
|
|
74
|
+
/** Number of pairs currently stored in the relation. */
|
|
75
|
+
readonly size: () => number;
|
|
76
|
+
}
|
|
77
|
+
/** Creates a {@link Relation}. */
|
|
78
|
+
export declare const createRelation: <A, B>() => Relation<A, B>;
|
|
79
|
+
//# sourceMappingURL=Relation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Relation.d.ts","sourceRoot":"","sources":["../../src/Relation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,EAAE,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;IAEtC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAA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AC,IAAI,EAAE,MAAM,MAAM,CAAC;CAC7B;AAED,kCAAkC;AAClC,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,OAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,CA2IpD,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { assert } from "./Assert.js";
|
|
2
|
+
/** Creates a {@link Relation}. */
|
|
3
|
+
export const createRelation = () => {
|
|
4
|
+
const aToB = new Map();
|
|
5
|
+
const bToA = new Map();
|
|
6
|
+
let sizeInternal = 0;
|
|
7
|
+
const relation = {
|
|
8
|
+
add(a, b) {
|
|
9
|
+
let bSet = aToB.get(a);
|
|
10
|
+
if (bSet?.has(b))
|
|
11
|
+
return false;
|
|
12
|
+
if (!bSet) {
|
|
13
|
+
bSet = new Set();
|
|
14
|
+
aToB.set(a, bSet);
|
|
15
|
+
}
|
|
16
|
+
bSet.add(b);
|
|
17
|
+
let aSet = bToA.get(b);
|
|
18
|
+
if (!aSet) {
|
|
19
|
+
aSet = new Set();
|
|
20
|
+
bToA.set(b, aSet);
|
|
21
|
+
}
|
|
22
|
+
aSet.add(a);
|
|
23
|
+
sizeInternal++;
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
remove(a, b) {
|
|
27
|
+
const bSet = aToB.get(a);
|
|
28
|
+
if (!bSet?.has(b))
|
|
29
|
+
return false;
|
|
30
|
+
bSet.delete(b);
|
|
31
|
+
if (bSet.size === 0) {
|
|
32
|
+
aToB.delete(a);
|
|
33
|
+
}
|
|
34
|
+
const aSet = bToA.get(b);
|
|
35
|
+
assert(aSet, "Relation mapping inconsistency");
|
|
36
|
+
aSet.delete(a);
|
|
37
|
+
if (aSet.size === 0) {
|
|
38
|
+
bToA.delete(b);
|
|
39
|
+
}
|
|
40
|
+
sizeInternal--;
|
|
41
|
+
return true;
|
|
42
|
+
},
|
|
43
|
+
getB(a) {
|
|
44
|
+
return aToB.get(a);
|
|
45
|
+
},
|
|
46
|
+
getA(b) {
|
|
47
|
+
return bToA.get(b);
|
|
48
|
+
},
|
|
49
|
+
forEach(callback) {
|
|
50
|
+
for (const [a, bSet] of aToB) {
|
|
51
|
+
for (const b of bSet)
|
|
52
|
+
callback(a, b);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[Symbol.iterator]() {
|
|
56
|
+
const iterator = function* () {
|
|
57
|
+
for (const [a, bSet] of aToB) {
|
|
58
|
+
for (const b of bSet) {
|
|
59
|
+
yield [a, b];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return iterator();
|
|
64
|
+
},
|
|
65
|
+
has(a, b) {
|
|
66
|
+
const bSet = aToB.get(a);
|
|
67
|
+
return bSet?.has(b) ?? false;
|
|
68
|
+
},
|
|
69
|
+
hasA(a) {
|
|
70
|
+
return aToB.has(a);
|
|
71
|
+
},
|
|
72
|
+
hasB(b) {
|
|
73
|
+
return bToA.has(b);
|
|
74
|
+
},
|
|
75
|
+
deleteA(a) {
|
|
76
|
+
const bSet = aToB.get(a);
|
|
77
|
+
if (!bSet)
|
|
78
|
+
return false;
|
|
79
|
+
const removed = bSet.size;
|
|
80
|
+
for (const b of bSet) {
|
|
81
|
+
const aSet = bToA.get(b);
|
|
82
|
+
if (aSet) {
|
|
83
|
+
aSet.delete(a);
|
|
84
|
+
if (aSet.size === 0) {
|
|
85
|
+
bToA.delete(b);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
aToB.delete(a);
|
|
90
|
+
sizeInternal -= removed;
|
|
91
|
+
return true;
|
|
92
|
+
},
|
|
93
|
+
deleteB(b) {
|
|
94
|
+
const aSet = bToA.get(b);
|
|
95
|
+
if (!aSet)
|
|
96
|
+
return false;
|
|
97
|
+
const removed = aSet.size;
|
|
98
|
+
for (const a of aSet) {
|
|
99
|
+
const bSet = aToB.get(a);
|
|
100
|
+
if (bSet) {
|
|
101
|
+
bSet.delete(b);
|
|
102
|
+
if (bSet.size === 0) {
|
|
103
|
+
aToB.delete(a);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
bToA.delete(b);
|
|
108
|
+
sizeInternal -= removed;
|
|
109
|
+
return true;
|
|
110
|
+
},
|
|
111
|
+
clear() {
|
|
112
|
+
aToB.clear();
|
|
113
|
+
bToA.clear();
|
|
114
|
+
sizeInternal = 0;
|
|
115
|
+
},
|
|
116
|
+
aCount() {
|
|
117
|
+
return aToB.size;
|
|
118
|
+
},
|
|
119
|
+
bCount() {
|
|
120
|
+
return bToA.size;
|
|
121
|
+
},
|
|
122
|
+
size() {
|
|
123
|
+
return sizeInternal;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
return relation;
|
|
127
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Result } from "./Result.js";
|
|
2
|
+
/**
|
|
3
|
+
* A generic resource manager that handles reference counting and delayed
|
|
4
|
+
* disposal of shared resources. Useful for managing expensive resources like
|
|
5
|
+
* WebSocket connections that need to be shared among multiple consumers.
|
|
6
|
+
*/
|
|
7
|
+
export interface Resources<TResource extends Disposable, TResourceKey extends string, TResourceConfig, TConsumer, TConsumerId extends string> extends Disposable {
|
|
8
|
+
/**
|
|
9
|
+
* Adds a consumer to resources, creating them if necessary. Increments
|
|
10
|
+
* reference counts for existing consumer-resource pairs.
|
|
11
|
+
*/
|
|
12
|
+
readonly addConsumer: (consumer: TConsumer, resourceConfigs: ReadonlyArray<TResourceConfig>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Removes a consumer from resources. Decrements reference counts and
|
|
15
|
+
* schedules disposal when no consumers remain.
|
|
16
|
+
*
|
|
17
|
+
* Returns an error if the resource doesn't exist or if the consumer wasn't
|
|
18
|
+
* added to the resource.
|
|
19
|
+
*/
|
|
20
|
+
readonly removeConsumer: (consumer: TConsumer, resourceConfigs: ReadonlyArray<TResourceConfig>) => Result<void, ResourceNotFoundError<TResourceKey> | ConsumerNotFoundError<TConsumerId, TResourceKey>>;
|
|
21
|
+
/** Gets the resource for the specified key, or null if it doesn't exist. */
|
|
22
|
+
readonly getResource: (key: TResourceKey) => TResource | null;
|
|
23
|
+
/** Gets all consumer IDs currently using the specified resource key. */
|
|
24
|
+
readonly getConsumersForResource: (key: TResourceKey) => ReadonlyArray<TConsumerId>;
|
|
25
|
+
/** Checks if a consumer is currently using any resources. */
|
|
26
|
+
readonly hasConsumerAnyResource: (consumer: TConsumer) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the consumer for the specified consumer ID, or null if not found or
|
|
29
|
+
* not using any resources.
|
|
30
|
+
*/
|
|
31
|
+
readonly getConsumer: (consumerId: TConsumerId) => TConsumer | null;
|
|
32
|
+
}
|
|
33
|
+
/** Error when trying to remove a consumer from a resource that doesn't exist. */
|
|
34
|
+
export interface ResourceNotFoundError<TResourceKey extends string = string> {
|
|
35
|
+
readonly type: "ResourceNotFoundError";
|
|
36
|
+
readonly resourceKey: TResourceKey;
|
|
37
|
+
}
|
|
38
|
+
/** Error when trying to remove a consumer that wasn't added to a resource. */
|
|
39
|
+
export interface ConsumerNotFoundError<TConsumerId extends string = string, TResourceKey extends string = string> {
|
|
40
|
+
readonly type: "ConsumerNotFoundError";
|
|
41
|
+
readonly consumerId: TConsumerId;
|
|
42
|
+
readonly resourceKey: TResourceKey;
|
|
43
|
+
}
|
|
44
|
+
export interface ResourcesConfig<TResource extends Disposable, TResourceKey extends string, TResourceConfig, TConsumer, TConsumerId extends string> {
|
|
45
|
+
/** Creates a new resource for the given config. */
|
|
46
|
+
readonly createResource: (config: TResourceConfig) => TResource;
|
|
47
|
+
/** Extracts a unique key from a resource config for deduplication. */
|
|
48
|
+
readonly getResourceKey: (config: TResourceConfig) => TResourceKey;
|
|
49
|
+
/** Extracts a unique identifier from a consumer for reference counting. */
|
|
50
|
+
readonly getConsumerId: (consumer: TConsumer) => TConsumerId;
|
|
51
|
+
/**
|
|
52
|
+
* Delay in milliseconds before disposing unused resources. Helps avoid
|
|
53
|
+
* resource churn during rapid add/remove cycles. Defaults to 100ms.
|
|
54
|
+
*/
|
|
55
|
+
readonly disposalDelay?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Called when a consumer is added to a resource for the first time. This
|
|
58
|
+
* happens when the consumer's reference count goes from 0 to 1 for this
|
|
59
|
+
* resource.
|
|
60
|
+
*/
|
|
61
|
+
readonly onConsumerAdded?: (consumer: TConsumer, resource: TResource, resourceKey: TResourceKey) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Called when a consumer is completely removed from a resource. This happens
|
|
64
|
+
* when the consumer's reference count goes from 1 to 0 for this resource.
|
|
65
|
+
*/
|
|
66
|
+
readonly onConsumerRemoved?: (consumer: TConsumer, resource: TResource, resourceKey: TResourceKey) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates {@link Resources}.
|
|
70
|
+
*
|
|
71
|
+
* This tracks which consumers are using which resources and maintains reference
|
|
72
|
+
* counts to know when it's safe to dispose resources. Resources are created
|
|
73
|
+
* on-demand and disposed with a configurable delay to avoid churn.
|
|
74
|
+
*
|
|
75
|
+
* ### Example Usage
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* // WebSocket connections
|
|
79
|
+
* interface WebSocketConfig {
|
|
80
|
+
* readonly url: WebSocketUrl;
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* type WebSocketUrl = string & Brand<"WebSocketUrl">;
|
|
84
|
+
* type UserId = string & Brand<"UserId">;
|
|
85
|
+
*
|
|
86
|
+
* const webSockets = createResources<
|
|
87
|
+
* WebSocket,
|
|
88
|
+
* WebSocketUrl,
|
|
89
|
+
* WebSocketConfig,
|
|
90
|
+
* User,
|
|
91
|
+
* UserId
|
|
92
|
+
* >({
|
|
93
|
+
* createResource: (config) => new WebSocket(config.url),
|
|
94
|
+
* getResourceKey: (config) => config.url,
|
|
95
|
+
* getConsumerId: (user) => user.id,
|
|
96
|
+
* disposalDelay: 1000,
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Add users to WebSocket connections
|
|
100
|
+
* webSockets.addConsumer(user1, [
|
|
101
|
+
* { url: "ws://server1.com" as WebSocketUrl },
|
|
102
|
+
* { url: "ws://server2.com" as WebSocketUrl },
|
|
103
|
+
* ]);
|
|
104
|
+
* webSockets.addConsumer(user2, [
|
|
105
|
+
* { url: "ws://server1.com" as WebSocketUrl },
|
|
106
|
+
* ]);
|
|
107
|
+
*
|
|
108
|
+
* // Remove users - server1 stays alive (user2 still using it)
|
|
109
|
+
* webSockets.removeConsumer(user1, [
|
|
110
|
+
* { url: "ws://server1.com" as WebSocketUrl },
|
|
111
|
+
* { url: "ws://server2.com" as WebSocketUrl },
|
|
112
|
+
* ]);
|
|
113
|
+
*
|
|
114
|
+
* // server2 gets disposed after delay, server1 stays alive
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare const createResources: <TResource extends Disposable, TResourceKey extends string, TResourceConfig, TConsumer, TConsumerId extends string>(config: ResourcesConfig<TResource, TResourceKey, TResourceConfig, TConsumer, TConsumerId>) => Resources<TResource, TResourceKey, TResourceConfig, TConsumer, TConsumerId>;
|
|
118
|
+
//# sourceMappingURL=Resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Resources.d.ts","sourceRoot":"","sources":["../../src/Resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,MAAM,aAAa,CAAC;AAG9C;;;;GAIG;AACH,MAAM,WAAW,SAAS,CACxB,SAAS,SAAS,UAAU,EAC5B,YAAY,SAAS,MAAM,EAC3B,eAAe,EACf,SAAS,EACT,WAAW,SAAS,MAAM,CAC1B,SAAQ,UAAU;IAClB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,CACpB,QAAQ,EAAE,SAAS,EACnB,eAAe,EAAE,aAAa,CAAC,eAAe,CAAC,KAC5C,IAAI,CAAC;IAEV;;;;;;OAMG;IACH,QAAQ,CAA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