Schema.Codec<Document, Schema.Json, never, never>Schema that decodes a Document from JSON and encodes it back.
When to use
Use when you need a JSON codec for schema representation documents with
Schema.decodeUnknownSync or Schema.encodeSync.
Example (Round-tripping a Document through JSON)
import { Schema, SchemaRepresentation } from "effect"
const doc = SchemaRepresentation.fromAST(Schema.String.ast)
const json = Schema.encodeSync(SchemaRepresentation.DocumentFromJson)(doc)
const back = Schema.decodeUnknownSync(SchemaRepresentation.DocumentFromJson)(json)export const const DocumentFromJson: Schema.Codec<
Document,
Schema.Json
>
const DocumentFromJson: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Document, any>) => Schema.Codec<Document, Schema.Json, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<Document>) => Schema.Codec<Document, Schema.Json, never, never>;
check: (checks_0: SchemaAST.Check<Document>, ...checks: Array<SchemaAST.Check<Document>>) => Schema.Codec<Document, Schema.Json, never, never>;
rebuild: (ast: SchemaAST.AST) => Schema.Codec<Document, Schema.Json, never, never>;
make: (input: unknown, options?: MakeOptions) => SchemaRepresentation.Document;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<SchemaRepresentation.Document>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<SchemaRepresentation.Document, 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; <…;
}
Schema that decodes a
Document
from JSON and encodes it back.
When to use
Use when you need a JSON codec for schema representation documents with
Schema.decodeUnknownSync or Schema.encodeSync.
Example (Round-tripping a Document through JSON)
import { Schema, SchemaRepresentation } from "effect"
const doc = SchemaRepresentation.fromAST(Schema.String.ast)
const json = Schema.encodeSync(SchemaRepresentation.DocumentFromJson)(doc)
const back = Schema.decodeUnknownSync(SchemaRepresentation.DocumentFromJson)(json)
DocumentFromJson: import SchemaSchema.type Schema.Codec = /*unresolved*/ anyCodec<type Document = {
readonly representation: Representation
readonly references: References
}
A single
Representation
together with its named
References
.
When to use
Use when representing a single Schema AST together with its named references
before reconstructing a runtime Schema, converting to JSON Schema, or
wrapping it as a
MultiDocument
.
Document, import SchemaSchema.type Schema.Json = /*unresolved*/ anyJson> = import SchemaSchema.toCodecJson(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)