@tsed/platform-serverless-http 8.0.1 → 8.0.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/package.json
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
"name": "@tsed/platform-serverless-http",
|
|
3
3
|
"description": "Module to support Serverless HTTP function with Ts.ED",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.0.
|
|
5
|
+
"version": "8.0.2",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
9
9
|
"typings": "./lib/types/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"@tsed/source": "./src/index.ts",
|
|
12
13
|
"types": "./lib/types/index.d.ts",
|
|
13
14
|
"import": "./lib/esm/index.js",
|
|
14
15
|
"default": "./lib/esm/index.js"
|
|
@@ -57,12 +58,12 @@
|
|
|
57
58
|
"tslib": "2.7.0"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@tsed/barrels": "8.0.
|
|
61
|
-
"@tsed/di": "8.0.
|
|
62
|
-
"@tsed/hooks": "8.0.
|
|
63
|
-
"@tsed/platform-http": "8.0.
|
|
64
|
-
"@tsed/platform-serverless-testing": "8.0.
|
|
65
|
-
"@tsed/typescript": "8.0.
|
|
61
|
+
"@tsed/barrels": "8.0.2",
|
|
62
|
+
"@tsed/di": "8.0.2",
|
|
63
|
+
"@tsed/hooks": "8.0.2",
|
|
64
|
+
"@tsed/platform-http": "8.0.2",
|
|
65
|
+
"@tsed/platform-serverless-testing": "8.0.2",
|
|
66
|
+
"@tsed/typescript": "8.0.2",
|
|
66
67
|
"@types/aws-lambda": "^8.10.145",
|
|
67
68
|
"eslint": "9.12.0",
|
|
68
69
|
"serverless-http": "^3.2.0",
|
|
@@ -70,13 +71,13 @@
|
|
|
70
71
|
"vitest": "2.1.2"
|
|
71
72
|
},
|
|
72
73
|
"peerDependencies": {
|
|
73
|
-
"@tsed/core": "8.0.
|
|
74
|
-
"@tsed/di": "8.0.
|
|
75
|
-
"@tsed/json-mapper": "8.0.
|
|
74
|
+
"@tsed/core": "8.0.2",
|
|
75
|
+
"@tsed/di": "8.0.2",
|
|
76
|
+
"@tsed/json-mapper": "8.0.2",
|
|
76
77
|
"@tsed/logger": ">=6.7.5",
|
|
77
|
-
"@tsed/openspec": "8.0.
|
|
78
|
-
"@tsed/platform-http": "8.0.
|
|
79
|
-
"@tsed/schema": "8.0.
|
|
78
|
+
"@tsed/openspec": "8.0.2",
|
|
79
|
+
"@tsed/platform-http": "8.0.2",
|
|
80
|
+
"@tsed/schema": "8.0.2",
|
|
80
81
|
"serverless-http": ">=2.0.0"
|
|
81
82
|
},
|
|
82
83
|
"peerDependenciesMeta": {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {PlatformExpress} from "@tsed/platform-express";
|
|
2
|
+
import {PlatformBuilder} from "@tsed/platform-http";
|
|
3
|
+
import serverless from "serverless-http";
|
|
4
|
+
|
|
5
|
+
import {PlatformServerlessHttp} from "./PlatformServerlessHttp.js";
|
|
6
|
+
|
|
7
|
+
vi.mock("serverless-http");
|
|
8
|
+
|
|
9
|
+
class Server {}
|
|
10
|
+
|
|
11
|
+
describe("PlatformServerlessHttp", () => {
|
|
12
|
+
beforeEach(() => {});
|
|
13
|
+
it("should create a new serverless http app", async () => {
|
|
14
|
+
const event = {};
|
|
15
|
+
const context = {};
|
|
16
|
+
const callback = vi.fn();
|
|
17
|
+
const platform = {
|
|
18
|
+
callback: vi.fn().mockReturnValue(callback),
|
|
19
|
+
listen: vi.fn().mockResolvedValue(undefined)
|
|
20
|
+
};
|
|
21
|
+
vi.spyOn(PlatformBuilder, "create").mockReturnValue(platform as any);
|
|
22
|
+
|
|
23
|
+
const handler = vi.fn();
|
|
24
|
+
|
|
25
|
+
(serverless as any).mockReturnValue(handler);
|
|
26
|
+
|
|
27
|
+
const instance = PlatformServerlessHttp.bootstrap(Server, {
|
|
28
|
+
adapter: PlatformExpress
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const h: any = instance.handler();
|
|
32
|
+
|
|
33
|
+
await h(event, context);
|
|
34
|
+
|
|
35
|
+
expect(serverless).toHaveBeenCalledWith(callback, {
|
|
36
|
+
request: expect.any(Function)
|
|
37
|
+
});
|
|
38
|
+
expect(handler).toHaveBeenCalledWith(event, context);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {Type} from "@tsed/core";
|
|
2
|
+
import {PlatformBuilder, PlatformBuilderSettings} from "@tsed/platform-http";
|
|
3
|
+
import type {Handler} from "aws-lambda";
|
|
4
|
+
import serverless from "serverless-http";
|
|
5
|
+
|
|
6
|
+
export class PlatformServerlessHttp {
|
|
7
|
+
static bootstrap(module: Type<any>, settings: PlatformBuilderSettings<any>): PlatformBuilder & {handler(): Handler} {
|
|
8
|
+
const platform = PlatformBuilder.create(module, settings);
|
|
9
|
+
const promise = platform.listen();
|
|
10
|
+
|
|
11
|
+
(platform as any).handler = (): Handler => {
|
|
12
|
+
let handler: any;
|
|
13
|
+
|
|
14
|
+
return async (event, context) => {
|
|
15
|
+
// istanbul ignore else
|
|
16
|
+
if (!handler) {
|
|
17
|
+
await promise;
|
|
18
|
+
handler = serverless(platform.callback(), {
|
|
19
|
+
request(request: any) {
|
|
20
|
+
request.serverless = {event, context};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return handler(event, context);
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return platform as any;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Req} from "@tsed/platform-http";
|
|
2
|
+
import type {Context} from "aws-lambda";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return the Serverless context
|
|
6
|
+
* @decorator
|
|
7
|
+
*/
|
|
8
|
+
export function ServerlessContext(): ParameterDecorator {
|
|
9
|
+
return Req("serverless.context");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type ServerlessContext = Context;
|