From 8ef23f1d786493de55d839d7d8624dda18e40598 Mon Sep 17 00:00:00 2001 From: Robin Baum Date: Wed, 6 Nov 2024 09:58:19 +0100 Subject: [PATCH] WIP --- src/core/compose.spec.ts | 6 +++++- src/core/compose.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/compose.spec.ts b/src/core/compose.spec.ts index 7d942c2..8907b5c 100644 --- a/src/core/compose.spec.ts +++ b/src/core/compose.spec.ts @@ -18,16 +18,20 @@ it('should execute middleware handlers in order', async () => { order.push(middleware1); return handler(...args); }; + middleware1['meta'] = {1: '1'}; const middleware2 = (handler) => (...args) => { order.push(middleware2); return handler(...args); }; + middleware2['meta'] = {2: '2'}; - compose(middleware1, middleware2)(async () => {})({}); + const composedHandler = compose(middleware1, middleware2)(async () => {}); + composedHandler({}); expect(order).toEqual([middleware1, middleware2]); + expect(composedHandler['meta']).toEqual({1: '1', 2: '2'}); }); it('should provide actual handler reference via "actual" property', async () => { diff --git a/src/core/compose.ts b/src/core/compose.ts index f48d389..b1ca17e 100644 --- a/src/core/compose.ts +++ b/src/core/compose.ts @@ -293,5 +293,5 @@ export function compose( // -> Anyway: This should be fixed in the future export function compose(f: Middleware): Middleware; export function compose(...fns) { - return fns.reduce((f, g) => (handler) => Object.assign(f(g(handler)), { actual: handler })); + return fns.reduce((f, g) => (handler) => Object.assign(f(g(handler)), { actual: handler, meta: {...f.meta, ...g.meta} })); }