@modern-js/plugin-koa 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 +25 -0
- package/dist/cjs/cli/index.js +57 -50
- package/dist/cjs/context.js +13 -26
- package/dist/cjs/index.js +28 -37
- package/dist/cjs/plugin.js +158 -134
- package/dist/cjs/registerRoutes.js +10 -26
- package/dist/cjs/runtime.js +27 -28
- package/dist/cjs/utils.js +36 -54
- package/dist/esm/cli/index.js +47 -47
- package/dist/esm/index.js +1 -2
- package/dist/esm/plugin.js +374 -365
- package/dist/esm/registerRoutes.js +7 -8
- package/dist/esm/runtime.js +3 -4
- package/dist/esm/utils.js +391 -369
- package/dist/esm-node/cli/index.js +7 -17
- package/dist/esm-node/context.js +1 -4
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/plugin.js +94 -92
- package/dist/esm-node/registerRoutes.js +1 -4
- package/dist/esm-node/runtime.js +2 -6
- package/dist/esm-node/utils.js +14 -23
- package/package.json +15 -11
package/dist/esm/utils.js
CHANGED
|
@@ -1,410 +1,432 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
5
7
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
8
11
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
12
|
+
function _array_without_holes(arr) {
|
|
13
|
+
if (Array.isArray(arr))
|
|
14
|
+
return _array_like_to_array(arr);
|
|
11
15
|
}
|
|
12
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
try {
|
|
18
|
+
var info = gen[key](arg);
|
|
19
|
+
var value = info.value;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
reject(error);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (info.done) {
|
|
25
|
+
resolve(value);
|
|
26
|
+
} else {
|
|
27
|
+
Promise.resolve(value).then(_next, _throw);
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
function _async_to_generator(fn) {
|
|
31
|
+
return function() {
|
|
32
|
+
var self = this, args = arguments;
|
|
33
|
+
return new Promise(function(resolve, reject) {
|
|
34
|
+
var gen = fn.apply(self, args);
|
|
35
|
+
function _next(value) {
|
|
36
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
37
|
+
}
|
|
38
|
+
function _throw(err) {
|
|
39
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
40
|
+
}
|
|
41
|
+
_next(void 0);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
40
44
|
}
|
|
41
45
|
function _instanceof(left, right) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
47
|
+
return !!right[Symbol.hasInstance](left);
|
|
48
|
+
} else {
|
|
49
|
+
return left instanceof right;
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
52
|
+
function _iterable_to_array(iter) {
|
|
53
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
54
|
+
return Array.from(iter);
|
|
50
55
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
function _iterable_to_array_limit(arr, i) {
|
|
57
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
58
|
+
if (_i == null)
|
|
59
|
+
return;
|
|
60
|
+
var _arr = [];
|
|
61
|
+
var _n = true;
|
|
62
|
+
var _d = false;
|
|
63
|
+
var _s, _e;
|
|
64
|
+
try {
|
|
65
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
66
|
+
_arr.push(_s.value);
|
|
67
|
+
if (i && _arr.length === i)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
_d = true;
|
|
72
|
+
_e = err;
|
|
73
|
+
} finally {
|
|
58
74
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
_d = true;
|
|
65
|
-
_e = err;
|
|
66
|
-
} finally{
|
|
67
|
-
try {
|
|
68
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
69
|
-
} finally{
|
|
70
|
-
if (_d) throw _e;
|
|
71
|
-
}
|
|
75
|
+
if (!_n && _i["return"] != null)
|
|
76
|
+
_i["return"]();
|
|
77
|
+
} finally {
|
|
78
|
+
if (_d)
|
|
79
|
+
throw _e;
|
|
72
80
|
}
|
|
73
|
-
|
|
81
|
+
}
|
|
82
|
+
return _arr;
|
|
74
83
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
84
|
+
function _non_iterable_rest() {
|
|
85
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
86
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
87
|
+
function _non_iterable_spread() {
|
|
88
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
80
89
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
90
|
+
function _sliced_to_array(arr, i) {
|
|
91
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
83
92
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
93
|
+
function _to_consumable_array(arr) {
|
|
94
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
86
95
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
97
|
+
if (!o)
|
|
98
|
+
return;
|
|
99
|
+
if (typeof o === "string")
|
|
100
|
+
return _array_like_to_array(o, minLen);
|
|
101
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
102
|
+
if (n === "Object" && o.constructor)
|
|
103
|
+
n = o.constructor.name;
|
|
104
|
+
if (n === "Map" || n === "Set")
|
|
105
|
+
return Array.from(n);
|
|
106
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
107
|
+
return _array_like_to_array(o, minLen);
|
|
94
108
|
}
|
|
95
|
-
var __generator =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
var __generator = function(thisArg, body) {
|
|
110
|
+
var f, y, t, g, _ = {
|
|
111
|
+
label: 0,
|
|
112
|
+
sent: function() {
|
|
113
|
+
if (t[0] & 1)
|
|
114
|
+
throw t[1];
|
|
115
|
+
return t[1];
|
|
116
|
+
},
|
|
117
|
+
trys: [],
|
|
118
|
+
ops: []
|
|
119
|
+
};
|
|
120
|
+
return g = {
|
|
121
|
+
next: verb(0),
|
|
122
|
+
"throw": verb(1),
|
|
123
|
+
"return": verb(2)
|
|
124
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
125
|
+
return this;
|
|
126
|
+
}), g;
|
|
127
|
+
function verb(n) {
|
|
128
|
+
return function(v) {
|
|
129
|
+
return step([
|
|
130
|
+
n,
|
|
131
|
+
v
|
|
132
|
+
]);
|
|
104
133
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
break;
|
|
133
|
-
case 4:
|
|
134
|
-
_.label++;
|
|
135
|
-
return {
|
|
136
|
-
value: op[1],
|
|
137
|
-
done: false
|
|
138
|
-
};
|
|
139
|
-
case 5:
|
|
140
|
-
_.label++;
|
|
141
|
-
y = op[1];
|
|
142
|
-
op = [
|
|
143
|
-
0
|
|
144
|
-
];
|
|
145
|
-
continue;
|
|
146
|
-
case 7:
|
|
147
|
-
op = _.ops.pop();
|
|
148
|
-
_.trys.pop();
|
|
149
|
-
continue;
|
|
150
|
-
default:
|
|
151
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
152
|
-
_ = 0;
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
156
|
-
_.label = op[1];
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
160
|
-
_.label = t[1];
|
|
161
|
-
t = op;
|
|
162
|
-
break;
|
|
163
|
-
}
|
|
164
|
-
if (t && _.label < t[2]) {
|
|
165
|
-
_.label = t[2];
|
|
166
|
-
_.ops.push(op);
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
if (t[2]) _.ops.pop();
|
|
170
|
-
_.trys.pop();
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
op = body.call(thisArg, _);
|
|
174
|
-
} catch (e) {
|
|
134
|
+
}
|
|
135
|
+
function step(op) {
|
|
136
|
+
if (f)
|
|
137
|
+
throw new TypeError("Generator is already executing.");
|
|
138
|
+
while (_)
|
|
139
|
+
try {
|
|
140
|
+
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)
|
|
141
|
+
return t;
|
|
142
|
+
if (y = 0, t)
|
|
143
|
+
op = [
|
|
144
|
+
op[0] & 2,
|
|
145
|
+
t.value
|
|
146
|
+
];
|
|
147
|
+
switch (op[0]) {
|
|
148
|
+
case 0:
|
|
149
|
+
case 1:
|
|
150
|
+
t = op;
|
|
151
|
+
break;
|
|
152
|
+
case 4:
|
|
153
|
+
_.label++;
|
|
154
|
+
return {
|
|
155
|
+
value: op[1],
|
|
156
|
+
done: false
|
|
157
|
+
};
|
|
158
|
+
case 5:
|
|
159
|
+
_.label++;
|
|
160
|
+
y = op[1];
|
|
175
161
|
op = [
|
|
176
|
-
|
|
177
|
-
e
|
|
162
|
+
0
|
|
178
163
|
];
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
164
|
+
continue;
|
|
165
|
+
case 7:
|
|
166
|
+
op = _.ops.pop();
|
|
167
|
+
_.trys.pop();
|
|
168
|
+
continue;
|
|
169
|
+
default:
|
|
170
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
171
|
+
_ = 0;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
175
|
+
_.label = op[1];
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
179
|
+
_.label = t[1];
|
|
180
|
+
t = op;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
if (t && _.label < t[2]) {
|
|
184
|
+
_.label = t[2];
|
|
185
|
+
_.ops.push(op);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (t[2])
|
|
189
|
+
_.ops.pop();
|
|
190
|
+
_.trys.pop();
|
|
191
|
+
continue;
|
|
182
192
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
193
|
+
op = body.call(thisArg, _);
|
|
194
|
+
} catch (e) {
|
|
195
|
+
op = [
|
|
196
|
+
6,
|
|
197
|
+
e
|
|
198
|
+
];
|
|
199
|
+
y = 0;
|
|
200
|
+
} finally {
|
|
201
|
+
f = t = 0;
|
|
202
|
+
}
|
|
203
|
+
if (op[0] & 5)
|
|
204
|
+
throw op[1];
|
|
205
|
+
return {
|
|
206
|
+
value: op[0] ? op[1] : void 0,
|
|
207
|
+
done: true
|
|
208
|
+
};
|
|
209
|
+
}
|
|
189
210
|
};
|
|
190
211
|
import { httpMethods, isWithMetaHandler, ResponseMetaType, HttpMetadata } from "@modern-js/bff-core";
|
|
191
212
|
import { isSchemaHandler } from "@modern-js/bff-runtime";
|
|
192
213
|
import typeIs from "type-is";
|
|
193
214
|
var handleResponseMeta = function(ctx, handler) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
try {
|
|
206
|
-
for(var _iterator1 = Object.entries(metaValue)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
207
|
-
var _step_value = _slicedToArray(_step1.value, 2), key = _step_value[0], value = _step_value[1];
|
|
208
|
-
if (typeof value === "string") {
|
|
209
|
-
ctx.append(key, value);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_didIteratorError1 = true;
|
|
214
|
-
_iteratorError1 = err;
|
|
215
|
-
} finally{
|
|
216
|
-
try {
|
|
217
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
218
|
-
_iterator1.return();
|
|
219
|
-
}
|
|
220
|
-
} finally{
|
|
221
|
-
if (_didIteratorError1) {
|
|
222
|
-
throw _iteratorError1;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
case ResponseMetaType.Redirect:
|
|
228
|
-
if (typeof metaValue === "string") {
|
|
229
|
-
ctx.redirect(metaValue);
|
|
230
|
-
}
|
|
231
|
-
break;
|
|
232
|
-
case ResponseMetaType.StatusCode:
|
|
233
|
-
if (typeof metaValue === "number") {
|
|
234
|
-
ctx.status = metaValue;
|
|
235
|
-
}
|
|
236
|
-
break;
|
|
237
|
-
default:
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
} catch (err) {
|
|
242
|
-
_didIteratorError = true;
|
|
243
|
-
_iteratorError = err;
|
|
244
|
-
} finally{
|
|
215
|
+
var responseMeta = Reflect.getMetadata(HttpMetadata.Response, handler);
|
|
216
|
+
if (Array.isArray(responseMeta)) {
|
|
217
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
218
|
+
try {
|
|
219
|
+
for (var _iterator = responseMeta[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
220
|
+
var meta = _step.value;
|
|
221
|
+
var metaType = meta.type;
|
|
222
|
+
var metaValue = meta.value;
|
|
223
|
+
switch (metaType) {
|
|
224
|
+
case ResponseMetaType.Headers:
|
|
225
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
245
226
|
try {
|
|
246
|
-
|
|
247
|
-
|
|
227
|
+
for (var _iterator1 = Object.entries(metaValue)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
228
|
+
var _step_value = _sliced_to_array(_step1.value, 2), key = _step_value[0], value = _step_value[1];
|
|
229
|
+
if (typeof value === "string") {
|
|
230
|
+
ctx.append(key, value);
|
|
248
231
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
232
|
+
}
|
|
233
|
+
} catch (err) {
|
|
234
|
+
_didIteratorError1 = true;
|
|
235
|
+
_iteratorError1 = err;
|
|
236
|
+
} finally {
|
|
237
|
+
try {
|
|
238
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
239
|
+
_iterator1.return();
|
|
252
240
|
}
|
|
241
|
+
} finally {
|
|
242
|
+
if (_didIteratorError1) {
|
|
243
|
+
throw _iteratorError1;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
case ResponseMetaType.Redirect:
|
|
249
|
+
if (typeof metaValue === "string") {
|
|
250
|
+
ctx.redirect(metaValue);
|
|
253
251
|
}
|
|
252
|
+
break;
|
|
253
|
+
case ResponseMetaType.StatusCode:
|
|
254
|
+
if (typeof metaValue === "number") {
|
|
255
|
+
ctx.status = metaValue;
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} catch (err) {
|
|
263
|
+
_didIteratorError = true;
|
|
264
|
+
_iteratorError = err;
|
|
265
|
+
} finally {
|
|
266
|
+
try {
|
|
267
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
268
|
+
_iterator.return();
|
|
269
|
+
}
|
|
270
|
+
} finally {
|
|
271
|
+
if (_didIteratorError) {
|
|
272
|
+
throw _iteratorError;
|
|
254
273
|
}
|
|
274
|
+
}
|
|
255
275
|
}
|
|
276
|
+
}
|
|
256
277
|
};
|
|
257
|
-
var createRouteHandler = function(handler) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
];
|
|
311
|
-
}
|
|
312
|
-
return [
|
|
313
|
-
3,
|
|
314
|
-
5
|
|
315
|
-
];
|
|
316
|
-
case 5:
|
|
317
|
-
return [
|
|
318
|
-
3,
|
|
319
|
-
10
|
|
320
|
-
];
|
|
321
|
-
case 6:
|
|
322
|
-
if (!isSchemaHandler(handler)) return [
|
|
323
|
-
3,
|
|
324
|
-
8
|
|
325
|
-
];
|
|
326
|
-
return [
|
|
327
|
-
4,
|
|
328
|
-
handler(input)
|
|
329
|
-
];
|
|
330
|
-
case 7:
|
|
331
|
-
result = _state.sent();
|
|
332
|
-
if (result.type !== "HandleSuccess") {
|
|
333
|
-
if (result.type === "InputValidationError") {
|
|
334
|
-
ctx.status = 400;
|
|
335
|
-
} else {
|
|
336
|
-
ctx.status = 500;
|
|
337
|
-
}
|
|
338
|
-
ctx.body = result.message;
|
|
339
|
-
} else {
|
|
340
|
-
ctx.body = result.value;
|
|
341
|
-
}
|
|
342
|
-
return [
|
|
343
|
-
3,
|
|
344
|
-
10
|
|
345
|
-
];
|
|
346
|
-
case 8:
|
|
347
|
-
args = Object.values(input.params).concat(input);
|
|
348
|
-
return [
|
|
349
|
-
4,
|
|
350
|
-
handler.apply(void 0, _toConsumableArray(args))
|
|
351
|
-
];
|
|
352
|
-
case 9:
|
|
353
|
-
body1 = _state.sent();
|
|
354
|
-
if (typeof body1 !== "undefined") {
|
|
355
|
-
ctx.body = body1;
|
|
356
|
-
}
|
|
357
|
-
_state.label = 10;
|
|
358
|
-
case 10:
|
|
359
|
-
return [
|
|
360
|
-
2
|
|
361
|
-
];
|
|
278
|
+
export var createRouteHandler = function(handler) {
|
|
279
|
+
var apiHandler = function() {
|
|
280
|
+
var _ref = _async_to_generator(function(ctx) {
|
|
281
|
+
var input, body, error, result, args, body1;
|
|
282
|
+
return __generator(this, function(_state) {
|
|
283
|
+
switch (_state.label) {
|
|
284
|
+
case 0:
|
|
285
|
+
return [
|
|
286
|
+
4,
|
|
287
|
+
getInputFromRequest(ctx)
|
|
288
|
+
];
|
|
289
|
+
case 1:
|
|
290
|
+
input = _state.sent();
|
|
291
|
+
if (!isWithMetaHandler(handler))
|
|
292
|
+
return [
|
|
293
|
+
3,
|
|
294
|
+
6
|
|
295
|
+
];
|
|
296
|
+
_state.label = 2;
|
|
297
|
+
case 2:
|
|
298
|
+
_state.trys.push([
|
|
299
|
+
2,
|
|
300
|
+
4,
|
|
301
|
+
,
|
|
302
|
+
5
|
|
303
|
+
]);
|
|
304
|
+
handleResponseMeta(ctx, handler);
|
|
305
|
+
return [
|
|
306
|
+
4,
|
|
307
|
+
handler(input)
|
|
308
|
+
];
|
|
309
|
+
case 3:
|
|
310
|
+
body = _state.sent();
|
|
311
|
+
if (typeof body !== "undefined") {
|
|
312
|
+
ctx.body = body;
|
|
313
|
+
}
|
|
314
|
+
return [
|
|
315
|
+
3,
|
|
316
|
+
5
|
|
317
|
+
];
|
|
318
|
+
case 4:
|
|
319
|
+
error = _state.sent();
|
|
320
|
+
if (_instanceof(error, Error)) {
|
|
321
|
+
if (error.status) {
|
|
322
|
+
ctx.status = error.status;
|
|
323
|
+
} else {
|
|
324
|
+
ctx.status = 500;
|
|
325
|
+
}
|
|
326
|
+
return [
|
|
327
|
+
2,
|
|
328
|
+
ctx.body = {
|
|
329
|
+
code: error.code,
|
|
330
|
+
message: error.message
|
|
362
331
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
} else if (typeIs.is(ctx.request.type, [
|
|
394
|
-
"application/x-www-form-urlencoded"
|
|
395
|
-
])) {
|
|
396
|
-
draft.formUrlencoded = ctx.request.body;
|
|
332
|
+
];
|
|
333
|
+
}
|
|
334
|
+
return [
|
|
335
|
+
3,
|
|
336
|
+
5
|
|
337
|
+
];
|
|
338
|
+
case 5:
|
|
339
|
+
return [
|
|
340
|
+
3,
|
|
341
|
+
10
|
|
342
|
+
];
|
|
343
|
+
case 6:
|
|
344
|
+
if (!isSchemaHandler(handler))
|
|
345
|
+
return [
|
|
346
|
+
3,
|
|
347
|
+
8
|
|
348
|
+
];
|
|
349
|
+
return [
|
|
350
|
+
4,
|
|
351
|
+
handler(input)
|
|
352
|
+
];
|
|
353
|
+
case 7:
|
|
354
|
+
result = _state.sent();
|
|
355
|
+
if (result.type !== "HandleSuccess") {
|
|
356
|
+
if (result.type === "InputValidationError") {
|
|
357
|
+
ctx.status = 400;
|
|
358
|
+
} else {
|
|
359
|
+
ctx.status = 500;
|
|
360
|
+
}
|
|
361
|
+
ctx.body = result.message;
|
|
397
362
|
} else {
|
|
398
|
-
|
|
363
|
+
ctx.body = result.value;
|
|
399
364
|
}
|
|
400
365
|
return [
|
|
401
|
-
|
|
402
|
-
|
|
366
|
+
3,
|
|
367
|
+
10
|
|
368
|
+
];
|
|
369
|
+
case 8:
|
|
370
|
+
args = Object.values(input.params).concat(input);
|
|
371
|
+
return [
|
|
372
|
+
4,
|
|
373
|
+
handler.apply(void 0, _to_consumable_array(args))
|
|
403
374
|
];
|
|
404
|
-
|
|
375
|
+
case 9:
|
|
376
|
+
body1 = _state.sent();
|
|
377
|
+
if (typeof body1 !== "undefined") {
|
|
378
|
+
ctx.body = body1;
|
|
379
|
+
}
|
|
380
|
+
_state.label = 10;
|
|
381
|
+
case 10:
|
|
382
|
+
return [
|
|
383
|
+
2
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
405
387
|
});
|
|
406
|
-
return function
|
|
407
|
-
|
|
388
|
+
return function apiHandler2(ctx) {
|
|
389
|
+
return _ref.apply(this, arguments);
|
|
408
390
|
};
|
|
391
|
+
}();
|
|
392
|
+
Object.defineProperties(apiHandler, Object.getOwnPropertyDescriptors(handler));
|
|
393
|
+
return apiHandler;
|
|
394
|
+
};
|
|
395
|
+
export var isNormalMethod = function(httpMethod) {
|
|
396
|
+
return httpMethods.includes(httpMethod);
|
|
397
|
+
};
|
|
398
|
+
var getInputFromRequest = function() {
|
|
399
|
+
var _ref = _async_to_generator(function(ctx) {
|
|
400
|
+
var draft;
|
|
401
|
+
return __generator(this, function(_state) {
|
|
402
|
+
draft = {
|
|
403
|
+
params: ctx.params,
|
|
404
|
+
query: ctx.query,
|
|
405
|
+
headers: ctx.headers,
|
|
406
|
+
cookies: ctx.headers.cookie
|
|
407
|
+
};
|
|
408
|
+
if (typeIs.is(ctx.request.type, [
|
|
409
|
+
"application/json"
|
|
410
|
+
])) {
|
|
411
|
+
draft.data = ctx.request.body;
|
|
412
|
+
} else if (typeIs.is(ctx.request.type, [
|
|
413
|
+
"multipart/form-data"
|
|
414
|
+
])) {
|
|
415
|
+
draft.formData = ctx.request.files;
|
|
416
|
+
} else if (typeIs.is(ctx.request.type, [
|
|
417
|
+
"application/x-www-form-urlencoded"
|
|
418
|
+
])) {
|
|
419
|
+
draft.formUrlencoded = ctx.request.body;
|
|
420
|
+
} else {
|
|
421
|
+
draft.body = ctx.request.body;
|
|
422
|
+
}
|
|
423
|
+
return [
|
|
424
|
+
2,
|
|
425
|
+
draft
|
|
426
|
+
];
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
return function getInputFromRequest2(ctx) {
|
|
430
|
+
return _ref.apply(this, arguments);
|
|
431
|
+
};
|
|
409
432
|
}();
|
|
410
|
-
export { createRouteHandler, isNormalMethod };
|