turtle-express
Version:
`turtle-express` is kinda a framework or a library based on `express.js` with an opinionated express router with type safety and schema validation with zod. Also many [more features](https://github.com/mm-ninja-turtles/turtle-express/discussions/7) planni
21 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolverValidation = void 0;
function resolverValidation(resolvedObj, schemas) {
// resolved object might be a object of many keys
// since response shape is reflected with `HttpStatusCodes`
// get the first most key of the resolved object
// which is ideally the result of the resolver
const resolvedKey = Object.keys(resolvedObj)[0];
// get the resolved object
const resolved = resolvedObj[resolvedKey];
// get the same schema as the resolved key
const resolvedSchema = schemas[resolvedKey];
// throw the error if resolved key's validation schema is not provided
if (resolvedSchema === undefined)
throw new Error('The `controlled` resolver type need at least one `response schema`.');
// safe parse and return the result
return resolvedSchema.safeParse(resolved);
}
exports.resolverValidation = resolverValidation;
//# sourceMappingURL=resolver-validation.js.map