@modern-js/plugin 1.21.2-beta.1 → 1.21.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 (70) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/js/modern/farrow-pipeline/context.js +38 -0
  3. package/dist/js/modern/farrow-pipeline/counter.js +18 -0
  4. package/dist/js/modern/farrow-pipeline/index.js +5 -0
  5. package/dist/js/modern/farrow-pipeline/pipeline.js +76 -0
  6. package/dist/js/modern/index.js +4 -0
  7. package/dist/js/modern/manager/async.js +112 -0
  8. package/dist/js/modern/manager/index.js +3 -0
  9. package/dist/js/modern/manager/shared.js +44 -0
  10. package/dist/js/modern/manager/sync.js +188 -0
  11. package/dist/js/modern/manager/types.js +0 -0
  12. package/dist/js/modern/waterfall/async.js +47 -0
  13. package/dist/js/modern/waterfall/index.js +2 -0
  14. package/dist/js/modern/waterfall/sync.js +47 -0
  15. package/dist/js/modern/workflow/async.js +43 -0
  16. package/dist/js/modern/workflow/index.js +3 -0
  17. package/dist/js/modern/workflow/parallel.js +31 -0
  18. package/dist/js/modern/workflow/sync.js +34 -0
  19. package/dist/js/node/farrow-pipeline/context.js +47 -0
  20. package/dist/js/node/farrow-pipeline/counter.js +27 -0
  21. package/dist/js/node/farrow-pipeline/index.js +18 -0
  22. package/dist/js/node/farrow-pipeline/pipeline.js +94 -0
  23. package/dist/js/node/index.js +57 -0
  24. package/dist/js/node/manager/async.js +124 -0
  25. package/dist/js/node/manager/index.js +44 -0
  26. package/dist/js/node/manager/shared.js +64 -0
  27. package/dist/js/node/manager/sync.js +212 -0
  28. package/dist/js/node/manager/types.js +0 -0
  29. package/dist/js/node/waterfall/async.js +64 -0
  30. package/dist/js/node/waterfall/index.js +31 -0
  31. package/dist/js/node/waterfall/sync.js +64 -0
  32. package/dist/js/node/workflow/async.js +57 -0
  33. package/dist/js/node/workflow/index.js +44 -0
  34. package/dist/js/node/workflow/parallel.js +45 -0
  35. package/dist/js/node/workflow/sync.js +48 -0
  36. package/dist/js/treeshaking/farrow-pipeline/context.js +42 -0
  37. package/dist/js/treeshaking/farrow-pipeline/counter.js +23 -0
  38. package/dist/js/treeshaking/farrow-pipeline/index.js +5 -0
  39. package/dist/js/treeshaking/farrow-pipeline/pipeline.js +81 -0
  40. package/dist/js/treeshaking/index.js +4 -0
  41. package/dist/js/treeshaking/manager/async.js +146 -0
  42. package/dist/js/treeshaking/manager/index.js +3 -0
  43. package/dist/js/treeshaking/manager/shared.js +79 -0
  44. package/dist/js/treeshaking/manager/sync.js +216 -0
  45. package/dist/js/treeshaking/manager/types.js +0 -0
  46. package/dist/js/treeshaking/waterfall/async.js +84 -0
  47. package/dist/js/treeshaking/waterfall/index.js +2 -0
  48. package/dist/js/treeshaking/waterfall/sync.js +59 -0
  49. package/dist/js/treeshaking/workflow/async.js +108 -0
  50. package/dist/js/treeshaking/workflow/index.js +3 -0
  51. package/dist/js/treeshaking/workflow/parallel.js +62 -0
  52. package/dist/js/treeshaking/workflow/sync.js +42 -0
  53. package/dist/types/farrow-pipeline/context.d.ts +13 -0
  54. package/dist/types/farrow-pipeline/counter.d.ts +11 -0
  55. package/dist/types/farrow-pipeline/index.d.ts +5 -0
  56. package/dist/types/farrow-pipeline/pipeline.d.ts +29 -0
  57. package/dist/types/index.d.ts +4 -0
  58. package/dist/types/manager/async.d.ts +63 -0
  59. package/dist/types/manager/index.d.ts +3 -0
  60. package/dist/types/manager/shared.d.ts +12 -0
  61. package/dist/types/manager/sync.d.ts +75 -0
  62. package/dist/types/manager/types.d.ts +36 -0
  63. package/dist/types/waterfall/async.d.ts +21 -0
  64. package/dist/types/waterfall/index.d.ts +2 -0
  65. package/dist/types/waterfall/sync.d.ts +20 -0
  66. package/dist/types/workflow/async.d.ts +12 -0
  67. package/dist/types/workflow/index.d.ts +3 -0
  68. package/dist/types/workflow/parallel.d.ts +10 -0
  69. package/dist/types/workflow/sync.d.ts +11 -0
  70. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @modern-js/plugin
2
2
 
3
+ ## 1.21.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 9d4c0ba: chore: add types for exports field
8
+ chore: 为 exports 补充 types 字段
9
+
3
10
  ## 1.21.1
4
11
 
5
12
  ## 1.21.0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ export const createContext = value => {
6
+ let currentValue;
7
+
8
+ const create = value => {
9
+ currentValue = value;
10
+
11
+ const use = () => ({
12
+ get value() {
13
+ return currentValue;
14
+ },
15
+
16
+ set value(v) {
17
+ currentValue = v;
18
+ }
19
+
20
+ });
21
+
22
+ const get = () => currentValue;
23
+
24
+ const set = v => {
25
+ currentValue = v;
26
+ };
27
+
28
+ const Context = {
29
+ create,
30
+ use,
31
+ get,
32
+ set
33
+ };
34
+ return Context;
35
+ };
36
+
37
+ return create(value);
38
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ export const createCounter = callback => {
6
+ const dispatch = (index, input) => {
7
+ const next = (nextInput = input) => dispatch(index + 1, nextInput);
8
+
9
+ return callback(index, input, next);
10
+ };
11
+
12
+ const start = input => dispatch(0, input);
13
+
14
+ return {
15
+ start,
16
+ dispatch
17
+ };
18
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
3
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
4
+ */
5
+ export * from "./pipeline";
@@ -0,0 +1,76 @@
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
+
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
+
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
+
7
+ /**
8
+ * modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
9
+ * license at https://github.com/farrow-js/farrow/blob/master/LICENSE
10
+ */
11
+ import { createContext } from "./context";
12
+ import { createCounter } from "./counter";
13
+ export { createContext };
14
+ export const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
15
+ const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
16
+
17
+ const getMiddleware = input => {
18
+ if (typeof input === 'function') {
19
+ return input;
20
+ } else if (input && typeof input.middleware === 'function') {
21
+ return input.middleware;
22
+ }
23
+
24
+ throw new Error(`${input} is not a Middleware`);
25
+ };
26
+
27
+ export const createPipeline = () => {
28
+ const middlewares = [];
29
+
30
+ const use = (...inputs) => {
31
+ middlewares.push(...inputs.map(getMiddleware));
32
+ return pipeline;
33
+ };
34
+
35
+ const createCurrentCounter = onLast => {
36
+ return createCounter((index, input, next) => {
37
+ if (index >= middlewares.length) {
38
+ if (onLast) {
39
+ return onLast(input);
40
+ }
41
+
42
+ throw new Error(`Expect returning a value, but all middlewares just calling next()`);
43
+ }
44
+
45
+ return middlewares[index](input, next);
46
+ });
47
+ };
48
+
49
+ const currentCounter = createCurrentCounter();
50
+
51
+ const getCounter = options => {
52
+ if (!options) {
53
+ return currentCounter;
54
+ }
55
+
56
+ return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
57
+ };
58
+
59
+ const run = (input, options) => getCounter(options).start(input);
60
+
61
+ const middleware = (input, next) => run(input, {
62
+ onLast: next
63
+ });
64
+
65
+ const pipeline = {
66
+ [PipelineSymbol]: true,
67
+ use,
68
+ run,
69
+ middleware
70
+ };
71
+ return pipeline;
72
+ };
73
+ export const createAsyncPipeline = () => {
74
+ const pipeline = createPipeline();
75
+ return _objectSpread({}, pipeline);
76
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./farrow-pipeline";
2
+ export * from "./waterfall";
3
+ export * from "./workflow";
4
+ export * from "./manager";
@@ -0,0 +1,112 @@
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
+
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
+
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
+
7
+ import { generateRunner, DEFAULT_OPTIONS } from "./sync";
8
+ import { checkPlugins, isObject, hasOwnProperty, sortPlugins, includePlugin } from "./shared";
9
+ const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
10
+ export const createAsyncManager = (hooks, api) => {
11
+ let index = 0;
12
+ let runners;
13
+
14
+ let currentHooks = _objectSpread({}, hooks);
15
+
16
+ const useRunner = () => runners;
17
+
18
+ const registerHook = extraHooks => {
19
+ currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
20
+ };
21
+
22
+ const isPlugin = input => isObject(input) && hasOwnProperty(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
23
+
24
+ const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
25
+ useHookRunners: useRunner
26
+ });
27
+
28
+ const clone = overrideAPI => {
29
+ let plugins = [];
30
+
31
+ const addPlugin = plugin => {
32
+ if (!includePlugin(plugins, plugin)) {
33
+ plugins.push(_objectSpread({}, plugin));
34
+ }
35
+ };
36
+
37
+ const usePlugin = (...input) => {
38
+ for (const plugin of input) {
39
+ // already created by createPlugin
40
+ if (isPlugin(plugin)) {
41
+ addPlugin(plugin);
42
+ } // using function to return plugin options
43
+ else if (typeof plugin === 'function') {
44
+ const options = plugin();
45
+ addPlugin(createPlugin(options.setup, options));
46
+ } // plain plugin object
47
+ else if (isObject(plugin)) {
48
+ addPlugin(createPlugin(plugin.setup, plugin));
49
+ } // unknown plugin
50
+ else {
51
+ console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
52
+ }
53
+ }
54
+
55
+ return manager;
56
+ };
57
+
58
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
59
+ setup = () => {}, options = {}) => {
60
+ var _options$usePlugins;
61
+
62
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
63
+ options.usePlugins.forEach(plugin => {
64
+ usePlugin(createPlugin(plugin.setup, plugin));
65
+ });
66
+ }
67
+
68
+ if (options.registerHook) {
69
+ registerHook(options.registerHook);
70
+ }
71
+
72
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
73
+ name: `No.${index++} plugin`
74
+ }, options), {}, {
75
+ ASYNC_PLUGIN_SYMBOL,
76
+ setup
77
+ });
78
+ };
79
+
80
+ const clear = () => {
81
+ plugins = [];
82
+ };
83
+
84
+ const init = async () => {
85
+ const sortedPlugins = sortPlugins(plugins);
86
+
87
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
88
+
89
+ checkPlugins(sortedPlugins);
90
+ const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
91
+ runners = generateRunner(hooksList, currentHooks);
92
+ return runners;
93
+ };
94
+
95
+ const run = cb => cb();
96
+
97
+ const manager = {
98
+ createPlugin,
99
+ isPlugin,
100
+ usePlugin,
101
+ init,
102
+ run,
103
+ clear,
104
+ clone,
105
+ registerHook,
106
+ useRunner
107
+ };
108
+ return manager;
109
+ };
110
+
111
+ return clone();
112
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./sync";
2
+ export * from "./async";
3
+ export * from "./types";
@@ -0,0 +1,44 @@
1
+ export const checkPlugins = plugins => {
2
+ plugins.forEach(origin => {
3
+ origin.rivals.forEach(rival => {
4
+ plugins.forEach(plugin => {
5
+ if (rival === plugin.name) {
6
+ throw new Error(`${origin.name} has rival ${plugin.name}`);
7
+ }
8
+ });
9
+ });
10
+ origin.required.forEach(required => {
11
+ if (!plugins.some(plugin => plugin.name === required)) {
12
+ throw new Error(`The plugin: ${required} is required when plugin: ${origin.name} is exist.`);
13
+ }
14
+ });
15
+ });
16
+ };
17
+ export function sortPlugins(input) {
18
+ let plugins = input.slice();
19
+
20
+ for (let i = 0; i < plugins.length; i++) {
21
+ const plugin = plugins[i];
22
+
23
+ for (const pre of plugin.pre) {
24
+ for (let j = i + 1; j < plugins.length; j++) {
25
+ if (plugins[j].name === pre) {
26
+ plugins = [...plugins.slice(0, i), plugins[j], ...plugins.slice(i, j), ...plugins.slice(j + 1, plugins.length)];
27
+ }
28
+ }
29
+ }
30
+
31
+ for (const post of plugin.post) {
32
+ for (let j = 0; j < i; j++) {
33
+ if (plugins[j].name === post) {
34
+ plugins = [...plugins.slice(0, j), ...plugins.slice(j + 1, i + 1), plugins[j], ...plugins.slice(i + 1, plugins.length)];
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ return plugins;
41
+ }
42
+ export const includePlugin = (plugins, input) => plugins.some(plugin => plugin.name === input.name);
43
+ export const isObject = obj => obj !== null && typeof obj === 'object';
44
+ export const hasOwnProperty = (obj, prop) => obj.hasOwnProperty(prop);
@@ -0,0 +1,188 @@
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
+
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
+
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
+
7
+ import { isPipeline, createPipeline } from "../farrow-pipeline";
8
+ import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
9
+ import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
10
+ import { checkPlugins, hasOwnProperty, includePlugin, isObject, sortPlugins } from "./shared";
11
+ const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
12
+ export const DEFAULT_OPTIONS = {
13
+ name: 'untitled',
14
+ pre: [],
15
+ post: [],
16
+ rivals: [],
17
+ required: [],
18
+ usePlugins: [],
19
+ registerHook: {}
20
+ };
21
+ export const createManager = (hooks, api) => {
22
+ let index = 0;
23
+ let runners;
24
+
25
+ let currentHooks = _objectSpread({}, hooks);
26
+
27
+ const useRunner = () => runners;
28
+
29
+ const registerHook = extraHooks => {
30
+ currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
31
+ };
32
+
33
+ const isPlugin = input => isObject(input) && hasOwnProperty(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
34
+
35
+ const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
36
+ useHookRunners: useRunner
37
+ });
38
+
39
+ const clone = overrideAPI => {
40
+ let plugins = [];
41
+
42
+ const addPlugin = plugin => {
43
+ if (!includePlugin(plugins, plugin)) {
44
+ plugins.push(_objectSpread({}, plugin));
45
+ }
46
+ };
47
+
48
+ const usePlugin = (...input) => {
49
+ input.forEach(plugin => {
50
+ // already created by createPlugin
51
+ if (isPlugin(plugin)) {
52
+ addPlugin(plugin);
53
+ } // using function to return plugin options
54
+ else if (typeof plugin === 'function') {
55
+ const options = plugin();
56
+ addPlugin(createPlugin(options.setup, options));
57
+ } // plain plugin object
58
+ else if (isObject(plugin)) {
59
+ addPlugin(createPlugin(plugin.setup, plugin));
60
+ } // unknown plugin
61
+ else {
62
+ console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
63
+ }
64
+ });
65
+ return manager;
66
+ };
67
+
68
+ const createPlugin = ( // eslint-disable-next-line @typescript-eslint/no-empty-function
69
+ setup = () => {}, options = {}) => {
70
+ var _options$usePlugins;
71
+
72
+ if ((_options$usePlugins = options.usePlugins) !== null && _options$usePlugins !== void 0 && _options$usePlugins.length) {
73
+ options.usePlugins.forEach(plugin => {
74
+ usePlugin(createPlugin(plugin.setup, plugin));
75
+ });
76
+ }
77
+
78
+ if (options.registerHook) {
79
+ registerHook(options.registerHook);
80
+ }
81
+
82
+ return _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_OPTIONS), {}, {
83
+ name: `No.${index++} plugin`
84
+ }, options), {}, {
85
+ SYNC_PLUGIN_SYMBOL,
86
+ setup
87
+ });
88
+ };
89
+
90
+ const clear = () => {
91
+ plugins = [];
92
+ };
93
+
94
+ const init = () => {
95
+ const sortedPlugins = sortPlugins(plugins);
96
+
97
+ const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
98
+
99
+ checkPlugins(sortedPlugins);
100
+ const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
101
+ runners = generateRunner(hooksList, currentHooks);
102
+ return runners;
103
+ };
104
+
105
+ const run = cb => cb();
106
+
107
+ const manager = {
108
+ createPlugin,
109
+ isPlugin,
110
+ usePlugin,
111
+ init,
112
+ clear,
113
+ run,
114
+ registerHook,
115
+ useRunner,
116
+ clone
117
+ };
118
+ return manager;
119
+ };
120
+
121
+ return clone();
122
+ };
123
+ export const generateRunner = (hooksList, hooksMap) => {
124
+ const runner = {};
125
+ const cloneShape = cloneHooksMap(hooksMap);
126
+
127
+ if (hooksMap) {
128
+ for (const key in cloneShape) {
129
+ for (const hooks of hooksList) {
130
+ if (!hooks) {
131
+ continue;
132
+ }
133
+
134
+ if (hooks[key]) {
135
+ cloneShape[key].use(hooks[key]);
136
+ }
137
+ } // eslint-disable-next-line @typescript-eslint/ban-ts-comment
138
+ // @ts-expect-error
139
+
140
+
141
+ runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
142
+ }
143
+ }
144
+
145
+ return runner;
146
+ };
147
+ export const cloneHook = hook => {
148
+ if (isWaterfall(hook)) {
149
+ return createWaterfall();
150
+ }
151
+
152
+ if (isAsyncWaterfall(hook)) {
153
+ return createAsyncWaterfall();
154
+ }
155
+
156
+ if (isWorkflow(hook)) {
157
+ return createWorkflow();
158
+ }
159
+
160
+ if (isAsyncWorkflow(hook)) {
161
+ return createAsyncWorkflow();
162
+ }
163
+
164
+ if (isParallelWorkflow(hook)) {
165
+ return createParallelWorkflow();
166
+ }
167
+
168
+ if (isPipeline(hook)) {
169
+ return createPipeline();
170
+ }
171
+
172
+ throw new Error(`Unknown hook: ${hook}`);
173
+ };
174
+ export const cloneHooksMap = record => {
175
+ if (!record) {
176
+ return record;
177
+ }
178
+
179
+ const result = {};
180
+
181
+ for (const key in record) {
182
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
183
+ // @ts-expect-error
184
+ result[key] = cloneHook(record[key]);
185
+ }
186
+
187
+ return result;
188
+ };
File without changes
@@ -0,0 +1,47 @@
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
+
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
+
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
+
7
+ import { createAsyncPipeline } from "../farrow-pipeline";
8
+ const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
9
+ export const getAsyncBrook = input => {
10
+ if (typeof input === 'function') {
11
+ return input;
12
+ } else if (input && typeof input.middleware === 'function') {
13
+ return input.middleware;
14
+ }
15
+
16
+ throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
17
+ };
18
+ export const createAsyncWaterfall = () => {
19
+ const pipeline = createAsyncPipeline();
20
+
21
+ const use = (...input) => {
22
+ pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
23
+ return waterfall;
24
+ };
25
+
26
+ const run = (input, options) => pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
27
+ onLast: input => input
28
+ }));
29
+
30
+ const middleware = input => {
31
+ return pipeline.run(input, {
32
+ onLast: input => input
33
+ });
34
+ };
35
+
36
+ const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
37
+ use,
38
+ run,
39
+ middleware,
40
+ [ASYNC_WATERFALL_SYMBOL]: true
41
+ });
42
+
43
+ return waterfall;
44
+ };
45
+ export const isAsyncWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
46
+
47
+ const mapAsyncBrookToAsyncMiddleware = brook => async (input, next) => next(await brook(input));
@@ -0,0 +1,2 @@
1
+ export * from "./sync";
2
+ export * from "./async";
@@ -0,0 +1,47 @@
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
+
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
+
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
+
7
+ import { createPipeline } from "../farrow-pipeline";
8
+ const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
9
+ export const getBrook = input => {
10
+ if (typeof input === 'function') {
11
+ return input;
12
+ } else if (input && typeof input.middleware === 'function') {
13
+ return input.middleware;
14
+ }
15
+
16
+ throw new Error(`${input} is not a Brook or { brook: Brook }`);
17
+ };
18
+ export const createWaterfall = () => {
19
+ const pipeline = createPipeline();
20
+
21
+ const use = (...brooks) => {
22
+ pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
23
+ return waterfall;
24
+ };
25
+
26
+ const run = (input, options) => pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
27
+ onLast: input => input
28
+ }));
29
+
30
+ const middleware = input => {
31
+ return pipeline.run(input, {
32
+ onLast: input => input
33
+ });
34
+ };
35
+
36
+ const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
37
+ use,
38
+ run,
39
+ middleware,
40
+ [WATERFALL_SYMBOL]: true
41
+ });
42
+
43
+ return waterfall;
44
+ };
45
+ export const isWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
46
+
47
+ const mapBrookToMiddleware = brook => (input, next) => next(brook(input));
@@ -0,0 +1,43 @@
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
+
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
+
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
+
7
+ import { createAsyncPipeline } from "../farrow-pipeline";
8
+ const ASYNC_WORKFLOW_SYMBOL = Symbol.for('MODERN_ASYNC_WORKFLOW');
9
+ export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
10
+ export const createAsyncWorkflow = () => {
11
+ const pipeline = createAsyncPipeline();
12
+
13
+ const use = (...input) => {
14
+ pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
15
+ return workflow;
16
+ };
17
+
18
+ const run = async input => {
19
+ const result = pipeline.run(input, {
20
+ onLast: () => []
21
+ });
22
+
23
+ if (isPromise(result)) {
24
+ return result.then(result => result.filter(Boolean));
25
+ } else {
26
+ return result.filter(Boolean);
27
+ }
28
+ };
29
+
30
+ const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
31
+ use,
32
+ run,
33
+ [ASYNC_WORKFLOW_SYMBOL]: true
34
+ });
35
+
36
+ return workflow;
37
+ };
38
+
39
+ const mapAsyncWorkerToAsyncMiddleware = worker => async (input, next) => [await worker(input), ...(await next(input))];
40
+
41
+ function isPromise(obj) {
42
+ return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
43
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./sync";
2
+ export * from "./parallel";
3
+ export * from "./async";