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/Optic.ts CHANGED
@@ -12,7 +12,6 @@
12
12
  * @since 4.0.0
13
13
  */
14
14
 
15
- import { format } from "./Formatter.ts"
16
15
  import { identity } from "./Function.ts"
17
16
  import * as InternalRecord from "./internal/record.ts"
18
17
  import * as Option from "./Option.ts"
@@ -20,7 +19,7 @@ import * as Predicate from "./Predicate.ts"
20
19
  import * as Result from "./Result.ts"
21
20
  import type * as Schema from "./Schema.ts"
22
21
  import * as SchemaAST from "./SchemaAST.ts"
23
- import type * as SchemaIssue from "./SchemaIssue.ts"
22
+ import * as SchemaIssue from "./SchemaIssue.ts"
24
23
  import * as Struct from "./Struct.ts"
25
24
  import type { IsUnion } from "./Types.ts"
26
25
 
@@ -192,7 +191,7 @@ export function makeLens<S, A>(get: (s: S) => A, replace: (a: A, s: S) => S): Le
192
191
  * **Details**
193
192
  *
194
193
  * - `getResult(s)` returns `Result.Success<A>` when the focus matches, or
195
- * `Result.Failure<string>` with an error message.
194
+ * `Result.Failure<SchemaIssue.Issue>` with a structured issue.
196
195
  * - `set(a)` always succeeds and returns a new `S`.
197
196
  * - Extends {@link Optional}.
198
197
  * - Composing two Prisms produces a Prism; composing a Prism with a
@@ -235,17 +234,20 @@ export interface Prism<in out S, in out A> extends Optional<S, A> {
235
234
  *
236
235
  * **Details**
237
236
  *
238
- * - `getResult` should return `Result.fail(message)` on mismatch.
237
+ * - `getResult` should return `Result.fail(issue)` on mismatch.
238
+ * - Issues are not formatted automatically; callers choose how to render them.
239
239
  *
240
240
  * **Example** (Parsing a string to a number)
241
241
  *
242
242
  * ```ts import.meta.vitest
243
- * import { Optic, Result } from "effect"
243
+ * import { Optic, Result, SchemaIssue } from "effect"
244
244
  *
245
245
  * const numeric = Optic.makePrism<string, number>(
246
246
  * (s) => {
247
247
  * const n = Number(s)
248
- * return Number.isNaN(n) ? Result.fail("not a number") : Result.succeed(n)
248
+ * return Number.isNaN(n)
249
+ * ? Result.fail(new SchemaIssue.InvalidValue({ message: "not a number" }))
250
+ * : Result.succeed(n)
249
251
  * },
250
252
  * String
251
253
  * )
@@ -261,7 +263,10 @@ export interface Prism<in out S, in out A> extends Optional<S, A> {
261
263
  * @category constructors
262
264
  * @since 4.0.0
263
265
  */
264
- export function makePrism<S, A>(getResult: (s: S) => Result.Result<A, string>, set: (a: A) => S): Prism<S, A> {
266
+ export function makePrism<S, A>(
267
+ getResult: (s: S) => Result.Result<A, SchemaIssue.Issue>,
268
+ set: (a: A) => S
269
+ ): Prism<S, A> {
265
270
  return make(primitiveNode("Prism", getResult, set))
266
271
  }
267
272
 
@@ -276,7 +281,7 @@ export function makePrism<S, A>(getResult: (s: S) => Result.Result<A, string>, s
276
281
  *
277
282
  * **Details**
278
283
  *
279
- * - `getResult` runs all checks; fails with a combined error message when
284
+ * - `getResult` runs all checks and preserves their structured issues when
280
285
  * any check fails.
281
286
  * - `set` is identity — the value passes through unchanged.
282
287
  *
@@ -366,12 +371,12 @@ class CheckNode<T> {
366
371
  readonly _tag = "CheckNode"
367
372
  readonly kind = "Prism"
368
373
  readonly checks: readonly [SchemaAST.Check<T>, ...Array<SchemaAST.Check<T>>]
369
- readonly get: (s: T) => Result.Result<T, string>
374
+ readonly get: (s: T) => Result.Result<T, SchemaIssue.Issue>
370
375
  readonly set = identity
371
376
 
372
377
  constructor(checks: readonly [SchemaAST.Check<T>, ...Array<SchemaAST.Check<T>>]) {
373
378
  this.checks = checks
374
- this.get = (s) => Result.mapError(SchemaAST.runChecks(checks, s), String)
379
+ this.get = (s) => SchemaAST.runChecks(checks, s)
375
380
  }
376
381
  }
377
382
 
@@ -407,9 +412,9 @@ type ForbidUnion<A, Message extends string> = IsUnion<A> extends true ? [Message
407
412
  *
408
413
  * **Details**
409
414
  *
410
- * - `getResult(s)` returns `Result.Success<A>` or `Result.Failure<string>`.
415
+ * - `getResult(s)` returns `Result.Success<A>` or `Result.Failure<SchemaIssue.Issue>`.
411
416
  * - `replaceResult(a, s)` returns `Result.Success<S>` or
412
- * `Result.Failure<string>`.
417
+ * `Result.Failure<SchemaIssue.Issue>`.
413
418
  * - `replace(a, s)` returns the original `s` on failure (never throws).
414
419
  * - `modify(f)` returns the original `s` on failure (never throws).
415
420
  * - All operations are pure; inputs are never mutated.
@@ -441,9 +446,9 @@ export interface Optional<in out S, in out A> {
441
446
  /**
442
447
  * Attempts to read the focus `A` from the whole `S`. Returns
443
448
  * `Result.Success<A>` when the focus exists, or
444
- * `Result.Failure<string>` with a descriptive error otherwise.
449
+ * `Result.Failure<SchemaIssue.Issue>` with a structured issue otherwise.
445
450
  */
446
- readonly getResult: (s: S) => Result.Result<A, string>
451
+ readonly getResult: (s: S) => Result.Result<A, SchemaIssue.Issue>
447
452
  /**
448
453
  * Replaces the focus in `S` with a new `A`. Returns the original `s`
449
454
  * unchanged when the optic cannot focus (never throws).
@@ -453,7 +458,7 @@ export interface Optional<in out S, in out A> {
453
458
  * Like {@link replace}, but returns an explicit `Result` so callers can
454
459
  * detect and handle failure.
455
460
  */
456
- readonly replaceResult: (a: A, s: S) => Result.Result<S, string>
461
+ readonly replaceResult: (a: A, s: S) => Result.Result<S, SchemaIssue.Issue>
457
462
  /**
458
463
  * Composes this optic with another. The result type is the weakest of
459
464
  * the two: Iso + Iso = Iso, Lens + Prism = Optional, etc.
@@ -635,6 +640,8 @@ export interface Optional<in out S, in out A> {
635
640
  * - On a {@link Prism}, returns a Prism.
636
641
  * - On an {@link Optional}, returns an Optional.
637
642
  * - Shorthand for `.refine(s => s._tag === tag)`.
643
+ * - A non-matching value fails with {@link SchemaIssue.InvalidValue} whose
644
+ * `expected` annotation is `"<tag> tag"`.
638
645
  *
639
646
  * **Example** (Focusing a tagged variant)
640
647
  *
@@ -674,6 +681,9 @@ export interface Optional<in out S, in out A> {
674
681
  *
675
682
  * - Always returns an {@link Optional}.
676
683
  * - Does **not** work on union types (compile error).
684
+ * - A missing key fails with a {@link SchemaIssue.Pointer} at that key whose
685
+ * inner issue is {@link SchemaIssue.MissingKey}, for both `getResult` and
686
+ * `replaceResult`.
677
687
  *
678
688
  * **Example** (Accessing records safely)
679
689
  *
@@ -800,7 +810,9 @@ export interface Optional<in out S, in out A> {
800
810
  * element. Non-focusable elements are skipped.
801
811
  * - **replaceResult** expects exactly as many values as were collected by
802
812
  * `getResult` and writes them back in order. Fails with a
803
- * length-mismatch error if counts differ.
813
+ * {@link SchemaIssue.InvalidValue} if counts differ. If an inner replacement
814
+ * fails, its issue is wrapped in a {@link SchemaIssue.Pointer} at the element
815
+ * index.
804
816
  *
805
817
  * **Example** (Incrementing liked posts)
806
818
  *
@@ -871,26 +883,29 @@ export interface Optional<in out S, in out A> {
871
883
  *
872
884
  * **Details**
873
885
  *
874
- * - `getResult` should return `Result.fail(message)` on mismatch.
875
- * - `set` should return `Result.fail(message)` when the update cannot be
886
+ * - `getResult` should return `Result.fail(issue)` on mismatch.
887
+ * - `set` should return `Result.fail(issue)` when the update cannot be
876
888
  * applied.
889
+ * - Issues are not formatted automatically; callers choose how to render them.
877
890
  *
878
891
  * **Example** (Accessing record keys safely)
879
892
  *
880
893
  * ```ts import.meta.vitest
881
- * import { Optic, Result } from "effect"
894
+ * import { Optic, Result, SchemaIssue } from "effect"
882
895
  *
883
- * const atKey = (key: string) =>
884
- * Optic.makeOptional<Record<string, number>, number>(
896
+ * const atKey = (key: string) => {
897
+ * const issue = new SchemaIssue.Pointer([key], new SchemaIssue.MissingKey(undefined))
898
+ * return Optic.makeOptional<Record<string, number>, number>(
885
899
  * (s) =>
886
900
  * Object.hasOwn(s, key)
887
901
  * ? Result.succeed(s[key])
888
- * : Result.fail(`Key "${key}" not found`),
902
+ * : Result.fail(issue),
889
903
  * (a, s) =>
890
904
  * Object.hasOwn(s, key)
891
905
  * ? Result.succeed({ ...s, [key]: a })
892
- * : Result.fail(`Key "${key}" not found`)
906
+ * : Result.fail(issue)
893
907
  * )
908
+ * }
894
909
  *
895
910
  * atKey("x").getResult({ x: 1 }) // => Result.succeed(1)
896
911
  * ```
@@ -903,8 +918,8 @@ export interface Optional<in out S, in out A> {
903
918
  * @since 4.0.0
904
919
  */
905
920
  export function makeOptional<S, A>(
906
- getResult: (s: S) => Result.Result<A, string>,
907
- set: (a: A, s: S) => Result.Result<S, string>
921
+ getResult: (s: S) => Result.Result<A, SchemaIssue.Issue>,
922
+ set: (a: A, s: S) => Result.Result<S, SchemaIssue.Issue>
908
923
  ): Optional<S, A> {
909
924
  return make(primitiveNode("Optional", getResult, set))
910
925
  }
@@ -953,12 +968,12 @@ export interface Traversal<in out S, in out A> extends Optional<S, ReadonlyArray
953
968
  class OptionalImpl<S, A> implements Optional<S, A> {
954
969
  /** @internal */
955
970
  readonly node: Node
956
- readonly getResult: (s: S) => Result.Result<A, string>
957
- readonly replaceResult: (a: A, s: S) => Result.Result<S, string>
971
+ readonly getResult: (s: S) => Result.Result<A, SchemaIssue.Issue>
972
+ readonly replaceResult: (a: A, s: S) => Result.Result<S, SchemaIssue.Issue>
958
973
  constructor(
959
974
  node: Node,
960
- getResult: (s: S) => Result.Result<A, string>,
961
- replaceResult: (a: A, s: S) => Result.Result<S, string>
975
+ getResult: (s: S) => Result.Result<A, SchemaIssue.Issue>,
976
+ replaceResult: (a: A, s: S) => Result.Result<S, SchemaIssue.Issue>
962
977
  ) {
963
978
  this.node = node
964
979
  this.getResult = getResult
@@ -1007,22 +1022,22 @@ class OptionalImpl<S, A> implements Optional<S, A> {
1007
1022
  return make(compose(this.node, [new CheckNode([SchemaAST.makeFilterByGuard(refinement, annotations)])]))
1008
1023
  }
1009
1024
  tag(tag: string): any {
1025
+ const err = Result.fail(new SchemaIssue.InvalidValue({ expected: `${JSON.stringify(tag)} tag` }))
1010
1026
  return make(
1011
1027
  compose(
1012
1028
  this.node,
1013
1029
  primitiveNode(
1014
1030
  "Prism",
1015
- (s) =>
1016
- s._tag === tag
1017
- ? Result.succeed(s)
1018
- : Result.fail(`Expected ${format(tag)} tag, got ${format(s._tag)}`),
1031
+ (s) => s._tag === tag ? Result.succeed(s) : err,
1019
1032
  identity
1020
1033
  )
1021
1034
  )
1022
1035
  )
1023
1036
  }
1024
1037
  at(key: PropertyKey, ..._rest: Array<any>): any {
1025
- const err = Result.fail(`Key ${format(key)} not found`)
1038
+ const err = Result.fail(
1039
+ new SchemaIssue.Pointer([key], new SchemaIssue.MissingKey(undefined))
1040
+ )
1026
1041
  return make(
1027
1042
  compose(
1028
1043
  this.node,
@@ -1076,7 +1091,9 @@ class OptionalImpl<S, A> implements Optional<S, A> {
1076
1091
  // 2) arity check
1077
1092
  if (bs.length !== idxs.length) {
1078
1093
  return Result.fail(
1079
- `each: replacement length mismatch: ${bs.length} !== ${idxs.length}`
1094
+ new SchemaIssue.InvalidValue({
1095
+ message: `each: replacement length mismatch: ${bs.length} !== ${idxs.length}`
1096
+ })
1080
1097
  )
1081
1098
  }
1082
1099
 
@@ -1086,7 +1103,7 @@ class OptionalImpl<S, A> implements Optional<S, A> {
1086
1103
  const i = idxs[k]
1087
1104
  const r = inner.replaceResult(bs[k], as[i])
1088
1105
  if (Result.isFailure(r)) {
1089
- return Result.fail(`each: could not set element ${i}`)
1106
+ return Result.fail(new SchemaIssue.Pointer([i], r.failure))
1090
1107
  }
1091
1108
  out[i] = r.success
1092
1109
  }
@@ -1133,7 +1150,7 @@ class LensImpl<S, A> extends OptionalImpl<S, A> implements Lens<S, A> {
1133
1150
 
1134
1151
  class PrismImpl<S, A> extends OptionalImpl<S, A> implements Prism<S, A> {
1135
1152
  readonly set: (a: A) => S
1136
- constructor(node: Node, getResult: (s: S) => Result.Result<A, string>, set: (a: A) => S) {
1153
+ constructor(node: Node, getResult: (s: S) => Result.Result<A, SchemaIssue.Issue>, set: (a: A) => S) {
1137
1154
  super(node, getResult, (a, _) => Result.succeed(set(a)))
1138
1155
  this.set = set
1139
1156
  }
@@ -1390,7 +1407,7 @@ export function entries<A>(): Iso<Record<string, A>, ReadonlyArray<readonly [str
1390
1407
  *
1391
1408
  * **Details**
1392
1409
  *
1393
- * - `getResult` fails with an error message when the option is `None`.
1410
+ * - `getResult` fails with a structured issue when the option is `None`.
1394
1411
  * - `set(a)` wraps `a` in `Option.some(a)`.
1395
1412
  *
1396
1413
  * **Example** (Accessing Some value)
@@ -1416,11 +1433,7 @@ export function entries<A>(): Iso<Record<string, A>, ReadonlyArray<readonly [str
1416
1433
  export function some<A>(): Prism<Option.Option<A>, A> {
1417
1434
  const run = runRefinement(Option.isSome, { expected: "a Some value" })
1418
1435
  return makePrism(
1419
- (s) =>
1420
- Result.mapBoth(run(s), {
1421
- onFailure: String,
1422
- onSuccess: (s) => s.value
1423
- }),
1436
+ (s) => Result.map(run(s), (s) => s.value),
1424
1437
  Option.some
1425
1438
  )
1426
1439
  }
@@ -1459,11 +1472,7 @@ export function some<A>(): Prism<Option.Option<A>, A> {
1459
1472
  export function none<A>(): Prism<Option.Option<A>, undefined> {
1460
1473
  const run = runRefinement(Option.isNone, { expected: "a None value" })
1461
1474
  return makePrism(
1462
- (s) =>
1463
- Result.mapBoth(run(s), {
1464
- onFailure: String,
1465
- onSuccess: () => undefined
1466
- }),
1475
+ (s) => Result.map(run(s), () => undefined),
1467
1476
  () => Option.none()
1468
1477
  )
1469
1478
  }
@@ -1502,11 +1511,7 @@ export function none<A>(): Prism<Option.Option<A>, undefined> {
1502
1511
  export function success<A, E>(): Prism<Result.Result<A, E>, A> {
1503
1512
  const run = runRefinement(Result.isSuccess, { expected: "a Result.Success value" })
1504
1513
  return makePrism(
1505
- (s) =>
1506
- Result.mapBoth(run(s), {
1507
- onFailure: String,
1508
- onSuccess: (s) => s.success
1509
- }),
1514
+ (s) => Result.map(run(s), (s) => s.success),
1510
1515
  Result.succeed
1511
1516
  )
1512
1517
  }
@@ -1545,11 +1550,7 @@ export function success<A, E>(): Prism<Result.Result<A, E>, A> {
1545
1550
  export function failure<A, E>(): Prism<Result.Result<A, E>, E> {
1546
1551
  const run = runRefinement(Result.isFailure, { expected: "a Result.Failure value" })
1547
1552
  return makePrism(
1548
- (s) =>
1549
- Result.mapBoth(run(s), {
1550
- onFailure: String,
1551
- onSuccess: (s) => s.failure
1552
- }),
1553
+ (s) => Result.map(run(s), (s) => s.failure),
1553
1554
  Result.fail
1554
1555
  )
1555
1556
  }