schema-dsl chain method list

Updated: 2026-06-18

Use this page when a field needs more than a plain DSL string. The recommended v2.1.0 path is:

import { s } from 'schema-dsl/pure';

const schema = s({
  email: 'email!',
  username: s('string:3-32!').label('Username'),
  age: s.number().min(18).max(120).require()
});

Entry support

EntryExampleTypeScript hintsRuntime side effect
Plain DSL stringemail: 'email!'DSL literal value inference onlynone
s('...') seeds('email!').label('Email')full IDslBuilder methodsnone
s.xxx() factorys.email().label('Email')full IDslBuilder methods plus discoverable factory namesnone
runtime.sruntime.s.email().require()runtime-scoped builder methodsisolated runtime instance
Direct String chain'email!'.label('Email')requires schema-dsl/string-types opt-inrequires schema-dsl/register-string, compat/root, or compile-time transform

Direct String chaining is still supported, but it is no longer the default documentation entry. Use it intentionally, or use the transform path when you want direct-string source without runtime prototype mutation.

Common methods

MethodApplies toResult
.label(text)all buildersSets the field label used by error messages.
.description(text)all buildersAdds JSON Schema description.
.messages(map) / .error(map)all buildersAdds custom validation messages.
.default(value)all buildersAdds JSON Schema default.
.optional()all buildersMarks the field optional.
.require() / .required()all buildersMarks the field required. .require() does not accept arguments on field builders.
.enum(...values)compatible primitive buildersRestricts allowed values.
.format(name)string-like buildersSets JSON Schema format.
.pattern(regex, message?)string buildersAdds a safe regex pattern.
.custom(fn)all buildersAdds a synchronous or async custom validator.

String methods

MethodResult
.min(n) / .max(n)Sets minLength / maxLength on strings.
.length(n)Exact string length. Builder only; direct String chains cannot use it because native strings already have .length.
.alphanum()Allows only letters and digits.
.trim()Rejects leading/trailing whitespace. Builder only; direct String chains cannot use it because native strings already have .trim().
.lowercase() / .uppercase()Requires lowercase or uppercase input.
.json()Requires a valid JSON string.
.dateFormat(fmt)Validates a string date format.
.after(date) / .dateGreater(date)Requires a date string after the given value.
.before(date) / .dateLess(date)Requires a date string before the given value.
.slug()URL slug pattern.
.domain()Domain pattern.
.ip()IP address pattern.
.base64()Base64 string pattern.
.jwt()JWT pattern.
.username(preset)Username preset or options.
.password(strength)Password strength preset: weak, medium, strong, veryStrong.
.phone(country) / .phoneNumber(country)Phone number pattern.
.idCard(country)National ID pattern.
.creditCard(type)Credit card pattern.
.licensePlate(country)License plate pattern.
.postalCode(country)Postal code pattern.
.passport(country)Passport pattern.

Number methods

MethodResult
.min(n) / .max(n)Sets numeric minimum / maximum.
.precision(n)Limits decimal precision.
.multiple(n)Sets JSON Schema multipleOf.
.port()Validates an integer port range.

Array methods

MethodResult
.min(n) / .max(n)Sets minItems / maxItems.
.items(item)Sets item schema from a DSL string, builder or JSON Schema.
.noSparse()Rejects sparse arrays.
.includesRequired(items)Requires the array to contain specified values.

Object methods

MethodResult
.requireAll()Marks all defined object properties as required.
.strict()Rejects additional properties.

Output methods

MethodResult
.toSchema()Returns schema-dsl internal schema, including metadata used by the validator.
.toJsonSchema()Returns clean JSON Schema suitable for export and OpenAPI embedding.
.toString()Serializes .toJsonSchema(). Builder only.
.validate(data)Validates with a builder-owned validator. Builder only.

Custom methods

This page lists built-in field builder methods. For user-defined methods, first decide which layer you need:


Corresponding example file

Example entry: chain-methods.ts Description: Exercises common, string, number, array, object, output and runtime-scoped chain methods.