
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
ajsc is an npm package that transforms JSON Schema definitions into an intermediate representation (IR) called IRNode
. This intermediate form is designed to be consumed by language-specific converters—such as the built-in TypeScript converter—or by any custom converter you create for languages like Kotlin or Swift. This library streamlines the process of converting API JSON Schema definitions into strong-typed code representations, ensuring consistency between your API contracts and client implementations.
Comprehensive Schema Parsing:
Convert JSON Schema types including strings, numbers, booleans, nulls, literals, enums, unions, intersections, arrays, and objects into a unified IR.
Intermediate Representation (IRNode
):
The IRNode
provides a standard structure that captures type, constraints, and path information. This representation is ideal for further transformation into various target languages.
Plugin-Based Architecture:
Use the provided language plugin (currently, a TypeScript converter) or write your own converter to support additional languages such as Kotlin or Swift.
$defs and References Handling:
Resolve JSON Schema definitions ($defs
) and references ($ref
) seamlessly, ensuring reusable schema components are properly processed.
Unique Signature Tracking:
For objects and arrays, the library tracks unique signatures to avoid duplicate type definitions when converting to code.
Install ajsc via npm:
npm install ajsc
The primary function of ajsc is to convert a JSON Schema into an IRNode. Here’s an example of converting a simple JSON Schema that defines a string type:
import { JSONSchemaConverter } from "ajsc";
const schema = { type: "string" };
const converter = new JSONSchemaConverter(schema);
console.log(converter.irNode);
// Output:
// {
// type: "string",
// constraints: {},
// path: "",
// }
Converting Complex Schemas
You can also convert more complex schemas including objects, arrays, unions, intersections, and even schemas with $defs:
javascript
Copy
import { JSONSchemaConverter } from "ajsc";
const complexSchema = {
$defs: {
Person: {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" },
},
required: ["name"],
},
},
type: "object",
properties: {
person: { $ref: "#/$defs/Person" },
},
};
const converter = new JSONSchemaConverter(complexSchema);
console.log(converter.irNode);
new JSONSchemaConverter(schema: object)
The package includes a TypeScript language plugin that converts the IRNode into TypeScript type definitions.
new TypescriptConverter(schema: object, options?: { inlineTypes?: boolean })
Usage Example:
import { TypescriptConverter } from "ajsc";
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number" },
contacts: {
type: "array",
items: {
type: "object",
properties: {
email: { type: "string" },
},
required: ["email"],
},
},
profile: {
type: "object",
properties: {
email: { type: "string" },
},
required: ["email"],
},
},
required: ["name", "age"],
};
const tsConverter = new TypescriptConverter(schema, { inlineTypes: true });
console.log(tsConverter.code);
// Expected output (formatted):
// {
// name: string;
// age: number;
// contacts?: Array<{ email: string; }>;
// profile?: { email: string; };
// }
FAQs
Another Json-Schema Converter
The npm package ajsc receives a total of 18 weekly downloads. As such, ajsc popularity was classified as not popular.
We found that ajsc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.