@modern-js/plugin 1.3.8 → 1.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/js/modern/farrow-pipeline/context.js +14 -75
- package/dist/js/modern/farrow-pipeline/index.js +0 -14
- package/dist/js/modern/farrow-pipeline/pipeline.js +12 -29
- package/dist/js/modern/manager/async.js +4 -11
- package/dist/js/modern/manager/runner.js +1 -9
- package/dist/js/modern/manager/sync.js +8 -16
- package/dist/js/modern/waterfall/async.js +1 -3
- package/dist/js/modern/waterfall/sync.js +1 -3
- package/dist/js/modern/workflow/async.js +3 -3
- package/dist/js/modern/workflow/parallel.js +2 -2
- package/dist/js/modern/workflow/sync.js +3 -3
- package/dist/js/node/farrow-pipeline/context.js +15 -88
- package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
- package/dist/js/node/manager/async.js +4 -12
- package/dist/js/node/manager/runner.js +1 -9
- package/dist/js/node/manager/sync.js +8 -15
- package/dist/js/node/waterfall/async.js +0 -2
- package/dist/js/node/waterfall/sync.js +0 -2
- package/dist/js/node/workflow/async.js +3 -3
- package/dist/js/node/workflow/parallel.js +2 -2
- package/dist/js/node/workflow/sync.js +3 -3
- package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
- package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
- package/dist/js/treeshaking/manager/async.js +10 -17
- package/dist/js/treeshaking/manager/runner.js +1 -7
- package/dist/js/treeshaking/manager/sync.js +9 -17
- package/dist/js/treeshaking/waterfall/async.js +1 -3
- package/dist/js/treeshaking/waterfall/sync.js +1 -3
- package/dist/js/treeshaking/workflow/async.js +6 -6
- package/dist/js/treeshaking/workflow/parallel.js +5 -5
- package/dist/js/treeshaking/workflow/sync.js +3 -3
- package/dist/types/farrow-pipeline/context.d.ts +5 -20
- package/dist/types/farrow-pipeline/index.d.ts +0 -14
- package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
- package/dist/types/manager/async.d.ts +4 -7
- package/dist/types/manager/runner.d.ts +0 -1
- package/dist/types/manager/sync.d.ts +5 -9
- package/dist/types/manager/types.d.ts +1 -6
- package/dist/types/waterfall/async.d.ts +1 -7
- package/dist/types/waterfall/sync.d.ts +0 -7
- package/dist/types/workflow/async.d.ts +1 -7
- package/dist/types/workflow/parallel.d.ts +2 -9
- package/dist/types/workflow/sync.d.ts +1 -10
- package/package.json +1 -12
- package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -80
- package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/modern/farrow-pipeline/hook.js +0 -42
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -100
- package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
- package/dist/js/node/farrow-pipeline/hook.js +0 -52
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -80
- package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
- package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
- package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
- package/dist/types/farrow-pipeline/hook.d.ts +0 -9
@@ -1,6 +1,6 @@
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
3
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
5
5
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
6
6
|
import { createPipeline } from "../farrow-pipeline";
|
@@ -21,16 +21,16 @@ export var createParallelWorkflow = function createParallelWorkflow() {
|
|
21
21
|
};
|
22
22
|
|
23
23
|
var run = /*#__PURE__*/function () {
|
24
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input
|
24
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
25
25
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
26
26
|
while (1) {
|
27
27
|
switch (_context.prev = _context.next) {
|
28
28
|
case 0:
|
29
|
-
return _context.abrupt("return", Promise.all(pipeline.run(input,
|
29
|
+
return _context.abrupt("return", Promise.all(pipeline.run(input, {
|
30
30
|
onLast: function onLast() {
|
31
31
|
return [];
|
32
32
|
}
|
33
|
-
}))
|
33
|
+
})).then(function (result) {
|
34
34
|
return result.filter(Boolean);
|
35
35
|
}));
|
36
36
|
|
@@ -42,7 +42,7 @@ export var createParallelWorkflow = function createParallelWorkflow() {
|
|
42
42
|
}, _callee);
|
43
43
|
}));
|
44
44
|
|
45
|
-
return function run(_x
|
45
|
+
return function run(_x) {
|
46
46
|
return _ref.apply(this, arguments);
|
47
47
|
};
|
48
48
|
}();
|
@@ -15,12 +15,12 @@ export var createWorkflow = function createWorkflow() {
|
|
15
15
|
return workflow;
|
16
16
|
};
|
17
17
|
|
18
|
-
var run = function run(input
|
19
|
-
var result = pipeline.run(input,
|
18
|
+
var run = function run(input) {
|
19
|
+
var result = pipeline.run(input, {
|
20
20
|
onLast: function onLast() {
|
21
21
|
return [];
|
22
22
|
}
|
23
|
-
})
|
23
|
+
});
|
24
24
|
return result.filter(Boolean);
|
25
25
|
};
|
26
26
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
1
|
+
/**
|
2
|
+
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
+
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
+
*/
|
2
5
|
export declare type Context<T = any> = {
|
3
|
-
id: symbol;
|
4
|
-
[ContextSymbol]: T;
|
5
6
|
create: (value: T) => Context<T>;
|
6
7
|
use: () => {
|
7
8
|
value: T;
|
@@ -9,20 +10,4 @@ export declare type Context<T = any> = {
|
|
9
10
|
get: () => T;
|
10
11
|
set: (value: T) => void;
|
11
12
|
};
|
12
|
-
export declare const createContext: <T>(value: T) => Context<T>;
|
13
|
-
export declare type ContextStorage = {
|
14
|
-
[key: string]: Context;
|
15
|
-
};
|
16
|
-
export declare type Container = {
|
17
|
-
read: <V>(Context: Context<V>) => V;
|
18
|
-
write: <V>(Context: Context<V>, value: V) => void;
|
19
|
-
};
|
20
|
-
export declare const createContainer: (ContextStorage?: ContextStorage) => Container;
|
21
|
-
export declare type Hooks = {
|
22
|
-
useContainer: () => Container;
|
23
|
-
};
|
24
|
-
export type { AnyFn } from './asyncHooksInterface';
|
25
|
-
export declare const runHooks: <F extends import("./asyncHooksInterface").AnyFn>(f: F, implementations: Hooks) => ReturnType<F>;
|
26
|
-
export declare const useContainer: () => Container;
|
27
|
-
export declare const fromContainer: (container: Container) => Hooks;
|
28
|
-
export declare const runWithContainer: <F extends (...args: any) => any>(f: F, container: Container) => ReturnType<F>;
|
13
|
+
export declare const createContext: <T>(value: T) => Context<T>;
|
@@ -1,19 +1,5 @@
|
|
1
1
|
/**
|
2
2
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
3
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*
|
5
|
-
* removed:
|
6
|
-
* - dependencies:
|
7
|
-
* - tslib
|
8
|
-
* - files
|
9
|
-
* - compose.ts
|
10
|
-
* - methods:
|
11
|
-
* - usePipeline
|
12
|
-
* - assertContainer
|
13
|
-
* - assertContext
|
14
|
-
* - isContext
|
15
|
-
* - isContainer
|
16
|
-
* - pipeline.useLazy
|
17
|
-
* - context.assert
|
18
4
|
*/
|
19
5
|
export * from './pipeline';
|
@@ -2,37 +2,28 @@
|
|
2
2
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
3
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
4
|
*/
|
5
|
-
import { createContext,
|
5
|
+
import { createContext, Context } from './context';
|
6
6
|
import { Next } from './counter';
|
7
7
|
export type { Next };
|
8
|
-
export { createContext
|
9
|
-
export type {
|
8
|
+
export { createContext };
|
9
|
+
export type { Context };
|
10
10
|
export declare type Middleware<I = unknown, O = unknown> = (input: I, next: Next<I, O>) => O;
|
11
11
|
export declare type Middlewares<I = unknown, O = unknown> = Middleware<I, O>[];
|
12
12
|
export declare const isPipeline: (input: any) => input is Pipeline<unknown, unknown>;
|
13
13
|
declare const PipelineSymbol: unique symbol;
|
14
|
-
export declare type PipelineOptions = {
|
15
|
-
contexts?: ContextStorage;
|
16
|
-
};
|
17
14
|
export declare type RunPipelineOptions<I = unknown, O = unknown> = {
|
18
|
-
container?: Container;
|
19
15
|
onLast?: (input: I) => O;
|
20
|
-
onLastWithContext?: boolean;
|
21
16
|
};
|
22
17
|
export declare type MiddlewareInput<I = unknown, O = unknown> = Middleware<I, O> | {
|
23
18
|
middleware: Middleware<I, O>;
|
24
19
|
};
|
25
|
-
export declare type MiddlewareType<T extends MiddlewareInput> = T extends MiddlewareInput<infer I, infer O> ? Middleware<I, O> : never;
|
26
20
|
export declare type Pipeline<I = unknown, O = unknown> = {
|
27
21
|
[PipelineSymbol]: true;
|
28
22
|
use: (...inputs: MiddlewareInput<I, O>[]) => Pipeline<I, O>;
|
29
23
|
run: (input: I, options?: RunPipelineOptions<I, O>) => O;
|
30
24
|
middleware: Middleware<I, O>;
|
31
25
|
};
|
32
|
-
export declare const createPipeline: <I, O>(
|
33
|
-
export declare type PipelineInput<T extends Pipeline> = T extends Pipeline<infer I> ? I : never;
|
34
|
-
export declare type PipelineOutput<T extends Pipeline> = T extends Pipeline<any, infer O> ? O : never;
|
26
|
+
export declare const createPipeline: <I, O>() => Pipeline<I, O>;
|
35
27
|
export declare type MaybeAsync<T> = T | Promise<T>;
|
36
|
-
export declare type ThunkMiddlewareInput<I, O> = () => MaybeAsync<MiddlewareInput<I, MaybeAsync<O>>>;
|
37
28
|
export declare type AsyncPipeline<I = unknown, O = unknown> = Pipeline<I, MaybeAsync<O>>;
|
38
|
-
export declare const createAsyncPipeline: <I, O>(
|
29
|
+
export declare const createAsyncPipeline: <I, O>() => AsyncPipeline<I, O>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { ToRunners, ToThreads, CommonAPI,
|
1
|
+
import type { ToRunners, ToThreads, CommonAPI, PluginOptions } from './types';
|
2
2
|
/** Setup function of async plugin. */
|
3
3
|
|
4
4
|
export declare type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
|
@@ -6,7 +6,6 @@ declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
|
6
6
|
export declare type AsyncPlugin<Hooks, API> = {
|
7
7
|
ASYNC_PLUGIN_SYMBOL: typeof ASYNC_PLUGIN_SYMBOL;
|
8
8
|
} & Required<PluginOptions<Hooks, AsyncSetup<Hooks, API>>>;
|
9
|
-
export declare type PluginFromAsyncManager<M extends AsyncManager<any, any>> = M extends AsyncManager<infer Hooks, infer API> ? AsyncPlugin<Hooks, API> : never;
|
10
9
|
export declare type AsyncManager<Hooks, API> = {
|
11
10
|
/**
|
12
11
|
* Create a sync plugin.
|
@@ -28,17 +27,15 @@ export declare type AsyncManager<Hooks, API> = {
|
|
28
27
|
usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
|
29
28
|
/**
|
30
29
|
* Init manager, it will call the setup function of all registered plugins.
|
31
|
-
* @param options passing a custom container.
|
32
30
|
*/
|
33
31
|
|
34
|
-
init: (
|
32
|
+
init: () => Promise<ToRunners<Hooks>>;
|
35
33
|
/**
|
36
|
-
* Run callback function
|
34
|
+
* Run callback function.
|
37
35
|
* @param callback
|
38
|
-
* @param options passing a custom container.
|
39
36
|
*/
|
40
37
|
|
41
|
-
run: <O>(cb: () => O
|
38
|
+
run: <O>(cb: () => O) => O;
|
42
39
|
/**
|
43
40
|
* Register new hooks.
|
44
41
|
* @param newHooks
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
import type { Hook, CommonAPI, ToRunners, ToThreads, InitOptions, PluginOptions } from './types';
|
1
|
+
import type { Hook, CommonAPI, ToRunners, ToThreads, PluginOptions } from './types';
|
3
2
|
/** Setup function of sync plugin. */
|
4
3
|
|
5
4
|
export declare type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
|
@@ -7,7 +6,6 @@ declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
|
7
6
|
export declare type Plugin<Hooks, API> = {
|
8
7
|
SYNC_PLUGIN_SYMBOL: typeof SYNC_PLUGIN_SYMBOL;
|
9
8
|
} & Required<PluginOptions<Hooks, Setup<Hooks, API>>>;
|
10
|
-
export declare type PluginFromManager<M extends Manager<any, any>> = M extends Manager<infer Hooks, infer API> ? Plugin<Hooks, API> : never;
|
11
9
|
export declare type Manager<Hooks, API> = {
|
12
10
|
/**
|
13
11
|
* Create a sync plugin.
|
@@ -29,17 +27,15 @@ export declare type Manager<Hooks, API> = {
|
|
29
27
|
usePlugin: (...plugins: Array<Plugin<Hooks, API> | PluginOptions<Hooks, Setup<Hooks, API>> | (() => PluginOptions<Hooks, Setup<Hooks, API>>)>) => Manager<Hooks, API>;
|
30
28
|
/**
|
31
29
|
* Init manager, it will call the setup function of all registered plugins.
|
32
|
-
* @param options passing a custom container.
|
33
30
|
*/
|
34
31
|
|
35
|
-
init: (
|
32
|
+
init: () => ToRunners<Hooks>;
|
36
33
|
/**
|
37
|
-
* Run callback function
|
34
|
+
* Run callback function.
|
38
35
|
* @param callback
|
39
|
-
* @param options passing a custom container.
|
40
36
|
*/
|
41
37
|
|
42
|
-
run: <O>(cb: () => O
|
38
|
+
run: <O>(cb: () => O) => O;
|
43
39
|
/**
|
44
40
|
* Register new hooks.
|
45
41
|
* @param newHooks
|
@@ -73,7 +69,7 @@ export declare const DEFAULT_OPTIONS: {
|
|
73
69
|
registerHook: {};
|
74
70
|
};
|
75
71
|
export declare const createManager: <Hooks, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => Manager<Hooks, API>;
|
76
|
-
export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[],
|
72
|
+
export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], hooksMap?: Hooks | undefined) => ToRunners<Hooks>;
|
77
73
|
export declare const cloneHook: (hook: Hook) => Hook;
|
78
74
|
export declare const closeHooksMap: <Hooks>(record: Hooks) => Hooks;
|
79
75
|
export {};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Pipeline,
|
1
|
+
import type { Pipeline, MaybeAsync, Middleware, AsyncPipeline } from '../farrow-pipeline';
|
2
2
|
import type { Brook, Waterfall, AsyncBrook, AsyncWaterfall } from '../waterfall';
|
3
3
|
import type { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
|
4
4
|
/** All hook types. */
|
@@ -29,11 +29,6 @@ export declare type PluginOptions<Hooks, Setup = undefined> = {
|
|
29
29
|
usePlugins?: PluginOptions<Hooks, Setup>[];
|
30
30
|
registerHook?: Partial<Hooks>;
|
31
31
|
};
|
32
|
-
/** Options of manager.init method. */
|
33
|
-
|
34
|
-
export declare type InitOptions = {
|
35
|
-
container?: Container;
|
36
|
-
};
|
37
32
|
/** Common api of setup function. */
|
38
33
|
|
39
34
|
export declare type CommonAPI<Hooks> = {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { MaybeAsync
|
1
|
+
import { MaybeAsync } from '../farrow-pipeline';
|
2
2
|
declare const ASYNC_WATERFALL_SYMBOL: unique symbol;
|
3
3
|
export declare type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
|
4
4
|
export declare type AsyncBrookInput<I = unknown> = AsyncBrook<I> | {
|
@@ -8,7 +8,6 @@ export declare type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
|
|
8
8
|
export declare type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
|
9
9
|
export declare const getAsyncBrook: <I>(input: AsyncBrookInput<I>) => AsyncBrook<I>;
|
10
10
|
export declare type RunAsyncWaterfallOptions<I = unknown> = {
|
11
|
-
container?: Container;
|
12
11
|
onLast?: AsyncBrook<I>;
|
13
12
|
};
|
14
13
|
export declare type AsyncWaterfall<I> = {
|
@@ -17,11 +16,6 @@ export declare type AsyncWaterfall<I> = {
|
|
17
16
|
middleware: AsyncBrook<I>;
|
18
17
|
[ASYNC_WATERFALL_SYMBOL]: true;
|
19
18
|
};
|
20
|
-
export declare type AsyncWaterfall2AsyncBrook<P extends AsyncWaterfall<any>> = P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : never;
|
21
|
-
export declare type AsyncWaterfallRecord = Record<string, AsyncWaterfall<any>>;
|
22
|
-
export declare type AsyncWaterfalls2Brooks<PS extends AsyncWaterfallRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWaterfall<any> ? AsyncWaterfall2AsyncBrook<PS[K]> : PS[K] extends void ? void : never };
|
23
|
-
export declare type RunnerFromAsyncWaterfall<M extends AsyncWaterfall<any>> = M extends AsyncWaterfall<infer VS> ? AsyncWaterfall<VS>['run'] : never;
|
24
|
-
export declare type AsyncWaterfalls2Runners<PS extends AsyncWaterfallRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWaterfall<any> ? RunnerFromAsyncWaterfall<PS[K]> : PS[K] extends void ? void : never };
|
25
19
|
export declare const createAsyncWaterfall: <I = void>() => AsyncWaterfall<I>;
|
26
20
|
export declare const isAsyncWaterfall: (input: any) => input is AsyncWaterfall<any>;
|
27
21
|
export {};
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { Container } from '../farrow-pipeline';
|
2
1
|
declare const WATERFALL_SYMBOL: unique symbol;
|
3
2
|
export declare type Brook<I = unknown> = (I: I) => I;
|
4
3
|
export declare type BrookInput<I = unknown> = Brook<I> | {
|
@@ -8,7 +7,6 @@ export declare type Brooks<I = unknown> = Brook<I>[];
|
|
8
7
|
export declare type BrookInputs<I = unknown> = BrookInput<I>[];
|
9
8
|
export declare const getBrook: <I>(input: BrookInput<I>) => Brook<I>;
|
10
9
|
export declare type RunWaterfallOptions<I = unknown> = {
|
11
|
-
container?: Container;
|
12
10
|
onLast?: Brook<I>;
|
13
11
|
};
|
14
12
|
export declare type Waterfall<I = void> = {
|
@@ -17,11 +15,6 @@ export declare type Waterfall<I = void> = {
|
|
17
15
|
middleware: Brook<I>;
|
18
16
|
[WATERFALL_SYMBOL]: true;
|
19
17
|
};
|
20
|
-
export declare type Waterfall2Brook<P extends Waterfall<any>> = P extends Waterfall<infer I> ? Brook<I> : never;
|
21
|
-
export declare type WaterfallRecord = Record<string, Waterfall<any>>;
|
22
|
-
export declare type Waterfalls2Brooks<PS extends WaterfallRecord | void> = { [K in keyof PS]: PS[K] extends Waterfall<any> ? Waterfall2Brook<PS[K]> : PS[K] extends void ? void : never };
|
23
|
-
export declare type RunnerFromWaterfall<M extends Waterfall<any>> = M extends Waterfall<infer VS> ? Waterfall<VS>['run'] : never;
|
24
|
-
export declare type Waterfalls2Runners<PS extends WaterfallRecord | void> = { [K in keyof PS]: PS[K] extends Waterfall<any> ? RunnerFromWaterfall<PS[K]> : PS[K] extends void ? void : never };
|
25
18
|
export declare const createWaterfall: <I = void>() => Waterfall<I>;
|
26
19
|
export declare const isWaterfall: (input: any) => input is Waterfall<any>;
|
27
20
|
export {};
|
@@ -1,18 +1,12 @@
|
|
1
1
|
import { MaybeAsync } from '../farrow-pipeline';
|
2
|
-
import type { RunWorkflowOptions } from './sync';
|
3
2
|
declare const ASYNC_WORKFLOW_SYMBOL: unique symbol;
|
4
3
|
export declare type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
|
5
4
|
export declare type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
|
6
5
|
export declare type AsyncWorkflow<I, O> = {
|
7
|
-
run: (input: I
|
6
|
+
run: (input: I) => MaybeAsync<O[]>;
|
8
7
|
use: (...I: AsyncWorkers<I, O>) => AsyncWorkflow<I, O>;
|
9
8
|
[ASYNC_WORKFLOW_SYMBOL]: true;
|
10
9
|
};
|
11
|
-
export declare type AsyncWorkflow2AsyncWorker<W extends AsyncWorkflow<any, any>> = W extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : never;
|
12
|
-
export declare type AsyncWorkflowRecord = Record<string, AsyncWorkflow<any, any>>;
|
13
|
-
export declare type AsyncWorkflows2AsyncWorkers<PS extends AsyncWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWorkflow<any, any> ? AsyncWorkflow2AsyncWorker<PS[K]> : PS[K] extends void ? void : never };
|
14
|
-
export declare type RunnerFromAsyncWorkflow<W extends AsyncWorkflow<any, any>> = W extends AsyncWorkflow<infer I, infer O> ? AsyncWorkflow<I, O>['run'] : never;
|
15
|
-
export declare type AsyncWorkflows2Runners<PS extends AsyncWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWorkflow<any, any> ? RunnerFromAsyncWorkflow<PS[K]> : PS[K] extends void ? void : never };
|
16
10
|
export declare const isAsyncWorkflow: (input: any) => input is AsyncWorkflow<any, any>;
|
17
11
|
export declare const createAsyncWorkflow: <I = void, O = unknown>() => AsyncWorkflow<I, O>;
|
18
12
|
export {};
|
@@ -1,17 +1,10 @@
|
|
1
|
-
import type {
|
2
|
-
import type { RunWorkflowOptions } from './sync';
|
1
|
+
import type { AsyncWorkers } from './async';
|
3
2
|
declare const PARALLEL_WORKFLOW_SYMBOL: unique symbol;
|
4
3
|
export declare type ParallelWorkflow<I, O = any> = {
|
5
|
-
run: (input: I
|
4
|
+
run: (input: I) => Promise<O[]>;
|
6
5
|
use: (...I: AsyncWorkers<I, O>) => ParallelWorkflow<I, O>;
|
7
6
|
[PARALLEL_WORKFLOW_SYMBOL]: true;
|
8
7
|
};
|
9
|
-
export declare type ParallelWorkflow2Worker<W extends ParallelWorkflow<any>> = W extends ParallelWorkflow<infer CS, infer O> ? AsyncWorker<CS, O> : never;
|
10
|
-
export declare type ParallelWorkflowRecord = Record<string, ParallelWorkflow<any>>;
|
11
|
-
export declare type ParallelWorkflows2Workers<PS extends ParallelWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends ParallelWorkflow<any> ? ParallelWorkflow2Worker<PS[K]> : PS[K] extends void ? void : never };
|
12
|
-
export declare type ParallelWorkflows2AsyncWorkers<PS extends ParallelWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends ParallelWorkflow<any> ? ParallelWorkflow2Worker<PS[K]> : PS[K] extends void ? void : never };
|
13
|
-
export declare type RunnerFromParallelWorkflow<W extends ParallelWorkflow<any>> = W extends ParallelWorkflow<infer CS, infer O> ? ParallelWorkflow<CS, O>['run'] : never;
|
14
|
-
export declare type ParallelWorkflows2Runners<PS extends ParallelWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends ParallelWorkflow<any> ? RunnerFromParallelWorkflow<PS[K]> : PS[K] extends void ? void : never };
|
15
8
|
export declare const isParallelWorkflow: (input: any) => input is ParallelWorkflow<any, any>;
|
16
9
|
export declare const createParallelWorkflow: <I = void, O = unknown>() => ParallelWorkflow<I, O>;
|
17
10
|
export {};
|
@@ -1,20 +1,11 @@
|
|
1
|
-
import { Container } from '../farrow-pipeline';
|
2
1
|
declare const WORKFLOW_SYMBOL: unique symbol;
|
3
2
|
export declare type Worker<I, O> = (I: I) => O;
|
4
3
|
export declare type Workers<I, O> = Worker<I, O>[];
|
5
|
-
export declare type RunWorkflowOptions = {
|
6
|
-
container?: Container;
|
7
|
-
};
|
8
4
|
export declare type Workflow<I, O> = {
|
9
|
-
run: (input: I
|
5
|
+
run: (input: I) => void;
|
10
6
|
use: (...I: Workers<I, O>) => Workflow<I, O>;
|
11
7
|
[WORKFLOW_SYMBOL]: true;
|
12
8
|
};
|
13
|
-
export declare type Workflow2Worker<W extends Workflow<any, any>> = W extends Workflow<infer I, infer O> ? Worker<I, O> : never;
|
14
|
-
export declare type WorkflowRecord = Record<string, Workflow<any, any>>;
|
15
|
-
export declare type Workflows2Workers<PS extends WorkflowRecord | void> = { [K in keyof PS]: PS[K] extends Workflow<any, any> ? Workflow2Worker<PS[K]> : PS[K] extends void ? void : never };
|
16
|
-
export declare type RunnerFromWorkflow<W extends Workflow<any, any>> = W extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : never;
|
17
|
-
export declare type Workflows2Runners<PS extends WorkflowRecord | void> = { [K in keyof PS]: PS[K] extends Workflow<any, any> ? RunnerFromWorkflow<PS[K]> : PS[K] extends void ? void : never };
|
18
9
|
export declare const createWorkflow: <I = void, O = unknown>() => Workflow<I, O>;
|
19
10
|
export declare const isWorkflow: (input: any) => input is Workflow<unknown, unknown>;
|
20
11
|
export {};
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.4.0-alpha.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -25,17 +25,6 @@
|
|
25
25
|
"require": "./dist/js/node/index.js"
|
26
26
|
},
|
27
27
|
"default": "./dist/js/treeshaking/index.js"
|
28
|
-
},
|
29
|
-
"./node": {
|
30
|
-
"jsnext:source": "./src/farrow-pipeline/asyncHooks.node.ts",
|
31
|
-
"default": "./dist/js/node/farrow-pipeline/asyncHooks.node.js"
|
32
|
-
}
|
33
|
-
},
|
34
|
-
"typesVersions": {
|
35
|
-
"*": {
|
36
|
-
"node": [
|
37
|
-
"./dist/types/farrow-pipeline/asyncHooks.node.d.ts"
|
38
|
-
]
|
39
28
|
}
|
40
29
|
},
|
41
30
|
"dependencies": {
|
@@ -1,80 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import NodeAsyncHooks from 'async_hooks';
|
6
|
-
import * as asyncHooksInterface from "./asyncHooksInterface";
|
7
|
-
|
8
|
-
const createAsyncHooks = () => {
|
9
|
-
const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
10
|
-
|
11
|
-
const hooks = NodeAsyncHooks.createHook({
|
12
|
-
init: (asyncId, _, triggerAsyncId) => {
|
13
|
-
if (store.has(triggerAsyncId)) {
|
14
|
-
const value = store.get(triggerAsyncId);
|
15
|
-
|
16
|
-
if (value) {
|
17
|
-
store.set(asyncId, value);
|
18
|
-
}
|
19
|
-
}
|
20
|
-
},
|
21
|
-
destroy: asyncId => {
|
22
|
-
if (store.has(asyncId)) {
|
23
|
-
store.delete(asyncId);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
});
|
27
|
-
|
28
|
-
const set = value => {
|
29
|
-
store.set(NodeAsyncHooks.executionAsyncId(), value);
|
30
|
-
};
|
31
|
-
|
32
|
-
const get = () => {
|
33
|
-
return store.get(NodeAsyncHooks.executionAsyncId());
|
34
|
-
};
|
35
|
-
|
36
|
-
const clear = () => {
|
37
|
-
store.clear();
|
38
|
-
};
|
39
|
-
|
40
|
-
const enable = () => {
|
41
|
-
hooks.enable();
|
42
|
-
};
|
43
|
-
|
44
|
-
const disable = () => {
|
45
|
-
hooks.disable();
|
46
|
-
store.clear();
|
47
|
-
};
|
48
|
-
|
49
|
-
const entries = () => {
|
50
|
-
return store.entries();
|
51
|
-
};
|
52
|
-
|
53
|
-
return {
|
54
|
-
enable,
|
55
|
-
disable,
|
56
|
-
set,
|
57
|
-
get,
|
58
|
-
clear,
|
59
|
-
entries
|
60
|
-
};
|
61
|
-
};
|
62
|
-
|
63
|
-
let enabled = false;
|
64
|
-
export const enable = () => {
|
65
|
-
if (enabled) {
|
66
|
-
return;
|
67
|
-
}
|
68
|
-
|
69
|
-
enabled = true;
|
70
|
-
const hooks = createAsyncHooks();
|
71
|
-
asyncHooksInterface.impl(hooks);
|
72
|
-
hooks.enable();
|
73
|
-
};
|
74
|
-
export const disable = () => {
|
75
|
-
var _asyncHooksInterface$;
|
76
|
-
|
77
|
-
enabled = false;
|
78
|
-
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
79
|
-
asyncHooksInterface.reset();
|
80
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
// eslint-disable-next-line import/no-mutable-exports
|
6
|
-
export let asyncHooks;
|
7
|
-
export const impl = implimentations => {
|
8
|
-
asyncHooks = implimentations;
|
9
|
-
};
|
10
|
-
export const reset = () => {
|
11
|
-
asyncHooks = undefined;
|
12
|
-
};
|
@@ -1,42 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
import { asyncHooks } from "./asyncHooksInterface";
|
6
|
-
export const createHooks = defaultHooks => {
|
7
|
-
let currentHooks = {};
|
8
|
-
const hooks = {};
|
9
|
-
|
10
|
-
for (const key in defaultHooks) {
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
12
|
-
const f = (...args) => {
|
13
|
-
var _asyncHooks$get;
|
14
|
-
|
15
|
-
const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
16
|
-
let handler = hooks[key];
|
17
|
-
|
18
|
-
if (typeof handler !== 'function') {
|
19
|
-
handler = defaultHooks[key];
|
20
|
-
}
|
21
|
-
|
22
|
-
return handler(...args);
|
23
|
-
};
|
24
|
-
|
25
|
-
hooks[key] = f;
|
26
|
-
}
|
27
|
-
|
28
|
-
const run = (f, implementations) => {
|
29
|
-
try {
|
30
|
-
currentHooks = implementations || defaultHooks;
|
31
|
-
asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
|
32
|
-
return f();
|
33
|
-
} finally {
|
34
|
-
currentHooks = defaultHooks;
|
35
|
-
}
|
36
|
-
};
|
37
|
-
|
38
|
-
return {
|
39
|
-
run,
|
40
|
-
hooks
|
41
|
-
};
|
42
|
-
};
|
@@ -1,100 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.enable = exports.disable = void 0;
|
7
|
-
|
8
|
-
var _async_hooks = _interopRequireDefault(require("async_hooks"));
|
9
|
-
|
10
|
-
var asyncHooksInterface = _interopRequireWildcard(require("./asyncHooksInterface"));
|
11
|
-
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13
|
-
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15
|
-
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
|
18
|
-
/**
|
19
|
-
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
20
|
-
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
21
|
-
*/
|
22
|
-
const createAsyncHooks = () => {
|
23
|
-
const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
24
|
-
|
25
|
-
const hooks = _async_hooks.default.createHook({
|
26
|
-
init: (asyncId, _, triggerAsyncId) => {
|
27
|
-
if (store.has(triggerAsyncId)) {
|
28
|
-
const value = store.get(triggerAsyncId);
|
29
|
-
|
30
|
-
if (value) {
|
31
|
-
store.set(asyncId, value);
|
32
|
-
}
|
33
|
-
}
|
34
|
-
},
|
35
|
-
destroy: asyncId => {
|
36
|
-
if (store.has(asyncId)) {
|
37
|
-
store.delete(asyncId);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
});
|
41
|
-
|
42
|
-
const set = value => {
|
43
|
-
store.set(_async_hooks.default.executionAsyncId(), value);
|
44
|
-
};
|
45
|
-
|
46
|
-
const get = () => {
|
47
|
-
return store.get(_async_hooks.default.executionAsyncId());
|
48
|
-
};
|
49
|
-
|
50
|
-
const clear = () => {
|
51
|
-
store.clear();
|
52
|
-
};
|
53
|
-
|
54
|
-
const enable = () => {
|
55
|
-
hooks.enable();
|
56
|
-
};
|
57
|
-
|
58
|
-
const disable = () => {
|
59
|
-
hooks.disable();
|
60
|
-
store.clear();
|
61
|
-
};
|
62
|
-
|
63
|
-
const entries = () => {
|
64
|
-
return store.entries();
|
65
|
-
};
|
66
|
-
|
67
|
-
return {
|
68
|
-
enable,
|
69
|
-
disable,
|
70
|
-
set,
|
71
|
-
get,
|
72
|
-
clear,
|
73
|
-
entries
|
74
|
-
};
|
75
|
-
};
|
76
|
-
|
77
|
-
let enabled = false;
|
78
|
-
|
79
|
-
const enable = () => {
|
80
|
-
if (enabled) {
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
|
84
|
-
enabled = true;
|
85
|
-
const hooks = createAsyncHooks();
|
86
|
-
asyncHooksInterface.impl(hooks);
|
87
|
-
hooks.enable();
|
88
|
-
};
|
89
|
-
|
90
|
-
exports.enable = enable;
|
91
|
-
|
92
|
-
const disable = () => {
|
93
|
-
var _asyncHooksInterface$;
|
94
|
-
|
95
|
-
enabled = false;
|
96
|
-
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
97
|
-
asyncHooksInterface.reset();
|
98
|
-
};
|
99
|
-
|
100
|
-
exports.disable = disable;
|