2 Object.defineProperty(exports, "__esModule", { value: true });
3 const code_1 = require("../code");
4 const codegen_1 = require("../../compile/codegen");
5 const util_1 = require("../../compile/util");
7 message: ({ params: { missingProperty } }) => (0, codegen_1.str) `must have required property '${missingProperty}'`,
8 params: ({ params: { missingProperty } }) => (0, codegen_1._) `{missingProperty: ${missingProperty}}`,
17 const { gen, schema, schemaCode, data, $data, it } = cxt;
19 if (!$data && schema.length === 0)
21 const useLoop = schema.length >= opts.loopRequired;
26 if (opts.strictRequired) {
27 const props = cxt.parentSchema.properties;
28 const { definedProperties } = cxt.it;
29 for (const requiredKey of schema) {
30 if ((props === null || props === void 0 ? void 0 : props[requiredKey]) === undefined && !definedProperties.has(requiredKey)) {
31 const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
32 const msg = `required property "${requiredKey}" is not defined at "${schemaPath}" (strictRequired)`;
33 (0, util_1.checkStrictMode)(it, msg, it.opts.strictRequired);
37 function allErrorsMode() {
38 if (useLoop || $data) {
39 cxt.block$data(codegen_1.nil, loopAllRequired);
42 for (const prop of schema) {
43 (0, code_1.checkReportMissingProp)(cxt, prop);
47 function exitOnErrorMode() {
48 const missing = gen.let("missing");
49 if (useLoop || $data) {
50 const valid = gen.let("valid", true);
51 cxt.block$data(valid, () => loopUntilMissing(missing, valid));
55 gen.if((0, code_1.checkMissingProp)(cxt, schema, missing));
56 (0, code_1.reportMissingProp)(cxt, missing);
60 function loopAllRequired() {
61 gen.forOf("prop", schemaCode, (prop) => {
62 cxt.setParams({ missingProperty: prop });
63 gen.if((0, code_1.noPropertyInData)(gen, data, prop, opts.ownProperties), () => cxt.error());
66 function loopUntilMissing(missing, valid) {
67 cxt.setParams({ missingProperty: missing });
68 gen.forOf(missing, schemaCode, () => {
69 gen.assign(valid, (0, code_1.propertyInData)(gen, data, missing, opts.ownProperties));
70 gen.if((0, codegen_1.not)(valid), () => {
78 exports.default = def;
79 //# sourceMappingURL=required.js.map