@midwayjs/faas 3.9.0 → 3.9.1-beta.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.
@@ -0,0 +1,2 @@
1
+ export declare const Event: () => ParameterDecorator;
2
+ //# sourceMappingURL=decorator.d.ts.map
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Event = void 0;
4
+ const core_1 = require("@midwayjs/core");
5
+ // 实现装饰器
6
+ const Event = () => {
7
+ return (0, core_1.createRequestParamDecorator)(ctx => {
8
+ return ctx.originEvent && ctx.originContext ? ctx.originEvent : ctx;
9
+ });
10
+ };
11
+ exports.Event = Event;
12
+ //# sourceMappingURL=decorator.js.map
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions } from './interface';
2
+ import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions, HttpResponseFormat } from './interface';
3
3
  import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IMidwayBootstrapOptions, MidwayEnvironmentService, MidwayFrameworkType, MidwayMiddlewareService, RouterInfo } from '@midwayjs/core';
4
4
  import { LoggerOptions } from '@midwayjs/logger';
5
5
  import * as http from 'http';
@@ -33,6 +33,7 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
33
33
  */
34
34
  handleInvokeWrapper(handlerMapping: string): (...args: any[]) => Promise<any>;
35
35
  invokeTriggerFunction(context: any, handlerMapping: string, options: HandlerOptions): Promise<any>;
36
+ formatHttpResponse(context: any): HttpResponseFormat;
36
37
  wrapHttpRequest(req: http.IncomingMessage | Record<string, any>, res?: http.ServerResponse): Promise<unknown>;
37
38
  /**
38
39
  * @deprecated
package/dist/framework.js CHANGED
@@ -92,33 +92,8 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
92
92
  getEventMiddleware: () => {
93
93
  return this.getEventMiddleware();
94
94
  },
95
- getServerlessInstance: async (serviceClass, customContext = {}) => {
96
- const instance = new Proxy({}, {
97
- get: (target, prop) => {
98
- let funcInfo;
99
- if (typeof serviceClass === 'string') {
100
- funcInfo = this.funMappingStore.get(`${serviceClass}.${prop}`);
101
- }
102
- else {
103
- funcInfo = Array.from(this.funMappingStore.values()).find(item => {
104
- return (item.id === (0, core_1.getProviderUUId)(serviceClass) &&
105
- item.method === prop);
106
- });
107
- }
108
- if (funcInfo) {
109
- return async (...args) => {
110
- const context = this.app.createAnonymousContext({
111
- originContext: customContext,
112
- originEvent: args[0],
113
- });
114
- return this.invokeTriggerFunction(context, funcInfo.funcHandlerName, {
115
- isHttpFunction: false,
116
- });
117
- };
118
- }
119
- },
120
- });
121
- return instance;
95
+ getServerlessInstance: async () => {
96
+ throw new core_1.MidwayFeatureNotImplementedError('Please use it in by @midwayjs/mock in test.');
122
97
  },
123
98
  invokeTriggerFunction: (context, handlerMapping, options) => {
124
99
  return this.invokeTriggerFunction(context, handlerMapping, options);
@@ -216,7 +191,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
216
191
  };
217
192
  }
218
193
  async invokeTriggerFunction(context, handlerMapping, options) {
219
- var _a, _b;
194
+ var _a;
220
195
  let funOptions = this.funMappingStore.get(handlerMapping);
221
196
  const isHttpFunction = options.isHttpFunction;
222
197
  if (!funOptions && isHttpFunction) {
@@ -268,60 +243,66 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
268
243
  return await fn(ctx, next);
269
244
  }))(context);
270
245
  if (isHttpFunction) {
271
- if (!((_b = context.response) === null || _b === void 0 ? void 0 : _b._explicitStatus)) {
272
- if (context.body === null || context.body === 'undefined') {
273
- context.body = '';
274
- context.type = 'text';
275
- context.status = 204;
276
- }
246
+ if (!options.isChunked) {
247
+ return this.formatHttpResponse(context);
277
248
  }
278
- let encoded = false;
279
- const data = context.body;
280
- if (typeof data === 'string') {
281
- if (!context.type) {
282
- context.type = 'text/plain';
283
- }
284
- context.body = data;
285
- }
286
- else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
287
- encoded = true;
288
- if (!context.type) {
289
- context.type = 'application/octet-stream';
290
- }
291
- // data is reserved as buffer
292
- context.body = Buffer.from(data).toString('base64');
249
+ }
250
+ else {
251
+ return result;
252
+ }
253
+ }
254
+ formatHttpResponse(context) {
255
+ var _a;
256
+ if (!((_a = context.response) === null || _a === void 0 ? void 0 : _a._explicitStatus)) {
257
+ if (context.body === null || context.body === 'undefined') {
258
+ context.body = '';
259
+ context.type = 'text';
260
+ context.status = 204;
293
261
  }
294
- else if (typeof data === 'object') {
295
- if (!context.type) {
296
- context.type = 'application/json';
297
- }
298
- // set data to string
299
- context.body = JSON.stringify(data);
262
+ }
263
+ let encoded = false;
264
+ const data = context.body;
265
+ if (typeof data === 'string') {
266
+ if (!context.type) {
267
+ context.type = 'text/plain';
300
268
  }
301
- else {
302
- if (!context.type) {
303
- context.type = 'text/plain';
304
- }
305
- // set data to string
306
- context.body = data + '';
269
+ context.body = data;
270
+ }
271
+ else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
272
+ encoded = true;
273
+ if (!context.type) {
274
+ context.type = 'application/octet-stream';
307
275
  }
308
- // middleware return value and will be got 204 status
309
- if (context.body === undefined &&
310
- !context.response._explicitStatus &&
311
- context._matchedRoute) {
312
- // 如果进了路由,重新赋值,防止 404
313
- context.body = undefined;
276
+ // data is reserved as buffer
277
+ context.body = Buffer.from(data).toString('base64');
278
+ }
279
+ else if (typeof data === 'object') {
280
+ if (!context.type) {
281
+ context.type = 'application/json';
314
282
  }
315
- return {
316
- isBase64Encoded: encoded,
317
- statusCode: context.status,
318
- headers: context.res.headers,
319
- body: context.body,
320
- };
283
+ // set data to string
284
+ context.body = JSON.stringify(data);
321
285
  }
322
286
  else {
323
- return result;
287
+ if (!context.type) {
288
+ context.type = 'text/plain';
289
+ }
290
+ // set data to string
291
+ context.body = data + '';
292
+ }
293
+ // middleware return value and will be got 204 status
294
+ if (context.body === undefined &&
295
+ !context.response._explicitStatus &&
296
+ context._matchedRoute) {
297
+ // 如果进了路由,重新赋值,防止 404
298
+ context.body = undefined;
324
299
  }
300
+ return {
301
+ isBase64Encoded: encoded,
302
+ statusCode: context.status,
303
+ headers: context.res.headers,
304
+ body: context.body,
305
+ };
325
306
  }
326
307
  async wrapHttpRequest(req, res) {
327
308
  const newReq = res ? new serverless_http_parser_1.HTTPRequest(req, res) : req;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './interface';
2
2
  export { MidwayFaaSFramework as Framework } from './framework';
3
3
  export { FaaSConfiguration as Configuration } from './configuration';
4
4
  export { AbstractBootstrapStarter } from './starter';
5
+ export * from './decorator';
5
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -22,4 +22,5 @@ var configuration_1 = require("./configuration");
22
22
  Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.FaaSConfiguration; } });
23
23
  var starter_1 = require("./starter");
24
24
  Object.defineProperty(exports, "AbstractBootstrapStarter", { enumerable: true, get: function () { return starter_1.AbstractBootstrapStarter; } });
25
+ __exportStar(require("./decorator"), exports);
25
26
  //# sourceMappingURL=index.js.map
@@ -13,10 +13,14 @@ export interface FaaSContext extends IMidwayContext<FaaSHTTPContext> {
13
13
  */
14
14
  export declare type FaaSMiddleware = ((context: Context, next: () => Promise<any>) => any) | string;
15
15
  export interface HandlerOptions {
16
- isHttpFunction: boolean;
16
+ isHttpFunction?: boolean;
17
+ isChunked?: boolean;
17
18
  }
18
19
  export declare type IMidwayFaaSApplication = IMidwayApplication<Context, {
19
20
  getInitializeContext(): any;
21
+ /**
22
+ * @deprecated use useMiddleware instead
23
+ */
20
24
  use(middleware: FaaSMiddleware): any;
21
25
  /**
22
26
  * @deprecated
@@ -36,7 +40,7 @@ export declare type IMidwayFaaSApplication = IMidwayApplication<Context, {
36
40
  invokeTriggerFunction(context: any, handler: string, options: HandlerOptions): Promise<any>;
37
41
  getServerlessInstance<T>(serviceClass: ObjectIdentifier | {
38
42
  new (...args: any[]): T;
39
- }, customContext?: any): Promise<T>;
43
+ }, customContext?: Record<string, any>): Promise<T>;
40
44
  }> & ServerlessHttpApplication;
41
45
  export interface Application extends IMidwayFaaSApplication {
42
46
  }
@@ -77,4 +81,10 @@ export interface ServerlessStarterOptions extends IMidwayBootstrapOptions {
77
81
  end(): any;
78
82
  };
79
83
  }
84
+ export interface HttpResponseFormat<T = unknown> {
85
+ isBase64Encoded: boolean;
86
+ statusCode: number;
87
+ headers: Record<string, string>;
88
+ body: T;
89
+ }
80
90
  //# sourceMappingURL=interface.d.ts.map
package/dist/starter.d.ts CHANGED
@@ -9,6 +9,9 @@ export declare abstract class AbstractBootstrapStarter {
9
9
  close(): Promise<void>;
10
10
  start(options?: ServerlessStarterOptions): any;
11
11
  initFramework(bootstrapOptions?: IMidwayBootstrapOptions): Promise<void>;
12
+ protected createDefaultMockHttpEvent(): void;
13
+ protected createDefaultMockEvent(): void;
14
+ protected createDefaultMockContext(): void;
12
15
  abstract onStart(): any;
13
16
  abstract onInit(...args: unknown[]): any;
14
17
  abstract onRequest(...args: unknown[]): any;
package/dist/starter.js CHANGED
@@ -22,6 +22,9 @@ class AbstractBootstrapStarter {
22
22
  const midwayFrameworkService = this.applicationContext.get(core_1.MidwayFrameworkService);
23
23
  this.framework = midwayFrameworkService.getMainFramework();
24
24
  }
25
+ createDefaultMockHttpEvent() { }
26
+ createDefaultMockEvent() { }
27
+ createDefaultMockContext() { }
25
28
  }
26
29
  exports.AbstractBootstrapStarter = AbstractBootstrapStarter;
27
30
  //# sourceMappingURL=starter.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/faas",
3
- "version": "3.9.0",
3
+ "version": "3.9.1-beta.1",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
@@ -45,5 +45,5 @@
45
45
  "url": "git@github.com:midwayjs/midway.git"
46
46
  },
47
47
  "license": "MIT",
48
- "gitHead": "5f6603d2c9606fc6fc7ece71f956e89e394efeee"
48
+ "gitHead": "a603d2348d6141f8f723901498f03a162a037708"
49
49
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2013 - Now midwayjs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.