@trpc/client 10.0.0-alpha.0 → 10.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{TRPCClientError-e1da1ef0.esm.js → TRPCClientError-17b117e1.mjs} +16 -7
- package/dist/TRPCClientError-ec6bd2ca.js +94 -0
- package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -29
- package/dist/TRPCClientError.d.ts.map +1 -0
- package/dist/{createChain-93a38e1c.cjs.dev.js → createChain-3b458753.js} +2 -2
- package/dist/{createChain-e45e6cf2.esm.js → createChain-b7cb1f5a.mjs} +2 -2
- 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/{httpUtils-a1426e14.cjs.dev.js → httpUtils-1f9e4e3c.js} +9 -1
- package/dist/{httpUtils-e45c9056.esm.js → httpUtils-c09d7b79.mjs} +5 -1
- package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/{trpc-client.cjs.dev.js → index.js} +23 -81
- package/dist/{trpc-client.esm.js → index.mjs} +16 -79
- package/dist/index.ts.js +1 -0
- package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +62 -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/links/httpBatchLink.js +195 -0
- package/dist/links/httpBatchLink.mjs +191 -0
- package/dist/links/httpBatchLink.ts.js +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/httpLink.js +44 -0
- package/dist/links/httpLink.mjs +40 -0
- package/dist/links/httpLink.ts.js +1 -0
- package/dist/{declarations/src/links → links}/httpUtils.d.ts +21 -21
- package/dist/links/httpUtils.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/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/loggerLink.js +107 -0
- package/dist/links/loggerLink.mjs +98 -0
- package/dist/links/loggerLink.ts.js +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/links/splitLink.js +32 -0
- package/dist/links/splitLink.mjs +28 -0
- package/dist/links/splitLink.ts.js +1 -0
- package/dist/{declarations/src/links → links}/transformerLink.d.ts +3 -3
- package/dist/links/transformerLink.d.ts.map +1 -0
- package/dist/links/transformerLink.js +79 -0
- package/dist/links/transformerLink.mjs +71 -0
- package/dist/links/transformerLink.ts.js +1 -0
- package/dist/{declarations/src/links → links}/types.d.ts +38 -39
- package/dist/links/types.d.ts.map +1 -0
- package/dist/{declarations/src/links → links}/wsLink.d.ts +20 -19
- package/dist/links/wsLink.d.ts.map +1 -0
- package/dist/links/wsLink.js +385 -0
- package/dist/links/wsLink.mjs +370 -0
- package/dist/links/wsLink.ts.js +1 -0
- package/dist/rx.d.ts +12 -0
- package/dist/rx.d.ts.map +1 -0
- package/dist/rx.js +130 -0
- package/dist/rx.mjs +114 -0
- package/dist/rx.ts.js +1 -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/httpBatchLink/index.d.ts +1 -0
- package/links/httpBatchLink/index.js +1 -0
- 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/httpLink/index.d.ts +1 -0
- package/links/httpLink/index.js +1 -0
- 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/loggerLink/index.d.ts +1 -0
- package/links/loggerLink/index.js +1 -0
- 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/splitLink/index.d.ts +1 -0
- package/links/splitLink/index.js +1 -0
- package/links/transformerLink/index.d.ts +1 -0
- package/links/transformerLink/index.js +1 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +85 -60
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +85 -60
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +85 -60
- package/links/wsLink/index.d.ts +1 -0
- package/links/wsLink/index.js +1 -0
- package/package.json +54 -23
- package/src/internals/TRPCClient.ts +5 -12
- package/src/internals/dataLoader.ts +13 -1
- package/src/links/dedupeLink.test.ts +3 -3
- package/src/links/dedupeLink.ts +26 -27
- package/src/links/httpBatchLink.ts +11 -5
- package/src/links/httpLink.ts +2 -2
- package/src/links/internals/createChain.test.ts +7 -7
- package/src/links/internals/createChain.ts +2 -2
- package/src/links/loggerLink.ts +2 -3
- package/src/links/retryLink.ts +2 -3
- package/src/links/splitLink.test.ts +3 -3
- package/src/links/splitLink.ts +2 -2
- package/src/links/transformerLink.ts +10 -6
- package/src/links/types.ts +3 -4
- package/src/links/wsLink.ts +5 -3
- package/src/rx.ts +82 -0
- package/dist/TRPCClientError-a5312a5f.cjs.dev.js +0 -74
- package/dist/TRPCClientError-ea7d89b2.cjs.prod.js +0 -74
- package/dist/createChain-e45e052a.cjs.prod.js +0 -27
- 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 +0 -4
- package/dist/declarations/src/rx/observable.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/index.d.ts +0 -4
- package/dist/declarations/src/rx/operators/index.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/map.d.ts +0 -3
- package/dist/declarations/src/rx/operators/map.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/share.d.ts +0 -6
- package/dist/declarations/src/rx/operators/share.d.ts.map +0 -1
- package/dist/declarations/src/rx/operators/tap.d.ts +0 -3
- package/dist/declarations/src/rx/operators/tap.d.ts.map +0 -1
- package/dist/declarations/src/rx/types.d.ts +0 -29
- package/dist/declarations/src/rx/types.d.ts.map +0 -1
- package/dist/declarations/src/rx/util/identity.d.ts +0 -2
- package/dist/declarations/src/rx/util/identity.d.ts.map +0 -1
- package/dist/declarations/src/rx/util/observableToPromise.d.ts +0 -10
- package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +0 -1
- package/dist/declarations/src/rx/util/pipe.d.ts +0 -4
- package/dist/declarations/src/rx/util/pipe.d.ts.map +0 -1
- package/dist/httpUtils-299a66f6.cjs.prod.js +0 -89
- 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.js +0 -7
- package/dist/trpc-client.cjs.prod.js +0 -300
- 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/package.json +0 -4
- package/links/wsLink/package.json +0 -4
- package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
- package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
- package/rx/dist/trpc-client-rx.cjs.js +0 -7
- package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
- package/rx/dist/trpc-client-rx.esm.js +0 -1
- package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
- package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
- 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/dist/trpc-client-rx-operators.esm.js +0 -33
- package/rx/operators/package.json +0 -4
- package/rx/package.json +0 -4
- package/src/internals/transformRPCResponse.ts +0 -25
- package/src/rx/index.ts +0 -2
- package/src/rx/observable.test.ts +0 -83
- package/src/rx/observable.ts +0 -70
- package/src/rx/operators/index.ts +0 -3
- package/src/rx/operators/map.test.ts +0 -92
- package/src/rx/operators/map.ts +0 -25
- package/src/rx/operators/share.test.ts +0 -60
- package/src/rx/operators/share.ts +0 -67
- package/src/rx/operators/tap.ts +0 -26
- package/src/rx/types.ts +0 -69
- package/src/rx/util/identity.ts +0 -3
- package/src/rx/util/observableToPromise.ts +0 -49
- package/src/rx/util/pipe.ts +0 -22
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
+
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
1
3
|
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
|
|
2
4
|
import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
|
|
3
5
|
import _inherits from '@babel/runtime/helpers/esm/inherits';
|
|
4
6
|
import _createSuper from '@babel/runtime/helpers/esm/createSuper';
|
|
5
7
|
import _wrapNativeSuper from '@babel/runtime/helpers/esm/wrapNativeSuper';
|
|
6
|
-
import {
|
|
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,55 +314,74 @@ var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
|
|
|
308
314
|
return _this2;
|
|
309
315
|
}
|
|
310
316
|
|
|
311
|
-
return TRPCSubscriptionEndedError;
|
|
317
|
+
return _createClass(TRPCSubscriptionEndedError);
|
|
312
318
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
313
319
|
|
|
314
320
|
function wsLink(opts) {
|
|
315
|
-
|
|
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
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
+
},
|
|
361
|
+
onError: function onError(err) {
|
|
362
|
+
if (isDone) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
prev(err instanceof Error ? err : TRPCClientError.from(_objectSpread(_objectSpread({}, err), {}, {
|
|
367
|
+
error: rt.transformer.deserialize(err.error)
|
|
368
|
+
})));
|
|
369
|
+
},
|
|
370
|
+
onDone: function onDone() {
|
|
371
|
+
if (isDone) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
var result = new TRPCSubscriptionEndedError('Operation ended prematurely');
|
|
376
|
+
prev(TRPCClientError.from(result, {
|
|
377
|
+
isDone: true
|
|
378
|
+
}));
|
|
379
|
+
isDone = true;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
onDestroy(function () {
|
|
383
|
+
isDone = true;
|
|
384
|
+
unsub();
|
|
360
385
|
});
|
|
361
386
|
};
|
|
362
387
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/links/wsLink';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/links/wsLink');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.11",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,41 +10,72 @@
|
|
|
10
10
|
"url": "git+https://github.com/trpc/trpc.git",
|
|
11
11
|
"directory": "packages/client"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"rx
|
|
24
|
-
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"module": "dist/index.mjs",
|
|
15
|
+
"typings": "dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.mjs",
|
|
19
|
+
"require": "./dist/index.js",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./rx": {
|
|
23
|
+
"import": "./dist/rx.mjs",
|
|
24
|
+
"require": "./dist/rx.js",
|
|
25
|
+
"default": "./dist/rx.js"
|
|
26
|
+
},
|
|
27
|
+
"./links/httpBatchLink": {
|
|
28
|
+
"import": "./dist/links/httpBatchLink.mjs",
|
|
29
|
+
"require": "./dist/links/httpBatchLink.js",
|
|
30
|
+
"default": "./dist/links/httpBatchLink.js"
|
|
31
|
+
},
|
|
32
|
+
"./links/httpLink": {
|
|
33
|
+
"import": "./dist/links/httpLink.mjs",
|
|
34
|
+
"require": "./dist/links/httpLink.js",
|
|
35
|
+
"default": "./dist/links/httpLink.js"
|
|
36
|
+
},
|
|
37
|
+
"./links/loggerLink": {
|
|
38
|
+
"import": "./dist/links/loggerLink.mjs",
|
|
39
|
+
"require": "./dist/links/loggerLink.js",
|
|
40
|
+
"default": "./dist/links/loggerLink.js"
|
|
41
|
+
},
|
|
42
|
+
"./links/splitLink": {
|
|
43
|
+
"import": "./dist/links/splitLink.mjs",
|
|
44
|
+
"require": "./dist/links/splitLink.js",
|
|
45
|
+
"default": "./dist/links/splitLink.js"
|
|
46
|
+
},
|
|
47
|
+
"./links/transformerLink": {
|
|
48
|
+
"import": "./dist/links/transformerLink.mjs",
|
|
49
|
+
"require": "./dist/links/transformerLink.js",
|
|
50
|
+
"default": "./dist/links/transformerLink.js"
|
|
51
|
+
},
|
|
52
|
+
"./links/wsLink": {
|
|
53
|
+
"import": "./dist/links/wsLink.mjs",
|
|
54
|
+
"require": "./dist/links/wsLink.js",
|
|
55
|
+
"default": "./dist/links/wsLink.js"
|
|
56
|
+
}
|
|
25
57
|
},
|
|
26
|
-
"scripts": {},
|
|
27
|
-
"main": "dist/trpc-client.cjs.js",
|
|
28
|
-
"module": "dist/trpc-client.esm.js",
|
|
29
|
-
"typings": "dist/trpc-client.cjs.d.ts",
|
|
30
58
|
"files": [
|
|
31
59
|
"README.md",
|
|
32
60
|
"dist",
|
|
33
61
|
"links",
|
|
34
|
-
"src"
|
|
35
|
-
"rx"
|
|
62
|
+
"src"
|
|
36
63
|
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "rollup -c"
|
|
66
|
+
},
|
|
37
67
|
"dependencies": {
|
|
38
|
-
"@babel/runtime": "^7.9.0"
|
|
68
|
+
"@babel/runtime": "^7.9.0",
|
|
69
|
+
"rxjs": "^7.5.4"
|
|
39
70
|
},
|
|
40
71
|
"peerDependencies": {
|
|
41
|
-
"@trpc/server": "10.0.0-alpha.
|
|
72
|
+
"@trpc/server": "10.0.0-alpha.11"
|
|
42
73
|
},
|
|
43
74
|
"devDependencies": {
|
|
44
|
-
"@trpc/server": "10.0.0-alpha.
|
|
75
|
+
"@trpc/server": "10.0.0-alpha.11"
|
|
45
76
|
},
|
|
46
77
|
"publishConfig": {
|
|
47
78
|
"access": "public"
|
|
48
79
|
},
|
|
49
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "a330502ab8d9aeb1f8f01d9a0711aab849d3a938"
|
|
50
81
|
}
|
|
@@ -18,11 +18,8 @@ import {
|
|
|
18
18
|
OperationLink,
|
|
19
19
|
TRPCLink,
|
|
20
20
|
} from '../links/types';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { share } from '../rx/operators';
|
|
24
|
-
import { Observer } from '../rx/types';
|
|
25
|
-
import { observableToPromise } from '../rx/util/observableToPromise';
|
|
21
|
+
import { inferObservableValue, observableToPromise, share } from '../rx';
|
|
22
|
+
import { Observer, Subscription } from 'rxjs';
|
|
26
23
|
import { TRPCClientError } from '../TRPCClientError';
|
|
27
24
|
import { getAbortController } from './fetchHelpers';
|
|
28
25
|
|
|
@@ -216,16 +213,15 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
216
213
|
>(
|
|
217
214
|
path: TPath,
|
|
218
215
|
input: TInput,
|
|
219
|
-
opts: TRPCRequestOptions &
|
|
220
|
-
|
|
221
|
-
): UnsubscribeFn {
|
|
216
|
+
opts: TRPCRequestOptions & Partial<Observer<TRPCResult<TOutput>>>,
|
|
217
|
+
): Subscription {
|
|
222
218
|
const observable$ = this.$request<TInput, TOutput>({
|
|
223
219
|
type: 'subscription',
|
|
224
220
|
path,
|
|
225
221
|
input,
|
|
226
222
|
context: opts.context,
|
|
227
223
|
});
|
|
228
|
-
|
|
224
|
+
return observable$.subscribe({
|
|
229
225
|
next(result) {
|
|
230
226
|
if ('error' in result.data) {
|
|
231
227
|
const err = TRPCClientError.from(result.data, {
|
|
@@ -244,8 +240,5 @@ export class TRPCClient<TRouter extends AnyRouter> {
|
|
|
244
240
|
opts.complete?.();
|
|
245
241
|
},
|
|
246
242
|
});
|
|
247
|
-
return () => {
|
|
248
|
-
observer.unsubscribe();
|
|
249
|
-
};
|
|
250
243
|
}
|
|
251
244
|
}
|
|
@@ -20,7 +20,10 @@ type BatchLoadFn<TKey, TValue> = (keys: TKey[]) => {
|
|
|
20
20
|
* Less configuration, no caching, and allows you to cancel requests
|
|
21
21
|
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
22
22
|
*/
|
|
23
|
-
export function dataLoader<TKey, TValue>(
|
|
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 {
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
5
|
import { dedupeLink } from './dedupeLink';
|
|
6
6
|
import { createChain } from './internals/createChain';
|
|
7
7
|
|
|
@@ -12,7 +12,7 @@ test('dedupeLink', async () => {
|
|
|
12
12
|
// "dedupe link"
|
|
13
13
|
dedupeLink()(null as any),
|
|
14
14
|
({ op }) => {
|
|
15
|
-
return
|
|
15
|
+
return new Observable((subscribe) => {
|
|
16
16
|
endingLinkTriggered();
|
|
17
17
|
const timer = setTimeout(() => {
|
|
18
18
|
timerTriggered();
|
|
@@ -75,7 +75,7 @@ test('dedupe - cancel one does not cancel the other', async () => {
|
|
|
75
75
|
// "dedupe link"
|
|
76
76
|
dedupeLink()(null as any),
|
|
77
77
|
({ op }) => {
|
|
78
|
-
return
|
|
78
|
+
return new Observable((subscribe) => {
|
|
79
79
|
endingLinkTriggered();
|
|
80
80
|
const timer = setTimeout(() => {
|
|
81
81
|
timerTriggered();
|
package/src/links/dedupeLink.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import {
|
|
3
|
-
import { share } from '../rx
|
|
4
|
-
import {
|
|
5
|
-
import { TRPCLink } from './types';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { share } from '../rx';
|
|
4
|
+
import { OperationResult, TRPCLink } from './types';
|
|
6
5
|
|
|
7
6
|
export function dedupeLink<
|
|
8
7
|
TRouter extends AnyRouter = AnyRouter,
|
|
@@ -10,7 +9,7 @@ export function dedupeLink<
|
|
|
10
9
|
// initialized config
|
|
11
10
|
return () => {
|
|
12
11
|
// initialized in app
|
|
13
|
-
const pending: Record<string, Observable<any
|
|
12
|
+
const pending: Record<string, Observable<any>> = {};
|
|
14
13
|
return ({ op, next }) => {
|
|
15
14
|
// initialized for request
|
|
16
15
|
|
|
@@ -21,31 +20,31 @@ export function dedupeLink<
|
|
|
21
20
|
const key = JSON.stringify([op.path, op.input]);
|
|
22
21
|
if (pending[key]) {
|
|
23
22
|
// console.log('hooking into pending', { op });
|
|
24
|
-
return
|
|
23
|
+
return new Observable((observer) => pending[key].subscribe(observer));
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
const shared$ =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
next(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const shared$ = new Observable<OperationResult<TRouter, unknown>>(
|
|
27
|
+
(observer) => {
|
|
28
|
+
function reset() {
|
|
29
|
+
delete pending[key];
|
|
30
|
+
}
|
|
31
|
+
const next$ = next(op).subscribe({
|
|
32
|
+
next(v) {
|
|
33
|
+
observer.next(v);
|
|
34
|
+
},
|
|
35
|
+
error(e) {
|
|
36
|
+
observer.error(e);
|
|
37
|
+
},
|
|
38
|
+
complete() {
|
|
39
|
+
observer.complete();
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
36
43
|
reset();
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
observer.complete();
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
return () => {
|
|
45
|
-
reset();
|
|
46
|
-
next$.unsubscribe();
|
|
47
|
-
};
|
|
48
|
-
}).pipe(share());
|
|
44
|
+
next$.unsubscribe();
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
).pipe(share());
|
|
49
48
|
pending[key] = shared$;
|
|
50
49
|
return shared$;
|
|
51
50
|
};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { AnyRouter, ProcedureType } from '@trpc/server';
|
|
2
2
|
import { dataLoader } from '../internals/dataLoader';
|
|
3
|
-
import {
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
4
|
import { TRPCLink } from './types';
|
|
5
5
|
import { HTTPLinkOptions, httpRequest, ResponseShape } from './httpUtils';
|
|
6
6
|
|
|
7
|
+
export interface HttpBatchLinkOptions extends HTTPLinkOptions {
|
|
8
|
+
maxBatchSize?: number;
|
|
9
|
+
}
|
|
7
10
|
export function httpBatchLink<TRouter extends AnyRouter>(
|
|
8
|
-
opts:
|
|
11
|
+
opts: HttpBatchLinkOptions,
|
|
9
12
|
): TRPCLink<TRouter> {
|
|
10
13
|
const { url } = opts;
|
|
14
|
+
// initialized config
|
|
11
15
|
return (runtime) => {
|
|
12
16
|
type Key = { id: number; path: string; input: unknown };
|
|
17
|
+
|
|
13
18
|
const fetcher = (type: ProcedureType) => (keyInputPairs: Key[]) => {
|
|
14
19
|
const path = keyInputPairs.map((op) => op.path).join(',');
|
|
15
20
|
const inputs = keyInputPairs.map((op) => op.input);
|
|
@@ -38,15 +43,16 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
38
43
|
cancel,
|
|
39
44
|
};
|
|
40
45
|
};
|
|
41
|
-
const query = dataLoader<Key, ResponseShape>(fetcher('query'));
|
|
42
|
-
const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'));
|
|
46
|
+
const query = dataLoader<Key, ResponseShape>(fetcher('query'), opts);
|
|
47
|
+
const mutation = dataLoader<Key, ResponseShape>(fetcher('mutation'), opts);
|
|
43
48
|
const subscription = dataLoader<Key, ResponseShape>(
|
|
44
49
|
fetcher('subscription'),
|
|
50
|
+
opts,
|
|
45
51
|
);
|
|
46
52
|
|
|
47
53
|
const loaders = { query, subscription, mutation };
|
|
48
54
|
return ({ op }) => {
|
|
49
|
-
return
|
|
55
|
+
return new Observable((observer) => {
|
|
50
56
|
const loader = loaders[op.type];
|
|
51
57
|
const { promise, cancel } = loader.load(op);
|
|
52
58
|
|
package/src/links/httpLink.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import {
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
3
|
import { TRPCLink } from './types';
|
|
4
4
|
import { HTTPLinkOptions, httpRequest } from './httpUtils';
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ export function httpLink<TRouter extends AnyRouter>(
|
|
|
9
9
|
const { url } = opts;
|
|
10
10
|
return (runtime) =>
|
|
11
11
|
({ op }) =>
|
|
12
|
-
|
|
12
|
+
new Observable((observer) => {
|
|
13
13
|
const { path, input, type } = op;
|
|
14
14
|
const { promise, cancel } = httpRequest({
|
|
15
15
|
runtime,
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server/src';
|
|
2
2
|
import { createChain } from './createChain';
|
|
3
|
-
import {
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
4
|
|
|
5
5
|
describe('chain', () => {
|
|
6
6
|
test('trivial', () => {
|
|
7
7
|
const result$ = createChain<AnyRouter, unknown, unknown>({
|
|
8
8
|
links: [
|
|
9
9
|
({ next, op }) => {
|
|
10
|
-
return
|
|
11
|
-
const
|
|
10
|
+
return new Observable((observer) => {
|
|
11
|
+
const subscription = next(op).subscribe(observer);
|
|
12
12
|
return () => {
|
|
13
|
-
|
|
13
|
+
subscription.unsubscribe();
|
|
14
14
|
};
|
|
15
15
|
});
|
|
16
16
|
},
|
|
17
17
|
({ op }) => {
|
|
18
|
-
return
|
|
18
|
+
return new Observable((observer) => {
|
|
19
19
|
observer.next({
|
|
20
20
|
context: {},
|
|
21
21
|
data: {
|
|
@@ -51,7 +51,7 @@ describe('chain', () => {
|
|
|
51
51
|
const result$ = createChain<AnyRouter, unknown, unknown>({
|
|
52
52
|
links: [
|
|
53
53
|
({ next, op }) => {
|
|
54
|
-
return
|
|
54
|
+
return new Observable((observer) => {
|
|
55
55
|
observer.next({
|
|
56
56
|
context: {},
|
|
57
57
|
data: {
|
|
@@ -69,7 +69,7 @@ describe('chain', () => {
|
|
|
69
69
|
});
|
|
70
70
|
},
|
|
71
71
|
({ op }) => {
|
|
72
|
-
return
|
|
72
|
+
return new Observable((observer) => {
|
|
73
73
|
observer.next({
|
|
74
74
|
data: {
|
|
75
75
|
id: null,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import {
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
3
|
import { Operation, OperationLink, OperationResultObservable } from '../types';
|
|
4
4
|
|
|
5
5
|
/** @internal */
|
|
@@ -11,7 +11,7 @@ export function createChain<
|
|
|
11
11
|
links: OperationLink<TRouter, TInput, TOutput>[];
|
|
12
12
|
op: Operation<TInput>;
|
|
13
13
|
}): OperationResultObservable<TRouter, TOutput> {
|
|
14
|
-
return
|
|
14
|
+
return new Observable((observer) => {
|
|
15
15
|
function execute(index = 0, op = opts.op) {
|
|
16
16
|
const next = opts.links[index];
|
|
17
17
|
const next$ = next({
|
package/src/links/loggerLink.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { TRPCClientError } from '..';
|
|
3
|
-
import {
|
|
4
|
-
import { tap } from '../rx/operators';
|
|
3
|
+
import { Observable, tap } from 'rxjs';
|
|
5
4
|
import { Operation, OperationResult, TRPCLink } from './types';
|
|
6
5
|
|
|
7
6
|
type ConsoleEsque = {
|
|
@@ -108,7 +107,7 @@ export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
|
|
|
108
107
|
|
|
109
108
|
return () => {
|
|
110
109
|
return ({ op, next }) => {
|
|
111
|
-
return
|
|
110
|
+
return new Observable((observer) => {
|
|
112
111
|
// ->
|
|
113
112
|
enabled({ ...op, direction: 'up' }) &&
|
|
114
113
|
logger({
|