@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
@@ -1,164 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useContainer = exports.runWithContainer = exports.runHooks = exports.isContext = exports.isContainer = exports.fromContainer = exports.createContext = exports.createContainer = exports.assertContext = exports.assertContainer = exports.ContainerSymbol = void 0;
7
-
8
- var _hook = require("./hook");
9
-
10
- /**
11
- * Copyright Lucifier129 and other contributors.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file at
15
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
16
- *
17
- */
18
- const ContextSymbol = Symbol('Context');
19
-
20
- const isContext = input => Object.prototype.hasOwnProperty.call(input, ContextSymbol);
21
-
22
- exports.isContext = isContext;
23
-
24
- const assertContext = input => {
25
- if (!isContext(input)) {
26
- throw new Error(`Expected Context, but received ${input}`);
27
- }
28
- };
29
-
30
- exports.assertContext = assertContext;
31
-
32
- const createContext = value => {
33
- const id = Symbol('ContextID'); // eslint-disable-next-line @typescript-eslint/no-shadow
34
-
35
- const create = value => {
36
- const use = () => {
37
- // eslint-disable-next-line react-hooks/rules-of-hooks
38
- const container = useContainer();
39
- return Object.seal({
40
- get value() {
41
- return container.read(Context);
42
- },
43
-
44
- set value(v) {
45
- container.write(Context, v);
46
- }
47
-
48
- });
49
- };
50
-
51
- const get = () => {
52
- // eslint-disable-next-line react-hooks/rules-of-hooks
53
- const container = useContainer();
54
- return container.read(Context);
55
- };
56
-
57
- const set = v => {
58
- // eslint-disable-next-line react-hooks/rules-of-hooks
59
- const container = useContainer();
60
- container.write(Context, v);
61
- };
62
-
63
- const assert = () => {
64
- // eslint-disable-next-line @typescript-eslint/no-shadow
65
- const value = get();
66
-
67
- if (value === null || value === undefined) {
68
- throw new Error( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
69
- `Expected value is not null or undefined, but got: ${value}`);
70
- }
71
-
72
- return value;
73
- };
74
-
75
- const Context = {
76
- id,
77
- [ContextSymbol]: value,
78
- create,
79
- use,
80
- get,
81
- set,
82
- assert
83
- };
84
- return Context;
85
- };
86
-
87
- return create(value);
88
- };
89
-
90
- exports.createContext = createContext;
91
- const ContainerSymbol = Symbol('Container'); // eslint-disable-next-line @typescript-eslint/no-redeclare
92
-
93
- exports.ContainerSymbol = ContainerSymbol;
94
-
95
- const isContainer = input => Boolean(input === null || input === void 0 ? void 0 : input[ContainerSymbol]);
96
-
97
- exports.isContainer = isContainer;
98
-
99
- const assertContainer = input => {
100
- if (!isContainer(input)) {
101
- throw new Error(`Expected Context, but received ${input}`);
102
- }
103
- };
104
-
105
- exports.assertContainer = assertContainer;
106
-
107
- const createContextMap = storage => {
108
- const contextMap = new Map();
109
- Object.values(storage).forEach(context => {
110
- contextMap.set(context.id, context);
111
- });
112
- return contextMap;
113
- };
114
-
115
- const createContainer = (ContextStorage = {}) => {
116
- const contextMap = createContextMap(ContextStorage);
117
-
118
- const read = context => {
119
- const target = contextMap.get(context.id);
120
-
121
- if (target) {
122
- return target[ContextSymbol];
123
- }
124
-
125
- return context[ContextSymbol];
126
- };
127
-
128
- const write = (context, value) => {
129
- contextMap.set(context.id, context.create(value));
130
- };
131
-
132
- const container = Object.freeze({
133
- [ContainerSymbol]: true,
134
- read,
135
- write
136
- });
137
- return container;
138
- };
139
-
140
- exports.createContainer = createContainer;
141
- const {
142
- run,
143
- hooks
144
- } = (0, _hook.createHooks)({
145
- useContainer: () => {
146
- throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
147
- }
148
- });
149
- const runHooks = run;
150
- exports.runHooks = runHooks;
151
- const {
152
- useContainer
153
- } = hooks;
154
- exports.useContainer = useContainer;
155
-
156
- const fromContainer = container => ({
157
- useContainer: () => container
158
- });
159
-
160
- exports.fromContainer = fromContainer;
161
-
162
- const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
163
-
164
- exports.runWithContainer = runWithContainer;
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createCounter = exports.createAsyncCounter = void 0;
7
-
8
- /**
9
- * Copyright Lucifier129 and other contributors.
10
- *
11
- * This source code is licensed under the MIT license found in the
12
- * LICENSE file at
13
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
14
- *
15
- */
16
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
17
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
18
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
19
- const createCounter = callback => {
20
- const dispatch = (index, input) => {
21
- const next = (nextInput = input) => dispatch(index + 1, nextInput);
22
-
23
- return callback(index, input, next);
24
- };
25
-
26
- const start = input => dispatch(0, input);
27
-
28
- return {
29
- start,
30
- dispatch
31
- };
32
- }; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
33
-
34
-
35
- exports.createCounter = createCounter;
36
-
37
- const createAsyncCounter = callback => {
38
- const dispatch = async (index, input) => {
39
- const next = (nextInput = input) => dispatch(index + 1, nextInput);
40
-
41
- return callback(index, input, next);
42
- };
43
-
44
- const start = input => dispatch(0, input);
45
-
46
- return {
47
- start,
48
- dispatch
49
- };
50
- };
51
-
52
- exports.createAsyncCounter = createAsyncCounter;
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createHooks = void 0;
7
-
8
- var _asyncHooksInterface = require("./asyncHooksInterface");
9
-
10
- /**
11
- * Copyright Lucifier129 and other contributors.
12
- *
13
- * This source code is licensed under the MIT license found in the
14
- * LICENSE file at
15
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
16
- *
17
- */
18
- const createHooks = defaultHooks => {
19
- let currentHooks = {};
20
- const hooks = {};
21
-
22
- for (const key in defaultHooks) {
23
- // eslint-disable-next-line @typescript-eslint/no-loop-func
24
- const f = (...args) => {
25
- var _asyncHooks$get;
26
-
27
- // eslint-disable-next-line @typescript-eslint/no-shadow
28
- const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = _asyncHooksInterface.asyncHooks === null || _asyncHooksInterface.asyncHooks === void 0 ? void 0 : _asyncHooksInterface.asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
29
- let handler = hooks[key];
30
-
31
- if (typeof handler !== 'function') {
32
- handler = defaultHooks[key];
33
- }
34
-
35
- return handler(...args);
36
- };
37
-
38
- hooks[key] = f;
39
- }
40
-
41
- const run = (f, implementations) => {
42
- try {
43
- currentHooks = implementations || defaultHooks;
44
- _asyncHooksInterface.asyncHooks === null || _asyncHooksInterface.asyncHooks === void 0 ? void 0 : _asyncHooksInterface.asyncHooks.set(currentHooks);
45
- return f();
46
- } finally {
47
- currentHooks = defaultHooks;
48
- }
49
- };
50
-
51
- return {
52
- run,
53
- hooks
54
- };
55
- };
56
-
57
- exports.createHooks = createHooks;
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useAsyncPipeline = exports.isAsyncPipeline = exports.getAsyncMiddleware = exports.createAsyncPipeline = void 0;
7
-
8
- var _context = require("../context");
9
-
10
- var _counter = require("../counter");
11
-
12
- 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; }
13
-
14
- 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; }
15
-
16
- 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; }
17
-
18
- const ASYNC_PIPELINE_SYMBOL = Symbol('ASYNC_PIPELINE_SYMBOL');
19
-
20
- const isAsyncPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_PIPELINE_SYMBOL]);
21
-
22
- exports.isAsyncPipeline = isAsyncPipeline;
23
-
24
- const getAsyncMiddleware = input => {
25
- if (typeof input === 'function') {
26
- return input;
27
- } else if (input && typeof input.middleware === 'function') {
28
- return input.middleware;
29
- } // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
30
-
31
-
32
- throw new Error(`${input} is not a Middleware or { middleware: Middleware }`);
33
- };
34
-
35
- exports.getAsyncMiddleware = getAsyncMiddleware;
36
-
37
- const createAsyncPipeline = options => {
38
- const config = _objectSpread({}, options);
39
-
40
- const middlewares = [];
41
-
42
- const use = (...inputs) => {
43
- middlewares.push(...inputs.map(getAsyncMiddleware));
44
- return pipeline;
45
- };
46
-
47
- const createCurrentCounter = (hooks, onLast) => (0, _counter.createAsyncCounter)(async (index, input, next) => {
48
- if (index >= middlewares.length) {
49
- if (onLast) {
50
- return onLast(input);
51
- }
52
-
53
- throw new Error(`Expect returning a value, but all middlewares just calling next()`);
54
- }
55
-
56
- const middleware = middlewares[index];
57
- const result = await (0, _context.runHooks)(async () => middleware(input, next), hooks);
58
- return result;
59
- });
60
-
61
- const currentContainer = (0, _context.createContainer)(config.contexts);
62
- const currentHooks = (0, _context.fromContainer)(currentContainer);
63
- const currentCounter = createCurrentCounter(currentHooks); // eslint-disable-next-line @typescript-eslint/no-shadow
64
-
65
- const run = (input, options) => {
66
- var _options$container;
67
-
68
- const container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
69
- const hooks = container === currentContainer ? currentHooks : (0, _context.fromContainer)(container);
70
- let counter = container === currentContainer ? currentCounter : createCurrentCounter(hooks);
71
-
72
- if (options !== null && options !== void 0 && options.onLast) {
73
- counter = createCurrentCounter(hooks, options.onLast);
74
- }
75
-
76
- const result = counter.start(input);
77
- return result;
78
- };
79
-
80
- const middleware = (input, next) => {
81
- // eslint-disable-next-line react-hooks/rules-of-hooks
82
- const container = (0, _context.useContainer)();
83
- return run(input, {
84
- container,
85
- onLast: next
86
- });
87
- };
88
-
89
- const pipeline = {
90
- [ASYNC_PIPELINE_SYMBOL]: true,
91
- use,
92
- run,
93
- middleware
94
- };
95
- return pipeline;
96
- };
97
-
98
- exports.createAsyncPipeline = createAsyncPipeline;
99
-
100
- const useAsyncPipeline = pipeline => {
101
- const container = (0, _context.useContainer)();
102
-
103
- const runPipeline = (input, options) => pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
104
- container
105
- }));
106
-
107
- return runPipeline;
108
- };
109
-
110
- exports.useAsyncPipeline = useAsyncPipeline;
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _sync = require("./sync");
8
-
9
- Object.keys(_sync).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _sync[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _sync[key];
16
- }
17
- });
18
- });
19
-
20
- var _async = require("./async");
21
-
22
- Object.keys(_async).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _async[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _async[key];
29
- }
30
- });
31
- });
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.usePipeline = exports.isPipeline = exports.getMiddleware = exports.createPipeline = void 0;
7
-
8
- var _context = require("../context");
9
-
10
- var _counter = require("../counter");
11
-
12
- 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; }
13
-
14
- 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; }
15
-
16
- 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; }
17
-
18
- const PIPELINE_SYMBOL = Symbol('PIPELINE_SYMBOL');
19
-
20
- const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PIPELINE_SYMBOL]);
21
-
22
- exports.isPipeline = isPipeline;
23
-
24
- const getMiddleware = input => {
25
- if (typeof input === 'function') {
26
- return input;
27
- } else if (input && typeof input.middleware === 'function') {
28
- return input.middleware;
29
- } // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
30
-
31
-
32
- throw new Error(`${input} is not a Middleware or { middleware: Middleware }`);
33
- };
34
-
35
- exports.getMiddleware = getMiddleware;
36
-
37
- const createPipeline = options => {
38
- const config = _objectSpread({}, options);
39
-
40
- const middlewares = [];
41
-
42
- const use = (...inputs) => {
43
- middlewares.push(...inputs.map(getMiddleware));
44
- return pipeline;
45
- };
46
-
47
- const createCurrentCounter = (hooks, onLast) => (0, _counter.createCounter)((index, input, next) => {
48
- if (index >= middlewares.length) {
49
- if (onLast) {
50
- return onLast(input);
51
- }
52
-
53
- throw new Error(`Expect returning a value, but all middlewares just calling next()`);
54
- }
55
-
56
- const middleware = middlewares[index];
57
- const result = (0, _context.runHooks)(() => middleware(input, next), hooks);
58
- return result;
59
- });
60
-
61
- const currentContainer = (0, _context.createContainer)(config.contexts);
62
- const currentHooks = (0, _context.fromContainer)(currentContainer);
63
- const currentCounter = createCurrentCounter(currentHooks); // eslint-disable-next-line @typescript-eslint/no-shadow
64
-
65
- const run = (input, options) => {
66
- var _options$container;
67
-
68
- const container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
69
- const hooks = container === currentContainer ? currentHooks : (0, _context.fromContainer)(container);
70
- let counter = container === currentContainer ? currentCounter : createCurrentCounter(hooks);
71
-
72
- if (options !== null && options !== void 0 && options.onLast) {
73
- counter = createCurrentCounter(hooks, options.onLast);
74
- }
75
-
76
- const result = counter.start(input);
77
- return result;
78
- };
79
-
80
- const middleware = (input, next) => {
81
- // eslint-disable-next-line react-hooks/rules-of-hooks
82
- const container = (0, _context.useContainer)();
83
- return run(input, {
84
- container,
85
- onLast: next
86
- });
87
- };
88
-
89
- const pipeline = {
90
- [PIPELINE_SYMBOL]: true,
91
- use,
92
- run,
93
- middleware
94
- };
95
- return pipeline;
96
- };
97
-
98
- exports.createPipeline = createPipeline;
99
-
100
- const usePipeline = pipeline => {
101
- const container = (0, _context.useContainer)();
102
-
103
- const runPipeline = (input, options) => pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
104
- container
105
- }));
106
-
107
- return runPipeline;
108
- };
109
-
110
- exports.usePipeline = usePipeline;
@@ -1,65 +0,0 @@
1
- /**
2
- * Copyright Lucifier129 and other contributors.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file at
6
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
7
- *
8
- */
9
- import NodeAsyncHooks from 'async_hooks';
10
- import * as asyncHooksInterface from "./asyncHooksInterface";
11
-
12
- var createAsyncHooks = function createAsyncHooks() {
13
- var store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
14
-
15
- var hooks = NodeAsyncHooks.createHook({
16
- init: function init(asyncId, _, triggerAsyncId) {
17
- if (store.has(triggerAsyncId)) {
18
- var value = store.get(triggerAsyncId);
19
- store.set(asyncId, value);
20
- }
21
- },
22
- destroy: function destroy(asyncId) {
23
- if (store.has(asyncId)) {
24
- store["delete"](asyncId);
25
- }
26
- }
27
- });
28
-
29
- var set = function set(value) {
30
- store.set(NodeAsyncHooks.executionAsyncId(), value);
31
- };
32
-
33
- var get = function get() {
34
- return store.get(NodeAsyncHooks.executionAsyncId());
35
- };
36
-
37
- var enable = function enable() {
38
- hooks.enable();
39
- };
40
-
41
- var disable = function disable() {
42
- hooks.disable();
43
- store.clear();
44
- };
45
-
46
- return {
47
- enable: enable,
48
- disable: disable,
49
- set: set,
50
- get: get
51
- };
52
- };
53
-
54
- export var enable = function enable() {
55
- var hooks = createAsyncHooks();
56
- disable();
57
- asyncHooksInterface.impl(hooks);
58
- hooks.enable();
59
- };
60
- export var disable = function disable() {
61
- var _asyncHooksInterface$;
62
-
63
- (_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
64
- asyncHooksInterface.reset();
65
- };
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright Lucifier129 and other contributors.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file at
6
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
7
- *
8
- */
9
- // eslint-disable-next-line import/no-mutable-exports
10
- export var asyncHooks;
11
- export var impl = function impl(implimentations) {
12
- asyncHooks = implimentations;
13
- };
14
- export var reset = function reset() {
15
- asyncHooks = undefined;
16
- };