@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/src/Type.ts
CHANGED
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
* - Predefined constraints add a {@link Brand} to their Output.
|
|
15
15
|
* - Invalid declarations produce readable {@link CompileTimeError} types when the
|
|
16
16
|
* compiler can detect them.
|
|
17
|
-
* - Evolu Type uses runtime {@link assert | assertions} to detect
|
|
18
|
-
*
|
|
19
|
-
* arrays.
|
|
17
|
+
* - Evolu Type uses runtime {@link assert | assertions} to detect bugs that
|
|
18
|
+
* TypeScript cannot prevent, such as excess properties and sparse arrays.
|
|
20
19
|
* - Typed `from` boundaries allow connecting value producers to domain fields
|
|
21
20
|
* through their exact TypeScript types, so incompatible contract changes are
|
|
22
21
|
* compile-time errors rather than runtime validation errors.
|
|
@@ -77,14 +76,14 @@
|
|
|
77
76
|
* type Age = typeof Age.Output;
|
|
78
77
|
*
|
|
79
78
|
* assertType<
|
|
79
|
+
* Age,
|
|
80
80
|
* number &
|
|
81
81
|
* Brand<"NonNaN"> &
|
|
82
82
|
* Brand<"Finite"> &
|
|
83
83
|
* Brand<"Int"> &
|
|
84
84
|
* Brand<"NonNegative"> &
|
|
85
85
|
* Brand<"LessThan200"> &
|
|
86
|
-
* Brand<"Age"
|
|
87
|
-
* Age
|
|
86
|
+
* Brand<"Age">
|
|
88
87
|
* >();
|
|
89
88
|
*
|
|
90
89
|
* const User = object({
|
|
@@ -97,13 +96,13 @@
|
|
|
97
96
|
* const user = User.fromUnknown(value);
|
|
98
97
|
*
|
|
99
98
|
* assertOk(user, { name: "Ada", age: 37 });
|
|
100
|
-
* assertType<typeof
|
|
99
|
+
* assertType<typeof user.value, typeof User.Output>();
|
|
101
100
|
*
|
|
102
101
|
* const invalidUser = User.fromUnknown({ name: "Ada", age: 37.5 });
|
|
103
102
|
*
|
|
104
103
|
* assertErr(invalidUser);
|
|
105
104
|
* // InferErrors includes every structured error User.fromUnknown can return.
|
|
106
|
-
* assertType<InferErrors<typeof User
|
|
105
|
+
* assertType<typeof invalidUser.error, InferErrors<typeof User>>();
|
|
107
106
|
* assertType(Data, invalidUser.error);
|
|
108
107
|
* assertEqual(invalidUser.error, {
|
|
109
108
|
* type: "Object",
|
|
@@ -185,11 +184,11 @@
|
|
|
185
184
|
*
|
|
186
185
|
* // No "not a string" or "not trimmed" errors: the input guarantees both.
|
|
187
186
|
* assertType<
|
|
187
|
+
* typeof validatedTitle,
|
|
188
188
|
* Result<
|
|
189
189
|
* NonEmptyTrimmedString100,
|
|
190
190
|
* MaxLengthError<100> | MinLengthError<1>
|
|
191
|
-
*
|
|
192
|
-
* typeof validatedTitle
|
|
191
|
+
* >
|
|
193
192
|
* >();
|
|
194
193
|
* assertOk(validatedTitle, "Buy milk");
|
|
195
194
|
* ```
|
|
@@ -214,9 +213,8 @@
|
|
|
214
213
|
* Defending against it would add complexity without creating a meaningful
|
|
215
214
|
* security boundary.
|
|
216
215
|
*
|
|
217
|
-
* Runtime assertions still detect
|
|
218
|
-
*
|
|
219
|
-
* code.
|
|
216
|
+
* Runtime assertions still detect bugs that TypeScript cannot prevent. They are
|
|
217
|
+
* correctness checks, not defenses against malicious code.
|
|
220
218
|
*
|
|
221
219
|
* Evolu does not support subclassing native JavaScript objects. Such subclasses
|
|
222
220
|
* can be classified as their reported built-in representation, but their
|
|
@@ -350,9 +348,10 @@
|
|
|
350
348
|
* Consequently, structural representation errors such as sparse Arrays,
|
|
351
349
|
* accessors, and excess properties normally do not enter user-facing validation
|
|
352
350
|
* in typed application flows. They violate the producer's declared contract and
|
|
353
|
-
* throw
|
|
354
|
-
* schema-authoring tool, import, or external protocol, the
|
|
355
|
-
* legitimate typed validation errors and their formatter
|
|
351
|
+
* therefore throw instead of becoming validation errors. At a genuinely unknown
|
|
352
|
+
* boundary, such as a schema-authoring tool, import, or external protocol, the
|
|
353
|
+
* same issues are legitimate typed validation errors and their formatter
|
|
354
|
+
* messages are useful.
|
|
356
355
|
*
|
|
357
356
|
* This distinction applies to data failures. Any Type operation, including
|
|
358
357
|
* `fromUnknown`, can throw when trusted Type-declaration code, such as a
|
|
@@ -666,7 +665,7 @@ export interface Type<
|
|
|
666
665
|
* const values: ReadonlyArray<unknown> = [42n, "42", null];
|
|
667
666
|
* const integers = values.filter(Int64FromInt64String.is);
|
|
668
667
|
*
|
|
669
|
-
* assertType<Array<Int64
|
|
668
|
+
* assertType<typeof integers, Array<Int64>>();
|
|
670
669
|
* assertTrue(Int64FromInt64String.is(42n));
|
|
671
670
|
* assertFalse(Int64FromInt64String.is("42"));
|
|
672
671
|
* ```
|
|
@@ -681,10 +680,10 @@ export interface Type<
|
|
|
681
680
|
* Type toward the root. The deepest suffix accepts the root Output.
|
|
682
681
|
*
|
|
683
682
|
* Every entry point asserts its selected boundary before running the
|
|
684
|
-
* remaining pipeline. Assertion failures throw because they indicate a
|
|
685
|
-
*
|
|
686
|
-
* and its cause preserves the structured validation error. Only
|
|
687
|
-
* introduced after that boundary are returned through `Result`.
|
|
683
|
+
* remaining pipeline. Assertion failures throw because they indicate a bug
|
|
684
|
+
* that must be fixed. The Error message identifies the expected boundary
|
|
685
|
+
* Type, and its cause preserves the structured validation error. Only
|
|
686
|
+
* failures introduced after that boundary are returned through `Result`.
|
|
688
687
|
*
|
|
689
688
|
* ### Example
|
|
690
689
|
*
|
|
@@ -729,8 +728,8 @@ export interface Type<
|
|
|
729
728
|
* const result = saveTodo(title, note);
|
|
730
729
|
*
|
|
731
730
|
* assertType<
|
|
732
|
-
*
|
|
733
|
-
* typeof
|
|
731
|
+
* typeof result,
|
|
732
|
+
* Result<typeof Todo.Output, MaxLengthError<100> | MinLengthError<1>>
|
|
734
733
|
* >();
|
|
735
734
|
* assertOk(result, { title, note });
|
|
736
735
|
* ```
|
|
@@ -772,7 +771,7 @@ export interface Type<
|
|
|
772
771
|
* `from` operation, which accepts this Type's `Input`.
|
|
773
772
|
*
|
|
774
773
|
* The typed `Input` boundary is asserted before the remaining pipeline runs.
|
|
775
|
-
* A boundary violation
|
|
774
|
+
* A boundary violation is a bug, so it throws directly; `getOrThrow` maps
|
|
776
775
|
* only a validation error returned after that boundary.
|
|
777
776
|
*
|
|
778
777
|
* `Type.orThrow.parent(value)` does not exist. To throw after starting from a
|
|
@@ -811,8 +810,8 @@ export interface Type<
|
|
|
811
810
|
* `from` operation, which accepts this Type's `Input`.
|
|
812
811
|
*
|
|
813
812
|
* The typed `Input` boundary is asserted before the remaining pipeline runs.
|
|
814
|
-
* A boundary violation
|
|
815
|
-
*
|
|
813
|
+
* A boundary violation is a bug, so it throws directly; `getOrNull` maps only
|
|
814
|
+
* a validation error returned after that boundary to `null`.
|
|
816
815
|
*
|
|
817
816
|
* `Type.orNull.parent(value)` does not exist. To return `null` after starting
|
|
818
817
|
* from a typed boundary, call `getOrNull` with the corresponding `from`
|
|
@@ -1035,18 +1034,18 @@ const formatDefaultRuntimeTypeIssue: RuntimeFormatTypeIssue = (issue) =>
|
|
|
1035
1034
|
issue.formatError(issue.error);
|
|
1036
1035
|
|
|
1037
1036
|
/**
|
|
1038
|
-
* Asserts
|
|
1039
|
-
* {@link Type} Output domain.
|
|
1037
|
+
* Asserts type equality or validates a value with a {@link Type}.
|
|
1040
1038
|
*
|
|
1041
|
-
* - `assertType<
|
|
1042
|
-
* evaluating a value.
|
|
1039
|
+
* - `assertType<Actual, Expected>()` requires compiler-identical types without
|
|
1040
|
+
* evaluating a value. It is Evolu's platform-agnostic equivalent of Vitest's
|
|
1041
|
+
* `expectTypeOf(...).toEqualTypeOf<...>()` and does not require a test
|
|
1042
|
+
* runner.
|
|
1043
1043
|
* - `assertType(type, value)` validates and narrows a runtime value to the Type's
|
|
1044
1044
|
* Output.
|
|
1045
1045
|
*
|
|
1046
|
-
* Use the runtime form for
|
|
1047
|
-
* external input with `Type.fromUnknown` so validation
|
|
1048
|
-
*
|
|
1049
|
-
* preserves the exact Output validation error as the thrown Error's cause.
|
|
1046
|
+
* Use the runtime form for code-correctness invariants, not expected validation
|
|
1047
|
+
* failures. Validate external input with `Type.fromUnknown` so validation
|
|
1048
|
+
* failures remain typed values.
|
|
1050
1049
|
*
|
|
1051
1050
|
* ### Example
|
|
1052
1051
|
*
|
|
@@ -1060,23 +1059,20 @@ const formatDefaultRuntimeTypeIssue: RuntimeFormatTypeIssue = (issue) =>
|
|
|
1060
1059
|
* const value: unknown = "Evolu";
|
|
1061
1060
|
* assertType(NonEmptyTrimmedString100, value);
|
|
1062
1061
|
* assertType<
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
* Brand<"MinLength1"> &
|
|
1066
|
-
* Brand<"MaxLength100">,
|
|
1067
|
-
* typeof value
|
|
1062
|
+
* typeof value,
|
|
1063
|
+
* string & Brand<"Trimmed"> & Brand<"MinLength1"> & Brand<"MaxLength100">
|
|
1068
1064
|
* >();
|
|
1069
1065
|
* ```
|
|
1070
1066
|
*
|
|
1071
1067
|
* @group Core
|
|
1072
1068
|
*/
|
|
1073
|
-
export function assertType<
|
|
1074
|
-
...error: IsSameType<
|
|
1069
|
+
export function assertType<Actual, Expected>(
|
|
1070
|
+
...error: IsSameType<Actual, Expected> extends true
|
|
1075
1071
|
? []
|
|
1076
1072
|
: [
|
|
1077
1073
|
error: CompileTimeError<
|
|
1078
1074
|
"assertType",
|
|
1079
|
-
"
|
|
1075
|
+
"Actual and expected types must be identical"
|
|
1080
1076
|
>,
|
|
1081
1077
|
]
|
|
1082
1078
|
): void;
|
|
@@ -1090,15 +1086,15 @@ export function assertType<T extends TypeNode>(
|
|
|
1090
1086
|
): void {
|
|
1091
1087
|
if (type === undefined) return;
|
|
1092
1088
|
|
|
1093
|
-
// TODO: Make assert prepend "Expected " and accept an optional third cause
|
|
1094
|
-
// argument. Then use it here and migrate every other assertion to pass an
|
|
1095
|
-
// expectation fragment.
|
|
1096
1089
|
const runtimeType = type as unknown as RuntimeTypeNode;
|
|
1097
1090
|
const result = runtimeType[outputValidationSymbol](value);
|
|
1098
1091
|
|
|
1099
|
-
if (
|
|
1100
|
-
|
|
1101
|
-
}
|
|
1092
|
+
if (result.ok) return;
|
|
1093
|
+
|
|
1094
|
+
assert(false, `Expected ${runtimeType.name}.`, {
|
|
1095
|
+
cause: result.error,
|
|
1096
|
+
stackStartFn: assertType,
|
|
1097
|
+
});
|
|
1102
1098
|
}
|
|
1103
1099
|
|
|
1104
1100
|
const assertTypeOutput = <Error extends TypeError>(
|
|
@@ -1116,7 +1112,7 @@ const assertTypeOutput = <Error extends TypeError>(
|
|
|
1116
1112
|
const result = validateOutput(value, options);
|
|
1117
1113
|
const error = (result as { readonly ok: false; readonly error: Error }).error;
|
|
1118
1114
|
|
|
1119
|
-
|
|
1115
|
+
assert(false, `Expected ${name}.`, { cause: error });
|
|
1120
1116
|
};
|
|
1121
1117
|
|
|
1122
1118
|
/**
|
|
@@ -1174,7 +1170,7 @@ const assertTypeOutput = <Error extends TypeError>(
|
|
|
1174
1170
|
* },
|
|
1175
1171
|
* );
|
|
1176
1172
|
*
|
|
1177
|
-
* assertType<typeof Label, typeof
|
|
1173
|
+
* assertType<typeof typesByLocale.cs.Label, typeof Label>();
|
|
1178
1174
|
*
|
|
1179
1175
|
* const result = typesByLocale.cs.Label.fromUnknown("");
|
|
1180
1176
|
* assertErr(result);
|
|
@@ -1597,7 +1593,7 @@ declare const identityEncodingSymbol: unique symbol;
|
|
|
1597
1593
|
*
|
|
1598
1594
|
* const user = User.orThrow({ name: "Ada", age: 37 });
|
|
1599
1595
|
*
|
|
1600
|
-
* assertType<typeof
|
|
1596
|
+
* assertType<typeof user, typeof User.Output>();
|
|
1601
1597
|
* assertEqual(user.name, "Ada");
|
|
1602
1598
|
* ```
|
|
1603
1599
|
*
|
|
@@ -2230,11 +2226,10 @@ const createChildType = <
|
|
|
2230
2226
|
* not lose distinctions present in the Output domain.
|
|
2231
2227
|
*
|
|
2232
2228
|
* Transformation callbacks are Type construction code. Their successful results
|
|
2233
|
-
* are asserted against the declared boundary so a broken callback
|
|
2234
|
-
*
|
|
2235
|
-
*
|
|
2236
|
-
*
|
|
2237
|
-
* return an `Err`.
|
|
2229
|
+
* are asserted against the declared boundary, so a broken callback throws
|
|
2230
|
+
* instead of becoming a validation error. Like all Type-construction callbacks,
|
|
2231
|
+
* they are trusted to follow their declared TypeScript types. A `Result<_,
|
|
2232
|
+
* never>` callback is therefore trusted never to return an `Err`.
|
|
2238
2233
|
*
|
|
2239
2234
|
* Errors from the parent and the forward callback remain unchanged. A forward
|
|
2240
2235
|
* callback error must use the transformation name as its type. Errors from the
|
|
@@ -2870,7 +2865,7 @@ export interface TypeOfError<
|
|
|
2870
2865
|
* const WireValue100 = maxLength(100)(String);
|
|
2871
2866
|
* type WireValue100 = typeof WireValue100.Output;
|
|
2872
2867
|
*
|
|
2873
|
-
* assertType<string & Brand<"MaxLength100"
|
|
2868
|
+
* assertType<WireValue100, string & Brand<"MaxLength100">>();
|
|
2874
2869
|
* assertOk(WireValue100.fromUnknown(""), "");
|
|
2875
2870
|
* assertOk(WireValue100.fromUnknown(" value "), " value ");
|
|
2876
2871
|
* ```
|
|
@@ -2914,34 +2909,34 @@ export const String = /*#__PURE__*/ createTypeOfType("String");
|
|
|
2914
2909
|
* } from "@evolu/common";
|
|
2915
2910
|
*
|
|
2916
2911
|
* // Note how every additional constraint accumulates its Brand.
|
|
2917
|
-
* assertType<
|
|
2918
|
-
* assertType<number & Brand<"NonNaN"
|
|
2912
|
+
* assertType<typeof Number.Output, number>();
|
|
2913
|
+
* assertType<typeof NonNaNNumber.Output, number & Brand<"NonNaN">>();
|
|
2919
2914
|
* assertType<
|
|
2920
|
-
*
|
|
2921
|
-
*
|
|
2915
|
+
* typeof FiniteNumber.Output,
|
|
2916
|
+
* number & Brand<"NonNaN"> & Brand<"Finite">
|
|
2922
2917
|
* >();
|
|
2923
2918
|
* assertType<
|
|
2924
|
-
*
|
|
2925
|
-
*
|
|
2919
|
+
* typeof Int.Output,
|
|
2920
|
+
* number & Brand<"NonNaN"> & Brand<"Finite"> & Brand<"Int">
|
|
2926
2921
|
* >();
|
|
2927
2922
|
* assertType<
|
|
2923
|
+
* typeof NonNegativeInt.Output,
|
|
2928
2924
|
* number &
|
|
2929
2925
|
* Brand<"NonNaN"> &
|
|
2930
2926
|
* Brand<"Finite"> &
|
|
2931
2927
|
* Brand<"Int"> &
|
|
2932
|
-
* Brand<"NonNegative"
|
|
2933
|
-
* typeof NonNegativeInt.Output
|
|
2928
|
+
* Brand<"NonNegative">
|
|
2934
2929
|
* >();
|
|
2935
2930
|
*
|
|
2936
2931
|
* assertType<
|
|
2932
|
+
* typeof Age.Output,
|
|
2937
2933
|
* number &
|
|
2938
2934
|
* Brand<"NonNaN"> &
|
|
2939
2935
|
* Brand<"Finite"> &
|
|
2940
2936
|
* Brand<"Int"> &
|
|
2941
2937
|
* Brand<"NonNegative"> &
|
|
2942
2938
|
* Brand<"LessThan200"> &
|
|
2943
|
-
* Brand<"Age"
|
|
2944
|
-
* typeof Age.Output
|
|
2939
|
+
* Brand<"Age">
|
|
2945
2940
|
* >();
|
|
2946
2941
|
*
|
|
2947
2942
|
* assertOk(Age.fromUnknown(122), 122);
|
|
@@ -3153,8 +3148,8 @@ export function objectTag<Name extends keyof ObjectTagOutputByName>(
|
|
|
3153
3148
|
* assertOk(result);
|
|
3154
3149
|
* assertSame(result.value, value);
|
|
3155
3150
|
* assertType<
|
|
3156
|
-
* true,
|
|
3157
|
-
*
|
|
3151
|
+
* typeof result.value extends TaggedValue ? true : false,
|
|
3152
|
+
* true
|
|
3158
3153
|
* >();
|
|
3159
3154
|
* assertEqual(TaggedValueType.expected, "TaggedValue");
|
|
3160
3155
|
* ```
|
|
@@ -3375,7 +3370,7 @@ type InstanceConstructorCompileTimeError = CompileTimeError<
|
|
|
3375
3370
|
*
|
|
3376
3371
|
* const Ready = literal("ready");
|
|
3377
3372
|
*
|
|
3378
|
-
* assertType<
|
|
3373
|
+
* assertType<typeof Ready.Output, "ready">();
|
|
3379
3374
|
* assertOk(Ready.fromUnknown("ready"), "ready");
|
|
3380
3375
|
* const invalid = Ready.fromUnknown("pending");
|
|
3381
3376
|
* assertErr(invalid);
|
|
@@ -4015,20 +4010,20 @@ interface UnionErrorValue<
|
|
|
4015
4010
|
*
|
|
4016
4011
|
* // Output is the decoded language and region.
|
|
4017
4012
|
* type SupportedLocale = typeof SupportedLocale.Output;
|
|
4018
|
-
* assertType<readonly ["en" | "cs", "US" | "CZ"]
|
|
4013
|
+
* assertType<SupportedLocale, readonly ["en" | "cs", "US" | "CZ"]>();
|
|
4019
4014
|
*
|
|
4020
4015
|
* // The parent Output is the canonical locale string.
|
|
4021
4016
|
* type SupportedLocaleLiteral = typeof SupportedLocale.parent.Output;
|
|
4022
4017
|
* assertType<
|
|
4023
|
-
*
|
|
4024
|
-
*
|
|
4018
|
+
* SupportedLocaleLiteral,
|
|
4019
|
+
* "en-US" | "en-CZ" | "cs-US" | "cs-CZ"
|
|
4025
4020
|
* >();
|
|
4026
4021
|
*
|
|
4027
4022
|
* // Parse an unknown string into structured data.
|
|
4028
4023
|
* const result = SupportedLocale.fromUnknown("cs-CZ");
|
|
4029
4024
|
* assertOk(result, ["cs", "CZ"]);
|
|
4030
4025
|
* const locale = result.value;
|
|
4031
|
-
* assertType<
|
|
4026
|
+
* assertType<typeof locale, SupportedLocale>();
|
|
4032
4027
|
* const invalid = SupportedLocale.fromUnknown("cs/CZ");
|
|
4033
4028
|
* assertErr(invalid);
|
|
4034
4029
|
* assertType(Data, invalid.error);
|
|
@@ -4040,13 +4035,13 @@ interface UnionErrorValue<
|
|
|
4040
4035
|
*
|
|
4041
4036
|
* // Encode structured data into its canonical string.
|
|
4042
4037
|
* const localeLiteral = SupportedLocale.to(locale);
|
|
4043
|
-
* assertType<
|
|
4038
|
+
* assertType<typeof localeLiteral, SupportedLocaleLiteral>();
|
|
4044
4039
|
* assertEqual(localeLiteral, "cs-CZ");
|
|
4045
4040
|
*
|
|
4046
4041
|
* // Validate a string configuration value.
|
|
4047
4042
|
* const configValue: unknown = "cs-CZ";
|
|
4048
4043
|
* assertType(SupportedLocale.parent, configValue);
|
|
4049
|
-
* assertType<
|
|
4044
|
+
* assertType<typeof configValue, SupportedLocaleLiteral>();
|
|
4050
4045
|
* assertFalse(SupportedLocale.parent.is("fr-CZ"));
|
|
4051
4046
|
* ```
|
|
4052
4047
|
*
|
|
@@ -4098,11 +4093,11 @@ interface UnionErrorValue<
|
|
|
4098
4093
|
* const result = ItemId.fromUnknown("item-42");
|
|
4099
4094
|
* assertOk(result, [42n]);
|
|
4100
4095
|
* const itemId = result.value;
|
|
4101
|
-
* assertType<
|
|
4096
|
+
* assertType<typeof itemId, ItemId>();
|
|
4102
4097
|
*
|
|
4103
4098
|
* // Encode the structured data into its canonical string.
|
|
4104
4099
|
* const itemIdLiteral = ItemId.to(itemId);
|
|
4105
|
-
* assertType<
|
|
4100
|
+
* assertType<typeof itemIdLiteral, ItemIdLiteral>();
|
|
4106
4101
|
* assertEqual(itemIdLiteral, "item-42");
|
|
4107
4102
|
*
|
|
4108
4103
|
* // TypeScript cannot prove from the literal alone that "42" is a valid Int64 encoding.
|
|
@@ -4319,7 +4314,7 @@ const createTemplateLiteralParserType = <
|
|
|
4319
4314
|
String.from(value);
|
|
4320
4315
|
const result = decodeString(value, options);
|
|
4321
4316
|
if (!result.ok || encodeCaptures(result.value) !== value) {
|
|
4322
|
-
|
|
4317
|
+
assert(false, "Expected TemplateLiteral.", {
|
|
4323
4318
|
cause: result.ok
|
|
4324
4319
|
? ({
|
|
4325
4320
|
type: "TemplateLiteral",
|
|
@@ -4430,8 +4425,8 @@ export interface TemplateLiteralType<
|
|
|
4430
4425
|
* const Locale = templateLiteral(Language, "-", Region);
|
|
4431
4426
|
*
|
|
4432
4427
|
* assertType<
|
|
4433
|
-
*
|
|
4434
|
-
*
|
|
4428
|
+
* typeof Locale.Output,
|
|
4429
|
+
* "en-US" | "en-CZ" | "cs-US" | "cs-CZ"
|
|
4435
4430
|
* >();
|
|
4436
4431
|
* assertOk(Locale.fromUnknown("cs-CZ"), "cs-CZ");
|
|
4437
4432
|
* assertFalse(Locale.is("fr-CZ"));
|
|
@@ -4890,7 +4885,7 @@ const getTemplateLiteralPartFraming = (
|
|
|
4890
4885
|
* type Int64 = typeof Int64.Output;
|
|
4891
4886
|
*
|
|
4892
4887
|
* // Note the Brand.
|
|
4893
|
-
* assertType<bigint & Brand<"Int64"
|
|
4888
|
+
* assertType<Int64, bigint & Brand<"Int64">>();
|
|
4894
4889
|
*
|
|
4895
4890
|
* interface Int64Error extends TypeError<"Int64"> {
|
|
4896
4891
|
* readonly value: bigint;
|
|
@@ -5162,7 +5157,7 @@ export interface UInt64Error extends TypeError<"UInt64"> {
|
|
|
5162
5157
|
* const TrimmedString = trimmed(String);
|
|
5163
5158
|
* type TrimmedString = typeof TrimmedString.Output;
|
|
5164
5159
|
*
|
|
5165
|
-
* assertType<string & Brand<"Trimmed"
|
|
5160
|
+
* assertType<TrimmedString, string & Brand<"Trimmed">>();
|
|
5166
5161
|
*
|
|
5167
5162
|
* interface TrimmedError extends TypeError<"Trimmed"> {
|
|
5168
5163
|
* readonly value: string;
|
|
@@ -5236,8 +5231,8 @@ export type BrandFactory<
|
|
|
5236
5231
|
* const LessThan100 = lessThan(100)(Number);
|
|
5237
5232
|
* type LessThan100 = typeof LessThan100.Output;
|
|
5238
5233
|
*
|
|
5239
|
-
* assertType<
|
|
5240
|
-
* assertType<number & Brand<"LessThan100"
|
|
5234
|
+
* assertType<typeof LessThan100.name, "LessThan100">();
|
|
5235
|
+
* assertType<LessThan100, number & Brand<"LessThan100">>();
|
|
5241
5236
|
*
|
|
5242
5237
|
* interface LessThanError<
|
|
5243
5238
|
* Max extends number,
|
|
@@ -5286,7 +5281,7 @@ type BrandFactoryNumberError = CompileTimeError<
|
|
|
5286
5281
|
* const CapitalizedString = capitalized(String);
|
|
5287
5282
|
* type CapitalizedString = typeof CapitalizedString.Output;
|
|
5288
5283
|
*
|
|
5289
|
-
* assertType<string & Brand<"Capitalized"
|
|
5284
|
+
* assertType<CapitalizedString, string & Brand<"Capitalized">>();
|
|
5290
5285
|
*
|
|
5291
5286
|
* assertOk(CapitalizedString.fromUnknown("Evolu"), "Evolu");
|
|
5292
5287
|
* const invalid = CapitalizedString.fromUnknown("evolu");
|
|
@@ -5613,7 +5608,7 @@ export interface LengthError<
|
|
|
5613
5608
|
* )(String);
|
|
5614
5609
|
* type UrlSafeString = typeof UrlSafeString.Output;
|
|
5615
5610
|
*
|
|
5616
|
-
* assertType<string & Brand<"UrlSafeString"
|
|
5611
|
+
* assertType<UrlSafeString, string & Brand<"UrlSafeString">>();
|
|
5617
5612
|
*
|
|
5618
5613
|
* assertOk(UrlSafeString.fromUnknown("abc-123_DEF"), "abc-123_DEF");
|
|
5619
5614
|
* const invalid = UrlSafeString.fromUnknown("not safe");
|
|
@@ -5695,6 +5690,7 @@ const base64UrlOptions = {
|
|
|
5695
5690
|
|
|
5696
5691
|
const uint8ArrayToBase64UrlString = (bytes: Uint8Array): string => {
|
|
5697
5692
|
if (hasNodeBuffer) {
|
|
5693
|
+
// oxlint-disable-next-line evolu/no-unnecessary-global-this -- Use the global object constructor verified by hasNodeBuffer even if a realm lexical binding shadows it.
|
|
5698
5694
|
return globalThis.Buffer.from(bytes).toString("base64url");
|
|
5699
5695
|
}
|
|
5700
5696
|
const uint8ArrayPrototype: object = globalThis.Uint8Array.prototype;
|
|
@@ -5712,6 +5708,7 @@ const uint8ArrayToBase64UrlString = (bytes: Uint8Array): string => {
|
|
|
5712
5708
|
|
|
5713
5709
|
const base64UrlStringToUint8Array = (value: string): Uint8Array => {
|
|
5714
5710
|
if (hasNodeBuffer) {
|
|
5711
|
+
// oxlint-disable-next-line evolu/no-unnecessary-global-this -- Use the global object constructor verified by hasNodeBuffer even if a realm lexical binding shadows it.
|
|
5715
5712
|
const buffer = globalThis.Buffer.from(value, "base64url");
|
|
5716
5713
|
return new globalThis.Uint8Array(buffer);
|
|
5717
5714
|
}
|
|
@@ -5876,6 +5873,12 @@ export interface MnemonicError extends TypeError<"Mnemonic"> {
|
|
|
5876
5873
|
/**
|
|
5877
5874
|
* Evolu Id: 16 bytes encoded as a 22-character {@link Base64Url}.
|
|
5878
5875
|
*
|
|
5876
|
+
* Like [Nano ID](https://github.com/ai/nanoid), it is compact and URL-safe.
|
|
5877
|
+
* Unlike Nano ID's 21-character default, an Evolu Id is the canonical Base64Url
|
|
5878
|
+
* encoding of a full 128-bit value, so it round-trips directly between its
|
|
5879
|
+
* string and byte representations with {@link idToIdBytes} and
|
|
5880
|
+
* {@link idBytesToId}. These helpers use native Base64 APIs.
|
|
5881
|
+
*
|
|
5879
5882
|
* {@link createId} is the privacy-preserving default. Use
|
|
5880
5883
|
* {@link createIdFromString} for stable mappings from external identifiers, or
|
|
5881
5884
|
* {@link createIdAsUuidv7} only when insertion locality is worth exposing the
|
|
@@ -5925,7 +5928,7 @@ export interface IdError extends TypeError<"Id"> {
|
|
|
5925
5928
|
* const userId = createId<"User">({ randomBytes: createRandomBytes() });
|
|
5926
5929
|
*
|
|
5927
5930
|
* assertTrue(Id.is(userId));
|
|
5928
|
-
* assertType<Id & Brand<"User"
|
|
5931
|
+
* assertType<typeof userId, Id & Brand<"User">>();
|
|
5929
5932
|
* ```
|
|
5930
5933
|
*
|
|
5931
5934
|
* @group String
|
|
@@ -5959,7 +5962,7 @@ export const createId = <B extends string = never>(
|
|
|
5959
5962
|
* const todoId = createIdFromString<"Todo">("external-todo-456");
|
|
5960
5963
|
*
|
|
5961
5964
|
* assertEqual(first, second);
|
|
5962
|
-
* assertType<Id & Brand<"Todo"
|
|
5965
|
+
* assertType<typeof todoId, Id & Brand<"Todo">>();
|
|
5963
5966
|
* ```
|
|
5964
5967
|
*
|
|
5965
5968
|
* @group String
|
|
@@ -6039,7 +6042,7 @@ export const createIdAsUuidv7 = <B extends string = never>(
|
|
|
6039
6042
|
* const TodoId = id("Todo");
|
|
6040
6043
|
* const todoId = TodoId.orThrow(createIdFromString("todo"));
|
|
6041
6044
|
*
|
|
6042
|
-
* assertType<Id & Brand<"Todo"
|
|
6045
|
+
* assertType<typeof todoId, Id & Brand<"Todo">>();
|
|
6043
6046
|
* ```
|
|
6044
6047
|
*
|
|
6045
6048
|
* @group String
|
|
@@ -6587,7 +6590,7 @@ export type PositiveFiniteNumber = typeof PositiveFiniteNumber.Output;
|
|
|
6587
6590
|
* const Int = int(Number);
|
|
6588
6591
|
* type Int = typeof Int.Output;
|
|
6589
6592
|
*
|
|
6590
|
-
* assertType<number & Brand<"Int"
|
|
6593
|
+
* assertType<Int, number & Brand<"Int">>();
|
|
6591
6594
|
*
|
|
6592
6595
|
* assertOk(Int.fromUnknown(42), 42);
|
|
6593
6596
|
* const invalid = Int.fromUnknown(1.5);
|
|
@@ -7240,8 +7243,8 @@ export type NegativeDecimalString = typeof NegativeDecimalString.Output;
|
|
|
7240
7243
|
* const Tenths = multipleOf("0.1")(FiniteNumber);
|
|
7241
7244
|
*
|
|
7242
7245
|
* assertType<
|
|
7243
|
-
*
|
|
7244
|
-
*
|
|
7246
|
+
* typeof Tenths.Output,
|
|
7247
|
+
* FiniteNumber & Brand<"MultipleOf0.1">
|
|
7245
7248
|
* >();
|
|
7246
7249
|
*
|
|
7247
7250
|
* assertOk(Tenths.fromUnknown(0.3), 0.3);
|
|
@@ -7476,8 +7479,8 @@ export interface BetweenError<
|
|
|
7476
7479
|
* const result = UserIds.from.parent(["ada", "grace"]);
|
|
7477
7480
|
*
|
|
7478
7481
|
* assertType<
|
|
7479
|
-
*
|
|
7480
|
-
*
|
|
7482
|
+
* typeof result,
|
|
7483
|
+
* Result<ReadonlyArray<string & Brand<"UserId">>>
|
|
7481
7484
|
* >();
|
|
7482
7485
|
* assertOk(result, ["ada", "grace"]);
|
|
7483
7486
|
* assertOk(UserIds.fromUnknown(["ada", "grace"]), ["ada", "grace"]);
|
|
@@ -9617,8 +9620,8 @@ export { _Object as Object };
|
|
|
9617
9620
|
*
|
|
9618
9621
|
* assertOk(scoresFromInput, { ada: 10n, grace: 20n });
|
|
9619
9622
|
* assertType<
|
|
9620
|
-
*
|
|
9621
|
-
*
|
|
9623
|
+
* typeof scoresFromInput.value,
|
|
9624
|
+
* Readonly<Partial<Record<string, Int64>>>
|
|
9622
9625
|
* >();
|
|
9623
9626
|
* ```
|
|
9624
9627
|
*
|
|
@@ -10388,7 +10391,7 @@ type ObjectProperty = ObjectProps[string];
|
|
|
10388
10391
|
* const userFromInput = User.from.parent(userInput.value);
|
|
10389
10392
|
*
|
|
10390
10393
|
* assertOk(userFromInput, { name: "Ada", loginCount: 42n });
|
|
10391
|
-
* assertType<typeof
|
|
10394
|
+
* assertType<typeof userFromInput.value, typeof User.Output>();
|
|
10392
10395
|
* ```
|
|
10393
10396
|
*
|
|
10394
10397
|
* Note that TypeScript does not model an object's runtime prototype. This can
|
|
@@ -10499,7 +10502,7 @@ export function object<const Props extends ObjectProps>(
|
|
|
10499
10502
|
* authorization: "Bearer token",
|
|
10500
10503
|
* "x-request-id": "request-1",
|
|
10501
10504
|
* });
|
|
10502
|
-
* assertType<
|
|
10505
|
+
* assertType<(typeof result.value)["x-request-id"], string | undefined>();
|
|
10503
10506
|
* ```
|
|
10504
10507
|
*/
|
|
10505
10508
|
export function object<
|
|
@@ -11820,10 +11823,10 @@ export type UnknownResult = typeof UnknownResult.Output;
|
|
|
11820
11823
|
* });
|
|
11821
11824
|
* assertFalse(Loading.is({ type: "Loading", progress: 1 }));
|
|
11822
11825
|
* assertType<
|
|
11823
|
-
* true,
|
|
11824
11826
|
* typeof Loading.Output extends { readonly type: "Loading" }
|
|
11825
11827
|
* ? true
|
|
11826
|
-
* : false
|
|
11828
|
+
* : false,
|
|
11829
|
+
* true
|
|
11827
11830
|
* >();
|
|
11828
11831
|
* ```
|
|
11829
11832
|
*
|
|
@@ -11888,7 +11891,7 @@ export function typed<
|
|
|
11888
11891
|
* label: "Ready",
|
|
11889
11892
|
* note: "Connected",
|
|
11890
11893
|
* });
|
|
11891
|
-
* assertType<
|
|
11894
|
+
* assertType<typeof result.value.note, string | undefined>();
|
|
11892
11895
|
* ```
|
|
11893
11896
|
*/
|
|
11894
11897
|
export function typed<
|
|
@@ -12005,7 +12008,7 @@ export interface Typed<Tag extends TypeName> {
|
|
|
12005
12008
|
*
|
|
12006
12009
|
* type CreateMessage = ExtractTyped<Message, "Create">;
|
|
12007
12010
|
*
|
|
12008
|
-
* assertType<typeof Create.Output
|
|
12011
|
+
* assertType<CreateMessage, typeof Create.Output>();
|
|
12009
12012
|
*
|
|
12010
12013
|
* // @ts-expect-error "Cretae" is not a Message type.
|
|
12011
12014
|
* type _Typo = ExtractTyped<Message, "Cretae">;
|
|
@@ -12868,7 +12871,7 @@ type RuntimeDiscriminatedUnionMember = RuntimeObjectTypeNode & {
|
|
|
12868
12871
|
* value: "root",
|
|
12869
12872
|
* children: [{ value: "leaf", children: [] }],
|
|
12870
12873
|
* });
|
|
12871
|
-
* assertType<
|
|
12874
|
+
* assertType<typeof result.value, Tree>();
|
|
12872
12875
|
* ```
|
|
12873
12876
|
*
|
|
12874
12877
|
* @group Recursive
|
|
@@ -12898,7 +12901,7 @@ export function lazy(getType: Thunk<TypeNode>): TypeNode {
|
|
|
12898
12901
|
false,
|
|
12899
12902
|
"A Lazy Type definition must not resolve itself while it is being created.",
|
|
12900
12903
|
);
|
|
12901
|
-
//
|
|
12904
|
+
// oxlint-disable-next-line eslint/no-fallthrough
|
|
12902
12905
|
case "unresolved": {
|
|
12903
12906
|
resolution = { state: "resolving" };
|
|
12904
12907
|
|
|
@@ -13099,7 +13102,7 @@ const assertLazyReferencesAreGuarded = (type: RuntimeTypeNode): void => {
|
|
|
13099
13102
|
*
|
|
13100
13103
|
* assertOk(result);
|
|
13101
13104
|
* assertSame(result.value, value);
|
|
13102
|
-
* assertType<
|
|
13105
|
+
* assertType<typeof result.value, Data>();
|
|
13103
13106
|
* ```
|
|
13104
13107
|
*
|
|
13105
13108
|
* @group Base
|
|
@@ -13143,8 +13146,8 @@ export type Data =
|
|
|
13143
13146
|
* readonly run: () => void;
|
|
13144
13147
|
* }
|
|
13145
13148
|
*
|
|
13146
|
-
* assertType<
|
|
13147
|
-
* assertType<
|
|
13149
|
+
* assertType<IsData<User>, true>();
|
|
13150
|
+
* assertType<IsData<Service>, false>();
|
|
13148
13151
|
* ```
|
|
13149
13152
|
*
|
|
13150
13153
|
* @group Base
|
|
@@ -14190,7 +14193,7 @@ const stringifyJsonValue = (value: JsonValue): Json => {
|
|
|
14190
14193
|
* const result = JsonValue.fromUnknown(input);
|
|
14191
14194
|
*
|
|
14192
14195
|
* assertOk(result, input);
|
|
14193
|
-
* assertType<
|
|
14196
|
+
* assertType<typeof result.value, JsonValue>();
|
|
14194
14197
|
* ```
|
|
14195
14198
|
*
|
|
14196
14199
|
* @group JSON
|
|
@@ -14349,8 +14352,8 @@ export const JsonValueFromJson = /*#__PURE__*/ transform(
|
|
|
14349
14352
|
* const userJson = userToUserJson(user);
|
|
14350
14353
|
*
|
|
14351
14354
|
* assertType<
|
|
14352
|
-
*
|
|
14353
|
-
*
|
|
14355
|
+
* typeof userJson,
|
|
14356
|
+
* string & Brand<"Json"> & Brand<"UserJson">
|
|
14354
14357
|
* >();
|
|
14355
14358
|
* assertEqual(userJson, '{"name":"Ada","age":37}');
|
|
14356
14359
|
* assertEqual(UserJson.orThrow(userJson), userJson);
|
|
@@ -14442,7 +14445,7 @@ export const json = <T extends ConcreteTypeNode, Name extends TypeName>(
|
|
|
14442
14445
|
const result = jsonStringToBrandedJson(value, options);
|
|
14443
14446
|
|
|
14444
14447
|
if (!result.ok && result.error.type === "Json") {
|
|
14445
|
-
|
|
14448
|
+
assert(false, "Expected Json.", { cause: result.error });
|
|
14446
14449
|
}
|
|
14447
14450
|
return result;
|
|
14448
14451
|
};
|