1 | import type {AnySchemaObject} from "./types"
|
2 | import AjvCore, {Options} from "./core"
|
3 |
|
4 | import draft2020Vocabularies from "./vocabularies/draft2020"
|
5 | import discriminator from "./vocabularies/discriminator"
|
6 | import addMetaSchema2020 from "./refs/json-schema-2020-12"
|
7 |
|
8 | const META_SCHEMA_ID = "https://json-schema.org/draft/2020-12/schema"
|
9 |
|
10 | class Ajv2020 extends AjvCore {
|
11 | constructor(opts: Options = {}) {
|
12 | super({
|
13 | ...opts,
|
14 | dynamicRef: true,
|
15 | next: true,
|
16 | unevaluated: true,
|
17 | })
|
18 | }
|
19 |
|
20 | _addVocabularies(): void {
|
21 | super._addVocabularies()
|
22 | draft2020Vocabularies.forEach((v) => this.addVocabulary(v))
|
23 | if (this.opts.discriminator) this.addKeyword(discriminator)
|
24 | }
|
25 |
|
26 | _addDefaultMetaSchema(): void {
|
27 | super._addDefaultMetaSchema()
|
28 | const {$data, meta} = this.opts
|
29 | if (!meta) return
|
30 | addMetaSchema2020.call(this, $data)
|
31 | this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID
|
32 | }
|
33 |
|
34 | defaultMeta(): string | AnySchemaObject | undefined {
|
35 | return (this.opts.defaultMeta =
|
36 | super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined))
|
37 | }
|
38 | }
|
39 |
|
40 | module.exports = exports = Ajv2020
|
41 | Object.defineProperty(exports, "__esModule", {value: true})
|
42 |
|
43 | export default Ajv2020
|
44 |
|
45 | export {
|
46 | Format,
|
47 | FormatDefinition,
|
48 | AsyncFormatDefinition,
|
49 | KeywordDefinition,
|
50 | KeywordErrorDefinition,
|
51 | CodeKeywordDefinition,
|
52 | MacroKeywordDefinition,
|
53 | FuncKeywordDefinition,
|
54 | Vocabulary,
|
55 | Schema,
|
56 | SchemaObject,
|
57 | AnySchemaObject,
|
58 | AsyncSchema,
|
59 | AnySchema,
|
60 | ValidateFunction,
|
61 | AsyncValidateFunction,
|
62 | ErrorObject,
|
63 | ErrorNoParams,
|
64 | } from "./types"
|
65 |
|
66 | export {Plugin, Options, CodeOptions, InstanceOptions, Logger, ErrorsTextOptions} from "./core"
|
67 | export {SchemaCxt, SchemaObjCxt} from "./compile"
|
68 | export {KeywordCxt} from "./compile/validate"
|
69 | export {DefinedError} from "./vocabularies/errors"
|
70 | export {JSONType} from "./compile/rules"
|
71 | export {JSONSchemaType} from "./types/json-schema"
|
72 | export {_, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions} from "./compile/codegen"
|