@trpc/server 11.0.0-alpha-tmp-export-from-main.221 → 11.0.0-alpha-tmp-export-from-main.222

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 (136) hide show
  1. package/dist/adapters/aws-lambda/index.d.mts +68 -0
  2. package/dist/adapters/aws-lambda/index.d.ts +54 -6
  3. package/dist/adapters/aws-lambda/index.js +110 -20
  4. package/dist/adapters/aws-lambda/index.mjs +94 -4
  5. package/dist/adapters/express.d.mts +19 -0
  6. package/dist/adapters/express.d.ts +9 -6
  7. package/dist/adapters/express.js +3 -3
  8. package/dist/adapters/express.mjs +1 -1
  9. package/dist/adapters/fastify/index.d.mts +33 -0
  10. package/dist/adapters/fastify/index.d.ts +33 -3
  11. package/dist/adapters/fastify/index.js +124 -5
  12. package/dist/adapters/fastify/index.mjs +125 -2
  13. package/dist/adapters/fetch/index.d.mts +51 -0
  14. package/dist/adapters/fetch/index.d.ts +51 -3
  15. package/dist/adapters/fetch/index.js +115 -4
  16. package/dist/adapters/fetch/index.mjs +116 -1
  17. package/dist/adapters/next.d.mts +21 -0
  18. package/dist/adapters/next.d.ts +11 -7
  19. package/dist/adapters/next.js +6 -6
  20. package/dist/adapters/next.mjs +2 -2
  21. package/dist/adapters/node-http/content-type/form-data/index.d.mts +219 -0
  22. package/dist/adapters/node-http/content-type/form-data/index.d.ts +201 -10
  23. package/dist/adapters/node-http/content-type/form-data/index.js +662 -23
  24. package/dist/adapters/node-http/content-type/form-data/index.mjs +646 -10
  25. package/dist/adapters/node-http/{types.d.ts → content-type/json/index.d.mts} +21 -15
  26. package/dist/adapters/node-http/content-type/json/index.d.ts +89 -2
  27. package/dist/adapters/node-http/content-type/json/index.js +48 -7
  28. package/dist/adapters/node-http/content-type/json/index.mjs +44 -3
  29. package/dist/adapters/node-http/index.d.mts +100 -0
  30. package/dist/adapters/node-http/index.d.ts +100 -3
  31. package/dist/adapters/node-http/index.js +106 -4
  32. package/dist/adapters/node-http/index.mjs +107 -1
  33. package/dist/adapters/standalone.d.mts +21 -0
  34. package/dist/adapters/standalone.d.ts +11 -9
  35. package/dist/adapters/standalone.js +9 -5
  36. package/dist/adapters/standalone.mjs +2 -2
  37. package/dist/adapters/ws.d.mts +36 -0
  38. package/dist/adapters/ws.d.ts +12 -13
  39. package/dist/adapters/ws.js +30 -28
  40. package/dist/adapters/ws.mjs +12 -10
  41. package/dist/http.d.mts +1 -0
  42. package/dist/http.d.ts +1 -7
  43. package/dist/http.js +7 -7
  44. package/dist/http.mjs +1 -1
  45. package/dist/index.d.mts +9 -0
  46. package/dist/index.d.ts +5 -65
  47. package/dist/index.js +809 -46
  48. package/dist/index.mjs +798 -1
  49. package/dist/observable.d.mts +1 -0
  50. package/dist/observable.d.ts +1 -3
  51. package/dist/observable.js +8 -8
  52. package/dist/observable.mjs +1 -1
  53. package/dist/rpc.d.mts +1 -0
  54. package/dist/rpc.d.ts +1 -3
  55. package/dist/rpc.js +5 -5
  56. package/dist/rpc.mjs +1 -1
  57. package/dist/shared.d.mts +1 -0
  58. package/dist/shared.d.ts +1 -26
  59. package/dist/shared.js +4 -4
  60. package/dist/shared.mjs +1 -1
  61. package/dist/unstableDontImportMe.d.mts +1 -0
  62. package/dist/unstableDontImportMe.d.ts +1 -10
  63. package/dist/unstableDontImportMe.js +1549 -142
  64. package/dist/unstableDontImportMe.mjs +1514 -1
  65. package/package.json +6 -4
  66. package/dist/@trpc-server/http.d.ts +0 -2
  67. package/dist/@trpc-server/http.d.ts.map +0 -1
  68. package/dist/adapters/aws-lambda/index.d.ts.map +0 -1
  69. package/dist/adapters/aws-lambda/utils.d.ts +0 -48
  70. package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
  71. package/dist/adapters/aws-lambda/utils.js +0 -100
  72. package/dist/adapters/aws-lambda/utils.mjs +0 -93
  73. package/dist/adapters/express.d.ts.map +0 -1
  74. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +0 -13
  75. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +0 -1
  76. package/dist/adapters/fastify/fastifyRequestHandler.js +0 -81
  77. package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -79
  78. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -22
  79. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
  80. package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -51
  81. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -49
  82. package/dist/adapters/fastify/index.d.ts.map +0 -1
  83. package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -18
  84. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
  85. package/dist/adapters/fetch/fetchRequestHandler.js +0 -118
  86. package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -116
  87. package/dist/adapters/fetch/index.d.ts.map +0 -1
  88. package/dist/adapters/fetch/types.d.ts +0 -31
  89. package/dist/adapters/fetch/types.d.ts.map +0 -1
  90. package/dist/adapters/next.d.ts.map +0 -1
  91. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -70
  92. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
  93. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
  94. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
  95. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
  96. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
  97. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
  98. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
  99. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
  100. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
  101. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
  102. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
  103. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
  104. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
  105. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
  106. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
  107. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
  108. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
  109. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
  110. package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -42
  111. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -40
  112. package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
  113. package/dist/adapters/node-http/index.d.ts.map +0 -1
  114. package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
  115. package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
  116. package/dist/adapters/node-http/internals/contentType.js +0 -8
  117. package/dist/adapters/node-http/internals/contentType.mjs +0 -6
  118. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +0 -14
  119. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
  120. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -109
  121. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -107
  122. package/dist/adapters/node-http/types.d.ts.map +0 -1
  123. package/dist/adapters/standalone.d.ts.map +0 -1
  124. package/dist/adapters/ws.d.ts.map +0 -1
  125. package/dist/http.d.ts.map +0 -1
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
  128. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
  129. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
  130. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
  131. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
  132. package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
  133. package/dist/observable.d.ts.map +0 -1
  134. package/dist/rpc.d.ts.map +0 -1
  135. package/dist/shared.d.ts.map +0 -1
  136. package/dist/unstableDontImportMe.d.ts.map +0 -1
@@ -0,0 +1,68 @@
1
+ import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context } from 'aws-lambda';
2
+ import { AnyRouter, inferRouterContext } from '@trpc/server';
3
+ import { TRPCRequestInfo, OnErrorFunction, ResponseMetaFn, HTTPHeaders } from '@trpc/server/http';
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
+ */
15
+
16
+ type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
17
+ type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
18
+ type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
19
+ event: TEvent;
20
+ context: Context;
21
+ info: TRPCRequestInfo;
22
+ };
23
+ type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
24
+ type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = {
25
+ router: TRouter;
26
+ batching?: {
27
+ enabled: boolean;
28
+ };
29
+ onError?: OnErrorFunction<TRouter, TEvent>;
30
+ responseMeta?: ResponseMetaFn<TRouter>;
31
+ } & ({
32
+ /**
33
+ * @link https://trpc.io/docs/v11/context
34
+ **/
35
+ createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
36
+ } | {
37
+ /**
38
+ * @link https://trpc.io/docs/v11/context
39
+ **/
40
+ createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
41
+ });
42
+ declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
43
+ declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
44
+ declare function getHTTPMethod(event: APIGatewayEvent): string;
45
+ declare function getPath(event: APIGatewayEvent): string;
46
+ declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
47
+ type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
48
+ type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
49
+ declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
50
+
51
+ /**
52
+ * 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`
53
+ *
54
+ * Do **not** import from `@trpc/core`
55
+ * @example
56
+ * ```ts
57
+ * import type { AnyTRPCRouter } from '@trpc/server'
58
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
59
+ * ```
60
+ */
61
+
62
+ /** 1:1 mapping of v1 or v2 input events, deduces which is which.
63
+ * @internal
64
+ **/
65
+ type inferAPIGWReturn<TType> = TType extends APIGatewayProxyEvent ? APIGatewayProxyResult : TType extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
66
+ declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends APIGatewayEvent, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: Context) => Promise<TResult>;
67
+
68
+ export { type APIGatewayEvent, type APIGatewayPayloadFormatVersion, type APIGatewayResult, type AWSLambdaCreateContextFn, type AWSLambdaOptions, type CreateAWSLambdaContextOptions, type DefinedAPIGatewayPayloadFormats, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, awsLambdaRequestHandler, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
@@ -1,3 +1,7 @@
1
+ import { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context } from 'aws-lambda';
2
+ import { AnyRouter, inferRouterContext } from '@trpc/server';
3
+ import { TRPCRequestInfo, OnErrorFunction, ResponseMetaFn, HTTPHeaders } from '@trpc/server/http';
4
+
1
5
  /**
2
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`
3
7
  *
@@ -8,13 +12,57 @@
8
12
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
13
  * ```
10
14
  */
11
- import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyStructuredResultV2, Context as APIGWContext } from 'aws-lambda';
12
- import type { AnyRouter } from '../..';
13
- import type { APIGatewayEvent, AWSLambdaOptions } from './utils';
14
- export * from './utils';
15
+
16
+ type APIGatewayEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2;
17
+ type APIGatewayResult = APIGatewayProxyResult | APIGatewayProxyStructuredResultV2;
18
+ type CreateAWSLambdaContextOptions<TEvent extends APIGatewayEvent> = {
19
+ event: TEvent;
20
+ context: Context;
21
+ info: TRPCRequestInfo;
22
+ };
23
+ type AWSLambdaCreateContextFn<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = ({ event, context, info, }: CreateAWSLambdaContextOptions<TEvent>) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
24
+ type AWSLambdaOptions<TRouter extends AnyRouter, TEvent extends APIGatewayEvent> = {
25
+ router: TRouter;
26
+ batching?: {
27
+ enabled: boolean;
28
+ };
29
+ onError?: OnErrorFunction<TRouter, TEvent>;
30
+ responseMeta?: ResponseMetaFn<TRouter>;
31
+ } & ({
32
+ /**
33
+ * @link https://trpc.io/docs/v11/context
34
+ **/
35
+ createContext: AWSLambdaCreateContextFn<TRouter, TEvent>;
36
+ } | {
37
+ /**
38
+ * @link https://trpc.io/docs/v11/context
39
+ **/
40
+ createContext?: AWSLambdaCreateContextFn<TRouter, TEvent>;
41
+ });
42
+ declare function isPayloadV1(event: APIGatewayEvent): event is APIGatewayProxyEvent;
43
+ declare function isPayloadV2(event: APIGatewayEvent): event is APIGatewayProxyEventV2;
44
+ declare function getHTTPMethod(event: APIGatewayEvent): string;
45
+ declare function getPath(event: APIGatewayEvent): string;
46
+ declare function transformHeaders(headers: HTTPHeaders): APIGatewayResult['headers'];
47
+ type DefinedAPIGatewayPayloadFormats = '1.0' | '2.0';
48
+ type APIGatewayPayloadFormatVersion = DefinedAPIGatewayPayloadFormats | 'custom';
49
+ declare const UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE: string;
50
+
51
+ /**
52
+ * 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`
53
+ *
54
+ * Do **not** import from `@trpc/core`
55
+ * @example
56
+ * ```ts
57
+ * import type { AnyTRPCRouter } from '@trpc/server'
58
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
59
+ * ```
60
+ */
61
+
15
62
  /** 1:1 mapping of v1 or v2 input events, deduces which is which.
16
63
  * @internal
17
64
  **/
18
65
  type inferAPIGWReturn<TType> = TType extends APIGatewayProxyEvent ? APIGatewayProxyResult : TType extends APIGatewayProxyEventV2 ? APIGatewayProxyStructuredResultV2 : never;
19
- export declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends APIGatewayEvent, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: APIGWContext) => Promise<TResult>;
20
- //# sourceMappingURL=index.d.ts.map
66
+ declare function awsLambdaRequestHandler<TRouter extends AnyRouter, TEvent extends APIGatewayEvent, TResult extends inferAPIGWReturn<TEvent>>(opts: AWSLambdaOptions<TRouter, TEvent>): (event: TEvent, context: Context) => Promise<TResult>;
67
+
68
+ export { type APIGatewayEvent, type APIGatewayPayloadFormatVersion, type APIGatewayResult, type AWSLambdaCreateContextFn, type AWSLambdaOptions, type CreateAWSLambdaContextOptions, type DefinedAPIGatewayPayloadFormats, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE, awsLambdaRequestHandler, getHTTPMethod, getPath, isPayloadV1, isPayloadV2, transformHeaders };
@@ -1,7 +1,97 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- var core = require('@trpc/core');
4
- var utils = require('./utils.js');
3
+ var server = require('@trpc/server');
4
+ var http = require('@trpc/server/http');
5
+
6
+ /**
7
+ * 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`
8
+ *
9
+ * Do **not** import from `@trpc/core`
10
+ * @example
11
+ * ```ts
12
+ * import type { AnyTRPCRouter } from '@trpc/server'
13
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
14
+ * ```
15
+ */ // @trpc/server
16
+ function isPayloadV1(event) {
17
+ return determinePayloadFormat(event) == '1.0';
18
+ }
19
+ function isPayloadV2(event) {
20
+ return determinePayloadFormat(event) == '2.0';
21
+ }
22
+ function determinePayloadFormat(event) {
23
+ // https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
24
+ // According to AWS support, version is is extracted from the version property in the event.
25
+ // If there is no version property, then the version is implied as 1.0
26
+ const unknownEvent = event;
27
+ if (typeof unknownEvent.version === 'undefined') {
28
+ return '1.0';
29
+ } else {
30
+ if ([
31
+ '1.0',
32
+ '2.0'
33
+ ].includes(unknownEvent.version)) {
34
+ return unknownEvent.version;
35
+ } else {
36
+ return 'custom';
37
+ }
38
+ }
39
+ }
40
+ function getHTTPMethod(event) {
41
+ if (isPayloadV1(event)) {
42
+ return event.httpMethod;
43
+ }
44
+ if (isPayloadV2(event)) {
45
+ return event.requestContext.http.method;
46
+ }
47
+ throw new server.TRPCError({
48
+ code: 'INTERNAL_SERVER_ERROR',
49
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
50
+ });
51
+ }
52
+ function getPath(event) {
53
+ if (isPayloadV1(event)) {
54
+ if (!event.pathParameters) {
55
+ // Then this event was not triggered by a resource denoted with {proxy+}
56
+ return event.path.split('/').pop() ?? '';
57
+ }
58
+ const matches = event.resource.matchAll(/\{(.*?)\}/g);
59
+ for (const match of matches){
60
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
61
+ const group = match[1];
62
+ if (group.includes('+') && event.pathParameters) {
63
+ return event.pathParameters[group.replace('+', '')] ?? '';
64
+ }
65
+ }
66
+ return event.path.slice(1);
67
+ }
68
+ if (isPayloadV2(event)) {
69
+ const matches = event.routeKey.matchAll(/\{(.*?)\}/g);
70
+ for (const match of matches){
71
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
72
+ const group = match[1];
73
+ if (group.includes('+') && event.pathParameters) {
74
+ return event.pathParameters[group.replace('+', '')] ?? '';
75
+ }
76
+ }
77
+ return event.rawPath.slice(1);
78
+ }
79
+ throw new server.TRPCError({
80
+ code: 'INTERNAL_SERVER_ERROR',
81
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
82
+ });
83
+ }
84
+ function transformHeaders(headers) {
85
+ const obj = {};
86
+ for (const [key, value] of Object.entries(headers)){
87
+ if (typeof value === 'undefined') {
88
+ continue;
89
+ }
90
+ obj[key] = Array.isArray(value) ? value.join(',') : value;
91
+ }
92
+ return obj;
93
+ }
94
+ 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
95
 
6
96
  /**
7
97
  * 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`
@@ -27,38 +117,38 @@ function lambdaEventToHTTPRequest(event) {
27
117
  body = event.body;
28
118
  }
29
119
  return {
30
- method: utils.getHTTPMethod(event),
120
+ method: getHTTPMethod(event),
31
121
  query: query,
32
122
  headers: event.headers,
33
123
  body: body
34
124
  };
35
125
  }
36
126
  function tRPCOutputToAPIGatewayOutput(event, response) {
37
- if (utils.isPayloadV1(event)) {
127
+ if (isPayloadV1(event)) {
38
128
  const resp = {
39
129
  statusCode: response.status,
40
130
  body: response.body ?? '',
41
- headers: utils.transformHeaders(response.headers ?? {})
131
+ headers: transformHeaders(response.headers ?? {})
42
132
  };
43
133
  return resp;
44
- } else if (utils.isPayloadV2(event)) {
45
- const resp1 = {
134
+ } else if (isPayloadV2(event)) {
135
+ const resp = {
46
136
  statusCode: response.status,
47
137
  body: response.body ?? undefined,
48
- headers: utils.transformHeaders(response.headers ?? {})
138
+ headers: transformHeaders(response.headers ?? {})
49
139
  };
50
- return resp1;
140
+ return resp;
51
141
  } else {
52
- throw new core.TRPCError({
142
+ throw new server.TRPCError({
53
143
  code: 'INTERNAL_SERVER_ERROR',
54
- message: utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
144
+ message: UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE
55
145
  });
56
146
  }
57
147
  }
58
148
  function awsLambdaRequestHandler(opts) {
59
149
  return async (event, context)=>{
60
150
  const req = lambdaEventToHTTPRequest(event);
61
- const path = utils.getPath(event);
151
+ const path = getPath(event);
62
152
  const createContext = async (innerOpts)=>{
63
153
  return await opts.createContext?.({
64
154
  event,
@@ -66,7 +156,7 @@ function awsLambdaRequestHandler(opts) {
66
156
  ...innerOpts
67
157
  });
68
158
  };
69
- const response = await core.resolveHTTPResponse({
159
+ const response = await http.resolveHTTPResponse({
70
160
  router: opts.router,
71
161
  batching: opts.batching,
72
162
  responseMeta: opts?.responseMeta,
@@ -85,10 +175,10 @@ function awsLambdaRequestHandler(opts) {
85
175
  };
86
176
  }
87
177
 
88
- exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = utils.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
89
- exports.getHTTPMethod = utils.getHTTPMethod;
90
- exports.getPath = utils.getPath;
91
- exports.isPayloadV1 = utils.isPayloadV1;
92
- exports.isPayloadV2 = utils.isPayloadV2;
93
- exports.transformHeaders = utils.transformHeaders;
178
+ exports.UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE = UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE;
94
179
  exports.awsLambdaRequestHandler = awsLambdaRequestHandler;
180
+ exports.getHTTPMethod = getHTTPMethod;
181
+ exports.getPath = getPath;
182
+ exports.isPayloadV1 = isPayloadV1;
183
+ exports.isPayloadV2 = isPayloadV2;
184
+ exports.transformHeaders = transformHeaders;
@@ -1,5 +1,95 @@
1
- import { resolveHTTPResponse, TRPCError } from '@trpc/core';
2
- import { getPath, getHTTPMethod, isPayloadV1, transformHeaders, isPayloadV2, UNKNOWN_PAYLOAD_FORMAT_VERSION_ERROR_MESSAGE } from './utils.mjs';
1
+ import { TRPCError } from '@trpc/server';
2
+ import { resolveHTTPResponse } from '@trpc/server/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 matches = event.routeKey.matchAll(/\{(.*?)\}/g);
68
+ for (const match of matches){
69
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
70
+ const group = match[1];
71
+ if (group.includes('+') && event.pathParameters) {
72
+ return event.pathParameters[group.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
93
 
4
94
  /**
5
95
  * 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`
@@ -40,12 +130,12 @@ function tRPCOutputToAPIGatewayOutput(event, response) {
40
130
  };
41
131
  return resp;
42
132
  } else if (isPayloadV2(event)) {
43
- const resp1 = {
133
+ const resp = {
44
134
  statusCode: response.status,
45
135
  body: response.body ?? undefined,
46
136
  headers: transformHeaders(response.headers ?? {})
47
137
  };
48
- return resp1;
138
+ return resp;
49
139
  } else {
50
140
  throw new TRPCError({
51
141
  code: 'INTERNAL_SERVER_ERROR',
@@ -0,0 +1,19 @@
1
+ import * as express from 'express';
2
+ import { AnyRouter } from '@trpc/server';
3
+ import { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from '@trpc/server/adapters/node-http';
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
+ */
15
+
16
+ type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<express.Request, express.Response>;
17
+ declare function createExpressMiddleware<TRouter extends AnyRouter>(opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>): express.Handler;
18
+
19
+ export { type CreateExpressContextOptions, createExpressMiddleware };
@@ -1,3 +1,7 @@
1
+ import * as express from 'express';
2
+ import { AnyRouter } from '@trpc/server';
3
+ import { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from '@trpc/server/adapters/node-http';
4
+
1
5
  /**
2
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`
3
7
  *
@@ -8,9 +12,8 @@
8
12
  * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
9
13
  * ```
10
14
  */
11
- import type * as express from 'express';
12
- import type { AnyRouter } from '..';
13
- import type { NodeHTTPCreateContextFnOptions, NodeHTTPHandlerOptions } from './node-http';
14
- export type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<express.Request, express.Response>;
15
- export declare function createExpressMiddleware<TRouter extends AnyRouter>(opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>): express.Handler;
16
- //# sourceMappingURL=express.d.ts.map
15
+
16
+ type CreateExpressContextOptions = NodeHTTPCreateContextFnOptions<express.Request, express.Response>;
17
+ declare function createExpressMiddleware<TRouter extends AnyRouter>(opts: NodeHTTPHandlerOptions<TRouter, express.Request, express.Response>): express.Handler;
18
+
19
+ export { type CreateExpressContextOptions, createExpressMiddleware };
@@ -1,11 +1,11 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
3
+ var nodeHttp = require('@trpc/server/adapters/node-http');
4
4
 
5
5
  function createExpressMiddleware(opts) {
6
6
  return async (req, res)=>{
7
7
  const endpoint = req.path.slice(1);
8
- await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
8
+ await nodeHttp.nodeHTTPRequestHandler({
9
9
  // FIXME: no typecasting should be needed here
10
10
  ...opts,
11
11
  req,
@@ -1,4 +1,4 @@
1
- import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
1
+ import { nodeHTTPRequestHandler } from '@trpc/server/adapters/node-http';
2
2
 
3
3
  function createExpressMiddleware(opts) {
4
4
  return async (req, res)=>{
@@ -0,0 +1,33 @@
1
+ import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
2
+ import { AnyRouter } from '@trpc/server';
3
+ import { HTTPBaseHandlerOptions } from '@trpc/server/http';
4
+ import { NodeHTTPCreateContextOption, NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
5
+
6
+ type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
7
+ type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
8
+ req: TRequest;
9
+ res: TResponse;
10
+ path: string;
11
+ };
12
+ declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
13
+
14
+ /**
15
+ * 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`
16
+ *
17
+ * Do **not** import from `@trpc/core`
18
+ * @example
19
+ * ```ts
20
+ * import type { AnyTRPCRouter } from '@trpc/server'
21
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
22
+ * ```
23
+ */
24
+
25
+ interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
26
+ prefix?: string;
27
+ useWSS?: boolean;
28
+ trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;
29
+ }
30
+ type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
31
+ declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
32
+
33
+ export { type CreateFastifyContextOptions, type FastifyHandlerOptions, type FastifyTRPCPluginOptions, fastifyRequestHandler, fastifyTRPCPlugin };
@@ -1,3 +1,33 @@
1
- export * from './fastifyRequestHandler';
2
- export * from './fastifyTRPCPlugin';
3
- //# sourceMappingURL=index.d.ts.map
1
+ import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
2
+ import { AnyRouter } from '@trpc/server';
3
+ import { HTTPBaseHandlerOptions } from '@trpc/server/http';
4
+ import { NodeHTTPCreateContextOption, NodeHTTPCreateContextFnOptions } from '@trpc/server/adapters/node-http';
5
+
6
+ type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse>;
7
+ type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
8
+ req: TRequest;
9
+ res: TResponse;
10
+ path: string;
11
+ };
12
+ declare function fastifyRequestHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>(opts: FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>): Promise<never>;
13
+
14
+ /**
15
+ * 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`
16
+ *
17
+ * Do **not** import from `@trpc/core`
18
+ * @example
19
+ * ```ts
20
+ * import type { AnyTRPCRouter } from '@trpc/server'
21
+ * import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
22
+ * ```
23
+ */
24
+
25
+ interface FastifyTRPCPluginOptions<TRouter extends AnyRouter> {
26
+ prefix?: string;
27
+ useWSS?: boolean;
28
+ trpcOptions: FastifyHandlerOptions<TRouter, FastifyRequest, FastifyReply>;
29
+ }
30
+ type CreateFastifyContextOptions = NodeHTTPCreateContextFnOptions<FastifyRequest, FastifyReply>;
31
+ declare function fastifyTRPCPlugin<TRouter extends AnyRouter>(fastify: FastifyInstance, opts: FastifyTRPCPluginOptions<TRouter>, done: (err?: Error) => void): void;
32
+
33
+ export { type CreateFastifyContextOptions, type FastifyHandlerOptions, type FastifyTRPCPluginOptions, fastifyRequestHandler, fastifyTRPCPlugin };