@modern-js/plugin 1.3.6 → 1.4.0-alpha.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 +19 -0
- package/dist/js/modern/farrow-pipeline/context.js +14 -75
- package/dist/js/modern/farrow-pipeline/index.js +0 -14
- package/dist/js/modern/farrow-pipeline/pipeline.js +12 -29
- package/dist/js/modern/manager/async.js +9 -69
- package/dist/js/modern/manager/runner.js +1 -9
- package/dist/js/modern/manager/shared.js +44 -0
- package/dist/js/modern/manager/sync.js +12 -77
- package/dist/js/modern/waterfall/async.js +1 -3
- package/dist/js/modern/waterfall/sync.js +1 -3
- package/dist/js/modern/workflow/async.js +3 -3
- package/dist/js/modern/workflow/parallel.js +2 -2
- package/dist/js/modern/workflow/sync.js +3 -3
- package/dist/js/node/farrow-pipeline/context.js +15 -88
- package/dist/js/node/farrow-pipeline/pipeline.js +10 -45
- package/dist/js/node/manager/async.js +12 -72
- package/dist/js/node/manager/runner.js +1 -9
- package/dist/js/node/manager/shared.js +64 -0
- package/dist/js/node/manager/sync.js +19 -87
- package/dist/js/node/waterfall/async.js +0 -2
- package/dist/js/node/waterfall/sync.js +0 -2
- package/dist/js/node/workflow/async.js +3 -3
- package/dist/js/node/workflow/parallel.js +2 -2
- package/dist/js/node/workflow/sync.js +3 -3
- package/dist/js/treeshaking/farrow-pipeline/context.js +14 -75
- package/dist/js/treeshaking/farrow-pipeline/index.js +0 -14
- package/dist/js/treeshaking/farrow-pipeline/pipeline.js +10 -29
- package/dist/js/treeshaking/manager/async.js +15 -160
- package/dist/js/treeshaking/manager/runner.js +1 -7
- package/dist/js/treeshaking/manager/shared.js +79 -0
- package/dist/js/treeshaking/manager/sync.js +12 -168
- package/dist/js/treeshaking/waterfall/async.js +1 -3
- package/dist/js/treeshaking/waterfall/sync.js +1 -3
- package/dist/js/treeshaking/workflow/async.js +6 -6
- package/dist/js/treeshaking/workflow/parallel.js +5 -5
- package/dist/js/treeshaking/workflow/sync.js +8 -28
- package/dist/types/farrow-pipeline/context.d.ts +5 -20
- package/dist/types/farrow-pipeline/index.d.ts +0 -14
- package/dist/types/farrow-pipeline/pipeline.d.ts +5 -14
- package/dist/types/manager/async.d.ts +4 -7
- package/dist/types/manager/shared.d.ts +12 -0
- package/dist/types/manager/sync.d.ts +5 -11
- package/dist/types/manager/types.d.ts +1 -6
- package/dist/types/waterfall/async.d.ts +1 -7
- package/dist/types/waterfall/sync.d.ts +0 -7
- package/dist/types/workflow/async.d.ts +1 -7
- package/dist/types/workflow/parallel.d.ts +2 -9
- package/dist/types/workflow/sync.d.ts +1 -10
- package/package.json +1 -12
- package/dist/js/modern/farrow-pipeline/asyncHooks.node.js +0 -74
- package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/modern/farrow-pipeline/hook.js +0 -42
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -93
- package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
- package/dist/js/node/farrow-pipeline/hook.js +0 -52
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -74
- package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
- package/dist/types/farrow-pipeline/asyncHooks.node.d.ts +0 -2
- package/dist/types/farrow-pipeline/asyncHooksInterface.d.ts +0 -19
- package/dist/types/farrow-pipeline/hook.d.ts +0 -9
@@ -1,4 +1,3 @@
|
|
1
|
-
import { Container } from '../farrow-pipeline';
|
2
1
|
declare const WATERFALL_SYMBOL: unique symbol;
|
3
2
|
export declare type Brook<I = unknown> = (I: I) => I;
|
4
3
|
export declare type BrookInput<I = unknown> = Brook<I> | {
|
@@ -8,7 +7,6 @@ export declare type Brooks<I = unknown> = Brook<I>[];
|
|
8
7
|
export declare type BrookInputs<I = unknown> = BrookInput<I>[];
|
9
8
|
export declare const getBrook: <I>(input: BrookInput<I>) => Brook<I>;
|
10
9
|
export declare type RunWaterfallOptions<I = unknown> = {
|
11
|
-
container?: Container;
|
12
10
|
onLast?: Brook<I>;
|
13
11
|
};
|
14
12
|
export declare type Waterfall<I = void> = {
|
@@ -17,11 +15,6 @@ export declare type Waterfall<I = void> = {
|
|
17
15
|
middleware: Brook<I>;
|
18
16
|
[WATERFALL_SYMBOL]: true;
|
19
17
|
};
|
20
|
-
export declare type Waterfall2Brook<P extends Waterfall<any>> = P extends Waterfall<infer I> ? Brook<I> : never;
|
21
|
-
export declare type WaterfallRecord = Record<string, Waterfall<any>>;
|
22
|
-
export declare type Waterfalls2Brooks<PS extends WaterfallRecord | void> = { [K in keyof PS]: PS[K] extends Waterfall<any> ? Waterfall2Brook<PS[K]> : PS[K] extends void ? void : never };
|
23
|
-
export declare type RunnerFromWaterfall<M extends Waterfall<any>> = M extends Waterfall<infer VS> ? Waterfall<VS>['run'] : never;
|
24
|
-
export declare type Waterfalls2Runners<PS extends WaterfallRecord | void> = { [K in keyof PS]: PS[K] extends Waterfall<any> ? RunnerFromWaterfall<PS[K]> : PS[K] extends void ? void : never };
|
25
18
|
export declare const createWaterfall: <I = void>() => Waterfall<I>;
|
26
19
|
export declare const isWaterfall: (input: any) => input is Waterfall<any>;
|
27
20
|
export {};
|
@@ -1,18 +1,12 @@
|
|
1
1
|
import { MaybeAsync } from '../farrow-pipeline';
|
2
|
-
import type { RunWorkflowOptions } from './sync';
|
3
2
|
declare const ASYNC_WORKFLOW_SYMBOL: unique symbol;
|
4
3
|
export declare type AsyncWorker<I, O> = (I: I) => MaybeAsync<O>;
|
5
4
|
export declare type AsyncWorkers<I, O> = AsyncWorker<I, O>[];
|
6
5
|
export declare type AsyncWorkflow<I, O> = {
|
7
|
-
run: (input: I
|
6
|
+
run: (input: I) => MaybeAsync<O[]>;
|
8
7
|
use: (...I: AsyncWorkers<I, O>) => AsyncWorkflow<I, O>;
|
9
8
|
[ASYNC_WORKFLOW_SYMBOL]: true;
|
10
9
|
};
|
11
|
-
export declare type AsyncWorkflow2AsyncWorker<W extends AsyncWorkflow<any, any>> = W extends AsyncWorkflow<infer I, infer O> ? AsyncWorker<I, O> : never;
|
12
|
-
export declare type AsyncWorkflowRecord = Record<string, AsyncWorkflow<any, any>>;
|
13
|
-
export declare type AsyncWorkflows2AsyncWorkers<PS extends AsyncWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWorkflow<any, any> ? AsyncWorkflow2AsyncWorker<PS[K]> : PS[K] extends void ? void : never };
|
14
|
-
export declare type RunnerFromAsyncWorkflow<W extends AsyncWorkflow<any, any>> = W extends AsyncWorkflow<infer I, infer O> ? AsyncWorkflow<I, O>['run'] : never;
|
15
|
-
export declare type AsyncWorkflows2Runners<PS extends AsyncWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends AsyncWorkflow<any, any> ? RunnerFromAsyncWorkflow<PS[K]> : PS[K] extends void ? void : never };
|
16
10
|
export declare const isAsyncWorkflow: (input: any) => input is AsyncWorkflow<any, any>;
|
17
11
|
export declare const createAsyncWorkflow: <I = void, O = unknown>() => AsyncWorkflow<I, O>;
|
18
12
|
export {};
|
@@ -1,17 +1,10 @@
|
|
1
|
-
import type {
|
2
|
-
import type { RunWorkflowOptions } from './sync';
|
1
|
+
import type { AsyncWorkers } from './async';
|
3
2
|
declare const PARALLEL_WORKFLOW_SYMBOL: unique symbol;
|
4
3
|
export declare type ParallelWorkflow<I, O = any> = {
|
5
|
-
run: (input: I
|
4
|
+
run: (input: I) => Promise<O[]>;
|
6
5
|
use: (...I: AsyncWorkers<I, O>) => ParallelWorkflow<I, O>;
|
7
6
|
[PARALLEL_WORKFLOW_SYMBOL]: true;
|
8
7
|
};
|
9
|
-
export declare type ParallelWorkflow2Worker<W extends ParallelWorkflow<any>> = W extends ParallelWorkflow<infer CS, infer O> ? AsyncWorker<CS, O> : never;
|
10
|
-
export declare type ParallelWorkflowRecord = Record<string, ParallelWorkflow<any>>;
|
11
|
-
export declare type ParallelWorkflows2Workers<PS extends ParallelWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends ParallelWorkflow<any> ? ParallelWorkflow2Worker<PS[K]> : PS[K] extends void ? void : never };
|
12
|
-
export declare type ParallelWorkflows2AsyncWorkers<PS extends ParallelWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends ParallelWorkflow<any> ? ParallelWorkflow2Worker<PS[K]> : PS[K] extends void ? void : never };
|
13
|
-
export declare type RunnerFromParallelWorkflow<W extends ParallelWorkflow<any>> = W extends ParallelWorkflow<infer CS, infer O> ? ParallelWorkflow<CS, O>['run'] : never;
|
14
|
-
export declare type ParallelWorkflows2Runners<PS extends ParallelWorkflowRecord | void> = { [K in keyof PS]: PS[K] extends ParallelWorkflow<any> ? RunnerFromParallelWorkflow<PS[K]> : PS[K] extends void ? void : never };
|
15
8
|
export declare const isParallelWorkflow: (input: any) => input is ParallelWorkflow<any, any>;
|
16
9
|
export declare const createParallelWorkflow: <I = void, O = unknown>() => ParallelWorkflow<I, O>;
|
17
10
|
export {};
|
@@ -1,20 +1,11 @@
|
|
1
|
-
import { Container } from '../farrow-pipeline';
|
2
1
|
declare const WORKFLOW_SYMBOL: unique symbol;
|
3
2
|
export declare type Worker<I, O> = (I: I) => O;
|
4
3
|
export declare type Workers<I, O> = Worker<I, O>[];
|
5
|
-
export declare type RunWorkflowOptions = {
|
6
|
-
container?: Container;
|
7
|
-
};
|
8
4
|
export declare type Workflow<I, O> = {
|
9
|
-
run: (input: I
|
5
|
+
run: (input: I) => void;
|
10
6
|
use: (...I: Workers<I, O>) => Workflow<I, O>;
|
11
7
|
[WORKFLOW_SYMBOL]: true;
|
12
8
|
};
|
13
|
-
export declare type Workflow2Worker<W extends Workflow<any, any>> = W extends Workflow<infer I, infer O> ? Worker<I, O> : never;
|
14
|
-
export declare type WorkflowRecord = Record<string, Workflow<any, any>>;
|
15
|
-
export declare type Workflows2Workers<PS extends WorkflowRecord | void> = { [K in keyof PS]: PS[K] extends Workflow<any, any> ? Workflow2Worker<PS[K]> : PS[K] extends void ? void : never };
|
16
|
-
export declare type RunnerFromWorkflow<W extends Workflow<any, any>> = W extends Workflow<infer I, infer O> ? Workflow<I, O>['run'] : never;
|
17
|
-
export declare type Workflows2Runners<PS extends WorkflowRecord | void> = { [K in keyof PS]: PS[K] extends Workflow<any, any> ? RunnerFromWorkflow<PS[K]> : PS[K] extends void ? void : never };
|
18
9
|
export declare const createWorkflow: <I = void, O = unknown>() => Workflow<I, O>;
|
19
10
|
export declare const isWorkflow: (input: any) => input is Workflow<unknown, unknown>;
|
20
11
|
export {};
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.4.0-alpha.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -25,17 +25,6 @@
|
|
25
25
|
"require": "./dist/js/node/index.js"
|
26
26
|
},
|
27
27
|
"default": "./dist/js/treeshaking/index.js"
|
28
|
-
},
|
29
|
-
"./node": {
|
30
|
-
"jsnext:source": "./src/farrow-pipeline/asyncHooks.node.ts",
|
31
|
-
"default": "./dist/js/node/farrow-pipeline/asyncHooks.node.js"
|
32
|
-
}
|
33
|
-
},
|
34
|
-
"typesVersions": {
|
35
|
-
"*": {
|
36
|
-
"node": [
|
37
|
-
"./dist/types/farrow-pipeline/asyncHooks.node.d.ts"
|
38
|
-
]
|
39
28
|
}
|
40
29
|
},
|
41
30
|
"dependencies": {
|
@@ -1,74 +0,0 @@
|
|
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
|
-
};
|
@@ -1,12 +0,0 @@
|
|
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
|
-
};
|
@@ -1,42 +0,0 @@
|
|
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
|
-
};
|
@@ -1,93 +0,0 @@
|
|
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;
|
@@ -1,26 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.reset = exports.impl = exports.asyncHooks = 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
|
-
// eslint-disable-next-line import/no-mutable-exports
|
13
|
-
let asyncHooks;
|
14
|
-
exports.asyncHooks = asyncHooks;
|
15
|
-
|
16
|
-
const impl = implimentations => {
|
17
|
-
exports.asyncHooks = asyncHooks = implimentations;
|
18
|
-
};
|
19
|
-
|
20
|
-
exports.impl = impl;
|
21
|
-
|
22
|
-
const reset = () => {
|
23
|
-
exports.asyncHooks = asyncHooks = undefined;
|
24
|
-
};
|
25
|
-
|
26
|
-
exports.reset = reset;
|
@@ -1,52 +0,0 @@
|
|
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;
|
@@ -1,74 +0,0 @@
|
|
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
|
-
};
|
@@ -1,12 +0,0 @@
|
|
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
|
-
};
|
@@ -1,46 +0,0 @@
|
|
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 var createHooks = function createHooks(defaultHooks) {
|
7
|
-
var currentHooks = {};
|
8
|
-
var hooks = {};
|
9
|
-
|
10
|
-
var _loop = function _loop(key) {
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-loop-func
|
12
|
-
var f = function f() {
|
13
|
-
var _asyncHooks$get;
|
14
|
-
|
15
|
-
var hooks = currentHooks === defaultHooks ? (_asyncHooks$get = asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.get()) !== null && _asyncHooks$get !== void 0 ? _asyncHooks$get : defaultHooks : currentHooks;
|
16
|
-
var handler = hooks[key];
|
17
|
-
|
18
|
-
if (typeof handler !== 'function') {
|
19
|
-
handler = defaultHooks[key];
|
20
|
-
}
|
21
|
-
|
22
|
-
return handler.apply(void 0, arguments);
|
23
|
-
};
|
24
|
-
|
25
|
-
hooks[key] = f;
|
26
|
-
};
|
27
|
-
|
28
|
-
for (var key in defaultHooks) {
|
29
|
-
_loop(key);
|
30
|
-
}
|
31
|
-
|
32
|
-
var run = function run(f, implementations) {
|
33
|
-
try {
|
34
|
-
currentHooks = implementations || defaultHooks;
|
35
|
-
asyncHooks === null || asyncHooks === void 0 ? void 0 : asyncHooks.set(currentHooks);
|
36
|
-
return f();
|
37
|
-
} finally {
|
38
|
-
currentHooks = defaultHooks;
|
39
|
-
}
|
40
|
-
};
|
41
|
-
|
42
|
-
return {
|
43
|
-
run: run,
|
44
|
-
hooks: hooks
|
45
|
-
};
|
46
|
-
};
|
@@ -1,19 +0,0 @@
|
|
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 declare type AnyFn = (...args: any) => any;
|
6
|
-
export declare type Hooks = {
|
7
|
-
[key: string]: AnyFn;
|
8
|
-
};
|
9
|
-
export declare type AsyncHooks = {
|
10
|
-
enable: () => void;
|
11
|
-
disable: () => void;
|
12
|
-
set: (value: Hooks) => void;
|
13
|
-
get: () => Hooks | undefined;
|
14
|
-
clear: () => void;
|
15
|
-
entries: () => IterableIterator<[number, Hooks]>;
|
16
|
-
} | undefined;
|
17
|
-
export declare let asyncHooks: AsyncHooks;
|
18
|
-
export declare const impl: (implimentations: AsyncHooks) => void;
|
19
|
-
export declare const reset: () => void;
|
@@ -1,9 +0,0 @@
|
|
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 { Hooks, AnyFn } from './asyncHooksInterface';
|
6
|
-
export declare const createHooks: <HS extends Hooks>(defaultHooks: HS) => {
|
7
|
-
run: <F extends AnyFn>(f: F, implementations: HS) => ReturnType<F>;
|
8
|
-
hooks: HS;
|
9
|
-
};
|