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/dist/Schema.js CHANGED
@@ -55,7 +55,6 @@ import * as SchemaIssue from "./SchemaIssue.js";
55
55
  import * as SchemaParser from "./SchemaParser.js";
56
56
  import * as SchemaTransformation from "./SchemaTransformation.js";
57
57
  import * as Struct_ from "./Struct.js";
58
- import * as FastCheck from "./testing/FastCheck.js";
59
58
  const TypeId = InternalSchema.TypeId;
60
59
  /**
61
60
  * Creates a schema for a **parametric** type (a generic container such as
@@ -81,7 +80,7 @@ const TypeId = InternalSchema.TypeId;
81
80
  * **Example** (Schema for a parametric `Box<A>` type)
82
81
  *
83
82
  * ```ts import.meta.vitest
84
- * import { Effect, Schema, SchemaIssue as Issue, SchemaParser } from "effect"
83
+ * import { Effect, Schema, SchemaIssue, SchemaParser } from "effect"
85
84
  *
86
85
  * interface Box<A> {
87
86
  * readonly value: A
@@ -96,7 +95,7 @@ const TypeId = InternalSchema.TypeId;
96
95
  * ([itemCodec]) =>
97
96
  * (u, ast, options) => {
98
97
  * if (!isBox(u)) {
99
- * return Effect.fail(new SchemaIssue.InvalidType(ast))
98
+ * return Effect.fail(new SchemaIssue.InvalidType(ast, u, options))
100
99
  * }
101
100
  * return Effect.map(
102
101
  * SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
@@ -150,7 +149,7 @@ export function declareConstructor() {
150
149
  * @since 3.10.0
151
150
  */
152
151
  export function declare(is, annotations) {
153
- return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast)), annotations);
152
+ return declareConstructor()([], () => (input, ast, options) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, input, options)), annotations);
154
153
  }
155
154
  /**
156
155
  * Returns a schema widened to the fully-parameterized {@link Bottom} interface,
@@ -338,10 +337,12 @@ isSchemaError,
338
337
  *
339
338
  * The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
340
339
  * every validation failure, including the path to the problematic value and
341
- * the expected type or constraint. Built-in issues have no `actual` field,
342
- * and built-in messages do not include the rejected value. Other Issue fields
343
- * and custom annotations or messages are not sanitized. `message` renders the
344
- * issue tree as a human-readable string.
340
+ * the expected type or constraint. Parsing with `reportInput: true` adds an
341
+ * enumerable `input` field to value-bearing issues created by the parser.
342
+ * Built-in messages may include reported input. Other issue fields and
343
+ * custom annotations or messages are not sanitized.
344
+ * `message` renders the issue tree as a human-readable string and can disclose
345
+ * retained input.
345
346
  *
346
347
  * Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
347
348
  *
@@ -584,6 +585,9 @@ export const is = SchemaParser.is;
584
585
  *
585
586
  * The input is narrowed if the assertion succeeds. If schema validation fails,
586
587
  * the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
588
+ * Schema validation failures use the generic message `"Schema validation failed"`.
589
+ * Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
590
+ * human-readable details are needed.
587
591
  *
588
592
  * **Gotchas**
589
593
  *
@@ -641,9 +645,12 @@ export const asserts = SchemaParser.asserts;
641
645
  export function decodeUnknownEffect(schema, options) {
642
646
  const parser = SchemaParser.decodeUnknownEffect(schema, options);
643
647
  return (input, options) => {
644
- return InternalSchema.fromIssueEffect(parser(input, options));
648
+ return fromIssueEffect(parser(input, options));
645
649
  };
646
650
  }
651
+ function fromIssueEffect(self) {
652
+ return Effect.catchCause(self, cause => Effect.failCauseSync(() => Cause_.map(cause, issue => new SchemaError(issue))));
653
+ }
647
654
  /**
648
655
  * Decodes a typed input (the schema's `Encoded` type) against a schema,
649
656
  * returning an `Effect` that succeeds with the decoded value or fails with a
@@ -1050,7 +1057,7 @@ export const decodeSync = decodeUnknownSync;
1050
1057
  export function encodeUnknownEffect(schema, options) {
1051
1058
  const parser = SchemaParser.encodeUnknownEffect(schema, options);
1052
1059
  return (input, options) => {
1053
- return InternalSchema.fromIssueEffect(parser(input, options));
1060
+ return fromIssueEffect(parser(input, options));
1054
1061
  };
1055
1062
  }
1056
1063
  /**
@@ -1467,7 +1474,12 @@ export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
1467
1474
  * @category combinators
1468
1475
  * @since 3.10.0
1469
1476
  */
1470
- export const optional = /*#__PURE__*/Struct_.lambda(self => optionalKey(UndefinedOr(self)));
1477
+ export const optional = /*#__PURE__*/Struct_.lambda(self => {
1478
+ const schema = UndefinedOr(self);
1479
+ return make(SchemaAST.optional(self.ast), {
1480
+ schema
1481
+ });
1482
+ });
1471
1483
  /**
1472
1484
  * Reverses `optional` and returns the inner schema.
1473
1485
  *
@@ -2657,7 +2669,7 @@ export function decodeTo(to, transformation) {
2657
2669
  * ```
2658
2670
  *
2659
2671
  * @category transforming
2660
- * @since 3.10.0
2672
+ * @since 4.0.0
2661
2673
  */
2662
2674
  export function decode(transformation) {
2663
2675
  return self => {
@@ -2693,7 +2705,7 @@ export function encodeTo(to, transformation) {
2693
2705
  * ```
2694
2706
  *
2695
2707
  * @category transforming
2696
- * @since 3.10.0
2708
+ * @since 4.0.0
2697
2709
  */
2698
2710
  export function encode(transformation) {
2699
2711
  return self => {
@@ -2706,7 +2718,7 @@ export function encode(transformation) {
2706
2718
  * **Details**
2707
2719
  *
2708
2720
  * Constructor defaults are applied only during `make*`, not during decoding or
2709
- * encoding.
2721
+ * encoding. Failures are represented directly as `SchemaIssue.Issue` values.
2710
2722
  *
2711
2723
  * **Example** (Defining an optional field with a static default)
2712
2724
  *
@@ -2730,7 +2742,7 @@ export function withConstructorDefault(
2730
2742
  // `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
2731
2743
  // it makes easier to define the default value if there are nested defaults
2732
2744
  defaultValue) {
2733
- return schema => make(SchemaAST.withConstructorDefault(schema.ast, toIssueEffect(defaultValue)), {
2745
+ return schema => make(SchemaAST.withConstructorDefault(schema.ast, defaultValue), {
2734
2746
  schema
2735
2747
  });
2736
2748
  }
@@ -5903,7 +5915,7 @@ export function isPropertyNames(keySchema, annotations) {
5903
5915
  }
5904
5916
  }
5905
5917
  if (Arr.isArrayNonEmpty(issues)) {
5906
- return new SchemaIssue.Composite(ast, issues);
5918
+ return new SchemaIssue.Composite(ast, issues, input, options);
5907
5919
  }
5908
5920
  return true;
5909
5921
  }, {
@@ -6037,10 +6049,10 @@ export function Option(value) {
6037
6049
  }
6038
6050
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
6039
6051
  onSuccess: Option_.some,
6040
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], issue)])
6052
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
6041
6053
  });
6042
6054
  }
6043
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6055
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
6044
6056
  }, {
6045
6057
  representation: {
6046
6058
  id: "effect/schema/Option",
@@ -6208,18 +6220,18 @@ export function OptionFromOptionalNullOr(schema, options) {
6208
6220
  export function Result(success, failure) {
6209
6221
  const schema = declareConstructor()([success, failure], ([success, failure]) => (input, ast, options) => {
6210
6222
  if (!Result_.isResult(input)) {
6211
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6223
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
6212
6224
  }
6213
6225
  switch (input._tag) {
6214
6226
  case "Success":
6215
6227
  return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
6216
6228
  onSuccess: Result_.succeed,
6217
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["success"], issue)])
6229
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "success", issue, input, options)
6218
6230
  });
6219
6231
  case "Failure":
6220
6232
  return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
6221
6233
  onSuccess: Result_.fail,
6222
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["failure"], issue)])
6234
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "failure", issue, input, options)
6223
6235
  });
6224
6236
  }
6225
6237
  }, {
@@ -6340,11 +6352,11 @@ export function Redacted(value, options) {
6340
6352
  onSuccess: () => input,
6341
6353
  onFailure: (/** ignore the issue because of security reasons */
6342
6354
  ) => {
6343
- return new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue())]);
6355
+ return new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue(undefined, input, poptions))], input, poptions);
6344
6356
  }
6345
6357
  }));
6346
6358
  }
6347
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6359
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions));
6348
6360
  }, {
6349
6361
  representation: {
6350
6362
  id: "effect/schema/Redacted",
@@ -6442,18 +6454,18 @@ export function RedactedFromValue(value, options) {
6442
6454
  export function CauseReason(error, defect) {
6443
6455
  const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
6444
6456
  if (!Cause_.isReason(input)) {
6445
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6457
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
6446
6458
  }
6447
6459
  switch (input._tag) {
6448
6460
  case "Fail":
6449
6461
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(error)(input.error, options), {
6450
6462
  onSuccess: Cause_.makeFailReason,
6451
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["error"], issue)])
6463
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "error", issue, input, options)
6452
6464
  });
6453
6465
  case "Die":
6454
6466
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(defect)(input.defect, options), {
6455
6467
  onSuccess: Cause_.makeDieReason,
6456
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["defect"], issue)])
6468
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "defect", issue, input, options)
6457
6469
  });
6458
6470
  case "Interrupt":
6459
6471
  return Effect.succeed(input);
@@ -6581,11 +6593,11 @@ export function Cause(error, defect) {
6581
6593
  const failures = ArraySchema(CauseReason(error, defect));
6582
6594
  return (input, ast, options) => {
6583
6595
  if (!Cause_.isCause(input)) {
6584
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6596
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
6585
6597
  }
6586
6598
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
6587
6599
  onSuccess: Cause_.fromReasons,
6588
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["failures"], issue)])
6600
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
6589
6601
  });
6590
6602
  };
6591
6603
  }, {
@@ -6806,18 +6818,18 @@ export function Exit(value, error, defect) {
6806
6818
  const cause = Cause(error, defect);
6807
6819
  return (input, ast, options) => {
6808
6820
  if (!Exit_.isExit(input)) {
6809
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6821
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
6810
6822
  }
6811
6823
  switch (input._tag) {
6812
6824
  case "Success":
6813
6825
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
6814
6826
  onSuccess: Exit_.succeed,
6815
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], issue)])
6827
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
6816
6828
  });
6817
6829
  case "Failure":
6818
6830
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(cause)(input.cause, options), {
6819
6831
  onSuccess: Exit_.failCause,
6820
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["cause"], issue)])
6832
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
6821
6833
  });
6822
6834
  }
6823
6835
  };
@@ -6961,10 +6973,10 @@ export function ReadonlyMap(key, value) {
6961
6973
  if (input instanceof globalThis.Map) {
6962
6974
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
6963
6975
  onSuccess: array => new globalThis.Map(array),
6964
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["entries"], issue)])
6976
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
6965
6977
  });
6966
6978
  }
6967
- return Effect.fail(new SchemaIssue.InvalidType(ast));
6979
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
6968
6980
  };
6969
6981
  }, {
6970
6982
  representation: {
@@ -7030,10 +7042,10 @@ export function HashMap(key, value) {
7030
7042
  if (HashMap_.isHashMap(input)) {
7031
7043
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
7032
7044
  onSuccess: HashMap_.fromIterable,
7033
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["entries"], issue)])
7045
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
7034
7046
  });
7035
7047
  }
7036
- return Effect.fail(new SchemaIssue.InvalidType(ast));
7048
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
7037
7049
  };
7038
7050
  }, {
7039
7051
  representation: {
@@ -7100,10 +7112,10 @@ export function ReadonlySet(value) {
7100
7112
  if (input instanceof globalThis.Set) {
7101
7113
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
7102
7114
  onSuccess: array => new globalThis.Set(array),
7103
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["values"], issue)])
7115
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
7104
7116
  });
7105
7117
  }
7106
- return Effect.fail(new SchemaIssue.InvalidType(ast));
7118
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
7107
7119
  };
7108
7120
  }, {
7109
7121
  representation: {
@@ -7168,10 +7180,10 @@ export function HashSet(value) {
7168
7180
  if (HashSet_.isHashSet(input)) {
7169
7181
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
7170
7182
  onSuccess: HashSet_.fromIterable,
7171
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["values"], issue)])
7183
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
7172
7184
  });
7173
7185
  }
7174
- return Effect.fail(new SchemaIssue.InvalidType(ast));
7186
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
7175
7187
  };
7176
7188
  }, {
7177
7189
  representation: {
@@ -7236,10 +7248,10 @@ export function Chunk(value) {
7236
7248
  if (Chunk_.isChunk(input)) {
7237
7249
  return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
7238
7250
  onSuccess: Chunk_.fromIterable,
7239
- onFailure: issue => new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["values"], issue)])
7251
+ onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
7240
7252
  });
7241
7253
  }
7242
- return Effect.fail(new SchemaIssue.InvalidType(ast));
7254
+ return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
7243
7255
  };
7244
7256
  }, {
7245
7257
  representation: {
@@ -7315,11 +7327,11 @@ export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
7315
7327
  source: String,
7316
7328
  flags: String
7317
7329
  }), SchemaTransformation.transformOrFail({
7318
- decode: e => Effect.try({
7330
+ decode: (e, options) => Effect.try({
7319
7331
  try: () => new globalThis.RegExp(e.source, e.flags),
7320
7332
  catch: () => new SchemaIssue.InvalidValue({
7321
- message: "Expected valid RegExp source and flags"
7322
- })
7333
+ expected: "valid RegExp source and flags"
7334
+ }, e, options)
7323
7335
  }),
7324
7336
  encode: regExp => Effect.succeed({
7325
7337
  source: regExp.source,
@@ -7894,10 +7906,10 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
7894
7906
  name: String,
7895
7907
  lastModified: Int
7896
7908
  }), SchemaTransformation.transformOrFail({
7897
- decode: e => Result_.match(Encoding.decodeBase64(e.data), {
7909
+ decode: (e, options) => Result_.match(Encoding.decodeBase64(e.data), {
7898
7910
  onFailure: () => Effect.fail(new SchemaIssue.InvalidValue({
7899
- message: "Expected a valid Base64 string"
7900
- })),
7911
+ expected: "a valid Base64 string"
7912
+ }, e.data, options)),
7901
7913
  onSuccess: bytes => {
7902
7914
  const buffer = new globalThis.Uint8Array(bytes);
7903
7915
  return Effect.succeed(new globalThis.File([buffer], e.name, {
@@ -7906,7 +7918,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
7906
7918
  }));
7907
7919
  }
7908
7920
  }),
7909
- encode: file => Effect.tryPromise({
7921
+ encode: (file, options) => Effect.tryPromise({
7910
7922
  try: async () => {
7911
7923
  const bytes = new globalThis.Uint8Array(await file.arrayBuffer());
7912
7924
  return {
@@ -7917,8 +7929,8 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
7917
7929
  };
7918
7930
  },
7919
7931
  catch: () => new SchemaIssue.InvalidValue({
7920
- message: "Expected File to be readable"
7921
- })
7932
+ expected: "a readable File"
7933
+ }, file, options)
7922
7934
  })
7923
7935
  }))
7924
7936
  });
@@ -8988,8 +9000,8 @@ function getClassSchemaFactory(from, identifier, annotations) {
8988
9000
  const ClassTypeId = getClassTypeId(identifier);
8989
9001
  const isClassValue = input => input instanceof self || Predicate.hasProperty(input, ClassTypeId);
8990
9002
  const transformation = getClassTransformation(self);
8991
- const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
8992
- return isClassValue(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast));
9003
+ const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast, options) => {
9004
+ return isClassValue(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
8993
9005
  }, {
8994
9006
  identifier,
8995
9007
  [InternalAnnotations.CONSTRUCTOR_ANNOTATION_KEY]: ([from]) => ({
@@ -9013,8 +9025,8 @@ function isStruct(schema) {
9013
9025
  }
9014
9026
  /**
9015
9027
  * Creates a schema-backed class whose constructor validates input against a
9016
- * {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
9017
- * input.
9028
+ * {@link Struct} schema. Construction throws an `Error` with a
9029
+ * `SchemaIssue.Issue` in its `cause` on invalid input.
9018
9030
  *
9019
9031
  * **When to use**
9020
9032
  *
@@ -9204,35 +9216,41 @@ export const TaggedError = identifier => {
9204
9216
  };
9205
9217
  };
9206
9218
  /**
9207
- * Derives a {@link LazyArbitrary} from a schema. The result is memoized so
9208
- * repeated calls with the same schema are cheap.
9219
+ * Returns an {@link Arbitrary} factory derived from a schema. The generated
9220
+ * values satisfy the schema and use its decoded `Type`.
9221
+ *
9222
+ * **When to use**
9223
+ *
9224
+ * Use when you need a fast-check generator for values accepted by a schema.
9209
9225
  *
9210
9226
  * **Details**
9211
9227
  *
9212
- * Prefer {@link toArbitrary} when you need the arbitrary directly, or when you
9213
- * want derivation diagnostics via `{ report: true }`. Unsupported schema
9214
- * nodes, impossible constraints, invalid candidates, and recursive schemas
9215
- * without a finite terminal path fail immediately.
9228
+ * Constraints refine base generators; candidates add weighted sources while
9229
+ * filters still validate every value. Recursive schemas use terminal branches
9230
+ * and fail when no finite terminal path exists. The result is memoized so
9231
+ * repeated calls with the same schema are cheap.
9232
+ *
9233
+ * **Example** (Generating arbitrary values)
9234
+ *
9235
+ * ```ts import.meta.vitest
9236
+ * import { Schema } from "effect"
9237
+ * import * as FastCheck from "fast-check"
9238
+ *
9239
+ * const makePersonArbitrary = Schema.toArbitrary(
9240
+ * Schema.Struct({ name: Schema.String, age: Schema.Number })
9241
+ * )
9242
+ *
9243
+ * const PersonArbitrary = makePersonArbitrary(FastCheck)
9244
+ * FastCheck.sample(PersonArbitrary, 1)
9245
+ * ```
9216
9246
  *
9217
9247
  * @category generators
9218
9248
  * @since 4.0.0
9219
9249
  */
9220
- export function toArbitraryLazy(schema) {
9250
+ export function toArbitrary(schema) {
9221
9251
  const lawc = InternalArbitrary.memoized(schema.ast);
9222
9252
  return fc => lawc(fc, {});
9223
9253
  }
9224
- export function toArbitrary(schema, options) {
9225
- if (options?.report === true) {
9226
- const lawc = InternalArbitrary.memoized(schema.ast);
9227
- const report = InternalArbitrary.makeReport();
9228
- InternalArbitrary.collectReport(schema.ast, report);
9229
- return {
9230
- value: lawc(FastCheck, {}),
9231
- report: InternalArbitrary.toReport(report)
9232
- };
9233
- }
9234
- return toArbitraryLazy(schema)(FastCheck);
9235
- }
9236
9254
  // -----------------------------------------------------------------------------
9237
9255
  // Formatter
9238
9256
  // -----------------------------------------------------------------------------
@@ -9480,7 +9498,7 @@ export function toRepresentation(schema) {
9480
9498
  * @since 4.0.0
9481
9499
  */
9482
9500
  export function toJsonSchemaDocument(schema, options) {
9483
- const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast));
9501
+ const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast), InternalToJsonSchemaDocument.toRepresentationOptions);
9484
9502
  return InternalToJsonSchemaDocument.toJsonSchemaDocument(document, options);
9485
9503
  }
9486
9504
  /**
@@ -9503,14 +9521,13 @@ export function toCodecJson(schema) {
9503
9521
  schema
9504
9522
  });
9505
9523
  }
9506
- const toCodecJsonASTBase = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
9507
- const out = toCodecJsonBase(ast, toCodecJsonAST);
9524
+ /** @internal */
9525
+ export const toCodecJsonAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
9526
+ const out = toCodecJsonASTStep(ast, toCodecJsonAST);
9508
9527
  const context = ast.context;
9509
9528
  if (out === ast || context === undefined) return out;
9510
9529
  return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(context));
9511
9530
  });
9512
- /** @internal */
9513
- export const toCodecJsonAST = /*#__PURE__*/memoize(toCodecJsonASTBase);
9514
9531
  function withoutConstructorDefault(context) {
9515
9532
  return context.constructorDefault === undefined ? context : new SchemaAST.Context(context.isOptional, context.isMutable, undefined, context.annotations);
9516
9533
  }
@@ -9554,7 +9571,7 @@ const toCodecJsonReorder = /*#__PURE__*/makeReorder(ast => {
9554
9571
  return 1;
9555
9572
  }
9556
9573
  });
9557
- function toCodecJsonBase(ast, recur) {
9574
+ function toCodecJsonASTStep(ast, recur) {
9558
9575
  switch (ast._tag) {
9559
9576
  case "Declaration":
9560
9577
  {
@@ -9607,13 +9624,13 @@ function toCodecJsonBase(ast, recur) {
9607
9624
  * @since 4.0.0
9608
9625
  */
9609
9626
  export function toCodecIso(schema) {
9610
- return make(toCodecIsoTop(SchemaAST.toType(schema.ast)));
9627
+ return make(toCodecIsoAST(SchemaAST.toType(schema.ast)));
9611
9628
  }
9612
- const toCodecIsoTop = /*#__PURE__*/memoize(ast => {
9613
- const out = toCodecIsoBase(ast, toCodecIsoTop);
9629
+ const toCodecIsoAST = /*#__PURE__*/memoize(ast => {
9630
+ const out = toCodecIsoASTStep(ast, toCodecIsoAST);
9614
9631
  return out !== ast && ast.context !== undefined ? SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context)) : out;
9615
9632
  });
9616
- function toCodecIsoBase(ast, recur) {
9633
+ function toCodecIsoASTStep(ast, recur) {
9617
9634
  switch (ast._tag) {
9618
9635
  case "Declaration":
9619
9636
  {
@@ -9646,7 +9663,7 @@ function toCodecIsoBase(ast, recur) {
9646
9663
  * @since 4.0.0
9647
9664
  */
9648
9665
  export function toCodecStringTree(schema) {
9649
- return make(serializerStringTree(schema.ast), {
9666
+ return make(toCodecStringTreeAST(schema.ast), {
9650
9667
  schema
9651
9668
  });
9652
9669
  }
@@ -9669,7 +9686,7 @@ export function toCodecStringTree(schema) {
9669
9686
  * @since 4.0.0
9670
9687
  */
9671
9688
  export function toCodecArrayFromSingle(schema) {
9672
- return make(toCodecArrayFromSingleTop(schema.ast));
9689
+ return make(toCodecArrayFromSingleAST(schema.ast));
9673
9690
  }
9674
9691
  /**
9675
9692
  * Derives an XML encoder from a codec.
@@ -9793,7 +9810,7 @@ const toStringTreeReorder = /*#__PURE__*/makeReorder(ast => {
9793
9810
  return 1;
9794
9811
  }
9795
9812
  });
9796
- function serializerTree(ast, recur, onMissingAnnotation) {
9813
+ function toCodecStringTreeASTStep(ast, recur, onMissingAnnotation) {
9797
9814
  switch (ast._tag) {
9798
9815
  case "Declaration":
9799
9816
  {
@@ -9846,13 +9863,10 @@ function serializerTree(ast, recur, onMissingAnnotation) {
9846
9863
  }
9847
9864
  const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
9848
9865
  const booleanToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Union([/*#__PURE__*/new SchemaAST.Literal("true"), /*#__PURE__*/new SchemaAST.Literal("false")], "anyOf"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(s => s === "true"), /*#__PURE__*/SchemaGetter.String()));
9849
- const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
9850
- const isSerializerArrayFromSingle = ast => SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true;
9851
- const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
9852
- if (isSerializerArrayFromSingle(ast)) {
9853
- return ast;
9854
- }
9855
- const out = serializerTree(ast, serializerStringTree, ast => {
9866
+ const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
9867
+ const isCodecArrayFromSingleLink = link => link.transformation === arrayFromSingleTransformation;
9868
+ const toCodecStringTreeAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
9869
+ const out = toCodecStringTreeASTStep(ast, toCodecStringTreeAST, ast => {
9856
9870
  throw new globalThis.Error("Missing structural codec for StringTree", {
9857
9871
  cause: ast
9858
9872
  });
@@ -9861,24 +9875,22 @@ const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodin
9861
9875
  return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context));
9862
9876
  }
9863
9877
  return out;
9878
+ }, {
9879
+ stopAt: isCodecArrayFromSingleLink
9864
9880
  });
9865
9881
  const toArrayFromSingleInputElement = ast => SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown;
9866
- const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
9867
- const toCodecArrayFromSingleTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
9868
- if (isSerializerArrayFromSingle(ast)) {
9869
- return ast;
9870
- }
9871
- const out = onSerializerArrayFromSingle(ast);
9882
+ const toCodecArrayFromSingleAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
9883
+ const out = toCodecArrayFromSingleASTStep(ast);
9872
9884
  if (SchemaAST.isArrays(out)) {
9873
- const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf", {
9874
- [SERIALIZER_ENSURE_ARRAY]: true
9875
- }), out, arrayFromSingleTransformation);
9885
+ const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf"), out, arrayFromSingleTransformation);
9876
9886
  return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
9877
9887
  }
9878
9888
  return out;
9889
+ }, {
9890
+ stopAt: isCodecArrayFromSingleLink
9879
9891
  });
9880
- function onSerializerArrayFromSingle(ast) {
9881
- return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleTop) : ast;
9892
+ function toCodecArrayFromSingleASTStep(ast) {
9893
+ return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleAST) : ast;
9882
9894
  }
9883
9895
  /**
9884
9896
  * Reviver for persisted `isGreaterThanDate` checks.
@@ -10073,6 +10085,18 @@ export const isBetweenBigIntReviver = /*#__PURE__*/InternalSchema.makeFilterRevi
10073
10085
  * Derives an `Iso` optic from a schema that isomorphically converts between
10074
10086
  * the schema's `Type` and its `Iso` (intermediate / serialized form).
10075
10087
  *
10088
+ * **Details**
10089
+ *
10090
+ * Reading through the `Iso` encodes the schema value, while replacing through
10091
+ * it decodes the new focus.
10092
+ *
10093
+ * **Gotchas**
10094
+ *
10095
+ * Either direction can throw an `Error` with the generic message
10096
+ * `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
10097
+ * the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
10098
+ * human-readable details are needed.
10099
+ *
10076
10100
  * @category converting
10077
10101
  * @since 4.0.0
10078
10102
  */
@@ -10132,6 +10156,19 @@ export function overrideToCodecIso(to, transformation) {
10132
10156
  * {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
10133
10157
  * and new values, and can apply patches back to the typed value.
10134
10158
  *
10159
+ * **Details**
10160
+ *
10161
+ * `diff` encodes both values before computing the patch. `patch` encodes the old
10162
+ * value, applies the patch to its JSON representation, and decodes the result.
10163
+ *
10164
+ * **Gotchas**
10165
+ *
10166
+ * Schema encoding or decoding failures throw an `Error` with the generic message
10167
+ * `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
10168
+ * the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
10169
+ * human-readable details are needed. Errors produced by {@link JsonPatch.apply}
10170
+ * for invalid patch operations are separate from schema validation failures.
10171
+ *
10135
10172
  * @category converting
10136
10173
  * @since 4.0.0
10137
10174
  */