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

synesia-data-schema

v0.0.9

Published

Synesia data schema utilities: types, validation, and JSON Schema conversion

Readme

synesia-data-schema

Synesia data schema toolkit: define your data once, validate it, generate defaults, and convert to/from JSON Schema.

Why synesia-data-schema?

  • Single source of truth: strong types for your schema, shared across apps.
  • Built-in validation: validateData with precise messages and error paths.
  • Smart defaults: generateDefaultData using enum, formats, min/max, etc.
  • JSON Schema interop: bidirectional conversion toJSONSchema / fromJSONSchema.
  • TypeScript native: autocomplete and type safety.

DataSchema is a simplified, opinionated adaptation of JSON Schema tailored to Synesia’s needs. It keeps the essentials (types, enum, formats, min/max/step, objects/arrays) for clear, robust application use, while remaining convertible to/from JSON Schema when needed.

Installation

pnpm add synesia-data-schema

Quick Start

import { validateData, generateDefaultData } from "synesia-data-schema";
import { DataSchema } from "synesia-data-schema";

const userSchema: DataSchema = {
  id: "user",
  name: "User",
  type: "object",
  required: true,
  schema: [
    {
      id: "email",
      name: "email",
      type: "text",
      required: true,
      format: "email",
    },
    { id: "age", name: "age", type: "number", required: false, min: 0 },
    {
      id: "roles",
      name: "roles",
      type: "array",
      required: false,
      childSchema: { id: "role", name: "role", type: "text", required: true },
    },
  ],
};

const defaults = generateDefaultData(userSchema, true);

const result = validateData({ email: "bad", age: -1 }, userSchema);

JSON Schema conversion

import { toJSONSchema, fromJSONSchema } from "synesia-data-schema";

const jsonSchema = toJSONSchema({
  type: "object",
  properties: {
    title: { type: "string", format: "email" },
    count: { type: "number", minimum: 0 },
  },
  required: ["title"],
});
const backToJsonSchema = fromJSONSchema({
  id: "root",
  name: "root",
  type: "object",
  schema: [
    {
      id: "title",
      name: "title",
      type: "text",
      required: true,
      format: "email",
    },
    { id: "count", name: "count", type: "number", required: false, min: 0 },
  ],
});

API

  • generateDefaultData(schema, includeOptional?) => unknown
    • Generates default values based on defaultValue, enum, format, min/max/step.
  • validateData(data, schema, strict?) => { isValid: boolean; errors: { message: string; path: string[] }[] }
    • Recursively validates input and returns precise error paths.
    • When strict=true, every field must be present even if required=false.
  • toJSONSchema(json, name?) => DataSchema
    • Converts a JSON Schema into a strongly typed DataSchema.
  • fromJSONSchema(schema, strict?) => any
    • Converts a DataSchema to JSON Schema. strict forces all object keys to be required.

Supported formats

email, uuid, date, time, datetime (mapped to date-time in JSON Schema). Patterns are backed by TEXT_VALIDATION_REGEX and covered by tests.

Types

Exposed types: DataSchema, TextDataSchema, NumberDataSchema, BooleanDataSchema, ArrayDataSchema, ObjectDataSchema, EmptyDataSchema, and InputEnum<T>.

Tests & Quality

pnpm run test
pnpm run test:coverage

High coverage (~95%) with unit tests covering validation, default generation, and conversions.

Contributing

  • Fork, create a feature branch, open a PR with a clear description
  • Keep strict TypeScript style and high coverage

License

MIT