source: trip-planner-front/node_modules/ajv/lib/vocabularies/jtd/elements.ts@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 976 bytes
Line 
1import type {CodeKeywordDefinition, SchemaObject} from "../../types"
2import type {KeywordCxt} from "../../compile/validate"
3import {alwaysValidSchema} from "../../compile/util"
4import {validateArray} from "../code"
5import {_, not} from "../../compile/codegen"
6import {checkMetadata} from "./metadata"
7import {checkNullable} from "./nullable"
8import {typeError, _JTDTypeError} from "./error"
9
10export type JTDElementsError = _JTDTypeError<"elements", "array", SchemaObject>
11
12const def: CodeKeywordDefinition = {
13 keyword: "elements",
14 schemaType: "object",
15 error: typeError("array"),
16 code(cxt: KeywordCxt) {
17 checkMetadata(cxt)
18 const {gen, data, schema, it} = cxt
19 if (alwaysValidSchema(it, schema)) return
20 const [valid] = checkNullable(cxt)
21 gen.if(not(valid), () =>
22 gen.if(
23 _`Array.isArray(${data})`,
24 () => gen.assign(valid, validateArray(cxt)),
25 () => cxt.error()
26 )
27 )
28 cxt.ok(valid)
29 },
30}
31
32export default def
Note: See TracBrowser for help on using the repository browser.