Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@hyperjump/json-schema-bundle
Advanced tools
Readme
JSON Schema Bundle (JSB) is built on JSON Schema Core.
JSB includes support for node.js JavaScript (CommonJS and ES Modules), TypeScript, and browsers.
npm install @hyperjump/json-schema-bundle
When in a browser context, JSB is designed to use the browser's fetch
implementation instead of a node.js fetch clone. The Webpack bundler does this
properly without any extra configuration, but if you are using the Rollup
bundler you will need to include the browser: true
option in your Rollup
configuration.
plugins: [
resolve({
browser: true
}),
commonjs()
]
This project is in beta and there may be breaking changes at any time. When it's stable enough, I'll publish v1.0.0 and follow semantic versioning from there on out.
const Bundler = require("@hyperjump/json-schema-bundle");
// Optionally load schema manually
Bundler.add({
"$id": "https://json-schema.hyperjump.io/schemas/string",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string"
});
// Get the initial schema to pass to the bundler
const main = await Bundler.get(`file://${__dirname}/schemas/main.schema.json`);
// The bundler will fetch from the file system, network, or internal schemas as
// needed to build to bundle.
const bundle = await Bundler.bundle(main);
Although the package is written in JavaScript, type definitions are included for TypeScript support. The following example shows the types you might want to know.
import Bundler from "@hyperjump/json-schema-bundle";
import type { SchemaDocument, Draft202012Schema, InvalidSchemaError } from "@hyperjump/json-schema-bundle";
(async function () {
const schemaJson: Draft202012Schema = {
"$id": "https://json-schema.hyperjump.io/schemas/string",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "string"
};
Bundler.add(schemaJson);
try {
const main: SchemaDocument = await Bundler.get(`file://${__dirname}/schemas/main.schema.json`);
const bundle: Draft202012Schema = await Bundler.bundle(main);
console.log(JSON.stringify(bundle, null, " "));
} catch (error: unknown) {
if (error instanceof InvalidSchemaError) {
console.log(error.output);
} else {
console.log(error);
}
}
}());
add: (schema: object, url?: URI, schemaVersion?: string) => SDoc
Load a schema. See JSC - $id and JSC - $schema for more information.
get: (url: URI, contextDoc?: SDoc, recursive: boolean = false) => Promise<SDoc>
Fetch a schema. Schemas can come from an HTTP request, a file, or a schema
that was added with add
.
bundle: (schema: SDoc, options: Options) => Promise<SchemaObject>
Create a bundled schema starting with the given schema. External schemas will be fetched from the filesystem, the network, or internally as needed.
Options:
$defs
. When using
"full" mode, it will keep the already embedded schemas around, which will
result in some embedded schema duplication.setMetaOutputFormat: (outputFormat: OutputFormat = DETAILED) => undefined
Set the output format for meta-validation. Meta-validation output is only returned if meta-validation results in an error.
setShouldMetaValidate: (isEnabled: boolean) => undefined
Enable or disable meta-validation.
OutputFormat: [FLAG | BASIC | DETAILED | VERBOSE]
See JSC - Output for more information on output formats.
Run the tests
npm test
Run the tests with a continuous test runner
npm test -- --watch
FAQs
A tool for bundling JSON Schema documents
We found that @hyperjump/json-schema-bundle 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.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).