effect 4.0.0-beta.84 → 4.0.0-beta.86

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 (292) hide show
  1. package/dist/ChannelSchema.d.ts +8 -8
  2. package/dist/ChannelSchema.d.ts.map +1 -1
  3. package/dist/Config.d.ts +2 -2
  4. package/dist/Config.d.ts.map +1 -1
  5. package/dist/Config.js +10 -3
  6. package/dist/Config.js.map +1 -1
  7. package/dist/Context.d.ts.map +1 -1
  8. package/dist/Context.js +4 -3
  9. package/dist/Context.js.map +1 -1
  10. package/dist/Cron.d.ts.map +1 -1
  11. package/dist/Cron.js +4 -0
  12. package/dist/Cron.js.map +1 -1
  13. package/dist/Layer.js +4 -3
  14. package/dist/Layer.js.map +1 -1
  15. package/dist/LayerMap.d.ts.map +1 -1
  16. package/dist/LayerMap.js +4 -3
  17. package/dist/LayerMap.js.map +1 -1
  18. package/dist/Random.d.ts +31 -0
  19. package/dist/Random.d.ts.map +1 -1
  20. package/dist/Random.js +32 -0
  21. package/dist/Random.js.map +1 -1
  22. package/dist/Schema.d.ts +793 -399
  23. package/dist/Schema.d.ts.map +1 -1
  24. package/dist/Schema.js +121 -75
  25. package/dist/Schema.js.map +1 -1
  26. package/dist/SchemaAST.d.ts +8 -7
  27. package/dist/SchemaAST.d.ts.map +1 -1
  28. package/dist/SchemaAST.js +207 -157
  29. package/dist/SchemaAST.js.map +1 -1
  30. package/dist/SchemaParser.d.ts +24 -24
  31. package/dist/SchemaParser.d.ts.map +1 -1
  32. package/dist/SchemaParser.js +43 -39
  33. package/dist/SchemaParser.js.map +1 -1
  34. package/dist/SchemaRepresentation.d.ts +300 -300
  35. package/dist/internal/effect.js +16 -17
  36. package/dist/internal/effect.js.map +1 -1
  37. package/dist/internal/matcher.js +0 -2
  38. package/dist/internal/matcher.js.map +1 -1
  39. package/dist/internal/schema/arbitrary.js +17 -1
  40. package/dist/internal/schema/arbitrary.js.map +1 -1
  41. package/dist/internal/schema/representation.js +1 -5
  42. package/dist/internal/schema/representation.js.map +1 -1
  43. package/dist/internal/schema/schema.js.map +1 -1
  44. package/dist/internal/stackTraceLimit.d.ts +2 -0
  45. package/dist/internal/stackTraceLimit.d.ts.map +1 -0
  46. package/dist/internal/stackTraceLimit.js +40 -0
  47. package/dist/internal/stackTraceLimit.js.map +1 -0
  48. package/dist/internal/tracer.d.ts.map +1 -1
  49. package/dist/internal/tracer.js +4 -3
  50. package/dist/internal/tracer.js.map +1 -1
  51. package/dist/testing/TestSchema.d.ts +9 -9
  52. package/dist/testing/TestSchema.d.ts.map +1 -1
  53. package/dist/testing/TestSchema.js +3 -2
  54. package/dist/testing/TestSchema.js.map +1 -1
  55. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +2 -2
  56. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  57. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  58. package/dist/unstable/ai/Chat.d.ts +1 -1
  59. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  60. package/dist/unstable/ai/LanguageModel.d.ts +4 -4
  61. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  62. package/dist/unstable/ai/McpSchema.d.ts +13 -6
  63. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  64. package/dist/unstable/ai/McpSchema.js.map +1 -1
  65. package/dist/unstable/ai/McpServer.d.ts +4 -4
  66. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  67. package/dist/unstable/ai/McpServer.js.map +1 -1
  68. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +2 -2
  69. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  70. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  71. package/dist/unstable/ai/Response.d.ts +2 -2
  72. package/dist/unstable/ai/Response.d.ts.map +1 -1
  73. package/dist/unstable/ai/Response.js.map +1 -1
  74. package/dist/unstable/ai/Tool.d.ts +26 -26
  75. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  76. package/dist/unstable/ai/Tool.js +4 -5
  77. package/dist/unstable/ai/Tool.js.map +1 -1
  78. package/dist/unstable/cli/Argument.d.ts +8 -7
  79. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  80. package/dist/unstable/cli/Argument.js.map +1 -1
  81. package/dist/unstable/cli/Flag.d.ts +8 -7
  82. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  83. package/dist/unstable/cli/Flag.js.map +1 -1
  84. package/dist/unstable/cli/Param.d.ts +1806 -168
  85. package/dist/unstable/cli/Param.d.ts.map +1 -1
  86. package/dist/unstable/cli/Param.js +0 -70
  87. package/dist/unstable/cli/Param.js.map +1 -1
  88. package/dist/unstable/cli/Primitive.d.ts +3 -4
  89. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  90. package/dist/unstable/cli/Primitive.js.map +1 -1
  91. package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
  92. package/dist/unstable/cli/internal/ansi.js +0 -22
  93. package/dist/unstable/cli/internal/ansi.js.map +1 -1
  94. package/dist/unstable/cli/internal/config.d.ts +48 -0
  95. package/dist/unstable/cli/internal/config.d.ts.map +1 -1
  96. package/dist/unstable/cli/internal/config.js +0 -6
  97. package/dist/unstable/cli/internal/config.js.map +1 -1
  98. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -3
  99. package/dist/unstable/cluster/Reply.d.ts +2 -2
  100. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  101. package/dist/unstable/cluster/Reply.js.map +1 -1
  102. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  103. package/dist/unstable/encoding/Msgpack.d.ts +6 -6
  104. package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
  105. package/dist/unstable/encoding/Msgpack.js.map +1 -1
  106. package/dist/unstable/encoding/Ndjson.d.ts +8 -8
  107. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  108. package/dist/unstable/encoding/Sse.d.ts +1 -1
  109. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  110. package/dist/unstable/encoding/Sse.js.map +1 -1
  111. package/dist/unstable/eventlog/EventLogMessage.d.ts +22 -22
  112. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  113. package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
  114. package/dist/unstable/http/HttpBody.d.ts +1 -1
  115. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  116. package/dist/unstable/http/HttpClientRequest.d.ts +1 -1
  117. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  118. package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
  119. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  120. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  121. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  122. package/dist/unstable/http/HttpMiddleware.js +12 -3
  123. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  124. package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
  125. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  126. package/dist/unstable/httpapi/HttpApiClient.d.ts +2 -2
  127. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  128. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  129. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +32 -32
  130. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  131. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  132. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
  133. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  134. package/dist/unstable/httpapi/HttpApiMiddleware.js +4 -3
  135. package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
  136. package/dist/unstable/httpapi/HttpApiSchema.d.ts +13 -6
  137. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  138. package/dist/unstable/httpapi/HttpApiSchema.js +0 -13
  139. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  140. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  141. package/dist/unstable/observability/internal/otlpProtobuf.js +0 -68
  142. package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
  143. package/dist/unstable/observability/internal/protobuf.js +0 -28
  144. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  145. package/dist/unstable/persistence/KeyValueStore.d.ts +2 -2
  146. package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
  147. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  148. package/dist/unstable/persistence/Persistable.d.ts +6 -6
  149. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  150. package/dist/unstable/persistence/PersistedQueue.d.ts +3 -3
  151. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  152. package/dist/unstable/persistence/PersistedQueue.js +1 -1
  153. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  154. package/dist/unstable/persistence/Persistence.d.ts +5 -5
  155. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  156. package/dist/unstable/reactivity/AsyncResult.d.ts +2 -2
  157. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  158. package/dist/unstable/reactivity/Atom.d.ts +1 -1
  159. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  160. package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
  161. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  162. package/dist/unstable/rpc/Rpc.d.ts +3 -4
  163. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  164. package/dist/unstable/rpc/Rpc.js +1 -1
  165. package/dist/unstable/rpc/Rpc.js.map +1 -1
  166. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  167. package/dist/unstable/rpc/RpcClient.js +25 -4
  168. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  169. package/dist/unstable/rpc/RpcMessage.d.ts +7 -0
  170. package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
  171. package/dist/unstable/rpc/RpcMessage.js +20 -0
  172. package/dist/unstable/rpc/RpcMessage.js.map +1 -1
  173. package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
  174. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  175. package/dist/unstable/rpc/RpcMiddleware.js +4 -3
  176. package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
  177. package/dist/unstable/rpc/RpcSchema.d.ts +10 -3
  178. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  179. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  180. package/dist/unstable/rpc/RpcWorker.d.ts +3 -3
  181. package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
  182. package/dist/unstable/schema/Model.d.ts +2 -2
  183. package/dist/unstable/schema/Model.d.ts.map +1 -1
  184. package/dist/unstable/schema/Model.js.map +1 -1
  185. package/dist/unstable/schema/VariantSchema.d.ts +16 -2
  186. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  187. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  188. package/dist/unstable/sql/SqlConnection.d.ts +1 -0
  189. package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
  190. package/dist/unstable/sql/SqlConnection.js.map +1 -1
  191. package/dist/unstable/sql/SqlModel.js.map +1 -1
  192. package/dist/unstable/sql/SqlResolver.d.ts +4 -4
  193. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  194. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  195. package/dist/unstable/sql/SqlSchema.d.ts +5 -5
  196. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  197. package/dist/unstable/sql/Statement.d.ts +1 -0
  198. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  199. package/dist/unstable/sql/Statement.js +3 -0
  200. package/dist/unstable/sql/Statement.js.map +1 -1
  201. package/dist/unstable/workflow/Activity.d.ts +2 -2
  202. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  203. package/dist/unstable/workflow/DurableDeferred.d.ts +18 -18
  204. package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
  205. package/dist/unstable/workflow/Workflow.d.ts +3 -3
  206. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  207. package/dist/unstable/workflow/Workflow.js.map +1 -1
  208. package/dist/unstable/workflow/WorkflowEngine.d.ts +3 -3
  209. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  210. package/package.json +1 -1
  211. package/src/ChannelSchema.ts +9 -9
  212. package/src/Config.ts +12 -5
  213. package/src/Context.ts +4 -5
  214. package/src/Cron.ts +4 -0
  215. package/src/Layer.ts +4 -4
  216. package/src/LayerMap.ts +4 -3
  217. package/src/Random.ts +42 -0
  218. package/src/Schema.ts +1038 -710
  219. package/src/SchemaAST.ts +239 -169
  220. package/src/SchemaParser.ts +85 -77
  221. package/src/internal/effect.ts +17 -33
  222. package/src/internal/matcher.ts +0 -5
  223. package/src/internal/schema/arbitrary.ts +24 -3
  224. package/src/internal/schema/representation.ts +1 -5
  225. package/src/internal/schema/schema.ts +1 -1
  226. package/src/internal/stackTraceLimit.ts +63 -0
  227. package/src/internal/tracer.ts +4 -3
  228. package/src/testing/TestSchema.ts +14 -13
  229. package/src/unstable/ai/AnthropicStructuredOutput.ts +2 -2
  230. package/src/unstable/ai/Chat.ts +1 -1
  231. package/src/unstable/ai/LanguageModel.ts +7 -7
  232. package/src/unstable/ai/McpSchema.ts +16 -14
  233. package/src/unstable/ai/McpServer.ts +7 -7
  234. package/src/unstable/ai/OpenAiStructuredOutput.ts +2 -2
  235. package/src/unstable/ai/Response.ts +9 -5
  236. package/src/unstable/ai/Tool.ts +53 -50
  237. package/src/unstable/cli/Argument.ts +9 -8
  238. package/src/unstable/cli/Flag.ts +9 -8
  239. package/src/unstable/cli/Param.ts +6 -146
  240. package/src/unstable/cli/Primitive.ts +5 -6
  241. package/src/unstable/cli/internal/ansi.ts +0 -33
  242. package/src/unstable/cli/internal/config.ts +0 -8
  243. package/src/unstable/cli/internal/parser.ts +2 -2
  244. package/src/unstable/cluster/MessageStorage.ts +1 -1
  245. package/src/unstable/cluster/Reply.ts +6 -2
  246. package/src/unstable/devtools/DevToolsSchema.ts +1 -1
  247. package/src/unstable/encoding/Msgpack.ts +9 -7
  248. package/src/unstable/encoding/Ndjson.ts +10 -10
  249. package/src/unstable/encoding/Sse.ts +1 -1
  250. package/src/unstable/eventlog/Event.ts +3 -3
  251. package/src/unstable/http/HttpBody.ts +1 -1
  252. package/src/unstable/http/HttpClientRequest.ts +1 -1
  253. package/src/unstable/http/HttpIncomingMessage.ts +1 -1
  254. package/src/unstable/http/HttpMiddleware.ts +12 -3
  255. package/src/unstable/httpapi/HttpApi.ts +1 -1
  256. package/src/unstable/httpapi/HttpApiBuilder.ts +9 -5
  257. package/src/unstable/httpapi/HttpApiClient.ts +10 -10
  258. package/src/unstable/httpapi/HttpApiEndpoint.ts +45 -33
  259. package/src/unstable/httpapi/HttpApiMiddleware.ts +6 -5
  260. package/src/unstable/httpapi/HttpApiSchema.ts +16 -43
  261. package/src/unstable/httpapi/OpenApi.ts +5 -5
  262. package/src/unstable/observability/internal/otlpProtobuf.ts +0 -75
  263. package/src/unstable/observability/internal/protobuf.ts +0 -42
  264. package/src/unstable/persistence/KeyValueStore.ts +2 -2
  265. package/src/unstable/persistence/Persistable.ts +7 -7
  266. package/src/unstable/persistence/PersistedQueue.ts +4 -4
  267. package/src/unstable/persistence/Persistence.ts +5 -5
  268. package/src/unstable/reactivity/AsyncResult.ts +4 -4
  269. package/src/unstable/reactivity/Atom.ts +1 -1
  270. package/src/unstable/reactivity/AtomHttpApi.ts +1 -1
  271. package/src/unstable/rpc/Rpc.ts +7 -8
  272. package/src/unstable/rpc/RpcClient.ts +26 -4
  273. package/src/unstable/rpc/RpcMessage.ts +19 -0
  274. package/src/unstable/rpc/RpcMiddleware.ts +6 -5
  275. package/src/unstable/rpc/RpcSchema.ts +12 -9
  276. package/src/unstable/rpc/RpcWorker.ts +3 -3
  277. package/src/unstable/schema/Model.ts +2 -2
  278. package/src/unstable/schema/VariantSchema.ts +19 -17
  279. package/src/unstable/sql/SqlConnection.ts +5 -0
  280. package/src/unstable/sql/SqlModel.ts +2 -2
  281. package/src/unstable/sql/SqlResolver.ts +6 -6
  282. package/src/unstable/sql/SqlSchema.ts +5 -5
  283. package/src/unstable/sql/Statement.ts +11 -0
  284. package/src/unstable/workflow/Activity.ts +6 -6
  285. package/src/unstable/workflow/DurableDeferred.ts +33 -33
  286. package/src/unstable/workflow/Workflow.ts +5 -5
  287. package/src/unstable/workflow/WorkflowEngine.ts +10 -10
  288. package/dist/internal/concurrency.d.ts +0 -2
  289. package/dist/internal/concurrency.d.ts.map +0 -1
  290. package/dist/internal/concurrency.js +0 -29
  291. package/dist/internal/concurrency.js.map +0 -1
  292. package/src/internal/concurrency.ts +0 -52
package/dist/Schema.js CHANGED
@@ -87,7 +87,7 @@ const TypeId = InternalSchema.TypeId;
87
87
  * const isBox = (u: unknown): u is Box<unknown> =>
88
88
  * typeof u === "object" && u !== null && "value" in u
89
89
  *
90
- * const Box = <A extends Schema.Top>(item: A) =>
90
+ * const Box = <A extends Schema.Constraint>(item: A) =>
91
91
  * Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
92
92
  * [item],
93
93
  * ([itemCodec]) =>
@@ -813,7 +813,7 @@ export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
813
813
  * @category decoding
814
814
  * @since 3.10.0
815
815
  */
816
- export const decodeOption = decodeUnknownOption;
816
+ export const decodeOption = SchemaParser.decodeOption;
817
817
  /**
818
818
  * Decodes an `unknown` input against a schema, returning a `Result` that
819
819
  * succeeds with the decoded value or fails with a {@link SchemaError} for schema
@@ -1194,7 +1194,7 @@ export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
1194
1194
  * @category encoding
1195
1195
  * @since 3.10.0
1196
1196
  */
1197
- export const encodeOption = encodeUnknownOption;
1197
+ export const encodeOption = SchemaParser.encodeOption;
1198
1198
  /**
1199
1199
  * Encodes an `unknown` input against a schema, returning a `Result` that
1200
1200
  * succeeds with the encoded value or fails with a {@link SchemaError} for schema
@@ -1600,14 +1600,20 @@ function templateLiteralFromParts(parts) {
1600
1600
  return new SchemaAST.TemplateLiteral(parts.map(part => isSchema(part) ? part.ast : new SchemaAST.Literal(part)));
1601
1601
  }
1602
1602
  /**
1603
- * Creates a schema that validates strings matching a template literal pattern. Each part can be
1604
- * a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
1603
+ * Creates a schema that validates strings by matching ordered template literal
1604
+ * parts.
1605
1605
  *
1606
1606
  * **When to use**
1607
1607
  *
1608
1608
  * Use when the decoded value should remain the matched string and you do not
1609
1609
  * need the individual template parts parsed into a tuple.
1610
1610
  *
1611
+ * **Details**
1612
+ *
1613
+ * Each part can be a literal `string`, `number`, or `bigint`, or a schema whose
1614
+ * encoded type is `string`, `number`, or `bigint`. Checks on string, number,
1615
+ * and bigint schema parts are applied while matching each segment.
1616
+ *
1611
1617
  * **Example** (Defining a URL path pattern)
1612
1618
  *
1613
1619
  * ```ts
@@ -1627,7 +1633,7 @@ export function TemplateLiteral(parts) {
1627
1633
  });
1628
1634
  }
1629
1635
  /**
1630
- * Schema for parsing template literal matches into typed tuple parts.
1636
+ * Schema for parsing matched template literal strings into typed tuple parts.
1631
1637
  *
1632
1638
  * **When to use**
1633
1639
  *
@@ -1637,7 +1643,8 @@ export function TemplateLiteral(parts) {
1637
1643
  * **Details**
1638
1644
  *
1639
1645
  * Unlike {@link TemplateLiteral}, this schema decodes the matched string into a
1640
- * readonly tuple with one element per schema part.
1646
+ * readonly tuple with one element per schema part. Checks on string, number,
1647
+ * and bigint schema parts are applied while matching each segment.
1641
1648
  *
1642
1649
  * **Example** (Parsing path parameters)
1643
1650
  *
@@ -2015,7 +2022,18 @@ derive) {
2015
2022
  };
2016
2023
  }
2017
2024
  /**
2018
- * Defines a record (dictionary) schema with typed keys and values.
2025
+ * Defines a record schema whose dynamic properties are selected by a key schema
2026
+ * and decoded with a value schema.
2027
+ *
2028
+ * **Details**
2029
+ *
2030
+ * For dynamic keys, the key schema selects matching own properties and the
2031
+ * value schema decodes or encodes only those selected properties. Checks on
2032
+ * string, number, symbol, and template literal key schemas narrow which
2033
+ * properties are selected.
2034
+ *
2035
+ * For transformed key schemas, property selection is based on encoded property
2036
+ * names before the selected key is decoded.
2019
2037
  *
2020
2038
  * **Example** (Defining a string-keyed record of numbers)
2021
2039
  *
@@ -2046,6 +2064,13 @@ export function Record(key, value, options) {
2046
2064
  * Extends a struct schema with one or more record (index-signature) schemas,
2047
2065
  * producing a schema whose decoded type intersects the struct and all records.
2048
2066
  *
2067
+ * **Gotchas**
2068
+ *
2069
+ * TypeScript index signatures also apply to fixed keys. `StructWithRest` does
2070
+ * not reject incompatible fixed fields at the call site; use
2071
+ * `StructWithRest.ValidateRecords` when you want an explicit type-level
2072
+ * compatibility check.
2073
+ *
2049
2074
  * **Example** (Defining structs with string-indexed extra keys)
2050
2075
  *
2051
2076
  * ```ts
@@ -2550,7 +2575,7 @@ export function catchDecoding(f) {
2550
2575
  * @since 4.0.0
2551
2576
  */
2552
2577
  export function catchDecodingWithContext(f) {
2553
- return self => self.pipe(middlewareDecoding(Effect.catchEager(f)));
2578
+ return self => middlewareDecoding(Effect.catchEager(f))(self);
2554
2579
  }
2555
2580
  /**
2556
2581
  * Recovers from an encoding error by providing a fallback value.
@@ -2588,7 +2613,7 @@ export function catchEncoding(f) {
2588
2613
  * @since 4.0.0
2589
2614
  */
2590
2615
  export function catchEncodingWithContext(f) {
2591
- return self => self.pipe(middlewareEncoding(Effect.catchEager(f)));
2616
+ return self => middlewareEncoding(Effect.catchEager(f))(self);
2592
2617
  }
2593
2618
  export function decodeTo(to, transformation) {
2594
2619
  return from => {
@@ -2643,12 +2668,12 @@ export function decodeTo(to, transformation) {
2643
2668
  */
2644
2669
  export function decode(transformation) {
2645
2670
  return self => {
2646
- return self.pipe(decodeTo(toType(self), transformation));
2671
+ return decodeTo(toType(self), transformation)(self);
2647
2672
  };
2648
2673
  }
2649
2674
  export function encodeTo(to, transformation) {
2650
2675
  return from => {
2651
- return transformation ? to.pipe(decodeTo(from, transformation)) : to.pipe(decodeTo(from));
2676
+ return transformation ? decodeTo(from, transformation)(to) : decodeTo(from)(to);
2652
2677
  };
2653
2678
  }
2654
2679
  /**
@@ -2678,7 +2703,7 @@ export function encodeTo(to, transformation) {
2678
2703
  */
2679
2704
  export function encode(transformation) {
2680
2705
  return self => {
2681
- return toEncoded(self).pipe(decodeTo(self, transformation));
2706
+ return decodeTo(self, transformation)(toEncoded(self));
2682
2707
  };
2683
2708
  }
2684
2709
  /**
@@ -5210,6 +5235,7 @@ export function Result(success, failure) {
5210
5235
  * into JSON, it will fail with an error. This is useful when the wrapped schema is
5211
5236
  * sensitive and should not be exposed in JSON.
5212
5237
  *
5238
+ * @see {@link RedactedFromValue} for decoding raw values and wrapping them in `Redacted`.
5213
5239
  * @category Redacted
5214
5240
  * @since 3.10.0
5215
5241
  */
@@ -5268,13 +5294,14 @@ export function Redacted(value, options) {
5268
5294
  * @since 4.0.0
5269
5295
  */
5270
5296
  export function redact(schema) {
5271
- return schema.pipe(middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact)));
5297
+ return middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact))(schema);
5272
5298
  }
5273
5299
  /**
5274
5300
  * Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
5275
5301
  * expects the input to already be a `Redacted` instance, this schema decodes
5276
5302
  * the raw value and wraps it.
5277
5303
  *
5304
+ * @see {@link Redacted} for schemas whose input is already a `Redacted` value.
5278
5305
  * @category Redacted
5279
5306
  * @since 4.0.0
5280
5307
  */
@@ -6636,10 +6663,8 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
6636
6663
  *
6637
6664
  * You can express nested values using bracket notation.
6638
6665
  *
6639
- * If you want to decode values that are not strings, use
6640
- * `Schema.toCodecStringTree` with the `keepDeclarations: true` option.
6641
- * This serializer preserves values such as numbers and `Blob` objects when
6642
- * compatible with the schema.
6666
+ * If you want to decode string fields into non-string primitive values, use
6667
+ * `Schema.toCodecStringTree`.
6643
6668
  *
6644
6669
  * **Example** (Decoding a flat structure)
6645
6670
  *
@@ -6693,8 +6718,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
6693
6718
  * Schema.toCodecStringTree(
6694
6719
  * Schema.Struct({
6695
6720
  * a: Schema.Int
6696
- * }),
6697
- * { keepDeclarations: true }
6721
+ * })
6698
6722
  * )
6699
6723
  * )
6700
6724
  *
@@ -7482,14 +7506,16 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
7482
7506
  return this.rebuild(SchemaAST.appendChecks(this.ast, checks));
7483
7507
  }
7484
7508
  static extend(identifier) {
7485
- return (newFields, annotations) => {
7509
+ return (schema, annotations) => {
7510
+ const extension = isStruct(schema) ? schema : Struct(schema);
7486
7511
  const fields = {
7487
7512
  ...struct.fields,
7488
- ...newFields
7513
+ ...extension.fields
7489
7514
  };
7490
- return makeClass(this, identifier, makeStruct(SchemaAST.struct(fields, struct.ast.checks, {
7515
+ const ast = SchemaAST.struct(fields, struct.ast.checks, {
7491
7516
  identifier
7492
- }), fields), annotations, proto);
7517
+ });
7518
+ return makeClass(this, identifier, makeStruct(SchemaAST.appendChecks(ast, extension.ast.checks), fields), annotations, proto);
7493
7519
  };
7494
7520
  }
7495
7521
  static mapFields(f, options) {
@@ -7510,25 +7536,25 @@ function getClassTypeId(identifier) {
7510
7536
  function getClassSchemaFactory(from, identifier, annotations) {
7511
7537
  let memo;
7512
7538
  return self => {
7513
- if (memo === undefined) {
7514
- const transformation = getClassTransformation(self);
7515
- const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
7516
- return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
7517
- }, {
7518
- identifier,
7519
- [SchemaAST.ClassTypeId]: ([from]) => new SchemaAST.Link(from, transformation),
7520
- toCodec: ([from]) => new SchemaAST.Link(from.ast, transformation),
7521
- toArbitrary: ([from]) => () => ({
7522
- arbitrary: from.arbitrary.map(args => new self(args)),
7523
- terminal: from.terminal?.map(args => new self(args))
7524
- }),
7525
- toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
7526
- "~sentinels": SchemaAST.collectSentinels(from.ast),
7527
- ...annotations
7528
- }));
7529
- memo = from.pipe(decodeTo(to, transformation));
7539
+ if (memo !== undefined) {
7540
+ return memo;
7530
7541
  }
7531
- return memo;
7542
+ const transformation = getClassTransformation(self);
7543
+ const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
7544
+ return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
7545
+ }, {
7546
+ identifier,
7547
+ [SchemaAST.ClassTypeId]: ([from]) => new SchemaAST.Link(from, transformation),
7548
+ toCodec: ([from]) => new SchemaAST.Link(from.ast, transformation),
7549
+ toArbitrary: ([from]) => () => ({
7550
+ arbitrary: from.arbitrary.map(args => new self(args)),
7551
+ terminal: from.terminal?.map(args => new self(args))
7552
+ }),
7553
+ toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
7554
+ "~sentinels": SchemaAST.collectSentinels(from.ast),
7555
+ ...annotations
7556
+ }));
7557
+ return memo = decodeTo(to, transformation)(from);
7532
7558
  };
7533
7559
  }
7534
7560
  function isStruct(schema) {
@@ -7991,9 +8017,6 @@ export function toJsonSchemaDocument(schema, options) {
7991
8017
  definitions: jd.definitions
7992
8018
  };
7993
8019
  }
7994
- // -----------------------------------------------------------------------------
7995
- // Canonical Codecs
7996
- // -----------------------------------------------------------------------------
7997
8020
  /**
7998
8021
  * Derives a canonical JSON codec from a schema. The encoded form is `Json`, and
7999
8022
  * decoding produces the schema's `Type`.
@@ -8004,7 +8027,7 @@ export function toJsonSchemaDocument(schema, options) {
8004
8027
  export function toCodecJson(schema) {
8005
8028
  return make(toCodecJsonTop(schema.ast));
8006
8029
  }
8007
- const toCodecJsonTop = /*#__PURE__*/SchemaAST.toCodec(ast => {
8030
+ const toCodecJsonTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
8008
8031
  const out = toCodecJsonBase(ast, toCodecJsonTop);
8009
8032
  return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out;
8010
8033
  });
@@ -8040,7 +8063,7 @@ function toCodecJsonBase(ast, recur) {
8040
8063
  cause: ast
8041
8064
  });
8042
8065
  }
8043
- return ast.recur(recur);
8066
+ return ast.recur(recur, SchemaAST.parameterFromString);
8044
8067
  }
8045
8068
  case "Union":
8046
8069
  {
@@ -8091,8 +8114,41 @@ function toCodecIsoBase(ast, recur) {
8091
8114
  }
8092
8115
  return ast;
8093
8116
  }
8094
- export function toCodecStringTree(schema, options) {
8095
- return make(toCodecEnsureArray(options?.keepDeclarations === true ? serializerStringTreeKeepDeclarations(schema.ast) : serializerStringTree(schema.ast)));
8117
+ /**
8118
+ * Converts a schema to the StringTree canonical codec, where every leaf value
8119
+ * becomes a string while preserving the original structure.
8120
+ *
8121
+ * **Details**
8122
+ *
8123
+ * Declarations are converted to `undefined` (unless they have a
8124
+ * `toCodecJson` or `toCodec` annotation).
8125
+ *
8126
+ * @category Canonical Codecs
8127
+ * @since 4.0.0
8128
+ */
8129
+ export function toCodecStringTree(schema) {
8130
+ return make(serializerStringTree(schema.ast));
8131
+ }
8132
+ /**
8133
+ * Allows array schemas to decode from either an array input or a single value
8134
+ * input.
8135
+ *
8136
+ * **When to use**
8137
+ *
8138
+ * Use when you need to accept transport formats that may represent a
8139
+ * single-item array as a bare value, such as query-string or form-data adapters.
8140
+ *
8141
+ * **Gotchas**
8142
+ *
8143
+ * This combinator is intentionally not part of `toCodecStringTree`; it adds a
8144
+ * decoding convenience rather than a canonical StringTree representation. It
8145
+ * does not parse comma-separated strings.
8146
+ *
8147
+ * @category Canonical Codecs
8148
+ * @since 4.0.0
8149
+ */
8150
+ export function toCodecArrayFromSingle(schema) {
8151
+ return make(toCodecArrayFromSingleTop(schema.ast));
8096
8152
  }
8097
8153
  /**
8098
8154
  * Derives an XML encoder from a codec.
@@ -8251,7 +8307,7 @@ function serializerTree(ast, recur, onMissingAnnotation) {
8251
8307
  cause: ast
8252
8308
  });
8253
8309
  }
8254
- return ast.recur(recur);
8310
+ return ast.recur(recur, SchemaAST.parameterFromString);
8255
8311
  }
8256
8312
  case "Union":
8257
8313
  {
@@ -8270,7 +8326,12 @@ function serializerTree(ast, recur, onMissingAnnotation) {
8270
8326
  }
8271
8327
  const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
8272
8328
  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()));
8273
- const serializerStringTree = /*#__PURE__*/SchemaAST.toCodec(ast => {
8329
+ const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
8330
+ const isSerializerArrayFromSingle = ast => SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true;
8331
+ const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
8332
+ if (isSerializerArrayFromSingle(ast)) {
8333
+ return ast;
8334
+ }
8274
8335
  const out = serializerTree(ast, serializerStringTree, ast => SchemaAST.replaceEncoding(ast, [unknownToUndefined]));
8275
8336
  if (out !== ast && SchemaAST.isOptional(ast)) {
8276
8337
  return SchemaAST.optionalKeyLastLink(out);
@@ -8278,38 +8339,23 @@ const serializerStringTree = /*#__PURE__*/SchemaAST.toCodec(ast => {
8278
8339
  return out;
8279
8340
  });
8280
8341
  const unknownToUndefined = /*#__PURE__*/new SchemaAST.Link(SchemaAST.undefined, /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.passthrough(), /*#__PURE__*/SchemaGetter.transform(() => undefined)));
8281
- const serializerStringTreeKeepDeclarations = /*#__PURE__*/SchemaAST.toCodec(ast => {
8282
- const out = serializerTree(ast, serializerStringTreeKeepDeclarations, identity);
8283
- if (out !== ast && SchemaAST.isOptional(ast)) {
8284
- return SchemaAST.optionalKeyLastLink(out);
8285
- }
8286
- return out;
8287
- });
8288
- const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
8289
- const toCodecEnsureArray = /*#__PURE__*/SchemaAST.toCodec(ast => {
8290
- if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
8342
+ const toArrayFromSingleInputElement = ast => SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown;
8343
+ const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
8344
+ const toCodecArrayFromSingleTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
8345
+ if (isSerializerArrayFromSingle(ast)) {
8291
8346
  return ast;
8292
8347
  }
8293
- const out = onSerializerEnsureArray(ast);
8348
+ const out = onSerializerArrayFromSingle(ast);
8294
8349
  if (SchemaAST.isArrays(out)) {
8295
- const ensure = new SchemaAST.Union([out, SchemaAST.decodeTo(SchemaAST.string, out, new SchemaTransformation.Transformation(SchemaGetter.split(), SchemaGetter.passthrough()))], "anyOf", {
8350
+ const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf", {
8296
8351
  [SERIALIZER_ENSURE_ARRAY]: true
8297
- });
8352
+ }), out, arrayFromSingleTransformation);
8298
8353
  return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
8299
8354
  }
8300
8355
  return out;
8301
8356
  });
8302
- function onSerializerEnsureArray(ast) {
8303
- switch (ast._tag) {
8304
- default:
8305
- return ast;
8306
- case "Declaration":
8307
- case "Arrays":
8308
- case "Objects":
8309
- case "Union":
8310
- case "Suspend":
8311
- return ast.recur(toCodecEnsureArray);
8312
- }
8357
+ function onSerializerArrayFromSingle(ast) {
8358
+ return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleTop) : ast;
8313
8359
  }
8314
8360
  // -----------------------------------------------------------------------------
8315
8361
  // Optic APIs