@modern-js/plugin 1.3.6 → 1.4.0-alpha.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 (61) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/js/modern/farrow-pipeline/context.js +14 -75
  3. package/dist/js/modern/farrow-pipeline/index.js +0 -14
  4. package/dist/js/modern/farrow-pipeline/pipeline.js +12 -29
  5. package/dist/js/modern/manager/async.js +9 -69
  6. package/dist/js/modern/manager/runner.js +1 -9
  7. package/dist/js/modern/manager/shared.js +44 -0
  8. package/dist/js/modern/manager/sync.js +12 -77
  9. package/dist/js/modern/waterfall/async.js +1 -3
  10. package/dist/js/modern/waterfall/sync.js +1 -3
  11. package/dist/js/modern/workflow/async.js +3 -3
  12. package/dist/js/modern/workflow/parallel.js +2 -2
  13. package/dist/js/modern/workflow/sync.js +3 -3
  14. package/dist/js/node/farrow-pipeline/context.js +15 -88
  15. package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
  16. package/dist/js/node/manager/async.js +12 -72
  17. package/dist/js/node/manager/runner.js +1 -9
  18. package/dist/js/node/manager/shared.js +64 -0
  19. package/dist/js/node/manager/sync.js +19 -87
  20. package/dist/js/node/waterfall/async.js +0 -2
  21. package/dist/js/node/waterfall/sync.js +0 -2
  22. package/dist/js/node/workflow/async.js +3 -3
  23. package/dist/js/node/workflow/parallel.js +2 -2
  24. package/dist/js/node/workflow/sync.js +3 -3
  25. package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
  26. package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
  27. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
  28. package/dist/js/treeshaking/manager/async.js +15 -160
  29. package/dist/js/treeshaking/manager/runner.js +1 -7
  30. package/dist/js/treeshaking/manager/shared.js +79 -0
  31. package/dist/js/treeshaking/manager/sync.js +12 -168
  32. package/dist/js/treeshaking/waterfall/async.js +1 -3
  33. package/dist/js/treeshaking/waterfall/sync.js +1 -3
  34. package/dist/js/treeshaking/workflow/async.js +6 -6
  35. package/dist/js/treeshaking/workflow/parallel.js +5 -5
  36. package/dist/js/treeshaking/workflow/sync.js +8 -28
  37. package/dist/types/farrow-pipeline/context.d.ts +5 -20
  38. package/dist/types/farrow-pipeline/index.d.ts +0 -14
  39. package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
  40. package/dist/types/manager/async.d.ts +4 -7
  41. package/dist/types/manager/shared.d.ts +12 -0
  42. package/dist/types/manager/sync.d.ts +5 -11
  43. package/dist/types/manager/types.d.ts +1 -6
  44. package/dist/types/waterfall/async.d.ts +1 -7
  45. package/dist/types/waterfall/sync.d.ts +0 -7
  46. package/dist/types/workflow/async.d.ts +1 -7
  47. package/dist/types/workflow/parallel.d.ts +2 -9
  48. package/dist/types/workflow/sync.d.ts +1 -10
  49. package/package.json +1 -12
  50. package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -74
  51. package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
  52. package/dist/js/modern/farrow-pipeline/hook.js +0 -42
  53. package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -93
  54. package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
  55. package/dist/js/node/farrow-pipeline/hook.js +0 -52
  56. package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -74
  57. package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
  58. package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
  59. package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
  60. package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
  61. package/dist/types/farrow-pipeline/hook.d.ts +0 -9
@@ -1,11 +1,10 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
- import { isPipeline, createPipeline, runWithContainer, createContainer } from "../farrow-pipeline";
3
+ import { isPipeline, createPipeline } from "../farrow-pipeline";
6
4
  import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
7
5
  import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
8
6
  import { RunnerContext, useRunner } from "./runner";
7
+ import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
9
8
  var SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
10
9
  export var DEFAULT_OPTIONS = {
11
10
  name: 'untitled',
@@ -47,9 +46,7 @@ export var createManager = function createManager(hooks, api) {
47
46
  input[_key] = arguments[_key];
48
47
  }
49
48
 
50
- for (var _i = 0, _input = input; _i < _input.length; _i++) {
51
- var plugin = _input[_i];
52
-
49
+ input.forEach(function (plugin) {
53
50
  // already created by createPlugin
54
51
  if (isPlugin(plugin)) {
55
52
  addPlugin(plugin);
@@ -65,8 +62,7 @@ export var createManager = function createManager(hooks, api) {
65
62
  else {
66
63
  console.warn("Unknown plugin: ".concat(JSON.stringify(plugin)));
67
64
  }
68
- }
69
-
65
+ });
70
66
  return manager;
71
67
  };
72
68
 
@@ -98,26 +94,20 @@ export var createManager = function createManager(hooks, api) {
98
94
  plugins = [];
99
95
  };
100
96
 
101
- var currentContainer = createContainer();
102
-
103
- var init = function init(options) {
104
- var container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
97
+ var init = function init() {
105
98
  var sortedPlugins = sortPlugins(plugins);
106
99
 
107
100
  var mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
108
101
 
109
102
  checkPlugins(sortedPlugins);
110
103
  var hooksList = sortedPlugins.map(function (plugin) {
111
- return runWithContainer(function () {
112
- return plugin.setup(mergedPluginAPI);
113
- }, container);
104
+ return plugin.setup(mergedPluginAPI);
114
105
  });
115
- return generateRunner(hooksList, container, currentHooks);
106
+ return generateRunner(hooksList, currentHooks);
116
107
  };
117
108
 
118
- var run = function run(cb, options) {
119
- var container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
120
- return runWithContainer(cb, container);
109
+ var run = function run(cb) {
110
+ return cb();
121
111
  };
122
112
 
123
113
  var manager = {
@@ -136,7 +126,7 @@ export var createManager = function createManager(hooks, api) {
136
126
 
137
127
  return clone();
138
128
  };
139
- export var generateRunner = function generateRunner(hooksList, container, hooksMap) {
129
+ export var generateRunner = function generateRunner(hooksList, hooksMap) {
140
130
  var runner = {};
141
131
  var cloneShape = closeHooksMap(hooksMap);
142
132
 
@@ -166,9 +156,7 @@ export var generateRunner = function generateRunner(hooksList, container, hooksM
166
156
  }
167
157
 
168
158
  runner[key] = function (input, options) {
169
- return cloneShape[key].run(input, _objectSpread({
170
- container: container
171
- }, options));
159
+ return cloneShape[key].run(input, _objectSpread({}, options));
172
160
  };
173
161
  };
174
162
 
@@ -177,7 +165,7 @@ export var generateRunner = function generateRunner(hooksList, container, hooksM
177
165
  }
178
166
  }
179
167
 
180
- container.write(RunnerContext, runner);
168
+ RunnerContext.set(runner);
181
169
  return runner;
182
170
  };
183
171
  export var cloneHook = function cloneHook(hook) {
@@ -221,148 +209,4 @@ export var closeHooksMap = function closeHooksMap(record) {
221
209
  }
222
210
 
223
211
  return result;
224
- };
225
-
226
- var includePlugin = function includePlugin(plugins, input) {
227
- var _iterator2 = _createForOfIteratorHelper(plugins),
228
- _step2;
229
-
230
- try {
231
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
232
- var plugin = _step2.value;
233
-
234
- if (plugin.name === input.name) {
235
- return true;
236
- }
237
- }
238
- } catch (err) {
239
- _iterator2.e(err);
240
- } finally {
241
- _iterator2.f();
242
- }
243
-
244
- return false;
245
- };
246
-
247
- var sortPlugins = function sortPlugins(input) {
248
- var plugins = input.slice();
249
-
250
- for (var i = 0; i < plugins.length; i++) {
251
- var plugin = plugins[i];
252
-
253
- var _iterator3 = _createForOfIteratorHelper(plugin.pre),
254
- _step3;
255
-
256
- try {
257
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
258
- var pre = _step3.value;
259
-
260
- for (var j = i + 1; j < plugins.length; j++) {
261
- if (plugins[j].name === pre) {
262
- plugins = [].concat(_toConsumableArray(plugins.slice(0, i)), [plugins[j]], _toConsumableArray(plugins.slice(i, j)), _toConsumableArray(plugins.slice(j + 1, plugins.length)));
263
- }
264
- }
265
- }
266
- } catch (err) {
267
- _iterator3.e(err);
268
- } finally {
269
- _iterator3.f();
270
- }
271
-
272
- var _iterator4 = _createForOfIteratorHelper(plugin.post),
273
- _step4;
274
-
275
- try {
276
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
277
- var post = _step4.value;
278
-
279
- for (var _j = 0; _j < i; _j++) {
280
- if (plugins[_j].name === post) {
281
- plugins = [].concat(_toConsumableArray(plugins.slice(0, _j)), _toConsumableArray(plugins.slice(_j + 1, i + 1)), [plugins[_j]], _toConsumableArray(plugins.slice(i + 1, plugins.length)));
282
- }
283
- }
284
- }
285
- } catch (err) {
286
- _iterator4.e(err);
287
- } finally {
288
- _iterator4.f();
289
- }
290
- }
291
-
292
- return plugins;
293
- };
294
-
295
- var checkPlugins = function checkPlugins(plugins) {
296
- var _iterator5 = _createForOfIteratorHelper(plugins),
297
- _step5;
298
-
299
- try {
300
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
301
- var origin = _step5.value;
302
-
303
- var _iterator6 = _createForOfIteratorHelper(origin.rivals),
304
- _step6;
305
-
306
- try {
307
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
308
- var rival = _step6.value;
309
-
310
- var _iterator8 = _createForOfIteratorHelper(plugins),
311
- _step8;
312
-
313
- try {
314
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
315
- var plugin = _step8.value;
316
-
317
- if (rival === plugin.name) {
318
- throw new Error("".concat(origin.name, " has rival ").concat(plugin.name));
319
- }
320
- }
321
- } catch (err) {
322
- _iterator8.e(err);
323
- } finally {
324
- _iterator8.f();
325
- }
326
- }
327
- } catch (err) {
328
- _iterator6.e(err);
329
- } finally {
330
- _iterator6.f();
331
- }
332
-
333
- var _iterator7 = _createForOfIteratorHelper(origin.required),
334
- _step7;
335
-
336
- try {
337
- var _loop2 = function _loop2() {
338
- var required = _step7.value;
339
-
340
- if (!plugins.some(function (plugin) {
341
- return plugin.name === required;
342
- })) {
343
- throw new Error("The plugin: ".concat(required, " is required when plugin: ").concat(origin.name, " is exist."));
344
- }
345
- };
346
-
347
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
348
- _loop2();
349
- }
350
- } catch (err) {
351
- _iterator7.e(err);
352
- } finally {
353
- _iterator7.f();
354
- }
355
- }
356
- } catch (err) {
357
- _iterator5.e(err);
358
- } finally {
359
- _iterator5.f();
360
- }
361
- };
362
-
363
- export var isObject = function isObject(obj) {
364
- return obj !== null && _typeof(obj) === 'object';
365
- };
366
- export var hasOwnProperty = function hasOwnProperty(obj, prop) {
367
- return obj.hasOwnProperty(prop);
368
212
  };
@@ -3,7 +3,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
5
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
6
- import { createAsyncPipeline, useContainer } from "../farrow-pipeline";
6
+ import { createAsyncPipeline } from "../farrow-pipeline";
7
7
  var ASYNC_WATERFALL_SYMBOL = Symbol["for"]('MODERN_ASYNC_WATERFALL');
8
8
  export var getAsyncBrook = function getAsyncBrook(input) {
9
9
  if (typeof input === 'function') {
@@ -35,9 +35,7 @@ export var createAsyncWaterfall = function createAsyncWaterfall() {
35
35
  };
36
36
 
37
37
  var middleware = function middleware(input) {
38
- var container = useContainer();
39
38
  return pipeline.run(input, {
40
- container: container,
41
39
  onLast: function onLast(input) {
42
40
  return input;
43
41
  }
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
- import { useContainer, createPipeline } from "../farrow-pipeline";
4
+ import { createPipeline } from "../farrow-pipeline";
5
5
  var WATERFALL_SYMBOL = Symbol["for"]('MODERN_WATERFALL');
6
6
  export var getBrook = function getBrook(input) {
7
7
  if (typeof input === 'function') {
@@ -33,9 +33,7 @@ export var createWaterfall = function createWaterfall() {
33
33
  };
34
34
 
35
35
  var middleware = function middleware(input) {
36
- var container = useContainer();
37
36
  return pipeline.run(input, {
38
- container: container,
39
37
  onLast: function onLast(input) {
40
38
  return input;
41
39
  }
@@ -1,7 +1,7 @@
1
1
  import _typeof from "@babel/runtime/helpers/esm/typeof";
2
2
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
5
5
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
6
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
7
  import { createAsyncPipeline } from "../farrow-pipeline";
@@ -22,17 +22,17 @@ export var createAsyncWorkflow = function createAsyncWorkflow() {
22
22
  };
23
23
 
24
24
  var run = /*#__PURE__*/function () {
25
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, options) {
25
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
26
26
  var result;
27
27
  return _regeneratorRuntime().wrap(function _callee$(_context) {
28
28
  while (1) {
29
29
  switch (_context.prev = _context.next) {
30
30
  case 0:
31
- result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
31
+ result = pipeline.run(input, {
32
32
  onLast: function onLast() {
33
33
  return [];
34
34
  }
35
- }));
35
+ });
36
36
 
37
37
  if (!isPromise(result)) {
38
38
  _context.next = 5;
@@ -54,7 +54,7 @@ export var createAsyncWorkflow = function createAsyncWorkflow() {
54
54
  }, _callee);
55
55
  }));
56
56
 
57
- return function run(_x, _x2) {
57
+ return function run(_x) {
58
58
  return _ref.apply(this, arguments);
59
59
  };
60
60
  }();
@@ -97,7 +97,7 @@ var mapAsyncWorkerToAsyncMiddleware = function mapAsyncWorkerToAsyncMiddleware(w
97
97
  }, _callee2);
98
98
  }));
99
99
 
100
- return function (_x3, _x4) {
100
+ return function (_x2, _x3) {
101
101
  return _ref2.apply(this, arguments);
102
102
  };
103
103
  }();
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
4
4
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
5
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
6
6
  import { createPipeline } from "../farrow-pipeline";
@@ -21,16 +21,16 @@ export var createParallelWorkflow = function createParallelWorkflow() {
21
21
  };
22
22
 
23
23
  var run = /*#__PURE__*/function () {
24
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, options) {
24
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
25
25
  return _regeneratorRuntime().wrap(function _callee$(_context) {
26
26
  while (1) {
27
27
  switch (_context.prev = _context.next) {
28
28
  case 0:
29
- return _context.abrupt("return", Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
29
+ return _context.abrupt("return", Promise.all(pipeline.run(input, {
30
30
  onLast: function onLast() {
31
31
  return [];
32
32
  }
33
- }))).then(function (result) {
33
+ })).then(function (result) {
34
34
  return result.filter(Boolean);
35
35
  }));
36
36
 
@@ -42,7 +42,7 @@ export var createParallelWorkflow = function createParallelWorkflow() {
42
42
  }, _callee);
43
43
  }));
44
44
 
45
- return function run(_x, _x2) {
45
+ return function run(_x) {
46
46
  return _ref.apply(this, arguments);
47
47
  };
48
48
  }();
@@ -1,7 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
3
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
6
4
  import { createPipeline } from "../farrow-pipeline";
7
5
  var WORKFLOW_SYMBOL = Symbol["for"]('MODERN_WORKFLOW');
@@ -17,32 +15,14 @@ export var createWorkflow = function createWorkflow() {
17
15
  return workflow;
18
16
  };
19
17
 
20
- var run = /*#__PURE__*/function () {
21
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, options) {
22
- var result;
23
- return _regeneratorRuntime().wrap(function _callee$(_context) {
24
- while (1) {
25
- switch (_context.prev = _context.next) {
26
- case 0:
27
- result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
28
- onLast: function onLast() {
29
- return [];
30
- }
31
- }));
32
- return _context.abrupt("return", result.filter(Boolean));
33
-
34
- case 2:
35
- case "end":
36
- return _context.stop();
37
- }
38
- }
39
- }, _callee);
40
- }));
41
-
42
- return function run(_x, _x2) {
43
- return _ref.apply(this, arguments);
44
- };
45
- }();
18
+ var run = function run(input) {
19
+ var result = pipeline.run(input, {
20
+ onLast: function onLast() {
21
+ return [];
22
+ }
23
+ });
24
+ return result.filter(Boolean);
25
+ };
46
26
 
47
27
  var workflow = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
48
28
  use: use,
@@ -1,7 +1,8 @@
1
- declare const ContextSymbol: unique symbol;
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
2
5
  export declare type Context<T = any> = {
3
- id: symbol;
4
- [ContextSymbol]: T;
5
6
  create: (value: T) => Context<T>;
6
7
  use: () => {
7
8
  value: T;
@@ -9,20 +10,4 @@ export declare type Context<T = any> = {
9
10
  get: () => T;
10
11
  set: (value: T) => void;
11
12
  };
12
- export declare const createContext: <T>(value: T) => Context<T>;
13
- export declare type ContextStorage = {
14
- [key: string]: Context;
15
- };
16
- export declare type Container = {
17
- read: <V>(Context: Context<V>) => V;
18
- write: <V>(Context: Context<V>, value: V) => void;
19
- };
20
- export declare const createContainer: (ContextStorage?: ContextStorage) => Container;
21
- export declare type Hooks = {
22
- useContainer: () => Container;
23
- };
24
- export declare const runHooks: <F extends import("./asyncHooksInterface").AnyFn>(f: F, implementations: Hooks) => ReturnType<F>;
25
- export declare const useContainer: () => Container;
26
- export declare const fromContainer: (container: Container) => Hooks;
27
- export declare const runWithContainer: <F extends (...args: any) => any>(f: F, container: Container) => ReturnType<F>;
28
- export {};
13
+ export declare const createContext: <T>(value: T) => Context<T>;
@@ -1,19 +1,5 @@
1
1
  /**
2
2
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
3
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
- *
5
- * removed:
6
- * - dependencies:
7
- * - tslib
8
- * - files
9
- * - compose.ts
10
- * - methods:
11
- * - usePipeline
12
- * - assertContainer
13
- * - assertContext
14
- * - isContext
15
- * - isContainer
16
- * - pipeline.useLazy
17
- * - context.assert
18
4
  */
19
5
  export * from './pipeline';
@@ -2,37 +2,28 @@
2
2
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
3
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
4
  */
5
- import { createContext, createContainer, ContextStorage, Context, Container, useContainer, runWithContainer } from './context';
5
+ import { createContext, Context } from './context';
6
6
  import { Next } from './counter';
7
7
  export type { Next };
8
- export { createContext, createContainer, useContainer, runWithContainer };
9
- export type { ContextStorage, Context, Container };
8
+ export { createContext };
9
+ export type { Context };
10
10
  export declare type Middleware<I = unknown, O = unknown> = (input: I, next: Next<I, O>) => O;
11
11
  export declare type Middlewares<I = unknown, O = unknown> = Middleware<I, O>[];
12
12
  export declare const isPipeline: (input: any) => input is Pipeline<unknown, unknown>;
13
13
  declare const PipelineSymbol: unique symbol;
14
- export declare type PipelineOptions = {
15
- contexts?: ContextStorage;
16
- };
17
14
  export declare type RunPipelineOptions<I = unknown, O = unknown> = {
18
- container?: Container;
19
15
  onLast?: (input: I) => O;
20
- onLastWithContext?: boolean;
21
16
  };
22
17
  export declare type MiddlewareInput<I = unknown, O = unknown> = Middleware<I, O> | {
23
18
  middleware: Middleware<I, O>;
24
19
  };
25
- export declare type MiddlewareType<T extends MiddlewareInput> = T extends MiddlewareInput<infer I, infer O> ? Middleware<I, O> : never;
26
20
  export declare type Pipeline<I = unknown, O = unknown> = {
27
21
  [PipelineSymbol]: true;
28
22
  use: (...inputs: MiddlewareInput<I, O>[]) => Pipeline<I, O>;
29
23
  run: (input: I, options?: RunPipelineOptions<I, O>) => O;
30
24
  middleware: Middleware<I, O>;
31
25
  };
32
- export declare const createPipeline: <I, O>(options?: PipelineOptions | undefined) => Pipeline<I, O>;
33
- export declare type PipelineInput<T extends Pipeline> = T extends Pipeline<infer I> ? I : never;
34
- export declare type PipelineOutput<T extends Pipeline> = T extends Pipeline<any, infer O> ? O : never;
26
+ export declare const createPipeline: <I, O>() => Pipeline<I, O>;
35
27
  export declare type MaybeAsync<T> = T | Promise<T>;
36
- export declare type ThunkMiddlewareInput<I, O> = () => MaybeAsync<MiddlewareInput<I, MaybeAsync<O>>>;
37
28
  export declare type AsyncPipeline<I = unknown, O = unknown> = Pipeline<I, MaybeAsync<O>>;
38
- export declare const createAsyncPipeline: <I, O>(options?: PipelineOptions | undefined) => AsyncPipeline<I, O>;
29
+ export declare const createAsyncPipeline: <I, O>() => AsyncPipeline<I, O>;
@@ -1,4 +1,4 @@
1
- import type { ToRunners, ToThreads, CommonAPI, InitOptions, PluginOptions } from './types';
1
+ import type { ToRunners, ToThreads, CommonAPI, PluginOptions } from './types';
2
2
  /** Setup function of async plugin. */
3
3
 
4
4
  export declare type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
@@ -6,7 +6,6 @@ declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
6
6
  export declare type AsyncPlugin<Hooks, API> = {
7
7
  ASYNC_PLUGIN_SYMBOL: typeof ASYNC_PLUGIN_SYMBOL;
8
8
  } & Required<PluginOptions<Hooks, AsyncSetup<Hooks, API>>>;
9
- export declare type PluginFromAsyncManager<M extends AsyncManager<any, any>> = M extends AsyncManager<infer Hooks, infer API> ? AsyncPlugin<Hooks, API> : never;
10
9
  export declare type AsyncManager<Hooks, API> = {
11
10
  /**
12
11
  * Create a sync plugin.
@@ -28,17 +27,15 @@ export declare type AsyncManager<Hooks, API> = {
28
27
  usePlugin: (...plugins: Array<AsyncPlugin<Hooks, API> | PluginOptions<Hooks, AsyncSetup<Hooks, API>> | (() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>)>) => AsyncManager<Hooks, API>;
29
28
  /**
30
29
  * Init manager, it will call the setup function of all registered plugins.
31
- * @param options passing a custom container.
32
30
  */
33
31
 
34
- init: (options?: InitOptions) => Promise<ToRunners<Hooks>>;
32
+ init: () => Promise<ToRunners<Hooks>>;
35
33
  /**
36
- * Run callback function with current container.
34
+ * Run callback function.
37
35
  * @param callback
38
- * @param options passing a custom container.
39
36
  */
40
37
 
41
- run: <O>(cb: () => O, options?: InitOptions) => O;
38
+ run: <O>(cb: () => O) => O;
42
39
  /**
43
40
  * Register new hooks.
44
41
  * @param newHooks
@@ -0,0 +1,12 @@
1
+ import type { AsyncPlugin } from './async';
2
+ import type { Plugin } from './sync';
3
+ export declare const checkPlugins: <Hooks, API>(plugins: Plugin<Hooks, API>[] | AsyncPlugin<Hooks, API>[]) => void;
4
+ export declare function sortPlugins<Hooks, API>(input: Plugin<Hooks, API>[]): Plugin<Hooks, API>[];
5
+ export declare function sortPlugins<Hooks, API>(input: AsyncPlugin<Hooks, API>[]): AsyncPlugin<Hooks, API>[];
6
+ export declare const includePlugin: <P extends {
7
+ name: string;
8
+ }, I extends {
9
+ name: string;
10
+ }>(plugins: P[], input: I) => boolean;
11
+ export declare const isObject: (obj: unknown) => obj is Record<string, any>;
12
+ export declare const hasOwnProperty: <X extends Record<string, unknown>, Y extends PropertyKey>(obj: X, prop: Y) => obj is X & Record<Y, unknown>;
@@ -1,5 +1,4 @@
1
- import { Container } from '../farrow-pipeline';
2
- import type { Hook, CommonAPI, ToRunners, ToThreads, InitOptions, PluginOptions } from './types';
1
+ import type { Hook, CommonAPI, ToRunners, ToThreads, PluginOptions } from './types';
3
2
  /** Setup function of sync plugin. */
4
3
 
5
4
  export declare type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
@@ -7,7 +6,6 @@ declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
7
6
  export declare type Plugin<Hooks, API> = {
8
7
  SYNC_PLUGIN_SYMBOL: typeof SYNC_PLUGIN_SYMBOL;
9
8
  } & Required<PluginOptions<Hooks, Setup<Hooks, API>>>;
10
- export declare type PluginFromManager<M extends Manager<any, any>> = M extends Manager<infer Hooks, infer API> ? Plugin<Hooks, API> : never;
11
9
  export declare type Manager<Hooks, API> = {
12
10
  /**
13
11
  * Create a sync plugin.
@@ -29,17 +27,15 @@ export declare type Manager<Hooks, API> = {
29
27
  usePlugin: (...plugins: Array<Plugin<Hooks, API> | PluginOptions<Hooks, Setup<Hooks, API>> | (() => PluginOptions<Hooks, Setup<Hooks, API>>)>) => Manager<Hooks, API>;
30
28
  /**
31
29
  * Init manager, it will call the setup function of all registered plugins.
32
- * @param options passing a custom container.
33
30
  */
34
31
 
35
- init: (options?: InitOptions) => ToRunners<Hooks>;
32
+ init: () => ToRunners<Hooks>;
36
33
  /**
37
- * Run callback function with current container.
34
+ * Run callback function.
38
35
  * @param callback
39
- * @param options passing a custom container.
40
36
  */
41
37
 
42
- run: <O>(cb: () => O, options?: InitOptions) => O;
38
+ run: <O>(cb: () => O) => O;
43
39
  /**
44
40
  * Register new hooks.
45
41
  * @param newHooks
@@ -73,9 +69,7 @@ export declare const DEFAULT_OPTIONS: {
73
69
  registerHook: {};
74
70
  };
75
71
  export declare const createManager: <Hooks, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => Manager<Hooks, API>;
76
- export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], container: Container, hooksMap?: Hooks | undefined) => ToRunners<Hooks>;
72
+ export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], hooksMap?: Hooks | undefined) => ToRunners<Hooks>;
77
73
  export declare const cloneHook: (hook: Hook) => Hook;
78
74
  export declare const closeHooksMap: <Hooks>(record: Hooks) => Hooks;
79
- export declare const isObject: (obj: unknown) => obj is Record<string, any>;
80
- export declare const hasOwnProperty: <X extends Record<string, unknown>, Y extends PropertyKey>(obj: X, prop: Y) => obj is X & Record<Y, unknown>;
81
75
  export {};
@@ -1,4 +1,4 @@
1
- import type { Pipeline, Container, MaybeAsync, Middleware, AsyncPipeline } from '../farrow-pipeline';
1
+ import type { Pipeline, MaybeAsync, Middleware, AsyncPipeline } from '../farrow-pipeline';
2
2
  import type { Brook, Waterfall, AsyncBrook, AsyncWaterfall } from '../waterfall';
3
3
  import type { Worker, Workflow, AsyncWorker, AsyncWorkflow, ParallelWorkflow } from '../workflow';
4
4
  /** All hook types. */
@@ -29,11 +29,6 @@ export declare type PluginOptions<Hooks, Setup = undefined> = {
29
29
  usePlugins?: PluginOptions<Hooks, Setup>[];
30
30
  registerHook?: Partial<Hooks>;
31
31
  };
32
- /** Options of manager.init method. */
33
-
34
- export declare type InitOptions = {
35
- container?: Container;
36
- };
37
32
  /** Common api of setup function. */
38
33
 
39
34
  export declare type CommonAPI<Hooks> = {
@@ -1,4 +1,4 @@
1
- import { MaybeAsync, Container } from '../farrow-pipeline';
1
+ import { MaybeAsync } from '../farrow-pipeline';
2
2
  declare const ASYNC_WATERFALL_SYMBOL: unique symbol;
3
3
  export declare type AsyncBrook<I = unknown> = (I: I) => MaybeAsync<I>;
4
4
  export declare type AsyncBrookInput<I = unknown> = AsyncBrook<I> | {
@@ -8,7 +8,6 @@ export declare type AsyncBrooks<I = unknown> = AsyncBrook<I>[];
8
8
  export declare type AsyncBrookInputs<I = unknown> = AsyncBrookInput<I>[];
9
9
  export declare const getAsyncBrook: <I>(input: AsyncBrookInput<I>) => AsyncBrook<I>;
10
10
  export declare type RunAsyncWaterfallOptions<I = unknown> = {
11
- container?: Container;
12
11
  onLast?: AsyncBrook<I>;
13
12
  };
14
13
  export declare type AsyncWaterfall<I> = {
@@ -17,11 +16,6 @@ export declare type AsyncWaterfall<I> = {
17
16
  middleware: AsyncBrook<I>;
18
17
  [ASYNC_WATERFALL_SYMBOL]: true;
19
18
  };
20
- export declare type AsyncWaterfall2AsyncBrook<P extends AsyncWaterfall<any>> = P extends AsyncWaterfall<infer I> ? AsyncBrook<I> : never;
21
- export declare type AsyncWaterfallRecord = Record<string, AsyncWaterfall<any>>;
22
- export declare type AsyncWaterfalls2Brooks<PS extends AsyncWaterfallRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWaterfall<any> ? AsyncWaterfall2AsyncBrook<PS[K]> : PS[K] extends void ? void : never };
23
- export declare type RunnerFromAsyncWaterfall<M extends AsyncWaterfall<any>> = M extends AsyncWaterfall<infer VS> ? AsyncWaterfall<VS>['run'] : never;
24
- export declare type AsyncWaterfalls2Runners<PS extends AsyncWaterfallRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWaterfall<any> ? RunnerFromAsyncWaterfall<PS[K]> : PS[K] extends void ? void : never };
25
19
  export declare const createAsyncWaterfall: <I = void>() => AsyncWaterfall<I>;
26
20
  export declare const isAsyncWaterfall: (input: any) => input is AsyncWaterfall<any>;
27
21
  export {};