Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
avro-schema-builder
Advanced tools
A robust and feature-rich package for building Avro Schema definitions.
avro-schema-builder is a convenient way of programmatically building Avro Schemas. With the help of TypeScript type definitions, this library provides a type-safe and self-documenting way of creating Avro schemas, without dealing with JSON files or worrying about schema validation or learning the depth of Avro specific representation like defaults and object nesting.
yarn add avro-schema-builder
npm install avro-schema-builder
import {AvroSchemaBuilder, PrimitiveField, PrimitiveType} from 'avro-schema-builder';
new AvroSchemaBuilder('myRecord')
.record('record.record')
.addField(
new RecordField({
namespace: 'record.primitive.x',
name: 'children',
doc: 'children field',
order: FieldOrder.ascending,
nullable: true,
})
.addField(
new PrimitiveField({
name: 'id',
type: 'int',
}),
)
.addField(
new RecordField({
namespace: 'record.primitive.x.y',
name: 'grandchildren',
doc: 'children field',
order: FieldOrder.descending,
nullable: true,
defaultValue: null,
}).addField(
new PrimitiveField({
name: 'id',
type: 'int',
}),
),
),
)
.compile();
console.log(JSON.stringify(schema, null, 2));
This will output the following Avro Schema:
{
"type": "record",
"name": "myRecord",
"namespace": "record.record",
"fields": [
{
"name": "children",
"type": [
"null",
{
"fields": [
{
"name": "id",
"type": "int"
},
{
"name": "grandchildren",
"type": [
"null",
{
"default": null,
"fields": [
{
"name": "id",
"type": "int"
}
],
"name": "grandchildren",
"namespace": "record.primitive.x.y",
"type": "record"
}
]
}
],
"name": "children",
"namespace": "record.primitive.x",
"type": "record"
}
]
}
]
}
This package provides several classes and types for building Avro schemas:
AvroSchemaBuilder
: Main entry point for creating a schema. It is initialized with the name of the schema.FieldBuilder
: Represents a field in the schema. It can be of various types including PrimitiveField, RecordField, ArrayField, EnumField, MapField, FixedField, UnionField, and ReferenceField.PrimitiveField
, RecordField
, ArrayField
, etc.): Represent the different types of fields available in Avro.types
: Contains TypeScript type definitions for the various Avro types.For a more detailed explanation of the classes and types available, and how to use them, please check out the source code and the test cases.
Contributions are welcome! Please submit a pull request with any improvements or bug fixes. Make sure to add tests for any new features and bug fixes, and ensure that the existing tests pass.
This project is licensed under the MIT License.
If you need help or have questions, feel free to open an issue in the GitHub repository.
FAQs
avro-schema-builder
The npm package avro-schema-builder receives a total of 71 weekly downloads. As such, avro-schema-builder popularity was classified as not popular.
We found that avro-schema-builder demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.