@modern-js/plugin 2.4.0 → 2.5.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 +11 -0
- package/dist/{js/node → cjs}/farrow-pipeline/context.js +0 -0
- package/dist/{js/node → cjs}/farrow-pipeline/counter.js +0 -0
- package/dist/{js/node → cjs}/farrow-pipeline/index.js +0 -0
- package/dist/{js/node → cjs}/farrow-pipeline/pipeline.js +1 -15
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/manager/async.js +21 -50
- package/dist/{js/node → cjs}/manager/index.js +0 -0
- package/dist/{js/node → cjs}/manager/shared.js +0 -0
- package/dist/{js/node → cjs}/manager/sync.js +21 -28
- package/dist/{js/node → cjs}/manager/types.js +0 -0
- package/dist/{js/node → cjs}/utils/pluginDagSort.js +0 -0
- package/dist/{js/node → cjs}/waterfall/async.js +5 -43
- package/dist/{js/node → cjs}/waterfall/index.js +0 -0
- package/dist/{js/node → cjs}/waterfall/sync.js +4 -20
- package/dist/{js/node → cjs}/workflow/async.js +6 -44
- package/dist/{js/node → cjs}/workflow/index.js +0 -0
- package/dist/{js/node → cjs}/workflow/parallel.js +6 -44
- package/dist/{js/node → cjs}/workflow/sync.js +3 -19
- package/dist/{js/treeshaking → esm}/farrow-pipeline/context.js +0 -0
- package/dist/{js/treeshaking → esm}/farrow-pipeline/counter.js +0 -0
- package/dist/{js/treeshaking → esm}/farrow-pipeline/index.js +0 -0
- package/dist/{js/treeshaking → esm}/farrow-pipeline/pipeline.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/manager/async.js +2 -2
- package/dist/{js/treeshaking → esm}/manager/index.js +0 -0
- package/dist/{js/treeshaking → esm}/manager/shared.js +0 -0
- package/dist/{js/treeshaking → esm}/manager/sync.js +2 -2
- package/dist/{js/treeshaking → esm}/manager/types.js +0 -0
- package/dist/{js/treeshaking → esm}/utils/pluginDagSort.js +0 -0
- package/dist/{js/treeshaking → esm}/waterfall/async.js +0 -0
- package/dist/{js/treeshaking → esm}/waterfall/index.js +0 -0
- package/dist/{js/treeshaking → esm}/waterfall/sync.js +0 -0
- package/dist/{js/treeshaking → esm}/workflow/async.js +0 -0
- package/dist/{js/treeshaking → esm}/workflow/index.js +0 -0
- package/dist/{js/treeshaking → esm}/workflow/parallel.js +0 -0
- package/dist/{js/treeshaking → esm}/workflow/sync.js +0 -0
- package/dist/{js/modern → esm-node}/farrow-pipeline/context.js +0 -0
- package/dist/{js/modern → esm-node}/farrow-pipeline/counter.js +0 -0
- package/dist/{js/modern → esm-node}/farrow-pipeline/index.js +0 -0
- package/dist/{js/modern → esm-node}/farrow-pipeline/pipeline.js +1 -17
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/{js/modern → esm-node}/manager/async.js +21 -52
- package/dist/{js/modern → esm-node}/manager/index.js +0 -0
- package/dist/{js/modern → esm-node}/manager/shared.js +0 -0
- package/dist/{js/modern → esm-node}/manager/sync.js +21 -30
- package/dist/{js/modern → esm-node}/manager/types.js +0 -0
- package/dist/{js/modern → esm-node}/utils/pluginDagSort.js +0 -0
- package/dist/esm-node/waterfall/async.js +40 -0
- package/dist/{js/modern → esm-node}/waterfall/index.js +0 -0
- package/dist/esm-node/waterfall/sync.js +36 -0
- package/dist/esm-node/workflow/async.js +35 -0
- package/dist/{js/modern → esm-node}/workflow/index.js +0 -0
- package/dist/esm-node/workflow/parallel.js +25 -0
- package/dist/esm-node/workflow/sync.js +26 -0
- package/package.json +8 -9
- package/dist/js/modern/waterfall/async.js +0 -80
- package/dist/js/modern/waterfall/sync.js +0 -54
- package/dist/js/modern/workflow/async.js +0 -75
- package/dist/js/modern/workflow/parallel.js +0 -65
- package/dist/js/modern/workflow/sync.js +0 -44
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,19 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
-
var __spreadValues = (a, b) => {
|
7
|
-
for (var prop in b || (b = {}))
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
10
|
-
if (__getOwnPropSymbols)
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
-
if (__propIsEnum.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
}
|
15
|
-
return a;
|
16
|
-
};
|
17
1
|
import { createContext } from "./context";
|
18
2
|
import { createCounter } from "./counter";
|
19
3
|
const isPipeline = (input) => Boolean(input == null ? void 0 : input[PipelineSymbol]);
|
@@ -66,7 +50,7 @@ const createPipeline = () => {
|
|
66
50
|
};
|
67
51
|
const createAsyncPipeline = () => {
|
68
52
|
const pipeline = createPipeline();
|
69
|
-
return
|
53
|
+
return { ...pipeline };
|
70
54
|
};
|
71
55
|
export {
|
72
56
|
createAsyncPipeline,
|
File without changes
|
@@ -1,42 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
21
|
-
return new Promise((resolve, reject) => {
|
22
|
-
var fulfilled = (value) => {
|
23
|
-
try {
|
24
|
-
step(generator.next(value));
|
25
|
-
} catch (e) {
|
26
|
-
reject(e);
|
27
|
-
}
|
28
|
-
};
|
29
|
-
var rejected = (value) => {
|
30
|
-
try {
|
31
|
-
step(generator.throw(value));
|
32
|
-
} catch (e) {
|
33
|
-
reject(e);
|
34
|
-
}
|
35
|
-
};
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
38
|
-
});
|
39
|
-
};
|
40
1
|
import { generateRunner, DEFAULT_OPTIONS } from "./sync";
|
41
2
|
import {
|
42
3
|
checkPlugins,
|
@@ -49,20 +10,24 @@ const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
|
49
10
|
const createAsyncManager = (hooks, api) => {
|
50
11
|
let index = 0;
|
51
12
|
let runners;
|
52
|
-
let currentHooks =
|
13
|
+
let currentHooks = { ...hooks };
|
53
14
|
const useRunner = () => runners;
|
54
15
|
const registerHook = (extraHooks) => {
|
55
|
-
currentHooks =
|
16
|
+
currentHooks = {
|
17
|
+
...extraHooks,
|
18
|
+
...currentHooks
|
19
|
+
};
|
56
20
|
};
|
57
21
|
const isPlugin = (input) => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
|
58
|
-
const pluginAPI =
|
22
|
+
const pluginAPI = {
|
23
|
+
...api,
|
59
24
|
useHookRunners: useRunner
|
60
|
-
}
|
25
|
+
};
|
61
26
|
const clone = (overrideAPI) => {
|
62
27
|
let plugins = [];
|
63
28
|
const addPlugin = (plugin) => {
|
64
29
|
if (!includePlugin(plugins, plugin)) {
|
65
|
-
plugins.push(
|
30
|
+
plugins.push({ ...plugin });
|
66
31
|
}
|
67
32
|
};
|
68
33
|
const usePlugin = (...input) => {
|
@@ -91,26 +56,30 @@ const createAsyncManager = (hooks, api) => {
|
|
91
56
|
if (options.registerHook) {
|
92
57
|
registerHook(options.registerHook);
|
93
58
|
}
|
94
|
-
return
|
95
|
-
|
96
|
-
|
59
|
+
return {
|
60
|
+
...DEFAULT_OPTIONS,
|
61
|
+
name: `No.${index++} plugin`,
|
62
|
+
...options,
|
97
63
|
ASYNC_PLUGIN_SYMBOL,
|
98
64
|
setup
|
99
|
-
}
|
65
|
+
};
|
100
66
|
};
|
101
67
|
const clear = () => {
|
102
68
|
plugins = [];
|
103
69
|
};
|
104
|
-
const init = () =>
|
70
|
+
const init = async () => {
|
105
71
|
const sortedPlugins = sortPlugins(plugins);
|
106
|
-
const mergedPluginAPI =
|
72
|
+
const mergedPluginAPI = {
|
73
|
+
...pluginAPI,
|
74
|
+
...overrideAPI
|
75
|
+
};
|
107
76
|
checkPlugins(sortedPlugins);
|
108
|
-
const hooksList =
|
77
|
+
const hooksList = await Promise.all(
|
109
78
|
sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))
|
110
79
|
);
|
111
80
|
runners = generateRunner(hooksList, currentHooks);
|
112
81
|
return runners;
|
113
|
-
}
|
82
|
+
};
|
114
83
|
const run = (cb) => cb();
|
115
84
|
const manager = {
|
116
85
|
createPlugin,
|
File without changes
|
File without changes
|
@@ -1,22 +1,3 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
1
|
import { isPipeline, createPipeline } from "../farrow-pipeline";
|
21
2
|
import {
|
22
3
|
isWaterfall,
|
@@ -52,20 +33,24 @@ const DEFAULT_OPTIONS = {
|
|
52
33
|
const createManager = (hooks, api) => {
|
53
34
|
let index = 0;
|
54
35
|
let runners;
|
55
|
-
let currentHooks =
|
36
|
+
let currentHooks = { ...hooks };
|
56
37
|
const useRunner = () => runners;
|
57
38
|
const registerHook = (extraHooks) => {
|
58
|
-
currentHooks =
|
39
|
+
currentHooks = {
|
40
|
+
...extraHooks,
|
41
|
+
...currentHooks
|
42
|
+
};
|
59
43
|
};
|
60
44
|
const isPlugin = (input) => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
61
|
-
const pluginAPI =
|
45
|
+
const pluginAPI = {
|
46
|
+
...api,
|
62
47
|
useHookRunners: useRunner
|
63
|
-
}
|
48
|
+
};
|
64
49
|
const clone = (overrideAPI) => {
|
65
50
|
let plugins = [];
|
66
51
|
const addPlugin = (plugin) => {
|
67
52
|
if (!includePlugin(plugins, plugin)) {
|
68
|
-
plugins.push(
|
53
|
+
plugins.push({ ...plugin });
|
69
54
|
}
|
70
55
|
};
|
71
56
|
const usePlugin = (...input) => {
|
@@ -94,19 +79,23 @@ const createManager = (hooks, api) => {
|
|
94
79
|
if (options.registerHook) {
|
95
80
|
registerHook(options.registerHook);
|
96
81
|
}
|
97
|
-
return
|
98
|
-
|
99
|
-
|
82
|
+
return {
|
83
|
+
...DEFAULT_OPTIONS,
|
84
|
+
name: `No.${index++} plugin`,
|
85
|
+
...options,
|
100
86
|
SYNC_PLUGIN_SYMBOL,
|
101
87
|
setup
|
102
|
-
}
|
88
|
+
};
|
103
89
|
};
|
104
90
|
const clear = () => {
|
105
91
|
plugins = [];
|
106
92
|
};
|
107
93
|
const init = () => {
|
108
94
|
const sortedPlugins = sortPlugins(plugins);
|
109
|
-
const mergedPluginAPI =
|
95
|
+
const mergedPluginAPI = {
|
96
|
+
...pluginAPI,
|
97
|
+
...overrideAPI
|
98
|
+
};
|
110
99
|
checkPlugins(sortedPlugins);
|
111
100
|
const hooksList = sortedPlugins.map(
|
112
101
|
(plugin) => plugin.setup(mergedPluginAPI)
|
@@ -143,7 +132,9 @@ const generateRunner = (hooksList, hooksMap) => {
|
|
143
132
|
cloneShape[key].use(hooks[key]);
|
144
133
|
}
|
145
134
|
}
|
146
|
-
runner[key] = (input, options) => cloneShape[key].run(input,
|
135
|
+
runner[key] = (input, options) => cloneShape[key].run(input, {
|
136
|
+
...options
|
137
|
+
});
|
147
138
|
}
|
148
139
|
}
|
149
140
|
return runner;
|
File without changes
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import {
|
2
|
+
createAsyncPipeline
|
3
|
+
} from "../farrow-pipeline";
|
4
|
+
const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
|
5
|
+
const getAsyncBrook = (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 AsyncBrook or { brook: AsyncBrook }`);
|
12
|
+
};
|
13
|
+
const createAsyncWaterfall = () => {
|
14
|
+
const pipeline = createAsyncPipeline();
|
15
|
+
const use = (...input) => {
|
16
|
+
pipeline.use(
|
17
|
+
...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware)
|
18
|
+
);
|
19
|
+
return waterfall;
|
20
|
+
};
|
21
|
+
const run = (input, options) => pipeline.run(input, { ...options, onLast: (input2) => input2 });
|
22
|
+
const middleware = (input) => {
|
23
|
+
return pipeline.run(input, { onLast: (input2) => input2 });
|
24
|
+
};
|
25
|
+
const waterfall = {
|
26
|
+
...pipeline,
|
27
|
+
use,
|
28
|
+
run,
|
29
|
+
middleware,
|
30
|
+
[ASYNC_WATERFALL_SYMBOL]: true
|
31
|
+
};
|
32
|
+
return waterfall;
|
33
|
+
};
|
34
|
+
const isAsyncWaterfall = (input) => Boolean(input == null ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
35
|
+
const mapAsyncBrookToAsyncMiddleware = (brook) => async (input, next) => next(await brook(input));
|
36
|
+
export {
|
37
|
+
createAsyncWaterfall,
|
38
|
+
getAsyncBrook,
|
39
|
+
isAsyncWaterfall
|
40
|
+
};
|
File without changes
|
@@ -0,0 +1,36 @@
|
|
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, { ...options, onLast: (input2) => input2 });
|
18
|
+
const middleware = (input) => {
|
19
|
+
return pipeline.run(input, { onLast: (input2) => input2 });
|
20
|
+
};
|
21
|
+
const waterfall = {
|
22
|
+
...pipeline,
|
23
|
+
use,
|
24
|
+
run,
|
25
|
+
middleware,
|
26
|
+
[WATERFALL_SYMBOL]: true
|
27
|
+
};
|
28
|
+
return waterfall;
|
29
|
+
};
|
30
|
+
const isWaterfall = (input) => Boolean(input == null ? void 0 : input[WATERFALL_SYMBOL]);
|
31
|
+
const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
|
32
|
+
export {
|
33
|
+
createWaterfall,
|
34
|
+
getBrook,
|
35
|
+
isWaterfall
|
36
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import {
|
2
|
+
createAsyncPipeline
|
3
|
+
} from "../farrow-pipeline";
|
4
|
+
const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
|
5
|
+
const isAsyncWorkflow = (input) => Boolean(input == null ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
6
|
+
const createAsyncWorkflow = () => {
|
7
|
+
const pipeline = createAsyncPipeline();
|
8
|
+
const use = (...input) => {
|
9
|
+
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
10
|
+
return workflow;
|
11
|
+
};
|
12
|
+
const run = async (input) => {
|
13
|
+
const result = pipeline.run(input, { onLast: () => [] });
|
14
|
+
if (isPromise(result)) {
|
15
|
+
return result.then((result2) => result2.filter(Boolean));
|
16
|
+
} else {
|
17
|
+
return result.filter(Boolean);
|
18
|
+
}
|
19
|
+
};
|
20
|
+
const workflow = {
|
21
|
+
...pipeline,
|
22
|
+
use,
|
23
|
+
run,
|
24
|
+
[ASYNC_WORKFLOW_SYMBOL]: true
|
25
|
+
};
|
26
|
+
return workflow;
|
27
|
+
};
|
28
|
+
const mapAsyncWorkerToAsyncMiddleware = (worker) => async (input, next) => [await worker(input), ...await next(input)];
|
29
|
+
function isPromise(obj) {
|
30
|
+
return Boolean(obj) && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
|
31
|
+
}
|
32
|
+
export {
|
33
|
+
createAsyncWorkflow,
|
34
|
+
isAsyncWorkflow
|
35
|
+
};
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { createPipeline } from "../farrow-pipeline";
|
2
|
+
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
|
3
|
+
const isParallelWorkflow = (input) => Boolean(input == null ? 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 = async (input) => Promise.all(pipeline.run(input, { onLast: () => [] })).then(
|
11
|
+
(result) => result.filter(Boolean)
|
12
|
+
);
|
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) => [worker(input), ...next(input)];
|
22
|
+
export {
|
23
|
+
createParallelWorkflow,
|
24
|
+
isParallelWorkflow
|
25
|
+
};
|
@@ -0,0 +1,26 @@
|
|
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, { onLast: () => [] });
|
11
|
+
return result.filter(Boolean);
|
12
|
+
};
|
13
|
+
const workflow = {
|
14
|
+
...pipeline,
|
15
|
+
use,
|
16
|
+
run,
|
17
|
+
[WORKFLOW_SYMBOL]: true
|
18
|
+
};
|
19
|
+
return workflow;
|
20
|
+
};
|
21
|
+
const isWorkflow = (input) => Boolean(input == null ? void 0 : input[WORKFLOW_SYMBOL]);
|
22
|
+
const mapWorkerToMiddleware = (worker) => (input, next) => [worker(input), ...next(input)];
|
23
|
+
export {
|
24
|
+
createWorkflow,
|
25
|
+
isWorkflow
|
26
|
+
};
|
package/package.json
CHANGED
@@ -11,21 +11,20 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.
|
14
|
+
"version": "2.5.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
|
-
"main": "./dist/
|
18
|
-
"module": "./dist/
|
19
|
-
"jsnext:modern": "./dist/js/modern/index.js",
|
17
|
+
"main": "./dist/cjs/index.js",
|
18
|
+
"module": "./dist/esm/index.js",
|
20
19
|
"exports": {
|
21
20
|
".": {
|
22
21
|
"node": {
|
23
22
|
"jsnext:source": "./src/index.ts",
|
24
|
-
"import": "./dist/
|
25
|
-
"require": "./dist/
|
23
|
+
"import": "./dist/esm-node/index.js",
|
24
|
+
"require": "./dist/cjs/index.js"
|
26
25
|
},
|
27
26
|
"types": "./dist/types/index.d.ts",
|
28
|
-
"default": "./dist/
|
27
|
+
"default": "./dist/esm/index.js"
|
29
28
|
}
|
30
29
|
},
|
31
30
|
"dependencies": {
|
@@ -36,8 +35,8 @@
|
|
36
35
|
"@types/node": "^14",
|
37
36
|
"typescript": "^4",
|
38
37
|
"jest": "^27",
|
39
|
-
"@scripts/build": "2.
|
40
|
-
"@scripts/jest-config": "2.
|
38
|
+
"@scripts/build": "2.5.0",
|
39
|
+
"@scripts/jest-config": "2.5.0"
|
41
40
|
},
|
42
41
|
"sideEffects": false,
|
43
42
|
"publishConfig": {
|
@@ -1,80 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
21
|
-
return new Promise((resolve, reject) => {
|
22
|
-
var fulfilled = (value) => {
|
23
|
-
try {
|
24
|
-
step(generator.next(value));
|
25
|
-
} catch (e) {
|
26
|
-
reject(e);
|
27
|
-
}
|
28
|
-
};
|
29
|
-
var rejected = (value) => {
|
30
|
-
try {
|
31
|
-
step(generator.throw(value));
|
32
|
-
} catch (e) {
|
33
|
-
reject(e);
|
34
|
-
}
|
35
|
-
};
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
38
|
-
});
|
39
|
-
};
|
40
|
-
import {
|
41
|
-
createAsyncPipeline
|
42
|
-
} from "../farrow-pipeline";
|
43
|
-
const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
|
44
|
-
const getAsyncBrook = (input) => {
|
45
|
-
if (typeof input === "function") {
|
46
|
-
return input;
|
47
|
-
} else if (input && typeof input.middleware === "function") {
|
48
|
-
return input.middleware;
|
49
|
-
}
|
50
|
-
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
51
|
-
};
|
52
|
-
const createAsyncWaterfall = () => {
|
53
|
-
const pipeline = createAsyncPipeline();
|
54
|
-
const use = (...input) => {
|
55
|
-
pipeline.use(
|
56
|
-
...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware)
|
57
|
-
);
|
58
|
-
return waterfall;
|
59
|
-
};
|
60
|
-
const run = (input, options) => pipeline.run(input, __spreadProps(__spreadValues({}, options), { onLast: (input2) => input2 }));
|
61
|
-
const middleware = (input) => {
|
62
|
-
return pipeline.run(input, { onLast: (input2) => input2 });
|
63
|
-
};
|
64
|
-
const waterfall = __spreadProps(__spreadValues({}, pipeline), {
|
65
|
-
use,
|
66
|
-
run,
|
67
|
-
middleware,
|
68
|
-
[ASYNC_WATERFALL_SYMBOL]: true
|
69
|
-
});
|
70
|
-
return waterfall;
|
71
|
-
};
|
72
|
-
const isAsyncWaterfall = (input) => Boolean(input == null ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
73
|
-
const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => __async(void 0, null, function* () {
|
74
|
-
return next(yield brook(input));
|
75
|
-
});
|
76
|
-
export {
|
77
|
-
createAsyncWaterfall,
|
78
|
-
getAsyncBrook,
|
79
|
-
isAsyncWaterfall
|
80
|
-
};
|
@@ -1,54 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __defProps = Object.defineProperties;
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
|
-
import { createPipeline } from "../farrow-pipeline";
|
21
|
-
const WATERFALL_SYMBOL = Symbol.for("MODERN_WATERFALL");
|
22
|
-
const getBrook = (input) => {
|
23
|
-
if (typeof input === "function") {
|
24
|
-
return input;
|
25
|
-
} else if (input && typeof input.middleware === "function") {
|
26
|
-
return input.middleware;
|
27
|
-
}
|
28
|
-
throw new Error(`${input} is not a Brook or { brook: Brook }`);
|
29
|
-
};
|
30
|
-
const createWaterfall = () => {
|
31
|
-
const pipeline = createPipeline();
|
32
|
-
const use = (...brooks) => {
|
33
|
-
pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
|
34
|
-
return waterfall;
|
35
|
-
};
|
36
|
-
const run = (input, options) => pipeline.run(input, __spreadProps(__spreadValues({}, options), { onLast: (input2) => input2 }));
|
37
|
-
const middleware = (input) => {
|
38
|
-
return pipeline.run(input, { onLast: (input2) => input2 });
|
39
|
-
};
|
40
|
-
const waterfall = __spreadProps(__spreadValues({}, pipeline), {
|
41
|
-
use,
|
42
|
-
run,
|
43
|
-
middleware,
|
44
|
-
[WATERFALL_SYMBOL]: true
|
45
|
-
});
|
46
|
-
return waterfall;
|
47
|
-
};
|
48
|
-
const isWaterfall = (input) => Boolean(input == null ? void 0 : input[WATERFALL_SYMBOL]);
|
49
|
-
const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
|
50
|
-
export {
|
51
|
-
createWaterfall,
|
52
|
-
getBrook,
|
53
|
-
isWaterfall
|
54
|
-
};
|