@midwayjs/faas 3.0.0-alpha.6 → 3.0.0-beta.11
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 +106 -0
- package/dist/config.default.d.ts +8 -0
- package/dist/config.default.js +15 -0
- package/dist/configuration.d.ts +11 -0
- package/dist/configuration.js +69 -0
- package/dist/framework.d.ts +13 -9
- package/dist/framework.js +75 -106
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -9
- package/dist/interface.d.ts +6 -5
- package/dist/util.d.ts +3 -7
- package/dist/util.js +4 -8
- package/package.json +11 -12
- package/dist/hooks.d.ts +0 -16
- package/dist/hooks.js +0 -32
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,112 @@
|
|
|
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.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* 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))
|
|
20
|
+
* implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* faas missing config in framework ([#1413](https://github.com/midwayjs/midway/issues/1413)) ([7ab16a2](https://github.com/midwayjs/midway/commit/7ab16a24b29d5254a762bfffcdf18385effdf639))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
38
|
+
|
|
39
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
|
|
57
|
+
|
|
58
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
|
|
65
|
+
|
|
66
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### Features
|
|
76
|
+
|
|
77
|
+
* add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
|
|
78
|
+
* auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
|
|
79
|
+
* support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
86
|
+
|
|
87
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
94
|
+
|
|
95
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Bug Fixes
|
|
105
|
+
|
|
106
|
+
* static prefix ([#1321](https://github.com/midwayjs/midway/issues/1321)) ([31fe961](https://github.com/midwayjs/midway/commit/31fe961931fed7656a144b1682ee4c4bb25fdff5))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
6
112
|
## [2.12.4](https://github.com/midwayjs/midway/compare/v2.12.3...v2.12.4) (2021-08-13)
|
|
7
113
|
|
|
8
114
|
|
|
@@ -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
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
import { FaaSContext,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
},
|
|
@@ -50,37 +68,11 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
50
68
|
},
|
|
51
69
|
});
|
|
52
70
|
}
|
|
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();
|
|
72
|
-
}
|
|
73
71
|
async run() {
|
|
74
72
|
return this.lock.sureOnce(async () => {
|
|
75
73
|
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
74
|
// set app keys
|
|
83
|
-
this.app['keys'] = this.
|
|
75
|
+
this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
|
|
84
76
|
// store all http function entry
|
|
85
77
|
const collector = new core_1.ServerlessTriggerCollector();
|
|
86
78
|
const functionList = await collector.getFunctionList();
|
|
@@ -98,50 +90,47 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
98
90
|
if (args.length === 0) {
|
|
99
91
|
throw new Error('first parameter must be function context');
|
|
100
92
|
}
|
|
93
|
+
if (!funOptions) {
|
|
94
|
+
throw new Error(`function handler = ${handlerMapping} not found`);
|
|
95
|
+
}
|
|
101
96
|
const context = this.getContext(args.shift());
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}
|
|
114
109
|
// invoke handler
|
|
115
|
-
const result = await this.invokeHandler(funOptions, ctx,
|
|
116
|
-
if (result !== undefined) {
|
|
110
|
+
const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
|
|
111
|
+
if (isHttpFunction && result !== undefined) {
|
|
117
112
|
ctx.body = result;
|
|
118
113
|
}
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// invoke handler
|
|
127
|
-
return this.invokeHandler(funOptions, context, null, args);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
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);
|
|
131
121
|
};
|
|
132
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated
|
|
125
|
+
* @param middlewareId
|
|
126
|
+
*/
|
|
133
127
|
async generateMiddleware(middlewareId) {
|
|
134
128
|
const mwIns = await this.getApplicationContext().getAsync(middlewareId);
|
|
135
129
|
return mwIns.resolve();
|
|
136
130
|
}
|
|
137
131
|
getContext(context) {
|
|
138
132
|
if (!context.env) {
|
|
139
|
-
context.env = this.
|
|
140
|
-
.getEnvironmentService()
|
|
141
|
-
.getCurrentEnvironment();
|
|
142
|
-
}
|
|
143
|
-
if (!context.hooks) {
|
|
144
|
-
context.hooks = new hooks_1.MidwayHooks(context, this.app);
|
|
133
|
+
context.env = this.environmentService.getCurrentEnvironment();
|
|
145
134
|
}
|
|
146
135
|
if (this.isReplaceLogger || !context.logger) {
|
|
147
136
|
context._serverlessLogger = this.createContextLogger(context);
|
|
@@ -157,13 +146,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
157
146
|
this.app.createAnonymousContext(context);
|
|
158
147
|
return context;
|
|
159
148
|
}
|
|
160
|
-
async invokeHandler(routerInfo, context,
|
|
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
|
-
}
|
|
149
|
+
async invokeHandler(routerInfo, context, args, isHttpFunction) {
|
|
167
150
|
const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
|
|
168
151
|
const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
|
|
169
152
|
this.defaultHandlerMethod;
|
|
@@ -172,7 +155,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
172
155
|
const result = await funModule[handlerName](...args);
|
|
173
156
|
// implement response decorator
|
|
174
157
|
const routerResponseData = routerInfo.responseMetadata;
|
|
175
|
-
if (
|
|
158
|
+
if (isHttpFunction) {
|
|
176
159
|
for (const routerRes of routerResponseData) {
|
|
177
160
|
switch (routerRes.type) {
|
|
178
161
|
case decorator_1.WEB_RESPONSE_HTTP_CODE:
|
|
@@ -206,38 +189,24 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
206
189
|
}
|
|
207
190
|
throw new Error(`no handler setup on ${target.name}#${method || this.defaultHandlerMethod}`);
|
|
208
191
|
}
|
|
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
192
|
createLogger(name, option = {}) {
|
|
235
193
|
// 覆盖基类的创建日志对象,函数场景下的日志,即使自定义,也只启用控制台输出
|
|
236
|
-
return logger_1.createConsoleLogger(name, option);
|
|
194
|
+
return (0, logger_1.createConsoleLogger)(name, option);
|
|
237
195
|
}
|
|
238
196
|
getFrameworkName() {
|
|
239
197
|
return 'midway:faas';
|
|
240
198
|
}
|
|
241
|
-
}
|
|
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);
|
|
242
211
|
exports.MidwayFaaSFramework = MidwayFaaSFramework;
|
|
243
212
|
//# 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 {
|
|
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.
|
|
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
|
|
18
|
-
Object.defineProperty(exports, "
|
|
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
|
package/dist/interface.d.ts
CHANGED
|
@@ -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
|
-
|
|
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,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
entry: {
|
|
5
|
-
Configuration: any;
|
|
6
|
-
};
|
|
7
|
-
}) => Promise<Framework>;
|
|
1
|
+
import { IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
2
|
+
import { Framework, IFaaSConfigurationOptions } from './index';
|
|
3
|
+
export declare const createModuleServerlessFramework: (globalOption: Omit<IMidwayBootstrapOptions, 'applicationContext'> & IFaaSConfigurationOptions) => Promise<Framework>;
|
|
8
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 (
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
framework.configure({});
|
|
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
|
-
|
|
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-
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@midwayjs/core": "^3.0.0-
|
|
8
|
-
"@midwayjs/
|
|
9
|
-
"@midwayjs/
|
|
10
|
-
"@midwayjs/
|
|
11
|
-
"@midwayjs/simple-lock": "^1.1.4",
|
|
12
|
-
"koa-compose": "^4.1.0"
|
|
7
|
+
"@midwayjs/core": "^3.0.0-beta.11",
|
|
8
|
+
"@midwayjs/faas-typings": "^3.0.0-beta.11",
|
|
9
|
+
"@midwayjs/logger": "^3.0.0-beta.11",
|
|
10
|
+
"@midwayjs/simple-lock": "^1.1.4"
|
|
13
11
|
},
|
|
14
12
|
"devDependencies": {
|
|
15
|
-
"@midwayjs/
|
|
16
|
-
"@midwayjs/
|
|
17
|
-
"@midwayjs/serverless-
|
|
13
|
+
"@midwayjs/decorator": "^3.0.0-beta.11",
|
|
14
|
+
"@midwayjs/mock": "^3.0.0-beta.11",
|
|
15
|
+
"@midwayjs/serverless-fc-starter": "^3.0.0-beta.11",
|
|
16
|
+
"@midwayjs/serverless-scf-starter": "^3.0.0-beta.11",
|
|
18
17
|
"mm": "3"
|
|
19
18
|
},
|
|
20
19
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
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": "
|
|
48
|
+
"gitHead": "a2b066fd500e815e799e7f421cd216f12e0e9f8e"
|
|
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
|