diff options
author | EuAndreh <eu@euandre.org> | 2024-03-06 20:25:58 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-03-06 20:26:00 -0300 |
commit | 1a15b80316b9cdbe56b0cac48ecc9e09cfc3182d (patch) | |
tree | bc71af675af5d6fff78c4efaafe3b600f6e94d6c | |
parent | src/hero.mjs: Add minimalistic "ping" action for doing smoke tests in production (diff) | |
download | papod-1a15b80316b9cdbe56b0cac48ecc9e09cfc3182d.tar.gz papod-1a15b80316b9cdbe56b0cac48ecc9e09cfc3182d.tar.xz |
src/hero.mjs: Better handling of default values for arguments
Now one can give a partial specification of the object and still get the
other attributes to have their default values.
-rw-r--r-- | src/hero.mjs | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index 7ac7c19..451198d 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -178,12 +178,9 @@ export const makeLogger = (writerFn = console.error) => ({ export const log = makeLogger(); export const interceptorsFn = ({ - uuidFn, - logger, -} = { - uuidFn: crypto.randomUUID, - logger: log, -}) => ({ + uuidFn = crypto.randomUUID, + logger = log, +} = {}) => ({ requestId: (req, next) => next({ ...req, id: uuidFn() }), logged: async (req, next) => { const { id, url, method } = req; @@ -256,10 +253,8 @@ export const wrapHandler = (fn, arr) => chainInterceptors(arr.concat([ (req, _next) => fn(req) ])); export const actionsFn = ({ - logger, -} = { - logger: log, -}) => ({ + logger = log, +} = {}) => ({ "toggle-debug-env": action => { const before = process.env.DEBUG; if (process.env.DEBUG) { @@ -291,12 +286,9 @@ export const actionsFn = ({ export const actions = actionsFn(); export const lineHandlerFn = ({ - logger, - actionsMap, -} = { - logger: log, - actionsMap: actions, -}) => line => { + logger = log, + actionsMap = actions, +} = {}) => line => { let cmd = null; try { cmd = JSON.parse(line); @@ -359,10 +351,8 @@ export const makeLineEmitter = fn => { }; export const makePipeReaderFn = ({ - lineFn, -} = { - lineFn: lineHandler -}) => path => { + lineFn = lineHandler, +} = {}) => path => { mkfifo(path); fs.createReadStream(path, "UTF-8").on("data", makeLineEmitter(lineFn)); }; |