@modern-js/plugin 1.3.2 → 1.3.5
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/farrow-pipeline/asyncHooks.node.js +74 -0
- package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +12 -0
- package/dist/js/modern/farrow-pipeline/context.js +99 -0
- package/dist/js/modern/farrow-pipeline/counter.js +18 -0
- package/dist/js/modern/farrow-pipeline/hook.js +42 -0
- package/dist/js/modern/farrow-pipeline/index.js +19 -0
- package/dist/js/modern/farrow-pipeline/pipeline.js +93 -0
- package/dist/js/modern/index.js +1 -1
- package/dist/js/modern/manager/async.js +1 -1
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +2 -3
- package/dist/js/modern/waterfall/async.js +5 -9
- package/dist/js/modern/waterfall/sync.js +5 -9
- package/dist/js/modern/workflow/async.js +2 -5
- package/dist/js/modern/workflow/parallel.js +3 -4
- package/dist/js/modern/workflow/sync.js +2 -2
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +93 -0
- package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +26 -0
- package/dist/js/node/farrow-pipeline/context.js +120 -0
- package/dist/js/node/farrow-pipeline/counter.js +27 -0
- package/dist/js/node/farrow-pipeline/hook.js +52 -0
- package/dist/js/node/farrow-pipeline/index.js +18 -0
- package/dist/js/node/farrow-pipeline/pipeline.js +129 -0
- package/dist/js/node/index.js +1 -1
- package/dist/js/node/manager/async.js +1 -1
- package/dist/js/node/manager/runner.js +1 -1
- package/dist/js/node/manager/sync.js +2 -3
- package/dist/js/node/waterfall/async.js +5 -9
- package/dist/js/node/waterfall/sync.js +5 -9
- package/dist/js/node/workflow/async.js +2 -5
- package/dist/js/node/workflow/parallel.js +3 -4
- package/dist/js/node/workflow/sync.js +2 -2
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +74 -0
- package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +12 -0
- package/dist/js/treeshaking/farrow-pipeline/context.js +103 -0
- package/dist/js/treeshaking/farrow-pipeline/counter.js +23 -0
- package/dist/js/treeshaking/farrow-pipeline/hook.js +46 -0
- package/dist/js/treeshaking/farrow-pipeline/index.js +19 -0
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +100 -0
- package/dist/js/treeshaking/index.js +1 -1
- package/dist/js/treeshaking/manager/async.js +5 -26
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +6 -25
- package/dist/js/treeshaking/waterfall/async.js +13 -37
- package/dist/js/treeshaking/waterfall/sync.js +12 -32
- package/dist/js/treeshaking/workflow/async.js +7 -29
- package/dist/js/treeshaking/workflow/parallel.js +7 -27
- package/dist/js/treeshaking/workflow/sync.js +6 -25
- package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +2 -0
- package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +19 -0
- package/dist/types/farrow-pipeline/context.d.ts +28 -0
- package/dist/types/farrow-pipeline/counter.d.ts +11 -0
- package/dist/types/farrow-pipeline/hook.d.ts +9 -0
- package/dist/types/farrow-pipeline/index.d.ts +19 -0
- package/dist/types/farrow-pipeline/pipeline.d.ts +38 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/manager/runner.d.ts +1 -1
- package/dist/types/manager/sync.d.ts +1 -1
- package/dist/types/manager/types.d.ts +1 -1
- package/dist/types/waterfall/async.d.ts +1 -1
- package/dist/types/waterfall/sync.d.ts +1 -1
- package/dist/types/workflow/async.d.ts +1 -1
- package/dist/types/workflow/sync.d.ts +1 -1
- package/package.json +37 -8
- package/jest.config.js +0 -8
- package/modern.config.js +0 -2
- package/node.d.ts +0 -1
- package/node.js +0 -1
- package/tests/.eslintrc.js +0 -6
- package/tests/async.test.ts +0 -738
- package/tests/fixtures/async/base/bar.ts +0 -22
- package/tests/fixtures/async/base/foo.ts +0 -20
- package/tests/fixtures/async/base/fooManager.ts +0 -47
- package/tests/fixtures/async/core/index.ts +0 -174
- package/tests/fixtures/async/dynamic/bar.ts +0 -18
- package/tests/fixtures/async/dynamic/foo.ts +0 -27
- package/tests/fixtures/sync/base/bar.ts +0 -21
- package/tests/fixtures/sync/base/foo.ts +0 -20
- package/tests/fixtures/sync/base/fooManager.ts +0 -47
- package/tests/fixtures/sync/core/index.ts +0 -171
- package/tests/fixtures/sync/dynamic/bar.ts +0 -22
- package/tests/fixtures/sync/dynamic/foo.ts +0 -27
- package/tests/helpers.ts +0 -4
- package/tests/pipeline.test.ts +0 -607
- package/tests/sync.test.ts +0 -701
- package/tests/tsconfig.json +0 -13
- package/tests/waterfall.test.ts +0 -172
- package/tests/workflow.test.ts +0 -111
- package/tsconfig.json +0 -14
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# @modern-js/plugin
|
2
2
|
|
3
|
+
## 1.3.5
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 54fa1dbd6: fix(plugin): allow multiple versions to be installed
|
8
|
+
|
9
|
+
## 1.3.4
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- d5913bd96: feat: fork farrow-pipeline to remove tslib and reduce bundle size
|
14
|
+
- d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
|
15
|
+
|
16
|
+
## 1.3.3
|
17
|
+
|
18
|
+
### Patch Changes
|
19
|
+
|
20
|
+
- 6cffe99d: chore:
|
21
|
+
remove react eslint rules for `modern-js` rule set.
|
22
|
+
add .eslintrc for each package to speed up linting
|
23
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
24
|
+
|
3
25
|
## 1.3.2
|
4
26
|
|
5
27
|
### Patch Changes
|
@@ -0,0 +1,74 @@
|
|
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
|
+
import NodeAsyncHooks from 'async_hooks';
|
6
|
+
import * as asyncHooksInterface from "./asyncHooksInterface";
|
7
|
+
|
8
|
+
const createAsyncHooks = () => {
|
9
|
+
const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
10
|
+
|
11
|
+
const hooks = NodeAsyncHooks.createHook({
|
12
|
+
init: (asyncId, _, triggerAsyncId) => {
|
13
|
+
if (store.has(triggerAsyncId)) {
|
14
|
+
const value = store.get(triggerAsyncId);
|
15
|
+
|
16
|
+
if (value) {
|
17
|
+
store.set(asyncId, value);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
},
|
21
|
+
destroy: asyncId => {
|
22
|
+
if (store.has(asyncId)) {
|
23
|
+
store.delete(asyncId);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
const set = value => {
|
29
|
+
store.set(NodeAsyncHooks.executionAsyncId(), value);
|
30
|
+
};
|
31
|
+
|
32
|
+
const get = () => {
|
33
|
+
return store.get(NodeAsyncHooks.executionAsyncId());
|
34
|
+
};
|
35
|
+
|
36
|
+
const clear = () => {
|
37
|
+
store.clear();
|
38
|
+
};
|
39
|
+
|
40
|
+
const enable = () => {
|
41
|
+
hooks.enable();
|
42
|
+
};
|
43
|
+
|
44
|
+
const disable = () => {
|
45
|
+
hooks.disable();
|
46
|
+
store.clear();
|
47
|
+
};
|
48
|
+
|
49
|
+
const entries = () => {
|
50
|
+
return store.entries();
|
51
|
+
};
|
52
|
+
|
53
|
+
return {
|
54
|
+
enable,
|
55
|
+
disable,
|
56
|
+
set,
|
57
|
+
get,
|
58
|
+
clear,
|
59
|
+
entries
|
60
|
+
};
|
61
|
+
};
|
62
|
+
|
63
|
+
export const enable = () => {
|
64
|
+
const hooks = createAsyncHooks();
|
65
|
+
disable();
|
66
|
+
asyncHooksInterface.impl(hooks);
|
67
|
+
hooks.enable();
|
68
|
+
};
|
69
|
+
export const disable = () => {
|
70
|
+
var _asyncHooksInterface$;
|
71
|
+
|
72
|
+
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
73
|
+
asyncHooksInterface.reset();
|
74
|
+
};
|
@@ -0,0 +1,12 @@
|
|
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
|
+
// eslint-disable-next-line import/no-mutable-exports
|
6
|
+
export let asyncHooks;
|
7
|
+
export const impl = implimentations => {
|
8
|
+
asyncHooks = implimentations;
|
9
|
+
};
|
10
|
+
export const reset = () => {
|
11
|
+
asyncHooks = undefined;
|
12
|
+
};
|
@@ -0,0 +1,99 @@
|
|
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
|
+
import { createHooks } from "./hook";
|
6
|
+
const ContextSymbol = Symbol.for('MODERN_CONTEXT');
|
7
|
+
export const createContext = value => {
|
8
|
+
const id = Symbol('MODERN_CONTEXT_ID');
|
9
|
+
|
10
|
+
const create = value => {
|
11
|
+
const use = () => {
|
12
|
+
const container = useContainer();
|
13
|
+
return Object.seal({
|
14
|
+
get value() {
|
15
|
+
return container.read(Context);
|
16
|
+
},
|
17
|
+
|
18
|
+
set value(v) {
|
19
|
+
container.write(Context, v);
|
20
|
+
}
|
21
|
+
|
22
|
+
});
|
23
|
+
};
|
24
|
+
|
25
|
+
const get = () => {
|
26
|
+
const container = useContainer();
|
27
|
+
return container.read(Context);
|
28
|
+
};
|
29
|
+
|
30
|
+
const set = v => {
|
31
|
+
const container = useContainer();
|
32
|
+
container.write(Context, v);
|
33
|
+
};
|
34
|
+
|
35
|
+
const Context = {
|
36
|
+
id,
|
37
|
+
[ContextSymbol]: value,
|
38
|
+
create,
|
39
|
+
use,
|
40
|
+
get,
|
41
|
+
set
|
42
|
+
};
|
43
|
+
return Context;
|
44
|
+
};
|
45
|
+
|
46
|
+
return create(value);
|
47
|
+
};
|
48
|
+
|
49
|
+
const createContextMap = storage => {
|
50
|
+
const contextMap = new Map();
|
51
|
+
const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
|
52
|
+
|
53
|
+
for (let i = 0; i < contexts.length; i++) {
|
54
|
+
contextMap.set(contexts[i].id, contexts[i]);
|
55
|
+
}
|
56
|
+
|
57
|
+
return contextMap;
|
58
|
+
};
|
59
|
+
|
60
|
+
export const createContainer = (ContextStorage = {}) => {
|
61
|
+
const contextMap = createContextMap(ContextStorage);
|
62
|
+
|
63
|
+
const read = context => {
|
64
|
+
const target = contextMap.get(context.id);
|
65
|
+
|
66
|
+
if (target) {
|
67
|
+
return target[ContextSymbol];
|
68
|
+
}
|
69
|
+
|
70
|
+
return context[ContextSymbol];
|
71
|
+
};
|
72
|
+
|
73
|
+
const write = (context, value) => {
|
74
|
+
contextMap.set(context.id, context.create(value));
|
75
|
+
};
|
76
|
+
|
77
|
+
return Object.freeze({
|
78
|
+
read,
|
79
|
+
write
|
80
|
+
});
|
81
|
+
};
|
82
|
+
const {
|
83
|
+
run,
|
84
|
+
hooks
|
85
|
+
} = createHooks({
|
86
|
+
useContainer: () => {
|
87
|
+
throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
export const runHooks = run;
|
91
|
+
export const {
|
92
|
+
useContainer
|
93
|
+
} = hooks;
|
94
|
+
export const fromContainer = container => ({
|
95
|
+
useContainer: () => {
|
96
|
+
return container;
|
97
|
+
}
|
98
|
+
});
|
99
|
+
export const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
|
@@ -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,42 @@
|
|
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
|
+
import { asyncHooks } from "./asyncHooksInterface";
|
6
|
+
export const createHooks = defaultHooks => {
|
7
|
+
let currentHooks = {};
|
8
|
+
const hooks = {};
|
9
|
+
|
10
|
+
for (const key in defaultHooks) {
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
12
|
+
const f = (...args) => {
|
13
|
+
var _asyncHooks$get;
|
14
|
+
|
15
|
+
const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
16
|
+
let handler = hooks[key];
|
17
|
+
|
18
|
+
if (typeof handler !== 'function') {
|
19
|
+
handler = defaultHooks[key];
|
20
|
+
}
|
21
|
+
|
22
|
+
return handler(...args);
|
23
|
+
};
|
24
|
+
|
25
|
+
hooks[key] = f;
|
26
|
+
}
|
27
|
+
|
28
|
+
const run = (f, implementations) => {
|
29
|
+
try {
|
30
|
+
currentHooks = implementations || defaultHooks;
|
31
|
+
asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
|
32
|
+
return f();
|
33
|
+
} finally {
|
34
|
+
currentHooks = defaultHooks;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
return {
|
39
|
+
run,
|
40
|
+
hooks
|
41
|
+
};
|
42
|
+
};
|
@@ -0,0 +1,19 @@
|
|
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
|
+
* removed:
|
6
|
+
* - dependencies:
|
7
|
+
* - tslib
|
8
|
+
* - files
|
9
|
+
* - compose.ts
|
10
|
+
* - methods:
|
11
|
+
* - usePipeline
|
12
|
+
* - assertContainer
|
13
|
+
* - assertContext
|
14
|
+
* - isContext
|
15
|
+
* - isContainer
|
16
|
+
* - pipeline.useLazy
|
17
|
+
* - context.assert
|
18
|
+
*/
|
19
|
+
export * from "./pipeline";
|
@@ -0,0 +1,93 @@
|
|
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, createContainer, fromContainer, runHooks, useContainer, runWithContainer } from "./context";
|
12
|
+
import { createCounter } from "./counter";
|
13
|
+
export { createContext, createContainer, useContainer, runWithContainer };
|
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 = options => {
|
28
|
+
const config = _objectSpread({}, options);
|
29
|
+
|
30
|
+
const middlewares = [];
|
31
|
+
|
32
|
+
const use = (...inputs) => {
|
33
|
+
middlewares.push(...inputs.map(getMiddleware));
|
34
|
+
return pipeline;
|
35
|
+
};
|
36
|
+
|
37
|
+
const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
|
38
|
+
return createCounter((index, input, next) => {
|
39
|
+
if (index >= middlewares.length) {
|
40
|
+
if (onLast) {
|
41
|
+
if (onLastWithContext) {
|
42
|
+
return runHooks(() => onLast(input), hooks);
|
43
|
+
}
|
44
|
+
|
45
|
+
return onLast(input);
|
46
|
+
}
|
47
|
+
|
48
|
+
throw new Error(`Expect returning a value, but all middlewares just calling next()`);
|
49
|
+
}
|
50
|
+
|
51
|
+
return runHooks(() => middlewares[index](input, next), hooks);
|
52
|
+
});
|
53
|
+
};
|
54
|
+
|
55
|
+
const currentContainer = createContainer(config.contexts);
|
56
|
+
const currentHooks = fromContainer(currentContainer);
|
57
|
+
const currentCounter = createCurrentCounter(currentHooks);
|
58
|
+
|
59
|
+
const getCounter = options => {
|
60
|
+
if (!options) {
|
61
|
+
return currentCounter;
|
62
|
+
}
|
63
|
+
|
64
|
+
if (options !== null && options !== void 0 && options.container) {
|
65
|
+
const hooks = fromContainer(options === null || options === void 0 ? void 0 : options.container);
|
66
|
+
return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
|
67
|
+
}
|
68
|
+
|
69
|
+
return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
|
70
|
+
};
|
71
|
+
|
72
|
+
const run = (input, options) => getCounter(options).start(input);
|
73
|
+
|
74
|
+
const middleware = (input, next) => {
|
75
|
+
const container = useContainer();
|
76
|
+
return run(input, {
|
77
|
+
container,
|
78
|
+
onLast: next
|
79
|
+
});
|
80
|
+
};
|
81
|
+
|
82
|
+
const pipeline = {
|
83
|
+
[PipelineSymbol]: true,
|
84
|
+
use,
|
85
|
+
run,
|
86
|
+
middleware
|
87
|
+
};
|
88
|
+
return pipeline;
|
89
|
+
};
|
90
|
+
export const createAsyncPipeline = options => {
|
91
|
+
const pipeline = createPipeline(options);
|
92
|
+
return _objectSpread({}, pipeline);
|
93
|
+
};
|
package/dist/js/modern/index.js
CHANGED
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { runWithContainer, createContainer } from
|
7
|
+
import { runWithContainer, createContainer } from "../farrow-pipeline";
|
8
8
|
import { isObject, generateRunner, hasOwnProperty, DEFAULT_OPTIONS } from "./sync";
|
9
9
|
import { useRunner } from "./runner";
|
10
10
|
const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
|
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { isPipeline, createPipeline, runWithContainer, createContainer } from
|
7
|
+
import { isPipeline, createPipeline, runWithContainer, createContainer } from "../farrow-pipeline";
|
8
8
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
9
9
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
10
10
|
import { RunnerContext, useRunner } from "./runner";
|
@@ -173,8 +173,7 @@ export const cloneHook = hook => {
|
|
173
173
|
|
174
174
|
if (isPipeline(hook)) {
|
175
175
|
return createPipeline();
|
176
|
-
}
|
177
|
-
|
176
|
+
}
|
178
177
|
|
179
178
|
throw new Error(`Unknown hook: ${hook}`);
|
180
179
|
};
|
@@ -4,15 +4,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { createAsyncPipeline, useContainer } from
|
8
|
-
const ASYNC_WATERFALL_SYMBOL = Symbol('
|
7
|
+
import { createAsyncPipeline, useContainer } from "../farrow-pipeline";
|
8
|
+
const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
|
9
9
|
export const getAsyncBrook = input => {
|
10
10
|
if (typeof input === 'function') {
|
11
11
|
return input;
|
12
12
|
} else if (input && typeof input.middleware === 'function') {
|
13
13
|
return input.middleware;
|
14
|
-
}
|
15
|
-
|
14
|
+
}
|
16
15
|
|
17
16
|
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
18
17
|
};
|
@@ -24,15 +23,12 @@ export const createAsyncWaterfall = () => {
|
|
24
23
|
return waterfall;
|
25
24
|
};
|
26
25
|
|
27
|
-
const run = (input, options) =>
|
28
|
-
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
26
|
+
const run = (input, options) => pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
29
27
|
onLast: input => input
|
30
28
|
}));
|
31
29
|
|
32
30
|
const middleware = input => {
|
33
|
-
|
34
|
-
const container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
35
|
-
|
31
|
+
const container = useContainer();
|
36
32
|
return pipeline.run(input, {
|
37
33
|
container,
|
38
34
|
onLast: input => input
|
@@ -4,15 +4,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { useContainer, createPipeline } from
|
8
|
-
const WATERFALL_SYMBOL = Symbol('
|
7
|
+
import { useContainer, createPipeline } from "../farrow-pipeline";
|
8
|
+
const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
|
9
9
|
export const getBrook = input => {
|
10
10
|
if (typeof input === 'function') {
|
11
11
|
return input;
|
12
12
|
} else if (input && typeof input.middleware === 'function') {
|
13
13
|
return input.middleware;
|
14
|
-
}
|
15
|
-
|
14
|
+
}
|
16
15
|
|
17
16
|
throw new Error(`${input} is not a Brook or { brook: Brook }`);
|
18
17
|
};
|
@@ -24,15 +23,12 @@ export const createWaterfall = () => {
|
|
24
23
|
return waterfall;
|
25
24
|
};
|
26
25
|
|
27
|
-
const run = (input, options) =>
|
28
|
-
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
26
|
+
const run = (input, options) => pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
29
27
|
onLast: input => input
|
30
28
|
}));
|
31
29
|
|
32
30
|
const middleware = input => {
|
33
|
-
|
34
|
-
const container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
35
|
-
|
31
|
+
const container = useContainer();
|
36
32
|
return pipeline.run(input, {
|
37
33
|
container,
|
38
34
|
onLast: input => input
|
@@ -4,8 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { createAsyncPipeline } from
|
8
|
-
const ASYNC_WORKFLOW_SYMBOL = Symbol('
|
7
|
+
import { createAsyncPipeline } from "../farrow-pipeline";
|
8
|
+
const ASYNC_WORKFLOW_SYMBOL = Symbol.for('MODERN_ASYNC_WORKFLOW');
|
9
9
|
export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
10
10
|
export const createAsyncWorkflow = () => {
|
11
11
|
const pipeline = createAsyncPipeline();
|
@@ -21,7 +21,6 @@ export const createAsyncWorkflow = () => {
|
|
21
21
|
}));
|
22
22
|
|
23
23
|
if (isPromise(result)) {
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow,promise/prefer-await-to-then
|
25
24
|
return result.then(result => result.filter(Boolean));
|
26
25
|
} else {
|
27
26
|
return result.filter(Boolean);
|
@@ -40,7 +39,5 @@ export const createAsyncWorkflow = () => {
|
|
40
39
|
const mapAsyncWorkerToAsyncMiddleware = worker => async (input, next) => [await worker(input), ...(await next(input))];
|
41
40
|
|
42
41
|
function isPromise(obj) {
|
43
|
-
/* eslint-disable promise/prefer-await-to-then */
|
44
42
|
return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
45
|
-
/* eslint-enable promise/prefer-await-to-then */
|
46
43
|
}
|
@@ -4,8 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { createPipeline } from
|
8
|
-
const PARALLEL_WORKFLOW_SYMBOL = Symbol('
|
7
|
+
import { createPipeline } from "../farrow-pipeline";
|
8
|
+
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for('MODERN_PARALLEL_WORKFLOW');
|
9
9
|
export const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
10
10
|
export const createParallelWorkflow = () => {
|
11
11
|
const pipeline = createPipeline();
|
@@ -15,8 +15,7 @@ export const createParallelWorkflow = () => {
|
|
15
15
|
return workflow;
|
16
16
|
};
|
17
17
|
|
18
|
-
const run = async (input, options) =>
|
19
|
-
Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
18
|
+
const run = async (input, options) => Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
20
19
|
onLast: () => []
|
21
20
|
}))).then(result => result.filter(Boolean));
|
22
21
|
|
@@ -4,8 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
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
|
|
7
|
-
import { createPipeline } from
|
8
|
-
const WORKFLOW_SYMBOL = Symbol('
|
7
|
+
import { createPipeline } from "../farrow-pipeline";
|
8
|
+
const WORKFLOW_SYMBOL = Symbol.for('MODERN_WORKFLOW');
|
9
9
|
export const createWorkflow = () => {
|
10
10
|
const pipeline = createPipeline();
|
11
11
|
|
@@ -0,0 +1,93 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.enable = exports.disable = void 0;
|
7
|
+
|
8
|
+
var _async_hooks = _interopRequireDefault(require("async_hooks"));
|
9
|
+
|
10
|
+
var asyncHooksInterface = _interopRequireWildcard(require("./asyncHooksInterface"));
|
11
|
+
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13
|
+
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
/**
|
19
|
+
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
20
|
+
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
21
|
+
*/
|
22
|
+
const createAsyncHooks = () => {
|
23
|
+
const store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
24
|
+
|
25
|
+
const hooks = _async_hooks.default.createHook({
|
26
|
+
init: (asyncId, _, triggerAsyncId) => {
|
27
|
+
if (store.has(triggerAsyncId)) {
|
28
|
+
const value = store.get(triggerAsyncId);
|
29
|
+
|
30
|
+
if (value) {
|
31
|
+
store.set(asyncId, value);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
},
|
35
|
+
destroy: asyncId => {
|
36
|
+
if (store.has(asyncId)) {
|
37
|
+
store.delete(asyncId);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
});
|
41
|
+
|
42
|
+
const set = value => {
|
43
|
+
store.set(_async_hooks.default.executionAsyncId(), value);
|
44
|
+
};
|
45
|
+
|
46
|
+
const get = () => {
|
47
|
+
return store.get(_async_hooks.default.executionAsyncId());
|
48
|
+
};
|
49
|
+
|
50
|
+
const clear = () => {
|
51
|
+
store.clear();
|
52
|
+
};
|
53
|
+
|
54
|
+
const enable = () => {
|
55
|
+
hooks.enable();
|
56
|
+
};
|
57
|
+
|
58
|
+
const disable = () => {
|
59
|
+
hooks.disable();
|
60
|
+
store.clear();
|
61
|
+
};
|
62
|
+
|
63
|
+
const entries = () => {
|
64
|
+
return store.entries();
|
65
|
+
};
|
66
|
+
|
67
|
+
return {
|
68
|
+
enable,
|
69
|
+
disable,
|
70
|
+
set,
|
71
|
+
get,
|
72
|
+
clear,
|
73
|
+
entries
|
74
|
+
};
|
75
|
+
};
|
76
|
+
|
77
|
+
const enable = () => {
|
78
|
+
const hooks = createAsyncHooks();
|
79
|
+
disable();
|
80
|
+
asyncHooksInterface.impl(hooks);
|
81
|
+
hooks.enable();
|
82
|
+
};
|
83
|
+
|
84
|
+
exports.enable = enable;
|
85
|
+
|
86
|
+
const disable = () => {
|
87
|
+
var _asyncHooksInterface$;
|
88
|
+
|
89
|
+
(_asyncHooksInterface$ = asyncHooksInterface.asyncHooks) === null || _asyncHooksInterface$ === void 0 ? void 0 : _asyncHooksInterface$.disable();
|
90
|
+
asyncHooksInterface.reset();
|
91
|
+
};
|
92
|
+
|
93
|
+
exports.disable = disable;
|