@trpc/client 10.0.0-alpha.2 → 10.0.0-alpha.20
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.
- package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +21 -29
- package/dist/TRPCClientError.d.ts.map +1 -0
- package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -5
- package/dist/createTRPCClient.d.ts.map +1 -0
- package/dist/{declarations/src/getFetch.d.ts → getFetch.d.ts} +1 -1
- package/dist/getFetch.d.ts.map +1 -0
- package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1373 -0
- package/dist/index.mjs +1346 -0
- package/dist/index.ts.js +1 -0
- package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +56 -64
- package/dist/internals/TRPCClient.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +16 -14
- package/dist/internals/dataLoader.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/fetchHelpers.d.ts +2 -2
- package/dist/internals/fetchHelpers.d.ts.map +1 -0
- package/dist/{declarations/src/internals → internals}/retryDelay.d.ts +1 -1
- package/dist/internals/retryDelay.d.ts.map +1 -0
- package/dist/links/dedupeLink.d.ts +4 -0
- package/dist/links/dedupeLink.d.ts.map +1 -0
- package/dist/links/httpBatchLink.d.ts +8 -0
- package/dist/links/httpBatchLink.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -4
- package/dist/links/httpLink.d.ts.map +1 -0
- package/dist/links/index.d.ts +11 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/internals/createChain.d.ts +7 -7
- package/dist/links/internals/createChain.d.ts.map +1 -0
- package/dist/{declarations/src/links → links/internals}/httpUtils.d.ts +21 -21
- package/dist/links/internals/httpUtils.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/internals/transformOperationResult.d.ts +15 -15
- package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -38
- package/dist/links/loggerLink.d.ts.map +1 -0
- package/dist/links/retryLink.d.ts +6 -0
- package/dist/links/retryLink.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/splitLink.d.ts +13 -13
- package/dist/links/splitLink.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/transformerLink.d.ts +3 -3
- package/dist/links/transformerLink.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/types.d.ts +39 -39
- package/dist/links/types.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/wsLink.d.ts +19 -19
- package/dist/links/wsLink.d.ts.map +1 -0
- package/dist/observable/index.d.ts +4 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/{rx/operators/dist/trpc-client-rx-operators.cjs.dev.js → dist/observable/index.js} +3 -4
- package/{rx/operators/dist/trpc-client-rx-operators.esm.js → dist/observable/index.mjs} +1 -3
- package/dist/observable/index.ts.js +1 -0
- package/dist/{declarations/src/rx/util → observable/internals}/identity.d.ts +1 -1
- package/dist/observable/internals/identity.d.ts.map +1 -0
- package/dist/{declarations/src/rx/util → observable/internals}/observableToPromise.d.ts +9 -9
- package/dist/observable/internals/observableToPromise.d.ts.map +1 -0
- package/dist/{declarations/src/rx/util → observable/internals}/pipe.d.ts +3 -3
- package/dist/observable/internals/pipe.d.ts.map +1 -0
- package/dist/{declarations/src/rx → observable}/observable.d.ts +3 -3
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/{declarations/src/rx → observable}/operators/index.d.ts +3 -3
- package/dist/observable/operators/index.d.ts.map +1 -0
- package/dist/{declarations/src/rx → observable}/operators/map.d.ts +2 -2
- package/dist/observable/operators/map.d.ts.map +1 -0
- package/dist/{declarations/src/rx → observable}/operators/share.d.ts +5 -5
- package/dist/observable/operators/share.d.ts.map +1 -0
- package/dist/{declarations/src/rx → observable}/operators/tap.d.ts +2 -2
- package/dist/observable/operators/tap.d.ts.map +1 -0
- package/dist/{declarations/src/rx → observable}/types.d.ts +28 -28
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/tap-0dcdee86.js +243 -0
- package/dist/tap-136a9a90.mjs +239 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +68 -38
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +68 -38
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +67 -37
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +52 -29
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +52 -29
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +52 -29
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +19 -31
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +19 -31
- package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +19 -31
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +7 -20
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +7 -20
- package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +7 -20
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +84 -60
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +84 -60
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +84 -60
- package/{rx → observable}/dist/trpc-client-rx.cjs.d.ts +0 -0
- package/{rx → observable}/dist/trpc-client-rx.cjs.dev.js +0 -0
- package/{rx → observable}/dist/trpc-client-rx.cjs.js +0 -0
- package/{rx → observable}/dist/trpc-client-rx.cjs.prod.js +0 -0
- package/{rx → observable}/dist/trpc-client-rx.esm.js +0 -0
- package/observable/index.d.ts +1 -0
- package/observable/index.js +1 -0
- package/package.json +22 -21
- package/src/TRPCClientError.ts +3 -11
- package/src/createTRPCClient.ts +1 -1
- package/src/index.ts +1 -1
- package/src/internals/TRPCClient.ts +11 -19
- package/src/internals/dataLoader.ts +13 -1
- package/src/links/dedupeLink.test.ts +1 -1
- package/src/links/dedupeLink.ts +4 -5
- package/src/links/httpBatchLink.ts +15 -5
- package/src/links/httpLink.ts +2 -2
- package/src/links/index.ts +10 -0
- package/src/links/internals/createChain.test.ts +5 -5
- package/src/links/internals/createChain.ts +3 -3
- package/src/links/{httpUtils.ts → internals/httpUtils.ts} +2 -1
- package/src/links/loggerLink.ts +1 -2
- package/src/links/retryLink.ts +2 -2
- package/src/links/splitLink.test.ts +3 -3
- package/src/links/splitLink.ts +2 -2
- package/src/links/transformerLink.ts +9 -5
- package/src/links/types.ts +3 -3
- package/src/links/wsLink.ts +2 -3
- package/src/{rx → observable}/index.ts +1 -0
- package/src/{rx/util → observable/internals}/identity.ts +0 -0
- package/src/{rx/util → observable/internals}/observableToPromise.ts +0 -0
- package/src/{rx/util → observable/internals}/pipe.ts +1 -1
- package/src/{rx → observable}/observable.test.ts +22 -4
- package/src/{rx → observable}/observable.ts +1 -1
- package/src/{rx → observable}/operators/index.ts +0 -0
- package/src/{rx → observable}/operators/map.test.ts +2 -2
- package/src/{rx → observable}/operators/map.ts +0 -0
- package/src/{rx → observable}/operators/share.test.ts +0 -0
- package/src/{rx → observable}/operators/share.ts +0 -0
- package/src/{rx → observable}/operators/tap.ts +0 -0
- package/src/{rx → observable}/types.ts +0 -0
- package/dist/TRPCClientError-a5312a5f.cjs.dev.js +0 -74
- package/dist/TRPCClientError-e1da1ef0.esm.js +0 -72
- package/dist/TRPCClientError-ea7d89b2.cjs.prod.js +0 -74
- package/dist/createChain-93a38e1c.cjs.dev.js +0 -27
- package/dist/createChain-e45e052a.cjs.prod.js +0 -27
- package/dist/createChain-e45e6cf2.esm.js +0 -25
- package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
- package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
- package/dist/declarations/src/getFetch.d.ts.map +0 -1
- package/dist/declarations/src/index.d.ts.map +0 -1
- package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
- package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
- package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
- package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
- package/dist/declarations/src/links/httpBatchLink.d.ts +0 -5
- package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
- package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
- package/dist/declarations/src/links/httpUtils.d.ts.map +0 -1
- package/dist/declarations/src/links/internals/createChain.d.ts.map +0 -1
- package/dist/declarations/src/links/internals/transformOperationResult.d.ts.map +0 -1
- package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
- package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
- package/dist/declarations/src/links/transformerLink.d.ts.map +0 -1
- package/dist/declarations/src/links/types.d.ts.map +0 -1
- package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
- package/dist/declarations/src/rx/index.d.ts +0 -3
- package/dist/declarations/src/rx/index.d.ts.map +0 -1
- package/dist/declarations/src/rx/observable.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/index.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/map.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/share.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/tap.d.ts.map +0 -1
- package/dist/declarations/src/rx/types.d.ts.map +0 -1
- package/dist/declarations/src/rx/util/identity.d.ts.map +0 -1
- package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +0 -1
- package/dist/declarations/src/rx/util/pipe.d.ts.map +0 -1
- package/dist/httpUtils-299a66f6.cjs.prod.js +0 -89
- package/dist/httpUtils-a1426e14.cjs.dev.js +0 -89
- package/dist/httpUtils-e45c9056.esm.js +0 -87
- package/dist/observable-01534ea8.esm.js +0 -102
- package/dist/observable-9aad8c3e.cjs.dev.js +0 -104
- package/dist/observable-ccb54234.cjs.prod.js +0 -104
- package/dist/share-5a8c2543.cjs.prod.js +0 -106
- package/dist/share-ca585761.esm.js +0 -104
- package/dist/share-f2ac9332.cjs.dev.js +0 -106
- package/dist/tap-2d565250.cjs.dev.js +0 -32
- package/dist/tap-606957cb.esm.js +0 -30
- package/dist/tap-d907998d.cjs.prod.js +0 -32
- package/dist/trpc-client.cjs.d.ts +0 -1
- package/dist/trpc-client.cjs.dev.js +0 -300
- package/dist/trpc-client.cjs.js +0 -7
- package/dist/trpc-client.cjs.prod.js +0 -300
- package/dist/trpc-client.esm.js +0 -295
- package/links/httpBatchLink/package.json +0 -4
- package/links/httpLink/package.json +0 -4
- package/links/loggerLink/package.json +0 -4
- package/links/splitLink/package.json +0 -4
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
- package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
- package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
- package/links/transformerLink/package.json +0 -4
- package/links/wsLink/package.json +0 -4
- package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
- package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
- package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
- package/rx/operators/package.json +0 -4
- package/rx/package.json +0 -4
- package/src/internals/transformRPCResponse.ts +0 -25
|
@@ -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 {
|
|
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(
|
|
149
|
-
var _req$callbacks$
|
|
147
|
+
var handleIncomingResponse = function handleIncomingResponse(res) {
|
|
148
|
+
var _req$callbacks$onNext, _req$callbacks2;
|
|
150
149
|
|
|
151
|
-
var req =
|
|
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
|
-
|
|
159
|
-
|
|
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 (
|
|
170
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
213
|
+
var _req$callbacks$onDone2, _req$callbacks5;
|
|
208
214
|
|
|
209
215
|
delete pendingRequests[key];
|
|
210
|
-
(_req$callbacks$
|
|
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$
|
|
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$
|
|
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
|
-
|
|
321
|
+
// initialized config
|
|
322
|
+
return function (rt) {
|
|
316
323
|
var client = opts.client;
|
|
317
324
|
return function (_ref2) {
|
|
318
|
-
var op = _ref2.op
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
|
|
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
|
-
|
|
360
|
-
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
onDestroy(function () {
|
|
383
|
+
isDone = true;
|
|
384
|
+
unsub();
|
|
361
385
|
});
|
|
362
386
|
};
|
|
363
387
|
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/observable';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/observable/index');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.20",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,41 +10,42 @@
|
|
|
10
10
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
11
11
|
"directory": "packages/client"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
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
|
+
"./observable": {
|
|
23
|
+
"import": "./dist/observable/index.mjs",
|
|
24
|
+
"require": "./dist/observable/index.js",
|
|
25
|
+
"default": "./dist/observable/index.js"
|
|
26
|
+
}
|
|
25
27
|
},
|
|
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
28
|
"files": [
|
|
31
29
|
"README.md",
|
|
32
30
|
"dist",
|
|
33
31
|
"links",
|
|
34
32
|
"src",
|
|
35
|
-
"
|
|
33
|
+
"observable"
|
|
36
34
|
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "rollup -c"
|
|
37
|
+
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"@babel/runtime": "^7.9.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"@trpc/server": "10.0.0-alpha.
|
|
42
|
+
"@trpc/server": "10.0.0-alpha.20"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@trpc/server": "10.0.0-alpha.
|
|
45
|
+
"@trpc/server": "10.0.0-alpha.20"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
|
47
48
|
"access": "public"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b1d41d19a79b71045bf92dd6a5b8370a9f4f017c"
|
|
50
51
|
}
|
package/src/TRPCClientError.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRouter,
|
|
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
|
|
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 =
|
|
35
|
+
this.cause = cause;
|
|
44
36
|
this.shape = opts?.result?.error;
|
|
45
37
|
this.data = opts?.result?.error.data;
|
|
46
38
|
this.name = 'TRPCClientError';
|
package/src/createTRPCClient.ts
CHANGED
|
@@ -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
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
} from '@trpc/server';
|
|
8
8
|
import { TRPCResult } from '@trpc/server/rpc';
|
|
9
9
|
import { CancelFn } from '..';
|
|
10
|
+
import { TRPCClientError } from '../TRPCClientError';
|
|
10
11
|
import { getFetch } from '../getFetch';
|
|
11
|
-
import { httpBatchLink } from '../links
|
|
12
|
+
import { httpBatchLink } from '../links';
|
|
12
13
|
import { createChain } from '../links/internals/createChain';
|
|
13
14
|
import { transformOperationResult } from '../links/internals/transformOperationResult';
|
|
14
15
|
import {
|
|
@@ -18,25 +19,19 @@ import {
|
|
|
18
19
|
OperationLink,
|
|
19
20
|
TRPCLink,
|
|
20
21
|
} from '../links/types';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
import {
|
|
23
|
+
Observer,
|
|
24
|
+
Unsubscribable,
|
|
25
|
+
inferObservableValue,
|
|
26
|
+
share,
|
|
27
|
+
} from '../observable';
|
|
28
|
+
import { observableToPromise } from '../observable/internals/observableToPromise';
|
|
27
29
|
import { getAbortController } from './fetchHelpers';
|
|
28
30
|
|
|
29
31
|
type CancellablePromise<T = unknown> = Promise<T> & {
|
|
30
32
|
cancel: CancelFn;
|
|
31
33
|
};
|
|
32
34
|
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated no longer used
|
|
35
|
-
*/
|
|
36
|
-
export interface FetchOptions {
|
|
37
|
-
fetch?: typeof fetch;
|
|
38
|
-
AbortController?: typeof AbortController;
|
|
39
|
-
}
|
|
40
35
|
let idCounter = 0;
|
|
41
36
|
function getRequestId() {
|
|
42
37
|
return ++idCounter;
|
|
@@ -218,14 +213,14 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
218
213
|
input: TInput,
|
|
219
214
|
opts: TRPCRequestOptions &
|
|
220
215
|
Partial<Observer<TRPCResult<TOutput>, TRPCClientError<TRouter>>>,
|
|
221
|
-
):
|
|
216
|
+
): Unsubscribable {
|
|
222
217
|
const observable$ = this.$request<TInput, TOutput>({
|
|
223
218
|
type: 'subscription',
|
|
224
219
|
path,
|
|
225
220
|
input,
|
|
226
221
|
context: opts.context,
|
|
227
222
|
});
|
|
228
|
-
|
|
223
|
+
return observable$.subscribe({
|
|
229
224
|
next(result) {
|
|
230
225
|
if ('error' in result.data) {
|
|
231
226
|
const err = TRPCClientError.from(result.data, {
|
|
@@ -244,8 +239,5 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
244
239
|
opts.complete?.();
|
|
245
240
|
},
|
|
246
241
|
});
|
|
247
|
-
return () => {
|
|
248
|
-
observer.unsubscribe();
|
|
249
|
-
};
|
|
250
242
|
}
|
|
251
243
|
}
|
|
@@ -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>(
|
|
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 '../
|
|
4
|
+
import { observable } from '../observable';
|
|
5
5
|
import { dedupeLink } from './dedupeLink';
|
|
6
6
|
import { createChain } from './internals/createChain';
|
|
7
7
|
|
package/src/links/dedupeLink.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { observable } from '../
|
|
3
|
-
import {
|
|
4
|
-
import { Observable } from '../rx/types';
|
|
2
|
+
import { observable, share } from '../observable';
|
|
3
|
+
import { Observable } from '../observable/types';
|
|
5
4
|
import { TRPCLink } from './types';
|
|
6
5
|
|
|
7
6
|
export function dedupeLink<
|
|
@@ -28,7 +27,7 @@ export function dedupeLink<
|
|
|
28
27
|
function reset() {
|
|
29
28
|
delete pending[key];
|
|
30
29
|
}
|
|
31
|
-
const
|
|
30
|
+
const subscription = next(op).subscribe({
|
|
32
31
|
next(v) {
|
|
33
32
|
observer.next(v);
|
|
34
33
|
},
|
|
@@ -43,7 +42,7 @@ export function dedupeLink<
|
|
|
43
42
|
});
|
|
44
43
|
return () => {
|
|
45
44
|
reset();
|
|
46
|
-
|
|
45
|
+
subscription.unsubscribe();
|
|
47
46
|
};
|
|
48
47
|
}).pipe(share());
|
|
49
48
|
pending[key] = shared$;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { AnyRouter, ProcedureType } from '@trpc/server';
|
|
2
2
|
import { dataLoader } from '../internals/dataLoader';
|
|
3
|
-
import { observable } from '../
|
|
3
|
+
import { observable } from '../observable';
|
|
4
|
+
import {
|
|
5
|
+
HTTPLinkOptions,
|
|
6
|
+
ResponseShape,
|
|
7
|
+
httpRequest,
|
|
8
|
+
} from './internals/httpUtils';
|
|
4
9
|
import { TRPCLink } from './types';
|
|
5
|
-
import { HTTPLinkOptions, httpRequest, ResponseShape } from './httpUtils';
|
|
6
10
|
|
|
11
|
+
export interface HttpBatchLinkOptions extends HTTPLinkOptions {
|
|
12
|
+
maxBatchSize?: number;
|
|
13
|
+
}
|
|
7
14
|
export function httpBatchLink<TRouter extends AnyRouter>(
|
|
8
|
-
opts:
|
|
15
|
+
opts: HttpBatchLinkOptions,
|
|
9
16
|
): TRPCLink<TRouter> {
|
|
10
17
|
const { url } = opts;
|
|
18
|
+
// initialized config
|
|
11
19
|
return (runtime) => {
|
|
12
20
|
type Key = { id: number; path: string; input: unknown };
|
|
21
|
+
|
|
13
22
|
const fetcher = (type: ProcedureType) => (keyInputPairs: Key[]) => {
|
|
14
23
|
const path = keyInputPairs.map((op) => op.path).join(',');
|
|
15
24
|
const inputs = keyInputPairs.map((op) => op.input);
|
|
@@ -38,10 +47,11 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
38
47
|
cancel,
|
|
39
48
|
};
|
|
40
49
|
};
|
|
41
|
-
const query = dataLoader<Key, ResponseShape>(fetcher('query'));
|
|
42
|
-
const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'));
|
|
50
|
+
const query = dataLoader<Key, ResponseShape>(fetcher('query'), opts);
|
|
51
|
+
const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'), opts);
|
|
43
52
|
const subscription = dataLoader<Key, ResponseShape>(
|
|
44
53
|
fetcher('subscription'),
|
|
54
|
+
opts,
|
|
45
55
|
);
|
|
46
56
|
|
|
47
57
|
const loaders = { query, subscription, mutation };
|
package/src/links/httpLink.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { observable } from '../
|
|
2
|
+
import { observable } from '../observable';
|
|
3
|
+
import { HTTPLinkOptions, httpRequest } from './internals/httpUtils';
|
|
3
4
|
import { TRPCLink } from './types';
|
|
4
|
-
import { HTTPLinkOptions, httpRequest } from './httpUtils';
|
|
5
5
|
|
|
6
6
|
export function httpLink<TRouter extends AnyRouter>(
|
|
7
7
|
opts: HTTPLinkOptions,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './dedupeLink';
|
|
2
|
+
export * from './httpBatchLink';
|
|
3
|
+
export * from './httpLink';
|
|
4
|
+
export * from './loggerLink';
|
|
5
|
+
export * from './loggerLink';
|
|
6
|
+
export * from './retryLink';
|
|
7
|
+
export * from './splitLink';
|
|
8
|
+
export * from './transformerLink';
|
|
9
|
+
export * from './wsLink';
|
|
10
|
+
export * from './types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server/src';
|
|
2
|
+
import { observable } from '../../observable';
|
|
2
3
|
import { createChain } from './createChain';
|
|
3
|
-
import { observable } from '../../rx/observable';
|
|
4
4
|
|
|
5
5
|
describe('chain', () => {
|
|
6
6
|
test('trivial', () => {
|
|
@@ -8,9 +8,9 @@ describe('chain', () => {
|
|
|
8
8
|
links: [
|
|
9
9
|
({ next, op }) => {
|
|
10
10
|
return observable((observer) => {
|
|
11
|
-
const
|
|
11
|
+
const subscription = next(op).subscribe(observer);
|
|
12
12
|
return () => {
|
|
13
|
-
|
|
13
|
+
subscription.unsubscribe();
|
|
14
14
|
};
|
|
15
15
|
});
|
|
16
16
|
},
|
|
@@ -62,9 +62,9 @@ describe('chain', () => {
|
|
|
62
62
|
},
|
|
63
63
|
},
|
|
64
64
|
});
|
|
65
|
-
const
|
|
65
|
+
const subscription = next(op).subscribe(observer);
|
|
66
66
|
return () => {
|
|
67
|
-
|
|
67
|
+
subscription.unsubscribe();
|
|
68
68
|
};
|
|
69
69
|
});
|
|
70
70
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { observable } from '../../
|
|
2
|
+
import { observable } from '../../observable/observable';
|
|
3
3
|
import { Operation, OperationLink, OperationResultObservable } from '../types';
|
|
4
4
|
|
|
5
5
|
/** @internal */
|
|
@@ -14,7 +14,7 @@ export function createChain<
|
|
|
14
14
|
return observable((observer) => {
|
|
15
15
|
function execute(index = 0, op = opts.op) {
|
|
16
16
|
const next = opts.links[index];
|
|
17
|
-
const
|
|
17
|
+
const subscription = next({
|
|
18
18
|
op,
|
|
19
19
|
next(nextOp) {
|
|
20
20
|
const nextObserver = execute(index + 1, nextOp);
|
|
@@ -22,7 +22,7 @@ export function createChain<
|
|
|
22
22
|
return nextObserver;
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
|
-
return
|
|
25
|
+
return subscription;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const obs$ = execute();
|
package/src/links/loggerLink.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { TRPCClientError } from '..';
|
|
3
|
-
import { observable } from '../
|
|
4
|
-
import { tap } from '../rx/operators';
|
|
3
|
+
import { observable, tap } from '../observable';
|
|
5
4
|
import { Operation, OperationResult, TRPCLink } from './types';
|
|
6
5
|
|
|
7
6
|
type ConsoleEsque = {
|