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.d.ts
CHANGED
|
@@ -157,6 +157,8 @@ export interface Bottom<out T, out E, out RD, out RE, out Ast extends SchemaAST.
|
|
|
157
157
|
*
|
|
158
158
|
* Throws an `Error` with the schema issue in its `cause` when validation
|
|
159
159
|
* fails.
|
|
160
|
+
* Causes that contain defects, interruptions, or other non-schema reasons
|
|
161
|
+
* throw with the underlying `Cause` attached instead.
|
|
160
162
|
*
|
|
161
163
|
* @see {@link Bottom.makeOption} — construct synchronously and discard validation details
|
|
162
164
|
* @see {@link Bottom.makeEffect} — construct through `Effect` when validation failure should stay in the error channel
|
|
@@ -176,6 +178,12 @@ export interface Bottom<out T, out E, out RD, out RE, out Ast extends SchemaAST.
|
|
|
176
178
|
* Applies constructor defaults and type-side validation according to
|
|
177
179
|
* `MakeOptions`.
|
|
178
180
|
*
|
|
181
|
+
* **Gotchas**
|
|
182
|
+
*
|
|
183
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
184
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
185
|
+
* instead.
|
|
186
|
+
*
|
|
179
187
|
* @see {@link Bottom.make} — construct synchronously when validation failure should throw
|
|
180
188
|
* @see {@link Bottom.makeEffect} — construct through `Effect` when validation details should stay in the error channel
|
|
181
189
|
*/
|
|
@@ -276,7 +284,7 @@ export interface declare<T, Iso = T> extends declareConstructor<T, T, readonly [
|
|
|
276
284
|
* Use when you are defining a schema for an opaque type with no type parameters
|
|
277
285
|
* and validation can be expressed as a type guard.
|
|
278
286
|
*
|
|
279
|
-
* **Example** (
|
|
287
|
+
* **Example** (Defining a schema for a custom `UserId` branded type)
|
|
280
288
|
*
|
|
281
289
|
* ```ts
|
|
282
290
|
* import { Schema } from "effect"
|
|
@@ -400,7 +408,7 @@ export declare function annotateEncoded<S extends Top>(annotations: Annotations.
|
|
|
400
408
|
* as well as standard documentation fields such as `title`, `description`,
|
|
401
409
|
* and `examples`.
|
|
402
410
|
*
|
|
403
|
-
* **Example** (
|
|
411
|
+
* **Example** (Customizing the missing-key message for a required field)
|
|
404
412
|
*
|
|
405
413
|
* ```ts
|
|
406
414
|
* import { Schema } from "effect"
|
|
@@ -477,7 +485,7 @@ export declare namespace Schema {
|
|
|
477
485
|
* constructors in this module (e.g. {@link Struct}, {@link String}, {@link Number}).
|
|
478
486
|
* When you also need the encoded type or service requirements, use {@link Codec}.
|
|
479
487
|
*
|
|
480
|
-
* **Example** (
|
|
488
|
+
* **Example** (Accepting any schema decoding to `string`)
|
|
481
489
|
*
|
|
482
490
|
* ```ts
|
|
483
491
|
* import { Schema } from "effect"
|
|
@@ -628,7 +636,7 @@ export interface Codec<out T, out E = T, out RD = never, out RE = never> extends
|
|
|
628
636
|
* constraining or depending on the encoded representation (`Encoded` is
|
|
629
637
|
* `unknown`) or encoding services.
|
|
630
638
|
*
|
|
631
|
-
* **Example** (
|
|
639
|
+
* **Example** (Accepting schemas that only need to decode)
|
|
632
640
|
*
|
|
633
641
|
* ```ts
|
|
634
642
|
* import { Schema } from "effect"
|
|
@@ -654,7 +662,7 @@ export interface Decoder<out T, out RD = never> extends Codec<T, unknown, RD, un
|
|
|
654
662
|
* constraining or depending on the decoded `Type` (`Type` is `unknown`) or
|
|
655
663
|
* decoding services.
|
|
656
664
|
*
|
|
657
|
-
* **Example** (
|
|
665
|
+
* **Example** (Accepting schemas that only need to encode)
|
|
658
666
|
*
|
|
659
667
|
* ```ts
|
|
660
668
|
* import { Schema } from "effect"
|
|
@@ -733,7 +741,7 @@ SchemaError };
|
|
|
733
741
|
/**
|
|
734
742
|
* Returns `true` if `u` is a {@link SchemaError}.
|
|
735
743
|
*
|
|
736
|
-
* **Example** (
|
|
744
|
+
* **Example** (Narrowing Schema errors in a catch block)
|
|
737
745
|
*
|
|
738
746
|
* ```ts
|
|
739
747
|
* import { Schema } from "effect"
|
|
@@ -837,10 +845,16 @@ export declare function toStandardJSONSchemaV1<S extends Top>(self: S): Standard
|
|
|
837
845
|
* **Details**
|
|
838
846
|
*
|
|
839
847
|
* This function returns a predicate that performs a type-safe check, narrowing
|
|
840
|
-
* the type of the input value if the check passes.
|
|
841
|
-
*
|
|
848
|
+
* the type of the input value if the check passes. The predicate returns `false`
|
|
849
|
+
* for schema mismatches.
|
|
850
|
+
*
|
|
851
|
+
* **Gotchas**
|
|
852
|
+
*
|
|
853
|
+
* Only causes made entirely of schema issues are converted to `false`. Causes
|
|
854
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
855
|
+
* instead.
|
|
842
856
|
*
|
|
843
|
-
* **Example** (
|
|
857
|
+
* **Example** (Defining a basic type guard)
|
|
844
858
|
*
|
|
845
859
|
* ```ts
|
|
846
860
|
* import { Schema } from "effect"
|
|
@@ -863,7 +877,7 @@ export declare function toStandardJSONSchemaV1<S extends Top>(self: S): Standard
|
|
|
863
877
|
*/
|
|
864
878
|
export declare const is: typeof SchemaParser.is;
|
|
865
879
|
/**
|
|
866
|
-
* Creates an assertion function that throws an error if the input
|
|
880
|
+
* Creates an assertion function that throws an error if the input does not match
|
|
867
881
|
* the schema.
|
|
868
882
|
*
|
|
869
883
|
* **When to use**
|
|
@@ -873,10 +887,16 @@ export declare const is: typeof SchemaParser.is;
|
|
|
873
887
|
*
|
|
874
888
|
* **Details**
|
|
875
889
|
*
|
|
876
|
-
* The input is narrowed if the assertion succeeds. If validation fails,
|
|
877
|
-
* assertion throws.
|
|
890
|
+
* The input is narrowed if the assertion succeeds. If schema validation fails,
|
|
891
|
+
* the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
|
|
878
892
|
*
|
|
879
|
-
* **
|
|
893
|
+
* **Gotchas**
|
|
894
|
+
*
|
|
895
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
896
|
+
* with the underlying `Cause` attached instead of being converted to schema
|
|
897
|
+
* validation errors.
|
|
898
|
+
*
|
|
899
|
+
* **Example** (Asserting and narrowing an input)
|
|
880
900
|
*
|
|
881
901
|
* ```ts
|
|
882
902
|
* import { Schema } from "effect"
|
|
@@ -946,13 +966,12 @@ export declare function decodeUnknownEffect<S extends Top>(schema: S, options?:
|
|
|
946
966
|
export declare const decodeEffect: <S extends Top>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>;
|
|
947
967
|
/**
|
|
948
968
|
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
949
|
-
* `Exit` that is either a `Success` with the decoded value or a `Failure
|
|
950
|
-
* a {@link SchemaError}.
|
|
969
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure`.
|
|
951
970
|
*
|
|
952
971
|
* **When to use**
|
|
953
972
|
*
|
|
954
|
-
* Use when you need to decode unknown input into an `Exit`
|
|
955
|
-
*
|
|
973
|
+
* Use when you need to decode unknown input into an `Exit` and capture schema
|
|
974
|
+
* mismatches as `SchemaError`.
|
|
956
975
|
*
|
|
957
976
|
* **Details**
|
|
958
977
|
*
|
|
@@ -961,6 +980,14 @@ export declare const decodeEffect: <S extends Top>(schema: S, options?: SchemaAS
|
|
|
961
980
|
* type.
|
|
962
981
|
* Options may be provided either when creating the decoder or when applying it;
|
|
963
982
|
* application options override creation options.
|
|
983
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
984
|
+
* `SchemaError`.
|
|
985
|
+
*
|
|
986
|
+
* **Gotchas**
|
|
987
|
+
*
|
|
988
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
989
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
990
|
+
* including when they are mixed with schema issues.
|
|
964
991
|
*
|
|
965
992
|
* @see {@link SchemaParser.decodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
966
993
|
*
|
|
@@ -970,13 +997,13 @@ export declare const decodeEffect: <S extends Top>(schema: S, options?: SchemaAS
|
|
|
970
997
|
export declare function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>;
|
|
971
998
|
/**
|
|
972
999
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
973
|
-
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
974
|
-
*
|
|
1000
|
+
* synchronously, returning an `Exit` that is either a `Success` with the decoded
|
|
1001
|
+
* value or a `Failure`.
|
|
975
1002
|
*
|
|
976
1003
|
* **When to use**
|
|
977
1004
|
*
|
|
978
|
-
* Use when you need to decode already typed `Encoded` input into an `Exit`
|
|
979
|
-
*
|
|
1005
|
+
* Use when you need to decode already typed `Encoded` input into an `Exit` and
|
|
1006
|
+
* capture schema mismatches as `SchemaError`.
|
|
980
1007
|
*
|
|
981
1008
|
* **Details**
|
|
982
1009
|
*
|
|
@@ -984,6 +1011,14 @@ export declare function decodeUnknownExit<S extends Decoder<unknown>>(schema: S,
|
|
|
984
1011
|
* `unknown` input use {@link decodeUnknownExit}.
|
|
985
1012
|
* Options may be provided either when creating the decoder or when applying it;
|
|
986
1013
|
* application options override creation options.
|
|
1014
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1015
|
+
* `SchemaError`.
|
|
1016
|
+
*
|
|
1017
|
+
* **Gotchas**
|
|
1018
|
+
*
|
|
1019
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1020
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1021
|
+
* including when they are mixed with schema issues.
|
|
987
1022
|
*
|
|
988
1023
|
* @see {@link SchemaParser.decodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
989
1024
|
*
|
|
@@ -993,7 +1028,7 @@ export declare function decodeUnknownExit<S extends Decoder<unknown>>(schema: S,
|
|
|
993
1028
|
export declare const decodeExit: <S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>;
|
|
994
1029
|
/**
|
|
995
1030
|
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
996
|
-
* `Some` with the decoded value on success or `None`
|
|
1031
|
+
* `Some` with the decoded value on success or `None` for schema mismatches.
|
|
997
1032
|
*
|
|
998
1033
|
* **When to use**
|
|
999
1034
|
*
|
|
@@ -1008,6 +1043,12 @@ export declare const decodeExit: <S extends Decoder<unknown>>(schema: S, options
|
|
|
1008
1043
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1009
1044
|
* application options override creation options.
|
|
1010
1045
|
*
|
|
1046
|
+
* **Gotchas**
|
|
1047
|
+
*
|
|
1048
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1049
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1050
|
+
* instead.
|
|
1051
|
+
*
|
|
1011
1052
|
* @category decoding
|
|
1012
1053
|
* @since 3.10.0
|
|
1013
1054
|
*/
|
|
@@ -1015,7 +1056,7 @@ export declare const decodeUnknownOption: <S extends Decoder<unknown>>(schema: S
|
|
|
1015
1056
|
/**
|
|
1016
1057
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1017
1058
|
* returning an `Option` that is `Some` with the decoded value on success or
|
|
1018
|
-
* `None`
|
|
1059
|
+
* `None` for schema mismatches.
|
|
1019
1060
|
*
|
|
1020
1061
|
* **When to use**
|
|
1021
1062
|
*
|
|
@@ -1028,18 +1069,25 @@ export declare const decodeUnknownOption: <S extends Decoder<unknown>>(schema: S
|
|
|
1028
1069
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1029
1070
|
* application options override creation options.
|
|
1030
1071
|
*
|
|
1072
|
+
* **Gotchas**
|
|
1073
|
+
*
|
|
1074
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1075
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1076
|
+
* instead.
|
|
1077
|
+
*
|
|
1031
1078
|
* @category decoding
|
|
1032
1079
|
* @since 3.10.0
|
|
1033
1080
|
*/
|
|
1034
1081
|
export declare const decodeOption: <S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Type"]>;
|
|
1035
1082
|
/**
|
|
1036
1083
|
* Decodes an `unknown` input against a schema, returning a `Result` that
|
|
1037
|
-
* succeeds with the decoded value or fails with a {@link SchemaError}
|
|
1084
|
+
* succeeds with the decoded value or fails with a {@link SchemaError} for schema
|
|
1085
|
+
* mismatches.
|
|
1038
1086
|
*
|
|
1039
1087
|
* **When to use**
|
|
1040
1088
|
*
|
|
1041
|
-
* Use when you do not know the input type statically and want
|
|
1042
|
-
*
|
|
1089
|
+
* Use when you do not know the input type statically and want schema mismatches
|
|
1090
|
+
* returned as `Result.fail` with `SchemaError`.
|
|
1043
1091
|
*
|
|
1044
1092
|
* **Details**
|
|
1045
1093
|
*
|
|
@@ -1047,6 +1095,13 @@ export declare const decodeOption: <S extends Decoder<unknown>>(schema: S, optio
|
|
|
1047
1095
|
* {@link decodeResult}.
|
|
1048
1096
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1049
1097
|
* application options override creation options.
|
|
1098
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1099
|
+
*
|
|
1100
|
+
* **Gotchas**
|
|
1101
|
+
*
|
|
1102
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1103
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1104
|
+
* instead.
|
|
1050
1105
|
*
|
|
1051
1106
|
* @see {@link SchemaParser.decodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1052
1107
|
*
|
|
@@ -1057,18 +1112,25 @@ export declare function decodeUnknownResult<S extends Decoder<unknown>>(schema:
|
|
|
1057
1112
|
/**
|
|
1058
1113
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1059
1114
|
* returning a `Result` that succeeds with the decoded value or fails with a
|
|
1060
|
-
* {@link SchemaError}.
|
|
1115
|
+
* {@link SchemaError} for schema mismatches.
|
|
1061
1116
|
*
|
|
1062
1117
|
* **When to use**
|
|
1063
1118
|
*
|
|
1064
|
-
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1065
|
-
*
|
|
1119
|
+
* Use when you already have input typed as the schema's `Encoded` type and want
|
|
1120
|
+
* schema mismatches returned as `Result.fail` with `SchemaError`.
|
|
1066
1121
|
*
|
|
1067
1122
|
* **Details**
|
|
1068
1123
|
*
|
|
1069
1124
|
* For `unknown` input use {@link decodeUnknownResult}.
|
|
1070
1125
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1071
1126
|
* application options override creation options.
|
|
1127
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1128
|
+
*
|
|
1129
|
+
* **Gotchas**
|
|
1130
|
+
*
|
|
1131
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1132
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1133
|
+
* instead.
|
|
1072
1134
|
*
|
|
1073
1135
|
* @see {@link SchemaParser.decodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1074
1136
|
*
|
|
@@ -1078,12 +1140,13 @@ export declare function decodeUnknownResult<S extends Decoder<unknown>>(schema:
|
|
|
1078
1140
|
export declare const decodeResult: <S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Result_.Result<S["Type"], SchemaError>;
|
|
1079
1141
|
/**
|
|
1080
1142
|
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
1081
|
-
* resolves with the decoded value or rejects with a {@link SchemaError}
|
|
1143
|
+
* resolves with the decoded value or rejects with a {@link SchemaError} for
|
|
1144
|
+
* schema mismatches.
|
|
1082
1145
|
*
|
|
1083
1146
|
* **When to use**
|
|
1084
1147
|
*
|
|
1085
1148
|
* Use when you need decoding of unknown input to return a JavaScript `Promise`
|
|
1086
|
-
* that rejects with `SchemaError
|
|
1149
|
+
* that rejects with `SchemaError` for schema mismatches.
|
|
1087
1150
|
*
|
|
1088
1151
|
* **Details**
|
|
1089
1152
|
*
|
|
@@ -1092,7 +1155,12 @@ export declare const decodeResult: <S extends Decoder<unknown>>(schema: S, optio
|
|
|
1092
1155
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1093
1156
|
* application options override creation options.
|
|
1094
1157
|
*
|
|
1095
|
-
*
|
|
1158
|
+
* **Gotchas**
|
|
1159
|
+
*
|
|
1160
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1161
|
+
* `SchemaError`.
|
|
1162
|
+
*
|
|
1163
|
+
* @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1096
1164
|
*
|
|
1097
1165
|
* @category decoding
|
|
1098
1166
|
* @since 3.10.0
|
|
@@ -1101,13 +1169,13 @@ export declare function decodeUnknownPromise<S extends Decoder<unknown>>(schema:
|
|
|
1101
1169
|
/**
|
|
1102
1170
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1103
1171
|
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
1104
|
-
* {@link SchemaError}.
|
|
1172
|
+
* {@link SchemaError} for schema mismatches.
|
|
1105
1173
|
*
|
|
1106
1174
|
* **When to use**
|
|
1107
1175
|
*
|
|
1108
1176
|
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1109
1177
|
* need decoding to return a JavaScript `Promise` that rejects with
|
|
1110
|
-
* `SchemaError
|
|
1178
|
+
* `SchemaError` for schema mismatches.
|
|
1111
1179
|
*
|
|
1112
1180
|
* **Details**
|
|
1113
1181
|
*
|
|
@@ -1115,7 +1183,12 @@ export declare function decodeUnknownPromise<S extends Decoder<unknown>>(schema:
|
|
|
1115
1183
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1116
1184
|
* application options override creation options.
|
|
1117
1185
|
*
|
|
1118
|
-
*
|
|
1186
|
+
* **Gotchas**
|
|
1187
|
+
*
|
|
1188
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1189
|
+
* `SchemaError`.
|
|
1190
|
+
*
|
|
1191
|
+
* @see {@link SchemaParser.decodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1119
1192
|
*
|
|
1120
1193
|
* @category decoding
|
|
1121
1194
|
* @since 3.10.0
|
|
@@ -1123,7 +1196,7 @@ export declare function decodeUnknownPromise<S extends Decoder<unknown>>(schema:
|
|
|
1123
1196
|
export declare const decodePromise: <S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Promise<S["Type"]>;
|
|
1124
1197
|
/**
|
|
1125
1198
|
* Decodes an `unknown` input against a schema synchronously, returning the
|
|
1126
|
-
* decoded value or throwing a {@link SchemaError}.
|
|
1199
|
+
* decoded value or throwing a {@link SchemaError} for schema mismatches.
|
|
1127
1200
|
*
|
|
1128
1201
|
* **When to use**
|
|
1129
1202
|
*
|
|
@@ -1133,10 +1206,15 @@ export declare const decodePromise: <S extends Decoder<unknown>>(schema: S, opti
|
|
|
1133
1206
|
* **Details**
|
|
1134
1207
|
*
|
|
1135
1208
|
* For input already typed as the schema's `Encoded` type use `decodeSync`.
|
|
1136
|
-
* Only service-free schemas can be decoded synchronously. For
|
|
1137
|
-
*
|
|
1138
|
-
* `decodeUnknownEffect`. Options may be provided either
|
|
1139
|
-
* decoder or when applying it; application options override
|
|
1209
|
+
* Only service-free schemas can be decoded synchronously. For alternatives that
|
|
1210
|
+
* do not throw on schema mismatches, see `decodeUnknownOption`,
|
|
1211
|
+
* `decodeUnknownExit`, or `decodeUnknownEffect`. Options may be provided either
|
|
1212
|
+
* when creating the decoder or when applying it; application options override
|
|
1213
|
+
* creation options.
|
|
1214
|
+
*
|
|
1215
|
+
* **Gotchas**
|
|
1216
|
+
*
|
|
1217
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1140
1218
|
*
|
|
1141
1219
|
* **Example** (Decoding with a transformation schema)
|
|
1142
1220
|
*
|
|
@@ -1163,7 +1241,8 @@ export declare const decodePromise: <S extends Decoder<unknown>>(schema: S, opti
|
|
|
1163
1241
|
export declare function decodeUnknownSync<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => S["Type"];
|
|
1164
1242
|
/**
|
|
1165
1243
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
1166
|
-
* synchronously, returning the decoded value or throwing a {@link SchemaError}
|
|
1244
|
+
* synchronously, returning the decoded value or throwing a {@link SchemaError}
|
|
1245
|
+
* for schema mismatches.
|
|
1167
1246
|
*
|
|
1168
1247
|
* **When to use**
|
|
1169
1248
|
*
|
|
@@ -1177,6 +1256,10 @@ export declare function decodeUnknownSync<S extends Decoder<unknown>>(schema: S,
|
|
|
1177
1256
|
* provided either when creating the decoder or when applying it; application
|
|
1178
1257
|
* options override creation options.
|
|
1179
1258
|
*
|
|
1259
|
+
* **Gotchas**
|
|
1260
|
+
*
|
|
1261
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1262
|
+
*
|
|
1180
1263
|
* @see {@link SchemaParser.decodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1181
1264
|
*
|
|
1182
1265
|
* @category decoding
|
|
@@ -1240,13 +1323,12 @@ export declare function encodeUnknownEffect<S extends Top>(schema: S, options?:
|
|
|
1240
1323
|
export declare const encodeEffect: <S extends Top>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]>;
|
|
1241
1324
|
/**
|
|
1242
1325
|
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
1243
|
-
* `Exit` that is either a `Success` with the encoded value or a `Failure
|
|
1244
|
-
* a {@link SchemaError}.
|
|
1326
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure`.
|
|
1245
1327
|
*
|
|
1246
1328
|
* **When to use**
|
|
1247
1329
|
*
|
|
1248
|
-
* Use when you need to encode unknown input into an `Exit`
|
|
1249
|
-
*
|
|
1330
|
+
* Use when you need to encode unknown input into an `Exit` and capture schema
|
|
1331
|
+
* mismatches as `SchemaError`.
|
|
1250
1332
|
*
|
|
1251
1333
|
* **Details**
|
|
1252
1334
|
*
|
|
@@ -1254,6 +1336,14 @@ export declare const encodeEffect: <S extends Top>(schema: S, options?: SchemaAS
|
|
|
1254
1336
|
* {@link encodeExit} when the value is already typed as the schema's `Type`.
|
|
1255
1337
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1256
1338
|
* application options override creation options.
|
|
1339
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1340
|
+
* `SchemaError`.
|
|
1341
|
+
*
|
|
1342
|
+
* **Gotchas**
|
|
1343
|
+
*
|
|
1344
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1345
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1346
|
+
* including when they are mixed with schema issues.
|
|
1257
1347
|
*
|
|
1258
1348
|
* @see {@link SchemaParser.encodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1259
1349
|
*
|
|
@@ -1264,12 +1354,12 @@ export declare function encodeUnknownExit<S extends Encoder<unknown>>(schema: S,
|
|
|
1264
1354
|
/**
|
|
1265
1355
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1266
1356
|
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
1267
|
-
* `Failure
|
|
1357
|
+
* `Failure`.
|
|
1268
1358
|
*
|
|
1269
1359
|
* **When to use**
|
|
1270
1360
|
*
|
|
1271
|
-
* Use when you need to encode already typed schema values into an `Exit`
|
|
1272
|
-
*
|
|
1361
|
+
* Use when you need to encode already typed schema values into an `Exit` and
|
|
1362
|
+
* capture schema mismatches as `SchemaError`.
|
|
1273
1363
|
*
|
|
1274
1364
|
* **Details**
|
|
1275
1365
|
*
|
|
@@ -1277,6 +1367,14 @@ export declare function encodeUnknownExit<S extends Encoder<unknown>>(schema: S,
|
|
|
1277
1367
|
* `unknown` input use {@link encodeUnknownExit}.
|
|
1278
1368
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1279
1369
|
* application options override creation options.
|
|
1370
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1371
|
+
* `SchemaError`.
|
|
1372
|
+
*
|
|
1373
|
+
* **Gotchas**
|
|
1374
|
+
*
|
|
1375
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1376
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1377
|
+
* including when they are mixed with schema issues.
|
|
1280
1378
|
*
|
|
1281
1379
|
* @see {@link SchemaParser.encodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1282
1380
|
*
|
|
@@ -1286,7 +1384,7 @@ export declare function encodeUnknownExit<S extends Encoder<unknown>>(schema: S,
|
|
|
1286
1384
|
export declare const encodeExit: <S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>;
|
|
1287
1385
|
/**
|
|
1288
1386
|
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
1289
|
-
* `Some` with the encoded value on success or `None`
|
|
1387
|
+
* `Some` with the encoded value on success or `None` for schema mismatches.
|
|
1290
1388
|
*
|
|
1291
1389
|
* **When to use**
|
|
1292
1390
|
*
|
|
@@ -1301,14 +1399,20 @@ export declare const encodeExit: <S extends Encoder<unknown>>(schema: S, options
|
|
|
1301
1399
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1302
1400
|
* application options override creation options.
|
|
1303
1401
|
*
|
|
1402
|
+
* **Gotchas**
|
|
1403
|
+
*
|
|
1404
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1405
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1406
|
+
* instead.
|
|
1407
|
+
*
|
|
1304
1408
|
* @category encoding
|
|
1305
1409
|
* @since 3.10.0
|
|
1306
1410
|
*/
|
|
1307
1411
|
export declare const encodeUnknownOption: <S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: unknown, options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]>;
|
|
1308
1412
|
/**
|
|
1309
1413
|
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1310
|
-
* `Option` that is `Some` with the encoded value on success or `None`
|
|
1311
|
-
*
|
|
1414
|
+
* `Option` that is `Some` with the encoded value on success or `None` for schema
|
|
1415
|
+
* mismatches.
|
|
1312
1416
|
*
|
|
1313
1417
|
* **When to use**
|
|
1314
1418
|
*
|
|
@@ -1321,24 +1425,38 @@ export declare const encodeUnknownOption: <S extends Encoder<unknown>>(schema: S
|
|
|
1321
1425
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1322
1426
|
* application options override creation options.
|
|
1323
1427
|
*
|
|
1428
|
+
* **Gotchas**
|
|
1429
|
+
*
|
|
1430
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1431
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1432
|
+
* instead.
|
|
1433
|
+
*
|
|
1324
1434
|
* @category encoding
|
|
1325
1435
|
* @since 3.10.0
|
|
1326
1436
|
*/
|
|
1327
1437
|
export declare const encodeOption: <S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Option_.Option<S["Encoded"]>;
|
|
1328
1438
|
/**
|
|
1329
1439
|
* Encodes an `unknown` input against a schema, returning a `Result` that
|
|
1330
|
-
* succeeds with the encoded value or fails with a {@link SchemaError}
|
|
1440
|
+
* succeeds with the encoded value or fails with a {@link SchemaError} for schema
|
|
1441
|
+
* mismatches.
|
|
1331
1442
|
*
|
|
1332
1443
|
* **When to use**
|
|
1333
1444
|
*
|
|
1334
|
-
* Use when you do not know the input type statically and want
|
|
1335
|
-
*
|
|
1445
|
+
* Use when you do not know the input type statically and want schema mismatches
|
|
1446
|
+
* returned as `Result.fail` with `SchemaError`.
|
|
1336
1447
|
*
|
|
1337
1448
|
* **Details**
|
|
1338
1449
|
*
|
|
1339
1450
|
* For values already typed as the schema's `Type` use {@link encodeResult}.
|
|
1340
1451
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1341
1452
|
* application options override creation options.
|
|
1453
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1454
|
+
*
|
|
1455
|
+
* **Gotchas**
|
|
1456
|
+
*
|
|
1457
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1458
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1459
|
+
* instead.
|
|
1342
1460
|
*
|
|
1343
1461
|
* @see {@link SchemaParser.encodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1344
1462
|
*
|
|
@@ -1349,18 +1467,25 @@ export declare function encodeUnknownResult<S extends Encoder<unknown>>(schema:
|
|
|
1349
1467
|
/**
|
|
1350
1468
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1351
1469
|
* `Result` that succeeds with the encoded value or fails with a
|
|
1352
|
-
* {@link SchemaError}.
|
|
1470
|
+
* {@link SchemaError} for schema mismatches.
|
|
1353
1471
|
*
|
|
1354
1472
|
* **When to use**
|
|
1355
1473
|
*
|
|
1356
|
-
* Use when you already have a value typed as the schema's `Type` and want
|
|
1357
|
-
*
|
|
1474
|
+
* Use when you already have a value typed as the schema's `Type` and want schema
|
|
1475
|
+
* mismatches returned as `Result.fail` with `SchemaError`.
|
|
1358
1476
|
*
|
|
1359
1477
|
* **Details**
|
|
1360
1478
|
*
|
|
1361
1479
|
* For `unknown` input use {@link encodeUnknownResult}.
|
|
1362
1480
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1363
1481
|
* application options override creation options.
|
|
1482
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1483
|
+
*
|
|
1484
|
+
* **Gotchas**
|
|
1485
|
+
*
|
|
1486
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1487
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1488
|
+
* instead.
|
|
1364
1489
|
*
|
|
1365
1490
|
* @see {@link SchemaParser.encodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1366
1491
|
*
|
|
@@ -1370,12 +1495,13 @@ export declare function encodeUnknownResult<S extends Encoder<unknown>>(schema:
|
|
|
1370
1495
|
export declare const encodeResult: <S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Result_.Result<S["Encoded"], SchemaError>;
|
|
1371
1496
|
/**
|
|
1372
1497
|
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1373
|
-
* resolves with the encoded value or rejects with a {@link SchemaError}
|
|
1498
|
+
* resolves with the encoded value or rejects with a {@link SchemaError} for
|
|
1499
|
+
* schema mismatches.
|
|
1374
1500
|
*
|
|
1375
1501
|
* **When to use**
|
|
1376
1502
|
*
|
|
1377
1503
|
* Use when you need encoding of unknown input to return a JavaScript `Promise`
|
|
1378
|
-
* that rejects with `SchemaError
|
|
1504
|
+
* that rejects with `SchemaError` for schema mismatches.
|
|
1379
1505
|
*
|
|
1380
1506
|
* **Details**
|
|
1381
1507
|
*
|
|
@@ -1383,7 +1509,12 @@ export declare const encodeResult: <S extends Encoder<unknown>>(schema: S, optio
|
|
|
1383
1509
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1384
1510
|
* application options override creation options.
|
|
1385
1511
|
*
|
|
1386
|
-
*
|
|
1512
|
+
* **Gotchas**
|
|
1513
|
+
*
|
|
1514
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1515
|
+
* `SchemaError`.
|
|
1516
|
+
*
|
|
1517
|
+
* @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1387
1518
|
*
|
|
1388
1519
|
* @category encoding
|
|
1389
1520
|
* @since 3.10.0
|
|
@@ -1392,12 +1523,13 @@ export declare function encodeUnknownPromise<S extends Encoder<unknown>>(schema:
|
|
|
1392
1523
|
/**
|
|
1393
1524
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1394
1525
|
* `Promise` that resolves with the encoded value or rejects with a
|
|
1395
|
-
* {@link SchemaError}.
|
|
1526
|
+
* {@link SchemaError} for schema mismatches.
|
|
1396
1527
|
*
|
|
1397
1528
|
* **When to use**
|
|
1398
1529
|
*
|
|
1399
1530
|
* Use when you already have a value typed as the schema's `Type` and need
|
|
1400
|
-
* encoding to return a JavaScript `Promise` that rejects with `SchemaError
|
|
1531
|
+
* encoding to return a JavaScript `Promise` that rejects with `SchemaError` for
|
|
1532
|
+
* schema mismatches.
|
|
1401
1533
|
*
|
|
1402
1534
|
* **Details**
|
|
1403
1535
|
*
|
|
@@ -1405,7 +1537,12 @@ export declare function encodeUnknownPromise<S extends Encoder<unknown>>(schema:
|
|
|
1405
1537
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1406
1538
|
* application options override creation options.
|
|
1407
1539
|
*
|
|
1408
|
-
*
|
|
1540
|
+
* **Gotchas**
|
|
1541
|
+
*
|
|
1542
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1543
|
+
* `SchemaError`.
|
|
1544
|
+
*
|
|
1545
|
+
* @see {@link SchemaParser.encodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1409
1546
|
*
|
|
1410
1547
|
* @category encoding
|
|
1411
1548
|
* @since 3.10.0
|
|
@@ -1413,7 +1550,7 @@ export declare function encodeUnknownPromise<S extends Encoder<unknown>>(schema:
|
|
|
1413
1550
|
export declare const encodePromise: <S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Promise<S["Encoded"]>;
|
|
1414
1551
|
/**
|
|
1415
1552
|
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
1416
|
-
* {@link SchemaError}
|
|
1553
|
+
* {@link SchemaError} for schema mismatches.
|
|
1417
1554
|
*
|
|
1418
1555
|
* **When to use**
|
|
1419
1556
|
*
|
|
@@ -1422,11 +1559,15 @@ export declare const encodePromise: <S extends Encoder<unknown>>(schema: S, opti
|
|
|
1422
1559
|
*
|
|
1423
1560
|
* **Details**
|
|
1424
1561
|
*
|
|
1425
|
-
* For
|
|
1426
|
-
* {@link
|
|
1427
|
-
* already typed as the schema's `Type`
|
|
1428
|
-
* Options may be provided either when creating the
|
|
1429
|
-
* application options override creation options.
|
|
1562
|
+
* For alternatives that do not throw on schema mismatches, see
|
|
1563
|
+
* {@link encodeUnknownOption}, {@link encodeUnknownExit}, or
|
|
1564
|
+
* {@link encodeUnknownEffect}. For values already typed as the schema's `Type`
|
|
1565
|
+
* use {@link encodeSync}. Options may be provided either when creating the
|
|
1566
|
+
* encoder or when applying it; application options override creation options.
|
|
1567
|
+
*
|
|
1568
|
+
* **Gotchas**
|
|
1569
|
+
*
|
|
1570
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1430
1571
|
*
|
|
1431
1572
|
* @see {@link SchemaParser.encodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1432
1573
|
*
|
|
@@ -1436,7 +1577,7 @@ export declare const encodePromise: <S extends Encoder<unknown>>(schema: S, opti
|
|
|
1436
1577
|
export declare function encodeUnknownSync<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => S["Encoded"];
|
|
1437
1578
|
/**
|
|
1438
1579
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1439
|
-
* throwing a {@link SchemaError}
|
|
1580
|
+
* throwing a {@link SchemaError} for schema mismatches.
|
|
1440
1581
|
*
|
|
1441
1582
|
* **When to use**
|
|
1442
1583
|
*
|
|
@@ -1449,6 +1590,10 @@ export declare function encodeUnknownSync<S extends Encoder<unknown>>(schema: S,
|
|
|
1449
1590
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1450
1591
|
* application options override creation options.
|
|
1451
1592
|
*
|
|
1593
|
+
* **Gotchas**
|
|
1594
|
+
*
|
|
1595
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1596
|
+
*
|
|
1452
1597
|
* @see {@link SchemaParser.encodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1453
1598
|
*
|
|
1454
1599
|
* @category encoding
|
|
@@ -1581,7 +1726,7 @@ interface optionalLambda extends Lambda {
|
|
|
1581
1726
|
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
1582
1727
|
* only, not `undefined`).
|
|
1583
1728
|
*
|
|
1584
|
-
* **Example** (
|
|
1729
|
+
* **Example** (Defining an optional field accepting undefined)
|
|
1585
1730
|
*
|
|
1586
1731
|
* ```ts
|
|
1587
1732
|
* import { Schema } from "effect"
|
|
@@ -1718,7 +1863,7 @@ export interface flip<S extends Top> extends Bottom<S["Encoded"], S["Type"], S["
|
|
|
1718
1863
|
*
|
|
1719
1864
|
* Calling `flip` twice returns the original schema.
|
|
1720
1865
|
*
|
|
1721
|
-
* **Example** (
|
|
1866
|
+
* **Example** (Flipping a number-from-string schema)
|
|
1722
1867
|
*
|
|
1723
1868
|
* ```ts
|
|
1724
1869
|
* import { Schema } from "effect"
|
|
@@ -1745,7 +1890,7 @@ export interface Literal<L extends SchemaAST.LiteralValue> extends Bottom<L, L,
|
|
|
1745
1890
|
/**
|
|
1746
1891
|
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
1747
1892
|
*
|
|
1748
|
-
* **Example** (
|
|
1893
|
+
* **Example** (Defining a string literal)
|
|
1749
1894
|
*
|
|
1750
1895
|
* ```ts
|
|
1751
1896
|
* import { Schema } from "effect"
|
|
@@ -1823,15 +1968,21 @@ export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends Bo
|
|
|
1823
1968
|
readonly parts: Parts;
|
|
1824
1969
|
}
|
|
1825
1970
|
/**
|
|
1826
|
-
* Creates a schema that validates strings matching
|
|
1827
|
-
*
|
|
1971
|
+
* Creates a schema that validates strings by matching ordered template literal
|
|
1972
|
+
* parts.
|
|
1828
1973
|
*
|
|
1829
1974
|
* **When to use**
|
|
1830
1975
|
*
|
|
1831
1976
|
* Use when the decoded value should remain the matched string and you do not
|
|
1832
1977
|
* need the individual template parts parsed into a tuple.
|
|
1833
1978
|
*
|
|
1834
|
-
* **
|
|
1979
|
+
* **Details**
|
|
1980
|
+
*
|
|
1981
|
+
* Each part can be a literal `string`, `number`, or `bigint`, or a schema whose
|
|
1982
|
+
* encoded type is `string`, `number`, or `bigint`. Checks on string, number,
|
|
1983
|
+
* and bigint schema parts are applied while matching each segment.
|
|
1984
|
+
*
|
|
1985
|
+
* **Example** (Defining a URL path pattern)
|
|
1835
1986
|
*
|
|
1836
1987
|
* ```ts
|
|
1837
1988
|
* import { Schema } from "effect"
|
|
@@ -1877,7 +2028,7 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
1877
2028
|
readonly parts: Parts;
|
|
1878
2029
|
}
|
|
1879
2030
|
/**
|
|
1880
|
-
* Schema for parsing template literal
|
|
2031
|
+
* Schema for parsing matched template literal strings into typed tuple parts.
|
|
1881
2032
|
*
|
|
1882
2033
|
* **When to use**
|
|
1883
2034
|
*
|
|
@@ -1887,9 +2038,10 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
1887
2038
|
* **Details**
|
|
1888
2039
|
*
|
|
1889
2040
|
* Unlike {@link TemplateLiteral}, this schema decodes the matched string into a
|
|
1890
|
-
* readonly tuple with one element per schema part.
|
|
2041
|
+
* readonly tuple with one element per schema part. Checks on string, number,
|
|
2042
|
+
* and bigint schema parts are applied while matching each segment.
|
|
1891
2043
|
*
|
|
1892
|
-
* **Example** (
|
|
2044
|
+
* **Example** (Parsing path parameters)
|
|
1893
2045
|
*
|
|
1894
2046
|
* ```ts
|
|
1895
2047
|
* import { Schema } from "effect"
|
|
@@ -1917,7 +2069,7 @@ export interface Enum<A extends {
|
|
|
1917
2069
|
/**
|
|
1918
2070
|
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
1919
2071
|
*
|
|
1920
|
-
* **Example** (
|
|
2072
|
+
* **Example** (Defining a direction enum)
|
|
1921
2073
|
*
|
|
1922
2074
|
* ```ts
|
|
1923
2075
|
* import { Schema } from "effect"
|
|
@@ -2160,7 +2312,7 @@ export interface UniqueSymbol<sym extends symbol> extends Bottom<sym, sym, never
|
|
|
2160
2312
|
/**
|
|
2161
2313
|
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
2162
2314
|
*
|
|
2163
|
-
* **Example** (
|
|
2315
|
+
* **Example** (Defining a specific symbol)
|
|
2164
2316
|
*
|
|
2165
2317
|
* ```ts
|
|
2166
2318
|
* import { Schema } from "effect"
|
|
@@ -2389,7 +2541,7 @@ export interface Struct<Fields extends Struct.Fields> extends Bottom<Struct.Type
|
|
|
2389
2541
|
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
2390
2542
|
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
2391
2543
|
*
|
|
2392
|
-
* **Example** (
|
|
2544
|
+
* **Example** (Defining a basic struct)
|
|
2393
2545
|
*
|
|
2394
2546
|
* ```ts
|
|
2395
2547
|
* import { Schema } from "effect"
|
|
@@ -2469,7 +2621,7 @@ export interface encodeKeys<S extends Top & {
|
|
|
2469
2621
|
* If two existing fields would produce the same encoded key, construction
|
|
2470
2622
|
* fails.
|
|
2471
2623
|
*
|
|
2472
|
-
* **Example** (
|
|
2624
|
+
* **Example** (Renaming `name` to `full_name` in the encoded form)
|
|
2473
2625
|
*
|
|
2474
2626
|
* ```ts
|
|
2475
2627
|
* import { Schema } from "effect"
|
|
@@ -2501,7 +2653,7 @@ export declare function encodeKeys<S extends Top & {
|
|
|
2501
2653
|
* computed or enriched fields to live in the decoded type without appearing in
|
|
2502
2654
|
* the encoded form.
|
|
2503
2655
|
*
|
|
2504
|
-
* **Example** (
|
|
2656
|
+
* **Example** (Adding a computed `fullName` field)
|
|
2505
2657
|
*
|
|
2506
2658
|
* ```ts
|
|
2507
2659
|
* import { Option, Schema } from "effect"
|
|
@@ -2688,9 +2840,20 @@ export interface $Record<Key extends Record.Key, Value extends Top> extends Bott
|
|
|
2688
2840
|
readonly value: Value;
|
|
2689
2841
|
}
|
|
2690
2842
|
/**
|
|
2691
|
-
* Defines a record
|
|
2843
|
+
* Defines a record schema whose dynamic properties are selected by a key schema
|
|
2844
|
+
* and decoded with a value schema.
|
|
2845
|
+
*
|
|
2846
|
+
* **Details**
|
|
2847
|
+
*
|
|
2848
|
+
* For dynamic keys, the key schema selects matching own properties and the
|
|
2849
|
+
* value schema decodes or encodes only those selected properties. Checks on
|
|
2850
|
+
* string, number, symbol, and template literal key schemas narrow which
|
|
2851
|
+
* properties are selected.
|
|
2692
2852
|
*
|
|
2693
|
-
*
|
|
2853
|
+
* For transformed key schemas, property selection is based on encoded property
|
|
2854
|
+
* names before the selected key is decoded.
|
|
2855
|
+
*
|
|
2856
|
+
* **Example** (Defining a string-keyed record of numbers)
|
|
2694
2857
|
*
|
|
2695
2858
|
* ```ts
|
|
2696
2859
|
* import { Schema } from "effect"
|
|
@@ -2831,7 +2994,7 @@ export interface StructWithRest<S extends StructWithRest.Objects, Records extend
|
|
|
2831
2994
|
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
2832
2995
|
* producing a schema whose decoded type intersects the struct and all records.
|
|
2833
2996
|
*
|
|
2834
|
-
* **Example** (
|
|
2997
|
+
* **Example** (Defining structs with string-indexed extra keys)
|
|
2835
2998
|
*
|
|
2836
2999
|
* ```ts
|
|
2837
3000
|
* import { Schema } from "effect"
|
|
@@ -2984,7 +3147,7 @@ export interface Tuple<Elements extends Tuple.Elements> extends Bottom<Tuple.Typ
|
|
|
2984
3147
|
/**
|
|
2985
3148
|
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
2986
3149
|
*
|
|
2987
|
-
* **Example** (
|
|
3150
|
+
* **Example** (Defining a pair of string and number)
|
|
2988
3151
|
*
|
|
2989
3152
|
* ```ts
|
|
2990
3153
|
* import { Schema } from "effect"
|
|
@@ -3137,7 +3300,7 @@ export interface TupleWithRest<S extends TupleWithRest.TupleType, Rest extends T
|
|
|
3137
3300
|
* example, `[Schema.Boolean, Schema.String]` represents zero or more booleans
|
|
3138
3301
|
* followed by a final string.
|
|
3139
3302
|
*
|
|
3140
|
-
* **Example** (
|
|
3303
|
+
* **Example** (Defining tuples with rest elements)
|
|
3141
3304
|
*
|
|
3142
3305
|
* ```ts
|
|
3143
3306
|
* import { Schema } from "effect"
|
|
@@ -3179,7 +3342,7 @@ export {
|
|
|
3179
3342
|
/**
|
|
3180
3343
|
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
3181
3344
|
*
|
|
3182
|
-
* **Example** (
|
|
3345
|
+
* **Example** (Defining an array of strings)
|
|
3183
3346
|
*
|
|
3184
3347
|
* ```ts
|
|
3185
3348
|
* import { Schema } from "effect"
|
|
@@ -3212,7 +3375,7 @@ interface NonEmptyArrayLambda extends Lambda {
|
|
|
3212
3375
|
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
3213
3376
|
* Type is `readonly [T, ...T[]]`.
|
|
3214
3377
|
*
|
|
3215
|
-
* **Example** (
|
|
3378
|
+
* **Example** (Defining a non-empty array of numbers)
|
|
3216
3379
|
*
|
|
3217
3380
|
* ```ts
|
|
3218
3381
|
* import { Schema } from "effect"
|
|
@@ -3306,7 +3469,7 @@ interface mutableLambda extends Lambda {
|
|
|
3306
3469
|
/**
|
|
3307
3470
|
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
3308
3471
|
*
|
|
3309
|
-
* **Example** (
|
|
3472
|
+
* **Example** (Defining mutable arrays)
|
|
3310
3473
|
*
|
|
3311
3474
|
* ```ts
|
|
3312
3475
|
* import { Schema } from "effect"
|
|
@@ -3373,7 +3536,7 @@ export interface Union<Members extends ReadonlyArray<Top>> extends Bottom<{
|
|
|
3373
3536
|
* - `"anyOf"` (default) — matches if any member matches.
|
|
3374
3537
|
* - `"oneOf"` — matches if exactly one member matches.
|
|
3375
3538
|
*
|
|
3376
|
-
* **Example** (
|
|
3539
|
+
* **Example** (Defining a string or number union)
|
|
3377
3540
|
*
|
|
3378
3541
|
* ```ts
|
|
3379
3542
|
* import { Schema } from "effect"
|
|
@@ -3415,7 +3578,7 @@ export interface Literals<L extends ReadonlyArray<SchemaAST.LiteralValue>> exten
|
|
|
3415
3578
|
/**
|
|
3416
3579
|
* Creates a union schema from an array of literal values.
|
|
3417
3580
|
*
|
|
3418
|
-
* **Example** (
|
|
3581
|
+
* **Example** (Defining status codes)
|
|
3419
3582
|
*
|
|
3420
3583
|
* ```ts
|
|
3421
3584
|
* import { Schema } from "effect"
|
|
@@ -3502,7 +3665,7 @@ export interface suspend<S extends Top> extends Bottom<S["Type"], S["Encoded"],
|
|
|
3502
3665
|
* essential for creating recursive schemas where a schema references itself,
|
|
3503
3666
|
* preventing infinite recursion during schema definition.
|
|
3504
3667
|
*
|
|
3505
|
-
* **Example** (
|
|
3668
|
+
* **Example** (Defining recursive tree schemas)
|
|
3506
3669
|
*
|
|
3507
3670
|
* ```ts
|
|
3508
3671
|
* import { Schema } from "effect"
|
|
@@ -3798,7 +3961,7 @@ export interface compose<To extends Top, From extends Top> extends decodeTo<To,
|
|
|
3798
3961
|
* and is used on the encoding path, while `encode` maps `To["Encoded"]` to
|
|
3799
3962
|
* `From["Type"]` and is used on the decoding path.
|
|
3800
3963
|
*
|
|
3801
|
-
* **Example** (
|
|
3964
|
+
* **Example** (Transforming strings to numbers with a schema transformation)
|
|
3802
3965
|
*
|
|
3803
3966
|
* ```ts
|
|
3804
3967
|
* import { Schema, SchemaGetter } from "effect"
|
|
@@ -3885,7 +4048,7 @@ export declare function decode<S extends Top, RD = never, RE = never>(transforma
|
|
|
3885
4048
|
* `encodeTo(to)(from)` is equivalent to `to.pipe(decodeTo(from))`. The `from`
|
|
3886
4049
|
* schema acts as the target decoded schema and `to` acts as the encoded source.
|
|
3887
4050
|
*
|
|
3888
|
-
* **Example** (
|
|
4051
|
+
* **Example** (Encoding a number back to a string)
|
|
3889
4052
|
*
|
|
3890
4053
|
* ```ts
|
|
3891
4054
|
* import { Schema, SchemaGetter } from "effect"
|
|
@@ -3965,7 +4128,7 @@ export interface withConstructorDefault<S extends Top & WithoutConstructorDefaul
|
|
|
3965
4128
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
3966
4129
|
* encoding.
|
|
3967
4130
|
*
|
|
3968
|
-
* **Example** (
|
|
4131
|
+
* **Example** (Defining an optional field with a static default)
|
|
3969
4132
|
*
|
|
3970
4133
|
* ```ts
|
|
3971
4134
|
* import { Effect, Schema } from "effect"
|
|
@@ -4025,7 +4188,7 @@ export type DecodingDefaultOptions = {
|
|
|
4025
4188
|
* - `"passthrough"` (default): include the value in the encoded output.
|
|
4026
4189
|
* - `"omit"`: omit the key from the encoded output.
|
|
4027
4190
|
*
|
|
4028
|
-
* **Example** (
|
|
4191
|
+
* **Example** (Providing a default for a missing struct key)
|
|
4029
4192
|
*
|
|
4030
4193
|
* ```ts
|
|
4031
4194
|
* import { Effect, Schema } from "effect"
|
|
@@ -4106,7 +4269,7 @@ export interface withDecodingDefault<S extends Top, R = never> extends decodeTo<
|
|
|
4106
4269
|
* - `"passthrough"` (default): include the value in the encoded output.
|
|
4107
4270
|
* - `"omit"`: omit the key from the encoded output.
|
|
4108
4271
|
*
|
|
4109
|
-
* **Example** (
|
|
4272
|
+
* **Example** (Providing a default for an optional field value)
|
|
4110
4273
|
*
|
|
4111
4274
|
* ```ts
|
|
4112
4275
|
* import { Effect, Schema } from "effect"
|
|
@@ -4175,7 +4338,7 @@ export interface tag<Tag extends SchemaAST.LiteralValue> extends withConstructor
|
|
|
4175
4338
|
* for discriminator fields in tagged unions. When constructing via `make`, the
|
|
4176
4339
|
* `_tag` field can be omitted and will be filled automatically.
|
|
4177
4340
|
*
|
|
4178
|
-
* **Example** (
|
|
4341
|
+
* **Example** (Defining a discriminated union tag)
|
|
4179
4342
|
*
|
|
4180
4343
|
* ```ts
|
|
4181
4344
|
* import { Schema } from "effect"
|
|
@@ -4206,7 +4369,7 @@ export declare function tag<Tag extends SchemaAST.LiteralValue>(literal: Tag): t
|
|
|
4206
4369
|
* The tag is filled during decoding and construction, like {@link tag}, but is
|
|
4207
4370
|
* omitted when encoding.
|
|
4208
4371
|
*
|
|
4209
|
-
* **Example** (
|
|
4372
|
+
* **Example** (Omitting tags during encoding)
|
|
4210
4373
|
*
|
|
4211
4374
|
* ```ts
|
|
4212
4375
|
* import { Schema } from "effect"
|
|
@@ -4248,7 +4411,7 @@ export type TaggedStruct<Tag extends SchemaAST.LiteralValue, Fields extends Stru
|
|
|
4248
4411
|
* added automatically. However, when decoding or encoding, the `_tag` field
|
|
4249
4412
|
* must be present in the input.
|
|
4250
4413
|
*
|
|
4251
|
-
* **Example** (
|
|
4414
|
+
* **Example** (Defining a tagged struct shorthand)
|
|
4252
4415
|
*
|
|
4253
4416
|
* ```ts
|
|
4254
4417
|
* import { Schema } from "effect"
|
|
@@ -4389,7 +4552,7 @@ export interface TaggedUnion<Cases extends Record<string, Top>> extends Bottom<{
|
|
|
4389
4552
|
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
4390
4553
|
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
4391
4554
|
*
|
|
4392
|
-
* **Example** (
|
|
4555
|
+
* **Example** (Pattern matching a discriminated union)
|
|
4393
4556
|
*
|
|
4394
4557
|
* ```ts
|
|
4395
4558
|
* import { Schema } from "effect"
|
|
@@ -4427,7 +4590,7 @@ export interface Opaque<Self, S extends Top, Brand> extends Bottom<Self, S["Enco
|
|
|
4427
4590
|
* Useful for creating opaque types that are structurally identical to a base struct
|
|
4428
4591
|
* but type-incompatible with it.
|
|
4429
4592
|
*
|
|
4430
|
-
* **Example** (
|
|
4593
|
+
* **Example** (Defining opaque structs)
|
|
4431
4594
|
*
|
|
4432
4595
|
* ```ts
|
|
4433
4596
|
* import { Schema } from "effect"
|
|
@@ -4460,7 +4623,7 @@ export interface instanceOf<T, Iso = T> extends declare<T, Iso> {
|
|
|
4460
4623
|
* Creates a schema that validates values using `instanceof`.
|
|
4461
4624
|
* Decoding and encoding pass the value through unchanged.
|
|
4462
4625
|
*
|
|
4463
|
-
* **Example** (
|
|
4626
|
+
* **Example** (Defining a schema for a built-in class)
|
|
4464
4627
|
*
|
|
4465
4628
|
* ```ts
|
|
4466
4629
|
* import { Schema } from "effect"
|
|
@@ -4500,7 +4663,7 @@ export declare function link<T>(): <To extends Top>(encodeTo: To, transformation
|
|
|
4500
4663
|
* When `abort` is `true`, parsing stops after this filter fails instead of
|
|
4501
4664
|
* collecting later check failures.
|
|
4502
4665
|
*
|
|
4503
|
-
* **Example** (
|
|
4666
|
+
* **Example** (Reporting failure at a nested path)
|
|
4504
4667
|
*
|
|
4505
4668
|
* ```ts
|
|
4506
4669
|
* import { Schema } from "effect"
|
|
@@ -5442,7 +5605,7 @@ export declare const isBetweenBigDecimal: (options: {
|
|
|
5442
5605
|
* constraint to ensure generated strings or arrays have at least the required
|
|
5443
5606
|
* length.
|
|
5444
5607
|
*
|
|
5445
|
-
* **Example** (
|
|
5608
|
+
* **Example** (Checking minimum length)
|
|
5446
5609
|
*
|
|
5447
5610
|
* ```ts
|
|
5448
5611
|
* import { Schema } from "effect"
|
|
@@ -6476,7 +6639,7 @@ export interface Date extends instanceOf<globalThis.Date> {
|
|
|
6476
6639
|
* JSON serializer encodes valid dates as ISO 8601 strings; invalid dates encode
|
|
6477
6640
|
* as `"Invalid Date"`.
|
|
6478
6641
|
*
|
|
6479
|
-
* **Example** (Date schema)
|
|
6642
|
+
* **Example** (Defining a Date schema)
|
|
6480
6643
|
*
|
|
6481
6644
|
* ```ts
|
|
6482
6645
|
* import { Schema } from "effect"
|
|
@@ -6566,7 +6729,7 @@ export interface Duration extends declare<Duration_.Duration> {
|
|
|
6566
6729
|
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
6567
6730
|
* duration type and value.
|
|
6568
6731
|
*
|
|
6569
|
-
* **Example** (Duration schema)
|
|
6732
|
+
* **Example** (Defining a Duration schema)
|
|
6570
6733
|
*
|
|
6571
6734
|
* ```ts
|
|
6572
6735
|
* import { Duration, Schema } from "effect"
|
|
@@ -6928,7 +7091,7 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
|
6928
7091
|
* // Success({"a":"1"})
|
|
6929
7092
|
* ```
|
|
6930
7093
|
*
|
|
6931
|
-
* **Example** (
|
|
7094
|
+
* **Example** (Decoding nested fields)
|
|
6932
7095
|
*
|
|
6933
7096
|
* ```ts
|
|
6934
7097
|
* import { Schema } from "effect"
|
|
@@ -7043,7 +7206,7 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
|
|
|
7043
7206
|
* // Success({"a":"1"})
|
|
7044
7207
|
* ```
|
|
7045
7208
|
*
|
|
7046
|
-
* **Example** (
|
|
7209
|
+
* **Example** (Decoding nested fields)
|
|
7047
7210
|
*
|
|
7048
7211
|
* ```ts
|
|
7049
7212
|
* import { Schema } from "effect"
|
|
@@ -7828,7 +7991,31 @@ export interface Class<Self, S extends Top & {
|
|
|
7828
7991
|
mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
|
|
7829
7992
|
readonly unsafePreserveChecks?: boolean | undefined;
|
|
7830
7993
|
} | undefined): Struct<Simplify<Readonly<To>>>;
|
|
7831
|
-
|
|
7994
|
+
/**
|
|
7995
|
+
* Returns a function that creates a schema-backed subclass with this class's
|
|
7996
|
+
* fields plus additional fields.
|
|
7997
|
+
*
|
|
7998
|
+
* **When to use**
|
|
7999
|
+
*
|
|
8000
|
+
* Use when you need a subclass whose constructor validates both inherited
|
|
8001
|
+
* fields and newly added fields.
|
|
8002
|
+
*
|
|
8003
|
+
* **Details**
|
|
8004
|
+
*
|
|
8005
|
+
* The returned function accepts either a field map or a `Struct`. When you
|
|
8006
|
+
* pass a `Struct`, checks attached to that extension schema are preserved and
|
|
8007
|
+
* combined with checks from the base class schema.
|
|
8008
|
+
*
|
|
8009
|
+
* **Gotchas**
|
|
8010
|
+
*
|
|
8011
|
+
* Checks from a `Struct` argument are evaluated against the full subclass
|
|
8012
|
+
* value after inherited and extension fields are merged. Object-wide checks
|
|
8013
|
+
* such as `isMaxProperties` count inherited fields too.
|
|
8014
|
+
*/
|
|
8015
|
+
extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
|
|
8016
|
+
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
|
|
8017
|
+
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
|
|
8018
|
+
};
|
|
7832
8019
|
}
|
|
7833
8020
|
type InheritStaticMembers<C, Static> = C & Pick<Static, Exclude<keyof Static, keyof C>>;
|
|
7834
8021
|
type MissingSelfGeneric<Usage extends string> = `Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``;
|
|
@@ -7851,7 +8038,7 @@ type MissingSelfGeneric<Usage extends string> = `Missing \`Self\` generic - use
|
|
|
7851
8038
|
*
|
|
7852
8039
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
7853
8040
|
*
|
|
7854
|
-
* **Example** (
|
|
8041
|
+
* **Example** (Defining a basic class)
|
|
7855
8042
|
*
|
|
7856
8043
|
* ```ts
|
|
7857
8044
|
* import { Schema } from "effect"
|
|
@@ -7911,7 +8098,7 @@ export declare const Class: {
|
|
|
7911
8098
|
*
|
|
7912
8099
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
7913
8100
|
*
|
|
7914
|
-
* **Example** (
|
|
8101
|
+
* **Example** (Defining a basic class)
|
|
7915
8102
|
*
|
|
7916
8103
|
* ```ts
|
|
7917
8104
|
* import { Schema } from "effect"
|
|
@@ -7971,7 +8158,7 @@ export declare const Class: {
|
|
|
7971
8158
|
*
|
|
7972
8159
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
7973
8160
|
*
|
|
7974
|
-
* **Example** (
|
|
8161
|
+
* **Example** (Defining a basic class)
|
|
7975
8162
|
*
|
|
7976
8163
|
* ```ts
|
|
7977
8164
|
* import { Schema } from "effect"
|
|
@@ -8031,7 +8218,7 @@ export declare const Class: {
|
|
|
8031
8218
|
*
|
|
8032
8219
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
8033
8220
|
*
|
|
8034
|
-
* **Example** (
|
|
8221
|
+
* **Example** (Defining a basic class)
|
|
8035
8222
|
*
|
|
8036
8223
|
* ```ts
|
|
8037
8224
|
* import { Schema } from "effect"
|
|
@@ -8087,7 +8274,7 @@ export declare const Class: {
|
|
|
8087
8274
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
8088
8275
|
* it defaults to the `tag` value.
|
|
8089
8276
|
*
|
|
8090
|
-
* **Example** (
|
|
8277
|
+
* **Example** (Defining a tagged class)
|
|
8091
8278
|
*
|
|
8092
8279
|
* ```ts
|
|
8093
8280
|
* import { Schema } from "effect"
|
|
@@ -8118,7 +8305,7 @@ export declare const TaggedClass: {
|
|
|
8118
8305
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
8119
8306
|
* it defaults to the `tag` value.
|
|
8120
8307
|
*
|
|
8121
|
-
* **Example** (
|
|
8308
|
+
* **Example** (Defining a tagged class)
|
|
8122
8309
|
*
|
|
8123
8310
|
* ```ts
|
|
8124
8311
|
* import { Schema } from "effect"
|
|
@@ -8149,7 +8336,7 @@ export declare const TaggedClass: {
|
|
|
8149
8336
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
8150
8337
|
* it defaults to the `tag` value.
|
|
8151
8338
|
*
|
|
8152
|
-
* **Example** (
|
|
8339
|
+
* **Example** (Defining a tagged class)
|
|
8153
8340
|
*
|
|
8154
8341
|
* ```ts
|
|
8155
8342
|
* import { Schema } from "effect"
|
|
@@ -8180,7 +8367,7 @@ export declare const TaggedClass: {
|
|
|
8180
8367
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
8181
8368
|
* it defaults to the `tag` value.
|
|
8182
8369
|
*
|
|
8183
|
-
* **Example** (
|
|
8370
|
+
* **Example** (Defining a tagged class)
|
|
8184
8371
|
*
|
|
8185
8372
|
* ```ts
|
|
8186
8373
|
* import { Schema } from "effect"
|
|
@@ -8311,7 +8498,7 @@ export declare const ErrorClass: {
|
|
|
8311
8498
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
8312
8499
|
* and matched as tagged union members.
|
|
8313
8500
|
*
|
|
8314
|
-
* **Example** (
|
|
8501
|
+
* **Example** (Defining a tagged error class)
|
|
8315
8502
|
*
|
|
8316
8503
|
* ```ts
|
|
8317
8504
|
* import { Effect, Schema } from "effect"
|
|
@@ -8338,7 +8525,7 @@ export declare const TaggedErrorClass: {
|
|
|
8338
8525
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
8339
8526
|
* and matched as tagged union members.
|
|
8340
8527
|
*
|
|
8341
|
-
* **Example** (
|
|
8528
|
+
* **Example** (Defining a tagged error class)
|
|
8342
8529
|
*
|
|
8343
8530
|
* ```ts
|
|
8344
8531
|
* import { Effect, Schema } from "effect"
|
|
@@ -8365,7 +8552,7 @@ export declare const TaggedErrorClass: {
|
|
|
8365
8552
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
8366
8553
|
* and matched as tagged union members.
|
|
8367
8554
|
*
|
|
8368
|
-
* **Example** (
|
|
8555
|
+
* **Example** (Defining a tagged error class)
|
|
8369
8556
|
*
|
|
8370
8557
|
* ```ts
|
|
8371
8558
|
* import { Effect, Schema } from "effect"
|
|
@@ -8392,7 +8579,7 @@ export declare const TaggedErrorClass: {
|
|
|
8392
8579
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
8393
8580
|
* and matched as tagged union members.
|
|
8394
8581
|
*
|
|
8395
|
-
* **Example** (
|
|
8582
|
+
* **Example** (Defining a tagged error class)
|
|
8396
8583
|
*
|
|
8397
8584
|
* ```ts
|
|
8398
8585
|
* import { Effect, Schema } from "effect"
|
|
@@ -8520,7 +8707,7 @@ export declare function overrideToEquivalence<S extends Top>(toEquivalence: () =
|
|
|
8520
8707
|
* every field (and nested field) compares equal according to the schema
|
|
8521
8708
|
* structure.
|
|
8522
8709
|
*
|
|
8523
|
-
* **Example** (
|
|
8710
|
+
* **Example** (Comparing structs)
|
|
8524
8711
|
*
|
|
8525
8712
|
* ```ts
|
|
8526
8713
|
* import { Schema } from "effect"
|