aboutsummaryrefslogtreecommitdiff
path: root/sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts
diff options
context:
space:
mode:
authorDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
committerDanijel Andjelkovic <adanijel99@gmail.com>2022-03-01 21:54:41 +0100
commit6c8128f9fd5a5d0be115806c35a21b3d683df8d6 (patch)
treef46c2f6b3b9b294ff32bd75c08ccdc9e7a8cc4ef /sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts
parent2400b84e95913665da6279114168148444b8f9ab (diff)
parent7d3640f824f46490b47bd95f1c5a16644f712068 (diff)
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into logo
Diffstat (limited to 'sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts')
-rw-r--r--sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts74
1 files changed, 74 insertions, 0 deletions
diff --git a/sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts b/sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts
new file mode 100644
index 00000000..0731b1f6
--- /dev/null
+++ b/sandbox/testAppNevena/Front/node_modules/ajv/lib/vocabularies/jtd/ref.ts
@@ -0,0 +1,74 @@
+import type {CodeKeywordDefinition, AnySchemaObject} from "../../types"
+import type {KeywordCxt} from "../../compile/validate"
+import {compileSchema, SchemaEnv} from "../../compile"
+import {_, not, nil, stringify} from "../../compile/codegen"
+import MissingRefError from "../../compile/ref_error"
+import N from "../../compile/names"
+import {getValidate, callRef} from "../core/ref"
+import {checkMetadata} from "./metadata"
+
+const def: CodeKeywordDefinition = {
+ keyword: "ref",
+ schemaType: "string",
+ code(cxt: KeywordCxt) {
+ checkMetadata(cxt)
+ const {gen, data, schema: ref, parentSchema, it} = cxt
+ const {
+ schemaEnv: {root},
+ } = it
+ const valid = gen.name("valid")
+ if (parentSchema.nullable) {
+ gen.var(valid, _`${data} === null`)
+ gen.if(not(valid), validateJtdRef)
+ } else {
+ gen.var(valid, false)
+ validateJtdRef()
+ }
+ cxt.ok(valid)
+
+ function validateJtdRef(): void {
+ const refSchema = (root.schema as AnySchemaObject).definitions?.[ref]
+ if (!refSchema) throw new MissingRefError("", ref, `No definition ${ref}`)
+ if (hasRef(refSchema) || !it.opts.inlineRefs) callValidate(refSchema)
+ else inlineRefSchema(refSchema)
+ }
+
+ function callValidate(schema: AnySchemaObject): void {
+ const sch = compileSchema.call(
+ it.self,
+ new SchemaEnv({schema, root, schemaPath: `/definitions/${ref}`})
+ )
+ const v = getValidate(cxt, sch)
+ const errsCount = gen.const("_errs", N.errors)
+ callRef(cxt, v, sch, sch.$async)
+ gen.assign(valid, _`${errsCount} === ${N.errors}`)
+ }
+
+ function inlineRefSchema(schema: AnySchemaObject): void {
+ const schName = gen.scopeValue(
+ "schema",
+ it.opts.code.source === true ? {ref: schema, code: stringify(schema)} : {ref: schema}
+ )
+ cxt.subschema(
+ {
+ schema,
+ dataTypes: [],
+ schemaPath: nil,
+ topSchemaRef: schName,
+ errSchemaPath: `/definitions/${ref}`,
+ },
+ valid
+ )
+ }
+ },
+}
+
+export function hasRef(schema: AnySchemaObject): boolean {
+ for (const key in schema) {
+ let sch: AnySchemaObject
+ if (key === "ref" || (typeof (sch = schema[key]) == "object" && hasRef(sch))) return true
+ }
+ return false
+}
+
+export default def