@trpc/client 10.0.0-alpha.2 → 10.0.0-alpha.22

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 (183) hide show
  1. package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +21 -29
  2. package/dist/TRPCClientError.d.ts.map +1 -0
  3. package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -5
  4. package/dist/createTRPCClient.d.ts.map +1 -0
  5. package/dist/{declarations/src/getFetch.d.ts → getFetch.d.ts} +1 -1
  6. package/dist/getFetch.d.ts.map +1 -0
  7. package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +1417 -0
  10. package/dist/index.mjs +1391 -0
  11. package/dist/index.ts.js +1 -0
  12. package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +61 -64
  13. package/dist/internals/TRPCClient.d.ts.map +1 -0
  14. package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +17 -14
  15. package/dist/internals/dataLoader.d.ts.map +1 -0
  16. package/dist/{declarations/src/internals → internals}/fetchHelpers.d.ts +2 -2
  17. package/dist/internals/fetchHelpers.d.ts.map +1 -0
  18. package/dist/{declarations/src/internals → internals}/retryDelay.d.ts +1 -1
  19. package/dist/internals/retryDelay.d.ts.map +1 -0
  20. package/dist/links/dedupeLink.d.ts +4 -0
  21. package/dist/links/dedupeLink.d.ts.map +1 -0
  22. package/dist/links/httpBatchLink.d.ts +8 -0
  23. package/dist/links/httpBatchLink.d.ts.map +1 -0
  24. package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -4
  25. package/dist/links/httpLink.d.ts.map +1 -0
  26. package/dist/links/index.d.ts +9 -0
  27. package/dist/links/index.d.ts.map +1 -0
  28. package/dist/{declarations/src/links → links}/internals/createChain.d.ts +7 -7
  29. package/dist/links/internals/createChain.d.ts.map +1 -0
  30. package/dist/links/internals/httpUtils.d.ts +30 -0
  31. package/dist/links/internals/httpUtils.d.ts.map +1 -0
  32. package/dist/links/internals/transformOperationResult.d.ts +30 -0
  33. package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
  34. package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -38
  35. package/dist/links/loggerLink.d.ts.map +1 -0
  36. package/dist/links/retryLink.d.ts +6 -0
  37. package/dist/links/retryLink.d.ts.map +1 -0
  38. package/dist/{declarations/src/links → links}/splitLink.d.ts +13 -13
  39. package/dist/links/splitLink.d.ts.map +1 -0
  40. package/dist/{declarations/src/links → links}/types.d.ts +42 -39
  41. package/dist/links/types.d.ts.map +1 -0
  42. package/dist/{declarations/src/links → links}/wsLink.d.ts +19 -19
  43. package/dist/links/wsLink.d.ts.map +1 -0
  44. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +68 -38
  45. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +68 -38
  46. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +67 -37
  47. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +52 -29
  48. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +52 -29
  49. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +52 -29
  50. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +19 -31
  51. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +19 -31
  52. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +19 -31
  53. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +7 -20
  54. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +7 -20
  55. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +7 -20
  56. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +84 -60
  57. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +84 -60
  58. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +84 -60
  59. package/package.json +26 -23
  60. package/src/TRPCClientError.ts +3 -11
  61. package/src/createTRPCClient.ts +1 -1
  62. package/src/index.ts +1 -1
  63. package/src/internals/TRPCClient.ts +52 -36
  64. package/src/internals/dataLoader.ts +120 -45
  65. package/src/links/dedupeLink.test.ts +1 -1
  66. package/src/links/dedupeLink.ts +3 -5
  67. package/src/links/httpBatchLink.ts +64 -31
  68. package/src/links/httpLink.ts +4 -4
  69. package/src/links/index.ts +8 -0
  70. package/src/links/internals/createChain.test.ts +5 -5
  71. package/src/links/internals/createChain.ts +3 -3
  72. package/src/links/internals/httpUtils.ts +116 -0
  73. package/src/links/internals/transformOperationResult.ts +40 -12
  74. package/src/links/loggerLink.ts +1 -2
  75. package/src/links/retryLink.ts +1 -2
  76. package/src/links/splitLink.test.ts +3 -3
  77. package/src/links/splitLink.ts +5 -5
  78. package/src/links/types.ts +13 -8
  79. package/src/links/wsLink.ts +12 -12
  80. package/dist/TRPCClientError-a5312a5f.cjs.dev.js +0 -74
  81. package/dist/TRPCClientError-e1da1ef0.esm.js +0 -72
  82. package/dist/TRPCClientError-ea7d89b2.cjs.prod.js +0 -74
  83. package/dist/createChain-93a38e1c.cjs.dev.js +0 -27
  84. package/dist/createChain-e45e052a.cjs.prod.js +0 -27
  85. package/dist/createChain-e45e6cf2.esm.js +0 -25
  86. package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
  87. package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
  88. package/dist/declarations/src/getFetch.d.ts.map +0 -1
  89. package/dist/declarations/src/index.d.ts.map +0 -1
  90. package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
  91. package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
  92. package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
  93. package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
  94. package/dist/declarations/src/links/httpBatchLink.d.ts +0 -5
  95. package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
  96. package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
  97. package/dist/declarations/src/links/httpUtils.d.ts +0 -22
  98. package/dist/declarations/src/links/httpUtils.d.ts.map +0 -1
  99. package/dist/declarations/src/links/internals/createChain.d.ts.map +0 -1
  100. package/dist/declarations/src/links/internals/transformOperationResult.d.ts +0 -16
  101. package/dist/declarations/src/links/internals/transformOperationResult.d.ts.map +0 -1
  102. package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
  103. package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
  104. package/dist/declarations/src/links/transformerLink.d.ts +0 -4
  105. package/dist/declarations/src/links/transformerLink.d.ts.map +0 -1
  106. package/dist/declarations/src/links/types.d.ts.map +0 -1
  107. package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
  108. package/dist/declarations/src/rx/index.d.ts +0 -3
  109. package/dist/declarations/src/rx/index.d.ts.map +0 -1
  110. package/dist/declarations/src/rx/observable.d.ts +0 -4
  111. package/dist/declarations/src/rx/observable.d.ts.map +0 -1
  112. package/dist/declarations/src/rx/operators/index.d.ts +0 -4
  113. package/dist/declarations/src/rx/operators/index.d.ts.map +0 -1
  114. package/dist/declarations/src/rx/operators/map.d.ts +0 -3
  115. package/dist/declarations/src/rx/operators/map.d.ts.map +0 -1
  116. package/dist/declarations/src/rx/operators/share.d.ts +0 -6
  117. package/dist/declarations/src/rx/operators/share.d.ts.map +0 -1
  118. package/dist/declarations/src/rx/operators/tap.d.ts +0 -3
  119. package/dist/declarations/src/rx/operators/tap.d.ts.map +0 -1
  120. package/dist/declarations/src/rx/types.d.ts +0 -29
  121. package/dist/declarations/src/rx/types.d.ts.map +0 -1
  122. package/dist/declarations/src/rx/util/identity.d.ts +0 -2
  123. package/dist/declarations/src/rx/util/identity.d.ts.map +0 -1
  124. package/dist/declarations/src/rx/util/observableToPromise.d.ts +0 -10
  125. package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +0 -1
  126. package/dist/declarations/src/rx/util/pipe.d.ts +0 -4
  127. package/dist/declarations/src/rx/util/pipe.d.ts.map +0 -1
  128. package/dist/httpUtils-299a66f6.cjs.prod.js +0 -89
  129. package/dist/httpUtils-a1426e14.cjs.dev.js +0 -89
  130. package/dist/httpUtils-e45c9056.esm.js +0 -87
  131. package/dist/observable-01534ea8.esm.js +0 -102
  132. package/dist/observable-9aad8c3e.cjs.dev.js +0 -104
  133. package/dist/observable-ccb54234.cjs.prod.js +0 -104
  134. package/dist/share-5a8c2543.cjs.prod.js +0 -106
  135. package/dist/share-ca585761.esm.js +0 -104
  136. package/dist/share-f2ac9332.cjs.dev.js +0 -106
  137. package/dist/tap-2d565250.cjs.dev.js +0 -32
  138. package/dist/tap-606957cb.esm.js +0 -30
  139. package/dist/tap-d907998d.cjs.prod.js +0 -32
  140. package/dist/trpc-client.cjs.d.ts +0 -1
  141. package/dist/trpc-client.cjs.dev.js +0 -300
  142. package/dist/trpc-client.cjs.js +0 -7
  143. package/dist/trpc-client.cjs.prod.js +0 -300
  144. package/dist/trpc-client.esm.js +0 -295
  145. package/links/httpBatchLink/package.json +0 -4
  146. package/links/httpLink/package.json +0 -4
  147. package/links/loggerLink/package.json +0 -4
  148. package/links/splitLink/package.json +0 -4
  149. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
  150. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
  151. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
  152. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
  153. package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
  154. package/links/transformerLink/package.json +0 -4
  155. package/links/wsLink/package.json +0 -4
  156. package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
  157. package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
  158. package/rx/dist/trpc-client-rx.cjs.js +0 -7
  159. package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
  160. package/rx/dist/trpc-client-rx.esm.js +0 -1
  161. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
  162. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
  163. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
  164. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
  165. package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
  166. package/rx/operators/package.json +0 -4
  167. package/rx/package.json +0 -4
  168. package/src/internals/transformRPCResponse.ts +0 -25
  169. package/src/links/httpUtils.ts +0 -94
  170. package/src/links/transformerLink.ts +0 -70
  171. package/src/rx/index.ts +0 -2
  172. package/src/rx/observable.test.ts +0 -83
  173. package/src/rx/observable.ts +0 -70
  174. package/src/rx/operators/index.ts +0 -3
  175. package/src/rx/operators/map.test.ts +0 -92
  176. package/src/rx/operators/map.ts +0 -25
  177. package/src/rx/operators/share.test.ts +0 -60
  178. package/src/rx/operators/share.ts +0 -67
  179. package/src/rx/operators/tap.ts +0 -26
  180. package/src/rx/types.ts +0 -69
  181. package/src/rx/util/identity.ts +0 -3
  182. package/src/rx/util/observableToPromise.ts +0 -49
  183. package/src/rx/util/pipe.ts +0 -22
@@ -2,15 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
+ var _createClass = require('@babel/runtime/helpers/createClass');
5
7
  var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
6
8
  var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
7
9
  var _inherits = require('@babel/runtime/helpers/inherits');
8
10
  var _createSuper = require('@babel/runtime/helpers/createSuper');
9
11
  var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
10
- var observable = require('../../../dist/observable-ccb54234.cjs.prod.js');
11
- var TRPCClientError = require('../../../dist/TRPCClientError-ea7d89b2.cjs.prod.js');
12
- require('@babel/runtime/helpers/objectSpread2');
13
- require('@babel/runtime/helpers/createClass');
12
+ var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
14
13
 
15
14
  /* istanbul ignore next */
16
15
  var retryDelay = function retryDelay(attemptIndex) {
@@ -149,19 +148,24 @@ function createWSClient(opts) {
149
148
  }
150
149
  };
151
150
 
152
- var handleIncomingResponse = function handleIncomingResponse(data) {
153
- var _req$callbacks$next, _req$callbacks;
151
+ var handleIncomingResponse = function handleIncomingResponse(res) {
152
+ var _req$callbacks$onNext, _req$callbacks2;
154
153
 
155
- var req = data.id !== null && pendingRequests[data.id];
154
+ var req = res.id !== null && pendingRequests[res.id];
156
155
 
157
156
  if (!req) {
158
157
  // do something?
159
158
  return;
160
159
  }
161
160
 
162
- (_req$callbacks$next = (_req$callbacks = req.callbacks).next) === null || _req$callbacks$next === void 0 ? void 0 : _req$callbacks$next.call(_req$callbacks, {
163
- data: data
164
- });
161
+ if ('error' in res) {
162
+ var _req$callbacks$onErro, _req$callbacks;
163
+
164
+ (_req$callbacks$onErro = (_req$callbacks = req.callbacks).onError) === null || _req$callbacks$onErro === void 0 ? void 0 : _req$callbacks$onErro.call(_req$callbacks, res);
165
+ return;
166
+ }
167
+
168
+ (_req$callbacks$onNext = (_req$callbacks2 = req.callbacks).onNext) === null || _req$callbacks$onNext === void 0 ? void 0 : _req$callbacks$onNext.call(_req$callbacks2, res.result);
165
169
 
166
170
  if (req.ws !== activeConnection && conn === activeConnection) {
167
171
  var oldWs = req.ws; // gracefully replace old connection with this
@@ -170,8 +174,10 @@ function createWSClient(opts) {
170
174
  closeIfNoPending(oldWs);
171
175
  }
172
176
 
173
- if ('result' in data && data.result.type === 'stopped' && conn === activeConnection) {
174
- req.callbacks.complete();
177
+ if (res.result.type === 'stopped' && conn === activeConnection) {
178
+ var _req$callbacks$onDone, _req$callbacks3;
179
+
180
+ (_req$callbacks$onDone = (_req$callbacks3 = req.callbacks).onDone) === null || _req$callbacks$onDone === void 0 ? void 0 : _req$callbacks$onDone.call(_req$callbacks3);
175
181
  }
176
182
  };
177
183
 
@@ -197,7 +203,7 @@ function createWSClient(opts) {
197
203
  }
198
204
 
199
205
  for (var key in pendingRequests) {
200
- var _req$callbacks$error, _req$callbacks2;
206
+ var _req$callbacks$onErro2, _req$callbacks4;
201
207
 
202
208
  var req = pendingRequests[key];
203
209
 
@@ -205,13 +211,13 @@ function createWSClient(opts) {
205
211
  continue;
206
212
  }
207
213
 
208
- (_req$callbacks$error = (_req$callbacks2 = req.callbacks).error) === null || _req$callbacks$error === void 0 ? void 0 : _req$callbacks$error.call(_req$callbacks2, TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
214
+ (_req$callbacks$onErro2 = (_req$callbacks4 = req.callbacks).onError) === null || _req$callbacks$onErro2 === void 0 ? void 0 : _req$callbacks$onErro2.call(_req$callbacks4, TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError('WebSocket closed prematurely')));
209
215
 
210
216
  if (req.type !== 'subscription') {
211
- var _req$callbacks$comple, _req$callbacks3;
217
+ var _req$callbacks$onDone2, _req$callbacks5;
212
218
 
213
219
  delete pendingRequests[key];
214
- (_req$callbacks$comple = (_req$callbacks3 = req.callbacks).complete) === null || _req$callbacks$comple === void 0 ? void 0 : _req$callbacks$comple.call(_req$callbacks3);
220
+ (_req$callbacks$onDone2 = (_req$callbacks5 = req.callbacks).onDone) === null || _req$callbacks$onDone2 === void 0 ? void 0 : _req$callbacks$onDone2.call(_req$callbacks5);
215
221
  } else if (state !== 'closed') {
216
222
  // request restart of sub with next connection
217
223
  resumeSubscriptionOnReconnect(req);
@@ -245,14 +251,14 @@ function createWSClient(opts) {
245
251
  outgoing.push(envelope);
246
252
  dispatch();
247
253
  return function () {
248
- var _pendingRequests$id, _callbacks$complete;
254
+ var _pendingRequests$id, _callbacks$onDone;
249
255
 
250
256
  var callbacks = (_pendingRequests$id = pendingRequests[id]) === null || _pendingRequests$id === void 0 ? void 0 : _pendingRequests$id.callbacks;
251
257
  delete pendingRequests[id];
252
258
  outgoing = outgoing.filter(function (msg) {
253
259
  return msg.id !== id;
254
260
  });
255
- callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$complete = callbacks.complete) === null || _callbacks$complete === void 0 ? void 0 : _callbacks$complete.call(callbacks);
261
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onDone = callbacks.onDone) === null || _callbacks$onDone === void 0 ? void 0 : _callbacks$onDone.call(callbacks);
256
262
 
257
263
  if (op.type === 'subscription') {
258
264
  outgoing.push({
@@ -293,7 +299,7 @@ var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
293
299
  return _this;
294
300
  }
295
301
 
296
- return TRPCWebSocketClosedError;
302
+ return _createClass(TRPCWebSocketClosedError);
297
303
  }( /*#__PURE__*/_wrapNativeSuper(Error));
298
304
 
299
305
  var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
@@ -312,56 +318,74 @@ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
312
318
  return _this2;
313
319
  }
314
320
 
315
- return TRPCSubscriptionEndedError;
321
+ return _createClass(TRPCSubscriptionEndedError);
316
322
  }( /*#__PURE__*/_wrapNativeSuper(Error));
317
323
 
318
324
  function wsLink(opts) {
319
- return function () {
325
+ // initialized config
326
+ return function (rt) {
320
327
  var client = opts.client;
321
328
  return function (_ref2) {
322
- var op = _ref2.op;
323
- return observable.observable(function (observer) {
324
- var type = op.type,
325
- input = op.input,
326
- path = op.path,
327
- id = op.id,
328
- context = op.context;
329
- var isDone = false;
330
- var unsub = client.request({
331
- type: type,
332
- path: path,
333
- input: input,
334
- id: id,
335
- context: context
336
- }, {
337
- error: function error(err) {
329
+ var op = _ref2.op,
330
+ prev = _ref2.prev,
331
+ onDestroy = _ref2.onDestroy;
332
+ var type = op.type,
333
+ rawInput = op.input,
334
+ path = op.path,
335
+ id = op.id;
336
+ var input = rt.transformer.serialize(rawInput);
337
+ var isDone = false;
338
+ var unsub = client.request({
339
+ type: type,
340
+ path: path,
341
+ input: input,
342
+ id: id
343
+ }, {
344
+ onNext: function onNext(result) {
345
+ if (isDone) {
346
+ return;
347
+ }
348
+
349
+ if ('data' in result) {
350
+ var data = rt.transformer.deserialize(result.data);
351
+ prev({
352
+ type: 'data',
353
+ data: data
354
+ });
355
+ } else {
356
+ prev(result);
357
+ }
358
+
359
+ if (op.type !== 'subscription') {
360
+ // if it isn't a subscription we don't care about next response
338
361
  isDone = true;
339
- observer.error(err);
340
362
  unsub();
341
- },
342
- complete: function complete() {
343
- if (!isDone) {
344
- isDone = true;
345
- observer.error(TRPCClientError.TRPCClientError.from(new TRPCSubscriptionEndedError('Operation ended prematurely')));
346
- } else {
347
- observer.complete();
348
- }
349
- },
350
- next: function next(result) {
351
- observer.next(result);
352
-
353
- if (op.type !== 'subscription') {
354
- // if it isn't a subscription we don't care about next response
355
- isDone = true;
356
- unsub();
357
- observer.complete();
358
- }
359
363
  }
360
- });
361
- return function () {
364
+ },
365
+ onError: function onError(err) {
366
+ if (isDone) {
367
+ return;
368
+ }
369
+
370
+ prev(err instanceof Error ? err : TRPCClientError.TRPCClientError.from(_objectSpread(_objectSpread({}, err), {}, {
371
+ error: rt.transformer.deserialize(err.error)
372
+ })));
373
+ },
374
+ onDone: function onDone() {
375
+ if (isDone) {
376
+ return;
377
+ }
378
+
379
+ var result = new TRPCSubscriptionEndedError('Operation ended prematurely');
380
+ prev(TRPCClientError.TRPCClientError.from(result, {
381
+ isDone: true
382
+ }));
362
383
  isDone = true;
363
- unsub();
364
- };
384
+ }
385
+ });
386
+ onDestroy(function () {
387
+ isDone = true;
388
+ unsub();
365
389
  });
366
390
  };
367
391
  };
@@ -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,56 +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 () {
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
+ }));
358
379
  isDone = true;
359
- unsub();
360
- };
380
+ }
381
+ });
382
+ onDestroy(function () {
383
+ isDone = true;
384
+ unsub();
361
385
  });
362
386
  };
363
387
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/client",
3
- "version": "10.0.0-alpha.2",
3
+ "version": "10.0.0-alpha.22",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -10,41 +10,44 @@
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
- ]
25
- },
26
- "scripts": {},
27
- "main": "dist/trpc-client.cjs.js",
28
- "module": "dist/trpc-client.esm.js",
29
- "typings": "dist/trpc-client.cjs.d.ts",
13
+ "eslintConfig": {
14
+ "rules": {
15
+ "no-restricted-imports": [
16
+ "error",
17
+ "@trpc/client"
18
+ ]
19
+ }
20
+ },
21
+ "main": "dist/index.js",
22
+ "module": "dist/index.mjs",
23
+ "typings": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.mjs",
27
+ "require": "./dist/index.js",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
30
31
  "files": [
31
32
  "README.md",
32
33
  "dist",
33
34
  "links",
34
- "src",
35
- "rx"
35
+ "src"
36
36
  ],
37
+ "scripts": {
38
+ "build": "rollup -c"
39
+ },
37
40
  "dependencies": {
38
41
  "@babel/runtime": "^7.9.0"
39
42
  },
40
43
  "peerDependencies": {
41
- "@trpc/server": "10.0.0-alpha.2"
44
+ "@trpc/server": "10.0.0-alpha.22"
42
45
  },
43
46
  "devDependencies": {
44
- "@trpc/server": "10.0.0-alpha.2"
47
+ "@trpc/server": "10.0.0-alpha.22"
45
48
  },
46
49
  "publishConfig": {
47
50
  "access": "public"
48
51
  },
49
- "gitHead": "4d72f1922cfb8a74e2bb03a29b39903418312728"
52
+ "gitHead": "d720eb2215f0fad6e70f4172a1bf084225d4d6de"
50
53
  }
@@ -1,4 +1,4 @@
1
- import { AnyRouter, inferRouterError, Maybe } from '@trpc/server';
1
+ import { AnyRouter, Maybe, inferRouterError } from '@trpc/server';
2
2
  import { TRPCErrorResponse } from '@trpc/server/rpc';
3
3
 
4
4
  export interface TRPCClientErrorLike<TRouter extends AnyRouter> {
@@ -11,10 +11,6 @@ export class TRPCClientError<TRouter extends AnyRouter>
11
11
  extends Error
12
12
  implements TRPCClientErrorLike<TRouter>
13
13
  {
14
- /**
15
- * @deprecated use `cause`
16
- */
17
- public readonly originalError;
18
14
  public readonly cause;
19
15
  public readonly shape: Maybe<inferRouterError<TRouter>>;
20
16
  public readonly data: Maybe<inferRouterError<TRouter>['data']>;
@@ -24,15 +20,11 @@ export class TRPCClientError<TRouter extends AnyRouter>
24
20
  message: string,
25
21
  opts?: {
26
22
  result: Maybe<TRPCErrorResponse<inferRouterError<TRouter>>>;
27
- /**
28
- * @deprecated use `cause`
29
- **/
30
- originalError?: Maybe<Error>;
31
23
  cause?: Maybe<Error>;
32
24
  meta?: Record<string, unknown>;
33
25
  },
34
26
  ) {
35
- const cause = opts?.cause ?? opts?.originalError;
27
+ const cause = opts?.cause;
36
28
 
37
29
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
38
30
  // @ts-ignore https://github.com/tc39/proposal-error-cause
@@ -40,7 +32,7 @@ export class TRPCClientError<TRouter extends AnyRouter>
40
32
 
41
33
  this.meta = opts?.meta;
42
34
 
43
- this.cause = this.originalError = cause;
35
+ this.cause = cause;
44
36
  this.shape = opts?.result?.error;
45
37
  this.data = opts?.result?.error.data;
46
38
  this.name = 'TRPCClientError';
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import type { AnyRouter } from '@trpc/server';
3
3
  import {
4
- CreateTRPCClientOptions,
5
4
  TRPCClient as Client,
5
+ CreateTRPCClientOptions,
6
6
  } from './internals/TRPCClient';
7
7
 
8
8
  export function createTRPCClient<TRouter extends AnyRouter>(
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './createTRPCClient';
2
2
  export * from './getFetch';
3
- export * from './links/types';
4
3
  export * from './TRPCClientError';
4
+ export * from './links';