Registry / testing / middy-standard-schema

middy-standard-schema

JSON →
library1.0.0jsnpmunverified

Middy middleware that validates events, contexts, or responses using any Standard Schema-compatible validation library (Zod, Arktype, Valibot, Joi, Yup, etc.). Version 1.0.0 is stable, with active development. It intelligently merges validated types into the event TypeScript type and provides opt-in detailed error exposure. Supports all modern Middy core versions (4-7) and dual CJS/ESM module output. Differentiators: library-agnostic via Standard Schema spec, optional event transformation, and flexible error handling.

npm install middy-standard-schema
INSTALL
IMPORT
SIG · MIDDY-STANDARD-SCH
M
middy-standard-schema
testingjavascriptv1.0.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.

standardSchemaValidator
import { standardSchemaValidator } from 'middy-standard-schema'
const standardSchemaValidator = require('middy-standard-schema')
ESM-only package; requires @middy/core as peer dependency. Use named import.
StandardSchemaValidatorOptions
import type { StandardSchemaValidatorOptions } from 'middy-standard-schema'
import { StandardSchemaValidatorOptions } from 'middy-standard-schema'
This is a TypeScript type; use 'import type' to avoid runtime errors.
standardSchemaValidator (default export)
import validator from 'middy-standard-schema'
const validator = require('middy-standard-schema')
Default export is the same function as named export. Prefer named import for consistency.

Validates event body using Zod schema with middy-standard-schema, using @middy/core and error handler.

import middy from '@middy/core'; import httpErrorHandler from '@middy/http-error-handler'; import { standardSchemaValidator } from 'middy-standard-schema'; import z from 'zod'; const eventSchema = z.object({ body: z.object({ HelloWorld: z.string() }) }); const baseHandler = async (event: any) => { return { statusCode: 200, body: JSON.stringify({ message: event.body.HelloWorld }) }; }; export const handler = middy(baseHandler) .use(httpErrorHandler()) .use(standardSchemaValidator({ eventSchema }));
Debug
Known issues
gotchaValidation transforms the event by default; parsed/replaced object may lose prototype methods.
fix
Set { transform: false } in options to disable event transformation.
affects: >=1.0.0
gotchaUsing CommonJS require() will fail; this package is ESM-only (no CJS export).
fix
Use dynamic import or switch to ESM: import { standardSchemaValidator } from 'middy-standard-schema'.
affects: >=1.0.0
breakingPeer dependency @middy/core must be v4, v5, v6, or v7; incompatible with v3 or earlier.
fix
Update @middy/core to version ^4.0.0 or later.
affects: >=1.0.0
deprecatedOption exposeErrors: true may expose internal schema failure details in production responses.
fix
Use custom error handler instead of exposing errors to end users in production.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'middy-standard-schema' or its corresponding type declarations.
Package not installed or tsconfig missing moduleResolution 'node16'/'nodenext' for ESM.
fix
npm install middy-standard-schema @middy/core && set moduleResolution to 'node16' in tsconfig.json.
ERR_REQUIRE_ESM: require() of ES Module /path/middy-standard-schema/index.mjs not supported.
Using require() instead of import; package is ESM-only.
fix
Change to dynamic import() or switch to ESM: use 'type': 'module' in package.json.
TypeError: middy(...).use is not a function
Missing or incompatible @middy/core version.
fix
Install @middy/core >=4.0.0 and ensure it is imported correctly: import middy from '@middy/core'.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@middy/corerequiredPeer dependency; required middleware framework
Agent activity
7 hits · last 30 days
node
6
Bingbot
1
Resources
middy-standard-schema — npm install middy-standard-schema · libregistry