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