@trpc/server 11.0.0-rc.619 → 11.0.0-rc.630

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 (74) hide show
  1. package/dist/adapters/aws-lambda/getPlanner.js +2 -2
  2. package/dist/adapters/aws-lambda/getPlanner.mjs +2 -2
  3. package/dist/adapters/aws-lambda/index.js +1 -0
  4. package/dist/adapters/aws-lambda/index.mjs +1 -0
  5. package/dist/adapters/express.js +1 -0
  6. package/dist/adapters/express.mjs +1 -0
  7. package/dist/adapters/fastify/fastifyRequestHandler.js +1 -0
  8. package/dist/adapters/fastify/fastifyRequestHandler.mjs +1 -0
  9. package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -1
  10. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -1
  11. package/dist/adapters/fetch/fetchRequestHandler.js +7 -6
  12. package/dist/adapters/fetch/fetchRequestHandler.mjs +7 -6
  13. package/dist/adapters/next-app-dir/nextAppDirCaller.js +5 -4
  14. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +5 -4
  15. package/dist/adapters/next-app-dir/notFound.js +1 -0
  16. package/dist/adapters/next-app-dir/notFound.mjs +1 -0
  17. package/dist/adapters/next-app-dir/redirect.js +3 -1
  18. package/dist/adapters/next-app-dir/redirect.mjs +3 -1
  19. package/dist/adapters/next-app-dir/rethrowNextErrors.js +1 -1
  20. package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +1 -1
  21. package/dist/adapters/next.js +1 -0
  22. package/dist/adapters/next.mjs +1 -0
  23. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
  24. package/dist/adapters/node-http/incomingMessageToRequest.js +7 -2
  25. package/dist/adapters/node-http/incomingMessageToRequest.mjs +7 -2
  26. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +5 -4
  27. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +5 -4
  28. package/dist/adapters/standalone.js +1 -0
  29. package/dist/adapters/standalone.mjs +1 -0
  30. package/dist/adapters/ws.js +9 -9
  31. package/dist/adapters/ws.mjs +9 -9
  32. package/dist/bundle-analysis.json +122 -105
  33. package/dist/http.js +1 -0
  34. package/dist/http.mjs +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/index.mjs +1 -0
  37. package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +11 -0
  38. package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +9 -0
  39. package/dist/observable/observable.js +1 -1
  40. package/dist/observable/observable.mjs +1 -1
  41. package/dist/rpc.js +1 -0
  42. package/dist/rpc.mjs +1 -0
  43. package/dist/shared.js +1 -0
  44. package/dist/shared.mjs +1 -0
  45. package/dist/unstable-core-do-not-import/createProxy.js +1 -1
  46. package/dist/unstable-core-do-not-import/createProxy.mjs +1 -1
  47. package/dist/unstable-core-do-not-import/error/TRPCError.js +4 -1
  48. package/dist/unstable-core-do-not-import/error/TRPCError.mjs +4 -1
  49. package/dist/unstable-core-do-not-import/error/formatter.js +1 -1
  50. package/dist/unstable-core-do-not-import/error/formatter.mjs +1 -1
  51. package/dist/unstable-core-do-not-import/error/getErrorShape.js +2 -2
  52. package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +2 -2
  53. package/dist/unstable-core-do-not-import/http/contentType.js +3 -3
  54. package/dist/unstable-core-do-not-import/http/contentType.mjs +3 -3
  55. package/dist/unstable-core-do-not-import/http/resolveResponse.js +24 -24
  56. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +24 -24
  57. package/dist/unstable-core-do-not-import/middleware.js +1 -1
  58. package/dist/unstable-core-do-not-import/middleware.mjs +1 -1
  59. package/dist/unstable-core-do-not-import/procedureBuilder.js +1 -1
  60. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -1
  61. package/dist/unstable-core-do-not-import/router.js +2 -2
  62. package/dist/unstable-core-do-not-import/router.mjs +2 -2
  63. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +2 -2
  64. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +2 -2
  65. package/dist/unstable-core-do-not-import/stream/jsonl.js +14 -15
  66. package/dist/unstable-core-do-not-import/stream/jsonl.mjs +14 -15
  67. package/dist/unstable-core-do-not-import/stream/sse.js +2 -2
  68. package/dist/unstable-core-do-not-import/stream/sse.mjs +2 -2
  69. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +1 -1
  70. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +1 -1
  71. package/dist/vendor/unpromise/unpromise.js +21 -16
  72. package/dist/vendor/unpromise/unpromise.mjs +21 -16
  73. package/package.json +11 -4
  74. package/src/adapters/node-http/incomingMessageToRequest.ts +7 -2
@@ -68,7 +68,7 @@ const v1Processor = {
68
68
  },
69
69
  getMethod: (event)=>event.httpMethod,
70
70
  toResult: async (response)=>{
71
- const { headers , cookies } = getHeadersAndCookiesFromResponse(response);
71
+ const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
72
72
  const result = {
73
73
  ...cookies.length && {
74
74
  multiValueHeaders: {
@@ -115,7 +115,7 @@ const v2Processor = {
115
115
  },
116
116
  getMethod: (event)=>event.requestContext.http.method,
117
117
  toResult: async (response)=>{
118
- const { headers , cookies } = getHeadersAndCookiesFromResponse(response);
118
+ const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
119
119
  const result = {
120
120
  cookies,
121
121
  statusCode: response.status,
@@ -66,7 +66,7 @@ const v1Processor = {
66
66
  },
67
67
  getMethod: (event)=>event.httpMethod,
68
68
  toResult: async (response)=>{
69
- const { headers , cookies } = getHeadersAndCookiesFromResponse(response);
69
+ const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
70
70
  const result = {
71
71
  ...cookies.length && {
72
72
  multiValueHeaders: {
@@ -113,7 +113,7 @@ const v2Processor = {
113
113
  },
114
114
  getMethod: (event)=>event.requestContext.http.method,
115
115
  toResult: async (response)=>{
116
- const { headers , cookies } = getHeadersAndCookiesFromResponse(response);
116
+ const { headers, cookies } = getHeadersAndCookiesFromResponse(response);
117
117
  const result = {
118
118
  cookies,
119
119
  statusCode: response.status,
@@ -2,6 +2,7 @@
2
2
 
3
3
  var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
4
4
  require('../../unstable-core-do-not-import/rootConfig.js');
5
+ require('../../vendor/unpromise/unpromise.js');
5
6
  var getPlanner = require('./getPlanner.js');
6
7
 
7
8
  function awsLambdaRequestHandler(opts) {
@@ -1,5 +1,6 @@
1
1
  import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
2
2
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
+ import '../../vendor/unpromise/unpromise.mjs';
3
4
  import { getPlanner } from './getPlanner.mjs';
4
5
 
5
6
  function awsLambdaRequestHandler(opts) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('../unstable-core-do-not-import/utils.js');
4
+ require('../vendor/unpromise/unpromise.js');
4
5
  require('../unstable-core-do-not-import/rootConfig.js');
5
6
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
6
7
 
@@ -1,4 +1,5 @@
1
1
  import { run } from '../unstable-core-do-not-import/utils.mjs';
2
+ import '../vendor/unpromise/unpromise.mjs';
2
3
  import '../unstable-core-do-not-import/rootConfig.mjs';
3
4
  import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
4
5
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
4
4
  require('../../unstable-core-do-not-import/rootConfig.js');
5
+ require('../../vendor/unpromise/unpromise.js');
5
6
  var incomingMessageToRequest = require('../node-http/incomingMessageToRequest.js');
6
7
 
7
8
  /**
@@ -1,5 +1,6 @@
1
1
  import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
2
2
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
+ import '../../vendor/unpromise/unpromise.mjs';
3
4
  import { incomingMessageToRequest } from '../node-http/incomingMessageToRequest.mjs';
4
5
 
5
6
  /**
@@ -45,7 +45,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
45
45
  }, async (socket, req)=>{
46
46
  await onConnection(socket, req.raw);
47
47
  if (trpcOptions?.keepAlive?.enabled) {
48
- const { pingMs , pongWaitMs } = trpcOptions.keepAlive;
48
+ const { pingMs, pongWaitMs } = trpcOptions.keepAlive;
49
49
  ws.handleKeepAlive(socket, pingMs, pongWaitMs);
50
50
  }
51
51
  });
@@ -43,7 +43,7 @@ function fastifyTRPCPlugin(fastify, opts, done) {
43
43
  }, async (socket, req)=>{
44
44
  await onConnection(socket, req.raw);
45
45
  if (trpcOptions?.keepAlive?.enabled) {
46
- const { pingMs , pongWaitMs } = trpcOptions.keepAlive;
46
+ const { pingMs, pongWaitMs } = trpcOptions.keepAlive;
47
47
  handleKeepAlive(socket, pingMs, pongWaitMs);
48
48
  }
49
49
  });
@@ -2,6 +2,7 @@
2
2
 
3
3
  var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
4
4
  require('../../unstable-core-do-not-import/rootConfig.js');
5
+ require('../../vendor/unpromise/unpromise.js');
5
6
 
6
7
  /**
7
8
  * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
@@ -52,13 +53,13 @@ async function fetchRequestHandler(opts) {
52
53
  } else {
53
54
  /**
54
55
  * @deprecated, delete in v12
55
- */ for (const [key1, value1] of Object.entries(meta.headers)){
56
- if (Array.isArray(value1)) {
57
- for (const v of value1){
58
- resHeaders.append(key1, v);
56
+ */ for (const [key, value] of Object.entries(meta.headers)){
57
+ if (Array.isArray(value)) {
58
+ for (const v of value){
59
+ resHeaders.append(key, v);
59
60
  }
60
- } else if (typeof value1 === 'string') {
61
- resHeaders.set(key1, value1);
61
+ } else if (typeof value === 'string') {
62
+ resHeaders.set(key, value);
62
63
  }
63
64
  }
64
65
  }
@@ -1,5 +1,6 @@
1
1
  import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
2
2
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
+ import '../../vendor/unpromise/unpromise.mjs';
3
4
 
4
5
  /**
5
6
  * If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
@@ -50,13 +51,13 @@ async function fetchRequestHandler(opts) {
50
51
  } else {
51
52
  /**
52
53
  * @deprecated, delete in v12
53
- */ for (const [key1, value1] of Object.entries(meta.headers)){
54
- if (Array.isArray(value1)) {
55
- for (const v of value1){
56
- resHeaders.append(key1, v);
54
+ */ for (const [key, value] of Object.entries(meta.headers)){
55
+ if (Array.isArray(value)) {
56
+ for (const v of value){
57
+ resHeaders.append(key, v);
57
58
  }
58
- } else if (typeof value1 === 'string') {
59
- resHeaders.set(key1, value1);
59
+ } else if (typeof value === 'string') {
60
+ resHeaders.set(key, value);
60
61
  }
61
62
  }
62
63
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
4
  var formDataToObject = require('../../unstable-core-do-not-import/http/formDataToObject.js');
5
+ require('../../vendor/unpromise/unpromise.js');
5
6
  require('../../unstable-core-do-not-import/rootConfig.js');
6
7
  var redirect = require('./redirect.js');
7
8
  var rethrowNextErrors = require('./rethrowNextErrors.js');
@@ -9,7 +10,7 @@ var rethrowNextErrors = require('./rethrowNextErrors.js');
9
10
  /**
10
11
  * Create a caller that works with Next.js React Server Components & Server Actions
11
12
  */ function nextAppDirCaller(config) {
12
- const { normalizeFormData =true } = config;
13
+ const { normalizeFormData = true } = config;
13
14
  const createContext = async ()=>{
14
15
  return config?.createContext?.() ?? {};
15
16
  };
@@ -63,13 +64,13 @@ var rethrowNextErrors = require('./rethrowNextErrors.js');
63
64
  }
64
65
  case 'query':
65
66
  {
66
- const input1 = opts.args[0];
67
+ const input = opts.args[0];
67
68
  return await opts.invoke({
68
69
  type: opts._def.type,
69
70
  ctx,
70
- getRawInput: async ()=>input1,
71
+ getRawInput: async ()=>input,
71
72
  path,
72
- input: input1,
73
+ input,
73
74
  signal: undefined
74
75
  }).then((data)=>{
75
76
  if (data instanceof redirect.TRPCRedirectError) throw data;
@@ -1,5 +1,6 @@
1
1
  import { TRPCError, getTRPCErrorFromUnknown } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
2
  import { formDataToObject } from '../../unstable-core-do-not-import/http/formDataToObject.mjs';
3
+ import '../../vendor/unpromise/unpromise.mjs';
3
4
  import '../../unstable-core-do-not-import/rootConfig.mjs';
4
5
  import { TRPCRedirectError } from './redirect.mjs';
5
6
  import { rethrowNextErrors } from './rethrowNextErrors.mjs';
@@ -7,7 +8,7 @@ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
7
8
  /**
8
9
  * Create a caller that works with Next.js React Server Components & Server Actions
9
10
  */ function nextAppDirCaller(config) {
10
- const { normalizeFormData =true } = config;
11
+ const { normalizeFormData = true } = config;
11
12
  const createContext = async ()=>{
12
13
  return config?.createContext?.() ?? {};
13
14
  };
@@ -61,13 +62,13 @@ import { rethrowNextErrors } from './rethrowNextErrors.mjs';
61
62
  }
62
63
  case 'query':
63
64
  {
64
- const input1 = opts.args[0];
65
+ const input = opts.args[0];
65
66
  return await opts.invoke({
66
67
  type: opts._def.type,
67
68
  ctx,
68
- getRawInput: async ()=>input1,
69
+ getRawInput: async ()=>input,
69
70
  path,
70
- input: input1,
71
+ input,
71
72
  signal: undefined
72
73
  }).then((data)=>{
73
74
  if (data instanceof TRPCRedirectError) throw data;
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
+ require('../../vendor/unpromise/unpromise.js');
4
5
  require('../../unstable-core-do-not-import/rootConfig.js');
5
6
 
6
7
  /**
@@ -1,4 +1,5 @@
1
1
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
+ import '../../vendor/unpromise/unpromise.mjs';
2
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
4
 
4
5
  /**
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ var _define_property = require('../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js');
3
4
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
5
+ require('../../vendor/unpromise/unpromise.js');
4
6
  require('../../unstable-core-do-not-import/rootConfig.js');
5
7
 
6
8
  /**
@@ -11,7 +13,7 @@ require('../../unstable-core-do-not-import/rootConfig.js');
11
13
  // TODO(?): This should maybe a custom error code
12
14
  code: 'UNPROCESSABLE_CONTENT',
13
15
  message: `Redirect error to "${url}" that will be handled by Next.js`
14
- });
16
+ }), _define_property._(this, "args", void 0);
15
17
  this.args = [
16
18
  url.toString(),
17
19
  redirectType
@@ -1,4 +1,6 @@
1
+ import { _ as _define_property } from '../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs';
1
2
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
3
+ import '../../vendor/unpromise/unpromise.mjs';
2
4
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
5
 
4
6
  /**
@@ -9,7 +11,7 @@ import '../../unstable-core-do-not-import/rootConfig.mjs';
9
11
  // TODO(?): This should maybe a custom error code
10
12
  code: 'UNPROCESSABLE_CONTENT',
11
13
  message: `Redirect error to "${url}" that will be handled by Next.js`
12
- });
14
+ }), _define_property(this, "args", void 0);
13
15
  this.args = [
14
16
  url.toString(),
15
17
  redirectType
@@ -55,7 +55,7 @@ function isNotFoundError(error) {
55
55
  if (error instanceof redirect.TRPCRedirectError) {
56
56
  nextNavigation__namespace.redirect(...error.args);
57
57
  }
58
- const { cause } = error;
58
+ const { cause } = error;
59
59
  // Next.js 15 has `unstable_rethrow`. Use that if it exists.
60
60
  if ('unstable_rethrow' in nextNavigation__namespace && typeof nextNavigation__namespace.unstable_rethrow === 'function') {
61
61
  nextNavigation__namespace.unstable_rethrow(cause);
@@ -34,7 +34,7 @@ function isNotFoundError(error) {
34
34
  if (error instanceof TRPCRedirectError) {
35
35
  nextNavigation.redirect(...error.args);
36
36
  }
37
- const { cause } = error;
37
+ const { cause } = error;
38
38
  // Next.js 15 has `unstable_rethrow`. Use that if it exists.
39
39
  if ('unstable_rethrow' in nextNavigation && typeof nextNavigation.unstable_rethrow === 'function') {
40
40
  nextNavigation.unstable_rethrow(cause);
@@ -2,6 +2,7 @@
2
2
 
3
3
  var utils = require('../unstable-core-do-not-import/utils.js');
4
4
  var TRPCError = require('../unstable-core-do-not-import/error/TRPCError.js');
5
+ require('../vendor/unpromise/unpromise.js');
5
6
  require('../unstable-core-do-not-import/rootConfig.js');
6
7
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
7
8
 
@@ -1,5 +1,6 @@
1
1
  import { run } from '../unstable-core-do-not-import/utils.mjs';
2
2
  import { TRPCError } from '../unstable-core-do-not-import/error/TRPCError.mjs';
3
+ import '../vendor/unpromise/unpromise.mjs';
3
4
  import '../unstable-core-do-not-import/rootConfig.mjs';
4
5
  import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
5
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,eAAe;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,GAAG,CAkBxD;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CA6BT"}
1
+ {"version":3,"file":"incomingMessageToRequest.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/incomingMessageToRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CAAC,eAAe;IACnE;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAiED,wBAAgB,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,GAAG,GAAG,CAkBxD;AAwBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,IAAI,EAAE;IACJ;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GACA,OAAO,CAkCT"}
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var TRPCError = require('../../unstable-core-do-not-import/error/TRPCError.js');
4
+ require('../../vendor/unpromise/unpromise.js');
4
5
  require('../../unstable-core-do-not-import/rootConfig.js');
5
6
 
6
7
  function createBody(req, opts) {
@@ -84,9 +85,13 @@ function createHeaders(incoming) {
84
85
  * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
85
86
  */ function incomingMessageToRequest(req, opts) {
86
87
  const ac = new AbortController();
87
- req.once('aborted', ()=>{
88
+ const onAbort = ()=>{
88
89
  ac.abort();
89
- });
90
+ req.off('aborted', onAbort);
91
+ req.off('close', onAbort);
92
+ };
93
+ req.once('aborted', onAbort);
94
+ req.socket?.once('close', onAbort);
90
95
  // Get host from either regular header or HTTP/2 pseudo-header
91
96
  const url = createURL(req);
92
97
  const init = {
@@ -1,4 +1,5 @@
1
1
  import { TRPCError } from '../../unstable-core-do-not-import/error/TRPCError.mjs';
2
+ import '../../vendor/unpromise/unpromise.mjs';
2
3
  import '../../unstable-core-do-not-import/rootConfig.mjs';
3
4
 
4
5
  function createBody(req, opts) {
@@ -82,9 +83,13 @@ function createHeaders(incoming) {
82
83
  * Convert an [`IncomingMessage`](https://nodejs.org/api/http.html#class-httpincomingmessage) to a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
83
84
  */ function incomingMessageToRequest(req, opts) {
84
85
  const ac = new AbortController();
85
- req.once('aborted', ()=>{
86
+ const onAbort = ()=>{
86
87
  ac.abort();
87
- });
88
+ req.off('aborted', onAbort);
89
+ req.off('close', onAbort);
90
+ };
91
+ req.once('aborted', onAbort);
92
+ req.socket?.once('close', onAbort);
88
93
  // Get host from either regular header or HTTP/2 pseudo-header
89
94
  const url = createURL(req);
90
95
  const init = {
@@ -6,6 +6,7 @@ var utils = require('../../unstable-core-do-not-import/utils.js');
6
6
  var resolveResponse = require('../../unstable-core-do-not-import/http/resolveResponse.js');
7
7
  require('../../unstable-core-do-not-import/rootConfig.js');
8
8
  var transformer = require('../../unstable-core-do-not-import/transformer.js');
9
+ require('../../vendor/unpromise/unpromise.js');
9
10
  var incomingMessageToRequest = require('./incomingMessageToRequest.js');
10
11
 
11
12
  /**
@@ -21,7 +22,7 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
21
22
  * @internal
22
23
  */ function internal_exceptionHandler(opts) {
23
24
  return (cause)=>{
24
- const { res , req } = opts;
25
+ const { res, req } = opts;
25
26
  const error = TRPCError.getTRPCErrorFromUnknown(cause);
26
27
  const shape = getErrorShape.getErrorShape({
27
28
  config: opts.router._def._config,
@@ -78,7 +79,7 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
78
79
  });
79
80
  }
80
81
  });
81
- const { res } = opts;
82
+ const { res } = opts;
82
83
  if (res.statusCode === 200) {
83
84
  // if the status code is set, we assume that it's been manually overridden
84
85
  res.statusCode = response.status;
@@ -98,14 +99,14 @@ var incomingMessageToRequest = require('./incomingMessageToRequest.js');
98
99
  once: true
99
100
  });
100
101
  while(true){
101
- const { done , value: value1 } = await reader.read();
102
+ const { done, value } = await reader.read();
102
103
  if (done) {
103
104
  break;
104
105
  }
105
106
  if (!res.writable) {
106
107
  break;
107
108
  }
108
- if (res.write(value1) === false) {
109
+ if (res.write(value) === false) {
109
110
  await new Promise((resolve)=>{
110
111
  res.once('drain', resolve);
111
112
  });
@@ -4,6 +4,7 @@ import { run } from '../../unstable-core-do-not-import/utils.mjs';
4
4
  import { resolveResponse } from '../../unstable-core-do-not-import/http/resolveResponse.mjs';
5
5
  import '../../unstable-core-do-not-import/rootConfig.mjs';
6
6
  import { transformTRPCResponse } from '../../unstable-core-do-not-import/transformer.mjs';
7
+ import '../../vendor/unpromise/unpromise.mjs';
7
8
  import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
8
9
 
9
10
  /**
@@ -19,7 +20,7 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
19
20
  * @internal
20
21
  */ function internal_exceptionHandler(opts) {
21
22
  return (cause)=>{
22
- const { res , req } = opts;
23
+ const { res, req } = opts;
23
24
  const error = getTRPCErrorFromUnknown(cause);
24
25
  const shape = getErrorShape({
25
26
  config: opts.router._def._config,
@@ -76,7 +77,7 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
76
77
  });
77
78
  }
78
79
  });
79
- const { res } = opts;
80
+ const { res } = opts;
80
81
  if (res.statusCode === 200) {
81
82
  // if the status code is set, we assume that it's been manually overridden
82
83
  res.statusCode = response.status;
@@ -96,14 +97,14 @@ import { incomingMessageToRequest } from './incomingMessageToRequest.mjs';
96
97
  once: true
97
98
  });
98
99
  while(true){
99
- const { done , value: value1 } = await reader.read();
100
+ const { done, value } = await reader.read();
100
101
  if (done) {
101
102
  break;
102
103
  }
103
104
  if (!res.writable) {
104
105
  break;
105
106
  }
106
- if (res.write(value1) === false) {
107
+ if (res.write(value) === false) {
107
108
  await new Promise((resolve)=>{
108
109
  res.once('drain', resolve);
109
110
  });
@@ -2,6 +2,7 @@
2
2
 
3
3
  var http = require('node:http');
4
4
  var utils = require('../unstable-core-do-not-import/utils.js');
5
+ require('../vendor/unpromise/unpromise.js');
5
6
  require('../unstable-core-do-not-import/rootConfig.js');
6
7
  var nodeHTTPRequestHandler = require('./node-http/nodeHTTPRequestHandler.js');
7
8
  var incomingMessageToRequest = require('./node-http/incomingMessageToRequest.js');
@@ -1,5 +1,6 @@
1
1
  import http from 'node:http';
2
2
  import { run } from '../unstable-core-do-not-import/utils.mjs';
3
+ import '../vendor/unpromise/unpromise.mjs';
3
4
  import '../unstable-core-do-not-import/rootConfig.mjs';
4
5
  import { nodeHTTPRequestHandler, internal_exceptionHandler } from './node-http/nodeHTTPRequestHandler.mjs';
5
6
  import { createURL } from './node-http/incomingMessageToRequest.mjs';
@@ -19,13 +19,13 @@ var incomingMessageToRequest = require('./node-http/incomingMessageToRequest.js'
19
19
  */ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
20
20
  const unsetContextPromiseSymbol = Symbol('unsetContextPromise');
21
21
  function getWSConnectionHandler(opts) {
22
- const { createContext , router: router$1 } = opts;
23
- const { transformer: transformer$1 } = router$1._def._config;
22
+ const { createContext, router: router$1 } = opts;
23
+ const { transformer: transformer$1 } = router$1._def._config;
24
24
  return async (client, req)=>{
25
25
  const clientSubscriptions = new Map();
26
26
  const abortController = new AbortController();
27
27
  if (opts.keepAlive?.enabled) {
28
- const { pingMs , pongWaitMs } = opts.keepAlive;
28
+ const { pingMs, pongWaitMs } = opts.keepAlive;
29
29
  handleKeepAlive(client, pingMs, pongWaitMs);
30
30
  }
31
31
  function respond(untransformedJSON) {
@@ -82,7 +82,7 @@ function getWSConnectionHandler(opts) {
82
82
  * - if connection params are expected, they will be created once received
83
83
  */ let ctxPromise = incomingMessageToRequest.createURL(req).searchParams.get('connectionParams') === '1' ? unsetContextPromiseSymbol : createCtxPromise(()=>null);
84
84
  async function handleRequest(msg) {
85
- const { id , jsonrpc } = msg;
85
+ const { id, jsonrpc } = msg;
86
86
  /* istanbul ignore next -- @preserve */ if (id === null) {
87
87
  throw new TRPCError.TRPCError({
88
88
  code: 'BAD_REQUEST',
@@ -93,8 +93,8 @@ function getWSConnectionHandler(opts) {
93
93
  clientSubscriptions.get(id)?.abort();
94
94
  return;
95
95
  }
96
- const { path , lastEventId } = msg.params;
97
- let { input } = msg.params;
96
+ const { path, lastEventId } = msg.params;
97
+ let { input } = msg.params;
98
98
  const type = msg.method;
99
99
  try {
100
100
  if (lastEventId !== undefined) {
@@ -207,10 +207,10 @@ function getWSConnectionHandler(opts) {
207
207
  data: next.value
208
208
  };
209
209
  if (tracked.isTrackedEnvelope(next.value)) {
210
- const [id1, data] = next.value;
211
- result.id = id1;
210
+ const [id, data] = next.value;
211
+ result.id = id;
212
212
  result.data = {
213
- id: id1,
213
+ id,
214
214
  data
215
215
  };
216
216
  }
@@ -17,13 +17,13 @@ import { createURL } from './node-http/incomingMessageToRequest.mjs';
17
17
  */ const WEBSOCKET_OPEN = 1; /* ws.WebSocket.OPEN */
18
18
  const unsetContextPromiseSymbol = Symbol('unsetContextPromise');
19
19
  function getWSConnectionHandler(opts) {
20
- const { createContext , router } = opts;
21
- const { transformer } = router._def._config;
20
+ const { createContext, router } = opts;
21
+ const { transformer } = router._def._config;
22
22
  return async (client, req)=>{
23
23
  const clientSubscriptions = new Map();
24
24
  const abortController = new AbortController();
25
25
  if (opts.keepAlive?.enabled) {
26
- const { pingMs , pongWaitMs } = opts.keepAlive;
26
+ const { pingMs, pongWaitMs } = opts.keepAlive;
27
27
  handleKeepAlive(client, pingMs, pongWaitMs);
28
28
  }
29
29
  function respond(untransformedJSON) {
@@ -80,7 +80,7 @@ function getWSConnectionHandler(opts) {
80
80
  * - if connection params are expected, they will be created once received
81
81
  */ let ctxPromise = createURL(req).searchParams.get('connectionParams') === '1' ? unsetContextPromiseSymbol : createCtxPromise(()=>null);
82
82
  async function handleRequest(msg) {
83
- const { id , jsonrpc } = msg;
83
+ const { id, jsonrpc } = msg;
84
84
  /* istanbul ignore next -- @preserve */ if (id === null) {
85
85
  throw new TRPCError({
86
86
  code: 'BAD_REQUEST',
@@ -91,8 +91,8 @@ function getWSConnectionHandler(opts) {
91
91
  clientSubscriptions.get(id)?.abort();
92
92
  return;
93
93
  }
94
- const { path , lastEventId } = msg.params;
95
- let { input } = msg.params;
94
+ const { path, lastEventId } = msg.params;
95
+ let { input } = msg.params;
96
96
  const type = msg.method;
97
97
  try {
98
98
  if (lastEventId !== undefined) {
@@ -205,10 +205,10 @@ function getWSConnectionHandler(opts) {
205
205
  data: next.value
206
206
  };
207
207
  if (isTrackedEnvelope(next.value)) {
208
- const [id1, data] = next.value;
209
- result.id = id1;
208
+ const [id, data] = next.value;
209
+ result.id = id;
210
210
  result.data = {
211
- id: id1,
211
+ id,
212
212
  data
213
213
  };
214
214
  }