@travetto/web-aws-lambda 8.0.0-alpha.23 → 8.0.0-alpha.25

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/README.md CHANGED
@@ -13,7 +13,7 @@ npm install @travetto/web-aws-lambda
13
13
  yarn add @travetto/web-aws-lambda
14
14
  ```
15
15
 
16
- This module provides an adapter between [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") and [AWS Lambda](https://aws.amazon.com/lambda/). The event-driven invocation model for [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") aligns cleanly with [AWS Lambda](https://aws.amazon.com/lambda/)'s model for event-driven operation.
16
+ This module provides an adapter between [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") and [AWS Lambda](https://aws.amazon.com/lambda/). The event-driven invocation model for [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative support for creating Web Applications") aligns cleanly with [AWS Lambda](https://aws.amazon.com/lambda/)'s model for event-driven operation.
17
17
 
18
18
  **NOTE:** The only caveat to consider, is that while the framework supports streams for responses, [AWS Lambda](https://aws.amazon.com/lambda/) does not. Any streaming result will be read and converted into a [Buffer](https://nodejs.org/api/buffer.html) before being sent back.
19
19
 
package/__index__.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './src/handler.ts';
2
- export * from './src/util.ts';
2
+ export * from './src/util.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/web-aws-lambda",
3
- "version": "8.0.0-alpha.23",
3
+ "version": "8.0.0-alpha.25",
4
4
  "type": "module",
5
5
  "description": "Web APIs entry point support for AWS Lambdas.",
6
6
  "keywords": [
@@ -26,13 +26,13 @@
26
26
  "directory": "module/web-aws-lambda"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/web": "^8.0.0-alpha.22",
29
+ "@travetto/web": "^8.0.0-alpha.24",
30
30
  "@types/aws-lambda": "^8.10.162"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/cli": "^8.0.0-alpha.27",
34
- "@travetto/pack": "^8.0.0-alpha.22",
35
- "@travetto/test": "^8.0.0-alpha.20"
33
+ "@travetto/cli": "^8.0.0-alpha.29",
34
+ "@travetto/pack": "^8.0.0-alpha.24",
35
+ "@travetto/test": "^8.0.0-alpha.22"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/test": {
package/src/handler.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  import type lambda from 'aws-lambda';
2
2
 
3
- import { Runtime, ConsoleManager } from '@travetto/runtime';
3
+ import { ConfigurationService } from '@travetto/config';
4
4
  import { DependencyRegistryIndex, Inject, Injectable } from '@travetto/di';
5
5
  import { Registry } from '@travetto/registry';
6
- import { ConfigurationService } from '@travetto/config';
6
+ import { ConsoleManager, Runtime } from '@travetto/runtime';
7
7
  import type { StandardWebRouter } from '@travetto/web';
8
8
 
9
9
  import { AwsLambdaWebUtil } from './util.ts';
10
10
 
11
11
  @Injectable()
12
12
  export class AwsLambdaWebHandler {
13
-
14
13
  static inst: AwsLambdaWebHandler;
15
14
 
16
15
  static entryPoint(): (event: lambda.APIGatewayProxyEvent, context: lambda.Context) => Promise<lambda.APIGatewayProxyResult> {
@@ -35,4 +34,4 @@ export class AwsLambdaWebHandler {
35
34
  const response = await this.router.dispatch({ request });
36
35
  return AwsLambdaWebUtil.toLambdaResult(response, event.isBase64Encoded);
37
36
  }
38
- }
37
+ }
package/src/util.ts CHANGED
@@ -1,29 +1,29 @@
1
1
  import type { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
2
2
 
3
- import { BinaryUtil, castTo, CodecUtil, type BinaryArray } from '@travetto/runtime';
3
+ import { type BinaryArray, BinaryUtil, CodecUtil, castTo } from '@travetto/runtime';
4
4
  import { WebBodyUtil, WebCommonUtil, WebRequest, WebResponse } from '@travetto/web';
5
5
 
6
6
  export class AwsLambdaWebUtil {
7
-
8
7
  /**
9
8
  * Create a request from an api gateway event
10
9
  */
11
10
  static toWebRequest(event: APIGatewayProxyEvent): WebRequest {
12
11
  // Build request
13
- const body = !event.body ? undefined :
14
- event.isBase64Encoded ?
15
- CodecUtil.fromBase64String(event.body) :
16
- CodecUtil.fromUTF8String(event.body);
12
+ const body = !event.body
13
+ ? undefined
14
+ : event.isBase64Encoded
15
+ ? CodecUtil.fromBase64String(event.body)
16
+ : CodecUtil.fromUTF8String(event.body);
17
17
 
18
18
  return new WebRequest({
19
19
  context: {
20
20
  connection: {
21
21
  httpProtocol: 'http',
22
- ip: event.requestContext.identity?.sourceIp,
22
+ ip: event.requestContext.identity?.sourceIp
23
23
  },
24
24
  httpMethod: castTo(event.httpMethod.toUpperCase()),
25
25
  httpQuery: castTo(event.queryStringParameters!),
26
- path: event.path,
26
+ path: event.path
27
27
  },
28
28
  headers: { ...event.headers, ...event.multiValueHeaders },
29
29
  body: WebBodyUtil.markRawBinary(body)
@@ -38,9 +38,7 @@ export class AwsLambdaWebUtil {
38
38
  context: response.context,
39
39
  ...WebBodyUtil.toBinaryMessage(response)
40
40
  });
41
- const output: BinaryArray = binaryResponse.body ?
42
- await BinaryUtil.toBinaryArray(binaryResponse.body) :
43
- BinaryUtil.makeBinaryArray(0);
41
+ const output: BinaryArray = binaryResponse.body ? await BinaryUtil.toBinaryArray(binaryResponse.body) : BinaryUtil.makeBinaryArray(0);
44
42
 
45
43
  const isBase64Encoded = !!output.byteLength && base64Encoded;
46
44
  const headers: Record<string, string> = {};
@@ -59,7 +57,7 @@ export class AwsLambdaWebUtil {
59
57
  isBase64Encoded,
60
58
  body: isBase64Encoded ? CodecUtil.toBase64String(output) : CodecUtil.toUTF8String(output),
61
59
  headers,
62
- multiValueHeaders,
60
+ multiValueHeaders
63
61
  };
64
62
  }
65
- }
63
+ }
@@ -1,4 +1,5 @@
1
1
  import { CliCommand, CliUtil } from '@travetto/cli';
2
+
2
3
  import { PackOperation } from '@travetto/pack/support/bin/operation.ts';
3
4
  import { BasePackCommand, type PackOperationShape } from '@travetto/pack/support/pack.base.ts';
4
5
 
@@ -10,7 +11,6 @@ import { BasePackCommand, type PackOperationShape } from '@travetto/pack/support
10
11
  */
11
12
  @CliCommand()
12
13
  export class PackLambdaCommand extends BasePackCommand {
13
-
14
14
  constructor() {
15
15
  super();
16
16
  this.entryPoint = '@travetto/web-aws-lambda/support/entry.handler.ts';
@@ -25,9 +25,6 @@ export class PackLambdaCommand extends BasePackCommand {
25
25
  }
26
26
 
27
27
  getOperations(): PackOperationShape<this>[] {
28
- return [
29
- ...super.getOperations(),
30
- PackOperation.compress
31
- ];
28
+ return [...super.getOperations(), PackOperation.compress];
32
29
  }
33
- }
30
+ }
@@ -1,3 +1,3 @@
1
1
  // @trv-no-transform
2
2
  import { AwsLambdaWebHandler } from '../src/handler.ts';
3
- export const handler = AwsLambdaWebHandler.entryPoint();
3
+ export const handler = AwsLambdaWebHandler.entryPoint();
@@ -1,8 +1,8 @@
1
1
  import type { APIGatewayProxyEvent, Context } from 'aws-lambda';
2
2
 
3
3
  import { Inject, Injectable } from '@travetto/di';
4
+ import { asFull, type BinaryArray, BinaryUtil, CodecUtil, castTo, RuntimeError } from '@travetto/runtime';
4
5
  import { type WebDispatcher, type WebFilterContext, type WebRequest, WebResponse } from '@travetto/web';
5
- import { RuntimeError, asFull, BinaryUtil, castTo, CodecUtil, type BinaryArray } from '@travetto/runtime';
6
6
 
7
7
  import { WebTestDispatchUtil } from '@travetto/web/support/test/dispatch-util.ts';
8
8
 
@@ -48,8 +48,8 @@ function toLambdaEvent(request: WebRequest<BinaryArray>): APIGatewayProxyEvent {
48
48
  isBase64Encoded: true,
49
49
  body: request.body ? CodecUtil.toBase64String(request.body) : null,
50
50
  requestContext: castTo({
51
- identity: castTo({ sourceIp: '127.0.0.1' }),
52
- }),
51
+ identity: castTo({ sourceIp: '127.0.0.1' })
52
+ })
53
53
  };
54
54
  }
55
55
 
@@ -58,7 +58,6 @@ function toLambdaEvent(request: WebRequest<BinaryArray>): APIGatewayProxyEvent {
58
58
  */
59
59
  @Injectable()
60
60
  export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
61
-
62
61
  @Inject()
63
62
  app: AwsLambdaWebHandler;
64
63
 
@@ -68,10 +67,8 @@ export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
68
67
 
69
68
  return WebTestDispatchUtil.finalizeResponseBody(
70
69
  new WebResponse<unknown>({
71
- body: response.isBase64Encoded ?
72
- CodecUtil.fromBase64String(response.body) :
73
- CodecUtil.fromUTF8String(response.body),
74
- headers: { ...response.headers ?? {}, ...response.multiValueHeaders ?? {} },
70
+ body: response.isBase64Encoded ? CodecUtil.fromBase64String(response.body) : CodecUtil.fromUTF8String(response.body),
71
+ headers: { ...(response.headers ?? {}), ...(response.multiValueHeaders ?? {}) },
75
72
  context: {
76
73
  httpStatusCode: response.statusCode
77
74
  }
@@ -79,4 +76,4 @@ export class LocalAwsLambdaWebDispatcher implements WebDispatcher {
79
76
  true
80
77
  );
81
78
  }
82
- }
79
+ }