@trpc/client 11.0.0-rc.417 → 11.0.0-rc.419

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 (42) hide show
  1. package/dist/bundle-analysis.json +52 -37
  2. package/dist/index.js +2 -0
  3. package/dist/index.mjs +1 -0
  4. package/dist/internals/TRPCUntypedClient.d.ts +3 -1
  5. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  6. package/dist/internals/TRPCUntypedClient.js +3 -1
  7. package/dist/internals/TRPCUntypedClient.mjs +3 -1
  8. package/dist/internals/dataLoader.d.ts.map +1 -1
  9. package/dist/links/httpBatchLink.d.ts.map +1 -1
  10. package/dist/links/httpBatchLink.js +3 -2
  11. package/dist/links/httpBatchLink.mjs +3 -2
  12. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  13. package/dist/links/httpBatchStreamLink.js +5 -6
  14. package/dist/links/httpBatchStreamLink.mjs +5 -6
  15. package/dist/links/httpLink.d.ts +2 -2
  16. package/dist/links/httpLink.d.ts.map +1 -1
  17. package/dist/links/httpLink.js +3 -0
  18. package/dist/links/httpLink.mjs +3 -0
  19. package/dist/links/httpSubscriptionLink.d.ts +19 -0
  20. package/dist/links/httpSubscriptionLink.d.ts.map +1 -0
  21. package/dist/links/httpSubscriptionLink.js +87 -0
  22. package/dist/links/httpSubscriptionLink.mjs +85 -0
  23. package/dist/links/internals/contentTypes.d.ts +3 -3
  24. package/dist/links/internals/contentTypes.d.ts.map +1 -1
  25. package/dist/links/internals/httpUtils.d.ts +4 -4
  26. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  27. package/dist/links/internals/httpUtils.js +6 -7
  28. package/dist/links/internals/httpUtils.mjs +6 -7
  29. package/dist/links/loggerLink.d.ts +0 -1
  30. package/dist/links/loggerLink.d.ts.map +1 -1
  31. package/dist/links/wsLink.d.ts +4 -4
  32. package/dist/links/wsLink.d.ts.map +1 -1
  33. package/dist/links.d.ts +1 -0
  34. package/dist/links.d.ts.map +1 -1
  35. package/package.json +4 -4
  36. package/src/internals/TRPCUntypedClient.ts +4 -2
  37. package/src/links/httpBatchLink.ts +8 -5
  38. package/src/links/httpBatchStreamLink.ts +10 -7
  39. package/src/links/httpLink.ts +8 -2
  40. package/src/links/httpSubscriptionLink.ts +121 -0
  41. package/src/links/internals/httpUtils.ts +10 -11
  42. package/src/links.ts +1 -0
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 46957,
3
- "bundleOrigSize": 63578,
4
- "bundleReduction": 26.14,
2
+ "bundleSize": 50717,
3
+ "bundleOrigSize": 67665,
4
+ "bundleReduction": 25.05,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/links/wsLink.ts",
@@ -13,20 +13,20 @@
13
13
  ],
14
14
  "removedExports": [],
15
15
  "dependents": [],
16
- "percent": 25.68,
16
+ "percent": 23.78,
17
17
  "reduction": 11.68
18
18
  },
19
19
  {
20
20
  "id": "/src/links/httpBatchStreamLink.ts",
21
- "size": 6153,
22
- "origSize": 6253,
21
+ "size": 6237,
22
+ "origSize": 6400,
23
23
  "renderedExports": [
24
24
  "unstable_httpBatchStreamLink"
25
25
  ],
26
26
  "removedExports": [],
27
27
  "dependents": [],
28
- "percent": 13.1,
29
- "reduction": 1.6
28
+ "percent": 12.3,
29
+ "reduction": 2.55
30
30
  },
31
31
  {
32
32
  "id": "/src/links/loggerLink.ts",
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "removedExports": [],
39
39
  "dependents": [],
40
- "percent": 11.62,
40
+ "percent": 10.76,
41
41
  "reduction": 18.48
42
42
  },
43
43
  {
@@ -52,25 +52,25 @@
52
52
  "/src/links/httpBatchLink.ts",
53
53
  "/src/links/httpBatchStreamLink.ts"
54
54
  ],
55
- "percent": 9.59,
55
+ "percent": 8.88,
56
56
  "reduction": 6.34
57
57
  },
58
58
  {
59
59
  "id": "/src/links/httpBatchLink.ts",
60
- "size": 3906,
61
- "origSize": 4074,
60
+ "size": 4030,
61
+ "origSize": 4173,
62
62
  "renderedExports": [
63
63
  "httpBatchLink"
64
64
  ],
65
65
  "removedExports": [],
66
66
  "dependents": [],
67
- "percent": 8.32,
68
- "reduction": 4.12
67
+ "percent": 7.95,
68
+ "reduction": 3.43
69
69
  },
70
70
  {
71
71
  "id": "/src/links/internals/httpUtils.ts",
72
- "size": 3469,
73
- "origSize": 5927,
72
+ "size": 3443,
73
+ "origSize": 5895,
74
74
  "renderedExports": [
75
75
  "resolveHTTPLinkOptions",
76
76
  "getInput",
@@ -84,27 +84,40 @@
84
84
  "dependents": [
85
85
  "/src/links/httpBatchLink.ts",
86
86
  "/src/links/httpLink.ts",
87
- "/src/links/httpBatchStreamLink.ts"
87
+ "/src/links/httpBatchStreamLink.ts",
88
+ "/src/links/httpSubscriptionLink.ts"
89
+ ],
90
+ "percent": 6.79,
91
+ "reduction": 41.59
92
+ },
93
+ {
94
+ "id": "/src/links/httpSubscriptionLink.ts",
95
+ "size": 3277,
96
+ "origSize": 3535,
97
+ "renderedExports": [
98
+ "unstable_httpSubscriptionLink"
88
99
  ],
89
- "percent": 7.39,
90
- "reduction": 41.47
100
+ "removedExports": [],
101
+ "dependents": [],
102
+ "percent": 6.46,
103
+ "reduction": 7.3
91
104
  },
92
105
  {
93
106
  "id": "/src/links/httpLink.ts",
94
- "size": 2939,
95
- "origSize": 3459,
107
+ "size": 3167,
108
+ "origSize": 3698,
96
109
  "renderedExports": [
97
110
  "httpLink"
98
111
  ],
99
112
  "removedExports": [],
100
113
  "dependents": [],
101
- "percent": 6.26,
102
- "reduction": 15.03
114
+ "percent": 6.24,
115
+ "reduction": 14.36
103
116
  },
104
117
  {
105
118
  "id": "/src/internals/TRPCUntypedClient.ts",
106
- "size": 2299,
107
- "origSize": 4207,
119
+ "size": 2372,
120
+ "origSize": 4306,
108
121
  "renderedExports": [
109
122
  "TRPCUntypedClient"
110
123
  ],
@@ -113,8 +126,8 @@
113
126
  "/src/createTRPCUntypedClient.ts",
114
127
  "/src/createTRPCClient.ts"
115
128
  ],
116
- "percent": 4.9,
117
- "reduction": 45.35
129
+ "percent": 4.68,
130
+ "reduction": 44.91
118
131
  },
119
132
  {
120
133
  "id": "/src/TRPCClientError.ts",
@@ -130,10 +143,11 @@
130
143
  "/src/links/httpLink.ts",
131
144
  "/src/links/wsLink.ts",
132
145
  "/src/links/httpBatchStreamLink.ts",
146
+ "/src/links/httpSubscriptionLink.ts",
133
147
  "/src/internals/TRPCUntypedClient.ts",
134
148
  "/src/links/internals/httpUtils.ts"
135
149
  ],
136
- "percent": 3.97,
150
+ "percent": 3.68,
137
151
  "reduction": 45.71
138
152
  },
139
153
  {
@@ -150,7 +164,7 @@
150
164
  "dependents": [
151
165
  "/src/index.ts"
152
166
  ],
153
- "percent": 2.53,
167
+ "percent": 2.34,
154
168
  "reduction": 73.19
155
169
  },
156
170
  {
@@ -165,7 +179,7 @@
165
179
  "/src/links/splitLink.ts",
166
180
  "/src/internals/TRPCUntypedClient.ts"
167
181
  ],
168
- "percent": 1.47,
182
+ "percent": 1.36,
169
183
  "reduction": 32.75
170
184
  },
171
185
  {
@@ -177,7 +191,7 @@
177
191
  ],
178
192
  "removedExports": [],
179
193
  "dependents": [],
180
- "percent": 1.3,
194
+ "percent": 1.2,
181
195
  "reduction": 44.95
182
196
  },
183
197
  {
@@ -191,7 +205,7 @@
191
205
  "dependents": [
192
206
  "/src/unstable-internals.ts"
193
207
  ],
194
- "percent": 1.2,
208
+ "percent": 1.11,
195
209
  "reduction": 66.75
196
210
  },
197
211
  {
@@ -206,7 +220,7 @@
206
220
  "/src/index.ts",
207
221
  "/src/links/internals/httpUtils.ts"
208
222
  ],
209
- "percent": 0.91,
223
+ "percent": 0.84,
210
224
  "reduction": 33.54
211
225
  },
212
226
  {
@@ -220,7 +234,7 @@
220
234
  "dependents": [
221
235
  "/src/links/internals/httpUtils.ts"
222
236
  ],
223
- "percent": 0.84,
237
+ "percent": 0.78,
224
238
  "reduction": 30.4
225
239
  },
226
240
  {
@@ -234,7 +248,7 @@
234
248
  ],
235
249
  "removedExports": [],
236
250
  "dependents": [],
237
- "percent": 0.7,
251
+ "percent": 0.65,
238
252
  "reduction": 15.17
239
253
  },
240
254
  {
@@ -248,7 +262,7 @@
248
262
  "dependents": [
249
263
  "/src/index.ts"
250
264
  ],
251
- "percent": 0.21,
265
+ "percent": 0.2,
252
266
  "reduction": 82.58
253
267
  },
254
268
  {
@@ -269,11 +283,12 @@
269
283
  "removedExports": [],
270
284
  "dependents": [
271
285
  "/src/links/wsLink.ts",
286
+ "/src/links/httpSubscriptionLink.ts",
272
287
  "/src/links/internals/httpUtils.ts"
273
288
  ],
274
289
  "percent": 0,
275
290
  "reduction": 100
276
291
  }
277
292
  ],
278
- "moduleCount": 19
293
+ "moduleCount": 20
279
294
  }
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ var httpLink = require('./links/httpLink.js');
11
11
  var loggerLink = require('./links/loggerLink.js');
12
12
  var splitLink = require('./links/splitLink.js');
13
13
  var wsLink = require('./links/wsLink.js');
14
+ var httpSubscriptionLink = require('./links/httpSubscriptionLink.js');
14
15
  var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
15
16
 
16
17
 
@@ -33,4 +34,5 @@ exports.loggerLink = loggerLink.loggerLink;
33
34
  exports.splitLink = splitLink.splitLink;
34
35
  exports.createWSClient = wsLink.createWSClient;
35
36
  exports.wsLink = wsLink.wsLink;
37
+ exports.unstable_httpSubscriptionLink = httpSubscriptionLink.unstable_httpSubscriptionLink;
36
38
  exports.TRPCUntypedClient = TRPCUntypedClient.TRPCUntypedClient;
package/dist/index.mjs CHANGED
@@ -9,4 +9,5 @@ export { httpLink } from './links/httpLink.mjs';
9
9
  export { loggerLink } from './links/loggerLink.mjs';
10
10
  export { splitLink } from './links/splitLink.mjs';
11
11
  export { createWSClient, wsLink } from './links/wsLink.mjs';
12
+ export { unstable_httpSubscriptionLink } from './links/httpSubscriptionLink.mjs';
12
13
  export { TRPCUntypedClient } from './internals/TRPCUntypedClient.mjs';
@@ -10,7 +10,9 @@ export interface TRPCRequestOptions {
10
10
  signal?: AbortSignal;
11
11
  }
12
12
  export interface TRPCSubscriptionObserver<TValue, TError> {
13
- onStarted: () => void;
13
+ onStarted: (opts: {
14
+ context: OperationContext | undefined;
15
+ }) => void;
14
16
  onData: (value: TValue) => void;
15
17
  onError: (err: TError) => void;
16
18
  onStopped: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"TRPCUntypedClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EACV,SAAS,EACT,qBAAqB,EACrB,SAAS,EACV,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACV,gBAAgB,EAEhB,iBAAiB,EACjB,QAAQ,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB,CAAC,MAAM,EAAE,MAAM;IACtD,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,gBAAgB;AAChB,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,qBAAqB,IAAI;IAC3E,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,SAAS,CAAC,qEAAqE,CAAC,CAAC;CAChG,CAAC;AAEF,gBAAgB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AK,EAAE,OAAO,EACd,IAAI,EAAE,OAAO,CACX,wBAAwB,CAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC,CAC9D,GACC,kBAAkB,GACnB,cAAc;CA2BlB"}
@@ -59,7 +59,9 @@ class TRPCUntypedClient {
59
59
  return observable$.subscribe({
60
60
  next (envelope) {
61
61
  if (envelope.result.type === 'started') {
62
- opts.onStarted?.();
62
+ opts.onStarted?.({
63
+ context: envelope.context
64
+ });
63
65
  } else if (envelope.result.type === 'stopped') {
64
66
  opts.onStopped?.();
65
67
  } else {
@@ -57,7 +57,9 @@ class TRPCUntypedClient {
57
57
  return observable$.subscribe({
58
58
  next (envelope) {
59
59
  if (envelope.result.type === 'started') {
60
- opts.onStarted?.();
60
+ opts.onStarted?.({
61
+ context: envelope.context
62
+ });
61
63
  } else if (envelope.result.type === 'stopped') {
62
64
  opts.onStopped?.();
63
65
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAajE,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC;IACpC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK;QACvB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,QAAQ,CAAC;KAClB,CAAC;CACH,CAAC;AAWF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC;gBA0GnB,IAAI,KAAG,iBAAiB,MAAM,CAAC;EAsCnD"}
1
+ {"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAajE,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC;IACpC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK;QACvB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,QAAQ,CAAC;KAClB,CAAC;CACH,CAAC;AAWF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC;gBA0GnB,IAAI,KAAG,gBAAgB,CAAC,MAAM,CAAC;EAsCnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAO7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAOnE,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC/D,QAAQ,CAAC,OAAO,CAAC,CAmHnB"}
1
+ {"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAO7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAOnE,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC/D,QAAQ,CAAC,OAAO,CAAC,CAsHnB"}
@@ -65,14 +65,15 @@ var httpUtils = require('./internals/httpUtils.js');
65
65
  };
66
66
  const query = dataLoader.dataLoader(batchLoader('query'));
67
67
  const mutation = dataLoader.dataLoader(batchLoader('mutation'));
68
- const subscription = dataLoader.dataLoader(batchLoader('subscription'));
69
68
  const loaders = {
70
69
  query,
71
- subscription,
72
70
  mutation
73
71
  };
74
72
  return ({ op })=>{
75
73
  return observable.observable((observer)=>{
74
+ /* istanbul ignore if -- @preserve */ if (op.type === 'subscription') {
75
+ throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
76
+ }
76
77
  const loader = loaders[op.type];
77
78
  const { promise , cancel } = loader.load(op);
78
79
  let _res = undefined;
@@ -63,14 +63,15 @@ import { resolveHTTPLinkOptions, getUrl, jsonHttpRequester } from './internals/h
63
63
  };
64
64
  const query = dataLoader(batchLoader('query'));
65
65
  const mutation = dataLoader(batchLoader('mutation'));
66
- const subscription = dataLoader(batchLoader('subscription'));
67
66
  const loaders = {
68
67
  query,
69
- subscription,
70
68
  mutation
71
69
  };
72
70
  return ({ op })=>{
73
71
  return observable((observer)=>{
72
+ /* istanbul ignore if -- @preserve */ if (op.type === 'subscription') {
73
+ throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
74
+ }
74
75
  const loader = loaders[op.type];
75
76
  const { promise , cancel } = loader.load(op);
76
77
  let _res = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchStreamLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchStreamLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAG7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAQnE,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,YAAY,IAC/D,oBAAoB,CAAC,KAAK,CAAC,GAAG;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEJ;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,SAAS,SAAS,EACpE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GACrE,QAAQ,CAAC,OAAO,CAAC,CAkKnB"}
1
+ {"version":3,"file":"httpBatchStreamLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchStreamLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAG7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAM7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAQnE,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD,MAAM,MAAM,0BAA0B,CAAC,KAAK,SAAS,YAAY,IAC/D,oBAAoB,CAAC,KAAK,CAAC,GAAG;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEJ;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,SAAS,SAAS,EACpE,IAAI,EAAE,0BAA0B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GACrE,QAAQ,CAAC,OAAO,CAAC,CAqKnB"}
@@ -60,10 +60,8 @@ var httpUtils = require('./internals/httpUtils.js');
60
60
  }, ac);
61
61
  return {
62
62
  promise: responsePromise.then(async (res)=>{
63
- if (!res.body) {
64
- throw new Error('Received response without body');
65
- }
66
63
  const [head] = await unstableCoreDoNotImport.jsonlStreamConsumer({
64
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67
65
  from: res.body,
68
66
  deserialize: resolvedOpts.transformer.output.deserialize,
69
67
  // onError: console.error,
@@ -75,7 +73,7 @@ var httpUtils = require('./internals/httpUtils.js');
75
73
  }
76
74
  });
77
75
  const promises = Object.keys(batchOps).map(async (key)=>{
78
- let json = await head[key];
76
+ let json = await Promise.resolve(head[key]);
79
77
  if ('result' in json) {
80
78
  /**
81
79
  * Not very pretty, but we need to unwrap nested data as promises
@@ -105,14 +103,15 @@ var httpUtils = require('./internals/httpUtils.js');
105
103
  };
106
104
  const query = dataLoader.dataLoader(batchLoader('query'));
107
105
  const mutation = dataLoader.dataLoader(batchLoader('mutation'));
108
- const subscription = dataLoader.dataLoader(batchLoader('subscription'));
109
106
  const loaders = {
110
107
  query,
111
- subscription,
112
108
  mutation
113
109
  };
114
110
  return ({ op })=>{
115
111
  return observable.observable((observer)=>{
112
+ /* istanbul ignore if -- @preserve */ if (op.type === 'subscription') {
113
+ throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
114
+ }
116
115
  const loader = loaders[op.type];
117
116
  const { promise , cancel } = loader.load(op);
118
117
  let _res = undefined;
@@ -58,10 +58,8 @@ import { resolveHTTPLinkOptions, getUrl, fetchHTTPResponse, getBody } from './in
58
58
  }, ac);
59
59
  return {
60
60
  promise: responsePromise.then(async (res)=>{
61
- if (!res.body) {
62
- throw new Error('Received response without body');
63
- }
64
61
  const [head] = await jsonlStreamConsumer({
62
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
65
63
  from: res.body,
66
64
  deserialize: resolvedOpts.transformer.output.deserialize,
67
65
  // onError: console.error,
@@ -73,7 +71,7 @@ import { resolveHTTPLinkOptions, getUrl, fetchHTTPResponse, getBody } from './in
73
71
  }
74
72
  });
75
73
  const promises = Object.keys(batchOps).map(async (key)=>{
76
- let json = await head[key];
74
+ let json = await Promise.resolve(head[key]);
77
75
  if ('result' in json) {
78
76
  /**
79
77
  * Not very pretty, but we need to unwrap nested data as promises
@@ -103,14 +101,15 @@ import { resolveHTTPLinkOptions, getUrl, fetchHTTPResponse, getBody } from './in
103
101
  };
104
102
  const query = dataLoader(batchLoader('query'));
105
103
  const mutation = dataLoader(batchLoader('mutation'));
106
- const subscription = dataLoader(batchLoader('subscription'));
107
104
  const loaders = {
108
105
  query,
109
- subscription,
110
106
  mutation
111
107
  };
112
108
  return ({ op })=>{
113
109
  return observable((observer)=>{
110
+ /* istanbul ignore if -- @preserve */ if (op.type === 'subscription') {
111
+ throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
112
+ }
114
113
  const loader = loaders[op.type];
115
114
  const { promise , cancel } = loader.load(op);
116
115
  let _res = undefined;
@@ -1,7 +1,7 @@
1
- import type { AnyRootTypes, AnyRouter } from '@trpc/server/unstable-core-do-not-import';
1
+ import type { AnyClientTypes, AnyRouter } from '@trpc/server/unstable-core-do-not-import';
2
2
  import type { HTTPLinkBaseOptions } from './internals/httpUtils';
3
3
  import { type HTTPHeaders, type Operation, type TRPCLink } from './types';
4
- export type HTTPLinkOptions<TRoot extends AnyRootTypes> = HTTPLinkBaseOptions<TRoot> & {
4
+ export type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
5
5
  /**
6
6
  * Headers to be set on outgoing requests or a callback that of said headers
7
7
  * @link http://trpc.io/docs/client/headers
@@ -1 +1 @@
1
- {"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["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OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CACvE,CAAC;AAmCJ;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC5D,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC1D,QAAQ,CAAC,OAAO,CAAC,CA+DnB"}
@@ -41,6 +41,9 @@ const universalRequester = (opts)=>{
41
41
  return ({ op })=>{
42
42
  return observable.observable((observer)=>{
43
43
  const { path , input , type } = op;
44
+ /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
45
+ throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
46
+ }
44
47
  const request = universalRequester({
45
48
  ...resolvedOpts,
46
49
  type,
@@ -39,6 +39,9 @@ const universalRequester = (opts)=>{
39
39
  return ({ op })=>{
40
40
  return observable((observer)=>{
41
41
  const { path , input , type } = op;
42
+ /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
43
+ throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
44
+ }
42
45
  const request = universalRequester({
43
46
  ...resolvedOpts,
44
47
  type,
@@ -0,0 +1,19 @@
1
+ import type { AnyClientTypes, inferClientTypes, InferrableClientTypes, MaybePromise } from '@trpc/server/unstable-core-do-not-import';
2
+ import { type TransformerOptions } from '../unstable-internals';
3
+ import type { TRPCLink } from './types';
4
+ type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes> = {
5
+ /**
6
+ * The URL to connect to (can be a function that returns a URL)
7
+ */
8
+ url: string | (() => MaybePromise<string>);
9
+ /**
10
+ * EventSource options
11
+ */
12
+ eventSourceOptions?: EventSourceInit;
13
+ } & TransformerOptions<TRoot>;
14
+ /**
15
+ * @see https://trpc.io/docs/client/links/httpSubscriptionLink
16
+ */
17
+ export declare function unstable_httpSubscriptionLink<TInferrable extends InferrableClientTypes>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>>): TRPCLink<TInferrable>;
18
+ export {};
19
+ //# sourceMappingURL=httpSubscriptionLink.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpSubscriptionLink.d.ts","sourceRoot":"","sources":["../../src/links/httpSubscriptionLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EAEb,MAAM,0CAA0C,CAAC;AAMlD,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,KAAK,2BAA2B,CAAC,KAAK,SAAS,cAAc,IAAI;IAC/D;;OAEG;IACH,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C;;OAEG;IACH,kBAAkB,CAAC,EAAE,eAAe,CAAC;CACtC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAS9B;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,SAAS,qBAAqB,EAEzC,IAAI,EAAE,2BAA2B,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,GAC/D,QAAQ,CAAC,WAAW,CAAC,CA8EvB"}
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ var observable = require('@trpc/server/observable');
4
+ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
5
+ var TRPCClientError = require('../TRPCClientError.js');
6
+ var transformer = require('../internals/transformer.js');
7
+ var httpUtils = require('./internals/httpUtils.js');
8
+
9
+ /**
10
+ * Get the result of a value or function that returns a value
11
+ */ const resultOf = (value)=>{
12
+ return typeof value === 'function' ? value() : value;
13
+ };
14
+ /**
15
+ * @see https://trpc.io/docs/client/links/httpSubscriptionLink
16
+ */ function unstable_httpSubscriptionLink(opts) {
17
+ const transformer$1 = transformer.getTransformer(opts.transformer);
18
+ return ()=>{
19
+ return ({ op })=>{
20
+ return observable.observable((observer)=>{
21
+ const { type , path , input } = op;
22
+ /* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
23
+ throw new Error('httpSubscriptionLink only supports subscriptions');
24
+ }
25
+ let eventSource = null;
26
+ let unsubscribed = false;
27
+ unstableCoreDoNotImport.run(async ()=>{
28
+ const url = httpUtils.getUrl({
29
+ transformer: transformer$1,
30
+ url: await resultOf(opts.url),
31
+ input,
32
+ path,
33
+ type,
34
+ AbortController: null
35
+ });
36
+ /* istanbul ignore if -- @preserve */ if (unsubscribed) {
37
+ // already unsubscribed - rare race condition
38
+ return;
39
+ }
40
+ eventSource = new EventSource(url, opts.eventSourceOptions);
41
+ const onStarted = ()=>{
42
+ observer.next({
43
+ result: {
44
+ type: 'started'
45
+ },
46
+ context: {
47
+ eventSource
48
+ }
49
+ });
50
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
+ eventSource.removeEventListener('open', onStarted);
52
+ };
53
+ // console.log('starting', new Date());
54
+ eventSource.addEventListener('open', onStarted);
55
+ const iterable = unstableCoreDoNotImport.sseStreamConsumer({
56
+ from: eventSource,
57
+ deserialize: transformer$1.input.deserialize
58
+ });
59
+ for await (const chunk of iterable){
60
+ // if the `sse({})`-helper is used, we always have an `id` field
61
+ const data = 'id' in chunk ? chunk : chunk.data;
62
+ observer.next({
63
+ result: {
64
+ data
65
+ }
66
+ });
67
+ }
68
+ observer.next({
69
+ result: {
70
+ type: 'stopped'
71
+ }
72
+ });
73
+ observer.complete();
74
+ }).catch((error)=>{
75
+ observer.error(TRPCClientError.TRPCClientError.from(error));
76
+ });
77
+ return ()=>{
78
+ observer.complete();
79
+ eventSource?.close();
80
+ unsubscribed = true;
81
+ };
82
+ });
83
+ };
84
+ };
85
+ }
86
+
87
+ exports.unstable_httpSubscriptionLink = unstable_httpSubscriptionLink;
@@ -0,0 +1,85 @@
1
+ import { observable } from '@trpc/server/observable';
2
+ import { run, sseStreamConsumer } from '@trpc/server/unstable-core-do-not-import';
3
+ import { TRPCClientError } from '../TRPCClientError.mjs';
4
+ import { getTransformer } from '../internals/transformer.mjs';
5
+ import { getUrl } from './internals/httpUtils.mjs';
6
+
7
+ /**
8
+ * Get the result of a value or function that returns a value
9
+ */ const resultOf = (value)=>{
10
+ return typeof value === 'function' ? value() : value;
11
+ };
12
+ /**
13
+ * @see https://trpc.io/docs/client/links/httpSubscriptionLink
14
+ */ function unstable_httpSubscriptionLink(opts) {
15
+ const transformer = getTransformer(opts.transformer);
16
+ return ()=>{
17
+ return ({ op })=>{
18
+ return observable((observer)=>{
19
+ const { type , path , input } = op;
20
+ /* istanbul ignore if -- @preserve */ if (type !== 'subscription') {
21
+ throw new Error('httpSubscriptionLink only supports subscriptions');
22
+ }
23
+ let eventSource = null;
24
+ let unsubscribed = false;
25
+ run(async ()=>{
26
+ const url = getUrl({
27
+ transformer,
28
+ url: await resultOf(opts.url),
29
+ input,
30
+ path,
31
+ type,
32
+ AbortController: null
33
+ });
34
+ /* istanbul ignore if -- @preserve */ if (unsubscribed) {
35
+ // already unsubscribed - rare race condition
36
+ return;
37
+ }
38
+ eventSource = new EventSource(url, opts.eventSourceOptions);
39
+ const onStarted = ()=>{
40
+ observer.next({
41
+ result: {
42
+ type: 'started'
43
+ },
44
+ context: {
45
+ eventSource
46
+ }
47
+ });
48
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
+ eventSource.removeEventListener('open', onStarted);
50
+ };
51
+ // console.log('starting', new Date());
52
+ eventSource.addEventListener('open', onStarted);
53
+ const iterable = sseStreamConsumer({
54
+ from: eventSource,
55
+ deserialize: transformer.input.deserialize
56
+ });
57
+ for await (const chunk of iterable){
58
+ // if the `sse({})`-helper is used, we always have an `id` field
59
+ const data = 'id' in chunk ? chunk : chunk.data;
60
+ observer.next({
61
+ result: {
62
+ data
63
+ }
64
+ });
65
+ }
66
+ observer.next({
67
+ result: {
68
+ type: 'stopped'
69
+ }
70
+ });
71
+ observer.complete();
72
+ }).catch((error)=>{
73
+ observer.error(TRPCClientError.from(error));
74
+ });
75
+ return ()=>{
76
+ observer.complete();
77
+ eventSource?.close();
78
+ unsubscribed = true;
79
+ };
80
+ });
81
+ };
82
+ };
83
+ }
84
+
85
+ export { unstable_httpSubscriptionLink };
@@ -1,4 +1,4 @@
1
- export declare function isOctetType(input: unknown): boolean;
2
- export declare function isFormData(input: unknown): boolean;
3
- export declare function isNonJsonSerializable(input: unknown): boolean;
1
+ export declare function isOctetType(input: unknown): input is Uint8Array | Blob;
2
+ export declare function isFormData(input: unknown): input is FormData;
3
+ export declare function isNonJsonSerializable(input: unknown): input is Uint8Array | Blob | FormData;
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,WAMzC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,WAExC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,WAEnD"}
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,11 +1,11 @@
1
- import type { AnyRootTypes, CombinedDataTransformer, ProcedureType, TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
1
+ import type { AnyClientTypes, CombinedDataTransformer, ProcedureType, TRPCAcceptHeader, TRPCResponse } from '@trpc/server/unstable-core-do-not-import';
2
2
  import type { AbortControllerEsque, AbortControllerInstanceEsque, FetchEsque, RequestInitEsque, ResponseEsque } from '../../internals/types';
3
3
  import type { TransformerOptions } from '../../unstable-internals';
4
4
  import type { HTTPHeaders, PromiseAndCancel } from '../types';
5
5
  /**
6
6
  * @internal
7
7
  */
8
- export type HTTPLinkBaseOptions<TRoot extends Pick<AnyRootTypes, 'transformer'>> = {
8
+ export type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
9
9
  url: string | URL;
10
10
  /**
11
11
  * Add ponyfill for fetch
@@ -29,7 +29,7 @@ export interface ResolvedHTTPLinkOptions {
29
29
  transformer: CombinedDataTransformer;
30
30
  methodOverride?: 'POST';
31
31
  }
32
- export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions<AnyRootTypes>): ResolvedHTTPLinkOptions;
32
+ export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions<AnyClientTypes>): ResolvedHTTPLinkOptions;
33
33
  export interface HTTPResult {
34
34
  json: TRPCResponse;
35
35
  meta: {
@@ -52,7 +52,7 @@ export type HTTPBaseRequestOptions = GetInputOptions & ResolvedHTTPLinkOptions &
52
52
  type GetUrl = (opts: HTTPBaseRequestOptions) => string;
53
53
  type GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];
54
54
  export type ContentOptions = {
55
- trpcAcceptHeader?: 'application/jsonl';
55
+ trpcAcceptHeader?: TRPCAcceptHeader;
56
56
  contentTypeHeader?: string;
57
57
  getUrl: GetUrl;
58
58
  getBody: GetBody;
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,YAAY,EACb,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EACV,oBAAoB,EACpB,4BAA4B,EAC5B,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;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AsB,GAAG,eAAe,GAClD,uBAAuB,GAAG;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,MAAM,CAAC;AACvD,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG;IAC3B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAiBpB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,OAMrB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,sBAAsB,GAAG;IAC7B,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,KACE,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAElC,eAAO,MAAM,iBAAiB,EAAE,SAO/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAC7C,sBAAsB,GAAG;IACvB,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,CAAC;AAEJ,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,EACxB,EAAE,CAAC,EAAE,4BAA4B,GAAG,IAAI,0BA4BzC;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CA8B9B"}
@@ -7,7 +7,7 @@ var transformer = require('../../internals/transformer.js');
7
7
 
8
8
  function resolveHTTPLinkOptions(opts) {
9
9
  return {
10
- url: opts.url.toString().replace(/\/$/, ''),
10
+ url: opts.url.toString(),
11
11
  fetch: opts.fetch,
12
12
  AbortController: getAbortController.getAbortController(opts.AbortController),
13
13
  transformer: transformer.getTransformer(opts.transformer),
@@ -25,18 +25,20 @@ function arrayToDict(array) {
25
25
  }
26
26
  const METHOD = {
27
27
  query: 'GET',
28
- mutation: 'POST'
28
+ mutation: 'POST',
29
+ subscription: 'PATCH'
29
30
  };
30
31
  function getInput(opts) {
31
32
  return 'input' in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.transformer.input.serialize(_input)));
32
33
  }
33
34
  const getUrl = (opts)=>{
34
- let url = opts.url + '/' + opts.path;
35
+ const base = opts.url.replace(/\/$/, ''); // Remove any trailing slashes
36
+ let url = base + '/' + opts.path;
35
37
  const queryParts = [];
36
38
  if ('inputs' in opts) {
37
39
  queryParts.push('batch=1');
38
40
  }
39
- if (opts.type === 'query') {
41
+ if (opts.type === 'query' || opts.type === 'subscription') {
40
42
  const input = getInput(opts);
41
43
  if (input !== undefined && opts.methodOverride !== 'POST') {
42
44
  queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
@@ -73,9 +75,6 @@ async function fetchHTTPResponse(opts, ac) {
73
75
  }
74
76
  return heads;
75
77
  })();
76
- /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
77
- throw new Error('Subscriptions should use wsLink');
78
- }
79
78
  const headers = {
80
79
  ...opts.contentTypeHeader ? {
81
80
  'content-type': opts.contentTypeHeader
@@ -5,7 +5,7 @@ import { getTransformer } from '../../internals/transformer.mjs';
5
5
 
6
6
  function resolveHTTPLinkOptions(opts) {
7
7
  return {
8
- url: opts.url.toString().replace(/\/$/, ''),
8
+ url: opts.url.toString(),
9
9
  fetch: opts.fetch,
10
10
  AbortController: getAbortController(opts.AbortController),
11
11
  transformer: getTransformer(opts.transformer),
@@ -23,18 +23,20 @@ function arrayToDict(array) {
23
23
  }
24
24
  const METHOD = {
25
25
  query: 'GET',
26
- mutation: 'POST'
26
+ mutation: 'POST',
27
+ subscription: 'PATCH'
27
28
  };
28
29
  function getInput(opts) {
29
30
  return 'input' in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.transformer.input.serialize(_input)));
30
31
  }
31
32
  const getUrl = (opts)=>{
32
- let url = opts.url + '/' + opts.path;
33
+ const base = opts.url.replace(/\/$/, ''); // Remove any trailing slashes
34
+ let url = base + '/' + opts.path;
33
35
  const queryParts = [];
34
36
  if ('inputs' in opts) {
35
37
  queryParts.push('batch=1');
36
38
  }
37
- if (opts.type === 'query') {
39
+ if (opts.type === 'query' || opts.type === 'subscription') {
38
40
  const input = getInput(opts);
39
41
  if (input !== undefined && opts.methodOverride !== 'POST') {
40
42
  queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
@@ -71,9 +73,6 @@ async function fetchHTTPResponse(opts, ac) {
71
73
  }
72
74
  return heads;
73
75
  })();
74
- /* istanbul ignore if -- @preserve */ if (type === 'subscription') {
75
- throw new Error('Subscriptions should use wsLink');
76
- }
77
76
  const headers = {
78
77
  ...opts.contentTypeHeader ? {
79
78
  'content-type': opts.contentTypeHeader
@@ -1,4 +1,3 @@
1
- /// <reference lib="dom.iterable" />
2
1
  import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
3
2
  import type { TRPCClientError } from '../TRPCClientError';
4
3
  import type { Operation, OperationResultEnvelope, TRPCLink } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5E,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAA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EJ,KAAK,YAAY,CAAC,OAAO,SAAS,SAAS,IAAI,CAC7C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,KAC/B,IAAI,CAAC;AAEV,KAAK,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAEzC,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,SAAS;IAC1D,MAAM,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC7B;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAoID;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CAgDnB"}
@@ -52,14 +52,14 @@ export declare function createWSClient(opts: WebSocketClientOptions): {
52
52
  readonly connection: ({
53
53
  id: number;
54
54
  } & ({
55
- state: 'open';
55
+ state: "open";
56
56
  ws: WebSocket;
57
57
  } | {
58
- state: 'closed';
58
+ state: "closed";
59
59
  ws: WebSocket;
60
60
  } | {
61
- state: 'connecting';
62
- ws?: WebSocket | undefined;
61
+ state: "connecting";
62
+ ws?: WebSocket;
63
63
  })) | null;
64
64
  };
65
65
  export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
@@ -1 +1 @@
1
- {"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../src/links/wsLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EAMZ,mBAAmB,EACpB,MAA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AAM,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3C;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACzC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,IAAI,CAAC,EAAE;QACL;;;WAGG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAOD,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB;;kBAgSpC,SAAS,wDAA0B,aAAa;;YAhP/D,MAAM;;eAGC,MAAM;YACT,SAAS;;eAGN,QAAQ;YACX,SAAS;;eAGN,YAAY;aACd,SAAS;;EAoSrB;AACD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAEpE,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI;IAC5D,MAAM,EAAE,mBAAmB,CAAC;CAC7B,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AASlD;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,SAAS,SAAS,EAC9C,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,QAAQ,CAAC,OAAO,CAAC,CA8CnB"}
package/dist/links.d.ts CHANGED
@@ -6,4 +6,5 @@ export * from './links/httpLink';
6
6
  export * from './links/loggerLink';
7
7
  export * from './links/splitLink';
8
8
  export * from './links/wsLink';
9
+ export * from './links/httpSubscriptionLink';
9
10
  //# sourceMappingURL=links.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "11.0.0-rc.417+94650c185",
3
+ "version": "11.0.0-rc.419+343b6de2e",
4
4
  "description": "The tRPC client library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -76,10 +76,10 @@
76
76
  "!**/*.test.*"
77
77
  ],
78
78
  "peerDependencies": {
79
- "@trpc/server": "11.0.0-rc.417+94650c185"
79
+ "@trpc/server": "11.0.0-rc.419+343b6de2e"
80
80
  },
81
81
  "devDependencies": {
82
- "@trpc/server": "11.0.0-rc.417+94650c185",
82
+ "@trpc/server": "11.0.0-rc.419+343b6de2e",
83
83
  "@types/isomorphic-fetch": "^0.0.39",
84
84
  "@types/node": "^20.10.0",
85
85
  "eslint": "^8.56.0",
@@ -96,5 +96,5 @@
96
96
  "funding": [
97
97
  "https://trpc.io/sponsor"
98
98
  ],
99
- "gitHead": "94650c185b067c86f2e71fb224b1e70f463632b7"
99
+ "gitHead": "343b6de2ea719347bffe8332f37589c66c323349"
100
100
  }
@@ -27,7 +27,7 @@ export interface TRPCRequestOptions {
27
27
  }
28
28
 
29
29
  export interface TRPCSubscriptionObserver<TValue, TError> {
30
- onStarted: () => void;
30
+ onStarted: (opts: { context: OperationContext | undefined }) => void;
31
31
  onData: (value: TValue) => void;
32
32
  onError: (err: TError) => void;
33
33
  onStopped: () => void;
@@ -148,7 +148,9 @@ export class TRPCUntypedClient<TRouter extends AnyRouter> {
148
148
  return observable$.subscribe({
149
149
  next(envelope) {
150
150
  if (envelope.result.type === 'started') {
151
- opts.onStarted?.();
151
+ opts.onStarted?.({
152
+ context: envelope.context,
153
+ });
152
154
  } else if (envelope.result.type === 'stopped') {
153
155
  opts.onStopped?.();
154
156
  } else {
@@ -86,14 +86,17 @@ export function httpBatchLink<TRouter extends AnyRouter>(
86
86
  };
87
87
 
88
88
  const query = dataLoader(batchLoader('query'));
89
- const mutation = dataLoader<Operation, HTTPResult>(batchLoader('mutation'));
90
- const subscription = dataLoader<Operation, HTTPResult>(
91
- batchLoader('subscription'),
92
- );
89
+ const mutation = dataLoader(batchLoader('mutation'));
93
90
 
94
- const loaders = { query, subscription, mutation };
91
+ const loaders = { query, mutation };
95
92
  return ({ op }) => {
96
93
  return observable((observer) => {
94
+ /* istanbul ignore if -- @preserve */
95
+ if (op.type === 'subscription') {
96
+ throw new Error(
97
+ 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',
98
+ );
99
+ }
97
100
  const loader = loaders[op.type];
98
101
  const { promise, cancel } = loader.load(op);
99
102
 
@@ -95,13 +95,11 @@ export function unstable_httpBatchStreamLink<TRouter extends AnyRouter>(
95
95
 
96
96
  return {
97
97
  promise: responsePromise.then(async (res) => {
98
- if (!res.body) {
99
- throw new Error('Received response without body');
100
- }
101
98
  const [head] = await jsonlStreamConsumer<
102
99
  Record<string, Promise<any>>
103
100
  >({
104
- from: res.body,
101
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
102
+ from: res.body!,
105
103
  deserialize: resolvedOpts.transformer.output.deserialize,
106
104
  // onError: console.error,
107
105
  formatError(opts) {
@@ -114,7 +112,7 @@ export function unstable_httpBatchStreamLink<TRouter extends AnyRouter>(
114
112
 
115
113
  const promises = Object.keys(batchOps).map(
116
114
  async (key): Promise<HTTPResult> => {
117
- let json: TRPCResponse = await head[key];
115
+ let json: TRPCResponse = await Promise.resolve(head[key]);
118
116
 
119
117
  if ('result' in json) {
120
118
  /**
@@ -149,11 +147,16 @@ export function unstable_httpBatchStreamLink<TRouter extends AnyRouter>(
149
147
 
150
148
  const query = dataLoader(batchLoader('query'));
151
149
  const mutation = dataLoader(batchLoader('mutation'));
152
- const subscription = dataLoader(batchLoader('subscription'));
153
150
 
154
- const loaders = { query, subscription, mutation };
151
+ const loaders = { query, mutation };
155
152
  return ({ op }) => {
156
153
  return observable((observer) => {
154
+ /* istanbul ignore if -- @preserve */
155
+ if (op.type === 'subscription') {
156
+ throw new Error(
157
+ 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',
158
+ );
159
+ }
157
160
  const loader = loaders[op.type];
158
161
  const { promise, cancel } = loader.load(op);
159
162
 
@@ -1,6 +1,6 @@
1
1
  import { observable } from '@trpc/server/observable';
2
2
  import type {
3
- AnyRootTypes,
3
+ AnyClientTypes,
4
4
  AnyRouter,
5
5
  } from '@trpc/server/unstable-core-do-not-import';
6
6
  import { transformResult } from '@trpc/server/unstable-core-do-not-import';
@@ -25,7 +25,7 @@ import {
25
25
  type TRPCLink,
26
26
  } from './types';
27
27
 
28
- export type HTTPLinkOptions<TRoot extends AnyRootTypes> =
28
+ export type HTTPLinkOptions<TRoot extends AnyClientTypes> =
29
29
  HTTPLinkBaseOptions<TRoot> & {
30
30
  /**
31
31
  * Headers to be set on outgoing requests or a callback that of said headers
@@ -80,6 +80,12 @@ export function httpLink<TRouter extends AnyRouter = AnyRouter>(
80
80
  return ({ op }) => {
81
81
  return observable((observer) => {
82
82
  const { path, input, type } = op;
83
+ /* istanbul ignore if -- @preserve */
84
+ if (type === 'subscription') {
85
+ throw new Error(
86
+ 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',
87
+ );
88
+ }
83
89
 
84
90
  const request = universalRequester({
85
91
  ...resolvedOpts,
@@ -0,0 +1,121 @@
1
+ import { observable } from '@trpc/server/observable';
2
+ import type {
3
+ AnyClientTypes,
4
+ inferClientTypes,
5
+ InferrableClientTypes,
6
+ MaybePromise,
7
+ SSEvent,
8
+ } from '@trpc/server/unstable-core-do-not-import';
9
+ import {
10
+ run,
11
+ sseStreamConsumer,
12
+ } from '@trpc/server/unstable-core-do-not-import';
13
+ import { TRPCClientError } from '../TRPCClientError';
14
+ import { getTransformer, type TransformerOptions } from '../unstable-internals';
15
+ import { getUrl } from './internals/httpUtils';
16
+ import type { TRPCLink } from './types';
17
+
18
+ type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes> = {
19
+ /**
20
+ * The URL to connect to (can be a function that returns a URL)
21
+ */
22
+ url: string | (() => MaybePromise<string>);
23
+ /**
24
+ * EventSource options
25
+ */
26
+ eventSourceOptions?: EventSourceInit;
27
+ } & TransformerOptions<TRoot>;
28
+
29
+ /**
30
+ * Get the result of a value or function that returns a value
31
+ */
32
+ const resultOf = <T>(value: T | (() => T)): T => {
33
+ return typeof value === 'function' ? (value as () => T)() : value;
34
+ };
35
+
36
+ /**
37
+ * @see https://trpc.io/docs/client/links/httpSubscriptionLink
38
+ */
39
+ export function unstable_httpSubscriptionLink<
40
+ TInferrable extends InferrableClientTypes,
41
+ >(
42
+ opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>>,
43
+ ): TRPCLink<TInferrable> {
44
+ const transformer = getTransformer(opts.transformer);
45
+ return () => {
46
+ return ({ op }) => {
47
+ return observable((observer) => {
48
+ const { type, path, input } = op;
49
+ /* istanbul ignore if -- @preserve */
50
+ if (type !== 'subscription') {
51
+ throw new Error('httpSubscriptionLink only supports subscriptions');
52
+ }
53
+
54
+ let eventSource: EventSource | null = null;
55
+ let unsubscribed = false;
56
+
57
+ run(async () => {
58
+ const url = getUrl({
59
+ transformer,
60
+ url: await resultOf(opts.url),
61
+ input,
62
+ path,
63
+ type,
64
+ AbortController: null,
65
+ });
66
+
67
+ /* istanbul ignore if -- @preserve */
68
+ if (unsubscribed) {
69
+ // already unsubscribed - rare race condition
70
+ return;
71
+ }
72
+ eventSource = new EventSource(url, opts.eventSourceOptions);
73
+ const onStarted = () => {
74
+ observer.next({
75
+ result: {
76
+ type: 'started',
77
+ },
78
+ context: {
79
+ eventSource,
80
+ },
81
+ });
82
+
83
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84
+ eventSource!.removeEventListener('open', onStarted);
85
+ };
86
+ // console.log('starting', new Date());
87
+ eventSource.addEventListener('open', onStarted);
88
+ const iterable = sseStreamConsumer<SSEvent>({
89
+ from: eventSource,
90
+ deserialize: transformer.input.deserialize,
91
+ });
92
+
93
+ for await (const chunk of iterable) {
94
+ // if the `sse({})`-helper is used, we always have an `id` field
95
+ const data = 'id' in chunk ? chunk : chunk.data;
96
+ observer.next({
97
+ result: {
98
+ data,
99
+ },
100
+ });
101
+ }
102
+
103
+ observer.next({
104
+ result: {
105
+ type: 'stopped',
106
+ },
107
+ });
108
+ observer.complete();
109
+ }).catch((error) => {
110
+ observer.error(TRPCClientError.from(error));
111
+ });
112
+
113
+ return () => {
114
+ observer.complete();
115
+ eventSource?.close();
116
+ unsubscribed = true;
117
+ };
118
+ });
119
+ };
120
+ };
121
+ }
@@ -1,7 +1,8 @@
1
1
  import type {
2
- AnyRootTypes,
2
+ AnyClientTypes,
3
3
  CombinedDataTransformer,
4
4
  ProcedureType,
5
+ TRPCAcceptHeader,
5
6
  TRPCResponse,
6
7
  } from '@trpc/server/unstable-core-do-not-import';
7
8
  import { getFetch } from '../../getFetch';
@@ -22,7 +23,7 @@ import type { HTTPHeaders, PromiseAndCancel } from '../types';
22
23
  * @internal
23
24
  */
24
25
  export type HTTPLinkBaseOptions<
25
- TRoot extends Pick<AnyRootTypes, 'transformer'>,
26
+ TRoot extends Pick<AnyClientTypes, 'transformer'>,
26
27
  > = {
27
28
  url: string | URL;
28
29
  /**
@@ -50,10 +51,10 @@ export interface ResolvedHTTPLinkOptions {
50
51
  }
51
52
 
52
53
  export function resolveHTTPLinkOptions(
53
- opts: HTTPLinkBaseOptions<AnyRootTypes>,
54
+ opts: HTTPLinkBaseOptions<AnyClientTypes>,
54
55
  ): ResolvedHTTPLinkOptions {
55
56
  return {
56
- url: opts.url.toString().replace(/\/$/, ''), // Remove any trailing slashes
57
+ url: opts.url.toString(),
57
58
  fetch: opts.fetch,
58
59
  AbortController: getAbortController(opts.AbortController),
59
60
  transformer: getTransformer(opts.transformer),
@@ -74,6 +75,7 @@ function arrayToDict(array: unknown[]) {
74
75
  const METHOD = {
75
76
  query: 'GET',
76
77
  mutation: 'POST',
78
+ subscription: 'PATCH',
77
79
  } as const;
78
80
 
79
81
  export interface HTTPResult {
@@ -106,19 +108,20 @@ type GetUrl = (opts: HTTPBaseRequestOptions) => string;
106
108
  type GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];
107
109
 
108
110
  export type ContentOptions = {
109
- trpcAcceptHeader?: 'application/jsonl';
111
+ trpcAcceptHeader?: TRPCAcceptHeader;
110
112
  contentTypeHeader?: string;
111
113
  getUrl: GetUrl;
112
114
  getBody: GetBody;
113
115
  };
114
116
 
115
117
  export const getUrl: GetUrl = (opts) => {
116
- let url = opts.url + '/' + opts.path;
118
+ const base = opts.url.replace(/\/$/, ''); // Remove any trailing slashes
119
+ let url = base + '/' + opts.path;
117
120
  const queryParts: string[] = [];
118
121
  if ('inputs' in opts) {
119
122
  queryParts.push('batch=1');
120
123
  }
121
- if (opts.type === 'query') {
124
+ if (opts.type === 'query' || opts.type === 'subscription') {
122
125
  const input = getInput(opts);
123
126
  if (input !== undefined && opts.methodOverride !== 'POST') {
124
127
  queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
@@ -172,10 +175,6 @@ export async function fetchHTTPResponse(
172
175
  }
173
176
  return heads;
174
177
  })();
175
- /* istanbul ignore if -- @preserve */
176
- if (type === 'subscription') {
177
- throw new Error('Subscriptions should use wsLink');
178
- }
179
178
  const headers = {
180
179
  ...(opts.contentTypeHeader
181
180
  ? { 'content-type': opts.contentTypeHeader }
package/src/links.ts CHANGED
@@ -7,6 +7,7 @@ export * from './links/httpLink';
7
7
  export * from './links/loggerLink';
8
8
  export * from './links/splitLink';
9
9
  export * from './links/wsLink';
10
+ export * from './links/httpSubscriptionLink';
10
11
 
11
12
  // These are not public (yet) as we get this functionality from tanstack query
12
13
  // export * from './links/internals/retryLink';