Schema.Struct<{
readonly representations: Schema.NonEmptyArray<$Representation>
readonly references: Schema.$Record<Schema.String, $Representation>
}>Schema for MultiDocument.
export const const $MultiDocument: Schema.Struct<{
readonly representations: Schema.NonEmptyArray<$Representation>
readonly references: Schema.$Record<
Schema.String,
$Representation
>
}>
const $MultiDocument: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: { readonly representations: Schema.NonEmptyArray<$Representation>; readonly references: Schema.$Record<Schema.String, $Representation> }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) =>…;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly representations: Schema.NonEmptyArray<$Representation>; readonly references: Schema.$Record<Schema.String, $Representation>; }, 'Type'>, readonly []>) => Schema.…;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly representations: Schema.NonEmptyArray<$Representation>; readonly references: Schema.$Record<Schema.String, $Representation> }, 'Type'>>) => Schema.Struct<{ readonly…;
check: (checks_0: SchemaAST.Check<Schema.Struct.ReadonlySide<{ readonly representations: Schema.NonEmptyArray<$Representation>; readonly references: Schema.$Record<Schema.String, $Representation> }, 'Type'>>, ...checks: Array<SchemaAST.Check<Sche…;
rebuild: (ast: SchemaAST.Objects) => Schema.Struct<{ readonly representations: Schema.NonEmptyArray<$Representation>; readonly references: Schema.$Record<Schema.String, $Representation> }>;
make: (input: Struct.ReadonlyMakeIn<{ readonly representations: NonEmptyArray<SchemaRepresentation.$Representation>; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Struct.ReadonlySide<{ r…;
makeOption: (input: Struct.ReadonlyMakeIn<{ readonly representations: NonEmptyArray<SchemaRepresentation.$Representation>; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Option_.Option<Struct.R…;
makeEffect: (input: Struct.ReadonlyMakeIn<{ readonly representations: NonEmptyArray<SchemaRepresentation.$Representation>; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Effect.Effect<Struct.Re…;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Schema for
MultiDocument
.
$MultiDocument = import SchemaSchema.function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({
representations: Schema.NonEmptyArray<$Representation>(property) representations: {
Type: readonly [S["Type"], ...Array<S["Type"]>];
Encoded: readonly [S["Encoded"], ...Array<S["Encoded"]>];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: readonly [S["Iso"], ...Array<S["Iso"]>];
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<readonly [Representation, ...Representation[]], readonly []>) => Schema.NonEmptyArray<$Representation>;
annotateKey: (annotations: Schema.Annotations.Key<readonly [Representation, ...Representation[]]>) => Schema.NonEmptyArray<$Representation>;
check: (checks_0: SchemaAST.Check<readonly [Representation, ...Representation[]]>, ...checks: Array<SchemaAST.Check<readonly [Representation, ...Representation[]]>>) => Schema.NonEmptyArray<$Representation>;
rebuild: (ast: SchemaAST.Arrays) => Schema.NonEmptyArray<$Representation>;
make: (input: readonly [unknown, ...unknown[]], options?: MakeOptions) => readonly [SchemaRepresentation.Representation, ...SchemaRepresentation.Representation[]];
makeOption: (input: readonly [unknown, ...unknown[]], options?: MakeOptions) => Option_.Option<readonly [SchemaRepresentation.Representation, ...SchemaRepresentation.Representation[]]>;
makeEffect: (input: readonly [unknown, ...unknown[]], options?: MakeOptions) => Effect.Effect<readonly [SchemaRepresentation.Representation, ...SchemaRepresentation.Representation[]], SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
representations: import SchemaSchema.const NonEmptyArray: NonEmptyArrayLambda
;<$Representation>(self: $Representation) =>
Schema.NonEmptyArray<$Representation>
Type-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray(const $Representation: $Representationconst $Representation: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Representation, any>) => Schema.Codec<Representation, Representation, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<Representation>) => Schema.Codec<Representation, Representation, never, never>;
check: (checks_0: SchemaAST.Check<Representation>, ...checks: Array<SchemaAST.Check<Representation>>) => Schema.Codec<Representation, Representation, never, never>;
rebuild: (ast: SchemaAST.AST) => Schema.Codec<Representation, Representation, never, never>;
make: (input: unknown, options?: MakeOptions) => SchemaRepresentation.Representation;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<SchemaRepresentation.Representation>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<SchemaRepresentation.Representation, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level helper for the recursive
$Representation
codec.
Schema for the full
Representation
union. It recursively validates
and encodes any representation node.
$Representation),
references: Schema.$Record<
Schema.String,
$Representation
>
(property) references: {
Type: Record.Type<Key, Value>;
Encoded: Record.Encoded<Key, Value>;
DecodingServices: Record.DecodingServices<Key, Value>;
EncodingServices: Record.EncodingServices<Key, Value>;
Iso: Record.Iso<Key, Value>;
key: Key;
value: Value;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<{ readonly [x: string]: Representation; }, readonly []>) => Schema.$Record<Schema.String, $Representation>;
annotateKey: (annotations: Schema.Annotations.Key<{ readonly [x: string]: Representation }>) => Schema.$Record<Schema.String, $Representation>;
check: (checks_0: SchemaAST.Check<{ readonly [x: string]: Representation }>, ...checks: Array<SchemaAST.Check<{ readonly [x: string]: Representation }>>) => Schema.$Record<Schema.String, $Representation>;
rebuild: (ast: SchemaAST.Objects) => Schema.$Record<Schema.String, $Representation>;
make: (input: { readonly [x: string]: unknown }, options?: MakeOptions) => { readonly [x: string]: SchemaRepresentation.Representation };
makeOption: (input: { readonly [x: string]: unknown }, options?: MakeOptions) => Option_.Option<{ readonly [x: string]: SchemaRepresentation.Representation }>;
makeEffect: (input: { readonly [x: string]: unknown }, options?: MakeOptions) => Effect.Effect<{ readonly [x: string]: SchemaRepresentation.Representation }, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
references: import SchemaSchema.function Record<
Key extends Record.Key,
Value extends Constraint
>(
key: Key,
value: Value,
options?: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
): $Record<Key, Value>
Defines a record schema whose dynamic properties are selected by a key schema
and decoded with a value schema.
Details
For dynamic keys, the key schema selects matching own properties and the
value schema decodes or encodes only those selected properties. Checks on
string, number, symbol, and template literal key schemas narrow which
properties are selected.
For transformed key schemas, property selection is based on encoded property
names before the selected key is decoded.
Example (Defining a string-keyed record of numbers)
import { Schema } from "effect"
const schema = Schema.Record(Schema.String, Schema.Number)
// { readonly [x: string]: number }
type R = typeof schema.Type
const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
console.log(result)
// { a: 1, b: 2 }
Record(import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String, const $Representation: $Representationconst $Representation: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Representation, any>) => Schema.Codec<Representation, Representation, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<Representation>) => Schema.Codec<Representation, Representation, never, never>;
check: (checks_0: SchemaAST.Check<Representation>, ...checks: Array<SchemaAST.Check<Representation>>) => Schema.Codec<Representation, Representation, never, never>;
rebuild: (ast: SchemaAST.AST) => Schema.Codec<Representation, Representation, never, never>;
make: (input: unknown, options?: MakeOptions) => SchemaRepresentation.Representation;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<SchemaRepresentation.Representation>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<SchemaRepresentation.Representation, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level helper for the recursive
$Representation
codec.
Schema for the full
Representation
union. It recursively validates
and encodes any representation node.
$Representation)
}).Bottom<unknown, unknown, unknown, unknown, Objects, Struct<{ readonly representations: NonEmptyArray<$Representation>; readonly references: $Record<String, $Representation>; }>, ... 8 more ..., "required">.annotate(annotations: Schema.Annotations.Bottom<Schema.Struct<Fields extends Schema.Struct.Fields>.ReadonlySide<{
readonly representations: Schema.NonEmptyArray<$Representation>;
readonly references: Schema.$Record<Schema.String, $Representation>;
}, "Type">, readonly []>): Schema.Struct<{
readonly representations: Schema.NonEmptyArray<$Representation>;
readonly references: Schema.$Record<Schema.String, $Representation>;
}>
annotate({ Annotations.Bottom<T, TypeParameters extends ReadonlyArray<Constraint>>.identifier?: string | undefinedStable identifier for this schema node.
Details
Identifiers are used by schema tooling, including JSON Schema
generation, to name references. The default formatter also uses
identifier as the expected label for type-level failures, such as
Expected UserId, got null.
identifier does not name a failed filter or refinement. If the base
type matches and a filter fails, put expected or message on the
filter/refinement instead.
identifier: "MultiDocument" })