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/src/SchemaAST.ts CHANGED
@@ -680,7 +680,7 @@ export class Declaration extends Base {
680
680
  }
681
681
  private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
682
682
  const tps = mapOrSame(this.typeParameters, recur)
683
- return tps === this.typeParameters ?
683
+ return tps === this.typeParameters && checks === this.checks && encodingChecks === this.encodingChecks ?
684
684
  this :
685
685
  new Declaration(tps, this.run, this.annotations, checks, undefined, this.context, encodingChecks)
686
686
  }
@@ -1704,7 +1704,8 @@ export class Arrays extends Base {
1704
1704
  private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
1705
1705
  const elements = mapOrSame(this.elements, recur)
1706
1706
  const rest = mapOrSame(this.rest, recur)
1707
- return elements === this.elements && rest === this.rest ?
1707
+ return elements === this.elements && rest === this.rest && checks === this.checks &&
1708
+ encodingChecks === this.encodingChecks ?
1708
1709
  this :
1709
1710
  new Arrays(
1710
1711
  this.isMutable,
@@ -2245,7 +2246,8 @@ export class Objects extends Base {
2245
2246
  : new IndexSignature(p, t, merge)
2246
2247
  })
2247
2248
 
2248
- return props === this.propertySignatures && indexes === this.indexSignatures
2249
+ return props === this.propertySignatures && indexes === this.indexSignatures && checks === this.checks &&
2250
+ encodingChecks === this.encodingChecks
2249
2251
  ? this
2250
2252
  : new Objects(
2251
2253
  props,
@@ -2345,7 +2347,7 @@ export function struct<Fields extends Schema.Struct.Fields>(
2345
2347
  }
2346
2348
 
2347
2349
  /** @internal */
2348
- export function getAST<S extends Schema.Top>(self: S): S["ast"] {
2350
+ export function getAST<S extends { readonly ast: AST }>(self: S): S["ast"] {
2349
2351
  return self.ast
2350
2352
  }
2351
2353
 
@@ -2358,7 +2360,7 @@ export function tuple<Elements extends Schema.Tuple.Elements>(
2358
2360
  }
2359
2361
 
2360
2362
  /** @internal */
2361
- export function union<Members extends ReadonlyArray<Schema.Top>>(
2363
+ export function union<Members extends ReadonlyArray<{ readonly ast: AST }>>(
2362
2364
  members: Members,
2363
2365
  mode: "anyOf" | "oneOf",
2364
2366
  checks: Checks | undefined
@@ -2661,7 +2663,7 @@ export class Union<A extends AST = AST> extends Base {
2661
2663
  }
2662
2664
  private _rebuild(recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) {
2663
2665
  const types = mapOrSame(this.types, recur)
2664
- return types === this.types ?
2666
+ return types === this.types && checks === this.checks && encodingChecks === this.encodingChecks ?
2665
2667
  this :
2666
2668
  new Union(types, this.mode, this.annotations, checks, undefined, this.context, encodingChecks)
2667
2669
  }
@@ -2860,19 +2862,6 @@ export class Suspend extends Base {
2860
2862
  }
2861
2863
  }
2862
2864
 
2863
- /** @internal */
2864
- export function getEncodingChecks(ast: AST): Checks | undefined {
2865
- switch (ast._tag) {
2866
- case "Declaration":
2867
- case "Arrays":
2868
- case "Objects":
2869
- case "Union":
2870
- return ast.encodingChecks
2871
- default:
2872
- return undefined
2873
- }
2874
- }
2875
-
2876
2865
  // -----------------------------------------------------------------------------
2877
2866
  // Checks
2878
2867
  // -----------------------------------------------------------------------------
@@ -3140,6 +3129,14 @@ export function applyToLastLink(f: (ast: AST) => AST) {
3140
3129
  return <A extends AST>(ast: A): A => ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, f)) : ast
3141
3130
  }
3142
3131
 
3132
+ /** @internal */
3133
+ export function applyToSelfOrLastLinkEncoding(f: (ast: AST) => AST) {
3134
+ function out(ast: AST): AST {
3135
+ return ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, out)) : f(ast)
3136
+ }
3137
+ return memoize(out)
3138
+ }
3139
+
3143
3140
  /** @internal */
3144
3141
  export function middlewareDecoding(
3145
3142
  ast: AST,
@@ -3384,9 +3381,13 @@ export const toType = memoize(<A extends AST>(ast: A): A => {
3384
3381
  }
3385
3382
  const out: any = ast
3386
3383
  const type = out.recur?.(toType) ?? out
3387
- if (getEncodingChecks(type)) {
3384
+ const encodingChecks = type.encodingChecks
3385
+ if (encodingChecks) {
3388
3386
  return modifyOwnPropertyDescriptors(type, (d) => {
3389
3387
  d.encodingChecks.value = undefined
3388
+ if (type === ast) {
3389
+ d.checks.value = combineChecks(type.checks, encodingChecks)
3390
+ }
3390
3391
  })
3391
3392
  }
3392
3393
  return type
@@ -3560,15 +3561,7 @@ export const enumsToLiterals = memoize((ast: Enum): Union<Literal> => {
3560
3561
  )
3561
3562
  })
3562
3563
 
3563
- /** @internal */
3564
- export function toCodec(f: (ast: AST) => AST) {
3565
- function out(ast: AST): AST {
3566
- return ast.encoding ? replaceEncoding(ast, updateLastLink(ast.encoding, out)) : f(ast)
3567
- }
3568
- return memoize(out)
3569
- }
3570
-
3571
- const parameterFromPropertyKey = toCodec((ast) => {
3564
+ const parameterFromPropertyKey = applyToSelfOrLastLinkEncoding((ast) => {
3572
3565
  switch (ast._tag) {
3573
3566
  default:
3574
3567
  return ast
@@ -3580,7 +3573,7 @@ const parameterFromPropertyKey = toCodec((ast) => {
3580
3573
  })
3581
3574
 
3582
3575
  /** @internal */
3583
- export const parameterFromString = toCodec((ast) => {
3576
+ export const parameterFromString = applyToSelfOrLastLinkEncoding((ast) => {
3584
3577
  switch (ast._tag) {
3585
3578
  default:
3586
3579
  return ast
@@ -3592,7 +3585,7 @@ export const parameterFromString = toCodec((ast) => {
3592
3585
  }
3593
3586
  })
3594
3587
 
3595
- const partFromString = toCodec((ast) => {
3588
+ const partFromString = applyToSelfOrLastLinkEncoding((ast) => {
3596
3589
  switch (ast._tag) {
3597
3590
  default:
3598
3591
  return ast
@@ -3970,10 +3963,7 @@ const StringTree = new Declaration(
3970
3963
  isStringTree(input) ?
3971
3964
  Effect.succeed(input) :
3972
3965
  Effect.fail(new SchemaIssue.InvalidType(ast, Option.some(input))),
3973
- {
3974
- expected: "StringTree",
3975
- toCodecStringTree: () => new Link(unknown, SchemaTransformation.passthrough())
3976
- }
3966
+ { expected: "StringTree" }
3977
3967
  )
3978
3968
 
3979
3969
  /** @internal */
@@ -67,7 +67,7 @@ const recurDefaults = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
67
67
  * @category constructors
68
68
  * @since 4.0.0
69
69
  */
70
- export function makeEffect<S extends Schema.Top>(schema: S) {
70
+ export function makeEffect<S extends Schema.Constraint>(schema: S) {
71
71
  const ast = recurDefaults(SchemaAST.toType(schema.ast))
72
72
  const parser = run<S["Type"], never>(ast)
73
73
  return (input: S["~type.make.in"], options?: Schema.MakeOptions): Effect.Effect<S["Type"], SchemaIssue.Issue> => {
@@ -98,7 +98,7 @@ export function makeEffect<S extends Schema.Top>(schema: S) {
98
98
  * @category constructors
99
99
  * @since 4.0.0
100
100
  */
101
- export function makeOption<S extends Schema.Top>(schema: S) {
101
+ export function makeOption<S extends Schema.Constraint>(schema: S) {
102
102
  const parser = makeEffect(schema)
103
103
  return (input: S["~type.make.in"], options?: Schema.MakeOptions): Option.Option<S["Type"]> => {
104
104
  const exit = Effect.runSyncExit(parser(input, options))
@@ -132,7 +132,7 @@ export function makeOption<S extends Schema.Top>(schema: S) {
132
132
  * @category constructors
133
133
  * @since 4.0.0
134
134
  */
135
- export function make<S extends Schema.Top>(schema: S) {
135
+ export function make<S extends Schema.Constraint>(schema: S) {
136
136
  const parser = makeEffect(schema)
137
137
  return (input: S["~type.make.in"], options?: Schema.MakeOptions): S["Type"] => {
138
138
  const exit = Effect.runSyncExit(parser(input, options))
@@ -222,7 +222,7 @@ export function _issue<T>(ast: SchemaAST.AST) {
222
222
  * @category Asserting
223
223
  * @since 4.0.0
224
224
  */
225
- export function asserts<S extends Schema.Top, I>(schema: S, input: I): asserts input is I & S["Type"] {
225
+ export function asserts<S extends Schema.Constraint, I>(schema: S, input: I): asserts input is I & S["Type"] {
226
226
  const parser = asExit(run<S["Type"], never>(SchemaAST.toType(schema.ast)))
227
227
  const exit = parser(input, SchemaAST.defaultParseOptions)
228
228
  if (Exit.isFailure(exit)) {
@@ -255,7 +255,7 @@ export function asserts<S extends Schema.Top, I>(schema: S, input: I): asserts i
255
255
  * @category decoding
256
256
  * @since 4.0.0
257
257
  */
258
- export function decodeUnknownEffect<S extends Schema.Top>(
258
+ export function decodeUnknownEffect<S extends Schema.Constraint>(
259
259
  schema: S,
260
260
  options?: SchemaAST.ParseOptions
261
261
  ): (
@@ -290,7 +290,7 @@ export function decodeUnknownEffect<S extends Schema.Top>(
290
290
  * @category decoding
291
291
  * @since 4.0.0
292
292
  */
293
- export const decodeEffect: <S extends Schema.Top>(
293
+ export const decodeEffect: <S extends Schema.Constraint>(
294
294
  schema: S,
295
295
  options?: SchemaAST.ParseOptions
296
296
  ) => (
@@ -322,7 +322,7 @@ export const decodeEffect: <S extends Schema.Top>(
322
322
  * @category decoding
323
323
  * @since 3.10.0
324
324
  */
325
- export function decodeUnknownPromise<S extends Schema.Decoder<unknown>>(
325
+ export function decodeUnknownPromise<S extends Schema.ConstraintDecoder<unknown>>(
326
326
  schema: S,
327
327
  options?: SchemaAST.ParseOptions
328
328
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Promise<S["Type"]> {
@@ -354,7 +354,7 @@ export function decodeUnknownPromise<S extends Schema.Decoder<unknown>>(
354
354
  * @category decoding
355
355
  * @since 3.10.0
356
356
  */
357
- export function decodePromise<S extends Schema.Decoder<unknown>>(
357
+ export function decodePromise<S extends Schema.ConstraintDecoder<unknown>>(
358
358
  schema: S,
359
359
  options?: SchemaAST.ParseOptions
360
360
  ): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Promise<S["Type"]> {
@@ -390,7 +390,7 @@ export function decodePromise<S extends Schema.Decoder<unknown>>(
390
390
  * @category decoding
391
391
  * @since 4.0.0
392
392
  */
393
- export function decodeUnknownExit<S extends Schema.Decoder<unknown>>(
393
+ export function decodeUnknownExit<S extends Schema.ConstraintDecoder<unknown>>(
394
394
  schema: S,
395
395
  options?: SchemaAST.ParseOptions
396
396
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Exit.Exit<S["Type"], SchemaIssue.Issue> {
@@ -423,14 +423,14 @@ export function decodeUnknownExit<S extends Schema.Decoder<unknown>>(
423
423
  * @category decoding
424
424
  * @since 4.0.0
425
425
  */
426
- export const decodeExit: <S extends Schema.Decoder<unknown>>(
426
+ export const decodeExit: <S extends Schema.ConstraintDecoder<unknown>>(
427
427
  schema: S,
428
428
  options?: SchemaAST.ParseOptions
429
429
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Exit.Exit<S["Type"], SchemaIssue.Issue> =
430
430
  decodeUnknownExit
431
431
 
432
432
  /** @internal */
433
- export function decodeUnknownOption<S extends Schema.Decoder<unknown>>(
433
+ export function decodeUnknownOption<S extends Schema.ConstraintDecoder<unknown>>(
434
434
  schema: S,
435
435
  options?: SchemaAST.ParseOptions
436
436
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Option.Option<S["Type"]> {
@@ -438,7 +438,7 @@ export function decodeUnknownOption<S extends Schema.Decoder<unknown>>(
438
438
  }
439
439
 
440
440
  /** @internal */
441
- export const decodeOption: <S extends Schema.Decoder<unknown>>(
441
+ export const decodeOption: <S extends Schema.ConstraintDecoder<unknown>>(
442
442
  schema: S,
443
443
  options?: SchemaAST.ParseOptions
444
444
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Option.Option<S["Type"]> = decodeUnknownOption
@@ -469,7 +469,7 @@ export const decodeOption: <S extends Schema.Decoder<unknown>>(
469
469
  * @category decoding
470
470
  * @since 4.0.0
471
471
  */
472
- export function decodeUnknownResult<S extends Schema.Decoder<unknown>>(
472
+ export function decodeUnknownResult<S extends Schema.ConstraintDecoder<unknown>>(
473
473
  schema: S,
474
474
  options?: SchemaAST.ParseOptions
475
475
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Type"], SchemaIssue.Issue> {
@@ -502,7 +502,7 @@ export function decodeUnknownResult<S extends Schema.Decoder<unknown>>(
502
502
  * @category decoding
503
503
  * @since 4.0.0
504
504
  */
505
- export const decodeResult: <S extends Schema.Decoder<unknown>>(
505
+ export const decodeResult: <S extends Schema.ConstraintDecoder<unknown>>(
506
506
  schema: S,
507
507
  options?: SchemaAST.ParseOptions
508
508
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Result.Result<S["Type"], SchemaIssue.Issue> =
@@ -534,7 +534,7 @@ export const decodeResult: <S extends Schema.Decoder<unknown>>(
534
534
  * @category decoding
535
535
  * @since 3.10.0
536
536
  */
537
- export function decodeUnknownSync<S extends Schema.Decoder<unknown>>(
537
+ export function decodeUnknownSync<S extends Schema.ConstraintDecoder<unknown>>(
538
538
  schema: S,
539
539
  options?: SchemaAST.ParseOptions
540
540
  ): (input: unknown, options?: SchemaAST.ParseOptions) => S["Type"] {
@@ -568,7 +568,7 @@ export function decodeUnknownSync<S extends Schema.Decoder<unknown>>(
568
568
  * @category decoding
569
569
  * @since 3.10.0
570
570
  */
571
- export const decodeSync: <S extends Schema.Decoder<unknown>>(
571
+ export const decodeSync: <S extends Schema.ConstraintDecoder<unknown>>(
572
572
  schema: S,
573
573
  options?: SchemaAST.ParseOptions
574
574
  ) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"] = decodeUnknownSync
@@ -594,7 +594,7 @@ export const decodeSync: <S extends Schema.Decoder<unknown>>(
594
594
  * @category encoding
595
595
  * @since 4.0.0
596
596
  */
597
- export function encodeUnknownEffect<S extends Schema.Top>(
597
+ export function encodeUnknownEffect<S extends Schema.Constraint>(
598
598
  schema: S,
599
599
  options?: SchemaAST.ParseOptions
600
600
  ): (
@@ -628,7 +628,7 @@ export function encodeUnknownEffect<S extends Schema.Top>(
628
628
  * @category encoding
629
629
  * @since 4.0.0
630
630
  */
631
- export const encodeEffect: <S extends Schema.Top>(
631
+ export const encodeEffect: <S extends Schema.Constraint>(
632
632
  schema: S,
633
633
  options?: SchemaAST.ParseOptions
634
634
  ) => (
@@ -660,7 +660,7 @@ export const encodeEffect: <S extends Schema.Top>(
660
660
  * @category encoding
661
661
  * @since 3.10.0
662
662
  */
663
- export const encodeUnknownPromise = <S extends Schema.Encoder<unknown>>(
663
+ export const encodeUnknownPromise = <S extends Schema.ConstraintEncoder<unknown>>(
664
664
  schema: S,
665
665
  options?: SchemaAST.ParseOptions
666
666
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]> =>
@@ -691,7 +691,7 @@ export const encodeUnknownPromise = <S extends Schema.Encoder<unknown>>(
691
691
  * @category encoding
692
692
  * @since 3.10.0
693
693
  */
694
- export const encodePromise: <S extends Schema.Encoder<unknown>>(
694
+ export const encodePromise: <S extends Schema.ConstraintEncoder<unknown>>(
695
695
  schema: S,
696
696
  options?: SchemaAST.ParseOptions
697
697
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]> = encodeUnknownPromise
@@ -722,7 +722,7 @@ export const encodePromise: <S extends Schema.Encoder<unknown>>(
722
722
  * @category encoding
723
723
  * @since 4.0.0
724
724
  */
725
- export function encodeUnknownExit<S extends Schema.Encoder<unknown>>(
725
+ export function encodeUnknownExit<S extends Schema.ConstraintEncoder<unknown>>(
726
726
  schema: S,
727
727
  options?: SchemaAST.ParseOptions
728
728
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Exit.Exit<S["Encoded"], SchemaIssue.Issue> {
@@ -755,14 +755,14 @@ export function encodeUnknownExit<S extends Schema.Encoder<unknown>>(
755
755
  * @category encoding
756
756
  * @since 4.0.0
757
757
  */
758
- export const encodeExit: <S extends Schema.Encoder<unknown>>(
758
+ export const encodeExit: <S extends Schema.ConstraintEncoder<unknown>>(
759
759
  schema: S,
760
760
  options?: SchemaAST.ParseOptions
761
761
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit.Exit<S["Encoded"], SchemaIssue.Issue> =
762
762
  encodeUnknownExit
763
763
 
764
764
  /** @internal */
765
- export function encodeUnknownOption<S extends Schema.Encoder<unknown>>(
765
+ export function encodeUnknownOption<S extends Schema.ConstraintEncoder<unknown>>(
766
766
  schema: S,
767
767
  options?: SchemaAST.ParseOptions
768
768
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Option.Option<S["Encoded"]> {
@@ -770,7 +770,7 @@ export function encodeUnknownOption<S extends Schema.Encoder<unknown>>(
770
770
  }
771
771
 
772
772
  /** @internal */
773
- export const encodeOption: <S extends Schema.Encoder<unknown>>(
773
+ export const encodeOption: <S extends Schema.ConstraintEncoder<unknown>>(
774
774
  schema: S,
775
775
  options?: SchemaAST.ParseOptions
776
776
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Option.Option<S["Encoded"]> = encodeUnknownOption
@@ -803,7 +803,7 @@ export const encodeOption: <S extends Schema.Encoder<unknown>>(
803
803
  * @category encoding
804
804
  * @since 4.0.0
805
805
  */
806
- export function encodeUnknownResult<S extends Schema.Encoder<unknown>>(
806
+ export function encodeUnknownResult<S extends Schema.ConstraintEncoder<unknown>>(
807
807
  schema: S,
808
808
  options?: SchemaAST.ParseOptions
809
809
  ): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue> {
@@ -836,7 +836,7 @@ export function encodeUnknownResult<S extends Schema.Encoder<unknown>>(
836
836
  * @category encoding
837
837
  * @since 4.0.0
838
838
  */
839
- export const encodeResult: <S extends Schema.Encoder<unknown>>(
839
+ export const encodeResult: <S extends Schema.ConstraintEncoder<unknown>>(
840
840
  schema: S,
841
841
  options?: SchemaAST.ParseOptions
842
842
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue> =
@@ -867,7 +867,7 @@ export const encodeResult: <S extends Schema.Encoder<unknown>>(
867
867
  * @category encoding
868
868
  * @since 3.10.0
869
869
  */
870
- export function encodeUnknownSync<S extends Schema.Encoder<unknown>>(
870
+ export function encodeUnknownSync<S extends Schema.ConstraintEncoder<unknown>>(
871
871
  schema: S,
872
872
  options?: SchemaAST.ParseOptions
873
873
  ): (input: unknown, options?: SchemaAST.ParseOptions) => S["Encoded"] {
@@ -901,7 +901,7 @@ export function encodeUnknownSync<S extends Schema.Encoder<unknown>>(
901
901
  * @category encoding
902
902
  * @since 3.10.0
903
903
  */
904
- export const encodeSync: <S extends Schema.Encoder<unknown>>(
904
+ export const encodeSync: <S extends Schema.ConstraintEncoder<unknown>>(
905
905
  schema: S,
906
906
  options?: SchemaAST.ParseOptions
907
907
  ) => (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"] = encodeUnknownSync
@@ -1007,11 +1007,14 @@ export interface Parser {
1007
1007
  const recur = memoize(
1008
1008
  (ast: SchemaAST.AST): Parser => {
1009
1009
  let parser: Parser
1010
- const encodingChecks = SchemaAST.getEncodingChecks(ast)
1011
- const resolvedChecks = ast.checks ?? encodingChecks
1012
- const astOptions = (resolvedChecks ? resolvedChecks[resolvedChecks.length - 1].annotations : ast.annotations)
1010
+ const checks = ast.checks
1011
+ const encoding = ast.encoding
1012
+ const links = encoding
1013
+ const len = links?.length ?? 0
1014
+ const encodingChecks = (ast as any).encodingChecks
1015
+ const astOptions = (checks ? checks[checks.length - 1].annotations : ast.annotations)
1013
1016
  ?.["parseOptions"]
1014
- if (!ast.context && !ast.encoding && !ast.checks && !encodingChecks) {
1017
+ if (!ast.context && !encoding && !checks && !encodingChecks) {
1015
1018
  return (ou, options) => {
1016
1019
  parser ??= ast.getParser(recur)
1017
1020
  if (astOptions) {
@@ -1022,15 +1025,15 @@ const recur = memoize(
1022
1025
  }
1023
1026
  const isStructural = SchemaAST.isArrays(ast) || SchemaAST.isObjects(ast) ||
1024
1027
  (SchemaAST.isDeclaration(ast) && ast.typeParameters.length > 0)
1028
+ const structuralChecks = checks && isStructural ?
1029
+ checks.filter((check) => check.annotations?.[SchemaAST.STRUCTURAL_ANNOTATION_KEY]) :
1030
+ undefined
1025
1031
  return (ou, options) => {
1026
1032
  if (astOptions) {
1027
1033
  options = { ...options, ...astOptions }
1028
1034
  }
1029
- const encoding = ast.encoding
1030
1035
  let srou: Effect.Effect<Option.Option<unknown>, SchemaIssue.Issue, unknown> | undefined
1031
- if (encoding) {
1032
- const links = encoding
1033
- const len = links.length
1036
+ if (links) {
1034
1037
  for (let i = len - 1; i >= 0; i--) {
1035
1038
  const link = links[i]
1036
1039
  const to = link.to
@@ -1047,58 +1050,63 @@ const recur = memoize(
1047
1050
  }
1048
1051
 
1049
1052
  parser ??= ast.getParser(recur)
1050
- let sroa = srou ? Effect.flatMapEager(srou, (ou) => parser(ou, options)) : parser(ou, options)
1053
+ const parseLocal = (localOu: Option.Option<unknown>) => {
1054
+ let sroa = parser(localOu, options)
1051
1055
 
1052
- if (encodingChecks && !options?.disableChecks) {
1053
- sroa = Effect.flatMapEager(sroa, (oa) => {
1054
- if (Option.isSome(ou) && Option.isSome(oa)) {
1055
- const issues: Array<SchemaIssue.Issue> = []
1056
+ if (encodingChecks && !options?.disableChecks) {
1057
+ sroa = Effect.flatMapEager(sroa, (oa) => {
1058
+ if (Option.isSome(localOu) && Option.isSome(oa)) {
1059
+ const issues: Array<SchemaIssue.Issue> = []
1056
1060
 
1057
- SchemaAST.collectIssues(encodingChecks, ou.value, issues, ast, options)
1061
+ SchemaAST.collectIssues(encodingChecks, localOu.value, issues, ast, options)
1058
1062
 
1059
- if (Arr.isArrayNonEmpty(issues)) {
1060
- return Effect.fail(new SchemaIssue.Composite(ast, ou, issues))
1063
+ if (Arr.isArrayNonEmpty(issues)) {
1064
+ return Effect.fail(new SchemaIssue.Composite(ast, localOu, issues))
1065
+ }
1061
1066
  }
1062
- }
1063
- return Effect.succeed(oa)
1064
- })
1065
- }
1066
-
1067
- if (ast.checks && !options?.disableChecks) {
1068
- const checks = ast.checks
1069
- if (options?.errors === "all" && isStructural && Option.isSome(ou)) {
1070
- sroa = mapSchemaIssueEffect(sroa, (issue) => {
1071
- const issues: Array<SchemaIssue.Issue> = []
1072
- SchemaAST.collectIssues(
1073
- checks.filter((check) => check.annotations?.[SchemaAST.STRUCTURAL_ANNOTATION_KEY]),
1074
- ou.value,
1075
- issues,
1076
- ast,
1077
- options
1078
- )
1079
- const out: SchemaIssue.Issue = Arr.isArrayNonEmpty(issues)
1080
- ? issue._tag === "Composite" && issue.ast === ast
1081
- ? new SchemaIssue.Composite(ast, issue.actual, [...issue.issues, ...issues])
1082
- : new SchemaIssue.Composite(ast, ou, [issue, ...issues])
1083
- : issue
1084
- return out
1067
+ return Effect.succeed(oa)
1085
1068
  })
1086
1069
  }
1087
- sroa = Effect.flatMapEager(sroa, (oa) => {
1088
- if (Option.isSome(oa)) {
1089
- const value = oa.value
1090
- const issues: Array<SchemaIssue.Issue> = []
1091
1070
 
1092
- SchemaAST.collectIssues(checks, value, issues, ast, options)
1071
+ if (checks && !options?.disableChecks) {
1072
+ if (options?.errors === "all" && structuralChecks && structuralChecks.length > 0 && Option.isSome(localOu)) {
1073
+ sroa = mapSchemaIssueEffect(sroa, (issue) => {
1074
+ const issues: Array<SchemaIssue.Issue> = []
1075
+ SchemaAST.collectIssues(
1076
+ structuralChecks,
1077
+ localOu.value,
1078
+ issues,
1079
+ ast,
1080
+ options
1081
+ )
1082
+ const out: SchemaIssue.Issue = Arr.isArrayNonEmpty(issues)
1083
+ ? issue._tag === "Composite" && issue.ast === ast
1084
+ ? new SchemaIssue.Composite(ast, issue.actual, [...issue.issues, ...issues])
1085
+ : new SchemaIssue.Composite(ast, localOu, [issue, ...issues])
1086
+ : issue
1087
+ return out
1088
+ })
1089
+ }
1090
+ sroa = Effect.flatMapEager(sroa, (oa) => {
1091
+ if (Option.isSome(oa)) {
1092
+ const value = oa.value
1093
+ const issues: Array<SchemaIssue.Issue> = []
1094
+
1095
+ SchemaAST.collectIssues(checks, value, issues, ast, options)
1093
1096
 
1094
- if (Arr.isArrayNonEmpty(issues)) {
1095
- return Effect.fail(new SchemaIssue.Composite(ast, oa, issues))
1097
+ if (Arr.isArrayNonEmpty(issues)) {
1098
+ return Effect.fail(new SchemaIssue.Composite(ast, oa, issues))
1099
+ }
1096
1100
  }
1097
- }
1098
- return Effect.succeed(oa)
1099
- })
1101
+ return Effect.succeed(oa)
1102
+ })
1103
+ }
1104
+
1105
+ return sroa
1100
1106
  }
1101
1107
 
1108
+ const sroa = srou ? Effect.flatMapEager(srou, parseLocal) : parseLocal(ou)
1109
+
1102
1110
  return sroa
1103
1111
  }
1104
1112
  }
@@ -1312,8 +1312,8 @@ export function optionFromOptional<T>(): Transformation<Option.Option<T>, T | un
1312
1312
  *
1313
1313
  * **Details**
1314
1314
  *
1315
- * Decoding calls `new URL(s)` and fails with `InvalidValue` if the string is
1316
- * not a valid URL. Encoding returns `url.href`.
1315
+ * Decoding checks `URL.canParse(s)` and fails with `InvalidValue` if the string
1316
+ * is not a valid URL. Encoding returns `url.href`.
1317
1317
  *
1318
1318
  * **Example** (Converting a string to a URL)
1319
1319
  *
@@ -1333,10 +1333,9 @@ export function optionFromOptional<T>(): Transformation<Option.Option<T>, T | un
1333
1333
  */
1334
1334
  export const urlFromString: Transformation<URL, string> = transformOrFail<URL, string>({
1335
1335
  decode: (s) =>
1336
- Effect.try({
1337
- try: () => new URL(s),
1338
- catch: () => new SchemaIssue.InvalidValue(Option.some(s), { message: `Invalid URL string: ${s}` })
1339
- }),
1336
+ URL.canParse(s)
1337
+ ? Effect.succeed(new URL(s))
1338
+ : Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: `Invalid URL string: ${s}` })),
1340
1339
  encode: (url) => Effect.succeed(url.href)
1341
1340
  })
1342
1341
 
@@ -3154,23 +3154,6 @@ export const unwrapReason: {
3154
3154
  ) as any
3155
3155
  )
3156
3156
 
3157
- /** @internal */
3158
- export const mapErrorCause: {
3159
- <E, E2>(
3160
- f: (e: Cause.Cause<E>) => Cause.Cause<E2>
3161
- ): <A, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E2, R>
3162
- <A, E, R, E2>(
3163
- self: Effect.Effect<A, E, R>,
3164
- f: (e: Cause.Cause<E>) => Cause.Cause<E2>
3165
- ): Effect.Effect<A, E2, R>
3166
- } = dual(
3167
- 2,
3168
- <A, E, R, E2>(
3169
- self: Effect.Effect<A, E, R>,
3170
- f: (e: Cause.Cause<E>) => Cause.Cause<E2>
3171
- ): Effect.Effect<A, E2, R> => catchCause(self, (cause) => failCauseSync(() => f(cause)))
3172
- )
3173
-
3174
3157
  /** @internal */
3175
3158
  export const mapError: {
3176
3159
  <E, E2>(
@@ -5827,11 +5810,12 @@ const performanceNowNanos = (function() {
5827
5810
  const bigint1e6 = BigInt(1_000_000)
5828
5811
  if (typeof performance === "undefined" || typeof performance.now === "undefined") {
5829
5812
  return () => BigInt(Date.now()) * bigint1e6
5830
- } else if (typeof performance.timeOrigin === "number" && performance.timeOrigin === 0) {
5831
- return () => BigInt(Math.round(performance.now() * 1_000_000))
5832
5813
  }
5833
- const origin = (BigInt(Date.now()) * bigint1e6) - BigInt(Math.round(performance.now() * 1_000_000))
5834
- return () => origin + BigInt(Math.round(performance.now() * 1_000_000))
5814
+ let origin: bigint
5815
+ return () => {
5816
+ origin ??= (BigInt(Date.now()) * bigint1e6) - BigInt(Math.round(performance.now() * 1_000_000))
5817
+ return origin + BigInt(Math.round(performance.now() * 1_000_000))
5818
+ }
5835
5819
  })()
5836
5820
  const processOrPerformanceNow = (function() {
5837
5821
  const processHrtime =
@@ -5841,7 +5825,7 @@ const processOrPerformanceNow = (function() {
5841
5825
  if (!processHrtime) {
5842
5826
  return performanceNowNanos
5843
5827
  }
5844
- const origin = performanceNowNanos() - processHrtime.bigint()
5828
+ const origin = (BigInt(Date.now()) * BigInt(1e6)) - processHrtime.bigint()
5845
5829
  return () => origin + processHrtime.bigint()
5846
5830
  })()
5847
5831
 
@@ -520,11 +520,6 @@ export const instanceOf = <A extends abstract new(...args: any) => any>(
520
520
  constructor: A
521
521
  ): SafeRefinement<InstanceType<A>, never> => ((u: unknown) => u instanceof constructor) as any
522
522
 
523
- /** @internal */
524
- export const instanceOfUnsafe: <A extends abstract new(...args: any) => any>(
525
- constructor: A
526
- ) => SafeRefinement<InstanceType<A>, InstanceType<A>> = instanceOf
527
-
528
523
  /** @internal */
529
524
  export const orElse =
530
525
  <RA, Ret, F extends (_: RA) => Ret>(f: F) =>
@@ -22,7 +22,7 @@ const emptyRecursionStack: RecursionStack = []
22
22
  type RecursionStack = ReadonlyArray<SchemaAST.Suspend>
23
23
 
24
24
  type Context = Schema.Annotations.ToArbitrary.Context
25
- type Constraint = Schema.Annotations.ToArbitrary.Constraint
25
+ type Constraint = Schema.Annotations.ToArbitrary.GenerationConstraint
26
26
  type OrderedConstraint = Schema.Annotations.ToArbitrary.OrderedConstraint<any>
27
27
  type ArbitraryFilter = Schema.Annotations.ToArbitrary.Filter
28
28
 
@@ -127,6 +127,7 @@ export function fromASTs(asts: readonly [SchemaAST.AST, ...Array<SchemaAST.AST>]
127
127
  case "Any":
128
128
  case "Boolean":
129
129
  case "Symbol":
130
+ case "ObjectKeyword":
130
131
  return { _tag: last._tag, ...annotations }
131
132
  case "String": {
132
133
  const contentMediaType = last.annotations?.contentMediaType
@@ -159,11 +160,6 @@ export function fromASTs(asts: readonly [SchemaAST.AST, ...Array<SchemaAST.AST>]
159
160
  symbol: last.symbol,
160
161
  ...annotations
161
162
  }
162
- case "ObjectKeyword":
163
- return {
164
- _tag: last._tag,
165
- ...annotations
166
- }
167
163
  case "Enum":
168
164
  return {
169
165
  _tag: last._tag,
@@ -28,7 +28,7 @@ const SchemaProto = {
28
28
  }
29
29
 
30
30
  /** @internal */
31
- export function make<S extends Schema.Top>(ast: S["ast"], options?: object): S {
31
+ export function make<S extends Schema.Constraint>(ast: S["ast"], options?: object): S {
32
32
  const self = Object.create(SchemaProto)
33
33
  if (options) {
34
34
  Object.assign(self, options)