@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/Result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../src/Result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../src/Result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAmB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkXG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAEzC,mCAAmC;AACnC,MAAM,WAAW,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C,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAC9B,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EACnB,OAAO,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,GACnC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAoE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,SAAS,CACvB,KAAK,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,EACjE,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/src/Result.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Type-safe error handling with Result
|
|
2
|
+
* Type-safe error handling with the Result type.
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { emptyArray, isNonEmptyArray, } from "./Array.js";
|
|
7
7
|
import { assert } from "./Assert.js";
|
|
8
8
|
import { exhaustiveCheck } from "./Function.js";
|
|
9
|
-
import {
|
|
9
|
+
import { createMutableRecord, emptyRecord, isIterable } from "./Object.js";
|
|
10
10
|
export function ok(value) {
|
|
11
11
|
if (value === undefined)
|
|
12
12
|
return okVoid;
|
|
@@ -21,7 +21,7 @@ export const isOk = (result) => result.ok;
|
|
|
21
21
|
/** Type guard for {@link Err} results. */
|
|
22
22
|
export const isErr = (result) => !result.ok;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Gets the value from an `Ok` {@link Result}, or throws if it is an `Err`.
|
|
25
25
|
*
|
|
26
26
|
* Use this where failure should crash the current flow instead of being handled
|
|
27
27
|
* locally.
|
|
@@ -29,8 +29,8 @@ export const isErr = (result) => !result.ok;
|
|
|
29
29
|
* **When to use:**
|
|
30
30
|
*
|
|
31
31
|
* - Application startup or composition-root setup where errors must stop the
|
|
32
|
-
* program immediately. In Evolu apps,
|
|
33
|
-
*
|
|
32
|
+
* program immediately. In Evolu apps, the root Run reports the defect and the
|
|
33
|
+
* platform lifecycle API handles shutdown.
|
|
34
34
|
* - Module-level constants
|
|
35
35
|
* - Test setup with values that are expected to be valid
|
|
36
36
|
*
|
|
@@ -40,9 +40,30 @@ export const isErr = (result) => !result.ok;
|
|
|
40
40
|
* ### Example
|
|
41
41
|
*
|
|
42
42
|
* ```ts
|
|
43
|
-
*
|
|
43
|
+
* import { err, getOrThrow, ok, type Result } from "@evolu/common";
|
|
44
|
+
*
|
|
45
|
+
* interface Config {
|
|
46
|
+
* readonly port: number;
|
|
47
|
+
* }
|
|
48
|
+
* interface InvalidConfigError {
|
|
49
|
+
* readonly type: "InvalidConfigError";
|
|
50
|
+
* }
|
|
51
|
+
* const loadConfig = (): Result<Config, InvalidConfigError> =>
|
|
52
|
+
* ok({ port: 3000 });
|
|
53
|
+
*
|
|
54
|
+
* // At app startup, crash if the config is invalid.
|
|
44
55
|
* const config = getOrThrow(loadConfig());
|
|
45
|
-
*
|
|
56
|
+
* expectTypeOf(config).toEqualTypeOf<Config>();
|
|
57
|
+
* expect(config).toEqual({ port: 3000 });
|
|
58
|
+
*
|
|
59
|
+
* try {
|
|
60
|
+
* getOrThrow(err({ type: "InvalidConfigError" }));
|
|
61
|
+
* assert.fail("Expected getOrThrow to throw");
|
|
62
|
+
* } catch (error) {
|
|
63
|
+
* assert(error instanceof Error);
|
|
64
|
+
* expect(error.message).toBe("getOrThrow");
|
|
65
|
+
* expect(error.cause).toEqual({ type: "InvalidConfigError" });
|
|
66
|
+
* }
|
|
46
67
|
* ```
|
|
47
68
|
*
|
|
48
69
|
* Throws: `Error` with the original error attached as `cause`.
|
|
@@ -56,8 +77,8 @@ export const getOrThrow = (result) => {
|
|
|
56
77
|
}
|
|
57
78
|
};
|
|
58
79
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
80
|
+
* Gets the value from an `Ok` {@link Result}, or returns `null` if it is an
|
|
81
|
+
* `Err`.
|
|
61
82
|
*
|
|
62
83
|
* **Intended usage:**
|
|
63
84
|
*
|
|
@@ -68,142 +89,182 @@ export const getOrThrow = (result) => {
|
|
|
68
89
|
* ### Example
|
|
69
90
|
*
|
|
70
91
|
* ```ts
|
|
71
|
-
*
|
|
72
|
-
*
|
|
92
|
+
* import { err, getOrNull, ok, type Result } from "@evolu/common";
|
|
93
|
+
*
|
|
94
|
+
* interface User {
|
|
95
|
+
* readonly id: string;
|
|
96
|
+
* }
|
|
97
|
+
* interface UserNotFoundError {
|
|
98
|
+
* readonly type: "UserNotFoundError";
|
|
99
|
+
* }
|
|
100
|
+
* const findUser = (id: string): Result<User, UserNotFoundError> =>
|
|
101
|
+
* id === "user-1" ? ok({ id }) : err({ type: "UserNotFoundError" });
|
|
102
|
+
*
|
|
103
|
+
* // For APIs that expect T | null.
|
|
104
|
+
* const user = getOrNull(findUser("user-1"));
|
|
105
|
+
* const missingUser = getOrNull(findUser("missing"));
|
|
106
|
+
*
|
|
107
|
+
* expectTypeOf(user).toEqualTypeOf<User | null>();
|
|
108
|
+
* expect(user).toEqual({ id: "user-1" });
|
|
109
|
+
* expect(missingUser).toBeNull();
|
|
73
110
|
* ```
|
|
74
111
|
*/
|
|
75
112
|
export const getOrNull = (result) => result.ok ? result.value : null;
|
|
76
113
|
/**
|
|
77
|
-
*
|
|
114
|
+
* Gets the value from a {@link Result} whose error type is `never`.
|
|
78
115
|
*
|
|
79
116
|
* This is useful when the type system guarantees the result cannot fail (for
|
|
80
117
|
* example `Result<T, never>`), avoiding impossible `if (!result.ok)` branches
|
|
81
118
|
* at call sites.
|
|
82
|
-
*/
|
|
83
|
-
export const getOk = (result) => {
|
|
84
|
-
assert(result.ok, "Expected Ok result.");
|
|
85
|
-
return result.value;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Wraps a synchronous function that may throw, returning a {@link Result}.
|
|
89
|
-
*
|
|
90
|
-
* Use this when the thrown value should become a typed, recoverable error for
|
|
91
|
-
* the caller. Do not use it for failures that should terminate the current flow
|
|
92
|
-
* and propagate to a global handler.
|
|
93
119
|
*
|
|
94
120
|
* ### Example
|
|
95
121
|
*
|
|
96
122
|
* ```ts
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
123
|
+
* import { getOk, ok, type Result } from "@evolu/common";
|
|
124
|
+
*
|
|
125
|
+
* const getCount = (): Result<number> => ok(2);
|
|
126
|
+
* const count = getOk(getCount());
|
|
127
|
+
* expectTypeOf(count).toEqualTypeOf<number>();
|
|
128
|
+
* expect(count).toBe(2);
|
|
102
129
|
* ```
|
|
103
130
|
*/
|
|
104
|
-
export const
|
|
131
|
+
export const getOk = (result) => {
|
|
132
|
+
assert(result.ok, "Expected Ok result.");
|
|
133
|
+
return result.value;
|
|
134
|
+
};
|
|
135
|
+
export function trySync(fn, mapError) {
|
|
105
136
|
try {
|
|
106
137
|
return ok(fn());
|
|
107
138
|
}
|
|
108
139
|
catch (error) {
|
|
109
|
-
return err(mapError(error));
|
|
140
|
+
return err(mapError ? mapError(error) : error);
|
|
110
141
|
}
|
|
111
|
-
}
|
|
142
|
+
}
|
|
143
|
+
export async function tryAsync(promiseThunk, mapError) {
|
|
144
|
+
try {
|
|
145
|
+
return ok(await promiseThunk());
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return err(mapError ? mapError(error) : error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export function done(value) {
|
|
152
|
+
return {
|
|
153
|
+
type: "Done",
|
|
154
|
+
done: value,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
112
157
|
/**
|
|
113
|
-
*
|
|
158
|
+
* Composes a successful {@link Result} with another Result-returning operation.
|
|
159
|
+
*
|
|
160
|
+
* Returns the existing error without calling the operation when the Result has
|
|
161
|
+
* failed.
|
|
114
162
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* propagate to a global handler.
|
|
163
|
+
* Do not nest `flatMapResult`. For longer workflows, use explicit checks, which
|
|
164
|
+
* keep names, intermediate values, and control flow flat and easy to read.
|
|
118
165
|
*
|
|
119
166
|
* ### Example
|
|
120
167
|
*
|
|
121
168
|
* ```ts
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
169
|
+
* import { err, flatMapResult, ok, type Result } from "@evolu/common";
|
|
170
|
+
*
|
|
171
|
+
* interface User {
|
|
172
|
+
* readonly id: string;
|
|
173
|
+
* }
|
|
174
|
+
* interface UserError {
|
|
175
|
+
* readonly type: "UserError";
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* interface Profile {
|
|
179
|
+
* readonly userId: string;
|
|
180
|
+
* }
|
|
181
|
+
* interface ProfileError {
|
|
182
|
+
* readonly type: "ProfileError";
|
|
183
|
+
* }
|
|
184
|
+
* const getProfile = (userId: string): Result<Profile, ProfileError> =>
|
|
185
|
+
* ok({ userId });
|
|
186
|
+
*
|
|
187
|
+
* let getProfileCalls = 0;
|
|
188
|
+
* const getProfileForUser = (
|
|
189
|
+
* user: User,
|
|
190
|
+
* ): Result<Profile, ProfileError> => {
|
|
191
|
+
* getProfileCalls++;
|
|
192
|
+
* return getProfile(user.id);
|
|
193
|
+
* };
|
|
194
|
+
*
|
|
195
|
+
* const user: Result<User, UserError> = ok({ id: "user-1" });
|
|
196
|
+
* const profile = flatMapResult(user, getProfileForUser);
|
|
197
|
+
* expectTypeOf(profile).toEqualTypeOf<
|
|
198
|
+
* Result<Profile, UserError | ProfileError>
|
|
199
|
+
* >();
|
|
200
|
+
* expectOk(profile, { userId: "user-1" });
|
|
201
|
+
* expect(getProfileCalls).toBe(1);
|
|
202
|
+
*
|
|
203
|
+
* const missingUser: Result<User, UserError> = err({ type: "UserError" });
|
|
204
|
+
* const missingProfile = flatMapResult(missingUser, getProfileForUser);
|
|
205
|
+
* expectErr(missingProfile, { type: "UserError" });
|
|
206
|
+
* expect(getProfileCalls).toBe(1);
|
|
131
207
|
* ```
|
|
208
|
+
*
|
|
209
|
+
* @group Composition
|
|
132
210
|
*/
|
|
133
|
-
export const
|
|
134
|
-
export function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
211
|
+
export const flatMapResult = (result, fn) => (result.ok ? fn(result.value) : result);
|
|
212
|
+
export function allResult(input, fnOrOptions, options) {
|
|
213
|
+
const fn = typeof fnOrOptions === "function" ? fnOrOptions : undefined;
|
|
214
|
+
const collect = typeof fnOrOptions === "function"
|
|
215
|
+
? options?.collect !== false
|
|
216
|
+
: fnOrOptions?.collect !== false;
|
|
217
|
+
if (!collect) {
|
|
218
|
+
if (isIterable(input)) {
|
|
219
|
+
for (const value of input) {
|
|
220
|
+
const result = fn ? fn(value) : value;
|
|
221
|
+
if (!result.ok)
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
return ok();
|
|
225
|
+
}
|
|
226
|
+
const keys = Object.keys(input);
|
|
227
|
+
for (const key of keys) {
|
|
228
|
+
const value = input[key];
|
|
229
|
+
const result = fn ? fn(value) : value;
|
|
230
|
+
if (!result.ok)
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
return ok();
|
|
234
|
+
}
|
|
235
|
+
if (Array.isArray(input)) {
|
|
236
|
+
const length = input.length;
|
|
237
|
+
if (length === 0)
|
|
144
238
|
return ok(emptyArray);
|
|
145
|
-
const length = array.length;
|
|
146
239
|
const values = new Array(length);
|
|
147
240
|
for (let i = 0; i < length; i++) {
|
|
148
|
-
const result =
|
|
241
|
+
const result = fn ? fn(input[i]) : input[i];
|
|
149
242
|
if (!result.ok)
|
|
150
243
|
return result;
|
|
151
244
|
values[i] = result.value;
|
|
152
245
|
}
|
|
153
246
|
return ok(values);
|
|
154
247
|
}
|
|
155
|
-
const length = Object.keys(input).length;
|
|
156
|
-
if (length === 0)
|
|
157
|
-
return ok(emptyRecord);
|
|
158
|
-
const keys = new Array(length);
|
|
159
|
-
const results = new Array(length);
|
|
160
|
-
let index = 0;
|
|
161
|
-
for (const key in input) {
|
|
162
|
-
keys[index] = key;
|
|
163
|
-
results[index] = input[key];
|
|
164
|
-
index++;
|
|
165
|
-
}
|
|
166
|
-
const record = createRecord();
|
|
167
|
-
for (let i = 0; i < length; i++) {
|
|
168
|
-
const result = results[i];
|
|
169
|
-
if (!result.ok)
|
|
170
|
-
return result;
|
|
171
|
-
record[keys[i]] = result.value;
|
|
172
|
-
}
|
|
173
|
-
return ok(record);
|
|
174
|
-
}
|
|
175
|
-
export function mapResult(input, fn) {
|
|
176
248
|
if (isIterable(input)) {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const length = array.length;
|
|
181
|
-
const values = new Array(length);
|
|
182
|
-
for (let i = 0; i < length; i++) {
|
|
183
|
-
const result = fn(array[i]);
|
|
249
|
+
const values = [];
|
|
250
|
+
for (const value of input) {
|
|
251
|
+
const result = fn ? fn(value) : value;
|
|
184
252
|
if (!result.ok)
|
|
185
253
|
return result;
|
|
186
|
-
values
|
|
254
|
+
values.push(result.value);
|
|
187
255
|
}
|
|
188
|
-
return ok(values);
|
|
256
|
+
return ok(values.length === 0 ? emptyArray : values);
|
|
189
257
|
}
|
|
190
|
-
const
|
|
191
|
-
if (length === 0)
|
|
258
|
+
const keys = Object.keys(input);
|
|
259
|
+
if (keys.length === 0)
|
|
192
260
|
return ok(emptyRecord);
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
keys[index] = key;
|
|
198
|
-
items[index] = input[key];
|
|
199
|
-
index++;
|
|
200
|
-
}
|
|
201
|
-
const record = createRecord();
|
|
202
|
-
for (let i = 0; i < length; i++) {
|
|
203
|
-
const result = fn(items[i]);
|
|
261
|
+
const record = createMutableRecord();
|
|
262
|
+
for (const key of keys) {
|
|
263
|
+
const value = input[key];
|
|
264
|
+
const result = fn ? fn(value) : value;
|
|
204
265
|
if (!result.ok)
|
|
205
266
|
return result;
|
|
206
|
-
record[
|
|
267
|
+
record[key] = result.value;
|
|
207
268
|
}
|
|
208
269
|
return ok(record);
|
|
209
270
|
}
|