Definition Generator Framework
raw JSON → 2.1.2 verified Fri May 01 auth: no javascript
A framework for generating definitions with custom validators, version 2.1.2. It integrates with Joi to provide custom validation decorators for file system operations. The framework is part of a monorepo and depends on helpers-lib, script-engine-lib, and Joi. Release cadence is not specified. Key differentiators include built-in custom validators and seamless integration with the definition generation ecosystem.
Common errors
error Cannot read properties of undefined (reading 'decorate') ↓
cause JoiCustomValidators is undefined because import failed or wrong import syntax.
fix
Use correct import: import { JoiCustomValidators } from 'definition-generator-framework';
error JoiCustomValidators.decorate is not a function ↓
cause The decorator method was removed in v2.0.0, but the API changed.
fix
Upgrade to v2.1.0+ and use setupValidators instead, or downgrade to v1.x.
error TypeError: Cannot read property 'existsSync' of undefined ↓
cause The 'fs' object passed to decorate does not have existsSync.
fix
Ensure you import 'fs' correctly: import * as fs from 'fs'; then pass fs object.
Warnings
breaking Version 2.0.0 changed the default export from object to class. Use named imports for specific modules. ↓
fix Use named imports like { JoiCustomValidators } instead of default import.
deprecated The 'validateConfig' method is deprecated since v2.1.0. Use 'setupValidators' instead. ↓
fix Replace validateConfig() calls with setupValidators().
gotcha JoiCustomValidators.decorate() must be called before any Joi validation that uses the custom validators. ↓
fix Ensure decorate() is called at application startup, before Joi schemas are compiled.
gotcha In Node.js, passing 'fs' directly to decorate works, but in browser environments you must provide a compatible mock. ↓
fix Provide a 'fs' mock object with required methods (existsSync, readFileSync, etc.).
Install
npm install definition-generator-framework yarn add definition-generator-framework pnpm add definition-generator-framework Imports
- JoiCustomValidators wrong
const JoiCustomValidators = require('definition-generator-framework').JoiCustomValidatorscorrectimport { JoiCustomValidators } from 'definition-generator-framework' - default wrong
const definitionGeneratorFramework = require('definition-generator-framework')correctimport definitionGeneratorFramework from 'definition-generator-framework' - SchemaGenerator wrong
import SchemaGenerator from 'definition-generator-framework'correctimport { SchemaGenerator } from 'definition-generator-framework'
Quickstart
import * as fs from 'fs';
import { JoiCustomValidators } from 'definition-generator-framework';
// Decorate Joi with custom validators
JoiCustomValidators.decorate(fs);
// Now use Joi with custom validators, e.g., Joi.string().custom(fs.existsSync)
const Joi = require('joi');
const schema = Joi.string().custom((value, helpers) => {
if (!fs.existsSync(value)) {
return helpers.error('any.invalid');
}
return value;
});
await schema.validateAsync('/path/to/file.txt');
console.log('Validation passed');