@midwayjs/faas 3.19.2 → 4.0.0-alpha.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.
@@ -17,8 +17,9 @@ exports.default = (appInfo) => ({
17
17
  },
18
18
  },
19
19
  format: (info) => {
20
- var _a, _b, _c, _d, _e, _f;
21
- 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 : '';
20
+ const requestId = info.ctx?.['originContext']?.['requestId'] ??
21
+ info.ctx?.['originContext']?.['request_id'] ??
22
+ '';
22
23
  return `${new Date().toISOString()} ${requestId} [${info.level}] ${info.message}`;
23
24
  },
24
25
  },
@@ -16,13 +16,11 @@ const DefaultConfig = require("./config.default");
16
16
  let FaaSConfiguration = class FaaSConfiguration {
17
17
  async init() {
18
18
  this.decoratorService.registerPropertyHandler(core_1.PLUGIN_KEY, (key, meta, target) => {
19
- var _a;
20
- return (((_a = target === null || target === void 0 ? void 0 : target[core_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a[key]) ||
19
+ return (target?.[core_1.REQUEST_OBJ_CTX_KEY]?.[key] ||
21
20
  this.framework.getApplication()[key]);
22
21
  });
23
22
  this.decoratorService.registerPropertyHandler(core_1.LOGGER_KEY, (key, meta, target) => {
24
- var _a;
25
- return (((_a = target === null || target === void 0 ? void 0 : target[core_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a['logger']) ||
23
+ return (target?.[core_1.REQUEST_OBJ_CTX_KEY]?.['logger'] ||
26
24
  this.framework.getLogger());
27
25
  });
28
26
  this.decoratorService.registerParameterHandler(core_1.WEB_ROUTER_PARAM_KEY, options => {
@@ -38,6 +36,7 @@ let FaaSConfiguration = class FaaSConfiguration {
38
36
  await this.framework.loadFunction();
39
37
  }
40
38
  };
39
+ exports.FaaSConfiguration = FaaSConfiguration;
41
40
  __decorate([
42
41
  (0, core_1.Inject)(),
43
42
  __metadata("design:type", framework_1.MidwayFaaSFramework)
@@ -56,7 +55,7 @@ __decorate([
56
55
  __metadata("design:paramtypes", []),
57
56
  __metadata("design:returntype", Promise)
58
57
  ], FaaSConfiguration.prototype, "init", null);
59
- FaaSConfiguration = __decorate([
58
+ exports.FaaSConfiguration = FaaSConfiguration = __decorate([
60
59
  (0, core_1.Configuration)({
61
60
  namespace: 'faas',
62
61
  importConfigs: [
@@ -66,5 +65,4 @@ FaaSConfiguration = __decorate([
66
65
  ],
67
66
  })
68
67
  ], FaaSConfiguration);
69
- exports.FaaSConfiguration = FaaSConfiguration;
70
68
  //# sourceMappingURL=configuration.js.map
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions, HttpResponseFormat, wrapHttpRequestOptions } from './interface';
3
- import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IMidwayBootstrapOptions, MidwayEnvironmentService, MidwayFrameworkType, MidwayMiddlewareService, RouterInfo } from '@midwayjs/core';
3
+ import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IMidwayBootstrapOptions, MidwayEnvironmentService, MidwayMiddlewareService, RouterInfo } from '@midwayjs/core';
4
4
  import { LoggerOptions } from '@midwayjs/logger';
5
5
  import * as http from 'http';
6
6
  export declare class MidwayFaaSFramework extends BaseFramework<Application, Context, IFaaSConfigurationOptions> {
@@ -26,7 +26,6 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
26
26
  applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
27
27
  run(): Promise<void>;
28
28
  loadFunction(): Promise<void>;
29
- getFrameworkType(): MidwayFrameworkType;
30
29
  /**
31
30
  * @deprecated
32
31
  * @param handlerMapping
package/dist/framework.js CHANGED
@@ -15,6 +15,7 @@ const simple_lock_1 = require("@midwayjs/simple-lock");
15
15
  const logger_1 = require("@midwayjs/logger");
16
16
  const serverless_http_parser_1 = require("@midwayjs/serverless-http-parser");
17
17
  const util_1 = require("util");
18
+ const debug = (0, util_1.debuglog)('midway:debug');
18
19
  const { isAnyArrayBuffer, isUint8Array } = util_1.types;
19
20
  const LOCK_KEY = '_faas_starter_start_key';
20
21
  let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework {
@@ -31,8 +32,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
31
32
  this.loadedFunction = false;
32
33
  }
33
34
  configure(options) {
34
- var _a;
35
- const faasConfig = (_a = this.configService.getConfiguration('faas')) !== null && _a !== void 0 ? _a : {};
35
+ const faasConfig = this.configService.getConfiguration('faas') ?? {};
36
36
  if (options || faasConfig['developmentRun']) {
37
37
  this.developmentRun = true;
38
38
  this.configurationOptions = options;
@@ -45,7 +45,6 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
45
45
  return !this.developmentRun;
46
46
  }
47
47
  async applicationInitialize(options) {
48
- var _a, _b, _c;
49
48
  if (!this.logger) {
50
49
  this.logger = options.logger || logger_1.loggers.getLogger('appLogger');
51
50
  }
@@ -55,7 +54,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
55
54
  this.legacyVersion = true;
56
55
  }
57
56
  this.app =
58
- ((_b = (_a = this.applicationAdapter).getApplication) === null || _b === void 0 ? void 0 : _b.call(_a)) ||
57
+ this.applicationAdapter.getApplication?.() ||
59
58
  new serverless_http_parser_1.Application();
60
59
  this.defineApplicationProperties({
61
60
  /**
@@ -72,18 +71,16 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
72
71
  return this.generateMiddleware(middlewareId);
73
72
  },
74
73
  getFunctionName: () => {
75
- var _a;
76
74
  return (process.env.MIDWAY_SERVERLESS_FUNCTION_NAME ||
77
- ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.getFunctionName()) ||
75
+ this.configurationOptions.applicationAdapter?.getFunctionName() ||
78
76
  '');
79
77
  },
80
78
  /**
81
79
  * get function service/group in runtime
82
80
  */
83
81
  getFunctionServiceName: () => {
84
- var _a;
85
82
  return (process.env.MIDWAY_SERVERLESS_SERVICE_NAME ||
86
- ((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.getFunctionServiceName()) ||
83
+ this.configurationOptions.applicationAdapter?.getFunctionServiceName() ||
87
84
  '');
88
85
  },
89
86
  useEventMiddleware: middleware => {
@@ -102,7 +99,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
102
99
  // hack use method
103
100
  this.app.originUse = this.app.use;
104
101
  this.app.use = this.app.useMiddleware;
105
- if ((_c = this.configurationOptions.applicationAdapter) === null || _c === void 0 ? void 0 : _c.runAppHook) {
102
+ if (this.configurationOptions.applicationAdapter?.runAppHook) {
106
103
  this.configurationOptions.applicationAdapter.runAppHook(this.app);
107
104
  }
108
105
  }
@@ -115,13 +112,14 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
115
112
  if (!this.loadedFunction) {
116
113
  this.loadedFunction = true;
117
114
  return this.lock.sureOnce(async () => {
118
- var _a;
119
115
  // set app keys
120
- this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
116
+ this.app['keys'] = this.configService.getConfiguration('keys') ?? '';
121
117
  // store all http function entry
122
118
  this.serverlessFunctionService = await this.applicationContext.getAsync(core_1.MidwayServerlessFunctionService);
123
119
  const functionList = await this.serverlessFunctionService.getFunctionList();
120
+ debug(`[faas]: load ${functionList.length} function list`);
124
121
  for (const funcInfo of functionList) {
122
+ debug(`[faas]: load function ${funcInfo.funcHandlerName}, router = ${funcInfo.fullUrl}`);
125
123
  // store handler
126
124
  this.funMappingStore.set(funcInfo.funcHandlerName, funcInfo);
127
125
  }
@@ -129,9 +127,6 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
129
127
  }, LOCK_KEY);
130
128
  }
131
129
  }
132
- getFrameworkType() {
133
- return core_1.MidwayFrameworkType.FAAS;
134
- }
135
130
  /**
136
131
  * @deprecated
137
132
  * @param handlerMapping
@@ -191,7 +186,6 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
191
186
  };
192
187
  }
193
188
  async invokeTriggerFunction(context, handlerMapping, options) {
194
- var _a, _b;
195
189
  let funOptions = this.funMappingStore.get(handlerMapping);
196
190
  const isHttpFunction = options.isHttpFunction;
197
191
  if (!funOptions && isHttpFunction) {
@@ -201,8 +195,8 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
201
195
  context.req.pathParameters = matchRes['params'] || {};
202
196
  }
203
197
  else {
204
- // options request pass throuth to middleware
205
- if (((_a = context.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'options') {
198
+ // options request pass through to middleware
199
+ if (context.method?.toLowerCase() === 'options') {
206
200
  funOptions = {
207
201
  url: context.path,
208
202
  method: 'options',
@@ -217,7 +211,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
217
211
  throw new Error(`function handler = ${handlerMapping} not found`);
218
212
  }
219
213
  context = this.getContext(context);
220
- if ((_b = this.configurationOptions.applicationAdapter) === null || _b === void 0 ? void 0 : _b.runContextHook) {
214
+ if (this.configurationOptions.applicationAdapter?.runContextHook) {
221
215
  this.configurationOptions.applicationAdapter.runContextHook(context);
222
216
  }
223
217
  const result = await (await this.applyMiddleware(async (ctx, next) => {
@@ -267,8 +261,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
267
261
  }
268
262
  }
269
263
  formatHttpResponse(context, options = {}) {
270
- var _a;
271
- if (!((_a = context.response) === null || _a === void 0 ? void 0 : _a._explicitStatus)) {
264
+ if (!context.response?._explicitStatus) {
272
265
  if (context.body === null || context.body === 'undefined') {
273
266
  context.body = '';
274
267
  context.type = 'text';
@@ -379,7 +372,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
379
372
  context.status = routerRes.code;
380
373
  break;
381
374
  case core_1.WEB_RESPONSE_HEADER:
382
- for (const key in (routerRes === null || routerRes === void 0 ? void 0 : routerRes.setHeaders) || {}) {
375
+ for (const key in routerRes?.setHeaders || {}) {
383
376
  context.set(key, routerRes.setHeaders[key]);
384
377
  }
385
378
  break;
@@ -412,7 +405,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
412
405
  return (0, logger_1.createConsoleLogger)(name, option);
413
406
  }
414
407
  getFrameworkName() {
415
- return 'midway:faas';
408
+ return 'faas';
416
409
  }
417
410
  getServer() {
418
411
  return this.server;
@@ -442,6 +435,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
442
435
  return Array.from(this.funMappingStore.keys());
443
436
  }
444
437
  };
438
+ exports.MidwayFaaSFramework = MidwayFaaSFramework;
445
439
  __decorate([
446
440
  (0, core_1.Inject)(),
447
441
  __metadata("design:type", core_1.MidwayEnvironmentService)
@@ -450,8 +444,7 @@ __decorate([
450
444
  (0, core_1.Inject)(),
451
445
  __metadata("design:type", core_1.MidwayMiddlewareService)
452
446
  ], MidwayFaaSFramework.prototype, "middlewareService", void 0);
453
- MidwayFaaSFramework = __decorate([
447
+ exports.MidwayFaaSFramework = MidwayFaaSFramework = __decorate([
454
448
  (0, core_1.Framework)()
455
449
  ], MidwayFaaSFramework);
456
- exports.MidwayFaaSFramework = MidwayFaaSFramework;
457
450
  //# sourceMappingURL=framework.js.map
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { MidwayRequestContainer, IMidwayApplication, IConfigurationOptions, IMidwayContext, NextFunction as BaseNextFunction, CommonMiddlewareUnion, ContextMiddlewareManager, IMidwayBootstrapOptions, ObjectIdentifier, ILogger } from '@midwayjs/core';
3
3
  import { Application as ServerlessHttpApplication, HttpResponseOptions } from '@midwayjs/serverless-http-parser';
4
- import { Cookies } from '@midwayjs/cookies';
4
+ import type { Cookies } from '@midwayjs/cookies';
5
5
  import { Writable } from 'stream';
6
6
  interface ContextDelegatedRequest {
7
7
  /**
package/dist/starter.js CHANGED
@@ -34,6 +34,10 @@ class AbstractBootstrapStarter {
34
34
  this.startedExports = this.onStart();
35
35
  }
36
36
  if (this.startedExports) {
37
+ if (options) {
38
+ // 单测时这里要再覆盖一次,不然外面的 options 传不进来
39
+ this.options = Object.assign(this.options, options);
40
+ }
37
41
  this.startedExports['getStarter'] = () => {
38
42
  return this;
39
43
  };
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@midwayjs/faas",
3
- "version": "3.19.2",
3
+ "version": "4.0.0-alpha.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "index.d.ts",
6
6
  "dependencies": {
7
- "@midwayjs/core": "^3.19.0",
8
- "@midwayjs/serverless-http-parser": "^3.14.0",
7
+ "@midwayjs/core": "^4.0.0-alpha.1",
8
+ "@midwayjs/serverless-http-parser": "^4.0.0-alpha.1",
9
9
  "@midwayjs/simple-lock": "^1.1.4"
10
10
  },
11
11
  "devDependencies": {
12
+ "@midwayjs/cookies": "^1.0.2",
12
13
  "@midwayjs/logger": "^3.0.0",
13
- "@midwayjs/mock": "^3.19.2",
14
- "@midwayjs/serverless-fc-starter": "^3.19.0",
15
- "@midwayjs/serverless-scf-starter": "^3.14.0",
14
+ "@midwayjs/mock": "^4.0.0-alpha.1",
16
15
  "mm": "3.4.0"
17
16
  },
18
17
  "engines": {
@@ -36,13 +35,13 @@
36
35
  ],
37
36
  "scripts": {
38
37
  "build": "tsc",
39
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
40
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit"
38
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
39
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit"
41
40
  },
42
41
  "repository": {
43
42
  "type": "git",
44
43
  "url": "git@github.com:midwayjs/midway.git"
45
44
  },
46
45
  "license": "MIT",
47
- "gitHead": "57fd034be94897fb819b0d9ef776de0b9923ab0f"
46
+ "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
48
47
  }