@midwayjs/faas 3.0.0-alpha.43 → 3.0.0-beta.10

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,104 @@
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.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
7
+
8
+
9
+ ### Features
10
+
11
+ * 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))
12
+ * implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
13
+
14
+
15
+
16
+
17
+
18
+ # [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * faas missing config in framework ([#1413](https://github.com/midwayjs/midway/issues/1413)) ([7ab16a2](https://github.com/midwayjs/midway/commit/7ab16a24b29d5254a762bfffcdf18385effdf639))
24
+
25
+
26
+
27
+
28
+
29
+ # [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
30
+
31
+ **Note:** Version bump only for package @midwayjs/faas
32
+
33
+
34
+
35
+
36
+
37
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
38
+
39
+
40
+ ### Bug Fixes
41
+
42
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
43
+
44
+
45
+
46
+
47
+
48
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
49
+
50
+ **Note:** Version bump only for package @midwayjs/faas
51
+
52
+
53
+
54
+
55
+
56
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
57
+
58
+ **Note:** Version bump only for package @midwayjs/faas
59
+
60
+
61
+
62
+
63
+
64
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
65
+
66
+
67
+ ### Features
68
+
69
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
70
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
71
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
72
+
73
+
74
+
75
+
76
+
77
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
78
+
79
+ **Note:** Version bump only for package @midwayjs/faas
80
+
81
+
82
+
83
+
84
+
85
+ # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
86
+
87
+ **Note:** Version bump only for package @midwayjs/faas
88
+
89
+
90
+
91
+
92
+
93
+ # [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
94
+
95
+
96
+ ### Bug Fixes
97
+
98
+ * static prefix ([#1321](https://github.com/midwayjs/midway/issues/1321)) ([31fe961](https://github.com/midwayjs/midway/commit/31fe961931fed7656a144b1682ee4c4bb25fdff5))
99
+
100
+
101
+
102
+
103
+
6
104
  ## [2.12.4](https://github.com/midwayjs/midway/compare/v2.12.3...v2.12.4) (2021-08-13)
7
105
 
8
106
 
@@ -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,23 +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
16
  const logger_1 = require("@midwayjs/logger");
9
17
  const LOCK_KEY = '_faas_starter_start_key';
10
- class MidwayFaaSFramework extends core_1.BaseFramework {
18
+ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework {
11
19
  constructor() {
12
20
  super(...arguments);
13
21
  this.defaultHandlerMethod = 'handler';
14
22
  this.funMappingStore = new Map();
15
23
  this.lock = new simple_lock_1.default();
16
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;
17
38
  }
18
39
  async applicationInitialize(options) {
19
40
  var _a;
20
- this.globalMiddleware = this.configurationOptions.middleware || [];
41
+ if (!this.logger) {
42
+ this.logger = options.logger || logger_1.loggers.getLogger('appLogger');
43
+ }
21
44
  this.app =
22
45
  ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.getApplication()) ||
23
46
  {};
@@ -28,14 +51,10 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
28
51
  getInitializeContext: () => {
29
52
  return this.configurationOptions.initializeContext;
30
53
  },
31
- useMiddleware: async (middlewares) => {
32
- if (middlewares.length) {
33
- const newMiddlewares = await this.loadMiddleware(middlewares);
34
- for (const mw of newMiddlewares) {
35
- this.app.use(mw);
36
- }
37
- }
38
- },
54
+ /**
55
+ * @deprecated
56
+ * @param middlewareId
57
+ */
39
58
  generateMiddleware: async (middlewareId) => {
40
59
  return this.generateMiddleware(middlewareId);
41
60
  },
@@ -49,48 +68,17 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
49
68
  },
50
69
  });
51
70
  }
52
- async initializeLogger(options) {
53
- if (!this.logger) {
54
- this.logger =
55
- options.logger ||
56
- (0, logger_1.createConsoleLogger)('midwayServerlessLogger', {
57
- printFormat: info => {
58
- var _a, _b, _c, _d, _e, _f;
59
- 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 : '';
60
- return `${new Date().toISOString()} ${requestId} [${info.level}] ${info.message}`;
61
- },
62
- });
63
- this.appLogger = this.logger;
64
- logger_1.loggers.addLogger('coreLogger', this.logger, false);
65
- logger_1.loggers.addLogger('appLogger', this.logger, false);
66
- logger_1.loggers.addLogger('logger', this.logger, false);
67
- }
68
- }
69
- async afterContainerReady(options) {
70
- this.registerDecorator();
71
- }
72
71
  async run() {
73
72
  return this.lock.sureOnce(async () => {
74
73
  var _a;
75
- // attach global middleware from user config
76
- if ((_a = this.app) === null || _a === void 0 ? void 0 : _a.use) {
77
- const middlewares = this.app.getConfig('middleware') || [];
78
- await this.app.useMiddleware(middlewares);
79
- this.globalMiddleware = this.globalMiddleware.concat(this.app['middleware']);
80
- }
81
74
  // set app keys
82
- this.app['keys'] = this.app.getConfig('keys') || '';
75
+ this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
83
76
  // store all http function entry
84
77
  const collector = new core_1.ServerlessTriggerCollector();
85
78
  const functionList = await collector.getFunctionList();
86
79
  for (const funcInfo of functionList) {
87
80
  this.funMappingStore.set(funcInfo.funcHandlerName, funcInfo);
88
81
  }
89
- // bind func and controller module
90
- const routerModules = await collector.getRouterModules();
91
- for (const module of routerModules) {
92
- this.getApplicationContext().bindClass(module);
93
- }
94
82
  }, LOCK_KEY);
95
83
  }
96
84
  getFrameworkType() {
@@ -102,47 +90,47 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
102
90
  if (args.length === 0) {
103
91
  throw new Error('first parameter must be function context');
104
92
  }
93
+ if (!funOptions) {
94
+ throw new Error(`function handler = ${handlerMapping} not found`);
95
+ }
105
96
  const context = this.getContext(args.shift());
106
- if (funOptions) {
107
- let fnMiddlewere = [];
108
- // invoke middleware, just for http
109
- if (context.headers && context.get) {
110
- fnMiddlewere = fnMiddlewere
111
- .concat(this.globalMiddleware)
112
- .concat(funOptions.controllerMiddleware);
113
- }
114
- fnMiddlewere = fnMiddlewere.concat(funOptions.middleware);
115
- if (fnMiddlewere.length) {
116
- const mw = await this.loadMiddleware(fnMiddlewere);
117
- mw.push(async (ctx, next) => {
97
+ const isHttpFunction = !!(context.headers && context.get);
98
+ const globalMiddlewareFn = await this.applyMiddleware();
99
+ const middlewareManager = new core_1.ContextMiddlewareManager();
100
+ middlewareManager.insertLast(globalMiddlewareFn);
101
+ middlewareManager.insertLast(async (ctx, next) => {
102
+ const fn = await this.middlewareService.compose([
103
+ ...funOptions.controllerMiddleware,
104
+ ...funOptions.middleware,
105
+ async (ctx, next) => {
106
+ if (isHttpFunction) {
107
+ args = [ctx];
108
+ }
118
109
  // invoke handler
119
- const result = await this.invokeHandler(funOptions, ctx, next, args);
120
- if (result !== undefined) {
110
+ const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
111
+ if (isHttpFunction && result !== undefined) {
121
112
  ctx.body = result;
122
113
  }
123
- return next();
124
- });
125
- return compose(mw)(context).then(() => {
126
- return context.body;
127
- });
128
- }
129
- else {
130
- // invoke handler
131
- return this.invokeHandler(funOptions, context, null, args);
132
- }
133
- }
134
- throw new Error(`function handler = ${handlerMapping} not found`);
114
+ return result;
115
+ },
116
+ ], this.app);
117
+ return await fn(ctx, next);
118
+ });
119
+ const composeMiddleware = await this.middlewareService.compose(middlewareManager, this.app);
120
+ return await composeMiddleware(context);
135
121
  };
136
122
  }
123
+ /**
124
+ * @deprecated
125
+ * @param middlewareId
126
+ */
137
127
  async generateMiddleware(middlewareId) {
138
128
  const mwIns = await this.getApplicationContext().getAsync(middlewareId);
139
129
  return mwIns.resolve();
140
130
  }
141
131
  getContext(context) {
142
132
  if (!context.env) {
143
- context.env = this.getApplicationContext()
144
- .getEnvironmentService()
145
- .getCurrentEnvironment();
133
+ context.env = this.environmentService.getCurrentEnvironment();
146
134
  }
147
135
  if (this.isReplaceLogger || !context.logger) {
148
136
  context._serverlessLogger = this.createContextLogger(context);
@@ -158,13 +146,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
158
146
  this.app.createAnonymousContext(context);
159
147
  return context;
160
148
  }
161
- async invokeHandler(routerInfo, context, next, args) {
162
- if (Array.isArray(routerInfo.requestMetadata) &&
163
- routerInfo.requestMetadata.length) {
164
- await Promise.all(routerInfo.requestMetadata.map(async ({ index, type, propertyData }) => {
165
- args[index] = await (0, core_1.extractKoaLikeValue)(type, propertyData)(context, next);
166
- }));
167
- }
149
+ async invokeHandler(routerInfo, context, args, isHttpFunction) {
168
150
  const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
169
151
  const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
170
152
  this.defaultHandlerMethod;
@@ -173,7 +155,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
173
155
  const result = await funModule[handlerName](...args);
174
156
  // implement response decorator
175
157
  const routerResponseData = routerInfo.responseMetadata;
176
- if (context.headers && routerResponseData.length) {
158
+ if (isHttpFunction) {
177
159
  for (const routerRes of routerResponseData) {
178
160
  switch (routerRes.type) {
179
161
  case decorator_1.WEB_RESPONSE_HTTP_CODE:
@@ -207,31 +189,6 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
207
189
  }
208
190
  throw new Error(`no handler setup on ${target.name}#${method || this.defaultHandlerMethod}`);
209
191
  }
210
- registerDecorator() {
211
- this.getApplicationContext().registerDataHandler(decorator_1.PLUGIN_KEY, (key, meta, target) => {
212
- var _a;
213
- 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];
214
- });
215
- this.getApplicationContext().registerDataHandler(decorator_1.LOGGER_KEY, (key, meta, target) => {
216
- var _a;
217
- 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());
218
- });
219
- }
220
- async loadMiddleware(middlewares) {
221
- const newMiddlewares = [];
222
- for (const middleware of middlewares) {
223
- if (typeof middleware === 'function') {
224
- newMiddlewares.push(middleware);
225
- }
226
- else {
227
- const middlewareImpl = await this.getApplicationContext().getAsync(middleware);
228
- if (middlewareImpl && typeof middlewareImpl.resolve === 'function') {
229
- newMiddlewares.push(middlewareImpl.resolve());
230
- }
231
- }
232
- }
233
- return newMiddlewares;
234
- }
235
192
  createLogger(name, option = {}) {
236
193
  // 覆盖基类的创建日志对象,函数场景下的日志,即使自定义,也只启用控制台输出
237
194
  return (0, logger_1.createConsoleLogger)(name, option);
@@ -239,6 +196,17 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
239
196
  getFrameworkName() {
240
197
  return 'midway:faas';
241
198
  }
242
- }
199
+ };
200
+ __decorate([
201
+ (0, decorator_1.Inject)(),
202
+ __metadata("design:type", core_1.MidwayEnvironmentService)
203
+ ], MidwayFaaSFramework.prototype, "environmentService", void 0);
204
+ __decorate([
205
+ (0, decorator_1.Inject)(),
206
+ __metadata("design:type", core_1.MidwayMiddlewareService)
207
+ ], MidwayFaaSFramework.prototype, "middlewareService", void 0);
208
+ MidwayFaaSFramework = __decorate([
209
+ (0, decorator_1.Framework)()
210
+ ], MidwayFaaSFramework);
243
211
  exports.MidwayFaaSFramework = MidwayFaaSFramework;
244
212
  //# sourceMappingURL=framework.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './interface';
2
2
  export { MidwayFaaSFramework as Framework } from './framework';
3
+ export { FaaSConfiguration as Configuration } from './configuration';
3
4
  export * from './util';
4
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -10,9 +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.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 configuration_1 = require("./configuration");
18
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.FaaSConfiguration; } });
17
19
  __exportStar(require("./util"), exports);
18
20
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
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
3
  import { ILogger } from '@midwayjs/logger';
4
4
  export interface FaaSContext extends IMidwayContext<FaaSHTTPContext> {
@@ -11,7 +11,10 @@ export declare type FaaSMiddleware = ((context: FaaSContext, next: () => Promise
11
11
  export declare type IMidwayFaaSApplication = IMidwayApplication<FaaSContext, {
12
12
  getInitializeContext(): any;
13
13
  use(middleware: FaaSMiddleware): any;
14
- useMiddleware(mw: string[]): any;
14
+ /**
15
+ * @deprecated
16
+ * @param middlewareId
17
+ */
15
18
  generateMiddleware(middlewareId: any): Promise<FaaSMiddleware>;
16
19
  /**
17
20
  * Get function name in serverless environment
@@ -26,9 +29,9 @@ export interface Application extends IMidwayFaaSApplication {
26
29
  }
27
30
  export interface Context extends FaaSContext {
28
31
  }
32
+ export declare type NextFunction = BaseNextFunction;
29
33
  export interface IFaaSConfigurationOptions extends IConfigurationOptions {
30
34
  config?: object;
31
- middleware?: string[];
32
35
  initializeContext?: object;
33
36
  applicationAdapter?: {
34
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 = (0, 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.43+8b8075f0",
3
+ "version": "3.0.0-beta.10",
4
4
  "main": "dist/index",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
7
- "@midwayjs/core": "^3.0.0-alpha.43+8b8075f0",
8
- "@midwayjs/decorator": "^3.0.0-alpha.43+8b8075f0",
9
- "@midwayjs/faas-typings": "^3.0.0-alpha.43+8b8075f0",
10
- "@midwayjs/logger": "^3.0.0-alpha.43+8b8075f0",
11
- "@midwayjs/simple-lock": "^1.1.4",
12
- "koa-compose": "^4.1.0"
7
+ "@midwayjs/core": "^3.0.0-beta.10",
8
+ "@midwayjs/faas-typings": "^3.0.0-beta.10",
9
+ "@midwayjs/logger": "^3.0.0-beta.10",
10
+ "@midwayjs/simple-lock": "^1.1.4"
13
11
  },
14
12
  "devDependencies": {
15
- "@midwayjs/mock": "^3.0.0-alpha.43+8b8075f0",
16
- "@midwayjs/serverless-fc-starter": "^3.0.0-alpha.43+8b8075f0",
17
- "@midwayjs/serverless-scf-starter": "^3.0.0-alpha.43+8b8075f0",
13
+ "@midwayjs/decorator": "^3.0.0-beta.10",
14
+ "@midwayjs/mock": "^3.0.0-beta.10",
15
+ "@midwayjs/serverless-fc-starter": "^3.0.0-beta.10",
16
+ "@midwayjs/serverless-scf-starter": "^3.0.0-beta.10",
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": "8b8075f0d40c5de19bb9026f0950e738ca512c7e"
48
+ "gitHead": "153870f2e2dd6b17673ec7591e49224a6bd51b36"
50
49
  }