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/Schema.ts
CHANGED
|
@@ -63,7 +63,7 @@ import type * as SchemaRepresentation from "./SchemaRepresentation.ts"
|
|
|
63
63
|
import * as SchemaTransformation from "./SchemaTransformation.ts"
|
|
64
64
|
import type { Assign, Lambda, Mutable, Simplify } from "./Struct.ts"
|
|
65
65
|
import * as Struct_ from "./Struct.ts"
|
|
66
|
-
import * as FastCheck from "./testing/FastCheck.ts"
|
|
66
|
+
import type * as FastCheck from "./testing/FastCheck.ts"
|
|
67
67
|
import type { RequiredKeys, UnionToIntersection } from "./Types.ts"
|
|
68
68
|
import type { Unify } from "./Unify.ts"
|
|
69
69
|
|
|
@@ -203,7 +203,9 @@ export interface BottomWithoutNew<
|
|
|
203
203
|
* **Gotchas**
|
|
204
204
|
*
|
|
205
205
|
* Throws an `Error` with the schema issue in its `cause` when validation
|
|
206
|
-
* fails.
|
|
206
|
+
* fails. Schema validation failures use the generic message
|
|
207
|
+
* `"Schema validation failed"`; format the `cause` explicitly with
|
|
208
|
+
* `SchemaIssue.makeFormatterDefault()` when human-readable details are needed.
|
|
207
209
|
* Causes that contain defects, interruptions, or other non-schema reasons
|
|
208
210
|
* throw with the underlying `Cause` attached instead.
|
|
209
211
|
*
|
|
@@ -244,10 +246,15 @@ export interface BottomWithoutNew<
|
|
|
244
246
|
* Use when constructor input may fail validation and you want to
|
|
245
247
|
* compose that failure with other `Effect` operations instead of throwing.
|
|
246
248
|
*
|
|
249
|
+
* **Details**
|
|
250
|
+
*
|
|
251
|
+
* Validation failures are returned directly as `SchemaIssue.Issue` values
|
|
252
|
+
* and are not wrapped in `SchemaError`.
|
|
253
|
+
*
|
|
247
254
|
* @see {@link BottomWithoutNew.make} — construct synchronously when validation failure should throw
|
|
248
255
|
* @see {@link BottomWithoutNew.makeOption} — construct synchronously and discard validation details
|
|
249
256
|
*/
|
|
250
|
-
makeEffect(input: this["~type.make.in"], options?: MakeOptions): Effect.Effect<this["Type"],
|
|
257
|
+
makeEffect(input: this["~type.make.in"], options?: MakeOptions): Effect.Effect<this["Type"], SchemaIssue.Issue>
|
|
251
258
|
}
|
|
252
259
|
|
|
253
260
|
/**
|
|
@@ -449,7 +456,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<C
|
|
|
449
456
|
* **Example** (Schema for a parametric `Box<A>` type)
|
|
450
457
|
*
|
|
451
458
|
* ```ts import.meta.vitest
|
|
452
|
-
* import { Effect, Schema, SchemaIssue
|
|
459
|
+
* import { Effect, Schema, SchemaIssue, SchemaParser } from "effect"
|
|
453
460
|
*
|
|
454
461
|
* interface Box<A> {
|
|
455
462
|
* readonly value: A
|
|
@@ -464,7 +471,7 @@ export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<C
|
|
|
464
471
|
* ([itemCodec]) =>
|
|
465
472
|
* (u, ast, options) => {
|
|
466
473
|
* if (!isBox(u)) {
|
|
467
|
-
* return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
474
|
+
* return Effect.fail(new SchemaIssue.InvalidType(ast, u, options))
|
|
468
475
|
* }
|
|
469
476
|
* return Effect.map(
|
|
470
477
|
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
@@ -552,10 +559,10 @@ export function declare<T, Iso = T>(
|
|
|
552
559
|
): declare<T, Iso> {
|
|
553
560
|
return declareConstructor<T, T, Iso>()(
|
|
554
561
|
[],
|
|
555
|
-
() => (input, ast) =>
|
|
562
|
+
() => (input, ast, options) =>
|
|
556
563
|
is(input) ?
|
|
557
564
|
Effect.succeed(input) :
|
|
558
|
-
Effect.fail(new SchemaIssue.InvalidType(ast)),
|
|
565
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options)),
|
|
559
566
|
annotations
|
|
560
567
|
)
|
|
561
568
|
}
|
|
@@ -1161,10 +1168,12 @@ export {
|
|
|
1161
1168
|
*
|
|
1162
1169
|
* The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
|
|
1163
1170
|
* every validation failure, including the path to the problematic value and
|
|
1164
|
-
* the expected type or constraint.
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1167
|
-
*
|
|
1171
|
+
* the expected type or constraint. Parsing with `reportInput: true` adds an
|
|
1172
|
+
* enumerable `input` field to value-bearing issues created by the parser.
|
|
1173
|
+
* Built-in messages may include reported input. Other issue fields and
|
|
1174
|
+
* custom annotations or messages are not sanitized.
|
|
1175
|
+
* `message` renders the issue tree as a human-readable string and can disclose
|
|
1176
|
+
* retained input.
|
|
1168
1177
|
*
|
|
1169
1178
|
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
1170
1179
|
*
|
|
@@ -1416,6 +1425,9 @@ export const is = SchemaParser.is
|
|
|
1416
1425
|
*
|
|
1417
1426
|
* The input is narrowed if the assertion succeeds. If schema validation fails,
|
|
1418
1427
|
* the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
|
|
1428
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
1429
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
1430
|
+
* human-readable details are needed.
|
|
1419
1431
|
*
|
|
1420
1432
|
* **Gotchas**
|
|
1421
1433
|
*
|
|
@@ -1478,10 +1490,19 @@ export function decodeUnknownEffect<S extends Constraint>(schema: S, options?: S
|
|
|
1478
1490
|
input: unknown,
|
|
1479
1491
|
options?: SchemaAST.ParseOptions
|
|
1480
1492
|
): Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]> => {
|
|
1481
|
-
return
|
|
1493
|
+
return fromIssueEffect(parser(input, options))
|
|
1482
1494
|
}
|
|
1483
1495
|
}
|
|
1484
1496
|
|
|
1497
|
+
function fromIssueEffect<A, R>(
|
|
1498
|
+
self: Effect.Effect<A, SchemaIssue.Issue, R>
|
|
1499
|
+
): Effect.Effect<A, SchemaError, R> {
|
|
1500
|
+
return Effect.catchCause(
|
|
1501
|
+
self,
|
|
1502
|
+
(cause) => Effect.failCauseSync(() => Cause_.map(cause, (issue) => new SchemaError(issue)))
|
|
1503
|
+
)
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1485
1506
|
/**
|
|
1486
1507
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1487
1508
|
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
@@ -1939,7 +1960,7 @@ export function encodeUnknownEffect<S extends Constraint>(schema: S, options?: S
|
|
|
1939
1960
|
input: unknown,
|
|
1940
1961
|
options?: SchemaAST.ParseOptions
|
|
1941
1962
|
): Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]> => {
|
|
1942
|
-
return
|
|
1963
|
+
return fromIssueEffect(parser(input, options))
|
|
1943
1964
|
}
|
|
1944
1965
|
}
|
|
1945
1966
|
|
|
@@ -2455,7 +2476,10 @@ interface optionalLambda extends Lambda {
|
|
|
2455
2476
|
* @category combinators
|
|
2456
2477
|
* @since 3.10.0
|
|
2457
2478
|
*/
|
|
2458
|
-
export const optional = Struct_.lambda<optionalLambda>((self) =>
|
|
2479
|
+
export const optional = Struct_.lambda<optionalLambda>((self) => {
|
|
2480
|
+
const schema = UndefinedOr(self)
|
|
2481
|
+
return make(SchemaAST.optional(self.ast), { schema })
|
|
2482
|
+
})
|
|
2459
2483
|
|
|
2460
2484
|
interface requiredLambda extends Lambda {
|
|
2461
2485
|
<S extends Constraint>(self: optional<S>): S
|
|
@@ -5596,7 +5620,7 @@ export function decodeTo<To extends Constraint, From extends Constraint, RD = ne
|
|
|
5596
5620
|
* ```
|
|
5597
5621
|
*
|
|
5598
5622
|
* @category transforming
|
|
5599
|
-
* @since
|
|
5623
|
+
* @since 4.0.0
|
|
5600
5624
|
*/
|
|
5601
5625
|
export function decode<S extends Constraint, RD = never, RE = never>(transformation: {
|
|
5602
5626
|
readonly decode: SchemaGetter.Getter<S["Type"], S["Type"], RD>
|
|
@@ -5685,7 +5709,7 @@ export function encodeTo<To extends Constraint, From extends Constraint, RD = ne
|
|
|
5685
5709
|
* ```
|
|
5686
5710
|
*
|
|
5687
5711
|
* @category transforming
|
|
5688
|
-
* @since
|
|
5712
|
+
* @since 4.0.0
|
|
5689
5713
|
*/
|
|
5690
5714
|
export function encode<S extends Constraint, RD = never, RE = never>(transformation: {
|
|
5691
5715
|
readonly decode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RD>
|
|
@@ -5744,7 +5768,7 @@ export interface withConstructorDefault<S extends Constraint & WithoutConstructo
|
|
|
5744
5768
|
* **Details**
|
|
5745
5769
|
*
|
|
5746
5770
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
5747
|
-
* encoding.
|
|
5771
|
+
* encoding. Failures are represented directly as `SchemaIssue.Issue` values.
|
|
5748
5772
|
*
|
|
5749
5773
|
* **Example** (Defining an optional field with a static default)
|
|
5750
5774
|
*
|
|
@@ -5767,10 +5791,10 @@ export interface withConstructorDefault<S extends Constraint & WithoutConstructo
|
|
|
5767
5791
|
export function withConstructorDefault<S extends Constraint & WithoutConstructorDefault>(
|
|
5768
5792
|
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
5769
5793
|
// it makes easier to define the default value if there are nested defaults
|
|
5770
|
-
defaultValue: Effect.Effect<S["~type.make.in"],
|
|
5794
|
+
defaultValue: Effect.Effect<S["~type.make.in"], SchemaIssue.Issue>
|
|
5771
5795
|
) {
|
|
5772
5796
|
return (schema: S): withConstructorDefault<S> =>
|
|
5773
|
-
make(SchemaAST.withConstructorDefault(schema.ast,
|
|
5797
|
+
make(SchemaAST.withConstructorDefault(schema.ast, defaultValue), { schema })
|
|
5774
5798
|
}
|
|
5775
5799
|
|
|
5776
5800
|
function toIssueEffect<A, R>(
|
|
@@ -6552,12 +6576,13 @@ export const makeFilter: <T>(
|
|
|
6552
6576
|
*
|
|
6553
6577
|
* - `string`: failure with that string as the message. Produces an
|
|
6554
6578
|
* {@link SchemaIssue.InvalidValue} with the string used as the issue's
|
|
6555
|
-
* `message` annotation
|
|
6556
|
-
* - {@link SchemaIssue.Issue}: a fully-formed issue, returned as-is.
|
|
6579
|
+
* `message` annotation and honors `reportInput`.
|
|
6580
|
+
* - {@link SchemaIssue.Issue}: a fully-formed issue, returned as-is. It is not
|
|
6581
|
+
* enriched when `reportInput` is enabled.
|
|
6557
6582
|
* - `{ path, issue }`: failure attached to a nested path. `issue` is either
|
|
6558
|
-
* a `string` (wrapped in an {@link SchemaIssue.InvalidValue}
|
|
6559
|
-
*
|
|
6560
|
-
* at the given `path`.
|
|
6583
|
+
* a `string` (wrapped in an {@link SchemaIssue.InvalidValue} that honors
|
|
6584
|
+
* `reportInput`) or a full {@link SchemaIssue.Issue} (returned unchanged);
|
|
6585
|
+
* the result is wrapped in an {@link SchemaIssue.Pointer} at the given `path`.
|
|
6561
6586
|
*
|
|
6562
6587
|
* @category models
|
|
6563
6588
|
* @since 3.10.0
|
|
@@ -6579,7 +6604,7 @@ export type FilterIssue = string | SchemaIssue.Issue | {
|
|
|
6579
6604
|
* - `true`: success. Equivalent to `undefined`, useful when the predicate is
|
|
6580
6605
|
* a plain boolean expression.
|
|
6581
6606
|
* - `false`: generic failure. Produces an {@link SchemaIssue.InvalidValue}
|
|
6582
|
-
* with no custom message
|
|
6607
|
+
* with no custom message and honors `reportInput`.
|
|
6583
6608
|
* - {@link FilterIssue}: a single failure. See {@link FilterIssue} for the
|
|
6584
6609
|
* shapes (`string`, {@link SchemaIssue.Issue}, or `{ path, issue }`).
|
|
6585
6610
|
* - `ReadonlyArray<FilterIssue>`: several failures reported together. An
|
|
@@ -9379,7 +9404,7 @@ export function isPropertyNames(keySchema: Constraint, annotations?: Annotations
|
|
|
9379
9404
|
}
|
|
9380
9405
|
}
|
|
9381
9406
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
9382
|
-
return new SchemaIssue.Composite(ast, issues)
|
|
9407
|
+
return new SchemaIssue.Composite(ast, issues, input, options)
|
|
9383
9408
|
}
|
|
9384
9409
|
return true
|
|
9385
9410
|
},
|
|
@@ -9580,11 +9605,11 @@ export function Option<A extends Constraint>(value: A): Option<A> {
|
|
|
9580
9605
|
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
9581
9606
|
{
|
|
9582
9607
|
onSuccess: Option_.some,
|
|
9583
|
-
onFailure: (issue) =>
|
|
9608
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
9584
9609
|
}
|
|
9585
9610
|
)
|
|
9586
9611
|
}
|
|
9587
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
9612
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
9588
9613
|
},
|
|
9589
9614
|
{
|
|
9590
9615
|
representation: {
|
|
@@ -9897,18 +9922,18 @@ export function Result<A extends Constraint, E extends Constraint>(
|
|
|
9897
9922
|
[success, failure],
|
|
9898
9923
|
([success, failure]) => (input, ast, options) => {
|
|
9899
9924
|
if (!Result_.isResult(input)) {
|
|
9900
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
9925
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
9901
9926
|
}
|
|
9902
9927
|
switch (input._tag) {
|
|
9903
9928
|
case "Success":
|
|
9904
9929
|
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
9905
9930
|
onSuccess: Result_.succeed,
|
|
9906
|
-
onFailure: (issue) =>
|
|
9931
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "success", issue, input, options)
|
|
9907
9932
|
})
|
|
9908
9933
|
case "Failure":
|
|
9909
9934
|
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
9910
9935
|
onSuccess: Result_.fail,
|
|
9911
|
-
onFailure: (issue) =>
|
|
9936
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failure", issue, input, options)
|
|
9912
9937
|
})
|
|
9913
9938
|
}
|
|
9914
9939
|
},
|
|
@@ -10080,15 +10105,23 @@ export function Redacted<S extends Constraint>(value: S, options?: {
|
|
|
10080
10105
|
{
|
|
10081
10106
|
onSuccess: () => input,
|
|
10082
10107
|
onFailure: (/** ignore the issue because of security reasons */) => {
|
|
10083
|
-
return new SchemaIssue.Composite(
|
|
10084
|
-
|
|
10085
|
-
|
|
10108
|
+
return new SchemaIssue.Composite(
|
|
10109
|
+
ast,
|
|
10110
|
+
[
|
|
10111
|
+
new SchemaIssue.Pointer(
|
|
10112
|
+
["value"],
|
|
10113
|
+
new SchemaIssue.InvalidValue(undefined, input, poptions)
|
|
10114
|
+
)
|
|
10115
|
+
],
|
|
10116
|
+
input,
|
|
10117
|
+
poptions
|
|
10118
|
+
)
|
|
10086
10119
|
}
|
|
10087
10120
|
}
|
|
10088
10121
|
)
|
|
10089
10122
|
)
|
|
10090
10123
|
}
|
|
10091
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10124
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions))
|
|
10092
10125
|
},
|
|
10093
10126
|
{
|
|
10094
10127
|
representation: {
|
|
@@ -10254,7 +10287,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
|
|
|
10254
10287
|
[error, defect],
|
|
10255
10288
|
([error, defect]) => (input, ast, options) => {
|
|
10256
10289
|
if (!Cause_.isReason(input)) {
|
|
10257
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10290
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
10258
10291
|
}
|
|
10259
10292
|
switch (input._tag) {
|
|
10260
10293
|
case "Fail":
|
|
@@ -10262,7 +10295,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
|
|
|
10262
10295
|
SchemaParser.decodeUnknownEffect(error)(input.error, options),
|
|
10263
10296
|
{
|
|
10264
10297
|
onSuccess: Cause_.makeFailReason,
|
|
10265
|
-
onFailure: (issue) =>
|
|
10298
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "error", issue, input, options)
|
|
10266
10299
|
}
|
|
10267
10300
|
)
|
|
10268
10301
|
case "Die":
|
|
@@ -10270,7 +10303,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
|
|
|
10270
10303
|
SchemaParser.decodeUnknownEffect(defect)(input.defect, options),
|
|
10271
10304
|
{
|
|
10272
10305
|
onSuccess: Cause_.makeDieReason,
|
|
10273
|
-
onFailure: (issue) =>
|
|
10306
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "defect", issue, input, options)
|
|
10274
10307
|
}
|
|
10275
10308
|
)
|
|
10276
10309
|
case "Interrupt":
|
|
@@ -10445,11 +10478,11 @@ export function Cause<E extends Constraint, D extends Constraint>(error: E, defe
|
|
|
10445
10478
|
const failures = ArraySchema(CauseReason(error, defect))
|
|
10446
10479
|
return (input, ast, options) => {
|
|
10447
10480
|
if (!Cause_.isCause(input)) {
|
|
10448
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10481
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
10449
10482
|
}
|
|
10450
10483
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
10451
10484
|
onSuccess: Cause_.fromReasons,
|
|
10452
|
-
onFailure: (issue) =>
|
|
10485
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
|
|
10453
10486
|
})
|
|
10454
10487
|
}
|
|
10455
10488
|
},
|
|
@@ -10791,7 +10824,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
|
|
|
10791
10824
|
const cause = Cause(error, defect)
|
|
10792
10825
|
return (input, ast, options) => {
|
|
10793
10826
|
if (!Exit_.isExit(input)) {
|
|
10794
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10827
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
10795
10828
|
}
|
|
10796
10829
|
switch (input._tag) {
|
|
10797
10830
|
case "Success":
|
|
@@ -10799,7 +10832,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
|
|
|
10799
10832
|
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
10800
10833
|
{
|
|
10801
10834
|
onSuccess: Exit_.succeed,
|
|
10802
|
-
onFailure: (issue) =>
|
|
10835
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
10803
10836
|
}
|
|
10804
10837
|
)
|
|
10805
10838
|
case "Failure":
|
|
@@ -10807,7 +10840,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
|
|
|
10807
10840
|
SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
|
|
10808
10841
|
{
|
|
10809
10842
|
onSuccess: Exit_.failCause,
|
|
10810
|
-
onFailure: (issue) =>
|
|
10843
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
|
|
10811
10844
|
}
|
|
10812
10845
|
)
|
|
10813
10846
|
}
|
|
@@ -11048,11 +11081,11 @@ export function ReadonlyMap<Key extends Constraint, Value extends Constraint>(
|
|
|
11048
11081
|
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
11049
11082
|
{
|
|
11050
11083
|
onSuccess: (array: ReadonlyArray<readonly [Key["Type"], Value["Type"]]>) => new globalThis.Map(array),
|
|
11051
|
-
onFailure: (issue) =>
|
|
11084
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
11052
11085
|
}
|
|
11053
11086
|
)
|
|
11054
11087
|
}
|
|
11055
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11088
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11056
11089
|
}
|
|
11057
11090
|
},
|
|
11058
11091
|
{
|
|
@@ -11160,11 +11193,11 @@ export function HashMap<Key extends Constraint, Value extends Constraint>(key: K
|
|
|
11160
11193
|
SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options),
|
|
11161
11194
|
{
|
|
11162
11195
|
onSuccess: HashMap_.fromIterable,
|
|
11163
|
-
onFailure: (issue) =>
|
|
11196
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
11164
11197
|
}
|
|
11165
11198
|
)
|
|
11166
11199
|
}
|
|
11167
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11200
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11168
11201
|
}
|
|
11169
11202
|
},
|
|
11170
11203
|
{
|
|
@@ -11270,11 +11303,11 @@ export function ReadonlySet<Value extends Constraint>(value: Value): $ReadonlySe
|
|
|
11270
11303
|
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
11271
11304
|
{
|
|
11272
11305
|
onSuccess: (array: ReadonlyArray<Value["Type"]>) => new globalThis.Set(array),
|
|
11273
|
-
onFailure: (issue) =>
|
|
11306
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
11274
11307
|
}
|
|
11275
11308
|
)
|
|
11276
11309
|
}
|
|
11277
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11310
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11278
11311
|
}
|
|
11279
11312
|
},
|
|
11280
11313
|
{
|
|
@@ -11380,11 +11413,11 @@ export function HashSet<Value extends Constraint>(value: Value): HashSet<Value>
|
|
|
11380
11413
|
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
11381
11414
|
{
|
|
11382
11415
|
onSuccess: HashSet_.fromIterable,
|
|
11383
|
-
onFailure: (issue) =>
|
|
11416
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
11384
11417
|
}
|
|
11385
11418
|
)
|
|
11386
11419
|
}
|
|
11387
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11420
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11388
11421
|
}
|
|
11389
11422
|
},
|
|
11390
11423
|
{
|
|
@@ -11497,11 +11530,11 @@ export function Chunk<Value extends Constraint>(value: Value): Chunk<Value> {
|
|
|
11497
11530
|
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
11498
11531
|
{
|
|
11499
11532
|
onSuccess: Chunk_.fromIterable,
|
|
11500
|
-
onFailure: (issue) =>
|
|
11533
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
11501
11534
|
}
|
|
11502
11535
|
)
|
|
11503
11536
|
}
|
|
11504
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11537
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11505
11538
|
}
|
|
11506
11539
|
},
|
|
11507
11540
|
{
|
|
@@ -11598,10 +11631,15 @@ export const RegExp: RegExp = instanceOf(
|
|
|
11598
11631
|
flags: String
|
|
11599
11632
|
}),
|
|
11600
11633
|
SchemaTransformation.transformOrFail({
|
|
11601
|
-
decode: (e) =>
|
|
11634
|
+
decode: (e, options) =>
|
|
11602
11635
|
Effect.try({
|
|
11603
11636
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
11604
|
-
catch: () =>
|
|
11637
|
+
catch: () =>
|
|
11638
|
+
new SchemaIssue.InvalidValue(
|
|
11639
|
+
{ expected: "valid RegExp source and flags" },
|
|
11640
|
+
e,
|
|
11641
|
+
options
|
|
11642
|
+
)
|
|
11605
11643
|
}),
|
|
11606
11644
|
encode: (regExp) =>
|
|
11607
11645
|
Effect.succeed({
|
|
@@ -12430,13 +12468,15 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
12430
12468
|
lastModified: Int
|
|
12431
12469
|
}),
|
|
12432
12470
|
SchemaTransformation.transformOrFail({
|
|
12433
|
-
decode: (e) =>
|
|
12471
|
+
decode: (e, options) =>
|
|
12434
12472
|
Result_.match(Encoding.decodeBase64(e.data), {
|
|
12435
12473
|
onFailure: () =>
|
|
12436
12474
|
Effect.fail(
|
|
12437
|
-
new SchemaIssue.InvalidValue(
|
|
12438
|
-
|
|
12439
|
-
|
|
12475
|
+
new SchemaIssue.InvalidValue(
|
|
12476
|
+
{ expected: "a valid Base64 string" },
|
|
12477
|
+
e.data,
|
|
12478
|
+
options
|
|
12479
|
+
)
|
|
12440
12480
|
),
|
|
12441
12481
|
onSuccess: (bytes) => {
|
|
12442
12482
|
const buffer = new globalThis.Uint8Array(bytes)
|
|
@@ -12445,7 +12485,7 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
12445
12485
|
)
|
|
12446
12486
|
}
|
|
12447
12487
|
}),
|
|
12448
|
-
encode: (file) =>
|
|
12488
|
+
encode: (file, options) =>
|
|
12449
12489
|
Effect.tryPromise({
|
|
12450
12490
|
try: async () => {
|
|
12451
12491
|
const bytes = new globalThis.Uint8Array(await file.arrayBuffer())
|
|
@@ -12457,9 +12497,11 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
12457
12497
|
}
|
|
12458
12498
|
},
|
|
12459
12499
|
catch: () =>
|
|
12460
|
-
new SchemaIssue.InvalidValue(
|
|
12461
|
-
|
|
12462
|
-
|
|
12500
|
+
new SchemaIssue.InvalidValue(
|
|
12501
|
+
{ expected: "a readable File" },
|
|
12502
|
+
file,
|
|
12503
|
+
options
|
|
12504
|
+
)
|
|
12463
12505
|
})
|
|
12464
12506
|
})
|
|
12465
12507
|
)
|
|
@@ -14053,7 +14095,7 @@ function makeClass<
|
|
|
14053
14095
|
static makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self> {
|
|
14054
14096
|
return SchemaParser.makeOption(getClassSchema(this) as any)(input ?? {}, options) as any
|
|
14055
14097
|
}
|
|
14056
|
-
static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self,
|
|
14098
|
+
static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self, SchemaIssue.Issue> {
|
|
14057
14099
|
return (getClassSchema(this) as any).makeEffect(input ?? {}, options)
|
|
14058
14100
|
}
|
|
14059
14101
|
static annotate(annotations: Annotations.Declaration<Self, readonly [S]>) {
|
|
@@ -14138,10 +14180,10 @@ function getClassSchemaFactory<S extends Constraint>(
|
|
|
14138
14180
|
const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
|
|
14139
14181
|
new SchemaAST.Declaration(
|
|
14140
14182
|
[from.ast],
|
|
14141
|
-
() => (input, ast) => {
|
|
14183
|
+
() => (input, ast, options) => {
|
|
14142
14184
|
return isClassValue(input) ?
|
|
14143
14185
|
Effect.succeed(input) :
|
|
14144
|
-
Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
14186
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
14145
14187
|
},
|
|
14146
14188
|
{
|
|
14147
14189
|
identifier,
|
|
@@ -14176,8 +14218,8 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
14176
14218
|
|
|
14177
14219
|
/**
|
|
14178
14220
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14179
|
-
* {@link Struct} schema. Construction throws
|
|
14180
|
-
* input.
|
|
14221
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14222
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14181
14223
|
*
|
|
14182
14224
|
* **When to use**
|
|
14183
14225
|
*
|
|
@@ -14246,8 +14288,8 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
14246
14288
|
export const Class: {
|
|
14247
14289
|
/**
|
|
14248
14290
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14249
|
-
* {@link Struct} schema. Construction throws
|
|
14250
|
-
* input.
|
|
14291
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14292
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14251
14293
|
*
|
|
14252
14294
|
* **When to use**
|
|
14253
14295
|
*
|
|
@@ -14316,8 +14358,8 @@ export const Class: {
|
|
|
14316
14358
|
<Self = never, Brand = {}>(identifier: string): {
|
|
14317
14359
|
/**
|
|
14318
14360
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14319
|
-
* {@link Struct} schema. Construction throws
|
|
14320
|
-
* input.
|
|
14361
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14362
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14321
14363
|
*
|
|
14322
14364
|
* **When to use**
|
|
14323
14365
|
*
|
|
@@ -14389,8 +14431,8 @@ export const Class: {
|
|
|
14389
14431
|
): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>
|
|
14390
14432
|
/**
|
|
14391
14433
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14392
|
-
* {@link Struct} schema. Construction throws
|
|
14393
|
-
* input.
|
|
14434
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14435
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14394
14436
|
*
|
|
14395
14437
|
* **When to use**
|
|
14396
14438
|
*
|
|
@@ -14918,44 +14960,32 @@ export const TaggedError: {
|
|
|
14918
14960
|
// -----------------------------------------------------------------------------
|
|
14919
14961
|
|
|
14920
14962
|
/**
|
|
14921
|
-
*
|
|
14922
|
-
*
|
|
14923
|
-
*
|
|
14963
|
+
* Represents a function that builds a fast-check `Arbitrary<T>` from the
|
|
14964
|
+
* `fast-check` module.
|
|
14965
|
+
*
|
|
14966
|
+
* **When to use**
|
|
14967
|
+
*
|
|
14968
|
+
* Use as the result type of schema arbitrary derivation.
|
|
14924
14969
|
*
|
|
14925
14970
|
* @category utility types
|
|
14926
14971
|
* @since 4.0.0
|
|
14927
14972
|
*/
|
|
14928
|
-
export type
|
|
14973
|
+
export type Arbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>
|
|
14929
14974
|
|
|
14930
14975
|
/**
|
|
14931
|
-
*
|
|
14932
|
-
*
|
|
14976
|
+
* Returns an {@link Arbitrary} factory derived from a schema. The generated
|
|
14977
|
+
* values satisfy the schema and use its decoded `Type`.
|
|
14933
14978
|
*
|
|
14934
|
-
* **
|
|
14979
|
+
* **When to use**
|
|
14935
14980
|
*
|
|
14936
|
-
*
|
|
14937
|
-
* want derivation diagnostics via `{ report: true }`. Unsupported schema
|
|
14938
|
-
* nodes, impossible constraints, invalid candidates, and recursive schemas
|
|
14939
|
-
* without a finite terminal path fail immediately.
|
|
14940
|
-
*
|
|
14941
|
-
* @category generators
|
|
14942
|
-
* @since 4.0.0
|
|
14943
|
-
*/
|
|
14944
|
-
export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<S["Type"]> {
|
|
14945
|
-
const lawc = InternalArbitrary.memoized(schema.ast)
|
|
14946
|
-
return (fc) => lawc(fc, {})
|
|
14947
|
-
}
|
|
14948
|
-
|
|
14949
|
-
/**
|
|
14950
|
-
* Derives a `fast-check` `Arbitrary` from a schema for property-based
|
|
14951
|
-
* testing. The derived arbitrary generates values that satisfy the schema.
|
|
14981
|
+
* Use when you need a fast-check generator for values accepted by a schema.
|
|
14952
14982
|
*
|
|
14953
14983
|
* **Details**
|
|
14954
14984
|
*
|
|
14955
14985
|
* Constraints refine base generators; candidates add weighted sources while
|
|
14956
|
-
* filters still validate every value.
|
|
14957
|
-
*
|
|
14958
|
-
*
|
|
14986
|
+
* filters still validate every value. Recursive schemas use terminal branches
|
|
14987
|
+
* and fail when no finite terminal path exists. The result is memoized so
|
|
14988
|
+
* repeated calls with the same schema are cheap.
|
|
14959
14989
|
*
|
|
14960
14990
|
* **Example** (Generating arbitrary values)
|
|
14961
14991
|
*
|
|
@@ -14963,36 +14993,20 @@ export function toArbitraryLazy<S extends Constraint>(schema: S): LazyArbitrary<
|
|
|
14963
14993
|
* import { Schema } from "effect"
|
|
14964
14994
|
* import * as FastCheck from "fast-check"
|
|
14965
14995
|
*
|
|
14966
|
-
* const
|
|
14996
|
+
* const makePersonArbitrary = Schema.toArbitrary(
|
|
14967
14997
|
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
14968
14998
|
* )
|
|
14969
14999
|
*
|
|
14970
|
-
*
|
|
14971
|
-
* FastCheck.sample(
|
|
15000
|
+
* const PersonArbitrary = makePersonArbitrary(FastCheck)
|
|
15001
|
+
* FastCheck.sample(PersonArbitrary, 1)
|
|
14972
15002
|
* ```
|
|
14973
15003
|
*
|
|
14974
15004
|
* @category generators
|
|
14975
15005
|
* @since 4.0.0
|
|
14976
15006
|
*/
|
|
14977
|
-
export function toArbitrary<S extends Constraint>(schema: S):
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
options: { readonly report: true }
|
|
14981
|
-
): Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>>
|
|
14982
|
-
export function toArbitrary<S extends Constraint>(
|
|
14983
|
-
schema: S,
|
|
14984
|
-
options?: { readonly report?: boolean }
|
|
14985
|
-
): FastCheck.Arbitrary<S["Type"]> | Annotations.ToArbitrary.WithReport<FastCheck.Arbitrary<S["Type"]>> {
|
|
14986
|
-
if (options?.report === true) {
|
|
14987
|
-
const lawc = InternalArbitrary.memoized(schema.ast)
|
|
14988
|
-
const report = InternalArbitrary.makeReport()
|
|
14989
|
-
InternalArbitrary.collectReport(schema.ast, report)
|
|
14990
|
-
return {
|
|
14991
|
-
value: lawc(FastCheck, {}),
|
|
14992
|
-
report: InternalArbitrary.toReport(report)
|
|
14993
|
-
}
|
|
14994
|
-
}
|
|
14995
|
-
return toArbitraryLazy(schema)(FastCheck)
|
|
15007
|
+
export function toArbitrary<S extends Constraint>(schema: S): Arbitrary<S["Type"]> {
|
|
15008
|
+
const lawc = InternalArbitrary.memoized(schema.ast)
|
|
15009
|
+
return (fc) => lawc(fc, {})
|
|
14996
15010
|
}
|
|
14997
15011
|
|
|
14998
15012
|
// -----------------------------------------------------------------------------
|
|
@@ -15328,7 +15342,10 @@ export function toJsonSchemaDocument(
|
|
|
15328
15342
|
schema: Constraint,
|
|
15329
15343
|
options?: ToJsonSchemaOptions
|
|
15330
15344
|
): JsonSchema.Document<"draft-2020-12"> {
|
|
15331
|
-
const document = InternalToRepresentation.toRepresentation(
|
|
15345
|
+
const document = InternalToRepresentation.toRepresentation(
|
|
15346
|
+
toCodecJsonAST(schema.ast),
|
|
15347
|
+
InternalToJsonSchemaDocument.toRepresentationOptions
|
|
15348
|
+
)
|
|
15332
15349
|
return InternalToJsonSchemaDocument.toJsonSchemaDocument(document, options)
|
|
15333
15350
|
}
|
|
15334
15351
|
|
|
@@ -15383,16 +15400,14 @@ export function toCodecJson<S extends Constraint>(schema: S): toCodecJson<S> {
|
|
|
15383
15400
|
return make(toCodecJsonAST(schema.ast), { schema })
|
|
15384
15401
|
}
|
|
15385
15402
|
|
|
15386
|
-
|
|
15387
|
-
|
|
15403
|
+
/** @internal */
|
|
15404
|
+
export const toCodecJsonAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
15405
|
+
const out = toCodecJsonASTStep(ast, toCodecJsonAST)
|
|
15388
15406
|
const context = ast.context
|
|
15389
15407
|
if (out === ast || context === undefined) return out
|
|
15390
15408
|
return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(context))
|
|
15391
15409
|
})
|
|
15392
15410
|
|
|
15393
|
-
/** @internal */
|
|
15394
|
-
export const toCodecJsonAST = memoize(toCodecJsonASTBase)
|
|
15395
|
-
|
|
15396
15411
|
function withoutConstructorDefault(context: SchemaAST.Context): SchemaAST.Context {
|
|
15397
15412
|
return context.constructorDefault === undefined ?
|
|
15398
15413
|
context :
|
|
@@ -15443,7 +15458,7 @@ const toCodecJsonReorder = makeReorder((ast: SchemaAST.AST) => {
|
|
|
15443
15458
|
}
|
|
15444
15459
|
})
|
|
15445
15460
|
|
|
15446
|
-
function
|
|
15461
|
+
function toCodecJsonASTStep(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
15447
15462
|
switch (ast._tag) {
|
|
15448
15463
|
case "Declaration": {
|
|
15449
15464
|
const getLink = ast.annotations?.toCodecJson ?? ast.annotations?.toCodec
|
|
@@ -15502,17 +15517,17 @@ function toCodecJsonBase(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => Sche
|
|
|
15502
15517
|
* @since 4.0.0
|
|
15503
15518
|
*/
|
|
15504
15519
|
export function toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]> {
|
|
15505
|
-
return make(
|
|
15520
|
+
return make(toCodecIsoAST(SchemaAST.toType(schema.ast)))
|
|
15506
15521
|
}
|
|
15507
15522
|
|
|
15508
|
-
const
|
|
15509
|
-
const out =
|
|
15523
|
+
const toCodecIsoAST = memoize((ast: SchemaAST.AST): SchemaAST.AST => {
|
|
15524
|
+
const out = toCodecIsoASTStep(ast, toCodecIsoAST)
|
|
15510
15525
|
return out !== ast && ast.context !== undefined ?
|
|
15511
15526
|
SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context)) :
|
|
15512
15527
|
out
|
|
15513
15528
|
})
|
|
15514
15529
|
|
|
15515
|
-
function
|
|
15530
|
+
function toCodecIsoASTStep(ast: SchemaAST.AST, recur: (ast: SchemaAST.AST) => SchemaAST.AST): SchemaAST.AST {
|
|
15516
15531
|
switch (ast._tag) {
|
|
15517
15532
|
case "Declaration": {
|
|
15518
15533
|
const getLink = ast.annotations?.toCodecIso ?? ast.annotations?.toCodec
|
|
@@ -15582,7 +15597,7 @@ export interface toCodecStringTree<S extends Constraint> extends
|
|
|
15582
15597
|
* @since 4.0.0
|
|
15583
15598
|
*/
|
|
15584
15599
|
export function toCodecStringTree<S extends Constraint>(schema: S): toCodecStringTree<S> {
|
|
15585
|
-
return make(
|
|
15600
|
+
return make(toCodecStringTreeAST(schema.ast), { schema })
|
|
15586
15601
|
}
|
|
15587
15602
|
|
|
15588
15603
|
/**
|
|
@@ -15631,7 +15646,7 @@ export interface toCodecArrayFromSingle<S extends Constraint> extends
|
|
|
15631
15646
|
* @since 4.0.0
|
|
15632
15647
|
*/
|
|
15633
15648
|
export function toCodecArrayFromSingle<S extends Constraint>(schema: S): toCodecArrayFromSingle<S> {
|
|
15634
|
-
return make(
|
|
15649
|
+
return make(toCodecArrayFromSingleAST(schema.ast))
|
|
15635
15650
|
}
|
|
15636
15651
|
|
|
15637
15652
|
type XmlEncoderOptions = {
|
|
@@ -15768,7 +15783,7 @@ const toStringTreeReorder = makeReorder((ast: SchemaAST.AST) => {
|
|
|
15768
15783
|
}
|
|
15769
15784
|
})
|
|
15770
15785
|
|
|
15771
|
-
function
|
|
15786
|
+
function toCodecStringTreeASTStep(
|
|
15772
15787
|
ast: SchemaAST.AST,
|
|
15773
15788
|
recur: (ast: SchemaAST.AST) => SchemaAST.AST,
|
|
15774
15789
|
onMissingAnnotation: (ast: SchemaAST.AST) => SchemaAST.AST
|
|
@@ -15847,37 +15862,29 @@ const booleanToString = new SchemaAST.Link(
|
|
|
15847
15862
|
)
|
|
15848
15863
|
)
|
|
15849
15864
|
|
|
15850
|
-
const
|
|
15865
|
+
const arrayFromSingleTransformation = new SchemaTransformation.Transformation(
|
|
15866
|
+
SchemaGetter.transform((input: ReadonlyArray<unknown> | string) => typeof input === "string" ? [input] : input),
|
|
15867
|
+
SchemaGetter.passthrough()
|
|
15868
|
+
)
|
|
15851
15869
|
|
|
15852
|
-
const
|
|
15853
|
-
|
|
15870
|
+
const isCodecArrayFromSingleLink = (link: SchemaAST.Link): boolean =>
|
|
15871
|
+
link.transformation === arrayFromSingleTransformation
|
|
15854
15872
|
|
|
15855
|
-
const
|
|
15856
|
-
|
|
15857
|
-
return ast
|
|
15858
|
-
}
|
|
15859
|
-
const out = serializerTree(ast, serializerStringTree, (ast) => {
|
|
15873
|
+
const toCodecStringTreeAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
15874
|
+
const out = toCodecStringTreeASTStep(ast, toCodecStringTreeAST, (ast) => {
|
|
15860
15875
|
throw new globalThis.Error("Missing structural codec for StringTree", { cause: ast })
|
|
15861
15876
|
})
|
|
15862
15877
|
if (out !== ast && ast.context !== undefined) {
|
|
15863
15878
|
return SchemaAST.replaceContextLastLink(out, withoutConstructorDefault(ast.context))
|
|
15864
15879
|
}
|
|
15865
15880
|
return out
|
|
15866
|
-
})
|
|
15881
|
+
}, { stopAt: isCodecArrayFromSingleLink })
|
|
15867
15882
|
|
|
15868
15883
|
const toArrayFromSingleInputElement = (ast: SchemaAST.AST): SchemaAST.AST =>
|
|
15869
15884
|
SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(SchemaAST.unknown) : SchemaAST.unknown
|
|
15870
15885
|
|
|
15871
|
-
const
|
|
15872
|
-
|
|
15873
|
-
SchemaGetter.passthrough()
|
|
15874
|
-
)
|
|
15875
|
-
|
|
15876
|
-
const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast) => {
|
|
15877
|
-
if (isSerializerArrayFromSingle(ast)) {
|
|
15878
|
-
return ast
|
|
15879
|
-
}
|
|
15880
|
-
const out = onSerializerArrayFromSingle(ast)
|
|
15886
|
+
const toCodecArrayFromSingleAST = SchemaAST.applyToSelfOrLastLinkEncodingIdempotent((ast) => {
|
|
15887
|
+
const out = toCodecArrayFromSingleASTStep(ast)
|
|
15881
15888
|
if (SchemaAST.isArrays(out)) {
|
|
15882
15889
|
const ensure = SchemaAST.decodeTo(
|
|
15883
15890
|
new SchemaAST.Union(
|
|
@@ -15889,8 +15896,7 @@ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast)
|
|
|
15889
15896
|
),
|
|
15890
15897
|
SchemaAST.string
|
|
15891
15898
|
],
|
|
15892
|
-
"anyOf"
|
|
15893
|
-
{ [SERIALIZER_ENSURE_ARRAY]: true }
|
|
15899
|
+
"anyOf"
|
|
15894
15900
|
),
|
|
15895
15901
|
out,
|
|
15896
15902
|
arrayFromSingleTransformation
|
|
@@ -15898,12 +15904,12 @@ const toCodecArrayFromSingleTop = SchemaAST.applyToSelfOrLastLinkEncoding((ast)
|
|
|
15898
15904
|
return SchemaAST.isOptional(ast) ? SchemaAST.optionalKey(ensure) : ensure
|
|
15899
15905
|
}
|
|
15900
15906
|
return out
|
|
15901
|
-
})
|
|
15907
|
+
}, { stopAt: isCodecArrayFromSingleLink })
|
|
15902
15908
|
|
|
15903
|
-
function
|
|
15909
|
+
function toCodecArrayFromSingleASTStep(ast: SchemaAST.AST): SchemaAST.AST {
|
|
15904
15910
|
return ast._tag === "Declaration" || ast._tag === "Arrays" || ast._tag === "Objects" || ast._tag === "Union" ||
|
|
15905
15911
|
ast._tag === "Suspend"
|
|
15906
|
-
? ast.recur(
|
|
15912
|
+
? ast.recur(toCodecArrayFromSingleAST)
|
|
15907
15913
|
: ast
|
|
15908
15914
|
}
|
|
15909
15915
|
|
|
@@ -16131,6 +16137,18 @@ export const isBetweenBigIntReviver: SchemaRepresentation.FilterReviver<{
|
|
|
16131
16137
|
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
16132
16138
|
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
16133
16139
|
*
|
|
16140
|
+
* **Details**
|
|
16141
|
+
*
|
|
16142
|
+
* Reading through the `Iso` encodes the schema value, while replacing through
|
|
16143
|
+
* it decodes the new focus.
|
|
16144
|
+
*
|
|
16145
|
+
* **Gotchas**
|
|
16146
|
+
*
|
|
16147
|
+
* Either direction can throw an `Error` with the generic message
|
|
16148
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
16149
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
16150
|
+
* human-readable details are needed.
|
|
16151
|
+
*
|
|
16134
16152
|
* @category converting
|
|
16135
16153
|
* @since 4.0.0
|
|
16136
16154
|
*/
|
|
@@ -16230,6 +16248,19 @@ export function overrideToCodecIso<S extends Constraint, Iso>(
|
|
|
16230
16248
|
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
16231
16249
|
* and new values, and can apply patches back to the typed value.
|
|
16232
16250
|
*
|
|
16251
|
+
* **Details**
|
|
16252
|
+
*
|
|
16253
|
+
* `diff` encodes both values before computing the patch. `patch` encodes the old
|
|
16254
|
+
* value, applies the patch to its JSON representation, and decodes the result.
|
|
16255
|
+
*
|
|
16256
|
+
* **Gotchas**
|
|
16257
|
+
*
|
|
16258
|
+
* Schema encoding or decoding failures throw an `Error` with the generic message
|
|
16259
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
16260
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
16261
|
+
* human-readable details are needed. Errors produced by {@link JsonPatch.apply}
|
|
16262
|
+
* for invalid patch operations are separate from schema validation failures.
|
|
16263
|
+
*
|
|
16233
16264
|
* @category converting
|
|
16234
16265
|
* @since 4.0.0
|
|
16235
16266
|
*/
|
|
@@ -16704,6 +16735,15 @@ export declare namespace Annotations {
|
|
|
16704
16735
|
readonly representation?:
|
|
16705
16736
|
| SchemaRepresentation.CheckRepresentationAnnotation<SchemaAST.AST>
|
|
16706
16737
|
| undefined
|
|
16738
|
+
/**
|
|
16739
|
+
* Compiles this filter to a JSON Schema fragment.
|
|
16740
|
+
*
|
|
16741
|
+
* **Gotchas**
|
|
16742
|
+
*
|
|
16743
|
+
* Treat the input schemas as immutable. The returned value must be a valid JSON Schema object graph and must not be
|
|
16744
|
+
* mutated after this function returns. Return a new object graph to produce different output during a later
|
|
16745
|
+
* compilation.
|
|
16746
|
+
*/
|
|
16707
16747
|
readonly toJsonSchema?: SchemaRepresentation.ToJsonSchema.Check | undefined
|
|
16708
16748
|
readonly toCode?: SchemaRepresentation.Generation.Check | undefined
|
|
16709
16749
|
/**
|
|
@@ -16754,8 +16794,7 @@ export declare namespace Annotations {
|
|
|
16754
16794
|
|
|
16755
16795
|
/**
|
|
16756
16796
|
* Types used by arbitrary-derivation annotations to configure `toArbitrary`
|
|
16757
|
-
* hooks, filter hints, candidate sources,
|
|
16758
|
-
* constraints.
|
|
16797
|
+
* hooks, filter hints, candidate sources, and merged generation constraints.
|
|
16759
16798
|
*
|
|
16760
16799
|
* @since 4.0.0
|
|
16761
16800
|
*/
|
|
@@ -16768,8 +16807,7 @@ export declare namespace Annotations {
|
|
|
16768
16807
|
* `constraint` refines the schema node's base generator. `candidate` adds a
|
|
16769
16808
|
* weighted source before all filters run. If neither hint is provided, the
|
|
16770
16809
|
* filter does not guide generation; generated values are still checked by
|
|
16771
|
-
* the filter predicate.
|
|
16772
|
-
* `OpaqueFilter`.
|
|
16810
|
+
* the filter predicate.
|
|
16773
16811
|
*
|
|
16774
16812
|
* @category models
|
|
16775
16813
|
* @since 4.0.0
|
|
@@ -16957,58 +16995,6 @@ export declare namespace Annotations {
|
|
|
16957
16995
|
typeParameters: { readonly [K in keyof TypeParameters]: TypeParameter<TypeParameters[K]["Type"]> }
|
|
16958
16996
|
): (fc: typeof FastCheck, context: Context) => Output<T>
|
|
16959
16997
|
}
|
|
16960
|
-
|
|
16961
|
-
/**
|
|
16962
|
-
* Wraps a derived value together with arbitrary-derivation diagnostics.
|
|
16963
|
-
*
|
|
16964
|
-
* @category models
|
|
16965
|
-
* @since 4.0.0
|
|
16966
|
-
*/
|
|
16967
|
-
export interface WithReport<A> {
|
|
16968
|
-
readonly value: A
|
|
16969
|
-
readonly report: Report
|
|
16970
|
-
}
|
|
16971
|
-
|
|
16972
|
-
/**
|
|
16973
|
-
* Diagnostics collected while deriving an arbitrary.
|
|
16974
|
-
*
|
|
16975
|
-
* **Details**
|
|
16976
|
-
*
|
|
16977
|
-
* Reports contain warnings only. Unsupported schema nodes, impossible
|
|
16978
|
-
* constraints, invalid candidate weights, and throwing candidate factories
|
|
16979
|
-
* fail immediately.
|
|
16980
|
-
*
|
|
16981
|
-
* @category models
|
|
16982
|
-
* @since 4.0.0
|
|
16983
|
-
*/
|
|
16984
|
-
export interface Report {
|
|
16985
|
-
readonly warnings: ReadonlyArray<Warning>
|
|
16986
|
-
}
|
|
16987
|
-
|
|
16988
|
-
/**
|
|
16989
|
-
* Non-fatal arbitrary-derivation warning.
|
|
16990
|
-
*
|
|
16991
|
-
* @category models
|
|
16992
|
-
* @since 4.0.0
|
|
16993
|
-
*/
|
|
16994
|
-
export type Warning = OpaqueFilterWarning
|
|
16995
|
-
|
|
16996
|
-
/**
|
|
16997
|
-
* Warning emitted when a filter is handled only by the final `.filter`.
|
|
16998
|
-
*
|
|
16999
|
-
* **Details**
|
|
17000
|
-
*
|
|
17001
|
-
* The filter is still enforced. The warning means it did not contribute
|
|
17002
|
-
* a constraint or candidate, so generation may rely on fast-check discards.
|
|
17003
|
-
*
|
|
17004
|
-
* @category models
|
|
17005
|
-
* @since 4.0.0
|
|
17006
|
-
*/
|
|
17007
|
-
export interface OpaqueFilterWarning {
|
|
17008
|
-
readonly _tag: "OpaqueFilter"
|
|
17009
|
-
readonly path: ReadonlyArray<PropertyKey>
|
|
17010
|
-
readonly description?: string | undefined
|
|
17011
|
-
}
|
|
17012
16998
|
}
|
|
17013
16999
|
|
|
17014
17000
|
/**
|
|
@@ -17066,12 +17052,22 @@ export declare namespace Annotations {
|
|
|
17066
17052
|
*
|
|
17067
17053
|
* **Details**
|
|
17068
17054
|
*
|
|
17069
|
-
*
|
|
17055
|
+
* For `InvalidValue` issues, `message` overrides the complete formatted
|
|
17056
|
+
* message. When `message` is absent, `expected` uses the default expected
|
|
17057
|
+
* value policy, including reported input when available. Other issue types
|
|
17058
|
+
* ignore `expected`.
|
|
17070
17059
|
*
|
|
17071
17060
|
* @category models
|
|
17072
17061
|
* @since 4.0.0
|
|
17073
17062
|
*/
|
|
17074
17063
|
export interface Issue extends Annotations {
|
|
17064
|
+
/**
|
|
17065
|
+
* The expected value description for an `InvalidValue` issue.
|
|
17066
|
+
*/
|
|
17067
|
+
readonly expected?: string | undefined
|
|
17068
|
+
/**
|
|
17069
|
+
* The complete formatted message for the issue.
|
|
17070
|
+
*/
|
|
17075
17071
|
readonly message?: string | undefined
|
|
17076
17072
|
}
|
|
17077
17073
|
}
|