effect 4.0.0-beta.104 → 4.0.0-beta.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +381 -0
- package/CLAUDE.md +381 -0
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +5 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +165 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +116 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +136 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +24 -0
- package/dist/Brand.d.ts +3 -3
- package/dist/Brand.d.ts.map +1 -1
- package/dist/Brand.js +4 -3
- package/dist/Brand.js.map +1 -1
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +5 -4
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +35 -3
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +41 -8
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Context.d.ts +0 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +1 -22
- package/dist/Context.js.map +1 -1
- package/dist/Cron.d.ts +31 -0
- package/dist/Cron.d.ts.map +1 -1
- package/dist/Cron.js +58 -2
- package/dist/Cron.js.map +1 -1
- package/dist/Fiber.d.ts +1 -1
- package/dist/Fiber.d.ts.map +1 -1
- package/dist/Function.d.ts +26 -0
- package/dist/Function.d.ts.map +1 -1
- package/dist/Function.js +36 -0
- package/dist/Function.js.map +1 -1
- package/dist/JsonSchema.d.ts.map +1 -1
- package/dist/JsonSchema.js +34 -17
- package/dist/JsonSchema.js.map +1 -1
- package/dist/Optic.d.ts +35 -21
- package/dist/Optic.d.ts.map +1 -1
- package/dist/Optic.js +33 -34
- package/dist/Optic.js.map +1 -1
- package/dist/Schema.d.ts +105 -109
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +141 -104
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +32 -17
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +79 -60
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +8 -8
- package/dist/SchemaError.d.ts.map +1 -1
- package/dist/SchemaError.js +7 -6
- package/dist/SchemaError.js.map +1 -1
- package/dist/SchemaGetter.d.ts +8 -5
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +41 -37
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaIssue.d.ts +195 -38
- package/dist/SchemaIssue.d.ts.map +1 -1
- package/dist/SchemaIssue.js +243 -68
- package/dist/SchemaIssue.js.map +1 -1
- package/dist/SchemaParser.d.ts +30 -0
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +39 -9
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +15 -3
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +8 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +2 -2
- package/dist/SchemaTransformation.d.ts.map +1 -1
- package/dist/SchemaTransformation.js +26 -26
- package/dist/SchemaTransformation.js.map +1 -1
- package/dist/ScopedRef.d.ts.map +1 -1
- package/dist/ScopedRef.js +1 -1
- package/dist/ScopedRef.js.map +1 -1
- package/dist/Stdio.d.ts +17 -4
- package/dist/Stdio.d.ts.map +1 -1
- package/dist/Stdio.js +6 -3
- package/dist/Stdio.js.map +1 -1
- package/dist/TxQueue.js +1 -1
- package/dist/TxQueue.js.map +1 -1
- package/dist/internal/effect.js +2 -4
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/executionPlan.js +3 -2
- package/dist/internal/executionPlan.js.map +1 -1
- package/dist/internal/rcRef.js +18 -13
- package/dist/internal/rcRef.js.map +1 -1
- package/dist/internal/schema/fromJsonSchemaDocument.js +10 -6
- package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/schema.js +1 -9
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/schema/toArbitrary.d.ts +1 -4
- package/dist/internal/schema/toArbitrary.d.ts.map +1 -1
- package/dist/internal/schema/toArbitrary.js +0 -74
- package/dist/internal/schema/toArbitrary.js.map +1 -1
- package/dist/internal/schema/toJsonSchemaDocument.js +18 -4
- package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
- package/dist/internal/schema/toRepresentation.js +45 -43
- package/dist/internal/schema/toRepresentation.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +1 -1
- package/dist/testing/TestSchema.d.ts.map +1 -1
- package/dist/testing/TestSchema.js +10 -9
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/McpSchema.d.ts +110 -110
- package/dist/unstable/ai/McpSchema.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +23 -11
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts +4 -3
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +42 -17
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Entity.d.ts +2 -2
- package/dist/unstable/cluster/Entity.d.ts.map +1 -1
- package/dist/unstable/cluster/Entity.js.map +1 -1
- package/dist/unstable/cluster/EntityProxy.d.ts +3 -3
- package/dist/unstable/cluster/EntityProxy.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxy.js +4 -3
- package/dist/unstable/cluster/EntityProxy.js.map +1 -1
- package/dist/unstable/cluster/Reply.js +4 -4
- package/dist/unstable/cluster/Reply.js.map +1 -1
- package/dist/unstable/cluster/Sharding.d.ts +2 -2
- package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
- package/dist/unstable/cluster/Sharding.js +14 -5
- package/dist/unstable/cluster/Sharding.js.map +1 -1
- package/dist/unstable/encoding/Msgpack.d.ts.map +1 -1
- package/dist/unstable/encoding/Msgpack.js +6 -6
- package/dist/unstable/encoding/Msgpack.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +6 -5
- package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +14 -12
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +3 -3
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.js +2 -3
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.js +4 -4
- package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerEncrypted.js +3 -2
- package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -1
- package/dist/unstable/http/HttpClient.d.ts +59 -3
- package/dist/unstable/http/HttpClient.d.ts.map +1 -1
- package/dist/unstable/http/HttpClient.js +33 -19
- package/dist/unstable/http/HttpClient.js.map +1 -1
- package/dist/unstable/http/HttpServerRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js +7 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/MultipartParser/internal/multipart.d.ts.map +1 -1
- package/dist/unstable/http/MultipartParser/internal/multipart.js +18 -6
- package/dist/unstable/http/MultipartParser/internal/multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +10 -10
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +9 -9
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +1 -1
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.d.ts.map +1 -1
- package/dist/unstable/reactivity/AsyncResult.js +4 -4
- package/dist/unstable/reactivity/AsyncResult.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts +26 -11
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +9 -22
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +8 -1
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +3 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +20 -16
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workers/Worker.d.ts.map +1 -1
- package/dist/unstable/workers/Worker.js +11 -12
- package/dist/unstable/workers/Worker.js.map +1 -1
- package/dist/unstable/workflow/Workflow.d.ts.map +1 -1
- package/dist/unstable/workflow/Workflow.js +2 -2
- package/dist/unstable/workflow/Workflow.js.map +1 -1
- package/package.json +5 -2
- package/src/Brand.ts +4 -4
- package/src/Config.ts +6 -4
- package/src/ConfigProvider.ts +43 -8
- package/src/Context.ts +1 -23
- package/src/Cron.ts +65 -2
- package/src/Fiber.ts +1 -1
- package/src/Function.ts +37 -0
- package/src/JsonSchema.ts +43 -42
- package/src/Optic.ts +59 -58
- package/src/Schema.ts +213 -217
- package/src/SchemaAST.ts +135 -78
- package/src/SchemaError.ts +9 -9
- package/src/SchemaGetter.ts +89 -30
- package/src/SchemaIssue.ts +285 -80
- package/src/SchemaParser.ts +51 -17
- package/src/SchemaRepresentation.ts +15 -3
- package/src/SchemaTransformation.ts +66 -18
- package/src/ScopedRef.ts +3 -1
- package/src/Stdio.ts +23 -4
- package/src/TxQueue.ts +1 -1
- package/src/internal/effect.ts +3 -6
- package/src/internal/executionPlan.ts +3 -2
- package/src/internal/rcRef.ts +24 -16
- package/src/internal/schema/fromJsonSchemaDocument.ts +19 -14
- package/src/internal/schema/schema.ts +1 -17
- package/src/internal/schema/toArbitrary.ts +0 -72
- package/src/internal/schema/toJsonSchemaDocument.ts +24 -4
- package/src/internal/schema/toRepresentation.ts +66 -48
- package/src/testing/TestSchema.ts +10 -10
- package/src/unstable/ai/McpServer.ts +23 -11
- package/src/unstable/ai/Prompt.ts +51 -19
- package/src/unstable/cluster/Entity.ts +7 -2
- package/src/unstable/cluster/EntityProxy.ts +12 -5
- package/src/unstable/cluster/Reply.ts +4 -4
- package/src/unstable/cluster/Sharding.ts +29 -17
- package/src/unstable/encoding/Msgpack.ts +12 -8
- package/src/unstable/eventlog/EventLogEncryption.ts +15 -16
- package/src/unstable/eventlog/EventLogMessage.ts +2 -3
- package/src/unstable/eventlog/EventLogRemote.ts +4 -4
- package/src/unstable/eventlog/EventLogServerEncrypted.ts +2 -2
- package/src/unstable/http/HttpClient.ts +132 -23
- package/src/unstable/http/HttpServerRequest.ts +8 -3
- package/src/unstable/http/MultipartParser/internal/multipart.ts +19 -6
- package/src/unstable/httpapi/HttpApiBuilder.ts +32 -13
- package/src/unstable/httpapi/HttpApiClient.ts +26 -8
- package/src/unstable/httpapi/OpenApi.ts +4 -1
- package/src/unstable/reactivity/AsyncResult.ts +11 -6
- package/src/unstable/reactivity/Atom.ts +44 -25
- package/src/unstable/rpc/RpcClient.ts +9 -1
- package/src/unstable/rpc/RpcServer.ts +4 -2
- package/src/unstable/sql/SqlResolver.ts +28 -20
- package/src/unstable/workers/Worker.ts +13 -14
- package/src/unstable/workflow/Workflow.ts +2 -5
package/src/SchemaParser.ts
CHANGED
|
@@ -94,6 +94,9 @@ export function makeOption<S extends Schema.Constraint>(schema: S) {
|
|
|
94
94
|
*
|
|
95
95
|
* The returned function constructs a value from constructor input and throws an
|
|
96
96
|
* `Error` with the `SchemaIssue.Issue` in its `cause` when construction fails.
|
|
97
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
98
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
99
|
+
* human-readable details are needed.
|
|
97
100
|
*
|
|
98
101
|
* **Gotchas**
|
|
99
102
|
*
|
|
@@ -115,7 +118,7 @@ export function make<S extends Schema.Constraint>(schema: S) {
|
|
|
115
118
|
exit.cause,
|
|
116
119
|
"Constructor adapter can only throw schema issues"
|
|
117
120
|
)
|
|
118
|
-
throw new Error(
|
|
121
|
+
throw new Error("Schema validation failed", { cause: issue })
|
|
119
122
|
}
|
|
120
123
|
}
|
|
121
124
|
|
|
@@ -184,6 +187,9 @@ export function _issue<T>(ast: SchemaAST.AST) {
|
|
|
184
187
|
* The assertion returns normally when validation succeeds. When the input does
|
|
185
188
|
* not satisfy the schema with a schema-only failure, it throws an `Error` with
|
|
186
189
|
* the `SchemaIssue.Issue` in its `cause`.
|
|
190
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
191
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
192
|
+
* human-readable details are needed.
|
|
187
193
|
*
|
|
188
194
|
* **Gotchas**
|
|
189
195
|
*
|
|
@@ -202,7 +208,7 @@ export function asserts<S extends Schema.Constraint, I>(schema: S, input: I): as
|
|
|
202
208
|
exit.cause,
|
|
203
209
|
"Assertion adapter can only throw schema issues"
|
|
204
210
|
)
|
|
205
|
-
throw new Error(
|
|
211
|
+
throw new Error("Schema validation failed", { cause: issue })
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
214
|
|
|
@@ -282,6 +288,9 @@ export const decodeEffect: <S extends Schema.Constraint>(
|
|
|
282
288
|
*
|
|
283
289
|
* The returned function resolves with the decoded `Type` on success and rejects
|
|
284
290
|
* with an `Error` whose cause is a `SchemaIssue.Issue` on decoding failure.
|
|
291
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
292
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
293
|
+
* human-readable details are needed.
|
|
285
294
|
*
|
|
286
295
|
* **Gotchas**
|
|
287
296
|
*
|
|
@@ -314,6 +323,9 @@ export function decodeUnknownPromise<S extends Schema.ConstraintDecoder<unknown>
|
|
|
314
323
|
*
|
|
315
324
|
* The returned function resolves with the decoded `Type` on success and rejects
|
|
316
325
|
* with an `Error` whose cause is a `SchemaIssue.Issue` on decoding failure.
|
|
326
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
327
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
328
|
+
* human-readable details are needed.
|
|
317
329
|
*
|
|
318
330
|
* **Gotchas**
|
|
319
331
|
*
|
|
@@ -492,6 +504,9 @@ export const decodeResult: <S extends Schema.ConstraintDecoder<unknown>>(
|
|
|
492
504
|
*
|
|
493
505
|
* The returned function returns the decoded `Type` on success and throws an
|
|
494
506
|
* `Error` with the `SchemaIssue.Issue` in its `cause` on decoding failure.
|
|
507
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
508
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
509
|
+
* human-readable details are needed.
|
|
495
510
|
*
|
|
496
511
|
* **Gotchas**
|
|
497
512
|
*
|
|
@@ -526,6 +541,9 @@ export function decodeUnknownSync<S extends Schema.ConstraintDecoder<unknown>>(
|
|
|
526
541
|
*
|
|
527
542
|
* The returned function returns the decoded `Type` on success and throws an
|
|
528
543
|
* `Error` with the `SchemaIssue.Issue` in its `cause` on decoding failure.
|
|
544
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
545
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
546
|
+
* human-readable details are needed.
|
|
529
547
|
*
|
|
530
548
|
* **Gotchas**
|
|
531
549
|
*
|
|
@@ -620,6 +638,9 @@ export const encodeEffect: <S extends Schema.Constraint>(
|
|
|
620
638
|
*
|
|
621
639
|
* The returned function resolves with the schema's `Encoded` value on success and
|
|
622
640
|
* rejects with an `Error` whose cause is a `SchemaIssue.Issue` on encoding failure.
|
|
641
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
642
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
643
|
+
* human-readable details are needed.
|
|
623
644
|
*
|
|
624
645
|
* **Gotchas**
|
|
625
646
|
*
|
|
@@ -651,6 +672,9 @@ export const encodeUnknownPromise = <S extends Schema.ConstraintEncoder<unknown>
|
|
|
651
672
|
*
|
|
652
673
|
* The returned function resolves with the schema's `Encoded` value on success and
|
|
653
674
|
* rejects with an `Error` whose cause is a `SchemaIssue.Issue` on encoding failure.
|
|
675
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
676
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
677
|
+
* human-readable details are needed.
|
|
654
678
|
*
|
|
655
679
|
* **Gotchas**
|
|
656
680
|
*
|
|
@@ -826,6 +850,9 @@ export const encodeResult: <S extends Schema.ConstraintEncoder<unknown>>(
|
|
|
826
850
|
*
|
|
827
851
|
* The returned function returns the schema's `Encoded` value on success and throws
|
|
828
852
|
* an `Error` with the `SchemaIssue.Issue` in its `cause` on encoding failure.
|
|
853
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
854
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
855
|
+
* human-readable details are needed.
|
|
829
856
|
*
|
|
830
857
|
* **Gotchas**
|
|
831
858
|
*
|
|
@@ -859,6 +886,9 @@ export function encodeUnknownSync<S extends Schema.ConstraintEncoder<unknown>>(
|
|
|
859
886
|
*
|
|
860
887
|
* The returned function returns the schema's `Encoded` value on success and throws
|
|
861
888
|
* an `Error` with the `SchemaIssue.Issue` in its `cause` on encoding failure.
|
|
889
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
890
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
891
|
+
* human-readable details are needed.
|
|
862
892
|
*
|
|
863
893
|
* **Gotchas**
|
|
864
894
|
*
|
|
@@ -927,7 +957,7 @@ function asPromise<T, E>(
|
|
|
927
957
|
exit.cause,
|
|
928
958
|
"Promise adapter can only reject schema issues"
|
|
929
959
|
)
|
|
930
|
-
throw new Error(
|
|
960
|
+
throw new Error("Schema validation failed", { cause: issue })
|
|
931
961
|
})
|
|
932
962
|
}
|
|
933
963
|
|
|
@@ -977,7 +1007,7 @@ function asSync<T, E>(
|
|
|
977
1007
|
return exit.value
|
|
978
1008
|
}
|
|
979
1009
|
const issue = InternalSchemaCause.getSchemaIssueOrThrow(exit.cause, "Sync adapter can only throw schema issues")
|
|
980
|
-
throw new Error(
|
|
1010
|
+
throw new Error("Schema validation failed", { cause: issue })
|
|
981
1011
|
}
|
|
982
1012
|
}
|
|
983
1013
|
|
|
@@ -1086,9 +1116,7 @@ function makeParser(
|
|
|
1086
1116
|
if (input !== InternalParser.missing && output !== InternalParser.missing) {
|
|
1087
1117
|
const issues = SchemaAST.collectIssues(encodingChecks, input, undefined, ast, options)
|
|
1088
1118
|
if (issues) {
|
|
1089
|
-
result = Effect.fail(
|
|
1090
|
-
new SchemaIssue.Composite(ast, issues)
|
|
1091
|
-
)
|
|
1119
|
+
result = Effect.fail(new SchemaIssue.Composite(ast, issues, input, options))
|
|
1092
1120
|
}
|
|
1093
1121
|
}
|
|
1094
1122
|
}
|
|
@@ -1097,9 +1125,7 @@ function makeParser(
|
|
|
1097
1125
|
if (input !== InternalParser.missing && value !== InternalParser.missing) {
|
|
1098
1126
|
const issues = SchemaAST.collectIssues(encodingChecks, input, undefined, ast, options)
|
|
1099
1127
|
if (issues) {
|
|
1100
|
-
return Effect.fail(
|
|
1101
|
-
new SchemaIssue.Composite(ast, issues)
|
|
1102
|
-
)
|
|
1128
|
+
return Effect.fail(new SchemaIssue.Composite(ast, issues, input, options))
|
|
1103
1129
|
}
|
|
1104
1130
|
}
|
|
1105
1131
|
return Effect.succeed(value)
|
|
@@ -1116,9 +1142,7 @@ function makeParser(
|
|
|
1116
1142
|
if (value === InternalParser.missing) return result
|
|
1117
1143
|
const issues = SchemaAST.collectIssues(checks, value, undefined, ast, options)
|
|
1118
1144
|
if (issues) {
|
|
1119
|
-
result = Effect.fail(
|
|
1120
|
-
new SchemaIssue.Composite(ast, issues)
|
|
1121
|
-
)
|
|
1145
|
+
result = Effect.fail(new SchemaIssue.Composite(ast, issues, value, options))
|
|
1122
1146
|
}
|
|
1123
1147
|
}
|
|
1124
1148
|
} else {
|
|
@@ -1126,9 +1150,7 @@ function makeParser(
|
|
|
1126
1150
|
if (value !== InternalParser.missing) {
|
|
1127
1151
|
const issues = SchemaAST.collectIssues(checks, value, undefined, ast, options)
|
|
1128
1152
|
if (issues) {
|
|
1129
|
-
return Effect.fail(
|
|
1130
|
-
new SchemaIssue.Composite(ast, issues)
|
|
1131
|
-
)
|
|
1153
|
+
return Effect.fail(new SchemaIssue.Composite(ast, issues, value, options))
|
|
1132
1154
|
}
|
|
1133
1155
|
}
|
|
1134
1156
|
return Effect.succeed(value)
|
|
@@ -1175,7 +1197,19 @@ function makeParser(
|
|
|
1175
1197
|
}
|
|
1176
1198
|
result = Effect.catchCause(
|
|
1177
1199
|
result,
|
|
1178
|
-
(cause) =>
|
|
1200
|
+
(cause) =>
|
|
1201
|
+
Effect.failCauseSync(() =>
|
|
1202
|
+
Cause.map(
|
|
1203
|
+
cause,
|
|
1204
|
+
(issue) =>
|
|
1205
|
+
new SchemaIssue.Encoding(
|
|
1206
|
+
ast,
|
|
1207
|
+
issue,
|
|
1208
|
+
input,
|
|
1209
|
+
options
|
|
1210
|
+
)
|
|
1211
|
+
)
|
|
1212
|
+
)
|
|
1179
1213
|
)
|
|
1180
1214
|
return Effect.flatMapEager(result, (value) => {
|
|
1181
1215
|
const local = parseLocal(value, options)
|
|
@@ -55,7 +55,13 @@ export declare namespace ToJsonSchema {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Compiles a check to a JSON Schema fragment.
|
|
59
|
+
*
|
|
60
|
+
* **Gotchas**
|
|
61
|
+
*
|
|
62
|
+
* Treat the input schemas as immutable. The returned value must be a valid JSON Schema object graph and must not be
|
|
63
|
+
* mutated after this function returns. Return a new object graph to produce different output during a later
|
|
64
|
+
* compilation.
|
|
59
65
|
*
|
|
60
66
|
* @category models
|
|
61
67
|
* @since 4.0.0
|
|
@@ -728,7 +734,10 @@ export function toMultiDocument(document: Document): MultiDocument {
|
|
|
728
734
|
*
|
|
729
735
|
* **Gotchas**
|
|
730
736
|
*
|
|
731
|
-
* Opaque declarations are represented by an unconstrained JSON Schema. Check callback results are used directly, and
|
|
737
|
+
* Opaque declarations are represented by an unconstrained JSON Schema. Check callback results are used directly, and
|
|
738
|
+
* exceptions raised by a callback pass through unchanged. Callbacks must treat their input schemas as immutable. Each
|
|
739
|
+
* returned value must be a valid JSON Schema object graph and must not be mutated after the callback returns. Local
|
|
740
|
+
* definition references returned by callbacks are resolved together with compiler-generated references.
|
|
732
741
|
*
|
|
733
742
|
* @see {@link toJsonSchemaMultiDocument} for multiple roots sharing definitions
|
|
734
743
|
*
|
|
@@ -751,7 +760,10 @@ export function toJsonSchemaDocument(
|
|
|
751
760
|
*
|
|
752
761
|
* **Gotchas**
|
|
753
762
|
*
|
|
754
|
-
* Every definition is compiled, including definitions that are not reachable from a root.
|
|
763
|
+
* Every definition is compiled, including definitions that are not reachable from a root. Check callbacks must treat
|
|
764
|
+
* their input schemas as immutable. Each returned value must be a valid JSON Schema object graph and must not be
|
|
765
|
+
* mutated after the callback returns. Local definition references returned by callbacks are resolved together with
|
|
766
|
+
* compiler-generated references.
|
|
755
767
|
*
|
|
756
768
|
* @see {@link toJsonSchemaDocument} for a single root
|
|
757
769
|
*
|
|
@@ -263,10 +263,10 @@ export const make = <T, E, RD = never, RE = never>(options: {
|
|
|
263
263
|
* Schema.decodeTo(
|
|
264
264
|
* Schema.Date,
|
|
265
265
|
* SchemaTransformation.transformOrFail({
|
|
266
|
-
* decode: (s) => {
|
|
266
|
+
* decode: (s, options) => {
|
|
267
267
|
* const d = new Date(s)
|
|
268
268
|
* return isNaN(d.getTime())
|
|
269
|
-
* ? Effect.fail(new SchemaIssue.InvalidValue({ message: "Invalid date" }))
|
|
269
|
+
* ? Effect.fail(new SchemaIssue.InvalidValue({ message: "Invalid date" }, s, options))
|
|
270
270
|
* : Effect.succeed(d)
|
|
271
271
|
* },
|
|
272
272
|
* encode: (d) => Effect.succeed(d.toISOString())
|
|
@@ -974,9 +974,16 @@ export const durationFromString: Transformation<Duration.Duration, string> = tra
|
|
|
974
974
|
Duration.Duration,
|
|
975
975
|
string
|
|
976
976
|
>({
|
|
977
|
-
decode: (s) =>
|
|
977
|
+
decode: (s, options) =>
|
|
978
978
|
Option.match(Duration.fromInput(s as Duration.Input), {
|
|
979
|
-
onNone: () =>
|
|
979
|
+
onNone: () =>
|
|
980
|
+
Effect.fail(
|
|
981
|
+
new SchemaIssue.InvalidValue(
|
|
982
|
+
{ expected: "a valid Duration string" },
|
|
983
|
+
s,
|
|
984
|
+
options
|
|
985
|
+
)
|
|
986
|
+
),
|
|
980
987
|
onSome: Effect.succeed
|
|
981
988
|
}),
|
|
982
989
|
encode: (duration) => Effect.succeed(globalThis.String(duration))
|
|
@@ -1015,11 +1022,15 @@ export const durationFromString: Transformation<Duration.Duration, string> = tra
|
|
|
1015
1022
|
*/
|
|
1016
1023
|
export const durationFromNanos: Transformation<Duration.Duration, bigint> = transformOrFail({
|
|
1017
1024
|
decode: (i) => Effect.succeed(Duration.nanos(i)),
|
|
1018
|
-
encode: (a) =>
|
|
1025
|
+
encode: (a, options) =>
|
|
1019
1026
|
Option.match(Duration.toNanos(a), {
|
|
1020
1027
|
onNone: () =>
|
|
1021
1028
|
Effect.fail(
|
|
1022
|
-
new SchemaIssue.InvalidValue(
|
|
1029
|
+
new SchemaIssue.InvalidValue(
|
|
1030
|
+
{ expected: "a Duration representable as a bigint" },
|
|
1031
|
+
a,
|
|
1032
|
+
options
|
|
1033
|
+
)
|
|
1023
1034
|
),
|
|
1024
1035
|
onSome: (nanos) => Effect.succeed(nanos)
|
|
1025
1036
|
})
|
|
@@ -1395,10 +1406,16 @@ export function optionFromOptional<T>(): Transformation<Option.Option<T>, T | un
|
|
|
1395
1406
|
* @since 4.0.0
|
|
1396
1407
|
*/
|
|
1397
1408
|
export const urlFromString: Transformation<URL, string> = transformOrFail<URL, string>({
|
|
1398
|
-
decode: (s) =>
|
|
1409
|
+
decode: (s, options) =>
|
|
1399
1410
|
URL.canParse(s)
|
|
1400
1411
|
? Effect.succeed(new URL(s))
|
|
1401
|
-
: Effect.fail(
|
|
1412
|
+
: Effect.fail(
|
|
1413
|
+
new SchemaIssue.InvalidValue(
|
|
1414
|
+
{ expected: "a valid URL string" },
|
|
1415
|
+
s,
|
|
1416
|
+
options
|
|
1417
|
+
)
|
|
1418
|
+
),
|
|
1402
1419
|
encode: (url) => Effect.succeed(url.href)
|
|
1403
1420
|
})
|
|
1404
1421
|
|
|
@@ -1424,10 +1441,16 @@ export const bigDecimalFromString: Transformation<BigDecimal.BigDecimal, string>
|
|
|
1424
1441
|
BigDecimal.BigDecimal,
|
|
1425
1442
|
string
|
|
1426
1443
|
>({
|
|
1427
|
-
decode: (s) => {
|
|
1444
|
+
decode: (s, options) => {
|
|
1428
1445
|
const result = BigDecimal.fromString(s)
|
|
1429
1446
|
return Option.isNone(result)
|
|
1430
|
-
? Effect.fail(
|
|
1447
|
+
? Effect.fail(
|
|
1448
|
+
new SchemaIssue.InvalidValue(
|
|
1449
|
+
{ expected: "a valid BigDecimal string" },
|
|
1450
|
+
s,
|
|
1451
|
+
options
|
|
1452
|
+
)
|
|
1453
|
+
)
|
|
1431
1454
|
: Effect.succeed(result.value)
|
|
1432
1455
|
},
|
|
1433
1456
|
encode: (bd) => Effect.succeed(BigDecimal.format(bd))
|
|
@@ -1784,9 +1807,16 @@ export const timeZoneNamedFromString: Transformation<DateTime.TimeZone.Named, st
|
|
|
1784
1807
|
DateTime.TimeZone.Named,
|
|
1785
1808
|
string
|
|
1786
1809
|
>({
|
|
1787
|
-
decode: (s) => {
|
|
1810
|
+
decode: (s, options) => {
|
|
1788
1811
|
return Option.match(DateTime.zoneMakeNamed(s), {
|
|
1789
|
-
onNone: () =>
|
|
1812
|
+
onNone: () =>
|
|
1813
|
+
Effect.fail(
|
|
1814
|
+
new SchemaIssue.InvalidValue(
|
|
1815
|
+
{ expected: "a valid IANA time zone" },
|
|
1816
|
+
s,
|
|
1817
|
+
options
|
|
1818
|
+
)
|
|
1819
|
+
),
|
|
1790
1820
|
onSome: Effect.succeed
|
|
1791
1821
|
})
|
|
1792
1822
|
},
|
|
@@ -1818,9 +1848,16 @@ export const timeZoneFromString: Transformation<DateTime.TimeZone, string> = tra
|
|
|
1818
1848
|
DateTime.TimeZone,
|
|
1819
1849
|
string
|
|
1820
1850
|
>({
|
|
1821
|
-
decode: (s) => {
|
|
1851
|
+
decode: (s, options) => {
|
|
1822
1852
|
return Option.match(DateTime.zoneFromString(s), {
|
|
1823
|
-
onNone: () =>
|
|
1853
|
+
onNone: () =>
|
|
1854
|
+
Effect.fail(
|
|
1855
|
+
new SchemaIssue.InvalidValue(
|
|
1856
|
+
{ expected: "a valid time zone" },
|
|
1857
|
+
s,
|
|
1858
|
+
options
|
|
1859
|
+
)
|
|
1860
|
+
),
|
|
1824
1861
|
onSome: Effect.succeed
|
|
1825
1862
|
})
|
|
1826
1863
|
},
|
|
@@ -1852,9 +1889,16 @@ export const dateTimeUtcFromString: Transformation<DateTime.Utc, string> = trans
|
|
|
1852
1889
|
DateTime.Utc,
|
|
1853
1890
|
string
|
|
1854
1891
|
>({
|
|
1855
|
-
decode: (s) => {
|
|
1892
|
+
decode: (s, options) => {
|
|
1856
1893
|
return Option.match(DateTime.make(s), {
|
|
1857
|
-
onNone: () =>
|
|
1894
|
+
onNone: () =>
|
|
1895
|
+
Effect.fail(
|
|
1896
|
+
new SchemaIssue.InvalidValue(
|
|
1897
|
+
{ expected: "a valid UTC DateTime string" },
|
|
1898
|
+
s,
|
|
1899
|
+
options
|
|
1900
|
+
)
|
|
1901
|
+
),
|
|
1858
1902
|
onSome: (result) => Effect.succeed(DateTime.toUtc(result))
|
|
1859
1903
|
})
|
|
1860
1904
|
},
|
|
@@ -1885,11 +1929,15 @@ export const dateTimeZonedFromString: Transformation<DateTime.Zoned, string> = t
|
|
|
1885
1929
|
DateTime.Zoned,
|
|
1886
1930
|
string
|
|
1887
1931
|
>({
|
|
1888
|
-
decode: (s) => {
|
|
1932
|
+
decode: (s, options) => {
|
|
1889
1933
|
return Option.match(DateTime.makeZonedFromString(s), {
|
|
1890
1934
|
onNone: () =>
|
|
1891
1935
|
Effect.fail(
|
|
1892
|
-
new SchemaIssue.InvalidValue(
|
|
1936
|
+
new SchemaIssue.InvalidValue(
|
|
1937
|
+
{ expected: "a valid Zoned DateTime string" },
|
|
1938
|
+
s,
|
|
1939
|
+
options
|
|
1940
|
+
)
|
|
1893
1941
|
),
|
|
1894
1942
|
onSome: Effect.succeed
|
|
1895
1943
|
})
|
package/src/ScopedRef.ts
CHANGED
|
@@ -219,7 +219,9 @@ export const set: {
|
|
|
219
219
|
Scope.provide(scope),
|
|
220
220
|
Effect.tapCause((cause) => Scope.close(scope, Exit.failCause(cause)))
|
|
221
221
|
)
|
|
222
|
-
yield* Scope.close(self.backing.backing.ref.current[0], Exit.void)
|
|
222
|
+
yield* Scope.close(self.backing.backing.ref.current[0], Exit.void).pipe(
|
|
223
|
+
Effect.tapCause((cause) => Scope.close(scope, Exit.failCause(cause)))
|
|
224
|
+
)
|
|
223
225
|
self.backing.backing.ref.current = [scope, value]
|
|
224
226
|
},
|
|
225
227
|
Effect.uninterruptible,
|
package/src/Stdio.ts
CHANGED
|
@@ -63,6 +63,18 @@ export const TypeId: TypeId = "~effect/Stdio"
|
|
|
63
63
|
export interface Stdio {
|
|
64
64
|
readonly [TypeId]: TypeId
|
|
65
65
|
readonly args: Effect.Effect<ReadonlyArray<string>>
|
|
66
|
+
/**
|
|
67
|
+
* Whether standard input is attached to a terminal.
|
|
68
|
+
*
|
|
69
|
+
* @since 4.0.0
|
|
70
|
+
*/
|
|
71
|
+
readonly stdinIsTerminal: Effect.Effect<boolean>
|
|
72
|
+
/**
|
|
73
|
+
* Whether standard output is attached to a terminal.
|
|
74
|
+
*
|
|
75
|
+
* @since 4.0.0
|
|
76
|
+
*/
|
|
77
|
+
readonly stdoutIsTerminal: Effect.Effect<boolean>
|
|
66
78
|
stdout(options?: {
|
|
67
79
|
readonly endOnDone?: boolean | undefined
|
|
68
80
|
}): Sink.Sink<void, string | Uint8Array, never, PlatformError>
|
|
@@ -98,16 +110,23 @@ export const Stdio: Context.Service<Stdio, Stdio> = Context.Service<Stdio>(TypeI
|
|
|
98
110
|
*
|
|
99
111
|
* **Details**
|
|
100
112
|
*
|
|
101
|
-
* The returned service reuses the supplied fields unchanged and
|
|
102
|
-
* `Stdio` type identifier
|
|
113
|
+
* The returned service reuses the supplied fields unchanged and adds the
|
|
114
|
+
* `Stdio` type identifier. Omitted terminal-detection fields default to
|
|
115
|
+
* effects that succeed with `false`.
|
|
103
116
|
*
|
|
104
117
|
* @see {@link layerTest} for a test layer with default fields that can be overridden
|
|
105
118
|
*
|
|
106
119
|
* @category constructors
|
|
107
120
|
* @since 4.0.0
|
|
108
121
|
*/
|
|
109
|
-
export const make = (
|
|
122
|
+
export const make = (
|
|
123
|
+
options:
|
|
124
|
+
& Omit<Stdio, TypeId | "stdinIsTerminal" | "stdoutIsTerminal">
|
|
125
|
+
& Partial<Pick<Stdio, "stdinIsTerminal" | "stdoutIsTerminal">>
|
|
126
|
+
): Stdio => ({
|
|
110
127
|
[TypeId]: TypeId,
|
|
128
|
+
stdinIsTerminal: Effect.succeed(false),
|
|
129
|
+
stdoutIsTerminal: Effect.succeed(false),
|
|
111
130
|
...options
|
|
112
131
|
})
|
|
113
132
|
|
|
@@ -123,7 +142,7 @@ export const make = (options: Omit<Stdio, TypeId>): Stdio => ({
|
|
|
123
142
|
*
|
|
124
143
|
* Any provided fields override defaults. By default, arguments are empty,
|
|
125
144
|
* standard output and error are draining sinks, and standard input is an empty
|
|
126
|
-
* stream
|
|
145
|
+
* stream, and terminal-detection effects succeed with `false`.
|
|
127
146
|
*
|
|
128
147
|
* @see {@link make} for constructing a `Stdio` service directly without a `Layer` or defaults
|
|
129
148
|
*
|
package/src/TxQueue.ts
CHANGED
|
@@ -1700,7 +1700,7 @@ export const clear = <A, E>(self: TxEnqueue<A, E>): Effect.Effect<Array<A>, Excl
|
|
|
1700
1700
|
*/
|
|
1701
1701
|
export const shutdown = <A, E>(self: TxEnqueue<A, E>): Effect.Effect<boolean> =>
|
|
1702
1702
|
Effect.gen(function*() {
|
|
1703
|
-
yield* Effect.
|
|
1703
|
+
yield* Effect.ignoreCause(clear(self))
|
|
1704
1704
|
return yield* interrupt(self)
|
|
1705
1705
|
}).pipe(Effect.tx)
|
|
1706
1706
|
|
package/src/internal/effect.ts
CHANGED
|
@@ -822,7 +822,7 @@ export const fiberJoin = <A, E>(self: Fiber.Fiber<A, E>): Effect.Effect<A, E> =>
|
|
|
822
822
|
/** @internal */
|
|
823
823
|
export const fiberJoinAll = <A extends Iterable<Fiber.Fiber<any, any>>>(self: A): Effect.Effect<
|
|
824
824
|
Arr.ReadonlyArray.With<A, A extends Iterable<Fiber.Fiber<infer _A, infer _E>> ? _A : never>,
|
|
825
|
-
A extends Fiber.Fiber<infer _A, infer _E
|
|
825
|
+
A extends Iterable<Fiber.Fiber<infer _A, infer _E>> ? _E : never
|
|
826
826
|
> =>
|
|
827
827
|
callback((resume) => {
|
|
828
828
|
const fibers = Array.from(self)
|
|
@@ -5862,11 +5862,8 @@ export const useSpan: {
|
|
|
5862
5862
|
return withFiber((fiber) => {
|
|
5863
5863
|
const span = makeSpanUnsafe(fiber, name, options)
|
|
5864
5864
|
const clock = fiber.getRef(ClockRef)
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
if (span.status._tag === "Ended") return
|
|
5868
|
-
span.end(clock.currentTimeNanosUnsafe(), exit)
|
|
5869
|
-
}))
|
|
5865
|
+
const timingEnabled = fiber.getRef(TracerTimingEnabled)
|
|
5866
|
+
return onExit(internalCall(() => evaluate(span)), (exit) => endSpan(span, exit, clock, timingEnabled))
|
|
5870
5867
|
})
|
|
5871
5868
|
}
|
|
5872
5869
|
|
|
@@ -31,6 +31,7 @@ export const makeEventEmitter = (
|
|
|
31
31
|
): EventEmitter => {
|
|
32
32
|
let lastStepIndex = -1
|
|
33
33
|
let stepAttempt = 0
|
|
34
|
+
const emit = (event: Api.Event<any>) => effect.ignoreCause(onEvent(event))
|
|
34
35
|
return {
|
|
35
36
|
begin: effect.clockWith((clock) =>
|
|
36
37
|
effect.suspend(() => {
|
|
@@ -47,7 +48,7 @@ export const makeEventEmitter = (
|
|
|
47
48
|
startNanos: clock.monotonicTimeNanosUnsafe()
|
|
48
49
|
}
|
|
49
50
|
return effect.as(
|
|
50
|
-
|
|
51
|
+
emit({
|
|
51
52
|
_tag: "AttemptStart",
|
|
52
53
|
attempt: state.attempt,
|
|
53
54
|
stepAttempt: state.stepAttempt,
|
|
@@ -60,7 +61,7 @@ export const makeEventEmitter = (
|
|
|
60
61
|
end: (state, exit) =>
|
|
61
62
|
effect.clockWith((clock) => {
|
|
62
63
|
const duration = Duration.nanos(clock.monotonicTimeNanosUnsafe() - state.startNanos)
|
|
63
|
-
return
|
|
64
|
+
return emit(
|
|
64
65
|
exit._tag === "Success"
|
|
65
66
|
? {
|
|
66
67
|
_tag: "AttemptSuccess",
|
package/src/internal/rcRef.ts
CHANGED
|
@@ -94,7 +94,7 @@ export const make = <A, E, R>(options: {
|
|
|
94
94
|
})
|
|
95
95
|
|
|
96
96
|
const getState = <A, E>(self: RcRefImpl<A, E>) =>
|
|
97
|
-
Effect.uninterruptibleMask((restore)
|
|
97
|
+
Effect.uninterruptibleMask(function loop(restore): Effect.Effect<State.Acquired<A>, E> {
|
|
98
98
|
switch (self.state._tag) {
|
|
99
99
|
case "Closed": {
|
|
100
100
|
return Effect.interrupt
|
|
@@ -107,22 +107,30 @@ const getState = <A, E>(self: RcRefImpl<A, E>) =>
|
|
|
107
107
|
}
|
|
108
108
|
case "Empty": {
|
|
109
109
|
const scope = Scope.makeUnsafe()
|
|
110
|
-
return self.semaphore.
|
|
111
|
-
|
|
112
|
-
self.
|
|
113
|
-
|
|
114
|
-
)).pipe(Effect.map((value) => {
|
|
115
|
-
const state: State.Acquired<A> = {
|
|
116
|
-
_tag: "Acquired",
|
|
117
|
-
value,
|
|
118
|
-
scope,
|
|
119
|
-
fiber: undefined,
|
|
120
|
-
refCount: 1,
|
|
121
|
-
invalidated: false
|
|
110
|
+
return self.semaphore.withPermit(
|
|
111
|
+
Effect.suspend(() => {
|
|
112
|
+
if (self.state._tag !== "Empty") {
|
|
113
|
+
return loop(restore)
|
|
122
114
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
return restore(Effect.provideContext(
|
|
116
|
+
self.acquire as Effect.Effect<A, E>,
|
|
117
|
+
Context.add(self.context, Scope.Scope, scope)
|
|
118
|
+
)).pipe(
|
|
119
|
+
Effect.map((value) => {
|
|
120
|
+
const state: State.Acquired<A> = {
|
|
121
|
+
_tag: "Acquired",
|
|
122
|
+
value,
|
|
123
|
+
scope,
|
|
124
|
+
fiber: undefined,
|
|
125
|
+
refCount: 1,
|
|
126
|
+
invalidated: false
|
|
127
|
+
}
|
|
128
|
+
self.state = state
|
|
129
|
+
return state
|
|
130
|
+
}),
|
|
131
|
+
Effect.onExit((exit) => Exit.isFailure(exit) ? Scope.close(scope, exit) : Effect.void)
|
|
132
|
+
)
|
|
133
|
+
})
|
|
126
134
|
)
|
|
127
135
|
}
|
|
128
136
|
}
|
|
@@ -757,23 +757,26 @@ function translateJsonSchemaMultiDocument(
|
|
|
757
757
|
case "boolean":
|
|
758
758
|
return { _tag: "Boolean", checks: [] }
|
|
759
759
|
case "array": {
|
|
760
|
+
const prefixItems = Array.isArray(schema.prefixItems) ? schema.prefixItems : undefined
|
|
760
761
|
const minItems = typeof schema.minItems === "number" ? schema.minItems : 0
|
|
761
|
-
const elements =
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
762
|
+
const elements = prefixItems?.map((element, index) => ({
|
|
763
|
+
isOptional: index + 1 > minItems,
|
|
764
|
+
type: recur(element, [...path, "prefixItems", index])
|
|
765
|
+
})) ?? []
|
|
766
|
+
const isTupleClosed = schema.items === false ||
|
|
767
|
+
(schema.items === undefined &&
|
|
768
|
+
prefixItems !== undefined &&
|
|
769
|
+
schema.maxItems === prefixItems.length)
|
|
770
|
+
const isMaxItemsRedundant = isTupleClosed &&
|
|
771
|
+
typeof schema.maxItems === "number" &&
|
|
772
|
+
schema.maxItems >= elements.length
|
|
772
773
|
return {
|
|
773
774
|
_tag: "Arrays",
|
|
774
775
|
elements,
|
|
775
|
-
rest
|
|
776
|
-
|
|
776
|
+
rest: isTupleClosed
|
|
777
|
+
? []
|
|
778
|
+
: [schema.items === undefined ? unknown : recur(schema.items, [...path, "items"])],
|
|
779
|
+
checks: collectArrayChecks(schema, isMaxItemsRedundant)
|
|
777
780
|
}
|
|
778
781
|
}
|
|
779
782
|
case "object":
|
|
@@ -808,10 +811,12 @@ function translateJsonSchemaMultiDocument(
|
|
|
808
811
|
return checks
|
|
809
812
|
}
|
|
810
813
|
|
|
811
|
-
function collectArrayChecks(schema: JsonSchema.JsonSchema): Array<Check> {
|
|
814
|
+
function collectArrayChecks(schema: JsonSchema.JsonSchema, isMaxItemsRedundant: boolean): Array<Check> {
|
|
812
815
|
const checks: Array<Check> = []
|
|
813
816
|
if (schema.prefixItems === undefined) {
|
|
814
817
|
addNumberCheck(checks, schema.minItems, "effect/schema/isMinLength", "minLength")
|
|
818
|
+
}
|
|
819
|
+
if (!isMaxItemsRedundant) {
|
|
815
820
|
addNumberCheck(checks, schema.maxItems, "effect/schema/isMaxLength", "maxLength")
|
|
816
821
|
}
|
|
817
822
|
if (schema.uniqueItems === true) {
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import * as Cause from "../../Cause.ts"
|
|
2
|
-
import * as Effect from "../../Effect.ts"
|
|
3
1
|
import * as Pipeable from "../../Pipeable.ts"
|
|
4
2
|
import type * as Schema from "../../Schema.ts"
|
|
5
3
|
import * as SchemaAST from "../../SchemaAST.ts"
|
|
6
|
-
import { SchemaError } from "../../SchemaError.ts"
|
|
7
|
-
import type { Issue } from "../../SchemaIssue.ts"
|
|
8
4
|
import * as SchemaParser from "../../SchemaParser.ts"
|
|
9
5
|
import type * as SchemaRepresentation from "../../SchemaRepresentation.ts"
|
|
10
6
|
|
|
@@ -75,20 +71,8 @@ export function make<S extends Schema.Constraint>(ast: S["ast"], options?: objec
|
|
|
75
71
|
)
|
|
76
72
|
self.ast = ast
|
|
77
73
|
self.rebuild = (ast: SchemaAST.AST) => make(ast, options)
|
|
78
|
-
|
|
79
|
-
self.makeEffect = (input: S["~type.make.in"], options?: Schema.MakeOptions) =>
|
|
80
|
-
fromIssueEffect(makeEffect(input, options))
|
|
74
|
+
self.makeEffect = SchemaParser.makeEffect(self)
|
|
81
75
|
self.make = SchemaParser.make(self)
|
|
82
76
|
self.makeOption = SchemaParser.makeOption(self)
|
|
83
77
|
return self
|
|
84
78
|
}
|
|
85
|
-
|
|
86
|
-
/** @internal */
|
|
87
|
-
export function fromIssueEffect<A, R>(
|
|
88
|
-
self: Effect.Effect<A, Issue, R>
|
|
89
|
-
): Effect.Effect<A, SchemaError, R> {
|
|
90
|
-
return Effect.catchCause(
|
|
91
|
-
self,
|
|
92
|
-
(cause) => Effect.failCauseSync(() => Cause.map(cause, (issue) => new SchemaError(issue)))
|
|
93
|
-
)
|
|
94
|
-
}
|