errors.cjs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. exports.ZodRealError = exports.ZodError = void 0;
  27. const core = __importStar(require("../core/index.cjs"));
  28. const index_js_1 = require("../core/index.cjs");
  29. const util = __importStar(require("../core/util.cjs"));
  30. const initializer = (inst, issues) => {
  31. index_js_1.$ZodError.init(inst, issues);
  32. inst.name = "ZodError";
  33. Object.defineProperties(inst, {
  34. format: {
  35. value: (mapper) => core.formatError(inst, mapper),
  36. // enumerable: false,
  37. },
  38. flatten: {
  39. value: (mapper) => core.flattenError(inst, mapper),
  40. // enumerable: false,
  41. },
  42. addIssue: {
  43. value: (issue) => {
  44. inst.issues.push(issue);
  45. inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
  46. },
  47. // enumerable: false,
  48. },
  49. addIssues: {
  50. value: (issues) => {
  51. inst.issues.push(...issues);
  52. inst.message = JSON.stringify(inst.issues, util.jsonStringifyReplacer, 2);
  53. },
  54. // enumerable: false,
  55. },
  56. isEmpty: {
  57. get() {
  58. return inst.issues.length === 0;
  59. },
  60. // enumerable: false,
  61. },
  62. });
  63. // Object.defineProperty(inst, "isEmpty", {
  64. // get() {
  65. // return inst.issues.length === 0;
  66. // },
  67. // });
  68. };
  69. exports.ZodError = core.$constructor("ZodError", initializer);
  70. exports.ZodRealError = core.$constructor("ZodError", initializer, {
  71. Parent: Error,
  72. });
  73. // /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
  74. // export type ErrorMapCtx = core.$ZodErrorMapCtx;