@trpc/server 9.25.0 → 9.25.3
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/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.d.ts +1 -1
- package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.dev.js +100 -20
- package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.prod.js +100 -20
- package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.esm.js +99 -19
- package/adapters/aws-lambda/package.json +4 -0
- package/adapters/lambda/dist/trpc-server-adapters-lambda.cjs.dev.js +12 -157
- package/adapters/lambda/dist/trpc-server-adapters-lambda.cjs.prod.js +12 -157
- package/adapters/lambda/dist/trpc-server-adapters-lambda.esm.js +12 -157
- package/dist/declarations/src/TRPCError.d.ts.map +1 -1
- package/dist/declarations/src/adapters/aws-lambda/index.d.ts +14 -0
- package/dist/declarations/src/adapters/aws-lambda/index.d.ts.map +1 -0
- package/dist/declarations/src/adapters/{lambda → aws-lambda}/utils.d.ts +4 -4
- package/dist/declarations/src/adapters/aws-lambda/utils.d.ts.map +1 -0
- package/dist/declarations/src/adapters/lambda/index.d.ts +11 -13
- package/dist/declarations/src/adapters/lambda/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/TRPCError.ts +3 -1
- package/src/adapters/aws-lambda/index.ts +156 -0
- package/src/adapters/{lambda → aws-lambda}/utils.ts +5 -5
- package/src/adapters/lambda/index.ts +17 -155
- package/dist/declarations/src/adapters/lambda/utils.d.ts.map +0 -1
|
@@ -2,169 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var adapters_awsLambda_dist_trpcServerAdaptersAwsLambda = require('../../aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.prod.js');
|
|
5
6
|
require('../../../dist/router-459409c8.cjs.prod.js');
|
|
7
|
+
require('../../../dist/resolveHTTPResponse-02e61299.cjs.prod.js');
|
|
8
|
+
require('../../../dist/transformTRPCResponse-1e125b28.cjs.prod.js');
|
|
9
|
+
require('../../../dist/codes-aff770a3.cjs.prod.js');
|
|
6
10
|
require('events');
|
|
7
|
-
var transformTRPCResponse = require('../../../dist/transformTRPCResponse-1e125b28.cjs.prod.js');
|
|
8
11
|
require('http');
|
|
9
12
|
require('url');
|
|
10
13
|
require('../../../dist/nodeHTTPRequestHandler-91e7ca3d.cjs.prod.js');
|
|
11
|
-
var resolveHTTPResponse = require('../../../dist/resolveHTTPResponse-02e61299.cjs.prod.js');
|
|
12
|
-
require('../../../dist/codes-aff770a3.cjs.prod.js');
|
|
13
|
-
|
|
14
|
-
function isPayloadV1(event) {
|
|
15
|
-
return determinePayloadFormat(event) == '1.0';
|
|
16
|
-
}
|
|
17
|
-
function isPayloadV2(event) {
|
|
18
|
-
return determinePayloadFormat(event) == '2.0';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function determinePayloadFormat(event) {
|
|
22
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
23
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
24
|
-
// If there is no version property, then the version is implied as 1.0
|
|
25
|
-
const unknownEvent = event;
|
|
26
|
-
|
|
27
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
28
|
-
return '1.0';
|
|
29
|
-
} else {
|
|
30
|
-
if (['1.0', '2.0'].includes(unknownEvent.version)) {
|
|
31
|
-
return unknownEvent.version;
|
|
32
|
-
} else {
|
|
33
|
-
return 'custom';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
39
|
-
|
|
40
|
-
function lambdaEventToHTTPRequest(event) {
|
|
41
|
-
const query = new URLSearchParams();
|
|
42
|
-
|
|
43
|
-
for (const [key, value] of Object.entries((_event$queryStringPar = event.queryStringParameters) !== null && _event$queryStringPar !== void 0 ? _event$queryStringPar : {})) {
|
|
44
|
-
var _event$queryStringPar;
|
|
45
|
-
|
|
46
|
-
if (typeof value !== 'undefined') {
|
|
47
|
-
query.append(key, value);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
method: getHTTPMethod(event),
|
|
53
|
-
query: query,
|
|
54
|
-
headers: event.headers,
|
|
55
|
-
body: event.body
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getHTTPMethod(event) {
|
|
60
|
-
if (isPayloadV1(event)) {
|
|
61
|
-
return event.httpMethod;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (isPayloadV2(event)) {
|
|
65
|
-
return event.requestContext.http.method;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
throw new transformTRPCResponse.TRPCError({
|
|
69
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
70
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getPath(event) {
|
|
75
|
-
if (isPayloadV1(event)) {
|
|
76
|
-
return event.path.slice(1);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (isPayloadV2(event)) {
|
|
80
|
-
return event.rawPath.slice(1);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
throw new transformTRPCResponse.TRPCError({
|
|
84
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
85
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function transformHeaders(headers) {
|
|
90
|
-
const obj = {};
|
|
91
|
-
|
|
92
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
93
|
-
if (typeof value === 'undefined') {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return obj;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function tRPCOutputToAPIGatewayOutput(event, response) {
|
|
104
|
-
if (isPayloadV1(event)) {
|
|
105
|
-
var _response$body, _response$headers;
|
|
106
|
-
|
|
107
|
-
const resp = {
|
|
108
|
-
statusCode: response.status,
|
|
109
|
-
body: (_response$body = response.body) !== null && _response$body !== void 0 ? _response$body : '',
|
|
110
|
-
headers: transformHeaders((_response$headers = response.headers) !== null && _response$headers !== void 0 ? _response$headers : {})
|
|
111
|
-
};
|
|
112
|
-
return resp;
|
|
113
|
-
} else if (isPayloadV2(event)) {
|
|
114
|
-
var _response$body2, _response$headers2;
|
|
115
|
-
|
|
116
|
-
const resp = {
|
|
117
|
-
statusCode: response.status,
|
|
118
|
-
body: (_response$body2 = response.body) !== null && _response$body2 !== void 0 ? _response$body2 : undefined,
|
|
119
|
-
headers: transformHeaders((_response$headers2 = response.headers) !== null && _response$headers2 !== void 0 ? _response$headers2 : {})
|
|
120
|
-
};
|
|
121
|
-
return resp;
|
|
122
|
-
} else {
|
|
123
|
-
throw new transformTRPCResponse.TRPCError({
|
|
124
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
125
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/** Will check the createContext of the TRouter and get the parameter of event.
|
|
130
|
-
* @internal
|
|
131
|
-
**/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
function lambdaRequestHandler(opts) {
|
|
135
|
-
return async (event, context) => {
|
|
136
|
-
const req = lambdaEventToHTTPRequest(event);
|
|
137
|
-
const path = getPath(event);
|
|
138
|
-
|
|
139
|
-
const createContext = async function _createContext() {
|
|
140
|
-
var _opts$createContext;
|
|
141
|
-
|
|
142
|
-
return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, {
|
|
143
|
-
event,
|
|
144
|
-
context
|
|
145
|
-
}));
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
const response = await resolveHTTPResponse.resolveHTTPResponse({
|
|
149
|
-
router: opts.router,
|
|
150
|
-
batching: opts.batching,
|
|
151
|
-
responseMeta: opts === null || opts === void 0 ? void 0 : opts.responseMeta,
|
|
152
|
-
createContext,
|
|
153
|
-
req,
|
|
154
|
-
path,
|
|
155
|
-
error: null,
|
|
156
|
-
|
|
157
|
-
onError(o) {
|
|
158
|
-
var _opts$onError;
|
|
159
14
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated use `aws-lambda` instead
|
|
17
|
+
*/
|
|
164
18
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated use `aws-lambda` instead
|
|
21
|
+
*/
|
|
22
|
+
const lambdaRequestHandler = adapters_awsLambda_dist_trpcServerAdaptersAwsLambda.awsLambdaRequestHandler;
|
|
169
23
|
|
|
24
|
+
exports.awsLambdaRequestHandler = adapters_awsLambda_dist_trpcServerAdaptersAwsLambda.awsLambdaRequestHandler;
|
|
170
25
|
exports.lambdaRequestHandler = lambdaRequestHandler;
|
|
@@ -1,166 +1,21 @@
|
|
|
1
|
+
import { awsLambdaRequestHandler } from '../../aws-lambda/dist/trpc-server-adapters-aws-lambda.esm.js';
|
|
2
|
+
export { awsLambdaRequestHandler } from '../../aws-lambda/dist/trpc-server-adapters-aws-lambda.esm.js';
|
|
1
3
|
import '../../../dist/router-93491dae.esm.js';
|
|
4
|
+
import '../../../dist/resolveHTTPResponse-ddb56677.esm.js';
|
|
5
|
+
import '../../../dist/transformTRPCResponse-45c225c3.esm.js';
|
|
6
|
+
import '../../../dist/codes-5678cc97.esm.js';
|
|
2
7
|
import 'events';
|
|
3
|
-
import { T as TRPCError } from '../../../dist/transformTRPCResponse-45c225c3.esm.js';
|
|
4
8
|
import 'http';
|
|
5
9
|
import 'url';
|
|
6
10
|
import '../../../dist/nodeHTTPRequestHandler-372a4a4f.esm.js';
|
|
7
|
-
import { r as resolveHTTPResponse } from '../../../dist/resolveHTTPResponse-ddb56677.esm.js';
|
|
8
|
-
import '../../../dist/codes-5678cc97.esm.js';
|
|
9
|
-
|
|
10
|
-
function isPayloadV1(event) {
|
|
11
|
-
return determinePayloadFormat(event) == '1.0';
|
|
12
|
-
}
|
|
13
|
-
function isPayloadV2(event) {
|
|
14
|
-
return determinePayloadFormat(event) == '2.0';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function determinePayloadFormat(event) {
|
|
18
|
-
// https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
|
|
19
|
-
// According to AWS support, version is is extracted from the version property in the event.
|
|
20
|
-
// If there is no version property, then the version is implied as 1.0
|
|
21
|
-
const unknownEvent = event;
|
|
22
|
-
|
|
23
|
-
if (typeof unknownEvent.version === 'undefined') {
|
|
24
|
-
return '1.0';
|
|
25
|
-
} else {
|
|
26
|
-
if (['1.0', '2.0'].includes(unknownEvent.version)) {
|
|
27
|
-
return unknownEvent.version;
|
|
28
|
-
} else {
|
|
29
|
-
return 'custom';
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = 'Custom payload format version not handled by this adapter. Please use either 1.0 or 2.0. More information here' + 'https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html';
|
|
35
|
-
|
|
36
|
-
function lambdaEventToHTTPRequest(event) {
|
|
37
|
-
const query = new URLSearchParams();
|
|
38
|
-
|
|
39
|
-
for (const [key, value] of Object.entries((_event$queryStringPar = event.queryStringParameters) !== null && _event$queryStringPar !== void 0 ? _event$queryStringPar : {})) {
|
|
40
|
-
var _event$queryStringPar;
|
|
41
|
-
|
|
42
|
-
if (typeof value !== 'undefined') {
|
|
43
|
-
query.append(key, value);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
method: getHTTPMethod(event),
|
|
49
|
-
query: query,
|
|
50
|
-
headers: event.headers,
|
|
51
|
-
body: event.body
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getHTTPMethod(event) {
|
|
56
|
-
if (isPayloadV1(event)) {
|
|
57
|
-
return event.httpMethod;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (isPayloadV2(event)) {
|
|
61
|
-
return event.requestContext.http.method;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
throw new TRPCError({
|
|
65
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
66
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function getPath(event) {
|
|
71
|
-
if (isPayloadV1(event)) {
|
|
72
|
-
return event.path.slice(1);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (isPayloadV2(event)) {
|
|
76
|
-
return event.rawPath.slice(1);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
throw new TRPCError({
|
|
80
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
81
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function transformHeaders(headers) {
|
|
86
|
-
const obj = {};
|
|
87
|
-
|
|
88
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
89
|
-
if (typeof value === 'undefined') {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return obj;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function tRPCOutputToAPIGatewayOutput(event, response) {
|
|
100
|
-
if (isPayloadV1(event)) {
|
|
101
|
-
var _response$body, _response$headers;
|
|
102
|
-
|
|
103
|
-
const resp = {
|
|
104
|
-
statusCode: response.status,
|
|
105
|
-
body: (_response$body = response.body) !== null && _response$body !== void 0 ? _response$body : '',
|
|
106
|
-
headers: transformHeaders((_response$headers = response.headers) !== null && _response$headers !== void 0 ? _response$headers : {})
|
|
107
|
-
};
|
|
108
|
-
return resp;
|
|
109
|
-
} else if (isPayloadV2(event)) {
|
|
110
|
-
var _response$body2, _response$headers2;
|
|
111
|
-
|
|
112
|
-
const resp = {
|
|
113
|
-
statusCode: response.status,
|
|
114
|
-
body: (_response$body2 = response.body) !== null && _response$body2 !== void 0 ? _response$body2 : undefined,
|
|
115
|
-
headers: transformHeaders((_response$headers2 = response.headers) !== null && _response$headers2 !== void 0 ? _response$headers2 : {})
|
|
116
|
-
};
|
|
117
|
-
return resp;
|
|
118
|
-
} else {
|
|
119
|
-
throw new TRPCError({
|
|
120
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
121
|
-
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/** Will check the createContext of the TRouter and get the parameter of event.
|
|
126
|
-
* @internal
|
|
127
|
-
**/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function lambdaRequestHandler(opts) {
|
|
131
|
-
return async (event, context) => {
|
|
132
|
-
const req = lambdaEventToHTTPRequest(event);
|
|
133
|
-
const path = getPath(event);
|
|
134
|
-
|
|
135
|
-
const createContext = async function _createContext() {
|
|
136
|
-
var _opts$createContext;
|
|
137
|
-
|
|
138
|
-
return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, {
|
|
139
|
-
event,
|
|
140
|
-
context
|
|
141
|
-
}));
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const response = await resolveHTTPResponse({
|
|
145
|
-
router: opts.router,
|
|
146
|
-
batching: opts.batching,
|
|
147
|
-
responseMeta: opts === null || opts === void 0 ? void 0 : opts.responseMeta,
|
|
148
|
-
createContext,
|
|
149
|
-
req,
|
|
150
|
-
path,
|
|
151
|
-
error: null,
|
|
152
|
-
|
|
153
|
-
onError(o) {
|
|
154
|
-
var _opts$onError;
|
|
155
11
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated use `aws-lambda` instead
|
|
14
|
+
*/
|
|
160
15
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated use `aws-lambda` instead
|
|
18
|
+
*/
|
|
19
|
+
const lambdaRequestHandler = awsLambdaRequestHandler;
|
|
165
20
|
|
|
166
21
|
export { lambdaRequestHandler };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCError.d.ts","sourceRoot":"../../../src","sources":["TRPCError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,qBAAa,SAAU,SAAQ,KAAK;IAClC;;OAEG;IACH,SAAgB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxC,SAAgB,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"TRPCError.d.ts","sourceRoot":"../../../src","sources":["TRPCError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,qBAAa,SAAU,SAAQ,KAAK;IAClC;;OAEG;IACH,SAAgB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxC,SAAgB,KAAK,CAAC,UAAC;IACvB,SAAgB,IAAI,iOAAC;gBAET,IAAI,EAAE;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,mBAAmB,CAAC;QAC1B;;WAEG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QAGxB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAeF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context as APIGWContext, APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2 } from 'aws-lambda';
|
|
2
|
+
import { AnyRouter } from '../../router';
|
|
3
|
+
import { APIGatewayEvent, AWSLambdaOptions } from './utils';
|
|
4
|
+
export type { CreateAWSLambdaContextOptions, AWSLambdaOptions } from './utils';
|
|
5
|
+
/** Will check the createContext of the TRouter and get the parameter of event.
|
|
6
|
+
* @internal
|
|
7
|
+
**/
|
|
8
|
+
declare type inferAPIGWEvent<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = AWSLambdaOptions<TRouter, TEvent>['createContext'] extends NonNullable<AWSLambdaOptions<TRouter, TEvent>['createContext']> ? Parameters<AWSLambdaOptions<TRouter, TEvent>['createContext']>[0]['event'] : APIGatewayEvent;
|
|
9
|
+
/** 1:1 mapping of v1 or v2 input events, deduces which is which.
|
|
10
|
+
* @internal
|
|
11
|
+
**/
|
|
12
|
+
declare type inferAPIGWReturn<T> = T extends APIGatewayProxyEvent ? APIGatewayProxyResult : T extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
|
|
13
|
+
export declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends inferAPIGWEvent<TRouter, TEvent>, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: APIGWContext) => Promise<TResult>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts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 -3,11 +3,11 @@ import type { ResponseMetaFn } from '../../http/internals/types';
|
|
|
3
3
|
import type { AnyRouter, inferRouterContext } from '../../router';
|
|
4
4
|
export declare type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
|
|
5
5
|
export declare type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
|
|
6
|
-
export declare type
|
|
6
|
+
export declare type CreateAWSLambdaContextOptions<T extends APIGatewayEvent> = {
|
|
7
7
|
event: T;
|
|
8
8
|
context: APIGWContext;
|
|
9
9
|
};
|
|
10
|
-
export declare type
|
|
10
|
+
export declare type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
11
11
|
export declare type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({
|
|
12
12
|
router: TRouter;
|
|
13
13
|
batching?: {
|
|
@@ -19,12 +19,12 @@ export declare type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends A
|
|
|
19
19
|
/**
|
|
20
20
|
* @link https://trpc.io/docs/context
|
|
21
21
|
**/
|
|
22
|
-
createContext:
|
|
22
|
+
createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
23
23
|
} | {
|
|
24
24
|
/**
|
|
25
25
|
* @link https://trpc.io/docs/context
|
|
26
26
|
**/
|
|
27
|
-
createContext?:
|
|
27
|
+
createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
|
|
28
28
|
}));
|
|
29
29
|
export declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
|
|
30
30
|
export declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"../../../../../src/adapters/aws-lambda","sources":["utils.ts"],"names":[],"mappings":"AA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,CACJ,CAAA,CAAC;AAEN,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,oBAAoB,CAE/B;AACD,wBAAgB,WAAW,CACzB,KAAK,EAAE,eAAe,GACrB,KAAK,IAAI,sBAAsB,CAEjC;AAmBD,oBAAY,+BAA+B,GAAG,KAAK,GAAG,KAAK,CAAC;AAC5D,oBAAY,8BAA8B,GACtC,+BAA+B,GAC/B,QAAQ,CAAC;AAEb,eAAO,MAAM,4CAA4C,QAEiD,CAAC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
declare type inferAPIGWReturn<T> = T extends APIGatewayProxyEvent ? APIGatewayProxyResult : T extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
|
|
13
|
-
export declare function lambdaRequestHandler<TRouter extends AnyRouter, TEvent extends inferAPIGWEvent<TRouter, TEvent>, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: APIGWContext) => Promise<TResult>;
|
|
1
|
+
import { CreateAWSLambdaContextOptions, awsLambdaRequestHandler } from '../aws-lambda';
|
|
2
|
+
import { APIGatewayEvent } from '../aws-lambda/utils';
|
|
3
|
+
export * from '../aws-lambda';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use `aws-lambda` instead
|
|
6
|
+
*/
|
|
7
|
+
export declare type CreateLambdaContextOptions<T extends APIGatewayEvent> = CreateAWSLambdaContextOptions<T>;
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated use `aws-lambda` instead
|
|
10
|
+
*/
|
|
11
|
+
export declare const lambdaRequestHandler: typeof awsLambdaRequestHandler;
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/adapters/lambda","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../../src/adapters/lambda","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,cAAc,eAAe,CAAC;AAE9B;;GAEG;AACH,oBAAY,0BAA0B,CAAC,CAAC,SAAS,eAAe,IAC9D,6BAA6B,CAAC,CAAC,CAAC,CAAC;AAEnC;;GAEG;AACH,eAAO,MAAM,oBAAoB,gCAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/server",
|
|
3
|
-
"version": "9.25.
|
|
3
|
+
"version": "9.25.3",
|
|
4
4
|
"description": "tRPC Server",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"adapters/standalone.ts",
|
|
26
26
|
"adapters/ws.ts",
|
|
27
27
|
"adapters/lambda/index.ts",
|
|
28
|
+
"adapters/aws-lambda/index.ts",
|
|
28
29
|
"ws/index.ts",
|
|
29
30
|
"rpc/index.ts"
|
|
30
31
|
]
|
|
@@ -69,5 +70,5 @@
|
|
|
69
70
|
"yup": "^0.32.8",
|
|
70
71
|
"zod": "^3.0.0"
|
|
71
72
|
},
|
|
72
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "0bb99b3eddb54ec411a37a5ba9cfc18a3be19d4d"
|
|
73
74
|
}
|
package/src/TRPCError.ts
CHANGED
|
@@ -6,7 +6,7 @@ export class TRPCError extends Error {
|
|
|
6
6
|
* @deprecated use `cause`
|
|
7
7
|
*/
|
|
8
8
|
public readonly originalError?: unknown;
|
|
9
|
-
public readonly cause
|
|
9
|
+
public readonly cause?;
|
|
10
10
|
public readonly code;
|
|
11
11
|
|
|
12
12
|
constructor(opts: {
|
|
@@ -16,6 +16,8 @@ export class TRPCError extends Error {
|
|
|
16
16
|
* @deprecated use `cause`
|
|
17
17
|
*/
|
|
18
18
|
originalError?: unknown;
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
20
|
+
// @ts-ignore This will be `Error` in next major version
|
|
19
21
|
cause?: unknown;
|
|
20
22
|
}) {
|
|
21
23
|
const cause = opts.cause ?? opts.originalError;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Context as APIGWContext,
|
|
3
|
+
APIGatewayProxyEvent,
|
|
4
|
+
APIGatewayProxyEventV2,
|
|
5
|
+
APIGatewayProxyResult,
|
|
6
|
+
APIGatewayProxyStructuredResultV2,
|
|
7
|
+
} from 'aws-lambda';
|
|
8
|
+
import { TRPCError, resolveHTTPResponse } from '../..';
|
|
9
|
+
import { HTTPHeaders, HTTPRequest } from '../../http/internals/types';
|
|
10
|
+
import type { HTTPResponse } from '../../http/internals/types';
|
|
11
|
+
import { AnyRouter, inferRouterContext } from '../../router';
|
|
12
|
+
import {
|
|
13
|
+
APIGatewayEvent,
|
|
14
|
+
APIGatewayResult,
|
|
15
|
+
AWSLambdaOptions,
|
|
16
|
+
UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
17
|
+
isPayloadV1,
|
|
18
|
+
isPayloadV2,
|
|
19
|
+
} from './utils';
|
|
20
|
+
|
|
21
|
+
export type { CreateAWSLambdaContextOptions, AWSLambdaOptions } from './utils';
|
|
22
|
+
|
|
23
|
+
function lambdaEventToHTTPRequest(event: APIGatewayEvent): HTTPRequest {
|
|
24
|
+
const query = new URLSearchParams();
|
|
25
|
+
for (const [key, value] of Object.entries(
|
|
26
|
+
event.queryStringParameters ?? {},
|
|
27
|
+
)) {
|
|
28
|
+
if (typeof value !== 'undefined') {
|
|
29
|
+
query.append(key, value);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
method: getHTTPMethod(event),
|
|
35
|
+
query: query,
|
|
36
|
+
headers: event.headers,
|
|
37
|
+
body: event.body,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getHTTPMethod(event: APIGatewayEvent) {
|
|
42
|
+
if (isPayloadV1(event)) {
|
|
43
|
+
return event.httpMethod;
|
|
44
|
+
}
|
|
45
|
+
if (isPayloadV2(event)) {
|
|
46
|
+
return event.requestContext.http.method;
|
|
47
|
+
}
|
|
48
|
+
throw new TRPCError({
|
|
49
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
50
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function getPath(event: APIGatewayEvent) {
|
|
54
|
+
if (isPayloadV1(event)) {
|
|
55
|
+
return event.path.slice(1);
|
|
56
|
+
}
|
|
57
|
+
if (isPayloadV2(event)) {
|
|
58
|
+
return event.rawPath.slice(1);
|
|
59
|
+
}
|
|
60
|
+
throw new TRPCError({
|
|
61
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
62
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'] {
|
|
66
|
+
const obj: APIGatewayResult['headers'] = {};
|
|
67
|
+
|
|
68
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
69
|
+
if (typeof value === 'undefined') {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
obj[key] = Array.isArray(value) ? value.join(',') : value;
|
|
73
|
+
}
|
|
74
|
+
return obj;
|
|
75
|
+
}
|
|
76
|
+
function tRPCOutputToAPIGatewayOutput<
|
|
77
|
+
TEvent extends APIGatewayEvent,
|
|
78
|
+
TResult extends APIGatewayResult,
|
|
79
|
+
>(event: TEvent, response: HTTPResponse): TResult {
|
|
80
|
+
if (isPayloadV1(event)) {
|
|
81
|
+
const resp: APIGatewayProxyResult = {
|
|
82
|
+
statusCode: response.status,
|
|
83
|
+
body: response.body ?? '',
|
|
84
|
+
headers: transformHeaders(response.headers ?? {}),
|
|
85
|
+
};
|
|
86
|
+
return resp as TResult;
|
|
87
|
+
} else if (isPayloadV2(event)) {
|
|
88
|
+
const resp: APIGatewayProxyStructuredResultV2 = {
|
|
89
|
+
statusCode: response.status,
|
|
90
|
+
body: response.body ?? undefined,
|
|
91
|
+
headers: transformHeaders(response.headers ?? {}),
|
|
92
|
+
};
|
|
93
|
+
return resp as TResult;
|
|
94
|
+
} else {
|
|
95
|
+
throw new TRPCError({
|
|
96
|
+
code: 'INTERNAL_SERVER_ERROR',
|
|
97
|
+
message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Will check the createContext of the TRouter and get the parameter of event.
|
|
103
|
+
* @internal
|
|
104
|
+
**/
|
|
105
|
+
type inferAPIGWEvent<
|
|
106
|
+
TRouter extends AnyRouter,
|
|
107
|
+
TEvent extends APIGatewayEvent,
|
|
108
|
+
> = AWSLambdaOptions<TRouter, TEvent>['createContext'] extends NonNullable<
|
|
109
|
+
AWSLambdaOptions<TRouter, TEvent>['createContext']
|
|
110
|
+
>
|
|
111
|
+
? Parameters<AWSLambdaOptions<TRouter, TEvent>['createContext']>[0]['event']
|
|
112
|
+
: APIGatewayEvent;
|
|
113
|
+
|
|
114
|
+
/** 1:1 mapping of v1 or v2 input events, deduces which is which.
|
|
115
|
+
* @internal
|
|
116
|
+
**/
|
|
117
|
+
type inferAPIGWReturn<T> = T extends APIGatewayProxyEvent
|
|
118
|
+
? APIGatewayProxyResult
|
|
119
|
+
: T extends APIGatewayProxyEventV2
|
|
120
|
+
? APIGatewayProxyStructuredResultV2
|
|
121
|
+
: never;
|
|
122
|
+
export function awsLambdaRequestHandler<
|
|
123
|
+
TRouter extends AnyRouter,
|
|
124
|
+
TEvent extends inferAPIGWEvent<TRouter, TEvent>,
|
|
125
|
+
TResult extends inferAPIGWReturn<TEvent>,
|
|
126
|
+
>(
|
|
127
|
+
opts: AWSLambdaOptions<TRouter, TEvent>,
|
|
128
|
+
): (event: TEvent, context: APIGWContext) => Promise<TResult> {
|
|
129
|
+
return async (event, context) => {
|
|
130
|
+
const req = lambdaEventToHTTPRequest(event);
|
|
131
|
+
const path = getPath(event);
|
|
132
|
+
const createContext = async function _createContext(): Promise<
|
|
133
|
+
inferRouterContext<TRouter>
|
|
134
|
+
> {
|
|
135
|
+
return await opts.createContext?.({ event, context });
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const response = await resolveHTTPResponse({
|
|
139
|
+
router: opts.router,
|
|
140
|
+
batching: opts.batching,
|
|
141
|
+
responseMeta: opts?.responseMeta,
|
|
142
|
+
createContext,
|
|
143
|
+
req,
|
|
144
|
+
path,
|
|
145
|
+
error: null,
|
|
146
|
+
onError(o) {
|
|
147
|
+
opts?.onError?.({
|
|
148
|
+
...o,
|
|
149
|
+
req: event,
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return tRPCOutputToAPIGatewayOutput<TEvent, TResult>(event, response);
|
|
155
|
+
};
|
|
156
|
+
}
|