Registry / testing / mali-ajv

mali-ajv

JSON →
library0.4.0jsnpmunverified

Opinionated input validation for Mali.js gRPC microservices using Ajv (version 0.4.0). Integrates Ajv JSON schema validation into Mali middleware, automatically validating request payloads against provided schemas. Updated infrequently; depends on @grpc/grpc-js ^1.3.6 and ajv ^8.6.2. Key differentiators: no manual validation calls, schema-first approach, standard gRPC error codes on failure.

npm install mali-ajv
INSTALL
IMPORT
SIG · MALI-AJV
M
mali-ajv
testingjavascriptv0.4.0
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.

addSchemas
import { addSchemas } from 'mali-ajv'
const { addSchemas } = require('mali-ajv')
Module may be ESM-only; check your project's module system.
default
import maliAjv from 'mali-ajv'
const maliAjv = require('mali-ajv')
No default export in 0.4.0, only named exports.
Mali
import Mali from 'mali'
const Mali = require('mali')
Mali.js itself must be imported separately.

Import and apply Ajv validation schemas to Mali gRPC services.

import Mali from 'mali' import { addSchemas } from 'mali-ajv' const schemas = { MyService: { myMethod: { type: 'object', properties: { id: { type: 'string', format: 'uuid' }, name: { type: 'string', minLength: 1 } }, required: ['id'] } } } const app = new Mali() app.use(addSchemas(app, schemas)) // app.addService(...) app.use('MyService', { myMethod: (ctx) => { ctx.res = { status: 'ok' } } })
Debug
Known issues
gotchaMust call addSchemas before any service handlers are defined; validation middleware order matters.
fix
Register addSchemas(app, schemas) as the first middleware before addService or use handlers.
affects: >=0.0
gotchaSchemas must be provided as an object with keys matching service names; nested methods require a specific structure.
fix
Format: { ServiceName: { methodName: { type: 'object', ... } } }
affects: >=0.0
gotchaValidation error responses use gRPC status code 9 (FAILED_PRECONDITION); ensure clients expect this code.
fix
No fix needed, but document client-side handling of FAILED_PRECONDITION.
affects: >=0.0
deprecatedThis package may not be actively maintained; check for fork or alternatives.
fix
Consider using mali-onerror or custom validation middleware.
affects: >=0.4.0
Errors
Common errors & fixes
Cannot find module 'mali-ajv'
Package not installed or path incorrect.
fix
npm install mali-ajv
addSchemas is not a function
Default import used instead of named import.
fix
Use import { addSchemas } from 'mali-ajv'
TypeError: Cannot read properties of undefined (reading 'prototype')
Mali app not passed correctly as first argument to addSchemas.
fix
Ensure addSchemas is called with the Mali instance: addSchemas(app, schemas)
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
@grpc/grpc-jsoptionalPeer dependency for gRPC runtime
ajvoptionalPeer dependency for JSON schema validation library
Agent activity
4 hits · last 30 days
node
4
Resources
mali-ajv — npm install mali-ajv · libregistry