@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,31 +0,0 @@
1
- import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import '../../unstable-core-do-not-import/rootConfig.mjs';
3
-
4
- function selectContentHandlerOrUnsupportedMediaType(handlers, opts) {
5
- const headers = new Headers(opts.req.headers);
6
- const contentType = headers.get('content-type');
7
- if (contentType === null) {
8
- return [
9
- undefined,
10
- new TRPCError({
11
- code: 'UNSUPPORTED_MEDIA_TYPE',
12
- message: 'No Content-Type header detected on the incoming request. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all'
13
- })
14
- ];
15
- }
16
- const handler = handlers.find((handler)=>handler.isMatch(headers));
17
- if (!handler) {
18
- return [
19
- undefined,
20
- new TRPCError({
21
- code: 'UNSUPPORTED_MEDIA_TYPE',
22
- message: `Invalid Content-Type header '${contentType}'. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all`
23
- })
24
- ];
25
- }
26
- return [
27
- handler
28
- ];
29
- }
30
-
31
- export { selectContentHandlerOrUnsupportedMediaType };
@@ -1,8 +0,0 @@
1
- import type { FastifyReply, FastifyRequest } from 'fastify';
2
- import type { AnyRouter } from '../../../../@trpc/server';
3
- import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
4
- import type { FastifyRequestHandlerOptions } from '../../types';
5
- export interface FastifyHTTPContentTypeHandler<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> extends BaseContentTypeHandler<FastifyRequestHandlerOptions<TRouter, TRequest, TResponse>> {
6
- }
7
- export declare const getFastifyHTTPJSONContentTypeHandler: <TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply>() => FastifyHTTPContentTypeHandler<TRouter, TRequest, TResponse>;
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/fastify/content-type/json/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,WAAW,6BAA6B,CAC5C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,CAC9B,SAAQ,sBAAsB,CAC5B,4BAA4B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAC3D;CAAG;AAEN,eAAO,MAAM,oCAAoC,EAAE,CACjD,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,OACzB,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CA0E/D,CAAC"}
@@ -1,59 +0,0 @@
1
- 'use strict';
2
-
3
- var TRPCError = require('../../../../unstable-core-do-not-import/error/TRPCError.js');
4
- require('../../../../unstable-core-do-not-import/rootConfig.js');
5
-
6
- // @trpc/server
7
- const getFastifyHTTPJSONContentTypeHandler = ()=>({
8
- name: 'fastify-json',
9
- isMatch: (headers)=>{
10
- return !!headers.get('content-type')?.startsWith('application/json');
11
- },
12
- getInputs: async (opts, info)=>{
13
- async function getRawProcedureInputOrThrow() {
14
- const { req } = opts;
15
- try {
16
- if (req.method === 'GET') {
17
- const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
18
- const input = query.get('input');
19
- if (!input) {
20
- return undefined;
21
- }
22
- return JSON.parse(input);
23
- }
24
- const body = opts.req.body ?? 'null';
25
- if (typeof body === 'string') {
26
- // A mutation with no inputs will have req.body === ''
27
- return body.length === 0 ? undefined : JSON.parse(body);
28
- }
29
- return body;
30
- } catch (cause) {
31
- throw new TRPCError.TRPCError({
32
- code: 'PARSE_ERROR',
33
- cause
34
- });
35
- }
36
- }
37
- const deserializeInputValue = (rawValue, transformer)=>{
38
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
39
- };
40
- const rawInput = await getRawProcedureInputOrThrow();
41
- if (rawInput === undefined) {
42
- return undefined;
43
- }
44
- const transformer = opts.router._def._config.transformer;
45
- if (!info.isBatchCall) {
46
- return deserializeInputValue(rawInput, transformer);
47
- }
48
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
49
- throw new TRPCError.TRPCError({
50
- code: 'BAD_REQUEST',
51
- message: '"input" needs to be an object when doing a batch call'
52
- });
53
- }
54
- const rawValue = rawInput[info.batch];
55
- return deserializeInputValue(rawValue, transformer);
56
- }
57
- });
58
-
59
- exports.getFastifyHTTPJSONContentTypeHandler = getFastifyHTTPJSONContentTypeHandler;
@@ -1,57 +0,0 @@
1
- import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
-
4
- // @trpc/server
5
- const getFastifyHTTPJSONContentTypeHandler = ()=>({
6
- name: 'fastify-json',
7
- isMatch: (headers)=>{
8
- return !!headers.get('content-type')?.startsWith('application/json');
9
- },
10
- getInputs: async (opts, info)=>{
11
- async function getRawProcedureInputOrThrow() {
12
- const { req } = opts;
13
- try {
14
- if (req.method === 'GET') {
15
- const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
16
- const input = query.get('input');
17
- if (!input) {
18
- return undefined;
19
- }
20
- return JSON.parse(input);
21
- }
22
- const body = opts.req.body ?? 'null';
23
- if (typeof body === 'string') {
24
- // A mutation with no inputs will have req.body === ''
25
- return body.length === 0 ? undefined : JSON.parse(body);
26
- }
27
- return body;
28
- } catch (cause) {
29
- throw new TRPCError({
30
- code: 'PARSE_ERROR',
31
- cause
32
- });
33
- }
34
- }
35
- const deserializeInputValue = (rawValue, transformer)=>{
36
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
37
- };
38
- const rawInput = await getRawProcedureInputOrThrow();
39
- if (rawInput === undefined) {
40
- return undefined;
41
- }
42
- const transformer = opts.router._def._config.transformer;
43
- if (!info.isBatchCall) {
44
- return deserializeInputValue(rawInput, transformer);
45
- }
46
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
47
- throw new TRPCError({
48
- code: 'BAD_REQUEST',
49
- message: '"input" needs to be an object when doing a batch call'
50
- });
51
- }
52
- const rawValue = rawInput[info.batch];
53
- return deserializeInputValue(rawValue, transformer);
54
- }
55
- });
56
-
57
- export { getFastifyHTTPJSONContentTypeHandler };
@@ -1,11 +0,0 @@
1
- import type { FastifyReply, FastifyRequest } from 'fastify';
2
- import type { AnyRouter } from '../../@trpc/server';
3
- import type { HTTPBaseHandlerOptions } from '../../@trpc/server/http';
4
- import type { NodeHTTPConditionCreateContextOption } from '../node-http';
5
- export type FastifyHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = HTTPBaseHandlerOptions<TRouter, TRequest> & NodeHTTPConditionCreateContextOption<TRouter, TRequest, TResponse>;
6
- export type FastifyRequestHandlerOptions<TRouter extends AnyRouter, TRequest extends FastifyRequest, TResponse extends FastifyReply> = FastifyHandlerOptions<TRouter, TRequest, TResponse> & {
7
- req: TRequest;
8
- res: TResponse;
9
- path: string;
10
- };
11
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/fastify/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,GAC3C,oCAAoC,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE,MAAM,MAAM,4BAA4B,CACtC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,cAAc,EAC/B,SAAS,SAAS,YAAY,IAC5B,qBAAqB,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IACxD,GAAG,EAAE,QAAQ,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -1,9 +0,0 @@
1
- import type { AnyRouter } from '../../../../@trpc/server';
2
- import type { BaseContentTypeHandler } from '../../../../@trpc/server/http';
3
- import type { FetchHandlerRequestOptions } from '../../types';
4
- export interface FetchHTTPContentTypeHandler<TRouter extends AnyRouter> extends BaseContentTypeHandler<FetchHandlerRequestOptions<TRouter> & {
5
- url: URL;
6
- }> {
7
- }
8
- export declare const getFetchHTTPJSONContentTypeHandler: <TRouter extends AnyRouter>() => FetchHTTPContentTypeHandler<TRouter>;
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/fetch/content-type/json/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,WAAW,2BAA2B,CAAC,OAAO,SAAS,SAAS,CACpE,SAAQ,sBAAsB,CAC5B,0BAA0B,CAAC,OAAO,CAAC,GAAG;IACpC,GAAG,EAAE,GAAG,CAAC;CACV,CACF;CAAG;AAEN,eAAO,MAAM,kCAAkC,EAAE,CAC/C,OAAO,SAAS,SAAS,OACpB,2BAA2B,CAAC,OAAO,CA2ExC,CAAC"}
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- var TRPCError = require('../../../../unstable-core-do-not-import/error/TRPCError.js');
4
- require('../../../../unstable-core-do-not-import/rootConfig.js');
5
-
6
- // @trpc/server
7
- const getFetchHTTPJSONContentTypeHandler = ()=>({
8
- name: 'fetch-json',
9
- isMatch: (headers)=>{
10
- return !!headers.get('content-type')?.startsWith('application/json');
11
- },
12
- getInputs: async (opts, info)=>{
13
- async function getRawProcedureInputOrThrow() {
14
- const { req } = opts;
15
- try {
16
- if (req.method === 'GET') {
17
- const input = opts.url.searchParams.get('input');
18
- if (!input) {
19
- return undefined;
20
- }
21
- return JSON.parse(input);
22
- }
23
- const body = opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : '';
24
- if (typeof body === 'string') {
25
- // A mutation with no inputs will have req.body === ''
26
- return body.length === 0 ? undefined : JSON.parse(body);
27
- }
28
- return body;
29
- } catch (cause) {
30
- throw new TRPCError.TRPCError({
31
- code: 'PARSE_ERROR',
32
- cause
33
- });
34
- }
35
- }
36
- const deserializeInputValue = (rawValue, transformer)=>{
37
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
38
- };
39
- const rawInput = await getRawProcedureInputOrThrow();
40
- if (rawInput === undefined) {
41
- return undefined;
42
- }
43
- const transformer = opts.router._def._config.transformer;
44
- if (!info.isBatchCall) {
45
- return deserializeInputValue(rawInput, transformer);
46
- }
47
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
48
- throw new TRPCError.TRPCError({
49
- code: 'BAD_REQUEST',
50
- message: '"input" needs to be an object when doing a batch call'
51
- });
52
- }
53
- const rawValue = rawInput[info.batch];
54
- return deserializeInputValue(rawValue, transformer);
55
- }
56
- });
57
-
58
- exports.getFetchHTTPJSONContentTypeHandler = getFetchHTTPJSONContentTypeHandler;
@@ -1,56 +0,0 @@
1
- import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
-
4
- // @trpc/server
5
- const getFetchHTTPJSONContentTypeHandler = ()=>({
6
- name: 'fetch-json',
7
- isMatch: (headers)=>{
8
- return !!headers.get('content-type')?.startsWith('application/json');
9
- },
10
- getInputs: async (opts, info)=>{
11
- async function getRawProcedureInputOrThrow() {
12
- const { req } = opts;
13
- try {
14
- if (req.method === 'GET') {
15
- const input = opts.url.searchParams.get('input');
16
- if (!input) {
17
- return undefined;
18
- }
19
- return JSON.parse(input);
20
- }
21
- const body = opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : '';
22
- if (typeof body === 'string') {
23
- // A mutation with no inputs will have req.body === ''
24
- return body.length === 0 ? undefined : JSON.parse(body);
25
- }
26
- return body;
27
- } catch (cause) {
28
- throw new TRPCError({
29
- code: 'PARSE_ERROR',
30
- cause
31
- });
32
- }
33
- }
34
- const deserializeInputValue = (rawValue, transformer)=>{
35
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
36
- };
37
- const rawInput = await getRawProcedureInputOrThrow();
38
- if (rawInput === undefined) {
39
- return undefined;
40
- }
41
- const transformer = opts.router._def._config.transformer;
42
- if (!info.isBatchCall) {
43
- return deserializeInputValue(rawInput, transformer);
44
- }
45
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
46
- throw new TRPCError({
47
- code: 'BAD_REQUEST',
48
- message: '"input" needs to be an object when doing a batch call'
49
- });
50
- }
51
- const rawValue = rawInput[info.batch];
52
- return deserializeInputValue(rawValue, transformer);
53
- }
54
- });
55
-
56
- export { getFetchHTTPJSONContentTypeHandler };
@@ -1,5 +0,0 @@
1
- import type { AnyRouter } from '../../../../@trpc/server';
2
- import type { NodeHTTPRequest, NodeHTTPResponse } from '../../types';
3
- import type { NodeHTTPContentTypeHandler } from '../types';
4
- export declare const getOctetContentTypeHandler: <TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse>() => NodeHTTPContentTypeHandler<TRouter, TRequest, TResponse>;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/octet/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAE3D,eAAO,MAAM,0BAA0B,EAAE,CACvC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,OAC7B,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAgB5D,CAAC"}
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var node_stream = require('node:stream');
4
-
5
- const getOctetContentTypeHandler = ()=>({
6
- name: 'node-http-octet',
7
- isMatch: (headers)=>{
8
- return !!headers.get('content-type')?.startsWith('application/octet-stream');
9
- },
10
- async getInputs (opts, inputOpts) {
11
- if (inputOpts.isBatchCall) {
12
- throw new Error('Batch calls not supported for octet-stream');
13
- }
14
- const stream = node_stream.Stream.Readable.toWeb(opts.req);
15
- return stream;
16
- }
17
- });
18
-
19
- exports.getOctetContentTypeHandler = getOctetContentTypeHandler;
@@ -1,17 +0,0 @@
1
- import { Stream } from 'node:stream';
2
-
3
- const getOctetContentTypeHandler = ()=>({
4
- name: 'node-http-octet',
5
- isMatch: (headers)=>{
6
- return !!headers.get('content-type')?.startsWith('application/octet-stream');
7
- },
8
- async getInputs (opts, inputOpts) {
9
- if (inputOpts.isBatchCall) {
10
- throw new Error('Batch calls not supported for octet-stream');
11
- }
12
- const stream = Stream.Readable.toWeb(opts.req);
13
- return stream;
14
- }
15
- });
16
-
17
- export { getOctetContentTypeHandler };
@@ -1,8 +0,0 @@
1
- import type { AnyRouter } from '../../../@trpc/server';
2
- import type { BaseContentTypeHandler } from '../../../@trpc/server/http';
3
- import type { NodeHTTPRequest, NodeHTTPRequestHandlerOptions, NodeHTTPResponse } from '../types';
4
- export interface NodeHTTPContentTypeHandler<TRouter extends AnyRouter, TRequest extends NodeHTTPRequest, TResponse extends NodeHTTPResponse> extends BaseContentTypeHandler<NodeHTTPRequestHandlerOptions<TRouter, TRequest, TResponse> & {
5
- query: URLSearchParams;
6
- }> {
7
- }
8
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/adapters/node-http/content-type/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,0BAA0B,CACzC,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,CAClC,SAAQ,sBAAsB,CAC5B,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG;IAC5D,KAAK,EAAE,eAAe,CAAC;CACxB,CACF;CAAG"}
@@ -1,16 +0,0 @@
1
- import type { ParserZodEsque } from './parser';
2
- export type UtilityParser<TInput, TOutput> = ParserZodEsque<TInput, TOutput> & {
3
- parse: (input: unknown) => TOutput;
4
- };
5
- /**
6
- * File is only available from Node19+ but it always extends Blob so we can use that as a type until we eventually drop Node18
7
- */
8
- interface FileLike extends Blob {
9
- readonly name: string;
10
- }
11
- /**
12
- * 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.
13
- */
14
- export declare function parseOctetInput<TInput extends Blob | Uint8Array | FileLike>(): UtilityParser<TInput, ReadableStream>;
15
- export {};
16
- //# sourceMappingURL=contentTypeParsers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contentTypeParsers.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/contentTypeParsers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,MAAM,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC7E,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CACpC,CAAC;AAIF;;GAEG;AACH,UAAU,QAAS,SAAQ,IAAI;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,SAAS,IAAI,GAAG,UAAU,GAAG,QAAQ,KACxC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,CAezC"}
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- var TRPCError = require('./error/TRPCError.js');
4
-
5
- /**
6
- * 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.
7
- */ function parseOctetInput() {
8
- return {
9
- _input: null,
10
- _output: null,
11
- parse (input) {
12
- if (input instanceof ReadableStream) {
13
- return input;
14
- }
15
- throw new TRPCError.TRPCError({
16
- code: 'INTERNAL_SERVER_ERROR',
17
- cause: `Parsed input was expected to be a ReadableStream but was: ${typeof input}`
18
- });
19
- }
20
- };
21
- }
22
-
23
- exports.parseOctetInput = parseOctetInput;
@@ -1,21 +0,0 @@
1
- import { TRPCError } from './error/TRPCError.mjs';
2
-
3
- /**
4
- * 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.
5
- */ function parseOctetInput() {
6
- return {
7
- _input: null,
8
- _output: null,
9
- parse (input) {
10
- if (input instanceof ReadableStream) {
11
- return input;
12
- }
13
- throw new TRPCError({
14
- code: 'INTERNAL_SERVER_ERROR',
15
- cause: `Parsed input was expected to be a ReadableStream but was: ${typeof input}`
16
- });
17
- }
18
- };
19
- }
20
-
21
- export { parseOctetInput };
@@ -1,99 +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 {
8
- BaseContentTypeHandler,
9
- HTTPRequest,
10
- } from '../../../../@trpc/server/http';
11
- import {
12
- lambdaEventToHTTPBody,
13
- type APIGatewayEvent,
14
- type AWSLambdaOptions,
15
- } from '../../utils';
16
-
17
- export interface LambdaHTTPContentTypeHandler<
18
- TRouter extends AnyRouter,
19
- TEvent extends APIGatewayEvent,
20
- > extends BaseContentTypeHandler<
21
- AWSLambdaOptions<TRouter, TEvent> & {
22
- event: TEvent;
23
- req: HTTPRequest;
24
- }
25
- > {}
26
-
27
- export const getLambdaHTTPJSONContentTypeHandler: <
28
- TRouter extends AnyRouter,
29
- TEvent extends APIGatewayEvent,
30
- >() => LambdaHTTPContentTypeHandler<TRouter, TEvent> = () => ({
31
- name: 'lambda-json',
32
- isMatch: (headers) => {
33
- return !!headers.get('content-type')?.startsWith('application/json');
34
- },
35
- getInputs: async (opts, info) => {
36
- function getRawProcedureInputOrThrow() {
37
- const { event, req } = opts;
38
-
39
- try {
40
- if (req.method === 'GET') {
41
- const input = req.query.get('input');
42
- if (!input) {
43
- return undefined;
44
- }
45
-
46
- return JSON.parse(input);
47
- }
48
-
49
- const body = lambdaEventToHTTPBody(opts.event);
50
- if (typeof body === 'string') {
51
- // A mutation with no inputs will have req.body === ''
52
- return body.length === 0 ? undefined : JSON.parse(body);
53
- }
54
- return event.body;
55
- } catch (cause) {
56
- throw new TRPCError({
57
- code: 'PARSE_ERROR',
58
- cause,
59
- });
60
- }
61
- }
62
-
63
- const deserializeInputValue = (
64
- rawValue: unknown,
65
- transformer: CombinedDataTransformer,
66
- ) => {
67
- return typeof rawValue !== 'undefined'
68
- ? transformer.input.deserialize(rawValue)
69
- : rawValue;
70
- };
71
-
72
- const rawInput = getRawProcedureInputOrThrow();
73
- if (rawInput === undefined) {
74
- return undefined;
75
- }
76
-
77
- const transformer = opts.router._def._config.transformer;
78
-
79
- if (!info.isBatchCall) {
80
- return deserializeInputValue(rawInput, transformer);
81
- }
82
-
83
- /* istanbul ignore if */
84
- if (
85
- rawInput == null ||
86
- typeof rawInput !== 'object' ||
87
- Array.isArray(rawInput)
88
- ) {
89
- throw new TRPCError({
90
- code: 'BAD_REQUEST',
91
- message: '"input" needs to be an object when doing a batch call',
92
- });
93
- }
94
-
95
- const rawValue = rawInput[info.batch];
96
-
97
- return deserializeInputValue(rawValue, transformer);
98
- },
99
- });
@@ -1,45 +0,0 @@
1
- import { TRPCError } from '../../@trpc/server';
2
- import type {
3
- BaseContentTypeHandler,
4
- HTTPHeaders,
5
- } from '../../@trpc/server/http';
6
-
7
- interface MinimalHandlerOpts {
8
- req: {
9
- // TODO: This could probably only take Headers and do the conversion higher up,
10
- // but that's a bigger refactor for another day
11
- headers: HTTPHeaders | Headers;
12
- };
13
- }
14
-
15
- export function selectContentHandlerOrUnsupportedMediaType<
16
- THandlerOpts extends MinimalHandlerOpts,
17
- THandler extends BaseContentTypeHandler<THandlerOpts>,
18
- >(handlers: THandler[], opts: THandlerOpts) {
19
- const headers = new Headers(opts.req.headers as HeadersInit);
20
- const contentType = headers.get('content-type');
21
-
22
- if (contentType === null) {
23
- return [
24
- undefined,
25
- new TRPCError({
26
- code: 'UNSUPPORTED_MEDIA_TYPE',
27
- message:
28
- 'No Content-Type header detected on the incoming request. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all',
29
- }),
30
- ] as const;
31
- }
32
-
33
- const handler = handlers.find((handler) => handler.isMatch(headers));
34
- if (!handler) {
35
- return [
36
- undefined,
37
- new TRPCError({
38
- code: 'UNSUPPORTED_MEDIA_TYPE',
39
- message: `Invalid Content-Type header '${contentType}'. This request may not be supported by your tRPC Adapter, or possibly by tRPC at all`,
40
- }),
41
- ] as const;
42
- }
43
-
44
- return [handler] as const;
45
- }