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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sylvanas-cry/schema-registry-ajv

v2.1.2

Published

An Ajv instance wrapper for @kafkajs/confluent-schema-registry.

Downloads

3

Readme

schema-registry-ajv

An Ajv instance wrapper for @kafkajs/confluent-schema-registry.

Coverage Status Tested with: Jest semantic-release: angular TypeScript 5.1.6 ECMAScript 2022 License: MIT

Description

The library is a wrapper for the Ajv instance, which is in turn used in conjunction with @kafkajs/confluent-schema-registry.

Key Features

  • Resolves the Ajv "schema with id ... already exists" error that occurs at high RPS during communication with Kafka when using @kafkajs/confluent-schema-registry.
  • Allows retrieval of Ajv validation errors for the payload data by pulling them up to the application level.
  • Resolves the TypeError when passing an Ajv instance to the SchemaRegistry constructor options.

Bonus Features

  • Saves you from having to handle the schema ID.

Installation

Install the library:

npm install @sylvanas-cry/schema-registry-ajv

Install peer dependencies:

npm install \
  @kafkajs/confluent-schema-registry \
  ajv \
  ajv-formats \
  axios

Usage

Constructing and initialization:

const builder = new SchemaRegistryAjvBuilder({
  // Ajv class you want to use. Check "$schema" attribute of your schemas
  ajvClass: Ajv2020,
  // Optional Ajv native format options
  ajvFormats: ['date-time'],
  // Optional Ajv custom format options
  ajvCustomFormats: [{ name: 'custom-format', format: (value) => !!value }],
  // Schema Registry options
  schemaRegistry: {
    // Schema Registry URI
    host: 'https://schema-registry.example.com:8081',
    // Schema subject
    subject: 'foo.bar.baz.event.baz-done.v0-value',
    // Optional version of schema you want to use (can be number or 'latest')
    version: 'latest',
  },
});

const { ajvInstance, getSchemaId, getErrors } = await builder.build();

const schemaRegistry = new SchemaRegistry({ 
  host: 'https://schema-registry.example.com:8081',
}, {
  [SchemaType.JSON]: {
    ajvInstance, // <-- put your new safe Ajv instance here
  },
});

Somewhere in your code:

// Publishing to Kafka topic
try {
  // To encode Kafka message value
  const value = await schemaRegistry.encode(getSchemaId(), event);

  // ...
} catch (err) {
  // To get Ajv validation errors
  const validationErorrs = getErrors();

  // ...
}

Changes and Release Notes

CHANGELOG.md

License

The scripts and documentation in this project are released under the MIT License.