@evolu/common 7.4.0 → 8.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -61
- package/dist/src/Array.d.ts +343 -102
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +181 -85
- package/dist/src/Assert.d.ts +57 -11
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +47 -11
- package/dist/src/BigInt.d.ts +6 -1
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -0
- package/dist/src/Brand.d.ts +40 -12
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Brand.js +5 -0
- package/dist/src/Buffer.d.ts +6 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +7 -2
- package/dist/src/Cache.d.ts +10 -2
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +6 -0
- package/dist/src/Callbacks.d.ts +10 -7
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +23 -13
- package/dist/src/Console.d.ts +361 -69
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +217 -117
- package/dist/src/Crypto.d.ts +70 -21
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +72 -27
- package/dist/src/Eq.d.ts +22 -2
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +21 -1
- package/dist/src/Error.d.ts +23 -12
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +27 -11
- package/dist/src/Function.d.ts +128 -56
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +118 -14
- package/dist/src/Identicon.d.ts +5 -0
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +6 -1
- package/dist/src/Lookup.d.ts +160 -0
- package/dist/src/Lookup.d.ts.map +1 -0
- package/dist/src/Lookup.js +192 -0
- package/dist/src/Microtask.d.ts +21 -0
- package/dist/src/Microtask.d.ts.map +1 -0
- package/dist/src/Microtask.js +37 -0
- package/dist/src/Number.d.ts +18 -4
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +23 -1
- package/dist/src/Object.d.ts +110 -5
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +108 -5
- package/dist/src/Option.d.ts +58 -0
- package/dist/src/Option.d.ts.map +1 -0
- package/dist/src/Option.js +43 -0
- package/dist/src/Order.d.ts +5 -0
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +8 -3
- package/dist/src/Platform.d.ts +36 -2
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +10 -6
- package/dist/src/Polyfills.d.ts +27 -0
- package/dist/src/Polyfills.d.ts.map +1 -0
- package/dist/src/Polyfills.js +299 -0
- package/dist/src/Random.d.ts +18 -7
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +9 -7
- package/dist/src/Redacted.d.ts +7 -4
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +5 -0
- package/dist/src/Ref.d.ts +31 -16
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +35 -7
- package/dist/src/RefCount.d.ts +62 -0
- package/dist/src/RefCount.d.ts.map +1 -0
- package/dist/src/RefCount.js +83 -0
- package/dist/src/Relation.d.ts +84 -29
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +83 -105
- package/dist/src/Resource.d.ts +263 -0
- package/dist/src/Resource.d.ts.map +1 -0
- package/dist/src/Resource.js +389 -0
- package/dist/src/Result.d.ts +390 -374
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +142 -70
- package/dist/src/Schedule.d.ts +953 -0
- package/dist/src/Schedule.d.ts.map +1 -0
- package/dist/src/Schedule.js +1199 -0
- package/dist/src/Set.d.ts +181 -0
- package/dist/src/Set.d.ts.map +1 -0
- package/dist/src/Set.js +137 -0
- package/dist/src/Skiplist.d.ts +6 -1
- package/dist/src/Skiplist.d.ts.map +1 -1
- package/dist/src/Skiplist.js +5 -0
- package/dist/src/Sqlite.d.ts +160 -60
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +290 -190
- package/dist/src/Store.d.ts +36 -28
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +55 -15
- package/dist/src/String.d.ts +5 -0
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +5 -0
- package/dist/src/Task.d.ts +2263 -423
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1488 -348
- package/dist/src/Test.d.ts +122 -0
- package/dist/src/Test.d.ts.map +1 -0
- package/dist/src/Test.js +66 -0
- package/dist/src/Time.d.ts +201 -48
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +190 -86
- package/dist/src/Tracer.d.ts +48 -0
- package/dist/src/Tracer.d.ts.map +1 -0
- package/dist/src/Tracer.js +6 -0
- package/dist/src/Type.d.ts +582 -209
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +362 -240
- package/dist/src/Types.d.ts +160 -6
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +22 -2
- package/dist/src/WebSocket.d.ts +113 -58
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +210 -118
- package/dist/src/Worker.d.ts +245 -60
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +220 -64
- package/dist/src/index.d.ts +25 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +19 -3
- package/dist/src/local-first/Db.d.ts +24 -213
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +622 -293
- package/dist/src/local-first/Error.d.ts +12 -0
- package/dist/src/local-first/Error.d.ts.map +1 -0
- package/dist/src/local-first/Error.js +6 -0
- package/dist/src/local-first/Evolu.d.ts +330 -285
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +472 -402
- package/dist/src/local-first/LocalAuth.d.ts +10 -10
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/LocalAuth.js +6 -1
- package/dist/src/local-first/Owner.d.ts +70 -27
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +27 -14
- package/dist/src/local-first/Protocol.d.ts +58 -50
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +253 -155
- package/dist/src/local-first/Query.d.ts +133 -43
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +139 -90
- package/dist/src/local-first/Relay.d.ts +18 -38
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Relay.js +59 -171
- package/dist/src/local-first/Schema.d.ts +139 -144
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +78 -163
- package/dist/src/local-first/Shared.d.ts +125 -0
- package/dist/src/local-first/Shared.d.ts.map +1 -0
- package/dist/src/local-first/Shared.js +569 -0
- package/dist/src/local-first/Storage.d.ts +50 -53
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +121 -173
- package/dist/src/local-first/Timestamp.d.ts +28 -35
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +24 -25
- package/dist/src/local-first/index.d.ts +2 -15
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +2 -15
- package/package.json +36 -26
- package/src/Array.ts +467 -106
- package/src/Assert.ts +87 -12
- package/src/BigInt.ts +7 -1
- package/src/Brand.ts +41 -12
- package/src/Buffer.ts +10 -4
- package/src/Cache.ts +11 -2
- package/src/Callbacks.ts +33 -23
- package/src/Console.ts +567 -178
- package/src/Crypto.ts +111 -62
- package/src/Eq.ts +30 -3
- package/src/Error.ts +50 -34
- package/src/Function.ts +140 -68
- package/src/Identicon.ts +7 -1
- package/src/Lookup.ts +415 -0
- package/src/Microtask.ts +58 -0
- package/src/Number.ts +40 -7
- package/src/Object.ts +155 -16
- package/src/Option.ts +74 -0
- package/src/Order.ts +11 -3
- package/src/Platform.ts +43 -7
- package/src/Polyfills.ts +465 -0
- package/src/Random.ts +25 -11
- package/src/Redacted.ts +8 -4
- package/src/Ref.ts +72 -21
- package/src/RefCount.ts +170 -0
- package/src/Relation.ts +188 -136
- package/src/Resource.ts +864 -0
- package/src/Result.ts +548 -381
- package/src/Schedule.ts +1471 -0
- package/src/Set.ts +247 -0
- package/src/Skiplist.ts +7 -1
- package/src/Sqlite.ts +409 -304
- package/src/Store.ts +94 -48
- package/src/String.ts +6 -0
- package/src/Task.ts +3685 -740
- package/src/Test.ts +162 -0
- package/src/Time.ts +348 -145
- package/src/Tracer.ts +54 -0
- package/src/Type.ts +1064 -630
- package/src/Types.ts +202 -7
- package/src/WebSocket.ts +311 -178
- package/src/Worker.ts +527 -147
- package/src/index.ts +74 -3
- package/src/local-first/Db.ts +871 -597
- package/src/local-first/Error.ts +17 -0
- package/src/local-first/Evolu.ts +884 -823
- package/src/local-first/LocalAuth.ts +10 -10
- package/src/local-first/Owner.ts +94 -42
- package/src/local-first/Protocol.ts +440 -303
- package/src/local-first/Query.ts +243 -194
- package/src/local-first/Relay.ts +91 -252
- package/src/local-first/Schema.ts +284 -394
- package/src/local-first/Shared.ts +932 -0
- package/src/local-first/Storage.ts +209 -282
- package/src/local-first/Timestamp.ts +38 -45
- package/src/local-first/index.ts +2 -16
- package/LICENSE +0 -21
- package/dist/src/Instances.d.ts +0 -34
- package/dist/src/Instances.d.ts.map +0 -1
- package/dist/src/Instances.js +0 -44
- package/dist/src/Resources.d.ts +0 -118
- package/dist/src/Resources.d.ts.map +0 -1
- package/dist/src/Resources.js +0 -197
- package/dist/src/local-first/Platform.d.ts +0 -25
- package/dist/src/local-first/Platform.d.ts.map +0 -1
- package/dist/src/local-first/Platform.js +0 -1
- package/dist/src/local-first/Public.d.ts +0 -22
- package/dist/src/local-first/Public.d.ts.map +0 -1
- package/dist/src/local-first/Public.js +0 -15
- package/dist/src/local-first/PublicKysely.d.ts +0 -148
- package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
- package/dist/src/local-first/PublicKysely.js +0 -184
- package/dist/src/local-first/Sync.d.ts +0 -112
- package/dist/src/local-first/Sync.d.ts.map +0 -1
- package/dist/src/local-first/Sync.js +0 -529
- package/src/Instances.ts +0 -90
- package/src/Resources.ts +0 -367
- package/src/local-first/Platform.ts +0 -27
- package/src/local-first/Public.ts +0 -42
- package/src/local-first/PublicKysely.ts +0 -239
- package/src/local-first/Sync.ts +0 -960
package/dist/src/Result.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../src/Result.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Result.d.ts","sourceRoot":"","sources":["../../src/Result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkNG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC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,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE/B;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,MAAM,EACjD,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAC7B,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACzB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAyCrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;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,27 +1,41 @@
|
|
|
1
|
-
export function ok(value = undefined) {
|
|
2
|
-
return { ok: true, value: value };
|
|
3
|
-
}
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* ### Example
|
|
2
|
+
* Type-safe error handling with Result types.
|
|
8
3
|
*
|
|
9
|
-
*
|
|
10
|
-
* const failure = err("Something went wrong");
|
|
11
|
-
* console.log(failure); // { ok: false, error: "Something went wrong" }
|
|
12
|
-
* ```
|
|
4
|
+
* @module
|
|
13
5
|
*/
|
|
6
|
+
import { arrayFrom, emptyArray, isNonEmptyArray, } from "./Array.js";
|
|
7
|
+
import { assert } from "./Assert.js";
|
|
8
|
+
import { exhaustiveCheck } from "./Function.js";
|
|
9
|
+
import { createRecord, emptyRecord, isIterable } from "./Object.js";
|
|
10
|
+
export function ok(value) {
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
return okVoid;
|
|
13
|
+
return { ok: true, value: value };
|
|
14
|
+
}
|
|
15
|
+
/** Cache ok() and ok(undefined) to avoid repeated allocations. */
|
|
16
|
+
const okVoid = { ok: true, value: undefined };
|
|
17
|
+
/** Creates an {@link Err} result. */
|
|
14
18
|
export const err = (error) => ({ ok: false, error });
|
|
19
|
+
/** Type guard for {@link Ok} results. */
|
|
20
|
+
export const isOk = (result) => result.ok;
|
|
21
|
+
/** Type guard for {@link Err} results. */
|
|
22
|
+
export const isErr = (result) => !result.ok;
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
17
|
-
* if it is an `Err`.
|
|
24
|
+
* Returns the value from an `Ok` {@link Result}, or throws if it is an `Err`.
|
|
18
25
|
*
|
|
19
|
-
*
|
|
26
|
+
* Use this where failure should crash the current flow instead of being handled
|
|
27
|
+
* locally.
|
|
28
|
+
*
|
|
29
|
+
* **When to use:**
|
|
30
|
+
*
|
|
31
|
+
* - Application startup or composition-root setup where errors must stop the
|
|
32
|
+
* program immediately. In Evolu apps, errors are handled by platform-specific
|
|
33
|
+
* `createRun` adapters at the app boundary.
|
|
34
|
+
* - Module-level constants
|
|
35
|
+
* - Test setup with values that are expected to be valid
|
|
20
36
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* - Not recommended for general error handling in application logic—prefer
|
|
24
|
-
* explicit checks.
|
|
37
|
+
* Prefer an explicit `if (!result.ok)` check in ordinary application logic
|
|
38
|
+
* where the caller can recover, retry, or choose a different flow.
|
|
25
39
|
*
|
|
26
40
|
* ### Example
|
|
27
41
|
*
|
|
@@ -54,40 +68,36 @@ export const getOrThrow = (result) => {
|
|
|
54
68
|
* ### Example
|
|
55
69
|
*
|
|
56
70
|
* ```ts
|
|
57
|
-
*
|
|
58
|
-
* const
|
|
59
|
-
* // value is unknown | null
|
|
60
|
-
*
|
|
61
|
-
* if (value != null) {
|
|
62
|
-
* console.log("Parsed value:", value);
|
|
63
|
-
* }
|
|
71
|
+
* // For APIs that expect T | null
|
|
72
|
+
* const user = getOrNull(findUser(id));
|
|
64
73
|
* ```
|
|
65
74
|
*/
|
|
66
75
|
export const getOrNull = (result) => result.ok ? result.value : null;
|
|
67
76
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
77
|
+
* Extracts the value from a {@link Result} whose error type is `never`.
|
|
78
|
+
*
|
|
79
|
+
* This is useful when the type system guarantees the result cannot fail (for
|
|
80
|
+
* example `Result<T, never>`), avoiding impossible `if (!result.ok)` branches
|
|
81
|
+
* 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}.
|
|
70
89
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* custom type and returns an `Err` result.
|
|
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.
|
|
75
93
|
*
|
|
76
94
|
* ### Example
|
|
77
95
|
*
|
|
78
96
|
* ```ts
|
|
79
|
-
* interface ParseJsonError {
|
|
80
|
-
* readonly type: "ParseJsonError";
|
|
81
|
-
* readonly message: string;
|
|
82
|
-
* }
|
|
83
|
-
*
|
|
84
97
|
* const parseJson = (value: string): Result<unknown, ParseJsonError> =>
|
|
85
98
|
* trySync(
|
|
86
99
|
* () => JSON.parse(value) as unknown,
|
|
87
|
-
* (error): ParseJsonError
|
|
88
|
-
* type: "ParseJsonError",
|
|
89
|
-
* message: String(error),
|
|
90
|
-
* }),
|
|
100
|
+
* (error) => ({ type: "ParseJsonError", message: String(error) }),
|
|
91
101
|
* );
|
|
92
102
|
* ```
|
|
93
103
|
*/
|
|
@@ -100,47 +110,109 @@ export const trySync = (fn, mapError) => {
|
|
|
100
110
|
}
|
|
101
111
|
};
|
|
102
112
|
/**
|
|
103
|
-
* Wraps async
|
|
104
|
-
* {@link Result}.
|
|
113
|
+
* Wraps an async function that may throw, returning a {@link Result}.
|
|
105
114
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* the error and returns an `Err` result.
|
|
115
|
+
* Use this when the rejection should become a typed, recoverable error for the
|
|
116
|
+
* caller. Do not use it for failures that should terminate the current flow and
|
|
117
|
+
* propagate to a global handler.
|
|
110
118
|
*
|
|
111
119
|
* ### Example
|
|
112
120
|
*
|
|
113
121
|
* ```ts
|
|
114
|
-
*
|
|
115
|
-
* readonly type: "FetchError";
|
|
116
|
-
* readonly message: string;
|
|
117
|
-
* }
|
|
118
|
-
*
|
|
119
|
-
* const tryFetch = async (
|
|
120
|
-
* url: string,
|
|
121
|
-
* ): Promise<Result<unknown, FetchError>> =>
|
|
122
|
+
* const fetchJson = (url: string): Promise<Result<unknown, FetchError>> =>
|
|
122
123
|
* tryAsync(
|
|
123
124
|
* async () => {
|
|
124
125
|
* const response = await fetch(url);
|
|
125
|
-
* if (!response.ok) {
|
|
126
|
-
* throw new Error(`Request failed with status ${response.status}`);
|
|
127
|
-
* }
|
|
126
|
+
* if (!response.ok) throw new Error(`Status ${response.status}`);
|
|
128
127
|
* return response.json();
|
|
129
128
|
* },
|
|
130
|
-
* (error) => ({
|
|
131
|
-
* type: "FetchError",
|
|
132
|
-
* message: String(error),
|
|
133
|
-
* }),
|
|
129
|
+
* (error) => ({ type: "FetchError", message: String(error) }),
|
|
134
130
|
* );
|
|
135
|
-
*
|
|
136
|
-
* const result = await tryFetch(
|
|
137
|
-
* "https://jsonplaceholder.typicode.com/posts/1",
|
|
138
|
-
* );
|
|
139
|
-
* if (result.ok) {
|
|
140
|
-
* console.log("Data:", result.value);
|
|
141
|
-
* } else {
|
|
142
|
-
* console.error("Error:", result.error);
|
|
143
|
-
* }
|
|
144
131
|
* ```
|
|
145
132
|
*/
|
|
146
|
-
export const tryAsync =
|
|
133
|
+
export const tryAsync = (lazyPromise, mapError) => Promise.try(lazyPromise).then((value) => ok(value), (error) => err(mapError(error)));
|
|
134
|
+
export function done(value) {
|
|
135
|
+
return {
|
|
136
|
+
type: "Done",
|
|
137
|
+
done: value,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export function allResult(input) {
|
|
141
|
+
if (isIterable(input)) {
|
|
142
|
+
const array = arrayFrom(input);
|
|
143
|
+
if (!isNonEmptyArray(array))
|
|
144
|
+
return ok(emptyArray);
|
|
145
|
+
const length = array.length;
|
|
146
|
+
const values = new Array(length);
|
|
147
|
+
for (let i = 0; i < length; i++) {
|
|
148
|
+
const result = array[i];
|
|
149
|
+
if (!result.ok)
|
|
150
|
+
return result;
|
|
151
|
+
values[i] = result.value;
|
|
152
|
+
}
|
|
153
|
+
return ok(values);
|
|
154
|
+
}
|
|
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
|
+
if (isIterable(input)) {
|
|
177
|
+
const array = arrayFrom(input);
|
|
178
|
+
if (!isNonEmptyArray(array))
|
|
179
|
+
return ok(emptyArray);
|
|
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]);
|
|
184
|
+
if (!result.ok)
|
|
185
|
+
return result;
|
|
186
|
+
values[i] = result.value;
|
|
187
|
+
}
|
|
188
|
+
return ok(values);
|
|
189
|
+
}
|
|
190
|
+
const length = Object.keys(input).length;
|
|
191
|
+
if (length === 0)
|
|
192
|
+
return ok(emptyRecord);
|
|
193
|
+
const keys = new Array(length);
|
|
194
|
+
const items = new Array(length);
|
|
195
|
+
let index = 0;
|
|
196
|
+
for (const key in input) {
|
|
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]);
|
|
204
|
+
if (!result.ok)
|
|
205
|
+
return result;
|
|
206
|
+
record[keys[i]] = result.value;
|
|
207
|
+
}
|
|
208
|
+
return ok(record);
|
|
209
|
+
}
|
|
210
|
+
export function anyResult(results) {
|
|
211
|
+
let lastError = null;
|
|
212
|
+
for (const result of results) {
|
|
213
|
+
if (result.ok)
|
|
214
|
+
return result;
|
|
215
|
+
lastError = result;
|
|
216
|
+
}
|
|
217
|
+
return lastError;
|
|
218
|
+
}
|