{"version":3,"sources":["../../src/adapters/zod.ts"],"sourcesContent":["// Code based on https://github.com/decs/typeschema/blob/main/packages/zod/src/validation.ts\n\n// MIT License\n\n// Copyright (c) 2023 André Costa\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all\n// copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nimport type { z } from \"zod\";\nimport type { IfInstalled, Infer, ValidationAdapter } from \"./types\";\n\nclass ZodAdapter implements ValidationAdapter {\n\tasync validate<S extends IfInstalled<z.ZodType>>(schema: S, data: unknown) {\n\t\tconst result = await schema.safeParseAsync(data);\n\n\t\tif (result.success) {\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: result.data as Infer<S>,\n\t\t\t} as const;\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tissues: result.error.issues.map(({ message, path }) => ({ message, path })),\n\t\t} as const;\n\t}\n}\n\nexport function zodAdapter() {\n\treturn new ZodAdapter();\n}\n"],"mappings":";AA2BA,IAAM,aAAN,MAA8C;AAAA,EAC7C,MAAM,SAA2C,QAAW,MAAe;AAC1E,UAAM,SAAS,MAAM,OAAO,eAAe,IAAI;AAE/C,QAAI,OAAO,SAAS;AACnB,aAAO;AAAA,QACN,SAAS;AAAA,QACT,MAAM,OAAO;AAAA,MACd;AAAA,IACD;AAEA,WAAO;AAAA,MACN,SAAS;AAAA,MACT,QAAQ,OAAO,MAAM,OAAO,IAAI,CAAC,EAAE,SAAS,KAAK,OAAO,EAAE,SAAS,KAAK,EAAE;AAAA,IAC3E;AAAA,EACD;AACD;AAEO,SAAS,aAAa;AAC5B,SAAO,IAAI,WAAW;AACvB;","names":[]}