@trpc/client 11.0.0-alpha-tmp-subscription-connection-state.489 → 11.0.0-alpha-tmp-12-06-react.667

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 (97) hide show
  1. package/dist/TRPCClientError.d.ts +1 -1
  2. package/dist/TRPCClientError.d.ts.map +1 -1
  3. package/dist/TRPCClientError.js +19 -1
  4. package/dist/TRPCClientError.mjs +19 -1
  5. package/dist/bundle-analysis.json +118 -92
  6. package/dist/createTRPCClient.d.ts +3 -2
  7. package/dist/createTRPCClient.d.ts.map +1 -1
  8. package/dist/createTRPCClient.js +1 -1
  9. package/dist/createTRPCClient.mjs +1 -1
  10. package/dist/index.js +6 -6
  11. package/dist/index.mjs +2 -2
  12. package/dist/internals/TRPCUntypedClient.d.ts +5 -4
  13. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  14. package/dist/internals/TRPCUntypedClient.js +42 -12
  15. package/dist/internals/TRPCUntypedClient.mjs +42 -12
  16. package/dist/internals/inputWithTrackedEventId.d.ts +2 -0
  17. package/dist/internals/inputWithTrackedEventId.d.ts.map +1 -0
  18. package/dist/internals/inputWithTrackedEventId.js +16 -0
  19. package/dist/internals/inputWithTrackedEventId.mjs +14 -0
  20. package/dist/internals/signals.d.ts +15 -0
  21. package/dist/internals/signals.d.ts.map +1 -0
  22. package/dist/internals/signals.js +47 -0
  23. package/dist/internals/signals.mjs +44 -0
  24. package/dist/internals/transformer.d.ts +2 -2
  25. package/dist/internals/types.d.ts +1 -1
  26. package/dist/internals/types.d.ts.map +1 -1
  27. package/dist/links/HTTPBatchLinkOptions.d.ts +1 -1
  28. package/dist/links/httpBatchLink.d.ts.map +1 -1
  29. package/dist/links/httpBatchLink.js +4 -3
  30. package/dist/links/httpBatchLink.mjs +5 -4
  31. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  32. package/dist/links/httpBatchStreamLink.js +6 -4
  33. package/dist/links/httpBatchStreamLink.mjs +7 -5
  34. package/dist/links/httpLink.d.ts +2 -2
  35. package/dist/links/httpLink.js +3 -3
  36. package/dist/links/httpLink.mjs +3 -3
  37. package/dist/links/httpSubscriptionLink.d.ts +11 -6
  38. package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
  39. package/dist/links/httpSubscriptionLink.js +130 -98
  40. package/dist/links/httpSubscriptionLink.mjs +132 -100
  41. package/dist/links/internals/contentTypes.d.ts +2 -2
  42. package/dist/links/internals/contentTypes.d.ts.map +1 -1
  43. package/dist/links/internals/httpUtils.d.ts +1 -8
  44. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  45. package/dist/links/internals/httpUtils.js +1 -30
  46. package/dist/links/internals/httpUtils.mjs +2 -30
  47. package/dist/links/internals/subscriptions.d.ts +20 -0
  48. package/dist/links/internals/subscriptions.d.ts.map +1 -0
  49. package/dist/links/internals/urlWithConnectionParams.d.ts +2 -1
  50. package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
  51. package/dist/links/internals/urlWithConnectionParams.js +3 -2
  52. package/dist/links/internals/urlWithConnectionParams.mjs +3 -2
  53. package/dist/links/loggerLink.d.ts +5 -5
  54. package/dist/links/loggerLink.d.ts.map +1 -1
  55. package/dist/links/loggerLink.js +25 -21
  56. package/dist/links/loggerLink.mjs +25 -21
  57. package/dist/links/retryLink.d.ts +29 -0
  58. package/dist/links/retryLink.d.ts.map +1 -0
  59. package/dist/links/retryLink.js +65 -0
  60. package/dist/links/retryLink.mjs +63 -0
  61. package/dist/links/types.d.ts +4 -23
  62. package/dist/links/types.d.ts.map +1 -1
  63. package/dist/links/wsLink.d.ts +49 -5
  64. package/dist/links/wsLink.d.ts.map +1 -1
  65. package/dist/links/wsLink.js +210 -155
  66. package/dist/links/wsLink.mjs +211 -156
  67. package/dist/links.d.ts +1 -0
  68. package/dist/links.d.ts.map +1 -1
  69. package/dist/unstable-internals.d.ts +1 -0
  70. package/dist/unstable-internals.d.ts.map +1 -1
  71. package/package.json +14 -11
  72. package/src/TRPCClientError.ts +1 -1
  73. package/src/createTRPCClient.ts +28 -23
  74. package/src/internals/TRPCUntypedClient.ts +26 -15
  75. package/src/internals/inputWithTrackedEventId.ts +15 -0
  76. package/src/internals/signals.ts +54 -0
  77. package/src/internals/transformer.ts +2 -2
  78. package/src/internals/types.ts +1 -1
  79. package/src/links/HTTPBatchLinkOptions.ts +1 -1
  80. package/src/links/httpBatchLink.ts +3 -3
  81. package/src/links/httpBatchStreamLink.ts +7 -4
  82. package/src/links/httpLink.ts +2 -2
  83. package/src/links/httpSubscriptionLink.ts +172 -123
  84. package/src/links/internals/httpUtils.ts +1 -41
  85. package/src/links/internals/subscriptions.ts +26 -0
  86. package/src/links/internals/urlWithConnectionParams.ts +8 -2
  87. package/src/links/loggerLink.ts +21 -9
  88. package/src/links/retryLink.ts +101 -0
  89. package/src/links/types.ts +8 -46
  90. package/src/links/wsLink.ts +276 -173
  91. package/src/links.ts +1 -1
  92. package/src/unstable-internals.ts +1 -0
  93. package/dist/links/internals/retryLink.d.ts +0 -9
  94. package/dist/links/internals/retryLink.d.ts.map +0 -1
  95. package/dist/links/types.js +0 -7
  96. package/dist/links/types.mjs +0 -5
  97. package/src/links/internals/retryLink.ts +0 -53
@@ -1,7 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var observable = require('@trpc/server/observable');
4
+ var rpc = require('@trpc/server/rpc');
4
5
  var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
6
+ var inputWithTrackedEventId = require('../internals/inputWithTrackedEventId.js');
7
+ var signals = require('../internals/signals.js');
5
8
  var TRPCClientError = require('../TRPCClientError.js');
6
9
  var transformer = require('../internals/transformer.js');
7
10
  var httpUtils = require('./internals/httpUtils.js');
@@ -16,93 +19,142 @@ async function urlWithConnectionParams(opts) {
16
19
  }
17
20
  return url;
18
21
  }
22
+ /**
23
+ * tRPC error codes that are considered retryable
24
+ * With out of the box SSE, the client will reconnect when these errors are encountered
25
+ */ const codes5xx = [
26
+ rpc.TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
27
+ rpc.TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
28
+ rpc.TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
29
+ rpc.TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
30
+ ];
19
31
  /**
20
32
  * @see https://trpc.io/docs/client/links/httpSubscriptionLink
21
33
  */ function unstable_httpSubscriptionLink(opts) {
22
34
  const transformer$1 = transformer.getTransformer(opts.transformer);
23
35
  return ()=>{
24
- return ({ op })=>{
36
+ return ({ op })=>{
25
37
  return observable.observable((observer)=>{
26
- const { type , path , input } = op;
38
+ const { type, path, input } = op;
27
39
  /* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
28
40
  throw new Error('httpSubscriptionLink only supports subscriptions');
29
41
  }
30
- let eventSource = null;
31
- let unsubscribed = false;
32
- unstableCoreDoNotImport.run(async ()=>{
33
- const url = httpUtils.getUrl({
34
- transformer: transformer$1,
35
- url: await urlWithConnectionParams(opts),
36
- input,
37
- path,
38
- type,
39
- signal: null
40
- });
41
- const eventSourceOptions = await urlWithConnectionParams$1.resultOf(opts.eventSourceOptions);
42
- /* istanbul ignore if -- @preserve */ if (unsubscribed) {
43
- // already unsubscribed - rare race condition
44
- return;
45
- }
46
- eventSource = new EventSource(url, eventSourceOptions);
47
- observer.next({
48
- result: {
49
- type: 'state',
50
- state: 'connecting',
51
- data: null
52
- }
53
- });
54
- const onStarted = ()=>{
55
- observer.next({
56
- result: {
57
- type: 'started'
58
- },
59
- context: {
60
- eventSource
61
- }
62
- });
63
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
64
- eventSource.removeEventListener('open', onStarted);
65
- };
66
- // console.log('starting', new Date());
67
- eventSource.addEventListener('open', onStarted);
68
- eventSource.addEventListener('open', ()=>{
69
- observer.next({
70
- result: {
71
- type: 'state',
72
- state: 'pending'
73
- }
74
- });
75
- });
76
- eventSource.addEventListener('error', (event)=>{
77
- // sseStreamConsumer handles this already
78
- if (eventSource?.readyState === EventSource.CLOSED) {
79
- return;
80
- }
81
- const error = globalThis.ErrorEvent && event instanceof ErrorEvent ? TRPCClientError.TRPCClientError.from(event.error) : TRPCClientError.TRPCClientError.from(new Error(`Unknown EventSource error`));
42
+ let lastEventId = undefined;
43
+ const ac = new AbortController();
44
+ const signal = signals.raceAbortSignals(op.signal, ac.signal);
45
+ const eventSourceStream = unstableCoreDoNotImport.sseStreamConsumer({
46
+ url: async ()=>httpUtils.getUrl({
47
+ transformer: transformer$1,
48
+ url: await urlWithConnectionParams(opts),
49
+ input: inputWithTrackedEventId.inputWithTrackedEventId(input, lastEventId),
50
+ path,
51
+ type,
52
+ signal: null
53
+ }),
54
+ init: ()=>urlWithConnectionParams$1.resultOf(opts.eventSourceOptions, {
55
+ op
56
+ }),
57
+ signal,
58
+ deserialize: transformer$1.output.deserialize,
59
+ EventSource: opts.EventSource ?? globalThis.EventSource
60
+ });
61
+ const connectionState = observable.behaviorSubject({
62
+ type: 'state',
63
+ state: 'connecting',
64
+ error: null
65
+ });
66
+ const connectionSub = connectionState.subscribe({
67
+ next (state) {
82
68
  observer.next({
83
- result: {
84
- type: 'state',
85
- state: 'connecting',
86
- data: error
87
- }
69
+ result: state
88
70
  });
89
- });
90
- const iterable = unstableCoreDoNotImport.sseStreamConsumer({
91
- from: eventSource,
92
- deserialize: transformer$1.output.deserialize
93
- });
94
- for await (const chunk of iterable){
95
- if (!chunk.ok) {
96
- continue;
71
+ }
72
+ });
73
+ unstableCoreDoNotImport.run(async ()=>{
74
+ for await (const chunk of eventSourceStream){
75
+ switch(chunk.type){
76
+ case 'ping':
77
+ break;
78
+ case 'data':
79
+ const chunkData = chunk.data;
80
+ let result;
81
+ if (chunkData.id) {
82
+ // if the `tracked()`-helper is used, we always have an `id` field
83
+ lastEventId = chunkData.id;
84
+ result = {
85
+ id: chunkData.id,
86
+ data: chunkData
87
+ };
88
+ } else {
89
+ result = {
90
+ data: chunkData.data
91
+ };
92
+ }
93
+ observer.next({
94
+ result,
95
+ context: {
96
+ eventSource: chunk.eventSource
97
+ }
98
+ });
99
+ break;
100
+ case 'connected':
101
+ {
102
+ observer.next({
103
+ result: {
104
+ type: 'started'
105
+ },
106
+ context: {
107
+ eventSource: chunk.eventSource
108
+ }
109
+ });
110
+ connectionState.next({
111
+ type: 'state',
112
+ state: 'pending',
113
+ error: null
114
+ });
115
+ break;
116
+ }
117
+ case 'serialized-error':
118
+ {
119
+ const error = TRPCClientError.TRPCClientError.from({
120
+ error: chunk.error
121
+ });
122
+ if (codes5xx.includes(chunk.error.code)) {
123
+ //
124
+ connectionState.next({
125
+ type: 'state',
126
+ state: 'connecting',
127
+ error
128
+ });
129
+ break;
130
+ }
131
+ //
132
+ // non-retryable error, cancel the subscription
133
+ throw error;
134
+ }
135
+ case 'connecting':
136
+ {
137
+ const lastState = connectionState.get();
138
+ const error = chunk.event && TRPCClientError.TRPCClientError.from(chunk.event);
139
+ if (!error && lastState.state === 'connecting') {
140
+ break;
141
+ }
142
+ connectionState.next({
143
+ type: 'state',
144
+ state: 'connecting',
145
+ error
146
+ });
147
+ break;
148
+ }
149
+ case 'timeout':
150
+ {
151
+ connectionState.next({
152
+ type: 'state',
153
+ state: 'connecting',
154
+ error: new TRPCClientError.TRPCClientError(`Timeout of ${chunk.ms}ms reached while waiting for a response`)
155
+ });
156
+ }
97
157
  }
98
- const chunkData = chunk.data;
99
- // if the `tracked()`-helper is used, we always have an `id` field
100
- const data = 'id' in chunkData ? chunkData : chunkData.data;
101
- observer.next({
102
- result: {
103
- data
104
- }
105
- });
106
158
  }
107
159
  observer.next({
108
160
  result: {
@@ -110,33 +162,13 @@ async function urlWithConnectionParams(opts) {
110
162
  }
111
163
  });
112
164
  observer.complete();
113
- observer.next({
114
- result: {
115
- type: 'state',
116
- state: 'idle'
117
- }
118
- });
119
165
  }).catch((error)=>{
120
- const trpcError = TRPCClientError.TRPCClientError.from(error);
121
- observer.next({
122
- result: {
123
- type: 'state',
124
- state: 'error',
125
- data: TRPCClientError.TRPCClientError.from(trpcError)
126
- }
127
- });
128
- observer.error(trpcError);
166
+ observer.error(TRPCClientError.TRPCClientError.from(error));
129
167
  });
130
168
  return ()=>{
131
169
  observer.complete();
132
- observer.next({
133
- result: {
134
- type: 'state',
135
- state: 'idle'
136
- }
137
- });
138
- eventSource?.close();
139
- unsubscribed = true;
170
+ ac.abort();
171
+ connectionSub.unsubscribe();
140
172
  };
141
173
  });
142
174
  };
@@ -1,5 +1,8 @@
1
- import { observable } from '@trpc/server/observable';
2
- import { run, sseStreamConsumer } from '@trpc/server/unstable-core-do-not-import';
1
+ import { observable, behaviorSubject } from '@trpc/server/observable';
2
+ import { TRPC_ERROR_CODES_BY_KEY } from '@trpc/server/rpc';
3
+ import { sseStreamConsumer, run } from '@trpc/server/unstable-core-do-not-import';
4
+ import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId.mjs';
5
+ import { raceAbortSignals } from '../internals/signals.mjs';
3
6
  import { TRPCClientError } from '../TRPCClientError.mjs';
4
7
  import { getTransformer } from '../internals/transformer.mjs';
5
8
  import { getUrl } from './internals/httpUtils.mjs';
@@ -14,93 +17,142 @@ async function urlWithConnectionParams(opts) {
14
17
  }
15
18
  return url;
16
19
  }
20
+ /**
21
+ * tRPC error codes that are considered retryable
22
+ * With out of the box SSE, the client will reconnect when these errors are encountered
23
+ */ const codes5xx = [
24
+ TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
25
+ TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
26
+ TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
27
+ TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
28
+ ];
17
29
  /**
18
30
  * @see https://trpc.io/docs/client/links/httpSubscriptionLink
19
31
  */ function unstable_httpSubscriptionLink(opts) {
20
32
  const transformer = getTransformer(opts.transformer);
21
33
  return ()=>{
22
- return ({ op })=>{
34
+ return ({ op })=>{
23
35
  return observable((observer)=>{
24
- const { type , path , input } = op;
36
+ const { type, path, input } = op;
25
37
  /* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
26
38
  throw new Error('httpSubscriptionLink only supports subscriptions');
27
39
  }
28
- let eventSource = null;
29
- let unsubscribed = false;
30
- run(async ()=>{
31
- const url = getUrl({
32
- transformer,
33
- url: await urlWithConnectionParams(opts),
34
- input,
35
- path,
36
- type,
37
- signal: null
38
- });
39
- const eventSourceOptions = await resultOf(opts.eventSourceOptions);
40
- /* istanbul ignore if -- @preserve */ if (unsubscribed) {
41
- // already unsubscribed - rare race condition
42
- return;
43
- }
44
- eventSource = new EventSource(url, eventSourceOptions);
45
- observer.next({
46
- result: {
47
- type: 'state',
48
- state: 'connecting',
49
- data: null
50
- }
51
- });
52
- const onStarted = ()=>{
53
- observer.next({
54
- result: {
55
- type: 'started'
56
- },
57
- context: {
58
- eventSource
59
- }
60
- });
61
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
- eventSource.removeEventListener('open', onStarted);
63
- };
64
- // console.log('starting', new Date());
65
- eventSource.addEventListener('open', onStarted);
66
- eventSource.addEventListener('open', ()=>{
67
- observer.next({
68
- result: {
69
- type: 'state',
70
- state: 'pending'
71
- }
72
- });
73
- });
74
- eventSource.addEventListener('error', (event)=>{
75
- // sseStreamConsumer handles this already
76
- if (eventSource?.readyState === EventSource.CLOSED) {
77
- return;
78
- }
79
- const error = globalThis.ErrorEvent && event instanceof ErrorEvent ? TRPCClientError.from(event.error) : TRPCClientError.from(new Error(`Unknown EventSource error`));
40
+ let lastEventId = undefined;
41
+ const ac = new AbortController();
42
+ const signal = raceAbortSignals(op.signal, ac.signal);
43
+ const eventSourceStream = sseStreamConsumer({
44
+ url: async ()=>getUrl({
45
+ transformer,
46
+ url: await urlWithConnectionParams(opts),
47
+ input: inputWithTrackedEventId(input, lastEventId),
48
+ path,
49
+ type,
50
+ signal: null
51
+ }),
52
+ init: ()=>resultOf(opts.eventSourceOptions, {
53
+ op
54
+ }),
55
+ signal,
56
+ deserialize: transformer.output.deserialize,
57
+ EventSource: opts.EventSource ?? globalThis.EventSource
58
+ });
59
+ const connectionState = behaviorSubject({
60
+ type: 'state',
61
+ state: 'connecting',
62
+ error: null
63
+ });
64
+ const connectionSub = connectionState.subscribe({
65
+ next (state) {
80
66
  observer.next({
81
- result: {
82
- type: 'state',
83
- state: 'connecting',
84
- data: error
85
- }
67
+ result: state
86
68
  });
87
- });
88
- const iterable = sseStreamConsumer({
89
- from: eventSource,
90
- deserialize: transformer.output.deserialize
91
- });
92
- for await (const chunk of iterable){
93
- if (!chunk.ok) {
94
- continue;
69
+ }
70
+ });
71
+ run(async ()=>{
72
+ for await (const chunk of eventSourceStream){
73
+ switch(chunk.type){
74
+ case 'ping':
75
+ break;
76
+ case 'data':
77
+ const chunkData = chunk.data;
78
+ let result;
79
+ if (chunkData.id) {
80
+ // if the `tracked()`-helper is used, we always have an `id` field
81
+ lastEventId = chunkData.id;
82
+ result = {
83
+ id: chunkData.id,
84
+ data: chunkData
85
+ };
86
+ } else {
87
+ result = {
88
+ data: chunkData.data
89
+ };
90
+ }
91
+ observer.next({
92
+ result,
93
+ context: {
94
+ eventSource: chunk.eventSource
95
+ }
96
+ });
97
+ break;
98
+ case 'connected':
99
+ {
100
+ observer.next({
101
+ result: {
102
+ type: 'started'
103
+ },
104
+ context: {
105
+ eventSource: chunk.eventSource
106
+ }
107
+ });
108
+ connectionState.next({
109
+ type: 'state',
110
+ state: 'pending',
111
+ error: null
112
+ });
113
+ break;
114
+ }
115
+ case 'serialized-error':
116
+ {
117
+ const error = TRPCClientError.from({
118
+ error: chunk.error
119
+ });
120
+ if (codes5xx.includes(chunk.error.code)) {
121
+ //
122
+ connectionState.next({
123
+ type: 'state',
124
+ state: 'connecting',
125
+ error
126
+ });
127
+ break;
128
+ }
129
+ //
130
+ // non-retryable error, cancel the subscription
131
+ throw error;
132
+ }
133
+ case 'connecting':
134
+ {
135
+ const lastState = connectionState.get();
136
+ const error = chunk.event && TRPCClientError.from(chunk.event);
137
+ if (!error && lastState.state === 'connecting') {
138
+ break;
139
+ }
140
+ connectionState.next({
141
+ type: 'state',
142
+ state: 'connecting',
143
+ error
144
+ });
145
+ break;
146
+ }
147
+ case 'timeout':
148
+ {
149
+ connectionState.next({
150
+ type: 'state',
151
+ state: 'connecting',
152
+ error: new TRPCClientError(`Timeout of ${chunk.ms}ms reached while waiting for a response`)
153
+ });
154
+ }
95
155
  }
96
- const chunkData = chunk.data;
97
- // if the `tracked()`-helper is used, we always have an `id` field
98
- const data = 'id' in chunkData ? chunkData : chunkData.data;
99
- observer.next({
100
- result: {
101
- data
102
- }
103
- });
104
156
  }
105
157
  observer.next({
106
158
  result: {
@@ -108,33 +160,13 @@ async function urlWithConnectionParams(opts) {
108
160
  }
109
161
  });
110
162
  observer.complete();
111
- observer.next({
112
- result: {
113
- type: 'state',
114
- state: 'idle'
115
- }
116
- });
117
163
  }).catch((error)=>{
118
- const trpcError = TRPCClientError.from(error);
119
- observer.next({
120
- result: {
121
- type: 'state',
122
- state: 'error',
123
- data: TRPCClientError.from(trpcError)
124
- }
125
- });
126
- observer.error(trpcError);
164
+ observer.error(TRPCClientError.from(error));
127
165
  });
128
166
  return ()=>{
129
167
  observer.complete();
130
- observer.next({
131
- result: {
132
- type: 'state',
133
- state: 'idle'
134
- }
135
- });
136
- eventSource?.close();
137
- unsubscribed = true;
168
+ ac.abort();
169
+ connectionSub.unsubscribe();
138
170
  };
139
171
  });
140
172
  };
@@ -1,4 +1,4 @@
1
- export declare function isOctetType(input: unknown): input is Uint8Array | Blob;
1
+ export declare function isOctetType(input: unknown): input is Uint8Array<ArrayBufferLike> | Blob;
2
2
  export declare function isFormData(input: unknown): input is FormData;
3
- export declare function isNonJsonSerializable(input: unknown): input is Uint8Array | Blob | FormData;
3
+ export declare function isNonJsonSerializable(input: unknown): input is FormData | Uint8Array<ArrayBufferLike> | Blob;
4
4
  //# sourceMappingURL=contentTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contentTypes.d.ts","sourceRoot":"","sources":["../../../src/links/internals/contentTypes.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,8BAMzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,qBAExC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,yCAEnD"}
1
+ {"version":3,"file":"contentTypes.d.ts","sourceRoot":"","sources":["../../../src/links/internals/contentTypes.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,+CAMzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,qBAExC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,0DAEnD"}
@@ -14,7 +14,7 @@ export type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'
14
14
  /**
15
15
  * Send all requests `as POST`s requests regardless of the procedure type
16
16
  * The HTTP handler must separately allow overriding the method. See:
17
- * @link https://trpc.io/docs/rpc
17
+ * @see https://trpc.io/docs/rpc
18
18
  */
19
19
  methodOverride?: 'POST';
20
20
  } & TransformerOptions<TRoot>;
@@ -64,12 +64,5 @@ export type HTTPRequestOptions = ContentOptions & HTTPBaseRequestOptions & {
64
64
  };
65
65
  export declare function fetchHTTPResponse(opts: HTTPRequestOptions): Promise<ResponseEsque>;
66
66
  export declare function httpRequest(opts: HTTPRequestOptions): Promise<HTTPResult>;
67
- /**
68
- * Merges multiple abort signals into a single one
69
- * - When all signals have been aborted, the merged signal will be aborted
70
- */
71
- export declare function mergeAbortSignals(opts: {
72
- signal: Maybe<AbortSignal>;
73
- }[]): AbortController;
74
67
  export {};
75
68
  //# sourceMappingURL=httpUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cA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96
96
  throwIfAborted(opts.signal);
97
97
  const url = opts.getUrl(opts);
98
98
  const body = opts.getBody(opts);
99
- const { type } = opts;
99
+ const { type } = opts;
100
100
  const resolvedHeaders = await (async ()=>{
101
101
  const heads = await opts.headers();
102
102
  if (Symbol.iterator in heads) {
@@ -131,34 +131,6 @@ async function httpRequest(opts) {
131
131
  meta
132
132
  };
133
133
  }
134
- /**
135
- * Merges multiple abort signals into a single one
136
- * - When all signals have been aborted, the merged signal will be aborted
137
- */ function mergeAbortSignals(opts) {
138
- const ac = new AbortController();
139
- if (opts.some((o)=>!o.signal)) {
140
- return ac;
141
- }
142
- const count = opts.length;
143
- let abortedCount = 0;
144
- const onAbort = ()=>{
145
- if (++abortedCount === count) {
146
- ac.abort();
147
- }
148
- };
149
- for (const o of opts){
150
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
151
- const signal = o.signal;
152
- if (signal.aborted) {
153
- onAbort();
154
- } else {
155
- signal.addEventListener('abort', onAbort, {
156
- once: true
157
- });
158
- }
159
- }
160
- return ac;
161
- }
162
134
 
163
135
  exports.fetchHTTPResponse = fetchHTTPResponse;
164
136
  exports.getBody = getBody;
@@ -166,5 +138,4 @@ exports.getInput = getInput;
166
138
  exports.getUrl = getUrl;
167
139
  exports.httpRequest = httpRequest;
168
140
  exports.jsonHttpRequester = jsonHttpRequester;
169
- exports.mergeAbortSignals = mergeAbortSignals;
170
141
  exports.resolveHTTPLinkOptions = resolveHTTPLinkOptions;