{"version":3,"file":"errorMessages.cjs","names":[],"sources":["../../../src/utils/zod-to-json-schema/errorMessages.ts"],"sourcesContent":["import { JsonSchema7TypeUnion } from \"./parseTypes.js\";\nimport { Refs } from \"./Refs.js\";\n\nexport type ErrorMessages<\n  T extends JsonSchema7TypeUnion | { format: string } | { pattern: string },\n  OmitProperties extends string = \"\",\n> = Partial<\n  Omit<{ [key in keyof T]: string }, OmitProperties | \"type\" | \"errorMessages\">\n>;\n\nexport function addErrorMessage<\n  T extends { errorMessage?: ErrorMessages<any> },\n>(res: T, key: keyof T, errorMessage: string | undefined, refs: Refs) {\n  if (!refs?.errorMessages) return;\n  if (errorMessage) {\n    res.errorMessage = {\n      ...res.errorMessage,\n      [key]: errorMessage,\n    };\n  }\n}\n\nexport function setResponseValueAndErrors<\n  Json7Type extends JsonSchema7TypeUnion & {\n    errorMessage?: ErrorMessages<Json7Type>;\n  },\n  Key extends keyof Omit<Json7Type, \"errorMessage\">,\n>(\n  res: Json7Type,\n  key: Key,\n  value: Json7Type[Key],\n  errorMessage: string | undefined,\n  refs: Refs,\n) {\n  res[key] = value;\n  addErrorMessage(res, key, errorMessage, refs);\n}\n"],"mappings":";AAUA,SAAgB,gBAEd,KAAQ,KAAc,cAAkC,MAAY;AACpE,KAAI,CAAC,MAAM,cAAe;AAC1B,KAAI,aACF,KAAI,eAAe;EACjB,GAAG,IAAI;GACN,MAAM;EACR;;AAIL,SAAgB,0BAMd,KACA,KACA,OACA,cACA,MACA;AACA,KAAI,OAAO;AACX,iBAAgB,KAAK,KAAK,cAAc,KAAK"}