@hyperjump/json-schema
Advanced tools
Comparing version 1.2.3 to 1.2.4
import curry from "just-curry-it"; | ||
import * as PubSub from "./pubsub.js"; | ||
import * as Configuration from "./configuration.js"; | ||
import { subscribe, unsubscribe } from "./pubsub.js"; | ||
import { | ||
setMetaSchemaOutputFormat, | ||
getShouldValidateSchema, | ||
isExperimentalKeywordEnabled, | ||
setExperimentalKeywordEnabled, | ||
getMetaSchemaOutputFormat | ||
} from "./configuration.js"; | ||
import * as Instance from "./instance.js"; | ||
@@ -11,3 +17,3 @@ import { InvalidSchemaError } from "./invalid-schema-error.js"; | ||
export const FLAG = "FLAG", BASIC = "BASIC", DETAILED = "DETAILED", VERBOSE = "VERBOSE"; | ||
Configuration.setMetaSchemaOutputFormat(FLAG); | ||
setMetaSchemaOutputFormat(FLAG); | ||
@@ -34,5 +40,8 @@ export const validate = async (url, value = undefined, outputFormat = undefined) => { | ||
const output = []; | ||
const subscriptionToken = PubSub.subscribe("result", outputHandler(outputFormat, output)); | ||
Validation.interpret(schemaUri, value, ast, {}); | ||
PubSub.unsubscribe("result", subscriptionToken); | ||
const subscriptionToken = subscribe("result", outputHandler(outputFormat, output)); | ||
try { | ||
Validation.interpret(schemaUri, value, ast, {}); | ||
} finally { | ||
unsubscribe("result", subscriptionToken); | ||
} | ||
@@ -75,4 +84,4 @@ return output[0]; | ||
const metaValidators = {}; | ||
PubSub.subscribe("validate.metaValidate", async (message, schema) => { | ||
if (Configuration.getShouldValidateSchema() && !schema.validated) { | ||
subscribe("validate.metaValidate", async (message, schema) => { | ||
if (getShouldValidateSchema() && !schema.validated) { | ||
Schema.markValidated(schema.id); | ||
@@ -84,4 +93,4 @@ | ||
const dyanmicRefKeywordId = "https://json-schema.org/keyword/dynamicRef"; | ||
const isDynamicRefEnabled = Configuration.isExperimentalKeywordEnabled(dyanmicRefKeywordId); | ||
Configuration.setExperimentalKeywordEnabled(dyanmicRefKeywordId, true); | ||
const isDynamicRefEnabled = isExperimentalKeywordEnabled(dyanmicRefKeywordId); | ||
setExperimentalKeywordEnabled(dyanmicRefKeywordId, true); | ||
@@ -91,3 +100,3 @@ const compiledSchema = await compile(schema.dialectId); | ||
Configuration.setExperimentalKeywordEnabled(dyanmicRefKeywordId, isDynamicRefEnabled); | ||
setExperimentalKeywordEnabled(dyanmicRefKeywordId, isDynamicRefEnabled); | ||
} | ||
@@ -97,3 +106,3 @@ | ||
const schemaInstance = Instance.cons(schema.schema, schema.id); | ||
const metaResults = metaValidators[schema.dialectId](schemaInstance, Configuration.getMetaSchemaOutputFormat()); | ||
const metaResults = metaValidators[schema.dialectId](schemaInstance, getMetaSchemaOutputFormat()); | ||
if (!metaResults.valid) { | ||
@@ -100,0 +109,0 @@ throw new InvalidSchemaError(metaResults); |
import fs from "fs/promises"; | ||
import fetch, { Response } from "node-fetch"; | ||
import { fetch, Response } from "undici"; | ||
import Url from "url"; | ||
@@ -4,0 +4,0 @@ import * as MediaTypes from "./media-types.js"; |
@@ -60,2 +60,3 @@ import { addKeyword } from "./keywords.js"; | ||
import uniqueItems from "./keywords/uniqueItems.js"; | ||
import unknown from "./keywords/unknown.js"; | ||
import vocabulary from "./keywords/vocabulary.js"; | ||
@@ -129,2 +130,3 @@ import writeOnly from "./keywords/writeOnly.js"; | ||
addKeyword(uniqueItems); | ||
addKeyword(unknown); | ||
addKeyword(vocabulary); | ||
@@ -131,0 +133,0 @@ addKeyword(writeOnly); |
@@ -1,6 +0,3 @@ | ||
import metaData from "./keywords/meta-data.js"; | ||
const _keywords = {}; | ||
export const getKeyword = (id) => _keywords[id] || id.startsWith("https://json-schema.org/keyword/unknown#") && { id, ...metaData }; | ||
export const getKeyword = (id) => _keywords[id]; | ||
@@ -19,3 +16,3 @@ export const addKeyword = (keywordHandler) => { | ||
export const getKeywordId = (dialectId, keyword) => _dialects[dialectId]?.[keyword] | ||
|| _allowUnknownKeywords[dialectId] && `https://json-schema.org/keyword/unknown#${keyword}`; | ||
|| _allowUnknownKeywords[dialectId] && "https://json-schema.org/keyword/unknown"; | ||
export const getKeywordName = (dialectId, keywordId) => { | ||
@@ -40,10 +37,5 @@ for (const keyword in _dialects[dialectId]) { | ||
.forEach(([keyword, keywordId]) => { | ||
if (!(keywordId in _keywords)) { | ||
if (isRequired) { | ||
delete _dialects[dialectId]; | ||
throw Error(`The '${keywordId}' keyword is not supported. This keyword was included in the '${vocabularyId}' vocabulary which is required by the '${dialectId}' dialect.`); | ||
} else { | ||
// Allow keyword to be ignored | ||
keywordId = `https://json-schema.org/keyword/unknown#${keyword}`; | ||
} | ||
if (!(keywordId in _keywords) && !isRequired) { | ||
// Allow keyword to be ignored | ||
keywordId = "https://json-schema.org/keyword/unknown"; | ||
} | ||
@@ -50,0 +42,0 @@ _dialects[dialectId][keyword] = keywordId; |
@@ -1,4 +0,7 @@ | ||
const compile = (schema) => schema.value; | ||
import { value } from "../schema.js"; | ||
const compile = value; | ||
const interpret = () => true; | ||
export default { compile, interpret }; |
@@ -30,3 +30,3 @@ import * as Pact from "@hyperjump/pact"; | ||
if (!["object", "boolean"].includes(typeof schemaValue)) { | ||
throw Error(`No schema found at '${Schema.uri(schema)}'`); | ||
throw Error(`No schema found at '${url}'`); | ||
} | ||
@@ -42,8 +42,11 @@ | ||
if (!keywordId) { | ||
throw Error(`Encountered unknown keyword '${keyword}' at ${Schema.uri(schema)}`); | ||
throw Error(`Encountered unknown keyword '${keyword}' at ${url}`); | ||
} | ||
const keywordHandler = getKeyword(keywordId); | ||
if (!keywordHandler) { | ||
throw Error(`Encountered unsupported keyword ${keyword} at '${url}'. You can provide an implementation for the '${keywordId}' keyword using the 'addKeyword' function.`); | ||
} | ||
if (keywordHandler.experimental && !isExperimentalKeywordEnabled(keywordId)) { | ||
throw Error(`Encountered experimental keyword ${keyword} at '${Schema.uri(schema)}'. You can enable this keyword with: setExperimentalKeywordEnabled('${keywordId}', true)`); | ||
throw Error(`Encountered experimental keyword ${keyword} at '${url}'. You can enable this keyword with: setExperimentalKeywordEnabled('${keywordId}', true)`); | ||
} | ||
@@ -50,0 +53,0 @@ |
import type { SchemaObject } from "./schema.js"; | ||
import type { Response } from "undici"; | ||
@@ -3,0 +4,0 @@ |
{ | ||
"name": "@hyperjump/json-schema", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects", | ||
@@ -59,3 +59,2 @@ "type": "module", | ||
"mocha": "*", | ||
"nock": "*", | ||
"ts-node": "*", | ||
@@ -71,3 +70,3 @@ "typescript": "*", | ||
"fastest-stable-stringify": "^2.0.2", | ||
"node-fetch": "^3.3.0", | ||
"undici": "^5.19.1", | ||
"uuid": "^9.0.0" | ||
@@ -74,0 +73,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
288905
14
163
7840
+ Addedundici@^5.19.1
+ Added@fastify/busboy@2.1.1(transitive)
+ Addedundici@5.28.4(transitive)
- Removednode-fetch@^3.3.0
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)