Files
klz-cables.com/.pnpm-store/v10/files/ba/6808e99ad7e3dfbeaebcaaa5d6c29effd45fa28063348951cab774ddf228f50c5947ba5dfe44ff1bca2e4991e0644b349f1d0f9106c44b084869c23ec09bbb
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

43 lines
1.3 KiB
Plaintext

import type {CodeKeywordDefinition, ErrorObject, KeywordErrorDefinition} from "../../types"
import type {KeywordCxt} from "../../compile/validate"
import {_, str, operators, Code} from "../../compile/codegen"
const ops = operators
type Kwd = "maximum" | "minimum" | "exclusiveMaximum" | "exclusiveMinimum"
type Comparison = "<=" | ">=" | "<" | ">"
const KWDs: {[K in Kwd]: {okStr: Comparison; ok: Code; fail: Code}} = {
maximum: {okStr: "<=", ok: ops.LTE, fail: ops.GT},
minimum: {okStr: ">=", ok: ops.GTE, fail: ops.LT},
exclusiveMaximum: {okStr: "<", ok: ops.LT, fail: ops.GTE},
exclusiveMinimum: {okStr: ">", ok: ops.GT, fail: ops.LTE},
}
export type LimitNumberError = ErrorObject<
Kwd,
{limit: number; comparison: Comparison},
number | {$data: string}
>
const error: KeywordErrorDefinition = {
message: ({keyword, schemaCode}) => str`must be ${KWDs[keyword as Kwd].okStr} ${schemaCode}`,
params: ({keyword, schemaCode}) =>
_`{comparison: ${KWDs[keyword as Kwd].okStr}, limit: ${schemaCode}}`,
}
const def: CodeKeywordDefinition = {
keyword: Object.keys(KWDs),
type: "number",
schemaType: "number",
$data: true,
error,
code(cxt: KeywordCxt) {
const {keyword, data, schemaCode} = cxt
cxt.fail$data(_`${data} ${KWDs[keyword as Kwd].fail} ${schemaCode} || isNaN(${data})`)
},
}
export default def