@modern-js/plugin 1.0.1 → 1.2.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 +20 -2
- package/dist/js/modern/index.js +2 -3
- package/dist/js/modern/manager/async.js +3 -3
- package/dist/js/modern/manager/runner.js +1 -1
- package/dist/js/modern/manager/sync.js +3 -8
- package/dist/js/modern/waterfall/async.js +28 -34
- package/dist/js/modern/waterfall/sync.js +29 -36
- package/dist/js/modern/workflow/async.js +31 -30
- package/dist/js/modern/workflow/parallel.js +20 -29
- package/dist/js/modern/workflow/sync.js +20 -27
- package/dist/js/node/index.js +12 -25
- package/dist/js/node/manager/async.js +6 -6
- package/dist/js/node/manager/runner.js +2 -2
- package/dist/js/node/manager/sync.js +8 -14
- package/dist/js/node/waterfall/async.js +27 -34
- package/dist/js/node/waterfall/sync.js +29 -36
- package/dist/js/node/workflow/async.js +30 -30
- package/dist/js/node/workflow/parallel.js +19 -29
- package/dist/js/node/workflow/sync.js +19 -27
- package/dist/js/treeshaking/index.js +2 -3
- package/dist/js/treeshaking/manager/async.js +3 -3
- package/dist/js/treeshaking/manager/runner.js +1 -1
- package/dist/js/treeshaking/manager/sync.js +3 -8
- package/dist/js/treeshaking/waterfall/async.js +63 -108
- package/dist/js/treeshaking/waterfall/sync.js +36 -39
- package/dist/js/treeshaking/workflow/async.js +89 -88
- package/dist/js/treeshaking/workflow/parallel.js +42 -66
- package/dist/js/treeshaking/workflow/sync.js +50 -30
- package/dist/types/index.d.ts +2 -3
- package/dist/types/manager/runner.d.ts +1 -1
- package/dist/types/manager/sync.d.ts +2 -3
- package/dist/types/waterfall/async.d.ts +9 -5
- package/dist/types/waterfall/sync.d.ts +4 -4
- package/dist/types/workflow/async.d.ts +3 -2
- package/dist/types/workflow/parallel.d.ts +1 -1
- package/dist/types/workflow/sync.d.ts +1 -1
- package/jest.config.js +8 -0
- package/modern.config.js +1 -9
- package/node.d.ts +1 -1
- package/node.js +1 -1
- package/package.json +13 -7
- package/src/index.ts +2 -2
- package/src/manager/async.ts +1 -1
- package/src/manager/runner.ts +1 -1
- package/src/manager/sync.ts +12 -16
- package/src/waterfall/async.ts +34 -49
- package/src/waterfall/sync.ts +26 -45
- package/src/workflow/async.ts +29 -33
- package/src/workflow/parallel.ts +17 -35
- package/src/workflow/sync.ts +13 -35
- package/tests/async.test.ts +14 -10
- package/tests/fixtures/async/base/fooManager.ts +1 -1
- package/tests/fixtures/async/core/index.ts +1 -1
- package/tests/fixtures/async/dynamic/foo.ts +1 -1
- package/tests/fixtures/sync/base/fooManager.ts +1 -1
- package/tests/fixtures/sync/core/index.ts +1 -1
- package/tests/fixtures/sync/dynamic/foo.ts +1 -1
- package/tests/pipeline.test.ts +6 -16
- package/tests/sync.test.ts +13 -9
- package/tests/tsconfig.json +1 -3
- package/tests/waterfall.test.ts +3 -3
- package/tests/workflow.test.ts +2 -2
- package/tsconfig.json +1 -3
- package/dist/js/modern/asyncHooksImpl.js +0 -63
- package/dist/js/modern/asyncHooksInterface.js +0 -16
- package/dist/js/modern/context.js +0 -130
- package/dist/js/modern/counter.js +0 -40
- package/dist/js/modern/hook.js +0 -47
- package/dist/js/modern/pipeline/async.js +0 -97
- package/dist/js/modern/pipeline/index.js +0 -2
- package/dist/js/modern/pipeline/sync.js +0 -97
- package/dist/js/node/asyncHooksImpl.js +0 -82
- package/dist/js/node/asyncHooksInterface.js +0 -30
- package/dist/js/node/context.js +0 -164
- package/dist/js/node/counter.js +0 -52
- package/dist/js/node/hook.js +0 -57
- package/dist/js/node/pipeline/async.js +0 -110
- package/dist/js/node/pipeline/index.js +0 -31
- package/dist/js/node/pipeline/sync.js +0 -110
- package/dist/js/treeshaking/asyncHooksImpl.js +0 -65
- package/dist/js/treeshaking/asyncHooksInterface.js +0 -16
- package/dist/js/treeshaking/context.js +0 -137
- package/dist/js/treeshaking/counter.js +0 -74
- package/dist/js/treeshaking/hook.js +0 -51
- package/dist/js/treeshaking/pipeline/async.js +0 -165
- package/dist/js/treeshaking/pipeline/index.js +0 -2
- package/dist/js/treeshaking/pipeline/sync.js +0 -118
- package/dist/types/asyncHooksImpl.d.ts +0 -10
- package/dist/types/asyncHooksInterface.d.ts +0 -21
- package/dist/types/context.d.ts +0 -47
- package/dist/types/counter.d.ts +0 -22
- package/dist/types/hook.d.ts +0 -13
- package/dist/types/pipeline/async.d.ts +0 -35
- package/dist/types/pipeline/index.d.ts +0 -2
- package/dist/types/pipeline/sync.d.ts +0 -37
- package/src/asyncHooksImpl.ts +0 -64
- package/src/asyncHooksInterface.ts +0 -34
- package/src/context.ts +0 -184
- package/src/counter.ts +0 -78
- package/src/hook.ts +0 -46
- package/src/pipeline/async.ts +0 -155
- package/src/pipeline/index.ts +0 -2
- package/src/pipeline/sync.ts +0 -152
- package/tests/context.test.ts +0 -114
- package/tests/counter.test.ts +0 -31
- package/tests/hook.test.ts +0 -113
package/CHANGELOG.md
CHANGED
@@ -1,10 +1,28 @@
|
|
1
1
|
# @modern-js/plugin
|
2
2
|
|
3
|
-
## 1.0
|
3
|
+
## 1.2.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- cfe11628: Make Modern.js self bootstraping
|
8
|
+
|
9
|
+
## 1.1.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 0fa83663: support more .env files
|
14
|
+
|
15
|
+
## 1.1.1
|
4
16
|
|
5
17
|
### Patch Changes
|
6
18
|
|
7
|
-
-
|
19
|
+
- 6ffd1a50: Refactor to base on farrow-pipeline
|
20
|
+
|
21
|
+
## 1.1.0
|
22
|
+
|
23
|
+
### Minor Changes
|
24
|
+
|
25
|
+
- 96119db2: Relese v1.1.0
|
8
26
|
|
9
27
|
## 1.0.0
|
10
28
|
|
package/dist/js/modern/index.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
2
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
4
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
6
|
|
7
|
-
import { runWithContainer, createContainer } from
|
7
|
+
import { runWithContainer, createContainer } from 'farrow-pipeline';
|
8
8
|
import { generateRunner, hasOwnProperty, DEFAULT_OPTIONS } from "./sync";
|
9
9
|
import { useRunner } from "./runner"; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
10
10
|
|
@@ -1,16 +1,15 @@
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
2
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
4
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6
6
|
|
7
7
|
// eslint-disable-next-line eslint-comments/disable-enable-pair
|
8
8
|
|
9
9
|
/* eslint-disable max-lines */
|
10
|
-
import { runWithContainer, createContainer } from
|
10
|
+
import { isPipeline, createPipeline, runWithContainer, createContainer } from 'farrow-pipeline';
|
11
11
|
import { isWaterfall, createWaterfall, isAsyncWaterfall, createAsyncWaterfall } from "../waterfall";
|
12
12
|
import { isWorkflow, createWorkflow, isAsyncWorkflow, createAsyncWorkflow, isParallelWorkflow, createParallelWorkflow } from "../workflow";
|
13
|
-
import { isPipeline, createPipeline, isAsyncPipeline, createAsyncPipeline } from "../pipeline";
|
14
13
|
import { RunnerContext, useRunner } from "./runner"; // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
15
14
|
|
16
15
|
const SYNC_PLUGIN_SYMBOL = 'SYNC_PLUGIN_SYMBOL';
|
@@ -155,10 +154,6 @@ export const cloneProgress = progress => {
|
|
155
154
|
|
156
155
|
if (isPipeline(progress)) {
|
157
156
|
return createPipeline();
|
158
|
-
}
|
159
|
-
|
160
|
-
if (isAsyncPipeline(progress)) {
|
161
|
-
return createAsyncPipeline();
|
162
157
|
} // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
163
158
|
|
164
159
|
|
@@ -1,11 +1,16 @@
|
|
1
|
-
|
2
|
-
|
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, useContainer } from 'farrow-pipeline';
|
3
8
|
const ASYNC_WATERFALL_SYMBOL = Symbol('ASYNC_WATERFALL_SYMBOL');
|
4
9
|
export const getAsyncBrook = input => {
|
5
10
|
if (typeof input === 'function') {
|
6
11
|
return input;
|
7
|
-
} else if (input && typeof input.
|
8
|
-
return input.
|
12
|
+
} else if (input && typeof input.middlware === 'function') {
|
13
|
+
return input.middlware;
|
9
14
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
10
15
|
|
11
16
|
|
@@ -13,48 +18,37 @@ export const getAsyncBrook = input => {
|
|
13
18
|
};
|
14
19
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
15
20
|
export const createAsyncWaterfall = () => {
|
16
|
-
const
|
17
|
-
|
18
|
-
const createCurrentRunner = hooks => createAsyncCounter(async (index, input, next) => {
|
19
|
-
if (index >= middlewares.length) {
|
20
|
-
return input;
|
21
|
-
}
|
22
|
-
|
23
|
-
return runHooks(async () => next((await middlewares[index](input)) || input), hooks);
|
24
|
-
});
|
25
|
-
|
26
|
-
const currentContainer = createContainer();
|
27
|
-
const currentHooks = fromContainer(currentContainer);
|
28
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
21
|
+
const pipeline = createAsyncPipeline();
|
29
22
|
|
30
23
|
const use = (...input) => {
|
31
|
-
|
24
|
+
pipeline.use(...input.map(getAsyncBrook).map(mapAsyncBrookToAsyncMiddleware));
|
32
25
|
return waterfall;
|
33
26
|
};
|
34
27
|
|
35
|
-
const run =
|
36
|
-
|
28
|
+
const run = (input, options) => // eslint-disable-next-line @typescript-eslint/no-shadow
|
29
|
+
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
30
|
+
onLast: input => input
|
31
|
+
}));
|
37
32
|
|
38
|
-
|
39
|
-
const hooks = container === currentContainer ? currentHooks : fromContainer(container);
|
40
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
41
|
-
return runner.start(input);
|
42
|
-
};
|
43
|
-
|
44
|
-
const brook = input => {
|
33
|
+
const middlware = input => {
|
45
34
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
46
|
-
const container = useContainer();
|
47
|
-
|
48
|
-
|
35
|
+
const container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
36
|
+
|
37
|
+
return pipeline.run(input, {
|
38
|
+
container,
|
39
|
+
onLast: input => input
|
49
40
|
});
|
50
41
|
};
|
51
42
|
|
52
|
-
const waterfall = {
|
43
|
+
const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
|
53
44
|
use,
|
54
45
|
run,
|
55
|
-
|
46
|
+
middlware,
|
56
47
|
[ASYNC_WATERFALL_SYMBOL]: true
|
57
|
-
};
|
48
|
+
});
|
49
|
+
|
58
50
|
return waterfall;
|
59
51
|
};
|
60
|
-
export const isAsyncWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
52
|
+
export const isAsyncWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
53
|
+
|
54
|
+
const mapAsyncBrookToAsyncMiddleware = brook => async (input, next) => next(await brook(input));
|
@@ -1,12 +1,16 @@
|
|
1
|
-
|
2
|
-
import { runHooks, fromContainer, createContainer, useContainer } from "../context";
|
3
|
-
const WATERFALL_SYMBOL = Symbol('WATERFALL_SYMBOL'); // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
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; }
|
4
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 { useContainer, createPipeline } from 'farrow-pipeline';
|
8
|
+
const WATERFALL_SYMBOL = Symbol('WATERFALL_SYMBOL');
|
5
9
|
export const getBrook = input => {
|
6
10
|
if (typeof input === 'function') {
|
7
11
|
return input;
|
8
|
-
} else if (input && typeof input.
|
9
|
-
return input.
|
12
|
+
} else if (input && typeof input.middleware === 'function') {
|
13
|
+
return input.middleware;
|
10
14
|
} // eslint-disable-next-line @typescript-eslint/no-base-to-string,@typescript-eslint/restrict-template-expressions
|
11
15
|
|
12
16
|
|
@@ -14,48 +18,37 @@ export const getBrook = input => {
|
|
14
18
|
};
|
15
19
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
16
20
|
export const createWaterfall = () => {
|
17
|
-
const
|
21
|
+
const pipeline = createPipeline();
|
18
22
|
|
19
|
-
const
|
20
|
-
|
21
|
-
return input;
|
22
|
-
}
|
23
|
-
|
24
|
-
return runHooks(() => next(middlewares[index](input) || input), hooks);
|
25
|
-
});
|
26
|
-
|
27
|
-
const currentContainer = createContainer();
|
28
|
-
const currentHooks = fromContainer(currentContainer);
|
29
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
30
|
-
|
31
|
-
const use = (...input) => {
|
32
|
-
middlewares.push(...input.map(getBrook));
|
23
|
+
const use = (...brooks) => {
|
24
|
+
pipeline.use(...brooks.map(getBrook).map(mapBrookToMiddleware));
|
33
25
|
return waterfall;
|
34
26
|
};
|
35
27
|
|
36
|
-
const run = (input, options) =>
|
37
|
-
|
28
|
+
const run = (input, options) => // eslint-disable-next-line @typescript-eslint/no-shadow
|
29
|
+
pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
30
|
+
onLast: input => input
|
31
|
+
}));
|
38
32
|
|
39
|
-
|
40
|
-
const hooks = container === currentContainer ? currentHooks : fromContainer(container);
|
41
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
42
|
-
return runner.start(input);
|
43
|
-
};
|
44
|
-
|
45
|
-
const brook = input => {
|
33
|
+
const middleware = input => {
|
46
34
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
47
|
-
const container = useContainer();
|
48
|
-
|
49
|
-
|
35
|
+
const container = useContainer(); // eslint-disable-next-line @typescript-eslint/no-shadow
|
36
|
+
|
37
|
+
return pipeline.run(input, {
|
38
|
+
container,
|
39
|
+
onLast: input => input
|
50
40
|
});
|
51
41
|
};
|
52
42
|
|
53
|
-
const waterfall = {
|
43
|
+
const waterfall = _objectSpread(_objectSpread({}, pipeline), {}, {
|
54
44
|
use,
|
55
45
|
run,
|
56
|
-
|
46
|
+
middleware,
|
57
47
|
[WATERFALL_SYMBOL]: true
|
58
|
-
};
|
48
|
+
});
|
49
|
+
|
59
50
|
return waterfall;
|
60
51
|
};
|
61
|
-
export const isWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
52
|
+
export const isWaterfall = input => Boolean(input === null || input === void 0 ? void 0 : input[WATERFALL_SYMBOL]);
|
53
|
+
|
54
|
+
const mapBrookToMiddleware = brook => (input, next) => next(brook(input));
|
@@ -1,46 +1,47 @@
|
|
1
|
-
|
2
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
3
|
-
const ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
|
4
|
-
export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]); // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
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; }
|
5
2
|
|
6
|
-
|
7
|
-
const middlewares = [];
|
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; }
|
8
4
|
|
9
|
-
|
10
|
-
if (index >= middlewares.length) {
|
11
|
-
return [];
|
12
|
-
}
|
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; }
|
13
6
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
const rest = await next(input);
|
18
|
-
return [result, ...rest];
|
19
|
-
}, hooks);
|
20
|
-
});
|
7
|
+
import { createAsyncPipeline } from 'farrow-pipeline';
|
8
|
+
const ASYNC_WORKFLOW_SYMBOL = Symbol('ASYNC_WORKFLOW_SYMBOL');
|
9
|
+
export const isAsyncWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[ASYNC_WORKFLOW_SYMBOL]); // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
21
10
|
|
22
|
-
|
23
|
-
const
|
24
|
-
const currentRunner = createCurrentRunner(currentHooks);
|
11
|
+
export const createAsyncWorkflow = () => {
|
12
|
+
const pipeline = createAsyncPipeline();
|
25
13
|
|
26
14
|
const use = (...input) => {
|
27
|
-
|
15
|
+
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
28
16
|
return workflow;
|
29
17
|
};
|
30
18
|
|
31
19
|
const run = async (input, options) => {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
20
|
+
const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
21
|
+
onLast: () => []
|
22
|
+
}));
|
23
|
+
|
24
|
+
if (isPromise(result)) {
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow,promise/prefer-await-to-then
|
26
|
+
return result.then(result => result.filter(Boolean));
|
27
|
+
} else {
|
28
|
+
return result.filter(Boolean);
|
29
|
+
}
|
38
30
|
};
|
39
31
|
|
40
|
-
const workflow = {
|
32
|
+
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
41
33
|
use,
|
42
34
|
run,
|
43
35
|
[ASYNC_WORKFLOW_SYMBOL]: true
|
44
|
-
};
|
36
|
+
});
|
37
|
+
|
45
38
|
return workflow;
|
46
|
-
};
|
39
|
+
};
|
40
|
+
|
41
|
+
const mapAsyncWorkerToAsyncMiddleware = worker => async (input, next) => [await worker(input), ...(await next(input))];
|
42
|
+
|
43
|
+
function isPromise(obj) {
|
44
|
+
/* eslint-disable promise/prefer-await-to-then */
|
45
|
+
return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
46
|
+
/* eslint-enable promise/prefer-await-to-then */
|
47
|
+
}
|
@@ -1,41 +1,32 @@
|
|
1
|
-
|
2
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
3
|
-
const PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
|
4
|
-
export const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
5
|
-
export const createParallelWorkflow = () => {
|
6
|
-
const middlewares = [];
|
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; }
|
7
2
|
|
8
|
-
|
9
|
-
if (index >= middlewares.length) {
|
10
|
-
return Promise.resolve([]);
|
11
|
-
}
|
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; }
|
12
4
|
|
13
|
-
|
14
|
-
return runHooks(async () => Promise.all([middleware(input), ...(await next(input))]), hooks);
|
15
|
-
});
|
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; }
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
import { createPipeline } from 'farrow-pipeline';
|
8
|
+
const PARALLEL_WORKFLOW_SYMBOL = Symbol('PARALLEL_WORKFLOW_SYMBOL');
|
9
|
+
export const isParallelWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[PARALLEL_WORKFLOW_SYMBOL]);
|
10
|
+
export const createParallelWorkflow = () => {
|
11
|
+
const pipeline = createPipeline();
|
20
12
|
|
21
13
|
const use = (...input) => {
|
22
|
-
|
14
|
+
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
23
15
|
return workflow;
|
24
16
|
};
|
25
17
|
|
26
|
-
const run = async (input, options) =>
|
27
|
-
|
18
|
+
const run = async (input, options) => // eslint-disable-next-line promise/prefer-await-to-then
|
19
|
+
Promise.all(pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
20
|
+
onLast: () => []
|
21
|
+
}))).then(result => result.filter(Boolean));
|
28
22
|
|
29
|
-
|
30
|
-
const hooks = container === currentContainer ? currentHooks : fromContainer(container);
|
31
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
32
|
-
return runner.start(input);
|
33
|
-
};
|
34
|
-
|
35
|
-
const workflow = {
|
36
|
-
use,
|
23
|
+
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
37
24
|
run,
|
25
|
+
use,
|
38
26
|
[PARALLEL_WORKFLOW_SYMBOL]: true
|
39
|
-
};
|
27
|
+
});
|
28
|
+
|
40
29
|
return workflow;
|
41
|
-
};
|
30
|
+
};
|
31
|
+
|
32
|
+
const mapParallelWorkerToAsyncMiddleware = worker => (input, next) => [worker(input), ...next(input)];
|
@@ -1,42 +1,35 @@
|
|
1
|
-
|
2
|
-
import { runHooks, fromContainer, createContainer } from "../context";
|
3
|
-
const WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
5
|
-
export const createWorkflow = () => {
|
6
|
-
const middlewares = [];
|
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; }
|
7
2
|
|
8
|
-
|
9
|
-
if (index >= middlewares.length) {
|
10
|
-
return [];
|
11
|
-
}
|
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; }
|
12
4
|
|
13
|
-
|
14
|
-
return runHooks(() => [middleware(input), ...next(input)], hooks);
|
15
|
-
});
|
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; }
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
import { createPipeline } from 'farrow-pipeline';
|
8
|
+
const WORKFLOW_SYMBOL = Symbol('WORKFLOW_SYMBOL');
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
10
|
+
export const createWorkflow = () => {
|
11
|
+
const pipeline = createPipeline();
|
20
12
|
|
21
13
|
const use = (...input) => {
|
22
|
-
|
14
|
+
pipeline.use(...input.map(mapWorkerToMiddleware));
|
23
15
|
return workflow;
|
24
16
|
};
|
25
17
|
|
26
|
-
const run = (input, options) => {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
const runner = container === currentContainer ? currentRunner : createCurrentRunner(hooks);
|
32
|
-
return runner.start(input);
|
18
|
+
const run = async (input, options) => {
|
19
|
+
const result = pipeline.run(input, _objectSpread(_objectSpread({}, options), {}, {
|
20
|
+
onLast: () => []
|
21
|
+
}));
|
22
|
+
return result.filter(Boolean);
|
33
23
|
};
|
34
24
|
|
35
|
-
const workflow = {
|
25
|
+
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
36
26
|
use,
|
37
27
|
run,
|
38
28
|
[WORKFLOW_SYMBOL]: true
|
39
|
-
};
|
29
|
+
});
|
30
|
+
|
40
31
|
return workflow;
|
41
32
|
};
|
42
|
-
export const isWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
33
|
+
export const isWorkflow = input => Boolean(input === null || input === void 0 ? void 0 : input[WORKFLOW_SYMBOL]);
|
34
|
+
|
35
|
+
const mapWorkerToMiddleware = worker => (input, next) => [worker(input), ...next(input)];
|
package/dist/js/node/index.js
CHANGED
@@ -4,41 +4,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
|
7
|
-
var
|
7
|
+
var _farrowPipeline = require("farrow-pipeline");
|
8
8
|
|
9
|
-
Object.keys(
|
9
|
+
Object.keys(_farrowPipeline).forEach(function (key) {
|
10
10
|
if (key === "default" || key === "__esModule") return;
|
11
|
-
if (key in exports && exports[key] ===
|
11
|
+
if (key in exports && exports[key] === _farrowPipeline[key]) return;
|
12
12
|
Object.defineProperty(exports, key, {
|
13
13
|
enumerable: true,
|
14
14
|
get: function () {
|
15
|
-
return
|
15
|
+
return _farrowPipeline[key];
|
16
16
|
}
|
17
17
|
});
|
18
18
|
});
|
19
19
|
|
20
|
-
var
|
20
|
+
var _waterfall = require("./waterfall");
|
21
21
|
|
22
|
-
Object.keys(
|
22
|
+
Object.keys(_waterfall).forEach(function (key) {
|
23
23
|
if (key === "default" || key === "__esModule") return;
|
24
|
-
if (key in exports && exports[key] ===
|
24
|
+
if (key in exports && exports[key] === _waterfall[key]) return;
|
25
25
|
Object.defineProperty(exports, key, {
|
26
26
|
enumerable: true,
|
27
27
|
get: function () {
|
28
|
-
return
|
28
|
+
return _waterfall[key];
|
29
29
|
}
|
30
30
|
});
|
31
31
|
});
|
32
32
|
|
33
|
-
var
|
33
|
+
var _workflow = require("./workflow");
|
34
34
|
|
35
|
-
Object.keys(
|
35
|
+
Object.keys(_workflow).forEach(function (key) {
|
36
36
|
if (key === "default" || key === "__esModule") return;
|
37
|
-
if (key in exports && exports[key] ===
|
37
|
+
if (key in exports && exports[key] === _workflow[key]) return;
|
38
38
|
Object.defineProperty(exports, key, {
|
39
39
|
enumerable: true,
|
40
40
|
get: function () {
|
41
|
-
return
|
41
|
+
return _workflow[key];
|
42
42
|
}
|
43
43
|
});
|
44
44
|
});
|
@@ -54,17 +54,4 @@ Object.keys(_manager).forEach(function (key) {
|
|
54
54
|
return _manager[key];
|
55
55
|
}
|
56
56
|
});
|
57
|
-
});
|
58
|
-
|
59
|
-
var _context = require("./context");
|
60
|
-
|
61
|
-
Object.keys(_context).forEach(function (key) {
|
62
|
-
if (key === "default" || key === "__esModule") return;
|
63
|
-
if (key in exports && exports[key] === _context[key]) return;
|
64
|
-
Object.defineProperty(exports, key, {
|
65
|
-
enumerable: true,
|
66
|
-
get: function () {
|
67
|
-
return _context[key];
|
68
|
-
}
|
69
|
-
});
|
70
57
|
});
|
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.createAsyncManager = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
10
|
var _sync = require("./sync");
|
11
11
|
|
12
12
|
var _runner = require("./runner");
|
13
13
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
14
|
+
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; }
|
15
15
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
16
|
+
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; }
|
17
17
|
|
18
18
|
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; }
|
19
19
|
|
@@ -61,19 +61,19 @@ const createAsyncManager = processes => {
|
|
61
61
|
plugins = [];
|
62
62
|
};
|
63
63
|
|
64
|
-
const currentContainer = (0,
|
64
|
+
const currentContainer = (0, _farrowPipeline.createContainer)();
|
65
65
|
|
66
66
|
const init = async options => {
|
67
67
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
68
68
|
const sortedPlugins = sortAsyncPlugins(plugins);
|
69
69
|
checkAsyncPlugins(sortedPlugins);
|
70
|
-
const hooksList = await Promise.all(sortedPlugins.map(plugin => (0,
|
70
|
+
const hooksList = await Promise.all(sortedPlugins.map(plugin => (0, _farrowPipeline.runWithContainer)(() => plugin.initializer(), container)));
|
71
71
|
return (0, _sync.generateRunner)(hooksList, container, processes);
|
72
72
|
};
|
73
73
|
|
74
74
|
const run = (cb, options) => {
|
75
75
|
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
76
|
-
return (0,
|
76
|
+
return (0, _farrowPipeline.runWithContainer)(cb, container);
|
77
77
|
};
|
78
78
|
|
79
79
|
const manager = {
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useRunner = exports.RunnerContext = void 0;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _farrowPipeline = require("farrow-pipeline");
|
9
9
|
|
10
|
-
const RunnerContext = (0,
|
10
|
+
const RunnerContext = (0, _farrowPipeline.createContext)(null);
|
11
11
|
exports.RunnerContext = RunnerContext;
|
12
12
|
|
13
13
|
const useRunner = () => {
|