@midwayjs/faas 3.4.0-beta.4 → 3.4.0-beta.5

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.
@@ -33,8 +33,10 @@ let FaaSConfiguration = class FaaSConfiguration {
33
33
  async onReady(container) { }
34
34
  async onServerReady() {
35
35
  if (!this.framework.isEnable()) {
36
+ // just in legacy local dev and test
36
37
  await this.framework.run();
37
38
  }
39
+ await this.framework.loadFunction();
38
40
  }
39
41
  };
40
42
  __decorate([
@@ -18,12 +18,15 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
18
18
  private serverlessFunctionService;
19
19
  protected httpMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
20
20
  protected eventMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
21
+ private legacyVersion;
22
+ private loadedFunction;
21
23
  environmentService: MidwayEnvironmentService;
22
24
  middlewareService: MidwayMiddlewareService<Context, any>;
23
25
  configure(options: IFaaSConfigurationOptions): any;
24
26
  isEnable(): boolean;
25
27
  applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
26
28
  run(): Promise<void>;
29
+ loadFunction(): Promise<void>;
27
30
  getFrameworkType(): MidwayFrameworkType;
28
31
  /**
29
32
  * @deprecated
@@ -49,5 +52,4 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
49
52
  getEventMiddleware(): ContextMiddlewareManager<Context, NextFunction, undefined>;
50
53
  getAllHandlerNames(): string[];
51
54
  }
52
- export declare const createModuleServerlessFramework: (globalOption: Omit<IMidwayBootstrapOptions, 'applicationContext'> & IFaaSConfigurationOptions) => Promise<MidwayFaaSFramework>;
53
55
  //# sourceMappingURL=framework.d.ts.map
package/dist/framework.js CHANGED
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.createModuleServerlessFramework = exports.MidwayFaaSFramework = void 0;
12
+ exports.MidwayFaaSFramework = void 0;
13
13
  const core_1 = require("@midwayjs/core");
14
14
  const decorator_1 = require("@midwayjs/decorator");
15
15
  const simple_lock_1 = require("@midwayjs/simple-lock");
@@ -29,6 +29,8 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
29
29
  this.serverlessRoutes = [];
30
30
  this.httpMiddlewareManager = this.createMiddlewareManager();
31
31
  this.eventMiddlewareManager = this.createMiddlewareManager();
32
+ this.legacyVersion = false;
33
+ this.loadedFunction = false;
32
34
  }
33
35
  configure(options) {
34
36
  var _a;
@@ -51,6 +53,9 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
51
53
  }
52
54
  this.applicationAdapter =
53
55
  this.configurationOptions.applicationAdapter || {};
56
+ if (this.applicationAdapter.getApplication) {
57
+ this.legacyVersion = true;
58
+ }
54
59
  this.app =
55
60
  ((_b = (_a = this.applicationAdapter).getApplication) === null || _b === void 0 ? void 0 : _b.call(_a)) ||
56
61
  new serverless_http_parser_1.Application();
@@ -106,26 +111,34 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
106
111
  }
107
112
  }
108
113
  async run() {
109
- return this.lock.sureOnce(async () => {
110
- var _a;
111
- // set app keys
112
- this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
113
- // store all http function entry
114
- this.serverlessFunctionService = await this.applicationContext.getAsync(core_1.MidwayServerlessFunctionService);
115
- const functionList = await this.serverlessFunctionService.getFunctionList();
116
- for (const funcInfo of functionList) {
117
- // store handler
118
- this.funMappingStore.set(funcInfo.funcHandlerName, funcInfo);
119
- if (funcInfo.url) {
120
- // store router
121
- this.serverlessRoutes.push({
122
- matchPattern: (0, core_1.pathToRegexp)(funcInfo.url, [], { end: false }),
123
- funcInfo: funcInfo,
124
- });
114
+ if (this.legacyVersion) {
115
+ return this.loadFunction();
116
+ }
117
+ }
118
+ async loadFunction() {
119
+ if (!this.loadedFunction) {
120
+ this.loadedFunction = true;
121
+ return this.lock.sureOnce(async () => {
122
+ var _a;
123
+ // set app keys
124
+ this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
125
+ // store all http function entry
126
+ this.serverlessFunctionService = await this.applicationContext.getAsync(core_1.MidwayServerlessFunctionService);
127
+ const functionList = await this.serverlessFunctionService.getFunctionList();
128
+ for (const funcInfo of functionList) {
129
+ // store handler
130
+ this.funMappingStore.set(funcInfo.funcHandlerName, funcInfo);
131
+ if (funcInfo.url) {
132
+ // store router
133
+ this.serverlessRoutes.push({
134
+ matchPattern: (0, core_1.pathToRegexp)(funcInfo.url, [], { end: false }),
135
+ funcInfo: funcInfo,
136
+ });
137
+ }
125
138
  }
126
- }
127
- this.respond = this.app.callback();
128
- }, LOCK_KEY);
139
+ this.respond = this.app.callback();
140
+ }, LOCK_KEY);
141
+ }
129
142
  }
130
143
  getFrameworkType() {
131
144
  return core_1.MidwayFrameworkType.FAAS;
@@ -320,36 +333,44 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
320
333
  return context;
321
334
  }
322
335
  async invokeHandler(routerInfo, context, args, isHttpFunction) {
323
- const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
324
- const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
325
- this.defaultHandlerMethod;
326
- if (funModule[handlerName]) {
327
- // invoke real method
328
- const result = await funModule[handlerName](...args);
329
- // implement response decorator
330
- const routerResponseData = routerInfo.responseMetadata;
331
- if (isHttpFunction) {
332
- for (const routerRes of routerResponseData) {
333
- switch (routerRes.type) {
334
- case decorator_1.WEB_RESPONSE_HTTP_CODE:
335
- context.status = routerRes.code;
336
- break;
337
- case decorator_1.WEB_RESPONSE_HEADER:
338
- for (const key in (routerRes === null || routerRes === void 0 ? void 0 : routerRes.setHeaders) || {}) {
339
- context.set(key, routerRes.setHeaders[key]);
340
- }
341
- break;
342
- case decorator_1.WEB_RESPONSE_CONTENT_TYPE:
343
- context.type = routerRes.contentType;
344
- break;
345
- case decorator_1.WEB_RESPONSE_REDIRECT:
346
- context.status = routerRes.code;
347
- context.redirect(routerRes.url);
348
- return;
336
+ if (typeof routerInfo.method !== 'string') {
337
+ if (!isHttpFunction) {
338
+ args.unshift(context);
339
+ }
340
+ return routerInfo.method(...args);
341
+ }
342
+ else {
343
+ const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
344
+ const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
345
+ this.defaultHandlerMethod;
346
+ if (funModule[handlerName]) {
347
+ // invoke real method
348
+ const result = await funModule[handlerName](...args);
349
+ // implement response decorator
350
+ const routerResponseData = routerInfo.responseMetadata;
351
+ if (isHttpFunction) {
352
+ for (const routerRes of routerResponseData) {
353
+ switch (routerRes.type) {
354
+ case decorator_1.WEB_RESPONSE_HTTP_CODE:
355
+ context.status = routerRes.code;
356
+ break;
357
+ case decorator_1.WEB_RESPONSE_HEADER:
358
+ for (const key in (routerRes === null || routerRes === void 0 ? void 0 : routerRes.setHeaders) || {}) {
359
+ context.set(key, routerRes.setHeaders[key]);
360
+ }
361
+ break;
362
+ case decorator_1.WEB_RESPONSE_CONTENT_TYPE:
363
+ context.type = routerRes.contentType;
364
+ break;
365
+ case decorator_1.WEB_RESPONSE_REDIRECT:
366
+ context.status = routerRes.code;
367
+ context.redirect(routerRes.url);
368
+ return;
369
+ }
349
370
  }
350
371
  }
372
+ return result;
351
373
  }
352
- return result;
353
374
  }
354
375
  }
355
376
  getFunctionHandler(ctx, args, target, method) {
@@ -402,13 +423,4 @@ MidwayFaaSFramework = __decorate([
402
423
  (0, decorator_1.Framework)()
403
424
  ], MidwayFaaSFramework);
404
425
  exports.MidwayFaaSFramework = MidwayFaaSFramework;
405
- const createModuleServerlessFramework = async (globalOption) => {
406
- const applicationContext = await (0, core_1.initializeGlobalApplicationContext)({
407
- ...globalOption,
408
- baseDir: '',
409
- appDir: '',
410
- });
411
- return applicationContext.get(MidwayFaaSFramework);
412
- };
413
- exports.createModuleServerlessFramework = createModuleServerlessFramework;
414
426
  //# sourceMappingURL=framework.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './interface';
2
- export { MidwayFaaSFramework as Framework, createModuleServerlessFramework, } from './framework';
2
+ export { MidwayFaaSFramework as Framework } from './framework';
3
3
  export { FaaSConfiguration as Configuration } from './configuration';
4
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,11 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Configuration = exports.createModuleServerlessFramework = exports.Framework = void 0;
17
+ exports.Configuration = exports.Framework = void 0;
18
18
  __exportStar(require("./interface"), exports);
19
19
  var framework_1 = require("./framework");
20
20
  Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayFaaSFramework; } });
21
- Object.defineProperty(exports, "createModuleServerlessFramework", { enumerable: true, get: function () { return framework_1.createModuleServerlessFramework; } });
22
21
  var configuration_1 = require("./configuration");
23
22
  Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.FaaSConfiguration; } });
24
23
  //# sourceMappingURL=index.js.map
@@ -47,6 +47,9 @@ export interface IFaaSConfigurationOptions extends IConfigurationOptions {
47
47
  config?: object;
48
48
  initializeContext?: object;
49
49
  applicationAdapter?: {
50
+ /**
51
+ * @deprecated
52
+ */
50
53
  getApplication(): Application;
51
54
  getFunctionName(): string;
52
55
  getFunctionServiceName(): string;
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@midwayjs/faas",
3
- "version": "3.4.0-beta.4",
3
+ "version": "3.4.0-beta.5",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
7
- "@midwayjs/core": "^3.4.0-beta.4",
7
+ "@midwayjs/core": "^3.4.0-beta.5",
8
8
  "@midwayjs/faas-typings": "^3.3.5",
9
9
  "@midwayjs/logger": "^2.15.0",
10
- "@midwayjs/serverless-http-parser": "^3.4.0-beta.4",
10
+ "@midwayjs/serverless-http-parser": "^3.4.0-beta.5",
11
11
  "@midwayjs/simple-lock": "^1.1.4"
12
12
  },
13
13
  "devDependencies": {
14
- "@midwayjs/decorator": "^3.4.0-beta.4",
15
- "@midwayjs/mock": "^3.4.0-beta.4",
16
- "@midwayjs/serverless-fc-starter": "^3.4.0-beta.4",
17
- "@midwayjs/serverless-scf-starter": "^3.4.0-beta.4",
14
+ "@midwayjs/decorator": "^3.4.0-beta.5",
15
+ "@midwayjs/mock": "^3.4.0-beta.5",
16
+ "@midwayjs/serverless-fc-starter": "^3.4.0-beta.5",
17
+ "@midwayjs/serverless-scf-starter": "^3.4.0-beta.5",
18
18
  "mm": "3.2.0"
19
19
  },
20
20
  "engines": {
@@ -46,5 +46,5 @@
46
46
  "url": "git@github.com:midwayjs/midway.git"
47
47
  },
48
48
  "license": "MIT",
49
- "gitHead": "3b686101f7802f87d47b8c9d25561339d556e573"
49
+ "gitHead": "d84d1c77aed1fd973d002ab65cd0adeadb7924a6"
50
50
  }