tuple.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.parseTupleDef = void 0;
  4. const parseDef_js_1 = require("../parseDef.js");
  5. function parseTupleDef(def, refs) {
  6. if (def.rest) {
  7. return {
  8. type: "array",
  9. minItems: def.items.length,
  10. items: def.items
  11. .map((x, i) => (0, parseDef_js_1.parseDef)(x._def, {
  12. ...refs,
  13. currentPath: [...refs.currentPath, "items", `${i}`],
  14. }))
  15. .reduce((acc, x) => (x === undefined ? acc : [...acc, x]), []),
  16. additionalItems: (0, parseDef_js_1.parseDef)(def.rest._def, {
  17. ...refs,
  18. currentPath: [...refs.currentPath, "additionalItems"],
  19. }),
  20. };
  21. }
  22. else {
  23. return {
  24. type: "array",
  25. minItems: def.items.length,
  26. maxItems: def.items.length,
  27. items: def.items
  28. .map((x, i) => (0, parseDef_js_1.parseDef)(x._def, {
  29. ...refs,
  30. currentPath: [...refs.currentPath, "items", `${i}`],
  31. }))
  32. .reduce((acc, x) => (x === undefined ? acc : [...acc, x]), []),
  33. };
  34. }
  35. }
  36. exports.parseTupleDef = parseTupleDef;