effect 4.0.0-beta.85 → 4.0.0-beta.87

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 (263) hide show
  1. package/dist/ChannelSchema.d.ts +8 -8
  2. package/dist/ChannelSchema.d.ts.map +1 -1
  3. package/dist/Config.d.ts +2 -2
  4. package/dist/Config.d.ts.map +1 -1
  5. package/dist/Config.js +10 -3
  6. package/dist/Config.js.map +1 -1
  7. package/dist/Cron.d.ts.map +1 -1
  8. package/dist/Cron.js +4 -0
  9. package/dist/Cron.js.map +1 -1
  10. package/dist/Schema.d.ts +749 -393
  11. package/dist/Schema.d.ts.map +1 -1
  12. package/dist/Schema.js +95 -65
  13. package/dist/Schema.js.map +1 -1
  14. package/dist/SchemaAST.d.ts.map +1 -1
  15. package/dist/SchemaAST.js +20 -29
  16. package/dist/SchemaAST.js.map +1 -1
  17. package/dist/SchemaParser.d.ts +24 -24
  18. package/dist/SchemaParser.d.ts.map +1 -1
  19. package/dist/SchemaParser.js +43 -39
  20. package/dist/SchemaParser.js.map +1 -1
  21. package/dist/SchemaRepresentation.d.ts +300 -300
  22. package/dist/SchemaTransformation.d.ts +2 -2
  23. package/dist/SchemaTransformation.d.ts.map +1 -1
  24. package/dist/SchemaTransformation.js +5 -8
  25. package/dist/SchemaTransformation.js.map +1 -1
  26. package/dist/internal/effect.js +6 -7
  27. package/dist/internal/effect.js.map +1 -1
  28. package/dist/internal/matcher.js +0 -2
  29. package/dist/internal/matcher.js.map +1 -1
  30. package/dist/internal/schema/representation.js +1 -5
  31. package/dist/internal/schema/representation.js.map +1 -1
  32. package/dist/internal/schema/schema.js.map +1 -1
  33. package/dist/testing/TestSchema.d.ts +9 -9
  34. package/dist/testing/TestSchema.d.ts.map +1 -1
  35. package/dist/testing/TestSchema.js +3 -2
  36. package/dist/testing/TestSchema.js.map +1 -1
  37. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +2 -2
  38. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  39. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  40. package/dist/unstable/ai/Chat.d.ts +1 -1
  41. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  42. package/dist/unstable/ai/LanguageModel.d.ts +4 -4
  43. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  44. package/dist/unstable/ai/McpSchema.d.ts +13 -6
  45. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  46. package/dist/unstable/ai/McpSchema.js.map +1 -1
  47. package/dist/unstable/ai/McpServer.d.ts +4 -4
  48. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  49. package/dist/unstable/ai/McpServer.js.map +1 -1
  50. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +2 -2
  51. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  52. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  53. package/dist/unstable/ai/Response.d.ts +2 -2
  54. package/dist/unstable/ai/Response.d.ts.map +1 -1
  55. package/dist/unstable/ai/Response.js.map +1 -1
  56. package/dist/unstable/ai/Tool.d.ts +26 -26
  57. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  58. package/dist/unstable/ai/Tool.js.map +1 -1
  59. package/dist/unstable/cli/Argument.d.ts +8 -7
  60. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  61. package/dist/unstable/cli/Argument.js.map +1 -1
  62. package/dist/unstable/cli/Flag.d.ts +8 -7
  63. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  64. package/dist/unstable/cli/Flag.js.map +1 -1
  65. package/dist/unstable/cli/Param.d.ts +1806 -168
  66. package/dist/unstable/cli/Param.d.ts.map +1 -1
  67. package/dist/unstable/cli/Param.js +0 -70
  68. package/dist/unstable/cli/Param.js.map +1 -1
  69. package/dist/unstable/cli/Primitive.d.ts +3 -4
  70. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  71. package/dist/unstable/cli/Primitive.js.map +1 -1
  72. package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
  73. package/dist/unstable/cli/internal/ansi.js +0 -22
  74. package/dist/unstable/cli/internal/ansi.js.map +1 -1
  75. package/dist/unstable/cli/internal/config.d.ts +48 -0
  76. package/dist/unstable/cli/internal/config.d.ts.map +1 -1
  77. package/dist/unstable/cli/internal/config.js +0 -6
  78. package/dist/unstable/cli/internal/config.js.map +1 -1
  79. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -3
  80. package/dist/unstable/cluster/Reply.d.ts +2 -2
  81. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  82. package/dist/unstable/cluster/Reply.js.map +1 -1
  83. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  84. package/dist/unstable/encoding/Msgpack.d.ts +6 -6
  85. package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
  86. package/dist/unstable/encoding/Msgpack.js.map +1 -1
  87. package/dist/unstable/encoding/Ndjson.d.ts +8 -8
  88. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  89. package/dist/unstable/encoding/Sse.d.ts +1 -1
  90. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  91. package/dist/unstable/encoding/Sse.js.map +1 -1
  92. package/dist/unstable/eventlog/EventLogMessage.d.ts +22 -22
  93. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  94. package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
  95. package/dist/unstable/http/HttpBody.d.ts +1 -1
  96. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  97. package/dist/unstable/http/HttpClientRequest.d.ts +1 -1
  98. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  99. package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
  100. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  101. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  102. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  103. package/dist/unstable/http/HttpMiddleware.js +12 -3
  104. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  105. package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
  106. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  107. package/dist/unstable/httpapi/HttpApiClient.d.ts +2 -2
  108. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  109. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  110. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +32 -32
  111. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  112. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  113. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
  114. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  115. package/dist/unstable/httpapi/HttpApiSchema.d.ts +13 -6
  116. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  117. package/dist/unstable/httpapi/HttpApiSchema.js +0 -13
  118. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  119. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  120. package/dist/unstable/observability/internal/otlpProtobuf.js +0 -68
  121. package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
  122. package/dist/unstable/observability/internal/protobuf.js +0 -28
  123. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  124. package/dist/unstable/persistence/KeyValueStore.d.ts +2 -2
  125. package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
  126. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  127. package/dist/unstable/persistence/Persistable.d.ts +6 -6
  128. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  129. package/dist/unstable/persistence/PersistedQueue.d.ts +3 -3
  130. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  131. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  132. package/dist/unstable/persistence/Persistence.d.ts +5 -5
  133. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  134. package/dist/unstable/reactivity/AsyncResult.d.ts +2 -2
  135. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  136. package/dist/unstable/reactivity/Atom.d.ts +1 -1
  137. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  138. package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
  139. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  140. package/dist/unstable/rpc/Rpc.d.ts +3 -4
  141. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  142. package/dist/unstable/rpc/Rpc.js +1 -1
  143. package/dist/unstable/rpc/Rpc.js.map +1 -1
  144. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  145. package/dist/unstable/rpc/RpcClient.js +25 -4
  146. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  147. package/dist/unstable/rpc/RpcMessage.d.ts +7 -0
  148. package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
  149. package/dist/unstable/rpc/RpcMessage.js +20 -0
  150. package/dist/unstable/rpc/RpcMessage.js.map +1 -1
  151. package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
  152. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  153. package/dist/unstable/rpc/RpcSchema.d.ts +10 -3
  154. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  155. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  156. package/dist/unstable/rpc/RpcWorker.d.ts +3 -3
  157. package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
  158. package/dist/unstable/schema/Model.d.ts +2 -2
  159. package/dist/unstable/schema/Model.d.ts.map +1 -1
  160. package/dist/unstable/schema/Model.js.map +1 -1
  161. package/dist/unstable/schema/VariantSchema.d.ts +16 -2
  162. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  163. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  164. package/dist/unstable/sql/SqlConnection.d.ts +1 -0
  165. package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
  166. package/dist/unstable/sql/SqlConnection.js.map +1 -1
  167. package/dist/unstable/sql/SqlModel.js.map +1 -1
  168. package/dist/unstable/sql/SqlResolver.d.ts +4 -4
  169. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  170. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  171. package/dist/unstable/sql/SqlSchema.d.ts +5 -5
  172. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  173. package/dist/unstable/sql/Statement.d.ts +1 -0
  174. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  175. package/dist/unstable/sql/Statement.js +3 -0
  176. package/dist/unstable/sql/Statement.js.map +1 -1
  177. package/dist/unstable/workflow/Activity.d.ts +2 -2
  178. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  179. package/dist/unstable/workflow/DurableDeferred.d.ts +18 -18
  180. package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
  181. package/dist/unstable/workflow/Workflow.d.ts +3 -3
  182. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  183. package/dist/unstable/workflow/Workflow.js.map +1 -1
  184. package/dist/unstable/workflow/WorkflowEngine.d.ts +3 -3
  185. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  186. package/package.json +1 -1
  187. package/src/ChannelSchema.ts +9 -9
  188. package/src/Config.ts +12 -5
  189. package/src/Cron.ts +4 -0
  190. package/src/Schema.ts +968 -689
  191. package/src/SchemaAST.ts +25 -35
  192. package/src/SchemaParser.ts +85 -77
  193. package/src/SchemaTransformation.ts +5 -6
  194. package/src/internal/effect.ts +6 -22
  195. package/src/internal/matcher.ts +0 -5
  196. package/src/internal/schema/arbitrary.ts +1 -1
  197. package/src/internal/schema/representation.ts +1 -5
  198. package/src/internal/schema/schema.ts +1 -1
  199. package/src/testing/TestSchema.ts +14 -13
  200. package/src/unstable/ai/AnthropicStructuredOutput.ts +2 -2
  201. package/src/unstable/ai/Chat.ts +1 -1
  202. package/src/unstable/ai/LanguageModel.ts +7 -7
  203. package/src/unstable/ai/McpSchema.ts +16 -14
  204. package/src/unstable/ai/McpServer.ts +7 -7
  205. package/src/unstable/ai/OpenAiStructuredOutput.ts +2 -2
  206. package/src/unstable/ai/Response.ts +9 -5
  207. package/src/unstable/ai/Tool.ts +49 -47
  208. package/src/unstable/cli/Argument.ts +9 -8
  209. package/src/unstable/cli/Flag.ts +9 -8
  210. package/src/unstable/cli/Param.ts +6 -146
  211. package/src/unstable/cli/Primitive.ts +5 -6
  212. package/src/unstable/cli/internal/ansi.ts +0 -33
  213. package/src/unstable/cli/internal/config.ts +0 -8
  214. package/src/unstable/cli/internal/parser.ts +2 -2
  215. package/src/unstable/cluster/MessageStorage.ts +1 -1
  216. package/src/unstable/cluster/Reply.ts +6 -2
  217. package/src/unstable/devtools/DevToolsSchema.ts +1 -1
  218. package/src/unstable/encoding/Msgpack.ts +9 -7
  219. package/src/unstable/encoding/Ndjson.ts +10 -10
  220. package/src/unstable/encoding/Sse.ts +1 -1
  221. package/src/unstable/eventlog/Event.ts +3 -3
  222. package/src/unstable/http/HttpBody.ts +1 -1
  223. package/src/unstable/http/HttpClientRequest.ts +1 -1
  224. package/src/unstable/http/HttpIncomingMessage.ts +1 -1
  225. package/src/unstable/http/HttpMiddleware.ts +12 -3
  226. package/src/unstable/httpapi/HttpApi.ts +1 -1
  227. package/src/unstable/httpapi/HttpApiBuilder.ts +9 -5
  228. package/src/unstable/httpapi/HttpApiClient.ts +10 -10
  229. package/src/unstable/httpapi/HttpApiEndpoint.ts +45 -33
  230. package/src/unstable/httpapi/HttpApiMiddleware.ts +2 -2
  231. package/src/unstable/httpapi/HttpApiSchema.ts +16 -43
  232. package/src/unstable/httpapi/OpenApi.ts +5 -5
  233. package/src/unstable/observability/internal/otlpProtobuf.ts +0 -75
  234. package/src/unstable/observability/internal/protobuf.ts +0 -42
  235. package/src/unstable/persistence/KeyValueStore.ts +2 -2
  236. package/src/unstable/persistence/Persistable.ts +7 -7
  237. package/src/unstable/persistence/PersistedQueue.ts +3 -3
  238. package/src/unstable/persistence/Persistence.ts +5 -5
  239. package/src/unstable/reactivity/AsyncResult.ts +4 -4
  240. package/src/unstable/reactivity/Atom.ts +1 -1
  241. package/src/unstable/reactivity/AtomHttpApi.ts +1 -1
  242. package/src/unstable/rpc/Rpc.ts +7 -8
  243. package/src/unstable/rpc/RpcClient.ts +26 -4
  244. package/src/unstable/rpc/RpcMessage.ts +19 -0
  245. package/src/unstable/rpc/RpcMiddleware.ts +2 -2
  246. package/src/unstable/rpc/RpcSchema.ts +12 -9
  247. package/src/unstable/rpc/RpcWorker.ts +3 -3
  248. package/src/unstable/schema/Model.ts +2 -2
  249. package/src/unstable/schema/VariantSchema.ts +19 -17
  250. package/src/unstable/sql/SqlConnection.ts +5 -0
  251. package/src/unstable/sql/SqlModel.ts +2 -2
  252. package/src/unstable/sql/SqlResolver.ts +6 -6
  253. package/src/unstable/sql/SqlSchema.ts +5 -5
  254. package/src/unstable/sql/Statement.ts +11 -0
  255. package/src/unstable/workflow/Activity.ts +6 -6
  256. package/src/unstable/workflow/DurableDeferred.ts +33 -33
  257. package/src/unstable/workflow/Workflow.ts +5 -5
  258. package/src/unstable/workflow/WorkflowEngine.ts +10 -10
  259. package/dist/internal/concurrency.d.ts +0 -2
  260. package/dist/internal/concurrency.d.ts.map +0 -1
  261. package/dist/internal/concurrency.js +0 -29
  262. package/dist/internal/concurrency.js.map +0 -1
  263. package/src/internal/concurrency.ts +0 -52
package/src/Schema.ts CHANGED
@@ -126,19 +126,13 @@ export interface MakeOptions {
126
126
 
127
127
  /**
128
128
  * The fully-parameterized base interface for all schemas. Exposes all 14 type
129
- * parameters controlling type inference, mutability, optionality, services,
130
- * and transformation behavior.
129
+ * parameters controlling type inference, mutability, optionality, services, and
130
+ * transformation behavior.
131
131
  *
132
132
  * **When to use**
133
133
  *
134
- * Use when you are writing advanced generic schema utilities or performing schema
135
- * introspection.
136
- * - In user code, prefer {@link Schema}, {@link Codec}, {@link Decoder}, or
137
- * {@link Encoder} instead.
138
- *
139
- * @see {@link Top} — the existential "any schema" type (erased type params)
140
- * @see {@link Schema} — tracks only the decoded Type
141
- * @see {@link Codec} — tracks Type + Encoded
134
+ * Use when you are writing advanced generic schema utilities or performing
135
+ * schema introspection.
142
136
  *
143
137
  * @category models
144
138
  * @since 4.0.0
@@ -152,7 +146,7 @@ export interface Bottom<
152
146
  out Rebuild extends Top,
153
147
  out TypeMakeIn = T,
154
148
  out Iso = T,
155
- in out TypeParameters extends ReadonlyArray<Top> = readonly [],
149
+ in out TypeParameters extends ReadonlyArray<Constraint> = readonly [],
156
150
  out TypeMake = TypeMakeIn,
157
151
  out TypeMutability extends Mutability = "readonly",
158
152
  out TypeOptionality extends Optionality = "required",
@@ -248,13 +242,67 @@ export interface Bottom<
248
242
  makeEffect(input: this["~type.make.in"], options?: MakeOptions): Effect.Effect<this["Type"], SchemaError>
249
243
  }
250
244
 
245
+ /**
246
+ * Lazy `Bottom` variant for schema implementations that compute their public
247
+ * views on demand.
248
+ *
249
+ * **When to use**
250
+ *
251
+ * Use as an implementation base for schema interfaces that must expose
252
+ * `Bottom` behavior without forcing TypeScript to eagerly evaluate expensive
253
+ * `Type`, `Encoded`, or service views.
254
+ *
255
+ * **Details**
256
+ *
257
+ * The laziness is purely type-level; runtime behavior is unchanged.
258
+ * `BottomLazy` keeps the structural operations inherited from `Bottom`, but
259
+ * erases the expensive schema views to `unknown`. Concrete schema interfaces can
260
+ * then redeclare the precise views they expose. This keeps wide schemas such as
261
+ * `Struct` and `Union` cheaper when generic code reads a single view, while
262
+ * preserving their exact public types.
263
+ *
264
+ * @see {@link Bottom} for the fully parameterized schema interface when every
265
+ * view must be supplied directly.
266
+ *
267
+ * @category utility types
268
+ * @since 4.0.0
269
+ */
270
+ export interface BottomLazy<
271
+ out Ast extends SchemaAST.AST,
272
+ out Rebuild extends Top,
273
+ in out TypeParameters extends ReadonlyArray<Constraint> = readonly [],
274
+ out TypeMutability extends Mutability = "readonly",
275
+ out TypeOptionality extends Optionality = "required",
276
+ out TypeConstructorDefault extends ConstructorDefault = "no-default",
277
+ out EncodedMutability extends Mutability = "readonly",
278
+ out EncodedOptionality extends Optionality = "required"
279
+ > extends
280
+ Bottom<
281
+ unknown,
282
+ unknown,
283
+ unknown,
284
+ unknown,
285
+ Ast,
286
+ Rebuild,
287
+ unknown,
288
+ unknown,
289
+ TypeParameters,
290
+ unknown,
291
+ TypeMutability,
292
+ TypeOptionality,
293
+ TypeConstructorDefault,
294
+ EncodedMutability,
295
+ EncodedOptionality
296
+ >
297
+ {}
298
+
251
299
  /**
252
300
  * Type-level representation returned by {@link declareConstructor}.
253
301
  *
254
302
  * @category constructors
255
303
  * @since 4.0.0
256
304
  */
257
- export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Top>, Iso = T> extends
305
+ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T> extends
258
306
  Bottom<
259
307
  T,
260
308
  E,
@@ -301,7 +349,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<T
301
349
  * const isBox = (u: unknown): u is Box<unknown> =>
302
350
  * typeof u === "object" && u !== null && "value" in u
303
351
  *
304
- * const Box = <A extends Schema.Top>(item: A) =>
352
+ * const Box = <A extends Schema.Constraint>(item: A) =>
305
353
  * Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
306
354
  * [item],
307
355
  * ([itemCodec]) =>
@@ -323,7 +371,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<T
323
371
  * @since 4.0.0
324
372
  */
325
373
  export function declareConstructor<T, E = T, Iso = T>() {
326
- return <const TypeParameters extends ReadonlyArray<Top>>(
374
+ return <const TypeParameters extends ReadonlyArray<Constraint>>(
327
375
  typeParameters: TypeParameters,
328
376
  run: (
329
377
  typeParameters: {
@@ -566,8 +614,8 @@ export function annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"
566
614
  * In user code prefer the narrower interfaces:
567
615
  * - {@link Schema}`<T>` — when you only care about the decoded type
568
616
  * - {@link Codec}`<T, E, RD, RE>` — when you need the encoded type and service requirements
569
- * - {@link Decoder}`<T, RD>` — for decode-only APIs
570
- * - {@link Encoder}`<E, RE>` — for encode-only APIs
617
+ * - {@link ConstraintDecoder}`<T, RD>` — for decode-only APIs
618
+ * - {@link ConstraintEncoder}`<E, RE>` — for encode-only APIs
571
619
  *
572
620
  * @category models
573
621
  * @since 4.0.0
@@ -592,6 +640,127 @@ export interface Top extends
592
640
  >
593
641
  {}
594
642
 
643
+ /**
644
+ * Lightweight structural constraint for APIs that accept schema values but only
645
+ * read their data and type-level views.
646
+ *
647
+ * **When to use**
648
+ *
649
+ * Use when you need to constrain a generic value to be a schema, but the API
650
+ * only reads properties such as `ast`, `Type`, `Encoded`, service
651
+ * requirements, constructor input views, or modifier flags.
652
+ *
653
+ * **Details**
654
+ *
655
+ * `Constraint` keeps the schema type identifier and the property surface needed
656
+ * by schema constructors, while avoiding the full `Bottom` protocol. Use
657
+ * {@link Top} when an API calls schema methods such as `annotate`, `check`,
658
+ * `rebuild`, `make`, or `makeEffect`.
659
+ *
660
+ * @see {@link Top} for the complete schema protocol.
661
+ *
662
+ * @category models
663
+ * @since 4.0.0
664
+ */
665
+ export interface Constraint {
666
+ readonly [TypeId]: typeof TypeId
667
+ readonly "ast": SchemaAST.AST
668
+
669
+ readonly "Type": unknown
670
+ readonly "Encoded": unknown
671
+ readonly "DecodingServices": unknown
672
+ readonly "EncodingServices": unknown
673
+
674
+ readonly "~type.parameters": any
675
+ readonly "~type.make.in": unknown
676
+ readonly "~type.make": unknown
677
+ readonly "Iso": unknown
678
+
679
+ readonly "~type.optionality": Optionality
680
+ readonly "~type.mutability": Mutability
681
+ readonly "~type.constructor.default": ConstructorDefault
682
+ readonly "~encoded.optionality": Optionality
683
+ readonly "~encoded.mutability": Mutability
684
+ }
685
+
686
+ /**
687
+ * Lightweight structural constraint for APIs that need codec type views but do
688
+ * not need the full schema protocol.
689
+ *
690
+ * **When to use**
691
+ *
692
+ * Use when you need to preserve decoded type, encoded type, and service
693
+ * requirements for a schema value, but the API does not call schema methods
694
+ * such as `annotate`, `check`, `rebuild`, `make`, or `makeEffect`.
695
+ *
696
+ * @see {@link Constraint} for the generic lightweight schema constraint.
697
+ * @see {@link Codec} for the full schema protocol with codec type views.
698
+ *
699
+ * @category models
700
+ * @since 4.0.0
701
+ */
702
+ export interface ConstraintCodec<out T, out E = T, out RD = never, out RE = never> extends Constraint {
703
+ readonly "Type": T
704
+ readonly "Encoded": E
705
+ readonly "DecodingServices": RD
706
+ readonly "EncodingServices": RE
707
+ }
708
+
709
+ /**
710
+ * Lightweight structural constraint for APIs that need decoder type views but
711
+ * do not need the full schema protocol.
712
+ *
713
+ * **When to use**
714
+ *
715
+ * Use when you need to preserve a schema's decoded type and decoding services,
716
+ * but the API does not constrain the encoded type, encoding services, or call
717
+ * schema methods such as `annotate`, `check`, `rebuild`, `make`, or
718
+ * `makeEffect`.
719
+ *
720
+ * @see {@link ConstraintCodec} for APIs that need both decoded and encoded codec views.
721
+ * @see {@link Codec} for the full schema protocol with codec type views.
722
+ *
723
+ * @category models
724
+ * @since 4.0.0
725
+ */
726
+ export interface ConstraintDecoder<out T, out RD = never> extends ConstraintCodec<T, unknown, RD, unknown> {}
727
+
728
+ /**
729
+ * Lightweight structural constraint for APIs that need encoder type views but
730
+ * do not need the full schema protocol.
731
+ *
732
+ * **When to use**
733
+ *
734
+ * Use when you need to preserve a schema's encoded type and encoding services,
735
+ * but the API does not constrain the decoded type, decoding services, or call
736
+ * schema methods such as `annotate`, `check`, `rebuild`, `make`, or
737
+ * `makeEffect`.
738
+ *
739
+ * @see {@link ConstraintCodec} for APIs that need both decoded and encoded codec views.
740
+ * @see {@link Codec} for the full schema protocol with codec type views.
741
+ *
742
+ * @category models
743
+ * @since 4.0.0
744
+ */
745
+ export interface ConstraintEncoder<out E, out RE = never> extends ConstraintCodec<unknown, E, unknown, RE> {}
746
+
747
+ /**
748
+ * Lightweight structural constraint for APIs that need schema views and the
749
+ * rebuilt schema type, but do not call the full schema protocol.
750
+ *
751
+ * **When to use**
752
+ *
753
+ * Use when an API needs to read `Rebuild` in addition to the schema views
754
+ * exposed by {@link Constraint}, but does not call methods such as `annotate`,
755
+ * `check`, `rebuild`, `make`, or `makeEffect`.
756
+ *
757
+ * @category models
758
+ * @since 4.0.0
759
+ */
760
+ export interface ConstraintRebuildable extends Constraint {
761
+ readonly "Rebuild": Constraint
762
+ }
763
+
595
764
  /**
596
765
  * Namespace of type-level helpers for {@link Schema}.
597
766
  *
@@ -614,7 +783,7 @@ export declare namespace Schema {
614
783
  * @category utility types
615
784
  * @since 3.10.0
616
785
  */
617
- export type Type<S> = S extends Top ? S["Type"] : never
786
+ export type Type<S> = S extends { readonly "Type": infer T } ? T : never
618
787
  }
619
788
 
620
789
  /**
@@ -674,7 +843,8 @@ export declare namespace Codec {
674
843
  * @category utility types
675
844
  * @since 3.10.0
676
845
  */
677
- export type Encoded<S> = S extends Top ? S["Encoded"] : never
846
+ export type Encoded<S> = S extends { readonly "Encoded": infer E } ? E : never
847
+
678
848
  /**
679
849
  * Extracts the Effect services required during *decoding* from a schema.
680
850
  *
@@ -691,7 +861,8 @@ export declare namespace Codec {
691
861
  * @category utility types
692
862
  * @since 4.0.0
693
863
  */
694
- export type DecodingServices<S> = S extends Top ? S["DecodingServices"] : never
864
+ export type DecodingServices<S> = S extends { readonly "DecodingServices": infer R } ? R : never
865
+
695
866
  /**
696
867
  * Extracts the Effect services required during *encoding* from a schema.
697
868
  *
@@ -708,7 +879,7 @@ export declare namespace Codec {
708
879
  * @category utility types
709
880
  * @since 4.0.0
710
881
  */
711
- export type EncodingServices<S> = S extends Top ? S["EncodingServices"] : never
882
+ export type EncodingServices<S> = S extends { readonly "EncodingServices": infer R } ? R : never
712
883
  }
713
884
 
714
885
  /**
@@ -747,8 +918,8 @@ export interface Optic<out T, out Iso> extends Schema<T> {
747
918
  * Most concrete schemas produced by this module implement `Codec`.
748
919
  *
749
920
  * For APIs that only need one direction, prefer the narrower views:
750
- * - {@link Decoder}`<T, RD>` — decode-only
751
- * - {@link Encoder}`<E, RE>` — encode-only
921
+ * - {@link ConstraintDecoder}`<T, RD>` — decode-only
922
+ * - {@link ConstraintEncoder}`<E, RE>` — encode-only
752
923
  * - {@link Schema}`<T>` — type-only (no encoded representation)
753
924
  *
754
925
  * **Example** (Accepting a codec that decodes to `number` from `string`)
@@ -776,60 +947,6 @@ export interface Codec<out T, out E = T, out RD = never, out RE = never> extends
776
947
  readonly "Rebuild": Codec<T, E, RD, RE>
777
948
  }
778
949
 
779
- /**
780
- * A {@link Codec} view for APIs that only *decode* (parse/validate) values.
781
- *
782
- * **Details**
783
- *
784
- * Use `Decoder<T, RD>` to accept "any schema that can decode to `T`" without
785
- * constraining or depending on the encoded representation (`Encoded` is
786
- * `unknown`) or encoding services.
787
- *
788
- * **Example** (Accepting schemas that only need to decode)
789
- *
790
- * ```ts
791
- * import { Schema } from "effect"
792
- *
793
- * declare function validate<T>(decoder: Schema.Decoder<T>): (input: unknown) => T
794
- *
795
- * validate(Schema.String) // ok
796
- * validate(Schema.NumberFromString) // ok
797
- * ```
798
- *
799
- * @category models
800
- * @since 4.0.0
801
- */
802
- export interface Decoder<out T, out RD = never> extends Codec<T, unknown, RD, unknown> {
803
- readonly "Rebuild": Decoder<T, RD>
804
- }
805
-
806
- /**
807
- * A {@link Codec} view for APIs that only *encode* values.
808
- *
809
- * **Details**
810
- *
811
- * Use `Encoder<E, RE>` to accept "any schema that can encode to `E`" without
812
- * constraining or depending on the decoded `Type` (`Type` is `unknown`) or
813
- * decoding services.
814
- *
815
- * **Example** (Accepting schemas that only need to encode)
816
- *
817
- * ```ts
818
- * import { Schema } from "effect"
819
- *
820
- * declare function serialize<E>(encoder: Schema.Encoder<E>): (value: unknown) => E
821
- *
822
- * serialize(Schema.String) // ok — encodes to string
823
- * serialize(Schema.NumberFromString) // ok — encodes number to string
824
- * ```
825
- *
826
- * @category models
827
- * @since 4.0.0
828
- */
829
- export interface Encoder<out E, out RE = never> extends Codec<unknown, E, unknown, RE> {
830
- readonly "Rebuild": Encoder<E, RE>
831
- }
832
-
833
950
  /**
834
951
  * Returns a codec widened to the full {@link Codec} interface, prompting
835
952
  * TypeScript to infer all four type parameters (`T`, `E`, `RD`, `RE`).
@@ -987,7 +1104,7 @@ function makeStandardResult<A>(exit: Exit_.Exit<StandardSchemaV1.Result<A>>): St
987
1104
  * @category Standard Schema
988
1105
  * @since 4.0.0
989
1106
  */
990
- export function toStandardSchemaV1<S extends Decoder<unknown>>(
1107
+ export function toStandardSchemaV1<S extends ConstraintDecoder<unknown>>(
991
1108
  self: S,
992
1109
  options?: {
993
1110
  readonly leafHook?: SchemaIssue.LeafHook | undefined
@@ -1037,7 +1154,7 @@ export function toStandardSchemaV1<S extends Decoder<unknown>>(
1037
1154
  }
1038
1155
  }
1039
1156
 
1040
- function toBaseStandardJSONSchemaV1(self: Top, target: StandardJSONSchemaV1.Target): JsonSchema.JsonSchema {
1157
+ function toBaseStandardJSONSchemaV1(self: Constraint, target: StandardJSONSchemaV1.Target): JsonSchema.JsonSchema {
1041
1158
  const doc2020_12 = toJsonSchemaDocument(self)
1042
1159
  if (target === "draft-2020-12") {
1043
1160
  const schema = doc2020_12.schema
@@ -1066,7 +1183,9 @@ function toBaseStandardJSONSchemaV1(self: Top, target: StandardJSONSchemaV1.Targ
1066
1183
  * @category Standard Schema
1067
1184
  * @since 4.0.0
1068
1185
  */
1069
- export function toStandardJSONSchemaV1<S extends Top>(self: S): StandardJSONSchemaV1<S["Encoded"], S["Type"]> & S {
1186
+ export function toStandardJSONSchemaV1<S extends Constraint>(
1187
+ self: S
1188
+ ): StandardJSONSchemaV1<S["Encoded"], S["Type"]> & S {
1070
1189
  const jsonSchema: StandardJSONSchemaV1.Props<S["Encoded"], S["Type"]>["jsonSchema"] = {
1071
1190
  input(options) {
1072
1191
  return toBaseStandardJSONSchemaV1(self, options.target)
@@ -1173,7 +1292,8 @@ export const is = SchemaParser.is
1173
1292
  * @category guards
1174
1293
  * @since 4.0.0
1175
1294
  */
1176
- export const asserts: <S extends Top, I>(schema: S, input: I) => asserts input is I & S["Type"] = SchemaParser.asserts
1295
+ export const asserts: <S extends Constraint, I>(schema: S, input: I) => asserts input is I & S["Type"] =
1296
+ SchemaParser.asserts
1177
1297
 
1178
1298
  /**
1179
1299
  * Decodes an `unknown` input against a schema, returning an `Effect` that
@@ -1196,7 +1316,7 @@ export const asserts: <S extends Top, I>(schema: S, input: I) => asserts input i
1196
1316
  * @category decoding
1197
1317
  * @since 4.0.0
1198
1318
  */
1199
- export function decodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAST.ParseOptions) {
1319
+ export function decodeUnknownEffect<S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions) {
1200
1320
  const parser = SchemaParser.decodeUnknownEffect(schema, options)
1201
1321
  return (
1202
1322
  input: unknown,
@@ -1227,7 +1347,7 @@ export function decodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAS
1227
1347
  * @category decoding
1228
1348
  * @since 4.0.0
1229
1349
  */
1230
- export const decodeEffect: <S extends Top>(
1350
+ export const decodeEffect: <S extends Constraint>(
1231
1351
  schema: S,
1232
1352
  options?: SchemaAST.ParseOptions
1233
1353
  ) => (
@@ -1303,7 +1423,7 @@ function runSchemaErrorSync<A>(
1303
1423
  * @category decoding
1304
1424
  * @since 4.0.0
1305
1425
  */
1306
- export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1426
+ export function decodeUnknownExit<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1307
1427
  const parser = SchemaParser.decodeUnknownExit(schema, options)
1308
1428
  return (input: unknown, options?: SchemaAST.ParseOptions): Exit_.Exit<S["Type"], SchemaError> => {
1309
1429
  return InternalSchema.mapSchemaIssueExit(parser(input, options))
@@ -1340,7 +1460,7 @@ export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options
1340
1460
  * @category decoding
1341
1461
  * @since 4.0.0
1342
1462
  */
1343
- export const decodeExit: <S extends Decoder<unknown>>(
1463
+ export const decodeExit: <S extends ConstraintDecoder<unknown>>(
1344
1464
  schema: S,
1345
1465
  options?: SchemaAST.ParseOptions
1346
1466
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError> = decodeUnknownExit
@@ -1371,7 +1491,7 @@ export const decodeExit: <S extends Decoder<unknown>>(
1371
1491
  * @category decoding
1372
1492
  * @since 3.10.0
1373
1493
  */
1374
- export const decodeUnknownOption: <S extends Decoder<unknown>>(
1494
+ export const decodeUnknownOption: <S extends ConstraintDecoder<unknown>>(
1375
1495
  schema: S,
1376
1496
  options?: SchemaAST.ParseOptions
1377
1497
  ) => (input: unknown, options?: SchemaAST.ParseOptions) => Option_.Option<S["Type"]> = SchemaParser.decodeUnknownOption
@@ -1401,10 +1521,10 @@ export const decodeUnknownOption: <S extends Decoder<unknown>>(
1401
1521
  * @category decoding
1402
1522
  * @since 3.10.0
1403
1523
  */
1404
- export const decodeOption: <S extends Decoder<unknown>>(
1524
+ export const decodeOption: <S extends ConstraintDecoder<unknown>>(
1405
1525
  schema: S,
1406
1526
  options?: SchemaAST.ParseOptions
1407
- ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Type"]> = decodeUnknownOption
1527
+ ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Type"]> = SchemaParser.decodeOption
1408
1528
 
1409
1529
  /**
1410
1530
  * Decodes an `unknown` input against a schema, returning a `Result` that
@@ -1435,7 +1555,7 @@ export const decodeOption: <S extends Decoder<unknown>>(
1435
1555
  * @category decoding
1436
1556
  * @since 4.0.0
1437
1557
  */
1438
- export function decodeUnknownResult<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1558
+ export function decodeUnknownResult<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1439
1559
  const parser = SchemaParser.decodeUnknownResult(schema, options)
1440
1560
  return (input: unknown, options?: SchemaAST.ParseOptions): Result_.Result<S["Type"], SchemaError> => {
1441
1561
  return Result_.mapError(parser(input, options), (issue) => new SchemaError(issue))
@@ -1470,7 +1590,7 @@ export function decodeUnknownResult<S extends Decoder<unknown>>(schema: S, optio
1470
1590
  * @category decoding
1471
1591
  * @since 4.0.0
1472
1592
  */
1473
- export const decodeResult: <S extends Decoder<unknown>>(
1593
+ export const decodeResult: <S extends ConstraintDecoder<unknown>>(
1474
1594
  schema: S,
1475
1595
  options?: SchemaAST.ParseOptions
1476
1596
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Result_.Result<S["Type"], SchemaError> =
@@ -1503,7 +1623,10 @@ export const decodeResult: <S extends Decoder<unknown>>(
1503
1623
  * @category decoding
1504
1624
  * @since 3.10.0
1505
1625
  */
1506
- export function decodeUnknownPromise<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1626
+ export function decodeUnknownPromise<S extends ConstraintDecoder<unknown>>(
1627
+ schema: S,
1628
+ options?: SchemaAST.ParseOptions
1629
+ ) {
1507
1630
  const parser = decodeUnknownEffect(schema, options)
1508
1631
  return (input: unknown, options?: SchemaAST.ParseOptions): Promise<S["Type"]> => {
1509
1632
  return runSchemaErrorPromise(parser(input, options))
@@ -1537,7 +1660,7 @@ export function decodeUnknownPromise<S extends Decoder<unknown>>(schema: S, opti
1537
1660
  * @category decoding
1538
1661
  * @since 3.10.0
1539
1662
  */
1540
- export const decodePromise: <S extends Decoder<unknown>>(
1663
+ export const decodePromise: <S extends ConstraintDecoder<unknown>>(
1541
1664
  schema: S,
1542
1665
  options?: SchemaAST.ParseOptions
1543
1666
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Promise<S["Type"]> = decodeUnknownPromise
@@ -1586,7 +1709,7 @@ export const decodePromise: <S extends Decoder<unknown>>(
1586
1709
  * @category decoding
1587
1710
  * @since 4.0.0
1588
1711
  */
1589
- export function decodeUnknownSync<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1712
+ export function decodeUnknownSync<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1590
1713
  const parser = decodeUnknownEffect(schema, options)
1591
1714
  return (input: unknown, options?: SchemaAST.ParseOptions): S["Type"] => {
1592
1715
  return runSchemaErrorSync(parser(input, options))
@@ -1619,7 +1742,7 @@ export function decodeUnknownSync<S extends Decoder<unknown>>(schema: S, options
1619
1742
  * @category decoding
1620
1743
  * @since 4.0.0
1621
1744
  */
1622
- export const decodeSync: <S extends Decoder<unknown>>(
1745
+ export const decodeSync: <S extends ConstraintDecoder<unknown>>(
1623
1746
  schema: S,
1624
1747
  options?: SchemaAST.ParseOptions
1625
1748
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"] = decodeUnknownSync
@@ -1656,7 +1779,7 @@ export const decodeSync: <S extends Decoder<unknown>>(
1656
1779
  * @category encoding
1657
1780
  * @since 4.0.0
1658
1781
  */
1659
- export function encodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAST.ParseOptions) {
1782
+ export function encodeUnknownEffect<S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions) {
1660
1783
  const parser = SchemaParser.encodeUnknownEffect(schema, options)
1661
1784
  return (
1662
1785
  input: unknown,
@@ -1687,7 +1810,7 @@ export function encodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAS
1687
1810
  * @category encoding
1688
1811
  * @since 4.0.0
1689
1812
  */
1690
- export const encodeEffect: <S extends Top>(
1813
+ export const encodeEffect: <S extends Constraint>(
1691
1814
  schema: S,
1692
1815
  options?: SchemaAST.ParseOptions
1693
1816
  ) => (
@@ -1724,7 +1847,7 @@ export const encodeEffect: <S extends Top>(
1724
1847
  * @category encoding
1725
1848
  * @since 4.0.0
1726
1849
  */
1727
- export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1850
+ export function encodeUnknownExit<S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1728
1851
  const parser = SchemaParser.encodeUnknownExit(schema, options)
1729
1852
  return (input: unknown, options?: SchemaAST.ParseOptions): Exit_.Exit<S["Encoded"], SchemaError> => {
1730
1853
  return InternalSchema.mapSchemaIssueExit(parser(input, options))
@@ -1761,7 +1884,7 @@ export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options
1761
1884
  * @category encoding
1762
1885
  * @since 4.0.0
1763
1886
  */
1764
- export const encodeExit: <S extends Encoder<unknown>>(
1887
+ export const encodeExit: <S extends ConstraintEncoder<unknown>>(
1765
1888
  schema: S,
1766
1889
  options?: SchemaAST.ParseOptions
1767
1890
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError> = encodeUnknownExit
@@ -1792,7 +1915,7 @@ export const encodeExit: <S extends Encoder<unknown>>(
1792
1915
  * @category encoding
1793
1916
  * @since 3.10.0
1794
1917
  */
1795
- export const encodeUnknownOption: <S extends Encoder<unknown>>(
1918
+ export const encodeUnknownOption: <S extends ConstraintEncoder<unknown>>(
1796
1919
  schema: S,
1797
1920
  options?: SchemaAST.ParseOptions
1798
1921
  ) => (input: unknown, options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]> =
@@ -1823,10 +1946,10 @@ export const encodeUnknownOption: <S extends Encoder<unknown>>(
1823
1946
  * @category encoding
1824
1947
  * @since 3.10.0
1825
1948
  */
1826
- export const encodeOption: <S extends Encoder<unknown>>(
1949
+ export const encodeOption: <S extends ConstraintEncoder<unknown>>(
1827
1950
  schema: S,
1828
1951
  options?: SchemaAST.ParseOptions
1829
- ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]> = encodeUnknownOption
1952
+ ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]> = SchemaParser.encodeOption
1830
1953
 
1831
1954
  /**
1832
1955
  * Encodes an `unknown` input against a schema, returning a `Result` that
@@ -1856,7 +1979,7 @@ export const encodeOption: <S extends Encoder<unknown>>(
1856
1979
  * @category encoding
1857
1980
  * @since 4.0.0
1858
1981
  */
1859
- export function encodeUnknownResult<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1982
+ export function encodeUnknownResult<S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1860
1983
  const parser = SchemaParser.encodeUnknownResult(schema, options)
1861
1984
  return (input: unknown, options?: SchemaAST.ParseOptions): Result_.Result<S["Encoded"], SchemaError> => {
1862
1985
  return Result_.mapError(parser(input, options), (issue) => new SchemaError(issue))
@@ -1891,7 +2014,7 @@ export function encodeUnknownResult<S extends Encoder<unknown>>(schema: S, optio
1891
2014
  * @category encoding
1892
2015
  * @since 4.0.0
1893
2016
  */
1894
- export const encodeResult: <S extends Encoder<unknown>>(
2017
+ export const encodeResult: <S extends ConstraintEncoder<unknown>>(
1895
2018
  schema: S,
1896
2019
  options?: SchemaAST.ParseOptions
1897
2020
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Result_.Result<S["Encoded"], SchemaError> =
@@ -1923,7 +2046,10 @@ export const encodeResult: <S extends Encoder<unknown>>(
1923
2046
  * @category encoding
1924
2047
  * @since 3.10.0
1925
2048
  */
1926
- export function encodeUnknownPromise<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
2049
+ export function encodeUnknownPromise<S extends ConstraintEncoder<unknown>>(
2050
+ schema: S,
2051
+ options?: SchemaAST.ParseOptions
2052
+ ) {
1927
2053
  const parser = encodeUnknownEffect(schema, options)
1928
2054
  return (input: unknown, options?: SchemaAST.ParseOptions): Promise<S["Encoded"]> => {
1929
2055
  return runSchemaErrorPromise(parser(input, options))
@@ -1957,7 +2083,7 @@ export function encodeUnknownPromise<S extends Encoder<unknown>>(schema: S, opti
1957
2083
  * @category encoding
1958
2084
  * @since 3.10.0
1959
2085
  */
1960
- export const encodePromise: <S extends Encoder<unknown>>(
2086
+ export const encodePromise: <S extends ConstraintEncoder<unknown>>(
1961
2087
  schema: S,
1962
2088
  options?: SchemaAST.ParseOptions
1963
2089
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]> = encodeUnknownPromise
@@ -1988,7 +2114,7 @@ export const encodePromise: <S extends Encoder<unknown>>(
1988
2114
  * @category encoding
1989
2115
  * @since 4.0.0
1990
2116
  */
1991
- export function encodeUnknownSync<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
2117
+ export function encodeUnknownSync<S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
1992
2118
  const parser = encodeUnknownEffect(schema, options)
1993
2119
  return (input: unknown, options?: SchemaAST.ParseOptions): S["Encoded"] => {
1994
2120
  return runSchemaErrorSync(parser(input, options) as Effect.Effect<S["Encoded"], SchemaError>)
@@ -2019,7 +2145,7 @@ export function encodeUnknownSync<S extends Encoder<unknown>>(schema: S, options
2019
2145
  * @category encoding
2020
2146
  * @since 4.0.0
2021
2147
  */
2022
- export const encodeSync: <S extends Encoder<unknown>>(
2148
+ export const encodeSync: <S extends ConstraintEncoder<unknown>>(
2023
2149
  schema: S,
2024
2150
  options?: SchemaAST.ParseOptions
2025
2151
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"] = encodeUnknownSync
@@ -2041,7 +2167,7 @@ export const encodeSync: <S extends Encoder<unknown>>(
2041
2167
  * @category constructors
2042
2168
  * @since 3.10.0
2043
2169
  */
2044
- export const make: <S extends Top>(ast: S["ast"], options?: object) => S = InternalSchema.make
2170
+ export const make: <S extends Constraint>(ast: S["ast"], options?: object) => S = InternalSchema.make
2045
2171
 
2046
2172
  /**
2047
2173
  * Transforms a schema into a class that can be extended with `extends`. The
@@ -2086,18 +2212,11 @@ export function isSchema(u: unknown): u is Top {
2086
2212
  * @category models
2087
2213
  * @since 4.0.0
2088
2214
  */
2089
- export interface optionalKey<S extends Top> extends
2090
- Bottom<
2091
- S["Type"],
2092
- S["Encoded"],
2093
- S["DecodingServices"],
2094
- S["EncodingServices"],
2215
+ export interface optionalKey<S extends Constraint> extends
2216
+ BottomLazy<
2095
2217
  S["ast"],
2096
2218
  optionalKey<S>,
2097
- S["~type.make.in"],
2098
- S["Iso"],
2099
2219
  S["~type.parameters"],
2100
- S["~type.make"],
2101
2220
  S["~type.mutability"],
2102
2221
  "optional",
2103
2222
  S["~type.constructor.default"],
@@ -2105,12 +2224,19 @@ export interface optionalKey<S extends Top> extends
2105
2224
  "optional"
2106
2225
  >
2107
2226
  {
2227
+ readonly "Type": S["Type"]
2228
+ readonly "Encoded": S["Encoded"]
2229
+ readonly "DecodingServices": S["DecodingServices"]
2230
+ readonly "EncodingServices": S["EncodingServices"]
2231
+ readonly "~type.make.in": S["~type.make.in"]
2232
+ readonly "~type.make": S["~type.make"]
2233
+ readonly "Iso": S["Iso"]
2108
2234
  readonly schema: S
2109
2235
  }
2110
2236
 
2111
2237
  interface optionalKeyLambda extends Lambda {
2112
- <S extends Top>(self: S): optionalKey<S>
2113
- readonly "~lambda.out": this["~lambda.in"] extends Top ? optionalKey<this["~lambda.in"]> : never
2238
+ <S extends Constraint>(self: S): optionalKey<S>
2239
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? optionalKey<this["~lambda.in"]> : never
2114
2240
  }
2115
2241
 
2116
2242
  /**
@@ -2140,8 +2266,8 @@ export const optionalKey = Struct_.lambda<optionalKeyLambda>((schema) =>
2140
2266
  )
2141
2267
 
2142
2268
  interface requiredKeyLambda extends Lambda {
2143
- <S extends Top>(self: optionalKey<S>): S
2144
- readonly "~lambda.out": this["~lambda.in"] extends optionalKey<Top> ? this["~lambda.in"]["schema"]
2269
+ <S extends Constraint>(self: optionalKey<S>): S
2270
+ readonly "~lambda.out": this["~lambda.in"] extends optionalKey<Constraint> ? this["~lambda.in"]["schema"]
2145
2271
  : "Error: schema not eligible for requiredKey"
2146
2272
  }
2147
2273
 
@@ -2164,13 +2290,13 @@ export const requiredKey = Struct_.lambda<requiredKeyLambda>((self) => self.sche
2164
2290
  * @category models
2165
2291
  * @since 3.10.0
2166
2292
  */
2167
- export interface optional<S extends Top> extends optionalKey<UndefinedOr<S>> {
2293
+ export interface optional<S extends Constraint> extends optionalKey<UndefinedOr<S>> {
2168
2294
  readonly "Rebuild": optional<S>
2169
2295
  }
2170
2296
 
2171
2297
  interface optionalLambda extends Lambda {
2172
- <S extends Top>(self: S): optional<S>
2173
- readonly "~lambda.out": this["~lambda.in"] extends Top ? optional<this["~lambda.in"]> : never
2298
+ <S extends Constraint>(self: S): optional<S>
2299
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? optional<this["~lambda.in"]> : never
2174
2300
  }
2175
2301
 
2176
2302
  /**
@@ -2205,8 +2331,8 @@ interface optionalLambda extends Lambda {
2205
2331
  export const optional = Struct_.lambda<optionalLambda>((self) => optionalKey(UndefinedOr(self)))
2206
2332
 
2207
2333
  interface requiredLambda extends Lambda {
2208
- <S extends Top>(self: optional<S>): S
2209
- readonly "~lambda.out": this["~lambda.in"] extends optional<Top> ? this["~lambda.in"]["schema"]["members"][0]
2334
+ <S extends Constraint>(self: optional<S>): S
2335
+ readonly "~lambda.out": this["~lambda.in"] extends optional<Constraint> ? this["~lambda.in"]["schema"]["members"][0]
2210
2336
  : "Error: schema not eligible for required"
2211
2337
  }
2212
2338
 
@@ -2233,18 +2359,11 @@ export const required = Struct_.lambda<requiredLambda>((self) => self.schema.mem
2233
2359
  * @category models
2234
2360
  * @since 4.0.0
2235
2361
  */
2236
- export interface mutableKey<S extends Top> extends
2237
- Bottom<
2238
- S["Type"],
2239
- S["Encoded"],
2240
- S["DecodingServices"],
2241
- S["EncodingServices"],
2362
+ export interface mutableKey<S extends Constraint> extends
2363
+ BottomLazy<
2242
2364
  S["ast"],
2243
2365
  mutableKey<S>,
2244
- S["~type.make.in"],
2245
- S["Iso"],
2246
2366
  S["~type.parameters"],
2247
- S["~type.make"],
2248
2367
  "mutable",
2249
2368
  S["~type.optionality"],
2250
2369
  S["~type.constructor.default"],
@@ -2252,12 +2371,19 @@ export interface mutableKey<S extends Top> extends
2252
2371
  S["~encoded.optionality"]
2253
2372
  >
2254
2373
  {
2374
+ readonly "Type": S["Type"]
2375
+ readonly "Encoded": S["Encoded"]
2376
+ readonly "DecodingServices": S["DecodingServices"]
2377
+ readonly "EncodingServices": S["EncodingServices"]
2378
+ readonly "~type.make.in": S["~type.make.in"]
2379
+ readonly "~type.make": S["~type.make"]
2380
+ readonly "Iso": S["Iso"]
2255
2381
  readonly schema: S
2256
2382
  }
2257
2383
 
2258
2384
  interface mutableKeyLambda extends Lambda {
2259
- <S extends Top>(self: S): mutableKey<S>
2260
- readonly "~lambda.out": this["~lambda.in"] extends Top ? mutableKey<this["~lambda.in"]> : never
2385
+ <S extends Constraint>(self: S): mutableKey<S>
2386
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? mutableKey<this["~lambda.in"]> : never
2261
2387
  }
2262
2388
 
2263
2389
  /**
@@ -2272,8 +2398,8 @@ export const mutableKey = Struct_.lambda<mutableKeyLambda>((schema) =>
2272
2398
  )
2273
2399
 
2274
2400
  interface readonlyKeyLambda extends Lambda {
2275
- <S extends Top>(self: mutableKey<S>): S
2276
- readonly "~lambda.out": this["~lambda.in"] extends mutableKey<Top> ? this["~lambda.in"]["schema"]
2401
+ <S extends Constraint>(self: mutableKey<S>): S
2402
+ readonly "~lambda.out": this["~lambda.in"] extends mutableKey<Constraint> ? this["~lambda.in"]["schema"]
2277
2403
  : "Error: schema not eligible for readonlyKey"
2278
2404
  }
2279
2405
 
@@ -2296,29 +2422,31 @@ export const readonlyKey = Struct_.lambda<readonlyKeyLambda>((self) => self.sche
2296
2422
  * @category transforming
2297
2423
  * @since 4.0.0
2298
2424
  */
2299
- export interface toType<S extends Top> extends
2300
- Bottom<
2301
- S["Type"],
2302
- S["Type"],
2303
- never,
2304
- never,
2425
+ export interface toType<S extends Constraint> extends
2426
+ BottomLazy<
2305
2427
  S["ast"],
2306
2428
  toType<S>,
2307
- S["~type.make.in"],
2308
- S["Iso"],
2309
2429
  S["~type.parameters"],
2310
- S["~type.make"],
2311
2430
  S["~type.mutability"],
2312
2431
  S["~type.optionality"],
2313
2432
  S["~type.constructor.default"],
2314
2433
  S["~encoded.mutability"],
2315
2434
  S["~encoded.optionality"]
2316
2435
  >
2317
- {}
2436
+ {
2437
+ readonly "Type": S["Type"]
2438
+ readonly "Encoded": S["Type"]
2439
+ readonly "DecodingServices": never
2440
+ readonly "EncodingServices": never
2441
+ readonly "~type.make.in": S["~type.make.in"]
2442
+ readonly "~type.make": S["~type.make"]
2443
+ readonly "Iso": S["Iso"]
2444
+ readonly schema: S
2445
+ }
2318
2446
 
2319
2447
  interface toTypeLambda extends Lambda {
2320
- <S extends Top>(self: S): toType<S>
2321
- readonly "~lambda.out": this["~lambda.in"] extends Top ? toType<this["~lambda.in"]> : never
2448
+ <S extends Constraint>(self: S): toType<S>
2449
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? toType<this["~lambda.in"]> : never
2322
2450
  }
2323
2451
 
2324
2452
  /**
@@ -2336,29 +2464,31 @@ export const toType = Struct_.lambda<toTypeLambda>((schema) => make(SchemaAST.to
2336
2464
  * @category transforming
2337
2465
  * @since 4.0.0
2338
2466
  */
2339
- export interface toEncoded<S extends Top> extends
2340
- Bottom<
2341
- S["Encoded"],
2342
- S["Encoded"],
2343
- never,
2344
- never,
2467
+ export interface toEncoded<S extends Constraint> extends
2468
+ BottomLazy<
2345
2469
  SchemaAST.AST,
2346
2470
  toEncoded<S>,
2347
- S["Encoded"],
2348
- S["Encoded"],
2349
- ReadonlyArray<Top>,
2350
- S["Encoded"],
2471
+ ReadonlyArray<Constraint>,
2351
2472
  S["~type.mutability"],
2352
2473
  S["~type.optionality"],
2353
2474
  S["~type.constructor.default"],
2354
2475
  S["~encoded.mutability"],
2355
2476
  S["~encoded.optionality"]
2356
2477
  >
2357
- {}
2478
+ {
2479
+ readonly "Type": S["Encoded"]
2480
+ readonly "Encoded": S["Encoded"]
2481
+ readonly "DecodingServices": never
2482
+ readonly "EncodingServices": never
2483
+ readonly "~type.make.in": S["Encoded"]
2484
+ readonly "~type.make": S["Encoded"]
2485
+ readonly "Iso": S["Encoded"]
2486
+ readonly schema: S
2487
+ }
2358
2488
 
2359
2489
  interface toEncodedLambda extends Lambda {
2360
- <S extends Top>(self: S): toEncoded<S>
2361
- readonly "~lambda.out": this["~lambda.in"] extends Top ? toEncoded<this["~lambda.in"]> : never
2490
+ <S extends Constraint>(self: S): toEncoded<S>
2491
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? toEncoded<this["~lambda.in"]> : never
2362
2492
  }
2363
2493
 
2364
2494
  /**
@@ -2379,17 +2509,10 @@ const FlipTypeId = "~effect/Schema/flip"
2379
2509
  * @since 4.0.0
2380
2510
  */
2381
2511
  export interface flip<S extends Top> extends
2382
- Bottom<
2383
- S["Encoded"],
2384
- S["Type"],
2385
- S["EncodingServices"],
2386
- S["DecodingServices"],
2512
+ BottomLazy<
2387
2513
  SchemaAST.AST,
2388
2514
  flip<S>,
2389
- S["Encoded"],
2390
- S["Encoded"],
2391
- ReadonlyArray<Top>,
2392
- S["Encoded"],
2515
+ ReadonlyArray<Constraint>,
2393
2516
  S["~encoded.mutability"],
2394
2517
  S["~encoded.optionality"],
2395
2518
  ConstructorDefault,
@@ -2397,6 +2520,13 @@ export interface flip<S extends Top> extends
2397
2520
  S["~type.optionality"]
2398
2521
  >
2399
2522
  {
2523
+ readonly "Type": S["Encoded"]
2524
+ readonly "Encoded": S["Type"]
2525
+ readonly "DecodingServices": S["EncodingServices"]
2526
+ readonly "EncodingServices": S["DecodingServices"]
2527
+ readonly "~type.make.in": S["Encoded"]
2528
+ readonly "~type.make": S["Encoded"]
2529
+ readonly "Iso": S["Encoded"]
2400
2530
  readonly [FlipTypeId]: typeof FlipTypeId
2401
2531
  readonly schema: S
2402
2532
  }
@@ -2498,7 +2628,7 @@ export declare namespace TemplateLiteral {
2498
2628
  * @category utility types
2499
2629
  * @since 4.0.0
2500
2630
  */
2501
- export interface SchemaPart extends Top {
2631
+ export interface SchemaPart extends Constraint {
2502
2632
  readonly Encoded: string | number | bigint
2503
2633
  }
2504
2634
 
@@ -2531,7 +2661,7 @@ export declare namespace TemplateLiteral {
2531
2661
  Template extends string,
2532
2662
  Next
2533
2663
  > = Next extends LiteralPart ? `${Template}${Next}`
2534
- : Next extends Codec<unknown, infer E extends LiteralPart, unknown, unknown> ? `${Template}${E}`
2664
+ : Next extends { readonly Encoded: infer E extends LiteralPart } ? `${Template}${E}`
2535
2665
  : never
2536
2666
 
2537
2667
  /**
@@ -2565,7 +2695,9 @@ export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends
2565
2695
  }
2566
2696
 
2567
2697
  function templateLiteralFromParts<Parts extends TemplateLiteral.Parts>(parts: Parts) {
2568
- return new SchemaAST.TemplateLiteral(parts.map((part) => isSchema(part) ? part.ast : new SchemaAST.Literal(part)))
2698
+ return new SchemaAST.TemplateLiteral(
2699
+ parts.map((part) => isSchema(part) ? part.ast : new SchemaAST.Literal(part as TemplateLiteral.LiteralPart))
2700
+ )
2569
2701
  }
2570
2702
 
2571
2703
  /**
@@ -2633,15 +2765,18 @@ export declare namespace TemplateLiteralParser {
2633
2765
  * @since 3.10.0
2634
2766
  */
2635
2767
  export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> extends
2636
- Bottom<
2637
- TemplateLiteralParser.Type<Parts>,
2638
- TemplateLiteral.Encoded<Parts>,
2639
- never,
2640
- never,
2768
+ BottomLazy<
2641
2769
  SchemaAST.Arrays,
2642
2770
  TemplateLiteralParser<Parts>
2643
2771
  >
2644
2772
  {
2773
+ readonly "Type": TemplateLiteralParser.Type<Parts>
2774
+ readonly "Encoded": TemplateLiteral.Encoded<Parts>
2775
+ readonly "DecodingServices": never
2776
+ readonly "EncodingServices": never
2777
+ readonly "~type.make.in": TemplateLiteralParser.Type<Parts>
2778
+ readonly "~type.make": TemplateLiteralParser.Type<Parts>
2779
+ readonly "Iso": TemplateLiteralParser.Type<Parts>
2645
2780
  readonly parts: Parts
2646
2781
  }
2647
2782
 
@@ -2999,7 +3134,7 @@ export declare namespace Struct {
2999
3134
  * @category utility types
3000
3135
  * @since 3.10.0
3001
3136
  */
3002
- export type Fields = { readonly [x: PropertyKey]: Top }
3137
+ export type Fields = { readonly [x: PropertyKey]: Constraint }
3003
3138
 
3004
3139
  type TypeOptionalKeys<Fields extends Struct.Fields> = {
3005
3140
  [K in keyof Fields]: Fields[K] extends { readonly "~type.optionality": "optional" } ? K
@@ -3011,15 +3146,46 @@ export declare namespace Struct {
3011
3146
  : never
3012
3147
  }[keyof Fields]
3013
3148
 
3014
- type Type_<
3149
+ type SetOptional<A, K extends keyof A> = Omit<A, K> & Partial<Pick<A, K>>
3150
+
3151
+ type Mutable<A> = { -readonly [K in keyof A]: A[K] }
3152
+
3153
+ type SetMutable<A, K extends keyof A> = Omit<A, K> & Mutable<Pick<A, K>>
3154
+
3155
+ type Side = "Type" | "Iso" | "Encoded"
3156
+
3157
+ type EncodedOptionalKeys<Fields extends Struct.Fields> = {
3158
+ [K in keyof Fields]: Fields[K] extends { readonly "~encoded.optionality": "optional" } ? K
3159
+ : never
3160
+ }[keyof Fields]
3161
+
3162
+ type EncodedMutableKeys<Fields extends Struct.Fields> = {
3163
+ [K in keyof Fields]: Fields[K] extends { readonly "~encoded.mutability": "mutable" } ? K
3164
+ : never
3165
+ }[keyof Fields]
3166
+
3167
+ type SideOptionalKeys<F extends Fields, S extends Side> = S extends "Encoded" ? EncodedOptionalKeys<F>
3168
+ : TypeOptionalKeys<F>
3169
+
3170
+ type SideMutableKeys<F extends Fields, S extends Side> = S extends "Encoded" ? EncodedMutableKeys<F>
3171
+ : TypeMutableKeys<F>
3172
+
3173
+ type ReadonlySide<F extends Fields, S extends Side> = { readonly [K in keyof F]: F[K][S] }
3174
+
3175
+ type View<
3015
3176
  F extends Fields,
3016
- O extends keyof F = TypeOptionalKeys<F>,
3017
- M extends keyof F = TypeMutableKeys<F>
3018
- > =
3019
- & { readonly [K in keyof F as K extends M | O ? never : K]: F[K]["Type"] }
3020
- & { readonly [K in keyof F as K extends O ? K extends M ? never : K : never]?: F[K]["Type"] }
3021
- & { -readonly [K in keyof F as K extends M ? K extends O ? never : K : never]: F[K]["Type"] }
3022
- & { -readonly [K in keyof F as K extends M & O ? K : never]?: F[K]["Type"] }
3177
+ S extends Side,
3178
+ O extends keyof F = SideOptionalKeys<F, S>,
3179
+ M extends keyof F = SideMutableKeys<F, S>
3180
+ > = [O | M] extends [never] ? ReadonlySide<F, S>
3181
+ : [M] extends [never] ? Simplify<SetOptional<ReadonlySide<F, S>, O>>
3182
+ : [O] extends [never] ? Simplify<SetMutable<ReadonlySide<F, S>, M>>
3183
+ : Simplify<
3184
+ SetMutable<
3185
+ SetOptional<ReadonlySide<F, S>, O>,
3186
+ Extract<keyof SetOptional<ReadonlySide<F, S>, O>, M>
3187
+ >
3188
+ >
3023
3189
 
3024
3190
  /**
3025
3191
  * Computes the decoded object type for a struct field map.
@@ -3032,17 +3198,7 @@ export declare namespace Struct {
3032
3198
  * @category utility types
3033
3199
  * @since 3.10.0
3034
3200
  */
3035
- export type Type<F extends Fields> = Simplify<Type_<F>>
3036
-
3037
- type Iso_<
3038
- F extends Fields,
3039
- O extends keyof F = TypeOptionalKeys<F>,
3040
- M extends keyof F = TypeMutableKeys<F>
3041
- > =
3042
- & { readonly [K in keyof F as K extends M | O ? never : K]: F[K]["Iso"] }
3043
- & { readonly [K in keyof F as K extends O ? K extends M ? never : K : never]?: F[K]["Iso"] }
3044
- & { -readonly [K in keyof F as K extends M ? K extends O ? never : K : never]: F[K]["Iso"] }
3045
- & { -readonly [K in keyof F as K extends M & O ? K : never]?: F[K]["Iso"] }
3201
+ export type Type<F extends Fields> = View<F, "Type">
3046
3202
 
3047
3203
  /**
3048
3204
  * Computes the iso object type for a struct field map from each field schema's
@@ -3056,27 +3212,7 @@ export declare namespace Struct {
3056
3212
  * @category utility types
3057
3213
  * @since 4.0.0
3058
3214
  */
3059
- export type Iso<F extends Fields> = Simplify<Iso_<F>>
3060
-
3061
- type EncodedOptionalKeys<Fields extends Struct.Fields> = {
3062
- [K in keyof Fields]: Fields[K] extends { readonly "~encoded.optionality": "optional" } ? K
3063
- : never
3064
- }[keyof Fields]
3065
-
3066
- type EncodedMutableKeys<Fields extends Struct.Fields> = {
3067
- [K in keyof Fields]: Fields[K] extends { readonly "~encoded.mutability": "mutable" } ? K
3068
- : never
3069
- }[keyof Fields]
3070
-
3071
- type Encoded_<
3072
- F extends Fields,
3073
- O extends keyof F = EncodedOptionalKeys<F>,
3074
- M extends keyof F = EncodedMutableKeys<F>
3075
- > =
3076
- & { readonly [K in keyof F as K extends M | O ? never : K]: F[K]["Encoded"] }
3077
- & { readonly [K in keyof F as K extends O ? K extends M ? never : K : never]?: F[K]["Encoded"] }
3078
- & { -readonly [K in keyof F as K extends M ? K extends O ? never : K : never]: F[K]["Encoded"] }
3079
- & { -readonly [K in keyof F as K extends M & O ? K : never]?: F[K]["Encoded"] }
3215
+ export type Iso<F extends Fields> = View<F, "Iso">
3080
3216
 
3081
3217
  /**
3082
3218
  * Computes the encoded object type for a struct field map.
@@ -3090,7 +3226,7 @@ export declare namespace Struct {
3090
3226
  * @category utility types
3091
3227
  * @since 3.10.0
3092
3228
  */
3093
- export type Encoded<F extends Fields> = Simplify<Encoded_<F>>
3229
+ export type Encoded<F extends Fields> = View<F, "Encoded">
3094
3230
 
3095
3231
  /**
3096
3232
  * Union of all decoding service requirements needed by the schemas in a struct
@@ -3115,12 +3251,12 @@ export declare namespace Struct {
3115
3251
  : never
3116
3252
  }[keyof Fields]
3117
3253
 
3118
- type MakeIn_<
3254
+ type ReadonlyMakeIn<F extends Fields> = { readonly [K in keyof F]: F[K]["~type.make"] }
3255
+
3256
+ type MakeInView<
3119
3257
  F extends Fields,
3120
- O = TypeOptionalKeys<F> | TypeConstructorDefaultedKeys<F>
3121
- > =
3122
- & { readonly [K in keyof F as K extends O ? never : K]: F[K]["~type.make"] }
3123
- & { readonly [K in keyof F as K extends O ? K : never]?: F[K]["~type.make"] }
3258
+ O extends keyof F = TypeOptionalKeys<F> | TypeConstructorDefaultedKeys<F>
3259
+ > = [O] extends [never] ? ReadonlyMakeIn<F> : Simplify<SetOptional<ReadonlyMakeIn<F>, O>>
3124
3260
 
3125
3261
  /**
3126
3262
  * Computes the input object type accepted when constructing a struct value.
@@ -3133,7 +3269,7 @@ export declare namespace Struct {
3133
3269
  * @category utility types
3134
3270
  * @since 4.0.0
3135
3271
  */
3136
- export type MakeIn<F extends Fields> = Simplify<MakeIn_<F>>
3272
+ export type MakeIn<F extends Fields> = MakeInView<F>
3137
3273
  }
3138
3274
 
3139
3275
  /**
@@ -3142,18 +3278,14 @@ export declare namespace Struct {
3142
3278
  * @category models
3143
3279
  * @since 3.10.0
3144
3280
  */
3145
- export interface Struct<Fields extends Struct.Fields> extends
3146
- Bottom<
3147
- Struct.Type<Fields>,
3148
- Struct.Encoded<Fields>,
3149
- Struct.DecodingServices<Fields>,
3150
- Struct.EncodingServices<Fields>,
3151
- SchemaAST.Objects,
3152
- Struct<Fields>,
3153
- Struct.MakeIn<Fields>,
3154
- Struct.Iso<Fields>
3155
- >
3156
- {
3281
+ export interface Struct<Fields extends Struct.Fields> extends BottomLazy<SchemaAST.Objects, Struct<Fields>> {
3282
+ readonly "Type": Struct.Type<Fields>
3283
+ readonly "Encoded": Struct.Encoded<Fields>
3284
+ readonly "DecodingServices": Struct.DecodingServices<Fields>
3285
+ readonly "EncodingServices": Struct.EncodingServices<Fields>
3286
+ readonly "~type.make.in": Struct.MakeIn<Fields>
3287
+ readonly "~type.make": Struct.MakeIn<Fields>
3288
+ readonly "Iso": Struct.Iso<Fields>
3157
3289
  /**
3158
3290
  * The field definitions of this struct. Spread them into a new struct to
3159
3291
  * reuse fields across schemas.
@@ -3300,7 +3432,7 @@ export function fieldsAssign<const NewFields extends Struct.Fields>(fields: NewF
3300
3432
  * @since 4.0.0
3301
3433
  */
3302
3434
  export interface encodeKeys<
3303
- S extends Top & { readonly fields: Struct.Fields },
3435
+ S extends Constraint & { readonly fields: Struct.Fields },
3304
3436
  M extends { readonly [K in keyof S["fields"]]?: PropertyKey }
3305
3437
  > extends
3306
3438
  decodeTo<
@@ -3347,7 +3479,7 @@ const canonicalPropertyKey = (key: PropertyKey): string | symbol =>
3347
3479
  * @since 4.0.0
3348
3480
  */
3349
3481
  export function encodeKeys<
3350
- S extends Top & { readonly fields: Struct.Fields },
3482
+ S extends Constraint & { readonly fields: Struct.Fields },
3351
3483
  const M extends { readonly [K in keyof S["fields"]]?: PropertyKey }
3352
3484
  >(mapping: M) {
3353
3485
  return function(self: S): encodeKeys<S, M> {
@@ -3489,7 +3621,7 @@ export declare namespace Record {
3489
3621
  * @category utility types
3490
3622
  * @since 3.10.0
3491
3623
  */
3492
- export type Type<Key extends Record.Key, Value extends Top> = Value extends
3624
+ export type Type<Key extends Record.Key, Value extends Constraint> = Value extends
3493
3625
  { readonly "~type.optionality": "optional" } ?
3494
3626
  Value extends { readonly "~type.mutability": "mutable" } ? { [P in Key["Type"]]?: Value["Type"] }
3495
3627
  : { readonly [P in Key["Type"]]?: Value["Type"] }
@@ -3503,7 +3635,7 @@ export declare namespace Record {
3503
3635
  * @category utility types
3504
3636
  * @since 4.0.0
3505
3637
  */
3506
- export type Iso<Key extends Record.Key, Value extends Top> = Value extends
3638
+ export type Iso<Key extends Record.Key, Value extends Constraint> = Value extends
3507
3639
  { readonly "~type.optionality": "optional" } ?
3508
3640
  Value extends { readonly "~type.mutability": "mutable" } ? { [P in Key["Iso"]]?: Value["Iso"] }
3509
3641
  : { readonly [P in Key["Iso"]]?: Value["Iso"] }
@@ -3522,7 +3654,7 @@ export declare namespace Record {
3522
3654
  * @category utility types
3523
3655
  * @since 3.10.0
3524
3656
  */
3525
- export type Encoded<Key extends Record.Key, Value extends Top> = Value extends
3657
+ export type Encoded<Key extends Record.Key, Value extends Constraint> = Value extends
3526
3658
  { readonly "~encoded.optionality": "optional" } ?
3527
3659
  Value extends { readonly "~encoded.mutability": "mutable" } ? { [P in Key["Encoded"]]?: Value["Encoded"] }
3528
3660
  : { readonly [P in Key["Encoded"]]?: Value["Encoded"] }
@@ -3536,7 +3668,7 @@ export declare namespace Record {
3536
3668
  * @category utility types
3537
3669
  * @since 4.0.0
3538
3670
  */
3539
- export type DecodingServices<Key extends Record.Key, Value extends Top> =
3671
+ export type DecodingServices<Key extends Record.Key, Value extends Constraint> =
3540
3672
  | Key["DecodingServices"]
3541
3673
  | Value["DecodingServices"]
3542
3674
 
@@ -3547,7 +3679,7 @@ export declare namespace Record {
3547
3679
  * @category utility types
3548
3680
  * @since 4.0.0
3549
3681
  */
3550
- export type EncodingServices<Key extends Record.Key, Value extends Top> =
3682
+ export type EncodingServices<Key extends Record.Key, Value extends Constraint> =
3551
3683
  | Key["EncodingServices"]
3552
3684
  | Value["EncodingServices"]
3553
3685
 
@@ -3563,7 +3695,7 @@ export declare namespace Record {
3563
3695
  * @category utility types
3564
3696
  * @since 4.0.0
3565
3697
  */
3566
- export type MakeIn<Key extends Record.Key, Value extends Top> = Value extends
3698
+ export type MakeIn<Key extends Record.Key, Value extends Constraint> = Value extends
3567
3699
  { readonly "~encoded.optionality": "optional" } ?
3568
3700
  Value extends { readonly "~encoded.mutability": "mutable" } ? { [P in Key["~type.make"]]?: Value["~type.make"] }
3569
3701
  : { readonly [P in Key["~type.make"]]?: Value["~type.make"] }
@@ -3577,18 +3709,19 @@ export declare namespace Record {
3577
3709
  * @category models
3578
3710
  * @since 4.0.0
3579
3711
  */
3580
- export interface $Record<Key extends Record.Key, Value extends Top> extends
3581
- Bottom<
3582
- Record.Type<Key, Value>,
3583
- Record.Encoded<Key, Value>,
3584
- Record.DecodingServices<Key, Value>,
3585
- Record.EncodingServices<Key, Value>,
3712
+ export interface $Record<Key extends Record.Key, Value extends Constraint> extends
3713
+ BottomLazy<
3586
3714
  SchemaAST.Objects,
3587
- $Record<Key, Value>,
3588
- Simplify<Record.MakeIn<Key, Value>>,
3589
- Record.Iso<Key, Value>
3715
+ $Record<Key, Value>
3590
3716
  >
3591
3717
  {
3718
+ readonly "Type": Record.Type<Key, Value>
3719
+ readonly "Encoded": Record.Encoded<Key, Value>
3720
+ readonly "DecodingServices": Record.DecodingServices<Key, Value>
3721
+ readonly "EncodingServices": Record.EncodingServices<Key, Value>
3722
+ readonly "~type.make.in": Simplify<Record.MakeIn<Key, Value>>
3723
+ readonly "~type.make": Simplify<Record.MakeIn<Key, Value>>
3724
+ readonly "Iso": Record.Iso<Key, Value>
3592
3725
  readonly key: Key
3593
3726
  readonly value: Value
3594
3727
  }
@@ -3625,7 +3758,7 @@ export interface $Record<Key extends Record.Key, Value extends Top> extends
3625
3758
  * @category constructors
3626
3759
  * @since 3.10.0
3627
3760
  */
3628
- export function Record<Key extends Record.Key, Value extends Top>(
3761
+ export function Record<Key extends Record.Key, Value extends Constraint>(
3629
3762
  key: Key,
3630
3763
  value: Value,
3631
3764
  options?: {
@@ -3659,7 +3792,7 @@ export declare namespace StructWithRest {
3659
3792
  * @category utility types
3660
3793
  * @since 4.0.0
3661
3794
  */
3662
- export type Objects = Top & { readonly ast: SchemaAST.Objects }
3795
+ export type Objects = Constraint & { readonly ast: SchemaAST.Objects }
3663
3796
 
3664
3797
  /**
3665
3798
  * Readonly list of record schemas that provide the additional index signatures
@@ -3668,7 +3801,7 @@ export declare namespace StructWithRest {
3668
3801
  * @category utility types
3669
3802
  * @since 3.10.0
3670
3803
  */
3671
- export type Records = ReadonlyArray<$Record<Record.Key, Top>>
3804
+ export type Records = ReadonlyArray<$Record<Record.Key, Constraint>>
3672
3805
 
3673
3806
  type MergeTuple<T extends ReadonlyArray<unknown>> = T extends readonly [infer Head, ...infer Tail] ?
3674
3807
  Head & MergeTuple<Tail>
@@ -3765,24 +3898,52 @@ export declare namespace StructWithRest {
3765
3898
  [I in keyof Records]: Records[I][Side] extends object ? IncompatibleKeys<S[Side], Records[I][Side]> : never
3766
3899
  }[number]
3767
3900
 
3901
+ type IncompatibleRecords<S extends Objects, Records extends StructWithRest.Records> =
3902
+ | IncompatibleSideKeys<S, Records, "Type">
3903
+ | IncompatibleSideKeys<S, Records, "Encoded">
3904
+ | IncompatibleSideKeys<S, Records, "Iso">
3905
+ | IncompatibleSideKeys<S, Records, "~type.make">
3906
+
3768
3907
  /**
3769
- * Validates that the records are compatible with the struct.
3908
+ * Checks whether fixed fields are compatible with the rest record schemas.
3909
+ *
3910
+ * **Details**
3911
+ *
3912
+ * Returns `true` when all fixed fields can also satisfy the matching rest
3913
+ * index signatures. Returns a diagnostic object when TypeScript would make
3914
+ * the resulting intersection too narrow for one or more fixed keys.
3915
+ *
3916
+ * **Example** (Checking record compatibility)
3917
+ *
3918
+ * ```ts
3919
+ * import { Schema } from "effect"
3920
+ *
3921
+ * const user = Schema.Struct({ id: Schema.String })
3922
+ * const stringExtras = [Schema.Record(Schema.String, Schema.String)] as const
3923
+ *
3924
+ * type UserCheck = Schema.StructWithRest.ValidateRecords<typeof user, typeof stringExtras>
3925
+ *
3926
+ * const userCheck: UserCheck = true
3927
+ * void userCheck
3928
+ *
3929
+ * const counter = Schema.Struct({ count: Schema.NumberFromString })
3930
+ *
3931
+ * type CounterCheck = Schema.StructWithRest.ValidateRecords<typeof counter, typeof stringExtras>
3932
+ * // ^? { "incompatible index signatures": "count" }
3933
+ *
3934
+ * const counterCheck = null as unknown as CounterCheck
3935
+ * void counterCheck
3936
+ * ```
3770
3937
  *
3771
3938
  * @category utility types
3772
3939
  * @since 4.0.0
3773
3940
  */
3774
- export type ValidateRecords<S extends Objects, Records extends StructWithRest.Records> = [
3775
- | IncompatibleSideKeys<S, Records, "Type">
3776
- | IncompatibleSideKeys<S, Records, "Encoded">
3777
- | IncompatibleSideKeys<S, Records, "Iso">
3778
- | IncompatibleSideKeys<S, Records, "~type.make">
3779
- ] extends [never] ? unknown
3941
+ export type ValidateRecords<
3942
+ S extends Objects,
3943
+ Records extends StructWithRest.Records
3944
+ > = [IncompatibleRecords<S, Records>] extends [never] ? true
3780
3945
  : {
3781
- "incompatible index signatures":
3782
- | IncompatibleSideKeys<S, Records, "Type">
3783
- | IncompatibleSideKeys<S, Records, "Encoded">
3784
- | IncompatibleSideKeys<S, Records, "Iso">
3785
- | IncompatibleSideKeys<S, Records, "~type.make">
3946
+ "incompatible index signatures": IncompatibleRecords<S, Records>
3786
3947
  }
3787
3948
  }
3788
3949
 
@@ -3796,17 +3957,18 @@ export interface StructWithRest<
3796
3957
  S extends StructWithRest.Objects,
3797
3958
  Records extends StructWithRest.Records
3798
3959
  > extends
3799
- Bottom<
3800
- Simplify<StructWithRest.Type<S, Records>>,
3801
- Simplify<StructWithRest.Encoded<S, Records>>,
3802
- StructWithRest.DecodingServices<S, Records>,
3803
- StructWithRest.EncodingServices<S, Records>,
3960
+ BottomLazy<
3804
3961
  SchemaAST.Objects,
3805
- StructWithRest<S, Records>,
3806
- Simplify<StructWithRest.MakeIn<S, Records>>,
3807
- Simplify<StructWithRest.Iso<S, Records>>
3962
+ StructWithRest<S, Records>
3808
3963
  >
3809
3964
  {
3965
+ readonly "Type": Simplify<StructWithRest.Type<S, Records>>
3966
+ readonly "Encoded": Simplify<StructWithRest.Encoded<S, Records>>
3967
+ readonly "DecodingServices": StructWithRest.DecodingServices<S, Records>
3968
+ readonly "EncodingServices": StructWithRest.EncodingServices<S, Records>
3969
+ readonly "~type.make.in": Simplify<StructWithRest.MakeIn<S, Records>>
3970
+ readonly "~type.make": Simplify<StructWithRest.MakeIn<S, Records>>
3971
+ readonly "Iso": Simplify<StructWithRest.Iso<S, Records>>
3810
3972
  readonly schema: S
3811
3973
  readonly records: Records
3812
3974
  }
@@ -3815,6 +3977,13 @@ export interface StructWithRest<
3815
3977
  * Extends a struct schema with one or more record (index-signature) schemas,
3816
3978
  * producing a schema whose decoded type intersects the struct and all records.
3817
3979
  *
3980
+ * **Gotchas**
3981
+ *
3982
+ * TypeScript index signatures also apply to fixed keys. `StructWithRest` does
3983
+ * not reject incompatible fixed fields at the call site; use
3984
+ * `StructWithRest.ValidateRecords` when you want an explicit type-level
3985
+ * compatibility check.
3986
+ *
3818
3987
  * **Example** (Defining structs with string-indexed extra keys)
3819
3988
  *
3820
3989
  * ```ts
@@ -3837,7 +4006,7 @@ export function StructWithRest<
3837
4006
  const Records extends StructWithRest.Records
3838
4007
  >(
3839
4008
  schema: S,
3840
- records: Records & StructWithRest.ValidateRecords<S, Records>
4009
+ records: Records
3841
4010
  ): StructWithRest<S, Records> {
3842
4011
  return make(SchemaAST.structWithRest(schema.ast, records.map(SchemaAST.getAST)), { schema, records })
3843
4012
  }
@@ -3862,7 +4031,7 @@ export declare namespace Tuple {
3862
4031
  * @category utility types
3863
4032
  * @since 3.10.0
3864
4033
  */
3865
- export type Elements = ReadonlyArray<Top>
4034
+ export type Elements = ReadonlyArray<Constraint>
3866
4035
 
3867
4036
  type Type_<
3868
4037
  Elements,
@@ -3980,17 +4149,18 @@ export declare namespace Tuple {
3980
4149
  * @since 3.10.0
3981
4150
  */
3982
4151
  export interface Tuple<Elements extends Tuple.Elements> extends
3983
- Bottom<
3984
- Tuple.Type<Elements>,
3985
- Tuple.Encoded<Elements>,
3986
- Tuple.DecodingServices<Elements>,
3987
- Tuple.EncodingServices<Elements>,
4152
+ BottomLazy<
3988
4153
  SchemaAST.Arrays,
3989
- Tuple<Elements>,
3990
- Tuple.MakeIn<Elements>,
3991
- Tuple.Iso<Elements>
4154
+ Tuple<Elements>
3992
4155
  >
3993
4156
  {
4157
+ readonly "Type": Tuple.Type<Elements>
4158
+ readonly "Encoded": Tuple.Encoded<Elements>
4159
+ readonly "DecodingServices": Tuple.DecodingServices<Elements>
4160
+ readonly "EncodingServices": Tuple.EncodingServices<Elements>
4161
+ readonly "~type.make.in": Tuple.MakeIn<Elements>
4162
+ readonly "~type.make": Tuple.MakeIn<Elements>
4163
+ readonly "Iso": Tuple.Iso<Elements>
3994
4164
  readonly elements: Elements
3995
4165
  /**
3996
4166
  * Returns a new tuple with the elements modified by the provided function.
@@ -4050,7 +4220,7 @@ function makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, eleme
4050
4220
  * @category constructors
4051
4221
  * @since 3.10.0
4052
4222
  */
4053
- export function Tuple<const Elements extends ReadonlyArray<Top>>(elements: Elements): Tuple<Elements> {
4223
+ export function Tuple<const Elements extends ReadonlyArray<Constraint>>(elements: Elements): Tuple<Elements> {
4054
4224
  return makeTuple(SchemaAST.tuple(elements), elements)
4055
4225
  }
4056
4226
 
@@ -4074,7 +4244,7 @@ export declare namespace TupleWithRest {
4074
4244
  * @category utility types
4075
4245
  * @since 3.10.0
4076
4246
  */
4077
- export type TupleType = Top & {
4247
+ export type TupleType = Constraint & {
4078
4248
  readonly Type: ReadonlyArray<unknown>
4079
4249
  readonly Encoded: ReadonlyArray<unknown>
4080
4250
  readonly ast: SchemaAST.Arrays
@@ -4093,7 +4263,7 @@ export declare namespace TupleWithRest {
4093
4263
  * @category utility types
4094
4264
  * @since 3.10.0
4095
4265
  */
4096
- export type Rest = readonly [Top, ...Array<Top>]
4266
+ export type Rest = readonly [Constraint, ...Array<Constraint>]
4097
4267
 
4098
4268
  /**
4099
4269
  * Computes the decoded tuple type for a `TupleWithRest`.
@@ -4108,7 +4278,7 @@ export declare namespace TupleWithRest {
4108
4278
  * @since 3.10.0
4109
4279
  */
4110
4280
  export type Type<T extends ReadonlyArray<unknown>, Rest extends TupleWithRest.Rest> = Rest extends
4111
- readonly [infer Head extends Top, ...infer Tail extends ReadonlyArray<Top>] ? Readonly<[
4281
+ readonly [infer Head extends Constraint, ...infer Tail extends ReadonlyArray<Constraint>] ? Readonly<[
4112
4282
  ...T,
4113
4283
  ...Array<Head["Type"]>,
4114
4284
  ...{ readonly [K in keyof Tail]: Tail[K]["Type"] }
@@ -4128,7 +4298,7 @@ export declare namespace TupleWithRest {
4128
4298
  * @since 4.0.0
4129
4299
  */
4130
4300
  export type Iso<T extends ReadonlyArray<unknown>, Rest extends TupleWithRest.Rest> = Rest extends
4131
- readonly [infer Head extends Top, ...infer Tail extends ReadonlyArray<Top>] ? Readonly<[
4301
+ readonly [infer Head extends Constraint, ...infer Tail extends ReadonlyArray<Constraint>] ? Readonly<[
4132
4302
  ...T,
4133
4303
  ...Array<Head["Iso"]>,
4134
4304
  ...{ readonly [K in keyof Tail]: Tail[K]["Iso"] }
@@ -4148,7 +4318,7 @@ export declare namespace TupleWithRest {
4148
4318
  * @since 3.10.0
4149
4319
  */
4150
4320
  export type Encoded<E extends ReadonlyArray<unknown>, Rest extends TupleWithRest.Rest> = Rest extends
4151
- readonly [infer Head extends Top, ...infer Tail extends ReadonlyArray<Top>] ? readonly [
4321
+ readonly [infer Head extends Constraint, ...infer Tail extends ReadonlyArray<Constraint>] ? readonly [
4152
4322
  ...E,
4153
4323
  ...Array<Head["Encoded"]>,
4154
4324
  ...{ readonly [K in keyof Tail]: Tail[K]["Encoded"] }
@@ -4168,7 +4338,7 @@ export declare namespace TupleWithRest {
4168
4338
  * @since 4.0.0
4169
4339
  */
4170
4340
  export type MakeIn<M extends ReadonlyArray<unknown>, Rest extends TupleWithRest.Rest> = Rest extends
4171
- readonly [infer Head extends Top, ...infer Tail extends ReadonlyArray<Top>] ? readonly [
4341
+ readonly [infer Head extends Constraint, ...infer Tail extends ReadonlyArray<Constraint>] ? readonly [
4172
4342
  ...M,
4173
4343
  ...Array<Head["~type.make"]>,
4174
4344
  ...{ readonly [K in keyof Tail]: Tail[K]["~type.make"] }
@@ -4186,17 +4356,18 @@ export interface TupleWithRest<
4186
4356
  S extends TupleWithRest.TupleType,
4187
4357
  Rest extends TupleWithRest.Rest
4188
4358
  > extends
4189
- Bottom<
4190
- TupleWithRest.Type<S["Type"], Rest>,
4191
- TupleWithRest.Encoded<S["Encoded"], Rest>,
4192
- S["DecodingServices"] | Rest[number]["DecodingServices"],
4193
- S["EncodingServices"] | Rest[number]["EncodingServices"],
4359
+ BottomLazy<
4194
4360
  SchemaAST.Arrays,
4195
- TupleWithRest<S, Rest>,
4196
- TupleWithRest.MakeIn<S["~type.make"], Rest>,
4197
- TupleWithRest.Iso<S["Iso"], Rest>
4361
+ TupleWithRest<S, Rest>
4198
4362
  >
4199
4363
  {
4364
+ readonly "Type": TupleWithRest.Type<S["Type"], Rest>
4365
+ readonly "Encoded": TupleWithRest.Encoded<S["Encoded"], Rest>
4366
+ readonly "DecodingServices": S["DecodingServices"] | Rest[number]["DecodingServices"]
4367
+ readonly "EncodingServices": S["EncodingServices"] | Rest[number]["EncodingServices"]
4368
+ readonly "~type.make.in": TupleWithRest.MakeIn<S["~type.make"], Rest>
4369
+ readonly "~type.make": TupleWithRest.MakeIn<S["~type.make"], Rest>
4370
+ readonly "Iso": TupleWithRest.Iso<S["Iso"], Rest>
4200
4371
  readonly schema: S
4201
4372
  readonly rest: Rest
4202
4373
  }
@@ -4244,24 +4415,25 @@ export function TupleWithRest<S extends Tuple<Tuple.Elements>, const Rest extend
4244
4415
  * @category models
4245
4416
  * @since 4.0.0
4246
4417
  */
4247
- export interface $Array<S extends Top> extends
4248
- Bottom<
4249
- ReadonlyArray<S["Type"]>,
4250
- ReadonlyArray<S["Encoded"]>,
4251
- S["DecodingServices"],
4252
- S["EncodingServices"],
4418
+ export interface $Array<S extends Constraint> extends
4419
+ BottomLazy<
4253
4420
  SchemaAST.Arrays,
4254
- $Array<S>,
4255
- ReadonlyArray<S["~type.make"]>,
4256
- ReadonlyArray<S["Iso"]>
4421
+ $Array<S>
4257
4422
  >
4258
4423
  {
4424
+ readonly "Type": ReadonlyArray<S["Type"]>
4425
+ readonly "Encoded": ReadonlyArray<S["Encoded"]>
4426
+ readonly "DecodingServices": S["DecodingServices"]
4427
+ readonly "EncodingServices": S["EncodingServices"]
4428
+ readonly "~type.make.in": ReadonlyArray<S["~type.make"]>
4429
+ readonly "~type.make": ReadonlyArray<S["~type.make"]>
4430
+ readonly "Iso": ReadonlyArray<S["Iso"]>
4259
4431
  readonly value: S
4260
4432
  }
4261
4433
 
4262
4434
  interface ArrayLambda extends Lambda {
4263
- <S extends Top>(self: S): $Array<S>
4264
- readonly "~lambda.out": this["~lambda.in"] extends Top ? $Array<this["~lambda.in"]> : never
4435
+ <S extends Constraint>(self: S): $Array<S>
4436
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? $Array<this["~lambda.in"]> : never
4265
4437
  }
4266
4438
 
4267
4439
  /**
@@ -4300,24 +4472,25 @@ export {
4300
4472
  * @category models
4301
4473
  * @since 3.10.0
4302
4474
  */
4303
- export interface NonEmptyArray<S extends Top> extends
4304
- Bottom<
4305
- readonly [S["Type"], ...Array<S["Type"]>],
4306
- readonly [S["Encoded"], ...Array<S["Encoded"]>],
4307
- S["DecodingServices"],
4308
- S["EncodingServices"],
4475
+ export interface NonEmptyArray<S extends Constraint> extends
4476
+ BottomLazy<
4309
4477
  SchemaAST.Arrays,
4310
- NonEmptyArray<S>,
4311
- readonly [S["~type.make"], ...Array<S["~type.make"]>],
4312
- readonly [S["Iso"], ...Array<S["Iso"]>]
4478
+ NonEmptyArray<S>
4313
4479
  >
4314
4480
  {
4481
+ readonly "Type": readonly [S["Type"], ...Array<S["Type"]>]
4482
+ readonly "Encoded": readonly [S["Encoded"], ...Array<S["Encoded"]>]
4483
+ readonly "DecodingServices": S["DecodingServices"]
4484
+ readonly "EncodingServices": S["EncodingServices"]
4485
+ readonly "~type.make.in": readonly [S["~type.make"], ...Array<S["~type.make"]>]
4486
+ readonly "~type.make": readonly [S["~type.make"], ...Array<S["~type.make"]>]
4487
+ readonly "Iso": readonly [S["Iso"], ...Array<S["Iso"]>]
4315
4488
  readonly value: S
4316
4489
  }
4317
4490
 
4318
4491
  interface NonEmptyArrayLambda extends Lambda {
4319
- <S extends Top>(self: S): NonEmptyArray<S>
4320
- readonly "~lambda.out": this["~lambda.in"] extends Top ? NonEmptyArray<this["~lambda.in"]> : never
4492
+ <S extends Constraint>(self: S): NonEmptyArray<S>
4493
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? NonEmptyArray<this["~lambda.in"]> : never
4321
4494
  }
4322
4495
 
4323
4496
  /**
@@ -4348,7 +4521,7 @@ export const NonEmptyArray = Struct_.lambda<NonEmptyArrayLambda>((schema) =>
4348
4521
  * @category constructors
4349
4522
  * @since 3.10.0
4350
4523
  */
4351
- export interface ArrayEnsure<S extends Top> extends decodeTo<$Array<toType<S>>, Union<readonly [S, $Array<S>]>> {
4524
+ export interface ArrayEnsure<S extends Constraint> extends decodeTo<$Array<toType<S>>, Union<readonly [S, $Array<S>]>> {
4352
4525
  readonly "Rebuild": ArrayEnsure<S>
4353
4526
  }
4354
4527
 
@@ -4378,7 +4551,7 @@ export interface ArrayEnsure<S extends Top> extends decodeTo<$Array<toType<S>>,
4378
4551
  * @category constructors
4379
4552
  * @since 3.10.0
4380
4553
  */
4381
- export function ArrayEnsure<S extends Top>(schema: S): ArrayEnsure<S> {
4554
+ export function ArrayEnsure<S extends Constraint>(schema: S): ArrayEnsure<S> {
4382
4555
  return Union([schema, ArraySchema(schema)]).pipe(decodeTo(
4383
4556
  ArraySchema(toType(schema)),
4384
4557
  SchemaTransformation.transform({
@@ -4394,7 +4567,7 @@ export function ArrayEnsure<S extends Top>(schema: S): ArrayEnsure<S> {
4394
4567
  * @category models
4395
4568
  * @since 4.0.0
4396
4569
  */
4397
- export interface UniqueArray<S extends Top> extends $Array<S> {
4570
+ export interface UniqueArray<S extends Constraint> extends $Array<S> {
4398
4571
  readonly "Rebuild": UniqueArray<S>
4399
4572
  }
4400
4573
 
@@ -4409,7 +4582,7 @@ export interface UniqueArray<S extends Top> extends $Array<S> {
4409
4582
  * @category constructors
4410
4583
  * @since 4.0.0
4411
4584
  */
4412
- export function UniqueArray<S extends Top>(item: S): UniqueArray<S> {
4585
+ export function UniqueArray<S extends Constraint>(item: S): UniqueArray<S> {
4413
4586
  return ArraySchema(item).check(isUnique())
4414
4587
  }
4415
4588
 
@@ -4419,19 +4592,11 @@ export function UniqueArray<S extends Top>(item: S): UniqueArray<S> {
4419
4592
  * @category transforming
4420
4593
  * @since 3.10.0
4421
4594
  */
4422
- export interface mutable<S extends Top & { readonly "ast": SchemaAST.Arrays }> extends
4423
- Bottom<
4424
- Mutable<S["Type"]>,
4425
- Mutable<S["Encoded"]>,
4426
- S["DecodingServices"],
4427
- S["EncodingServices"],
4595
+ export interface mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays }> extends
4596
+ BottomLazy<
4428
4597
  S["ast"],
4429
4598
  mutable<S>,
4430
- // "~type.make" and "~type.make.in" as they are because they are contravariant
4431
- S["~type.make.in"],
4432
- S["Iso"],
4433
4599
  S["~type.parameters"],
4434
- S["~type.make"],
4435
4600
  S["~type.mutability"],
4436
4601
  S["~type.optionality"],
4437
4602
  S["~type.constructor.default"],
@@ -4439,12 +4604,20 @@ export interface mutable<S extends Top & { readonly "ast": SchemaAST.Arrays }> e
4439
4604
  S["~encoded.optionality"]
4440
4605
  >
4441
4606
  {
4607
+ readonly "Type": Mutable<S["Type"]>
4608
+ readonly "Encoded": Mutable<S["Encoded"]>
4609
+ readonly "DecodingServices": S["DecodingServices"]
4610
+ readonly "EncodingServices": S["EncodingServices"]
4611
+ // "~type.make" and "~type.make.in" as they are because they are contravariant
4612
+ readonly "~type.make.in": S["~type.make.in"]
4613
+ readonly "~type.make": S["~type.make"]
4614
+ readonly "Iso": S["Iso"]
4442
4615
  readonly schema: S
4443
4616
  }
4444
4617
 
4445
4618
  interface mutableLambda extends Lambda {
4446
- <S extends Top & { readonly "ast": SchemaAST.Arrays }>(self: S): mutable<S>
4447
- readonly "~lambda.out": this["~lambda.in"] extends Top & { readonly "ast": SchemaAST.Arrays } ?
4619
+ <S extends Constraint & { readonly "ast": SchemaAST.Arrays }>(self: S): mutable<S>
4620
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint & { readonly "ast": SchemaAST.Arrays } ?
4448
4621
  mutable<this["~lambda.in"]>
4449
4622
  : "Error: schema not eligible for mutable"
4450
4623
  }
@@ -4476,18 +4649,19 @@ export const mutable = Struct_.lambda<mutableLambda>((schema) => {
4476
4649
  * @category models
4477
4650
  * @since 3.10.0
4478
4651
  */
4479
- export interface Union<Members extends ReadonlyArray<Top>> extends
4480
- Bottom<
4481
- { [K in keyof Members]: Members[K]["Type"] }[number],
4482
- { [K in keyof Members]: Members[K]["Encoded"] }[number],
4483
- { [K in keyof Members]: Members[K]["DecodingServices"] }[number],
4484
- { [K in keyof Members]: Members[K]["EncodingServices"] }[number],
4652
+ export interface Union<Members extends ReadonlyArray<Constraint>> extends
4653
+ BottomLazy<
4485
4654
  SchemaAST.Union<{ [K in keyof Members]: Members[K]["ast"] }[number]>,
4486
- Union<Members>,
4487
- { [K in keyof Members]: Members[K]["~type.make"] }[number],
4488
- { [K in keyof Members]: Members[K]["Iso"] }[number]
4655
+ Union<Members>
4489
4656
  >
4490
4657
  {
4658
+ readonly "Type": { [K in keyof Members]: Members[K]["Type"] }[number]
4659
+ readonly "Encoded": { [K in keyof Members]: Members[K]["Encoded"] }[number]
4660
+ readonly "DecodingServices": { [K in keyof Members]: Members[K]["DecodingServices"] }[number]
4661
+ readonly "EncodingServices": { [K in keyof Members]: Members[K]["EncodingServices"] }[number]
4662
+ readonly "~type.make.in": { [K in keyof Members]: Members[K]["~type.make"] }[number]
4663
+ readonly "~type.make": { [K in keyof Members]: Members[K]["~type.make"] }[number]
4664
+ readonly "Iso": { [K in keyof Members]: Members[K]["Iso"] }[number]
4491
4665
  readonly members: Members
4492
4666
  /**
4493
4667
  * Returns a new union with the members modified by the provided function.
@@ -4505,7 +4679,7 @@ export interface Union<Members extends ReadonlyArray<Top>> extends
4505
4679
  * use this option if you have verified that your refinements remain correct
4506
4680
  * after the transformation.
4507
4681
  */
4508
- mapMembers<To extends ReadonlyArray<Top>>(
4682
+ mapMembers<To extends ReadonlyArray<Constraint>>(
4509
4683
  f: (members: Members) => To,
4510
4684
  options?: {
4511
4685
  readonly unsafePreserveChecks?: boolean | undefined
@@ -4513,13 +4687,13 @@ export interface Union<Members extends ReadonlyArray<Top>> extends
4513
4687
  ): Union<Simplify<Readonly<To>>>
4514
4688
  }
4515
4689
 
4516
- function makeUnion<Members extends ReadonlyArray<Top>>(
4690
+ function makeUnion<Members extends ReadonlyArray<Constraint>>(
4517
4691
  ast: SchemaAST.Union<Members[number]["ast"]>,
4518
4692
  members: Members
4519
4693
  ): Union<Members> {
4520
4694
  return make(ast, {
4521
4695
  members,
4522
- mapMembers<To extends ReadonlyArray<Top>>(
4696
+ mapMembers<To extends ReadonlyArray<Constraint>>(
4523
4697
  this: Union<Members>,
4524
4698
  f: (members: Members) => To,
4525
4699
  options?: {
@@ -4559,7 +4733,7 @@ function makeUnion<Members extends ReadonlyArray<Top>>(
4559
4733
  * @category constructors
4560
4734
  * @since 3.10.0
4561
4735
  */
4562
- export function Union<const Members extends ReadonlyArray<Top>>(
4736
+ export function Union<const Members extends ReadonlyArray<Constraint>>(
4563
4737
  members: Members,
4564
4738
  options?: { mode?: "anyOf" | "oneOf" }
4565
4739
  ): Union<Members> {
@@ -4580,7 +4754,7 @@ export interface Literals<L extends ReadonlyArray<SchemaAST.LiteralValue>>
4580
4754
  /**
4581
4755
  * Map over the members of the union.
4582
4756
  */
4583
- mapMembers<To extends ReadonlyArray<Top>>(f: (members: this["members"]) => To): Union<Simplify<Readonly<To>>>
4757
+ mapMembers<To extends ReadonlyArray<Constraint>>(f: (members: this["members"]) => To): Union<Simplify<Readonly<To>>>
4584
4758
 
4585
4759
  pick<const L2 extends ReadonlyArray<L[number]>>(literals: L2): Literals<L2>
4586
4760
 
@@ -4610,7 +4784,7 @@ export function Literals<const L extends ReadonlyArray<SchemaAST.LiteralValue>>(
4610
4784
  return make(SchemaAST.union(members, "anyOf", undefined), {
4611
4785
  literals,
4612
4786
  members,
4613
- mapMembers<To extends ReadonlyArray<Top>>(
4787
+ mapMembers<To extends ReadonlyArray<Constraint>>(
4614
4788
  this: Literals<L>,
4615
4789
  f: (members: Literals<L>["members"]) => To
4616
4790
  ): Union<Simplify<Readonly<To>>> {
@@ -4633,13 +4807,13 @@ export function Literals<const L extends ReadonlyArray<SchemaAST.LiteralValue>>(
4633
4807
  * @category models
4634
4808
  * @since 3.10.0
4635
4809
  */
4636
- export interface NullOr<S extends Top> extends Union<readonly [S, Null]> {
4810
+ export interface NullOr<S extends Constraint> extends Union<readonly [S, Null]> {
4637
4811
  readonly "Rebuild": NullOr<S>
4638
4812
  }
4639
4813
 
4640
4814
  interface NullOrLambda extends Lambda {
4641
- <S extends Top>(self: S): NullOr<S>
4642
- readonly "~lambda.out": this["~lambda.in"] extends Top ? NullOr<this["~lambda.in"]> : never
4815
+ <S extends Constraint>(self: S): NullOr<S>
4816
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? NullOr<this["~lambda.in"]> : never
4643
4817
  }
4644
4818
 
4645
4819
  /**
@@ -4656,13 +4830,13 @@ export const NullOr = Struct_.lambda<NullOrLambda>((self) => Union([self, Null])
4656
4830
  * @category models
4657
4831
  * @since 3.10.0
4658
4832
  */
4659
- export interface UndefinedOr<S extends Top> extends Union<readonly [S, Undefined]> {
4833
+ export interface UndefinedOr<S extends Constraint> extends Union<readonly [S, Undefined]> {
4660
4834
  readonly "Rebuild": UndefinedOr<S>
4661
4835
  }
4662
4836
 
4663
4837
  interface UndefinedOrLambda extends Lambda {
4664
- <S extends Top>(self: S): UndefinedOr<S>
4665
- readonly "~lambda.out": this["~lambda.in"] extends Top ? UndefinedOr<this["~lambda.in"]> : never
4838
+ <S extends Constraint>(self: S): UndefinedOr<S>
4839
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? UndefinedOr<this["~lambda.in"]> : never
4666
4840
  }
4667
4841
 
4668
4842
  /**
@@ -4679,13 +4853,13 @@ export const UndefinedOr = Struct_.lambda<UndefinedOrLambda>((self) => Union([se
4679
4853
  * @category models
4680
4854
  * @since 3.10.0
4681
4855
  */
4682
- export interface NullishOr<S extends Top> extends Union<readonly [S, Null, Undefined]> {
4856
+ export interface NullishOr<S extends Constraint> extends Union<readonly [S, Null, Undefined]> {
4683
4857
  readonly "Rebuild": NullishOr<S>
4684
4858
  }
4685
4859
 
4686
4860
  interface NullishOrLambda extends Lambda {
4687
- <S extends Top>(self: S): NullishOr<S>
4688
- readonly "~lambda.out": this["~lambda.in"] extends Top ? NullishOr<this["~lambda.in"]> : never
4861
+ <S extends Constraint>(self: S): NullishOr<S>
4862
+ readonly "~lambda.out": this["~lambda.in"] extends Constraint ? NullishOr<this["~lambda.in"]> : never
4689
4863
  }
4690
4864
 
4691
4865
  /**
@@ -4702,25 +4876,26 @@ export const NullishOr = Struct_.lambda<NullishOrLambda>((self) => Union([self,
4702
4876
  * @category models
4703
4877
  * @since 3.10.0
4704
4878
  */
4705
- export interface suspend<S extends Top> extends
4706
- Bottom<
4707
- S["Type"],
4708
- S["Encoded"],
4709
- S["DecodingServices"],
4710
- S["EncodingServices"],
4879
+ export interface suspend<S extends Constraint> extends
4880
+ BottomLazy<
4711
4881
  SchemaAST.Suspend,
4712
4882
  suspend<S>,
4713
- S["~type.make.in"],
4714
- S["Iso"],
4715
4883
  S["~type.parameters"],
4716
- S["~type.make"],
4717
4884
  S["~type.mutability"],
4718
4885
  S["~type.optionality"],
4719
4886
  S["~type.constructor.default"],
4720
4887
  S["~encoded.mutability"],
4721
4888
  S["~encoded.optionality"]
4722
4889
  >
4723
- {}
4890
+ {
4891
+ readonly "Type": S["Type"]
4892
+ readonly "Encoded": S["Encoded"]
4893
+ readonly "DecodingServices": S["DecodingServices"]
4894
+ readonly "EncodingServices": S["EncodingServices"]
4895
+ readonly "~type.make.in": S["~type.make.in"]
4896
+ readonly "~type.make": S["~type.make"]
4897
+ readonly "Iso": S["Iso"]
4898
+ }
4724
4899
 
4725
4900
  /**
4726
4901
  * Creates a suspended schema that defers evaluation until needed. This is
@@ -4746,7 +4921,7 @@ export interface suspend<S extends Top> extends
4746
4921
  * @category constructors
4747
4922
  * @since 3.10.0
4748
4923
  */
4749
- export function suspend<S extends Top>(f: () => S): suspend<S> {
4924
+ export function suspend<S extends Constraint>(f: () => S): suspend<S> {
4750
4925
  return make(new SchemaAST.Suspend(() => f().ast))
4751
4926
  }
4752
4927
 
@@ -4779,18 +4954,11 @@ export function check<S extends Top>(
4779
4954
  * @category filtering
4780
4955
  * @since 3.10.0
4781
4956
  */
4782
- export interface refine<T extends S["Type"], S extends Top> extends
4783
- Bottom<
4784
- T,
4785
- S["Encoded"],
4786
- S["DecodingServices"],
4787
- S["EncodingServices"],
4957
+ export interface refine<T extends S["Type"], S extends Constraint> extends
4958
+ BottomLazy<
4788
4959
  S["ast"],
4789
4960
  refine<T, S>,
4790
- S["~type.make.in"],
4791
- T,
4792
4961
  S["~type.parameters"],
4793
- T,
4794
4962
  S["~type.mutability"],
4795
4963
  S["~type.optionality"],
4796
4964
  S["~type.constructor.default"],
@@ -4798,6 +4966,13 @@ export interface refine<T extends S["Type"], S extends Top> extends
4798
4966
  S["~encoded.optionality"]
4799
4967
  >
4800
4968
  {
4969
+ readonly "Type": T
4970
+ readonly "Encoded": S["Encoded"]
4971
+ readonly "DecodingServices": S["DecodingServices"]
4972
+ readonly "EncodingServices": S["EncodingServices"]
4973
+ readonly "~type.make.in": S["~type.make.in"]
4974
+ readonly "~type.make": T
4975
+ readonly "Iso": T
4801
4976
  readonly schema: S
4802
4977
  }
4803
4978
 
@@ -4816,7 +4991,7 @@ export interface refine<T extends S["Type"], S extends Top> extends
4816
4991
  * @category filtering
4817
4992
  * @since 3.10.0
4818
4993
  */
4819
- export function refine<S extends Top, T extends S["Type"]>(
4994
+ export function refine<S extends Constraint, T extends S["Type"]>(
4820
4995
  refinement: (value: S["Type"]) => value is T,
4821
4996
  annotations?: Annotations.Filter
4822
4997
  ) {
@@ -4832,18 +5007,11 @@ type DistributeBrands<B> = UnionToIntersection<B extends infer U extends string
4832
5007
  * @category branding
4833
5008
  * @since 3.10.0
4834
5009
  */
4835
- export interface brand<S extends Top, B> extends
4836
- Bottom<
4837
- S["Type"] & DistributeBrands<B>,
4838
- S["Encoded"],
4839
- S["DecodingServices"],
4840
- S["EncodingServices"],
5010
+ export interface brand<S extends Constraint, B> extends
5011
+ BottomLazy<
4841
5012
  S["ast"],
4842
5013
  brand<S, B>,
4843
- S["~type.make.in"],
4844
- S["Type"] & DistributeBrands<B>,
4845
5014
  S["~type.parameters"],
4846
- S["Type"] & DistributeBrands<B>,
4847
5015
  S["~type.mutability"],
4848
5016
  S["~type.optionality"],
4849
5017
  S["~type.constructor.default"],
@@ -4851,6 +5019,13 @@ export interface brand<S extends Top, B> extends
4851
5019
  S["~encoded.optionality"]
4852
5020
  >
4853
5021
  {
5022
+ readonly "Type": S["Type"] & DistributeBrands<B>
5023
+ readonly "Encoded": S["Encoded"]
5024
+ readonly "DecodingServices": S["DecodingServices"]
5025
+ readonly "EncodingServices": S["EncodingServices"]
5026
+ readonly "~type.make.in": S["~type.make.in"]
5027
+ readonly "~type.make": S["Type"] & DistributeBrands<B>
5028
+ readonly "Iso": S["Type"] & DistributeBrands<B>
4854
5029
  readonly schema: S
4855
5030
  readonly identifier: string
4856
5031
  }
@@ -4875,7 +5050,7 @@ export interface brand<S extends Top, B> extends
4875
5050
  * @since 3.10.0
4876
5051
  */
4877
5052
  export function brand<B extends string>(identifier: B) {
4878
- return <S extends Top>(schema: S): brand<S["Rebuild"], B> =>
5053
+ return <S extends ConstraintRebuildable>(schema: S): brand<S["Rebuild"], B> =>
4879
5054
  make(SchemaAST.brand(schema.ast, identifier), { schema, identifier })
4880
5055
  }
4881
5056
 
@@ -4900,18 +5075,11 @@ export function fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor:
4900
5075
  * @category decoding
4901
5076
  * @since 4.0.0
4902
5077
  */
4903
- export interface middlewareDecoding<S extends Top, RD> extends
4904
- Bottom<
4905
- S["Type"],
4906
- S["Encoded"],
4907
- RD,
4908
- S["EncodingServices"],
5078
+ export interface middlewareDecoding<S extends Constraint, RD> extends
5079
+ BottomLazy<
4909
5080
  S["ast"],
4910
5081
  middlewareDecoding<S, RD>,
4911
- S["~type.make.in"],
4912
- S["Iso"],
4913
5082
  S["~type.parameters"],
4914
- S["~type.make"],
4915
5083
  S["~type.mutability"],
4916
5084
  S["~type.optionality"],
4917
5085
  S["~type.constructor.default"],
@@ -4919,6 +5087,13 @@ export interface middlewareDecoding<S extends Top, RD> extends
4919
5087
  S["~encoded.optionality"]
4920
5088
  >
4921
5089
  {
5090
+ readonly "Type": S["Type"]
5091
+ readonly "Encoded": S["Encoded"]
5092
+ readonly "DecodingServices": RD
5093
+ readonly "EncodingServices": S["EncodingServices"]
5094
+ readonly "~type.make.in": S["~type.make.in"]
5095
+ readonly "~type.make": S["~type.make"]
5096
+ readonly "Iso": S["Iso"]
4922
5097
  readonly schema: S
4923
5098
  }
4924
5099
 
@@ -4947,7 +5122,7 @@ export interface middlewareDecoding<S extends Top, RD> extends
4947
5122
  * @category decoding
4948
5123
  * @since 4.0.0
4949
5124
  */
4950
- export function middlewareDecoding<S extends Top, RD>(
5125
+ export function middlewareDecoding<S extends Constraint, RD>(
4951
5126
  decode: (
4952
5127
  effect: Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, S["DecodingServices"]>,
4953
5128
  options: SchemaAST.ParseOptions
@@ -4966,18 +5141,11 @@ export function middlewareDecoding<S extends Top, RD>(
4966
5141
  * @category encoding
4967
5142
  * @since 4.0.0
4968
5143
  */
4969
- export interface middlewareEncoding<S extends Top, RE> extends
4970
- Bottom<
4971
- S["Type"],
4972
- S["Encoded"],
4973
- S["DecodingServices"],
4974
- RE,
5144
+ export interface middlewareEncoding<S extends Constraint, RE> extends
5145
+ BottomLazy<
4975
5146
  S["ast"],
4976
5147
  middlewareEncoding<S, RE>,
4977
- S["~type.make.in"],
4978
- S["Iso"],
4979
5148
  S["~type.parameters"],
4980
- S["~type.make"],
4981
5149
  S["~type.mutability"],
4982
5150
  S["~type.optionality"],
4983
5151
  S["~type.constructor.default"],
@@ -4985,6 +5153,13 @@ export interface middlewareEncoding<S extends Top, RE> extends
4985
5153
  S["~encoded.optionality"]
4986
5154
  >
4987
5155
  {
5156
+ readonly "Type": S["Type"]
5157
+ readonly "Encoded": S["Encoded"]
5158
+ readonly "DecodingServices": S["DecodingServices"]
5159
+ readonly "EncodingServices": RE
5160
+ readonly "~type.make.in": S["~type.make.in"]
5161
+ readonly "~type.make": S["~type.make"]
5162
+ readonly "Iso": S["Iso"]
4988
5163
  readonly schema: S
4989
5164
  }
4990
5165
 
@@ -5013,7 +5188,7 @@ export interface middlewareEncoding<S extends Top, RE> extends
5013
5188
  * @category encoding
5014
5189
  * @since 4.0.0
5015
5190
  */
5016
- export function middlewareEncoding<S extends Top, RE>(
5191
+ export function middlewareEncoding<S extends Constraint, RE>(
5017
5192
  encode: (
5018
5193
  effect: Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue, S["EncodingServices"]>,
5019
5194
  options: SchemaAST.ParseOptions
@@ -5048,9 +5223,9 @@ export function middlewareEncoding<S extends Top, RE>(
5048
5223
  * @category error handling
5049
5224
  * @since 4.0.0
5050
5225
  */
5051
- export function catchDecoding<S extends Top>(
5226
+ export function catchDecoding<S extends Constraint>(
5052
5227
  f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue>
5053
- ): (self: S) => S["Rebuild"] {
5228
+ ): (self: S) => middlewareDecoding<S, S["DecodingServices"]> {
5054
5229
  return catchDecodingWithContext(f)
5055
5230
  }
5056
5231
 
@@ -5074,11 +5249,11 @@ export function catchDecoding<S extends Top>(
5074
5249
  * @category error handling
5075
5250
  * @since 4.0.0
5076
5251
  */
5077
- export function catchDecodingWithContext<S extends Top, R = never>(
5252
+ export function catchDecodingWithContext<S extends Constraint, R = never>(
5078
5253
  f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, SchemaIssue.Issue, R>
5079
5254
  ) {
5080
5255
  return (self: S): middlewareDecoding<S, S["DecodingServices"] | R> =>
5081
- self.pipe(middlewareDecoding(Effect.catchEager(f)))
5256
+ middlewareDecoding<S, S["DecodingServices"] | R>(Effect.catchEager(f))(self)
5082
5257
  }
5083
5258
 
5084
5259
  /**
@@ -5093,9 +5268,9 @@ export function catchDecodingWithContext<S extends Top, R = never>(
5093
5268
  * @category error handling
5094
5269
  * @since 4.0.0
5095
5270
  */
5096
- export function catchEncoding<S extends Top>(
5271
+ export function catchEncoding<S extends Constraint>(
5097
5272
  f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue>
5098
- ): (self: S) => S["Rebuild"] {
5273
+ ): (self: S) => middlewareEncoding<S, S["EncodingServices"]> {
5099
5274
  return catchEncodingWithContext(f)
5100
5275
  }
5101
5276
 
@@ -5119,11 +5294,11 @@ export function catchEncoding<S extends Top>(
5119
5294
  * @category error handling
5120
5295
  * @since 4.0.0
5121
5296
  */
5122
- export function catchEncodingWithContext<S extends Top, R = never>(
5297
+ export function catchEncodingWithContext<S extends Constraint, R = never>(
5123
5298
  f: (issue: SchemaIssue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, SchemaIssue.Issue, R>
5124
5299
  ) {
5125
5300
  return (self: S): middlewareEncoding<S, S["EncodingServices"] | R> =>
5126
- self.pipe(middlewareEncoding(Effect.catchEager(f)))
5301
+ middlewareEncoding<S, S["EncodingServices"] | R>(Effect.catchEager(f))(self)
5127
5302
  }
5128
5303
 
5129
5304
  /**
@@ -5132,18 +5307,11 @@ export function catchEncodingWithContext<S extends Top, R = never>(
5132
5307
  * @category transforming
5133
5308
  * @since 4.0.0
5134
5309
  */
5135
- export interface decodeTo<To extends Top, From extends Top, RD = never, RE = never> extends
5136
- Bottom<
5137
- To["Type"],
5138
- From["Encoded"],
5139
- To["DecodingServices"] | From["DecodingServices"] | RD,
5140
- To["EncodingServices"] | From["EncodingServices"] | RE,
5310
+ export interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never> extends
5311
+ BottomLazy<
5141
5312
  To["ast"],
5142
5313
  decodeTo<To, From, RD, RE>,
5143
- To["~type.make.in"],
5144
- To["Iso"],
5145
5314
  To["~type.parameters"],
5146
- To["~type.make"],
5147
5315
  To["~type.mutability"],
5148
5316
  To["~type.optionality"],
5149
5317
  To["~type.constructor.default"],
@@ -5151,6 +5319,13 @@ export interface decodeTo<To extends Top, From extends Top, RD = never, RE = nev
5151
5319
  From["~encoded.optionality"]
5152
5320
  >
5153
5321
  {
5322
+ readonly "Type": To["Type"]
5323
+ readonly "Encoded": From["Encoded"]
5324
+ readonly "DecodingServices": To["DecodingServices"] | From["DecodingServices"] | RD
5325
+ readonly "EncodingServices": To["EncodingServices"] | From["EncodingServices"] | RE
5326
+ readonly "~type.make.in": To["~type.make.in"]
5327
+ readonly "~type.make": To["~type.make"]
5328
+ readonly "Iso": To["Iso"]
5154
5329
  readonly from: From
5155
5330
  readonly to: To
5156
5331
  }
@@ -5161,7 +5336,7 @@ export interface decodeTo<To extends Top, From extends Top, RD = never, RE = nev
5161
5336
  * @category transforming
5162
5337
  * @since 3.10.0
5163
5338
  */
5164
- export interface compose<To extends Top, From extends Top> extends decodeTo<To, From> {}
5339
+ export interface compose<To extends Constraint, From extends Constraint> extends decodeTo<To, From> {}
5165
5340
 
5166
5341
  /**
5167
5342
  * Creates a schema that transforms from a source schema to a target schema.
@@ -5211,15 +5386,15 @@ export interface compose<To extends Top, From extends Top> extends decodeTo<To,
5211
5386
  * @category transforming
5212
5387
  * @since 4.0.0
5213
5388
  */
5214
- export function decodeTo<To extends Top>(to: To): <From extends Top>(from: From) => compose<To, From>
5215
- export function decodeTo<To extends Top, From extends Top, RD = never, RE = never>(
5389
+ export function decodeTo<To extends Constraint>(to: To): <From extends Constraint>(from: From) => compose<To, From>
5390
+ export function decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>(
5216
5391
  to: To,
5217
5392
  transformation: {
5218
5393
  readonly decode: SchemaGetter.Getter<NoInfer<To["Encoded"]>, NoInfer<From["Type"]>, RD>
5219
5394
  readonly encode: SchemaGetter.Getter<NoInfer<From["Type"]>, NoInfer<To["Encoded"]>, RE>
5220
5395
  }
5221
5396
  ): (from: From) => decodeTo<To, From, RD, RE>
5222
- export function decodeTo<To extends Top, From extends Top, RD = never, RE = never>(
5397
+ export function decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>(
5223
5398
  to: To,
5224
5399
  transformation?: {
5225
5400
  readonly decode: SchemaGetter.Getter<To["Encoded"], From["Type"], RD>
@@ -5284,12 +5459,12 @@ export function decodeTo<To extends Top, From extends Top, RD = never, RE = neve
5284
5459
  * @category transforming
5285
5460
  * @since 3.10.0
5286
5461
  */
5287
- export function decode<S extends Top, RD = never, RE = never>(transformation: {
5462
+ export function decode<S extends Constraint, RD = never, RE = never>(transformation: {
5288
5463
  readonly decode: SchemaGetter.Getter<S["Type"], S["Type"], RD>
5289
5464
  readonly encode: SchemaGetter.Getter<S["Type"], S["Type"], RE>
5290
5465
  }) {
5291
5466
  return (self: S): decodeTo<toType<S>, S, RD, RE> => {
5292
- return self.pipe(decodeTo(toType(self), transformation))
5467
+ return decodeTo<toType<S>, S, RD, RE>(toType(self), transformation)(self)
5293
5468
  }
5294
5469
  }
5295
5470
 
@@ -5322,17 +5497,17 @@ export function decode<S extends Top, RD = never, RE = never>(transformation: {
5322
5497
  * @category transforming
5323
5498
  * @since 4.0.0
5324
5499
  */
5325
- export function encodeTo<To extends Top>(
5500
+ export function encodeTo<To extends Constraint>(
5326
5501
  to: To
5327
- ): <From extends Top>(from: From) => decodeTo<From, To>
5328
- export function encodeTo<To extends Top, From extends Top, RD = never, RE = never>(
5502
+ ): <From extends Constraint>(from: From) => decodeTo<From, To>
5503
+ export function encodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>(
5329
5504
  to: To,
5330
5505
  transformation: {
5331
5506
  readonly decode: SchemaGetter.Getter<NoInfer<From["Encoded"]>, NoInfer<To["Type"]>, RD>
5332
5507
  readonly encode: SchemaGetter.Getter<NoInfer<To["Type"]>, NoInfer<From["Encoded"]>, RE>
5333
5508
  }
5334
5509
  ): (from: From) => decodeTo<From, To, RD, RE>
5335
- export function encodeTo<To extends Top, From extends Top, RD = never, RE = never>(
5510
+ export function encodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>(
5336
5511
  to: To,
5337
5512
  transformation?: {
5338
5513
  readonly decode: SchemaGetter.Getter<From["Encoded"], To["Type"], RD>
@@ -5341,8 +5516,8 @@ export function encodeTo<To extends Top, From extends Top, RD = never, RE = neve
5341
5516
  ) {
5342
5517
  return (from: From): decodeTo<From, To, RD, RE> => {
5343
5518
  return transformation ?
5344
- to.pipe(decodeTo(from, transformation)) :
5345
- to.pipe(decodeTo(from))
5519
+ decodeTo<From, To, RD, RE>(from, transformation)(to) :
5520
+ decodeTo<From>(from)(to)
5346
5521
  }
5347
5522
  }
5348
5523
 
@@ -5371,12 +5546,12 @@ export function encodeTo<To extends Top, From extends Top, RD = never, RE = neve
5371
5546
  * @category transforming
5372
5547
  * @since 3.10.0
5373
5548
  */
5374
- export function encode<S extends Top, RD = never, RE = never>(transformation: {
5549
+ export function encode<S extends Constraint, RD = never, RE = never>(transformation: {
5375
5550
  readonly decode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RD>
5376
5551
  readonly encode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RE>
5377
5552
  }) {
5378
5553
  return (self: S): decodeTo<S, toEncoded<S>, RD, RE> => {
5379
- return toEncoded(self).pipe(decodeTo(self, transformation))
5554
+ return decodeTo<S, toEncoded<S>, RD, RE>(self, transformation)(toEncoded(self))
5380
5555
  }
5381
5556
  }
5382
5557
 
@@ -5400,18 +5575,11 @@ export interface WithoutConstructorDefault {
5400
5575
  * @category constructors
5401
5576
  * @since 3.10.0
5402
5577
  */
5403
- export interface withConstructorDefault<S extends Top & WithoutConstructorDefault> extends
5404
- Bottom<
5405
- S["Type"],
5406
- S["Encoded"],
5407
- S["DecodingServices"],
5408
- S["EncodingServices"],
5578
+ export interface withConstructorDefault<S extends Constraint & WithoutConstructorDefault> extends
5579
+ BottomLazy<
5409
5580
  S["ast"],
5410
5581
  withConstructorDefault<S>,
5411
- S["~type.make.in"],
5412
- S["Iso"],
5413
5582
  S["~type.parameters"],
5414
- S["~type.make"],
5415
5583
  S["~type.mutability"],
5416
5584
  S["~type.optionality"],
5417
5585
  "with-default",
@@ -5419,6 +5587,13 @@ export interface withConstructorDefault<S extends Top & WithoutConstructorDefaul
5419
5587
  S["~encoded.optionality"]
5420
5588
  >
5421
5589
  {
5590
+ readonly "Type": S["Type"]
5591
+ readonly "Encoded": S["Encoded"]
5592
+ readonly "DecodingServices": S["DecodingServices"]
5593
+ readonly "EncodingServices": S["EncodingServices"]
5594
+ readonly "~type.make.in": S["~type.make.in"]
5595
+ readonly "~type.make": S["~type.make"]
5596
+ readonly "Iso": S["Iso"]
5422
5597
  readonly schema: S
5423
5598
  }
5424
5599
 
@@ -5449,7 +5624,7 @@ export interface withConstructorDefault<S extends Top & WithoutConstructorDefaul
5449
5624
  * @category constructors
5450
5625
  * @since 3.10.0
5451
5626
  */
5452
- export function withConstructorDefault<S extends Top & WithoutConstructorDefault>(
5627
+ export function withConstructorDefault<S extends Constraint & WithoutConstructorDefault>(
5453
5628
  // `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
5454
5629
  // it makes easier to define the default value if there are nested defaults
5455
5630
  defaultValue: Effect.Effect<S["~type.make.in"], SchemaError>
@@ -5464,7 +5639,9 @@ export function withConstructorDefault<S extends Top & WithoutConstructorDefault
5464
5639
  * @category decoding
5465
5640
  * @since 4.0.0
5466
5641
  */
5467
- export interface withDecodingDefaultKey<S extends Top, R = never> extends decodeTo<S, optionalKey<toEncoded<S>>, R> {
5642
+ export interface withDecodingDefaultKey<S extends Constraint, R = never>
5643
+ extends decodeTo<S, optionalKey<toEncoded<S>>, R>
5644
+ {
5468
5645
  readonly "Rebuild": withDecodingDefaultKey<S, R>
5469
5646
  }
5470
5647
 
@@ -5518,7 +5695,7 @@ export type DecodingDefaultOptions = {
5518
5695
  * @category decoding
5519
5696
  * @since 4.0.0
5520
5697
  */
5521
- export function withDecodingDefaultKey<S extends Top, R = never>(
5698
+ export function withDecodingDefaultKey<S extends Constraint, R = never>(
5522
5699
  defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
5523
5700
  options?: DecodingDefaultOptions
5524
5701
  ) {
@@ -5537,7 +5714,7 @@ export function withDecodingDefaultKey<S extends Top, R = never>(
5537
5714
  * @category decoding
5538
5715
  * @since 4.0.0
5539
5716
  */
5540
- export interface withDecodingDefaultTypeKey<S extends Top, R = never>
5717
+ export interface withDecodingDefaultTypeKey<S extends Constraint, R = never>
5541
5718
  extends decodeTo<withDecodingDefaultKey<toType<S>, R>, optionalKey<S>>
5542
5719
  {
5543
5720
  readonly "Rebuild": withDecodingDefaultTypeKey<S, R>
@@ -5565,7 +5742,7 @@ export interface withDecodingDefaultTypeKey<S extends Top, R = never>
5565
5742
  * @category decoding
5566
5743
  * @since 4.0.0
5567
5744
  */
5568
- export function withDecodingDefaultTypeKey<S extends Top, R = never>(
5745
+ export function withDecodingDefaultTypeKey<S extends Constraint, R = never>(
5569
5746
  defaultValue: Effect.Effect<S["Type"], SchemaError, R>,
5570
5747
  options?: DecodingDefaultOptions
5571
5748
  ) {
@@ -5583,7 +5760,7 @@ export function withDecodingDefaultTypeKey<S extends Top, R = never>(
5583
5760
  * @category decoding
5584
5761
  * @since 3.10.0
5585
5762
  */
5586
- export interface withDecodingDefault<S extends Top, R = never> extends decodeTo<S, optional<toEncoded<S>>, R> {
5763
+ export interface withDecodingDefault<S extends Constraint, R = never> extends decodeTo<S, optional<toEncoded<S>>, R> {
5587
5764
  readonly "Rebuild": withDecodingDefault<S, R>
5588
5765
  }
5589
5766
 
@@ -5626,7 +5803,7 @@ export interface withDecodingDefault<S extends Top, R = never> extends decodeTo<
5626
5803
  * @category decoding
5627
5804
  * @since 3.10.0
5628
5805
  */
5629
- export function withDecodingDefault<S extends Top, R = never>(
5806
+ export function withDecodingDefault<S extends Constraint, R = never>(
5630
5807
  defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
5631
5808
  options?: DecodingDefaultOptions
5632
5809
  ) {
@@ -5645,7 +5822,7 @@ export function withDecodingDefault<S extends Top, R = never>(
5645
5822
  * @category decoding
5646
5823
  * @since 4.0.0
5647
5824
  */
5648
- export interface withDecodingDefaultType<S extends Top, R = never>
5825
+ export interface withDecodingDefaultType<S extends Constraint, R = never>
5649
5826
  extends decodeTo<withDecodingDefault<toType<S>, R>, optional<S>>
5650
5827
  {
5651
5828
  readonly "Rebuild": withDecodingDefaultType<S, R>
@@ -5678,7 +5855,7 @@ export interface withDecodingDefaultType<S extends Top, R = never>
5678
5855
  * @category decoding
5679
5856
  * @since 4.0.0
5680
5857
  */
5681
- export function withDecodingDefaultType<S extends Top, R = never>(
5858
+ export function withDecodingDefaultType<S extends Constraint, R = never>(
5682
5859
  defaultValue: Effect.Effect<S["Type"], SchemaError, R>,
5683
5860
  options?: DecodingDefaultOptions
5684
5861
  ) {
@@ -5833,8 +6010,8 @@ type Flatten<Schemas> = Schemas extends readonly [infer Head, ...infer Tail]
5833
6010
 
5834
6011
  type TaggedUnionUtils<
5835
6012
  Tag extends PropertyKey,
5836
- Members extends ReadonlyArray<Top & { readonly Type: { readonly [K in Tag]: PropertyKey } }>,
5837
- Flattened extends ReadonlyArray<Top & { readonly Type: { readonly [K in Tag]: PropertyKey } }> = Flatten<
6013
+ Members extends ReadonlyArray<Constraint & { readonly Type: { readonly [K in Tag]: PropertyKey } }>,
6014
+ Flattened extends ReadonlyArray<Constraint & { readonly Type: { readonly [K in Tag]: PropertyKey } }> = Flatten<
5838
6015
  Members
5839
6016
  >
5840
6017
  > = {
@@ -5868,7 +6045,7 @@ type TaggedUnionUtils<
5868
6045
  */
5869
6046
  export type toTaggedUnion<
5870
6047
  Tag extends PropertyKey,
5871
- Members extends ReadonlyArray<Top & { readonly Type: { readonly [K in Tag]: PropertyKey } }>
6048
+ Members extends ReadonlyArray<Constraint & { readonly Type: { readonly [K in Tag]: PropertyKey } }>
5872
6049
  > = Union<Members> & TaggedUnionUtils<Tag, Members>
5873
6050
 
5874
6051
  /**
@@ -5896,7 +6073,7 @@ export type toTaggedUnion<
5896
6073
  * @since 4.0.0
5897
6074
  */
5898
6075
  export function toTaggedUnion<const Tag extends PropertyKey>(tag: Tag) {
5899
- return <const Members extends ReadonlyArray<Top & { readonly Type: { readonly [K in Tag]: PropertyKey } }>>(
6076
+ return <const Members extends ReadonlyArray<Constraint & { readonly Type: { readonly [K in Tag]: PropertyKey } }>>(
5900
6077
  self: Union<Members>
5901
6078
  ): toTaggedUnion<Tag, Members> => {
5902
6079
  const cases: Record<PropertyKey, unknown> = {}
@@ -5907,7 +6084,7 @@ export function toTaggedUnion<const Tag extends PropertyKey>(tag: Tag) {
5907
6084
 
5908
6085
  return Object.assign(self, { cases, isAnyOf, guards, match }) as any
5909
6086
 
5910
- function walk(schema: Top) {
6087
+ function walk(schema: Constraint) {
5911
6088
  const ast = schema.ast
5912
6089
 
5913
6090
  if (
@@ -5950,17 +6127,19 @@ export function toTaggedUnion<const Tag extends PropertyKey>(tag: Tag) {
5950
6127
  * @category models
5951
6128
  * @since 4.0.0
5952
6129
  */
5953
- export interface TaggedUnion<Cases extends Record<string, Top>> extends
5954
- Bottom<
5955
- { [K in keyof Cases]: Cases[K]["Type"] }[keyof Cases],
5956
- { [K in keyof Cases]: Cases[K]["Encoded"] }[keyof Cases],
5957
- { [K in keyof Cases]: Cases[K]["DecodingServices"] }[keyof Cases],
5958
- { [K in keyof Cases]: Cases[K]["EncodingServices"] }[keyof Cases],
6130
+ export interface TaggedUnion<Cases extends Record<string, Constraint>> extends
6131
+ BottomLazy<
5959
6132
  SchemaAST.Union<SchemaAST.Objects>,
5960
- TaggedUnion<Cases>,
5961
- { [K in keyof Cases]: Cases[K]["~type.make"] }[keyof Cases]
6133
+ TaggedUnion<Cases>
5962
6134
  >
5963
6135
  {
6136
+ readonly "Type": { [K in keyof Cases]: Cases[K]["Type"] }[keyof Cases]
6137
+ readonly "Encoded": { [K in keyof Cases]: Cases[K]["Encoded"] }[keyof Cases]
6138
+ readonly "DecodingServices": { [K in keyof Cases]: Cases[K]["DecodingServices"] }[keyof Cases]
6139
+ readonly "EncodingServices": { [K in keyof Cases]: Cases[K]["EncodingServices"] }[keyof Cases]
6140
+ readonly "~type.make.in": { [K in keyof Cases]: Cases[K]["~type.make"] }[keyof Cases]
6141
+ readonly "~type.make": { [K in keyof Cases]: Cases[K]["~type.make"] }[keyof Cases]
6142
+ readonly "Iso": { [K in keyof Cases]: Cases[K]["Type"] }[keyof Cases]
5964
6143
  readonly cases: Cases
5965
6144
  readonly isAnyOf: <const Keys>(
5966
6145
  keys: ReadonlyArray<Keys>
@@ -6023,17 +6202,10 @@ export function TaggedUnion<const CasesByTag extends Record<string, Struct.Field
6023
6202
  * @since 4.0.0
6024
6203
  */
6025
6204
  export interface Opaque<Self, S extends Top, Brand> extends
6026
- Bottom<
6027
- Self,
6028
- S["Encoded"],
6029
- S["DecodingServices"],
6030
- S["EncodingServices"],
6205
+ BottomLazy<
6031
6206
  S["ast"],
6032
6207
  S["Rebuild"],
6033
- S["~type.make.in"],
6034
- S["Iso"],
6035
6208
  S["~type.parameters"],
6036
- S["~type.make"],
6037
6209
  S["~type.mutability"],
6038
6210
  S["~type.optionality"],
6039
6211
  S["~type.constructor.default"],
@@ -6041,6 +6213,13 @@ export interface Opaque<Self, S extends Top, Brand> extends
6041
6213
  S["~encoded.optionality"]
6042
6214
  >
6043
6215
  {
6216
+ readonly "Type": Self
6217
+ readonly "Encoded": S["Encoded"]
6218
+ readonly "DecodingServices": S["DecodingServices"]
6219
+ readonly "EncodingServices": S["EncodingServices"]
6220
+ readonly "~type.make.in": S["~type.make.in"]
6221
+ readonly "~type.make": S["~type.make"]
6222
+ readonly "Iso": S["Iso"]
6044
6223
  new(_: never): S["Type"] & Brand
6045
6224
  }
6046
6225
 
@@ -6119,7 +6298,7 @@ export function instanceOf<C extends abstract new(...args: any) => any, Iso = In
6119
6298
  * @since 4.0.0
6120
6299
  */
6121
6300
  export function link<T>() {
6122
- return <To extends Top>(
6301
+ return <To extends Constraint>(
6123
6302
  encodeTo: To,
6124
6303
  transformation: {
6125
6304
  readonly decode: SchemaGetter.Getter<T, NoInfer<To["Type"]>>
@@ -8132,7 +8311,7 @@ export function isPropertiesLengthBetween(minimum: number, maximum: number, anno
8132
8311
  * @category Object checks
8133
8312
  * @since 4.0.0
8134
8313
  */
8135
- export function isPropertyNames(keySchema: Top, annotations?: Annotations.Filter) {
8314
+ export function isPropertyNames(keySchema: Constraint, annotations?: Annotations.Filter) {
8136
8315
  const propertyNames = toEncoded(keySchema)
8137
8316
  const parser = SchemaParser._issue(propertyNames.ast)
8138
8317
  return makeFilter<object>(
@@ -8258,7 +8437,7 @@ export const Char: Char = String.check(isLengthBetween(1, 1))
8258
8437
  * @category Option
8259
8438
  * @since 3.10.0
8260
8439
  */
8261
- export interface Option<A extends Top> extends
8440
+ export interface Option<A extends Constraint> extends
8262
8441
  declareConstructor<
8263
8442
  Option_.Option<A["Type"]>,
8264
8443
  Option_.Option<A["Encoded"]>,
@@ -8281,7 +8460,7 @@ export interface Option<A extends Top> extends
8281
8460
  * @category Option
8282
8461
  * @since 4.0.0
8283
8462
  */
8284
- export type OptionIso<A extends Top> =
8463
+ export type OptionIso<A extends Constraint> =
8285
8464
  | { readonly _tag: "None" }
8286
8465
  | { readonly _tag: "Some"; readonly value: A["Iso"] }
8287
8466
 
@@ -8291,7 +8470,7 @@ export type OptionIso<A extends Top> =
8291
8470
  * @category Option
8292
8471
  * @since 3.10.0
8293
8472
  */
8294
- export function Option<A extends Top>(value: A): Option<A> {
8473
+ export function Option<A extends Constraint>(value: A): Option<A> {
8295
8474
  const schema = declareConstructor<
8296
8475
  Option_.Option<A["Type"]>,
8297
8476
  Option_.Option<A["Encoded"]>,
@@ -8360,7 +8539,7 @@ export function Option<A extends Top>(value: A): Option<A> {
8360
8539
  * @category Option
8361
8540
  * @since 3.10.0
8362
8541
  */
8363
- export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<S>>, NullOr<S>> {
8542
+ export interface OptionFromNullOr<S extends Constraint> extends decodeTo<Option<toType<S>>, NullOr<S>> {
8364
8543
  readonly "Rebuild": OptionFromNullOr<S>
8365
8544
  }
8366
8545
 
@@ -8375,7 +8554,7 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
8375
8554
  * @category Option
8376
8555
  * @since 3.10.0
8377
8556
  */
8378
- export function OptionFromNullOr<S extends Top>(schema: S): OptionFromNullOr<S> {
8557
+ export function OptionFromNullOr<S extends Constraint>(schema: S): OptionFromNullOr<S> {
8379
8558
  return NullOr(schema).pipe(decodeTo(
8380
8559
  Option(toType(schema)),
8381
8560
  SchemaTransformation.optionFromNullOr()
@@ -8388,7 +8567,7 @@ export function OptionFromNullOr<S extends Top>(schema: S): OptionFromNullOr<S>
8388
8567
  * @category Option
8389
8568
  * @since 3.10.0
8390
8569
  */
8391
- export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<toType<S>>, UndefinedOr<S>> {
8570
+ export interface OptionFromUndefinedOr<S extends Constraint> extends decodeTo<Option<toType<S>>, UndefinedOr<S>> {
8392
8571
  readonly "Rebuild": OptionFromUndefinedOr<S>
8393
8572
  }
8394
8573
 
@@ -8404,7 +8583,7 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
8404
8583
  * @category Option
8405
8584
  * @since 3.10.0
8406
8585
  */
8407
- export function OptionFromUndefinedOr<S extends Top>(schema: S): OptionFromUndefinedOr<S> {
8586
+ export function OptionFromUndefinedOr<S extends Constraint>(schema: S): OptionFromUndefinedOr<S> {
8408
8587
  return UndefinedOr(schema).pipe(decodeTo(
8409
8588
  Option(toType(schema)),
8410
8589
  SchemaTransformation.optionFromUndefinedOr()
@@ -8417,7 +8596,7 @@ export function OptionFromUndefinedOr<S extends Top>(schema: S): OptionFromUndef
8417
8596
  * @category Option
8418
8597
  * @since 3.10.0
8419
8598
  */
8420
- export interface OptionFromNullishOr<S extends Top> extends decodeTo<Option<toType<S>>, NullishOr<S>> {
8599
+ export interface OptionFromNullishOr<S extends Constraint> extends decodeTo<Option<toType<S>>, NullishOr<S>> {
8421
8600
  readonly "Rebuild": OptionFromNullishOr<S>
8422
8601
  }
8423
8602
 
@@ -8434,7 +8613,7 @@ export interface OptionFromNullishOr<S extends Top> extends decodeTo<Option<toTy
8434
8613
  * @category Option
8435
8614
  * @since 3.10.0
8436
8615
  */
8437
- export function OptionFromNullishOr<S extends Top>(
8616
+ export function OptionFromNullishOr<S extends Constraint>(
8438
8617
  schema: S,
8439
8618
  options?: {
8440
8619
  onNoneEncoding: null | undefined
@@ -8452,7 +8631,7 @@ export function OptionFromNullishOr<S extends Top>(
8452
8631
  * @category Option
8453
8632
  * @since 4.0.0
8454
8633
  */
8455
- export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<toType<S>>, optionalKey<S>> {
8634
+ export interface OptionFromOptionalKey<S extends Constraint> extends decodeTo<Option<toType<S>>, optionalKey<S>> {
8456
8635
  readonly "Rebuild": OptionFromOptionalKey<S>
8457
8636
  }
8458
8637
 
@@ -8467,7 +8646,7 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
8467
8646
  * @category Option
8468
8647
  * @since 4.0.0
8469
8648
  */
8470
- export function OptionFromOptionalKey<S extends Top>(schema: S): OptionFromOptionalKey<S> {
8649
+ export function OptionFromOptionalKey<S extends Constraint>(schema: S): OptionFromOptionalKey<S> {
8471
8650
  return optionalKey(schema).pipe(decodeTo(
8472
8651
  Option(toType(schema)),
8473
8652
  SchemaTransformation.optionFromOptionalKey()
@@ -8480,7 +8659,7 @@ export function OptionFromOptionalKey<S extends Top>(schema: S): OptionFromOptio
8480
8659
  * @category Option
8481
8660
  * @since 4.0.0
8482
8661
  */
8483
- export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toType<S>>, optional<S>> {
8662
+ export interface OptionFromOptional<S extends Constraint> extends decodeTo<Option<toType<S>>, optional<S>> {
8484
8663
  readonly "Rebuild": OptionFromOptional<S>
8485
8664
  }
8486
8665
 
@@ -8497,7 +8676,7 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
8497
8676
  * @category Option
8498
8677
  * @since 4.0.0
8499
8678
  */
8500
- export function OptionFromOptional<S extends Top>(schema: S): OptionFromOptional<S> {
8679
+ export function OptionFromOptional<S extends Constraint>(schema: S): OptionFromOptional<S> {
8501
8680
  return optional(schema).pipe(decodeTo(
8502
8681
  Option(toType(schema)),
8503
8682
  SchemaTransformation.optionFromOptional<any>()
@@ -8510,7 +8689,9 @@ export function OptionFromOptional<S extends Top>(schema: S): OptionFromOptional
8510
8689
  * @category Option
8511
8690
  * @since 4.0.0
8512
8691
  */
8513
- export interface OptionFromOptionalNullOr<S extends Top> extends decodeTo<Option<toType<S>>, optional<NullOr<S>>> {
8692
+ export interface OptionFromOptionalNullOr<S extends Constraint>
8693
+ extends decodeTo<Option<toType<S>>, optional<NullOr<S>>>
8694
+ {
8514
8695
  readonly "Rebuild": OptionFromOptionalNullOr<S>
8515
8696
  }
8516
8697
 
@@ -8528,7 +8709,7 @@ export interface OptionFromOptionalNullOr<S extends Top> extends decodeTo<Option
8528
8709
  * @category Option
8529
8710
  * @since 4.0.0
8530
8711
  */
8531
- export function OptionFromOptionalNullOr<S extends Top>(
8712
+ export function OptionFromOptionalNullOr<S extends Constraint>(
8532
8713
  schema: S,
8533
8714
  options?: {
8534
8715
  readonly onNoneEncoding: "omit" | null | undefined
@@ -8555,7 +8736,7 @@ export function OptionFromOptionalNullOr<S extends Top>(
8555
8736
  * @category schemas
8556
8737
  * @since 4.0.0
8557
8738
  */
8558
- export interface Result<A extends Top, E extends Top> extends
8739
+ export interface Result<A extends Constraint, E extends Constraint> extends
8559
8740
  declareConstructor<
8560
8741
  Result_.Result<A["Type"], E["Type"]>,
8561
8742
  Result_.Result<A["Encoded"], E["Encoded"]>,
@@ -8579,7 +8760,7 @@ export interface Result<A extends Top, E extends Top> extends
8579
8760
  * @category schemas
8580
8761
  * @since 4.0.0
8581
8762
  */
8582
- export type ResultIso<A extends Top, E extends Top> =
8763
+ export type ResultIso<A extends Constraint, E extends Constraint> =
8583
8764
  | { readonly _tag: "Success"; readonly success: A["Iso"] }
8584
8765
  | { readonly _tag: "Failure"; readonly failure: E["Iso"] }
8585
8766
 
@@ -8589,7 +8770,7 @@ export type ResultIso<A extends Top, E extends Top> =
8589
8770
  * @category schemas
8590
8771
  * @since 4.0.0
8591
8772
  */
8592
- export function Result<A extends Top, E extends Top>(
8773
+ export function Result<A extends Constraint, E extends Constraint>(
8593
8774
  success: A,
8594
8775
  failure: E
8595
8776
  ): Result<A, E> {
@@ -8672,7 +8853,7 @@ export function Result<A extends Top, E extends Top>(
8672
8853
  * @category Redacted
8673
8854
  * @since 3.10.0
8674
8855
  */
8675
- export interface Redacted<S extends Top> extends
8856
+ export interface Redacted<S extends Constraint> extends
8676
8857
  declareConstructor<
8677
8858
  Redacted_.Redacted<S["Type"]>,
8678
8859
  Redacted_.Redacted<S["Encoded"]>,
@@ -8703,10 +8884,11 @@ export interface Redacted<S extends Top> extends
8703
8884
  * into JSON, it will fail with an error. This is useful when the wrapped schema is
8704
8885
  * sensitive and should not be exposed in JSON.
8705
8886
  *
8887
+ * @see {@link RedactedFromValue} for decoding raw values and wrapping them in `Redacted`.
8706
8888
  * @category Redacted
8707
8889
  * @since 3.10.0
8708
8890
  */
8709
- export function Redacted<S extends Top>(value: S, options?: {
8891
+ export function Redacted<S extends Constraint>(value: S, options?: {
8710
8892
  readonly label?: string | undefined
8711
8893
  readonly disallowJsonEncode?: boolean | undefined
8712
8894
  }): Redacted<S> {
@@ -8783,7 +8965,7 @@ export function Redacted<S extends Top>(value: S, options?: {
8783
8965
  * @category Redacted
8784
8966
  * @since 4.0.0
8785
8967
  */
8786
- export interface RedactedFromValue<S extends Top>
8968
+ export interface RedactedFromValue<S extends Constraint>
8787
8969
  extends decodeTo<Redacted<toType<S>>, middlewareDecoding<S, S["DecodingServices"]>>
8788
8970
  {
8789
8971
  readonly "Rebuild": RedactedFromValue<S>
@@ -8796,8 +8978,8 @@ export interface RedactedFromValue<S extends Top>
8796
8978
  * @category Redacted
8797
8979
  * @since 4.0.0
8798
8980
  */
8799
- export function redact<S extends Top>(schema: S): middlewareDecoding<S, S["DecodingServices"]> {
8800
- return schema.pipe(middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact)))
8981
+ export function redact<S extends Constraint>(schema: S): middlewareDecoding<S, S["DecodingServices"]> {
8982
+ return middlewareDecoding<S, S["DecodingServices"]>(Effect.mapErrorEager(SchemaIssue.redact))(schema)
8801
8983
  }
8802
8984
 
8803
8985
  /**
@@ -8805,10 +8987,11 @@ export function redact<S extends Top>(schema: S): middlewareDecoding<S, S["Decod
8805
8987
  * expects the input to already be a `Redacted` instance, this schema decodes
8806
8988
  * the raw value and wraps it.
8807
8989
  *
8990
+ * @see {@link Redacted} for schemas whose input is already a `Redacted` value.
8808
8991
  * @category Redacted
8809
8992
  * @since 4.0.0
8810
8993
  */
8811
- export function RedactedFromValue<S extends Top>(value: S, options?: {
8994
+ export function RedactedFromValue<S extends Constraint>(value: S, options?: {
8812
8995
  readonly label?: string | undefined
8813
8996
  readonly disallowEncode?: boolean | undefined
8814
8997
  }): RedactedFromValue<S> {
@@ -8837,7 +9020,7 @@ export function RedactedFromValue<S extends Top>(value: S, options?: {
8837
9020
  * @category CauseReason
8838
9021
  * @since 4.0.0
8839
9022
  */
8840
- export interface CauseReason<E extends Top, D extends Top> extends
9023
+ export interface CauseReason<E extends Constraint, D extends Constraint> extends
8841
9024
  declareConstructor<
8842
9025
  Cause_.Reason<E["Type"]>,
8843
9026
  Cause_.Reason<E["Encoded"]>,
@@ -8861,7 +9044,7 @@ export interface CauseReason<E extends Top, D extends Top> extends
8861
9044
  * @category CauseReason
8862
9045
  * @since 4.0.0
8863
9046
  */
8864
- export type CauseReasonIso<E extends Top, D extends Top> = {
9047
+ export type CauseReasonIso<E extends Constraint, D extends Constraint> = {
8865
9048
  readonly _tag: "Fail"
8866
9049
  readonly error: E["Iso"]
8867
9050
  } | {
@@ -8892,7 +9075,7 @@ export type CauseReasonIso<E extends Top, D extends Top> = {
8892
9075
  * @category CauseReason
8893
9076
  * @since 4.0.0
8894
9077
  */
8895
- export function CauseReason<E extends Top, D extends Top>(error: E, defect: D): CauseReason<E, D> {
9078
+ export function CauseReason<E extends Constraint, D extends Constraint>(error: E, defect: D): CauseReason<E, D> {
8896
9079
  const schema = declareConstructor<Cause_.Reason<E["Type"]>, Cause_.Reason<E["Encoded"]>, CauseReasonIso<E, D>>()(
8897
9080
  [error, defect],
8898
9081
  ([error, defect]) => (input, ast, options) => {
@@ -9010,7 +9193,7 @@ function causeReasonToFormatter<E>(error: Formatter<E>, defect: Formatter<unknow
9010
9193
  * @category Cause
9011
9194
  * @since 3.10.0
9012
9195
  */
9013
- export interface Cause<E extends Top, D extends Top> extends
9196
+ export interface Cause<E extends Constraint, D extends Constraint> extends
9014
9197
  declareConstructor<
9015
9198
  Cause_.Cause<E["Type"]>,
9016
9199
  Cause_.Cause<E["Encoded"]>,
@@ -9038,7 +9221,7 @@ export interface Cause<E extends Top, D extends Top> extends
9038
9221
  * @category Cause
9039
9222
  * @since 4.0.0
9040
9223
  */
9041
- export type CauseIso<E extends Top, D extends Top> = ReadonlyArray<CauseReasonIso<E, D>>
9224
+ export type CauseIso<E extends Constraint, D extends Constraint> = ReadonlyArray<CauseReasonIso<E, D>>
9042
9225
 
9043
9226
  /**
9044
9227
  * Creates a schema for `Cause` values using separate schemas for typed failures
@@ -9061,7 +9244,7 @@ export type CauseIso<E extends Top, D extends Top> = ReadonlyArray<CauseReasonIs
9061
9244
  * @category Cause
9062
9245
  * @since 3.10.0
9063
9246
  */
9064
- export function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<E, D> {
9247
+ export function Cause<E extends Constraint, D extends Constraint>(error: E, defect: D): Cause<E, D> {
9065
9248
  const schema = declareConstructor<Cause_.Cause<E["Type"]>, Cause_.Cause<E["Encoded"]>, CauseIso<E, D>>()(
9066
9249
  [error, defect],
9067
9250
  ([error, defect]) => {
@@ -9287,7 +9470,7 @@ export function Defect(options?: ErrorOptions): Defect {
9287
9470
  * @category Exit
9288
9471
  * @since 3.10.0
9289
9472
  */
9290
- export interface Exit<A extends Top, E extends Top, D extends Top> extends
9473
+ export interface Exit<A extends Constraint, E extends Constraint, D extends Constraint> extends
9291
9474
  declareConstructor<
9292
9475
  Exit_.Exit<A["Type"], E["Type"]>,
9293
9476
  Exit_.Exit<A["Encoded"], E["Encoded"]>,
@@ -9312,7 +9495,7 @@ export interface Exit<A extends Top, E extends Top, D extends Top> extends
9312
9495
  * @category Exit
9313
9496
  * @since 4.0.0
9314
9497
  */
9315
- export type ExitIso<A extends Top, E extends Top, D extends Top> = {
9498
+ export type ExitIso<A extends Constraint, E extends Constraint, D extends Constraint> = {
9316
9499
  readonly _tag: "Success"
9317
9500
  readonly value: A["Iso"]
9318
9501
  } | {
@@ -9332,7 +9515,11 @@ export type ExitIso<A extends Top, E extends Top, D extends Top> = {
9332
9515
  * @category Exit
9333
9516
  * @since 3.10.0
9334
9517
  */
9335
- export function Exit<A extends Top, E extends Top, D extends Top>(value: A, error: E, defect: D): Exit<A, E, D> {
9518
+ export function Exit<A extends Constraint, E extends Constraint, D extends Constraint>(
9519
+ value: A,
9520
+ error: E,
9521
+ defect: D
9522
+ ): Exit<A, E, D> {
9336
9523
  const schema = declareConstructor<
9337
9524
  Exit_.Exit<A["Type"], E["Type"]>,
9338
9525
  Exit_.Exit<A["Encoded"], E["Encoded"]>,
@@ -9439,7 +9626,7 @@ export function Exit<A extends Top, E extends Top, D extends Top>(value: A, erro
9439
9626
  * @category ReadonlyMap
9440
9627
  * @since 4.0.0
9441
9628
  */
9442
- export interface $ReadonlyMap<Key extends Top, Value extends Top> extends
9629
+ export interface $ReadonlyMap<Key extends Constraint, Value extends Constraint> extends
9443
9630
  declareConstructor<
9444
9631
  globalThis.ReadonlyMap<Key["Type"], Value["Type"]>,
9445
9632
  globalThis.ReadonlyMap<Key["Encoded"], Value["Encoded"]>,
@@ -9459,7 +9646,9 @@ export interface $ReadonlyMap<Key extends Top, Value extends Top> extends
9459
9646
  * @category ReadonlyMap
9460
9647
  * @since 4.0.0
9461
9648
  */
9462
- export type ReadonlyMapIso<Key extends Top, Value extends Top> = ReadonlyArray<readonly [Key["Iso"], Value["Iso"]]>
9649
+ export type ReadonlyMapIso<Key extends Constraint, Value extends Constraint> = ReadonlyArray<
9650
+ readonly [Key["Iso"], Value["Iso"]]
9651
+ >
9463
9652
 
9464
9653
  function oneOfArbitraries<T>(
9465
9654
  fc: typeof FastCheck,
@@ -9558,7 +9747,10 @@ function entriesArbitrary<K, V, Out>(
9558
9747
  * @category ReadonlyMap
9559
9748
  * @since 3.10.0
9560
9749
  */
9561
- export function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value: Value): $ReadonlyMap<Key, Value> {
9750
+ export function ReadonlyMap<Key extends Constraint, Value extends Constraint>(
9751
+ key: Key,
9752
+ value: Value
9753
+ ): $ReadonlyMap<Key, Value> {
9562
9754
  const schema = declareConstructor<
9563
9755
  globalThis.ReadonlyMap<Key["Type"], Value["Type"]>,
9564
9756
  globalThis.ReadonlyMap<Key["Encoded"], Value["Encoded"]>,
@@ -9619,7 +9811,7 @@ export function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value:
9619
9811
  * @category HashMap
9620
9812
  * @since 3.10.0
9621
9813
  */
9622
- export interface HashMap<Key extends Top, Value extends Top> extends
9814
+ export interface HashMap<Key extends Constraint, Value extends Constraint> extends
9623
9815
  declareConstructor<
9624
9816
  HashMap_.HashMap<Key["Type"], Value["Type"]>,
9625
9817
  HashMap_.HashMap<Key["Encoded"], Value["Encoded"]>,
@@ -9639,7 +9831,9 @@ export interface HashMap<Key extends Top, Value extends Top> extends
9639
9831
  * @category HashMap
9640
9832
  * @since 4.0.0
9641
9833
  */
9642
- export type HashMapIso<Key extends Top, Value extends Top> = ReadonlyArray<readonly [Key["Iso"], Value["Iso"]]>
9834
+ export type HashMapIso<Key extends Constraint, Value extends Constraint> = ReadonlyArray<
9835
+ readonly [Key["Iso"], Value["Iso"]]
9836
+ >
9643
9837
 
9644
9838
  /**
9645
9839
  * Schema for hash maps whose keys and values conform to the provided schemas.
@@ -9647,7 +9841,7 @@ export type HashMapIso<Key extends Top, Value extends Top> = ReadonlyArray<reado
9647
9841
  * @category HashMap
9648
9842
  * @since 3.10.0
9649
9843
  */
9650
- export function HashMap<Key extends Top, Value extends Top>(key: Key, value: Value): HashMap<Key, Value> {
9844
+ export function HashMap<Key extends Constraint, Value extends Constraint>(key: Key, value: Value): HashMap<Key, Value> {
9651
9845
  const schema = declareConstructor<
9652
9846
  HashMap_.HashMap<Key["Type"], Value["Type"]>,
9653
9847
  HashMap_.HashMap<Key["Encoded"], Value["Encoded"]>,
@@ -9709,7 +9903,7 @@ export function HashMap<Key extends Top, Value extends Top>(key: Key, value: Val
9709
9903
  * @category ReadonlySet
9710
9904
  * @since 4.0.0
9711
9905
  */
9712
- export interface $ReadonlySet<Value extends Top> extends
9906
+ export interface $ReadonlySet<Value extends Constraint> extends
9713
9907
  declareConstructor<
9714
9908
  globalThis.ReadonlySet<Value["Type"]>,
9715
9909
  globalThis.ReadonlySet<Value["Encoded"]>,
@@ -9728,7 +9922,7 @@ export interface $ReadonlySet<Value extends Top> extends
9728
9922
  * @category ReadonlySet
9729
9923
  * @since 4.0.0
9730
9924
  */
9731
- export type ReadonlySetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>
9925
+ export type ReadonlySetIso<Value extends Constraint> = ReadonlyArray<Value["Iso"]>
9732
9926
 
9733
9927
  /**
9734
9928
  * Schema for readonly sets whose values conform to the provided element schema.
@@ -9736,7 +9930,7 @@ export type ReadonlySetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>
9736
9930
  * @category ReadonlySet
9737
9931
  * @since 3.10.0
9738
9932
  */
9739
- export function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value> {
9933
+ export function ReadonlySet<Value extends Constraint>(value: Value): $ReadonlySet<Value> {
9740
9934
  const schema = declareConstructor<
9741
9935
  globalThis.ReadonlySet<Value["Type"]>,
9742
9936
  globalThis.ReadonlySet<Value["Encoded"]>,
@@ -9798,7 +9992,7 @@ export function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value
9798
9992
  * @category HashSet
9799
9993
  * @since 3.10.0
9800
9994
  */
9801
- export interface HashSet<Value extends Top> extends
9995
+ export interface HashSet<Value extends Constraint> extends
9802
9996
  declareConstructor<
9803
9997
  HashSet_.HashSet<Value["Type"]>,
9804
9998
  HashSet_.HashSet<Value["Encoded"]>,
@@ -9817,7 +10011,7 @@ export interface HashSet<Value extends Top> extends
9817
10011
  * @category HashSet
9818
10012
  * @since 4.0.0
9819
10013
  */
9820
- export type HashSetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>
10014
+ export type HashSetIso<Value extends Constraint> = ReadonlyArray<Value["Iso"]>
9821
10015
 
9822
10016
  /**
9823
10017
  * Schema for hash sets whose values conform to the provided element schema.
@@ -9825,7 +10019,7 @@ export type HashSetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>
9825
10019
  * @category HashSet
9826
10020
  * @since 3.10.0
9827
10021
  */
9828
- export function HashSet<Value extends Top>(value: Value): HashSet<Value> {
10022
+ export function HashSet<Value extends Constraint>(value: Value): HashSet<Value> {
9829
10023
  const schema = declareConstructor<
9830
10024
  HashSet_.HashSet<Value["Type"]>,
9831
10025
  HashSet_.HashSet<Value["Encoded"]>,
@@ -9887,7 +10081,7 @@ export function HashSet<Value extends Top>(value: Value): HashSet<Value> {
9887
10081
  * @category Chunk
9888
10082
  * @since 3.10.0
9889
10083
  */
9890
- export interface Chunk<Value extends Top> extends
10084
+ export interface Chunk<Value extends Constraint> extends
9891
10085
  declareConstructor<
9892
10086
  Chunk_.Chunk<Value["Type"]>,
9893
10087
  Chunk_.Chunk<Value["Encoded"]>,
@@ -9913,7 +10107,7 @@ export interface Chunk<Value extends Top> extends
9913
10107
  * @category Chunk
9914
10108
  * @since 4.0.0
9915
10109
  */
9916
- export type ChunkIso<Value extends Top> = ReadonlyArray<Value["Iso"]>
10110
+ export type ChunkIso<Value extends Constraint> = ReadonlyArray<Value["Iso"]>
9917
10111
 
9918
10112
  /**
9919
10113
  * Schema for chunks whose values conform to the provided element schema.
@@ -9921,7 +10115,7 @@ export type ChunkIso<Value extends Top> = ReadonlyArray<Value["Iso"]>
9921
10115
  * @category Chunk
9922
10116
  * @since 3.10.0
9923
10117
  */
9924
- export function Chunk<Value extends Top>(value: Value): Chunk<Value> {
10118
+ export function Chunk<Value extends Constraint>(value: Value): Chunk<Value> {
9925
10119
  const schema = declareConstructor<
9926
10120
  Chunk_.Chunk<Value["Type"]>,
9927
10121
  Chunk_.Chunk<Value["Encoded"]>,
@@ -10139,7 +10333,7 @@ type DateArbitraryConstraints = FastCheck.DateConstraints & {
10139
10333
  }
10140
10334
 
10141
10335
  function dateArbitraryConstraints<T = globalThis.Date>(
10142
- constraint: Annotations.ToArbitrary.Constraint | undefined,
10336
+ constraint: Annotations.ToArbitrary.GenerationConstraint | undefined,
10143
10337
  ordered: Annotations.ToArbitrary.OrderedConstraint<T> | undefined,
10144
10338
  base?: DateArbitraryConstraints | undefined,
10145
10339
  toDate?: (value: T) => globalThis.Date
@@ -10697,7 +10891,7 @@ export const UnknownFromJsonString: UnknownFromJsonString = fromJsonString(Unkno
10697
10891
  * @category models
10698
10892
  * @since 4.0.0
10699
10893
  */
10700
- export interface fromJsonString<S extends Top> extends decodeTo<S, String> {
10894
+ export interface fromJsonString<S extends Constraint> extends decodeTo<S, String> {
10701
10895
  readonly "Rebuild": fromJsonString<S>
10702
10896
  }
10703
10897
 
@@ -10767,7 +10961,7 @@ export interface fromJsonString<S extends Top> extends decodeTo<S, String> {
10767
10961
  * @category constructors
10768
10962
  * @since 4.0.0
10769
10963
  */
10770
- export function fromJsonString<S extends Top>(schema: S): fromJsonString<S> {
10964
+ export function fromJsonString<S extends Constraint>(schema: S): fromJsonString<S> {
10771
10965
  return String.annotate({
10772
10966
  expected: "a string that will be decoded as JSON",
10773
10967
  contentMediaType: "application/json",
@@ -10919,7 +11113,7 @@ export const FormData: FormData = instanceOf(globalThis.FormData, {
10919
11113
  * @category FormData
10920
11114
  * @since 4.0.0
10921
11115
  */
10922
- export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
11116
+ export interface fromFormData<S extends Constraint> extends decodeTo<S, FormData> {
10923
11117
  readonly "Rebuild": fromFormData<S>
10924
11118
  }
10925
11119
 
@@ -10939,10 +11133,8 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
10939
11133
  *
10940
11134
  * You can express nested values using bracket notation.
10941
11135
  *
10942
- * If you want to decode values that are not strings, use
10943
- * `Schema.toCodecStringTree` with the `keepDeclarations: true` option.
10944
- * This serializer preserves values such as numbers and `Blob` objects when
10945
- * compatible with the schema.
11136
+ * If you want to decode string fields into non-string primitive values, use
11137
+ * `Schema.toCodecStringTree`.
10946
11138
  *
10947
11139
  * **Example** (Decoding a flat structure)
10948
11140
  *
@@ -10996,8 +11188,7 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
10996
11188
  * Schema.toCodecStringTree(
10997
11189
  * Schema.Struct({
10998
11190
  * a: Schema.Int
10999
- * }),
11000
- * { keepDeclarations: true }
11191
+ * })
11001
11192
  * )
11002
11193
  * )
11003
11194
  *
@@ -11011,7 +11202,7 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
11011
11202
  * @category decoding
11012
11203
  * @since 4.0.0
11013
11204
  */
11014
- export function fromFormData<S extends Top>(schema: S): fromFormData<S> {
11205
+ export function fromFormData<S extends Constraint>(schema: S): fromFormData<S> {
11015
11206
  return FormData.pipe(decodeTo(schema, SchemaTransformation.fromFormData))
11016
11207
  }
11017
11208
 
@@ -11060,7 +11251,7 @@ export const URLSearchParams: URLSearchParams = instanceOf(globalThis.URLSearchP
11060
11251
  * @category search params
11061
11252
  * @since 4.0.0
11062
11253
  */
11063
- export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearchParams> {
11254
+ export interface fromURLSearchParams<S extends Constraint> extends decodeTo<S, URLSearchParams> {
11064
11255
  readonly "Rebuild": fromURLSearchParams<S>
11065
11256
  }
11066
11257
 
@@ -11144,7 +11335,7 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
11144
11335
  * @category decoding
11145
11336
  * @since 4.0.0
11146
11337
  */
11147
- export function fromURLSearchParams<S extends Top>(schema: S): fromURLSearchParams<S> {
11338
+ export function fromURLSearchParams<S extends Constraint>(schema: S): fromURLSearchParams<S> {
11148
11339
  return URLSearchParams.pipe(decodeTo(schema, SchemaTransformation.fromURLSearchParams))
11149
11340
  }
11150
11341
 
@@ -12163,18 +12354,11 @@ export const DateTimeZonedFromString: DateTimeZonedFromString = DateTimeZonedStr
12163
12354
  * @category models
12164
12355
  * @since 3.10.0
12165
12356
  */
12166
- export interface Class<Self, S extends Top & { readonly fields: Struct.Fields }, Inherited> extends
12167
- Bottom<
12168
- Self,
12169
- S["Encoded"],
12170
- S["DecodingServices"],
12171
- S["EncodingServices"],
12357
+ export interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields }, Inherited> extends
12358
+ BottomLazy<
12172
12359
  SchemaAST.Declaration,
12173
12360
  decodeTo<declareConstructor<Self, S["Encoded"], readonly [S], S["Iso"]>, S>,
12174
- RequiredKeys<S["~type.make.in"]> extends never ? void | S["~type.make.in"] : S["~type.make.in"],
12175
- S["Iso"],
12176
12361
  readonly [S],
12177
- Self,
12178
12362
  S["~type.mutability"],
12179
12363
  S["~type.optionality"],
12180
12364
  S["~type.constructor.default"],
@@ -12182,6 +12366,14 @@ export interface Class<Self, S extends Top & { readonly fields: Struct.Fields },
12182
12366
  S["~encoded.optionality"]
12183
12367
  >
12184
12368
  {
12369
+ readonly "Type": Self
12370
+ readonly "Encoded": S["Encoded"]
12371
+ readonly "DecodingServices": S["DecodingServices"]
12372
+ readonly "EncodingServices": S["EncodingServices"]
12373
+ readonly "~type.make.in": RequiredKeys<S["~type.make.in"]> extends never ? void | S["~type.make.in"]
12374
+ : S["~type.make.in"]
12375
+ readonly "~type.make": Self
12376
+ readonly "Iso": S["Iso"]
12185
12377
  new(
12186
12378
  ...args: {} extends S["~type.make.in"] ? [props?: S["~type.make.in"], options?: MakeOptions]
12187
12379
  : [props: S["~type.make.in"], options?: MakeOptions]
@@ -12368,7 +12560,7 @@ function getClassTypeId(identifier: string) {
12368
12560
  return `~effect/Schema/Class/${identifier}`
12369
12561
  }
12370
12562
 
12371
- function getClassSchemaFactory<S extends Top>(
12563
+ function getClassSchemaFactory<S extends Constraint>(
12372
12564
  from: S,
12373
12565
  identifier: string,
12374
12566
  annotations: Annotations.Declaration<any, readonly [S]> | undefined
@@ -12377,34 +12569,34 @@ function getClassSchemaFactory<S extends Top>(
12377
12569
  return <Self extends (new(...args: ReadonlyArray<any>) => any) & { readonly identifier: string }>(
12378
12570
  self: Self
12379
12571
  ): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S> => {
12380
- if (memo === undefined) {
12381
- const transformation = getClassTransformation(self)
12382
- const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
12383
- new SchemaAST.Declaration(
12384
- [from.ast],
12385
- () => (input, ast) => {
12386
- return input instanceof self ||
12387
- Predicate.hasProperty(input, getClassTypeId(identifier)) ?
12388
- Effect.succeed(input) :
12389
- Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
12390
- },
12391
- {
12392
- identifier,
12393
- [SchemaAST.ClassTypeId]: ([from]: readonly [SchemaAST.AST]) => new SchemaAST.Link(from, transformation),
12394
- toCodec: ([from]: readonly [Codec<S["Encoded"]>]) => new SchemaAST.Link(from.ast, transformation),
12395
- toArbitrary: ([from]: readonly [Annotations.ToArbitrary.TypeParameter<S["Type"]>]) => () => ({
12396
- arbitrary: from.arbitrary.map((args: S["Type"]) => new self(args)),
12397
- terminal: from.terminal?.map((args: S["Type"]) => new self(args))
12398
- }),
12399
- toFormatter: ([from]: readonly [Formatter<S["Type"]>]) => (t: Self) => `${self.identifier}(${from(t)})`,
12400
- "~sentinels": SchemaAST.collectSentinels(from.ast),
12401
- ...annotations
12402
- }
12403
- )
12404
- )
12405
- memo = from.pipe(decodeTo(to, transformation))
12572
+ if (memo !== undefined) {
12573
+ return memo
12406
12574
  }
12407
- return memo
12575
+ const transformation = getClassTransformation(self)
12576
+ const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
12577
+ new SchemaAST.Declaration(
12578
+ [from.ast],
12579
+ () => (input, ast) => {
12580
+ return input instanceof self ||
12581
+ Predicate.hasProperty(input, getClassTypeId(identifier)) ?
12582
+ Effect.succeed(input) :
12583
+ Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)))
12584
+ },
12585
+ {
12586
+ identifier,
12587
+ [SchemaAST.ClassTypeId]: ([from]: readonly [SchemaAST.AST]) => new SchemaAST.Link(from, transformation),
12588
+ toCodec: ([from]: readonly [Codec<S["Encoded"]>]) => new SchemaAST.Link(from.ast, transformation),
12589
+ toArbitrary: ([from]: readonly [Annotations.ToArbitrary.TypeParameter<S["Type"]>]) => () => ({
12590
+ arbitrary: from.arbitrary.map((args: S["Type"]) => new self(args)),
12591
+ terminal: from.terminal?.map((args: S["Type"]) => new self(args))
12592
+ }),
12593
+ toFormatter: ([from]: readonly [Formatter<S["Type"]>]) => (t: Self) => `${self.identifier}(${from(t)})`,
12594
+ "~sentinels": SchemaAST.collectSentinels(from.ast),
12595
+ ...annotations
12596
+ }
12597
+ )
12598
+ )
12599
+ return memo = decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>(to, transformation)(from)
12408
12600
  }
12409
12601
  }
12410
12602
 
@@ -13122,7 +13314,7 @@ export type LazyArbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>
13122
13314
  * @category Arbitrary
13123
13315
  * @since 4.0.0
13124
13316
  */
13125
- export function toArbitraryLazy<S extends Top>(schema: S): LazyArbitrary<S["Type"]> {
13317
+ export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<S["Type"]> {
13126
13318
  const lawc = InternalArbitrary.memoized(schema.ast)
13127
13319
  return (fc) => lawc(fc, {})
13128
13320
  }
@@ -13156,12 +13348,12 @@ export function toArbitraryLazy<S extends Top>(schema: S): LazyArbitrary<S["Type
13156
13348
  * @category Arbitrary
13157
13349
  * @since 4.0.0
13158
13350
  */
13159
- export function toArbitrary<S extends Top>(schema: S): FastCheck.Arbitrary<S["Type"]>
13160
- export function toArbitrary<S extends Top>(
13351
+ export function toArbitrary<S extends Constraint>(schema: S): FastCheck.Arbitrary<S["Type"]>
13352
+ export function toArbitrary<S extends Constraint>(
13161
13353
  schema: S,
13162
13354
  options: { readonly report: true }
13163
13355
  ): Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>>
13164
- export function toArbitrary<S extends Top>(
13356
+ export function toArbitrary<S extends Constraint>(
13165
13357
  schema: S,
13166
13358
  options?: { readonly report?: boolean }
13167
13359
  ): FastCheck.Arbitrary<S["Type"]> | Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>> {
@@ -13212,14 +13404,14 @@ export function overrideToFormatter<S extends Top>(toFormatter: () => Formatter<
13212
13404
  * @category Formatter
13213
13405
  * @since 4.0.0
13214
13406
  */
13215
- export function toFormatter<T>(schema: Schema<T>, options?: {
13407
+ export function toFormatter<S extends Constraint>(schema: S, options?: {
13216
13408
  readonly onBefore?:
13217
13409
  | ((ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Formatter<any>) => Formatter<any> | undefined)
13218
13410
  | undefined
13219
- }): Formatter<T> {
13411
+ }): Formatter<S["Type"]> {
13220
13412
  return recur(schema.ast)
13221
13413
 
13222
- function recur(ast: SchemaAST.AST): Formatter<T> {
13414
+ function recur(ast: SchemaAST.AST): Formatter<S["Type"]> {
13223
13415
  // ---------------------------------------------
13224
13416
  // handle annotation
13225
13417
  // ---------------------------------------------
@@ -13403,7 +13595,7 @@ export function toEquivalence<T>(schema: Schema<T>): Equivalence.Equivalence<T>
13403
13595
  * @category Representation
13404
13596
  * @since 4.0.0
13405
13597
  */
13406
- export function toRepresentation(schema: Top): SchemaRepresentation.Document {
13598
+ export function toRepresentation(schema: Constraint): SchemaRepresentation.Document {
13407
13599
  return InternalStandard.fromAST(schema.ast)
13408
13600
  }
13409
13601
 
@@ -13504,7 +13696,10 @@ export interface ToJsonSchemaOptions {
13504
13696
  * @category converting
13505
13697
  * @since 4.0.0
13506
13698
  */
13507
- export function toJsonSchemaDocument(schema: Top, options?: ToJsonSchemaOptions): JsonSchema.Document<"draft-2020-12"> {
13699
+ export function toJsonSchemaDocument(
13700
+ schema: Constraint,
13701
+ options?: ToJsonSchemaOptions
13702
+ ): JsonSchema.Document<"draft-2020-12"> {
13508
13703
  const sd = toRepresentation(schema)
13509
13704
  const jd = InternalStandard.toJsonSchemaDocument(sd, options)
13510
13705
  return {
@@ -13518,6 +13713,34 @@ export function toJsonSchemaDocument(schema: Top, options?: ToJsonSchemaOptions)
13518
13713
  // Canonical Codecs
13519
13714
  // -----------------------------------------------------------------------------
13520
13715
 
13716
+ /**
13717
+ * Type-level representation returned by {@link toCodecJson}.
13718
+ *
13719
+ * @category Canonical Codecs
13720
+ * @since 4.0.0
13721
+ */
13722
+ export interface toCodecJson<S extends Constraint> extends
13723
+ BottomLazy<
13724
+ S["ast"],
13725
+ toCodecJson<S>,
13726
+ S["~type.parameters"],
13727
+ S["~type.mutability"],
13728
+ S["~type.optionality"],
13729
+ S["~type.constructor.default"],
13730
+ S["~encoded.mutability"],
13731
+ S["~encoded.optionality"]
13732
+ >
13733
+ {
13734
+ readonly "Type": S["Type"]
13735
+ readonly "Encoded": Json
13736
+ readonly "DecodingServices": S["DecodingServices"]
13737
+ readonly "EncodingServices": S["EncodingServices"]
13738
+ readonly "~type.make.in": S["~type.make.in"]
13739
+ readonly "~type.make": S["~type.make"]
13740
+ readonly "Iso": S["Iso"]
13741
+ readonly schema: S
13742
+ }
13743
+
13521
13744
  /**
13522
13745
  * Derives a canonical JSON codec from a schema. The encoded form is `Json`, and
13523
13746
  * decoding produces the schema's `Type`.
@@ -13525,11 +13748,11 @@ export function toJsonSchemaDocument(schema: Top, options?: ToJsonSchemaOptions)
13525
13748
  * @category Canonical Codecs
13526
13749
  * @since 4.0.0
13527
13750
  */
13528
- export function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T, Json, RD, RE> {
13529
- return make(toCodecJsonTop(schema.ast))
13751
+ export function toCodecJson<S extends Constraint>(schema: S): toCodecJson<S> {
13752
+ return make(toCodecJsonTop(schema.ast), { schema })
13530
13753
  }
13531
13754
 
13532
- const toCodecJsonTop = SchemaAST.toCodec((ast) => {
13755
+ const toCodecJsonTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
13533
13756
  const out = toCodecJsonBase(ast, toCodecJsonTop)
13534
13757
  return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out
13535
13758
  })
@@ -13596,7 +13819,7 @@ function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Sche
13596
13819
  * @category Canonical Codecs
13597
13820
  * @since 4.0.0
13598
13821
  */
13599
- export function toCodecIso<S extends Top>(schema: S): Codec<S["Type"], S["Iso"]> {
13822
+ export function toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]> {
13600
13823
  return make(toCodecIsoTop(SchemaAST.toType(schema.ast)))
13601
13824
  }
13602
13825
 
@@ -13634,6 +13857,34 @@ function toCodecIsoBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Schem
13634
13857
  */
13635
13858
  export type StringTree = Tree<string | undefined>
13636
13859
 
13860
+ /**
13861
+ * Type-level representation returned by {@link toCodecStringTree}.
13862
+ *
13863
+ * @category Canonical Codecs
13864
+ * @since 4.0.0
13865
+ */
13866
+ export interface toCodecStringTree<S extends Constraint> extends
13867
+ BottomLazy<
13868
+ S["ast"],
13869
+ toCodecStringTree<S>,
13870
+ ReadonlyArray<Constraint>,
13871
+ S["~type.mutability"],
13872
+ S["~type.optionality"],
13873
+ S["~type.constructor.default"],
13874
+ S["~encoded.mutability"],
13875
+ S["~encoded.optionality"]
13876
+ >
13877
+ {
13878
+ readonly "Type": S["Type"]
13879
+ readonly "Encoded": StringTree
13880
+ readonly "DecodingServices": S["DecodingServices"]
13881
+ readonly "EncodingServices": S["EncodingServices"]
13882
+ readonly "~type.make.in": S["~type.make.in"]
13883
+ readonly "~type.make": S["~type.make"]
13884
+ readonly "Iso": S["Iso"]
13885
+ readonly schema: S
13886
+ }
13887
+
13637
13888
  /**
13638
13889
  * Converts a schema to the StringTree canonical codec, where every leaf value
13639
13890
  * becomes a string while preserving the original structure.
@@ -13643,33 +13894,60 @@ export type StringTree = Tree<string | undefined>
13643
13894
  * Declarations are converted to `undefined` (unless they have a
13644
13895
  * `toCodecJson` or `toCodec` annotation).
13645
13896
  *
13646
- * Options:
13897
+ * @category Canonical Codecs
13898
+ * @since 4.0.0
13899
+ */
13900
+ export function toCodecStringTree<S extends Constraint>(schema: S): toCodecStringTree<S> {
13901
+ return make(serializerStringTree(schema.ast), { schema })
13902
+ }
13903
+
13904
+ /**
13905
+ * Type-level representation returned by {@link toCodecArrayFromSingle}.
13647
13906
  *
13648
- * - `keepDeclarations`: if `true`, it **does not** convert declarations to
13649
- * `undefined` but instead keeps them as they are (unless they have a
13650
- * `toCodecJson` or `toCodec` annotation).
13907
+ * @category Canonical Codecs
13908
+ * @since 4.0.0
13909
+ */
13910
+ export interface toCodecArrayFromSingle<S extends Constraint> extends
13911
+ BottomLazy<
13912
+ S["ast"],
13913
+ toCodecArrayFromSingle<S>,
13914
+ S["~type.parameters"],
13915
+ S["~type.mutability"],
13916
+ S["~type.optionality"],
13917
+ S["~type.constructor.default"],
13918
+ S["~encoded.mutability"],
13919
+ S["~encoded.optionality"]
13920
+ >
13921
+ {
13922
+ readonly "Type": S["Type"]
13923
+ readonly "Encoded": S["Encoded"]
13924
+ readonly "DecodingServices": S["DecodingServices"]
13925
+ readonly "EncodingServices": S["EncodingServices"]
13926
+ readonly "~type.make.in": S["~type.make.in"]
13927
+ readonly "~type.make": S["~type.make"]
13928
+ readonly "Iso": S["Iso"]
13929
+ }
13930
+
13931
+ /**
13932
+ * Allows array schemas to decode from either an array input or a single value
13933
+ * input.
13934
+ *
13935
+ * **When to use**
13936
+ *
13937
+ * Use when you need to accept transport formats that may represent a
13938
+ * single-item array as a bare value, such as query-string or form-data adapters.
13939
+ *
13940
+ * **Gotchas**
13651
13941
  *
13652
- * Defaults to `false`.
13942
+ * This combinator is intentionally not part of `toCodecStringTree`; it adds a
13943
+ * decoding convenience rather than a canonical StringTree representation. It
13944
+ * does not parse comma-separated strings.
13653
13945
  *
13654
13946
  * @category Canonical Codecs
13655
13947
  * @since 4.0.0
13656
13948
  */
13657
- export function toCodecStringTree<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T, StringTree, RD, RE>
13658
- export function toCodecStringTree<T, E, RD, RE>(
13659
- schema: Codec<T, E, RD, RE>,
13660
- options: { readonly keepDeclarations: true } // Used in FormData
13661
- ): Codec<T, unknown, RD, RE>
13662
- export function toCodecStringTree<T, E, RD, RE>(
13663
- schema: Codec<T, E, RD, RE>,
13664
- options?: { readonly keepDeclarations?: boolean | undefined }
13665
- ): Codec<T, unknown, RD, RE> {
13666
- return make(
13667
- toCodecEnsureArray(
13668
- options?.keepDeclarations === true
13669
- ? serializerStringTreeKeepDeclarations(schema.ast)
13670
- : serializerStringTree(schema.ast)
13671
- )
13672
- )
13949
+ export function toCodecArrayFromSingle<S extends Constraint>(schema: S): toCodecArrayFromSingle<S> {
13950
+ return make(toCodecArrayFromSingleTop(schema.ast))
13673
13951
  }
13674
13952
 
13675
13953
  type XmlEncoderOptions = {
@@ -13885,7 +14163,15 @@ const booleanToString = new SchemaAST.Link(
13885
14163
  )
13886
14164
  )
13887
14165
 
13888
- const serializerStringTree = SchemaAST.toCodec((ast) => {
14166
+ const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY"
14167
+
14168
+ const isSerializerArrayFromSingle = (ast: SchemaAST.AST): boolean =>
14169
+ SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true
14170
+
14171
+ const serializerStringTree = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
14172
+ if (isSerializerArrayFromSingle(ast)) {
14173
+ return ast
14174
+ }
13889
14175
  const out = serializerTree(ast, serializerStringTree, (ast) => SchemaAST.replaceEncoding(ast, [unknownToUndefined]))
13890
14176
  if (out !== ast && SchemaAST.isOptional(ast)) {
13891
14177
  return SchemaAST.optionalKeyLastLink(out)
@@ -13901,53 +14187,46 @@ const unknownToUndefined = new SchemaAST.Link(
13901
14187
  )
13902
14188
  )
13903
14189
 
13904
- const serializerStringTreeKeepDeclarations = SchemaAST.toCodec((ast) => {
13905
- const out = serializerTree(ast, serializerStringTreeKeepDeclarations, identity)
13906
- if (out !== ast && SchemaAST.isOptional(ast)) {
13907
- return SchemaAST.optionalKeyLastLink(out)
13908
- }
13909
- return out
13910
- })
14190
+ const toArrayFromSingleInputElement = (ast: SchemaAST.AST): SchemaAST.AST =>
14191
+ SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown
13911
14192
 
13912
- const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY"
14193
+ const arrayFromSingleTransformation = new SchemaTransformation.Transformation(
14194
+ SchemaGetter.transform((input: ReadonlyArray<unknown> | string) => typeof input === "string" ? [input] : input),
14195
+ SchemaGetter.passthrough()
14196
+ )
13913
14197
 
13914
- const toCodecEnsureArray = SchemaAST.toCodec((ast) => {
13915
- if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
14198
+ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
14199
+ if (isSerializerArrayFromSingle(ast)) {
13916
14200
  return ast
13917
14201
  }
13918
- const out = onSerializerEnsureArray(ast)
14202
+ const out = onSerializerArrayFromSingle(ast)
13919
14203
  if (SchemaAST.isArrays(out)) {
13920
- const ensure = new SchemaAST.Union(
13921
- [
13922
- out,
13923
- SchemaAST.decodeTo(
13924
- SchemaAST.string,
13925
- out,
13926
- new SchemaTransformation.Transformation(
13927
- SchemaGetter.split(),
13928
- SchemaGetter.passthrough()
13929
- )
13930
- )
13931
- ],
13932
- "anyOf",
13933
- { [SERIALIZER_ENSURE_ARRAY]: true }
14204
+ const ensure = SchemaAST.decodeTo(
14205
+ new SchemaAST.Union(
14206
+ [
14207
+ new SchemaAST.Arrays(
14208
+ out.isMutable,
14209
+ out.elements.map(toArrayFromSingleInputElement),
14210
+ out.rest.map(toArrayFromSingleInputElement)
14211
+ ),
14212
+ SchemaAST.string
14213
+ ],
14214
+ "anyOf",
14215
+ { [SERIALIZER_ENSURE_ARRAY]: true }
14216
+ ),
14217
+ out,
14218
+ arrayFromSingleTransformation
13934
14219
  )
13935
14220
  return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure
13936
14221
  }
13937
14222
  return out
13938
14223
  })
13939
14224
 
13940
- function onSerializerEnsureArray(ast: SchemaAST.AST): SchemaAST.AST {
13941
- switch (ast._tag) {
13942
- default:
13943
- return ast
13944
- case "Declaration":
13945
- case "Arrays":
13946
- case "Objects":
13947
- case "Union":
13948
- case "Suspend":
13949
- return ast.recur(toCodecEnsureArray)
13950
- }
14225
+ function onSerializerArrayFromSingle(ast: SchemaAST.AST): SchemaAST.AST {
14226
+ return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" ||
14227
+ ast._tag === "Suspend"
14228
+ ? ast.recur(toCodecArrayFromSingleTop)
14229
+ : ast
13951
14230
  }
13952
14231
 
13953
14232
  // -----------------------------------------------------------------------------
@@ -13961,7 +14240,7 @@ function onSerializerEnsureArray(ast: SchemaAST.AST): SchemaAST.AST {
13961
14240
  * @category Optic
13962
14241
  * @since 4.0.0
13963
14242
  */
13964
- export function toIso<S extends Top>(schema: S): Optic_.Iso<S["Type"], S["Iso"]> {
14243
+ export function toIso<S extends Constraint>(schema: S): Optic_.Iso<S["Type"], S["Iso"]> {
13965
14244
  const serializer = toCodecIso(schema)
13966
14245
  return Optic_.makeIso(SchemaParser.encodeSync(serializer), SchemaParser.decodeSync(serializer))
13967
14246
  }
@@ -13972,7 +14251,7 @@ export function toIso<S extends Top>(schema: S): Optic_.Iso<S["Type"], S["Iso"]>
13972
14251
  * @category Optic
13973
14252
  * @since 4.0.0
13974
14253
  */
13975
- export function toIsoSource<S extends Top>(_: S): Optic_.Iso<S["Type"], S["Type"]> {
14254
+ export function toIsoSource<S extends Constraint>(_: S): Optic_.Iso<S["Type"], S["Type"]> {
13976
14255
  return Optic_.id()
13977
14256
  }
13978
14257
 
@@ -13982,7 +14261,7 @@ export function toIsoSource<S extends Top>(_: S): Optic_.Iso<S["Type"], S["Type"
13982
14261
  * @category Optic
13983
14262
  * @since 4.0.0
13984
14263
  */
13985
- export function toIsoFocus<S extends Top>(_: S): Optic_.Iso<S["Iso"], S["Iso"]> {
14264
+ export function toIsoFocus<S extends Constraint>(_: S): Optic_.Iso<S["Iso"], S["Iso"]> {
13986
14265
  return Optic_.id()
13987
14266
  }
13988
14267
 
@@ -13992,18 +14271,11 @@ export function toIsoFocus<S extends Top>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>
13992
14271
  * @category Optic
13993
14272
  * @since 4.0.0
13994
14273
  */
13995
- export interface overrideToCodecIso<S extends Top, Iso> extends
13996
- Bottom<
13997
- S["Type"],
13998
- S["Encoded"],
13999
- S["DecodingServices"],
14000
- S["EncodingServices"],
14274
+ export interface overrideToCodecIso<S extends Constraint, Iso> extends
14275
+ BottomLazy<
14001
14276
  S["ast"],
14002
14277
  overrideToCodecIso<S, Iso>,
14003
- S["~type.make.in"],
14004
- Iso,
14005
14278
  S["~type.parameters"],
14006
- S["~type.make"],
14007
14279
  S["~type.mutability"],
14008
14280
  S["~type.optionality"],
14009
14281
  S["~type.constructor.default"],
@@ -14011,6 +14283,13 @@ export interface overrideToCodecIso<S extends Top, Iso> extends
14011
14283
  S["~encoded.optionality"]
14012
14284
  >
14013
14285
  {
14286
+ readonly "Type": S["Type"]
14287
+ readonly "Encoded": S["Encoded"]
14288
+ readonly "DecodingServices": S["DecodingServices"]
14289
+ readonly "EncodingServices": S["EncodingServices"]
14290
+ readonly "~type.make.in": S["~type.make.in"]
14291
+ readonly "~type.make": S["~type.make"]
14292
+ readonly "Iso": Iso
14014
14293
  readonly schema: S
14015
14294
  }
14016
14295
 
@@ -14031,7 +14310,7 @@ export interface overrideToCodecIso<S extends Top, Iso> extends
14031
14310
  * @category Optic
14032
14311
  * @since 4.0.0
14033
14312
  */
14034
- export function overrideToCodecIso<S extends Top, Iso>(
14313
+ export function overrideToCodecIso<S extends Constraint, Iso>(
14035
14314
  to: Codec<Iso>,
14036
14315
  transformation: {
14037
14316
  readonly decode: SchemaGetter.Getter<S["Type"], Iso>
@@ -14104,7 +14383,7 @@ export interface TreeRecord<A> {
14104
14383
  * @category Tree
14105
14384
  * @since 4.0.0
14106
14385
  */
14107
- export function Tree<S extends Top>(node: S) {
14386
+ export function Tree<S extends Constraint>(node: S) {
14108
14387
  const Tree$ref = suspend((): Codec<
14109
14388
  Tree<S["Type"]>,
14110
14389
  Tree<S["Encoded"]>,
@@ -14221,7 +14500,7 @@ export const MutableJson: Codec<MutableJson> = make(SchemaAST.MutableJson)
14221
14500
  * @category Schema Resolvers
14222
14501
  * @since 4.0.0
14223
14502
  */
14224
- export function resolveAnnotations<S extends Top>(
14503
+ export function resolveAnnotations<S extends Constraint>(
14225
14504
  schema: S
14226
14505
  ): Annotations.Bottom<S["Type"], S["~type.parameters"]> | undefined {
14227
14506
  return InternalAnnotations.resolve(schema.ast)
@@ -14235,7 +14514,7 @@ export function resolveAnnotations<S extends Top>(
14235
14514
  * @category Schema Resolvers
14236
14515
  * @since 4.0.0
14237
14516
  */
14238
- export function resolveAnnotationsKey<S extends Top>(schema: S): Annotations.Key<S["Type"]> | undefined {
14517
+ export function resolveAnnotationsKey<S extends Constraint>(schema: S): Annotations.Key<S["Type"]> | undefined {
14239
14518
  return schema.ast.context?.annotations
14240
14519
  }
14241
14520
 
@@ -14364,7 +14643,7 @@ export declare namespace Annotations {
14364
14643
  * @category models
14365
14644
  * @since 4.0.0
14366
14645
  */
14367
- export interface Bottom<T, TypeParameters extends ReadonlyArray<Top>> extends Documentation<T> {
14646
+ export interface Bottom<T, TypeParameters extends ReadonlyArray<Constraint>> extends Documentation<T> {
14368
14647
  /**
14369
14648
  * Complete message to use when this schema node reports an issue.
14370
14649
  *
@@ -14424,7 +14703,7 @@ export declare namespace Annotations {
14424
14703
  * @category utility types
14425
14704
  * @since 4.0.0
14426
14705
  */
14427
- export type Type<TypeParameters extends ReadonlyArray<Top>> = {
14706
+ export type Type<TypeParameters extends ReadonlyArray<Constraint>> = {
14428
14707
  readonly [K in keyof TypeParameters]: Codec<TypeParameters[K]["Type"]>
14429
14708
  }
14430
14709
  /**
@@ -14433,7 +14712,7 @@ export declare namespace Annotations {
14433
14712
  * @category utility types
14434
14713
  * @since 4.0.0
14435
14714
  */
14436
- export type Encoded<TypeParameters extends ReadonlyArray<Top>> = {
14715
+ export type Encoded<TypeParameters extends ReadonlyArray<Constraint>> = {
14437
14716
  readonly [K in keyof TypeParameters]: Codec<TypeParameters[K]["Encoded"]>
14438
14717
  }
14439
14718
  }
@@ -14448,7 +14727,7 @@ export declare namespace Annotations {
14448
14727
  * @category models
14449
14728
  * @since 4.0.0
14450
14729
  */
14451
- export interface Declaration<T, TypeParameters extends ReadonlyArray<Top> = readonly []>
14730
+ export interface Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>
14452
14731
  extends Bottom<T, TypeParameters>
14453
14732
  {
14454
14733
  readonly toCodec?:
@@ -14561,7 +14840,7 @@ export declare namespace Annotations {
14561
14840
  * @since 4.0.0
14562
14841
  */
14563
14842
  export interface Filter {
14564
- readonly constraint?: Constraint | undefined
14843
+ readonly constraint?: GenerationConstraint | undefined
14565
14844
  readonly candidate?: Candidate | undefined
14566
14845
  }
14567
14846
 
@@ -14613,10 +14892,10 @@ export declare namespace Annotations {
14613
14892
  *
14614
14893
  * **Details**
14615
14894
  *
14616
- * `Constraint` is a generation hint for the current schema AST node, not a
14617
- * self-describing validation contract. Each generator consumes the fields it
14618
- * understands for the current node and ignores the rest; final schema
14619
- * filters still validate every generated value.
14895
+ * `GenerationConstraint` is a generation hint for the current schema AST
14896
+ * node, not a self-describing validation contract. Each generator consumes
14897
+ * the fields it understands for the current node and ignores the rest;
14898
+ * final schema filters still validate every generated value.
14620
14899
  *
14621
14900
  * `minLength` and `maxLength` represent node-local cardinality: string
14622
14901
  * length for strings, array length for arrays, final own-property count for
@@ -14629,7 +14908,7 @@ export declare namespace Annotations {
14629
14908
  * @category models
14630
14909
  * @since 4.0.0
14631
14910
  */
14632
- export interface Constraint {
14911
+ export interface GenerationConstraint {
14633
14912
  readonly minLength?: number | undefined
14634
14913
  readonly maxLength?: number | undefined
14635
14914
  readonly patterns?: readonly [string, ...Array<string>]
@@ -14672,7 +14951,7 @@ export declare namespace Annotations {
14672
14951
  * @since 4.0.0
14673
14952
  */
14674
14953
  export interface Context {
14675
- readonly constraint?: ToArbitrary.Constraint | undefined
14954
+ readonly constraint?: ToArbitrary.GenerationConstraint | undefined
14676
14955
  readonly recursion?: ToArbitrary.Recursion | undefined
14677
14956
  }
14678
14957
 
@@ -14738,7 +15017,7 @@ export declare namespace Annotations {
14738
15017
  * @category models
14739
15018
  * @since 4.0.0
14740
15019
  */
14741
- export interface Declaration<T, TypeParameters extends ReadonlyArray<Top>> {
15020
+ export interface Declaration<T, TypeParameters extends ReadonlyArray<Constraint>> {
14742
15021
  (
14743
15022
  /* Arbitrary derivations for any type parameters of the schema (if present) */
14744
15023
  typeParameters: { readonly [K in keyof TypeParameters]: TypeParameter<TypeParameters[K]["Type"]> }
@@ -14815,7 +15094,7 @@ export declare namespace Annotations {
14815
15094
  * @category models
14816
15095
  * @since 4.0.0
14817
15096
  */
14818
- export interface Declaration<T, TypeParameters extends ReadonlyArray<Top>> {
15097
+ export interface Declaration<T, TypeParameters extends ReadonlyArray<Constraint>> {
14819
15098
  (
14820
15099
  /* Formatters for any type parameters of the schema (if present) */
14821
15100
  typeParameters: { readonly [K in keyof TypeParameters]: Formatter<TypeParameters[K]["Type"]> }
@@ -14840,7 +15119,7 @@ export declare namespace Annotations {
14840
15119
  * @category models
14841
15120
  * @since 4.0.0
14842
15121
  */
14843
- export interface Declaration<T, TypeParameters extends ReadonlyArray<Top>> {
15122
+ export interface Declaration<T, TypeParameters extends ReadonlyArray<Constraint>> {
14844
15123
  (
14845
15124
  /* Equivalences for any type parameters of the schema (if present) */
14846
15125
  typeParameters: { readonly [K in keyof TypeParameters]: Equivalence.Equivalence<TypeParameters[K]["Type"]> }