Schema API
Generated public TypeScript reference for @relkit/schema.
Common APIs
For configuration and examples, read Runtime schemas, requests, uploads.
For a complete workflow, follow upload product images.
Public imports
@relkit/schema— 56 exports
All exported APIs
Names link to their complete contracts. Re-exports share their original contract; legacy exports keep their separate identity. Examples link to the API’s inline sample, a maintained repository usage, or the shared module walkthrough.
builder-composites.ts
arraySchema
Builds an array validator from one item schema.
Example
arraySchema(z.number());
Signature
declare const arraySchema: <S extends AnySchema>(schema: S) => Schema<InputOf<S>[], OutputOf<S>[]>;
objectSchema
Builds an object validator from named child schemas.
Example
objectSchema({ id: z.string() });
Signature
declare const objectSchema: <S extends Shape>(shape: S) => Schema<ObjectInput<S>, ObjectOutput<S>>;
unionSchema
Builds a nonempty union with first-success precedence.
Example
unionSchema([z.string(), z.number()]);
Signature
declare const unionSchema: <S extends SchemaTuple>(
schemas: S,
) => Schema<InputOf<S[number]>, OutputOf<S[number]>>;
builder-composites.types.ts
AnySchema (type alias)
Any compatible validator accepted by a composite builder.
Example
const child: AnySchema = z.string();
Signature
type AnySchema = StandardSchemaV1;
InputOf (type alias)
Accepted input of a child validator.
Example
type Input = InputOf<typeof schema>;
Signature
type InputOf<S extends AnySchema> = InferInput<S>;
ObjectInput (type alias)
Object input with optional keys inferred from child schemas.
Example
type Input = ObjectInput<{ id: typeof idSchema }>;
Signature
type ObjectInput<S extends Shape> = {
[K in RequiredInputKeys<S>]: InputOf<S[K]>;
} & {
[K in OptionalInputKeys<S>]?: Exclude<InputOf<S[K]>, undefined>;
};
ObjectOutput (type alias)
Object output with optional keys inferred from child schemas.
Example
type Output = ObjectOutput<{ id: typeof idSchema }>;
Signature
type ObjectOutput<S extends Shape> = {
[K in RequiredOutputKeys<S>]: OutputOf<S[K]>;
} & {
[K in OptionalOutputKeys<S>]?: Exclude<OutputOf<S[K]>, undefined>;
};
OutputOf (type alias)
Validated output of a child validator.
Example
type Output = OutputOf<typeof schema>;
Signature
type OutputOf<S extends AnySchema> = InferOutput<S>;
SchemaTuple (type alias)
Nonempty tuple of union members, preserving declaration order.
Example
const members: SchemaTuple = [z.string(), z.number()];
Signature
type SchemaTuple = readonly [AnySchema, ...AnySchema[]];
Shape (type alias)
Named child validators for an object schema.
Example
const shape: Shape = { id: z.string() };
Signature
type Shape = Record<string, AnySchema>;
builder-effect.ts
SchemaBuilderError (class)
Tagged failure when a schema builder rejects options or its dependencies throw.
The original exception remains available in cause.
Example
Effect.catchTag("SchemaBuilderError", (error) => Effect.succeed(error.cause));
Signature
declare class SchemaBuilderError
buildSchema
Runs a synchronous schema builder and preserves its original error.
Throws
The original construction error.
Example
buildSchema("builder.string", () => z.string());
Signature
declare const buildSchema: <A>(operation: SchemaOperation, build: () => A) => A;
buildSchemaEffect
Constructs a schema inside an observed Effect.
Example
Effect.runSync(buildSchemaEffect("builder.string", () => z.string()));
Signature
declare const buildSchemaEffect: <A>(
operation: SchemaOperation,
build: () => A,
) => Effect.Effect<A, SchemaBuilderError>;
builder-refinements.ts
numberSchema
Builds a finite-number schema with numeric refinements.
Example
numberSchema().int().parse(2);
Signature
declare const numberSchema: () => NumberSchema;
stringSchema
Builds a string schema with format and length refinements.
Example
stringSchema().min(2).parse("ok");
Signature
declare const stringSchema: () => StringSchema;
builder-refinements.types.ts
NumberSchema (interface)
Finite-number schema with range and integer refinement methods.
Example
const schema: NumberSchema = z.number().int();
Signature
export interface NumberSchema extends Schema<number, number> {
/**
* Requires an inclusive minimum.
* @param value - Minimum value.
* @param message - Optional issue text.
* @returns A refined number schema.
* @example z.number().min(1);
*/
min(value: number, message?: string): NumberSchema;
/**
* Requires an inclusive maximum.
* @param value - Maximum value.
* @param message - Optional issue text.
* @returns A refined number schema.
* @example z.number().max(10);
*/
max(value: number, message?: string): NumberSchema;
/**
* Requires an integer.
* @param message - Optional issue text.
* @returns An integer schema.
* @example z.number().int();
*/
int(message?: string): NumberSchema;
/**
* Requires a value above zero.
* @param message - Optional issue text.
* @returns A positive number schema.
* @example z.number().positive();
*/
positive(message?: string): NumberSchema;
/**
* Requires a value of zero or greater.
* @param message - Optional issue text.
* @returns A nonnegative number schema.
* @example z.number().nonnegative();
*/
nonnegative(message?: string): NumberSchema;
}
StringSchema (interface)
String schema with length and format refinement methods.
Example
const schema: StringSchema = z.string().min(1);
Signature
export interface StringSchema extends Schema<string, string> {
/**
* Requires a minimum string length.
* @param length - Minimum length.
* @param message - Optional issue text.
* @returns A refined string schema.
* @example z.string().min(2);
*/
min(length: number, message?: string): StringSchema;
/**
* Requires a maximum string length.
* @param length - Maximum length.
* @param message - Optional issue text.
* @returns A refined string schema.
* @example z.string().max(8);
*/
max(length: number, message?: string): StringSchema;
/**
* Requires a UUID string.
* @param message - Optional issue text.
* @returns A UUID string schema.
* @example z.string().uuid();
*/
uuid(message?: string): StringSchema;
/**
* Requires a parseable datetime string.
* @param message - Optional issue text.
* @returns A datetime string schema.
* @example z.string().datetime();
*/
datetime(message?: string): StringSchema;
/**
* Requires an email address string.
* @param message - Optional issue text.
* @returns An email string schema.
* @example z.string().email();
*/
email(message?: string): StringSchema;
}
builder.ts
z
Builds RELKIT Standard Schema validators with familiar composition helpers.
Example
import { z } from "@relkit/app/schema";
const order = z.object({ id: z.string(), quantity: z.number().int().positive() });
order.parse({ id: "order-1", quantity: 2 });
Signature
declare const z: ZBuilder;
Since v0.1.0
AnySchema
Signature
declare const AnySchema: AnySchema;
InputOf
Signature
declare const InputOf: InputOf<S>;
NumberSchema
Signature
declare const NumberSchema: NumberSchema;
ObjectInput
Signature
declare const ObjectInput: ObjectInput<S>;
ObjectOutput
Signature
declare const ObjectOutput: ObjectOutput<S>;
OutputOf
Signature
declare const OutputOf: OutputOf<S>;
SchemaTuple
Signature
declare const SchemaTuple: SchemaTuple;
Shape
Signature
declare const Shape: Shape;
StringSchema
Signature
declare const StringSchema: StringSchema;
ZBuilder
Signature
declare const ZBuilder: ZBuilder;
builder.types.ts
AnySchema
Signature
declare const AnySchema: AnySchema;
InputOf
Signature
declare const InputOf: InputOf<S>;
NumberSchema
Signature
declare const NumberSchema: NumberSchema;
ObjectInput
Signature
declare const ObjectInput: ObjectInput<S>;
ObjectOutput
Signature
declare const ObjectOutput: ObjectOutput<S>;
OutputOf
Signature
declare const OutputOf: OutputOf<S>;
SchemaTuple
Signature
declare const SchemaTuple: SchemaTuple;
Shape
Signature
declare const Shape: Shape;
StringSchema
Signature
declare const StringSchema: StringSchema;
ZBuilder (interface)
Builder methods used to compose Standard Schema validators.
Example
const builder: ZBuilder = z;
Signature
export interface ZBuilder {
/**
* Builds a string validator.
* @returns A string schema with refinement methods.
* @example z.string().min(1);
*/
string(): StringSchema;
/**
* Builds a finite-number validator.
* @returns A number schema with refinement methods.
* @example z.number().int();
*/
number(): NumberSchema;
/**
* Builds a boolean validator.
* @returns A boolean schema.
* @example z.boolean().parse(true);
*/
boolean(): Schema<boolean, boolean>;
/**
* Builds a validator accepting any input without changing it.
* @returns An unknown-value schema.
* @example z.unknown().parse({ name: "Ada" });
*/
unknown(): Schema<unknown, unknown>;
/**
* Builds an unrestricted value validator.
* @returns An unknown-value schema.
* @example z.any().parse(null);
*/
any(): Schema<unknown, unknown>;
/**
* Builds a null validator.
* @returns A null schema.
* @example z.null().parse(null);
*/
null(): Schema<null, null>;
/**
* Builds a buffered Web File validator.
* @param options - Byte and media-type constraints.
* @returns A File schema.
* @example z.file({ maxBytes: 1024 });
*/
file(options?: FileSchemaOptions): FileSchema;
/**
* Builds an undefined validator.
* @returns An undefined schema.
* @example z.undefined().parse(undefined);
*/
undefined(): Schema<undefined, undefined>;
/**
* Builds a void-result validator.
* @returns An undefined schema.
* @example z.void().parse(undefined);
*/
void(): Schema<undefined, undefined>;
/**
* Builds an exact-value validator.
* @param value - Literal value to require.
* @returns A literal schema.
* @example z.literal("ready").parse("ready");
*/
literal<T extends string | number | boolean | null | undefined>(value: T): Schema<T, T>;
/**
* Builds a named object validator.
* @param shape - Child schemas by property name.
* @returns An object schema with inferred input and output.
* @example z.object({ id: z.string() });
*/
object<S extends Shape>(shape: S): Schema<ObjectInput<S>, ObjectOutput<S>>;
/**
* Builds an array validator.
* @param schema - Child item schema.
* @returns An array schema with inferred item types.
* @example z.array(z.number());
*/
array<S extends AnySchema>(schema: S): Schema<InputOf<S>[], OutputOf<S>[]>;
/**
* Builds a nonempty union validator.
* @param schemas - Member schemas in precedence order.
* @returns A union schema with inferred member types.
* @example z.union([z.string(), z.number()]);
*/
union<S extends SchemaTuple>(schemas: S): Schema<InputOf<S[number]>, OutputOf<S[number]>>;
}
file.ts
FileSchema
Signature
declare const FileSchema: FileSchema;
FileSchemaOptions
Signature
declare const FileSchemaOptions: FileSchemaOptions;
fileSchema
Builds a buffered Web File validator with binary projection metadata.
Throws
TypeError for invalid options in this synchronous adapter.
Example
fileSchema({ maxBytes: 1024, mediaTypes: ["image/*"] });
Signature
declare const fileSchema: (options?: FileSchemaOptions) => FileSchema;
file.types.ts
FileSchema (type alias)
A schema that accepts and returns a Web File.
Example
const schema: FileSchema = z.file();
Signature
type FileSchema = Schema<File, File>;
FileSchemaOptions (interface)
Constraints for a buffered Web File validator.
Example
const options: FileSchemaOptions = { maxBytes: 1024, mediaTypes: ["image/*"] };
Signature
export interface FileSchemaOptions {
readonly maxBytes?: number;
readonly mediaTypes?: readonly string[];
}
index.ts
FileSchema
Signature
declare const FileSchema: FileSchema;
FileSchemaOptions
Signature
declare const FileSchemaOptions: FileSchemaOptions;
InferInput
Signature
declare const InferInput: InferInput<S>;
InferOutput
Signature
declare const InferOutput: InferOutput<S>;
JSON_SCHEMA_UNAVAILABLE
Signature
declare const JSON_SCHEMA_UNAVAILABLE: "RELKIT_SCHEMA_UNAVAILABLE";
JsonSchema
Signature
declare const JsonSchema: JsonSchema;
JsonSchemaAvailable
Signature
declare const JsonSchemaAvailable: JsonSchemaAvailable;
JsonSchemaDirection
Signature
declare const JsonSchemaDirection: SchemaProjectionDirection;
JsonSchemaFactory
Signature
declare const JsonSchemaFactory: JsonSchemaFactory;
JsonSchemaOptions
Signature
declare const JsonSchemaOptions: JsonSchemaOptions;
JsonSchemaResult
Signature
declare const JsonSchemaResult: JsonSchemaResult;
JsonSchemaUnavailable
Signature
declare const JsonSchemaUnavailable: JsonSchemaUnavailable;
JsonSchemaUnavailableError
Signature
declare const JsonSchemaUnavailableError: typeof JsonSchemaUnavailableError;
NumberSchema
Signature
declare const NumberSchema: NumberSchema;
RelkitSchema
Signature
declare const RelkitSchema: RelkitSchema<TInput, TOutput>;
Schema
Signature
declare const Schema: Schema<TInput, TOutput>;
SchemaAsyncError
Signature
declare const SchemaAsyncError: typeof SchemaAsyncError;
SchemaBuilderError
Signature
declare const SchemaBuilderError: typeof SchemaBuilderError;
SchemaExecutionError
Signature
declare const SchemaExecutionError: typeof SchemaExecutionError;
SchemaInvalidError
Signature
declare const SchemaInvalidError: typeof SchemaInvalidError;
SchemaIssuesError
Signature
declare const SchemaIssuesError: typeof SchemaIssuesError;
SchemaProjector
Signature
declare const SchemaProjector: typeof SchemaProjector;
SchemaProjectorLive
Signature
declare const SchemaProjectorLive: Layer<SchemaProjector, never, never>;
SchemaProjectorService
Signature
declare const SchemaProjectorService: SchemaProjectorService;
SchemaTelemetry
Signature
declare const SchemaTelemetry: typeof SchemaTelemetry;
SchemaTelemetryLive
Signature
declare const SchemaTelemetryLive: Layer<SchemaTelemetry, never, never>;
SchemaTelemetryService
Signature
declare const SchemaTelemetryService: SchemaTelemetryService;
SchemaValidationError
Signature
declare const SchemaValidationError: typeof SchemaValidationError;
SchemaValidator
Signature
declare const SchemaValidator: typeof SchemaValidator;
SchemaValidatorLive
Signature
declare const SchemaValidatorLive: Layer<SchemaValidator, never, never>;
SchemaValidatorService
Signature
declare const SchemaValidatorService: SchemaValidatorService;
StandardFailure
Signature
declare const StandardFailure: StandardFailure;
StandardIssue
Signature
declare const StandardIssue: StandardIssue;
StandardJSONSchemaV1
Signature
declare const StandardJSONSchemaV1: StandardJSONSchemaV1<TInput, TOutput>;
StandardPathSegment
Signature
declare const StandardPathSegment: StandardPathSegment;
StandardResult
Signature
declare const StandardResult: StandardResult<T>;
StandardSchemaOptions
Signature
declare const StandardSchemaOptions: StandardSchemaOptions;
StandardSchemaTypes
Signature
declare const StandardSchemaTypes: StandardSchemaTypes<TInput, TOutput>;
StandardSchemaV1
Signature
declare const StandardSchemaV1: StandardSchemaV1<TInput, TOutput>;
StandardSuccess
Signature
declare const StandardSuccess: StandardSuccess<T>;
StringSchema
Signature
declare const StringSchema: StringSchema;
ZBuilder
Signature
declare const ZBuilder: ZBuilder;
buildSchemaEffect
Signature
declare const buildSchemaEffect: <A>(
operation: SchemaOperation,
build: () => A,
) => Effect<A, SchemaBuilderError>;
getJsonSchema
Signature
declare const getJsonSchema: (
schema: StandardSchemaV1,
options?: JsonSchemaOptions,
) => JsonSchemaResult;
getJsonSchemaEffect
Signature
declare const getJsonSchemaEffect: (
schema: StandardSchemaV1,
options?: JsonSchemaOptions,
) => Effect<JsonSchema, JsonSchemaUnavailableError, SchemaProjector>;
getSchemaMetadata
Signature
declare const getSchemaMetadata: (schema: StandardSchemaV1) => SchemaMetadata | undefined;
getSchemaMetadataEffect
Signature
declare const getSchemaMetadataEffect: (
schema: StandardSchemaV1,
) => Effect<SchemaMetadata | undefined>;
isJsonSchemaAvailable
Signature
declare const isJsonSchemaAvailable: (result: JsonSchemaResult) => result is JsonSchemaAvailable;
isSchemaTransformed
Signature
declare const isSchemaTransformed: (schema: StandardSchemaV1) => boolean;
isSchemaTransformedEffect
Signature
declare const isSchemaTransformedEffect: (schema: StandardSchemaV1) => Effect<boolean>;
toJsonSchema
Signature
declare const toJsonSchema: (
schema: StandardSchemaV1,
options?: JsonSchemaOptions,
) => JsonSchemaResult;
validate
Signature
declare const validate: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => StandardResult<InferOutput<S>> | Promise<StandardResult<InferOutput<S>>>;
validateEffect
Signature
declare const validateEffect: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => Effect<
InferOutput<S>,
SchemaIssuesError | SchemaInvalidError | SchemaExecutionError,
SchemaValidator
>;
validateSync
Signature
declare const validateSync: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => StandardResult<InferOutput<S>>;
validateSyncEffect
Signature
declare const validateSyncEffect: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => Effect<
InferOutput<S>,
SchemaIssuesError | SchemaInvalidError | SchemaExecutionError | SchemaAsyncError,
SchemaValidator
>;
z
Signature
declare const z: ZBuilder;
json-schema-effect.ts
JsonSchemaUnavailableError (class)
Tagged failure for an unavailable or invalid JSON Schema projection.
Example
Effect.catchTag("JsonSchemaUnavailableError", (error) => Effect.succeed(error.reason));
Signature
declare class JsonSchemaUnavailableError
SchemaProjector (class)
Injectable JSON Schema projection boundary.
Example
Effect.provide(getJsonSchemaEffect(z.string()), SchemaProjectorLive);
Signature
declare class SchemaProjector
SchemaProjectorLive
Live JSON Schema projector using registered schema metadata and hooks.
Example
Effect.runSync(Effect.provide(getJsonSchemaEffect(z.string()), SchemaProjectorLive));
Signature
declare const SchemaProjectorLive: Layer.Layer<SchemaProjector, never, never>;
getJsonSchemaEffect
Projects a validator into canonical JSON Schema with typed failures.
Example
Effect.runSync(Effect.provide(getJsonSchemaEffect(z.string()), SchemaProjectorLive));
Signature
declare const getJsonSchemaEffect: (
schema: StandardSchemaV1,
options?: JsonSchemaOptions,
) => Effect.Effect<JsonSchema, JsonSchemaUnavailableError, SchemaProjector>;
json-schema-effect.types.ts
SchemaProjectorService (interface)
Injectable boundary for a schema’s JSON projection hook. Test Layers can substitute projection without a third-party schema package.
Example
Layer.succeed(SchemaProjector, { projection: () => () => ({ type: "string" }) });
Signature
export interface SchemaProjectorService {
/**
* Selects a directional or legacy projection hook.
* @param schema - Compatible schema to inspect.
* @param direction - Input, output, or legacy projection.
* @returns A projection factory when the schema exposes one.
* @example projector.projection(z.string(), "input");
*/
readonly projection: (
schema: StandardSchemaV1,
direction: JsonSchemaDirection | "legacy",
) => JsonSchemaFactory | undefined;
}
json-schema-inspection.ts
getSchemaProjection
Finds a deterministic projection hook without executing it.
Example
getSchemaProjection(z.string(), "input");
Signature
declare const getSchemaProjection: (
schema: StandardSchemaV1,
direction?: JsonSchemaDirection | "legacy",
) => JsonSchemaFactory | undefined;
getSchemaProjectionEffect
Finds a deterministic projection hook inside Effect.
Example
Effect.runSync(getSchemaProjectionEffect(z.string(), "input"));
Signature
declare const getSchemaProjectionEffect: (
schema: StandardSchemaV1,
direction?: JsonSchemaDirection | "legacy",
) => Effect.Effect<JsonSchemaFactory | undefined>;
isSchemaOptional
Checks whether a schema accepts an omitted property.
Example
isSchemaOptional(z.string().optional());
Signature
declare const isSchemaOptional: (
schema: StandardSchemaV1,
direction?: JsonSchemaDirection | "legacy",
) => boolean;
isSchemaOptionalEffect
Checks schema optionality inside Effect.
Example
Effect.runSync(isSchemaOptionalEffect(z.string().optional()));
Signature
declare const isSchemaOptionalEffect: (
schema: StandardSchemaV1,
direction?: JsonSchemaDirection | "legacy",
) => Effect.Effect<boolean>;
json-schema-inspection.types.ts
RelkitProjectable (type alias)
RELKIT extension hook shapes for directional JSON projections.
Example
const projection = (schema as RelkitProjectable).relkit?.inputJsonSchema;
Signature
type RelkitProjectable = StandardSchemaV1 & {
readonly relkit?: {
readonly jsonSchema?: JsonSchemaFactory;
readonly inputJsonSchema?: JsonSchemaFactory;
readonly outputJsonSchema?: JsonSchemaFactory;
};
};
StandardProjectable (type alias)
Standard JSON Schema extension hook shapes for compatible schemas.
Example
const hook = (schema["~standard"] as StandardProjectable).jsonSchema?.input;
Signature
type StandardProjectable = StandardSchemaV1["~standard"] & {
readonly jsonSchema?: {
readonly input?: (options: { readonly target: "draft-2020-12" }) => Record<string, unknown>;
readonly output?: (options: { readonly target: "draft-2020-12" }) => Record<string, unknown>;
};
};
json-schema.ts
JSON_SCHEMA_UNAVAILABLE
Stable code for unavailable deterministic JSON Schema projections.
Signature
declare const JSON_SCHEMA_UNAVAILABLE: "RELKIT_SCHEMA_UNAVAILABLE";
JsonSchema
Signature
declare const JsonSchema: JsonSchema;
JsonSchemaAvailable
Signature
declare const JsonSchemaAvailable: JsonSchemaAvailable;
JsonSchemaDirection
Signature
declare const JsonSchemaDirection: SchemaProjectionDirection;
JsonSchemaFactory
Signature
declare const JsonSchemaFactory: JsonSchemaFactory;
JsonSchemaOptions
Signature
declare const JsonSchemaOptions: JsonSchemaOptions;
JsonSchemaResult
Signature
declare const JsonSchemaResult: JsonSchemaResult;
JsonSchemaUnavailable
Signature
declare const JsonSchemaUnavailable: JsonSchemaUnavailable;
JsonSchemaValueError (class)
Tagged failure for non-JSON projection data.
The original validation exception remains in cause.
Example
Effect.catchTag("JsonSchemaValueError", (error) => Effect.succeed(error.cause));
Signature
declare class JsonSchemaValueError
getJsonSchema
Produces a canonical JSON Schema or an unavailable result.
Example
getJsonSchema(z.string());
Signature
declare const getJsonSchema: (
schema: StandardSchemaV1,
options?: JsonSchemaOptions,
) => JsonSchemaResult;
getSchemaProjection
Signature
declare const getSchemaProjection: (
schema: StandardSchemaV1,
direction?: JsonSchemaDirection | "legacy",
) => JsonSchemaFactory | undefined;
isJsonSchemaAvailable
Narrows a successful projection result.
Example
isJsonSchemaAvailable(getJsonSchema(z.string()));
Signature
declare const isJsonSchemaAvailable: (result: JsonSchemaResult) => result is JsonSchemaAvailable;
isJsonSchemaAvailableEffect
Checks projection availability inside Effect.
Example
Effect.runSync(isJsonSchemaAvailableEffect(getJsonSchema(z.string())));
Signature
declare const isJsonSchemaAvailableEffect: (result: JsonSchemaResult) => Effect.Effect<boolean>;
isSchemaOptional
Signature
declare const isSchemaOptional: (
schema: StandardSchemaV1,
direction?: JsonSchemaDirection | "legacy",
) => boolean;
sortJsonValue
Canonicalizes JSON-safe projection data and preserves TypeError behavior.
Throws
TypeError for unsupported data.
Example
sortJsonValue({ b: 2, a: 1 }, "$", undefined);
Signature
declare const sortJsonValue: (value: unknown, path: string, key: string | undefined) => JsonValue;
sortJsonValueEffect
Canonicalizes JSON-safe projection data inside Effect.
Example
Effect.runSync(sortJsonValueEffect({ b: 2, a: 1 }, "$", undefined));
Signature
declare const sortJsonValueEffect: (
value: unknown,
path: string,
key: string | undefined,
) => Effect.Effect<JsonValue, JsonSchemaValueError>;
toJsonSchema
Alias for callers that describe projection as a conversion.
Example
toJsonSchema(z.string());
Signature
declare const toJsonSchema: (
schema: StandardSchemaV1,
options?: JsonSchemaOptions,
) => JsonSchemaResult;
json-schema.types.ts
JsonSchema (type alias)
A deterministic JSON Schema document.
Example
const document: JsonSchema = { type: "string" };
Signature
type JsonSchema = { readonly [key: string]: JsonValue };
JsonSchemaAvailable (interface)
A successful JSON Schema projection.
Example
const available: JsonSchemaAvailable = { ok: true, schema: { type: "string" } };
Signature
export interface JsonSchemaAvailable {
readonly ok: true;
readonly schema: JsonSchema;
}
JsonSchemaDirection (type alias)
Projection direction accepted by getJsonSchema.
Example
const direction: JsonSchemaDirection = "input";
Signature
type JsonSchemaDirection = SchemaProjectionDirection;
JsonSchemaFactory (type alias)
Factory for a JSON-safe schema value.
Example
const projection: JsonSchemaFactory = () => ({ type: "string" });
Signature
type JsonSchemaFactory = () => JsonValue;
JsonSchemaOptions (interface)
Options for a JSON Schema projection.
Example
const options: JsonSchemaOptions = { direction: "output" };
Signature
export interface JsonSchemaOptions {
readonly direction?: JsonSchemaDirection;
}
JsonSchemaResult (type alias)
The result of a JSON Schema projection.
Example
const result: JsonSchemaResult = getJsonSchema(z.string());
Signature
type JsonSchemaResult = JsonSchemaAvailable | JsonSchemaUnavailable;
JsonSchemaUnavailable (interface)
An unavailable projection with a stable code and reason.
Example
const unavailable: JsonSchemaUnavailable = {
ok: false,
code: JSON_SCHEMA_UNAVAILABLE,
reason: "missing",
};
Signature
export interface JsonSchemaUnavailable {
readonly ok: false;
readonly code: typeof JSON_SCHEMA_UNAVAILABLE;
readonly reason: string;
}
schema-collection.ts
collectResults
Collects object or array validation results and preserves issue order.
Throws
The first rejected child validator in input order.
Example
collectResults([() => ({ value: 1 })], ([value]) => value);
Signature
declare const collectResults: <T, U>(
tasks: readonly SchemaTask<T>[],
map: (values: T[]) => U,
) => StandardResult<U> | Promise<StandardResult<U>>;
collectUnion
Selects the first successful union member in declaration order.
Throws
The first rejected validator in input order.
Example
collectUnion([() => ({ value: "ok" })], []);
Signature
declare const collectUnion: <T>(
tasks: readonly SchemaTask<T>[],
path: readonly StandardPathSegment[],
) => StandardResult<T> | Promise<StandardResult<T>>;
resolveTasksEffect
Resolves child validators in input order with bounded async concurrency.
Example
Effect.runPromise(resolveTasksEffect([() => Promise.resolve({ value: 1 })]));
Signature
declare const resolveTasksEffect: <T>(
tasks: readonly SchemaTask<T>[],
) => Effect.Effect<readonly StandardResult<T>[], SchemaExecutionError>;
schema-collection.types.ts
SchemaTask (type alias)
Deferred child validation used by object, array, and union schemas.
Example
const task: SchemaTask<number> = () => ({ value: 1 });
Signature
type SchemaTask<T> = () => StandardResult<T> | Promise<StandardResult<T>>;
schema-execution.ts
throwCause
Rethrows the original cause of an Effect execution failure.
Throws
The original cause.
Example
throwCause(new SchemaExecutionError({ cause: new TypeError("bad") }));
Signature
declare const throwCause: (error: unknown) => never;
schema-impl-helpers.ts
SchemaProjectionError (class)
Tagged failure for an unsupported target or missing projection.
The original exception remains available in cause.
Example
Effect.catchTag("SchemaProjectionError", (error) => Effect.succeed(error.cause));
Signature
declare class SchemaProjectionError
addPath
Prefixes nested issues without changing sync/async shape.
Example
addPath({ issues: [{ message: "bad" }] }, ["item"]);
Signature
declare const addPath: <T>(
result: StandardResult<T> | Promise<StandardResult<T>>,
path: readonly StandardPathSegment[],
) => StandardResult<T> | Promise<StandardResult<T>>;
addPathEffect
Prefixes issues from a nested third-party validator in Effect.
Example
Effect.runSync(addPathEffect({ issues: [{ message: "bad" }] }, ["item"]));
Signature
declare const addPathEffect: <T>(
result: StandardResult<T> | Promise<StandardResult<T>>,
path: readonly StandardPathSegment[],
) => Effect.Effect<StandardResult<T> | Promise<StandardResult<T>>>;
projectJsonSchema
Projects metadata through a Standard JSON Schema hook.
Throws
TypeError for an unsupported target or absent projection.
Example
projectJsonSchema({ jsonSchema: () => ({}) }, "input", "draft-07");
Signature
declare const projectJsonSchema: (
metadata: SchemaMetadata,
direction: "input" | "output",
target: StandardJSONSchemaV1.Options["target"],
) => Record<string, unknown>;
projectJsonSchemaEffect
Projects metadata through a Standard JSON Schema hook inside Effect.
Example
Effect.runSync(projectJsonSchemaEffect({ jsonSchema: () => ({}) }, "input", "draft-07"));
Signature
declare const projectJsonSchemaEffect: (
metadata: SchemaMetadata,
direction: "input" | "output",
target: StandardJSONSchemaV1.Options["target"],
) => Effect.Effect<Record<string, unknown>, SchemaProjectionError>;
schema-impl.ts
SchemaValidationError
Signature
declare const SchemaValidationError: typeof SchemaValidationError;
createSchema
Synchronous compatibility adapter for schema construction.
Throws
The original construction error if creation fails.
Example
createSchema((value) => ({ value }));
Signature
declare const createSchema: <TInput, TOutput>(
check: SchemaCheck<TOutput>,
metadata?: SchemaMetadata,
) => Schema<TInput, TOutput>;
createSchemaEffect
Constructs a schema within an observed Effect.
Example
Effect.runSync(createSchemaEffect((value) => ({ value })));
Signature
declare const createSchemaEffect: <TInput, TOutput>(
check: SchemaCheck<TOutput>,
metadata?: SchemaMetadata,
) => Effect.Effect<Schema<TInput, TOutput>, SchemaExecutionError>;
runSchema
Compatibility adapter for path-aware schema validation.
Throws
The original validator error if evaluation fails.
Example
runSchema(z.string(), "ok", ["name"]);
Signature
declare const runSchema: <TOutput>(
schema: StandardSchemaV1<unknown, TOutput>,
value: unknown,
path?: readonly StandardPathSegment[],
) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
runSchemaEffect
Evaluates a schema while preserving its synchronous or asynchronous result.
Example
Effect.runSync(runSchemaEffect(z.string(), "ok"));
Signature
declare const runSchemaEffect: <TOutput>(
schema: StandardSchemaV1<unknown, TOutput>,
value: unknown,
path?: readonly StandardPathSegment[],
) => Effect.Effect<
StandardResult<TOutput> | Promise<StandardResult<TOutput>>,
SchemaExecutionError
>;
schema-impl.types.ts
InternalSchema (interface)
RELKIT schema with its internal path-aware validation hook. The hook is only used while composing nested schemas.
Example
const internal = schema as InternalSchema<string, string>;
Signature
export interface InternalSchema<TInput, TOutput> extends Schema<TInput, TOutput> {
readonly _run: SchemaCheck<TOutput>;
}
SchemaCheck (type alias)
Path-aware validation callback used by a constructed RELKIT schema.
Example
const check: SchemaCheck<string> = (value) => ({ value: String(value) });
Signature
type SchemaCheck<T> = (
value: unknown,
path: readonly StandardPathSegment[],
) => StandardResult<T> | Promise<StandardResult<T>>;
schema-implementation.ts
SchemaImplementation (class)
Internal path-aware schema with Standard Schema and JSON Schema hooks.
Example
new SchemaImplementation((value) => ({ value }), {});
Signature
declare class SchemaImplementation<TInput, TOutput> {
constructor(check: SchemaCheck<TOutput>, metadata: SchemaMetadata);
}
optional (method)
Accepts an omitted or undefined value.
Example
z.string().optional();
Signature
declare const optional: () => Schema<TInput | undefined, TOutput | undefined>;
nullable (method)
Accepts null without changing other validation.
Example
z.string().nullable();
Signature
declare const nullable: () => Schema<TInput | null, TOutput | null>;
default (method)
Substitutes a value when input is undefined.
Example
z.string().default("pending");
Signature
declare const default: (value: TInput | (() => TInput)) => Schema<TInput | undefined, TOutput>
transform (method)
Maps a validated value to a new output.
Example
z.string().transform(Number);
Signature
declare const transform: <TNext>(
transform: (value: TOutput) => TNext | Promise<TNext>,
) => Schema<TInput, TNext>;
refine (method)
Adds a check after base validation succeeds.
Example
z.number().refine((value) => value > 0);
Signature
declare const refine: (
check: (value: TOutput) => boolean | Promise<boolean>,
message?: string,
) => Schema<TInput, TOutput>;
parse (method)
Parses one input synchronously.
Throws
SchemaValidationError or TypeError for invalid or asynchronous input.
Example
z.string().parse("ready");
Signature
declare const parse: (value: unknown) => TOutput;
parseAsync (method)
Parses one input and awaits asynchronous checks.
Throws
SchemaValidationError when validation fails.
Example
await z.string().parseAsync("ready");
Signature
declare const parseAsync: (value: unknown) => Promise<TOutput>;
safeParse (method)
Returns issues instead of throwing for invalid input.
Example
z.string().safeParse("ready");
Signature
declare const safeParse: (
value: unknown,
) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
_run (property)
Signature
readonly _run: SchemaCheck<TOutput>
“~standard” (property)
Signature
readonly "~standard": { readonly version: 1; readonly vendor: string; readonly validate: (value: unknown, options?: StandardSchemaOptions) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>; readonly types?: StandardSchemaTypes<TInput, TOutput>; } & StandardJSONSchemaV1.Props<TInput, TOutput>
relkit (property)
Signature
readonly relkit: SchemaProjectionHooks
schema-implementation.types.ts
Schema (interface)
RELKIT schema with parsing and composition methods. Input and output types may differ after transformation.
Example
const schema: Schema<string, number> = z.string().transform(Number);
Signature
export interface Schema<TInput = unknown, TOutput = TInput> extends RelkitSchema<TInput, TOutput> {
/**
* Accepts undefined as input and output.
* @returns A schema with optional value types.
* @example z.string().optional();
*/
optional(): Schema<TInput | undefined, TOutput | undefined>;
/**
* Accepts null as input and output.
* @returns A nullable schema.
* @example z.string().nullable();
*/
nullable(): Schema<TInput | null, TOutput | null>;
/**
* Supplies a value for undefined input.
* @param value - Constant or lazy default.
* @returns A schema with optional input and required output.
* @example z.string().default("ready");
*/
default(value: TInput | (() => TInput)): Schema<TInput | undefined, TOutput>;
/**
* Maps a valid output to a new value.
* @param transform - Synchronous or asynchronous mapper.
* @returns A schema with the mapped output type.
* @example z.string().transform(Number);
*/
transform<TNext>(transform: (value: TOutput) => TNext | Promise<TNext>): Schema<TInput, TNext>;
/**
* Checks a valid output with a predicate.
* @param check - Predicate for valid output.
* @param message - Failure message.
* @returns A refined schema.
* @example z.number().refine((value) => value > 0);
*/
refine(
check: (value: TOutput) => boolean | Promise<boolean>,
message?: string,
): Schema<TInput, TOutput>;
/**
* Parses synchronously or throws.
* @param value - Input to parse.
* @returns Validated output.
* @throws SchemaValidationError or TypeError for invalid or asynchronous input.
* @example z.string().parse("ready");
*/
parse(value: unknown): TOutput;
/**
* Parses and awaits asynchronous checks.
* @param value - Input to parse.
* @returns A promise of validated output.
* @throws SchemaValidationError for invalid input.
* @example await z.string().parseAsync("ready");
*/
parseAsync(value: unknown): Promise<TOutput>;
/**
* Returns a result for sync or async validation.
* @param value - Input to validate.
* @returns A result or promise with value or issues.
* @example z.string().safeParse("ready");
*/
safeParse(value: unknown): StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
}
SchemaProjectionHooks (interface)
Directional JSON Schema projection hooks carried by a RELKIT schema.
Example
const hooks: SchemaProjectionHooks = { jsonSchema: () => ({ type: "string" }) };
Signature
export interface SchemaProjectionHooks {
readonly jsonSchema?: () => JsonValue;
readonly inputJsonSchema?: () => JsonValue;
readonly outputJsonSchema?: () => JsonValue;
}
schema-metadata-composition.ts
withDefaultMetadata
Adds a static default only to output and legacy projections.
Example
withDefaultMetadata(z.string(), "ready");
Signature
declare const withDefaultMetadata: <T>(
schema: StandardSchemaV1,
value: T | (() => T),
) => SchemaMetadata;
withDefaultMetadataEffect
Builds default metadata in Effect without evaluating lazy values.
Example
Effect.runSync(withDefaultMetadataEffect(z.string(), "ready"));
Signature
declare const withDefaultMetadataEffect: <T>(
schema: StandardSchemaV1,
value: T | (() => T),
) => Effect.Effect<SchemaMetadata>;
withNullableMetadata
Wraps each available projection in a nullable union.
Example
withNullableMetadata(z.string());
Signature
declare const withNullableMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withNullableMetadataEffect
Builds nullable metadata in Effect.
Example
Effect.runSync(withNullableMetadataEffect(z.string()));
Signature
declare const withNullableMetadataEffect: (
schema: StandardSchemaV1,
) => Effect.Effect<SchemaMetadata>;
withOptionalMetadata
Marks a schema optional in both projection directions.
Example
withOptionalMetadata(z.string());
Signature
declare const withOptionalMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withOptionalMetadataEffect
Builds optional metadata in Effect.
Example
Effect.runSync(withOptionalMetadataEffect(z.string()));
Signature
declare const withOptionalMetadataEffect: (
schema: StandardSchemaV1,
) => Effect.Effect<SchemaMetadata>;
withRefinementMetadata
Preserves projection metadata while marking a schema refined.
Example
withRefinementMetadata(z.string());
Signature
declare const withRefinementMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withRefinementMetadataEffect
Builds refinement metadata in Effect.
Example
Effect.runSync(withRefinementMetadataEffect(z.string()));
Signature
declare const withRefinementMetadataEffect: (
schema: StandardSchemaV1,
) => Effect.Effect<SchemaMetadata>;
withTransformMetadata
Keeps only input projection metadata after a transform.
Example
withTransformMetadata(z.string());
Signature
declare const withTransformMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withTransformMetadataEffect
Builds transform metadata in Effect.
Example
Effect.runSync(withTransformMetadataEffect(z.string()));
Signature
declare const withTransformMetadataEffect: (
schema: StandardSchemaV1,
) => Effect.Effect<SchemaMetadata>;
schema-metadata.ts
SchemaMetadata
Signature
declare const SchemaMetadata: SchemaMetadata;
SchemaMetadataError (class)
Tagged failure when schema metadata cannot be attached.
The original exception remains available in cause.
Example
Effect.catchTag("SchemaMetadataError", (error) => Effect.succeed(error.cause));
Signature
declare class SchemaMetadataError
SchemaProjection
Signature
declare const SchemaProjection: SchemaProjection;
SchemaProjectionDirection
Signature
declare const SchemaProjectionDirection: SchemaProjectionDirection;
getMetadataProjection
Selects the projection hook for a direction.
Example
getMetadataProjection({}, "output");
Signature
declare const getMetadataProjection: (
metadata: SchemaMetadata | undefined,
direction?: SchemaProjectionDirection | "legacy",
) => SchemaProjection | undefined;
getMetadataProjectionEffect
Selects the requested projection hook inside Effect.
Example
Effect.runSync(getMetadataProjectionEffect({}, "input"));
Signature
declare const getMetadataProjectionEffect: (
metadata: SchemaMetadata | undefined,
direction?: SchemaProjectionDirection | "legacy",
) => Effect.Effect<SchemaMetadata["jsonSchema"]>;
getSchemaMetadata
Reads metadata attached to a schema.
Example
getSchemaMetadata(z.string());
Signature
declare const getSchemaMetadata: (schema: StandardSchemaV1) => SchemaMetadata | undefined;
getSchemaMetadataEffect
Reads attached metadata inside Effect.
Example
Effect.runSync(getSchemaMetadataEffect(z.string()));
Signature
declare const getSchemaMetadataEffect: (
schema: StandardSchemaV1,
) => Effect.Effect<SchemaMetadata | undefined>;
isMetadataOptional
Checks whether a schema accepts an omitted property.
Example
isMetadataOptional({ optional: true });
Signature
declare const isMetadataOptional: (
metadata: SchemaMetadata | undefined,
direction?: SchemaProjectionDirection | "legacy",
) => boolean;
isMetadataOptionalEffect
Checks optionality inside Effect.
Example
Effect.runSync(isMetadataOptionalEffect({ optional: true }));
Signature
declare const isMetadataOptionalEffect: (
metadata: SchemaMetadata | undefined,
direction?: SchemaProjectionDirection | "legacy",
) => Effect.Effect<boolean>;
isSchemaTransformed
Checks whether a schema has a value transform.
Example
isSchemaTransformed(z.string().transform(Number));
Signature
declare const isSchemaTransformed: (schema: StandardSchemaV1) => boolean;
isSchemaTransformedEffect
Checks whether a schema has been transformed inside Effect.
Example
Effect.runSync(isSchemaTransformedEffect(z.string()));
Signature
declare const isSchemaTransformedEffect: (schema: StandardSchemaV1) => Effect.Effect<boolean>;
setSchemaMetadata
Attaches metadata for cross-copy projection lookup.
Throws
The original property-definition error.
Example
setSchemaMetadata(z.string(), { optional: true });
Signature
declare const setSchemaMetadata: (schema: StandardSchemaV1, metadata: SchemaMetadata) => void;
setSchemaMetadataEffect
Attaches metadata inside Effect.
Example
Effect.runSync(setSchemaMetadataEffect(z.string(), {}));
Signature
declare const setSchemaMetadataEffect: (
schema: StandardSchemaV1,
metadata: SchemaMetadata,
) => Effect.Effect<void, SchemaMetadataError>;
withDefaultMetadata
Signature
declare const withDefaultMetadata: <T>(
schema: StandardSchemaV1,
value: T | (() => T),
) => SchemaMetadata;
withNullableMetadata
Signature
declare const withNullableMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withOptionalMetadata
Signature
declare const withOptionalMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withRefinementMetadata
Signature
declare const withRefinementMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
withTransformMetadata
Signature
declare const withTransformMetadata: (schema: StandardSchemaV1) => SchemaMetadata;
schema-metadata.types.ts
SchemaMetadata (interface)
Metadata attached to a RELKIT schema for deterministic projection. Directional hooks may differ after a transform or default is applied.
Example
const metadata: SchemaMetadata = { jsonSchema: () => ({ type: "string" }) };
Signature
export interface SchemaMetadata {
/** Historical projection used by getJsonSchema(schema) without options. */
readonly jsonSchema?: SchemaProjection;
readonly inputJsonSchema?: SchemaProjection;
readonly outputJsonSchema?: SchemaProjection;
readonly optional?: boolean;
readonly inputOptional?: boolean;
readonly outputOptional?: boolean;
readonly transformed?: boolean;
readonly refined?: boolean;
}
SchemaProjection (type alias)
Factory for a JSON-safe schema projection.
Example
const projection: SchemaProjection = () => ({ type: "string" });
Signature
type SchemaProjection = () => JsonValue;
SchemaProjectionDirection (type alias)
Projection direction for input or validated output.
Example
const direction: SchemaProjectionDirection = "input";
Signature
type SchemaProjectionDirection = "input" | "output";
schema-observability.ts
SchemaOperation
Signature
declare const SchemaOperation: SchemaOperation;
SchemaTelemetry (class)
Injectable observer for schema operation spans and metrics.
Example
Effect.provide(validateEffect(z.string(), "ok"), SchemaTelemetryLive);
Signature
declare class SchemaTelemetry
SchemaTelemetryLive
Live schema telemetry based on Effect spans, Clock, and Metric.
Example
Effect.runSync(Effect.provide(validateSyncEffect(z.string(), "ok"), SchemaTelemetryLive));
Signature
declare const SchemaTelemetryLive: Layer.Layer<SchemaTelemetry, never, never>;
SchemaTelemetryService
Signature
declare const SchemaTelemetryService: SchemaTelemetryService;
observeSchema
Instruments a schema operation with bounded metric labels.
Example
observeSchema("json-schema", Effect.succeed({ ok: true }));
Signature
declare const observeSchema: <A, E, R>(
operation: SchemaOperation,
effect: Effect.Effect<A, E, R>,
) => Effect.Effect<A, E, R>;
runSchemaSync
Runs a fully provided synchronous Effect and preserves its failure.
Throws
The original cause on failure.
Example
runSchemaSync(Effect.succeed(1));
Signature
declare const runSchemaSync: <A, E>(effect: Effect.Effect<A, E>) => A;
schema-observability.types.ts
SchemaOperation (type alias)
Fixed operation names used for schema telemetry labels. The union prevents input data from entering metric cardinality.
Example
const operation: SchemaOperation = "validate";
Signature
type SchemaOperation =
| "builder.string"
| "builder.number"
| "builder.boolean"
| "builder.unknown"
| "builder.any"
| "builder.null"
| "builder.undefined"
| "builder.literal"
| "builder.object"
| "builder.array"
| "builder.union"
| "builder.file"
| "builder.string-refine"
| "builder.number-refine"
| "schema.optional"
| "schema.nullable"
| "schema.default"
| "schema.transform"
| "schema.refine"
| "validate"
| "validate-sync"
| "json-schema"
| "schema.create"
| "schema.run"
| "schema.parse"
| "schema.parse-async"
| "schema.safe-parse";
SchemaTelemetryService (interface)
Injectable observer for schema operations. A test Layer can replace the live span and metric behavior.
Example
Layer.succeed(SchemaTelemetry, { observe: (_name, effect) => effect });
Signature
export interface SchemaTelemetryService {
/**
* Wraps one operation without changing its Effect channels.
* @param operation - Fixed operation name.
* @param effect - Operation being observed.
* @returns The observed Effect with its original success and error channels.
* @example telemetry.observe("validate", Effect.succeed(1));
*/
readonly observe: <A, E, R>(
operation: SchemaOperation,
effect: Effect.Effect<A, E, R>,
) => Effect.Effect<A, E, R>;
}
schema-parse.ts
parseSchemaAsync
Parses asynchronously while preserving compatibility exceptions.
Throws
SchemaValidationError or the original callback error.
Example
await parseSchemaAsync(() => Promise.resolve({ value: "ok" }));
Signature
declare const parseSchemaAsync: <T>(check: SchemaParseCheck<T>) => Promise<T>;
parseSchemaAsyncEffect
Parses one schema input asynchronously in Effect.
Example
Effect.runPromise(parseSchemaAsyncEffect(() => Promise.resolve({ value: "ok" })));
Signature
declare const parseSchemaAsyncEffect: <T>(
check: SchemaParseCheck<T>,
) => Effect.Effect<T, SchemaIssuesError | SchemaExecutionError>;
parseSchemaSync
Parses synchronously while preserving compatibility exceptions.
Throws
SchemaValidationError, TypeError, or the original callback error.
Example
parseSchemaSync(() => ({ value: "ok" }));
Signature
declare const parseSchemaSync: <T>(check: SchemaParseCheck<T>) => T;
parseSchemaSyncEffect
Parses one schema input synchronously in Effect.
Example
Effect.runSync(parseSchemaSyncEffect(() => ({ value: "ok" })));
Signature
declare const parseSchemaSyncEffect: <T>(
check: SchemaParseCheck<T>,
) => Effect.Effect<T, SchemaIssuesError | SchemaAsyncError | SchemaExecutionError>;
safeParseSchema
Validates while preserving a synchronous or asynchronous result.
Throws
The original callback error.
Example
safeParseSchema(() => ({ value: "ok" }));
Signature
declare const safeParseSchema: <T>(
check: SchemaParseCheck<T>,
) => StandardResult<T> | Promise<StandardResult<T>>;
schema-parse.types.ts
SchemaParseCheck (type alias)
Deferred schema check used by parsing compatibility adapters.
Example
const check: SchemaParseCheck<string> = () => ({ value: "ok" });
Signature
type SchemaParseCheck<T> = () => StandardResult<T> | Promise<StandardResult<T>>;
schema-result.ts
failure
Creates a failure result.
Example
failure("bad", ["name"]);
Signature
declare const failure: (message: string, path: readonly StandardPathSegment[]) => StandardFailure;
failureEffect
Creates a failure result in Effect.
Example
Effect.runSync(failureEffect("bad", ["name"]));
Signature
declare const failureEffect: (
message: string,
path: readonly StandardPathSegment[],
) => Effect.Effect<StandardFailure>;
flatMapResult
Chains successful validation and preserves sync/async shape.
Example
flatMapResult({ value: 1 }, (value) => ({ value: value + 1 }));
Signature
declare const flatMapResult: <T, U>(
result: StandardResult<T> | Promise<StandardResult<T>>,
map: (value: T) => StandardResult<U> | Promise<StandardResult<U>>,
) => StandardResult<U> | Promise<StandardResult<U>>;
flatMapResultEffect
Chains successful validation while retaining failures in Effect.
Example
Effect.runSync(flatMapResultEffect({ value: 1 }, (value) => ({ value })));
Signature
declare const flatMapResultEffect: <T, U>(
result: StandardResult<T> | Promise<StandardResult<T>>,
map: (value: T) => StandardResult<U> | Promise<StandardResult<U>>,
) => Effect.Effect<StandardResult<U> | Promise<StandardResult<U>>>;
isFailure
Narrows a result to a validation failure.
Example
isFailure({ issues: [{ message: "bad" }] });
Signature
declare const isFailure: <T>(result: StandardResult<T>) => result is StandardFailure;
isFailureEffect
Detects a failure result in Effect.
Example
Effect.runSync(isFailureEffect({ issues: [] }));
Signature
declare const isFailureEffect: <T>(result: StandardResult<T>) => Effect.Effect<boolean>;
isPromiseLike
Narrows a value to a promise-like object.
Example
isPromiseLike(Promise.resolve(1));
Signature
declare const isPromiseLike: <T>(value: unknown) => value is PromiseLike<T>;
isPromiseLikeEffect
Detects thenable objects in Effect.
Example
Effect.runSync(isPromiseLikeEffect(Promise.resolve(1)));
Signature
declare const isPromiseLikeEffect: (value: unknown) => Effect.Effect<boolean>;
mapResult
Maps a result without changing whether it is synchronous.
Example
mapResult({ value: 1 }, (result) => result);
Signature
declare const mapResult: <T, U>(
result: StandardResult<T> | Promise<StandardResult<T>>,
map: (value: StandardResult<T>) => U,
) => U | Promise<U>;
mapResultEffect
Maps a synchronous or asynchronous validation result in Effect.
Example
Effect.runSync(mapResultEffect({ value: 1 }, (result) => result));
Signature
declare const mapResultEffect: <T, U>(
result: StandardResult<T> | Promise<StandardResult<T>>,
map: (value: StandardResult<T>) => U,
) => Effect.Effect<U | Promise<U>>;
mapValue
Maps a value without changing whether it is synchronous.
Example
mapValue(1, (value) => value + 1);
Signature
declare const mapValue: <T, U>(value: T | Promise<T>, map: (value: T) => U) => U | Promise<U>;
mapValueEffect
Maps a value or promise inside Effect.
Example
Effect.runSync(mapValueEffect(1, (value) => value + 1));
Signature
declare const mapValueEffect: <T, U>(
value: T | Promise<T>,
map: (value: T) => U,
) => Effect.Effect<U | Promise<U>>;
success
Creates a success result.
Example
success("ready");
Signature
declare const success: <T>(value: T) => StandardSuccess<T>;
successEffect
Creates a success result in Effect.
Example
Effect.runSync(successEffect("ready"));
Signature
declare const successEffect: <T>(value: T) => Effect.Effect<StandardSuccess<T>>;
schema-validation-error.ts
SchemaValidationError (class)
Compatibility error thrown when parsing returns validation issues.
Example
try {
z.string().parse(1);
} catch (error) {
console.error(error);
}
Signature
declare class SchemaValidationError {
constructor(issues: StandardFailure["issues"]);
}
issues (property)
Signature
readonly issues: ReadonlyArray<StandardIssue>
standard-schema-effect.ts
SchemaAsyncError (class)
Tagged failure when a synchronous call reaches an asynchronous validator.
Example
Effect.catchTag("SchemaAsyncError", () => Effect.succeed(undefined));
Signature
declare class SchemaAsyncError
SchemaExecutionError (class)
Tagged failure when a validator throws or rejects.
The original exception remains available in cause.
Example
Effect.catchTag("SchemaExecutionError", (error) => Effect.succeed(error.cause));
Signature
declare class SchemaExecutionError
SchemaInvalidError (class)
Tagged failure when a value is not a Standard Schema v1 validator.
Example
Effect.catchTag("SchemaInvalidError", (error) => Effect.succeed(error.reason));
Signature
declare class SchemaInvalidError
SchemaIssuesError (class)
Tagged failure representing ordinary validation issues.
Example
Effect.catchTag("SchemaIssuesError", (error) => Effect.succeed(error.issues));
Signature
declare class SchemaIssuesError
SchemaValidator (class)
Injectable boundary for external Standard Schema validators.
Example
Effect.provide(validateEffect(z.string(), "ok"), SchemaValidatorLive);
Signature
declare class SchemaValidator
SchemaValidatorLive
Live validator Layer that delegates to the Standard Schema hook.
Example
Effect.runPromise(Effect.provide(validateEffect(z.string(), "ok"), SchemaValidatorLive));
Signature
declare const SchemaValidatorLive: Layer.Layer<SchemaValidator, never, never>;
validateEffect
Validates an input and fails with tagged errors for issues and hook failures.
Example
Effect.runPromise(Effect.provide(validateEffect(z.string(), "ok"), SchemaValidatorLive));
Signature
declare const validateEffect: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => Effect.Effect<
InferOutput<S>,
SchemaIssuesError | SchemaInvalidError | SchemaExecutionError,
SchemaValidator
>;
validateMaybeEffect
Calls a validator while retaining its synchronous or asynchronous shape.
Example
Effect.runSync(Effect.provide(validateMaybeEffect(z.string(), "ok"), SchemaValidatorLive));
Signature
declare const validateMaybeEffect: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => Effect.Effect<
StandardResult<InferOutput<S>> | Promise<StandardResult<InferOutput<S>>>,
SchemaInvalidError | SchemaExecutionError,
SchemaValidator
>;
validateSyncEffect
Validates without waiting and rejects asynchronous validators by tag.
Example
Effect.runSync(Effect.provide(validateSyncEffect(z.number(), 2), SchemaValidatorLive));
Signature
declare const validateSyncEffect: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => Effect.Effect<
InferOutput<S>,
SchemaIssuesError | SchemaInvalidError | SchemaExecutionError | SchemaAsyncError,
SchemaValidator
>;
standard-schema-effect.types.ts
SchemaValidatorService (interface)
Substitutable boundary for third-party Standard Schema validation. Test Layers can provide a deterministic validator.
Example
Layer.succeed(SchemaValidator, { validate: () => ({ value: "ok" }) });
Signature
export interface SchemaValidatorService {
/**
* Runs one Standard Schema validation hook.
* @param schema - Compatible validator.
* @param value - Candidate input.
* @returns A result or promise of a result.
* @example validator.validate(z.string(), "ok");
*/
readonly validate: <T>(
schema: StandardSchemaV1<unknown, T>,
value: unknown,
) => StandardResult<T> | Promise<StandardResult<T>>;
}
standard-schema.ts
validate
Validates with a Standard Schema v1 compatible validator.
Throws
TypeError when the validator does not implement Standard Schema v1.
Example
import { validate, z } from "@relkit/app/schema";
const result = await validate(z.string(), "ready");
if (!("value" in result)) throw new Error("validation failed");
Signature
declare const validate: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => StandardResult<InferOutput<S>> | Promise<StandardResult<InferOutput<S>>>;
Since v0.1.0
InferInput
Signature
declare const InferInput: InferInput<S>;
InferOutput
Signature
declare const InferOutput: InferOutput<S>;
JsonValue
Signature
declare const JsonValue: JsonValue;
RelkitSchema
Signature
declare const RelkitSchema: RelkitSchema<TInput, TOutput>;
Schema
Signature
declare const Schema: Schema<TInput, TOutput>;
SchemaValidationError
Signature
declare const SchemaValidationError: typeof SchemaValidationError;
StandardFailure
Signature
declare const StandardFailure: StandardFailure;
StandardIssue
Signature
declare const StandardIssue: StandardIssue;
StandardJSONSchemaV1
Signature
declare const StandardJSONSchemaV1: StandardJSONSchemaV1<TInput, TOutput>;
StandardPathSegment
Signature
declare const StandardPathSegment: StandardPathSegment;
StandardResult
Signature
declare const StandardResult: StandardResult<T>;
StandardSchemaOptions
Signature
declare const StandardSchemaOptions: StandardSchemaOptions;
StandardSchemaTypes
Signature
declare const StandardSchemaTypes: StandardSchemaTypes<TInput, TOutput>;
StandardSchemaV1
Signature
declare const StandardSchemaV1: StandardSchemaV1<TInput, TOutput>;
StandardSuccess
Signature
declare const StandardSuccess: StandardSuccess<T>;
createSchema
Signature
declare const createSchema: <TInput, TOutput>(
check: SchemaCheck<TOutput>,
metadata?: SchemaMetadata,
) => Schema<TInput, TOutput>;
isPromiseLike
Signature
declare const isPromiseLike: <T>(value: unknown) => value is PromiseLike<T>;
issue
Constructs a portable validation failure at a schema path.
Example
issue("Expected a string", ["name"]);
Signature
declare const issue: (message: string, path: readonly StandardPathSegment[]) => StandardFailure;
runSchema
Signature
declare const runSchema: <TOutput>(
schema: StandardSchemaV1<unknown, TOutput>,
value: unknown,
path?: readonly StandardPathSegment[],
) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
validateSync
Validates synchronously with a Standard Schema v1 compatible validator.
Throws
TypeError when the validator is invalid or asynchronous.
Example
const result = validateSync(z.number(), 3);
Signature
declare const validateSync: <S extends StandardSchemaV1>(
schema: S,
value: InferInput<S>,
) => StandardResult<InferOutput<S>>;
standard-schema.types.ts
A Standard Schema issue path accepts keys and structured segments.
Example
const path: StandardPathSegment[] = ["items", 0, { key: "name" }];
InferInput (type alias)
Infers the accepted input type of a compatible schema.
Example
type Input = InferInput<typeof schema>;
Signature
type InferInput<S extends StandardSchemaV1> = S["~standard"] extends {
readonly types?: infer Types;
}
? Types extends StandardSchemaTypes<infer Input, unknown>
? Input
: unknown
: unknown;
InferOutput (type alias)
Infers the validated output type of a compatible schema.
Example
type Output = InferOutput<typeof schema>;
Signature
type InferOutput<S extends StandardSchemaV1> = S["~standard"] extends {
readonly types?: infer Types;
}
? Types extends StandardSchemaTypes<unknown, infer Output>
? Output
: unknown
: unknown;
JsonValue (type alias)
JSON-safe value produced by a schema projection hook.
Example
const projection: JsonValue = { type: "string" };
Signature
type JsonValue =
string | number | boolean | null | readonly JsonValue[] | { readonly [key: string]: JsonValue };
RelkitSchema (interface)
RELKIT schema boundary with optional legacy and directional projections.
Example
const schema: RelkitSchema = z.string();
Signature
export interface RelkitSchema<TInput = unknown, TOutput = TInput> extends StandardSchemaV1<
TInput,
TOutput
> {
readonly "~standard": StandardSchemaV1<TInput, TOutput>["~standard"] &
StandardJSONSchemaV1<TInput, TOutput>["~standard"];
readonly relkit?: {
readonly jsonSchema?: () => JsonValue;
readonly inputJsonSchema?: () => JsonValue;
readonly outputJsonSchema?: () => JsonValue;
};
}
Schema
Signature
declare const Schema: Schema<TInput, TOutput>;
StandardFailure (interface)
Standard Schema validation failure with structured issues.
Example
const failure: StandardFailure = { issues: [{ message: "Required" }] };
Signature
export interface StandardFailure {
readonly issues: readonly StandardIssue[];
}
StandardIssue (interface)
A portable issue that may identify a nested path.
Example
const issue: StandardIssue = { message: "Required", path: ["name"] };
Signature
export interface StandardIssue {
readonly message: string;
readonly path?: readonly StandardPathSegment[];
}
StandardJSONSchemaV1 (interface)
Standard JSON Schema v1 projection contract.
Example
schema["~standard"].jsonSchema.input({ target: "draft-2020-12" });
Signature
export interface StandardJSONSchemaV1<TInput = unknown, TOutput = TInput> {
readonly "~standard": StandardJSONSchemaV1.Props<TInput, TOutput>;
}
StandardJSONSchemaV1 (namespace)
Props (interface)
Type and projection hooks advertised by a schema.
Example
const props: StandardJSONSchemaV1.Props = schema["~standard"];
Signature
export interface Props<Input = unknown, Output = Input> {
readonly version: 1;
readonly vendor: string;
readonly types?: StandardSchemaTypes<Input, Output>;
readonly jsonSchema: {
readonly input: (options: Options) => Record<string, unknown>;
readonly output: (options: Options) => Record<string, unknown>;
};
}
Options (interface)
Dialect and vendor options for Standard JSON Schema hooks.
Example
const options: StandardJSONSchemaV1.Options = { target: "draft-2020-12" };
Signature
export interface Options {
readonly target: "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
readonly libraryOptions?: Record<string, unknown> | undefined;
}
StandardPathSegment (type alias)
A Standard Schema issue path accepts keys and structured segments.
Example
const path: StandardPathSegment[] = ["items", 0, { key: "name" }];
Signature
type StandardPathSegment = PropertyKey | { readonly key: PropertyKey };
StandardResult (type alias)
Result union that preserves issues instead of throwing.
Example
const result: StandardResult<number> = { value: 2 };
Signature
type StandardResult<T> = StandardSuccess<T> | StandardFailure;
StandardSchemaOptions (interface)
Vendor-specific options accepted by a compatible validator.
Example
const options: StandardSchemaOptions = { libraryOptions: {} };
Signature
export interface StandardSchemaOptions {
readonly libraryOptions?: Record<string, unknown> | undefined;
}
StandardSchemaTypes (interface)
Phantom input and output types advertised by Standard Schema.
Example
type Types = StandardSchemaTypes<string, number>;
Signature
export interface StandardSchemaTypes<TInput = unknown, TOutput = TInput> {
readonly input: TInput;
readonly output: TOutput;
}
StandardSchemaV1 (interface)
Standard Schema v1 contract accepted by RELKIT. The validate hook may return synchronously or asynchronously.
Example
const result = await schema["~standard"].validate(value);
Signature
export interface StandardSchemaV1<TInput = unknown, TOutput = TInput> {
readonly "~standard": {
readonly version: 1;
readonly vendor: string;
/**
* Validates unknown input.
* @param value - Candidate input.
* @param options - Optional vendor settings.
* @returns A validation result or promise of one.
* @example schema["~standard"].validate("ready");
*/
readonly validate: (
value: unknown,
options?: StandardSchemaOptions,
) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
readonly types?: StandardSchemaTypes<TInput, TOutput>;
};
}
StandardSchemaV1 (namespace)
Namespace aliases matching the official Standard Schema v1 vocabulary.
Example
type Result = StandardSchemaV1.Result<string>;
Props (type alias)
Signature
type Props<Input = unknown, Output = Input> = StandardSchemaV1<Input, Output>["~standard"];
Result (type alias)
Signature
type Result<Output> = StandardResult<Output>;
SuccessResult (type alias)
Signature
type SuccessResult<Output> = StandardSuccess<Output>;
FailureResult (type alias)
Signature
type FailureResult = StandardFailure;
Issue (type alias)
Signature
type Issue = StandardIssue;
PathSegment (type alias)
Signature
type PathSegment = { readonly key: PropertyKey };
Types (type alias)
Signature
type Types<Input = unknown, Output = Input> = StandardSchemaTypes<Input, Output>;
Options (type alias)
Signature
type Options = StandardSchemaOptions;
InferInput (type alias)
Signature
type InferInput<S extends StandardSchemaV1> = import("./standard-schema.types.js").InferInput<S>;
InferOutput (type alias)
Signature
type InferOutput<S extends StandardSchemaV1> = import("./standard-schema.types.js").InferOutput<S>;
StandardSuccess (interface)
Successful Standard Schema validation with a typed output.
Example
const success: StandardSuccess<string> = { value: "ready" };
Signature
export interface StandardSuccess<T> {
readonly value: T;
readonly issues?: undefined;
}