@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/Eq.d.ts
CHANGED
|
@@ -3,22 +3,70 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { Order } from "./Order.
|
|
7
|
-
import type { JsonValue, JsonValueInput } from "./Type.
|
|
6
|
+
import type { Order } from "./Order.ts";
|
|
7
|
+
import type { JsonValue, JsonValueInput } from "./Type.ts";
|
|
8
8
|
/**
|
|
9
9
|
* Compares two values of the same type `A` for equality.
|
|
10
10
|
*
|
|
11
11
|
* Equality functions start with an 'eq' prefix, e.g., `eqString`.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* An `Eq` must define an equivalence relation over its intended domain:
|
|
14
|
+
*
|
|
15
|
+
* - **Reflexive**: `eq(a, a)` is `true`.
|
|
16
|
+
* - **Symmetric**: `eq(a, b)` equals `eq(b, a)`.
|
|
17
|
+
* - **Transitive**: if `eq(a, b)` and `eq(b, c)` are `true`, then `eq(a, c)` is
|
|
18
|
+
* `true`.
|
|
19
|
+
*
|
|
20
|
+
* Use {@link eqFromOrder} to derive equality from an {@link Order}.
|
|
21
|
+
*
|
|
22
|
+
* ### Example
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { createEqObject, eqNumber } from "@evolu/common";
|
|
26
|
+
*
|
|
27
|
+
* const eqPoint = createEqObject({ x: eqNumber, y: eqNumber });
|
|
28
|
+
*
|
|
29
|
+
* expect(eqPoint({ x: 1, y: 2 }, { x: 1, y: 2 })).toBe(true);
|
|
30
|
+
* expect(eqPoint({ x: 1, y: 2 }, { x: 2, y: 1 })).toBe(false);
|
|
31
|
+
* ```
|
|
14
32
|
*/
|
|
15
33
|
export type Eq<in A> = (x: A, y: A) => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Compares two values with strict equality (`===`).
|
|
36
|
+
*
|
|
37
|
+
* Strict equality considers `NaN` unequal to itself. Use {@link eqSameValueZero}
|
|
38
|
+
* when values can contain `NaN` and equality must be reflexive.
|
|
39
|
+
*/
|
|
16
40
|
export declare const eqStrict: <A>(x: A, y: A) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Compares two values using SameValueZero equality.
|
|
43
|
+
*
|
|
44
|
+
* SameValueZero is the standard equality algorithm used by `Map`, `Set`, and
|
|
45
|
+
* `Array.prototype.includes`. It behaves like strict equality except that `NaN`
|
|
46
|
+
* equals itself. Both algorithms consider `0` and `-0` equal.
|
|
47
|
+
*
|
|
48
|
+
* ### Example
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { eqSameValueZero } from "@evolu/common";
|
|
52
|
+
*
|
|
53
|
+
* expect(eqSameValueZero(NaN, NaN)).toBe(true);
|
|
54
|
+
* expect(eqSameValueZero(0, -0)).toBe(true);
|
|
55
|
+
* expect(eqSameValueZero({}, {})).toBe(false);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const eqSameValueZero: <A>(x: A, y: A) => boolean;
|
|
59
|
+
/** An {@link Eq} for strings using strict equality. */
|
|
17
60
|
export declare const eqString: Eq<string>;
|
|
61
|
+
/** An {@link Eq} for numbers using {@link eqSameValueZero}. */
|
|
18
62
|
export declare const eqNumber: Eq<number>;
|
|
63
|
+
/** An {@link Eq} for bigints using strict equality. */
|
|
19
64
|
export declare const eqBigInt: Eq<bigint>;
|
|
65
|
+
/** An {@link Eq} for booleans using strict equality. */
|
|
20
66
|
export declare const eqBoolean: Eq<boolean>;
|
|
67
|
+
/** An {@link Eq} for `undefined`. */
|
|
21
68
|
export declare const eqUndefined: Eq<undefined>;
|
|
69
|
+
/** An {@link Eq} for `null`. */
|
|
22
70
|
export declare const eqNull: Eq<null>;
|
|
23
71
|
/** Derives an {@link Eq} from an {@link Order}. */
|
|
24
72
|
export declare const eqFromOrder: <A>(order: Order<A>) => Eq<A>;
|
|
@@ -29,10 +77,15 @@ export declare const eqFromOrder: <A>(order: Order<A>) => Eq<A>;
|
|
|
29
77
|
* ### Example
|
|
30
78
|
*
|
|
31
79
|
* ```ts
|
|
80
|
+
* import { createEqArrayLike, eqNumber } from "@evolu/common";
|
|
81
|
+
*
|
|
32
82
|
* const eqArrayNumber = createEqArrayLike(eqNumber);
|
|
33
|
-
*
|
|
34
|
-
* eqArrayNumber(
|
|
35
|
-
*
|
|
83
|
+
*
|
|
84
|
+
* expect(eqArrayNumber([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
85
|
+
* expect(
|
|
86
|
+
* eqArrayNumber(new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3])),
|
|
87
|
+
* ).toBe(true);
|
|
88
|
+
* expect(eqArrayNumber([1, 2, 3], [1, 2, 4])).toBe(false);
|
|
36
89
|
* ```
|
|
37
90
|
*/
|
|
38
91
|
export declare const createEqArrayLike: <A>(item: Eq<A>) => Eq<ArrayLike<A>>;
|
|
@@ -44,10 +97,12 @@ export declare const createEqArrayLike: <A>(item: Eq<A>) => Eq<ArrayLike<A>>;
|
|
|
44
97
|
* ### Example
|
|
45
98
|
*
|
|
46
99
|
* ```ts
|
|
100
|
+
* import { eqArrayStrict } from "@evolu/common";
|
|
101
|
+
*
|
|
47
102
|
* const a = { x: 1 };
|
|
48
103
|
* const b = { x: 1 };
|
|
49
|
-
* eqArrayStrict([a, a], [a, a])
|
|
50
|
-
* eqArrayStrict([a], [b])
|
|
104
|
+
* expect(eqArrayStrict([a, a], [a, a])).toBe(true);
|
|
105
|
+
* expect(eqArrayStrict([a], [b])).toBe(false);
|
|
51
106
|
* ```
|
|
52
107
|
*/
|
|
53
108
|
export declare const eqArrayStrict: <A>(x: ArrayLike<A>, y: ArrayLike<A>) => boolean;
|
|
@@ -57,9 +112,9 @@ export declare const eqArrayStrict: <A>(x: ArrayLike<A>, y: ArrayLike<A>) => boo
|
|
|
57
112
|
* ### Example
|
|
58
113
|
*
|
|
59
114
|
* ```ts
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* eqArrayNumber([1,
|
|
115
|
+
* import { eqArrayNumber } from "@evolu/common";
|
|
116
|
+
*
|
|
117
|
+
* expect(eqArrayNumber([1, NaN], [1, NaN])).toBe(true);
|
|
63
118
|
* ```
|
|
64
119
|
*/
|
|
65
120
|
export declare const eqArrayNumber: Eq<ArrayLike<number>>;
|
|
@@ -70,9 +125,12 @@ export declare const eqArrayNumber: Eq<ArrayLike<number>>;
|
|
|
70
125
|
* ### Example
|
|
71
126
|
*
|
|
72
127
|
* ```ts
|
|
128
|
+
* import { createEqObject, eqNumber } from "@evolu/common";
|
|
129
|
+
*
|
|
73
130
|
* const eqObjectNumber = createEqObject({ a: eqNumber });
|
|
74
|
-
*
|
|
75
|
-
* eqObjectNumber({ a: 1 }, { a:
|
|
131
|
+
*
|
|
132
|
+
* expect(eqObjectNumber({ a: 1 }, { a: 1 })).toBe(true);
|
|
133
|
+
* expect(eqObjectNumber({ a: 1 }, { a: 2 })).toBe(false);
|
|
76
134
|
* ```
|
|
77
135
|
*/
|
|
78
136
|
export declare const createEqObject: <A>(eqs: { [K in keyof A]: Eq<A[K]>; }) => Eq<{ readonly [K in keyof A]: A[K]; }>;
|
|
@@ -81,7 +139,8 @@ export declare const createEqObject: <A>(eqs: { [K in keyof A]: Eq<A[K]>; }) =>
|
|
|
81
139
|
*
|
|
82
140
|
* - Uses an iterative approach with a stack to handle large or deeply nested
|
|
83
141
|
* objects without risking stack overflow.
|
|
84
|
-
* -
|
|
142
|
+
* - Defensively handles circular references in runtime values without looping,
|
|
143
|
+
* although cyclic values are not valid JSON.
|
|
85
144
|
* - Unlike JSON.stringify, this function directly compares values, avoiding
|
|
86
145
|
* serialization overhead and leveraging short-circuit evaluation for faster
|
|
87
146
|
* failure on mismatched structures.
|
|
@@ -89,9 +148,12 @@ export declare const createEqObject: <A>(eqs: { [K in keyof A]: Eq<A[K]>; }) =>
|
|
|
89
148
|
* ### Example
|
|
90
149
|
*
|
|
91
150
|
* ```ts
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
151
|
+
* import { eqJsonValue, type JsonValue } from "@evolu/common";
|
|
152
|
+
*
|
|
153
|
+
* const first: JsonValue = { profile: { name: "Ada" } };
|
|
154
|
+
* const second: JsonValue = { profile: { name: "Ada" } };
|
|
155
|
+
*
|
|
156
|
+
* expect(eqJsonValue(first, second)).toBe(true);
|
|
95
157
|
* ```
|
|
96
158
|
*/
|
|
97
159
|
export declare const eqJsonValue: (a: JsonValue, b: JsonValue) => boolean;
|
|
@@ -100,7 +162,8 @@ export declare const eqJsonValue: (a: JsonValue, b: JsonValue) => boolean;
|
|
|
100
162
|
*
|
|
101
163
|
* - Uses an iterative approach with a stack to handle large or deeply nested
|
|
102
164
|
* objects without risking stack overflow.
|
|
103
|
-
* -
|
|
165
|
+
* - Defensively handles circular references in runtime values without looping,
|
|
166
|
+
* although cyclic values are not valid JSON.
|
|
104
167
|
* - Unlike JSON.stringify, this function directly compares values, avoiding
|
|
105
168
|
* serialization overhead and leveraging short-circuit evaluation for faster
|
|
106
169
|
* failure on mismatched structures.
|
|
@@ -108,9 +171,12 @@ export declare const eqJsonValue: (a: JsonValue, b: JsonValue) => boolean;
|
|
|
108
171
|
* ### Example
|
|
109
172
|
*
|
|
110
173
|
* ```ts
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
174
|
+
* import { eqJsonValueInput, type JsonValueInput } from "@evolu/common";
|
|
175
|
+
*
|
|
176
|
+
* const first: JsonValueInput = { profile: { name: "Ada" } };
|
|
177
|
+
* const second: JsonValueInput = { profile: { name: "Ada" } };
|
|
178
|
+
*
|
|
179
|
+
* expect(eqJsonValueInput(first, second)).toBe(true);
|
|
114
180
|
* ```
|
|
115
181
|
*/
|
|
116
182
|
export declare const eqJsonValueInput: (a: JsonValueInput, b: JsonValueInput) => boolean;
|
package/dist/src/Eq.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Eq.d.ts","sourceRoot":"","sources":["../../src/Eq.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAGV,SAAS,EACT,cAAc,EACf,MAAM,WAAW,CAAC;AAEnB
|
|
1
|
+
{"version":3,"file":"Eq.d.ts","sourceRoot":"","sources":["../../src/Eq.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAGV,SAAS,EACT,cAAc,EACf,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;AAE/C;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OAAkB,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAG,OACpB,CAAC;AAE7B,uDAAuD;AACvD,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAY,CAAC;AAE7C,+DAA+D;AAC/D,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAmB,CAAC;AAEpD,uDAAuD;AACvD,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAY,CAAC;AAE7C,wDAAwD;AACxD,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC,OAAO,CAAY,CAAC;AAE/C,qCAAqC;AACrC,eAAO,MAAM,WAAW,EAAE,EAAE,CAAC,SAAS,CAAY,CAAC;AAEnD,gCAAgC;AAChC,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,IAAI,CAAY,CAAC;AAEzC,mDAAmD;AACnD,eAAO,MAAM,WAAW,GACrB,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,KAAG,EAAE,CAAC,CAAC,CAEP,CAAC;AAEtB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iBAAiB,GAC3B,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAUhC,CAAC;AAEJ;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GA7FD,CAAC,uCARa,OAqG+B,CAAC;AAEvE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,uBAA4C,CAAC;AAEvE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GACxB,CAAC,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAE,KAAG,EAAE,CAAC,EACzC,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAC9B,CASA,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,MAAO,SAAS,KAAK,SAAS,KAAG,OAsExD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,gBAAgB,MACxB,cAAc,KACd,cAAc,KAChB,OAAsD,CAAC"}
|
package/dist/src/Eq.js
CHANGED
|
@@ -3,12 +3,42 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* Compares two values with strict equality (`===`).
|
|
8
|
+
*
|
|
9
|
+
* Strict equality considers `NaN` unequal to itself. Use {@link eqSameValueZero}
|
|
10
|
+
* when values can contain `NaN` and equality must be reflexive.
|
|
11
|
+
*/
|
|
6
12
|
export const eqStrict = (x, y) => x === y;
|
|
13
|
+
/**
|
|
14
|
+
* Compares two values using SameValueZero equality.
|
|
15
|
+
*
|
|
16
|
+
* SameValueZero is the standard equality algorithm used by `Map`, `Set`, and
|
|
17
|
+
* `Array.prototype.includes`. It behaves like strict equality except that `NaN`
|
|
18
|
+
* equals itself. Both algorithms consider `0` and `-0` equal.
|
|
19
|
+
*
|
|
20
|
+
* ### Example
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { eqSameValueZero } from "@evolu/common";
|
|
24
|
+
*
|
|
25
|
+
* expect(eqSameValueZero(NaN, NaN)).toBe(true);
|
|
26
|
+
* expect(eqSameValueZero(0, -0)).toBe(true);
|
|
27
|
+
* expect(eqSameValueZero({}, {})).toBe(false);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const eqSameValueZero = (x, y) => x === y || Object.is(x, y);
|
|
31
|
+
/** An {@link Eq} for strings using strict equality. */
|
|
7
32
|
export const eqString = eqStrict;
|
|
8
|
-
|
|
33
|
+
/** An {@link Eq} for numbers using {@link eqSameValueZero}. */
|
|
34
|
+
export const eqNumber = eqSameValueZero;
|
|
35
|
+
/** An {@link Eq} for bigints using strict equality. */
|
|
9
36
|
export const eqBigInt = eqStrict;
|
|
37
|
+
/** An {@link Eq} for booleans using strict equality. */
|
|
10
38
|
export const eqBoolean = eqStrict;
|
|
39
|
+
/** An {@link Eq} for `undefined`. */
|
|
11
40
|
export const eqUndefined = eqStrict;
|
|
41
|
+
/** An {@link Eq} for `null`. */
|
|
12
42
|
export const eqNull = eqStrict;
|
|
13
43
|
/** Derives an {@link Eq} from an {@link Order}. */
|
|
14
44
|
export const eqFromOrder = (order) => (x, y) => order(x, y) === 0;
|
|
@@ -19,10 +49,15 @@ export const eqFromOrder = (order) => (x, y) => order(x, y) === 0;
|
|
|
19
49
|
* ### Example
|
|
20
50
|
*
|
|
21
51
|
* ```ts
|
|
52
|
+
* import { createEqArrayLike, eqNumber } from "@evolu/common";
|
|
53
|
+
*
|
|
22
54
|
* const eqArrayNumber = createEqArrayLike(eqNumber);
|
|
23
|
-
*
|
|
24
|
-
* eqArrayNumber(
|
|
25
|
-
*
|
|
55
|
+
*
|
|
56
|
+
* expect(eqArrayNumber([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
57
|
+
* expect(
|
|
58
|
+
* eqArrayNumber(new Uint8Array([1, 2, 3]), new Uint8Array([1, 2, 3])),
|
|
59
|
+
* ).toBe(true);
|
|
60
|
+
* expect(eqArrayNumber([1, 2, 3], [1, 2, 4])).toBe(false);
|
|
26
61
|
* ```
|
|
27
62
|
*/
|
|
28
63
|
export const createEqArrayLike = (item) => (x, y) => {
|
|
@@ -44,10 +79,12 @@ export const createEqArrayLike = (item) => (x, y) => {
|
|
|
44
79
|
* ### Example
|
|
45
80
|
*
|
|
46
81
|
* ```ts
|
|
82
|
+
* import { eqArrayStrict } from "@evolu/common";
|
|
83
|
+
*
|
|
47
84
|
* const a = { x: 1 };
|
|
48
85
|
* const b = { x: 1 };
|
|
49
|
-
* eqArrayStrict([a, a], [a, a])
|
|
50
|
-
* eqArrayStrict([a], [b])
|
|
86
|
+
* expect(eqArrayStrict([a, a], [a, a])).toBe(true);
|
|
87
|
+
* expect(eqArrayStrict([a], [b])).toBe(false);
|
|
51
88
|
* ```
|
|
52
89
|
*/
|
|
53
90
|
export const eqArrayStrict = /*#__PURE__*/ createEqArrayLike(eqStrict);
|
|
@@ -57,9 +94,9 @@ export const eqArrayStrict = /*#__PURE__*/ createEqArrayLike(eqStrict);
|
|
|
57
94
|
* ### Example
|
|
58
95
|
*
|
|
59
96
|
* ```ts
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* eqArrayNumber([1,
|
|
97
|
+
* import { eqArrayNumber } from "@evolu/common";
|
|
98
|
+
*
|
|
99
|
+
* expect(eqArrayNumber([1, NaN], [1, NaN])).toBe(true);
|
|
63
100
|
* ```
|
|
64
101
|
*/
|
|
65
102
|
export const eqArrayNumber = /*#__PURE__*/ createEqArrayLike(eqNumber);
|
|
@@ -70,9 +107,12 @@ export const eqArrayNumber = /*#__PURE__*/ createEqArrayLike(eqNumber);
|
|
|
70
107
|
* ### Example
|
|
71
108
|
*
|
|
72
109
|
* ```ts
|
|
110
|
+
* import { createEqObject, eqNumber } from "@evolu/common";
|
|
111
|
+
*
|
|
73
112
|
* const eqObjectNumber = createEqObject({ a: eqNumber });
|
|
74
|
-
*
|
|
75
|
-
* eqObjectNumber({ a: 1 }, { a:
|
|
113
|
+
*
|
|
114
|
+
* expect(eqObjectNumber({ a: 1 }, { a: 1 })).toBe(true);
|
|
115
|
+
* expect(eqObjectNumber({ a: 1 }, { a: 2 })).toBe(false);
|
|
76
116
|
* ```
|
|
77
117
|
*/
|
|
78
118
|
export const createEqObject = (eqs) => (x, y) => {
|
|
@@ -90,7 +130,8 @@ export const createEqObject = (eqs) => (x, y) => {
|
|
|
90
130
|
*
|
|
91
131
|
* - Uses an iterative approach with a stack to handle large or deeply nested
|
|
92
132
|
* objects without risking stack overflow.
|
|
93
|
-
* -
|
|
133
|
+
* - Defensively handles circular references in runtime values without looping,
|
|
134
|
+
* although cyclic values are not valid JSON.
|
|
94
135
|
* - Unlike JSON.stringify, this function directly compares values, avoiding
|
|
95
136
|
* serialization overhead and leveraging short-circuit evaluation for faster
|
|
96
137
|
* failure on mismatched structures.
|
|
@@ -98,9 +139,12 @@ export const createEqObject = (eqs) => (x, y) => {
|
|
|
98
139
|
* ### Example
|
|
99
140
|
*
|
|
100
141
|
* ```ts
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
142
|
+
* import { eqJsonValue, type JsonValue } from "@evolu/common";
|
|
143
|
+
*
|
|
144
|
+
* const first: JsonValue = { profile: { name: "Ada" } };
|
|
145
|
+
* const second: JsonValue = { profile: { name: "Ada" } };
|
|
146
|
+
*
|
|
147
|
+
* expect(eqJsonValue(first, second)).toBe(true);
|
|
104
148
|
* ```
|
|
105
149
|
*/
|
|
106
150
|
export const eqJsonValue = (a, b) => {
|
|
@@ -171,7 +215,8 @@ export const eqJsonValue = (a, b) => {
|
|
|
171
215
|
*
|
|
172
216
|
* - Uses an iterative approach with a stack to handle large or deeply nested
|
|
173
217
|
* objects without risking stack overflow.
|
|
174
|
-
* -
|
|
218
|
+
* - Defensively handles circular references in runtime values without looping,
|
|
219
|
+
* although cyclic values are not valid JSON.
|
|
175
220
|
* - Unlike JSON.stringify, this function directly compares values, avoiding
|
|
176
221
|
* serialization overhead and leveraging short-circuit evaluation for faster
|
|
177
222
|
* failure on mismatched structures.
|
|
@@ -179,9 +224,12 @@ export const eqJsonValue = (a, b) => {
|
|
|
179
224
|
* ### Example
|
|
180
225
|
*
|
|
181
226
|
* ```ts
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
227
|
+
* import { eqJsonValueInput, type JsonValueInput } from "@evolu/common";
|
|
228
|
+
*
|
|
229
|
+
* const first: JsonValueInput = { profile: { name: "Ada" } };
|
|
230
|
+
* const second: JsonValueInput = { profile: { name: "Ada" } };
|
|
231
|
+
*
|
|
232
|
+
* expect(eqJsonValueInput(first, second)).toBe(true);
|
|
185
233
|
* ```
|
|
186
234
|
*/
|
|
187
235
|
export const eqJsonValueInput = (a, b) => eqJsonValue(a, b);
|
package/dist/src/Error.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import { type InferType, type TypedType, Unknown } from "./Type.ts";
|
|
7
7
|
/**
|
|
8
8
|
* A wrapper for unknown errors caught at runtime.
|
|
9
9
|
*
|
|
@@ -16,8 +16,10 @@ import type { Typed } from "./Type.js";
|
|
|
16
16
|
*
|
|
17
17
|
* Use {@link createUnknownError} to create instances.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
20
|
-
readonly error:
|
|
19
|
+
export declare const UnknownError: TypedType<"UnknownError", {
|
|
20
|
+
readonly error: typeof Unknown;
|
|
21
|
+
}>;
|
|
22
|
+
export interface UnknownError extends InferType<typeof UnknownError> {
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Creates an {@link UnknownError} from an unknown error.
|
package/dist/src/Error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../src/Error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAS,KAAK,SAAS,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,EAAE,SAAS,CAClC,cAAc,EACd;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,OAAO,CAAA;CAAE,CAGlC,CAAC;AACH,MAAM,WAAW,YAAa,SAAQ,SAAS,CAAC,OAAO,YAAY,CAAC;CAAG;AAEvE;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,KAAG,YAkDnD,CAAC"}
|
package/dist/src/Error.js
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import { typed, Unknown } from "./Type.js";
|
|
7
|
+
/**
|
|
8
|
+
* A wrapper for unknown errors caught at runtime.
|
|
9
|
+
*
|
|
10
|
+
* When catching errors from unsafe code (third-party libraries, worker
|
|
11
|
+
* boundaries, etc.), we wrap them in `UnknownError` so they can be used in
|
|
12
|
+
* union types and distinguished from other error types.
|
|
13
|
+
*
|
|
14
|
+
* The `error` property contains error details (including `message`, `stack`,
|
|
15
|
+
* and `cause` if available), a string, or a fallback value.
|
|
16
|
+
*
|
|
17
|
+
* Use {@link createUnknownError} to create instances.
|
|
18
|
+
*/
|
|
19
|
+
export const UnknownError = /*#__PURE__*/ typed("UnknownError", {
|
|
20
|
+
error: Unknown,
|
|
21
|
+
});
|
|
6
22
|
/**
|
|
7
23
|
* Creates an {@link UnknownError} from an unknown error.
|
|
8
24
|
*
|