@modern-js/plugin 2.35.0 → 2.36.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/farrow-pipeline/context.js +24 -7
- package/dist/cjs/farrow-pipeline/counter.js +24 -7
- package/dist/cjs/farrow-pipeline/index.js +34 -30
- package/dist/cjs/index.js +26 -7
- package/dist/cjs/manager/async.js +39 -20
- package/dist/cjs/manager/index.js +24 -6
- package/dist/cjs/manager/shared.js +33 -26
- package/dist/cjs/manager/sync.js +53 -47
- package/dist/cjs/manager/types.js +15 -3
- package/dist/cjs/waterfall/async.js +30 -24
- package/dist/cjs/waterfall/index.js +22 -5
- package/dist/cjs/waterfall/sync.js +30 -24
- package/dist/cjs/workflow/async.js +29 -24
- package/dist/cjs/workflow/index.js +24 -6
- package/dist/cjs/workflow/parallel.js +28 -21
- package/dist/cjs/workflow/sync.js +28 -21
- package/dist/esm/index.js +129 -63
- package/dist/esm-node/farrow-pipeline/context.js +4 -1
- package/dist/esm-node/farrow-pipeline/counter.js +4 -1
- package/dist/esm-node/farrow-pipeline/index.js +10 -9
- package/dist/esm-node/manager/async.js +11 -6
- package/dist/esm-node/manager/shared.js +12 -5
- package/dist/esm-node/manager/sync.js +13 -7
- package/dist/esm-node/manager/types.js +0 -1
- package/dist/esm-node/waterfall/async.js +8 -6
- package/dist/esm-node/waterfall/sync.js +8 -6
- package/dist/esm-node/workflow/async.js +7 -8
- package/dist/esm-node/workflow/parallel.js +6 -5
- package/dist/esm-node/workflow/sync.js +6 -5
- package/package.json +4 -4
package/dist/esm/index.js
CHANGED
@@ -39,14 +39,13 @@ var createCounter = function(callback) {
|
|
39
39
|
start: function(input) {
|
40
40
|
return dispatch(0, input);
|
41
41
|
},
|
42
|
-
dispatch
|
42
|
+
dispatch
|
43
43
|
};
|
44
44
|
};
|
45
45
|
|
46
46
|
// src/farrow-pipeline/index.ts
|
47
47
|
var isPipeline = function(input) {
|
48
|
-
|
49
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PipelineSymbol]);
|
48
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
50
49
|
};
|
51
50
|
var PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
52
51
|
var getMiddleware = function(input) {
|
@@ -80,11 +79,10 @@ var createPipeline = function() {
|
|
80
79
|
};
|
81
80
|
var currentCounter = createCurrentCounter();
|
82
81
|
var getCounter = function(options) {
|
83
|
-
var _options;
|
84
82
|
if (!options) {
|
85
83
|
return currentCounter;
|
86
84
|
}
|
87
|
-
return createCurrentCounter(
|
85
|
+
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
88
86
|
};
|
89
87
|
var run = function(input, options) {
|
90
88
|
return getCounter(options).start(input);
|
@@ -142,15 +140,14 @@ var createWaterfall = function() {
|
|
142
140
|
});
|
143
141
|
};
|
144
142
|
var waterfall = _object_spread_props(_object_spread2({}, pipeline), _define_property2({
|
145
|
-
use
|
146
|
-
run
|
147
|
-
middleware
|
143
|
+
use,
|
144
|
+
run,
|
145
|
+
middleware
|
148
146
|
}, WATERFALL_SYMBOL, true));
|
149
147
|
return waterfall;
|
150
148
|
};
|
151
149
|
var isWaterfall = function(input) {
|
152
|
-
|
153
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WATERFALL_SYMBOL]);
|
150
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
154
151
|
};
|
155
152
|
var mapBrookToMiddleware = function(brook) {
|
156
153
|
return function(input, next) {
|
@@ -198,15 +195,14 @@ var createAsyncWaterfall = function() {
|
|
198
195
|
});
|
199
196
|
};
|
200
197
|
var waterfall = _object_spread_props2(_object_spread3({}, pipeline), _define_property3({
|
201
|
-
use
|
202
|
-
run
|
203
|
-
middleware
|
198
|
+
use,
|
199
|
+
run,
|
200
|
+
middleware
|
204
201
|
}, ASYNC_WATERFALL_SYMBOL, true));
|
205
202
|
return waterfall;
|
206
203
|
};
|
207
204
|
var isAsyncWaterfall = function(input) {
|
208
|
-
|
209
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WATERFALL_SYMBOL]);
|
205
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
210
206
|
};
|
211
207
|
var mapAsyncBrookToAsyncMiddleware = function(brook) {
|
212
208
|
return function(input, next) {
|
@@ -241,14 +237,13 @@ var createWorkflow = function() {
|
|
241
237
|
return result.filter(Boolean);
|
242
238
|
};
|
243
239
|
var workflow = _object_spread_props3(_object_spread4({}, pipeline), _define_property4({
|
244
|
-
use
|
245
|
-
run
|
240
|
+
use,
|
241
|
+
run
|
246
242
|
}, WORKFLOW_SYMBOL, true));
|
247
243
|
return workflow;
|
248
244
|
};
|
249
245
|
var isWorkflow = function(input) {
|
250
|
-
|
251
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WORKFLOW_SYMBOL]);
|
246
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
252
247
|
};
|
253
248
|
var mapWorkerToMiddleware = function(worker) {
|
254
249
|
return function(input, next) {
|
@@ -265,8 +260,7 @@ import { _ as _object_spread_props4 } from "@swc/helpers/_/_object_spread_props"
|
|
265
260
|
import { _ as _to_consumable_array5 } from "@swc/helpers/_/_to_consumable_array";
|
266
261
|
var PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
|
267
262
|
var isParallelWorkflow = function(input) {
|
268
|
-
|
269
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PARALLEL_WORKFLOW_SYMBOL]);
|
263
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
270
264
|
};
|
271
265
|
var createParallelWorkflow = function() {
|
272
266
|
var pipeline = createPipeline();
|
@@ -288,8 +282,8 @@ var createParallelWorkflow = function() {
|
|
288
282
|
});
|
289
283
|
};
|
290
284
|
var workflow = _object_spread_props4(_object_spread5({}, pipeline), _define_property5({
|
291
|
-
run
|
292
|
-
use
|
285
|
+
run,
|
286
|
+
use
|
293
287
|
}, PARALLEL_WORKFLOW_SYMBOL, true));
|
294
288
|
return workflow;
|
295
289
|
};
|
@@ -307,9 +301,11 @@ import { _ as _object_spread6 } from "@swc/helpers/_/_object_spread";
|
|
307
301
|
import { _ as _object_spread_props5 } from "@swc/helpers/_/_object_spread_props";
|
308
302
|
import { _ as _to_consumable_array6 } from "@swc/helpers/_/_to_consumable_array";
|
309
303
|
var ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
|
304
|
+
var isPromise = function(obj) {
|
305
|
+
return obj && typeof obj.then === "function";
|
306
|
+
};
|
310
307
|
var isAsyncWorkflow = function(input) {
|
311
|
-
|
312
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WORKFLOW_SYMBOL]);
|
308
|
+
return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
313
309
|
};
|
314
310
|
var createAsyncWorkflow = function() {
|
315
311
|
var pipeline = createAsyncPipeline();
|
@@ -335,8 +331,8 @@ var createAsyncWorkflow = function() {
|
|
335
331
|
return result.filter(Boolean);
|
336
332
|
};
|
337
333
|
var workflow = _object_spread_props5(_object_spread6({}, pipeline), _define_property6({
|
338
|
-
use
|
339
|
-
run
|
334
|
+
use,
|
335
|
+
run
|
340
336
|
}, ASYNC_WORKFLOW_SYMBOL, true));
|
341
337
|
return workflow;
|
342
338
|
};
|
@@ -351,9 +347,6 @@ var mapAsyncWorkerToAsyncMiddleware = function(worker) {
|
|
351
347
|
});
|
352
348
|
};
|
353
349
|
};
|
354
|
-
function isPromise(obj) {
|
355
|
-
return obj && typeof obj.then === "function";
|
356
|
-
}
|
357
350
|
|
358
351
|
// src/manager/sync.ts
|
359
352
|
import { _ as _object_spread7 } from "@swc/helpers/_/_object_spread";
|
@@ -463,8 +456,8 @@ var createManager = function(hooks, api) {
|
|
463
456
|
return _object_spread_props6(_object_spread7(_object_spread_props6(_object_spread7({}, DEFAULT_OPTIONS), {
|
464
457
|
name: "No.".concat(index++, " plugin")
|
465
458
|
}), options), {
|
466
|
-
SYNC_PLUGIN_SYMBOL
|
467
|
-
setup
|
459
|
+
SYNC_PLUGIN_SYMBOL,
|
460
|
+
setup
|
468
461
|
});
|
469
462
|
};
|
470
463
|
var clear = function() {
|
@@ -484,15 +477,15 @@ var createManager = function(hooks, api) {
|
|
484
477
|
return cb();
|
485
478
|
};
|
486
479
|
var manager = {
|
487
|
-
createPlugin
|
488
|
-
isPlugin
|
489
|
-
usePlugin
|
490
|
-
init
|
491
|
-
clear
|
492
|
-
run
|
493
|
-
registerHook
|
494
|
-
useRunner
|
495
|
-
clone
|
480
|
+
createPlugin,
|
481
|
+
isPlugin,
|
482
|
+
usePlugin,
|
483
|
+
init,
|
484
|
+
clear,
|
485
|
+
run,
|
486
|
+
registerHook,
|
487
|
+
useRunner,
|
488
|
+
clone
|
496
489
|
};
|
497
490
|
return manager;
|
498
491
|
};
|
@@ -504,8 +497,7 @@ var generateRunner = function(hooksList, hooksMap) {
|
|
504
497
|
if (hooksMap) {
|
505
498
|
var _loop = function(key2) {
|
506
499
|
hooksList.forEach(function(hooks) {
|
507
|
-
|
508
|
-
if ((_hooks = hooks) === null || _hooks === void 0 ? void 0 : _hooks[key2]) {
|
500
|
+
if (hooks === null || hooks === void 0 ? void 0 : hooks[key2]) {
|
509
501
|
cloneShape[key2].use(hooks[key2]);
|
510
502
|
}
|
511
503
|
});
|
@@ -551,8 +543,10 @@ var cloneHooksMap = function(record) {
|
|
551
543
|
};
|
552
544
|
|
553
545
|
// src/manager/async.ts
|
546
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
554
547
|
import { _ as _object_spread8 } from "@swc/helpers/_/_object_spread";
|
555
548
|
import { _ as _object_spread_props7 } from "@swc/helpers/_/_object_spread_props";
|
549
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
556
550
|
var ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
557
551
|
var createAsyncManager = function(hooks, api) {
|
558
552
|
var index = 0;
|
@@ -610,37 +604,109 @@ var createAsyncManager = function(hooks, api) {
|
|
610
604
|
return _object_spread_props7(_object_spread8(_object_spread_props7(_object_spread8({}, DEFAULT_OPTIONS), {
|
611
605
|
name: "No.".concat(index++, " plugin")
|
612
606
|
}), options), {
|
613
|
-
ASYNC_PLUGIN_SYMBOL
|
614
|
-
setup
|
607
|
+
ASYNC_PLUGIN_SYMBOL,
|
608
|
+
setup
|
615
609
|
});
|
616
610
|
};
|
617
611
|
var clear = function() {
|
618
612
|
plugins = [];
|
619
613
|
};
|
620
614
|
var init = function() {
|
621
|
-
var
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
615
|
+
var _ref = _async_to_generator(function() {
|
616
|
+
var sortedPlugins, mergedPluginAPI, hooksList, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, plugin, _, err;
|
617
|
+
return _ts_generator(this, function(_state) {
|
618
|
+
switch (_state.label) {
|
619
|
+
case 0:
|
620
|
+
sortedPlugins = sortPlugins(plugins);
|
621
|
+
mergedPluginAPI = _object_spread8({}, pluginAPI, overrideAPI);
|
622
|
+
checkPlugins(sortedPlugins);
|
623
|
+
hooksList = [];
|
624
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
625
|
+
_state.label = 1;
|
626
|
+
case 1:
|
627
|
+
_state.trys.push([
|
628
|
+
1,
|
629
|
+
6,
|
630
|
+
7,
|
631
|
+
8
|
632
|
+
]);
|
633
|
+
_iterator = sortedPlugins[Symbol.iterator]();
|
634
|
+
_state.label = 2;
|
635
|
+
case 2:
|
636
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
637
|
+
return [
|
638
|
+
3,
|
639
|
+
5
|
640
|
+
];
|
641
|
+
plugin = _step.value;
|
642
|
+
_ = hooksList.push;
|
643
|
+
return [
|
644
|
+
4,
|
645
|
+
plugin.setup(mergedPluginAPI)
|
646
|
+
];
|
647
|
+
case 3:
|
648
|
+
_.apply(hooksList, [
|
649
|
+
_state.sent()
|
650
|
+
]);
|
651
|
+
_state.label = 4;
|
652
|
+
case 4:
|
653
|
+
_iteratorNormalCompletion = true;
|
654
|
+
return [
|
655
|
+
3,
|
656
|
+
2
|
657
|
+
];
|
658
|
+
case 5:
|
659
|
+
return [
|
660
|
+
3,
|
661
|
+
8
|
662
|
+
];
|
663
|
+
case 6:
|
664
|
+
err = _state.sent();
|
665
|
+
_didIteratorError = true;
|
666
|
+
_iteratorError = err;
|
667
|
+
return [
|
668
|
+
3,
|
669
|
+
8
|
670
|
+
];
|
671
|
+
case 7:
|
672
|
+
try {
|
673
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
674
|
+
_iterator.return();
|
675
|
+
}
|
676
|
+
} finally {
|
677
|
+
if (_didIteratorError) {
|
678
|
+
throw _iteratorError;
|
679
|
+
}
|
680
|
+
}
|
681
|
+
return [
|
682
|
+
7
|
683
|
+
];
|
684
|
+
case 8:
|
685
|
+
runners = generateRunner(hooksList, currentHooks);
|
686
|
+
return [
|
687
|
+
2,
|
688
|
+
runners
|
689
|
+
];
|
690
|
+
}
|
691
|
+
});
|
629
692
|
});
|
630
|
-
|
693
|
+
return function init2() {
|
694
|
+
return _ref.apply(this, arguments);
|
695
|
+
};
|
696
|
+
}();
|
631
697
|
var run = function(cb) {
|
632
698
|
return cb();
|
633
699
|
};
|
634
700
|
var manager = {
|
635
|
-
createPlugin
|
636
|
-
isPlugin
|
637
|
-
usePlugin
|
638
|
-
init
|
639
|
-
run
|
640
|
-
clear
|
641
|
-
clone
|
642
|
-
registerHook
|
643
|
-
useRunner
|
701
|
+
createPlugin,
|
702
|
+
isPlugin,
|
703
|
+
usePlugin,
|
704
|
+
init,
|
705
|
+
run,
|
706
|
+
clear,
|
707
|
+
clone,
|
708
|
+
registerHook,
|
709
|
+
useRunner
|
644
710
|
};
|
645
711
|
return manager;
|
646
712
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
const createCounter = (callback) => {
|
2
2
|
const dispatch = (index, input) => {
|
3
3
|
const next = (nextInput = input) => dispatch(index + 1, nextInput);
|
4
4
|
return callback(index, input, next);
|
@@ -8,3 +8,6 @@ export const createCounter = (callback) => {
|
|
8
8
|
dispatch
|
9
9
|
};
|
10
10
|
};
|
11
|
+
export {
|
12
|
+
createCounter
|
13
|
+
};
|
@@ -1,10 +1,6 @@
|
|
1
1
|
import { createContext } from "./context";
|
2
2
|
import { createCounter } from "./counter";
|
3
|
-
|
4
|
-
export const isPipeline = (input) => {
|
5
|
-
var _input;
|
6
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PipelineSymbol]);
|
7
|
-
};
|
3
|
+
const isPipeline = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
8
4
|
const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
9
5
|
const getMiddleware = (input) => {
|
10
6
|
if (typeof input === "function") {
|
@@ -14,7 +10,7 @@ const getMiddleware = (input) => {
|
|
14
10
|
}
|
15
11
|
throw new Error(`${input} is not a Middleware`);
|
16
12
|
};
|
17
|
-
|
13
|
+
const createPipeline = () => {
|
18
14
|
const middlewares = [];
|
19
15
|
const use = (...inputs) => {
|
20
16
|
middlewares.push(...inputs.map(getMiddleware));
|
@@ -33,11 +29,10 @@ export const createPipeline = () => {
|
|
33
29
|
};
|
34
30
|
const currentCounter = createCurrentCounter();
|
35
31
|
const getCounter = (options) => {
|
36
|
-
var _options;
|
37
32
|
if (!options) {
|
38
33
|
return currentCounter;
|
39
34
|
}
|
40
|
-
return createCurrentCounter(
|
35
|
+
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
41
36
|
};
|
42
37
|
const run = (input, options) => getCounter(options).start(input);
|
43
38
|
const middleware = (input, next) => run(input, {
|
@@ -51,9 +46,15 @@ export const createPipeline = () => {
|
|
51
46
|
};
|
52
47
|
return pipeline;
|
53
48
|
};
|
54
|
-
|
49
|
+
const createAsyncPipeline = () => {
|
55
50
|
const pipeline = createPipeline();
|
56
51
|
return {
|
57
52
|
...pipeline
|
58
53
|
};
|
59
54
|
};
|
55
|
+
export {
|
56
|
+
createAsyncPipeline,
|
57
|
+
createContext,
|
58
|
+
createPipeline,
|
59
|
+
isPipeline
|
60
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { generateRunner, DEFAULT_OPTIONS } from "./sync";
|
2
2
|
import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
|
3
3
|
const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
4
|
-
|
4
|
+
const createAsyncManager = (hooks, api) => {
|
5
5
|
let index = 0;
|
6
6
|
let runners;
|
7
7
|
let currentHooks = {
|
@@ -65,17 +65,19 @@ export const createAsyncManager = (hooks, api) => {
|
|
65
65
|
const clear = () => {
|
66
66
|
plugins = [];
|
67
67
|
};
|
68
|
-
const init = () => {
|
68
|
+
const init = async () => {
|
69
69
|
const sortedPlugins = sortPlugins(plugins);
|
70
70
|
const mergedPluginAPI = {
|
71
71
|
...pluginAPI,
|
72
72
|
...overrideAPI
|
73
73
|
};
|
74
74
|
checkPlugins(sortedPlugins);
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
75
|
+
const hooksList = [];
|
76
|
+
for (const plugin of sortedPlugins) {
|
77
|
+
hooksList.push(await plugin.setup(mergedPluginAPI));
|
78
|
+
}
|
79
|
+
runners = generateRunner(hooksList, currentHooks);
|
80
|
+
return runners;
|
79
81
|
};
|
80
82
|
const run = (cb) => cb();
|
81
83
|
const manager = {
|
@@ -93,3 +95,6 @@ export const createAsyncManager = (hooks, api) => {
|
|
93
95
|
};
|
94
96
|
return clone();
|
95
97
|
};
|
98
|
+
export {
|
99
|
+
createAsyncManager
|
100
|
+
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { pluginDagSort } from "@modern-js/utils/universal/plugin-dag-sort";
|
2
|
-
|
2
|
+
const checkPlugins = (plugins) => {
|
3
3
|
if (process.env.NODE_ENV !== "production") {
|
4
4
|
plugins.forEach((origin) => {
|
5
5
|
origin.rivals.forEach((rival) => {
|
@@ -17,9 +17,16 @@ export const checkPlugins = (plugins) => {
|
|
17
17
|
});
|
18
18
|
}
|
19
19
|
};
|
20
|
-
|
20
|
+
function sortPlugins(input) {
|
21
21
|
return pluginDagSort(input.slice());
|
22
22
|
}
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
+
};
|
@@ -3,7 +3,7 @@ import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall }
|
|
3
3
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
4
4
|
import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
|
5
5
|
const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
6
|
-
|
6
|
+
const DEFAULT_OPTIONS = {
|
7
7
|
name: "untitled",
|
8
8
|
pre: [],
|
9
9
|
post: [],
|
@@ -12,7 +12,7 @@ export const DEFAULT_OPTIONS = {
|
|
12
12
|
usePlugins: [],
|
13
13
|
registerHook: {}
|
14
14
|
};
|
15
|
-
|
15
|
+
const createManager = (hooks, api) => {
|
16
16
|
let index = 0;
|
17
17
|
let runners;
|
18
18
|
let currentHooks = {
|
@@ -103,14 +103,13 @@ export const createManager = (hooks, api) => {
|
|
103
103
|
};
|
104
104
|
return clone();
|
105
105
|
};
|
106
|
-
|
106
|
+
const generateRunner = (hooksList, hooksMap) => {
|
107
107
|
const runner = {};
|
108
108
|
const cloneShape = cloneHooksMap(hooksMap);
|
109
109
|
if (hooksMap) {
|
110
110
|
for (const key in cloneShape) {
|
111
111
|
hooksList.forEach((hooks) => {
|
112
|
-
|
113
|
-
if ((_hooks = hooks) === null || _hooks === void 0 ? void 0 : _hooks[key]) {
|
112
|
+
if (hooks === null || hooks === void 0 ? void 0 : hooks[key]) {
|
114
113
|
cloneShape[key].use(hooks[key]);
|
115
114
|
}
|
116
115
|
});
|
@@ -121,7 +120,7 @@ export const generateRunner = (hooksList, hooksMap) => {
|
|
121
120
|
}
|
122
121
|
return runner;
|
123
122
|
};
|
124
|
-
|
123
|
+
const cloneHook = (hook) => {
|
125
124
|
if (isWaterfall(hook)) {
|
126
125
|
return createWaterfall();
|
127
126
|
}
|
@@ -142,7 +141,7 @@ export const cloneHook = (hook) => {
|
|
142
141
|
}
|
143
142
|
throw new Error(`Unknown hook: ${hook}`);
|
144
143
|
};
|
145
|
-
|
144
|
+
const cloneHooksMap = (record) => {
|
146
145
|
if (!record) {
|
147
146
|
return record;
|
148
147
|
}
|
@@ -152,3 +151,10 @@ export const cloneHooksMap = (record) => {
|
|
152
151
|
}
|
153
152
|
return result;
|
154
153
|
};
|
154
|
+
export {
|
155
|
+
DEFAULT_OPTIONS,
|
156
|
+
cloneHook,
|
157
|
+
cloneHooksMap,
|
158
|
+
createManager,
|
159
|
+
generateRunner
|
160
|
+
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createAsyncPipeline } from "../farrow-pipeline";
|
2
2
|
const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
|
3
|
-
|
3
|
+
const getAsyncBrook = (input) => {
|
4
4
|
if (typeof input === "function") {
|
5
5
|
return input;
|
6
6
|
}
|
@@ -9,7 +9,7 @@ export const getAsyncBrook = (input) => {
|
|
9
9
|
}
|
10
10
|
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
11
11
|
};
|
12
|
-
|
12
|
+
const createAsyncWaterfall = () => {
|
13
13
|
const pipeline = createAsyncPipeline();
|
14
14
|
const use = (...input) => {
|
15
15
|
pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
|
@@ -33,8 +33,10 @@ export const createAsyncWaterfall = () => {
|
|
33
33
|
};
|
34
34
|
return waterfall;
|
35
35
|
};
|
36
|
-
|
37
|
-
var _input;
|
38
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[ASYNC_WATERFALL_SYMBOL]);
|
39
|
-
};
|
36
|
+
const isAsyncWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
40
37
|
const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
|
38
|
+
export {
|
39
|
+
createAsyncWaterfall,
|
40
|
+
getAsyncBrook,
|
41
|
+
isAsyncWaterfall
|
42
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createPipeline } from "../farrow-pipeline";
|
2
2
|
const WATERFALL_SYMBOL = Symbol.for("MODERN_WATERFALL");
|
3
|
-
|
3
|
+
const getBrook = (input) => {
|
4
4
|
if (typeof input === "function") {
|
5
5
|
return input;
|
6
6
|
} else if (input && typeof input.middleware === "function") {
|
@@ -8,7 +8,7 @@ export const getBrook = (input) => {
|
|
8
8
|
}
|
9
9
|
throw new Error(`${input} is not a Brook or { brook: Brook }`);
|
10
10
|
};
|
11
|
-
|
11
|
+
const createWaterfall = () => {
|
12
12
|
const pipeline = createPipeline();
|
13
13
|
const use = (...brooks) => {
|
14
14
|
pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
|
@@ -32,8 +32,10 @@ export const createWaterfall = () => {
|
|
32
32
|
};
|
33
33
|
return waterfall;
|
34
34
|
};
|
35
|
-
|
36
|
-
var _input;
|
37
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WATERFALL_SYMBOL]);
|
38
|
-
};
|
35
|
+
const isWaterfall = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
39
36
|
const mapBrookToMiddleware = (brook) => (input, next) => next(brook(input));
|
37
|
+
export {
|
38
|
+
createWaterfall,
|
39
|
+
getBrook,
|
40
|
+
isWaterfall
|
41
|
+
};
|
@@ -1,10 +1,8 @@
|
|
1
1
|
import { createAsyncPipeline } from "../farrow-pipeline";
|
2
2
|
const ASYNC_WORKFLOW_SYMBOL = Symbol.for("MODERN_ASYNC_WORKFLOW");
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
};
|
7
|
-
export const createAsyncWorkflow = () => {
|
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 = () => {
|
8
6
|
const pipeline = createAsyncPipeline();
|
9
7
|
const use = (...input) => {
|
10
8
|
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
@@ -31,6 +29,7 @@ const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.res
|
|
31
29
|
result,
|
32
30
|
...nextResult
|
33
31
|
]));
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
export {
|
33
|
+
createAsyncWorkflow,
|
34
|
+
isAsyncWorkflow
|
35
|
+
};
|
@@ -1,10 +1,7 @@
|
|
1
1
|
import { createPipeline } from "../farrow-pipeline";
|
2
2
|
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for("MODERN_PARALLEL_WORKFLOW");
|
3
|
-
|
4
|
-
|
5
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[PARALLEL_WORKFLOW_SYMBOL]);
|
6
|
-
};
|
7
|
-
export const createParallelWorkflow = () => {
|
3
|
+
const isParallelWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
4
|
+
const createParallelWorkflow = () => {
|
8
5
|
const pipeline = createPipeline();
|
9
6
|
const use = (...input) => {
|
10
7
|
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
@@ -25,3 +22,7 @@ const mapParallelWorkerToAsyncMiddleware = (worker) => (input, next) => [
|
|
25
22
|
worker(input),
|
26
23
|
...next(input)
|
27
24
|
];
|
25
|
+
export {
|
26
|
+
createParallelWorkflow,
|
27
|
+
isParallelWorkflow
|
28
|
+
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createPipeline } from "../farrow-pipeline";
|
2
2
|
const WORKFLOW_SYMBOL = Symbol.for("MODERN_WORKFLOW");
|
3
|
-
|
3
|
+
const createWorkflow = () => {
|
4
4
|
const pipeline = createPipeline();
|
5
5
|
const use = (...input) => {
|
6
6
|
pipeline.use(...input.map(mapWorkerToMiddleware));
|
@@ -20,11 +20,12 @@ export const createWorkflow = () => {
|
|
20
20
|
};
|
21
21
|
return workflow;
|
22
22
|
};
|
23
|
-
|
24
|
-
var _input;
|
25
|
-
return Boolean((_input = input) === null || _input === void 0 ? void 0 : _input[WORKFLOW_SYMBOL]);
|
26
|
-
};
|
23
|
+
const isWorkflow = (input) => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
27
24
|
const mapWorkerToMiddleware = (worker) => (input, next) => [
|
28
25
|
worker(input),
|
29
26
|
...next(input)
|
30
27
|
];
|
28
|
+
export {
|
29
|
+
createWorkflow,
|
30
|
+
isWorkflow
|
31
|
+
};
|