From 4494630f5267ef07b0377d405015d866da85c5ee Mon Sep 17 00:00:00 2001 From: Rafa Mel Date: Wed, 17 Feb 2021 13:44:25 +0100 Subject: [PATCH] feat(tasks): adds context transform --- src/tasks/transform/context.ts | 16 ++++++++++++++++ src/tasks/transform/index.ts | 1 + 2 files changed, 17 insertions(+) create mode 100644 src/tasks/transform/context.ts diff --git a/src/tasks/transform/context.ts b/src/tasks/transform/context.ts new file mode 100644 index 0000000..effe55e --- /dev/null +++ b/src/tasks/transform/context.ts @@ -0,0 +1,16 @@ +import { Task, Context } from '../../definitions'; +import { run } from '../consume/run'; +import { UnaryFn, Empty } from 'type-core'; + +export function context( + context: + | Empty + | Partial + | UnaryFn | Empty>, + task: Task +): Task.Async { + const fn = typeof context === 'function' ? context : () => context; + return async (context: Context): Promise => { + await run(task, { ...context, ...fn(context) }); + }; +} diff --git a/src/tasks/transform/index.ts b/src/tasks/transform/index.ts index c739673..69a932d 100644 --- a/src/tasks/transform/index.ts +++ b/src/tasks/transform/index.ts @@ -1 +1,2 @@ +export * from './context'; export * from './select';