effect 4.0.0-beta.104 → 4.0.0-beta.106

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 (300) hide show
  1. package/AGENTS.md +381 -0
  2. package/CLAUDE.md +381 -0
  3. package/ai-docs/README.md +44 -0
  4. package/ai-docs/package.json +36 -0
  5. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  6. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
  7. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  8. package/ai-docs/src/01_effect/01_basics/index.md +5 -0
  9. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  10. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  11. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  12. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  13. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  14. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  15. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  16. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  17. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  18. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  19. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  20. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  21. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  22. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  23. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  24. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  25. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  26. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  27. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  28. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  29. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  30. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  31. package/ai-docs/src/03_stream/30_encoding.ts +165 -0
  32. package/ai-docs/src/03_stream/index.md +4 -0
  33. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  34. package/ai-docs/src/04_integration/index.md +5 -0
  35. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  36. package/ai-docs/src/05_batching/index.md +3 -0
  37. package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
  38. package/ai-docs/src/06_schedule/index.md +3 -0
  39. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  40. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  41. package/ai-docs/src/07_datetime/index.md +5 -0
  42. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  43. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  44. package/ai-docs/src/08_observability/index.md +7 -0
  45. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  46. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  47. package/ai-docs/src/09_testing/index.md +1 -0
  48. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  49. package/ai-docs/src/10_predicate/index.md +9 -0
  50. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  51. package/ai-docs/src/50_http-client/index.md +3 -0
  52. package/ai-docs/src/51_http-server/10_basics.ts +116 -0
  53. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  54. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  55. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  56. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
  57. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
  58. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  59. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
  60. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
  61. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
  62. package/ai-docs/src/51_http-server/index.md +3 -0
  63. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  64. package/ai-docs/src/60_child-process/index.md +3 -0
  65. package/ai-docs/src/70_cli/10_basics.ts +136 -0
  66. package/ai-docs/src/70_cli/index.md +5 -0
  67. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  68. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  69. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  70. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  71. package/ai-docs/src/71_ai/index.md +5 -0
  72. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  73. package/ai-docs/src/80_cluster/index.md +4 -0
  74. package/ai-docs/src/index.md +10 -0
  75. package/ai-docs/tsconfig.json +24 -0
  76. package/dist/Brand.d.ts +3 -3
  77. package/dist/Brand.d.ts.map +1 -1
  78. package/dist/Brand.js +4 -3
  79. package/dist/Brand.js.map +1 -1
  80. package/dist/Config.d.ts.map +1 -1
  81. package/dist/Config.js +5 -4
  82. package/dist/Config.js.map +1 -1
  83. package/dist/ConfigProvider.d.ts +35 -3
  84. package/dist/ConfigProvider.d.ts.map +1 -1
  85. package/dist/ConfigProvider.js +41 -8
  86. package/dist/ConfigProvider.js.map +1 -1
  87. package/dist/Context.d.ts +0 -1
  88. package/dist/Context.d.ts.map +1 -1
  89. package/dist/Context.js +1 -22
  90. package/dist/Context.js.map +1 -1
  91. package/dist/Cron.d.ts +31 -0
  92. package/dist/Cron.d.ts.map +1 -1
  93. package/dist/Cron.js +58 -2
  94. package/dist/Cron.js.map +1 -1
  95. package/dist/Fiber.d.ts +1 -1
  96. package/dist/Fiber.d.ts.map +1 -1
  97. package/dist/Function.d.ts +26 -0
  98. package/dist/Function.d.ts.map +1 -1
  99. package/dist/Function.js +36 -0
  100. package/dist/Function.js.map +1 -1
  101. package/dist/JsonSchema.d.ts.map +1 -1
  102. package/dist/JsonSchema.js +34 -17
  103. package/dist/JsonSchema.js.map +1 -1
  104. package/dist/Optic.d.ts +35 -21
  105. package/dist/Optic.d.ts.map +1 -1
  106. package/dist/Optic.js +33 -34
  107. package/dist/Optic.js.map +1 -1
  108. package/dist/Schema.d.ts +105 -109
  109. package/dist/Schema.d.ts.map +1 -1
  110. package/dist/Schema.js +141 -104
  111. package/dist/Schema.js.map +1 -1
  112. package/dist/SchemaAST.d.ts +32 -17
  113. package/dist/SchemaAST.d.ts.map +1 -1
  114. package/dist/SchemaAST.js +79 -60
  115. package/dist/SchemaAST.js.map +1 -1
  116. package/dist/SchemaError.d.ts +8 -8
  117. package/dist/SchemaError.d.ts.map +1 -1
  118. package/dist/SchemaError.js +7 -6
  119. package/dist/SchemaError.js.map +1 -1
  120. package/dist/SchemaGetter.d.ts +8 -5
  121. package/dist/SchemaGetter.d.ts.map +1 -1
  122. package/dist/SchemaGetter.js +41 -37
  123. package/dist/SchemaGetter.js.map +1 -1
  124. package/dist/SchemaIssue.d.ts +195 -38
  125. package/dist/SchemaIssue.d.ts.map +1 -1
  126. package/dist/SchemaIssue.js +243 -68
  127. package/dist/SchemaIssue.js.map +1 -1
  128. package/dist/SchemaParser.d.ts +30 -0
  129. package/dist/SchemaParser.d.ts.map +1 -1
  130. package/dist/SchemaParser.js +39 -9
  131. package/dist/SchemaParser.js.map +1 -1
  132. package/dist/SchemaRepresentation.d.ts +15 -3
  133. package/dist/SchemaRepresentation.d.ts.map +1 -1
  134. package/dist/SchemaRepresentation.js +8 -2
  135. package/dist/SchemaRepresentation.js.map +1 -1
  136. package/dist/SchemaTransformation.d.ts +2 -2
  137. package/dist/SchemaTransformation.d.ts.map +1 -1
  138. package/dist/SchemaTransformation.js +26 -26
  139. package/dist/SchemaTransformation.js.map +1 -1
  140. package/dist/ScopedRef.d.ts.map +1 -1
  141. package/dist/ScopedRef.js +1 -1
  142. package/dist/ScopedRef.js.map +1 -1
  143. package/dist/Stdio.d.ts +17 -4
  144. package/dist/Stdio.d.ts.map +1 -1
  145. package/dist/Stdio.js +6 -3
  146. package/dist/Stdio.js.map +1 -1
  147. package/dist/TxQueue.js +1 -1
  148. package/dist/TxQueue.js.map +1 -1
  149. package/dist/internal/effect.js +2 -4
  150. package/dist/internal/effect.js.map +1 -1
  151. package/dist/internal/executionPlan.js +3 -2
  152. package/dist/internal/executionPlan.js.map +1 -1
  153. package/dist/internal/rcRef.js +18 -13
  154. package/dist/internal/rcRef.js.map +1 -1
  155. package/dist/internal/schema/fromJsonSchemaDocument.js +10 -6
  156. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  157. package/dist/internal/schema/schema.js +1 -9
  158. package/dist/internal/schema/schema.js.map +1 -1
  159. package/dist/internal/schema/toArbitrary.d.ts +1 -4
  160. package/dist/internal/schema/toArbitrary.d.ts.map +1 -1
  161. package/dist/internal/schema/toArbitrary.js +0 -74
  162. package/dist/internal/schema/toArbitrary.js.map +1 -1
  163. package/dist/internal/schema/toJsonSchemaDocument.js +18 -4
  164. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  165. package/dist/internal/schema/toRepresentation.js +45 -43
  166. package/dist/internal/schema/toRepresentation.js.map +1 -1
  167. package/dist/testing/TestSchema.d.ts +1 -1
  168. package/dist/testing/TestSchema.d.ts.map +1 -1
  169. package/dist/testing/TestSchema.js +10 -9
  170. package/dist/testing/TestSchema.js.map +1 -1
  171. package/dist/unstable/ai/McpSchema.d.ts +110 -110
  172. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  173. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  174. package/dist/unstable/ai/McpServer.js +23 -11
  175. package/dist/unstable/ai/McpServer.js.map +1 -1
  176. package/dist/unstable/ai/Prompt.d.ts +4 -3
  177. package/dist/unstable/ai/Prompt.d.ts.map +1 -1
  178. package/dist/unstable/ai/Prompt.js +42 -17
  179. package/dist/unstable/ai/Prompt.js.map +1 -1
  180. package/dist/unstable/cluster/Entity.d.ts +2 -2
  181. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  182. package/dist/unstable/cluster/Entity.js.map +1 -1
  183. package/dist/unstable/cluster/EntityProxy.d.ts +3 -3
  184. package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
  185. package/dist/unstable/cluster/EntityProxy.js +4 -3
  186. package/dist/unstable/cluster/EntityProxy.js.map +1 -1
  187. package/dist/unstable/cluster/Reply.js +4 -4
  188. package/dist/unstable/cluster/Reply.js.map +1 -1
  189. package/dist/unstable/cluster/Sharding.d.ts +2 -2
  190. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  191. package/dist/unstable/cluster/Sharding.js +14 -5
  192. package/dist/unstable/cluster/Sharding.js.map +1 -1
  193. package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
  194. package/dist/unstable/encoding/Msgpack.js +6 -6
  195. package/dist/unstable/encoding/Msgpack.js.map +1 -1
  196. package/dist/unstable/eventlog/EventLogEncryption.d.ts +6 -5
  197. package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
  198. package/dist/unstable/eventlog/EventLogEncryption.js +14 -12
  199. package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
  200. package/dist/unstable/eventlog/EventLogMessage.d.ts +3 -3
  201. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  202. package/dist/unstable/eventlog/EventLogMessage.js +2 -3
  203. package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
  204. package/dist/unstable/eventlog/EventLogRemote.js +4 -4
  205. package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
  206. package/dist/unstable/eventlog/EventLogServerEncrypted.js +3 -2
  207. package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
  208. package/dist/unstable/http/HttpClient.d.ts +59 -3
  209. package/dist/unstable/http/HttpClient.d.ts.map +1 -1
  210. package/dist/unstable/http/HttpClient.js +33 -19
  211. package/dist/unstable/http/HttpClient.js.map +1 -1
  212. package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
  213. package/dist/unstable/http/HttpServerRequest.js +7 -1
  214. package/dist/unstable/http/HttpServerRequest.js.map +1 -1
  215. package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
  216. package/dist/unstable/http/MultipartParser/internal/multipart.js +18 -6
  217. package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
  218. package/dist/unstable/httpapi/HttpApiBuilder.js +10 -10
  219. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  220. package/dist/unstable/httpapi/HttpApiClient.js +9 -9
  221. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  222. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  223. package/dist/unstable/httpapi/OpenApi.js +1 -1
  224. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  225. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  226. package/dist/unstable/reactivity/AsyncResult.js +4 -4
  227. package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
  228. package/dist/unstable/reactivity/Atom.d.ts +26 -11
  229. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  230. package/dist/unstable/reactivity/Atom.js +9 -22
  231. package/dist/unstable/reactivity/Atom.js.map +1 -1
  232. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  233. package/dist/unstable/rpc/RpcClient.js +8 -1
  234. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  235. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  236. package/dist/unstable/rpc/RpcServer.js +3 -2
  237. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  238. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  239. package/dist/unstable/sql/SqlResolver.js +20 -16
  240. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  241. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  242. package/dist/unstable/workers/Worker.js +11 -12
  243. package/dist/unstable/workers/Worker.js.map +1 -1
  244. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  245. package/dist/unstable/workflow/Workflow.js +2 -2
  246. package/dist/unstable/workflow/Workflow.js.map +1 -1
  247. package/package.json +5 -2
  248. package/src/Brand.ts +4 -4
  249. package/src/Config.ts +6 -4
  250. package/src/ConfigProvider.ts +43 -8
  251. package/src/Context.ts +1 -23
  252. package/src/Cron.ts +65 -2
  253. package/src/Fiber.ts +1 -1
  254. package/src/Function.ts +37 -0
  255. package/src/JsonSchema.ts +43 -42
  256. package/src/Optic.ts +59 -58
  257. package/src/Schema.ts +213 -217
  258. package/src/SchemaAST.ts +135 -78
  259. package/src/SchemaError.ts +9 -9
  260. package/src/SchemaGetter.ts +89 -30
  261. package/src/SchemaIssue.ts +285 -80
  262. package/src/SchemaParser.ts +51 -17
  263. package/src/SchemaRepresentation.ts +15 -3
  264. package/src/SchemaTransformation.ts +66 -18
  265. package/src/ScopedRef.ts +3 -1
  266. package/src/Stdio.ts +23 -4
  267. package/src/TxQueue.ts +1 -1
  268. package/src/internal/effect.ts +3 -6
  269. package/src/internal/executionPlan.ts +3 -2
  270. package/src/internal/rcRef.ts +24 -16
  271. package/src/internal/schema/fromJsonSchemaDocument.ts +19 -14
  272. package/src/internal/schema/schema.ts +1 -17
  273. package/src/internal/schema/toArbitrary.ts +0 -72
  274. package/src/internal/schema/toJsonSchemaDocument.ts +24 -4
  275. package/src/internal/schema/toRepresentation.ts +66 -48
  276. package/src/testing/TestSchema.ts +10 -10
  277. package/src/unstable/ai/McpServer.ts +23 -11
  278. package/src/unstable/ai/Prompt.ts +51 -19
  279. package/src/unstable/cluster/Entity.ts +7 -2
  280. package/src/unstable/cluster/EntityProxy.ts +12 -5
  281. package/src/unstable/cluster/Reply.ts +4 -4
  282. package/src/unstable/cluster/Sharding.ts +29 -17
  283. package/src/unstable/encoding/Msgpack.ts +12 -8
  284. package/src/unstable/eventlog/EventLogEncryption.ts +15 -16
  285. package/src/unstable/eventlog/EventLogMessage.ts +2 -3
  286. package/src/unstable/eventlog/EventLogRemote.ts +4 -4
  287. package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -2
  288. package/src/unstable/http/HttpClient.ts +132 -23
  289. package/src/unstable/http/HttpServerRequest.ts +8 -3
  290. package/src/unstable/http/MultipartParser/internal/multipart.ts +19 -6
  291. package/src/unstable/httpapi/HttpApiBuilder.ts +32 -13
  292. package/src/unstable/httpapi/HttpApiClient.ts +26 -8
  293. package/src/unstable/httpapi/OpenApi.ts +4 -1
  294. package/src/unstable/reactivity/AsyncResult.ts +11 -6
  295. package/src/unstable/reactivity/Atom.ts +44 -25
  296. package/src/unstable/rpc/RpcClient.ts +9 -1
  297. package/src/unstable/rpc/RpcServer.ts +4 -2
  298. package/src/unstable/sql/SqlResolver.ts +28 -20
  299. package/src/unstable/workers/Worker.ts +13 -14
  300. package/src/unstable/workflow/Workflow.ts +2 -5
package/src/Schema.ts CHANGED
@@ -63,7 +63,7 @@ import type * as SchemaRepresentation from "./SchemaRepresentation.ts"
63
63
  import * as SchemaTransformation from "./SchemaTransformation.ts"
64
64
  import type { Assign, Lambda, Mutable, Simplify } from "./Struct.ts"
65
65
  import * as Struct_ from "./Struct.ts"
66
- import * as FastCheck from "./testing/FastCheck.ts"
66
+ import type * as FastCheck from "./testing/FastCheck.ts"
67
67
  import type { RequiredKeys, UnionToIntersection } from "./Types.ts"
68
68
  import type { Unify } from "./Unify.ts"
69
69
 
@@ -203,7 +203,9 @@ export interface BottomWithoutNew<
203
203
  * **Gotchas**
204
204
  *
205
205
  * Throws an `Error` with the schema issue in its `cause` when validation
206
- * fails.
206
+ * fails. Schema validation failures use the generic message
207
+ * `"Schema validation failed"`; format the `cause` explicitly with
208
+ * `SchemaIssue.makeFormatterDefault()` when human-readable details are needed.
207
209
  * Causes that contain defects, interruptions, or other non-schema reasons
208
210
  * throw with the underlying `Cause` attached instead.
209
211
  *
@@ -244,10 +246,15 @@ export interface BottomWithoutNew<
244
246
  * Use when constructor input may fail validation and you want to
245
247
  * compose that failure with other `Effect` operations instead of throwing.
246
248
  *
249
+ * **Details**
250
+ *
251
+ * Validation failures are returned directly as `SchemaIssue.Issue` values
252
+ * and are not wrapped in `SchemaError`.
253
+ *
247
254
  * @see {@link BottomWithoutNew.make} — construct synchronously when validation failure should throw
248
255
  * @see {@link BottomWithoutNew.makeOption} — construct synchronously and discard validation details
249
256
  */
250
- makeEffect(input: this["~type.make.in"], options?: MakeOptions): Effect.Effect<this["Type"], SchemaError>
257
+ makeEffect(input: this["~type.make.in"], options?: MakeOptions): Effect.Effect<this["Type"], SchemaIssue.Issue>
251
258
  }
252
259
 
253
260
  /**
@@ -449,7 +456,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<C
449
456
  * **Example** (Schema for a parametric `Box<A>` type)
450
457
  *
451
458
  * ```ts import.meta.vitest
452
- * import { Effect, Schema, SchemaIssue as Issue, SchemaParser } from "effect"
459
+ * import { Effect, Schema, SchemaIssue, SchemaParser } from "effect"
453
460
  *
454
461
  * interface Box<A> {
455
462
  * readonly value: A
@@ -464,7 +471,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<C
464
471
  * ([itemCodec]) =>
465
472
  * (u, ast, options) => {
466
473
  * if (!isBox(u)) {
467
- * return Effect.fail(new SchemaIssue.InvalidType(ast))
474
+ * return Effect.fail(new SchemaIssue.InvalidType(ast, u, options))
468
475
  * }
469
476
  * return Effect.map(
470
477
  * SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
@@ -552,10 +559,10 @@ export function declare<T, Iso = T>(
552
559
  ): declare<T, Iso> {
553
560
  return declareConstructor<T, T, Iso>()(
554
561
  [],
555
- () => (input, ast) =>
562
+ () => (input, ast, options) =>
556
563
  is(input) ?
557
564
  Effect.succeed(input) :
558
- Effect.fail(new SchemaIssue.InvalidType(ast)),
565
+ Effect.fail(new SchemaIssue.InvalidType(ast, input, options)),
559
566
  annotations
560
567
  )
561
568
  }
@@ -1161,10 +1168,12 @@ export {
1161
1168
  *
1162
1169
  * The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
1163
1170
  * every validation failure, including the path to the problematic value and
1164
- * the expected type or constraint. Built-in issues have no `actual` field,
1165
- * and built-in messages do not include the rejected value. Other Issue fields
1166
- * and custom annotations or messages are not sanitized. `message` renders the
1167
- * issue tree as a human-readable string.
1171
+ * the expected type or constraint. Parsing with `reportInput: true` adds an
1172
+ * enumerable `input` field to value-bearing issues created by the parser.
1173
+ * Built-in messages may include reported input. Other issue fields and
1174
+ * custom annotations or messages are not sanitized.
1175
+ * `message` renders the issue tree as a human-readable string and can disclose
1176
+ * retained input.
1168
1177
  *
1169
1178
  * Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
1170
1179
  *
@@ -1416,6 +1425,9 @@ export const is = SchemaParser.is
1416
1425
  *
1417
1426
  * The input is narrowed if the assertion succeeds. If schema validation fails,
1418
1427
  * the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
1428
+ * Schema validation failures use the generic message `"Schema validation failed"`.
1429
+ * Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
1430
+ * human-readable details are needed.
1419
1431
  *
1420
1432
  * **Gotchas**
1421
1433
  *
@@ -1478,10 +1490,19 @@ export function decodeUnknownEffect<S extends Constraint>(schema: S, options?: S
1478
1490
  input: unknown,
1479
1491
  options?: SchemaAST.ParseOptions
1480
1492
  ): Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]> => {
1481
- return InternalSchema.fromIssueEffect(parser(input, options))
1493
+ return fromIssueEffect(parser(input, options))
1482
1494
  }
1483
1495
  }
1484
1496
 
1497
+ function fromIssueEffect<A, R>(
1498
+ self: Effect.Effect<A, SchemaIssue.Issue, R>
1499
+ ): Effect.Effect<A, SchemaError, R> {
1500
+ return Effect.catchCause(
1501
+ self,
1502
+ (cause) => Effect.failCauseSync(() => Cause_.map(cause, (issue) => new SchemaError(issue)))
1503
+ )
1504
+ }
1505
+
1485
1506
  /**
1486
1507
  * Decodes a typed input (the schema's `Encoded` type) against a schema,
1487
1508
  * returning an `Effect` that succeeds with the decoded value or fails with a
@@ -1939,7 +1960,7 @@ export function encodeUnknownEffect<S extends Constraint>(schema: S, options?: S
1939
1960
  input: unknown,
1940
1961
  options?: SchemaAST.ParseOptions
1941
1962
  ): Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]> => {
1942
- return InternalSchema.fromIssueEffect(parser(input, options))
1963
+ return fromIssueEffect(parser(input, options))
1943
1964
  }
1944
1965
  }
1945
1966
 
@@ -2455,7 +2476,10 @@ interface optionalLambda extends Lambda {
2455
2476
  * @category combinators
2456
2477
  * @since 3.10.0
2457
2478
  */
2458
- export const optional = Struct_.lambda<optionalLambda>((self) => optionalKey(UndefinedOr(self)))
2479
+ export const optional = Struct_.lambda<optionalLambda>((self) => {
2480
+ const schema = UndefinedOr(self)
2481
+ return make(SchemaAST.optional(self.ast), { schema })
2482
+ })
2459
2483
 
2460
2484
  interface requiredLambda extends Lambda {
2461
2485
  <S extends Constraint>(self: optional<S>): S
@@ -5596,7 +5620,7 @@ export function decodeTo<To extends Constraint, From extends Constraint, RD = ne
5596
5620
  * ```
5597
5621
  *
5598
5622
  * @category transforming
5599
- * @since 3.10.0
5623
+ * @since 4.0.0
5600
5624
  */
5601
5625
  export function decode<S extends Constraint, RD = never, RE = never>(transformation: {
5602
5626
  readonly decode: SchemaGetter.Getter<S["Type"], S["Type"], RD>
@@ -5685,7 +5709,7 @@ export function encodeTo<To extends Constraint, From extends Constraint, RD = ne
5685
5709
  * ```
5686
5710
  *
5687
5711
  * @category transforming
5688
- * @since 3.10.0
5712
+ * @since 4.0.0
5689
5713
  */
5690
5714
  export function encode<S extends Constraint, RD = never, RE = never>(transformation: {
5691
5715
  readonly decode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RD>
@@ -5744,7 +5768,7 @@ export interface withConstructorDefault<S extends Constraint & WithoutConstructo
5744
5768
  * **Details**
5745
5769
  *
5746
5770
  * Constructor defaults are applied only during `make*`, not during decoding or
5747
- * encoding.
5771
+ * encoding. Failures are represented directly as `SchemaIssue.Issue` values.
5748
5772
  *
5749
5773
  * **Example** (Defining an optional field with a static default)
5750
5774
  *
@@ -5767,10 +5791,10 @@ export interface withConstructorDefault<S extends Constraint & WithoutConstructo
5767
5791
  export function withConstructorDefault<S extends Constraint & WithoutConstructorDefault>(
5768
5792
  // `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
5769
5793
  // it makes easier to define the default value if there are nested defaults
5770
- defaultValue: Effect.Effect<S["~type.make.in"], SchemaError>
5794
+ defaultValue: Effect.Effect<S["~type.make.in"], SchemaIssue.Issue>
5771
5795
  ) {
5772
5796
  return (schema: S): withConstructorDefault<S> =>
5773
- make(SchemaAST.withConstructorDefault(schema.ast, toIssueEffect(defaultValue)), { schema })
5797
+ make(SchemaAST.withConstructorDefault(schema.ast, defaultValue), { schema })
5774
5798
  }
5775
5799
 
5776
5800
  function toIssueEffect<A, R>(
@@ -6552,12 +6576,13 @@ export const makeFilter: <T>(
6552
6576
  *
6553
6577
  * - `string`: failure with that string as the message. Produces an
6554
6578
  * {@link SchemaIssue.InvalidValue} with the string used as the issue's
6555
- * `message` annotation.
6556
- * - {@link SchemaIssue.Issue}: a fully-formed issue, returned as-is.
6579
+ * `message` annotation and honors `reportInput`.
6580
+ * - {@link SchemaIssue.Issue}: a fully-formed issue, returned as-is. It is not
6581
+ * enriched when `reportInput` is enabled.
6557
6582
  * - `{ path, issue }`: failure attached to a nested path. `issue` is either
6558
- * a `string` (wrapped in an {@link SchemaIssue.InvalidValue}) or a full
6559
- * {@link SchemaIssue.Issue}; the result is wrapped in an {@link SchemaIssue.Pointer}
6560
- * at the given `path`.
6583
+ * a `string` (wrapped in an {@link SchemaIssue.InvalidValue} that honors
6584
+ * `reportInput`) or a full {@link SchemaIssue.Issue} (returned unchanged);
6585
+ * the result is wrapped in an {@link SchemaIssue.Pointer} at the given `path`.
6561
6586
  *
6562
6587
  * @category models
6563
6588
  * @since 3.10.0
@@ -6579,7 +6604,7 @@ export type FilterIssue = string | SchemaIssue.Issue | {
6579
6604
  * - `true`: success. Equivalent to `undefined`, useful when the predicate is
6580
6605
  * a plain boolean expression.
6581
6606
  * - `false`: generic failure. Produces an {@link SchemaIssue.InvalidValue}
6582
- * with no custom message.
6607
+ * with no custom message and honors `reportInput`.
6583
6608
  * - {@link FilterIssue}: a single failure. See {@link FilterIssue} for the
6584
6609
  * shapes (`string`, {@link SchemaIssue.Issue}, or `{ path, issue }`).
6585
6610
  * - `ReadonlyArray<FilterIssue>`: several failures reported together. An
@@ -9379,7 +9404,7 @@ export function isPropertyNames(keySchema: Constraint, annotations?: Annotations
9379
9404
  }
9380
9405
  }
9381
9406
  if (Arr.isArrayNonEmpty(issues)) {
9382
- return new SchemaIssue.Composite(ast, issues)
9407
+ return new SchemaIssue.Composite(ast, issues, input, options)
9383
9408
  }
9384
9409
  return true
9385
9410
  },
@@ -9580,11 +9605,11 @@ export function Option<A extends Constraint>(value: A): Option<A> {
9580
9605
  SchemaParser.decodeUnknownEffect(value)(input.value, options),
9581
9606
  {
9582
9607
  onSuccess: Option_.some,
9583
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], issue)])
9608
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
9584
9609
  }
9585
9610
  )
9586
9611
  }
9587
- return Effect.fail(new SchemaIssue.InvalidType(ast))
9612
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
9588
9613
  },
9589
9614
  {
9590
9615
  representation: {
@@ -9897,18 +9922,18 @@ export function Result<A extends Constraint, E extends Constraint>(
9897
9922
  [success, failure],
9898
9923
  ([success, failure]) => (input, ast, options) => {
9899
9924
  if (!Result_.isResult(input)) {
9900
- return Effect.fail(new SchemaIssue.InvalidType(ast))
9925
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
9901
9926
  }
9902
9927
  switch (input._tag) {
9903
9928
  case "Success":
9904
9929
  return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
9905
9930
  onSuccess: Result_.succeed,
9906
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["success"], issue)])
9931
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "success", issue, input, options)
9907
9932
  })
9908
9933
  case "Failure":
9909
9934
  return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
9910
9935
  onSuccess: Result_.fail,
9911
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["failure"], issue)])
9936
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failure", issue, input, options)
9912
9937
  })
9913
9938
  }
9914
9939
  },
@@ -10080,15 +10105,23 @@ export function Redacted<S extends Constraint>(value: S, options?: {
10080
10105
  {
10081
10106
  onSuccess: () => input,
10082
10107
  onFailure: (/** ignore the issue because of security reasons */) => {
10083
- return new SchemaIssue.Composite(ast, [
10084
- new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue())
10085
- ])
10108
+ return new SchemaIssue.Composite(
10109
+ ast,
10110
+ [
10111
+ new SchemaIssue.Pointer(
10112
+ ["value"],
10113
+ new SchemaIssue.InvalidValue(undefined, input, poptions)
10114
+ )
10115
+ ],
10116
+ input,
10117
+ poptions
10118
+ )
10086
10119
  }
10087
10120
  }
10088
10121
  )
10089
10122
  )
10090
10123
  }
10091
- return Effect.fail(new SchemaIssue.InvalidType(ast))
10124
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions))
10092
10125
  },
10093
10126
  {
10094
10127
  representation: {
@@ -10254,7 +10287,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
10254
10287
  [error, defect],
10255
10288
  ([error, defect]) => (input, ast, options) => {
10256
10289
  if (!Cause_.isReason(input)) {
10257
- return Effect.fail(new SchemaIssue.InvalidType(ast))
10290
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
10258
10291
  }
10259
10292
  switch (input._tag) {
10260
10293
  case "Fail":
@@ -10262,7 +10295,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
10262
10295
  SchemaParser.decodeUnknownEffect(error)(input.error, options),
10263
10296
  {
10264
10297
  onSuccess: Cause_.makeFailReason,
10265
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["error"], issue)])
10298
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "error", issue, input, options)
10266
10299
  }
10267
10300
  )
10268
10301
  case "Die":
@@ -10270,7 +10303,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
10270
10303
  SchemaParser.decodeUnknownEffect(defect)(input.defect, options),
10271
10304
  {
10272
10305
  onSuccess: Cause_.makeDieReason,
10273
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["defect"], issue)])
10306
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "defect", issue, input, options)
10274
10307
  }
10275
10308
  )
10276
10309
  case "Interrupt":
@@ -10445,11 +10478,11 @@ export function Cause<E extends Constraint, D extends Constraint>(error: E, defe
10445
10478
  const failures = ArraySchema(CauseReason(error, defect))
10446
10479
  return (input, ast, options) => {
10447
10480
  if (!Cause_.isCause(input)) {
10448
- return Effect.fail(new SchemaIssue.InvalidType(ast))
10481
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
10449
10482
  }
10450
10483
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
10451
10484
  onSuccess: Cause_.fromReasons,
10452
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["failures"], issue)])
10485
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
10453
10486
  })
10454
10487
  }
10455
10488
  },
@@ -10791,7 +10824,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
10791
10824
  const cause = Cause(error, defect)
10792
10825
  return (input, ast, options) => {
10793
10826
  if (!Exit_.isExit(input)) {
10794
- return Effect.fail(new SchemaIssue.InvalidType(ast))
10827
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
10795
10828
  }
10796
10829
  switch (input._tag) {
10797
10830
  case "Success":
@@ -10799,7 +10832,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
10799
10832
  SchemaParser.decodeUnknownEffect(value)(input.value, options),
10800
10833
  {
10801
10834
  onSuccess: Exit_.succeed,
10802
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], issue)])
10835
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
10803
10836
  }
10804
10837
  )
10805
10838
  case "Failure":
@@ -10807,7 +10840,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
10807
10840
  SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
10808
10841
  {
10809
10842
  onSuccess: Exit_.failCause,
10810
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["cause"], issue)])
10843
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
10811
10844
  }
10812
10845
  )
10813
10846
  }
@@ -11048,11 +11081,11 @@ export function ReadonlyMap<Key extends Constraint, Value extends Constraint>(
11048
11081
  SchemaParser.decodeUnknownEffect(array)([...input], options),
11049
11082
  {
11050
11083
  onSuccess: (array: ReadonlyArray<readonly [Key["Type"], Value["Type"]]>) => new globalThis.Map(array),
11051
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["entries"], issue)])
11084
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
11052
11085
  }
11053
11086
  )
11054
11087
  }
11055
- return Effect.fail(new SchemaIssue.InvalidType(ast))
11088
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11056
11089
  }
11057
11090
  },
11058
11091
  {
@@ -11160,11 +11193,11 @@ export function HashMap<Key extends Constraint, Value extends Constraint>(key: K
11160
11193
  SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options),
11161
11194
  {
11162
11195
  onSuccess: HashMap_.fromIterable,
11163
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["entries"], issue)])
11196
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
11164
11197
  }
11165
11198
  )
11166
11199
  }
11167
- return Effect.fail(new SchemaIssue.InvalidType(ast))
11200
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11168
11201
  }
11169
11202
  },
11170
11203
  {
@@ -11270,11 +11303,11 @@ export function ReadonlySet<Value extends Constraint>(value: Value): $ReadonlySe
11270
11303
  SchemaParser.decodeUnknownEffect(array)([...input], options),
11271
11304
  {
11272
11305
  onSuccess: (array: ReadonlyArray<Value["Type"]>) => new globalThis.Set(array),
11273
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["values"], issue)])
11306
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
11274
11307
  }
11275
11308
  )
11276
11309
  }
11277
- return Effect.fail(new SchemaIssue.InvalidType(ast))
11310
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11278
11311
  }
11279
11312
  },
11280
11313
  {
@@ -11380,11 +11413,11 @@ export function HashSet<Value extends Constraint>(value: Value): HashSet<Value>
11380
11413
  SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
11381
11414
  {
11382
11415
  onSuccess: HashSet_.fromIterable,
11383
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["values"], issue)])
11416
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
11384
11417
  }
11385
11418
  )
11386
11419
  }
11387
- return Effect.fail(new SchemaIssue.InvalidType(ast))
11420
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11388
11421
  }
11389
11422
  },
11390
11423
  {
@@ -11497,11 +11530,11 @@ export function Chunk<Value extends Constraint>(value: Value): Chunk<Value> {
11497
11530
  SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
11498
11531
  {
11499
11532
  onSuccess: Chunk_.fromIterable,
11500
- onFailure: (issue) => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["values"], issue)])
11533
+ onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
11501
11534
  }
11502
11535
  )
11503
11536
  }
11504
- return Effect.fail(new SchemaIssue.InvalidType(ast))
11537
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
11505
11538
  }
11506
11539
  },
11507
11540
  {
@@ -11598,10 +11631,15 @@ export const RegExp: RegExp = instanceOf(
11598
11631
  flags: String
11599
11632
  }),
11600
11633
  SchemaTransformation.transformOrFail({
11601
- decode: (e) =>
11634
+ decode: (e, options) =>
11602
11635
  Effect.try({
11603
11636
  try: () => new globalThis.RegExp(e.source, e.flags),
11604
- catch: () => new SchemaIssue.InvalidValue({ message: "Expected valid RegExp source and flags" })
11637
+ catch: () =>
11638
+ new SchemaIssue.InvalidValue(
11639
+ { expected: "valid RegExp source and flags" },
11640
+ e,
11641
+ options
11642
+ )
11605
11643
  }),
11606
11644
  encode: (regExp) =>
11607
11645
  Effect.succeed({
@@ -12430,13 +12468,15 @@ export const File: File = instanceOf(globalThis.File, {
12430
12468
  lastModified: Int
12431
12469
  }),
12432
12470
  SchemaTransformation.transformOrFail({
12433
- decode: (e) =>
12471
+ decode: (e, options) =>
12434
12472
  Result_.match(Encoding.decodeBase64(e.data), {
12435
12473
  onFailure: () =>
12436
12474
  Effect.fail(
12437
- new SchemaIssue.InvalidValue({
12438
- message: "Expected a valid Base64 string"
12439
- })
12475
+ new SchemaIssue.InvalidValue(
12476
+ { expected: "a valid Base64 string" },
12477
+ e.data,
12478
+ options
12479
+ )
12440
12480
  ),
12441
12481
  onSuccess: (bytes) => {
12442
12482
  const buffer = new globalThis.Uint8Array(bytes)
@@ -12445,7 +12485,7 @@ export const File: File = instanceOf(globalThis.File, {
12445
12485
  )
12446
12486
  }
12447
12487
  }),
12448
- encode: (file) =>
12488
+ encode: (file, options) =>
12449
12489
  Effect.tryPromise({
12450
12490
  try: async () => {
12451
12491
  const bytes = new globalThis.Uint8Array(await file.arrayBuffer())
@@ -12457,9 +12497,11 @@ export const File: File = instanceOf(globalThis.File, {
12457
12497
  }
12458
12498
  },
12459
12499
  catch: () =>
12460
- new SchemaIssue.InvalidValue({
12461
- message: "Expected File to be readable"
12462
- })
12500
+ new SchemaIssue.InvalidValue(
12501
+ { expected: "a readable File" },
12502
+ file,
12503
+ options
12504
+ )
12463
12505
  })
12464
12506
  })
12465
12507
  )
@@ -14053,7 +14095,7 @@ function makeClass<
14053
14095
  static makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self> {
14054
14096
  return SchemaParser.makeOption(getClassSchema(this) as any)(input ?? {}, options) as any
14055
14097
  }
14056
- static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self, SchemaError> {
14098
+ static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self, SchemaIssue.Issue> {
14057
14099
  return (getClassSchema(this) as any).makeEffect(input ?? {}, options)
14058
14100
  }
14059
14101
  static annotate(annotations: Annotations.Declaration<Self, readonly [S]>) {
@@ -14138,10 +14180,10 @@ function getClassSchemaFactory<S extends Constraint>(
14138
14180
  const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
14139
14181
  new SchemaAST.Declaration(
14140
14182
  [from.ast],
14141
- () => (input, ast) => {
14183
+ () => (input, ast, options) => {
14142
14184
  return isClassValue(input) ?
14143
14185
  Effect.succeed(input) :
14144
- Effect.fail(new SchemaIssue.InvalidType(ast))
14186
+ Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
14145
14187
  },
14146
14188
  {
14147
14189
  identifier,
@@ -14176,8 +14218,8 @@ type MissingSelfGeneric<Usage extends string> =
14176
14218
 
14177
14219
  /**
14178
14220
  * Creates a schema-backed class whose constructor validates input against a
14179
- * {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
14180
- * input.
14221
+ * {@link Struct} schema. Construction throws an `Error` with a
14222
+ * `SchemaIssue.Issue` in its `cause` on invalid input.
14181
14223
  *
14182
14224
  * **When to use**
14183
14225
  *
@@ -14246,8 +14288,8 @@ type MissingSelfGeneric<Usage extends string> =
14246
14288
  export const Class: {
14247
14289
  /**
14248
14290
  * Creates a schema-backed class whose constructor validates input against a
14249
- * {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
14250
- * input.
14291
+ * {@link Struct} schema. Construction throws an `Error` with a
14292
+ * `SchemaIssue.Issue` in its `cause` on invalid input.
14251
14293
  *
14252
14294
  * **When to use**
14253
14295
  *
@@ -14316,8 +14358,8 @@ export const Class: {
14316
14358
  <Self = never, Brand = {}>(identifier: string): {
14317
14359
  /**
14318
14360
  * Creates a schema-backed class whose constructor validates input against a
14319
- * {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
14320
- * input.
14361
+ * {@link Struct} schema. Construction throws an `Error` with a
14362
+ * `SchemaIssue.Issue` in its `cause` on invalid input.
14321
14363
  *
14322
14364
  * **When to use**
14323
14365
  *
@@ -14389,8 +14431,8 @@ export const Class: {
14389
14431
  ): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>
14390
14432
  /**
14391
14433
  * Creates a schema-backed class whose constructor validates input against a
14392
- * {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
14393
- * input.
14434
+ * {@link Struct} schema. Construction throws an `Error` with a
14435
+ * `SchemaIssue.Issue` in its `cause` on invalid input.
14394
14436
  *
14395
14437
  * **When to use**
14396
14438
  *
@@ -14918,44 +14960,32 @@ export const TaggedError: {
14918
14960
  // -----------------------------------------------------------------------------
14919
14961
 
14920
14962
  /**
14921
- * A thunk that, given the `fast-check` module, returns an `Arbitrary<T>`.
14922
- * Use this type when you need to defer instantiation of the arbitrary, for
14923
- * example to support recursive schemas.
14963
+ * Represents a function that builds a fast-check `Arbitrary<T>` from the
14964
+ * `fast-check` module.
14965
+ *
14966
+ * **When to use**
14967
+ *
14968
+ * Use as the result type of schema arbitrary derivation.
14924
14969
  *
14925
14970
  * @category utility types
14926
14971
  * @since 4.0.0
14927
14972
  */
14928
- export type LazyArbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>
14973
+ export type Arbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>
14929
14974
 
14930
14975
  /**
14931
- * Derives a {@link LazyArbitrary} from a schema. The result is memoized so
14932
- * repeated calls with the same schema are cheap.
14976
+ * Returns an {@link Arbitrary} factory derived from a schema. The generated
14977
+ * values satisfy the schema and use its decoded `Type`.
14933
14978
  *
14934
- * **Details**
14979
+ * **When to use**
14935
14980
  *
14936
- * Prefer {@link toArbitrary} when you need the arbitrary directly, or when you
14937
- * want derivation diagnostics via `{ report: true }`. Unsupported schema
14938
- * nodes, impossible constraints, invalid candidates, and recursive schemas
14939
- * without a finite terminal path fail immediately.
14940
- *
14941
- * @category generators
14942
- * @since 4.0.0
14943
- */
14944
- export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<S["Type"]> {
14945
- const lawc = InternalArbitrary.memoized(schema.ast)
14946
- return (fc) => lawc(fc, {})
14947
- }
14948
-
14949
- /**
14950
- * Derives a `fast-check` `Arbitrary` from a schema for property-based
14951
- * testing. The derived arbitrary generates values that satisfy the schema.
14981
+ * Use when you need a fast-check generator for values accepted by a schema.
14952
14982
  *
14953
14983
  * **Details**
14954
14984
  *
14955
14985
  * Constraints refine base generators; candidates add weighted sources while
14956
- * filters still validate every value. `{ report: true }` returns warnings such
14957
- * as `OpaqueFilter`, while derivation errors remain fail-fast. Recursive
14958
- * schemas use terminal branches and fail when no finite terminal path exists.
14986
+ * filters still validate every value. Recursive schemas use terminal branches
14987
+ * and fail when no finite terminal path exists. The result is memoized so
14988
+ * repeated calls with the same schema are cheap.
14959
14989
  *
14960
14990
  * **Example** (Generating arbitrary values)
14961
14991
  *
@@ -14963,36 +14993,20 @@ export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<
14963
14993
  * import { Schema } from "effect"
14964
14994
  * import * as FastCheck from "fast-check"
14965
14995
  *
14966
- * const PersonArb = Schema.toArbitrary(
14996
+ * const makePersonArbitrary = Schema.toArbitrary(
14967
14997
  * Schema.Struct({ name: Schema.String, age: Schema.Number })
14968
14998
  * )
14969
14999
  *
14970
- * // Sample a random value
14971
- * FastCheck.sample(PersonArb, 1)
15000
+ * const PersonArbitrary = makePersonArbitrary(FastCheck)
15001
+ * FastCheck.sample(PersonArbitrary, 1)
14972
15002
  * ```
14973
15003
  *
14974
15004
  * @category generators
14975
15005
  * @since 4.0.0
14976
15006
  */
14977
- export function toArbitrary<S extends Constraint>(schema: S): FastCheck.Arbitrary<S["Type"]>
14978
- export function toArbitrary<S extends Constraint>(
14979
- schema: S,
14980
- options: { readonly report: true }
14981
- ): Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>>
14982
- export function toArbitrary<S extends Constraint>(
14983
- schema: S,
14984
- options?: { readonly report?: boolean }
14985
- ): FastCheck.Arbitrary<S["Type"]> | Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>> {
14986
- if (options?.report === true) {
14987
- const lawc = InternalArbitrary.memoized(schema.ast)
14988
- const report = InternalArbitrary.makeReport()
14989
- InternalArbitrary.collectReport(schema.ast, report)
14990
- return {
14991
- value: lawc(FastCheck, {}),
14992
- report: InternalArbitrary.toReport(report)
14993
- }
14994
- }
14995
- return toArbitraryLazy(schema)(FastCheck)
15007
+ export function toArbitrary<S extends Constraint>(schema: S): Arbitrary<S["Type"]> {
15008
+ const lawc = InternalArbitrary.memoized(schema.ast)
15009
+ return (fc) => lawc(fc, {})
14996
15010
  }
14997
15011
 
14998
15012
  // -----------------------------------------------------------------------------
@@ -15328,7 +15342,10 @@ export function toJsonSchemaDocument(
15328
15342
  schema: Constraint,
15329
15343
  options?: ToJsonSchemaOptions
15330
15344
  ): JsonSchema.Document<"draft-2020-12"> {
15331
- const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast))
15345
+ const document = InternalToRepresentation.toRepresentation(
15346
+ toCodecJsonAST(schema.ast),
15347
+ InternalToJsonSchemaDocument.toRepresentationOptions
15348
+ )
15332
15349
  return InternalToJsonSchemaDocument.toJsonSchemaDocument(document, options)
15333
15350
  }
15334
15351
 
@@ -15383,16 +15400,14 @@ export function toCodecJson<S extends Constraint>(schema: S): toCodecJson<S> {
15383
15400
  return make(toCodecJsonAST(schema.ast), { schema })
15384
15401
  }
15385
15402
 
15386
- const toCodecJsonASTBase = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
15387
- const out = toCodecJsonBase(ast, toCodecJsonAST)
15403
+ /** @internal */
15404
+ export const toCodecJsonAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
15405
+ const out = toCodecJsonASTStep(ast, toCodecJsonAST)
15388
15406
  const context = ast.context
15389
15407
  if (out === ast || context === undefined) return out
15390
15408
  return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(context))
15391
15409
  })
15392
15410
 
15393
- /** @internal */
15394
- export const toCodecJsonAST = memoize(toCodecJsonASTBase)
15395
-
15396
15411
  function withoutConstructorDefault(context: SchemaAST.Context): SchemaAST.Context {
15397
15412
  return context.constructorDefault === undefined ?
15398
15413
  context :
@@ -15443,7 +15458,7 @@ const toCodecJsonReorder = makeReorder((ast: SchemaAST.AST) => {
15443
15458
  }
15444
15459
  })
15445
15460
 
15446
- function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
15461
+ function toCodecJsonASTStep(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
15447
15462
  switch (ast._tag) {
15448
15463
  case "Declaration": {
15449
15464
  const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
@@ -15502,17 +15517,17 @@ function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Sche
15502
15517
  * @since 4.0.0
15503
15518
  */
15504
15519
  export function toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]> {
15505
- return make(toCodecIsoTop(SchemaAST.toType(schema.ast)))
15520
+ return make(toCodecIsoAST(SchemaAST.toType(schema.ast)))
15506
15521
  }
15507
15522
 
15508
- const toCodecIsoTop = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
15509
- const out = toCodecIsoBase(ast, toCodecIsoTop)
15523
+ const toCodecIsoAST = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
15524
+ const out = toCodecIsoASTStep(ast, toCodecIsoAST)
15510
15525
  return out !== ast && ast.context !== undefined ?
15511
15526
  SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context)) :
15512
15527
  out
15513
15528
  })
15514
15529
 
15515
- function toCodecIsoBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
15530
+ function toCodecIsoASTStep(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
15516
15531
  switch (ast._tag) {
15517
15532
  case "Declaration": {
15518
15533
  const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
@@ -15582,7 +15597,7 @@ export interface toCodecStringTree<S extends Constraint> extends
15582
15597
  * @since 4.0.0
15583
15598
  */
15584
15599
  export function toCodecStringTree<S extends Constraint>(schema: S): toCodecStringTree<S> {
15585
- return make(serializerStringTree(schema.ast), { schema })
15600
+ return make(toCodecStringTreeAST(schema.ast), { schema })
15586
15601
  }
15587
15602
 
15588
15603
  /**
@@ -15631,7 +15646,7 @@ export interface toCodecArrayFromSingle<S extends Constraint> extends
15631
15646
  * @since 4.0.0
15632
15647
  */
15633
15648
  export function toCodecArrayFromSingle<S extends Constraint>(schema: S): toCodecArrayFromSingle<S> {
15634
- return make(toCodecArrayFromSingleTop(schema.ast))
15649
+ return make(toCodecArrayFromSingleAST(schema.ast))
15635
15650
  }
15636
15651
 
15637
15652
  type XmlEncoderOptions = {
@@ -15768,7 +15783,7 @@ const toStringTreeReorder = makeReorder((ast: SchemaAST.AST) => {
15768
15783
  }
15769
15784
  })
15770
15785
 
15771
- function serializerTree(
15786
+ function toCodecStringTreeASTStep(
15772
15787
  ast: SchemaAST.AST,
15773
15788
  recur: (ast: SchemaAST.AST) => SchemaAST.AST,
15774
15789
  onMissingAnnotation: (ast: SchemaAST.AST) => SchemaAST.AST
@@ -15847,37 +15862,29 @@ const booleanToString = new SchemaAST.Link(
15847
15862
  )
15848
15863
  )
15849
15864
 
15850
- const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY"
15865
+ const arrayFromSingleTransformation = new SchemaTransformation.Transformation(
15866
+ SchemaGetter.transform((input: ReadonlyArray<unknown> | string) => typeof input === "string" ? [input] : input),
15867
+ SchemaGetter.passthrough()
15868
+ )
15851
15869
 
15852
- const isSerializerArrayFromSingle = (ast: SchemaAST.AST): boolean =>
15853
- SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true
15870
+ const isCodecArrayFromSingleLink = (link: SchemaAST.Link): boolean =>
15871
+ link.transformation === arrayFromSingleTransformation
15854
15872
 
15855
- const serializerStringTree = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
15856
- if (isSerializerArrayFromSingle(ast)) {
15857
- return ast
15858
- }
15859
- const out = serializerTree(ast, serializerStringTree, (ast) => {
15873
+ const toCodecStringTreeAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
15874
+ const out = toCodecStringTreeASTStep(ast, toCodecStringTreeAST, (ast) => {
15860
15875
  throw new globalThis.Error("Missing structural codec for StringTree", { cause: ast })
15861
15876
  })
15862
15877
  if (out !== ast && ast.context !== undefined) {
15863
15878
  return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context))
15864
15879
  }
15865
15880
  return out
15866
- })
15881
+ }, { stopAt: isCodecArrayFromSingleLink })
15867
15882
 
15868
15883
  const toArrayFromSingleInputElement = (ast: SchemaAST.AST): SchemaAST.AST =>
15869
15884
  SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown
15870
15885
 
15871
- const arrayFromSingleTransformation = new SchemaTransformation.Transformation(
15872
- SchemaGetter.transform((input: ReadonlyArray<unknown> | string) => typeof input === "string" ? [input] : input),
15873
- SchemaGetter.passthrough()
15874
- )
15875
-
15876
- const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
15877
- if (isSerializerArrayFromSingle(ast)) {
15878
- return ast
15879
- }
15880
- const out = onSerializerArrayFromSingle(ast)
15886
+ const toCodecArrayFromSingleAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
15887
+ const out = toCodecArrayFromSingleASTStep(ast)
15881
15888
  if (SchemaAST.isArrays(out)) {
15882
15889
  const ensure = SchemaAST.decodeTo(
15883
15890
  new SchemaAST.Union(
@@ -15889,8 +15896,7 @@ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast)
15889
15896
  ),
15890
15897
  SchemaAST.string
15891
15898
  ],
15892
- "anyOf",
15893
- { [SERIALIZER_ENSURE_ARRAY]: true }
15899
+ "anyOf"
15894
15900
  ),
15895
15901
  out,
15896
15902
  arrayFromSingleTransformation
@@ -15898,12 +15904,12 @@ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast)
15898
15904
  return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure
15899
15905
  }
15900
15906
  return out
15901
- })
15907
+ }, { stopAt: isCodecArrayFromSingleLink })
15902
15908
 
15903
- function onSerializerArrayFromSingle(ast: SchemaAST.AST): SchemaAST.AST {
15909
+ function toCodecArrayFromSingleASTStep(ast: SchemaAST.AST): SchemaAST.AST {
15904
15910
  return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" ||
15905
15911
  ast._tag === "Suspend"
15906
- ? ast.recur(toCodecArrayFromSingleTop)
15912
+ ? ast.recur(toCodecArrayFromSingleAST)
15907
15913
  : ast
15908
15914
  }
15909
15915
 
@@ -16131,6 +16137,18 @@ export const isBetweenBigIntReviver: SchemaRepresentation.FilterReviver<{
16131
16137
  * Derives an `Iso` optic from a schema that isomorphically converts between
16132
16138
  * the schema's `Type` and its `Iso` (intermediate / serialized form).
16133
16139
  *
16140
+ * **Details**
16141
+ *
16142
+ * Reading through the `Iso` encodes the schema value, while replacing through
16143
+ * it decodes the new focus.
16144
+ *
16145
+ * **Gotchas**
16146
+ *
16147
+ * Either direction can throw an `Error` with the generic message
16148
+ * `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
16149
+ * the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
16150
+ * human-readable details are needed.
16151
+ *
16134
16152
  * @category converting
16135
16153
  * @since 4.0.0
16136
16154
  */
@@ -16230,6 +16248,19 @@ export function overrideToCodecIso<S extends Constraint, Iso>(
16230
16248
  * {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
16231
16249
  * and new values, and can apply patches back to the typed value.
16232
16250
  *
16251
+ * **Details**
16252
+ *
16253
+ * `diff` encodes both values before computing the patch. `patch` encodes the old
16254
+ * value, applies the patch to its JSON representation, and decodes the result.
16255
+ *
16256
+ * **Gotchas**
16257
+ *
16258
+ * Schema encoding or decoding failures throw an `Error` with the generic message
16259
+ * `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
16260
+ * the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
16261
+ * human-readable details are needed. Errors produced by {@link JsonPatch.apply}
16262
+ * for invalid patch operations are separate from schema validation failures.
16263
+ *
16233
16264
  * @category converting
16234
16265
  * @since 4.0.0
16235
16266
  */
@@ -16704,6 +16735,15 @@ export declare namespace Annotations {
16704
16735
  readonly representation?:
16705
16736
  | SchemaRepresentation.CheckRepresentationAnnotation<SchemaAST.AST>
16706
16737
  | undefined
16738
+ /**
16739
+ * Compiles this filter to a JSON Schema fragment.
16740
+ *
16741
+ * **Gotchas**
16742
+ *
16743
+ * Treat the input schemas as immutable. The returned value must be a valid JSON Schema object graph and must not be
16744
+ * mutated after this function returns. Return a new object graph to produce different output during a later
16745
+ * compilation.
16746
+ */
16707
16747
  readonly toJsonSchema?: SchemaRepresentation.ToJsonSchema.Check | undefined
16708
16748
  readonly toCode?: SchemaRepresentation.Generation.Check | undefined
16709
16749
  /**
@@ -16754,8 +16794,7 @@ export declare namespace Annotations {
16754
16794
 
16755
16795
  /**
16756
16796
  * Types used by arbitrary-derivation annotations to configure `toArbitrary`
16757
- * hooks, filter hints, candidate sources, diagnostics, and merged generation
16758
- * constraints.
16797
+ * hooks, filter hints, candidate sources, and merged generation constraints.
16759
16798
  *
16760
16799
  * @since 4.0.0
16761
16800
  */
@@ -16768,8 +16807,7 @@ export declare namespace Annotations {
16768
16807
  * `constraint` refines the schema node's base generator. `candidate` adds a
16769
16808
  * weighted source before all filters run. If neither hint is provided, the
16770
16809
  * filter does not guide generation; generated values are still checked by
16771
- * the filter predicate. With `{ report: true }`, this is reported as
16772
- * `OpaqueFilter`.
16810
+ * the filter predicate.
16773
16811
  *
16774
16812
  * @category models
16775
16813
  * @since 4.0.0
@@ -16957,58 +16995,6 @@ export declare namespace Annotations {
16957
16995
  typeParameters: { readonly [K in keyof TypeParameters]: TypeParameter<TypeParameters[K]["Type"]> }
16958
16996
  ): (fc: typeof FastCheck, context: Context) => Output<T>
16959
16997
  }
16960
-
16961
- /**
16962
- * Wraps a derived value together with arbitrary-derivation diagnostics.
16963
- *
16964
- * @category models
16965
- * @since 4.0.0
16966
- */
16967
- export interface WithReport<A> {
16968
- readonly value: A
16969
- readonly report: Report
16970
- }
16971
-
16972
- /**
16973
- * Diagnostics collected while deriving an arbitrary.
16974
- *
16975
- * **Details**
16976
- *
16977
- * Reports contain warnings only. Unsupported schema nodes, impossible
16978
- * constraints, invalid candidate weights, and throwing candidate factories
16979
- * fail immediately.
16980
- *
16981
- * @category models
16982
- * @since 4.0.0
16983
- */
16984
- export interface Report {
16985
- readonly warnings: ReadonlyArray<Warning>
16986
- }
16987
-
16988
- /**
16989
- * Non-fatal arbitrary-derivation warning.
16990
- *
16991
- * @category models
16992
- * @since 4.0.0
16993
- */
16994
- export type Warning = OpaqueFilterWarning
16995
-
16996
- /**
16997
- * Warning emitted when a filter is handled only by the final `.filter`.
16998
- *
16999
- * **Details**
17000
- *
17001
- * The filter is still enforced. The warning means it did not contribute
17002
- * a constraint or candidate, so generation may rely on fast-check discards.
17003
- *
17004
- * @category models
17005
- * @since 4.0.0
17006
- */
17007
- export interface OpaqueFilterWarning {
17008
- readonly _tag: "OpaqueFilter"
17009
- readonly path: ReadonlyArray<PropertyKey>
17010
- readonly description?: string | undefined
17011
- }
17012
16998
  }
17013
16999
 
17014
17000
  /**
@@ -17066,12 +17052,22 @@ export declare namespace Annotations {
17066
17052
  *
17067
17053
  * **Details**
17068
17054
  *
17069
- * The optional `message` field overrides the default issue message.
17055
+ * For `InvalidValue` issues, `message` overrides the complete formatted
17056
+ * message. When `message` is absent, `expected` uses the default expected
17057
+ * value policy, including reported input when available. Other issue types
17058
+ * ignore `expected`.
17070
17059
  *
17071
17060
  * @category models
17072
17061
  * @since 4.0.0
17073
17062
  */
17074
17063
  export interface Issue extends Annotations {
17064
+ /**
17065
+ * The expected value description for an `InvalidValue` issue.
17066
+ */
17067
+ readonly expected?: string | undefined
17068
+ /**
17069
+ * The complete formatted message for the issue.
17070
+ */
17075
17071
  readonly message?: string | undefined
17076
17072
  }
17077
17073
  }