@trpc/server 11.0.0-rc.621 → 11.0.0-rc.632

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 (133) hide show
  1. package/dist/@trpc/server/http.d.ts +1 -1
  2. package/dist/@trpc/server/http.d.ts.map +1 -1
  3. package/dist/adapters/aws-lambda/getPlanner.js +2 -2
  4. package/dist/adapters/aws-lambda/getPlanner.mjs +2 -2
  5. package/dist/adapters/aws-lambda/index.js +2 -0
  6. package/dist/adapters/aws-lambda/index.mjs +2 -0
  7. package/dist/adapters/express.js +2 -0
  8. package/dist/adapters/express.mjs +2 -0
  9. package/dist/adapters/fastify/fastifyRequestHandler.js +3 -1
  10. package/dist/adapters/fastify/fastifyRequestHandler.mjs +3 -1
  11. package/dist/adapters/fastify/fastifyTRPCPlugin.js +1 -1
  12. package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +1 -1
  13. package/dist/adapters/fetch/fetchRequestHandler.js +8 -6
  14. package/dist/adapters/fetch/fetchRequestHandler.mjs +8 -6
  15. package/dist/adapters/next-app-dir/nextAppDirCaller.js +6 -4
  16. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +6 -4
  17. package/dist/adapters/next-app-dir/notFound.js +2 -0
  18. package/dist/adapters/next-app-dir/notFound.mjs +2 -0
  19. package/dist/adapters/next-app-dir/redirect.js +4 -1
  20. package/dist/adapters/next-app-dir/redirect.mjs +4 -1
  21. package/dist/adapters/next-app-dir/rethrowNextErrors.js +1 -1
  22. package/dist/adapters/next-app-dir/rethrowNextErrors.mjs +1 -1
  23. package/dist/adapters/next.js +2 -0
  24. package/dist/adapters/next.mjs +2 -0
  25. package/dist/adapters/node-http/incomingMessageToRequest.d.ts +1 -1
  26. package/dist/adapters/node-http/incomingMessageToRequest.d.ts.map +1 -1
  27. package/dist/adapters/node-http/incomingMessageToRequest.js +8 -5
  28. package/dist/adapters/node-http/incomingMessageToRequest.mjs +8 -5
  29. package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +1 -1
  30. package/dist/adapters/node-http/nodeHTTPRequestHandler.js +11 -43
  31. package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +11 -43
  32. package/dist/adapters/node-http/writeResponse.d.ts +18 -0
  33. package/dist/adapters/node-http/writeResponse.d.ts.map +1 -0
  34. package/dist/adapters/node-http/writeResponse.js +85 -0
  35. package/dist/adapters/node-http/writeResponse.mjs +82 -0
  36. package/dist/adapters/standalone.js +2 -0
  37. package/dist/adapters/standalone.mjs +2 -0
  38. package/dist/adapters/ws.js +11 -10
  39. package/dist/adapters/ws.mjs +11 -10
  40. package/dist/bundle-analysis.json +230 -186
  41. package/dist/http.js +2 -2
  42. package/dist/http.mjs +2 -1
  43. package/dist/index.js +2 -0
  44. package/dist/index.mjs +2 -0
  45. package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js +11 -0
  46. package/dist/node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs +9 -0
  47. package/dist/observable/observable.js +1 -1
  48. package/dist/observable/observable.mjs +1 -1
  49. package/dist/rpc.js +2 -0
  50. package/dist/rpc.mjs +2 -0
  51. package/dist/shared.js +2 -0
  52. package/dist/shared.mjs +2 -0
  53. package/dist/unstable-core-do-not-import/createProxy.js +1 -1
  54. package/dist/unstable-core-do-not-import/createProxy.mjs +1 -1
  55. package/dist/unstable-core-do-not-import/error/TRPCError.js +4 -1
  56. package/dist/unstable-core-do-not-import/error/TRPCError.mjs +4 -1
  57. package/dist/unstable-core-do-not-import/error/formatter.js +1 -1
  58. package/dist/unstable-core-do-not-import/error/formatter.mjs +1 -1
  59. package/dist/unstable-core-do-not-import/error/getErrorShape.js +2 -2
  60. package/dist/unstable-core-do-not-import/error/getErrorShape.mjs +2 -2
  61. package/dist/unstable-core-do-not-import/http/contentType.js +3 -3
  62. package/dist/unstable-core-do-not-import/http/contentType.mjs +3 -3
  63. package/dist/unstable-core-do-not-import/http/isAbortError.d.ts +4 -0
  64. package/dist/unstable-core-do-not-import/http/isAbortError.d.ts.map +1 -0
  65. package/dist/unstable-core-do-not-import/http/isAbortError.js +9 -0
  66. package/dist/unstable-core-do-not-import/http/isAbortError.mjs +7 -0
  67. package/dist/unstable-core-do-not-import/http/resolveResponse.js +24 -24
  68. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +24 -24
  69. package/dist/unstable-core-do-not-import/middleware.js +1 -1
  70. package/dist/unstable-core-do-not-import/middleware.mjs +1 -1
  71. package/dist/unstable-core-do-not-import/procedureBuilder.js +1 -1
  72. package/dist/unstable-core-do-not-import/procedureBuilder.mjs +1 -1
  73. package/dist/unstable-core-do-not-import/router.js +2 -2
  74. package/dist/unstable-core-do-not-import/router.mjs +2 -2
  75. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.js +2 -2
  76. package/dist/unstable-core-do-not-import/rpc/parseTRPCMessage.mjs +2 -2
  77. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts +6 -9
  78. package/dist/unstable-core-do-not-import/stream/jsonl.d.ts.map +1 -1
  79. package/dist/unstable-core-do-not-import/stream/jsonl.js +86 -136
  80. package/dist/unstable-core-do-not-import/stream/jsonl.mjs +87 -137
  81. package/dist/unstable-core-do-not-import/stream/sse.d.ts.map +1 -1
  82. package/dist/unstable-core-do-not-import/stream/sse.js +27 -23
  83. package/dist/unstable-core-do-not-import/stream/sse.mjs +28 -24
  84. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts +10 -10
  85. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.d.ts.map +1 -1
  86. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.js +47 -34
  87. package/dist/unstable-core-do-not-import/stream/utils/asyncIterable.mjs +47 -34
  88. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts +0 -4
  89. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.d.ts.map +1 -1
  90. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.js +0 -11
  91. package/dist/unstable-core-do-not-import/stream/utils/createReadableStream.mjs +1 -11
  92. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts +6 -0
  93. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.d.ts.map +1 -0
  94. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.js +28 -0
  95. package/dist/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.mjs +25 -0
  96. package/dist/unstable-core-do-not-import/stream/utils/withPing.d.ts.map +1 -1
  97. package/dist/unstable-core-do-not-import/stream/utils/withPing.js +17 -17
  98. package/dist/unstable-core-do-not-import/stream/utils/withPing.mjs +17 -17
  99. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts +17 -0
  100. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.d.ts.map +1 -0
  101. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.js +59 -0
  102. package/dist/unstable-core-do-not-import/stream/utils/withRefCount.mjs +57 -0
  103. package/dist/unstable-core-do-not-import.d.ts +2 -2
  104. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  105. package/dist/unstable-core-do-not-import.js +2 -2
  106. package/dist/unstable-core-do-not-import.mjs +1 -1
  107. package/dist/vendor/unpromise/unpromise.js +21 -16
  108. package/dist/vendor/unpromise/unpromise.mjs +21 -16
  109. package/package.json +12 -5
  110. package/src/@trpc/server/http.ts +0 -1
  111. package/src/adapters/fastify/fastifyRequestHandler.ts +1 -1
  112. package/src/adapters/node-http/incomingMessageToRequest.ts +8 -4
  113. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +8 -46
  114. package/src/adapters/node-http/writeResponse.ts +96 -0
  115. package/src/unstable-core-do-not-import/http/isAbortError.ts +7 -0
  116. package/src/unstable-core-do-not-import/stream/jsonl.ts +85 -154
  117. package/src/unstable-core-do-not-import/stream/sse.ts +24 -25
  118. package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +58 -37
  119. package/src/unstable-core-do-not-import/stream/utils/createReadableStream.ts +0 -13
  120. package/src/unstable-core-do-not-import/stream/utils/disposablePromiseTimer.ts +27 -0
  121. package/src/unstable-core-do-not-import/stream/utils/withPing.ts +31 -19
  122. package/src/unstable-core-do-not-import/stream/utils/withRefCount.ts +93 -0
  123. package/src/unstable-core-do-not-import.ts +2 -2
  124. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts +0 -24
  125. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.d.ts.map +0 -1
  126. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.js +0 -32
  127. package/dist/unstable-core-do-not-import/http/batchStreamFormatter.mjs +0 -30
  128. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts +0 -8
  129. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.d.ts.map +0 -1
  130. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.js +0 -38
  131. package/dist/unstable-core-do-not-import/stream/utils/promiseTimer.mjs +0 -36
  132. package/src/unstable-core-do-not-import/http/batchStreamFormatter.ts +0 -29
  133. package/src/unstable-core-do-not-import/stream/utils/promiseTimer.ts +0 -40
@@ -0,0 +1,57 @@
1
+ // Callback function type that is called when a collection is drained
2
+ function withRefCount(_obj, onDrain) {
3
+ const obj = _obj;
4
+ // Track whether the collection has been drained
5
+ let drained = false;
6
+ // Track whether the collection has been activated
7
+ let active = false;
8
+ // Check if collection should be drained (empty and active)
9
+ const checkDrain = ()=>{
10
+ if (!drained && active && obj.size === 0) {
11
+ onDrain();
12
+ drained = true;
13
+ }
14
+ };
15
+ // Create proxy to intercept collection operations
16
+ return new Proxy(obj, {
17
+ get (_, prop) {
18
+ // Handle activation
19
+ if (prop === 'activate') {
20
+ return ()=>{
21
+ active = true;
22
+ checkDrain();
23
+ };
24
+ }
25
+ // Handle adding items - prevent if already drained
26
+ if (prop === 'set' || prop === 'add') {
27
+ return (...args)=>{
28
+ if (drained) {
29
+ throw new Error('Already drained');
30
+ }
31
+ return obj[prop](...args);
32
+ };
33
+ }
34
+ // Handle removing items - check if should drain after
35
+ if (prop === 'delete' || prop === 'clear') {
36
+ return (...args)=>{
37
+ try {
38
+ return obj[prop](...args);
39
+ } finally{
40
+ checkDrain();
41
+ }
42
+ };
43
+ }
44
+ // Pass through other method calls
45
+ const target = obj[prop];
46
+ if (typeof target === 'function') {
47
+ return (...args)=>{
48
+ return obj[prop](...args);
49
+ };
50
+ }
51
+ // Pass through property access
52
+ return target;
53
+ }
54
+ });
55
+ }
56
+
57
+ export { withRefCount };
@@ -15,11 +15,11 @@ export * from './unstable-core-do-not-import/createProxy';
15
15
  export * from './unstable-core-do-not-import/error/formatter';
16
16
  export * from './unstable-core-do-not-import/error/getErrorShape';
17
17
  export * from './unstable-core-do-not-import/error/TRPCError';
18
- export * from './unstable-core-do-not-import/http/batchStreamFormatter';
19
18
  export * from './unstable-core-do-not-import/http/contentType';
20
19
  export * from './unstable-core-do-not-import/http/contentTypeParsers';
21
20
  export * from './unstable-core-do-not-import/http/formDataToObject';
22
21
  export * from './unstable-core-do-not-import/http/getHTTPStatusCode';
22
+ export * from './unstable-core-do-not-import/http/isAbortError';
23
23
  export * from './unstable-core-do-not-import/http/parseConnectionParams';
24
24
  export * from './unstable-core-do-not-import/http/resolveResponse';
25
25
  export * from './unstable-core-do-not-import/http/types';
@@ -32,8 +32,8 @@ export * from './unstable-core-do-not-import/rootConfig';
32
32
  export * from './unstable-core-do-not-import/router';
33
33
  export * from './unstable-core-do-not-import/rpc';
34
34
  export * from './unstable-core-do-not-import/stream/jsonl';
35
- export * from './unstable-core-do-not-import/stream/sse';
36
35
  export * from './unstable-core-do-not-import/stream/sse.types';
36
+ export * from './unstable-core-do-not-import/stream/sse';
37
37
  export * from './unstable-core-do-not-import/stream/tracked';
38
38
  export * from './unstable-core-do-not-import/stream/utils/createDeferred';
39
39
  export * from './unstable-core-do-not-import/transformer';
@@ -1 +1 @@
1
- {"version":3,"file":"unstable-core-do-not-import.d.ts","sourceRoot":"","sources":["../src/unstable-core-do-not-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,mDAAmD,CAAC;AAClE,cAAc,oDAAoD,CAAC;AACnE,cAAc,mDAAmD,CAAC;AAClE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,mDAAmD,CAAC;AAClE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,yDAAyD,CAAC;AACxE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,uDAAuD,CAAC;AACtE,cAAc,qDAAqD,CAAC;AACpE,cAAc,sDAAsD,CAAC;AACrE,cAAc,0DAA0D,CAAC;AACzE,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,sCAAsC,CAAC;AACrD,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,0CAA0C,CAAC;AACzD,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,0CAA0C,CAAC;AACzD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2DAA2D,CAAC;AAC1E,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC"}
1
+ {"version":3,"file":"unstable-core-do-not-import.d.ts","sourceRoot":"","sources":["../src/unstable-core-do-not-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,mDAAmD,CAAC;AAClE,cAAc,oDAAoD,CAAC;AACnE,cAAc,mDAAmD,CAAC;AAClE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,mDAAmD,CAAC;AAClE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,uDAAuD,CAAC;AACtE,cAAc,qDAAqD,CAAC;AACpE,cAAc,sDAAsD,CAAC;AACrE,cAAc,iDAAiD,CAAC;AAChE,cAAc,0DAA0D,CAAC;AACzE,cAAc,oDAAoD,CAAC;AACnE,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,0CAA0C,CAAC;AACzD,cAAc,sCAAsC,CAAC;AACrD,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,0CAA0C,CAAC;AACzD,cAAc,sCAAsC,CAAC;AACrD,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,0CAA0C,CAAC;AACzD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,2DAA2D,CAAC;AAC1E,cAAc,2CAA2C,CAAC;AAC1D,cAAc,qCAAqC,CAAC;AACpD,cAAc,qCAAqC,CAAC"}
@@ -4,11 +4,11 @@ var createProxy = require('./unstable-core-do-not-import/createProxy.js');
4
4
  var formatter = require('./unstable-core-do-not-import/error/formatter.js');
5
5
  var getErrorShape = require('./unstable-core-do-not-import/error/getErrorShape.js');
6
6
  var TRPCError = require('./unstable-core-do-not-import/error/TRPCError.js');
7
- var batchStreamFormatter = require('./unstable-core-do-not-import/http/batchStreamFormatter.js');
8
7
  var contentType = require('./unstable-core-do-not-import/http/contentType.js');
9
8
  var contentTypeParsers = require('./unstable-core-do-not-import/http/contentTypeParsers.js');
10
9
  var formDataToObject = require('./unstable-core-do-not-import/http/formDataToObject.js');
11
10
  var getHTTPStatusCode = require('./unstable-core-do-not-import/http/getHTTPStatusCode.js');
11
+ var isAbortError = require('./unstable-core-do-not-import/http/isAbortError.js');
12
12
  var parseConnectionParams = require('./unstable-core-do-not-import/http/parseConnectionParams.js');
13
13
  var resolveResponse = require('./unstable-core-do-not-import/http/resolveResponse.js');
14
14
  var initTRPC = require('./unstable-core-do-not-import/initTRPC.js');
@@ -36,7 +36,6 @@ exports.getErrorShape = getErrorShape.getErrorShape;
36
36
  exports.TRPCError = TRPCError.TRPCError;
37
37
  exports.getCauseFromUnknown = TRPCError.getCauseFromUnknown;
38
38
  exports.getTRPCErrorFromUnknown = TRPCError.getTRPCErrorFromUnknown;
39
- exports.getBatchStreamFormatter = batchStreamFormatter.getBatchStreamFormatter;
40
39
  exports.getRequestInfo = contentType.getRequestInfo;
41
40
  exports.octetInputParser = contentTypeParsers.octetInputParser;
42
41
  exports.formDataToObject = formDataToObject.formDataToObject;
@@ -46,6 +45,7 @@ exports.getHTTPStatusCode = getHTTPStatusCode.getHTTPStatusCode;
46
45
  exports.getHTTPStatusCodeFromError = getHTTPStatusCode.getHTTPStatusCodeFromError;
47
46
  exports.getStatusCodeFromKey = getHTTPStatusCode.getStatusCodeFromKey;
48
47
  exports.getStatusKeyFromCode = getHTTPStatusCode.getStatusKeyFromCode;
48
+ exports.isAbortError = isAbortError.isAbortError;
49
49
  exports.parseConnectionParamsFromString = parseConnectionParams.parseConnectionParamsFromString;
50
50
  exports.parseConnectionParamsFromUnknown = parseConnectionParams.parseConnectionParamsFromUnknown;
51
51
  exports.resolveResponse = resolveResponse.resolveResponse;
@@ -2,11 +2,11 @@ export { createFlatProxy, createRecursiveProxy } from './unstable-core-do-not-im
2
2
  export { defaultFormatter } from './unstable-core-do-not-import/error/formatter.mjs';
3
3
  export { getErrorShape } from './unstable-core-do-not-import/error/getErrorShape.mjs';
4
4
  export { TRPCError, getCauseFromUnknown, getTRPCErrorFromUnknown } from './unstable-core-do-not-import/error/TRPCError.mjs';
5
- export { getBatchStreamFormatter } from './unstable-core-do-not-import/http/batchStreamFormatter.mjs';
6
5
  export { getRequestInfo } from './unstable-core-do-not-import/http/contentType.mjs';
7
6
  export { octetInputParser } from './unstable-core-do-not-import/http/contentTypeParsers.mjs';
8
7
  export { formDataToObject } from './unstable-core-do-not-import/http/formDataToObject.mjs';
9
8
  export { HTTP_CODE_TO_JSONRPC2, JSONRPC2_TO_HTTP_CODE, getHTTPStatusCode, getHTTPStatusCodeFromError, getStatusCodeFromKey, getStatusKeyFromCode } from './unstable-core-do-not-import/http/getHTTPStatusCode.mjs';
9
+ export { isAbortError } from './unstable-core-do-not-import/http/isAbortError.mjs';
10
10
  export { parseConnectionParamsFromString, parseConnectionParamsFromUnknown } from './unstable-core-do-not-import/http/parseConnectionParams.mjs';
11
11
  export { resolveResponse } from './unstable-core-do-not-import/http/resolveResponse.mjs';
12
12
  export { initTRPC } from './unstable-core-do-not-import/initTRPC.mjs';
@@ -1,6 +1,9 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable @typescript-eslint/unbound-method */ /** Memory safe (weakmapped) cache of the ProxyPromise for each Promise,
3
+ var _define_property = require('../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.js');
4
+
5
+ var _computedKey;
6
+ /** Memory safe (weakmapped) cache of the ProxyPromise for each Promise,
4
7
  * which is retained for the lifetime of the original Promise.
5
8
  */ const subscribableCache = new WeakMap();
6
9
  /** A NOOP function allowing a consistent interface for settled
@@ -8,7 +11,8 @@
8
11
  * immediately). */ const NOOP = ()=>{
9
12
  // noop
10
13
  };
11
- let _toStringTag = Symbol.toStringTag;
14
+ _computedKey = Symbol.toStringTag;
15
+ let _computedKey1 = _computedKey;
12
16
  /**
13
17
  * Every `Promise<T>` can be shadowed by a single `ProxyPromise<T>`. It is
14
18
  * created once, cached and reused throughout the lifetime of the Promise. Get a
@@ -63,7 +67,7 @@ let _toStringTag = Symbol.toStringTag;
63
67
  // in all cases we will combine some promise with its unsubscribe function
64
68
  let promise;
65
69
  let unsubscribe;
66
- const { settlement } = this;
70
+ const { settlement } = this;
67
71
  if (settlement === null) {
68
72
  // not yet settled - subscribe new promise. Expect eventual settlement
69
73
  if (this.subscribers === null) {
@@ -80,7 +84,7 @@ let _toStringTag = Symbol.toStringTag;
80
84
  };
81
85
  } else {
82
86
  // settled - don't create subscribed promise. Just resolve or reject
83
- const { status } = settlement;
87
+ const { status } = settlement;
84
88
  if (status === "fulfilled") {
85
89
  promise = Promise.resolve(settlement.value);
86
90
  } else {
@@ -95,21 +99,21 @@ let _toStringTag = Symbol.toStringTag;
95
99
  }
96
100
  /** STANDARD PROMISE METHODS (but returning a SubscribedPromise) */ then(onfulfilled, onrejected) {
97
101
  const subscribed = this.subscribe();
98
- const { unsubscribe } = subscribed;
102
+ const { unsubscribe } = subscribed;
99
103
  return Object.assign(subscribed.then(onfulfilled, onrejected), {
100
104
  unsubscribe
101
105
  });
102
106
  }
103
107
  catch(onrejected) {
104
108
  const subscribed = this.subscribe();
105
- const { unsubscribe } = subscribed;
109
+ const { unsubscribe } = subscribed;
106
110
  return Object.assign(subscribed.catch(onrejected), {
107
111
  unsubscribe
108
112
  });
109
113
  }
110
114
  finally(onfinally) {
111
115
  const subscribed = this.subscribe();
112
- const { unsubscribe } = subscribed;
116
+ const { unsubscribe } = subscribed;
113
117
  return Object.assign(subscribed.finally(onfinally), {
114
118
  unsubscribe
115
119
  });
@@ -141,7 +145,7 @@ let _toStringTag = Symbol.toStringTag;
141
145
  try {
142
146
  return await Promise.any(subscribedPromises);
143
147
  } finally{
144
- subscribedPromises.forEach(({ unsubscribe })=>{
148
+ subscribedPromises.forEach(({ unsubscribe })=>{
145
149
  unsubscribe();
146
150
  });
147
151
  }
@@ -154,7 +158,7 @@ let _toStringTag = Symbol.toStringTag;
154
158
  try {
155
159
  return await Promise.race(subscribedPromises);
156
160
  } finally{
157
- subscribedPromises.forEach(({ unsubscribe })=>{
161
+ subscribedPromises.forEach(({ unsubscribe })=>{
158
162
  unsubscribe();
159
163
  });
160
164
  }
@@ -184,12 +188,13 @@ let _toStringTag = Symbol.toStringTag;
184
188
  }
185
189
  }
186
190
  constructor(arg){
191
+ /** INSTANCE IMPLEMENTATION */ /** The promise shadowed by this Unpromise<T> */ _define_property._(this, "promise", void 0);
187
192
  /** Promises expecting eventual settlement (unless unsubscribed first). This list is deleted
188
- * after the original promise settles - no further notifications will be issued. */ this.subscribers = [];
193
+ * after the original promise settles - no further notifications will be issued. */ _define_property._(this, "subscribers", []);
189
194
  /** The Promise's settlement (recorded when it fulfils or rejects). This is consulted when
190
195
  * calling .subscribe() .then() .catch() .finally() to see if an immediately-resolving Promise
191
- * can be returned, and therefore subscription can be bypassed. */ this.settlement = null;
192
- /** TOSTRING SUPPORT */ this[_toStringTag] = "Unpromise";
196
+ * can be returned, and therefore subscription can be bypassed. */ _define_property._(this, "settlement", null);
197
+ /** TOSTRING SUPPORT */ _define_property._(this, _computedKey1, "Unpromise");
193
198
  // handle either a Promise or a Promise executor function
194
199
  if (typeof arg === "function") {
195
200
  this.promise = new Promise(arg);
@@ -200,14 +205,14 @@ let _toStringTag = Symbol.toStringTag;
200
205
  // handle PromiseLike objects (that at least have .then)
201
206
  const thenReturn = this.promise.then((value)=>{
202
207
  // atomically record fulfilment and detach subscriber list
203
- const { subscribers } = this;
208
+ const { subscribers } = this;
204
209
  this.subscribers = null;
205
210
  this.settlement = {
206
211
  status: "fulfilled",
207
212
  value
208
213
  };
209
214
  // notify fulfilment to subscriber list
210
- subscribers?.forEach(({ resolve })=>{
215
+ subscribers?.forEach(({ resolve })=>{
211
216
  resolve(value);
212
217
  });
213
218
  });
@@ -215,14 +220,14 @@ let _toStringTag = Symbol.toStringTag;
215
220
  if ("catch" in thenReturn) {
216
221
  thenReturn.catch((reason)=>{
217
222
  // atomically record rejection and detach subscriber list
218
- const { subscribers } = this;
223
+ const { subscribers } = this;
219
224
  this.subscribers = null;
220
225
  this.settlement = {
221
226
  status: "rejected",
222
227
  reason
223
228
  };
224
229
  // notify rejection to subscriber list
225
- subscribers?.forEach(({ reject })=>{
230
+ subscribers?.forEach(({ reject })=>{
226
231
  reject(reason);
227
232
  });
228
233
  });
@@ -1,4 +1,7 @@
1
- /* eslint-disable @typescript-eslint/unbound-method */ /** Memory safe (weakmapped) cache of the ProxyPromise for each Promise,
1
+ import { _ as _define_property } from '../../node_modules/.pnpm/@swc_helpers@0.5.13/node_modules/@swc/helpers/esm/_define_property.mjs';
2
+
3
+ var _computedKey;
4
+ /** Memory safe (weakmapped) cache of the ProxyPromise for each Promise,
2
5
  * which is retained for the lifetime of the original Promise.
3
6
  */ const subscribableCache = new WeakMap();
4
7
  /** A NOOP function allowing a consistent interface for settled
@@ -6,7 +9,8 @@
6
9
  * immediately). */ const NOOP = ()=>{
7
10
  // noop
8
11
  };
9
- let _toStringTag = Symbol.toStringTag;
12
+ _computedKey = Symbol.toStringTag;
13
+ let _computedKey1 = _computedKey;
10
14
  /**
11
15
  * Every `Promise<T>` can be shadowed by a single `ProxyPromise<T>`. It is
12
16
  * created once, cached and reused throughout the lifetime of the Promise. Get a
@@ -61,7 +65,7 @@ let _toStringTag = Symbol.toStringTag;
61
65
  // in all cases we will combine some promise with its unsubscribe function
62
66
  let promise;
63
67
  let unsubscribe;
64
- const { settlement } = this;
68
+ const { settlement } = this;
65
69
  if (settlement === null) {
66
70
  // not yet settled - subscribe new promise. Expect eventual settlement
67
71
  if (this.subscribers === null) {
@@ -78,7 +82,7 @@ let _toStringTag = Symbol.toStringTag;
78
82
  };
79
83
  } else {
80
84
  // settled - don't create subscribed promise. Just resolve or reject
81
- const { status } = settlement;
85
+ const { status } = settlement;
82
86
  if (status === "fulfilled") {
83
87
  promise = Promise.resolve(settlement.value);
84
88
  } else {
@@ -93,21 +97,21 @@ let _toStringTag = Symbol.toStringTag;
93
97
  }
94
98
  /** STANDARD PROMISE METHODS (but returning a SubscribedPromise) */ then(onfulfilled, onrejected) {
95
99
  const subscribed = this.subscribe();
96
- const { unsubscribe } = subscribed;
100
+ const { unsubscribe } = subscribed;
97
101
  return Object.assign(subscribed.then(onfulfilled, onrejected), {
98
102
  unsubscribe
99
103
  });
100
104
  }
101
105
  catch(onrejected) {
102
106
  const subscribed = this.subscribe();
103
- const { unsubscribe } = subscribed;
107
+ const { unsubscribe } = subscribed;
104
108
  return Object.assign(subscribed.catch(onrejected), {
105
109
  unsubscribe
106
110
  });
107
111
  }
108
112
  finally(onfinally) {
109
113
  const subscribed = this.subscribe();
110
- const { unsubscribe } = subscribed;
114
+ const { unsubscribe } = subscribed;
111
115
  return Object.assign(subscribed.finally(onfinally), {
112
116
  unsubscribe
113
117
  });
@@ -139,7 +143,7 @@ let _toStringTag = Symbol.toStringTag;
139
143
  try {
140
144
  return await Promise.any(subscribedPromises);
141
145
  } finally{
142
- subscribedPromises.forEach(({ unsubscribe })=>{
146
+ subscribedPromises.forEach(({ unsubscribe })=>{
143
147
  unsubscribe();
144
148
  });
145
149
  }
@@ -152,7 +156,7 @@ let _toStringTag = Symbol.toStringTag;
152
156
  try {
153
157
  return await Promise.race(subscribedPromises);
154
158
  } finally{
155
- subscribedPromises.forEach(({ unsubscribe })=>{
159
+ subscribedPromises.forEach(({ unsubscribe })=>{
156
160
  unsubscribe();
157
161
  });
158
162
  }
@@ -182,12 +186,13 @@ let _toStringTag = Symbol.toStringTag;
182
186
  }
183
187
  }
184
188
  constructor(arg){
189
+ /** INSTANCE IMPLEMENTATION */ /** The promise shadowed by this Unpromise<T> */ _define_property(this, "promise", void 0);
185
190
  /** Promises expecting eventual settlement (unless unsubscribed first). This list is deleted
186
- * after the original promise settles - no further notifications will be issued. */ this.subscribers = [];
191
+ * after the original promise settles - no further notifications will be issued. */ _define_property(this, "subscribers", []);
187
192
  /** The Promise's settlement (recorded when it fulfils or rejects). This is consulted when
188
193
  * calling .subscribe() .then() .catch() .finally() to see if an immediately-resolving Promise
189
- * can be returned, and therefore subscription can be bypassed. */ this.settlement = null;
190
- /** TOSTRING SUPPORT */ this[_toStringTag] = "Unpromise";
194
+ * can be returned, and therefore subscription can be bypassed. */ _define_property(this, "settlement", null);
195
+ /** TOSTRING SUPPORT */ _define_property(this, _computedKey1, "Unpromise");
191
196
  // handle either a Promise or a Promise executor function
192
197
  if (typeof arg === "function") {
193
198
  this.promise = new Promise(arg);
@@ -198,14 +203,14 @@ let _toStringTag = Symbol.toStringTag;
198
203
  // handle PromiseLike objects (that at least have .then)
199
204
  const thenReturn = this.promise.then((value)=>{
200
205
  // atomically record fulfilment and detach subscriber list
201
- const { subscribers } = this;
206
+ const { subscribers } = this;
202
207
  this.subscribers = null;
203
208
  this.settlement = {
204
209
  status: "fulfilled",
205
210
  value
206
211
  };
207
212
  // notify fulfilment to subscriber list
208
- subscribers?.forEach(({ resolve })=>{
213
+ subscribers?.forEach(({ resolve })=>{
209
214
  resolve(value);
210
215
  });
211
216
  });
@@ -213,14 +218,14 @@ let _toStringTag = Symbol.toStringTag;
213
218
  if ("catch" in thenReturn) {
214
219
  thenReturn.catch((reason)=>{
215
220
  // atomically record rejection and detach subscriber list
216
- const { subscribers } = this;
221
+ const { subscribers } = this;
217
222
  this.subscribers = null;
218
223
  this.settlement = {
219
224
  status: "rejected",
220
225
  reason
221
226
  };
222
227
  // notify rejection to subscriber list
223
- subscribers?.forEach(({ reject })=>{
228
+ subscribers?.forEach(({ reject })=>{
224
229
  reject(reason);
225
230
  });
226
231
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-rc.621+87fde6297",
3
+ "version": "11.0.0-rc.632+3df8b21be",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -121,7 +121,7 @@
121
121
  "@types/aws-lambda": "^8.10.137",
122
122
  "@types/express": "^4.17.17",
123
123
  "@types/hash-sum": "^1.0.0",
124
- "@types/node": "^20.17.3",
124
+ "@types/node": "^22.9.0",
125
125
  "@types/react": "^18.3.1",
126
126
  "@types/react-dom": "^18.3.0",
127
127
  "@types/ws": "^8.2.0",
@@ -135,10 +135,10 @@
135
135
  "next": "^15.0.2",
136
136
  "react": "^18.3.1",
137
137
  "react-dom": "^18.3.1",
138
- "rollup": "^4.9.5",
138
+ "rollup": "^4.24.4",
139
139
  "superjson": "^1.12.4",
140
140
  "superstruct": "^2.0.0",
141
- "tslib": "^2.5.0",
141
+ "tslib": "^2.8.1",
142
142
  "tsx": "^4.0.0",
143
143
  "typescript": "^5.6.2",
144
144
  "valibot": "^0.42.0",
@@ -149,5 +149,12 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "87fde62978441b1cedd1d5cf7290f6ade9a92607"
152
+ "optionalDependencies": {
153
+ "@types/aws-lambda": "*",
154
+ "express": "*",
155
+ "fastify": "*",
156
+ "next": "*",
157
+ "ws": "*"
158
+ },
159
+ "gitHead": "3df8b21beb4925cf73194fc776d1a88603a3c420"
153
160
  }
@@ -18,7 +18,6 @@ export type {
18
18
  } from '../../unstable-core-do-not-import';
19
19
 
20
20
  export {
21
- getBatchStreamFormatter,
22
21
  octetInputParser,
23
22
  parseConnectionParamsFromUnknown,
24
23
  parseConnectionParamsFromString,
@@ -60,7 +60,7 @@ export async function fastifyRequestHandler<
60
60
  if ('body' in opts.req) {
61
61
  incomingMessage.body = opts.req.body;
62
62
  }
63
- const req = incomingMessageToRequest(incomingMessage, {
63
+ const req = incomingMessageToRequest(incomingMessage, opts.res.raw, {
64
64
  maxBodySize: null,
65
65
  });
66
66
 
@@ -118,6 +118,7 @@ function createHeaders(incoming: http.IncomingHttpHeaders): Headers {
118
118
  */
119
119
  export function incomingMessageToRequest(
120
120
  req: http.IncomingMessage,
121
+ res: http.ServerResponse,
121
122
  opts: {
122
123
  /**
123
124
  * Max body size in bytes. If the body is larger than this, the request will be aborted
@@ -128,12 +129,15 @@ export function incomingMessageToRequest(
128
129
  const ac = new AbortController();
129
130
 
130
131
  const onAbort = () => {
132
+ res.off('close', onAbort);
133
+ req.socket.off('end', onAbort);
134
+
135
+ // abort the request
131
136
  ac.abort();
132
- req.off('aborted', onAbort);
133
- req.off('close', onAbort);
134
137
  };
135
- req.once('aborted', onAbort);
136
- req.socket?.once('close', onAbort);
138
+
139
+ res.once('close', onAbort);
140
+ req.socket.once('end', onAbort);
137
141
 
138
142
  // Get host from either regular header or HTTP/2 pseudo-header
139
143
  const url = createURL(req);
@@ -25,6 +25,7 @@ import type {
25
25
  NodeHTTPRequestHandlerOptions,
26
26
  NodeHTTPResponse,
27
27
  } from './types';
28
+ import { writeResponse } from './writeResponse';
28
29
 
29
30
  /**
30
31
  * @internal
@@ -82,7 +83,7 @@ export async function nodeHTTPRequestHandler<
82
83
  });
83
84
  return handleViaMiddleware(opts.req, opts.res, (err: unknown) => {
84
85
  run(async () => {
85
- const req = incomingMessageToRequest(opts.req, {
86
+ const request = incomingMessageToRequest(opts.req, opts.res, {
86
87
  maxBodySize: opts.maxBodySize ?? null,
87
88
  });
88
89
 
@@ -98,7 +99,7 @@ export async function nodeHTTPRequestHandler<
98
99
 
99
100
  const response = await resolveResponse({
100
101
  ...opts,
101
- req,
102
+ req: request,
102
103
  error: err ? getTRPCErrorFromUnknown(err) : null,
103
104
  createContext,
104
105
  onError(o) {
@@ -109,50 +110,11 @@ export async function nodeHTTPRequestHandler<
109
110
  },
110
111
  });
111
112
 
112
- const { res } = opts;
113
- if (res.statusCode === 200) {
114
- // if the status code is set, we assume that it's been manually overridden
115
- res.statusCode = response.status;
116
- }
117
- for (const [key, value] of response.headers) {
118
- res.setHeader(key, value);
119
- }
120
- if (response.body) {
121
- const reader = response.body.getReader();
122
- const onAbort = () => {
123
- // cancelling the reader will cause the whole stream to be cancelled
124
- reader.cancel().catch(() => {
125
- // console.error('reader.cancel() error', err);
126
- });
127
- };
128
- req.signal.addEventListener('abort', onAbort, {
129
- once: true,
130
- });
131
-
132
- while (true) {
133
- const { done, value } = await reader.read();
134
-
135
- if (done) {
136
- break;
137
- }
138
- if (!res.writable) {
139
- break;
140
- }
141
- if (res.write(value) === false) {
142
- await new Promise<void>((resolve) => {
143
- res.once('drain', resolve);
144
- });
145
- }
146
-
147
- // useful for debugging chunked responses:
148
- // console.log('wrote', Buffer.from(value).toString());
149
-
150
- // IMPORTANT - flush the response buffer, otherwise the client will not receive the data until `.end()`
151
- res.flush?.();
152
- }
153
- req.signal.removeEventListener('abort', onAbort);
154
- }
155
- res.end();
113
+ await writeResponse({
114
+ request,
115
+ response,
116
+ rawResponse: opts.res,
117
+ });
156
118
  }).catch(internal_exceptionHandler(opts));
157
119
  });
158
120
  });
@@ -0,0 +1,96 @@
1
+ // eslint-disable-next-line no-restricted-imports
2
+ import { isAbortError } from '../../unstable-core-do-not-import';
3
+ import type { NodeHTTPResponse } from './types';
4
+
5
+ async function writeResponseBodyChunk(
6
+ res: NodeHTTPResponse,
7
+ chunk: Uint8Array,
8
+ ) {
9
+ if (res.write(chunk) === false) {
10
+ await new Promise<void>((resolve, reject) => {
11
+ const onError = (err: unknown) => {
12
+ reject(err);
13
+ cleanup();
14
+ };
15
+ const onDrain = () => {
16
+ resolve();
17
+ cleanup();
18
+ };
19
+ const cleanup = () => {
20
+ res.off('error', onError);
21
+ res.off('drain', onDrain);
22
+ };
23
+ res.once('error', onError);
24
+ res.once('drain', onDrain);
25
+ });
26
+ }
27
+ }
28
+ /**
29
+ * @internal
30
+ */
31
+
32
+ export async function writeResponseBody(opts: {
33
+ res: NodeHTTPResponse;
34
+ signal: AbortSignal;
35
+ body: NonNullable<Response['body']>;
36
+ }) {
37
+ const { res } = opts;
38
+
39
+ try {
40
+ const writableStream = new WritableStream({
41
+ async write(chunk) {
42
+ await writeResponseBodyChunk(res, chunk);
43
+ res.flush?.();
44
+ },
45
+ abort() {
46
+ if (!res.headersSent) {
47
+ res.statusCode = 500;
48
+ }
49
+ },
50
+ });
51
+
52
+ await opts.body.pipeTo(writableStream, {
53
+ signal: opts.signal,
54
+ });
55
+ } catch (err) {
56
+ if (isAbortError(err)) {
57
+ return;
58
+ }
59
+ throw err;
60
+ }
61
+ }
62
+ /**
63
+ * @internal
64
+ */
65
+
66
+ export async function writeResponse(opts: {
67
+ request: Request;
68
+ response: Response;
69
+ rawResponse: NodeHTTPResponse;
70
+ }) {
71
+ const { response, rawResponse } = opts;
72
+
73
+ // Only override status code if it hasn't been explicitly set in a procedure etc
74
+ if (rawResponse.statusCode === 200) {
75
+ rawResponse.statusCode = response.status;
76
+ }
77
+ for (const [key, value] of response.headers) {
78
+ rawResponse.setHeader(key, value);
79
+ }
80
+ try {
81
+ if (response.body) {
82
+ await writeResponseBody({
83
+ res: rawResponse,
84
+ signal: opts.request.signal,
85
+ body: response.body,
86
+ });
87
+ }
88
+ } catch (err) {
89
+ if (!rawResponse.headersSent) {
90
+ rawResponse.statusCode = 500;
91
+ }
92
+ throw err;
93
+ } finally {
94
+ rawResponse.end();
95
+ }
96
+ }