@trpc/server 11.0.0-alpha-tmp-issues-5851-take-two.488 → 11.0.0-alpha-tmp-issues-5851-take-two.490

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.
@@ -1 +1 @@
1
- {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI7E,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAsElE"}
1
+ {"version":3,"file":"nodeHTTPRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/node-http/nodeHTTPRequestHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAA2B,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI7E,OAAO,KAAK,EACV,eAAe,EACf,6BAA6B,EAC7B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB,wBAAsB,sBAAsB,CAC1C,OAAO,SAAS,SAAS,EACzB,QAAQ,SAAS,eAAe,EAChC,SAAS,SAAS,gBAAgB,EAClC,IAAI,EAAE,6BAA6B,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,iBAwElE"}
@@ -55,7 +55,9 @@ async function nodeHTTPRequestHandler(opts) {
55
55
  // console.error('reader.cancel() error', err);
56
56
  });
57
57
  };
58
- req.signal.addEventListener('abort', onAbort);
58
+ req.signal.addEventListener('abort', onAbort, {
59
+ once: true
60
+ });
59
61
  while(true){
60
62
  const { done , value: value1 } = await reader.read();
61
63
  if (done) {
@@ -53,7 +53,9 @@ async function nodeHTTPRequestHandler(opts) {
53
53
  // console.error('reader.cancel() error', err);
54
54
  });
55
55
  };
56
- req.signal.addEventListener('abort', onAbort);
56
+ req.signal.addEventListener('abort', onAbort, {
57
+ once: true
58
+ });
57
59
  while(true){
58
60
  const { done , value: value1 } = await reader.read();
59
61
  if (done) {
@@ -1 +1 @@
1
- {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/adapters/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAS,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAatE,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAQlE;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,8BAA8B,CACpE,eAAe,EACf,EAAE,CAAC,SAAS,CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1D,IAAI,EAAE,yBAAyB,KAC5B,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAE/C,MAAM,MAAM,0BAA0B,CAAC,OAAO,SAAS,SAAS,IAC9D,kBAAkB,CAAC,OAAO,EAAE,eAAe,CAAC,GAC1C,qBAAqB,CACnB,kBAAkB,CAAC,OAAO,CAAC,EAC3B,kBAAkB,CAAC,OAAO,CAAC,CAC5B,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,SAAS,IACrD,0BAA0B,CAA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A0B,CAAC,OAAO,SAAS,SAAS,IAC9D,kBAAkB,CAAC,OAAO,EAAE,eAAe,CAAC,GAC1C,qBAAqB,CACnB,kBAAkB,CAAC,OAAO,CAAC,EAC3B,kBAAkB,CAAC,OAAO,CAAC,CAC5B,CAAC;AAEN;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,OAAO,SAAS,SAAS,IACrD,0BAA0B,CAAC,OAAO,CAAC,GAAG;IACpC,GAAG,EAAE,EAAE,CAAC,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE;QACV;;;WAGG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;;WAGG;QACH,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAGJ,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,YAKnB,EAAE,CAAC,SAAS,OAAO,eAAe,mBAmUzD;AAiCD,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EACvD,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;;EA+BjC"}
@@ -21,12 +21,13 @@ function getWSConnectionHandler(opts) {
21
21
  const { transformer: transformer$1 } = router$1._def._config;
22
22
  return async (client, req)=>{
23
23
  const clientSubscriptions = new Map();
24
+ const abortController = new AbortController();
24
25
  function respond(untransformedJSON) {
25
26
  client.send(JSON.stringify(transformer.transformTRPCResponse(router$1._def._config, untransformedJSON)));
26
27
  }
27
- function createCtxPromise(getConnectionParams) {
28
- return utils.run(async ()=>{
29
- ctx = await createContext?.({
28
+ async function createCtxPromise(getConnectionParams) {
29
+ try {
30
+ return await createContext?.({
30
31
  req,
31
32
  res: client,
32
33
  info: {
@@ -34,11 +35,11 @@ function getWSConnectionHandler(opts) {
34
35
  calls: [],
35
36
  isBatchCall: false,
36
37
  accept: null,
37
- type: 'unknown'
38
+ type: 'unknown',
39
+ signal: abortController.signal
38
40
  }
39
41
  });
40
- return ctx;
41
- }).catch((cause)=>{
42
+ } catch (cause) {
42
43
  const error = TRPCError.getTRPCErrorFromUnknown(cause);
43
44
  opts.onError?.({
44
45
  error,
@@ -64,7 +65,7 @@ function getWSConnectionHandler(opts) {
64
65
  client.close();
65
66
  });
66
67
  throw error;
67
- });
68
+ }
68
69
  }
69
70
  /**
70
71
  * promise for initializing the context
@@ -72,7 +73,7 @@ function getWSConnectionHandler(opts) {
72
73
  * - the context promise will be created immediately on connection if no connectionParams are expected
73
74
  * - if connection params are expected, they will be created once received
74
75
  */ let ctxPromise = toURL.toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextSymbol : createCtxPromise(()=>null);
75
- let ctx = undefined;
76
+ const ctx = undefined;
76
77
  async function handleRequest(msg) {
77
78
  const { id , jsonrpc } = msg;
78
79
  /* istanbul ignore next -- @preserve */ if (id === null) {
@@ -310,6 +311,7 @@ function getWSConnectionHandler(opts) {
310
311
  sub.abort();
311
312
  }
312
313
  clientSubscriptions.clear();
314
+ abortController.abort();
313
315
  });
314
316
  if (ctxPromise !== unsetContextSymbol) {
315
317
  // prevent unhandled promise rejection errors
@@ -1,6 +1,6 @@
1
1
  import { getErrorShape } from '../unstable-core-do-not-import/error/getErrorShape.mjs';
2
2
  import { TRPCError, getTRPCErrorFromUnknown } from '../unstable-core-do-not-import/error/TRPCError.mjs';
3
- import { run, isAsyncIterable, isObject } from '../unstable-core-do-not-import/utils.mjs';
3
+ import { isAsyncIterable, run, isObject } from '../unstable-core-do-not-import/utils.mjs';
4
4
  import { parseConnectionParamsFromUnknown } from '../unstable-core-do-not-import/http/parseConnectionParams.mjs';
5
5
  import { parseTRPCMessage } from '../unstable-core-do-not-import/rpc/parseTRPCMessage.mjs';
6
6
  import { isObservable, observableToAsyncIterable } from '../observable/observable.mjs';
@@ -19,12 +19,13 @@ function getWSConnectionHandler(opts) {
19
19
  const { transformer } = router._def._config;
20
20
  return async (client, req)=>{
21
21
  const clientSubscriptions = new Map();
22
+ const abortController = new AbortController();
22
23
  function respond(untransformedJSON) {
23
24
  client.send(JSON.stringify(transformTRPCResponse(router._def._config, untransformedJSON)));
24
25
  }
25
- function createCtxPromise(getConnectionParams) {
26
- return run(async ()=>{
27
- ctx = await createContext?.({
26
+ async function createCtxPromise(getConnectionParams) {
27
+ try {
28
+ return await createContext?.({
28
29
  req,
29
30
  res: client,
30
31
  info: {
@@ -32,11 +33,11 @@ function getWSConnectionHandler(opts) {
32
33
  calls: [],
33
34
  isBatchCall: false,
34
35
  accept: null,
35
- type: 'unknown'
36
+ type: 'unknown',
37
+ signal: abortController.signal
36
38
  }
37
39
  });
38
- return ctx;
39
- }).catch((cause)=>{
40
+ } catch (cause) {
40
41
  const error = getTRPCErrorFromUnknown(cause);
41
42
  opts.onError?.({
42
43
  error,
@@ -62,7 +63,7 @@ function getWSConnectionHandler(opts) {
62
63
  client.close();
63
64
  });
64
65
  throw error;
65
- });
66
+ }
66
67
  }
67
68
  /**
68
69
  * promise for initializing the context
@@ -70,7 +71,7 @@ function getWSConnectionHandler(opts) {
70
71
  * - the context promise will be created immediately on connection if no connectionParams are expected
71
72
  * - if connection params are expected, they will be created once received
72
73
  */ let ctxPromise = toURL(req.url ?? '').searchParams.get('connectionParams') === '1' ? unsetContextSymbol : createCtxPromise(()=>null);
73
- let ctx = undefined;
74
+ const ctx = undefined;
74
75
  async function handleRequest(msg) {
75
76
  const { id , jsonrpc } = msg;
76
77
  /* istanbul ignore next -- @preserve */ if (id === null) {
@@ -308,6 +309,7 @@ function getWSConnectionHandler(opts) {
308
309
  sub.abort();
309
310
  }
310
311
  clientSubscriptions.clear();
312
+ abortController.abort();
311
313
  });
312
314
  if (ctxPromise !== unsetContextSymbol) {
313
315
  // prevent unhandled promise rejection errors
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 131082,
3
- "bundleOrigSize": 180516,
4
- "bundleReduction": 27.38,
2
+ "bundleSize": 131324,
3
+ "bundleOrigSize": 180714,
4
+ "bundleReduction": 27.33,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/unstable-core-do-not-import/stream/jsonl.ts",
@@ -17,7 +17,7 @@
17
17
  "/src/unstable-core-do-not-import.ts",
18
18
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
19
19
  ],
20
- "percent": 13.23,
20
+ "percent": 13.2,
21
21
  "reduction": 4.22
22
22
  },
23
23
  {
@@ -31,13 +31,13 @@
31
31
  "dependents": [
32
32
  "/src/unstable-core-do-not-import.ts"
33
33
  ],
34
- "percent": 13.03,
34
+ "percent": 13,
35
35
  "reduction": 0
36
36
  },
37
37
  {
38
38
  "id": "/src/adapters/ws.ts",
39
- "size": 14274,
40
- "origSize": 13514,
39
+ "size": 14376,
40
+ "origSize": 13603,
41
41
  "renderedExports": [
42
42
  "getWSConnectionHandler",
43
43
  "applyWSSHandler"
@@ -46,13 +46,13 @@
46
46
  "dependents": [
47
47
  "/src/adapters/fastify/fastifyTRPCPlugin.ts"
48
48
  ],
49
- "percent": 10.89,
49
+ "percent": 10.95,
50
50
  "reduction": 0
51
51
  },
52
52
  {
53
53
  "id": "/src/unstable-core-do-not-import/http/contentType.ts",
54
- "size": 7592,
55
- "origSize": 7530,
54
+ "size": 7688,
55
+ "origSize": 7608,
56
56
  "renderedExports": [
57
57
  "getRequestInfo"
58
58
  ],
@@ -61,7 +61,7 @@
61
61
  "/src/unstable-core-do-not-import.ts",
62
62
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
63
63
  ],
64
- "percent": 5.79,
64
+ "percent": 5.85,
65
65
  "reduction": 0
66
66
  },
67
67
  {
@@ -79,7 +79,7 @@
79
79
  "/src/unstable-core-do-not-import.ts",
80
80
  "/src/unstable-core-do-not-import/initTRPC.ts"
81
81
  ],
82
- "percent": 4.87,
82
+ "percent": 4.86,
83
83
  "reduction": 39.77
84
84
  },
85
85
  {
@@ -94,7 +94,7 @@
94
94
  "/src/unstable-core-do-not-import.ts",
95
95
  "/src/unstable-core-do-not-import/initTRPC.ts"
96
96
  ],
97
- "percent": 4.83,
97
+ "percent": 4.82,
98
98
  "reduction": 60.06
99
99
  },
100
100
  {
@@ -113,7 +113,7 @@
113
113
  "/src/unstable-core-do-not-import.ts",
114
114
  "/src/unstable-core-do-not-import/http/resolveResponse.ts"
115
115
  ],
116
- "percent": 4.3,
116
+ "percent": 4.29,
117
117
  "reduction": 24.48
118
118
  },
119
119
  {
@@ -147,7 +147,7 @@
147
147
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
148
148
  "/src/observable/operators.ts"
149
149
  ],
150
- "percent": 3.14,
150
+ "percent": 3.13,
151
151
  "reduction": 0
152
152
  },
153
153
  {
@@ -201,32 +201,32 @@
201
201
  "reduction": 45.94
202
202
  },
203
203
  {
204
- "id": "/src/unstable-core-do-not-import/initTRPC.ts",
205
- "size": 2704,
206
- "origSize": 4576,
204
+ "id": "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
205
+ "size": 2732,
206
+ "origSize": 2931,
207
207
  "renderedExports": [
208
- "initTRPC"
208
+ "nodeHTTPRequestHandler"
209
209
  ],
210
210
  "removedExports": [],
211
211
  "dependents": [
212
- "/src/unstable-core-do-not-import.ts"
212
+ "/src/adapters/node-http/index.ts"
213
213
  ],
214
- "percent": 2.06,
215
- "reduction": 40.91
214
+ "percent": 2.08,
215
+ "reduction": 6.79
216
216
  },
217
217
  {
218
- "id": "/src/adapters/node-http/nodeHTTPRequestHandler.ts",
219
- "size": 2688,
220
- "origSize": 2900,
218
+ "id": "/src/unstable-core-do-not-import/initTRPC.ts",
219
+ "size": 2704,
220
+ "origSize": 4576,
221
221
  "renderedExports": [
222
- "nodeHTTPRequestHandler"
222
+ "initTRPC"
223
223
  ],
224
224
  "removedExports": [],
225
225
  "dependents": [
226
- "/src/adapters/node-http/index.ts"
226
+ "/src/unstable-core-do-not-import.ts"
227
227
  ],
228
- "percent": 2.05,
229
- "reduction": 7.31
228
+ "percent": 2.06,
229
+ "reduction": 40.91
230
230
  },
231
231
  {
232
232
  "id": "/src/unstable-core-do-not-import/middleware.ts",
@@ -261,7 +261,7 @@
261
261
  "/src/unstable-core-do-not-import.ts",
262
262
  "/src/unstable-core-do-not-import/router.ts"
263
263
  ],
264
- "percent": 1.78,
264
+ "percent": 1.77,
265
265
  "reduction": 0
266
266
  },
267
267
  {
@@ -340,7 +340,7 @@
340
340
  ],
341
341
  "removedExports": [],
342
342
  "dependents": [],
343
- "percent": 1.21,
343
+ "percent": 1.2,
344
344
  "reduction": 21.04
345
345
  },
346
346
  {
@@ -352,7 +352,7 @@
352
352
  ],
353
353
  "removedExports": [],
354
354
  "dependents": [],
355
- "percent": 1.18,
355
+ "percent": 1.17,
356
356
  "reduction": 26.94
357
357
  },
358
358
  {
@@ -418,12 +418,12 @@
418
418
  "/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts",
419
419
  "/src/unstable-core-do-not-import/http/parseConnectionParams.ts",
420
420
  "/src/unstable-core-do-not-import/http/resolveResponse.ts",
421
- "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
422
421
  "/src/unstable-core-do-not-import/error/TRPCError.ts",
423
422
  "/src/unstable-core-do-not-import/stream/sse.ts",
424
423
  "/src/unstable-core-do-not-import/transformer.ts",
425
424
  "/src/unstable-core-do-not-import/middleware.ts",
426
425
  "/src/unstable-core-do-not-import/router.ts",
426
+ "/src/unstable-core-do-not-import/rpc/parseTRPCMessage.ts",
427
427
  "/src/unstable-core-do-not-import/http/contentType.ts",
428
428
  "/src/unstable-core-do-not-import/procedureBuilder.ts",
429
429
  "/src/unstable-core-do-not-import/stream/jsonl.ts"
@@ -722,9 +722,9 @@
722
722
  "reduction": 100
723
723
  },
724
724
  {
725
- "id": "/src/rpc.ts",
725
+ "id": "/src/index.ts",
726
726
  "size": 0,
727
- "origSize": 36,
727
+ "origSize": 32,
728
728
  "renderedExports": [],
729
729
  "removedExports": [],
730
730
  "dependents": [],
@@ -732,9 +732,9 @@
732
732
  "reduction": 100
733
733
  },
734
734
  {
735
- "id": "/src/index.ts",
735
+ "id": "/src/shared.ts",
736
736
  "size": 0,
737
- "origSize": 32,
737
+ "origSize": 653,
738
738
  "renderedExports": [],
739
739
  "removedExports": [],
740
740
  "dependents": [],
@@ -742,9 +742,9 @@
742
742
  "reduction": 100
743
743
  },
744
744
  {
745
- "id": "/src/shared.ts",
745
+ "id": "/src/rpc.ts",
746
746
  "size": 0,
747
- "origSize": 653,
747
+ "origSize": 36,
748
748
  "renderedExports": [],
749
749
  "removedExports": [],
750
750
  "dependents": [],
@@ -1 +1 @@
1
- {"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAqQF,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,eAAe,CAG3E"}
1
+ {"version":3,"file":"contentType.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/contentType.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,SAAS,CAAC;AAEjE,KAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,OAAO,CAAC;IACb,YAAY,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAwQF,wBAAgB,cAAc,CAAC,IAAI,EAAE,qBAAqB,GAAG,eAAe,CAG3E"}
@@ -128,7 +128,8 @@ const jsonContentTypeHandler = {
128
128
  accept: req.headers.get('trpc-accept'),
129
129
  calls,
130
130
  type,
131
- connectionParams: connectionParamsStr === null ? null : parseConnectionParams.parseConnectionParamsFromString(connectionParamsStr)
131
+ connectionParams: connectionParamsStr === null ? null : parseConnectionParams.parseConnectionParamsFromString(connectionParamsStr),
132
+ signal: req.signal
132
133
  };
133
134
  return info;
134
135
  }
@@ -161,7 +162,8 @@ const formDataContentTypeHandler = {
161
162
  ],
162
163
  isBatchCall: false,
163
164
  type: 'mutation',
164
- connectionParams: null
165
+ connectionParams: null,
166
+ signal: req.signal
165
167
  };
166
168
  }
167
169
  };
@@ -192,7 +194,8 @@ const octetStreamContentTypeHandler = {
192
194
  isBatchCall: false,
193
195
  accept: null,
194
196
  type: 'mutation',
195
- connectionParams: null
197
+ connectionParams: null,
198
+ signal: req.signal
196
199
  };
197
200
  }
198
201
  };
@@ -126,7 +126,8 @@ const jsonContentTypeHandler = {
126
126
  accept: req.headers.get('trpc-accept'),
127
127
  calls,
128
128
  type,
129
- connectionParams: connectionParamsStr === null ? null : parseConnectionParamsFromString(connectionParamsStr)
129
+ connectionParams: connectionParamsStr === null ? null : parseConnectionParamsFromString(connectionParamsStr),
130
+ signal: req.signal
130
131
  };
131
132
  return info;
132
133
  }
@@ -159,7 +160,8 @@ const formDataContentTypeHandler = {
159
160
  ],
160
161
  isBatchCall: false,
161
162
  type: 'mutation',
162
- connectionParams: null
163
+ connectionParams: null,
164
+ signal: req.signal
163
165
  };
164
166
  }
165
167
  };
@@ -190,7 +192,8 @@ const octetStreamContentTypeHandler = {
190
192
  isBatchCall: false,
191
193
  accept: null,
192
194
  type: 'mutation',
193
- connectionParams: null
195
+ connectionParams: null,
196
+ signal: req.signal
194
197
  };
195
198
  }
196
199
  };
@@ -83,6 +83,11 @@ export interface TRPCRequestInfo {
83
83
  * Connection params when using `httpSubscriptionLink` or `createWSClient`
84
84
  */
85
85
  connectionParams: Dict<string> | null;
86
+ /**
87
+ * Signal when the request is aborted
88
+ * Can be used to abort async operations during the request, e.g. `fetch()`-requests
89
+ */
90
+ signal: AbortSignal;
86
91
  }
87
92
  /**
88
93
  * Inner createContext function for `resolveResponse` used to forward `TRPCRequestInfo` to `createContext`
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,KAAK,WAAW,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,SAAS,IAAI,CAAC,IAAI,EAAE;IAC7D,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;IACzD,GAAG,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAClC;;;QAGI;IACJ,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACrC,IAAI,EAAE,eAAe,GAAG,SAAS,CAAC;IAClC,IAAI,EAAE,aAAa,GAAG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M,EAAE,WAAW,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,kCAAkC,CAAC,OAAO,SAAS,SAAS,IACtE,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,KAAK,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAE5E,UAAU,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ,CACnE,SAAQ,mBAAmB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxD,GAAG,EAAE,QAAQ,CAAC;CACf;AACD;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ,IAAI,CAClE,IAAI,EAAE,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,KAC7C,IAAI,CAAC;AAEV;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,SAAS,EAAE,QAAQ;IACrE,OAAO,CAAC,EAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC9C;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/server",
3
- "version": "11.0.0-alpha-tmp-issues-5851-take-two.488+33ec2950b",
3
+ "version": "11.0.0-alpha-tmp-issues-5851-take-two.490+8c0dddb9c",
4
4
  "description": "The tRPC server library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -149,5 +149,5 @@
149
149
  "funding": [
150
150
  "https://trpc.io/sponsor"
151
151
  ],
152
- "gitHead": "33ec2950bd3d9da1f49796cbe512c6e27fc3b1fb"
152
+ "gitHead": "8c0dddb9c79ebbd92493838a5c447d093105a335"
153
153
  }
@@ -71,7 +71,9 @@ export async function nodeHTTPRequestHandler<
71
71
  // console.error('reader.cancel() error', err);
72
72
  });
73
73
  };
74
- req.signal.addEventListener('abort', onAbort);
74
+ req.signal.addEventListener('abort', onAbort, {
75
+ once: true,
76
+ });
75
77
 
76
78
  while (true) {
77
79
  const { done, value } = await reader.read();
@@ -97,6 +97,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
97
97
 
98
98
  return async (client: ws.WebSocket, req: IncomingMessage) => {
99
99
  const clientSubscriptions = new Map<number | string, AbortController>();
100
+ const abortController = new AbortController();
100
101
 
101
102
  function respond(untransformedJSON: TRPCResponseMessage) {
102
103
  client.send(
@@ -106,11 +107,11 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
106
107
  );
107
108
  }
108
109
 
109
- function createCtxPromise(
110
+ async function createCtxPromise(
110
111
  getConnectionParams: () => TRPCRequestInfo['connectionParams'],
111
112
  ): Promise<inferRouterContext<TRouter>> {
112
- return run(async () => {
113
- ctx = await createContext?.({
113
+ try {
114
+ return await createContext?.({
114
115
  req,
115
116
  res: client,
116
117
  info: {
@@ -119,11 +120,10 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
119
120
  isBatchCall: false,
120
121
  accept: null,
121
122
  type: 'unknown',
123
+ signal: abortController.signal,
122
124
  },
123
125
  });
124
-
125
- return ctx;
126
- }).catch((cause) => {
126
+ } catch (cause) {
127
127
  const error = getTRPCErrorFromUnknown(cause);
128
128
  opts.onError?.({
129
129
  error,
@@ -151,7 +151,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
151
151
  });
152
152
 
153
153
  throw error;
154
- });
154
+ }
155
155
  }
156
156
 
157
157
  /**
@@ -165,7 +165,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
165
165
  ? unsetContextSymbol
166
166
  : createCtxPromise(() => null);
167
167
 
168
- let ctx: inferRouterContext<TRouter> | undefined = undefined;
168
+ const ctx: inferRouterContext<TRouter> | undefined = undefined;
169
169
 
170
170
  async function handleRequest(msg: TRPCClientOutgoingMessage) {
171
171
  const { id, jsonrpc } = msg;
@@ -410,6 +410,7 @@ export function getWSConnectionHandler<TRouter extends AnyRouter>(
410
410
  sub.abort();
411
411
  }
412
412
  clientSubscriptions.clear();
413
+ abortController.abort();
413
414
  });
414
415
 
415
416
  if (ctxPromise !== unsetContextSymbol) {
@@ -173,6 +173,7 @@ const jsonContentTypeHandler: ContentTypeHandler = {
173
173
  connectionParamsStr === null
174
174
  ? null
175
175
  : parseConnectionParamsFromString(connectionParamsStr),
176
+ signal: req.signal,
176
177
  };
177
178
  return info;
178
179
  },
@@ -208,6 +209,7 @@ const formDataContentTypeHandler: ContentTypeHandler = {
208
209
  isBatchCall: false,
209
210
  type: 'mutation',
210
211
  connectionParams: null,
212
+ signal: req.signal,
211
213
  };
212
214
  },
213
215
  };
@@ -243,6 +245,7 @@ const octetStreamContentTypeHandler: ContentTypeHandler = {
243
245
  accept: null,
244
246
  type: 'mutation',
245
247
  connectionParams: null,
248
+ signal: req.signal,
246
249
  };
247
250
  },
248
251
  };
@@ -99,6 +99,11 @@ export interface TRPCRequestInfo {
99
99
  * Connection params when using `httpSubscriptionLink` or `createWSClient`
100
100
  */
101
101
  connectionParams: Dict<string> | null;
102
+ /**
103
+ * Signal when the request is aborted
104
+ * Can be used to abort async operations during the request, e.g. `fetch()`-requests
105
+ */
106
+ signal: AbortSignal;
102
107
  }
103
108
 
104
109
  /**