@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.
@@ -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
- return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
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) { }
@@ -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(handlerMapping: string): (context: any, options: HandlerOptions) => Promise<any>;
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
- return async (context, options) => {
198
- var _a, _b;
199
- const isHttpFunction = options.isHttpFunction;
200
- if (!funOptions && isHttpFunction) {
201
- funOptions = await this.serverlessFunctionService.getMatchedRouterInfo(context.path, context.method);
202
- if (funOptions) {
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
- context = this.getContext(context);
211
- if ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.runContextHook) {
212
- this.configurationOptions.applicationAdapter.runContextHook(context);
213
- }
214
- const result = await (await this.applyMiddleware(async (ctx, next) => {
215
- const fn = await this.middlewareService.compose([
216
- ...(isHttpFunction
217
- ? this.httpMiddlewareManager
218
- : this.eventMiddlewareManager),
219
- ...funOptions.controllerMiddleware,
220
- ...funOptions.middleware,
221
- async (ctx, next) => {
222
- let args;
223
- if (isHttpFunction) {
224
- args = [ctx];
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
- args = [options.originEvent, options.originContext];
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
- context.body = data;
263
- }
264
- else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
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
- // data is reserved as buffer
270
- context.body = Buffer.from(data).toString('base64');
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
- else if (typeof data === 'object') {
273
- if (!context.type) {
274
- context.type = 'application/json';
275
- }
276
- // set data to string
277
- context.body = data = JSON.stringify(data);
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
- else {
280
- if (!context.type) {
281
- context.type = 'text/plain';
282
- }
283
- // set data to string
284
- context.body = data = data + '';
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
- // middleware return value and will be got 204 status
287
- if (context.body === undefined &&
288
- !context.response._explicitStatus &&
289
- context._matchedRoute) {
290
- // 如果进了路由,重新赋值,防止 404
291
- context.body = undefined;
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
- return {
294
- isBase64Encoded: encoded,
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
- return result;
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;
@@ -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(handler: string): (context: any, options: HandlerOptions) => Promise<any>;
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.6.0",
3
+ "version": "3.7.0",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
7
- "@midwayjs/core": "^3.6.0",
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.6.0",
15
- "@midwayjs/serverless-fc-starter": "^3.6.0",
16
- "@midwayjs/serverless-scf-starter": "^3.6.0",
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": "22643b0e8519766bb7c68b975930199fc136336e"
48
+ "gitHead": "99386083ee26b386fd508b9c892091c914e77535"
49
49
  }