Urara-Blog/node_modules/.pnpm-store/v3/files/17/3de38c2c84159cee79361dc48857bdc60aac25b63b4a9dfdcdb034e49227fab2340cda50a033829014d4b9902c6e8f5cf44dd71b90430d099daf7a692be1a8
2022-08-14 01:14:53 +08:00

24 lines
716 B
Text

import {KeywordCxt} from "../../ajv"
import type {CodeKeywordDefinition} from "../../types"
import {alwaysValidSchema} from "../../compile/util"
const def: CodeKeywordDefinition = {
keyword: "metadata",
schemaType: "object",
code(cxt: KeywordCxt) {
checkMetadata(cxt)
const {gen, schema, it} = cxt
if (alwaysValidSchema(it, schema)) return
const valid = gen.name("valid")
cxt.subschema({keyword: "metadata", jtdMetadata: true}, valid)
cxt.ok(valid)
},
}
export function checkMetadata({it, keyword}: KeywordCxt, metadata?: boolean): void {
if (it.jtdMetadata !== metadata) {
throw new Error(`JTD: "${keyword}" cannot be used in this schema location`)
}
}
export default def