@samveys/validator
Typed schemas implementing Standard Schema v1
This list was read from version 1.0.2; run pnpm sync to refresh it.
import { isOptional, toJsonSchema, schema, ValidationError } from '@samveys/validator'
Function (2)
isOptional
Function
True when the schema accepts `undefined` (optional or defaulted): the property is not required.
function isOptional(schema: StandardSchemaV1): boolean;
Exported from packages/validator/src/json-schema.ts
toJsonSchema
Function
JSON Schema (draft 2020-12, as used by OpenAPI 3.1) for a `@samveys/validator` schema, describing its INPUT. Custom `refine()` checks and `transform()`s cannot be expressed and are left out; unknown Standard Schema vendors become `{}` (any value).
function toJsonSchema(schema: StandardSchemaV1): JsonSchema;
Exported from packages/validator/src/json-schema.ts
Value (1)
schema
Value
Every factory of the locked `SchemaBuilder` contract; all return immutable schemas.
const schema: SchemaBuilder;
Exported from packages/validator/src/builders.ts
Class (1)
ValidationError
Class
Thrown by `parse`; carries every issue found, not only the first.
class ValidationError extends Error {
readonly issues: readonly ValidationIssueOut[];
constructor(issues: readonly SchemaIssue[]);
}
Exported from packages/validator/src/schema.ts
Interface (7)
ArraySchema
Interface
No documentation comment.
interface ArraySchema<Item extends StandardSchemaV1> extends Schema<InferInput<Item>[], Infer<Item>[]> {
min(length: number, message?: string): ArraySchema<Item>;
max(length: number, message?: string): ArraySchema<Item>;
}
Exported from packages/validator/src/contracts.ts
NumberSchema
Interface
No documentation comment.
interface NumberSchema extends Schema<number, number> {
min(value: number, message?: string): NumberSchema;
max(value: number, message?: string): NumberSchema;
int(message?: string): NumberSchema;
positive(message?: string): NumberSchema;
}
Exported from packages/validator/src/contracts.ts
ObjectSchema
Interface
No documentation comment.
interface ObjectSchema<S extends ObjectShape> extends Schema<ObjectInput<S>, ObjectOutput<S>> {
readonly shape: S;
/** Default: unknown keys are removed from the output (used by response schemas). */
strip(): ObjectSchema<S>;
/** Unknown keys are an issue. */
strict(): ObjectSchema<S>;
/** Unknown keys are copied, except `__proto__`, `constructor`, `prototype`. */
passthrough(): ObjectSchema<S>;
extend<E extends ObjectShape>(shape: E): ObjectSchema<Omit<S, keyof E> & E>;
pick<K extends keyof S & string>(...keys: readonly K[]): ObjectSchema<Pick<S, K>>;
…
Show the whole declaration (15 lines)
interface ObjectSchema<S extends ObjectShape> extends Schema<ObjectInput<S>, ObjectOutput<S>> {
readonly shape: S;
/** Default: unknown keys are removed from the output (used by response schemas). */
strip(): ObjectSchema<S>;
/** Unknown keys are an issue. */
strict(): ObjectSchema<S>;
/** Unknown keys are copied, except `__proto__`, `constructor`, `prototype`. */
passthrough(): ObjectSchema<S>;
extend<E extends ObjectShape>(shape: E): ObjectSchema<Omit<S, keyof E> & E>;
pick<K extends keyof S & string>(...keys: readonly K[]): ObjectSchema<Pick<S, K>>;
…interface ObjectSchema<S extends ObjectShape> extends Schema<ObjectInput<S>, ObjectOutput<S>> {
readonly shape: S;
/** Default: unknown keys are removed from the output (used by response schemas). */
strip(): ObjectSchema<S>;
/** Unknown keys are an issue. */
strict(): ObjectSchema<S>;
/** Unknown keys are copied, except `__proto__`, `constructor`, `prototype`. */
passthrough(): ObjectSchema<S>;
extend<E extends ObjectShape>(shape: E): ObjectSchema<Omit<S, keyof E> & E>;
pick<K extends keyof S & string>(...keys: readonly K[]): ObjectSchema<Pick<S, K>>;
omit<K extends keyof S & string>(...keys: readonly K[]): ObjectSchema<Omit<S, K>>;
partial(): ObjectSchema<{
[K in keyof S]: Schema<InferInput<S[K]> | undefined, Infer<S[K]> | undefined>;
}>;
}
Exported from packages/validator/src/contracts.ts
Schema
Interface
A schema producing `Output` from `Input`. Immutable: every modifier returns a new schema.
interface Schema<Input = unknown, Output = Input> extends StandardSchemaV1<Input, Output> {
readonly kind: string;
/** Accepts `undefined`; the key may be absent in objects. */
optional(): Schema<Input | undefined, Output | undefined>;
/** Accepts `null`. */
nullable(): Schema<Input | null, Output | null>;
/** Uses `value` when the input is `undefined`; the key may be absent in objects. */
default(value: Exclude<Output, undefined> | (() => Exclude<Output, undefined>)): Schema<Input | undefined, Exclude<Output, undefined>>;
Exported from packages/validator/src/contracts.ts
SchemaBuilder
Interface
No documentation comment.
interface SchemaBuilder {
string(message?: string): StringSchema;
number(message?: string): NumberSchema;
/** Accepts numbers and numeric strings (query and params); output is a number. */
coerceNumber(message?: string): NumberSchema;
boolean(message?: string): Schema<boolean, boolean>;
/** Accepts booleans and `'true' | 'false' | '1' | '0'`. */
coerceBoolean(message?: string): Schema<boolean | string, boolean>;
literal<const V extends string | number | boolean | null>(value: V, message?: string): Schema<V, V>;
enum<const V extends readonly [string, ...string[]]>(values: V, message?: string): Schema<V[number], V[number]>;
…
Show the whole declaration (17 lines)
interface SchemaBuilder {
string(message?: string): StringSchema;
number(message?: string): NumberSchema;
/** Accepts numbers and numeric strings (query and params); output is a number. */
coerceNumber(message?: string): NumberSchema;
boolean(message?: string): Schema<boolean, boolean>;
/** Accepts booleans and `'true' | 'false' | '1' | '0'`. */
coerceBoolean(message?: string): Schema<boolean | string, boolean>;
literal<const V extends string | number | boolean | null>(value: V, message?: string): Schema<V, V>;
enum<const V extends readonly [string, ...string[]]>(values: V, message?: string): Schema<V[number], V[number]>;
…interface SchemaBuilder {
string(message?: string): StringSchema;
number(message?: string): NumberSchema;
/** Accepts numbers and numeric strings (query and params); output is a number. */
coerceNumber(message?: string): NumberSchema;
boolean(message?: string): Schema<boolean, boolean>;
/** Accepts booleans and `'true' | 'false' | '1' | '0'`. */
coerceBoolean(message?: string): Schema<boolean | string, boolean>;
literal<const V extends string | number | boolean | null>(value: V, message?: string): Schema<V, V>;
enum<const V extends readonly [string, ...string[]]>(values: V, message?: string): Schema<V[number], V[number]>;
array<Item extends StandardSchemaV1>(item: Item, message?: string): ArraySchema<Item>;
object<S extends ObjectShape>(shape: S, message?: string): ObjectSchema<S>;
/** First matching member wins. */
union<const M extends readonly [StandardSchemaV1, StandardSchemaV1, ...StandardSchemaV1[]]>(members: M): Schema<InferInput<M[number]>, Infer<M[number]>>;
record<V extends StandardSchemaV1>(value: V): Schema<Record<string, InferInput<V>>, Record<string, Infer<V>>>;
unknown(): Schema<unknown, unknown>;
}
Exported from packages/validator/src/contracts.ts
StringSchema
Interface
No documentation comment.
interface StringSchema<Output extends string = string> extends Schema<string, Output> {
min(length: number, message?: string): StringSchema<Output>;
max(length: number, message?: string): StringSchema<Output>;
length(length: number, message?: string): StringSchema<Output>;
/** Practical address check: one `@`, no spaces, a dot in the domain, ≤ 254 chars. */
email(message?: string): StringSchema<Output>;
/** Absolute `http:` or `https:` URL. */
url(message?: string): StringSchema<Output>;
uuid(message?: string): StringSchema<Output>;
/** Regex is allowed here (input validation), never in route patterns. */
…
Show the whole declaration (15 lines)
interface StringSchema<Output extends string = string> extends Schema<string, Output> {
min(length: number, message?: string): StringSchema<Output>;
max(length: number, message?: string): StringSchema<Output>;
length(length: number, message?: string): StringSchema<Output>;
/** Practical address check: one `@`, no spaces, a dot in the domain, ≤ 254 chars. */
email(message?: string): StringSchema<Output>;
/** Absolute `http:` or `https:` URL. */
url(message?: string): StringSchema<Output>;
uuid(message?: string): StringSchema<Output>;
/** Regex is allowed here (input validation), never in route patterns. */
…interface StringSchema<Output extends string = string> extends Schema<string, Output> {
min(length: number, message?: string): StringSchema<Output>;
max(length: number, message?: string): StringSchema<Output>;
length(length: number, message?: string): StringSchema<Output>;
/** Practical address check: one `@`, no spaces, a dot in the domain, ≤ 254 chars. */
email(message?: string): StringSchema<Output>;
/** Absolute `http:` or `https:` URL. */
url(message?: string): StringSchema<Output>;
uuid(message?: string): StringSchema<Output>;
/** Regex is allowed here (input validation), never in route patterns. */
regex(pattern: RegExp, message?: string): StringSchema<Output>;
/** Strips leading and trailing whitespace before checks. */
trim(): StringSchema<Output>;
toLowerCase(): StringSchema<Output>;
}
Exported from packages/validator/src/contracts.ts
ValidationIssueOut
Interface
No documentation comment.
interface ValidationIssueOut {
readonly message: string;
/** Property keys from the root. */
readonly path: readonly PropertyKey[];
}
Exported from packages/validator/src/contracts.ts
Type (6)
Infer
Type
No documentation comment.
type Infer<S extends StandardSchemaV1> = StandardSchemaV1.InferOutput<S>;
Exported from packages/validator/src/contracts.ts
InferInput
Type
No documentation comment.
type InferInput<S extends StandardSchemaV1> = StandardSchemaV1.InferInput<S>;
Exported from packages/validator/src/contracts.ts
ObjectInput
Type
No documentation comment.
type ObjectInput<S extends ObjectShape> = Simplify<{
[K in Exclude<keyof S, OptionalInputKeys<S>>]: InferInput<S[K]>;
} & {
[K in OptionalInputKeys<S>]?: InferInput<S[K]>;
}>;
Exported from packages/validator/src/contracts.ts
ObjectOutput
Type
No documentation comment.
type ObjectOutput<S extends ObjectShape> = Simplify<{
[K in Exclude<keyof S, OptionalOutputKeys<S>>]: Infer<S[K]>;
} & {
[K in OptionalOutputKeys<S>]?: Infer<S[K]>;
}>;
Exported from packages/validator/src/contracts.ts
ObjectShape
Type
No documentation comment.
type ObjectShape = Readonly<Record<string, StandardSchemaV1>>;
Exported from packages/validator/src/contracts.ts
UnknownKeys
Type
No documentation comment.
type UnknownKeys = 'strip' | 'strict' | 'passthrough';
Exported from packages/validator/src/contracts.ts