Skip to main content

@versionzero/schema / SchemaResolver

Class: SchemaResolver

Defined in: src/schema-resolver.js:60

The SchemaResolver uses its internal registries of named schemas and value processor keywords to convert Schemas containing unresolved references into resolved Schemas that are fully self-contained.

Methods

registerSchema()

registerSchema(name, schema): SchemaResolver

Defined in: src/schema-resolver.js:85

add a schema to the registry

Parameters

ParameterTypeDescription
namestring-
schemaSchema-

Returns

SchemaResolver


getSchema()

getSchema(name): Schema

Defined in: src/schema-resolver.js:99

return the registered schema with a given name

Parameters

ParameterTypeDescription
namestring-

Returns

Schema


hasSchema()

hasSchema(name): boolean

Defined in: src/schema-resolver.js:113

return true if there exists a registered schema with a given name

Parameters

ParameterTypeDescription
namestring-

Returns

boolean


listRegisteredSchemas()

listRegisteredSchemas(): RegisteredSchemaInfo[]

Defined in: src/schema-resolver.js:122

return all registered schemas

Returns

RegisteredSchemaInfo[]


registerValueProcessorDefinition()

registerValueProcessorDefinition(definition): SchemaResolver

Defined in: src/schema-resolver.js:131

Register a value processor definition

Parameters

ParameterTypeDescription
definitionValueProcessorDefinition-

Returns

SchemaResolver


registerValueProcessor()

registerValueProcessor(keyword, process, description?): SchemaResolver

Defined in: src/schema-resolver.js:165

register a named "simple" ValueProcessor

Parameters

ParameterTypeDescription
keywordstring-
processValueProcessorFunction-
description?string-

Returns

SchemaResolver


registerValueProcessorBuilder()

registerValueProcessorBuilder(keyword, build): SchemaResolver

Defined in: src/schema-resolver.js:183

register a complex ValueProcessor that needs to be built based on schema processor spec

Parameters

ParameterTypeDescription
keywordstring-
buildValueProcessorBuilder-

Returns

SchemaResolver


listValueProcessorDefinitions()

listValueProcessorDefinitions(): ValueProcessorDefinition[]

Defined in: src/schema-resolver.js:198

List all registered value processors (and reserved builtins)

Returns

ValueProcessorDefinition[]


use()

use(libraryFunction, options?): Promise<void>

Defined in: src/schema-resolver.js:225

Load a library of schemas and/or value processors.

Expects a (potentially async) library function accepting a SchemaResolver. Options passed to use will be propagated to the library function.

The name option is used for error messages. The sync option is used internally to enforce the core library does not get loaded asynchronously.

Parameters

ParameterTypeDescription
libraryFunction(resolver, options) => void | Promise<void>-
options?any-

Returns

Promise<void>


compileKeywordValueProcessorSpec()

compileKeywordValueProcessorSpec(compiler, spec, recursive?): ValueProcessor

Defined in: src/schema-resolver.js:257

Parameters

ParameterTypeDescription
compilerSchemaCompiler-
specKeywordValueProcessorSpec-
recursive?boolean-

Returns

ValueProcessor


compileValueProcessorSpecObject()

compileValueProcessorSpecObject(compiler, spec, recursive?): ValueProcessor

Defined in: src/schema-resolver.js:319

Convert a processor specification into an executor

Parameters

ParameterTypeDefault valueDescription
compilerSchemaCompilerundefined-
specanyundefinedThe processor specification
recursive?booleanfalse-

Returns

ValueProcessor


compileValueProcessorSpecArray()

compileValueProcessorSpecArray(compiler, spec, recursive?): ValueProcessor

Defined in: src/schema-resolver.js:340

Convert a processor specification into an executor

Parameters

ParameterTypeDefault valueDescription
compilerSchemaCompilerundefined-
specanyundefinedThe processor specification
recursive?booleanfalse-

Returns

ValueProcessor


compileValueProcessorSpec()

compileValueProcessorSpec(compiler, spec, recursive?): ValueProcessor

Defined in: src/schema-resolver.js:362

Convert a value processor specification into a value processor executor

Parameters

ParameterTypeDefault valueDescription
compilerSchemaCompilerundefined-
specanyundefinedThe processor specification
recursive?booleanfalse-

Returns

ValueProcessor


compile()

compile(inputSchema): CompiledSchema

Defined in: src/schema-resolver.js:452

Build a compiled schema from the schema definition.

Parameters

ParameterTypeDescription
inputSchemaCompiledSchema | SchemaData | Schema-

Returns

CompiledSchema


resolve()

resolve(inputSchema, recursive?): CompiledSchema | Schema

Defined in: src/schema-resolver.js:470

Create a new Schema that contains the flattened hierarchy of all resolved base schemas.

This can be useful if you need to make changes to the full schema, e.g. prepending processors before the base class handlers.

Parameters

ParameterTypeDefault valueDescription
inputSchemastring | CompiledSchema | SchemaData | Schemaundefined-
recursive?booleantrue-

Returns

CompiledSchema | Schema