@modern-js/plugin 2.69.4 → 3.0.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/dist/cjs/cli/api.js +119 -0
- package/dist/cjs/cli/context.js +85 -0
- package/dist/cjs/cli/hooks.js +65 -0
- package/dist/cjs/cli/index.js +68 -0
- package/dist/cjs/cli/run/config/createLoadedConfig.js +87 -0
- package/dist/cjs/cli/run/config/createResolvedConfig.js +48 -0
- package/dist/cjs/cli/run/config/loadConfig.js +113 -0
- package/dist/cjs/cli/run/create.js +187 -0
- package/dist/cjs/cli/run/index.js +56 -0
- package/dist/cjs/cli/run/run.js +57 -0
- package/dist/cjs/cli/run/types.js +18 -0
- package/dist/cjs/cli/run/utils/checkIsDuplicationPlugin.js +45 -0
- package/dist/cjs/cli/run/utils/commander.js +56 -0
- package/dist/cjs/cli/run/utils/createFileWatcher.js +112 -0
- package/dist/cjs/cli/run/utils/debug.js +37 -0
- package/dist/cjs/cli/run/utils/initAppDir.js +55 -0
- package/dist/cjs/cli/run/utils/mergeConfig.js +66 -0
- package/dist/cjs/hooks.js +169 -0
- package/dist/cjs/index.js +53 -26
- package/dist/cjs/manager.js +135 -0
- package/dist/cjs/runtime/api.js +95 -0
- package/dist/cjs/runtime/context.js +60 -0
- package/dist/cjs/runtime/hooks.js +46 -0
- package/dist/cjs/runtime/index.js +51 -0
- package/dist/cjs/runtime/run/create.js +79 -0
- package/dist/cjs/runtime/run/index.js +37 -0
- package/dist/cjs/runtime/run/types.js +18 -0
- package/dist/cjs/server/api.js +96 -0
- package/dist/cjs/server/context.js +75 -0
- package/dist/cjs/server/hooks.js +43 -0
- package/dist/cjs/server/index.js +54 -0
- package/dist/cjs/server/run/create.js +79 -0
- package/dist/cjs/server/run/index.js +40 -0
- package/dist/cjs/server/run/types.js +18 -0
- package/dist/cjs/types/cli/api.js +18 -0
- package/dist/cjs/types/cli/context.js +18 -0
- package/dist/cjs/types/cli/hooks.js +18 -0
- package/dist/cjs/types/cli/index.js +18 -0
- package/dist/cjs/types/cli/plugin.js +18 -0
- package/dist/cjs/types/hooks.js +18 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/cjs/types/plugin.js +18 -0
- package/dist/cjs/types/runtime/api.js +18 -0
- package/dist/cjs/types/runtime/context.js +18 -0
- package/dist/cjs/types/runtime/hooks.js +18 -0
- package/dist/cjs/types/runtime/index.js +18 -0
- package/dist/cjs/types/runtime/plugin.js +18 -0
- package/dist/cjs/types/server/api.js +18 -0
- package/dist/cjs/types/server/context.js +18 -0
- package/dist/cjs/types/server/hooks.js +18 -0
- package/dist/cjs/types/server/index.js +18 -0
- package/dist/cjs/types/server/plugin.js +18 -0
- package/dist/cjs/types/utils.js +18 -0
- package/dist/esm/cli/api.mjs +85 -0
- package/dist/esm/cli/context.mjs +38 -0
- package/dist/esm/cli/hooks.mjs +31 -0
- package/dist/esm/cli/index.mjs +7 -0
- package/dist/esm/cli/run/config/createLoadedConfig.mjs +53 -0
- package/dist/esm/cli/run/config/createResolvedConfig.mjs +14 -0
- package/dist/esm/cli/run/config/loadConfig.mjs +59 -0
- package/dist/esm/cli/run/create.mjs +150 -0
- package/dist/esm/cli/run/index.mjs +7 -0
- package/dist/esm/cli/run/run.mjs +23 -0
- package/dist/esm/cli/run/types.mjs +0 -0
- package/dist/esm/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
- package/dist/esm/cli/run/utils/commander.mjs +16 -0
- package/dist/esm/cli/run/utils/createFileWatcher.mjs +68 -0
- package/dist/esm/cli/run/utils/debug.mjs +3 -0
- package/dist/esm/cli/run/utils/initAppDir.mjs +11 -0
- package/dist/esm/cli/run/utils/mergeConfig.mjs +32 -0
- package/dist/esm/hooks.mjs +120 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/manager.mjs +101 -0
- package/dist/esm/runtime/api.mjs +61 -0
- package/dist/esm/runtime/context.mjs +23 -0
- package/dist/esm/runtime/hooks.mjs +12 -0
- package/dist/esm/runtime/index.mjs +5 -0
- package/dist/esm/runtime/run/create.mjs +45 -0
- package/dist/esm/runtime/run/index.mjs +3 -0
- package/dist/esm/runtime/run/types.mjs +0 -0
- package/dist/esm/server/api.mjs +59 -0
- package/dist/esm/server/context.mjs +38 -0
- package/dist/esm/server/hooks.mjs +9 -0
- package/dist/esm/server/index.mjs +5 -0
- package/dist/esm/server/run/create.mjs +45 -0
- package/dist/esm/server/run/index.mjs +3 -0
- package/dist/esm/server/run/types.mjs +0 -0
- package/dist/esm/types/cli/api.mjs +0 -0
- package/dist/esm/types/cli/context.mjs +0 -0
- package/dist/esm/types/cli/hooks.mjs +0 -0
- package/dist/esm/types/cli/index.mjs +0 -0
- package/dist/esm/types/cli/plugin.mjs +0 -0
- package/dist/esm/types/hooks.mjs +0 -0
- package/dist/esm/types/index.mjs +0 -0
- package/dist/esm/types/plugin.mjs +0 -0
- package/dist/esm/types/runtime/api.mjs +0 -0
- package/dist/esm/types/runtime/context.mjs +0 -0
- package/dist/esm/types/runtime/hooks.mjs +0 -0
- package/dist/esm/types/runtime/index.mjs +0 -0
- package/dist/esm/types/runtime/plugin.mjs +0 -0
- package/dist/esm/types/server/api.mjs +0 -0
- package/dist/esm/types/server/context.mjs +0 -0
- package/dist/esm/types/server/hooks.mjs +0 -0
- package/dist/esm/types/server/index.mjs +0 -0
- package/dist/esm/types/server/plugin.mjs +0 -0
- package/dist/esm/types/utils.mjs +0 -0
- package/dist/esm-node/cli/api.mjs +85 -0
- package/dist/esm-node/cli/context.mjs +38 -0
- package/dist/esm-node/cli/hooks.mjs +31 -0
- package/dist/esm-node/cli/index.mjs +7 -0
- package/dist/esm-node/cli/run/config/createLoadedConfig.mjs +53 -0
- package/dist/esm-node/cli/run/config/createResolvedConfig.mjs +14 -0
- package/dist/esm-node/cli/run/config/loadConfig.mjs +59 -0
- package/dist/esm-node/cli/run/create.mjs +150 -0
- package/dist/esm-node/cli/run/index.mjs +7 -0
- package/dist/esm-node/cli/run/run.mjs +23 -0
- package/dist/esm-node/cli/run/utils/checkIsDuplicationPlugin.mjs +11 -0
- package/dist/esm-node/cli/run/utils/commander.mjs +16 -0
- package/dist/esm-node/cli/run/utils/createFileWatcher.mjs +68 -0
- package/dist/esm-node/cli/run/utils/debug.mjs +3 -0
- package/dist/esm-node/cli/run/utils/initAppDir.mjs +11 -0
- package/dist/esm-node/cli/run/utils/mergeConfig.mjs +32 -0
- package/dist/esm-node/hooks.mjs +120 -0
- package/dist/esm-node/index.mjs +3 -0
- package/dist/esm-node/manager.mjs +101 -0
- package/dist/esm-node/runtime/api.mjs +61 -0
- package/dist/esm-node/runtime/context.mjs +23 -0
- package/dist/esm-node/runtime/hooks.mjs +12 -0
- package/dist/esm-node/runtime/index.mjs +5 -0
- package/dist/esm-node/runtime/run/create.mjs +45 -0
- package/dist/esm-node/runtime/run/index.mjs +3 -0
- package/dist/esm-node/runtime/run/types.mjs +0 -0
- package/dist/esm-node/server/api.mjs +59 -0
- package/dist/esm-node/server/context.mjs +38 -0
- package/dist/esm-node/server/hooks.mjs +9 -0
- package/dist/esm-node/server/index.mjs +5 -0
- package/dist/esm-node/server/run/create.mjs +45 -0
- package/dist/esm-node/server/run/index.mjs +3 -0
- package/dist/esm-node/server/run/types.mjs +0 -0
- package/dist/esm-node/types/cli/api.mjs +0 -0
- package/dist/esm-node/types/cli/context.mjs +0 -0
- package/dist/esm-node/types/cli/hooks.mjs +0 -0
- package/dist/esm-node/types/cli/index.mjs +0 -0
- package/dist/esm-node/types/cli/plugin.mjs +0 -0
- package/dist/esm-node/types/hooks.mjs +0 -0
- package/dist/esm-node/types/index.mjs +0 -0
- package/dist/esm-node/types/plugin.mjs +0 -0
- package/dist/esm-node/types/runtime/api.mjs +0 -0
- package/dist/esm-node/types/runtime/context.mjs +0 -0
- package/dist/esm-node/types/runtime/hooks.mjs +0 -0
- package/dist/esm-node/types/runtime/index.mjs +0 -0
- package/dist/esm-node/types/runtime/plugin.mjs +0 -0
- package/dist/esm-node/types/server/api.mjs +0 -0
- package/dist/esm-node/types/server/context.mjs +0 -0
- package/dist/esm-node/types/server/hooks.mjs +0 -0
- package/dist/esm-node/types/server/index.mjs +0 -0
- package/dist/esm-node/types/server/plugin.mjs +0 -0
- package/dist/esm-node/types/utils.mjs +0 -0
- package/dist/types/cli/api.d.ts +8 -0
- package/dist/types/cli/context.d.ts +19 -0
- package/dist/types/cli/hooks.d.ts +42 -0
- package/dist/types/cli/index.d.ts +6 -0
- package/dist/types/cli/run/config/createLoadedConfig.d.ts +2 -0
- package/dist/types/cli/run/config/createResolvedConfig.d.ts +3 -0
- package/dist/types/cli/run/config/loadConfig.d.ts +25 -0
- package/dist/types/cli/run/create.d.ts +16 -0
- package/dist/types/cli/run/index.d.ts +13 -0
- package/dist/types/cli/run/run.d.ts +2 -0
- package/dist/types/cli/run/types.d.ts +32 -0
- package/dist/types/cli/run/utils/checkIsDuplicationPlugin.d.ts +1 -0
- package/dist/types/cli/run/utils/commander.d.ts +5 -0
- package/dist/types/cli/run/utils/createFileWatcher.d.ts +3 -0
- package/dist/types/cli/run/utils/debug.d.ts +1 -0
- package/dist/types/cli/run/utils/initAppDir.d.ts +1 -0
- package/dist/types/cli/run/utils/mergeConfig.d.ts +2 -0
- package/dist/types/hooks.d.ts +7 -0
- package/dist/types/index.d.ts +7 -4
- package/dist/types/manager.d.ts +5 -0
- package/dist/types/runtime/api.d.ts +9 -0
- package/dist/types/runtime/context.d.ts +11 -0
- package/dist/types/runtime/hooks.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/run/create.d.ts +7 -0
- package/dist/types/runtime/run/index.d.ts +5 -0
- package/dist/types/runtime/run/types.d.ts +6 -0
- package/dist/types/server/api.d.ts +9 -0
- package/dist/types/server/context.d.ts +13 -0
- package/dist/types/server/hooks.d.ts +9 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/run/create.d.ts +7 -0
- package/dist/types/server/run/index.d.ts +8 -0
- package/dist/types/server/run/types.d.ts +22 -0
- package/dist/types/types/cli/api.d.ts +49 -0
- package/dist/types/types/cli/context.d.ts +42 -0
- package/dist/types/types/cli/hooks.d.ts +72 -0
- package/dist/types/types/cli/index.d.ts +4 -0
- package/dist/types/types/cli/plugin.d.ts +17 -0
- package/dist/types/types/hooks.d.ts +27 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/plugin.d.ts +46 -0
- package/dist/types/types/runtime/api.d.ts +22 -0
- package/dist/types/types/runtime/context.d.ts +13 -0
- package/dist/types/types/runtime/hooks.d.ts +39 -0
- package/dist/types/types/runtime/index.d.ts +4 -0
- package/dist/types/types/runtime/plugin.d.ts +14 -0
- package/dist/types/types/server/api.d.ts +19 -0
- package/dist/types/types/server/context.d.ts +28 -0
- package/dist/types/types/server/hooks.d.ts +24 -0
- package/dist/types/types/server/index.d.ts +4 -0
- package/dist/types/types/server/plugin.d.ts +14 -0
- package/dist/types/types/utils.d.ts +7 -0
- package/package.json +68 -14
- package/rslib.config.mts +4 -0
- package/rstest.config.ts +5 -0
- package/dist/cjs/farrow-pipeline/context.js +0 -44
- package/dist/cjs/farrow-pipeline/counter.js +0 -37
- package/dist/cjs/farrow-pipeline/index.js +0 -87
- package/dist/cjs/manager/async.js +0 -124
- package/dist/cjs/manager/index.js +0 -26
- package/dist/cjs/manager/shared.js +0 -60
- package/dist/cjs/manager/sync.js +0 -194
- package/dist/cjs/manager/types.js +0 -16
- package/dist/cjs/waterfall/async.js +0 -68
- package/dist/cjs/waterfall/index.js +0 -24
- package/dist/cjs/waterfall/sync.js +0 -67
- package/dist/cjs/workflow/async.js +0 -60
- package/dist/cjs/workflow/index.js +0 -30
- package/dist/cjs/workflow/interrupt.js +0 -64
- package/dist/cjs/workflow/parallel.js +0 -53
- package/dist/cjs/workflow/sync.js +0 -56
- package/dist/cjs/workflow/syncParallel.js +0 -55
- package/dist/esm/index.js +0 -882
- package/dist/esm-node/farrow-pipeline/context.js +0 -20
- package/dist/esm-node/farrow-pipeline/counter.js +0 -13
- package/dist/esm-node/farrow-pipeline/index.js +0 -60
- package/dist/esm-node/index.js +0 -4
- package/dist/esm-node/manager/async.js +0 -106
- package/dist/esm-node/manager/index.js +0 -3
- package/dist/esm-node/manager/shared.js +0 -32
- package/dist/esm-node/manager/sync.js +0 -172
- package/dist/esm-node/waterfall/async.js +0 -42
- package/dist/esm-node/waterfall/index.js +0 -2
- package/dist/esm-node/waterfall/sync.js +0 -41
- package/dist/esm-node/workflow/async.js +0 -35
- package/dist/esm-node/workflow/index.js +0 -5
- package/dist/esm-node/workflow/interrupt.js +0 -39
- package/dist/esm-node/workflow/parallel.js +0 -28
- package/dist/esm-node/workflow/sync.js +0 -31
- package/dist/esm-node/workflow/syncParallel.js +0 -30
- package/dist/types/farrow-pipeline/context.d.ts +0 -12
- package/dist/types/farrow-pipeline/counter.d.ts +0 -11
- package/dist/types/farrow-pipeline/index.d.ts +0 -29
- package/dist/types/manager/async.d.ts +0 -54
- package/dist/types/manager/index.d.ts +0 -3
- package/dist/types/manager/shared.d.ts +0 -12
- package/dist/types/manager/sync.d.ts +0 -66
- package/dist/types/manager/types.d.ts +0 -33
- package/dist/types/waterfall/async.d.ts +0 -21
- package/dist/types/waterfall/index.d.ts +0 -2
- package/dist/types/waterfall/sync.d.ts +0 -20
- package/dist/types/workflow/async.d.ts +0 -12
- package/dist/types/workflow/index.d.ts +0 -5
- package/dist/types/workflow/interrupt.d.ts +0 -12
- package/dist/types/workflow/parallel.d.ts +0 -10
- package/dist/types/workflow/sync.d.ts +0 -11
- package/dist/types/workflow/syncParallel.d.ts +0 -10
- /package/dist/esm-node/{manager/types.js → cli/run/types.mjs} +0 -0
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const createContext = (value) => {
|
|
2
|
-
let currentValue = value;
|
|
3
|
-
return {
|
|
4
|
-
use: () => ({
|
|
5
|
-
get value() {
|
|
6
|
-
return currentValue;
|
|
7
|
-
},
|
|
8
|
-
set value(v) {
|
|
9
|
-
currentValue = v;
|
|
10
|
-
}
|
|
11
|
-
}),
|
|
12
|
-
get: () => currentValue,
|
|
13
|
-
set: (v1) => {
|
|
14
|
-
currentValue = v1;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export {
|
|
19
|
-
createContext
|
|
20
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const createCounter = (callback) => {
|
|
2
|
-
const dispatch = (index, input) => {
|
|
3
|
-
const next = (nextInput = input) => dispatch(index + 1, nextInput);
|
|
4
|
-
return callback(index, input, next);
|
|
5
|
-
};
|
|
6
|
-
return {
|
|
7
|
-
start: (input) => dispatch(0, input),
|
|
8
|
-
dispatch
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export {
|
|
12
|
-
createCounter
|
|
13
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { createContext } from "./context";
|
|
2
|
-
import { createCounter } from "./counter";
|
|
3
|
-
const isPipeline = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
|
4
|
-
const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
|
5
|
-
const getMiddleware = (input) => {
|
|
6
|
-
if (typeof input === "function") {
|
|
7
|
-
return input;
|
|
8
|
-
} else if (input && typeof input.middleware === "function") {
|
|
9
|
-
return input.middleware;
|
|
10
|
-
}
|
|
11
|
-
throw new Error(`${input} is not a Middleware`);
|
|
12
|
-
};
|
|
13
|
-
const createPipeline = () => {
|
|
14
|
-
const middlewares = [];
|
|
15
|
-
const use = (...inputs) => {
|
|
16
|
-
middlewares.push(...inputs.map(getMiddleware));
|
|
17
|
-
return pipeline;
|
|
18
|
-
};
|
|
19
|
-
const createCurrentCounter = (onLast) => {
|
|
20
|
-
return createCounter((index, input, next) => {
|
|
21
|
-
if (index >= middlewares.length) {
|
|
22
|
-
if (onLast) {
|
|
23
|
-
return onLast(input);
|
|
24
|
-
}
|
|
25
|
-
throw new Error(`Expect returning a value, but all middlewares just calling next()`);
|
|
26
|
-
}
|
|
27
|
-
return middlewares[index](input, next);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
const currentCounter = createCurrentCounter();
|
|
31
|
-
const getCounter = (options) => {
|
|
32
|
-
if (!options) {
|
|
33
|
-
return currentCounter;
|
|
34
|
-
}
|
|
35
|
-
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
|
36
|
-
};
|
|
37
|
-
const run = (input, options) => getCounter(options).start(input);
|
|
38
|
-
const middleware = (input, next) => run(input, {
|
|
39
|
-
onLast: next
|
|
40
|
-
});
|
|
41
|
-
const pipeline = {
|
|
42
|
-
[PipelineSymbol]: true,
|
|
43
|
-
use,
|
|
44
|
-
run,
|
|
45
|
-
middleware
|
|
46
|
-
};
|
|
47
|
-
return pipeline;
|
|
48
|
-
};
|
|
49
|
-
const createAsyncPipeline = () => {
|
|
50
|
-
const pipeline = createPipeline();
|
|
51
|
-
return {
|
|
52
|
-
...pipeline
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
export {
|
|
56
|
-
createAsyncPipeline,
|
|
57
|
-
createContext,
|
|
58
|
-
createPipeline,
|
|
59
|
-
isPipeline
|
|
60
|
-
};
|
package/dist/esm-node/index.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
checkPlugins,
|
|
3
|
-
hasOwnProperty,
|
|
4
|
-
includePlugin,
|
|
5
|
-
isObject,
|
|
6
|
-
sortPlugins
|
|
7
|
-
} from "./shared";
|
|
8
|
-
import { DEFAULT_OPTIONS, generateRunner } from "./sync";
|
|
9
|
-
const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
|
10
|
-
const createAsyncManager = (hooks, api) => {
|
|
11
|
-
let index = 0;
|
|
12
|
-
let runners;
|
|
13
|
-
let currentHooks = {
|
|
14
|
-
...hooks
|
|
15
|
-
};
|
|
16
|
-
const useRunner = () => runners;
|
|
17
|
-
const registerHook = (extraHooks) => {
|
|
18
|
-
currentHooks = {
|
|
19
|
-
...extraHooks,
|
|
20
|
-
...currentHooks
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
const isPlugin = (input) => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
|
|
24
|
-
const pluginAPI = {
|
|
25
|
-
...api,
|
|
26
|
-
useHookRunners: useRunner
|
|
27
|
-
};
|
|
28
|
-
const clone = (overrideAPI) => {
|
|
29
|
-
let plugins = [];
|
|
30
|
-
const addPlugin = (plugin) => {
|
|
31
|
-
if (!includePlugin(plugins, plugin)) {
|
|
32
|
-
plugins.push({
|
|
33
|
-
...plugin
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const usePlugin = (...input) => {
|
|
38
|
-
input.forEach((plugin) => {
|
|
39
|
-
if (isPlugin(plugin)) {
|
|
40
|
-
addPlugin(plugin);
|
|
41
|
-
} else if (typeof plugin === "function") {
|
|
42
|
-
const options = plugin();
|
|
43
|
-
addPlugin(createPlugin(options.setup, options));
|
|
44
|
-
} else if (isObject(plugin)) {
|
|
45
|
-
addPlugin(createPlugin(plugin.setup, plugin));
|
|
46
|
-
} else if (process.env.NODE_ENV !== "production") {
|
|
47
|
-
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return manager;
|
|
51
|
-
};
|
|
52
|
-
const createPlugin = (setup = () => {
|
|
53
|
-
}, options = {}) => {
|
|
54
|
-
var _options_usePlugins;
|
|
55
|
-
if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
|
|
56
|
-
options.usePlugins.forEach((plugin) => {
|
|
57
|
-
usePlugin(createPlugin(plugin.setup, plugin));
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (options.registerHook) {
|
|
61
|
-
registerHook(options.registerHook);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
...DEFAULT_OPTIONS,
|
|
65
|
-
name: `No.${index++} plugin`,
|
|
66
|
-
...options,
|
|
67
|
-
ASYNC_PLUGIN_SYMBOL,
|
|
68
|
-
setup
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
const clear = () => {
|
|
72
|
-
plugins = [];
|
|
73
|
-
};
|
|
74
|
-
const init = async () => {
|
|
75
|
-
const sortedPlugins = sortPlugins(plugins);
|
|
76
|
-
const mergedPluginAPI = {
|
|
77
|
-
...pluginAPI,
|
|
78
|
-
...overrideAPI
|
|
79
|
-
};
|
|
80
|
-
checkPlugins(sortedPlugins);
|
|
81
|
-
const hooksList = [];
|
|
82
|
-
for (const plugin of sortedPlugins) {
|
|
83
|
-
hooksList.push(await plugin.setup(mergedPluginAPI));
|
|
84
|
-
}
|
|
85
|
-
runners = generateRunner(hooksList, currentHooks);
|
|
86
|
-
return runners;
|
|
87
|
-
};
|
|
88
|
-
const run = (cb) => cb();
|
|
89
|
-
const manager = {
|
|
90
|
-
createPlugin,
|
|
91
|
-
isPlugin,
|
|
92
|
-
usePlugin,
|
|
93
|
-
init,
|
|
94
|
-
run,
|
|
95
|
-
clear,
|
|
96
|
-
clone,
|
|
97
|
-
registerHook,
|
|
98
|
-
useRunner
|
|
99
|
-
};
|
|
100
|
-
return manager;
|
|
101
|
-
};
|
|
102
|
-
return clone();
|
|
103
|
-
};
|
|
104
|
-
export {
|
|
105
|
-
createAsyncManager
|
|
106
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { pluginDagSort } from "@modern-js/utils/universal/plugin-dag-sort";
|
|
2
|
-
const checkPlugins = (plugins) => {
|
|
3
|
-
if (process.env.NODE_ENV !== "production") {
|
|
4
|
-
plugins.forEach((origin) => {
|
|
5
|
-
origin.rivals.forEach((rival) => {
|
|
6
|
-
plugins.forEach((plugin) => {
|
|
7
|
-
if (rival === plugin.name) {
|
|
8
|
-
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
origin.required.forEach((required) => {
|
|
13
|
-
if (!plugins.some((plugin) => plugin.name === required)) {
|
|
14
|
-
throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
function sortPlugins(input) {
|
|
21
|
-
return pluginDagSort(input.slice());
|
|
22
|
-
}
|
|
23
|
-
const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
|
|
24
|
-
const isObject = (obj) => obj !== null && typeof obj === "object";
|
|
25
|
-
const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
|
|
26
|
-
export {
|
|
27
|
-
checkPlugins,
|
|
28
|
-
hasOwnProperty,
|
|
29
|
-
includePlugin,
|
|
30
|
-
isObject,
|
|
31
|
-
sortPlugins
|
|
32
|
-
};
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { createPipeline, isPipeline } from "../farrow-pipeline";
|
|
2
|
-
import { createAsyncWaterfall, createWaterfall, isAsyncWaterfall, isWaterfall } from "../waterfall";
|
|
3
|
-
import { createAsyncInterruptWorkflow, createAsyncWorkflow, createParallelWorkflow, createSyncParallelWorkflow, createWorkflow, isAsyncInterruptWorkflow, isAsyncWorkflow, isParallelWorkflow, isSyncParallelWorkflow, isWorkflow } from "../workflow";
|
|
4
|
-
import {
|
|
5
|
-
checkPlugins,
|
|
6
|
-
hasOwnProperty,
|
|
7
|
-
includePlugin,
|
|
8
|
-
isObject,
|
|
9
|
-
sortPlugins
|
|
10
|
-
} from "./shared";
|
|
11
|
-
const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
|
12
|
-
const DEFAULT_OPTIONS = {
|
|
13
|
-
name: "untitled",
|
|
14
|
-
pre: [],
|
|
15
|
-
post: [],
|
|
16
|
-
rivals: [],
|
|
17
|
-
required: [],
|
|
18
|
-
usePlugins: [],
|
|
19
|
-
registerHook: {}
|
|
20
|
-
};
|
|
21
|
-
const createManager = (hooks, api) => {
|
|
22
|
-
let index = 0;
|
|
23
|
-
let runners;
|
|
24
|
-
let currentHooks = {
|
|
25
|
-
...hooks
|
|
26
|
-
};
|
|
27
|
-
const useRunner = () => runners;
|
|
28
|
-
const registerHook = (extraHooks) => {
|
|
29
|
-
currentHooks = {
|
|
30
|
-
...extraHooks,
|
|
31
|
-
...currentHooks
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const isPlugin = (input) => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
|
35
|
-
const pluginAPI = {
|
|
36
|
-
...api,
|
|
37
|
-
useHookRunners: useRunner
|
|
38
|
-
};
|
|
39
|
-
const clone = (overrideAPI) => {
|
|
40
|
-
let plugins = [];
|
|
41
|
-
const addPlugin = (plugin) => {
|
|
42
|
-
if (!includePlugin(plugins, plugin)) {
|
|
43
|
-
plugins.push({
|
|
44
|
-
...plugin
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const usePlugin = (...input) => {
|
|
49
|
-
input.forEach((plugin) => {
|
|
50
|
-
if (isPlugin(plugin)) {
|
|
51
|
-
addPlugin(plugin);
|
|
52
|
-
} else if (typeof plugin === "function") {
|
|
53
|
-
const options = plugin();
|
|
54
|
-
addPlugin(createPlugin(options.setup, options));
|
|
55
|
-
} else if (isObject(plugin)) {
|
|
56
|
-
addPlugin(createPlugin(plugin.setup, plugin));
|
|
57
|
-
} else if (process.env.NODE_ENV !== "production") {
|
|
58
|
-
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return manager;
|
|
62
|
-
};
|
|
63
|
-
const createPlugin = (setup = () => {
|
|
64
|
-
}, options = {}) => {
|
|
65
|
-
var _options_usePlugins;
|
|
66
|
-
if ((_options_usePlugins = options.usePlugins) === null || _options_usePlugins === void 0 ? void 0 : _options_usePlugins.length) {
|
|
67
|
-
options.usePlugins.forEach((plugin) => {
|
|
68
|
-
usePlugin(createPlugin(plugin.setup, plugin));
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (options.registerHook) {
|
|
72
|
-
registerHook(options.registerHook);
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
...DEFAULT_OPTIONS,
|
|
76
|
-
name: `No.${index++} plugin`,
|
|
77
|
-
...options,
|
|
78
|
-
SYNC_PLUGIN_SYMBOL,
|
|
79
|
-
setup
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
const clear = () => {
|
|
83
|
-
plugins = [];
|
|
84
|
-
};
|
|
85
|
-
const init = () => {
|
|
86
|
-
const sortedPlugins = sortPlugins(plugins);
|
|
87
|
-
const mergedPluginAPI = {
|
|
88
|
-
...pluginAPI,
|
|
89
|
-
...overrideAPI
|
|
90
|
-
};
|
|
91
|
-
checkPlugins(sortedPlugins);
|
|
92
|
-
const hooksList = sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI));
|
|
93
|
-
runners = generateRunner(hooksList, currentHooks);
|
|
94
|
-
return runners;
|
|
95
|
-
};
|
|
96
|
-
const run = (cb) => cb();
|
|
97
|
-
const manager = {
|
|
98
|
-
createPlugin,
|
|
99
|
-
isPlugin,
|
|
100
|
-
usePlugin,
|
|
101
|
-
init,
|
|
102
|
-
clear,
|
|
103
|
-
run,
|
|
104
|
-
registerHook,
|
|
105
|
-
useRunner,
|
|
106
|
-
clone
|
|
107
|
-
};
|
|
108
|
-
return manager;
|
|
109
|
-
};
|
|
110
|
-
return clone();
|
|
111
|
-
};
|
|
112
|
-
const generateRunner = (hooksList, hooksMap) => {
|
|
113
|
-
const runner = {};
|
|
114
|
-
const cloneShape = cloneHooksMap(hooksMap);
|
|
115
|
-
if (hooksMap) {
|
|
116
|
-
for (const key in cloneShape) {
|
|
117
|
-
hooksList.forEach((hooks) => {
|
|
118
|
-
if (hooks === null || hooks === void 0 ? void 0 : hooks[key]) {
|
|
119
|
-
cloneShape[key].use(hooks[key]);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
runner[key] = (input, options) => cloneShape[key].run(input, {
|
|
123
|
-
...options
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return runner;
|
|
128
|
-
};
|
|
129
|
-
const cloneHook = (hook) => {
|
|
130
|
-
if (isWaterfall(hook)) {
|
|
131
|
-
return createWaterfall();
|
|
132
|
-
}
|
|
133
|
-
if (isAsyncWaterfall(hook)) {
|
|
134
|
-
return createAsyncWaterfall();
|
|
135
|
-
}
|
|
136
|
-
if (isWorkflow(hook)) {
|
|
137
|
-
return createWorkflow();
|
|
138
|
-
}
|
|
139
|
-
if (isAsyncWorkflow(hook)) {
|
|
140
|
-
return createAsyncWorkflow();
|
|
141
|
-
}
|
|
142
|
-
if (isParallelWorkflow(hook)) {
|
|
143
|
-
return createParallelWorkflow();
|
|
144
|
-
}
|
|
145
|
-
if (isAsyncInterruptWorkflow(hook)) {
|
|
146
|
-
return createAsyncInterruptWorkflow();
|
|
147
|
-
}
|
|
148
|
-
if (isSyncParallelWorkflow(hook)) {
|
|
149
|
-
return createSyncParallelWorkflow();
|
|
150
|
-
}
|
|
151
|
-
if (isPipeline(hook)) {
|
|
152
|
-
return createPipeline();
|
|
153
|
-
}
|
|
154
|
-
throw new Error(`Unknown hook: ${hook}`);
|
|
155
|
-
};
|
|
156
|
-
const cloneHooksMap = (record) => {
|
|
157
|
-
if (!record) {
|
|
158
|
-
return record;
|
|
159
|
-
}
|
|
160
|
-
const result = {};
|
|
161
|
-
for (const key in record) {
|
|
162
|
-
result[key] = cloneHook(record[key]);
|
|
163
|
-
}
|
|
164
|
-
return result;
|
|
165
|
-
};
|
|
166
|
-
export {
|
|
167
|
-
DEFAULT_OPTIONS,
|
|
168
|
-
cloneHook,
|
|
169
|
-
cloneHooksMap,
|
|
170
|
-
createManager,
|
|
171
|
-
generateRunner
|
|
172
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { createAsyncPipeline } from "../farrow-pipeline";
|
|
2
|
-
const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
|
|
3
|
-
const getAsyncBrook = (input) => {
|
|
4
|
-
if (typeof input === "function") {
|
|
5
|
-
return input;
|
|
6
|
-
}
|
|
7
|
-
if (input && typeof input.middleware === "function") {
|
|
8
|
-
return input.middleware;
|
|
9
|
-
}
|
|
10
|
-
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
|
11
|
-
};
|
|
12
|
-
const createAsyncWaterfall = () => {
|
|
13
|
-
const pipeline = createAsyncPipeline();
|
|
14
|
-
const use = (...input) => {
|
|
15
|
-
pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
|
|
16
|
-
return waterfall;
|
|
17
|
-
};
|
|
18
|
-
const run = (input, options) => pipeline.run(input, {
|
|
19
|
-
...options,
|
|
20
|
-
onLast: (input2) => input2
|
|
21
|
-
});
|
|
22
|
-
const middleware = (input) => {
|
|
23
|
-
return pipeline.run(input, {
|
|
24
|
-
onLast: (input2) => input2
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const waterfall = {
|
|
28
|
-
...pipeline,
|
|
29
|
-
use,
|
|
30
|
-
run,
|
|
31
|
-
middleware,
|
|
32
|
-
[ASYNC_WATERFALL_SYMBOL]: true
|
|
33
|
-
};
|
|
34
|
-
return waterfall;
|
|
35
|
-
};
|
|
36
|
-
const isAsyncWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
|
37
|
-
const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
|
|
38
|
-
export {
|
|
39
|
-
createAsyncWaterfall,
|
|
40
|
-
getAsyncBrook,
|
|
41
|
-
isAsyncWaterfall
|
|
42
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createPipeline } from "../farrow-pipeline";
|
|
2
|
-
const WATERFALL_SYMBOL = Symbol.for("MODERN_WATERFALL");
|
|
3
|
-
const getBrook = (input) => {
|
|
4
|
-
if (typeof input === "function") {
|
|
5
|
-
return input;
|
|
6
|
-
} else if (input && typeof input.middleware === "function") {
|
|
7
|
-
return input.middleware;
|
|
8
|
-
}
|
|
9
|
-
throw new Error(`${input} is not a Brook or { brook: Brook }`);
|
|
10
|
-
};
|
|
11
|
-
const createWaterfall = () => {
|
|
12
|
-
const pipeline = createPipeline();
|
|
13
|
-
const use = (...brooks) => {
|
|
14
|
-
pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
|
|
15
|
-
return waterfall;
|
|
16
|
-
};
|
|
17
|
-
const run = (input, options) => pipeline.run(input, {
|
|
18
|
-
...options,
|
|
19
|
-
onLast: (input2) => input2
|
|
20
|
-
});
|
|
21
|
-
const middleware = (input) => {
|
|
22
|
-
return pipeline.run(input, {
|
|
23
|
-
onLast: (input2) => input2
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
const waterfall = {
|
|
27
|
-
...pipeline,
|
|
28
|
-
use,
|
|
29
|
-
run,
|
|
30
|
-
middleware,
|
|
31
|
-
[WATERFALL_SYMBOL]: true
|
|
32
|
-
};
|
|
33
|
-
return waterfall;
|
|
34
|
-
};
|
|
35
|
-
const isWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
|
36
|
-
const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
|
|
37
|
-
export {
|
|
38
|
-
createWaterfall,
|
|
39
|
-
getBrook,
|
|
40
|
-
isWaterfall
|
|
41
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createAsyncPipeline } from "../farrow-pipeline";
|
|
2
|
-
const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
|
|
3
|
-
const isPromise = (obj) => obj && typeof obj.then === "function";
|
|
4
|
-
const isAsyncWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
|
5
|
-
const createAsyncWorkflow = () => {
|
|
6
|
-
const pipeline = createAsyncPipeline();
|
|
7
|
-
const use = (...input) => {
|
|
8
|
-
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
|
9
|
-
return workflow;
|
|
10
|
-
};
|
|
11
|
-
const run = (input) => {
|
|
12
|
-
const result = pipeline.run(input, {
|
|
13
|
-
onLast: () => []
|
|
14
|
-
});
|
|
15
|
-
if (isPromise(result)) {
|
|
16
|
-
return result.then((result2) => result2.filter(Boolean));
|
|
17
|
-
}
|
|
18
|
-
return result.filter(Boolean);
|
|
19
|
-
};
|
|
20
|
-
const workflow = {
|
|
21
|
-
...pipeline,
|
|
22
|
-
use,
|
|
23
|
-
run,
|
|
24
|
-
[ASYNC_WORKFLOW_SYMBOL]: true
|
|
25
|
-
};
|
|
26
|
-
return workflow;
|
|
27
|
-
};
|
|
28
|
-
const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.resolve(worker(input)).then((result) => Promise.resolve(next(input)).then((nextResult) => [
|
|
29
|
-
result,
|
|
30
|
-
...nextResult
|
|
31
|
-
]));
|
|
32
|
-
export {
|
|
33
|
-
createAsyncWorkflow,
|
|
34
|
-
isAsyncWorkflow
|
|
35
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createAsyncPipeline } from "../farrow-pipeline";
|
|
2
|
-
const ASYNC_INTERRUPT_WORKFLOW_SYMBOL = Symbol.for("ASYNC_INTERRUPT_WORKFLOW_SYMBOL");
|
|
3
|
-
const isAsyncInterruptWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_INTERRUPT_WORKFLOW_SYMBOL]);
|
|
4
|
-
const createAsyncInterruptWorkflow = () => {
|
|
5
|
-
const pipeline = createAsyncPipeline();
|
|
6
|
-
const use = (...input) => {
|
|
7
|
-
pipeline.use(...input.map(mapAsyncWorkerToInterruptMiddleware));
|
|
8
|
-
return workflow;
|
|
9
|
-
};
|
|
10
|
-
const run = async (input) => {
|
|
11
|
-
const result = await pipeline.run(input, {
|
|
12
|
-
onLast: () => []
|
|
13
|
-
});
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
const workflow = {
|
|
17
|
-
...pipeline,
|
|
18
|
-
use,
|
|
19
|
-
run,
|
|
20
|
-
[ASYNC_INTERRUPT_WORKFLOW_SYMBOL]: true
|
|
21
|
-
};
|
|
22
|
-
return workflow;
|
|
23
|
-
};
|
|
24
|
-
const mapAsyncWorkerToInterruptMiddleware = (worker) => async (input, next) => {
|
|
25
|
-
let isInterrupted = false;
|
|
26
|
-
const interrupt = (value) => {
|
|
27
|
-
isInterrupted = true;
|
|
28
|
-
return value;
|
|
29
|
-
};
|
|
30
|
-
const result = await Promise.resolve(worker(input, interrupt));
|
|
31
|
-
if (isInterrupted) {
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
return Promise.resolve(next(input));
|
|
35
|
-
};
|
|
36
|
-
export {
|
|
37
|
-
createAsyncInterruptWorkflow,
|
|
38
|
-
isAsyncInterruptWorkflow
|
|
39
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { createPipeline } from "../farrow-pipeline";
|
|
2
|
-
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
|
|
3
|
-
const isParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
|
4
|
-
const createParallelWorkflow = () => {
|
|
5
|
-
const pipeline = createPipeline();
|
|
6
|
-
const use = (...input) => {
|
|
7
|
-
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
|
8
|
-
return workflow;
|
|
9
|
-
};
|
|
10
|
-
const run = (input) => Promise.all(pipeline.run(input, {
|
|
11
|
-
onLast: () => []
|
|
12
|
-
})).then((result) => result.filter(Boolean));
|
|
13
|
-
const workflow = {
|
|
14
|
-
...pipeline,
|
|
15
|
-
run,
|
|
16
|
-
use,
|
|
17
|
-
[PARALLEL_WORKFLOW_SYMBOL]: true
|
|
18
|
-
};
|
|
19
|
-
return workflow;
|
|
20
|
-
};
|
|
21
|
-
const mapParallelWorkerToAsyncMiddleware = (worker) => (input, next) => [
|
|
22
|
-
worker(input),
|
|
23
|
-
...next(input)
|
|
24
|
-
];
|
|
25
|
-
export {
|
|
26
|
-
createParallelWorkflow,
|
|
27
|
-
isParallelWorkflow
|
|
28
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createPipeline } from "../farrow-pipeline";
|
|
2
|
-
const WORKFLOW_SYMBOL = Symbol.for("MODERN_WORKFLOW");
|
|
3
|
-
const createWorkflow = () => {
|
|
4
|
-
const pipeline = createPipeline();
|
|
5
|
-
const use = (...input) => {
|
|
6
|
-
pipeline.use(...input.map(mapWorkerToMiddleware));
|
|
7
|
-
return workflow;
|
|
8
|
-
};
|
|
9
|
-
const run = (input) => {
|
|
10
|
-
const result = pipeline.run(input, {
|
|
11
|
-
onLast: () => []
|
|
12
|
-
});
|
|
13
|
-
return result.filter(Boolean);
|
|
14
|
-
};
|
|
15
|
-
const workflow = {
|
|
16
|
-
...pipeline,
|
|
17
|
-
use,
|
|
18
|
-
run,
|
|
19
|
-
[WORKFLOW_SYMBOL]: true
|
|
20
|
-
};
|
|
21
|
-
return workflow;
|
|
22
|
-
};
|
|
23
|
-
const isWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
|
24
|
-
const mapWorkerToMiddleware = (worker) => (input, next) => [
|
|
25
|
-
worker(input),
|
|
26
|
-
...next(input)
|
|
27
|
-
];
|
|
28
|
-
export {
|
|
29
|
-
createWorkflow,
|
|
30
|
-
isWorkflow
|
|
31
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createPipeline } from "../farrow-pipeline";
|
|
2
|
-
const SYNC_PARALLEL_WORKFLOW_SYMBOL = Symbol.for("SYNC_MODERN_PARALLEL_WORKFLOW");
|
|
3
|
-
const isSyncParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[SYNC_PARALLEL_WORKFLOW_SYMBOL]);
|
|
4
|
-
const createSyncParallelWorkflow = () => {
|
|
5
|
-
const pipeline = createPipeline();
|
|
6
|
-
const use = (...input) => {
|
|
7
|
-
pipeline.use(...input.map(mapSyncParallelWorkerToMiddleware));
|
|
8
|
-
return workflow;
|
|
9
|
-
};
|
|
10
|
-
const run = (input) => {
|
|
11
|
-
return pipeline.run(input, {
|
|
12
|
-
onLast: () => []
|
|
13
|
-
}).filter((result) => Boolean(result));
|
|
14
|
-
};
|
|
15
|
-
const workflow = {
|
|
16
|
-
...pipeline,
|
|
17
|
-
run,
|
|
18
|
-
use,
|
|
19
|
-
[SYNC_PARALLEL_WORKFLOW_SYMBOL]: true
|
|
20
|
-
};
|
|
21
|
-
return workflow;
|
|
22
|
-
};
|
|
23
|
-
const mapSyncParallelWorkerToMiddleware = (worker) => (input, next) => [
|
|
24
|
-
worker(input),
|
|
25
|
-
...next(input)
|
|
26
|
-
];
|
|
27
|
-
export {
|
|
28
|
-
createSyncParallelWorkflow,
|
|
29
|
-
isSyncParallelWorkflow
|
|
30
|
-
};
|
|
@@ -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
|
-
export type Context<T = any> = {
|
|
6
|
-
use: () => {
|
|
7
|
-
value: T;
|
|
8
|
-
};
|
|
9
|
-
get: () => T;
|
|
10
|
-
set: (value: T) => void;
|
|
11
|
-
};
|
|
12
|
-
export declare const createContext: <T>(value: T) => Context<T>;
|