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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/dist/ChannelSchema.d.ts +8 -8
  2. package/dist/ChannelSchema.d.ts.map +1 -1
  3. package/dist/Config.d.ts +2 -2
  4. package/dist/Config.d.ts.map +1 -1
  5. package/dist/Config.js +10 -3
  6. package/dist/Config.js.map +1 -1
  7. package/dist/Cron.d.ts.map +1 -1
  8. package/dist/Cron.js +4 -0
  9. package/dist/Cron.js.map +1 -1
  10. package/dist/Schema.d.ts +749 -393
  11. package/dist/Schema.d.ts.map +1 -1
  12. package/dist/Schema.js +95 -65
  13. package/dist/Schema.js.map +1 -1
  14. package/dist/SchemaAST.d.ts.map +1 -1
  15. package/dist/SchemaAST.js +20 -29
  16. package/dist/SchemaAST.js.map +1 -1
  17. package/dist/SchemaParser.d.ts +24 -24
  18. package/dist/SchemaParser.d.ts.map +1 -1
  19. package/dist/SchemaParser.js +43 -39
  20. package/dist/SchemaParser.js.map +1 -1
  21. package/dist/SchemaRepresentation.d.ts +300 -300
  22. package/dist/SchemaTransformation.d.ts +2 -2
  23. package/dist/SchemaTransformation.d.ts.map +1 -1
  24. package/dist/SchemaTransformation.js +5 -8
  25. package/dist/SchemaTransformation.js.map +1 -1
  26. package/dist/internal/effect.js +6 -7
  27. package/dist/internal/effect.js.map +1 -1
  28. package/dist/internal/matcher.js +0 -2
  29. package/dist/internal/matcher.js.map +1 -1
  30. package/dist/internal/schema/representation.js +1 -5
  31. package/dist/internal/schema/representation.js.map +1 -1
  32. package/dist/internal/schema/schema.js.map +1 -1
  33. package/dist/testing/TestSchema.d.ts +9 -9
  34. package/dist/testing/TestSchema.d.ts.map +1 -1
  35. package/dist/testing/TestSchema.js +3 -2
  36. package/dist/testing/TestSchema.js.map +1 -1
  37. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts +2 -2
  38. package/dist/unstable/ai/AnthropicStructuredOutput.d.ts.map +1 -1
  39. package/dist/unstable/ai/AnthropicStructuredOutput.js.map +1 -1
  40. package/dist/unstable/ai/Chat.d.ts +1 -1
  41. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  42. package/dist/unstable/ai/LanguageModel.d.ts +4 -4
  43. package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
  44. package/dist/unstable/ai/McpSchema.d.ts +13 -6
  45. package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
  46. package/dist/unstable/ai/McpSchema.js.map +1 -1
  47. package/dist/unstable/ai/McpServer.d.ts +4 -4
  48. package/dist/unstable/ai/McpServer.d.ts.map +1 -1
  49. package/dist/unstable/ai/McpServer.js.map +1 -1
  50. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts +2 -2
  51. package/dist/unstable/ai/OpenAiStructuredOutput.d.ts.map +1 -1
  52. package/dist/unstable/ai/OpenAiStructuredOutput.js.map +1 -1
  53. package/dist/unstable/ai/Response.d.ts +2 -2
  54. package/dist/unstable/ai/Response.d.ts.map +1 -1
  55. package/dist/unstable/ai/Response.js.map +1 -1
  56. package/dist/unstable/ai/Tool.d.ts +26 -26
  57. package/dist/unstable/ai/Tool.d.ts.map +1 -1
  58. package/dist/unstable/ai/Tool.js.map +1 -1
  59. package/dist/unstable/cli/Argument.d.ts +8 -7
  60. package/dist/unstable/cli/Argument.d.ts.map +1 -1
  61. package/dist/unstable/cli/Argument.js.map +1 -1
  62. package/dist/unstable/cli/Flag.d.ts +8 -7
  63. package/dist/unstable/cli/Flag.d.ts.map +1 -1
  64. package/dist/unstable/cli/Flag.js.map +1 -1
  65. package/dist/unstable/cli/Param.d.ts +1806 -168
  66. package/dist/unstable/cli/Param.d.ts.map +1 -1
  67. package/dist/unstable/cli/Param.js +0 -70
  68. package/dist/unstable/cli/Param.js.map +1 -1
  69. package/dist/unstable/cli/Primitive.d.ts +3 -4
  70. package/dist/unstable/cli/Primitive.d.ts.map +1 -1
  71. package/dist/unstable/cli/Primitive.js.map +1 -1
  72. package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
  73. package/dist/unstable/cli/internal/ansi.js +0 -22
  74. package/dist/unstable/cli/internal/ansi.js.map +1 -1
  75. package/dist/unstable/cli/internal/config.d.ts +48 -0
  76. package/dist/unstable/cli/internal/config.d.ts.map +1 -1
  77. package/dist/unstable/cli/internal/config.js +0 -6
  78. package/dist/unstable/cli/internal/config.js.map +1 -1
  79. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts +3 -3
  80. package/dist/unstable/cluster/Reply.d.ts +2 -2
  81. package/dist/unstable/cluster/Reply.d.ts.map +1 -1
  82. package/dist/unstable/cluster/Reply.js.map +1 -1
  83. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  84. package/dist/unstable/encoding/Msgpack.d.ts +6 -6
  85. package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
  86. package/dist/unstable/encoding/Msgpack.js.map +1 -1
  87. package/dist/unstable/encoding/Ndjson.d.ts +8 -8
  88. package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
  89. package/dist/unstable/encoding/Sse.d.ts +1 -1
  90. package/dist/unstable/encoding/Sse.d.ts.map +1 -1
  91. package/dist/unstable/encoding/Sse.js.map +1 -1
  92. package/dist/unstable/eventlog/EventLogMessage.d.ts +22 -22
  93. package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
  94. package/dist/unstable/eventlog/EventLogRemote.d.ts +15 -15
  95. package/dist/unstable/http/HttpBody.d.ts +1 -1
  96. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  97. package/dist/unstable/http/HttpClientRequest.d.ts +1 -1
  98. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  99. package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
  100. package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
  101. package/dist/unstable/http/HttpIncomingMessage.js.map +1 -1
  102. package/dist/unstable/http/HttpMiddleware.d.ts.map +1 -1
  103. package/dist/unstable/http/HttpMiddleware.js +12 -3
  104. package/dist/unstable/http/HttpMiddleware.js.map +1 -1
  105. package/dist/unstable/httpapi/HttpApi.d.ts +1 -1
  106. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  107. package/dist/unstable/httpapi/HttpApiClient.d.ts +2 -2
  108. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  109. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  110. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +32 -32
  111. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  112. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  113. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +1 -1
  114. package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
  115. package/dist/unstable/httpapi/HttpApiSchema.d.ts +13 -6
  116. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  117. package/dist/unstable/httpapi/HttpApiSchema.js +0 -13
  118. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  119. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  120. package/dist/unstable/observability/internal/otlpProtobuf.js +0 -68
  121. package/dist/unstable/observability/internal/otlpProtobuf.js.map +1 -1
  122. package/dist/unstable/observability/internal/protobuf.js +0 -28
  123. package/dist/unstable/observability/internal/protobuf.js.map +1 -1
  124. package/dist/unstable/persistence/KeyValueStore.d.ts +2 -2
  125. package/dist/unstable/persistence/KeyValueStore.d.ts.map +1 -1
  126. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  127. package/dist/unstable/persistence/Persistable.d.ts +6 -6
  128. package/dist/unstable/persistence/Persistable.d.ts.map +1 -1
  129. package/dist/unstable/persistence/PersistedQueue.d.ts +3 -3
  130. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  131. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  132. package/dist/unstable/persistence/Persistence.d.ts +5 -5
  133. package/dist/unstable/persistence/Persistence.d.ts.map +1 -1
  134. package/dist/unstable/reactivity/AsyncResult.d.ts +2 -2
  135. package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
  136. package/dist/unstable/reactivity/Atom.d.ts +1 -1
  137. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  138. package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -1
  139. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  140. package/dist/unstable/rpc/Rpc.d.ts +3 -4
  141. package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
  142. package/dist/unstable/rpc/Rpc.js +1 -1
  143. package/dist/unstable/rpc/Rpc.js.map +1 -1
  144. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  145. package/dist/unstable/rpc/RpcClient.js +25 -4
  146. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  147. package/dist/unstable/rpc/RpcMessage.d.ts +7 -0
  148. package/dist/unstable/rpc/RpcMessage.d.ts.map +1 -1
  149. package/dist/unstable/rpc/RpcMessage.js +20 -0
  150. package/dist/unstable/rpc/RpcMessage.js.map +1 -1
  151. package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
  152. package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
  153. package/dist/unstable/rpc/RpcSchema.d.ts +10 -3
  154. package/dist/unstable/rpc/RpcSchema.d.ts.map +1 -1
  155. package/dist/unstable/rpc/RpcSchema.js.map +1 -1
  156. package/dist/unstable/rpc/RpcWorker.d.ts +3 -3
  157. package/dist/unstable/rpc/RpcWorker.d.ts.map +1 -1
  158. package/dist/unstable/schema/Model.d.ts +2 -2
  159. package/dist/unstable/schema/Model.d.ts.map +1 -1
  160. package/dist/unstable/schema/Model.js.map +1 -1
  161. package/dist/unstable/schema/VariantSchema.d.ts +16 -2
  162. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  163. package/dist/unstable/schema/VariantSchema.js.map +1 -1
  164. package/dist/unstable/sql/SqlConnection.d.ts +1 -0
  165. package/dist/unstable/sql/SqlConnection.d.ts.map +1 -1
  166. package/dist/unstable/sql/SqlConnection.js.map +1 -1
  167. package/dist/unstable/sql/SqlModel.js.map +1 -1
  168. package/dist/unstable/sql/SqlResolver.d.ts +4 -4
  169. package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
  170. package/dist/unstable/sql/SqlResolver.js.map +1 -1
  171. package/dist/unstable/sql/SqlSchema.d.ts +5 -5
  172. package/dist/unstable/sql/SqlSchema.d.ts.map +1 -1
  173. package/dist/unstable/sql/Statement.d.ts +1 -0
  174. package/dist/unstable/sql/Statement.d.ts.map +1 -1
  175. package/dist/unstable/sql/Statement.js +3 -0
  176. package/dist/unstable/sql/Statement.js.map +1 -1
  177. package/dist/unstable/workflow/Activity.d.ts +2 -2
  178. package/dist/unstable/workflow/Activity.d.ts.map +1 -1
  179. package/dist/unstable/workflow/DurableDeferred.d.ts +18 -18
  180. package/dist/unstable/workflow/DurableDeferred.d.ts.map +1 -1
  181. package/dist/unstable/workflow/Workflow.d.ts +3 -3
  182. package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
  183. package/dist/unstable/workflow/Workflow.js.map +1 -1
  184. package/dist/unstable/workflow/WorkflowEngine.d.ts +3 -3
  185. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  186. package/package.json +1 -1
  187. package/src/ChannelSchema.ts +9 -9
  188. package/src/Config.ts +12 -5
  189. package/src/Cron.ts +4 -0
  190. package/src/Schema.ts +968 -689
  191. package/src/SchemaAST.ts +25 -35
  192. package/src/SchemaParser.ts +85 -77
  193. package/src/SchemaTransformation.ts +5 -6
  194. package/src/internal/effect.ts +6 -22
  195. package/src/internal/matcher.ts +0 -5
  196. package/src/internal/schema/arbitrary.ts +1 -1
  197. package/src/internal/schema/representation.ts +1 -5
  198. package/src/internal/schema/schema.ts +1 -1
  199. package/src/testing/TestSchema.ts +14 -13
  200. package/src/unstable/ai/AnthropicStructuredOutput.ts +2 -2
  201. package/src/unstable/ai/Chat.ts +1 -1
  202. package/src/unstable/ai/LanguageModel.ts +7 -7
  203. package/src/unstable/ai/McpSchema.ts +16 -14
  204. package/src/unstable/ai/McpServer.ts +7 -7
  205. package/src/unstable/ai/OpenAiStructuredOutput.ts +2 -2
  206. package/src/unstable/ai/Response.ts +9 -5
  207. package/src/unstable/ai/Tool.ts +49 -47
  208. package/src/unstable/cli/Argument.ts +9 -8
  209. package/src/unstable/cli/Flag.ts +9 -8
  210. package/src/unstable/cli/Param.ts +6 -146
  211. package/src/unstable/cli/Primitive.ts +5 -6
  212. package/src/unstable/cli/internal/ansi.ts +0 -33
  213. package/src/unstable/cli/internal/config.ts +0 -8
  214. package/src/unstable/cli/internal/parser.ts +2 -2
  215. package/src/unstable/cluster/MessageStorage.ts +1 -1
  216. package/src/unstable/cluster/Reply.ts +6 -2
  217. package/src/unstable/devtools/DevToolsSchema.ts +1 -1
  218. package/src/unstable/encoding/Msgpack.ts +9 -7
  219. package/src/unstable/encoding/Ndjson.ts +10 -10
  220. package/src/unstable/encoding/Sse.ts +1 -1
  221. package/src/unstable/eventlog/Event.ts +3 -3
  222. package/src/unstable/http/HttpBody.ts +1 -1
  223. package/src/unstable/http/HttpClientRequest.ts +1 -1
  224. package/src/unstable/http/HttpIncomingMessage.ts +1 -1
  225. package/src/unstable/http/HttpMiddleware.ts +12 -3
  226. package/src/unstable/httpapi/HttpApi.ts +1 -1
  227. package/src/unstable/httpapi/HttpApiBuilder.ts +9 -5
  228. package/src/unstable/httpapi/HttpApiClient.ts +10 -10
  229. package/src/unstable/httpapi/HttpApiEndpoint.ts +45 -33
  230. package/src/unstable/httpapi/HttpApiMiddleware.ts +2 -2
  231. package/src/unstable/httpapi/HttpApiSchema.ts +16 -43
  232. package/src/unstable/httpapi/OpenApi.ts +5 -5
  233. package/src/unstable/observability/internal/otlpProtobuf.ts +0 -75
  234. package/src/unstable/observability/internal/protobuf.ts +0 -42
  235. package/src/unstable/persistence/KeyValueStore.ts +2 -2
  236. package/src/unstable/persistence/Persistable.ts +7 -7
  237. package/src/unstable/persistence/PersistedQueue.ts +3 -3
  238. package/src/unstable/persistence/Persistence.ts +5 -5
  239. package/src/unstable/reactivity/AsyncResult.ts +4 -4
  240. package/src/unstable/reactivity/Atom.ts +1 -1
  241. package/src/unstable/reactivity/AtomHttpApi.ts +1 -1
  242. package/src/unstable/rpc/Rpc.ts +7 -8
  243. package/src/unstable/rpc/RpcClient.ts +26 -4
  244. package/src/unstable/rpc/RpcMessage.ts +19 -0
  245. package/src/unstable/rpc/RpcMiddleware.ts +2 -2
  246. package/src/unstable/rpc/RpcSchema.ts +12 -9
  247. package/src/unstable/rpc/RpcWorker.ts +3 -3
  248. package/src/unstable/schema/Model.ts +2 -2
  249. package/src/unstable/schema/VariantSchema.ts +19 -17
  250. package/src/unstable/sql/SqlConnection.ts +5 -0
  251. package/src/unstable/sql/SqlModel.ts +2 -2
  252. package/src/unstable/sql/SqlResolver.ts +6 -6
  253. package/src/unstable/sql/SqlSchema.ts +5 -5
  254. package/src/unstable/sql/Statement.ts +11 -0
  255. package/src/unstable/workflow/Activity.ts +6 -6
  256. package/src/unstable/workflow/DurableDeferred.ts +33 -33
  257. package/src/unstable/workflow/Workflow.ts +5 -5
  258. package/src/unstable/workflow/WorkflowEngine.ts +10 -10
  259. package/dist/internal/concurrency.d.ts +0 -2
  260. package/dist/internal/concurrency.d.ts.map +0 -1
  261. package/dist/internal/concurrency.js +0 -29
  262. package/dist/internal/concurrency.js.map +0 -1
  263. package/src/internal/concurrency.ts +0 -52
package/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
@@ -2064,6 +2064,13 @@ export function Record(key, value, options) {
2064
2064
  * Extends a struct schema with one or more record (index-signature) schemas,
2065
2065
  * producing a schema whose decoded type intersects the struct and all records.
2066
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
+ *
2067
2074
  * **Example** (Defining structs with string-indexed extra keys)
2068
2075
  *
2069
2076
  * ```ts
@@ -2568,7 +2575,7 @@ export function catchDecoding(f) {
2568
2575
  * @since 4.0.0
2569
2576
  */
2570
2577
  export function catchDecodingWithContext(f) {
2571
- return self => self.pipe(middlewareDecoding(Effect.catchEager(f)));
2578
+ return self => middlewareDecoding(Effect.catchEager(f))(self);
2572
2579
  }
2573
2580
  /**
2574
2581
  * Recovers from an encoding error by providing a fallback value.
@@ -2606,7 +2613,7 @@ export function catchEncoding(f) {
2606
2613
  * @since 4.0.0
2607
2614
  */
2608
2615
  export function catchEncodingWithContext(f) {
2609
- return self => self.pipe(middlewareEncoding(Effect.catchEager(f)));
2616
+ return self => middlewareEncoding(Effect.catchEager(f))(self);
2610
2617
  }
2611
2618
  export function decodeTo(to, transformation) {
2612
2619
  return from => {
@@ -2661,12 +2668,12 @@ export function decodeTo(to, transformation) {
2661
2668
  */
2662
2669
  export function decode(transformation) {
2663
2670
  return self => {
2664
- return self.pipe(decodeTo(toType(self), transformation));
2671
+ return decodeTo(toType(self), transformation)(self);
2665
2672
  };
2666
2673
  }
2667
2674
  export function encodeTo(to, transformation) {
2668
2675
  return from => {
2669
- return transformation ? to.pipe(decodeTo(from, transformation)) : to.pipe(decodeTo(from));
2676
+ return transformation ? decodeTo(from, transformation)(to) : decodeTo(from)(to);
2670
2677
  };
2671
2678
  }
2672
2679
  /**
@@ -2696,7 +2703,7 @@ export function encodeTo(to, transformation) {
2696
2703
  */
2697
2704
  export function encode(transformation) {
2698
2705
  return self => {
2699
- return toEncoded(self).pipe(decodeTo(self, transformation));
2706
+ return decodeTo(self, transformation)(toEncoded(self));
2700
2707
  };
2701
2708
  }
2702
2709
  /**
@@ -5228,6 +5235,7 @@ export function Result(success, failure) {
5228
5235
  * into JSON, it will fail with an error. This is useful when the wrapped schema is
5229
5236
  * sensitive and should not be exposed in JSON.
5230
5237
  *
5238
+ * @see {@link RedactedFromValue} for decoding raw values and wrapping them in `Redacted`.
5231
5239
  * @category Redacted
5232
5240
  * @since 3.10.0
5233
5241
  */
@@ -5286,13 +5294,14 @@ export function Redacted(value, options) {
5286
5294
  * @since 4.0.0
5287
5295
  */
5288
5296
  export function redact(schema) {
5289
- return schema.pipe(middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact)));
5297
+ return middlewareDecoding(Effect.mapErrorEager(SchemaIssue.redact))(schema);
5290
5298
  }
5291
5299
  /**
5292
5300
  * Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
5293
5301
  * expects the input to already be a `Redacted` instance, this schema decodes
5294
5302
  * the raw value and wraps it.
5295
5303
  *
5304
+ * @see {@link Redacted} for schemas whose input is already a `Redacted` value.
5296
5305
  * @category Redacted
5297
5306
  * @since 4.0.0
5298
5307
  */
@@ -6654,10 +6663,8 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
6654
6663
  *
6655
6664
  * You can express nested values using bracket notation.
6656
6665
  *
6657
- * If you want to decode values that are not strings, use
6658
- * `Schema.toCodecStringTree` with the `keepDeclarations: true` option.
6659
- * This serializer preserves values such as numbers and `Blob` objects when
6660
- * compatible with the schema.
6666
+ * If you want to decode string fields into non-string primitive values, use
6667
+ * `Schema.toCodecStringTree`.
6661
6668
  *
6662
6669
  * **Example** (Decoding a flat structure)
6663
6670
  *
@@ -6711,8 +6718,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
6711
6718
  * Schema.toCodecStringTree(
6712
6719
  * Schema.Struct({
6713
6720
  * a: Schema.Int
6714
- * }),
6715
- * { keepDeclarations: true }
6721
+ * })
6716
6722
  * )
6717
6723
  * )
6718
6724
  *
@@ -7530,25 +7536,25 @@ function getClassTypeId(identifier) {
7530
7536
  function getClassSchemaFactory(from, identifier, annotations) {
7531
7537
  let memo;
7532
7538
  return self => {
7533
- if (memo === undefined) {
7534
- const transformation = getClassTransformation(self);
7535
- const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
7536
- return input instanceof self || Predicate.hasProperty(input, getClassTypeId(identifier)) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, Option_.some(input)));
7537
- }, {
7538
- identifier,
7539
- [SchemaAST.ClassTypeId]: ([from]) => new SchemaAST.Link(from, transformation),
7540
- toCodec: ([from]) => new SchemaAST.Link(from.ast, transformation),
7541
- toArbitrary: ([from]) => () => ({
7542
- arbitrary: from.arbitrary.map(args => new self(args)),
7543
- terminal: from.terminal?.map(args => new self(args))
7544
- }),
7545
- toFormatter: ([from]) => t => `${self.identifier}(${from(t)})`,
7546
- "~sentinels": SchemaAST.collectSentinels(from.ast),
7547
- ...annotations
7548
- }));
7549
- memo = from.pipe(decodeTo(to, transformation));
7539
+ if (memo !== undefined) {
7540
+ return memo;
7550
7541
  }
7551
- 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);
7552
7558
  };
7553
7559
  }
7554
7560
  function isStruct(schema) {
@@ -8011,9 +8017,6 @@ export function toJsonSchemaDocument(schema, options) {
8011
8017
  definitions: jd.definitions
8012
8018
  };
8013
8019
  }
8014
- // -----------------------------------------------------------------------------
8015
- // Canonical Codecs
8016
- // -----------------------------------------------------------------------------
8017
8020
  /**
8018
8021
  * Derives a canonical JSON codec from a schema. The encoded form is `Json`, and
8019
8022
  * decoding produces the schema's `Type`.
@@ -8022,9 +8025,11 @@ export function toJsonSchemaDocument(schema, options) {
8022
8025
  * @since 4.0.0
8023
8026
  */
8024
8027
  export function toCodecJson(schema) {
8025
- return make(toCodecJsonTop(schema.ast));
8028
+ return make(toCodecJsonTop(schema.ast), {
8029
+ schema
8030
+ });
8026
8031
  }
8027
- const toCodecJsonTop = /*#__PURE__*/SchemaAST.toCodec(ast => {
8032
+ const toCodecJsonTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
8028
8033
  const out = toCodecJsonBase(ast, toCodecJsonTop);
8029
8034
  return out !== ast && SchemaAST.isOptional(ast) ? SchemaAST.optionalKeyLastLink(out) : out;
8030
8035
  });
@@ -8111,8 +8116,43 @@ function toCodecIsoBase(ast, recur) {
8111
8116
  }
8112
8117
  return ast;
8113
8118
  }
8114
- export function toCodecStringTree(schema, options) {
8115
- return make(toCodecEnsureArray(options?.keepDeclarations === true ? serializerStringTreeKeepDeclarations(schema.ast) : serializerStringTree(schema.ast)));
8119
+ /**
8120
+ * Converts a schema to the StringTree canonical codec, where every leaf value
8121
+ * becomes a string while preserving the original structure.
8122
+ *
8123
+ * **Details**
8124
+ *
8125
+ * Declarations are converted to `undefined` (unless they have a
8126
+ * `toCodecJson` or `toCodec` annotation).
8127
+ *
8128
+ * @category Canonical Codecs
8129
+ * @since 4.0.0
8130
+ */
8131
+ export function toCodecStringTree(schema) {
8132
+ return make(serializerStringTree(schema.ast), {
8133
+ schema
8134
+ });
8135
+ }
8136
+ /**
8137
+ * Allows array schemas to decode from either an array input or a single value
8138
+ * input.
8139
+ *
8140
+ * **When to use**
8141
+ *
8142
+ * Use when you need to accept transport formats that may represent a
8143
+ * single-item array as a bare value, such as query-string or form-data adapters.
8144
+ *
8145
+ * **Gotchas**
8146
+ *
8147
+ * This combinator is intentionally not part of `toCodecStringTree`; it adds a
8148
+ * decoding convenience rather than a canonical StringTree representation. It
8149
+ * does not parse comma-separated strings.
8150
+ *
8151
+ * @category Canonical Codecs
8152
+ * @since 4.0.0
8153
+ */
8154
+ export function toCodecArrayFromSingle(schema) {
8155
+ return make(toCodecArrayFromSingleTop(schema.ast));
8116
8156
  }
8117
8157
  /**
8118
8158
  * Derives an XML encoder from a codec.
@@ -8290,7 +8330,12 @@ function serializerTree(ast, recur, onMissingAnnotation) {
8290
8330
  }
8291
8331
  const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
8292
8332
  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()));
8293
- const serializerStringTree = /*#__PURE__*/SchemaAST.toCodec(ast => {
8333
+ const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
8334
+ const isSerializerArrayFromSingle = ast => SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY] === true;
8335
+ const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
8336
+ if (isSerializerArrayFromSingle(ast)) {
8337
+ return ast;
8338
+ }
8294
8339
  const out = serializerTree(ast, serializerStringTree, ast => SchemaAST.replaceEncoding(ast, [unknownToUndefined]));
8295
8340
  if (out !== ast && SchemaAST.isOptional(ast)) {
8296
8341
  return SchemaAST.optionalKeyLastLink(out);
@@ -8298,38 +8343,23 @@ const serializerStringTree = /*#__PURE__*/SchemaAST.toCodec(ast => {
8298
8343
  return out;
8299
8344
  });
8300
8345
  const unknownToUndefined = /*#__PURE__*/new SchemaAST.Link(SchemaAST.undefined, /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.passthrough(), /*#__PURE__*/SchemaGetter.transform(() => undefined)));
8301
- const serializerStringTreeKeepDeclarations = /*#__PURE__*/SchemaAST.toCodec(ast => {
8302
- const out = serializerTree(ast, serializerStringTreeKeepDeclarations, identity);
8303
- if (out !== ast && SchemaAST.isOptional(ast)) {
8304
- return SchemaAST.optionalKeyLastLink(out);
8305
- }
8306
- return out;
8307
- });
8308
- const SERIALIZER_ENSURE_ARRAY = "~effect/Schema/SERIALIZER_ENSURE_ARRAY";
8309
- const toCodecEnsureArray = /*#__PURE__*/SchemaAST.toCodec(ast => {
8310
- if (SchemaAST.isUnion(ast) && ast.annotations?.[SERIALIZER_ENSURE_ARRAY]) {
8346
+ const toArrayFromSingleInputElement = ast => SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown;
8347
+ const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
8348
+ const toCodecArrayFromSingleTop = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncoding(ast => {
8349
+ if (isSerializerArrayFromSingle(ast)) {
8311
8350
  return ast;
8312
8351
  }
8313
- const out = onSerializerEnsureArray(ast);
8352
+ const out = onSerializerArrayFromSingle(ast);
8314
8353
  if (SchemaAST.isArrays(out)) {
8315
- const ensure = new SchemaAST.Union([out, SchemaAST.decodeTo(SchemaAST.string, out, new SchemaTransformation.Transformation(SchemaGetter.split(), SchemaGetter.passthrough()))], "anyOf", {
8354
+ const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf", {
8316
8355
  [SERIALIZER_ENSURE_ARRAY]: true
8317
- });
8356
+ }), out, arrayFromSingleTransformation);
8318
8357
  return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
8319
8358
  }
8320
8359
  return out;
8321
8360
  });
8322
- function onSerializerEnsureArray(ast) {
8323
- switch (ast._tag) {
8324
- default:
8325
- return ast;
8326
- case "Declaration":
8327
- case "Arrays":
8328
- case "Objects":
8329
- case "Union":
8330
- case "Suspend":
8331
- return ast.recur(toCodecEnsureArray);
8332
- }
8361
+ function onSerializerArrayFromSingle(ast) {
8362
+ return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleTop) : ast;
8333
8363
  }
8334
8364
  // -----------------------------------------------------------------------------
8335
8365
  // Optic APIs