effect 4.0.0-beta.83 → 4.0.0-beta.85
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/dist/Array.d.ts +64 -64
- package/dist/Array.js +26 -26
- package/dist/Cache.d.ts +1 -1
- package/dist/Cache.js +1 -1
- package/dist/Cause.d.ts +68 -68
- package/dist/Cause.js +47 -47
- package/dist/Channel.d.ts +5 -5
- package/dist/Channel.js +3 -3
- package/dist/Clock.d.ts +1 -1
- package/dist/Clock.js +1 -1
- package/dist/Combiner.d.ts +9 -9
- package/dist/Combiner.js +8 -8
- package/dist/Config.d.ts +15 -94
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +22 -70
- package/dist/Config.js.map +1 -1
- package/dist/ConfigProvider.d.ts +58 -74
- package/dist/ConfigProvider.d.ts.map +1 -1
- package/dist/ConfigProvider.js +66 -41
- package/dist/ConfigProvider.js.map +1 -1
- package/dist/Console.d.ts +1 -1
- package/dist/Console.js +1 -1
- package/dist/Context.d.ts.map +1 -1
- package/dist/Context.js +4 -3
- package/dist/Context.js.map +1 -1
- package/dist/Data.d.ts +15 -15
- package/dist/Data.js +3 -3
- package/dist/DateTime.d.ts +6 -6
- package/dist/DateTime.js +2 -2
- package/dist/Duration.d.ts +3 -3
- package/dist/Duration.js +3 -3
- package/dist/Effect.d.ts +84 -45
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +72 -33
- package/dist/Effect.js.map +1 -1
- package/dist/Equal.d.ts +7 -7
- package/dist/Equal.js +5 -5
- package/dist/Equivalence.d.ts +17 -17
- package/dist/Equivalence.js +13 -13
- package/dist/Exit.d.ts +3 -3
- package/dist/Exit.js +3 -3
- package/dist/Formatter.d.ts +5 -5
- package/dist/Formatter.js +4 -4
- package/dist/Function.d.ts +10 -10
- package/dist/Function.js +3 -3
- package/dist/HashMap.d.ts +3 -3
- package/dist/HashMap.js +1 -1
- package/dist/Iterable.d.ts +6 -6
- package/dist/Iterable.js +2 -2
- package/dist/JsonPatch.d.ts +2 -2
- package/dist/Layer.d.ts +1 -1
- package/dist/Layer.js +5 -4
- package/dist/Layer.js.map +1 -1
- package/dist/LayerMap.d.ts.map +1 -1
- package/dist/LayerMap.js +4 -3
- package/dist/LayerMap.js.map +1 -1
- package/dist/Logger.d.ts +1 -1
- package/dist/Logger.js +1 -1
- package/dist/Match.d.ts +8 -8
- package/dist/Match.js +8 -8
- package/dist/Metric.d.ts +3 -3
- package/dist/Metric.js +3 -3
- package/dist/Optic.d.ts +30 -30
- package/dist/Optic.js +12 -12
- package/dist/Option.d.ts +7 -7
- package/dist/Option.js +7 -7
- package/dist/Order.d.ts +23 -23
- package/dist/Order.js +20 -20
- package/dist/Pool.d.ts +1 -1
- package/dist/Pool.js +1 -1
- package/dist/Predicate.d.ts +88 -88
- package/dist/Predicate.js +47 -47
- package/dist/PubSub.d.ts +3 -3
- package/dist/PubSub.js +3 -3
- package/dist/Random.d.ts +31 -0
- package/dist/Random.d.ts.map +1 -1
- package/dist/Random.js +32 -0
- package/dist/Random.js.map +1 -1
- package/dist/Reducer.d.ts +1 -1
- package/dist/Reducer.js +1 -1
- package/dist/Result.d.ts +18 -18
- package/dist/Result.js +8 -8
- package/dist/Runtime.d.ts +1 -1
- package/dist/Runtime.js +1 -1
- package/dist/Schema.d.ts +313 -126
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +316 -127
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +9 -8
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +203 -140
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaGetter.d.ts +48 -48
- package/dist/SchemaGetter.js +44 -44
- package/dist/SchemaIssue.d.ts +3 -3
- package/dist/SchemaIssue.js +3 -3
- package/dist/SchemaParser.d.ts +122 -22
- package/dist/SchemaParser.d.ts.map +1 -1
- package/dist/SchemaParser.js +186 -50
- package/dist/SchemaParser.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +96 -2
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/SchemaTransformation.d.ts +20 -20
- package/dist/SchemaTransformation.js +18 -18
- package/dist/Stream.d.ts +3 -3
- package/dist/Stream.js +2 -2
- package/dist/Stream.js.map +1 -1
- package/dist/String.d.ts +1 -1
- package/dist/String.js +1 -1
- package/dist/Struct.d.ts +1 -1
- package/dist/Struct.js +1 -1
- package/dist/Types.d.ts +13 -13
- package/dist/internal/effect.js +33 -20
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/arbitrary.js +17 -1
- package/dist/internal/schema/arbitrary.js.map +1 -1
- package/dist/internal/schema/cause.d.ts +2 -0
- package/dist/internal/schema/cause.d.ts.map +1 -0
- package/dist/internal/schema/cause.js +24 -0
- package/dist/internal/schema/cause.js.map +1 -0
- package/dist/internal/schema/schema.d.ts +8 -4
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +21 -8
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/internal/stackTraceLimit.d.ts +2 -0
- package/dist/internal/stackTraceLimit.d.ts.map +1 -0
- package/dist/internal/stackTraceLimit.js +40 -0
- package/dist/internal/stackTraceLimit.js.map +1 -0
- package/dist/internal/tracer.d.ts.map +1 -1
- package/dist/internal/tracer.js +4 -3
- package/dist/internal/tracer.js.map +1 -1
- package/dist/testing/TestSchema.d.ts +3 -3
- package/dist/testing/TestSchema.js +1 -1
- package/dist/unstable/ai/AiError.d.ts +1 -1
- package/dist/unstable/ai/AiError.js +1 -1
- package/dist/unstable/ai/Chat.d.ts +1 -1
- package/dist/unstable/ai/Chat.js +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +4 -5
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/Prompt.js +2 -2
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js +4 -3
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/persistence/PersistedQueue.js +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +1 -1
- package/dist/unstable/rpc/Rpc.js +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcGroup.js +3 -4
- package/dist/unstable/rpc/RpcGroup.js.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.js +4 -3
- package/dist/unstable/rpc/RpcMiddleware.js.map +1 -1
- package/dist/unstable/sql/SqlResolver.d.ts.map +1 -1
- package/dist/unstable/sql/SqlResolver.js +15 -2
- package/dist/unstable/sql/SqlResolver.js.map +1 -1
- package/dist/unstable/workflow/Activity.d.ts +1 -0
- package/dist/unstable/workflow/Activity.d.ts.map +1 -1
- package/dist/unstable/workflow/Activity.js +1 -0
- package/dist/unstable/workflow/Activity.js.map +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js +1 -1
- package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +65 -65
- package/src/Cache.ts +1 -1
- package/src/Cause.ts +68 -68
- package/src/Channel.ts +5 -5
- package/src/Clock.ts +1 -1
- package/src/Combiner.ts +9 -9
- package/src/Config.ts +40 -108
- package/src/ConfigProvider.ts +139 -100
- package/src/Console.ts +1 -1
- package/src/Context.ts +4 -5
- package/src/Data.ts +15 -15
- package/src/DateTime.ts +6 -6
- package/src/Duration.ts +3 -3
- package/src/Effect.ts +89 -45
- package/src/Equal.ts +7 -7
- package/src/Equivalence.ts +17 -17
- package/src/Exit.ts +3 -3
- package/src/Formatter.ts +5 -5
- package/src/Function.ts +10 -10
- package/src/HashMap.ts +3 -3
- package/src/Iterable.ts +6 -6
- package/src/JsonPatch.ts +2 -2
- package/src/Layer.ts +5 -5
- package/src/LayerMap.ts +4 -3
- package/src/Logger.ts +1 -1
- package/src/Match.ts +8 -8
- package/src/Metric.ts +3 -3
- package/src/Optic.ts +30 -30
- package/src/Option.ts +7 -7
- package/src/Order.ts +23 -23
- package/src/Pool.ts +1 -1
- package/src/Predicate.ts +88 -88
- package/src/PubSub.ts +3 -3
- package/src/Random.ts +42 -0
- package/src/Reducer.ts +1 -1
- package/src/Result.ts +20 -20
- package/src/Runtime.ts +1 -1
- package/src/Schema.ts +389 -153
- package/src/SchemaAST.ts +237 -148
- package/src/SchemaGetter.ts +48 -48
- package/src/SchemaIssue.ts +3 -3
- package/src/SchemaParser.ts +197 -58
- package/src/SchemaRepresentation.ts +73 -3
- package/src/SchemaTransformation.ts +20 -20
- package/src/Stream.ts +4 -4
- package/src/String.ts +1 -1
- package/src/Struct.ts +1 -1
- package/src/Types.ts +13 -13
- package/src/internal/effect.ts +40 -21
- package/src/internal/schema/arbitrary.ts +23 -2
- package/src/internal/schema/cause.ts +26 -0
- package/src/internal/schema/schema.ts +36 -10
- package/src/internal/stackTraceLimit.ts +63 -0
- package/src/internal/tracer.ts +4 -3
- package/src/testing/TestSchema.ts +3 -3
- package/src/unstable/ai/AiError.ts +1 -1
- package/src/unstable/ai/Chat.ts +1 -1
- package/src/unstable/ai/Tool.ts +4 -3
- package/src/unstable/cli/Prompt.ts +1 -1
- package/src/unstable/httpapi/HttpApiMiddleware.ts +4 -3
- package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
- package/src/unstable/persistence/PersistedQueue.ts +1 -1
- package/src/unstable/rpc/Rpc.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -4
- package/src/unstable/rpc/RpcMiddleware.ts +4 -3
- package/src/unstable/sql/SqlResolver.ts +15 -2
- package/src/unstable/workflow/Activity.ts +2 -0
- package/src/unstable/workflow/WorkflowEngine.ts +1 -1
package/dist/Schema.js
CHANGED
|
@@ -123,7 +123,7 @@ export function declareConstructor() {
|
|
|
123
123
|
* Use when you are defining a schema for an opaque type with no type parameters
|
|
124
124
|
* and validation can be expressed as a type guard.
|
|
125
125
|
*
|
|
126
|
-
* **Example** (
|
|
126
|
+
* **Example** (Defining a schema for a custom `UserId` branded type)
|
|
127
127
|
*
|
|
128
128
|
* ```ts
|
|
129
129
|
* import { Schema } from "effect"
|
|
@@ -255,7 +255,7 @@ export function annotateEncoded(annotations) {
|
|
|
255
255
|
* as well as standard documentation fields such as `title`, `description`,
|
|
256
256
|
* and `examples`.
|
|
257
257
|
*
|
|
258
|
-
* **Example** (
|
|
258
|
+
* **Example** (Customizing the missing-key message for a required field)
|
|
259
259
|
*
|
|
260
260
|
* ```ts
|
|
261
261
|
* import { Schema } from "effect"
|
|
@@ -342,7 +342,7 @@ SchemaError };
|
|
|
342
342
|
/**
|
|
343
343
|
* Returns `true` if `u` is a {@link SchemaError}.
|
|
344
344
|
*
|
|
345
|
-
* **Example** (
|
|
345
|
+
* **Example** (Narrowing Schema errors in a catch block)
|
|
346
346
|
*
|
|
347
347
|
* ```ts
|
|
348
348
|
* import { Schema } from "effect"
|
|
@@ -538,10 +538,16 @@ export function toStandardJSONSchemaV1(self) {
|
|
|
538
538
|
* **Details**
|
|
539
539
|
*
|
|
540
540
|
* This function returns a predicate that performs a type-safe check, narrowing
|
|
541
|
-
* the type of the input value if the check passes.
|
|
542
|
-
*
|
|
541
|
+
* the type of the input value if the check passes. The predicate returns `false`
|
|
542
|
+
* for schema mismatches.
|
|
543
543
|
*
|
|
544
|
-
* **
|
|
544
|
+
* **Gotchas**
|
|
545
|
+
*
|
|
546
|
+
* Only causes made entirely of schema issues are converted to `false`. Causes
|
|
547
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
548
|
+
* instead.
|
|
549
|
+
*
|
|
550
|
+
* **Example** (Defining a basic type guard)
|
|
545
551
|
*
|
|
546
552
|
* ```ts
|
|
547
553
|
* import { Schema } from "effect"
|
|
@@ -564,7 +570,7 @@ export function toStandardJSONSchemaV1(self) {
|
|
|
564
570
|
*/
|
|
565
571
|
export const is = SchemaParser.is;
|
|
566
572
|
/**
|
|
567
|
-
* Creates an assertion function that throws an error if the input
|
|
573
|
+
* Creates an assertion function that throws an error if the input does not match
|
|
568
574
|
* the schema.
|
|
569
575
|
*
|
|
570
576
|
* **When to use**
|
|
@@ -574,10 +580,16 @@ export const is = SchemaParser.is;
|
|
|
574
580
|
*
|
|
575
581
|
* **Details**
|
|
576
582
|
*
|
|
577
|
-
* The input is narrowed if the assertion succeeds. If validation fails,
|
|
578
|
-
* assertion throws.
|
|
583
|
+
* The input is narrowed if the assertion succeeds. If schema validation fails,
|
|
584
|
+
* the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
|
|
579
585
|
*
|
|
580
|
-
* **
|
|
586
|
+
* **Gotchas**
|
|
587
|
+
*
|
|
588
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
589
|
+
* with the underlying `Cause` attached instead of being converted to schema
|
|
590
|
+
* validation errors.
|
|
591
|
+
*
|
|
592
|
+
* **Example** (Asserting and narrowing an input)
|
|
581
593
|
*
|
|
582
594
|
* ```ts
|
|
583
595
|
* import { Schema } from "effect"
|
|
@@ -625,7 +637,7 @@ export const asserts = SchemaParser.asserts;
|
|
|
625
637
|
export function decodeUnknownEffect(schema, options) {
|
|
626
638
|
const parser = SchemaParser.decodeUnknownEffect(schema, options);
|
|
627
639
|
return (input, options) => {
|
|
628
|
-
return
|
|
640
|
+
return InternalSchema.mapSchemaIssueEffect(parser(input, options));
|
|
629
641
|
};
|
|
630
642
|
}
|
|
631
643
|
/**
|
|
@@ -650,15 +662,46 @@ export function decodeUnknownEffect(schema, options) {
|
|
|
650
662
|
* @since 4.0.0
|
|
651
663
|
*/
|
|
652
664
|
export const decodeEffect = decodeUnknownEffect;
|
|
665
|
+
function getSchemaErrorOrThrow(cause, message) {
|
|
666
|
+
let schemaError;
|
|
667
|
+
for (const reason of cause.reasons) {
|
|
668
|
+
if (!Cause_.isFailReason(reason) || !isSchemaError(reason.error)) {
|
|
669
|
+
throw new globalThis.Error(message, {
|
|
670
|
+
cause
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
schemaError ??= reason.error;
|
|
674
|
+
}
|
|
675
|
+
if (schemaError === undefined) {
|
|
676
|
+
throw new globalThis.Error(message, {
|
|
677
|
+
cause
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
return schemaError;
|
|
681
|
+
}
|
|
682
|
+
function runSchemaErrorPromise(self) {
|
|
683
|
+
return Effect.runPromiseExit(self).then(exit => {
|
|
684
|
+
if (Exit_.isSuccess(exit)) {
|
|
685
|
+
return exit.value;
|
|
686
|
+
}
|
|
687
|
+
throw getSchemaErrorOrThrow(exit.cause, "Promise adapter can only reject schema errors");
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
function runSchemaErrorSync(self) {
|
|
691
|
+
const exit = Effect.runSyncExit(self);
|
|
692
|
+
if (Exit_.isSuccess(exit)) {
|
|
693
|
+
return exit.value;
|
|
694
|
+
}
|
|
695
|
+
throw getSchemaErrorOrThrow(exit.cause, "Sync adapter can only throw schema errors");
|
|
696
|
+
}
|
|
653
697
|
/**
|
|
654
698
|
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
655
|
-
* `Exit` that is either a `Success` with the decoded value or a `Failure
|
|
656
|
-
* a {@link SchemaError}.
|
|
699
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure`.
|
|
657
700
|
*
|
|
658
701
|
* **When to use**
|
|
659
702
|
*
|
|
660
|
-
* Use when you need to decode unknown input into an `Exit`
|
|
661
|
-
*
|
|
703
|
+
* Use when you need to decode unknown input into an `Exit` and capture schema
|
|
704
|
+
* mismatches as `SchemaError`.
|
|
662
705
|
*
|
|
663
706
|
* **Details**
|
|
664
707
|
*
|
|
@@ -667,6 +710,14 @@ export const decodeEffect = decodeUnknownEffect;
|
|
|
667
710
|
* type.
|
|
668
711
|
* Options may be provided either when creating the decoder or when applying it;
|
|
669
712
|
* application options override creation options.
|
|
713
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
714
|
+
* `SchemaError`.
|
|
715
|
+
*
|
|
716
|
+
* **Gotchas**
|
|
717
|
+
*
|
|
718
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
719
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
720
|
+
* including when they are mixed with schema issues.
|
|
670
721
|
*
|
|
671
722
|
* @see {@link SchemaParser.decodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
672
723
|
*
|
|
@@ -676,18 +727,18 @@ export const decodeEffect = decodeUnknownEffect;
|
|
|
676
727
|
export function decodeUnknownExit(schema, options) {
|
|
677
728
|
const parser = SchemaParser.decodeUnknownExit(schema, options);
|
|
678
729
|
return (input, options) => {
|
|
679
|
-
return
|
|
730
|
+
return InternalSchema.mapSchemaIssueExit(parser(input, options));
|
|
680
731
|
};
|
|
681
732
|
}
|
|
682
733
|
/**
|
|
683
734
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
684
|
-
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
685
|
-
*
|
|
735
|
+
* synchronously, returning an `Exit` that is either a `Success` with the decoded
|
|
736
|
+
* value or a `Failure`.
|
|
686
737
|
*
|
|
687
738
|
* **When to use**
|
|
688
739
|
*
|
|
689
|
-
* Use when you need to decode already typed `Encoded` input into an `Exit`
|
|
690
|
-
*
|
|
740
|
+
* Use when you need to decode already typed `Encoded` input into an `Exit` and
|
|
741
|
+
* capture schema mismatches as `SchemaError`.
|
|
691
742
|
*
|
|
692
743
|
* **Details**
|
|
693
744
|
*
|
|
@@ -695,6 +746,14 @@ export function decodeUnknownExit(schema, options) {
|
|
|
695
746
|
* `unknown` input use {@link decodeUnknownExit}.
|
|
696
747
|
* Options may be provided either when creating the decoder or when applying it;
|
|
697
748
|
* application options override creation options.
|
|
749
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
750
|
+
* `SchemaError`.
|
|
751
|
+
*
|
|
752
|
+
* **Gotchas**
|
|
753
|
+
*
|
|
754
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
755
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
756
|
+
* including when they are mixed with schema issues.
|
|
698
757
|
*
|
|
699
758
|
* @see {@link SchemaParser.decodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
700
759
|
*
|
|
@@ -704,7 +763,7 @@ export function decodeUnknownExit(schema, options) {
|
|
|
704
763
|
export const decodeExit = decodeUnknownExit;
|
|
705
764
|
/**
|
|
706
765
|
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
707
|
-
* `Some` with the decoded value on success or `None`
|
|
766
|
+
* `Some` with the decoded value on success or `None` for schema mismatches.
|
|
708
767
|
*
|
|
709
768
|
* **When to use**
|
|
710
769
|
*
|
|
@@ -719,6 +778,12 @@ export const decodeExit = decodeUnknownExit;
|
|
|
719
778
|
* Options may be provided either when creating the decoder or when applying it;
|
|
720
779
|
* application options override creation options.
|
|
721
780
|
*
|
|
781
|
+
* **Gotchas**
|
|
782
|
+
*
|
|
783
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
784
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
785
|
+
* instead.
|
|
786
|
+
*
|
|
722
787
|
* @category decoding
|
|
723
788
|
* @since 3.10.0
|
|
724
789
|
*/
|
|
@@ -726,7 +791,7 @@ export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
|
|
|
726
791
|
/**
|
|
727
792
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
728
793
|
* returning an `Option` that is `Some` with the decoded value on success or
|
|
729
|
-
* `None`
|
|
794
|
+
* `None` for schema mismatches.
|
|
730
795
|
*
|
|
731
796
|
* **When to use**
|
|
732
797
|
*
|
|
@@ -739,18 +804,25 @@ export const decodeUnknownOption = SchemaParser.decodeUnknownOption;
|
|
|
739
804
|
* Options may be provided either when creating the decoder or when applying it;
|
|
740
805
|
* application options override creation options.
|
|
741
806
|
*
|
|
807
|
+
* **Gotchas**
|
|
808
|
+
*
|
|
809
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
810
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
811
|
+
* instead.
|
|
812
|
+
*
|
|
742
813
|
* @category decoding
|
|
743
814
|
* @since 3.10.0
|
|
744
815
|
*/
|
|
745
816
|
export const decodeOption = decodeUnknownOption;
|
|
746
817
|
/**
|
|
747
818
|
* Decodes an `unknown` input against a schema, returning a `Result` that
|
|
748
|
-
* succeeds with the decoded value or fails with a {@link SchemaError}
|
|
819
|
+
* succeeds with the decoded value or fails with a {@link SchemaError} for schema
|
|
820
|
+
* mismatches.
|
|
749
821
|
*
|
|
750
822
|
* **When to use**
|
|
751
823
|
*
|
|
752
|
-
* Use when you do not know the input type statically and want
|
|
753
|
-
*
|
|
824
|
+
* Use when you do not know the input type statically and want schema mismatches
|
|
825
|
+
* returned as `Result.fail` with `SchemaError`.
|
|
754
826
|
*
|
|
755
827
|
* **Details**
|
|
756
828
|
*
|
|
@@ -758,6 +830,13 @@ export const decodeOption = decodeUnknownOption;
|
|
|
758
830
|
* {@link decodeResult}.
|
|
759
831
|
* Options may be provided either when creating the decoder or when applying it;
|
|
760
832
|
* application options override creation options.
|
|
833
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
834
|
+
*
|
|
835
|
+
* **Gotchas**
|
|
836
|
+
*
|
|
837
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
838
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
839
|
+
* instead.
|
|
761
840
|
*
|
|
762
841
|
* @see {@link SchemaParser.decodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
763
842
|
*
|
|
@@ -773,18 +852,25 @@ export function decodeUnknownResult(schema, options) {
|
|
|
773
852
|
/**
|
|
774
853
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
775
854
|
* returning a `Result` that succeeds with the decoded value or fails with a
|
|
776
|
-
* {@link SchemaError}.
|
|
855
|
+
* {@link SchemaError} for schema mismatches.
|
|
777
856
|
*
|
|
778
857
|
* **When to use**
|
|
779
858
|
*
|
|
780
|
-
* Use when you already have input typed as the schema's `Encoded` type and
|
|
781
|
-
*
|
|
859
|
+
* Use when you already have input typed as the schema's `Encoded` type and want
|
|
860
|
+
* schema mismatches returned as `Result.fail` with `SchemaError`.
|
|
782
861
|
*
|
|
783
862
|
* **Details**
|
|
784
863
|
*
|
|
785
864
|
* For `unknown` input use {@link decodeUnknownResult}.
|
|
786
865
|
* Options may be provided either when creating the decoder or when applying it;
|
|
787
866
|
* application options override creation options.
|
|
867
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
868
|
+
*
|
|
869
|
+
* **Gotchas**
|
|
870
|
+
*
|
|
871
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
872
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
873
|
+
* instead.
|
|
788
874
|
*
|
|
789
875
|
* @see {@link SchemaParser.decodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
790
876
|
*
|
|
@@ -794,12 +880,13 @@ export function decodeUnknownResult(schema, options) {
|
|
|
794
880
|
export const decodeResult = decodeUnknownResult;
|
|
795
881
|
/**
|
|
796
882
|
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
797
|
-
* resolves with the decoded value or rejects with a {@link SchemaError}
|
|
883
|
+
* resolves with the decoded value or rejects with a {@link SchemaError} for
|
|
884
|
+
* schema mismatches.
|
|
798
885
|
*
|
|
799
886
|
* **When to use**
|
|
800
887
|
*
|
|
801
888
|
* Use when you need decoding of unknown input to return a JavaScript `Promise`
|
|
802
|
-
* that rejects with `SchemaError
|
|
889
|
+
* that rejects with `SchemaError` for schema mismatches.
|
|
803
890
|
*
|
|
804
891
|
* **Details**
|
|
805
892
|
*
|
|
@@ -808,7 +895,12 @@ export const decodeResult = decodeUnknownResult;
|
|
|
808
895
|
* Options may be provided either when creating the decoder or when applying it;
|
|
809
896
|
* application options override creation options.
|
|
810
897
|
*
|
|
811
|
-
*
|
|
898
|
+
* **Gotchas**
|
|
899
|
+
*
|
|
900
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
901
|
+
* `SchemaError`.
|
|
902
|
+
*
|
|
903
|
+
* @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
812
904
|
*
|
|
813
905
|
* @category decoding
|
|
814
906
|
* @since 3.10.0
|
|
@@ -816,19 +908,19 @@ export const decodeResult = decodeUnknownResult;
|
|
|
816
908
|
export function decodeUnknownPromise(schema, options) {
|
|
817
909
|
const parser = decodeUnknownEffect(schema, options);
|
|
818
910
|
return (input, options) => {
|
|
819
|
-
return
|
|
911
|
+
return runSchemaErrorPromise(parser(input, options));
|
|
820
912
|
};
|
|
821
913
|
}
|
|
822
914
|
/**
|
|
823
915
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
824
916
|
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
825
|
-
* {@link SchemaError}.
|
|
917
|
+
* {@link SchemaError} for schema mismatches.
|
|
826
918
|
*
|
|
827
919
|
* **When to use**
|
|
828
920
|
*
|
|
829
921
|
* Use when you already have input typed as the schema's `Encoded` type and
|
|
830
922
|
* need decoding to return a JavaScript `Promise` that rejects with
|
|
831
|
-
* `SchemaError
|
|
923
|
+
* `SchemaError` for schema mismatches.
|
|
832
924
|
*
|
|
833
925
|
* **Details**
|
|
834
926
|
*
|
|
@@ -836,7 +928,12 @@ export function decodeUnknownPromise(schema, options) {
|
|
|
836
928
|
* Options may be provided either when creating the decoder or when applying it;
|
|
837
929
|
* application options override creation options.
|
|
838
930
|
*
|
|
839
|
-
*
|
|
931
|
+
* **Gotchas**
|
|
932
|
+
*
|
|
933
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
934
|
+
* `SchemaError`.
|
|
935
|
+
*
|
|
936
|
+
* @see {@link SchemaParser.decodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
840
937
|
*
|
|
841
938
|
* @category decoding
|
|
842
939
|
* @since 3.10.0
|
|
@@ -844,7 +941,7 @@ export function decodeUnknownPromise(schema, options) {
|
|
|
844
941
|
export const decodePromise = decodeUnknownPromise;
|
|
845
942
|
/**
|
|
846
943
|
* Decodes an `unknown` input against a schema synchronously, returning the
|
|
847
|
-
* decoded value or throwing a {@link SchemaError}.
|
|
944
|
+
* decoded value or throwing a {@link SchemaError} for schema mismatches.
|
|
848
945
|
*
|
|
849
946
|
* **When to use**
|
|
850
947
|
*
|
|
@@ -854,10 +951,15 @@ export const decodePromise = decodeUnknownPromise;
|
|
|
854
951
|
* **Details**
|
|
855
952
|
*
|
|
856
953
|
* For input already typed as the schema's `Encoded` type use `decodeSync`.
|
|
857
|
-
* Only service-free schemas can be decoded synchronously. For
|
|
858
|
-
*
|
|
859
|
-
* `decodeUnknownEffect`. Options may be provided either
|
|
860
|
-
* decoder or when applying it; application options override
|
|
954
|
+
* Only service-free schemas can be decoded synchronously. For alternatives that
|
|
955
|
+
* do not throw on schema mismatches, see `decodeUnknownOption`,
|
|
956
|
+
* `decodeUnknownExit`, or `decodeUnknownEffect`. Options may be provided either
|
|
957
|
+
* when creating the decoder or when applying it; application options override
|
|
958
|
+
* creation options.
|
|
959
|
+
*
|
|
960
|
+
* **Gotchas**
|
|
961
|
+
*
|
|
962
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
861
963
|
*
|
|
862
964
|
* **Example** (Decoding with a transformation schema)
|
|
863
965
|
*
|
|
@@ -884,12 +986,13 @@ export const decodePromise = decodeUnknownPromise;
|
|
|
884
986
|
export function decodeUnknownSync(schema, options) {
|
|
885
987
|
const parser = decodeUnknownEffect(schema, options);
|
|
886
988
|
return (input, options) => {
|
|
887
|
-
return
|
|
989
|
+
return runSchemaErrorSync(parser(input, options));
|
|
888
990
|
};
|
|
889
991
|
}
|
|
890
992
|
/**
|
|
891
993
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
892
|
-
* synchronously, returning the decoded value or throwing a {@link SchemaError}
|
|
994
|
+
* synchronously, returning the decoded value or throwing a {@link SchemaError}
|
|
995
|
+
* for schema mismatches.
|
|
893
996
|
*
|
|
894
997
|
* **When to use**
|
|
895
998
|
*
|
|
@@ -903,6 +1006,10 @@ export function decodeUnknownSync(schema, options) {
|
|
|
903
1006
|
* provided either when creating the decoder or when applying it; application
|
|
904
1007
|
* options override creation options.
|
|
905
1008
|
*
|
|
1009
|
+
* **Gotchas**
|
|
1010
|
+
*
|
|
1011
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1012
|
+
*
|
|
906
1013
|
* @see {@link SchemaParser.decodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
907
1014
|
*
|
|
908
1015
|
* @category decoding
|
|
@@ -944,7 +1051,7 @@ export const decodeSync = decodeUnknownSync;
|
|
|
944
1051
|
export function encodeUnknownEffect(schema, options) {
|
|
945
1052
|
const parser = SchemaParser.encodeUnknownEffect(schema, options);
|
|
946
1053
|
return (input, options) => {
|
|
947
|
-
return
|
|
1054
|
+
return InternalSchema.mapSchemaIssueEffect(parser(input, options));
|
|
948
1055
|
};
|
|
949
1056
|
}
|
|
950
1057
|
/**
|
|
@@ -971,13 +1078,12 @@ export function encodeUnknownEffect(schema, options) {
|
|
|
971
1078
|
export const encodeEffect = encodeUnknownEffect;
|
|
972
1079
|
/**
|
|
973
1080
|
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
974
|
-
* `Exit` that is either a `Success` with the encoded value or a `Failure
|
|
975
|
-
* a {@link SchemaError}.
|
|
1081
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure`.
|
|
976
1082
|
*
|
|
977
1083
|
* **When to use**
|
|
978
1084
|
*
|
|
979
|
-
* Use when you need to encode unknown input into an `Exit`
|
|
980
|
-
*
|
|
1085
|
+
* Use when you need to encode unknown input into an `Exit` and capture schema
|
|
1086
|
+
* mismatches as `SchemaError`.
|
|
981
1087
|
*
|
|
982
1088
|
* **Details**
|
|
983
1089
|
*
|
|
@@ -985,6 +1091,14 @@ export const encodeEffect = encodeUnknownEffect;
|
|
|
985
1091
|
* {@link encodeExit} when the value is already typed as the schema's `Type`.
|
|
986
1092
|
* Options may be provided either when creating the encoder or when applying it;
|
|
987
1093
|
* application options override creation options.
|
|
1094
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1095
|
+
* `SchemaError`.
|
|
1096
|
+
*
|
|
1097
|
+
* **Gotchas**
|
|
1098
|
+
*
|
|
1099
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1100
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1101
|
+
* including when they are mixed with schema issues.
|
|
988
1102
|
*
|
|
989
1103
|
* @see {@link SchemaParser.encodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
990
1104
|
*
|
|
@@ -994,18 +1108,18 @@ export const encodeEffect = encodeUnknownEffect;
|
|
|
994
1108
|
export function encodeUnknownExit(schema, options) {
|
|
995
1109
|
const parser = SchemaParser.encodeUnknownExit(schema, options);
|
|
996
1110
|
return (input, options) => {
|
|
997
|
-
return
|
|
1111
|
+
return InternalSchema.mapSchemaIssueExit(parser(input, options));
|
|
998
1112
|
};
|
|
999
1113
|
}
|
|
1000
1114
|
/**
|
|
1001
1115
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1002
1116
|
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
1003
|
-
* `Failure
|
|
1117
|
+
* `Failure`.
|
|
1004
1118
|
*
|
|
1005
1119
|
* **When to use**
|
|
1006
1120
|
*
|
|
1007
|
-
* Use when you need to encode already typed schema values into an `Exit`
|
|
1008
|
-
*
|
|
1121
|
+
* Use when you need to encode already typed schema values into an `Exit` and
|
|
1122
|
+
* capture schema mismatches as `SchemaError`.
|
|
1009
1123
|
*
|
|
1010
1124
|
* **Details**
|
|
1011
1125
|
*
|
|
@@ -1013,6 +1127,14 @@ export function encodeUnknownExit(schema, options) {
|
|
|
1013
1127
|
* `unknown` input use {@link encodeUnknownExit}.
|
|
1014
1128
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1015
1129
|
* application options override creation options.
|
|
1130
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1131
|
+
* `SchemaError`.
|
|
1132
|
+
*
|
|
1133
|
+
* **Gotchas**
|
|
1134
|
+
*
|
|
1135
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1136
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1137
|
+
* including when they are mixed with schema issues.
|
|
1016
1138
|
*
|
|
1017
1139
|
* @see {@link SchemaParser.encodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1018
1140
|
*
|
|
@@ -1022,7 +1144,7 @@ export function encodeUnknownExit(schema, options) {
|
|
|
1022
1144
|
export const encodeExit = encodeUnknownExit;
|
|
1023
1145
|
/**
|
|
1024
1146
|
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
1025
|
-
* `Some` with the encoded value on success or `None`
|
|
1147
|
+
* `Some` with the encoded value on success or `None` for schema mismatches.
|
|
1026
1148
|
*
|
|
1027
1149
|
* **When to use**
|
|
1028
1150
|
*
|
|
@@ -1037,14 +1159,20 @@ export const encodeExit = encodeUnknownExit;
|
|
|
1037
1159
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1038
1160
|
* application options override creation options.
|
|
1039
1161
|
*
|
|
1162
|
+
* **Gotchas**
|
|
1163
|
+
*
|
|
1164
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1165
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1166
|
+
* instead.
|
|
1167
|
+
*
|
|
1040
1168
|
* @category encoding
|
|
1041
1169
|
* @since 3.10.0
|
|
1042
1170
|
*/
|
|
1043
1171
|
export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
|
|
1044
1172
|
/**
|
|
1045
1173
|
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1046
|
-
* `Option` that is `Some` with the encoded value on success or `None`
|
|
1047
|
-
*
|
|
1174
|
+
* `Option` that is `Some` with the encoded value on success or `None` for schema
|
|
1175
|
+
* mismatches.
|
|
1048
1176
|
*
|
|
1049
1177
|
* **When to use**
|
|
1050
1178
|
*
|
|
@@ -1057,24 +1185,38 @@ export const encodeUnknownOption = SchemaParser.encodeUnknownOption;
|
|
|
1057
1185
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1058
1186
|
* application options override creation options.
|
|
1059
1187
|
*
|
|
1188
|
+
* **Gotchas**
|
|
1189
|
+
*
|
|
1190
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1191
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1192
|
+
* instead.
|
|
1193
|
+
*
|
|
1060
1194
|
* @category encoding
|
|
1061
1195
|
* @since 3.10.0
|
|
1062
1196
|
*/
|
|
1063
1197
|
export const encodeOption = encodeUnknownOption;
|
|
1064
1198
|
/**
|
|
1065
1199
|
* Encodes an `unknown` input against a schema, returning a `Result` that
|
|
1066
|
-
* succeeds with the encoded value or fails with a {@link SchemaError}
|
|
1200
|
+
* succeeds with the encoded value or fails with a {@link SchemaError} for schema
|
|
1201
|
+
* mismatches.
|
|
1067
1202
|
*
|
|
1068
1203
|
* **When to use**
|
|
1069
1204
|
*
|
|
1070
|
-
* Use when you do not know the input type statically and want
|
|
1071
|
-
*
|
|
1205
|
+
* Use when you do not know the input type statically and want schema mismatches
|
|
1206
|
+
* returned as `Result.fail` with `SchemaError`.
|
|
1072
1207
|
*
|
|
1073
1208
|
* **Details**
|
|
1074
1209
|
*
|
|
1075
1210
|
* For values already typed as the schema's `Type` use {@link encodeResult}.
|
|
1076
1211
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1077
1212
|
* application options override creation options.
|
|
1213
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1214
|
+
*
|
|
1215
|
+
* **Gotchas**
|
|
1216
|
+
*
|
|
1217
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1218
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1219
|
+
* instead.
|
|
1078
1220
|
*
|
|
1079
1221
|
* @see {@link SchemaParser.encodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1080
1222
|
*
|
|
@@ -1090,18 +1232,25 @@ export function encodeUnknownResult(schema, options) {
|
|
|
1090
1232
|
/**
|
|
1091
1233
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1092
1234
|
* `Result` that succeeds with the encoded value or fails with a
|
|
1093
|
-
* {@link SchemaError}.
|
|
1235
|
+
* {@link SchemaError} for schema mismatches.
|
|
1094
1236
|
*
|
|
1095
1237
|
* **When to use**
|
|
1096
1238
|
*
|
|
1097
|
-
* Use when you already have a value typed as the schema's `Type` and want
|
|
1098
|
-
*
|
|
1239
|
+
* Use when you already have a value typed as the schema's `Type` and want schema
|
|
1240
|
+
* mismatches returned as `Result.fail` with `SchemaError`.
|
|
1099
1241
|
*
|
|
1100
1242
|
* **Details**
|
|
1101
1243
|
*
|
|
1102
1244
|
* For `unknown` input use {@link encodeUnknownResult}.
|
|
1103
1245
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1104
1246
|
* application options override creation options.
|
|
1247
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1248
|
+
*
|
|
1249
|
+
* **Gotchas**
|
|
1250
|
+
*
|
|
1251
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1252
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1253
|
+
* instead.
|
|
1105
1254
|
*
|
|
1106
1255
|
* @see {@link SchemaParser.encodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1107
1256
|
*
|
|
@@ -1111,12 +1260,13 @@ export function encodeUnknownResult(schema, options) {
|
|
|
1111
1260
|
export const encodeResult = encodeUnknownResult;
|
|
1112
1261
|
/**
|
|
1113
1262
|
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1114
|
-
* resolves with the encoded value or rejects with a {@link SchemaError}
|
|
1263
|
+
* resolves with the encoded value or rejects with a {@link SchemaError} for
|
|
1264
|
+
* schema mismatches.
|
|
1115
1265
|
*
|
|
1116
1266
|
* **When to use**
|
|
1117
1267
|
*
|
|
1118
1268
|
* Use when you need encoding of unknown input to return a JavaScript `Promise`
|
|
1119
|
-
* that rejects with `SchemaError
|
|
1269
|
+
* that rejects with `SchemaError` for schema mismatches.
|
|
1120
1270
|
*
|
|
1121
1271
|
* **Details**
|
|
1122
1272
|
*
|
|
@@ -1124,7 +1274,12 @@ export const encodeResult = encodeUnknownResult;
|
|
|
1124
1274
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1125
1275
|
* application options override creation options.
|
|
1126
1276
|
*
|
|
1127
|
-
*
|
|
1277
|
+
* **Gotchas**
|
|
1278
|
+
*
|
|
1279
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1280
|
+
* `SchemaError`.
|
|
1281
|
+
*
|
|
1282
|
+
* @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1128
1283
|
*
|
|
1129
1284
|
* @category encoding
|
|
1130
1285
|
* @since 3.10.0
|
|
@@ -1132,18 +1287,19 @@ export const encodeResult = encodeUnknownResult;
|
|
|
1132
1287
|
export function encodeUnknownPromise(schema, options) {
|
|
1133
1288
|
const parser = encodeUnknownEffect(schema, options);
|
|
1134
1289
|
return (input, options) => {
|
|
1135
|
-
return
|
|
1290
|
+
return runSchemaErrorPromise(parser(input, options));
|
|
1136
1291
|
};
|
|
1137
1292
|
}
|
|
1138
1293
|
/**
|
|
1139
1294
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1140
1295
|
* `Promise` that resolves with the encoded value or rejects with a
|
|
1141
|
-
* {@link SchemaError}.
|
|
1296
|
+
* {@link SchemaError} for schema mismatches.
|
|
1142
1297
|
*
|
|
1143
1298
|
* **When to use**
|
|
1144
1299
|
*
|
|
1145
1300
|
* Use when you already have a value typed as the schema's `Type` and need
|
|
1146
|
-
* encoding to return a JavaScript `Promise` that rejects with `SchemaError
|
|
1301
|
+
* encoding to return a JavaScript `Promise` that rejects with `SchemaError` for
|
|
1302
|
+
* schema mismatches.
|
|
1147
1303
|
*
|
|
1148
1304
|
* **Details**
|
|
1149
1305
|
*
|
|
@@ -1151,7 +1307,12 @@ export function encodeUnknownPromise(schema, options) {
|
|
|
1151
1307
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1152
1308
|
* application options override creation options.
|
|
1153
1309
|
*
|
|
1154
|
-
*
|
|
1310
|
+
* **Gotchas**
|
|
1311
|
+
*
|
|
1312
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1313
|
+
* `SchemaError`.
|
|
1314
|
+
*
|
|
1315
|
+
* @see {@link SchemaParser.encodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1155
1316
|
*
|
|
1156
1317
|
* @category encoding
|
|
1157
1318
|
* @since 3.10.0
|
|
@@ -1159,7 +1320,7 @@ export function encodeUnknownPromise(schema, options) {
|
|
|
1159
1320
|
export const encodePromise = encodeUnknownPromise;
|
|
1160
1321
|
/**
|
|
1161
1322
|
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
1162
|
-
* {@link SchemaError}
|
|
1323
|
+
* {@link SchemaError} for schema mismatches.
|
|
1163
1324
|
*
|
|
1164
1325
|
* **When to use**
|
|
1165
1326
|
*
|
|
@@ -1168,11 +1329,15 @@ export const encodePromise = encodeUnknownPromise;
|
|
|
1168
1329
|
*
|
|
1169
1330
|
* **Details**
|
|
1170
1331
|
*
|
|
1171
|
-
* For
|
|
1172
|
-
* {@link
|
|
1173
|
-
* already typed as the schema's `Type`
|
|
1174
|
-
* Options may be provided either when creating the
|
|
1175
|
-
* application options override creation options.
|
|
1332
|
+
* For alternatives that do not throw on schema mismatches, see
|
|
1333
|
+
* {@link encodeUnknownOption}, {@link encodeUnknownExit}, or
|
|
1334
|
+
* {@link encodeUnknownEffect}. For values already typed as the schema's `Type`
|
|
1335
|
+
* use {@link encodeSync}. Options may be provided either when creating the
|
|
1336
|
+
* encoder or when applying it; application options override creation options.
|
|
1337
|
+
*
|
|
1338
|
+
* **Gotchas**
|
|
1339
|
+
*
|
|
1340
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1176
1341
|
*
|
|
1177
1342
|
* @see {@link SchemaParser.encodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1178
1343
|
*
|
|
@@ -1182,12 +1347,12 @@ export const encodePromise = encodeUnknownPromise;
|
|
|
1182
1347
|
export function encodeUnknownSync(schema, options) {
|
|
1183
1348
|
const parser = encodeUnknownEffect(schema, options);
|
|
1184
1349
|
return (input, options) => {
|
|
1185
|
-
return
|
|
1350
|
+
return runSchemaErrorSync(parser(input, options));
|
|
1186
1351
|
};
|
|
1187
1352
|
}
|
|
1188
1353
|
/**
|
|
1189
1354
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1190
|
-
* throwing a {@link SchemaError}
|
|
1355
|
+
* throwing a {@link SchemaError} for schema mismatches.
|
|
1191
1356
|
*
|
|
1192
1357
|
* **When to use**
|
|
1193
1358
|
*
|
|
@@ -1200,6 +1365,10 @@ export function encodeUnknownSync(schema, options) {
|
|
|
1200
1365
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1201
1366
|
* application options override creation options.
|
|
1202
1367
|
*
|
|
1368
|
+
* **Gotchas**
|
|
1369
|
+
*
|
|
1370
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1371
|
+
*
|
|
1203
1372
|
* @see {@link SchemaParser.encodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1204
1373
|
*
|
|
1205
1374
|
* @category encoding
|
|
@@ -1308,7 +1477,7 @@ export const requiredKey = /*#__PURE__*/Struct_.lambda(self => self.schema);
|
|
|
1308
1477
|
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
1309
1478
|
* only, not `undefined`).
|
|
1310
1479
|
*
|
|
1311
|
-
* **Example** (
|
|
1480
|
+
* **Example** (Defining an optional field accepting undefined)
|
|
1312
1481
|
*
|
|
1313
1482
|
* ```ts
|
|
1314
1483
|
* import { Schema } from "effect"
|
|
@@ -1400,7 +1569,7 @@ export function flip(schema) {
|
|
|
1400
1569
|
/**
|
|
1401
1570
|
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
1402
1571
|
*
|
|
1403
|
-
* **Example** (
|
|
1572
|
+
* **Example** (Defining a string literal)
|
|
1404
1573
|
*
|
|
1405
1574
|
* ```ts
|
|
1406
1575
|
* import { Schema } from "effect"
|
|
@@ -1431,15 +1600,21 @@ function templateLiteralFromParts(parts) {
|
|
|
1431
1600
|
return new SchemaAST.TemplateLiteral(parts.map(part => isSchema(part) ? part.ast : new SchemaAST.Literal(part)));
|
|
1432
1601
|
}
|
|
1433
1602
|
/**
|
|
1434
|
-
* Creates a schema that validates strings matching
|
|
1435
|
-
*
|
|
1603
|
+
* Creates a schema that validates strings by matching ordered template literal
|
|
1604
|
+
* parts.
|
|
1436
1605
|
*
|
|
1437
1606
|
* **When to use**
|
|
1438
1607
|
*
|
|
1439
1608
|
* Use when the decoded value should remain the matched string and you do not
|
|
1440
1609
|
* need the individual template parts parsed into a tuple.
|
|
1441
1610
|
*
|
|
1442
|
-
* **
|
|
1611
|
+
* **Details**
|
|
1612
|
+
*
|
|
1613
|
+
* Each part can be a literal `string`, `number`, or `bigint`, or a schema whose
|
|
1614
|
+
* encoded type is `string`, `number`, or `bigint`. Checks on string, number,
|
|
1615
|
+
* and bigint schema parts are applied while matching each segment.
|
|
1616
|
+
*
|
|
1617
|
+
* **Example** (Defining a URL path pattern)
|
|
1443
1618
|
*
|
|
1444
1619
|
* ```ts
|
|
1445
1620
|
* import { Schema } from "effect"
|
|
@@ -1458,7 +1633,7 @@ export function TemplateLiteral(parts) {
|
|
|
1458
1633
|
});
|
|
1459
1634
|
}
|
|
1460
1635
|
/**
|
|
1461
|
-
* Schema for parsing template literal
|
|
1636
|
+
* Schema for parsing matched template literal strings into typed tuple parts.
|
|
1462
1637
|
*
|
|
1463
1638
|
* **When to use**
|
|
1464
1639
|
*
|
|
@@ -1468,9 +1643,10 @@ export function TemplateLiteral(parts) {
|
|
|
1468
1643
|
* **Details**
|
|
1469
1644
|
*
|
|
1470
1645
|
* Unlike {@link TemplateLiteral}, this schema decodes the matched string into a
|
|
1471
|
-
* readonly tuple with one element per schema part.
|
|
1646
|
+
* readonly tuple with one element per schema part. Checks on string, number,
|
|
1647
|
+
* and bigint schema parts are applied while matching each segment.
|
|
1472
1648
|
*
|
|
1473
|
-
* **Example** (
|
|
1649
|
+
* **Example** (Parsing path parameters)
|
|
1474
1650
|
*
|
|
1475
1651
|
* ```ts
|
|
1476
1652
|
* import { Schema } from "effect"
|
|
@@ -1491,7 +1667,7 @@ export function TemplateLiteralParser(parts) {
|
|
|
1491
1667
|
/**
|
|
1492
1668
|
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
1493
1669
|
*
|
|
1494
|
-
* **Example** (
|
|
1670
|
+
* **Example** (Defining a direction enum)
|
|
1495
1671
|
*
|
|
1496
1672
|
* ```ts
|
|
1497
1673
|
* import { Schema } from "effect"
|
|
@@ -1632,7 +1808,7 @@ export const ObjectKeyword = /*#__PURE__*/make(SchemaAST.objectKeyword);
|
|
|
1632
1808
|
/**
|
|
1633
1809
|
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
1634
1810
|
*
|
|
1635
|
-
* **Example** (
|
|
1811
|
+
* **Example** (Defining a specific symbol)
|
|
1636
1812
|
*
|
|
1637
1813
|
* ```ts
|
|
1638
1814
|
* import { Schema } from "effect"
|
|
@@ -1668,7 +1844,7 @@ function makeStruct(ast, fields) {
|
|
|
1668
1844
|
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
1669
1845
|
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
1670
1846
|
*
|
|
1671
|
-
* **Example** (
|
|
1847
|
+
* **Example** (Defining a basic struct)
|
|
1672
1848
|
*
|
|
1673
1849
|
* ```ts
|
|
1674
1850
|
* import { Schema } from "effect"
|
|
@@ -1735,7 +1911,7 @@ const canonicalPropertyKey = key => typeof key === "symbol" ? key : globalThis.S
|
|
|
1735
1911
|
* If two existing fields would produce the same encoded key, construction
|
|
1736
1912
|
* fails.
|
|
1737
1913
|
*
|
|
1738
|
-
* **Example** (
|
|
1914
|
+
* **Example** (Renaming `name` to `full_name` in the encoded form)
|
|
1739
1915
|
*
|
|
1740
1916
|
* ```ts
|
|
1741
1917
|
* import { Schema } from "effect"
|
|
@@ -1789,7 +1965,7 @@ export function encodeKeys(mapping) {
|
|
|
1789
1965
|
* computed or enriched fields to live in the decoded type without appearing in
|
|
1790
1966
|
* the encoded form.
|
|
1791
1967
|
*
|
|
1792
|
-
* **Example** (
|
|
1968
|
+
* **Example** (Adding a computed `fullName` field)
|
|
1793
1969
|
*
|
|
1794
1970
|
* ```ts
|
|
1795
1971
|
* import { Option, Schema } from "effect"
|
|
@@ -1846,9 +2022,20 @@ derive) {
|
|
|
1846
2022
|
};
|
|
1847
2023
|
}
|
|
1848
2024
|
/**
|
|
1849
|
-
* Defines a record
|
|
2025
|
+
* Defines a record schema whose dynamic properties are selected by a key schema
|
|
2026
|
+
* and decoded with a value schema.
|
|
1850
2027
|
*
|
|
1851
|
-
* **
|
|
2028
|
+
* **Details**
|
|
2029
|
+
*
|
|
2030
|
+
* For dynamic keys, the key schema selects matching own properties and the
|
|
2031
|
+
* value schema decodes or encodes only those selected properties. Checks on
|
|
2032
|
+
* string, number, symbol, and template literal key schemas narrow which
|
|
2033
|
+
* properties are selected.
|
|
2034
|
+
*
|
|
2035
|
+
* For transformed key schemas, property selection is based on encoded property
|
|
2036
|
+
* names before the selected key is decoded.
|
|
2037
|
+
*
|
|
2038
|
+
* **Example** (Defining a string-keyed record of numbers)
|
|
1852
2039
|
*
|
|
1853
2040
|
* ```ts
|
|
1854
2041
|
* import { Schema } from "effect"
|
|
@@ -1877,7 +2064,7 @@ export function Record(key, value, options) {
|
|
|
1877
2064
|
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
1878
2065
|
* producing a schema whose decoded type intersects the struct and all records.
|
|
1879
2066
|
*
|
|
1880
|
-
* **Example** (
|
|
2067
|
+
* **Example** (Defining structs with string-indexed extra keys)
|
|
1881
2068
|
*
|
|
1882
2069
|
* ```ts
|
|
1883
2070
|
* import { Schema } from "effect"
|
|
@@ -1912,7 +2099,7 @@ function makeTuple(ast, elements) {
|
|
|
1912
2099
|
/**
|
|
1913
2100
|
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
1914
2101
|
*
|
|
1915
|
-
* **Example** (
|
|
2102
|
+
* **Example** (Defining a pair of string and number)
|
|
1916
2103
|
*
|
|
1917
2104
|
* ```ts
|
|
1918
2105
|
* import { Schema } from "effect"
|
|
@@ -1941,7 +2128,7 @@ export function Tuple(elements) {
|
|
|
1941
2128
|
* example, `[Schema.Boolean, Schema.String]` represents zero or more booleans
|
|
1942
2129
|
* followed by a final string.
|
|
1943
2130
|
*
|
|
1944
|
-
* **Example** (
|
|
2131
|
+
* **Example** (Defining tuples with rest elements)
|
|
1945
2132
|
*
|
|
1946
2133
|
* ```ts
|
|
1947
2134
|
* import { Schema } from "effect"
|
|
@@ -1977,7 +2164,7 @@ export {
|
|
|
1977
2164
|
/**
|
|
1978
2165
|
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
1979
2166
|
*
|
|
1980
|
-
* **Example** (
|
|
2167
|
+
* **Example** (Defining an array of strings)
|
|
1981
2168
|
*
|
|
1982
2169
|
* ```ts
|
|
1983
2170
|
* import { Schema } from "effect"
|
|
@@ -1997,7 +2184,7 @@ ArraySchema as Array };
|
|
|
1997
2184
|
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
1998
2185
|
* Type is `readonly [T, ...T[]]`.
|
|
1999
2186
|
*
|
|
2000
|
-
* **Example** (
|
|
2187
|
+
* **Example** (Defining a non-empty array of numbers)
|
|
2001
2188
|
*
|
|
2002
2189
|
* ```ts
|
|
2003
2190
|
* import { Schema } from "effect"
|
|
@@ -2063,7 +2250,7 @@ export function UniqueArray(item) {
|
|
|
2063
2250
|
/**
|
|
2064
2251
|
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
2065
2252
|
*
|
|
2066
|
-
* **Example** (
|
|
2253
|
+
* **Example** (Defining mutable arrays)
|
|
2067
2254
|
*
|
|
2068
2255
|
* ```ts
|
|
2069
2256
|
* import { Schema } from "effect"
|
|
@@ -2101,7 +2288,7 @@ function makeUnion(ast, members) {
|
|
|
2101
2288
|
* - `"anyOf"` (default) — matches if any member matches.
|
|
2102
2289
|
* - `"oneOf"` — matches if exactly one member matches.
|
|
2103
2290
|
*
|
|
2104
|
-
* **Example** (
|
|
2291
|
+
* **Example** (Defining a string or number union)
|
|
2105
2292
|
*
|
|
2106
2293
|
* ```ts
|
|
2107
2294
|
* import { Schema } from "effect"
|
|
@@ -2121,7 +2308,7 @@ export function Union(members, options) {
|
|
|
2121
2308
|
/**
|
|
2122
2309
|
* Creates a union schema from an array of literal values.
|
|
2123
2310
|
*
|
|
2124
|
-
* **Example** (
|
|
2311
|
+
* **Example** (Defining status codes)
|
|
2125
2312
|
*
|
|
2126
2313
|
* ```ts
|
|
2127
2314
|
* import { Schema } from "effect"
|
|
@@ -2176,7 +2363,7 @@ export const NullishOr = /*#__PURE__*/Struct_.lambda(self => Union([self, Null,
|
|
|
2176
2363
|
* essential for creating recursive schemas where a schema references itself,
|
|
2177
2364
|
* preventing infinite recursion during schema definition.
|
|
2178
2365
|
*
|
|
2179
|
-
* **Example** (
|
|
2366
|
+
* **Example** (Defining recursive tree schemas)
|
|
2180
2367
|
*
|
|
2181
2368
|
* ```ts
|
|
2182
2369
|
* import { Schema } from "effect"
|
|
@@ -2520,7 +2707,7 @@ export function encode(transformation) {
|
|
|
2520
2707
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
2521
2708
|
* encoding.
|
|
2522
2709
|
*
|
|
2523
|
-
* **Example** (
|
|
2710
|
+
* **Example** (Defining an optional field with a static default)
|
|
2524
2711
|
*
|
|
2525
2712
|
* ```ts
|
|
2526
2713
|
* import { Effect, Schema } from "effect"
|
|
@@ -2543,7 +2730,7 @@ export function withConstructorDefault(
|
|
|
2543
2730
|
// `S["~type.make.in"]` instead of `S["Type"]` is intentional here because
|
|
2544
2731
|
// it makes easier to define the default value if there are nested defaults
|
|
2545
2732
|
defaultValue) {
|
|
2546
|
-
return schema => make(SchemaAST.withConstructorDefault(schema.ast,
|
|
2733
|
+
return schema => make(SchemaAST.withConstructorDefault(schema.ast, InternalSchema.mapSchemaErrorEffect(defaultValue)), {
|
|
2547
2734
|
schema
|
|
2548
2735
|
});
|
|
2549
2736
|
}
|
|
@@ -2563,7 +2750,7 @@ defaultValue) {
|
|
|
2563
2750
|
* - `"passthrough"` (default): include the value in the encoded output.
|
|
2564
2751
|
* - `"omit"`: omit the key from the encoded output.
|
|
2565
2752
|
*
|
|
2566
|
-
* **Example** (
|
|
2753
|
+
* **Example** (Providing a default for a missing struct key)
|
|
2567
2754
|
*
|
|
2568
2755
|
* ```ts
|
|
2569
2756
|
* import { Effect, Schema } from "effect"
|
|
@@ -2585,7 +2772,7 @@ export function withDecodingDefaultKey(defaultValue, options) {
|
|
|
2585
2772
|
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough();
|
|
2586
2773
|
return self => {
|
|
2587
2774
|
return optionalKey(toEncoded(self)).pipe(decodeTo(self, {
|
|
2588
|
-
decode: SchemaGetter.withDefault(
|
|
2775
|
+
decode: SchemaGetter.withDefault(InternalSchema.mapSchemaErrorEffect(defaultValue)),
|
|
2589
2776
|
encode
|
|
2590
2777
|
}));
|
|
2591
2778
|
};
|
|
@@ -2638,7 +2825,7 @@ export function withDecodingDefaultTypeKey(defaultValue, options) {
|
|
|
2638
2825
|
* - `"passthrough"` (default): include the value in the encoded output.
|
|
2639
2826
|
* - `"omit"`: omit the key from the encoded output.
|
|
2640
2827
|
*
|
|
2641
|
-
* **Example** (
|
|
2828
|
+
* **Example** (Providing a default for an optional field value)
|
|
2642
2829
|
*
|
|
2643
2830
|
* ```ts
|
|
2644
2831
|
* import { Effect, Schema } from "effect"
|
|
@@ -2660,7 +2847,7 @@ export function withDecodingDefault(defaultValue, options) {
|
|
|
2660
2847
|
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough();
|
|
2661
2848
|
return self => {
|
|
2662
2849
|
return optional(toEncoded(self)).pipe(decodeTo(self, {
|
|
2663
|
-
decode: SchemaGetter.withDefault(
|
|
2850
|
+
decode: SchemaGetter.withDefault(InternalSchema.mapSchemaErrorEffect(defaultValue)),
|
|
2664
2851
|
encode
|
|
2665
2852
|
}));
|
|
2666
2853
|
};
|
|
@@ -2702,7 +2889,7 @@ export function withDecodingDefaultType(defaultValue, options) {
|
|
|
2702
2889
|
* for discriminator fields in tagged unions. When constructing via `make`, the
|
|
2703
2890
|
* `_tag` field can be omitted and will be filled automatically.
|
|
2704
2891
|
*
|
|
2705
|
-
* **Example** (
|
|
2892
|
+
* **Example** (Defining a discriminated union tag)
|
|
2706
2893
|
*
|
|
2707
2894
|
* ```ts
|
|
2708
2895
|
* import { Schema } from "effect"
|
|
@@ -2735,7 +2922,7 @@ export function tag(literal) {
|
|
|
2735
2922
|
* The tag is filled during decoding and construction, like {@link tag}, but is
|
|
2736
2923
|
* omitted when encoding.
|
|
2737
2924
|
*
|
|
2738
|
-
* **Example** (
|
|
2925
|
+
* **Example** (Omitting tags during encoding)
|
|
2739
2926
|
*
|
|
2740
2927
|
* ```ts
|
|
2741
2928
|
* import { Schema } from "effect"
|
|
@@ -2772,7 +2959,7 @@ export function tagDefaultOmit(literal) {
|
|
|
2772
2959
|
* added automatically. However, when decoding or encoding, the `_tag` field
|
|
2773
2960
|
* must be present in the input.
|
|
2774
2961
|
*
|
|
2775
|
-
* **Example** (
|
|
2962
|
+
* **Example** (Defining a tagged struct shorthand)
|
|
2776
2963
|
*
|
|
2777
2964
|
* ```ts
|
|
2778
2965
|
* import { Schema } from "effect"
|
|
@@ -2881,7 +3068,7 @@ export function toTaggedUnion(tag) {
|
|
|
2881
3068
|
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
2882
3069
|
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
2883
3070
|
*
|
|
2884
|
-
* **Example** (
|
|
3071
|
+
* **Example** (Pattern matching a discriminated union)
|
|
2885
3072
|
*
|
|
2886
3073
|
* ```ts
|
|
2887
3074
|
* import { Schema } from "effect"
|
|
@@ -2926,7 +3113,7 @@ export function TaggedUnion(casesByTag) {
|
|
|
2926
3113
|
* Useful for creating opaque types that are structurally identical to a base struct
|
|
2927
3114
|
* but type-incompatible with it.
|
|
2928
3115
|
*
|
|
2929
|
-
* **Example** (
|
|
3116
|
+
* **Example** (Defining opaque structs)
|
|
2930
3117
|
*
|
|
2931
3118
|
* ```ts
|
|
2932
3119
|
* import { Schema } from "effect"
|
|
@@ -2956,7 +3143,7 @@ export function Opaque() {
|
|
|
2956
3143
|
* Creates a schema that validates values using `instanceof`.
|
|
2957
3144
|
* Decoding and encoding pass the value through unchanged.
|
|
2958
3145
|
*
|
|
2959
|
-
* **Example** (
|
|
3146
|
+
* **Example** (Defining a schema for a built-in class)
|
|
2960
3147
|
*
|
|
2961
3148
|
* ```ts
|
|
2962
3149
|
* import { Schema } from "effect"
|
|
@@ -3002,7 +3189,7 @@ export function link() {
|
|
|
3002
3189
|
* When `abort` is `true`, parsing stops after this filter fails instead of
|
|
3003
3190
|
* collecting later check failures.
|
|
3004
3191
|
*
|
|
3005
|
-
* **Example** (
|
|
3192
|
+
* **Example** (Reporting failure at a nested path)
|
|
3006
3193
|
*
|
|
3007
3194
|
* ```ts
|
|
3008
3195
|
* import { Schema } from "effect"
|
|
@@ -4345,7 +4532,7 @@ export const isBetweenBigDecimal = /*#__PURE__*/makeIsBetween({
|
|
|
4345
4532
|
* constraint to ensure generated strings or arrays have at least the required
|
|
4346
4533
|
* length.
|
|
4347
4534
|
*
|
|
4348
|
-
* **Example** (
|
|
4535
|
+
* **Example** (Checking minimum length)
|
|
4349
4536
|
*
|
|
4350
4537
|
* ```ts
|
|
4351
4538
|
* import { Schema } from "effect"
|
|
@@ -5916,7 +6103,7 @@ const DateString = /*#__PURE__*/String.annotate({
|
|
|
5916
6103
|
* JSON serializer encodes valid dates as ISO 8601 strings; invalid dates encode
|
|
5917
6104
|
* as `"Invalid Date"`.
|
|
5918
6105
|
*
|
|
5919
|
-
* **Example** (Date schema)
|
|
6106
|
+
* **Example** (Defining a Date schema)
|
|
5920
6107
|
*
|
|
5921
6108
|
* ```ts
|
|
5922
6109
|
* import { Schema } from "effect"
|
|
@@ -5990,7 +6177,7 @@ export const DateValid = /*#__PURE__*/Date.check(/*#__PURE__*/isDateValid());
|
|
|
5990
6177
|
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
5991
6178
|
* duration type and value.
|
|
5992
6179
|
*
|
|
5993
|
-
* **Example** (Duration schema)
|
|
6180
|
+
* **Example** (Defining a Duration schema)
|
|
5994
6181
|
*
|
|
5995
6182
|
* ```ts
|
|
5996
6183
|
* import { Duration, Schema } from "effect"
|
|
@@ -6491,7 +6678,7 @@ export const FormData = /*#__PURE__*/instanceOf(globalThis.FormData, {
|
|
|
6491
6678
|
* // Success({"a":"1"})
|
|
6492
6679
|
* ```
|
|
6493
6680
|
*
|
|
6494
|
-
* **Example** (
|
|
6681
|
+
* **Example** (Decoding nested fields)
|
|
6495
6682
|
*
|
|
6496
6683
|
* ```ts
|
|
6497
6684
|
* import { Schema } from "effect"
|
|
@@ -6605,7 +6792,7 @@ export const URLSearchParams = /*#__PURE__*/instanceOf(globalThis.URLSearchParam
|
|
|
6605
6792
|
* // Success({"a":"1"})
|
|
6606
6793
|
* ```
|
|
6607
6794
|
*
|
|
6608
|
-
* **Example** (
|
|
6795
|
+
* **Example** (Decoding nested fields)
|
|
6609
6796
|
*
|
|
6610
6797
|
* ```ts
|
|
6611
6798
|
* import { Schema } from "effect"
|
|
@@ -7313,14 +7500,16 @@ function makeClass(Inherited, identifier, struct, annotations, proto) {
|
|
|
7313
7500
|
return this.rebuild(SchemaAST.appendChecks(this.ast, checks));
|
|
7314
7501
|
}
|
|
7315
7502
|
static extend(identifier) {
|
|
7316
|
-
return (
|
|
7503
|
+
return (schema, annotations) => {
|
|
7504
|
+
const extension = isStruct(schema) ? schema : Struct(schema);
|
|
7317
7505
|
const fields = {
|
|
7318
7506
|
...struct.fields,
|
|
7319
|
-
...
|
|
7507
|
+
...extension.fields
|
|
7320
7508
|
};
|
|
7321
|
-
|
|
7509
|
+
const ast = SchemaAST.struct(fields, struct.ast.checks, {
|
|
7322
7510
|
identifier
|
|
7323
|
-
})
|
|
7511
|
+
});
|
|
7512
|
+
return makeClass(this, identifier, makeStruct(SchemaAST.appendChecks(ast, extension.ast.checks), fields), annotations, proto);
|
|
7324
7513
|
};
|
|
7325
7514
|
}
|
|
7326
7515
|
static mapFields(f, options) {
|
|
@@ -7384,7 +7573,7 @@ function isStruct(schema) {
|
|
|
7384
7573
|
*
|
|
7385
7574
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
7386
7575
|
*
|
|
7387
|
-
* **Example** (
|
|
7576
|
+
* **Example** (Defining a basic class)
|
|
7388
7577
|
*
|
|
7389
7578
|
* ```ts
|
|
7390
7579
|
* import { Schema } from "effect"
|
|
@@ -7447,7 +7636,7 @@ export const Class = identifier => (schema, annotations) => {
|
|
|
7447
7636
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
7448
7637
|
* it defaults to the `tag` value.
|
|
7449
7638
|
*
|
|
7450
|
-
* **Example** (
|
|
7639
|
+
* **Example** (Defining a tagged class)
|
|
7451
7640
|
*
|
|
7452
7641
|
* ```ts
|
|
7453
7642
|
* import { Schema } from "effect"
|
|
@@ -7514,7 +7703,7 @@ export const ErrorClass = identifier => (schema, annotations) => {
|
|
|
7514
7703
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
7515
7704
|
* and matched as tagged union members.
|
|
7516
7705
|
*
|
|
7517
|
-
* **Example** (
|
|
7706
|
+
* **Example** (Defining a tagged error class)
|
|
7518
7707
|
*
|
|
7519
7708
|
* ```ts
|
|
7520
7709
|
* import { Effect, Schema } from "effect"
|
|
@@ -7763,7 +7952,7 @@ export function overrideToEquivalence(toEquivalence) {
|
|
|
7763
7952
|
* every field (and nested field) compares equal according to the schema
|
|
7764
7953
|
* structure.
|
|
7765
7954
|
*
|
|
7766
|
-
* **Example** (
|
|
7955
|
+
* **Example** (Comparing structs)
|
|
7767
7956
|
*
|
|
7768
7957
|
* ```ts
|
|
7769
7958
|
* import { Schema } from "effect"
|
|
@@ -7871,7 +8060,7 @@ function toCodecJsonBase(ast, recur) {
|
|
|
7871
8060
|
cause: ast
|
|
7872
8061
|
});
|
|
7873
8062
|
}
|
|
7874
|
-
return ast.recur(recur);
|
|
8063
|
+
return ast.recur(recur, SchemaAST.parameterFromString);
|
|
7875
8064
|
}
|
|
7876
8065
|
case "Union":
|
|
7877
8066
|
{
|
|
@@ -8082,7 +8271,7 @@ function serializerTree(ast, recur, onMissingAnnotation) {
|
|
|
8082
8271
|
cause: ast
|
|
8083
8272
|
});
|
|
8084
8273
|
}
|
|
8085
|
-
return ast.recur(recur);
|
|
8274
|
+
return ast.recur(recur, SchemaAST.parameterFromString);
|
|
8086
8275
|
}
|
|
8087
8276
|
case "Union":
|
|
8088
8277
|
{
|