@trpc/server 11.0.0-rc.361 → 11.0.0-rc.362

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 (173) hide show
  1. package/dist/@trpc/server/http.d.ts +7 -5
  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/getPlanner.d.ts +13 -0
  6. package/dist/adapters/aws-lambda/getPlanner.d.ts.map +1 -0
  7. package/dist/adapters/aws-lambda/getPlanner.js +143 -0
  8. package/dist/adapters/aws-lambda/getPlanner.mjs +141 -0
  9. package/dist/adapters/aws-lambda/index.d.ts +12 -9
  10. package/dist/adapters/aws-lambda/index.d.ts.map +1 -1
  11. package/dist/adapters/aws-lambda/index.js +7 -76
  12. package/dist/adapters/aws-lambda/index.mjs +9 -72
  13. package/dist/adapters/express.js +1 -0
  14. package/dist/adapters/express.mjs +1 -0
  15. package/dist/adapters/fastify/fastifyRequestHandler.d.ts +19 -2
  16. package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +1 -1
  17. package/dist/adapters/fastify/fastifyRequestHandler.js +12 -63
  18. package/dist/adapters/fastify/fastifyRequestHandler.mjs +13 -64
  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 +2 -2
  22. package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +1 -1
  23. package/dist/adapters/fetch/fetchRequestHandler.js +28 -85
  24. package/dist/adapters/fetch/fetchRequestHandler.mjs +29 -86
  25. package/dist/adapters/fetch/types.d.ts +2 -2
  26. package/dist/adapters/fetch/types.d.ts.map +1 -1
  27. package/dist/adapters/next.js +1 -1
  28. package/dist/adapters/next.mjs +1 -1
  29. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +18 -0
  30. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -0
  31. package/dist/adapters/node-http/incomingMessageToRequest.js +71 -0
  32. package/dist/adapters/node-http/incomingMessageToRequest.mjs +69 -0
  33. package/dist/adapters/node-http/index.d.ts +1 -0
  34. package/dist/adapters/node-http/index.d.ts.map +1 -1
  35. package/dist/adapters/node-http/index.js +2 -0
  36. package/dist/adapters/node-http/index.mjs +1 -0
  37. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +1 -1
  38. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  39. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +27 -70
  40. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +28 -71
  41. package/dist/adapters/node-http/types.d.ts +7 -8
  42. package/dist/adapters/node-http/types.d.ts.map +1 -1
  43. package/dist/adapters/ws.js +1 -1
  44. package/dist/adapters/ws.mjs +1 -1
  45. package/dist/bundle-analysis.json +180 -277
  46. package/dist/http.js +4 -2
  47. package/dist/http.mjs +2 -1
  48. package/dist/index.js +2 -4
  49. package/dist/index.mjs +1 -2
  50. package/dist/unstable-core-do-not-import/http/contentType.d.ts +8 -20
  51. package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
  52. package/dist/unstable-core-do-not-import/http/contentType.js +180 -0
  53. package/dist/unstable-core-do-not-import/http/contentType.mjs +178 -0
  54. package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts +14 -0
  55. package/dist/unstable-core-do-not-import/http/contentTypeParsers.d.ts.map +1 -0
  56. package/dist/unstable-core-do-not-import/http/contentTypeParsers.js +14 -0
  57. package/dist/unstable-core-do-not-import/http/contentTypeParsers.mjs +12 -0
  58. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts +1 -1
  59. package/dist/unstable-core-do-not-import/http/getHTTPStatusCode.d.ts.map +1 -1
  60. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts +7 -43
  61. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.d.ts.map +1 -1
  62. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.js +119 -134
  63. package/dist/unstable-core-do-not-import/http/resolveHTTPResponse.mjs +119 -134
  64. package/dist/unstable-core-do-not-import/http/types.d.ts +25 -27
  65. package/dist/unstable-core-do-not-import/http/types.d.ts.map +1 -1
  66. package/dist/unstable-core-do-not-import/initTRPC.d.ts +1 -1
  67. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts +1 -3
  68. package/dist/unstable-core-do-not-import/procedureBuilder.d.ts.map +1 -1
  69. package/dist/unstable-core-do-not-import/procedureBuilder.js +0 -2
  70. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -2
  71. package/dist/unstable-core-do-not-import/rootConfig.d.ts +0 -9
  72. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  73. package/dist/unstable-core-do-not-import/utils.d.ts +3 -0
  74. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  75. package/dist/unstable-core-do-not-import/utils.js +2 -0
  76. package/dist/unstable-core-do-not-import/utils.mjs +2 -1
  77. package/dist/unstable-core-do-not-import.d.ts +9 -3
  78. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  79. package/dist/unstable-core-do-not-import.js +11 -7
  80. package/dist/unstable-core-do-not-import.mjs +7 -5
  81. package/package.json +3 -13
  82. package/src/@trpc/server/http.ts +7 -12
  83. package/src/@trpc/server/index.ts +0 -3
  84. package/src/adapters/aws-lambda/getPlanner.ts +191 -0
  85. package/src/adapters/aws-lambda/index.ts +43 -107
  86. package/src/adapters/express.ts +1 -1
  87. package/src/adapters/fastify/fastifyRequestHandler.ts +40 -89
  88. package/src/adapters/fastify/fastifyTRPCPlugin.ts +1 -1
  89. package/src/adapters/fetch/fetchRequestHandler.ts +35 -111
  90. package/src/adapters/fetch/types.ts +4 -2
  91. package/src/adapters/next.ts +1 -1
  92. package/src/adapters/node-http/incomingMessageToRequest.ts +94 -0
  93. package/src/adapters/node-http/index.ts +1 -0
  94. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +31 -97
  95. package/src/adapters/node-http/types.ts +27 -37
  96. package/src/adapters/standalone.ts +1 -1
  97. package/src/unstable-core-do-not-import/http/contentType.ts +214 -22
  98. package/src/unstable-core-do-not-import/http/contentTypeParsers.ts +29 -0
  99. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +2 -2
  100. package/src/unstable-core-do-not-import/http/resolveHTTPResponse.ts +135 -210
  101. package/src/unstable-core-do-not-import/http/types.ts +25 -30
  102. package/src/unstable-core-do-not-import/procedureBuilder.ts +2 -4
  103. package/src/unstable-core-do-not-import/rootConfig.ts +0 -10
  104. package/src/unstable-core-do-not-import/utils.ts +4 -0
  105. package/src/unstable-core-do-not-import.ts +9 -3
  106. package/adapters/node-http/content-type/form-data/index.d.ts +0 -1
  107. package/adapters/node-http/content-type/form-data/index.js +0 -1
  108. package/adapters/node-http/content-type/json/index.d.ts +0 -1
  109. package/adapters/node-http/content-type/json/index.js +0 -1
  110. package/dist/adapters/aws-lambda/content-type/json/index.d.ts +0 -10
  111. package/dist/adapters/aws-lambda/content-type/json/index.d.ts.map +0 -1
  112. package/dist/adapters/aws-lambda/content-type/json/index.js +0 -62
  113. package/dist/adapters/aws-lambda/content-type/json/index.mjs +0 -60
  114. package/dist/adapters/aws-lambda/utils.d.ts +0 -31
  115. package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
  116. package/dist/adapters/aws-lambda/utils.js +0 -111
  117. package/dist/adapters/aws-lambda/utils.mjs +0 -103
  118. package/dist/adapters/content-handlers/concurrentCache.d.ts +0 -7
  119. package/dist/adapters/content-handlers/concurrentCache.d.ts.map +0 -1
  120. package/dist/adapters/content-handlers/concurrentCache.js +0 -17
  121. package/dist/adapters/content-handlers/concurrentCache.mjs +0 -15
  122. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +0 -10
  123. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +0 -1
  124. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +0 -33
  125. package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +0 -31
  126. package/dist/adapters/fastify/content-type/json/index.d.ts +0 -8
  127. package/dist/adapters/fastify/content-type/json/index.d.ts.map +0 -1
  128. package/dist/adapters/fastify/content-type/json/index.js +0 -62
  129. package/dist/adapters/fastify/content-type/json/index.mjs +0 -60
  130. package/dist/adapters/fastify/types.d.ts +0 -11
  131. package/dist/adapters/fastify/types.d.ts.map +0 -1
  132. package/dist/adapters/fetch/content-type/json/index.d.ts +0 -9
  133. package/dist/adapters/fetch/content-type/json/index.d.ts.map +0 -1
  134. package/dist/adapters/fetch/content-type/json/index.js +0 -55
  135. package/dist/adapters/fetch/content-type/json/index.mjs +0 -53
  136. package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -5
  137. package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
  138. package/dist/adapters/node-http/content-type/form-data/index.js +0 -32
  139. package/dist/adapters/node-http/content-type/form-data/index.mjs +0 -30
  140. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
  141. package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
  142. package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -45
  143. package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -43
  144. package/dist/adapters/node-http/content-type/json/index.d.ts +0 -5
  145. package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
  146. package/dist/adapters/node-http/content-type/json/index.js +0 -68
  147. package/dist/adapters/node-http/content-type/json/index.mjs +0 -66
  148. package/dist/adapters/node-http/content-type/octet/index.d.ts +0 -5
  149. package/dist/adapters/node-http/content-type/octet/index.d.ts.map +0 -1
  150. package/dist/adapters/node-http/content-type/octet/index.js +0 -19
  151. package/dist/adapters/node-http/content-type/octet/index.mjs +0 -17
  152. package/dist/adapters/node-http/content-type/types.d.ts +0 -8
  153. package/dist/adapters/node-http/content-type/types.d.ts.map +0 -1
  154. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts +0 -16
  155. package/dist/unstable-core-do-not-import/contentTypeParsers.d.ts.map +0 -1
  156. package/dist/unstable-core-do-not-import/contentTypeParsers.js +0 -23
  157. package/dist/unstable-core-do-not-import/contentTypeParsers.mjs +0 -21
  158. package/dist/unstable-core-do-not-import/http/index.d.ts +0 -11
  159. package/dist/unstable-core-do-not-import/http/index.d.ts.map +0 -1
  160. package/src/adapters/aws-lambda/content-type/json/index.ts +0 -108
  161. package/src/adapters/aws-lambda/utils.ts +0 -170
  162. package/src/adapters/content-handlers/concurrentCache.ts +0 -16
  163. package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +0 -45
  164. package/src/adapters/fastify/content-type/json/index.ts +0 -106
  165. package/src/adapters/fastify/types.ts +0 -22
  166. package/src/adapters/fetch/content-type/json/index.ts +0 -90
  167. package/src/adapters/node-http/content-type/form-data/index.ts +0 -37
  168. package/src/adapters/node-http/content-type/json/getPostBody.ts +0 -49
  169. package/src/adapters/node-http/content-type/json/index.ts +0 -100
  170. package/src/adapters/node-http/content-type/octet/index.ts +0 -27
  171. package/src/adapters/node-http/content-type/types.ts +0 -19
  172. package/src/unstable-core-do-not-import/contentTypeParsers.ts +0 -37
  173. package/src/unstable-core-do-not-import/http/index.ts +0 -28
@@ -1,60 +0,0 @@
1
- import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
- import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
4
-
5
- // @trpc/server
6
- const getFastifyHTTPJSONContentTypeHandler = ()=>{
7
- const cache = createConcurrentCache();
8
- return {
9
- name: 'fastify-json',
10
- isMatch: (headers)=>{
11
- return !!headers.get('content-type')?.startsWith('application/json');
12
- },
13
- getInputs: async (opts, info)=>{
14
- async function getRawProcedureInputOrThrow() {
15
- const { req } = opts;
16
- try {
17
- if (req.method === 'GET') {
18
- const query = opts.req.query ? new URLSearchParams(opts.req.query) : new URLSearchParams(opts.req.url.split('?')[1]);
19
- const input = query.get('input');
20
- if (!input) {
21
- return undefined;
22
- }
23
- return JSON.parse(input);
24
- }
25
- const body = opts.req.body ?? 'null';
26
- if (typeof body === 'string') {
27
- // A mutation with no inputs will have req.body === ''
28
- return body.length === 0 ? undefined : JSON.parse(body);
29
- }
30
- return body;
31
- } catch (cause) {
32
- throw new TRPCError({
33
- code: 'PARSE_ERROR',
34
- cause
35
- });
36
- }
37
- }
38
- const deserializeInputValue = (rawValue, transformer)=>{
39
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
40
- };
41
- const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
42
- if (rawInput === undefined) {
43
- return undefined;
44
- }
45
- const transformer = opts.router._def._config.transformer;
46
- if (!info.isBatchCall) {
47
- return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
48
- }
49
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
50
- throw new TRPCError({
51
- code: 'BAD_REQUEST',
52
- message: '"input" needs to be an object when doing a batch call'
53
- });
54
- }
55
- return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
56
- }
57
- };
58
- };
59
-
60
- 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;AAE5E,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,CAsEzC,CAAC"}
@@ -1,55 +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
- var concurrentCache = require('../../../content-handlers/concurrentCache.js');
6
-
7
- // @trpc/server
8
- const getFetchHTTPJSONContentTypeHandler = ()=>{
9
- const cache = concurrentCache.createConcurrentCache();
10
- return {
11
- name: 'fetch-json',
12
- isMatch: (headers)=>{
13
- return !!headers.get('content-type')?.startsWith('application/json');
14
- },
15
- getInputs: async (opts, info)=>{
16
- async function getRawProcedureInputOrThrow() {
17
- try {
18
- if (opts.url.searchParams.has('input')) {
19
- const input = opts.url.searchParams.get('input');
20
- if (!input) {
21
- return undefined;
22
- }
23
- return JSON.parse(input);
24
- }
25
- return await opts.req.json();
26
- } catch (cause) {
27
- throw new TRPCError.TRPCError({
28
- code: 'PARSE_ERROR',
29
- cause
30
- });
31
- }
32
- }
33
- const deserializeInputValue = (rawValue, transformer)=>{
34
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
35
- };
36
- const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
37
- if (rawInput === undefined) {
38
- return undefined;
39
- }
40
- const transformer = opts.router._def._config.transformer;
41
- if (!info.isBatchCall) {
42
- return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
43
- }
44
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
45
- throw new TRPCError.TRPCError({
46
- code: 'BAD_REQUEST',
47
- message: '"input" needs to be an object when doing a batch call'
48
- });
49
- }
50
- return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
51
- }
52
- };
53
- };
54
-
55
- exports.getFetchHTTPJSONContentTypeHandler = getFetchHTTPJSONContentTypeHandler;
@@ -1,53 +0,0 @@
1
- import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
- import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
4
-
5
- // @trpc/server
6
- const getFetchHTTPJSONContentTypeHandler = ()=>{
7
- const cache = createConcurrentCache();
8
- return {
9
- name: 'fetch-json',
10
- isMatch: (headers)=>{
11
- return !!headers.get('content-type')?.startsWith('application/json');
12
- },
13
- getInputs: async (opts, info)=>{
14
- async function getRawProcedureInputOrThrow() {
15
- try {
16
- if (opts.url.searchParams.has('input')) {
17
- const input = opts.url.searchParams.get('input');
18
- if (!input) {
19
- return undefined;
20
- }
21
- return JSON.parse(input);
22
- }
23
- return await opts.req.json();
24
- } catch (cause) {
25
- throw new TRPCError({
26
- code: 'PARSE_ERROR',
27
- cause
28
- });
29
- }
30
- }
31
- const deserializeInputValue = (rawValue, transformer)=>{
32
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
33
- };
34
- const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
35
- if (rawInput === undefined) {
36
- return undefined;
37
- }
38
- const transformer = opts.router._def._config.transformer;
39
- if (!info.isBatchCall) {
40
- return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
41
- }
42
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
43
- throw new TRPCError({
44
- code: 'BAD_REQUEST',
45
- message: '"input" needs to be an object when doing a batch call'
46
- });
47
- }
48
- return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
49
- }
50
- };
51
- };
52
-
53
- 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 getFormDataContentTypeHandler: <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/form-data/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,6BAA6B,EAAE,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,OAC7B,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CA0B5D,CAAC"}
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- var node_stream = require('node:stream');
4
-
5
- const getFormDataContentTypeHandler = ()=>({
6
- name: 'node-http-formdata',
7
- isMatch: (headers)=>{
8
- return !!headers.get('content-type')?.startsWith('multipart/form-data');
9
- },
10
- async getInputs (opts, inputOpts) {
11
- if (inputOpts.isBatchCall) {
12
- throw new Error('Batch calls not supported for form-data');
13
- }
14
- const contentType = opts.req.headers['content-type'];
15
- if (!contentType) {
16
- // Should be unreachable given the isMatch check
17
- throw new Error('No content-type header found');
18
- }
19
- const form = await new Request('https://unused.com', {
20
- method: 'POST',
21
- headers: {
22
- 'content-type': contentType
23
- },
24
- body: node_stream.Readable.toWeb(opts.req),
25
- // @ts-expect-error - outdated types? this exists
26
- duplex: 'half'
27
- }).formData();
28
- return form;
29
- }
30
- });
31
-
32
- exports.getFormDataContentTypeHandler = getFormDataContentTypeHandler;
@@ -1,30 +0,0 @@
1
- import { Readable } from 'node:stream';
2
-
3
- const getFormDataContentTypeHandler = ()=>({
4
- name: 'node-http-formdata',
5
- isMatch: (headers)=>{
6
- return !!headers.get('content-type')?.startsWith('multipart/form-data');
7
- },
8
- async getInputs (opts, inputOpts) {
9
- if (inputOpts.isBatchCall) {
10
- throw new Error('Batch calls not supported for form-data');
11
- }
12
- const contentType = opts.req.headers['content-type'];
13
- if (!contentType) {
14
- // Should be unreachable given the isMatch check
15
- throw new Error('No content-type header found');
16
- }
17
- const form = await new Request('https://unused.com', {
18
- method: 'POST',
19
- headers: {
20
- 'content-type': contentType
21
- },
22
- body: Readable.toWeb(opts.req),
23
- // @ts-expect-error - outdated types? this exists
24
- duplex: 'half'
25
- }).formData();
26
- return form;
27
- }
28
- });
29
-
30
- export { getFormDataContentTypeHandler };
@@ -1,7 +0,0 @@
1
- import type { BodyResult } from '../../../../@trpc/server/http';
2
- import type { NodeHTTPRequest } from '../../types';
3
- export declare function getPostBody(opts: {
4
- req: NodeHTTPRequest;
5
- maxBodySize?: number;
6
- }): Promise<BodyResult>;
7
- //# sourceMappingURL=getPostBody.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPostBody.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/json/getPostBody.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,WAAW,CAAC,IAAI,EAAE;IACtC,GAAG,EAAE,eAAe,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,UAAU,CAAC,CAwCtB"}
@@ -1,45 +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
- async function getPostBody(opts) {
8
- const { req , maxBodySize =Infinity } = opts;
9
- return new Promise((resolve)=>{
10
- if ('body' in req) {
11
- resolve({
12
- ok: true,
13
- data: req.body,
14
- // If the request headers specifies a content-type, we assume that the body has been preprocessed
15
- preprocessed: !!req.headers['content-type']?.startsWith('application/json')
16
- });
17
- return;
18
- }
19
- let body = '';
20
- let hasBody = false;
21
- function onData(data) {
22
- body += data;
23
- hasBody = true;
24
- if (body.length > maxBodySize) {
25
- req.off('data', onData);
26
- resolve({
27
- ok: false,
28
- error: new TRPCError.TRPCError({
29
- code: 'PAYLOAD_TOO_LARGE'
30
- })
31
- });
32
- }
33
- }
34
- req.on('data', onData);
35
- req.on('end', ()=>{
36
- resolve({
37
- ok: true,
38
- data: hasBody ? body : undefined,
39
- preprocessed: false
40
- });
41
- });
42
- });
43
- }
44
-
45
- exports.getPostBody = getPostBody;
@@ -1,43 +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
- async function getPostBody(opts) {
6
- const { req , maxBodySize =Infinity } = opts;
7
- return new Promise((resolve)=>{
8
- if ('body' in req) {
9
- resolve({
10
- ok: true,
11
- data: req.body,
12
- // If the request headers specifies a content-type, we assume that the body has been preprocessed
13
- preprocessed: !!req.headers['content-type']?.startsWith('application/json')
14
- });
15
- return;
16
- }
17
- let body = '';
18
- let hasBody = false;
19
- function onData(data) {
20
- body += data;
21
- hasBody = true;
22
- if (body.length > maxBodySize) {
23
- req.off('data', onData);
24
- resolve({
25
- ok: false,
26
- error: new TRPCError({
27
- code: 'PAYLOAD_TOO_LARGE'
28
- })
29
- });
30
- }
31
- }
32
- req.on('data', onData);
33
- req.on('end', ()=>{
34
- resolve({
35
- ok: true,
36
- data: hasBody ? body : undefined,
37
- preprocessed: false
38
- });
39
- });
40
- });
41
- }
42
-
43
- export { getPostBody };
@@ -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 getNodeHTTPJSONContentTypeHandler: <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/json/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EAEV,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAG3D,eAAO,MAAM,iCAAiC,EAAE,CAC9C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,OAC7B,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAoF7D,CAAC"}
@@ -1,68 +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
- var concurrentCache = require('../../../content-handlers/concurrentCache.js');
6
- var getPostBody = require('./getPostBody.js');
7
-
8
- // @trpc/server
9
- const getNodeHTTPJSONContentTypeHandler = ()=>{
10
- const cache = concurrentCache.createConcurrentCache();
11
- return {
12
- name: 'node-http-json',
13
- isMatch: (headers)=>{
14
- return !!headers.get('content-type')?.startsWith('application/json');
15
- },
16
- getInputs: async (opts, info)=>{
17
- async function getRawProcedureInputOrThrow() {
18
- const bodyResult = await getPostBody.getPostBody(opts);
19
- if (!bodyResult.ok) {
20
- throw bodyResult.error;
21
- }
22
- const preprocessedBody = bodyResult.preprocessed;
23
- const body = bodyResult.data;
24
- try {
25
- if (opts.req.method === 'GET') {
26
- const input = opts.query.get('input');
27
- if (!input) {
28
- return undefined;
29
- }
30
- return JSON.parse(input);
31
- }
32
- if (preprocessedBody || typeof body !== 'string') {
33
- // Some tools like nextjs may parse json
34
- // requests before they reach us. So we just use them as is
35
- return body;
36
- } else {
37
- return JSON.parse(body);
38
- }
39
- } catch (cause) {
40
- throw new TRPCError.TRPCError({
41
- code: 'PARSE_ERROR',
42
- cause
43
- });
44
- }
45
- }
46
- const deserializeInputValue = (rawValue, transformer)=>{
47
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
48
- };
49
- const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
50
- if (rawInput === undefined) {
51
- return undefined;
52
- }
53
- const transformer = opts.router._def._config.transformer;
54
- if (!info.isBatchCall) {
55
- return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
56
- }
57
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
58
- throw new TRPCError.TRPCError({
59
- code: 'BAD_REQUEST',
60
- message: '"input" needs to be an object when doing a batch call'
61
- });
62
- }
63
- return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
64
- }
65
- };
66
- };
67
-
68
- exports.getNodeHTTPJSONContentTypeHandler = getNodeHTTPJSONContentTypeHandler;
@@ -1,66 +0,0 @@
1
- import { TRPCError } from '../../../../unstable-core-do-not-import/error/TRPCError.mjs';
2
- import '../../../../unstable-core-do-not-import/rootConfig.mjs';
3
- import { createConcurrentCache } from '../../../content-handlers/concurrentCache.mjs';
4
- import { getPostBody } from './getPostBody.mjs';
5
-
6
- // @trpc/server
7
- const getNodeHTTPJSONContentTypeHandler = ()=>{
8
- const cache = createConcurrentCache();
9
- return {
10
- name: 'node-http-json',
11
- isMatch: (headers)=>{
12
- return !!headers.get('content-type')?.startsWith('application/json');
13
- },
14
- getInputs: async (opts, info)=>{
15
- async function getRawProcedureInputOrThrow() {
16
- const bodyResult = await getPostBody(opts);
17
- if (!bodyResult.ok) {
18
- throw bodyResult.error;
19
- }
20
- const preprocessedBody = bodyResult.preprocessed;
21
- const body = bodyResult.data;
22
- try {
23
- if (opts.req.method === 'GET') {
24
- const input = opts.query.get('input');
25
- if (!input) {
26
- return undefined;
27
- }
28
- return JSON.parse(input);
29
- }
30
- if (preprocessedBody || typeof body !== 'string') {
31
- // Some tools like nextjs may parse json
32
- // requests before they reach us. So we just use them as is
33
- return body;
34
- } else {
35
- return JSON.parse(body);
36
- }
37
- } catch (cause) {
38
- throw new TRPCError({
39
- code: 'PARSE_ERROR',
40
- cause
41
- });
42
- }
43
- }
44
- const deserializeInputValue = (rawValue, transformer)=>{
45
- return typeof rawValue !== 'undefined' ? transformer.input.deserialize(rawValue) : rawValue;
46
- };
47
- const rawInput = await cache.concurrentSafeGet('rawInput', ()=>getRawProcedureInputOrThrow());
48
- if (rawInput === undefined) {
49
- return undefined;
50
- }
51
- const transformer = opts.router._def._config.transformer;
52
- if (!info.isBatchCall) {
53
- return cache.concurrentSafeGet('input', ()=>deserializeInputValue(rawInput, transformer));
54
- }
55
- /* istanbul ignore if */ if (rawInput == null || typeof rawInput !== 'object' || Array.isArray(rawInput)) {
56
- throw new TRPCError({
57
- code: 'BAD_REQUEST',
58
- message: '"input" needs to be an object when doing a batch call'
59
- });
60
- }
61
- return cache.concurrentSafeGet(String(info.batch), ()=>deserializeInputValue(rawInput[info.batch], transformer));
62
- }
63
- };
64
- };
65
-
66
- export { getNodeHTTPJSONContentTypeHandler };
@@ -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;