@trpc/server 11.0.0-next-beta.206 → 11.0.0-next-beta.216

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 (56) hide show
  1. package/dist/adapters/aws-lambda/index.js +14 -105
  2. package/dist/adapters/aws-lambda/index.mjs +1 -90
  3. package/dist/adapters/aws-lambda/utils.js +100 -0
  4. package/dist/adapters/aws-lambda/utils.mjs +93 -0
  5. package/dist/adapters/express.js +1 -7
  6. package/dist/adapters/express.mjs +1 -5
  7. package/dist/adapters/fastify/fastifyRequestHandler.js +81 -0
  8. package/dist/adapters/fastify/fastifyRequestHandler.mjs +79 -0
  9. package/dist/adapters/fastify/fastifyTRPCPlugin.js +51 -0
  10. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +49 -0
  11. package/dist/adapters/fastify/index.js +4 -128
  12. package/dist/adapters/fastify/index.mjs +2 -128
  13. package/dist/adapters/fetch/fetchRequestHandler.js +118 -0
  14. package/dist/adapters/fetch/fetchRequestHandler.mjs +116 -0
  15. package/dist/adapters/fetch/index.js +2 -115
  16. package/dist/adapters/fetch/index.mjs +1 -116
  17. package/dist/adapters/next.js +1 -6
  18. package/dist/adapters/next.mjs +1 -4
  19. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
  20. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
  21. package/dist/adapters/node-http/content-type/form-data/index.js +20 -646
  22. package/dist/adapters/node-http/content-type/form-data/index.mjs +9 -631
  23. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
  24. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
  25. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
  26. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
  27. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
  28. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
  29. package/dist/adapters/node-http/content-type/json/getPostBody.js +42 -0
  30. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +40 -0
  31. package/dist/adapters/node-http/content-type/json/index.js +3 -42
  32. package/dist/adapters/node-http/content-type/json/index.mjs +2 -39
  33. package/dist/adapters/node-http/index.js +1 -7
  34. package/dist/adapters/node-http/index.mjs +1 -5
  35. package/dist/{contentType-72ed9df5.mjs → adapters/node-http/internals/contentType.mjs} +1 -1
  36. package/dist/{nodeHTTPRequestHandler-83441c73.js → adapters/node-http/nodeHTTPRequestHandler.js} +2 -2
  37. package/dist/{nodeHTTPRequestHandler-0223fac5.mjs → adapters/node-http/nodeHTTPRequestHandler.mjs} +2 -2
  38. package/dist/adapters/standalone.js +2 -12
  39. package/dist/adapters/standalone.mjs +1 -5
  40. package/dist/adapters/ws.js +0 -2
  41. package/dist/bundle-analysis.json +97 -97
  42. package/dist/http.js +1 -3
  43. package/dist/index.js +10 -12
  44. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +203 -0
  45. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +201 -0
  46. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +167 -0
  47. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +163 -0
  48. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +35 -0
  49. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +30 -0
  50. package/dist/observable.js +1 -3
  51. package/dist/rpc.js +1 -3
  52. package/dist/shared.js +2 -4
  53. package/package.json +4 -4
  54. package/dist/contentType-24c44bba.js +0 -5
  55. package/dist/nodeHTTPRequestHandler-aa0dce4e.js +0 -105
  56. /package/dist/{contentType-d9d22104.js → adapters/node-http/internals/contentType.js} +0 -0
@@ -1,99 +1,8 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var core = require('@trpc/core');
6
4
  var http = require('@trpc/core/http');
7
-
8
- /**
9
- * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
10
- *
11
- * Do **not** import from `@trpc/core`
12
- * @example
13
- * ```ts
14
- * import type { AnyTRPCRouter } from '@trpc/server'
15
- * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
16
- * ```
17
- */ // @trpc/server
18
- function isPayloadV1(event) {
19
- return determinePayloadFormat(event) == '1.0';
20
- }
21
- function isPayloadV2(event) {
22
- return determinePayloadFormat(event) == '2.0';
23
- }
24
- function determinePayloadFormat(event) {
25
- // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
26
- // According to AWS support, version is is extracted from the version property in the event.
27
- // If there is no version property, then the version is implied as 1.0
28
- const unknownEvent = event;
29
- if (typeof unknownEvent.version === 'undefined') {
30
- return '1.0';
31
- } else {
32
- if ([
33
- '1.0',
34
- '2.0'
35
- ].includes(unknownEvent.version)) {
36
- return unknownEvent.version;
37
- } else {
38
- return 'custom';
39
- }
40
- }
41
- }
42
- function getHTTPMethod(event) {
43
- if (isPayloadV1(event)) {
44
- return event.httpMethod;
45
- }
46
- if (isPayloadV2(event)) {
47
- return event.requestContext.http.method;
48
- }
49
- throw new core.TRPCError({
50
- code: 'INTERNAL_SERVER_ERROR',
51
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
52
- });
53
- }
54
- function getPath(event) {
55
- if (isPayloadV1(event)) {
56
- if (!event.pathParameters) {
57
- // Then this event was not triggered by a resource denoted with {proxy+}
58
- return event.path.split('/').pop() ?? '';
59
- }
60
- const matches = event.resource.matchAll(/\{(.*?)\}/g);
61
- for (const match of matches){
62
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63
- const group = match[1];
64
- if (group.includes('+') && event.pathParameters) {
65
- return event.pathParameters[group.replace('+', '')] ?? '';
66
- }
67
- }
68
- return event.path.slice(1);
69
- }
70
- if (isPayloadV2(event)) {
71
- const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
72
- for (const match1 of matches1){
73
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
74
- const group1 = match1[1];
75
- if (group1.includes('+') && event.pathParameters) {
76
- return event.pathParameters[group1.replace('+', '')] ?? '';
77
- }
78
- }
79
- return event.rawPath.slice(1);
80
- }
81
- throw new core.TRPCError({
82
- code: 'INTERNAL_SERVER_ERROR',
83
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
84
- });
85
- }
86
- function transformHeaders(headers) {
87
- const obj = {};
88
- for (const [key, value] of Object.entries(headers)){
89
- if (typeof value === 'undefined') {
90
- continue;
91
- }
92
- obj[key] = Array.isArray(value) ? value.join(',') : value;
93
- }
94
- return obj;
95
- }
96
- 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';
5
+ var utils = require('./utils.js');
97
6
 
98
7
  /**
99
8
  * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
@@ -119,38 +28,38 @@ function lambdaEventToHTTPRequest(event) {
119
28
  body = event.body;
120
29
  }
121
30
  return {
122
- method: getHTTPMethod(event),
31
+ method: utils.getHTTPMethod(event),
123
32
  query: query,
124
33
  headers: event.headers,
125
34
  body: body
126
35
  };
127
36
  }
128
37
  function tRPCOutputToAPIGatewayOutput(event, response) {
129
- if (isPayloadV1(event)) {
38
+ if (utils.isPayloadV1(event)) {
130
39
  const resp = {
131
40
  statusCode: response.status,
132
41
  body: response.body ?? '',
133
- headers: transformHeaders(response.headers ?? {})
42
+ headers: utils.transformHeaders(response.headers ?? {})
134
43
  };
135
44
  return resp;
136
- } else if (isPayloadV2(event)) {
45
+ } else if (utils.isPayloadV2(event)) {
137
46
  const resp1 = {
138
47
  statusCode: response.status,
139
48
  body: response.body ?? undefined,
140
- headers: transformHeaders(response.headers ?? {})
49
+ headers: utils.transformHeaders(response.headers ?? {})
141
50
  };
142
51
  return resp1;
143
52
  } else {
144
53
  throw new core.TRPCError({
145
54
  code: 'INTERNAL_SERVER_ERROR',
146
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
55
+ message: utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
147
56
  });
148
57
  }
149
58
  }
150
59
  function awsLambdaRequestHandler(opts) {
151
60
  return async (event, context)=>{
152
61
  const req = lambdaEventToHTTPRequest(event);
153
- const path = getPath(event);
62
+ const path = utils.getPath(event);
154
63
  const createContext = async (innerOpts)=>{
155
64
  return await opts.createContext?.({
156
65
  event,
@@ -177,10 +86,10 @@ function awsLambdaRequestHandler(opts) {
177
86
  };
178
87
  }
179
88
 
180
- exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
89
+ exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
90
+ exports.getHTTPMethod = utils.getHTTPMethod;
91
+ exports.getPath = utils.getPath;
92
+ exports.isPayloadV1 = utils.isPayloadV1;
93
+ exports.isPayloadV2 = utils.isPayloadV2;
94
+ exports.transformHeaders = utils.transformHeaders;
181
95
  exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
182
- exports.getHTTPMethod = getHTTPMethod;
183
- exports.getPath = getPath;
184
- exports.isPayloadV1 = isPayloadV1;
185
- exports.isPayloadV2 = isPayloadV2;
186
- exports.transformHeaders = transformHeaders;
@@ -1,95 +1,6 @@
1
1
  import { TRPCError } from '@trpc/core';
2
2
  import { resolveHTTPResponse } from '@trpc/core/http';
3
-
4
- /**
5
- * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
6
- *
7
- * Do **not** import from `@trpc/core`
8
- * @example
9
- * ```ts
10
- * import type { AnyTRPCRouter } from '@trpc/server'
11
- * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
12
- * ```
13
- */ // @trpc/server
14
- function isPayloadV1(event) {
15
- return determinePayloadFormat(event) == '1.0';
16
- }
17
- function isPayloadV2(event) {
18
- return determinePayloadFormat(event) == '2.0';
19
- }
20
- function determinePayloadFormat(event) {
21
- // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
22
- // According to AWS support, version is is extracted from the version property in the event.
23
- // If there is no version property, then the version is implied as 1.0
24
- const unknownEvent = event;
25
- if (typeof unknownEvent.version === 'undefined') {
26
- return '1.0';
27
- } else {
28
- if ([
29
- '1.0',
30
- '2.0'
31
- ].includes(unknownEvent.version)) {
32
- return unknownEvent.version;
33
- } else {
34
- return 'custom';
35
- }
36
- }
37
- }
38
- function getHTTPMethod(event) {
39
- if (isPayloadV1(event)) {
40
- return event.httpMethod;
41
- }
42
- if (isPayloadV2(event)) {
43
- return event.requestContext.http.method;
44
- }
45
- throw new TRPCError({
46
- code: 'INTERNAL_SERVER_ERROR',
47
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
48
- });
49
- }
50
- function getPath(event) {
51
- if (isPayloadV1(event)) {
52
- if (!event.pathParameters) {
53
- // Then this event was not triggered by a resource denoted with {proxy+}
54
- return event.path.split('/').pop() ?? '';
55
- }
56
- const matches = event.resource.matchAll(/\{(.*?)\}/g);
57
- for (const match of matches){
58
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59
- const group = match[1];
60
- if (group.includes('+') && event.pathParameters) {
61
- return event.pathParameters[group.replace('+', '')] ?? '';
62
- }
63
- }
64
- return event.path.slice(1);
65
- }
66
- if (isPayloadV2(event)) {
67
- const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
68
- for (const match1 of matches1){
69
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70
- const group1 = match1[1];
71
- if (group1.includes('+') && event.pathParameters) {
72
- return event.pathParameters[group1.replace('+', '')] ?? '';
73
- }
74
- }
75
- return event.rawPath.slice(1);
76
- }
77
- throw new TRPCError({
78
- code: 'INTERNAL_SERVER_ERROR',
79
- message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
80
- });
81
- }
82
- function transformHeaders(headers) {
83
- const obj = {};
84
- for (const [key, value] of Object.entries(headers)){
85
- if (typeof value === 'undefined') {
86
- continue;
87
- }
88
- obj[key] = Array.isArray(value) ? value.join(',') : value;
89
- }
90
- return obj;
91
- }
92
- 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';
3
+ import { getPath, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE } from './utils.mjs';
93
4
 
94
5
  /**
95
6
  * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var core = require('@trpc/core');
4
+
5
+ /**
6
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
7
+ *
8
+ * Do **not** import from `@trpc/core`
9
+ * @example
10
+ * ```ts
11
+ * import type { AnyTRPCRouter } from '@trpc/server'
12
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
13
+ * ```
14
+ */ // @trpc/server
15
+ function isPayloadV1(event) {
16
+ return determinePayloadFormat(event) == '1.0';
17
+ }
18
+ function isPayloadV2(event) {
19
+ return determinePayloadFormat(event) == '2.0';
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
+ if (typeof unknownEvent.version === 'undefined') {
27
+ return '1.0';
28
+ } else {
29
+ if ([
30
+ '1.0',
31
+ '2.0'
32
+ ].includes(unknownEvent.version)) {
33
+ return unknownEvent.version;
34
+ } else {
35
+ return 'custom';
36
+ }
37
+ }
38
+ }
39
+ function getHTTPMethod(event) {
40
+ if (isPayloadV1(event)) {
41
+ return event.httpMethod;
42
+ }
43
+ if (isPayloadV2(event)) {
44
+ return event.requestContext.http.method;
45
+ }
46
+ throw new core.TRPCError({
47
+ code: 'INTERNAL_SERVER_ERROR',
48
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
49
+ });
50
+ }
51
+ function getPath(event) {
52
+ if (isPayloadV1(event)) {
53
+ if (!event.pathParameters) {
54
+ // Then this event was not triggered by a resource denoted with {proxy+}
55
+ return event.path.split('/').pop() ?? '';
56
+ }
57
+ const matches = event.resource.matchAll(/\{(.*?)\}/g);
58
+ for (const match of matches){
59
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
+ const group = match[1];
61
+ if (group.includes('+') && event.pathParameters) {
62
+ return event.pathParameters[group.replace('+', '')] ?? '';
63
+ }
64
+ }
65
+ return event.path.slice(1);
66
+ }
67
+ if (isPayloadV2(event)) {
68
+ const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
69
+ for (const match1 of matches1){
70
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
71
+ const group1 = match1[1];
72
+ if (group1.includes('+') && event.pathParameters) {
73
+ return event.pathParameters[group1.replace('+', '')] ?? '';
74
+ }
75
+ }
76
+ return event.rawPath.slice(1);
77
+ }
78
+ throw new core.TRPCError({
79
+ code: 'INTERNAL_SERVER_ERROR',
80
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
81
+ });
82
+ }
83
+ function transformHeaders(headers) {
84
+ const obj = {};
85
+ for (const [key, value] of Object.entries(headers)){
86
+ if (typeof value === 'undefined') {
87
+ continue;
88
+ }
89
+ obj[key] = Array.isArray(value) ? value.join(',') : value;
90
+ }
91
+ return obj;
92
+ }
93
+ 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';
94
+
95
+ exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
96
+ exports.getHTTPMethod = getHTTPMethod;
97
+ exports.getPath = getPath;
98
+ exports.isPayloadV1 = isPayloadV1;
99
+ exports.isPayloadV2 = isPayloadV2;
100
+ exports.transformHeaders = transformHeaders;
@@ -0,0 +1,93 @@
1
+ import { TRPCError } from '@trpc/core';
2
+
3
+ /**
4
+ * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
5
+ *
6
+ * Do **not** import from `@trpc/core`
7
+ * @example
8
+ * ```ts
9
+ * import type { AnyTRPCRouter } from '@trpc/server'
10
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
11
+ * ```
12
+ */ // @trpc/server
13
+ function isPayloadV1(event) {
14
+ return determinePayloadFormat(event) == '1.0';
15
+ }
16
+ function isPayloadV2(event) {
17
+ return determinePayloadFormat(event) == '2.0';
18
+ }
19
+ function determinePayloadFormat(event) {
20
+ // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
21
+ // According to AWS support, version is is extracted from the version property in the event.
22
+ // If there is no version property, then the version is implied as 1.0
23
+ const unknownEvent = event;
24
+ if (typeof unknownEvent.version === 'undefined') {
25
+ return '1.0';
26
+ } else {
27
+ if ([
28
+ '1.0',
29
+ '2.0'
30
+ ].includes(unknownEvent.version)) {
31
+ return unknownEvent.version;
32
+ } else {
33
+ return 'custom';
34
+ }
35
+ }
36
+ }
37
+ function getHTTPMethod(event) {
38
+ if (isPayloadV1(event)) {
39
+ return event.httpMethod;
40
+ }
41
+ if (isPayloadV2(event)) {
42
+ return event.requestContext.http.method;
43
+ }
44
+ throw new TRPCError({
45
+ code: 'INTERNAL_SERVER_ERROR',
46
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
47
+ });
48
+ }
49
+ function getPath(event) {
50
+ if (isPayloadV1(event)) {
51
+ if (!event.pathParameters) {
52
+ // Then this event was not triggered by a resource denoted with {proxy+}
53
+ return event.path.split('/').pop() ?? '';
54
+ }
55
+ const matches = event.resource.matchAll(/\{(.*?)\}/g);
56
+ for (const match of matches){
57
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
58
+ const group = match[1];
59
+ if (group.includes('+') && event.pathParameters) {
60
+ return event.pathParameters[group.replace('+', '')] ?? '';
61
+ }
62
+ }
63
+ return event.path.slice(1);
64
+ }
65
+ if (isPayloadV2(event)) {
66
+ const matches1 = event.routeKey.matchAll(/\{(.*?)\}/g);
67
+ for (const match1 of matches1){
68
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
+ const group1 = match1[1];
70
+ if (group1.includes('+') && event.pathParameters) {
71
+ return event.pathParameters[group1.replace('+', '')] ?? '';
72
+ }
73
+ }
74
+ return event.rawPath.slice(1);
75
+ }
76
+ throw new TRPCError({
77
+ code: 'INTERNAL_SERVER_ERROR',
78
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
79
+ });
80
+ }
81
+ function transformHeaders(headers) {
82
+ const obj = {};
83
+ for (const [key, value] of Object.entries(headers)){
84
+ if (typeof value === 'undefined') {
85
+ continue;
86
+ }
87
+ obj[key] = Array.isArray(value) ? value.join(',') : value;
88
+ }
89
+ return obj;
90
+ }
91
+ 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';
92
+
93
+ export { UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
@@ -1,12 +1,6 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var nodeHTTPRequestHandler = require('../nodeHTTPRequestHandler-83441c73.js');
6
- require('@trpc/core/http');
7
- require('./node-http/content-type/json/index.js');
8
- require('../contentType-d9d22104.js');
9
- require('@trpc/core');
3
+ var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
10
4
 
11
5
  function createExpressMiddleware(opts) {
12
6
  return async (req, res)=>{
@@ -1,8 +1,4 @@
1
- import { n as nodeHTTPRequestHandler } from '../nodeHTTPRequestHandler-0223fac5.mjs';
2
- import '@trpc/core/http';
3
- import './node-http/content-type/json/index.mjs';
4
- import '../contentType-72ed9df5.mjs';
5
- import '@trpc/core';
1
+ import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
6
2
 
7
3
  function createExpressMiddleware(opts) {
8
4
  return async (req, res)=>{
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ var node_stream = require('node:stream');
4
+ var http = require('@trpc/core/http');
5
+
6
+ async function fastifyRequestHandler(opts) {
7
+ const createContext = async (innerOpts)=>{
8
+ return await opts.createContext?.({
9
+ ...opts,
10
+ ...innerOpts
11
+ });
12
+ };
13
+ const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
14
+ const req = {
15
+ query,
16
+ method: opts.req.method,
17
+ headers: opts.req.headers,
18
+ body: opts.req.body ?? 'null'
19
+ };
20
+ let resolve;
21
+ const promise = new Promise((r)=>resolve = r);
22
+ let isStream = false;
23
+ let stream;
24
+ let formatter;
25
+ const unstable_onHead = (head, isStreaming)=>{
26
+ if (!opts.res.statusCode || opts.res.statusCode === 200) {
27
+ opts.res.statusCode = head.status;
28
+ }
29
+ for (const [key, value] of Object.entries(head.headers ?? {})){
30
+ /* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
31
+ continue;
32
+ }
33
+ void opts.res.header(key, value);
34
+ }
35
+ if (isStreaming) {
36
+ void opts.res.header('Transfer-Encoding', 'chunked');
37
+ void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
38
+ stream = new node_stream.Readable();
39
+ stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
40
+ resolve(opts.res.send(stream));
41
+ isStream = true;
42
+ formatter = http.getBatchStreamFormatter();
43
+ }
44
+ };
45
+ const unstable_onChunk = ([index, string])=>{
46
+ if (index === -1) {
47
+ // full response, no streaming
48
+ resolve(opts.res.send(string));
49
+ } else {
50
+ stream.push(formatter(index, string));
51
+ }
52
+ };
53
+ http.resolveHTTPResponse({
54
+ req,
55
+ createContext,
56
+ path: opts.path,
57
+ router: opts.router,
58
+ batching: opts.batching,
59
+ responseMeta: opts.responseMeta,
60
+ onError (o) {
61
+ opts?.onError?.({
62
+ ...o,
63
+ req: opts.req
64
+ });
65
+ },
66
+ unstable_onHead,
67
+ unstable_onChunk
68
+ }).then(()=>{
69
+ if (isStream) {
70
+ stream.push(formatter.end());
71
+ stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
72
+ }
73
+ }).catch(()=>{
74
+ if (isStream) {
75
+ stream.push(null);
76
+ }
77
+ });
78
+ return promise;
79
+ }
80
+
81
+ exports.fastifyRequestHandler = fastifyRequestHandler;
@@ -0,0 +1,79 @@
1
+ import { Readable } from 'node:stream';
2
+ import { resolveHTTPResponse, getBatchStreamFormatter } from '@trpc/core/http';
3
+
4
+ async function fastifyRequestHandler(opts) {
5
+ const createContext = async (innerOpts)=>{
6
+ return await opts.createContext?.({
7
+ ...opts,
8
+ ...innerOpts
9
+ });
10
+ };
11
+ const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
12
+ const req = {
13
+ query,
14
+ method: opts.req.method,
15
+ headers: opts.req.headers,
16
+ body: opts.req.body ?? 'null'
17
+ };
18
+ let resolve;
19
+ const promise = new Promise((r)=>resolve = r);
20
+ let isStream = false;
21
+ let stream;
22
+ let formatter;
23
+ const unstable_onHead = (head, isStreaming)=>{
24
+ if (!opts.res.statusCode || opts.res.statusCode === 200) {
25
+ opts.res.statusCode = head.status;
26
+ }
27
+ for (const [key, value] of Object.entries(head.headers ?? {})){
28
+ /* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
29
+ continue;
30
+ }
31
+ void opts.res.header(key, value);
32
+ }
33
+ if (isStreaming) {
34
+ void opts.res.header('Transfer-Encoding', 'chunked');
35
+ void opts.res.header('Vary', opts.res.hasHeader('Vary') ? 'trpc-batch-mode, ' + opts.res.getHeader('Vary') : 'trpc-batch-mode');
36
+ stream = new Readable();
37
+ stream._read = ()=>{}; // eslint-disable-line @typescript-eslint/no-empty-function -- https://github.com/fastify/fastify/issues/805#issuecomment-369172154
38
+ resolve(opts.res.send(stream));
39
+ isStream = true;
40
+ formatter = getBatchStreamFormatter();
41
+ }
42
+ };
43
+ const unstable_onChunk = ([index, string])=>{
44
+ if (index === -1) {
45
+ // full response, no streaming
46
+ resolve(opts.res.send(string));
47
+ } else {
48
+ stream.push(formatter(index, string));
49
+ }
50
+ };
51
+ resolveHTTPResponse({
52
+ req,
53
+ createContext,
54
+ path: opts.path,
55
+ router: opts.router,
56
+ batching: opts.batching,
57
+ responseMeta: opts.responseMeta,
58
+ onError (o) {
59
+ opts?.onError?.({
60
+ ...o,
61
+ req: opts.req
62
+ });
63
+ },
64
+ unstable_onHead,
65
+ unstable_onChunk
66
+ }).then(()=>{
67
+ if (isStream) {
68
+ stream.push(formatter.end());
69
+ stream.push(null); // https://github.com/fastify/fastify/issues/805#issuecomment-369172154
70
+ }
71
+ }).catch(()=>{
72
+ if (isStream) {
73
+ stream.push(null);
74
+ }
75
+ });
76
+ return promise;
77
+ }
78
+
79
+ export { fastifyRequestHandler };