@evolu/common 8.0.0-next.4 → 8.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/dist/src/Array.d.ts +279 -173
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +105 -101
- package/dist/src/Assert.d.ts +44 -44
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +44 -32
- package/dist/src/BigInt.d.ts +6 -3
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -2
- package/dist/src/Brand.d.ts +27 -40
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Buffer.d.ts +27 -11
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Cache.d.ts +9 -4
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +8 -3
- package/dist/src/Callbacks.d.ts +30 -19
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Console.d.ts +145 -66
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +91 -43
- package/dist/src/Crypto.d.ts +85 -42
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +44 -20
- package/dist/src/Eq.d.ts +87 -21
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +67 -19
- package/dist/src/Error.d.ts +5 -3
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +16 -0
- package/dist/src/Function.d.ts +119 -58
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +86 -43
- package/dist/src/Http.d.ts +394 -0
- package/dist/src/Http.d.ts.map +1 -0
- package/dist/src/Http.js +102 -0
- package/dist/src/Identicon.d.ts +16 -7
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +14 -5
- package/dist/src/LeakDetector.d.ts +88 -0
- package/dist/src/LeakDetector.d.ts.map +1 -0
- package/dist/src/LeakDetector.js +86 -0
- package/dist/src/LockManager.d.ts +18 -9
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/LockManager.js +7 -8
- package/dist/src/Lookup.d.ts +43 -13
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +28 -8
- package/dist/src/Microtask.d.ts +1 -1
- package/dist/src/Microtask.d.ts.map +1 -1
- package/dist/src/Microtask.js +3 -7
- package/dist/src/Number.d.ts +49 -13
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +34 -5
- package/dist/src/Object.d.ts +160 -40
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +92 -46
- package/dist/src/Option.d.ts +10 -7
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +9 -6
- package/dist/src/Order.d.ts +21 -21
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +18 -21
- package/dist/src/Platform.d.ts +31 -0
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +98 -0
- package/dist/src/Random.d.ts +32 -17
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +12 -8
- package/dist/src/Redacted.d.ts +43 -29
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +14 -3
- package/dist/src/Ref.d.ts +11 -3
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +2 -2
- package/dist/src/RefCount.d.ts +2 -6
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/RefCount.js +33 -90
- package/dist/src/Relation.d.ts +70 -5
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +77 -2
- package/dist/src/Resource.d.ts +590 -155
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +592 -343
- package/dist/src/Result.d.ts +838 -191
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +163 -102
- package/dist/src/Schedule.d.ts +684 -231
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +766 -295
- package/dist/src/Set.d.ts +89 -40
- package/dist/src/Set.d.ts.map +1 -1
- package/dist/src/Set.js +50 -29
- package/dist/src/Sqlite.d.ts +29 -72
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +41 -46
- package/dist/src/StackTrace.d.ts +40 -0
- package/dist/src/StackTrace.d.ts.map +1 -0
- package/dist/src/StackTrace.js +140 -0
- package/dist/src/Store.d.ts +5 -4
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +5 -4
- package/dist/src/String.d.ts +7 -1
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +20 -7
- package/dist/src/Task.d.ts +3572 -1770
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1879 -1274
- package/dist/src/Test.d.ts +17 -125
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +17 -68
- package/dist/src/Time.d.ts +108 -49
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +172 -73
- package/dist/src/Type.d.ts +3542 -1926
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +3070 -1784
- package/dist/src/Types.d.ts +200 -108
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +39 -8
- package/dist/src/WebSocket.d.ts +48 -23
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +15 -6
- package/dist/src/Worker.d.ts +94 -36
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +58 -24
- package/dist/src/index.d.ts +55 -52
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/intl/cs.d.ts +94 -0
- package/dist/src/intl/cs.d.ts.map +1 -0
- package/dist/src/intl/cs.js +220 -0
- package/dist/src/intl/index.d.ts +7 -0
- package/dist/src/intl/index.d.ts.map +1 -0
- package/dist/src/intl/index.js +6 -0
- package/dist/src/local-first/Db.d.ts +12 -8
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +109 -132
- package/dist/src/local-first/Error.d.ts +4 -4
- package/dist/src/local-first/Evolu.d.ts +338 -92
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +47 -55
- package/dist/src/local-first/LocalAuth.d.ts +4 -4
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +61 -24
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +45 -8
- package/dist/src/local-first/Protocol.d.ts +44 -31
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +36 -13
- package/dist/src/local-first/Query.d.ts +147 -62
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +112 -58
- package/dist/src/local-first/Relay.d.ts +44 -14
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Schema.d.ts +92 -41
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +25 -8
- package/dist/src/local-first/Shared.d.ts +23 -21
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +100 -57
- package/dist/src/local-first/Storage.d.ts +53 -32
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +194 -234
- package/dist/src/local-first/Timestamp.d.ts +21 -21
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +2 -2
- package/dist/src/local-first/index.d.ts +11 -11
- package/package.json +14 -13
- package/src/Array.ts +306 -205
- package/src/Assert.ts +54 -69
- package/src/BigInt.ts +6 -3
- package/src/Brand.ts +27 -40
- package/src/Buffer.ts +28 -12
- package/src/Cache.ts +9 -4
- package/src/Callbacks.ts +30 -19
- package/src/Console.ts +156 -84
- package/src/Crypto.ts +83 -41
- package/src/Eq.ts +95 -22
- package/src/Error.ts +8 -4
- package/src/Function.ts +167 -59
- package/src/Http.ts +549 -0
- package/src/Identicon.ts +16 -7
- package/src/LeakDetector.ts +182 -0
- package/src/LockManager.ts +43 -39
- package/src/Lookup.ts +62 -28
- package/src/Microtask.ts +19 -23
- package/src/Number.ts +64 -12
- package/src/Object.ts +173 -49
- package/src/Option.ts +10 -7
- package/src/Order.ts +23 -21
- package/src/Platform.ts +136 -0
- package/src/Polyfills.ts +6 -12
- package/src/Random.ts +32 -19
- package/src/Redacted.ts +44 -30
- package/src/Ref.ts +14 -6
- package/src/RefCount.ts +38 -80
- package/src/Relation.ts +202 -10
- package/src/Resource.ts +1199 -591
- package/src/Result.ts +930 -271
- package/src/Schedule.ts +859 -343
- package/src/Set.ts +89 -40
- package/src/Sqlite.ts +144 -138
- package/src/StackTrace.ts +230 -0
- package/src/Store.ts +8 -7
- package/src/String.ts +22 -5
- package/src/Task.ts +5101 -2832
- package/src/Test.ts +20 -168
- package/src/Time.ts +293 -90
- package/src/Type.ts +10034 -4117
- package/src/Types.ts +227 -110
- package/src/WebSocket.ts +64 -36
- package/src/Worker.ts +180 -72
- package/src/index.ts +55 -52
- package/src/intl/cs.ts +388 -0
- package/src/intl/index.ts +7 -0
- package/src/local-first/Db.ts +152 -179
- package/src/local-first/Error.ts +4 -4
- package/src/local-first/Evolu.ts +495 -250
- package/src/local-first/LocalAuth.ts +6 -12
- package/src/local-first/Owner.ts +58 -21
- package/src/local-first/Protocol.ts +49 -31
- package/src/local-first/Query.ts +146 -61
- package/src/local-first/Relay.ts +51 -21
- package/src/local-first/Schema.ts +109 -51
- package/src/local-first/Shared.ts +266 -226
- package/src/local-first/Storage.ts +266 -264
- package/src/local-first/Timestamp.ts +25 -18
- package/src/local-first/index.ts +11 -11
- package/dist/src/Skiplist.d.ts +0 -28
- package/dist/src/Skiplist.d.ts.map +0 -1
- package/dist/src/Skiplist.js +0 -64
- package/dist/src/Tracer.d.ts +0 -48
- package/dist/src/Tracer.d.ts.map +0 -1
- package/dist/src/Tracer.js +0 -6
- package/src/Skiplist.ts +0 -108
- package/src/Tracer.ts +0 -54
package/dist/src/Order.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../src/Order.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"Order.d.ts","sourceRoot":"","sources":["../../src/Order.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC;AAEnD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW,GACrB,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,KAAG,KAAK,CAAC,CAAC,CAER,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,GACtB,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAEhB,CAAC;AAEhB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,MAAM,CAErC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,eAAqD,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,eAAqD,CAAC;AAE9E,uCAAuC;AACvC,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,UAAU,CAU7C,CAAC"}
|
package/dist/src/Order.js
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
* ### Example
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
|
+
* import { createOrder } from "@evolu/common";
|
|
13
|
+
*
|
|
12
14
|
* const orderNumber = createOrder<number>((x, y) => x < y);
|
|
13
|
-
* expect(orderNumber(1, 2)).
|
|
14
|
-
* expect(orderNumber(2, 1)).
|
|
15
|
-
* expect(orderNumber(1, 1)).
|
|
15
|
+
* expect(orderNumber(1, 2)).toBe(-1);
|
|
16
|
+
* expect(orderNumber(2, 1)).toBe(1);
|
|
17
|
+
* expect(orderNumber(1, 1)).toBe(0);
|
|
16
18
|
* ```
|
|
17
19
|
*/
|
|
18
20
|
export const createOrder = (isLessThan) => (x, y) => x === y ? 0 : isLessThan(x, y) ? -1 : 1;
|
|
@@ -22,9 +24,10 @@ export const createOrder = (isLessThan) => (x, y) => x === y ? 0 : isLessThan(x,
|
|
|
22
24
|
* ### Example
|
|
23
25
|
*
|
|
24
26
|
* ```ts
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* reverseOrder(orderNumber)
|
|
27
|
+
* import { orderNumber, reverseOrder } from "@evolu/common";
|
|
28
|
+
*
|
|
29
|
+
* const descendingOrderNumber = reverseOrder(orderNumber);
|
|
30
|
+
* expect([3, 1, 2].toSorted(descendingOrderNumber)).toEqual([3, 2, 1]);
|
|
28
31
|
* ```
|
|
29
32
|
*/
|
|
30
33
|
export const reverseOrder = (order) => (a, b) => order(b, a);
|
|
@@ -34,10 +37,9 @@ export const reverseOrder = (order) => (a, b) => order(b, a);
|
|
|
34
37
|
* ### Example
|
|
35
38
|
*
|
|
36
39
|
* ```ts
|
|
37
|
-
* orderString
|
|
38
|
-
*
|
|
39
|
-
* orderString("a", "
|
|
40
|
-
* ["c", "b", "a"].toSorted(orderString); // ["a", "b", "c"]
|
|
40
|
+
* import { orderString } from "@evolu/common";
|
|
41
|
+
*
|
|
42
|
+
* expect(["c", "b", "a"].toSorted(orderString)).toEqual(["a", "b", "c"]);
|
|
41
43
|
* ```
|
|
42
44
|
*/
|
|
43
45
|
export const orderString = /*#__PURE__*/ createOrder((a, b) => a < b);
|
|
@@ -47,13 +49,9 @@ export const orderString = /*#__PURE__*/ createOrder((a, b) => a < b);
|
|
|
47
49
|
* ### Example
|
|
48
50
|
*
|
|
49
51
|
* ```ts
|
|
50
|
-
* orderNumber
|
|
51
|
-
*
|
|
52
|
-
* orderNumber(1,
|
|
53
|
-
* [2, 1, 3].toSorted(orderNumber); // [1, 2, 3]
|
|
54
|
-
* reverseOrder(orderNumber)(1, 2); // 1
|
|
55
|
-
* reverseOrder(orderNumber)(2, 1); // -1
|
|
56
|
-
* reverseOrder(orderNumber)(1, 1); // 0
|
|
52
|
+
* import { orderNumber } from "@evolu/common";
|
|
53
|
+
*
|
|
54
|
+
* expect([2, 1, 3].toSorted(orderNumber)).toEqual([1, 2, 3]);
|
|
57
55
|
* ```
|
|
58
56
|
*/
|
|
59
57
|
export const orderNumber = /*#__PURE__*/ createOrder((a, b) => a < b);
|
|
@@ -63,10 +61,9 @@ export const orderNumber = /*#__PURE__*/ createOrder((a, b) => a < b);
|
|
|
63
61
|
* ### Example
|
|
64
62
|
*
|
|
65
63
|
* ```ts
|
|
66
|
-
* orderBigInt
|
|
67
|
-
*
|
|
68
|
-
* orderBigInt(1n,
|
|
69
|
-
* [2n, 1n, 3n].toSorted(orderBigInt); // [1n, 2n, 3n]
|
|
64
|
+
* import { orderBigInt } from "@evolu/common";
|
|
65
|
+
*
|
|
66
|
+
* expect([2n, 1n, 3n].toSorted(orderBigInt)).toEqual([1n, 2n, 3n]);
|
|
70
67
|
* ```
|
|
71
68
|
*/
|
|
72
69
|
export const orderBigInt = /*#__PURE__*/ createOrder((a, b) => a < b);
|
package/dist/src/Platform.d.ts
CHANGED
|
@@ -7,6 +7,18 @@
|
|
|
7
7
|
export declare const isHermes: boolean;
|
|
8
8
|
/** Returns true if running in a server environment (no DOM). */
|
|
9
9
|
export declare const isServer: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* True outside production builds.
|
|
12
|
+
*
|
|
13
|
+
* Bundlers (webpack, Vite, esbuild, Metro) replace the text
|
|
14
|
+
* `process.env.NODE_ENV` statically at build time, so in production bundles
|
|
15
|
+
* this expression folds to `false` and code behind it is dead-code-eliminated —
|
|
16
|
+
* the same mechanism React uses. The `typeof` guard makes the runtime read safe
|
|
17
|
+
* where no bundler ran, such as un-bundled browser ESM, where it fails closed
|
|
18
|
+
* to production behavior. Node.js reads it natively; React Native polyfills it.
|
|
19
|
+
* A missing `NODE_ENV` counts as development, matching React semantics.
|
|
20
|
+
*/
|
|
21
|
+
export declare const isDev: boolean;
|
|
10
22
|
/**
|
|
11
23
|
* Detects if Node.js Buffer is available and should be used.
|
|
12
24
|
*
|
|
@@ -46,4 +58,23 @@ export type ReloadApp = (url?: string) => void;
|
|
|
46
58
|
export interface ReloadAppDep {
|
|
47
59
|
readonly reloadApp: ReloadApp;
|
|
48
60
|
}
|
|
61
|
+
export interface TestGlobalErrors extends Disposable {
|
|
62
|
+
readonly errors: ReadonlyArray<unknown>;
|
|
63
|
+
readonly next: () => Promise<unknown>;
|
|
64
|
+
/**
|
|
65
|
+
* Waits until every error already reported to the platform has been delivered
|
|
66
|
+
* to this recorder, then returns {@link TestGlobalErrors.errors}.
|
|
67
|
+
*
|
|
68
|
+
* Platforms deliver global errors asynchronously and provide no hook for
|
|
69
|
+
* "nothing was reported", so settle emits a sentinel of the same kind and
|
|
70
|
+
* resolves when it arrives. Platform delivery is ordered, so all earlier
|
|
71
|
+
* errors are recorded by then. Use it to assert absence: `expect(await
|
|
72
|
+
* unhandledRejections.settle()).toEqual([])`.
|
|
73
|
+
*/
|
|
74
|
+
readonly settle: () => Promise<ReadonlyArray<unknown>>;
|
|
75
|
+
}
|
|
76
|
+
/** Records platform global uncaught-error reporting until disposed. */
|
|
77
|
+
export declare const testGlobalUncaughtErrors: () => TestGlobalErrors;
|
|
78
|
+
/** Records platform global unhandled-rejection reporting until disposed. */
|
|
79
|
+
export declare const testGlobalUnhandledRejections: () => TestGlobalErrors;
|
|
49
80
|
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,eAAO,MAAM,QAAQ,SAAiC,CAAC;AAEvD,gEAAgE;AAChE,eAAO,MAAM,QAAQ,SAAkC,CAAC;AAExD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,SAC6B,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B"}
|
|
1
|
+
{"version":3,"file":"Platform.d.ts","sourceRoot":"","sources":["../../src/Platform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,kEAAkE;AAClE,eAAO,MAAM,QAAQ,SAAiC,CAAC;AAEvD,gEAAgE;AAChE,eAAO,MAAM,QAAQ,SAAkC,CAAC;AAExD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,SAGyB,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,SAC6B,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAE/C,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtC;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;CACxD;AAED,uEAAuE;AACvE,eAAO,MAAM,wBAAwB,QAAO,gBACF,CAAC;AAE3C,4EAA4E;AAC5E,eAAO,MAAM,6BAA6B,QAAO,gBACH,CAAC"}
|
package/dist/src/Platform.js
CHANGED
|
@@ -7,6 +7,20 @@
|
|
|
7
7
|
export const isHermes = "HermesInternal" in globalThis;
|
|
8
8
|
/** Returns true if running in a server environment (no DOM). */
|
|
9
9
|
export const isServer = typeof document === "undefined";
|
|
10
|
+
/**
|
|
11
|
+
* True outside production builds.
|
|
12
|
+
*
|
|
13
|
+
* Bundlers (webpack, Vite, esbuild, Metro) replace the text
|
|
14
|
+
* `process.env.NODE_ENV` statically at build time, so in production bundles
|
|
15
|
+
* this expression folds to `false` and code behind it is dead-code-eliminated —
|
|
16
|
+
* the same mechanism React uses. The `typeof` guard makes the runtime read safe
|
|
17
|
+
* where no bundler ran, such as un-bundled browser ESM, where it fails closed
|
|
18
|
+
* to production behavior. Node.js reads it natively; React Native polyfills it.
|
|
19
|
+
* A missing `NODE_ENV` counts as development, matching React semantics.
|
|
20
|
+
*/
|
|
21
|
+
export const isDev = typeof process === "undefined"
|
|
22
|
+
? false
|
|
23
|
+
: process.env.NODE_ENV !== "production";
|
|
10
24
|
/**
|
|
11
25
|
* Detects if Node.js Buffer is available and should be used.
|
|
12
26
|
*
|
|
@@ -19,3 +33,87 @@ export const isServer = typeof document === "undefined";
|
|
|
19
33
|
* @see https://github.com/craftzdog/react-native-quick-base64#installation
|
|
20
34
|
*/
|
|
21
35
|
export const hasNodeBuffer = !isHermes && typeof globalThis.Buffer !== "undefined";
|
|
36
|
+
/** Records platform global uncaught-error reporting until disposed. */
|
|
37
|
+
export const testGlobalUncaughtErrors = () => createTestGlobalErrors("uncaughtErrors");
|
|
38
|
+
/** Records platform global unhandled-rejection reporting until disposed. */
|
|
39
|
+
export const testGlobalUnhandledRejections = () => createTestGlobalErrors("unhandledRejection");
|
|
40
|
+
const settleSentinel = new Error("TestGlobalErrors.settle sentinel");
|
|
41
|
+
const createTestGlobalErrors = (kind) => {
|
|
42
|
+
const nodeEvent = kind === "uncaughtErrors" ? "uncaughtException" : "unhandledRejection";
|
|
43
|
+
const webEvent = kind === "uncaughtErrors" ? "error" : "unhandledrejection";
|
|
44
|
+
const webErrorKey = kind === "uncaughtErrors" ? "error" : "reason";
|
|
45
|
+
const errorType = kind === "uncaughtErrors" ? "uncaught-error" : "unhandled-rejection";
|
|
46
|
+
const disposableStack = new DisposableStack();
|
|
47
|
+
const errors = [];
|
|
48
|
+
const nextWaiters = [];
|
|
49
|
+
const settleWaiters = [];
|
|
50
|
+
let nextIndex = 0;
|
|
51
|
+
const next = () => {
|
|
52
|
+
if (nextIndex < errors.length) {
|
|
53
|
+
const error = errors[nextIndex];
|
|
54
|
+
nextIndex += 1;
|
|
55
|
+
return Promise.resolve(error);
|
|
56
|
+
}
|
|
57
|
+
const next = Promise.withResolvers();
|
|
58
|
+
nextWaiters.push(next.resolve);
|
|
59
|
+
return next.promise;
|
|
60
|
+
};
|
|
61
|
+
const record = (error) => {
|
|
62
|
+
if (error === settleSentinel) {
|
|
63
|
+
settleWaiters.shift()?.();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
errors.push(error);
|
|
67
|
+
const resolveNext = nextWaiters.shift();
|
|
68
|
+
if (!resolveNext)
|
|
69
|
+
return;
|
|
70
|
+
nextIndex += 1;
|
|
71
|
+
resolveNext(error);
|
|
72
|
+
};
|
|
73
|
+
const settle = () => {
|
|
74
|
+
const settled = Promise.withResolvers();
|
|
75
|
+
settleWaiters.push(() => {
|
|
76
|
+
settled.resolve(errors);
|
|
77
|
+
});
|
|
78
|
+
if (kind === "unhandledRejection") {
|
|
79
|
+
void Promise.reject(settleSentinel);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
queueMicrotask(() => {
|
|
83
|
+
throw settleSentinel;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return settled.promise;
|
|
87
|
+
};
|
|
88
|
+
if (typeof process === "object" &&
|
|
89
|
+
typeof process.on === "function" &&
|
|
90
|
+
typeof process.off === "function") {
|
|
91
|
+
process.on(nodeEvent, record);
|
|
92
|
+
disposableStack.defer(() => {
|
|
93
|
+
process.off(nodeEvent, record);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
else if (typeof globalThis.addEventListener === "function") {
|
|
97
|
+
const listener = (event) => {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
record(event[webErrorKey]);
|
|
100
|
+
};
|
|
101
|
+
globalThis.addEventListener(webEvent, listener);
|
|
102
|
+
disposableStack.defer(() => {
|
|
103
|
+
globalThis.removeEventListener(webEvent, listener);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw new Error(`Unsupported platform global ${errorType} reporting.`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
errors,
|
|
111
|
+
next,
|
|
112
|
+
settle,
|
|
113
|
+
[Symbol.dispose]: () => {
|
|
114
|
+
nextWaiters.length = 0;
|
|
115
|
+
settleWaiters.length = 0;
|
|
116
|
+
disposableStack.dispose();
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
};
|
package/dist/src/Random.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Random number generation.
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { Random as RandomLib } from "random";
|
|
7
|
-
import type { Brand } from "./Brand.
|
|
7
|
+
import type { Brand } from "./Brand.ts";
|
|
8
8
|
/**
|
|
9
9
|
* A random floating point number in [0, 1).
|
|
10
10
|
*
|
|
@@ -19,41 +19,56 @@ export type RandomNumber = number & Brand<"RandomNumber">;
|
|
|
19
19
|
* ### Example
|
|
20
20
|
*
|
|
21
21
|
* ```ts
|
|
22
|
-
*
|
|
22
|
+
* import {
|
|
23
|
+
* createRandom,
|
|
24
|
+
* testCreateRandom,
|
|
25
|
+
* type RandomNumber,
|
|
26
|
+
* } from "@evolu/common";
|
|
27
|
+
*
|
|
28
|
+
* // For apps, use the Math.random-backed implementation.
|
|
23
29
|
* const random = createRandom();
|
|
24
|
-
* random.next();
|
|
30
|
+
* const value = random.next();
|
|
31
|
+
* expectTypeOf(value).toEqualTypeOf<RandomNumber>();
|
|
32
|
+
* expect(value).toBeGreaterThanOrEqual(0);
|
|
33
|
+
* expect(value).toBeLessThan(1);
|
|
25
34
|
*
|
|
26
|
-
* // For tests
|
|
27
|
-
* const
|
|
28
|
-
*
|
|
35
|
+
* // For tests, use a seed.
|
|
36
|
+
* const firstTestRandom = testCreateRandom("test");
|
|
37
|
+
* const secondTestRandom = testCreateRandom("test");
|
|
38
|
+
* expect(firstTestRandom.next()).toBe(secondTestRandom.next());
|
|
29
39
|
* ```
|
|
30
40
|
*/
|
|
31
41
|
export interface Random {
|
|
32
42
|
/** Returns a floating point number in [0, 1). Just like Math.random(). */
|
|
33
|
-
next: () => RandomNumber;
|
|
43
|
+
readonly next: () => RandomNumber;
|
|
34
44
|
}
|
|
35
45
|
export interface RandomDep {
|
|
36
|
-
random: Random;
|
|
46
|
+
readonly random: Random;
|
|
37
47
|
}
|
|
38
48
|
/** Creates a {@link Random} using Math.random(). */
|
|
39
49
|
export declare const createRandom: () => Random;
|
|
40
|
-
/** Creates a seeded {@link Random} for deterministic tests. Default seed "evolu". */
|
|
41
|
-
export declare const testCreateRandom: (seed?: string) => Random;
|
|
42
50
|
/**
|
|
43
|
-
* Creates
|
|
44
|
-
*
|
|
51
|
+
* Creates a seeded {@link Random} for deterministic tests.
|
|
52
|
+
*
|
|
53
|
+
* Default seed "evolu".
|
|
45
54
|
*/
|
|
46
|
-
export declare const
|
|
55
|
+
export declare const testCreateRandom: (seed?: string) => Random;
|
|
47
56
|
/**
|
|
48
|
-
*
|
|
57
|
+
* Seedable random number generator supporting many common distributions,
|
|
58
|
+
* provided by the NPM `random` package.
|
|
49
59
|
*
|
|
50
60
|
* https://github.com/transitive-bullshit/random
|
|
51
61
|
*/
|
|
52
62
|
export interface RandomLibDep {
|
|
53
63
|
readonly randomLib: RandomLib;
|
|
54
64
|
}
|
|
55
|
-
/** Creates a
|
|
65
|
+
/** Creates a random number generator from the NPM `random` package. */
|
|
56
66
|
export declare const createRandomLib: () => RandomLib;
|
|
57
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Creates a seeded random number generator from the NPM `random` package for
|
|
69
|
+
* deterministic tests.
|
|
70
|
+
*
|
|
71
|
+
* Default seed "evolu".
|
|
72
|
+
*/
|
|
58
73
|
export declare const testCreateRandomLib: (seed?: string) => RandomLib;
|
|
59
74
|
//# sourceMappingURL=Random.d.ts.map
|
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;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;AAE1D
|
|
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;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,MAAM;IACrB,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,YAAY,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,oDAAoD;AACpD,eAAO,MAAM,YAAY,QAAO,MAE9B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,qBAAqB,MAKjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED,uEAAuE;AACvE,eAAO,MAAM,eAAe,QAAO,SAA4B,CAAC;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,qBAAqB,SAChC,CAAC"}
|
package/dist/src/Random.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Random number generation.
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
@@ -8,19 +8,23 @@ import { Random as RandomLib } from "random";
|
|
|
8
8
|
export const createRandom = () => ({
|
|
9
9
|
next: () => Math.random(),
|
|
10
10
|
});
|
|
11
|
-
/** Creates a seeded {@link Random} for deterministic tests. Default seed "evolu". */
|
|
12
|
-
export const testCreateRandom = (seed = "evolu") => createRandomWithSeed(seed);
|
|
13
11
|
/**
|
|
14
|
-
* Creates
|
|
15
|
-
*
|
|
12
|
+
* Creates a seeded {@link Random} for deterministic tests.
|
|
13
|
+
*
|
|
14
|
+
* Default seed "evolu".
|
|
16
15
|
*/
|
|
17
|
-
export const
|
|
16
|
+
export const testCreateRandom = (seed = "evolu") => {
|
|
18
17
|
const random = new RandomLib(seed);
|
|
19
18
|
return {
|
|
20
19
|
next: () => random.next(),
|
|
21
20
|
};
|
|
22
21
|
};
|
|
23
|
-
/** Creates a
|
|
22
|
+
/** Creates a random number generator from the NPM `random` package. */
|
|
24
23
|
export const createRandomLib = () => new RandomLib();
|
|
25
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Creates a seeded random number generator from the NPM `random` package for
|
|
26
|
+
* deterministic tests.
|
|
27
|
+
*
|
|
28
|
+
* Default seed "evolu".
|
|
29
|
+
*/
|
|
26
30
|
export const testCreateRandomLib = (seed = "evolu") => new RandomLib(seed);
|
package/dist/src/Redacted.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { Brand } from "./Brand.
|
|
7
|
-
import type { Eq } from "./Eq.
|
|
6
|
+
import type { Brand } from "./Brand.ts";
|
|
7
|
+
import type { Eq } from "./Eq.ts";
|
|
8
8
|
/**
|
|
9
9
|
* A wrapper type that prevents sensitive values from being accidentally exposed
|
|
10
10
|
* through logging, serialization, or inspection.
|
|
@@ -26,35 +26,38 @@ import type { Eq } from "./Eq.js";
|
|
|
26
26
|
* ### Example
|
|
27
27
|
*
|
|
28
28
|
* ```ts
|
|
29
|
-
*
|
|
29
|
+
* import {
|
|
30
|
+
* createRedacted,
|
|
31
|
+
* revealRedacted,
|
|
32
|
+
* type Brand,
|
|
33
|
+
* type Redacted,
|
|
34
|
+
* } from "@evolu/common";
|
|
35
|
+
*
|
|
30
36
|
* type ApiKey = string & Brand<"ApiKey">;
|
|
31
37
|
* type DbPassword = string & Brand<"DbPassword">;
|
|
32
|
-
*
|
|
33
|
-
* // Wrap them with Redacted for safe passing
|
|
34
38
|
* type RedactedApiKey = Redacted<ApiKey>;
|
|
35
|
-
* type RedactedDbPassword = Redacted<DbPassword>;
|
|
36
39
|
*
|
|
37
|
-
* //
|
|
40
|
+
* // Apply brands only after validation or at another trusted boundary.
|
|
38
41
|
* const apiKey: ApiKey = "secret-123" as ApiKey;
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* fetchUser(
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
42
|
+
* using redactedKey: RedactedApiKey = createRedacted(apiKey);
|
|
43
|
+
* const fetchUser = (key: RedactedApiKey): ApiKey => revealRedacted(key);
|
|
44
|
+
*
|
|
45
|
+
* expect(redactedKey.toString()).toBe("<redacted>");
|
|
46
|
+
* expect(JSON.stringify({ apiKey: redactedKey })).toBe(
|
|
47
|
+
* '{"apiKey":"<redacted>"}',
|
|
48
|
+
* );
|
|
49
|
+
* expect(fetchUser(redactedKey)).toBe(apiKey);
|
|
50
|
+
*
|
|
51
|
+
* using password = createRedacted("password" as DbPassword);
|
|
52
|
+
* // @ts-expect-error Redacted secrets retain their distinct branded types.
|
|
53
|
+
* fetchUser(password);
|
|
54
|
+
*
|
|
55
|
+
* const disposedKey = (() => {
|
|
56
|
+
* using key = createRedacted(apiKey);
|
|
57
|
+
* return key;
|
|
58
|
+
* })();
|
|
59
|
+
* // Leaving the `using` scope removes the value from memory.
|
|
60
|
+
* expect(() => revealRedacted(disposedKey)).toThrow();
|
|
58
61
|
* ```
|
|
59
62
|
*/
|
|
60
63
|
export interface Redacted<A> extends Brand<"Redacted">, Disposable {
|
|
@@ -80,12 +83,23 @@ export declare const isRedacted: (value: unknown) => value is Redacted<unknown>;
|
|
|
80
83
|
* ### Example
|
|
81
84
|
*
|
|
82
85
|
* ```ts
|
|
86
|
+
* import {
|
|
87
|
+
* createEqRedacted,
|
|
88
|
+
* createRedacted,
|
|
89
|
+
* eqString,
|
|
90
|
+
* type Brand,
|
|
91
|
+
* } from "@evolu/common";
|
|
92
|
+
*
|
|
83
93
|
* type ApiKey = string & Brand<"ApiKey">;
|
|
84
94
|
* const eqRedactedApiKey = createEqRedacted<ApiKey>(eqString);
|
|
85
95
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
96
|
+
* // Apply brands only after validation or at another trusted boundary.
|
|
97
|
+
* using a = createRedacted("x" as ApiKey);
|
|
98
|
+
* using b = createRedacted("x" as ApiKey);
|
|
99
|
+
* using c = createRedacted("y" as ApiKey);
|
|
100
|
+
*
|
|
101
|
+
* expect(eqRedactedApiKey(a, b)).toBe(true);
|
|
102
|
+
* expect(eqRedactedApiKey(a, c)).toBe(false);
|
|
89
103
|
* ```
|
|
90
104
|
*/
|
|
91
105
|
export declare const createEqRedacted: <A>(eq: Eq<A>) => Eq<Redacted<A>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Redacted.d.ts","sourceRoot":"","sources":["../../src/Redacted.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"Redacted.d.ts","sourceRoot":"","sources":["../../src/Redacted.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,UAAU,CAAC,EAAE,UAAU;IAChE,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;CAClB;AAED,gEAAgE;AAChE,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,CAAC,KAAG,QAAQ,CAAC,CAAC,CAItD,CAAC;AAaF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,CAAC,YAAY,QAAQ,CAAC,CAAC,CAAC,KAAG,CAGzD,CAAC;AAEF,uDAAuD;AACvD,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CAG7B,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,gBAAgB,GAC1B,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAEY,CAAC"}
|
package/dist/src/Redacted.js
CHANGED
|
@@ -42,12 +42,23 @@ export const isRedacted = (value) => typeof value === "object" &&
|
|
|
42
42
|
* ### Example
|
|
43
43
|
*
|
|
44
44
|
* ```ts
|
|
45
|
+
* import {
|
|
46
|
+
* createEqRedacted,
|
|
47
|
+
* createRedacted,
|
|
48
|
+
* eqString,
|
|
49
|
+
* type Brand,
|
|
50
|
+
* } from "@evolu/common";
|
|
51
|
+
*
|
|
45
52
|
* type ApiKey = string & Brand<"ApiKey">;
|
|
46
53
|
* const eqRedactedApiKey = createEqRedacted<ApiKey>(eqString);
|
|
47
54
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
55
|
+
* // Apply brands only after validation or at another trusted boundary.
|
|
56
|
+
* using a = createRedacted("x" as ApiKey);
|
|
57
|
+
* using b = createRedacted("x" as ApiKey);
|
|
58
|
+
* using c = createRedacted("y" as ApiKey);
|
|
59
|
+
*
|
|
60
|
+
* expect(eqRedactedApiKey(a, b)).toBe(true);
|
|
61
|
+
* expect(eqRedactedApiKey(a, c)).toBe(false);
|
|
51
62
|
* ```
|
|
52
63
|
*/
|
|
53
64
|
export const createEqRedacted = (eq) => (x, y) => eq(revealRedacted(x), revealRedacted(y));
|
package/dist/src/Ref.d.ts
CHANGED
|
@@ -18,18 +18,26 @@
|
|
|
18
18
|
* ### Example
|
|
19
19
|
*
|
|
20
20
|
* ```ts
|
|
21
|
+
* import { createRef } from "@evolu/common";
|
|
22
|
+
*
|
|
21
23
|
* const count = createRef(0);
|
|
22
24
|
* count.set(1);
|
|
23
25
|
* count.update((n) => n + 1);
|
|
24
|
-
*
|
|
26
|
+
* expect(count.get()).toBe(2);
|
|
25
27
|
* ```
|
|
26
28
|
*
|
|
27
|
-
* ###
|
|
29
|
+
* ### As a dependency
|
|
28
30
|
*
|
|
29
31
|
* ```ts
|
|
32
|
+
* import { createRef, type Ref } from "@evolu/common";
|
|
33
|
+
*
|
|
30
34
|
* interface CounterRefDep {
|
|
31
35
|
* readonly counterRef: Ref<number>;
|
|
32
36
|
* }
|
|
37
|
+
*
|
|
38
|
+
* const deps: CounterRefDep = { counterRef: createRef(0) };
|
|
39
|
+
* deps.counterRef.update((count) => count + 1);
|
|
40
|
+
* expect(deps.counterRef.get()).toBe(1);
|
|
33
41
|
* ```
|
|
34
42
|
*/
|
|
35
43
|
export interface Ref<T> {
|
|
@@ -48,7 +56,7 @@ export interface Ref<T> {
|
|
|
48
56
|
/** Updates the current value and returns it. */
|
|
49
57
|
readonly updateAndGet: (updater: (current: T) => T) => T;
|
|
50
58
|
/** Modifies the current value and returns a computed result. */
|
|
51
|
-
readonly modify: <R>(
|
|
59
|
+
readonly modify: <R>(modifier: (current: T) => readonly [result: R, nextValue: T]) => R;
|
|
52
60
|
}
|
|
53
61
|
/** Creates a {@link Ref} with the given initial immutable value. */
|
|
54
62
|
export declare const createRef: <T>(initialValue: T) => Ref<T>;
|
package/dist/src/Ref.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../src/Ref.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH
|
|
1
|
+
{"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../src/Ref.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,WAAW,GAAG,CAAC,CAAC;IACpB,iCAAiC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEtB,8BAA8B;IAC9B,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAEjC,6DAA6D;IAC7D,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAEpC,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAEpC,iCAAiC;IACjC,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAEtD,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEzD,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEzD,gEAAgE;IAChE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,KACzD,CAAC,CAAC;CACR;AAED,oEAAoE;AACpE,eAAO,MAAM,SAAS,GAAI,CAAC,gBAAgB,CAAC,KAAG,GAAG,CAAC,CAAC,CA0CnD,CAAC"}
|
package/dist/src/Ref.js
CHANGED
|
@@ -32,8 +32,8 @@ export const createRef = (initialValue) => {
|
|
|
32
32
|
currentValue = updater(currentValue);
|
|
33
33
|
return currentValue;
|
|
34
34
|
},
|
|
35
|
-
modify: (
|
|
36
|
-
const [result, nextValue] =
|
|
35
|
+
modify: (modifier) => {
|
|
36
|
+
const [result, nextValue] = modifier(currentValue);
|
|
37
37
|
currentValue = nextValue;
|
|
38
38
|
return result;
|
|
39
39
|
},
|
package/dist/src/RefCount.d.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import { type LookupOption } from "./Lookup.
|
|
7
|
-
import { NonNegativeInt, PositiveInt } from "./Type.
|
|
6
|
+
import { type LookupOption } from "./Lookup.ts";
|
|
7
|
+
import { NonNegativeInt, PositiveInt } from "./Type.ts";
|
|
8
8
|
/**
|
|
9
9
|
* Reference count for one retained value.
|
|
10
10
|
*
|
|
@@ -21,8 +21,6 @@ export interface RefCount extends Disposable {
|
|
|
21
21
|
readonly decrement: () => NonNegativeInt;
|
|
22
22
|
/** Returns the current count. */
|
|
23
23
|
readonly getCount: () => NonNegativeInt;
|
|
24
|
-
/** Disposes and invalidates the helper. Further method calls throw. */
|
|
25
|
-
readonly [Symbol.dispose]: () => void;
|
|
26
24
|
}
|
|
27
25
|
/** Creates {@link RefCount}. */
|
|
28
26
|
export declare const createRefCount: () => RefCount;
|
|
@@ -50,8 +48,6 @@ export interface RefCountByKey<TKey> extends Disposable {
|
|
|
50
48
|
readonly has: (key: TKey) => boolean;
|
|
51
49
|
/** Returns all currently tracked keys. */
|
|
52
50
|
readonly keys: () => ReadonlySet<TKey>;
|
|
53
|
-
/** Disposes and invalidates the helper. Further method calls throw. */
|
|
54
|
-
readonly [Symbol.dispose]: () => void;
|
|
55
51
|
}
|
|
56
52
|
/** Options for {@link createRefCountByKey}. */
|
|
57
53
|
export interface CreateRefCountByKeyOptions<TKey, L = TKey> extends LookupOption<TKey, L> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefCount.d.ts","sourceRoot":"","sources":["../../src/RefCount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAsB,MAAM,WAAW,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,WAAW,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,cAAc,CAAC;IAEzC,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"RefCount.d.ts","sourceRoot":"","sources":["../../src/RefCount.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAgC,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,WAAW,EAAsB,MAAM,WAAW,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,WAAW,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,cAAc,CAAC;IAEzC,iCAAiC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,cAAc,CAAC;CACzC;AAED,gCAAgC;AAChC,eAAO,MAAM,cAAc,QAAO,QAkBjC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa,CAAC,IAAI,CAAE,SAAQ,UAAU;IACrD,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,WAAW,CAAC;IAE/C;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,cAAc,CAAC;IAElD,2EAA2E;IAC3E,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,cAAc,CAAC;IAEjD,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,OAAO,CAAC;IAErC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B,CACzC,IAAI,EACJ,CAAC,GAAG,IAAI,CACR,SAAQ,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;CAAG;AAElC,qCAAqC;AACrC,wBAAgB,mBAAmB,CAAC,IAAI,GAAG,OAAO,KAAK,aAAa,CAAC,IAAI,CAAC,CAAC;AAC3E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,CAAC,EACzC,OAAO,EAAE,0BAA0B,CAAC,IAAI,EAAE,CAAC,CAAC,GAC3C,aAAa,CAAC,IAAI,CAAC,CAAC"}
|