UNPKG

@whook/whook

Version:

Build strong and efficient REST web services.

30 lines 1.4 kB
import { service, location } from 'knifecycle'; import { noop } from '../libs/utils.js'; export default location(service(initRoutesWrappers, 'ROUTES_WRAPPERS', [ '?ROUTES_WRAPPERS_NAMES', '?log', ]), import.meta.url); export const ROUTES_WRAPPERS_REG_EXP = /^(wrapRoute)[A-Z][a-zA-Z0-9]+/; /** * A simple passthrough service proxying the ROUTES_WRAPPERS. * @param {Object} services * The service dependencies * @param {Array} [services.ROUTES_WRAPPERS_NAMES] * The global wrappers names to wrap the routes with * @param {Object} [services.log=noop] * An optional logging service * @param {Object} services.ROUTES_WRAPPERS * The dependencies must all be injected wrappers * @return {Promise<Function>} * A promise of the `ROUTES_WRAPPERS` hash. */ async function initRoutesWrappers({ ROUTES_WRAPPERS_NAMES = [], log = noop, ...ROUTES_WRAPPERS }) { log('warning', `🏭 - Initializing the ROUTES_WRAPPERS service.`); // Except with exotic configurations, those numbers should equal // leaving this small debug message may help with messed configs if (Object.keys(ROUTES_WRAPPERS).length !== ROUTES_WRAPPERS_NAMES.length) { log('debug', `🏭 - Found inconsistencies between ROUTES_WRAPPERS and ROUTES_WRAPPERS_NAMES.`); } return ROUTES_WRAPPERS_NAMES.map((key) => ROUTES_WRAPPERS[key]); } //# sourceMappingURL=ROUTES_WRAPPERS.js.map