Skip to content

Commit 00d5c71

Browse files
committed
add jsdocs with example events and links to types and documentation
1 parent e1ebf2b commit 00d5c71

20 files changed

+1146
-48
lines changed

packages/parser/src/schemas/alb.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
import { z } from 'zod';
22

3+
/**
4+
* Zod schema for Application load balancer event
5+
*
6+
* @example
7+
* ```json
8+
* {
9+
* "requestContext": {
10+
* "elb": {
11+
* "targetGroupArn": "arn:aws:elasticloadbalancing:region:123456789012:targetgroup/my-target-group/6d0ecf831eec9f09"
12+
* }
13+
* },
14+
* "httpMethod": "GET",
15+
* "path": "/",
16+
* "queryStringParameters": {
17+
* parameters
18+
* },
19+
* "headers": {
20+
* "accept": "text/html,application/xhtml+xml",
21+
* "accept-language": "en-US,en;q=0.8",
22+
* "content-type": "text/plain",
23+
* "cookie": "cookies",
24+
* "host": "lambda-846800462-us-east-2.elb.amazonaws.com",
25+
* "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)",
26+
* "x-amzn-trace-id": "Root=1-5bdb40ca-556d8b0c50dc66f0511bf520",
27+
* "x-forwarded-for": "72.21.198.66",
28+
* "x-forwarded-port": "443",
29+
* "x-forwarded-proto": "https"
30+
* },
31+
* "isBase64Encoded": false,
32+
* "body": "request_body"
33+
* }
34+
* ```
35+
*
36+
* @see {@link types.ALBEvent | ALBEvent}
37+
* @see {@link https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html}
38+
* @see {@link https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html}
39+
*/
340
const AlbSchema = z.object({
441
httpMethod: z.string(),
542
path: z.string(),
@@ -14,6 +51,24 @@ const AlbSchema = z.object({
1451
}),
1552
});
1653

54+
/**
55+
* Zod schema for Application load balancer event with multi-value headers
56+
*
57+
* @example
58+
* ```json
59+
* {
60+
* "multiValueHeaders": {
61+
* "Set-cookie": [
62+
* "cookie-name=cookie-value;Domain=myweb.com;Secure;HttpOnly",
63+
* "cookie-name=cookie-value;Expires=May 8, 2019"
64+
* ],
65+
* "Content-Type": [
66+
* "application/json"
67+
* ]
68+
* }
69+
* }
70+
* ```
71+
*/
1772
const AlbMultiValueHeadersSchema = AlbSchema.extend({
1873
multiValueHeaders: z.record(z.string(), z.array(z.string())),
1974
multiValueQueryStringParameters: z.record(z.string(), z.array(z.string())),

packages/parser/src/schemas/apigw.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,56 @@ const APIGatewayEventRequestContext = z
8888
}
8989
);
9090

91+
/**
92+
* Zod schema for an API Gateway Proxy event
93+
*
94+
* @example
95+
* ```json
96+
* {
97+
* "type": "REQUEST",
98+
* "methodArn": "arn:aws:execute-api:us-east-1:123456789012:abcdef123/test/GET/request",
99+
* "resource": "/request",
100+
* "path": "/request",
101+
* "httpMethod": "GET",
102+
* "headers": {
103+
* "X-AMZ-Date": "20170718T062915Z",
104+
* "Accept": "application/json",
105+
* "HeaderAuth1": "headerValue1"
106+
* },
107+
* "queryStringParameters": {
108+
* "QueryString1": "queryValue1"
109+
* },
110+
* "pathParameters": {},
111+
* "stageVariables": null,
112+
* "requestContext": {
113+
* "path": "/request",
114+
* "accountId": "123456789012",
115+
* "resourceId": "05c7jb",
116+
* "stage": "test",
117+
* "requestId": "...",
118+
* "identity": {
119+
* "cognitoIdentityPoolId": null,
120+
* "accountId": null,
121+
* "cognitoIdentityId": null,
122+
* "caller": null,
123+
* "sourceIp": "192.168.1.1",
124+
* "principalOrgId": null,
125+
* "accessKey": null,
126+
* "cognitoAuthenticationType": null,
127+
* "cognitoAuthenticationProvider": null,
128+
* "userArn": null,
129+
* "userAgent": "HTTPie/3.2.2",
130+
* "user": null
131+
* }
132+
* },
133+
* "resourcePath": "/request",
134+
* "httpMethod": "GET",
135+
* "apiId": "abcdef123"
136+
* }
137+
* ```
138+
* @see {@link types.APIGatewayProxyEvent | APIGatewayProxyEvent}
139+
* @see {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html}
140+
*/
91141
const APIGatewayProxyEventSchema = z.object({
92142
version: z.string().optional(),
93143
authorizationToken: z.string().optional(),
@@ -115,5 +165,5 @@ const APIGatewayProxyEventSchema = z.object({
115165
isBase64Encoded: z.boolean().optional(),
116166
body: z.string().nullable(),
117167
});
118-
168+
export const foo = APIGatewayProxyEventSchema;
119169
export { APIGatewayProxyEventSchema, APIGatewayCert };

packages/parser/src/schemas/apigwv2.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,85 @@ const RequestContextV2 = z.object({
5555
timeEpoch: z.number(),
5656
});
5757

58+
/**
59+
* Zod schema for an API Gateway V2 Proxy event
60+
*
61+
* @example
62+
* ```json
63+
* {
64+
* "version": "2.0",
65+
* "routeKey": "$default",
66+
* "rawPath": "/my/path",
67+
* "rawQueryString": "parameter1=value1&parameter1=value2&parameter2=value",
68+
* "cookies": [
69+
* "cookie1",
70+
* "cookie2"
71+
* ],
72+
* "headers": {
73+
* "Header1": "value1",
74+
* "Header2": "value1,value2"
75+
* },
76+
* "queryStringParameters": {
77+
* "parameter1": "value1,value2",
78+
* "parameter2": "value"
79+
* },
80+
* "requestContext": {
81+
* "accountId": "123456789012",
82+
* "apiId": "api-id",
83+
* "authentication": {
84+
* "clientCert": {
85+
* "clientCertPem": "CERT_CONTENT",
86+
* "subjectDN": "www.example.com",
87+
* "issuerDN": "Example issuer",
88+
* "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",
89+
* "validity": {
90+
* "notBefore": "May 28 12:30:02 2019 GMT",
91+
* "notAfter": "Aug 5 09:36:04 2021 GMT"
92+
* }
93+
* }
94+
* },
95+
* "authorizer": {
96+
* "jwt": {
97+
* "claims": {
98+
* "claim1": "value1",
99+
* "claim2": "value2"
100+
* },
101+
* "scopes": [
102+
* "scope1",
103+
* "scope2"
104+
* ]
105+
* }
106+
* },
107+
* "domainName": "id.execute-api.us-east-1.amazonaws.com",
108+
* "domainPrefix": "id",
109+
* "http": {
110+
* "method": "POST",
111+
* "path": "/my/path",
112+
* "protocol": "HTTP/1.1",
113+
* "sourceIp": "192.168.0.1",
114+
* "userAgent": "agent"
115+
* },
116+
* "requestId": "id",
117+
* "routeKey": "$default",
118+
* "stage": "$default",
119+
* "time": "12/Mar/2020:19:03:58 +0000",
120+
* "timeEpoch": 1583348638390
121+
* },
122+
* "body": "{\"message\": \"hello world\", \"username\": \"tom\"}",
123+
* "pathParameters": {
124+
* "parameter1": "value1"
125+
* },
126+
* "isBase64Encoded": false,
127+
* "stageVariables": {
128+
* "stageVariable1": "value1",
129+
* "stageVariable2": "value2"
130+
* }
131+
* }
132+
* ```
133+
*
134+
* @see {@link types.APIGatewayProxyEventV2 | APIGatewayProxyEventV2}
135+
* @see {@link https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html}
136+
*/
58137
const APIGatewayProxyEventV2Schema = z.object({
59138
version: z.string(),
60139
routeKey: z.string(),

packages/parser/src/schemas/cloudformation-custom-resource.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,90 @@ const CloudFormationCustomResourceBaseSchema = z.object({
1010
ResourceProperties: z.record(z.any()),
1111
});
1212

13+
/**
14+
* Zod schema for CloudFormation Custom Resource event with RequestType = 'Create'
15+
*
16+
* @example
17+
* ```json
18+
* {
19+
* "RequestType": "Create",
20+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxx:function:xxxx-CrbuiltinfunctionidProvi-2vKAalSppmKe",
21+
* "ResponseURL": "https://cloudformation-custom-resource-response-useast1.s3.amazonaws.com/7F%7Cb1f50fdfc25f3b",
22+
* "StackId": "arn:aws:cloudformation:us-east-1:xxxx:stack/xxxx/271845b0-f2e8-11ed-90ac-0eeb25b8ae21",
23+
* "RequestId": "xxxxx-d2a0-4dfb-ab1f-xxxxxx",
24+
* "LogicalResourceId": "xxxxxxxxx",
25+
* "ResourceType": "Custom::MyType",
26+
* "ResourceProperties": {
27+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxxxx:function:xxxxx",
28+
* "MyProps": "ss"
29+
* }
30+
* }
31+
* ```
32+
* @see {@link types.CloudFormationCustomResourceCreateEvent | CloudFormationCustomResourceCreateEvent}
33+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requesttypes-create.html
34+
*/
1335
const CloudFormationCustomResourceCreateSchema =
1436
CloudFormationCustomResourceBaseSchema.merge(
1537
z.object({
1638
RequestType: z.literal('Create'),
1739
})
1840
);
1941

42+
/**
43+
* Zod schema for CloudFormation Custom Resource event with RequestType = 'Delete'
44+
*
45+
* @example
46+
* ```json
47+
* {
48+
* "RequestType": "Delete",
49+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxx:function:xxxx-CrbuiltinfunctionidProvi-2vKAalSppmKe",
50+
* "ResponseURL": "https://cloudformation-custom-resource-response-useast1.s3.amazonaws.com/7F%7Cb1f50fdfc25f3b",
51+
* "StackId": "arn:aws:cloudformation:us-east-1:xxxx:stack/xxxx/271845b0-f2e8-11ed-90ac-0eeb25b8ae21",
52+
* "RequestId": "xxxxx-d2a0-4dfb-ab1f-xxxxxx",
53+
* "LogicalResourceId": "xxxxxxxxx",
54+
* "ResourceType": "Custom::MyType",
55+
* "ResourceProperties": {
56+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxxxx:function:xxxxx",
57+
* "MyProps": "ss"
58+
* }
59+
* }
60+
* ```
61+
* @see {@link types.CloudFormationCustomResourceDeleteEvent | CloudFormationCustomResourceDeleteEvent}
62+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requesttypes-delete.html
63+
*/
2064
const CloudFormationCustomResourceDeleteSchema =
2165
CloudFormationCustomResourceBaseSchema.merge(
2266
z.object({
2367
RequestType: z.literal('Delete'),
2468
})
2569
);
2670

71+
/**
72+
* Zod schema for CloudFormation Custom Resource event with RequestType = 'Update'
73+
*
74+
* @example
75+
* ```json
76+
* {
77+
* "RequestType": "Update",
78+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxx:function:xxxx-CrbuiltinfunctionidProvi-2vKAalSppmKe",
79+
* "ResponseURL": "https://cloudformation-custom-resource-response-useast1.s3.amazonaws.com/7F%7Cb1f50fdfc25f3b",
80+
* "StackId": "arn:aws:cloudformation:us-east-1:xxxx:stack/xxxx/271845b0-f2e8-11ed-90ac-0eeb25b8ae21",
81+
* "RequestId": "xxxxx-d2a0-4dfb-ab1f-xxxxxx",
82+
* "LogicalResourceId": "xxxxxxxxx",
83+
* "ResourceType": "Custom::MyType",
84+
* "ResourceProperties": {
85+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxxxx:function:xxxxx",
86+
* "MyProps": "new"
87+
* },
88+
* "OldResourceProperties": {
89+
* "ServiceToken": "arn:aws:lambda:us-east-1:xxxxx:function:xxxxx-xxxx-xxx",
90+
* "MyProps": "old"
91+
* }
92+
* }
93+
* ```
94+
* @see {@link types.CloudFormationCustomResourceUpdateEvent | CloudFormationCustomResourceUpdateEvent}
95+
* @see {@links https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requesttypes-update.html}
96+
*/
2797
const CloudFormationCustomResourceUpdateSchema =
2898
CloudFormationCustomResourceBaseSchema.merge(
2999
z.object({

packages/parser/src/schemas/cloudwatch.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,52 @@ const decompressRecordToJSON = (
2424
return CloudWatchLogsDecodeSchema.parse(JSON.parse(uncompressed));
2525
};
2626

27+
/**
28+
* Zod schema for CloudWatch Logs.
29+
*
30+
* @example
31+
* ```json
32+
* {
33+
* "awslogs": {
34+
* "data": "H4sIAAAAAAAAAHWPwQqCQBCGX0Xm7EFtK+smZBEUgXoLCdMhFtKV3akI8d0bLYmibvPPN3wz00CJxmQnTO41whwWQRIctmEcB6sQbFC3CjW3XW8kxpOpP+OC22d1Wml1qZkQGtoMsScxaczKN3plG8zlaHIta5KqWsozoTYw3/djzwhpLwivWFGHGpAFe7DL68JlBUk+l7KSN7tCOEJ4M3/qOI49vMHj+zCKdlFqLaU2ZHV2a4Ct/an0/ivdX8oYc1UVX860fQDQiMdxRQEAAA=="
35+
* }
36+
* }
37+
* ```
38+
* The `data` field compressed JSON string, once transformed the payload will look like:
39+
*
40+
* @example
41+
* ```json
42+
* {
43+
* "owner": "123456789012",
44+
* "logGroup": "CloudTrail",
45+
* "logStream": "123456789012_CloudTrail_us-east-1",
46+
* "subscriptionFilters": [
47+
* "Destination"
48+
* ],
49+
* "messageType": "DATA_MESSAGE",
50+
* "logEvents": [
51+
* {
52+
* "id": "31953106606966983378809025079804211143289615424298221568",
53+
* "timestamp": 1432826855000,
54+
* "message": "{\"eventVersion\":\"1.03\",\"userIdentity\":{\"type\":\"Root\"}"
55+
* },
56+
* {
57+
* "id": "31953106606966983378809025079804211143289615424298221569",
58+
* "timestamp": 1432826855000,
59+
* "message": "{\"eventVersion\":\"1.03\",\"userIdentity\":{\"type\":\"Root\"}"
60+
* },
61+
* {
62+
* "id": "31953106606966983378809025079804211143289615424298221570",
63+
* "timestamp": 1432826855000,
64+
* "message": "{\"eventVersion\":\"1.03\",\"userIdentity\":{\"type\":\"Root\"}"
65+
* }
66+
* ]
67+
* }
68+
* ```
69+
*
70+
* @see {@link types.CloudWatchLogsEvent | CloudWatchLogsEvent}
71+
* @see {@link https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SubscriptionFilters.html#LambdaFunctionExample}
72+
*/
2773
const CloudWatchLogsSchema = z.object({
2874
awslogs: z.object({
2975
data: z.string().transform((data) => decompressRecordToJSON(data)),

0 commit comments

Comments
 (0)