effect 4.0.0-beta.30 → 4.0.0-beta.31
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/Channel.d.ts +2 -2
- package/dist/Channel.d.ts.map +1 -1
- package/dist/Channel.js.map +1 -1
- package/dist/Cron.js +3 -3
- package/dist/Cron.js.map +1 -1
- package/dist/DateTime.d.ts +33 -77
- package/dist/DateTime.d.ts.map +1 -1
- package/dist/DateTime.js +1 -1
- package/dist/DateTime.js.map +1 -1
- package/dist/Duration.d.ts +29 -1
- package/dist/Duration.d.ts.map +1 -1
- package/dist/Duration.js +77 -48
- package/dist/Duration.js.map +1 -1
- package/dist/Layer.d.ts +97 -2
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +8 -2
- package/dist/Layer.js.map +1 -1
- package/dist/Schema.d.ts +2316 -114
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +1331 -67
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts +2 -2
- package/dist/SchemaAST.js +2 -2
- package/dist/SchemaRepresentation.d.ts +2 -2
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/internal/dateTime.js +57 -50
- package/dist/internal/dateTime.js.map +1 -1
- package/dist/internal/effect.js +1 -1
- package/dist/internal/effect.js.map +1 -1
- package/dist/unstable/ai/Chat.d.ts +3 -4
- package/dist/unstable/ai/Chat.d.ts.map +1 -1
- package/dist/unstable/ai/Chat.js.map +1 -1
- package/dist/unstable/ai/LanguageModel.d.ts +30 -16
- package/dist/unstable/ai/LanguageModel.d.ts.map +1 -1
- package/dist/unstable/ai/LanguageModel.js +10 -87
- package/dist/unstable/ai/LanguageModel.js.map +1 -1
- package/dist/unstable/cli/Completions.d.ts +16 -0
- package/dist/unstable/cli/Completions.d.ts.map +1 -0
- package/dist/unstable/cli/Completions.js +23 -0
- package/dist/unstable/cli/Completions.js.map +1 -0
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +4 -4
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js +1 -1
- package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
- package/dist/unstable/cluster/DeliverAt.js +1 -1
- package/dist/unstable/cluster/DeliverAt.js.map +1 -1
- package/dist/unstable/encoding/Ndjson.d.ts +8 -8
- package/dist/unstable/encoding/Ndjson.d.ts.map +1 -1
- package/dist/unstable/encoding/Ndjson.js.map +1 -1
- package/dist/unstable/http/HttpClientResponse.js.map +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts +1 -1
- package/dist/unstable/http/HttpIncomingMessage.d.ts.map +1 -1
- package/dist/unstable/http/HttpServerRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/persistence/Persistable.js +1 -1
- package/dist/unstable/persistence/Persistable.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +1 -3
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Channel.ts +3 -3
- package/src/Cron.ts +3 -3
- package/src/DateTime.ts +35 -77
- package/src/Duration.ts +78 -23
- package/src/Layer.ts +123 -19
- package/src/Schema.ts +2317 -115
- package/src/SchemaAST.ts +2 -2
- package/src/SchemaRepresentation.ts +2 -2
- package/src/internal/dateTime.ts +60 -51
- package/src/internal/effect.ts +1 -1
- package/src/unstable/ai/Chat.ts +11 -13
- package/src/unstable/ai/LanguageModel.ts +148 -97
- package/src/unstable/cli/Completions.ts +36 -0
- package/src/unstable/cli/GlobalFlag.ts +4 -5
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cluster/ClusterWorkflowEngine.ts +1 -1
- package/src/unstable/cluster/DeliverAt.ts +1 -1
- package/src/unstable/encoding/Ndjson.ts +17 -17
- package/src/unstable/http/HttpClientResponse.ts +2 -2
- package/src/unstable/http/HttpIncomingMessage.ts +1 -1
- package/src/unstable/http/HttpServerRequest.ts +4 -4
- package/src/unstable/http/HttpServerResponse.ts +2 -2
- package/src/unstable/httpapi/HttpApiBuilder.ts +4 -4
- package/src/unstable/persistence/Persistable.ts +1 -1
- package/src/unstable/rpc/RpcGroup.ts +3 -3
- package/dist/unstable/cli/internal/completions/Completions.d.ts +0 -2
- package/dist/unstable/cli/internal/completions/Completions.d.ts.map +0 -1
- package/dist/unstable/cli/internal/completions/Completions.js +0 -23
- package/dist/unstable/cli/internal/completions/Completions.js.map +0 -1
- package/src/unstable/cli/internal/completions/Completions.ts +0 -31
package/dist/Schema.d.ts
CHANGED
|
@@ -1,4 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Define data shapes, validate unknown input, and transform values between formats.
|
|
3
|
+
*
|
|
4
|
+
* ## Mental model
|
|
5
|
+
*
|
|
6
|
+
* - **Schema** — a description of a data shape. Every schema carries a decoded
|
|
7
|
+
* *Type* (the value you work with) and an *Encoded* representation (the
|
|
8
|
+
* serialized form, e.g. JSON).
|
|
9
|
+
* - **Decoding** — turning unknown external data (API responses, form
|
|
10
|
+
* submissions, config files) into typed, validated values.
|
|
11
|
+
* - **Encoding** — turning typed values back into a serializable format.
|
|
12
|
+
* - **Codec** — a schema that tracks both Type and Encoded, so it can decode
|
|
13
|
+
* *and* encode. Most concrete schemas are Codecs.
|
|
14
|
+
* - **Check / Filter** — a constraint attached to a schema (e.g. `isMinLength`,
|
|
15
|
+
* `isGreaterThan`). Attach them with `.check(...)`.
|
|
16
|
+
* - **Transformation** — a pair of functions (decode + encode) that convert
|
|
17
|
+
* values between two schemas. Created with {@link decodeTo} / {@link encodeTo}.
|
|
18
|
+
* - **Annotation** — metadata attached to a schema (title, description, custom
|
|
19
|
+
* keys). Attach with `.annotate(...)`.
|
|
20
|
+
*
|
|
21
|
+
* ## Common tasks
|
|
22
|
+
*
|
|
23
|
+
* - Define a struct: {@link Struct}
|
|
24
|
+
* - Define a union: {@link Union}, {@link TaggedUnion}, {@link Literals}
|
|
25
|
+
* - Define an array: {@link Array}, {@link NonEmptyArray}
|
|
26
|
+
* - Define a record: {@link Record}
|
|
27
|
+
* - Define a tuple: {@link Tuple}, {@link TupleWithRest}
|
|
28
|
+
* - Validate unknown data synchronously: {@link decodeUnknownSync}
|
|
29
|
+
* - Validate unknown data (Effect): {@link decodeUnknownEffect}
|
|
30
|
+
* - Encode a value: {@link encodeUnknownSync}, {@link encodeUnknownEffect}
|
|
31
|
+
* - Type guard: {@link is}
|
|
32
|
+
* - Assertion: {@link asserts}
|
|
33
|
+
* - Add constraints: `.check(...)` with filters like {@link isMinLength},
|
|
34
|
+
* {@link isGreaterThan}, {@link isPattern}, {@link isUUID}
|
|
35
|
+
* - Transform between schemas: {@link decodeTo}, {@link encodeTo}
|
|
36
|
+
* - Add a default for missing keys: {@link withDecodingDefault}, {@link withDecodingDefaultKey}
|
|
37
|
+
* - Create branded types: {@link brand}
|
|
38
|
+
* - Define classes with validation: {@link Class}, {@link TaggedClass}
|
|
39
|
+
* - Define error classes: {@link ErrorClass}, {@link TaggedErrorClass}
|
|
40
|
+
* - Generate JSON Schema: {@link toJsonSchemaDocument}
|
|
41
|
+
* - Generate test data: {@link toArbitrary}
|
|
42
|
+
* - Derive equivalence: {@link toEquivalence}
|
|
43
|
+
*
|
|
44
|
+
* ## Gotchas
|
|
45
|
+
*
|
|
46
|
+
* - `Schema.optional` creates `T | undefined` (key can be missing *or*
|
|
47
|
+
* `undefined`). Use `Schema.optionalKey` for exact optional properties.
|
|
48
|
+
* - `decodeTo` is curried: use `from.pipe(Schema.decodeTo(to, ...))`.
|
|
49
|
+
* - `decodeUnknownSync` throws on failure. Use `decodeUnknownExit` or
|
|
50
|
+
* `decodeUnknownOption` for non-throwing alternatives.
|
|
51
|
+
* - Filters do not change the TypeScript type. Use {@link refine} or
|
|
52
|
+
* {@link brand} to narrow the type.
|
|
53
|
+
* - Recursive schemas require {@link suspend} to avoid infinite loops.
|
|
54
|
+
*
|
|
55
|
+
* ## Quickstart
|
|
56
|
+
*
|
|
57
|
+
* **Example** (Validate a user object)
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { Schema } from "effect"
|
|
61
|
+
*
|
|
62
|
+
* const User = Schema.Struct({
|
|
63
|
+
* name: Schema.String.check(Schema.isMinLength(1)),
|
|
64
|
+
* age: Schema.Number.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
65
|
+
* email: Schema.optionalKey(Schema.String)
|
|
66
|
+
* })
|
|
67
|
+
*
|
|
68
|
+
* // Decode unknown input — throws on failure
|
|
69
|
+
* const user = Schema.decodeUnknownSync(User)({
|
|
70
|
+
* name: "Alice",
|
|
71
|
+
* age: 30
|
|
72
|
+
* })
|
|
73
|
+
*
|
|
74
|
+
* console.log(user)
|
|
75
|
+
* // { name: "Alice", age: 30 }
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link Schema} — type-level view tracking only the decoded Type
|
|
79
|
+
* @see {@link Codec} — type-level view tracking both Type and Encoded
|
|
80
|
+
* @see {@link Struct} — define object shapes
|
|
81
|
+
* @see {@link decodeUnknownSync} — synchronous validation
|
|
82
|
+
* @see {@link decodeTo} — schema transformations
|
|
83
|
+
*
|
|
2
84
|
* @since 4.0.0
|
|
3
85
|
*/
|
|
4
86
|
/** @effect-diagnostics schemaStructWithTag:skip-file */
|
|
@@ -37,26 +119,39 @@ import type { UnionToIntersection } from "./Types.ts";
|
|
|
37
119
|
import type { Unify } from "./Unify.ts";
|
|
38
120
|
declare const TypeId = "~effect/Schema/Schema";
|
|
39
121
|
/**
|
|
40
|
-
*
|
|
122
|
+
* Whether a schema field is required or optional within a struct.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link optionalKey} — mark a struct field as optional
|
|
125
|
+
* @see {@link optional} — mark a struct field as optional with `| undefined`
|
|
41
126
|
*
|
|
42
127
|
* @since 4.0.0
|
|
43
128
|
*/
|
|
44
129
|
export type Optionality = "required" | "optional";
|
|
45
130
|
/**
|
|
46
|
-
*
|
|
131
|
+
* Whether a schema field is readonly or mutable within a struct.
|
|
132
|
+
*
|
|
133
|
+
* @see {@link mutableKey} — mark a struct field as mutable
|
|
47
134
|
*
|
|
48
135
|
* @since 4.0.0
|
|
49
136
|
*/
|
|
50
137
|
export type Mutability = "readonly" | "mutable";
|
|
51
138
|
/**
|
|
52
|
-
*
|
|
139
|
+
* Whether a schema field has a constructor default value.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link withConstructorDefault} — add a default to a schema field
|
|
142
|
+
* @see {@link tag} — creates a literal field with a constructor default
|
|
53
143
|
*
|
|
54
144
|
* @since 4.0.0
|
|
55
145
|
*/
|
|
56
146
|
export type ConstructorDefault = "no-default" | "with-default";
|
|
57
147
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
148
|
+
* Options for `makeUnsafe` and Class constructors.
|
|
149
|
+
*
|
|
150
|
+
* When to use:
|
|
151
|
+
* - Pass `disableValidation: true` to skip validation when you trust the data.
|
|
152
|
+
* - Pass `parseOptions` to control error reporting behavior.
|
|
153
|
+
*
|
|
154
|
+
* @see {@link Bottom.makeUnsafe}
|
|
60
155
|
*
|
|
61
156
|
* @since 4.0.0
|
|
62
157
|
*/
|
|
@@ -71,15 +166,19 @@ export interface MakeOptions {
|
|
|
71
166
|
readonly disableValidation?: boolean | undefined;
|
|
72
167
|
}
|
|
73
168
|
/**
|
|
74
|
-
* The base interface for all schemas
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
169
|
+
* The fully-parameterized base interface for all schemas. Exposes all 14 type
|
|
170
|
+
* parameters controlling type inference, mutability, optionality, services,
|
|
171
|
+
* and transformation behavior.
|
|
172
|
+
*
|
|
173
|
+
* When to use:
|
|
174
|
+
* - You are writing advanced generic schema utilities or performing schema
|
|
175
|
+
* introspection.
|
|
176
|
+
* - In user code, prefer {@link Schema}, {@link Codec}, {@link Decoder}, or
|
|
177
|
+
* {@link Encoder} instead.
|
|
78
178
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* transformation characteristics.
|
|
179
|
+
* @see {@link Top} — the existential "any schema" type (erased type params)
|
|
180
|
+
* @see {@link Schema} — tracks only the decoded Type
|
|
181
|
+
* @see {@link Codec} — tracks Type + Encoded
|
|
83
182
|
*
|
|
84
183
|
* @since 4.0.0
|
|
85
184
|
*/
|
|
@@ -112,69 +211,199 @@ export interface Bottom<out T, out E, out RD, out RE, out Ast extends AST.AST, o
|
|
|
112
211
|
makeOption(input: this["~type.make.in"], options?: MakeOptions): Option_.Option<this["Type"]>;
|
|
113
212
|
}
|
|
114
213
|
/**
|
|
214
|
+
* The schema type returned by {@link declareConstructor}, tracking the decoded
|
|
215
|
+
* type `T`, the encoded type `E`, and the list of type-parameter schemas
|
|
216
|
+
* `TypeParameters`.
|
|
217
|
+
*
|
|
218
|
+
* @category Constructors
|
|
115
219
|
* @since 4.0.0
|
|
116
220
|
*/
|
|
117
221
|
export interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Top>, Iso = T> extends Bottom<T, E, TypeParameters[number]["DecodingServices"], TypeParameters[number]["EncodingServices"], AST.Declaration, declareConstructor<T, E, TypeParameters, Iso>, T, Iso, TypeParameters> {
|
|
118
222
|
readonly "~rebuild.out": this;
|
|
119
223
|
}
|
|
120
224
|
/**
|
|
121
|
-
*
|
|
225
|
+
* Creates a schema for a **parametric** type (a generic container such as
|
|
226
|
+
* `Array<A>`, `Option<A>`, etc.) by accepting a list of type-parameter schemas
|
|
227
|
+
* and a decoder factory.
|
|
228
|
+
*
|
|
229
|
+
* The outer call `declareConstructor<T, E, Iso>()` fixes the decoded type `T`,
|
|
230
|
+
* the encoded type `E`, and the optional iso type. The inner call receives:
|
|
231
|
+
* - `typeParameters` — the concrete schemas for each type variable
|
|
232
|
+
* - `run` — a factory that, given resolved codecs for each type parameter,
|
|
233
|
+
* returns a parsing function `(u, ast, options) => Effect<T, Issue>`
|
|
234
|
+
* - `annotations` — optional metadata
|
|
235
|
+
*
|
|
236
|
+
* @see {@link declare} for creating schemas for non-parametric types.
|
|
237
|
+
*
|
|
238
|
+
* **Example** (Schema for a parametric `Box<A>` type)
|
|
239
|
+
*
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { Effect, Schema } from "effect"
|
|
242
|
+
* import * as SchemaParser from "effect/SchemaParser"
|
|
243
|
+
* import * as Issue from "effect/SchemaIssue"
|
|
244
|
+
* import * as Option from "effect/Option"
|
|
122
245
|
*
|
|
123
|
-
*
|
|
246
|
+
* interface Box<A> {
|
|
247
|
+
* readonly value: A
|
|
248
|
+
* }
|
|
249
|
+
*
|
|
250
|
+
* const isBox = (u: unknown): u is Box<unknown> =>
|
|
251
|
+
* typeof u === "object" && u !== null && "value" in u
|
|
252
|
+
*
|
|
253
|
+
* const Box = <A extends Schema.Top>(item: A) =>
|
|
254
|
+
* Schema.declareConstructor<Box<A["Type"]>, Box<A["Encoded"]>>()(
|
|
255
|
+
* [item],
|
|
256
|
+
* ([itemCodec]) =>
|
|
257
|
+
* (u, ast, options) => {
|
|
258
|
+
* if (!isBox(u)) {
|
|
259
|
+
* return Effect.fail(new Issue.InvalidType(ast, Option.some(u)))
|
|
260
|
+
* }
|
|
261
|
+
* return Effect.map(
|
|
262
|
+
* SchemaParser.decodeUnknownEffect(itemCodec)(u.value, options),
|
|
263
|
+
* (value) => ({ value })
|
|
264
|
+
* )
|
|
265
|
+
* }
|
|
266
|
+
* )
|
|
267
|
+
*
|
|
268
|
+
* const schema = Box(Schema.Number)
|
|
269
|
+
* ```
|
|
124
270
|
*
|
|
125
271
|
* @category Constructors
|
|
126
272
|
* @since 4.0.0
|
|
127
273
|
*/
|
|
128
274
|
export declare function declareConstructor<T, E = T, Iso = T>(): <const TypeParameters extends ReadonlyArray<Top>>(typeParameters: TypeParameters, run: (typeParameters: { readonly [K in keyof TypeParameters]: Codec<TypeParameters[K]["Type"], TypeParameters[K]["Encoded"]>; }) => (u: unknown, self: AST.Declaration, options: AST.ParseOptions) => Effect.Effect<T, Issue.Issue>, annotations?: Annotations.Declaration<T, TypeParameters>) => declareConstructor<T, E, TypeParameters, Iso>;
|
|
129
275
|
/**
|
|
276
|
+
* The schema type returned by {@link declare}, representing a non-parametric
|
|
277
|
+
* opaque type `T` with no type parameters.
|
|
278
|
+
*
|
|
130
279
|
* @category Constructors
|
|
131
280
|
* @since 4.0.0
|
|
132
281
|
*/
|
|
133
282
|
export interface declare<T, Iso = T> extends declareConstructor<T, T, readonly [], Iso> {
|
|
134
283
|
}
|
|
135
284
|
/**
|
|
136
|
-
*
|
|
285
|
+
* Creates a schema for a **non-parametric** opaque type using a type-guard
|
|
286
|
+
* function. The schema accepts any unknown value and succeeds when `is` returns
|
|
287
|
+
* `true`, failing with an `InvalidType` issue otherwise.
|
|
288
|
+
*
|
|
289
|
+
* Use this when the type has no type parameters. For parametric types such as
|
|
290
|
+
* `Option<A>` or `Array<A>`, use {@link declareConstructor} instead.
|
|
291
|
+
*
|
|
292
|
+
* **Example** (Schema for a custom `UserId` branded type)
|
|
293
|
+
*
|
|
294
|
+
* ```ts
|
|
295
|
+
* import { Schema } from "effect"
|
|
296
|
+
*
|
|
297
|
+
* type UserId = string & { readonly _tag: "UserId" }
|
|
298
|
+
*
|
|
299
|
+
* const isUserId = (u: unknown): u is UserId =>
|
|
300
|
+
* typeof u === "string" && u.startsWith("user_")
|
|
301
|
+
*
|
|
302
|
+
* const UserId = Schema.declare<UserId>(isUserId, {
|
|
303
|
+
* title: "UserId",
|
|
304
|
+
* description: "A user identifier starting with 'user_'"
|
|
305
|
+
* })
|
|
306
|
+
* ```
|
|
137
307
|
*
|
|
138
308
|
* @see {@link declareConstructor} for creating schemas for parametric types.
|
|
139
309
|
*
|
|
310
|
+
* @category Constructors
|
|
140
311
|
* @since 4.0.0
|
|
141
312
|
*/
|
|
142
313
|
export declare function declare<T, Iso = T>(is: (u: unknown) => u is T, annotations?: Annotations.Declaration<T> | undefined): declare<T, Iso>;
|
|
143
314
|
/**
|
|
144
|
-
*
|
|
145
|
-
* parameters.
|
|
315
|
+
* Widens a schema's type to the fully-parameterized {@link Bottom} interface,
|
|
316
|
+
* making all 14 type parameters visible to TypeScript.
|
|
317
|
+
*
|
|
318
|
+
* Normally, concrete schema interfaces (e.g. `Schema<string>`) hide most type
|
|
319
|
+
* parameters. `revealBottom` is useful when writing generic utilities that need
|
|
320
|
+
* to inspect or propagate the complete set of type parameters.
|
|
321
|
+
*
|
|
322
|
+
* **Example** (Inspecting all type parameters of a schema)
|
|
323
|
+
*
|
|
324
|
+
* ```ts
|
|
325
|
+
* import { Schema } from "effect"
|
|
326
|
+
*
|
|
327
|
+
* const schema = Schema.String
|
|
328
|
+
*
|
|
329
|
+
* // Widen to Bottom to access all 14 type parameters
|
|
330
|
+
* const bottom = Schema.revealBottom(schema)
|
|
331
|
+
*
|
|
332
|
+
* // `bottom` now exposes Type, Encoded, DecodingServices, EncodingServices,
|
|
333
|
+
* // ast, ~rebuild.out, ~type.make.in, Iso, ~type.parameters, etc.
|
|
334
|
+
* type T = typeof bottom["Type"] // string
|
|
335
|
+
* type E = typeof bottom["Encoded"] // string
|
|
336
|
+
* ```
|
|
146
337
|
*
|
|
147
338
|
* @since 4.0.0
|
|
148
339
|
*/
|
|
149
340
|
export declare function revealBottom<S extends Top>(bottom: S): Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], S["~rebuild.out"], S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]>;
|
|
150
341
|
/**
|
|
151
342
|
* Adds metadata annotations to a schema without changing its runtime behavior.
|
|
152
|
-
*
|
|
153
|
-
*
|
|
343
|
+
* This is the pipeable (curried) counterpart of the `.annotate` method.
|
|
344
|
+
*
|
|
345
|
+
* Annotations provide extra context used by documentation generators, JSON
|
|
346
|
+
* Schema converters, error formatters, and other tooling. Common keys include
|
|
347
|
+
* `title`, `description`, `examples`, `message`, and `identifier`.
|
|
348
|
+
*
|
|
349
|
+
* **Example** (Adding a title and description)
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { Schema } from "effect"
|
|
353
|
+
*
|
|
354
|
+
* const Age = Schema.Number.pipe(
|
|
355
|
+
* Schema.annotate({
|
|
356
|
+
* title: "Age",
|
|
357
|
+
* description: "A non-negative integer representing age in years"
|
|
358
|
+
* })
|
|
359
|
+
* )
|
|
360
|
+
* ```
|
|
154
361
|
*
|
|
155
362
|
* @category Annotations
|
|
156
363
|
* @since 4.0.0
|
|
157
364
|
*/
|
|
158
365
|
export declare function annotate<S extends Top>(annotations: S["~annotate.in"]): (self: S) => S["~rebuild.out"];
|
|
159
366
|
/**
|
|
160
|
-
* Adds key-
|
|
161
|
-
*
|
|
162
|
-
*
|
|
367
|
+
* Adds key-level annotations to a schema field. This is the pipeable
|
|
368
|
+
* (curried) counterpart of the `.annotateKey` method.
|
|
369
|
+
*
|
|
370
|
+
* Key annotations apply to a field's position inside a `Struct` or `Tuple`
|
|
371
|
+
* rather than to the field's value type. They can carry a
|
|
372
|
+
* `messageMissingKey` to customise the error shown when the field is absent,
|
|
373
|
+
* as well as standard documentation fields such as `title`, `description`,
|
|
374
|
+
* and `examples`.
|
|
375
|
+
*
|
|
376
|
+
* **Example** (Custom missing-key message for a required field)
|
|
377
|
+
*
|
|
378
|
+
* ```ts
|
|
379
|
+
* import { Schema } from "effect"
|
|
380
|
+
*
|
|
381
|
+
* const schema = Schema.Struct({
|
|
382
|
+
* username: Schema.String.pipe(
|
|
383
|
+
* Schema.annotateKey({
|
|
384
|
+
* description: "The username used to log in",
|
|
385
|
+
* messageMissingKey: "Username is required"
|
|
386
|
+
* })
|
|
387
|
+
* )
|
|
388
|
+
* })
|
|
389
|
+
* ```
|
|
163
390
|
*
|
|
164
391
|
* @category Annotations
|
|
165
392
|
* @since 4.0.0
|
|
166
393
|
*/
|
|
167
394
|
export declare function annotateKey<S extends Top>(annotations: Annotations.Key<S["Type"]>): (self: S) => S["~rebuild.out"];
|
|
168
395
|
/**
|
|
169
|
-
* The
|
|
396
|
+
* The existential "any schema" type — all type parameters are erased to `unknown`.
|
|
170
397
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
398
|
+
* Use `Top` as a constraint when writing generic utilities that must accept *any*
|
|
399
|
+
* schema regardless of its `Type`, `Encoded`, or service requirements. It is the
|
|
400
|
+
* widest possible schema type and therefore gives you the least static information.
|
|
174
401
|
*
|
|
175
|
-
*
|
|
176
|
-
* -
|
|
177
|
-
* -
|
|
402
|
+
* In user code prefer the narrower interfaces:
|
|
403
|
+
* - {@link Schema}`<T>` — when you only care about the decoded type
|
|
404
|
+
* - {@link Codec}`<T, E, RD, RE>` — when you need the encoded type and service requirements
|
|
405
|
+
* - {@link Decoder}`<T, RD>` — for decode-only APIs
|
|
406
|
+
* - {@link Encoder}`<E, RE>` — for encode-only APIs
|
|
178
407
|
*
|
|
179
408
|
* @since 4.0.0
|
|
180
409
|
*/
|
|
@@ -182,24 +411,52 @@ export interface Top extends Bottom<unknown, unknown, unknown, unknown, AST.AST,
|
|
|
182
411
|
unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality> {
|
|
183
412
|
}
|
|
184
413
|
/**
|
|
414
|
+
* Namespace of type-level helpers for {@link Schema}.
|
|
415
|
+
*
|
|
185
416
|
* @since 4.0.0
|
|
186
417
|
*/
|
|
187
418
|
export declare namespace Schema {
|
|
188
419
|
/**
|
|
420
|
+
* Extracts the decoded `Type` from a schema.
|
|
421
|
+
*
|
|
422
|
+
* **Example** (Extracting the decoded type)
|
|
423
|
+
*
|
|
424
|
+
* ```ts
|
|
425
|
+
* import { Schema } from "effect"
|
|
426
|
+
*
|
|
427
|
+
* const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
428
|
+
* type Person = Schema.Schema.Type<typeof Person>
|
|
429
|
+
* // { readonly name: string; readonly age: number }
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
189
432
|
* @since 4.0.0
|
|
190
433
|
*/
|
|
191
434
|
type Type<S> = S extends Top ? S["Type"] : never;
|
|
192
435
|
}
|
|
193
436
|
/**
|
|
194
|
-
* A typed view of a schema that tracks the decoded (output) type `T`.
|
|
437
|
+
* A typed view of a schema that tracks only the decoded (output) type `T`.
|
|
195
438
|
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
439
|
+
* Use `Schema<T>` as a constraint when you want to accept "any schema that
|
|
440
|
+
* decodes to `T`" and do not need to know or constrain the encoded
|
|
441
|
+
* representation, required services, or any other type parameters.
|
|
199
442
|
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
443
|
+
* This is a structural interface — concrete schema values are produced by the
|
|
444
|
+
* constructors in this module (e.g. {@link Struct}, {@link String}, {@link Number}).
|
|
445
|
+
* When you also need the encoded type or service requirements, use {@link Codec}.
|
|
446
|
+
*
|
|
447
|
+
* **Example** (Function that accepts any schema decoding to `string`)
|
|
448
|
+
*
|
|
449
|
+
* ```ts
|
|
450
|
+
* import { Schema } from "effect"
|
|
451
|
+
*
|
|
452
|
+
* declare function print(schema: Schema.Schema<string>): void
|
|
453
|
+
*
|
|
454
|
+
* print(Schema.String) // ok
|
|
455
|
+
* print(Schema.NonEmptyString) // ok
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* @see {@link Codec} — also tracks Encoded, DecodingServices, EncodingServices
|
|
459
|
+
* @see {@link Schema.Type} — extract the decoded type at the type level
|
|
203
460
|
*
|
|
204
461
|
* @since 4.0.0
|
|
205
462
|
*/
|
|
@@ -208,22 +465,66 @@ export interface Schema<out T> extends Top {
|
|
|
208
465
|
readonly "~rebuild.out": Schema<T>;
|
|
209
466
|
}
|
|
210
467
|
/**
|
|
468
|
+
* Namespace of type-level helpers for {@link Codec}.
|
|
469
|
+
*
|
|
211
470
|
* @since 4.0.0
|
|
212
471
|
*/
|
|
213
472
|
export declare namespace Codec {
|
|
214
473
|
/**
|
|
474
|
+
* Extracts the encoded (`Encoded`) type from a schema.
|
|
475
|
+
*
|
|
476
|
+
* **Example** (Extracting the encoded type)
|
|
477
|
+
*
|
|
478
|
+
* ```ts
|
|
479
|
+
* import { Schema } from "effect"
|
|
480
|
+
*
|
|
481
|
+
* const schema = Schema.NumberFromString
|
|
482
|
+
* type Enc = Schema.Codec.Encoded<typeof schema>
|
|
483
|
+
* // string
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
215
486
|
* @since 4.0.0
|
|
216
487
|
*/
|
|
217
488
|
type Encoded<S> = S extends Top ? S["Encoded"] : never;
|
|
218
489
|
/**
|
|
490
|
+
* Extracts the Effect services required during *decoding* from a schema.
|
|
491
|
+
*
|
|
492
|
+
* **Example** (Checking decoding service requirements)
|
|
493
|
+
*
|
|
494
|
+
* ```ts
|
|
495
|
+
* import { Schema } from "effect"
|
|
496
|
+
*
|
|
497
|
+
* const schema = Schema.String
|
|
498
|
+
* type RD = Schema.Codec.DecodingServices<typeof schema>
|
|
499
|
+
* // never
|
|
500
|
+
* ```
|
|
501
|
+
*
|
|
219
502
|
* @since 4.0.0
|
|
220
503
|
*/
|
|
221
504
|
type DecodingServices<S> = S extends Top ? S["DecodingServices"] : never;
|
|
222
505
|
/**
|
|
506
|
+
* Extracts the Effect services required during *encoding* from a schema.
|
|
507
|
+
*
|
|
508
|
+
* **Example** (Checking encoding service requirements)
|
|
509
|
+
*
|
|
510
|
+
* ```ts
|
|
511
|
+
* import { Schema } from "effect"
|
|
512
|
+
*
|
|
513
|
+
* const schema = Schema.String
|
|
514
|
+
* type RE = Schema.Codec.EncodingServices<typeof schema>
|
|
515
|
+
* // never
|
|
516
|
+
* ```
|
|
517
|
+
*
|
|
223
518
|
* @since 4.0.0
|
|
224
519
|
*/
|
|
225
520
|
type EncodingServices<S> = S extends Top ? S["EncodingServices"] : never;
|
|
226
521
|
/**
|
|
522
|
+
* Converts a schema type into an assertion function signature. The resulting
|
|
523
|
+
* function narrows its argument to `I & S["Type"]`. Only schemas with
|
|
524
|
+
* `DecodingServices: never` (i.e. no required services) can be used here.
|
|
525
|
+
*
|
|
526
|
+
* Produced by {@link asserts}.
|
|
527
|
+
*
|
|
227
528
|
* @since 4.0.0
|
|
228
529
|
*/
|
|
229
530
|
type ToAsserts<S extends Top & {
|
|
@@ -231,6 +532,18 @@ export declare namespace Codec {
|
|
|
231
532
|
}> = <I>(input: I) => asserts input is I & S["Type"];
|
|
232
533
|
}
|
|
233
534
|
/**
|
|
535
|
+
* A schema that additionally supports optic (lens/prism) operations.
|
|
536
|
+
*
|
|
537
|
+
* `Optic<T, Iso>` extends {@link Schema}`<T>` with an `Iso` type that
|
|
538
|
+
* describes the isomorphic counterpart used by the optic layer. Crucially,
|
|
539
|
+
* decoding and encoding require *no* Effect services (`DecodingServices` and
|
|
540
|
+
* `EncodingServices` are both `never`), which means the optic can operate
|
|
541
|
+
* purely without an Effect runtime.
|
|
542
|
+
*
|
|
543
|
+
* Most primitive schemas (e.g. `Schema.String`, `Schema.Number`) implement
|
|
544
|
+
* `Optic` automatically. You normally interact with this interface through
|
|
545
|
+
* {@link Optic_} utilities rather than constructing it directly.
|
|
546
|
+
*
|
|
234
547
|
* @since 4.0.0
|
|
235
548
|
*/
|
|
236
549
|
export interface Optic<out T, out Iso> extends Schema<T> {
|
|
@@ -240,16 +553,32 @@ export interface Optic<out T, out Iso> extends Schema<T> {
|
|
|
240
553
|
readonly "~rebuild.out": Optic<T, Iso>;
|
|
241
554
|
}
|
|
242
555
|
/**
|
|
243
|
-
* A schema that tracks
|
|
556
|
+
* A schema that tracks the decoded type `T`, the encoded type `E`, and the
|
|
557
|
+
* Effect services required during decoding (`RD`) and encoding (`RE`).
|
|
244
558
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
559
|
+
* Use `Codec<T, E, RD, RE>` when you need to preserve full type information
|
|
560
|
+
* about a schema — both what it decodes to and what it serializes from/to.
|
|
561
|
+
* Most concrete schemas produced by this module implement `Codec`.
|
|
562
|
+
*
|
|
563
|
+
* For APIs that only need one direction, prefer the narrower views:
|
|
564
|
+
* - {@link Decoder}`<T, RD>` — decode-only
|
|
565
|
+
* - {@link Encoder}`<E, RE>` — encode-only
|
|
566
|
+
* - {@link Schema}`<T>` — type-only (no encoded representation)
|
|
567
|
+
*
|
|
568
|
+
* **Example** (Accepting a codec that decodes to `number` from `string`)
|
|
569
|
+
*
|
|
570
|
+
* ```ts
|
|
571
|
+
* import { Schema } from "effect"
|
|
249
572
|
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
573
|
+
* declare function serialize<T>(codec: Schema.Codec<T, string>): string
|
|
574
|
+
*
|
|
575
|
+
* serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
|
|
576
|
+
* ```
|
|
577
|
+
*
|
|
578
|
+
* @see {@link Codec.Encoded} — extract the encoded type
|
|
579
|
+
* @see {@link Codec.DecodingServices} — extract required decoding services
|
|
580
|
+
* @see {@link Codec.EncodingServices} — extract required encoding services
|
|
581
|
+
* @see {@link revealCodec} — helper to make TypeScript infer the full Codec type
|
|
253
582
|
*
|
|
254
583
|
* @since 4.0.0
|
|
255
584
|
*/
|
|
@@ -260,11 +589,22 @@ export interface Codec<out T, out E = T, out RD = never, out RE = never> extends
|
|
|
260
589
|
readonly "~rebuild.out": Codec<T, E, RD, RE>;
|
|
261
590
|
}
|
|
262
591
|
/**
|
|
263
|
-
* A
|
|
592
|
+
* A {@link Codec} view for APIs that only *decode* (parse/validate) values.
|
|
264
593
|
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
594
|
+
* Use `Decoder<T, RD>` to accept "any schema that can decode to `T`" without
|
|
595
|
+
* constraining or depending on the encoded representation (`Encoded` is
|
|
596
|
+
* `unknown`) or encoding services.
|
|
597
|
+
*
|
|
598
|
+
* **Example** (Function that only needs to decode)
|
|
599
|
+
*
|
|
600
|
+
* ```ts
|
|
601
|
+
* import { Schema } from "effect"
|
|
602
|
+
*
|
|
603
|
+
* declare function validate<T>(decoder: Schema.Decoder<T>): (input: unknown) => T
|
|
604
|
+
*
|
|
605
|
+
* validate(Schema.String) // ok
|
|
606
|
+
* validate(Schema.NumberFromString) // ok
|
|
607
|
+
* ```
|
|
268
608
|
*
|
|
269
609
|
* @since 4.0.0
|
|
270
610
|
*/
|
|
@@ -272,11 +612,22 @@ export interface Decoder<out T, out RD = never> extends Codec<T, unknown, RD, un
|
|
|
272
612
|
readonly "~rebuild.out": Decoder<T, RD>;
|
|
273
613
|
}
|
|
274
614
|
/**
|
|
275
|
-
* A
|
|
615
|
+
* A {@link Codec} view for APIs that only *encode* values.
|
|
276
616
|
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
617
|
+
* Use `Encoder<E, RE>` to accept "any schema that can encode to `E`" without
|
|
618
|
+
* constraining or depending on the decoded `Type` (`Type` is `unknown`) or
|
|
619
|
+
* decoding services.
|
|
620
|
+
*
|
|
621
|
+
* **Example** (Function that only needs to encode)
|
|
622
|
+
*
|
|
623
|
+
* ```ts
|
|
624
|
+
* import { Schema } from "effect"
|
|
625
|
+
*
|
|
626
|
+
* declare function serialize<E>(encoder: Schema.Encoder<E>): (value: unknown) => E
|
|
627
|
+
*
|
|
628
|
+
* serialize(Schema.String) // ok — encodes to string
|
|
629
|
+
* serialize(Schema.NumberFromString) // ok — encodes number to string
|
|
630
|
+
* ```
|
|
280
631
|
*
|
|
281
632
|
* @since 4.0.0
|
|
282
633
|
*/
|
|
@@ -284,17 +635,54 @@ export interface Encoder<out E, out RE = never> extends Codec<unknown, E, unknow
|
|
|
284
635
|
readonly "~rebuild.out": Encoder<E, RE>;
|
|
285
636
|
}
|
|
286
637
|
/**
|
|
638
|
+
* Identity function that widens a value to the full {@link Codec} interface,
|
|
639
|
+
* prompting TypeScript to infer all four type parameters (`T`, `E`, `RD`, `RE`).
|
|
640
|
+
*
|
|
641
|
+
* When a schema is stored in a variable typed as `Schema<T>` or `Top`, the
|
|
642
|
+
* encoded type and service requirements are erased. Passing the value through
|
|
643
|
+
* `revealCodec` recovers those parameters without any runtime cost.
|
|
644
|
+
*
|
|
645
|
+
* **Example** (Recovering encoded type from a schema variable)
|
|
646
|
+
*
|
|
647
|
+
* ```ts
|
|
648
|
+
* import { Schema } from "effect"
|
|
649
|
+
*
|
|
650
|
+
* const schema: Schema.Schema<number> = Schema.NumberFromString
|
|
651
|
+
*
|
|
652
|
+
* // Without revealCodec, Encoded is unknown
|
|
653
|
+
* const codec = Schema.revealCodec(schema)
|
|
654
|
+
* type Enc = typeof codec["Encoded"] // string
|
|
655
|
+
* ```
|
|
656
|
+
*
|
|
287
657
|
* @since 4.0.0
|
|
288
658
|
*/
|
|
289
659
|
export declare function revealCodec<T, E, RD, RE>(codec: Codec<T, E, RD, RE>): Codec<T, E, RD, RE>;
|
|
290
660
|
declare const SchemaErrorTypeId = "~effect/Schema/SchemaError";
|
|
291
661
|
/**
|
|
292
|
-
*
|
|
662
|
+
* Error thrown (or returned as the error channel value) when schema decoding
|
|
663
|
+
* or encoding fails.
|
|
293
664
|
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
665
|
+
* The `issue` field contains a structured {@link Issue.Issue} tree describing
|
|
666
|
+
* every validation failure, including the path to the problematic value,
|
|
667
|
+
* expected types, and actual values received. `message` renders the issue tree
|
|
668
|
+
* as a human-readable string.
|
|
669
|
+
*
|
|
670
|
+
* Use {@link isSchemaError} to narrow an unknown value to `SchemaError`.
|
|
671
|
+
*
|
|
672
|
+
* **Example** (Catching a SchemaError)
|
|
673
|
+
*
|
|
674
|
+
* ```ts
|
|
675
|
+
* import { Schema } from "effect"
|
|
676
|
+
*
|
|
677
|
+
* try {
|
|
678
|
+
* Schema.decodeUnknownSync(Schema.Number)("not a number")
|
|
679
|
+
* } catch (err) {
|
|
680
|
+
* if (Schema.isSchemaError(err)) {
|
|
681
|
+
* console.log(err.message)
|
|
682
|
+
* // Expected number, actual "not a number"
|
|
683
|
+
* }
|
|
684
|
+
* }
|
|
685
|
+
* ```
|
|
298
686
|
*
|
|
299
687
|
* @since 4.0.0
|
|
300
688
|
*/
|
|
@@ -308,6 +696,22 @@ export declare class SchemaError {
|
|
|
308
696
|
toString(): string;
|
|
309
697
|
}
|
|
310
698
|
/**
|
|
699
|
+
* Returns `true` if `u` is a {@link SchemaError}.
|
|
700
|
+
*
|
|
701
|
+
* **Example** (Type guard in a catch block)
|
|
702
|
+
*
|
|
703
|
+
* ```ts
|
|
704
|
+
* import { Schema } from "effect"
|
|
705
|
+
*
|
|
706
|
+
* try {
|
|
707
|
+
* Schema.decodeUnknownSync(Schema.Number)("oops")
|
|
708
|
+
* } catch (err) {
|
|
709
|
+
* if (Schema.isSchemaError(err)) {
|
|
710
|
+
* console.log(err._tag) // "SchemaError"
|
|
711
|
+
* }
|
|
712
|
+
* }
|
|
713
|
+
* ```
|
|
714
|
+
*
|
|
311
715
|
* @since 4.0.0
|
|
312
716
|
*/
|
|
313
717
|
export declare function isSchemaError(u: unknown): u is SchemaError;
|
|
@@ -457,16 +861,32 @@ export declare const is: typeof Parser.is;
|
|
|
457
861
|
*/
|
|
458
862
|
export declare const asserts: typeof Parser.asserts;
|
|
459
863
|
/**
|
|
864
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
865
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}. Use this
|
|
866
|
+
* when the input type is not statically known. Prefer {@link decodeEffect} when
|
|
867
|
+
* the input is already typed as the schema's `Encoded` type.
|
|
868
|
+
*
|
|
460
869
|
* @category Decoding
|
|
461
870
|
* @since 4.0.0
|
|
462
871
|
*/
|
|
463
872
|
export declare function decodeUnknownEffect<S extends Top>(schema: S): (input: unknown, options?: AST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>;
|
|
464
873
|
/**
|
|
874
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
875
|
+
* returning an `Effect` that succeeds with the decoded value or fails with a
|
|
876
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
877
|
+
* input use {@link decodeUnknownEffect}.
|
|
878
|
+
*
|
|
465
879
|
* @category Decoding
|
|
466
880
|
* @since 4.0.0
|
|
467
881
|
*/
|
|
468
882
|
export declare const decodeEffect: <S extends Top>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>;
|
|
469
883
|
/**
|
|
884
|
+
* Decodes an `unknown` input against a schema synchronously, returning an
|
|
885
|
+
* `Exit` that is either a `Success` with the decoded value or a `Failure` with
|
|
886
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
887
|
+
* `DecodingServices` requirement. Prefer {@link decodeExit} when the input is
|
|
888
|
+
* already typed as the schema's `Encoded` type.
|
|
889
|
+
*
|
|
470
890
|
* @category Decoding
|
|
471
891
|
* @since 4.0.0
|
|
472
892
|
*/
|
|
@@ -474,6 +894,12 @@ export declare function decodeUnknownExit<S extends Top & {
|
|
|
474
894
|
readonly DecodingServices: never;
|
|
475
895
|
}>(schema: S): (input: unknown, options?: AST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>;
|
|
476
896
|
/**
|
|
897
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
898
|
+
* synchronously, returning an `Exit` that is either a `Success` with the
|
|
899
|
+
* decoded value or a `Failure` with a {@link SchemaError}. Only usable with
|
|
900
|
+
* schemas that have no `DecodingServices` requirement. For `unknown` input use
|
|
901
|
+
* {@link decodeUnknownExit}.
|
|
902
|
+
*
|
|
477
903
|
* @category Decoding
|
|
478
904
|
* @since 4.0.0
|
|
479
905
|
*/
|
|
@@ -481,11 +907,21 @@ export declare const decodeExit: <S extends Top & {
|
|
|
481
907
|
readonly DecodingServices: never;
|
|
482
908
|
}>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>;
|
|
483
909
|
/**
|
|
910
|
+
* Decodes an `unknown` input against a schema, returning an `Option` that is
|
|
911
|
+
* `Some` with the decoded value on success or `None` on failure. Prefer this
|
|
912
|
+
* over {@link decodeUnknownExit} or {@link decodeUnknownEffect} when you only
|
|
913
|
+
* need to know whether decoding succeeded and don't need error details. For
|
|
914
|
+
* typed input use {@link decodeOption}.
|
|
915
|
+
*
|
|
484
916
|
* @category Decoding
|
|
485
917
|
* @since 4.0.0
|
|
486
918
|
*/
|
|
487
919
|
export declare const decodeUnknownOption: typeof Parser.decodeUnknownOption;
|
|
488
920
|
/**
|
|
921
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
922
|
+
* returning an `Option` that is `Some` with the decoded value on success or
|
|
923
|
+
* `None` on failure. For `unknown` input use {@link decodeUnknownOption}.
|
|
924
|
+
*
|
|
489
925
|
* @category Decoding
|
|
490
926
|
* @since 4.0.0
|
|
491
927
|
*/
|
|
@@ -493,21 +929,58 @@ export declare const decodeOption: <S extends Top & {
|
|
|
493
929
|
readonly DecodingServices: never;
|
|
494
930
|
}>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => Option_.Option<S["Type"]>;
|
|
495
931
|
/**
|
|
932
|
+
* Decodes an `unknown` input against a schema, returning a `Promise` that
|
|
933
|
+
* resolves with the decoded value or rejects with a {@link SchemaError}. Useful
|
|
934
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
935
|
+
* {@link decodePromise}.
|
|
936
|
+
*
|
|
496
937
|
* @category Decoding
|
|
497
938
|
* @since 4.0.0
|
|
498
939
|
*/
|
|
499
940
|
export declare const decodeUnknownPromise: typeof Parser.decodeUnknownPromise;
|
|
500
941
|
/**
|
|
942
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema,
|
|
943
|
+
* returning a `Promise` that resolves with the decoded value or rejects with a
|
|
944
|
+
* {@link SchemaError}. For `unknown` input use {@link decodeUnknownPromise}.
|
|
945
|
+
*
|
|
501
946
|
* @category Decoding
|
|
502
947
|
* @since 4.0.0
|
|
503
948
|
*/
|
|
504
949
|
export declare const decodePromise: typeof Parser.decodePromise;
|
|
505
950
|
/**
|
|
951
|
+
* Decodes an `unknown` input against a schema synchronously, throwing a
|
|
952
|
+
* {@link SchemaError} on failure. Use this when you want to validate data at a
|
|
953
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
954
|
+
* non-throwing alternatives see {@link decodeUnknownOption},
|
|
955
|
+
* {@link decodeUnknownExit}, or {@link decodeUnknownEffect}. For typed input
|
|
956
|
+
* use {@link decodeSync}.
|
|
957
|
+
*
|
|
958
|
+
* **Example** (Decoding with a transformation schema)
|
|
959
|
+
*
|
|
960
|
+
* ```ts
|
|
961
|
+
* import { Schema } from "effect"
|
|
962
|
+
*
|
|
963
|
+
* const NumberFromString = Schema.NumberFromString
|
|
964
|
+
*
|
|
965
|
+
* console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
|
|
966
|
+
* // Output: 42
|
|
967
|
+
*
|
|
968
|
+
* Schema.decodeUnknownSync(NumberFromString)("not a number")
|
|
969
|
+
* // throws SchemaError: NumberFromString
|
|
970
|
+
* // └─ Encoded side transformation failure
|
|
971
|
+
* // └─ NumberFromString
|
|
972
|
+
* // └─ Expected a numeric string, actual "not a number"
|
|
973
|
+
* ```
|
|
974
|
+
*
|
|
506
975
|
* @category Decoding
|
|
507
976
|
* @since 4.0.0
|
|
508
977
|
*/
|
|
509
978
|
export declare const decodeUnknownSync: typeof Parser.decodeUnknownSync;
|
|
510
979
|
/**
|
|
980
|
+
* Decodes a typed input (the schema's `Encoded` type) against a schema
|
|
981
|
+
* synchronously, throwing a {@link SchemaError} on failure. For `unknown` input
|
|
982
|
+
* use {@link decodeUnknownSync}.
|
|
983
|
+
*
|
|
511
984
|
* @category Decoding
|
|
512
985
|
* @since 4.0.0
|
|
513
986
|
*/
|
|
@@ -515,16 +988,43 @@ export declare const decodeSync: <S extends Top & {
|
|
|
515
988
|
readonly DecodingServices: never;
|
|
516
989
|
}>(schema: S) => (input: S["Encoded"], options?: AST.ParseOptions) => S["Type"];
|
|
517
990
|
/**
|
|
991
|
+
* Encodes an `unknown` input against a schema, returning an `Effect` that
|
|
992
|
+
* succeeds with the encoded value or fails with a {@link SchemaError}. Use this
|
|
993
|
+
* when the input type is not statically known. Prefer {@link encodeEffect} when
|
|
994
|
+
* the input is already typed as the schema's `Type`.
|
|
995
|
+
*
|
|
996
|
+
* **Example** (Encoding a value to a string)
|
|
997
|
+
*
|
|
998
|
+
* ```ts
|
|
999
|
+
* import { Effect, Schema } from "effect"
|
|
1000
|
+
*
|
|
1001
|
+
* const NumberFromString = Schema.NumberFromString
|
|
1002
|
+
*
|
|
1003
|
+
* Effect.runPromise(Schema.encodeUnknownEffect(NumberFromString)(42)).then(console.log)
|
|
1004
|
+
* // Output: "42"
|
|
1005
|
+
* ```
|
|
1006
|
+
*
|
|
518
1007
|
* @category Encoding
|
|
519
1008
|
* @since 4.0.0
|
|
520
1009
|
*/
|
|
521
1010
|
export declare function encodeUnknownEffect<S extends Top>(schema: S): (input: unknown, options?: AST.ParseOptions) => Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]>;
|
|
522
1011
|
/**
|
|
1012
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1013
|
+
* `Effect` that succeeds with the encoded value or fails with a
|
|
1014
|
+
* {@link SchemaError}. Use this when the input is already typed; for `unknown`
|
|
1015
|
+
* input use {@link encodeUnknownEffect}.
|
|
1016
|
+
*
|
|
523
1017
|
* @category Encoding
|
|
524
1018
|
* @since 4.0.0
|
|
525
1019
|
*/
|
|
526
1020
|
export declare const encodeEffect: <S extends Top>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Effect.Effect<S["Encoded"], SchemaError, S["EncodingServices"]>;
|
|
527
1021
|
/**
|
|
1022
|
+
* Encodes an `unknown` input against a schema synchronously, returning an
|
|
1023
|
+
* `Exit` that is either a `Success` with the encoded value or a `Failure` with
|
|
1024
|
+
* a {@link SchemaError}. Only usable with schemas that have no
|
|
1025
|
+
* `EncodingServices` requirement. Prefer {@link encodeExit} when the input is
|
|
1026
|
+
* already typed as the schema's `Type`.
|
|
1027
|
+
*
|
|
528
1028
|
* @category Encoding
|
|
529
1029
|
* @since 4.0.0
|
|
530
1030
|
*/
|
|
@@ -532,6 +1032,12 @@ export declare function encodeUnknownExit<S extends Top & {
|
|
|
532
1032
|
readonly EncodingServices: never;
|
|
533
1033
|
}>(schema: S): (input: unknown, options?: AST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>;
|
|
534
1034
|
/**
|
|
1035
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1036
|
+
* returning an `Exit` that is either a `Success` with the encoded value or a
|
|
1037
|
+
* `Failure` with a {@link SchemaError}. Only usable with schemas that have no
|
|
1038
|
+
* `EncodingServices` requirement. For `unknown` input use
|
|
1039
|
+
* {@link encodeUnknownExit}.
|
|
1040
|
+
*
|
|
535
1041
|
* @category Encoding
|
|
536
1042
|
* @since 4.0.0
|
|
537
1043
|
*/
|
|
@@ -539,11 +1045,21 @@ export declare const encodeExit: <S extends Top & {
|
|
|
539
1045
|
readonly EncodingServices: never;
|
|
540
1046
|
}>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>;
|
|
541
1047
|
/**
|
|
1048
|
+
* Encodes an `unknown` input against a schema, returning an `Option` that is
|
|
1049
|
+
* `Some` with the encoded value on success or `None` on failure. Prefer this
|
|
1050
|
+
* over {@link encodeUnknownExit} or {@link encodeUnknownEffect} when you only
|
|
1051
|
+
* need to know whether encoding succeeded and don't need error details. For
|
|
1052
|
+
* typed input use {@link encodeOption}.
|
|
1053
|
+
*
|
|
542
1054
|
* @category Encoding
|
|
543
1055
|
* @since 4.0.0
|
|
544
1056
|
*/
|
|
545
1057
|
export declare const encodeUnknownOption: typeof Parser.encodeUnknownOption;
|
|
546
1058
|
/**
|
|
1059
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning an
|
|
1060
|
+
* `Option` that is `Some` with the encoded value on success or `None` on
|
|
1061
|
+
* failure. For `unknown` input use {@link encodeUnknownOption}.
|
|
1062
|
+
*
|
|
547
1063
|
* @category Encoding
|
|
548
1064
|
* @since 4.0.0
|
|
549
1065
|
*/
|
|
@@ -551,6 +1067,11 @@ export declare const encodeOption: <S extends Top & {
|
|
|
551
1067
|
readonly EncodingServices: never;
|
|
552
1068
|
}>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Option_.Option<S["Encoded"]>;
|
|
553
1069
|
/**
|
|
1070
|
+
* Encodes an `unknown` input against a schema, returning a `Promise` that
|
|
1071
|
+
* resolves with the encoded value or rejects with a {@link SchemaError}. Useful
|
|
1072
|
+
* for integrating with Promise-based APIs. For typed input use
|
|
1073
|
+
* {@link encodePromise}.
|
|
1074
|
+
*
|
|
554
1075
|
* @category Encoding
|
|
555
1076
|
* @since 4.0.0
|
|
556
1077
|
*/
|
|
@@ -558,6 +1079,10 @@ export declare const encodeUnknownPromise: <S extends Top & {
|
|
|
558
1079
|
readonly EncodingServices: never;
|
|
559
1080
|
}>(schema: S) => (input: unknown, options?: AST.ParseOptions) => Promise<S["Encoded"]>;
|
|
560
1081
|
/**
|
|
1082
|
+
* Encodes a typed input (the schema's `Type`) against a schema, returning a
|
|
1083
|
+
* `Promise` that resolves with the encoded value or rejects with a
|
|
1084
|
+
* {@link SchemaError}. For `unknown` input use {@link encodeUnknownPromise}.
|
|
1085
|
+
*
|
|
561
1086
|
* @category Encoding
|
|
562
1087
|
* @since 4.0.0
|
|
563
1088
|
*/
|
|
@@ -565,11 +1090,22 @@ export declare const encodePromise: <S extends Top & {
|
|
|
565
1090
|
readonly EncodingServices: never;
|
|
566
1091
|
}>(schema: S) => (input: S["Type"], options?: AST.ParseOptions) => Promise<S["Encoded"]>;
|
|
567
1092
|
/**
|
|
1093
|
+
* Encodes an `unknown` input against a schema synchronously, throwing a
|
|
1094
|
+
* {@link SchemaError} on failure. Use this when you want to serialize data at a
|
|
1095
|
+
* boundary and treat a schema mismatch as an unrecoverable error. For
|
|
1096
|
+
* non-throwing alternatives see {@link encodeUnknownOption},
|
|
1097
|
+
* {@link encodeUnknownExit}, or {@link encodeUnknownEffect}. For typed input
|
|
1098
|
+
* use {@link encodeSync}.
|
|
1099
|
+
*
|
|
568
1100
|
* @category Encoding
|
|
569
1101
|
* @since 4.0.0
|
|
570
1102
|
*/
|
|
571
1103
|
export declare const encodeUnknownSync: typeof Parser.encodeUnknownSync;
|
|
572
1104
|
/**
|
|
1105
|
+
* Encodes a typed input (the schema's `Type`) against a schema synchronously,
|
|
1106
|
+
* throwing a {@link SchemaError} on failure. For `unknown` input use
|
|
1107
|
+
* {@link encodeUnknownSync}.
|
|
1108
|
+
*
|
|
573
1109
|
* @category Encoding
|
|
574
1110
|
* @since 4.0.0
|
|
575
1111
|
*/
|
|
@@ -600,6 +1136,10 @@ export declare const make: <S extends Top>(ast: S["ast"], options?: object) => S
|
|
|
600
1136
|
*/
|
|
601
1137
|
export declare function isSchema(u: unknown): u is Top;
|
|
602
1138
|
/**
|
|
1139
|
+
* Schema type for an exact optional struct key. The key may be absent, but
|
|
1140
|
+
* when present must match the wrapped schema (no implicit `undefined`).
|
|
1141
|
+
* Produced by {@link optionalKey}.
|
|
1142
|
+
*
|
|
603
1143
|
* @since 4.0.0
|
|
604
1144
|
*/
|
|
605
1145
|
export interface optionalKey<S extends Top> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], optionalKey<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], "optional", S["~type.constructor.default"], S["~encoded.mutability"], "optional"> {
|
|
@@ -637,10 +1177,16 @@ interface requiredKeyLambda extends Lambda {
|
|
|
637
1177
|
readonly "~lambda.out": this["~lambda.in"] extends optionalKey<Top> ? this["~lambda.in"]["schema"] : "Error: schema not eligible for requiredKey";
|
|
638
1178
|
}
|
|
639
1179
|
/**
|
|
1180
|
+
* Reverses {@link optionalKey}, returning the inner required schema. Only
|
|
1181
|
+
* applicable to schemas already wrapped with `optionalKey`.
|
|
1182
|
+
*
|
|
640
1183
|
* @since 4.0.0
|
|
641
1184
|
*/
|
|
642
1185
|
export declare const requiredKey: requiredKeyLambda;
|
|
643
1186
|
/**
|
|
1187
|
+
* Schema type for an optional struct key that also accepts `undefined`.
|
|
1188
|
+
* Equivalent to `optionalKey<UndefinedOr<S>>`. Produced by {@link optional}.
|
|
1189
|
+
*
|
|
644
1190
|
* @since 4.0.0
|
|
645
1191
|
*/
|
|
646
1192
|
export interface optional<S extends Top> extends optionalKey<UndefinedOr<S>> {
|
|
@@ -650,27 +1196,26 @@ interface optionalLambda extends Lambda {
|
|
|
650
1196
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? optional<this["~lambda.in"]> : never;
|
|
651
1197
|
}
|
|
652
1198
|
/**
|
|
653
|
-
*
|
|
1199
|
+
* Marks a struct field as optional, allowing the key to be absent or
|
|
654
1200
|
* `undefined`.
|
|
655
1201
|
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
* - Can contain the specified schema type
|
|
1202
|
+
* explicitly set to `undefined`. Equivalent to `optionalKey(UndefinedOr(S))`.
|
|
1203
|
+
*
|
|
1204
|
+
* Use {@link optionalKey} instead if you want exact optional semantics (absent
|
|
1205
|
+
* only, not `undefined`).
|
|
661
1206
|
*
|
|
662
|
-
* **Example** (
|
|
1207
|
+
* **Example** (Optional field accepting undefined)
|
|
663
1208
|
*
|
|
664
1209
|
* ```ts
|
|
665
1210
|
* import { Schema } from "effect"
|
|
666
1211
|
*
|
|
667
1212
|
* const schema = Schema.Struct({
|
|
668
1213
|
* name: Schema.String,
|
|
669
|
-
* age: Schema.
|
|
1214
|
+
* age: Schema.optional(Schema.Number)
|
|
670
1215
|
* })
|
|
671
1216
|
*
|
|
672
|
-
* //
|
|
673
|
-
* type Person = typeof schema
|
|
1217
|
+
* // { readonly name: string; readonly age?: number | undefined }
|
|
1218
|
+
* type Person = typeof schema.Type
|
|
674
1219
|
* ```
|
|
675
1220
|
*
|
|
676
1221
|
* @since 4.0.0
|
|
@@ -681,10 +1226,16 @@ interface requiredLambda extends Lambda {
|
|
|
681
1226
|
readonly "~lambda.out": this["~lambda.in"] extends optional<Top> ? this["~lambda.in"]["schema"]["members"][0] : "Error: schema not eligible for required";
|
|
682
1227
|
}
|
|
683
1228
|
/**
|
|
1229
|
+
* Reverses {@link optional}, returning the inner schema (unwrapping `UndefinedOr`).
|
|
1230
|
+
* Only applicable to schemas already wrapped with `optional`.
|
|
1231
|
+
*
|
|
684
1232
|
* @since 4.0.0
|
|
685
1233
|
*/
|
|
686
1234
|
export declare const required: requiredLambda;
|
|
687
1235
|
/**
|
|
1236
|
+
* Schema type for a mutable struct key. The key's property is writable.
|
|
1237
|
+
* Produced by {@link mutableKey}.
|
|
1238
|
+
*
|
|
688
1239
|
* @since 4.0.0
|
|
689
1240
|
*/
|
|
690
1241
|
export interface mutableKey<S extends Top> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], mutableKey<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], "mutable", S["~type.optionality"], S["~type.constructor.default"], "mutable", S["~encoded.optionality"]> {
|
|
@@ -696,6 +1247,9 @@ interface mutableKeyLambda extends Lambda {
|
|
|
696
1247
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? mutableKey<this["~lambda.in"]> : never;
|
|
697
1248
|
}
|
|
698
1249
|
/**
|
|
1250
|
+
* Makes a struct field mutable (removes the `readonly` modifier on the property).
|
|
1251
|
+
* Use {@link readonlyKey} to reverse.
|
|
1252
|
+
*
|
|
699
1253
|
* @since 4.0.0
|
|
700
1254
|
*/
|
|
701
1255
|
export declare const mutableKey: mutableKeyLambda;
|
|
@@ -704,10 +1258,16 @@ interface readonlyKeyLambda extends Lambda {
|
|
|
704
1258
|
readonly "~lambda.out": this["~lambda.in"] extends mutableKey<Top> ? this["~lambda.in"]["schema"] : "Error: schema not eligible for readonlyKey";
|
|
705
1259
|
}
|
|
706
1260
|
/**
|
|
1261
|
+
* Reverses {@link mutableKey}, returning the inner schema as readonly again.
|
|
1262
|
+
* Only applicable to schemas already wrapped with `mutableKey`.
|
|
1263
|
+
*
|
|
707
1264
|
* @since 4.0.0
|
|
708
1265
|
*/
|
|
709
1266
|
export declare const readonlyKey: readonlyKeyLambda;
|
|
710
1267
|
/**
|
|
1268
|
+
* Schema type that collapses a transformation schema to its decoded `Type` on
|
|
1269
|
+
* both sides (Type = Encoded = S["Type"]). Produced by {@link toType}.
|
|
1270
|
+
*
|
|
711
1271
|
* @since 4.0.0
|
|
712
1272
|
*/
|
|
713
1273
|
export interface toType<S extends Top> extends Bottom<S["Type"], S["Type"], never, never, S["ast"], toType<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -718,10 +1278,16 @@ interface toTypeLambda extends Lambda {
|
|
|
718
1278
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? toType<this["~lambda.in"]> : never;
|
|
719
1279
|
}
|
|
720
1280
|
/**
|
|
1281
|
+
* Extracts the type-side schema: sets `Encoded` to equal the decoded `Type`,
|
|
1282
|
+
* discarding the encoding transformation path.
|
|
1283
|
+
*
|
|
721
1284
|
* @since 4.0.0
|
|
722
1285
|
*/
|
|
723
1286
|
export declare const toType: toTypeLambda;
|
|
724
1287
|
/**
|
|
1288
|
+
* Schema type that collapses a transformation schema to its `Encoded` side on
|
|
1289
|
+
* both sides (Type = Encoded = S["Encoded"]). Produced by {@link toEncoded}.
|
|
1290
|
+
*
|
|
725
1291
|
* @since 4.0.0
|
|
726
1292
|
*/
|
|
727
1293
|
export interface toEncoded<S extends Top> extends Bottom<S["Encoded"], S["Encoded"], never, never, AST.AST, toEncoded<S>, S["Encoded"], S["Encoded"], ReadonlyArray<Top>, S["Encoded"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -732,11 +1298,17 @@ interface toEncodedLambda extends Lambda {
|
|
|
732
1298
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? toEncoded<this["~lambda.in"]> : never;
|
|
733
1299
|
}
|
|
734
1300
|
/**
|
|
1301
|
+
* Extracts the encoded-side schema: sets `Type` to equal the `Encoded`,
|
|
1302
|
+
* discarding the decoding transformation path.
|
|
1303
|
+
*
|
|
735
1304
|
* @since 4.0.0
|
|
736
1305
|
*/
|
|
737
1306
|
export declare const toEncoded: toEncodedLambda;
|
|
738
1307
|
declare const FlipTypeId = "~effect/Schema/flip";
|
|
739
1308
|
/**
|
|
1309
|
+
* Schema type representing a flipped schema where `Type` and `Encoded` are
|
|
1310
|
+
* swapped. Produced by {@link flip}.
|
|
1311
|
+
*
|
|
740
1312
|
* @since 4.0.0
|
|
741
1313
|
*/
|
|
742
1314
|
export interface flip<S extends Top> extends Bottom<S["Encoded"], S["Type"], S["EncodingServices"], S["DecodingServices"], AST.AST, flip<S>, S["Encoded"], S["Encoded"], ReadonlyArray<Top>, S["Encoded"], S["~encoded.mutability"], S["~encoded.optionality"], ConstructorDefault, S["~type.mutability"], S["~type.optionality"]> {
|
|
@@ -745,10 +1317,26 @@ export interface flip<S extends Top> extends Bottom<S["Encoded"], S["Type"], S["
|
|
|
745
1317
|
readonly schema: S;
|
|
746
1318
|
}
|
|
747
1319
|
/**
|
|
1320
|
+
* Swaps the `Type` and `Encoded` of a schema, inverting the transformation
|
|
1321
|
+
* direction. Calling `flip` twice returns the original schema.
|
|
1322
|
+
*
|
|
1323
|
+
* **Example** (Flip a number-from-string schema)
|
|
1324
|
+
*
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* import { Schema } from "effect"
|
|
1327
|
+
*
|
|
1328
|
+
* // NumberFromString: decodes string → number
|
|
1329
|
+
* const flipped = Schema.flip(Schema.NumberFromString)
|
|
1330
|
+
* // flipped: decodes number → string
|
|
1331
|
+
* ```
|
|
1332
|
+
*
|
|
748
1333
|
* @since 4.0.0
|
|
749
1334
|
*/
|
|
750
1335
|
export declare function flip<S extends Top>(schema: S): S extends flip<infer F> ? F["~rebuild.out"] : flip<S>;
|
|
751
1336
|
/**
|
|
1337
|
+
* Represents a schema for a single literal value.
|
|
1338
|
+
*
|
|
1339
|
+
* @see {@link Literal} for the constructor function.
|
|
752
1340
|
* @since 4.0.0
|
|
753
1341
|
*/
|
|
754
1342
|
export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never, never, AST.Literal, Literal<L>> {
|
|
@@ -757,6 +1345,16 @@ export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never,
|
|
|
757
1345
|
transform<L2 extends AST.LiteralValue>(to: L2): decodeTo<Literal<L2>, Literal<L>>;
|
|
758
1346
|
}
|
|
759
1347
|
/**
|
|
1348
|
+
* Creates a schema for a single literal value (string, number, bigint, boolean, or null).
|
|
1349
|
+
*
|
|
1350
|
+
* **Example** (String literal)
|
|
1351
|
+
* ```ts
|
|
1352
|
+
* import { Schema } from "effect"
|
|
1353
|
+
*
|
|
1354
|
+
* const schema = Schema.Literal("hello")
|
|
1355
|
+
* // Type: Schema.Literal<"hello">
|
|
1356
|
+
* ```
|
|
1357
|
+
*
|
|
760
1358
|
* @see {@link Literals} for a schema that represents a union of literals.
|
|
761
1359
|
* @see {@link tag} for a schema that represents a literal value that can be
|
|
762
1360
|
* used as a discriminator field in tagged unions and has a constructor default.
|
|
@@ -764,6 +1362,8 @@ export interface Literal<L extends AST.LiteralValue> extends Bottom<L, L, never,
|
|
|
764
1362
|
*/
|
|
765
1363
|
export declare function Literal<L extends AST.LiteralValue>(literal: L): Literal<L>;
|
|
766
1364
|
/**
|
|
1365
|
+
* Namespace for {@link TemplateLiteral} helper types.
|
|
1366
|
+
*
|
|
767
1367
|
* @since 4.0.0
|
|
768
1368
|
*/
|
|
769
1369
|
export declare namespace TemplateLiteral {
|
|
@@ -792,6 +1392,10 @@ export declare namespace TemplateLiteral {
|
|
|
792
1392
|
type Encoded<Parts> = Parts extends readonly [...infer Init, infer Last] ? AppendType<Encoded<Init>, Last> : ``;
|
|
793
1393
|
}
|
|
794
1394
|
/**
|
|
1395
|
+
* Represents a schema that validates strings matching a template literal pattern.
|
|
1396
|
+
* The encoded type is a string formed by concatenating the parts.
|
|
1397
|
+
*
|
|
1398
|
+
* @see {@link TemplateLiteral} for the constructor function.
|
|
795
1399
|
* @since 4.0.0
|
|
796
1400
|
*/
|
|
797
1401
|
export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends Bottom<TemplateLiteral.Encoded<Parts>, TemplateLiteral.Encoded<Parts>, never, never, AST.TemplateLiteral, TemplateLiteral<Parts>> {
|
|
@@ -799,10 +1403,24 @@ export interface TemplateLiteral<Parts extends TemplateLiteral.Parts> extends Bo
|
|
|
799
1403
|
readonly parts: Parts;
|
|
800
1404
|
}
|
|
801
1405
|
/**
|
|
1406
|
+
* Creates a schema that validates strings matching a template literal pattern. Each part can be
|
|
1407
|
+
* a literal string/number/bigint or a schema whose encoded type is a string, number, or bigint.
|
|
1408
|
+
*
|
|
1409
|
+
* **Example** (URL path pattern)
|
|
1410
|
+
* ```ts
|
|
1411
|
+
* import { Schema } from "effect"
|
|
1412
|
+
*
|
|
1413
|
+
* const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
|
|
1414
|
+
* // matches strings like "/user/123", "/user/42", etc.
|
|
1415
|
+
* ```
|
|
1416
|
+
*
|
|
1417
|
+
* @see {@link TemplateLiteralParser} for a schema that also parses matched parts into a tuple.
|
|
802
1418
|
* @since 4.0.0
|
|
803
1419
|
*/
|
|
804
1420
|
export declare function TemplateLiteral<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteral<Parts>;
|
|
805
1421
|
/**
|
|
1422
|
+
* Namespace for {@link TemplateLiteralParser} helper types.
|
|
1423
|
+
*
|
|
806
1424
|
* @since 4.0.0
|
|
807
1425
|
*/
|
|
808
1426
|
export declare namespace TemplateLiteralParser {
|
|
@@ -815,6 +1433,10 @@ export declare namespace TemplateLiteralParser {
|
|
|
815
1433
|
] : [];
|
|
816
1434
|
}
|
|
817
1435
|
/**
|
|
1436
|
+
* Represents a schema that validates strings matching a template literal pattern and decodes
|
|
1437
|
+
* them into a tuple of typed values, one per schema part.
|
|
1438
|
+
*
|
|
1439
|
+
* @see {@link TemplateLiteralParser} for the constructor function.
|
|
818
1440
|
* @since 4.0.0
|
|
819
1441
|
*/
|
|
820
1442
|
export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> extends Bottom<TemplateLiteralParser.Type<Parts>, TemplateLiteral.Encoded<Parts>, never, never, AST.Arrays, TemplateLiteralParser<Parts>> {
|
|
@@ -822,10 +1444,26 @@ export interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts> exte
|
|
|
822
1444
|
readonly parts: Parts;
|
|
823
1445
|
}
|
|
824
1446
|
/**
|
|
1447
|
+
* Like {@link TemplateLiteral} but decodes the matched string into a readonly tuple of typed values,
|
|
1448
|
+
* one element per schema part.
|
|
1449
|
+
*
|
|
1450
|
+
* **Example** (Parse path parameters)
|
|
1451
|
+
* ```ts
|
|
1452
|
+
* import { Schema } from "effect"
|
|
1453
|
+
*
|
|
1454
|
+
* const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
|
|
1455
|
+
* // decodes "/user/42" => readonly ["/user/", 42]
|
|
1456
|
+
* ```
|
|
1457
|
+
*
|
|
1458
|
+
* @see {@link TemplateLiteral} for a validation-only version that keeps the string encoded.
|
|
825
1459
|
* @since 4.0.0
|
|
826
1460
|
*/
|
|
827
1461
|
export declare function TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteralParser<Parts>;
|
|
828
1462
|
/**
|
|
1463
|
+
* Represents a schema derived from a TypeScript `const enum` or a plain enum object,
|
|
1464
|
+
* accepting any of its values.
|
|
1465
|
+
*
|
|
1466
|
+
* @see {@link Enum} for the constructor function.
|
|
829
1467
|
* @since 4.0.0
|
|
830
1468
|
*/
|
|
831
1469
|
export interface Enum<A extends {
|
|
@@ -835,176 +1473,262 @@ export interface Enum<A extends {
|
|
|
835
1473
|
readonly enums: A;
|
|
836
1474
|
}
|
|
837
1475
|
/**
|
|
1476
|
+
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
|
|
1477
|
+
*
|
|
1478
|
+
* **Example** (Direction enum)
|
|
1479
|
+
* ```ts
|
|
1480
|
+
* import { Schema } from "effect"
|
|
1481
|
+
*
|
|
1482
|
+
* enum Direction {
|
|
1483
|
+
* Up = "Up",
|
|
1484
|
+
* Down = "Down"
|
|
1485
|
+
* }
|
|
1486
|
+
*
|
|
1487
|
+
* const schema = Schema.Enum(Direction)
|
|
1488
|
+
* // accepts "Up" or "Down"
|
|
1489
|
+
* ```
|
|
1490
|
+
*
|
|
838
1491
|
* @since 4.0.0
|
|
839
1492
|
*/
|
|
840
1493
|
export declare function Enum<A extends {
|
|
841
1494
|
[x: string]: string | number;
|
|
842
1495
|
}>(enums: A): Enum<A>;
|
|
843
1496
|
/**
|
|
1497
|
+
* Schema for the `never` type. Always fails validation.
|
|
1498
|
+
*
|
|
1499
|
+
* @see {@link Never} for the schema value.
|
|
844
1500
|
* @since 4.0.0
|
|
845
1501
|
*/
|
|
846
1502
|
export interface Never extends Bottom<never, never, never, never, AST.Never, Never> {
|
|
847
1503
|
readonly "~rebuild.out": this;
|
|
848
1504
|
}
|
|
849
1505
|
/**
|
|
1506
|
+
* Schema for the `never` type. Always fails validation — no value satisfies it.
|
|
1507
|
+
*
|
|
850
1508
|
* @since 4.0.0
|
|
851
1509
|
*/
|
|
852
1510
|
export declare const Never: Never;
|
|
853
1511
|
/**
|
|
1512
|
+
* Schema for the `any` type. Accepts any value without validation.
|
|
1513
|
+
*
|
|
1514
|
+
* @see {@link Any} for the schema value.
|
|
854
1515
|
* @since 4.0.0
|
|
855
1516
|
*/
|
|
856
1517
|
export interface Any extends Bottom<any, any, never, never, AST.Any, Any> {
|
|
857
1518
|
readonly "~rebuild.out": this;
|
|
858
1519
|
}
|
|
859
1520
|
/**
|
|
1521
|
+
* Schema for the `any` type. Accepts any value without validation.
|
|
1522
|
+
*
|
|
1523
|
+
* @see {@link Unknown} for a safer alternative that uses `unknown`.
|
|
860
1524
|
* @since 4.0.0
|
|
861
1525
|
*/
|
|
862
1526
|
export declare const Any: Any;
|
|
863
1527
|
/**
|
|
1528
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1529
|
+
*
|
|
1530
|
+
* @see {@link Unknown} for the schema value.
|
|
864
1531
|
* @since 4.0.0
|
|
865
1532
|
*/
|
|
866
1533
|
export interface Unknown extends Bottom<unknown, unknown, never, never, AST.Unknown, Unknown> {
|
|
867
1534
|
readonly "~rebuild.out": this;
|
|
868
1535
|
}
|
|
869
1536
|
/**
|
|
1537
|
+
* Schema for the `unknown` type. Accepts any value without validation.
|
|
1538
|
+
*
|
|
1539
|
+
* @see {@link Any} for the `any` variant.
|
|
870
1540
|
* @since 4.0.0
|
|
871
1541
|
*/
|
|
872
1542
|
export declare const Unknown: Unknown;
|
|
873
1543
|
/**
|
|
1544
|
+
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1545
|
+
*
|
|
1546
|
+
* @see {@link Null} for the schema value.
|
|
874
1547
|
* @since 4.0.0
|
|
875
1548
|
*/
|
|
876
1549
|
export interface Null extends Bottom<null, null, never, never, AST.Null, Null> {
|
|
877
1550
|
readonly "~rebuild.out": this;
|
|
878
1551
|
}
|
|
879
1552
|
/**
|
|
1553
|
+
* Schema for the `null` literal. Validates that the input is strictly `null`.
|
|
1554
|
+
*
|
|
1555
|
+
* @see {@link NullOr} for a union with another schema.
|
|
880
1556
|
* @since 4.0.0
|
|
881
1557
|
*/
|
|
882
1558
|
export declare const Null: Null;
|
|
883
1559
|
/**
|
|
1560
|
+
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1561
|
+
*
|
|
1562
|
+
* @see {@link Undefined} for the schema value.
|
|
884
1563
|
* @since 4.0.0
|
|
885
1564
|
*/
|
|
886
1565
|
export interface Undefined extends Bottom<undefined, undefined, never, never, AST.Undefined, Undefined> {
|
|
887
1566
|
readonly "~rebuild.out": this;
|
|
888
1567
|
}
|
|
889
1568
|
/**
|
|
1569
|
+
* Schema for the `undefined` literal. Validates that the input is strictly `undefined`.
|
|
1570
|
+
*
|
|
1571
|
+
* @see {@link UndefinedOr} for a union with another schema.
|
|
890
1572
|
* @since 4.0.0
|
|
891
1573
|
*/
|
|
892
1574
|
export declare const Undefined: Undefined;
|
|
893
1575
|
/**
|
|
1576
|
+
* Schema for `string` values.
|
|
1577
|
+
*
|
|
1578
|
+
* @see {@link String} for the schema value.
|
|
894
1579
|
* @since 4.0.0
|
|
895
1580
|
*/
|
|
896
1581
|
export interface String extends Bottom<string, string, never, never, AST.String, String> {
|
|
897
1582
|
readonly "~rebuild.out": this;
|
|
898
1583
|
}
|
|
899
1584
|
/**
|
|
900
|
-
*
|
|
1585
|
+
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
901
1586
|
*
|
|
902
1587
|
* @since 4.0.0
|
|
903
1588
|
*/
|
|
904
1589
|
export declare const String: String;
|
|
905
1590
|
/**
|
|
1591
|
+
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
1592
|
+
*
|
|
1593
|
+
* @see {@link Number} for the schema value.
|
|
906
1594
|
* @since 4.0.0
|
|
907
1595
|
*/
|
|
908
1596
|
export interface Number extends Bottom<number, number, never, never, AST.Number, Number> {
|
|
909
1597
|
readonly "~rebuild.out": this;
|
|
910
1598
|
}
|
|
911
1599
|
/**
|
|
912
|
-
*
|
|
1600
|
+
* Schema for `number` values, including `NaN`, `Infinity`, and `-Infinity`.
|
|
913
1601
|
*
|
|
914
1602
|
* **Default Json Serializer**
|
|
915
1603
|
*
|
|
916
|
-
* -
|
|
917
|
-
* -
|
|
1604
|
+
* - Finite numbers are serialized as numbers.
|
|
1605
|
+
* - Non-finite values are serialized as strings (`"NaN"`, `"Infinity"`, `"-Infinity"`).
|
|
918
1606
|
*
|
|
1607
|
+
* @see {@link Finite} for a schema that excludes non-finite values.
|
|
919
1608
|
* @since 4.0.0
|
|
920
1609
|
*/
|
|
921
1610
|
export declare const Number: Number;
|
|
922
1611
|
/**
|
|
1612
|
+
* Schema for `boolean` values.
|
|
1613
|
+
*
|
|
1614
|
+
* @see {@link Boolean} for the schema value.
|
|
923
1615
|
* @since 4.0.0
|
|
924
1616
|
*/
|
|
925
1617
|
export interface Boolean extends Bottom<boolean, boolean, never, never, AST.Boolean, Boolean> {
|
|
926
1618
|
readonly "~rebuild.out": this;
|
|
927
1619
|
}
|
|
928
1620
|
/**
|
|
929
|
-
*
|
|
1621
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
930
1622
|
*
|
|
931
1623
|
* @category Boolean
|
|
932
1624
|
* @since 4.0.0
|
|
933
1625
|
*/
|
|
934
1626
|
export declare const Boolean: Boolean;
|
|
935
1627
|
/**
|
|
1628
|
+
* Schema for `symbol` values.
|
|
1629
|
+
*
|
|
1630
|
+
* @see {@link Symbol} for the schema value.
|
|
936
1631
|
* @since 4.0.0
|
|
937
1632
|
*/
|
|
938
1633
|
export interface Symbol extends Bottom<symbol, symbol, never, never, AST.Symbol, Symbol> {
|
|
939
1634
|
readonly "~rebuild.out": this;
|
|
940
1635
|
}
|
|
941
1636
|
/**
|
|
942
|
-
*
|
|
1637
|
+
* Schema for `symbol` values. Validates that the input is `typeof` `"symbol"`.
|
|
943
1638
|
*
|
|
1639
|
+
* @see {@link UniqueSymbol} for a schema that matches a specific symbol.
|
|
944
1640
|
* @since 4.0.0
|
|
945
1641
|
*/
|
|
946
1642
|
export declare const Symbol: Symbol;
|
|
947
1643
|
/**
|
|
1644
|
+
* Schema for `bigint` values.
|
|
1645
|
+
*
|
|
1646
|
+
* @see {@link BigInt} for the schema value.
|
|
948
1647
|
* @since 4.0.0
|
|
949
1648
|
*/
|
|
950
1649
|
export interface BigInt extends Bottom<bigint, bigint, never, never, AST.BigInt, BigInt> {
|
|
951
1650
|
readonly "~rebuild.out": this;
|
|
952
1651
|
}
|
|
953
1652
|
/**
|
|
954
|
-
*
|
|
1653
|
+
* Schema for `bigint` values. Validates that the input is `typeof` `"bigint"`.
|
|
955
1654
|
*
|
|
956
1655
|
* @since 4.0.0
|
|
957
1656
|
*/
|
|
958
1657
|
export declare const BigInt: BigInt;
|
|
959
1658
|
/**
|
|
1659
|
+
* Schema for the `void` type.
|
|
1660
|
+
*
|
|
1661
|
+
* @see {@link Void} for the schema value.
|
|
960
1662
|
* @since 4.0.0
|
|
961
1663
|
*/
|
|
962
1664
|
export interface Void extends Bottom<void, void, never, never, AST.Void, Void> {
|
|
963
1665
|
readonly "~rebuild.out": this;
|
|
964
1666
|
}
|
|
965
1667
|
/**
|
|
966
|
-
*
|
|
1668
|
+
* Schema for the `void` type. Accepts `undefined` as the encoded value.
|
|
967
1669
|
*
|
|
968
1670
|
* @since 4.0.0
|
|
969
1671
|
*/
|
|
970
1672
|
export declare const Void: Void;
|
|
971
1673
|
/**
|
|
1674
|
+
* Schema for the `object` type keyword.
|
|
1675
|
+
*
|
|
1676
|
+
* @see {@link ObjectKeyword} for the schema value.
|
|
972
1677
|
* @since 4.0.0
|
|
973
1678
|
*/
|
|
974
1679
|
export interface ObjectKeyword extends Bottom<object, object, never, never, AST.ObjectKeyword, ObjectKeyword> {
|
|
975
1680
|
readonly "~rebuild.out": this;
|
|
976
1681
|
}
|
|
977
1682
|
/**
|
|
978
|
-
*
|
|
1683
|
+
* Schema for the `object` type. Validates that the input is a non-null object or function
|
|
1684
|
+
* (i.e. `typeof value === "object" && value !== null || typeof value === "function"`).
|
|
979
1685
|
*
|
|
980
1686
|
* @since 4.0.0
|
|
981
1687
|
*/
|
|
982
1688
|
export declare const ObjectKeyword: ObjectKeyword;
|
|
983
1689
|
/**
|
|
1690
|
+
* Represents a schema for a specific unique symbol.
|
|
1691
|
+
*
|
|
1692
|
+
* @see {@link UniqueSymbol} for the constructor function.
|
|
984
1693
|
* @since 4.0.0
|
|
985
1694
|
*/
|
|
986
1695
|
export interface UniqueSymbol<sym extends symbol> extends Bottom<sym, sym, never, never, AST.UniqueSymbol, UniqueSymbol<sym>> {
|
|
987
1696
|
readonly "~rebuild.out": this;
|
|
988
1697
|
}
|
|
989
1698
|
/**
|
|
990
|
-
*
|
|
991
|
-
*
|
|
992
|
-
* **Example**
|
|
1699
|
+
* Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
|
|
993
1700
|
*
|
|
1701
|
+
* **Example** (Specific symbol)
|
|
994
1702
|
* ```ts
|
|
995
1703
|
* import { Schema } from "effect"
|
|
996
1704
|
*
|
|
997
|
-
* const
|
|
998
|
-
* const schema = Schema.UniqueSymbol(
|
|
1705
|
+
* const mySymbol = Symbol.for("mySymbol")
|
|
1706
|
+
* const schema = Schema.UniqueSymbol(mySymbol)
|
|
999
1707
|
* ```
|
|
1708
|
+
*
|
|
1709
|
+
* @see {@link Symbol} for a schema that accepts any symbol.
|
|
1000
1710
|
* @since 4.0.0
|
|
1001
1711
|
*/
|
|
1002
1712
|
export declare function UniqueSymbol<const sym extends symbol>(symbol: sym): UniqueSymbol<sym>;
|
|
1003
1713
|
/**
|
|
1714
|
+
* Namespace for struct field type utilities.
|
|
1715
|
+
*
|
|
1716
|
+
* These types compute the decoded `Type`, encoded `Encoded`, and constructor
|
|
1717
|
+
* input `MakeIn` of a {@link Struct} from its field map, handling optional,
|
|
1718
|
+
* mutable, and other field modifiers automatically.
|
|
1719
|
+
*
|
|
1720
|
+
* - `Struct.Fields` — constraint for the field map object
|
|
1721
|
+
* - `Struct.Type<F>` — decoded type of the struct
|
|
1722
|
+
* - `Struct.Encoded<F>` — encoded type of the struct
|
|
1723
|
+
* - `Struct.MakeIn<F>` — constructor input (optional/defaulted fields may be omitted)
|
|
1724
|
+
* - `Struct.DecodingServices<F>` / `Struct.EncodingServices<F>` — required services
|
|
1725
|
+
*
|
|
1004
1726
|
* @since 4.0.0
|
|
1005
1727
|
*/
|
|
1006
1728
|
export declare namespace Struct {
|
|
1007
1729
|
/**
|
|
1730
|
+
* Constraint for a struct field map: an object whose values are schemas.
|
|
1731
|
+
*
|
|
1008
1732
|
* @since 4.0.0
|
|
1009
1733
|
*/
|
|
1010
1734
|
type Fields = {
|
|
@@ -1142,6 +1866,34 @@ export interface Struct<Fields extends Struct.Fields> extends Bottom<Simplify<St
|
|
|
1142
1866
|
} | undefined): Struct<Simplify<Readonly<To>>>;
|
|
1143
1867
|
}
|
|
1144
1868
|
/**
|
|
1869
|
+
* Defines a struct schema from a map of field schemas.
|
|
1870
|
+
*
|
|
1871
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
1872
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
1873
|
+
*
|
|
1874
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
1875
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
1876
|
+
*
|
|
1877
|
+
* **Example** (Basic struct)
|
|
1878
|
+
*
|
|
1879
|
+
* ```ts
|
|
1880
|
+
* import { Schema } from "effect"
|
|
1881
|
+
*
|
|
1882
|
+
* const Person = Schema.Struct({
|
|
1883
|
+
* name: Schema.String,
|
|
1884
|
+
* age: Schema.Number,
|
|
1885
|
+
* email: Schema.optionalKey(Schema.String)
|
|
1886
|
+
* })
|
|
1887
|
+
*
|
|
1888
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
1889
|
+
* type Person = typeof Person.Type
|
|
1890
|
+
*
|
|
1891
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
1892
|
+
* console.log(alice)
|
|
1893
|
+
* // { name: 'Alice', age: 30 }
|
|
1894
|
+
* ```
|
|
1895
|
+
*
|
|
1896
|
+
* @category Constructors
|
|
1145
1897
|
* @since 4.0.0
|
|
1146
1898
|
*/
|
|
1147
1899
|
export declare function Struct<const Fields extends Struct.Fields>(fields: Fields): Struct<Fields>;
|
|
@@ -1169,6 +1921,26 @@ interface fieldsAssign<NewFields extends Struct.Fields> extends Lambda {
|
|
|
1169
1921
|
*/
|
|
1170
1922
|
export declare function fieldsAssign<const NewFields extends Struct.Fields>(fields: NewFields): fieldsAssign<NewFields>;
|
|
1171
1923
|
/**
|
|
1924
|
+
* Renames struct keys in the encoded form without changing the decoded type.
|
|
1925
|
+
*
|
|
1926
|
+
* Takes a partial mapping `{ decodedKey: encodedKey }` and produces a
|
|
1927
|
+
* transformation schema that decodes from the renamed keys and encodes back to
|
|
1928
|
+
* the renamed keys. Keys not present in the mapping are left unchanged.
|
|
1929
|
+
*
|
|
1930
|
+
* **Example** (Rename `name` to `full_name` in the encoded form)
|
|
1931
|
+
*
|
|
1932
|
+
* ```ts
|
|
1933
|
+
* import { Schema } from "effect"
|
|
1934
|
+
*
|
|
1935
|
+
* const Person = Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
1936
|
+
* const Encoded = Person.pipe(Schema.encodeKeys({ name: "full_name" }))
|
|
1937
|
+
*
|
|
1938
|
+
* // Decodes { full_name: "Alice", age: 30 } → { name: "Alice", age: 30 }
|
|
1939
|
+
* const alice = Schema.decodeUnknownSync(Encoded)({ full_name: "Alice", age: 30 })
|
|
1940
|
+
* console.log(alice)
|
|
1941
|
+
* // { name: 'Alice', age: 30 }
|
|
1942
|
+
* ```
|
|
1943
|
+
*
|
|
1172
1944
|
* @category Struct transformations
|
|
1173
1945
|
* @since 4.0.0
|
|
1174
1946
|
*/
|
|
@@ -1178,6 +1950,31 @@ export declare function encodeKeys<S extends Top & {
|
|
|
1178
1950
|
readonly [K in keyof S["fields"]]?: PropertyKey;
|
|
1179
1951
|
}>(mapping: M): (self: S) => decodeTo<S, Struct<{ [K in keyof S["fields"] as K extends keyof M ? M[K] extends PropertyKey ? M[K] : K : K]: toEncoded<S["fields"][K]>; }>>;
|
|
1180
1952
|
/**
|
|
1953
|
+
* Adds derived fields to a struct schema during decoding.
|
|
1954
|
+
*
|
|
1955
|
+
* Each new field is derived from the decoded struct value via a function that
|
|
1956
|
+
* returns `Option`. On encoding the derived fields are stripped. This allows
|
|
1957
|
+
* computed or enriched fields to live in the decoded type without appearing in
|
|
1958
|
+
* the encoded form.
|
|
1959
|
+
*
|
|
1960
|
+
* **Example** (Add a computed `fullName` field)
|
|
1961
|
+
*
|
|
1962
|
+
* ```ts
|
|
1963
|
+
* import { Option, Schema } from "effect"
|
|
1964
|
+
*
|
|
1965
|
+
* const Person = Schema.Struct({ first: Schema.String, last: Schema.String })
|
|
1966
|
+
* const Extended = Person.pipe(
|
|
1967
|
+
* Schema.extendTo(
|
|
1968
|
+
* { fullName: Schema.String },
|
|
1969
|
+
* { fullName: (p) => Option.some(`${p.first} ${p.last}`) }
|
|
1970
|
+
* )
|
|
1971
|
+
* )
|
|
1972
|
+
*
|
|
1973
|
+
* const alice = Schema.decodeUnknownSync(Extended)({ first: "Alice", last: "Smith" })
|
|
1974
|
+
* console.log(alice.fullName)
|
|
1975
|
+
* // Alice Smith
|
|
1976
|
+
* ```
|
|
1977
|
+
*
|
|
1181
1978
|
* @since 4.0.0
|
|
1182
1979
|
* @experimental
|
|
1183
1980
|
*/
|
|
@@ -1189,6 +1986,12 @@ derive: {
|
|
|
1189
1986
|
readonly [K in keyof Fields]: (s: S["Type"]) => Option_.Option<Fields[K]["Type"]>;
|
|
1190
1987
|
}): (self: S) => decodeTo<Struct<Simplify<{ [K in keyof S["fields"]]: toType<S["fields"][K]>; } & Fields>>, S>;
|
|
1191
1988
|
/**
|
|
1989
|
+
* Namespace for `Record` type utilities.
|
|
1990
|
+
*
|
|
1991
|
+
* - `Record.Key` — constraint for the key schema (must encode to `PropertyKey`)
|
|
1992
|
+
* - `Record.Type<K, V>` — decoded type of the record
|
|
1993
|
+
* - `Record.Encoded<K, V>` — encoded type of the record
|
|
1994
|
+
*
|
|
1192
1995
|
* @since 4.0.0
|
|
1193
1996
|
*/
|
|
1194
1997
|
export declare namespace Record {
|
|
@@ -1281,6 +2084,9 @@ export declare namespace Record {
|
|
|
1281
2084
|
};
|
|
1282
2085
|
}
|
|
1283
2086
|
/**
|
|
2087
|
+
* Schema type for a key-value record (map) with a typed key and value schema.
|
|
2088
|
+
* Produced by {@link Record}.
|
|
2089
|
+
*
|
|
1284
2090
|
* @since 4.0.0
|
|
1285
2091
|
*/
|
|
1286
2092
|
export interface $Record<Key extends Record.Key, Value extends Top> extends Bottom<Record.Type<Key, Value>, Record.Encoded<Key, Value>, Record.DecodingServices<Key, Value>, Record.EncodingServices<Key, Value>, AST.Objects, $Record<Key, Value>, Simplify<Record.MakeIn<Key, Value>>, Record.Iso<Key, Value>> {
|
|
@@ -1289,6 +2095,24 @@ export interface $Record<Key extends Record.Key, Value extends Top> extends Bott
|
|
|
1289
2095
|
readonly value: Value;
|
|
1290
2096
|
}
|
|
1291
2097
|
/**
|
|
2098
|
+
* Defines a record (dictionary) schema with typed keys and values.
|
|
2099
|
+
*
|
|
2100
|
+
* **Example** (String-keyed record of numbers)
|
|
2101
|
+
*
|
|
2102
|
+
* ```ts
|
|
2103
|
+
* import { Schema } from "effect"
|
|
2104
|
+
*
|
|
2105
|
+
* const schema = Schema.Record(Schema.String, Schema.Number)
|
|
2106
|
+
*
|
|
2107
|
+
* // { readonly [x: string]: number }
|
|
2108
|
+
* type R = typeof schema.Type
|
|
2109
|
+
*
|
|
2110
|
+
* const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
|
|
2111
|
+
* console.log(result)
|
|
2112
|
+
* // { a: 1, b: 2 }
|
|
2113
|
+
* ```
|
|
2114
|
+
*
|
|
2115
|
+
* @category Constructors
|
|
1292
2116
|
* @since 4.0.0
|
|
1293
2117
|
*/
|
|
1294
2118
|
export declare function Record<Key extends Record.Key, Value extends Top>(key: Key, value: Value, options?: {
|
|
@@ -1298,6 +2122,11 @@ export declare function Record<Key extends Record.Key, Value extends Top>(key: K
|
|
|
1298
2122
|
};
|
|
1299
2123
|
}): $Record<Key, Value>;
|
|
1300
2124
|
/**
|
|
2125
|
+
* Namespace for `StructWithRest` type utilities.
|
|
2126
|
+
*
|
|
2127
|
+
* - `StructWithRest.Type<S, R>` — decoded type (struct type intersected with record types)
|
|
2128
|
+
* - `StructWithRest.Encoded<S, R>` — encoded type
|
|
2129
|
+
*
|
|
1301
2130
|
* @since 4.0.0
|
|
1302
2131
|
*/
|
|
1303
2132
|
export declare namespace StructWithRest {
|
|
@@ -1350,6 +2179,9 @@ export declare namespace StructWithRest {
|
|
|
1350
2179
|
}>;
|
|
1351
2180
|
}
|
|
1352
2181
|
/**
|
|
2182
|
+
* Schema type for a struct combined with one or more record schemas. Produced
|
|
2183
|
+
* by {@link StructWithRest}.
|
|
2184
|
+
*
|
|
1353
2185
|
* @since 4.0.0
|
|
1354
2186
|
*/
|
|
1355
2187
|
export interface StructWithRest<S extends StructWithRest.Objects, Records extends StructWithRest.Records> extends Bottom<Simplify<StructWithRest.Type<S, Records>>, Simplify<StructWithRest.Encoded<S, Records>>, StructWithRest.DecodingServices<S, Records>, StructWithRest.EncodingServices<S, Records>, AST.Objects, StructWithRest<S, Records>, Simplify<StructWithRest.MakeIn<S, Records>>, Simplify<StructWithRest.Iso<S, Records>>> {
|
|
@@ -1358,10 +2190,35 @@ export interface StructWithRest<S extends StructWithRest.Objects, Records extend
|
|
|
1358
2190
|
readonly records: Records;
|
|
1359
2191
|
}
|
|
1360
2192
|
/**
|
|
2193
|
+
* Extends a struct schema with one or more record (index-signature) schemas,
|
|
2194
|
+
* producing a schema whose decoded type intersects the struct and all records.
|
|
2195
|
+
*
|
|
2196
|
+
* **Example** (Struct with string-indexed extra keys)
|
|
2197
|
+
*
|
|
2198
|
+
* ```ts
|
|
2199
|
+
* import { Schema } from "effect"
|
|
2200
|
+
*
|
|
2201
|
+
* const schema = Schema.StructWithRest(
|
|
2202
|
+
* Schema.Struct({ id: Schema.Number }),
|
|
2203
|
+
* [Schema.Record(Schema.String, Schema.String)]
|
|
2204
|
+
* )
|
|
2205
|
+
*
|
|
2206
|
+
* // { readonly id: number } & { readonly [x: string]: string }
|
|
2207
|
+
* type T = typeof schema.Type
|
|
2208
|
+
* ```
|
|
2209
|
+
*
|
|
2210
|
+
* @category Constructors
|
|
1361
2211
|
* @since 4.0.0
|
|
1362
2212
|
*/
|
|
1363
2213
|
export declare function StructWithRest<const S extends StructWithRest.Objects, const Records extends StructWithRest.Records>(schema: S, records: Records): StructWithRest<S, Records>;
|
|
1364
2214
|
/**
|
|
2215
|
+
* Namespace for `Tuple` type utilities.
|
|
2216
|
+
*
|
|
2217
|
+
* - `Tuple.Elements` — constraint for the element schema array
|
|
2218
|
+
* - `Tuple.Type<E>` — decoded tuple type
|
|
2219
|
+
* - `Tuple.Encoded<E>` — encoded tuple type
|
|
2220
|
+
* - `Tuple.MakeIn<E>` — constructor input tuple
|
|
2221
|
+
*
|
|
1365
2222
|
* @since 4.0.0
|
|
1366
2223
|
*/
|
|
1367
2224
|
export declare namespace Tuple {
|
|
@@ -1417,6 +2274,8 @@ export declare namespace Tuple {
|
|
|
1417
2274
|
type MakeIn<E extends Elements> = MakeIn_<E>;
|
|
1418
2275
|
}
|
|
1419
2276
|
/**
|
|
2277
|
+
* Schema type for a fixed-length tuple. Produced by {@link Tuple}.
|
|
2278
|
+
*
|
|
1420
2279
|
* @since 4.0.0
|
|
1421
2280
|
*/
|
|
1422
2281
|
export interface Tuple<Elements extends Tuple.Elements> extends Bottom<Tuple.Type<Elements>, Tuple.Encoded<Elements>, Tuple.DecodingServices<Elements>, Tuple.EncodingServices<Elements>, AST.Arrays, Tuple<Elements>, Tuple.MakeIn<Elements>, Tuple.Iso<Elements>> {
|
|
@@ -1441,11 +2300,32 @@ export interface Tuple<Elements extends Tuple.Elements> extends Bottom<Tuple.Typ
|
|
|
1441
2300
|
} | undefined): Tuple<Simplify<Readonly<To>>>;
|
|
1442
2301
|
}
|
|
1443
2302
|
/**
|
|
2303
|
+
* Defines a fixed-length tuple schema from an array of element schemas.
|
|
2304
|
+
*
|
|
2305
|
+
* **Example** (Pair of string and number)
|
|
2306
|
+
*
|
|
2307
|
+
* ```ts
|
|
2308
|
+
* import { Schema } from "effect"
|
|
2309
|
+
*
|
|
2310
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
2311
|
+
*
|
|
2312
|
+
* const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
|
|
2313
|
+
* console.log(pair)
|
|
2314
|
+
* // [ 'hello', 42 ]
|
|
2315
|
+
* ```
|
|
2316
|
+
*
|
|
1444
2317
|
* @category Constructors
|
|
1445
2318
|
* @since 4.0.0
|
|
1446
2319
|
*/
|
|
1447
2320
|
export declare function Tuple<const Elements extends ReadonlyArray<Top>>(elements: Elements): Tuple<Elements>;
|
|
1448
2321
|
/**
|
|
2322
|
+
* Namespace for `TupleWithRest` type utilities.
|
|
2323
|
+
*
|
|
2324
|
+
* - `TupleWithRest.TupleType` — constraint for the leading tuple schema
|
|
2325
|
+
* - `TupleWithRest.Rest` — the rest element schema(s)
|
|
2326
|
+
* - `TupleWithRest.Type<T, R>` — decoded type (fixed elements + rest)
|
|
2327
|
+
* - `TupleWithRest.Encoded<T, R>` — encoded type
|
|
2328
|
+
*
|
|
1449
2329
|
* @since 4.0.0
|
|
1450
2330
|
*/
|
|
1451
2331
|
export declare namespace TupleWithRest {
|
|
@@ -1505,6 +2385,9 @@ export declare namespace TupleWithRest {
|
|
|
1505
2385
|
] : M;
|
|
1506
2386
|
}
|
|
1507
2387
|
/**
|
|
2388
|
+
* Schema type for a tuple with additional rest elements. Produced by
|
|
2389
|
+
* {@link TupleWithRest}.
|
|
2390
|
+
*
|
|
1508
2391
|
* @since 4.0.0
|
|
1509
2392
|
*/
|
|
1510
2393
|
export interface TupleWithRest<S extends TupleWithRest.TupleType, Rest extends TupleWithRest.Rest> extends Bottom<TupleWithRest.Type<S["Type"], Rest>, TupleWithRest.Encoded<S["Encoded"], Rest>, S["DecodingServices"] | Rest[number]["DecodingServices"], S["EncodingServices"] | Rest[number]["EncodingServices"], AST.Arrays, TupleWithRest<S, Rest>, TupleWithRest.MakeIn<S["~type.make"], Rest>, TupleWithRest.Iso<S["Iso"], Rest>> {
|
|
@@ -1513,11 +2396,33 @@ export interface TupleWithRest<S extends TupleWithRest.TupleType, Rest extends T
|
|
|
1513
2396
|
readonly rest: Rest;
|
|
1514
2397
|
}
|
|
1515
2398
|
/**
|
|
2399
|
+
* Extends a fixed-length tuple schema with rest elements, creating a variadic
|
|
2400
|
+
* tuple that starts with the fixed elements and ends with zero or more rest
|
|
2401
|
+
* elements.
|
|
2402
|
+
*
|
|
2403
|
+
* **Example** (Tuple with rest)
|
|
2404
|
+
*
|
|
2405
|
+
* ```ts
|
|
2406
|
+
* import { Schema } from "effect"
|
|
2407
|
+
*
|
|
2408
|
+
* // [string, number, ...boolean[]]
|
|
2409
|
+
* const schema = Schema.TupleWithRest(
|
|
2410
|
+
* Schema.Tuple([Schema.String, Schema.Number]),
|
|
2411
|
+
* [Schema.Boolean]
|
|
2412
|
+
* )
|
|
2413
|
+
*
|
|
2414
|
+
* const result = Schema.decodeUnknownSync(schema)(["hello", 1, true, false])
|
|
2415
|
+
* console.log(result)
|
|
2416
|
+
* // [ 'hello', 1, true, false ]
|
|
2417
|
+
* ```
|
|
2418
|
+
*
|
|
1516
2419
|
* @category Constructors
|
|
1517
2420
|
* @since 4.0.0
|
|
1518
2421
|
*/
|
|
1519
2422
|
export declare function TupleWithRest<S extends Tuple<Tuple.Elements>, const Rest extends TupleWithRest.Rest>(schema: S, rest: Rest): TupleWithRest<S, Rest>;
|
|
1520
2423
|
/**
|
|
2424
|
+
* Schema type for a `ReadonlyArray`. Produced by {@link Array}.
|
|
2425
|
+
*
|
|
1521
2426
|
* @since 4.0.0
|
|
1522
2427
|
*/
|
|
1523
2428
|
export interface $Array<S extends Top> extends Bottom<ReadonlyArray<S["Type"]>, ReadonlyArray<S["Encoded"]>, S["DecodingServices"], S["EncodingServices"], AST.Arrays, $Array<S>, ReadonlyArray<S["~type.make"]>, ReadonlyArray<S["Iso"]>> {
|
|
@@ -1529,11 +2434,27 @@ interface ArrayLambda extends Lambda {
|
|
|
1529
2434
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? $Array<this["~lambda.in"]> : never;
|
|
1530
2435
|
}
|
|
1531
2436
|
/**
|
|
2437
|
+
* Defines a `ReadonlyArray` schema for a given element schema.
|
|
2438
|
+
*
|
|
2439
|
+
* **Example** (Array of strings)
|
|
2440
|
+
*
|
|
2441
|
+
* ```ts
|
|
2442
|
+
* import { Schema } from "effect"
|
|
2443
|
+
*
|
|
2444
|
+
* const schema = Schema.Array(Schema.String)
|
|
2445
|
+
*
|
|
2446
|
+
* const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
|
|
2447
|
+
* console.log(result)
|
|
2448
|
+
* // [ 'a', 'b', 'c' ]
|
|
2449
|
+
* ```
|
|
2450
|
+
*
|
|
1532
2451
|
* @category Constructors
|
|
1533
2452
|
* @since 4.0.0
|
|
1534
2453
|
*/
|
|
1535
2454
|
export declare const Array: ArrayLambda;
|
|
1536
2455
|
/**
|
|
2456
|
+
* Schema type for a non-empty `ReadonlyArray`. Produced by {@link NonEmptyArray}.
|
|
2457
|
+
*
|
|
1537
2458
|
* @since 4.0.0
|
|
1538
2459
|
*/
|
|
1539
2460
|
export interface NonEmptyArray<S extends Top> extends Bottom<readonly [S["Type"], ...Array<S["Type"]>], readonly [S["Encoded"], ...Array<S["Encoded"]>], S["DecodingServices"], S["EncodingServices"], AST.Arrays, NonEmptyArray<S>, readonly [S["~type.make"], ...Array<S["~type.make"]>], readonly [S["Iso"], ...Array<S["Iso"]>]> {
|
|
@@ -1545,11 +2466,27 @@ interface NonEmptyArrayLambda extends Lambda {
|
|
|
1545
2466
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? NonEmptyArray<this["~lambda.in"]> : never;
|
|
1546
2467
|
}
|
|
1547
2468
|
/**
|
|
2469
|
+
* Defines a non-empty `ReadonlyArray` schema — at least one element required.
|
|
2470
|
+
* Type is `readonly [T, ...T[]]`.
|
|
2471
|
+
*
|
|
2472
|
+
* **Example** (Non-empty array of numbers)
|
|
2473
|
+
*
|
|
2474
|
+
* ```ts
|
|
2475
|
+
* import { Schema } from "effect"
|
|
2476
|
+
*
|
|
2477
|
+
* const schema = Schema.NonEmptyArray(Schema.Number)
|
|
2478
|
+
*
|
|
2479
|
+
* Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
|
|
2480
|
+
* Schema.decodeUnknownSync(schema)([]) // throws
|
|
2481
|
+
* ```
|
|
2482
|
+
*
|
|
1548
2483
|
* @category Constructors
|
|
1549
2484
|
* @since 4.0.0
|
|
1550
2485
|
*/
|
|
1551
2486
|
export declare const NonEmptyArray: NonEmptyArrayLambda;
|
|
1552
2487
|
/**
|
|
2488
|
+
* Schema type for an array with unique elements. Produced by {@link UniqueArray}.
|
|
2489
|
+
*
|
|
1553
2490
|
* @since 4.0.0
|
|
1554
2491
|
*/
|
|
1555
2492
|
export interface UniqueArray<S extends Top> extends $Array<S> {
|
|
@@ -1565,6 +2502,9 @@ export interface UniqueArray<S extends Top> extends $Array<S> {
|
|
|
1565
2502
|
*/
|
|
1566
2503
|
export declare function UniqueArray<S extends Top>(item: S): UniqueArray<S>;
|
|
1567
2504
|
/**
|
|
2505
|
+
* Schema type that makes array or tuple elements mutable (removes `readonly`).
|
|
2506
|
+
* Produced by {@link mutable}.
|
|
2507
|
+
*
|
|
1568
2508
|
* @since 4.0.0
|
|
1569
2509
|
*/
|
|
1570
2510
|
export interface mutable<S extends Top & {
|
|
@@ -1582,12 +2522,25 @@ interface mutableLambda extends Lambda {
|
|
|
1582
2522
|
} ? mutable<this["~lambda.in"]> : "Error: schema not eligible for mutable";
|
|
1583
2523
|
}
|
|
1584
2524
|
/**
|
|
1585
|
-
* Makes
|
|
2525
|
+
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
|
|
2526
|
+
*
|
|
2527
|
+
* **Example** (Mutable array)
|
|
2528
|
+
*
|
|
2529
|
+
* ```ts
|
|
2530
|
+
* import { Schema } from "effect"
|
|
2531
|
+
*
|
|
2532
|
+
* const schema = Schema.mutable(Schema.Array(Schema.Number))
|
|
2533
|
+
*
|
|
2534
|
+
* // number[] (mutable)
|
|
2535
|
+
* type T = typeof schema.Type
|
|
2536
|
+
* ```
|
|
1586
2537
|
*
|
|
1587
2538
|
* @since 4.0.0
|
|
1588
2539
|
*/
|
|
1589
2540
|
export declare const mutable: mutableLambda;
|
|
1590
2541
|
/**
|
|
2542
|
+
* Schema type for a union of multiple schemas. Produced by {@link Union}.
|
|
2543
|
+
*
|
|
1591
2544
|
* @since 4.0.0
|
|
1592
2545
|
*/
|
|
1593
2546
|
export interface Union<Members extends ReadonlyArray<Top>> extends Bottom<{
|
|
@@ -1626,12 +2579,23 @@ export interface Union<Members extends ReadonlyArray<Top>> extends Bottom<{
|
|
|
1626
2579
|
} | undefined): Union<Simplify<Readonly<To>>>;
|
|
1627
2580
|
}
|
|
1628
2581
|
/**
|
|
1629
|
-
* Creates a schema
|
|
2582
|
+
* Creates a union schema from an array of member schemas. Members are tested in
|
|
2583
|
+
* order; the first match is returned.
|
|
2584
|
+
*
|
|
2585
|
+
* Optionally, specify `mode`:
|
|
2586
|
+
* - `"anyOf"` (default) — matches if any member matches.
|
|
2587
|
+
* - `"oneOf"` — matches if exactly one member matches.
|
|
1630
2588
|
*
|
|
1631
|
-
*
|
|
2589
|
+
* **Example** (String or number union)
|
|
1632
2590
|
*
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
2591
|
+
* ```ts
|
|
2592
|
+
* import { Schema } from "effect"
|
|
2593
|
+
*
|
|
2594
|
+
* const schema = Schema.Union([Schema.String, Schema.Number])
|
|
2595
|
+
*
|
|
2596
|
+
* Schema.decodeUnknownSync(schema)("hello") // "hello"
|
|
2597
|
+
* Schema.decodeUnknownSync(schema)(42) // 42
|
|
2598
|
+
* ```
|
|
1635
2599
|
*
|
|
1636
2600
|
* @category Constructors
|
|
1637
2601
|
* @since 4.0.0
|
|
@@ -1640,6 +2604,9 @@ export declare function Union<const Members extends ReadonlyArray<Top>>(members:
|
|
|
1640
2604
|
mode?: "anyOf" | "oneOf";
|
|
1641
2605
|
}): Union<Members>;
|
|
1642
2606
|
/**
|
|
2607
|
+
* Represents a union schema of multiple literal values.
|
|
2608
|
+
*
|
|
2609
|
+
* @see {@link Literals} for the constructor function.
|
|
1643
2610
|
* @since 4.0.0
|
|
1644
2611
|
*/
|
|
1645
2612
|
export interface Literals<L extends ReadonlyArray<AST.LiteralValue>> extends Bottom<L[number], L[number], never, never, AST.Union<AST.Literal>, Literals<L>> {
|
|
@@ -1660,12 +2627,24 @@ export interface Literals<L extends ReadonlyArray<AST.LiteralValue>> extends Bot
|
|
|
1660
2627
|
}>;
|
|
1661
2628
|
}
|
|
1662
2629
|
/**
|
|
2630
|
+
* Creates a union schema from an array of literal values.
|
|
2631
|
+
*
|
|
2632
|
+
* **Example** (Status codes)
|
|
2633
|
+
* ```ts
|
|
2634
|
+
* import { Schema } from "effect"
|
|
2635
|
+
*
|
|
2636
|
+
* const schema = Schema.Literals(["active", "inactive", "pending"])
|
|
2637
|
+
* // accepts "active", "inactive", or "pending"
|
|
2638
|
+
* ```
|
|
2639
|
+
*
|
|
1663
2640
|
* @see {@link Literal} for a schema that represents a single literal.
|
|
1664
2641
|
* @category Constructors
|
|
1665
2642
|
* @since 4.0.0
|
|
1666
2643
|
*/
|
|
1667
2644
|
export declare function Literals<const L extends ReadonlyArray<AST.LiteralValue>>(literals: L): Literals<L>;
|
|
1668
2645
|
/**
|
|
2646
|
+
* Schema type for `S | null`. Produced by {@link NullOr}.
|
|
2647
|
+
*
|
|
1669
2648
|
* @since 4.0.0
|
|
1670
2649
|
*/
|
|
1671
2650
|
export interface NullOr<S extends Top> extends Union<readonly [S, Null]> {
|
|
@@ -1675,11 +2654,15 @@ interface NullOrLambda extends Lambda {
|
|
|
1675
2654
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? NullOr<this["~lambda.in"]> : never;
|
|
1676
2655
|
}
|
|
1677
2656
|
/**
|
|
2657
|
+
* Creates a union schema of `S | null`.
|
|
2658
|
+
*
|
|
1678
2659
|
* @category Constructors
|
|
1679
2660
|
* @since 4.0.0
|
|
1680
2661
|
*/
|
|
1681
2662
|
export declare const NullOr: NullOrLambda;
|
|
1682
2663
|
/**
|
|
2664
|
+
* Schema type for `S | undefined`. Produced by {@link UndefinedOr}.
|
|
2665
|
+
*
|
|
1683
2666
|
* @since 4.0.0
|
|
1684
2667
|
*/
|
|
1685
2668
|
export interface UndefinedOr<S extends Top> extends Union<readonly [S, Undefined]> {
|
|
@@ -1689,11 +2672,14 @@ interface UndefinedOrLambda extends Lambda {
|
|
|
1689
2672
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? UndefinedOr<this["~lambda.in"]> : never;
|
|
1690
2673
|
}
|
|
1691
2674
|
/**
|
|
2675
|
+
* Creates a union schema of `S | undefined`.
|
|
2676
|
+
*
|
|
1692
2677
|
* @category Constructors
|
|
1693
2678
|
* @since 4.0.0
|
|
1694
2679
|
*/
|
|
1695
2680
|
export declare const UndefinedOr: UndefinedOrLambda;
|
|
1696
2681
|
/**
|
|
2682
|
+
* Schema type for `S | null | undefined`. Produced by {@link NullishOr}.
|
|
1697
2683
|
* @since 4.0.0
|
|
1698
2684
|
*/
|
|
1699
2685
|
export interface NullishOr<S extends Top> extends Union<readonly [S, Null, Undefined]> {
|
|
@@ -1703,11 +2689,13 @@ interface NullishOrLambda extends Lambda {
|
|
|
1703
2689
|
readonly "~lambda.out": this["~lambda.in"] extends Top ? NullishOr<this["~lambda.in"]> : never;
|
|
1704
2690
|
}
|
|
1705
2691
|
/**
|
|
2692
|
+
* Creates a union schema of `S | null | undefined`.
|
|
1706
2693
|
* @category Constructors
|
|
1707
2694
|
* @since 4.0.0
|
|
1708
2695
|
*/
|
|
1709
2696
|
export declare const NullishOr: NullishOrLambda;
|
|
1710
2697
|
/**
|
|
2698
|
+
* Schema type wrapping a lazily-evaluated schema. Produced by {@link suspend}.
|
|
1711
2699
|
* @since 4.0.0
|
|
1712
2700
|
*/
|
|
1713
2701
|
export interface suspend<S extends Top> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], AST.Suspend, suspend<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1718,16 +2706,46 @@ export interface suspend<S extends Top> extends Bottom<S["Type"], S["Encoded"],
|
|
|
1718
2706
|
* essential for creating recursive schemas where a schema references itself,
|
|
1719
2707
|
* preventing infinite recursion during schema definition.
|
|
1720
2708
|
*
|
|
2709
|
+
* **Example** (Recursive tree schema)
|
|
2710
|
+
* ```ts
|
|
2711
|
+
* import { Schema } from "effect"
|
|
2712
|
+
*
|
|
2713
|
+
* interface Tree {
|
|
2714
|
+
* readonly value: number
|
|
2715
|
+
* readonly children: ReadonlyArray<Tree>
|
|
2716
|
+
* }
|
|
2717
|
+
*
|
|
2718
|
+
* const Tree = Schema.Struct({
|
|
2719
|
+
* value: Schema.Number,
|
|
2720
|
+
* children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
|
|
2721
|
+
* })
|
|
2722
|
+
* ```
|
|
2723
|
+
*
|
|
1721
2724
|
* @category Constructors
|
|
1722
2725
|
* @since 4.0.0
|
|
1723
2726
|
*/
|
|
1724
2727
|
export declare function suspend<S extends Top>(f: () => S): suspend<S>;
|
|
1725
2728
|
/**
|
|
2729
|
+
* Pipeable function that attaches one or more filter checks to a schema without
|
|
2730
|
+
* changing the TypeScript type.
|
|
2731
|
+
*
|
|
2732
|
+
* **Example** (Adding checks to a schema)
|
|
2733
|
+
* ```ts
|
|
2734
|
+
* import { Schema } from "effect"
|
|
2735
|
+
*
|
|
2736
|
+
* const AgeSchema = Schema.Number.pipe(
|
|
2737
|
+
* Schema.check(Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(120))
|
|
2738
|
+
* )
|
|
2739
|
+
* ```
|
|
2740
|
+
*
|
|
1726
2741
|
* @category Filtering
|
|
1727
2742
|
* @since 4.0.0
|
|
1728
2743
|
*/
|
|
1729
2744
|
export declare function check<S extends Top>(...checks: readonly [AST.Check<S["Type"]>, ...Array<AST.Check<S["Type"]>>]): (self: S) => S["~rebuild.out"];
|
|
1730
2745
|
/**
|
|
2746
|
+
* The output type of {@link refine}, narrowing the schema's `Type` to `T` via a
|
|
2747
|
+
* type guard.
|
|
2748
|
+
*
|
|
1731
2749
|
* @since 4.0.0
|
|
1732
2750
|
*/
|
|
1733
2751
|
export interface refine<T extends S["Type"], S extends Top> extends Bottom<T, S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], refine<T, S>, S["~type.make.in"], T, S["~type.parameters"], T, S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1735,12 +2753,18 @@ export interface refine<T extends S["Type"], S extends Top> extends Bottom<T, S[
|
|
|
1735
2753
|
readonly schema: S;
|
|
1736
2754
|
}
|
|
1737
2755
|
/**
|
|
2756
|
+
* Narrows the TypeScript type of a schema's output via a type guard predicate,
|
|
2757
|
+
* attaching the guard as a runtime filter check.
|
|
2758
|
+
*
|
|
1738
2759
|
* @category Filtering
|
|
1739
2760
|
* @since 4.0.0
|
|
1740
2761
|
*/
|
|
1741
2762
|
export declare function refine<S extends Top, T extends S["Type"]>(refinement: (value: S["Type"]) => value is T, annotations?: Annotations.Filter): (schema: S) => refine<T, S>;
|
|
1742
2763
|
type DistributeBrands<B> = UnionToIntersection<B extends infer U extends string ? Brand.Brand<U> : never>;
|
|
1743
2764
|
/**
|
|
2765
|
+
* The output type of {@link brand}, intersecting the schema's `Type` with one or
|
|
2766
|
+
* more {@link Brand.Brand} tags.
|
|
2767
|
+
*
|
|
1744
2768
|
* @since 4.0.0
|
|
1745
2769
|
*/
|
|
1746
2770
|
export interface brand<S extends Top, B> extends Bottom<S["Type"] & DistributeBrands<B>, S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], brand<S, B>, S["~type.make.in"], S["Type"] & DistributeBrands<B>, S["~type.parameters"], S["Type"] & DistributeBrands<B>, S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1749,20 +2773,30 @@ export interface brand<S extends Top, B> extends Bottom<S["Type"] & DistributeBr
|
|
|
1749
2773
|
readonly identifier: string;
|
|
1750
2774
|
}
|
|
1751
2775
|
/**
|
|
1752
|
-
* Adds a brand to a schema
|
|
2776
|
+
* Adds a nominal brand to a schema, intersecting the output type with
|
|
2777
|
+
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
1753
2778
|
*
|
|
1754
2779
|
* @category Branding
|
|
1755
2780
|
* @since 4.0.0
|
|
1756
2781
|
*/
|
|
1757
2782
|
export declare function brand<B extends string>(identifier: B): <S extends Top>(schema: S) => brand<S["~rebuild.out"], B>;
|
|
1758
2783
|
/**
|
|
1759
|
-
* @
|
|
2784
|
+
* Creates a branded schema from a {@link Brand.Constructor}, applying the
|
|
2785
|
+
* constructor's checks and brand tag to the underlying schema.
|
|
2786
|
+
*
|
|
2787
|
+
* @category Branding
|
|
1760
2788
|
* @since 4.0.0
|
|
1761
2789
|
*/
|
|
1762
2790
|
export declare function fromBrand<A extends Brand.Brand<any>>(identifier: string, ctor: Brand.Constructor<A>): <S extends Top & {
|
|
1763
2791
|
readonly "Type": Brand.Brand.Unbranded<A>;
|
|
1764
2792
|
}>(self: S) => brand<S["~rebuild.out"], Brand.Brand.Keys<A>>;
|
|
1765
2793
|
/**
|
|
2794
|
+
* A schema that wraps another schema and intercepts its decoding pipeline.
|
|
2795
|
+
*
|
|
2796
|
+
* The interceptor receives the full decoding `Effect` and may replace, modify,
|
|
2797
|
+
* or augment it — including adding service requirements via `RD`.
|
|
2798
|
+
*
|
|
2799
|
+
* @see {@link middlewareDecoding} for the constructor
|
|
1766
2800
|
* @since 4.0.0
|
|
1767
2801
|
*/
|
|
1768
2802
|
export interface middlewareDecoding<S extends Top, RD> extends Bottom<S["Type"], S["Encoded"], RD, S["EncodingServices"], S["ast"], middlewareDecoding<S, RD>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1770,10 +2804,35 @@ export interface middlewareDecoding<S extends Top, RD> extends Bottom<S["Type"],
|
|
|
1770
2804
|
readonly schema: S;
|
|
1771
2805
|
}
|
|
1772
2806
|
/**
|
|
2807
|
+
* Intercepts the decoding pipeline of a schema.
|
|
2808
|
+
*
|
|
2809
|
+
* The provided function receives the current decoding `Effect` and `ParseOptions`,
|
|
2810
|
+
* and returns a new `Effect` — potentially adding service requirements (`RD`),
|
|
2811
|
+
* recovering from errors, or augmenting the result.
|
|
2812
|
+
*
|
|
2813
|
+
* **Example** (Logging decode failures)
|
|
2814
|
+
*
|
|
2815
|
+
* ```ts
|
|
2816
|
+
* import { Effect, Schema } from "effect"
|
|
2817
|
+
*
|
|
2818
|
+
* const Logged = Schema.String.pipe(
|
|
2819
|
+
* Schema.middlewareDecoding((effect) =>
|
|
2820
|
+
* Effect.tapError(effect, (issue) => Effect.log("decode failed", issue))
|
|
2821
|
+
* )
|
|
2822
|
+
* )
|
|
2823
|
+
* ```
|
|
2824
|
+
*
|
|
2825
|
+
* @see {@link catchDecoding} for a simpler error-recovery variant
|
|
1773
2826
|
* @since 4.0.0
|
|
1774
2827
|
*/
|
|
1775
2828
|
export declare function middlewareDecoding<S extends Top, RD>(decode: (effect: Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue, S["DecodingServices"]>, options: AST.ParseOptions) => Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue, RD>): (schema: S) => middlewareDecoding<S, RD>;
|
|
1776
2829
|
/**
|
|
2830
|
+
* A schema that wraps another schema and intercepts its encoding pipeline.
|
|
2831
|
+
*
|
|
2832
|
+
* The interceptor receives the full encoding `Effect` and may replace, modify,
|
|
2833
|
+
* or augment it — including adding service requirements via `RE`.
|
|
2834
|
+
*
|
|
2835
|
+
* @see {@link middlewareEncoding} for the constructor
|
|
1777
2836
|
* @since 4.0.0
|
|
1778
2837
|
*/
|
|
1779
2838
|
export interface middlewareEncoding<S extends Top, RE> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], RE, S["ast"], middlewareEncoding<S, RE>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1781,26 +2840,77 @@ export interface middlewareEncoding<S extends Top, RE> extends Bottom<S["Type"],
|
|
|
1781
2840
|
readonly schema: S;
|
|
1782
2841
|
}
|
|
1783
2842
|
/**
|
|
2843
|
+
* Intercepts the encoding pipeline of a schema.
|
|
2844
|
+
*
|
|
2845
|
+
* The provided function receives the current encoding `Effect` and `ParseOptions`,
|
|
2846
|
+
* and returns a new `Effect` — potentially adding service requirements (`RE`),
|
|
2847
|
+
* recovering from errors, or augmenting the result.
|
|
2848
|
+
*
|
|
2849
|
+
* **Example** (Logging encode failures)
|
|
2850
|
+
*
|
|
2851
|
+
* ```ts
|
|
2852
|
+
* import { Effect, Schema } from "effect"
|
|
2853
|
+
*
|
|
2854
|
+
* const Logged = Schema.String.pipe(
|
|
2855
|
+
* Schema.middlewareEncoding((effect) =>
|
|
2856
|
+
* Effect.tapError(effect, (issue) => Effect.log("encode failed", issue))
|
|
2857
|
+
* )
|
|
2858
|
+
* )
|
|
2859
|
+
* ```
|
|
2860
|
+
*
|
|
2861
|
+
* @see {@link catchEncoding} for a simpler error-recovery variant
|
|
1784
2862
|
* @since 4.0.0
|
|
1785
2863
|
*/
|
|
1786
2864
|
export declare function middlewareEncoding<S extends Top, RE>(encode: (effect: Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue, S["EncodingServices"]>, options: AST.ParseOptions) => Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue, RE>): (schema: S) => middlewareEncoding<S, RE>;
|
|
1787
2865
|
/**
|
|
2866
|
+
* Recovers from a decoding error by providing a fallback value.
|
|
2867
|
+
*
|
|
2868
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
2869
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
2870
|
+
*
|
|
2871
|
+
* **Example** (Returning a default on decode failure)
|
|
2872
|
+
*
|
|
2873
|
+
* ```ts
|
|
2874
|
+
* import { Effect, Option, Schema } from "effect"
|
|
2875
|
+
*
|
|
2876
|
+
* const schema = Schema.Number.pipe(
|
|
2877
|
+
* Schema.catchDecoding((_issue) => Effect.succeed(Option.some(0)))
|
|
2878
|
+
* )
|
|
2879
|
+
* ```
|
|
2880
|
+
*
|
|
2881
|
+
* @see {@link catchDecodingWithContext} to add service requirements to the handler
|
|
1788
2882
|
* @since 4.0.0
|
|
1789
2883
|
*/
|
|
1790
2884
|
export declare function catchDecoding<S extends Top>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue>): (self: S) => S["~rebuild.out"];
|
|
1791
2885
|
/**
|
|
2886
|
+
* Like {@link catchDecoding}, but the handler may require Effect services (`R`).
|
|
2887
|
+
*
|
|
1792
2888
|
* @since 4.0.0
|
|
1793
2889
|
*/
|
|
1794
2890
|
export declare function catchDecodingWithContext<S extends Top, R = never>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Type"]>, Issue.Issue, R>): (self: S) => middlewareDecoding<S, S["DecodingServices"] | R>;
|
|
1795
2891
|
/**
|
|
2892
|
+
* Recovers from an encoding error by providing a fallback value.
|
|
2893
|
+
*
|
|
2894
|
+
* The handler receives the `Issue` and returns an `Effect` that either
|
|
2895
|
+
* succeeds with a fallback value or re-fails with a (possibly different) issue.
|
|
2896
|
+
*
|
|
2897
|
+
* @see {@link catchEncodingWithContext} to add service requirements to the handler
|
|
1796
2898
|
* @since 4.0.0
|
|
1797
2899
|
*/
|
|
1798
2900
|
export declare function catchEncoding<S extends Top>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue>): (self: S) => S["~rebuild.out"];
|
|
1799
2901
|
/**
|
|
2902
|
+
* Like {@link catchEncoding}, but the handler may require Effect services (`R`).
|
|
2903
|
+
*
|
|
1800
2904
|
* @since 4.0.0
|
|
1801
2905
|
*/
|
|
1802
2906
|
export declare function catchEncodingWithContext<S extends Top, R = never>(f: (issue: Issue.Issue) => Effect.Effect<Option_.Option<S["Encoded"]>, Issue.Issue, R>): (self: S) => middlewareEncoding<S, S["EncodingServices"] | R>;
|
|
1803
2907
|
/**
|
|
2908
|
+
* The type produced by {@link decodeTo} when a custom transformation is provided.
|
|
2909
|
+
*
|
|
2910
|
+
* - `Type` is `To["Type"]`, `Encoded` is `From["Encoded"]`
|
|
2911
|
+
* - Decoding services from both `from` and `to` are combined
|
|
2912
|
+
*
|
|
2913
|
+
* @see {@link compose} for the passthrough (no transformation) variant
|
|
1804
2914
|
* @since 4.0.0
|
|
1805
2915
|
*/
|
|
1806
2916
|
export interface decodeTo<To extends Top, From extends Top, RD = never, RE = never> extends Bottom<To["Type"], From["Encoded"], To["DecodingServices"] | From["DecodingServices"] | RD, To["EncodingServices"] | From["EncodingServices"] | RE, To["ast"], decodeTo<To, From, RD, RE>, To["~type.make.in"], To["Iso"], To["~type.parameters"], To["~type.make"], To["~type.mutability"], To["~type.optionality"], To["~type.constructor.default"], From["~encoded.mutability"], From["~encoded.optionality"]> {
|
|
@@ -1809,6 +2919,12 @@ export interface decodeTo<To extends Top, From extends Top, RD = never, RE = nev
|
|
|
1809
2919
|
readonly to: To;
|
|
1810
2920
|
}
|
|
1811
2921
|
/**
|
|
2922
|
+
* The type produced by {@link decodeTo} when called without a custom transformation (passthrough composition).
|
|
2923
|
+
*
|
|
2924
|
+
* Equivalent to {@link decodeTo} with `RD = never` and `RE = never`, meaning the schemas
|
|
2925
|
+
* are composed using their natural encoding/decoding chain.
|
|
2926
|
+
*
|
|
2927
|
+
* @see {@link decodeTo} for the transformation variant
|
|
1812
2928
|
* @since 4.0.0
|
|
1813
2929
|
*/
|
|
1814
2930
|
export interface compose<To extends Top, From extends Top> extends decodeTo<To, From> {
|
|
@@ -1902,6 +3018,25 @@ export declare function decode<S extends Top, RD = never, RE = never>(transforma
|
|
|
1902
3018
|
readonly encode: Getter.Getter<S["Type"], S["Type"], RE>;
|
|
1903
3019
|
}): (self: S) => decodeTo<toType<S>, S, RD, RE>;
|
|
1904
3020
|
/**
|
|
3021
|
+
* Like {@link decodeTo} but reverses the direction: the `from` schema acts as the target (decoded type)
|
|
3022
|
+
* and `to` acts as the encoded source.
|
|
3023
|
+
*
|
|
3024
|
+
* `encodeTo(to)(from)` is equivalent to `to.pipe(decodeTo(from))` — useful when it reads more
|
|
3025
|
+
* naturally to specify the encoded schema first.
|
|
3026
|
+
*
|
|
3027
|
+
* **Example** (Encode a number back to string)
|
|
3028
|
+
*
|
|
3029
|
+
* ```ts
|
|
3030
|
+
* import { Schema, SchemaGetter } from "effect"
|
|
3031
|
+
*
|
|
3032
|
+
* const NumberFromString = Schema.Number.pipe(
|
|
3033
|
+
* Schema.encodeTo(Schema.String, {
|
|
3034
|
+
* decode: SchemaGetter.transform((s: string) => Number(s)),
|
|
3035
|
+
* encode: SchemaGetter.transform((n: number) => String(n))
|
|
3036
|
+
* })
|
|
3037
|
+
* )
|
|
3038
|
+
* ```
|
|
3039
|
+
*
|
|
1905
3040
|
* @since 4.0.0
|
|
1906
3041
|
*/
|
|
1907
3042
|
export declare function encodeTo<To extends Top>(to: To): <From extends Top>(from: From) => decodeTo<From, To>;
|
|
@@ -1910,6 +3045,25 @@ export declare function encodeTo<To extends Top, From extends Top, RD = never, R
|
|
|
1910
3045
|
readonly encode: Getter.Getter<NoInfer<To["Type"]>, NoInfer<From["Encoded"]>, RE>;
|
|
1911
3046
|
}): (from: From) => decodeTo<From, To, RD, RE>;
|
|
1912
3047
|
/**
|
|
3048
|
+
* Applies a transformation to a schema's encoded type, creating a new schema where encoding/decoding
|
|
3049
|
+
* operate on `S["Encoded"]` rather than `S["Type"]`.
|
|
3050
|
+
*
|
|
3051
|
+
* The `decode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during decoding),
|
|
3052
|
+
* and the `encode` getter maps `S["Encoded"]` → `S["Encoded"]` (applied during encoding).
|
|
3053
|
+
*
|
|
3054
|
+
* **Example** (Upper-casing encoded strings)
|
|
3055
|
+
*
|
|
3056
|
+
* ```ts
|
|
3057
|
+
* import { Schema, SchemaGetter } from "effect"
|
|
3058
|
+
*
|
|
3059
|
+
* const UpperFromLower = Schema.String.pipe(
|
|
3060
|
+
* Schema.encode({
|
|
3061
|
+
* decode: SchemaGetter.transform((s: string) => s.toLowerCase()),
|
|
3062
|
+
* encode: SchemaGetter.transform((s: string) => s.toUpperCase())
|
|
3063
|
+
* })
|
|
3064
|
+
* )
|
|
3065
|
+
* ```
|
|
3066
|
+
*
|
|
1913
3067
|
* @since 4.0.0
|
|
1914
3068
|
*/
|
|
1915
3069
|
export declare function encode<S extends Top, RD = never, RE = never>(transformation: {
|
|
@@ -1917,12 +3071,19 @@ export declare function encode<S extends Top, RD = never, RE = never>(transforma
|
|
|
1917
3071
|
readonly encode: Getter.Getter<S["Encoded"], S["Encoded"], RE>;
|
|
1918
3072
|
}): (self: S) => decodeTo<S, toEncoded<S>, RD, RE>;
|
|
1919
3073
|
/**
|
|
3074
|
+
* Constraint used to ensure a schema field does not already have a constructor default.
|
|
3075
|
+
*
|
|
3076
|
+
* Only schemas that satisfy this constraint can be passed to {@link withConstructorDefault}.
|
|
3077
|
+
*
|
|
1920
3078
|
* @since 4.0.0
|
|
1921
3079
|
*/
|
|
1922
3080
|
export interface WithoutConstructorDefault {
|
|
1923
3081
|
readonly "~type.constructor.default": "no-default";
|
|
1924
3082
|
}
|
|
1925
3083
|
/**
|
|
3084
|
+
* The type produced by {@link withConstructorDefault} — a schema with `"~type.constructor.default": "with-default"`.
|
|
3085
|
+
*
|
|
3086
|
+
* @see {@link withConstructorDefault} for the constructor
|
|
1926
3087
|
* @since 4.0.0
|
|
1927
3088
|
*/
|
|
1928
3089
|
export interface withConstructorDefault<S extends Top & WithoutConstructorDefault> extends Bottom<S["Type"], S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], withConstructorDefault<S>, S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], "with-default", S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
@@ -1930,15 +3091,50 @@ export interface withConstructorDefault<S extends Top & WithoutConstructorDefaul
|
|
|
1930
3091
|
readonly schema: S;
|
|
1931
3092
|
}
|
|
1932
3093
|
/**
|
|
3094
|
+
* Attaches a constructor default value to a schema field.
|
|
3095
|
+
*
|
|
3096
|
+
* The `defaultValue` function receives `Option.some(undefined)` when the field is
|
|
3097
|
+
* explicitly set to `undefined`, or `Option.none()` when the field is absent.
|
|
3098
|
+
* Return `Option.some(value)` to supply a default, or `Option.none()` to leave the
|
|
3099
|
+
* field required. An `Effect` may be returned for async or service-dependent defaults.
|
|
3100
|
+
*
|
|
3101
|
+
* Constructor defaults are applied only during `makeUnsafe` / `make`, not during
|
|
3102
|
+
* decoding or encoding.
|
|
3103
|
+
*
|
|
3104
|
+
* **Example** (Optional field with a static default)
|
|
3105
|
+
*
|
|
3106
|
+
* ```ts
|
|
3107
|
+
* import { Option, Schema } from "effect"
|
|
3108
|
+
*
|
|
3109
|
+
* const MySchema = Schema.Struct({
|
|
3110
|
+
* name: Schema.String.pipe(
|
|
3111
|
+
* Schema.optionalKey,
|
|
3112
|
+
* Schema.withConstructorDefault(() => Option.some("anonymous"))
|
|
3113
|
+
* )
|
|
3114
|
+
* })
|
|
3115
|
+
*
|
|
3116
|
+
* const value = MySchema.makeUnsafe({})
|
|
3117
|
+
* // value: { name: "anonymous" }
|
|
3118
|
+
* ```
|
|
3119
|
+
*
|
|
1933
3120
|
* @since 4.0.0
|
|
1934
3121
|
*/
|
|
1935
3122
|
export declare function withConstructorDefault<S extends Top & WithoutConstructorDefault>(defaultValue: (input: Option_.Option<undefined>) => Option_.Option<S["~type.make.in"]> | Effect.Effect<Option_.Option<S["~type.make.in"]>>): (schema: S) => withConstructorDefault<S>;
|
|
1936
3123
|
/**
|
|
3124
|
+
* The type produced by {@link withDecodingDefaultKey} — a schema that decodes from an `optionalKey` encoded source.
|
|
3125
|
+
*
|
|
3126
|
+
* @see {@link withDecodingDefaultKey} for the constructor
|
|
1937
3127
|
* @since 4.0.0
|
|
1938
3128
|
*/
|
|
1939
3129
|
export interface withDecodingDefaultKey<S extends Top> extends decodeTo<S, optionalKey<toEncoded<S>>> {
|
|
1940
3130
|
}
|
|
1941
3131
|
/**
|
|
3132
|
+
* Options for {@link withDecodingDefaultKey} and {@link withDecodingDefault}.
|
|
3133
|
+
*
|
|
3134
|
+
* - `encodingStrategy`:
|
|
3135
|
+
* - `"passthrough"` (default): pass the value through during encoding
|
|
3136
|
+
* - `"omit"`: omit the key from the encoded output
|
|
3137
|
+
*
|
|
1942
3138
|
* @since 4.0.0
|
|
1943
3139
|
*/
|
|
1944
3140
|
export type DecodingDefaultOptions = {
|
|
@@ -1951,10 +3147,34 @@ export type DecodingDefaultOptions = {
|
|
|
1951
3147
|
* - `passthrough`: (default) Pass the default value through to the output.
|
|
1952
3148
|
* - `omit`: Omit the value from the output.
|
|
1953
3149
|
*
|
|
3150
|
+
* Provides a default value for a missing key during decoding.
|
|
3151
|
+
*
|
|
3152
|
+
* When the key is absent from the input, `defaultValue()` is called to supply a value.
|
|
3153
|
+
* During encoding, the behavior is controlled by `options.encodingStrategy`:
|
|
3154
|
+
* - `"passthrough"` (default): include the value in the output
|
|
3155
|
+
* - `"omit"`: omit the key from the output
|
|
3156
|
+
*
|
|
3157
|
+
* **Example** (Default for a missing struct key)
|
|
3158
|
+
*
|
|
3159
|
+
* ```ts
|
|
3160
|
+
* import { Schema } from "effect"
|
|
3161
|
+
*
|
|
3162
|
+
* const MySchema = Schema.Struct({
|
|
3163
|
+
* name: Schema.String.pipe(Schema.withDecodingDefaultKey(() => "anonymous"))
|
|
3164
|
+
* })
|
|
3165
|
+
*
|
|
3166
|
+
* const result = Schema.decodeUnknownSync(MySchema)({})
|
|
3167
|
+
* // result: { name: "anonymous" }
|
|
3168
|
+
* ```
|
|
3169
|
+
*
|
|
3170
|
+
* @see {@link withDecodingDefault} for the `optional` (value-level) variant
|
|
1954
3171
|
* @since 4.0.0
|
|
1955
3172
|
*/
|
|
1956
3173
|
export declare function withDecodingDefaultKey<S extends Top>(defaultValue: () => S["Encoded"], options?: DecodingDefaultOptions): (self: S) => withDecodingDefaultKey<S>;
|
|
1957
3174
|
/**
|
|
3175
|
+
* The type produced by {@link withDecodingDefault} — a schema that decodes from an `optional` encoded source.
|
|
3176
|
+
*
|
|
3177
|
+
* @see {@link withDecodingDefault} for the constructor
|
|
1958
3178
|
* @since 4.0.0
|
|
1959
3179
|
*/
|
|
1960
3180
|
export interface withDecodingDefault<S extends Top> extends decodeTo<S, optional<toEncoded<S>>> {
|
|
@@ -1966,34 +3186,93 @@ export interface withDecodingDefault<S extends Top> extends decodeTo<S, optional
|
|
|
1966
3186
|
* - `passthrough`: (default) Pass the default value through to the output.
|
|
1967
3187
|
* - `omit`: Omit the value from the output.
|
|
1968
3188
|
*
|
|
3189
|
+
* Provides a default value for an `optional` field during decoding.
|
|
3190
|
+
*
|
|
3191
|
+
* Similar to {@link withDecodingDefaultKey} but works on `optional` (value-level optional)
|
|
3192
|
+
* rather than `optionalKey` (key-level optional).
|
|
3193
|
+
*
|
|
3194
|
+
* When the value is `undefined` or absent, `defaultValue()` is called to supply a value.
|
|
3195
|
+
* During encoding, the behavior is controlled by `options.encodingStrategy`:
|
|
3196
|
+
* - `"passthrough"` (default): include the value in the output
|
|
3197
|
+
* - `"omit"`: omit the value from the output
|
|
3198
|
+
*
|
|
3199
|
+
* **Example** (Default for an optional field value)
|
|
3200
|
+
*
|
|
3201
|
+
* ```ts
|
|
3202
|
+
* import { Schema } from "effect"
|
|
3203
|
+
*
|
|
3204
|
+
* const MySchema = Schema.Struct({
|
|
3205
|
+
* name: Schema.String.pipe(Schema.optional, Schema.withDecodingDefault(() => "anonymous"))
|
|
3206
|
+
* })
|
|
3207
|
+
*
|
|
3208
|
+
* const result = Schema.decodeUnknownSync(MySchema)({ name: undefined })
|
|
3209
|
+
* // result: { name: "anonymous" }
|
|
3210
|
+
* ```
|
|
3211
|
+
*
|
|
3212
|
+
* @see {@link withDecodingDefaultKey} for the key-level variant
|
|
1969
3213
|
* @since 4.0.0
|
|
1970
3214
|
*/
|
|
1971
3215
|
export declare function withDecodingDefault<S extends Top>(defaultValue: () => S["Encoded"], options?: DecodingDefaultOptions): (self: S) => withDecodingDefault<S>;
|
|
1972
3216
|
/**
|
|
3217
|
+
* The type produced by {@link tag} — a literal schema with a constructor default.
|
|
3218
|
+
*
|
|
3219
|
+
* Used as the type of the `_tag` field in {@link TaggedStruct} and related helpers.
|
|
3220
|
+
*
|
|
3221
|
+
* @see {@link tag} for the constructor
|
|
1973
3222
|
* @since 4.0.0
|
|
1974
3223
|
*/
|
|
1975
3224
|
export interface tag<Tag extends AST.LiteralValue> extends withConstructorDefault<Literal<Tag>> {
|
|
1976
3225
|
}
|
|
1977
3226
|
/**
|
|
1978
|
-
*
|
|
1979
|
-
*
|
|
3227
|
+
* Combines a {@link Literal} schema with {@link withConstructorDefault}, making it ideal
|
|
3228
|
+
* for discriminator fields in tagged unions. When constructing via `makeUnsafe`, the
|
|
3229
|
+
* `_tag` field can be omitted and will be filled automatically.
|
|
3230
|
+
*
|
|
3231
|
+
* **Example** (Discriminated union tag)
|
|
3232
|
+
*
|
|
3233
|
+
* ```ts
|
|
3234
|
+
* import { Schema } from "effect"
|
|
1980
3235
|
*
|
|
1981
|
-
*
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
1984
|
-
*
|
|
3236
|
+
* const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
|
|
3237
|
+
*
|
|
3238
|
+
* // _tag is optional in makeUnsafe, auto-filled to "A"
|
|
3239
|
+
* const a = A.makeUnsafe({ value: 42 })
|
|
3240
|
+
* // a: { _tag: "A", value: 42 }
|
|
3241
|
+
* ```
|
|
1985
3242
|
*
|
|
3243
|
+
* @see {@link tagDefaultOmit} to also omit the tag during encoding
|
|
3244
|
+
* @see {@link TaggedStruct} for a shorthand that adds `_tag` automatically
|
|
1986
3245
|
* @since 4.0.0
|
|
1987
3246
|
*/
|
|
1988
3247
|
export declare function tag<Tag extends AST.LiteralValue>(literal: Tag): tag<Tag>;
|
|
1989
3248
|
/**
|
|
1990
|
-
*
|
|
1991
|
-
* the
|
|
3249
|
+
* Like {@link tag}, but additionally omits the tag field from the encoded output.
|
|
3250
|
+
* Useful when the encoded form (e.g. JSON) does not include the discriminator key,
|
|
3251
|
+
* but the decoded type and constructor still need it.
|
|
1992
3252
|
*
|
|
3253
|
+
* **Example** (Tag omitted during encoding)
|
|
3254
|
+
*
|
|
3255
|
+
* ```ts
|
|
3256
|
+
* import { Schema } from "effect"
|
|
3257
|
+
*
|
|
3258
|
+
* const A = Schema.Struct({
|
|
3259
|
+
* _tag: Schema.tagDefaultOmit("A"),
|
|
3260
|
+
* value: Schema.Number
|
|
3261
|
+
* })
|
|
3262
|
+
*
|
|
3263
|
+
* // Encode strips the _tag field
|
|
3264
|
+
* const encoded = Schema.encodeUnknownSync(A)({ _tag: "A", value: 1 })
|
|
3265
|
+
* // encoded: { value: 1 }
|
|
3266
|
+
* ```
|
|
3267
|
+
*
|
|
3268
|
+
* @see {@link tag} for the variant that keeps the tag during encoding
|
|
1993
3269
|
* @since 4.0.0
|
|
1994
3270
|
*/
|
|
1995
3271
|
export declare function tagDefaultOmit<Tag extends AST.LiteralValue>(literal: Tag): withDecodingDefaultKey<tag<Tag>>;
|
|
1996
3272
|
/**
|
|
3273
|
+
* The type produced by {@link TaggedStruct} — a {@link Struct} with an extra `_tag` field of type {@link tag}.
|
|
3274
|
+
*
|
|
3275
|
+
* @see {@link TaggedStruct} for the constructor
|
|
1997
3276
|
* @since 4.0.0
|
|
1998
3277
|
*/
|
|
1999
3278
|
export type TaggedStruct<Tag extends AST.LiteralValue, Fields extends Struct.Fields> = Struct<Simplify<{
|
|
@@ -2074,6 +3353,9 @@ type TaggedUnionUtils<Tag extends PropertyKey, Members extends ReadonlyArray<Top
|
|
|
2074
3353
|
};
|
|
2075
3354
|
};
|
|
2076
3355
|
/**
|
|
3356
|
+
* The type produced by {@link toTaggedUnion} — a {@link Union} augmented with `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
3357
|
+
*
|
|
3358
|
+
* @see {@link toTaggedUnion} for the constructor
|
|
2077
3359
|
* @since 4.0.0
|
|
2078
3360
|
* @experimental
|
|
2079
3361
|
*/
|
|
@@ -2083,6 +3365,26 @@ export type toTaggedUnion<Tag extends PropertyKey, Members extends ReadonlyArray
|
|
|
2083
3365
|
};
|
|
2084
3366
|
}>> = Union<Members> & TaggedUnionUtils<Tag, Members>;
|
|
2085
3367
|
/**
|
|
3368
|
+
* Augments an existing {@link Union} of tagged structs with utility methods keyed by the discriminant field.
|
|
3369
|
+
*
|
|
3370
|
+
* **Example** (Adding tagged-union utilities to an existing union)
|
|
3371
|
+
*
|
|
3372
|
+
* ```ts
|
|
3373
|
+
* import { Schema } from "effect"
|
|
3374
|
+
*
|
|
3375
|
+
* const A = Schema.TaggedStruct("A", { value: Schema.Number })
|
|
3376
|
+
* const B = Schema.TaggedStruct("B", { name: Schema.String })
|
|
3377
|
+
*
|
|
3378
|
+
* const MyUnion = Schema.Union([A, B]).pipe(Schema.toTaggedUnion("_tag"))
|
|
3379
|
+
*
|
|
3380
|
+
* // Pattern-match on the union
|
|
3381
|
+
* const result = MyUnion.match({ _tag: "A", value: 1 }, {
|
|
3382
|
+
* A: (a) => `number: ${a.value}`,
|
|
3383
|
+
* B: (b) => `name: ${b.name}`
|
|
3384
|
+
* })
|
|
3385
|
+
* ```
|
|
3386
|
+
*
|
|
3387
|
+
* @see {@link TaggedUnion} for a shorthand that builds the union from scratch
|
|
2086
3388
|
* @since 4.0.0
|
|
2087
3389
|
* @experimental
|
|
2088
3390
|
*/
|
|
@@ -2090,6 +3392,10 @@ export declare function toTaggedUnion<const Tag extends PropertyKey>(tag: Tag):
|
|
|
2090
3392
|
readonly Type: { readonly [K in Tag]: PropertyKey; };
|
|
2091
3393
|
}>>(self: Union<Members>) => toTaggedUnion<Tag, Members>;
|
|
2092
3394
|
/**
|
|
3395
|
+
* A union schema that exposes `cases`, `guards`, `isAnyOf`, and `match` utilities keyed by the `_tag` discriminant.
|
|
3396
|
+
* Produced by {@link TaggedUnion}.
|
|
3397
|
+
*
|
|
3398
|
+
* @see {@link TaggedUnion} for the constructor
|
|
2093
3399
|
* @since 4.0.0
|
|
2094
3400
|
* @experimental
|
|
2095
3401
|
*/
|
|
@@ -2122,6 +3428,28 @@ export interface TaggedUnion<Cases extends Record<string, Top>> extends Bottom<{
|
|
|
2122
3428
|
};
|
|
2123
3429
|
}
|
|
2124
3430
|
/**
|
|
3431
|
+
* Builds a discriminated union from a record of field sets, one per variant.
|
|
3432
|
+
* Each key becomes the `_tag` literal and the value is passed to {@link TaggedStruct}.
|
|
3433
|
+
* The result includes `cases`, `guards`, `isAnyOf`, and `match` utilities.
|
|
3434
|
+
*
|
|
3435
|
+
* **Example** (Discriminated union with pattern matching)
|
|
3436
|
+
*
|
|
3437
|
+
* ```ts
|
|
3438
|
+
* import { Schema } from "effect"
|
|
3439
|
+
*
|
|
3440
|
+
* const Shape = Schema.TaggedUnion({
|
|
3441
|
+
* Circle: { radius: Schema.Number },
|
|
3442
|
+
* Rectangle: { width: Schema.Number, height: Schema.Number }
|
|
3443
|
+
* })
|
|
3444
|
+
*
|
|
3445
|
+
* // Pattern-match on a decoded value
|
|
3446
|
+
* const area = Shape.match({ _tag: "Circle", radius: 5 }, {
|
|
3447
|
+
* Circle: (c) => Math.PI * c.radius ** 2,
|
|
3448
|
+
* Rectangle: (r) => r.width * r.height
|
|
3449
|
+
* })
|
|
3450
|
+
* ```
|
|
3451
|
+
*
|
|
3452
|
+
* @see {@link toTaggedUnion} to augment an existing union instead
|
|
2125
3453
|
* @category Constructors
|
|
2126
3454
|
* @since 4.0.0
|
|
2127
3455
|
*/
|
|
@@ -2129,29 +3457,69 @@ export declare function TaggedUnion<const CasesByTag extends Record<string, Stru
|
|
|
2129
3457
|
readonly [K in keyof CasesByTag & string]: TaggedStruct<K, CasesByTag[K]>;
|
|
2130
3458
|
}>;
|
|
2131
3459
|
/**
|
|
3460
|
+
* The interface type for schemas created by {@link Opaque}.
|
|
3461
|
+
* Carries the same encoded/decoded shape as `S` but replaces `Type` with `Self & Brand`,
|
|
3462
|
+
* making the decoded value nominally distinct.
|
|
3463
|
+
*
|
|
3464
|
+
* @see {@link Opaque} for the constructor
|
|
2132
3465
|
* @since 4.0.0
|
|
2133
3466
|
*/
|
|
2134
3467
|
export interface Opaque<Self, S extends Top, Brand> extends Bottom<Self, S["Encoded"], S["DecodingServices"], S["EncodingServices"], S["ast"], S["~rebuild.out"], S["~type.make.in"], S["Iso"], S["~type.parameters"], S["~type.make"], S["~type.mutability"], S["~type.optionality"], S["~type.constructor.default"], S["~encoded.mutability"], S["~encoded.optionality"]> {
|
|
2135
3468
|
new (_: never): S["Type"] & Brand;
|
|
2136
3469
|
}
|
|
2137
3470
|
/**
|
|
3471
|
+
* Wraps a schema so that its decoded `Type` becomes a nominally distinct type `Self`.
|
|
3472
|
+
* Useful for creating opaque types that are structurally identical to a base schema
|
|
3473
|
+
* but type-incompatible with it.
|
|
3474
|
+
*
|
|
3475
|
+
* **Example** (Opaque user ID)
|
|
3476
|
+
*
|
|
3477
|
+
* ```ts
|
|
3478
|
+
* import { Schema } from "effect"
|
|
3479
|
+
*
|
|
3480
|
+
* type UserId = string & { readonly _tag: "UserId" }
|
|
3481
|
+
* const UserId = Schema.Opaque<UserId>()(Schema.String)
|
|
3482
|
+
*
|
|
3483
|
+
* // Decoded value is UserId, not plain string
|
|
3484
|
+
* const id = Schema.decodeUnknownSync(UserId)("abc")
|
|
3485
|
+
* // id: UserId
|
|
3486
|
+
* ```
|
|
3487
|
+
*
|
|
2138
3488
|
* @since 4.0.0
|
|
2139
3489
|
*/
|
|
2140
3490
|
export declare function Opaque<Self, Brand = {}>(): <S extends Top>(schema: S) => Opaque<Self, S, Brand> & Omit<S, "Type">;
|
|
2141
3491
|
/**
|
|
3492
|
+
* The type produced by {@link instanceOf} — a declaration schema that validates class instances.
|
|
3493
|
+
*
|
|
3494
|
+
* @see {@link instanceOf} for the constructor
|
|
2142
3495
|
* @since 4.0.0
|
|
2143
3496
|
*/
|
|
2144
3497
|
export interface instanceOf<T, Iso = T> extends declare<T, Iso> {
|
|
2145
3498
|
readonly "~rebuild.out": this;
|
|
2146
3499
|
}
|
|
2147
3500
|
/**
|
|
2148
|
-
* Creates a schema that validates
|
|
3501
|
+
* Creates a schema that validates values using `instanceof`.
|
|
3502
|
+
* Decoding and encoding pass the value through unchanged.
|
|
3503
|
+
*
|
|
3504
|
+
* **Example** (Schema for a built-in class)
|
|
3505
|
+
*
|
|
3506
|
+
* ```ts
|
|
3507
|
+
* import { Schema } from "effect"
|
|
3508
|
+
*
|
|
3509
|
+
* const DateSchema = Schema.instanceOf(Date)
|
|
3510
|
+
*
|
|
3511
|
+
* const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
|
|
3512
|
+
* // decoded: Date
|
|
3513
|
+
* ```
|
|
2149
3514
|
*
|
|
2150
3515
|
* @category Constructors
|
|
2151
3516
|
* @since 4.0.0
|
|
2152
3517
|
*/
|
|
2153
3518
|
export declare function instanceOf<C extends abstract new (...args: any) => any, Iso = InstanceType<C>>(constructor: C, annotations?: Annotations.Declaration<InstanceType<C>> | undefined): instanceOf<InstanceType<C>, Iso>;
|
|
2154
3519
|
/**
|
|
3520
|
+
* Constructs an `AST.Link` that describes how a value of type `T` encodes to and decodes from a `To` schema.
|
|
3521
|
+
* Used when building low-level AST transformations that bridge two schema types.
|
|
3522
|
+
*
|
|
2155
3523
|
* @since 4.0.0
|
|
2156
3524
|
* @experimental
|
|
2157
3525
|
*/
|
|
@@ -2160,6 +3528,22 @@ export declare function link<T>(): <To extends Top>(encodeTo: To, transformation
|
|
|
2160
3528
|
readonly encode: Getter.Getter<NoInfer<To["Type"]>, T>;
|
|
2161
3529
|
}) => AST.Link;
|
|
2162
3530
|
/**
|
|
3531
|
+
* Creates a custom filter check from a predicate function. The predicate
|
|
3532
|
+
* receives the input value, the schema's AST, and parse options, and returns
|
|
3533
|
+
* `true`/`undefined` on success or a failure description on error.
|
|
3534
|
+
*
|
|
3535
|
+
* **Example** (Custom filter check)
|
|
3536
|
+
* ```ts
|
|
3537
|
+
* import { Schema } from "effect"
|
|
3538
|
+
*
|
|
3539
|
+
* // Check that a number is even
|
|
3540
|
+
* const isEven = Schema.makeFilter(
|
|
3541
|
+
* (n: number) => n % 2 === 0 || "expected an even number"
|
|
3542
|
+
* )
|
|
3543
|
+
*
|
|
3544
|
+
* const EvenNumber = Schema.Number.check(isEven)
|
|
3545
|
+
* ```
|
|
3546
|
+
*
|
|
2163
3547
|
* @category Checks Constructors
|
|
2164
3548
|
* @since 4.0.0
|
|
2165
3549
|
*/
|
|
@@ -2168,6 +3552,9 @@ export declare const makeFilter: <T>(filter: (input: T, ast: AST.AST, options: A
|
|
|
2168
3552
|
readonly message: string;
|
|
2169
3553
|
}, annotations?: Annotations.Filter | undefined, abort?: boolean) => AST.Filter<T>;
|
|
2170
3554
|
/**
|
|
3555
|
+
* Groups multiple checks into a single {@link AST.FilterGroup}, applying
|
|
3556
|
+
* optional shared annotations to the group as a whole.
|
|
3557
|
+
*
|
|
2171
3558
|
* @category Checks Constructors
|
|
2172
3559
|
* @since 4.0.0
|
|
2173
3560
|
*/
|
|
@@ -2465,6 +3852,9 @@ export declare function isUncapitalized(annotations?: Annotations.Filter): AST.F
|
|
|
2465
3852
|
*/
|
|
2466
3853
|
export declare function isFinite(annotations?: Annotations.Filter): AST.Filter<number>;
|
|
2467
3854
|
/**
|
|
3855
|
+
* Generic factory for creating a "greater than" (`>`) check for any ordered
|
|
3856
|
+
* type by supplying an {@link Order.Order} instance.
|
|
3857
|
+
*
|
|
2468
3858
|
* @category Order checks
|
|
2469
3859
|
* @since 4.0.0
|
|
2470
3860
|
*/
|
|
@@ -2474,6 +3864,9 @@ export declare function makeIsGreaterThan<T>(options: {
|
|
|
2474
3864
|
readonly formatter?: Formatter<T> | undefined;
|
|
2475
3865
|
}): (exclusiveMinimum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2476
3866
|
/**
|
|
3867
|
+
* Generic factory for creating a ">=" check for any ordered type by supplying
|
|
3868
|
+
* an {@link Order.Order} instance.
|
|
3869
|
+
*
|
|
2477
3870
|
* @category Order checks
|
|
2478
3871
|
* @since 4.0.0
|
|
2479
3872
|
*/
|
|
@@ -2483,6 +3876,9 @@ export declare function makeIsGreaterThanOrEqualTo<T>(options: {
|
|
|
2483
3876
|
readonly formatter?: Formatter<T> | undefined;
|
|
2484
3877
|
}): (minimum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2485
3878
|
/**
|
|
3879
|
+
* Generic factory for creating a "<" check for any ordered type by supplying
|
|
3880
|
+
* an {@link Order.Order} instance.
|
|
3881
|
+
*
|
|
2486
3882
|
* @category Order checks
|
|
2487
3883
|
* @since 4.0.0
|
|
2488
3884
|
*/
|
|
@@ -2492,6 +3888,9 @@ export declare function makeIsLessThan<T>(options: {
|
|
|
2492
3888
|
readonly formatter?: Formatter<T> | undefined;
|
|
2493
3889
|
}): (exclusiveMaximum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2494
3890
|
/**
|
|
3891
|
+
* Generic factory for creating a "<=" check for any ordered type by supplying
|
|
3892
|
+
* an {@link Order.Order} instance.
|
|
3893
|
+
*
|
|
2495
3894
|
* @category Order checks
|
|
2496
3895
|
* @since 4.0.0
|
|
2497
3896
|
*/
|
|
@@ -2501,6 +3900,9 @@ export declare function makeIsLessThanOrEqualTo<T>(options: {
|
|
|
2501
3900
|
readonly formatter?: Formatter<T> | undefined;
|
|
2502
3901
|
}): (maximum: T, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2503
3902
|
/**
|
|
3903
|
+
* Generic factory for creating an inclusive/exclusive range check for any
|
|
3904
|
+
* ordered type by supplying an {@link Order.Order} instance.
|
|
3905
|
+
*
|
|
2504
3906
|
* @category Order checks
|
|
2505
3907
|
* @since 4.0.0
|
|
2506
3908
|
*/
|
|
@@ -2520,6 +3922,9 @@ export declare function makeIsBetween<T>(deriveOptions: {
|
|
|
2520
3922
|
readonly exclusiveMaximum?: boolean | undefined;
|
|
2521
3923
|
}, annotations?: Annotations.Filter) => AST.Filter<T>;
|
|
2522
3924
|
/**
|
|
3925
|
+
* Generic factory for creating a divisibility check for any numeric type by
|
|
3926
|
+
* supplying a remainder function and a zero value.
|
|
3927
|
+
*
|
|
2523
3928
|
* @category Numeric checks
|
|
2524
3929
|
* @since 4.0.0
|
|
2525
3930
|
*/
|
|
@@ -2925,6 +4330,14 @@ export declare const isBetweenBigDecimal: (options: {
|
|
|
2925
4330
|
* constraint to ensure generated strings or arrays have at least the required
|
|
2926
4331
|
* length.
|
|
2927
4332
|
*
|
|
4333
|
+
* **Example** (Minimum length check)
|
|
4334
|
+
* ```ts
|
|
4335
|
+
* import { Schema } from "effect"
|
|
4336
|
+
*
|
|
4337
|
+
* const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
|
|
4338
|
+
* const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
|
|
4339
|
+
* ```
|
|
4340
|
+
*
|
|
2928
4341
|
* @category Length checks
|
|
2929
4342
|
* @since 4.0.0
|
|
2930
4343
|
*/
|
|
@@ -3140,6 +4553,7 @@ export declare function isPropertyNames(keySchema: Top, annotations?: Annotation
|
|
|
3140
4553
|
* constraint using the provided equivalence function to ensure generated arrays
|
|
3141
4554
|
* contain only unique items.
|
|
3142
4555
|
*
|
|
4556
|
+
* @category Array checks
|
|
3143
4557
|
* @since 4.0.0
|
|
3144
4558
|
*/
|
|
3145
4559
|
export declare function isUnique<T>(annotations?: Annotations.Filter): AST.Filter<readonly T[]>;
|
|
@@ -3157,6 +4571,23 @@ export declare const NonEmptyString: String;
|
|
|
3157
4571
|
*/
|
|
3158
4572
|
export declare const Char: String;
|
|
3159
4573
|
/**
|
|
4574
|
+
* Schema for the `Option<A>` type, representing an optional value that is
|
|
4575
|
+
* either `None` or `Some<A>`.
|
|
4576
|
+
*
|
|
4577
|
+
* **Example** (Option schema)
|
|
4578
|
+
*
|
|
4579
|
+
* ```ts
|
|
4580
|
+
* import { Schema } from "effect"
|
|
4581
|
+
* import { Option } from "effect"
|
|
4582
|
+
*
|
|
4583
|
+
* const schema = Schema.Option(Schema.Number)
|
|
4584
|
+
*
|
|
4585
|
+
* Schema.decodeUnknownSync(schema)(Option.some(1))
|
|
4586
|
+
* // => Some(1)
|
|
4587
|
+
* Schema.decodeUnknownSync(schema)(Option.none())
|
|
4588
|
+
* // => None
|
|
4589
|
+
* ```
|
|
4590
|
+
*
|
|
3160
4591
|
* @category Option
|
|
3161
4592
|
* @since 4.0.0
|
|
3162
4593
|
*/
|
|
@@ -3174,11 +4605,16 @@ export type OptionIso<A extends Top> = {
|
|
|
3174
4605
|
readonly value: A["Iso"];
|
|
3175
4606
|
};
|
|
3176
4607
|
/**
|
|
4608
|
+
* Creates a schema for `Option<A>`. See {@link Option} for details.
|
|
4609
|
+
*
|
|
3177
4610
|
* @category Option
|
|
3178
4611
|
* @since 4.0.0
|
|
3179
4612
|
*/
|
|
3180
4613
|
export declare function Option<A extends Top>(value: A): Option<A>;
|
|
3181
4614
|
/**
|
|
4615
|
+
* Schema type for {@link OptionFromNullOr}.
|
|
4616
|
+
*
|
|
4617
|
+
* @category Option
|
|
3182
4618
|
* @since 4.0.0
|
|
3183
4619
|
*/
|
|
3184
4620
|
export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<S>>, NullOr<S>> {
|
|
@@ -3199,6 +4635,9 @@ export interface OptionFromNullOr<S extends Top> extends decodeTo<Option<toType<
|
|
|
3199
4635
|
*/
|
|
3200
4636
|
export declare function OptionFromNullOr<S extends Top>(schema: S): OptionFromNullOr<S>;
|
|
3201
4637
|
/**
|
|
4638
|
+
* Schema type for {@link OptionFromUndefinedOr}.
|
|
4639
|
+
*
|
|
4640
|
+
* @category Option
|
|
3202
4641
|
* @since 4.0.0
|
|
3203
4642
|
*/
|
|
3204
4643
|
export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<toType<S>>, UndefinedOr<S>> {
|
|
@@ -3219,6 +4658,9 @@ export interface OptionFromUndefinedOr<S extends Top> extends decodeTo<Option<to
|
|
|
3219
4658
|
*/
|
|
3220
4659
|
export declare function OptionFromUndefinedOr<S extends Top>(schema: S): OptionFromUndefinedOr<S>;
|
|
3221
4660
|
/**
|
|
4661
|
+
* Schema type for {@link OptionFromNullishOr}.
|
|
4662
|
+
*
|
|
4663
|
+
* @category Option
|
|
3222
4664
|
* @since 4.0.0
|
|
3223
4665
|
*/
|
|
3224
4666
|
export interface OptionFromNullishOr<S extends Top> extends decodeTo<Option<toType<S>>, NullishOr<S>> {
|
|
@@ -3241,6 +4683,9 @@ export declare function OptionFromNullishOr<S extends Top>(schema: S, options?:
|
|
|
3241
4683
|
onNoneEncoding: null | undefined;
|
|
3242
4684
|
}): OptionFromNullishOr<S>;
|
|
3243
4685
|
/**
|
|
4686
|
+
* Schema type for {@link OptionFromOptionalKey}.
|
|
4687
|
+
*
|
|
4688
|
+
* @category Option
|
|
3244
4689
|
* @since 4.0.0
|
|
3245
4690
|
*/
|
|
3246
4691
|
export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<toType<S>>, optionalKey<S>> {
|
|
@@ -3261,6 +4706,9 @@ export interface OptionFromOptionalKey<S extends Top> extends decodeTo<Option<to
|
|
|
3261
4706
|
*/
|
|
3262
4707
|
export declare function OptionFromOptionalKey<S extends Top>(schema: S): OptionFromOptionalKey<S>;
|
|
3263
4708
|
/**
|
|
4709
|
+
* Schema type for {@link OptionFromOptional}.
|
|
4710
|
+
*
|
|
4711
|
+
* @category Option
|
|
3264
4712
|
* @since 4.0.0
|
|
3265
4713
|
*/
|
|
3266
4714
|
export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toType<S>>, optional<S>> {
|
|
@@ -3283,6 +4731,9 @@ export interface OptionFromOptional<S extends Top> extends decodeTo<Option<toTyp
|
|
|
3283
4731
|
*/
|
|
3284
4732
|
export declare function OptionFromOptional<S extends Top>(schema: S): OptionFromOptional<S>;
|
|
3285
4733
|
/**
|
|
4734
|
+
* Schema for the `Result<A, E>` type, representing a computation that either
|
|
4735
|
+
* succeeds with `A` or fails with `E`.
|
|
4736
|
+
*
|
|
3286
4737
|
* @category Result
|
|
3287
4738
|
* @since 4.0.0
|
|
3288
4739
|
*/
|
|
@@ -3302,11 +4753,16 @@ export type ResultIso<A extends Top, E extends Top> = {
|
|
|
3302
4753
|
readonly failure: E["Iso"];
|
|
3303
4754
|
};
|
|
3304
4755
|
/**
|
|
4756
|
+
* Creates a schema for `Result<A, E>`. See {@link Result} for details.
|
|
4757
|
+
*
|
|
3305
4758
|
* @category Result
|
|
3306
4759
|
* @since 4.0.0
|
|
3307
4760
|
*/
|
|
3308
4761
|
export declare function Result<A extends Top, E extends Top>(success: A, failure: E): Result<A, E>;
|
|
3309
4762
|
/**
|
|
4763
|
+
* Schema for the `Redacted<A>` type, providing secure handling of sensitive
|
|
4764
|
+
* values. The inner value is hidden from error messages.
|
|
4765
|
+
*
|
|
3310
4766
|
* @category Redacted
|
|
3311
4767
|
* @since 4.0.0
|
|
3312
4768
|
*/
|
|
@@ -3340,17 +4796,26 @@ export declare function Redacted<S extends Top>(value: S, options?: {
|
|
|
3340
4796
|
readonly label?: string | undefined;
|
|
3341
4797
|
}): Redacted<S>;
|
|
3342
4798
|
/**
|
|
4799
|
+
* Schema type for {@link RedactedFromValue}.
|
|
4800
|
+
*
|
|
3343
4801
|
* @category Redacted
|
|
3344
4802
|
* @since 4.0.0
|
|
3345
4803
|
*/
|
|
3346
4804
|
export interface RedactedFromValue<S extends Top> extends decodeTo<Redacted<toType<S>>, middlewareDecoding<S, S["DecodingServices"]>> {
|
|
3347
4805
|
}
|
|
3348
4806
|
/**
|
|
4807
|
+
* Middleware that wraps decoded errors in `Redacted`, preventing sensitive
|
|
4808
|
+
* schema details from leaking in error messages.
|
|
4809
|
+
*
|
|
3349
4810
|
* @category Redacted
|
|
3350
4811
|
* @since 4.0.0
|
|
3351
4812
|
*/
|
|
3352
4813
|
export declare function redact<S extends Top>(schema: S): middlewareDecoding<S, S["DecodingServices"]>;
|
|
3353
4814
|
/**
|
|
4815
|
+
* Decodes a value and wraps it in `Redacted<A>`. Unlike {@link Redacted} which
|
|
4816
|
+
* expects the input to already be a `Redacted` instance, this schema decodes
|
|
4817
|
+
* the raw value and wraps it.
|
|
4818
|
+
*
|
|
3354
4819
|
* @category Redacted
|
|
3355
4820
|
* @since 4.0.0
|
|
3356
4821
|
*/
|
|
@@ -3358,6 +4823,10 @@ export declare function RedactedFromValue<S extends Top>(value: S, options?: {
|
|
|
3358
4823
|
readonly label?: string | undefined;
|
|
3359
4824
|
}): RedactedFromValue<S>;
|
|
3360
4825
|
/**
|
|
4826
|
+
* Schema for a single `Cause.Reason<E>`, representing one reason a fiber may
|
|
4827
|
+
* fail: a typed error (`Fail`), an unexpected defect (`Die`), or an interrupt
|
|
4828
|
+
* (`Interrupt`).
|
|
4829
|
+
*
|
|
3361
4830
|
* @category CauseReason
|
|
3362
4831
|
* @since 4.0.0
|
|
3363
4832
|
*/
|
|
@@ -3380,11 +4849,16 @@ export type CauseReasonIso<E extends Top, D extends Top> = {
|
|
|
3380
4849
|
readonly fiberId: number | undefined;
|
|
3381
4850
|
};
|
|
3382
4851
|
/**
|
|
4852
|
+
* Creates a schema for `Cause.Reason<E>`. See {@link CauseReason} for details.
|
|
4853
|
+
*
|
|
3383
4854
|
* @category CauseReason
|
|
3384
4855
|
* @since 4.0.0
|
|
3385
4856
|
*/
|
|
3386
4857
|
export declare function CauseReason<E extends Top, D extends Top>(error: E, defect: D): CauseReason<E, D>;
|
|
3387
4858
|
/**
|
|
4859
|
+
* Schema for `Cause<E>`, an ordered collection of reasons a fiber failed,
|
|
4860
|
+
* combining typed errors, defects, and interrupts.
|
|
4861
|
+
*
|
|
3388
4862
|
* @category Cause
|
|
3389
4863
|
* @since 4.0.0
|
|
3390
4864
|
*/
|
|
@@ -3398,11 +4872,16 @@ export interface Cause<E extends Top, D extends Top> extends declareConstructor<
|
|
|
3398
4872
|
*/
|
|
3399
4873
|
export type CauseIso<E extends Top, D extends Top> = ReadonlyArray<CauseReasonIso<E, D>>;
|
|
3400
4874
|
/**
|
|
4875
|
+
* Creates a schema for `Cause<E>`. See {@link Cause} for details.
|
|
4876
|
+
*
|
|
3401
4877
|
* @category Cause
|
|
3402
4878
|
* @since 4.0.0
|
|
3403
4879
|
*/
|
|
3404
4880
|
export declare function Cause<E extends Top, D extends Top>(error: E, defect: D): Cause<E, D>;
|
|
3405
4881
|
/**
|
|
4882
|
+
* Schema type for {@link Error}.
|
|
4883
|
+
*
|
|
4884
|
+
* @category Schemas
|
|
3406
4885
|
* @since 4.0.0
|
|
3407
4886
|
*/
|
|
3408
4887
|
export interface Error extends instanceOf<globalThis.Error> {
|
|
@@ -3428,6 +4907,9 @@ export declare const Error: Error;
|
|
|
3428
4907
|
*/
|
|
3429
4908
|
export declare const ErrorWithStack: Error;
|
|
3430
4909
|
/**
|
|
4910
|
+
* Schema type for {@link Defect}.
|
|
4911
|
+
*
|
|
4912
|
+
* @category Schemas
|
|
3431
4913
|
* @since 4.0.0
|
|
3432
4914
|
*/
|
|
3433
4915
|
export interface Defect extends Union<readonly [
|
|
@@ -3455,6 +4937,9 @@ export declare const Defect: Defect;
|
|
|
3455
4937
|
*/
|
|
3456
4938
|
export declare const DefectWithStack: Defect;
|
|
3457
4939
|
/**
|
|
4940
|
+
* Schema for `Exit<A, E>`, representing the result of a fiber execution —
|
|
4941
|
+
* either a success with value `A` or a failure with `Cause<E>`.
|
|
4942
|
+
*
|
|
3458
4943
|
* @category Exit
|
|
3459
4944
|
* @since 4.0.0
|
|
3460
4945
|
*/
|
|
@@ -3475,11 +4960,15 @@ export type ExitIso<A extends Top, E extends Top, D extends Top> = {
|
|
|
3475
4960
|
readonly cause: CauseIso<E, D>;
|
|
3476
4961
|
};
|
|
3477
4962
|
/**
|
|
4963
|
+
* Creates a schema for `Exit<A, E>`. See {@link Exit} for details.
|
|
4964
|
+
*
|
|
3478
4965
|
* @category Exit
|
|
3479
4966
|
* @since 4.0.0
|
|
3480
4967
|
*/
|
|
3481
4968
|
export declare function Exit<A extends Top, E extends Top, D extends Top>(value: A, error: E, defect: D): Exit<A, E, D>;
|
|
3482
4969
|
/**
|
|
4970
|
+
* Schema type for {@link ReadonlyMap}.
|
|
4971
|
+
*
|
|
3483
4972
|
* @category ReadonlyMap
|
|
3484
4973
|
* @since 4.0.0
|
|
3485
4974
|
*/
|
|
@@ -3501,6 +4990,9 @@ export type ReadonlyMapIso<Key extends Top, Value extends Top> = ReadonlyArray<r
|
|
|
3501
4990
|
*/
|
|
3502
4991
|
export declare function ReadonlyMap<Key extends Top, Value extends Top>(key: Key, value: Value): $ReadonlyMap<Key, Value>;
|
|
3503
4992
|
/**
|
|
4993
|
+
* Schema for an Effect `HashMap` where keys and values must conform to the
|
|
4994
|
+
* provided schemas.
|
|
4995
|
+
*
|
|
3504
4996
|
* @category HashMap
|
|
3505
4997
|
* @since 4.0.0
|
|
3506
4998
|
*/
|
|
@@ -3522,6 +5014,8 @@ export type HashMapIso<Key extends Top, Value extends Top> = ReadonlyArray<reado
|
|
|
3522
5014
|
*/
|
|
3523
5015
|
export declare function HashMap<Key extends Top, Value extends Top>(key: Key, value: Value): HashMap<Key, Value>;
|
|
3524
5016
|
/**
|
|
5017
|
+
* Schema type for {@link ReadonlySet}.
|
|
5018
|
+
*
|
|
3525
5019
|
* @category ReadonlySet
|
|
3526
5020
|
* @since 4.0.0
|
|
3527
5021
|
*/
|
|
@@ -3539,6 +5033,9 @@ export type ReadonlySetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>;
|
|
|
3539
5033
|
*/
|
|
3540
5034
|
export declare function ReadonlySet<Value extends Top>(value: Value): $ReadonlySet<Value>;
|
|
3541
5035
|
/**
|
|
5036
|
+
* Schema for an Effect `HashSet` where values must conform to the provided
|
|
5037
|
+
* schema.
|
|
5038
|
+
*
|
|
3542
5039
|
* @category HashSet
|
|
3543
5040
|
* @since 4.0.0
|
|
3544
5041
|
*/
|
|
@@ -3559,6 +5056,9 @@ export type HashSetIso<Value extends Top> = ReadonlyArray<Value["Iso"]>;
|
|
|
3559
5056
|
*/
|
|
3560
5057
|
export declare function HashSet<Value extends Top>(value: Value): HashSet<Value>;
|
|
3561
5058
|
/**
|
|
5059
|
+
* Schema for an Effect `Chunk` (immutable array-like collection) where values
|
|
5060
|
+
* must conform to the provided schema.
|
|
5061
|
+
*
|
|
3562
5062
|
* @category Chunk
|
|
3563
5063
|
* @since 4.0.0
|
|
3564
5064
|
*/
|
|
@@ -3579,15 +5079,26 @@ export type ChunkIso<Value extends Top> = ReadonlyArray<Value["Iso"]>;
|
|
|
3579
5079
|
*/
|
|
3580
5080
|
export declare function Chunk<Value extends Top>(value: Value): Chunk<Value>;
|
|
3581
5081
|
/**
|
|
5082
|
+
* Schema type for {@link RegExp}.
|
|
5083
|
+
*
|
|
5084
|
+
* @category Schemas
|
|
3582
5085
|
* @since 4.0.0
|
|
3583
5086
|
*/
|
|
3584
5087
|
export interface RegExp extends instanceOf<globalThis.RegExp> {
|
|
3585
5088
|
}
|
|
3586
5089
|
/**
|
|
5090
|
+
* Schema for JavaScript `RegExp` objects.
|
|
5091
|
+
*
|
|
5092
|
+
* The default JSON serializer encodes a `RegExp` as `{ source, flags }`.
|
|
5093
|
+
*
|
|
5094
|
+
* @category Schemas
|
|
3587
5095
|
* @since 4.0.0
|
|
3588
5096
|
*/
|
|
3589
5097
|
export declare const RegExp: RegExp;
|
|
3590
5098
|
/**
|
|
5099
|
+
* Schema type for {@link URL}.
|
|
5100
|
+
*
|
|
5101
|
+
* @category URL
|
|
3591
5102
|
* @since 4.0.0
|
|
3592
5103
|
*/
|
|
3593
5104
|
export interface URL extends instanceOf<globalThis.URL> {
|
|
@@ -3604,6 +5115,9 @@ export interface URL extends instanceOf<globalThis.URL> {
|
|
|
3604
5115
|
*/
|
|
3605
5116
|
export declare const URL: URL;
|
|
3606
5117
|
/**
|
|
5118
|
+
* Schema type for {@link URLFromString}.
|
|
5119
|
+
*
|
|
5120
|
+
* @category URL
|
|
3607
5121
|
* @since 4.0.0
|
|
3608
5122
|
*/
|
|
3609
5123
|
export interface URLFromString extends decodeTo<URL, String> {
|
|
@@ -3622,6 +5136,9 @@ export interface URLFromString extends decodeTo<URL, String> {
|
|
|
3622
5136
|
*/
|
|
3623
5137
|
export declare const URLFromString: URLFromString;
|
|
3624
5138
|
/**
|
|
5139
|
+
* Schema type for {@link Date}.
|
|
5140
|
+
*
|
|
5141
|
+
* @category Schemas
|
|
3625
5142
|
* @since 4.0.0
|
|
3626
5143
|
*/
|
|
3627
5144
|
export interface Date extends instanceOf<globalThis.Date> {
|
|
@@ -3630,12 +5147,26 @@ export interface Date extends instanceOf<globalThis.Date> {
|
|
|
3630
5147
|
* A schema for JavaScript `Date` objects.
|
|
3631
5148
|
*
|
|
3632
5149
|
* This schema accepts any `Date` instance, including invalid dates (e.g., `new
|
|
3633
|
-
* Date("invalid")`). For validating only valid dates, use
|
|
5150
|
+
* Date("invalid")`). For validating only valid dates, use {@link DateValid}
|
|
5151
|
+
* instead. The default JSON serializer encodes `Date` as an ISO 8601 string.
|
|
5152
|
+
*
|
|
5153
|
+
* **Example** (Date schema)
|
|
5154
|
+
*
|
|
5155
|
+
* ```ts
|
|
5156
|
+
* import { Schema } from "effect"
|
|
5157
|
+
*
|
|
5158
|
+
* Schema.decodeUnknownSync(Schema.Date)(new Date("2024-01-01"))
|
|
5159
|
+
* // => Date { 2024-01-01T00:00:00.000Z }
|
|
5160
|
+
* ```
|
|
3634
5161
|
*
|
|
5162
|
+
* @category Schemas
|
|
3635
5163
|
* @since 4.0.0
|
|
3636
5164
|
*/
|
|
3637
5165
|
export declare const Date: Date;
|
|
3638
5166
|
/**
|
|
5167
|
+
* Schema type for {@link DateValid}.
|
|
5168
|
+
*
|
|
5169
|
+
* @category Schemas
|
|
3639
5170
|
* @since 4.0.0
|
|
3640
5171
|
*/
|
|
3641
5172
|
export interface DateValid extends Date {
|
|
@@ -3650,6 +5181,9 @@ export interface DateValid extends Date {
|
|
|
3650
5181
|
*/
|
|
3651
5182
|
export declare const DateValid: Date;
|
|
3652
5183
|
/**
|
|
5184
|
+
* Schema type for {@link Duration}.
|
|
5185
|
+
*
|
|
5186
|
+
* @category Duration
|
|
3653
5187
|
* @since 4.0.0
|
|
3654
5188
|
*/
|
|
3655
5189
|
export interface Duration extends declare<Duration_.Duration> {
|
|
@@ -3657,14 +5191,28 @@ export interface Duration extends declare<Duration_.Duration> {
|
|
|
3657
5191
|
/**
|
|
3658
5192
|
* A schema for `Duration` values.
|
|
3659
5193
|
*
|
|
3660
|
-
*
|
|
5194
|
+
* The default JSON serializer encodes `Duration` as a tagged object with the
|
|
5195
|
+
* duration type and value.
|
|
5196
|
+
*
|
|
5197
|
+
* **Example** (Duration schema)
|
|
5198
|
+
*
|
|
5199
|
+
* ```ts
|
|
5200
|
+
* import { Schema } from "effect"
|
|
5201
|
+
* import { Duration } from "effect"
|
|
5202
|
+
*
|
|
5203
|
+
* Schema.decodeUnknownSync(Schema.Duration)(Duration.seconds(5))
|
|
5204
|
+
* // => Duration(5s)
|
|
5205
|
+
* ```
|
|
3661
5206
|
*
|
|
3662
|
-
*
|
|
5207
|
+
* @category Duration
|
|
3663
5208
|
*
|
|
3664
5209
|
* @since 4.0.0
|
|
3665
5210
|
*/
|
|
3666
5211
|
export declare const Duration: Duration;
|
|
3667
5212
|
/**
|
|
5213
|
+
* Schema type for {@link DurationFromNanos}.
|
|
5214
|
+
*
|
|
5215
|
+
* @category Duration
|
|
3668
5216
|
* @since 4.0.0
|
|
3669
5217
|
*/
|
|
3670
5218
|
export interface DurationFromNanos extends decodeTo<Duration, BigInt> {
|
|
@@ -3684,6 +5232,9 @@ export interface DurationFromNanos extends decodeTo<Duration, BigInt> {
|
|
|
3684
5232
|
*/
|
|
3685
5233
|
export declare const DurationFromNanos: DurationFromNanos;
|
|
3686
5234
|
/**
|
|
5235
|
+
* Schema type for {@link DurationFromMillis}.
|
|
5236
|
+
*
|
|
5237
|
+
* @category Duration
|
|
3687
5238
|
* @since 4.0.0
|
|
3688
5239
|
*/
|
|
3689
5240
|
export interface DurationFromMillis extends decodeTo<Duration, Number> {
|
|
@@ -3706,6 +5257,9 @@ export interface DurationFromMillis extends decodeTo<Duration, Number> {
|
|
|
3706
5257
|
*/
|
|
3707
5258
|
export declare const DurationFromMillis: DurationFromMillis;
|
|
3708
5259
|
/**
|
|
5260
|
+
* Schema type for {@link BigDecimal}.
|
|
5261
|
+
*
|
|
5262
|
+
* @category Schemas
|
|
3709
5263
|
* @since 4.0.0
|
|
3710
5264
|
*/
|
|
3711
5265
|
export interface BigDecimal extends declare<BigDecimal_.BigDecimal> {
|
|
@@ -3721,6 +5275,9 @@ export interface BigDecimal extends declare<BigDecimal_.BigDecimal> {
|
|
|
3721
5275
|
*/
|
|
3722
5276
|
export declare const BigDecimal: BigDecimal;
|
|
3723
5277
|
/**
|
|
5278
|
+
* Schema type for {@link UnknownFromJsonString}.
|
|
5279
|
+
*
|
|
5280
|
+
* @category JSON
|
|
3724
5281
|
* @since 4.0.0
|
|
3725
5282
|
*/
|
|
3726
5283
|
export interface UnknownFromJsonString extends fromJsonString<Unknown> {
|
|
@@ -3749,6 +5306,9 @@ export interface UnknownFromJsonString extends fromJsonString<Unknown> {
|
|
|
3749
5306
|
*/
|
|
3750
5307
|
export declare const UnknownFromJsonString: fromJsonString<Unknown>;
|
|
3751
5308
|
/**
|
|
5309
|
+
* Schema type for {@link fromJsonString}.
|
|
5310
|
+
*
|
|
5311
|
+
* @category JSON
|
|
3752
5312
|
* @since 4.0.0
|
|
3753
5313
|
*/
|
|
3754
5314
|
export interface fromJsonString<S extends Top> extends decodeTo<S, String> {
|
|
@@ -3818,24 +5378,45 @@ export interface fromJsonString<S extends Top> extends decodeTo<S, String> {
|
|
|
3818
5378
|
*/
|
|
3819
5379
|
export declare function fromJsonString<S extends Top>(schema: S): fromJsonString<S>;
|
|
3820
5380
|
/**
|
|
5381
|
+
* Schema type for {@link File}.
|
|
5382
|
+
*
|
|
5383
|
+
* @category Schemas
|
|
3821
5384
|
* @since 4.0.0
|
|
3822
5385
|
*/
|
|
3823
5386
|
export interface File extends instanceOf<globalThis.File> {
|
|
3824
5387
|
}
|
|
3825
5388
|
/**
|
|
5389
|
+
* Schema for JavaScript `File` objects.
|
|
5390
|
+
*
|
|
5391
|
+
* The default JSON serializer encodes a `File` as `{ data, type, name, lastModified }`
|
|
5392
|
+
* where `data` is base64-encoded.
|
|
5393
|
+
*
|
|
5394
|
+
* @category Schemas
|
|
3826
5395
|
* @since 4.0.0
|
|
3827
5396
|
*/
|
|
3828
5397
|
export declare const File: File;
|
|
3829
5398
|
/**
|
|
5399
|
+
* Schema type for {@link FormData}.
|
|
5400
|
+
*
|
|
5401
|
+
* @category Schemas
|
|
3830
5402
|
* @since 4.0.0
|
|
3831
5403
|
*/
|
|
3832
5404
|
export interface FormData extends instanceOf<globalThis.FormData> {
|
|
3833
5405
|
}
|
|
3834
5406
|
/**
|
|
5407
|
+
* Schema for JavaScript `FormData` objects.
|
|
5408
|
+
*
|
|
5409
|
+
* The default JSON serializer encodes a `FormData` as an array of `[key, entry]`
|
|
5410
|
+
* pairs where each entry is tagged as `"String"` or `"File"`.
|
|
5411
|
+
*
|
|
5412
|
+
* @category Schemas
|
|
3835
5413
|
* @since 4.0.0
|
|
3836
5414
|
*/
|
|
3837
5415
|
export declare const FormData: FormData;
|
|
3838
5416
|
/**
|
|
5417
|
+
* Schema type for {@link fromFormData}.
|
|
5418
|
+
*
|
|
5419
|
+
* @category Schemas
|
|
3839
5420
|
* @since 4.0.0
|
|
3840
5421
|
*/
|
|
3841
5422
|
export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
@@ -3925,15 +5506,26 @@ export interface fromFormData<S extends Top> extends decodeTo<S, FormData> {
|
|
|
3925
5506
|
*/
|
|
3926
5507
|
export declare function fromFormData<S extends Top>(schema: S): fromFormData<S>;
|
|
3927
5508
|
/**
|
|
5509
|
+
* Schema type for {@link URLSearchParams}.
|
|
5510
|
+
*
|
|
5511
|
+
* @category Schemas
|
|
3928
5512
|
* @since 4.0.0
|
|
3929
5513
|
*/
|
|
3930
5514
|
export interface URLSearchParams extends instanceOf<globalThis.URLSearchParams> {
|
|
3931
5515
|
}
|
|
3932
5516
|
/**
|
|
5517
|
+
* Schema for JavaScript `URLSearchParams` objects.
|
|
5518
|
+
*
|
|
5519
|
+
* The default JSON serializer encodes a `URLSearchParams` as a query string.
|
|
5520
|
+
*
|
|
5521
|
+
* @category Schemas
|
|
3933
5522
|
* @since 4.0.0
|
|
3934
5523
|
*/
|
|
3935
5524
|
export declare const URLSearchParams: URLSearchParams;
|
|
3936
5525
|
/**
|
|
5526
|
+
* Schema type for {@link fromURLSearchParams}.
|
|
5527
|
+
*
|
|
5528
|
+
* @category Schemas
|
|
3937
5529
|
* @since 4.0.0
|
|
3938
5530
|
*/
|
|
3939
5531
|
export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearchParams> {
|
|
@@ -4014,6 +5606,9 @@ export interface fromURLSearchParams<S extends Top> extends decodeTo<S, URLSearc
|
|
|
4014
5606
|
*/
|
|
4015
5607
|
export declare function fromURLSearchParams<S extends Top>(schema: S): fromURLSearchParams<S>;
|
|
4016
5608
|
/**
|
|
5609
|
+
* Schema type for {@link Finite}.
|
|
5610
|
+
*
|
|
5611
|
+
* @category Schemas
|
|
4017
5612
|
* @since 4.0.0
|
|
4018
5613
|
*/
|
|
4019
5614
|
export interface Finite extends Number {
|
|
@@ -4025,6 +5620,9 @@ export interface Finite extends Number {
|
|
|
4025
5620
|
*/
|
|
4026
5621
|
export declare const Finite: Finite;
|
|
4027
5622
|
/**
|
|
5623
|
+
* Schema type for {@link Int}.
|
|
5624
|
+
*
|
|
5625
|
+
* @category Schemas
|
|
4028
5626
|
* @since 4.0.0
|
|
4029
5627
|
*/
|
|
4030
5628
|
export interface Int extends Number {
|
|
@@ -4036,6 +5634,9 @@ export interface Int extends Number {
|
|
|
4036
5634
|
*/
|
|
4037
5635
|
export declare const Int: Int;
|
|
4038
5636
|
/**
|
|
5637
|
+
* Schema type for {@link NumberFromString}.
|
|
5638
|
+
*
|
|
5639
|
+
* @category Schemas
|
|
4039
5640
|
* @since 4.0.0
|
|
4040
5641
|
*/
|
|
4041
5642
|
export interface NumberFromString extends decodeTo<Finite, String> {
|
|
@@ -4053,6 +5654,9 @@ export interface NumberFromString extends decodeTo<Finite, String> {
|
|
|
4053
5654
|
*/
|
|
4054
5655
|
export declare const NumberFromString: NumberFromString;
|
|
4055
5656
|
/**
|
|
5657
|
+
* Schema type for {@link FiniteFromString}.
|
|
5658
|
+
*
|
|
5659
|
+
* @category Schemas
|
|
4056
5660
|
* @since 4.0.0
|
|
4057
5661
|
*/
|
|
4058
5662
|
export interface FiniteFromString extends decodeTo<Finite, String> {
|
|
@@ -4071,6 +5675,9 @@ export interface FiniteFromString extends decodeTo<Finite, String> {
|
|
|
4071
5675
|
*/
|
|
4072
5676
|
export declare const FiniteFromString: FiniteFromString;
|
|
4073
5677
|
/**
|
|
5678
|
+
* Schema type for {@link Trimmed}.
|
|
5679
|
+
*
|
|
5680
|
+
* @category Schemas
|
|
4074
5681
|
* @since 4.0.0
|
|
4075
5682
|
*/
|
|
4076
5683
|
export interface Trimmed extends String {
|
|
@@ -4082,6 +5689,9 @@ export interface Trimmed extends String {
|
|
|
4082
5689
|
*/
|
|
4083
5690
|
export declare const Trimmed: Trimmed;
|
|
4084
5691
|
/**
|
|
5692
|
+
* Schema type for {@link Trim}.
|
|
5693
|
+
*
|
|
5694
|
+
* @category Schemas
|
|
4085
5695
|
* @since 4.0.0
|
|
4086
5696
|
*/
|
|
4087
5697
|
export interface Trim extends decodeTo<Trimmed, String> {
|
|
@@ -4099,6 +5709,9 @@ export interface Trim extends decodeTo<Trimmed, String> {
|
|
|
4099
5709
|
*/
|
|
4100
5710
|
export declare const Trim: Trim;
|
|
4101
5711
|
/**
|
|
5712
|
+
* A union schema for JavaScript property keys: `number | symbol | string`.
|
|
5713
|
+
*
|
|
5714
|
+
* @category Schemas
|
|
4102
5715
|
* @since 4.0.0
|
|
4103
5716
|
*/
|
|
4104
5717
|
export declare const PropertyKey: Union<readonly [Finite, Symbol, String]>;
|
|
@@ -4114,6 +5727,9 @@ export declare const StandardSchemaV1FailureResult: Struct<{
|
|
|
4114
5727
|
}>>;
|
|
4115
5728
|
}>;
|
|
4116
5729
|
/**
|
|
5730
|
+
* Schema type for {@link BooleanFromBit}.
|
|
5731
|
+
*
|
|
5732
|
+
* @category Schemas
|
|
4117
5733
|
* @since 4.0.0
|
|
4118
5734
|
*/
|
|
4119
5735
|
export interface BooleanFromBit extends decodeTo<Boolean, Literals<readonly [0, 1]>> {
|
|
@@ -4126,6 +5742,9 @@ export interface BooleanFromBit extends decodeTo<Boolean, Literals<readonly [0,
|
|
|
4126
5742
|
*/
|
|
4127
5743
|
export declare const BooleanFromBit: BooleanFromBit;
|
|
4128
5744
|
/**
|
|
5745
|
+
* Schema type for {@link Uint8Array}.
|
|
5746
|
+
*
|
|
5747
|
+
* @category Schemas
|
|
4129
5748
|
* @since 4.0.0
|
|
4130
5749
|
*/
|
|
4131
5750
|
export interface Uint8Array extends instanceOf<globalThis.Uint8Array<ArrayBufferLike>> {
|
|
@@ -4142,6 +5761,9 @@ export interface Uint8Array extends instanceOf<globalThis.Uint8Array<ArrayBuffer
|
|
|
4142
5761
|
*/
|
|
4143
5762
|
export declare const Uint8Array: Uint8Array;
|
|
4144
5763
|
/**
|
|
5764
|
+
* Schema type for {@link Uint8ArrayFromBase64}.
|
|
5765
|
+
*
|
|
5766
|
+
* @category Schemas
|
|
4145
5767
|
* @since 4.0.0
|
|
4146
5768
|
*/
|
|
4147
5769
|
export interface Uint8ArrayFromBase64 extends decodeTo<Uint8Array, String> {
|
|
@@ -4161,6 +5783,9 @@ export interface Uint8ArrayFromBase64 extends decodeTo<Uint8Array, String> {
|
|
|
4161
5783
|
*/
|
|
4162
5784
|
export declare const Uint8ArrayFromBase64: Uint8ArrayFromBase64;
|
|
4163
5785
|
/**
|
|
5786
|
+
* Schema type for {@link Uint8ArrayFromBase64Url}.
|
|
5787
|
+
*
|
|
5788
|
+
* @category Schemas
|
|
4164
5789
|
* @since 4.0.0
|
|
4165
5790
|
*/
|
|
4166
5791
|
export interface Uint8ArrayFromBase64Url extends decodeTo<Uint8Array, String> {
|
|
@@ -4180,6 +5805,9 @@ export interface Uint8ArrayFromBase64Url extends decodeTo<Uint8Array, String> {
|
|
|
4180
5805
|
*/
|
|
4181
5806
|
export declare const Uint8ArrayFromBase64Url: Uint8ArrayFromBase64Url;
|
|
4182
5807
|
/**
|
|
5808
|
+
* Schema type for {@link Uint8ArrayFromHex}.
|
|
5809
|
+
*
|
|
5810
|
+
* @category Schemas
|
|
4183
5811
|
* @since 4.0.0
|
|
4184
5812
|
*/
|
|
4185
5813
|
export interface Uint8ArrayFromHex extends decodeTo<Uint8Array, String> {
|
|
@@ -4199,6 +5827,9 @@ export interface Uint8ArrayFromHex extends decodeTo<Uint8Array, String> {
|
|
|
4199
5827
|
*/
|
|
4200
5828
|
export declare const Uint8ArrayFromHex: Uint8ArrayFromHex;
|
|
4201
5829
|
/**
|
|
5830
|
+
* Schema type for {@link DateTimeUtc}.
|
|
5831
|
+
*
|
|
5832
|
+
* @category DateTime
|
|
4202
5833
|
* @since 4.0.0
|
|
4203
5834
|
*/
|
|
4204
5835
|
export interface DateTimeUtc extends declare<DateTime.Utc> {
|
|
@@ -4215,6 +5846,9 @@ export interface DateTimeUtc extends declare<DateTime.Utc> {
|
|
|
4215
5846
|
*/
|
|
4216
5847
|
export declare const DateTimeUtc: DateTimeUtc;
|
|
4217
5848
|
/**
|
|
5849
|
+
* Schema type for {@link DateTimeUtcFromDate}.
|
|
5850
|
+
*
|
|
5851
|
+
* @category DateTime
|
|
4218
5852
|
* @since 4.0.0
|
|
4219
5853
|
*/
|
|
4220
5854
|
export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
@@ -4233,6 +5867,9 @@ export interface DateTimeUtcFromDate extends decodeTo<DateTimeUtc, Date> {
|
|
|
4233
5867
|
*/
|
|
4234
5868
|
export declare const DateTimeUtcFromDate: DateTimeUtcFromDate;
|
|
4235
5869
|
/**
|
|
5870
|
+
* Schema type for {@link DateTimeUtcFromString}.
|
|
5871
|
+
*
|
|
5872
|
+
* @category DateTime
|
|
4236
5873
|
* @since 4.0.0
|
|
4237
5874
|
*/
|
|
4238
5875
|
export interface DateTimeUtcFromString extends decodeTo<DateTimeUtc, String> {
|
|
@@ -4253,6 +5890,9 @@ export interface DateTimeUtcFromString extends decodeTo<DateTimeUtc, String> {
|
|
|
4253
5890
|
*/
|
|
4254
5891
|
export declare const DateTimeUtcFromString: DateTimeUtcFromString;
|
|
4255
5892
|
/**
|
|
5893
|
+
* Schema type for {@link DateTimeUtcFromMillis}.
|
|
5894
|
+
*
|
|
5895
|
+
* @category DateTime
|
|
4256
5896
|
* @since 4.0.0
|
|
4257
5897
|
*/
|
|
4258
5898
|
export interface DateTimeUtcFromMillis extends decodeTo<instanceOf<DateTime.Utc>, Number> {
|
|
@@ -4271,6 +5911,9 @@ export interface DateTimeUtcFromMillis extends decodeTo<instanceOf<DateTime.Utc>
|
|
|
4271
5911
|
*/
|
|
4272
5912
|
export declare const DateTimeUtcFromMillis: DateTimeUtcFromMillis;
|
|
4273
5913
|
/**
|
|
5914
|
+
* Schema type for {@link TimeZoneOffset}.
|
|
5915
|
+
*
|
|
5916
|
+
* @category DateTime
|
|
4274
5917
|
* @since 4.0.0
|
|
4275
5918
|
*/
|
|
4276
5919
|
export interface TimeZoneOffset extends declare<DateTime.TimeZone.Offset> {
|
|
@@ -4287,6 +5930,9 @@ export interface TimeZoneOffset extends declare<DateTime.TimeZone.Offset> {
|
|
|
4287
5930
|
*/
|
|
4288
5931
|
export declare const TimeZoneOffset: TimeZoneOffset;
|
|
4289
5932
|
/**
|
|
5933
|
+
* Schema type for {@link TimeZoneNamed}.
|
|
5934
|
+
*
|
|
5935
|
+
* @category DateTime
|
|
4290
5936
|
* @since 4.0.0
|
|
4291
5937
|
*/
|
|
4292
5938
|
export interface TimeZoneNamed extends declare<DateTime.TimeZone.Named> {
|
|
@@ -4303,6 +5949,9 @@ export interface TimeZoneNamed extends declare<DateTime.TimeZone.Named> {
|
|
|
4303
5949
|
*/
|
|
4304
5950
|
export declare const TimeZoneNamed: TimeZoneNamed;
|
|
4305
5951
|
/**
|
|
5952
|
+
* Schema type for {@link TimeZone}.
|
|
5953
|
+
*
|
|
5954
|
+
* @category DateTime
|
|
4306
5955
|
* @since 4.0.0
|
|
4307
5956
|
*/
|
|
4308
5957
|
export interface TimeZone extends declare<DateTime.TimeZone> {
|
|
@@ -4320,6 +5969,9 @@ export interface TimeZone extends declare<DateTime.TimeZone> {
|
|
|
4320
5969
|
*/
|
|
4321
5970
|
export declare const TimeZone: TimeZone;
|
|
4322
5971
|
/**
|
|
5972
|
+
* Schema type for {@link DateTimeZoned}.
|
|
5973
|
+
*
|
|
5974
|
+
* @category DateTime
|
|
4323
5975
|
* @since 4.0.0
|
|
4324
5976
|
*/
|
|
4325
5977
|
export interface DateTimeZoned extends declare<DateTime.Zoned> {
|
|
@@ -4337,6 +5989,14 @@ export interface DateTimeZoned extends declare<DateTime.Zoned> {
|
|
|
4337
5989
|
*/
|
|
4338
5990
|
export declare const DateTimeZoned: DateTimeZoned;
|
|
4339
5991
|
/**
|
|
5992
|
+
* Interface for schema-backed classes created with {@link Class}.
|
|
5993
|
+
*
|
|
5994
|
+
* A `Class` is a TypeScript class whose constructor validates its input
|
|
5995
|
+
* against a {@link Struct} schema. Instances are always structurally valid.
|
|
5996
|
+
*
|
|
5997
|
+
* The interface exposes the schema's `fields`, an `identifier` string, and
|
|
5998
|
+
* helpers such as `mapFields`, `annotate`, `check`, and `extend`.
|
|
5999
|
+
*
|
|
4340
6000
|
* @since 4.0.0
|
|
4341
6001
|
*/
|
|
4342
6002
|
export interface Class<Self, S extends Top & {
|
|
@@ -4365,6 +6025,10 @@ export interface Class<Self, S extends Top & {
|
|
|
4365
6025
|
}
|
|
4366
6026
|
type AddStaticMembers<C, Static> = C & Pick<Static, Exclude<keyof Static, keyof C>>;
|
|
4367
6027
|
/**
|
|
6028
|
+
* A {@link Class} that additionally exposes an `extend` method, allowing
|
|
6029
|
+
* subclasses to be derived with extra fields while inheriting all parent
|
|
6030
|
+
* fields and validation.
|
|
6031
|
+
*
|
|
4368
6032
|
* @since 4.0.0
|
|
4369
6033
|
*/
|
|
4370
6034
|
export interface ExtendableClass<Self, S extends Top & {
|
|
@@ -4373,21 +6037,181 @@ export interface ExtendableClass<Self, S extends Top & {
|
|
|
4373
6037
|
extend<Extended, Static = {}, Brand = {}>(identifier: string): <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>) => AddStaticMembers<ExtendableClass<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
|
|
4374
6038
|
}
|
|
4375
6039
|
/**
|
|
6040
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6041
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6042
|
+
* input (unless `disableValidation` is set in the options).
|
|
6043
|
+
*
|
|
6044
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6045
|
+
* type parameter can be used to add nominal brands.
|
|
6046
|
+
*
|
|
6047
|
+
* **Example** (Basic class)
|
|
6048
|
+
*
|
|
6049
|
+
* ```ts
|
|
6050
|
+
* import { Schema } from "effect"
|
|
6051
|
+
*
|
|
6052
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6053
|
+
* name: Schema.String,
|
|
6054
|
+
* age: Schema.Number
|
|
6055
|
+
* }) {}
|
|
6056
|
+
*
|
|
6057
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6058
|
+
* console.log(alice.name) // "Alice"
|
|
6059
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6060
|
+
* ```
|
|
6061
|
+
*
|
|
6062
|
+
* **Example** (Extending a class)
|
|
6063
|
+
*
|
|
6064
|
+
* ```ts
|
|
6065
|
+
* import { Schema } from "effect"
|
|
6066
|
+
*
|
|
6067
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6068
|
+
* name: Schema.String
|
|
6069
|
+
* }) {}
|
|
6070
|
+
*
|
|
6071
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6072
|
+
* breed: Schema.String
|
|
6073
|
+
* }) {}
|
|
6074
|
+
*
|
|
6075
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6076
|
+
* console.log(dog.name) // "Rex"
|
|
6077
|
+
* console.log(dog.breed) // "Labrador"
|
|
6078
|
+
* ```
|
|
6079
|
+
*
|
|
4376
6080
|
* @category Constructors
|
|
4377
6081
|
* @since 4.0.0
|
|
4378
6082
|
*/
|
|
4379
6083
|
export declare const Class: {
|
|
4380
6084
|
/**
|
|
6085
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6086
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6087
|
+
* input (unless `disableValidation` is set in the options).
|
|
6088
|
+
*
|
|
6089
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6090
|
+
* type parameter can be used to add nominal brands.
|
|
6091
|
+
*
|
|
6092
|
+
* **Example** (Basic class)
|
|
6093
|
+
*
|
|
6094
|
+
* ```ts
|
|
6095
|
+
* import { Schema } from "effect"
|
|
6096
|
+
*
|
|
6097
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6098
|
+
* name: Schema.String,
|
|
6099
|
+
* age: Schema.Number
|
|
6100
|
+
* }) {}
|
|
6101
|
+
*
|
|
6102
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6103
|
+
* console.log(alice.name) // "Alice"
|
|
6104
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6105
|
+
* ```
|
|
6106
|
+
*
|
|
6107
|
+
* **Example** (Extending a class)
|
|
6108
|
+
*
|
|
6109
|
+
* ```ts
|
|
6110
|
+
* import { Schema } from "effect"
|
|
6111
|
+
*
|
|
6112
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6113
|
+
* name: Schema.String
|
|
6114
|
+
* }) {}
|
|
6115
|
+
*
|
|
6116
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6117
|
+
* breed: Schema.String
|
|
6118
|
+
* }) {}
|
|
6119
|
+
*
|
|
6120
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6121
|
+
* console.log(dog.name) // "Rex"
|
|
6122
|
+
* console.log(dog.breed) // "Labrador"
|
|
6123
|
+
* ```
|
|
6124
|
+
*
|
|
4381
6125
|
* @category Constructors
|
|
4382
6126
|
* @since 4.0.0
|
|
4383
6127
|
*/
|
|
4384
6128
|
<Self, Brand = {}>(identifier: string): {
|
|
4385
6129
|
/**
|
|
6130
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6131
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6132
|
+
* input (unless `disableValidation` is set in the options).
|
|
6133
|
+
*
|
|
6134
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6135
|
+
* type parameter can be used to add nominal brands.
|
|
6136
|
+
*
|
|
6137
|
+
* **Example** (Basic class)
|
|
6138
|
+
*
|
|
6139
|
+
* ```ts
|
|
6140
|
+
* import { Schema } from "effect"
|
|
6141
|
+
*
|
|
6142
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6143
|
+
* name: Schema.String,
|
|
6144
|
+
* age: Schema.Number
|
|
6145
|
+
* }) {}
|
|
6146
|
+
*
|
|
6147
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6148
|
+
* console.log(alice.name) // "Alice"
|
|
6149
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6150
|
+
* ```
|
|
6151
|
+
*
|
|
6152
|
+
* **Example** (Extending a class)
|
|
6153
|
+
*
|
|
6154
|
+
* ```ts
|
|
6155
|
+
* import { Schema } from "effect"
|
|
6156
|
+
*
|
|
6157
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6158
|
+
* name: Schema.String
|
|
6159
|
+
* }) {}
|
|
6160
|
+
*
|
|
6161
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6162
|
+
* breed: Schema.String
|
|
6163
|
+
* }) {}
|
|
6164
|
+
*
|
|
6165
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6166
|
+
* console.log(dog.name) // "Rex"
|
|
6167
|
+
* console.log(dog.breed) // "Labrador"
|
|
6168
|
+
* ```
|
|
6169
|
+
*
|
|
4386
6170
|
* @category Constructors
|
|
4387
6171
|
* @since 4.0.0
|
|
4388
6172
|
*/
|
|
4389
6173
|
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): ExtendableClass<Self, Struct<Fields>, Brand>;
|
|
4390
6174
|
/**
|
|
6175
|
+
* Creates a schema-backed class whose constructor validates input against a
|
|
6176
|
+
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
|
|
6177
|
+
* input (unless `disableValidation` is set in the options).
|
|
6178
|
+
*
|
|
6179
|
+
* Pass the desired class type as the first type parameter. The second optional
|
|
6180
|
+
* type parameter can be used to add nominal brands.
|
|
6181
|
+
*
|
|
6182
|
+
* **Example** (Basic class)
|
|
6183
|
+
*
|
|
6184
|
+
* ```ts
|
|
6185
|
+
* import { Schema } from "effect"
|
|
6186
|
+
*
|
|
6187
|
+
* class Person extends Schema.Class<Person>("Person")({
|
|
6188
|
+
* name: Schema.String,
|
|
6189
|
+
* age: Schema.Number
|
|
6190
|
+
* }) {}
|
|
6191
|
+
*
|
|
6192
|
+
* const alice = new Person({ name: "Alice", age: 30 })
|
|
6193
|
+
* console.log(alice.name) // "Alice"
|
|
6194
|
+
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
|
|
6195
|
+
* ```
|
|
6196
|
+
*
|
|
6197
|
+
* **Example** (Extending a class)
|
|
6198
|
+
*
|
|
6199
|
+
* ```ts
|
|
6200
|
+
* import { Schema } from "effect"
|
|
6201
|
+
*
|
|
6202
|
+
* class Animal extends Schema.Class<Animal>("Animal")({
|
|
6203
|
+
* name: Schema.String
|
|
6204
|
+
* }) {}
|
|
6205
|
+
*
|
|
6206
|
+
* class Dog extends Animal.extend<Dog>("Dog")({
|
|
6207
|
+
* breed: Schema.String
|
|
6208
|
+
* }) {}
|
|
6209
|
+
*
|
|
6210
|
+
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
|
|
6211
|
+
* console.log(dog.name) // "Rex"
|
|
6212
|
+
* console.log(dog.breed) // "Labrador"
|
|
6213
|
+
* ```
|
|
6214
|
+
*
|
|
4391
6215
|
* @category Constructors
|
|
4392
6216
|
* @since 4.0.0
|
|
4393
6217
|
*/
|
|
@@ -4395,21 +6219,105 @@ export declare const Class: {
|
|
|
4395
6219
|
};
|
|
4396
6220
|
};
|
|
4397
6221
|
/**
|
|
6222
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6223
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6224
|
+
* discrimination patterns.
|
|
6225
|
+
*
|
|
6226
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6227
|
+
* it defaults to the `tag` value.
|
|
6228
|
+
*
|
|
6229
|
+
* **Example** (Tagged class)
|
|
6230
|
+
*
|
|
6231
|
+
* ```ts
|
|
6232
|
+
* import { Schema } from "effect"
|
|
6233
|
+
*
|
|
6234
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6235
|
+
* radius: Schema.Number
|
|
6236
|
+
* }) {}
|
|
6237
|
+
*
|
|
6238
|
+
* const c = new Circle({ radius: 5 })
|
|
6239
|
+
* console.log(c._tag) // "Circle"
|
|
6240
|
+
* console.log(c.radius) // 5
|
|
6241
|
+
* ```
|
|
6242
|
+
*
|
|
4398
6243
|
* @category Constructors
|
|
4399
6244
|
* @since 4.0.0
|
|
4400
6245
|
*/
|
|
4401
6246
|
export declare const TaggedClass: {
|
|
4402
6247
|
/**
|
|
6248
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6249
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6250
|
+
* discrimination patterns.
|
|
6251
|
+
*
|
|
6252
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6253
|
+
* it defaults to the `tag` value.
|
|
6254
|
+
*
|
|
6255
|
+
* **Example** (Tagged class)
|
|
6256
|
+
*
|
|
6257
|
+
* ```ts
|
|
6258
|
+
* import { Schema } from "effect"
|
|
6259
|
+
*
|
|
6260
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6261
|
+
* radius: Schema.Number
|
|
6262
|
+
* }) {}
|
|
6263
|
+
*
|
|
6264
|
+
* const c = new Circle({ radius: 5 })
|
|
6265
|
+
* console.log(c._tag) // "Circle"
|
|
6266
|
+
* console.log(c.radius) // 5
|
|
6267
|
+
* ```
|
|
6268
|
+
*
|
|
4403
6269
|
* @category Constructors
|
|
4404
6270
|
* @since 4.0.0
|
|
4405
6271
|
*/
|
|
4406
6272
|
<Self, Brand = {}>(identifier?: string): {
|
|
4407
6273
|
/**
|
|
6274
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6275
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6276
|
+
* discrimination patterns.
|
|
6277
|
+
*
|
|
6278
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6279
|
+
* it defaults to the `tag` value.
|
|
6280
|
+
*
|
|
6281
|
+
* **Example** (Tagged class)
|
|
6282
|
+
*
|
|
6283
|
+
* ```ts
|
|
6284
|
+
* import { Schema } from "effect"
|
|
6285
|
+
*
|
|
6286
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6287
|
+
* radius: Schema.Number
|
|
6288
|
+
* }) {}
|
|
6289
|
+
*
|
|
6290
|
+
* const c = new Circle({ radius: 5 })
|
|
6291
|
+
* console.log(c._tag) // "Circle"
|
|
6292
|
+
* console.log(c.radius) // 5
|
|
6293
|
+
* ```
|
|
6294
|
+
*
|
|
4408
6295
|
* @category Constructors
|
|
4409
6296
|
* @since 4.0.0
|
|
4410
6297
|
*/
|
|
4411
6298
|
<Tag extends string, const Fields extends Struct.Fields>(tag: Tag, fields: Fields, annotations?: Annotations.Declaration<Self, readonly [TaggedStruct<Tag, Fields>]>): ExtendableClass<Self, TaggedStruct<Tag, Fields>, Brand>;
|
|
4412
6299
|
/**
|
|
6300
|
+
* Like {@link Class} but automatically adds a `_tag` literal field set to the
|
|
6301
|
+
* given `tag` value. This makes instances compatible with tagged union
|
|
6302
|
+
* discrimination patterns.
|
|
6303
|
+
*
|
|
6304
|
+
* The optional `identifier` parameter overrides the schema identifier;
|
|
6305
|
+
* it defaults to the `tag` value.
|
|
6306
|
+
*
|
|
6307
|
+
* **Example** (Tagged class)
|
|
6308
|
+
*
|
|
6309
|
+
* ```ts
|
|
6310
|
+
* import { Schema } from "effect"
|
|
6311
|
+
*
|
|
6312
|
+
* class Circle extends Schema.TaggedClass<Circle>()("Circle", {
|
|
6313
|
+
* radius: Schema.Number
|
|
6314
|
+
* }) {}
|
|
6315
|
+
*
|
|
6316
|
+
* const c = new Circle({ radius: 5 })
|
|
6317
|
+
* console.log(c._tag) // "Circle"
|
|
6318
|
+
* console.log(c.radius) // 5
|
|
6319
|
+
* ```
|
|
6320
|
+
*
|
|
4413
6321
|
* @category Constructors
|
|
4414
6322
|
* @since 4.0.0
|
|
4415
6323
|
*/
|
|
@@ -4421,6 +6329,10 @@ export declare const TaggedClass: {
|
|
|
4421
6329
|
};
|
|
4422
6330
|
};
|
|
4423
6331
|
/**
|
|
6332
|
+
* Interface for schema-backed error classes created with {@link ErrorClass}.
|
|
6333
|
+
* Extends {@link ExtendableClass} and is also a `YieldableError`, so instances
|
|
6334
|
+
* can be yielded inside `Effect.gen` as failures.
|
|
6335
|
+
*
|
|
4424
6336
|
* @since 4.0.0
|
|
4425
6337
|
*/
|
|
4426
6338
|
export interface ErrorClass<Self, S extends Top & {
|
|
@@ -4428,21 +6340,97 @@ export interface ErrorClass<Self, S extends Top & {
|
|
|
4428
6340
|
}, Inherited> extends ExtendableClass<Self, S, Inherited> {
|
|
4429
6341
|
}
|
|
4430
6342
|
/**
|
|
6343
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6344
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6345
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6346
|
+
* `Effect.gen`.
|
|
6347
|
+
*
|
|
6348
|
+
* **Example** (Schema-backed error)
|
|
6349
|
+
*
|
|
6350
|
+
* ```ts
|
|
6351
|
+
* import { Effect, Schema } from "effect"
|
|
6352
|
+
*
|
|
6353
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6354
|
+
* id: Schema.Number
|
|
6355
|
+
* }) {}
|
|
6356
|
+
*
|
|
6357
|
+
* const program = Effect.gen(function*() {
|
|
6358
|
+
* yield* new NotFound({ id: 1 })
|
|
6359
|
+
* })
|
|
6360
|
+
* ```
|
|
6361
|
+
*
|
|
4431
6362
|
* @category Constructors
|
|
4432
6363
|
* @since 4.0.0
|
|
4433
6364
|
*/
|
|
4434
6365
|
export declare const ErrorClass: {
|
|
4435
6366
|
/**
|
|
6367
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6368
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6369
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6370
|
+
* `Effect.gen`.
|
|
6371
|
+
*
|
|
6372
|
+
* **Example** (Schema-backed error)
|
|
6373
|
+
*
|
|
6374
|
+
* ```ts
|
|
6375
|
+
* import { Effect, Schema } from "effect"
|
|
6376
|
+
*
|
|
6377
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6378
|
+
* id: Schema.Number
|
|
6379
|
+
* }) {}
|
|
6380
|
+
*
|
|
6381
|
+
* const program = Effect.gen(function*() {
|
|
6382
|
+
* yield* new NotFound({ id: 1 })
|
|
6383
|
+
* })
|
|
6384
|
+
* ```
|
|
6385
|
+
*
|
|
4436
6386
|
* @category Constructors
|
|
4437
6387
|
* @since 4.0.0
|
|
4438
6388
|
*/
|
|
4439
6389
|
<Self, Brand = {}>(identifier: string): {
|
|
4440
6390
|
/**
|
|
6391
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6392
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6393
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6394
|
+
* `Effect.gen`.
|
|
6395
|
+
*
|
|
6396
|
+
* **Example** (Schema-backed error)
|
|
6397
|
+
*
|
|
6398
|
+
* ```ts
|
|
6399
|
+
* import { Effect, Schema } from "effect"
|
|
6400
|
+
*
|
|
6401
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6402
|
+
* id: Schema.Number
|
|
6403
|
+
* }) {}
|
|
6404
|
+
*
|
|
6405
|
+
* const program = Effect.gen(function*() {
|
|
6406
|
+
* yield* new NotFound({ id: 1 })
|
|
6407
|
+
* })
|
|
6408
|
+
* ```
|
|
6409
|
+
*
|
|
4441
6410
|
* @category Constructors
|
|
4442
6411
|
* @since 4.0.0
|
|
4443
6412
|
*/
|
|
4444
6413
|
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): ErrorClass<Self, Struct<Fields>, Cause_.YieldableError & Brand>;
|
|
4445
6414
|
/**
|
|
6415
|
+
* Creates a schema-backed error class that can be used as a typed,
|
|
6416
|
+
* yieldable error in Effect programs. Combines {@link Class} validation with
|
|
6417
|
+
* the `YieldableError` interface so instances can be yielded directly inside
|
|
6418
|
+
* `Effect.gen`.
|
|
6419
|
+
*
|
|
6420
|
+
* **Example** (Schema-backed error)
|
|
6421
|
+
*
|
|
6422
|
+
* ```ts
|
|
6423
|
+
* import { Effect, Schema } from "effect"
|
|
6424
|
+
*
|
|
6425
|
+
* class NotFound extends Schema.ErrorClass<NotFound>("NotFound")({
|
|
6426
|
+
* id: Schema.Number
|
|
6427
|
+
* }) {}
|
|
6428
|
+
*
|
|
6429
|
+
* const program = Effect.gen(function*() {
|
|
6430
|
+
* yield* new NotFound({ id: 1 })
|
|
6431
|
+
* })
|
|
6432
|
+
* ```
|
|
6433
|
+
*
|
|
4446
6434
|
* @category Constructors
|
|
4447
6435
|
* @since 4.0.0
|
|
4448
6436
|
*/
|
|
@@ -4450,21 +6438,93 @@ export declare const ErrorClass: {
|
|
|
4450
6438
|
};
|
|
4451
6439
|
};
|
|
4452
6440
|
/**
|
|
6441
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6442
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6443
|
+
* union member.
|
|
6444
|
+
*
|
|
6445
|
+
* **Example** (Tagged error class)
|
|
6446
|
+
*
|
|
6447
|
+
* ```ts
|
|
6448
|
+
* import { Effect, Schema } from "effect"
|
|
6449
|
+
*
|
|
6450
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6451
|
+
* id: Schema.Number
|
|
6452
|
+
* }) {}
|
|
6453
|
+
*
|
|
6454
|
+
* const program = Effect.gen(function*() {
|
|
6455
|
+
* yield* new NotFound({ id: 42 })
|
|
6456
|
+
* })
|
|
6457
|
+
* ```
|
|
6458
|
+
*
|
|
4453
6459
|
* @category Constructors
|
|
4454
6460
|
* @since 4.0.0
|
|
4455
6461
|
*/
|
|
4456
6462
|
export declare const TaggedErrorClass: {
|
|
4457
6463
|
/**
|
|
6464
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6465
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6466
|
+
* union member.
|
|
6467
|
+
*
|
|
6468
|
+
* **Example** (Tagged error class)
|
|
6469
|
+
*
|
|
6470
|
+
* ```ts
|
|
6471
|
+
* import { Effect, Schema } from "effect"
|
|
6472
|
+
*
|
|
6473
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6474
|
+
* id: Schema.Number
|
|
6475
|
+
* }) {}
|
|
6476
|
+
*
|
|
6477
|
+
* const program = Effect.gen(function*() {
|
|
6478
|
+
* yield* new NotFound({ id: 42 })
|
|
6479
|
+
* })
|
|
6480
|
+
* ```
|
|
6481
|
+
*
|
|
4458
6482
|
* @category Constructors
|
|
4459
6483
|
* @since 4.0.0
|
|
4460
6484
|
*/
|
|
4461
6485
|
<Self, Brand = {}>(identifier?: string): {
|
|
4462
6486
|
/**
|
|
6487
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6488
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6489
|
+
* union member.
|
|
6490
|
+
*
|
|
6491
|
+
* **Example** (Tagged error class)
|
|
6492
|
+
*
|
|
6493
|
+
* ```ts
|
|
6494
|
+
* import { Effect, Schema } from "effect"
|
|
6495
|
+
*
|
|
6496
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6497
|
+
* id: Schema.Number
|
|
6498
|
+
* }) {}
|
|
6499
|
+
*
|
|
6500
|
+
* const program = Effect.gen(function*() {
|
|
6501
|
+
* yield* new NotFound({ id: 42 })
|
|
6502
|
+
* })
|
|
6503
|
+
* ```
|
|
6504
|
+
*
|
|
4463
6505
|
* @category Constructors
|
|
4464
6506
|
* @since 4.0.0
|
|
4465
6507
|
*/
|
|
4466
6508
|
<Tag extends string, const Fields extends Struct.Fields>(tag: Tag, fields: Fields, annotations?: Annotations.Declaration<Self, readonly [TaggedStruct<Tag, Fields>]>): ErrorClass<Self, TaggedStruct<Tag, Fields>, Cause_.YieldableError & Brand>;
|
|
4467
6509
|
/**
|
|
6510
|
+
* Like {@link ErrorClass} but automatically adds a `_tag` literal field. The
|
|
6511
|
+
* resulting class is both a schema-validated, yieldable error and a tagged
|
|
6512
|
+
* union member.
|
|
6513
|
+
*
|
|
6514
|
+
* **Example** (Tagged error class)
|
|
6515
|
+
*
|
|
6516
|
+
* ```ts
|
|
6517
|
+
* import { Effect, Schema } from "effect"
|
|
6518
|
+
*
|
|
6519
|
+
* class NotFound extends Schema.TaggedErrorClass<NotFound>()("NotFound", {
|
|
6520
|
+
* id: Schema.Number
|
|
6521
|
+
* }) {}
|
|
6522
|
+
*
|
|
6523
|
+
* const program = Effect.gen(function*() {
|
|
6524
|
+
* yield* new NotFound({ id: 42 })
|
|
6525
|
+
* })
|
|
6526
|
+
* ```
|
|
6527
|
+
*
|
|
4468
6528
|
* @category Constructors
|
|
4469
6529
|
* @since 4.0.0
|
|
4470
6530
|
*/
|
|
@@ -4476,16 +6536,43 @@ export declare const TaggedErrorClass: {
|
|
|
4476
6536
|
};
|
|
4477
6537
|
};
|
|
4478
6538
|
/**
|
|
6539
|
+
* A thunk that, given the `fast-check` module, returns an `Arbitrary<T>`.
|
|
6540
|
+
* Use this type when you need to defer instantiation of the arbitrary, for
|
|
6541
|
+
* example to support recursive schemas.
|
|
6542
|
+
*
|
|
4479
6543
|
* @category Arbitrary
|
|
4480
6544
|
* @since 4.0.0
|
|
4481
6545
|
*/
|
|
4482
6546
|
export type LazyArbitrary<T> = (fc: typeof FastCheck) => FastCheck.Arbitrary<T>;
|
|
4483
6547
|
/**
|
|
6548
|
+
* Derives a {@link LazyArbitrary} from a schema. The result is memoized so
|
|
6549
|
+
* repeated calls with the same schema are cheap.
|
|
6550
|
+
*
|
|
6551
|
+
* Prefer {@link toArbitrary} when you just need the arbitrary directly.
|
|
6552
|
+
*
|
|
4484
6553
|
* @category Arbitrary
|
|
4485
6554
|
* @since 4.0.0
|
|
4486
6555
|
*/
|
|
4487
6556
|
export declare function toArbitraryLazy<S extends Top>(schema: S): LazyArbitrary<S["Type"]>;
|
|
4488
6557
|
/**
|
|
6558
|
+
* Derives a `fast-check` `Arbitrary` from a schema for property-based
|
|
6559
|
+
* testing. The derived arbitrary generates values that satisfy the schema.
|
|
6560
|
+
*
|
|
6561
|
+
* **Example** (Generating arbitrary values)
|
|
6562
|
+
*
|
|
6563
|
+
* ```ts
|
|
6564
|
+
* import { Schema } from "effect"
|
|
6565
|
+
* import * as FastCheck from "fast-check"
|
|
6566
|
+
*
|
|
6567
|
+
* const PersonArb = Schema.toArbitrary(
|
|
6568
|
+
* Schema.Struct({ name: Schema.String, age: Schema.Number })
|
|
6569
|
+
* )
|
|
6570
|
+
*
|
|
6571
|
+
* // Sample a random value
|
|
6572
|
+
* const sample = FastCheck.sample(PersonArb, 1)[0]
|
|
6573
|
+
* console.log(typeof sample.name) // "string"
|
|
6574
|
+
* ```
|
|
6575
|
+
*
|
|
4489
6576
|
* @category Arbitrary
|
|
4490
6577
|
* @since 4.0.0
|
|
4491
6578
|
*/
|
|
@@ -4501,6 +6588,13 @@ export declare function toArbitrary<S extends Top>(schema: S): FastCheck.Arbitra
|
|
|
4501
6588
|
*/
|
|
4502
6589
|
export declare function overrideToFormatter<S extends Top>(toFormatter: () => Formatter<S["Type"]>): (self: S) => S["~rebuild.out"];
|
|
4503
6590
|
/**
|
|
6591
|
+
* Derives a string formatter function from a schema. The formatter converts
|
|
6592
|
+
* a value to its human-readable string representation, recursing into structs,
|
|
6593
|
+
* arrays, and unions.
|
|
6594
|
+
*
|
|
6595
|
+
* The optional `onBefore` hook lets you intercept specific AST nodes before
|
|
6596
|
+
* the default formatting logic runs.
|
|
6597
|
+
*
|
|
4504
6598
|
* @category Formatter
|
|
4505
6599
|
* @since 4.0.0
|
|
4506
6600
|
*/
|
|
@@ -4508,26 +6602,46 @@ export declare function toFormatter<T>(schema: Schema<T>, options?: {
|
|
|
4508
6602
|
readonly onBefore?: ((ast: AST.AST, recur: (ast: AST.AST) => Formatter<any>) => Formatter<any> | undefined) | undefined;
|
|
4509
6603
|
}): Formatter<T>;
|
|
4510
6604
|
/**
|
|
4511
|
-
*
|
|
4512
|
-
*
|
|
4513
|
-
*
|
|
4514
|
-
* the schema invariant.
|
|
6605
|
+
* Overrides the equivalence derivation for a schema by supplying a custom
|
|
6606
|
+
* `Equivalence`. Use this when the default structural equivalence derived by
|
|
6607
|
+
* {@link toEquivalence} is not appropriate for a type.
|
|
4515
6608
|
*
|
|
4516
6609
|
* @category Equivalence
|
|
4517
6610
|
* @since 4.0.0
|
|
4518
6611
|
*/
|
|
4519
6612
|
export declare function overrideToEquivalence<S extends Top>(toEquivalence: () => Equivalence.Equivalence<S["Type"]>): (self: S) => S["~rebuild.out"];
|
|
4520
6613
|
/**
|
|
6614
|
+
* Derives an `Equivalence` from a schema. Two values are considered equal when
|
|
6615
|
+
* every field (and nested field) compares equal according to the schema
|
|
6616
|
+
* structure.
|
|
6617
|
+
*
|
|
6618
|
+
* **Example** (Struct equivalence)
|
|
6619
|
+
*
|
|
6620
|
+
* ```ts
|
|
6621
|
+
* import { Schema } from "effect"
|
|
6622
|
+
*
|
|
6623
|
+
* const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
|
|
6624
|
+
*
|
|
6625
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
|
|
6626
|
+
* console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // false
|
|
6627
|
+
* ```
|
|
6628
|
+
*
|
|
4521
6629
|
* @category Equivalence
|
|
4522
6630
|
* @since 4.0.0
|
|
4523
6631
|
*/
|
|
4524
6632
|
export declare function toEquivalence<T>(schema: Schema<T>): Equivalence.Equivalence<T>;
|
|
4525
6633
|
/**
|
|
6634
|
+
* Derives an intermediate `SchemaRepresentation.Document` from a schema. This
|
|
6635
|
+
* document is used internally by {@link toJsonSchemaDocument} and related
|
|
6636
|
+
* functions to produce JSON Schema output.
|
|
6637
|
+
*
|
|
4526
6638
|
* @category Representation
|
|
4527
6639
|
* @since 4.0.0
|
|
4528
6640
|
*/
|
|
4529
6641
|
export declare function toRepresentation(schema: Top): SchemaRepresentation.Document;
|
|
4530
6642
|
/**
|
|
6643
|
+
* Options for {@link toJsonSchemaDocument}.
|
|
6644
|
+
*
|
|
4531
6645
|
* @since 4.0.0
|
|
4532
6646
|
*/
|
|
4533
6647
|
export interface ToJsonSchemaOptions {
|
|
@@ -4557,16 +6671,25 @@ export interface ToJsonSchemaOptions {
|
|
|
4557
6671
|
*/
|
|
4558
6672
|
export declare function toJsonSchemaDocument(schema: Top, options?: ToJsonSchemaOptions): JsonSchema.Document<"draft-2020-12">;
|
|
4559
6673
|
/**
|
|
6674
|
+
* Derives a canonical JSON codec from a schema. The encoded form is `unknown`
|
|
6675
|
+
* (any JSON-compatible value), decoded to the schema's `Type`.
|
|
6676
|
+
*
|
|
4560
6677
|
* @category Canonical Codecs
|
|
4561
6678
|
* @since 4.0.0
|
|
4562
6679
|
*/
|
|
4563
|
-
export declare function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T,
|
|
6680
|
+
export declare function toCodecJson<T, E, RD, RE>(schema: Codec<T, E, RD, RE>): Codec<T, Json, RD, RE>;
|
|
4564
6681
|
/**
|
|
6682
|
+
* Derives an isomorphism codec from a schema. The encoded form is the
|
|
6683
|
+
* schema's `Iso` type — the intermediate representation used for round-tripping.
|
|
6684
|
+
*
|
|
4565
6685
|
* @category Canonical Codecs
|
|
4566
6686
|
* @since 4.0.0
|
|
4567
6687
|
*/
|
|
4568
6688
|
export declare function toCodecIso<S extends Top>(schema: S): Codec<S["Type"], S["Iso"]>;
|
|
4569
6689
|
/**
|
|
6690
|
+
* A {@link Tree} of `string | undefined` nodes. Leaf values are either a
|
|
6691
|
+
* string representation or `undefined` for opaque/declaration types.
|
|
6692
|
+
*
|
|
4570
6693
|
* @category Canonical Codecs
|
|
4571
6694
|
* @since 4.0.0
|
|
4572
6695
|
*/
|
|
@@ -4606,26 +6729,40 @@ type XmlEncoderOptions = {
|
|
|
4606
6729
|
readonly sortKeys?: boolean | undefined;
|
|
4607
6730
|
};
|
|
4608
6731
|
/**
|
|
6732
|
+
* Derives an XML encoder from a codec. Encodes a value to an XML string by
|
|
6733
|
+
* first converting it through {@link toCodecStringTree}, then serializing the
|
|
6734
|
+
* resulting tree to XML.
|
|
6735
|
+
*
|
|
4609
6736
|
* @category Canonical Codecs
|
|
4610
6737
|
* @since 4.0.0
|
|
4611
6738
|
*/
|
|
4612
6739
|
export declare function toEncoderXml<T, E, RD, RE>(codec: Codec<T, E, RD, RE>, options?: XmlEncoderOptions): (t: T) => Effect.Effect<string, SchemaError, RE>;
|
|
4613
6740
|
/**
|
|
6741
|
+
* Derives an `Iso` optic from a schema that isomorphically converts between
|
|
6742
|
+
* the schema's `Type` and its `Iso` (intermediate / serialized form).
|
|
6743
|
+
*
|
|
4614
6744
|
* @category Optic
|
|
4615
6745
|
* @since 4.0.0
|
|
4616
6746
|
*/
|
|
4617
6747
|
export declare function toIso<S extends Top>(schema: S): Optic_.Iso<S["Type"], S["Iso"]>;
|
|
4618
6748
|
/**
|
|
6749
|
+
* Returns an identity `Iso` over the schema's source (`Type`) side.
|
|
6750
|
+
*
|
|
4619
6751
|
* @category Optic
|
|
4620
6752
|
* @since 4.0.0
|
|
4621
6753
|
*/
|
|
4622
6754
|
export declare function toIsoSource<S extends Top>(_: S): Optic_.Iso<S["Type"], S["Type"]>;
|
|
4623
6755
|
/**
|
|
6756
|
+
* Returns an identity `Iso` over the schema's focus (`Iso`) side.
|
|
6757
|
+
*
|
|
4624
6758
|
* @category Optic
|
|
4625
6759
|
* @since 4.0.0
|
|
4626
6760
|
*/
|
|
4627
6761
|
export declare function toIsoFocus<S extends Top>(_: S): Optic_.Iso<S["Iso"], S["Iso"]>;
|
|
4628
6762
|
/**
|
|
6763
|
+
* The schema type returned by {@link overrideToCodecIso}. Carries a custom
|
|
6764
|
+
* `Iso` type parameter and exposes the original `schema`.
|
|
6765
|
+
*
|
|
4629
6766
|
* @category Optic
|
|
4630
6767
|
* @since 4.0.0
|
|
4631
6768
|
*/
|
|
@@ -4634,10 +6771,11 @@ export interface overrideToCodecIso<S extends Top, Iso> extends Bottom<S["Type"]
|
|
|
4634
6771
|
readonly schema: S;
|
|
4635
6772
|
}
|
|
4636
6773
|
/**
|
|
4637
|
-
*
|
|
4638
|
-
*
|
|
4639
|
-
*
|
|
4640
|
-
* the
|
|
6774
|
+
* Overrides the ISO codec derivation for a schema by providing a target codec
|
|
6775
|
+
* and explicit `decode`/`encode` getters. The resulting schema carries a
|
|
6776
|
+
* custom `Iso` type, which changes the schema's type parameter — use
|
|
6777
|
+
* {@link overrideToCodecIso} when the default ISO transformation is not
|
|
6778
|
+
* appropriate.
|
|
4641
6779
|
*
|
|
4642
6780
|
* @category Optic
|
|
4643
6781
|
* @since 4.0.0
|
|
@@ -4647,6 +6785,10 @@ export declare function overrideToCodecIso<S extends Top, Iso>(to: Codec<Iso>, t
|
|
|
4647
6785
|
readonly encode: Getter.Getter<Iso, S["Type"]>;
|
|
4648
6786
|
}): (schema: S) => overrideToCodecIso<S, Iso>;
|
|
4649
6787
|
/**
|
|
6788
|
+
* Derives a JSON Patch differ from a codec. Serializes values to JSON (via
|
|
6789
|
+
* {@link toCodecJson}), computes RFC 6902 JSON Patch operations between old
|
|
6790
|
+
* and new values, and can apply patches back to the typed value.
|
|
6791
|
+
*
|
|
4650
6792
|
* @category JsonPatch
|
|
4651
6793
|
* @since 4.0.0
|
|
4652
6794
|
*/
|
|
@@ -4657,6 +6799,9 @@ export declare function toDifferJsonPatch<T, E>(schema: Codec<T, E>): Differ<T,
|
|
|
4657
6799
|
*/
|
|
4658
6800
|
export type Tree<Node> = Node | TreeRecord<Node> | ReadonlyArray<Tree<Node>>;
|
|
4659
6801
|
/**
|
|
6802
|
+
* A record node in a {@link Tree}: an object mapping string keys to child
|
|
6803
|
+
* `Tree` nodes.
|
|
6804
|
+
*
|
|
4660
6805
|
* @category Tree
|
|
4661
6806
|
* @since 4.0.0
|
|
4662
6807
|
*/
|
|
@@ -4664,22 +6809,35 @@ export interface TreeRecord<A> {
|
|
|
4664
6809
|
readonly [x: string]: Tree<A>;
|
|
4665
6810
|
}
|
|
4666
6811
|
/**
|
|
6812
|
+
* Creates a recursive schema for a {@link Tree} of values described by `node`.
|
|
6813
|
+
* The resulting schema accepts a single node value, an array of trees, or an
|
|
6814
|
+
* object whose values are trees.
|
|
6815
|
+
*
|
|
4667
6816
|
* @category Tree
|
|
4668
6817
|
* @since 4.0.0
|
|
4669
6818
|
*/
|
|
4670
6819
|
export declare function Tree<S extends Top>(node: S): Union<readonly [S, $Array<suspend<Codec<Tree<S["Type"]>, Tree<S["Encoded"]>, S["DecodingServices"], S["EncodingServices"]>>>, $Record<String, suspend<Codec<Tree<S["Type"]>, Tree<S["Encoded"]>, S["DecodingServices"], S["EncodingServices"]>>>]>;
|
|
4671
6820
|
/**
|
|
6821
|
+
* Recursive TypeScript type for any valid immutable JSON value: `null`,
|
|
6822
|
+
* `number`, `boolean`, `string`, a readonly array of `Json` values, or a
|
|
6823
|
+
* readonly record of `string → Json`. For the corresponding schema, see the
|
|
6824
|
+
* {@link Json} const.
|
|
6825
|
+
*
|
|
4672
6826
|
* @category JSON
|
|
4673
6827
|
* @since 4.0.0
|
|
4674
6828
|
*/
|
|
4675
6829
|
export type Json = null | number | boolean | string | JsonArray | JsonObject;
|
|
4676
6830
|
/**
|
|
6831
|
+
* A readonly array of {@link Json} values.
|
|
6832
|
+
*
|
|
4677
6833
|
* @category JSON
|
|
4678
6834
|
* @since 4.0.0
|
|
4679
6835
|
*/
|
|
4680
6836
|
export interface JsonArray extends ReadonlyArray<Json> {
|
|
4681
6837
|
}
|
|
4682
6838
|
/**
|
|
6839
|
+
* A readonly record whose values are {@link Json} values.
|
|
6840
|
+
*
|
|
4683
6841
|
* @category JSON
|
|
4684
6842
|
* @since 4.0.0
|
|
4685
6843
|
*/
|
|
@@ -4687,6 +6845,17 @@ export interface JsonObject {
|
|
|
4687
6845
|
readonly [x: string]: Json;
|
|
4688
6846
|
}
|
|
4689
6847
|
/**
|
|
6848
|
+
* Schema that accepts and validates any immutable JSON-compatible value.
|
|
6849
|
+
*
|
|
6850
|
+
* **Example** (Validating a JSON value)
|
|
6851
|
+
*
|
|
6852
|
+
* ```ts
|
|
6853
|
+
* import { Schema } from "effect"
|
|
6854
|
+
*
|
|
6855
|
+
* const result = Schema.decodeUnknownOption(Schema.Json)({ key: [1, true, null] })
|
|
6856
|
+
* console.log(result._tag) // "Some"
|
|
6857
|
+
* ```
|
|
6858
|
+
*
|
|
4690
6859
|
* @category JSON
|
|
4691
6860
|
* @since 4.0.0
|
|
4692
6861
|
*/
|
|
@@ -4697,12 +6866,16 @@ export declare const Json: Codec<Json>;
|
|
|
4697
6866
|
*/
|
|
4698
6867
|
export type MutableJson = null | number | boolean | string | MutableJsonArray | MutableJsonObject;
|
|
4699
6868
|
/**
|
|
6869
|
+
* A mutable array of {@link MutableJson} values.
|
|
6870
|
+
*
|
|
4700
6871
|
* @category JSON
|
|
4701
6872
|
* @since 4.0.0
|
|
4702
6873
|
*/
|
|
4703
6874
|
export interface MutableJsonArray extends Array<MutableJson> {
|
|
4704
6875
|
}
|
|
4705
6876
|
/**
|
|
6877
|
+
* A mutable record whose values are {@link MutableJson} values.
|
|
6878
|
+
*
|
|
4706
6879
|
* @category JSON
|
|
4707
6880
|
* @since 4.0.0
|
|
4708
6881
|
*/
|
|
@@ -4710,6 +6883,9 @@ export interface MutableJsonObject {
|
|
|
4710
6883
|
[x: string]: MutableJson;
|
|
4711
6884
|
}
|
|
4712
6885
|
/**
|
|
6886
|
+
* Schema that accepts any mutable JSON-compatible value. See {@link Json} for
|
|
6887
|
+
* the immutable variant.
|
|
6888
|
+
*
|
|
4713
6889
|
* @category JSON
|
|
4714
6890
|
* @since 4.0.0
|
|
4715
6891
|
*/
|
|
@@ -4722,6 +6898,13 @@ export declare const MutableJson: Codec<MutableJson>;
|
|
|
4722
6898
|
*/
|
|
4723
6899
|
export declare function resolveInto<S extends Top>(schema: S): S["~annotate.in"] | undefined;
|
|
4724
6900
|
/**
|
|
6901
|
+
* The `Annotations` namespace groups all annotation interfaces used to attach
|
|
6902
|
+
* metadata to schemas. Annotations control documentation, validation messages,
|
|
6903
|
+
* JSON Schema generation, equivalence, arbitrary generation, and more.
|
|
6904
|
+
*
|
|
6905
|
+
* Use {@link resolveInto} to read the annotations attached to a schema at
|
|
6906
|
+
* runtime.
|
|
6907
|
+
*
|
|
4725
6908
|
* @since 4.0.0
|
|
4726
6909
|
*/
|
|
4727
6910
|
export declare namespace Annotations {
|
|
@@ -4770,6 +6953,9 @@ export declare namespace Annotations {
|
|
|
4770
6953
|
readonly [x: string]: unknown;
|
|
4771
6954
|
}
|
|
4772
6955
|
/**
|
|
6956
|
+
* Annotations shared by all schema nodes. These map to common JSON Schema /
|
|
6957
|
+
* OpenAPI fields: `title`, `description`, `format`, etc.
|
|
6958
|
+
*
|
|
4773
6959
|
* @since 4.0.0
|
|
4774
6960
|
*/
|
|
4775
6961
|
interface Augment extends Annotations {
|
|
@@ -4784,6 +6970,8 @@ export declare namespace Annotations {
|
|
|
4784
6970
|
readonly contentMediaType?: string | undefined;
|
|
4785
6971
|
}
|
|
4786
6972
|
/**
|
|
6973
|
+
* Extends {@link Augment} with type-parametric `default` and `examples` fields.
|
|
6974
|
+
*
|
|
4787
6975
|
* @since 4.0.0
|
|
4788
6976
|
*/
|
|
4789
6977
|
interface Documentation<T> extends Augment {
|
|
@@ -4791,6 +6979,10 @@ export declare namespace Annotations {
|
|
|
4791
6979
|
readonly examples?: ReadonlyArray<T> | undefined;
|
|
4792
6980
|
}
|
|
4793
6981
|
/**
|
|
6982
|
+
* Annotations for struct property schemas. Extends {@link Documentation}
|
|
6983
|
+
* with an optional `messageMissingKey` to override the error message when
|
|
6984
|
+
* the property key is absent during decoding.
|
|
6985
|
+
*
|
|
4794
6986
|
* @category Model
|
|
4795
6987
|
* @since 4.0.0
|
|
4796
6988
|
*/
|
|
@@ -4801,6 +6993,11 @@ export declare namespace Annotations {
|
|
|
4801
6993
|
readonly messageMissingKey?: string | undefined;
|
|
4802
6994
|
}
|
|
4803
6995
|
/**
|
|
6996
|
+
* Base annotations shared by all composite schema nodes. Extends
|
|
6997
|
+
* {@link Documentation} with error messages, branding, parse options, and
|
|
6998
|
+
* arbitrary generation hooks. {@link Declaration} and other annotation
|
|
6999
|
+
* interfaces build on top of this.
|
|
7000
|
+
*
|
|
4804
7001
|
* @category Model
|
|
4805
7002
|
* @since 4.0.0
|
|
4806
7003
|
*/
|
|
@@ -4843,6 +7040,12 @@ export declare namespace Annotations {
|
|
|
4843
7040
|
};
|
|
4844
7041
|
}
|
|
4845
7042
|
/**
|
|
7043
|
+
* Full annotation set for `Declaration` schema nodes — used when defining
|
|
7044
|
+
* custom, opaque schema types via `Schema.declare`. Extends {@link Bottom}
|
|
7045
|
+
* with optional codec, arbitrary, equivalence, and formatter hooks so that
|
|
7046
|
+
* derived capabilities (JSON encoding, property testing, etc.) can be
|
|
7047
|
+
* provided for the custom type.
|
|
7048
|
+
*
|
|
4846
7049
|
* @category Model
|
|
4847
7050
|
* @since 4.0.0
|
|
4848
7051
|
*/
|
|
@@ -4864,10 +7067,9 @@ export declare namespace Annotations {
|
|
|
4864
7067
|
} | undefined;
|
|
4865
7068
|
}
|
|
4866
7069
|
/**
|
|
4867
|
-
*
|
|
4868
|
-
*
|
|
4869
|
-
*
|
|
4870
|
-
* invariant
|
|
7070
|
+
* Annotations for filter schema nodes (created via `Schema.filter`). Extends
|
|
7071
|
+
* {@link Augment} with an optional error message, identifier, and metadata.
|
|
7072
|
+
* Filters are intentionally non-parametric to keep them covariant.
|
|
4871
7073
|
*
|
|
4872
7074
|
* @category Model
|
|
4873
7075
|
* @since 4.0.0
|