@trpc/server 10.11.1 → 10.13.0

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.
Files changed (75) hide show
  1. package/dist/TRPCError-ef1ceb74.js +55 -0
  2. package/dist/adapters/aws-lambda/index.js +2 -2
  3. package/dist/adapters/aws-lambda/index.mjs +2 -2
  4. package/dist/adapters/express.js +3 -3
  5. package/dist/adapters/express.mjs +3 -3
  6. package/dist/adapters/fastify/index.js +3 -3
  7. package/dist/adapters/fastify/index.mjs +3 -3
  8. package/dist/adapters/fetch/index.js +3 -3
  9. package/dist/adapters/fetch/index.mjs +3 -3
  10. package/dist/adapters/next.js +3 -3
  11. package/dist/adapters/next.mjs +3 -3
  12. package/dist/adapters/node-http/index.js +3 -3
  13. package/dist/adapters/node-http/index.mjs +3 -3
  14. package/dist/adapters/standalone.js +3 -3
  15. package/dist/adapters/standalone.mjs +3 -3
  16. package/dist/adapters/ws.js +10 -10
  17. package/dist/adapters/ws.mjs +10 -10
  18. package/dist/codes-ec2bad91.js +45 -0
  19. package/dist/{config-d356ff77.js → config-cc5b2d45.js} +1 -1
  20. package/dist/{config-4ca0221b.mjs → config-cd794c2a.mjs} +1 -1
  21. package/dist/config-e8f70019.js +225 -0
  22. package/dist/core/index.d.ts +1 -0
  23. package/dist/core/index.d.ts.map +1 -1
  24. package/dist/core/internals/config.d.ts +4 -1
  25. package/dist/core/internals/config.d.ts.map +1 -1
  26. package/dist/core/internals/procedureBuilder.d.ts +3 -6
  27. package/dist/core/internals/procedureBuilder.d.ts.map +1 -1
  28. package/dist/error/TRPCError.d.ts +1 -1
  29. package/dist/http/index.js +2 -2
  30. package/dist/http/index.mjs +2 -2
  31. package/dist/http/resolveHTTPResponse.d.ts.map +1 -1
  32. package/dist/index-f38f12ba.js +47 -0
  33. package/dist/index.js +1 -1
  34. package/dist/index.mjs +2 -2
  35. package/dist/internals.d.ts +2 -3
  36. package/dist/internals.d.ts.map +1 -1
  37. package/dist/{nodeHTTPRequestHandler-34404221.mjs → nodeHTTPRequestHandler-85d2b636.mjs} +1 -1
  38. package/dist/{nodeHTTPRequestHandler-64cf5f55.js → nodeHTTPRequestHandler-a649e036.js} +1 -1
  39. package/dist/nodeHTTPRequestHandler-fa0b13d4.js +76 -0
  40. package/dist/observable-a1c2103f.js +83 -0
  41. package/dist/{resolveHTTPResponse-3408bbf7.js → resolveHTTPResponse-6cffb0ce.js} +4 -3
  42. package/dist/{resolveHTTPResponse-b831e644.mjs → resolveHTTPResponse-7a4f75b3.mjs} +4 -3
  43. package/dist/resolveHTTPResponse-fed650e4.js +205 -0
  44. package/dist/subscription.js +3 -3
  45. package/dist/subscription.mjs +3 -3
  46. package/dist/transformTRPCResponse-896669e0.js +28 -0
  47. package/dist/transformer.d.ts +35 -8
  48. package/dist/transformer.d.ts.map +1 -1
  49. package/package.json +10 -14
  50. package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
  51. package/src/adapters/fetch/fetchRequestHandler.ts +1 -1
  52. package/src/adapters/ws.ts +9 -9
  53. package/src/core/index.ts +1 -0
  54. package/src/core/internals/config.ts +7 -2
  55. package/src/core/internals/procedureBuilder.ts +9 -20
  56. package/src/http/resolveHTTPResponse.ts +3 -2
  57. package/src/internals.ts +2 -3
  58. package/src/observable/observable.test.ts +15 -15
  59. package/src/observable/operators/map.test.ts +2 -2
  60. package/src/observable/operators/share.test.ts +9 -9
  61. package/src/subscription.ts +3 -3
  62. package/src/transformer.ts +36 -8
  63. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.d.ts +0 -1
  64. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.dev.js +0 -190
  65. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.js +0 -7
  66. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.cjs.prod.js +0 -190
  67. package/adapters/aws-lambda/dist/trpc-server-adapters-aws-lambda.esm.js +0 -186
  68. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.d.ts +0 -1
  69. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.dev.js +0 -109
  70. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.js +0 -7
  71. package/adapters/fastify/dist/trpc-server-adapters-fastify.cjs.prod.js +0 -109
  72. package/adapters/fastify/dist/trpc-server-adapters-fastify.esm.js +0 -104
  73. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts +0 -202
  74. package/dist/core/internals/__generated__/mergeRoutersGeneric.d.ts.map +0 -1
  75. package/src/core/internals/__generated__/mergeRoutersGeneric.ts +0 -306
@@ -6,9 +6,9 @@ test('vanilla observable - complete()', () => {
6
6
  observer.complete();
7
7
  });
8
8
 
9
- const next = jest.fn();
10
- const error = jest.fn();
11
- const complete = jest.fn();
9
+ const next = vi.fn();
10
+ const error = vi.fn();
11
+ const complete = vi.fn();
12
12
  obs.subscribe({
13
13
  next,
14
14
  error,
@@ -25,9 +25,9 @@ test('vanilla observable - unsubscribe()', () => {
25
25
  observer.next(1);
26
26
  });
27
27
 
28
- const next = jest.fn();
29
- const error = jest.fn();
30
- const complete = jest.fn();
28
+ const next = vi.fn();
29
+ const error = vi.fn();
30
+ const complete = vi.fn();
31
31
  const sub = obs$.subscribe({
32
32
  next,
33
33
  error,
@@ -42,9 +42,9 @@ test('vanilla observable - unsubscribe()', () => {
42
42
 
43
43
  test('pipe - combine operators', () => {
44
44
  const taps = {
45
- next: jest.fn(),
46
- complete: jest.fn(),
47
- error: jest.fn(),
45
+ next: vi.fn(),
46
+ complete: vi.fn(),
47
+ error: vi.fn(),
48
48
  };
49
49
  const obs = observable<number, Error>((observer) => {
50
50
  observer.next(1);
@@ -54,9 +54,9 @@ test('pipe - combine operators', () => {
54
54
  tap(taps),
55
55
  );
56
56
  {
57
- const next = jest.fn();
58
- const error = jest.fn();
59
- const complete = jest.fn();
57
+ const next = vi.fn();
58
+ const error = vi.fn();
59
+ const complete = vi.fn();
60
60
  obs.subscribe({
61
61
  next,
62
62
  error,
@@ -69,9 +69,9 @@ test('pipe - combine operators', () => {
69
69
  }
70
70
 
71
71
  {
72
- const next = jest.fn();
73
- const error = jest.fn();
74
- const complete = jest.fn();
72
+ const next = vi.fn();
73
+ const error = vi.fn();
74
+ const complete = vi.fn();
75
75
  obs.subscribe({
76
76
  next,
77
77
  error,
@@ -39,7 +39,7 @@ test('map', () => {
39
39
  ee.off('data', callback);
40
40
  };
41
41
  });
42
- const pipeCalls = jest.fn();
42
+ const pipeCalls = vi.fn();
43
43
  const piped = eventObservable.pipe(
44
44
  map((...args) => {
45
45
  pipeCalls(...args);
@@ -48,7 +48,7 @@ test('map', () => {
48
48
  }),
49
49
  );
50
50
 
51
- const next = jest.fn();
51
+ const next = vi.fn();
52
52
  const subscription = piped.subscribe({
53
53
  next(value) {
54
54
  expectTypeOf<number>(value);
@@ -10,9 +10,9 @@ test('share', () => {
10
10
  );
11
11
 
12
12
  {
13
- const next = jest.fn();
14
- const error = jest.fn();
15
- const complete = jest.fn();
13
+ const next = vi.fn();
14
+ const error = vi.fn();
15
+ const complete = vi.fn();
16
16
  var subscription1 = obs.subscribe({
17
17
  next,
18
18
  error,
@@ -26,9 +26,9 @@ test('share', () => {
26
26
 
27
27
  {
28
28
  // subscribe again - it's shared so should not propagate any results
29
- const next = jest.fn();
30
- const error = jest.fn();
31
- const complete = jest.fn();
29
+ const next = vi.fn();
30
+ const error = vi.fn();
31
+ const complete = vi.fn();
32
32
  var subscription2 = obs.subscribe({
33
33
  next,
34
34
  error,
@@ -43,9 +43,9 @@ test('share', () => {
43
43
  subscription2.unsubscribe();
44
44
  // now it should be reset so we can do a new subscription
45
45
  {
46
- const next = jest.fn();
47
- const error = jest.fn();
48
- const complete = jest.fn();
46
+ const next = vi.fn();
47
+ const error = vi.fn();
48
+ const complete = vi.fn();
49
49
  var subscription3 = obs.subscribe({
50
50
  next,
51
51
  error,
@@ -15,17 +15,17 @@ export function subscriptionPullFactory<TOutput>(opts: {
15
15
  let timer: any;
16
16
  let stopped = false;
17
17
  async function _pull(emit: Observer<TOutput, unknown>) {
18
- /* istanbul ignore next */
18
+ /* istanbul ignore next -- @preserve */
19
19
  if (stopped) {
20
20
  return;
21
21
  }
22
22
  try {
23
23
  await opts.pull(emit);
24
- } catch (err /* istanbul ignore next */) {
24
+ } catch (err /* istanbul ignore next -- @preserve */) {
25
25
  emit.error(getTRPCErrorFromUnknown(err));
26
26
  }
27
27
 
28
- /* istanbul ignore else */
28
+ /* istanbul ignore else -- @preserve */
29
29
  if (!stopped) {
30
30
  timer = setTimeout(() => _pull(emit), opts.intervalMs);
31
31
  }
@@ -1,25 +1,53 @@
1
1
  /**
2
2
  * @public
3
3
  */
4
- export type DataTransformer = {
4
+ export interface DataTransformer {
5
5
  serialize(object: any): any;
6
6
  deserialize(object: any): any;
7
- };
7
+ }
8
+
9
+ interface InputDataTransformer extends DataTransformer {
10
+ /**
11
+ * This function runs **on the client** before sending the data to the server.
12
+ */
13
+ serialize(object: any): any;
14
+ /**
15
+ * This function runs **on the server** to transform the data before it is passed to the resolver
16
+ */
17
+ deserialize(object: any): any;
18
+ }
19
+
20
+ interface OutputDataTransformer extends DataTransformer {
21
+ /**
22
+ * This function runs **on the server** before sending the data to the client.
23
+ */
24
+ serialize(object: any): any;
25
+ /**
26
+ * This function runs **only on the client** to transform the data sent from the server.
27
+ */
28
+ deserialize(object: any): any;
29
+ }
8
30
 
9
31
  /**
10
32
  * @public
11
33
  */
12
- export type CombinedDataTransformer = {
13
- input: DataTransformer;
14
- output: DataTransformer;
15
- };
34
+ export interface CombinedDataTransformer {
35
+ /**
36
+ * Specify how the data sent from the client to the server should be transformed.
37
+ */
38
+ input: InputDataTransformer;
39
+ /**
40
+ * Specify how the data sent from the server to the client should be transformed.
41
+ */
42
+ output: OutputDataTransformer;
43
+ }
16
44
 
17
45
  /**
18
46
  * @public
19
47
  */
20
48
  export type CombinedDataTransformerClient = {
21
- input: Pick<DataTransformer, 'serialize'>;
22
- output: Pick<DataTransformer, 'deserialize'>;
49
+ input: Pick<CombinedDataTransformer['input'], 'serialize'>;
50
+ output: Pick<CombinedDataTransformer['output'], 'deserialize'>;
23
51
  };
24
52
 
25
53
  /**
@@ -1 +0,0 @@
1
- export * from "../../../dist/declarations/src/adapters/aws-lambda/index";
@@ -1,190 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var transformTRPCResponse = require('../../../dist/transformTRPCResponse-36a41418.cjs.dev.js');
6
- require('../../../dist/router-ee876044.cjs.dev.js');
7
- require('events');
8
- require('http');
9
- require('url');
10
- require('../../../dist/nodeHTTPRequestHandler-9a93c255.cjs.dev.js');
11
- var resolveHTTPResponse = require('../../../dist/resolveHTTPResponse-ab01e4b9.cjs.dev.js');
12
- require('../../../dist/codes-130e62df.cjs.dev.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
- const matches = event.resource.matchAll(/\{(.*?)\}/g);
77
-
78
- for (const match of matches) {
79
- const group = match[1];
80
-
81
- if (group.includes('+') && event.pathParameters) {
82
- return event.pathParameters[group.replace('+', '')] || '';
83
- }
84
- }
85
-
86
- return event.path.slice(1);
87
- }
88
-
89
- if (isPayloadV2(event)) {
90
- const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
91
-
92
- for (const match of matches) {
93
- const group = match[1];
94
-
95
- if (group.includes('+') && event.pathParameters) {
96
- return event.pathParameters[group.replace('+', '')] || '';
97
- }
98
- }
99
-
100
- return event.rawPath.slice(1);
101
- }
102
-
103
- throw new transformTRPCResponse.TRPCError({
104
- code: 'INTERNAL_SERVER_ERROR',
105
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
106
- });
107
- }
108
-
109
- function transformHeaders(headers) {
110
- const obj = {};
111
-
112
- for (const [key, value] of Object.entries(headers)) {
113
- if (typeof value === 'undefined') {
114
- continue;
115
- }
116
-
117
- obj[key] = Array.isArray(value) ? value.join(',') : value;
118
- }
119
-
120
- return obj;
121
- }
122
-
123
- function tRPCOutputToAPIGatewayOutput(event, response) {
124
- if (isPayloadV1(event)) {
125
- var _response$body, _response$headers;
126
-
127
- const resp = {
128
- statusCode: response.status,
129
- body: (_response$body = response.body) !== null && _response$body !== void 0 ? _response$body : '',
130
- headers: transformHeaders((_response$headers = response.headers) !== null && _response$headers !== void 0 ? _response$headers : {})
131
- };
132
- return resp;
133
- } else if (isPayloadV2(event)) {
134
- var _response$body2, _response$headers2;
135
-
136
- const resp = {
137
- statusCode: response.status,
138
- body: (_response$body2 = response.body) !== null && _response$body2 !== void 0 ? _response$body2 : undefined,
139
- headers: transformHeaders((_response$headers2 = response.headers) !== null && _response$headers2 !== void 0 ? _response$headers2 : {})
140
- };
141
- return resp;
142
- } else {
143
- throw new transformTRPCResponse.TRPCError({
144
- code: 'INTERNAL_SERVER_ERROR',
145
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
146
- });
147
- }
148
- }
149
- /** Will check the createContext of the TRouter and get the parameter of event.
150
- * @internal
151
- **/
152
-
153
-
154
- function awsLambdaRequestHandler(opts) {
155
- return async (event, context) => {
156
- const req = lambdaEventToHTTPRequest(event);
157
- const path = getPath(event);
158
-
159
- const createContext = async function _createContext() {
160
- var _opts$createContext;
161
-
162
- return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, {
163
- event,
164
- context
165
- }));
166
- };
167
-
168
- const response = await resolveHTTPResponse.resolveHTTPResponse({
169
- router: opts.router,
170
- batching: opts.batching,
171
- responseMeta: opts === null || opts === void 0 ? void 0 : opts.responseMeta,
172
- createContext,
173
- req,
174
- path,
175
- error: null,
176
-
177
- onError(o) {
178
- var _opts$onError;
179
-
180
- opts === null || opts === void 0 ? void 0 : (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, { ...o,
181
- req: event
182
- });
183
- }
184
-
185
- });
186
- return tRPCOutputToAPIGatewayOutput(event, response);
187
- };
188
- }
189
-
190
- exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./trpc-server-adapters-aws-lambda.cjs.prod.js");
5
- } else {
6
- module.exports = require("./trpc-server-adapters-aws-lambda.cjs.dev.js");
7
- }
@@ -1,190 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var transformTRPCResponse = require('../../../dist/transformTRPCResponse-077b7539.cjs.prod.js');
6
- require('../../../dist/router-aaecbe82.cjs.prod.js');
7
- require('events');
8
- require('http');
9
- require('url');
10
- require('../../../dist/nodeHTTPRequestHandler-21707788.cjs.prod.js');
11
- var resolveHTTPResponse = require('../../../dist/resolveHTTPResponse-9812e803.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
- const matches = event.resource.matchAll(/\{(.*?)\}/g);
77
-
78
- for (const match of matches) {
79
- const group = match[1];
80
-
81
- if (group.includes('+') && event.pathParameters) {
82
- return event.pathParameters[group.replace('+', '')] || '';
83
- }
84
- }
85
-
86
- return event.path.slice(1);
87
- }
88
-
89
- if (isPayloadV2(event)) {
90
- const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
91
-
92
- for (const match of matches) {
93
- const group = match[1];
94
-
95
- if (group.includes('+') && event.pathParameters) {
96
- return event.pathParameters[group.replace('+', '')] || '';
97
- }
98
- }
99
-
100
- return event.rawPath.slice(1);
101
- }
102
-
103
- throw new transformTRPCResponse.TRPCError({
104
- code: 'INTERNAL_SERVER_ERROR',
105
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
106
- });
107
- }
108
-
109
- function transformHeaders(headers) {
110
- const obj = {};
111
-
112
- for (const [key, value] of Object.entries(headers)) {
113
- if (typeof value === 'undefined') {
114
- continue;
115
- }
116
-
117
- obj[key] = Array.isArray(value) ? value.join(',') : value;
118
- }
119
-
120
- return obj;
121
- }
122
-
123
- function tRPCOutputToAPIGatewayOutput(event, response) {
124
- if (isPayloadV1(event)) {
125
- var _response$body, _response$headers;
126
-
127
- const resp = {
128
- statusCode: response.status,
129
- body: (_response$body = response.body) !== null && _response$body !== void 0 ? _response$body : '',
130
- headers: transformHeaders((_response$headers = response.headers) !== null && _response$headers !== void 0 ? _response$headers : {})
131
- };
132
- return resp;
133
- } else if (isPayloadV2(event)) {
134
- var _response$body2, _response$headers2;
135
-
136
- const resp = {
137
- statusCode: response.status,
138
- body: (_response$body2 = response.body) !== null && _response$body2 !== void 0 ? _response$body2 : undefined,
139
- headers: transformHeaders((_response$headers2 = response.headers) !== null && _response$headers2 !== void 0 ? _response$headers2 : {})
140
- };
141
- return resp;
142
- } else {
143
- throw new transformTRPCResponse.TRPCError({
144
- code: 'INTERNAL_SERVER_ERROR',
145
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
146
- });
147
- }
148
- }
149
- /** Will check the createContext of the TRouter and get the parameter of event.
150
- * @internal
151
- **/
152
-
153
-
154
- function awsLambdaRequestHandler(opts) {
155
- return async (event, context) => {
156
- const req = lambdaEventToHTTPRequest(event);
157
- const path = getPath(event);
158
-
159
- const createContext = async function _createContext() {
160
- var _opts$createContext;
161
-
162
- return await ((_opts$createContext = opts.createContext) === null || _opts$createContext === void 0 ? void 0 : _opts$createContext.call(opts, {
163
- event,
164
- context
165
- }));
166
- };
167
-
168
- const response = await resolveHTTPResponse.resolveHTTPResponse({
169
- router: opts.router,
170
- batching: opts.batching,
171
- responseMeta: opts === null || opts === void 0 ? void 0 : opts.responseMeta,
172
- createContext,
173
- req,
174
- path,
175
- error: null,
176
-
177
- onError(o) {
178
- var _opts$onError;
179
-
180
- opts === null || opts === void 0 ? void 0 : (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, { ...o,
181
- req: event
182
- });
183
- }
184
-
185
- });
186
- return tRPCOutputToAPIGatewayOutput(event, response);
187
- };
188
- }
189
-
190
- exports.awsLambdaRequestHandler = awsLambdaRequestHandler;