API Reference
Builder Functions
| Function | Description | Key Methods |
|---|---|---|
any() | Accepts any value | .optional(), .default(value), .catch(value), .addValidator(fn) |
string() | String schema builder | .minLength(n), .maxLength(n), .matches(re), .email(), .url(), .uuid(), .ip(), .trim(), .toLowerCase(), .nonempty(), .default(value), .catch(value) |
number() | Number schema builder | .min(n), .max(n), .isInteger(), .positive(), .negative(), .finite(), .multipleOf(n), .default(value), .catch(value) |
boolean() | Boolean schema builder | .optional(), .default(value), .catch(value) |
date() | Date schema builder | .optional(), .default(value), .catch(value) |
func() | Function schema builder | .optional(), .default(value), .catch(value) |
object({...}) | Object schema with named properties | .validate(data), .validateAsync(data), .addProps({...}), .default(value), .catch(value) |
array(schema) | Array of items schema | .minLength(n), .maxLength(n), .of(schema), .nonempty(), .unique(), .default(value), .catch(value) |
union(...schemas) | Union of schemas | .validate(data), .validateAsync(data), .default(value), .catch(value) |
lazy(getter) | Recursive / self-referential schema builder | .resolve(), .optional(), .addValidator(fn), .default(value), .catch(value) |
extern(standardSchema) | Wraps an external Standard Schema v1 schema (Zod, Valibot, ArkType, …) into a native builder | .validate(data), .optional(), .nullable(), .default(value), .catch(value) |
Extension Functions
| Function | Description |
|---|---|
defineExtension(config) | Defines an extension targeting one or more builder types. Returns a branded ExtensionDescriptor. |
withExtensions(...exts) | Creates augmented builder factories with extension methods applied. Accepts one or more ExtensionDescriptors. |
Utility Types
| Type | Description |
|---|---|
InferType<T> | Extracts the TypeScript type from a schema definition. type User = InferType<typeof UserSchema> |
ValidationResult | Result of .validate(). Contains valid, errors, and object. For object schemas, also includes getErrorsFor() (errors is deprecated on object schema results). |
ValidationError | Individual error: { message: string } |
PropertyDescriptor | Runtime metadata for a schema property (type, constraints, getters/setters). |
PropertyDescriptorTree | Tree of PropertyDescriptors for an object schema. Used as selectors in mapper and form libraries. |
MakeOptional | Utility type that makes a type optional (used internally by InferType). |
Exports
// Builder functions
export { any, lazy, array, boolean, date, func, number, object, string, union }
// Builder classes
export {
SchemaBuilder, AnySchemaBuilder, ArraySchemaBuilder,
BooleanSchemaBuilder, DateSchemaBuilder, FunctionSchemaBuilder,
LazySchemaBuilder, NumberSchemaBuilder, ObjectSchemaBuilder,
StringSchemaBuilder, UnionSchemaBuilder
}
// Extension system
export { defineExtension, withExtensions }
export { stringExtensions, numberExtensions, arrayExtensions } // built-in extension descriptors
export type { ExtensionConfig, ExtensionDescriptor }
// Sub-path export: bare builders without built-in extensions
// import { string } from '@cleverbrush/schema/core'
// Types
export type {
InferType, MakeOptional, ValidationError, ValidationResult,
PropertyDescriptor, PropertyDescriptorInner, PropertyDescriptorTree,
PropertySetterOptions, SchemaPropertySelector
}
// Standard Schema
// Re-exported from @standard-schema/spec — use for typing custom integrations
export type { StandardSchemaV1 } from '@standard-schema/spec'