(cxt, def)
| 3314 | } |
| 3315 | exports.macroKeywordCode = macroKeywordCode; |
| 3316 | function funcKeywordCode(cxt, def) { |
| 3317 | var _a; |
| 3318 | const { gen, keyword, schema, parentSchema, $data, it } = cxt; |
| 3319 | checkAsyncKeyword(it, def); |
| 3320 | const validate = !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate; |
| 3321 | const validateRef = useKeyword(gen, keyword, validate); |
| 3322 | const valid = gen.let("valid"); |
| 3323 | cxt.block$data(valid, validateKeyword); |
| 3324 | cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a : valid); |
| 3325 | function validateKeyword() { |
| 3326 | if (def.errors === false) { |
| 3327 | assignValid(); |
| 3328 | if (def.modifying) |
| 3329 | modifyData(cxt); |
| 3330 | reportErrs(() => cxt.error()); |
| 3331 | } |
| 3332 | else { |
| 3333 | const ruleErrs = def.async ? validateAsync() : validateSync(); |
| 3334 | if (def.modifying) |
| 3335 | modifyData(cxt); |
| 3336 | reportErrs(() => addErrs(cxt, ruleErrs)); |
| 3337 | } |
| 3338 | } |
| 3339 | function validateAsync() { |
| 3340 | const ruleErrs = gen.let("ruleErrs", null); |
| 3341 | gen.try(() => assignValid((0, codegen_1._) `await `), (e) => gen.assign(valid, false).if((0, codegen_1._) `${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, (0, codegen_1._) `${e}.errors`), () => gen.throw(e))); |
| 3342 | return ruleErrs; |
| 3343 | } |
| 3344 | function validateSync() { |
| 3345 | const validateErrs = (0, codegen_1._) `${validateRef}.errors`; |
| 3346 | gen.assign(validateErrs, null); |
| 3347 | assignValid(codegen_1.nil); |
| 3348 | return validateErrs; |
| 3349 | } |
| 3350 | function assignValid(_await = def.async ? (0, codegen_1._) `await ` : codegen_1.nil) { |
| 3351 | const passCxt = it.opts.passContext ? names_1.default.this : names_1.default.self; |
| 3352 | const passSchema = !(("compile" in def && !$data) || def.schema === false); |
| 3353 | gen.assign(valid, (0, codegen_1._) `${_await}${(0, code_1.callValidateCode)(cxt, validateRef, passCxt, passSchema)}`, def.modifying); |
| 3354 | } |
| 3355 | function reportErrs(errors) { |
| 3356 | var _a; |
| 3357 | gen.if((0, codegen_1.not)((_a = def.valid) !== null && _a !== void 0 ? _a : valid), errors); |
| 3358 | } |
| 3359 | } |
| 3360 | exports.funcKeywordCode = funcKeywordCode; |
| 3361 | function modifyData(cxt) { |
| 3362 | const { gen, data, it } = cxt; |
nothing calls this directly
no test coverage detected