UNPKG

@nahkies/typescript-koa-runtime

Version:

Runtime package for code generated by @nahkies/openapi-code-generator using the typescript-koa template

27 lines (26 loc) 846 B
import { t as KoaRuntimeError } from "./errors-CrlMSPkU.mjs"; import { t as findMatchingSchema } from "./validation-Bk2toxs9.mjs"; //#region src/zod-v4.ts function parseRequestInput(schema, input, type) { try { return schema?.parse(input); } catch (err) { throw KoaRuntimeError.RequestError(err, type); } } function responseValidationFactory(possibleResponses, defaultResponse) { possibleResponses.sort((x, y) => x[0] < y[0] ? -1 : 1); return (status, value) => { try { const schema = findMatchingSchema(status, possibleResponses); if (schema) return schema.parse(value); if (defaultResponse) return defaultResponse.parse(value); return value; } catch (err) { throw KoaRuntimeError.ResponseError(err); } }; } //#endregion export { parseRequestInput, responseValidationFactory }; //# sourceMappingURL=zod-v4.mjs.map