@midwayjs/faas 3.8.1 → 3.9.1-beta.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.
- package/dist/decorator.d.ts +2 -0
- package/dist/decorator.js +12 -0
- package/dist/framework.d.ts +2 -1
- package/dist/framework.js +55 -74
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interface.d.ts +12 -2
- package/dist/starter.d.ts +3 -0
- package/dist/starter.js +3 -0
- package/package.json +4 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Event = void 0;
|
|
4
|
+
const core_1 = require("@midwayjs/core");
|
|
5
|
+
// 实现装饰器
|
|
6
|
+
const Event = () => {
|
|
7
|
+
return (0, core_1.createRequestParamDecorator)(ctx => {
|
|
8
|
+
return ctx.originEvent && ctx.originContext ? ctx.originEvent : ctx;
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
exports.Event = Event;
|
|
12
|
+
//# sourceMappingURL=decorator.js.map
|
package/dist/framework.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions } from './interface';
|
|
2
|
+
import { Context, IFaaSConfigurationOptions, Application, NextFunction, HandlerOptions, HttpResponseFormat } from './interface';
|
|
3
3
|
import { BaseFramework, CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IMidwayBootstrapOptions, MidwayEnvironmentService, MidwayFrameworkType, MidwayMiddlewareService, RouterInfo } from '@midwayjs/core';
|
|
4
4
|
import { LoggerOptions } from '@midwayjs/logger';
|
|
5
5
|
import * as http from 'http';
|
|
@@ -33,6 +33,7 @@ export declare class MidwayFaaSFramework extends BaseFramework<Application, Cont
|
|
|
33
33
|
*/
|
|
34
34
|
handleInvokeWrapper(handlerMapping: string): (...args: any[]) => Promise<any>;
|
|
35
35
|
invokeTriggerFunction(context: any, handlerMapping: string, options: HandlerOptions): Promise<any>;
|
|
36
|
+
formatHttpResponse(context: any): HttpResponseFormat;
|
|
36
37
|
wrapHttpRequest(req: http.IncomingMessage | Record<string, any>, res?: http.ServerResponse): Promise<unknown>;
|
|
37
38
|
/**
|
|
38
39
|
* @deprecated
|
package/dist/framework.js
CHANGED
|
@@ -92,33 +92,8 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
92
92
|
getEventMiddleware: () => {
|
|
93
93
|
return this.getEventMiddleware();
|
|
94
94
|
},
|
|
95
|
-
getServerlessInstance: async (
|
|
96
|
-
|
|
97
|
-
get: (target, prop) => {
|
|
98
|
-
let funcInfo;
|
|
99
|
-
if (typeof serviceClass === 'string') {
|
|
100
|
-
funcInfo = this.funMappingStore.get(`${serviceClass}.${prop}`);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
funcInfo = Array.from(this.funMappingStore.values()).find(item => {
|
|
104
|
-
return (item.id === (0, core_1.getProviderUUId)(serviceClass) &&
|
|
105
|
-
item.method === prop);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (funcInfo) {
|
|
109
|
-
return async (...args) => {
|
|
110
|
-
const context = this.app.createAnonymousContext({
|
|
111
|
-
originContext: customContext,
|
|
112
|
-
originEvent: args[0],
|
|
113
|
-
});
|
|
114
|
-
return this.invokeTriggerFunction(context, funcInfo.funcHandlerName, {
|
|
115
|
-
isHttpFunction: false,
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
return instance;
|
|
95
|
+
getServerlessInstance: async () => {
|
|
96
|
+
throw new core_1.MidwayFeatureNotImplementedError('Please use it in by @midwayjs/mock in test.');
|
|
122
97
|
},
|
|
123
98
|
invokeTriggerFunction: (context, handlerMapping, options) => {
|
|
124
99
|
return this.invokeTriggerFunction(context, handlerMapping, options);
|
|
@@ -216,7 +191,7 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
216
191
|
};
|
|
217
192
|
}
|
|
218
193
|
async invokeTriggerFunction(context, handlerMapping, options) {
|
|
219
|
-
var _a
|
|
194
|
+
var _a;
|
|
220
195
|
let funOptions = this.funMappingStore.get(handlerMapping);
|
|
221
196
|
const isHttpFunction = options.isHttpFunction;
|
|
222
197
|
if (!funOptions && isHttpFunction) {
|
|
@@ -268,60 +243,66 @@ let MidwayFaaSFramework = class MidwayFaaSFramework extends core_1.BaseFramework
|
|
|
268
243
|
return await fn(ctx, next);
|
|
269
244
|
}))(context);
|
|
270
245
|
if (isHttpFunction) {
|
|
271
|
-
if (!
|
|
272
|
-
|
|
273
|
-
context.body = '';
|
|
274
|
-
context.type = 'text';
|
|
275
|
-
context.status = 204;
|
|
276
|
-
}
|
|
246
|
+
if (!options.isChunked) {
|
|
247
|
+
return this.formatHttpResponse(context);
|
|
277
248
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
// data is reserved as buffer
|
|
292
|
-
context.body = Buffer.from(data).toString('base64');
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
formatHttpResponse(context) {
|
|
255
|
+
var _a;
|
|
256
|
+
if (!((_a = context.response) === null || _a === void 0 ? void 0 : _a._explicitStatus)) {
|
|
257
|
+
if (context.body === null || context.body === 'undefined') {
|
|
258
|
+
context.body = '';
|
|
259
|
+
context.type = 'text';
|
|
260
|
+
context.status = 204;
|
|
293
261
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
context.
|
|
262
|
+
}
|
|
263
|
+
let encoded = false;
|
|
264
|
+
const data = context.body;
|
|
265
|
+
if (typeof data === 'string') {
|
|
266
|
+
if (!context.type) {
|
|
267
|
+
context.type = 'text/plain';
|
|
300
268
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
context.
|
|
269
|
+
context.body = data;
|
|
270
|
+
}
|
|
271
|
+
else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
|
|
272
|
+
encoded = true;
|
|
273
|
+
if (!context.type) {
|
|
274
|
+
context.type = 'application/octet-stream';
|
|
307
275
|
}
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
context.
|
|
276
|
+
// data is reserved as buffer
|
|
277
|
+
context.body = Buffer.from(data).toString('base64');
|
|
278
|
+
}
|
|
279
|
+
else if (typeof data === 'object') {
|
|
280
|
+
if (!context.type) {
|
|
281
|
+
context.type = 'application/json';
|
|
314
282
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
statusCode: context.status,
|
|
318
|
-
headers: context.res.headers,
|
|
319
|
-
body: context.body,
|
|
320
|
-
};
|
|
283
|
+
// set data to string
|
|
284
|
+
context.body = JSON.stringify(data);
|
|
321
285
|
}
|
|
322
286
|
else {
|
|
323
|
-
|
|
287
|
+
if (!context.type) {
|
|
288
|
+
context.type = 'text/plain';
|
|
289
|
+
}
|
|
290
|
+
// set data to string
|
|
291
|
+
context.body = data + '';
|
|
292
|
+
}
|
|
293
|
+
// middleware return value and will be got 204 status
|
|
294
|
+
if (context.body === undefined &&
|
|
295
|
+
!context.response._explicitStatus &&
|
|
296
|
+
context._matchedRoute) {
|
|
297
|
+
// 如果进了路由,重新赋值,防止 404
|
|
298
|
+
context.body = undefined;
|
|
324
299
|
}
|
|
300
|
+
return {
|
|
301
|
+
isBase64Encoded: encoded,
|
|
302
|
+
statusCode: context.status,
|
|
303
|
+
headers: context.res.headers,
|
|
304
|
+
body: context.body,
|
|
305
|
+
};
|
|
325
306
|
}
|
|
326
307
|
async wrapHttpRequest(req, res) {
|
|
327
308
|
const newReq = res ? new serverless_http_parser_1.HTTPRequest(req, res) : req;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export * from './interface';
|
|
|
2
2
|
export { MidwayFaaSFramework as Framework } from './framework';
|
|
3
3
|
export { FaaSConfiguration as Configuration } from './configuration';
|
|
4
4
|
export { AbstractBootstrapStarter } from './starter';
|
|
5
|
+
export * from './decorator';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -22,4 +22,5 @@ var configuration_1 = require("./configuration");
|
|
|
22
22
|
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.FaaSConfiguration; } });
|
|
23
23
|
var starter_1 = require("./starter");
|
|
24
24
|
Object.defineProperty(exports, "AbstractBootstrapStarter", { enumerable: true, get: function () { return starter_1.AbstractBootstrapStarter; } });
|
|
25
|
+
__exportStar(require("./decorator"), exports);
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -13,10 +13,14 @@ export interface FaaSContext extends IMidwayContext<FaaSHTTPContext> {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare type FaaSMiddleware = ((context: Context, next: () => Promise<any>) => any) | string;
|
|
15
15
|
export interface HandlerOptions {
|
|
16
|
-
isHttpFunction
|
|
16
|
+
isHttpFunction?: boolean;
|
|
17
|
+
isChunked?: boolean;
|
|
17
18
|
}
|
|
18
19
|
export declare type IMidwayFaaSApplication = IMidwayApplication<Context, {
|
|
19
20
|
getInitializeContext(): any;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated use useMiddleware instead
|
|
23
|
+
*/
|
|
20
24
|
use(middleware: FaaSMiddleware): any;
|
|
21
25
|
/**
|
|
22
26
|
* @deprecated
|
|
@@ -36,7 +40,7 @@ export declare type IMidwayFaaSApplication = IMidwayApplication<Context, {
|
|
|
36
40
|
invokeTriggerFunction(context: any, handler: string, options: HandlerOptions): Promise<any>;
|
|
37
41
|
getServerlessInstance<T>(serviceClass: ObjectIdentifier | {
|
|
38
42
|
new (...args: any[]): T;
|
|
39
|
-
}, customContext?: any): Promise<T>;
|
|
43
|
+
}, customContext?: Record<string, any>): Promise<T>;
|
|
40
44
|
}> & ServerlessHttpApplication;
|
|
41
45
|
export interface Application extends IMidwayFaaSApplication {
|
|
42
46
|
}
|
|
@@ -77,4 +81,10 @@ export interface ServerlessStarterOptions extends IMidwayBootstrapOptions {
|
|
|
77
81
|
end(): any;
|
|
78
82
|
};
|
|
79
83
|
}
|
|
84
|
+
export interface HttpResponseFormat<T = unknown> {
|
|
85
|
+
isBase64Encoded: boolean;
|
|
86
|
+
statusCode: number;
|
|
87
|
+
headers: Record<string, string>;
|
|
88
|
+
body: T;
|
|
89
|
+
}
|
|
80
90
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/starter.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export declare abstract class AbstractBootstrapStarter {
|
|
|
9
9
|
close(): Promise<void>;
|
|
10
10
|
start(options?: ServerlessStarterOptions): any;
|
|
11
11
|
initFramework(bootstrapOptions?: IMidwayBootstrapOptions): Promise<void>;
|
|
12
|
+
protected createDefaultMockHttpEvent(): void;
|
|
13
|
+
protected createDefaultMockEvent(): void;
|
|
14
|
+
protected createDefaultMockContext(): void;
|
|
12
15
|
abstract onStart(): any;
|
|
13
16
|
abstract onInit(...args: unknown[]): any;
|
|
14
17
|
abstract onRequest(...args: unknown[]): any;
|
package/dist/starter.js
CHANGED
|
@@ -22,6 +22,9 @@ class AbstractBootstrapStarter {
|
|
|
22
22
|
const midwayFrameworkService = this.applicationContext.get(core_1.MidwayFrameworkService);
|
|
23
23
|
this.framework = midwayFrameworkService.getMainFramework();
|
|
24
24
|
}
|
|
25
|
+
createDefaultMockHttpEvent() { }
|
|
26
|
+
createDefaultMockEvent() { }
|
|
27
|
+
createDefaultMockContext() { }
|
|
25
28
|
}
|
|
26
29
|
exports.AbstractBootstrapStarter = AbstractBootstrapStarter;
|
|
27
30
|
//# sourceMappingURL=starter.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/faas",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.1-beta.1",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@midwayjs/core": "^3.
|
|
7
|
+
"@midwayjs/core": "^3.9.0",
|
|
8
8
|
"@midwayjs/faas-typings": "^3.6.0",
|
|
9
9
|
"@midwayjs/logger": "^2.15.0",
|
|
10
10
|
"@midwayjs/serverless-http-parser": "^3.6.0",
|
|
11
11
|
"@midwayjs/simple-lock": "^1.1.4"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@midwayjs/mock": "^3.
|
|
15
|
-
"@midwayjs/serverless-fc-starter": "^3.
|
|
14
|
+
"@midwayjs/mock": "^3.9.0",
|
|
15
|
+
"@midwayjs/serverless-fc-starter": "^3.9.0",
|
|
16
16
|
"@midwayjs/serverless-scf-starter": "^3.7.0",
|
|
17
17
|
"mm": "3.2.1"
|
|
18
18
|
},
|