npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@maxjay/patchwork-ajv

v0.3.0

Published

AJV JSON Schema validation for patchwork Engine/NodeEngine drafts.

Readme


Install

npm install @maxjay/patchwork-ajv

Requires @maxjay/patchwork as a peer dependency if you're passing Engine or NodeEngine instances.

Usage

Validate an Engine's draft

import { Engine } from '@maxjay/patchwork';
import { validate } from '@maxjay/patchwork-ajv';

const schema = {
  type: 'object',
  properties: {
    host: { type: 'string' },
    port: { type: 'number' },
  },
  required: ['host', 'port'],
};

const engine = new Engine({ host: 'localhost', port: 8080 });
engine.replace('$.port', 'oops'); // type mismatch

const errors = validate(engine, schema);
// [{ instancePath: '/port', keyword: 'type', message: 'must be number', ... }]

validate reads engine.draft and runs it through AJV. It returns an empty array when the draft is valid.

Validate a NodeEngine (scoped lens)

const nodeEngine = engine.getNodeEngine('$.server');
const errors = validate(nodeEngine, serverSchema);

nodeEngine.draft is the subtree — validation is scoped to it.

Validate a plain value

You don't need an Engine at all. Pass any value directly:

const errors = validate({ host: 'localhost', port: 8080 }, schema);

validate detects the presence of a .draft property to decide whether to unwrap.

Patchwork schema extensions

Patchwork schemas can include x-key and x-ordered on array nodes for identity-based diffing:

const schema = {
  type: 'object',
  properties: {
    users: {
      type: 'array',
      'x-key': 'id',        // patchwork extension — identity field for diffing
      'x-ordered': true,    // patchwork extension — position changes emit as move ops
      items: {
        type: 'object',
        properties: {
          id: { type: 'string' },
          name: { type: 'string' },
        },
        required: ['id'],
      },
    },
  },
};

// Works fine — x-key and x-ordered are registered as no-ops in AJV
const errors = validate(engine, schema);

You can pass the same schema object to both new Engine(base, { schema }) and validate() — no stripping or copying needed.

API

validate(target, schema): ErrorObject[]

| Parameter | Type | Description | |---|---|---| | target | Engine \| NodeEngine \| { draft: unknown } \| unknown | If the value has a .draft property, that property is validated. Otherwise the value itself is validated. | | schema | object | Any valid JSON Schema object. Patchwork's x-key and x-ordered extensions are ignored by AJV. |

Returns AJV's ErrorObject[]. Empty array means valid.

ErrorObject

Re-exported from AJV for convenience:

import { type ErrorObject } from '@maxjay/patchwork-ajv';

Key fields:

| Field | Description | |---|---| | instancePath | JSON Pointer to the failing value (e.g. /users/0/id) | | keyword | The failing keyword (required, type, minimum, …) | | message | Human-readable error string | | params | Keyword-specific details (e.g. { missingProperty: 'id' }) |