Frequently Asked Questions (FAQ)
Basic questions
Q: What is schema-dsl designed for?
A: schema-dsl is designed for validation rules that need to stay compact, serializable, and easy to share between configuration, APIs, front-end forms, and back-end services.
Main Differences:
- More concise DSL syntax
- Optional builder chains when a field needs metadata or custom constraints
- Database Schema export support
- Built-in common validators such as username, password, phone, and email
- Based on JSON Schema standard
Q: How to install schema-dsl?
Node.js version requirement: >=18.0.0
The current version uses Node.js >=18.0.0 as the runtime baseline and no longer promises compatibility with older Node versions.
Q: Are ES Modules supported?
A: Supported.
Q: What language pack file formats are supported by i18n directory loading?
A: Under Node.js >= 18.0.0, s.config({ i18n: '/path/to/locales' }) supports:
.js(CommonJS language pack).cjs.json.jsonc.json5
Recommendation: If your project is type: module / ESM, give priority to using .cjs, .json, .jsonc, .json5, as the compatibility is the most stable.
.js / .cjs locale files are executed as trusted Node code. If the locale directory can contain untrusted files, configure s.config({ i18n: '/path/to/locales', codeLocaleFiles: 'deny' }) to load only .json, .jsonc, and .json5.
DSL syntax issues
Q: 'string:3-32!' What does it mean?
A: This is the DSL syntax:
string- Type3-32- length range (minimum 3, maximum 32)!- required
More examples:
Q: How to define an array?
A: Use array type:
Q: How to define nested objects?
A: Just nest directly:
Q: How to use String extension?
A: String extension is an explicit compatibility/ergonomics path. New public examples use schema-dsl/pure + s by default, because it supports pure DSL strings, s('...'), and s.xxx() without installing methods on String.prototype.
If you intentionally want direct String chains, import the explicit String runtime/type entries described in String Extensions.
Validation issues
Q: How to verify data?
A: Use validate() function or Validator class:
Q: What is the format of the validation results?
A: The returned object contains:
Q: How to get all errors instead of just the first one?
A: All errors will be returned by default. If you only want to keep the first error, you can explicitly turn off allErrors:
new Validator({ allErrors: false }) also works when you want an early-exit validator. A Validator created with allErrors: false cannot recover errors that AJV did not collect, but the default validator and root helpers can use { allErrors: false } per call to keep only the first formatted error.
Q: How to use default values?
A: Use .default() method:
Performance issues
Q: What is the performance of schema-dsl?
A: The current benchmark should be read as project-local throughput evidence, not as a permanent marketing claim. The latest local run recorded:
Environment: Node.js v20.20.2, Windows x64, run time 2026-06-18T08:49:22.365Z.
Conclusion:
- ✅ Hot-path validation is already in the million-ops/sec range on this local machine.
- ✅ Built-in caching avoids repeated schema parsing on reused schema objects.
- ✅ Treat these numbers as a regression baseline; rerun the benchmark when runtime, dependency, or schema complexity changes.
Q: Why is the performance difference between valid/invalid data scenarios so big?
A: Invalid-data throughput depends heavily on how errors are collected and formatted. schema-dsl keeps the hot validation path separate from localized message rendering, so the raw invalid-data benchmark can stay close to the valid-data benchmark. Once you enable custom formatting, i18n, or large nested error payloads, measure with your real schema and error output.
Q: When will performance become a bottleneck?
A: The following scenarios may become a bottleneck:
- API Gateway (>500,000 verifications per second)
- High concurrency service (>500,000 requests per second)
- Real-time data processing (millisecond-level latency requirements)
Most applications (<100,000 verifications per second) will not encounter performance bottlenecks.
Q: What should I do if the validation speed is slow?
A: Use precompilation and caching:
Q: How does caching work?
A: schema-dsl currently implements compilation caching through CacheManager entrusting cache-hub’s MemoryCache:
Q: How to verify in batches?
A: Use SchemaUtils.validateBatch():
design concept
Q: Why choose run-time parsing instead of compile-time building?
A: This is an intentional design choice that prioritizes flexibility over extreme performance.
Advantages of runtime parsing:
- ✅ Fully Dynamic - Rules can be generated dynamically from configuration/database
- ✅ Multi-tenant support - different rules for each tenant, zero code modification
- ✅ Serializable - can be stored, transmitted and shared
- ✅ Front-end and back-end sharing - one set of rules, used by both ends
- ✅ Low Code Basics - Visual configuration form validation
Compile-time build limitations:
- ❌ Schema is fixed and cannot be dynamically adjusted
- ❌ Unable to serialize and transmit
- ❌ Difficulties with multi-tenancy
- ❌ Unable to read rules from database
Detailed description: Design concept document
Q: What scenarios is schema-dsl suitable for?
A: ✅ Most suitable scenario:
- Multi-tenant SaaS system - different validation rules for each tenant
- Backstage Management System - Administrator configures form validation
- Configuration Driven Development - Validation rules are stored in config/database
- Low-Code/No-Code Platform - Visual form builder
- Rapid Prototyping - Get started in 5 minutes with minimal code
- Front-end and back-end shared validation - a set of rules, used by both ends
⚠️ Unsuitable scene:
- Absolute throughput is the only goal and DSL dynamic capabilities are not required
- You need a schema API that models every value constraint as static TypeScript types
- Validation rules are fully static and never need to be serialized, stored, or edited as configuration
Q: Why not make schema-dsl purely compile-time?
A: Because the core value will be lost:
Loss of Abilities:
RESERVED ABILITIES:
Q: How to balance performance and flexibility?
A: schema-dsl design priorities:
Weigh the results:
- Gain: compact, serializable rules that can be stored, transmitted, edited, and shared across runtime boundaries
- Cost: TypeScript cannot refine every DSL constraint into exact static value types
Error handling
Q: How to customize error messages?
A: Use .messages() method:
Q: How to support multiple languages?
A: Use Locale class:
Q: What is the error path format?
A: Currently the slash path is returned:
Database export
Q: How to export to MongoDB Schema?
Q: How to export to MySQL DDL?
Q: How to export to PostgreSQL DDL?
Q: How to add comments when exporting?
A: Use .description():
MySQL will generate COMMENT and PostgreSQL will generate COMMENT ON COLUMN.
TypeScript support
Q: Does schema-dsl support TypeScript?
A: Supported. Public TypeScript examples prefer schema-dsl/pure + s: pure DSL strings for simple fields, s('...') for DSL seeds with builder hints, and s.xxx() factories for the strongest method discovery.
Q: How to write a more reliable chain prompt in TypeScript?
A: Start the chain call from s('...') when you want to keep DSL syntax and still get builder-method hints:
more questions
If you have further questions:
- View Full Document
- Check out the DSL Syntax Guide
- View API Reference
- Submit GitHub Issue
Related documents
Corresponding sample file
Example entry: faq.ts Instructions: Put the 4 most commonly copied scenarios in the FAQ into a runnable example: single validation, multi-language errors, batch validation, and cache statistics.