@evolu/common 7.4.0 → 8.0.0-next.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.
Files changed (251) hide show
  1. package/README.md +4 -61
  2. package/dist/src/Array.d.ts +343 -102
  3. package/dist/src/Array.d.ts.map +1 -1
  4. package/dist/src/Array.js +181 -85
  5. package/dist/src/Assert.d.ts +57 -11
  6. package/dist/src/Assert.d.ts.map +1 -1
  7. package/dist/src/Assert.js +47 -11
  8. package/dist/src/BigInt.d.ts +6 -1
  9. package/dist/src/BigInt.d.ts.map +1 -1
  10. package/dist/src/BigInt.js +5 -0
  11. package/dist/src/Brand.d.ts +40 -12
  12. package/dist/src/Brand.d.ts.map +1 -1
  13. package/dist/src/Brand.js +5 -0
  14. package/dist/src/Buffer.d.ts +6 -1
  15. package/dist/src/Buffer.d.ts.map +1 -1
  16. package/dist/src/Buffer.js +7 -2
  17. package/dist/src/Cache.d.ts +10 -2
  18. package/dist/src/Cache.d.ts.map +1 -1
  19. package/dist/src/Cache.js +6 -0
  20. package/dist/src/Callbacks.d.ts +10 -7
  21. package/dist/src/Callbacks.d.ts.map +1 -1
  22. package/dist/src/Callbacks.js +23 -13
  23. package/dist/src/Console.d.ts +361 -69
  24. package/dist/src/Console.d.ts.map +1 -1
  25. package/dist/src/Console.js +217 -117
  26. package/dist/src/Crypto.d.ts +70 -21
  27. package/dist/src/Crypto.d.ts.map +1 -1
  28. package/dist/src/Crypto.js +72 -27
  29. package/dist/src/Eq.d.ts +22 -2
  30. package/dist/src/Eq.d.ts.map +1 -1
  31. package/dist/src/Eq.js +21 -1
  32. package/dist/src/Error.d.ts +23 -12
  33. package/dist/src/Error.d.ts.map +1 -1
  34. package/dist/src/Error.js +27 -11
  35. package/dist/src/Function.d.ts +128 -56
  36. package/dist/src/Function.d.ts.map +1 -1
  37. package/dist/src/Function.js +118 -14
  38. package/dist/src/Identicon.d.ts +5 -0
  39. package/dist/src/Identicon.d.ts.map +1 -1
  40. package/dist/src/Identicon.js +6 -1
  41. package/dist/src/Lookup.d.ts +160 -0
  42. package/dist/src/Lookup.d.ts.map +1 -0
  43. package/dist/src/Lookup.js +192 -0
  44. package/dist/src/Microtask.d.ts +21 -0
  45. package/dist/src/Microtask.d.ts.map +1 -0
  46. package/dist/src/Microtask.js +37 -0
  47. package/dist/src/Number.d.ts +18 -4
  48. package/dist/src/Number.d.ts.map +1 -1
  49. package/dist/src/Number.js +23 -1
  50. package/dist/src/Object.d.ts +110 -5
  51. package/dist/src/Object.d.ts.map +1 -1
  52. package/dist/src/Object.js +108 -5
  53. package/dist/src/Option.d.ts +58 -0
  54. package/dist/src/Option.d.ts.map +1 -0
  55. package/dist/src/Option.js +43 -0
  56. package/dist/src/Order.d.ts +5 -0
  57. package/dist/src/Order.d.ts.map +1 -1
  58. package/dist/src/Order.js +8 -3
  59. package/dist/src/Platform.d.ts +36 -2
  60. package/dist/src/Platform.d.ts.map +1 -1
  61. package/dist/src/Platform.js +10 -6
  62. package/dist/src/Polyfills.d.ts +27 -0
  63. package/dist/src/Polyfills.d.ts.map +1 -0
  64. package/dist/src/Polyfills.js +299 -0
  65. package/dist/src/Random.d.ts +18 -7
  66. package/dist/src/Random.d.ts.map +1 -1
  67. package/dist/src/Random.js +9 -7
  68. package/dist/src/Redacted.d.ts +7 -4
  69. package/dist/src/Redacted.d.ts.map +1 -1
  70. package/dist/src/Redacted.js +5 -0
  71. package/dist/src/Ref.d.ts +31 -16
  72. package/dist/src/Ref.d.ts.map +1 -1
  73. package/dist/src/Ref.js +35 -7
  74. package/dist/src/RefCount.d.ts +62 -0
  75. package/dist/src/RefCount.d.ts.map +1 -0
  76. package/dist/src/RefCount.js +83 -0
  77. package/dist/src/Relation.d.ts +84 -29
  78. package/dist/src/Relation.d.ts.map +1 -1
  79. package/dist/src/Relation.js +83 -105
  80. package/dist/src/Resource.d.ts +263 -0
  81. package/dist/src/Resource.d.ts.map +1 -0
  82. package/dist/src/Resource.js +389 -0
  83. package/dist/src/Result.d.ts +390 -374
  84. package/dist/src/Result.d.ts.map +1 -1
  85. package/dist/src/Result.js +142 -70
  86. package/dist/src/Schedule.d.ts +953 -0
  87. package/dist/src/Schedule.d.ts.map +1 -0
  88. package/dist/src/Schedule.js +1199 -0
  89. package/dist/src/Set.d.ts +181 -0
  90. package/dist/src/Set.d.ts.map +1 -0
  91. package/dist/src/Set.js +137 -0
  92. package/dist/src/Skiplist.d.ts +6 -1
  93. package/dist/src/Skiplist.d.ts.map +1 -1
  94. package/dist/src/Skiplist.js +5 -0
  95. package/dist/src/Sqlite.d.ts +160 -60
  96. package/dist/src/Sqlite.d.ts.map +1 -1
  97. package/dist/src/Sqlite.js +290 -190
  98. package/dist/src/Store.d.ts +36 -28
  99. package/dist/src/Store.d.ts.map +1 -1
  100. package/dist/src/Store.js +55 -15
  101. package/dist/src/String.d.ts +5 -0
  102. package/dist/src/String.d.ts.map +1 -1
  103. package/dist/src/String.js +5 -0
  104. package/dist/src/Task.d.ts +2263 -423
  105. package/dist/src/Task.d.ts.map +1 -1
  106. package/dist/src/Task.js +1488 -348
  107. package/dist/src/Test.d.ts +122 -0
  108. package/dist/src/Test.d.ts.map +1 -0
  109. package/dist/src/Test.js +66 -0
  110. package/dist/src/Time.d.ts +201 -48
  111. package/dist/src/Time.d.ts.map +1 -1
  112. package/dist/src/Time.js +190 -86
  113. package/dist/src/Tracer.d.ts +48 -0
  114. package/dist/src/Tracer.d.ts.map +1 -0
  115. package/dist/src/Tracer.js +6 -0
  116. package/dist/src/Type.d.ts +582 -209
  117. package/dist/src/Type.d.ts.map +1 -1
  118. package/dist/src/Type.js +362 -240
  119. package/dist/src/Types.d.ts +160 -6
  120. package/dist/src/Types.d.ts.map +1 -1
  121. package/dist/src/Types.js +22 -2
  122. package/dist/src/WebSocket.d.ts +113 -58
  123. package/dist/src/WebSocket.d.ts.map +1 -1
  124. package/dist/src/WebSocket.js +210 -118
  125. package/dist/src/Worker.d.ts +245 -60
  126. package/dist/src/Worker.d.ts.map +1 -1
  127. package/dist/src/Worker.js +220 -64
  128. package/dist/src/index.d.ts +25 -3
  129. package/dist/src/index.d.ts.map +1 -1
  130. package/dist/src/index.js +19 -3
  131. package/dist/src/local-first/Db.d.ts +24 -213
  132. package/dist/src/local-first/Db.d.ts.map +1 -1
  133. package/dist/src/local-first/Db.js +622 -293
  134. package/dist/src/local-first/Error.d.ts +12 -0
  135. package/dist/src/local-first/Error.d.ts.map +1 -0
  136. package/dist/src/local-first/Error.js +6 -0
  137. package/dist/src/local-first/Evolu.d.ts +330 -285
  138. package/dist/src/local-first/Evolu.d.ts.map +1 -1
  139. package/dist/src/local-first/Evolu.js +472 -402
  140. package/dist/src/local-first/LocalAuth.d.ts +10 -10
  141. package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
  142. package/dist/src/local-first/LocalAuth.js +6 -1
  143. package/dist/src/local-first/Owner.d.ts +70 -27
  144. package/dist/src/local-first/Owner.d.ts.map +1 -1
  145. package/dist/src/local-first/Owner.js +27 -14
  146. package/dist/src/local-first/Protocol.d.ts +58 -50
  147. package/dist/src/local-first/Protocol.d.ts.map +1 -1
  148. package/dist/src/local-first/Protocol.js +253 -155
  149. package/dist/src/local-first/Query.d.ts +133 -43
  150. package/dist/src/local-first/Query.d.ts.map +1 -1
  151. package/dist/src/local-first/Query.js +139 -90
  152. package/dist/src/local-first/Relay.d.ts +18 -38
  153. package/dist/src/local-first/Relay.d.ts.map +1 -1
  154. package/dist/src/local-first/Relay.js +59 -171
  155. package/dist/src/local-first/Schema.d.ts +139 -144
  156. package/dist/src/local-first/Schema.d.ts.map +1 -1
  157. package/dist/src/local-first/Schema.js +78 -163
  158. package/dist/src/local-first/Shared.d.ts +125 -0
  159. package/dist/src/local-first/Shared.d.ts.map +1 -0
  160. package/dist/src/local-first/Shared.js +569 -0
  161. package/dist/src/local-first/Storage.d.ts +50 -53
  162. package/dist/src/local-first/Storage.d.ts.map +1 -1
  163. package/dist/src/local-first/Storage.js +121 -173
  164. package/dist/src/local-first/Timestamp.d.ts +28 -35
  165. package/dist/src/local-first/Timestamp.d.ts.map +1 -1
  166. package/dist/src/local-first/Timestamp.js +24 -25
  167. package/dist/src/local-first/index.d.ts +2 -15
  168. package/dist/src/local-first/index.d.ts.map +1 -1
  169. package/dist/src/local-first/index.js +2 -15
  170. package/package.json +36 -26
  171. package/src/Array.ts +467 -106
  172. package/src/Assert.ts +87 -12
  173. package/src/BigInt.ts +7 -1
  174. package/src/Brand.ts +41 -12
  175. package/src/Buffer.ts +10 -4
  176. package/src/Cache.ts +11 -2
  177. package/src/Callbacks.ts +33 -23
  178. package/src/Console.ts +567 -178
  179. package/src/Crypto.ts +111 -62
  180. package/src/Eq.ts +30 -3
  181. package/src/Error.ts +50 -34
  182. package/src/Function.ts +140 -68
  183. package/src/Identicon.ts +7 -1
  184. package/src/Lookup.ts +415 -0
  185. package/src/Microtask.ts +58 -0
  186. package/src/Number.ts +40 -7
  187. package/src/Object.ts +155 -16
  188. package/src/Option.ts +74 -0
  189. package/src/Order.ts +11 -3
  190. package/src/Platform.ts +43 -7
  191. package/src/Polyfills.ts +465 -0
  192. package/src/Random.ts +25 -11
  193. package/src/Redacted.ts +8 -4
  194. package/src/Ref.ts +72 -21
  195. package/src/RefCount.ts +170 -0
  196. package/src/Relation.ts +188 -136
  197. package/src/Resource.ts +864 -0
  198. package/src/Result.ts +548 -381
  199. package/src/Schedule.ts +1471 -0
  200. package/src/Set.ts +247 -0
  201. package/src/Skiplist.ts +7 -1
  202. package/src/Sqlite.ts +409 -304
  203. package/src/Store.ts +94 -48
  204. package/src/String.ts +6 -0
  205. package/src/Task.ts +3685 -740
  206. package/src/Test.ts +162 -0
  207. package/src/Time.ts +348 -145
  208. package/src/Tracer.ts +54 -0
  209. package/src/Type.ts +1064 -630
  210. package/src/Types.ts +202 -7
  211. package/src/WebSocket.ts +311 -178
  212. package/src/Worker.ts +527 -147
  213. package/src/index.ts +74 -3
  214. package/src/local-first/Db.ts +871 -597
  215. package/src/local-first/Error.ts +17 -0
  216. package/src/local-first/Evolu.ts +884 -823
  217. package/src/local-first/LocalAuth.ts +10 -10
  218. package/src/local-first/Owner.ts +94 -42
  219. package/src/local-first/Protocol.ts +440 -303
  220. package/src/local-first/Query.ts +243 -194
  221. package/src/local-first/Relay.ts +91 -252
  222. package/src/local-first/Schema.ts +284 -394
  223. package/src/local-first/Shared.ts +932 -0
  224. package/src/local-first/Storage.ts +209 -282
  225. package/src/local-first/Timestamp.ts +38 -45
  226. package/src/local-first/index.ts +2 -16
  227. package/LICENSE +0 -21
  228. package/dist/src/Instances.d.ts +0 -34
  229. package/dist/src/Instances.d.ts.map +0 -1
  230. package/dist/src/Instances.js +0 -44
  231. package/dist/src/Resources.d.ts +0 -118
  232. package/dist/src/Resources.d.ts.map +0 -1
  233. package/dist/src/Resources.js +0 -197
  234. package/dist/src/local-first/Platform.d.ts +0 -25
  235. package/dist/src/local-first/Platform.d.ts.map +0 -1
  236. package/dist/src/local-first/Platform.js +0 -1
  237. package/dist/src/local-first/Public.d.ts +0 -22
  238. package/dist/src/local-first/Public.d.ts.map +0 -1
  239. package/dist/src/local-first/Public.js +0 -15
  240. package/dist/src/local-first/PublicKysely.d.ts +0 -148
  241. package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
  242. package/dist/src/local-first/PublicKysely.js +0 -184
  243. package/dist/src/local-first/Sync.d.ts +0 -112
  244. package/dist/src/local-first/Sync.d.ts.map +0 -1
  245. package/dist/src/local-first/Sync.js +0 -529
  246. package/src/Instances.ts +0 -90
  247. package/src/Resources.ts +0 -367
  248. package/src/local-first/Platform.ts +0 -27
  249. package/src/local-first/Public.ts +0 -42
  250. package/src/local-first/PublicKysely.ts +0 -239
  251. package/src/local-first/Sync.ts +0 -960
@@ -1,14 +1,24 @@
1
+ /**
2
+ * Runtime type validation, parsing, and branded types.
3
+ *
4
+ * @module
5
+ */
1
6
  import type { Brand } from "./Brand.js";
2
7
  import type { RandomBytesDep } from "./Crypto.js";
3
- import { Result } from "./Result.js";
8
+ import type { Result } from "./Result.js";
4
9
  import type { TimeDep } from "./Time.js";
5
10
  import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
6
11
  /**
7
12
  * Evolu {@link Type} is like a type guard that returns typed errors (via
8
- * {@link Result}) instead of throwing. We either get a safely typed value or a
9
- * composable typed error telling us exactly why validation failed.
13
+ * {@link Result}) instead of throwing. We either receive a safely typed value or
14
+ * a composable typed error that tells us exactly why the validation failed.
10
15
  *
11
- * Why another validation library?
16
+ * The reason why Evolu Type exists is that no other TypeScript validation
17
+ * library met Evolu's requirements. A distinctive feature of Evolu Type
18
+ * compared to other validation libraries is that it returns typed errors rather
19
+ * than string messages. This allows TypeScript to enforce that all validation
20
+ * errors are handled via {@link exhaustiveCheck}, significantly improving the
21
+ * developer experience. Those requirements are:
12
22
  *
13
23
  * - **Result-based error handling** – no exceptions for normal control flow.
14
24
  * - **Typed errors with decoupled formatters** – validation logic ≠ user
@@ -21,15 +31,10 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
21
31
  * bottom.
22
32
  * - **No user-land chaining DSL** – prepared for TC39 Hack pipes.
23
33
  *
24
- * A distinctive feature of Evolu Type compared to other validation libraries is
25
- * that it returns typed errors rather than string messages. This allows
26
- * TypeScript to enforce that all validation errors are handled by type
27
- * checking, significantly improving the developer experience.
28
- *
29
34
  * Evolu Type supports [Standard Schema](https://standardschema.dev/) for
30
35
  * interoperability with 40+ validation-compatible tools and frameworks.
31
36
  *
32
- * ### Base Types Quick Start
37
+ * ## Base Types
33
38
  *
34
39
  * ```ts
35
40
  * // Validate unknown values
@@ -37,7 +42,7 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
37
42
  * const stringResult = String.fromUnknown(value);
38
43
  * if (!stringResult.ok) {
39
44
  * // console.error(formatStringError(stringResult.error));
40
- * return stringResult; // inside a function returning Result<string, _>
45
+ * return stringResult;
41
46
  * }
42
47
  * // Safe branch: value is now string
43
48
  * const upper = stringResult.value.toUpperCase();
@@ -56,10 +61,12 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
56
61
  * Point.from({ x: 1, y: "2" }); // err -> nested Number error
57
62
  * ```
58
63
  *
59
- * ### Branding Basics
64
+ * ## Branded types
60
65
  *
61
- * Branding adds semantic meaning & constraints while preserving the runtime
62
- * shape:
66
+ * Branding is the recommended way to define types in Evolu. Instead of using
67
+ * primitive types like `string` or `number` directly, wrap them with
68
+ * {@link brand} to create semantically meaningful types. See {@link Brand} for
69
+ * why this matters.
63
70
  *
64
71
  * ```ts
65
72
  * const CurrencyCode = brand("CurrencyCode", String, (value) =>
@@ -83,20 +90,25 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
83
90
  * See also reusable brand factories like `minLength`, `maxLength`, `trimmed`,
84
91
  * `positive`, `between`, etc.
85
92
  *
86
- * ### Objects & Optional Fields
93
+ * ## Object types
87
94
  *
88
95
  * ```ts
89
96
  * const User = object({
90
97
  * name: NonEmptyTrimmedString100,
91
98
  * age: optional(PositiveInt),
92
99
  * });
93
- * type User = typeof User.Type;
100
+ *
101
+ * // Use interface for objects. TypeScript displays the interface name
102
+ * // instead of expanding all properties.
103
+ * interface User extends InferType<typeof User> {}
94
104
  *
95
105
  * User.from({ name: "Alice" }); // ok
96
106
  * User.from({ name: "Alice", age: -1 }); // err(PositiveInt)
107
+ *
108
+ * // TODO: Add `record`
97
109
  * ```
98
110
  *
99
- * ### Deriving JSON String Types
111
+ * ## JSON type
100
112
  *
101
113
  * ```ts
102
114
  * const Person = object({
@@ -105,7 +117,7 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
105
117
  * // To prevent this, use FiniteNumber.
106
118
  * age: FiniteNumber,
107
119
  * });
108
- * type Person = typeof Person.Type;
120
+ * interface Person extends InferType<typeof Person> {}
109
121
  *
110
122
  * const [PersonJson, personToPersonJson, personJsonToPerson] = json(
111
123
  * Person,
@@ -123,7 +135,7 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
123
135
  * expect(personJsonToPerson(personJson)).toEqual(person);
124
136
  * ```
125
137
  *
126
- * ### Error Formatting
138
+ * ## Error Formatting
127
139
  *
128
140
  * Evolu separates validation logic from human-readable messages. There are two
129
141
  * layers:
@@ -134,14 +146,14 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
134
146
  * custom errors (including nested composite types) and lets us override
135
147
  * selected messages.
136
148
  *
137
- * #### 1. Per-Type Formatter (recap)
149
+ * ### 1. Per-Type formatter
138
150
  *
139
151
  * ```ts
140
152
  * const r = String.fromUnknown(42);
141
153
  * if (!r.ok) console.error(formatStringError(r.error));
142
154
  * ```
143
155
  *
144
- * #### 2. Unified Formatter with Overrides
156
+ * ### 2. Unified formatter with overrides
145
157
  *
146
158
  * ```ts
147
159
  * // Override only what we care about; fall back to built-ins for the rest.
@@ -164,12 +176,14 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
164
176
  * tuple / union) and applies overrides only where specified, greatly reducing
165
177
  * boilerplate when formatting complex validation errors.
166
178
  *
167
- * ### Tip
179
+ * ## Naming
168
180
  *
169
- * If necessary, write `globalThis.String` instead of `String` to avoid naming
170
- * clashes with native types.
181
+ * Evolu Types intentionally use the same names as native JavaScript types
182
+ * (String, Number, Boolean, etc.). When you need to distinguish between an
183
+ * Evolu Type and the native type, use `globalThis` to reference the native one
184
+ * (e.g., `globalThis.String`, `globalThis.Number`).
171
185
  *
172
- * ### Design Decision: No Bidirectional Transformations
186
+ * ## Design decision
173
187
  *
174
188
  * Evolu Type intentionally does not support bidirectional transformations. It
175
189
  * previously did, but supporting that while keeping typed error fidelity added
@@ -178,28 +192,62 @@ import type { Literal, Refinement, Simplify, WidenLiteral } from "./Types.js";
178
192
  * reverse transforms would not buy much. We may revisit this if we can design a
179
193
  * minimal, 100% safe API that preserves simplicity.
180
194
  *
181
- * ### Prepared for TC39 Hack Pipes
195
+ * ## Composition without pipe
182
196
  *
183
197
  * Take a look how `SimplePassword` is defined:
184
198
  *
185
199
  * ```ts
186
- * export const SimplePassword = brand(
200
+ * const SimplePassword = brand(
187
201
  * "SimplePassword",
188
202
  * minLength(8)(maxLength(64)(TrimmedString)),
189
203
  * );
190
204
  * ```
191
205
  *
192
- * Nested functions are often OK (if not, make a helper) and read well, but with
193
- * TC39 Hack pipes it would be clearer:
206
+ * Shallow nesting often fits one line. If it doesn't, split into named parts:
194
207
  *
195
208
  * ```ts
196
- * // TrimmedString
197
- * // |> minLength(8)(%)
198
- * // |> maxLength(64)(%)
199
- * // |> brand("SimplePassword", %)
209
+ * const Min8TrimmedString64 = minLength(8)(maxLength(64)(TrimmedString));
210
+ * const SimplePassword = brand("SimplePassword", Min8TrimmedString64);
200
211
  * ```
201
212
  *
202
- * Note `minLength` and `maxLength` are curried because they are factories.
213
+ * ## FAQ
214
+ *
215
+ * ### How do I create a generic interface like `FooState<T>`?
216
+ *
217
+ * TypeScript's {@link InferType} extracts a concrete type, not a generic one. We
218
+ * cannot write `interface FooState<T> extends InferType<typeof fooState<T>>`
219
+ * because `InferType` needs a concrete Type instance.
220
+ *
221
+ * The recommended approach is to define the generic interface manually, then
222
+ * create a Type factory that produces structurally compatible Types:
223
+ *
224
+ * ```ts
225
+ * // Define the generic interface manually
226
+ * interface FooState<T> {
227
+ * readonly value: T;
228
+ * readonly loading: boolean;
229
+ * }
230
+ *
231
+ * // Create a Type factory that produces Types matching the interface
232
+ * const fooState = <T extends AnyType>(valueType: T) =>
233
+ * object({
234
+ * value: valueType,
235
+ * loading: Boolean,
236
+ * });
237
+ *
238
+ * // Usage
239
+ * const StringFooState = fooState(String);
240
+ * type StringFooState = InferType<typeof StringFooState>;
241
+ *
242
+ * // The interface and inferred type are structurally compatible
243
+ * const state: FooState<string> = StringFooState.orThrow({
244
+ * value: "hi",
245
+ * loading: false,
246
+ * });
247
+ * ```
248
+ *
249
+ * This keeps the interface generic while having type-safe runtime validation
250
+ * for each concrete use.
203
251
  */
204
252
  export interface Type<Name extends TypeName,
205
253
  /** The type this Type resolves to. */
@@ -224,6 +272,9 @@ ParentError extends TypeError = Error> extends StandardSchemaV1<Input, T> {
224
272
  /**
225
273
  * Creates `T` from an `Input` value, throwing an error if validation fails.
226
274
  *
275
+ * Use this where failure should crash the current flow instead of being
276
+ * handled locally.
277
+ *
227
278
  * Throws an Error with the Type validation error in its `cause` property,
228
279
  * making it debuggable while avoiding the need for custom error messages.
229
280
  *
@@ -231,36 +282,41 @@ ParentError extends TypeError = Error> extends StandardSchemaV1<Input, T> {
231
282
  *
232
283
  * **When to use:**
233
284
  *
234
- * - Configuration values that are guaranteed to be valid (e.g., hardcoded
235
- * constants)
236
- * - Application startup where failure should crash the program
285
+ * - Application startup or composition-root setup where errors must stop the
286
+ * program immediately. In Evolu apps, errors are handled by
287
+ * platform-specific `createRun` adapters at the app boundary.
288
+ * - Module-level constants
289
+ * - Test setup with values that are expected to be valid
237
290
  * - As an alternative to assertions when the Type error in the thrown Error's
238
291
  * `cause` provides sufficient debugging information
239
- * - Test code with known valid inputs (when error message clarity is not
240
- * critical; for better test error messages, use Vitest `schemaMatching` +
241
- * `assert` with `.is()`)
292
+ *
293
+ * Prefer `from` in ordinary application logic where the caller can recover,
294
+ * show validation errors, or choose a different flow.
295
+ *
296
+ * For clearer test failure messages on invalid input, use Vitest
297
+ * `schemaMatching` + `assert` with `.is()`.
242
298
  *
243
299
  * ### Example
244
300
  *
245
301
  * ```ts
246
- * // Good: Known valid constant
302
+ * // Good: Known valid constant
247
303
  * const maxRetries = PositiveInt.orThrow(3);
248
304
  *
249
- * // Good: App configuration that should crash on invalid values
250
- * const appName = SimpleName.orThrow("MyApp");
305
+ * // Good: App configuration that should crash on invalid values
306
+ * const appName = Name.orThrow("MyApp");
251
307
  *
252
- * // Good: Instead of assert when Type error is clear enough
308
+ * // Good: Instead of assert when Type error is clear enough
253
309
  * // Context makes it obvious: count increments from non-negative value
254
310
  * const currentCount = counts.get(id) ?? 0;
255
311
  * const newCount = PositiveInt.orThrow(currentCount + 1);
256
312
  *
257
- * // Good: Test setup with known valid values
313
+ * // Good: Test setup with known valid values
258
314
  * const testUser = User.orThrow({ name: "Alice", age: 30 });
259
315
  *
260
- * // Avoid: User input (use `from` instead)
316
+ * // Avoid: User input (use `from` instead)
261
317
  * const userAge = PositiveInt.orThrow(userInput); // Could crash!
262
318
  *
263
- * // Better: Handle user input gracefully
319
+ * // Better: Handle user input gracefully
264
320
  * const ageResult = PositiveInt.from(userInput);
265
321
  * if (!ageResult.ok) {
266
322
  * // Handle validation error
@@ -281,16 +337,16 @@ ParentError extends TypeError = Error> extends StandardSchemaV1<Input, T> {
281
337
  * ### Example
282
338
  *
283
339
  * ```ts
284
- * // Good: Optional user input
340
+ * // Good: Optional user input
285
341
  * const age = PositiveInt.orNull(userInput);
286
342
  * if (age != null) {
287
343
  * console.log("Valid age:", age);
288
344
  * }
289
345
  *
290
- * // Good: Default fallback
346
+ * // Good: Default fallback
291
347
  * const maxRetries = PositiveInt.orNull(config.retries) ?? 3;
292
348
  *
293
- * // Avoid: When you need to know why validation failed (use `from` instead)
349
+ * // Avoid: When you need to know why validation failed (use `from` instead)
294
350
  * const result = PositiveInt.from(userInput);
295
351
  * if (!result.ok) {
296
352
  * console.error(formatPositiveError(result.error));
@@ -394,7 +450,7 @@ ParentError extends TypeError = Error> extends StandardSchemaV1<Input, T> {
394
450
  /**
395
451
  * Unique identifier for a {@link Type}.
396
452
  *
397
- * @category Utilities
453
+ * @group Utilities
398
454
  */
399
455
  export type TypeName = Capitalize<string>;
400
456
  export interface TypeError<Name extends TypeName = TypeName> {
@@ -413,54 +469,72 @@ export interface TypeErrorWithReason<Name extends TypeName = TypeName, Reason ex
413
469
  /** The detailed reason for the error, represented as a tagged union. */
414
470
  readonly reason: Reason;
415
471
  }
472
+ /**
473
+ * A {@link Type} with all type parameters set to `any`.
474
+ *
475
+ * @group Utilities
476
+ */
416
477
  export type AnyType = Type<any, any, any, any, any, any>;
417
478
  /**
418
479
  * Extracts the name from a {@link Type}.
419
480
  *
420
- * @category Utilities
481
+ * @group Utilities
421
482
  */
422
483
  export type InferName<A extends AnyType> = A extends Type<infer Name, any, any, any, any, any> ? Name : never;
423
484
  /**
424
485
  * Extracts the type from a {@link Type}.
425
486
  *
426
- * @category Utilities
487
+ * ### Example
488
+ *
489
+ * ```ts
490
+ * const User = object({
491
+ * name: NonEmptyTrimmedString100,
492
+ * age: optional(PositiveInt),
493
+ * });
494
+ *
495
+ * // Use interface for objects. TypeScript displays the interface name
496
+ * // instead of expanding all properties.
497
+ * interface User extends InferType<typeof User> {}
498
+ * ```
499
+ *
500
+ * @group Utilities
427
501
  */
428
502
  export type InferType<A extends AnyType> = A extends Type<any, infer T, any, any, any, any> ? T : never;
429
503
  /**
430
504
  * Extracts the input type from a {@link Type}.
431
505
  *
432
- * @category Utilities
506
+ * @group Utilities
433
507
  */
434
508
  export type InferInput<A extends AnyType> = A extends Type<any, any, infer Input, any, any, any> ? Input : never;
435
509
  /**
436
510
  * Extracts the specific error type from a {@link Type}.
437
511
  *
438
- * @category Utilities
512
+ * @group Utilities
439
513
  */
440
514
  export type InferError<A extends AnyType> = A extends Type<any, any, any, infer Error, any, any> ? Error : never;
441
515
  /**
442
516
  * Extracts the parent type from a {@link Type}.
443
517
  *
444
- * @category Utilities
518
+ * @group Utilities
445
519
  */
446
520
  export type InferParent<A extends AnyType> = A extends Type<any, any, any, any, infer Parent, any> ? Parent : never;
447
521
  /**
448
522
  * Extracts the parent error type from a {@link Type}.
449
523
  *
450
- * @category Utilities
524
+ * @group Utilities
451
525
  */
452
526
  export type InferParentError<A extends AnyType> = A extends Type<any, any, any, any, any, infer ParentError> ? ParentError : never;
453
527
  /**
454
528
  * Extracts all error types from a {@link Type}.
455
529
  *
456
- * @category Utilities
530
+ * @group Utilities
457
531
  */
458
532
  export type InferErrors<T extends AnyType> = T extends Type<any, any, any, infer Error, any, infer ParentError> ? Error | ParentError : never;
459
533
  declare const EvoluTypeSymbol: unique symbol;
460
534
  /**
461
535
  * Checks if the given value is an {@link Type}.
462
536
  *
463
- * @category Utilities
537
+ * @group Utilities
464
538
  */
465
539
  export declare const isType: (value: unknown) => value is AnyType;
466
540
  /**
@@ -477,7 +551,7 @@ export declare const isType: (value: unknown) => value is AnyType;
477
551
  * );
478
552
  * ```
479
553
  *
480
- * @category Utilities
554
+ * @group Utilities
481
555
  */
482
556
  export declare const createTypeErrorFormatter: <Error extends TypeError>(format: (error: Simplify<Omit<Error, "value"> & {
483
557
  value: string;
@@ -504,7 +578,7 @@ export type TypeErrorFormatter<Error extends TypeError> = (error: Error) => stri
504
578
  * );
505
579
  * ```
506
580
  *
507
- * @category Base Factories
581
+ * @group Base factories
508
582
  */
509
583
  export declare const base: <Name extends TypeName, T, Error extends TypeError>(name: Name, fromUnknown: (value: unknown) => Result<T, Error>) => Type<Name, T, T, Error>;
510
584
  /**
@@ -520,50 +594,50 @@ export declare const base: <Name extends TypeName, T, Error extends TypeError>(n
520
594
  * createBaseTypeErrorFormatter<StringError>();
521
595
  * ```
522
596
  *
523
- * @category Utilities
597
+ * @group Utilities
524
598
  */
525
599
  export declare const createBaseTypeErrorFormatter: <Error extends TypeError>() => TypeErrorFormatter<Error>;
526
- /** @category Base Types */
600
+ /** @group Base Types */
527
601
  export declare const Unknown: Type<"Unknown", unknown, unknown, never, unknown, never>;
528
602
  /**
529
- * @category Base Types
530
- * @category String
603
+ * @group Base Types
604
+ * @group String
531
605
  */
532
606
  export declare const String: Type<"String", string, string, StringError, string, StringError>;
533
607
  export interface StringError extends TypeError<"String"> {
534
608
  }
535
609
  export declare const formatStringError: TypeErrorFormatter<StringError>;
536
- /** @category Base Types */
610
+ /** @group Base Types */
537
611
  export declare const Number: Type<"Number", number, number, NumberError, number, NumberError>;
538
612
  export interface NumberError extends TypeError<"Number"> {
539
613
  }
540
614
  export declare const formatNumberError: TypeErrorFormatter<NumberError>;
541
- /** @category Base Types */
615
+ /** @group Base Types */
542
616
  export declare const BigInt: Type<"BigInt", bigint, bigint, BigIntError, bigint, BigIntError>;
543
617
  export interface BigIntError extends TypeError<"BigInt"> {
544
618
  }
545
619
  export declare const formatBigIntError: TypeErrorFormatter<BigIntError>;
546
- /** @category Base Types */
620
+ /** @group Base Types */
547
621
  export declare const Boolean: Type<"Boolean", boolean, boolean, BooleanError, boolean, BooleanError>;
548
622
  export interface BooleanError extends TypeError<"Boolean"> {
549
623
  }
550
624
  export declare const formatBooleanError: TypeErrorFormatter<BooleanError>;
551
- /** @category Base Types */
625
+ /** @group Base Types */
552
626
  export declare const Undefined: Type<"Undefined", undefined, undefined, UndefinedError, undefined, UndefinedError>;
553
627
  export interface UndefinedError extends TypeError<"Undefined"> {
554
628
  }
555
629
  export declare const formatUndefinedError: TypeErrorFormatter<UndefinedError>;
556
- /** @category Base Types */
630
+ /** @group Base Types */
557
631
  export declare const Null: Type<"Null", null, null, NullError, null, NullError>;
558
632
  export interface NullError extends TypeError<"Null"> {
559
633
  }
560
634
  export declare const formatNullError: TypeErrorFormatter<NullError>;
561
- /** @category Base Types */
635
+ /** @group Base Types */
562
636
  export declare const Function: Type<"Function", Function, Function, FunctionError, Function, FunctionError>;
563
637
  export interface FunctionError extends TypeError<"Function"> {
564
638
  }
565
639
  export declare const formatFunctionError: TypeErrorFormatter<FunctionError>;
566
- /** @category Base Types */
640
+ /** @group Base Types */
567
641
  export declare const Uint8Array: Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, Uint8ArrayError, Uint8Array<ArrayBufferLike>, Uint8ArrayError>;
568
642
  export interface Uint8ArrayError extends TypeError<"Uint8Array"> {
569
643
  }
@@ -586,7 +660,7 @@ export declare const formatUint8ArrayError: TypeErrorFormatter<Uint8ArrayError>;
586
660
  * const error = UserInstance.from({}); // err
587
661
  * ```
588
662
  *
589
- * @category Base Factories
663
+ * @group Base factories
590
664
  */
591
665
  export declare const instanceOf: <T extends abstract new (...args: any) => any>(ctor: T) => InstanceOfType<T>;
592
666
  export interface InstanceOfError extends TypeError<"InstanceOf"> {
@@ -599,7 +673,7 @@ export declare const formatInstanceOfError: TypeErrorFormatter<InstanceOfError>;
599
673
  /**
600
674
  * JavaScript Date.
601
675
  *
602
- * @category Base Types
676
+ * @group Base Types
603
677
  */
604
678
  export declare const Date: InstanceOfType<DateConstructor>;
605
679
  /**
@@ -620,12 +694,16 @@ export declare const formatIsTypeError: TypeErrorFormatter<EvoluTypeError>;
620
694
  /**
621
695
  * Branded {@link Type}.
622
696
  *
697
+ * Branding is the recommended way to define types in Evolu. Instead of using
698
+ * primitive types like `string` or `number` directly, wrap them with `brand` to
699
+ * create semantically meaningful types. See {@link Brand} for why this matters.
700
+ *
623
701
  * The `brand` Type Factory takes the name of a new {@link Brand}, a parent Type
624
702
  * to be branded, and the optional `refine` function for additional constraint.
625
703
  *
626
704
  * The `refine` function can be omitted if we only want to add a brand.
627
705
  *
628
- * ### Examples
706
+ * ### Example
629
707
  *
630
708
  * A simple `CurrencyCode` Type:
631
709
  *
@@ -744,9 +822,10 @@ export declare const formatIsTypeError: TypeErrorFormatter<EvoluTypeError>;
744
822
  * );
745
823
  * ```
746
824
  *
747
- * @category Base Factories
825
+ * @group Base factories
748
826
  */
749
827
  export declare function brand<Name extends TypeName, ParentType extends AnyType, Parent = InferType<ParentType>, RefineError extends TypeError = never>(name: Name, parent: ParentType, refine: (value: Parent) => Result<Parent, RefineError>): BrandType<ParentType, Name, RefineError, InferErrors<ParentType>>;
828
+ /** Without refine function. */
750
829
  export declare function brand<Name extends TypeName, ParentType extends AnyType>(name: Name, parent: ParentType): BrandType<ParentType, Name, BrandWithoutRefineError<Name, InferErrors<ParentType>>>;
751
830
  export interface BrandType<ParentType extends AnyType, Name extends TypeName, Error extends TypeError = never, ParentError extends TypeError = never> extends Type<"Brand", InferType<ParentType> & Brand<Name>, InferInput<ParentType>, Error, InferType<ParentType>, ParentError> {
752
831
  readonly brand: Name;
@@ -758,7 +837,7 @@ export interface BrandWithoutRefineError<Name extends TypeName, ParentError exte
758
837
  /**
759
838
  * A three-letter ISO 4217 currency code (e.g., USD, EUR).
760
839
  *
761
- * @category String
840
+ * @group String
762
841
  */
763
842
  export declare const CurrencyCode: BrandType<Type<"String", string, string, StringError, string, StringError>, "CurrencyCode", CurrencyCodeError, StringError>;
764
843
  export type CurrencyCode = typeof CurrencyCode.Type;
@@ -784,7 +863,7 @@ export declare const formatCurrencyCodeError: TypeErrorFormatter<CurrencyCodeErr
784
863
  * const error = DateIso.from("10000-01-01T00:00:00.000Z"); // err
785
864
  * ```
786
865
  *
787
- * @category String
866
+ * @group String
788
867
  */
789
868
  export declare const DateIso: BrandType<Type<"String", string, string, StringError, string, StringError>, "DateIso", DateIsoError, StringError>;
790
869
  export type DateIso = typeof DateIso.Type;
@@ -809,7 +888,18 @@ export declare const dateIsoToDate: (value: DateIso) => Date;
809
888
  * );
810
889
  * ```
811
890
  *
812
- * @category Utilities
891
+ * ### Numeric literal inference
892
+ *
893
+ * When using factories with numeric parameters (like `lessThan`, `maxLength`,
894
+ * `between`), use numeric literals instead of expressions. TypeScript widens
895
+ * expressions to `number`, losing the literal type in the brand name:
896
+ *
897
+ * ```ts
898
+ * lessThan(100)(Number); // Brand<"LessThan100"> ✓
899
+ * lessThan(100 - 1)(Number); // Brand<"LessThan" + number> ✗
900
+ * ```
901
+ *
902
+ * @group Utilities
813
903
  */
814
904
  export type BrandFactory<Name extends TypeName, Input, RefineError extends TypeError> = <PName extends TypeName, P extends Input, PInput, PParent, PError extends TypeError = never, PParentError extends TypeError = never>(parent: Type<PName, P, PInput, PError, PParent, PParentError>) => BrandType<Type<PName, P, PInput, PError, PParent, PParentError>, Name, RefineError, PError | PParentError>;
815
905
  /**
@@ -826,7 +916,7 @@ export type BrandFactory<Name extends TypeName, Input, RefineError extends TypeE
826
916
  * type TrimmedNonEmptyString = typeof TrimmedNonEmptyString.Type;
827
917
  * ```
828
918
  *
829
- * @category String
919
+ * @group String
830
920
  */
831
921
  export declare const trimmed: BrandFactory<"Trimmed", string, TrimmedError>;
832
922
  export interface TrimmedError extends TypeError<"Trimmed"> {
@@ -838,7 +928,7 @@ export declare const formatTrimmedError: TypeErrorFormatter<TrimmedError>;
838
928
  * - Use `TrimmedString.is` to check if an unknown value is trimmed.
839
929
  * - Use `TrimmedString.from` to check if a string is trimmed.
840
930
  *
841
- * @category String
931
+ * @group String
842
932
  */
843
933
  export declare const TrimmedString: BrandType<Type<"String", string, string, StringError, string, StringError>, "Trimmed", TrimmedError, StringError>;
844
934
  export type TrimmedString = typeof TrimmedString.Type;
@@ -846,6 +936,8 @@ export declare const trim: (value: string) => TrimmedString;
846
936
  /**
847
937
  * Minimum length.
848
938
  *
939
+ * Use numeric literal, not expression. See {@link BrandFactory}.
940
+ *
849
941
  * ### Example
850
942
  *
851
943
  * ```ts
@@ -853,8 +945,8 @@ export declare const trim: (value: string) => TrimmedString;
853
945
  * const NonEmptyString = minLength(1)(String);
854
946
  * ```
855
947
  *
856
- * @category String
857
- * @category Array
948
+ * @group String
949
+ * @group Array
858
950
  */
859
951
  export declare const minLength: <Min extends number>(min: Min) => BrandFactory<`MinLength${Min}`, {
860
952
  length: number;
@@ -866,6 +958,8 @@ export declare const formatMinLengthError: TypeErrorFormatter<MinLengthError<num
866
958
  /**
867
959
  * Maximum length.
868
960
  *
961
+ * Use numeric literal, not expression. See {@link BrandFactory}.
962
+ *
869
963
  * ### Example
870
964
  *
871
965
  * ```ts
@@ -873,8 +967,8 @@ export declare const formatMinLengthError: TypeErrorFormatter<MinLengthError<num
873
967
  * const String100 = maxLength(100)(String);
874
968
  * ```
875
969
  *
876
- * @category String
877
- * @category Array
970
+ * @group String
971
+ * @group Array
878
972
  */
879
973
  export declare const maxLength: <Max extends number>(max: Max) => BrandFactory<`MaxLength${Max}`, {
880
974
  length: number;
@@ -886,6 +980,8 @@ export declare const formatMaxLengthError: TypeErrorFormatter<MaxLengthError<num
886
980
  /**
887
981
  * Exact length.
888
982
  *
983
+ * Use numeric literal, not expression. See {@link BrandFactory}.
984
+ *
889
985
  * ### Example
890
986
  *
891
987
  * ```ts
@@ -893,8 +989,8 @@ export declare const formatMaxLengthError: TypeErrorFormatter<MaxLengthError<num
893
989
  * const Length1String = length(1)(String);
894
990
  * ```
895
991
  *
896
- * @category String
897
- * @category Array
992
+ * @group String
993
+ * @group Array
898
994
  */
899
995
  export declare const length: <Exact extends number>(exact: Exact) => BrandFactory<`Length${Exact}`, {
900
996
  length: number;
@@ -903,34 +999,34 @@ export interface LengthError<Exact extends number = number> extends TypeError<"L
903
999
  readonly exact: Exact;
904
1000
  }
905
1001
  export declare const formatLengthError: TypeErrorFormatter<LengthError<number>>;
906
- /** @category String */
1002
+ /** @group String */
907
1003
  export declare const NonEmptyString: BrandType<Type<"String", string, string, StringError, string, StringError>, "MinLength1", MinLengthError<1>, StringError>;
908
1004
  export type NonEmptyString = typeof NonEmptyString.Type;
909
- /** @category String */
1005
+ /** @group String */
910
1006
  export declare const String100: BrandType<Type<"String", string, string, StringError, string, StringError>, "MaxLength100", MaxLengthError<100>, StringError>;
911
1007
  export type String100 = typeof String100.Type;
912
- /** @category String */
1008
+ /** @group String */
913
1009
  export declare const String1000: BrandType<Type<"String", string, string, StringError, string, StringError>, "MaxLength1000", MaxLengthError<1000>, StringError>;
914
1010
  export type String1000 = typeof String1000.Type;
915
- /** @category String */
1011
+ /** @group String */
916
1012
  export declare const NonEmptyString100: BrandType<Type<"Brand", string & Brand<"MaxLength100">, string, MaxLengthError<100>, string, StringError>, "MinLength1", MinLengthError<1>, StringError | MaxLengthError<100>>;
917
1013
  export type NonEmptyString100 = typeof NonEmptyString100.Type;
918
- /** @category String */
1014
+ /** @group String */
919
1015
  export declare const NonEmptyString1000: BrandType<Type<"Brand", string & Brand<"MaxLength1000">, string, MaxLengthError<1000>, string, StringError>, "MinLength1", MinLengthError<1>, StringError | MaxLengthError<1000>>;
920
1016
  export type NonEmptyString1000 = typeof NonEmptyString1000.Type;
921
- /** @category String */
1017
+ /** @group String */
922
1018
  export declare const NonEmptyTrimmedString: BrandType<Type<"Brand", string & Brand<"Trimmed">, string, TrimmedError, string, StringError>, "MinLength1", MinLengthError<1>, StringError | TrimmedError>;
923
1019
  export type NonEmptyTrimmedString = typeof NonEmptyTrimmedString.Type;
924
- /** @category String */
1020
+ /** @group String */
925
1021
  export declare const TrimmedString100: BrandType<Type<"Brand", string & Brand<"Trimmed">, string, TrimmedError, string, StringError>, "MaxLength100", MaxLengthError<100>, StringError | TrimmedError>;
926
1022
  export type TrimmedString100 = typeof TrimmedString100.Type;
927
- /** @category String */
1023
+ /** @group String */
928
1024
  export declare const TrimmedString1000: BrandType<Type<"Brand", string & Brand<"Trimmed">, string, TrimmedError, string, StringError>, "MaxLength1000", MaxLengthError<1000>, StringError | TrimmedError>;
929
1025
  export type TrimmedString1000 = typeof TrimmedString1000.Type;
930
- /** @category String */
1026
+ /** @group String */
931
1027
  export declare const NonEmptyTrimmedString100: BrandType<Type<"Brand", string & Brand<"Trimmed"> & Brand<"MaxLength100">, string, MaxLengthError<100>, string & Brand<"Trimmed">, StringError | TrimmedError>, "MinLength1", MinLengthError<1>, StringError | TrimmedError | MaxLengthError<100>>;
932
1028
  export type NonEmptyTrimmedString100 = typeof NonEmptyTrimmedString100.Type;
933
- /** @category String */
1029
+ /** @group String */
934
1030
  export declare const NonEmptyTrimmedString1000: BrandType<Type<"Brand", string & Brand<"Trimmed"> & Brand<"MaxLength1000">, string, MaxLengthError<1000>, string & Brand<"Trimmed">, StringError | TrimmedError>, "MinLength1", MinLengthError<1>, StringError | TrimmedError | MaxLengthError<1000>>;
935
1031
  export type NonEmptyTrimmedString1000 = typeof NonEmptyTrimmedString1000.Type;
936
1032
  /**
@@ -940,7 +1036,7 @@ export type NonEmptyTrimmedString1000 = typeof NonEmptyTrimmedString1000.Type;
940
1036
  * safely on the user's device using cryptographically secure random number
941
1037
  * generation, ensuring it remains private and unique.
942
1038
  *
943
- * @category String
1039
+ * @group String
944
1040
  */
945
1041
  export declare const Mnemonic: BrandType<BrandType<Type<"Brand", string & Brand<"Trimmed">, string, TrimmedError, string, StringError>, "MinLength1", MinLengthError<1>, StringError | TrimmedError>, "Mnemonic", MnemonicError, StringError | TrimmedError | MinLengthError<1>>;
946
1042
  export type Mnemonic = typeof Mnemonic.Type;
@@ -956,7 +1052,7 @@ export declare const formatMnemonicError: TypeErrorFormatter<MnemonicError>;
956
1052
  * const Alphanumeric = regex("Alphanumeric", /^[a-z0-9]+$/i)(String);
957
1053
  * ```
958
1054
  *
959
- * @category String
1055
+ * @group String
960
1056
  */
961
1057
  export declare const regex: <Name extends TypeName>(name: Name, pattern: RegExp) => BrandFactory<Name, string, RegexError<Name>>;
962
1058
  export interface RegexError<Name extends TypeName = TypeName> extends TypeError<"Regex"> {
@@ -989,7 +1085,7 @@ export declare const formatRegexError: TypeErrorFormatter<RegexError<Capitalize<
989
1085
  * }
990
1086
  * ```
991
1087
  *
992
- * @category String
1088
+ * @group String
993
1089
  */
994
1090
  export declare const UrlSafeString: BrandType<Type<"String", string, string, StringError, string, StringError>, "UrlSafeString", RegexError<"UrlSafeString">, StringError>;
995
1091
  export type UrlSafeString = typeof UrlSafeString.Type;
@@ -1000,7 +1096,7 @@ export type UrlSafeStringError = typeof UrlSafeString.Error;
1000
1096
  * Encode with {@link uint8ArrayToBase64Url}, decode with
1001
1097
  * {@link base64UrlToUint8Array}.
1002
1098
  *
1003
- * @category String
1099
+ * @group String
1004
1100
  */
1005
1101
  export declare const Base64Url: BrandType<Type<"String", string, string, StringError, string, StringError>, "Base64Url", Base64UrlError, StringError>;
1006
1102
  export type Base64Url = typeof Base64Url.Type;
@@ -1012,30 +1108,31 @@ export declare const uint8ArrayToBase64Url: (bytes: Uint8Array) => Base64Url;
1012
1108
  /** Decodes a {@link Base64Url} string to a Uint8Array. */
1013
1109
  export declare const base64UrlToUint8Array: (str: Base64Url) => Uint8Array;
1014
1110
  /**
1015
- * Simple alphanumeric string for naming in file systems, URLs, and identifiers.
1111
+ * Alphanumeric string for naming in file systems, URLs, and identifiers.
1016
1112
  *
1017
1113
  * Uses the same safe alphabet as {@link UrlSafeString} (letters, digits, `-`,
1018
- * `_`). See `UrlSafeString` for details.
1114
+ * `_`).
1019
1115
  *
1020
1116
  * The string must be between 1 and 64 characters.
1021
1117
  *
1022
1118
  * ### Example
1023
1119
  *
1024
1120
  * ```ts
1025
- * const result = SimpleName.from("data-report-123");
1121
+ * const result = Name.from("data-report-123");
1026
1122
  * if (result.ok) {
1027
- * console.log("Valid SimpleName string:", result.value);
1123
+ * console.log("Valid Name string:", result.value);
1028
1124
  * } else {
1029
- * console.error("Invalid SimpleName string:", result.error);
1125
+ * console.error("Invalid Name string:", result.error);
1030
1126
  * }
1031
1127
  * ```
1032
1128
  *
1033
- * @category String
1129
+ * @group String
1034
1130
  */
1035
- export declare const SimpleName: BrandType<BrandType<Type<"String", string, string, StringError, string, StringError>, "UrlSafeString", RegexError<"UrlSafeString">, StringError>, "SimpleName", SimpleNameError, StringError | RegexError<"UrlSafeString">>;
1036
- export type SimpleName = typeof SimpleName.Type;
1037
- export interface SimpleNameError extends TypeError<"SimpleName"> {
1131
+ export declare const Name: BrandType<BrandType<Type<"String", string, string, StringError, string, StringError>, "UrlSafeString", RegexError<"UrlSafeString">, StringError>, "Name", NameError, StringError | RegexError<"UrlSafeString">>;
1132
+ export type Name = typeof Name.Type;
1133
+ export interface NameError extends TypeError<"Name"> {
1038
1134
  }
1135
+ export declare const testName: string & Brand<"UrlSafeString"> & Brand<"Name">;
1039
1136
  /**
1040
1137
  * Trimmed string between 8 and 64 characters, branded as `SimplePassword`.
1041
1138
  *
@@ -1058,7 +1155,7 @@ export interface SimpleNameError extends TypeError<"SimpleName"> {
1058
1155
  * // |> brand("SimplePassword", %)
1059
1156
  * ```
1060
1157
  *
1061
- * @category String
1158
+ * @group String
1062
1159
  */
1063
1160
  export declare const SimplePassword: BrandType<BrandType<Type<"Brand", string & Brand<"Trimmed"> & Brand<"MaxLength64">, string, MaxLengthError<64>, string & Brand<"Trimmed">, StringError | TrimmedError>, "MinLength8", MinLengthError<8>, StringError | TrimmedError | MaxLengthError<64>>, "SimplePassword", BrandWithoutRefineError<"SimplePassword", StringError | TrimmedError | MinLengthError<8> | MaxLengthError<64>>, never>;
1064
1161
  export type SimplePassword = typeof SimplePassword.Type;
@@ -1080,14 +1177,14 @@ export declare const formatSimplePasswordError: (formatTypeError: TypeErrorForma
1080
1177
  * copied (logs, URLs, exports); only use it when you explicitly want insertion
1081
1178
  * locality for very large write‑heavy tables and accept timestamp exposure.
1082
1179
  *
1083
- * ### Future
1180
+ * ## Future
1084
1181
  *
1085
1182
  * A possible hybrid masked‑time approach (`timestamp ^ H(cluster_id, timestamp
1086
1183
  *
1087
1184
  * > > N)`) could provide locality without exposing raw creation time. See
1088
1185
  * > > https://brooker.co.za/blog/2025/10/22/uuidv7.html
1089
1186
  *
1090
- * @category String
1187
+ * @group String
1091
1188
  */
1092
1189
  export declare const Id: BrandType<Type<"String", string, string, StringError, string, StringError>, "Id", IdError, StringError>;
1093
1190
  export type Id = typeof Id.Type;
@@ -1139,7 +1236,7 @@ export declare const createId: <B extends string = never>(deps: RandomBytesDep)
1139
1236
  * external string from the generated {@link Id}. If you need to preserve the
1140
1237
  * original external ID, store it in a separate column.
1141
1238
  *
1142
- * @category String
1239
+ * @group String
1143
1240
  */
1144
1241
  export declare const createIdFromString: <B extends string = never>(value: string) => [B] extends [never] ? Id : Id & Brand<B>;
1145
1242
  /**
@@ -1172,7 +1269,7 @@ export declare const createIdAsUuidv7: <B extends string = never>(deps: RandomBy
1172
1269
  * type TodoId = typeof TodoId.Type;
1173
1270
  * ```
1174
1271
  *
1175
- * @category String
1272
+ * @group String
1176
1273
  */
1177
1274
  export declare const id: <Table extends TypeName>(table: Table) => TableId<Table>;
1178
1275
  export interface TableId<Table extends TypeName> extends Type<"Id", string & Brand<"Id"> & Brand<Table>, string, TableIdError<Table>, string, StringError> {
@@ -1183,7 +1280,7 @@ export interface TableIdError<Table extends TypeName = TypeName> extends TypeErr
1183
1280
  }
1184
1281
  export declare const formatTableIdError: TypeErrorFormatter<TableIdError<Capitalize<string>>>;
1185
1282
  /** Binary representation of an {@link Id}. */
1186
- export declare const IdBytes: BrandType<BrandType<Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, Uint8ArrayError, Uint8Array<ArrayBufferLike>, Uint8ArrayError>, "Length16", LengthError<16>, Uint8ArrayError>, "IdBytes", BrandWithoutRefineError<"IdBytes", LengthError<16> | Uint8ArrayError>, never>;
1283
+ export declare const IdBytes: BrandType<BrandType<Type<"Uint8Array", Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>, Uint8ArrayError, Uint8Array<ArrayBufferLike>, Uint8ArrayError>, "Length16", LengthError<16>, Uint8ArrayError>, "IdBytes", BrandWithoutRefineError<"IdBytes", Uint8ArrayError | LengthError<16>>, never>;
1187
1284
  export type IdBytes = typeof IdBytes.Type;
1188
1285
  export declare const idBytesTypeValueLength: NonNegativeInt;
1189
1286
  export declare const idToIdBytes: (id: Id) => IdBytes;
@@ -1200,7 +1297,7 @@ export declare const idBytesToId: (idBytes: IdBytes) => Id;
1200
1297
  * const errorResult = PositiveNumber.from(-5); // err
1201
1298
  * ```
1202
1299
  *
1203
- * @category Number
1300
+ * @group Number
1204
1301
  */
1205
1302
  export declare const positive: BrandFactory<"Positive", number, PositiveError>;
1206
1303
  export interface PositiveError extends TypeError<"Positive"> {
@@ -1215,7 +1312,7 @@ export declare const formatPositiveError: TypeErrorFormatter<PositiveError>;
1215
1312
  * const NegativeNumber = negative(Number);
1216
1313
  * ```
1217
1314
  *
1218
- * @category Number
1315
+ * @group Number
1219
1316
  */
1220
1317
  export declare const negative: BrandFactory<"Negative", number, NegativeError>;
1221
1318
  export interface NegativeError extends TypeError<"Negative"> {
@@ -1230,7 +1327,7 @@ export declare const formatNegativeError: TypeErrorFormatter<NegativeError>;
1230
1327
  * const NonPositiveNumber = nonPositive(Number);
1231
1328
  * ```
1232
1329
  *
1233
- * @category Number
1330
+ * @group Number
1234
1331
  */
1235
1332
  export declare const nonPositive: BrandFactory<"NonPositive", number, NonPositiveError>;
1236
1333
  export interface NonPositiveError extends TypeError<"NonPositive"> {
@@ -1245,7 +1342,7 @@ export declare const formatNonPositiveError: TypeErrorFormatter<NonPositiveError
1245
1342
  * const NonNegativeNumber = nonNegative(Number);
1246
1343
  * ```
1247
1344
  *
1248
- * @category Number
1345
+ * @group Number
1249
1346
  */
1250
1347
  export declare const nonNegative: BrandFactory<"NonNegative", number, NonNegativeError>;
1251
1348
  export interface NonNegativeError extends TypeError<"NonNegative"> {
@@ -1254,87 +1351,81 @@ export declare const formatNonNegativeError: TypeErrorFormatter<NonNegativeError
1254
1351
  /**
1255
1352
  * Non-negative number (≥ 0).
1256
1353
  *
1257
- * @category Number
1354
+ * @group Number
1258
1355
  */
1259
1356
  export declare const NonNegativeNumber: BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "NonNegative", NonNegativeError, NumberError>;
1260
1357
  export type NonNegativeNumber = typeof NonNegativeNumber.Type;
1261
1358
  /**
1262
1359
  * Positive number (> 0).
1263
1360
  *
1264
- * @category Number
1361
+ * @group Number
1265
1362
  */
1266
- export declare const PositiveNumber: BrandType<Type<"Brand", number & Brand<"NonNegative">, number, NonNegativeError, number, NumberError>, "Positive", PositiveError, NonNegativeError | NumberError>;
1363
+ export declare const PositiveNumber: BrandType<Type<"Brand", number & Brand<"NonNegative">, number, NonNegativeError, number, NumberError>, "Positive", PositiveError, NumberError | NonNegativeError>;
1267
1364
  export type PositiveNumber = typeof PositiveNumber.Type;
1268
1365
  /**
1269
1366
  * Non-positive number (≤ 0).
1270
1367
  *
1271
- * @category Number
1368
+ * @group Number
1272
1369
  */
1273
1370
  export declare const NonPositiveNumber: BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "NonPositive", NonPositiveError, NumberError>;
1274
1371
  export type NonPositiveNumber = typeof NonPositiveNumber.Type;
1275
1372
  /**
1276
1373
  * Negative number (< 0).
1277
1374
  *
1278
- * @category Number
1375
+ * @group Number
1279
1376
  */
1280
1377
  export declare const NegativeNumber: BrandType<Type<"Brand", number & Brand<"NonPositive">, number, NonPositiveError, number, NumberError>, "Negative", NegativeError, NumberError | NonPositiveError>;
1281
1378
  export type NegativeNumber = typeof NegativeNumber.Type;
1282
- /**
1283
- * Integer within the safe range of JavaScript numbers.
1284
- *
1285
- * ### Example
1286
- *
1287
- * ```ts
1288
- * const Int = int(Number);
1289
- * ```
1290
- *
1291
- * @category Number
1292
- */
1293
- export declare const int: BrandFactory<"Int", number, IntError>;
1294
1379
  export interface IntError extends TypeError<"Int"> {
1295
1380
  }
1296
1381
  export declare const formatIntError: TypeErrorFormatter<IntError>;
1297
1382
  /**
1298
1383
  * Integer within the safe range of JavaScript numbers.
1299
1384
  *
1300
- * @category Number
1385
+ * @group Number
1301
1386
  */
1302
1387
  export declare const Int: BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "Int", IntError, NumberError>;
1303
1388
  export type Int = typeof Int.Type;
1304
1389
  /**
1305
1390
  * Non-negative integer (≥ 0).
1306
1391
  *
1307
- * @category Number
1392
+ * @group Number
1308
1393
  */
1309
- export declare const NonNegativeInt: BrandType<Type<"Brand", number & Brand<"Int">, number, IntError, number, NumberError>, "NonNegative", NonNegativeError, IntError | NumberError>;
1394
+ export declare const NonNegativeInt: BrandType<Type<"Brand", number & Brand<"Int">, number, IntError, number, NumberError>, "NonNegative", NonNegativeError, NumberError | IntError>;
1310
1395
  export type NonNegativeInt = typeof NonNegativeInt.Type;
1396
+ /** Minimum {@link NonNegativeInt} value (0). */
1397
+ export declare const zeroNonNegativeInt: number & Brand<"Int"> & Brand<"NonNegative">;
1311
1398
  /**
1312
1399
  * Positive integer (> 0).
1313
1400
  *
1314
- * @category Number
1401
+ * @group Number
1315
1402
  */
1316
- export declare const PositiveInt: BrandType<Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, NonNegativeError, number & Brand<"Int">, IntError | NumberError>, "Positive", PositiveError, NonNegativeError | IntError | NumberError>;
1403
+ export declare const PositiveInt: BrandType<Type<"Brand", number & Brand<"Int"> & Brand<"NonNegative">, number, NonNegativeError, number & Brand<"Int">, NumberError | IntError>, "Positive", PositiveError, NumberError | NonNegativeError | IntError>;
1317
1404
  export type PositiveInt = typeof PositiveInt.Type;
1318
- /** Maximum safe positive integer value for practically infinite operations. */
1405
+ /** {@link PositiveInt} value 1. */
1406
+ export declare const onePositiveInt: number & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
1407
+ /** Maximum {@link PositiveInt} value (MAX_SAFE_INTEGER). */
1319
1408
  export declare const maxPositiveInt: number & Brand<"Int"> & Brand<"NonNegative"> & Brand<"Positive">;
1320
1409
  /**
1321
1410
  * Non-positive integer (≤ 0).
1322
1411
  *
1323
- * @category Number
1412
+ * @group Number
1324
1413
  */
1325
- export declare const NonPositiveInt: BrandType<Type<"Brand", number & Brand<"Int">, number, IntError, number, NumberError>, "NonPositive", NonPositiveError, IntError | NumberError>;
1414
+ export declare const NonPositiveInt: BrandType<Type<"Brand", number & Brand<"Int">, number, IntError, number, NumberError>, "NonPositive", NonPositiveError, NumberError | IntError>;
1326
1415
  export type NonPositiveInt = typeof NonPositiveInt.Type;
1327
1416
  /**
1328
1417
  * Negative integer (< 0).
1329
1418
  *
1330
- * @category Number
1419
+ * @group Number
1331
1420
  */
1332
- export declare const NegativeInt: BrandType<Type<"Brand", number & Brand<"Int"> & Brand<"NonPositive">, number, NonPositiveError, number & Brand<"Int">, IntError | NumberError>, "Negative", NegativeError, IntError | NumberError | NonPositiveError>;
1421
+ export declare const NegativeInt: BrandType<Type<"Brand", number & Brand<"Int"> & Brand<"NonPositive">, number, NonPositiveError, number & Brand<"Int">, NumberError | IntError>, "Negative", NegativeError, NumberError | IntError | NonPositiveError>;
1333
1422
  export type NegativeInt = typeof NegativeInt.Type;
1334
1423
  /**
1335
1424
  * Number greater than a specified value.
1336
1425
  *
1337
- * @category Number
1426
+ * Use numeric literal, not expression. See {@link BrandFactory}.
1427
+ *
1428
+ * @group Number
1338
1429
  */
1339
1430
  export declare const greaterThan: <Min extends number>(min: Min) => BrandFactory<`GreaterThan${Min}`, number, GreaterThanError<Min>>;
1340
1431
  export interface GreaterThanError<Min extends number = number> extends TypeError<"GreaterThan"> {
@@ -1344,7 +1435,9 @@ export declare const formatGreaterThanError: TypeErrorFormatter<GreaterThanError
1344
1435
  /**
1345
1436
  * Number less than a specified value.
1346
1437
  *
1347
- * @category Number
1438
+ * Use numeric literal, not expression. See {@link BrandFactory}.
1439
+ *
1440
+ * @group Number
1348
1441
  */
1349
1442
  export declare const lessThan: <Max extends number>(max: Max) => BrandFactory<`LessThan${Max}`, number, LessThanError<Max>>;
1350
1443
  export interface LessThanError<Max extends number = number> extends TypeError<"LessThan"> {
@@ -1354,7 +1447,9 @@ export declare const formatLessThanError: TypeErrorFormatter<LessThanError<numbe
1354
1447
  /**
1355
1448
  * Number ≥ a specified value.
1356
1449
  *
1357
- * @category Number
1450
+ * Use numeric literal, not expression. See {@link BrandFactory}.
1451
+ *
1452
+ * @group Number
1358
1453
  */
1359
1454
  export declare const greaterThanOrEqualTo: <Min extends number>(min: Min) => BrandFactory<`GreaterThanOrEqualTo${Min}`, number, GreaterThanOrEqualToError<Min>>;
1360
1455
  export interface GreaterThanOrEqualToError<Min extends number = number> extends TypeError<"GreaterThanOrEqualTo"> {
@@ -1364,7 +1459,9 @@ export declare const formatGreaterThanOrEqualToError: TypeErrorFormatter<Greater
1364
1459
  /**
1365
1460
  * Number ≤ a specified value.
1366
1461
  *
1367
- * @category Number
1462
+ * Use numeric literal, not expression. See {@link BrandFactory}.
1463
+ *
1464
+ * @group Number
1368
1465
  */
1369
1466
  export declare const lessThanOrEqualTo: <Max extends number>(max: Max) => BrandFactory<`LessThanOrEqualTo${Max}`, number, LessThanOrEqualToError<Max>>;
1370
1467
  export interface LessThanOrEqualToError<Max extends number = number> extends TypeError<"LessThanOrEqualTo"> {
@@ -1374,19 +1471,19 @@ export declare const formatLessThanOrEqualToError: TypeErrorFormatter<LessThanOr
1374
1471
  /**
1375
1472
  * Number that is not NaN.
1376
1473
  *
1377
- * @category Number
1474
+ * @group Number
1378
1475
  */
1379
1476
  export declare const nonNaN: BrandFactory<"NonNaN", number, NonNaNError>;
1380
1477
  export interface NonNaNError extends TypeError<"NonNaN"> {
1381
1478
  }
1382
1479
  export declare const formatNonNaNError: TypeErrorFormatter<NonNaNError>;
1383
- /** @category Number */
1480
+ /** @group Number */
1384
1481
  export declare const NonNaNNumber: BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "NonNaN", NonNaNError, NumberError>;
1385
1482
  export type NonNaNNumber = typeof NonNaNNumber.Type;
1386
1483
  /**
1387
1484
  * Finite number.
1388
1485
  *
1389
- * @category Number
1486
+ * @group Number
1390
1487
  */
1391
1488
  export declare const finite: BrandFactory<"Finite", number, FiniteError>;
1392
1489
  export interface FiniteError extends TypeError<"Finite"> {
@@ -1403,14 +1500,16 @@ export declare const formatFiniteError: TypeErrorFormatter<FiniteError>;
1403
1500
  * finite (e.g., `Infinity`, `-Infinity`, or `NaN`). Using `FiniteNumber` helps
1404
1501
  * prevent these unexpected behaviors when working with JSON serialization.
1405
1502
  *
1406
- * @category Number
1503
+ * @group Number
1407
1504
  */
1408
1505
  export declare const FiniteNumber: BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "Finite", FiniteError, NumberError>;
1409
1506
  export type FiniteNumber = typeof FiniteNumber.Type;
1410
1507
  /**
1411
1508
  * Number that is a multiple of a divisor.
1412
1509
  *
1413
- * @category Number
1510
+ * Use numeric literal, not expression. See {@link BrandFactory}.
1511
+ *
1512
+ * @group Number
1414
1513
  */
1415
1514
  export declare const multipleOf: <Divisor extends number>(divisor: Divisor) => BrandFactory<`MultipleOf${Divisor}`, number, MultipleOfError<Divisor>>;
1416
1515
  export interface MultipleOfError<Divisor extends number = number> extends TypeError<"MultipleOf"> {
@@ -1420,6 +1519,8 @@ export declare const formatMultipleOfError: TypeErrorFormatter<MultipleOfError<n
1420
1519
  /**
1421
1520
  * Number within a range, inclusive.
1422
1521
  *
1522
+ * Use numeric literal, not expression. See {@link BrandFactory}.
1523
+ *
1423
1524
  * ### Example
1424
1525
  *
1425
1526
  * ```ts
@@ -1428,7 +1529,7 @@ export declare const formatMultipleOfError: TypeErrorFormatter<MultipleOfError<n
1428
1529
  * const errorResult = Between1And10.from(11); // err
1429
1530
  * ```
1430
1531
  *
1431
- * @category Number
1532
+ * @group Number
1432
1533
  */
1433
1534
  export declare const between: <Min extends number, Max extends number>(min: Min, max: Max) => BrandFactory<`Between${Min}-${Max}`, number, BetweenError<Min, Max>>;
1434
1535
  export interface BetweenError<Min extends number = number, Max extends number = number> extends TypeError<"Between"> {
@@ -1451,7 +1552,7 @@ export declare const formatBetweenError: TypeErrorFormatter<BetweenError<number,
1451
1552
  *
1452
1553
  * TODO: Add JsonValue
1453
1554
  *
1454
- * @category Base Factories
1555
+ * @group Base factories
1455
1556
  */
1456
1557
  export declare const literal: <T extends Literal>(expected: T) => LiteralType<T>;
1457
1558
  export interface LiteralType<T extends Literal> extends Type<"Literal", T, WidenLiteral<T>, LiteralError<T>> {
@@ -1464,7 +1565,7 @@ export declare const formatLiteralError: TypeErrorFormatter<LiteralError<Literal
1464
1565
  /**
1465
1566
  * Array of a specific {@link Type}.
1466
1567
  *
1467
- * Usage:
1568
+ * ### Example
1468
1569
  *
1469
1570
  * ```ts
1470
1571
  * const NumberArray = array(Number);
@@ -1473,8 +1574,8 @@ export declare const formatLiteralError: TypeErrorFormatter<LiteralError<Literal
1473
1574
  * const result2 = NumberArray.from(["a", "b"]); // err(...)
1474
1575
  * ```
1475
1576
  *
1476
- * @category Base Factories
1477
- * @category Array
1577
+ * @group Base factories
1578
+ * @group Array
1478
1579
  */
1479
1580
  export declare const array: <ElementType extends AnyType>(element: ElementType) => ArrayType<ElementType>;
1480
1581
  /** ArrayType extends Type with an additional `element` property for reflection. */
@@ -1502,7 +1603,7 @@ export declare const formatArrayError: <Error extends TypeError>(formatTypeError
1502
1603
  * const result2 = NumberSet.from(new Set(["a", "b"])); // err(...)
1503
1604
  * ```
1504
1605
  *
1505
- * @category Base Factories
1606
+ * @group Base factories
1506
1607
  */
1507
1608
  export declare const set: <ElementType extends AnyType>(element: ElementType) => SetType<ElementType>;
1508
1609
  /** SetType extends Type with an additional `element` property for reflection. */
@@ -1542,8 +1643,8 @@ export declare const formatSetError: <Error extends TypeError>(formatTypeError:
1542
1643
  * StringToNumberRecord.from({ a: "x", b: 2 });
1543
1644
  * ```
1544
1645
  *
1545
- * @category Base Factories
1546
- * @category Object
1646
+ * @group Base factories
1647
+ * @group Object
1547
1648
  */
1548
1649
  export declare const record: <KeyName extends TypeName, KeyT extends string, KeyInput extends string, KeyError extends TypeError, KeyParent extends string, KeyParentError extends TypeError, Value extends AnyType>(keyType: Type<KeyName, KeyT, KeyInput, KeyError, KeyParent, KeyParentError>, valueType: Value) => RecordType<KeyName, KeyT, KeyInput, KeyError, KeyParent, KeyParentError, Value>;
1549
1650
  /**
@@ -1585,22 +1686,22 @@ export declare const formatRecordError: <Error extends TypeError>(formatTypeErro
1585
1686
  *
1586
1687
  * https://www.typescriptlang.org/docs/handbook/2/objects.html#index-signatures
1587
1688
  *
1588
- * ### Examples
1689
+ * ### Example
1589
1690
  *
1590
- * #### Basic Object Validation
1691
+ * ## Basic Object Validation
1591
1692
  *
1592
1693
  * ```ts
1593
1694
  * const User = object({
1594
1695
  * name: NonEmptyTrimmedString,
1595
1696
  * age: PositiveNumber,
1596
1697
  * });
1597
- * type User = typeof User.Type;
1698
+ * interface User extends InferType<typeof User> {}
1598
1699
  *
1599
1700
  * const result = User.from({ name: "John", age: 30 }); // ok({ name: "John", age: 30 })
1600
1701
  * const error = User.from({ name: "John", age: -5 }); // err
1601
1702
  * ```
1602
1703
  *
1603
- * #### Optional Properties
1704
+ * ## Optional Properties
1604
1705
  *
1605
1706
  * In this example the `age` property is marked as optional using
1606
1707
  * {@link optional}.
@@ -1610,10 +1711,10 @@ export declare const formatRecordError: <Error extends TypeError>(formatTypeErro
1610
1711
  * name: NonEmptyString, // Required
1611
1712
  * age: optional(PositiveNumber), // Optional
1612
1713
  * });
1613
- * type User = typeof User.Type;
1714
+ * interface User extends InferType<typeof User> {}
1614
1715
  * ```
1615
1716
  *
1616
- * #### Allowing Additional Properties
1717
+ * ## Allowing Additional Properties
1617
1718
  *
1618
1719
  * ```ts
1619
1720
  * const UserWithAnyExtraProperties = object(
@@ -1632,7 +1733,7 @@ export declare const formatRecordError: <Error extends TypeError>(formatTypeErro
1632
1733
  * });
1633
1734
  * ```
1634
1735
  *
1635
- * #### Combining Fixed and Flexible Properties
1736
+ * ## Combining Fixed and Flexible Properties
1636
1737
  *
1637
1738
  * ```ts
1638
1739
  * const NumberDictionary = object(
@@ -1669,10 +1770,11 @@ export declare const formatRecordError: <Error extends TypeError>(formatTypeErro
1669
1770
  * );
1670
1771
  * ```
1671
1772
  *
1672
- * @category Base Factories
1673
- * @category Object
1773
+ * @group Base factories
1774
+ * @group Object
1674
1775
  */
1675
1776
  export declare function object<Props extends Record<string, AnyType>>(props: Props): ObjectType<Props>;
1777
+ /** With additional record properties. */
1676
1778
  export declare function object<Props extends Record<string, AnyType>, KeyName extends TypeName, KeyT extends string, KeyInput extends string, KeyError extends TypeError, KeyParent extends string, KeyParentError extends TypeError, Value extends AnyType>(props: Props, record: RecordType<KeyName, KeyT, KeyInput, KeyError, KeyParent, KeyParentError, Value>): ObjectWithRecordType<Props, KeyName, KeyT, KeyInput, KeyError, KeyParent, KeyParentError, Value>;
1677
1779
  /**
1678
1780
  * ObjectType extends {@link Type} with an additional `props` property for
@@ -1718,7 +1820,7 @@ export interface ObjectError<PropsErrors extends Record<string, TypeError> = Rec
1718
1820
  * Merge Error and ParentError into one ObjectError so tooltips and error
1719
1821
  * messages are easier to read.
1720
1822
  *
1721
- * @category Utilities
1823
+ * @group Utilities
1722
1824
  */
1723
1825
  export type MergeObjectTypeErrors<T extends ObjectType<any>> = T extends ObjectType<infer Props> ? ObjectError<{
1724
1826
  [K in keyof Props]: InferErrors<Props[K]>;
@@ -1752,6 +1854,170 @@ export interface ObjectWithRecordError<PropsErrors extends Record<string, TypeEr
1752
1854
  }> {
1753
1855
  }
1754
1856
  export declare const formatObjectWithRecordError: <Error extends TypeError>(formatTypeError: TypeErrorFormatter<Error>) => TypeErrorFormatter<ObjectWithRecordError<Record<string, Error>, Error, Error>>;
1857
+ /**
1858
+ * Base interface for objects with a discriminant `type` property.
1859
+ *
1860
+ * This enables
1861
+ * {@link https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions | discriminated unions}
1862
+ * (also known as tagged unions) — a pattern where TypeScript uses a literal
1863
+ * `type` field to narrow union types automatically.
1864
+ *
1865
+ * ## Why Discriminated Unions?
1866
+ *
1867
+ * Discriminated unions model states that are **mutually exclusive**. Instead of
1868
+ * optional fields and boolean flags that can combine into invalid
1869
+ * configurations, each variant is a distinct type. This makes illegal states
1870
+ * unrepresentable — invalid combinations cannot exist, so bugs cannot create
1871
+ * them.
1872
+ *
1873
+ * Benefits:
1874
+ *
1875
+ * - **Self-documenting** — Union cases immediately show all possible states
1876
+ * - **Compile-time safety** — TypeScript enforces handling all cases
1877
+ * - **Refactoring-friendly** — Adding a new state breaks code that doesn't handle
1878
+ * it
1879
+ *
1880
+ * ### Example
1881
+ *
1882
+ * ```ts
1883
+ * // Bad: optional fields allow invalid states (no contact info at all)
1884
+ * interface Contact {
1885
+ * readonly email?: Email;
1886
+ * readonly phone?: Phone;
1887
+ * }
1888
+ *
1889
+ * // Good: discriminated union makes "at least one" explicit
1890
+ * interface EmailOnly extends Typed<"EmailOnly"> {
1891
+ * readonly email: Email;
1892
+ * }
1893
+ * interface PhoneOnly extends Typed<"PhoneOnly"> {
1894
+ * readonly phone: Phone;
1895
+ * }
1896
+ * interface EmailAndPhone extends Typed<"EmailAndPhone"> {
1897
+ * readonly email: Email;
1898
+ * readonly phone: Phone;
1899
+ * }
1900
+ *
1901
+ * type ContactInfo = EmailOnly | PhoneOnly | EmailAndPhone;
1902
+ * ```
1903
+ *
1904
+ * ```ts
1905
+ * interface Pending extends Typed<"Pending"> {
1906
+ * readonly createdAt: DateIso;
1907
+ * }
1908
+ * interface Shipped extends Typed<"Shipped"> {
1909
+ * readonly trackingNumber: TrackingNumber;
1910
+ * }
1911
+ * interface Delivered extends Typed<"Delivered"> {
1912
+ * readonly deliveredAt: DateIso;
1913
+ * }
1914
+ * interface Cancelled extends Typed<"Cancelled"> {
1915
+ * readonly reason: CancellationReason;
1916
+ * }
1917
+ *
1918
+ * type OrderState = Pending | Shipped | Delivered | Cancelled;
1919
+ *
1920
+ * // TypeScript enforces exhaustiveness via return type
1921
+ * const getStatusMessage = (state: OrderState): string => {
1922
+ * switch (state.type) {
1923
+ * case "Pending":
1924
+ * return "Order placed";
1925
+ * case "Shipped":
1926
+ * return `Shipped: ${state.trackingNumber}`;
1927
+ * case "Delivered":
1928
+ * return `Delivered on ${state.deliveredAt.toLocaleDateString()}`;
1929
+ * case "Cancelled":
1930
+ * return `Cancelled: ${state.reason}`;
1931
+ * }
1932
+ * };
1933
+ *
1934
+ * // For void functions, use exhaustiveCheck to ensure all cases are handled
1935
+ * const logState = (state: OrderState): void => {
1936
+ * switch (state.type) {
1937
+ * case "Pending":
1938
+ * console.log("Order placed");
1939
+ * break;
1940
+ * case "Shipped":
1941
+ * console.log(`Shipped: ${state.trackingNumber}`);
1942
+ * break;
1943
+ * case "Delivered":
1944
+ * console.log(
1945
+ * `Delivered on ${state.deliveredAt.toLocaleDateString()}`,
1946
+ * );
1947
+ * break;
1948
+ * case "Cancelled":
1949
+ * console.log(`Cancelled: ${state.reason}`);
1950
+ * break;
1951
+ * default:
1952
+ * exhaustiveCheck(state);
1953
+ * }
1954
+ * };
1955
+ * ```
1956
+ *
1957
+ * ## Why `type` (and not e.g. `_tag`)?
1958
+ *
1959
+ * Underscore-prefixing is meant to avoid clashing with domain properties, but
1960
+ * proper discriminated union design means the discriminant IS the domain
1961
+ * concept — there's no clash to avoid. The `type` prop name also aligns with
1962
+ * {@link Type}'s name. If an entity has a meaningful "type" (like product
1963
+ * category), model it as the discriminant itself:
1964
+ *
1965
+ * ```ts
1966
+ * interface Electronics extends Typed<"Electronics"> {
1967
+ * voltage: Voltage;
1968
+ * }
1969
+ * interface Clothing extends Typed<"Clothing"> {
1970
+ * size: Size;
1971
+ * }
1972
+ * type Product = Electronics | Clothing;
1973
+ * ```
1974
+ *
1975
+ * @see {@link exhaustiveCheck} to ensure all cases are handled in void functions.
1976
+ * @see {@link typed} for runtime-validated typed objects.
1977
+ */
1978
+ export interface Typed<T extends TypeName> {
1979
+ readonly type: T;
1980
+ }
1981
+ /**
1982
+ * Creates a runtime-validated typed object with a `type` discriminant.
1983
+ *
1984
+ * ### Example
1985
+ *
1986
+ * ```ts
1987
+ * const Card = typed("Card", {
1988
+ * cardNumber: CardNumber,
1989
+ * expiry: DateIso,
1990
+ * });
1991
+ *
1992
+ * const Cash = typed("Cash", {
1993
+ * currency: NonEmptyTrimmedString,
1994
+ * });
1995
+ *
1996
+ * const Payment = union(Card, Cash);
1997
+ * type Payment = typeof Payment.Type;
1998
+ *
1999
+ * const result = Payment.fromUnknown(data);
2000
+ * if (result.ok) {
2001
+ * switch (result.value.type) {
2002
+ * case "Card":
2003
+ * console.log(result.value.cardNumber);
2004
+ * break;
2005
+ * case "Cash":
2006
+ * console.log(result.value.currency);
2007
+ * break;
2008
+ * }
2009
+ * }
2010
+ * ```
2011
+ *
2012
+ * @see {@link Typed} for type-only discrimination.
2013
+ */
2014
+ export declare function typed<Tag extends TypeName>(tag: Tag): TypedType<Tag>;
2015
+ /** With additional properties. */
2016
+ export declare function typed<Tag extends TypeName, Props extends Record<string, AnyType>>(tag: Tag, props: Props): TypedType<Tag, Props>;
2017
+ /** Return type of {@link typed}. */
2018
+ export type TypedType<Tag extends TypeName, Props extends Record<string, AnyType> = Record<never, never>> = ObjectType<{
2019
+ type: LiteralType<Tag>;
2020
+ } & Props>;
1755
2021
  /**
1756
2022
  * Union {@link Type}.
1757
2023
  *
@@ -1774,9 +2040,10 @@ export declare const formatObjectWithRecordError: <Error extends TypeError>(form
1774
2040
  * const result3 = StringOrNumber.from(42); // ok(42)
1775
2041
  * ```
1776
2042
  *
1777
- * @category Base Factories
2043
+ * @group Base factories
1778
2044
  */
1779
2045
  export declare function union<Members extends [AnyType, AnyType, ...ReadonlyArray<AnyType>]>(...members: Members): UnionType<Members>;
2046
+ /** With literal values. */
1780
2047
  export declare function union<Literals extends [Literal, Literal, ...ReadonlyArray<Literal>]>(...literals: Literals): UnionType<{
1781
2048
  [K in keyof Literals]: LiteralType<Literals[K]>;
1782
2049
  }>;
@@ -1792,6 +2059,99 @@ export interface UnionError<E extends TypeError = TypeError> extends TypeError<"
1792
2059
  }
1793
2060
  export declare const formatUnionError: <Error extends TypeError>(formatTypeError: TypeErrorFormatter<Error>) => TypeErrorFormatter<UnionError<Error>>;
1794
2061
  export declare const isUnionType: (t: AnyType) => t is UnionType<[AnyType, ...ReadonlyArray<AnyType>]>;
2062
+ /**
2063
+ * Creates a {@link Type} for {@link Result} values.
2064
+ *
2065
+ * Use for validating serialized Results from storage, APIs, or message passing.
2066
+ *
2067
+ * ### Example
2068
+ *
2069
+ * ```ts
2070
+ * const SyncResponse = result(
2071
+ * object({ timestamp: NonNegativeInt }),
2072
+ * typed("SyncError", { message: String }),
2073
+ * );
2074
+ *
2075
+ * // Validate response from worker or API
2076
+ * const validated = SyncResponse.from(JSON.parse(message));
2077
+ * if (!validated.ok) return validated; // validation error
2078
+ * // validated.value is Result<{ timestamp }, SyncError>
2079
+ * ```
2080
+ *
2081
+ * @group Composite factories
2082
+ */
2083
+ export declare const result: <OkType extends AnyType, ErrType extends AnyType>(okType: OkType, errType: ErrType) => UnionType<[ObjectType<{
2084
+ ok: LiteralType<true>;
2085
+ value: OkType;
2086
+ }>, ObjectType<{
2087
+ ok: LiteralType<false>;
2088
+ error: ErrType;
2089
+ }>]>;
2090
+ /**
2091
+ * A {@link result} type for `Result<unknown, unknown>`.
2092
+ *
2093
+ * Useful for serializing Results where the value and error types are unknown.
2094
+ *
2095
+ * @group Composite factories
2096
+ */
2097
+ export declare const UnknownResult: UnionType<[ObjectType<{
2098
+ ok: LiteralType<true>;
2099
+ value: Type<"Unknown", unknown, unknown, never, unknown, never>;
2100
+ }>, ObjectType<{
2101
+ ok: LiteralType<false>;
2102
+ error: Type<"Unknown", unknown, unknown, never, unknown, never>;
2103
+ }>]>;
2104
+ export type UnknownResult = typeof UnknownResult.Type;
2105
+ /**
2106
+ * Creates a {@link Type} for {@link NextResult} with three outcomes.
2107
+ *
2108
+ * Validates results where the producer responds with:
2109
+ *
2110
+ * - `Ok<A>` — produced a value
2111
+ * - `Err<Done<D>>` — completed normally with a done value
2112
+ * - `Err<E>` — failed with an error
2113
+ *
2114
+ * ### Example
2115
+ *
2116
+ * ```ts
2117
+ * const MyNextResult = nextResult(Item, MyError, Summary);
2118
+ *
2119
+ * const validated = MyNextResult.fromUnknown(data);
2120
+ * if (!validated.ok) return validated;
2121
+ *
2122
+ * const result = validated.value;
2123
+ * if (result.ok) {
2124
+ * console.log(result.value);
2125
+ * } else if (result.error.type === "Done") {
2126
+ * console.log("Done:", result.error.done);
2127
+ * } else {
2128
+ * console.error(result.error);
2129
+ * }
2130
+ * ```
2131
+ *
2132
+ * @group Composite factories
2133
+ */
2134
+ export declare const nextResult: <ValueType extends AnyType, ErrorType extends AnyType, DoneType extends AnyType>(valueType: ValueType, errorType: ErrorType, doneType: DoneType) => ReturnType<typeof result<ValueType, UnionType<[ErrorType, TypedType<"Done", {
2135
+ done: DoneType;
2136
+ }>]>>>;
2137
+ /**
2138
+ * A {@link nextResult} type for `NextResult<unknown, unknown, unknown>`.
2139
+ *
2140
+ * Useful for checking if a value is a {@link NextResult} via
2141
+ * `UnknownNextResult.is(value)`.
2142
+ *
2143
+ * @group Composite factories
2144
+ */
2145
+ export declare const UnknownNextResult: UnionType<[ObjectType<{
2146
+ ok: LiteralType<true>;
2147
+ value: Type<"Unknown", unknown, unknown, never, unknown, never>;
2148
+ }>, ObjectType<{
2149
+ ok: LiteralType<false>;
2150
+ error: UnionType<[Type<"Unknown", unknown, unknown, never, unknown, never>, TypedType<"Done", {
2151
+ done: Type<"Unknown", unknown, unknown, never, unknown, never>;
2152
+ }>]>;
2153
+ }>]>;
2154
+ export type UnknownNextResult = typeof UnknownNextResult.Type;
1795
2155
  /**
1796
2156
  * Recursive {@link Type}.
1797
2157
  *
@@ -1825,7 +2185,7 @@ export declare const isUnionType: (t: AnyType) => t is UnionType<[AnyType, ...Re
1825
2185
  * );
1826
2186
  * ```
1827
2187
  *
1828
- * @category Base Factories
2188
+ * @group Base factories
1829
2189
  */
1830
2190
  export declare const recursive: <ParentType extends AnyType>(create: () => ParentType) => RecursiveType<ParentType>;
1831
2191
  export interface RecursiveType<ParentType extends AnyType> extends Type<"Recursive", InferType<ParentType>, InferInput<ParentType>, InferError<ParentType>, InferParent<ParentType>, InferParentError<ParentType>> {
@@ -1843,7 +2203,7 @@ export interface RecursiveType<ParentType extends AnyType> extends Type<"Recursi
1843
2203
  * NullOrString.from(42); // err(...)
1844
2204
  * ```
1845
2205
  *
1846
- * @category Base Factories
2206
+ * @group Base factories
1847
2207
  */
1848
2208
  export declare const nullOr: <T extends AnyType>(type: T) => UnionType<[typeof Null, T]>;
1849
2209
  /**
@@ -1858,7 +2218,7 @@ export declare const nullOr: <T extends AnyType>(type: T) => UnionType<[typeof N
1858
2218
  * UndefinedOrString.from(42); // err(...)
1859
2219
  * ```
1860
2220
  *
1861
- * @category Base Factories
2221
+ * @group Base factories
1862
2222
  */
1863
2223
  export declare const undefinedOr: <T extends AnyType>(type: T) => UnionType<[typeof Undefined, T]>;
1864
2224
  /**
@@ -1877,7 +2237,7 @@ export declare const undefinedOr: <T extends AnyType>(type: T) => UnionType<[typ
1877
2237
  * NullishOrString.from(42); // err(...)
1878
2238
  * ```
1879
2239
  *
1880
- * @category Base Factories
2240
+ * @group Base factories
1881
2241
  */
1882
2242
  export declare const nullishOr: <T extends AnyType>(type: T) => UnionType<[typeof Undefined, typeof Null, T]>;
1883
2243
  /**
@@ -1894,7 +2254,7 @@ export declare const nullishOr: <T extends AnyType>(type: T) => UnionType<[typeo
1894
2254
  * const error = NameAndAge.from(["Alice", -10]); // err
1895
2255
  * ```
1896
2256
  *
1897
- * @category Base Factories
2257
+ * @group Base factories
1898
2258
  */
1899
2259
  export declare const tuple: <Elements extends [AnyType, ...ReadonlyArray<AnyType>]>(...elements: Elements) => TupleType<Elements>;
1900
2260
  /**
@@ -1939,7 +2299,7 @@ export declare const formatTupleError: <Error extends TypeError>(formatTypeError
1939
2299
  *
1940
2300
  * https://www.sqlite.org/c3ref/int64.html
1941
2301
  *
1942
- * @category Number
2302
+ * @group Number
1943
2303
  */
1944
2304
  export declare const Int64: BrandType<Type<"BigInt", bigint, bigint, BigIntError, bigint, BigIntError>, "Int64", Int64Error, BigIntError>;
1945
2305
  export type Int64 = typeof Int64.Type;
@@ -1949,14 +2309,37 @@ export declare const formatInt64Error: TypeErrorFormatter<Int64Error>;
1949
2309
  /**
1950
2310
  * Stringified {@link Int64}.
1951
2311
  *
1952
- * @category String
2312
+ * @group String
1953
2313
  */
1954
2314
  export declare const Int64String: BrandType<BrandType<Type<"Brand", string & Brand<"Trimmed">, string, TrimmedError, string, StringError>, "MinLength1", MinLengthError<1>, StringError | TrimmedError>, "Int64", Int64StringError, StringError | TrimmedError | MinLengthError<1>>;
1955
2315
  export type Int64String = typeof Int64String.Type;
1956
2316
  export interface Int64StringError extends TypeError<"Int64String"> {
1957
2317
  }
1958
2318
  export declare const formatInt64StringError: TypeErrorFormatter<Int64StringError>;
2319
+ /**
2320
+ * Validated JSON-compatible value.
2321
+ *
2322
+ * This is the output side of JSON data in Evolu. It uses {@link FiniteNumber}
2323
+ * instead of `number` because JSON numbers are expected to be finite once the
2324
+ * value has been parsed or validated.
2325
+ *
2326
+ * Compare with {@link JsonValueInput}, which represents caller-provided input
2327
+ * before validation.
2328
+ */
1959
2329
  export type JsonValue = string | FiniteNumber | boolean | null | JsonArray | JsonObject;
2330
+ /**
2331
+ * JSON-compatible input value before validation.
2332
+ *
2333
+ * This is broader than {@link JsonValue} because inputs arrive as ordinary
2334
+ * JavaScript values, so numbers are typed as `number` before validation can
2335
+ * narrow them to {@link FiniteNumber}.
2336
+ *
2337
+ * That means `JsonValueInput` can temporarily contain numbers that are lossy in
2338
+ * JSON serialization. For example, `JSON.stringify(NaN)` and
2339
+ * `JSON.stringify(Infinity)` produce `null`, and `JSON.stringify(-0)` produces
2340
+ * `0`. Use {@link JsonValue} when the value must already satisfy JSON numeric
2341
+ * constraints.
2342
+ */
1960
2343
  export type JsonValueInput = string | number | boolean | null | JsonArrayInput | JsonObjectInput;
1961
2344
  export type JsonValueError = UnionError<StringError | BooleanError | NullError | FiniteError | NumberError | ArrayError<JsonValueError> | RecordError<StringError, JsonValueError>>;
1962
2345
  export interface JsonObject {
@@ -1971,19 +2354,19 @@ export type JsonArrayInput = ReadonlyArray<JsonValueInput>;
1971
2354
  * JSON-compatible value: string, {@link FiniteNumber}, boolean, null,
1972
2355
  * {@link JsonArray}, or {@link JsonObject}.
1973
2356
  *
1974
- * @category Base Types
2357
+ * @group Base Types
1975
2358
  */
1976
2359
  export declare const JsonValue: RecursiveType<UnionType<[Type<"String", string, string, StringError, string, StringError>, BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "Finite", FiniteError, NumberError>, Type<"Boolean", boolean, boolean, BooleanError, boolean, BooleanError>, Type<"Null", null, null, NullError, null, NullError>, ArrayType<Type<"Recursive", JsonValue, JsonValueInput, JsonValueError, JsonValueInput, JsonValueError>>, RecordType<"String", string, string, StringError, string, StringError, Type<"Recursive", JsonValue, JsonValueInput, JsonValueError, JsonValueInput, JsonValueError>>]>>;
1977
2360
  /**
1978
2361
  * JSON-compatible array of {@link JsonValue} elements.
1979
2362
  *
1980
- * @category Array
2363
+ * @group Array
1981
2364
  */
1982
2365
  export declare const JsonArray: ArrayType<RecursiveType<UnionType<[Type<"String", string, string, StringError, string, StringError>, BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "Finite", FiniteError, NumberError>, Type<"Boolean", boolean, boolean, BooleanError, boolean, BooleanError>, Type<"Null", null, null, NullError, null, NullError>, ArrayType<Type<"Recursive", JsonValue, JsonValueInput, JsonValueError, JsonValueInput, JsonValueError>>, RecordType<"String", string, string, StringError, string, StringError, Type<"Recursive", JsonValue, JsonValueInput, JsonValueError, JsonValueInput, JsonValueError>>]>>>;
1983
2366
  /**
1984
2367
  * JSON-compatible object with string keys and {@link JsonValue} values.
1985
2368
  *
1986
- * @category Object
2369
+ * @group Object
1987
2370
  */
1988
2371
  export declare const JsonObject: RecordType<"String", string, string, StringError, string, StringError, RecursiveType<UnionType<[Type<"String", string, string, StringError, string, StringError>, BrandType<Type<"Number", number, number, NumberError, number, NumberError>, "Finite", FiniteError, NumberError>, Type<"Boolean", boolean, boolean, BooleanError, boolean, BooleanError>, Type<"Null", null, null, NullError, null, NullError>, ArrayType<Type<"Recursive", JsonValue, JsonValueInput, JsonValueError, JsonValueInput, JsonValueError>>, RecordType<"String", string, string, StringError, string, StringError, Type<"Recursive", JsonValue, JsonValueInput, JsonValueError, JsonValueInput, JsonValueError>>]>>>;
1989
2372
  export declare const parseJson: (value: string) => Result<JsonValue, JsonError>;
@@ -1997,7 +2380,7 @@ export declare const parseJson: (value: string) => Result<JsonValue, JsonError>;
1997
2380
  * const error = Json.from("invalid json"); // err
1998
2381
  * ```
1999
2382
  *
2000
- * @category String
2383
+ * @group String
2001
2384
  */
2002
2385
  export declare const Json: BrandType<Type<"String", string, string, StringError, string, StringError>, "Json", JsonError, StringError>;
2003
2386
  export type Json = typeof Json.Type;
@@ -2027,7 +2410,7 @@ export declare const jsonToJsonValue: (value: Json) => JsonValue;
2027
2410
  * name: NonEmptyString100,
2028
2411
  * age: FiniteNumber,
2029
2412
  * });
2030
- * type Person = typeof Person.Type;
2413
+ * interface Person extends InferType<typeof Person> {}
2031
2414
  *
2032
2415
  * const [PersonJson, personToPersonJson, personJsonToPerson] = json(
2033
2416
  * Person,
@@ -2095,7 +2478,7 @@ export declare const isOptionalType: (x: unknown) => x is OptionalType<any>;
2095
2478
  * PartialUser.from({ age: -5 });
2096
2479
  * ```
2097
2480
  *
2098
- * @category Object
2481
+ * @group Object
2099
2482
  */
2100
2483
  export declare const partial: <Props extends Record<string, AnyType>>(props: Props) => ObjectType<{ [K in keyof Props]: OptionalType<Props[K]>; }>;
2101
2484
  /**
@@ -2104,7 +2487,7 @@ export declare const partial: <Props extends Record<string, AnyType>>(props: Pro
2104
2487
  * entirely, or set it to `null`, or set it to the non-null member of the
2105
2488
  * union.
2106
2489
  *
2107
- * @category Object
2490
+ * @group Object
2108
2491
  */
2109
2492
  export declare const nullableToOptional: <Props extends Record<string, AnyType>>(props: Props) => ObjectType<NullableToOptionalProps<Props>>;
2110
2493
  export type NullableToOptionalProps<Props extends Record<string, AnyType>> = {
@@ -2116,21 +2499,9 @@ export type NullTypeInMembers<Members extends [AnyType, ...Array<AnyType>]> = Me
2116
2499
  /**
2117
2500
  * Create a new `object` {@link Type} by omitting some keys.
2118
2501
  *
2119
- * @category Object
2502
+ * @group Object
2120
2503
  */
2121
- export declare function omit<T extends ObjectType<any>, Keys extends keyof T["props"]>(objectType: T, ...keys: ReadonlyArray<Keys>): ObjectType<Omit<T["props"], Keys>>;
2122
- export declare const maxMutationSize = 655360;
2123
- /**
2124
- * Evolu has to limit the maximum mutation size. Otherwise, sync couldn't use
2125
- * the `maxProtocolMessageRangesSize`. The max size is 640KB in bytes, measured
2126
- * via MessagePack. Evolu Protocol DbChange will be smaller thanks to various
2127
- * optimizations.
2128
- */
2129
- export declare const validMutationSize: <T extends AnyType>(type: T) => BrandType<T, "ValidMutationSize", ValidMutationSizeError, InferErrors<T>>;
2130
- export interface ValidMutationSizeError extends TypeError<"ValidMutationSize"> {
2131
- }
2132
- export declare const formatValidMutationSizeError: TypeErrorFormatter<ValidMutationSizeError>;
2133
- export type ValidMutationSize<Props extends Record<string, AnyType>> = BrandType<ObjectType<Props>, "ValidMutationSize", ValidMutationSizeError, InferErrors<ObjectType<Props>>>;
2504
+ export declare const omit: <T extends ObjectType<any>, Keys extends keyof T["props"]>(objectType: T, ...keys: ReadonlyArray<Keys>) => ObjectType<Omit<T["props"], Keys>>;
2134
2505
  /**
2135
2506
  * Union of all `TypeError`s defined in the `Type.ts` file, including base type
2136
2507
  * errors (e.g., `StringError`, `NumberError`), composite type errors
@@ -2142,9 +2513,9 @@ export type ValidMutationSize<Props extends Record<string, AnyType>> = BrandType
2142
2513
  * Used by {@link createFormatTypeError} to generate human-readable error
2143
2514
  * messages.
2144
2515
  *
2145
- * @category Utilities
2516
+ * @group Utilities
2146
2517
  */
2147
- export type TypeErrors<ExtraErrors extends TypeError = never> = StringError | NumberError | BigIntError | BooleanError | UndefinedError | NullError | FunctionError | Uint8ArrayError | InstanceOfError | EvoluTypeError | CurrencyCodeError | DateIsoError | TrimmedError | MinLengthError | MaxLengthError | LengthError | MnemonicError | RegexError | SimplePasswordError | IdError | TableIdError | PositiveError | NegativeError | NonPositiveError | NonNegativeError | IntError | GreaterThanError | LessThanError | GreaterThanOrEqualToError | LessThanOrEqualToError | NonNaNError | FiniteError | MultipleOfError | BetweenError | LiteralError | Int64Error | Int64StringError | JsonError | ValidMutationSizeError | ExtraErrors | ArrayError<TypeErrors<ExtraErrors>> | SetError<TypeErrors<ExtraErrors>> | RecordError<TypeErrors<ExtraErrors>, TypeErrors<ExtraErrors>> | ObjectError<Record<string, TypeErrors<ExtraErrors>>> | ObjectWithRecordError<Record<string, TypeErrors<ExtraErrors>>, TypeErrors<ExtraErrors>, TypeErrors<ExtraErrors>> | UnionError<TypeErrors<ExtraErrors>> | TupleError<TypeErrors<ExtraErrors>>;
2518
+ export type TypeErrors<ExtraErrors extends TypeError = never> = StringError | NumberError | BigIntError | BooleanError | UndefinedError | NullError | FunctionError | Uint8ArrayError | InstanceOfError | EvoluTypeError | CurrencyCodeError | DateIsoError | TrimmedError | MinLengthError | MaxLengthError | LengthError | MnemonicError | RegexError | SimplePasswordError | IdError | TableIdError | PositiveError | NegativeError | NonPositiveError | NonNegativeError | IntError | GreaterThanError | LessThanError | GreaterThanOrEqualToError | LessThanOrEqualToError | NonNaNError | FiniteError | MultipleOfError | BetweenError | LiteralError | Int64Error | Int64StringError | JsonError | ExtraErrors | ArrayError<TypeErrors<ExtraErrors>> | SetError<TypeErrors<ExtraErrors>> | RecordError<TypeErrors<ExtraErrors>, TypeErrors<ExtraErrors>> | ObjectError<Record<string, TypeErrors<ExtraErrors>>> | ObjectWithRecordError<Record<string, TypeErrors<ExtraErrors>>, TypeErrors<ExtraErrors>, TypeErrors<ExtraErrors>> | UnionError<TypeErrors<ExtraErrors>> | TupleError<TypeErrors<ExtraErrors>>;
2148
2519
  /**
2149
2520
  * Formats Evolu Type errors into user-friendly messages.
2150
2521
  *
@@ -2223,18 +2594,20 @@ export type TypeErrors<ExtraErrors extends TypeError = never> = StringError | Nu
2223
2594
  * };
2224
2595
  * ```
2225
2596
  *
2226
- * @category Utilities
2597
+ * @group Utilities
2227
2598
  */
2228
2599
  export declare const createFormatTypeError: <ExtraErrors extends TypeError = never>(extraFormatter?: TypeErrorFormatter<ExtraErrors>) => TypeErrorFormatter<TypeErrors<ExtraErrors>>;
2229
2600
  /**
2230
2601
  * Converts an Evolu {@link TypeError} to Standard Schema V1 issues format.
2231
2602
  *
2232
2603
  * This function recursively converts Evolu's typed errors into the Standard
2233
- * Schema issue format with proper path tracking for nested structures.
2604
+ * Schema issue format with proper path tracking for nested structures. The
2605
+ * `message` field contains the JSON-serialized typed error, which users can
2606
+ * deserialize and format using appropriate {@link TypeErrorFormatter}s.
2234
2607
  *
2235
- * @category Utilities
2608
+ * @group Utilities
2236
2609
  */
2237
- export declare const typeErrorToStandardSchemaIssues: <ExtraErrors extends TypeError = never>(error: TypeErrors<ExtraErrors>, formatTypeError: TypeErrorFormatter<TypeErrors<ExtraErrors>>, path?: ReadonlyArray<PropertyKey>) => ReadonlyArray<StandardSchemaV1.Issue>;
2610
+ export declare const typeErrorToStandardSchemaIssues: <ExtraErrors extends TypeError = never>(error: TypeErrors<ExtraErrors>, path?: ReadonlyArray<PropertyKey>) => ReadonlyArray<StandardSchemaV1.Issue>;
2238
2611
  /** The Standard Schema interface. */
2239
2612
  export interface StandardSchemaV1<Input = unknown, Output = Input> {
2240
2613
  /** The Standard Schema properties. */