@modern-js/plugin 2.11.0 → 2.13.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 +10 -0
- package/dist/cjs/farrow-pipeline/context.js +7 -16
- package/dist/cjs/farrow-pipeline/counter.js +1 -2
- package/dist/cjs/farrow-pipeline/index.js +71 -2
- package/dist/cjs/manager/async.js +9 -8
- package/dist/cjs/manager/shared.js +16 -15
- package/dist/cjs/manager/sync.js +4 -9
- package/dist/cjs/waterfall/async.js +3 -2
- package/dist/cjs/workflow/async.js +6 -5
- package/dist/cjs/workflow/parallel.js +1 -1
- package/dist/esm/index.js +743 -4
- package/dist/esm-node/farrow-pipeline/context.js +7 -16
- package/dist/esm-node/farrow-pipeline/counter.js +1 -2
- package/dist/esm-node/farrow-pipeline/index.js +60 -1
- package/dist/esm-node/manager/async.js +9 -8
- package/dist/esm-node/manager/shared.js +16 -15
- package/dist/esm-node/manager/sync.js +4 -9
- package/dist/esm-node/waterfall/async.js +3 -2
- package/dist/esm-node/workflow/async.js +6 -5
- package/dist/esm-node/workflow/parallel.js +1 -1
- package/dist/types/farrow-pipeline/context.d.ts +0 -1
- package/dist/types/farrow-pipeline/index.d.ts +25 -1
- package/package.json +3 -3
- package/dist/cjs/farrow-pipeline/pipeline.js +0 -86
- package/dist/esm/farrow-pipeline/context.js +0 -31
- package/dist/esm/farrow-pipeline/counter.js +0 -17
- package/dist/esm/farrow-pipeline/index.js +0 -1
- package/dist/esm/farrow-pipeline/pipeline.js +0 -112
- package/dist/esm/manager/async.js +0 -306
- package/dist/esm/manager/index.js +0 -3
- package/dist/esm/manager/shared.js +0 -35
- package/dist/esm/manager/sync.js +0 -226
- package/dist/esm/manager/types.js +0 -1
- package/dist/esm/utils/pluginDagSort.js +0 -70
- package/dist/esm/waterfall/async.js +0 -271
- package/dist/esm/waterfall/index.js +0 -2
- package/dist/esm/waterfall/sync.js +0 -127
- package/dist/esm/workflow/async.js +0 -293
- package/dist/esm/workflow/index.js +0 -3
- package/dist/esm/workflow/parallel.js +0 -249
- package/dist/esm/workflow/sync.js +0 -114
- package/dist/esm-node/farrow-pipeline/pipeline.js +0 -60
- package/dist/types/farrow-pipeline/pipeline.d.ts +0 -29
@@ -1,28 +1,19 @@
|
|
1
1
|
const createContext = (value) => {
|
2
|
-
let currentValue;
|
3
|
-
|
4
|
-
|
5
|
-
const use = () => ({
|
2
|
+
let currentValue = value;
|
3
|
+
return {
|
4
|
+
use: () => ({
|
6
5
|
get value() {
|
7
6
|
return currentValue;
|
8
7
|
},
|
9
8
|
set value(v) {
|
10
9
|
currentValue = v;
|
11
10
|
}
|
12
|
-
})
|
13
|
-
|
14
|
-
|
11
|
+
}),
|
12
|
+
get: () => currentValue,
|
13
|
+
set: (v) => {
|
15
14
|
currentValue = v;
|
16
|
-
}
|
17
|
-
const Context = {
|
18
|
-
create,
|
19
|
-
use,
|
20
|
-
get,
|
21
|
-
set
|
22
|
-
};
|
23
|
-
return Context;
|
15
|
+
}
|
24
16
|
};
|
25
|
-
return create(value);
|
26
17
|
};
|
27
18
|
export {
|
28
19
|
createContext
|
@@ -3,9 +3,8 @@ const createCounter = (callback) => {
|
|
3
3
|
const next = (nextInput = input) => dispatch(index + 1, nextInput);
|
4
4
|
return callback(index, input, next);
|
5
5
|
};
|
6
|
-
const start = (input) => dispatch(0, input);
|
7
6
|
return {
|
8
|
-
start,
|
7
|
+
start: (input) => dispatch(0, input),
|
9
8
|
dispatch
|
10
9
|
};
|
11
10
|
};
|
@@ -1 +1,60 @@
|
|
1
|
-
|
1
|
+
import { createContext } from "./context";
|
2
|
+
import { createCounter } from "./counter";
|
3
|
+
const isPipeline = (input) => Boolean(input == null ? void 0 : input[PipelineSymbol]);
|
4
|
+
const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
5
|
+
const getMiddleware = (input) => {
|
6
|
+
if (typeof input === "function") {
|
7
|
+
return input;
|
8
|
+
} else if (input && typeof input.middleware === "function") {
|
9
|
+
return input.middleware;
|
10
|
+
}
|
11
|
+
throw new Error(`${input} is not a Middleware`);
|
12
|
+
};
|
13
|
+
const createPipeline = () => {
|
14
|
+
const middlewares = [];
|
15
|
+
const use = (...inputs) => {
|
16
|
+
middlewares.push(...inputs.map(getMiddleware));
|
17
|
+
return pipeline;
|
18
|
+
};
|
19
|
+
const createCurrentCounter = (onLast) => {
|
20
|
+
return createCounter((index, input, next) => {
|
21
|
+
if (index >= middlewares.length) {
|
22
|
+
if (onLast) {
|
23
|
+
return onLast(input);
|
24
|
+
}
|
25
|
+
throw new Error(
|
26
|
+
`Expect returning a value, but all middlewares just calling next()`
|
27
|
+
);
|
28
|
+
}
|
29
|
+
return middlewares[index](input, next);
|
30
|
+
});
|
31
|
+
};
|
32
|
+
const currentCounter = createCurrentCounter();
|
33
|
+
const getCounter = (options) => {
|
34
|
+
if (!options) {
|
35
|
+
return currentCounter;
|
36
|
+
}
|
37
|
+
return createCurrentCounter(options == null ? void 0 : options.onLast);
|
38
|
+
};
|
39
|
+
const run = (input, options) => getCounter(options).start(input);
|
40
|
+
const middleware = (input, next) => run(input, {
|
41
|
+
onLast: next
|
42
|
+
});
|
43
|
+
const pipeline = {
|
44
|
+
[PipelineSymbol]: true,
|
45
|
+
use,
|
46
|
+
run,
|
47
|
+
middleware
|
48
|
+
};
|
49
|
+
return pipeline;
|
50
|
+
};
|
51
|
+
const createAsyncPipeline = () => {
|
52
|
+
const pipeline = createPipeline();
|
53
|
+
return { ...pipeline };
|
54
|
+
};
|
55
|
+
export {
|
56
|
+
createAsyncPipeline,
|
57
|
+
createContext,
|
58
|
+
createPipeline,
|
59
|
+
isPipeline
|
60
|
+
};
|
@@ -31,7 +31,7 @@ const createAsyncManager = (hooks, api) => {
|
|
31
31
|
}
|
32
32
|
};
|
33
33
|
const usePlugin = (...input) => {
|
34
|
-
|
34
|
+
input.forEach((plugin) => {
|
35
35
|
if (isPlugin(plugin)) {
|
36
36
|
addPlugin(plugin);
|
37
37
|
} else if (typeof plugin === "function") {
|
@@ -39,10 +39,10 @@ const createAsyncManager = (hooks, api) => {
|
|
39
39
|
addPlugin(createPlugin(options.setup, options));
|
40
40
|
} else if (isObject(plugin)) {
|
41
41
|
addPlugin(createPlugin(plugin.setup, plugin));
|
42
|
-
} else {
|
42
|
+
} else if (process.env.NODE_ENV !== "production") {
|
43
43
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
44
44
|
}
|
45
|
-
}
|
45
|
+
});
|
46
46
|
return manager;
|
47
47
|
};
|
48
48
|
const createPlugin = (setup = () => {
|
@@ -67,18 +67,19 @@ const createAsyncManager = (hooks, api) => {
|
|
67
67
|
const clear = () => {
|
68
68
|
plugins = [];
|
69
69
|
};
|
70
|
-
const init =
|
70
|
+
const init = () => {
|
71
71
|
const sortedPlugins = sortPlugins(plugins);
|
72
72
|
const mergedPluginAPI = {
|
73
73
|
...pluginAPI,
|
74
74
|
...overrideAPI
|
75
75
|
};
|
76
76
|
checkPlugins(sortedPlugins);
|
77
|
-
|
77
|
+
return Promise.all(
|
78
78
|
sortedPlugins.map((plugin) => plugin.setup(mergedPluginAPI))
|
79
|
-
)
|
80
|
-
|
81
|
-
|
79
|
+
).then((hooksList) => {
|
80
|
+
runners = generateRunner(hooksList, currentHooks);
|
81
|
+
return runners;
|
82
|
+
});
|
82
83
|
};
|
83
84
|
const run = (cb) => cb();
|
84
85
|
const manager = {
|
@@ -1,25 +1,26 @@
|
|
1
1
|
import { dagSort } from "../utils/pluginDagSort";
|
2
2
|
const checkPlugins = (plugins) => {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
if (process.env.NODE_ENV !== "production") {
|
4
|
+
plugins.forEach((origin) => {
|
5
|
+
origin.rivals.forEach((rival) => {
|
6
|
+
plugins.forEach((plugin) => {
|
7
|
+
if (rival === plugin.name) {
|
8
|
+
throw new Error(`${origin.name} has rival ${plugin.name}`);
|
9
|
+
}
|
10
|
+
});
|
11
|
+
});
|
12
|
+
origin.required.forEach((required) => {
|
13
|
+
if (!plugins.some((plugin) => plugin.name === required)) {
|
14
|
+
throw new Error(
|
15
|
+
`The plugin: ${required} is required when plugin: ${origin.name} is exist.`
|
16
|
+
);
|
8
17
|
}
|
9
18
|
});
|
10
19
|
});
|
11
|
-
|
12
|
-
if (!plugins.some((plugin) => plugin.name === required)) {
|
13
|
-
throw new Error(
|
14
|
-
`The plugin: ${required} is required when plugin: ${origin.name} is exist.`
|
15
|
-
);
|
16
|
-
}
|
17
|
-
});
|
18
|
-
});
|
20
|
+
}
|
19
21
|
};
|
20
22
|
function sortPlugins(input) {
|
21
|
-
|
22
|
-
return dagSort(plugins);
|
23
|
+
return dagSort(input.slice());
|
23
24
|
}
|
24
25
|
const includePlugin = (plugins, input) => plugins.some((plugin) => plugin.name === input.name);
|
25
26
|
const isObject = (obj) => obj !== null && typeof obj === "object";
|
@@ -62,7 +62,7 @@ const createManager = (hooks, api) => {
|
|
62
62
|
addPlugin(createPlugin(options.setup, options));
|
63
63
|
} else if (isObject(plugin)) {
|
64
64
|
addPlugin(createPlugin(plugin.setup, plugin));
|
65
|
-
} else {
|
65
|
+
} else if (process.env.NODE_ENV !== "production") {
|
66
66
|
console.warn(`Unknown plugin: ${JSON.stringify(plugin)}`);
|
67
67
|
}
|
68
68
|
});
|
@@ -124,17 +124,12 @@ const generateRunner = (hooksList, hooksMap) => {
|
|
124
124
|
const cloneShape = cloneHooksMap(hooksMap);
|
125
125
|
if (hooksMap) {
|
126
126
|
for (const key in cloneShape) {
|
127
|
-
|
128
|
-
if (
|
129
|
-
continue;
|
130
|
-
}
|
131
|
-
if (hooks[key]) {
|
127
|
+
hooksList.forEach((hooks) => {
|
128
|
+
if (hooks == null ? void 0 : hooks[key]) {
|
132
129
|
cloneShape[key].use(hooks[key]);
|
133
130
|
}
|
134
|
-
}
|
135
|
-
runner[key] = (input, options) => cloneShape[key].run(input, {
|
136
|
-
...options
|
137
131
|
});
|
132
|
+
runner[key] = (input, options) => cloneShape[key].run(input, { ...options });
|
138
133
|
}
|
139
134
|
}
|
140
135
|
return runner;
|
@@ -5,7 +5,8 @@ const ASYNC_WATERFALL_SYMBOL = Symbol.for("MODERN_ASYNC_WATERFALL");
|
|
5
5
|
const getAsyncBrook = (input) => {
|
6
6
|
if (typeof input === "function") {
|
7
7
|
return input;
|
8
|
-
}
|
8
|
+
}
|
9
|
+
if (input && typeof input.middleware === "function") {
|
9
10
|
return input.middleware;
|
10
11
|
}
|
11
12
|
throw new Error(`${input} is not a AsyncBrook or { brook: AsyncBrook }`);
|
@@ -32,7 +33,7 @@ const createAsyncWaterfall = () => {
|
|
32
33
|
return waterfall;
|
33
34
|
};
|
34
35
|
const isAsyncWaterfall = (input) => Boolean(input == null ? void 0 : input[ASYNC_WATERFALL_SYMBOL]);
|
35
|
-
const mapAsyncBrookToAsyncMiddleware = (brook) =>
|
36
|
+
const mapAsyncBrookToAsyncMiddleware = (brook) => (input, next) => Promise.resolve(brook(input)).then((result) => next(result));
|
36
37
|
export {
|
37
38
|
createAsyncWaterfall,
|
38
39
|
getAsyncBrook,
|
@@ -9,13 +9,12 @@ const createAsyncWorkflow = () => {
|
|
9
9
|
pipeline.use(...input.map(mapAsyncWorkerToAsyncMiddleware));
|
10
10
|
return workflow;
|
11
11
|
};
|
12
|
-
const run =
|
12
|
+
const run = (input) => {
|
13
13
|
const result = pipeline.run(input, { onLast: () => [] });
|
14
14
|
if (isPromise(result)) {
|
15
15
|
return result.then((result2) => result2.filter(Boolean));
|
16
|
-
} else {
|
17
|
-
return result.filter(Boolean);
|
18
16
|
}
|
17
|
+
return result.filter(Boolean);
|
19
18
|
};
|
20
19
|
const workflow = {
|
21
20
|
...pipeline,
|
@@ -25,9 +24,11 @@ const createAsyncWorkflow = () => {
|
|
25
24
|
};
|
26
25
|
return workflow;
|
27
26
|
};
|
28
|
-
const mapAsyncWorkerToAsyncMiddleware = (worker) =>
|
27
|
+
const mapAsyncWorkerToAsyncMiddleware = (worker) => (input, next) => Promise.resolve(worker(input)).then(
|
28
|
+
(result) => Promise.resolve(next(input)).then((nextResult) => [result, ...nextResult])
|
29
|
+
);
|
29
30
|
function isPromise(obj) {
|
30
|
-
return
|
31
|
+
return obj && typeof obj.then === "function";
|
31
32
|
}
|
32
33
|
export {
|
33
34
|
createAsyncWorkflow,
|
@@ -7,7 +7,7 @@ const createParallelWorkflow = () => {
|
|
7
7
|
pipeline.use(...input.map(mapParallelWorkerToAsyncMiddleware));
|
8
8
|
return workflow;
|
9
9
|
};
|
10
|
-
const run =
|
10
|
+
const run = (input) => Promise.all(pipeline.run(input, { onLast: () => [] })).then(
|
11
11
|
(result) => result.filter(Boolean)
|
12
12
|
);
|
13
13
|
const workflow = {
|
@@ -2,4 +2,28 @@
|
|
2
2
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
3
3
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
4
4
|
*/
|
5
|
-
|
5
|
+
import { createContext, Context } from './context';
|
6
|
+
import { Next } from './counter';
|
7
|
+
export type { Next };
|
8
|
+
export { createContext };
|
9
|
+
export type { Context };
|
10
|
+
export type Middleware<I = unknown, O = unknown> = (input: I, next: Next<I, O>) => O;
|
11
|
+
export type Middlewares<I = unknown, O = unknown> = Middleware<I, O>[];
|
12
|
+
export declare const isPipeline: (input: any) => input is Pipeline<unknown, unknown>;
|
13
|
+
declare const PipelineSymbol: unique symbol;
|
14
|
+
export type RunPipelineOptions<I = unknown, O = unknown> = {
|
15
|
+
onLast?: (input: I) => O;
|
16
|
+
};
|
17
|
+
export type MiddlewareInput<I = unknown, O = unknown> = Middleware<I, O> | {
|
18
|
+
middleware: Middleware<I, O>;
|
19
|
+
};
|
20
|
+
export type Pipeline<I = unknown, O = unknown> = {
|
21
|
+
[PipelineSymbol]: true;
|
22
|
+
use: (...inputs: MiddlewareInput<I, O>[]) => Pipeline<I, O>;
|
23
|
+
run: (input: I, options?: RunPipelineOptions<I, O>) => O;
|
24
|
+
middleware: Middleware<I, O>;
|
25
|
+
};
|
26
|
+
export declare const createPipeline: <I, O>() => Pipeline<I, O>;
|
27
|
+
export type MaybeAsync<T> = T | Promise<T>;
|
28
|
+
export type AsyncPipeline<I = unknown, O = unknown> = Pipeline<I, MaybeAsync<O>>;
|
29
|
+
export declare const createAsyncPipeline: <I, O>() => AsyncPipeline<I, O>;
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "2.
|
14
|
+
"version": "2.13.0",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/cjs/index.js",
|
@@ -35,8 +35,8 @@
|
|
35
35
|
"@types/node": "^14",
|
36
36
|
"typescript": "^4",
|
37
37
|
"jest": "^29",
|
38
|
-
"@scripts/
|
39
|
-
"@scripts/
|
38
|
+
"@scripts/jest-config": "2.13.0",
|
39
|
+
"@scripts/build": "2.13.0"
|
40
40
|
},
|
41
41
|
"sideEffects": false,
|
42
42
|
"publishConfig": {
|
@@ -1,86 +0,0 @@
|
|
1
|
-
var __defProp = Object.defineProperty;
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
-
var __export = (target, all) => {
|
6
|
-
for (var name in all)
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
-
};
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var pipeline_exports = {};
|
19
|
-
__export(pipeline_exports, {
|
20
|
-
createAsyncPipeline: () => createAsyncPipeline,
|
21
|
-
createContext: () => import_context.createContext,
|
22
|
-
createPipeline: () => createPipeline,
|
23
|
-
isPipeline: () => isPipeline
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(pipeline_exports);
|
26
|
-
var import_context = require("./context");
|
27
|
-
var import_counter = require("./counter");
|
28
|
-
const isPipeline = (input) => Boolean(input == null ? void 0 : input[PipelineSymbol]);
|
29
|
-
const PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
30
|
-
const getMiddleware = (input) => {
|
31
|
-
if (typeof input === "function") {
|
32
|
-
return input;
|
33
|
-
} else if (input && typeof input.middleware === "function") {
|
34
|
-
return input.middleware;
|
35
|
-
}
|
36
|
-
throw new Error(`${input} is not a Middleware`);
|
37
|
-
};
|
38
|
-
const createPipeline = () => {
|
39
|
-
const middlewares = [];
|
40
|
-
const use = (...inputs) => {
|
41
|
-
middlewares.push(...inputs.map(getMiddleware));
|
42
|
-
return pipeline;
|
43
|
-
};
|
44
|
-
const createCurrentCounter = (onLast) => {
|
45
|
-
return (0, import_counter.createCounter)((index, input, next) => {
|
46
|
-
if (index >= middlewares.length) {
|
47
|
-
if (onLast) {
|
48
|
-
return onLast(input);
|
49
|
-
}
|
50
|
-
throw new Error(
|
51
|
-
`Expect returning a value, but all middlewares just calling next()`
|
52
|
-
);
|
53
|
-
}
|
54
|
-
return middlewares[index](input, next);
|
55
|
-
});
|
56
|
-
};
|
57
|
-
const currentCounter = createCurrentCounter();
|
58
|
-
const getCounter = (options) => {
|
59
|
-
if (!options) {
|
60
|
-
return currentCounter;
|
61
|
-
}
|
62
|
-
return createCurrentCounter(options == null ? void 0 : options.onLast);
|
63
|
-
};
|
64
|
-
const run = (input, options) => getCounter(options).start(input);
|
65
|
-
const middleware = (input, next) => run(input, {
|
66
|
-
onLast: next
|
67
|
-
});
|
68
|
-
const pipeline = {
|
69
|
-
[PipelineSymbol]: true,
|
70
|
-
use,
|
71
|
-
run,
|
72
|
-
middleware
|
73
|
-
};
|
74
|
-
return pipeline;
|
75
|
-
};
|
76
|
-
const createAsyncPipeline = () => {
|
77
|
-
const pipeline = createPipeline();
|
78
|
-
return { ...pipeline };
|
79
|
-
};
|
80
|
-
// Annotate the CommonJS export names for ESM import in node:
|
81
|
-
0 && (module.exports = {
|
82
|
-
createAsyncPipeline,
|
83
|
-
createContext,
|
84
|
-
createPipeline,
|
85
|
-
isPipeline
|
86
|
-
});
|
@@ -1,31 +0,0 @@
|
|
1
|
-
var createContext = function(value) {
|
2
|
-
var currentValue;
|
3
|
-
var create = function(value2) {
|
4
|
-
currentValue = value2;
|
5
|
-
var use = function() {
|
6
|
-
return {
|
7
|
-
get value () {
|
8
|
-
return currentValue;
|
9
|
-
},
|
10
|
-
set value (v){
|
11
|
-
currentValue = v;
|
12
|
-
}
|
13
|
-
};
|
14
|
-
};
|
15
|
-
var get = function() {
|
16
|
-
return currentValue;
|
17
|
-
};
|
18
|
-
var set = function(v1) {
|
19
|
-
currentValue = v1;
|
20
|
-
};
|
21
|
-
var Context = {
|
22
|
-
create: create,
|
23
|
-
use: use,
|
24
|
-
get: get,
|
25
|
-
set: set
|
26
|
-
};
|
27
|
-
return Context;
|
28
|
-
};
|
29
|
-
return create(value);
|
30
|
-
};
|
31
|
-
export { createContext };
|
@@ -1,17 +0,0 @@
|
|
1
|
-
var createCounter = function(callback) {
|
2
|
-
var dispatch = function(index, input) {
|
3
|
-
var next = function() {
|
4
|
-
var nextInput = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : input;
|
5
|
-
return dispatch(index + 1, nextInput);
|
6
|
-
};
|
7
|
-
return callback(index, input, next);
|
8
|
-
};
|
9
|
-
var start = function(input) {
|
10
|
-
return dispatch(0, input);
|
11
|
-
};
|
12
|
-
return {
|
13
|
-
start: start,
|
14
|
-
dispatch: dispatch
|
15
|
-
};
|
16
|
-
};
|
17
|
-
export { createCounter };
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from "./pipeline";
|
@@ -1,112 +0,0 @@
|
|
1
|
-
function _arrayLikeToArray(arr, len) {
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
4
|
-
return arr2;
|
5
|
-
}
|
6
|
-
function _arrayWithoutHoles(arr) {
|
7
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
8
|
-
}
|
9
|
-
function _defineProperty(obj, key, value) {
|
10
|
-
if (key in obj) {
|
11
|
-
Object.defineProperty(obj, key, {
|
12
|
-
value: value,
|
13
|
-
enumerable: true,
|
14
|
-
configurable: true,
|
15
|
-
writable: true
|
16
|
-
});
|
17
|
-
} else {
|
18
|
-
obj[key] = value;
|
19
|
-
}
|
20
|
-
return obj;
|
21
|
-
}
|
22
|
-
function _iterableToArray(iter) {
|
23
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
24
|
-
}
|
25
|
-
function _nonIterableSpread() {
|
26
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
27
|
-
}
|
28
|
-
function _objectSpread(target) {
|
29
|
-
for(var i = 1; i < arguments.length; i++){
|
30
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
31
|
-
var ownKeys = Object.keys(source);
|
32
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
33
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
34
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
35
|
-
}));
|
36
|
-
}
|
37
|
-
ownKeys.forEach(function(key) {
|
38
|
-
_defineProperty(target, key, source[key]);
|
39
|
-
});
|
40
|
-
}
|
41
|
-
return target;
|
42
|
-
}
|
43
|
-
function _toConsumableArray(arr) {
|
44
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
45
|
-
}
|
46
|
-
function _unsupportedIterableToArray(o, minLen) {
|
47
|
-
if (!o) return;
|
48
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
49
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
50
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
51
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
52
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
53
|
-
}
|
54
|
-
import { createContext } from "./context";
|
55
|
-
import { createCounter } from "./counter";
|
56
|
-
var isPipeline = function(input) {
|
57
|
-
return Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
58
|
-
};
|
59
|
-
var PipelineSymbol = Symbol.for("MODERN_PIPELINE");
|
60
|
-
var getMiddleware = function(input) {
|
61
|
-
if (typeof input === "function") {
|
62
|
-
return input;
|
63
|
-
} else if (input && typeof input.middleware === "function") {
|
64
|
-
return input.middleware;
|
65
|
-
}
|
66
|
-
throw new Error("".concat(input, " is not a Middleware"));
|
67
|
-
};
|
68
|
-
var createPipeline = function() {
|
69
|
-
var middlewares = [];
|
70
|
-
var use = function() {
|
71
|
-
for(var _len = arguments.length, inputs = new Array(_len), _key = 0; _key < _len; _key++){
|
72
|
-
inputs[_key] = arguments[_key];
|
73
|
-
}
|
74
|
-
var _middlewares;
|
75
|
-
(_middlewares = middlewares).push.apply(_middlewares, _toConsumableArray(inputs.map(getMiddleware)));
|
76
|
-
return pipeline;
|
77
|
-
};
|
78
|
-
var createCurrentCounter = function(onLast) {
|
79
|
-
return createCounter(function(index, input, next) {
|
80
|
-
if (index >= middlewares.length) {
|
81
|
-
if (onLast) {
|
82
|
-
return onLast(input);
|
83
|
-
}
|
84
|
-
throw new Error("Expect returning a value, but all middlewares just calling next()");
|
85
|
-
}
|
86
|
-
return middlewares[index](input, next);
|
87
|
-
});
|
88
|
-
};
|
89
|
-
var currentCounter = createCurrentCounter();
|
90
|
-
var getCounter = function(options) {
|
91
|
-
if (!options) {
|
92
|
-
return currentCounter;
|
93
|
-
}
|
94
|
-
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
95
|
-
};
|
96
|
-
var run = function(input, options) {
|
97
|
-
return getCounter(options).start(input);
|
98
|
-
};
|
99
|
-
var middleware = function(input, next) {
|
100
|
-
return run(input, {
|
101
|
-
onLast: next
|
102
|
-
});
|
103
|
-
};
|
104
|
-
var _obj;
|
105
|
-
var pipeline = (_obj = {}, _defineProperty(_obj, PipelineSymbol, true), _defineProperty(_obj, "use", use), _defineProperty(_obj, "run", run), _defineProperty(_obj, "middleware", middleware), _obj);
|
106
|
-
return pipeline;
|
107
|
-
};
|
108
|
-
var createAsyncPipeline = function() {
|
109
|
-
var pipeline = createPipeline();
|
110
|
-
return _objectSpread({}, pipeline);
|
111
|
-
};
|
112
|
-
export { createAsyncPipeline, createContext, createPipeline, isPipeline };
|