{"version":3,"sources":["../../src/adapters/typebox.ts"],"sourcesContent":["// Code based on https://github.com/decs/typeschema/blob/main/packages/typebox/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 TSchema } from \"@sinclair/typebox\";\nimport { TypeCompiler } from \"@sinclair/typebox/compiler\";\nimport type { IfInstalled, Infer, ValidationAdapter } from \"./types\";\n\nclass TypeboxAdapter implements ValidationAdapter {\n\tasync validate<S extends IfInstalled<TSchema>>(schema: S, data: unknown) {\n\t\tconst result = TypeCompiler.Compile(schema);\n\n\t\tif (result.Check(data)) {\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: 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.Errors(data)].map(({ message, path }) => ({\n\t\t\t\tmessage,\n\t\t\t\tpath: path.split(\"/\").slice(1),\n\t\t\t})),\n\t\t} as const;\n\t}\n}\n\nexport function typeboxAdapter() {\n\treturn new TypeboxAdapter();\n}\n"],"mappings":";AAyBA,SAAS,oBAAoB;AAG7B,IAAM,iBAAN,MAAkD;AAAA,EACjD,MAAM,SAAyC,QAAW,MAAe;AACxE,UAAM,SAAS,aAAa,QAAQ,MAAM;AAE1C,QAAI,OAAO,MAAM,IAAI,GAAG;AACvB,aAAO;AAAA,QACN,SAAS;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,MACN,SAAS;AAAA,MACT,QAAQ,CAAC,GAAG,OAAO,OAAO,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS,KAAK,OAAO;AAAA,QAC5D;AAAA,QACA,MAAM,KAAK,MAAM,GAAG,EAAE,MAAM,CAAC;AAAA,MAC9B,EAAE;AAAA,IACH;AAAA,EACD;AACD;AAEO,SAAS,iBAAiB;AAChC,SAAO,IAAI,eAAe;AAC3B;","names":[]}