values.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: (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. };
  50. exports.default = def;
  51. //# sourceMappingURL=values.js.map