UNPKG

1.84 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const util_1 = require("../../compile/util");
4const codegen_1 = require("../../compile/codegen");
5const metadata_1 = require("./metadata");
6const nullable_1 = require("./nullable");
7const error_1 = require("./error");
8const def = {
9 keyword: "values",
10 schemaType: "object",
11 error: (0, error_1.typeError)("object"),
12 code(cxt) {
13 (0, metadata_1.checkMetadata)(cxt);
14 const { gen, data, schema, it } = cxt;
15 const [valid, cond] = (0, nullable_1.checkNullableObject)(cxt, data);
16 if ((0, util_1.alwaysValidSchema)(it, schema)) {
17 gen.if((0, codegen_1.not)((0, codegen_1.or)(cond, valid)), () => cxt.error());
18 }
19 else {
20 gen.if(cond);
21 gen.assign(valid, validateMap());
22 gen.elseIf((0, codegen_1.not)(valid));
23 cxt.error();
24 gen.endIf();
25 }
26 cxt.ok(valid);
27 function validateMap() {
28 const _valid = gen.name("valid");
29 if (it.allErrors) {
30 const validMap = gen.let("valid", true);
31 validateValues(() => gen.assign(validMap, false));
32 return validMap;
33 }
34 gen.var(_valid, true);
35 validateValues(() => gen.break());
36 return _valid;
37 function validateValues(notValid) {
38 gen.forIn("key", data, (key) => {
39 cxt.subschema({
40 keyword: "values",
41 dataProp: key,
42 dataPropType: util_1.Type.Str,
43 }, _valid);
44 gen.if((0, codegen_1.not)(_valid), notValid);
45 });
46 }
47 }
48 },
49};
50exports.default = def;
51//# sourceMappingURL=values.js.map
\No newline at end of file