effect 4.0.0-beta.104 → 4.0.0-beta.105
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 +2 -1
- package/dist/Config.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/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 +73 -25
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +83 -50
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +30 -0
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +40 -32
- 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/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/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/internal/schema/schema.js +1 -9
- package/dist/internal/schema/schema.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 +8 -7
- package/dist/testing/TestSchema.js.map +1 -1
- package/dist/unstable/ai/Prompt.d.ts.map +1 -1
- package/dist/unstable/ai/Prompt.js +4 -4
- package/dist/unstable/ai/Prompt.js.map +1 -1
- package/dist/unstable/cluster/Reply.js +4 -4
- package/dist/unstable/cluster/Reply.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/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/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/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 +3 -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/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 +3 -1
- package/src/Context.ts +1 -23
- package/src/Cron.ts +65 -2
- package/src/Optic.ts +59 -58
- package/src/Schema.ts +145 -71
- package/src/SchemaAST.ts +85 -48
- 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/SchemaTransformation.ts +66 -18
- package/src/Stdio.ts +23 -4
- package/src/internal/schema/schema.ts +1 -17
- package/src/testing/TestSchema.ts +8 -8
- package/src/unstable/ai/Prompt.ts +14 -4
- package/src/unstable/cluster/Reply.ts +4 -4
- package/src/unstable/encoding/Msgpack.ts +12 -8
- package/src/unstable/http/HttpClient.ts +132 -23
- package/src/unstable/httpapi/HttpApiBuilder.ts +32 -13
- package/src/unstable/httpapi/HttpApiClient.ts +26 -8
- package/src/unstable/reactivity/AsyncResult.ts +11 -6
- package/src/unstable/reactivity/Atom.ts +44 -25
- package/src/unstable/rpc/RpcClient.ts +4 -1
- package/src/unstable/rpc/RpcServer.ts +4 -2
- package/src/unstable/workflow/Workflow.ts +2 -5
package/src/Schema.ts
CHANGED
|
@@ -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
|
|
|
@@ -5744,7 +5765,7 @@ export interface withConstructorDefault<S extends Constraint & WithoutConstructo
|
|
|
5744
5765
|
* **Details**
|
|
5745
5766
|
*
|
|
5746
5767
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
5747
|
-
* encoding.
|
|
5768
|
+
* encoding. Failures are represented directly as `SchemaIssue.Issue` values.
|
|
5748
5769
|
*
|
|
5749
5770
|
* **Example** (Defining an optional field with a static default)
|
|
5750
5771
|
*
|
|
@@ -5767,10 +5788,10 @@ export interface withConstructorDefault<S extends Constraint & WithoutConstructo
|
|
|
5767
5788
|
export function withConstructorDefault<S extends Constraint & WithoutConstructorDefault>(
|
|
5768
5789
|
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
5769
5790
|
// it makes easier to define the default value if there are nested defaults
|
|
5770
|
-
defaultValue: Effect.Effect<S["~type.make.in"],
|
|
5791
|
+
defaultValue: Effect.Effect<S["~type.make.in"], SchemaIssue.Issue>
|
|
5771
5792
|
) {
|
|
5772
5793
|
return (schema: S): withConstructorDefault<S> =>
|
|
5773
|
-
make(SchemaAST.withConstructorDefault(schema.ast,
|
|
5794
|
+
make(SchemaAST.withConstructorDefault(schema.ast, defaultValue), { schema })
|
|
5774
5795
|
}
|
|
5775
5796
|
|
|
5776
5797
|
function toIssueEffect<A, R>(
|
|
@@ -6552,12 +6573,13 @@ export const makeFilter: <T>(
|
|
|
6552
6573
|
*
|
|
6553
6574
|
* - `string`: failure with that string as the message. Produces an
|
|
6554
6575
|
* {@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.
|
|
6576
|
+
* `message` annotation and honors `reportInput`.
|
|
6577
|
+
* - {@link SchemaIssue.Issue}: a fully-formed issue, returned as-is. It is not
|
|
6578
|
+
* enriched when `reportInput` is enabled.
|
|
6557
6579
|
* - `{ 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`.
|
|
6580
|
+
* a `string` (wrapped in an {@link SchemaIssue.InvalidValue} that honors
|
|
6581
|
+
* `reportInput`) or a full {@link SchemaIssue.Issue} (returned unchanged);
|
|
6582
|
+
* the result is wrapped in an {@link SchemaIssue.Pointer} at the given `path`.
|
|
6561
6583
|
*
|
|
6562
6584
|
* @category models
|
|
6563
6585
|
* @since 3.10.0
|
|
@@ -6579,7 +6601,7 @@ export type FilterIssue = string | SchemaIssue.Issue | {
|
|
|
6579
6601
|
* - `true`: success. Equivalent to `undefined`, useful when the predicate is
|
|
6580
6602
|
* a plain boolean expression.
|
|
6581
6603
|
* - `false`: generic failure. Produces an {@link SchemaIssue.InvalidValue}
|
|
6582
|
-
* with no custom message
|
|
6604
|
+
* with no custom message and honors `reportInput`.
|
|
6583
6605
|
* - {@link FilterIssue}: a single failure. See {@link FilterIssue} for the
|
|
6584
6606
|
* shapes (`string`, {@link SchemaIssue.Issue}, or `{ path, issue }`).
|
|
6585
6607
|
* - `ReadonlyArray<FilterIssue>`: several failures reported together. An
|
|
@@ -9379,7 +9401,7 @@ export function isPropertyNames(keySchema: Constraint, annotations?: Annotations
|
|
|
9379
9401
|
}
|
|
9380
9402
|
}
|
|
9381
9403
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
9382
|
-
return new SchemaIssue.Composite(ast, issues)
|
|
9404
|
+
return new SchemaIssue.Composite(ast, issues, input, options)
|
|
9383
9405
|
}
|
|
9384
9406
|
return true
|
|
9385
9407
|
},
|
|
@@ -9580,11 +9602,11 @@ export function Option<A extends Constraint>(value: A): Option<A> {
|
|
|
9580
9602
|
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
9581
9603
|
{
|
|
9582
9604
|
onSuccess: Option_.some,
|
|
9583
|
-
onFailure: (issue) =>
|
|
9605
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
9584
9606
|
}
|
|
9585
9607
|
)
|
|
9586
9608
|
}
|
|
9587
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
9609
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
9588
9610
|
},
|
|
9589
9611
|
{
|
|
9590
9612
|
representation: {
|
|
@@ -9897,18 +9919,18 @@ export function Result<A extends Constraint, E extends Constraint>(
|
|
|
9897
9919
|
[success, failure],
|
|
9898
9920
|
([success, failure]) => (input, ast, options) => {
|
|
9899
9921
|
if (!Result_.isResult(input)) {
|
|
9900
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
9922
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
9901
9923
|
}
|
|
9902
9924
|
switch (input._tag) {
|
|
9903
9925
|
case "Success":
|
|
9904
9926
|
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
9905
9927
|
onSuccess: Result_.succeed,
|
|
9906
|
-
onFailure: (issue) =>
|
|
9928
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "success", issue, input, options)
|
|
9907
9929
|
})
|
|
9908
9930
|
case "Failure":
|
|
9909
9931
|
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
9910
9932
|
onSuccess: Result_.fail,
|
|
9911
|
-
onFailure: (issue) =>
|
|
9933
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failure", issue, input, options)
|
|
9912
9934
|
})
|
|
9913
9935
|
}
|
|
9914
9936
|
},
|
|
@@ -10080,15 +10102,23 @@ export function Redacted<S extends Constraint>(value: S, options?: {
|
|
|
10080
10102
|
{
|
|
10081
10103
|
onSuccess: () => input,
|
|
10082
10104
|
onFailure: (/** ignore the issue because of security reasons */) => {
|
|
10083
|
-
return new SchemaIssue.Composite(
|
|
10084
|
-
|
|
10085
|
-
|
|
10105
|
+
return new SchemaIssue.Composite(
|
|
10106
|
+
ast,
|
|
10107
|
+
[
|
|
10108
|
+
new SchemaIssue.Pointer(
|
|
10109
|
+
["value"],
|
|
10110
|
+
new SchemaIssue.InvalidValue(undefined, input, poptions)
|
|
10111
|
+
)
|
|
10112
|
+
],
|
|
10113
|
+
input,
|
|
10114
|
+
poptions
|
|
10115
|
+
)
|
|
10086
10116
|
}
|
|
10087
10117
|
}
|
|
10088
10118
|
)
|
|
10089
10119
|
)
|
|
10090
10120
|
}
|
|
10091
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10121
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions))
|
|
10092
10122
|
},
|
|
10093
10123
|
{
|
|
10094
10124
|
representation: {
|
|
@@ -10254,7 +10284,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
|
|
|
10254
10284
|
[error, defect],
|
|
10255
10285
|
([error, defect]) => (input, ast, options) => {
|
|
10256
10286
|
if (!Cause_.isReason(input)) {
|
|
10257
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10287
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
10258
10288
|
}
|
|
10259
10289
|
switch (input._tag) {
|
|
10260
10290
|
case "Fail":
|
|
@@ -10262,7 +10292,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
|
|
|
10262
10292
|
SchemaParser.decodeUnknownEffect(error)(input.error, options),
|
|
10263
10293
|
{
|
|
10264
10294
|
onSuccess: Cause_.makeFailReason,
|
|
10265
|
-
onFailure: (issue) =>
|
|
10295
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "error", issue, input, options)
|
|
10266
10296
|
}
|
|
10267
10297
|
)
|
|
10268
10298
|
case "Die":
|
|
@@ -10270,7 +10300,7 @@ export function CauseReason<E extends Constraint, D extends Constraint>(error: E
|
|
|
10270
10300
|
SchemaParser.decodeUnknownEffect(defect)(input.defect, options),
|
|
10271
10301
|
{
|
|
10272
10302
|
onSuccess: Cause_.makeDieReason,
|
|
10273
|
-
onFailure: (issue) =>
|
|
10303
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "defect", issue, input, options)
|
|
10274
10304
|
}
|
|
10275
10305
|
)
|
|
10276
10306
|
case "Interrupt":
|
|
@@ -10445,11 +10475,11 @@ export function Cause<E extends Constraint, D extends Constraint>(error: E, defe
|
|
|
10445
10475
|
const failures = ArraySchema(CauseReason(error, defect))
|
|
10446
10476
|
return (input, ast, options) => {
|
|
10447
10477
|
if (!Cause_.isCause(input)) {
|
|
10448
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10478
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
10449
10479
|
}
|
|
10450
10480
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
10451
10481
|
onSuccess: Cause_.fromReasons,
|
|
10452
|
-
onFailure: (issue) =>
|
|
10482
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
|
|
10453
10483
|
})
|
|
10454
10484
|
}
|
|
10455
10485
|
},
|
|
@@ -10791,7 +10821,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
|
|
|
10791
10821
|
const cause = Cause(error, defect)
|
|
10792
10822
|
return (input, ast, options) => {
|
|
10793
10823
|
if (!Exit_.isExit(input)) {
|
|
10794
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
10824
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
10795
10825
|
}
|
|
10796
10826
|
switch (input._tag) {
|
|
10797
10827
|
case "Success":
|
|
@@ -10799,7 +10829,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
|
|
|
10799
10829
|
SchemaParser.decodeUnknownEffect(value)(input.value, options),
|
|
10800
10830
|
{
|
|
10801
10831
|
onSuccess: Exit_.succeed,
|
|
10802
|
-
onFailure: (issue) =>
|
|
10832
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
10803
10833
|
}
|
|
10804
10834
|
)
|
|
10805
10835
|
case "Failure":
|
|
@@ -10807,7 +10837,7 @@ export function Exit<A extends Constraint, E extends Constraint, D extends Const
|
|
|
10807
10837
|
SchemaParser.decodeUnknownEffect(cause)(input.cause, options),
|
|
10808
10838
|
{
|
|
10809
10839
|
onSuccess: Exit_.failCause,
|
|
10810
|
-
onFailure: (issue) =>
|
|
10840
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
|
|
10811
10841
|
}
|
|
10812
10842
|
)
|
|
10813
10843
|
}
|
|
@@ -11048,11 +11078,11 @@ export function ReadonlyMap<Key extends Constraint, Value extends Constraint>(
|
|
|
11048
11078
|
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
11049
11079
|
{
|
|
11050
11080
|
onSuccess: (array: ReadonlyArray<readonly [Key["Type"], Value["Type"]]>) => new globalThis.Map(array),
|
|
11051
|
-
onFailure: (issue) =>
|
|
11081
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
11052
11082
|
}
|
|
11053
11083
|
)
|
|
11054
11084
|
}
|
|
11055
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11085
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11056
11086
|
}
|
|
11057
11087
|
},
|
|
11058
11088
|
{
|
|
@@ -11160,11 +11190,11 @@ export function HashMap<Key extends Constraint, Value extends Constraint>(key: K
|
|
|
11160
11190
|
SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options),
|
|
11161
11191
|
{
|
|
11162
11192
|
onSuccess: HashMap_.fromIterable,
|
|
11163
|
-
onFailure: (issue) =>
|
|
11193
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
11164
11194
|
}
|
|
11165
11195
|
)
|
|
11166
11196
|
}
|
|
11167
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11197
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11168
11198
|
}
|
|
11169
11199
|
},
|
|
11170
11200
|
{
|
|
@@ -11270,11 +11300,11 @@ export function ReadonlySet<Value extends Constraint>(value: Value): $ReadonlySe
|
|
|
11270
11300
|
SchemaParser.decodeUnknownEffect(array)([...input], options),
|
|
11271
11301
|
{
|
|
11272
11302
|
onSuccess: (array: ReadonlyArray<Value["Type"]>) => new globalThis.Set(array),
|
|
11273
|
-
onFailure: (issue) =>
|
|
11303
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
11274
11304
|
}
|
|
11275
11305
|
)
|
|
11276
11306
|
}
|
|
11277
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11307
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11278
11308
|
}
|
|
11279
11309
|
},
|
|
11280
11310
|
{
|
|
@@ -11380,11 +11410,11 @@ export function HashSet<Value extends Constraint>(value: Value): HashSet<Value>
|
|
|
11380
11410
|
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
11381
11411
|
{
|
|
11382
11412
|
onSuccess: HashSet_.fromIterable,
|
|
11383
|
-
onFailure: (issue) =>
|
|
11413
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
11384
11414
|
}
|
|
11385
11415
|
)
|
|
11386
11416
|
}
|
|
11387
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11417
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11388
11418
|
}
|
|
11389
11419
|
},
|
|
11390
11420
|
{
|
|
@@ -11497,11 +11527,11 @@ export function Chunk<Value extends Constraint>(value: Value): Chunk<Value> {
|
|
|
11497
11527
|
SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options),
|
|
11498
11528
|
{
|
|
11499
11529
|
onSuccess: Chunk_.fromIterable,
|
|
11500
|
-
onFailure: (issue) =>
|
|
11530
|
+
onFailure: (issue) => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
11501
11531
|
}
|
|
11502
11532
|
)
|
|
11503
11533
|
}
|
|
11504
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
11534
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
11505
11535
|
}
|
|
11506
11536
|
},
|
|
11507
11537
|
{
|
|
@@ -11598,10 +11628,15 @@ export const RegExp: RegExp = instanceOf(
|
|
|
11598
11628
|
flags: String
|
|
11599
11629
|
}),
|
|
11600
11630
|
SchemaTransformation.transformOrFail({
|
|
11601
|
-
decode: (e) =>
|
|
11631
|
+
decode: (e, options) =>
|
|
11602
11632
|
Effect.try({
|
|
11603
11633
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
11604
|
-
catch: () =>
|
|
11634
|
+
catch: () =>
|
|
11635
|
+
new SchemaIssue.InvalidValue(
|
|
11636
|
+
{ expected: "valid RegExp source and flags" },
|
|
11637
|
+
e,
|
|
11638
|
+
options
|
|
11639
|
+
)
|
|
11605
11640
|
}),
|
|
11606
11641
|
encode: (regExp) =>
|
|
11607
11642
|
Effect.succeed({
|
|
@@ -12430,13 +12465,15 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
12430
12465
|
lastModified: Int
|
|
12431
12466
|
}),
|
|
12432
12467
|
SchemaTransformation.transformOrFail({
|
|
12433
|
-
decode: (e) =>
|
|
12468
|
+
decode: (e, options) =>
|
|
12434
12469
|
Result_.match(Encoding.decodeBase64(e.data), {
|
|
12435
12470
|
onFailure: () =>
|
|
12436
12471
|
Effect.fail(
|
|
12437
|
-
new SchemaIssue.InvalidValue(
|
|
12438
|
-
|
|
12439
|
-
|
|
12472
|
+
new SchemaIssue.InvalidValue(
|
|
12473
|
+
{ expected: "a valid Base64 string" },
|
|
12474
|
+
e.data,
|
|
12475
|
+
options
|
|
12476
|
+
)
|
|
12440
12477
|
),
|
|
12441
12478
|
onSuccess: (bytes) => {
|
|
12442
12479
|
const buffer = new globalThis.Uint8Array(bytes)
|
|
@@ -12445,7 +12482,7 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
12445
12482
|
)
|
|
12446
12483
|
}
|
|
12447
12484
|
}),
|
|
12448
|
-
encode: (file) =>
|
|
12485
|
+
encode: (file, options) =>
|
|
12449
12486
|
Effect.tryPromise({
|
|
12450
12487
|
try: async () => {
|
|
12451
12488
|
const bytes = new globalThis.Uint8Array(await file.arrayBuffer())
|
|
@@ -12457,9 +12494,11 @@ export const File: File = instanceOf(globalThis.File, {
|
|
|
12457
12494
|
}
|
|
12458
12495
|
},
|
|
12459
12496
|
catch: () =>
|
|
12460
|
-
new SchemaIssue.InvalidValue(
|
|
12461
|
-
|
|
12462
|
-
|
|
12497
|
+
new SchemaIssue.InvalidValue(
|
|
12498
|
+
{ expected: "a readable File" },
|
|
12499
|
+
file,
|
|
12500
|
+
options
|
|
12501
|
+
)
|
|
12463
12502
|
})
|
|
12464
12503
|
})
|
|
12465
12504
|
)
|
|
@@ -14053,7 +14092,7 @@ function makeClass<
|
|
|
14053
14092
|
static makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self> {
|
|
14054
14093
|
return SchemaParser.makeOption(getClassSchema(this) as any)(input ?? {}, options) as any
|
|
14055
14094
|
}
|
|
14056
|
-
static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self,
|
|
14095
|
+
static makeEffect(input: S["~type.make.in"], options?: MakeOptions): Effect.Effect<Self, SchemaIssue.Issue> {
|
|
14057
14096
|
return (getClassSchema(this) as any).makeEffect(input ?? {}, options)
|
|
14058
14097
|
}
|
|
14059
14098
|
static annotate(annotations: Annotations.Declaration<Self, readonly [S]>) {
|
|
@@ -14138,10 +14177,10 @@ function getClassSchemaFactory<S extends Constraint>(
|
|
|
14138
14177
|
const to = make<declareConstructor<Self, S["Encoded"], readonly [S]>>(
|
|
14139
14178
|
new SchemaAST.Declaration(
|
|
14140
14179
|
[from.ast],
|
|
14141
|
-
() => (input, ast) => {
|
|
14180
|
+
() => (input, ast, options) => {
|
|
14142
14181
|
return isClassValue(input) ?
|
|
14143
14182
|
Effect.succeed(input) :
|
|
14144
|
-
Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
14183
|
+
Effect.fail(new SchemaIssue.InvalidType(ast, input, options))
|
|
14145
14184
|
},
|
|
14146
14185
|
{
|
|
14147
14186
|
identifier,
|
|
@@ -14176,8 +14215,8 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
14176
14215
|
|
|
14177
14216
|
/**
|
|
14178
14217
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14179
|
-
* {@link Struct} schema. Construction throws
|
|
14180
|
-
* input.
|
|
14218
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14219
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14181
14220
|
*
|
|
14182
14221
|
* **When to use**
|
|
14183
14222
|
*
|
|
@@ -14246,8 +14285,8 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
14246
14285
|
export const Class: {
|
|
14247
14286
|
/**
|
|
14248
14287
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14249
|
-
* {@link Struct} schema. Construction throws
|
|
14250
|
-
* input.
|
|
14288
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14289
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14251
14290
|
*
|
|
14252
14291
|
* **When to use**
|
|
14253
14292
|
*
|
|
@@ -14316,8 +14355,8 @@ export const Class: {
|
|
|
14316
14355
|
<Self = never, Brand = {}>(identifier: string): {
|
|
14317
14356
|
/**
|
|
14318
14357
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14319
|
-
* {@link Struct} schema. Construction throws
|
|
14320
|
-
* input.
|
|
14358
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14359
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14321
14360
|
*
|
|
14322
14361
|
* **When to use**
|
|
14323
14362
|
*
|
|
@@ -14389,8 +14428,8 @@ export const Class: {
|
|
|
14389
14428
|
): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>
|
|
14390
14429
|
/**
|
|
14391
14430
|
* Creates a schema-backed class whose constructor validates input against a
|
|
14392
|
-
* {@link Struct} schema. Construction throws
|
|
14393
|
-
* input.
|
|
14431
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
14432
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
14394
14433
|
*
|
|
14395
14434
|
* **When to use**
|
|
14396
14435
|
*
|
|
@@ -16131,6 +16170,18 @@ export const isBetweenBigIntReviver: SchemaRepresentation.FilterReviver<{
|
|
|
16131
16170
|
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
16132
16171
|
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
16133
16172
|
*
|
|
16173
|
+
* **Details**
|
|
16174
|
+
*
|
|
16175
|
+
* Reading through the `Iso` encodes the schema value, while replacing through
|
|
16176
|
+
* it decodes the new focus.
|
|
16177
|
+
*
|
|
16178
|
+
* **Gotchas**
|
|
16179
|
+
*
|
|
16180
|
+
* Either direction can throw an `Error` with the generic message
|
|
16181
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
16182
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
16183
|
+
* human-readable details are needed.
|
|
16184
|
+
*
|
|
16134
16185
|
* @category converting
|
|
16135
16186
|
* @since 4.0.0
|
|
16136
16187
|
*/
|
|
@@ -16230,6 +16281,19 @@ export function overrideToCodecIso<S extends Constraint, Iso>(
|
|
|
16230
16281
|
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
16231
16282
|
* and new values, and can apply patches back to the typed value.
|
|
16232
16283
|
*
|
|
16284
|
+
* **Details**
|
|
16285
|
+
*
|
|
16286
|
+
* `diff` encodes both values before computing the patch. `patch` encodes the old
|
|
16287
|
+
* value, applies the patch to its JSON representation, and decodes the result.
|
|
16288
|
+
*
|
|
16289
|
+
* **Gotchas**
|
|
16290
|
+
*
|
|
16291
|
+
* Schema encoding or decoding failures throw an `Error` with the generic message
|
|
16292
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
16293
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
16294
|
+
* human-readable details are needed. Errors produced by {@link JsonPatch.apply}
|
|
16295
|
+
* for invalid patch operations are separate from schema validation failures.
|
|
16296
|
+
*
|
|
16233
16297
|
* @category converting
|
|
16234
16298
|
* @since 4.0.0
|
|
16235
16299
|
*/
|
|
@@ -17066,12 +17130,22 @@ export declare namespace Annotations {
|
|
|
17066
17130
|
*
|
|
17067
17131
|
* **Details**
|
|
17068
17132
|
*
|
|
17069
|
-
*
|
|
17133
|
+
* For `InvalidValue` issues, `message` overrides the complete formatted
|
|
17134
|
+
* message. When `message` is absent, `expected` uses the default expected
|
|
17135
|
+
* value policy, including reported input when available. Other issue types
|
|
17136
|
+
* ignore `expected`.
|
|
17070
17137
|
*
|
|
17071
17138
|
* @category models
|
|
17072
17139
|
* @since 4.0.0
|
|
17073
17140
|
*/
|
|
17074
17141
|
export interface Issue extends Annotations {
|
|
17142
|
+
/**
|
|
17143
|
+
* The expected value description for an `InvalidValue` issue.
|
|
17144
|
+
*/
|
|
17145
|
+
readonly expected?: string | undefined
|
|
17146
|
+
/**
|
|
17147
|
+
* The complete formatted message for the issue.
|
|
17148
|
+
*/
|
|
17075
17149
|
readonly message?: string | undefined
|
|
17076
17150
|
}
|
|
17077
17151
|
}
|