@evolu/common 8.7.0 → 8.8.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 +478 -141
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +644 -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.js +4 -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 +1181 -0
- package/src/Assert.ts +971 -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 +3 -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/Type.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ export interface Type<Name extends TypeName, in out Input, in out Output, Error
|
|
|
143
143
|
* const values: ReadonlyArray<unknown> = [42n, "42", null];
|
|
144
144
|
* const integers = values.filter(Int64FromInt64String.is);
|
|
145
145
|
*
|
|
146
|
-
* assertType<Array<Int64
|
|
146
|
+
* assertType<typeof integers, Array<Int64>>();
|
|
147
147
|
* assertTrue(Int64FromInt64String.is(42n));
|
|
148
148
|
* assertFalse(Int64FromInt64String.is("42"));
|
|
149
149
|
* ```
|
|
@@ -157,10 +157,10 @@ export interface Type<Name extends TypeName, in out Input, in out Output, Error
|
|
|
157
157
|
* Type toward the root. The deepest suffix accepts the root Output.
|
|
158
158
|
*
|
|
159
159
|
* Every entry point asserts its selected boundary before running the
|
|
160
|
-
* remaining pipeline. Assertion failures throw because they indicate a
|
|
161
|
-
*
|
|
162
|
-
* and its cause preserves the structured validation error. Only
|
|
163
|
-
* introduced after that boundary are returned through `Result`.
|
|
160
|
+
* remaining pipeline. Assertion failures throw because they indicate a bug
|
|
161
|
+
* that must be fixed. The Error message identifies the expected boundary
|
|
162
|
+
* Type, and its cause preserves the structured validation error. Only
|
|
163
|
+
* failures introduced after that boundary are returned through `Result`.
|
|
164
164
|
*
|
|
165
165
|
* ### Example
|
|
166
166
|
*
|
|
@@ -205,8 +205,8 @@ export interface Type<Name extends TypeName, in out Input, in out Output, Error
|
|
|
205
205
|
* const result = saveTodo(title, note);
|
|
206
206
|
*
|
|
207
207
|
* assertType<
|
|
208
|
-
*
|
|
209
|
-
* typeof
|
|
208
|
+
* typeof result,
|
|
209
|
+
* Result<typeof Todo.Output, MaxLengthError<100> | MinLengthError<1>>
|
|
210
210
|
* >();
|
|
211
211
|
* assertOk(result, { title, note });
|
|
212
212
|
* ```
|
|
@@ -240,7 +240,7 @@ export interface Type<Name extends TypeName, in out Input, in out Output, Error
|
|
|
240
240
|
* `from` operation, which accepts this Type's `Input`.
|
|
241
241
|
*
|
|
242
242
|
* The typed `Input` boundary is asserted before the remaining pipeline runs.
|
|
243
|
-
* A boundary violation
|
|
243
|
+
* A boundary violation is a bug, so it throws directly; `getOrThrow` maps
|
|
244
244
|
* only a validation error returned after that boundary.
|
|
245
245
|
*
|
|
246
246
|
* `Type.orThrow.parent(value)` does not exist. To throw after starting from a
|
|
@@ -278,8 +278,8 @@ export interface Type<Name extends TypeName, in out Input, in out Output, Error
|
|
|
278
278
|
* `from` operation, which accepts this Type's `Input`.
|
|
279
279
|
*
|
|
280
280
|
* The typed `Input` boundary is asserted before the remaining pipeline runs.
|
|
281
|
-
* A boundary violation
|
|
282
|
-
*
|
|
281
|
+
* A boundary violation is a bug, so it throws directly; `getOrNull` maps only
|
|
282
|
+
* a validation error returned after that boundary to `null`.
|
|
283
283
|
*
|
|
284
284
|
* `Type.orNull.parent(value)` does not exist. To return `null` after starting
|
|
285
285
|
* from a typed boundary, call `getOrNull` with the corresponding `from`
|
|
@@ -380,18 +380,18 @@ export interface TypeNode {
|
|
|
380
380
|
readonly is: (value: unknown) => boolean;
|
|
381
381
|
}
|
|
382
382
|
/**
|
|
383
|
-
* Asserts
|
|
384
|
-
* {@link Type} Output domain.
|
|
383
|
+
* Asserts type equality or validates a value with a {@link Type}.
|
|
385
384
|
*
|
|
386
|
-
* - `assertType<
|
|
387
|
-
* evaluating a value.
|
|
385
|
+
* - `assertType<Actual, Expected>()` requires compiler-identical types without
|
|
386
|
+
* evaluating a value. It is Evolu's platform-agnostic equivalent of Vitest's
|
|
387
|
+
* `expectTypeOf(...).toEqualTypeOf<...>()` and does not require a test
|
|
388
|
+
* runner.
|
|
388
389
|
* - `assertType(type, value)` validates and narrows a runtime value to the Type's
|
|
389
390
|
* Output.
|
|
390
391
|
*
|
|
391
|
-
* Use the runtime form for
|
|
392
|
-
* external input with `Type.fromUnknown` so validation
|
|
393
|
-
*
|
|
394
|
-
* preserves the exact Output validation error as the thrown Error's cause.
|
|
392
|
+
* Use the runtime form for code-correctness invariants, not expected validation
|
|
393
|
+
* failures. Validate external input with `Type.fromUnknown` so validation
|
|
394
|
+
* failures remain typed values.
|
|
395
395
|
*
|
|
396
396
|
* ### Example
|
|
397
397
|
*
|
|
@@ -405,18 +405,15 @@ export interface TypeNode {
|
|
|
405
405
|
* const value: unknown = "Evolu";
|
|
406
406
|
* assertType(NonEmptyTrimmedString100, value);
|
|
407
407
|
* assertType<
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* Brand<"MinLength1"> &
|
|
411
|
-
* Brand<"MaxLength100">,
|
|
412
|
-
* typeof value
|
|
408
|
+
* typeof value,
|
|
409
|
+
* string & Brand<"Trimmed"> & Brand<"MinLength1"> & Brand<"MaxLength100">
|
|
413
410
|
* >();
|
|
414
411
|
* ```
|
|
415
412
|
*
|
|
416
413
|
* @group Core
|
|
417
414
|
*/
|
|
418
|
-
export declare function assertType<
|
|
419
|
-
error: CompileTimeError<"assertType", "
|
|
415
|
+
export declare function assertType<Actual, Expected>(...error: IsSameType<Actual, Expected> extends true ? [] : [
|
|
416
|
+
error: CompileTimeError<"assertType", "Actual and expected types must be identical">
|
|
420
417
|
]): void;
|
|
421
418
|
export declare function assertType<T extends TypeNode>(type: T, value: unknown): asserts value is T["Output"];
|
|
422
419
|
/**
|
|
@@ -474,7 +471,7 @@ export declare function assertType<T extends TypeNode>(type: T, value: unknown):
|
|
|
474
471
|
* },
|
|
475
472
|
* );
|
|
476
473
|
*
|
|
477
|
-
* assertType<typeof Label, typeof
|
|
474
|
+
* assertType<typeof typesByLocale.cs.Label, typeof Label>();
|
|
478
475
|
*
|
|
479
476
|
* const result = typesByLocale.cs.Label.fromUnknown("");
|
|
480
477
|
* assertErr(result);
|
|
@@ -625,7 +622,7 @@ declare const identityEncodingSymbol: unique symbol;
|
|
|
625
622
|
*
|
|
626
623
|
* const user = User.orThrow({ name: "Ada", age: 37 });
|
|
627
624
|
*
|
|
628
|
-
* assertType<typeof
|
|
625
|
+
* assertType<typeof user, typeof User.Output>();
|
|
629
626
|
* assertEqual(user.name, "Ada");
|
|
630
627
|
* ```
|
|
631
628
|
*
|
|
@@ -808,11 +805,10 @@ export declare function createType<Name extends TypeName, ParentType extends Con
|
|
|
808
805
|
* not lose distinctions present in the Output domain.
|
|
809
806
|
*
|
|
810
807
|
* Transformation callbacks are Type construction code. Their successful results
|
|
811
|
-
* are asserted against the declared boundary so a broken callback
|
|
812
|
-
*
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
* return an `Err`.
|
|
808
|
+
* are asserted against the declared boundary, so a broken callback throws
|
|
809
|
+
* instead of becoming a validation error. Like all Type-construction callbacks,
|
|
810
|
+
* they are trusted to follow their declared TypeScript types. A `Result<_,
|
|
811
|
+
* never>` callback is therefore trusted never to return an `Err`.
|
|
816
812
|
*
|
|
817
813
|
* Errors from the parent and the forward callback remain unchanged. A forward
|
|
818
814
|
* callback error must use the transformation name as its type. Errors from the
|
|
@@ -1012,7 +1008,7 @@ export interface TypeOfError<Name extends keyof TypeOfOutputByName> extends Type
|
|
|
1012
1008
|
* const WireValue100 = maxLength(100)(String);
|
|
1013
1009
|
* type WireValue100 = typeof WireValue100.Output;
|
|
1014
1010
|
*
|
|
1015
|
-
* assertType<string & Brand<"MaxLength100"
|
|
1011
|
+
* assertType<WireValue100, string & Brand<"MaxLength100">>();
|
|
1016
1012
|
* assertOk(WireValue100.fromUnknown(""), "");
|
|
1017
1013
|
* assertOk(WireValue100.fromUnknown(" value "), " value ");
|
|
1018
1014
|
* ```
|
|
@@ -1055,34 +1051,34 @@ export declare const String: Type<"String", string, string, TypeOfError<"String"
|
|
|
1055
1051
|
* } from "@evolu/common";
|
|
1056
1052
|
*
|
|
1057
1053
|
* // Note how every additional constraint accumulates its Brand.
|
|
1058
|
-
* assertType<
|
|
1059
|
-
* assertType<number & Brand<"NonNaN"
|
|
1054
|
+
* assertType<typeof Number.Output, number>();
|
|
1055
|
+
* assertType<typeof NonNaNNumber.Output, number & Brand<"NonNaN">>();
|
|
1060
1056
|
* assertType<
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1057
|
+
* typeof FiniteNumber.Output,
|
|
1058
|
+
* number & Brand<"NonNaN"> & Brand<"Finite">
|
|
1063
1059
|
* >();
|
|
1064
1060
|
* assertType<
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1061
|
+
* typeof Int.Output,
|
|
1062
|
+
* number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int">
|
|
1067
1063
|
* >();
|
|
1068
1064
|
* assertType<
|
|
1065
|
+
* typeof NonNegativeInt.Output,
|
|
1069
1066
|
* number &
|
|
1070
1067
|
* Brand<"NonNaN"> &
|
|
1071
1068
|
* Brand<"Finite"> &
|
|
1072
1069
|
* Brand<"Int"> &
|
|
1073
|
-
* Brand<"NonNegative"
|
|
1074
|
-
* typeof NonNegativeInt.Output
|
|
1070
|
+
* Brand<"NonNegative">
|
|
1075
1071
|
* >();
|
|
1076
1072
|
*
|
|
1077
1073
|
* assertType<
|
|
1074
|
+
* typeof Age.Output,
|
|
1078
1075
|
* number &
|
|
1079
1076
|
* Brand<"NonNaN"> &
|
|
1080
1077
|
* Brand<"Finite"> &
|
|
1081
1078
|
* Brand<"Int"> &
|
|
1082
1079
|
* Brand<"NonNegative"> &
|
|
1083
1080
|
* Brand<"LessThan200"> &
|
|
1084
|
-
* Brand<"Age"
|
|
1085
|
-
* typeof Age.Output
|
|
1081
|
+
* Brand<"Age">
|
|
1086
1082
|
* >();
|
|
1087
1083
|
*
|
|
1088
1084
|
* assertOk(Age.fromUnknown(122), 122);
|
|
@@ -1246,8 +1242,8 @@ export declare function objectTag<Name extends keyof ObjectTagOutputByName>(name
|
|
|
1246
1242
|
* assertOk(result);
|
|
1247
1243
|
* assertSame(result.value, value);
|
|
1248
1244
|
* assertType<
|
|
1249
|
-
* true,
|
|
1250
|
-
*
|
|
1245
|
+
* typeof result.value extends TaggedValue ? true : false,
|
|
1246
|
+
* true
|
|
1251
1247
|
* >();
|
|
1252
1248
|
* assertEqual(TaggedValueType.expected, "TaggedValue");
|
|
1253
1249
|
* ```
|
|
@@ -1368,7 +1364,7 @@ type InstanceConstructorCompileTimeError = CompileTimeError<"Type", "Constructor
|
|
|
1368
1364
|
*
|
|
1369
1365
|
* const Ready = literal("ready");
|
|
1370
1366
|
*
|
|
1371
|
-
* assertType<
|
|
1367
|
+
* assertType<typeof Ready.Output, "ready">();
|
|
1372
1368
|
* assertOk(Ready.fromUnknown("ready"), "ready");
|
|
1373
1369
|
* const invalid = Ready.fromUnknown("pending");
|
|
1374
1370
|
* assertErr(invalid);
|
|
@@ -1673,20 +1669,20 @@ interface UnionErrorValue<Error extends TypeError, MemberError extends UnionMemb
|
|
|
1673
1669
|
*
|
|
1674
1670
|
* // Output is the decoded language and region.
|
|
1675
1671
|
* type SupportedLocale = typeof SupportedLocale.Output;
|
|
1676
|
-
* assertType<readonly ["en" | "cs", "US" | "CZ"]
|
|
1672
|
+
* assertType<SupportedLocale, readonly ["en" | "cs", "US" | "CZ"]>();
|
|
1677
1673
|
*
|
|
1678
1674
|
* // The parent Output is the canonical locale string.
|
|
1679
1675
|
* type SupportedLocaleLiteral = typeof SupportedLocale.parent.Output;
|
|
1680
1676
|
* assertType<
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
1677
|
+
* SupportedLocaleLiteral,
|
|
1678
|
+
* "en-US" | "en-CZ" | "cs-US" | "cs-CZ"
|
|
1683
1679
|
* >();
|
|
1684
1680
|
*
|
|
1685
1681
|
* // Parse an unknown string into structured data.
|
|
1686
1682
|
* const result = SupportedLocale.fromUnknown("cs-CZ");
|
|
1687
1683
|
* assertOk(result, ["cs", "CZ"]);
|
|
1688
1684
|
* const locale = result.value;
|
|
1689
|
-
* assertType<
|
|
1685
|
+
* assertType<typeof locale, SupportedLocale>();
|
|
1690
1686
|
* const invalid = SupportedLocale.fromUnknown("cs/CZ");
|
|
1691
1687
|
* assertErr(invalid);
|
|
1692
1688
|
* assertType(Data, invalid.error);
|
|
@@ -1698,13 +1694,13 @@ interface UnionErrorValue<Error extends TypeError, MemberError extends UnionMemb
|
|
|
1698
1694
|
*
|
|
1699
1695
|
* // Encode structured data into its canonical string.
|
|
1700
1696
|
* const localeLiteral = SupportedLocale.to(locale);
|
|
1701
|
-
* assertType<
|
|
1697
|
+
* assertType<typeof localeLiteral, SupportedLocaleLiteral>();
|
|
1702
1698
|
* assertEqual(localeLiteral, "cs-CZ");
|
|
1703
1699
|
*
|
|
1704
1700
|
* // Validate a string configuration value.
|
|
1705
1701
|
* const configValue: unknown = "cs-CZ";
|
|
1706
1702
|
* assertType(SupportedLocale.parent, configValue);
|
|
1707
|
-
* assertType<
|
|
1703
|
+
* assertType<typeof configValue, SupportedLocaleLiteral>();
|
|
1708
1704
|
* assertFalse(SupportedLocale.parent.is("fr-CZ"));
|
|
1709
1705
|
* ```
|
|
1710
1706
|
*
|
|
@@ -1756,11 +1752,11 @@ interface UnionErrorValue<Error extends TypeError, MemberError extends UnionMemb
|
|
|
1756
1752
|
* const result = ItemId.fromUnknown("item-42");
|
|
1757
1753
|
* assertOk(result, [42n]);
|
|
1758
1754
|
* const itemId = result.value;
|
|
1759
|
-
* assertType<
|
|
1755
|
+
* assertType<typeof itemId, ItemId>();
|
|
1760
1756
|
*
|
|
1761
1757
|
* // Encode the structured data into its canonical string.
|
|
1762
1758
|
* const itemIdLiteral = ItemId.to(itemId);
|
|
1763
|
-
* assertType<
|
|
1759
|
+
* assertType<typeof itemIdLiteral, ItemIdLiteral>();
|
|
1764
1760
|
* assertEqual(itemIdLiteral, "item-42");
|
|
1765
1761
|
*
|
|
1766
1762
|
* // TypeScript cannot prove from the literal alone that "42" is a valid Int64 encoding.
|
|
@@ -1858,8 +1854,8 @@ export interface TemplateLiteralType<Parts extends TemplateLiteralParts> extends
|
|
|
1858
1854
|
* const Locale = templateLiteral(Language, "-", Region);
|
|
1859
1855
|
*
|
|
1860
1856
|
* assertType<
|
|
1861
|
-
*
|
|
1862
|
-
*
|
|
1857
|
+
* typeof Locale.Output,
|
|
1858
|
+
* "en-US" | "en-CZ" | "cs-US" | "cs-CZ"
|
|
1863
1859
|
* >();
|
|
1864
1860
|
* assertOk(Locale.fromUnknown("cs-CZ"), "cs-CZ");
|
|
1865
1861
|
* assertFalse(Locale.is("fr-CZ"));
|
|
@@ -1957,7 +1953,7 @@ type TemplateLiteralStringWidth<Value extends string, Width extends ReadonlyArra
|
|
|
1957
1953
|
* type Int64 = typeof Int64.Output;
|
|
1958
1954
|
*
|
|
1959
1955
|
* // Note the Brand.
|
|
1960
|
-
* assertType<bigint & Brand<"Int64"
|
|
1956
|
+
* assertType<Int64, bigint & Brand<"Int64">>();
|
|
1961
1957
|
*
|
|
1962
1958
|
* interface Int64Error extends TypeError<"Int64"> {
|
|
1963
1959
|
* readonly value: bigint;
|
|
@@ -2132,7 +2128,7 @@ export interface UInt64Error extends TypeError<"UInt64"> {
|
|
|
2132
2128
|
* const TrimmedString = trimmed(String);
|
|
2133
2129
|
* type TrimmedString = typeof TrimmedString.Output;
|
|
2134
2130
|
*
|
|
2135
|
-
* assertType<string & Brand<"Trimmed"
|
|
2131
|
+
* assertType<TrimmedString, string & Brand<"Trimmed">>();
|
|
2136
2132
|
*
|
|
2137
2133
|
* interface TrimmedError extends TypeError<"Trimmed"> {
|
|
2138
2134
|
* readonly value: string;
|
|
@@ -2201,8 +2197,8 @@ export type BrandFactory<Name extends TypeName, Value, Error extends TypeError<N
|
|
|
2201
2197
|
* const LessThan100 = lessThan(100)(Number);
|
|
2202
2198
|
* type LessThan100 = typeof LessThan100.Output;
|
|
2203
2199
|
*
|
|
2204
|
-
* assertType<
|
|
2205
|
-
* assertType<number & Brand<"LessThan100"
|
|
2200
|
+
* assertType<typeof LessThan100.name, "LessThan100">();
|
|
2201
|
+
* assertType<LessThan100, number & Brand<"LessThan100">>();
|
|
2206
2202
|
*
|
|
2207
2203
|
* interface LessThanError<
|
|
2208
2204
|
* Max extends number,
|
|
@@ -2241,7 +2237,7 @@ type BrandFactoryNumberError = CompileTimeError<"Brand Factory", "Parameter must
|
|
|
2241
2237
|
* const CapitalizedString = capitalized(String);
|
|
2242
2238
|
* type CapitalizedString = typeof CapitalizedString.Output;
|
|
2243
2239
|
*
|
|
2244
|
-
* assertType<string & Brand<"Capitalized"
|
|
2240
|
+
* assertType<CapitalizedString, string & Brand<"Capitalized">>();
|
|
2245
2241
|
*
|
|
2246
2242
|
* assertOk(CapitalizedString.fromUnknown("Evolu"), "Evolu");
|
|
2247
2243
|
* const invalid = CapitalizedString.fromUnknown("evolu");
|
|
@@ -2461,7 +2457,7 @@ export interface LengthError<Exact extends number = number> extends TypeError<`L
|
|
|
2461
2457
|
* )(String);
|
|
2462
2458
|
* type UrlSafeString = typeof UrlSafeString.Output;
|
|
2463
2459
|
*
|
|
2464
|
-
* assertType<string & Brand<"UrlSafeString"
|
|
2460
|
+
* assertType<UrlSafeString, string & Brand<"UrlSafeString">>();
|
|
2465
2461
|
*
|
|
2466
2462
|
* assertOk(UrlSafeString.fromUnknown("abc-123_DEF"), "abc-123_DEF");
|
|
2467
2463
|
* const invalid = UrlSafeString.fromUnknown("not safe");
|
|
@@ -2604,6 +2600,12 @@ export interface MnemonicError extends TypeError<"Mnemonic"> {
|
|
|
2604
2600
|
/**
|
|
2605
2601
|
* Evolu Id: 16 bytes encoded as a 22-character {@link Base64Url}.
|
|
2606
2602
|
*
|
|
2603
|
+
* Like [Nano ID](https://github.com/ai/nanoid), it is compact and URL-safe.
|
|
2604
|
+
* Unlike Nano ID's 21-character default, an Evolu Id is the canonical Base64Url
|
|
2605
|
+
* encoding of a full 128-bit value, so it round-trips directly between its
|
|
2606
|
+
* string and byte representations with {@link idToIdBytes} and
|
|
2607
|
+
* {@link idBytesToId}. These helpers use native Base64 APIs.
|
|
2608
|
+
*
|
|
2607
2609
|
* {@link createId} is the privacy-preserving default. Use
|
|
2608
2610
|
* {@link createIdFromString} for stable mappings from external identifiers, or
|
|
2609
2611
|
* {@link createIdAsUuidv7} only when insertion locality is worth exposing the
|
|
@@ -2642,7 +2644,7 @@ export interface IdError extends TypeError<"Id"> {
|
|
|
2642
2644
|
* const userId = createId<"User">({ randomBytes: createRandomBytes() });
|
|
2643
2645
|
*
|
|
2644
2646
|
* assertTrue(Id.is(userId));
|
|
2645
|
-
* assertType<Id & Brand<"User"
|
|
2647
|
+
* assertType<typeof userId, Id & Brand<"User">>();
|
|
2646
2648
|
* ```
|
|
2647
2649
|
*
|
|
2648
2650
|
* @group String
|
|
@@ -2671,7 +2673,7 @@ export declare const createId: <B extends string = never>(deps: RandomBytesDep,
|
|
|
2671
2673
|
* const todoId = createIdFromString<"Todo">("external-todo-456");
|
|
2672
2674
|
*
|
|
2673
2675
|
* assertEqual(first, second);
|
|
2674
|
-
* assertType<Id & Brand<"Todo"
|
|
2676
|
+
* assertType<typeof todoId, Id & Brand<"Todo">>();
|
|
2675
2677
|
* ```
|
|
2676
2678
|
*
|
|
2677
2679
|
* @group String
|
|
@@ -2726,7 +2728,7 @@ export declare const createIdAsUuidv7: <B extends string = never>(deps: RandomBy
|
|
|
2726
2728
|
* const TodoId = id("Todo");
|
|
2727
2729
|
* const todoId = TodoId.orThrow(createIdFromString("todo"));
|
|
2728
2730
|
*
|
|
2729
|
-
* assertType<Id & Brand<"Todo"
|
|
2731
|
+
* assertType<typeof todoId, Id & Brand<"Todo">>();
|
|
2730
2732
|
* ```
|
|
2731
2733
|
*
|
|
2732
2734
|
* @group String
|
|
@@ -3088,7 +3090,7 @@ export type PositiveFiniteNumber = typeof PositiveFiniteNumber.Output;
|
|
|
3088
3090
|
* const Int = int(Number);
|
|
3089
3091
|
* type Int = typeof Int.Output;
|
|
3090
3092
|
*
|
|
3091
|
-
* assertType<number & Brand<"Int"
|
|
3093
|
+
* assertType<Int, number & Brand<"Int">>();
|
|
3092
3094
|
*
|
|
3093
3095
|
* assertOk(Int.fromUnknown(42), 42);
|
|
3094
3096
|
* const invalid = Int.fromUnknown(1.5);
|
|
@@ -3519,8 +3521,8 @@ export type NegativeDecimalString = typeof NegativeDecimalString.Output;
|
|
|
3519
3521
|
* const Tenths = multipleOf("0.1")(FiniteNumber);
|
|
3520
3522
|
*
|
|
3521
3523
|
* assertType<
|
|
3522
|
-
*
|
|
3523
|
-
*
|
|
3524
|
+
* typeof Tenths.Output,
|
|
3525
|
+
* FiniteNumber & Brand<"MultipleOf0.1">
|
|
3524
3526
|
* >();
|
|
3525
3527
|
*
|
|
3526
3528
|
* assertOk(Tenths.fromUnknown(0.3), 0.3);
|
|
@@ -3623,8 +3625,8 @@ export interface BetweenError<Min extends number = number, Max extends number =
|
|
|
3623
3625
|
* const result = UserIds.from.parent(["ada", "grace"]);
|
|
3624
3626
|
*
|
|
3625
3627
|
* assertType<
|
|
3626
|
-
*
|
|
3627
|
-
*
|
|
3628
|
+
* typeof result,
|
|
3629
|
+
* Result<ReadonlyArray<string & Brand<"UserId">>>
|
|
3628
3630
|
* >();
|
|
3629
3631
|
* assertOk(result, ["ada", "grace"]);
|
|
3630
3632
|
* assertOk(UserIds.fromUnknown(["ada", "grace"]), ["ada", "grace"]);
|
|
@@ -4274,8 +4276,8 @@ export { _Object as Object };
|
|
|
4274
4276
|
*
|
|
4275
4277
|
* assertOk(scoresFromInput, { ada: 10n, grace: 20n });
|
|
4276
4278
|
* assertType<
|
|
4277
|
-
*
|
|
4278
|
-
*
|
|
4279
|
+
* typeof scoresFromInput.value,
|
|
4280
|
+
* Readonly<Partial<Record<string, Int64>>>
|
|
4279
4281
|
* >();
|
|
4280
4282
|
* ```
|
|
4281
4283
|
*
|
|
@@ -4607,7 +4609,7 @@ type ObjectProperty = ObjectProps[string];
|
|
|
4607
4609
|
* const userFromInput = User.from.parent(userInput.value);
|
|
4608
4610
|
*
|
|
4609
4611
|
* assertOk(userFromInput, { name: "Ada", loginCount: 42n });
|
|
4610
|
-
* assertType<typeof
|
|
4612
|
+
* assertType<typeof userFromInput.value, typeof User.Output>();
|
|
4611
4613
|
* ```
|
|
4612
4614
|
*
|
|
4613
4615
|
* Note that TypeScript does not model an object's runtime prototype. This can
|
|
@@ -4712,7 +4714,7 @@ export declare function object<const Props extends ObjectProps>(props: Props, ..
|
|
|
4712
4714
|
* authorization: "Bearer token",
|
|
4713
4715
|
* "x-request-id": "request-1",
|
|
4714
4716
|
* });
|
|
4715
|
-
* assertType<
|
|
4717
|
+
* assertType<(typeof result.value)["x-request-id"], string | undefined>();
|
|
4716
4718
|
* ```
|
|
4717
4719
|
*/
|
|
4718
4720
|
export declare function object<const Props extends ObjectProps, const Rest extends RecordTypeNode & ConcreteTypeNode>(props: Props, record: Rest, ...validation: [
|
|
@@ -5122,10 +5124,10 @@ export type UnknownResult = typeof UnknownResult.Output;
|
|
|
5122
5124
|
* });
|
|
5123
5125
|
* assertFalse(Loading.is({ type: "Loading", progress: 1 }));
|
|
5124
5126
|
* assertType<
|
|
5125
|
-
* true,
|
|
5126
5127
|
* typeof Loading.Output extends { readonly type: "Loading" }
|
|
5127
5128
|
* ? true
|
|
5128
|
-
* : false
|
|
5129
|
+
* : false,
|
|
5130
|
+
* true
|
|
5129
5131
|
* >();
|
|
5130
5132
|
* ```
|
|
5131
5133
|
*
|
|
@@ -5177,7 +5179,7 @@ export declare function typed<const Tag extends TypeName, const Props extends Ob
|
|
|
5177
5179
|
* label: "Ready",
|
|
5178
5180
|
* note: "Connected",
|
|
5179
5181
|
* });
|
|
5180
|
-
* assertType<
|
|
5182
|
+
* assertType<typeof result.value.note, string | undefined>();
|
|
5181
5183
|
* ```
|
|
5182
5184
|
*/
|
|
5183
5185
|
export declare function typed<const Tag extends TypeName, const Props extends ObjectProps, const Rest extends RecordTypeNode & ConcreteTypeNode>(tag: ValidateTypedTag<Tag>, props: Props, record: Rest, ...validation: [
|
|
@@ -5260,7 +5262,7 @@ export interface Typed<Tag extends TypeName> {
|
|
|
5260
5262
|
*
|
|
5261
5263
|
* type CreateMessage = ExtractTyped<Message, "Create">;
|
|
5262
5264
|
*
|
|
5263
|
-
* assertType<typeof Create.Output
|
|
5265
|
+
* assertType<CreateMessage, typeof Create.Output>();
|
|
5264
5266
|
*
|
|
5265
5267
|
* // @ts-expect-error "Cretae" is not a Message type.
|
|
5266
5268
|
* type _Typo = ExtractTyped<Message, "Cretae">;
|
|
@@ -5603,7 +5605,7 @@ type DiscriminatedUnionDuplicateValueError<Key extends string, Expected extends
|
|
|
5603
5605
|
* value: "root",
|
|
5604
5606
|
* children: [{ value: "leaf", children: [] }],
|
|
5605
5607
|
* });
|
|
5606
|
-
* assertType<
|
|
5608
|
+
* assertType<typeof result.value, Tree>();
|
|
5607
5609
|
* ```
|
|
5608
5610
|
*
|
|
5609
5611
|
* @group Recursive
|
|
@@ -5669,7 +5671,7 @@ type LazyTargetConcreteTypeError = CompileTimeError<"Type", "Lazy Type definitio
|
|
|
5669
5671
|
*
|
|
5670
5672
|
* assertOk(result);
|
|
5671
5673
|
* assertSame(result.value, value);
|
|
5672
|
-
* assertType<
|
|
5674
|
+
* assertType<typeof result.value, Data>();
|
|
5673
5675
|
* ```
|
|
5674
5676
|
*
|
|
5675
5677
|
* @group Base
|
|
@@ -5702,8 +5704,8 @@ export type Data = undefined | null | string | number | bigint | boolean | Reado
|
|
|
5702
5704
|
* readonly run: () => void;
|
|
5703
5705
|
* }
|
|
5704
5706
|
*
|
|
5705
|
-
* assertType<
|
|
5706
|
-
* assertType<
|
|
5707
|
+
* assertType<IsData<User>, true>();
|
|
5708
|
+
* assertType<IsData<Service>, false>();
|
|
5707
5709
|
* ```
|
|
5708
5710
|
*
|
|
5709
5711
|
* @group Base
|
|
@@ -5934,7 +5936,7 @@ export interface JsonError extends TypeError<"Json"> {
|
|
|
5934
5936
|
* const result = JsonValue.fromUnknown(input);
|
|
5935
5937
|
*
|
|
5936
5938
|
* assertOk(result, input);
|
|
5937
|
-
* assertType<
|
|
5939
|
+
* assertType<typeof result.value, JsonValue>();
|
|
5938
5940
|
* ```
|
|
5939
5941
|
*
|
|
5940
5942
|
* @group JSON
|
|
@@ -6054,8 +6056,8 @@ export declare const JsonValueFromJson: TransformType<BrandType<Type<"String", s
|
|
|
6054
6056
|
* const userJson = userToUserJson(user);
|
|
6055
6057
|
*
|
|
6056
6058
|
* assertType<
|
|
6057
|
-
*
|
|
6058
|
-
*
|
|
6059
|
+
* typeof userJson,
|
|
6060
|
+
* string & Brand<"Json"> & Brand<"UserJson">
|
|
6059
6061
|
* >();
|
|
6060
6062
|
* assertEqual(userJson, '{"name":"Ada","age":37}');
|
|
6061
6063
|
* assertEqual(UserJson.orThrow(userJson), userJson);
|