@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.
Files changed (107) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -4
  3. package/dist/js/modern/index.js +2 -3
  4. package/dist/js/modern/manager/async.js +1 -1
  5. package/dist/js/modern/manager/runner.js +1 -1
  6. package/dist/js/modern/manager/sync.js +1 -6
  7. package/dist/js/modern/waterfall/async.js +28 -34
  8. package/dist/js/modern/waterfall/sync.js +29 -36
  9. package/dist/js/modern/workflow/async.js +31 -30
  10. package/dist/js/modern/workflow/parallel.js +20 -29
  11. package/dist/js/modern/workflow/sync.js +20 -27
  12. package/dist/js/node/index.js +12 -25
  13. package/dist/js/node/manager/async.js +4 -4
  14. package/dist/js/node/manager/runner.js +2 -2
  15. package/dist/js/node/manager/sync.js +6 -12
  16. package/dist/js/node/waterfall/async.js +27 -34
  17. package/dist/js/node/waterfall/sync.js +29 -36
  18. package/dist/js/node/workflow/async.js +30 -30
  19. package/dist/js/node/workflow/parallel.js +19 -29
  20. package/dist/js/node/workflow/sync.js +19 -27
  21. package/dist/js/treeshaking/index.js +2 -3
  22. package/dist/js/treeshaking/manager/async.js +1 -1
  23. package/dist/js/treeshaking/manager/runner.js +1 -1
  24. package/dist/js/treeshaking/manager/sync.js +1 -6
  25. package/dist/js/treeshaking/waterfall/async.js +63 -108
  26. package/dist/js/treeshaking/waterfall/sync.js +36 -39
  27. package/dist/js/treeshaking/workflow/async.js +89 -88
  28. package/dist/js/treeshaking/workflow/parallel.js +42 -66
  29. package/dist/js/treeshaking/workflow/sync.js +50 -30
  30. package/dist/types/index.d.ts +2 -3
  31. package/dist/types/manager/runner.d.ts +1 -1
  32. package/dist/types/manager/sync.d.ts +2 -3
  33. package/dist/types/waterfall/async.d.ts +9 -5
  34. package/dist/types/waterfall/sync.d.ts +4 -4
  35. package/dist/types/workflow/async.d.ts +3 -2
  36. package/dist/types/workflow/parallel.d.ts +1 -1
  37. package/dist/types/workflow/sync.d.ts +1 -1
  38. package/node.d.ts +1 -1
  39. package/node.js +1 -1
  40. package/package.json +5 -4
  41. package/src/index.ts +2 -2
  42. package/src/manager/async.ts +1 -1
  43. package/src/manager/runner.ts +1 -1
  44. package/src/manager/sync.ts +12 -16
  45. package/src/waterfall/async.ts +34 -49
  46. package/src/waterfall/sync.ts +26 -45
  47. package/src/workflow/async.ts +29 -33
  48. package/src/workflow/parallel.ts +17 -35
  49. package/src/workflow/sync.ts +13 -35
  50. package/tests/.eslintrc.js +6 -0
  51. package/tests/async.test.ts +7 -3
  52. package/tests/fixtures/async/base/foo.ts +0 -1
  53. package/tests/fixtures/async/base/fooManager.ts +1 -1
  54. package/tests/fixtures/async/core/index.ts +1 -1
  55. package/tests/fixtures/async/dynamic/bar.ts +0 -1
  56. package/tests/fixtures/async/dynamic/foo.ts +1 -1
  57. package/tests/fixtures/sync/base/foo.ts +0 -2
  58. package/tests/fixtures/sync/base/fooManager.ts +1 -1
  59. package/tests/fixtures/sync/core/index.ts +1 -1
  60. package/tests/fixtures/sync/dynamic/bar.ts +0 -1
  61. package/tests/fixtures/sync/dynamic/foo.ts +1 -1
  62. package/tests/pipeline.test.ts +4 -15
  63. package/tests/sync.test.ts +6 -2
  64. package/tests/waterfall.test.ts +1 -2
  65. package/dist/js/modern/asyncHooksImpl.js +0 -63
  66. package/dist/js/modern/asyncHooksInterface.js +0 -16
  67. package/dist/js/modern/context.js +0 -130
  68. package/dist/js/modern/counter.js +0 -40
  69. package/dist/js/modern/hook.js +0 -47
  70. package/dist/js/modern/pipeline/async.js +0 -97
  71. package/dist/js/modern/pipeline/index.js +0 -2
  72. package/dist/js/modern/pipeline/sync.js +0 -97
  73. package/dist/js/node/asyncHooksImpl.js +0 -82
  74. package/dist/js/node/asyncHooksInterface.js +0 -30
  75. package/dist/js/node/context.js +0 -164
  76. package/dist/js/node/counter.js +0 -52
  77. package/dist/js/node/hook.js +0 -57
  78. package/dist/js/node/pipeline/async.js +0 -110
  79. package/dist/js/node/pipeline/index.js +0 -31
  80. package/dist/js/node/pipeline/sync.js +0 -110
  81. package/dist/js/treeshaking/asyncHooksImpl.js +0 -65
  82. package/dist/js/treeshaking/asyncHooksInterface.js +0 -16
  83. package/dist/js/treeshaking/context.js +0 -137
  84. package/dist/js/treeshaking/counter.js +0 -74
  85. package/dist/js/treeshaking/hook.js +0 -51
  86. package/dist/js/treeshaking/pipeline/async.js +0 -165
  87. package/dist/js/treeshaking/pipeline/index.js +0 -2
  88. package/dist/js/treeshaking/pipeline/sync.js +0 -118
  89. package/dist/types/asyncHooksImpl.d.ts +0 -10
  90. package/dist/types/asyncHooksInterface.d.ts +0 -21
  91. package/dist/types/context.d.ts +0 -47
  92. package/dist/types/counter.d.ts +0 -22
  93. package/dist/types/hook.d.ts +0 -13
  94. package/dist/types/pipeline/async.d.ts +0 -35
  95. package/dist/types/pipeline/index.d.ts +0 -2
  96. package/dist/types/pipeline/sync.d.ts +0 -37
  97. package/src/asyncHooksImpl.ts +0 -64
  98. package/src/asyncHooksInterface.ts +0 -34
  99. package/src/context.ts +0 -184
  100. package/src/counter.ts +0 -78
  101. package/src/hook.ts +0 -46
  102. package/src/pipeline/async.ts +0 -155
  103. package/src/pipeline/index.ts +0 -2
  104. package/src/pipeline/sync.ts +0 -152
  105. package/tests/context.test.ts +0 -114
  106. package/tests/counter.test.ts +0 -32
  107. 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); if (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 = 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; }
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 _regeneratorRuntime from "@babel/runtime/regenerator";
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.brook === 'function') {
28
- return input.brook;
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 middlewares = [];
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
- middlewares.push.apply(middlewares, _toConsumableArray(input.map(getAsyncBrook)));
46
+ pipeline.use.apply(pipeline, _toConsumableArray(input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware)));
108
47
  return waterfall;
109
48
  };
110
49
 
111
- var run = /*#__PURE__*/function () {
112
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(input, options) {
113
- var _options$container;
114
-
115
- var container, hooks, runner;
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
- }, _callee3);
131
- }));
132
-
133
- return function run(_x4, _x5) {
134
- return _ref3.apply(this, arguments);
135
- };
136
- }();
56
+ }))
57
+ );
58
+ };
137
59
 
138
- var brook = function brook(input) {
60
+ var middlware = function middlware(input) {
139
61
  // eslint-disable-next-line react-hooks/rules-of-hooks
140
- var container = useContainer();
141
- return run(input, {
142
- container: container
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
- brook: brook
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); if (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 = 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; }
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 { createCounter } from "../counter";
16
- import { runHooks, fromContainer, createContainer, useContainer } from "../context";
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.brook === 'function') {
23
- return input.brook;
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 middlewares = [];
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, input = new Array(_len), _key = 0; _key < _len; _key++) {
51
- input[_key] = arguments[_key];
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
- middlewares.push.apply(middlewares, _toConsumableArray(input.map(getBrook)));
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
- var _options$container;
60
-
61
- var container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
62
- var hooks = container === currentContainer ? currentHooks : fromContainer(container);
63
- var runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
64
- return runner.start(input);
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 brook = function brook(input) {
54
+ var middleware = function middleware(input) {
68
55
  // eslint-disable-next-line react-hooks/rules-of-hooks
69
- var container = useContainer();
70
- return run(input, {
71
- container: container
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
- brook: brook
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 _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; }
1
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _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); if (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 = 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; }
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
- 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 } 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 middlewares = [];
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
- middlewares.push.apply(middlewares, arguments);
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 _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(input, options) {
99
- var _options$container;
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 (_context3.prev = _context3.next) {
50
+ switch (_context.prev = _context.next) {
105
51
  case 0:
106
- container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
107
- hooks = container === currentContainer ? currentHooks : fromContainer(container);
108
- runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
109
- return _context3.abrupt("return", runner.start(input));
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
- case 4:
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 _context3.stop();
72
+ return _context.stop();
114
73
  }
115
74
  }
116
- }, _callee3);
75
+ }, _callee);
117
76
  }));
118
77
 
119
- return function run(_x4, _x5) {
120
- return _ref3.apply(this, arguments);
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
+ }