@midwayjs/faas 3.4.0-beta.3 → 3.4.0-beta.6
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/dist/configuration.js +2 -0
- package/dist/framework.d.ts +4 -3
- package/dist/framework.js +62 -68
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/interface.d.ts +3 -0
- package/package.json +8 -8
package/dist/configuration.js
CHANGED
|
@@ -33,8 +33,10 @@ let FaaSConfiguration = class FaaSConfiguration {
|
|
|
33
33
|
async onReady(container) { }
|
|
34
34
|
async onServerReady() {
|
|
35
35
|
if (!this.framework.isEnable()) {
|
|
36
|
+
// just in legacy local dev and test
|
|
36
37
|
await this.framework.run();
|
|
37
38
|
}
|
|
39
|
+
await this.framework.loadFunction();
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
42
|
__decorate([
|
package/dist/framework.d.ts
CHANGED
|
@@ -11,19 +11,21 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
|
|
|
11
11
|
app: Application;
|
|
12
12
|
private isReplaceLogger;
|
|
13
13
|
private developmentRun;
|
|
14
|
-
private serverlessRoutes;
|
|
15
14
|
private server;
|
|
16
15
|
private respond;
|
|
17
16
|
private applicationAdapter;
|
|
18
|
-
private
|
|
17
|
+
private serverlessFunctionService;
|
|
19
18
|
protected httpMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
|
|
20
19
|
protected eventMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
|
|
20
|
+
private legacyVersion;
|
|
21
|
+
private loadedFunction;
|
|
21
22
|
environmentService: MidwayEnvironmentService;
|
|
22
23
|
middlewareService: MidwayMiddlewareService<Context, any>;
|
|
23
24
|
configure(options: IFaaSConfigurationOptions): any;
|
|
24
25
|
isEnable(): boolean;
|
|
25
26
|
applicationInitialize(options: IMidwayBootstrapOptions): Promise<void>;
|
|
26
27
|
run(): Promise<void>;
|
|
28
|
+
loadFunction(): Promise<void>;
|
|
27
29
|
getFrameworkType(): MidwayFrameworkType;
|
|
28
30
|
/**
|
|
29
31
|
* @deprecated
|
|
@@ -49,5 +51,4 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
|
|
|
49
51
|
getEventMiddleware(): ContextMiddlewareManager<Context, NextFunction, undefined>;
|
|
50
52
|
getAllHandlerNames(): string[];
|
|
51
53
|
}
|
|
52
|
-
export declare const createModuleServerlessFramework: (globalOption: Omit<IMidwayBootstrapOptions, 'applicationContext'> & IFaaSConfigurationOptions) => Promise<MidwayFaaSFramework>;
|
|
53
54
|
//# sourceMappingURL=framework.d.ts.map
|
package/dist/framework.js
CHANGED
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.MidwayFaaSFramework = void 0;
|
|
13
13
|
const core_1 = require("@midwayjs/core");
|
|
14
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
15
15
|
const simple_lock_1 = require("@midwayjs/simple-lock");
|
|
@@ -26,9 +26,10 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
26
26
|
this.lock = new simple_lock_1.default();
|
|
27
27
|
this.isReplaceLogger = process.env['MIDWAY_SERVERLESS_REPLACE_LOGGER'] === 'true';
|
|
28
28
|
this.developmentRun = false;
|
|
29
|
-
this.serverlessRoutes = [];
|
|
30
29
|
this.httpMiddlewareManager = this.createMiddlewareManager();
|
|
31
30
|
this.eventMiddlewareManager = this.createMiddlewareManager();
|
|
31
|
+
this.legacyVersion = false;
|
|
32
|
+
this.loadedFunction = false;
|
|
32
33
|
}
|
|
33
34
|
configure(options) {
|
|
34
35
|
var _a;
|
|
@@ -51,6 +52,9 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
51
52
|
}
|
|
52
53
|
this.applicationAdapter =
|
|
53
54
|
this.configurationOptions.applicationAdapter || {};
|
|
55
|
+
if (this.applicationAdapter.getApplication) {
|
|
56
|
+
this.legacyVersion = true;
|
|
57
|
+
}
|
|
54
58
|
this.app =
|
|
55
59
|
((_b = (_a = this.applicationAdapter).getApplication) === null || _b === void 0 ? void 0 : _b.call(_a)) ||
|
|
56
60
|
new serverless_http_parser_1.Application();
|
|
@@ -106,30 +110,27 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
async run() {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.
|
|
123
|
-
|
|
124
|
-
// store
|
|
125
|
-
this.
|
|
126
|
-
matchPattern: (0, core_1.pathToRegexp)(funcInfo.url, [], { end: false }),
|
|
127
|
-
funcInfo: funcInfo,
|
|
128
|
-
});
|
|
113
|
+
if (this.legacyVersion) {
|
|
114
|
+
return this.loadFunction();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async loadFunction() {
|
|
118
|
+
if (!this.loadedFunction) {
|
|
119
|
+
this.loadedFunction = true;
|
|
120
|
+
return this.lock.sureOnce(async () => {
|
|
121
|
+
var _a;
|
|
122
|
+
// set app keys
|
|
123
|
+
this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
|
|
124
|
+
// store all http function entry
|
|
125
|
+
this.serverlessFunctionService = await this.applicationContext.getAsync(core_1.MidwayServerlessFunctionService);
|
|
126
|
+
const functionList = await this.serverlessFunctionService.getFunctionList();
|
|
127
|
+
for (const funcInfo of functionList) {
|
|
128
|
+
// store handler
|
|
129
|
+
this.funMappingStore.set(funcInfo.funcHandlerName, funcInfo);
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
131
|
+
this.respond = this.app.callback();
|
|
132
|
+
}, LOCK_KEY);
|
|
133
|
+
}
|
|
133
134
|
}
|
|
134
135
|
getFrameworkType() {
|
|
135
136
|
return core_1.MidwayFrameworkType.FAAS;
|
|
@@ -189,13 +190,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
189
190
|
var _a;
|
|
190
191
|
const isHttpFunction = options.isHttpFunction;
|
|
191
192
|
if (!funOptions && isHttpFunction) {
|
|
192
|
-
|
|
193
|
-
if (context.method === item.funcInfo['requestMethod'].toUpperCase() &&
|
|
194
|
-
item.matchPattern.test(context.path)) {
|
|
195
|
-
funOptions = item.funcInfo;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
193
|
+
funOptions = await this.serverlessFunctionService.getMatchedRouterInfo(context.path, context.method);
|
|
199
194
|
}
|
|
200
195
|
if (!funOptions) {
|
|
201
196
|
throw new Error(`function handler = ${handlerMapping} not found`);
|
|
@@ -324,36 +319,44 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
324
319
|
return context;
|
|
325
320
|
}
|
|
326
321
|
async invokeHandler(routerInfo, context, args, isHttpFunction) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
322
|
+
if (typeof routerInfo.method !== 'string') {
|
|
323
|
+
if (!isHttpFunction) {
|
|
324
|
+
args.unshift(context);
|
|
325
|
+
}
|
|
326
|
+
return routerInfo.method(...args);
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
const funModule = await context.requestContext.getAsync(routerInfo.controllerId);
|
|
330
|
+
const handlerName = this.getFunctionHandler(context, args, funModule, routerInfo.method) ||
|
|
331
|
+
this.defaultHandlerMethod;
|
|
332
|
+
if (funModule[handlerName]) {
|
|
333
|
+
// invoke real method
|
|
334
|
+
const result = await funModule[handlerName](...args);
|
|
335
|
+
// implement response decorator
|
|
336
|
+
const routerResponseData = routerInfo.responseMetadata;
|
|
337
|
+
if (isHttpFunction) {
|
|
338
|
+
for (const routerRes of routerResponseData) {
|
|
339
|
+
switch (routerRes.type) {
|
|
340
|
+
case decorator_1.WEB_RESPONSE_HTTP_CODE:
|
|
341
|
+
context.status = routerRes.code;
|
|
342
|
+
break;
|
|
343
|
+
case decorator_1.WEB_RESPONSE_HEADER:
|
|
344
|
+
for (const key in (routerRes === null || routerRes === void 0 ? void 0 : routerRes.setHeaders) || {}) {
|
|
345
|
+
context.set(key, routerRes.setHeaders[key]);
|
|
346
|
+
}
|
|
347
|
+
break;
|
|
348
|
+
case decorator_1.WEB_RESPONSE_CONTENT_TYPE:
|
|
349
|
+
context.type = routerRes.contentType;
|
|
350
|
+
break;
|
|
351
|
+
case decorator_1.WEB_RESPONSE_REDIRECT:
|
|
352
|
+
context.status = routerRes.code;
|
|
353
|
+
context.redirect(routerRes.url);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
353
356
|
}
|
|
354
357
|
}
|
|
358
|
+
return result;
|
|
355
359
|
}
|
|
356
|
-
return result;
|
|
357
360
|
}
|
|
358
361
|
}
|
|
359
362
|
getFunctionHandler(ctx, args, target, method) {
|
|
@@ -406,13 +409,4 @@ MidwayFaaSFramework = __decorate([
|
|
|
406
409
|
(0, decorator_1.Framework)()
|
|
407
410
|
], MidwayFaaSFramework);
|
|
408
411
|
exports.MidwayFaaSFramework = MidwayFaaSFramework;
|
|
409
|
-
const createModuleServerlessFramework = async (globalOption) => {
|
|
410
|
-
const applicationContext = await (0, core_1.initializeGlobalApplicationContext)({
|
|
411
|
-
...globalOption,
|
|
412
|
-
baseDir: '',
|
|
413
|
-
appDir: '',
|
|
414
|
-
});
|
|
415
|
-
return applicationContext.get(MidwayFaaSFramework);
|
|
416
|
-
};
|
|
417
|
-
exports.createModuleServerlessFramework = createModuleServerlessFramework;
|
|
418
412
|
//# sourceMappingURL=framework.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './interface';
|
|
2
|
-
export { MidwayFaaSFramework as Framework
|
|
2
|
+
export { MidwayFaaSFramework as Framework } from './framework';
|
|
3
3
|
export { FaaSConfiguration as Configuration } from './configuration';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -14,11 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Configuration = exports.
|
|
17
|
+
exports.Configuration = exports.Framework = void 0;
|
|
18
18
|
__exportStar(require("./interface"), exports);
|
|
19
19
|
var framework_1 = require("./framework");
|
|
20
20
|
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return framework_1.MidwayFaaSFramework; } });
|
|
21
|
-
Object.defineProperty(exports, "createModuleServerlessFramework", { enumerable: true, get: function () { return framework_1.createModuleServerlessFramework; } });
|
|
22
21
|
var configuration_1 = require("./configuration");
|
|
23
22
|
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.FaaSConfiguration; } });
|
|
24
23
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -47,6 +47,9 @@ export interface IFaaSConfigurationOptions extends IConfigurationOptions {
|
|
|
47
47
|
config?: object;
|
|
48
48
|
initializeContext?: object;
|
|
49
49
|
applicationAdapter?: {
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated
|
|
52
|
+
*/
|
|
50
53
|
getApplication(): Application;
|
|
51
54
|
getFunctionName(): string;
|
|
52
55
|
getFunctionServiceName(): string;
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/faas",
|
|
3
|
-
"version": "3.4.0-beta.
|
|
3
|
+
"version": "3.4.0-beta.6",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@midwayjs/core": "^3.4.0-beta.
|
|
7
|
+
"@midwayjs/core": "^3.4.0-beta.6",
|
|
8
8
|
"@midwayjs/faas-typings": "^3.3.5",
|
|
9
9
|
"@midwayjs/logger": "^2.15.0",
|
|
10
|
-
"@midwayjs/serverless-http-parser": "^3.4.0-beta.
|
|
10
|
+
"@midwayjs/serverless-http-parser": "^3.4.0-beta.6",
|
|
11
11
|
"@midwayjs/simple-lock": "^1.1.4"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@midwayjs/decorator": "^3.4.0-beta.
|
|
15
|
-
"@midwayjs/mock": "^3.4.0-beta.
|
|
16
|
-
"@midwayjs/serverless-fc-starter": "^3.4.0-beta.
|
|
17
|
-
"@midwayjs/serverless-scf-starter": "^3.4.0-beta.
|
|
14
|
+
"@midwayjs/decorator": "^3.4.0-beta.6",
|
|
15
|
+
"@midwayjs/mock": "^3.4.0-beta.6",
|
|
16
|
+
"@midwayjs/serverless-fc-starter": "^3.4.0-beta.6",
|
|
17
|
+
"@midwayjs/serverless-scf-starter": "^3.4.0-beta.6",
|
|
18
18
|
"mm": "3.2.0"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"url": "git@github.com:midwayjs/midway.git"
|
|
47
47
|
},
|
|
48
48
|
"license": "MIT",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "8e187c4593d4832de32b6745af3e195f6b90816c"
|
|
50
50
|
}
|