@modern-js/plugin-express 2.15.0 → 2.17.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 +27 -0
- package/dist/cjs/cli/index.js +62 -62
- package/dist/cjs/context.js +13 -26
- package/dist/cjs/index.js +28 -37
- package/dist/cjs/plugin.js +178 -155
- package/dist/cjs/registerRoutes.js +11 -27
- package/dist/cjs/runtime/hook.js +7 -25
- package/dist/cjs/runtime/index.js +30 -31
- package/dist/cjs/runtime/operators.js +15 -28
- package/dist/cjs/utils.js +36 -54
- package/dist/esm/cli/index.js +41 -55
- package/dist/esm/index.js +1 -2
- package/dist/esm/plugin.js +385 -376
- package/dist/esm/registerRoutes.js +12 -13
- package/dist/esm/runtime/hook.js +2 -3
- package/dist/esm/runtime/index.js +2 -3
- package/dist/esm/runtime/operators.js +196 -187
- package/dist/esm/utils.js +541 -515
- package/dist/esm-node/cli/index.js +9 -26
- package/dist/esm-node/context.js +1 -4
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/plugin.js +108 -107
- package/dist/esm-node/registerRoutes.js +1 -4
- package/dist/esm-node/runtime/hook.js +1 -4
- package/dist/esm-node/runtime/index.js +2 -6
- package/dist/esm-node/runtime/operators.js +2 -6
- package/dist/esm-node/utils.js +4 -8
- package/dist/types/runtime/operators.d.ts +1 -1
- package/package.json +18 -11
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { createRouteHandler } from "./utils";
|
|
3
3
|
var registerRoutes = function(app, handlerInfos) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
handlerInfos.forEach(function(param) {
|
|
5
|
+
var routePath = param.routePath, handler = param.handler, httpMethod = param.httpMethod;
|
|
6
|
+
var routeHandler = createRouteHandler(handler);
|
|
7
|
+
var method = httpMethod.toLowerCase();
|
|
8
|
+
var routeMiddlwares = Reflect.getMetadata("middleware", handler) || [];
|
|
9
|
+
if (routeMiddlwares.length > 0) {
|
|
10
|
+
app[method](routePath, routeMiddlwares, routeHandler);
|
|
11
|
+
} else {
|
|
12
|
+
app[method](routePath, routeHandler);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
export { registerRoutes_default as default };
|
|
16
|
+
export default registerRoutes;
|
package/dist/esm/runtime/hook.js
CHANGED
|
@@ -1,198 +1,207 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
|
-
var __generator =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
var __generator = function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1)
|
|
35
|
+
throw t[1];
|
|
36
|
+
return t[1];
|
|
37
|
+
},
|
|
38
|
+
trys: [],
|
|
39
|
+
ops: []
|
|
40
|
+
};
|
|
41
|
+
return g = {
|
|
42
|
+
next: verb(0),
|
|
43
|
+
"throw": verb(1),
|
|
44
|
+
"return": verb(2)
|
|
45
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
46
|
+
return this;
|
|
47
|
+
}), g;
|
|
48
|
+
function verb(n) {
|
|
49
|
+
return function(v) {
|
|
50
|
+
return step([
|
|
51
|
+
n,
|
|
52
|
+
v
|
|
53
|
+
]);
|
|
39
54
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
break;
|
|
68
|
-
case 4:
|
|
69
|
-
_.label++;
|
|
70
|
-
return {
|
|
71
|
-
value: op[1],
|
|
72
|
-
done: false
|
|
73
|
-
};
|
|
74
|
-
case 5:
|
|
75
|
-
_.label++;
|
|
76
|
-
y = op[1];
|
|
77
|
-
op = [
|
|
78
|
-
0
|
|
79
|
-
];
|
|
80
|
-
continue;
|
|
81
|
-
case 7:
|
|
82
|
-
op = _.ops.pop();
|
|
83
|
-
_.trys.pop();
|
|
84
|
-
continue;
|
|
85
|
-
default:
|
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
-
_ = 0;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
-
_.label = op[1];
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
-
_.label = t[1];
|
|
96
|
-
t = op;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (t && _.label < t[2]) {
|
|
100
|
-
_.label = t[2];
|
|
101
|
-
_.ops.push(op);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
if (t[2]) _.ops.pop();
|
|
105
|
-
_.trys.pop();
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
op = body.call(thisArg, _);
|
|
109
|
-
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f)
|
|
58
|
+
throw new TypeError("Generator is already executing.");
|
|
59
|
+
while (_)
|
|
60
|
+
try {
|
|
61
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
62
|
+
return t;
|
|
63
|
+
if (y = 0, t)
|
|
64
|
+
op = [
|
|
65
|
+
op[0] & 2,
|
|
66
|
+
t.value
|
|
67
|
+
];
|
|
68
|
+
switch (op[0]) {
|
|
69
|
+
case 0:
|
|
70
|
+
case 1:
|
|
71
|
+
t = op;
|
|
72
|
+
break;
|
|
73
|
+
case 4:
|
|
74
|
+
_.label++;
|
|
75
|
+
return {
|
|
76
|
+
value: op[1],
|
|
77
|
+
done: false
|
|
78
|
+
};
|
|
79
|
+
case 5:
|
|
80
|
+
_.label++;
|
|
81
|
+
y = op[1];
|
|
110
82
|
op = [
|
|
111
|
-
|
|
112
|
-
e
|
|
83
|
+
0
|
|
113
84
|
];
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
85
|
+
continue;
|
|
86
|
+
case 7:
|
|
87
|
+
op = _.ops.pop();
|
|
88
|
+
_.trys.pop();
|
|
89
|
+
continue;
|
|
90
|
+
default:
|
|
91
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
92
|
+
_ = 0;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
96
|
+
_.label = op[1];
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
100
|
+
_.label = t[1];
|
|
101
|
+
t = op;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t && _.label < t[2]) {
|
|
105
|
+
_.label = t[2];
|
|
106
|
+
_.ops.push(op);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (t[2])
|
|
110
|
+
_.ops.pop();
|
|
111
|
+
_.trys.pop();
|
|
112
|
+
continue;
|
|
117
113
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
op = body.call(thisArg, _);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
op = [
|
|
117
|
+
6,
|
|
118
|
+
e
|
|
119
|
+
];
|
|
120
|
+
y = 0;
|
|
121
|
+
} finally {
|
|
122
|
+
f = t = 0;
|
|
123
|
+
}
|
|
124
|
+
if (op[0] & 5)
|
|
125
|
+
throw op[1];
|
|
127
126
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function execute(executeHelper, next) {
|
|
131
|
-
return _asyncToGenerator(function() {
|
|
132
|
-
var inputs, ctx, res, isPiped, end, output;
|
|
133
|
-
return __generator(this, function(_state) {
|
|
134
|
-
switch(_state.label){
|
|
135
|
-
case 0:
|
|
136
|
-
inputs = executeHelper.inputs;
|
|
137
|
-
ctx = useContext();
|
|
138
|
-
res = ctx.res;
|
|
139
|
-
if (!(typeof func === "function")) return [
|
|
140
|
-
3,
|
|
141
|
-
3
|
|
142
|
-
];
|
|
143
|
-
isPiped = true;
|
|
144
|
-
end = function(value) {
|
|
145
|
-
isPiped = false;
|
|
146
|
-
if (typeof value === "function") {
|
|
147
|
-
value(res);
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
return value;
|
|
151
|
-
};
|
|
152
|
-
return [
|
|
153
|
-
4,
|
|
154
|
-
func(inputs, end)
|
|
155
|
-
];
|
|
156
|
-
case 1:
|
|
157
|
-
output = _state.sent();
|
|
158
|
-
if (!isPiped) {
|
|
159
|
-
if (output) {
|
|
160
|
-
return [
|
|
161
|
-
2,
|
|
162
|
-
executeHelper.result = output
|
|
163
|
-
];
|
|
164
|
-
} else {
|
|
165
|
-
return [
|
|
166
|
-
2
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
executeHelper.inputs = output;
|
|
171
|
-
return [
|
|
172
|
-
4,
|
|
173
|
-
next()
|
|
174
|
-
];
|
|
175
|
-
case 2:
|
|
176
|
-
_state.sent();
|
|
177
|
-
_state.label = 3;
|
|
178
|
-
case 3:
|
|
179
|
-
return [
|
|
180
|
-
2
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
})();
|
|
185
|
-
}
|
|
127
|
+
value: op[0] ? op[1] : void 0,
|
|
128
|
+
done: true
|
|
186
129
|
};
|
|
130
|
+
}
|
|
187
131
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
132
|
+
import { useContext } from "../context";
|
|
133
|
+
export var Pipe = function(func) {
|
|
134
|
+
return {
|
|
135
|
+
name: "pipe",
|
|
136
|
+
execute: (
|
|
137
|
+
// eslint-disable-next-line consistent-return
|
|
138
|
+
function execute(executeHelper, next) {
|
|
139
|
+
return _async_to_generator(function() {
|
|
140
|
+
var inputs, ctx, res, isPiped, end, output;
|
|
141
|
+
return __generator(this, function(_state) {
|
|
142
|
+
switch (_state.label) {
|
|
143
|
+
case 0:
|
|
144
|
+
inputs = executeHelper.inputs;
|
|
145
|
+
ctx = useContext();
|
|
146
|
+
res = ctx.res;
|
|
147
|
+
if (!(typeof func === "function"))
|
|
148
|
+
return [
|
|
149
|
+
3,
|
|
150
|
+
3
|
|
151
|
+
];
|
|
152
|
+
isPiped = true;
|
|
153
|
+
end = function(value) {
|
|
154
|
+
isPiped = false;
|
|
155
|
+
if (typeof value === "function") {
|
|
156
|
+
value(res);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
160
|
+
};
|
|
161
|
+
return [
|
|
162
|
+
4,
|
|
163
|
+
func(inputs, end)
|
|
164
|
+
];
|
|
165
|
+
case 1:
|
|
166
|
+
output = _state.sent();
|
|
167
|
+
if (!isPiped) {
|
|
168
|
+
if (output) {
|
|
169
|
+
return [
|
|
170
|
+
2,
|
|
171
|
+
executeHelper.result = output
|
|
172
|
+
];
|
|
173
|
+
} else {
|
|
174
|
+
return [
|
|
175
|
+
2
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
executeHelper.inputs = output;
|
|
180
|
+
return [
|
|
181
|
+
4,
|
|
182
|
+
next()
|
|
183
|
+
];
|
|
184
|
+
case 2:
|
|
185
|
+
_state.sent();
|
|
186
|
+
_state.label = 3;
|
|
187
|
+
case 3:
|
|
188
|
+
return [
|
|
189
|
+
2
|
|
190
|
+
];
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
})();
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
export var Middleware = function(middleware) {
|
|
199
|
+
return {
|
|
200
|
+
name: "middleware",
|
|
201
|
+
metadata: function metadata(helper) {
|
|
202
|
+
var middlewares = helper.getMetadata("pipe") || [];
|
|
203
|
+
middlewares.push(middleware);
|
|
204
|
+
helper.setMetadata("middleware", middlewares);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
197
207
|
};
|
|
198
|
-
export { Middleware, Pipe };
|