@modern-js/plugin 1.3.3 → 1.3.6
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 +19 -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 +1 -1
- package/dist/js/modern/waterfall/async.js +3 -5
- package/dist/js/modern/waterfall/sync.js +3 -5
- package/dist/js/modern/workflow/async.js +2 -2
- package/dist/js/modern/workflow/parallel.js +2 -2
- 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 +1 -1
- package/dist/js/node/waterfall/async.js +3 -5
- package/dist/js/node/waterfall/sync.js +3 -5
- package/dist/js/node/workflow/async.js +2 -2
- package/dist/js/node/workflow/parallel.js +2 -2
- 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 +8 -29
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +5 -23
- package/dist/js/treeshaking/waterfall/async.js +10 -31
- package/dist/js/treeshaking/waterfall/sync.js +6 -23
- package/dist/js/treeshaking/workflow/async.js +12 -32
- package/dist/js/treeshaking/workflow/parallel.js +9 -28
- package/dist/js/treeshaking/workflow/sync.js +9 -28
- 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/.eslintrc.js +0 -8
- package/jest.config.js +0 -7
- package/modern.config.js +0 -2
- package/node.d.ts +0 -1
- package/node.js +0 -1
- package/tsconfig.json +0 -14
@@ -0,0 +1,120 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useContainer = exports.runWithContainer = exports.runHooks = exports.fromContainer = exports.createContext = exports.createContainer = void 0;
|
7
|
+
|
8
|
+
var _hook = require("./hook");
|
9
|
+
|
10
|
+
/**
|
11
|
+
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
12
|
+
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
13
|
+
*/
|
14
|
+
const ContextSymbol = Symbol.for('MODERN_CONTEXT');
|
15
|
+
|
16
|
+
const createContext = value => {
|
17
|
+
const id = Symbol('MODERN_CONTEXT_ID');
|
18
|
+
|
19
|
+
const create = value => {
|
20
|
+
const use = () => {
|
21
|
+
const container = useContainer();
|
22
|
+
return Object.seal({
|
23
|
+
get value() {
|
24
|
+
return container.read(Context);
|
25
|
+
},
|
26
|
+
|
27
|
+
set value(v) {
|
28
|
+
container.write(Context, v);
|
29
|
+
}
|
30
|
+
|
31
|
+
});
|
32
|
+
};
|
33
|
+
|
34
|
+
const get = () => {
|
35
|
+
const container = useContainer();
|
36
|
+
return container.read(Context);
|
37
|
+
};
|
38
|
+
|
39
|
+
const set = v => {
|
40
|
+
const container = useContainer();
|
41
|
+
container.write(Context, v);
|
42
|
+
};
|
43
|
+
|
44
|
+
const Context = {
|
45
|
+
id,
|
46
|
+
[ContextSymbol]: value,
|
47
|
+
create,
|
48
|
+
use,
|
49
|
+
get,
|
50
|
+
set
|
51
|
+
};
|
52
|
+
return Context;
|
53
|
+
};
|
54
|
+
|
55
|
+
return create(value);
|
56
|
+
};
|
57
|
+
|
58
|
+
exports.createContext = createContext;
|
59
|
+
|
60
|
+
const createContextMap = storage => {
|
61
|
+
const contextMap = new Map();
|
62
|
+
const contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
|
63
|
+
|
64
|
+
for (let i = 0; i < contexts.length; i++) {
|
65
|
+
contextMap.set(contexts[i].id, contexts[i]);
|
66
|
+
}
|
67
|
+
|
68
|
+
return contextMap;
|
69
|
+
};
|
70
|
+
|
71
|
+
const createContainer = (ContextStorage = {}) => {
|
72
|
+
const contextMap = createContextMap(ContextStorage);
|
73
|
+
|
74
|
+
const read = context => {
|
75
|
+
const target = contextMap.get(context.id);
|
76
|
+
|
77
|
+
if (target) {
|
78
|
+
return target[ContextSymbol];
|
79
|
+
}
|
80
|
+
|
81
|
+
return context[ContextSymbol];
|
82
|
+
};
|
83
|
+
|
84
|
+
const write = (context, value) => {
|
85
|
+
contextMap.set(context.id, context.create(value));
|
86
|
+
};
|
87
|
+
|
88
|
+
return Object.freeze({
|
89
|
+
read,
|
90
|
+
write
|
91
|
+
});
|
92
|
+
};
|
93
|
+
|
94
|
+
exports.createContainer = createContainer;
|
95
|
+
const {
|
96
|
+
run,
|
97
|
+
hooks
|
98
|
+
} = (0, _hook.createHooks)({
|
99
|
+
useContainer: () => {
|
100
|
+
throw new Error(`Can't call useContainer out of scope, it should be placed on top of the function`);
|
101
|
+
}
|
102
|
+
});
|
103
|
+
const runHooks = run;
|
104
|
+
exports.runHooks = runHooks;
|
105
|
+
const {
|
106
|
+
useContainer
|
107
|
+
} = hooks;
|
108
|
+
exports.useContainer = useContainer;
|
109
|
+
|
110
|
+
const fromContainer = container => ({
|
111
|
+
useContainer: () => {
|
112
|
+
return container;
|
113
|
+
}
|
114
|
+
});
|
115
|
+
|
116
|
+
exports.fromContainer = fromContainer;
|
117
|
+
|
118
|
+
const runWithContainer = (f, container) => runHooks(f, fromContainer(container));
|
119
|
+
|
120
|
+
exports.runWithContainer = runWithContainer;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createCounter = void 0;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
10
|
+
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
11
|
+
*/
|
12
|
+
const createCounter = callback => {
|
13
|
+
const dispatch = (index, input) => {
|
14
|
+
const next = (nextInput = input) => dispatch(index + 1, nextInput);
|
15
|
+
|
16
|
+
return callback(index, input, next);
|
17
|
+
};
|
18
|
+
|
19
|
+
const start = input => dispatch(0, input);
|
20
|
+
|
21
|
+
return {
|
22
|
+
start,
|
23
|
+
dispatch
|
24
|
+
};
|
25
|
+
};
|
26
|
+
|
27
|
+
exports.createCounter = createCounter;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createHooks = void 0;
|
7
|
+
|
8
|
+
var _asyncHooksInterface = require("./asyncHooksInterface");
|
9
|
+
|
10
|
+
/**
|
11
|
+
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
12
|
+
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
13
|
+
*/
|
14
|
+
const createHooks = defaultHooks => {
|
15
|
+
let currentHooks = {};
|
16
|
+
const hooks = {};
|
17
|
+
|
18
|
+
for (const key in defaultHooks) {
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
20
|
+
const f = (...args) => {
|
21
|
+
var _asyncHooks$get;
|
22
|
+
|
23
|
+
const hooks = currentHooks === defaultHooks ? (_asyncHooks$get = _asyncHooksInterface.asyncHooks === null || _asyncHooksInterface.asyncHooks === void 0 ? void 0 : _asyncHooksInterface.asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
24
|
+
let handler = hooks[key];
|
25
|
+
|
26
|
+
if (typeof handler !== 'function') {
|
27
|
+
handler = defaultHooks[key];
|
28
|
+
}
|
29
|
+
|
30
|
+
return handler(...args);
|
31
|
+
};
|
32
|
+
|
33
|
+
hooks[key] = f;
|
34
|
+
}
|
35
|
+
|
36
|
+
const run = (f, implementations) => {
|
37
|
+
try {
|
38
|
+
currentHooks = implementations || defaultHooks;
|
39
|
+
_asyncHooksInterface.asyncHooks === null || _asyncHooksInterface.asyncHooks === void 0 ? void 0 : _asyncHooksInterface.asyncHooks.set(currentHooks);
|
40
|
+
return f();
|
41
|
+
} finally {
|
42
|
+
currentHooks = defaultHooks;
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
return {
|
47
|
+
run,
|
48
|
+
hooks
|
49
|
+
};
|
50
|
+
};
|
51
|
+
|
52
|
+
exports.createHooks = createHooks;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _pipeline = require("./pipeline");
|
8
|
+
|
9
|
+
Object.keys(_pipeline).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _pipeline[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _pipeline[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
@@ -0,0 +1,129 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.createAsyncPipeline = void 0;
|
7
|
+
Object.defineProperty(exports, "createContainer", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function () {
|
10
|
+
return _context.createContainer;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
Object.defineProperty(exports, "createContext", {
|
14
|
+
enumerable: true,
|
15
|
+
get: function () {
|
16
|
+
return _context.createContext;
|
17
|
+
}
|
18
|
+
});
|
19
|
+
exports.isPipeline = exports.createPipeline = void 0;
|
20
|
+
Object.defineProperty(exports, "runWithContainer", {
|
21
|
+
enumerable: true,
|
22
|
+
get: function () {
|
23
|
+
return _context.runWithContainer;
|
24
|
+
}
|
25
|
+
});
|
26
|
+
Object.defineProperty(exports, "useContainer", {
|
27
|
+
enumerable: true,
|
28
|
+
get: function () {
|
29
|
+
return _context.useContainer;
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
var _context = require("./context");
|
34
|
+
|
35
|
+
var _counter = require("./counter");
|
36
|
+
|
37
|
+
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; }
|
38
|
+
|
39
|
+
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; }
|
40
|
+
|
41
|
+
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; }
|
42
|
+
|
43
|
+
const isPipeline = input => Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
44
|
+
|
45
|
+
exports.isPipeline = isPipeline;
|
46
|
+
const PipelineSymbol = Symbol.for('MODERN_PIPELINE');
|
47
|
+
|
48
|
+
const getMiddleware = input => {
|
49
|
+
if (typeof input === 'function') {
|
50
|
+
return input;
|
51
|
+
} else if (input && typeof input.middleware === 'function') {
|
52
|
+
return input.middleware;
|
53
|
+
}
|
54
|
+
|
55
|
+
throw new Error(`${input} is not a Middleware`);
|
56
|
+
};
|
57
|
+
|
58
|
+
const createPipeline = options => {
|
59
|
+
const config = _objectSpread({}, options);
|
60
|
+
|
61
|
+
const middlewares = [];
|
62
|
+
|
63
|
+
const use = (...inputs) => {
|
64
|
+
middlewares.push(...inputs.map(getMiddleware));
|
65
|
+
return pipeline;
|
66
|
+
};
|
67
|
+
|
68
|
+
const createCurrentCounter = (hooks, onLast, onLastWithContext) => {
|
69
|
+
return (0, _counter.createCounter)((index, input, next) => {
|
70
|
+
if (index >= middlewares.length) {
|
71
|
+
if (onLast) {
|
72
|
+
if (onLastWithContext) {
|
73
|
+
return (0, _context.runHooks)(() => onLast(input), hooks);
|
74
|
+
}
|
75
|
+
|
76
|
+
return onLast(input);
|
77
|
+
}
|
78
|
+
|
79
|
+
throw new Error(`Expect returning a value, but all middlewares just calling next()`);
|
80
|
+
}
|
81
|
+
|
82
|
+
return (0, _context.runHooks)(() => middlewares[index](input, next), hooks);
|
83
|
+
});
|
84
|
+
};
|
85
|
+
|
86
|
+
const currentContainer = (0, _context.createContainer)(config.contexts);
|
87
|
+
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
88
|
+
const currentCounter = createCurrentCounter(currentHooks);
|
89
|
+
|
90
|
+
const getCounter = options => {
|
91
|
+
if (!options) {
|
92
|
+
return currentCounter;
|
93
|
+
}
|
94
|
+
|
95
|
+
if (options !== null && options !== void 0 && options.container) {
|
96
|
+
const hooks = (0, _context.fromContainer)(options === null || options === void 0 ? void 0 : options.container);
|
97
|
+
return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
|
98
|
+
}
|
99
|
+
|
100
|
+
return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
|
101
|
+
};
|
102
|
+
|
103
|
+
const run = (input, options) => getCounter(options).start(input);
|
104
|
+
|
105
|
+
const middleware = (input, next) => {
|
106
|
+
const container = (0, _context.useContainer)();
|
107
|
+
return run(input, {
|
108
|
+
container,
|
109
|
+
onLast: next
|
110
|
+
});
|
111
|
+
};
|
112
|
+
|
113
|
+
const pipeline = {
|
114
|
+
[PipelineSymbol]: true,
|
115
|
+
use,
|
116
|
+
run,
|
117
|
+
middleware
|
118
|
+
};
|
119
|
+
return pipeline;
|
120
|
+
};
|
121
|
+
|
122
|
+
exports.createPipeline = createPipeline;
|
123
|
+
|
124
|
+
const createAsyncPipeline = options => {
|
125
|
+
const pipeline = createPipeline(options);
|
126
|
+
return _objectSpread({}, pipeline);
|
127
|
+
};
|
128
|
+
|
129
|
+
exports.createAsyncPipeline = createAsyncPipeline;
|
package/dist/js/node/index.js
CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
|
7
|
-
var _farrowPipeline = require("farrow-pipeline");
|
7
|
+
var _farrowPipeline = require("./farrow-pipeline");
|
8
8
|
|
9
9
|
Object.keys(_farrowPipeline).forEach(function (key) {
|
10
10
|
if (key === "default" || key === "__esModule") return;
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useRunner = exports.RunnerContext = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
const RunnerContext = (0, _farrowPipeline.createContext)(null);
|
11
11
|
exports.RunnerContext = RunnerContext;
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isObject = exports.hasOwnProperty = exports.generateRunner = exports.createManager = exports.closeHooksMap = exports.cloneHook = exports.DEFAULT_OPTIONS = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
var _waterfall = require("../waterfall");
|
11
11
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isAsyncWaterfall = exports.getAsyncBrook = exports.createAsyncWaterfall = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
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; }
|
11
11
|
|
@@ -13,15 +13,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
13
13
|
|
14
14
|
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; }
|
15
15
|
|
16
|
-
const ASYNC_WATERFALL_SYMBOL = Symbol('
|
16
|
+
const ASYNC_WATERFALL_SYMBOL = Symbol.for('MODERN_ASYNC_WATERFALL');
|
17
17
|
|
18
18
|
const getAsyncBrook = input => {
|
19
19
|
if (typeof input === 'function') {
|
20
20
|
return input;
|
21
21
|
} else if (input && typeof input.middleware === 'function') {
|
22
22
|
return input.middleware;
|
23
|
-
}
|
24
|
-
|
23
|
+
}
|
25
24
|
|
26
25
|
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
27
26
|
};
|
@@ -41,7 +40,6 @@ const createAsyncWaterfall = () => {
|
|
41
40
|
}));
|
42
41
|
|
43
42
|
const middleware = input => {
|
44
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
45
43
|
const container = (0, _farrowPipeline.useContainer)();
|
46
44
|
return pipeline.run(input, {
|
47
45
|
container,
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isWaterfall = exports.getBrook = exports.createWaterfall = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
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; }
|
11
11
|
|
@@ -13,15 +13,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
13
13
|
|
14
14
|
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; }
|
15
15
|
|
16
|
-
const WATERFALL_SYMBOL = Symbol('
|
16
|
+
const WATERFALL_SYMBOL = Symbol.for('MODERN_WATERFALL');
|
17
17
|
|
18
18
|
const getBrook = input => {
|
19
19
|
if (typeof input === 'function') {
|
20
20
|
return input;
|
21
21
|
} else if (input && typeof input.middleware === 'function') {
|
22
22
|
return input.middleware;
|
23
|
-
}
|
24
|
-
|
23
|
+
}
|
25
24
|
|
26
25
|
throw new Error(`${input} is not a Brook or { brook: Brook }`);
|
27
26
|
};
|
@@ -41,7 +40,6 @@ const createWaterfall = () => {
|
|
41
40
|
}));
|
42
41
|
|
43
42
|
const middleware = input => {
|
44
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
45
43
|
const container = (0, _farrowPipeline.useContainer)();
|
46
44
|
return pipeline.run(input, {
|
47
45
|
container,
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isAsyncWorkflow = exports.createAsyncWorkflow = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
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; }
|
11
11
|
|
@@ -13,7 +13,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
13
13
|
|
14
14
|
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; }
|
15
15
|
|
16
|
-
const ASYNC_WORKFLOW_SYMBOL = Symbol('
|
16
|
+
const ASYNC_WORKFLOW_SYMBOL = Symbol.for('MODERN_ASYNC_WORKFLOW');
|
17
17
|
|
18
18
|
const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]);
|
19
19
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isParallelWorkflow = exports.createParallelWorkflow = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
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; }
|
11
11
|
|
@@ -13,7 +13,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
13
13
|
|
14
14
|
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; }
|
15
15
|
|
16
|
-
const PARALLEL_WORKFLOW_SYMBOL = Symbol('
|
16
|
+
const PARALLEL_WORKFLOW_SYMBOL = Symbol.for('MODERN_PARALLEL_WORKFLOW');
|
17
17
|
|
18
18
|
const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
19
19
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.isWorkflow = exports.createWorkflow = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("farrow-pipeline");
|
8
|
+
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
10
10
|
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; }
|
11
11
|
|
@@ -13,7 +13,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
13
13
|
|
14
14
|
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; }
|
15
15
|
|
16
|
-
const WORKFLOW_SYMBOL = Symbol('
|
16
|
+
const WORKFLOW_SYMBOL = Symbol.for('MODERN_WORKFLOW');
|
17
17
|
|
18
18
|
const createWorkflow = () => {
|
19
19
|
const pipeline = (0, _farrowPipeline.createPipeline)();
|
@@ -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
|
+
var createAsyncHooks = function createAsyncHooks() {
|
9
|
+
var store = new Map(); // eslint-disable-next-line node/no-unsupported-features/node-builtins
|
10
|
+
|
11
|
+
var hooks = NodeAsyncHooks.createHook({
|
12
|
+
init: function init(asyncId, _, triggerAsyncId) {
|
13
|
+
if (store.has(triggerAsyncId)) {
|
14
|
+
var value = store.get(triggerAsyncId);
|
15
|
+
|
16
|
+
if (value) {
|
17
|
+
store.set(asyncId, value);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
},
|
21
|
+
destroy: function destroy(asyncId) {
|
22
|
+
if (store.has(asyncId)) {
|
23
|
+
store["delete"](asyncId);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
var set = function set(value) {
|
29
|
+
store.set(NodeAsyncHooks.executionAsyncId(), value);
|
30
|
+
};
|
31
|
+
|
32
|
+
var get = function get() {
|
33
|
+
return store.get(NodeAsyncHooks.executionAsyncId());
|
34
|
+
};
|
35
|
+
|
36
|
+
var clear = function clear() {
|
37
|
+
store.clear();
|
38
|
+
};
|
39
|
+
|
40
|
+
var enable = function enable() {
|
41
|
+
hooks.enable();
|
42
|
+
};
|
43
|
+
|
44
|
+
var disable = function disable() {
|
45
|
+
hooks.disable();
|
46
|
+
store.clear();
|
47
|
+
};
|
48
|
+
|
49
|
+
var entries = function entries() {
|
50
|
+
return store.entries();
|
51
|
+
};
|
52
|
+
|
53
|
+
return {
|
54
|
+
enable: enable,
|
55
|
+
disable: disable,
|
56
|
+
set: set,
|
57
|
+
get: get,
|
58
|
+
clear: clear,
|
59
|
+
entries: entries
|
60
|
+
};
|
61
|
+
};
|
62
|
+
|
63
|
+
export var enable = function enable() {
|
64
|
+
var hooks = createAsyncHooks();
|
65
|
+
disable();
|
66
|
+
asyncHooksInterface.impl(hooks);
|
67
|
+
hooks.enable();
|
68
|
+
};
|
69
|
+
export var disable = function 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 var asyncHooks;
|
7
|
+
export var impl = function impl(implimentations) {
|
8
|
+
asyncHooks = implimentations;
|
9
|
+
};
|
10
|
+
export var reset = function reset() {
|
11
|
+
asyncHooks = undefined;
|
12
|
+
};
|