@trpc/client 10.0.0-alpha.0 → 10.0.0-alpha.11

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 (203) hide show
  1. package/dist/{TRPCClientError-e1da1ef0.esm.js → TRPCClientError-17b117e1.mjs} +16 -7
  2. package/dist/TRPCClientError-ec6bd2ca.js +94 -0
  3. package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -29
  4. package/dist/TRPCClientError.d.ts.map +1 -0
  5. package/dist/{createChain-93a38e1c.cjs.dev.js → createChain-3b458753.js} +2 -2
  6. package/dist/{createChain-e45e6cf2.esm.js → createChain-b7cb1f5a.mjs} +2 -2
  7. package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -5
  8. package/dist/createTRPCClient.d.ts.map +1 -0
  9. package/dist/{declarations/src/getFetch.d.ts → getFetch.d.ts} +1 -1
  10. package/dist/getFetch.d.ts.map +1 -0
  11. package/dist/{httpUtils-a1426e14.cjs.dev.js → httpUtils-1f9e4e3c.js} +9 -1
  12. package/dist/{httpUtils-e45c9056.esm.js → httpUtils-c09d7b79.mjs} +5 -1
  13. package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/{trpc-client.cjs.dev.js → index.js} +23 -81
  16. package/dist/{trpc-client.esm.js → index.mjs} +16 -79
  17. package/dist/index.ts.js +1 -0
  18. package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +62 -64
  19. package/dist/internals/TRPCClient.d.ts.map +1 -0
  20. package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +16 -14
  21. package/dist/internals/dataLoader.d.ts.map +1 -0
  22. package/dist/{declarations/src/internals → internals}/fetchHelpers.d.ts +2 -2
  23. package/dist/internals/fetchHelpers.d.ts.map +1 -0
  24. package/dist/{declarations/src/internals → internals}/retryDelay.d.ts +1 -1
  25. package/dist/internals/retryDelay.d.ts.map +1 -0
  26. package/dist/links/dedupeLink.d.ts +4 -0
  27. package/dist/links/dedupeLink.d.ts.map +1 -0
  28. package/dist/links/httpBatchLink.d.ts +8 -0
  29. package/dist/links/httpBatchLink.d.ts.map +1 -0
  30. package/dist/links/httpBatchLink.js +195 -0
  31. package/dist/links/httpBatchLink.mjs +191 -0
  32. package/dist/links/httpBatchLink.ts.js +1 -0
  33. package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -4
  34. package/dist/links/httpLink.d.ts.map +1 -0
  35. package/dist/links/httpLink.js +44 -0
  36. package/dist/links/httpLink.mjs +40 -0
  37. package/dist/links/httpLink.ts.js +1 -0
  38. package/dist/{declarations/src/links → links}/httpUtils.d.ts +21 -21
  39. package/dist/links/httpUtils.d.ts.map +1 -0
  40. package/dist/{declarations/src/links → links}/internals/createChain.d.ts +7 -7
  41. package/dist/links/internals/createChain.d.ts.map +1 -0
  42. package/dist/{declarations/src/links → links}/internals/transformOperationResult.d.ts +15 -15
  43. package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
  44. package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -38
  45. package/dist/links/loggerLink.d.ts.map +1 -0
  46. package/dist/links/loggerLink.js +107 -0
  47. package/dist/links/loggerLink.mjs +98 -0
  48. package/dist/links/loggerLink.ts.js +1 -0
  49. package/dist/links/retryLink.d.ts +6 -0
  50. package/dist/links/retryLink.d.ts.map +1 -0
  51. package/dist/{declarations/src/links → links}/splitLink.d.ts +13 -13
  52. package/dist/links/splitLink.d.ts.map +1 -0
  53. package/dist/links/splitLink.js +32 -0
  54. package/dist/links/splitLink.mjs +28 -0
  55. package/dist/links/splitLink.ts.js +1 -0
  56. package/dist/{declarations/src/links → links}/transformerLink.d.ts +3 -3
  57. package/dist/links/transformerLink.d.ts.map +1 -0
  58. package/dist/links/transformerLink.js +79 -0
  59. package/dist/links/transformerLink.mjs +71 -0
  60. package/dist/links/transformerLink.ts.js +1 -0
  61. package/dist/{declarations/src/links → links}/types.d.ts +38 -39
  62. package/dist/links/types.d.ts.map +1 -0
  63. package/dist/{declarations/src/links → links}/wsLink.d.ts +20 -19
  64. package/dist/links/wsLink.d.ts.map +1 -0
  65. package/dist/links/wsLink.js +385 -0
  66. package/dist/links/wsLink.mjs +370 -0
  67. package/dist/links/wsLink.ts.js +1 -0
  68. package/dist/rx.d.ts +12 -0
  69. package/dist/rx.d.ts.map +1 -0
  70. package/dist/rx.js +130 -0
  71. package/dist/rx.mjs +114 -0
  72. package/dist/rx.ts.js +1 -0
  73. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +68 -38
  74. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +68 -38
  75. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +67 -37
  76. package/links/httpBatchLink/index.d.ts +1 -0
  77. package/links/httpBatchLink/index.js +1 -0
  78. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +52 -29
  79. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +52 -29
  80. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +52 -29
  81. package/links/httpLink/index.d.ts +1 -0
  82. package/links/httpLink/index.js +1 -0
  83. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +19 -31
  84. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +19 -31
  85. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +19 -31
  86. package/links/loggerLink/index.d.ts +1 -0
  87. package/links/loggerLink/index.js +1 -0
  88. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +7 -20
  89. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +7 -20
  90. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +7 -20
  91. package/links/splitLink/index.d.ts +1 -0
  92. package/links/splitLink/index.js +1 -0
  93. package/links/transformerLink/index.d.ts +1 -0
  94. package/links/transformerLink/index.js +1 -0
  95. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +85 -60
  96. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +85 -60
  97. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +85 -60
  98. package/links/wsLink/index.d.ts +1 -0
  99. package/links/wsLink/index.js +1 -0
  100. package/package.json +54 -23
  101. package/src/internals/TRPCClient.ts +5 -12
  102. package/src/internals/dataLoader.ts +13 -1
  103. package/src/links/dedupeLink.test.ts +3 -3
  104. package/src/links/dedupeLink.ts +26 -27
  105. package/src/links/httpBatchLink.ts +11 -5
  106. package/src/links/httpLink.ts +2 -2
  107. package/src/links/internals/createChain.test.ts +7 -7
  108. package/src/links/internals/createChain.ts +2 -2
  109. package/src/links/loggerLink.ts +2 -3
  110. package/src/links/retryLink.ts +2 -3
  111. package/src/links/splitLink.test.ts +3 -3
  112. package/src/links/splitLink.ts +2 -2
  113. package/src/links/transformerLink.ts +10 -6
  114. package/src/links/types.ts +3 -4
  115. package/src/links/wsLink.ts +5 -3
  116. package/src/rx.ts +82 -0
  117. package/dist/TRPCClientError-a5312a5f.cjs.dev.js +0 -74
  118. package/dist/TRPCClientError-ea7d89b2.cjs.prod.js +0 -74
  119. package/dist/createChain-e45e052a.cjs.prod.js +0 -27
  120. package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
  121. package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
  122. package/dist/declarations/src/getFetch.d.ts.map +0 -1
  123. package/dist/declarations/src/index.d.ts.map +0 -1
  124. package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
  125. package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
  126. package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
  127. package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
  128. package/dist/declarations/src/links/httpBatchLink.d.ts +0 -5
  129. package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
  130. package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
  131. package/dist/declarations/src/links/httpUtils.d.ts.map +0 -1
  132. package/dist/declarations/src/links/internals/createChain.d.ts.map +0 -1
  133. package/dist/declarations/src/links/internals/transformOperationResult.d.ts.map +0 -1
  134. package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
  135. package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
  136. package/dist/declarations/src/links/transformerLink.d.ts.map +0 -1
  137. package/dist/declarations/src/links/types.d.ts.map +0 -1
  138. package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
  139. package/dist/declarations/src/rx/index.d.ts +0 -3
  140. package/dist/declarations/src/rx/index.d.ts.map +0 -1
  141. package/dist/declarations/src/rx/observable.d.ts +0 -4
  142. package/dist/declarations/src/rx/observable.d.ts.map +0 -1
  143. package/dist/declarations/src/rx/operators/index.d.ts +0 -4
  144. package/dist/declarations/src/rx/operators/index.d.ts.map +0 -1
  145. package/dist/declarations/src/rx/operators/map.d.ts +0 -3
  146. package/dist/declarations/src/rx/operators/map.d.ts.map +0 -1
  147. package/dist/declarations/src/rx/operators/share.d.ts +0 -6
  148. package/dist/declarations/src/rx/operators/share.d.ts.map +0 -1
  149. package/dist/declarations/src/rx/operators/tap.d.ts +0 -3
  150. package/dist/declarations/src/rx/operators/tap.d.ts.map +0 -1
  151. package/dist/declarations/src/rx/types.d.ts +0 -29
  152. package/dist/declarations/src/rx/types.d.ts.map +0 -1
  153. package/dist/declarations/src/rx/util/identity.d.ts +0 -2
  154. package/dist/declarations/src/rx/util/identity.d.ts.map +0 -1
  155. package/dist/declarations/src/rx/util/observableToPromise.d.ts +0 -10
  156. package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +0 -1
  157. package/dist/declarations/src/rx/util/pipe.d.ts +0 -4
  158. package/dist/declarations/src/rx/util/pipe.d.ts.map +0 -1
  159. package/dist/httpUtils-299a66f6.cjs.prod.js +0 -89
  160. package/dist/observable-01534ea8.esm.js +0 -102
  161. package/dist/observable-9aad8c3e.cjs.dev.js +0 -104
  162. package/dist/observable-ccb54234.cjs.prod.js +0 -104
  163. package/dist/share-5a8c2543.cjs.prod.js +0 -106
  164. package/dist/share-ca585761.esm.js +0 -104
  165. package/dist/share-f2ac9332.cjs.dev.js +0 -106
  166. package/dist/tap-2d565250.cjs.dev.js +0 -32
  167. package/dist/tap-606957cb.esm.js +0 -30
  168. package/dist/tap-d907998d.cjs.prod.js +0 -32
  169. package/dist/trpc-client.cjs.d.ts +0 -1
  170. package/dist/trpc-client.cjs.js +0 -7
  171. package/dist/trpc-client.cjs.prod.js +0 -300
  172. package/links/httpBatchLink/package.json +0 -4
  173. package/links/httpLink/package.json +0 -4
  174. package/links/loggerLink/package.json +0 -4
  175. package/links/splitLink/package.json +0 -4
  176. package/links/transformerLink/package.json +0 -4
  177. package/links/wsLink/package.json +0 -4
  178. package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
  179. package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
  180. package/rx/dist/trpc-client-rx.cjs.js +0 -7
  181. package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
  182. package/rx/dist/trpc-client-rx.esm.js +0 -1
  183. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
  184. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
  185. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
  186. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
  187. package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
  188. package/rx/operators/package.json +0 -4
  189. package/rx/package.json +0 -4
  190. package/src/internals/transformRPCResponse.ts +0 -25
  191. package/src/rx/index.ts +0 -2
  192. package/src/rx/observable.test.ts +0 -83
  193. package/src/rx/observable.ts +0 -70
  194. package/src/rx/operators/index.ts +0 -3
  195. package/src/rx/operators/map.test.ts +0 -92
  196. package/src/rx/operators/map.ts +0 -25
  197. package/src/rx/operators/share.test.ts +0 -60
  198. package/src/rx/operators/share.ts +0 -67
  199. package/src/rx/operators/tap.ts +0 -26
  200. package/src/rx/types.ts +0 -69
  201. package/src/rx/util/identity.ts +0 -3
  202. package/src/rx/util/observableToPromise.ts +0 -49
  203. package/src/rx/util/pipe.ts +0 -22
@@ -1,12 +1,11 @@
1
+ import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
2
+ import _createClass from '@babel/runtime/helpers/esm/createClass';
1
3
  import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
2
4
  import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
3
5
  import _inherits from '@babel/runtime/helpers/esm/inherits';
4
6
  import _createSuper from '@babel/runtime/helpers/esm/createSuper';
5
7
  import _wrapNativeSuper from '@babel/runtime/helpers/esm/wrapNativeSuper';
6
- import { o as observable } from '../../../dist/observable-01534ea8.esm.js';
7
- import { T as TRPCClientError } from '../../../dist/TRPCClientError-e1da1ef0.esm.js';
8
- import '@babel/runtime/helpers/objectSpread2';
9
- import '@babel/runtime/helpers/createClass';
8
+ import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
10
9
 
11
10
  /* istanbul ignore next */
12
11
  var retryDelay = function retryDelay(attemptIndex) {
@@ -145,19 +144,24 @@ function createWSClient(opts) {
145
144
  }
146
145
  };
147
146
 
148
- var handleIncomingResponse = function handleIncomingResponse(data) {
149
- var _req$callbacks$next, _req$callbacks;
147
+ var handleIncomingResponse = function handleIncomingResponse(res) {
148
+ var _req$callbacks$onNext, _req$callbacks2;
150
149
 
151
- var req = data.id !== null && pendingRequests[data.id];
150
+ var req = res.id !== null && pendingRequests[res.id];
152
151
 
153
152
  if (!req) {
154
153
  // do something?
155
154
  return;
156
155
  }
157
156
 
158
- (_req$callbacks$next = (_req$callbacks = req.callbacks).next) === null || _req$callbacks$next === void 0 ? void 0 : _req$callbacks$next.call(_req$callbacks, {
159
- data: data
160
- });
157
+ if ('error' in res) {
158
+ var _req$callbacks$onErro, _req$callbacks;
159
+
160
+ (_req$callbacks$onErro = (_req$callbacks = req.callbacks).onError) === null || _req$callbacks$onErro === void 0 ? void 0 : _req$callbacks$onErro.call(_req$callbacks, res);
161
+ return;
162
+ }
163
+
164
+ (_req$callbacks$onNext = (_req$callbacks2 = req.callbacks).onNext) === null || _req$callbacks$onNext === void 0 ? void 0 : _req$callbacks$onNext.call(_req$callbacks2, res.result);
161
165
 
162
166
  if (req.ws !== activeConnection && conn === activeConnection) {
163
167
  var oldWs = req.ws; // gracefully replace old connection with this
@@ -166,8 +170,10 @@ function createWSClient(opts) {
166
170
  closeIfNoPending(oldWs);
167
171
  }
168
172
 
169
- if ('result' in data && data.result.type === 'stopped' && conn === activeConnection) {
170
- req.callbacks.complete();
173
+ if (res.result.type === 'stopped' && conn === activeConnection) {
174
+ var _req$callbacks$onDone, _req$callbacks3;
175
+
176
+ (_req$callbacks$onDone = (_req$callbacks3 = req.callbacks).onDone) === null || _req$callbacks$onDone === void 0 ? void 0 : _req$callbacks$onDone.call(_req$callbacks3);
171
177
  }
172
178
  };
173
179
 
@@ -193,7 +199,7 @@ function createWSClient(opts) {
193
199
  }
194
200
 
195
201
  for (var key in pendingRequests) {
196
- var _req$callbacks$error, _req$callbacks2;
202
+ var _req$callbacks$onErro2, _req$callbacks4;
197
203
 
198
204
  var req = pendingRequests[key];
199
205
 
@@ -201,13 +207,13 @@ function createWSClient(opts) {
201
207
  continue;
202
208
  }
203
209
 
204
- (_req$callbacks$error = (_req$callbacks2 = req.callbacks).error) === null || _req$callbacks$error === void 0 ? void 0 : _req$callbacks$error.call(_req$callbacks2, TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
210
+ (_req$callbacks$onErro2 = (_req$callbacks4 = req.callbacks).onError) === null || _req$callbacks$onErro2 === void 0 ? void 0 : _req$callbacks$onErro2.call(_req$callbacks4, TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
205
211
 
206
212
  if (req.type !== 'subscription') {
207
- var _req$callbacks$comple, _req$callbacks3;
213
+ var _req$callbacks$onDone2, _req$callbacks5;
208
214
 
209
215
  delete pendingRequests[key];
210
- (_req$callbacks$comple = (_req$callbacks3 = req.callbacks).complete) === null || _req$callbacks$comple === void 0 ? void 0 : _req$callbacks$comple.call(_req$callbacks3);
216
+ (_req$callbacks$onDone2 = (_req$callbacks5 = req.callbacks).onDone) === null || _req$callbacks$onDone2 === void 0 ? void 0 : _req$callbacks$onDone2.call(_req$callbacks5);
211
217
  } else if (state !== 'closed') {
212
218
  // request restart of sub with next connection
213
219
  resumeSubscriptionOnReconnect(req);
@@ -241,14 +247,14 @@ function createWSClient(opts) {
241
247
  outgoing.push(envelope);
242
248
  dispatch();
243
249
  return function () {
244
- var _pendingRequests$id, _callbacks$complete;
250
+ var _pendingRequests$id, _callbacks$onDone;
245
251
 
246
252
  var callbacks = (_pendingRequests$id = pendingRequests[id]) === null || _pendingRequests$id === void 0 ? void 0 : _pendingRequests$id.callbacks;
247
253
  delete pendingRequests[id];
248
254
  outgoing = outgoing.filter(function (msg) {
249
255
  return msg.id !== id;
250
256
  });
251
- callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$complete = callbacks.complete) === null || _callbacks$complete === void 0 ? void 0 : _callbacks$complete.call(callbacks);
257
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onDone = callbacks.onDone) === null || _callbacks$onDone === void 0 ? void 0 : _callbacks$onDone.call(callbacks);
252
258
 
253
259
  if (op.type === 'subscription') {
254
260
  outgoing.push({
@@ -289,7 +295,7 @@ var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
289
295
  return _this;
290
296
  }
291
297
 
292
- return TRPCWebSocketClosedError;
298
+ return _createClass(TRPCWebSocketClosedError);
293
299
  }( /*#__PURE__*/_wrapNativeSuper(Error));
294
300
 
295
301
  var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
@@ -308,55 +314,74 @@ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
308
314
  return _this2;
309
315
  }
310
316
 
311
- return TRPCSubscriptionEndedError;
317
+ return _createClass(TRPCSubscriptionEndedError);
312
318
  }( /*#__PURE__*/_wrapNativeSuper(Error));
313
319
 
314
320
  function wsLink(opts) {
315
- return function () {
321
+ // initialized config
322
+ return function (rt) {
316
323
  var client = opts.client;
317
324
  return function (_ref2) {
318
- var op = _ref2.op;
319
- return observable(function (observer) {
320
- var type = op.type,
321
- input = op.input,
322
- path = op.path,
323
- id = op.id,
324
- context = op.context;
325
- var isDone = false;
326
- var unsub = client.request({
327
- type: type,
328
- path: path,
329
- input: input,
330
- id: id,
331
- context: context
332
- }, {
333
- error: function error(err) {
325
+ var op = _ref2.op,
326
+ prev = _ref2.prev,
327
+ onDestroy = _ref2.onDestroy;
328
+ var type = op.type,
329
+ rawInput = op.input,
330
+ path = op.path,
331
+ id = op.id;
332
+ var input = rt.transformer.serialize(rawInput);
333
+ var isDone = false;
334
+ var unsub = client.request({
335
+ type: type,
336
+ path: path,
337
+ input: input,
338
+ id: id
339
+ }, {
340
+ onNext: function onNext(result) {
341
+ if (isDone) {
342
+ return;
343
+ }
344
+
345
+ if ('data' in result) {
346
+ var data = rt.transformer.deserialize(result.data);
347
+ prev({
348
+ type: 'data',
349
+ data: data
350
+ });
351
+ } else {
352
+ prev(result);
353
+ }
354
+
355
+ if (op.type !== 'subscription') {
356
+ // if it isn't a subscription we don't care about next response
334
357
  isDone = true;
335
- observer.error(err);
336
358
  unsub();
337
- },
338
- complete: function complete() {
339
- if (!isDone) {
340
- isDone = true;
341
- observer.error(TRPCClientError.from(new TRPCSubscriptionEndedError('Operation ended prematurely')));
342
- } else {
343
- observer.complete();
344
- }
345
- },
346
- next: function next(result) {
347
- observer.next(result);
348
-
349
- if (op.type !== 'subscription') {
350
- // if it isn't a subscription we don't care about next response
351
- isDone = true;
352
- unsub();
353
- observer.complete();
354
- }
355
359
  }
356
- });
357
- return function () {
358
- unsub();
359
- };
360
+ },
361
+ onError: function onError(err) {
362
+ if (isDone) {
363
+ return;
364
+ }
365
+
366
+ prev(err instanceof Error ? err : TRPCClientError.from(_objectSpread(_objectSpread({}, err), {}, {
367
+ error: rt.transformer.deserialize(err.error)
368
+ })));
369
+ },
370
+ onDone: function onDone() {
371
+ if (isDone) {
372
+ return;
373
+ }
374
+
375
+ var result = new TRPCSubscriptionEndedError('Operation ended prematurely');
376
+ prev(TRPCClientError.from(result, {
377
+ isDone: true
378
+ }));
379
+ isDone = true;
380
+ }
381
+ });
382
+ onDestroy(function () {
383
+ isDone = true;
384
+ unsub();
360
385
  });
361
386
  };
362
387
  };
@@ -0,0 +1 @@
1
+ export * from '../../dist/links/wsLink';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/links/wsLink');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.0.0-alpha.0",
3
+ "version": "10.0.0-alpha.11",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -10,41 +10,72 @@
10
10
  "url": "git+https://github.com/trpc/trpc.git",
11
11
  "directory": "packages/client"
12
12
  },
13
- "preconstruct": {
14
- "entrypoints": [
15
- "index.ts",
16
- "links/httpBatchLink.ts",
17
- "links/httpLink.ts",
18
- "links/loggerLink.ts",
19
- "links/splitLink.ts",
20
- "links/transformerLink.ts",
21
- "links/wsLink.ts",
22
- "rx/index.ts",
23
- "rx/operators/index.ts"
24
- ]
13
+ "main": "dist/index.js",
14
+ "module": "dist/index.mjs",
15
+ "typings": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.js",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./rx": {
23
+ "import": "./dist/rx.mjs",
24
+ "require": "./dist/rx.js",
25
+ "default": "./dist/rx.js"
26
+ },
27
+ "./links/httpBatchLink": {
28
+ "import": "./dist/links/httpBatchLink.mjs",
29
+ "require": "./dist/links/httpBatchLink.js",
30
+ "default": "./dist/links/httpBatchLink.js"
31
+ },
32
+ "./links/httpLink": {
33
+ "import": "./dist/links/httpLink.mjs",
34
+ "require": "./dist/links/httpLink.js",
35
+ "default": "./dist/links/httpLink.js"
36
+ },
37
+ "./links/loggerLink": {
38
+ "import": "./dist/links/loggerLink.mjs",
39
+ "require": "./dist/links/loggerLink.js",
40
+ "default": "./dist/links/loggerLink.js"
41
+ },
42
+ "./links/splitLink": {
43
+ "import": "./dist/links/splitLink.mjs",
44
+ "require": "./dist/links/splitLink.js",
45
+ "default": "./dist/links/splitLink.js"
46
+ },
47
+ "./links/transformerLink": {
48
+ "import": "./dist/links/transformerLink.mjs",
49
+ "require": "./dist/links/transformerLink.js",
50
+ "default": "./dist/links/transformerLink.js"
51
+ },
52
+ "./links/wsLink": {
53
+ "import": "./dist/links/wsLink.mjs",
54
+ "require": "./dist/links/wsLink.js",
55
+ "default": "./dist/links/wsLink.js"
56
+ }
25
57
  },
26
- "scripts": {},
27
- "main": "dist/trpc-client.cjs.js",
28
- "module": "dist/trpc-client.esm.js",
29
- "typings": "dist/trpc-client.cjs.d.ts",
30
58
  "files": [
31
59
  "README.md",
32
60
  "dist",
33
61
  "links",
34
- "src",
35
- "rx"
62
+ "src"
36
63
  ],
64
+ "scripts": {
65
+ "build": "rollup -c"
66
+ },
37
67
  "dependencies": {
38
- "@babel/runtime": "^7.9.0"
68
+ "@babel/runtime": "^7.9.0",
69
+ "rxjs": "^7.5.4"
39
70
  },
40
71
  "peerDependencies": {
41
- "@trpc/server": "10.0.0-alpha.0"
72
+ "@trpc/server": "10.0.0-alpha.11"
42
73
  },
43
74
  "devDependencies": {
44
- "@trpc/server": "10.0.0-alpha.0"
75
+ "@trpc/server": "10.0.0-alpha.11"
45
76
  },
46
77
  "publishConfig": {
47
78
  "access": "public"
48
79
  },
49
- "gitHead": "ec10cf19bd153946e9211a32e3e2b511e37e6325"
80
+ "gitHead": "a330502ab8d9aeb1f8f01d9a0711aab849d3a938"
50
81
  }
@@ -18,11 +18,8 @@ import {
18
18
  OperationLink,
19
19
  TRPCLink,
20
20
  } from '../links/types';
21
- import { UnsubscribeFn } from '../rx';
22
- import { inferObservableValue } from '../rx/observable';
23
- import { share } from '../rx/operators';
24
- import { Observer } from '../rx/types';
25
- import { observableToPromise } from '../rx/util/observableToPromise';
21
+ import { inferObservableValue, observableToPromise, share } from '../rx';
22
+ import { Observer, Subscription } from 'rxjs';
26
23
  import { TRPCClientError } from '../TRPCClientError';
27
24
  import { getAbortController } from './fetchHelpers';
28
25
 
@@ -216,16 +213,15 @@ export class TRPCClient<TRouter extends AnyRouter> {
216
213
  >(
217
214
  path: TPath,
218
215
  input: TInput,
219
- opts: TRPCRequestOptions &
220
- Partial<Observer<TRPCResult<TOutput>, TRPCClientError<TRouter>>>,
221
- ): UnsubscribeFn {
216
+ opts: TRPCRequestOptions & Partial<Observer<TRPCResult<TOutput>>>,
217
+ ): Subscription {
222
218
  const observable$ = this.$request<TInput, TOutput>({
223
219
  type: 'subscription',
224
220
  path,
225
221
  input,
226
222
  context: opts.context,
227
223
  });
228
- const observer = observable$.subscribe({
224
+ return observable$.subscribe({
229
225
  next(result) {
230
226
  if ('error' in result.data) {
231
227
  const err = TRPCClientError.from(result.data, {
@@ -244,8 +240,5 @@ export class TRPCClient<TRouter extends AnyRouter> {
244
240
  opts.complete?.();
245
241
  },
246
242
  });
247
- return () => {
248
- observer.unsubscribe();
249
- };
250
243
  }
251
244
  }
@@ -20,7 +20,10 @@ type BatchLoadFn<TKey, TValue> = (keys: TKey[]) => {
20
20
  * Less configuration, no caching, and allows you to cancel requests
21
21
  * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
22
22
  */
23
- export function dataLoader<TKey, TValue>(fetchMany: BatchLoadFn<TKey, TValue>) {
23
+ export function dataLoader<TKey, TValue>(
24
+ fetchMany: BatchLoadFn<TKey, TValue>,
25
+ opts?: { maxBatchSize?: number },
26
+ ) {
24
27
  let batch: Batch<TKey, TValue> | null = null;
25
28
  let dispatchTimer: NodeJS.Timer | number | null = null;
26
29
 
@@ -69,7 +72,16 @@ export function dataLoader<TKey, TValue>(fetchMany: BatchLoadFn<TKey, TValue>) {
69
72
  item.reject = reject;
70
73
  item.resolve = resolve;
71
74
  thisBatch.items.push(item);
75
+
76
+ if (
77
+ typeof opts?.maxBatchSize !== 'undefined' &&
78
+ thisBatch.items.length >= opts.maxBatchSize
79
+ ) {
80
+ dispatch();
81
+ return;
82
+ }
72
83
  });
84
+
73
85
  if (!dispatchTimer) {
74
86
  dispatchTimer = setTimeout(dispatch);
75
87
  }
@@ -1,7 +1,7 @@
1
1
  import { waitFor } from '@testing-library/dom';
2
2
  import { AnyRouter } from '@trpc/server';
3
3
  import { OperationLink } from '..';
4
- import { observable } from '../rx/observable';
4
+ import { Observable } from 'rxjs';
5
5
  import { dedupeLink } from './dedupeLink';
6
6
  import { createChain } from './internals/createChain';
7
7
 
@@ -12,7 +12,7 @@ test('dedupeLink', async () => {
12
12
  // "dedupe link"
13
13
  dedupeLink()(null as any),
14
14
  ({ op }) => {
15
- return observable((subscribe) => {
15
+ return new Observable((subscribe) => {
16
16
  endingLinkTriggered();
17
17
  const timer = setTimeout(() => {
18
18
  timerTriggered();
@@ -75,7 +75,7 @@ test('dedupe - cancel one does not cancel the other', async () => {
75
75
  // "dedupe link"
76
76
  dedupeLink()(null as any),
77
77
  ({ op }) => {
78
- return observable((subscribe) => {
78
+ return new Observable((subscribe) => {
79
79
  endingLinkTriggered();
80
80
  const timer = setTimeout(() => {
81
81
  timerTriggered();
@@ -1,8 +1,7 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
- import { observable } from '../rx/observable';
3
- import { share } from '../rx/operators';
4
- import { Observable } from '../rx/types';
5
- import { TRPCLink } from './types';
2
+ import { Observable } from 'rxjs';
3
+ import { share } from '../rx';
4
+ import { OperationResult, TRPCLink } from './types';
6
5
 
7
6
  export function dedupeLink<
8
7
  TRouter extends AnyRouter = AnyRouter,
@@ -10,7 +9,7 @@ export function dedupeLink<
10
9
  // initialized config
11
10
  return () => {
12
11
  // initialized in app
13
- const pending: Record<string, Observable<any, any>> = {};
12
+ const pending: Record<string, Observable<any>> = {};
14
13
  return ({ op, next }) => {
15
14
  // initialized for request
16
15
 
@@ -21,31 +20,31 @@ export function dedupeLink<
21
20
  const key = JSON.stringify([op.path, op.input]);
22
21
  if (pending[key]) {
23
22
  // console.log('hooking into pending', { op });
24
- return observable((observer) => pending[key].subscribe(observer));
23
+ return new Observable((observer) => pending[key].subscribe(observer));
25
24
  }
26
25
 
27
- const shared$ = observable((observer) => {
28
- function reset() {
29
- delete pending[key];
30
- }
31
- const next$ = next(op).subscribe({
32
- next(v) {
33
- observer.next(v);
34
- },
35
- error(e) {
26
+ const shared$ = new Observable<OperationResult<TRouter, unknown>>(
27
+ (observer) => {
28
+ function reset() {
29
+ delete pending[key];
30
+ }
31
+ const next$ = next(op).subscribe({
32
+ next(v) {
33
+ observer.next(v);
34
+ },
35
+ error(e) {
36
+ observer.error(e);
37
+ },
38
+ complete() {
39
+ observer.complete();
40
+ },
41
+ });
42
+ return () => {
36
43
  reset();
37
- observer.error(e);
38
- },
39
- complete() {
40
- reset();
41
- observer.complete();
42
- },
43
- });
44
- return () => {
45
- reset();
46
- next$.unsubscribe();
47
- };
48
- }).pipe(share());
44
+ next$.unsubscribe();
45
+ };
46
+ },
47
+ ).pipe(share());
49
48
  pending[key] = shared$;
50
49
  return shared$;
51
50
  };
@@ -1,15 +1,20 @@
1
1
  import { AnyRouter, ProcedureType } from '@trpc/server';
2
2
  import { dataLoader } from '../internals/dataLoader';
3
- import { observable } from '../rx/observable';
3
+ import { Observable } from 'rxjs';
4
4
  import { TRPCLink } from './types';
5
5
  import { HTTPLinkOptions, httpRequest, ResponseShape } from './httpUtils';
6
6
 
7
+ export interface HttpBatchLinkOptions extends HTTPLinkOptions {
8
+ maxBatchSize?: number;
9
+ }
7
10
  export function httpBatchLink<TRouter extends AnyRouter>(
8
- opts: HTTPLinkOptions,
11
+ opts: HttpBatchLinkOptions,
9
12
  ): TRPCLink<TRouter> {
10
13
  const { url } = opts;
14
+ // initialized config
11
15
  return (runtime) => {
12
16
  type Key = { id: number; path: string; input: unknown };
17
+
13
18
  const fetcher = (type: ProcedureType) => (keyInputPairs: Key[]) => {
14
19
  const path = keyInputPairs.map((op) => op.path).join(',');
15
20
  const inputs = keyInputPairs.map((op) => op.input);
@@ -38,15 +43,16 @@ export function httpBatchLink<TRouter extends AnyRouter>(
38
43
  cancel,
39
44
  };
40
45
  };
41
- const query = dataLoader<Key, ResponseShape>(fetcher('query'));
42
- const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'));
46
+ const query = dataLoader<Key, ResponseShape>(fetcher('query'), opts);
47
+ const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'), opts);
43
48
  const subscription = dataLoader<Key, ResponseShape>(
44
49
  fetcher('subscription'),
50
+ opts,
45
51
  );
46
52
 
47
53
  const loaders = { query, subscription, mutation };
48
54
  return ({ op }) => {
49
- return observable((observer) => {
55
+ return new Observable((observer) => {
50
56
  const loader = loaders[op.type];
51
57
  const { promise, cancel } = loader.load(op);
52
58
 
@@ -1,5 +1,5 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
- import { observable } from '../rx/observable';
2
+ import { Observable } from 'rxjs';
3
3
  import { TRPCLink } from './types';
4
4
  import { HTTPLinkOptions, httpRequest } from './httpUtils';
5
5
 
@@ -9,7 +9,7 @@ export function httpLink<TRouter extends AnyRouter>(
9
9
  const { url } = opts;
10
10
  return (runtime) =>
11
11
  ({ op }) =>
12
- observable((observer) => {
12
+ new Observable((observer) => {
13
13
  const { path, input, type } = op;
14
14
  const { promise, cancel } = httpRequest({
15
15
  runtime,
@@ -1,21 +1,21 @@
1
1
  import { AnyRouter } from '@trpc/server/src';
2
2
  import { createChain } from './createChain';
3
- import { observable } from '../../rx/observable';
3
+ import { Observable } from 'rxjs';
4
4
 
5
5
  describe('chain', () => {
6
6
  test('trivial', () => {
7
7
  const result$ = createChain<AnyRouter, unknown, unknown>({
8
8
  links: [
9
9
  ({ next, op }) => {
10
- return observable((observer) => {
11
- const next$ = next(op).subscribe(observer);
10
+ return new Observable((observer) => {
11
+ const subscription = next(op).subscribe(observer);
12
12
  return () => {
13
- next$.unsubscribe();
13
+ subscription.unsubscribe();
14
14
  };
15
15
  });
16
16
  },
17
17
  ({ op }) => {
18
- return observable((observer) => {
18
+ return new Observable((observer) => {
19
19
  observer.next({
20
20
  context: {},
21
21
  data: {
@@ -51,7 +51,7 @@ describe('chain', () => {
51
51
  const result$ = createChain<AnyRouter, unknown, unknown>({
52
52
  links: [
53
53
  ({ next, op }) => {
54
- return observable((observer) => {
54
+ return new Observable((observer) => {
55
55
  observer.next({
56
56
  context: {},
57
57
  data: {
@@ -69,7 +69,7 @@ describe('chain', () => {
69
69
  });
70
70
  },
71
71
  ({ op }) => {
72
- return observable((observer) => {
72
+ return new Observable((observer) => {
73
73
  observer.next({
74
74
  data: {
75
75
  id: null,
@@ -1,5 +1,5 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
- import { observable } from '../../rx/observable';
2
+ import { Observable } from 'rxjs';
3
3
  import { Operation, OperationLink, OperationResultObservable } from '../types';
4
4
 
5
5
  /** @internal */
@@ -11,7 +11,7 @@ export function createChain<
11
11
  links: OperationLink<TRouter, TInput, TOutput>[];
12
12
  op: Operation<TInput>;
13
13
  }): OperationResultObservable<TRouter, TOutput> {
14
- return observable((observer) => {
14
+ return new Observable((observer) => {
15
15
  function execute(index = 0, op = opts.op) {
16
16
  const next = opts.links[index];
17
17
  const next$ = next({
@@ -1,7 +1,6 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
2
  import { TRPCClientError } from '..';
3
- import { observable } from '../rx/observable';
4
- import { tap } from '../rx/operators';
3
+ import { Observable, tap } from 'rxjs';
5
4
  import { Operation, OperationResult, TRPCLink } from './types';
6
5
 
7
6
  type ConsoleEsque = {
@@ -108,7 +107,7 @@ export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
108
107
 
109
108
  return () => {
110
109
  return ({ op, next }) => {
111
- return observable((observer) => {
110
+ return new Observable((observer) => {
112
111
  // ->
113
112
  enabled({ ...op, direction: 'up' }) &&
114
113
  logger({