@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/Array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../src/Array.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../src/Array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AAIH;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAE9E;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,EAAE,aAAa,CAAC,KAAK,CAAM,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACtE,oCAAoC;AACpC,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,GACxB,aAAa,CAAC,CAAC,CAAC,CAAC;AA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AgB9C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,qBAAqB,CAAC,CAAC,CAAC,KAAG,CAAa,CAAC;AAEhF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,qBAAqB,CAAC,CAAC,CAAC,KAAG,CACxC,CAAC"}
|
package/dist/src/Array.js
CHANGED
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
*
|
|
21
21
|
* const scores = [3, 1, 2];
|
|
22
22
|
* const leaderboard = sortScores(scores);
|
|
23
|
-
* leaderboard
|
|
24
|
-
* scores
|
|
23
|
+
* expect(leaderboard).toEqual([1, 2, 3]);
|
|
24
|
+
* expect(scores).toEqual([1, 2, 3]);
|
|
25
|
+
* expect(leaderboard).toBe(scores);
|
|
25
26
|
* ```
|
|
26
27
|
*
|
|
27
28
|
* Imagine every method doing that.
|
|
@@ -30,71 +31,50 @@
|
|
|
30
31
|
* instead:
|
|
31
32
|
*
|
|
32
33
|
* ```ts
|
|
34
|
+
* import { sortArray } from "@evolu/common";
|
|
35
|
+
*
|
|
33
36
|
* const sortScores = (arr: ReadonlyArray<number>) =>
|
|
34
37
|
* sortArray(arr, (a, b) => a - b);
|
|
35
38
|
*
|
|
36
39
|
* const scores: ReadonlyArray<number> = [3, 1, 2];
|
|
37
40
|
* const leaderboard = sortScores(scores);
|
|
38
|
-
* leaderboard
|
|
39
|
-
* scores
|
|
41
|
+
* expect(leaderboard).toEqual([1, 2, 3]);
|
|
42
|
+
* expect(scores).toEqual([3, 1, 2]);
|
|
43
|
+
* expect(leaderboard).not.toBe(scores);
|
|
40
44
|
* ```
|
|
41
45
|
*
|
|
42
46
|
* Even better, require a {@link NonEmptyReadonlyArray} — there's nothing to sort
|
|
43
47
|
* if the array is empty anyway:
|
|
44
48
|
*
|
|
45
49
|
* ```ts
|
|
50
|
+
* import { sortArray, type NonEmptyReadonlyArray } from "@evolu/common";
|
|
51
|
+
*
|
|
46
52
|
* const sortScores = (arr: NonEmptyReadonlyArray<number>) =>
|
|
47
53
|
* sortArray(arr, (a, b) => a - b);
|
|
54
|
+
*
|
|
55
|
+
* const leaderboard = sortScores([3, 1, 2]);
|
|
56
|
+
* expect(leaderboard).toEqual([1, 2, 3]);
|
|
57
|
+
* expectTypeOf(leaderboard).toEqualTypeOf<NonEmptyReadonlyArray<number>>();
|
|
48
58
|
* ```
|
|
49
59
|
*
|
|
50
60
|
* Sorting an empty array isn't expensive, but functions can have side effects
|
|
51
61
|
* like database queries or network requests. Using non-empty arrays whenever
|
|
52
62
|
* possible is a good convention.
|
|
53
63
|
*
|
|
54
|
-
* For performance-critical cases where mutation is needed, Evolu provides
|
|
55
|
-
* {@link shiftFromArray} and {@link popFromArray} — but only because they improve
|
|
56
|
-
* type safety by returning a guaranteed `T` rather than an optional value.
|
|
57
|
-
*
|
|
58
64
|
* ### When to use native methods
|
|
59
65
|
*
|
|
60
66
|
* These helpers only exist where they add type-level value. Native methods like
|
|
61
67
|
* `find`, `some`, `every`, `includes`, `indexOf`, and `findIndex` work well on
|
|
62
68
|
* readonly arrays without mutation — use them directly.
|
|
63
69
|
*
|
|
64
|
-
* ## Examples
|
|
65
|
-
*
|
|
66
70
|
* ```ts
|
|
67
|
-
*
|
|
68
|
-
* const _valid: NonEmptyReadonlyArray<number> = [1, 2, 3];
|
|
69
|
-
* // ts-expect-error - empty array is not a valid NonEmptyReadonlyArray
|
|
70
|
-
* const _invalid: NonEmptyReadonlyArray<number> = [];
|
|
71
|
-
*
|
|
72
|
-
* // Type guards
|
|
73
|
-
* const arr: ReadonlyArray<number> = [1, 2, 3];
|
|
74
|
-
* if (isNonEmptyArray(arr)) {
|
|
75
|
-
* firstInArray(arr);
|
|
76
|
-
* }
|
|
77
|
-
*
|
|
78
|
-
* // Transformations
|
|
79
|
-
* const appended = appendToArray([1, 2, 3], 4); // [1, 2, 3, 4]
|
|
80
|
-
* const prepended = prependToArray([2, 3], 1); // [1, 2, 3]
|
|
81
|
-
* const readonly: ReadonlyArray<number> = [1, 2, 3];
|
|
82
|
-
* const mapped = mapArray(readonly, (x) => x * 2); // [2, 4, 6]
|
|
83
|
-
* const filtered = filterArray(readonly, (x) => x > 1); // [2, 3]
|
|
84
|
-
* const deduped = dedupeArray([1, 2, 1, 3, 2]); // [1, 2, 3]
|
|
85
|
-
* const [evens, odds] = partitionArray(
|
|
86
|
-
* [1, 2, 3, 4, 5],
|
|
87
|
-
* (x) => x % 2 === 0,
|
|
88
|
-
* );
|
|
71
|
+
* import { type NonEmptyReadonlyArray } from "@evolu/common";
|
|
89
72
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* const
|
|
73
|
+
* const valid: NonEmptyReadonlyArray<number> = [1, 2, 3];
|
|
74
|
+
* // @ts-expect-error An empty array is not non-empty.
|
|
75
|
+
* const invalid: NonEmptyReadonlyArray<number> = [];
|
|
93
76
|
*
|
|
94
|
-
*
|
|
95
|
-
* const mutable: NonEmptyArray<number> = [1, 2, 3];
|
|
96
|
-
* shiftFromArray(mutable); // 1 (guaranteed to exist)
|
|
97
|
-
* mutable; // [2, 3]
|
|
77
|
+
* expect(valid.find((value) => value === 2)).toBe(2);
|
|
98
78
|
* ```
|
|
99
79
|
*
|
|
100
80
|
* ## Composition
|
|
@@ -103,16 +83,51 @@
|
|
|
103
83
|
* because it's natural for single operations:
|
|
104
84
|
*
|
|
105
85
|
* ```ts
|
|
86
|
+
* import { mapArray } from "@evolu/common";
|
|
87
|
+
*
|
|
88
|
+
* interface Message {
|
|
89
|
+
* readonly timestamp: number;
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* const messages: ReadonlyArray<Message> = [
|
|
93
|
+
* { timestamp: 10 },
|
|
94
|
+
* { timestamp: 20 },
|
|
95
|
+
* ];
|
|
106
96
|
* const timestamps = mapArray(messages, (m) => m.timestamp);
|
|
97
|
+
* expect(timestamps).toEqual([10, 20]);
|
|
107
98
|
* ```
|
|
108
99
|
*
|
|
109
100
|
* Data-first style also reads well for a few operations, often fitting on a
|
|
110
101
|
* line:
|
|
111
102
|
*
|
|
112
103
|
* ```ts
|
|
113
|
-
*
|
|
104
|
+
* import {
|
|
105
|
+
* dedupeArray,
|
|
106
|
+
* filterArray,
|
|
107
|
+
* firstInArray,
|
|
108
|
+
* isNonEmptyArray,
|
|
109
|
+
* lastInArray,
|
|
110
|
+
* mapArray,
|
|
111
|
+
* orderNumber,
|
|
112
|
+
* sortArray,
|
|
113
|
+
* } from "@evolu/common";
|
|
114
|
+
*
|
|
115
|
+
* const cheapest = firstInArray(sortArray([30, 10, 20], orderNumber));
|
|
116
|
+
* expect(cheapest).toBe(10);
|
|
117
|
+
*
|
|
118
|
+
* const users = [{ name: "Ada" }, { name: "Linus" }, { name: "Ada" }];
|
|
114
119
|
* const uniqueNames = dedupeArray(mapArray(users, (u) => u.name));
|
|
115
|
-
*
|
|
120
|
+
* expect(uniqueNames).toEqual(["Ada", "Linus"]);
|
|
121
|
+
*
|
|
122
|
+
* const jobs = [
|
|
123
|
+
* { id: 1, done: false },
|
|
124
|
+
* { id: 2, done: true },
|
|
125
|
+
* ];
|
|
126
|
+
* const completedJobs = filterArray(jobs, (job) => job.done);
|
|
127
|
+
* if (!isNonEmptyArray(completedJobs)) throw new Error("Expected a job");
|
|
128
|
+
* const latestDone = lastInArray(completedJobs);
|
|
129
|
+
*
|
|
130
|
+
* expect(latestDone).toEqual({ id: 2, done: true });
|
|
116
131
|
* ```
|
|
117
132
|
*
|
|
118
133
|
* For more operations, create a function like `getOldestActiveUser` or a
|
|
@@ -150,16 +165,22 @@ export function arrayFrom(iterableOrLength, map) {
|
|
|
150
165
|
* Returns a readonly array and awaits promised items from sync or async
|
|
151
166
|
* iterables.
|
|
152
167
|
*
|
|
153
|
-
* ###
|
|
168
|
+
* ### Awaiting sync and async iterables
|
|
154
169
|
*
|
|
155
170
|
* ```ts
|
|
156
|
-
*
|
|
157
|
-
*
|
|
171
|
+
* import { arrayFromAsync } from "@evolu/common";
|
|
172
|
+
*
|
|
173
|
+
* const fromIterable = await arrayFromAsync(new Set([1, 2, 3]));
|
|
174
|
+
* expect(fromIterable).toEqual([1, 2, 3]);
|
|
175
|
+
*
|
|
176
|
+
* const fromAsyncIterable = await arrayFromAsync(
|
|
158
177
|
* (async function* () {
|
|
159
178
|
* yield Promise.resolve(1);
|
|
160
179
|
* yield Promise.resolve(2);
|
|
161
180
|
* })(),
|
|
162
|
-
* );
|
|
181
|
+
* );
|
|
182
|
+
* expect(fromAsyncIterable).toEqual([1, 2]);
|
|
183
|
+
* expectTypeOf(fromAsyncIterable).toEqualTypeOf<ReadonlyArray<number>>();
|
|
163
184
|
* ```
|
|
164
185
|
*
|
|
165
186
|
* Unlike `Array.fromAsync`, there's no map parameter — map the result with
|
|
@@ -176,34 +197,46 @@ export function isNonEmptyArray(array) {
|
|
|
176
197
|
/**
|
|
177
198
|
* Appends an item to an array, returning a new non-empty readonly array.
|
|
178
199
|
*
|
|
179
|
-
* ###
|
|
200
|
+
* ### Appending a value
|
|
180
201
|
*
|
|
181
202
|
* ```ts
|
|
182
|
-
*
|
|
203
|
+
* import {
|
|
204
|
+
* appendToArray,
|
|
205
|
+
* type NonEmptyReadonlyArray,
|
|
206
|
+
* } from "@evolu/common";
|
|
207
|
+
*
|
|
208
|
+
* const values = appendToArray([1, 2, 3], 4);
|
|
209
|
+
* expect(values).toEqual([1, 2, 3, 4]);
|
|
210
|
+
* expectTypeOf(values).toEqualTypeOf<NonEmptyReadonlyArray<number>>();
|
|
183
211
|
* ```
|
|
184
212
|
*
|
|
185
213
|
* @group Transformations
|
|
186
214
|
*/
|
|
187
|
-
export const appendToArray = (array, item) =>
|
|
215
|
+
export const appendToArray = (array, item) =>
|
|
216
|
+
// The appended item guarantees non-emptiness, but TypeScript cannot infer a
|
|
217
|
+
// leading element after spreading a possibly empty array.
|
|
218
|
+
[...array, item];
|
|
188
219
|
/**
|
|
189
220
|
* Prepends an item to an array, returning a new non-empty readonly array.
|
|
190
221
|
*
|
|
191
|
-
* ###
|
|
222
|
+
* ### Prepending a value
|
|
192
223
|
*
|
|
193
224
|
* ```ts
|
|
194
|
-
*
|
|
225
|
+
* import {
|
|
226
|
+
* prependToArray,
|
|
227
|
+
* type NonEmptyReadonlyArray,
|
|
228
|
+
* } from "@evolu/common";
|
|
229
|
+
*
|
|
230
|
+
* const values = prependToArray([2, 3], 1);
|
|
231
|
+
* expect(values).toEqual([1, 2, 3]);
|
|
232
|
+
* expectTypeOf(values).toEqualTypeOf<NonEmptyReadonlyArray<number>>();
|
|
195
233
|
* ```
|
|
196
234
|
*
|
|
197
235
|
* @group Transformations
|
|
198
236
|
*/
|
|
199
237
|
export const prependToArray = (array, item) => [item, ...array];
|
|
200
238
|
export function mapArray(array, mapper) {
|
|
201
|
-
|
|
202
|
-
const length = array.length;
|
|
203
|
-
const result = new Array(length);
|
|
204
|
-
for (let i = 0; i < length; i++)
|
|
205
|
-
result[i] = mapper(array[i], i);
|
|
206
|
-
return result;
|
|
239
|
+
return array.map(mapper);
|
|
207
240
|
}
|
|
208
241
|
export function flatMapArray(array, mapper = identity) {
|
|
209
242
|
return array.flatMap(mapper);
|
|
@@ -231,7 +264,7 @@ export function partitionArray(array, predicate) {
|
|
|
231
264
|
const trueArray = [];
|
|
232
265
|
const falseArray = [];
|
|
233
266
|
for (let i = 0; i < array.length; i++) {
|
|
234
|
-
if (predicate(array[i], i)) {
|
|
267
|
+
if (predicate(array[i], i, array)) {
|
|
235
268
|
trueArray.push(array[i]);
|
|
236
269
|
}
|
|
237
270
|
else {
|
|
@@ -251,11 +284,15 @@ export function reverseArray(array) {
|
|
|
251
284
|
*
|
|
252
285
|
* Wraps native `toSpliced`.
|
|
253
286
|
*
|
|
254
|
-
* ###
|
|
287
|
+
* ### Removing and replacing values
|
|
255
288
|
*
|
|
256
289
|
* ```ts
|
|
257
|
-
*
|
|
258
|
-
*
|
|
290
|
+
* import { spliceArray } from "@evolu/common";
|
|
291
|
+
*
|
|
292
|
+
* const values: ReadonlyArray<number> = [1, 2, 3, 4];
|
|
293
|
+
* expect(spliceArray(values, 1, 2)).toEqual([1, 4]);
|
|
294
|
+
* expect(spliceArray([1, 2, 3], 1, 1, 10, 11)).toEqual([1, 10, 11, 3]);
|
|
295
|
+
* expect(values).toEqual([1, 2, 3, 4]);
|
|
259
296
|
* ```
|
|
260
297
|
*
|
|
261
298
|
* @group Transformations
|
|
@@ -274,10 +311,12 @@ export function zipArray(arrays) {
|
|
|
274
311
|
/**
|
|
275
312
|
* Returns the first element of a non-empty array.
|
|
276
313
|
*
|
|
277
|
-
* ###
|
|
314
|
+
* ### Reading the first value
|
|
278
315
|
*
|
|
279
316
|
* ```ts
|
|
280
|
-
* firstInArray
|
|
317
|
+
* import { firstInArray } from "@evolu/common";
|
|
318
|
+
*
|
|
319
|
+
* expect(firstInArray(["a", "b", "c"])).toBe("a");
|
|
281
320
|
* ```
|
|
282
321
|
*
|
|
283
322
|
* @group Accessors
|
|
@@ -286,49 +325,14 @@ export const firstInArray = (array) => array[0];
|
|
|
286
325
|
/**
|
|
287
326
|
* Returns the last element of a non-empty array.
|
|
288
327
|
*
|
|
289
|
-
* ###
|
|
328
|
+
* ### Reading the last value
|
|
290
329
|
*
|
|
291
330
|
* ```ts
|
|
292
|
-
* lastInArray
|
|
331
|
+
* import { lastInArray } from "@evolu/common";
|
|
332
|
+
*
|
|
333
|
+
* expect(lastInArray(["a", "b", "c"])).toBe("c");
|
|
293
334
|
* ```
|
|
294
335
|
*
|
|
295
336
|
* @group Accessors
|
|
296
337
|
*/
|
|
297
338
|
export const lastInArray = (array) => array[array.length - 1];
|
|
298
|
-
/**
|
|
299
|
-
* Shifts (removes and returns) the first element from a non-empty mutable
|
|
300
|
-
* array.
|
|
301
|
-
*
|
|
302
|
-
* **Mutates** the original array.
|
|
303
|
-
*
|
|
304
|
-
* ### Example
|
|
305
|
-
*
|
|
306
|
-
* ```ts
|
|
307
|
-
* // Process a queue of callbacks
|
|
308
|
-
* const waitingQueue: Array<() => void> = [callback1, callback2];
|
|
309
|
-
* if (isNonEmptyArray(waitingQueue)) {
|
|
310
|
-
* shiftFromArray(waitingQueue)(); // Remove and immediately invoke
|
|
311
|
-
* }
|
|
312
|
-
* ```
|
|
313
|
-
*
|
|
314
|
-
* @group Mutations
|
|
315
|
-
*/
|
|
316
|
-
export const shiftFromArray = (array) => array.shift();
|
|
317
|
-
/**
|
|
318
|
-
* Pops (removes and returns) the last element from a non-empty mutable array.
|
|
319
|
-
*
|
|
320
|
-
* **Mutates** the original array.
|
|
321
|
-
*
|
|
322
|
-
* ### Example
|
|
323
|
-
*
|
|
324
|
-
* ```ts
|
|
325
|
-
* // Process a stack of callbacks (LIFO)
|
|
326
|
-
* const callbackStack: Array<() => void> = [callback1, callback2];
|
|
327
|
-
* if (isNonEmptyArray(callbackStack)) {
|
|
328
|
-
* popFromArray(callbackStack)(); // Remove and immediately invoke
|
|
329
|
-
* }
|
|
330
|
-
* ```
|
|
331
|
-
*
|
|
332
|
-
* @group Mutations
|
|
333
|
-
*/
|
|
334
|
-
export const popFromArray = (array) => array.pop();
|
package/dist/src/Assert.d.ts
CHANGED
|
@@ -3,9 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { Ok, Result } from "./Result.js";
|
|
7
|
-
import type { AbortError } from "./Task.js";
|
|
8
|
-
import type { AnyType, InferType } from "./Type.js";
|
|
9
6
|
/**
|
|
10
7
|
* Ensures a condition is true, throwing an error with the provided message if
|
|
11
8
|
* not.
|
|
@@ -20,11 +17,22 @@ import type { AnyType, InferType } from "./Type.js";
|
|
|
20
17
|
* ### Example
|
|
21
18
|
*
|
|
22
19
|
* ```ts
|
|
23
|
-
* assert
|
|
24
|
-
*
|
|
20
|
+
* import { assert as assertInvariant } from "@evolu/common";
|
|
21
|
+
*
|
|
22
|
+
* expect(() => assertInvariant(true, "Expected true.")).not.toThrow();
|
|
23
|
+
* expect(() => assertInvariant(false, "Expected true.")).toThrow(
|
|
24
|
+
* "Expected true.",
|
|
25
|
+
* );
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
28
|
export declare const assert: (condition: unknown, message: string) => asserts condition;
|
|
29
|
+
/**
|
|
30
|
+
* Asserts that a value is non-nullable.
|
|
31
|
+
*
|
|
32
|
+
* Narrows a nullable value to {@link NonNullable} when null or undefined is
|
|
33
|
+
* logically impossible but TypeScript cannot prove it.
|
|
34
|
+
*/
|
|
35
|
+
export declare const assertNonNullable: <T>(value: T, message?: string) => asserts value is NonNullable<T>;
|
|
28
36
|
/**
|
|
29
37
|
* Asserts that an array is non-empty.
|
|
30
38
|
*
|
|
@@ -35,8 +43,13 @@ export declare const assert: (condition: unknown, message: string) => asserts co
|
|
|
35
43
|
* ### Example
|
|
36
44
|
*
|
|
37
45
|
* ```ts
|
|
38
|
-
* assertNonEmptyArray
|
|
39
|
-
*
|
|
46
|
+
* import { assertNonEmptyArray } from "@evolu/common";
|
|
47
|
+
*
|
|
48
|
+
* const values = [1, 2, 3];
|
|
49
|
+
* assertNonEmptyArray(values);
|
|
50
|
+
* expectTypeOf(values).toEqualTypeOf<[number, ...Array<number>]>();
|
|
51
|
+
* expect(values[0]).toBe(1);
|
|
52
|
+
* expect(() => assertNonEmptyArray([])).toThrow();
|
|
40
53
|
* ```
|
|
41
54
|
*/
|
|
42
55
|
export declare const assertNonEmptyArray: <T>(arr: Array<T>, message?: string) => asserts arr is [T, ...Array<T>];
|
|
@@ -50,42 +63,18 @@ export declare const assertNonEmptyArray: <T>(arr: Array<T>, message?: string) =
|
|
|
50
63
|
* ### Example
|
|
51
64
|
*
|
|
52
65
|
* ```ts
|
|
53
|
-
* assertNonEmptyReadonlyArray
|
|
54
|
-
*
|
|
66
|
+
* import { assertNonEmptyReadonlyArray } from "@evolu/common";
|
|
67
|
+
*
|
|
68
|
+
* const values: ReadonlyArray<number> = [1, 2, 3];
|
|
69
|
+
* assertNonEmptyReadonlyArray(values);
|
|
70
|
+
* expectTypeOf(values).toEqualTypeOf<
|
|
71
|
+
* readonly [number, ...Array<number>]
|
|
72
|
+
* >();
|
|
73
|
+
* expect(values[0]).toBe(1);
|
|
74
|
+
* expect(() => assertNonEmptyReadonlyArray([])).toThrow();
|
|
55
75
|
* ```
|
|
56
76
|
*/
|
|
57
77
|
export declare const assertNonEmptyReadonlyArray: <T>(arr: ReadonlyArray<T>, message?: string) => asserts arr is readonly [T, ...Array<T>];
|
|
58
|
-
/**
|
|
59
|
-
* Ensures a value conforms to a {@link Type}.
|
|
60
|
-
*
|
|
61
|
-
* Uses the Type name for the default error message.
|
|
62
|
-
*
|
|
63
|
-
* ### Example
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* const length = buffer.getLength();
|
|
67
|
-
*
|
|
68
|
-
* // We know length is logically non-negative, but TypeScript doesn't.
|
|
69
|
-
* assertType(NonNegativeInt, length);
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare const assertType: <T extends AnyType>(type: T, value: unknown, message?: string) => asserts value is InferType<T>;
|
|
73
|
-
/**
|
|
74
|
-
* Asserts that a {@link Result} did not fail with `AbortError`.
|
|
75
|
-
*
|
|
76
|
-
* Use when abort would indicate a programmer error rather than ordinary control
|
|
77
|
-
* flow.
|
|
78
|
-
*
|
|
79
|
-
* In general, abort is normal control flow. Stopping work and returning
|
|
80
|
-
* `AbortError` is the correct behavior when a `Run` or `Fiber` is cancelled.
|
|
81
|
-
*
|
|
82
|
-
* Use `assertNotAborted` only to protect invariants in code that has already
|
|
83
|
-
* decided abort must not happen, such as resource helpers built on
|
|
84
|
-
* `unabortable`. In those places it helps fail fast on mistakes, because
|
|
85
|
-
* TypeScript cannot fully enforce that lifecycle logic is correct.
|
|
86
|
-
*/
|
|
87
|
-
export declare function assertNotAborted<T>(result: Result<T, AbortError>, message?: string): asserts result is Ok<T>;
|
|
88
|
-
export declare function assertNotAborted<T, E>(result: Result<T, E | AbortError>, message?: string): asserts result is Result<T, E>;
|
|
89
78
|
/**
|
|
90
79
|
* Guards synchronous methods on objects that may be called after disposal.
|
|
91
80
|
*
|
|
@@ -94,11 +83,22 @@ export declare function assertNotAborted<T, E>(result: Result<T, E | AbortError>
|
|
|
94
83
|
* ### Example
|
|
95
84
|
*
|
|
96
85
|
* ```ts
|
|
97
|
-
*
|
|
98
|
-
*
|
|
86
|
+
* import { assertNotDisposed } from "@evolu/common";
|
|
87
|
+
*
|
|
88
|
+
* await using disposer = new globalThis.AsyncDisposableStack();
|
|
89
|
+
* expect(() => assertNotDisposed(disposer)).not.toThrow();
|
|
99
90
|
* await disposer.disposeAsync();
|
|
100
|
-
* assertNotDisposed(disposer)
|
|
91
|
+
* expect(() => assertNotDisposed(disposer)).toThrow(
|
|
92
|
+
* "Cannot use a disposed object.",
|
|
93
|
+
* );
|
|
101
94
|
* ```
|
|
95
|
+
*
|
|
96
|
+
* This is the JavaScript equivalent of the .NET `ObjectDisposedException`
|
|
97
|
+
* pattern: once a helper has been disposed, calling its synchronous methods is
|
|
98
|
+
* a programmer error and should throw immediately instead of continuing with
|
|
99
|
+
* invalid state.
|
|
102
100
|
*/
|
|
103
|
-
export declare const assertNotDisposed: (value: DisposableStack | AsyncDisposableStack
|
|
101
|
+
export declare const assertNotDisposed: (value: DisposableStack | AsyncDisposableStack | {
|
|
102
|
+
readonly disposed: boolean;
|
|
103
|
+
}) => void;
|
|
104
104
|
//# sourceMappingURL=Assert.d.ts.map
|
package/dist/src/Assert.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/Assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"Assert.d.ts","sourceRoot":"","sources":["../../src/Assert.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,MAAM,EAAE,CACnB,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,MAAM,KACZ,OAAO,CAAC,SAIZ,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,EAChC,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAKlC,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAClC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,EACb,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAKlC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,2BAA2B,EAAE,CAAC,CAAC,EAC1C,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,EACrB,OAAO,CAAC,EAAE,MAAM,KACb,OAAO,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAK3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,iBAAiB,UAE1B,eAAe,GAAG,oBAAoB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,KACxE,IAEF,CAAC"}
|
package/dist/src/Assert.js
CHANGED
|
@@ -17,8 +17,12 @@
|
|
|
17
17
|
* ### Example
|
|
18
18
|
*
|
|
19
19
|
* ```ts
|
|
20
|
-
* assert
|
|
21
|
-
*
|
|
20
|
+
* import { assert as assertInvariant } from "@evolu/common";
|
|
21
|
+
*
|
|
22
|
+
* expect(() => assertInvariant(true, "Expected true.")).not.toThrow();
|
|
23
|
+
* expect(() => assertInvariant(false, "Expected true.")).toThrow(
|
|
24
|
+
* "Expected true.",
|
|
25
|
+
* );
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
28
|
export const assert = (condition, message) => {
|
|
@@ -26,6 +30,15 @@ export const assert = (condition, message) => {
|
|
|
26
30
|
throw new Error(message);
|
|
27
31
|
}
|
|
28
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Asserts that a value is non-nullable.
|
|
35
|
+
*
|
|
36
|
+
* Narrows a nullable value to {@link NonNullable} when null or undefined is
|
|
37
|
+
* logically impossible but TypeScript cannot prove it.
|
|
38
|
+
*/
|
|
39
|
+
export const assertNonNullable = (value, message = "Expected value to be non-nullable.") => {
|
|
40
|
+
assert(value != null, message);
|
|
41
|
+
};
|
|
29
42
|
/**
|
|
30
43
|
* Asserts that an array is non-empty.
|
|
31
44
|
*
|
|
@@ -36,8 +49,13 @@ export const assert = (condition, message) => {
|
|
|
36
49
|
* ### Example
|
|
37
50
|
*
|
|
38
51
|
* ```ts
|
|
39
|
-
* assertNonEmptyArray
|
|
40
|
-
*
|
|
52
|
+
* import { assertNonEmptyArray } from "@evolu/common";
|
|
53
|
+
*
|
|
54
|
+
* const values = [1, 2, 3];
|
|
55
|
+
* assertNonEmptyArray(values);
|
|
56
|
+
* expectTypeOf(values).toEqualTypeOf<[number, ...Array<number>]>();
|
|
57
|
+
* expect(values[0]).toBe(1);
|
|
58
|
+
* expect(() => assertNonEmptyArray([])).toThrow();
|
|
41
59
|
* ```
|
|
42
60
|
*/
|
|
43
61
|
export const assertNonEmptyArray = (arr, message = "Expected a non-empty array.") => {
|
|
@@ -53,35 +71,20 @@ export const assertNonEmptyArray = (arr, message = "Expected a non-empty array."
|
|
|
53
71
|
* ### Example
|
|
54
72
|
*
|
|
55
73
|
* ```ts
|
|
56
|
-
* assertNonEmptyReadonlyArray
|
|
57
|
-
*
|
|
74
|
+
* import { assertNonEmptyReadonlyArray } from "@evolu/common";
|
|
75
|
+
*
|
|
76
|
+
* const values: ReadonlyArray<number> = [1, 2, 3];
|
|
77
|
+
* assertNonEmptyReadonlyArray(values);
|
|
78
|
+
* expectTypeOf(values).toEqualTypeOf<
|
|
79
|
+
* readonly [number, ...Array<number>]
|
|
80
|
+
* >();
|
|
81
|
+
* expect(values[0]).toBe(1);
|
|
82
|
+
* expect(() => assertNonEmptyReadonlyArray([])).toThrow();
|
|
58
83
|
* ```
|
|
59
84
|
*/
|
|
60
85
|
export const assertNonEmptyReadonlyArray = (arr, message = "Expected a non-empty readonly array.") => {
|
|
61
86
|
assert(arr.length > 0, message);
|
|
62
87
|
};
|
|
63
|
-
/**
|
|
64
|
-
* Ensures a value conforms to a {@link Type}.
|
|
65
|
-
*
|
|
66
|
-
* Uses the Type name for the default error message.
|
|
67
|
-
*
|
|
68
|
-
* ### Example
|
|
69
|
-
*
|
|
70
|
-
* ```ts
|
|
71
|
-
* const length = buffer.getLength();
|
|
72
|
-
*
|
|
73
|
-
* // We know length is logically non-negative, but TypeScript doesn't.
|
|
74
|
-
* assertType(NonNegativeInt, length);
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export const assertType = (type, value, message) => {
|
|
78
|
-
assert(type.is(value), message ?? `Expected ${type.name}.`);
|
|
79
|
-
};
|
|
80
|
-
export function assertNotAborted(result, message = "Expected result to not be aborted.") {
|
|
81
|
-
const isAbortError = !result.ok &&
|
|
82
|
-
result.error.type === "AbortError";
|
|
83
|
-
assert(!isAbortError, message);
|
|
84
|
-
}
|
|
85
88
|
/**
|
|
86
89
|
* Guards synchronous methods on objects that may be called after disposal.
|
|
87
90
|
*
|
|
@@ -90,12 +93,21 @@ export function assertNotAborted(result, message = "Expected result to not be ab
|
|
|
90
93
|
* ### Example
|
|
91
94
|
*
|
|
92
95
|
* ```ts
|
|
93
|
-
*
|
|
94
|
-
*
|
|
96
|
+
* import { assertNotDisposed } from "@evolu/common";
|
|
97
|
+
*
|
|
98
|
+
* await using disposer = new globalThis.AsyncDisposableStack();
|
|
99
|
+
* expect(() => assertNotDisposed(disposer)).not.toThrow();
|
|
95
100
|
* await disposer.disposeAsync();
|
|
96
|
-
* assertNotDisposed(disposer)
|
|
101
|
+
* expect(() => assertNotDisposed(disposer)).toThrow(
|
|
102
|
+
* "Cannot use a disposed object.",
|
|
103
|
+
* );
|
|
97
104
|
* ```
|
|
105
|
+
*
|
|
106
|
+
* This is the JavaScript equivalent of the .NET `ObjectDisposedException`
|
|
107
|
+
* pattern: once a helper has been disposed, calling its synchronous methods is
|
|
108
|
+
* a programmer error and should throw immediately instead of continuing with
|
|
109
|
+
* invalid state.
|
|
98
110
|
*/
|
|
99
111
|
export const assertNotDisposed = (value) => {
|
|
100
|
-
assert(!value.disposed, "
|
|
112
|
+
assert(!value.disposed, "Cannot use a disposed object.");
|
|
101
113
|
};
|
package/dist/src/BigInt.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { Predicate } from "./Types.
|
|
6
|
+
import type { Predicate } from "./Types.ts";
|
|
7
7
|
/** Increments a bigint by 1. */
|
|
8
8
|
export declare const incrementBigInt: (n: bigint) => bigint;
|
|
9
9
|
/** Decrements a bigint by 1. */
|
|
@@ -16,9 +16,12 @@ export declare const clampBigInt: (min: bigint, max: bigint) => (n: bigint) => b
|
|
|
16
16
|
* ### Example
|
|
17
17
|
*
|
|
18
18
|
* ```ts
|
|
19
|
+
* import { isBetweenBigInt } from "@evolu/common";
|
|
20
|
+
*
|
|
19
21
|
* const isBetween10And20 = isBetweenBigInt(10n, 20n);
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
*
|
|
23
|
+
* expect(isBetween10And20(20n)).toBe(true);
|
|
24
|
+
* expect(isBetween10And20(25n)).toBe(false);
|
|
22
25
|
* ```
|
|
23
26
|
*/
|
|
24
27
|
export declare const isBetweenBigInt: (min: bigint, max: bigint) => Predicate<bigint>;
|
package/dist/src/BigInt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BigInt.d.ts","sourceRoot":"","sources":["../../src/BigInt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,gCAAgC;AAChC,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"BigInt.d.ts","sourceRoot":"","sources":["../../src/BigInt.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,gCAAgC;AAChC,eAAO,MAAM,eAAe,MAAO,MAAM,KAAG,MAAgB,CAAC;AAE7D,gCAAgC;AAChC,eAAO,MAAM,eAAe,MAAO,MAAM,KAAG,MAAgB,CAAC;AAE7D,4CAA4C;AAC5C,eAAO,MAAM,WAAW,QAChB,MAAM,OAAO,MAAM,SACrB,MAAM,KAAG,MACsB,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,QACpB,MAAM,OAAO,MAAM,KAAG,SAAS,CAAC,MAAM,CAEd,CAAC"}
|
package/dist/src/BigInt.js
CHANGED
|
@@ -15,9 +15,12 @@ export const clampBigInt = (min, max) => (n) => n < min ? min : n > max ? max :
|
|
|
15
15
|
* ### Example
|
|
16
16
|
*
|
|
17
17
|
* ```ts
|
|
18
|
+
* import { isBetweenBigInt } from "@evolu/common";
|
|
19
|
+
*
|
|
18
20
|
* const isBetween10And20 = isBetweenBigInt(10n, 20n);
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
+
*
|
|
22
|
+
* expect(isBetween10And20(20n)).toBe(true);
|
|
23
|
+
* expect(isBetween10And20(25n)).toBe(false);
|
|
21
24
|
* ```
|
|
22
25
|
*/
|
|
23
26
|
export const isBetweenBigInt = (min, max) => (value) => value >= min && value <= max;
|