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'
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing peer dependency 'object-shape-tester' not installed.
fixRun 'npm install object-shape-tester'.
ERR_REQUIRE_ESM: require() of ES Module not supported
Trying to import schema-vir with CommonJS require().
fixUse 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.
fixRun 'npm install schema-vir'.
Audit
Dependencies
object-shape-testeroptionalpeer dependency for Shape instances returned by mapSchemaToShape and used in schema suites