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

@jayoncode/form-intelligence-ajv

v2.2.1

Published

AJV JSON Schema adapter for @jayoncode/form-intelligence.

Readme

Form Intelligence — AJV

npm version Become a Sponsor

Bridge AJV JSON Schema validation into @jayoncode/form-intelligence.

The problem

Your contract is already JSON Schema (OpenAPI, shared schemas/, server-side AJV). The UI then reimplements the same constraints in TypeScript. Every minLength change becomes two edits — or users hit errors the API never would.

The solution

ajvAdapter(schema | validateFn) feeds JSON Schema (or a compiled AJV function) into Form Intelligence. Same contract on client and server; drafts, rules, and submit sit on top.

What you get

| Capability | Detail | | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Schema object | Pass a JSON Schema literal: ajvAdapter({ type: "object", ... }) | | Compiled validator | Pass ValidateFunction / async compile for reuse and $async keywords | | Path mapping | instancePath + required/additionalProperties params → field paths; form-level → _form | | allErrors-friendly | Works with AJV configured for multiple field errors | | Formats | Use ajv-formats on your Ajv instance for email, uri, etc. | | With core workflows | Combine with when() rules, autosave, wizard, plugins, validateOn | | AjvAdapterOptions | Optional { ajv? } — reuse a configured Ajv instance (allErrors, custom formats/keywords) when compiling a schema literal; ignored when you pass a pre-compiled ValidateFunction | | formatAjvErrorPath | Exported helper mapping a single AJV ErrorObject to a Form Intelligence field path — reuse it if you post-process validate.errors yourself |

Behavior notes

  • First error per path wins. When AJV reports multiple errors for the same field (e.g. with allErrors: true), only the first one encountered is kept.
  • Validate-only. ajvAdapter() returns a SchemaAdapter — it validates values and returns { path: message }. It does not infer a TypeScript type for createForm's values from your JSON Schema; type your initialValues (or the TValues generic) separately.

Install

npm install @jayoncode/form-intelligence @jayoncode/form-intelligence-ajv ajv

For format keywords, add ajv-formats.

Usage

import { createForm, when } from "@jayoncode/form-intelligence";
import { ajvAdapter } from "@jayoncode/form-intelligence-ajv";

const checkoutSchema = {
  type: "object",
  properties: {
    plan: { type: "string", enum: ["starter", "enterprise"] },
    email: { type: "string", minLength: 1 },
    seatCount: { type: "integer", minimum: 1 },
  },
  required: ["plan", "email"],
  additionalProperties: false,
} as const;

const form = createForm({
  initialValues: { plan: "starter", email: "", seatCount: 1 },
  schema: ajvAdapter(checkoutSchema),
  validateOn: "onBlur",
  rules: [when("plan").equals("enterprise").show("seatCount").require("seatCount")],
  workflow: {
    autosave: { enabled: true, debounceMs: 800, onSave: (v) => api.saveDraft(v) },
  },
  async onSubmit(values) {
    await api.checkout(values);
  },
});

Pre-compiled / async AJV

import Ajv from "ajv";

const ajv = new Ajv({ allErrors: true });
const validate = await ajv.compileAsync(schema);

createForm({
  schema: ajvAdapter(validate),
  onSubmit,
});

Reusing a configured Ajv instance — AjvAdapterOptions

Pass { ajv } when you want ajvAdapter() to compile the schema literal with an instance you already configured (e.g. with ajv-formats, custom keywords, or allErrors), instead of the adapter's internal default new Ajv({ allErrors: true }):

import Ajv from "ajv";
import addFormats from "ajv-formats";
import { ajvAdapter } from "@jayoncode/form-intelligence-ajv";

const ajv = addFormats(new Ajv({ allErrors: true }));

const form = createForm({
  schema: ajvAdapter(checkoutSchema, { ajv }),
  onSubmit,
});

options.ajv only applies when schemaOrValidate is a schema literal — it is ignored when you pass an already-compiled ValidateFunction.

formatAjvErrorPath

formatAjvErrorPath(error: ErrorObject): string is the same path-mapping logic ajvAdapter() uses internally, exported for reuse:

import { formatAjvErrorPath } from "@jayoncode/form-intelligence-ajv";

const path = formatAjvErrorPath(validate.errors![0]);

It maps instancePath to a dot path (/address/cityaddress.city), and for required / additionalProperties errors appends the offending property name from error.params (since AJV reports those on the parent path). Root-level or unmapped errors fall back to "_form".

Docs

https://itsjayoncode.github.io/joc/packages/form-intelligence/modules/adapters

License

MIT © JayOnCode