values.js 1.5 KB

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