@modern-js/plugin 2.0.0-beta.0 → 2.0.0-beta.2
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 +28 -0
- package/dist/js/modern/farrow-pipeline/context.js +1 -8
- package/dist/js/modern/farrow-pipeline/counter.js +1 -3
- package/dist/js/modern/farrow-pipeline/pipeline.js +0 -16
- package/dist/js/modern/manager/async.js +8 -27
- package/dist/js/modern/manager/shared.js +3 -23
- package/dist/js/modern/manager/sync.js +10 -41
- package/dist/js/modern/utils/pluginDagSort.js +48 -0
- package/dist/js/modern/waterfall/async.js +0 -10
- package/dist/js/modern/waterfall/sync.js +0 -10
- package/dist/js/modern/workflow/async.js +0 -10
- package/dist/js/modern/workflow/parallel.js +0 -8
- package/dist/js/modern/workflow/sync.js +0 -8
- package/dist/js/node/farrow-pipeline/context.js +1 -10
- package/dist/js/node/farrow-pipeline/counter.js +1 -5
- package/dist/js/node/farrow-pipeline/index.js +0 -2
- package/dist/js/node/farrow-pipeline/pipeline.js +0 -23
- package/dist/js/node/index.js +0 -8
- package/dist/js/node/manager/async.js +8 -32
- package/dist/js/node/manager/index.js +0 -6
- package/dist/js/node/manager/shared.js +3 -32
- package/dist/js/node/manager/sync.js +10 -54
- package/dist/js/node/utils/pluginDagSort.js +55 -0
- package/dist/js/node/waterfall/async.js +0 -18
- package/dist/js/node/waterfall/index.js +0 -4
- package/dist/js/node/waterfall/sync.js +0 -18
- package/dist/js/node/workflow/async.js +0 -16
- package/dist/js/node/workflow/index.js +0 -6
- package/dist/js/node/workflow/parallel.js +0 -14
- package/dist/js/node/workflow/sync.js +0 -14
- package/dist/js/treeshaking/farrow-pipeline/context.js +1 -8
- package/dist/js/treeshaking/farrow-pipeline/counter.js +1 -3
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +0 -16
- package/dist/js/treeshaking/manager/async.js +6 -28
- package/dist/js/treeshaking/manager/shared.js +2 -46
- package/dist/js/treeshaking/manager/sync.js +9 -44
- package/dist/js/treeshaking/utils/pluginDagSort.js +74 -0
- package/dist/js/treeshaking/waterfall/async.js +0 -11
- package/dist/js/treeshaking/waterfall/sync.js +0 -8
- package/dist/js/treeshaking/workflow/async.js +0 -16
- package/dist/js/treeshaking/workflow/parallel.js +0 -8
- package/dist/js/treeshaking/workflow/sync.js +0 -6
- package/dist/types/manager/async.d.ts +0 -9
- package/dist/types/manager/sync.d.ts +0 -9
- package/dist/types/manager/types.d.ts +2 -9
- package/dist/types/utils/pluginDagSort.d.ts +1 -0
- package/package.json +6 -6
@@ -1,6 +1,5 @@
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
2
|
-
import
|
3
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
2
|
+
import { dagSort } from "../utils/pluginDagSort";
|
4
3
|
export var checkPlugins = function checkPlugins(plugins) {
|
5
4
|
plugins.forEach(function (origin) {
|
6
5
|
origin.rivals.forEach(function (rival) {
|
@@ -21,50 +20,7 @@ export var checkPlugins = function checkPlugins(plugins) {
|
|
21
20
|
};
|
22
21
|
export function sortPlugins(input) {
|
23
22
|
var plugins = input.slice();
|
24
|
-
|
25
|
-
for (var i = 0; i < plugins.length; i++) {
|
26
|
-
var plugin = plugins[i];
|
27
|
-
|
28
|
-
var _iterator = _createForOfIteratorHelper(plugin.pre),
|
29
|
-
_step;
|
30
|
-
|
31
|
-
try {
|
32
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
33
|
-
var pre = _step.value;
|
34
|
-
|
35
|
-
for (var j = i + 1; j < plugins.length; j++) {
|
36
|
-
if (plugins[j].name === pre) {
|
37
|
-
plugins = [].concat(_toConsumableArray(plugins.slice(0, i)), [plugins[j]], _toConsumableArray(plugins.slice(i, j)), _toConsumableArray(plugins.slice(j + 1, plugins.length)));
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
} catch (err) {
|
42
|
-
_iterator.e(err);
|
43
|
-
} finally {
|
44
|
-
_iterator.f();
|
45
|
-
}
|
46
|
-
|
47
|
-
var _iterator2 = _createForOfIteratorHelper(plugin.post),
|
48
|
-
_step2;
|
49
|
-
|
50
|
-
try {
|
51
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
52
|
-
var post = _step2.value;
|
53
|
-
|
54
|
-
for (var _j = 0; _j < i; _j++) {
|
55
|
-
if (plugins[_j].name === post) {
|
56
|
-
plugins = [].concat(_toConsumableArray(plugins.slice(0, _j)), _toConsumableArray(plugins.slice(_j + 1, i + 1)), [plugins[_j]], _toConsumableArray(plugins.slice(i + 1, plugins.length)));
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
} catch (err) {
|
61
|
-
_iterator2.e(err);
|
62
|
-
} finally {
|
63
|
-
_iterator2.f();
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
return plugins;
|
23
|
+
return dagSort(plugins);
|
68
24
|
}
|
69
25
|
export var includePlugin = function includePlugin(plugins, input) {
|
70
26
|
return plugins.some(function (plugin) {
|
@@ -17,75 +17,63 @@ export var DEFAULT_OPTIONS = {
|
|
17
17
|
export var createManager = function createManager(hooks, api) {
|
18
18
|
var index = 0;
|
19
19
|
var runners;
|
20
|
-
|
21
20
|
var currentHooks = _objectSpread({}, hooks);
|
22
|
-
|
23
21
|
var useRunner = function useRunner() {
|
24
22
|
return runners;
|
25
23
|
};
|
26
|
-
|
27
24
|
var registerHook = function registerHook(extraHooks) {
|
28
25
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
29
26
|
};
|
30
|
-
|
31
27
|
var isPlugin = function isPlugin(input) {
|
32
28
|
return isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
33
29
|
};
|
34
|
-
|
35
30
|
var pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
36
31
|
useHookRunners: useRunner
|
37
32
|
});
|
38
|
-
|
39
33
|
var clone = function clone(overrideAPI) {
|
40
34
|
var plugins = [];
|
41
|
-
|
42
35
|
var addPlugin = function addPlugin(plugin) {
|
43
36
|
if (!includePlugin(plugins, plugin)) {
|
44
37
|
plugins.push(_objectSpread({}, plugin));
|
45
38
|
}
|
46
39
|
};
|
47
|
-
|
48
40
|
var usePlugin = function usePlugin() {
|
49
41
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
50
42
|
input[_key] = arguments[_key];
|
51
43
|
}
|
52
|
-
|
53
44
|
input.forEach(function (plugin) {
|
54
45
|
// already created by createPlugin
|
55
46
|
if (isPlugin(plugin)) {
|
56
47
|
addPlugin(plugin);
|
57
|
-
}
|
48
|
+
}
|
49
|
+
// using function to return plugin options
|
58
50
|
else if (typeof plugin === 'function') {
|
59
51
|
var _options = plugin();
|
60
|
-
|
61
52
|
addPlugin(createPlugin(_options.setup, _options));
|
62
|
-
}
|
53
|
+
}
|
54
|
+
// plain plugin object
|
63
55
|
else if (isObject(plugin)) {
|
64
56
|
addPlugin(createPlugin(plugin.setup, plugin));
|
65
|
-
}
|
57
|
+
}
|
58
|
+
// unknown plugin
|
66
59
|
else {
|
67
60
|
console.warn("Unknown plugin: ".concat(JSON.stringify(plugin)));
|
68
61
|
}
|
69
62
|
});
|
70
63
|
return manager;
|
71
64
|
};
|
72
|
-
|
73
65
|
var createPlugin = function createPlugin() {
|
74
66
|
var _options$usePlugins;
|
75
|
-
|
76
67
|
var setup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
77
68
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
78
|
-
|
79
69
|
if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
|
80
70
|
options.usePlugins.forEach(function (plugin) {
|
81
71
|
usePlugin(createPlugin(plugin.setup, plugin));
|
82
72
|
});
|
83
73
|
}
|
84
|
-
|
85
74
|
if (options.registerHook) {
|
86
75
|
registerHook(options.registerHook);
|
87
76
|
}
|
88
|
-
|
89
77
|
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
|
90
78
|
name: "No.".concat(index++, " plugin")
|
91
79
|
}, options), {}, {
|
@@ -93,16 +81,12 @@ export var createManager = function createManager(hooks, api) {
|
|
93
81
|
setup: setup
|
94
82
|
});
|
95
83
|
};
|
96
|
-
|
97
84
|
var clear = function clear() {
|
98
85
|
plugins = [];
|
99
86
|
};
|
100
|
-
|
101
87
|
var init = function init() {
|
102
88
|
var sortedPlugins = sortPlugins(plugins);
|
103
|
-
|
104
89
|
var mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
105
|
-
|
106
90
|
checkPlugins(sortedPlugins);
|
107
91
|
var hooksList = sortedPlugins.map(function (plugin) {
|
108
92
|
return plugin.setup(mergedPluginAPI);
|
@@ -110,11 +94,9 @@ export var createManager = function createManager(hooks, api) {
|
|
110
94
|
runners = generateRunner(hooksList, currentHooks);
|
111
95
|
return runners;
|
112
96
|
};
|
113
|
-
|
114
97
|
var run = function run(cb) {
|
115
98
|
return cb();
|
116
99
|
};
|
117
|
-
|
118
100
|
var manager = {
|
119
101
|
createPlugin: createPlugin,
|
120
102
|
isPlugin: isPlugin,
|
@@ -128,89 +110,72 @@ export var createManager = function createManager(hooks, api) {
|
|
128
110
|
};
|
129
111
|
return manager;
|
130
112
|
};
|
131
|
-
|
132
113
|
return clone();
|
133
114
|
};
|
134
115
|
export var generateRunner = function generateRunner(hooksList, hooksMap) {
|
135
116
|
var runner = {};
|
136
117
|
var cloneShape = cloneHooksMap(hooksMap);
|
137
|
-
|
138
118
|
if (hooksMap) {
|
139
119
|
var _loop = function _loop(key) {
|
140
120
|
var _iterator = _createForOfIteratorHelper(hooksList),
|
141
|
-
|
142
|
-
|
121
|
+
_step;
|
143
122
|
try {
|
144
123
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
145
124
|
var hooks = _step.value;
|
146
|
-
|
147
125
|
if (!hooks) {
|
148
126
|
continue;
|
149
127
|
}
|
150
|
-
|
151
128
|
if (hooks[key]) {
|
152
129
|
cloneShape[key].use(hooks[key]);
|
153
130
|
}
|
154
|
-
}
|
131
|
+
}
|
132
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
155
133
|
// @ts-expect-error
|
156
|
-
|
157
134
|
} catch (err) {
|
158
135
|
_iterator.e(err);
|
159
136
|
} finally {
|
160
137
|
_iterator.f();
|
161
138
|
}
|
162
|
-
|
163
139
|
runner[key] = function (input, options) {
|
164
140
|
return cloneShape[key].run(input, _objectSpread({}, options));
|
165
141
|
};
|
166
142
|
};
|
167
|
-
|
168
143
|
for (var key in cloneShape) {
|
169
144
|
_loop(key);
|
170
145
|
}
|
171
146
|
}
|
172
|
-
|
173
147
|
return runner;
|
174
148
|
};
|
175
149
|
export var cloneHook = function cloneHook(hook) {
|
176
150
|
if (isWaterfall(hook)) {
|
177
151
|
return createWaterfall();
|
178
152
|
}
|
179
|
-
|
180
153
|
if (isAsyncWaterfall(hook)) {
|
181
154
|
return createAsyncWaterfall();
|
182
155
|
}
|
183
|
-
|
184
156
|
if (isWorkflow(hook)) {
|
185
157
|
return createWorkflow();
|
186
158
|
}
|
187
|
-
|
188
159
|
if (isAsyncWorkflow(hook)) {
|
189
160
|
return createAsyncWorkflow();
|
190
161
|
}
|
191
|
-
|
192
162
|
if (isParallelWorkflow(hook)) {
|
193
163
|
return createParallelWorkflow();
|
194
164
|
}
|
195
|
-
|
196
165
|
if (isPipeline(hook)) {
|
197
166
|
return createPipeline();
|
198
167
|
}
|
199
|
-
|
200
168
|
throw new Error("Unknown hook: ".concat(hook));
|
201
169
|
};
|
202
170
|
export var cloneHooksMap = function cloneHooksMap(record) {
|
203
171
|
if (!record) {
|
204
172
|
return record;
|
205
173
|
}
|
206
|
-
|
207
174
|
var result = {};
|
208
|
-
|
209
175
|
for (var key in record) {
|
210
176
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
211
177
|
// @ts-expect-error
|
212
178
|
result[key] = cloneHook(record[key]);
|
213
179
|
}
|
214
|
-
|
215
180
|
return result;
|
216
181
|
};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
export var dagSort = function dagSort(plugins) {
|
2
|
+
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'name';
|
3
|
+
var preKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'pre';
|
4
|
+
var postKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'post';
|
5
|
+
var allLines = [];
|
6
|
+
function getPluginByAny(q) {
|
7
|
+
var target = plugins.find(function (item) {
|
8
|
+
return typeof q === 'string' ? item[key] === q : item[key] === q[key];
|
9
|
+
});
|
10
|
+
// current plugin design can't guarantee the plugins in pre/post existed
|
11
|
+
if (!target) {
|
12
|
+
throw new Error("plugin ".concat(q, " not existed"));
|
13
|
+
}
|
14
|
+
return target;
|
15
|
+
}
|
16
|
+
plugins.forEach(function (item) {
|
17
|
+
item[preKey].forEach(function (p) {
|
18
|
+
// compatibility: do not add the plugin-name that plugins not have
|
19
|
+
if (plugins.find(function (ap) {
|
20
|
+
return ap.name === p;
|
21
|
+
})) {
|
22
|
+
allLines.push([getPluginByAny(p)[key], getPluginByAny(item)[key]]);
|
23
|
+
}
|
24
|
+
});
|
25
|
+
item[postKey].forEach(function (pt) {
|
26
|
+
// compatibility: do not add the plugin-name that plugins not have
|
27
|
+
if (plugins.find(function (ap) {
|
28
|
+
return ap.name === pt;
|
29
|
+
})) {
|
30
|
+
allLines.push([getPluginByAny(item)[key], getPluginByAny(pt)[key]]);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
// search the zero input plugin
|
36
|
+
var zeroEndPoints = plugins.filter(function (item) {
|
37
|
+
return !allLines.find(function (l) {
|
38
|
+
return l[1] === item[key];
|
39
|
+
});
|
40
|
+
});
|
41
|
+
var sortedPoint = [];
|
42
|
+
var _loop = function _loop() {
|
43
|
+
var zep = zeroEndPoints.shift();
|
44
|
+
sortedPoint.push(getPluginByAny(zep));
|
45
|
+
allLines = allLines.filter(function (l) {
|
46
|
+
return l[0] !== getPluginByAny(zep)[key];
|
47
|
+
});
|
48
|
+
var restPoints = plugins.filter(function (item) {
|
49
|
+
return !sortedPoint.find(function (sp) {
|
50
|
+
return sp[key] === item[key];
|
51
|
+
});
|
52
|
+
});
|
53
|
+
zeroEndPoints = restPoints.filter(
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
55
|
+
function (item) {
|
56
|
+
return !allLines.find(function (l) {
|
57
|
+
return l[1] === item[key];
|
58
|
+
});
|
59
|
+
});
|
60
|
+
};
|
61
|
+
while (zeroEndPoints.length) {
|
62
|
+
_loop();
|
63
|
+
}
|
64
|
+
// if has ring, throw error
|
65
|
+
if (allLines.length) {
|
66
|
+
var restInRingPoints = {};
|
67
|
+
allLines.forEach(function (l) {
|
68
|
+
restInRingPoints[l[0]] = true;
|
69
|
+
restInRingPoints[l[1]] = true;
|
70
|
+
});
|
71
|
+
throw new Error("plugins dependences has loop: ".concat(Object.keys(restInRingPoints).join(',')));
|
72
|
+
}
|
73
|
+
return sortedPoint;
|
74
|
+
};
|
@@ -11,21 +11,17 @@ export var getAsyncBrook = function getAsyncBrook(input) {
|
|
11
11
|
} else if (input && typeof input.middleware === 'function') {
|
12
12
|
return input.middleware;
|
13
13
|
}
|
14
|
-
|
15
14
|
throw new Error("".concat(input, " is not a AsyncBrook or { brook: AsyncBrook }"));
|
16
15
|
};
|
17
16
|
export var createAsyncWaterfall = function createAsyncWaterfall() {
|
18
17
|
var pipeline = createAsyncPipeline();
|
19
|
-
|
20
18
|
var use = function use() {
|
21
19
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
22
20
|
input[_key] = arguments[_key];
|
23
21
|
}
|
24
|
-
|
25
22
|
pipeline.use.apply(pipeline, _toConsumableArray(input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware)));
|
26
23
|
return waterfall;
|
27
24
|
};
|
28
|
-
|
29
25
|
var run = function run(input, options) {
|
30
26
|
return pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
31
27
|
onLast: function onLast(input) {
|
@@ -33,7 +29,6 @@ export var createAsyncWaterfall = function createAsyncWaterfall() {
|
|
33
29
|
}
|
34
30
|
}));
|
35
31
|
};
|
36
|
-
|
37
32
|
var middleware = function middleware(input) {
|
38
33
|
return pipeline.run(input, {
|
39
34
|
onLast: function onLast(input) {
|
@@ -41,19 +36,16 @@ export var createAsyncWaterfall = function createAsyncWaterfall() {
|
|
41
36
|
}
|
42
37
|
});
|
43
38
|
};
|
44
|
-
|
45
39
|
var waterfall = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
46
40
|
use: use,
|
47
41
|
run: run,
|
48
42
|
middleware: middleware
|
49
43
|
}, ASYNC_WATERFALL_SYMBOL, true));
|
50
|
-
|
51
44
|
return waterfall;
|
52
45
|
};
|
53
46
|
export var isAsyncWaterfall = function isAsyncWaterfall(input) {
|
54
47
|
return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
55
48
|
};
|
56
|
-
|
57
49
|
var mapAsyncBrookToAsyncMiddleware = function mapAsyncBrookToAsyncMiddleware(brook) {
|
58
50
|
return /*#__PURE__*/function () {
|
59
51
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, next) {
|
@@ -64,11 +56,9 @@ var mapAsyncBrookToAsyncMiddleware = function mapAsyncBrookToAsyncMiddleware(bro
|
|
64
56
|
_context.t0 = next;
|
65
57
|
_context.next = 3;
|
66
58
|
return brook(input);
|
67
|
-
|
68
59
|
case 3:
|
69
60
|
_context.t1 = _context.sent;
|
70
61
|
return _context.abrupt("return", (0, _context.t0)(_context.t1));
|
71
|
-
|
72
62
|
case 5:
|
73
63
|
case "end":
|
74
64
|
return _context.stop();
|
@@ -76,7 +66,6 @@ var mapAsyncBrookToAsyncMiddleware = function mapAsyncBrookToAsyncMiddleware(bro
|
|
76
66
|
}
|
77
67
|
}, _callee);
|
78
68
|
}));
|
79
|
-
|
80
69
|
return function (_x, _x2) {
|
81
70
|
return _ref.apply(this, arguments);
|
82
71
|
};
|
@@ -9,21 +9,17 @@ export var getBrook = function getBrook(input) {
|
|
9
9
|
} else if (input && typeof input.middleware === 'function') {
|
10
10
|
return input.middleware;
|
11
11
|
}
|
12
|
-
|
13
12
|
throw new Error("".concat(input, " is not a Brook or { brook: Brook }"));
|
14
13
|
};
|
15
14
|
export var createWaterfall = function createWaterfall() {
|
16
15
|
var pipeline = createPipeline();
|
17
|
-
|
18
16
|
var use = function use() {
|
19
17
|
for (var _len = arguments.length, brooks = new Array(_len), _key = 0; _key < _len; _key++) {
|
20
18
|
brooks[_key] = arguments[_key];
|
21
19
|
}
|
22
|
-
|
23
20
|
pipeline.use.apply(pipeline, _toConsumableArray(brooks.map(getBrook).map(mapBrookToMiddleware)));
|
24
21
|
return waterfall;
|
25
22
|
};
|
26
|
-
|
27
23
|
var run = function run(input, options) {
|
28
24
|
return pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
29
25
|
onLast: function onLast(input) {
|
@@ -31,7 +27,6 @@ export var createWaterfall = function createWaterfall() {
|
|
31
27
|
}
|
32
28
|
}));
|
33
29
|
};
|
34
|
-
|
35
30
|
var middleware = function middleware(input) {
|
36
31
|
return pipeline.run(input, {
|
37
32
|
onLast: function onLast(input) {
|
@@ -39,19 +34,16 @@ export var createWaterfall = function createWaterfall() {
|
|
39
34
|
}
|
40
35
|
});
|
41
36
|
};
|
42
|
-
|
43
37
|
var waterfall = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
44
38
|
use: use,
|
45
39
|
run: run,
|
46
40
|
middleware: middleware
|
47
41
|
}, WATERFALL_SYMBOL, true));
|
48
|
-
|
49
42
|
return waterfall;
|
50
43
|
};
|
51
44
|
export var isWaterfall = function isWaterfall(input) {
|
52
45
|
return Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
53
46
|
};
|
54
|
-
|
55
47
|
var mapBrookToMiddleware = function mapBrookToMiddleware(brook) {
|
56
48
|
return function (input, next) {
|
57
49
|
return next(brook(input));
|
@@ -11,16 +11,13 @@ export var isAsyncWorkflow = function isAsyncWorkflow(input) {
|
|
11
11
|
};
|
12
12
|
export var createAsyncWorkflow = function createAsyncWorkflow() {
|
13
13
|
var pipeline = createAsyncPipeline();
|
14
|
-
|
15
14
|
var use = function use() {
|
16
15
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
17
16
|
input[_key] = arguments[_key];
|
18
17
|
}
|
19
|
-
|
20
18
|
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapAsyncWorkerToAsyncMiddleware)));
|
21
19
|
return workflow;
|
22
20
|
};
|
23
|
-
|
24
21
|
var run = /*#__PURE__*/function () {
|
25
22
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
26
23
|
var result;
|
@@ -33,19 +30,15 @@ export var createAsyncWorkflow = function createAsyncWorkflow() {
|
|
33
30
|
return [];
|
34
31
|
}
|
35
32
|
});
|
36
|
-
|
37
33
|
if (!isPromise(result)) {
|
38
34
|
_context.next = 5;
|
39
35
|
break;
|
40
36
|
}
|
41
|
-
|
42
37
|
return _context.abrupt("return", result.then(function (result) {
|
43
38
|
return result.filter(Boolean);
|
44
39
|
}));
|
45
|
-
|
46
40
|
case 5:
|
47
41
|
return _context.abrupt("return", result.filter(Boolean));
|
48
|
-
|
49
42
|
case 6:
|
50
43
|
case "end":
|
51
44
|
return _context.stop();
|
@@ -53,20 +46,16 @@ export var createAsyncWorkflow = function createAsyncWorkflow() {
|
|
53
46
|
}
|
54
47
|
}, _callee);
|
55
48
|
}));
|
56
|
-
|
57
49
|
return function run(_x) {
|
58
50
|
return _ref.apply(this, arguments);
|
59
51
|
};
|
60
52
|
}();
|
61
|
-
|
62
53
|
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
63
54
|
use: use,
|
64
55
|
run: run
|
65
56
|
}, ASYNC_WORKFLOW_SYMBOL, true));
|
66
|
-
|
67
57
|
return workflow;
|
68
58
|
};
|
69
|
-
|
70
59
|
var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(worker) {
|
71
60
|
return /*#__PURE__*/function () {
|
72
61
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(input, next) {
|
@@ -76,19 +65,16 @@ var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(w
|
|
76
65
|
case 0:
|
77
66
|
_context2.next = 2;
|
78
67
|
return worker(input);
|
79
|
-
|
80
68
|
case 2:
|
81
69
|
_context2.t1 = _context2.sent;
|
82
70
|
_context2.t0 = [_context2.t1];
|
83
71
|
_context2.t2 = _toConsumableArray;
|
84
72
|
_context2.next = 7;
|
85
73
|
return next(input);
|
86
|
-
|
87
74
|
case 7:
|
88
75
|
_context2.t3 = _context2.sent;
|
89
76
|
_context2.t4 = (0, _context2.t2)(_context2.t3);
|
90
77
|
return _context2.abrupt("return", _context2.t0.concat.call(_context2.t0, _context2.t4));
|
91
|
-
|
92
78
|
case 10:
|
93
79
|
case "end":
|
94
80
|
return _context2.stop();
|
@@ -96,13 +82,11 @@ var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(w
|
|
96
82
|
}
|
97
83
|
}, _callee2);
|
98
84
|
}));
|
99
|
-
|
100
85
|
return function (_x2, _x3) {
|
101
86
|
return _ref2.apply(this, arguments);
|
102
87
|
};
|
103
88
|
}();
|
104
89
|
};
|
105
|
-
|
106
90
|
function isPromise(obj) {
|
107
91
|
return Boolean(obj) && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
108
92
|
}
|
@@ -10,16 +10,13 @@ export var isParallelWorkflow = function isParallelWorkflow(input) {
|
|
10
10
|
};
|
11
11
|
export var createParallelWorkflow = function createParallelWorkflow() {
|
12
12
|
var pipeline = createPipeline();
|
13
|
-
|
14
13
|
var use = function use() {
|
15
14
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
16
15
|
input[_key] = arguments[_key];
|
17
16
|
}
|
18
|
-
|
19
17
|
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapParallelWorkerToAsyncMiddleware)));
|
20
18
|
return workflow;
|
21
19
|
};
|
22
|
-
|
23
20
|
var run = /*#__PURE__*/function () {
|
24
21
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
25
22
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
@@ -33,7 +30,6 @@ export var createParallelWorkflow = function createParallelWorkflow() {
|
|
33
30
|
})).then(function (result) {
|
34
31
|
return result.filter(Boolean);
|
35
32
|
}));
|
36
|
-
|
37
33
|
case 1:
|
38
34
|
case "end":
|
39
35
|
return _context.stop();
|
@@ -41,20 +37,16 @@ export var createParallelWorkflow = function createParallelWorkflow() {
|
|
41
37
|
}
|
42
38
|
}, _callee);
|
43
39
|
}));
|
44
|
-
|
45
40
|
return function run(_x) {
|
46
41
|
return _ref.apply(this, arguments);
|
47
42
|
};
|
48
43
|
}();
|
49
|
-
|
50
44
|
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
51
45
|
run: run,
|
52
46
|
use: use
|
53
47
|
}, PARALLEL_WORKFLOW_SYMBOL, true));
|
54
|
-
|
55
48
|
return workflow;
|
56
49
|
};
|
57
|
-
|
58
50
|
var mapParallelWorkerToAsyncMiddleware = function mapParallelWorkerToAsyncMiddleware(worker) {
|
59
51
|
return function (input, next) {
|
60
52
|
return [worker(input)].concat(_toConsumableArray(next(input)));
|
@@ -5,16 +5,13 @@ import { createPipeline } from "../farrow-pipeline";
|
|
5
5
|
var WORKFLOW_SYMBOL = Symbol["for"]('MODERN_WORKFLOW');
|
6
6
|
export var createWorkflow = function createWorkflow() {
|
7
7
|
var pipeline = createPipeline();
|
8
|
-
|
9
8
|
var use = function use() {
|
10
9
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
11
10
|
input[_key] = arguments[_key];
|
12
11
|
}
|
13
|
-
|
14
12
|
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapWorkerToMiddleware)));
|
15
13
|
return workflow;
|
16
14
|
};
|
17
|
-
|
18
15
|
var run = function run(input) {
|
19
16
|
var result = pipeline.run(input, {
|
20
17
|
onLast: function onLast() {
|
@@ -23,18 +20,15 @@ export var createWorkflow = function createWorkflow() {
|
|
23
20
|
});
|
24
21
|
return result.filter(Boolean);
|
25
22
|
};
|
26
|
-
|
27
23
|
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
28
24
|
use: use,
|
29
25
|
run: run
|
30
26
|
}, WORKFLOW_SYMBOL, true));
|
31
|
-
|
32
27
|
return workflow;
|
33
28
|
};
|
34
29
|
export var isWorkflow = function isWorkflow(input) {
|
35
30
|
return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
36
31
|
};
|
37
|
-
|
38
32
|
var mapWorkerToMiddleware = function mapWorkerToMiddleware(worker) {
|
39
33
|
return function (input, next) {
|
40
34
|
return [worker(input)].concat(_toConsumableArray(next(input)));
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { ToRunners, ToThreads, CommonAPI, PluginOptions } from './types';
|
2
2
|
/** Setup function of async plugin. */
|
3
|
-
|
4
3
|
export declare type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
|
5
4
|
declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
6
5
|
export declare type AsyncPlugin<Hooks, API> = {
|
@@ -17,46 +16,38 @@ export declare type AsyncManager<Hooks, API> = {
|
|
17
16
|
* Determine if a value is a async plugin.
|
18
17
|
* @param input
|
19
18
|
*/
|
20
|
-
|
21
19
|
isPlugin: (input: unknown) => input is AsyncPlugin<Hooks, API>;
|
22
20
|
/**
|
23
21
|
* Register new plugins to current manager.
|
24
22
|
* @param plugins one or more plugin.
|
25
23
|
*/
|
26
|
-
|
27
24
|
usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
|
28
25
|
/**
|
29
26
|
* Init manager, it will call the setup function of all registered plugins.
|
30
27
|
*/
|
31
|
-
|
32
28
|
init: () => Promise<ToRunners<Hooks>>;
|
33
29
|
/**
|
34
30
|
* Run callback function.
|
35
31
|
* @param callback
|
36
32
|
*/
|
37
|
-
|
38
33
|
run: <O>(cb: () => O) => O;
|
39
34
|
/**
|
40
35
|
* Register new hooks.
|
41
36
|
* @param newHooks
|
42
37
|
*/
|
43
|
-
|
44
38
|
registerHook: (newHooks: Partial<Hooks>) => void;
|
45
39
|
/**
|
46
40
|
* Return a cloned manager.
|
47
41
|
* @param overrideAPI override the default plugin API.
|
48
42
|
*/
|
49
|
-
|
50
43
|
clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => AsyncManager<Hooks, API>;
|
51
44
|
/**
|
52
45
|
* Clear all registered plugins.
|
53
46
|
*/
|
54
|
-
|
55
47
|
clear: () => void;
|
56
48
|
/**
|
57
49
|
* Get all runner functions of the hooks.
|
58
50
|
*/
|
59
|
-
|
60
51
|
useRunner: () => ToRunners<Hooks>;
|
61
52
|
};
|
62
53
|
export declare const createAsyncManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => AsyncManager<Hooks, API>;
|