@modern-js/plugin 1.3.8 → 1.4.1
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 +6 -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 +8 -12
- package/dist/js/modern/manager/index.js +0 -1
- package/dist/js/modern/manager/sync.js +13 -19
- 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 +10 -16
- package/dist/js/node/manager/index.js +0 -13
- package/dist/js/node/manager/sync.js +16 -23
- 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 -17
- package/dist/js/treeshaking/manager/index.js +0 -1
- package/dist/js/treeshaking/manager/sync.js +16 -20
- 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 +3 -3
- 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/index.d.ts +0 -1
- package/dist/types/manager/sync.d.ts +6 -10
- 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 -80
- package/dist/js/modern/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/modern/farrow-pipeline/hook.js +0 -42
- package/dist/js/modern/manager/runner.js +0 -11
- package/dist/js/node/farrow-pipeline/asyncHooks.node.js +0 -100
- package/dist/js/node/farrow-pipeline/asyncHooksInterface.js +0 -26
- package/dist/js/node/farrow-pipeline/hook.js +0 -52
- package/dist/js/node/manager/runner.js +0 -23
- package/dist/js/treeshaking/farrow-pipeline/asyncHooks.node.js +0 -80
- package/dist/js/treeshaking/farrow-pipeline/asyncHooksInterface.js +0 -12
- package/dist/js/treeshaking/farrow-pipeline/hook.js +0 -46
- package/dist/js/treeshaking/manager/runner.js +0 -11
- 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
- package/dist/types/manager/runner.d.ts +0 -3
@@ -4,12 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createAsyncPipeline = void 0;
|
7
|
-
Object.defineProperty(exports, "createContainer", {
|
8
|
-
enumerable: true,
|
9
|
-
get: function () {
|
10
|
-
return _context.createContainer;
|
11
|
-
}
|
12
|
-
});
|
13
7
|
Object.defineProperty(exports, "createContext", {
|
14
8
|
enumerable: true,
|
15
9
|
get: function () {
|
@@ -17,18 +11,6 @@ Object.defineProperty(exports, "createContext", {
|
|
17
11
|
}
|
18
12
|
});
|
19
13
|
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
14
|
|
33
15
|
var _context = require("./context");
|
34
16
|
|
@@ -55,9 +37,7 @@ const getMiddleware = input => {
|
|
55
37
|
throw new Error(`${input} is not a Middleware`);
|
56
38
|
};
|
57
39
|
|
58
|
-
const createPipeline =
|
59
|
-
const config = _objectSpread({}, options);
|
60
|
-
|
40
|
+
const createPipeline = () => {
|
61
41
|
const middlewares = [];
|
62
42
|
|
63
43
|
const use = (...inputs) => {
|
@@ -65,50 +45,35 @@ const createPipeline = options => {
|
|
65
45
|
return pipeline;
|
66
46
|
};
|
67
47
|
|
68
|
-
const createCurrentCounter =
|
48
|
+
const createCurrentCounter = onLast => {
|
69
49
|
return (0, _counter.createCounter)((index, input, next) => {
|
70
50
|
if (index >= middlewares.length) {
|
71
51
|
if (onLast) {
|
72
|
-
if (onLastWithContext) {
|
73
|
-
return (0, _context.runHooks)(() => onLast(input), hooks);
|
74
|
-
}
|
75
|
-
|
76
52
|
return onLast(input);
|
77
53
|
}
|
78
54
|
|
79
55
|
throw new Error(`Expect returning a value, but all middlewares just calling next()`);
|
80
56
|
}
|
81
57
|
|
82
|
-
return
|
58
|
+
return middlewares[index](input, next);
|
83
59
|
});
|
84
60
|
};
|
85
61
|
|
86
|
-
const
|
87
|
-
const currentHooks = (0, _context.fromContainer)(currentContainer);
|
88
|
-
const currentCounter = createCurrentCounter(currentHooks);
|
62
|
+
const currentCounter = createCurrentCounter();
|
89
63
|
|
90
64
|
const getCounter = options => {
|
91
65
|
if (!options) {
|
92
66
|
return currentCounter;
|
93
67
|
}
|
94
68
|
|
95
|
-
|
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);
|
69
|
+
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
101
70
|
};
|
102
71
|
|
103
72
|
const run = (input, options) => getCounter(options).start(input);
|
104
73
|
|
105
|
-
const middleware = (input, next) => {
|
106
|
-
|
107
|
-
|
108
|
-
container,
|
109
|
-
onLast: next
|
110
|
-
});
|
111
|
-
};
|
74
|
+
const middleware = (input, next) => run(input, {
|
75
|
+
onLast: next
|
76
|
+
});
|
112
77
|
|
113
78
|
const pipeline = {
|
114
79
|
[PipelineSymbol]: true,
|
@@ -121,8 +86,8 @@ const createPipeline = options => {
|
|
121
86
|
|
122
87
|
exports.createPipeline = createPipeline;
|
123
88
|
|
124
|
-
const createAsyncPipeline =
|
125
|
-
const pipeline = createPipeline(
|
89
|
+
const createAsyncPipeline = () => {
|
90
|
+
const pipeline = createPipeline();
|
126
91
|
return _objectSpread({}, pipeline);
|
127
92
|
};
|
128
93
|
|
@@ -5,12 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.createAsyncManager = void 0;
|
7
7
|
|
8
|
-
var _farrowPipeline = require("../farrow-pipeline");
|
9
|
-
|
10
8
|
var _sync = require("./sync");
|
11
9
|
|
12
|
-
var _runner = require("./runner");
|
13
|
-
|
14
10
|
var _shared = require("./shared");
|
15
11
|
|
16
12
|
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; }
|
@@ -23,9 +19,12 @@ const ASYNC_PLUGIN_SYMBOL = 'ASYNC_PLUGIN_SYMBOL';
|
|
23
19
|
|
24
20
|
const createAsyncManager = (hooks, api) => {
|
25
21
|
let index = 0;
|
22
|
+
let runners;
|
26
23
|
|
27
24
|
let currentHooks = _objectSpread({}, hooks);
|
28
25
|
|
26
|
+
const useRunner = () => runners;
|
27
|
+
|
29
28
|
const registerHook = extraHooks => {
|
30
29
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
31
30
|
};
|
@@ -33,7 +32,7 @@ const createAsyncManager = (hooks, api) => {
|
|
33
32
|
const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, ASYNC_PLUGIN_SYMBOL) && input[ASYNC_PLUGIN_SYMBOL] === ASYNC_PLUGIN_SYMBOL;
|
34
33
|
|
35
34
|
const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
36
|
-
useHookRunners:
|
35
|
+
useHookRunners: useRunner
|
37
36
|
});
|
38
37
|
|
39
38
|
const clone = overrideAPI => {
|
@@ -92,23 +91,18 @@ const createAsyncManager = (hooks, api) => {
|
|
92
91
|
plugins = [];
|
93
92
|
};
|
94
93
|
|
95
|
-
const
|
96
|
-
|
97
|
-
const init = async options => {
|
98
|
-
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
94
|
+
const init = async () => {
|
99
95
|
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
100
96
|
|
101
97
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
102
98
|
|
103
99
|
(0, _shared.checkPlugins)(sortedPlugins);
|
104
|
-
const hooksList = await Promise.all(sortedPlugins.map(plugin =>
|
105
|
-
|
100
|
+
const hooksList = await Promise.all(sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI)));
|
101
|
+
runners = (0, _sync.generateRunner)(hooksList, currentHooks);
|
102
|
+
return runners;
|
106
103
|
};
|
107
104
|
|
108
|
-
const run =
|
109
|
-
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
110
|
-
return (0, _farrowPipeline.runWithContainer)(cb, container);
|
111
|
-
};
|
105
|
+
const run = cb => cb();
|
112
106
|
|
113
107
|
const manager = {
|
114
108
|
createPlugin,
|
@@ -119,7 +113,7 @@ const createAsyncManager = (hooks, api) => {
|
|
119
113
|
clear,
|
120
114
|
clone,
|
121
115
|
registerHook,
|
122
|
-
useRunner
|
116
|
+
useRunner
|
123
117
|
};
|
124
118
|
return manager;
|
125
119
|
};
|
@@ -30,19 +30,6 @@ Object.keys(_async).forEach(function (key) {
|
|
30
30
|
});
|
31
31
|
});
|
32
32
|
|
33
|
-
var _runner = require("./runner");
|
34
|
-
|
35
|
-
Object.keys(_runner).forEach(function (key) {
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
37
|
-
if (key in exports && exports[key] === _runner[key]) return;
|
38
|
-
Object.defineProperty(exports, key, {
|
39
|
-
enumerable: true,
|
40
|
-
get: function () {
|
41
|
-
return _runner[key];
|
42
|
-
}
|
43
|
-
});
|
44
|
-
});
|
45
|
-
|
46
33
|
var _types = require("./types");
|
47
34
|
|
48
35
|
Object.keys(_types).forEach(function (key) {
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.generateRunner = exports.createManager = exports.
|
6
|
+
exports.generateRunner = exports.createManager = exports.cloneHooksMap = exports.cloneHook = exports.DEFAULT_OPTIONS = void 0;
|
7
7
|
|
8
8
|
var _farrowPipeline = require("../farrow-pipeline");
|
9
9
|
|
@@ -11,8 +11,6 @@ var _waterfall = require("../waterfall");
|
|
11
11
|
|
12
12
|
var _workflow = require("../workflow");
|
13
13
|
|
14
|
-
var _runner = require("./runner");
|
15
|
-
|
16
14
|
var _shared = require("./shared");
|
17
15
|
|
18
16
|
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; }
|
@@ -35,9 +33,12 @@ exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
35
33
|
|
36
34
|
const createManager = (hooks, api) => {
|
37
35
|
let index = 0;
|
36
|
+
let runners;
|
38
37
|
|
39
38
|
let currentHooks = _objectSpread({}, hooks);
|
40
39
|
|
40
|
+
const useRunner = () => runners;
|
41
|
+
|
41
42
|
const registerHook = extraHooks => {
|
42
43
|
currentHooks = _objectSpread(_objectSpread({}, extraHooks), currentHooks);
|
43
44
|
};
|
@@ -45,7 +46,7 @@ const createManager = (hooks, api) => {
|
|
45
46
|
const isPlugin = input => (0, _shared.isObject)(input) && (0, _shared.hasOwnProperty)(input, SYNC_PLUGIN_SYMBOL) && input[SYNC_PLUGIN_SYMBOL] === SYNC_PLUGIN_SYMBOL;
|
46
47
|
|
47
48
|
const pluginAPI = _objectSpread(_objectSpread({}, api), {}, {
|
48
|
-
useHookRunners:
|
49
|
+
useHookRunners: useRunner
|
49
50
|
});
|
50
51
|
|
51
52
|
const clone = overrideAPI => {
|
@@ -103,23 +104,18 @@ const createManager = (hooks, api) => {
|
|
103
104
|
plugins = [];
|
104
105
|
};
|
105
106
|
|
106
|
-
const
|
107
|
-
|
108
|
-
const init = options => {
|
109
|
-
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
107
|
+
const init = () => {
|
110
108
|
const sortedPlugins = (0, _shared.sortPlugins)(plugins);
|
111
109
|
|
112
110
|
const mergedPluginAPI = _objectSpread(_objectSpread({}, pluginAPI), overrideAPI);
|
113
111
|
|
114
112
|
(0, _shared.checkPlugins)(sortedPlugins);
|
115
|
-
const hooksList = sortedPlugins.map(plugin =>
|
116
|
-
|
113
|
+
const hooksList = sortedPlugins.map(plugin => plugin.setup(mergedPluginAPI));
|
114
|
+
runners = generateRunner(hooksList, currentHooks);
|
115
|
+
return runners;
|
117
116
|
};
|
118
117
|
|
119
|
-
const run =
|
120
|
-
const container = (options === null || options === void 0 ? void 0 : options.container) || currentContainer;
|
121
|
-
return (0, _farrowPipeline.runWithContainer)(cb, container);
|
122
|
-
};
|
118
|
+
const run = cb => cb();
|
123
119
|
|
124
120
|
const manager = {
|
125
121
|
createPlugin,
|
@@ -129,7 +125,7 @@ const createManager = (hooks, api) => {
|
|
129
125
|
clear,
|
130
126
|
run,
|
131
127
|
registerHook,
|
132
|
-
useRunner
|
128
|
+
useRunner,
|
133
129
|
clone
|
134
130
|
};
|
135
131
|
return manager;
|
@@ -140,9 +136,9 @@ const createManager = (hooks, api) => {
|
|
140
136
|
|
141
137
|
exports.createManager = createManager;
|
142
138
|
|
143
|
-
const generateRunner = (hooksList,
|
139
|
+
const generateRunner = (hooksList, hooksMap) => {
|
144
140
|
const runner = {};
|
145
|
-
const cloneShape =
|
141
|
+
const cloneShape = cloneHooksMap(hooksMap);
|
146
142
|
|
147
143
|
if (hooksMap) {
|
148
144
|
for (const key in cloneShape) {
|
@@ -158,13 +154,10 @@ const generateRunner = (hooksList, container, hooksMap) => {
|
|
158
154
|
// @ts-expect-error
|
159
155
|
|
160
156
|
|
161
|
-
runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({
|
162
|
-
container
|
163
|
-
}, options));
|
157
|
+
runner[key] = (input, options) => cloneShape[key].run(input, _objectSpread({}, options));
|
164
158
|
}
|
165
159
|
}
|
166
160
|
|
167
|
-
container.write(_runner.RunnerContext, runner);
|
168
161
|
return runner;
|
169
162
|
};
|
170
163
|
|
@@ -200,7 +193,7 @@ const cloneHook = hook => {
|
|
200
193
|
|
201
194
|
exports.cloneHook = cloneHook;
|
202
195
|
|
203
|
-
const
|
196
|
+
const cloneHooksMap = record => {
|
204
197
|
if (!record) {
|
205
198
|
return record;
|
206
199
|
}
|
@@ -216,4 +209,4 @@ const closeHooksMap = record => {
|
|
216
209
|
return result;
|
217
210
|
};
|
218
211
|
|
219
|
-
exports.
|
212
|
+
exports.cloneHooksMap = cloneHooksMap;
|
@@ -27,10 +27,10 @@ const createAsyncWorkflow = () => {
|
|
27
27
|
return workflow;
|
28
28
|
};
|
29
29
|
|
30
|
-
const run = async
|
31
|
-
const result = pipeline.run(input,
|
30
|
+
const run = async input => {
|
31
|
+
const result = pipeline.run(input, {
|
32
32
|
onLast: () => []
|
33
|
-
})
|
33
|
+
});
|
34
34
|
|
35
35
|
if (isPromise(result)) {
|
36
36
|
return result.then(result => result.filter(Boolean));
|
@@ -27,9 +27,9 @@ const createParallelWorkflow = () => {
|
|
27
27
|
return workflow;
|
28
28
|
};
|
29
29
|
|
30
|
-
const run = async
|
30
|
+
const run = async input => Promise.all(pipeline.run(input, {
|
31
31
|
onLast: () => []
|
32
|
-
}))
|
32
|
+
})).then(result => result.filter(Boolean));
|
33
33
|
|
34
34
|
const workflow = _objectSpread(_objectSpread({}, pipeline), {}, {
|
35
35
|
run,
|
@@ -23,10 +23,10 @@ const createWorkflow = () => {
|
|
23
23
|
return workflow;
|
24
24
|
};
|
25
25
|
|
26
|
-
const run =
|
27
|
-
const result = pipeline.run(input,
|
26
|
+
const run = input => {
|
27
|
+
const result = pipeline.run(input, {
|
28
28
|
onLast: () => []
|
29
|
-
})
|
29
|
+
});
|
30
30
|
return result.filter(Boolean);
|
31
31
|
};
|
32
32
|
|
@@ -1,103 +1,42 @@
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
|
-
|
3
1
|
/**
|
4
2
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
5
3
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
6
4
|
*/
|
7
|
-
import { createHooks } from "./hook";
|
8
|
-
var ContextSymbol = Symbol["for"]('MODERN_CONTEXT');
|
9
5
|
export var createContext = function createContext(value) {
|
10
|
-
var
|
6
|
+
var currentValue;
|
11
7
|
|
12
8
|
var create = function create(value) {
|
13
|
-
|
9
|
+
currentValue = value;
|
14
10
|
|
15
11
|
var use = function use() {
|
16
|
-
|
17
|
-
return Object.seal({
|
12
|
+
return {
|
18
13
|
get value() {
|
19
|
-
return
|
14
|
+
return currentValue;
|
20
15
|
},
|
21
16
|
|
22
17
|
set value(v) {
|
23
|
-
|
18
|
+
currentValue = v;
|
24
19
|
}
|
25
20
|
|
26
|
-
}
|
21
|
+
};
|
27
22
|
};
|
28
23
|
|
29
24
|
var get = function get() {
|
30
|
-
|
31
|
-
return container.read(Context);
|
25
|
+
return currentValue;
|
32
26
|
};
|
33
27
|
|
34
28
|
var set = function set(v) {
|
35
|
-
|
36
|
-
container.write(Context, v);
|
29
|
+
currentValue = v;
|
37
30
|
};
|
38
31
|
|
39
|
-
var Context =
|
40
|
-
|
41
|
-
|
32
|
+
var Context = {
|
33
|
+
create: create,
|
34
|
+
use: use,
|
35
|
+
get: get,
|
36
|
+
set: set
|
37
|
+
};
|
42
38
|
return Context;
|
43
39
|
};
|
44
40
|
|
45
41
|
return create(value);
|
46
|
-
};
|
47
|
-
|
48
|
-
var createContextMap = function createContextMap(storage) {
|
49
|
-
var contextMap = new Map();
|
50
|
-
var contexts = Object.values(storage); // eslint-disable-next-line @typescript-eslint/prefer-for-of
|
51
|
-
|
52
|
-
for (var i = 0; i < contexts.length; i++) {
|
53
|
-
contextMap.set(contexts[i].id, contexts[i]);
|
54
|
-
}
|
55
|
-
|
56
|
-
return contextMap;
|
57
|
-
};
|
58
|
-
|
59
|
-
export var createContainer = function createContainer() {
|
60
|
-
var ContextStorage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
61
|
-
var contextMap = createContextMap(ContextStorage);
|
62
|
-
|
63
|
-
var read = function read(context) {
|
64
|
-
var target = contextMap.get(context.id);
|
65
|
-
|
66
|
-
if (target) {
|
67
|
-
return target[ContextSymbol];
|
68
|
-
}
|
69
|
-
|
70
|
-
return context[ContextSymbol];
|
71
|
-
};
|
72
|
-
|
73
|
-
var write = function write(context, value) {
|
74
|
-
contextMap.set(context.id, context.create(value));
|
75
|
-
};
|
76
|
-
|
77
|
-
return Object.freeze({
|
78
|
-
read: read,
|
79
|
-
write: write
|
80
|
-
});
|
81
|
-
};
|
82
|
-
|
83
|
-
var _createHooks = createHooks({
|
84
|
-
useContainer: function useContainer() {
|
85
|
-
throw new Error("Can't call useContainer out of scope, it should be placed on top of the function");
|
86
|
-
}
|
87
|
-
}),
|
88
|
-
run = _createHooks.run,
|
89
|
-
hooks = _createHooks.hooks;
|
90
|
-
|
91
|
-
export var runHooks = run;
|
92
|
-
var useContainer = hooks.useContainer;
|
93
|
-
export { useContainer };
|
94
|
-
export var fromContainer = function fromContainer(container) {
|
95
|
-
return {
|
96
|
-
useContainer: function useContainer() {
|
97
|
-
return container;
|
98
|
-
}
|
99
|
-
};
|
100
|
-
};
|
101
|
-
export var runWithContainer = function runWithContainer(f, container) {
|
102
|
-
return runHooks(f, fromContainer(container));
|
103
42
|
};
|
@@ -1,19 +1,5 @@
|
|
1
1
|
/**
|
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
|
-
*
|
5
|
-
* removed:
|
6
|
-
* - dependencies:
|
7
|
-
* - tslib
|
8
|
-
* - files
|
9
|
-
* - compose.ts
|
10
|
-
* - methods:
|
11
|
-
* - usePipeline
|
12
|
-
* - assertContainer
|
13
|
-
* - assertContext
|
14
|
-
* - isContext
|
15
|
-
* - isContainer
|
16
|
-
* - pipeline.useLazy
|
17
|
-
* - context.assert
|
18
4
|
*/
|
19
5
|
export * from "./pipeline";
|
@@ -1,14 +1,14 @@
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
1
2
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
2
3
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
3
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
4
|
|
5
5
|
/**
|
6
6
|
* modified from https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline
|
7
7
|
* license at https://github.com/farrow-js/farrow/blob/master/LICENSE
|
8
8
|
*/
|
9
|
-
import { createContext
|
9
|
+
import { createContext } from "./context";
|
10
10
|
import { createCounter } from "./counter";
|
11
|
-
export { createContext
|
11
|
+
export { createContext };
|
12
12
|
export var isPipeline = function isPipeline(input) {
|
13
13
|
return Boolean(input === null || input === void 0 ? void 0 : input[PipelineSymbol]);
|
14
14
|
};
|
@@ -24,11 +24,9 @@ var getMiddleware = function getMiddleware(input) {
|
|
24
24
|
throw new Error("".concat(input, " is not a Middleware"));
|
25
25
|
};
|
26
26
|
|
27
|
-
export var createPipeline = function createPipeline(
|
27
|
+
export var createPipeline = function createPipeline() {
|
28
28
|
var _pipeline;
|
29
29
|
|
30
|
-
var config = _objectSpread({}, options);
|
31
|
-
|
32
30
|
var middlewares = [];
|
33
31
|
|
34
32
|
var use = function use() {
|
@@ -40,43 +38,28 @@ export var createPipeline = function createPipeline(options) {
|
|
40
38
|
return pipeline;
|
41
39
|
};
|
42
40
|
|
43
|
-
var createCurrentCounter = function createCurrentCounter(
|
41
|
+
var createCurrentCounter = function createCurrentCounter(onLast) {
|
44
42
|
return createCounter(function (index, input, next) {
|
45
43
|
if (index >= middlewares.length) {
|
46
44
|
if (onLast) {
|
47
|
-
if (onLastWithContext) {
|
48
|
-
return runHooks(function () {
|
49
|
-
return onLast(input);
|
50
|
-
}, hooks);
|
51
|
-
}
|
52
|
-
|
53
45
|
return onLast(input);
|
54
46
|
}
|
55
47
|
|
56
48
|
throw new Error("Expect returning a value, but all middlewares just calling next()");
|
57
49
|
}
|
58
50
|
|
59
|
-
return
|
60
|
-
return middlewares[index](input, next);
|
61
|
-
}, hooks);
|
51
|
+
return middlewares[index](input, next);
|
62
52
|
});
|
63
53
|
};
|
64
54
|
|
65
|
-
var
|
66
|
-
var currentHooks = fromContainer(currentContainer);
|
67
|
-
var currentCounter = createCurrentCounter(currentHooks);
|
55
|
+
var currentCounter = createCurrentCounter();
|
68
56
|
|
69
57
|
var getCounter = function getCounter(options) {
|
70
58
|
if (!options) {
|
71
59
|
return currentCounter;
|
72
60
|
}
|
73
61
|
|
74
|
-
|
75
|
-
var hooks = fromContainer(options === null || options === void 0 ? void 0 : options.container);
|
76
|
-
return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(hooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(hooks);
|
77
|
-
}
|
78
|
-
|
79
|
-
return options !== null && options !== void 0 && options.onLast ? createCurrentCounter(currentHooks, options.onLast, typeof options.onLastWithContext === 'boolean' ? options.onLastWithContext : true) : createCurrentCounter(currentHooks);
|
62
|
+
return createCurrentCounter(options === null || options === void 0 ? void 0 : options.onLast);
|
80
63
|
};
|
81
64
|
|
82
65
|
var run = function run(input, options) {
|
@@ -84,9 +67,7 @@ export var createPipeline = function createPipeline(options) {
|
|
84
67
|
};
|
85
68
|
|
86
69
|
var middleware = function middleware(input, next) {
|
87
|
-
var container = useContainer();
|
88
70
|
return run(input, {
|
89
|
-
container: container,
|
90
71
|
onLast: next
|
91
72
|
});
|
92
73
|
};
|
@@ -94,7 +75,7 @@ export var createPipeline = function createPipeline(options) {
|
|
94
75
|
var pipeline = (_pipeline = {}, _defineProperty(_pipeline, PipelineSymbol, true), _defineProperty(_pipeline, "use", use), _defineProperty(_pipeline, "run", run), _defineProperty(_pipeline, "middleware", middleware), _pipeline);
|
95
76
|
return pipeline;
|
96
77
|
};
|
97
|
-
export var createAsyncPipeline = function createAsyncPipeline(
|
98
|
-
var pipeline = createPipeline(
|
78
|
+
export var createAsyncPipeline = function createAsyncPipeline() {
|
79
|
+
var pipeline = createPipeline();
|
99
80
|
return _objectSpread({}, pipeline);
|
100
81
|
};
|