@tsed/platform-serverless 6.89.0 → 6.92.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/jest.config.js +2 -2
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/package.json +9 -8
- package/readme.md +184 -20
- package/lib/cjs/services/PlatformServerlessTest.d.ts +0 -46
- package/lib/cjs/services/PlatformServerlessTest.js +0 -196
- package/lib/cjs/services/PlatformServerlessTest.js.map +0 -1
- package/lib/esm/services/PlatformServerlessTest.js +0 -191
- package/lib/esm/services/PlatformServerlessTest.js.map +0 -1
- package/lib/types/services/PlatformServerlessTest.d.ts +0 -46
package/jest.config.js
CHANGED
package/lib/cjs/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda } from "@
|
|
|
3
3
|
export * from "@tsed/platform-params";
|
|
4
4
|
export * from "./builder/PlatformServerlessHandler";
|
|
5
5
|
export * from "./builder/PlatformServerless";
|
|
6
|
-
export * from "./services/PlatformServerlessTest";
|
|
7
6
|
export * from "./domain/ServerlessContext";
|
|
8
7
|
export * from "./domain/ServerlessResponse";
|
|
9
8
|
export * from "./domain/ServerlessResponse";
|
package/lib/cjs/index.js
CHANGED
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "Lambda", { enumerable: true, get: function () {
|
|
|
15
15
|
(0, tslib_1.__exportStar)(require("@tsed/platform-params"), exports);
|
|
16
16
|
(0, tslib_1.__exportStar)(require("./builder/PlatformServerlessHandler"), exports);
|
|
17
17
|
(0, tslib_1.__exportStar)(require("./builder/PlatformServerless"), exports);
|
|
18
|
-
(0, tslib_1.__exportStar)(require("./services/PlatformServerlessTest"), exports);
|
|
19
18
|
// decorators
|
|
20
19
|
(0, tslib_1.__exportStar)(require("./domain/ServerlessContext"), exports);
|
|
21
20
|
(0, tslib_1.__exportStar)(require("./domain/ServerlessResponse"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAAyB;AACzB,uCAA2F;AAAnF,6FAAA,GAAG,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,6FAAA,GAAG,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,gGAAA,KAAK,OAAU;AACrE,qEAAsC;AAEtC,mFAAoD;AACpD,4EAA6C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAAyB;AACzB,uCAA2F;AAAnF,6FAAA,GAAG,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,6FAAA,GAAG,OAAA;AAAE,gGAAA,MAAM,OAAA;AAAE,8FAAA,IAAI,OAAA;AAAE,+FAAA,KAAK,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,gGAAA,KAAK,OAAU;AACrE,qEAAsC;AAEtC,mFAAoD;AACpD,4EAA6C;AAE7C,aAAa;AACb,0EAA2C;AAC3C,2EAA4C;AAC5C,2EAA4C","sourcesContent":["export * from \"@tsed/di\";\nexport {Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda} from \"@tsed/schema\";\nexport * from \"@tsed/platform-params\";\n\nexport * from \"./builder/PlatformServerlessHandler\";\nexport * from \"./builder/PlatformServerless\";\n\n// decorators\nexport * from \"./domain/ServerlessContext\";\nexport * from \"./domain/ServerlessResponse\";\nexport * from \"./domain/ServerlessResponse\";\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -3,7 +3,6 @@ export { Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda } from "@
|
|
|
3
3
|
export * from "@tsed/platform-params";
|
|
4
4
|
export * from "./builder/PlatformServerlessHandler";
|
|
5
5
|
export * from "./builder/PlatformServerless";
|
|
6
|
-
export * from "./services/PlatformServerlessTest";
|
|
7
6
|
// decorators
|
|
8
7
|
export * from "./domain/ServerlessContext";
|
|
9
8
|
export * from "./domain/ServerlessResponse";
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,MAAM,EAAC,MAAM,cAAc,CAAC;AAC3F,cAAc,uBAAuB,CAAC;AAEtC,cAAc,qCAAqC,CAAC;AACpD,cAAc,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,OAAO,EAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,MAAM,EAAC,MAAM,cAAc,CAAC;AAC3F,cAAc,uBAAuB,CAAC;AAEtC,cAAc,qCAAqC,CAAC;AACpD,cAAc,8BAA8B,CAAC;AAE7C,aAAa;AACb,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC","sourcesContent":["export * from \"@tsed/di\";\nexport {Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda} from \"@tsed/schema\";\nexport * from \"@tsed/platform-params\";\n\nexport * from \"./builder/PlatformServerlessHandler\";\nexport * from \"./builder/PlatformServerless\";\n\n// decorators\nexport * from \"./domain/ServerlessContext\";\nexport * from \"./domain/ServerlessResponse\";\nexport * from \"./domain/ServerlessResponse\";\n"]}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { Get, Post, Put, Delete, Head, Patch, Options, Route as Lambda } from "@
|
|
|
3
3
|
export * from "@tsed/platform-params";
|
|
4
4
|
export * from "./builder/PlatformServerlessHandler";
|
|
5
5
|
export * from "./builder/PlatformServerless";
|
|
6
|
-
export * from "./services/PlatformServerlessTest";
|
|
7
6
|
export * from "./domain/ServerlessContext";
|
|
8
7
|
export * from "./domain/ServerlessResponse";
|
|
9
8
|
export * from "./domain/ServerlessResponse";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-serverless",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.92.1",
|
|
4
4
|
"description": "Platform serverless module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -19,20 +19,21 @@
|
|
|
19
19
|
"test": "cross-env NODE_ENV=test jest"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@tsed/core": "6.
|
|
23
|
-
"@tsed/di": "6.
|
|
24
|
-
"@tsed/exceptions": "6.
|
|
25
|
-
"@tsed/json-mapper": "6.
|
|
22
|
+
"@tsed/core": "6.92.1",
|
|
23
|
+
"@tsed/di": "6.92.1",
|
|
24
|
+
"@tsed/exceptions": "6.92.1",
|
|
25
|
+
"@tsed/json-mapper": "6.92.1",
|
|
26
26
|
"@tsed/logger": "^6.0.0",
|
|
27
|
-
"@tsed/platform-exceptions": "6.
|
|
28
|
-
"@tsed/platform-params": "6.
|
|
29
|
-
"@tsed/schema": "6.
|
|
27
|
+
"@tsed/platform-exceptions": "6.92.1",
|
|
28
|
+
"@tsed/platform-params": "6.92.1",
|
|
29
|
+
"@tsed/schema": "6.92.1",
|
|
30
30
|
"encodeurl": "^1.0.2",
|
|
31
31
|
"mime": "^2.5.2",
|
|
32
32
|
"tslib": "2.2.0",
|
|
33
33
|
"uuid": "^8.3.2"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@tsed/platform-serverless-testing": "6.92.1",
|
|
36
37
|
"@types/aws-lambda": "^8.10.83",
|
|
37
38
|
"@types/encodeurl": "^1.0.0",
|
|
38
39
|
"@types/mime": "^2.0.3"
|
package/readme.md
CHANGED
|
@@ -36,16 +36,94 @@ This package allows the creation of pure Lambda AWS without mounting an Express.
|
|
|
36
36
|
It supports:
|
|
37
37
|
|
|
38
38
|
- Creating multiple lambda in one file,
|
|
39
|
+
- Support routing,
|
|
39
40
|
- DI injection with `@tsed/di`,
|
|
40
41
|
- Models mapping using `@tsed/schema` and `@tsed/json-mapper`,
|
|
41
42
|
- Params decorators can be used from `@tsed/platform-params` to get Query, Body, etc...
|
|
43
|
+
- Response can be modified by using `@tsed/platform-response-filter`,
|
|
44
|
+
- All error can be handled by using `@tsed/platform-exceptions`,
|
|
42
45
|
- Operation descriptions like `@Returns`,
|
|
43
46
|
- `@tsed/async-hook-context` to inject Context anywhere in your class!
|
|
47
|
+
- All ORM already available for other Ts.ED platform.
|
|
48
|
+
|
|
49
|
+
## Unsupported features
|
|
50
|
+
|
|
51
|
+
Some features that you can use with the Express.js or Koa.js platforms are not available with the Serverless
|
|
52
|
+
platform.
|
|
53
|
+
|
|
54
|
+
(See also our [table feature capabilities](https://tsed.io/getting-started/#platform-features-support)).
|
|
55
|
+
|
|
56
|
+
### Middlewares
|
|
57
|
+
|
|
58
|
+
This mechanism is specific to Koa.js / Express.js and doesn't exist with the Serverless approach.
|
|
59
|
+
|
|
60
|
+
Serverless provides a number of features such as Cors management via the configuration of `serverless.yml` and doesn't
|
|
61
|
+
need to use middleware. In addition, serverless [plugins](https://www.serverless.com/plugins/) are also available and
|
|
62
|
+
allow you to manage advanced scenarios without having to develop anything!
|
|
63
|
+
|
|
64
|
+
If you can't find what you are looking for on the Serverless side, you can use `@tsed/di`'
|
|
65
|
+
s [Interceptors](/docs/interceptors.md) to decorate the methods and add shareable features.
|
|
66
|
+
|
|
67
|
+
### Passport/OIDC/GraphQL etc...
|
|
68
|
+
|
|
69
|
+
Because middlewares aren't supported Passport.js, OIDC, GraphQL won't be usable in this platform either.
|
|
70
|
+
|
|
71
|
+
### Upload files
|
|
72
|
+
|
|
73
|
+
File upload isn't covered at this time. Any help is welcome to improve this platform :).
|
|
74
|
+
|
|
75
|
+
### Statics files
|
|
76
|
+
|
|
77
|
+
The goal of lambda isn't to expose static files. We do not plan to support this use in the near future.
|
|
78
|
+
|
|
79
|
+
## Rule
|
|
80
|
+
|
|
81
|
+
::: warning By convention, try to not import something from `@tsed/common`. `@tsed/common` embed a lot of codes designed
|
|
82
|
+
for the Full server platform which are not necessary in the Serverless context and aren't optimized for it.
|
|
83
|
+
|
|
84
|
+
The recent version of Ts.ED expose all necessary decorators from `@tsed/schema`, `@tsed/platform-params` or `@tsed/di`.
|
|
85
|
+
For example, @@Get@@ or @@Post@@ are commonly imported like this:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import {Get} from "@tsed/common";
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Now, you have to import the decorator from `@tsed/schema`.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import {Get} from "@tsed/schema";
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
:::
|
|
44
98
|
|
|
45
99
|
## Installation
|
|
46
100
|
|
|
101
|
+
Generate a new project with the CLI (you can also start from an existing project):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
tsed init .
|
|
105
|
+
? Choose the target platform: Express.js
|
|
106
|
+
? Choose the architecture for your project: Ts.ED
|
|
107
|
+
? Choose the convention file styling: Ts.ED
|
|
108
|
+
? Check the features needed for your project Swagger, Testing, Linter
|
|
109
|
+
? Choose unit framework Jest
|
|
110
|
+
? Choose linter tools framework EsLint
|
|
111
|
+
? Choose extra linter tools Prettier, Lint on commit
|
|
112
|
+
? Choose the package manager: Yarn
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This tutorial works also with NPM package manager!
|
|
116
|
+
|
|
117
|
+
Yarn:
|
|
47
118
|
```bash
|
|
48
|
-
|
|
119
|
+
yarn add @tsed/platform-serverless serverless serverless-offline
|
|
120
|
+
yarn add -D @types/aws-lambda
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Npm:
|
|
124
|
+
```bash
|
|
125
|
+
npm install --save @tsed/platform-serverless serverless serverless-offline
|
|
126
|
+
npm install --save-dev @types/aws-lambda
|
|
49
127
|
```
|
|
50
128
|
|
|
51
129
|
## Configuration
|
|
@@ -79,7 +157,7 @@ export class TimeslotsLambda {
|
|
|
79
157
|
Create new `handler.ts` to expose your lambda:
|
|
80
158
|
|
|
81
159
|
```typescript
|
|
82
|
-
import {PlatformServerless} from "@tsed/serverless";
|
|
160
|
+
import {PlatformServerless} from "@tsed/platform-serverless";
|
|
83
161
|
import {TimeslotsLambda} from "./lambda/TimeslotsLambda";
|
|
84
162
|
|
|
85
163
|
const platform = PlatformServerless.bootstrap({
|
|
@@ -119,18 +197,19 @@ functions:
|
|
|
119
197
|
|
|
120
198
|
## Invoke a lambda with serverless
|
|
121
199
|
|
|
122
|
-
Serverless provide a plugin named `serverless-offline`. This Serverless plugin emulates AWS λ and API Gateway on your
|
|
123
|
-
To do so, it starts an HTTP server that handles the request's
|
|
200
|
+
Serverless provide a plugin named `serverless-offline`. This Serverless plugin emulates AWS λ and API Gateway on your
|
|
201
|
+
local machine to speed up your development cycles. To do so, it starts an HTTP server that handles the request's
|
|
202
|
+
lifecycle like API does and invokes your handlers.
|
|
124
203
|
|
|
125
|
-
So, by using the `serverless offline` command, we'll be able to invoke our function. For that, we need also to build our
|
|
204
|
+
So, by using the `serverless offline` command, we'll be able to invoke our function. For that, we need also to build our
|
|
205
|
+
code before invoke the lambda.
|
|
126
206
|
|
|
127
207
|
To simplify our workflow, we can add the following npm script command in our `package.json`:
|
|
128
208
|
|
|
129
209
|
```json
|
|
130
210
|
{
|
|
131
211
|
"scripts": {
|
|
132
|
-
"invoke:timeslots": "yarn build && serverless invoke local -f timeslots"
|
|
133
|
-
"invoke:any": "yarn serverless invoke local -f any --data '{\"path\":\"/timeslots\", \"httpMethod\": \"GET\"}'"
|
|
212
|
+
"invoke:timeslots": "yarn build && serverless invoke local -f timeslots"
|
|
134
213
|
}
|
|
135
214
|
}
|
|
136
215
|
```
|
|
@@ -147,20 +226,20 @@ You should see in the terminal the following result:
|
|
|
147
226
|
|
|
148
227
|
```json
|
|
149
228
|
{
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
229
|
+
"statusCode": 200,
|
|
230
|
+
"body": "[{\"id\":\"b6de4fc7-faaa-4cd7-a144-42f6af0dec6b\",\"title\":\"title\",\"description\":\"description\",\"start_date\":\"2021-10-29T10:40:57.019Z\",\"end_date\":\"2021-10-29T10:40:57.019Z\",\"created_at\":\"2021-10-29T10:40:57.019Z\",\"update_at\":\"2021-10-29T10:40:57.019Z\"}]",
|
|
231
|
+
"headers": {
|
|
232
|
+
"content-type": "application/json",
|
|
233
|
+
"x-request-id": "ebb52d5e-113b-40da-b34e-c14811df596b"
|
|
234
|
+
},
|
|
235
|
+
"isBase64Encoded": false
|
|
157
236
|
}
|
|
158
237
|
```
|
|
159
238
|
|
|
160
239
|
## Manage routes from code
|
|
161
240
|
|
|
162
|
-
Declaring all routes in the `serverless.yml` file can be a source of error. `@tsed/platform-serverless` can
|
|
163
|
-
|
|
241
|
+
Declaring all routes in the `serverless.yml` file can be a source of error. `@tsed/platform-serverless` can handle all
|
|
242
|
+
routes and call the right lambda based on the decorators like `@Get`, `@Post`, etc...
|
|
164
243
|
|
|
165
244
|
To use the embed router, change the `serverless.yml` declaration by this example:
|
|
166
245
|
|
|
@@ -170,12 +249,12 @@ service: timeslots
|
|
|
170
249
|
frameworkVersion: '2'
|
|
171
250
|
|
|
172
251
|
provider:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
252
|
+
name: aws
|
|
253
|
+
runtime: nodejs14.x
|
|
254
|
+
lambdaHashingVersion: '20201221'
|
|
176
255
|
|
|
177
256
|
plugins:
|
|
178
|
-
|
|
257
|
+
- serverless-offline
|
|
179
258
|
|
|
180
259
|
functions:
|
|
181
260
|
any:
|
|
@@ -237,6 +316,91 @@ export class TimeslotsLambda {
|
|
|
237
316
|
}
|
|
238
317
|
```
|
|
239
318
|
|
|
319
|
+
## Testing
|
|
320
|
+
|
|
321
|
+
Ts.ED provide a way to test you lambda with mocked Aws event and context by using the `PlatformServerlessTest` util.
|
|
322
|
+
|
|
323
|
+
Here an example to test a Lambda controller:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import {PlatformServerlessTest} from "@tsed/platform-serverless-testing";
|
|
327
|
+
import {PlatformServerless} from "@tsed/platform-serverless";
|
|
328
|
+
|
|
329
|
+
@Controller("/")
|
|
330
|
+
class TimeslotsLambdaController {
|
|
331
|
+
@Get("/")
|
|
332
|
+
getAll() {
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
@Get("/:id")
|
|
337
|
+
getById(@PathParams("id") id: string, @QueryParams("start_date") startDate: Date, @QueryParams("end_date") endDate: Date) {
|
|
338
|
+
return {
|
|
339
|
+
id,
|
|
340
|
+
startDate,
|
|
341
|
+
endDate
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
describe("TimeslotsLambdaController", () => {
|
|
347
|
+
beforeEach(
|
|
348
|
+
PlatformServerlessTest.bootstrap(PlatformServerless, {
|
|
349
|
+
lambda: [TimeslotsLambdaController]
|
|
350
|
+
})
|
|
351
|
+
);
|
|
352
|
+
afterEach(() => PlatformServerlessTest.reset());
|
|
353
|
+
|
|
354
|
+
describe("Invoke by lambda name", () => {
|
|
355
|
+
it("should call getAll Lambda", async () => {
|
|
356
|
+
const response = await PlatformServerlessTest.request.call("getAll");
|
|
357
|
+
|
|
358
|
+
expect(response.statusCode).toEqual(200);
|
|
359
|
+
expect(response.headers).toEqual({
|
|
360
|
+
"x-request-id": "requestId",
|
|
361
|
+
"content-type": "application/json"
|
|
362
|
+
});
|
|
363
|
+
expect(JSON.parse(response.body)).toEqual([]);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("should call getAll Lambda", async () => {
|
|
367
|
+
const response = await PlatformServerlessTest.request.call("getById")
|
|
368
|
+
.params({
|
|
369
|
+
id: "1"
|
|
370
|
+
})
|
|
371
|
+
.query({
|
|
372
|
+
start_date: new Date("2020-01-01"),
|
|
373
|
+
end_date: new Date("2020-01-10")
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
expect(response.statusCode).toEqual(200);
|
|
377
|
+
expect(response.headers).toEqual({
|
|
378
|
+
"x-request-id": "requestId",
|
|
379
|
+
"content-type": "application/json"
|
|
380
|
+
});
|
|
381
|
+
expect(JSON.parse(response.body)).toEqual({
|
|
382
|
+
id: "1",
|
|
383
|
+
endDate: "2020-01-10T00:00:00.000Z",
|
|
384
|
+
startDate: "2020-01-01T00:00:00.000Z"
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
describe("invoke using the router", () => {
|
|
390
|
+
it("should call getAll Lambda", async () => {
|
|
391
|
+
const response = await PlatformServerlessTest.request.get("/");
|
|
392
|
+
|
|
393
|
+
expect(response.statusCode).toEqual(200);
|
|
394
|
+
expect(response.headers).toEqual({
|
|
395
|
+
"x-request-id": "requestId",
|
|
396
|
+
"content-type": "application/json"
|
|
397
|
+
});
|
|
398
|
+
expect(JSON.parse(response.body)).toEqual([]);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
```
|
|
403
|
+
|
|
240
404
|
## Contributors
|
|
241
405
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
242
406
|
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Type } from "@tsed/core";
|
|
2
|
-
import { DITest } from "@tsed/di";
|
|
3
|
-
import { JsonEntityStore } from "@tsed/schema";
|
|
4
|
-
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler, Context } from "aws-lambda";
|
|
5
|
-
import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
|
|
6
|
-
import { PlatformServerless } from "../builder/PlatformServerless";
|
|
7
|
-
import { ServerlessContext } from "../domain/ServerlessContext";
|
|
8
|
-
export interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {
|
|
9
|
-
}
|
|
10
|
-
export declare class LambdaClientRequest extends Promise<APIGatewayProxyResult> {
|
|
11
|
-
event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
12
|
-
context: Context;
|
|
13
|
-
static call(lambdaName: string): LambdaClientRequest;
|
|
14
|
-
static get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
15
|
-
static post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
16
|
-
static put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
17
|
-
static patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
18
|
-
static delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
19
|
-
static createFakeEvent(event?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
20
|
-
static createFakeContext(context?: Context): Context;
|
|
21
|
-
get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
22
|
-
post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
23
|
-
patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
24
|
-
put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
25
|
-
delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
26
|
-
query(query: any): this;
|
|
27
|
-
params(pathParameters: any): this;
|
|
28
|
-
headers(headers: Record<string, any>): this;
|
|
29
|
-
body(body: any): this;
|
|
30
|
-
protected init(lambda: string, resolve: Function, reject: Function): void;
|
|
31
|
-
}
|
|
32
|
-
export declare class PlatformServerlessTest extends DITest {
|
|
33
|
-
static callbacks: Record<string, APIGatewayProxyHandler>;
|
|
34
|
-
static instance: PlatformServerless;
|
|
35
|
-
static request: typeof LambdaClientRequest;
|
|
36
|
-
static bootstrap(settings?: Partial<TsED.Configuration & {
|
|
37
|
-
lambda: Type[];
|
|
38
|
-
}>): () => Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
41
|
-
*/
|
|
42
|
-
static reset(): Promise<void>;
|
|
43
|
-
static createServerlessContext({ endpoint }: {
|
|
44
|
-
endpoint: JsonEntityStore;
|
|
45
|
-
}): ServerlessContext;
|
|
46
|
-
}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PlatformServerlessTest = exports.LambdaClientRequest = void 0;
|
|
4
|
-
const di_1 = require("@tsed/di");
|
|
5
|
-
const PlatformServerless_1 = require("../builder/PlatformServerless");
|
|
6
|
-
const ServerlessContext_1 = require("../domain/ServerlessContext");
|
|
7
|
-
class LambdaClientRequest extends Promise {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(...arguments);
|
|
10
|
-
this.event = LambdaClientRequest.createFakeEvent();
|
|
11
|
-
this.context = LambdaClientRequest.createFakeContext();
|
|
12
|
-
}
|
|
13
|
-
static call(lambdaName) {
|
|
14
|
-
const resolvers = {};
|
|
15
|
-
const promise = new LambdaClientRequest((resolve, reject) => {
|
|
16
|
-
resolvers.resolve = resolve;
|
|
17
|
-
resolvers.reject = reject;
|
|
18
|
-
});
|
|
19
|
-
promise.init(lambdaName, resolvers.resolve, resolvers.reject);
|
|
20
|
-
return promise;
|
|
21
|
-
}
|
|
22
|
-
static get(path, options = {}) {
|
|
23
|
-
return this.call("handler").get(path, options);
|
|
24
|
-
}
|
|
25
|
-
static post(path, body, options = {}) {
|
|
26
|
-
return this.call("handler").post(path, body, options);
|
|
27
|
-
}
|
|
28
|
-
static put(path, body, options = {}) {
|
|
29
|
-
return this.call("handler").put(path, body, options);
|
|
30
|
-
}
|
|
31
|
-
static patch(path, body, options = {}) {
|
|
32
|
-
return this.call("handler").patch(path, body, options);
|
|
33
|
-
}
|
|
34
|
-
static delete(path, body, options = {}) {
|
|
35
|
-
return this.call("handler").delete(path, body, options);
|
|
36
|
-
}
|
|
37
|
-
static createFakeEvent(event = {}) {
|
|
38
|
-
return {
|
|
39
|
-
body: "",
|
|
40
|
-
headers: {},
|
|
41
|
-
httpMethod: "",
|
|
42
|
-
isBase64Encoded: false,
|
|
43
|
-
multiValueHeaders: {},
|
|
44
|
-
multiValueQueryStringParameters: {},
|
|
45
|
-
path: event.path || "/",
|
|
46
|
-
pathParameters: {},
|
|
47
|
-
queryStringParameters: {},
|
|
48
|
-
resource: "",
|
|
49
|
-
stageVariables: {},
|
|
50
|
-
...event,
|
|
51
|
-
requestContext: {
|
|
52
|
-
...event === null || event === void 0 ? void 0 : event.requestContext,
|
|
53
|
-
accountId: "",
|
|
54
|
-
apiId: "",
|
|
55
|
-
protocol: "https",
|
|
56
|
-
httpMethod: "",
|
|
57
|
-
identity: {},
|
|
58
|
-
path: event.path || "/",
|
|
59
|
-
stage: "",
|
|
60
|
-
requestId: "requestId",
|
|
61
|
-
requestTimeEpoch: 0,
|
|
62
|
-
resourceId: 1,
|
|
63
|
-
resourcePath: event.path || "/"
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
static createFakeContext(context) {
|
|
68
|
-
return {
|
|
69
|
-
awsRequestId: "awsRequestId",
|
|
70
|
-
callbackWaitsForEmptyEventLoop: false,
|
|
71
|
-
functionName: "",
|
|
72
|
-
functionVersion: "",
|
|
73
|
-
invokedFunctionArn: "",
|
|
74
|
-
logGroupName: "",
|
|
75
|
-
logStreamName: "",
|
|
76
|
-
memoryLimitInMB: "",
|
|
77
|
-
...(context || {})
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
get(path, options = {}) {
|
|
81
|
-
Object.assign(this.event, options);
|
|
82
|
-
this.event.path = path;
|
|
83
|
-
this.event.httpMethod = "GET";
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
post(path, body = {}, options = {}) {
|
|
87
|
-
Object.assign(this.event, options);
|
|
88
|
-
this.event.path = path;
|
|
89
|
-
this.event.httpMethod = "POST";
|
|
90
|
-
this.body(body);
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
patch(path, body = {}, options = {}) {
|
|
94
|
-
Object.assign(this.event, options);
|
|
95
|
-
this.event.path = path;
|
|
96
|
-
this.event.httpMethod = "PATCH";
|
|
97
|
-
this.body(body);
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
put(path, body = {}, options = {}) {
|
|
101
|
-
Object.assign(this.event, options);
|
|
102
|
-
this.event.path = path;
|
|
103
|
-
this.event.httpMethod = "PUT";
|
|
104
|
-
this.body(body);
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
delete(path, body = {}, options = {}) {
|
|
108
|
-
Object.assign(this.event, options);
|
|
109
|
-
this.event.path = path;
|
|
110
|
-
this.event.httpMethod = "DELETE";
|
|
111
|
-
this.body(body);
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
query(query) {
|
|
115
|
-
this.event.queryStringParameters = {
|
|
116
|
-
...this.event.queryStringParameters,
|
|
117
|
-
...JSON.parse(JSON.stringify(query))
|
|
118
|
-
};
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
params(pathParameters) {
|
|
122
|
-
this.event.pathParameters = {
|
|
123
|
-
...this.event.pathParameters,
|
|
124
|
-
...JSON.parse(JSON.stringify(pathParameters))
|
|
125
|
-
};
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
headers(headers) {
|
|
129
|
-
this.event.headers = {
|
|
130
|
-
...this.event.headers,
|
|
131
|
-
...JSON.parse(JSON.stringify(headers))
|
|
132
|
-
};
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
body(body) {
|
|
136
|
-
if (body !== undefined) {
|
|
137
|
-
this.event.headers["content-type"] = "application/json";
|
|
138
|
-
this.event.body = JSON.stringify(body);
|
|
139
|
-
}
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
init(lambda, resolve, reject) {
|
|
143
|
-
setTimeout(async () => {
|
|
144
|
-
try {
|
|
145
|
-
const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve);
|
|
146
|
-
resolve(result);
|
|
147
|
-
}
|
|
148
|
-
catch (er) {
|
|
149
|
-
reject(er);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.LambdaClientRequest = LambdaClientRequest;
|
|
155
|
-
class PlatformServerlessTest extends di_1.DITest {
|
|
156
|
-
static bootstrap(settings = {}) {
|
|
157
|
-
return async function before() {
|
|
158
|
-
// @ts-ignore
|
|
159
|
-
const instance = PlatformServerless_1.PlatformServerless.bootstrap(di_1.DITest.configure(settings));
|
|
160
|
-
PlatformServerlessTest.instance = instance;
|
|
161
|
-
PlatformServerlessTest.callbacks = instance.callbacks();
|
|
162
|
-
PlatformServerlessTest.callbacks.handler = instance.handler();
|
|
163
|
-
// used by inject method
|
|
164
|
-
di_1.DITest.injector = instance.injector;
|
|
165
|
-
return instance.promise;
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
170
|
-
*/
|
|
171
|
-
static async reset() {
|
|
172
|
-
if (PlatformServerlessTest.instance) {
|
|
173
|
-
await PlatformServerlessTest.instance.stop();
|
|
174
|
-
}
|
|
175
|
-
if (di_1.DITest.hasInjector()) {
|
|
176
|
-
await di_1.DITest.injector.destroy();
|
|
177
|
-
di_1.DITest._injector = null;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
static createServerlessContext({ endpoint }) {
|
|
181
|
-
const context = LambdaClientRequest.createFakeContext();
|
|
182
|
-
const event = LambdaClientRequest.createFakeEvent();
|
|
183
|
-
return new ServerlessContext_1.ServerlessContext({
|
|
184
|
-
event,
|
|
185
|
-
context,
|
|
186
|
-
id: context.awsRequestId,
|
|
187
|
-
logger: PlatformServerlessTest.injector.logger,
|
|
188
|
-
injector: PlatformServerlessTest.injector,
|
|
189
|
-
endpoint
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
exports.PlatformServerlessTest = PlatformServerlessTest;
|
|
194
|
-
PlatformServerlessTest.callbacks = {};
|
|
195
|
-
PlatformServerlessTest.request = LambdaClientRequest;
|
|
196
|
-
//# sourceMappingURL=PlatformServerlessTest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformServerlessTest.js","sourceRoot":"","sources":["../../../src/services/PlatformServerlessTest.ts"],"names":[],"mappings":";;;AACA,iCAAgC;AAKhC,sEAAiE;AACjE,mEAA8D;AAI9D,MAAa,mBAAoB,SAAQ,OAA8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AQ,CAAC,IAAI,EAAE,CAAC;SAC9C;QACD,IAAI,WAAM,CAAC,WAAW,EAAE,EAAE;YACxB,MAAM,WAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,WAAM,CAAC,SAAS,GAAG,IAAI,CAAC;SACzB;IACH,CAAC;IAED,MAAM,CAAC,uBAAuB,CAAC,EAAC,QAAQ,EAA8B;QACpE,MAAM,OAAO,GAAQ,mBAAmB,CAAC,iBAAiB,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAQ,mBAAmB,CAAC,eAAe,EAAE,CAAC;QAEzD,OAAO,IAAI,qCAAiB,CAAC;YAC3B,KAAK;YACL,OAAO;YACP,EAAE,EAAE,OAAO,CAAC,YAAY;YACxB,MAAM,EAAE,sBAAsB,CAAC,QAAQ,CAAC,MAAgB;YACxD,QAAQ,EAAE,sBAAsB,CAAC,QAAQ;YACzC,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;;AA5CH,wDA6CC;AA5CQ,gCAAS,GAA2C,EAAE,CAAC;AAEvD,8BAAO,GAAG,mBAAmB,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {DITest} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler, Context} from \"aws-lambda\";\nimport {APIGatewayProxyResult} from \"aws-lambda/trigger/api-gateway-proxy\";\nimport {PlatformServerless} from \"../builder/PlatformServerless\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\n\nexport interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {}\n\nexport class LambdaClientRequest extends Promise<APIGatewayProxyResult> {\n event = LambdaClientRequest.createFakeEvent();\n context = LambdaClientRequest.createFakeContext();\n\n static call(lambdaName: string) {\n const resolvers: any = {};\n const promise = new LambdaClientRequest((resolve, reject) => {\n resolvers.resolve = resolve;\n resolvers.reject = reject;\n });\n\n promise.init(lambdaName, resolvers.resolve, resolvers.reject);\n\n return promise;\n }\n\n static get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").get(path, options);\n }\n\n static post(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").post(path, body, options);\n }\n\n static put(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").put(path, body, options);\n }\n\n static patch(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").patch(path, body, options);\n }\n\n static delete(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").delete(path, body, options);\n }\n\n static createFakeEvent(event: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return {\n body: \"\",\n headers: {},\n httpMethod: \"\",\n isBase64Encoded: false,\n multiValueHeaders: {},\n multiValueQueryStringParameters: {},\n path: event.path || \"/\",\n pathParameters: {},\n queryStringParameters: {},\n resource: \"\",\n stageVariables: {},\n ...event,\n requestContext: {\n ...event?.requestContext,\n accountId: \"\",\n apiId: \"\",\n protocol: \"https\",\n httpMethod: \"\",\n identity: {} as any,\n path: event.path || \"/\",\n stage: \"\",\n requestId: \"requestId\",\n requestTimeEpoch: 0,\n resourceId: 1,\n resourcePath: event.path || \"/\"\n } as any\n } as APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n }\n\n static createFakeContext(context?: Context): Context {\n return {\n awsRequestId: \"awsRequestId\",\n callbackWaitsForEmptyEventLoop: false,\n functionName: \"\",\n functionVersion: \"\",\n invokedFunctionArn: \"\",\n logGroupName: \"\",\n logStreamName: \"\",\n memoryLimitInMB: \"\",\n ...(context || {})\n } as Context;\n }\n\n get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"GET\";\n\n return this;\n }\n\n post(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"POST\";\n\n this.body(body);\n\n return this;\n }\n\n patch(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PATCH\";\n\n this.body(body);\n\n return this;\n }\n\n put(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PUT\";\n\n this.body(body);\n\n return this;\n }\n\n delete(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"DELETE\";\n\n this.body(body);\n\n return this;\n }\n\n query(query: any) {\n this.event.queryStringParameters = {\n ...this.event.queryStringParameters,\n ...JSON.parse(JSON.stringify(query))\n };\n\n return this;\n }\n\n params(pathParameters: any) {\n this.event.pathParameters = {\n ...this.event.pathParameters,\n ...JSON.parse(JSON.stringify(pathParameters))\n };\n\n return this;\n }\n\n headers(headers: Record<string, any>) {\n this.event.headers = {\n ...this.event.headers,\n ...JSON.parse(JSON.stringify(headers))\n };\n\n return this;\n }\n\n body(body: any) {\n if (body !== undefined) {\n this.event.headers[\"content-type\"] = \"application/json\";\n\n this.event.body = JSON.stringify(body);\n }\n\n return this;\n }\n\n protected init(lambda: string, resolve: Function, reject: Function) {\n setTimeout(async () => {\n try {\n const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve as any);\n resolve(result as any);\n } catch (er) {\n reject(er);\n }\n });\n }\n}\n\nexport class PlatformServerlessTest extends DITest {\n static callbacks: Record<string, APIGatewayProxyHandler> = {};\n static instance: PlatformServerless;\n static request = LambdaClientRequest;\n\n static bootstrap(settings: Partial<TsED.Configuration & {lambda: Type[]}> = {}) {\n return async function before(): Promise<void> {\n // @ts-ignore\n const instance = PlatformServerless.bootstrap(DITest.configure(settings));\n PlatformServerlessTest.instance = instance;\n PlatformServerlessTest.callbacks = instance.callbacks();\n PlatformServerlessTest.callbacks.handler = instance.handler();\n // used by inject method\n DITest.injector = instance.injector;\n\n return instance.promise;\n };\n }\n\n /**\n * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.\n */\n static async reset() {\n if (PlatformServerlessTest.instance) {\n await PlatformServerlessTest.instance.stop();\n }\n if (DITest.hasInjector()) {\n await DITest.injector.destroy();\n DITest._injector = null;\n }\n }\n\n static createServerlessContext({endpoint}: {endpoint: JsonEntityStore}) {\n const context: any = LambdaClientRequest.createFakeContext();\n const event: any = LambdaClientRequest.createFakeEvent();\n\n return new ServerlessContext({\n event,\n context,\n id: context.awsRequestId,\n logger: PlatformServerlessTest.injector.logger as Logger,\n injector: PlatformServerlessTest.injector,\n endpoint\n });\n }\n}\n"]}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { DITest } from "@tsed/di";
|
|
2
|
-
import { PlatformServerless } from "../builder/PlatformServerless";
|
|
3
|
-
import { ServerlessContext } from "../domain/ServerlessContext";
|
|
4
|
-
export class LambdaClientRequest extends Promise {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.event = LambdaClientRequest.createFakeEvent();
|
|
8
|
-
this.context = LambdaClientRequest.createFakeContext();
|
|
9
|
-
}
|
|
10
|
-
static call(lambdaName) {
|
|
11
|
-
const resolvers = {};
|
|
12
|
-
const promise = new LambdaClientRequest((resolve, reject) => {
|
|
13
|
-
resolvers.resolve = resolve;
|
|
14
|
-
resolvers.reject = reject;
|
|
15
|
-
});
|
|
16
|
-
promise.init(lambdaName, resolvers.resolve, resolvers.reject);
|
|
17
|
-
return promise;
|
|
18
|
-
}
|
|
19
|
-
static get(path, options = {}) {
|
|
20
|
-
return this.call("handler").get(path, options);
|
|
21
|
-
}
|
|
22
|
-
static post(path, body, options = {}) {
|
|
23
|
-
return this.call("handler").post(path, body, options);
|
|
24
|
-
}
|
|
25
|
-
static put(path, body, options = {}) {
|
|
26
|
-
return this.call("handler").put(path, body, options);
|
|
27
|
-
}
|
|
28
|
-
static patch(path, body, options = {}) {
|
|
29
|
-
return this.call("handler").patch(path, body, options);
|
|
30
|
-
}
|
|
31
|
-
static delete(path, body, options = {}) {
|
|
32
|
-
return this.call("handler").delete(path, body, options);
|
|
33
|
-
}
|
|
34
|
-
static createFakeEvent(event = {}) {
|
|
35
|
-
return {
|
|
36
|
-
body: "",
|
|
37
|
-
headers: {},
|
|
38
|
-
httpMethod: "",
|
|
39
|
-
isBase64Encoded: false,
|
|
40
|
-
multiValueHeaders: {},
|
|
41
|
-
multiValueQueryStringParameters: {},
|
|
42
|
-
path: event.path || "/",
|
|
43
|
-
pathParameters: {},
|
|
44
|
-
queryStringParameters: {},
|
|
45
|
-
resource: "",
|
|
46
|
-
stageVariables: {},
|
|
47
|
-
...event,
|
|
48
|
-
requestContext: {
|
|
49
|
-
...event === null || event === void 0 ? void 0 : event.requestContext,
|
|
50
|
-
accountId: "",
|
|
51
|
-
apiId: "",
|
|
52
|
-
protocol: "https",
|
|
53
|
-
httpMethod: "",
|
|
54
|
-
identity: {},
|
|
55
|
-
path: event.path || "/",
|
|
56
|
-
stage: "",
|
|
57
|
-
requestId: "requestId",
|
|
58
|
-
requestTimeEpoch: 0,
|
|
59
|
-
resourceId: 1,
|
|
60
|
-
resourcePath: event.path || "/"
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
static createFakeContext(context) {
|
|
65
|
-
return {
|
|
66
|
-
awsRequestId: "awsRequestId",
|
|
67
|
-
callbackWaitsForEmptyEventLoop: false,
|
|
68
|
-
functionName: "",
|
|
69
|
-
functionVersion: "",
|
|
70
|
-
invokedFunctionArn: "",
|
|
71
|
-
logGroupName: "",
|
|
72
|
-
logStreamName: "",
|
|
73
|
-
memoryLimitInMB: "",
|
|
74
|
-
...(context || {})
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
get(path, options = {}) {
|
|
78
|
-
Object.assign(this.event, options);
|
|
79
|
-
this.event.path = path;
|
|
80
|
-
this.event.httpMethod = "GET";
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
post(path, body = {}, options = {}) {
|
|
84
|
-
Object.assign(this.event, options);
|
|
85
|
-
this.event.path = path;
|
|
86
|
-
this.event.httpMethod = "POST";
|
|
87
|
-
this.body(body);
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
patch(path, body = {}, options = {}) {
|
|
91
|
-
Object.assign(this.event, options);
|
|
92
|
-
this.event.path = path;
|
|
93
|
-
this.event.httpMethod = "PATCH";
|
|
94
|
-
this.body(body);
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
put(path, body = {}, options = {}) {
|
|
98
|
-
Object.assign(this.event, options);
|
|
99
|
-
this.event.path = path;
|
|
100
|
-
this.event.httpMethod = "PUT";
|
|
101
|
-
this.body(body);
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
delete(path, body = {}, options = {}) {
|
|
105
|
-
Object.assign(this.event, options);
|
|
106
|
-
this.event.path = path;
|
|
107
|
-
this.event.httpMethod = "DELETE";
|
|
108
|
-
this.body(body);
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
query(query) {
|
|
112
|
-
this.event.queryStringParameters = {
|
|
113
|
-
...this.event.queryStringParameters,
|
|
114
|
-
...JSON.parse(JSON.stringify(query))
|
|
115
|
-
};
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
params(pathParameters) {
|
|
119
|
-
this.event.pathParameters = {
|
|
120
|
-
...this.event.pathParameters,
|
|
121
|
-
...JSON.parse(JSON.stringify(pathParameters))
|
|
122
|
-
};
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
headers(headers) {
|
|
126
|
-
this.event.headers = {
|
|
127
|
-
...this.event.headers,
|
|
128
|
-
...JSON.parse(JSON.stringify(headers))
|
|
129
|
-
};
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
body(body) {
|
|
133
|
-
if (body !== undefined) {
|
|
134
|
-
this.event.headers["content-type"] = "application/json";
|
|
135
|
-
this.event.body = JSON.stringify(body);
|
|
136
|
-
}
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
init(lambda, resolve, reject) {
|
|
140
|
-
setTimeout(async () => {
|
|
141
|
-
try {
|
|
142
|
-
const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve);
|
|
143
|
-
resolve(result);
|
|
144
|
-
}
|
|
145
|
-
catch (er) {
|
|
146
|
-
reject(er);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
export class PlatformServerlessTest extends DITest {
|
|
152
|
-
static bootstrap(settings = {}) {
|
|
153
|
-
return async function before() {
|
|
154
|
-
// @ts-ignore
|
|
155
|
-
const instance = PlatformServerless.bootstrap(DITest.configure(settings));
|
|
156
|
-
PlatformServerlessTest.instance = instance;
|
|
157
|
-
PlatformServerlessTest.callbacks = instance.callbacks();
|
|
158
|
-
PlatformServerlessTest.callbacks.handler = instance.handler();
|
|
159
|
-
// used by inject method
|
|
160
|
-
DITest.injector = instance.injector;
|
|
161
|
-
return instance.promise;
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
166
|
-
*/
|
|
167
|
-
static async reset() {
|
|
168
|
-
if (PlatformServerlessTest.instance) {
|
|
169
|
-
await PlatformServerlessTest.instance.stop();
|
|
170
|
-
}
|
|
171
|
-
if (DITest.hasInjector()) {
|
|
172
|
-
await DITest.injector.destroy();
|
|
173
|
-
DITest._injector = null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
static createServerlessContext({ endpoint }) {
|
|
177
|
-
const context = LambdaClientRequest.createFakeContext();
|
|
178
|
-
const event = LambdaClientRequest.createFakeEvent();
|
|
179
|
-
return new ServerlessContext({
|
|
180
|
-
event,
|
|
181
|
-
context,
|
|
182
|
-
id: context.awsRequestId,
|
|
183
|
-
logger: PlatformServerlessTest.injector.logger,
|
|
184
|
-
injector: PlatformServerlessTest.injector,
|
|
185
|
-
endpoint
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
PlatformServerlessTest.callbacks = {};
|
|
190
|
-
PlatformServerlessTest.request = LambdaClientRequest;
|
|
191
|
-
//# sourceMappingURL=PlatformServerlessTest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformServerlessTest.js","sourceRoot":"","sources":["../../../src/services/PlatformServerlessTest.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAKhC,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAI9D,MAAM,OAAO,mBAAoB,SAAQ,OAA8B;IAAvE;;QACE,UAAK,GAAG,mBAAmB,CAAC,eAAe,EAAE,CAAC;QAC9C,YAAO,GAAG,mBAAmB,CAAC,iBAAiB,EAAE,CAAC;IAmLpD,CAAC;IAjLC,MAAM,CAAC,IAAI,CAAC,UAAkB;QAC5B,MAAM,SAAS,GAAQ,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1D,SAAS,CAAC,OAAO,GAAG,OAA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BAAmB,CAAC,eAAe,EAAE,CAAC;QAEzD,OAAO,IAAI,iBAAiB,CAAC;YAC3B,KAAK;YACL,OAAO;YACP,EAAE,EAAE,OAAO,CAAC,YAAY;YACxB,MAAM,EAAE,sBAAsB,CAAC,QAAQ,CAAC,MAAgB;YACxD,QAAQ,EAAE,sBAAsB,CAAC,QAAQ;YACzC,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;;AA3CM,gCAAS,GAA2C,EAAE,CAAC;AAEvD,8BAAO,GAAG,mBAAmB,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {DITest} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {JsonEntityStore} from \"@tsed/schema\";\nimport {APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler, Context} from \"aws-lambda\";\nimport {APIGatewayProxyResult} from \"aws-lambda/trigger/api-gateway-proxy\";\nimport {PlatformServerless} from \"../builder/PlatformServerless\";\nimport {ServerlessContext} from \"../domain/ServerlessContext\";\n\nexport interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {}\n\nexport class LambdaClientRequest extends Promise<APIGatewayProxyResult> {\n event = LambdaClientRequest.createFakeEvent();\n context = LambdaClientRequest.createFakeContext();\n\n static call(lambdaName: string) {\n const resolvers: any = {};\n const promise = new LambdaClientRequest((resolve, reject) => {\n resolvers.resolve = resolve;\n resolvers.reject = reject;\n });\n\n promise.init(lambdaName, resolvers.resolve, resolvers.reject);\n\n return promise;\n }\n\n static get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").get(path, options);\n }\n\n static post(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").post(path, body, options);\n }\n\n static put(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").put(path, body, options);\n }\n\n static patch(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").patch(path, body, options);\n }\n\n static delete(path: string, body?: any, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return this.call(\"handler\").delete(path, body, options);\n }\n\n static createFakeEvent(event: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n return {\n body: \"\",\n headers: {},\n httpMethod: \"\",\n isBase64Encoded: false,\n multiValueHeaders: {},\n multiValueQueryStringParameters: {},\n path: event.path || \"/\",\n pathParameters: {},\n queryStringParameters: {},\n resource: \"\",\n stageVariables: {},\n ...event,\n requestContext: {\n ...event?.requestContext,\n accountId: \"\",\n apiId: \"\",\n protocol: \"https\",\n httpMethod: \"\",\n identity: {} as any,\n path: event.path || \"/\",\n stage: \"\",\n requestId: \"requestId\",\n requestTimeEpoch: 0,\n resourceId: 1,\n resourcePath: event.path || \"/\"\n } as any\n } as APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;\n }\n\n static createFakeContext(context?: Context): Context {\n return {\n awsRequestId: \"awsRequestId\",\n callbackWaitsForEmptyEventLoop: false,\n functionName: \"\",\n functionVersion: \"\",\n invokedFunctionArn: \"\",\n logGroupName: \"\",\n logStreamName: \"\",\n memoryLimitInMB: \"\",\n ...(context || {})\n } as Context;\n }\n\n get(path: string, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"GET\";\n\n return this;\n }\n\n post(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"POST\";\n\n this.body(body);\n\n return this;\n }\n\n patch(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PATCH\";\n\n this.body(body);\n\n return this;\n }\n\n put(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"PUT\";\n\n this.body(body);\n\n return this;\n }\n\n delete(path: string, body: any = {}, options: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>> = {}) {\n Object.assign(this.event, options);\n\n this.event.path = path;\n this.event.httpMethod = \"DELETE\";\n\n this.body(body);\n\n return this;\n }\n\n query(query: any) {\n this.event.queryStringParameters = {\n ...this.event.queryStringParameters,\n ...JSON.parse(JSON.stringify(query))\n };\n\n return this;\n }\n\n params(pathParameters: any) {\n this.event.pathParameters = {\n ...this.event.pathParameters,\n ...JSON.parse(JSON.stringify(pathParameters))\n };\n\n return this;\n }\n\n headers(headers: Record<string, any>) {\n this.event.headers = {\n ...this.event.headers,\n ...JSON.parse(JSON.stringify(headers))\n };\n\n return this;\n }\n\n body(body: any) {\n if (body !== undefined) {\n this.event.headers[\"content-type\"] = \"application/json\";\n\n this.event.body = JSON.stringify(body);\n }\n\n return this;\n }\n\n protected init(lambda: string, resolve: Function, reject: Function) {\n setTimeout(async () => {\n try {\n const result = await PlatformServerlessTest.callbacks[lambda](this.event, this.context, resolve as any);\n resolve(result as any);\n } catch (er) {\n reject(er);\n }\n });\n }\n}\n\nexport class PlatformServerlessTest extends DITest {\n static callbacks: Record<string, APIGatewayProxyHandler> = {};\n static instance: PlatformServerless;\n static request = LambdaClientRequest;\n\n static bootstrap(settings: Partial<TsED.Configuration & {lambda: Type[]}> = {}) {\n return async function before(): Promise<void> {\n // @ts-ignore\n const instance = PlatformServerless.bootstrap(DITest.configure(settings));\n PlatformServerlessTest.instance = instance;\n PlatformServerlessTest.callbacks = instance.callbacks();\n PlatformServerlessTest.callbacks.handler = instance.handler();\n // used by inject method\n DITest.injector = instance.injector;\n\n return instance.promise;\n };\n }\n\n /**\n * Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.\n */\n static async reset() {\n if (PlatformServerlessTest.instance) {\n await PlatformServerlessTest.instance.stop();\n }\n if (DITest.hasInjector()) {\n await DITest.injector.destroy();\n DITest._injector = null;\n }\n }\n\n static createServerlessContext({endpoint}: {endpoint: JsonEntityStore}) {\n const context: any = LambdaClientRequest.createFakeContext();\n const event: any = LambdaClientRequest.createFakeEvent();\n\n return new ServerlessContext({\n event,\n context,\n id: context.awsRequestId,\n logger: PlatformServerlessTest.injector.logger as Logger,\n injector: PlatformServerlessTest.injector,\n endpoint\n });\n }\n}\n"]}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Type } from "@tsed/core";
|
|
2
|
-
import { DITest } from "@tsed/di";
|
|
3
|
-
import { JsonEntityStore } from "@tsed/schema";
|
|
4
|
-
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEventBase, APIGatewayProxyHandler, Context } from "aws-lambda";
|
|
5
|
-
import { APIGatewayProxyResult } from "aws-lambda/trigger/api-gateway-proxy";
|
|
6
|
-
import { PlatformServerless } from "../builder/PlatformServerless";
|
|
7
|
-
import { ServerlessContext } from "../domain/ServerlessContext";
|
|
8
|
-
export interface LambdaPromiseResult extends Promise<APIGatewayProxyResult> {
|
|
9
|
-
}
|
|
10
|
-
export declare class LambdaClientRequest extends Promise<APIGatewayProxyResult> {
|
|
11
|
-
event: APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
12
|
-
context: Context;
|
|
13
|
-
static call(lambdaName: string): LambdaClientRequest;
|
|
14
|
-
static get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
15
|
-
static post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
16
|
-
static put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
17
|
-
static patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
18
|
-
static delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): LambdaClientRequest;
|
|
19
|
-
static createFakeEvent(event?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>;
|
|
20
|
-
static createFakeContext(context?: Context): Context;
|
|
21
|
-
get(path: string, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
22
|
-
post(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
23
|
-
patch(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
24
|
-
put(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
25
|
-
delete(path: string, body?: any, options?: Partial<APIGatewayProxyEventBase<APIGatewayEventDefaultAuthorizerContext>>): this;
|
|
26
|
-
query(query: any): this;
|
|
27
|
-
params(pathParameters: any): this;
|
|
28
|
-
headers(headers: Record<string, any>): this;
|
|
29
|
-
body(body: any): this;
|
|
30
|
-
protected init(lambda: string, resolve: Function, reject: Function): void;
|
|
31
|
-
}
|
|
32
|
-
export declare class PlatformServerlessTest extends DITest {
|
|
33
|
-
static callbacks: Record<string, APIGatewayProxyHandler>;
|
|
34
|
-
static instance: PlatformServerless;
|
|
35
|
-
static request: typeof LambdaClientRequest;
|
|
36
|
-
static bootstrap(settings?: Partial<TsED.Configuration & {
|
|
37
|
-
lambda: Type[];
|
|
38
|
-
}>): () => Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Resets the test injector of the test context, so it won't pollute your next test. Call this in your `tearDown` logic.
|
|
41
|
-
*/
|
|
42
|
-
static reset(): Promise<void>;
|
|
43
|
-
static createServerlessContext({ endpoint }: {
|
|
44
|
-
endpoint: JsonEntityStore;
|
|
45
|
-
}): ServerlessContext;
|
|
46
|
-
}
|