@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,137 +0,0 @@
1
- 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; }
2
-
3
- /**
4
- * Copyright Lucifier129 and other contributors.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file at
8
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
9
- *
10
- */
11
- import { createHooks } from "./hook";
12
- var ContextSymbol = Symbol('Context');
13
- export var isContext = function isContext(input) {
14
- return Object.prototype.hasOwnProperty.call(input, ContextSymbol);
15
- };
16
- export var assertContext = function assertContext(input) {
17
- if (!isContext(input)) {
18
- throw new Error("Expected Context, but received ".concat(input));
19
- }
20
- };
21
- export var createContext = function createContext(value) {
22
- var id = Symbol('ContextID'); // eslint-disable-next-line @typescript-eslint/no-shadow
23
-
24
- var create = function create(value) {
25
- var _Context;
26
-
27
- var use = function use() {
28
- // eslint-disable-next-line react-hooks/rules-of-hooks
29
- var container = useContainer();
30
- return Object.seal({
31
- get value() {
32
- return container.read(Context);
33
- },
34
-
35
- set value(v) {
36
- container.write(Context, v);
37
- }
38
-
39
- });
40
- };
41
-
42
- var get = function get() {
43
- // eslint-disable-next-line react-hooks/rules-of-hooks
44
- var container = useContainer();
45
- return container.read(Context);
46
- };
47
-
48
- var set = function set(v) {
49
- // eslint-disable-next-line react-hooks/rules-of-hooks
50
- var container = useContainer();
51
- container.write(Context, v);
52
- };
53
-
54
- var assert = function assert() {
55
- // eslint-disable-next-line @typescript-eslint/no-shadow
56
- var value = get();
57
-
58
- if (value === null || value === undefined) {
59
- throw new Error( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
60
- "Expected value is not null or undefined, but got: ".concat(value));
61
- }
62
-
63
- return value;
64
- };
65
-
66
- var Context = (_Context = {
67
- id: id
68
- }, _defineProperty(_Context, ContextSymbol, value), _defineProperty(_Context, "create", create), _defineProperty(_Context, "use", use), _defineProperty(_Context, "get", get), _defineProperty(_Context, "set", set), _defineProperty(_Context, "assert", assert), _Context);
69
- return Context;
70
- };
71
-
72
- return create(value);
73
- };
74
- export var ContainerSymbol = Symbol('Container'); // eslint-disable-next-line @typescript-eslint/no-redeclare
75
-
76
- export var isContainer = function isContainer(input) {
77
- return Boolean(input === null || input === void 0 ? void 0 : input[ContainerSymbol]);
78
- };
79
- export var assertContainer = function assertContainer(input) {
80
- if (!isContainer(input)) {
81
- throw new Error("Expected Context, but received ".concat(input));
82
- }
83
- };
84
-
85
- var createContextMap = function createContextMap(storage) {
86
- var contextMap = new Map();
87
- Object.values(storage).forEach(function (context) {
88
- contextMap.set(context.id, context);
89
- });
90
- return contextMap;
91
- };
92
-
93
- export var createContainer = function createContainer() {
94
- var _Object$freeze;
95
-
96
- var ContextStorage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
97
- var contextMap = createContextMap(ContextStorage);
98
-
99
- var read = function read(context) {
100
- var target = contextMap.get(context.id);
101
-
102
- if (target) {
103
- return target[ContextSymbol];
104
- }
105
-
106
- return context[ContextSymbol];
107
- };
108
-
109
- var write = function write(context, value) {
110
- contextMap.set(context.id, context.create(value));
111
- };
112
-
113
- var container = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, ContainerSymbol, true), _defineProperty(_Object$freeze, "read", read), _defineProperty(_Object$freeze, "write", write), _Object$freeze));
114
- return container;
115
- };
116
-
117
- var _createHooks = createHooks({
118
- useContainer: function useContainer() {
119
- throw new Error("Can't call useContainer out of scope, it should be placed on top of the function");
120
- }
121
- }),
122
- run = _createHooks.run,
123
- hooks = _createHooks.hooks;
124
-
125
- export var runHooks = run;
126
- var useContainer = hooks.useContainer;
127
- export { useContainer };
128
- export var fromContainer = function fromContainer(container) {
129
- return {
130
- useContainer: function useContainer() {
131
- return container;
132
- }
133
- };
134
- };
135
- export var runWithContainer = function runWithContainer(f, container) {
136
- return runHooks(f, fromContainer(container));
137
- };
@@ -1,74 +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
- /**
8
- * Copyright Lucifier129 and other contributors.
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file at
12
- * https://github.com/farrow-js/farrow/blob/master/LICENSE
13
- *
14
- */
15
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
16
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
17
- // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
18
- export var createCounter = function createCounter(callback) {
19
- var dispatch = function dispatch(index, input) {
20
- var next = function next() {
21
- var nextInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : input;
22
- return dispatch(index + 1, nextInput);
23
- };
24
-
25
- return callback(index, input, next);
26
- };
27
-
28
- var start = function start(input) {
29
- return dispatch(0, input);
30
- };
31
-
32
- return {
33
- start: start,
34
- dispatch: dispatch
35
- };
36
- }; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
37
-
38
- export var createAsyncCounter = function createAsyncCounter(callback) {
39
- var dispatch = /*#__PURE__*/function () {
40
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(index, input) {
41
- var next;
42
- return _regeneratorRuntime.wrap(function _callee$(_context) {
43
- while (1) {
44
- switch (_context.prev = _context.next) {
45
- case 0:
46
- next = function next() {
47
- var nextInput = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : input;
48
- return dispatch(index + 1, nextInput);
49
- };
50
-
51
- return _context.abrupt("return", callback(index, input, next));
52
-
53
- case 2:
54
- case "end":
55
- return _context.stop();
56
- }
57
- }
58
- }, _callee);
59
- }));
60
-
61
- return function dispatch(_x, _x2) {
62
- return _ref.apply(this, arguments);
63
- };
64
- }();
65
-
66
- var start = function start(input) {
67
- return dispatch(0, input);
68
- };
69
-
70
- return {
71
- start: start,
72
- dispatch: dispatch
73
- };
74
- };
@@ -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
- };