@midwayjs/faas 3.4.0-beta.1 → 3.4.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/LICENSE +21 -0
- package/dist/framework.d.ts +2 -9
- package/dist/framework.js +31 -7
- package/dist/interface.d.ts +1 -0
- package/package.json +8 -8
- package/CHANGELOG.md +0 -1260
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 - Now midwayjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/framework.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
|
|
|
15
15
|
private server;
|
|
16
16
|
private respond;
|
|
17
17
|
private applicationAdapter;
|
|
18
|
+
private serverlessFunctionService;
|
|
18
19
|
protected httpMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
|
|
19
20
|
protected eventMiddlewareManager: ContextMiddlewareManager<Context, unknown, unknown>;
|
|
20
21
|
environmentService: MidwayEnvironmentService;
|
|
@@ -29,15 +30,7 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
|
|
|
29
30
|
* @param handlerMapping
|
|
30
31
|
*/
|
|
31
32
|
handleInvokeWrapper(handlerMapping: string): (...args: any[]) => Promise<any>;
|
|
32
|
-
getTriggerFunction(handlerMapping: string): (context: any, options: HandlerOptions) => Promise<
|
|
33
|
-
result: any;
|
|
34
|
-
error: Error;
|
|
35
|
-
} | {
|
|
36
|
-
isBase64Encoded: boolean;
|
|
37
|
-
statusCode: any;
|
|
38
|
-
headers: any;
|
|
39
|
-
body: any;
|
|
40
|
-
}>;
|
|
33
|
+
getTriggerFunction(handlerMapping: string): (context: any, options: HandlerOptions) => Promise<any>;
|
|
41
34
|
wrapHttpRequest(req: http.IncomingMessage, res?: http.ServerResponse): Promise<unknown>;
|
|
42
35
|
/**
|
|
43
36
|
* @deprecated
|
package/dist/framework.js
CHANGED
|
@@ -15,6 +15,8 @@ const decorator_1 = require("@midwayjs/decorator");
|
|
|
15
15
|
const simple_lock_1 = require("@midwayjs/simple-lock");
|
|
16
16
|
const logger_1 = require("@midwayjs/logger");
|
|
17
17
|
const serverless_http_parser_1 = require("@midwayjs/serverless-http-parser");
|
|
18
|
+
const util_1 = require("util");
|
|
19
|
+
const { isAnyArrayBuffer, isUint8Array } = util_1.types;
|
|
18
20
|
const LOCK_KEY = '_faas_starter_start_key';
|
|
19
21
|
let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework {
|
|
20
22
|
constructor() {
|
|
@@ -109,8 +111,8 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
109
111
|
// set app keys
|
|
110
112
|
this.app['keys'] = (_a = this.configService.getConfiguration('keys')) !== null && _a !== void 0 ? _a : '';
|
|
111
113
|
// store all http function entry
|
|
112
|
-
|
|
113
|
-
const functionList = await
|
|
114
|
+
this.serverlessFunctionService = await this.applicationContext.getAsync(core_1.MidwayServerlessFunctionService);
|
|
115
|
+
const functionList = await this.serverlessFunctionService.getFunctionList();
|
|
114
116
|
for (const funcInfo of functionList) {
|
|
115
117
|
// store handler
|
|
116
118
|
this.funMappingStore.set(funcInfo.funcHandlerName, funcInfo);
|
|
@@ -160,7 +162,13 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
160
162
|
// invoke handler
|
|
161
163
|
const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
|
|
162
164
|
if (isHttpFunction && result !== undefined) {
|
|
163
|
-
|
|
165
|
+
if (result === null) {
|
|
166
|
+
// 这样设置可以绕过 koa 的 _explicitStatus 赋值机制
|
|
167
|
+
ctx.response._body = null;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
ctx.body = result;
|
|
171
|
+
}
|
|
164
172
|
}
|
|
165
173
|
return result;
|
|
166
174
|
},
|
|
@@ -207,9 +215,18 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
207
215
|
// invoke handler
|
|
208
216
|
const result = await this.invokeHandler(funOptions, ctx, args, isHttpFunction);
|
|
209
217
|
if (isHttpFunction && result !== undefined) {
|
|
210
|
-
|
|
218
|
+
if (result === null) {
|
|
219
|
+
// 这样设置可以绕过 koa 的 _explicitStatus 赋值机制
|
|
220
|
+
ctx.response._body = null;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
ctx.body = result;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
// http 靠 ctx.body,否则会出现状态码不正确的问题
|
|
227
|
+
if (!isHttpFunction) {
|
|
228
|
+
return result;
|
|
211
229
|
}
|
|
212
|
-
return result;
|
|
213
230
|
},
|
|
214
231
|
], this.app);
|
|
215
232
|
return await fn(ctx, next);
|
|
@@ -230,13 +247,13 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
230
247
|
}
|
|
231
248
|
context.body = data;
|
|
232
249
|
}
|
|
233
|
-
else if (
|
|
250
|
+
else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
|
|
234
251
|
encoded = true;
|
|
235
252
|
if (!context.type) {
|
|
236
253
|
context.type = 'application/octet-stream';
|
|
237
254
|
}
|
|
238
255
|
// data is reserved as buffer
|
|
239
|
-
context.body = data.toString('base64');
|
|
256
|
+
context.body = Buffer.from(data).toString('base64');
|
|
240
257
|
}
|
|
241
258
|
else if (typeof data === 'object') {
|
|
242
259
|
if (!context.type) {
|
|
@@ -252,6 +269,13 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
252
269
|
// set data to string
|
|
253
270
|
context.body = data = data + '';
|
|
254
271
|
}
|
|
272
|
+
// middleware return value and will be got 204 status
|
|
273
|
+
if (context.body === undefined &&
|
|
274
|
+
!context.response._explicitStatus &&
|
|
275
|
+
context._matchedRoute) {
|
|
276
|
+
// 如果进了路由,重新赋值,防止 404
|
|
277
|
+
context.body = undefined;
|
|
278
|
+
}
|
|
255
279
|
return {
|
|
256
280
|
isBase64Encoded: encoded,
|
|
257
281
|
statusCode: context.status,
|
package/dist/interface.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export interface IWebMiddleware {
|
|
|
61
61
|
}
|
|
62
62
|
export interface ServerlessStarterOptions extends IMidwayBootstrapOptions {
|
|
63
63
|
initializeMethodName?: string;
|
|
64
|
+
handlerName?: string;
|
|
64
65
|
createAdapter?: () => Promise<{
|
|
65
66
|
close(): any;
|
|
66
67
|
createAppHook(app?: any): any;
|
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.4",
|
|
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.4",
|
|
8
8
|
"@midwayjs/faas-typings": "^3.3.5",
|
|
9
9
|
"@midwayjs/logger": "^2.15.0",
|
|
10
|
-
"@midwayjs/serverless-http-parser": "^3.
|
|
10
|
+
"@midwayjs/serverless-http-parser": "^3.4.0-beta.4",
|
|
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.
|
|
14
|
+
"@midwayjs/decorator": "^3.4.0-beta.4",
|
|
15
|
+
"@midwayjs/mock": "^3.4.0-beta.4",
|
|
16
|
+
"@midwayjs/serverless-fc-starter": "^3.4.0-beta.4",
|
|
17
|
+
"@midwayjs/serverless-scf-starter": "^3.4.0-beta.4",
|
|
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": "3b686101f7802f87d47b8c9d25561339d556e573"
|
|
50
50
|
}
|