@trpc/client 10.0.0-alpha.25 → 10.0.0-alpha.28

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 (72) hide show
  1. package/dist/TRPCClientError.d.ts +2 -2
  2. package/dist/TRPCClientError.d.ts.map +1 -1
  3. package/dist/httpUtils-089853f6.mjs +99 -0
  4. package/dist/httpUtils-a0169eef.js +106 -0
  5. package/dist/index.js +63 -1031
  6. package/dist/index.mjs +55 -1015
  7. package/dist/internals/TRPCClient.d.ts +4 -2
  8. package/dist/internals/TRPCClient.d.ts.map +1 -1
  9. package/dist/links/httpBatchLink.js +317 -0
  10. package/dist/links/httpBatchLink.mjs +313 -0
  11. package/dist/links/httpBatchLink.ts.js +1 -0
  12. package/dist/links/httpLink.js +44 -0
  13. package/dist/links/httpLink.mjs +40 -0
  14. package/dist/links/httpLink.ts.js +1 -0
  15. package/dist/links/loggerLink.js +107 -0
  16. package/dist/links/loggerLink.mjs +98 -0
  17. package/dist/links/loggerLink.ts.js +1 -0
  18. package/dist/links/splitLink.js +10 -0
  19. package/dist/links/splitLink.mjs +2 -0
  20. package/dist/links/splitLink.ts.js +1 -0
  21. package/dist/links/types.d.ts +1 -1
  22. package/dist/links/types.d.ts.map +1 -1
  23. package/dist/links/wsLink.d.ts +2 -2
  24. package/dist/links/wsLink.d.ts.map +1 -1
  25. package/dist/links/wsLink.js +19 -0
  26. package/dist/links/wsLink.mjs +10 -0
  27. package/dist/links/wsLink.ts.js +1 -0
  28. package/dist/splitLink-62ff9db0.mjs +49 -0
  29. package/dist/splitLink-8202386e.js +52 -0
  30. package/dist/wsLink-69f5adb8.js +451 -0
  31. package/dist/wsLink-9468a563.mjs +436 -0
  32. package/links/httpBatchLink/index.d.ts +1 -0
  33. package/links/httpBatchLink/index.js +1 -0
  34. package/links/httpLink/index.d.ts +1 -0
  35. package/links/httpLink/index.js +1 -0
  36. package/links/loggerLink/index.d.ts +1 -0
  37. package/links/loggerLink/index.js +1 -0
  38. package/links/splitLink/index.d.ts +1 -0
  39. package/links/splitLink/index.js +1 -0
  40. package/links/wsLink/index.d.ts +1 -0
  41. package/links/wsLink/index.js +1 -0
  42. package/package.json +31 -5
  43. package/src/TRPCClientError.ts +2 -2
  44. package/src/internals/TRPCClient.ts +17 -0
  45. package/src/internals/dataLoader.ts +1 -1
  46. package/src/links/types.ts +1 -1
  47. package/src/links/wsLink.ts +2 -2
  48. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +0 -1
  49. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +0 -214
  50. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +0 -7
  51. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +0 -214
  52. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +0 -210
  53. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +0 -1
  54. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +0 -67
  55. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +0 -7
  56. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +0 -67
  57. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +0 -63
  58. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +0 -1
  59. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +0 -89
  60. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +0 -7
  61. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +0 -89
  62. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +0 -85
  63. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +0 -1
  64. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +0 -19
  65. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +0 -7
  66. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +0 -19
  67. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +0 -15
  68. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +0 -1
  69. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +0 -397
  70. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +0 -7
  71. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +0 -397
  72. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +0 -392
@@ -0,0 +1,436 @@
1
+ import _createClass from '@babel/runtime/helpers/createClass';
2
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
3
+ import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
4
+ import _inherits from '@babel/runtime/helpers/inherits';
5
+ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
6
+ import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
7
+ import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
8
+ import { observable } from '@trpc/server/observable';
9
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
10
+
11
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
12
+
13
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
14
+
15
+ function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
16
+
17
+ function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
+
19
+ var TRPCClientError = /*#__PURE__*/function (_Error) {
20
+ _inherits(TRPCClientError, _Error);
21
+
22
+ var _super = /*#__PURE__*/_createSuper$1(TRPCClientError);
23
+
24
+ function TRPCClientError(message, opts) {
25
+ var _opts$result, _opts$result2;
26
+
27
+ var _this;
28
+
29
+ _classCallCheck(this, TRPCClientError);
30
+
31
+ var cause = opts === null || opts === void 0 ? void 0 : opts.cause; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
+ // @ts-ignore https://github.com/tc39/proposal-error-cause
33
+
34
+ _this = _super.call(this, message, {
35
+ cause: cause
36
+ });
37
+ _this.cause = void 0;
38
+ _this.shape = void 0;
39
+ _this.data = void 0;
40
+ _this.meta = void 0;
41
+ _this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
42
+ _this.cause = cause;
43
+ _this.shape = opts === null || opts === void 0 ? void 0 : (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
44
+ _this.data = opts === null || opts === void 0 ? void 0 : (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
45
+ _this.name = 'TRPCClientError';
46
+ Object.setPrototypeOf(_assertThisInitialized(_this), TRPCClientError.prototype);
47
+ return _this;
48
+ }
49
+
50
+ _createClass(TRPCClientError, null, [{
51
+ key: "from",
52
+ value: function from(cause) {
53
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
54
+
55
+ if (!(cause instanceof Error)) {
56
+ var _message;
57
+
58
+ return new TRPCClientError((_message = cause.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread(_objectSpread({}, opts), {}, {
59
+ cause: undefined,
60
+ result: cause
61
+ }));
62
+ }
63
+
64
+ if (cause.name === 'TRPCClientError') {
65
+ return cause;
66
+ }
67
+
68
+ return new TRPCClientError(cause.message, _objectSpread(_objectSpread({}, opts), {}, {
69
+ cause: cause,
70
+ result: null
71
+ }));
72
+ }
73
+ }]);
74
+
75
+ return TRPCClientError;
76
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
77
+
78
+ /* istanbul ignore next */
79
+ var retryDelay = function retryDelay(attemptIndex) {
80
+ return attemptIndex === 0 ? 0 : Math.min(1000 * Math.pow(2, attemptIndex), 30000);
81
+ };
82
+
83
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
84
+
85
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
86
+ function createWSClient(opts) {
87
+ var url = opts.url,
88
+ _opts$WebSocket = opts.WebSocket,
89
+ WebSocketImpl = _opts$WebSocket === void 0 ? WebSocket : _opts$WebSocket,
90
+ _opts$retryDelayMs = opts.retryDelayMs,
91
+ retryDelayFn = _opts$retryDelayMs === void 0 ? retryDelay : _opts$retryDelayMs;
92
+ /* istanbul ignore next */
93
+
94
+ if (!WebSocketImpl) {
95
+ throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
96
+ }
97
+ /**
98
+ * outgoing messages buffer whilst not open
99
+ */
100
+
101
+
102
+ var outgoing = [];
103
+ /**
104
+ * pending outgoing requests that are awaiting callback
105
+ */
106
+
107
+ var pendingRequests = Object.create(null);
108
+ var connectAttempt = 0;
109
+ var dispatchTimer = null;
110
+ var connectTimer = null;
111
+ var activeConnection = createWS();
112
+ var state = 'connecting';
113
+ /**
114
+ * tries to send the list of messages
115
+ */
116
+
117
+ function dispatch() {
118
+ if (state !== 'open' || dispatchTimer) {
119
+ return;
120
+ }
121
+
122
+ dispatchTimer = setTimeout(function () {
123
+ dispatchTimer = null;
124
+
125
+ if (outgoing.length === 1) {
126
+ // single send
127
+ activeConnection.send(JSON.stringify(outgoing.pop()));
128
+ } else {
129
+ // batch send
130
+ activeConnection.send(JSON.stringify(outgoing));
131
+ } // clear
132
+
133
+
134
+ outgoing = [];
135
+ });
136
+ }
137
+
138
+ function tryReconnect() {
139
+ if (connectTimer || state === 'closed') {
140
+ return;
141
+ }
142
+
143
+ var timeout = retryDelayFn(connectAttempt++);
144
+ reconnectInMs(timeout);
145
+ }
146
+
147
+ function reconnect() {
148
+ state = 'connecting';
149
+ var oldConnection = activeConnection;
150
+ activeConnection = createWS();
151
+ closeIfNoPending(oldConnection);
152
+ }
153
+
154
+ function reconnectInMs(ms) {
155
+ if (connectTimer) {
156
+ return;
157
+ }
158
+
159
+ state = 'connecting';
160
+ connectTimer = setTimeout(reconnect, ms);
161
+ }
162
+
163
+ function closeIfNoPending(conn) {
164
+ // disconnect as soon as there are are no pending result
165
+ var hasPendingRequests = Object.values(pendingRequests).some(function (p) {
166
+ return p.ws === conn;
167
+ });
168
+
169
+ if (!hasPendingRequests) {
170
+ conn.close();
171
+ }
172
+ }
173
+
174
+ function resumeSubscriptionOnReconnect(req) {
175
+ if (outgoing.some(function (r) {
176
+ return r.id === req.op.id;
177
+ })) {
178
+ return;
179
+ }
180
+
181
+ request(req.op, req.callbacks);
182
+ }
183
+
184
+ function createWS() {
185
+ var conn = new WebSocketImpl(url);
186
+ clearTimeout(connectTimer);
187
+ connectTimer = null;
188
+ conn.addEventListener('open', function () {
189
+ /* istanbul ignore next */
190
+ if (conn !== activeConnection) {
191
+ return;
192
+ }
193
+
194
+ connectAttempt = 0;
195
+ state = 'open';
196
+ dispatch();
197
+ });
198
+ conn.addEventListener('error', function () {
199
+ if (conn === activeConnection) {
200
+ tryReconnect();
201
+ }
202
+ });
203
+
204
+ var handleIncomingRequest = function handleIncomingRequest(req) {
205
+ if (req.method === 'reconnect' && conn === activeConnection) {
206
+ reconnect(); // notify subscribers
207
+
208
+ for (var _i = 0, _Object$values = Object.values(pendingRequests); _i < _Object$values.length; _i++) {
209
+ var pendingReq = _Object$values[_i];
210
+
211
+ if (pendingReq.type === 'subscription') {
212
+ resumeSubscriptionOnReconnect(pendingReq);
213
+ }
214
+ }
215
+ }
216
+ };
217
+
218
+ var handleIncomingResponse = function handleIncomingResponse(data) {
219
+ var _req$callbacks$next, _req$callbacks;
220
+
221
+ var req = data.id !== null && pendingRequests[data.id];
222
+
223
+ if (!req) {
224
+ // do something?
225
+ return;
226
+ }
227
+
228
+ (_req$callbacks$next = (_req$callbacks = req.callbacks).next) === null || _req$callbacks$next === void 0 ? void 0 : _req$callbacks$next.call(_req$callbacks, {
229
+ data: data
230
+ });
231
+
232
+ if (req.ws !== activeConnection && conn === activeConnection) {
233
+ var oldWs = req.ws; // gracefully replace old connection with this
234
+
235
+ req.ws = activeConnection;
236
+ closeIfNoPending(oldWs);
237
+ }
238
+
239
+ if ('result' in data && data.result.type === 'stopped' && conn === activeConnection) {
240
+ req.callbacks.complete();
241
+ }
242
+ };
243
+
244
+ conn.addEventListener('message', function (_ref) {
245
+ var data = _ref.data;
246
+ var msg = JSON.parse(data);
247
+
248
+ if ('method' in msg) {
249
+ handleIncomingRequest(msg);
250
+ } else {
251
+ handleIncomingResponse(msg);
252
+ }
253
+
254
+ if (conn !== activeConnection || state === 'closed') {
255
+ // when receiving a message, we close old connection that has no pending requests
256
+ closeIfNoPending(conn);
257
+ }
258
+ });
259
+ conn.addEventListener('close', function () {
260
+ if (activeConnection === conn) {
261
+ // connection might have been replaced already
262
+ tryReconnect();
263
+ }
264
+
265
+ for (var key in pendingRequests) {
266
+ var _req$callbacks$error, _req$callbacks2;
267
+
268
+ var req = pendingRequests[key];
269
+
270
+ if (req.ws !== conn) {
271
+ continue;
272
+ }
273
+
274
+ (_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')));
275
+
276
+ if (req.type !== 'subscription') {
277
+ var _req$callbacks$comple, _req$callbacks3;
278
+
279
+ delete pendingRequests[key];
280
+ (_req$callbacks$comple = (_req$callbacks3 = req.callbacks).complete) === null || _req$callbacks$comple === void 0 ? void 0 : _req$callbacks$comple.call(_req$callbacks3);
281
+ } else if (state !== 'closed') {
282
+ // request restart of sub with next connection
283
+ resumeSubscriptionOnReconnect(req);
284
+ }
285
+ }
286
+ });
287
+ return conn;
288
+ }
289
+
290
+ function request(op, callbacks) {
291
+ var type = op.type,
292
+ input = op.input,
293
+ path = op.path,
294
+ id = op.id;
295
+ var envelope = {
296
+ id: id,
297
+ method: type,
298
+ params: {
299
+ input: input,
300
+ path: path
301
+ }
302
+ };
303
+ pendingRequests[id] = {
304
+ ws: activeConnection,
305
+ type: type,
306
+ callbacks: callbacks,
307
+ op: op
308
+ }; // enqueue message
309
+
310
+ outgoing.push(envelope);
311
+ dispatch();
312
+ return function () {
313
+ var _pendingRequests$id, _callbacks$complete;
314
+
315
+ var callbacks = (_pendingRequests$id = pendingRequests[id]) === null || _pendingRequests$id === void 0 ? void 0 : _pendingRequests$id.callbacks;
316
+ delete pendingRequests[id];
317
+ outgoing = outgoing.filter(function (msg) {
318
+ return msg.id !== id;
319
+ });
320
+ callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$complete = callbacks.complete) === null || _callbacks$complete === void 0 ? void 0 : _callbacks$complete.call(callbacks);
321
+
322
+ if (op.type === 'subscription') {
323
+ outgoing.push({
324
+ id: id,
325
+ method: 'subscription.stop'
326
+ });
327
+ dispatch();
328
+ }
329
+ };
330
+ }
331
+
332
+ return {
333
+ close: function close() {
334
+ state = 'closed';
335
+ closeIfNoPending(activeConnection);
336
+ clearTimeout(connectTimer);
337
+ connectTimer = null;
338
+ },
339
+ request: request,
340
+ getConnection: function getConnection() {
341
+ return activeConnection;
342
+ }
343
+ };
344
+ }
345
+
346
+ var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
347
+ _inherits(TRPCWebSocketClosedError, _Error);
348
+
349
+ var _super = /*#__PURE__*/_createSuper(TRPCWebSocketClosedError);
350
+
351
+ function TRPCWebSocketClosedError(message) {
352
+ var _this;
353
+
354
+ _classCallCheck(this, TRPCWebSocketClosedError);
355
+
356
+ _this = _super.call(this, message);
357
+ _this.name = 'TRPCWebSocketClosedError';
358
+ Object.setPrototypeOf(_assertThisInitialized(_this), TRPCWebSocketClosedError.prototype);
359
+ return _this;
360
+ }
361
+
362
+ return _createClass(TRPCWebSocketClosedError);
363
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
364
+
365
+ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
366
+ _inherits(TRPCSubscriptionEndedError, _Error2);
367
+
368
+ var _super2 = /*#__PURE__*/_createSuper(TRPCSubscriptionEndedError);
369
+
370
+ function TRPCSubscriptionEndedError(message) {
371
+ var _this2;
372
+
373
+ _classCallCheck(this, TRPCSubscriptionEndedError);
374
+
375
+ _this2 = _super2.call(this, message);
376
+ _this2.name = 'TRPCSubscriptionEndedError';
377
+ Object.setPrototypeOf(_assertThisInitialized(_this2), TRPCSubscriptionEndedError.prototype);
378
+ return _this2;
379
+ }
380
+
381
+ return _createClass(TRPCSubscriptionEndedError);
382
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
383
+
384
+ function wsLink(opts) {
385
+ return function (runtime) {
386
+ var client = opts.client;
387
+ return function (_ref2) {
388
+ var op = _ref2.op;
389
+ return observable(function (observer) {
390
+ var type = op.type,
391
+ path = op.path,
392
+ id = op.id,
393
+ context = op.context;
394
+ var input = runtime.transformer.serialize(op.input);
395
+ var isDone = false;
396
+ var unsub = client.request({
397
+ type: type,
398
+ path: path,
399
+ input: input,
400
+ id: id,
401
+ context: context
402
+ }, {
403
+ error: function error(err) {
404
+ isDone = true;
405
+ observer.error(err);
406
+ unsub();
407
+ },
408
+ complete: function complete() {
409
+ if (!isDone) {
410
+ isDone = true;
411
+ observer.error(TRPCClientError.from(new TRPCSubscriptionEndedError('Operation ended prematurely')));
412
+ } else {
413
+ observer.complete();
414
+ }
415
+ },
416
+ next: function next(result) {
417
+ observer.next(result);
418
+
419
+ if (op.type !== 'subscription') {
420
+ // if it isn't a subscription we don't care about next response
421
+ isDone = true;
422
+ unsub();
423
+ observer.complete();
424
+ }
425
+ }
426
+ });
427
+ return function () {
428
+ isDone = true;
429
+ unsub();
430
+ };
431
+ });
432
+ };
433
+ };
434
+ }
435
+
436
+ export { TRPCClientError as T, createWSClient as c, wsLink as w };
@@ -0,0 +1 @@
1
+ export * from '../../dist/./links/httpBatchLink';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/./links/httpBatchLink');
@@ -0,0 +1 @@
1
+ export * from '../../dist/./links/httpLink';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/./links/httpLink');
@@ -0,0 +1 @@
1
+ export * from '../../dist/./links/loggerLink';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/./links/loggerLink');
@@ -0,0 +1 @@
1
+ export * from '../../dist/./links/splitLink';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/./links/splitLink');
@@ -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.25",
3
+ "version": "10.0.0-alpha.28",
4
4
  "description": "tRPC Client lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -26,6 +26,31 @@
26
26
  "import": "./dist/index.mjs",
27
27
  "require": "./dist/index.js",
28
28
  "default": "./dist/index.js"
29
+ },
30
+ "./links/httpLink": {
31
+ "import": "./dist/links/httpLink.mjs",
32
+ "require": "./dist/links/httpLink.js",
33
+ "default": "./dist/links/httpLink.js"
34
+ },
35
+ "./links/httpBatchLink": {
36
+ "import": "./dist/links/httpBatchLink.mjs",
37
+ "require": "./dist/links/httpBatchLink.js",
38
+ "default": "./dist/links/httpBatchLink.js"
39
+ },
40
+ "./links/splitLink": {
41
+ "import": "./dist/links/splitLink.mjs",
42
+ "require": "./dist/links/splitLink.js",
43
+ "default": "./dist/links/splitLink.js"
44
+ },
45
+ "./links/loggerLink": {
46
+ "import": "./dist/links/loggerLink.mjs",
47
+ "require": "./dist/links/loggerLink.js",
48
+ "default": "./dist/links/loggerLink.js"
49
+ },
50
+ "./links/wsLink": {
51
+ "import": "./dist/links/wsLink.mjs",
52
+ "require": "./dist/links/wsLink.js",
53
+ "default": "./dist/links/wsLink.js"
29
54
  }
30
55
  },
31
56
  "files": [
@@ -35,19 +60,20 @@
35
60
  "src"
36
61
  ],
37
62
  "scripts": {
38
- "build": "rollup -c"
63
+ "build": "rollup -c",
64
+ "ts-watch": "tsc --project tsconfig.watch.json"
39
65
  },
40
66
  "dependencies": {
41
67
  "@babel/runtime": "^7.9.0"
42
68
  },
43
69
  "peerDependencies": {
44
- "@trpc/server": "10.0.0-alpha.25"
70
+ "@trpc/server": "10.0.0-alpha.28"
45
71
  },
46
72
  "devDependencies": {
47
- "@trpc/server": "10.0.0-alpha.25"
73
+ "@trpc/server": "10.0.0-alpha.28"
48
74
  },
49
75
  "publishConfig": {
50
76
  "access": "public"
51
77
  },
52
- "gitHead": "7f35cc8aaf813e5f83fe3d7b8f4bfd851779aa99"
78
+ "gitHead": "9252bd0df8523fc90b56bdd4228b8662ad507198"
53
79
  }
@@ -20,7 +20,7 @@ export class TRPCClientError<TRouter extends AnyRouter>
20
20
  message: string,
21
21
  opts?: {
22
22
  result: Maybe<TRPCErrorResponse<inferRouterError<TRouter>>>;
23
- cause?: Maybe<Error>;
23
+ cause?: Error;
24
24
  meta?: Record<string, unknown>;
25
25
  },
26
26
  ) {
@@ -47,7 +47,7 @@ export class TRPCClientError<TRouter extends AnyRouter>
47
47
  if (!(cause instanceof Error)) {
48
48
  return new TRPCClientError<TRouter>((cause.error as any).message ?? '', {
49
49
  ...opts,
50
- cause: null,
50
+ cause: undefined,
51
51
  result: cause,
52
52
  });
53
53
  }
@@ -61,6 +61,14 @@ interface CreateTRPCClientBaseOptions {
61
61
  transformer?: ClientDataTransformerOptions;
62
62
  }
63
63
 
64
+ function createRouterProxy(callback: (...args: [string, ...unknown[]]) => any) {
65
+ return new Proxy({} as any, {
66
+ get(_, path: string) {
67
+ return (...args: unknown[]) => callback(path, ...args);
68
+ },
69
+ });
70
+ }
71
+
64
72
  /** @internal */
65
73
  export interface CreateTRPCClientWithURLOptions
66
74
  extends CreateTRPCClientBaseOptions {
@@ -94,6 +102,8 @@ export type CreateTRPCClientOptions<TRouter extends AnyRouter> =
94
102
  export class TRPCClient<TRouter extends AnyRouter> {
95
103
  private readonly links: OperationLink<TRouter>[];
96
104
  public readonly runtime: TRPCClientRuntime;
105
+ public readonly queries: TRouter['queries'];
106
+ public readonly mutations: TRouter['mutations'];
97
107
 
98
108
  constructor(opts: CreateTRPCClientOptions<TRouter>) {
99
109
  const _fetch = getFetch(opts?.fetch);
@@ -135,6 +145,13 @@ export class TRPCClient<TRouter extends AnyRouter> {
135
145
  })(this.runtime),
136
146
  ];
137
147
  }
148
+
149
+ this.queries = createRouterProxy((path, ...args) =>
150
+ this.query(path, ...(args as any)),
151
+ );
152
+ this.mutations = createRouterProxy((path, ...args) =>
153
+ this.mutation(path, ...(args as any)),
154
+ );
138
155
  }
139
156
 
140
157
  private $request<TInput = unknown, TOutput = unknown>({
@@ -58,7 +58,7 @@ export function dataLoader<TKey, TValue>(
58
58
  // we're done
59
59
  break;
60
60
  }
61
- const lastGroup = groupedItems[groupedItems.length - 1];
61
+ const lastGroup = groupedItems[groupedItems.length - 1]!;
62
62
 
63
63
  if (item.aborted) {
64
64
  // Item was aborted before it was dispatched
@@ -16,7 +16,7 @@ export type Operation<TInput = unknown> = {
16
16
  type: 'query' | 'mutation' | 'subscription';
17
17
  input: TInput;
18
18
  path: string;
19
- context?: OperationContext;
19
+ context: OperationContext;
20
20
  };
21
21
 
22
22
  export type HTTPHeaders = Record<string, string | string[]>;
@@ -13,7 +13,7 @@ import { Operation, OperationResultObserver, TRPCLink } from './types';
13
13
 
14
14
  export interface WebSocketClientOptions {
15
15
  url: string;
16
- WebSocket?: WebSocket;
16
+ WebSocket?: typeof WebSocket;
17
17
  retryDelayMs?: typeof retryDelay;
18
18
  }
19
19
  export function createWSClient(opts: WebSocketClientOptions) {
@@ -112,7 +112,7 @@ export function createWSClient(opts: WebSocketClientOptions) {
112
112
  }
113
113
 
114
114
  function createWS() {
115
- const conn = new WebSocket(url);
115
+ const conn = new WebSocketImpl(url);
116
116
  clearTimeout(connectTimer as any);
117
117
  connectTimer = null;
118
118
 
@@ -1 +0,0 @@
1
- export * from "../../../dist/declarations/src/links/httpBatchLink";