persona-community-5/.pnpm-store/v3/files/6d/44e2db69009600ac2f57bc9671320d234b2027f78fe3f011537a0511a07d533af3e904cf33eac51edd67969f0c4778c1363c6bd589d89969bf2322536ca036
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

59 lines
1.6 KiB
Plaintext

import type {CodeKeywordDefinition, SchemaObject} from "../../types"
import type {KeywordCxt} from "../../compile/validate"
import {alwaysValidSchema, Type} from "../../compile/util"
import {not, or, Name} from "../../compile/codegen"
import {checkMetadata} from "./metadata"
import {checkNullableObject} from "./nullable"
import {typeError, _JTDTypeError} from "./error"
export type JTDValuesError = _JTDTypeError<"values", "object", SchemaObject>
const def: CodeKeywordDefinition = {
keyword: "values",
schemaType: "object",
error: typeError("object"),
code(cxt: KeywordCxt) {
checkMetadata(cxt)
const {gen, data, schema, it} = cxt
const [valid, cond] = checkNullableObject(cxt, data)
if (alwaysValidSchema(it, schema)) {
gen.if(not(or(cond, valid)), () => cxt.error())
} else {
gen.if(cond)
gen.assign(valid, validateMap())
gen.elseIf(not(valid))
cxt.error()
gen.endIf()
}
cxt.ok(valid)
function validateMap(): Name | boolean {
const _valid = gen.name("valid")
if (it.allErrors) {
const validMap = gen.let("valid", true)
validateValues(() => gen.assign(validMap, false))
return validMap
}
gen.var(_valid, true)
validateValues(() => gen.break())
return _valid
function validateValues(notValid: () => void): void {
gen.forIn("key", data, (key) => {
cxt.subschema(
{
keyword: "values",
dataProp: key,
dataPropType: Type.Str,
},
_valid
)
gen.if(not(_valid), notValid)
})
}
}
},
}
export default def