From de761cbd8de1ef152fc97daf4cd518e2cb43e75d Mon Sep 17 00:00:00 2001 From: Jason Desrosiers Date: Mon, 26 Aug 2024 12:48:37 -0700 Subject: [PATCH] Add hasVocabulary function --- README.md | 12 +++++++++--- lib/experimental.d.ts | 1 + lib/experimental.js | 2 +- lib/keywords.js | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c1a4301..0475162 100644 --- a/README.md +++ b/README.md @@ -542,6 +542,9 @@ These are available from the `@hyperjump/json-schema/experimental` export. Define a vocabulary that maps keyword name to keyword URIs defined using `addKeyword`. +* **hasVocabulary**: (dialectId: string) => boolean; + + Determine whether the vocabulary is supported. * **getKeywordId**: (keywordName: string, dialectId: string) => string Get the identifier for a keyword by its name. @@ -571,14 +574,17 @@ These are available from the `@hyperjump/json-schema/experimental` export. * **getDialectIds** This function retrieves the identifiers of all loaded JSON Schema dialects. -* **getDialect**: (dialectId: string) => Record; +* **getDialect**: (dialectId: string) => Record; + + This function retrieves all the keywords appropriate for a particular + dialect. +* **hasDialect**: (dialectId: string) => boolean; - This function retrieves all the keywords appropriate for a particular dialect. + Determine whether the dialect is supported. * **Validation**: Keyword A Keyword object that represents a "validate" operation. You would use this for compiling and evaluating sub-schemas when defining a custom keyword. - * **getSchema**: (uri: string, browser?: Browser) => Promise\ Get a schema by it's URI taking the local schema registry into account. diff --git a/lib/experimental.d.ts b/lib/experimental.d.ts index cd5a328..001ef55 100644 --- a/lib/experimental.d.ts +++ b/lib/experimental.d.ts @@ -60,6 +60,7 @@ export const getKeyword: (id: string) => Keyword; export const getKeywordByName: (keywordName: string, dialectId: string) => Keyword; export const getKeywordId: (keywordName: string, dialectId: string) => string; export const defineVocabulary: (id: string, keywords: Record) => void; +export const hasVocabulary: (vocabularyId: string) => boolean; export const loadDialect: (dialectId: string, dialect: Record, allowUnknownKeywords?: boolean) => void; export const unloadDialect: (dialectId: string) => void; export const hasDialect: (dialectId: string) => boolean; diff --git a/lib/experimental.js b/lib/experimental.js index bd59ded..7da17bd 100644 --- a/lib/experimental.js +++ b/lib/experimental.js @@ -1,7 +1,7 @@ export { compile, interpret, BASIC } from "./core.js"; export { addKeyword, getKeyword, getKeywordByName, getKeywordName, getKeywordId, - defineVocabulary, + defineVocabulary, hasVocabulary, loadDialect, unloadDialect, hasDialect, getDialectIds, getDialect } from "./keywords.js"; export { getSchema, toSchema, canonicalUri, buildSchemaDocument } from "./schema.js"; diff --git a/lib/keywords.js b/lib/keywords.js index 2027cd0..4dd5386 100644 --- a/lib/keywords.js +++ b/lib/keywords.js @@ -34,6 +34,8 @@ export const defineVocabulary = (id, keywords) => { _vocabularies[id] = keywords; }; +export const hasVocabulary = (vocabularyId) => vocabularyId in _vocabularies; + const _dialects = {}; const _allowUnknownKeywords = {};