effect 4.0.0-beta.82 → 4.0.0-beta.84
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/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 +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/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 +265 -120
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +285 -116
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +13 -9
- 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 +23 -10
- package/dist/internal/effect.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/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/cli/Prompt.js +2 -2
- package/dist/unstable/cli/Prompt.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +39 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +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/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/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 +1 -1
- 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/Reducer.ts +1 -1
- package/src/Result.ts +20 -20
- package/src/Runtime.ts +1 -1
- package/src/Schema.ts +314 -131
- package/src/SchemaAST.ts +20 -11
- 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 +29 -10
- package/src/internal/schema/cause.ts +26 -0
- package/src/internal/schema/schema.ts +36 -10
- 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/cli/Prompt.ts +1 -1
- package/src/unstable/httpapi/HttpApiScalar.ts +2 -2
- package/src/unstable/httpapi/HttpApiSchema.ts +18 -6
- package/src/unstable/rpc/Rpc.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -4
- 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/src/Schema.ts
CHANGED
|
@@ -202,6 +202,8 @@ export interface Bottom<
|
|
|
202
202
|
*
|
|
203
203
|
* Throws an `Error` with the schema issue in its `cause` when validation
|
|
204
204
|
* fails.
|
|
205
|
+
* Causes that contain defects, interruptions, or other non-schema reasons
|
|
206
|
+
* throw with the underlying `Cause` attached instead.
|
|
205
207
|
*
|
|
206
208
|
* @see {@link Bottom.makeOption} — construct synchronously and discard validation details
|
|
207
209
|
* @see {@link Bottom.makeEffect} — construct through `Effect` when validation failure should stay in the error channel
|
|
@@ -221,6 +223,12 @@ export interface Bottom<
|
|
|
221
223
|
* Applies constructor defaults and type-side validation according to
|
|
222
224
|
* `MakeOptions`.
|
|
223
225
|
*
|
|
226
|
+
* **Gotchas**
|
|
227
|
+
*
|
|
228
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
229
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
230
|
+
* instead.
|
|
231
|
+
*
|
|
224
232
|
* @see {@link Bottom.make} — construct synchronously when validation failure should throw
|
|
225
233
|
* @see {@link Bottom.makeEffect} — construct through `Effect` when validation details should stay in the error channel
|
|
226
234
|
*/
|
|
@@ -358,7 +366,7 @@ export interface declare<T, Iso = T> extends declareConstructor<T, T, readonly [
|
|
|
358
366
|
* Use when you are defining a schema for an opaque type with no type parameters
|
|
359
367
|
* and validation can be expressed as a type guard.
|
|
360
368
|
*
|
|
361
|
-
* **Example** (
|
|
369
|
+
* **Example** (Defining a schema for a custom `UserId` branded type)
|
|
362
370
|
*
|
|
363
371
|
* ```ts
|
|
364
372
|
* import { Schema } from "effect"
|
|
@@ -522,7 +530,7 @@ export function annotateEncoded<S extends Top>(annotations: Annotations.Bottom<S
|
|
|
522
530
|
* as well as standard documentation fields such as `title`, `description`,
|
|
523
531
|
* and `examples`.
|
|
524
532
|
*
|
|
525
|
-
* **Example** (
|
|
533
|
+
* **Example** (Customizing the missing-key message for a required field)
|
|
526
534
|
*
|
|
527
535
|
* ```ts
|
|
528
536
|
* import { Schema } from "effect"
|
|
@@ -622,7 +630,7 @@ export declare namespace Schema {
|
|
|
622
630
|
* constructors in this module (e.g. {@link Struct}, {@link String}, {@link Number}).
|
|
623
631
|
* When you also need the encoded type or service requirements, use {@link Codec}.
|
|
624
632
|
*
|
|
625
|
-
* **Example** (
|
|
633
|
+
* **Example** (Accepting any schema decoding to `string`)
|
|
626
634
|
*
|
|
627
635
|
* ```ts
|
|
628
636
|
* import { Schema } from "effect"
|
|
@@ -777,7 +785,7 @@ export interface Codec<out T, out E = T, out RD = never, out RE = never> extends
|
|
|
777
785
|
* constraining or depending on the encoded representation (`Encoded` is
|
|
778
786
|
* `unknown`) or encoding services.
|
|
779
787
|
*
|
|
780
|
-
* **Example** (
|
|
788
|
+
* **Example** (Accepting schemas that only need to decode)
|
|
781
789
|
*
|
|
782
790
|
* ```ts
|
|
783
791
|
* import { Schema } from "effect"
|
|
@@ -804,7 +812,7 @@ export interface Decoder<out T, out RD = never> extends Codec<T, unknown, RD, un
|
|
|
804
812
|
* constraining or depending on the decoded `Type` (`Type` is `unknown`) or
|
|
805
813
|
* decoding services.
|
|
806
814
|
*
|
|
807
|
-
* **Example** (
|
|
815
|
+
* **Example** (Accepting schemas that only need to encode)
|
|
808
816
|
*
|
|
809
817
|
* ```ts
|
|
810
818
|
* import { Schema } from "effect"
|
|
@@ -889,7 +897,7 @@ export {
|
|
|
889
897
|
/**
|
|
890
898
|
* Returns `true` if `u` is a {@link SchemaError}.
|
|
891
899
|
*
|
|
892
|
-
* **Example** (
|
|
900
|
+
* **Example** (Narrowing Schema errors in a catch block)
|
|
893
901
|
*
|
|
894
902
|
* ```ts
|
|
895
903
|
* import { Schema } from "effect"
|
|
@@ -1090,10 +1098,16 @@ export function toStandardJSONSchemaV1<S extends Top>(self: S): StandardJSONSche
|
|
|
1090
1098
|
* **Details**
|
|
1091
1099
|
*
|
|
1092
1100
|
* This function returns a predicate that performs a type-safe check, narrowing
|
|
1093
|
-
* the type of the input value if the check passes.
|
|
1094
|
-
*
|
|
1101
|
+
* the type of the input value if the check passes. The predicate returns `false`
|
|
1102
|
+
* for schema mismatches.
|
|
1103
|
+
*
|
|
1104
|
+
* **Gotchas**
|
|
1105
|
+
*
|
|
1106
|
+
* Only causes made entirely of schema issues are converted to `false`. Causes
|
|
1107
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1108
|
+
* instead.
|
|
1095
1109
|
*
|
|
1096
|
-
* **Example** (
|
|
1110
|
+
* **Example** (Defining a basic type guard)
|
|
1097
1111
|
*
|
|
1098
1112
|
* ```ts
|
|
1099
1113
|
* import { Schema } from "effect"
|
|
@@ -1117,7 +1131,7 @@ export function toStandardJSONSchemaV1<S extends Top>(self: S): StandardJSONSche
|
|
|
1117
1131
|
export const is = SchemaParser.is
|
|
1118
1132
|
|
|
1119
1133
|
/**
|
|
1120
|
-
* Creates an assertion function that throws an error if the input
|
|
1134
|
+
* Creates an assertion function that throws an error if the input does not match
|
|
1121
1135
|
* the schema.
|
|
1122
1136
|
*
|
|
1123
1137
|
* **When to use**
|
|
@@ -1127,10 +1141,16 @@ export const is = SchemaParser.is
|
|
|
1127
1141
|
*
|
|
1128
1142
|
* **Details**
|
|
1129
1143
|
*
|
|
1130
|
-
* The input is narrowed if the assertion succeeds. If validation fails,
|
|
1131
|
-
* assertion throws.
|
|
1144
|
+
* The input is narrowed if the assertion succeeds. If schema validation fails,
|
|
1145
|
+
* the assertion throws an `Error` whose cause is `SchemaIssue.Issue`.
|
|
1132
1146
|
*
|
|
1133
|
-
* **
|
|
1147
|
+
* **Gotchas**
|
|
1148
|
+
*
|
|
1149
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1150
|
+
* with the underlying `Cause` attached instead of being converted to schema
|
|
1151
|
+
* validation errors.
|
|
1152
|
+
*
|
|
1153
|
+
* **Example** (Asserting and narrowing an input)
|
|
1134
1154
|
*
|
|
1135
1155
|
* ```ts
|
|
1136
1156
|
* import { Schema } from "effect"
|
|
@@ -1182,7 +1202,7 @@ export function decodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAS
|
|
|
1182
1202
|
input: unknown,
|
|
1183
1203
|
options?: SchemaAST.ParseOptions
|
|
1184
1204
|
): Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]> => {
|
|
1185
|
-
return
|
|
1205
|
+
return InternalSchema.mapSchemaIssueEffect(parser(input, options))
|
|
1186
1206
|
}
|
|
1187
1207
|
}
|
|
1188
1208
|
|
|
@@ -1215,15 +1235,52 @@ export const decodeEffect: <S extends Top>(
|
|
|
1215
1235
|
options?: SchemaAST.ParseOptions
|
|
1216
1236
|
) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]> = decodeUnknownEffect
|
|
1217
1237
|
|
|
1238
|
+
function getSchemaErrorOrThrow(
|
|
1239
|
+
cause: Cause_.Cause<SchemaError>,
|
|
1240
|
+
message: string
|
|
1241
|
+
): SchemaError {
|
|
1242
|
+
let schemaError: SchemaError | undefined
|
|
1243
|
+
for (const reason of cause.reasons) {
|
|
1244
|
+
if (!Cause_.isFailReason(reason) || !isSchemaError(reason.error)) {
|
|
1245
|
+
throw new globalThis.Error(message, { cause })
|
|
1246
|
+
}
|
|
1247
|
+
schemaError ??= reason.error
|
|
1248
|
+
}
|
|
1249
|
+
if (schemaError === undefined) {
|
|
1250
|
+
throw new globalThis.Error(message, { cause })
|
|
1251
|
+
}
|
|
1252
|
+
return schemaError
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
function runSchemaErrorPromise<A>(
|
|
1256
|
+
self: Effect.Effect<A, SchemaError>
|
|
1257
|
+
): Promise<A> {
|
|
1258
|
+
return Effect.runPromiseExit(self).then((exit) => {
|
|
1259
|
+
if (Exit_.isSuccess(exit)) {
|
|
1260
|
+
return exit.value
|
|
1261
|
+
}
|
|
1262
|
+
throw getSchemaErrorOrThrow(exit.cause, "Promise adapter can only reject schema errors")
|
|
1263
|
+
})
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function runSchemaErrorSync<A>(
|
|
1267
|
+
self: Effect.Effect<A, SchemaError>
|
|
1268
|
+
): A {
|
|
1269
|
+
const exit = Effect.runSyncExit(self)
|
|
1270
|
+
if (Exit_.isSuccess(exit)) {
|
|
1271
|
+
return exit.value
|
|
1272
|
+
}
|
|
1273
|
+
throw getSchemaErrorOrThrow(exit.cause, "Sync adapter can only throw schema errors")
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1218
1276
|
/**
|
|
1219
1277
|
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
1220
|
-
* `Exit` that is either a `Success` with the decoded value or a `Failure
|
|
1221
|
-
* a {@link SchemaError}.
|
|
1278
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure`.
|
|
1222
1279
|
*
|
|
1223
1280
|
* **When to use**
|
|
1224
1281
|
*
|
|
1225
|
-
* Use when you need to decode unknown input into an `Exit`
|
|
1226
|
-
*
|
|
1282
|
+
* Use when you need to decode unknown input into an `Exit` and capture schema
|
|
1283
|
+
* mismatches as `SchemaError`.
|
|
1227
1284
|
*
|
|
1228
1285
|
* **Details**
|
|
1229
1286
|
*
|
|
@@ -1232,6 +1289,14 @@ export const decodeEffect: <S extends Top>(
|
|
|
1232
1289
|
* type.
|
|
1233
1290
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1234
1291
|
* application options override creation options.
|
|
1292
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1293
|
+
* `SchemaError`.
|
|
1294
|
+
*
|
|
1295
|
+
* **Gotchas**
|
|
1296
|
+
*
|
|
1297
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1298
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1299
|
+
* including when they are mixed with schema issues.
|
|
1235
1300
|
*
|
|
1236
1301
|
* @see {@link SchemaParser.decodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1237
1302
|
*
|
|
@@ -1241,19 +1306,19 @@ export const decodeEffect: <S extends Top>(
|
|
|
1241
1306
|
export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1242
1307
|
const parser = SchemaParser.decodeUnknownExit(schema, options)
|
|
1243
1308
|
return (input: unknown, options?: SchemaAST.ParseOptions): Exit_.Exit<S["Type"], SchemaError> => {
|
|
1244
|
-
return
|
|
1309
|
+
return InternalSchema.mapSchemaIssueExit(parser(input, options))
|
|
1245
1310
|
}
|
|
1246
1311
|
}
|
|
1247
1312
|
|
|
1248
1313
|
/**
|
|
1249
1314
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
1250
|
-
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
1251
|
-
*
|
|
1315
|
+
* synchronously, returning an `Exit` that is either a `Success` with the decoded
|
|
1316
|
+
* value or a `Failure`.
|
|
1252
1317
|
*
|
|
1253
1318
|
* **When to use**
|
|
1254
1319
|
*
|
|
1255
|
-
* Use when you need to decode already typed `Encoded` input into an `Exit`
|
|
1256
|
-
*
|
|
1320
|
+
* Use when you need to decode already typed `Encoded` input into an `Exit` and
|
|
1321
|
+
* capture schema mismatches as `SchemaError`.
|
|
1257
1322
|
*
|
|
1258
1323
|
* **Details**
|
|
1259
1324
|
*
|
|
@@ -1261,6 +1326,14 @@ export function decodeUnknownExit<S extends Decoder<unknown>>(schema: S, options
|
|
|
1261
1326
|
* `unknown` input use {@link decodeUnknownExit}.
|
|
1262
1327
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1263
1328
|
* application options override creation options.
|
|
1329
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1330
|
+
* `SchemaError`.
|
|
1331
|
+
*
|
|
1332
|
+
* **Gotchas**
|
|
1333
|
+
*
|
|
1334
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1335
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1336
|
+
* including when they are mixed with schema issues.
|
|
1264
1337
|
*
|
|
1265
1338
|
* @see {@link SchemaParser.decodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1266
1339
|
*
|
|
@@ -1274,7 +1347,7 @@ export const decodeExit: <S extends Decoder<unknown>>(
|
|
|
1274
1347
|
|
|
1275
1348
|
/**
|
|
1276
1349
|
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
1277
|
-
* `Some` with the decoded value on success or `None`
|
|
1350
|
+
* `Some` with the decoded value on success or `None` for schema mismatches.
|
|
1278
1351
|
*
|
|
1279
1352
|
* **When to use**
|
|
1280
1353
|
*
|
|
@@ -1289,6 +1362,12 @@ export const decodeExit: <S extends Decoder<unknown>>(
|
|
|
1289
1362
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1290
1363
|
* application options override creation options.
|
|
1291
1364
|
*
|
|
1365
|
+
* **Gotchas**
|
|
1366
|
+
*
|
|
1367
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1368
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1369
|
+
* instead.
|
|
1370
|
+
*
|
|
1292
1371
|
* @category decoding
|
|
1293
1372
|
* @since 3.10.0
|
|
1294
1373
|
*/
|
|
@@ -1300,7 +1379,7 @@ export const decodeUnknownOption: <S extends Decoder<unknown>>(
|
|
|
1300
1379
|
/**
|
|
1301
1380
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1302
1381
|
* returning an `Option` that is `Some` with the decoded value on success or
|
|
1303
|
-
* `None`
|
|
1382
|
+
* `None` for schema mismatches.
|
|
1304
1383
|
*
|
|
1305
1384
|
* **When to use**
|
|
1306
1385
|
*
|
|
@@ -1313,6 +1392,12 @@ export const decodeUnknownOption: <S extends Decoder<unknown>>(
|
|
|
1313
1392
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1314
1393
|
* application options override creation options.
|
|
1315
1394
|
*
|
|
1395
|
+
* **Gotchas**
|
|
1396
|
+
*
|
|
1397
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1398
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1399
|
+
* instead.
|
|
1400
|
+
*
|
|
1316
1401
|
* @category decoding
|
|
1317
1402
|
* @since 3.10.0
|
|
1318
1403
|
*/
|
|
@@ -1323,12 +1408,13 @@ export const decodeOption: <S extends Decoder<unknown>>(
|
|
|
1323
1408
|
|
|
1324
1409
|
/**
|
|
1325
1410
|
* Decodes an `unknown` input against a schema, returning a `Result` that
|
|
1326
|
-
* succeeds with the decoded value or fails with a {@link SchemaError}
|
|
1411
|
+
* succeeds with the decoded value or fails with a {@link SchemaError} for schema
|
|
1412
|
+
* mismatches.
|
|
1327
1413
|
*
|
|
1328
1414
|
* **When to use**
|
|
1329
1415
|
*
|
|
1330
|
-
* Use when you do not know the input type statically and want
|
|
1331
|
-
*
|
|
1416
|
+
* Use when you do not know the input type statically and want schema mismatches
|
|
1417
|
+
* returned as `Result.fail` with `SchemaError`.
|
|
1332
1418
|
*
|
|
1333
1419
|
* **Details**
|
|
1334
1420
|
*
|
|
@@ -1336,6 +1422,13 @@ export const decodeOption: <S extends Decoder<unknown>>(
|
|
|
1336
1422
|
* {@link decodeResult}.
|
|
1337
1423
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1338
1424
|
* application options override creation options.
|
|
1425
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1426
|
+
*
|
|
1427
|
+
* **Gotchas**
|
|
1428
|
+
*
|
|
1429
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1430
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1431
|
+
* instead.
|
|
1339
1432
|
*
|
|
1340
1433
|
* @see {@link SchemaParser.decodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1341
1434
|
*
|
|
@@ -1352,18 +1445,25 @@ export function decodeUnknownResult<S extends Decoder<unknown>>(schema: S, optio
|
|
|
1352
1445
|
/**
|
|
1353
1446
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1354
1447
|
* returning a `Result` that succeeds with the decoded value or fails with a
|
|
1355
|
-
* {@link SchemaError}.
|
|
1448
|
+
* {@link SchemaError} for schema mismatches.
|
|
1356
1449
|
*
|
|
1357
1450
|
* **When to use**
|
|
1358
1451
|
*
|
|
1359
|
-
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1360
|
-
*
|
|
1452
|
+
* Use when you already have input typed as the schema's `Encoded` type and want
|
|
1453
|
+
* schema mismatches returned as `Result.fail` with `SchemaError`.
|
|
1361
1454
|
*
|
|
1362
1455
|
* **Details**
|
|
1363
1456
|
*
|
|
1364
1457
|
* For `unknown` input use {@link decodeUnknownResult}.
|
|
1365
1458
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1366
1459
|
* application options override creation options.
|
|
1460
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1461
|
+
*
|
|
1462
|
+
* **Gotchas**
|
|
1463
|
+
*
|
|
1464
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1465
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1466
|
+
* instead.
|
|
1367
1467
|
*
|
|
1368
1468
|
* @see {@link SchemaParser.decodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1369
1469
|
*
|
|
@@ -1378,12 +1478,13 @@ export const decodeResult: <S extends Decoder<unknown>>(
|
|
|
1378
1478
|
|
|
1379
1479
|
/**
|
|
1380
1480
|
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
1381
|
-
* resolves with the decoded value or rejects with a {@link SchemaError}
|
|
1481
|
+
* resolves with the decoded value or rejects with a {@link SchemaError} for
|
|
1482
|
+
* schema mismatches.
|
|
1382
1483
|
*
|
|
1383
1484
|
* **When to use**
|
|
1384
1485
|
*
|
|
1385
1486
|
* Use when you need decoding of unknown input to return a JavaScript `Promise`
|
|
1386
|
-
* that rejects with `SchemaError
|
|
1487
|
+
* that rejects with `SchemaError` for schema mismatches.
|
|
1387
1488
|
*
|
|
1388
1489
|
* **Details**
|
|
1389
1490
|
*
|
|
@@ -1392,7 +1493,12 @@ export const decodeResult: <S extends Decoder<unknown>>(
|
|
|
1392
1493
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1393
1494
|
* application options override creation options.
|
|
1394
1495
|
*
|
|
1395
|
-
*
|
|
1496
|
+
* **Gotchas**
|
|
1497
|
+
*
|
|
1498
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1499
|
+
* `SchemaError`.
|
|
1500
|
+
*
|
|
1501
|
+
* @see {@link SchemaParser.decodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1396
1502
|
*
|
|
1397
1503
|
* @category decoding
|
|
1398
1504
|
* @since 3.10.0
|
|
@@ -1400,20 +1506,20 @@ export const decodeResult: <S extends Decoder<unknown>>(
|
|
|
1400
1506
|
export function decodeUnknownPromise<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1401
1507
|
const parser = decodeUnknownEffect(schema, options)
|
|
1402
1508
|
return (input: unknown, options?: SchemaAST.ParseOptions): Promise<S["Type"]> => {
|
|
1403
|
-
return
|
|
1509
|
+
return runSchemaErrorPromise(parser(input, options))
|
|
1404
1510
|
}
|
|
1405
1511
|
}
|
|
1406
1512
|
|
|
1407
1513
|
/**
|
|
1408
1514
|
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
1409
1515
|
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
1410
|
-
* {@link SchemaError}.
|
|
1516
|
+
* {@link SchemaError} for schema mismatches.
|
|
1411
1517
|
*
|
|
1412
1518
|
* **When to use**
|
|
1413
1519
|
*
|
|
1414
1520
|
* Use when you already have input typed as the schema's `Encoded` type and
|
|
1415
1521
|
* need decoding to return a JavaScript `Promise` that rejects with
|
|
1416
|
-
* `SchemaError
|
|
1522
|
+
* `SchemaError` for schema mismatches.
|
|
1417
1523
|
*
|
|
1418
1524
|
* **Details**
|
|
1419
1525
|
*
|
|
@@ -1421,7 +1527,12 @@ export function decodeUnknownPromise<S extends Decoder<unknown>>(schema: S, opti
|
|
|
1421
1527
|
* Options may be provided either when creating the decoder or when applying it;
|
|
1422
1528
|
* application options override creation options.
|
|
1423
1529
|
*
|
|
1424
|
-
*
|
|
1530
|
+
* **Gotchas**
|
|
1531
|
+
*
|
|
1532
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1533
|
+
* `SchemaError`.
|
|
1534
|
+
*
|
|
1535
|
+
* @see {@link SchemaParser.decodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1425
1536
|
*
|
|
1426
1537
|
* @category decoding
|
|
1427
1538
|
* @since 3.10.0
|
|
@@ -1433,7 +1544,7 @@ export const decodePromise: <S extends Decoder<unknown>>(
|
|
|
1433
1544
|
|
|
1434
1545
|
/**
|
|
1435
1546
|
* Decodes an `unknown` input against a schema synchronously, returning the
|
|
1436
|
-
* decoded value or throwing a {@link SchemaError}.
|
|
1547
|
+
* decoded value or throwing a {@link SchemaError} for schema mismatches.
|
|
1437
1548
|
*
|
|
1438
1549
|
* **When to use**
|
|
1439
1550
|
*
|
|
@@ -1443,10 +1554,15 @@ export const decodePromise: <S extends Decoder<unknown>>(
|
|
|
1443
1554
|
* **Details**
|
|
1444
1555
|
*
|
|
1445
1556
|
* For input already typed as the schema's `Encoded` type use `decodeSync`.
|
|
1446
|
-
* Only service-free schemas can be decoded synchronously. For
|
|
1447
|
-
*
|
|
1448
|
-
* `decodeUnknownEffect`. Options may be provided either
|
|
1449
|
-
* decoder or when applying it; application options override
|
|
1557
|
+
* Only service-free schemas can be decoded synchronously. For alternatives that
|
|
1558
|
+
* do not throw on schema mismatches, see `decodeUnknownOption`,
|
|
1559
|
+
* `decodeUnknownExit`, or `decodeUnknownEffect`. Options may be provided either
|
|
1560
|
+
* when creating the decoder or when applying it; application options override
|
|
1561
|
+
* creation options.
|
|
1562
|
+
*
|
|
1563
|
+
* **Gotchas**
|
|
1564
|
+
*
|
|
1565
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1450
1566
|
*
|
|
1451
1567
|
* **Example** (Decoding with a transformation schema)
|
|
1452
1568
|
*
|
|
@@ -1473,13 +1589,14 @@ export const decodePromise: <S extends Decoder<unknown>>(
|
|
|
1473
1589
|
export function decodeUnknownSync<S extends Decoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1474
1590
|
const parser = decodeUnknownEffect(schema, options)
|
|
1475
1591
|
return (input: unknown, options?: SchemaAST.ParseOptions): S["Type"] => {
|
|
1476
|
-
return
|
|
1592
|
+
return runSchemaErrorSync(parser(input, options))
|
|
1477
1593
|
}
|
|
1478
1594
|
}
|
|
1479
1595
|
|
|
1480
1596
|
/**
|
|
1481
1597
|
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
1482
|
-
* synchronously, returning the decoded value or throwing a {@link SchemaError}
|
|
1598
|
+
* synchronously, returning the decoded value or throwing a {@link SchemaError}
|
|
1599
|
+
* for schema mismatches.
|
|
1483
1600
|
*
|
|
1484
1601
|
* **When to use**
|
|
1485
1602
|
*
|
|
@@ -1493,6 +1610,10 @@ export function decodeUnknownSync<S extends Decoder<unknown>>(schema: S, options
|
|
|
1493
1610
|
* provided either when creating the decoder or when applying it; application
|
|
1494
1611
|
* options override creation options.
|
|
1495
1612
|
*
|
|
1613
|
+
* **Gotchas**
|
|
1614
|
+
*
|
|
1615
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1616
|
+
*
|
|
1496
1617
|
* @see {@link SchemaParser.decodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1497
1618
|
*
|
|
1498
1619
|
* @category decoding
|
|
@@ -1541,7 +1662,7 @@ export function encodeUnknownEffect<S extends Top>(schema: S, options?: SchemaAS
|
|
|
1541
1662
|
input: unknown,
|
|
1542
1663
|
options?: SchemaAST.ParseOptions
|
|
1543
1664
|
): Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]> => {
|
|
1544
|
-
return
|
|
1665
|
+
return InternalSchema.mapSchemaIssueEffect(parser(input, options))
|
|
1545
1666
|
}
|
|
1546
1667
|
}
|
|
1547
1668
|
|
|
@@ -1576,13 +1697,12 @@ export const encodeEffect: <S extends Top>(
|
|
|
1576
1697
|
|
|
1577
1698
|
/**
|
|
1578
1699
|
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
1579
|
-
* `Exit` that is either a `Success` with the encoded value or a `Failure
|
|
1580
|
-
* a {@link SchemaError}.
|
|
1700
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure`.
|
|
1581
1701
|
*
|
|
1582
1702
|
* **When to use**
|
|
1583
1703
|
*
|
|
1584
|
-
* Use when you need to encode unknown input into an `Exit`
|
|
1585
|
-
*
|
|
1704
|
+
* Use when you need to encode unknown input into an `Exit` and capture schema
|
|
1705
|
+
* mismatches as `SchemaError`.
|
|
1586
1706
|
*
|
|
1587
1707
|
* **Details**
|
|
1588
1708
|
*
|
|
@@ -1590,6 +1710,14 @@ export const encodeEffect: <S extends Top>(
|
|
|
1590
1710
|
* {@link encodeExit} when the value is already typed as the schema's `Type`.
|
|
1591
1711
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1592
1712
|
* application options override creation options.
|
|
1713
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1714
|
+
* `SchemaError`.
|
|
1715
|
+
*
|
|
1716
|
+
* **Gotchas**
|
|
1717
|
+
*
|
|
1718
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1719
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1720
|
+
* including when they are mixed with schema issues.
|
|
1593
1721
|
*
|
|
1594
1722
|
* @see {@link SchemaParser.encodeUnknownExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1595
1723
|
*
|
|
@@ -1599,19 +1727,19 @@ export const encodeEffect: <S extends Top>(
|
|
|
1599
1727
|
export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1600
1728
|
const parser = SchemaParser.encodeUnknownExit(schema, options)
|
|
1601
1729
|
return (input: unknown, options?: SchemaAST.ParseOptions): Exit_.Exit<S["Encoded"], SchemaError> => {
|
|
1602
|
-
return
|
|
1730
|
+
return InternalSchema.mapSchemaIssueExit(parser(input, options))
|
|
1603
1731
|
}
|
|
1604
1732
|
}
|
|
1605
1733
|
|
|
1606
1734
|
/**
|
|
1607
1735
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1608
1736
|
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
1609
|
-
* `Failure
|
|
1737
|
+
* `Failure`.
|
|
1610
1738
|
*
|
|
1611
1739
|
* **When to use**
|
|
1612
1740
|
*
|
|
1613
|
-
* Use when you need to encode already typed schema values into an `Exit`
|
|
1614
|
-
*
|
|
1741
|
+
* Use when you need to encode already typed schema values into an `Exit` and
|
|
1742
|
+
* capture schema mismatches as `SchemaError`.
|
|
1615
1743
|
*
|
|
1616
1744
|
* **Details**
|
|
1617
1745
|
*
|
|
@@ -1619,6 +1747,14 @@ export function encodeUnknownExit<S extends Encoder<unknown>>(schema: S, options
|
|
|
1619
1747
|
* `unknown` input use {@link encodeUnknownExit}.
|
|
1620
1748
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1621
1749
|
* application options override creation options.
|
|
1750
|
+
* Schema mismatches are represented by a `Failure` cause containing
|
|
1751
|
+
* `SchemaError`.
|
|
1752
|
+
*
|
|
1753
|
+
* **Gotchas**
|
|
1754
|
+
*
|
|
1755
|
+
* Schema issue fail reasons are wrapped as `SchemaError`. Defects,
|
|
1756
|
+
* interruptions, and other non-schema reasons remain in the returned `Cause`,
|
|
1757
|
+
* including when they are mixed with schema issues.
|
|
1622
1758
|
*
|
|
1623
1759
|
* @see {@link SchemaParser.encodeExit} for the adapter whose failure contains `SchemaIssue.Issue` directly
|
|
1624
1760
|
*
|
|
@@ -1632,7 +1768,7 @@ export const encodeExit: <S extends Encoder<unknown>>(
|
|
|
1632
1768
|
|
|
1633
1769
|
/**
|
|
1634
1770
|
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
1635
|
-
* `Some` with the encoded value on success or `None`
|
|
1771
|
+
* `Some` with the encoded value on success or `None` for schema mismatches.
|
|
1636
1772
|
*
|
|
1637
1773
|
* **When to use**
|
|
1638
1774
|
*
|
|
@@ -1647,6 +1783,12 @@ export const encodeExit: <S extends Encoder<unknown>>(
|
|
|
1647
1783
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1648
1784
|
* application options override creation options.
|
|
1649
1785
|
*
|
|
1786
|
+
* **Gotchas**
|
|
1787
|
+
*
|
|
1788
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1789
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1790
|
+
* instead.
|
|
1791
|
+
*
|
|
1650
1792
|
* @category encoding
|
|
1651
1793
|
* @since 3.10.0
|
|
1652
1794
|
*/
|
|
@@ -1658,8 +1800,8 @@ export const encodeUnknownOption: <S extends Encoder<unknown>>(
|
|
|
1658
1800
|
|
|
1659
1801
|
/**
|
|
1660
1802
|
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1661
|
-
* `Option` that is `Some` with the encoded value on success or `None`
|
|
1662
|
-
*
|
|
1803
|
+
* `Option` that is `Some` with the encoded value on success or `None` for schema
|
|
1804
|
+
* mismatches.
|
|
1663
1805
|
*
|
|
1664
1806
|
* **When to use**
|
|
1665
1807
|
*
|
|
@@ -1672,6 +1814,12 @@ export const encodeUnknownOption: <S extends Encoder<unknown>>(
|
|
|
1672
1814
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1673
1815
|
* application options override creation options.
|
|
1674
1816
|
*
|
|
1817
|
+
* **Gotchas**
|
|
1818
|
+
*
|
|
1819
|
+
* Only causes made entirely of schema issues are converted to `None`. Causes
|
|
1820
|
+
* that contain defects, interruptions, or other non-schema reasons throw
|
|
1821
|
+
* instead.
|
|
1822
|
+
*
|
|
1675
1823
|
* @category encoding
|
|
1676
1824
|
* @since 3.10.0
|
|
1677
1825
|
*/
|
|
@@ -1682,18 +1830,26 @@ export const encodeOption: <S extends Encoder<unknown>>(
|
|
|
1682
1830
|
|
|
1683
1831
|
/**
|
|
1684
1832
|
* Encodes an `unknown` input against a schema, returning a `Result` that
|
|
1685
|
-
* succeeds with the encoded value or fails with a {@link SchemaError}
|
|
1833
|
+
* succeeds with the encoded value or fails with a {@link SchemaError} for schema
|
|
1834
|
+
* mismatches.
|
|
1686
1835
|
*
|
|
1687
1836
|
* **When to use**
|
|
1688
1837
|
*
|
|
1689
|
-
* Use when you do not know the input type statically and want
|
|
1690
|
-
*
|
|
1838
|
+
* Use when you do not know the input type statically and want schema mismatches
|
|
1839
|
+
* returned as `Result.fail` with `SchemaError`.
|
|
1691
1840
|
*
|
|
1692
1841
|
* **Details**
|
|
1693
1842
|
*
|
|
1694
1843
|
* For values already typed as the schema's `Type` use {@link encodeResult}.
|
|
1695
1844
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1696
1845
|
* application options override creation options.
|
|
1846
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1847
|
+
*
|
|
1848
|
+
* **Gotchas**
|
|
1849
|
+
*
|
|
1850
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1851
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1852
|
+
* instead.
|
|
1697
1853
|
*
|
|
1698
1854
|
* @see {@link SchemaParser.encodeUnknownResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1699
1855
|
*
|
|
@@ -1710,18 +1866,25 @@ export function encodeUnknownResult<S extends Encoder<unknown>>(schema: S, optio
|
|
|
1710
1866
|
/**
|
|
1711
1867
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1712
1868
|
* `Result` that succeeds with the encoded value or fails with a
|
|
1713
|
-
* {@link SchemaError}.
|
|
1869
|
+
* {@link SchemaError} for schema mismatches.
|
|
1714
1870
|
*
|
|
1715
1871
|
* **When to use**
|
|
1716
1872
|
*
|
|
1717
|
-
* Use when you already have a value typed as the schema's `Type` and want
|
|
1718
|
-
*
|
|
1873
|
+
* Use when you already have a value typed as the schema's `Type` and want schema
|
|
1874
|
+
* mismatches returned as `Result.fail` with `SchemaError`.
|
|
1719
1875
|
*
|
|
1720
1876
|
* **Details**
|
|
1721
1877
|
*
|
|
1722
1878
|
* For `unknown` input use {@link encodeUnknownResult}.
|
|
1723
1879
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1724
1880
|
* application options override creation options.
|
|
1881
|
+
* Schema mismatches are returned as `Result.fail` with `SchemaError`.
|
|
1882
|
+
*
|
|
1883
|
+
* **Gotchas**
|
|
1884
|
+
*
|
|
1885
|
+
* Only causes made entirely of schema issues are returned as `Result.fail`.
|
|
1886
|
+
* Causes that contain defects, interruptions, or other non-schema reasons throw
|
|
1887
|
+
* instead.
|
|
1725
1888
|
*
|
|
1726
1889
|
* @see {@link SchemaParser.encodeResult} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
1727
1890
|
*
|
|
@@ -1736,12 +1899,13 @@ export const encodeResult: <S extends Encoder<unknown>>(
|
|
|
1736
1899
|
|
|
1737
1900
|
/**
|
|
1738
1901
|
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1739
|
-
* resolves with the encoded value or rejects with a {@link SchemaError}
|
|
1902
|
+
* resolves with the encoded value or rejects with a {@link SchemaError} for
|
|
1903
|
+
* schema mismatches.
|
|
1740
1904
|
*
|
|
1741
1905
|
* **When to use**
|
|
1742
1906
|
*
|
|
1743
1907
|
* Use when you need encoding of unknown input to return a JavaScript `Promise`
|
|
1744
|
-
* that rejects with `SchemaError
|
|
1908
|
+
* that rejects with `SchemaError` for schema mismatches.
|
|
1745
1909
|
*
|
|
1746
1910
|
* **Details**
|
|
1747
1911
|
*
|
|
@@ -1749,7 +1913,12 @@ export const encodeResult: <S extends Encoder<unknown>>(
|
|
|
1749
1913
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1750
1914
|
* application options override creation options.
|
|
1751
1915
|
*
|
|
1752
|
-
*
|
|
1916
|
+
* **Gotchas**
|
|
1917
|
+
*
|
|
1918
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1919
|
+
* `SchemaError`.
|
|
1920
|
+
*
|
|
1921
|
+
* @see {@link SchemaParser.encodeUnknownPromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1753
1922
|
*
|
|
1754
1923
|
* @category encoding
|
|
1755
1924
|
* @since 3.10.0
|
|
@@ -1757,19 +1926,20 @@ export const encodeResult: <S extends Encoder<unknown>>(
|
|
|
1757
1926
|
export function encodeUnknownPromise<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1758
1927
|
const parser = encodeUnknownEffect(schema, options)
|
|
1759
1928
|
return (input: unknown, options?: SchemaAST.ParseOptions): Promise<S["Encoded"]> => {
|
|
1760
|
-
return
|
|
1929
|
+
return runSchemaErrorPromise(parser(input, options))
|
|
1761
1930
|
}
|
|
1762
1931
|
}
|
|
1763
1932
|
|
|
1764
1933
|
/**
|
|
1765
1934
|
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1766
1935
|
* `Promise` that resolves with the encoded value or rejects with a
|
|
1767
|
-
* {@link SchemaError}.
|
|
1936
|
+
* {@link SchemaError} for schema mismatches.
|
|
1768
1937
|
*
|
|
1769
1938
|
* **When to use**
|
|
1770
1939
|
*
|
|
1771
1940
|
* Use when you already have a value typed as the schema's `Type` and need
|
|
1772
|
-
* encoding to return a JavaScript `Promise` that rejects with `SchemaError
|
|
1941
|
+
* encoding to return a JavaScript `Promise` that rejects with `SchemaError` for
|
|
1942
|
+
* schema mismatches.
|
|
1773
1943
|
*
|
|
1774
1944
|
* **Details**
|
|
1775
1945
|
*
|
|
@@ -1777,7 +1947,12 @@ export function encodeUnknownPromise<S extends Encoder<unknown>>(schema: S, opti
|
|
|
1777
1947
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1778
1948
|
* application options override creation options.
|
|
1779
1949
|
*
|
|
1780
|
-
*
|
|
1950
|
+
* **Gotchas**
|
|
1951
|
+
*
|
|
1952
|
+
* Non-schema failures may reject with a runtime failure instead of
|
|
1953
|
+
* `SchemaError`.
|
|
1954
|
+
*
|
|
1955
|
+
* @see {@link SchemaParser.encodePromise} for the adapter that rejects with an `Error` whose cause is `SchemaIssue.Issue`
|
|
1781
1956
|
*
|
|
1782
1957
|
* @category encoding
|
|
1783
1958
|
* @since 3.10.0
|
|
@@ -1789,7 +1964,7 @@ export const encodePromise: <S extends Encoder<unknown>>(
|
|
|
1789
1964
|
|
|
1790
1965
|
/**
|
|
1791
1966
|
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
1792
|
-
* {@link SchemaError}
|
|
1967
|
+
* {@link SchemaError} for schema mismatches.
|
|
1793
1968
|
*
|
|
1794
1969
|
* **When to use**
|
|
1795
1970
|
*
|
|
@@ -1798,11 +1973,15 @@ export const encodePromise: <S extends Encoder<unknown>>(
|
|
|
1798
1973
|
*
|
|
1799
1974
|
* **Details**
|
|
1800
1975
|
*
|
|
1801
|
-
* For
|
|
1802
|
-
* {@link
|
|
1803
|
-
* already typed as the schema's `Type`
|
|
1804
|
-
* Options may be provided either when creating the
|
|
1805
|
-
* application options override creation options.
|
|
1976
|
+
* For alternatives that do not throw on schema mismatches, see
|
|
1977
|
+
* {@link encodeUnknownOption}, {@link encodeUnknownExit}, or
|
|
1978
|
+
* {@link encodeUnknownEffect}. For values already typed as the schema's `Type`
|
|
1979
|
+
* use {@link encodeSync}. Options may be provided either when creating the
|
|
1980
|
+
* encoder or when applying it; application options override creation options.
|
|
1981
|
+
*
|
|
1982
|
+
* **Gotchas**
|
|
1983
|
+
*
|
|
1984
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
1806
1985
|
*
|
|
1807
1986
|
* @see {@link SchemaParser.encodeUnknownSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1808
1987
|
*
|
|
@@ -1812,13 +1991,13 @@ export const encodePromise: <S extends Encoder<unknown>>(
|
|
|
1812
1991
|
export function encodeUnknownSync<S extends Encoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions) {
|
|
1813
1992
|
const parser = encodeUnknownEffect(schema, options)
|
|
1814
1993
|
return (input: unknown, options?: SchemaAST.ParseOptions): S["Encoded"] => {
|
|
1815
|
-
return
|
|
1994
|
+
return runSchemaErrorSync(parser(input, options) as Effect.Effect<S["Encoded"], SchemaError>)
|
|
1816
1995
|
}
|
|
1817
1996
|
}
|
|
1818
1997
|
|
|
1819
1998
|
/**
|
|
1820
1999
|
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1821
|
-
* throwing a {@link SchemaError}
|
|
2000
|
+
* throwing a {@link SchemaError} for schema mismatches.
|
|
1822
2001
|
*
|
|
1823
2002
|
* **When to use**
|
|
1824
2003
|
*
|
|
@@ -1831,6 +2010,10 @@ export function encodeUnknownSync<S extends Encoder<unknown>>(schema: S, options
|
|
|
1831
2010
|
* Options may be provided either when creating the encoder or when applying it;
|
|
1832
2011
|
* application options override creation options.
|
|
1833
2012
|
*
|
|
2013
|
+
* **Gotchas**
|
|
2014
|
+
*
|
|
2015
|
+
* Non-schema failures may throw a runtime failure instead of `SchemaError`.
|
|
2016
|
+
*
|
|
1834
2017
|
* @see {@link SchemaParser.encodeSync} for the adapter that throws an `Error` whose cause is `SchemaIssue.Issue`
|
|
1835
2018
|
*
|
|
1836
2019
|
* @category encoding
|
|
@@ -2002,7 +2185,7 @@ interface optionalLambda extends Lambda {
|
|
|
2002
2185
|
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
2003
2186
|
* only, not `undefined`).
|
|
2004
2187
|
*
|
|
2005
|
-
* **Example** (
|
|
2188
|
+
* **Example** (Defining an optional field accepting undefined)
|
|
2006
2189
|
*
|
|
2007
2190
|
* ```ts
|
|
2008
2191
|
* import { Schema } from "effect"
|
|
@@ -2233,7 +2416,7 @@ function isFlip$(schema: Top): schema is flip<any> {
|
|
|
2233
2416
|
*
|
|
2234
2417
|
* Calling `flip` twice returns the original schema.
|
|
2235
2418
|
*
|
|
2236
|
-
* **Example** (
|
|
2419
|
+
* **Example** (Flipping a number-from-string schema)
|
|
2237
2420
|
*
|
|
2238
2421
|
* ```ts
|
|
2239
2422
|
* import { Schema } from "effect"
|
|
@@ -2270,7 +2453,7 @@ export interface Literal<L extends SchemaAST.LiteralValue>
|
|
|
2270
2453
|
/**
|
|
2271
2454
|
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
2272
2455
|
*
|
|
2273
|
-
* **Example** (
|
|
2456
|
+
* **Example** (Defining a string literal)
|
|
2274
2457
|
*
|
|
2275
2458
|
* ```ts
|
|
2276
2459
|
* import { Schema } from "effect"
|
|
@@ -2394,7 +2577,7 @@ function templateLiteralFromParts<Parts extends TemplateLiteral.Parts>(parts: Pa
|
|
|
2394
2577
|
* Use when the decoded value should remain the matched string and you do not
|
|
2395
2578
|
* need the individual template parts parsed into a tuple.
|
|
2396
2579
|
*
|
|
2397
|
-
* **Example** (URL path pattern)
|
|
2580
|
+
* **Example** (Defining a URL path pattern)
|
|
2398
2581
|
*
|
|
2399
2582
|
* ```ts
|
|
2400
2583
|
* import { Schema } from "effect"
|
|
@@ -2469,7 +2652,7 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
2469
2652
|
* Unlike {@link TemplateLiteral}, this schema decodes the matched string into a
|
|
2470
2653
|
* readonly tuple with one element per schema part.
|
|
2471
2654
|
*
|
|
2472
|
-
* **Example** (
|
|
2655
|
+
* **Example** (Parsing path parameters)
|
|
2473
2656
|
*
|
|
2474
2657
|
* ```ts
|
|
2475
2658
|
* import { Schema } from "effect"
|
|
@@ -2503,7 +2686,7 @@ export interface Enum<A extends { [x: string]: string | number }>
|
|
|
2503
2686
|
/**
|
|
2504
2687
|
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
2505
2688
|
*
|
|
2506
|
-
* **Example** (
|
|
2689
|
+
* **Example** (Defining a direction enum)
|
|
2507
2690
|
*
|
|
2508
2691
|
* ```ts
|
|
2509
2692
|
* import { Schema } from "effect"
|
|
@@ -2768,7 +2951,7 @@ export interface UniqueSymbol<sym extends symbol>
|
|
|
2768
2951
|
/**
|
|
2769
2952
|
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
2770
2953
|
*
|
|
2771
|
-
* **Example** (
|
|
2954
|
+
* **Example** (Defining a specific symbol)
|
|
2772
2955
|
*
|
|
2773
2956
|
* ```ts
|
|
2774
2957
|
* import { Schema } from "effect"
|
|
@@ -3037,7 +3220,7 @@ function makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects,
|
|
|
3037
3220
|
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
3038
3221
|
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
3039
3222
|
*
|
|
3040
|
-
* **Example** (
|
|
3223
|
+
* **Example** (Defining a basic struct)
|
|
3041
3224
|
*
|
|
3042
3225
|
* ```ts
|
|
3043
3226
|
* import { Schema } from "effect"
|
|
@@ -3139,7 +3322,7 @@ const canonicalPropertyKey = (key: PropertyKey): string | symbol =>
|
|
|
3139
3322
|
* If two existing fields would produce the same encoded key, construction
|
|
3140
3323
|
* fails.
|
|
3141
3324
|
*
|
|
3142
|
-
* **Example** (
|
|
3325
|
+
* **Example** (Renaming `name` to `full_name` in the encoded form)
|
|
3143
3326
|
*
|
|
3144
3327
|
* ```ts
|
|
3145
3328
|
* import { Schema } from "effect"
|
|
@@ -3200,7 +3383,7 @@ export function encodeKeys<
|
|
|
3200
3383
|
* computed or enriched fields to live in the decoded type without appearing in
|
|
3201
3384
|
* the encoded form.
|
|
3202
3385
|
*
|
|
3203
|
-
* **Example** (
|
|
3386
|
+
* **Example** (Adding a computed `fullName` field)
|
|
3204
3387
|
*
|
|
3205
3388
|
* ```ts
|
|
3206
3389
|
* import { Option, Schema } from "effect"
|
|
@@ -3406,7 +3589,7 @@ export interface $Record<Key extends Record.Key, Value extends Top> extends
|
|
|
3406
3589
|
/**
|
|
3407
3590
|
* Defines a record (dictionary) schema with typed keys and values.
|
|
3408
3591
|
*
|
|
3409
|
-
* **Example** (
|
|
3592
|
+
* **Example** (Defining a string-keyed record of numbers)
|
|
3410
3593
|
*
|
|
3411
3594
|
* ```ts
|
|
3412
3595
|
* import { Schema } from "effect"
|
|
@@ -3614,7 +3797,7 @@ export interface StructWithRest<
|
|
|
3614
3797
|
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
3615
3798
|
* producing a schema whose decoded type intersects the struct and all records.
|
|
3616
3799
|
*
|
|
3617
|
-
* **Example** (
|
|
3800
|
+
* **Example** (Defining structs with string-indexed extra keys)
|
|
3618
3801
|
*
|
|
3619
3802
|
* ```ts
|
|
3620
3803
|
* import { Schema } from "effect"
|
|
@@ -3834,7 +4017,7 @@ function makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, eleme
|
|
|
3834
4017
|
/**
|
|
3835
4018
|
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
3836
4019
|
*
|
|
3837
|
-
* **Example** (
|
|
4020
|
+
* **Example** (Defining a pair of string and number)
|
|
3838
4021
|
*
|
|
3839
4022
|
* ```ts
|
|
3840
4023
|
* import { Schema } from "effect"
|
|
@@ -4011,7 +4194,7 @@ export interface TupleWithRest<
|
|
|
4011
4194
|
* example, `[Schema.Boolean, Schema.String]` represents zero or more booleans
|
|
4012
4195
|
* followed by a final string.
|
|
4013
4196
|
*
|
|
4014
|
-
* **Example** (
|
|
4197
|
+
* **Example** (Defining tuples with rest elements)
|
|
4015
4198
|
*
|
|
4016
4199
|
* ```ts
|
|
4017
4200
|
* import { Schema } from "effect"
|
|
@@ -4075,7 +4258,7 @@ export {
|
|
|
4075
4258
|
/**
|
|
4076
4259
|
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
4077
4260
|
*
|
|
4078
|
-
* **Example** (
|
|
4261
|
+
* **Example** (Defining an array of strings)
|
|
4079
4262
|
*
|
|
4080
4263
|
* ```ts
|
|
4081
4264
|
* import { Schema } from "effect"
|
|
@@ -4123,7 +4306,7 @@ interface NonEmptyArrayLambda extends Lambda {
|
|
|
4123
4306
|
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
4124
4307
|
* Type is `readonly [T, ...T[]]`.
|
|
4125
4308
|
*
|
|
4126
|
-
* **Example** (
|
|
4309
|
+
* **Example** (Defining a non-empty array of numbers)
|
|
4127
4310
|
*
|
|
4128
4311
|
* ```ts
|
|
4129
4312
|
* import { Schema } from "effect"
|
|
@@ -4251,7 +4434,7 @@ interface mutableLambda extends Lambda {
|
|
|
4251
4434
|
/**
|
|
4252
4435
|
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
4253
4436
|
*
|
|
4254
|
-
* **Example** (
|
|
4437
|
+
* **Example** (Defining mutable arrays)
|
|
4255
4438
|
*
|
|
4256
4439
|
* ```ts
|
|
4257
4440
|
* import { Schema } from "effect"
|
|
@@ -4344,7 +4527,7 @@ function makeUnion<Members extends ReadonlyArray<Top>>(
|
|
|
4344
4527
|
* - `"anyOf"` (default) — matches if any member matches.
|
|
4345
4528
|
* - `"oneOf"` — matches if exactly one member matches.
|
|
4346
4529
|
*
|
|
4347
|
-
* **Example** (
|
|
4530
|
+
* **Example** (Defining a string or number union)
|
|
4348
4531
|
*
|
|
4349
4532
|
* ```ts
|
|
4350
4533
|
* import { Schema } from "effect"
|
|
@@ -4391,7 +4574,7 @@ export interface Literals<L extends ReadonlyArray<SchemaAST.LiteralValue>>
|
|
|
4391
4574
|
/**
|
|
4392
4575
|
* Creates a union schema from an array of literal values.
|
|
4393
4576
|
*
|
|
4394
|
-
* **Example** (
|
|
4577
|
+
* **Example** (Defining status codes)
|
|
4395
4578
|
*
|
|
4396
4579
|
* ```ts
|
|
4397
4580
|
* import { Schema } from "effect"
|
|
@@ -4526,7 +4709,7 @@ export interface suspend<S extends Top> extends
|
|
|
4526
4709
|
* essential for creating recursive schemas where a schema references itself,
|
|
4527
4710
|
* preventing infinite recursion during schema definition.
|
|
4528
4711
|
*
|
|
4529
|
-
* **Example** (
|
|
4712
|
+
* **Example** (Defining recursive tree schemas)
|
|
4530
4713
|
*
|
|
4531
4714
|
* ```ts
|
|
4532
4715
|
* import { Schema } from "effect"
|
|
@@ -4988,7 +5171,7 @@ export interface compose<To extends Top, From extends Top> extends decodeTo<To,
|
|
|
4988
5171
|
* and is used on the encoding path, while `encode` maps `To["Encoded"]` to
|
|
4989
5172
|
* `From["Type"]` and is used on the decoding path.
|
|
4990
5173
|
*
|
|
4991
|
-
* **Example** (
|
|
5174
|
+
* **Example** (Transforming strings to numbers with a schema transformation)
|
|
4992
5175
|
*
|
|
4993
5176
|
* ```ts
|
|
4994
5177
|
* import { Schema, SchemaGetter } from "effect"
|
|
@@ -5105,7 +5288,7 @@ export function decode<S extends Top, RD = never, RE = never>(transformation: {
|
|
|
5105
5288
|
* `encodeTo(to)(from)` is equivalent to `to.pipe(decodeTo(from))`. The `from`
|
|
5106
5289
|
* schema acts as the target decoded schema and `to` acts as the encoded source.
|
|
5107
5290
|
*
|
|
5108
|
-
* **Example** (
|
|
5291
|
+
* **Example** (Encoding a number back to a string)
|
|
5109
5292
|
*
|
|
5110
5293
|
* ```ts
|
|
5111
5294
|
* import { Schema, SchemaGetter } from "effect"
|
|
@@ -5229,7 +5412,7 @@ export interface withConstructorDefault<S extends Top & WithoutConstructorDefaul
|
|
|
5229
5412
|
* Constructor defaults are applied only during `make*`, not during decoding or
|
|
5230
5413
|
* encoding.
|
|
5231
5414
|
*
|
|
5232
|
-
* **Example** (
|
|
5415
|
+
* **Example** (Defining an optional field with a static default)
|
|
5233
5416
|
*
|
|
5234
5417
|
* ```ts
|
|
5235
5418
|
* import { Effect, Schema } from "effect"
|
|
@@ -5254,7 +5437,7 @@ export function withConstructorDefault<S extends Top & WithoutConstructorDefault
|
|
|
5254
5437
|
defaultValue: Effect.Effect<S["~type.make.in"], SchemaError>
|
|
5255
5438
|
) {
|
|
5256
5439
|
return (schema: S): withConstructorDefault<S> =>
|
|
5257
|
-
make(SchemaAST.withConstructorDefault(schema.ast,
|
|
5440
|
+
make(SchemaAST.withConstructorDefault(schema.ast, InternalSchema.mapSchemaErrorEffect(defaultValue)), { schema })
|
|
5258
5441
|
}
|
|
5259
5442
|
|
|
5260
5443
|
/**
|
|
@@ -5299,7 +5482,7 @@ export type DecodingDefaultOptions = {
|
|
|
5299
5482
|
* - `"passthrough"` (default): include the value in the encoded output.
|
|
5300
5483
|
* - `"omit"`: omit the key from the encoded output.
|
|
5301
5484
|
*
|
|
5302
|
-
* **Example** (
|
|
5485
|
+
* **Example** (Providing a default for a missing struct key)
|
|
5303
5486
|
*
|
|
5304
5487
|
* ```ts
|
|
5305
5488
|
* import { Effect, Schema } from "effect"
|
|
@@ -5324,7 +5507,7 @@ export function withDecodingDefaultKey<S extends Top, R = never>(
|
|
|
5324
5507
|
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
|
|
5325
5508
|
return (self: S): withDecodingDefaultKey<S, R> => {
|
|
5326
5509
|
return optionalKey(toEncoded(self)).pipe(decodeTo(self, {
|
|
5327
|
-
decode: SchemaGetter.withDefault(
|
|
5510
|
+
decode: SchemaGetter.withDefault(InternalSchema.mapSchemaErrorEffect(defaultValue)),
|
|
5328
5511
|
encode
|
|
5329
5512
|
}))
|
|
5330
5513
|
}
|
|
@@ -5407,7 +5590,7 @@ export interface withDecodingDefault<S extends Top, R = never> extends decodeTo<
|
|
|
5407
5590
|
* - `"passthrough"` (default): include the value in the encoded output.
|
|
5408
5591
|
* - `"omit"`: omit the key from the encoded output.
|
|
5409
5592
|
*
|
|
5410
|
-
* **Example** (
|
|
5593
|
+
* **Example** (Providing a default for an optional field value)
|
|
5411
5594
|
*
|
|
5412
5595
|
* ```ts
|
|
5413
5596
|
* import { Effect, Schema } from "effect"
|
|
@@ -5432,7 +5615,7 @@ export function withDecodingDefault<S extends Top, R = never>(
|
|
|
5432
5615
|
const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
|
|
5433
5616
|
return (self: S): withDecodingDefault<S, R> => {
|
|
5434
5617
|
return optional(toEncoded(self)).pipe(decodeTo(self, {
|
|
5435
|
-
decode: SchemaGetter.withDefault(
|
|
5618
|
+
decode: SchemaGetter.withDefault(InternalSchema.mapSchemaErrorEffect(defaultValue)),
|
|
5436
5619
|
encode
|
|
5437
5620
|
}))
|
|
5438
5621
|
}
|
|
@@ -5502,7 +5685,7 @@ export interface tag<Tag extends SchemaAST.LiteralValue> extends withConstructor
|
|
|
5502
5685
|
* for discriminator fields in tagged unions. When constructing via `make`, the
|
|
5503
5686
|
* `_tag` field can be omitted and will be filled automatically.
|
|
5504
5687
|
*
|
|
5505
|
-
* **Example** (
|
|
5688
|
+
* **Example** (Defining a discriminated union tag)
|
|
5506
5689
|
*
|
|
5507
5690
|
* ```ts
|
|
5508
5691
|
* import { Schema } from "effect"
|
|
@@ -5536,7 +5719,7 @@ export function tag<Tag extends SchemaAST.LiteralValue>(literal: Tag): tag<Tag>
|
|
|
5536
5719
|
* The tag is filled during decoding and construction, like {@link tag}, but is
|
|
5537
5720
|
* omitted when encoding.
|
|
5538
5721
|
*
|
|
5539
|
-
* **Example** (
|
|
5722
|
+
* **Example** (Omitting tags during encoding)
|
|
5540
5723
|
*
|
|
5541
5724
|
* ```ts
|
|
5542
5725
|
* import { Schema } from "effect"
|
|
@@ -5582,7 +5765,7 @@ export type TaggedStruct<Tag extends SchemaAST.LiteralValue, Fields extends Stru
|
|
|
5582
5765
|
* added automatically. However, when decoding or encoding, the `_tag` field
|
|
5583
5766
|
* must be present in the input.
|
|
5584
5767
|
*
|
|
5585
|
-
* **Example** (
|
|
5768
|
+
* **Example** (Defining a tagged struct shorthand)
|
|
5586
5769
|
*
|
|
5587
5770
|
* ```ts
|
|
5588
5771
|
* import { Schema } from "effect"
|
|
@@ -5781,7 +5964,7 @@ export interface TaggedUnion<Cases extends Record<string, Top>> extends
|
|
|
5781
5964
|
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
5782
5965
|
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
5783
5966
|
*
|
|
5784
|
-
* **Example** (
|
|
5967
|
+
* **Example** (Pattern matching a discriminated union)
|
|
5785
5968
|
*
|
|
5786
5969
|
* ```ts
|
|
5787
5970
|
* import { Schema } from "effect"
|
|
@@ -5848,7 +6031,7 @@ export interface Opaque<Self, S extends Top, Brand> extends
|
|
|
5848
6031
|
* Useful for creating opaque types that are structurally identical to a base struct
|
|
5849
6032
|
* but type-incompatible with it.
|
|
5850
6033
|
*
|
|
5851
|
-
* **Example** (
|
|
6034
|
+
* **Example** (Defining opaque structs)
|
|
5852
6035
|
*
|
|
5853
6036
|
* ```ts
|
|
5854
6037
|
* import { Schema } from "effect"
|
|
@@ -5889,7 +6072,7 @@ export interface instanceOf<T, Iso = T> extends declare<T, Iso> {
|
|
|
5889
6072
|
* Creates a schema that validates values using `instanceof`.
|
|
5890
6073
|
* Decoding and encoding pass the value through unchanged.
|
|
5891
6074
|
*
|
|
5892
|
-
* **Example** (
|
|
6075
|
+
* **Example** (Defining a schema for a built-in class)
|
|
5893
6076
|
*
|
|
5894
6077
|
* ```ts
|
|
5895
6078
|
* import { Schema } from "effect"
|
|
@@ -5947,7 +6130,7 @@ export function link<T>() {
|
|
|
5947
6130
|
* When `abort` is `true`, parsing stops after this filter fails instead of
|
|
5948
6131
|
* collecting later check failures.
|
|
5949
6132
|
*
|
|
5950
|
-
* **Example** (
|
|
6133
|
+
* **Example** (Reporting failure at a nested path)
|
|
5951
6134
|
*
|
|
5952
6135
|
* ```ts
|
|
5953
6136
|
* import { Schema } from "effect"
|
|
@@ -7517,7 +7700,7 @@ export const isBetweenBigDecimal = makeIsBetween({
|
|
|
7517
7700
|
* constraint to ensure generated strings or arrays have at least the required
|
|
7518
7701
|
* length.
|
|
7519
7702
|
*
|
|
7520
|
-
* **Example** (
|
|
7703
|
+
* **Example** (Checking minimum length)
|
|
7521
7704
|
*
|
|
7522
7705
|
* ```ts
|
|
7523
7706
|
* import { Schema } from "effect"
|
|
@@ -9981,7 +10164,7 @@ const DateString = String.annotate({ expected: "a string in ISO 8601 format that
|
|
|
9981
10164
|
* JSON serializer encodes valid dates as ISO 8601 strings; invalid dates encode
|
|
9982
10165
|
* as `"Invalid Date"`.
|
|
9983
10166
|
*
|
|
9984
|
-
* **Example** (Date schema)
|
|
10167
|
+
* **Example** (Defining a Date schema)
|
|
9985
10168
|
*
|
|
9986
10169
|
* ```ts
|
|
9987
10170
|
* import { Schema } from "effect"
|
|
@@ -10099,7 +10282,7 @@ export interface Duration extends declare<Duration_.Duration> {
|
|
|
10099
10282
|
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
10100
10283
|
* duration type and value.
|
|
10101
10284
|
*
|
|
10102
|
-
* **Example** (Duration schema)
|
|
10285
|
+
* **Example** (Defining a Duration schema)
|
|
10103
10286
|
*
|
|
10104
10287
|
* ```ts
|
|
10105
10288
|
* import { Duration, Schema } from "effect"
|
|
@@ -10762,7 +10945,7 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
|
10762
10945
|
* // Success({"a":"1"})
|
|
10763
10946
|
* ```
|
|
10764
10947
|
*
|
|
10765
|
-
* **Example** (
|
|
10948
|
+
* **Example** (Decoding nested fields)
|
|
10766
10949
|
*
|
|
10767
10950
|
* ```ts
|
|
10768
10951
|
* import { Schema } from "effect"
|
|
@@ -10900,7 +11083,7 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
|
|
|
10900
11083
|
* // Success({"a":"1"})
|
|
10901
11084
|
* ```
|
|
10902
11085
|
*
|
|
10903
|
-
* **Example** (
|
|
11086
|
+
* **Example** (Decoding nested fields)
|
|
10904
11087
|
*
|
|
10905
11088
|
* ```ts
|
|
10906
11089
|
* import { Schema } from "effect"
|
|
@@ -12198,7 +12381,7 @@ type MissingSelfGeneric<Usage extends string> =
|
|
|
12198
12381
|
*
|
|
12199
12382
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
12200
12383
|
*
|
|
12201
|
-
* **Example** (
|
|
12384
|
+
* **Example** (Defining a basic class)
|
|
12202
12385
|
*
|
|
12203
12386
|
* ```ts
|
|
12204
12387
|
* import { Schema } from "effect"
|
|
@@ -12258,7 +12441,7 @@ export const Class: {
|
|
|
12258
12441
|
*
|
|
12259
12442
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
12260
12443
|
*
|
|
12261
|
-
* **Example** (
|
|
12444
|
+
* **Example** (Defining a basic class)
|
|
12262
12445
|
*
|
|
12263
12446
|
* ```ts
|
|
12264
12447
|
* import { Schema } from "effect"
|
|
@@ -12318,7 +12501,7 @@ export const Class: {
|
|
|
12318
12501
|
*
|
|
12319
12502
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
12320
12503
|
*
|
|
12321
|
-
* **Example** (
|
|
12504
|
+
* **Example** (Defining a basic class)
|
|
12322
12505
|
*
|
|
12323
12506
|
* ```ts
|
|
12324
12507
|
* import { Schema } from "effect"
|
|
@@ -12381,7 +12564,7 @@ export const Class: {
|
|
|
12381
12564
|
*
|
|
12382
12565
|
* Passing `disableChecks` in the options skips constructor validation.
|
|
12383
12566
|
*
|
|
12384
|
-
* **Example** (
|
|
12567
|
+
* **Example** (Defining a basic class)
|
|
12385
12568
|
*
|
|
12386
12569
|
* ```ts
|
|
12387
12570
|
* import { Schema } from "effect"
|
|
@@ -12455,7 +12638,7 @@ export const Class: {
|
|
|
12455
12638
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
12456
12639
|
* it defaults to the `tag` value.
|
|
12457
12640
|
*
|
|
12458
|
-
* **Example** (
|
|
12641
|
+
* **Example** (Defining a tagged class)
|
|
12459
12642
|
*
|
|
12460
12643
|
* ```ts
|
|
12461
12644
|
* import { Schema } from "effect"
|
|
@@ -12486,7 +12669,7 @@ export const TaggedClass: {
|
|
|
12486
12669
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
12487
12670
|
* it defaults to the `tag` value.
|
|
12488
12671
|
*
|
|
12489
|
-
* **Example** (
|
|
12672
|
+
* **Example** (Defining a tagged class)
|
|
12490
12673
|
*
|
|
12491
12674
|
* ```ts
|
|
12492
12675
|
* import { Schema } from "effect"
|
|
@@ -12517,7 +12700,7 @@ export const TaggedClass: {
|
|
|
12517
12700
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
12518
12701
|
* it defaults to the `tag` value.
|
|
12519
12702
|
*
|
|
12520
|
-
* **Example** (
|
|
12703
|
+
* **Example** (Defining a tagged class)
|
|
12521
12704
|
*
|
|
12522
12705
|
* ```ts
|
|
12523
12706
|
* import { Schema } from "effect"
|
|
@@ -12552,7 +12735,7 @@ export const TaggedClass: {
|
|
|
12552
12735
|
* The optional `identifier` parameter overrides the schema identifier;
|
|
12553
12736
|
* it defaults to the `tag` value.
|
|
12554
12737
|
*
|
|
12555
|
-
* **Example** (
|
|
12738
|
+
* **Example** (Defining a tagged class)
|
|
12556
12739
|
*
|
|
12557
12740
|
* ```ts
|
|
12558
12741
|
* import { Schema } from "effect"
|
|
@@ -12727,7 +12910,7 @@ export const ErrorClass: {
|
|
|
12727
12910
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
12728
12911
|
* and matched as tagged union members.
|
|
12729
12912
|
*
|
|
12730
|
-
* **Example** (
|
|
12913
|
+
* **Example** (Defining a tagged error class)
|
|
12731
12914
|
*
|
|
12732
12915
|
* ```ts
|
|
12733
12916
|
* import { Effect, Schema } from "effect"
|
|
@@ -12754,7 +12937,7 @@ export const TaggedErrorClass: {
|
|
|
12754
12937
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
12755
12938
|
* and matched as tagged union members.
|
|
12756
12939
|
*
|
|
12757
|
-
* **Example** (
|
|
12940
|
+
* **Example** (Defining a tagged error class)
|
|
12758
12941
|
*
|
|
12759
12942
|
* ```ts
|
|
12760
12943
|
* import { Effect, Schema } from "effect"
|
|
@@ -12781,7 +12964,7 @@ export const TaggedErrorClass: {
|
|
|
12781
12964
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
12782
12965
|
* and matched as tagged union members.
|
|
12783
12966
|
*
|
|
12784
|
-
* **Example** (
|
|
12967
|
+
* **Example** (Defining a tagged error class)
|
|
12785
12968
|
*
|
|
12786
12969
|
* ```ts
|
|
12787
12970
|
* import { Effect, Schema } from "effect"
|
|
@@ -12813,7 +12996,7 @@ export const TaggedErrorClass: {
|
|
|
12813
12996
|
* Use to define typed errors that are schema validated, yielded in `Effect.gen`,
|
|
12814
12997
|
* and matched as tagged union members.
|
|
12815
12998
|
*
|
|
12816
|
-
* **Example** (
|
|
12999
|
+
* **Example** (Defining a tagged error class)
|
|
12817
13000
|
*
|
|
12818
13001
|
* ```ts
|
|
12819
13002
|
* import { Effect, Schema } from "effect"
|
|
@@ -13137,7 +13320,7 @@ export function overrideToEquivalence<S extends Top>(toEquivalence: () => Equiva
|
|
|
13137
13320
|
* every field (and nested field) compares equal according to the schema
|
|
13138
13321
|
* structure.
|
|
13139
13322
|
*
|
|
13140
|
-
* **Example** (
|
|
13323
|
+
* **Example** (Comparing structs)
|
|
13141
13324
|
*
|
|
13142
13325
|
* ```ts
|
|
13143
13326
|
* import { Schema } from "effect"
|