@midwayjs/faas 3.0.0-alpha.9 → 3.0.0-beta.12

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 CHANGED
@@ -3,6 +3,123 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
7
+
8
+
9
+ ### Features
10
+
11
+ * support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
18
+
19
+ **Note:** Version bump only for package @midwayjs/faas
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
26
+
27
+
28
+ ### Features
29
+
30
+ * default add session & bodyparser support for koa/express/faas ([#1420](https://github.com/midwayjs/midway/issues/1420)) ([cdaff31](https://github.com/midwayjs/midway/commit/cdaff317c3e862a95494a167995a28280af639bf))
31
+ * implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
32
+
33
+
34
+
35
+
36
+
37
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
38
+
39
+
40
+ ### Bug Fixes
41
+
42
+ * faas missing config in framework ([#1413](https://github.com/midwayjs/midway/issues/1413)) ([7ab16a2](https://github.com/midwayjs/midway/commit/7ab16a24b29d5254a762bfffcdf18385effdf639))
43
+
44
+
45
+
46
+
47
+
48
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
49
+
50
+ **Note:** Version bump only for package @midwayjs/faas
51
+
52
+
53
+
54
+
55
+
56
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
57
+
58
+
59
+ ### Bug Fixes
60
+
61
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
62
+
63
+
64
+
65
+
66
+
67
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
68
+
69
+ **Note:** Version bump only for package @midwayjs/faas
70
+
71
+
72
+
73
+
74
+
75
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
76
+
77
+ **Note:** Version bump only for package @midwayjs/faas
78
+
79
+
80
+
81
+
82
+
83
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
84
+
85
+
86
+ ### Features
87
+
88
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
89
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
90
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
91
+
92
+
93
+
94
+
95
+
96
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
97
+
98
+ **Note:** Version bump only for package @midwayjs/faas
99
+
100
+
101
+
102
+
103
+
104
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
105
+
106
+ **Note:** Version bump only for package @midwayjs/faas
107
+
108
+
109
+
110
+
111
+
112
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
113
+
114
+
115
+ ### Bug Fixes
116
+
117
+ * static prefix ([#1321](https://github.com/midwayjs/midway/issues/1321)) ([31fe961](https://github.com/midwayjs/midway/commit/31fe961931fed7656a144b1682ee4c4bb25fdff5))
118
+
119
+
120
+
121
+
122
+
6
123
  ## [2.12.4](https://github.com/midwayjs/midway/compare/v2.12.3...v2.12.4) (2021-08-13)
7
124
 
8
125
 
@@ -0,0 +1,8 @@
1
+ export declare const midwayLogger: {
2
+ default: {
3
+ disableFile: boolean;
4
+ disableError: boolean;
5
+ printFormat: (info: any) => string;
6
+ };
7
+ };
8
+ //# sourceMappingURL=config.default.d.ts.map
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.midwayLogger = void 0;
4
+ exports.midwayLogger = {
5
+ default: {
6
+ disableFile: true,
7
+ disableError: true,
8
+ printFormat: (info) => {
9
+ var _a, _b, _c, _d, _e, _f;
10
+ const requestId = (_f = (_c = (_b = (_a = info.ctx) === null || _a === void 0 ? void 0 : _a['originContext']) === null || _b === void 0 ? void 0 : _b['requestId']) !== null && _c !== void 0 ? _c : (_e = (_d = info.ctx) === null || _d === void 0 ? void 0 : _d['originContext']) === null || _e === void 0 ? void 0 : _e['request_id']) !== null && _f !== void 0 ? _f : '';
11
+ return `${new Date().toISOString()} ${requestId} [${info.level}] ${info.message}`;
12
+ },
13
+ },
14
+ };
15
+ //# sourceMappingURL=config.default.js.map
@@ -0,0 +1,11 @@
1
+ import { MidwayFaaSFramework } from './framework';
2
+ import { MidwayDecoratorService } from '@midwayjs/core';
3
+ export declare class FaaSConfiguration {
4
+ framework: MidwayFaaSFramework;
5
+ decoratorService: MidwayDecoratorService;
6
+ applicationContext: any;
7
+ init(): Promise<void>;
8
+ onReady(container: any): Promise<void>;
9
+ onServerReady(): Promise<void>;
10
+ }
11
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FaaSConfiguration = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ const framework_1 = require("./framework");
15
+ const core_1 = require("@midwayjs/core");
16
+ const DefaultConfig = require("./config.default");
17
+ let FaaSConfiguration = class FaaSConfiguration {
18
+ async init() {
19
+ this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, meta, target) => {
20
+ var _a;
21
+ return (((_a = target === null || target === void 0 ? void 0 : target[core_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a[key]) ||
22
+ this.framework.getApplication()[key]);
23
+ });
24
+ this.decoratorService.registerPropertyHandler(decorator_1.LOGGER_KEY, (key, meta, target) => {
25
+ var _a;
26
+ return (((_a = target === null || target === void 0 ? void 0 : target[core_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a['logger']) ||
27
+ this.framework.getLogger());
28
+ });
29
+ this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
30
+ return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
31
+ });
32
+ }
33
+ async onReady(container) { }
34
+ async onServerReady() {
35
+ if (!this.framework.isEnable()) {
36
+ await this.framework.run();
37
+ }
38
+ }
39
+ };
40
+ __decorate([
41
+ (0, decorator_1.Inject)(),
42
+ __metadata("design:type", framework_1.MidwayFaaSFramework)
43
+ ], FaaSConfiguration.prototype, "framework", void 0);
44
+ __decorate([
45
+ (0, decorator_1.Inject)(),
46
+ __metadata("design:type", core_1.MidwayDecoratorService)
47
+ ], FaaSConfiguration.prototype, "decoratorService", void 0);
48
+ __decorate([
49
+ (0, decorator_1.ApplicationContext)(),
50
+ __metadata("design:type", Object)
51
+ ], FaaSConfiguration.prototype, "applicationContext", void 0);
52
+ __decorate([
53
+ (0, decorator_1.Init)(),
54
+ __metadata("design:type", Function),
55
+ __metadata("design:paramtypes", []),
56
+ __metadata("design:returntype", Promise)
57
+ ], FaaSConfiguration.prototype, "init", null);
58
+ FaaSConfiguration = __decorate([
59
+ (0, decorator_1.Configuration)({
60
+ namespace: 'faas',
61
+ importConfigs: [
62
+ {
63
+ default: DefaultConfig,
64
+ },
65
+ ],
66
+ })
67
+ ], FaaSConfiguration);
68
+ exports.FaaSConfiguration = FaaSConfiguration;
69
+ //# sourceMappingURL=configuration.js.map
@@ -1,27 +1,31 @@
1
- import { FaaSContext, FaaSMiddleware, IFaaSConfigurationOptions, IMidwayFaaSApplication } from './interface';
2
- import { BaseFramework, IMidwayBootstrapOptions, MidwayFrameworkType, RouterInfo } from '@midwayjs/core';
1
+ import { FaaSContext, IFaaSConfigurationOptions, IMidwayFaaSApplication } from './interface';
2
+ import { BaseFramework, FunctionMiddleware, IMidwayBootstrapOptions, MidwayEnvironmentService, MidwayFrameworkType, MidwayMiddlewareService, RouterInfo } from '@midwayjs/core';
3
3
  import { LoggerOptions } from '@midwayjs/logger';
4
4
  export declare class MidwayFaaSFramework extends BaseFramework<IMidwayFaaSApplication, FaaSContext, IFaaSConfigurationOptions> {
5
5
  protected defaultHandlerMethod: string;
6
- private globalMiddleware;
7
6
  protected funMappingStore: Map<string, RouterInfo>;
8
7
  protected logger: any;
9
8
  private lock;
10
9
  app: IMidwayFaaSApplication;
11
10
  private isReplaceLogger;
11
+ private developmentRun;
12
+ environmentService: MidwayEnvironmentService;
13
+ middlewareService: MidwayMiddlewareService<FaaSContext, any>;
14
+ configure(options: IFaaSConfigurationOptions): any;
15
+ isEnable(): boolean;
12
16
  applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
13
- protected initializeLogger(options: IMidwayBootstrapOptions): Promise<void>;
14
- protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
15
17
  run(): Promise<void>;
16
18
  getFrameworkType(): MidwayFrameworkType;
17
19
  handleInvokeWrapper(handlerMapping: string): (...args: any[]) => Promise<any>;
18
- generateMiddleware(middlewareId: string): Promise<FaaSMiddleware>;
20
+ /**
21
+ * @deprecated
22
+ * @param middlewareId
23
+ */
24
+ generateMiddleware(middlewareId: string): Promise<FunctionMiddleware<FaaSContext, any>>;
19
25
  getContext(context: any): any;
20
26
  private invokeHandler;
21
27
  protected getFunctionHandler(ctx: any, args: any, target: any, method: any): string;
22
- private registerDecorator;
23
- private loadMiddleware;
24
- createLogger(name: string, option?: LoggerOptions): import("@midwayjs/logger").ILogger;
28
+ createLogger(name: string, option?: LoggerOptions): import("@midwayjs/core").ILogger;
25
29
  getFrameworkName(): string;
26
30
  }
27
31
  //# sourceMappingURL=framework.d.ts.map
package/dist/framework.js CHANGED
@@ -1,24 +1,46 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.MidwayFaaSFramework = void 0;
4
13
  const core_1 = require("@midwayjs/core");
5
14
  const decorator_1 = require("@midwayjs/decorator");
6
15
  const simple_lock_1 = require("@midwayjs/simple-lock");
7
- const compose = require("koa-compose");
8
- const hooks_1 = require("./hooks");
9
16
  const logger_1 = require("@midwayjs/logger");
10
17
  const LOCK_KEY = '_faas_starter_start_key';
11
- class MidwayFaaSFramework extends core_1.BaseFramework {
18
+ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework {
12
19
  constructor() {
13
20
  super(...arguments);
14
21
  this.defaultHandlerMethod = 'handler';
15
22
  this.funMappingStore = new Map();
16
23
  this.lock = new simple_lock_1.default();
17
24
  this.isReplaceLogger = process.env['MIDWAY_SERVERLESS_REPLACE_LOGGER'] === 'true';
25
+ this.developmentRun = false;
26
+ }
27
+ configure(options) {
28
+ if (options) {
29
+ this.developmentRun = true;
30
+ this.configurationOptions = options;
31
+ }
32
+ else {
33
+ return this.configService.getConfiguration('faas');
34
+ }
35
+ }
36
+ isEnable() {
37
+ return !this.developmentRun;
18
38
  }
19
39
  async applicationInitialize(options) {
20
40
  var _a;
21
- this.globalMiddleware = this.configurationOptions.middleware || [];
41
+ if (!this.logger) {
42
+ this.logger = options.logger || logger_1.loggers.getLogger('appLogger');
43
+ }
22
44
  this.app =
23
45
  ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.getApplication()) ||
24
46
  {};
@@ -29,14 +51,10 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
29
51
  getInitializeContext: () => {
30
52
  return this.configurationOptions.initializeContext;
31
53
  },
32
- useMiddleware: async (middlewares) => {
33
- if (middlewares.length) {
34
- const newMiddlewares = await this.loadMiddleware(middlewares);
35
- for (const mw of newMiddlewares) {
36
- this.app.use(mw);
37
- }
38
- }
39
- },
54
+ /**
55
+ * @deprecated
56
+ * @param middlewareId
57
+ */
40
58
  generateMiddleware: async (middlewareId) => {
41
59
  return this.generateMiddleware(middlewareId);
42
60
  },
@@ -49,38 +67,15 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
49
67
  return (_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.getFunctionServiceName();
50
68
  },
51
69
  });
52
- }
53
- async initializeLogger(options) {
54
- if (!this.logger) {
55
- this.logger =
56
- options.logger ||
57
- logger_1.createConsoleLogger('midwayServerlessLogger', {
58
- printFormat: info => {
59
- var _a, _b, _c, _d, _e, _f;
60
- const requestId = (_f = (_c = (_b = (_a = info.ctx) === null || _a === void 0 ? void 0 : _a['originContext']) === null || _b === void 0 ? void 0 : _b['requestId']) !== null && _c !== void 0 ? _c : (_e = (_d = info.ctx) === null || _d === void 0 ? void 0 : _d['originContext']) === null || _e === void 0 ? void 0 : _e['request_id']) !== null && _f !== void 0 ? _f : '';
61
- return `${new Date().toISOString()} ${requestId} [${info.level}] ${info.message}`;
62
- },
63
- });
64
- this.appLogger = this.logger;
65
- logger_1.loggers.addLogger('coreLogger', this.logger, false);
66
- logger_1.loggers.addLogger('appLogger', this.logger, false);
67
- logger_1.loggers.addLogger('logger', this.logger, false);
68
- }
69
- }
70
- async afterContainerReady(options) {
71
- this.registerDecorator();
70
+ // hack use method
71
+ this.app.originUse = this.app.use;
72
+ this.app.use = this.app.useMiddleware;
72
73
  }
73
74
  async run() {
74
75
  return this.lock.sureOnce(async () => {
75
76
  var _a;
76
- // attach global middleware from user config
77
- if ((_a = this.app) === null || _a === void 0 ? void 0 : _a.use) {
78
- const middlewares = this.app.getConfig('middleware') || [];
79
- await this.app.useMiddleware(middlewares);
80
- this.globalMiddleware = this.globalMiddleware.concat(this.app['middleware']);
81
- }
82
77
  // set app keys
83
- this.app['keys'] = this.app.getConfig('keys') || '';
78
+ this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
84
79
  // store all http function entry
85
80
  const collector = new core_1.ServerlessTriggerCollector();
86
81
  const functionList = await collector.getFunctionList();
@@ -98,50 +93,47 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
98
93
  if (args.length === 0) {
99
94
  throw new Error('first parameter must be function context');
100
95
  }
96
+ if (!funOptions) {
97
+ throw new Error(`function handler = ${handlerMapping} not found`);
98
+ }
101
99
  const context = this.getContext(args.shift());
102
- if (funOptions) {
103
- let fnMiddlewere = [];
104
- // invoke middleware, just for http
105
- if (context.headers && context.get) {
106
- fnMiddlewere = fnMiddlewere
107
- .concat(this.globalMiddleware)
108
- .concat(funOptions.controllerMiddleware);
109
- }
110
- fnMiddlewere = fnMiddlewere.concat(funOptions.middleware);
111
- if (fnMiddlewere.length) {
112
- const mw = await this.loadMiddleware(fnMiddlewere);
113
- mw.push(async (ctx, next) => {
100
+ const isHttpFunction = !!(context.headers && context.get);
101
+ const globalMiddlewareFn = await this.applyMiddleware();
102
+ const middlewareManager = new core_1.ContextMiddlewareManager();
103
+ middlewareManager.insertLast(globalMiddlewareFn);
104
+ middlewareManager.insertLast(async (ctx, next) => {
105
+ const fn = await this.middlewareService.compose([
106
+ ...funOptions.controllerMiddleware,
107
+ ...funOptions.middleware,
108
+ async (ctx, next) => {
109
+ if (isHttpFunction) {
110
+ args = [ctx];
111
+ }
114
112
  // invoke handler
115
- const result = await this.invokeHandler(funOptions, ctx, next, args);
116
- if (result !== undefined) {
113
+ const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
114
+ if (isHttpFunction && result !== undefined) {
117
115
  ctx.body = result;
118
116
  }
119
- return next();
120
- });
121
- return compose(mw)(context).then(() => {
122
- return context.body;
123
- });
124
- }
125
- else {
126
- // invoke handler
127
- return this.invokeHandler(funOptions, context, null, args);
128
- }
129
- }
130
- throw new Error(`function handler = ${handlerMapping} not found`);
117
+ return result;
118
+ },
119
+ ], this.app);
120
+ return await fn(ctx, next);
121
+ });
122
+ const composeMiddleware = await this.middlewareService.compose(middlewareManager, this.app);
123
+ return await composeMiddleware(context);
131
124
  };
132
125
  }
126
+ /**
127
+ * @deprecated
128
+ * @param middlewareId
129
+ */
133
130
  async generateMiddleware(middlewareId) {
134
131
  const mwIns = await this.getApplicationContext().getAsync(middlewareId);
135
132
  return mwIns.resolve();
136
133
  }
137
134
  getContext(context) {
138
135
  if (!context.env) {
139
- context.env = this.getApplicationContext()
140
- .getEnvironmentService()
141
- .getCurrentEnvironment();
142
- }
143
- if (!context.hooks) {
144
- context.hooks = new hooks_1.MidwayHooks(context, this.app);
136
+ context.env = this.environmentService.getCurrentEnvironment();
145
137
  }
146
138
  if (this.isReplaceLogger || !context.logger) {
147
139
  context._serverlessLogger = this.createContextLogger(context);
@@ -157,13 +149,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
157
149
  this.app.createAnonymousContext(context);
158
150
  return context;
159
151
  }
160
- async invokeHandler(routerInfo, context, next, args) {
161
- if (Array.isArray(routerInfo.requestMetadata) &&
162
- routerInfo.requestMetadata.length) {
163
- await Promise.all(routerInfo.requestMetadata.map(async ({ index, type, propertyData }) => {
164
- args[index] = await core_1.extractKoaLikeValue(type, propertyData)(context, next);
165
- }));
166
- }
152
+ async invokeHandler(routerInfo, context, args, isHttpFunction) {
167
153
  const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
168
154
  const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
169
155
  this.defaultHandlerMethod;
@@ -172,7 +158,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
172
158
  const result = await funModule[handlerName](...args);
173
159
  // implement response decorator
174
160
  const routerResponseData = routerInfo.responseMetadata;
175
- if (context.headers && routerResponseData.length) {
161
+ if (isHttpFunction) {
176
162
  for (const routerRes of routerResponseData) {
177
163
  switch (routerRes.type) {
178
164
  case decorator_1.WEB_RESPONSE_HTTP_CODE:
@@ -206,38 +192,24 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
206
192
  }
207
193
  throw new Error(`no handler setup on ${target.name}#${method || this.defaultHandlerMethod}`);
208
194
  }
209
- registerDecorator() {
210
- this.getApplicationContext().registerDataHandler(decorator_1.PLUGIN_KEY, (key, meta, target) => {
211
- var _a;
212
- return ((_a = target === null || target === void 0 ? void 0 : target[core_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a[key]) || this.app[key];
213
- });
214
- this.getApplicationContext().registerDataHandler(decorator_1.LOGGER_KEY, (key, meta, target) => {
215
- var _a;
216
- return (((_a = target === null || target === void 0 ? void 0 : target[core_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a['logger']) || this.app.getLogger());
217
- });
218
- }
219
- async loadMiddleware(middlewares) {
220
- const newMiddlewares = [];
221
- for (const middleware of middlewares) {
222
- if (typeof middleware === 'function') {
223
- newMiddlewares.push(middleware);
224
- }
225
- else {
226
- const middlewareImpl = await this.getApplicationContext().getAsync(middleware);
227
- if (middlewareImpl && typeof middlewareImpl.resolve === 'function') {
228
- newMiddlewares.push(middlewareImpl.resolve());
229
- }
230
- }
231
- }
232
- return newMiddlewares;
233
- }
234
195
  createLogger(name, option = {}) {
235
196
  // 覆盖基类的创建日志对象,函数场景下的日志,即使自定义,也只启用控制台输出
236
- return logger_1.createConsoleLogger(name, option);
197
+ return (0, logger_1.createConsoleLogger)(name, option);
237
198
  }
238
199
  getFrameworkName() {
239
200
  return 'midway:faas';
240
201
  }
241
- }
202
+ };
203
+ __decorate([
204
+ (0, decorator_1.Inject)(),
205
+ __metadata("design:type", core_1.MidwayEnvironmentService)
206
+ ], MidwayFaaSFramework.prototype, "environmentService", void 0);
207
+ __decorate([
208
+ (0, decorator_1.Inject)(),
209
+ __metadata("design:type", core_1.MidwayMiddlewareService)
210
+ ], MidwayFaaSFramework.prototype, "middlewareService", void 0);
211
+ MidwayFaaSFramework = __decorate([
212
+ (0, decorator_1.Framework)()
213
+ ], MidwayFaaSFramework);
242
214
  exports.MidwayFaaSFramework = MidwayFaaSFramework;
243
215
  //# sourceMappingURL=framework.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './interface';
2
2
  export { MidwayFaaSFramework as Framework } from './framework';
3
- export { Func as func, Provide as provide, Inject as inject, Config as config, Plugin as plugin, Logger as logger, Init as init, } from '@midwayjs/decorator';
3
+ export { FaaSConfiguration as Configuration } from './configuration';
4
4
  export * from './util';
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,17 +10,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.init = exports.logger = exports.plugin = exports.config = exports.inject = exports.provide = exports.func = exports.Framework = void 0;
13
+ exports.Configuration = exports.Framework = void 0;
14
14
  __exportStar(require("./interface"), exports);
15
15
  var framework_1 = require("./framework");
16
16
  Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayFaaSFramework; } });
17
- var decorator_1 = require("@midwayjs/decorator");
18
- Object.defineProperty(exports, "func", { enumerable: true, get: function () { return decorator_1.Func; } });
19
- Object.defineProperty(exports, "provide", { enumerable: true, get: function () { return decorator_1.Provide; } });
20
- Object.defineProperty(exports, "inject", { enumerable: true, get: function () { return decorator_1.Inject; } });
21
- Object.defineProperty(exports, "config", { enumerable: true, get: function () { return decorator_1.Config; } });
22
- Object.defineProperty(exports, "plugin", { enumerable: true, get: function () { return decorator_1.Plugin; } });
23
- Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return decorator_1.Logger; } });
24
- Object.defineProperty(exports, "init", { enumerable: true, get: function () { return decorator_1.Init; } });
17
+ var configuration_1 = require("./configuration");
18
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.FaaSConfiguration; } });
25
19
  __exportStar(require("./util"), exports);
26
20
  //# sourceMappingURL=index.js.map
@@ -1,19 +1,20 @@
1
- import { MidwayRequestContainer, IMidwayApplication, IConfigurationOptions, IMidwayContext } from '@midwayjs/core';
1
+ import { MidwayRequestContainer, IMidwayApplication, IConfigurationOptions, IMidwayContext, NextFunction as BaseNextFunction } from '@midwayjs/core';
2
2
  import { FaaSHTTPContext } from '@midwayjs/faas-typings';
3
- import type { MidwayHooks } from './hooks';
4
3
  import { ILogger } from '@midwayjs/logger';
5
4
  export interface FaaSContext extends IMidwayContext<FaaSHTTPContext> {
6
5
  logger: ILogger;
7
6
  env: string;
8
7
  requestContext: MidwayRequestContainer;
9
8
  originContext: any;
10
- hooks?: MidwayHooks;
11
9
  }
12
10
  export declare type FaaSMiddleware = ((context: FaaSContext, next: () => Promise<any>) => any) | string;
13
11
  export declare type IMidwayFaaSApplication = IMidwayApplication<FaaSContext, {
14
12
  getInitializeContext(): any;
15
13
  use(middleware: FaaSMiddleware): any;
16
- useMiddleware(mw: string[]): any;
14
+ /**
15
+ * @deprecated
16
+ * @param middlewareId
17
+ */
17
18
  generateMiddleware(middlewareId: any): Promise<FaaSMiddleware>;
18
19
  /**
19
20
  * Get function name in serverless environment
@@ -28,9 +29,9 @@ export interface Application extends IMidwayFaaSApplication {
28
29
  }
29
30
  export interface Context extends FaaSContext {
30
31
  }
32
+ export declare type NextFunction = BaseNextFunction;
31
33
  export interface IFaaSConfigurationOptions extends IConfigurationOptions {
32
34
  config?: object;
33
- middleware?: string[];
34
35
  initializeContext?: object;
35
36
  applicationAdapter?: {
36
37
  getApplication(): IMidwayFaaSApplication;
package/dist/util.d.ts CHANGED
@@ -1,11 +1,4 @@
1
- import { IMidwayContainer } from '@midwayjs/core';
1
+ import { IMidwayBootstrapOptions } from '@midwayjs/core';
2
2
  import { Framework, IFaaSConfigurationOptions } from './index';
3
- export interface CreateOptions extends IFaaSConfigurationOptions {
4
- container?: IMidwayContainer;
5
- modules: any[];
6
- entry: {
7
- Configuration: any;
8
- };
9
- }
10
- export declare const createModuleServerlessFramework: (options: CreateOptions) => Promise<Framework>;
3
+ export declare const createModuleServerlessFramework: (globalOption: Omit<IMidwayBootstrapOptions, 'applicationContext'> & IFaaSConfigurationOptions) => Promise<Framework>;
11
4
  //# sourceMappingURL=util.d.ts.map
package/dist/util.js CHANGED
@@ -3,17 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createModuleServerlessFramework = void 0;
4
4
  const core_1 = require("@midwayjs/core");
5
5
  const index_1 = require("./index");
6
- const createModuleServerlessFramework = async (options) => {
7
- const container = core_1.createModuleContainer(options);
8
- const framework = new index_1.Framework();
9
- framework.configure(options);
10
- await framework.initialize({
11
- applicationContext: container,
6
+ const createModuleServerlessFramework = async (globalOption) => {
7
+ const applicationContext = await (0, core_1.initializeGlobalApplicationContext)({
8
+ ...globalOption,
12
9
  baseDir: '',
13
10
  appDir: '',
14
11
  });
15
- await framework.run();
16
- return framework;
12
+ return applicationContext.get(index_1.Framework);
17
13
  };
18
14
  exports.createModuleServerlessFramework = createModuleServerlessFramework;
19
15
  //# sourceMappingURL=util.js.map
package/package.json CHANGED
@@ -1,24 +1,23 @@
1
1
  {
2
2
  "name": "@midwayjs/faas",
3
- "version": "3.0.0-alpha.9+d5acc750",
3
+ "version": "3.0.0-beta.12",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
7
- "@midwayjs/core": "^3.0.0-alpha.9+d5acc750",
8
- "@midwayjs/decorator": "^3.0.0-alpha.2",
9
- "@midwayjs/faas-typings": "^2.11.1",
10
- "@midwayjs/logger": "^2.11.3",
11
- "@midwayjs/simple-lock": "^1.1.4",
12
- "koa-compose": "^4.1.0"
7
+ "@midwayjs/core": "^3.0.0-beta.12",
8
+ "@midwayjs/faas-typings": "^3.0.0-beta.12",
9
+ "@midwayjs/logger": "^3.0.0-beta.12",
10
+ "@midwayjs/simple-lock": "^1.1.4"
13
11
  },
14
12
  "devDependencies": {
15
- "@midwayjs/mock": "^3.0.0-alpha.9+d5acc750",
16
- "@midwayjs/serverless-fc-starter": "^3.0.0-alpha.9+d5acc750",
17
- "@midwayjs/serverless-scf-starter": "^3.0.0-alpha.2",
13
+ "@midwayjs/decorator": "^3.0.0-beta.12",
14
+ "@midwayjs/mock": "^3.0.0-beta.12",
15
+ "@midwayjs/serverless-fc-starter": "^3.0.0-beta.12",
16
+ "@midwayjs/serverless-scf-starter": "^3.0.0-beta.12",
18
17
  "mm": "3"
19
18
  },
20
19
  "engines": {
21
- "node": ">= 10"
20
+ "node": ">=12"
22
21
  },
23
22
  "files": [
24
23
  "dist/**/*.js",
@@ -46,5 +45,5 @@
46
45
  "url": "git@github.com:midwayjs/midway.git"
47
46
  },
48
47
  "license": "MIT",
49
- "gitHead": "d5acc7505275ea9d566edd38e5e0377141e0abc1"
48
+ "gitHead": "1c46e53eb934248007eeb7fe3920f5ac24e272c6"
50
49
  }
package/dist/hooks.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { FaaSContext, IMidwayFaaSApplication } from './interface';
2
- /**
3
- * Stability: 1 - Experimental
4
- */
5
- export declare class MidwayHooks {
6
- private readonly ctx;
7
- private readonly app;
8
- constructor(ctx: FaaSContext, app: IMidwayFaaSApplication);
9
- useContext(): FaaSContext;
10
- useInject<T>(identifier: any): Promise<T>;
11
- useConfig(key?: string): any;
12
- useLogger(): import("@midwayjs/logger").ILogger;
13
- usePlugin(key: string): any;
14
- useApp(): IMidwayFaaSApplication;
15
- }
16
- //# sourceMappingURL=hooks.d.ts.map
package/dist/hooks.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayHooks = void 0;
4
- /**
5
- * Stability: 1 - Experimental
6
- */
7
- class MidwayHooks {
8
- constructor(ctx, app) {
9
- this.ctx = ctx;
10
- this.app = app;
11
- }
12
- useContext() {
13
- return this.ctx;
14
- }
15
- useInject(identifier) {
16
- return this.ctx.requestContext.getAsync(identifier);
17
- }
18
- useConfig(key) {
19
- return this.ctx.requestContext.getConfigService().getConfiguration(key);
20
- }
21
- useLogger() {
22
- return this.ctx.logger;
23
- }
24
- usePlugin(key) {
25
- return this.ctx[key] || this.app[key];
26
- }
27
- useApp() {
28
- return this.app;
29
- }
30
- }
31
- exports.MidwayHooks = MidwayHooks;
32
- //# sourceMappingURL=hooks.js.map