Directory row — dial target plus resource keys this node serves (listen catalog).
export class class DirectoryEntryclass DirectoryEntry {
kind: 'Http' | 'WebSocket' | 'IpcSocket';
serves: ReadonlyArray<string>;
nodeKey: string;
url: string | undefined;
path: string | undefined;
}
Directory row — dial target plus resource keys this node serves (listen catalog).
DirectoryEntry extends import SchemaSchema.const Class: <DirectoryEntry, {}>(identifier: string) => {
<Fields>(fields: Fields, annotations?: Schema.Annotations.Declaration<DirectoryEntry, readonly [Schema.Struct<Fields>]> | undefined): Schema.Class<DirectoryEntry, Schema.Struct<Fields>, {}>;
<S>(schema: S, annotations?: Schema.Annotations.Declaration<DirectoryEntry, readonly [S]> | undefined): Schema.Class<DirectoryEntry, S, {}>;
}
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<class DirectoryEntryclass DirectoryEntry {
kind: 'Http' | 'WebSocket' | 'IpcSocket';
serves: ReadonlyArray<string>;
nodeKey: string;
url: string | undefined;
path: string | undefined;
}
Directory row — dial target plus resource keys this node serves (listen catalog).
DirectoryEntry>("LookupDirectoryEntry")({
nodeKey: Schema.String(property) nodeKey: {
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: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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; <…;
}
nodeKey: import SchemaSchema.const String: Schema.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: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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,
kind: Schema.Literals<
readonly ["Http", "WebSocket", "IpcSocket"]
>
(property) kind: {
literals: L;
members: { readonly [K in keyof L]: Literal<L[K]>; };
mapMembers: (f: (members: readonly [Schema.Literal<'Http'>, Schema.Literal<'WebSocket'>, Schema.Literal<'IpcSocket'>]) => To) => Schema.Union<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
pick: (literals: L2) => Schema.Literals<L2>;
transform: (to: L2) => Schema.Union<readonly [Schema.decodeTo<Schema.Literal<L2['0']>, Schema.Literal<'Http'>, never, never>, Schema.decodeTo<Schema.Literal<L2['1']>, Schema.Literal<'WebSocket'>, never, never>, Schema.decodeTo<Schema.Literal<L2['2']>…;
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<'Http' | 'WebSocket' | 'IpcSocket', readonly []>) => Schema.Literals<readonly ['Http', 'WebSocket', 'IpcSocket']>;
annotateKey: (annotations: Schema.Annotations.Key<'Http' | 'WebSocket' | 'IpcSocket'>) => Schema.Literals<readonly ['Http', 'WebSocket', 'IpcSocket']>;
check: (checks_0: Check<'Http' | 'WebSocket' | 'IpcSocket'>, ...checks: Array<Check<'Http' | 'WebSocket' | 'IpcSocket'>>) => Schema.Literals<readonly ['Http', 'WebSocket', 'IpcSocket']>;
rebuild: (ast: Union<Literal>) => Schema.Literals<readonly ['Http', 'WebSocket', 'IpcSocket']>;
make: (input: 'Http' | 'WebSocket' | 'IpcSocket', options?: Schema.MakeOptions) => 'Http' | 'WebSocket' | 'IpcSocket';
makeOption: (input: 'Http' | 'WebSocket' | 'IpcSocket', options?: Schema.MakeOptions) => Option.Option<'Http' | 'WebSocket' | 'IpcSocket'>;
makeEffect: (input: 'Http' | 'WebSocket' | 'IpcSocket', options?: Schema.MakeOptions) => Effect.Effect<'Http' | 'WebSocket' | 'IpcSocket', Schema.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; <…;
}
kind: import SchemaSchema.function Literals<readonly ["Http", "WebSocket", "IpcSocket"]>(literals: readonly ["Http", "WebSocket", "IpcSocket"]): Schema.Literals<readonly ["Http", "WebSocket", "IpcSocket"]>Creates a union schema from an array of literal values.
Example (Defining status codes)
import { Schema } from "effect"
const schema = Schema.Literals(["active", "inactive", "pending"])
// accepts "active", "inactive", or "pending"
Literals(["Http", "WebSocket", "IpcSocket"]),
url: Schema.optionalKey<Schema.String>(property) url: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.optionalKey<Schema.String>;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.optionalKey<Schema.String>;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.optionalKey<Schema.String>;
rebuild: (ast: String) => Schema.optionalKey<Schema.String>;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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; <…;
}
url: import SchemaSchema.const optionalKey: optionalKeyLambda
<Schema.String>(self: Schema.String) => Schema.optionalKey<Schema.String>
Type-level representation returned by
optionalKey
.
Creates an exact optional key schema for struct fields. Unlike optional,
this creates exact optional properties (not | undefined) that can be
completely omitted from the object.
Example (Creating a struct with optional key)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optionalKey(Schema.Number)
})
// Type: { readonly name: string; readonly age?: number }
type Person = typeof schema["Type"]
optionalKey(import SchemaSchema.const String: Schema.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: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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),
path: Schema.optionalKey<Schema.String>(property) path: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.optionalKey<Schema.String>;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.optionalKey<Schema.String>;
check: (checks_0: Check<string>, ...checks: Array<Check<string>>) => Schema.optionalKey<Schema.String>;
rebuild: (ast: String) => Schema.optionalKey<Schema.String>;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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; <…;
}
path: import SchemaSchema.const optionalKey: optionalKeyLambda
<Schema.String>(self: Schema.String) => Schema.optionalKey<Schema.String>
Type-level representation returned by
optionalKey
.
Creates an exact optional key schema for struct fields. Unlike optional,
this creates exact optional properties (not | undefined) that can be
completely omitted from the object.
Example (Creating a struct with optional key)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optionalKey(Schema.Number)
})
// Type: { readonly name: string; readonly age?: number }
type Person = typeof schema["Type"]
optionalKey(import SchemaSchema.const String: Schema.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: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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),
serves: Schema.$Array<Schema.String>(property) serves: {
Type: ReadonlyArray<S["Type"]>;
Encoded: ReadonlyArray<S["Encoded"]>;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: ReadonlyArray<S["Iso"]>;
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<ReadonlyArray<string>, readonly []>) => Schema.$Array<Schema.String>;
annotateKey: (annotations: Schema.Annotations.Key<ReadonlyArray<string>>) => Schema.$Array<Schema.String>;
check: (checks_0: Check<ReadonlyArray<string>>, ...checks: Array<Check<ReadonlyArray<string>>>) => Schema.$Array<Schema.String>;
rebuild: (ast: Arrays) => Schema.$Array<Schema.String>;
make: (input: ReadonlyArray<string>, options?: Schema.MakeOptions) => ReadonlyArray<string>;
makeOption: (input: ReadonlyArray<string>, options?: Schema.MakeOptions) => Option.Option<ReadonlyArray<string>>;
makeEffect: (input: ReadonlyArray<string>, options?: Schema.MakeOptions) => Effect.Effect<ReadonlyArray<string>, Schema.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; <…;
}
serves: import SchemaSchema.Array<Schema.String>(self: Schema.String): Schema.$Array<Schema.String>
export Array
Defines a ReadonlyArray schema for a given element schema.
Example (Defining an array of strings)
import { Schema } from "effect"
const schema = Schema.Array(Schema.String)
const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
console.log(result)
// [ 'a', 'b', 'c' ]
Array(import SchemaSchema.const String: Schema.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: Check<string>, ...checks: Array<Check<string>>) => Schema.String;
rebuild: (ast: String) => Schema.String;
make: (input: string, options?: Schema.MakeOptions) => string;
makeOption: (input: string, options?: Schema.MakeOptions) => Option.Option<string>;
makeEffect: (input: string, options?: Schema.MakeOptions) => Effect.Effect<string, Schema.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),
}) {}