Schema.Struct<{
readonly representation: $Representation
readonly references: Schema.$Record<Schema.String, $Representation>
}>Schema for Document.
When to use
Use to validate or serialize a single schema representation document with
Schema.decodeUnknownSync or Schema.encodeSync.
Gotchas
This codec validates document structure but does not resolve $ref keys
against references.
export const const $Document: Schema.Struct<{
readonly representation: $Representation
readonly references: Schema.$Record<
Schema.String,
$Representation
>
}>
const $Document: {
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 representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Schema.Struct<{ [K in …;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation>; }, 'Type'>, readonly []>) => Schema.Struct<{ readonly repre…;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }, 'Type'>>) => Schema.Struct<{ readonly representation: $Repre…;
check: (checks_0: SchemaAST.Check<Schema.Struct.ReadonlySide<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }, 'Type'>>, ...checks: Array<SchemaAST.Check<Schema.Struct.ReadonlySide<…;
rebuild: (ast: SchemaAST.Objects) => Schema.Struct<{ readonly representation: $Representation; readonly references: Schema.$Record<Schema.String, $Representation> }>;
make: (input: Struct.ReadonlyMakeIn<{ readonly representation: SchemaRepresentation.$Representation; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Struct.ReadonlySide<{ readonly represen…;
makeOption: (input: Struct.ReadonlyMakeIn<{ readonly representation: SchemaRepresentation.$Representation; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<{ re…;
makeEffect: (input: Struct.ReadonlyMakeIn<{ readonly representation: SchemaRepresentation.$Representation; readonly references: $Record<String, SchemaRepresentation.$Representation> }>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<{ rea…;
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
Document
.
When to use
Use to validate or serialize a single schema representation document with
Schema.decodeUnknownSync or Schema.encodeSync.
Gotchas
This codec validates document structure but does not resolve $ref keys
against references.
$Document = 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({
representation: $Representation(property) 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; <…;
}
representation: 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 representation: $Representation; readonly references: $Record<String, $Representation>; }>, ... 8 more ..., "required">.annotate(annotations: Schema.Annotations.Bottom<Schema.Struct<Fields extends Schema.Struct.Fields>.ReadonlySide<{
readonly representation: $Representation;
readonly references: Schema.$Record<Schema.String, $Representation>;
}, "Type">, readonly []>): Schema.Struct<{
readonly representation: $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: "Document" })