@whook/whook
Version:
Build strong and efficient REST web services.
31 lines • 1.55 kB
JavaScript
import { service, location } from 'knifecycle';
import { noop } from '../libs/utils.js';
export default location(service(initTransformersWrappers, 'TRANSFORMERS_WRAPPERS', [
'?TRANSFORMERS_WRAPPERS_NAMES',
'?log',
]), import.meta.url);
export const TRANSFORMERS_WRAPPERS_REG_EXP = /^(wrapTransformer)[A-Z][a-zA-Z0-9]+/;
/**
* A simple passthrough service proxying the TRANSFORMERS_WRAPPERS.
* @param {Object} services
* The services `TRANSFORMERS_WRAPPERS` depends on
* @param {Array} [services.TRANSFORMERS_WRAPPERS_NAMES]
* The global wrappers names to wrap the transformers with
* @param {Object} [services.log=noop]
* An optional logging service
* @param {Object} services.TRANSFORMERS_WRAPPERS
* The dependencies must all be injected wrappers
* @return {Promise<Function>}
* A promise of the `TRANSFORMERS_WRAPPERS` hash.
*/
async function initTransformersWrappers({ TRANSFORMERS_WRAPPERS_NAMES = [], log = noop, ...TRANSFORMERS_WRAPPERS }) {
log('warning', `🏭 - Initializing the TRANSFORMERS_WRAPPERS service.`);
// Except with exotic configurations, those numbers should equal
// leaving this small debug message may help with messed configs
if (Object.keys(TRANSFORMERS_WRAPPERS).length !==
TRANSFORMERS_WRAPPERS_NAMES.length) {
log('debug', `🏭 - Found inconsistencies between TRANSFORMERS_WRAPPERS and TRANSFORMERS_WRAPPERS_NAMES.`);
}
return TRANSFORMERS_WRAPPERS_NAMES.map((key) => TRANSFORMERS_WRAPPERS[key]);
}
//# sourceMappingURL=TRANSFORMERS_WRAPPERS.js.map