@modern-js/plugin 1.0.0 → 1.1.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 +18 -0
- package/README.md +1 -4
- package/dist/js/modern/index.js +2 -3
- package/dist/js/modern/manager/async.js +1 -1
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +1 -6
- 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 +4 -4
- package/dist/js/node/manager/runner.js +2 -2
- package/dist/js/node/manager/sync.js +6 -12
- 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 +1 -1
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +1 -6
- 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/node.d.ts +1 -1
- package/node.js +1 -1
- package/package.json +5 -4
- 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/.eslintrc.js +6 -0
- package/tests/async.test.ts +7 -3
- package/tests/fixtures/async/base/foo.ts +0 -1
- package/tests/fixtures/async/base/fooManager.ts +1 -1
- package/tests/fixtures/async/core/index.ts +1 -1
- package/tests/fixtures/async/dynamic/bar.ts +0 -1
- package/tests/fixtures/async/dynamic/foo.ts +1 -1
- package/tests/fixtures/sync/base/foo.ts +0 -2
- package/tests/fixtures/sync/base/fooManager.ts +1 -1
- package/tests/fixtures/sync/core/index.ts +1 -1
- package/tests/fixtures/sync/dynamic/bar.ts +0 -1
- package/tests/fixtures/sync/dynamic/foo.ts +1 -1
- package/tests/pipeline.test.ts +4 -15
- package/tests/sync.test.ts +6 -2
- package/tests/waterfall.test.ts +1 -2
- 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 -32
- package/tests/hook.test.ts +0 -113
@@ -1,6 +1,14 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
|
+
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
4
|
+
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
6
|
+
|
1
7
|
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; }
|
2
8
|
|
3
|
-
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
10
|
+
|
11
|
+
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); }); }; }
|
4
12
|
|
5
13
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
6
14
|
|
@@ -14,93 +22,61 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
14
22
|
|
15
23
|
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; }
|
16
24
|
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
-
import { createAsyncCounter } from "../counter";
|
22
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
25
|
+
import { createPipeline } from 'farrow-pipeline';
|
23
26
|
var PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
|
24
27
|
export var isParallelWorkflow = function isParallelWorkflow(input) {
|
25
28
|
return Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
26
29
|
};
|
27
30
|
export var createParallelWorkflow = function createParallelWorkflow() {
|
28
|
-
var
|
29
|
-
|
30
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
31
|
-
return createAsyncCounter(function (index, input, next) {
|
32
|
-
if (index >= middlewares.length) {
|
33
|
-
return Promise.resolve([]);
|
34
|
-
}
|
35
|
-
|
36
|
-
var middleware = middlewares[index];
|
37
|
-
return runHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
38
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
39
|
-
while (1) {
|
40
|
-
switch (_context.prev = _context.next) {
|
41
|
-
case 0:
|
42
|
-
_context.t0 = Promise;
|
43
|
-
_context.t1 = [middleware(input)];
|
44
|
-
_context.t2 = _toConsumableArray;
|
45
|
-
_context.next = 5;
|
46
|
-
return next(input);
|
47
|
-
|
48
|
-
case 5:
|
49
|
-
_context.t3 = _context.sent;
|
50
|
-
_context.t4 = (0, _context.t2)(_context.t3);
|
51
|
-
_context.t5 = _context.t1.concat.call(_context.t1, _context.t4);
|
52
|
-
return _context.abrupt("return", _context.t0.all.call(_context.t0, _context.t5));
|
53
|
-
|
54
|
-
case 9:
|
55
|
-
case "end":
|
56
|
-
return _context.stop();
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}, _callee);
|
60
|
-
})), hooks);
|
61
|
-
});
|
62
|
-
};
|
63
|
-
|
64
|
-
var currentContainer = createContainer();
|
65
|
-
var currentHooks = fromContainer(currentContainer);
|
66
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
31
|
+
var pipeline = createPipeline();
|
67
32
|
|
68
33
|
var use = function use() {
|
69
|
-
|
34
|
+
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
35
|
+
input[_key] = arguments[_key];
|
36
|
+
}
|
37
|
+
|
38
|
+
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapParallelWorkerToAsyncMiddleware)));
|
70
39
|
return workflow;
|
71
40
|
};
|
72
41
|
|
73
42
|
var run = /*#__PURE__*/function () {
|
74
|
-
var
|
75
|
-
|
76
|
-
|
77
|
-
var container, hooks, runner;
|
78
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
43
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
44
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
79
45
|
while (1) {
|
80
|
-
switch (
|
46
|
+
switch (_context.prev = _context.next) {
|
81
47
|
case 0:
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
48
|
+
return _context.abrupt("return", // eslint-disable-next-line promise/prefer-await-to-then
|
49
|
+
Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
50
|
+
onLast: function onLast() {
|
51
|
+
return [];
|
52
|
+
}
|
53
|
+
}))).then(function (result) {
|
54
|
+
return result.filter(Boolean);
|
55
|
+
}));
|
56
|
+
|
57
|
+
case 1:
|
88
58
|
case "end":
|
89
|
-
return
|
59
|
+
return _context.stop();
|
90
60
|
}
|
91
61
|
}
|
92
|
-
},
|
62
|
+
}, _callee);
|
93
63
|
}));
|
94
64
|
|
95
65
|
return function run(_x, _x2) {
|
96
|
-
return
|
66
|
+
return _ref.apply(this, arguments);
|
97
67
|
};
|
98
68
|
}();
|
99
69
|
|
100
|
-
var workflow = _defineProperty({
|
101
|
-
|
102
|
-
|
103
|
-
}, PARALLEL_WORKFLOW_SYMBOL, true);
|
70
|
+
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
71
|
+
run: run,
|
72
|
+
use: use
|
73
|
+
}, PARALLEL_WORKFLOW_SYMBOL, true));
|
104
74
|
|
105
75
|
return workflow;
|
76
|
+
};
|
77
|
+
|
78
|
+
var mapParallelWorkerToAsyncMiddleware = function mapParallelWorkerToAsyncMiddleware(worker) {
|
79
|
+
return function (input, next) {
|
80
|
+
return [worker(input)].concat(_toConsumableArray(next(input)));
|
81
|
+
};
|
106
82
|
};
|
@@ -1,5 +1,15 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
|
+
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
4
|
+
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
6
|
+
|
1
7
|
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; }
|
2
8
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
10
|
+
|
11
|
+
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); }); }; }
|
12
|
+
|
3
13
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
4
14
|
|
5
15
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
@@ -12,51 +22,61 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
12
22
|
|
13
23
|
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
24
|
|
15
|
-
import {
|
16
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
25
|
+
import { createPipeline } from 'farrow-pipeline';
|
17
26
|
var WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
18
27
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
19
28
|
export var createWorkflow = function createWorkflow() {
|
20
|
-
var
|
21
|
-
|
22
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
23
|
-
return createCounter(function (index, input, next) {
|
24
|
-
if (index >= middlewares.length) {
|
25
|
-
return [];
|
26
|
-
}
|
27
|
-
|
28
|
-
var middleware = middlewares[index];
|
29
|
-
return runHooks(function () {
|
30
|
-
return [middleware(input)].concat(_toConsumableArray(next(input)));
|
31
|
-
}, hooks);
|
32
|
-
});
|
33
|
-
};
|
34
|
-
|
35
|
-
var currentContainer = createContainer();
|
36
|
-
var currentHooks = fromContainer(currentContainer);
|
37
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
29
|
+
var pipeline = createPipeline();
|
38
30
|
|
39
31
|
var use = function use() {
|
40
|
-
|
32
|
+
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
33
|
+
input[_key] = arguments[_key];
|
34
|
+
}
|
35
|
+
|
36
|
+
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapWorkerToMiddleware)));
|
41
37
|
return workflow;
|
42
38
|
};
|
43
39
|
|
44
|
-
var run = function
|
45
|
-
var
|
40
|
+
var run = /*#__PURE__*/function () {
|
41
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
42
|
+
var result;
|
43
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
44
|
+
while (1) {
|
45
|
+
switch (_context.prev = _context.next) {
|
46
|
+
case 0:
|
47
|
+
result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
48
|
+
onLast: function onLast() {
|
49
|
+
return [];
|
50
|
+
}
|
51
|
+
}));
|
52
|
+
return _context.abrupt("return", result.filter(Boolean));
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
case 2:
|
55
|
+
case "end":
|
56
|
+
return _context.stop();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}, _callee);
|
60
|
+
}));
|
61
|
+
|
62
|
+
return function run(_x, _x2) {
|
63
|
+
return _ref.apply(this, arguments);
|
64
|
+
};
|
65
|
+
}();
|
52
66
|
|
53
|
-
var workflow = _defineProperty({
|
67
|
+
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
54
68
|
use: use,
|
55
69
|
run: run
|
56
|
-
}, WORKFLOW_SYMBOL, true);
|
70
|
+
}, WORKFLOW_SYMBOL, true));
|
57
71
|
|
58
72
|
return workflow;
|
59
73
|
};
|
60
74
|
export var isWorkflow = function isWorkflow(input) {
|
61
75
|
return Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
76
|
+
};
|
77
|
+
|
78
|
+
var mapWorkerToMiddleware = function mapWorkerToMiddleware(worker) {
|
79
|
+
return function (input, next) {
|
80
|
+
return [worker(input)].concat(_toConsumableArray(next(input)));
|
81
|
+
};
|
62
82
|
};
|
package/dist/types/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const RunnerContext: import("
|
1
|
+
export declare const RunnerContext: import("farrow-pipeline").Context<any>;
|
2
2
|
export declare const useRunner: () => any;
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { Container } from '
|
1
|
+
import { Middleware, Pipeline, AsyncPipeline, MaybeAsync, Container } from 'farrow-pipeline';
|
2
2
|
import { Waterfall, Brook, AsyncWaterfall, AsyncBrook } from '../waterfall';
|
3
3
|
import { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
|
4
|
-
import { Middleware, Pipeline, AsyncMiddleware, AsyncPipeline } from '../pipeline';
|
5
4
|
export declare type Initializer<O> = () => O | void;
|
6
5
|
declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
7
6
|
export declare type Plugin<O> = {
|
@@ -21,7 +20,7 @@ export declare type PluginOptions = {
|
|
21
20
|
required?: string[];
|
22
21
|
};
|
23
22
|
export declare type Progress = Waterfall<any> | AsyncWaterfall<any> | Workflow<any, any> | AsyncWorkflow<any, any> | ParallelWorkflow<any> | Pipeline<any, any> | AsyncPipeline<any, any>;
|
24
|
-
export declare type Progress2Thread<P extends Progress> = P extends Workflow<infer I, infer O> ? Worker<I, O> : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends ParallelWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends Waterfall<infer I> ? Brook<I> : P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : P extends Pipeline<infer I, infer O> ? Middleware<I, O> : P extends AsyncPipeline<infer I, infer O> ?
|
23
|
+
export declare type Progress2Thread<P extends Progress> = P extends Workflow<infer I, infer O> ? Worker<I, O> : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends ParallelWorkflow<infer I, infer O> ? AsyncWorker<I, O> : P extends Waterfall<infer I> ? Brook<I> : P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : P extends Pipeline<infer I, infer O> ? Middleware<I, O> : P extends AsyncPipeline<infer I, infer O> ? Middleware<I, MaybeAsync<O>> : never;
|
25
24
|
export declare type ProgressRecord = Record<string, Progress>;
|
26
25
|
export declare type Progresses2Threads<PS extends ProgressRecord | void> = { [K in keyof PS]: PS[K] extends Progress ? Progress2Thread<PS[K]> : PS[K] extends void ? void : never };
|
27
26
|
export declare type RunnerFromProgress<P extends Progress> = P extends Waterfall<infer I> ? Waterfall<I>['run'] : P extends AsyncWaterfall<infer I> ? AsyncWaterfall<I>['run'] : P extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : P extends AsyncWorkflow<infer I, infer O> ? AsyncWorkflow<I, O>['run'] : P extends ParallelWorkflow<infer I, infer O> ? ParallelWorkflow<I, O>['run'] : P extends Pipeline<infer I, infer O> ? Pipeline<I, O>['run'] : P extends AsyncPipeline<infer I, infer O> ? AsyncPipeline<I, O>['run'] : never;
|
@@ -1,16 +1,20 @@
|
|
1
|
-
import
|
1
|
+
import { MaybeAsync, Container } from 'farrow-pipeline';
|
2
2
|
declare const ASYNC_WATERFALL_SYMBOL: unique symbol;
|
3
|
-
export declare type AsyncBrook<I = unknown> = (I: I) =>
|
3
|
+
export declare type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
|
4
4
|
export declare type AsyncBrookInput<I = unknown> = AsyncBrook<I> | {
|
5
|
-
|
5
|
+
middlware: AsyncBrook<I>;
|
6
6
|
};
|
7
7
|
export declare type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
|
8
8
|
export declare type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
|
9
9
|
export declare const getAsyncBrook: <I>(input: AsyncBrookInput<I>) => AsyncBrook<I>;
|
10
|
+
export declare type RunAsyncWaterfallOptions<I = unknown> = {
|
11
|
+
container?: Container;
|
12
|
+
onLast?: AsyncBrook<I>;
|
13
|
+
};
|
10
14
|
export declare type AsyncWaterfall<I> = {
|
11
|
-
run: (input: I, options?:
|
15
|
+
run: (input: I, options?: RunAsyncWaterfallOptions<I>) => MaybeAsync<I>;
|
12
16
|
use: (...I: AsyncBrookInputs<I>) => AsyncWaterfall<I>;
|
13
|
-
|
17
|
+
middlware: AsyncBrook<I>;
|
14
18
|
[ASYNC_WATERFALL_SYMBOL]: true;
|
15
19
|
};
|
16
20
|
export declare type AsyncWaterfall2AsyncBrook<P extends AsyncWaterfall<any>> = P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : never;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { Container } from '
|
1
|
+
import { Container } from 'farrow-pipeline';
|
2
2
|
declare const WATERFALL_SYMBOL: unique symbol;
|
3
|
-
export declare type Brook<I = unknown> = (I: I) => I
|
3
|
+
export declare type Brook<I = unknown> = (I: I) => I;
|
4
4
|
export declare type BrookInput<I = unknown> = Brook<I> | {
|
5
|
-
|
5
|
+
middleware: Brook<I>;
|
6
6
|
};
|
7
7
|
export declare type Brooks<I = unknown> = Brook<I>[];
|
8
8
|
export declare type BrookInputs<I = unknown> = BrookInput<I>[];
|
@@ -14,7 +14,7 @@ export declare type RunWaterfallOptions<I = unknown> = {
|
|
14
14
|
export declare type Waterfall<I = void> = {
|
15
15
|
run: (input: I, options?: RunWaterfallOptions<I>) => I;
|
16
16
|
use: (...I: BrookInputs<I>) => Waterfall<I>;
|
17
|
-
|
17
|
+
middleware: Brook<I>;
|
18
18
|
[WATERFALL_SYMBOL]: true;
|
19
19
|
};
|
20
20
|
export declare type Waterfall2Brook<P extends Waterfall<any>> = P extends Waterfall<infer I> ? Brook<I> : never;
|
@@ -1,9 +1,10 @@
|
|
1
|
+
import { MaybeAsync } from 'farrow-pipeline';
|
1
2
|
import type { RunWorkflowOptions } from './sync';
|
2
3
|
declare const ASYNC_WORKFLOW_SYMBOL: unique symbol;
|
3
|
-
export declare type AsyncWorker<I, O> = (I: I) =>
|
4
|
+
export declare type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
|
4
5
|
export declare type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
|
5
6
|
export declare type AsyncWorkflow<I, O> = {
|
6
|
-
run: (input: I, options?: RunWorkflowOptions) =>
|
7
|
+
run: (input: I, options?: RunWorkflowOptions) => MaybeAsync<O[]>;
|
7
8
|
use: (...I: AsyncWorkers<I, O>) => AsyncWorkflow<I, O>;
|
8
9
|
[ASYNC_WORKFLOW_SYMBOL]: true;
|
9
10
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AsyncWorker, AsyncWorkers } from './async';
|
1
|
+
import type { AsyncWorker, AsyncWorkers } from './async';
|
2
2
|
import type { RunWorkflowOptions } from './sync';
|
3
3
|
declare const PARALLEL_WORKFLOW_SYMBOL: unique symbol;
|
4
4
|
export declare type ParallelWorkflow<I, O = any> = {
|
package/node.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from '
|
1
|
+
export * from 'farrow-pipeline/asyncHooks.node';
|
package/node.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
module.exports = require('
|
1
|
+
module.exports = require('farrow-pipeline/asyncHooks.node');
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.1.2",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -30,14 +30,15 @@
|
|
30
30
|
}
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
|
-
"@babel/runtime": "^7"
|
33
|
+
"@babel/runtime": "^7",
|
34
|
+
"farrow-pipeline": "^1.10.6"
|
34
35
|
},
|
35
36
|
"devDependencies": {
|
36
37
|
"@types/jest": "^26",
|
37
38
|
"@types/node": "^14",
|
38
39
|
"typescript": "^4",
|
39
|
-
"@modern-js/plugin-testing": "^1.
|
40
|
-
"@modern-js/module-tools": "^1.
|
40
|
+
"@modern-js/plugin-testing": "^1.1.0",
|
41
|
+
"@modern-js/module-tools": "^1.1.0"
|
41
42
|
},
|
42
43
|
"sideEffects": false,
|
43
44
|
"publishConfig": {
|
package/src/index.ts
CHANGED
package/src/manager/async.ts
CHANGED
package/src/manager/runner.ts
CHANGED
package/src/manager/sync.ts
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
2
2
|
/* eslint-disable max-lines */
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
Middleware,
|
5
|
+
Pipeline,
|
6
|
+
isPipeline,
|
7
|
+
createPipeline,
|
8
|
+
AsyncPipeline,
|
9
|
+
MaybeAsync,
|
10
|
+
runWithContainer,
|
11
|
+
createContainer,
|
12
|
+
Container,
|
13
|
+
} from 'farrow-pipeline';
|
4
14
|
import {
|
5
15
|
Waterfall,
|
6
16
|
Brook,
|
@@ -24,16 +34,6 @@ import {
|
|
24
34
|
isParallelWorkflow,
|
25
35
|
createParallelWorkflow,
|
26
36
|
} from '../workflow';
|
27
|
-
import {
|
28
|
-
Middleware,
|
29
|
-
Pipeline,
|
30
|
-
isPipeline,
|
31
|
-
createPipeline,
|
32
|
-
AsyncMiddleware,
|
33
|
-
AsyncPipeline,
|
34
|
-
isAsyncPipeline,
|
35
|
-
createAsyncPipeline,
|
36
|
-
} from '../pipeline';
|
37
37
|
import { RunnerContext, useRunner } from './runner';
|
38
38
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
@@ -86,7 +86,7 @@ export type Progress2Thread<P extends Progress> = P extends Workflow<
|
|
86
86
|
: P extends Pipeline<infer I, infer O>
|
87
87
|
? Middleware<I, O>
|
88
88
|
: P extends AsyncPipeline<infer I, infer O>
|
89
|
-
?
|
89
|
+
? Middleware<I, MaybeAsync<O>>
|
90
90
|
: never;
|
91
91
|
|
92
92
|
export type ProgressRecord = Record<string, Progress>;
|
@@ -360,10 +360,6 @@ export const cloneProgress = (progress: Progress): Progress => {
|
|
360
360
|
return createPipeline();
|
361
361
|
}
|
362
362
|
|
363
|
-
if (isAsyncPipeline(progress)) {
|
364
|
-
return createAsyncPipeline();
|
365
|
-
}
|
366
|
-
|
367
363
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
368
364
|
throw new Error(`Unknown progress: ${progress}`);
|
369
365
|
};
|
package/src/waterfall/async.ts
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
import { createAsyncCounter } from '../counter';
|
2
1
|
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
createAsyncPipeline,
|
3
|
+
Middleware,
|
4
|
+
MaybeAsync,
|
5
|
+
Container,
|
7
6
|
useContainer,
|
8
|
-
} from '
|
9
|
-
import type { RunWaterfallOptions } from './sync';
|
7
|
+
} from 'farrow-pipeline';
|
10
8
|
|
11
9
|
const ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
|
12
10
|
|
13
|
-
export type AsyncBrook<I = unknown> = (
|
14
|
-
I: I,
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
16
|
-
) => I | Promise<I> | void | Promise<void>;
|
11
|
+
export type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
|
17
12
|
export type AsyncBrookInput<I = unknown> =
|
18
13
|
| AsyncBrook<I>
|
19
|
-
| {
|
14
|
+
| { middlware: AsyncBrook<I> };
|
20
15
|
export type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
|
21
16
|
export type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
|
22
17
|
|
23
18
|
export const getAsyncBrook = <I>(input: AsyncBrookInput<I>) => {
|
24
19
|
if (typeof input === 'function') {
|
25
20
|
return input;
|
26
|
-
} else if (input && typeof input.
|
27
|
-
return input.
|
21
|
+
} else if (input && typeof input.middlware === 'function') {
|
22
|
+
return input.middlware;
|
28
23
|
}
|
29
24
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
30
25
|
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
31
26
|
};
|
32
27
|
|
28
|
+
export type RunAsyncWaterfallOptions<I = unknown> = {
|
29
|
+
container?: Container;
|
30
|
+
onLast?: AsyncBrook<I>;
|
31
|
+
};
|
32
|
+
|
33
33
|
export type AsyncWaterfall<I> = {
|
34
|
-
run: (input: I, options?:
|
34
|
+
run: (input: I, options?: RunAsyncWaterfallOptions<I>) => MaybeAsync<I>;
|
35
35
|
use: (...I: AsyncBrookInputs<I>) => AsyncWaterfall<I>;
|
36
|
-
|
36
|
+
middlware: AsyncBrook<I>;
|
37
37
|
[ASYNC_WATERFALL_SYMBOL]: true;
|
38
38
|
};
|
39
39
|
|
@@ -69,51 +69,31 @@ export type AsyncWaterfalls2Runners<PS extends AsyncWaterfallRecord | void> = {
|
|
69
69
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
71
71
|
export const createAsyncWaterfall = <I = void>(): AsyncWaterfall<I> => {
|
72
|
-
const
|
73
|
-
|
74
|
-
const createCurrentRunner = (hooks: Hooks) =>
|
75
|
-
createAsyncCounter<I, I>(async (index, input, next) => {
|
76
|
-
if (index >= middlewares.length) {
|
77
|
-
return input;
|
78
|
-
}
|
79
|
-
|
80
|
-
return runHooks(
|
81
|
-
async () => next((await middlewares[index](input)) || input),
|
82
|
-
hooks,
|
83
|
-
);
|
84
|
-
});
|
85
|
-
|
86
|
-
const currentContainer = createContainer();
|
87
|
-
const currentHooks = fromContainer(currentContainer);
|
88
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
72
|
+
const pipeline = createAsyncPipeline<I, I>();
|
89
73
|
|
90
74
|
const use: AsyncWaterfall<I>['use'] = (...input) => {
|
91
|
-
|
75
|
+
pipeline.use(
|
76
|
+
...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware),
|
77
|
+
);
|
92
78
|
return waterfall;
|
93
79
|
};
|
94
80
|
|
95
|
-
const run: AsyncWaterfall<I>['run'] =
|
96
|
-
|
97
|
-
|
98
|
-
container === currentContainer ? currentHooks : fromContainer(container);
|
99
|
-
const runner =
|
100
|
-
container === currentContainer
|
101
|
-
? currentRunner
|
102
|
-
: createCurrentRunner(hooks);
|
103
|
-
|
104
|
-
return runner.start(input);
|
105
|
-
};
|
81
|
+
const run: AsyncWaterfall<I>['run'] = (input, options) =>
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
83
|
+
pipeline.run(input, { ...options, onLast: input => input });
|
106
84
|
|
107
|
-
const
|
85
|
+
const middlware: AsyncWaterfall<I>['middlware'] = input => {
|
108
86
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
109
87
|
const container = useContainer();
|
110
|
-
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
89
|
+
return pipeline.run(input, { container, onLast: input => input });
|
111
90
|
};
|
112
91
|
|
113
|
-
const waterfall = {
|
92
|
+
const waterfall: AsyncWaterfall<I> = {
|
93
|
+
...pipeline,
|
114
94
|
use,
|
115
95
|
run,
|
116
|
-
|
96
|
+
middlware,
|
117
97
|
[ASYNC_WATERFALL_SYMBOL]: true as const,
|
118
98
|
};
|
119
99
|
|
@@ -122,3 +102,8 @@ export const createAsyncWaterfall = <I = void>(): AsyncWaterfall<I> => {
|
|
122
102
|
|
123
103
|
export const isAsyncWaterfall = (input: any): input is AsyncWaterfall<any> =>
|
124
104
|
Boolean(input?.[ASYNC_WATERFALL_SYMBOL]);
|
105
|
+
|
106
|
+
const mapAsyncBrookToAsyncMiddleware =
|
107
|
+
<I>(brook: AsyncBrook<I>): Middleware<I, MaybeAsync<I>> =>
|
108
|
+
async (input, next) =>
|
109
|
+
next(await brook(input));
|