
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
@janus-validator/avro
Advanced tools
Avro schema import/export for Janus Validator.
npm install @janus-validator/avro @janus-validator/core
🚧 Status: Avro conversion is scaffolded but not yet implemented. The exported functions currently throw Error('Not yet implemented').
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:
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);
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+$" }
// ]
// }
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 |
| 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, ...) |
Planned behavior once implemented:
avroToValidator(schema):
x-janus-* constraintsStruct(...) / DSL O(...) with configurable strictnessvalidatorToAvro(validator):
x-janus-* fieldsMIT
FAQs
Avro schema import/export for Janus Validator
We found that @janus-validator/avro demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.