@evolu/common 8.7.0 → 8.9.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 +21 -21
- package/dist/src/Array.js +5 -5
- package/dist/src/Assert.d.ts +498 -141
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +648 -99
- package/dist/src/{Buffer.d.ts → Binary.d.ts} +85 -12
- package/dist/src/Binary.d.ts.map +1 -0
- package/dist/src/{Buffer.js → Binary.js} +206 -24
- package/dist/src/Console.d.ts +2 -10
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +6 -12
- package/dist/src/Crypto.d.ts +5 -5
- package/dist/src/Crypto.js +1 -1
- package/dist/src/Eq.d.ts +35 -40
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +51 -87
- package/dist/src/Function.d.ts +9 -14
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +7 -9
- package/dist/src/Http.d.ts +6 -7
- package/dist/src/Http.d.ts.map +1 -1
- package/dist/src/LeakDetector.d.ts.map +1 -1
- package/dist/src/LeakDetector.js +1 -0
- package/dist/src/LockManager.d.ts +1 -1
- package/dist/src/LockManager.js +1 -1
- package/dist/src/Lookup.d.ts +3 -2
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +4 -3
- package/dist/src/Number.d.ts +1 -1
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +1 -1
- package/dist/src/Object.d.ts +4 -4
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +5 -4
- package/dist/src/Option.d.ts +1 -2
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +1 -2
- package/dist/src/Platform.js +2 -0
- package/dist/src/Polyfills.d.ts +6 -0
- package/dist/src/Polyfills.d.ts.map +1 -1
- package/dist/src/Polyfills.js +10 -1
- package/dist/src/Random.d.ts +1 -1
- package/dist/src/Result.d.ts +49 -54
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +17 -22
- package/dist/src/Set.d.ts +6 -6
- package/dist/src/Set.js +2 -2
- package/dist/src/Sqlite.js +1 -1
- package/dist/src/String.js +3 -2
- package/dist/src/Task.d.ts +32 -32
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +20 -22
- package/dist/src/Test.d.ts +31 -3
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +46 -3
- package/dist/src/Time.d.ts +3 -11
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +10 -18
- package/dist/src/Type.d.ts +87 -85
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +70 -63
- package/dist/src/Types.d.ts +12 -12
- package/dist/src/Types.js +1 -1
- package/dist/src/WebSocket.d.ts +4 -7
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/Worker.d.ts +1 -1
- package/dist/src/Worker.js +7 -7
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/intl/_en.d.ts.map +1 -1
- package/dist/src/intl/_en.js +1 -1
- package/dist/src/intl/ar.d.ts.map +1 -1
- package/dist/src/intl/ar.js +1 -1
- package/dist/src/intl/bn.d.ts.map +1 -1
- package/dist/src/intl/bn.js +1 -1
- package/dist/src/intl/ca.d.ts.map +1 -1
- package/dist/src/intl/ca.js +1 -1
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +1 -1
- package/dist/src/intl/da.d.ts.map +1 -1
- package/dist/src/intl/da.js +1 -1
- package/dist/src/intl/de.d.ts.map +1 -1
- package/dist/src/intl/de.js +1 -1
- package/dist/src/intl/el.d.ts.map +1 -1
- package/dist/src/intl/el.js +1 -1
- package/dist/src/intl/es.d.ts.map +1 -1
- package/dist/src/intl/es.js +1 -1
- package/dist/src/intl/fa.d.ts.map +1 -1
- package/dist/src/intl/fa.js +1 -1
- package/dist/src/intl/fi.d.ts.map +1 -1
- package/dist/src/intl/fi.js +1 -1
- package/dist/src/intl/fil.d.ts.map +1 -1
- package/dist/src/intl/fil.js +1 -1
- package/dist/src/intl/fr.d.ts.map +1 -1
- package/dist/src/intl/fr.js +1 -1
- package/dist/src/intl/he.d.ts.map +1 -1
- package/dist/src/intl/he.js +1 -1
- package/dist/src/intl/hi.d.ts.map +1 -1
- package/dist/src/intl/hi.js +1 -1
- package/dist/src/intl/hr.d.ts.map +1 -1
- package/dist/src/intl/hr.js +1 -1
- package/dist/src/intl/hu.d.ts.map +1 -1
- package/dist/src/intl/hu.js +1 -1
- package/dist/src/intl/id.d.ts.map +1 -1
- package/dist/src/intl/id.js +1 -1
- package/dist/src/intl/it.d.ts.map +1 -1
- package/dist/src/intl/it.js +1 -1
- package/dist/src/intl/ja.d.ts.map +1 -1
- package/dist/src/intl/ja.js +1 -1
- package/dist/src/intl/ko.d.ts.map +1 -1
- package/dist/src/intl/ko.js +1 -1
- package/dist/src/intl/ml.d.ts.map +1 -1
- package/dist/src/intl/ml.js +1 -1
- package/dist/src/intl/mr.d.ts.map +1 -1
- package/dist/src/intl/mr.js +1 -1
- package/dist/src/intl/ms.d.ts.map +1 -1
- package/dist/src/intl/ms.js +1 -1
- package/dist/src/intl/nb.d.ts.map +1 -1
- package/dist/src/intl/nb.js +1 -1
- package/dist/src/intl/nl.d.ts.map +1 -1
- package/dist/src/intl/nl.js +1 -1
- package/dist/src/intl/pa.d.ts.map +1 -1
- package/dist/src/intl/pa.js +1 -1
- package/dist/src/intl/pl.d.ts.map +1 -1
- package/dist/src/intl/pl.js +1 -1
- package/dist/src/intl/pt-BR.d.ts.map +1 -1
- package/dist/src/intl/pt-BR.js +1 -1
- package/dist/src/intl/pt.d.ts.map +1 -1
- package/dist/src/intl/pt.js +1 -1
- package/dist/src/intl/ro.d.ts.map +1 -1
- package/dist/src/intl/ro.js +1 -1
- package/dist/src/intl/sk.d.ts.map +1 -1
- package/dist/src/intl/sk.js +1 -1
- package/dist/src/intl/sl.d.ts.map +1 -1
- package/dist/src/intl/sl.js +1 -1
- package/dist/src/intl/sv.d.ts.map +1 -1
- package/dist/src/intl/sv.js +1 -1
- package/dist/src/intl/sw.d.ts.map +1 -1
- package/dist/src/intl/sw.js +1 -1
- package/dist/src/intl/ta.d.ts.map +1 -1
- package/dist/src/intl/ta.js +1 -1
- package/dist/src/intl/te.d.ts.map +1 -1
- package/dist/src/intl/te.js +1 -1
- package/dist/src/intl/th.d.ts.map +1 -1
- package/dist/src/intl/th.js +1 -1
- package/dist/src/intl/tr.d.ts.map +1 -1
- package/dist/src/intl/tr.js +1 -1
- package/dist/src/intl/uk.d.ts.map +1 -1
- package/dist/src/intl/uk.js +1 -1
- package/dist/src/intl/ur.d.ts.map +1 -1
- package/dist/src/intl/ur.js +1 -1
- package/dist/src/intl/vi.d.ts.map +1 -1
- package/dist/src/intl/vi.js +1 -1
- package/dist/src/intl/zh-CN.d.ts.map +1 -1
- package/dist/src/intl/zh-CN.js +1 -1
- package/dist/src/intl/zh-TW.d.ts.map +1 -1
- package/dist/src/intl/zh-TW.js +1 -1
- package/dist/src/local-first/Evolu.d.ts +12 -12
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +2 -2
- package/dist/src/local-first/Protocol.d.ts +14 -76
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +29 -206
- package/dist/src/local-first/Query.d.ts +11 -11
- package/dist/src/local-first/Query.js +6 -6
- package/dist/src/local-first/Relay.d.ts +2 -2
- package/dist/src/local-first/Schema.d.ts +3 -5
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +2 -4
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +5 -5
- package/dist/src/local-first/Storage.js +4 -4
- package/dist/src/local-first/Timestamp.d.ts +9 -0
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +13 -10
- package/package.json +7 -4
- package/src/Array.test.ts +809 -0
- package/src/Array.ts +21 -21
- package/src/Assert.test.ts +1232 -0
- package/src/Assert.ts +1023 -227
- package/src/BigInt.test.ts +28 -0
- package/src/Binary.test.ts +1128 -0
- package/src/{Buffer.ts → Binary.ts} +273 -46
- package/src/Brand.test.ts +90 -0
- package/src/Cache.test.ts +183 -0
- package/src/Callbacks.test.ts +66 -0
- package/src/Console.test.ts +809 -0
- package/src/Console.ts +9 -17
- package/src/Crypto.test.ts +138 -0
- package/src/Crypto.ts +5 -5
- package/src/Eq.test.ts +333 -0
- package/src/Eq.ts +110 -176
- package/src/Error.test.ts +118 -0
- package/src/Function.test.ts +204 -0
- package/src/Function.ts +10 -15
- package/src/Http.test.ts +816 -0
- package/src/Http.ts +6 -7
- package/src/LeakDetector.test.ts +210 -0
- package/src/LeakDetector.ts +1 -0
- package/src/LockManager.ts +2 -2
- package/src/Lookup.test.ts +418 -0
- package/src/Lookup.ts +4 -3
- package/src/Microtask.test.ts +140 -0
- package/src/Number.test.ts +218 -0
- package/src/Number.ts +2 -2
- package/src/Object.test.ts +293 -0
- package/src/Object.ts +5 -4
- package/src/Option.test.ts +104 -0
- package/src/Option.ts +1 -2
- package/src/Order.test.ts +56 -0
- package/src/Platform.ts +2 -0
- package/src/Polyfills.ts +9 -4
- package/src/Random.test.ts +89 -0
- package/src/Random.ts +1 -1
- package/src/Ref.test.ts +139 -0
- package/src/RefCount.test.ts +184 -0
- package/src/Relation.test.ts +505 -0
- package/src/Resource.test.ts +4623 -0
- package/src/Result.test.ts +1829 -0
- package/src/Result.ts +49 -54
- package/src/Schedule.test.ts +1554 -0
- package/src/Set.test.ts +279 -0
- package/src/Set.ts +6 -6
- package/src/Sqlite.ts +1 -1
- package/src/Store.test.ts +288 -0
- package/src/String.test.ts +54 -0
- package/src/String.ts +3 -3
- package/src/Task.test.ts +10820 -0
- package/src/Task.ts +38 -43
- package/src/Test.test.ts +88 -0
- package/src/Test.ts +49 -3
- package/src/Time.test.ts +926 -0
- package/src/Time.ts +13 -21
- package/src/Type.base64.test.ts +88 -0
- package/src/Type.test.ts +20465 -0
- package/src/Type.ts +114 -111
- package/src/Types.test.ts +324 -0
- package/src/Types.ts +13 -13
- package/src/WebSocket.ts +4 -7
- package/src/Worker.test.ts +755 -0
- package/src/Worker.ts +13 -18
- package/src/index.ts +1 -1
- package/src/intl/_en.ts +1 -1
- package/src/intl/ar.ts +1 -1
- package/src/intl/bn.ts +1 -1
- package/src/intl/ca.ts +1 -1
- package/src/intl/cs.ts +1 -1
- package/src/intl/da.ts +1 -1
- package/src/intl/de.ts +1 -1
- package/src/intl/el.ts +1 -1
- package/src/intl/es.ts +1 -1
- package/src/intl/fa.ts +1 -1
- package/src/intl/fi.ts +1 -1
- package/src/intl/fil.ts +1 -1
- package/src/intl/fr.ts +1 -1
- package/src/intl/he.ts +1 -1
- package/src/intl/hi.ts +1 -1
- package/src/intl/hr.ts +1 -1
- package/src/intl/hu.ts +1 -1
- package/src/intl/id.ts +1 -1
- package/src/intl/intl.test.ts +3106 -0
- package/src/intl/it.ts +1 -1
- package/src/intl/ja.ts +1 -1
- package/src/intl/ko.ts +1 -1
- package/src/intl/ml.ts +1 -1
- package/src/intl/mr.ts +1 -1
- package/src/intl/ms.ts +1 -1
- package/src/intl/nb.ts +1 -1
- package/src/intl/nl.ts +1 -1
- package/src/intl/pa.ts +1 -1
- package/src/intl/pl.ts +1 -1
- package/src/intl/pt-BR.ts +1 -1
- package/src/intl/pt.ts +1 -1
- package/src/intl/ro.ts +1 -1
- package/src/intl/sk.ts +1 -1
- package/src/intl/sl.ts +1 -1
- package/src/intl/sv.ts +1 -1
- package/src/intl/sw.ts +1 -1
- package/src/intl/ta.ts +1 -1
- package/src/intl/te.ts +1 -1
- package/src/intl/th.ts +1 -1
- package/src/intl/tr.ts +1 -1
- package/src/intl/uk.ts +1 -1
- package/src/intl/ur.ts +1 -1
- package/src/intl/vi.ts +1 -1
- package/src/intl/zh-CN.ts +1 -1
- package/src/intl/zh-TW.ts +1 -1
- package/src/local-first/Evolu.test.ts +1921 -0
- package/src/local-first/Evolu.ts +18 -14
- package/src/local-first/Owner.test.ts +83 -0
- package/src/local-first/Protocol.test.ts +1037 -0
- package/src/local-first/Protocol.ts +58 -261
- package/src/local-first/Query.test.ts +349 -0
- package/src/local-first/Query.ts +11 -11
- package/src/local-first/Relay.ts +2 -2
- package/src/local-first/Schema.ts +3 -5
- package/src/local-first/Shared.test.ts +1828 -0
- package/src/local-first/Shared.ts +9 -8
- package/src/local-first/Storage.ts +4 -4
- package/src/local-first/Timestamp.test.ts +374 -0
- package/src/local-first/Timestamp.ts +22 -10
- package/dist/src/Buffer.d.ts.map +0 -1
package/dist/src/Task.js
CHANGED
|
@@ -128,7 +128,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
128
128
|
* });
|
|
129
129
|
*
|
|
130
130
|
* const result = await run(getUser(user.id));
|
|
131
|
-
* assertType<Result<User, UserNotFoundError
|
|
131
|
+
* assertType<typeof result, Result<User, UserNotFoundError>>();
|
|
132
132
|
* assertOk(result, user);
|
|
133
133
|
* ```
|
|
134
134
|
*
|
|
@@ -233,11 +233,11 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
233
233
|
* await using run = createRun();
|
|
234
234
|
* const result = await run(getUserWithProfile("user-1"));
|
|
235
235
|
* assertType<
|
|
236
|
+
* typeof result,
|
|
236
237
|
* Result<
|
|
237
238
|
* { readonly user: User; readonly profile: Profile },
|
|
238
239
|
* UserNotFoundError | ProfileNotFoundError
|
|
239
|
-
*
|
|
240
|
-
* typeof result
|
|
240
|
+
* >
|
|
241
241
|
* >();
|
|
242
242
|
* assertOk(result, {
|
|
243
243
|
* user: { id: "user-1", profileId: "profile-1" },
|
|
@@ -280,8 +280,8 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
280
280
|
* );
|
|
281
281
|
*
|
|
282
282
|
* assertType<
|
|
283
|
-
*
|
|
284
|
-
*
|
|
283
|
+
* ReturnType<typeof fetchWithRetry>,
|
|
284
|
+
* Task<string, RetryTaskError<FetchError | TimeoutError>>
|
|
285
285
|
* >();
|
|
286
286
|
* ```
|
|
287
287
|
*
|
|
@@ -714,7 +714,7 @@ import { emptyArray, isNonEmptyArray, mapArray, } from "./Array.js";
|
|
|
714
714
|
import { assert, assertNonEmptyReadonlyArray, assertNonNullable, assertNotDisposed, } from "./Assert.js";
|
|
715
715
|
import { createConsole, testCreateConsole, } from "./Console.js";
|
|
716
716
|
import { createRandomBytes, testCreateRandomBytes, } from "./Crypto.js";
|
|
717
|
-
import {
|
|
717
|
+
import { eqArraySameValue } from "./Eq.js";
|
|
718
718
|
import { constTrue, constVoid, identity } from "./Function.js";
|
|
719
719
|
import { createLeakDetector, noopLeakDetector, testCreateLeakDetector, } from "./LeakDetector.js";
|
|
720
720
|
import { createLookupMap } from "./Lookup.js";
|
|
@@ -727,7 +727,7 @@ import { createRef } from "./Ref.js";
|
|
|
727
727
|
import { err, getOk, getOrThrow, ok, } from "./Result.js";
|
|
728
728
|
import { emptySet } from "./Set.js";
|
|
729
729
|
import { createTime, PositiveMillis, testCreateTime, } from "./Time.js";
|
|
730
|
-
import {
|
|
730
|
+
import { createId, maxPositiveInt, NonNegativeInt, object, onePositiveInt, PositiveInt, record, String, typed, Unknown, UnknownResult, } from "./Type.js";
|
|
731
731
|
/**
|
|
732
732
|
* Runtime Type for structured data explaining why a {@link Run} was aborted.
|
|
733
733
|
*
|
|
@@ -1181,7 +1181,7 @@ const createRunInternal = (deps, parent, rootRun, taskMeta) => {
|
|
|
1181
1181
|
// concern. Attach this late so V8 captures the defect stack before any
|
|
1182
1182
|
// catch observes the Fiber.
|
|
1183
1183
|
void fiber.catch(constVoid);
|
|
1184
|
-
//
|
|
1184
|
+
// oxlint-disable-next-line typescript/only-throw-error -- AbortError is Task abort control flow; aborts intentionally carry no stack.
|
|
1185
1185
|
throw taskExit.error;
|
|
1186
1186
|
};
|
|
1187
1187
|
const fiber = runTask();
|
|
@@ -1197,10 +1197,10 @@ const createRunInternal = (deps, parent, rootRun, taskMeta) => {
|
|
|
1197
1197
|
return fiber;
|
|
1198
1198
|
});
|
|
1199
1199
|
const root = rootRun ?? run;
|
|
1200
|
-
/*
|
|
1200
|
+
/* oxlint-disable typescript/no-unsafe-return -- Internal overload assignments implement public generics via TaskInternal. */
|
|
1201
1201
|
run.orThrow = (async (task, taskDeps) => getOrThrow(await run(task, taskDeps)));
|
|
1202
1202
|
run.ok = (async (task, taskDeps) => getOk((await run(task, taskDeps))));
|
|
1203
|
-
/*
|
|
1203
|
+
/* oxlint-enable typescript/no-unsafe-return */
|
|
1204
1204
|
run.abortable = ((task, deps) => run(task, deps, { abortable: true }));
|
|
1205
1205
|
run.daemon = ((task, taskDeps) => {
|
|
1206
1206
|
assertNotDisposed({ disposed: !!disposePromise });
|
|
@@ -1248,7 +1248,7 @@ const createRunInternal = (deps, parent, rootRun, taskMeta) => {
|
|
|
1248
1248
|
run.snapshot = () => {
|
|
1249
1249
|
const childSnapshots = Array.from(children.keys(), (childRun) => childRun.snapshot());
|
|
1250
1250
|
if (snapshot?.state !== state ||
|
|
1251
|
-
!
|
|
1251
|
+
!eqArraySameValue(snapshot.children, childSnapshots)) {
|
|
1252
1252
|
snapshot = {
|
|
1253
1253
|
id: run.id,
|
|
1254
1254
|
state,
|
|
@@ -1282,7 +1282,7 @@ const createRunInternal = (deps, parent, rootRun, taskMeta) => {
|
|
|
1282
1282
|
};
|
|
1283
1283
|
run[Symbol.asyncDispose] = async () => {
|
|
1284
1284
|
await dispose();
|
|
1285
|
-
//
|
|
1285
|
+
// oxlint-disable-next-line typescript/only-throw-error -- AbortError is Task abort control flow; rethrowing it avoids reporting the finalizer defect twice in Task code.
|
|
1286
1286
|
if (finalizerAbortError)
|
|
1287
1287
|
throw finalizerAbortError;
|
|
1288
1288
|
};
|
|
@@ -1483,7 +1483,7 @@ export const sleep = (duration) => callback(({ run: { deps }, resolve }) => {
|
|
|
1483
1483
|
* await using run = createRun();
|
|
1484
1484
|
*
|
|
1485
1485
|
* const result = await run(timeout(waitForAbort, "1ms"));
|
|
1486
|
-
* assertType<Result<never, TimeoutError
|
|
1486
|
+
* assertType<typeof result, Result<never, TimeoutError>>();
|
|
1487
1487
|
* assertErr(result, timeoutError);
|
|
1488
1488
|
* ```
|
|
1489
1489
|
*
|
|
@@ -1553,8 +1553,8 @@ export const timeoutError = { type: "TimeoutError" };
|
|
|
1553
1553
|
* await using run = createRun();
|
|
1554
1554
|
* const result = await run(fetchWithRetry);
|
|
1555
1555
|
* assertType<
|
|
1556
|
-
*
|
|
1557
|
-
*
|
|
1556
|
+
* typeof result,
|
|
1557
|
+
* Result<string, RetryTaskError<ServiceUnavailableError>>
|
|
1558
1558
|
* >();
|
|
1559
1559
|
* assertErr(result, {
|
|
1560
1560
|
* type: "RetryError",
|
|
@@ -1771,7 +1771,7 @@ export const repeat = (task, schedule, { shouldRepeat = constTrue, onRepeat } =
|
|
|
1771
1771
|
* await using run = createRun();
|
|
1772
1772
|
* const result = await run(any([unavailable, fallback]));
|
|
1773
1773
|
*
|
|
1774
|
-
* assertType<Result<string, ServiceUnavailableError
|
|
1774
|
+
* assertType<typeof result, Result<string, ServiceUnavailableError>>();
|
|
1775
1775
|
* assertOk(result, "fallback");
|
|
1776
1776
|
* assertTrue(fallbackStarted);
|
|
1777
1777
|
* ```
|
|
@@ -1868,7 +1868,7 @@ export const any = (tasks, options) => async (run) => {
|
|
|
1868
1868
|
* // Input order does not matter: the first settled Result wins, and the
|
|
1869
1869
|
* // still-running loser is aborted.
|
|
1870
1870
|
* const result = await run(race([slow, fast]));
|
|
1871
|
-
* assertType<Result<string
|
|
1871
|
+
* assertType<typeof result, Result<string>>();
|
|
1872
1872
|
* assertOk(result, "fast");
|
|
1873
1873
|
* assertFalse(slowCompleted);
|
|
1874
1874
|
* ```
|
|
@@ -1940,7 +1940,6 @@ export const race = (tasks) => async (run) => {
|
|
|
1940
1940
|
* @group Racing
|
|
1941
1941
|
*/
|
|
1942
1942
|
export const firstN = (tasks, count, options) => async (run) => {
|
|
1943
|
-
assertType(PositiveInt, count);
|
|
1944
1943
|
const values = [];
|
|
1945
1944
|
await run(each(tasks, (result) => {
|
|
1946
1945
|
if (result.ok)
|
|
@@ -2002,7 +2001,6 @@ export const firstN = (tasks, count, options) => async (run) => {
|
|
|
2002
2001
|
* @group Racing
|
|
2003
2002
|
*/
|
|
2004
2003
|
export const firstNSettled = (tasks, count, options) => async (run) => {
|
|
2005
|
-
assertType(PositiveInt, count);
|
|
2006
2004
|
const results = [];
|
|
2007
2005
|
await run(each(tasks, (result) => {
|
|
2008
2006
|
results.push(result);
|
|
@@ -2304,7 +2302,7 @@ export const yieldNow = async (run) => {
|
|
|
2304
2302
|
* return await run(waitForAbort);
|
|
2305
2303
|
* };
|
|
2306
2304
|
*
|
|
2307
|
-
* assertType<Task<never, never, ServerDep
|
|
2305
|
+
* assertType<ReturnType<typeof serve>, Task<never, never, ServerDep>>();
|
|
2308
2306
|
*
|
|
2309
2307
|
* await using run = createRun();
|
|
2310
2308
|
* const fiber = run.abortable(serve(), { port: 3000 });
|
|
@@ -2456,7 +2454,7 @@ export const waitForAbort = async (run) => {
|
|
|
2456
2454
|
* const task: Task<ResultValue> = () => promise;
|
|
2457
2455
|
*
|
|
2458
2456
|
* assertTrue(promiseStarted);
|
|
2459
|
-
* assertType<Task<ResultValue
|
|
2457
|
+
* assertType<typeof task, Task<ResultValue>>();
|
|
2460
2458
|
* ```
|
|
2461
2459
|
*
|
|
2462
2460
|
* @group Lifetime
|
|
@@ -2739,7 +2737,7 @@ export const acquireUseRelease = (acquire, use, release) => unabortableMask((res
|
|
|
2739
2737
|
* assertTrue(deferred.resolve(ok("ready")));
|
|
2740
2738
|
*
|
|
2741
2739
|
* const result = await fiber;
|
|
2742
|
-
* assertType<Result<string
|
|
2740
|
+
* assertType<typeof result, Result<string>>();
|
|
2743
2741
|
* assertOk(result, "ready");
|
|
2744
2742
|
*
|
|
2745
2743
|
* // A Deferred is one-shot: later resolutions are ignored, and future
|
package/dist/src/Test.d.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-module test utilities for deterministic testing.
|
|
3
3
|
*
|
|
4
|
-
* Test helpers are usually colocated with the code they test.
|
|
5
|
-
*
|
|
4
|
+
* Test helpers are usually colocated with the code they test. General helpers
|
|
5
|
+
* shared across unrelated modules, or helpers whose colocation would create
|
|
6
|
+
* dependency cycles, belong here.
|
|
6
7
|
*
|
|
7
8
|
* @module
|
|
8
9
|
*/
|
|
9
10
|
import type { Brand } from "./Brand.ts";
|
|
10
11
|
import { type Id } from "./Type.ts";
|
|
12
|
+
/**
|
|
13
|
+
* Temporarily replaces a global property for a test scope.
|
|
14
|
+
*
|
|
15
|
+
* Node.js can mock existing globals with `t.mock.property`, but it rejects a
|
|
16
|
+
* property that does not exist. That catches misspelled mock targets, but it
|
|
17
|
+
* cannot model optional platform globals whose presence varies. Use this helper
|
|
18
|
+
* to provide such a global, for example `scheduler`, or replace a global with
|
|
19
|
+
* `undefined` to exercise a fallback.
|
|
20
|
+
*
|
|
21
|
+
* The original property descriptor is restored on disposal. A property that did
|
|
22
|
+
* not exist is deleted. Prefer dependency injection when available because
|
|
23
|
+
* global properties are shared by concurrently running tests.
|
|
24
|
+
*
|
|
25
|
+
* ### Example
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { assertEqual, assertFalse, testStubGlobal } from "@evolu/common";
|
|
29
|
+
*
|
|
30
|
+
* const key = Symbol("test global");
|
|
31
|
+
* {
|
|
32
|
+
* using _stub = testStubGlobal(key, 42);
|
|
33
|
+
* assertEqual(Reflect.get(globalThis, key), 42);
|
|
34
|
+
* }
|
|
35
|
+
* assertFalse(Reflect.has(globalThis, key));
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const testStubGlobal: (key: PropertyKey, value: unknown) => Disposable;
|
|
11
39
|
export type TestCreateId = <B extends string = never>() => [B] extends [never] ? Id : Id & Brand<B>;
|
|
12
40
|
/**
|
|
13
41
|
* Creates a deterministic `createId` helper.
|
|
@@ -41,7 +69,7 @@ export type TestCreateId = <B extends string = never>() => [B] extends [never] ?
|
|
|
41
69
|
*
|
|
42
70
|
* const replayCreateId = testCreateId();
|
|
43
71
|
* assertEqual(replayCreateId(), callbackId);
|
|
44
|
-
* assertType<Id & Brand<"Todo"
|
|
72
|
+
* assertType<typeof todoId, Id & Brand<"Todo">>();
|
|
45
73
|
* ```
|
|
46
74
|
*/
|
|
47
75
|
export declare const testCreateId: () => TestCreateId;
|
package/dist/src/Test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Test.d.ts","sourceRoot":"","sources":["../../src/Test.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Test.d.ts","sourceRoot":"","sources":["../../src/Test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EAAY,KAAK,EAAE,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc,QACpB,WAAW,SACT,OAAO,KACb,UAcF,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,SAAS,MAAM,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1E,EAAE,GACF,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,YAAY,QAAO,YAO/B,CAAC"}
|
package/dist/src/Test.js
CHANGED
|
@@ -1,14 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cross-module test utilities for deterministic testing.
|
|
3
3
|
*
|
|
4
|
-
* Test helpers are usually colocated with the code they test.
|
|
5
|
-
*
|
|
4
|
+
* Test helpers are usually colocated with the code they test. General helpers
|
|
5
|
+
* shared across unrelated modules, or helpers whose colocation would create
|
|
6
|
+
* dependency cycles, belong here.
|
|
6
7
|
*
|
|
7
8
|
* @module
|
|
8
9
|
*/
|
|
9
10
|
import { testCreateRandomBytes } from "./Crypto.js";
|
|
10
11
|
import { testCreateRandomLib } from "./Random.js";
|
|
11
12
|
import { createId } from "./Type.js";
|
|
13
|
+
/**
|
|
14
|
+
* Temporarily replaces a global property for a test scope.
|
|
15
|
+
*
|
|
16
|
+
* Node.js can mock existing globals with `t.mock.property`, but it rejects a
|
|
17
|
+
* property that does not exist. That catches misspelled mock targets, but it
|
|
18
|
+
* cannot model optional platform globals whose presence varies. Use this helper
|
|
19
|
+
* to provide such a global, for example `scheduler`, or replace a global with
|
|
20
|
+
* `undefined` to exercise a fallback.
|
|
21
|
+
*
|
|
22
|
+
* The original property descriptor is restored on disposal. A property that did
|
|
23
|
+
* not exist is deleted. Prefer dependency injection when available because
|
|
24
|
+
* global properties are shared by concurrently running tests.
|
|
25
|
+
*
|
|
26
|
+
* ### Example
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { assertEqual, assertFalse, testStubGlobal } from "@evolu/common";
|
|
30
|
+
*
|
|
31
|
+
* const key = Symbol("test global");
|
|
32
|
+
* {
|
|
33
|
+
* using _stub = testStubGlobal(key, 42);
|
|
34
|
+
* assertEqual(Reflect.get(globalThis, key), 42);
|
|
35
|
+
* }
|
|
36
|
+
* assertFalse(Reflect.has(globalThis, key));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const testStubGlobal = (key, value) => {
|
|
40
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, key);
|
|
41
|
+
Object.defineProperty(globalThis, key, {
|
|
42
|
+
configurable: true,
|
|
43
|
+
value,
|
|
44
|
+
writable: true,
|
|
45
|
+
});
|
|
46
|
+
const disposer = new DisposableStack();
|
|
47
|
+
disposer.defer(() => {
|
|
48
|
+
if (descriptor === undefined)
|
|
49
|
+
Reflect.deleteProperty(globalThis, key);
|
|
50
|
+
else
|
|
51
|
+
Object.defineProperty(globalThis, key, descriptor);
|
|
52
|
+
});
|
|
53
|
+
return disposer;
|
|
54
|
+
};
|
|
12
55
|
/**
|
|
13
56
|
* Creates a deterministic `createId` helper.
|
|
14
57
|
*
|
|
@@ -41,7 +84,7 @@ import { createId } from "./Type.js";
|
|
|
41
84
|
*
|
|
42
85
|
* const replayCreateId = testCreateId();
|
|
43
86
|
* assertEqual(replayCreateId(), callbackId);
|
|
44
|
-
* assertType<Id & Brand<"Todo"
|
|
87
|
+
* assertType<typeof todoId, Id & Brand<"Todo">>();
|
|
45
88
|
* ```
|
|
46
89
|
*/
|
|
47
90
|
export const testCreateId = () => {
|
package/dist/src/Time.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ export declare const performanceDurationBetween: (start: PerformanceTime, end: P
|
|
|
151
151
|
* const readableSchedule = spaced("1s");
|
|
152
152
|
* const validatedSchedule = spaced(Millis.orThrow(1000));
|
|
153
153
|
*
|
|
154
|
-
* assertType<typeof
|
|
154
|
+
* assertType<typeof readableSchedule, typeof validatedSchedule>();
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
157
|
export type Duration = DurationLiteral | Millis;
|
|
@@ -169,7 +169,7 @@ export type Duration = DurationLiteral | Millis;
|
|
|
169
169
|
* const readableSleep = sleep("1s");
|
|
170
170
|
* const validatedSleep = sleep(PositiveMillis.orThrow(1000));
|
|
171
171
|
*
|
|
172
|
-
* assertType<typeof
|
|
172
|
+
* assertType<typeof readableSleep, typeof validatedSleep>();
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
export type PositiveDuration = DurationLiteral | PositiveMillis;
|
|
@@ -326,15 +326,7 @@ export declare const formatMillisAsDuration: (millis: Millis) => string;
|
|
|
326
326
|
* Millis,
|
|
327
327
|
* } from "@evolu/common";
|
|
328
328
|
*
|
|
329
|
-
* const timestamp = new
|
|
330
|
-
* 2026,
|
|
331
|
-
* 0,
|
|
332
|
-
* 28,
|
|
333
|
-
* 14,
|
|
334
|
-
* 32,
|
|
335
|
-
* 15,
|
|
336
|
-
* 234,
|
|
337
|
-
* ).getTime();
|
|
329
|
+
* const timestamp = new Date(2026, 0, 28, 14, 32, 15, 234).getTime();
|
|
338
330
|
* assertEqual(
|
|
339
331
|
* formatMillisAsClockTime(Millis.orThrow(timestamp)),
|
|
340
332
|
* "14:32:15.234",
|
package/dist/src/Time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Time.d.ts","sourceRoot":"","sources":["../../src/Time.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC,OAAO,EAEL,KAAK,OAAO,EASZ,KAAK,YAAY,EAKlB,MAAM,WAAW,CAAC;AAEnB,iCAAiC;AACjC,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,GAAG,EAAE;QACZ,uDAAuD;QACvD,IAAI,MAAM,CAAC;QAEX,sDAAsD;QACtD,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;KAC5B,CAAC;IAEF,QAAQ,CAAC,WAAW,EAAE;QACpB,uEAAuE;QACvE,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;QAE3C;;;;;;;;;WASG;QACH,QAAQ,CAAC,GAAG,EAAE,MAAM,eAAe,CAAC;KACrC,CAAC;IAEF,+DAA+D;IAC/D,QAAQ,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,gBAAgB,KAAK,SAAS,CAAC;IAE5E;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,IAAI,CAAC;CAChD;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI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;AACH,eAAO,MAAM,sBAAsB,WAAY,MAAM,KAAG,MAuBvD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,uBAAuB,WAAY,MAAM,KAAG,MAOxD,CAAC"}
|
package/dist/src/Time.js
CHANGED
|
@@ -27,8 +27,8 @@ export const createTime = () => {
|
|
|
27
27
|
return {
|
|
28
28
|
now,
|
|
29
29
|
performance: {
|
|
30
|
-
timeOrigin:
|
|
31
|
-
now: () =>
|
|
30
|
+
timeOrigin: performance.timeOrigin,
|
|
31
|
+
now: () => performance.now(),
|
|
32
32
|
},
|
|
33
33
|
setTimeout: (callback, duration) => scheduleNativeTimeout(timeoutOwner, callback, duration),
|
|
34
34
|
clearTimeout: (id) => {
|
|
@@ -41,7 +41,7 @@ const scheduleNativeTimeout = (owner, callback, duration) => {
|
|
|
41
41
|
let cancelled = false;
|
|
42
42
|
let nativeId;
|
|
43
43
|
if (delay <= maxNativeTimeoutMillis) {
|
|
44
|
-
nativeId =
|
|
44
|
+
nativeId = setTimeout(() => {
|
|
45
45
|
if (cancelled)
|
|
46
46
|
return;
|
|
47
47
|
cancelled = true;
|
|
@@ -57,19 +57,19 @@ const scheduleNativeTimeout = (owner, callback, duration) => {
|
|
|
57
57
|
return;
|
|
58
58
|
const remaining = deadline - getSystemNowMillis();
|
|
59
59
|
if (remaining > 0) {
|
|
60
|
-
nativeId =
|
|
60
|
+
nativeId = setTimeout(onTimeout, Math.min(remaining, maxNativeTimeoutMillis));
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
cancelled = true;
|
|
64
64
|
callback();
|
|
65
65
|
};
|
|
66
|
-
nativeId =
|
|
66
|
+
nativeId = setTimeout(onTimeout, maxNativeTimeoutMillis);
|
|
67
67
|
}
|
|
68
68
|
return {
|
|
69
69
|
owner,
|
|
70
70
|
clear: () => {
|
|
71
71
|
cancelled = true;
|
|
72
|
-
|
|
72
|
+
clearTimeout(nativeId);
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
};
|
|
@@ -79,7 +79,7 @@ const scheduleNativeTimeout = (owner, callback, duration) => {
|
|
|
79
79
|
* logical delays are scheduled in chunks to avoid native timer overflow.
|
|
80
80
|
*/
|
|
81
81
|
const maxNativeTimeoutMillis = 2 ** 31 - 1;
|
|
82
|
-
const getSystemNowMillis = () => Millis.orThrow(
|
|
82
|
+
const getSystemNowMillis = () => Millis.orThrow(Date.now());
|
|
83
83
|
const clearTimeoutId = (owner, id) => {
|
|
84
84
|
const internal = id;
|
|
85
85
|
assert(internal.owner === owner, "TimeoutId was created by another Time instance");
|
|
@@ -210,7 +210,7 @@ export const saturateMillis = (value) => Millis.orNull(Math.max(0, Math.round(va
|
|
|
210
210
|
* This is a safe cast because {@link Millis} guarantees a valid timestamp range
|
|
211
211
|
* that always produces a valid ISO string.
|
|
212
212
|
*/
|
|
213
|
-
export const millisToDateIso = (value) => new
|
|
213
|
+
export const millisToDateIso = (value) => new Date(value).toISOString();
|
|
214
214
|
/**
|
|
215
215
|
* Returns the elapsed fractional milliseconds between two performance times.
|
|
216
216
|
*
|
|
@@ -397,15 +397,7 @@ export const formatMillisAsDuration = (millis) => {
|
|
|
397
397
|
* Millis,
|
|
398
398
|
* } from "@evolu/common";
|
|
399
399
|
*
|
|
400
|
-
* const timestamp = new
|
|
401
|
-
* 2026,
|
|
402
|
-
* 0,
|
|
403
|
-
* 28,
|
|
404
|
-
* 14,
|
|
405
|
-
* 32,
|
|
406
|
-
* 15,
|
|
407
|
-
* 234,
|
|
408
|
-
* ).getTime();
|
|
400
|
+
* const timestamp = new Date(2026, 0, 28, 14, 32, 15, 234).getTime();
|
|
409
401
|
* assertEqual(
|
|
410
402
|
* formatMillisAsClockTime(Millis.orThrow(timestamp)),
|
|
411
403
|
* "14:32:15.234",
|
|
@@ -413,7 +405,7 @@ export const formatMillisAsDuration = (millis) => {
|
|
|
413
405
|
* ```
|
|
414
406
|
*/
|
|
415
407
|
export const formatMillisAsClockTime = (millis) => {
|
|
416
|
-
const date = new
|
|
408
|
+
const date = new Date(millis);
|
|
417
409
|
const hours = date.getHours().toString().padStart(2, "0");
|
|
418
410
|
const minutes = date.getMinutes().toString().padStart(2, "0");
|
|
419
411
|
const seconds = date.getSeconds().toString().padStart(2, "0");
|