@midwayjs/faas 3.6.0 → 3.7.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/dist/configuration.js +2 -1
- package/dist/framework.d.ts +1 -1
- package/dist/framework.js +95 -97
- package/dist/interface.d.ts +2 -2
- package/package.json +6 -6
package/dist/configuration.js
CHANGED
|
@@ -26,7 +26,8 @@ let FaaSConfiguration = class FaaSConfiguration {
|
|
|
26
26
|
this.framework.getLogger());
|
|
27
27
|
});
|
|
28
28
|
this.decoratorService.registerParameterHandler(core_1.WEB_ROUTER_PARAM_KEY, options => {
|
|
29
|
-
|
|
29
|
+
var _a;
|
|
30
|
+
return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType, (_a = options.metadata) === null || _a === void 0 ? void 0 : _a.pipes)(options.originArgs[0], options.originArgs[1]);
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
async onReady(container) { }
|
package/dist/framework.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
|
|
|
32
32
|
* @param handlerMapping
|
|
33
33
|
*/
|
|
34
34
|
handleInvokeWrapper(handlerMapping: string): (...args: any[]) => Promise<any>;
|
|
35
|
-
getTriggerFunction(
|
|
35
|
+
getTriggerFunction(context: any, handlerMapping: string, options: HandlerOptions): Promise<any>;
|
|
36
36
|
wrapHttpRequest(req: http.IncomingMessage | Record<string, any>, res?: http.ServerResponse): Promise<unknown>;
|
|
37
37
|
/**
|
|
38
38
|
* @deprecated
|
package/dist/framework.js
CHANGED
|
@@ -97,8 +97,8 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
97
97
|
.createAnonymousContext()
|
|
98
98
|
.requestContext.getAsync(serviceClass);
|
|
99
99
|
},
|
|
100
|
-
getTriggerFunction: (handlerMapping) => {
|
|
101
|
-
return this.getTriggerFunction(handlerMapping);
|
|
100
|
+
getTriggerFunction: (context, handlerMapping, options) => {
|
|
101
|
+
return this.getTriggerFunction(context, handlerMapping, options);
|
|
102
102
|
},
|
|
103
103
|
});
|
|
104
104
|
// hack use method
|
|
@@ -192,115 +192,113 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
192
192
|
return await composeMiddleware(context);
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
|
-
getTriggerFunction(handlerMapping) {
|
|
195
|
+
async getTriggerFunction(context, handlerMapping, options) {
|
|
196
|
+
var _a, _b;
|
|
196
197
|
let funOptions = this.funMappingStore.get(handlerMapping);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const matchRes = core_1.PathToRegexpUtil.match(funOptions.fullUrlFlattenString)(context.path);
|
|
204
|
-
context.req.pathParameters = matchRes['params'] || {};
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (!funOptions) {
|
|
208
|
-
throw new Error(`function handler = ${handlerMapping} not found`);
|
|
198
|
+
const isHttpFunction = options.isHttpFunction;
|
|
199
|
+
if (!funOptions && isHttpFunction) {
|
|
200
|
+
funOptions = await this.serverlessFunctionService.getMatchedRouterInfo(context.path, context.method);
|
|
201
|
+
if (funOptions) {
|
|
202
|
+
const matchRes = core_1.PathToRegexpUtil.match(funOptions.fullUrlFlattenString)(context.path);
|
|
203
|
+
context.req.pathParameters = matchRes['params'] || {};
|
|
209
204
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
205
|
+
}
|
|
206
|
+
if (!funOptions) {
|
|
207
|
+
throw new Error(`function handler = ${handlerMapping} not found`);
|
|
208
|
+
}
|
|
209
|
+
context = this.getContext(context);
|
|
210
|
+
if ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.runContextHook) {
|
|
211
|
+
this.configurationOptions.applicationAdapter.runContextHook(context);
|
|
212
|
+
}
|
|
213
|
+
const result = await (await this.applyMiddleware(async (ctx, next) => {
|
|
214
|
+
const fn = await this.middlewareService.compose([
|
|
215
|
+
...(isHttpFunction
|
|
216
|
+
? this.httpMiddlewareManager
|
|
217
|
+
: this.eventMiddlewareManager),
|
|
218
|
+
...funOptions.controllerMiddleware,
|
|
219
|
+
...funOptions.middleware,
|
|
220
|
+
async (ctx, next) => {
|
|
221
|
+
let args;
|
|
222
|
+
if (isHttpFunction) {
|
|
223
|
+
args = [ctx];
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
args = [options.originEvent, options.originContext];
|
|
227
|
+
}
|
|
228
|
+
// invoke handler
|
|
229
|
+
const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
|
|
230
|
+
if (isHttpFunction && result !== undefined) {
|
|
231
|
+
if (result === null) {
|
|
232
|
+
// 这样设置可以绕过 koa 的 _explicitStatus 赋值机制
|
|
233
|
+
ctx.response._body = null;
|
|
225
234
|
}
|
|
226
235
|
else {
|
|
227
|
-
|
|
236
|
+
ctx.body = result;
|
|
228
237
|
}
|
|
229
|
-
// invoke handler
|
|
230
|
-
const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
|
|
231
|
-
if (isHttpFunction && result !== undefined) {
|
|
232
|
-
if (result === null) {
|
|
233
|
-
// 这样设置可以绕过 koa 的 _explicitStatus 赋值机制
|
|
234
|
-
ctx.response._body = null;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
ctx.body = result;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
// http 靠 ctx.body,否则会出现状态码不正确的问题
|
|
241
|
-
if (!isHttpFunction) {
|
|
242
|
-
return result;
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
], this.app);
|
|
246
|
-
return await fn(ctx, next);
|
|
247
|
-
}))(context);
|
|
248
|
-
if (isHttpFunction) {
|
|
249
|
-
if (!((_b = context.response) === null || _b === void 0 ? void 0 : _b._explicitStatus)) {
|
|
250
|
-
if (context.body === null || context.body === 'undefined') {
|
|
251
|
-
context.body = '';
|
|
252
|
-
context.type = 'text';
|
|
253
|
-
context.status = 204;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
let encoded = false;
|
|
257
|
-
let data = context.body;
|
|
258
|
-
if (typeof data === 'string') {
|
|
259
|
-
if (!context.type) {
|
|
260
|
-
context.type = 'text/plain';
|
|
261
238
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
encoded = true;
|
|
266
|
-
if (!context.type) {
|
|
267
|
-
context.type = 'application/octet-stream';
|
|
239
|
+
// http 靠 ctx.body,否则会出现状态码不正确的问题
|
|
240
|
+
if (!isHttpFunction) {
|
|
241
|
+
return result;
|
|
268
242
|
}
|
|
269
|
-
|
|
270
|
-
|
|
243
|
+
},
|
|
244
|
+
], this.app);
|
|
245
|
+
return await fn(ctx, next);
|
|
246
|
+
}))(context);
|
|
247
|
+
if (isHttpFunction) {
|
|
248
|
+
if (!((_b = context.response) === null || _b === void 0 ? void 0 : _b._explicitStatus)) {
|
|
249
|
+
if (context.body === null || context.body === 'undefined') {
|
|
250
|
+
context.body = '';
|
|
251
|
+
context.type = 'text';
|
|
252
|
+
context.status = 204;
|
|
271
253
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
context.
|
|
254
|
+
}
|
|
255
|
+
let encoded = false;
|
|
256
|
+
const data = context.body;
|
|
257
|
+
if (typeof data === 'string') {
|
|
258
|
+
if (!context.type) {
|
|
259
|
+
context.type = 'text/plain';
|
|
278
260
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
context.
|
|
261
|
+
context.body = data;
|
|
262
|
+
}
|
|
263
|
+
else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
|
|
264
|
+
encoded = true;
|
|
265
|
+
if (!context.type) {
|
|
266
|
+
context.type = 'application/octet-stream';
|
|
285
267
|
}
|
|
286
|
-
//
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
context.
|
|
268
|
+
// data is reserved as buffer
|
|
269
|
+
context.body = Buffer.from(data).toString('base64');
|
|
270
|
+
}
|
|
271
|
+
else if (typeof data === 'object') {
|
|
272
|
+
if (!context.type) {
|
|
273
|
+
context.type = 'application/json';
|
|
292
274
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
statusCode: context.status,
|
|
296
|
-
headers: context.res.headers,
|
|
297
|
-
body: context.body,
|
|
298
|
-
};
|
|
275
|
+
// set data to string
|
|
276
|
+
context.body = JSON.stringify(data);
|
|
299
277
|
}
|
|
300
278
|
else {
|
|
301
|
-
|
|
279
|
+
if (!context.type) {
|
|
280
|
+
context.type = 'text/plain';
|
|
281
|
+
}
|
|
282
|
+
// set data to string
|
|
283
|
+
context.body = data + '';
|
|
302
284
|
}
|
|
303
|
-
|
|
285
|
+
// middleware return value and will be got 204 status
|
|
286
|
+
if (context.body === undefined &&
|
|
287
|
+
!context.response._explicitStatus &&
|
|
288
|
+
context._matchedRoute) {
|
|
289
|
+
// 如果进了路由,重新赋值,防止 404
|
|
290
|
+
context.body = undefined;
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
isBase64Encoded: encoded,
|
|
294
|
+
statusCode: context.status,
|
|
295
|
+
headers: context.res.headers,
|
|
296
|
+
body: context.body,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
304
302
|
}
|
|
305
303
|
async wrapHttpRequest(req, res) {
|
|
306
304
|
const newReq = res ? new serverless_http_parser_1.HTTPRequest(req, res) : req;
|
package/dist/interface.d.ts
CHANGED
|
@@ -34,8 +34,8 @@ export declare type IMidwayFaaSApplication = IMidwayApplication<Context, {
|
|
|
34
34
|
*/
|
|
35
35
|
getFunctionServiceName(): string;
|
|
36
36
|
useEventMiddleware(middleware: CommonMiddlewareUnion<Context, NextFunction, undefined>): void;
|
|
37
|
-
getEventMiddleware: ContextMiddlewareManager<Context, NextFunction, undefined>;
|
|
38
|
-
getTriggerFunction(
|
|
37
|
+
getEventMiddleware(): ContextMiddlewareManager<Context, NextFunction, undefined>;
|
|
38
|
+
getTriggerFunction(context: any, handler: string, options: HandlerOptions): Promise<any>;
|
|
39
39
|
getServerlessInstance<T>(serviceClass: T): Promise<T>;
|
|
40
40
|
}> & ServerlessHttpApplication;
|
|
41
41
|
export interface Application extends IMidwayFaaSApplication {
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/faas",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@midwayjs/core": "^3.
|
|
7
|
+
"@midwayjs/core": "^3.7.0",
|
|
8
8
|
"@midwayjs/faas-typings": "^3.6.0",
|
|
9
9
|
"@midwayjs/logger": "^2.15.0",
|
|
10
10
|
"@midwayjs/serverless-http-parser": "^3.6.0",
|
|
11
11
|
"@midwayjs/simple-lock": "^1.1.4"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@midwayjs/mock": "^3.
|
|
15
|
-
"@midwayjs/serverless-fc-starter": "^3.
|
|
16
|
-
"@midwayjs/serverless-scf-starter": "^3.
|
|
14
|
+
"@midwayjs/mock": "^3.7.0",
|
|
15
|
+
"@midwayjs/serverless-fc-starter": "^3.7.0",
|
|
16
|
+
"@midwayjs/serverless-scf-starter": "^3.7.0",
|
|
17
17
|
"mm": "3.2.0"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"url": "git@github.com:midwayjs/midway.git"
|
|
46
46
|
},
|
|
47
47
|
"license": "MIT",
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "99386083ee26b386fd508b9c892091c914e77535"
|
|
49
49
|
}
|