@modern-js/plugin 1.0.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -4
  3. package/dist/js/modern/index.js +2 -3
  4. package/dist/js/modern/manager/async.js +1 -1
  5. package/dist/js/modern/manager/runner.js +1 -1
  6. package/dist/js/modern/manager/sync.js +1 -6
  7. package/dist/js/modern/waterfall/async.js +28 -34
  8. package/dist/js/modern/waterfall/sync.js +29 -36
  9. package/dist/js/modern/workflow/async.js +31 -30
  10. package/dist/js/modern/workflow/parallel.js +20 -29
  11. package/dist/js/modern/workflow/sync.js +20 -27
  12. package/dist/js/node/index.js +12 -25
  13. package/dist/js/node/manager/async.js +4 -4
  14. package/dist/js/node/manager/runner.js +2 -2
  15. package/dist/js/node/manager/sync.js +6 -12
  16. package/dist/js/node/waterfall/async.js +27 -34
  17. package/dist/js/node/waterfall/sync.js +29 -36
  18. package/dist/js/node/workflow/async.js +30 -30
  19. package/dist/js/node/workflow/parallel.js +19 -29
  20. package/dist/js/node/workflow/sync.js +19 -27
  21. package/dist/js/treeshaking/index.js +2 -3
  22. package/dist/js/treeshaking/manager/async.js +1 -1
  23. package/dist/js/treeshaking/manager/runner.js +1 -1
  24. package/dist/js/treeshaking/manager/sync.js +1 -6
  25. package/dist/js/treeshaking/waterfall/async.js +63 -108
  26. package/dist/js/treeshaking/waterfall/sync.js +36 -39
  27. package/dist/js/treeshaking/workflow/async.js +89 -88
  28. package/dist/js/treeshaking/workflow/parallel.js +42 -66
  29. package/dist/js/treeshaking/workflow/sync.js +50 -30
  30. package/dist/types/index.d.ts +2 -3
  31. package/dist/types/manager/runner.d.ts +1 -1
  32. package/dist/types/manager/sync.d.ts +2 -3
  33. package/dist/types/waterfall/async.d.ts +9 -5
  34. package/dist/types/waterfall/sync.d.ts +4 -4
  35. package/dist/types/workflow/async.d.ts +3 -2
  36. package/dist/types/workflow/parallel.d.ts +1 -1
  37. package/dist/types/workflow/sync.d.ts +1 -1
  38. package/node.d.ts +1 -1
  39. package/node.js +1 -1
  40. package/package.json +5 -4
  41. package/src/index.ts +2 -2
  42. package/src/manager/async.ts +1 -1
  43. package/src/manager/runner.ts +1 -1
  44. package/src/manager/sync.ts +12 -16
  45. package/src/waterfall/async.ts +34 -49
  46. package/src/waterfall/sync.ts +26 -45
  47. package/src/workflow/async.ts +29 -33
  48. package/src/workflow/parallel.ts +17 -35
  49. package/src/workflow/sync.ts +13 -35
  50. package/tests/.eslintrc.js +6 -0
  51. package/tests/async.test.ts +7 -3
  52. package/tests/fixtures/async/base/foo.ts +0 -1
  53. package/tests/fixtures/async/base/fooManager.ts +1 -1
  54. package/tests/fixtures/async/core/index.ts +1 -1
  55. package/tests/fixtures/async/dynamic/bar.ts +0 -1
  56. package/tests/fixtures/async/dynamic/foo.ts +1 -1
  57. package/tests/fixtures/sync/base/foo.ts +0 -2
  58. package/tests/fixtures/sync/base/fooManager.ts +1 -1
  59. package/tests/fixtures/sync/core/index.ts +1 -1
  60. package/tests/fixtures/sync/dynamic/bar.ts +0 -1
  61. package/tests/fixtures/sync/dynamic/foo.ts +1 -1
  62. package/tests/pipeline.test.ts +4 -15
  63. package/tests/sync.test.ts +6 -2
  64. package/tests/waterfall.test.ts +1 -2
  65. package/dist/js/modern/asyncHooksImpl.js +0 -63
  66. package/dist/js/modern/asyncHooksInterface.js +0 -16
  67. package/dist/js/modern/context.js +0 -130
  68. package/dist/js/modern/counter.js +0 -40
  69. package/dist/js/modern/hook.js +0 -47
  70. package/dist/js/modern/pipeline/async.js +0 -97
  71. package/dist/js/modern/pipeline/index.js +0 -2
  72. package/dist/js/modern/pipeline/sync.js +0 -97
  73. package/dist/js/node/asyncHooksImpl.js +0 -82
  74. package/dist/js/node/asyncHooksInterface.js +0 -30
  75. package/dist/js/node/context.js +0 -164
  76. package/dist/js/node/counter.js +0 -52
  77. package/dist/js/node/hook.js +0 -57
  78. package/dist/js/node/pipeline/async.js +0 -110
  79. package/dist/js/node/pipeline/index.js +0 -31
  80. package/dist/js/node/pipeline/sync.js +0 -110
  81. package/dist/js/treeshaking/asyncHooksImpl.js +0 -65
  82. package/dist/js/treeshaking/asyncHooksInterface.js +0 -16
  83. package/dist/js/treeshaking/context.js +0 -137
  84. package/dist/js/treeshaking/counter.js +0 -74
  85. package/dist/js/treeshaking/hook.js +0 -51
  86. package/dist/js/treeshaking/pipeline/async.js +0 -165
  87. package/dist/js/treeshaking/pipeline/index.js +0 -2
  88. package/dist/js/treeshaking/pipeline/sync.js +0 -118
  89. package/dist/types/asyncHooksImpl.d.ts +0 -10
  90. package/dist/types/asyncHooksInterface.d.ts +0 -21
  91. package/dist/types/context.d.ts +0 -47
  92. package/dist/types/counter.d.ts +0 -22
  93. package/dist/types/hook.d.ts +0 -13
  94. package/dist/types/pipeline/async.d.ts +0 -35
  95. package/dist/types/pipeline/index.d.ts +0 -2
  96. package/dist/types/pipeline/sync.d.ts +0 -37
  97. package/src/asyncHooksImpl.ts +0 -64
  98. package/src/asyncHooksInterface.ts +0 -34
  99. package/src/context.ts +0 -184
  100. package/src/counter.ts +0 -78
  101. package/src/hook.ts +0 -46
  102. package/src/pipeline/async.ts +0 -155
  103. package/src/pipeline/index.ts +0 -2
  104. package/src/pipeline/sync.ts +0 -152
  105. package/tests/context.test.ts +0 -114
  106. package/tests/counter.test.ts +0 -32
  107. package/tests/hook.test.ts +0 -113
@@ -1,51 +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 { asyncHooks } from "./asyncHooksInterface";
10
- export var createHooks = function createHooks(defaultHooks) {
11
- var currentHooks = {};
12
- var hooks = {};
13
-
14
- var _loop = function _loop(key) {
15
- // eslint-disable-next-line @typescript-eslint/no-loop-func
16
- var f = function f() {
17
- var _asyncHooks$get;
18
-
19
- // eslint-disable-next-line @typescript-eslint/no-shadow
20
- var hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
21
- var handler = hooks[key];
22
-
23
- if (typeof handler !== 'function') {
24
- handler = defaultHooks[key];
25
- }
26
-
27
- return handler.apply(void 0, arguments);
28
- };
29
-
30
- hooks[key] = f;
31
- };
32
-
33
- for (var key in defaultHooks) {
34
- _loop(key);
35
- }
36
-
37
- var run = function run(f, implementations) {
38
- try {
39
- currentHooks = implementations || defaultHooks;
40
- asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
41
- return f();
42
- } finally {
43
- currentHooks = defaultHooks;
44
- }
45
- };
46
-
47
- return {
48
- run: run,
49
- hooks: hooks
50
- };
51
- };
@@ -1,165 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
7
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
-
9
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
-
15
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
-
17
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
-
19
- 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; }
20
-
21
- 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; }
22
-
23
- 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; }
24
-
25
- /**
26
- * Copyright Lucifier129 and other contributors.
27
- *
28
- * This source code is licensed under the MIT license found in the
29
- * LICENSE file at
30
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
31
- *
32
- */
33
- import { createContainer, fromContainer, runHooks, useContainer } from "../context";
34
- import { createAsyncCounter } from "../counter";
35
- var ASYNC_PIPELINE_SYMBOL = Symbol('ASYNC_PIPELINE_SYMBOL');
36
- export var isAsyncPipeline = function isAsyncPipeline(input) {
37
- return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_PIPELINE_SYMBOL]);
38
- };
39
- export var getAsyncMiddleware = function getAsyncMiddleware(input) {
40
- if (typeof input === 'function') {
41
- return input;
42
- } else if (input && typeof input.middleware === 'function') {
43
- return input.middleware;
44
- } // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
45
-
46
-
47
- throw new Error("".concat(input, " is not a Middleware or { middleware: Middleware }"));
48
- };
49
- export var createAsyncPipeline = function createAsyncPipeline(options) {
50
- var _pipeline;
51
-
52
- var config = _objectSpread({}, options);
53
-
54
- var middlewares = [];
55
-
56
- var use = function use() {
57
- for (var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++) {
58
- inputs[_key] = arguments[_key];
59
- }
60
-
61
- middlewares.push.apply(middlewares, _toConsumableArray(inputs.map(getAsyncMiddleware)));
62
- return pipeline;
63
- };
64
-
65
- var createCurrentCounter = function createCurrentCounter(hooks, onLast) {
66
- return createAsyncCounter( /*#__PURE__*/function () {
67
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(index, input, next) {
68
- var middleware, result;
69
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
70
- while (1) {
71
- switch (_context2.prev = _context2.next) {
72
- case 0:
73
- if (!(index >= middlewares.length)) {
74
- _context2.next = 4;
75
- break;
76
- }
77
-
78
- if (!onLast) {
79
- _context2.next = 3;
80
- break;
81
- }
82
-
83
- return _context2.abrupt("return", onLast(input));
84
-
85
- case 3:
86
- throw new Error("Expect returning a value, but all middlewares just calling next()");
87
-
88
- case 4:
89
- middleware = middlewares[index];
90
- _context2.next = 7;
91
- return runHooks( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
92
- return _regeneratorRuntime.wrap(function _callee$(_context) {
93
- while (1) {
94
- switch (_context.prev = _context.next) {
95
- case 0:
96
- return _context.abrupt("return", middleware(input, next));
97
-
98
- case 1:
99
- case "end":
100
- return _context.stop();
101
- }
102
- }
103
- }, _callee);
104
- })), hooks);
105
-
106
- case 7:
107
- result = _context2.sent;
108
- return _context2.abrupt("return", result);
109
-
110
- case 9:
111
- case "end":
112
- return _context2.stop();
113
- }
114
- }
115
- }, _callee2);
116
- }));
117
-
118
- return function (_x, _x2, _x3) {
119
- return _ref.apply(this, arguments);
120
- };
121
- }());
122
- };
123
-
124
- var currentContainer = createContainer(config.contexts);
125
- var currentHooks = fromContainer(currentContainer);
126
- var currentCounter = createCurrentCounter(currentHooks); // eslint-disable-next-line @typescript-eslint/no-shadow
127
-
128
- var run = function run(input, options) {
129
- var _options$container;
130
-
131
- var container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
132
- var hooks = container === currentContainer ? currentHooks : fromContainer(container);
133
- var counter = container === currentContainer ? currentCounter : createCurrentCounter(hooks);
134
-
135
- if (options !== null && options !== void 0 && options.onLast) {
136
- counter = createCurrentCounter(hooks, options.onLast);
137
- }
138
-
139
- var result = counter.start(input);
140
- return result;
141
- };
142
-
143
- var middleware = function middleware(input, next) {
144
- // eslint-disable-next-line react-hooks/rules-of-hooks
145
- var container = useContainer();
146
- return run(input, {
147
- container: container,
148
- onLast: next
149
- });
150
- };
151
-
152
- var pipeline = (_pipeline = {}, _defineProperty(_pipeline, ASYNC_PIPELINE_SYMBOL, true), _defineProperty(_pipeline, "use", use), _defineProperty(_pipeline, "run", run), _defineProperty(_pipeline, "middleware", middleware), _pipeline);
153
- return pipeline;
154
- };
155
- export var useAsyncPipeline = function useAsyncPipeline(pipeline) {
156
- var container = useContainer();
157
-
158
- var runPipeline = function runPipeline(input, options) {
159
- return pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
160
- container: container
161
- }));
162
- };
163
-
164
- return runPipeline;
165
- };
@@ -1,2 +0,0 @@
1
- export * from "./sync";
2
- export * from "./async";
@@ -1,118 +0,0 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- 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; }
12
-
13
- 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; }
14
-
15
- 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; }
16
-
17
- 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; }
18
-
19
- /**
20
- * Copyright Lucifier129 and other contributors.
21
- *
22
- * This source code is licensed under the MIT license found in the
23
- * LICENSE file at
24
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
25
- *
26
- */
27
- import { createContainer, fromContainer, runHooks, useContainer } from "../context";
28
- import { createCounter } from "../counter";
29
- var PIPELINE_SYMBOL = Symbol('PIPELINE_SYMBOL');
30
- export var isPipeline = function isPipeline(input) {
31
- return Boolean(input === null || input === void 0 ? void 0 : input[PIPELINE_SYMBOL]);
32
- };
33
- export var getMiddleware = function getMiddleware(input) {
34
- if (typeof input === 'function') {
35
- return input;
36
- } else if (input && typeof input.middleware === 'function') {
37
- return input.middleware;
38
- } // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
39
-
40
-
41
- throw new Error("".concat(input, " is not a Middleware or { middleware: Middleware }"));
42
- };
43
- export var createPipeline = function createPipeline(options) {
44
- var _pipeline;
45
-
46
- var config = _objectSpread({}, options);
47
-
48
- var middlewares = [];
49
-
50
- var use = function use() {
51
- for (var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++) {
52
- inputs[_key] = arguments[_key];
53
- }
54
-
55
- middlewares.push.apply(middlewares, _toConsumableArray(inputs.map(getMiddleware)));
56
- return pipeline;
57
- };
58
-
59
- var createCurrentCounter = function createCurrentCounter(hooks, onLast) {
60
- return createCounter(function (index, input, next) {
61
- if (index >= middlewares.length) {
62
- if (onLast) {
63
- return onLast(input);
64
- }
65
-
66
- throw new Error("Expect returning a value, but all middlewares just calling next()");
67
- }
68
-
69
- var middleware = middlewares[index];
70
- var result = runHooks(function () {
71
- return middleware(input, next);
72
- }, hooks);
73
- return result;
74
- });
75
- };
76
-
77
- var currentContainer = createContainer(config.contexts);
78
- var currentHooks = fromContainer(currentContainer);
79
- var currentCounter = createCurrentCounter(currentHooks); // eslint-disable-next-line @typescript-eslint/no-shadow
80
-
81
- var run = function run(input, options) {
82
- var _options$container;
83
-
84
- var container = (_options$container = options === null || options === void 0 ? void 0 : options.container) !== null && _options$container !== void 0 ? _options$container : currentContainer;
85
- var hooks = container === currentContainer ? currentHooks : fromContainer(container);
86
- var counter = container === currentContainer ? currentCounter : createCurrentCounter(hooks);
87
-
88
- if (options !== null && options !== void 0 && options.onLast) {
89
- counter = createCurrentCounter(hooks, options.onLast);
90
- }
91
-
92
- var result = counter.start(input);
93
- return result;
94
- };
95
-
96
- var middleware = function middleware(input, next) {
97
- // eslint-disable-next-line react-hooks/rules-of-hooks
98
- var container = useContainer();
99
- return run(input, {
100
- container: container,
101
- onLast: next
102
- });
103
- };
104
-
105
- var pipeline = (_pipeline = {}, _defineProperty(_pipeline, PIPELINE_SYMBOL, true), _defineProperty(_pipeline, "use", use), _defineProperty(_pipeline, "run", run), _defineProperty(_pipeline, "middleware", middleware), _pipeline);
106
- return pipeline;
107
- };
108
- export var usePipeline = function usePipeline(pipeline) {
109
- var container = useContainer();
110
-
111
- var runPipeline = function runPipeline(input, options) {
112
- return pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
113
- container: container
114
- }));
115
- };
116
-
117
- return runPipeline;
118
- };
@@ -1,10 +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
- export declare const enable: () => void;
10
- export declare const disable: () => void;
@@ -1,21 +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
- export declare type AnyFn = (...args: any) => any;
10
- export declare type Hooks = {
11
- [key: string]: AnyFn;
12
- };
13
- export declare type AsyncHooks = {
14
- enable: () => void;
15
- disable: () => void;
16
- set: (value: Hooks) => void;
17
- get: () => Hooks | undefined;
18
- } | undefined;
19
- export declare let asyncHooks: AsyncHooks;
20
- export declare const impl: (implimentations: AsyncHooks) => void;
21
- export declare const reset: () => void;
@@ -1,47 +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
- declare const ContextSymbol: unique symbol;
10
- export declare type Context<T = any> = {
11
- id: symbol;
12
- [ContextSymbol]: T;
13
- create: (value: T) => Context<T>;
14
- use: () => {
15
- value: T;
16
- };
17
- get: () => T;
18
- set: (value: T) => void;
19
- assert: () => Exclude<T, undefined | null>;
20
- };
21
- export declare const isContext: (input: any) => input is Context<any>;
22
- declare type AssertContext = (input: any) => asserts input is Context;
23
- export declare const assertContext: AssertContext;
24
- export declare const createContext: <T>(value: T) => Context<T>;
25
- export declare type ContextStorage = {
26
- [key: string]: Context;
27
- };
28
- export declare const ContainerSymbol: unique symbol;
29
- export declare type ContextSymbol = typeof ContainerSymbol;
30
- export declare const isContainer: (input: any) => input is Container;
31
- declare type AssertContainer = (input: any) => asserts input is Container;
32
- export declare const assertContainer: AssertContainer;
33
- export declare type Container = {
34
- [ContainerSymbol]: true;
35
- read: <V>(Context: Context<V>) => V;
36
- write: <V>(Context: Context<V>, value: V) => void;
37
- };
38
- export declare const createContainer: (ContextStorage?: ContextStorage) => Container;
39
- export declare type ValueFromContext<C extends Context> = C extends Context<infer V> ? V : never;
40
- export declare type Hooks = {
41
- useContainer: () => Container;
42
- };
43
- export declare const runHooks: <F extends import("./asyncHooksInterface").AnyFn>(f: F, implementations?: Hooks | undefined) => ReturnType<F>;
44
- export declare const useContainer: () => Container;
45
- export declare const fromContainer: (container: Container) => Hooks;
46
- export declare const runWithContainer: <F extends (...args: any) => any>(f: F, container: Container) => ReturnType<F>;
47
- export {};
@@ -1,22 +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
- export declare type Next<I = unknown, O = void> = (input?: I) => O;
10
- export declare type CounterCallback<I = unknown, O = void> = (index: number, input: I, next: Next<I, O>) => O;
11
- export declare type Counter<I = unknown, O = void> = {
12
- start: (input: I) => O;
13
- dispatch: (index: number, input: I) => O;
14
- };
15
- export declare const createCounter: <I, O>(callback: CounterCallback<I, O>) => Counter<I, O>;
16
- export declare type AsyncNext<I = unknown, O = void> = (input: I) => Promise<O>;
17
- export declare type AsyncCounterCallback<I = unknown, O = void> = (index: number, input: I, next: AsyncNext<I, O>) => Promise<O>;
18
- export declare type AsyncCounter<I = unknown, O = void> = {
19
- start: (input: I) => Promise<O>;
20
- dispatch: (index: number, input: I) => Promise<O>;
21
- };
22
- export declare const createAsyncCounter: <I, O>(callback: AsyncCounterCallback<I, O>) => AsyncCounter<I, O>;
@@ -1,13 +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 { Hooks, AnyFn } from './asyncHooksInterface';
10
- export declare const createHooks: <HS extends Hooks>(defaultHooks: HS) => {
11
- run: <F extends AnyFn>(f: F, implementations?: HS | undefined) => ReturnType<F>;
12
- hooks: HS;
13
- };
@@ -1,35 +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 { Container } from '../context';
10
- import { AsyncNext } from '../counter';
11
- import type { PipelineOptions } from './sync';
12
- export declare type AsyncMiddleware<I = unknown, O = unknown> = (input: I, next: AsyncNext<I, O>) => O | Promise<O>;
13
- export declare type AsyncMiddlewares<I = unknown, O = unknown> = AsyncMiddleware<I, O>[];
14
- declare const ASYNC_PIPELINE_SYMBOL: unique symbol;
15
- export declare const isAsyncPipeline: (input: any) => input is AsyncPipeline<unknown, unknown>;
16
- export declare type RunAsyncPipelineOptions<I = unknown, O = unknown> = {
17
- container?: Container;
18
- onLast?: (input: I) => O | Promise<O>;
19
- };
20
- export declare type AsyncMiddlewareInput<I = unknown, O = unknown> = AsyncMiddleware<I, O> | {
21
- middleware: AsyncMiddleware<I, O>;
22
- };
23
- export declare type AsyncMiddlewareType<T extends AsyncMiddlewareInput> = T extends AsyncMiddlewareInput<infer I, infer O> ? AsyncMiddleware<I, O> : never;
24
- export declare const getAsyncMiddleware: <I, O>(input: AsyncMiddlewareInput<I, O>) => AsyncMiddleware<I, O>;
25
- export declare type AsyncPipeline<I = unknown, O = unknown> = {
26
- [ASYNC_PIPELINE_SYMBOL]: true;
27
- use: (...inputs: AsyncMiddlewareInput<I, O>[]) => AsyncPipeline<I, O>;
28
- run: (input: I, options?: RunAsyncPipelineOptions<I, O>) => Promise<O>;
29
- middleware: AsyncMiddleware<I, O>;
30
- };
31
- export declare const createAsyncPipeline: <I, O>(options?: PipelineOptions | undefined) => AsyncPipeline<I, O>;
32
- export declare type AsyncPipelineInput<T extends AsyncPipeline> = T extends AsyncPipeline<infer I> ? I : never;
33
- export declare type AsyncPipelineOutput<T extends AsyncPipeline> = T extends AsyncPipeline<any, infer O> ? O : never;
34
- export declare const useAsyncPipeline: <I, O>(pipeline: AsyncPipeline<I, O>) => (input: I, options?: RunAsyncPipelineOptions<I, O> | undefined) => Promise<O>;
35
- export {};
@@ -1,2 +0,0 @@
1
- export * from './sync';
2
- export * from './async';
@@ -1,37 +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 { ContextStorage, Container } from '../context';
10
- import { Next } from '../counter';
11
- export declare type Middleware<I = unknown, O = unknown> = (input: I, next: Next<I, O>) => O;
12
- export declare type Middlewares<I = unknown, O = unknown> = Middleware<I, O>[];
13
- declare const PIPELINE_SYMBOL: unique symbol;
14
- export declare const isPipeline: (input: any) => input is Pipeline<unknown, unknown>;
15
- export declare type PipelineOptions = {
16
- contexts?: ContextStorage;
17
- };
18
- export declare type RunPipelineOptions<I = unknown, O = unknown> = {
19
- container?: Container;
20
- onLast?: (input: I) => O;
21
- };
22
- export declare type MiddlewareInput<I = unknown, O = unknown> = Middleware<I, O> | {
23
- middleware: Middleware<I, O>;
24
- };
25
- export declare type MiddlewareType<T extends MiddlewareInput> = T extends MiddlewareInput<infer I, infer O> ? Middleware<I, O> : never;
26
- export declare const getMiddleware: <I, O>(input: MiddlewareInput<I, O>) => Middleware<I, O>;
27
- export declare type Pipeline<I = unknown, O = unknown> = {
28
- [PIPELINE_SYMBOL]: true;
29
- use: (...inputs: MiddlewareInput<I, O>[]) => Pipeline<I, O>;
30
- run: (input: I, options?: RunPipelineOptions<I, O>) => O;
31
- middleware: Middleware<I, O>;
32
- };
33
- export declare const createPipeline: <I, O>(options?: PipelineOptions | undefined) => Pipeline<I, O>;
34
- export declare type PipelineInput<T extends Pipeline> = T extends Pipeline<infer I> ? I : never;
35
- export declare type PipelineOutput<T extends Pipeline> = T extends Pipeline<any, infer O> ? O : never;
36
- export declare const usePipeline: <I, O>(pipeline: Pipeline<I, O>) => (input: I, options?: RunPipelineOptions<I, O> | undefined) => O;
37
- export {};
@@ -1,64 +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
-
10
- import NodeAsyncHooks from 'async_hooks';
11
- import * as asyncHooksInterface from './asyncHooksInterface';
12
-
13
- const createAsyncHooks = <T>() => {
14
- const store = new Map<number, T>();
15
-
16
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
17
- const hooks = NodeAsyncHooks.createHook({
18
- init: (asyncId, _, triggerAsyncId) => {
19
- if (store.has(triggerAsyncId)) {
20
- const value = store.get(triggerAsyncId)!;
21
- store.set(asyncId, value);
22
- }
23
- },
24
- destroy: asyncId => {
25
- if (store.has(asyncId)) {
26
- store.delete(asyncId);
27
- }
28
- },
29
- });
30
-
31
- const set = (value: T) => {
32
- store.set(NodeAsyncHooks.executionAsyncId(), value);
33
- };
34
-
35
- const get = () => store.get(NodeAsyncHooks.executionAsyncId());
36
-
37
- const enable = () => {
38
- hooks.enable();
39
- };
40
-
41
- const disable = () => {
42
- hooks.disable();
43
- store.clear();
44
- };
45
-
46
- return {
47
- enable,
48
- disable,
49
- set,
50
- get,
51
- };
52
- };
53
-
54
- export const enable = () => {
55
- const hooks = createAsyncHooks<asyncHooksInterface.Hooks>();
56
- disable();
57
- asyncHooksInterface.impl(hooks);
58
- hooks.enable();
59
- };
60
-
61
- export const disable = () => {
62
- asyncHooksInterface.asyncHooks?.disable();
63
- asyncHooksInterface.reset();
64
- };
@@ -1,34 +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
-
10
- export type AnyFn = (...args: any) => any;
11
-
12
- export type Hooks = {
13
- [key: string]: AnyFn;
14
- };
15
-
16
- export type AsyncHooks =
17
- | {
18
- enable: () => void;
19
- disable: () => void;
20
- set: (value: Hooks) => void;
21
- get: () => Hooks | undefined;
22
- }
23
- | undefined;
24
-
25
- // eslint-disable-next-line import/no-mutable-exports
26
- export let asyncHooks: AsyncHooks;
27
-
28
- export const impl = (implimentations: AsyncHooks) => {
29
- asyncHooks = implimentations;
30
- };
31
-
32
- export const reset = () => {
33
- asyncHooks = undefined;
34
- };