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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@janus-validator/avro

v0.6.0

Published

Avro schema import/export for Janus Validator

Downloads

690

Readme

@janus-validator/avro

Avro schema import/export for Janus Validator.

Installation

npm install @janus-validator/avro @janus-validator/core

Usage

🚧 Status: Avro conversion is scaffolded but not yet implemented. The exported functions currently throw Error('Not yet implemented').

Why this package exists

Avro schemas describe shape but don’t standardize validation constraints (lengths, numeric bounds, regex patterns, etc). This package is intended to bridge that gap by encoding validation constraints as x-janus-* extension fields, so the same schema can be:

  • Validated forwards (Avro → Janus validator → validate)
  • Generated backwards (Janus validator → Generator → fixtures)

Import: Avro → Validator

Convert an Avro schema to a Janus validator:

import { avroToValidator } from '@janus-validator/avro';

const avroSchema = {
  type: 'record',
  name: 'User',
  fields: [
    {
      name: 'name',
      type: 'string',
      'x-janus-minLength': 1,
      'x-janus-maxLength': 100
    },
    {
      name: 'age',
      type: 'int',
      'x-janus-min': 0,
      'x-janus-max': 150
    },
    {
      name: 'email',
      type: 'string',
      'x-janus-pattern': '^[\\w.]+@[\\w.]+\\.\\w+$'
    }
  ]
};

const validator = avroToValidator(avroSchema);

// NOTE: Currently throws "Not yet implemented"

// And generate test data
import { Generator } from '@janus-validator/core';
const generator = new Generator({ random: Math.random });
const testUser = generator.generate(validator);

Export: Validator → Avro

Convert a Janus validator to an Avro schema:

import { validatorToAvro } from '@janus-validator/avro';
import { O, U, I, R } from '@janus-validator/dsl';

const userValidator = O({
  name: U(1, 100),
  age: I(0, 150),
  email: R(/^[\w.]+@[\w.]+\.\w+$/),
});

const schema = validatorToAvro(userValidator, {
  name: 'User',
  namespace: 'com.example',
  includeExtensions: true
});

console.log(JSON.stringify(schema, null, 2));
// {
//   "type": "record",
//   "name": "User",
//   "namespace": "com.example",
//   "fields": [
//     { "name": "name", "type": "string", "x-janus-minLength": 1, "x-janus-maxLength": 100 },
//     { "name": "age", "type": "int", "x-janus-min": 0, "x-janus-max": 150 },
//     { "name": "email", "type": "string", "x-janus-pattern": "^[\\w.]+@[\\w.]+\\.\\w+$" }
//   ]
// }

Extended Schema Fields

Since Avro doesn't natively support validation constraints, this package uses x-janus-* prefixed fields:

| Field | Type | Description | |-------|------|-------------| | x-janus-min | number | Minimum value for numeric types | | x-janus-max | number | Maximum value for numeric types | | x-janus-minLength | number | Minimum length for string/bytes | | x-janus-maxLength | number | Maximum length for string/bytes | | x-janus-pattern | string | Regex pattern for strings | | x-janus-enum | unknown[] | Allowed constant values | | x-janus-minItems | number | Minimum array length | | x-janus-maxItems | number | Maximum array length | | x-janus-description | string | Human-readable description | | x-janus-examples | unknown[] | Example values for generation |

Type Mapping

| Avro Type | Janus Validator | |-----------|-----------------| | null | Null() | | boolean | B() | | int | I(min?, max?) | | long | L(min?, max?) | | float | N(min?, max?) | | double | N(min?, max?) | | string | U(minLen?, maxLen?) or R(pattern) | | bytes | Bytes(minLen?, maxLen?) | | array | oneOrMore(item) / between(item, min, max) | | record | O({ ... }) | | enum | Or('a', 'b', ...) | | union | Or(type1, type2, ...) |

Roadmap

Planned behavior once implemented:

  • avroToValidator(schema):
    • Produces a validator from Avro schema + x-janus-* constraints
    • Records become Struct(...) / DSL O(...) with configurable strictness
  • validatorToAvro(validator):
    • Encodes domains/constraints back into Avro types + x-janus-* fields

License

MIT