@modern-js/plugin 1.1.2 → 1.3.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.
- package/CHANGELOG.md +22 -0
- package/dist/js/modern/manager/async.js +53 -26
- package/dist/js/modern/manager/index.js +2 -1
- package/dist/js/modern/manager/sync.js +73 -58
- package/dist/js/modern/manager/types.js +0 -0
- package/dist/js/modern/waterfall/async.js +6 -7
- package/dist/js/modern/waterfall/sync.js +2 -3
- package/dist/js/modern/workflow/async.js +3 -4
- package/dist/js/modern/workflow/parallel.js +2 -2
- package/dist/js/modern/workflow/sync.js +2 -3
- package/dist/js/node/manager/async.js +51 -23
- package/dist/js/node/manager/index.js +13 -0
- package/dist/js/node/manager/sync.js +78 -56
- package/dist/js/node/manager/types.js +0 -0
- package/dist/js/node/waterfall/async.js +6 -7
- package/dist/js/node/waterfall/sync.js +2 -3
- package/dist/js/node/workflow/async.js +3 -4
- package/dist/js/node/workflow/parallel.js +2 -2
- package/dist/js/node/workflow/sync.js +2 -3
- package/dist/js/treeshaking/manager/async.js +57 -32
- package/dist/js/treeshaking/manager/index.js +2 -1
- package/dist/js/treeshaking/manager/sync.js +79 -60
- package/dist/js/treeshaking/manager/types.js +0 -0
- package/dist/js/treeshaking/waterfall/async.js +6 -7
- package/dist/js/treeshaking/waterfall/sync.js +2 -3
- package/dist/js/treeshaking/workflow/async.js +4 -5
- package/dist/js/treeshaking/workflow/parallel.js +2 -2
- package/dist/js/treeshaking/workflow/sync.js +2 -3
- package/dist/types/manager/async.d.ts +60 -21
- package/dist/types/manager/index.d.ts +2 -1
- package/dist/types/manager/sync.d.ts +74 -43
- package/dist/types/manager/types.d.ts +41 -0
- package/dist/types/waterfall/async.d.ts +2 -2
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/package.json +10 -5
- package/tests/async.test.ts +132 -14
- package/tests/fixtures/async/core/index.ts +12 -4
- package/tests/fixtures/async/dynamic/foo.ts +2 -2
- package/tests/fixtures/sync/core/index.ts +9 -4
- package/tests/fixtures/sync/dynamic/foo.ts +2 -2
- package/tests/pipeline.test.ts +2 -2
- package/tests/sync.test.ts +126 -13
- package/tests/tsconfig.json +1 -3
- package/tests/waterfall.test.ts +2 -2
- package/tests/workflow.test.ts +2 -2
- package/tsconfig.json +1 -3
- package/src/index.ts +0 -5
- package/src/manager/async.ts +0 -248
- package/src/manager/index.ts +0 -3
- package/src/manager/runner.ts +0 -15
- package/src/manager/sync.ts +0 -458
- package/src/waterfall/async.ts +0 -109
- package/src/waterfall/index.ts +0 -2
- package/src/waterfall/sync.ts +0 -110
- package/src/workflow/async.ts +0 -96
- package/src/workflow/index.ts +0 -3
- package/src/workflow/parallel.ts +0 -97
- package/src/workflow/sync.ts +0 -82
@@ -1,3 +1,5 @@
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
|
+
|
1
3
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
2
4
|
|
3
5
|
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."); }
|
@@ -12,53 +14,52 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
12
14
|
|
13
15
|
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; }
|
14
16
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
17
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
16
18
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
18
20
|
|
19
21
|
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; }
|
20
22
|
|
21
|
-
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
22
|
-
|
23
|
-
/* eslint-disable max-lines */
|
24
23
|
import { isPipeline, createPipeline, runWithContainer, createContainer } from 'farrow-pipeline';
|
25
24
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
26
25
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
27
|
-
import { RunnerContext, useRunner } from "./runner";
|
28
|
-
|
26
|
+
import { RunnerContext, useRunner } from "./runner";
|
29
27
|
var SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
30
28
|
export var DEFAULT_OPTIONS = {
|
31
29
|
name: 'untitled',
|
32
30
|
pre: [],
|
33
31
|
post: [],
|
34
32
|
rivals: [],
|
35
|
-
required: []
|
33
|
+
required: [],
|
34
|
+
usePlugins: [],
|
35
|
+
registerHook: {}
|
36
36
|
};
|
37
|
-
export var createManager = function createManager(
|
37
|
+
export var createManager = function createManager(hooks, api) {
|
38
38
|
var index = 0;
|
39
39
|
|
40
|
-
var
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}, options), {}, {
|
45
|
-
SYNC_PLUGIN_SYMBOL: SYNC_PLUGIN_SYMBOL,
|
46
|
-
initializer: initializer
|
47
|
-
});
|
40
|
+
var currentHooks = _objectSpread({}, hooks);
|
41
|
+
|
42
|
+
var registerHook = function registerHook(extraHooks) {
|
43
|
+
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
48
44
|
};
|
49
45
|
|
50
46
|
var isPlugin = function isPlugin(input) {
|
51
|
-
return hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
47
|
+
return isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
52
48
|
};
|
53
49
|
|
54
|
-
var
|
55
|
-
|
56
|
-
|
57
|
-
};
|
50
|
+
var pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
51
|
+
useHookRunners: useRunner
|
52
|
+
});
|
58
53
|
|
59
|
-
var clone = function clone() {
|
54
|
+
var clone = function clone(overrideAPI) {
|
60
55
|
var plugins = [];
|
61
56
|
|
57
|
+
var addPlugin = function addPlugin(plugin) {
|
58
|
+
if (!includePlugin(plugins, plugin)) {
|
59
|
+
plugins.push(_objectSpread({}, plugin));
|
60
|
+
}
|
61
|
+
};
|
62
|
+
|
62
63
|
var usePlugin = function usePlugin() {
|
63
64
|
for (var _len = arguments.length, input = new Array(_len), _key = 0; _key < _len; _key++) {
|
64
65
|
input[_key] = arguments[_key];
|
@@ -68,11 +69,11 @@ export var createManager = function createManager(processes) {
|
|
68
69
|
var plugin = _input[_i];
|
69
70
|
|
70
71
|
if (isPlugin(plugin)) {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
addPlugin(plugin);
|
73
|
+
} else if (typeof plugin === 'function') {
|
74
|
+
var _options = plugin();
|
75
|
+
|
76
|
+
addPlugin(createPlugin(_options.setup, _options));
|
76
77
|
} else {
|
77
78
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
78
79
|
// @ts-expect-error
|
@@ -80,17 +81,31 @@ export var createManager = function createManager(processes) {
|
|
80
81
|
}
|
81
82
|
}
|
82
83
|
|
83
|
-
return
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
84
|
+
return manager;
|
85
|
+
};
|
86
|
+
|
87
|
+
var createPlugin = function createPlugin() {
|
88
|
+
var _options$usePlugins;
|
89
|
+
|
90
|
+
var setup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
91
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
92
|
+
|
93
|
+
if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
|
94
|
+
options.usePlugins.forEach(function (plugin) {
|
95
|
+
usePlugin(createPlugin(plugin.setup, plugin));
|
96
|
+
});
|
97
|
+
}
|
98
|
+
|
99
|
+
if (options.registerHook) {
|
100
|
+
registerHook(options.registerHook);
|
101
|
+
}
|
102
|
+
|
103
|
+
return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
|
104
|
+
name: "No.".concat(index++, " plugin")
|
105
|
+
}, options), {}, {
|
106
|
+
SYNC_PLUGIN_SYMBOL: SYNC_PLUGIN_SYMBOL,
|
107
|
+
setup: setup
|
108
|
+
});
|
94
109
|
};
|
95
110
|
|
96
111
|
var clear = function clear() {
|
@@ -102,13 +117,16 @@ export var createManager = function createManager(processes) {
|
|
102
117
|
var init = function init(options) {
|
103
118
|
var container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
104
119
|
var sortedPlugins = sortPlugins(plugins);
|
120
|
+
|
121
|
+
var mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
122
|
+
|
105
123
|
checkPlugins(sortedPlugins);
|
106
124
|
var hooksList = sortedPlugins.map(function (plugin) {
|
107
125
|
return runWithContainer(function () {
|
108
|
-
return plugin.
|
126
|
+
return plugin.setup(mergedPluginAPI);
|
109
127
|
}, container);
|
110
128
|
});
|
111
|
-
return generateRunner(hooksList, container,
|
129
|
+
return generateRunner(hooksList, container, currentHooks);
|
112
130
|
};
|
113
131
|
|
114
132
|
var run = function run(cb, options) {
|
@@ -116,26 +134,27 @@ export var createManager = function createManager(processes) {
|
|
116
134
|
return runWithContainer(cb, container);
|
117
135
|
};
|
118
136
|
|
119
|
-
|
137
|
+
var manager = {
|
120
138
|
createPlugin: createPlugin,
|
121
139
|
isPlugin: isPlugin,
|
122
140
|
usePlugin: usePlugin,
|
123
141
|
init: init,
|
124
142
|
clear: clear,
|
125
143
|
run: run,
|
126
|
-
|
144
|
+
registerHook: registerHook,
|
127
145
|
useRunner: useRunner,
|
128
146
|
clone: clone
|
129
147
|
};
|
148
|
+
return manager;
|
130
149
|
};
|
131
150
|
|
132
151
|
return clone();
|
133
152
|
};
|
134
|
-
export var generateRunner = function generateRunner(hooksList, container,
|
153
|
+
export var generateRunner = function generateRunner(hooksList, container, hooksMap) {
|
135
154
|
var runner = {};
|
136
|
-
var cloneShape =
|
155
|
+
var cloneShape = closeHooksMap(hooksMap);
|
137
156
|
|
138
|
-
if (
|
157
|
+
if (hooksMap) {
|
139
158
|
var _loop = function _loop(key) {
|
140
159
|
var _iterator = _createForOfIteratorHelper(hooksList),
|
141
160
|
_step;
|
@@ -149,8 +168,6 @@ export var generateRunner = function generateRunner(hooksList, container, proces
|
|
149
168
|
}
|
150
169
|
|
151
170
|
if (hooks[key]) {
|
152
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
153
|
-
// @ts-expect-error
|
154
171
|
cloneShape[key].use(hooks[key]);
|
155
172
|
}
|
156
173
|
} // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
@@ -177,36 +194,35 @@ export var generateRunner = function generateRunner(hooksList, container, proces
|
|
177
194
|
container.write(RunnerContext, runner);
|
178
195
|
return runner;
|
179
196
|
};
|
180
|
-
export var
|
181
|
-
if (isWaterfall(
|
197
|
+
export var cloneHook = function cloneHook(hook) {
|
198
|
+
if (isWaterfall(hook)) {
|
182
199
|
return createWaterfall();
|
183
200
|
}
|
184
201
|
|
185
|
-
if (isAsyncWaterfall(
|
202
|
+
if (isAsyncWaterfall(hook)) {
|
186
203
|
return createAsyncWaterfall();
|
187
204
|
}
|
188
205
|
|
189
|
-
if (isWorkflow(
|
206
|
+
if (isWorkflow(hook)) {
|
190
207
|
return createWorkflow();
|
191
208
|
}
|
192
209
|
|
193
|
-
if (isAsyncWorkflow(
|
210
|
+
if (isAsyncWorkflow(hook)) {
|
194
211
|
return createAsyncWorkflow();
|
195
212
|
}
|
196
213
|
|
197
|
-
if (isParallelWorkflow(
|
214
|
+
if (isParallelWorkflow(hook)) {
|
198
215
|
return createParallelWorkflow();
|
199
216
|
}
|
200
217
|
|
201
|
-
if (isPipeline(
|
218
|
+
if (isPipeline(hook)) {
|
202
219
|
return createPipeline();
|
203
220
|
} // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
204
221
|
|
205
222
|
|
206
|
-
throw new Error("Unknown
|
207
|
-
};
|
208
|
-
|
209
|
-
export var cloneProgressRecord = function cloneProgressRecord(record) {
|
223
|
+
throw new Error("Unknown hook: ".concat(hook));
|
224
|
+
};
|
225
|
+
export var closeHooksMap = function closeHooksMap(record) {
|
210
226
|
if (!record) {
|
211
227
|
return record;
|
212
228
|
}
|
@@ -216,7 +232,7 @@ export var cloneProgressRecord = function cloneProgressRecord(record) {
|
|
216
232
|
for (var key in record) {
|
217
233
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
218
234
|
// @ts-expect-error
|
219
|
-
result[key] =
|
235
|
+
result[key] = cloneHook(record[key]);
|
220
236
|
}
|
221
237
|
|
222
238
|
return result;
|
@@ -359,6 +375,9 @@ var checkPlugins = function checkPlugins(plugins) {
|
|
359
375
|
}
|
360
376
|
};
|
361
377
|
|
378
|
+
export var isObject = function isObject(obj) {
|
379
|
+
return obj !== null && _typeof(obj) === 'object';
|
380
|
+
};
|
362
381
|
export var hasOwnProperty = function hasOwnProperty(obj, prop) {
|
363
382
|
return obj.hasOwnProperty(prop);
|
364
383
|
};
|
File without changes
|
@@ -4,9 +4,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
4
4
|
|
5
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
6
|
|
7
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
8
8
|
|
9
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
10
10
|
|
11
11
|
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; }
|
12
12
|
|
@@ -27,14 +27,13 @@ var ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
|
|
27
27
|
export var getAsyncBrook = function getAsyncBrook(input) {
|
28
28
|
if (typeof input === 'function') {
|
29
29
|
return input;
|
30
|
-
} else if (input && typeof input.
|
31
|
-
return input.
|
30
|
+
} else if (input && typeof input.middleware === 'function') {
|
31
|
+
return input.middleware;
|
32
32
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
33
33
|
|
34
34
|
|
35
35
|
throw new Error("".concat(input, " is not a AsyncBrook or { brook: AsyncBrook }"));
|
36
36
|
};
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
38
37
|
export var createAsyncWaterfall = function createAsyncWaterfall() {
|
39
38
|
var pipeline = createAsyncPipeline();
|
40
39
|
|
@@ -57,7 +56,7 @@ export var createAsyncWaterfall = function createAsyncWaterfall() {
|
|
57
56
|
);
|
58
57
|
};
|
59
58
|
|
60
|
-
var
|
59
|
+
var middleware = function middleware(input) {
|
61
60
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
62
61
|
var container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
63
62
|
|
@@ -72,7 +71,7 @@ export var createAsyncWaterfall = function createAsyncWaterfall() {
|
|
72
71
|
var waterfall = _objectSpread(_objectSpread({}, pipeline), {}, _defineProperty({
|
73
72
|
use: use,
|
74
73
|
run: run,
|
75
|
-
|
74
|
+
middleware: middleware
|
76
75
|
}, ASYNC_WATERFALL_SYMBOL, true));
|
77
76
|
|
78
77
|
return waterfall;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
2
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
4
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
6
|
|
@@ -28,7 +28,6 @@ export var getBrook = function getBrook(input) {
|
|
28
28
|
|
29
29
|
throw new Error("".concat(input, " is not a Brook or { brook: Brook }"));
|
30
30
|
};
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
32
31
|
export var createWaterfall = function createWaterfall() {
|
33
32
|
var pipeline = createPipeline();
|
34
33
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2
2
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
4
4
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
6
6
|
|
7
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
8
8
|
|
9
9
|
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; }
|
10
10
|
|
@@ -28,8 +28,7 @@ import { createAsyncPipeline } from 'farrow-pipeline';
|
|
28
28
|
var ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
|
29
29
|
export var isAsyncWorkflow = function isAsyncWorkflow(input) {
|
30
30
|
return Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
31
|
-
};
|
32
|
-
|
31
|
+
};
|
33
32
|
export var createAsyncWorkflow = function createAsyncWorkflow() {
|
34
33
|
var pipeline = createAsyncPipeline();
|
35
34
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
2
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4
4
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6
6
|
|
7
7
|
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; }
|
8
8
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
2
2
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4
4
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6
6
|
|
7
7
|
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; }
|
8
8
|
|
@@ -24,7 +24,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
24
24
|
|
25
25
|
import { createPipeline } from 'farrow-pipeline';
|
26
26
|
var WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
28
27
|
export var createWorkflow = function createWorkflow() {
|
29
28
|
var pipeline = createPipeline();
|
30
29
|
|
@@ -1,27 +1,66 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import type { ToRunners, ToThreads, CommonAPI, InitOptions, PluginOptions } from './types';
|
2
|
+
/** Setup function of async plugin. */
|
3
|
+
|
4
|
+
export declare type AsyncSetup<Hooks, API = Record<string, never>> = (api: API & CommonAPI<Hooks>) => Partial<ToThreads<Hooks>> | Promise<Partial<ToThreads<Hooks>> | void> | void;
|
3
5
|
declare const ASYNC_PLUGIN_SYMBOL = "ASYNC_PLUGIN_SYMBOL";
|
4
|
-
export declare type AsyncPlugin<
|
5
|
-
initializer: AsyncInitializer<O>;
|
6
|
+
export declare type AsyncPlugin<Hooks, API> = {
|
6
7
|
ASYNC_PLUGIN_SYMBOL: typeof ASYNC_PLUGIN_SYMBOL;
|
7
|
-
} & Required<PluginOptions
|
8
|
-
export declare type
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
} & Required<PluginOptions<Hooks, AsyncSetup<Hooks, API>>>;
|
9
|
+
export declare type PluginFromAsyncManager<M extends AsyncManager<any, any>> = M extends AsyncManager<infer Hooks, infer API> ? AsyncPlugin<Hooks, API> : never;
|
10
|
+
export declare type AsyncManager<Hooks, API> = {
|
11
|
+
/**
|
12
|
+
* Create a sync plugin.
|
13
|
+
* @param setup the setup function.
|
14
|
+
* @param options optional plugin options.
|
15
|
+
*/
|
16
|
+
createPlugin: (setup?: AsyncSetup<Hooks, API>, options?: PluginOptions<Hooks, AsyncSetup<Hooks, API>>) => AsyncPlugin<Hooks, API>;
|
17
|
+
/**
|
18
|
+
* Determine if a value is a async plugin.
|
19
|
+
* @param input
|
20
|
+
*/
|
21
|
+
|
22
|
+
isPlugin: (input: unknown) => input is AsyncPlugin<Hooks, API>;
|
23
|
+
/**
|
24
|
+
* Register new plugins to current manager.
|
25
|
+
* @param plugins one or more plugin.
|
26
|
+
*/
|
27
|
+
|
28
|
+
usePlugin: (...plugins: AsyncPlugin<Hooks, API>[] | Array<() => PluginOptions<Hooks, AsyncSetup<Hooks, API>>>) => AsyncManager<Hooks, API>;
|
29
|
+
/**
|
30
|
+
* Init manager, it will call the setup function of all registered plugins.
|
31
|
+
* @param options passing a custom container.
|
32
|
+
*/
|
33
|
+
|
34
|
+
init: (options?: InitOptions) => Promise<ToRunners<Hooks>>;
|
35
|
+
/**
|
36
|
+
* Run callback function with current container.
|
37
|
+
* @param callback
|
38
|
+
* @param options passing a custom container.
|
39
|
+
*/
|
40
|
+
|
20
41
|
run: <O>(cb: () => O, options?: InitOptions) => O;
|
21
|
-
|
22
|
-
|
42
|
+
/**
|
43
|
+
* Register new hooks.
|
44
|
+
* @param newHooks
|
45
|
+
*/
|
46
|
+
|
47
|
+
registerHook: (newHooks: Partial<Hooks>) => void;
|
48
|
+
/**
|
49
|
+
* Return a cloned manager.
|
50
|
+
* @param overrideAPI override the default plugin API.
|
51
|
+
*/
|
52
|
+
|
53
|
+
clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => AsyncManager<Hooks, API>;
|
54
|
+
/**
|
55
|
+
* Clear all registered plugins.
|
56
|
+
*/
|
57
|
+
|
23
58
|
clear: () => void;
|
24
|
-
|
59
|
+
/**
|
60
|
+
* Get all runner functions of the hooks.
|
61
|
+
*/
|
62
|
+
|
63
|
+
useRunner: () => ToRunners<Hooks>;
|
25
64
|
};
|
26
|
-
export declare const createAsyncManager: <
|
65
|
+
export declare const createAsyncManager: <Hooks extends Record<string, any>, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => AsyncManager<Hooks, API>;
|
27
66
|
export {};
|
@@ -1,50 +1,81 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
1
|
+
import { Container } from 'farrow-pipeline';
|
2
|
+
import type { Hook, CommonAPI, ToRunners, ToThreads, InitOptions, PluginOptions } from './types';
|
3
|
+
/** Setup function of sync plugin. */
|
4
|
+
|
5
|
+
export declare type Setup<Hooks, API = Record<string, never>> = (api: API) => Partial<ToThreads<Hooks>> | void;
|
5
6
|
declare const SYNC_PLUGIN_SYMBOL = "SYNC_PLUGIN_SYMBOL";
|
6
|
-
export declare type Plugin<
|
7
|
-
initializer: Initializer<O>;
|
7
|
+
export declare type Plugin<Hooks, API> = {
|
8
8
|
SYNC_PLUGIN_SYMBOL: typeof SYNC_PLUGIN_SYMBOL;
|
9
|
-
} & Required<PluginOptions
|
10
|
-
export declare type
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
9
|
+
} & Required<PluginOptions<Hooks, Setup<Hooks, API>>>;
|
10
|
+
export declare type PluginFromManager<M extends Manager<any, any>> = M extends Manager<infer Hooks, infer API> ? Plugin<Hooks, API> : never;
|
11
|
+
export declare type Manager<Hooks, API> = {
|
12
|
+
/**
|
13
|
+
* Create a sync plugin.
|
14
|
+
* @param setup the setup function.
|
15
|
+
* @param options optional plugin options.
|
16
|
+
*/
|
17
|
+
createPlugin: (setup?: Setup<Hooks, API>, options?: PluginOptions<Hooks, Setup<Hooks, API>>) => Plugin<Hooks, API>;
|
18
|
+
/**
|
19
|
+
* Determine if a value is a sync plugin.
|
20
|
+
* @param input
|
21
|
+
*/
|
22
|
+
|
23
|
+
isPlugin: (input: unknown) => input is Plugin<Hooks, API>;
|
24
|
+
/**
|
25
|
+
* Register new plugins to current manager.
|
26
|
+
* @param plugins one or more plugin.
|
27
|
+
*/
|
28
|
+
|
29
|
+
usePlugin: (...plugins: Plugin<Hooks, API>[] | Array<() => PluginOptions<Hooks, Setup<Hooks, API>>>) => Manager<Hooks, API>;
|
30
|
+
/**
|
31
|
+
* Init manager, it will call the setup function of all registered plugins.
|
32
|
+
* @param options passing a custom container.
|
33
|
+
*/
|
34
|
+
|
35
|
+
init: (options?: InitOptions) => ToRunners<Hooks>;
|
36
|
+
/**
|
37
|
+
* Run callback function with current container.
|
38
|
+
* @param callback
|
39
|
+
* @param options passing a custom container.
|
40
|
+
*/
|
41
|
+
|
38
42
|
run: <O>(cb: () => O, options?: InitOptions) => O;
|
39
|
-
|
43
|
+
/**
|
44
|
+
* Register new hooks.
|
45
|
+
* @param newHooks
|
46
|
+
*/
|
47
|
+
|
48
|
+
registerHook: (hewHooks: Partial<Hooks>) => void;
|
49
|
+
/**
|
50
|
+
* Clear all registered plugins.
|
51
|
+
*/
|
52
|
+
|
40
53
|
clear: () => void;
|
41
|
-
|
42
|
-
|
54
|
+
/**
|
55
|
+
* Return a cloned manager.
|
56
|
+
* @param overrideAPI override the default plugin API.
|
57
|
+
*/
|
58
|
+
|
59
|
+
clone: (overrideAPI?: Partial<API & CommonAPI<Hooks>>) => Manager<Hooks, API>;
|
60
|
+
/**
|
61
|
+
* Get all runner functions of the hooks.
|
62
|
+
*/
|
63
|
+
|
64
|
+
useRunner: () => ToRunners<Hooks>;
|
65
|
+
};
|
66
|
+
export declare const DEFAULT_OPTIONS: {
|
67
|
+
name: string;
|
68
|
+
pre: never[];
|
69
|
+
post: never[];
|
70
|
+
rivals: never[];
|
71
|
+
required: never[];
|
72
|
+
usePlugins: never[];
|
73
|
+
registerHook: {};
|
43
74
|
};
|
44
|
-
export declare const
|
45
|
-
export declare const
|
46
|
-
export declare const
|
47
|
-
export declare const
|
48
|
-
export declare const
|
75
|
+
export declare const createManager: <Hooks, API extends Record<string, any> = Record<string, never>>(hooks?: Partial<Hooks> | undefined, api?: API | undefined) => Manager<Hooks, API>;
|
76
|
+
export declare const generateRunner: <Hooks extends Record<string, any>>(hooksList: (void | Partial<ToThreads<Hooks>>)[], container: Container, hooksMap?: Hooks | undefined) => ToRunners<Hooks>;
|
77
|
+
export declare const cloneHook: (hook: Hook) => Hook;
|
78
|
+
export declare const closeHooksMap: <Hooks>(record: Hooks) => Hooks;
|
79
|
+
export declare const isObject: (obj: unknown) => obj is Record<string, any>;
|
49
80
|
export declare const hasOwnProperty: <X extends Record<string, unknown>, Y extends PropertyKey>(obj: X, prop: Y) => obj is X & Record<Y, unknown>;
|
50
81
|
export {};
|