@modern-js/plugin 1.0.1 → 1.2.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 +20 -2
- package/dist/js/modern/index.js +2 -3
- package/dist/js/modern/manager/async.js +3 -3
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +3 -8
- package/dist/js/modern/waterfall/async.js +28 -34
- package/dist/js/modern/waterfall/sync.js +29 -36
- package/dist/js/modern/workflow/async.js +31 -30
- package/dist/js/modern/workflow/parallel.js +20 -29
- package/dist/js/modern/workflow/sync.js +20 -27
- package/dist/js/node/index.js +12 -25
- package/dist/js/node/manager/async.js +6 -6
- package/dist/js/node/manager/runner.js +2 -2
- package/dist/js/node/manager/sync.js +8 -14
- package/dist/js/node/waterfall/async.js +27 -34
- package/dist/js/node/waterfall/sync.js +29 -36
- package/dist/js/node/workflow/async.js +30 -30
- package/dist/js/node/workflow/parallel.js +19 -29
- package/dist/js/node/workflow/sync.js +19 -27
- package/dist/js/treeshaking/index.js +2 -3
- package/dist/js/treeshaking/manager/async.js +3 -3
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +3 -8
- package/dist/js/treeshaking/waterfall/async.js +63 -108
- package/dist/js/treeshaking/waterfall/sync.js +36 -39
- package/dist/js/treeshaking/workflow/async.js +89 -88
- package/dist/js/treeshaking/workflow/parallel.js +42 -66
- package/dist/js/treeshaking/workflow/sync.js +50 -30
- package/dist/types/index.d.ts +2 -3
- package/dist/types/manager/runner.d.ts +1 -1
- package/dist/types/manager/sync.d.ts +2 -3
- package/dist/types/waterfall/async.d.ts +9 -5
- package/dist/types/waterfall/sync.d.ts +4 -4
- package/dist/types/workflow/async.d.ts +3 -2
- package/dist/types/workflow/parallel.d.ts +1 -1
- package/dist/types/workflow/sync.d.ts +1 -1
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/node.d.ts +1 -1
- package/node.js +1 -1
- package/package.json +13 -7
- package/src/index.ts +2 -2
- package/src/manager/async.ts +1 -1
- package/src/manager/runner.ts +1 -1
- package/src/manager/sync.ts +12 -16
- package/src/waterfall/async.ts +34 -49
- package/src/waterfall/sync.ts +26 -45
- package/src/workflow/async.ts +29 -33
- package/src/workflow/parallel.ts +17 -35
- package/src/workflow/sync.ts +13 -35
- package/tests/async.test.ts +14 -10
- package/tests/fixtures/async/base/fooManager.ts +1 -1
- package/tests/fixtures/async/core/index.ts +1 -1
- package/tests/fixtures/async/dynamic/foo.ts +1 -1
- package/tests/fixtures/sync/base/fooManager.ts +1 -1
- package/tests/fixtures/sync/core/index.ts +1 -1
- package/tests/fixtures/sync/dynamic/foo.ts +1 -1
- package/tests/pipeline.test.ts +6 -16
- package/tests/sync.test.ts +13 -9
- package/tests/tsconfig.json +1 -3
- package/tests/waterfall.test.ts +3 -3
- package/tests/workflow.test.ts +2 -2
- package/tsconfig.json +1 -3
- package/dist/js/modern/asyncHooksImpl.js +0 -63
- package/dist/js/modern/asyncHooksInterface.js +0 -16
- package/dist/js/modern/context.js +0 -130
- package/dist/js/modern/counter.js +0 -40
- package/dist/js/modern/hook.js +0 -47
- package/dist/js/modern/pipeline/async.js +0 -97
- package/dist/js/modern/pipeline/index.js +0 -2
- package/dist/js/modern/pipeline/sync.js +0 -97
- package/dist/js/node/asyncHooksImpl.js +0 -82
- package/dist/js/node/asyncHooksInterface.js +0 -30
- package/dist/js/node/context.js +0 -164
- package/dist/js/node/counter.js +0 -52
- package/dist/js/node/hook.js +0 -57
- package/dist/js/node/pipeline/async.js +0 -110
- package/dist/js/node/pipeline/index.js +0 -31
- package/dist/js/node/pipeline/sync.js +0 -110
- package/dist/js/treeshaking/asyncHooksImpl.js +0 -65
- package/dist/js/treeshaking/asyncHooksInterface.js +0 -16
- package/dist/js/treeshaking/context.js +0 -137
- package/dist/js/treeshaking/counter.js +0 -74
- package/dist/js/treeshaking/hook.js +0 -51
- package/dist/js/treeshaking/pipeline/async.js +0 -165
- package/dist/js/treeshaking/pipeline/index.js +0 -2
- package/dist/js/treeshaking/pipeline/sync.js +0 -118
- package/dist/types/asyncHooksImpl.d.ts +0 -10
- package/dist/types/asyncHooksInterface.d.ts +0 -21
- package/dist/types/context.d.ts +0 -47
- package/dist/types/counter.d.ts +0 -22
- package/dist/types/hook.d.ts +0 -13
- package/dist/types/pipeline/async.d.ts +0 -35
- package/dist/types/pipeline/index.d.ts +0 -2
- package/dist/types/pipeline/sync.d.ts +0 -37
- package/src/asyncHooksImpl.ts +0 -64
- package/src/asyncHooksInterface.ts +0 -34
- package/src/context.ts +0 -184
- package/src/counter.ts +0 -78
- package/src/hook.ts +0 -46
- package/src/pipeline/async.ts +0 -155
- package/src/pipeline/index.ts +0 -2
- package/src/pipeline/sync.ts +0 -152
- package/tests/context.test.ts +0 -114
- package/tests/counter.test.ts +0 -31
- package/tests/hook.test.ts +0 -113
@@ -5,19 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.hasOwnProperty = exports.generateRunner = exports.createManager = exports.cloneProgressRecord = exports.cloneProgress = exports.DEFAULT_OPTIONS = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
10
|
var _waterfall = require("../waterfall");
|
11
11
|
|
12
12
|
var _workflow = require("../workflow");
|
13
13
|
|
14
|
-
var _pipeline = require("../pipeline");
|
15
|
-
|
16
14
|
var _runner = require("./runner");
|
17
15
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
19
17
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
21
19
|
|
22
20
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
21
|
|
@@ -83,19 +81,19 @@ const createManager = processes => {
|
|
83
81
|
plugins = [];
|
84
82
|
};
|
85
83
|
|
86
|
-
const currentContainer = (0,
|
84
|
+
const currentContainer = (0, _farrowPipeline.createContainer)();
|
87
85
|
|
88
86
|
const init = options => {
|
89
87
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
90
88
|
const sortedPlugins = sortPlugins(plugins);
|
91
89
|
checkPlugins(sortedPlugins);
|
92
|
-
const hooksList = sortedPlugins.map(plugin => (0,
|
90
|
+
const hooksList = sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.initializer(), container));
|
93
91
|
return generateRunner(hooksList, container, processes);
|
94
92
|
};
|
95
93
|
|
96
94
|
const run = (cb, options) => {
|
97
95
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
98
|
-
return (0,
|
96
|
+
return (0, _farrowPipeline.runWithContainer)(cb, container);
|
99
97
|
};
|
100
98
|
|
101
99
|
return {
|
@@ -169,12 +167,8 @@ const cloneProgress = progress => {
|
|
169
167
|
return (0, _workflow.createParallelWorkflow)();
|
170
168
|
}
|
171
169
|
|
172
|
-
if ((0,
|
173
|
-
return (0,
|
174
|
-
}
|
175
|
-
|
176
|
-
if ((0, _pipeline.isAsyncPipeline)(progress)) {
|
177
|
-
return (0, _pipeline.createAsyncPipeline)();
|
170
|
+
if ((0, _farrowPipeline.isPipeline)(progress)) {
|
171
|
+
return (0, _farrowPipeline.createPipeline)();
|
178
172
|
} // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
179
173
|
|
180
174
|
|
@@ -5,17 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isAsyncWaterfall = exports.getAsyncBrook = exports.createAsyncWaterfall = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
|
-
var
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
15
|
|
12
16
|
const ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
|
13
17
|
|
14
18
|
const getAsyncBrook = input => {
|
15
19
|
if (typeof input === 'function') {
|
16
20
|
return input;
|
17
|
-
} else if (input && typeof input.
|
18
|
-
return input.
|
21
|
+
} else if (input && typeof input.middlware === 'function') {
|
22
|
+
return input.middlware;
|
19
23
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
20
24
|
|
21
25
|
|
@@ -26,48 +30,35 @@ exports.getAsyncBrook = getAsyncBrook;
|
|
26
30
|
|
27
31
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
28
32
|
const createAsyncWaterfall = () => {
|
29
|
-
const
|
30
|
-
|
31
|
-
const createCurrentRunner = hooks => (0, _counter.createAsyncCounter)(async (index, input, next) => {
|
32
|
-
if (index >= middlewares.length) {
|
33
|
-
return input;
|
34
|
-
}
|
35
|
-
|
36
|
-
return (0, _context.runHooks)(async () => next((await middlewares[index](input)) || input), hooks);
|
37
|
-
});
|
38
|
-
|
39
|
-
const currentContainer = (0, _context.createContainer)();
|
40
|
-
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
41
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
33
|
+
const pipeline = (0, _farrowPipeline.createAsyncPipeline)();
|
42
34
|
|
43
35
|
const use = (...input) => {
|
44
|
-
|
36
|
+
pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
|
45
37
|
return waterfall;
|
46
38
|
};
|
47
39
|
|
48
|
-
const run =
|
49
|
-
|
40
|
+
const run = (input, options) => // eslint-disable-next-line @typescript-eslint/no-shadow
|
41
|
+
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
42
|
+
onLast: input => input
|
43
|
+
}));
|
50
44
|
|
51
|
-
|
52
|
-
const hooks = container === currentContainer ? currentHooks : (0, _context.fromContainer)(container);
|
53
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
54
|
-
return runner.start(input);
|
55
|
-
};
|
56
|
-
|
57
|
-
const brook = input => {
|
45
|
+
const middlware = input => {
|
58
46
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
59
|
-
const container = (0,
|
60
|
-
|
61
|
-
|
47
|
+
const container = (0, _farrowPipeline.useContainer)(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
48
|
+
|
49
|
+
return pipeline.run(input, {
|
50
|
+
container,
|
51
|
+
onLast: input => input
|
62
52
|
});
|
63
53
|
};
|
64
54
|
|
65
|
-
const waterfall = {
|
55
|
+
const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
|
66
56
|
use,
|
67
57
|
run,
|
68
|
-
|
58
|
+
middlware,
|
69
59
|
[ASYNC_WATERFALL_SYMBOL]: true
|
70
|
-
};
|
60
|
+
});
|
61
|
+
|
71
62
|
return waterfall;
|
72
63
|
};
|
73
64
|
|
@@ -75,4 +66,6 @@ exports.createAsyncWaterfall = createAsyncWaterfall;
|
|
75
66
|
|
76
67
|
const isAsyncWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
77
68
|
|
78
|
-
exports.isAsyncWaterfall = isAsyncWaterfall;
|
69
|
+
exports.isAsyncWaterfall = isAsyncWaterfall;
|
70
|
+
|
71
|
+
const mapAsyncBrookToAsyncMiddleware = brook => async (input, next) => next(await brook(input));
|
@@ -5,17 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isWaterfall = exports.getBrook = exports.createWaterfall = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
|
-
var
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
11
|
|
12
|
-
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15
|
+
|
16
|
+
const WATERFALL_SYMBOL = Symbol('WATERFALL_SYMBOL');
|
13
17
|
|
14
18
|
const getBrook = input => {
|
15
19
|
if (typeof input === 'function') {
|
16
20
|
return input;
|
17
|
-
} else if (input && typeof input.
|
18
|
-
return input.
|
21
|
+
} else if (input && typeof input.middleware === 'function') {
|
22
|
+
return input.middleware;
|
19
23
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
20
24
|
|
21
25
|
|
@@ -26,48 +30,35 @@ exports.getBrook = getBrook;
|
|
26
30
|
|
27
31
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
28
32
|
const createWaterfall = () => {
|
29
|
-
const
|
33
|
+
const pipeline = (0, _farrowPipeline.createPipeline)();
|
30
34
|
|
31
|
-
const
|
32
|
-
|
33
|
-
return input;
|
34
|
-
}
|
35
|
-
|
36
|
-
return (0, _context.runHooks)(() => next(middlewares[index](input) || input), hooks);
|
37
|
-
});
|
38
|
-
|
39
|
-
const currentContainer = (0, _context.createContainer)();
|
40
|
-
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
41
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
42
|
-
|
43
|
-
const use = (...input) => {
|
44
|
-
middlewares.push(...input.map(getBrook));
|
35
|
+
const use = (...brooks) => {
|
36
|
+
pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
|
45
37
|
return waterfall;
|
46
38
|
};
|
47
39
|
|
48
|
-
const run = (input, options) =>
|
49
|
-
|
40
|
+
const run = (input, options) => // eslint-disable-next-line @typescript-eslint/no-shadow
|
41
|
+
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
42
|
+
onLast: input => input
|
43
|
+
}));
|
50
44
|
|
51
|
-
|
52
|
-
const hooks = container === currentContainer ? currentHooks : (0, _context.fromContainer)(container);
|
53
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
54
|
-
return runner.start(input);
|
55
|
-
};
|
56
|
-
|
57
|
-
const brook = input => {
|
45
|
+
const middleware = input => {
|
58
46
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
59
|
-
const container = (0,
|
60
|
-
|
61
|
-
|
47
|
+
const container = (0, _farrowPipeline.useContainer)(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
48
|
+
|
49
|
+
return pipeline.run(input, {
|
50
|
+
container,
|
51
|
+
onLast: input => input
|
62
52
|
});
|
63
53
|
};
|
64
54
|
|
65
|
-
const waterfall = {
|
55
|
+
const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
|
66
56
|
use,
|
67
57
|
run,
|
68
|
-
|
58
|
+
middleware,
|
69
59
|
[WATERFALL_SYMBOL]: true
|
70
|
-
};
|
60
|
+
});
|
61
|
+
|
71
62
|
return waterfall;
|
72
63
|
};
|
73
64
|
|
@@ -75,4 +66,6 @@ exports.createWaterfall = createWaterfall;
|
|
75
66
|
|
76
67
|
const isWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
77
68
|
|
78
|
-
exports.isWaterfall = isWaterfall;
|
69
|
+
exports.isWaterfall = isWaterfall;
|
70
|
+
|
71
|
+
const mapBrookToMiddleware = brook => (input, next) => next(brook(input));
|
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isAsyncWorkflow = exports.createAsyncWorkflow = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
|
-
var
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
15
|
|
12
16
|
const ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
|
13
17
|
|
@@ -17,45 +21,41 @@ const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? vo
|
|
17
21
|
exports.isAsyncWorkflow = isAsyncWorkflow;
|
18
22
|
|
19
23
|
const createAsyncWorkflow = () => {
|
20
|
-
const
|
21
|
-
|
22
|
-
const createCurrentRunner = hooks => (0, _counter.createAsyncCounter)(async (index, input, next) => {
|
23
|
-
if (index >= middlewares.length) {
|
24
|
-
return [];
|
25
|
-
}
|
26
|
-
|
27
|
-
const middleware = middlewares[index];
|
28
|
-
return (0, _context.runHooks)(async () => {
|
29
|
-
const result = await middleware(input);
|
30
|
-
const rest = await next(input);
|
31
|
-
return [result, ...rest];
|
32
|
-
}, hooks);
|
33
|
-
});
|
34
|
-
|
35
|
-
const currentContainer = (0, _context.createContainer)();
|
36
|
-
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
37
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
24
|
+
const pipeline = (0, _farrowPipeline.createAsyncPipeline)();
|
38
25
|
|
39
26
|
const use = (...input) => {
|
40
|
-
|
27
|
+
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
41
28
|
return workflow;
|
42
29
|
};
|
43
30
|
|
44
31
|
const run = async (input, options) => {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
32
|
+
const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
33
|
+
onLast: () => []
|
34
|
+
}));
|
35
|
+
|
36
|
+
if (isPromise(result)) {
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow,promise/prefer-await-to-then
|
38
|
+
return result.then(result => result.filter(Boolean));
|
39
|
+
} else {
|
40
|
+
return result.filter(Boolean);
|
41
|
+
}
|
51
42
|
};
|
52
43
|
|
53
|
-
const workflow = {
|
44
|
+
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
54
45
|
use,
|
55
46
|
run,
|
56
47
|
[ASYNC_WORKFLOW_SYMBOL]: true
|
57
|
-
};
|
48
|
+
});
|
49
|
+
|
58
50
|
return workflow;
|
59
51
|
};
|
60
52
|
|
61
|
-
exports.createAsyncWorkflow = createAsyncWorkflow;
|
53
|
+
exports.createAsyncWorkflow = createAsyncWorkflow;
|
54
|
+
|
55
|
+
const mapAsyncWorkerToAsyncMiddleware = worker => async (input, next) => [await worker(input), ...(await next(input))];
|
56
|
+
|
57
|
+
function isPromise(obj) {
|
58
|
+
/* eslint-disable promise/prefer-await-to-then */
|
59
|
+
return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
60
|
+
/* eslint-enable promise/prefer-await-to-then */
|
61
|
+
}
|
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isParallelWorkflow = exports.createParallelWorkflow = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
|
-
var
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
15
|
|
12
16
|
const PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
|
13
17
|
|
@@ -16,41 +20,27 @@ const isParallelWorkflow = input => Boolean(input === null || input === void 0 ?
|
|
16
20
|
exports.isParallelWorkflow = isParallelWorkflow;
|
17
21
|
|
18
22
|
const createParallelWorkflow = () => {
|
19
|
-
const
|
20
|
-
|
21
|
-
const createCurrentRunner = hooks => (0, _counter.createAsyncCounter)((index, input, next) => {
|
22
|
-
if (index >= middlewares.length) {
|
23
|
-
return Promise.resolve([]);
|
24
|
-
}
|
25
|
-
|
26
|
-
const middleware = middlewares[index];
|
27
|
-
return (0, _context.runHooks)(async () => Promise.all([middleware(input), ...(await next(input))]), hooks);
|
28
|
-
});
|
29
|
-
|
30
|
-
const currentContainer = (0, _context.createContainer)();
|
31
|
-
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
32
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
23
|
+
const pipeline = (0, _farrowPipeline.createPipeline)();
|
33
24
|
|
34
25
|
const use = (...input) => {
|
35
|
-
|
26
|
+
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
36
27
|
return workflow;
|
37
28
|
};
|
38
29
|
|
39
|
-
const run = async (input, options) =>
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
const hooks = container === currentContainer ? currentHooks : (0, _context.fromContainer)(container);
|
44
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
45
|
-
return runner.start(input);
|
46
|
-
};
|
30
|
+
const run = async (input, options) => // eslint-disable-next-line promise/prefer-await-to-then
|
31
|
+
Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
32
|
+
onLast: () => []
|
33
|
+
}))).then(result => result.filter(Boolean));
|
47
34
|
|
48
|
-
const workflow = {
|
49
|
-
use,
|
35
|
+
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
50
36
|
run,
|
37
|
+
use,
|
51
38
|
[PARALLEL_WORKFLOW_SYMBOL]: true
|
52
|
-
};
|
39
|
+
});
|
40
|
+
|
53
41
|
return workflow;
|
54
42
|
};
|
55
43
|
|
56
|
-
exports.createParallelWorkflow = createParallelWorkflow;
|
44
|
+
exports.createParallelWorkflow = createParallelWorkflow;
|
45
|
+
|
46
|
+
const mapParallelWorkerToAsyncMiddleware = worker => (input, next) => [worker(input), ...next(input)];
|
@@ -5,48 +5,38 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isWorkflow = exports.createWorkflow = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
|
-
var
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
11
|
+
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
|
14
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
11
15
|
|
12
16
|
const WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
13
17
|
|
14
18
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
15
19
|
const createWorkflow = () => {
|
16
|
-
const
|
17
|
-
|
18
|
-
const createCurrentRunner = hooks => (0, _counter.createCounter)((index, input, next) => {
|
19
|
-
if (index >= middlewares.length) {
|
20
|
-
return [];
|
21
|
-
}
|
22
|
-
|
23
|
-
const middleware = middlewares[index];
|
24
|
-
return (0, _context.runHooks)(() => [middleware(input), ...next(input)], hooks);
|
25
|
-
});
|
26
|
-
|
27
|
-
const currentContainer = (0, _context.createContainer)();
|
28
|
-
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
29
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
20
|
+
const pipeline = (0, _farrowPipeline.createPipeline)();
|
30
21
|
|
31
22
|
const use = (...input) => {
|
32
|
-
|
23
|
+
pipeline.use(...input.map(mapWorkerToMiddleware));
|
33
24
|
return workflow;
|
34
25
|
};
|
35
26
|
|
36
|
-
const run = (input, options) => {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
42
|
-
return runner.start(input);
|
27
|
+
const run = async (input, options) => {
|
28
|
+
const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
29
|
+
onLast: () => []
|
30
|
+
}));
|
31
|
+
return result.filter(Boolean);
|
43
32
|
};
|
44
33
|
|
45
|
-
const workflow = {
|
34
|
+
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
46
35
|
use,
|
47
36
|
run,
|
48
37
|
[WORKFLOW_SYMBOL]: true
|
49
|
-
};
|
38
|
+
});
|
39
|
+
|
50
40
|
return workflow;
|
51
41
|
};
|
52
42
|
|
@@ -54,4 +44,6 @@ exports.createWorkflow = createWorkflow;
|
|
54
44
|
|
55
45
|
const isWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
56
46
|
|
57
|
-
exports.isWorkflow = isWorkflow;
|
47
|
+
exports.isWorkflow = isWorkflow;
|
48
|
+
|
49
|
+
const mapWorkerToMiddleware = worker => (input, next) => [worker(input), ...next(input)];
|
@@ -18,13 +18,13 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
18
18
|
|
19
19
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
20
20
|
|
21
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
21
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
22
22
|
|
23
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
23
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
24
24
|
|
25
25
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
26
26
|
|
27
|
-
import { runWithContainer, createContainer } from
|
27
|
+
import { runWithContainer, createContainer } from 'farrow-pipeline';
|
28
28
|
import { generateRunner, hasOwnProperty, DEFAULT_OPTIONS } from "./sync";
|
29
29
|
import { useRunner } from "./runner"; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
30
30
|
|
@@ -12,19 +12,18 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
12
12
|
|
13
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
14
14
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
15
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
16
16
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
17
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
18
18
|
|
19
19
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
20
20
|
|
21
21
|
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
22
22
|
|
23
23
|
/* eslint-disable max-lines */
|
24
|
-
import { runWithContainer, createContainer } from
|
24
|
+
import { isPipeline, createPipeline, runWithContainer, createContainer } from 'farrow-pipeline';
|
25
25
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
26
26
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
27
|
-
import { isPipeline, createPipeline, isAsyncPipeline, createAsyncPipeline } from "../pipeline";
|
28
27
|
import { RunnerContext, useRunner } from "./runner"; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
29
28
|
|
30
29
|
var SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
@@ -201,10 +200,6 @@ export var cloneProgress = function cloneProgress(progress) {
|
|
201
200
|
|
202
201
|
if (isPipeline(progress)) {
|
203
202
|
return createPipeline();
|
204
|
-
}
|
205
|
-
|
206
|
-
if (isAsyncPipeline(progress)) {
|
207
|
-
return createAsyncPipeline();
|
208
203
|
} // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
209
204
|
|
210
205
|
|