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/dist/Schema.js
CHANGED
|
@@ -81,7 +81,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
81
81
|
* **Example** (Schema for a parametric `Box<A>` type)
|
|
82
82
|
*
|
|
83
83
|
* ```ts import.meta.vitest
|
|
84
|
-
* import { Effect, Schema, SchemaIssue
|
|
84
|
+
* import { Effect, Schema, SchemaIssue, SchemaParser } from "effect"
|
|
85
85
|
*
|
|
86
86
|
* interface Box<A> {
|
|
87
87
|
* readonly value: A
|
|
@@ -96,7 +96,7 @@ const TypeId = InternalSchema.TypeId;
|
|
|
96
96
|
* ([itemCodec]) =>
|
|
97
97
|
* (u, ast, options) => {
|
|
98
98
|
* if (!isBox(u)) {
|
|
99
|
-
* return Effect.fail(new SchemaIssue.InvalidType(ast))
|
|
99
|
+
* return Effect.fail(new SchemaIssue.InvalidType(ast, u, options))
|
|
100
100
|
* }
|
|
101
101
|
* return Effect.map(
|
|
102
102
|
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
@@ -150,7 +150,7 @@ export function declareConstructor() {
|
|
|
150
150
|
* @since 3.10.0
|
|
151
151
|
*/
|
|
152
152
|
export function declare(is, annotations) {
|
|
153
|
-
return declareConstructor()([], () => (input, ast) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast)), annotations);
|
|
153
|
+
return declareConstructor()([], () => (input, ast, options) => is(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, input, options)), annotations);
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
156
|
* Returns a schema widened to the fully-parameterized {@link Bottom} interface,
|
|
@@ -338,10 +338,12 @@ isSchemaError,
|
|
|
338
338
|
*
|
|
339
339
|
* The `issue` field contains a structured {@link SchemaIssue.Issue} tree describing
|
|
340
340
|
* every validation failure, including the path to the problematic value and
|
|
341
|
-
* the expected type or constraint.
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
341
|
+
* the expected type or constraint. Parsing with `reportInput: true` adds an
|
|
342
|
+
* enumerable `input` field to value-bearing issues created by the parser.
|
|
343
|
+
* Built-in messages may include reported input. Other issue fields and
|
|
344
|
+
* custom annotations or messages are not sanitized.
|
|
345
|
+
* `message` renders the issue tree as a human-readable string and can disclose
|
|
346
|
+
* retained input.
|
|
345
347
|
*
|
|
346
348
|
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
347
349
|
*
|
|
@@ -584,6 +586,9 @@ export const is = SchemaParser.is;
|
|
|
584
586
|
*
|
|
585
587
|
* The input is narrowed if the assertion succeeds. If schema validation fails,
|
|
586
588
|
* the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
|
|
589
|
+
* Schema validation failures use the generic message `"Schema validation failed"`.
|
|
590
|
+
* Format the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
591
|
+
* human-readable details are needed.
|
|
587
592
|
*
|
|
588
593
|
* **Gotchas**
|
|
589
594
|
*
|
|
@@ -641,9 +646,12 @@ export const asserts = SchemaParser.asserts;
|
|
|
641
646
|
export function decodeUnknownEffect(schema, options) {
|
|
642
647
|
const parser = SchemaParser.decodeUnknownEffect(schema, options);
|
|
643
648
|
return (input, options) => {
|
|
644
|
-
return
|
|
649
|
+
return fromIssueEffect(parser(input, options));
|
|
645
650
|
};
|
|
646
651
|
}
|
|
652
|
+
function fromIssueEffect(self) {
|
|
653
|
+
return Effect.catchCause(self, cause => Effect.failCauseSync(() => Cause_.map(cause, issue => new SchemaError(issue))));
|
|
654
|
+
}
|
|
647
655
|
/**
|
|
648
656
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
649
657
|
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
@@ -1050,7 +1058,7 @@ export const decodeSync = decodeUnknownSync;
|
|
|
1050
1058
|
export function encodeUnknownEffect(schema, options) {
|
|
1051
1059
|
const parser = SchemaParser.encodeUnknownEffect(schema, options);
|
|
1052
1060
|
return (input, options) => {
|
|
1053
|
-
return
|
|
1061
|
+
return fromIssueEffect(parser(input, options));
|
|
1054
1062
|
};
|
|
1055
1063
|
}
|
|
1056
1064
|
/**
|
|
@@ -2706,7 +2714,7 @@ export function encode(transformation) {
|
|
|
2706
2714
|
* **Details**
|
|
2707
2715
|
*
|
|
2708
2716
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
2709
|
-
* encoding.
|
|
2717
|
+
* encoding. Failures are represented directly as `SchemaIssue.Issue` values.
|
|
2710
2718
|
*
|
|
2711
2719
|
* **Example** (Defining an optional field with a static default)
|
|
2712
2720
|
*
|
|
@@ -2730,7 +2738,7 @@ export function withConstructorDefault(
|
|
|
2730
2738
|
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
2731
2739
|
// it makes easier to define the default value if there are nested defaults
|
|
2732
2740
|
defaultValue) {
|
|
2733
|
-
return schema => make(SchemaAST.withConstructorDefault(schema.ast,
|
|
2741
|
+
return schema => make(SchemaAST.withConstructorDefault(schema.ast, defaultValue), {
|
|
2734
2742
|
schema
|
|
2735
2743
|
});
|
|
2736
2744
|
}
|
|
@@ -5903,7 +5911,7 @@ export function isPropertyNames(keySchema, annotations) {
|
|
|
5903
5911
|
}
|
|
5904
5912
|
}
|
|
5905
5913
|
if (Arr.isArrayNonEmpty(issues)) {
|
|
5906
|
-
return new SchemaIssue.Composite(ast, issues);
|
|
5914
|
+
return new SchemaIssue.Composite(ast, issues, input, options);
|
|
5907
5915
|
}
|
|
5908
5916
|
return true;
|
|
5909
5917
|
}, {
|
|
@@ -6037,10 +6045,10 @@ export function Option(value) {
|
|
|
6037
6045
|
}
|
|
6038
6046
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
|
|
6039
6047
|
onSuccess: Option_.some,
|
|
6040
|
-
onFailure: issue =>
|
|
6048
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
6041
6049
|
});
|
|
6042
6050
|
}
|
|
6043
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6051
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6044
6052
|
}, {
|
|
6045
6053
|
representation: {
|
|
6046
6054
|
id: "effect/schema/Option",
|
|
@@ -6208,18 +6216,18 @@ export function OptionFromOptionalNullOr(schema, options) {
|
|
|
6208
6216
|
export function Result(success, failure) {
|
|
6209
6217
|
const schema = declareConstructor()([success, failure], ([success, failure]) => (input, ast, options) => {
|
|
6210
6218
|
if (!Result_.isResult(input)) {
|
|
6211
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6219
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6212
6220
|
}
|
|
6213
6221
|
switch (input._tag) {
|
|
6214
6222
|
case "Success":
|
|
6215
6223
|
return Effect.mapBothEager(SchemaParser.decodeEffect(success)(input.success, options), {
|
|
6216
6224
|
onSuccess: Result_.succeed,
|
|
6217
|
-
onFailure: issue =>
|
|
6225
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "success", issue, input, options)
|
|
6218
6226
|
});
|
|
6219
6227
|
case "Failure":
|
|
6220
6228
|
return Effect.mapBothEager(SchemaParser.decodeEffect(failure)(input.failure, options), {
|
|
6221
6229
|
onSuccess: Result_.fail,
|
|
6222
|
-
onFailure: issue =>
|
|
6230
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "failure", issue, input, options)
|
|
6223
6231
|
});
|
|
6224
6232
|
}
|
|
6225
6233
|
}, {
|
|
@@ -6340,11 +6348,11 @@ export function Redacted(value, options) {
|
|
|
6340
6348
|
onSuccess: () => input,
|
|
6341
6349
|
onFailure: (/** ignore the issue because of security reasons */
|
|
6342
6350
|
) => {
|
|
6343
|
-
return new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue())]);
|
|
6351
|
+
return new SchemaIssue.Composite(ast, [new SchemaIssue.Pointer(["value"], new SchemaIssue.InvalidValue(undefined, input, poptions))], input, poptions);
|
|
6344
6352
|
}
|
|
6345
6353
|
}));
|
|
6346
6354
|
}
|
|
6347
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6355
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, poptions));
|
|
6348
6356
|
}, {
|
|
6349
6357
|
representation: {
|
|
6350
6358
|
id: "effect/schema/Redacted",
|
|
@@ -6442,18 +6450,18 @@ export function RedactedFromValue(value, options) {
|
|
|
6442
6450
|
export function CauseReason(error, defect) {
|
|
6443
6451
|
const schema = declareConstructor()([error, defect], ([error, defect]) => (input, ast, options) => {
|
|
6444
6452
|
if (!Cause_.isReason(input)) {
|
|
6445
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6453
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6446
6454
|
}
|
|
6447
6455
|
switch (input._tag) {
|
|
6448
6456
|
case "Fail":
|
|
6449
6457
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(error)(input.error, options), {
|
|
6450
6458
|
onSuccess: Cause_.makeFailReason,
|
|
6451
|
-
onFailure: issue =>
|
|
6459
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "error", issue, input, options)
|
|
6452
6460
|
});
|
|
6453
6461
|
case "Die":
|
|
6454
6462
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(defect)(input.defect, options), {
|
|
6455
6463
|
onSuccess: Cause_.makeDieReason,
|
|
6456
|
-
onFailure: issue =>
|
|
6464
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "defect", issue, input, options)
|
|
6457
6465
|
});
|
|
6458
6466
|
case "Interrupt":
|
|
6459
6467
|
return Effect.succeed(input);
|
|
@@ -6581,11 +6589,11 @@ export function Cause(error, defect) {
|
|
|
6581
6589
|
const failures = ArraySchema(CauseReason(error, defect));
|
|
6582
6590
|
return (input, ast, options) => {
|
|
6583
6591
|
if (!Cause_.isCause(input)) {
|
|
6584
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6592
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6585
6593
|
}
|
|
6586
6594
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(failures)(input.reasons, options), {
|
|
6587
6595
|
onSuccess: Cause_.fromReasons,
|
|
6588
|
-
onFailure: issue =>
|
|
6596
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "failures", issue, input, options)
|
|
6589
6597
|
});
|
|
6590
6598
|
};
|
|
6591
6599
|
}, {
|
|
@@ -6806,18 +6814,18 @@ export function Exit(value, error, defect) {
|
|
|
6806
6814
|
const cause = Cause(error, defect);
|
|
6807
6815
|
return (input, ast, options) => {
|
|
6808
6816
|
if (!Exit_.isExit(input)) {
|
|
6809
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6817
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6810
6818
|
}
|
|
6811
6819
|
switch (input._tag) {
|
|
6812
6820
|
case "Success":
|
|
6813
6821
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(value)(input.value, options), {
|
|
6814
6822
|
onSuccess: Exit_.succeed,
|
|
6815
|
-
onFailure: issue =>
|
|
6823
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "value", issue, input, options)
|
|
6816
6824
|
});
|
|
6817
6825
|
case "Failure":
|
|
6818
6826
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(cause)(input.cause, options), {
|
|
6819
6827
|
onSuccess: Exit_.failCause,
|
|
6820
|
-
onFailure: issue =>
|
|
6828
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "cause", issue, input, options)
|
|
6821
6829
|
});
|
|
6822
6830
|
}
|
|
6823
6831
|
};
|
|
@@ -6961,10 +6969,10 @@ export function ReadonlyMap(key, value) {
|
|
|
6961
6969
|
if (input instanceof globalThis.Map) {
|
|
6962
6970
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
|
|
6963
6971
|
onSuccess: array => new globalThis.Map(array),
|
|
6964
|
-
onFailure: issue =>
|
|
6972
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
6965
6973
|
});
|
|
6966
6974
|
}
|
|
6967
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
6975
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
6968
6976
|
};
|
|
6969
6977
|
}, {
|
|
6970
6978
|
representation: {
|
|
@@ -7030,10 +7038,10 @@ export function HashMap(key, value) {
|
|
|
7030
7038
|
if (HashMap_.isHashMap(input)) {
|
|
7031
7039
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(entries)(HashMap_.toEntries(input), options), {
|
|
7032
7040
|
onSuccess: HashMap_.fromIterable,
|
|
7033
|
-
onFailure: issue =>
|
|
7041
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "entries", issue, input, options)
|
|
7034
7042
|
});
|
|
7035
7043
|
}
|
|
7036
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7044
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7037
7045
|
};
|
|
7038
7046
|
}, {
|
|
7039
7047
|
representation: {
|
|
@@ -7100,10 +7108,10 @@ export function ReadonlySet(value) {
|
|
|
7100
7108
|
if (input instanceof globalThis.Set) {
|
|
7101
7109
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(array)([...input], options), {
|
|
7102
7110
|
onSuccess: array => new globalThis.Set(array),
|
|
7103
|
-
onFailure: issue =>
|
|
7111
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
7104
7112
|
});
|
|
7105
7113
|
}
|
|
7106
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7114
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7107
7115
|
};
|
|
7108
7116
|
}, {
|
|
7109
7117
|
representation: {
|
|
@@ -7168,10 +7176,10 @@ export function HashSet(value) {
|
|
|
7168
7176
|
if (HashSet_.isHashSet(input)) {
|
|
7169
7177
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
7170
7178
|
onSuccess: HashSet_.fromIterable,
|
|
7171
|
-
onFailure: issue =>
|
|
7179
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
7172
7180
|
});
|
|
7173
7181
|
}
|
|
7174
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7182
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7175
7183
|
};
|
|
7176
7184
|
}, {
|
|
7177
7185
|
representation: {
|
|
@@ -7236,10 +7244,10 @@ export function Chunk(value) {
|
|
|
7236
7244
|
if (Chunk_.isChunk(input)) {
|
|
7237
7245
|
return Effect.mapBothEager(SchemaParser.decodeUnknownEffect(values)(Arr.fromIterable(input), options), {
|
|
7238
7246
|
onSuccess: Chunk_.fromIterable,
|
|
7239
|
-
onFailure: issue =>
|
|
7247
|
+
onFailure: issue => SchemaIssue.makeCompositeAtKey(ast, "values", issue, input, options)
|
|
7240
7248
|
});
|
|
7241
7249
|
}
|
|
7242
|
-
return Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
7250
|
+
return Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
7243
7251
|
};
|
|
7244
7252
|
}, {
|
|
7245
7253
|
representation: {
|
|
@@ -7315,11 +7323,11 @@ export const RegExp = /*#__PURE__*/instanceOf(globalThis.RegExp, {
|
|
|
7315
7323
|
source: String,
|
|
7316
7324
|
flags: String
|
|
7317
7325
|
}), SchemaTransformation.transformOrFail({
|
|
7318
|
-
decode: e => Effect.try({
|
|
7326
|
+
decode: (e, options) => Effect.try({
|
|
7319
7327
|
try: () => new globalThis.RegExp(e.source, e.flags),
|
|
7320
7328
|
catch: () => new SchemaIssue.InvalidValue({
|
|
7321
|
-
|
|
7322
|
-
})
|
|
7329
|
+
expected: "valid RegExp source and flags"
|
|
7330
|
+
}, e, options)
|
|
7323
7331
|
}),
|
|
7324
7332
|
encode: regExp => Effect.succeed({
|
|
7325
7333
|
source: regExp.source,
|
|
@@ -7894,10 +7902,10 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
7894
7902
|
name: String,
|
|
7895
7903
|
lastModified: Int
|
|
7896
7904
|
}), SchemaTransformation.transformOrFail({
|
|
7897
|
-
decode: e => Result_.match(Encoding.decodeBase64(e.data), {
|
|
7905
|
+
decode: (e, options) => Result_.match(Encoding.decodeBase64(e.data), {
|
|
7898
7906
|
onFailure: () => Effect.fail(new SchemaIssue.InvalidValue({
|
|
7899
|
-
|
|
7900
|
-
})),
|
|
7907
|
+
expected: "a valid Base64 string"
|
|
7908
|
+
}, e.data, options)),
|
|
7901
7909
|
onSuccess: bytes => {
|
|
7902
7910
|
const buffer = new globalThis.Uint8Array(bytes);
|
|
7903
7911
|
return Effect.succeed(new globalThis.File([buffer], e.name, {
|
|
@@ -7906,7 +7914,7 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
7906
7914
|
}));
|
|
7907
7915
|
}
|
|
7908
7916
|
}),
|
|
7909
|
-
encode: file => Effect.tryPromise({
|
|
7917
|
+
encode: (file, options) => Effect.tryPromise({
|
|
7910
7918
|
try: async () => {
|
|
7911
7919
|
const bytes = new globalThis.Uint8Array(await file.arrayBuffer());
|
|
7912
7920
|
return {
|
|
@@ -7917,8 +7925,8 @@ export const File = /*#__PURE__*/instanceOf(globalThis.File, {
|
|
|
7917
7925
|
};
|
|
7918
7926
|
},
|
|
7919
7927
|
catch: () => new SchemaIssue.InvalidValue({
|
|
7920
|
-
|
|
7921
|
-
})
|
|
7928
|
+
expected: "a readable File"
|
|
7929
|
+
}, file, options)
|
|
7922
7930
|
})
|
|
7923
7931
|
}))
|
|
7924
7932
|
});
|
|
@@ -8988,8 +8996,8 @@ function getClassSchemaFactory(from, identifier, annotations) {
|
|
|
8988
8996
|
const ClassTypeId = getClassTypeId(identifier);
|
|
8989
8997
|
const isClassValue = input => input instanceof self || Predicate.hasProperty(input, ClassTypeId);
|
|
8990
8998
|
const transformation = getClassTransformation(self);
|
|
8991
|
-
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast) => {
|
|
8992
|
-
return isClassValue(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast));
|
|
8999
|
+
const to = make(new SchemaAST.Declaration([from.ast], () => (input, ast, options) => {
|
|
9000
|
+
return isClassValue(input) ? Effect.succeed(input) : Effect.fail(new SchemaIssue.InvalidType(ast, input, options));
|
|
8993
9001
|
}, {
|
|
8994
9002
|
identifier,
|
|
8995
9003
|
[InternalAnnotations.CONSTRUCTOR_ANNOTATION_KEY]: ([from]) => ({
|
|
@@ -9013,8 +9021,8 @@ function isStruct(schema) {
|
|
|
9013
9021
|
}
|
|
9014
9022
|
/**
|
|
9015
9023
|
* Creates a schema-backed class whose constructor validates input against a
|
|
9016
|
-
* {@link Struct} schema. Construction throws
|
|
9017
|
-
* input.
|
|
9024
|
+
* {@link Struct} schema. Construction throws an `Error` with a
|
|
9025
|
+
* `SchemaIssue.Issue` in its `cause` on invalid input.
|
|
9018
9026
|
*
|
|
9019
9027
|
* **When to use**
|
|
9020
9028
|
*
|
|
@@ -10073,6 +10081,18 @@ export const isBetweenBigIntReviver = /*#__PURE__*/InternalSchema.makeFilterRevi
|
|
|
10073
10081
|
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
10074
10082
|
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
10075
10083
|
*
|
|
10084
|
+
* **Details**
|
|
10085
|
+
*
|
|
10086
|
+
* Reading through the `Iso` encodes the schema value, while replacing through
|
|
10087
|
+
* it decodes the new focus.
|
|
10088
|
+
*
|
|
10089
|
+
* **Gotchas**
|
|
10090
|
+
*
|
|
10091
|
+
* Either direction can throw an `Error` with the generic message
|
|
10092
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
10093
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
10094
|
+
* human-readable details are needed.
|
|
10095
|
+
*
|
|
10076
10096
|
* @category converting
|
|
10077
10097
|
* @since 4.0.0
|
|
10078
10098
|
*/
|
|
@@ -10132,6 +10152,19 @@ export function overrideToCodecIso(to, transformation) {
|
|
|
10132
10152
|
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
10133
10153
|
* and new values, and can apply patches back to the typed value.
|
|
10134
10154
|
*
|
|
10155
|
+
* **Details**
|
|
10156
|
+
*
|
|
10157
|
+
* `diff` encodes both values before computing the patch. `patch` encodes the old
|
|
10158
|
+
* value, applies the patch to its JSON representation, and decodes the result.
|
|
10159
|
+
*
|
|
10160
|
+
* **Gotchas**
|
|
10161
|
+
*
|
|
10162
|
+
* Schema encoding or decoding failures throw an `Error` with the generic message
|
|
10163
|
+
* `"Schema validation failed"` and a `SchemaIssue.Issue` in its `cause`. Format
|
|
10164
|
+
* the `cause` explicitly with `SchemaIssue.makeFormatterDefault()` when
|
|
10165
|
+
* human-readable details are needed. Errors produced by {@link JsonPatch.apply}
|
|
10166
|
+
* for invalid patch operations are separate from schema validation failures.
|
|
10167
|
+
*
|
|
10135
10168
|
* @category converting
|
|
10136
10169
|
* @since 4.0.0
|
|
10137
10170
|
*/
|