@evolu/common 8.5.0 → 8.6.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 +170 -97
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +67 -42
- package/dist/src/Assert.d.ts +233 -30
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +150 -30
- package/dist/src/BigInt.d.ts +3 -3
- package/dist/src/BigInt.js +3 -3
- package/dist/src/Brand.d.ts +7 -7
- package/dist/src/Buffer.d.ts +12 -4
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Cache.d.ts +8 -3
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +8 -3
- package/dist/src/Callbacks.d.ts +8 -4
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Console.d.ts +45 -30
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +32 -21
- package/dist/src/Crypto.d.ts +13 -8
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +6 -3
- package/dist/src/Eq.d.ts +107 -58
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +308 -112
- package/dist/src/Function.d.ts +54 -24
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +34 -17
- package/dist/src/Http.d.ts +52 -19
- package/dist/src/Http.d.ts.map +1 -1
- package/dist/src/Identicon.d.ts +9 -4
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +9 -4
- package/dist/src/LockManager.d.ts +12 -10
- package/dist/src/LockManager.d.ts.map +1 -1
- package/dist/src/Lookup.d.ts +4 -2
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +4 -2
- package/dist/src/Number.d.ts +28 -24
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +16 -17
- package/dist/src/Object.d.ts +89 -47
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +88 -41
- package/dist/src/Option.d.ts +14 -5
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +14 -5
- package/dist/src/Order.d.ts +12 -12
- package/dist/src/Order.js +12 -12
- package/dist/src/Platform.d.ts +2 -2
- package/dist/src/Random.d.ts +7 -4
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Redacted.d.ts +13 -6
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +4 -2
- package/dist/src/Ref.d.ts +4 -4
- package/dist/src/Relation.d.ts +5 -7
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Resource.d.ts +27 -12
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Result.d.ts +258 -114
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +71 -34
- package/dist/src/Schedule.d.ts +233 -116
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/Schedule.js +204 -110
- package/dist/src/Set.d.ts +43 -24
- package/dist/src/Set.d.ts.map +1 -1
- package/dist/src/Set.js +25 -13
- package/dist/src/Sqlite.d.ts +4 -4
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +9 -8
- package/dist/src/Task.d.ts +441 -212
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +238 -115
- package/dist/src/Test.d.ts +10 -4
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +10 -4
- package/dist/src/Time.d.ts +27 -17
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +16 -6
- package/dist/src/Type.d.ts +1096 -387
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1046 -372
- package/dist/src/Types.d.ts +95 -40
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +13 -4
- package/dist/src/WebSocket.d.ts +14 -6
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/Worker.d.ts +10 -6
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/intl/_en.d.ts +3 -1
- package/dist/src/intl/_en.d.ts.map +1 -1
- package/dist/src/intl/_en.js +17 -3
- package/dist/src/intl/ar.d.ts +3 -1
- package/dist/src/intl/ar.d.ts.map +1 -1
- package/dist/src/intl/ar.js +15 -2
- package/dist/src/intl/bn.d.ts +3 -1
- package/dist/src/intl/bn.d.ts.map +1 -1
- package/dist/src/intl/bn.js +16 -3
- package/dist/src/intl/ca.d.ts +3 -1
- package/dist/src/intl/ca.d.ts.map +1 -1
- package/dist/src/intl/ca.js +16 -3
- package/dist/src/intl/cs.d.ts +3 -1
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +16 -3
- package/dist/src/intl/da.d.ts +3 -1
- package/dist/src/intl/da.d.ts.map +1 -1
- package/dist/src/intl/da.js +16 -3
- package/dist/src/intl/de.d.ts +3 -1
- package/dist/src/intl/de.d.ts.map +1 -1
- package/dist/src/intl/de.js +16 -3
- package/dist/src/intl/el.d.ts +3 -1
- package/dist/src/intl/el.d.ts.map +1 -1
- package/dist/src/intl/el.js +16 -3
- package/dist/src/intl/es.d.ts +3 -1
- package/dist/src/intl/es.d.ts.map +1 -1
- package/dist/src/intl/es.js +16 -3
- package/dist/src/intl/fa.d.ts +3 -1
- package/dist/src/intl/fa.d.ts.map +1 -1
- package/dist/src/intl/fa.js +16 -3
- package/dist/src/intl/fi.d.ts +3 -1
- package/dist/src/intl/fi.d.ts.map +1 -1
- package/dist/src/intl/fi.js +16 -3
- package/dist/src/intl/fil.d.ts +3 -1
- package/dist/src/intl/fil.d.ts.map +1 -1
- package/dist/src/intl/fil.js +16 -3
- package/dist/src/intl/fr.d.ts +3 -1
- package/dist/src/intl/fr.d.ts.map +1 -1
- package/dist/src/intl/fr.js +16 -3
- package/dist/src/intl/he.d.ts +3 -1
- package/dist/src/intl/he.d.ts.map +1 -1
- package/dist/src/intl/he.js +16 -3
- package/dist/src/intl/hi.d.ts +3 -1
- package/dist/src/intl/hi.d.ts.map +1 -1
- package/dist/src/intl/hi.js +16 -3
- package/dist/src/intl/hr.d.ts +3 -1
- package/dist/src/intl/hr.d.ts.map +1 -1
- package/dist/src/intl/hr.js +16 -3
- package/dist/src/intl/hu.d.ts +2 -1
- package/dist/src/intl/hu.d.ts.map +1 -1
- package/dist/src/intl/hu.js +15 -3
- package/dist/src/intl/id.d.ts +3 -1
- package/dist/src/intl/id.d.ts.map +1 -1
- package/dist/src/intl/id.js +16 -3
- package/dist/src/intl/it.d.ts +3 -1
- package/dist/src/intl/it.d.ts.map +1 -1
- package/dist/src/intl/it.js +16 -3
- package/dist/src/intl/ja.d.ts +3 -1
- package/dist/src/intl/ja.d.ts.map +1 -1
- package/dist/src/intl/ja.js +16 -3
- package/dist/src/intl/ko.d.ts +3 -1
- package/dist/src/intl/ko.d.ts.map +1 -1
- package/dist/src/intl/ko.js +16 -3
- package/dist/src/intl/ml.d.ts +3 -1
- package/dist/src/intl/ml.d.ts.map +1 -1
- package/dist/src/intl/ml.js +16 -3
- package/dist/src/intl/mr.d.ts +3 -1
- package/dist/src/intl/mr.d.ts.map +1 -1
- package/dist/src/intl/mr.js +16 -3
- package/dist/src/intl/ms.d.ts +3 -1
- package/dist/src/intl/ms.d.ts.map +1 -1
- package/dist/src/intl/ms.js +15 -2
- package/dist/src/intl/nb.d.ts +2 -1
- package/dist/src/intl/nb.d.ts.map +1 -1
- package/dist/src/intl/nb.js +14 -2
- package/dist/src/intl/nl.d.ts +3 -1
- package/dist/src/intl/nl.d.ts.map +1 -1
- package/dist/src/intl/nl.js +16 -3
- package/dist/src/intl/pa.d.ts +3 -1
- package/dist/src/intl/pa.d.ts.map +1 -1
- package/dist/src/intl/pa.js +16 -3
- package/dist/src/intl/pl.d.ts +2 -0
- package/dist/src/intl/pl.d.ts.map +1 -1
- package/dist/src/intl/pl.js +15 -2
- package/dist/src/intl/pt-BR.d.ts +3 -1
- package/dist/src/intl/pt-BR.d.ts.map +1 -1
- package/dist/src/intl/pt-BR.js +16 -3
- package/dist/src/intl/pt.d.ts +3 -1
- package/dist/src/intl/pt.d.ts.map +1 -1
- package/dist/src/intl/pt.js +15 -2
- package/dist/src/intl/ro.d.ts +3 -1
- package/dist/src/intl/ro.d.ts.map +1 -1
- package/dist/src/intl/ro.js +16 -3
- package/dist/src/intl/sk.d.ts +3 -1
- package/dist/src/intl/sk.d.ts.map +1 -1
- package/dist/src/intl/sk.js +15 -2
- package/dist/src/intl/sl.d.ts +3 -1
- package/dist/src/intl/sl.d.ts.map +1 -1
- package/dist/src/intl/sl.js +16 -3
- package/dist/src/intl/sv.d.ts +3 -1
- package/dist/src/intl/sv.d.ts.map +1 -1
- package/dist/src/intl/sv.js +16 -3
- package/dist/src/intl/sw.d.ts +1 -0
- package/dist/src/intl/sw.d.ts.map +1 -1
- package/dist/src/intl/sw.js +14 -2
- package/dist/src/intl/ta.d.ts +3 -1
- package/dist/src/intl/ta.d.ts.map +1 -1
- package/dist/src/intl/ta.js +16 -3
- package/dist/src/intl/te.d.ts +3 -1
- package/dist/src/intl/te.d.ts.map +1 -1
- package/dist/src/intl/te.js +16 -3
- package/dist/src/intl/th.d.ts +3 -1
- package/dist/src/intl/th.d.ts.map +1 -1
- package/dist/src/intl/th.js +16 -3
- package/dist/src/intl/tr.d.ts +3 -1
- package/dist/src/intl/tr.d.ts.map +1 -1
- package/dist/src/intl/tr.js +16 -3
- package/dist/src/intl/uk.d.ts +3 -1
- package/dist/src/intl/uk.d.ts.map +1 -1
- package/dist/src/intl/uk.js +16 -3
- package/dist/src/intl/ur.d.ts +3 -1
- package/dist/src/intl/ur.d.ts.map +1 -1
- package/dist/src/intl/ur.js +15 -2
- package/dist/src/intl/vi.d.ts +3 -1
- package/dist/src/intl/vi.d.ts.map +1 -1
- package/dist/src/intl/vi.js +16 -3
- package/dist/src/intl/zh-CN.d.ts +3 -1
- package/dist/src/intl/zh-CN.d.ts.map +1 -1
- package/dist/src/intl/zh-CN.js +16 -3
- package/dist/src/intl/zh-TW.d.ts +3 -1
- package/dist/src/intl/zh-TW.d.ts.map +1 -1
- package/dist/src/intl/zh-TW.js +16 -3
- package/dist/src/local-first/Evolu.d.ts +47 -24
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Owner.d.ts +10 -7
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +10 -7
- package/dist/src/local-first/Protocol.d.ts +5 -5
- package/dist/src/local-first/Protocol.js +5 -5
- package/dist/src/local-first/Query.d.ts +34 -21
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +25 -13
- package/dist/src/local-first/Relay.d.ts +12 -5
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Schema.d.ts +19 -11
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +11 -6
- package/dist/src/local-first/Storage.d.ts +4 -2
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/package.json +3 -4
- package/src/Array.ts +170 -97
- package/src/Assert.ts +336 -31
- package/src/BigInt.ts +3 -3
- package/src/Brand.ts +7 -7
- package/src/Buffer.ts +12 -4
- package/src/Cache.ts +8 -3
- package/src/Callbacks.ts +8 -4
- package/src/Console.ts +45 -30
- package/src/Crypto.ts +13 -8
- package/src/Eq.ts +450 -122
- package/src/Function.ts +54 -24
- package/src/Http.ts +52 -19
- package/src/Identicon.ts +9 -4
- package/src/LockManager.ts +12 -10
- package/src/Lookup.ts +4 -2
- package/src/Number.ts +28 -24
- package/src/Object.ts +115 -49
- package/src/Option.ts +14 -5
- package/src/Order.ts +12 -12
- package/src/Platform.ts +2 -2
- package/src/Random.ts +7 -4
- package/src/Redacted.ts +13 -6
- package/src/Ref.ts +4 -4
- package/src/Relation.ts +5 -7
- package/src/Resource.ts +27 -12
- package/src/Result.ts +258 -114
- package/src/Schedule.ts +233 -116
- package/src/Set.ts +43 -24
- package/src/Sqlite.ts +9 -8
- package/src/Task.ts +441 -212
- package/src/Test.ts +10 -4
- package/src/Time.ts +27 -17
- package/src/Type.ts +2077 -620
- package/src/Types.ts +108 -40
- package/src/WebSocket.ts +14 -6
- package/src/Worker.ts +10 -6
- package/src/intl/_en.ts +20 -4
- package/src/intl/ar.ts +17 -2
- package/src/intl/bn.ts +19 -4
- package/src/intl/ca.ts +19 -4
- package/src/intl/cs.ts +19 -4
- package/src/intl/da.ts +19 -4
- package/src/intl/de.ts +19 -4
- package/src/intl/el.ts +19 -4
- package/src/intl/es.ts +19 -4
- package/src/intl/fa.ts +19 -4
- package/src/intl/fi.ts +19 -4
- package/src/intl/fil.ts +19 -4
- package/src/intl/fr.ts +19 -4
- package/src/intl/he.ts +19 -4
- package/src/intl/hi.ts +19 -4
- package/src/intl/hr.ts +19 -4
- package/src/intl/hu.ts +18 -4
- package/src/intl/id.ts +19 -4
- package/src/intl/it.ts +19 -4
- package/src/intl/ja.ts +19 -4
- package/src/intl/ko.ts +19 -4
- package/src/intl/ml.ts +19 -4
- package/src/intl/mr.ts +19 -4
- package/src/intl/ms.ts +17 -2
- package/src/intl/nb.ts +16 -2
- package/src/intl/nl.ts +19 -4
- package/src/intl/pa.ts +19 -4
- package/src/intl/pl.ts +18 -2
- package/src/intl/pt-BR.ts +19 -4
- package/src/intl/pt.ts +17 -2
- package/src/intl/ro.ts +19 -4
- package/src/intl/sk.ts +17 -2
- package/src/intl/sl.ts +19 -4
- package/src/intl/sv.ts +19 -4
- package/src/intl/sw.ts +15 -2
- package/src/intl/ta.ts +19 -4
- package/src/intl/te.ts +19 -4
- package/src/intl/th.ts +19 -4
- package/src/intl/tr.ts +19 -4
- package/src/intl/uk.ts +19 -4
- package/src/intl/ur.ts +17 -2
- package/src/intl/vi.ts +19 -3
- package/src/intl/zh-CN.ts +19 -4
- package/src/intl/zh-TW.ts +19 -4
- package/src/local-first/Evolu.ts +47 -24
- package/src/local-first/Owner.ts +10 -7
- package/src/local-first/Protocol.ts +5 -5
- package/src/local-first/Query.ts +34 -21
- package/src/local-first/Relay.ts +12 -5
- package/src/local-first/Schema.ts +19 -11
- package/src/local-first/Storage.ts +4 -2
package/dist/src/Schedule.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ import type { Predicate } from "./Types.ts";
|
|
|
32
32
|
*
|
|
33
33
|
* ```ts
|
|
34
34
|
* import {
|
|
35
|
+
* assertOk,
|
|
35
36
|
* err,
|
|
36
37
|
* exponential,
|
|
37
38
|
* jitter,
|
|
@@ -59,18 +60,24 @@ import type { Predicate } from "./Types.ts";
|
|
|
59
60
|
* await using run = testCreateRun({
|
|
60
61
|
* random: { next: () => 0 as RandomNumber },
|
|
61
62
|
* });
|
|
62
|
-
*
|
|
63
|
+
* assertOk(await run(fetchWithRetry), "data");
|
|
63
64
|
* ```
|
|
64
65
|
*
|
|
65
66
|
* Or use a preset:
|
|
66
67
|
*
|
|
67
68
|
* ```ts
|
|
68
|
-
* import {
|
|
69
|
+
* import {
|
|
70
|
+
* assertTrue,
|
|
71
|
+
* ok,
|
|
72
|
+
* retry,
|
|
73
|
+
* retryStrategyAws,
|
|
74
|
+
* type Task,
|
|
75
|
+
* } from "@evolu/common";
|
|
69
76
|
*
|
|
70
77
|
* const fetchData: Task<string> = () => ok("data");
|
|
71
78
|
* const fetchWithRetry = retry(fetchData, retryStrategyAws);
|
|
72
79
|
*
|
|
73
|
-
*
|
|
80
|
+
* assertTrue(typeof fetchWithRetry === "function");
|
|
74
81
|
* ```
|
|
75
82
|
*/
|
|
76
83
|
export type Schedule<out Output, in Input = unknown> = (deps: ScheduleDeps) => (input: Input) => NextResult<readonly [Output, Millis]>;
|
|
@@ -105,12 +112,12 @@ export interface ScheduleStep<Output> {
|
|
|
105
112
|
* ### Recurring immediately
|
|
106
113
|
*
|
|
107
114
|
* ```ts
|
|
108
|
-
* import { forever, take, testCreateDeps } from "@evolu/common";
|
|
115
|
+
* import { assertOk, forever, take, testCreateDeps } from "@evolu/common";
|
|
109
116
|
*
|
|
110
117
|
* // Retry immediately, up to 5 times.
|
|
111
118
|
* const immediate = take(5)(forever);
|
|
112
119
|
* const step = immediate(testCreateDeps());
|
|
113
|
-
*
|
|
120
|
+
* assertOk(step(undefined), [0, 0]);
|
|
114
121
|
* ```
|
|
115
122
|
*
|
|
116
123
|
* @group Constructors
|
|
@@ -124,13 +131,19 @@ export declare const forever: Schedule<number>;
|
|
|
124
131
|
* ### Scheduling one recurrence
|
|
125
132
|
*
|
|
126
133
|
* ```ts
|
|
127
|
-
* import {
|
|
134
|
+
* import {
|
|
135
|
+
* assertErr,
|
|
136
|
+
* assertOk,
|
|
137
|
+
* done,
|
|
138
|
+
* once,
|
|
139
|
+
* testCreateDeps,
|
|
140
|
+
* } from "@evolu/common";
|
|
128
141
|
*
|
|
129
142
|
* // Produce one scheduled recurrence, then stop.
|
|
130
143
|
* const oneShot = once;
|
|
131
144
|
* const step = oneShot(testCreateDeps());
|
|
132
|
-
*
|
|
133
|
-
*
|
|
145
|
+
* assertOk(step(undefined), [0, 0]);
|
|
146
|
+
* assertErr(step(undefined), done());
|
|
134
147
|
* ```
|
|
135
148
|
*
|
|
136
149
|
* @group Constructors
|
|
@@ -148,15 +161,21 @@ export declare const once: Schedule<number>;
|
|
|
148
161
|
* ### Limiting recurrence count
|
|
149
162
|
*
|
|
150
163
|
* ```ts
|
|
151
|
-
* import {
|
|
164
|
+
* import {
|
|
165
|
+
* assertErr,
|
|
166
|
+
* assertOk,
|
|
167
|
+
* done,
|
|
168
|
+
* recurs,
|
|
169
|
+
* testCreateDeps,
|
|
170
|
+
* } from "@evolu/common";
|
|
152
171
|
*
|
|
153
172
|
* // Retry up to 3 times (4 total attempts including the initial operation).
|
|
154
173
|
* const retry = recurs(3);
|
|
155
174
|
* const step = retry(testCreateDeps());
|
|
156
|
-
*
|
|
175
|
+
* assertOk(step(undefined), [0, 0]);
|
|
157
176
|
* step(undefined);
|
|
158
177
|
* step(undefined);
|
|
159
|
-
*
|
|
178
|
+
* assertErr(step(undefined), done());
|
|
160
179
|
* ```
|
|
161
180
|
*
|
|
162
181
|
* @group Constructors
|
|
@@ -171,7 +190,7 @@ export declare const recurs: (n: Int0To100OrNonNegativeInt) => Schedule<number>;
|
|
|
171
190
|
* ### Constant spacing
|
|
172
191
|
*
|
|
173
192
|
* ```ts
|
|
174
|
-
* import { spaced, take, testCreateDeps } from "@evolu/common";
|
|
193
|
+
* import { assertOk, spaced, take, testCreateDeps } from "@evolu/common";
|
|
175
194
|
*
|
|
176
195
|
* // Poll every second, retry three times, or run a long-lived heartbeat.
|
|
177
196
|
* const poll = spaced("1s");
|
|
@@ -179,9 +198,9 @@ export declare const recurs: (n: Int0To100OrNonNegativeInt) => Schedule<number>;
|
|
|
179
198
|
* const heartbeat = spaced("30s");
|
|
180
199
|
* const deps = testCreateDeps();
|
|
181
200
|
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
201
|
+
* assertOk(poll(deps)(undefined), [1000, 1000]);
|
|
202
|
+
* assertOk(retry(deps)(undefined), [500, 500]);
|
|
203
|
+
* assertOk(heartbeat(deps)(undefined), [30000, 30000]);
|
|
185
204
|
* ```
|
|
186
205
|
*
|
|
187
206
|
* @group Constructors
|
|
@@ -202,17 +221,17 @@ export declare const spaced: (duration: Duration) => Schedule<Millis>;
|
|
|
202
221
|
* ### Exponential growth factors
|
|
203
222
|
*
|
|
204
223
|
* ```ts
|
|
205
|
-
* import { exponential, testCreateDeps } from "@evolu/common";
|
|
224
|
+
* import { assertOk, exponential, testCreateDeps } from "@evolu/common";
|
|
206
225
|
*
|
|
207
226
|
* // Standard doubling and gentler 1.5× growth.
|
|
208
227
|
* const standard = exponential("100ms");
|
|
209
228
|
* const gentle = exponential("100ms", 1.5);
|
|
210
229
|
* const standardStep = standard(testCreateDeps());
|
|
211
230
|
* const gentleStep = gentle(testCreateDeps());
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
231
|
+
* assertOk(standardStep(undefined), [100, 100]);
|
|
232
|
+
* assertOk(standardStep(undefined), [200, 200]);
|
|
233
|
+
* assertOk(gentleStep(undefined), [100, 100]);
|
|
234
|
+
* assertOk(gentleStep(undefined), [150, 150]);
|
|
216
235
|
* ```
|
|
217
236
|
*
|
|
218
237
|
* @group Constructors
|
|
@@ -233,12 +252,12 @@ export declare const exponential: (base: Duration, factor?: number) => Schedule<
|
|
|
233
252
|
* ### Linear growth
|
|
234
253
|
*
|
|
235
254
|
* ```ts
|
|
236
|
-
* import { linear, testCreateDeps } from "@evolu/common";
|
|
255
|
+
* import { assertOk, linear, testCreateDeps } from "@evolu/common";
|
|
237
256
|
*
|
|
238
257
|
* // 100ms, 200ms, 300ms, 400ms, ...
|
|
239
258
|
* const step = linear("100ms")(testCreateDeps());
|
|
240
|
-
*
|
|
241
|
-
*
|
|
259
|
+
* assertOk(step(undefined), [100, 100]);
|
|
260
|
+
* assertOk(step(undefined), [200, 200]);
|
|
242
261
|
* ```
|
|
243
262
|
*
|
|
244
263
|
* @group Constructors
|
|
@@ -261,13 +280,13 @@ export declare const linear: (base: Duration) => Schedule<Millis>;
|
|
|
261
280
|
* ### Fibonacci growth
|
|
262
281
|
*
|
|
263
282
|
* ```ts
|
|
264
|
-
* import { fibonacci, testCreateDeps } from "@evolu/common";
|
|
283
|
+
* import { assertOk, fibonacci, testCreateDeps } from "@evolu/common";
|
|
265
284
|
*
|
|
266
285
|
* // 100ms, 100ms, 200ms, 300ms, 500ms, ...
|
|
267
286
|
* const step = fibonacci("100ms")(testCreateDeps());
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
287
|
+
* assertOk(step(undefined), [100, 100]);
|
|
288
|
+
* assertOk(step(undefined), [100, 100]);
|
|
289
|
+
* assertOk(step(undefined), [200, 200]);
|
|
271
290
|
* ```
|
|
272
291
|
*
|
|
273
292
|
* @group Constructors
|
|
@@ -287,7 +306,7 @@ export declare const fibonacci: (initial: Duration) => Schedule<Millis>;
|
|
|
287
306
|
* ### Maintaining a fixed cadence
|
|
288
307
|
*
|
|
289
308
|
* ```ts
|
|
290
|
-
* import { fixed, take, testCreateDeps } from "@evolu/common";
|
|
309
|
+
* import { assertOk, fixed, take, testCreateDeps } from "@evolu/common";
|
|
291
310
|
*
|
|
292
311
|
* // A bounded health check and an unbounded cron-like cadence.
|
|
293
312
|
* const healthCheck = take(10)(fixed("5s"));
|
|
@@ -295,10 +314,10 @@ export declare const fibonacci: (initial: Duration) => Schedule<Millis>;
|
|
|
295
314
|
*
|
|
296
315
|
* const healthDeps = testCreateDeps();
|
|
297
316
|
* const healthStep = healthCheck(healthDeps);
|
|
298
|
-
*
|
|
317
|
+
* assertOk(healthStep(undefined), [0, 5000]);
|
|
299
318
|
* healthDeps.time.advance("3s");
|
|
300
|
-
*
|
|
301
|
-
*
|
|
319
|
+
* assertOk(healthStep(undefined), [1, 2000]);
|
|
320
|
+
* assertOk(cronLike(testCreateDeps())(undefined), [0, 60000]);
|
|
302
321
|
* ```
|
|
303
322
|
*
|
|
304
323
|
* @group Constructors
|
|
@@ -315,7 +334,7 @@ export declare const fixed: (interval: Duration) => Schedule<number>;
|
|
|
315
334
|
* ### Aligning to time windows
|
|
316
335
|
*
|
|
317
336
|
* ```ts
|
|
318
|
-
* import { testCreateDeps, windowed } from "@evolu/common";
|
|
337
|
+
* import { assertOk, testCreateDeps, windowed } from "@evolu/common";
|
|
319
338
|
*
|
|
320
339
|
* const stepAfter = (elapsed: "3s" | "7s") => {
|
|
321
340
|
* const deps = testCreateDeps();
|
|
@@ -326,8 +345,8 @@ export declare const fixed: (interval: Duration) => Schedule<number>;
|
|
|
326
345
|
* };
|
|
327
346
|
*
|
|
328
347
|
* // At 3s the next boundary is 2s away; at 7s it is 3s away.
|
|
329
|
-
*
|
|
330
|
-
*
|
|
348
|
+
* assertOk(stepAfter("3s"), [1, 2000]);
|
|
349
|
+
* assertOk(stepAfter("7s"), [1, 3000]);
|
|
331
350
|
* ```
|
|
332
351
|
*
|
|
333
352
|
* @group Constructors
|
|
@@ -341,12 +360,18 @@ export declare const windowed: (interval: Duration) => Schedule<number>;
|
|
|
341
360
|
* ### Scheduling one delayed recurrence
|
|
342
361
|
*
|
|
343
362
|
* ```ts
|
|
344
|
-
* import {
|
|
363
|
+
* import {
|
|
364
|
+
* assertErr,
|
|
365
|
+
* assertOk,
|
|
366
|
+
* done,
|
|
367
|
+
* fromDelay,
|
|
368
|
+
* testCreateDeps,
|
|
369
|
+
* } from "@evolu/common";
|
|
345
370
|
*
|
|
346
371
|
* // Wait one second, then stop.
|
|
347
372
|
* const step = fromDelay("1s")(testCreateDeps());
|
|
348
|
-
*
|
|
349
|
-
*
|
|
373
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
374
|
+
* assertErr(step(undefined), done());
|
|
350
375
|
* ```
|
|
351
376
|
*
|
|
352
377
|
* @group Constructors
|
|
@@ -361,15 +386,21 @@ export declare const fromDelay: (delay: Duration) => Schedule<Millis>;
|
|
|
361
386
|
* ### Sequencing custom delays
|
|
362
387
|
*
|
|
363
388
|
* ```ts
|
|
364
|
-
* import {
|
|
389
|
+
* import {
|
|
390
|
+
* assertErr,
|
|
391
|
+
* assertOk,
|
|
392
|
+
* done,
|
|
393
|
+
* fromDelays,
|
|
394
|
+
* testCreateDeps,
|
|
395
|
+
* } from "@evolu/common";
|
|
365
396
|
*
|
|
366
397
|
* // A custom retry sequence: 100ms, 500ms, then 2s.
|
|
367
398
|
* const custom = fromDelays("100ms", "500ms", "2s");
|
|
368
399
|
* const step = custom(testCreateDeps());
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
400
|
+
* assertOk(step(undefined), [100, 100]);
|
|
401
|
+
* assertOk(step(undefined), [500, 500]);
|
|
402
|
+
* assertOk(step(undefined), [2000, 2000]);
|
|
403
|
+
* assertErr(step(undefined), done());
|
|
373
404
|
* ```
|
|
374
405
|
*
|
|
375
406
|
* @group Constructors
|
|
@@ -385,6 +416,8 @@ export declare const fromDelays: (...delays: ReadonlyArray<Duration>) => Schedul
|
|
|
385
416
|
*
|
|
386
417
|
* ```ts
|
|
387
418
|
* import {
|
|
419
|
+
* assertErr,
|
|
420
|
+
* assertOk,
|
|
388
421
|
* done,
|
|
389
422
|
* elapsed,
|
|
390
423
|
* exponential,
|
|
@@ -396,7 +429,7 @@ export declare const fromDelays: (...delays: ReadonlyArray<Duration>) => Schedul
|
|
|
396
429
|
*
|
|
397
430
|
* // Track elapsed time alongside each backoff step.
|
|
398
431
|
* const withTiming = intersectSchedules(exponential("100ms"), elapsed);
|
|
399
|
-
*
|
|
432
|
+
* assertOk(withTiming(testCreateDeps())(undefined), [[100, 0], 100]);
|
|
400
433
|
*
|
|
401
434
|
* // Or stop a schedule after 30 seconds of elapsed time.
|
|
402
435
|
* const timeLimited = whileScheduleOutput((ms: Millis) => ms < 30000)(
|
|
@@ -406,7 +439,7 @@ export declare const fromDelays: (...delays: ReadonlyArray<Duration>) => Schedul
|
|
|
406
439
|
* const step = timeLimited(deps);
|
|
407
440
|
* step(undefined);
|
|
408
441
|
* deps.time.advance("30s");
|
|
409
|
-
*
|
|
442
|
+
* assertErr(step(undefined), done());
|
|
410
443
|
* ```
|
|
411
444
|
*
|
|
412
445
|
* @group Constructors
|
|
@@ -422,6 +455,8 @@ export declare const elapsed: Schedule<Millis>;
|
|
|
422
455
|
*
|
|
423
456
|
* ```ts
|
|
424
457
|
* import {
|
|
458
|
+
* assertErr,
|
|
459
|
+
* assertOk,
|
|
425
460
|
* done,
|
|
426
461
|
* during,
|
|
427
462
|
* exponential,
|
|
@@ -433,16 +468,16 @@ export declare const elapsed: Schedule<Millis>;
|
|
|
433
468
|
* const timeLimited = during("30s");
|
|
434
469
|
* const deps = testCreateDeps();
|
|
435
470
|
* const step = timeLimited(deps);
|
|
436
|
-
*
|
|
471
|
+
* assertOk(step(undefined), [0, 0]);
|
|
437
472
|
* deps.time.advance("30.1s");
|
|
438
|
-
*
|
|
473
|
+
* assertErr(step(undefined), done());
|
|
439
474
|
*
|
|
440
475
|
* // Combine elapsed time with backoff for a time-boxed retry.
|
|
441
476
|
* const timedRetry = intersectSchedules(
|
|
442
477
|
* exponential("100ms"),
|
|
443
478
|
* during("10s"),
|
|
444
479
|
* );
|
|
445
|
-
*
|
|
480
|
+
* assertOk(timedRetry(testCreateDeps())(undefined), [[100, 0], 100]);
|
|
446
481
|
* ```
|
|
447
482
|
*
|
|
448
483
|
* @group Constructors
|
|
@@ -457,6 +492,7 @@ export declare const during: (duration: Duration) => Schedule<Millis>;
|
|
|
457
492
|
*
|
|
458
493
|
* ```ts
|
|
459
494
|
* import {
|
|
495
|
+
* assertOk,
|
|
460
496
|
* always,
|
|
461
497
|
* exponential,
|
|
462
498
|
* intersectSchedules,
|
|
@@ -465,14 +501,14 @@ export declare const during: (duration: Duration) => Schedule<Millis>;
|
|
|
465
501
|
*
|
|
466
502
|
* // Always emit the same label.
|
|
467
503
|
* const labeled = always("retry");
|
|
468
|
-
*
|
|
504
|
+
* assertOk(labeled(testCreateDeps())(undefined), ["retry", 0]);
|
|
469
505
|
*
|
|
470
506
|
* // Add a label while preserving exponential timing.
|
|
471
507
|
* const withLabel = intersectSchedules(
|
|
472
508
|
* exponential("100ms"),
|
|
473
509
|
* always("backoff"),
|
|
474
510
|
* );
|
|
475
|
-
*
|
|
511
|
+
* assertOk(withLabel(testCreateDeps())(undefined), [
|
|
476
512
|
* [100, "backoff"],
|
|
477
513
|
* 100,
|
|
478
514
|
* ]);
|
|
@@ -491,7 +527,7 @@ export declare const always: <A>(value: A) => Schedule<A>;
|
|
|
491
527
|
* ### Unfolding state
|
|
492
528
|
*
|
|
493
529
|
* ```ts
|
|
494
|
-
* import { testCreateDeps, unfoldSchedule } from "@evolu/common";
|
|
530
|
+
* import { assertOk, testCreateDeps, unfoldSchedule } from "@evolu/common";
|
|
495
531
|
*
|
|
496
532
|
* // Unfold counters, custom backoff values, or state machines.
|
|
497
533
|
* const counter = unfoldSchedule(0, (n) => n + 1);
|
|
@@ -514,12 +550,12 @@ export declare const always: <A>(value: A) => Schedule<A>;
|
|
|
514
550
|
* const counterStep = counter(testCreateDeps());
|
|
515
551
|
* const backoffStep = customBackoff(testCreateDeps());
|
|
516
552
|
* const phaseStep = phases(testCreateDeps());
|
|
517
|
-
*
|
|
518
|
-
*
|
|
553
|
+
* assertOk(counterStep(undefined), [0, 0]);
|
|
554
|
+
* assertOk(counterStep(undefined), [1, 0]);
|
|
519
555
|
* backoffStep(undefined);
|
|
520
556
|
* phaseStep(undefined);
|
|
521
|
-
*
|
|
522
|
-
*
|
|
557
|
+
* assertOk(backoffStep(undefined), [150, 0]);
|
|
558
|
+
* assertOk(phaseStep(undefined), ["warmup", 0]);
|
|
523
559
|
* ```
|
|
524
560
|
*
|
|
525
561
|
* @group Constructors
|
|
@@ -536,14 +572,20 @@ export declare const unfoldSchedule: <State>(initial: State, next: (state: State
|
|
|
536
572
|
* ### Limiting a schedule
|
|
537
573
|
*
|
|
538
574
|
* ```ts
|
|
539
|
-
* import {
|
|
575
|
+
* import {
|
|
576
|
+
* assertErr,
|
|
577
|
+
* done,
|
|
578
|
+
* exponential,
|
|
579
|
+
* take,
|
|
580
|
+
* testCreateDeps,
|
|
581
|
+
* } from "@evolu/common";
|
|
540
582
|
*
|
|
541
583
|
* // Three exponential retries, then Done.
|
|
542
584
|
* const step = take(3)(exponential("100ms"))(testCreateDeps());
|
|
543
585
|
* step(undefined);
|
|
544
586
|
* step(undefined);
|
|
545
587
|
* step(undefined);
|
|
546
|
-
*
|
|
588
|
+
* assertErr(step(undefined), done());
|
|
547
589
|
* ```
|
|
548
590
|
*
|
|
549
591
|
* @group Limiting
|
|
@@ -558,6 +600,8 @@ export declare const take: (n: Int0To100OrNonNegativeInt) => <Output, Input>(sch
|
|
|
558
600
|
*
|
|
559
601
|
* ```ts
|
|
560
602
|
* import {
|
|
603
|
+
* assertErr,
|
|
604
|
+
* assertOk,
|
|
561
605
|
* done,
|
|
562
606
|
* exponential,
|
|
563
607
|
* maxElapsed,
|
|
@@ -567,9 +611,9 @@ export declare const take: (n: Int0To100OrNonNegativeInt) => <Output, Input>(sch
|
|
|
567
611
|
* // Retry for at most 30 seconds.
|
|
568
612
|
* const deps = testCreateDeps();
|
|
569
613
|
* const step = maxElapsed("30s")(exponential("1s"))(deps);
|
|
570
|
-
*
|
|
614
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
571
615
|
* deps.time.advance("30s");
|
|
572
|
-
*
|
|
616
|
+
* assertErr(step(undefined), done());
|
|
573
617
|
* ```
|
|
574
618
|
*
|
|
575
619
|
* @group Limiting
|
|
@@ -583,7 +627,12 @@ export declare const maxElapsed: (duration: Duration) => <Output, Input>(schedul
|
|
|
583
627
|
* ### Capping delays
|
|
584
628
|
*
|
|
585
629
|
* ```ts
|
|
586
|
-
* import {
|
|
630
|
+
* import {
|
|
631
|
+
* assertOk,
|
|
632
|
+
* exponential,
|
|
633
|
+
* maxDelay,
|
|
634
|
+
* testCreateDeps,
|
|
635
|
+
* } from "@evolu/common";
|
|
587
636
|
*
|
|
588
637
|
* // Exponential delays grow 1s, 2s, 4s, 8s, then stay capped at 10s.
|
|
589
638
|
* const step = maxDelay("10s")(exponential("1s"))(testCreateDeps());
|
|
@@ -591,7 +640,7 @@ export declare const maxElapsed: (duration: Duration) => <Output, Input>(schedul
|
|
|
591
640
|
* step(undefined);
|
|
592
641
|
* step(undefined);
|
|
593
642
|
* step(undefined);
|
|
594
|
-
*
|
|
643
|
+
* assertOk(step(undefined), [16000, 10000]);
|
|
595
644
|
* ```
|
|
596
645
|
*
|
|
597
646
|
* @group Limiting
|
|
@@ -617,6 +666,7 @@ export declare const maxDelay: (max: Duration) => <Output, Input>(schedule: Sche
|
|
|
617
666
|
*
|
|
618
667
|
* ```ts
|
|
619
668
|
* import {
|
|
669
|
+
* assertOk,
|
|
620
670
|
* exponential,
|
|
621
671
|
* jitter,
|
|
622
672
|
* spaced,
|
|
@@ -634,8 +684,8 @@ export declare const maxDelay: (max: Duration) => <Output, Input>(schedule: Sche
|
|
|
634
684
|
* // Poll around a 30s target cadence, from 27s to 33s.
|
|
635
685
|
* const polling = jitter("10%", "around")(spaced("30s"));
|
|
636
686
|
*
|
|
637
|
-
*
|
|
638
|
-
*
|
|
687
|
+
* assertOk(conservative(deps)(undefined), [1000, 875]);
|
|
688
|
+
* assertOk(polling(deps)(undefined), [30000, 30000]);
|
|
639
689
|
* ```
|
|
640
690
|
*
|
|
641
691
|
* @group Delay
|
|
@@ -650,12 +700,17 @@ export declare const jitter: (percentage?: Percentage, mode?: "below" | "around"
|
|
|
650
700
|
* ### Replacing the first delay
|
|
651
701
|
*
|
|
652
702
|
* ```ts
|
|
653
|
-
* import {
|
|
703
|
+
* import {
|
|
704
|
+
* assertOk,
|
|
705
|
+
* delayed,
|
|
706
|
+
* exponential,
|
|
707
|
+
* testCreateDeps,
|
|
708
|
+
* } from "@evolu/common";
|
|
654
709
|
*
|
|
655
710
|
* const step = delayed("1s")(exponential("100ms"))(testCreateDeps());
|
|
656
711
|
* // Only the first delay is replaced; later exponential delays are unchanged.
|
|
657
|
-
*
|
|
658
|
-
*
|
|
712
|
+
* assertOk(step(undefined), [100, 1000]);
|
|
713
|
+
* assertOk(step(undefined), [200, 200]);
|
|
659
714
|
* ```
|
|
660
715
|
*
|
|
661
716
|
* @group Delay
|
|
@@ -667,11 +722,16 @@ export declare const delayed: (initialDelay: Duration) => <Output, Input>(schedu
|
|
|
667
722
|
* ### Adding to every delay
|
|
668
723
|
*
|
|
669
724
|
* ```ts
|
|
670
|
-
* import {
|
|
725
|
+
* import {
|
|
726
|
+
* assertOk,
|
|
727
|
+
* addDelay,
|
|
728
|
+
* exponential,
|
|
729
|
+
* testCreateDeps,
|
|
730
|
+
* } from "@evolu/common";
|
|
671
731
|
*
|
|
672
732
|
* // Add 500ms to every exponential delay.
|
|
673
733
|
* const step = addDelay("500ms")(exponential("100ms"))(testCreateDeps());
|
|
674
|
-
*
|
|
734
|
+
* assertOk(step(undefined), [100, 600]);
|
|
675
735
|
* ```
|
|
676
736
|
*
|
|
677
737
|
* @group Delay
|
|
@@ -685,7 +745,12 @@ export declare const addDelay: (extra: Duration) => (<Output, Input>(schedule: S
|
|
|
685
745
|
* ### Transforming delays
|
|
686
746
|
*
|
|
687
747
|
* ```ts
|
|
688
|
-
* import {
|
|
748
|
+
* import {
|
|
749
|
+
* assertOk,
|
|
750
|
+
* exponential,
|
|
751
|
+
* modifyDelay,
|
|
752
|
+
* testCreateDeps,
|
|
753
|
+
* } from "@evolu/common";
|
|
689
754
|
*
|
|
690
755
|
* // Arbitrary transformations can double or cap delays.
|
|
691
756
|
* const slower = modifyDelay((delay) => delay * 2)(exponential("100ms"));
|
|
@@ -695,8 +760,8 @@ export declare const addDelay: (extra: Duration) => (<Output, Input>(schedule: S
|
|
|
695
760
|
* );
|
|
696
761
|
* const deps = testCreateDeps();
|
|
697
762
|
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
763
|
+
* assertOk(slower(deps)(undefined), [100, 200]);
|
|
764
|
+
* assertOk(capped(deps)(undefined), [20000, 10000]);
|
|
700
765
|
* ```
|
|
701
766
|
*
|
|
702
767
|
* @group Delay
|
|
@@ -719,21 +784,26 @@ export declare const modifyDelay: (f: (delay: Millis) => number) => <Output, Inp
|
|
|
719
784
|
* ### Compensating for execution time
|
|
720
785
|
*
|
|
721
786
|
* ```ts
|
|
722
|
-
* import {
|
|
787
|
+
* import {
|
|
788
|
+
* assertOk,
|
|
789
|
+
* compensate,
|
|
790
|
+
* spaced,
|
|
791
|
+
* testCreateDeps,
|
|
792
|
+
* } from "@evolu/common";
|
|
723
793
|
*
|
|
724
794
|
* const fastDeps = testCreateDeps();
|
|
725
795
|
* const fastStep = compensate(spaced("5s"))(fastDeps);
|
|
726
|
-
*
|
|
796
|
+
* assertOk(fastStep(undefined), [5000, 5000]);
|
|
727
797
|
* // Five seconds waiting plus one second working leaves four seconds.
|
|
728
798
|
* fastDeps.time.advance("6s");
|
|
729
|
-
*
|
|
799
|
+
* assertOk(fastStep(undefined), [5000, 4000]);
|
|
730
800
|
*
|
|
731
801
|
* const slowDeps = testCreateDeps();
|
|
732
802
|
* const slowStep = compensate(spaced("5s"))(slowDeps);
|
|
733
|
-
*
|
|
803
|
+
* assertOk(slowStep(undefined), [5000, 5000]);
|
|
734
804
|
* // Five seconds waiting plus six seconds working leaves no delay.
|
|
735
805
|
* slowDeps.time.advance("11s");
|
|
736
|
-
*
|
|
806
|
+
* assertOk(slowStep(undefined), [5000, 0]);
|
|
737
807
|
* ```
|
|
738
808
|
*
|
|
739
809
|
* @group Delay
|
|
@@ -750,6 +820,8 @@ export declare const compensate: <Output, Input>(schedule: Schedule<Output, Inpu
|
|
|
750
820
|
*
|
|
751
821
|
* ```ts
|
|
752
822
|
* import {
|
|
823
|
+
* assertErr,
|
|
824
|
+
* assertOk,
|
|
753
825
|
* done,
|
|
754
826
|
* exponential,
|
|
755
827
|
* testCreateDeps,
|
|
@@ -764,8 +836,8 @@ export declare const compensate: <Output, Input>(schedule: Schedule<Output, Inpu
|
|
|
764
836
|
* (error: MyError) => error.type === "Transient",
|
|
765
837
|
* )(exponential("100ms"));
|
|
766
838
|
* const step = retryTransient(testCreateDeps());
|
|
767
|
-
*
|
|
768
|
-
*
|
|
839
|
+
* assertOk(step({ type: "Transient" }), [100, 100]);
|
|
840
|
+
* assertErr(step({ type: "Fatal" }), done());
|
|
769
841
|
* ```
|
|
770
842
|
*
|
|
771
843
|
* @group Filtering
|
|
@@ -781,6 +853,8 @@ export declare const whileScheduleInput: <Input>(predicate: Predicate<Input>) =>
|
|
|
781
853
|
*
|
|
782
854
|
* ```ts
|
|
783
855
|
* import {
|
|
856
|
+
* assertErr,
|
|
857
|
+
* assertOk,
|
|
784
858
|
* done,
|
|
785
859
|
* exponential,
|
|
786
860
|
* testCreateDeps,
|
|
@@ -795,8 +869,8 @@ export declare const whileScheduleInput: <Input>(predicate: Predicate<Input>) =>
|
|
|
795
869
|
* (error: MyError) => error.type === "Fatal",
|
|
796
870
|
* )(exponential("100ms"));
|
|
797
871
|
* const step = stopOnFatal(testCreateDeps());
|
|
798
|
-
*
|
|
799
|
-
*
|
|
872
|
+
* assertOk(step({ type: "Transient" }), [100, 100]);
|
|
873
|
+
* assertErr(step({ type: "Fatal" }), done());
|
|
800
874
|
* ```
|
|
801
875
|
*
|
|
802
876
|
* @group Filtering
|
|
@@ -811,6 +885,7 @@ export declare const untilScheduleInput: <Input>(predicate: Predicate<Input>) =>
|
|
|
811
885
|
*
|
|
812
886
|
* ```ts
|
|
813
887
|
* import {
|
|
888
|
+
* assertErr,
|
|
814
889
|
* done,
|
|
815
890
|
* exponential,
|
|
816
891
|
* testCreateDeps,
|
|
@@ -826,7 +901,7 @@ export declare const untilScheduleInput: <Input>(predicate: Predicate<Input>) =>
|
|
|
826
901
|
* step(undefined);
|
|
827
902
|
* step(undefined);
|
|
828
903
|
* step(undefined);
|
|
829
|
-
*
|
|
904
|
+
* assertErr(step(undefined), done());
|
|
830
905
|
* ```
|
|
831
906
|
*
|
|
832
907
|
* @group Filtering
|
|
@@ -841,6 +916,7 @@ export declare const whileScheduleOutput: <Output>(predicate: Predicate<Output>)
|
|
|
841
916
|
*
|
|
842
917
|
* ```ts
|
|
843
918
|
* import {
|
|
919
|
+
* assertErr,
|
|
844
920
|
* done,
|
|
845
921
|
* exponential,
|
|
846
922
|
* testCreateDeps,
|
|
@@ -857,7 +933,7 @@ export declare const whileScheduleOutput: <Output>(predicate: Predicate<Output>)
|
|
|
857
933
|
* step(undefined);
|
|
858
934
|
* step(undefined);
|
|
859
935
|
* step(undefined);
|
|
860
|
-
*
|
|
936
|
+
* assertErr(step(undefined), done());
|
|
861
937
|
* ```
|
|
862
938
|
*
|
|
863
939
|
* @group Filtering
|
|
@@ -874,6 +950,7 @@ export declare const untilScheduleOutput: <Output>(predicate: Predicate<Output>)
|
|
|
874
950
|
*
|
|
875
951
|
* ```ts
|
|
876
952
|
* import {
|
|
953
|
+
* assertOk,
|
|
877
954
|
* exponential,
|
|
878
955
|
* resetScheduleAfter,
|
|
879
956
|
* testCreateDeps,
|
|
@@ -882,9 +959,9 @@ export declare const untilScheduleOutput: <Output>(predicate: Predicate<Output>)
|
|
|
882
959
|
* const backoff = resetScheduleAfter("1m")(exponential("1s"));
|
|
883
960
|
* const deps = testCreateDeps();
|
|
884
961
|
* const step = backoff(deps);
|
|
885
|
-
*
|
|
962
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
886
963
|
* deps.time.advance("1m");
|
|
887
|
-
*
|
|
964
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
888
965
|
* ```
|
|
889
966
|
*
|
|
890
967
|
* @group State
|
|
@@ -899,6 +976,7 @@ export declare const resetScheduleAfter: (duration: DurationLiteral | PositiveMi
|
|
|
899
976
|
*
|
|
900
977
|
* ```ts
|
|
901
978
|
* import {
|
|
979
|
+
* assertOk,
|
|
902
980
|
* exponential,
|
|
903
981
|
* mapSchedule,
|
|
904
982
|
* testCreateDeps,
|
|
@@ -910,7 +988,7 @@ export declare const resetScheduleAfter: (duration: DurationLiteral | PositiveMi
|
|
|
910
988
|
* doubled: delay * 2,
|
|
911
989
|
* }))(exponential("100ms"));
|
|
912
990
|
* const step = schedule(testCreateDeps());
|
|
913
|
-
*
|
|
991
|
+
* assertOk(step(undefined), [{ delay: 100, doubled: 200 }, 100]);
|
|
914
992
|
* ```
|
|
915
993
|
*
|
|
916
994
|
* @group Transform
|
|
@@ -927,7 +1005,15 @@ export declare const mapSchedule: <A, B>(f: (a: A) => B) => <Input>(schedule: Sc
|
|
|
927
1005
|
* ### Passing through input
|
|
928
1006
|
*
|
|
929
1007
|
* ```ts
|
|
930
|
-
* import {
|
|
1008
|
+
* import {
|
|
1009
|
+
* assertEqual,
|
|
1010
|
+
* assertOk,
|
|
1011
|
+
* assertType,
|
|
1012
|
+
* Data,
|
|
1013
|
+
* exponential,
|
|
1014
|
+
* passthrough,
|
|
1015
|
+
* testCreateDeps,
|
|
1016
|
+
* } from "@evolu/common";
|
|
931
1017
|
*
|
|
932
1018
|
* interface MyError {
|
|
933
1019
|
* readonly message: string;
|
|
@@ -939,8 +1025,16 @@ export declare const mapSchedule: <A, B>(f: (a: A) => B) => <Input>(schedule: Sc
|
|
|
939
1025
|
* const error = { message: "Unavailable" };
|
|
940
1026
|
* const deps = testCreateDeps();
|
|
941
1027
|
*
|
|
942
|
-
*
|
|
943
|
-
*
|
|
1028
|
+
* const identityResult = identity(deps)(error);
|
|
1029
|
+
* assertOk(identityResult);
|
|
1030
|
+
* assertType(Data, identityResult.value);
|
|
1031
|
+
* assertEqual(identityResult.value, [error, 0]);
|
|
1032
|
+
*
|
|
1033
|
+
* const inputResult = withInput(deps)(error);
|
|
1034
|
+
* assertOk(inputResult);
|
|
1035
|
+
* assertType(Data, inputResult.value);
|
|
1036
|
+
* const inputValue: Data = inputResult.value;
|
|
1037
|
+
* assertEqual(inputValue, [error, 100]);
|
|
944
1038
|
* ```
|
|
945
1039
|
*
|
|
946
1040
|
* @group Constructors
|
|
@@ -958,6 +1052,7 @@ export declare function passthrough<Output, Input>(schedule: Schedule<Output, In
|
|
|
958
1052
|
*
|
|
959
1053
|
* ```ts
|
|
960
1054
|
* import {
|
|
1055
|
+
* assertOk,
|
|
961
1056
|
* exponential,
|
|
962
1057
|
* foldSchedule,
|
|
963
1058
|
* minMillis,
|
|
@@ -987,9 +1082,9 @@ export declare function passthrough<Output, Input>(schedule: Schedule<Output, In
|
|
|
987
1082
|
* const deps = testCreateDeps();
|
|
988
1083
|
* const totalStep = withTotal(deps);
|
|
989
1084
|
* totalStep(undefined);
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
*
|
|
1085
|
+
* assertOk(totalStep(undefined), [300, 200]);
|
|
1086
|
+
* assertOk(collected(deps)(undefined), [[1000], 1000]);
|
|
1087
|
+
* assertOk(counted(deps)(undefined), [
|
|
993
1088
|
* { attempts: 1, lastDelay: 100 },
|
|
994
1089
|
* 100,
|
|
995
1090
|
* ]);
|
|
@@ -1008,12 +1103,17 @@ export declare const foldSchedule: <Z, Output>(initial: Z, f: (acc: Z, output: O
|
|
|
1008
1103
|
* ### Counting repetitions
|
|
1009
1104
|
*
|
|
1010
1105
|
* ```ts
|
|
1011
|
-
* import {
|
|
1106
|
+
* import {
|
|
1107
|
+
* assertOk,
|
|
1108
|
+
* exponential,
|
|
1109
|
+
* repetitions,
|
|
1110
|
+
* testCreateDeps,
|
|
1111
|
+
* } from "@evolu/common";
|
|
1012
1112
|
*
|
|
1013
1113
|
* // Count retries while preserving exponential timing.
|
|
1014
1114
|
* const step = repetitions(exponential("100ms"))(testCreateDeps());
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1115
|
+
* assertOk(step(undefined), [0, 100]);
|
|
1116
|
+
* assertOk(step(undefined), [1, 200]);
|
|
1017
1117
|
* ```
|
|
1018
1118
|
*
|
|
1019
1119
|
* @group Transform
|
|
@@ -1029,6 +1129,8 @@ export declare const repetitions: <Output, Input>(schedule: Schedule<Output, Inp
|
|
|
1029
1129
|
*
|
|
1030
1130
|
* ```ts
|
|
1031
1131
|
* import {
|
|
1132
|
+
* assertEqual,
|
|
1133
|
+
* assertOk,
|
|
1032
1134
|
* delays,
|
|
1033
1135
|
* exponential,
|
|
1034
1136
|
* tapScheduleOutput,
|
|
@@ -1044,9 +1146,9 @@ export declare const repetitions: <Output, Input>(schedule: Schedule<Output, Inp
|
|
|
1044
1146
|
* })(delays(exponential("100ms")));
|
|
1045
1147
|
* const deps = testCreateDeps();
|
|
1046
1148
|
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1149
|
+
* assertOk(monitorDelays(deps)(undefined), [100, 100]);
|
|
1150
|
+
* assertOk(logged(deps)(undefined), [100, 100]);
|
|
1151
|
+
* assertEqual(observed, [100]);
|
|
1050
1152
|
* ```
|
|
1051
1153
|
*
|
|
1052
1154
|
* @group Transform
|
|
@@ -1063,6 +1165,7 @@ export declare const delays: <Output, Input>(schedule: Schedule<Output, Input>)
|
|
|
1063
1165
|
*
|
|
1064
1166
|
* ```ts
|
|
1065
1167
|
* import {
|
|
1168
|
+
* assertOk,
|
|
1066
1169
|
* collectAllScheduleOutputs,
|
|
1067
1170
|
* spaced,
|
|
1068
1171
|
* take,
|
|
@@ -1073,7 +1176,7 @@ export declare const delays: <Output, Input>(schedule: Schedule<Output, Input>)
|
|
|
1073
1176
|
* const collected = collectAllScheduleOutputs(take(3)(spaced("100ms")));
|
|
1074
1177
|
* const step = collected(testCreateDeps());
|
|
1075
1178
|
* step(undefined);
|
|
1076
|
-
*
|
|
1179
|
+
* assertOk(step(undefined), [[100, 100], 100]);
|
|
1077
1180
|
* ```
|
|
1078
1181
|
*
|
|
1079
1182
|
* @group Collection
|
|
@@ -1089,6 +1192,7 @@ export declare const collectAllScheduleOutputs: <Output, Input>(schedule: Schedu
|
|
|
1089
1192
|
*
|
|
1090
1193
|
* ```ts
|
|
1091
1194
|
* import {
|
|
1195
|
+
* assertOk,
|
|
1092
1196
|
* collectScheduleInputs,
|
|
1093
1197
|
* exponential,
|
|
1094
1198
|
* take,
|
|
@@ -1102,7 +1206,7 @@ export declare const collectAllScheduleOutputs: <Output, Input>(schedule: Schedu
|
|
|
1102
1206
|
* const errorHistory = collectScheduleInputs(retries);
|
|
1103
1207
|
* const step = errorHistory(testCreateDeps());
|
|
1104
1208
|
* step("network");
|
|
1105
|
-
*
|
|
1209
|
+
* assertOk(step("timeout"), [["network", "timeout"], 200]);
|
|
1106
1210
|
* ```
|
|
1107
1211
|
*
|
|
1108
1212
|
* @group Collection
|
|
@@ -1118,6 +1222,8 @@ export declare const collectScheduleInputs: <Output, Input>(schedule: Schedule<O
|
|
|
1118
1222
|
*
|
|
1119
1223
|
* ```ts
|
|
1120
1224
|
* import {
|
|
1225
|
+
* assertErr,
|
|
1226
|
+
* assertOk,
|
|
1121
1227
|
* collectWhileScheduleOutput,
|
|
1122
1228
|
* done,
|
|
1123
1229
|
* exponential,
|
|
@@ -1133,8 +1239,8 @@ export declare const collectScheduleInputs: <Output, Input>(schedule: Schedule<O
|
|
|
1133
1239
|
* step(undefined);
|
|
1134
1240
|
* step(undefined);
|
|
1135
1241
|
* step(undefined);
|
|
1136
|
-
*
|
|
1137
|
-
*
|
|
1242
|
+
* assertOk(step(undefined), [[100, 200, 400, 800], 800]);
|
|
1243
|
+
* assertErr(step(undefined), done());
|
|
1138
1244
|
* ```
|
|
1139
1245
|
*
|
|
1140
1246
|
* @group Collection
|
|
@@ -1150,6 +1256,8 @@ export declare const collectWhileScheduleOutput: <Output>(predicate: Predicate<O
|
|
|
1150
1256
|
*
|
|
1151
1257
|
* ```ts
|
|
1152
1258
|
* import {
|
|
1259
|
+
* assertErr,
|
|
1260
|
+
* assertOk,
|
|
1153
1261
|
* collectUntilScheduleOutput,
|
|
1154
1262
|
* done,
|
|
1155
1263
|
* exponential,
|
|
@@ -1165,8 +1273,8 @@ export declare const collectWhileScheduleOutput: <Output>(predicate: Predicate<O
|
|
|
1165
1273
|
* step(undefined);
|
|
1166
1274
|
* step(undefined);
|
|
1167
1275
|
* step(undefined);
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1276
|
+
* assertOk(step(undefined), [[100, 200, 400, 800], 800]);
|
|
1277
|
+
* assertErr(step(undefined), done());
|
|
1170
1278
|
* ```
|
|
1171
1279
|
*
|
|
1172
1280
|
* @group Collection
|
|
@@ -1182,6 +1290,7 @@ export declare const collectUntilScheduleOutput: <Output>(predicate: Predicate<O
|
|
|
1182
1290
|
*
|
|
1183
1291
|
* ```ts
|
|
1184
1292
|
* import {
|
|
1293
|
+
* assertOk,
|
|
1185
1294
|
* exponential,
|
|
1186
1295
|
* fixed,
|
|
1187
1296
|
* sequenceSchedules,
|
|
@@ -1198,7 +1307,7 @@ export declare const collectUntilScheduleOutput: <Output>(predicate: Predicate<O
|
|
|
1198
1307
|
* step(undefined);
|
|
1199
1308
|
* step(undefined);
|
|
1200
1309
|
* step(undefined);
|
|
1201
|
-
*
|
|
1310
|
+
* assertOk(step(undefined), [0, 500]);
|
|
1202
1311
|
* ```
|
|
1203
1312
|
*
|
|
1204
1313
|
* @group Composition
|
|
@@ -1213,6 +1322,8 @@ export declare const sequenceSchedules: <Output, Input>(...schedules: ReadonlyAr
|
|
|
1213
1322
|
*
|
|
1214
1323
|
* ```ts
|
|
1215
1324
|
* import {
|
|
1325
|
+
* assertErr,
|
|
1326
|
+
* assertOk,
|
|
1216
1327
|
* done,
|
|
1217
1328
|
* exponential,
|
|
1218
1329
|
* forever,
|
|
@@ -1228,9 +1339,9 @@ export declare const sequenceSchedules: <Output, Input>(...schedules: ReadonlyAr
|
|
|
1228
1339
|
* take(5)(exponential("1s")),
|
|
1229
1340
|
* maxElapsed("30s")(forever),
|
|
1230
1341
|
* )(deps);
|
|
1231
|
-
*
|
|
1342
|
+
* assertOk(step(undefined), [[1000, 0], 1000]);
|
|
1232
1343
|
* deps.time.advance("30s");
|
|
1233
|
-
*
|
|
1344
|
+
* assertErr(step(undefined), done());
|
|
1234
1345
|
* ```
|
|
1235
1346
|
*
|
|
1236
1347
|
* @group Composition
|
|
@@ -1245,6 +1356,8 @@ export declare const intersectSchedules: <OutputA, OutputB, Input>(a: Schedule<O
|
|
|
1245
1356
|
*
|
|
1246
1357
|
* ```ts
|
|
1247
1358
|
* import {
|
|
1359
|
+
* assertErr,
|
|
1360
|
+
* assertOk,
|
|
1248
1361
|
* done,
|
|
1249
1362
|
* spaced,
|
|
1250
1363
|
* take,
|
|
@@ -1258,9 +1371,9 @@ export declare const intersectSchedules: <OutputA, OutputB, Input>(a: Schedule<O
|
|
|
1258
1371
|
* take(2)(spaced("200ms")),
|
|
1259
1372
|
* );
|
|
1260
1373
|
* const step = either(testCreateDeps());
|
|
1261
|
-
*
|
|
1262
|
-
*
|
|
1263
|
-
*
|
|
1374
|
+
* assertOk(step(undefined), [100, 100]);
|
|
1375
|
+
* assertOk(step(undefined), [200, 200]);
|
|
1376
|
+
* assertErr(step(undefined), done());
|
|
1264
1377
|
* ```
|
|
1265
1378
|
*
|
|
1266
1379
|
* @group Composition
|
|
@@ -1280,6 +1393,8 @@ export declare const unionSchedules: <OutputA, OutputB, Input>(a: Schedule<Outpu
|
|
|
1280
1393
|
*
|
|
1281
1394
|
* ```ts
|
|
1282
1395
|
* import {
|
|
1396
|
+
* assertErr,
|
|
1397
|
+
* assertOk,
|
|
1283
1398
|
* done,
|
|
1284
1399
|
* exponential,
|
|
1285
1400
|
* take,
|
|
@@ -1299,10 +1414,10 @@ export declare const unionSchedules: <OutputA, OutputB, Input>(a: Schedule<Outpu
|
|
|
1299
1414
|
* )(exponential("100ms")),
|
|
1300
1415
|
* );
|
|
1301
1416
|
* const step = awsWithThrottling(testCreateDeps());
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
*
|
|
1305
|
-
*
|
|
1417
|
+
* assertOk(step({ type: "Throttled" }), [1000, 1000]);
|
|
1418
|
+
* assertOk(step({ type: "NetworkError" }), [100, 100]);
|
|
1419
|
+
* assertOk(step({ type: "Throttled" }), [2000, 2000]);
|
|
1420
|
+
* assertErr(step({ type: "NetworkError" }), done());
|
|
1306
1421
|
* ```
|
|
1307
1422
|
*
|
|
1308
1423
|
* @group Composition
|
|
@@ -1318,6 +1433,7 @@ export declare const whenInput: <Input, Output>(predicate: Predicate<Input>, alt
|
|
|
1318
1433
|
*
|
|
1319
1434
|
* ```ts
|
|
1320
1435
|
* import {
|
|
1436
|
+
* assertEqual,
|
|
1321
1437
|
* exponential,
|
|
1322
1438
|
* retryStrategyAws,
|
|
1323
1439
|
* tapScheduleOutput,
|
|
@@ -1340,8 +1456,8 @@ export declare const whenInput: <Input, Output>(predicate: Predicate<Input>, alt
|
|
|
1340
1456
|
* logged(deps)(undefined);
|
|
1341
1457
|
* tracked(deps)(undefined);
|
|
1342
1458
|
*
|
|
1343
|
-
*
|
|
1344
|
-
*
|
|
1459
|
+
* assertEqual(messages, ["Next delay: 100ms"]);
|
|
1460
|
+
* assertEqual(recordedCandidates, [50]);
|
|
1345
1461
|
* ```
|
|
1346
1462
|
*
|
|
1347
1463
|
* @group Side effects
|
|
@@ -1357,6 +1473,7 @@ export declare const tapScheduleOutput: <Output>(f: (output: Output) => void) =>
|
|
|
1357
1473
|
*
|
|
1358
1474
|
* ```ts
|
|
1359
1475
|
* import {
|
|
1476
|
+
* assertEqual,
|
|
1360
1477
|
* exponential,
|
|
1361
1478
|
* tapScheduleInput,
|
|
1362
1479
|
* testCreateDeps,
|
|
@@ -1383,8 +1500,8 @@ export declare const tapScheduleOutput: <Output>(f: (output: Output) => void) =>
|
|
|
1383
1500
|
* logged(deps)(error);
|
|
1384
1501
|
* tracked(deps)(error);
|
|
1385
1502
|
*
|
|
1386
|
-
*
|
|
1387
|
-
*
|
|
1503
|
+
* assertEqual(messages, ["Retrying after error: NetworkError"]);
|
|
1504
|
+
* assertEqual(reasons, ["NetworkError"]);
|
|
1388
1505
|
* ```
|
|
1389
1506
|
*
|
|
1390
1507
|
* @group Side effects
|