date.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseDateDef = void 0;
  4. const errorMessages_1 = require("../errorMessages.js");
  5. function parseDateDef(def, refs, overrideDateStrategy) {
  6. const strategy = overrideDateStrategy ?? refs.dateStrategy;
  7. if (Array.isArray(strategy)) {
  8. return {
  9. anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)),
  10. };
  11. }
  12. switch (strategy) {
  13. case 'string':
  14. case 'format:date-time':
  15. return {
  16. type: 'string',
  17. format: 'date-time',
  18. };
  19. case 'format:date':
  20. return {
  21. type: 'string',
  22. format: 'date',
  23. };
  24. case 'integer':
  25. return integerDateParser(def, refs);
  26. }
  27. }
  28. exports.parseDateDef = parseDateDef;
  29. const integerDateParser = (def, refs) => {
  30. const res = {
  31. type: 'integer',
  32. format: 'unix-time',
  33. };
  34. if (refs.target === 'openApi3') {
  35. return res;
  36. }
  37. for (const check of def.checks) {
  38. switch (check.kind) {
  39. case 'min':
  40. (0, errorMessages_1.setResponseValueAndErrors)(res, 'minimum', check.value, // This is in milliseconds
  41. check.message, refs);
  42. break;
  43. case 'max':
  44. (0, errorMessages_1.setResponseValueAndErrors)(res, 'maximum', check.value, // This is in milliseconds
  45. check.message, refs);
  46. break;
  47. }
  48. }
  49. return res;
  50. };
  51. //# sourceMappingURL=date.js.map