1 import type {CodeKeywordDefinition, SchemaObject} from "../../types"
2 import type {KeywordCxt} from "../../compile/validate"
3 import {alwaysValidSchema} from "../../compile/util"
4 import {validateArray} from "../code"
5 import {_, not} from "../../compile/codegen"
6 import {checkMetadata} from "./metadata"
7 import {checkNullable} from "./nullable"
8 import {typeError, _JTDTypeError} from "./error"
10 export type JTDElementsError = _JTDTypeError<"elements", "array", SchemaObject>
12 const def: CodeKeywordDefinition = {
15 error: typeError("array"),
16 code(cxt: KeywordCxt) {
18 const {gen, data, schema, it} = cxt
19 if (alwaysValidSchema(it, schema)) return
20 const [valid] = checkNullable(cxt)
21 gen.if(not(valid), () =>
23 _`Array.isArray(${data})`,
24 () => gen.assign(valid, validateArray(cxt)),