@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.
- package/dist/adapters/aws-lambda/index.d.mts +68 -0
- package/dist/adapters/aws-lambda/index.d.ts +54 -6
- package/dist/adapters/aws-lambda/index.js +110 -20
- package/dist/adapters/aws-lambda/index.mjs +94 -4
- package/dist/adapters/express.d.mts +19 -0
- package/dist/adapters/express.d.ts +9 -6
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/index.d.mts +33 -0
- package/dist/adapters/fastify/index.d.ts +33 -3
- package/dist/adapters/fastify/index.js +124 -5
- package/dist/adapters/fastify/index.mjs +125 -2
- package/dist/adapters/fetch/index.d.mts +51 -0
- package/dist/adapters/fetch/index.d.ts +51 -3
- package/dist/adapters/fetch/index.js +115 -4
- package/dist/adapters/fetch/index.mjs +116 -1
- package/dist/adapters/next.d.mts +21 -0
- package/dist/adapters/next.d.ts +11 -7
- package/dist/adapters/next.js +6 -6
- package/dist/adapters/next.mjs +2 -2
- package/dist/adapters/node-http/content-type/form-data/index.d.mts +219 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +201 -10
- package/dist/adapters/node-http/content-type/form-data/index.js +662 -23
- package/dist/adapters/node-http/content-type/form-data/index.mjs +646 -10
- package/dist/adapters/node-http/{types.d.ts → content-type/json/index.d.mts} +21 -15
- package/dist/adapters/node-http/content-type/json/index.d.ts +89 -2
- package/dist/adapters/node-http/content-type/json/index.js +48 -7
- package/dist/adapters/node-http/content-type/json/index.mjs +44 -3
- package/dist/adapters/node-http/index.d.mts +100 -0
- package/dist/adapters/node-http/index.d.ts +100 -3
- package/dist/adapters/node-http/index.js +106 -4
- package/dist/adapters/node-http/index.mjs +107 -1
- package/dist/adapters/standalone.d.mts +21 -0
- package/dist/adapters/standalone.d.ts +11 -9
- package/dist/adapters/standalone.js +9 -5
- package/dist/adapters/standalone.mjs +2 -2
- package/dist/adapters/ws.d.mts +36 -0
- package/dist/adapters/ws.d.ts +12 -13
- package/dist/adapters/ws.js +30 -28
- package/dist/adapters/ws.mjs +12 -10
- package/dist/http.d.mts +1 -0
- package/dist/http.d.ts +1 -7
- package/dist/http.js +7 -7
- package/dist/http.mjs +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +5 -65
- package/dist/index.js +809 -46
- package/dist/index.mjs +798 -1
- package/dist/observable.d.mts +1 -0
- package/dist/observable.d.ts +1 -3
- package/dist/observable.js +8 -8
- package/dist/observable.mjs +1 -1
- package/dist/rpc.d.mts +1 -0
- package/dist/rpc.d.ts +1 -3
- package/dist/rpc.js +5 -5
- package/dist/rpc.mjs +1 -1
- package/dist/shared.d.mts +1 -0
- package/dist/shared.d.ts +1 -26
- package/dist/shared.js +4 -4
- package/dist/shared.mjs +1 -1
- package/dist/unstableDontImportMe.d.mts +1 -0
- package/dist/unstableDontImportMe.d.ts +1 -10
- package/dist/unstableDontImportMe.js +1549 -142
- package/dist/unstableDontImportMe.mjs +1514 -1
- package/package.json +6 -4
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.d.ts +0 -48
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -100
- package/dist/adapters/aws-lambda/utils.mjs +0 -93
- package/dist/adapters/express.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +0 -13
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +0 -81
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -79
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -22
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -51
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -49
- package/dist/adapters/fastify/index.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -18
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +0 -118
- package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -116
- package/dist/adapters/fetch/index.d.ts.map +0 -1
- package/dist/adapters/fetch/types.d.ts +0 -31
- package/dist/adapters/fetch/types.d.ts.map +0 -1
- package/dist/adapters/next.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -70
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -42
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -40
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/index.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +0 -14
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -109
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -107
- package/dist/adapters/node-http/types.d.ts.map +0 -1
- package/dist/adapters/standalone.d.ts.map +0 -1
- package/dist/adapters/ws.d.ts.map +0 -1
- package/dist/http.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
- package/dist/observable.d.ts.map +0 -1
- package/dist/rpc.d.ts.map +0 -1
- package/dist/shared.d.ts.map +0 -1
- package/dist/unstableDontImportMe.d.ts.map +0 -1
package/dist/adapters/next.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
'
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
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 =
|
|
29
|
+
const error = server.getErrorShape({
|
|
30
30
|
config: opts.router._def._config,
|
|
31
|
-
error: new
|
|
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
|
|
47
|
+
await nodeHttp.nodeHTTPRequestHandler({
|
|
48
48
|
// FIXME: no typecasting should be needed here
|
|
49
49
|
...opts,
|
|
50
50
|
req,
|
package/dist/adapters/next.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getErrorShape, TRPCError } from '@trpc/
|
|
2
|
-
import { nodeHTTPRequestHandler } from '
|
|
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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
export { createMemoryUploadHandler as experimental_createMemoryUploadHandler
|
|
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 };
|