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
@@ -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
  }
@@ -96,7 +96,8 @@ import {
96
96
  TracerSpanLinks,
97
97
  TracerTimingEnabled
98
98
  } from "./references.ts"
99
- import { addSpanStackTrace, type ErrorWithStackTraceLimit, makeStackCleaner } from "./tracer.ts"
99
+ import { getStackTraceLimit, setStackTraceLimit } from "./stackTraceLimit.ts"
100
+ import { addSpanStackTrace, makeStackCleaner } from "./tracer.ts"
100
101
  import { version } from "./version.ts"
101
102
 
102
103
  // ----------------------------------------------------------------------------
@@ -314,9 +315,8 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
314
315
  const interrupts: Array<Cause.Interrupt> = []
315
316
  if (self.reasons.length === 0) return errors
316
317
 
317
- const prevStackLimit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
318
- ;(Error as ErrorWithStackTraceLimit)
319
- .stackTraceLimit = 1
318
+ const prevStackLimit = getStackTraceLimit()
319
+ setStackTraceLimit(1)
320
320
 
321
321
  for (const failure of self.reasons) {
322
322
  if (failure._tag === "Interrupt") {
@@ -340,7 +340,7 @@ export const causePrettyErrors = <E>(self: Cause.Cause<E>): Array<Error> => {
340
340
  errors.push(causePrettyError(error, interrupts[0].annotations))
341
341
  }
342
342
 
343
- ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = prevStackLimit
343
+ setStackTraceLimit(prevStackLimit)
344
344
  return errors
345
345
  }
346
346
 
@@ -1157,10 +1157,10 @@ export const fn: typeof Effect.fn = function() {
1157
1157
  const name = nameFirst ? arguments[0] : "Effect.fn"
1158
1158
  const spanOptions = nameFirst ? arguments[1] : undefined
1159
1159
 
1160
- const prevLimit = globalThis.Error.stackTraceLimit
1161
- globalThis.Error.stackTraceLimit = 2
1160
+ const prevLimit = getStackTraceLimit()
1161
+ setStackTraceLimit(2)
1162
1162
  const defError = new globalThis.Error()
1163
- globalThis.Error.stackTraceLimit = prevLimit
1163
+ setStackTraceLimit(prevLimit)
1164
1164
 
1165
1165
  if (nameFirst) {
1166
1166
  return (body: Function | { readonly self: any }, ...pipeables: Array<Function>) =>
@@ -1200,10 +1200,10 @@ const makeFn = (
1200
1200
  if (!isEffect(result)) {
1201
1201
  return result
1202
1202
  }
1203
- const prevLimit = globalThis.Error.stackTraceLimit
1204
- globalThis.Error.stackTraceLimit = 2
1203
+ const prevLimit = getStackTraceLimit()
1204
+ setStackTraceLimit(2)
1205
1205
  const callError = new globalThis.Error()
1206
- globalThis.Error.stackTraceLimit = prevLimit
1206
+ setStackTraceLimit(prevLimit)
1207
1207
  return updateService(
1208
1208
  addSpan ?
1209
1209
  useSpan(name, spanOptions!, (span) => provideParentSpan(result, span)) :
@@ -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
 
@@ -382,6 +382,18 @@ function oneOf<T>(fc: typeof FastCheck, arbitraries: ReadonlyArray<FastCheck.Arb
382
382
  return arbitraries.length === 0 ? undefined : arbitraries.length === 1 ? arbitraries[0] : fc.oneof(...arbitraries)
383
383
  }
384
384
 
385
+ const finiteNumberConstraint: Constraint = {
386
+ noInfinity: true,
387
+ noNaN: true
388
+ }
389
+
390
+ function finiteNumberContext(ctx: Context): Context {
391
+ return {
392
+ ...ctx,
393
+ constraint: finiteNumberConstraint
394
+ }
395
+ }
396
+
385
397
  function reportChecks(report: MutableReport, checks: SchemaAST.Checks | undefined, path: ReadonlyArray<PropertyKey>) {
386
398
  function visit(check: SchemaAST.Check<any>, covered: boolean) {
387
399
  const arbitrary = check.annotations?.arbitrary
@@ -430,6 +442,9 @@ export function collectReport(ast: SchemaAST.AST, report: MutableReport) {
430
442
  case "Union":
431
443
  ast.types.forEach((type) => visit(type, path))
432
444
  break
445
+ case "TemplateLiteral":
446
+ ast.parts.forEach((part, i) => visit(SchemaAST.toEncoded(part), [...path, i]))
447
+ break
433
448
  case "Suspend":
434
449
  visit(ast.thunk(), path)
435
450
  break
@@ -605,8 +620,14 @@ function base(ast: SchemaAST.AST, path: ReadonlyArray<PropertyKey>): LazyArbitra
605
620
  return same((fc) => fc.oneof(fc.object(), fc.array(fc.anything())))
606
621
  case "Enum":
607
622
  return recur(SchemaAST.enumsToLiterals(ast), path)
608
- case "TemplateLiteral":
609
- return same((fc) => fc.stringMatching(SchemaAST.getTemplateLiteralRegExp(ast)))
623
+ case "TemplateLiteral": {
624
+ const parts = ast.parts.map((part, i) => recur(SchemaAST.toEncoded(part), [...path, i]))
625
+ return same((fc, ctx, recursionStack) =>
626
+ fc.tuple(...parts.map((part) => part(fc, finiteNumberContext(ctx), recursionStack))).map((segments) =>
627
+ segments.map((segment) => globalThis.String(segment)).join("")
628
+ )
629
+ )
630
+ }
610
631
  case "Arrays": {
611
632
  const elements = ast.elements.map((ast, i) => ({
612
633
  ast,
@@ -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)
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Utility for safely manipulating `Error.stackTraceLimit` in environments
3
+ * where intrinsics may be frozen (e.g., SES / hardened JavaScript or
4
+ * deterministic sandboxes such as Temporal). When the property is non-writable,
5
+ * mutating it throws, so all manipulation here degrades to a best-effort,
6
+ * silent no-op.
7
+ *
8
+ * Mirrors the guard Node uses internally:
9
+ * https://github.com/nodejs/node/blob/e77694631f1642c302f664703197b5aabc65b482/lib/internal/errors.js#L246
10
+ *
11
+ * The error is constructed inline at each call site (rather than inside a
12
+ * closure here) so the captured stack trace keeps pointing at the real caller
13
+ * instead of this module.
14
+ *
15
+ * @internal
16
+ */
17
+ import type { ErrorWithStackTraceLimit } from "./tracer.ts"
18
+
19
+ const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor
20
+ const ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty
21
+ const ObjectIsExtensible = Object.isExtensible
22
+
23
+ /**
24
+ * Check if `Error.stackTraceLimit` is writable.
25
+ * Returns `false` if the property is frozen, non-writable, or `Error` is non-extensible.
26
+ *
27
+ * @internal
28
+ */
29
+ export const isStackTraceLimitWritable = (): boolean => {
30
+ const desc = ObjectGetOwnPropertyDescriptor(Error, "stackTraceLimit")
31
+ if (desc === undefined) {
32
+ return ObjectIsExtensible(Error)
33
+ }
34
+
35
+ return ObjectPrototypeHasOwnProperty.call(desc, "writable")
36
+ ? desc.writable === true
37
+ : desc.set !== undefined
38
+ }
39
+
40
+ // Cache the check result since it won't change during runtime
41
+ const canWriteStackTraceLimit = isStackTraceLimitWritable()
42
+
43
+ /**
44
+ * Get the current `Error.stackTraceLimit` value.
45
+ * Returns `undefined` if the property doesn't exist.
46
+ *
47
+ * @internal
48
+ */
49
+ export const getStackTraceLimit = (): number | undefined => (Error as ErrorWithStackTraceLimit).stackTraceLimit
50
+
51
+ /**
52
+ * Safely set `Error.stackTraceLimit` if possible, otherwise no-op.
53
+ *
54
+ * Accepts `undefined` so a value read via {@link getStackTraceLimit} can be
55
+ * restored faithfully.
56
+ *
57
+ * @internal
58
+ */
59
+ export const setStackTraceLimit = (value: number | undefined): void => {
60
+ if (canWriteStackTraceLimit) {
61
+ ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = value
62
+ }
63
+ }
@@ -1,4 +1,5 @@
1
1
  import type * as Tracer from "../Tracer.ts"
2
+ import { getStackTraceLimit, setStackTraceLimit } from "./stackTraceLimit.ts"
2
3
 
3
4
  export interface ErrorWithStackTraceLimit {
4
5
  stackTraceLimit?: number | undefined
@@ -13,10 +14,10 @@ export const addSpanStackTrace = <A extends Tracer.TraceOptions>(
13
14
  } else if (options?.captureStackTrace !== undefined && typeof options.captureStackTrace !== "boolean") {
14
15
  return options
15
16
  }
16
- const limit = (Error as ErrorWithStackTraceLimit).stackTraceLimit
17
- ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = 3
17
+ const limit = getStackTraceLimit()
18
+ setStackTraceLimit(3)
18
19
  const traceError = new Error()
19
- ;(Error as ErrorWithStackTraceLimit).stackTraceLimit = limit
20
+ setStackTraceLimit(limit)
20
21
  return {
21
22
  ...options,
22
23
  captureStackTrace: spanCleaner(() => traceError.stack)