Registry / testing / schema-vir

schema-vir

JSON →
library0.7.1jsnpmunverified

Utilities for handling JSON Schemas and mapping them to object-shape-tester Shape instances. Current stable version: 0.7.1. Release cadence: irregular, actively maintained. Key differentiators: provides conversion from JSON Schema to Shape objects for type validation and default value generation, defines versioned schema suites with automatic version detection and matching, minimal dependencies, ESM-only, requires Node >=22.

npm install schema-vir
INSTALL
IMPORT
SIG · SCHEMA-VIR
S
schema-vir
testingjavascriptv0.7.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.

mapSchemaToShape
import { mapSchemaToShape } from 'schema-vir'
const mapSchemaToShape = require('schema-vir');
ESM-only package; CommonJS require will fail.
defineVersionedSchema
import { defineVersionedSchema } from 'schema-vir'
import defineVersionedSchema from 'schema-vir';
Named export, not default export.
defineVersionedSchemaSuite
import { defineVersionedSchemaSuite } from 'schema-vir'
import { defineVersionedSchemaSuite as suite } from 'schema-vir';
No known wrong pattern, but ensure named import syntax.
$SchemaShape
import type { $SchemaShape } from 'schema-vir'
TypeScript type export; use import type for type-only usage.

Shows mapping JSON Schema to Shape and defining versioned schemas with automatic version matching.

import { mapSchemaToShape, defineVersionedSchema, defineVersionedSchemaSuite } from 'schema-vir'; // Map a simple JSON Schema to a Shape const myShape = mapSchemaToShape({ type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' }, }, required: ['name'], }); // Define versioned schemas const v1 = defineVersionedSchema(['version'], { type: 'object', required: ['version', 'data'], properties: { version: { const: 'v1', type: 'string' }, data: { type: 'string' }, }, }); const v2 = defineVersionedSchema(['version'], { type: 'object', required: ['version', 'data'], properties: { version: { const: 'v2', type: 'string' }, data: { type: 'number' }, }, }); // Create a versioned schema suite const schemas = defineVersionedSchemaSuite({ v1, v2 }); // Access versions map const v2Schema = schemas.versions['v2']; // Type-safe version enum const version: typeof schemas.Version = 'v1'; // Find matching version for an object const result = schemas.assertWrapMatch({ version: 'v2', data: 42, }); console.log(result.version); // 'v2'
Debug
Known issues
gotchaESM-only package: requires Node >=22 and 'type': 'module' in package.json.
fix
Ensure your project is ESM (set 'type': 'module' in package.json) or use dynamic import().
affects: >=0.0.0
breakingmapSchemaToShape may throw on invalid or unsupported JSON Schema features (e.g., allOf, if/then/else).
fix
Validate schemas before passing or handle errors with try/catch.
affects: all
deprecatedNo known deprecated APIs in current version; always check changelog.
fix
Refer to GitHub releases for deprecation notices.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing peer dependency 'object-shape-tester' not installed.
fix
Run 'npm install object-shape-tester'.
ERR_REQUIRE_ESM: require() of ES Module not supported
Trying to import schema-vir with CommonJS require().
fix
Use import statement instead of require() or set 'type': 'module' in package.json.
Module not found: Error: Can't resolve 'schema-vir'
Package not installed or not in node_modules.
fix
Run 'npm install schema-vir'.
Upgrade
Version history
0.7.1latest on npm
Audit
Dependencies
object-shape-testeroptionalpeer dependency for Shape instances returned by mapSchemaToShape and used in schema suites
Agent activity
6 hits · last 30 days
node
6
Resources
schema-vir — npm install schema-vir · libregistry