@evolu/common 8.4.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 +191 -94
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +91 -40
- package/dist/src/Assert.d.ts +233 -30
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +151 -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/LeakDetector.d.ts.map +1 -1
- package/dist/src/LeakDetector.js +4 -1
- 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 +5 -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/Platform.js +1 -0
- 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/Relation.js +3 -3
- package/dist/src/Resource.d.ts +27 -12
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Resource.js +9 -3
- package/dist/src/Result.d.ts +258 -114
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +74 -39
- 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 +18 -15
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +3 -1
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +1 -1
- package/dist/src/Task.d.ts +555 -264
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +278 -168
- package/dist/src/Test.d.ts +10 -4
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +11 -4
- package/dist/src/Time.d.ts +27 -17
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +25 -8
- package/dist/src/Type.d.ts +1218 -372
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1056 -379
- 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/WebSocket.js +8 -0
- package/dist/src/Worker.d.ts +10 -6
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +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/Db.js +3 -2
- 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/Evolu.js +1 -0
- package/dist/src/local-first/Owner.d.ts +18 -14
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +14 -11
- package/dist/src/local-first/Protocol.d.ts +5 -5
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +35 -29
- 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 +27 -14
- 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/Relay.js +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/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +4 -2
- package/dist/src/local-first/Storage.d.ts +4 -2
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +1 -1
- package/package.json +3 -4
- package/src/Array.ts +195 -95
- package/src/Assert.ts +337 -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/LeakDetector.ts +4 -3
- package/src/LockManager.ts +12 -10
- package/src/Lookup.ts +5 -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 +3 -2
- package/src/Random.ts +7 -4
- package/src/Redacted.ts +13 -6
- package/src/Ref.ts +4 -4
- package/src/Relation.ts +8 -10
- package/src/Resource.ts +36 -15
- package/src/Result.ts +263 -119
- package/src/Schedule.ts +233 -116
- package/src/Set.ts +43 -24
- package/src/Sqlite.ts +18 -15
- package/src/Store.ts +3 -1
- package/src/String.ts +1 -1
- package/src/Task.ts +566 -286
- package/src/Test.ts +11 -4
- package/src/Time.ts +36 -19
- package/src/Type.ts +2191 -590
- package/src/Types.ts +108 -40
- package/src/WebSocket.ts +22 -6
- package/src/Worker.ts +11 -7
- 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/Db.ts +2 -1
- package/src/local-first/Evolu.ts +48 -24
- package/src/local-first/Owner.ts +18 -14
- package/src/local-first/Protocol.ts +45 -35
- package/src/local-first/Query.ts +40 -24
- package/src/local-first/Relay.ts +13 -6
- package/src/local-first/Schema.ts +19 -11
- package/src/local-first/Shared.ts +4 -2
- package/src/local-first/Storage.ts +4 -2
- package/src/local-first/Timestamp.ts +1 -1
package/src/Schedule.ts
CHANGED
|
@@ -60,6 +60,7 @@ import type { Predicate } from "./Types.ts";
|
|
|
60
60
|
*
|
|
61
61
|
* ```ts
|
|
62
62
|
* import {
|
|
63
|
+
* assertOk,
|
|
63
64
|
* err,
|
|
64
65
|
* exponential,
|
|
65
66
|
* jitter,
|
|
@@ -87,18 +88,24 @@ import type { Predicate } from "./Types.ts";
|
|
|
87
88
|
* await using run = testCreateRun({
|
|
88
89
|
* random: { next: () => 0 as RandomNumber },
|
|
89
90
|
* });
|
|
90
|
-
*
|
|
91
|
+
* assertOk(await run(fetchWithRetry), "data");
|
|
91
92
|
* ```
|
|
92
93
|
*
|
|
93
94
|
* Or use a preset:
|
|
94
95
|
*
|
|
95
96
|
* ```ts
|
|
96
|
-
* import {
|
|
97
|
+
* import {
|
|
98
|
+
* assertTrue,
|
|
99
|
+
* ok,
|
|
100
|
+
* retry,
|
|
101
|
+
* retryStrategyAws,
|
|
102
|
+
* type Task,
|
|
103
|
+
* } from "@evolu/common";
|
|
97
104
|
*
|
|
98
105
|
* const fetchData: Task<string> = () => ok("data");
|
|
99
106
|
* const fetchWithRetry = retry(fetchData, retryStrategyAws);
|
|
100
107
|
*
|
|
101
|
-
*
|
|
108
|
+
* assertTrue(typeof fetchWithRetry === "function");
|
|
102
109
|
* ```
|
|
103
110
|
*/
|
|
104
111
|
export type Schedule<out Output, in Input = unknown> = (
|
|
@@ -140,12 +147,12 @@ export interface ScheduleStep<Output> {
|
|
|
140
147
|
* ### Recurring immediately
|
|
141
148
|
*
|
|
142
149
|
* ```ts
|
|
143
|
-
* import { forever, take, testCreateDeps } from "@evolu/common";
|
|
150
|
+
* import { assertOk, forever, take, testCreateDeps } from "@evolu/common";
|
|
144
151
|
*
|
|
145
152
|
* // Retry immediately, up to 5 times.
|
|
146
153
|
* const immediate = take(5)(forever);
|
|
147
154
|
* const step = immediate(testCreateDeps());
|
|
148
|
-
*
|
|
155
|
+
* assertOk(step(undefined), [0, 0]);
|
|
149
156
|
* ```
|
|
150
157
|
*
|
|
151
158
|
* @group Constructors
|
|
@@ -163,13 +170,19 @@ export const forever: Schedule<number> = () => {
|
|
|
163
170
|
* ### Scheduling one recurrence
|
|
164
171
|
*
|
|
165
172
|
* ```ts
|
|
166
|
-
* import {
|
|
173
|
+
* import {
|
|
174
|
+
* assertErr,
|
|
175
|
+
* assertOk,
|
|
176
|
+
* done,
|
|
177
|
+
* once,
|
|
178
|
+
* testCreateDeps,
|
|
179
|
+
* } from "@evolu/common";
|
|
167
180
|
*
|
|
168
181
|
* // Produce one scheduled recurrence, then stop.
|
|
169
182
|
* const oneShot = once;
|
|
170
183
|
* const step = oneShot(testCreateDeps());
|
|
171
|
-
*
|
|
172
|
-
*
|
|
184
|
+
* assertOk(step(undefined), [0, 0]);
|
|
185
|
+
* assertErr(step(undefined), done());
|
|
173
186
|
* ```
|
|
174
187
|
*
|
|
175
188
|
* @group Constructors
|
|
@@ -195,15 +208,21 @@ export const once: Schedule<number> = () => {
|
|
|
195
208
|
* ### Limiting recurrence count
|
|
196
209
|
*
|
|
197
210
|
* ```ts
|
|
198
|
-
* import {
|
|
211
|
+
* import {
|
|
212
|
+
* assertErr,
|
|
213
|
+
* assertOk,
|
|
214
|
+
* done,
|
|
215
|
+
* recurs,
|
|
216
|
+
* testCreateDeps,
|
|
217
|
+
* } from "@evolu/common";
|
|
199
218
|
*
|
|
200
219
|
* // Retry up to 3 times (4 total attempts including the initial operation).
|
|
201
220
|
* const retry = recurs(3);
|
|
202
221
|
* const step = retry(testCreateDeps());
|
|
203
|
-
*
|
|
222
|
+
* assertOk(step(undefined), [0, 0]);
|
|
204
223
|
* step(undefined);
|
|
205
224
|
* step(undefined);
|
|
206
|
-
*
|
|
225
|
+
* assertErr(step(undefined), done());
|
|
207
226
|
* ```
|
|
208
227
|
*
|
|
209
228
|
* @group Constructors
|
|
@@ -220,7 +239,7 @@ export const recurs = (n: Int0To100OrNonNegativeInt): Schedule<number> =>
|
|
|
220
239
|
* ### Constant spacing
|
|
221
240
|
*
|
|
222
241
|
* ```ts
|
|
223
|
-
* import { spaced, take, testCreateDeps } from "@evolu/common";
|
|
242
|
+
* import { assertOk, spaced, take, testCreateDeps } from "@evolu/common";
|
|
224
243
|
*
|
|
225
244
|
* // Poll every second, retry three times, or run a long-lived heartbeat.
|
|
226
245
|
* const poll = spaced("1s");
|
|
@@ -228,9 +247,9 @@ export const recurs = (n: Int0To100OrNonNegativeInt): Schedule<number> =>
|
|
|
228
247
|
* const heartbeat = spaced("30s");
|
|
229
248
|
* const deps = testCreateDeps();
|
|
230
249
|
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
250
|
+
* assertOk(poll(deps)(undefined), [1000, 1000]);
|
|
251
|
+
* assertOk(retry(deps)(undefined), [500, 500]);
|
|
252
|
+
* assertOk(heartbeat(deps)(undefined), [30000, 30000]);
|
|
234
253
|
* ```
|
|
235
254
|
*
|
|
236
255
|
* @group Constructors
|
|
@@ -257,17 +276,17 @@ export const spaced =
|
|
|
257
276
|
* ### Exponential growth factors
|
|
258
277
|
*
|
|
259
278
|
* ```ts
|
|
260
|
-
* import { exponential, testCreateDeps } from "@evolu/common";
|
|
279
|
+
* import { assertOk, exponential, testCreateDeps } from "@evolu/common";
|
|
261
280
|
*
|
|
262
281
|
* // Standard doubling and gentler 1.5× growth.
|
|
263
282
|
* const standard = exponential("100ms");
|
|
264
283
|
* const gentle = exponential("100ms", 1.5);
|
|
265
284
|
* const standardStep = standard(testCreateDeps());
|
|
266
285
|
* const gentleStep = gentle(testCreateDeps());
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
286
|
+
* assertOk(standardStep(undefined), [100, 100]);
|
|
287
|
+
* assertOk(standardStep(undefined), [200, 200]);
|
|
288
|
+
* assertOk(gentleStep(undefined), [100, 100]);
|
|
289
|
+
* assertOk(gentleStep(undefined), [150, 150]);
|
|
271
290
|
* ```
|
|
272
291
|
*
|
|
273
292
|
* @group Constructors
|
|
@@ -308,12 +327,12 @@ const saturateComputedMillis = (value: number): Millis => {
|
|
|
308
327
|
* ### Linear growth
|
|
309
328
|
*
|
|
310
329
|
* ```ts
|
|
311
|
-
* import { linear, testCreateDeps } from "@evolu/common";
|
|
330
|
+
* import { assertOk, linear, testCreateDeps } from "@evolu/common";
|
|
312
331
|
*
|
|
313
332
|
* // 100ms, 200ms, 300ms, 400ms, ...
|
|
314
333
|
* const step = linear("100ms")(testCreateDeps());
|
|
315
|
-
*
|
|
316
|
-
*
|
|
334
|
+
* assertOk(step(undefined), [100, 100]);
|
|
335
|
+
* assertOk(step(undefined), [200, 200]);
|
|
317
336
|
* ```
|
|
318
337
|
*
|
|
319
338
|
* @group Constructors
|
|
@@ -347,13 +366,13 @@ export const linear =
|
|
|
347
366
|
* ### Fibonacci growth
|
|
348
367
|
*
|
|
349
368
|
* ```ts
|
|
350
|
-
* import { fibonacci, testCreateDeps } from "@evolu/common";
|
|
369
|
+
* import { assertOk, fibonacci, testCreateDeps } from "@evolu/common";
|
|
351
370
|
*
|
|
352
371
|
* // 100ms, 100ms, 200ms, 300ms, 500ms, ...
|
|
353
372
|
* const step = fibonacci("100ms")(testCreateDeps());
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
373
|
+
* assertOk(step(undefined), [100, 100]);
|
|
374
|
+
* assertOk(step(undefined), [100, 100]);
|
|
375
|
+
* assertOk(step(undefined), [200, 200]);
|
|
357
376
|
* ```
|
|
358
377
|
*
|
|
359
378
|
* @group Constructors
|
|
@@ -384,7 +403,7 @@ export const fibonacci =
|
|
|
384
403
|
* ### Maintaining a fixed cadence
|
|
385
404
|
*
|
|
386
405
|
* ```ts
|
|
387
|
-
* import { fixed, take, testCreateDeps } from "@evolu/common";
|
|
406
|
+
* import { assertOk, fixed, take, testCreateDeps } from "@evolu/common";
|
|
388
407
|
*
|
|
389
408
|
* // A bounded health check and an unbounded cron-like cadence.
|
|
390
409
|
* const healthCheck = take(10)(fixed("5s"));
|
|
@@ -392,10 +411,10 @@ export const fibonacci =
|
|
|
392
411
|
*
|
|
393
412
|
* const healthDeps = testCreateDeps();
|
|
394
413
|
* const healthStep = healthCheck(healthDeps);
|
|
395
|
-
*
|
|
414
|
+
* assertOk(healthStep(undefined), [0, 5000]);
|
|
396
415
|
* healthDeps.time.advance("3s");
|
|
397
|
-
*
|
|
398
|
-
*
|
|
416
|
+
* assertOk(healthStep(undefined), [1, 2000]);
|
|
417
|
+
* assertOk(cronLike(testCreateDeps())(undefined), [0, 60000]);
|
|
399
418
|
* ```
|
|
400
419
|
*
|
|
401
420
|
* @group Constructors
|
|
@@ -464,7 +483,7 @@ const createScheduleStepMetrics = (
|
|
|
464
483
|
* ### Aligning to time windows
|
|
465
484
|
*
|
|
466
485
|
* ```ts
|
|
467
|
-
* import { testCreateDeps, windowed } from "@evolu/common";
|
|
486
|
+
* import { assertOk, testCreateDeps, windowed } from "@evolu/common";
|
|
468
487
|
*
|
|
469
488
|
* const stepAfter = (elapsed: "3s" | "7s") => {
|
|
470
489
|
* const deps = testCreateDeps();
|
|
@@ -475,8 +494,8 @@ const createScheduleStepMetrics = (
|
|
|
475
494
|
* };
|
|
476
495
|
*
|
|
477
496
|
* // At 3s the next boundary is 2s away; at 7s it is 3s away.
|
|
478
|
-
*
|
|
479
|
-
*
|
|
497
|
+
* assertOk(stepAfter("3s"), [1, 2000]);
|
|
498
|
+
* assertOk(stepAfter("7s"), [1, 3000]);
|
|
480
499
|
* ```
|
|
481
500
|
*
|
|
482
501
|
* @group Constructors
|
|
@@ -503,12 +522,18 @@ export const windowed =
|
|
|
503
522
|
* ### Scheduling one delayed recurrence
|
|
504
523
|
*
|
|
505
524
|
* ```ts
|
|
506
|
-
* import {
|
|
525
|
+
* import {
|
|
526
|
+
* assertErr,
|
|
527
|
+
* assertOk,
|
|
528
|
+
* done,
|
|
529
|
+
* fromDelay,
|
|
530
|
+
* testCreateDeps,
|
|
531
|
+
* } from "@evolu/common";
|
|
507
532
|
*
|
|
508
533
|
* // Wait one second, then stop.
|
|
509
534
|
* const step = fromDelay("1s")(testCreateDeps());
|
|
510
|
-
*
|
|
511
|
-
*
|
|
535
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
536
|
+
* assertErr(step(undefined), done());
|
|
512
537
|
* ```
|
|
513
538
|
*
|
|
514
539
|
* @group Constructors
|
|
@@ -525,15 +550,21 @@ export const fromDelay = (delay: Duration): Schedule<Millis> =>
|
|
|
525
550
|
* ### Sequencing custom delays
|
|
526
551
|
*
|
|
527
552
|
* ```ts
|
|
528
|
-
* import {
|
|
553
|
+
* import {
|
|
554
|
+
* assertErr,
|
|
555
|
+
* assertOk,
|
|
556
|
+
* done,
|
|
557
|
+
* fromDelays,
|
|
558
|
+
* testCreateDeps,
|
|
559
|
+
* } from "@evolu/common";
|
|
529
560
|
*
|
|
530
561
|
* // A custom retry sequence: 100ms, 500ms, then 2s.
|
|
531
562
|
* const custom = fromDelays("100ms", "500ms", "2s");
|
|
532
563
|
* const step = custom(testCreateDeps());
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
564
|
+
* assertOk(step(undefined), [100, 100]);
|
|
565
|
+
* assertOk(step(undefined), [500, 500]);
|
|
566
|
+
* assertOk(step(undefined), [2000, 2000]);
|
|
567
|
+
* assertErr(step(undefined), done());
|
|
537
568
|
* ```
|
|
538
569
|
*
|
|
539
570
|
* @group Constructors
|
|
@@ -552,6 +583,8 @@ export const fromDelays = (
|
|
|
552
583
|
*
|
|
553
584
|
* ```ts
|
|
554
585
|
* import {
|
|
586
|
+
* assertErr,
|
|
587
|
+
* assertOk,
|
|
555
588
|
* done,
|
|
556
589
|
* elapsed,
|
|
557
590
|
* exponential,
|
|
@@ -563,7 +596,7 @@ export const fromDelays = (
|
|
|
563
596
|
*
|
|
564
597
|
* // Track elapsed time alongside each backoff step.
|
|
565
598
|
* const withTiming = intersectSchedules(exponential("100ms"), elapsed);
|
|
566
|
-
*
|
|
599
|
+
* assertOk(withTiming(testCreateDeps())(undefined), [[100, 0], 100]);
|
|
567
600
|
*
|
|
568
601
|
* // Or stop a schedule after 30 seconds of elapsed time.
|
|
569
602
|
* const timeLimited = whileScheduleOutput((ms: Millis) => ms < 30000)(
|
|
@@ -573,7 +606,7 @@ export const fromDelays = (
|
|
|
573
606
|
* const step = timeLimited(deps);
|
|
574
607
|
* step(undefined);
|
|
575
608
|
* deps.time.advance("30s");
|
|
576
|
-
*
|
|
609
|
+
* assertErr(step(undefined), done());
|
|
577
610
|
* ```
|
|
578
611
|
*
|
|
579
612
|
* @group Constructors
|
|
@@ -593,6 +626,8 @@ export const elapsed: Schedule<Millis> = (deps) => {
|
|
|
593
626
|
*
|
|
594
627
|
* ```ts
|
|
595
628
|
* import {
|
|
629
|
+
* assertErr,
|
|
630
|
+
* assertOk,
|
|
596
631
|
* done,
|
|
597
632
|
* during,
|
|
598
633
|
* exponential,
|
|
@@ -604,16 +639,16 @@ export const elapsed: Schedule<Millis> = (deps) => {
|
|
|
604
639
|
* const timeLimited = during("30s");
|
|
605
640
|
* const deps = testCreateDeps();
|
|
606
641
|
* const step = timeLimited(deps);
|
|
607
|
-
*
|
|
642
|
+
* assertOk(step(undefined), [0, 0]);
|
|
608
643
|
* deps.time.advance("30.1s");
|
|
609
|
-
*
|
|
644
|
+
* assertErr(step(undefined), done());
|
|
610
645
|
*
|
|
611
646
|
* // Combine elapsed time with backoff for a time-boxed retry.
|
|
612
647
|
* const timedRetry = intersectSchedules(
|
|
613
648
|
* exponential("100ms"),
|
|
614
649
|
* during("10s"),
|
|
615
650
|
* );
|
|
616
|
-
*
|
|
651
|
+
* assertOk(timedRetry(testCreateDeps())(undefined), [[100, 0], 100]);
|
|
617
652
|
* ```
|
|
618
653
|
*
|
|
619
654
|
* @group Constructors
|
|
@@ -632,6 +667,7 @@ export const during = (duration: Duration): Schedule<Millis> =>
|
|
|
632
667
|
*
|
|
633
668
|
* ```ts
|
|
634
669
|
* import {
|
|
670
|
+
* assertOk,
|
|
635
671
|
* always,
|
|
636
672
|
* exponential,
|
|
637
673
|
* intersectSchedules,
|
|
@@ -640,14 +676,14 @@ export const during = (duration: Duration): Schedule<Millis> =>
|
|
|
640
676
|
*
|
|
641
677
|
* // Always emit the same label.
|
|
642
678
|
* const labeled = always("retry");
|
|
643
|
-
*
|
|
679
|
+
* assertOk(labeled(testCreateDeps())(undefined), ["retry", 0]);
|
|
644
680
|
*
|
|
645
681
|
* // Add a label while preserving exponential timing.
|
|
646
682
|
* const withLabel = intersectSchedules(
|
|
647
683
|
* exponential("100ms"),
|
|
648
684
|
* always("backoff"),
|
|
649
685
|
* );
|
|
650
|
-
*
|
|
686
|
+
* assertOk(withLabel(testCreateDeps())(undefined), [
|
|
651
687
|
* [100, "backoff"],
|
|
652
688
|
* 100,
|
|
653
689
|
* ]);
|
|
@@ -668,7 +704,7 @@ export const always = <A>(value: A): Schedule<A> =>
|
|
|
668
704
|
* ### Unfolding state
|
|
669
705
|
*
|
|
670
706
|
* ```ts
|
|
671
|
-
* import { testCreateDeps, unfoldSchedule } from "@evolu/common";
|
|
707
|
+
* import { assertOk, testCreateDeps, unfoldSchedule } from "@evolu/common";
|
|
672
708
|
*
|
|
673
709
|
* // Unfold counters, custom backoff values, or state machines.
|
|
674
710
|
* const counter = unfoldSchedule(0, (n) => n + 1);
|
|
@@ -691,12 +727,12 @@ export const always = <A>(value: A): Schedule<A> =>
|
|
|
691
727
|
* const counterStep = counter(testCreateDeps());
|
|
692
728
|
* const backoffStep = customBackoff(testCreateDeps());
|
|
693
729
|
* const phaseStep = phases(testCreateDeps());
|
|
694
|
-
*
|
|
695
|
-
*
|
|
730
|
+
* assertOk(counterStep(undefined), [0, 0]);
|
|
731
|
+
* assertOk(counterStep(undefined), [1, 0]);
|
|
696
732
|
* backoffStep(undefined);
|
|
697
733
|
* phaseStep(undefined);
|
|
698
|
-
*
|
|
699
|
-
*
|
|
734
|
+
* assertOk(backoffStep(undefined), [150, 0]);
|
|
735
|
+
* assertOk(phaseStep(undefined), ["warmup", 0]);
|
|
700
736
|
* ```
|
|
701
737
|
*
|
|
702
738
|
* @group Constructors
|
|
@@ -723,14 +759,20 @@ export const unfoldSchedule =
|
|
|
723
759
|
* ### Limiting a schedule
|
|
724
760
|
*
|
|
725
761
|
* ```ts
|
|
726
|
-
* import {
|
|
762
|
+
* import {
|
|
763
|
+
* assertErr,
|
|
764
|
+
* done,
|
|
765
|
+
* exponential,
|
|
766
|
+
* take,
|
|
767
|
+
* testCreateDeps,
|
|
768
|
+
* } from "@evolu/common";
|
|
727
769
|
*
|
|
728
770
|
* // Three exponential retries, then Done.
|
|
729
771
|
* const step = take(3)(exponential("100ms"))(testCreateDeps());
|
|
730
772
|
* step(undefined);
|
|
731
773
|
* step(undefined);
|
|
732
774
|
* step(undefined);
|
|
733
|
-
*
|
|
775
|
+
* assertErr(step(undefined), done());
|
|
734
776
|
* ```
|
|
735
777
|
*
|
|
736
778
|
* @group Limiting
|
|
@@ -757,6 +799,8 @@ export const take =
|
|
|
757
799
|
*
|
|
758
800
|
* ```ts
|
|
759
801
|
* import {
|
|
802
|
+
* assertErr,
|
|
803
|
+
* assertOk,
|
|
760
804
|
* done,
|
|
761
805
|
* exponential,
|
|
762
806
|
* maxElapsed,
|
|
@@ -766,9 +810,9 @@ export const take =
|
|
|
766
810
|
* // Retry for at most 30 seconds.
|
|
767
811
|
* const deps = testCreateDeps();
|
|
768
812
|
* const step = maxElapsed("30s")(exponential("1s"))(deps);
|
|
769
|
-
*
|
|
813
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
770
814
|
* deps.time.advance("30s");
|
|
771
|
-
*
|
|
815
|
+
* assertErr(step(undefined), done());
|
|
772
816
|
* ```
|
|
773
817
|
*
|
|
774
818
|
* @group Limiting
|
|
@@ -802,7 +846,12 @@ export const maxElapsed = (duration: Duration) => {
|
|
|
802
846
|
* ### Capping delays
|
|
803
847
|
*
|
|
804
848
|
* ```ts
|
|
805
|
-
* import {
|
|
849
|
+
* import {
|
|
850
|
+
* assertOk,
|
|
851
|
+
* exponential,
|
|
852
|
+
* maxDelay,
|
|
853
|
+
* testCreateDeps,
|
|
854
|
+
* } from "@evolu/common";
|
|
806
855
|
*
|
|
807
856
|
* // Exponential delays grow 1s, 2s, 4s, 8s, then stay capped at 10s.
|
|
808
857
|
* const step = maxDelay("10s")(exponential("1s"))(testCreateDeps());
|
|
@@ -810,7 +859,7 @@ export const maxElapsed = (duration: Duration) => {
|
|
|
810
859
|
* step(undefined);
|
|
811
860
|
* step(undefined);
|
|
812
861
|
* step(undefined);
|
|
813
|
-
*
|
|
862
|
+
* assertOk(step(undefined), [16000, 10000]);
|
|
814
863
|
* ```
|
|
815
864
|
*
|
|
816
865
|
* @group Limiting
|
|
@@ -851,6 +900,7 @@ export const maxDelay = (max: Duration) => {
|
|
|
851
900
|
*
|
|
852
901
|
* ```ts
|
|
853
902
|
* import {
|
|
903
|
+
* assertOk,
|
|
854
904
|
* exponential,
|
|
855
905
|
* jitter,
|
|
856
906
|
* spaced,
|
|
@@ -868,8 +918,8 @@ export const maxDelay = (max: Duration) => {
|
|
|
868
918
|
* // Poll around a 30s target cadence, from 27s to 33s.
|
|
869
919
|
* const polling = jitter("10%", "around")(spaced("30s"));
|
|
870
920
|
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
921
|
+
* assertOk(conservative(deps)(undefined), [1000, 875]);
|
|
922
|
+
* assertOk(polling(deps)(undefined), [30000, 30000]);
|
|
873
923
|
* ```
|
|
874
924
|
*
|
|
875
925
|
* @group Delay
|
|
@@ -910,12 +960,17 @@ const createJitter =
|
|
|
910
960
|
* ### Replacing the first delay
|
|
911
961
|
*
|
|
912
962
|
* ```ts
|
|
913
|
-
* import {
|
|
963
|
+
* import {
|
|
964
|
+
* assertOk,
|
|
965
|
+
* delayed,
|
|
966
|
+
* exponential,
|
|
967
|
+
* testCreateDeps,
|
|
968
|
+
* } from "@evolu/common";
|
|
914
969
|
*
|
|
915
970
|
* const step = delayed("1s")(exponential("100ms"))(testCreateDeps());
|
|
916
971
|
* // Only the first delay is replaced; later exponential delays are unchanged.
|
|
917
|
-
*
|
|
918
|
-
*
|
|
972
|
+
* assertOk(step(undefined), [100, 1000]);
|
|
973
|
+
* assertOk(step(undefined), [200, 200]);
|
|
919
974
|
* ```
|
|
920
975
|
*
|
|
921
976
|
* @group Delay
|
|
@@ -946,11 +1001,16 @@ export const delayed = (initialDelay: Duration) => {
|
|
|
946
1001
|
* ### Adding to every delay
|
|
947
1002
|
*
|
|
948
1003
|
* ```ts
|
|
949
|
-
* import {
|
|
1004
|
+
* import {
|
|
1005
|
+
* assertOk,
|
|
1006
|
+
* addDelay,
|
|
1007
|
+
* exponential,
|
|
1008
|
+
* testCreateDeps,
|
|
1009
|
+
* } from "@evolu/common";
|
|
950
1010
|
*
|
|
951
1011
|
* // Add 500ms to every exponential delay.
|
|
952
1012
|
* const step = addDelay("500ms")(exponential("100ms"))(testCreateDeps());
|
|
953
|
-
*
|
|
1013
|
+
* assertOk(step(undefined), [100, 600]);
|
|
954
1014
|
* ```
|
|
955
1015
|
*
|
|
956
1016
|
* @group Delay
|
|
@@ -972,7 +1032,12 @@ export const addDelay = (
|
|
|
972
1032
|
* ### Transforming delays
|
|
973
1033
|
*
|
|
974
1034
|
* ```ts
|
|
975
|
-
* import {
|
|
1035
|
+
* import {
|
|
1036
|
+
* assertOk,
|
|
1037
|
+
* exponential,
|
|
1038
|
+
* modifyDelay,
|
|
1039
|
+
* testCreateDeps,
|
|
1040
|
+
* } from "@evolu/common";
|
|
976
1041
|
*
|
|
977
1042
|
* // Arbitrary transformations can double or cap delays.
|
|
978
1043
|
* const slower = modifyDelay((delay) => delay * 2)(exponential("100ms"));
|
|
@@ -982,8 +1047,8 @@ export const addDelay = (
|
|
|
982
1047
|
* );
|
|
983
1048
|
* const deps = testCreateDeps();
|
|
984
1049
|
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
1050
|
+
* assertOk(slower(deps)(undefined), [100, 200]);
|
|
1051
|
+
* assertOk(capped(deps)(undefined), [20000, 10000]);
|
|
987
1052
|
* ```
|
|
988
1053
|
*
|
|
989
1054
|
* @group Delay
|
|
@@ -1018,21 +1083,26 @@ export const modifyDelay =
|
|
|
1018
1083
|
* ### Compensating for execution time
|
|
1019
1084
|
*
|
|
1020
1085
|
* ```ts
|
|
1021
|
-
* import {
|
|
1086
|
+
* import {
|
|
1087
|
+
* assertOk,
|
|
1088
|
+
* compensate,
|
|
1089
|
+
* spaced,
|
|
1090
|
+
* testCreateDeps,
|
|
1091
|
+
* } from "@evolu/common";
|
|
1022
1092
|
*
|
|
1023
1093
|
* const fastDeps = testCreateDeps();
|
|
1024
1094
|
* const fastStep = compensate(spaced("5s"))(fastDeps);
|
|
1025
|
-
*
|
|
1095
|
+
* assertOk(fastStep(undefined), [5000, 5000]);
|
|
1026
1096
|
* // Five seconds waiting plus one second working leaves four seconds.
|
|
1027
1097
|
* fastDeps.time.advance("6s");
|
|
1028
|
-
*
|
|
1098
|
+
* assertOk(fastStep(undefined), [5000, 4000]);
|
|
1029
1099
|
*
|
|
1030
1100
|
* const slowDeps = testCreateDeps();
|
|
1031
1101
|
* const slowStep = compensate(spaced("5s"))(slowDeps);
|
|
1032
|
-
*
|
|
1102
|
+
* assertOk(slowStep(undefined), [5000, 5000]);
|
|
1033
1103
|
* // Five seconds waiting plus six seconds working leaves no delay.
|
|
1034
1104
|
* slowDeps.time.advance("11s");
|
|
1035
|
-
*
|
|
1105
|
+
* assertOk(slowStep(undefined), [5000, 0]);
|
|
1036
1106
|
* ```
|
|
1037
1107
|
*
|
|
1038
1108
|
* @group Delay
|
|
@@ -1068,6 +1138,8 @@ export const compensate =
|
|
|
1068
1138
|
*
|
|
1069
1139
|
* ```ts
|
|
1070
1140
|
* import {
|
|
1141
|
+
* assertErr,
|
|
1142
|
+
* assertOk,
|
|
1071
1143
|
* done,
|
|
1072
1144
|
* exponential,
|
|
1073
1145
|
* testCreateDeps,
|
|
@@ -1082,8 +1154,8 @@ export const compensate =
|
|
|
1082
1154
|
* (error: MyError) => error.type === "Transient",
|
|
1083
1155
|
* )(exponential("100ms"));
|
|
1084
1156
|
* const step = retryTransient(testCreateDeps());
|
|
1085
|
-
*
|
|
1086
|
-
*
|
|
1157
|
+
* assertOk(step({ type: "Transient" }), [100, 100]);
|
|
1158
|
+
* assertErr(step({ type: "Fatal" }), done());
|
|
1087
1159
|
* ```
|
|
1088
1160
|
*
|
|
1089
1161
|
* @group Filtering
|
|
@@ -1114,6 +1186,8 @@ export const whileScheduleInput =
|
|
|
1114
1186
|
*
|
|
1115
1187
|
* ```ts
|
|
1116
1188
|
* import {
|
|
1189
|
+
* assertErr,
|
|
1190
|
+
* assertOk,
|
|
1117
1191
|
* done,
|
|
1118
1192
|
* exponential,
|
|
1119
1193
|
* testCreateDeps,
|
|
@@ -1128,8 +1202,8 @@ export const whileScheduleInput =
|
|
|
1128
1202
|
* (error: MyError) => error.type === "Fatal",
|
|
1129
1203
|
* )(exponential("100ms"));
|
|
1130
1204
|
* const step = stopOnFatal(testCreateDeps());
|
|
1131
|
-
*
|
|
1132
|
-
*
|
|
1205
|
+
* assertOk(step({ type: "Transient" }), [100, 100]);
|
|
1206
|
+
* assertErr(step({ type: "Fatal" }), done());
|
|
1133
1207
|
* ```
|
|
1134
1208
|
*
|
|
1135
1209
|
* @group Filtering
|
|
@@ -1159,6 +1233,7 @@ export const untilScheduleInput =
|
|
|
1159
1233
|
*
|
|
1160
1234
|
* ```ts
|
|
1161
1235
|
* import {
|
|
1236
|
+
* assertErr,
|
|
1162
1237
|
* done,
|
|
1163
1238
|
* exponential,
|
|
1164
1239
|
* testCreateDeps,
|
|
@@ -1174,7 +1249,7 @@ export const untilScheduleInput =
|
|
|
1174
1249
|
* step(undefined);
|
|
1175
1250
|
* step(undefined);
|
|
1176
1251
|
* step(undefined);
|
|
1177
|
-
*
|
|
1252
|
+
* assertErr(step(undefined), done());
|
|
1178
1253
|
* ```
|
|
1179
1254
|
*
|
|
1180
1255
|
* @group Filtering
|
|
@@ -1206,6 +1281,7 @@ export const whileScheduleOutput =
|
|
|
1206
1281
|
*
|
|
1207
1282
|
* ```ts
|
|
1208
1283
|
* import {
|
|
1284
|
+
* assertErr,
|
|
1209
1285
|
* done,
|
|
1210
1286
|
* exponential,
|
|
1211
1287
|
* testCreateDeps,
|
|
@@ -1222,7 +1298,7 @@ export const whileScheduleOutput =
|
|
|
1222
1298
|
* step(undefined);
|
|
1223
1299
|
* step(undefined);
|
|
1224
1300
|
* step(undefined);
|
|
1225
|
-
*
|
|
1301
|
+
* assertErr(step(undefined), done());
|
|
1226
1302
|
* ```
|
|
1227
1303
|
*
|
|
1228
1304
|
* @group Filtering
|
|
@@ -1256,6 +1332,7 @@ export const untilScheduleOutput =
|
|
|
1256
1332
|
*
|
|
1257
1333
|
* ```ts
|
|
1258
1334
|
* import {
|
|
1335
|
+
* assertOk,
|
|
1259
1336
|
* exponential,
|
|
1260
1337
|
* resetScheduleAfter,
|
|
1261
1338
|
* testCreateDeps,
|
|
@@ -1264,9 +1341,9 @@ export const untilScheduleOutput =
|
|
|
1264
1341
|
* const backoff = resetScheduleAfter("1m")(exponential("1s"));
|
|
1265
1342
|
* const deps = testCreateDeps();
|
|
1266
1343
|
* const step = backoff(deps);
|
|
1267
|
-
*
|
|
1344
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
1268
1345
|
* deps.time.advance("1m");
|
|
1269
|
-
*
|
|
1346
|
+
* assertOk(step(undefined), [1000, 1000]);
|
|
1270
1347
|
* ```
|
|
1271
1348
|
*
|
|
1272
1349
|
* @group State
|
|
@@ -1304,6 +1381,7 @@ export const resetScheduleAfter = (
|
|
|
1304
1381
|
*
|
|
1305
1382
|
* ```ts
|
|
1306
1383
|
* import {
|
|
1384
|
+
* assertOk,
|
|
1307
1385
|
* exponential,
|
|
1308
1386
|
* mapSchedule,
|
|
1309
1387
|
* testCreateDeps,
|
|
@@ -1315,7 +1393,7 @@ export const resetScheduleAfter = (
|
|
|
1315
1393
|
* doubled: delay * 2,
|
|
1316
1394
|
* }))(exponential("100ms"));
|
|
1317
1395
|
* const step = schedule(testCreateDeps());
|
|
1318
|
-
*
|
|
1396
|
+
* assertOk(step(undefined), [{ delay: 100, doubled: 200 }, 100]);
|
|
1319
1397
|
* ```
|
|
1320
1398
|
*
|
|
1321
1399
|
* @group Transform
|
|
@@ -1344,7 +1422,15 @@ export const mapSchedule =
|
|
|
1344
1422
|
* ### Passing through input
|
|
1345
1423
|
*
|
|
1346
1424
|
* ```ts
|
|
1347
|
-
* import {
|
|
1425
|
+
* import {
|
|
1426
|
+
* assertEqual,
|
|
1427
|
+
* assertOk,
|
|
1428
|
+
* assertType,
|
|
1429
|
+
* Data,
|
|
1430
|
+
* exponential,
|
|
1431
|
+
* passthrough,
|
|
1432
|
+
* testCreateDeps,
|
|
1433
|
+
* } from "@evolu/common";
|
|
1348
1434
|
*
|
|
1349
1435
|
* interface MyError {
|
|
1350
1436
|
* readonly message: string;
|
|
@@ -1356,8 +1442,16 @@ export const mapSchedule =
|
|
|
1356
1442
|
* const error = { message: "Unavailable" };
|
|
1357
1443
|
* const deps = testCreateDeps();
|
|
1358
1444
|
*
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1445
|
+
* const identityResult = identity(deps)(error);
|
|
1446
|
+
* assertOk(identityResult);
|
|
1447
|
+
* assertType(Data, identityResult.value);
|
|
1448
|
+
* assertEqual(identityResult.value, [error, 0]);
|
|
1449
|
+
*
|
|
1450
|
+
* const inputResult = withInput(deps)(error);
|
|
1451
|
+
* assertOk(inputResult);
|
|
1452
|
+
* assertType(Data, inputResult.value);
|
|
1453
|
+
* const inputValue: Data = inputResult.value;
|
|
1454
|
+
* assertEqual(inputValue, [error, 100]);
|
|
1361
1455
|
* ```
|
|
1362
1456
|
*
|
|
1363
1457
|
* @group Constructors
|
|
@@ -1393,6 +1487,7 @@ export function passthrough<Output, Input>(
|
|
|
1393
1487
|
*
|
|
1394
1488
|
* ```ts
|
|
1395
1489
|
* import {
|
|
1490
|
+
* assertOk,
|
|
1396
1491
|
* exponential,
|
|
1397
1492
|
* foldSchedule,
|
|
1398
1493
|
* minMillis,
|
|
@@ -1422,9 +1517,9 @@ export function passthrough<Output, Input>(
|
|
|
1422
1517
|
* const deps = testCreateDeps();
|
|
1423
1518
|
* const totalStep = withTotal(deps);
|
|
1424
1519
|
* totalStep(undefined);
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
1427
|
-
*
|
|
1520
|
+
* assertOk(totalStep(undefined), [300, 200]);
|
|
1521
|
+
* assertOk(collected(deps)(undefined), [[1000], 1000]);
|
|
1522
|
+
* assertOk(counted(deps)(undefined), [
|
|
1428
1523
|
* { attempts: 1, lastDelay: 100 },
|
|
1429
1524
|
* 100,
|
|
1430
1525
|
* ]);
|
|
@@ -1457,12 +1552,17 @@ export const foldSchedule =
|
|
|
1457
1552
|
* ### Counting repetitions
|
|
1458
1553
|
*
|
|
1459
1554
|
* ```ts
|
|
1460
|
-
* import {
|
|
1555
|
+
* import {
|
|
1556
|
+
* assertOk,
|
|
1557
|
+
* exponential,
|
|
1558
|
+
* repetitions,
|
|
1559
|
+
* testCreateDeps,
|
|
1560
|
+
* } from "@evolu/common";
|
|
1461
1561
|
*
|
|
1462
1562
|
* // Count retries while preserving exponential timing.
|
|
1463
1563
|
* const step = repetitions(exponential("100ms"))(testCreateDeps());
|
|
1464
|
-
*
|
|
1465
|
-
*
|
|
1564
|
+
* assertOk(step(undefined), [0, 100]);
|
|
1565
|
+
* assertOk(step(undefined), [1, 200]);
|
|
1466
1566
|
* ```
|
|
1467
1567
|
*
|
|
1468
1568
|
* @group Transform
|
|
@@ -1481,6 +1581,8 @@ export const repetitions = <Output, Input>(
|
|
|
1481
1581
|
*
|
|
1482
1582
|
* ```ts
|
|
1483
1583
|
* import {
|
|
1584
|
+
* assertEqual,
|
|
1585
|
+
* assertOk,
|
|
1484
1586
|
* delays,
|
|
1485
1587
|
* exponential,
|
|
1486
1588
|
* tapScheduleOutput,
|
|
@@ -1496,9 +1598,9 @@ export const repetitions = <Output, Input>(
|
|
|
1496
1598
|
* })(delays(exponential("100ms")));
|
|
1497
1599
|
* const deps = testCreateDeps();
|
|
1498
1600
|
*
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1501
|
-
*
|
|
1601
|
+
* assertOk(monitorDelays(deps)(undefined), [100, 100]);
|
|
1602
|
+
* assertOk(logged(deps)(undefined), [100, 100]);
|
|
1603
|
+
* assertEqual(observed, [100]);
|
|
1502
1604
|
* ```
|
|
1503
1605
|
*
|
|
1504
1606
|
* @group Transform
|
|
@@ -1526,6 +1628,7 @@ export const delays =
|
|
|
1526
1628
|
*
|
|
1527
1629
|
* ```ts
|
|
1528
1630
|
* import {
|
|
1631
|
+
* assertOk,
|
|
1529
1632
|
* collectAllScheduleOutputs,
|
|
1530
1633
|
* spaced,
|
|
1531
1634
|
* take,
|
|
@@ -1536,7 +1639,7 @@ export const delays =
|
|
|
1536
1639
|
* const collected = collectAllScheduleOutputs(take(3)(spaced("100ms")));
|
|
1537
1640
|
* const step = collected(testCreateDeps());
|
|
1538
1641
|
* step(undefined);
|
|
1539
|
-
*
|
|
1642
|
+
* assertOk(step(undefined), [[100, 100], 100]);
|
|
1540
1643
|
* ```
|
|
1541
1644
|
*
|
|
1542
1645
|
* @group Collection
|
|
@@ -1558,6 +1661,7 @@ export const collectAllScheduleOutputs = <Output, Input>(
|
|
|
1558
1661
|
*
|
|
1559
1662
|
* ```ts
|
|
1560
1663
|
* import {
|
|
1664
|
+
* assertOk,
|
|
1561
1665
|
* collectScheduleInputs,
|
|
1562
1666
|
* exponential,
|
|
1563
1667
|
* take,
|
|
@@ -1571,7 +1675,7 @@ export const collectAllScheduleOutputs = <Output, Input>(
|
|
|
1571
1675
|
* const errorHistory = collectScheduleInputs(retries);
|
|
1572
1676
|
* const step = errorHistory(testCreateDeps());
|
|
1573
1677
|
* step("network");
|
|
1574
|
-
*
|
|
1678
|
+
* assertOk(step("timeout"), [["network", "timeout"], 200]);
|
|
1575
1679
|
* ```
|
|
1576
1680
|
*
|
|
1577
1681
|
* @group Collection
|
|
@@ -1591,6 +1695,8 @@ export const collectScheduleInputs = <Output, Input>(
|
|
|
1591
1695
|
*
|
|
1592
1696
|
* ```ts
|
|
1593
1697
|
* import {
|
|
1698
|
+
* assertErr,
|
|
1699
|
+
* assertOk,
|
|
1594
1700
|
* collectWhileScheduleOutput,
|
|
1595
1701
|
* done,
|
|
1596
1702
|
* exponential,
|
|
@@ -1606,8 +1712,8 @@ export const collectScheduleInputs = <Output, Input>(
|
|
|
1606
1712
|
* step(undefined);
|
|
1607
1713
|
* step(undefined);
|
|
1608
1714
|
* step(undefined);
|
|
1609
|
-
*
|
|
1610
|
-
*
|
|
1715
|
+
* assertOk(step(undefined), [[100, 200, 400, 800], 800]);
|
|
1716
|
+
* assertErr(step(undefined), done());
|
|
1611
1717
|
* ```
|
|
1612
1718
|
*
|
|
1613
1719
|
* @group Collection
|
|
@@ -1629,6 +1735,8 @@ export const collectWhileScheduleOutput =
|
|
|
1629
1735
|
*
|
|
1630
1736
|
* ```ts
|
|
1631
1737
|
* import {
|
|
1738
|
+
* assertErr,
|
|
1739
|
+
* assertOk,
|
|
1632
1740
|
* collectUntilScheduleOutput,
|
|
1633
1741
|
* done,
|
|
1634
1742
|
* exponential,
|
|
@@ -1644,8 +1752,8 @@ export const collectWhileScheduleOutput =
|
|
|
1644
1752
|
* step(undefined);
|
|
1645
1753
|
* step(undefined);
|
|
1646
1754
|
* step(undefined);
|
|
1647
|
-
*
|
|
1648
|
-
*
|
|
1755
|
+
* assertOk(step(undefined), [[100, 200, 400, 800], 800]);
|
|
1756
|
+
* assertErr(step(undefined), done());
|
|
1649
1757
|
* ```
|
|
1650
1758
|
*
|
|
1651
1759
|
* @group Collection
|
|
@@ -1667,6 +1775,7 @@ export const collectUntilScheduleOutput =
|
|
|
1667
1775
|
*
|
|
1668
1776
|
* ```ts
|
|
1669
1777
|
* import {
|
|
1778
|
+
* assertOk,
|
|
1670
1779
|
* exponential,
|
|
1671
1780
|
* fixed,
|
|
1672
1781
|
* sequenceSchedules,
|
|
@@ -1683,7 +1792,7 @@ export const collectUntilScheduleOutput =
|
|
|
1683
1792
|
* step(undefined);
|
|
1684
1793
|
* step(undefined);
|
|
1685
1794
|
* step(undefined);
|
|
1686
|
-
*
|
|
1795
|
+
* assertOk(step(undefined), [0, 500]);
|
|
1687
1796
|
* ```
|
|
1688
1797
|
*
|
|
1689
1798
|
* @group Composition
|
|
@@ -1719,6 +1828,8 @@ export const sequenceSchedules =
|
|
|
1719
1828
|
*
|
|
1720
1829
|
* ```ts
|
|
1721
1830
|
* import {
|
|
1831
|
+
* assertErr,
|
|
1832
|
+
* assertOk,
|
|
1722
1833
|
* done,
|
|
1723
1834
|
* exponential,
|
|
1724
1835
|
* forever,
|
|
@@ -1734,9 +1845,9 @@ export const sequenceSchedules =
|
|
|
1734
1845
|
* take(5)(exponential("1s")),
|
|
1735
1846
|
* maxElapsed("30s")(forever),
|
|
1736
1847
|
* )(deps);
|
|
1737
|
-
*
|
|
1848
|
+
* assertOk(step(undefined), [[1000, 0], 1000]);
|
|
1738
1849
|
* deps.time.advance("30s");
|
|
1739
|
-
*
|
|
1850
|
+
* assertErr(step(undefined), done());
|
|
1740
1851
|
* ```
|
|
1741
1852
|
*
|
|
1742
1853
|
* @group Composition
|
|
@@ -1773,6 +1884,8 @@ export const intersectSchedules =
|
|
|
1773
1884
|
*
|
|
1774
1885
|
* ```ts
|
|
1775
1886
|
* import {
|
|
1887
|
+
* assertErr,
|
|
1888
|
+
* assertOk,
|
|
1776
1889
|
* done,
|
|
1777
1890
|
* spaced,
|
|
1778
1891
|
* take,
|
|
@@ -1786,9 +1899,9 @@ export const intersectSchedules =
|
|
|
1786
1899
|
* take(2)(spaced("200ms")),
|
|
1787
1900
|
* );
|
|
1788
1901
|
* const step = either(testCreateDeps());
|
|
1789
|
-
*
|
|
1790
|
-
*
|
|
1791
|
-
*
|
|
1902
|
+
* assertOk(step(undefined), [100, 100]);
|
|
1903
|
+
* assertOk(step(undefined), [200, 200]);
|
|
1904
|
+
* assertErr(step(undefined), done());
|
|
1792
1905
|
* ```
|
|
1793
1906
|
*
|
|
1794
1907
|
* @group Composition
|
|
@@ -1841,6 +1954,8 @@ export const unionSchedules =
|
|
|
1841
1954
|
*
|
|
1842
1955
|
* ```ts
|
|
1843
1956
|
* import {
|
|
1957
|
+
* assertErr,
|
|
1958
|
+
* assertOk,
|
|
1844
1959
|
* done,
|
|
1845
1960
|
* exponential,
|
|
1846
1961
|
* take,
|
|
@@ -1860,10 +1975,10 @@ export const unionSchedules =
|
|
|
1860
1975
|
* )(exponential("100ms")),
|
|
1861
1976
|
* );
|
|
1862
1977
|
* const step = awsWithThrottling(testCreateDeps());
|
|
1863
|
-
*
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
1866
|
-
*
|
|
1978
|
+
* assertOk(step({ type: "Throttled" }), [1000, 1000]);
|
|
1979
|
+
* assertOk(step({ type: "NetworkError" }), [100, 100]);
|
|
1980
|
+
* assertOk(step({ type: "Throttled" }), [2000, 2000]);
|
|
1981
|
+
* assertErr(step({ type: "NetworkError" }), done());
|
|
1867
1982
|
* ```
|
|
1868
1983
|
*
|
|
1869
1984
|
* @group Composition
|
|
@@ -1896,6 +2011,7 @@ export const whenInput =
|
|
|
1896
2011
|
*
|
|
1897
2012
|
* ```ts
|
|
1898
2013
|
* import {
|
|
2014
|
+
* assertEqual,
|
|
1899
2015
|
* exponential,
|
|
1900
2016
|
* retryStrategyAws,
|
|
1901
2017
|
* tapScheduleOutput,
|
|
@@ -1918,8 +2034,8 @@ export const whenInput =
|
|
|
1918
2034
|
* logged(deps)(undefined);
|
|
1919
2035
|
* tracked(deps)(undefined);
|
|
1920
2036
|
*
|
|
1921
|
-
*
|
|
1922
|
-
*
|
|
2037
|
+
* assertEqual(messages, ["Next delay: 100ms"]);
|
|
2038
|
+
* assertEqual(recordedCandidates, [50]);
|
|
1923
2039
|
* ```
|
|
1924
2040
|
*
|
|
1925
2041
|
* @group Side effects
|
|
@@ -1947,6 +2063,7 @@ export const tapScheduleOutput =
|
|
|
1947
2063
|
*
|
|
1948
2064
|
* ```ts
|
|
1949
2065
|
* import {
|
|
2066
|
+
* assertEqual,
|
|
1950
2067
|
* exponential,
|
|
1951
2068
|
* tapScheduleInput,
|
|
1952
2069
|
* testCreateDeps,
|
|
@@ -1973,8 +2090,8 @@ export const tapScheduleOutput =
|
|
|
1973
2090
|
* logged(deps)(error);
|
|
1974
2091
|
* tracked(deps)(error);
|
|
1975
2092
|
*
|
|
1976
|
-
*
|
|
1977
|
-
*
|
|
2093
|
+
* assertEqual(messages, ["Retrying after error: NetworkError"]);
|
|
2094
|
+
* assertEqual(reasons, ["NetworkError"]);
|
|
1978
2095
|
* ```
|
|
1979
2096
|
*
|
|
1980
2097
|
* @group Side effects
|