@midwayjs/faas 3.0.0-alpha.9 → 3.0.0-beta.4
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 +40 -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 +67 -0
- package/dist/framework.d.ts +12 -9
- package/dist/framework.js +71 -105
- 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 +2 -9
- 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,46 @@
|
|
|
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.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
|
|
12
|
+
* auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
|
|
13
|
+
* support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
20
|
+
|
|
21
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
28
|
+
|
|
29
|
+
**Note:** Version bump only for package @midwayjs/faas
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* static prefix ([#1321](https://github.com/midwayjs/midway/issues/1321)) ([31fe961](https://github.com/midwayjs/midway/commit/31fe961931fed7656a144b1682ee4c4bb25fdff5))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
6
46
|
## [2.12.4](https://github.com/midwayjs/midway/compare/v2.12.3...v2.12.4) (2021-08-13)
|
|
7
47
|
|
|
8
48
|
|
|
@@ -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,67 @@
|
|
|
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
|
+
await this.framework.run();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, decorator_1.Inject)(),
|
|
40
|
+
__metadata("design:type", framework_1.MidwayFaaSFramework)
|
|
41
|
+
], FaaSConfiguration.prototype, "framework", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, decorator_1.Inject)(),
|
|
44
|
+
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
45
|
+
], FaaSConfiguration.prototype, "decoratorService", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, decorator_1.ApplicationContext)(),
|
|
48
|
+
__metadata("design:type", Object)
|
|
49
|
+
], FaaSConfiguration.prototype, "applicationContext", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, decorator_1.Init)(),
|
|
52
|
+
__metadata("design:type", Function),
|
|
53
|
+
__metadata("design:paramtypes", []),
|
|
54
|
+
__metadata("design:returntype", Promise)
|
|
55
|
+
], FaaSConfiguration.prototype, "init", null);
|
|
56
|
+
FaaSConfiguration = __decorate([
|
|
57
|
+
(0, decorator_1.Configuration)({
|
|
58
|
+
namespace: 'faas',
|
|
59
|
+
importConfigs: [
|
|
60
|
+
{
|
|
61
|
+
default: DefaultConfig,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
})
|
|
65
|
+
], FaaSConfiguration);
|
|
66
|
+
exports.FaaSConfiguration = FaaSConfiguration;
|
|
67
|
+
//# sourceMappingURL=configuration.js.map
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
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
|
+
environmentService: MidwayEnvironmentService;
|
|
12
|
+
middlewareService: MidwayMiddlewareService<FaaSContext, any>;
|
|
13
|
+
configure(options: IFaaSConfigurationOptions): void;
|
|
14
|
+
isEnable(): boolean;
|
|
12
15
|
applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
|
|
13
|
-
protected initializeLogger(options: IMidwayBootstrapOptions): Promise<void>;
|
|
14
|
-
protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
15
16
|
run(): Promise<void>;
|
|
16
17
|
getFrameworkType(): MidwayFrameworkType;
|
|
17
18
|
handleInvokeWrapper(handlerMapping: string): (...args: any[]) => Promise<any>;
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated
|
|
21
|
+
* @param middlewareId
|
|
22
|
+
*/
|
|
23
|
+
generateMiddleware(middlewareId: string): Promise<FunctionMiddleware<FaaSContext, any>>;
|
|
19
24
|
getContext(context: any): any;
|
|
20
25
|
private invokeHandler;
|
|
21
26
|
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;
|
|
27
|
+
createLogger(name: string, option?: LoggerOptions): import("@midwayjs/core").ILogger;
|
|
25
28
|
getFrameworkName(): string;
|
|
26
29
|
}
|
|
27
30
|
//# sourceMappingURL=framework.d.ts.map
|
package/dist/framework.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
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';
|
|
@@ -16,9 +23,17 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
16
23
|
this.lock = new simple_lock_1.default();
|
|
17
24
|
this.isReplaceLogger = process.env['MIDWAY_SERVERLESS_REPLACE_LOGGER'] === 'true';
|
|
18
25
|
}
|
|
26
|
+
configure(options) {
|
|
27
|
+
this.configurationOptions = options;
|
|
28
|
+
}
|
|
29
|
+
isEnable() {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
19
32
|
async applicationInitialize(options) {
|
|
20
33
|
var _a;
|
|
21
|
-
|
|
34
|
+
if (!this.logger) {
|
|
35
|
+
this.logger = options.logger || logger_1.loggers.getLogger('appLogger');
|
|
36
|
+
}
|
|
22
37
|
this.app =
|
|
23
38
|
((_a = this.configurationOptions.applicationAdapter) === null || _a === void 0 ? void 0 : _a.getApplication()) ||
|
|
24
39
|
{};
|
|
@@ -29,14 +44,10 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
29
44
|
getInitializeContext: () => {
|
|
30
45
|
return this.configurationOptions.initializeContext;
|
|
31
46
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.app.use(mw);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated
|
|
49
|
+
* @param middlewareId
|
|
50
|
+
*/
|
|
40
51
|
generateMiddleware: async (middlewareId) => {
|
|
41
52
|
return this.generateMiddleware(middlewareId);
|
|
42
53
|
},
|
|
@@ -50,37 +61,11 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
50
61
|
},
|
|
51
62
|
});
|
|
52
63
|
}
|
|
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
64
|
async run() {
|
|
74
65
|
return this.lock.sureOnce(async () => {
|
|
75
66
|
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
67
|
// set app keys
|
|
83
|
-
this.app['keys'] = this.
|
|
68
|
+
this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
|
|
84
69
|
// store all http function entry
|
|
85
70
|
const collector = new core_1.ServerlessTriggerCollector();
|
|
86
71
|
const functionList = await collector.getFunctionList();
|
|
@@ -98,50 +83,51 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
98
83
|
if (args.length === 0) {
|
|
99
84
|
throw new Error('first parameter must be function context');
|
|
100
85
|
}
|
|
86
|
+
if (!funOptions) {
|
|
87
|
+
throw new Error(`function handler = ${handlerMapping} not found`);
|
|
88
|
+
}
|
|
101
89
|
const context = this.getContext(args.shift());
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
90
|
+
const isHttpFunction = !!(context.headers && context.get);
|
|
91
|
+
const globalMiddlewareFn = await this.getMiddleware();
|
|
92
|
+
const middlewareManager = new core_1.ContextMiddlewareManager();
|
|
93
|
+
middlewareManager.insertLast(globalMiddlewareFn);
|
|
94
|
+
middlewareManager.insertLast(async (ctx, next) => {
|
|
95
|
+
const fn = await this.middlewareService.compose([
|
|
96
|
+
...funOptions.controllerMiddleware,
|
|
97
|
+
...funOptions.middleware,
|
|
98
|
+
async (ctx, next) => {
|
|
99
|
+
if (isHttpFunction) {
|
|
100
|
+
args = [ctx];
|
|
101
|
+
}
|
|
114
102
|
// invoke handler
|
|
115
|
-
const result = await this.invokeHandler(funOptions, ctx,
|
|
116
|
-
if (result !== undefined) {
|
|
103
|
+
const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
|
|
104
|
+
if (isHttpFunction && result !== undefined) {
|
|
117
105
|
ctx.body = result;
|
|
118
106
|
}
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
107
|
+
return result;
|
|
108
|
+
},
|
|
109
|
+
]);
|
|
110
|
+
return await fn(ctx, next);
|
|
111
|
+
});
|
|
112
|
+
const composeMiddleware = await this.middlewareService.compose(middlewareManager);
|
|
113
|
+
const { error, result } = await composeMiddleware(context);
|
|
114
|
+
if (error) {
|
|
115
|
+
throw error;
|
|
129
116
|
}
|
|
130
|
-
|
|
117
|
+
return result;
|
|
131
118
|
};
|
|
132
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* @deprecated
|
|
122
|
+
* @param middlewareId
|
|
123
|
+
*/
|
|
133
124
|
async generateMiddleware(middlewareId) {
|
|
134
125
|
const mwIns = await this.getApplicationContext().getAsync(middlewareId);
|
|
135
126
|
return mwIns.resolve();
|
|
136
127
|
}
|
|
137
128
|
getContext(context) {
|
|
138
129
|
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);
|
|
130
|
+
context.env = this.environmentService.getCurrentEnvironment();
|
|
145
131
|
}
|
|
146
132
|
if (this.isReplaceLogger || !context.logger) {
|
|
147
133
|
context._serverlessLogger = this.createContextLogger(context);
|
|
@@ -157,13 +143,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
157
143
|
this.app.createAnonymousContext(context);
|
|
158
144
|
return context;
|
|
159
145
|
}
|
|
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
|
-
}
|
|
146
|
+
async invokeHandler(routerInfo, context, args, isHttpFunction) {
|
|
167
147
|
const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
|
|
168
148
|
const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
|
|
169
149
|
this.defaultHandlerMethod;
|
|
@@ -172,7 +152,7 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
172
152
|
const result = await funModule[handlerName](...args);
|
|
173
153
|
// implement response decorator
|
|
174
154
|
const routerResponseData = routerInfo.responseMetadata;
|
|
175
|
-
if (
|
|
155
|
+
if (isHttpFunction) {
|
|
176
156
|
for (const routerRes of routerResponseData) {
|
|
177
157
|
switch (routerRes.type) {
|
|
178
158
|
case decorator_1.WEB_RESPONSE_HTTP_CODE:
|
|
@@ -206,38 +186,24 @@ class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
|
206
186
|
}
|
|
207
187
|
throw new Error(`no handler setup on ${target.name}#${method || this.defaultHandlerMethod}`);
|
|
208
188
|
}
|
|
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
189
|
createLogger(name, option = {}) {
|
|
235
190
|
// 覆盖基类的创建日志对象,函数场景下的日志,即使自定义,也只启用控制台输出
|
|
236
|
-
return logger_1.createConsoleLogger(name, option);
|
|
191
|
+
return (0, logger_1.createConsoleLogger)(name, option);
|
|
237
192
|
}
|
|
238
193
|
getFrameworkName() {
|
|
239
194
|
return 'midway:faas';
|
|
240
195
|
}
|
|
241
|
-
}
|
|
196
|
+
};
|
|
197
|
+
__decorate([
|
|
198
|
+
(0, decorator_1.Inject)(),
|
|
199
|
+
__metadata("design:type", core_1.MidwayEnvironmentService)
|
|
200
|
+
], MidwayFaaSFramework.prototype, "environmentService", void 0);
|
|
201
|
+
__decorate([
|
|
202
|
+
(0, decorator_1.Inject)(),
|
|
203
|
+
__metadata("design:type", core_1.MidwayMiddlewareService)
|
|
204
|
+
], MidwayFaaSFramework.prototype, "middlewareService", void 0);
|
|
205
|
+
MidwayFaaSFramework = __decorate([
|
|
206
|
+
(0, decorator_1.Framework)()
|
|
207
|
+
], MidwayFaaSFramework);
|
|
242
208
|
exports.MidwayFaaSFramework = MidwayFaaSFramework;
|
|
243
209
|
//# 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,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMidwayBootstrapOptions } from '@midwayjs/core';
|
|
2
2
|
import { Framework, IFaaSConfigurationOptions } from './index';
|
|
3
|
-
export
|
|
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 (
|
|
7
|
-
const
|
|
8
|
-
|
|
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
|
-
|
|
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.4",
|
|
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.4",
|
|
8
|
+
"@midwayjs/faas-typings": "^3.0.0-beta.4",
|
|
9
|
+
"@midwayjs/logger": "^3.0.0-beta.4",
|
|
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.4",
|
|
14
|
+
"@midwayjs/mock": "^3.0.0-beta.4",
|
|
15
|
+
"@midwayjs/serverless-fc-starter": "^3.0.0-beta.4",
|
|
16
|
+
"@midwayjs/serverless-scf-starter": "^3.0.0-beta.4",
|
|
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": "02e2144e302f807770b512b0d89da3145b1cbf2e"
|
|
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
|