@trpc/server 11.0.0-rc.347 → 11.0.0-rc.351

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 (157) hide show
  1. package/dist/@trpc/server/http.d.ts +1 -0
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/@trpc/server/index.d.ts +1 -2
  4. package/dist/@trpc/server/index.d.ts.map +1 -1
  5. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  6. package/dist/adapters/aws-lambda/index.js +9 -19
  7. package/dist/adapters/aws-lambda/index.mjs +9 -19
  8. package/dist/adapters/aws-lambda/utils.d.ts +12 -3
  9. package/dist/adapters/aws-lambda/utils.d.ts.map +1 -1
  10. package/dist/adapters/aws-lambda/utils.js +1 -12
  11. package/dist/adapters/aws-lambda/utils.mjs +2 -12
  12. package/dist/adapters/express.d.ts.map +1 -1
  13. package/dist/adapters/express.js +1 -0
  14. package/dist/adapters/express.mjs +1 -0
  15. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +9 -1
  16. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  17. package/dist/adapters/fastify/fastifyRequestHandler.js +2 -10
  18. package/dist/adapters/fastify/fastifyRequestHandler.mjs +2 -10
  19. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +1 -1
  20. package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +1 -1
  21. package/dist/adapters/fetch/fetchRequestHandler.d.ts +5 -1
  22. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  23. package/dist/adapters/fetch/fetchRequestHandler.js +2 -16
  24. package/dist/adapters/fetch/fetchRequestHandler.mjs +2 -16
  25. package/dist/adapters/fetch/types.d.ts +12 -9
  26. package/dist/adapters/fetch/types.d.ts.map +1 -1
  27. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +7 -2
  28. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
  29. package/dist/adapters/next.d.ts.map +1 -1
  30. package/dist/adapters/next.js +1 -0
  31. package/dist/adapters/next.mjs +1 -0
  32. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +73 -0
  33. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +1 -0
  34. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +161 -0
  35. package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +157 -0
  36. package/dist/adapters/node-http/content-type/form-data/index.d.ts +25 -4
  37. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
  38. package/dist/adapters/node-http/content-type/form-data/index.js +128 -25
  39. package/dist/adapters/node-http/content-type/form-data/index.mjs +103 -25
  40. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +31 -0
  41. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +1 -0
  42. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +29 -0
  43. package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +27 -0
  44. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +16 -0
  45. package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +1 -0
  46. package/dist/adapters/node-http/content-type/form-data/streamSlice.js +46 -0
  47. package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +44 -0
  48. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +45 -0
  49. package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +1 -0
  50. package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +30 -0
  51. package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +26 -0
  52. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +1 -1
  53. package/dist/adapters/node-http/content-type/json/getPostBody.js +12 -4
  54. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +12 -4
  55. package/dist/adapters/node-http/content-type/json/index.d.ts +1 -4
  56. package/dist/adapters/node-http/content-type/json/index.d.ts.map +1 -1
  57. package/dist/adapters/node-http/content-type/json/index.js +10 -59
  58. package/dist/adapters/node-http/content-type/json/index.mjs +10 -59
  59. package/dist/adapters/node-http/internals/contentType.d.ts +9 -0
  60. package/dist/adapters/node-http/internals/contentType.d.ts.map +1 -0
  61. package/dist/adapters/node-http/internals/contentType.js +8 -0
  62. package/dist/adapters/node-http/internals/contentType.mjs +6 -0
  63. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  64. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +21 -19
  65. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +22 -20
  66. package/dist/adapters/node-http/types.d.ts +19 -8
  67. package/dist/adapters/node-http/types.d.ts.map +1 -1
  68. package/dist/adapters/standalone.d.ts.map +1 -1
  69. package/dist/adapters/standalone.js +1 -0
  70. package/dist/adapters/standalone.mjs +1 -0
  71. package/dist/adapters/ws.d.ts +12 -2
  72. package/dist/adapters/ws.d.ts.map +1 -1
  73. package/dist/bundle-analysis.json +237 -231
  74. package/dist/http.js +2 -0
  75. package/dist/http.mjs +1 -0
  76. package/dist/index.js +0 -2
  77. package/dist/index.mjs +0 -1
  78. package/dist/unstable-core-do-not-import/http/contentType.d.ts +15 -7
  79. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  80. package/dist/unstable-core-do-not-import/http/contentType.js +54 -0
  81. package/dist/unstable-core-do-not-import/http/contentType.mjs +52 -0
  82. package/dist/unstable-core-do-not-import/http/index.d.ts +1 -0
  83. package/dist/unstable-core-do-not-import/http/index.d.ts.map +1 -1
  84. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +5 -5
  85. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
  86. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +22 -25
  87. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +22 -25
  88. package/dist/unstable-core-do-not-import/http/types.d.ts +2 -0
  89. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  90. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -21
  91. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  92. package/dist/unstable-core-do-not-import.js +2 -0
  93. package/dist/unstable-core-do-not-import.mjs +1 -0
  94. package/package.json +3 -2
  95. package/src/@trpc/server/http.ts +1 -0
  96. package/src/@trpc/server/index.ts +0 -4
  97. package/src/adapters/aws-lambda/index.ts +9 -24
  98. package/src/adapters/aws-lambda/utils.ts +15 -21
  99. package/src/adapters/express.ts +6 -1
  100. package/src/adapters/fastify/fastifyRequestHandler.ts +21 -15
  101. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
  102. package/src/adapters/fetch/fetchRequestHandler.ts +10 -22
  103. package/src/adapters/fetch/types.ts +15 -22
  104. package/src/adapters/next-app-dir/nextAppDirCaller.ts +9 -2
  105. package/src/adapters/next.ts +6 -1
  106. package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +277 -0
  107. package/src/adapters/node-http/content-type/form-data/index.ts +159 -33
  108. package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +56 -0
  109. package/src/adapters/node-http/content-type/form-data/streamSlice.ts +56 -0
  110. package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +89 -0
  111. package/src/adapters/node-http/content-type/json/getPostBody.ts +18 -9
  112. package/src/adapters/node-http/content-type/json/index.ts +7 -87
  113. package/src/adapters/node-http/{content-type/types.ts → internals/contentType.ts} +14 -2
  114. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +35 -22
  115. package/src/adapters/node-http/types.ts +46 -46
  116. package/src/adapters/standalone.ts +2 -1
  117. package/src/adapters/ws.ts +14 -9
  118. package/src/unstable-core-do-not-import/http/contentType.ts +85 -10
  119. package/src/unstable-core-do-not-import/http/index.ts +1 -0
  120. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +28 -29
  121. package/src/unstable-core-do-not-import/http/types.ts +2 -0
  122. package/src/unstable-core-do-not-import/rootConfig.ts +0 -31
  123. package/dist/adapters/aws-lambda/content-type/json/index.d.ts +0 -10
  124. package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
  125. package/dist/adapters/aws-lambda/content-type/json/index.js +0 -59
  126. package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -57
  127. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
  128. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
  129. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
  130. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
  131. package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
  132. package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
  133. package/dist/adapters/fastify/content-type/json/index.js +0 -59
  134. package/dist/adapters/fastify/content-type/json/index.mjs +0 -57
  135. package/dist/adapters/fastify/types.d.ts +0 -11
  136. package/dist/adapters/fastify/types.d.ts.map +0 -1
  137. package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
  138. package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
  139. package/dist/adapters/fetch/content-type/json/index.js +0 -58
  140. package/dist/adapters/fetch/content-type/json/index.mjs +0 -56
  141. package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
  142. package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
  143. package/dist/adapters/node-http/content-type/octet/index.js +0 -19
  144. package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
  145. package/dist/adapters/node-http/content-type/types.d.ts +0 -8
  146. package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
  147. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
  148. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
  149. package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
  150. package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
  151. package/src/adapters/aws-lambda/content-type/json/index.ts +0 -99
  152. package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
  153. package/src/adapters/fastify/content-type/json/index.ts +0 -97
  154. package/src/adapters/fastify/types.ts +0 -22
  155. package/src/adapters/fetch/content-type/json/index.ts +0 -94
  156. package/src/adapters/node-http/content-type/octet/index.ts +0 -27
  157. package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
@@ -1,97 +0,0 @@
1
- // @trpc/server
2
- import type { FastifyReply, FastifyRequest } from 'fastify';
3
- import { TRPCError } from '../../../../@trpc/server';
4
- import type {
5
- AnyRouter,
6
- CombinedDataTransformer,
7
- } from '../../../../@trpc/server';
8
- import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
9
- import type { FastifyRequestHandlerOptions } from '../../types';
10
-
11
- export interface FastifyHTTPContentTypeHandler<
12
- TRouter extends AnyRouter,
13
- TRequest extends FastifyRequest,
14
- TResponse extends FastifyReply,
15
- > extends BaseContentTypeHandler<
16
- FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>
17
- > {}
18
-
19
- export const getFastifyHTTPJSONContentTypeHandler: <
20
- TRouter extends AnyRouter,
21
- TRequest extends FastifyRequest,
22
- TResponse extends FastifyReply,
23
- >() => FastifyHTTPContentTypeHandler<TRouter, TRequest, TResponse> = () => ({
24
- name: 'fastify-json',
25
- isMatch: (headers) => {
26
- return !!headers.get('content-type')?.startsWith('application/json');
27
- },
28
- getInputs: async (opts, info) => {
29
- async function getRawProcedureInputOrThrow() {
30
- const { req } = opts;
31
-
32
- try {
33
- if (req.method === 'GET') {
34
- const query = opts.req.query
35
- ? new URLSearchParams(opts.req.query as any)
36
- : new URLSearchParams(opts.req.url.split('?')[1]);
37
-
38
- const input = query.get('input');
39
- if (!input) {
40
- return undefined;
41
- }
42
-
43
- return JSON.parse(input);
44
- }
45
-
46
- const body = opts.req.body ?? 'null';
47
- if (typeof body === 'string') {
48
- // A mutation with no inputs will have req.body === ''
49
- return body.length === 0 ? undefined : JSON.parse(body);
50
- }
51
-
52
- return body;
53
- } catch (cause) {
54
- throw new TRPCError({
55
- code: 'PARSE_ERROR',
56
- cause,
57
- });
58
- }
59
- }
60
-
61
- const deserializeInputValue = (
62
- rawValue: unknown,
63
- transformer: CombinedDataTransformer,
64
- ) => {
65
- return typeof rawValue !== 'undefined'
66
- ? transformer.input.deserialize(rawValue)
67
- : rawValue;
68
- };
69
-
70
- const rawInput = await getRawProcedureInputOrThrow();
71
- if (rawInput === undefined) {
72
- return undefined;
73
- }
74
-
75
- const transformer = opts.router._def._config.transformer;
76
-
77
- if (!info.isBatchCall) {
78
- return deserializeInputValue(rawInput, transformer);
79
- }
80
-
81
- /* istanbul ignore if */
82
- if (
83
- rawInput == null ||
84
- typeof rawInput !== 'object' ||
85
- Array.isArray(rawInput)
86
- ) {
87
- throw new TRPCError({
88
- code: 'BAD_REQUEST',
89
- message: '"input" needs to be an object when doing a batch call',
90
- });
91
- }
92
-
93
- const rawValue = rawInput[info.batch];
94
-
95
- return deserializeInputValue(rawValue, transformer);
96
- },
97
- });
@@ -1,22 +0,0 @@
1
- import type { FastifyReply, FastifyRequest } from 'fastify';
2
- // @trpc/server
3
- import type { AnyRouter } from '../../@trpc/server';
4
- import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
5
- import type { NodeHTTPConditionCreateContextOption } from '../node-http';
6
-
7
- export type FastifyHandlerOptions<
8
- TRouter extends AnyRouter,
9
- TRequest extends FastifyRequest,
10
- TResponse extends FastifyReply,
11
- > = HTTPBaseHandlerOptions<TRouter, TRequest> &
12
- NodeHTTPConditionCreateContextOption<TRouter, TRequest, TResponse>;
13
-
14
- export type FastifyRequestHandlerOptions<
15
- TRouter extends AnyRouter,
16
- TRequest extends FastifyRequest,
17
- TResponse extends FastifyReply,
18
- > = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
19
- req: TRequest;
20
- res: TResponse;
21
- path: string;
22
- };
@@ -1,94 +0,0 @@
1
- // @trpc/server
2
- import { TRPCError } from '../../../../@trpc/server';
3
- import type {
4
- AnyRouter,
5
- CombinedDataTransformer,
6
- } from '../../../../@trpc/server';
7
- import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
8
- import type { FetchHandlerRequestOptions } from '../../types';
9
-
10
- export interface FetchHTTPContentTypeHandler<TRouter extends AnyRouter>
11
- extends BaseContentTypeHandler<
12
- FetchHandlerRequestOptions<TRouter> & {
13
- url: URL;
14
- }
15
- > {}
16
-
17
- export const getFetchHTTPJSONContentTypeHandler: <
18
- TRouter extends AnyRouter,
19
- >() => FetchHTTPContentTypeHandler<TRouter> = () => ({
20
- name: 'fetch-json',
21
- isMatch: (headers) => {
22
- return !!headers.get('content-type')?.startsWith('application/json');
23
- },
24
- getInputs: async (opts, info) => {
25
- async function getRawProcedureInputOrThrow() {
26
- const { req } = opts;
27
-
28
- try {
29
- if (req.method === 'GET') {
30
- const input = opts.url.searchParams.get('input');
31
- if (!input) {
32
- return undefined;
33
- }
34
-
35
- return JSON.parse(input);
36
- }
37
-
38
- const body = opts.req.headers
39
- .get('content-type')
40
- ?.startsWith('application/json')
41
- ? await opts.req.text()
42
- : '';
43
-
44
- if (typeof body === 'string') {
45
- // A mutation with no inputs will have req.body === ''
46
- return body.length === 0 ? undefined : JSON.parse(body);
47
- }
48
-
49
- return body;
50
- } catch (cause) {
51
- throw new TRPCError({
52
- code: 'PARSE_ERROR',
53
- cause,
54
- });
55
- }
56
- }
57
-
58
- const deserializeInputValue = (
59
- rawValue: unknown,
60
- transformer: CombinedDataTransformer,
61
- ) => {
62
- return typeof rawValue !== 'undefined'
63
- ? transformer.input.deserialize(rawValue)
64
- : rawValue;
65
- };
66
-
67
- const rawInput = await getRawProcedureInputOrThrow();
68
- if (rawInput === undefined) {
69
- return undefined;
70
- }
71
-
72
- const transformer = opts.router._def._config.transformer;
73
-
74
- if (!info.isBatchCall) {
75
- return deserializeInputValue(rawInput, transformer);
76
- }
77
-
78
- /* istanbul ignore if */
79
- if (
80
- rawInput == null ||
81
- typeof rawInput !== 'object' ||
82
- Array.isArray(rawInput)
83
- ) {
84
- throw new TRPCError({
85
- code: 'BAD_REQUEST',
86
- message: '"input" needs to be an object when doing a batch call',
87
- });
88
- }
89
-
90
- const rawValue = rawInput[info.batch];
91
-
92
- return deserializeInputValue(rawValue, transformer);
93
- },
94
- });
@@ -1,27 +0,0 @@
1
- import { Stream } from 'stream';
2
- // @trpc/server
3
- import type { AnyRouter } from '../../../../@trpc/server';
4
- import type { NodeHTTPRequest, NodeHTTPResponse } from '../../types';
5
- import type { NodeHTTPContentTypeHandler } from '../types';
6
-
7
- export const getOctetContentTypeHandler: <
8
- TRouter extends AnyRouter,
9
- TRequest extends NodeHTTPRequest,
10
- TResponse extends NodeHTTPResponse,
11
- >() => NodeHTTPContentTypeHandler<TRouter, TRequest, TResponse> = () => ({
12
- name: 'node-http-octet',
13
- isMatch: (headers) => {
14
- return !!headers
15
- .get('content-type')
16
- ?.startsWith('application/octet-stream');
17
- },
18
- async getInputs(opts, inputOpts) {
19
- if (inputOpts.isBatchCall) {
20
- throw new Error('Batch calls not supported for octet-stream');
21
- }
22
-
23
- const stream = Stream.Readable.toWeb(opts.req);
24
-
25
- return stream;
26
- },
27
- });
@@ -1,37 +0,0 @@
1
- import { TRPCError } from './error/TRPCError';
2
- import type { ParserZodEsque } from './parser';
3
-
4
- export type UtilityParser<TInput, TOutput> = ParserZodEsque<TInput, TOutput> & {
5
- parse: (input: unknown) => TOutput;
6
- };
7
-
8
- // Should be the same possible types as packages/client/src/links/internals/contentTypes.ts isOctetType
9
-
10
- /**
11
- * File is only available from Node19+ but it always extends Blob so we can use that as a type until we eventually drop Node18
12
- */
13
- interface FileLike extends Blob {
14
- readonly name: string;
15
- }
16
-
17
- /**
18
- * When expecting a supported octet type to be passed from the frontend, this parser may be used to validate the type for your procedure. Note: the output is always a `Readable` stream.
19
- */
20
- export function parseOctetInput<
21
- TInput extends Blob | Uint8Array | FileLike,
22
- >(): UtilityParser<TInput, ReadableStream> {
23
- return {
24
- _input: null as any as TInput,
25
- _output: null as any as ReadableStream,
26
- parse(input: unknown) {
27
- if (input instanceof ReadableStream) {
28
- return input;
29
- }
30
-
31
- throw new TRPCError({
32
- code: 'INTERNAL_SERVER_ERROR',
33
- cause: `Parsed input was expected to be a ReadableStream but was: ${typeof input}`,
34
- });
35
- },
36
- };
37
- }