@modern-js/plugin 1.3.7 → 1.4.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 (57) hide show
  1. package/CHANGELOG.md +13 -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 +4 -11
  6. package/dist/js/modern/manager/runner.js +1 -9
  7. package/dist/js/modern/manager/sync.js +8 -16
  8. package/dist/js/modern/waterfall/async.js +1 -3
  9. package/dist/js/modern/waterfall/sync.js +1 -3
  10. package/dist/js/modern/workflow/async.js +3 -3
  11. package/dist/js/modern/workflow/parallel.js +2 -2
  12. package/dist/js/modern/workflow/sync.js +3 -3
  13. package/dist/js/node/farrow-pipeline/context.js +15 -88
  14. package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
  15. package/dist/js/node/manager/async.js +4 -12
  16. package/dist/js/node/manager/runner.js +1 -9
  17. package/dist/js/node/manager/sync.js +8 -15
  18. package/dist/js/node/waterfall/async.js +0 -2
  19. package/dist/js/node/waterfall/sync.js +0 -2
  20. package/dist/js/node/workflow/async.js +3 -3
  21. package/dist/js/node/workflow/parallel.js +2 -2
  22. package/dist/js/node/workflow/sync.js +3 -3
  23. package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
  24. package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
  25. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
  26. package/dist/js/treeshaking/manager/async.js +10 -17
  27. package/dist/js/treeshaking/manager/runner.js +1 -7
  28. package/dist/js/treeshaking/manager/sync.js +9 -17
  29. package/dist/js/treeshaking/waterfall/async.js +1 -3
  30. package/dist/js/treeshaking/waterfall/sync.js +1 -3
  31. package/dist/js/treeshaking/workflow/async.js +6 -6
  32. package/dist/js/treeshaking/workflow/parallel.js +5 -5
  33. package/dist/js/treeshaking/workflow/sync.js +3 -3
  34. package/dist/types/farrow-pipeline/context.d.ts +5 -20
  35. package/dist/types/farrow-pipeline/index.d.ts +0 -14
  36. package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
  37. package/dist/types/manager/async.d.ts +4 -7
  38. package/dist/types/manager/sync.d.ts +5 -9
  39. package/dist/types/manager/types.d.ts +1 -6
  40. package/dist/types/waterfall/async.d.ts +1 -7
  41. package/dist/types/waterfall/sync.d.ts +0 -7
  42. package/dist/types/workflow/async.d.ts +1 -7
  43. package/dist/types/workflow/parallel.d.ts +2 -9
  44. package/dist/types/workflow/sync.d.ts +1 -10
  45. package/package.json +1 -12
  46. package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -74
  47. package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
  48. package/dist/js/modern/farrow-pipeline/hook.js +0 -42
  49. package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -93
  50. package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
  51. package/dist/js/node/farrow-pipeline/hook.js +0 -52
  52. package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -74
  53. package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
  54. package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
  55. package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
  56. package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
  57. package/dist/types/farrow-pipeline/hook.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f29e9ba: feat(plugin): simplify context usage, no longer depend on containers
8
+
9
+ ## 1.3.8
10
+
11
+ ### Patch Changes
12
+
13
+ - b7302f781: Export some required types
14
+ - e0e708f83: perf(app-tools): speed up modern start command
15
+
3
16
  ## 1.3.7
4
17
 
5
18
  ### Patch Changes
@@ -2,39 +2,30 @@
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 { createHooks } from "./hook";
6
- const ContextSymbol = Symbol.for('MODERN_CONTEXT');
7
5
  export const createContext = value => {
8
- const id = Symbol('MODERN_CONTEXT_ID');
6
+ let currentValue;
9
7
 
10
8
  const create = value => {
11
- const use = () => {
12
- const container = useContainer();
13
- return Object.seal({
14
- get value() {
15
- return container.read(Context);
16
- },
9
+ currentValue = value;
17
10
 
18
- set value(v) {
19
- container.write(Context, v);
20
- }
11
+ const use = () => ({
12
+ get value() {
13
+ return currentValue;
14
+ },
21
15
 
22
- });
23
- };
16
+ set value(v) {
17
+ currentValue = v;
18
+ }
24
19
 
25
- const get = () => {
26
- const container = useContainer();
27
- return container.read(Context);
28
- };
20
+ });
21
+
22
+ const get = () => currentValue;
29
23
 
30
24
  const set = v => {
31
- const container = useContainer();
32
- container.write(Context, v);
25
+ currentValue = v;
33
26
  };
34
27
 
35
28
  const Context = {
36
- id,
37
- [ContextSymbol]: value,
38
29
  create,
39
30
  use,
40
31
  get,
@@ -44,56 +35,4 @@ export const createContext = value => {
44
35
  };
45
36
 
46
37
  return create(value);
47
- };
48
-
49
- const createContextMap = storage => {
50
- const contextMap = new Map();
51
- const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
52
-
53
- for (let i = 0; i < contexts.length; i++) {
54
- contextMap.set(contexts[i].id, contexts[i]);
55
- }
56
-
57
- return contextMap;
58
- };
59
-
60
- export const createContainer = (ContextStorage = {}) => {
61
- const contextMap = createContextMap(ContextStorage);
62
-
63
- const read = context => {
64
- const target = contextMap.get(context.id);
65
-
66
- if (target) {
67
- return target[ContextSymbol];
68
- }
69
-
70
- return context[ContextSymbol];
71
- };
72
-
73
- const write = (context, value) => {
74
- contextMap.set(context.id, context.create(value));
75
- };
76
-
77
- return Object.freeze({
78
- read,
79
- write
80
- });
81
- };
82
- const {
83
- run,
84
- hooks
85
- } = createHooks({
86
- useContainer: () => {
87
- throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
88
- }
89
- });
90
- export const runHooks = run;
91
- export const {
92
- useContainer
93
- } = hooks;
94
- export const fromContainer = container => ({
95
- useContainer: () => {
96
- return container;
97
- }
98
- });
99
- export const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
38
+ };
@@ -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";
@@ -8,9 +8,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
8
8
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
9
9
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
10
10
  */
11
- import { createContext, createContainer, fromContainer, runHooks, useContainer, runWithContainer } from "./context";
11
+ import { createContext } from "./context";
12
12
  import { createCounter } from "./counter";
13
- export { createContext, createContainer, useContainer, runWithContainer };
13
+ export { createContext };
14
14
  export const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
15
15
  const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
16
16
 
@@ -24,9 +24,7 @@ const getMiddleware = input => {
24
24
  throw new Error(`${input} is not a Middleware`);
25
25
  };
26
26
 
27
- export const createPipeline = options => {
28
- const config = _objectSpread({}, options);
29
-
27
+ export const createPipeline = () => {
30
28
  const middlewares = [];
31
29
 
32
30
  const use = (...inputs) => {
@@ -34,50 +32,35 @@ export const createPipeline = options => {
34
32
  return pipeline;
35
33
  };
36
34
 
37
- const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
35
+ const createCurrentCounter = onLast => {
38
36
  return createCounter((index, input, next) => {
39
37
  if (index >= middlewares.length) {
40
38
  if (onLast) {
41
- if (onLastWithContext) {
42
- return runHooks(() => onLast(input), hooks);
43
- }
44
-
45
39
  return onLast(input);
46
40
  }
47
41
 
48
42
  throw new Error(`Expect returning a value, but all middlewares just calling next()`);
49
43
  }
50
44
 
51
- return runHooks(() => middlewares[index](input, next), hooks);
45
+ return middlewares[index](input, next);
52
46
  });
53
47
  };
54
48
 
55
- const currentContainer = createContainer(config.contexts);
56
- const currentHooks = fromContainer(currentContainer);
57
- const currentCounter = createCurrentCounter(currentHooks);
49
+ const currentCounter = createCurrentCounter();
58
50
 
59
51
  const getCounter = options => {
60
52
  if (!options) {
61
53
  return currentCounter;
62
54
  }
63
55
 
64
- if (options !== null && options !== void 0 && options.container) {
65
- const hooks = fromContainer(options === null || options === void 0 ? void 0 : options.container);
66
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
67
- }
68
-
69
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
56
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
70
57
  };
71
58
 
72
59
  const run = (input, options) => getCounter(options).start(input);
73
60
 
74
- const middleware = (input, next) => {
75
- const container = useContainer();
76
- return run(input, {
77
- container,
78
- onLast: next
79
- });
80
- };
61
+ const middleware = (input, next) => run(input, {
62
+ onLast: next
63
+ });
81
64
 
82
65
  const pipeline = {
83
66
  [PipelineSymbol]: true,
@@ -87,7 +70,7 @@ export const createPipeline = options => {
87
70
  };
88
71
  return pipeline;
89
72
  };
90
- export const createAsyncPipeline = options => {
91
- const pipeline = createPipeline(options);
73
+ export const createAsyncPipeline = () => {
74
+ const pipeline = createPipeline();
92
75
  return _objectSpread({}, pipeline);
93
76
  };
@@ -4,7 +4,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
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; }
6
6
 
7
- import { runWithContainer, createContainer } from "../farrow-pipeline";
8
7
  import { generateRunner, DEFAULT_OPTIONS } from "./sync";
9
8
  import { useRunner } from "./runner";
10
9
  import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
@@ -80,23 +79,17 @@ export const createAsyncManager = (hooks, api) => {
80
79
  plugins = [];
81
80
  };
82
81
 
83
- const currentContainer = createContainer();
84
-
85
- const init = async options => {
86
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
82
+ const init = async () => {
87
83
  const sortedPlugins = sortPlugins(plugins);
88
84
 
89
85
  const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
90
86
 
91
87
  checkPlugins(sortedPlugins);
92
- const hooksList = await Promise.all(sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container)));
93
- return generateRunner(hooksList, container, currentHooks);
88
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
89
+ return generateRunner(hooksList, currentHooks);
94
90
  };
95
91
 
96
- const run = (cb, options) => {
97
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
98
- return runWithContainer(cb, container);
99
- };
92
+ const run = cb => cb();
100
93
 
101
94
  const manager = {
102
95
  createPlugin,
@@ -1,11 +1,3 @@
1
1
  import { createContext } from "../farrow-pipeline";
2
2
  export const RunnerContext = createContext(null);
3
- export const useRunner = () => {
4
- const runner = RunnerContext.use().value;
5
-
6
- if (!runner) {
7
- throw new Error(`Can't call useRunner out of scope, it should be placed in hooks of plugin`);
8
- }
9
-
10
- return runner;
11
- };
3
+ export const useRunner = () => RunnerContext.get();
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
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; }
6
6
 
7
- import { isPipeline, createPipeline, runWithContainer, createContainer } from "../farrow-pipeline";
7
+ import { isPipeline, createPipeline } from "../farrow-pipeline";
8
8
  import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
9
9
  import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
10
10
  import { RunnerContext, useRunner } from "./runner";
@@ -89,23 +89,17 @@ export const createManager = (hooks, api) => {
89
89
  plugins = [];
90
90
  };
91
91
 
92
- const currentContainer = createContainer();
93
-
94
- const init = options => {
95
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
92
+ const init = () => {
96
93
  const sortedPlugins = sortPlugins(plugins);
97
94
 
98
95
  const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
99
96
 
100
97
  checkPlugins(sortedPlugins);
101
- const hooksList = sortedPlugins.map(plugin => runWithContainer(() => plugin.setup(mergedPluginAPI), container));
102
- return generateRunner(hooksList, container, currentHooks);
98
+ const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
99
+ return generateRunner(hooksList, currentHooks);
103
100
  };
104
101
 
105
- const run = (cb, options) => {
106
- const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
107
- return runWithContainer(cb, container);
108
- };
102
+ const run = cb => cb();
109
103
 
110
104
  const manager = {
111
105
  createPlugin,
@@ -123,7 +117,7 @@ export const createManager = (hooks, api) => {
123
117
 
124
118
  return clone();
125
119
  };
126
- export const generateRunner = (hooksList, container, hooksMap) => {
120
+ export const generateRunner = (hooksList, hooksMap) => {
127
121
  const runner = {};
128
122
  const cloneShape = closeHooksMap(hooksMap);
129
123
 
@@ -141,13 +135,11 @@ export const generateRunner = (hooksList, container, hooksMap) => {
141
135
  // @ts-expect-error
142
136
 
143
137
 
144
- runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({
145
- container
146
- }, options));
138
+ runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
147
139
  }
148
140
  }
149
141
 
150
- container.write(RunnerContext, runner);
142
+ RunnerContext.set(runner);
151
143
  return runner;
152
144
  };
153
145
  export const cloneHook = hook => {
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
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; }
6
6
 
7
- import { createAsyncPipeline, useContainer } from "../farrow-pipeline";
7
+ import { createAsyncPipeline } from "../farrow-pipeline";
8
8
  const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
9
9
  export const getAsyncBrook = input => {
10
10
  if (typeof input === 'function') {
@@ -28,9 +28,7 @@ export const createAsyncWaterfall = () => {
28
28
  }));
29
29
 
30
30
  const middleware = input => {
31
- const container = useContainer();
32
31
  return pipeline.run(input, {
33
- container,
34
32
  onLast: input => input
35
33
  });
36
34
  };
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
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; }
6
6
 
7
- import { useContainer, createPipeline } from "../farrow-pipeline";
7
+ import { createPipeline } from "../farrow-pipeline";
8
8
  const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
9
9
  export const getBrook = input => {
10
10
  if (typeof input === 'function') {
@@ -28,9 +28,7 @@ export const createWaterfall = () => {
28
28
  }));
29
29
 
30
30
  const middleware = input => {
31
- const container = useContainer();
32
31
  return pipeline.run(input, {
33
- container,
34
32
  onLast: input => input
35
33
  });
36
34
  };
@@ -15,10 +15,10 @@ export const createAsyncWorkflow = () => {
15
15
  return workflow;
16
16
  };
17
17
 
18
- const run = async (input, options) => {
19
- const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
18
+ const run = async input => {
19
+ const result = pipeline.run(input, {
20
20
  onLast: () => []
21
- }));
21
+ });
22
22
 
23
23
  if (isPromise(result)) {
24
24
  return result.then(result => result.filter(Boolean));
@@ -15,9 +15,9 @@ export const createParallelWorkflow = () => {
15
15
  return workflow;
16
16
  };
17
17
 
18
- const run = async (input, options) => Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
18
+ const run = async input => Promise.all(pipeline.run(input, {
19
19
  onLast: () => []
20
- }))).then(result => result.filter(Boolean));
20
+ })).then(result => result.filter(Boolean));
21
21
 
22
22
  const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
23
23
  run,
@@ -14,10 +14,10 @@ export const createWorkflow = () => {
14
14
  return workflow;
15
15
  };
16
16
 
17
- const run = (input, options) => {
18
- const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
17
+ const run = input => {
18
+ const result = pipeline.run(input, {
19
19
  onLast: () => []
20
- }));
20
+ });
21
21
  return result.filter(Boolean);
22
22
  };
23
23
 
@@ -3,47 +3,36 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useContainer = exports.runWithContainer = exports.runHooks = exports.fromContainer = exports.createContext = exports.createContainer = void 0;
7
-
8
- var _hook = require("./hook");
6
+ exports.createContext = void 0;
9
7
 
10
8
  /**
11
9
  * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
12
10
  * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
13
11
  */
14
- const ContextSymbol = Symbol.for('MODERN_CONTEXT');
15
-
16
12
  const createContext = value => {
17
- const id = Symbol('MODERN_CONTEXT_ID');
13
+ let currentValue;
18
14
 
19
15
  const create = value => {
20
- const use = () => {
21
- const container = useContainer();
22
- return Object.seal({
23
- get value() {
24
- return container.read(Context);
25
- },
16
+ currentValue = value;
26
17
 
27
- set value(v) {
28
- container.write(Context, v);
29
- }
18
+ const use = () => ({
19
+ get value() {
20
+ return currentValue;
21
+ },
30
22
 
31
- });
32
- };
23
+ set value(v) {
24
+ currentValue = v;
25
+ }
33
26
 
34
- const get = () => {
35
- const container = useContainer();
36
- return container.read(Context);
37
- };
27
+ });
28
+
29
+ const get = () => currentValue;
38
30
 
39
31
  const set = v => {
40
- const container = useContainer();
41
- container.write(Context, v);
32
+ currentValue = v;
42
33
  };
43
34
 
44
35
  const Context = {
45
- id,
46
- [ContextSymbol]: value,
47
36
  create,
48
37
  use,
49
38
  get,
@@ -55,66 +44,4 @@ const createContext = value => {
55
44
  return create(value);
56
45
  };
57
46
 
58
- exports.createContext = createContext;
59
-
60
- const createContextMap = storage => {
61
- const contextMap = new Map();
62
- const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
63
-
64
- for (let i = 0; i < contexts.length; i++) {
65
- contextMap.set(contexts[i].id, contexts[i]);
66
- }
67
-
68
- return contextMap;
69
- };
70
-
71
- const createContainer = (ContextStorage = {}) => {
72
- const contextMap = createContextMap(ContextStorage);
73
-
74
- const read = context => {
75
- const target = contextMap.get(context.id);
76
-
77
- if (target) {
78
- return target[ContextSymbol];
79
- }
80
-
81
- return context[ContextSymbol];
82
- };
83
-
84
- const write = (context, value) => {
85
- contextMap.set(context.id, context.create(value));
86
- };
87
-
88
- return Object.freeze({
89
- read,
90
- write
91
- });
92
- };
93
-
94
- exports.createContainer = createContainer;
95
- const {
96
- run,
97
- hooks
98
- } = (0, _hook.createHooks)({
99
- useContainer: () => {
100
- throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
101
- }
102
- });
103
- const runHooks = run;
104
- exports.runHooks = runHooks;
105
- const {
106
- useContainer
107
- } = hooks;
108
- exports.useContainer = useContainer;
109
-
110
- const fromContainer = container => ({
111
- useContainer: () => {
112
- return container;
113
- }
114
- });
115
-
116
- exports.fromContainer = fromContainer;
117
-
118
- const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
119
-
120
- exports.runWithContainer = runWithContainer;
47
+ exports.createContext = createContext;
@@ -4,12 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createAsyncPipeline = void 0;
7
- Object.defineProperty(exports, "createContainer", {
8
- enumerable: true,
9
- get: function () {
10
- return _context.createContainer;
11
- }
12
- });
13
7
  Object.defineProperty(exports, "createContext", {
14
8
  enumerable: true,
15
9
  get: function () {
@@ -17,18 +11,6 @@ Object.defineProperty(exports, "createContext", {
17
11
  }
18
12
  });
19
13
  exports.isPipeline = exports.createPipeline = void 0;
20
- Object.defineProperty(exports, "runWithContainer", {
21
- enumerable: true,
22
- get: function () {
23
- return _context.runWithContainer;
24
- }
25
- });
26
- Object.defineProperty(exports, "useContainer", {
27
- enumerable: true,
28
- get: function () {
29
- return _context.useContainer;
30
- }
31
- });
32
14
 
33
15
  var _context = require("./context");
34
16
 
@@ -55,9 +37,7 @@ const getMiddleware = input => {
55
37
  throw new Error(`${input} is not a Middleware`);
56
38
  };
57
39
 
58
- const createPipeline = options => {
59
- const config = _objectSpread({}, options);
60
-
40
+ const createPipeline = () => {
61
41
  const middlewares = [];
62
42
 
63
43
  const use = (...inputs) => {
@@ -65,50 +45,35 @@ const createPipeline = options => {
65
45
  return pipeline;
66
46
  };
67
47
 
68
- const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
48
+ const createCurrentCounter = onLast => {
69
49
  return (0, _counter.createCounter)((index, input, next) => {
70
50
  if (index >= middlewares.length) {
71
51
  if (onLast) {
72
- if (onLastWithContext) {
73
- return (0, _context.runHooks)(() => onLast(input), hooks);
74
- }
75
-
76
52
  return onLast(input);
77
53
  }
78
54
 
79
55
  throw new Error(`Expect returning a value, but all middlewares just calling next()`);
80
56
  }
81
57
 
82
- return (0, _context.runHooks)(() => middlewares[index](input, next), hooks);
58
+ return middlewares[index](input, next);
83
59
  });
84
60
  };
85
61
 
86
- const currentContainer = (0, _context.createContainer)(config.contexts);
87
- const currentHooks = (0, _context.fromContainer)(currentContainer);
88
- const currentCounter = createCurrentCounter(currentHooks);
62
+ const currentCounter = createCurrentCounter();
89
63
 
90
64
  const getCounter = options => {
91
65
  if (!options) {
92
66
  return currentCounter;
93
67
  }
94
68
 
95
- if (options !== null && options !== void 0 && options.container) {
96
- const hooks = (0, _context.fromContainer)(options === null || options === void 0 ? void 0 : options.container);
97
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
98
- }
99
-
100
- return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
69
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
101
70
  };
102
71
 
103
72
  const run = (input, options) => getCounter(options).start(input);
104
73
 
105
- const middleware = (input, next) => {
106
- const container = (0, _context.useContainer)();
107
- return run(input, {
108
- container,
109
- onLast: next
110
- });
111
- };
74
+ const middleware = (input, next) => run(input, {
75
+ onLast: next
76
+ });
112
77
 
113
78
  const pipeline = {
114
79
  [PipelineSymbol]: true,
@@ -121,8 +86,8 @@ const createPipeline = options => {
121
86
 
122
87
  exports.createPipeline = createPipeline;
123
88
 
124
- const createAsyncPipeline = options => {
125
- const pipeline = createPipeline(options);
89
+ const createAsyncPipeline = () => {
90
+ const pipeline = createPipeline();
126
91
  return _objectSpread({}, pipeline);
127
92
  };
128
93