@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
@@ -1,7 +1,7 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- var core = require('@trpc/core');
4
- var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
3
+ var server = require('@trpc/server');
4
+ var nodeHttp = require('@trpc/server/adapters/node-http');
5
5
 
6
6
  /**
7
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`
@@ -26,9 +26,9 @@ function createNextApiHandler(opts) {
26
26
  }
27
27
  const path = getPath();
28
28
  if (path === null) {
29
- const error = core.getErrorShape({
29
+ const error = server.getErrorShape({
30
30
  config: opts.router._def._config,
31
- error: new core.TRPCError({
31
+ error: new server.TRPCError({
32
32
  message: 'Query "trpc" not found - is the file named `[trpc]`.ts or `[...trpc].ts`?',
33
33
  code: 'INTERNAL_SERVER_ERROR'
34
34
  }),
@@ -44,7 +44,7 @@ function createNextApiHandler(opts) {
44
44
  });
45
45
  return;
46
46
  }
47
- await nodeHTTPRequestHandler.nodeHTTPRequestHandler({
47
+ await nodeHttp.nodeHTTPRequestHandler({
48
48
  // FIXME: no typecasting should be needed here
49
49
  ...opts,
50
50
  req,
@@ -1,5 +1,5 @@
1
- import { getErrorShape, TRPCError } from '@trpc/core';
2
- import { nodeHTTPRequestHandler } from './node-http/nodeHTTPRequestHandler.mjs';
1
+ import { getErrorShape, TRPCError } from '@trpc/server';
2
+ import { nodeHTTPRequestHandler } from '@trpc/server/adapters/node-http';
3
3
 
4
4
  /**
5
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`
@@ -0,0 +1,219 @@
1
+ import { AnyRouter, inferRouterContext } from '@trpc/server';
2
+ import { HTTPBaseHandlerOptions, MaybePromise, TRPCRequestInfo, BaseContentTypeHandler } from '@trpc/core';
3
+ import { IncomingMessage, ServerResponse } from '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
+ interface ParsedQs {
17
+ [key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
18
+ }
19
+ type NodeHTTPRequest = IncomingMessage & {
20
+ query?: ParsedQs;
21
+ body?: unknown;
22
+ };
23
+ type NodeHTTPResponse = ServerResponse & {
24
+ /**
25
+ * Force the partially-compressed response to be flushed to the client.
26
+ *
27
+ * Added by compression middleware
28
+ * (depending on the environment,
29
+ * e.g. Next <= 12,
30
+ * e.g. Express w/ `compression()`)
31
+ */
32
+ flush?: () => void;
33
+ };
34
+ type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = object extends inferRouterContext<TRouter> ? {
35
+ /**
36
+ * @link https://trpc.io/docs/v11/context
37
+ **/
38
+ createContext?: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
39
+ } : {
40
+ /**
41
+ * @link https://trpc.io/docs/v11/context
42
+ **/
43
+ createContext: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
44
+ };
45
+ /**
46
+ * @internal
47
+ */
48
+ type ConnectMiddleware<TRequest extends NodeHTTPRequest = NodeHTTPRequest, TResponse extends NodeHTTPResponse = NodeHTTPResponse> = (req: TRequest, res: TResponse, next: (err?: any) => any) => void;
49
+ type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse> & {
50
+ /**
51
+ * By default, http `OPTIONS` requests are not handled, and CORS headers are not returned.
52
+ *
53
+ * This can be used to handle them manually or via the `cors` npm package: https://www.npmjs.com/package/cors
54
+ *
55
+ * ```ts
56
+ * import cors from 'cors'
57
+ *
58
+ * nodeHTTPRequestHandler({
59
+ * cors: cors()
60
+ * })
61
+ * ```
62
+ *
63
+ * You can also use it for other needs which a connect/node.js compatible middleware can solve,
64
+ * though you might wish to consider an alternative solution like the Express adapter if your needs are complex.
65
+ */
66
+ middleware?: ConnectMiddleware;
67
+ maxBodySize?: number;
68
+ experimental_contentTypeHandlers?: NodeHTTPContentTypeHandler<TRequest, TResponse>[];
69
+ };
70
+ type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
71
+ req: TRequest;
72
+ res: TResponse;
73
+ path: string;
74
+ } & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
75
+ type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
76
+ req: TRequest;
77
+ res: TResponse;
78
+ info: TRPCRequestInfo;
79
+ };
80
+ type NodeHTTPCreateContextFn<TRouter extends AnyRouter, TRequest, TResponse> = (opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>) => MaybePromise<inferRouterContext<TRouter>>;
81
+
82
+ interface NodeHTTPContentTypeHandler<TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<AnyRouter, TRequest, TResponse> & {
83
+ query: URLSearchParams;
84
+ }> {
85
+ }
86
+
87
+ type FileUploadHandlerFilterArgs = {
88
+ filename: string;
89
+ contentType: string;
90
+ name: string;
91
+ };
92
+ type FileUploadHandlerPathResolverArgs = {
93
+ filename: string;
94
+ contentType: string;
95
+ name: string;
96
+ };
97
+ /**
98
+ * Chooses the path of the file to be uploaded. If a string is not
99
+ * returned the file will not be written.
100
+ */
101
+ type FileUploadHandlerPathResolver = (args: FileUploadHandlerPathResolverArgs) => string | undefined;
102
+ type FileUploadHandlerOptions = {
103
+ /**
104
+ * Avoid file conflicts by appending a count on the end of the filename
105
+ * if it already exists on disk. Defaults to `true`.
106
+ */
107
+ avoidFileConflicts?: boolean;
108
+ /**
109
+ * The directory to write the upload.
110
+ */
111
+ directory?: FileUploadHandlerPathResolver | string;
112
+ /**
113
+ * The name of the file in the directory. Can be a relative path, the directory
114
+ * structure will be created if it does not exist.
115
+ */
116
+ file?: FileUploadHandlerPathResolver;
117
+ /**
118
+ * The maximum upload size allowed. If the size is exceeded an error will be thrown.
119
+ * Defaults to 3000000B (3MB).
120
+ */
121
+ maxPartSize?: number;
122
+ /**
123
+ *
124
+ * @param filename
125
+ * @param contentType
126
+ * @param name
127
+ */
128
+ filter?(args: FileUploadHandlerFilterArgs): Promise<boolean> | boolean;
129
+ };
130
+ declare function createFileUploadHandler({ directory, avoidFileConflicts, file, filter, maxPartSize, }?: FileUploadHandlerOptions): UploadHandler;
131
+ declare class NodeOnDiskFile {
132
+ private filepath;
133
+ type: string;
134
+ private slicer?;
135
+ name: string;
136
+ lastModified: number;
137
+ webkitRelativePath: string;
138
+ constructor(filepath: string, type: string, slicer?: {
139
+ start: number;
140
+ end: number;
141
+ } | undefined);
142
+ get size(): number;
143
+ slice(start?: number, end?: number, type?: string): NodeOnDiskFile;
144
+ arrayBuffer(): Promise<ArrayBuffer>;
145
+ stream(): ReadableStream<any>;
146
+ stream(): NodeJS.ReadableStream;
147
+ text(): Promise<string>;
148
+ readonly [Symbol.toStringTag] = "File";
149
+ remove(): Promise<void>;
150
+ getFilePath(): string;
151
+ }
152
+
153
+ /**
154
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
155
+ */
156
+ type UploadHandlerPart = {
157
+ name: string;
158
+ filename?: string;
159
+ contentType: string;
160
+ data: AsyncIterable<Uint8Array>;
161
+ };
162
+ type UploadHandler = (part: Required<UploadHandlerPart>) => Promise<File | NodeOnDiskFile | null | undefined>;
163
+ declare function composeUploadHandlers(...handlers: UploadHandler[]): UploadHandler;
164
+ declare class MaxPartSizeExceededError extends Error {
165
+ field: string;
166
+ maxBytes: number;
167
+ constructor(field: string, maxBytes: number);
168
+ }
169
+ declare class MaxBodySizeExceededError extends Error {
170
+ maxBytes: number;
171
+ constructor(maxBytes: number);
172
+ }
173
+
174
+ /**
175
+ * Copyright 2021 Remix Software Inc.
176
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
177
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
178
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
179
+ */
180
+ /**
181
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
182
+ */
183
+
184
+ type MemoryUploadHandlerFilterArgs = {
185
+ filename?: string;
186
+ contentType: string;
187
+ name: string;
188
+ };
189
+ type MemoryUploadHandlerOptions = {
190
+ /**
191
+ * The maximum upload size allowed. If the size is exceeded an error will be thrown.
192
+ * Defaults to 3000000B (3MB).
193
+ */
194
+ maxPartSize?: number;
195
+ /**
196
+ *
197
+ * @param filename
198
+ * @param mimetype
199
+ * @param encoding
200
+ */
201
+ filter?(args: MemoryUploadHandlerFilterArgs): Promise<boolean> | boolean;
202
+ };
203
+ declare function createMemoryUploadHandler({ filter, maxPartSize, }?: MemoryUploadHandlerOptions): UploadHandler;
204
+
205
+ /**
206
+ * Allows you to handle multipart forms (file uploads) for your app.
207
+ * Request body parts with a 'filename' property will be treated as files.
208
+ * The rest will be treated as text.
209
+ * @param request The incoming Node HTTP request
210
+ * @param uploadHandler A function that handles file uploads and returns a value to be used in the request body. If uploaded to disk, the returned value is a NodeOnDiskFile. If uploaded to memory, the returned value is a File.
211
+ * @param maxBodySize The maximum size of the request body in bytes. Defaults to Infinity.
212
+ *
213
+ * @link https://remix.run/utils/parse-multipart-form-data
214
+ */
215
+ declare function parseMultipartFormData(request: NodeHTTPRequest, uploadHandler: UploadHandler, maxBodySize?: number): Promise<FormData>;
216
+ declare function isMultipartFormDataRequest(req: NodeHTTPRequest): boolean;
217
+ declare const nodeHTTPFormDataContentTypeHandler: <TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>() => NodeHTTPContentTypeHandler<TRequest, TResponse>;
218
+
219
+ export { MaxBodySizeExceededError, MaxPartSizeExceededError, type UploadHandler, NodeOnDiskFile as experimental_NodeOnDiskFile, composeUploadHandlers as experimental_composeUploadHandlers, createFileUploadHandler as experimental_createFileUploadHandler, createMemoryUploadHandler as experimental_createMemoryUploadHandler, isMultipartFormDataRequest as experimental_isMultipartFormDataRequest, parseMultipartFormData as experimental_parseMultipartFormData, nodeHTTPFormDataContentTypeHandler };
@@ -1,11 +1,207 @@
1
+ import { AnyRouter, inferRouterContext } from '@trpc/server';
2
+ import { HTTPBaseHandlerOptions, MaybePromise, TRPCRequestInfo, BaseContentTypeHandler } from '@trpc/core';
3
+ import { IncomingMessage, ServerResponse } from '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
+ interface ParsedQs {
17
+ [key: string]: ParsedQs | ParsedQs[] | string[] | string | undefined;
18
+ }
19
+ type NodeHTTPRequest = IncomingMessage & {
20
+ query?: ParsedQs;
21
+ body?: unknown;
22
+ };
23
+ type NodeHTTPResponse = ServerResponse & {
24
+ /**
25
+ * Force the partially-compressed response to be flushed to the client.
26
+ *
27
+ * Added by compression middleware
28
+ * (depending on the environment,
29
+ * e.g. Next <= 12,
30
+ * e.g. Express w/ `compression()`)
31
+ */
32
+ flush?: () => void;
33
+ };
34
+ type NodeHTTPCreateContextOption<TRouter extends AnyRouter, TRequest, TResponse> = object extends inferRouterContext<TRouter> ? {
35
+ /**
36
+ * @link https://trpc.io/docs/v11/context
37
+ **/
38
+ createContext?: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
39
+ } : {
40
+ /**
41
+ * @link https://trpc.io/docs/v11/context
42
+ **/
43
+ createContext: NodeHTTPCreateContextFn<TRouter, TRequest, TResponse>;
44
+ };
45
+ /**
46
+ * @internal
47
+ */
48
+ type ConnectMiddleware<TRequest extends NodeHTTPRequest = NodeHTTPRequest, TResponse extends NodeHTTPResponse = NodeHTTPResponse> = (req: TRequest, res: TResponse, next: (err?: any) => any) => void;
49
+ type NodeHTTPHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPCreateContextOption<TRouter, TRequest, TResponse> & {
50
+ /**
51
+ * By default, http `OPTIONS` requests are not handled, and CORS headers are not returned.
52
+ *
53
+ * This can be used to handle them manually or via the `cors` npm package: https://www.npmjs.com/package/cors
54
+ *
55
+ * ```ts
56
+ * import cors from 'cors'
57
+ *
58
+ * nodeHTTPRequestHandler({
59
+ * cors: cors()
60
+ * })
61
+ * ```
62
+ *
63
+ * You can also use it for other needs which a connect/node.js compatible middleware can solve,
64
+ * though you might wish to consider an alternative solution like the Express adapter if your needs are complex.
65
+ */
66
+ middleware?: ConnectMiddleware;
67
+ maxBodySize?: number;
68
+ experimental_contentTypeHandlers?: NodeHTTPContentTypeHandler<TRequest, TResponse>[];
69
+ };
70
+ type NodeHTTPRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> = {
71
+ req: TRequest;
72
+ res: TResponse;
73
+ path: string;
74
+ } & NodeHTTPHandlerOptions<TRouter, TRequest, TResponse>;
75
+ type NodeHTTPCreateContextFnOptions<TRequest, TResponse> = {
76
+ req: TRequest;
77
+ res: TResponse;
78
+ info: TRPCRequestInfo;
79
+ };
80
+ type NodeHTTPCreateContextFn<TRouter extends AnyRouter, TRequest, TResponse> = (opts: NodeHTTPCreateContextFnOptions<TRequest, TResponse>) => MaybePromise<inferRouterContext<TRouter>>;
81
+
82
+ interface NodeHTTPContentTypeHandler<TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<AnyRouter, TRequest, TResponse> & {
83
+ query: URLSearchParams;
84
+ }> {
85
+ }
86
+
87
+ type FileUploadHandlerFilterArgs = {
88
+ filename: string;
89
+ contentType: string;
90
+ name: string;
91
+ };
92
+ type FileUploadHandlerPathResolverArgs = {
93
+ filename: string;
94
+ contentType: string;
95
+ name: string;
96
+ };
97
+ /**
98
+ * Chooses the path of the file to be uploaded. If a string is not
99
+ * returned the file will not be written.
100
+ */
101
+ type FileUploadHandlerPathResolver = (args: FileUploadHandlerPathResolverArgs) => string | undefined;
102
+ type FileUploadHandlerOptions = {
103
+ /**
104
+ * Avoid file conflicts by appending a count on the end of the filename
105
+ * if it already exists on disk. Defaults to `true`.
106
+ */
107
+ avoidFileConflicts?: boolean;
108
+ /**
109
+ * The directory to write the upload.
110
+ */
111
+ directory?: FileUploadHandlerPathResolver | string;
112
+ /**
113
+ * The name of the file in the directory. Can be a relative path, the directory
114
+ * structure will be created if it does not exist.
115
+ */
116
+ file?: FileUploadHandlerPathResolver;
117
+ /**
118
+ * The maximum upload size allowed. If the size is exceeded an error will be thrown.
119
+ * Defaults to 3000000B (3MB).
120
+ */
121
+ maxPartSize?: number;
122
+ /**
123
+ *
124
+ * @param filename
125
+ * @param contentType
126
+ * @param name
127
+ */
128
+ filter?(args: FileUploadHandlerFilterArgs): Promise<boolean> | boolean;
129
+ };
130
+ declare function createFileUploadHandler({ directory, avoidFileConflicts, file, filter, maxPartSize, }?: FileUploadHandlerOptions): UploadHandler;
131
+ declare class NodeOnDiskFile {
132
+ private filepath;
133
+ type: string;
134
+ private slicer?;
135
+ name: string;
136
+ lastModified: number;
137
+ webkitRelativePath: string;
138
+ constructor(filepath: string, type: string, slicer?: {
139
+ start: number;
140
+ end: number;
141
+ } | undefined);
142
+ get size(): number;
143
+ slice(start?: number, end?: number, type?: string): NodeOnDiskFile;
144
+ arrayBuffer(): Promise<ArrayBuffer>;
145
+ stream(): ReadableStream<any>;
146
+ stream(): NodeJS.ReadableStream;
147
+ text(): Promise<string>;
148
+ readonly [Symbol.toStringTag] = "File";
149
+ remove(): Promise<void>;
150
+ getFilePath(): string;
151
+ }
152
+
153
+ /**
154
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
155
+ */
156
+ type UploadHandlerPart = {
157
+ name: string;
158
+ filename?: string;
159
+ contentType: string;
160
+ data: AsyncIterable<Uint8Array>;
161
+ };
162
+ type UploadHandler = (part: Required<UploadHandlerPart>) => Promise<File | NodeOnDiskFile | null | undefined>;
163
+ declare function composeUploadHandlers(...handlers: UploadHandler[]): UploadHandler;
164
+ declare class MaxPartSizeExceededError extends Error {
165
+ field: string;
166
+ maxBytes: number;
167
+ constructor(field: string, maxBytes: number);
168
+ }
169
+ declare class MaxBodySizeExceededError extends Error {
170
+ maxBytes: number;
171
+ constructor(maxBytes: number);
172
+ }
173
+
1
174
  /**
2
175
  * Copyright 2021 Remix Software Inc.
3
176
  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
177
  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
178
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6
179
  */
7
- import type { NodeHTTPRequest } from '../../types';
8
- import type { UploadHandler } from './uploadHandler';
180
+ /**
181
+ * @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
182
+ */
183
+
184
+ type MemoryUploadHandlerFilterArgs = {
185
+ filename?: string;
186
+ contentType: string;
187
+ name: string;
188
+ };
189
+ type MemoryUploadHandlerOptions = {
190
+ /**
191
+ * The maximum upload size allowed. If the size is exceeded an error will be thrown.
192
+ * Defaults to 3000000B (3MB).
193
+ */
194
+ maxPartSize?: number;
195
+ /**
196
+ *
197
+ * @param filename
198
+ * @param mimetype
199
+ * @param encoding
200
+ */
201
+ filter?(args: MemoryUploadHandlerFilterArgs): Promise<boolean> | boolean;
202
+ };
203
+ declare function createMemoryUploadHandler({ filter, maxPartSize, }?: MemoryUploadHandlerOptions): UploadHandler;
204
+
9
205
  /**
10
206
  * Allows you to handle multipart forms (file uploads) for your app.
11
207
  * Request body parts with a 'filename' property will be treated as files.
@@ -18,11 +214,6 @@ import type { UploadHandler } from './uploadHandler';
18
214
  */
19
215
  declare function parseMultipartFormData(request: NodeHTTPRequest, uploadHandler: UploadHandler, maxBodySize?: number): Promise<FormData>;
20
216
  declare function isMultipartFormDataRequest(req: NodeHTTPRequest): boolean;
21
- export declare const nodeHTTPFormDataContentTypeHandler: <TRequest extends NodeHTTPRequest, TResponse extends import("../../types").NodeHTTPResponse>() => import("../../internals/contentType").NodeHTTPContentTypeHandler<TRequest, TResponse>;
22
- export { parseMultipartFormData as experimental_parseMultipartFormData };
23
- export { createMemoryUploadHandler as experimental_createMemoryUploadHandler } from './memoryUploadHandler';
24
- export { createFileUploadHandler as experimental_createFileUploadHandler, NodeOnDiskFile as experimental_NodeOnDiskFile, } from './fileUploadHandler';
25
- export { composeUploadHandlers as experimental_composeUploadHandlers, MaxPartSizeExceededError, MaxBodySizeExceededError, } from './uploadHandler';
26
- export { type UploadHandler } from './uploadHandler';
27
- export { isMultipartFormDataRequest as experimental_isMultipartFormDataRequest };
28
- //# sourceMappingURL=index.d.ts.map
217
+ declare const nodeHTTPFormDataContentTypeHandler: <TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>() => NodeHTTPContentTypeHandler<TRequest, TResponse>;
218
+
219
+ export { MaxBodySizeExceededError, MaxPartSizeExceededError, type UploadHandler, NodeOnDiskFile as experimental_NodeOnDiskFile, composeUploadHandlers as experimental_composeUploadHandlers, createFileUploadHandler as experimental_createFileUploadHandler, createMemoryUploadHandler as experimental_createMemoryUploadHandler, isMultipartFormDataRequest as experimental_isMultipartFormDataRequest, parseMultipartFormData as experimental_parseMultipartFormData, nodeHTTPFormDataContentTypeHandler };