1 import type {CodeKeywordDefinition, KeywordErrorDefinition} from "../../types"
2 import type {KeywordCxt} from "../../compile/validate"
3 import {_, str, operators} from "../../compile/codegen"
5 const error: KeywordErrorDefinition = {
6 message({keyword, schemaCode}) {
7 const comp = keyword === "maxProperties" ? "more" : "fewer"
8 return str`must NOT have ${comp} than ${schemaCode} items`
10 params: ({schemaCode}) => _`{limit: ${schemaCode}}`,
13 const def: CodeKeywordDefinition = {
14 keyword: ["maxProperties", "minProperties"],
19 code(cxt: KeywordCxt) {
20 const {keyword, data, schemaCode} = cxt
21 const op = keyword === "maxProperties" ? operators.GT : operators.LT
22 cxt.fail$data(_`Object.keys(${data}).length ${op} ${schemaCode}`)