ts-ag 1.0.27 → 1.0.29
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/lambda/client.d.ts.map +1 -1
- package/dist/lambda/client.js +7 -1
- package/dist/lambda/handlerUtils.d.ts +5 -5
- package/dist/lambda/handlerUtils.d.ts.map +1 -1
- package/dist/lambda/handlerUtils.js +8 -1
- package/package.json +6 -6
- package/src/lambda/client.ts +7 -1
- package/src/lambda/handlerUtils.ts +19 -6
- package/src/lambda/handlerUtils.unit.test.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lambda/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lambda/client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAiE7E,QAAA,MAAM,WAAW,uEAAwE,CAAC;AAC1F,KAAK,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/C,MAAM,MAAM,kBAAkB,CAAC,GAAG,SAAS,YAAY,IAAI,CACzD,IAAI,SAAS,GAAG,CAAC,MAAM,CAAC,EACxB,MAAM,SAAS,OAAO,CAAC,GAAG,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC,QAAQ,CAAC,EAErD,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,EAClC,OAAO,CAAC,EAAE,WAAW,KAClB,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,kBAAkB,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,SAAS,YAAY,EACvD,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,EAC7E,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,kBAAkB,CAAC,GAAG,CAAC,CAmBzB"}
|
package/dist/lambda/client.js
CHANGED
|
@@ -35,12 +35,18 @@ environment, apiUrl, headers) {
|
|
|
35
35
|
body: bodyMethods.includes(method) ? JSON.stringify(input) : undefined,
|
|
36
36
|
credentials: 'include'
|
|
37
37
|
});
|
|
38
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
38
39
|
let retrieved = false;
|
|
39
40
|
response.json = async () => {
|
|
40
41
|
if (retrieved === false) {
|
|
41
42
|
retrieved = response.text();
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
if (contentType === 'application/devalue') {
|
|
45
|
+
return await parse(await retrieved);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return JSON.parse(await retrieved);
|
|
49
|
+
}
|
|
44
50
|
};
|
|
45
51
|
return response;
|
|
46
52
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { APIGatewayProxyResultV2, Context } from 'aws-lambda';
|
|
1
|
+
import type { APIGatewayProxyResultV2, Context, APIGatewayProxyEventV2WithLambdaAuthorizer } from 'aws-lambda';
|
|
2
2
|
export type SuccessCode = 200 | 201 | 204;
|
|
3
3
|
export type ErrorCode = 400 | 401 | 403 | 404 | 409 | 500;
|
|
4
4
|
export type ErrorBody = {
|
|
@@ -14,7 +14,7 @@ export type ErrorBody = {
|
|
|
14
14
|
export type ErrorRawProxyResultV2 = {
|
|
15
15
|
statusCode: ErrorCode;
|
|
16
16
|
headers?: {
|
|
17
|
-
[header: string]:
|
|
17
|
+
[header: string]: string;
|
|
18
18
|
} | undefined;
|
|
19
19
|
body?: ErrorBody;
|
|
20
20
|
isBase64Encoded?: boolean | undefined;
|
|
@@ -23,7 +23,7 @@ export type ErrorRawProxyResultV2 = {
|
|
|
23
23
|
export type OkRawProxyResultV2 = {
|
|
24
24
|
statusCode: SuccessCode;
|
|
25
25
|
headers?: {
|
|
26
|
-
[header: string]:
|
|
26
|
+
[header: string]: string;
|
|
27
27
|
} | undefined;
|
|
28
28
|
body?: object | undefined;
|
|
29
29
|
isBase64Encoded?: boolean | undefined;
|
|
@@ -34,7 +34,7 @@ export type OkRawProxyResultV2 = {
|
|
|
34
34
|
*/
|
|
35
35
|
export type RawProxyResultV2 = ErrorRawProxyResultV2 | OkRawProxyResultV2;
|
|
36
36
|
export type APIGatewayHandler<E> = (event: E, context: Context) => Promise<APIGatewayProxyResultV2>;
|
|
37
|
-
export type RawApiGatewayHandler<E
|
|
37
|
+
export type RawApiGatewayHandler<E extends APIGatewayProxyEventV2WithLambdaAuthorizer<any>> = (event: E, context: Context) => Promise<RawProxyResultV2>;
|
|
38
38
|
/**
|
|
39
39
|
* Wraps a handler that returns the body as an object rather than a string.
|
|
40
40
|
*
|
|
@@ -49,5 +49,5 @@ export type AuthorizerContext = {
|
|
|
49
49
|
export const wrapHandler = baseWrapHandler<APIGatewayProxyEventV2WithLambdaAuthorizer<AuthorizerContext>>
|
|
50
50
|
|
|
51
51
|
*/
|
|
52
|
-
export declare function wrapHandler<E
|
|
52
|
+
export declare function wrapHandler<E extends APIGatewayProxyEventV2WithLambdaAuthorizer<any>>(handler: RawApiGatewayHandler<E>): APIGatewayHandler<E>;
|
|
53
53
|
//# sourceMappingURL=handlerUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlerUtils.d.ts","sourceRoot":"","sources":["../../src/lambda/handlerUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"handlerUtils.d.ts","sourceRoot":"","sources":["../../src/lambda/handlerUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,OAAO,EAAE,0CAA0C,EAAE,MAAM,YAAY,CAAC;AAG/G,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAC1C,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAE1D,MAAM,MAAM,SAAS,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AAErF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACnD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,WAAW,CAAC;IACxB,OAAO,CAAC,EAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC;IACnD,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAChC,CAAC;AACF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,kBAAkB,CAAC;AAG1E,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAGpG,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,0CAA0C,CAAC,GAAG,CAAC,IAAI,CAC5F,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE/B;;;;;;;;;;;;;EAaE;AACF,wBAAgB,WAAW,CAAC,CAAC,SAAS,0CAA0C,CAAC,GAAG,CAAC,EACnF,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,iBAAiB,CAAC,CAAC,CAAC,CAatB"}
|
|
@@ -16,6 +16,13 @@ export const wrapHandler = baseWrapHandler<APIGatewayProxyEventV2WithLambdaAutho
|
|
|
16
16
|
export function wrapHandler(handler) {
|
|
17
17
|
return async (event, context) => {
|
|
18
18
|
const result = await handler(event, context);
|
|
19
|
-
|
|
19
|
+
if (result.body) {
|
|
20
|
+
const headers = new Headers(result.headers);
|
|
21
|
+
headers.set('Content-Type', 'application/devalue');
|
|
22
|
+
return { ...result, headers: Object.fromEntries(headers), body: stringify(result.body) };
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return { ...result, body: undefined };
|
|
26
|
+
}
|
|
20
27
|
};
|
|
21
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ag",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.29",
|
|
4
4
|
"description": "Useful TS stuff",
|
|
5
5
|
"bugs": "https://github.com/ageorgeh/ts-ag/issues",
|
|
6
6
|
"author": "Alexander Hornung",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"tsc:watch": "concurrently \" npx tsc -w \" \" npx ts-alias -w \""
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@aws-sdk/client-cognito-identity-provider": "3.
|
|
46
|
-
"@aws-sdk/client-s3": "3.
|
|
47
|
-
"@aws-sdk/s3-request-presigner": "3.
|
|
45
|
+
"@aws-sdk/client-cognito-identity-provider": "3.1003.0",
|
|
46
|
+
"@aws-sdk/client-s3": "3.1003.0",
|
|
47
|
+
"@aws-sdk/s3-request-presigner": "3.1003.0",
|
|
48
48
|
"@ungap/structured-clone": "1.3.0",
|
|
49
49
|
"chalk": "5.6.2",
|
|
50
50
|
"chokidar": "5.0.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"devalue": "^5.6.3",
|
|
55
55
|
"get-tsconfig": "^4.13.6",
|
|
56
56
|
"glob": "^13.0.6",
|
|
57
|
-
"jose": "6.
|
|
57
|
+
"jose": "6.2.0",
|
|
58
58
|
"neverthrow": "8.2.0",
|
|
59
59
|
"oxfmt": "^0.36.0",
|
|
60
60
|
"radash": "^12.1.1",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/hast": "3.0.4",
|
|
72
72
|
"@types/node": "^24.11.0",
|
|
73
73
|
"@types/ungap__structured-clone": "1.2.0",
|
|
74
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
74
|
+
"@typescript/native-preview": "7.0.0-dev.20260305.1",
|
|
75
75
|
"concurrently": "^9.2.1",
|
|
76
76
|
"globals": "^17.4.0",
|
|
77
77
|
"husky": "^9.1.7",
|
package/src/lambda/client.ts
CHANGED
|
@@ -50,13 +50,19 @@ async function _apiRequest<T = Response>(
|
|
|
50
50
|
body: bodyMethods.includes(method as any) ? JSON.stringify(input) : undefined,
|
|
51
51
|
credentials: 'include'
|
|
52
52
|
});
|
|
53
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
53
54
|
|
|
54
55
|
let retrieved: Promise<string> | false = false;
|
|
55
56
|
response.json = async () => {
|
|
56
57
|
if (retrieved === false) {
|
|
57
58
|
retrieved = response.text();
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
+
|
|
61
|
+
if (contentType === 'application/devalue') {
|
|
62
|
+
return await parse(await retrieved);
|
|
63
|
+
} else {
|
|
64
|
+
return JSON.parse(await retrieved);
|
|
65
|
+
}
|
|
60
66
|
};
|
|
61
67
|
return response as unknown as T;
|
|
62
68
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { APIGatewayProxyResultV2, Context } from 'aws-lambda';
|
|
1
|
+
import type { APIGatewayProxyResultV2, Context, APIGatewayProxyEventV2WithLambdaAuthorizer } from 'aws-lambda';
|
|
2
2
|
import { stringify } from 'devalue';
|
|
3
3
|
|
|
4
4
|
export type SuccessCode = 200 | 201 | 204;
|
|
@@ -11,7 +11,7 @@ export type ErrorBody = { message: string; field?: { name: string; value: string
|
|
|
11
11
|
*/
|
|
12
12
|
export type ErrorRawProxyResultV2 = {
|
|
13
13
|
statusCode: ErrorCode;
|
|
14
|
-
headers?: { [header: string]:
|
|
14
|
+
headers?: { [header: string]: string } | undefined;
|
|
15
15
|
body?: ErrorBody;
|
|
16
16
|
isBase64Encoded?: boolean | undefined;
|
|
17
17
|
cookies?: string[] | undefined;
|
|
@@ -19,7 +19,7 @@ export type ErrorRawProxyResultV2 = {
|
|
|
19
19
|
|
|
20
20
|
export type OkRawProxyResultV2 = {
|
|
21
21
|
statusCode: SuccessCode;
|
|
22
|
-
headers?: { [header: string]:
|
|
22
|
+
headers?: { [header: string]: string } | undefined;
|
|
23
23
|
body?: object | undefined;
|
|
24
24
|
isBase64Encoded?: boolean | undefined;
|
|
25
25
|
cookies?: string[] | undefined;
|
|
@@ -33,7 +33,10 @@ export type RawProxyResultV2 = ErrorRawProxyResultV2 | OkRawProxyResultV2;
|
|
|
33
33
|
export type APIGatewayHandler<E> = (event: E, context: Context) => Promise<APIGatewayProxyResultV2>;
|
|
34
34
|
|
|
35
35
|
// The type of the handler passed into wrapHandler
|
|
36
|
-
export type RawApiGatewayHandler<E
|
|
36
|
+
export type RawApiGatewayHandler<E extends APIGatewayProxyEventV2WithLambdaAuthorizer<any>> = (
|
|
37
|
+
event: E,
|
|
38
|
+
context: Context
|
|
39
|
+
) => Promise<RawProxyResultV2>;
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* Wraps a handler that returns the body as an object rather than a string.
|
|
@@ -49,9 +52,19 @@ export type AuthorizerContext = {
|
|
|
49
52
|
export const wrapHandler = baseWrapHandler<APIGatewayProxyEventV2WithLambdaAuthorizer<AuthorizerContext>>
|
|
50
53
|
|
|
51
54
|
*/
|
|
52
|
-
export function wrapHandler<E
|
|
55
|
+
export function wrapHandler<E extends APIGatewayProxyEventV2WithLambdaAuthorizer<any>>(
|
|
56
|
+
handler: RawApiGatewayHandler<E>
|
|
57
|
+
): APIGatewayHandler<E> {
|
|
53
58
|
return async (event: E, context: Context): Promise<APIGatewayProxyResultV2> => {
|
|
54
59
|
const result = await handler(event, context);
|
|
55
|
-
|
|
60
|
+
|
|
61
|
+
if (result.body) {
|
|
62
|
+
const headers = new Headers(result.headers);
|
|
63
|
+
headers.set('Content-Type', 'application/devalue');
|
|
64
|
+
|
|
65
|
+
return { ...result, headers: Object.fromEntries(headers), body: stringify(result.body) };
|
|
66
|
+
} else {
|
|
67
|
+
return { ...result, body: undefined };
|
|
68
|
+
}
|
|
56
69
|
};
|
|
57
70
|
}
|
|
@@ -15,7 +15,7 @@ describe('wrapHandler', () => {
|
|
|
15
15
|
const response = await wrapped({} as never, {} as never);
|
|
16
16
|
|
|
17
17
|
expect(response.statusCode).toBe(200);
|
|
18
|
-
expect(response.headers).toEqual({ 'content-type': 'application/
|
|
18
|
+
expect(response.headers).toEqual({ 'content-type': 'application/devalue' });
|
|
19
19
|
expect(response.cookies).toEqual(['a=1']);
|
|
20
20
|
expect(typeof response.body).toBe('string');
|
|
21
21
|
expect(parse(response.body as string)).toEqual({ ok: true, nested: { value: 123 } });
|