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