@hyperjump/json-schema 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -1
- package/lib/keywords.js +9 -3
- package/lib/schema.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -201,6 +201,9 @@ Schema, such as `@hyperjump/json-schema/draft-2020-12`.
|
|
|
201
201
|
* **unregisterSchema**: (uri: string) => void
|
|
202
202
|
|
|
203
203
|
Remove a schema from the local schema registry.
|
|
204
|
+
* **getAllRegisteredSchemaUris**: () => string[]
|
|
205
|
+
|
|
206
|
+
This function returns the URIs of all registered schemas
|
|
204
207
|
* **hasSchema**: (uri: string) => boolean
|
|
205
208
|
|
|
206
209
|
Check if a schema with the given URI is already registered.
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type SchemaObject = { // eslint-disable-line @typescript-eslint/consisten
|
|
|
9
9
|
export const registerSchema: (schema: SchemaObject | boolean, retrievalUri?: string, contextDialectId?: string) => void;
|
|
10
10
|
export const unregisterSchema: (retrievalUri: string) => void;
|
|
11
11
|
export const hasSchema: (uri: string) => boolean;
|
|
12
|
+
export const getAllRegisteredSchemaUris: () => string[];
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @deprecated since 1.7.0. Use registerSchema instead.
|
package/lib/index.js
CHANGED
|
@@ -130,7 +130,7 @@ addKeyword(vocabulary);
|
|
|
130
130
|
addKeyword(writeOnly);
|
|
131
131
|
|
|
132
132
|
export { addSchema, unregisterSchema, validate, FLAG } from "./core.js";
|
|
133
|
-
export { registerSchema, hasSchema } from "./schema.js";
|
|
133
|
+
export { registerSchema, hasSchema, getAllRegisteredSchemaUris } from "./schema.js";
|
|
134
134
|
export {
|
|
135
135
|
getMetaSchemaOutputFormat,
|
|
136
136
|
setMetaSchemaOutputFormat,
|
package/lib/keywords.js
CHANGED
|
@@ -36,6 +36,7 @@ export const defineVocabulary = (id, keywords) => {
|
|
|
36
36
|
|
|
37
37
|
const _dialects = {};
|
|
38
38
|
const _allowUnknownKeywords = {};
|
|
39
|
+
const _persistentDialects = {};
|
|
39
40
|
|
|
40
41
|
export const getKeywordId = (keyword, dialectId) => getDialect(dialectId)?.[keyword]
|
|
41
42
|
|| (_allowUnknownKeywords[dialectId] || keyword.startsWith("x-"))
|
|
@@ -60,8 +61,9 @@ const getDialect = (dialectId) => {
|
|
|
60
61
|
|
|
61
62
|
export const hasDialect = (dialectId) => dialectId in _dialects;
|
|
62
63
|
|
|
63
|
-
export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false) => {
|
|
64
|
+
export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false, isPersistent = true) => {
|
|
64
65
|
_allowUnknownKeywords[dialectId] = allowUnknownKeywords;
|
|
66
|
+
_persistentDialects[dialectId] = _persistentDialects[dialectId] || isPersistent;
|
|
65
67
|
|
|
66
68
|
_dialects[dialectId] = {};
|
|
67
69
|
Object.entries(dialect)
|
|
@@ -77,12 +79,16 @@ export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false) =>
|
|
|
77
79
|
});
|
|
78
80
|
} else if (!allowUnknownKeywords || isRequired) {
|
|
79
81
|
delete _dialects[dialectId];
|
|
82
|
+
delete _allowUnknownKeywords[dialectId];
|
|
83
|
+
delete _persistentDialects[dialectId];
|
|
80
84
|
throw Error(`Unrecognized vocabulary: ${vocabularyId}. You can define this vocabulary with the 'defineVocabulary' function.`);
|
|
81
85
|
}
|
|
82
86
|
});
|
|
83
87
|
};
|
|
84
88
|
|
|
85
89
|
export const unloadDialect = (dialectId) => {
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
if (!_persistentDialects[dialectId]) {
|
|
91
|
+
delete _allowUnknownKeywords[dialectId];
|
|
92
|
+
delete _dialects[dialectId];
|
|
93
|
+
}
|
|
88
94
|
};
|
package/lib/schema.js
CHANGED
|
@@ -59,6 +59,8 @@ export const unregisterSchema = (uri) => {
|
|
|
59
59
|
delete schemaRegistry[normalizedUri];
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
+
export const getAllRegisteredSchemaUris = () => Object.keys(schemaRegistry);
|
|
63
|
+
|
|
62
64
|
export const hasSchema = (uri) => uri in schemaRegistry;
|
|
63
65
|
|
|
64
66
|
export const buildSchemaDocument = (schema, id, dialectId, embedded = {}) => {
|
|
@@ -93,7 +95,7 @@ export const buildSchemaDocument = (schema, id, dialectId, embedded = {}) => {
|
|
|
93
95
|
const allowUnknownKeywords = schema[vocabularyToken]["https://json-schema.org/draft/2019-09/vocab/core"]
|
|
94
96
|
|| schema[vocabularyToken]["https://json-schema.org/draft/2020-12/vocab/core"];
|
|
95
97
|
|
|
96
|
-
loadDialect(id, schema[vocabularyToken], allowUnknownKeywords);
|
|
98
|
+
loadDialect(id, schema[vocabularyToken], allowUnknownKeywords, false);
|
|
97
99
|
delete schema[vocabularyToken];
|
|
98
100
|
}
|
|
99
101
|
|
package/package.json
CHANGED