@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
@@ -1,3 +1,13 @@
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
|
+
|
3
|
+
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); } }
|
4
|
+
|
5
|
+
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); }); }; }
|
6
|
+
|
7
|
+
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; }
|
8
|
+
|
9
|
+
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; }
|
10
|
+
|
1
11
|
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
12
|
|
3
13
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
@@ -12,20 +22,13 @@ 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
|
-
|
17
|
-
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); } }
|
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, useContainer } from "../context";
|
25
|
+
import { createAsyncPipeline, useContainer } from 'farrow-pipeline';
|
23
26
|
var ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
|
24
27
|
export var getAsyncBrook = function getAsyncBrook(input) {
|
25
28
|
if (typeof input === 'function') {
|
26
29
|
return input;
|
27
|
-
} else if (input && typeof input.
|
28
|
-
return input.
|
30
|
+
} else if (input && typeof input.middlware === 'function') {
|
31
|
+
return input.middlware;
|
29
32
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
30
33
|
|
31
34
|
|
@@ -33,124 +36,76 @@ export var getAsyncBrook = function getAsyncBrook(input) {
|
|
33
36
|
};
|
34
37
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
35
38
|
export var createAsyncWaterfall = function createAsyncWaterfall() {
|
36
|
-
var
|
37
|
-
|
38
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
39
|
-
return createAsyncCounter( /*#__PURE__*/function () {
|
40
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(index, input, next) {
|
41
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
42
|
-
while (1) {
|
43
|
-
switch (_context2.prev = _context2.next) {
|
44
|
-
case 0:
|
45
|
-
if (!(index >= middlewares.length)) {
|
46
|
-
_context2.next = 2;
|
47
|
-
break;
|
48
|
-
}
|
49
|
-
|
50
|
-
return _context2.abrupt("return", input);
|
51
|
-
|
52
|
-
case 2:
|
53
|
-
return _context2.abrupt("return", runHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
54
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
55
|
-
while (1) {
|
56
|
-
switch (_context.prev = _context.next) {
|
57
|
-
case 0:
|
58
|
-
_context.t0 = next;
|
59
|
-
_context.next = 3;
|
60
|
-
return middlewares[index](input);
|
61
|
-
|
62
|
-
case 3:
|
63
|
-
_context.t1 = _context.sent;
|
64
|
-
|
65
|
-
if (_context.t1) {
|
66
|
-
_context.next = 6;
|
67
|
-
break;
|
68
|
-
}
|
69
|
-
|
70
|
-
_context.t1 = input;
|
71
|
-
|
72
|
-
case 6:
|
73
|
-
_context.t2 = _context.t1;
|
74
|
-
return _context.abrupt("return", (0, _context.t0)(_context.t2));
|
75
|
-
|
76
|
-
case 8:
|
77
|
-
case "end":
|
78
|
-
return _context.stop();
|
79
|
-
}
|
80
|
-
}
|
81
|
-
}, _callee);
|
82
|
-
})), hooks));
|
83
|
-
|
84
|
-
case 3:
|
85
|
-
case "end":
|
86
|
-
return _context2.stop();
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}, _callee2);
|
90
|
-
}));
|
91
|
-
|
92
|
-
return function (_x, _x2, _x3) {
|
93
|
-
return _ref.apply(this, arguments);
|
94
|
-
};
|
95
|
-
}());
|
96
|
-
};
|
97
|
-
|
98
|
-
var currentContainer = createContainer();
|
99
|
-
var currentHooks = fromContainer(currentContainer);
|
100
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
39
|
+
var pipeline = createAsyncPipeline();
|
101
40
|
|
102
41
|
var use = function use() {
|
103
42
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
104
43
|
input[_key] = arguments[_key];
|
105
44
|
}
|
106
45
|
|
107
|
-
|
46
|
+
pipeline.use.apply(pipeline, _toConsumableArray(input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware)));
|
108
47
|
return waterfall;
|
109
48
|
};
|
110
49
|
|
111
|
-
var run =
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
117
|
-
while (1) {
|
118
|
-
switch (_context3.prev = _context3.next) {
|
119
|
-
case 0:
|
120
|
-
container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
|
121
|
-
hooks = container === currentContainer ? currentHooks : fromContainer(container);
|
122
|
-
runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
123
|
-
return _context3.abrupt("return", runner.start(input));
|
124
|
-
|
125
|
-
case 4:
|
126
|
-
case "end":
|
127
|
-
return _context3.stop();
|
128
|
-
}
|
50
|
+
var run = function run(input, options) {
|
51
|
+
return (// eslint-disable-next-line @typescript-eslint/no-shadow
|
52
|
+
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
53
|
+
onLast: function onLast(input) {
|
54
|
+
return input;
|
129
55
|
}
|
130
|
-
}
|
131
|
-
|
132
|
-
|
133
|
-
return function run(_x4, _x5) {
|
134
|
-
return _ref3.apply(this, arguments);
|
135
|
-
};
|
136
|
-
}();
|
56
|
+
}))
|
57
|
+
);
|
58
|
+
};
|
137
59
|
|
138
|
-
var
|
60
|
+
var middlware = function middlware(input) {
|
139
61
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
140
|
-
var container = useContainer();
|
141
|
-
|
142
|
-
|
62
|
+
var container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
63
|
+
|
64
|
+
return pipeline.run(input, {
|
65
|
+
container: container,
|
66
|
+
onLast: function onLast(input) {
|
67
|
+
return input;
|
68
|
+
}
|
143
69
|
});
|
144
70
|
};
|
145
71
|
|
146
|
-
var waterfall = _defineProperty({
|
72
|
+
var waterfall = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
147
73
|
use: use,
|
148
74
|
run: run,
|
149
|
-
|
150
|
-
}, ASYNC_WATERFALL_SYMBOL, true);
|
75
|
+
middlware: middlware
|
76
|
+
}, ASYNC_WATERFALL_SYMBOL, true));
|
151
77
|
|
152
78
|
return waterfall;
|
153
79
|
};
|
154
80
|
export var isAsyncWaterfall = function isAsyncWaterfall(input) {
|
155
81
|
return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
82
|
+
};
|
83
|
+
|
84
|
+
var mapAsyncBrookToAsyncMiddleware = function mapAsyncBrookToAsyncMiddleware(brook) {
|
85
|
+
return /*#__PURE__*/function () {
|
86
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, next) {
|
87
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
88
|
+
while (1) {
|
89
|
+
switch (_context.prev = _context.next) {
|
90
|
+
case 0:
|
91
|
+
_context.t0 = next;
|
92
|
+
_context.next = 3;
|
93
|
+
return brook(input);
|
94
|
+
|
95
|
+
case 3:
|
96
|
+
_context.t1 = _context.sent;
|
97
|
+
return _context.abrupt("return", (0, _context.t0)(_context.t1));
|
98
|
+
|
99
|
+
case 5:
|
100
|
+
case "end":
|
101
|
+
return _context.stop();
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}, _callee);
|
105
|
+
}));
|
106
|
+
|
107
|
+
return function (_x, _x2) {
|
108
|
+
return _ref.apply(this, arguments);
|
109
|
+
};
|
110
|
+
}();
|
156
111
|
};
|
@@ -1,3 +1,7 @@
|
|
1
|
+
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; }
|
2
|
+
|
3
|
+
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; }
|
4
|
+
|
1
5
|
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
6
|
|
3
7
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
@@ -12,15 +16,13 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
12
16
|
|
13
17
|
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
18
|
|
15
|
-
import {
|
16
|
-
|
17
|
-
var WATERFALL_SYMBOL = Symbol('WATERFALL_SYMBOL'); // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
18
|
-
|
19
|
+
import { useContainer, createPipeline } from 'farrow-pipeline';
|
20
|
+
var WATERFALL_SYMBOL = Symbol('WATERFALL_SYMBOL');
|
19
21
|
export var getBrook = function getBrook(input) {
|
20
22
|
if (typeof input === 'function') {
|
21
23
|
return input;
|
22
|
-
} else if (input && typeof input.
|
23
|
-
return input.
|
24
|
+
} else if (input && typeof input.middleware === 'function') {
|
25
|
+
return input.middleware;
|
24
26
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
25
27
|
|
26
28
|
|
@@ -28,58 +30,53 @@ export var getBrook = function getBrook(input) {
|
|
28
30
|
};
|
29
31
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
30
32
|
export var createWaterfall = function createWaterfall() {
|
31
|
-
var
|
32
|
-
|
33
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
34
|
-
return createCounter(function (index, input, next) {
|
35
|
-
if (index >= middlewares.length) {
|
36
|
-
return input;
|
37
|
-
}
|
38
|
-
|
39
|
-
return runHooks(function () {
|
40
|
-
return next(middlewares[index](input) || input);
|
41
|
-
}, hooks);
|
42
|
-
});
|
43
|
-
};
|
44
|
-
|
45
|
-
var currentContainer = createContainer();
|
46
|
-
var currentHooks = fromContainer(currentContainer);
|
47
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
33
|
+
var pipeline = createPipeline();
|
48
34
|
|
49
35
|
var use = function use() {
|
50
|
-
for (var _len = arguments.length,
|
51
|
-
|
36
|
+
for (var _len = arguments.length, brooks = new Array(_len), _key = 0; _key < _len; _key++) {
|
37
|
+
brooks[_key] = arguments[_key];
|
52
38
|
}
|
53
39
|
|
54
|
-
|
40
|
+
pipeline.use.apply(pipeline, _toConsumableArray(brooks.map(getBrook).map(mapBrookToMiddleware)));
|
55
41
|
return waterfall;
|
56
42
|
};
|
57
43
|
|
58
44
|
var run = function run(input, options) {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
45
|
+
return (// eslint-disable-next-line @typescript-eslint/no-shadow
|
46
|
+
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
47
|
+
onLast: function onLast(input) {
|
48
|
+
return input;
|
49
|
+
}
|
50
|
+
}))
|
51
|
+
);
|
65
52
|
};
|
66
53
|
|
67
|
-
var
|
54
|
+
var middleware = function middleware(input) {
|
68
55
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
69
|
-
var container = useContainer();
|
70
|
-
|
71
|
-
|
56
|
+
var container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
57
|
+
|
58
|
+
return pipeline.run(input, {
|
59
|
+
container: container,
|
60
|
+
onLast: function onLast(input) {
|
61
|
+
return input;
|
62
|
+
}
|
72
63
|
});
|
73
64
|
};
|
74
65
|
|
75
|
-
var waterfall = _defineProperty({
|
66
|
+
var waterfall = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
76
67
|
use: use,
|
77
68
|
run: run,
|
78
|
-
|
79
|
-
}, WATERFALL_SYMBOL, true);
|
69
|
+
middleware: middleware
|
70
|
+
}, WATERFALL_SYMBOL, true));
|
80
71
|
|
81
72
|
return waterfall;
|
82
73
|
};
|
83
74
|
export var isWaterfall = function isWaterfall(input) {
|
84
75
|
return Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
76
|
+
};
|
77
|
+
|
78
|
+
var mapBrookToMiddleware = function mapBrookToMiddleware(brook) {
|
79
|
+
return function (input, next) {
|
80
|
+
return next(brook(input));
|
81
|
+
};
|
85
82
|
};
|
@@ -1,7 +1,17 @@
|
|
1
|
-
function
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
2
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
4
4
|
|
5
|
+
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; }
|
6
|
+
|
7
|
+
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; }
|
8
|
+
|
9
|
+
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; }
|
10
|
+
|
11
|
+
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); } }
|
12
|
+
|
13
|
+
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); }); }; }
|
14
|
+
|
5
15
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
6
16
|
|
7
17
|
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."); }
|
@@ -14,117 +24,108 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
14
24
|
|
15
25
|
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
26
|
|
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";
|
27
|
+
import { createAsyncPipeline } from 'farrow-pipeline';
|
23
28
|
var ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
|
24
29
|
export var isAsyncWorkflow = function isAsyncWorkflow(input) {
|
25
30
|
return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
26
31
|
}; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
27
32
|
|
28
33
|
export var createAsyncWorkflow = function createAsyncWorkflow() {
|
29
|
-
var
|
30
|
-
|
31
|
-
var createCurrentRunner = function createCurrentRunner(hooks) {
|
32
|
-
return createAsyncCounter( /*#__PURE__*/function () {
|
33
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(index, input, next) {
|
34
|
-
var middleware;
|
35
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
36
|
-
while (1) {
|
37
|
-
switch (_context2.prev = _context2.next) {
|
38
|
-
case 0:
|
39
|
-
if (!(index >= middlewares.length)) {
|
40
|
-
_context2.next = 2;
|
41
|
-
break;
|
42
|
-
}
|
43
|
-
|
44
|
-
return _context2.abrupt("return", []);
|
45
|
-
|
46
|
-
case 2:
|
47
|
-
middleware = middlewares[index];
|
48
|
-
return _context2.abrupt("return", runHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
49
|
-
var result, rest;
|
50
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
51
|
-
while (1) {
|
52
|
-
switch (_context.prev = _context.next) {
|
53
|
-
case 0:
|
54
|
-
_context.next = 2;
|
55
|
-
return middleware(input);
|
56
|
-
|
57
|
-
case 2:
|
58
|
-
result = _context.sent;
|
59
|
-
_context.next = 5;
|
60
|
-
return next(input);
|
61
|
-
|
62
|
-
case 5:
|
63
|
-
rest = _context.sent;
|
64
|
-
return _context.abrupt("return", [result].concat(_toConsumableArray(rest)));
|
65
|
-
|
66
|
-
case 7:
|
67
|
-
case "end":
|
68
|
-
return _context.stop();
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}, _callee);
|
72
|
-
})), hooks));
|
73
|
-
|
74
|
-
case 4:
|
75
|
-
case "end":
|
76
|
-
return _context2.stop();
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}, _callee2);
|
80
|
-
}));
|
81
|
-
|
82
|
-
return function (_x, _x2, _x3) {
|
83
|
-
return _ref.apply(this, arguments);
|
84
|
-
};
|
85
|
-
}());
|
86
|
-
};
|
87
|
-
|
88
|
-
var currentContainer = createContainer();
|
89
|
-
var currentHooks = fromContainer(currentContainer);
|
90
|
-
var currentRunner = createCurrentRunner(currentHooks);
|
34
|
+
var pipeline = createAsyncPipeline();
|
91
35
|
|
92
36
|
var use = function use() {
|
93
|
-
|
37
|
+
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
38
|
+
input[_key] = arguments[_key];
|
39
|
+
}
|
40
|
+
|
41
|
+
pipeline.use.apply(pipeline, _toConsumableArray(input.map(mapAsyncWorkerToAsyncMiddleware)));
|
94
42
|
return workflow;
|
95
43
|
};
|
96
44
|
|
97
45
|
var run = /*#__PURE__*/function () {
|
98
|
-
var
|
99
|
-
var
|
100
|
-
|
101
|
-
var container, hooks, runner;
|
102
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
46
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input, options) {
|
47
|
+
var result;
|
48
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
103
49
|
while (1) {
|
104
|
-
switch (
|
50
|
+
switch (_context.prev = _context.next) {
|
105
51
|
case 0:
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
52
|
+
result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
53
|
+
onLast: function onLast() {
|
54
|
+
return [];
|
55
|
+
}
|
56
|
+
}));
|
57
|
+
|
58
|
+
if (!isPromise(result)) {
|
59
|
+
_context.next = 5;
|
60
|
+
break;
|
61
|
+
}
|
110
62
|
|
111
|
-
|
63
|
+
return _context.abrupt("return", result.then(function (result) {
|
64
|
+
return result.filter(Boolean);
|
65
|
+
}));
|
66
|
+
|
67
|
+
case 5:
|
68
|
+
return _context.abrupt("return", result.filter(Boolean));
|
69
|
+
|
70
|
+
case 6:
|
112
71
|
case "end":
|
113
|
-
return
|
72
|
+
return _context.stop();
|
114
73
|
}
|
115
74
|
}
|
116
|
-
},
|
75
|
+
}, _callee);
|
117
76
|
}));
|
118
77
|
|
119
|
-
return function run(
|
120
|
-
return
|
78
|
+
return function run(_x, _x2) {
|
79
|
+
return _ref.apply(this, arguments);
|
121
80
|
};
|
122
81
|
}();
|
123
82
|
|
124
|
-
var workflow = _defineProperty({
|
83
|
+
var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
125
84
|
use: use,
|
126
85
|
run: run
|
127
|
-
}, ASYNC_WORKFLOW_SYMBOL, true);
|
86
|
+
}, ASYNC_WORKFLOW_SYMBOL, true));
|
128
87
|
|
129
88
|
return workflow;
|
130
|
-
};
|
89
|
+
};
|
90
|
+
|
91
|
+
var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(worker) {
|
92
|
+
return /*#__PURE__*/function () {
|
93
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(input, next) {
|
94
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
95
|
+
while (1) {
|
96
|
+
switch (_context2.prev = _context2.next) {
|
97
|
+
case 0:
|
98
|
+
_context2.next = 2;
|
99
|
+
return worker(input);
|
100
|
+
|
101
|
+
case 2:
|
102
|
+
_context2.t1 = _context2.sent;
|
103
|
+
_context2.t0 = [_context2.t1];
|
104
|
+
_context2.t2 = _toConsumableArray;
|
105
|
+
_context2.next = 7;
|
106
|
+
return next(input);
|
107
|
+
|
108
|
+
case 7:
|
109
|
+
_context2.t3 = _context2.sent;
|
110
|
+
_context2.t4 = (0, _context2.t2)(_context2.t3);
|
111
|
+
return _context2.abrupt("return", _context2.t0.concat.call(_context2.t0, _context2.t4));
|
112
|
+
|
113
|
+
case 10:
|
114
|
+
case "end":
|
115
|
+
return _context2.stop();
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}, _callee2);
|
119
|
+
}));
|
120
|
+
|
121
|
+
return function (_x3, _x4) {
|
122
|
+
return _ref2.apply(this, arguments);
|
123
|
+
};
|
124
|
+
}();
|
125
|
+
};
|
126
|
+
|
127
|
+
function isPromise(obj) {
|
128
|
+
/* eslint-disable promise/prefer-await-to-then */
|
129
|
+
return Boolean(obj) && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
130
|
+
/* eslint-enable promise/prefer-await-to-then */
|
131
|
+
}
|