Registry / testing / zenstack-validator

zenstack-validator

JSON →
library1.0.1jsnpmunverified

ZenStack plugin and decorator package that auto-generates DTOs with class-validator and class-transformer decorators from ZModel schemas. Version 1.0.1, active development. Key differentiator: seamless integration with ZenStack and NestJS ecosystems, filling gaps in class-validator with custom decorators like @Gt, @Lt, @Trim, and @LowerCase. Provides both a generator plugin for build-time and runtime decorators.

npm install zenstack-validator
INSTALL
IMPORT
SIG · ZENSTACK-VALIDATOR
Z
zenstack-validator
testingjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Gt
import { Gt } from 'zenstack-validator'
const Gt = require('zenstack-validator').Gt
Package is ESM-only; CJS require may break. Use named import.
default (plugin)
provider = 'zenstack-validator/plugin' in schema.zmodel
provider = 'zenstack-validator' (missing /plugin)
The generator plugin is exported from the subpath 'zenstack-validator/plugin'. Forgetting /plugin will not register the plugin.
generated DTOs
import { UserDTO } from './src/dto/dtos'
import UserDTO from './src/dto/dtos'
Generated DTOs are named exports, not default exports. Always use named import.

Generate DTOs from ZModel schema using the zenstack-validator plugin, then use them in a NestJS controller for validation.

// schema.zmodel model User { id String @id @default(cuid()) email String @email name String? @trim @lower age Int @gt(0, "Must be positive") @lte(120) createdAt DateTime @default(now()) } plugin validator { provider = 'zenstack-validator/plugin' output = './src/dto' } // Terminal: npx zenstack generate // Use in NestJS controller import { UserDTO } from './src/dto/dtos'; @Post() async createUser(@Body() body: UserDTO) { console.log(body.email); // Fully typed and validated! }
Debug
Known issues
gotchaThe generator plugin must be referenced as 'zenstack-validator/plugin', not 'zenstack-validator'.
fix
Use provider = 'zenstack-validator/plugin' in schema.zmodel.
affects: >=1.0.0
gotchaGenerated DTOs are named exports; importing without braces will fail at runtime.
fix
Use import { UserDTO } from './dto/dtos'; not import UserDTO from './dto/dtos';.
affects: >=1.0.0
gotchaThe package is ESM-only. Using require() may fail in Node.js without proper ESM configuration.
fix
Use import statements and ensure your project is ESM or use dynamic import().
affects: >=1.0.0
deprecatedThe @Trim, @LowerCase, and @UpperCase decorators are actually provided by class-transformer, but are re-exported here. They may be deprecated in favor of direct usage.
fix
Consider importing @Transform(({ value }) => value.trim()) directly from class-transformer instead.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'zenstack-validator' or its corresponding type declarations.
Package not installed or missing TypeScript declaration files.
fix
Run npm install zenstack-validator and ensure tsconfig.json includes node_modules types.
Plugin 'zenstack-validator' not found. Did you mean 'zenstack-validator/plugin'?
Provider string in schema.zmodel is missing the '/plugin' suffix.
fix
Change provider to 'zenstack-validator/plugin'.
Export 'UserDTO' was not found in './dto/dtos'.
Importing generated DTO as default instead of named export.
fix
Use import { UserDTO } from './dto/dtos'; instead of import UserDTO from './dto/dtos';.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
@nestjs/mapped-typesoptionalUsed for generating mapped types in NestJS
@zenstackhq/sdkrequiredRequired for the generator plugin
class-transformerrequiredRequired for transformation decorators like @Trim, @Type
class-validatorrequiredCore validation library for generated DTOs
Agent activity
32 hits · last 30 days
node
28
Resources
zenstack-validator — npm install zenstack-validator · libregistry