@midwayjs/faas 3.9.0 → 3.9.1-beta.2
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 +57 -73
- 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 +2 -2
- package/LICENSE +0 -21
|
@@ -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,69 @@ 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.isCustomHttpResponse) {
|
|
247
|
+
return context.body;
|
|
277
248
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (typeof data === 'string') {
|
|
281
|
-
if (!context.type) {
|
|
282
|
-
context.type = 'text/plain';
|
|
283
|
-
}
|
|
284
|
-
context.body = data;
|
|
249
|
+
else {
|
|
250
|
+
return this.formatHttpResponse(context);
|
|
285
251
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
formatHttpResponse(context) {
|
|
258
|
+
var _a;
|
|
259
|
+
if (!((_a = context.response) === null || _a === void 0 ? void 0 : _a._explicitStatus)) {
|
|
260
|
+
if (context.body === null || context.body === 'undefined') {
|
|
261
|
+
context.body = '';
|
|
262
|
+
context.type = 'text';
|
|
263
|
+
context.status = 204;
|
|
293
264
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
context.
|
|
265
|
+
}
|
|
266
|
+
let encoded = false;
|
|
267
|
+
const data = context.body;
|
|
268
|
+
if (typeof data === 'string') {
|
|
269
|
+
if (!context.type) {
|
|
270
|
+
context.type = 'text/plain';
|
|
300
271
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
context.
|
|
272
|
+
context.body = data;
|
|
273
|
+
}
|
|
274
|
+
else if (isAnyArrayBuffer(data) || isUint8Array(data)) {
|
|
275
|
+
encoded = true;
|
|
276
|
+
if (!context.type) {
|
|
277
|
+
context.type = 'application/octet-stream';
|
|
307
278
|
}
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
context.
|
|
279
|
+
// data is reserved as buffer
|
|
280
|
+
context.body = Buffer.from(data).toString('base64');
|
|
281
|
+
}
|
|
282
|
+
else if (typeof data === 'object') {
|
|
283
|
+
if (!context.type) {
|
|
284
|
+
context.type = 'application/json';
|
|
314
285
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
statusCode: context.status,
|
|
318
|
-
headers: context.res.headers,
|
|
319
|
-
body: context.body,
|
|
320
|
-
};
|
|
286
|
+
// set data to string
|
|
287
|
+
context.body = JSON.stringify(data);
|
|
321
288
|
}
|
|
322
289
|
else {
|
|
323
|
-
|
|
290
|
+
if (!context.type) {
|
|
291
|
+
context.type = 'text/plain';
|
|
292
|
+
}
|
|
293
|
+
// set data to string
|
|
294
|
+
context.body = data + '';
|
|
295
|
+
}
|
|
296
|
+
// middleware return value and will be got 204 status
|
|
297
|
+
if (context.body === undefined &&
|
|
298
|
+
!context.response._explicitStatus &&
|
|
299
|
+
context._matchedRoute) {
|
|
300
|
+
// 如果进了路由,重新赋值,防止 404
|
|
301
|
+
context.body = undefined;
|
|
324
302
|
}
|
|
303
|
+
return {
|
|
304
|
+
isBase64Encoded: encoded,
|
|
305
|
+
statusCode: context.status,
|
|
306
|
+
headers: context.res.headers,
|
|
307
|
+
body: context.body,
|
|
308
|
+
};
|
|
325
309
|
}
|
|
326
310
|
async wrapHttpRequest(req, res) {
|
|
327
311
|
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
|
+
isCustomHttpResponse?: 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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/faas",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.1-beta.2",
|
|
4
4
|
"main": "dist/index",
|
|
5
5
|
"typings": "index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"url": "git@github.com:midwayjs/midway.git"
|
|
46
46
|
},
|
|
47
47
|
"license": "MIT",
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "a603d2348d6141f8f723901498f03a162a037708"
|
|
49
49
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|