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/dist/Schema.js
CHANGED
|
@@ -55,7 +55,6 @@ import * as SchemaIssue from "./SchemaIssue.js";
|
|
|
55
55
|
import * as SchemaParser from "./SchemaParser.js";
|
|
56
56
|
import * as SchemaTransformation from "./SchemaTransformation.js";
|
|
57
57
|
import * as Struct_ from "./Struct.js";
|
|
58
|
-
import * as FastCheck from "./testing/FastCheck.js";
|
|
59
58
|
const TypeId = InternalSchema.TypeId;
|
|
60
59
|
/**
|
|
61
60
|
* Creates a schema for a **parametric** type (a generic container such as
|
|
@@ -81,7 +80,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
81
80
|
* **Example** (Schema for a parametric `Box<A>` type)
|
|
82
81
|
*
|
|
83
82
|
* ```ts import.meta.vitest
|
|
84
|
-
* import { Effect, Schema, SchemaIssue
|
|
83
|
+
* import { Effect, Schema, SchemaIssue, SchemaParser } from "effect"
|
|
85
84
|
*
|
|
86
85
|
* interface Box<A> {
|
|
87
86
|
* readonly value: A
|
|
@@ -96,7 +95,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
96
95
|
* ([itemCodec]) =>
|
|
97
96
|
* (u, ast, options) => {
|
|
98
97
|
* if (!isBox(u)) {
|
|
99
|
-
* return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
98
|
+
* return Effect.fail(new SchemaIssue.InvalidType(ast, u, options))
|
|
100
99
|
* }
|
|
101
100
|
* return Effect.map(
|
|
102
101
|
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
@@ -150,7 +149,7 @@ export function declareConstructor() {
|
|
|
150
149
|
* @since 3.10.0
|
|
151
150
|
*/
|
|
152
151
|
export function declare(is, annotations) {
|
|
153
|
-
return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast)), annotations);
|
|
152
|
+
return declareConstructor()([], () => (input, ast, options) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, input, options)), annotations);
|
|
154
153
|
}
|
|
155
154
|
/**
|
|
156
155
|
* Returns a schema widened to the fully-parameterized {@link Bottom} interface,
|
|
@@ -338,10 +337,12 @@ isSchemaError,
|
|
|
338
337
|
*
|
|
339
338
|
* The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
|
|
340
339
|
* every validation failure, including the path to the problematic value and
|
|
341
|
-
* the expected type or constraint.
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
340
|
+
* the expected type or constraint. Parsing with `reportInput: true` adds an
|
|
341
|
+
* enumerable `input` field to value-bearing issues created by the parser.
|
|
342
|
+
* Built-in messages may include reported input. Other issue fields and
|
|
343
|
+
* custom annotations or messages are not sanitized.
|
|
344
|
+
* `message` renders the issue tree as a human-readable string and can disclose
|
|
345
|
+
* retained input.
|
|
345
346
|
*
|
|
346
347
|
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
347
348
|
*
|
|
@@ -584,6 +585,9 @@ export const is = SchemaParser.is;
|
|
|
584
585
|
*
|
|
585
586
|
* The input is narrowed if the assertion succeeds. If schema validation fails,
|
|
586
587
|
* the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
|
|
588
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
589
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
590
|
+
* human-readable details are needed.
|
|
587
591
|
*
|
|
588
592
|
* **Gotchas**
|
|
589
593
|
*
|
|
@@ -641,9 +645,12 @@ export const asserts = SchemaParser.asserts;
|
|
|
641
645
|
export function decodeUnknownEffect(schema, options) {
|
|
642
646
|
const parser = SchemaParser.decodeUnknownEffect(schema, options);
|
|
643
647
|
return (input, options) => {
|
|
644
|
-
return
|
|
648
|
+
return fromIssueEffect(parser(input, options));
|
|
645
649
|
};
|
|
646
650
|
}
|
|
651
|
+
function fromIssueEffect(self) {
|
|
652
|
+
return Effect.catchCause(self, cause => Effect.failCauseSync(() => Cause_.map(cause, issue => new SchemaError(issue))));
|
|
653
|
+
}
|
|
647
654
|
/**
|
|
648
655
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
649
656
|
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
@@ -1050,7 +1057,7 @@ export const decodeSync = decodeUnknownSync;
|
|
|
1050
1057
|
export function encodeUnknownEffect(schema, options) {
|
|
1051
1058
|
const parser = SchemaParser.encodeUnknownEffect(schema, options);
|
|
1052
1059
|
return (input, options) => {
|
|
1053
|
-
return
|
|
1060
|
+
return fromIssueEffect(parser(input, options));
|
|
1054
1061
|
};
|
|
1055
1062
|
}
|
|
1056
1063
|
/**
|
|
@@ -1467,7 +1474,12 @@ export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
|
1467
1474
|
* @category combinators
|
|
1468
1475
|
* @since 3.10.0
|
|
1469
1476
|
*/
|
|
1470
|
-
export const optional = /*#__PURE__*/Struct_.lambda(self =>
|
|
1477
|
+
export const optional = /*#__PURE__*/Struct_.lambda(self => {
|
|
1478
|
+
const schema = UndefinedOr(self);
|
|
1479
|
+
return make(SchemaAST.optional(self.ast), {
|
|
1480
|
+
schema
|
|
1481
|
+
});
|
|
1482
|
+
});
|
|
1471
1483
|
/**
|
|
1472
1484
|
* Reverses `optional` and returns the inner schema.
|
|
1473
1485
|
*
|
|
@@ -2657,7 +2669,7 @@ export function decodeTo(to, transformation) {
|
|
|
2657
2669
|
* ```
|
|
2658
2670
|
*
|
|
2659
2671
|
* @category transforming
|
|
2660
|
-
* @since
|
|
2672
|
+
* @since 4.0.0
|
|
2661
2673
|
*/
|
|
2662
2674
|
export function decode(transformation) {
|
|
2663
2675
|
return self => {
|
|
@@ -2693,7 +2705,7 @@ export function encodeTo(to, transformation) {
|
|
|
2693
2705
|
* ```
|
|
2694
2706
|
*
|
|
2695
2707
|
* @category transforming
|
|
2696
|
-
* @since
|
|
2708
|
+
* @since 4.0.0
|
|
2697
2709
|
*/
|
|
2698
2710
|
export function encode(transformation) {
|
|
2699
2711
|
return self => {
|
|
@@ -2706,7 +2718,7 @@ export function encode(transformation) {
|
|
|
2706
2718
|
* **Details**
|
|
2707
2719
|
*
|
|
2708
2720
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
2709
|
-
* encoding.
|
|
2721
|
+
* encoding. Failures are represented directly as `SchemaIssue.Issue` values.
|
|
2710
2722
|
*
|
|
2711
2723
|
* **Example** (Defining an optional field with a static default)
|
|
2712
2724
|
*
|
|
@@ -2730,7 +2742,7 @@ export function withConstructorDefault(
|
|
|
2730
2742
|
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
2731
2743
|
// it makes easier to define the default value if there are nested defaults
|
|
2732
2744
|
defaultValue) {
|
|
2733
|
-
return schema => make(SchemaAST.withConstructorDefault(schema.ast,
|
|
2745
|
+
return schema => make(SchemaAST.withConstructorDefault(schema.ast, defaultValue), {
|
|
2734
2746
|
schema
|
|
2735
2747
|
});
|
|
2736
2748
|
}
|
|
@@ -5903,7 +5915,7 @@ export function isPropertyNames(keySchema, annotations) {
|
|
|
5903
5915
|
}
|
|
5904
5916
|
}
|
|
5905
5917
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
5906
|
-
return new SchemaIssue.Composite(ast, issues);
|
|
5918
|
+
return new SchemaIssue.Composite(ast, issues, input, options);
|
|
5907
5919
|
}
|
|
5908
5920
|
return true;
|
|
5909
5921
|
}, {
|
|
@@ -6037,10 +6049,10 @@ export function Option(value) {
|
|
|
6037
6049
|
}
|
|
6038
6050
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
|
|
6039
6051
|
onSuccess: Option_.some,
|
|
6040
|
-
onFailure: issue =>
|
|
6052
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
6041
6053
|
});
|
|
6042
6054
|
}
|
|
6043
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6055
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6044
6056
|
}, {
|
|
6045
6057
|
representation: {
|
|
6046
6058
|
id: "effect/schema/Option",
|
|
@@ -6208,18 +6220,18 @@ export function OptionFromOptionalNullOr(schema, options) {
|
|
|
6208
6220
|
export function Result(success, failure) {
|
|
6209
6221
|
const schema = declareConstructor()([success, failure], ([success, failure]) => (input, ast, options) => {
|
|
6210
6222
|
if (!Result_.isResult(input)) {
|
|
6211
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6223
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6212
6224
|
}
|
|
6213
6225
|
switch (input._tag) {
|
|
6214
6226
|
case "Success":
|
|
6215
6227
|
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
6216
6228
|
onSuccess: Result_.succeed,
|
|
6217
|
-
onFailure: issue =>
|
|
6229
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "success", issue, input, options)
|
|
6218
6230
|
});
|
|
6219
6231
|
case "Failure":
|
|
6220
6232
|
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
6221
6233
|
onSuccess: Result_.fail,
|
|
6222
|
-
onFailure: issue =>
|
|
6234
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "failure", issue, input, options)
|
|
6223
6235
|
});
|
|
6224
6236
|
}
|
|
6225
6237
|
}, {
|
|
@@ -6340,11 +6352,11 @@ export function Redacted(value, options) {
|
|
|
6340
6352
|
onSuccess: () => input,
|
|
6341
6353
|
onFailure: (/** ignore the issue because of security reasons */
|
|
6342
6354
|
) => {
|
|
6343
|
-
return new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue())]);
|
|
6355
|
+
return new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue(undefined, input, poptions))], input, poptions);
|
|
6344
6356
|
}
|
|
6345
6357
|
}));
|
|
6346
6358
|
}
|
|
6347
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6359
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions));
|
|
6348
6360
|
}, {
|
|
6349
6361
|
representation: {
|
|
6350
6362
|
id: "effect/schema/Redacted",
|
|
@@ -6442,18 +6454,18 @@ export function RedactedFromValue(value, options) {
|
|
|
6442
6454
|
export function CauseReason(error, defect) {
|
|
6443
6455
|
const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
|
|
6444
6456
|
if (!Cause_.isReason(input)) {
|
|
6445
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6457
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6446
6458
|
}
|
|
6447
6459
|
switch (input._tag) {
|
|
6448
6460
|
case "Fail":
|
|
6449
6461
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(error)(input.error, options), {
|
|
6450
6462
|
onSuccess: Cause_.makeFailReason,
|
|
6451
|
-
onFailure: issue =>
|
|
6463
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "error", issue, input, options)
|
|
6452
6464
|
});
|
|
6453
6465
|
case "Die":
|
|
6454
6466
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(defect)(input.defect, options), {
|
|
6455
6467
|
onSuccess: Cause_.makeDieReason,
|
|
6456
|
-
onFailure: issue =>
|
|
6468
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "defect", issue, input, options)
|
|
6457
6469
|
});
|
|
6458
6470
|
case "Interrupt":
|
|
6459
6471
|
return Effect.succeed(input);
|
|
@@ -6581,11 +6593,11 @@ export function Cause(error, defect) {
|
|
|
6581
6593
|
const failures = ArraySchema(CauseReason(error, defect));
|
|
6582
6594
|
return (input, ast, options) => {
|
|
6583
6595
|
if (!Cause_.isCause(input)) {
|
|
6584
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6596
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6585
6597
|
}
|
|
6586
6598
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
6587
6599
|
onSuccess: Cause_.fromReasons,
|
|
6588
|
-
onFailure: issue =>
|
|
6600
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
|
|
6589
6601
|
});
|
|
6590
6602
|
};
|
|
6591
6603
|
}, {
|
|
@@ -6806,18 +6818,18 @@ export function Exit(value, error, defect) {
|
|
|
6806
6818
|
const cause = Cause(error, defect);
|
|
6807
6819
|
return (input, ast, options) => {
|
|
6808
6820
|
if (!Exit_.isExit(input)) {
|
|
6809
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6821
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6810
6822
|
}
|
|
6811
6823
|
switch (input._tag) {
|
|
6812
6824
|
case "Success":
|
|
6813
6825
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
|
|
6814
6826
|
onSuccess: Exit_.succeed,
|
|
6815
|
-
onFailure: issue =>
|
|
6827
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
6816
6828
|
});
|
|
6817
6829
|
case "Failure":
|
|
6818
6830
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(cause)(input.cause, options), {
|
|
6819
6831
|
onSuccess: Exit_.failCause,
|
|
6820
|
-
onFailure: issue =>
|
|
6832
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
|
|
6821
6833
|
});
|
|
6822
6834
|
}
|
|
6823
6835
|
};
|
|
@@ -6961,10 +6973,10 @@ export function ReadonlyMap(key, value) {
|
|
|
6961
6973
|
if (input instanceof globalThis.Map) {
|
|
6962
6974
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
|
|
6963
6975
|
onSuccess: array => new globalThis.Map(array),
|
|
6964
|
-
onFailure: issue =>
|
|
6976
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
6965
6977
|
});
|
|
6966
6978
|
}
|
|
6967
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6979
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6968
6980
|
};
|
|
6969
6981
|
}, {
|
|
6970
6982
|
representation: {
|
|
@@ -7030,10 +7042,10 @@ export function HashMap(key, value) {
|
|
|
7030
7042
|
if (HashMap_.isHashMap(input)) {
|
|
7031
7043
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
|
|
7032
7044
|
onSuccess: HashMap_.fromIterable,
|
|
7033
|
-
onFailure: issue =>
|
|
7045
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
7034
7046
|
});
|
|
7035
7047
|
}
|
|
7036
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7048
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7037
7049
|
};
|
|
7038
7050
|
}, {
|
|
7039
7051
|
representation: {
|
|
@@ -7100,10 +7112,10 @@ export function ReadonlySet(value) {
|
|
|
7100
7112
|
if (input instanceof globalThis.Set) {
|
|
7101
7113
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
|
|
7102
7114
|
onSuccess: array => new globalThis.Set(array),
|
|
7103
|
-
onFailure: issue =>
|
|
7115
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
7104
7116
|
});
|
|
7105
7117
|
}
|
|
7106
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7118
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7107
7119
|
};
|
|
7108
7120
|
}, {
|
|
7109
7121
|
representation: {
|
|
@@ -7168,10 +7180,10 @@ export function HashSet(value) {
|
|
|
7168
7180
|
if (HashSet_.isHashSet(input)) {
|
|
7169
7181
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
7170
7182
|
onSuccess: HashSet_.fromIterable,
|
|
7171
|
-
onFailure: issue =>
|
|
7183
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
7172
7184
|
});
|
|
7173
7185
|
}
|
|
7174
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7186
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7175
7187
|
};
|
|
7176
7188
|
}, {
|
|
7177
7189
|
representation: {
|
|
@@ -7236,10 +7248,10 @@ export function Chunk(value) {
|
|
|
7236
7248
|
if (Chunk_.isChunk(input)) {
|
|
7237
7249
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
7238
7250
|
onSuccess: Chunk_.fromIterable,
|
|
7239
|
-
onFailure: issue =>
|
|
7251
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
7240
7252
|
});
|
|
7241
7253
|
}
|
|
7242
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7254
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7243
7255
|
};
|
|
7244
7256
|
}, {
|
|
7245
7257
|
representation: {
|
|
@@ -7315,11 +7327,11 @@ export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
|
|
|
7315
7327
|
source: String,
|
|
7316
7328
|
flags: String
|
|
7317
7329
|
}), SchemaTransformation.transformOrFail({
|
|
7318
|
-
decode: e => Effect.try({
|
|
7330
|
+
decode: (e, options) => Effect.try({
|
|
7319
7331
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
7320
7332
|
catch: () => new SchemaIssue.InvalidValue({
|
|
7321
|
-
|
|
7322
|
-
})
|
|
7333
|
+
expected: "valid RegExp source and flags"
|
|
7334
|
+
}, e, options)
|
|
7323
7335
|
}),
|
|
7324
7336
|
encode: regExp => Effect.succeed({
|
|
7325
7337
|
source: regExp.source,
|
|
@@ -7894,10 +7906,10 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
7894
7906
|
name: String,
|
|
7895
7907
|
lastModified: Int
|
|
7896
7908
|
}), SchemaTransformation.transformOrFail({
|
|
7897
|
-
decode: e => Result_.match(Encoding.decodeBase64(e.data), {
|
|
7909
|
+
decode: (e, options) => Result_.match(Encoding.decodeBase64(e.data), {
|
|
7898
7910
|
onFailure: () => Effect.fail(new SchemaIssue.InvalidValue({
|
|
7899
|
-
|
|
7900
|
-
})),
|
|
7911
|
+
expected: "a valid Base64 string"
|
|
7912
|
+
}, e.data, options)),
|
|
7901
7913
|
onSuccess: bytes => {
|
|
7902
7914
|
const buffer = new globalThis.Uint8Array(bytes);
|
|
7903
7915
|
return Effect.succeed(new globalThis.File([buffer], e.name, {
|
|
@@ -7906,7 +7918,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
7906
7918
|
}));
|
|
7907
7919
|
}
|
|
7908
7920
|
}),
|
|
7909
|
-
encode: file => Effect.tryPromise({
|
|
7921
|
+
encode: (file, options) => Effect.tryPromise({
|
|
7910
7922
|
try: async () => {
|
|
7911
7923
|
const bytes = new globalThis.Uint8Array(await file.arrayBuffer());
|
|
7912
7924
|
return {
|
|
@@ -7917,8 +7929,8 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
7917
7929
|
};
|
|
7918
7930
|
},
|
|
7919
7931
|
catch: () => new SchemaIssue.InvalidValue({
|
|
7920
|
-
|
|
7921
|
-
})
|
|
7932
|
+
expected: "a readable File"
|
|
7933
|
+
}, file, options)
|
|
7922
7934
|
})
|
|
7923
7935
|
}))
|
|
7924
7936
|
});
|
|
@@ -8988,8 +9000,8 @@ function getClassSchemaFactory(from, identifier, annotations) {
|
|
|
8988
9000
|
const ClassTypeId = getClassTypeId(identifier);
|
|
8989
9001
|
const isClassValue = input => input instanceof self || Predicate.hasProperty(input, ClassTypeId);
|
|
8990
9002
|
const transformation = getClassTransformation(self);
|
|
8991
|
-
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
|
|
8992
|
-
return isClassValue(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
9003
|
+
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast, options) => {
|
|
9004
|
+
return isClassValue(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
8993
9005
|
}, {
|
|
8994
9006
|
identifier,
|
|
8995
9007
|
[InternalAnnotations.CONSTRUCTOR_ANNOTATION_KEY]: ([from]) => ({
|
|
@@ -9013,8 +9025,8 @@ function isStruct(schema) {
|
|
|
9013
9025
|
}
|
|
9014
9026
|
/**
|
|
9015
9027
|
* Creates a schema-backed class whose constructor validates input against a
|
|
9016
|
-
* {@link Struct} schema. Construction throws
|
|
9017
|
-
* input.
|
|
9028
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
9029
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
9018
9030
|
*
|
|
9019
9031
|
* **When to use**
|
|
9020
9032
|
*
|
|
@@ -9204,35 +9216,41 @@ export const TaggedError = identifier => {
|
|
|
9204
9216
|
};
|
|
9205
9217
|
};
|
|
9206
9218
|
/**
|
|
9207
|
-
*
|
|
9208
|
-
*
|
|
9219
|
+
* Returns an {@link Arbitrary} factory derived from a schema. The generated
|
|
9220
|
+
* values satisfy the schema and use its decoded `Type`.
|
|
9221
|
+
*
|
|
9222
|
+
* **When to use**
|
|
9223
|
+
*
|
|
9224
|
+
* Use when you need a fast-check generator for values accepted by a schema.
|
|
9209
9225
|
*
|
|
9210
9226
|
* **Details**
|
|
9211
9227
|
*
|
|
9212
|
-
*
|
|
9213
|
-
*
|
|
9214
|
-
*
|
|
9215
|
-
*
|
|
9228
|
+
* Constraints refine base generators; candidates add weighted sources while
|
|
9229
|
+
* filters still validate every value. Recursive schemas use terminal branches
|
|
9230
|
+
* and fail when no finite terminal path exists. The result is memoized so
|
|
9231
|
+
* repeated calls with the same schema are cheap.
|
|
9232
|
+
*
|
|
9233
|
+
* **Example** (Generating arbitrary values)
|
|
9234
|
+
*
|
|
9235
|
+
* ```ts import.meta.vitest
|
|
9236
|
+
* import { Schema } from "effect"
|
|
9237
|
+
* import * as FastCheck from "fast-check"
|
|
9238
|
+
*
|
|
9239
|
+
* const makePersonArbitrary = Schema.toArbitrary(
|
|
9240
|
+
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
9241
|
+
* )
|
|
9242
|
+
*
|
|
9243
|
+
* const PersonArbitrary = makePersonArbitrary(FastCheck)
|
|
9244
|
+
* FastCheck.sample(PersonArbitrary, 1)
|
|
9245
|
+
* ```
|
|
9216
9246
|
*
|
|
9217
9247
|
* @category generators
|
|
9218
9248
|
* @since 4.0.0
|
|
9219
9249
|
*/
|
|
9220
|
-
export function
|
|
9250
|
+
export function toArbitrary(schema) {
|
|
9221
9251
|
const lawc = InternalArbitrary.memoized(schema.ast);
|
|
9222
9252
|
return fc => lawc(fc, {});
|
|
9223
9253
|
}
|
|
9224
|
-
export function toArbitrary(schema, options) {
|
|
9225
|
-
if (options?.report === true) {
|
|
9226
|
-
const lawc = InternalArbitrary.memoized(schema.ast);
|
|
9227
|
-
const report = InternalArbitrary.makeReport();
|
|
9228
|
-
InternalArbitrary.collectReport(schema.ast, report);
|
|
9229
|
-
return {
|
|
9230
|
-
value: lawc(FastCheck, {}),
|
|
9231
|
-
report: InternalArbitrary.toReport(report)
|
|
9232
|
-
};
|
|
9233
|
-
}
|
|
9234
|
-
return toArbitraryLazy(schema)(FastCheck);
|
|
9235
|
-
}
|
|
9236
9254
|
// -----------------------------------------------------------------------------
|
|
9237
9255
|
// Formatter
|
|
9238
9256
|
// -----------------------------------------------------------------------------
|
|
@@ -9480,7 +9498,7 @@ export function toRepresentation(schema) {
|
|
|
9480
9498
|
* @since 4.0.0
|
|
9481
9499
|
*/
|
|
9482
9500
|
export function toJsonSchemaDocument(schema, options) {
|
|
9483
|
-
const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast));
|
|
9501
|
+
const document = InternalToRepresentation.toRepresentation(toCodecJsonAST(schema.ast), InternalToJsonSchemaDocument.toRepresentationOptions);
|
|
9484
9502
|
return InternalToJsonSchemaDocument.toJsonSchemaDocument(document, options);
|
|
9485
9503
|
}
|
|
9486
9504
|
/**
|
|
@@ -9503,14 +9521,13 @@ export function toCodecJson(schema) {
|
|
|
9503
9521
|
schema
|
|
9504
9522
|
});
|
|
9505
9523
|
}
|
|
9506
|
-
|
|
9507
|
-
|
|
9524
|
+
/** @internal */
|
|
9525
|
+
export const toCodecJsonAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
|
|
9526
|
+
const out = toCodecJsonASTStep(ast, toCodecJsonAST);
|
|
9508
9527
|
const context = ast.context;
|
|
9509
9528
|
if (out === ast || context === undefined) return out;
|
|
9510
9529
|
return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(context));
|
|
9511
9530
|
});
|
|
9512
|
-
/** @internal */
|
|
9513
|
-
export const toCodecJsonAST = /*#__PURE__*/memoize(toCodecJsonASTBase);
|
|
9514
9531
|
function withoutConstructorDefault(context) {
|
|
9515
9532
|
return context.constructorDefault === undefined ? context : new SchemaAST.Context(context.isOptional, context.isMutable, undefined, context.annotations);
|
|
9516
9533
|
}
|
|
@@ -9554,7 +9571,7 @@ const toCodecJsonReorder = /*#__PURE__*/makeReorder(ast => {
|
|
|
9554
9571
|
return 1;
|
|
9555
9572
|
}
|
|
9556
9573
|
});
|
|
9557
|
-
function
|
|
9574
|
+
function toCodecJsonASTStep(ast, recur) {
|
|
9558
9575
|
switch (ast._tag) {
|
|
9559
9576
|
case "Declaration":
|
|
9560
9577
|
{
|
|
@@ -9607,13 +9624,13 @@ function toCodecJsonBase(ast, recur) {
|
|
|
9607
9624
|
* @since 4.0.0
|
|
9608
9625
|
*/
|
|
9609
9626
|
export function toCodecIso(schema) {
|
|
9610
|
-
return make(
|
|
9627
|
+
return make(toCodecIsoAST(SchemaAST.toType(schema.ast)));
|
|
9611
9628
|
}
|
|
9612
|
-
const
|
|
9613
|
-
const out =
|
|
9629
|
+
const toCodecIsoAST = /*#__PURE__*/memoize(ast => {
|
|
9630
|
+
const out = toCodecIsoASTStep(ast, toCodecIsoAST);
|
|
9614
9631
|
return out !== ast && ast.context !== undefined ? SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context)) : out;
|
|
9615
9632
|
});
|
|
9616
|
-
function
|
|
9633
|
+
function toCodecIsoASTStep(ast, recur) {
|
|
9617
9634
|
switch (ast._tag) {
|
|
9618
9635
|
case "Declaration":
|
|
9619
9636
|
{
|
|
@@ -9646,7 +9663,7 @@ function toCodecIsoBase(ast, recur) {
|
|
|
9646
9663
|
* @since 4.0.0
|
|
9647
9664
|
*/
|
|
9648
9665
|
export function toCodecStringTree(schema) {
|
|
9649
|
-
return make(
|
|
9666
|
+
return make(toCodecStringTreeAST(schema.ast), {
|
|
9650
9667
|
schema
|
|
9651
9668
|
});
|
|
9652
9669
|
}
|
|
@@ -9669,7 +9686,7 @@ export function toCodecStringTree(schema) {
|
|
|
9669
9686
|
* @since 4.0.0
|
|
9670
9687
|
*/
|
|
9671
9688
|
export function toCodecArrayFromSingle(schema) {
|
|
9672
|
-
return make(
|
|
9689
|
+
return make(toCodecArrayFromSingleAST(schema.ast));
|
|
9673
9690
|
}
|
|
9674
9691
|
/**
|
|
9675
9692
|
* Derives an XML encoder from a codec.
|
|
@@ -9793,7 +9810,7 @@ const toStringTreeReorder = /*#__PURE__*/makeReorder(ast => {
|
|
|
9793
9810
|
return 1;
|
|
9794
9811
|
}
|
|
9795
9812
|
});
|
|
9796
|
-
function
|
|
9813
|
+
function toCodecStringTreeASTStep(ast, recur, onMissingAnnotation) {
|
|
9797
9814
|
switch (ast._tag) {
|
|
9798
9815
|
case "Declaration":
|
|
9799
9816
|
{
|
|
@@ -9846,13 +9863,10 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
9846
9863
|
}
|
|
9847
9864
|
const nullToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Literal("null"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(() => null), /*#__PURE__*/SchemaGetter.transform(() => "null")));
|
|
9848
9865
|
const booleanToString = /*#__PURE__*/new SchemaAST.Link(/*#__PURE__*/new SchemaAST.Union([/*#__PURE__*/new SchemaAST.Literal("true"), /*#__PURE__*/new SchemaAST.Literal("false")], "anyOf"), /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(s => s === "true"), /*#__PURE__*/SchemaGetter.String()));
|
|
9849
|
-
const
|
|
9850
|
-
const
|
|
9851
|
-
const
|
|
9852
|
-
|
|
9853
|
-
return ast;
|
|
9854
|
-
}
|
|
9855
|
-
const out = serializerTree(ast, serializerStringTree, ast => {
|
|
9866
|
+
const arrayFromSingleTransformation = /*#__PURE__*/new SchemaTransformation.Transformation(/*#__PURE__*/SchemaGetter.transform(input => typeof input === "string" ? [input] : input), /*#__PURE__*/SchemaGetter.passthrough());
|
|
9867
|
+
const isCodecArrayFromSingleLink = link => link.transformation === arrayFromSingleTransformation;
|
|
9868
|
+
const toCodecStringTreeAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
|
|
9869
|
+
const out = toCodecStringTreeASTStep(ast, toCodecStringTreeAST, ast => {
|
|
9856
9870
|
throw new globalThis.Error("Missing structural codec for StringTree", {
|
|
9857
9871
|
cause: ast
|
|
9858
9872
|
});
|
|
@@ -9861,24 +9875,22 @@ const serializerStringTree = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodin
|
|
|
9861
9875
|
return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context));
|
|
9862
9876
|
}
|
|
9863
9877
|
return out;
|
|
9878
|
+
}, {
|
|
9879
|
+
stopAt: isCodecArrayFromSingleLink
|
|
9864
9880
|
});
|
|
9865
9881
|
const toArrayFromSingleInputElement = ast => SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown;
|
|
9866
|
-
const
|
|
9867
|
-
const
|
|
9868
|
-
if (isSerializerArrayFromSingle(ast)) {
|
|
9869
|
-
return ast;
|
|
9870
|
-
}
|
|
9871
|
-
const out = onSerializerArrayFromSingle(ast);
|
|
9882
|
+
const toCodecArrayFromSingleAST = /*#__PURE__*/SchemaAST.applyToSelfOrLastLinkEncodingIdempotent(ast => {
|
|
9883
|
+
const out = toCodecArrayFromSingleASTStep(ast);
|
|
9872
9884
|
if (SchemaAST.isArrays(out)) {
|
|
9873
|
-
const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf",
|
|
9874
|
-
[SERIALIZER_ENSURE_ARRAY]: true
|
|
9875
|
-
}), out, arrayFromSingleTransformation);
|
|
9885
|
+
const ensure = SchemaAST.decodeTo(new SchemaAST.Union([new SchemaAST.Arrays(out.isMutable, out.elements.map(toArrayFromSingleInputElement), out.rest.map(toArrayFromSingleInputElement)), SchemaAST.string], "anyOf"), out, arrayFromSingleTransformation);
|
|
9876
9886
|
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure;
|
|
9877
9887
|
}
|
|
9878
9888
|
return out;
|
|
9889
|
+
}, {
|
|
9890
|
+
stopAt: isCodecArrayFromSingleLink
|
|
9879
9891
|
});
|
|
9880
|
-
function
|
|
9881
|
-
return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(
|
|
9892
|
+
function toCodecArrayFromSingleASTStep(ast) {
|
|
9893
|
+
return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" || ast._tag === "Suspend" ? ast.recur(toCodecArrayFromSingleAST) : ast;
|
|
9882
9894
|
}
|
|
9883
9895
|
/**
|
|
9884
9896
|
* Reviver for persisted `isGreaterThanDate` checks.
|
|
@@ -10073,6 +10085,18 @@ export const isBetweenBigIntReviver = /*#__PURE__*/InternalSchema.makeFilterRevi
|
|
|
10073
10085
|
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
10074
10086
|
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
10075
10087
|
*
|
|
10088
|
+
* **Details**
|
|
10089
|
+
*
|
|
10090
|
+
* Reading through the `Iso` encodes the schema value, while replacing through
|
|
10091
|
+
* it decodes the new focus.
|
|
10092
|
+
*
|
|
10093
|
+
* **Gotchas**
|
|
10094
|
+
*
|
|
10095
|
+
* Either direction can throw an `Error` with the generic message
|
|
10096
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
10097
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
10098
|
+
* human-readable details are needed.
|
|
10099
|
+
*
|
|
10076
10100
|
* @category converting
|
|
10077
10101
|
* @since 4.0.0
|
|
10078
10102
|
*/
|
|
@@ -10132,6 +10156,19 @@ export function overrideToCodecIso(to, transformation) {
|
|
|
10132
10156
|
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
10133
10157
|
* and new values, and can apply patches back to the typed value.
|
|
10134
10158
|
*
|
|
10159
|
+
* **Details**
|
|
10160
|
+
*
|
|
10161
|
+
* `diff` encodes both values before computing the patch. `patch` encodes the old
|
|
10162
|
+
* value, applies the patch to its JSON representation, and decodes the result.
|
|
10163
|
+
*
|
|
10164
|
+
* **Gotchas**
|
|
10165
|
+
*
|
|
10166
|
+
* Schema encoding or decoding failures throw an `Error` with the generic message
|
|
10167
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
10168
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
10169
|
+
* human-readable details are needed. Errors produced by {@link JsonPatch.apply}
|
|
10170
|
+
* for invalid patch operations are separate from schema validation failures.
|
|
10171
|
+
*
|
|
10135
10172
|
* @category converting
|
|
10136
10173
|
* @since 4.0.0
|
|
10137
10174
|
*/
|