Indicative Compiler
raw JSON → 7.2.4 verified Fri May 01 auth: no javascript
Indicative Compiler is a low-level module used by Indicative, a validation library for Node.js, that compiles parsed schema into highly optimized executable functions. Current stable version is 7.2.4. It is part of the AdonisJS ecosystem and focuses on performance by generating optimized JavaScript functions from validation schemas during compilation. It uses a custom compiler pattern (ValidatorCompiler/ValidatorExecutor) and supports custom formatters and error collectors. Distinct from other validators like Joi or Yup by emphasizing ahead-of-time compilation for repeated validation runs. Typically paired with 'indicative-rules' and 'indicative-formatters'. Release cadence is irregular with major version bumps.
Common errors
error TypeError: ValidatorCompiler is not a constructor ↓
cause Using wrong import style (CommonJS default import instead of named import)
fix
Use import { ValidatorCompiler } from 'indicative-compiler'
error Cannot find module 'indicative-compiler' ↓
cause Package not installed or wrong path
fix
Run npm install indicative-compiler
error ValidationDefination is not exported from indicative-compiler ↓
cause Typo in type name; the correct export is 'ValidationDefinition'
fix
Replace 'ValidationDefination' with 'ValidationDefinition'
Warnings
breaking v7.0.0 introduced breaking changes: the compiler output structure changed, and the 'compile' method now returns an array instead of a single function. ↓
fix Update code to use ValidatorExecutor with compiled functions array.
deprecated The 'ValidationDefination' type (with typo) is deprecated in favor of 'ValidationDefinition' since v7.2.1. ↓
fix Use 'ValidationDefinition' instead.
gotcha The package is low-level; you should typically use the 'indicative' package directly, not this one. ↓
fix Use 'indicative' as the main validation entry point.
gotcha Formatters must be constructors, not instances. Passing an instance will cause runtime errors. ↓
fix Pass the class reference (e.g., VanillaFormatter), not new VanillaFormatter().
Install
npm install indicative-compiler yarn add indicative-compiler pnpm add indicative-compiler Imports
- ValidatorCompiler wrong
const { ValidatorCompiler } = require('indicative-compiler')correctimport { ValidatorCompiler } from 'indicative-compiler' - ValidatorExecutor wrong
const ValidatorExecutor = require('indicative-compiler').ValidatorExecutorcorrectimport { ValidatorExecutor } from 'indicative-compiler' - ValidationDefinition
import { ValidationDefinition } from 'indicative-compiler'
Quickstart
import { ValidatorCompiler, ValidatorExecutor } from 'indicative-compiler'
import { VanillaFormatter } from 'indicative-formatters'
import * as validations from 'indicative-rules'
const schema = {
username: 'required',
email: 'required|email'
}
const messages = {}
// Compile once
const compiledFunctions = new ValidatorCompiler(schema, messages).compile()
// Execute with data
const data = { username: 'john', email: 'john@example.com' }
const result = await new ValidatorExecutor(compiledFunctions).exec(data, VanillaFormatter, {}, false, false)
console.log(result)