@trpc/client 10.0.0-alpha.29 → 10.0.0-alpha.31
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/createTRPCClient.d.ts +1 -1
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClientProxy.d.ts +8 -0
- package/dist/createTRPCClientProxy.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -40
- package/dist/index.mjs +57 -41
- package/dist/internals/TRPCClient.d.ts +3 -5
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +1 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +280 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +7 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +280 -0
- package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +272 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +1 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +134 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +7 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +134 -0
- package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +126 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +1 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +89 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +7 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +89 -0
- package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +85 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +1 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +19 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +7 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +19 -0
- package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +15 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +1 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +397 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +7 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +397 -0
- package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +392 -0
- package/package.json +4 -4
- package/src/createTRPCClient.ts +7 -1
- package/src/createTRPCClientProxy.ts +56 -0
- package/src/index.ts +1 -0
- package/src/internals/TRPCClient.ts +0 -17
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { TRPCClient as Client, CreateTRPCClientOptions } from './internals/TRPCClient';
|
|
3
|
-
export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter
|
|
3
|
+
export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter> & (TRouter["_def"]["record"] extends infer T ? { [Key in keyof T]: TRouter["_def"]["record"][Key] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"] extends infer T_1 ? { [Key_1 in keyof T_1]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"] extends infer T_2 ? { [Key_2 in keyof T_2]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"] extends infer T_3 ? { [Key_3 in keyof T_3]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"] extends infer T_4 ? { [Key_4 in keyof T_4]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"] extends infer T_5 ? { [Key_5 in keyof T_5]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"] extends infer T_6 ? { [Key_6 in keyof T_6]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"] extends infer T_7 ? { [Key_7 in keyof T_7]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"] extends infer T_8 ? { [Key_8 in keyof T_8]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"] extends infer T_9 ? { [Key_9 in keyof T_9]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9] extends AnyRouter ? TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]["_def"]["record"] extends infer T_10 ? { [Key_10 in keyof T_10]: TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]["_def"]["record"][Key_10] extends AnyRouter ? any : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]["_def"]["record"][Key_10]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]["_def"]["record"][Key_9]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]["_def"]["record"][Key_8]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]["_def"]["record"][Key_7]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]["_def"]["record"][Key_6]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]["_def"]["record"][Key_5]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]["_def"]["record"][Key_4]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]["_def"]["record"][Key_3]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]["_def"]["record"][Key_2]; } : never : TRouter["_def"]["record"][Key]["_def"]["record"][Key_1]; } : never : TRouter["_def"]["record"][Key]; } : never);
|
|
4
4
|
export type { TRPCRequestOptions, CreateTRPCClientOptions, TRPCClient, } from './internals/TRPCClient';
|
|
5
5
|
//# sourceMappingURL=createTRPCClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EACL,UAAU,IAAI,MAAM,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,0zLAIvC;AAID,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,GACX,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AnyRouter } from '@trpc/server';
|
|
2
|
+
import { TRPCClient as Client } from './internals/TRPCClient';
|
|
3
|
+
declare type FlattenRouter<TRouter extends AnyRouter> = {
|
|
4
|
+
[Key in keyof TRouter['_def']['record']]: TRouter['_def']['record'][Key] extends AnyRouter ? FlattenRouter<TRouter['_def']['record'][Key]> : TRouter['_def']['record'][Key];
|
|
5
|
+
};
|
|
6
|
+
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): Client<TRouter> & FlattenRouter<TRouter>;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=createTRPCClientProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAE9D,aAAK,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;KAC7C,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,SAAS,SAAS,GACtF,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAC7C,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC;CACnC,CAAC;AAyCF,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,4CAGxB"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,54 @@ var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallChec
|
|
|
27
27
|
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
28
28
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
29
29
|
|
|
30
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
31
|
+
|
|
32
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
33
|
+
function makeProxy(client) {
|
|
34
|
+
for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
35
|
+
path[_key - 1] = arguments[_key];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var proxy = new Proxy(function () {// noop
|
|
39
|
+
}, {
|
|
40
|
+
get: function get(_obj, name) {
|
|
41
|
+
if (name in client && !path.length) {
|
|
42
|
+
return client[name];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeof name === 'string') {
|
|
46
|
+
return makeProxy.apply(void 0, [client].concat(path, [name]));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return client;
|
|
50
|
+
},
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
|
+
apply: function apply(_1, _2, args) {
|
|
53
|
+
var _ref;
|
|
54
|
+
|
|
55
|
+
var pathCopy = [].concat(path);
|
|
56
|
+
var type = pathCopy.pop();
|
|
57
|
+
|
|
58
|
+
if (type === 'mutate') {
|
|
59
|
+
type = 'mutation';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var fullPath = pathCopy.join('.');
|
|
63
|
+
|
|
64
|
+
if (type.startsWith('use')) {
|
|
65
|
+
throw new Error("Invalid hook call");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray__default["default"](args)));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return proxy;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function createTRPCClientProxy(client) {
|
|
75
|
+
return makeProxy(client);
|
|
76
|
+
}
|
|
77
|
+
|
|
30
78
|
function getWindow() {
|
|
31
79
|
if (typeof window !== 'undefined') {
|
|
32
80
|
return window;
|
|
@@ -229,22 +277,6 @@ function getRequestId() {
|
|
|
229
277
|
return ++idCounter;
|
|
230
278
|
}
|
|
231
279
|
|
|
232
|
-
function createRouterProxy(callback) {
|
|
233
|
-
return new Proxy({}, {
|
|
234
|
-
get: function get(_, path) {
|
|
235
|
-
return function () {
|
|
236
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
237
|
-
args[_key] = arguments[_key];
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return callback.apply(void 0, [path].concat(args));
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
/** @internal */
|
|
246
|
-
|
|
247
|
-
|
|
248
280
|
var TRPCClient = /*#__PURE__*/function () {
|
|
249
281
|
function TRPCClient(opts) {
|
|
250
282
|
var _this = this;
|
|
@@ -253,8 +285,6 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
253
285
|
|
|
254
286
|
this.links = void 0;
|
|
255
287
|
this.runtime = void 0;
|
|
256
|
-
this.queries = void 0;
|
|
257
|
-
this.mutations = void 0;
|
|
258
288
|
|
|
259
289
|
var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
|
|
260
290
|
|
|
@@ -300,21 +330,6 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
300
330
|
url: opts.url
|
|
301
331
|
})(this.runtime)];
|
|
302
332
|
}
|
|
303
|
-
|
|
304
|
-
this.queries = createRouterProxy(function (path) {
|
|
305
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
306
|
-
args[_key2 - 1] = arguments[_key2];
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return _this.query.apply(_this, [path].concat(_toConsumableArray__default["default"](args)));
|
|
310
|
-
});
|
|
311
|
-
this.mutations = createRouterProxy(function (path) {
|
|
312
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
313
|
-
args[_key3 - 1] = arguments[_key3];
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return _this.mutation.apply(_this, [path].concat(_toConsumableArray__default["default"](args)));
|
|
317
|
-
});
|
|
318
333
|
}
|
|
319
334
|
|
|
320
335
|
_createClass__default["default"](TRPCClient, [{
|
|
@@ -370,8 +385,8 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
370
385
|
value: function query(path) {
|
|
371
386
|
var _args$;
|
|
372
387
|
|
|
373
|
-
for (var
|
|
374
|
-
args[
|
|
388
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
389
|
+
args[_key - 1] = arguments[_key];
|
|
375
390
|
}
|
|
376
391
|
|
|
377
392
|
var context = (_args$ = args[1]) === null || _args$ === void 0 ? void 0 : _args$.context;
|
|
@@ -387,8 +402,8 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
387
402
|
value: function mutation(path) {
|
|
388
403
|
var _args$2;
|
|
389
404
|
|
|
390
|
-
for (var
|
|
391
|
-
args[
|
|
405
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
406
|
+
args[_key2 - 1] = arguments[_key2];
|
|
392
407
|
}
|
|
393
408
|
|
|
394
409
|
var context = (_args$2 = args[1]) === null || _args$2 === void 0 ? void 0 : _args$2.context;
|
|
@@ -441,10 +456,11 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
441
456
|
return TRPCClient;
|
|
442
457
|
}();
|
|
443
458
|
|
|
444
|
-
/* eslint-disable @typescript-eslint/no-
|
|
459
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
445
460
|
function createTRPCClient(opts) {
|
|
446
|
-
|
|
447
|
-
|
|
461
|
+
var client = new TRPCClient(opts);
|
|
462
|
+
return createTRPCClientProxy(client);
|
|
463
|
+
} // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
|
|
448
464
|
|
|
449
465
|
exports.TRPCClientError = links_wsLink.TRPCClientError;
|
|
450
466
|
exports.createWSClient = links_wsLink.createWSClient;
|
|
@@ -454,6 +470,7 @@ exports.splitLink = links_splitLink.splitLink;
|
|
|
454
470
|
exports.httpLink = links_httpLink.httpLink;
|
|
455
471
|
exports.loggerLink = links_loggerLink.loggerLink;
|
|
456
472
|
exports.createTRPCClient = createTRPCClient;
|
|
473
|
+
exports.createTRPCClientProxy = createTRPCClientProxy;
|
|
457
474
|
exports.dedupeLink = dedupeLink;
|
|
458
475
|
exports.getFetch = getFetch;
|
|
459
476
|
exports.retryLink = retryLink;
|
package/dist/index.mjs
CHANGED
|
@@ -19,6 +19,54 @@ export { httpLink } from './links/httpLink.mjs';
|
|
|
19
19
|
export { loggerLink } from './links/loggerLink.mjs';
|
|
20
20
|
import './httpUtils-089853f6.mjs';
|
|
21
21
|
|
|
22
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
23
|
+
|
|
24
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
|
+
function makeProxy(client) {
|
|
26
|
+
for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
27
|
+
path[_key - 1] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var proxy = new Proxy(function () {// noop
|
|
31
|
+
}, {
|
|
32
|
+
get: function get(_obj, name) {
|
|
33
|
+
if (name in client && !path.length) {
|
|
34
|
+
return client[name];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof name === 'string') {
|
|
38
|
+
return makeProxy.apply(void 0, [client].concat(path, [name]));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return client;
|
|
42
|
+
},
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
44
|
+
apply: function apply(_1, _2, args) {
|
|
45
|
+
var _ref;
|
|
46
|
+
|
|
47
|
+
var pathCopy = [].concat(path);
|
|
48
|
+
var type = pathCopy.pop();
|
|
49
|
+
|
|
50
|
+
if (type === 'mutate') {
|
|
51
|
+
type = 'mutation';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var fullPath = pathCopy.join('.');
|
|
55
|
+
|
|
56
|
+
if (type.startsWith('use')) {
|
|
57
|
+
throw new Error("Invalid hook call");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray(args)));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return proxy;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function createTRPCClientProxy(client) {
|
|
67
|
+
return makeProxy(client);
|
|
68
|
+
}
|
|
69
|
+
|
|
22
70
|
function getWindow() {
|
|
23
71
|
if (typeof window !== 'undefined') {
|
|
24
72
|
return window;
|
|
@@ -221,22 +269,6 @@ function getRequestId() {
|
|
|
221
269
|
return ++idCounter;
|
|
222
270
|
}
|
|
223
271
|
|
|
224
|
-
function createRouterProxy(callback) {
|
|
225
|
-
return new Proxy({}, {
|
|
226
|
-
get: function get(_, path) {
|
|
227
|
-
return function () {
|
|
228
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
229
|
-
args[_key] = arguments[_key];
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return callback.apply(void 0, [path].concat(args));
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/** @internal */
|
|
238
|
-
|
|
239
|
-
|
|
240
272
|
var TRPCClient = /*#__PURE__*/function () {
|
|
241
273
|
function TRPCClient(opts) {
|
|
242
274
|
var _this = this;
|
|
@@ -245,8 +277,6 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
245
277
|
|
|
246
278
|
this.links = void 0;
|
|
247
279
|
this.runtime = void 0;
|
|
248
|
-
this.queries = void 0;
|
|
249
|
-
this.mutations = void 0;
|
|
250
280
|
|
|
251
281
|
var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
|
|
252
282
|
|
|
@@ -292,21 +322,6 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
292
322
|
url: opts.url
|
|
293
323
|
})(this.runtime)];
|
|
294
324
|
}
|
|
295
|
-
|
|
296
|
-
this.queries = createRouterProxy(function (path) {
|
|
297
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
298
|
-
args[_key2 - 1] = arguments[_key2];
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return _this.query.apply(_this, [path].concat(_toConsumableArray(args)));
|
|
302
|
-
});
|
|
303
|
-
this.mutations = createRouterProxy(function (path) {
|
|
304
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
305
|
-
args[_key3 - 1] = arguments[_key3];
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return _this.mutation.apply(_this, [path].concat(_toConsumableArray(args)));
|
|
309
|
-
});
|
|
310
325
|
}
|
|
311
326
|
|
|
312
327
|
_createClass(TRPCClient, [{
|
|
@@ -362,8 +377,8 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
362
377
|
value: function query(path) {
|
|
363
378
|
var _args$;
|
|
364
379
|
|
|
365
|
-
for (var
|
|
366
|
-
args[
|
|
380
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
381
|
+
args[_key - 1] = arguments[_key];
|
|
367
382
|
}
|
|
368
383
|
|
|
369
384
|
var context = (_args$ = args[1]) === null || _args$ === void 0 ? void 0 : _args$.context;
|
|
@@ -379,8 +394,8 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
379
394
|
value: function mutation(path) {
|
|
380
395
|
var _args$2;
|
|
381
396
|
|
|
382
|
-
for (var
|
|
383
|
-
args[
|
|
397
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
398
|
+
args[_key2 - 1] = arguments[_key2];
|
|
384
399
|
}
|
|
385
400
|
|
|
386
401
|
var context = (_args$2 = args[1]) === null || _args$2 === void 0 ? void 0 : _args$2.context;
|
|
@@ -433,9 +448,10 @@ var TRPCClient = /*#__PURE__*/function () {
|
|
|
433
448
|
return TRPCClient;
|
|
434
449
|
}();
|
|
435
450
|
|
|
436
|
-
/* eslint-disable @typescript-eslint/no-
|
|
451
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
437
452
|
function createTRPCClient(opts) {
|
|
438
|
-
|
|
439
|
-
|
|
453
|
+
var client = new TRPCClient(opts);
|
|
454
|
+
return createTRPCClientProxy(client);
|
|
455
|
+
} // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
|
|
440
456
|
|
|
441
|
-
export { createTRPCClient, dedupeLink, getFetch, retryLink };
|
|
457
|
+
export { createTRPCClient, createTRPCClientProxy, dedupeLink, getFetch, retryLink };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyRouter, ClientDataTransformerOptions, inferHandlerInput, inferProcedureInput, inferSubscriptionOutput } from '@trpc/server';
|
|
1
|
+
import { AnyRouter, ClientDataTransformerOptions, inferHandlerInput, inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server';
|
|
2
2
|
import { Observer, Unsubscribable } from '@trpc/server/observable';
|
|
3
3
|
import { TRPCResultMessage } from '@trpc/server/rpc';
|
|
4
4
|
import { CancelFn } from '..';
|
|
@@ -51,13 +51,11 @@ export declare type CreateTRPCClientOptions<TRouter extends AnyRouter> = CreateT
|
|
|
51
51
|
export declare class TRPCClient<TRouter extends AnyRouter> {
|
|
52
52
|
private readonly links;
|
|
53
53
|
readonly runtime: TRPCClientRuntime;
|
|
54
|
-
readonly queries: TRouter['queries'];
|
|
55
|
-
readonly mutations: TRouter['mutations'];
|
|
56
54
|
constructor(opts: CreateTRPCClientOptions<TRouter>);
|
|
57
55
|
private $request;
|
|
58
56
|
private requestAsPromise;
|
|
59
|
-
query<TQueries extends TRouter['_def']['queries'], TPath extends string & keyof TQueries>(path: TPath, ...args: [...inferHandlerInput<TQueries[TPath]>, TRPCRequestOptions?]): CancellablePromise<
|
|
60
|
-
mutation<TMutations extends TRouter['_def']['mutations'], TPath extends string & keyof TMutations>(path: TPath, ...args: [...inferHandlerInput<TMutations[TPath]>, TRPCRequestOptions?]): CancellablePromise<
|
|
57
|
+
query<TQueries extends TRouter['_def']['queries'], TPath extends string & keyof TQueries>(path: TPath, ...args: [...inferHandlerInput<TQueries[TPath]>, TRPCRequestOptions?]): CancellablePromise<inferProcedureOutput<TQueries[TPath]>>;
|
|
58
|
+
mutation<TMutations extends TRouter['_def']['mutations'], TPath extends string & keyof TMutations>(path: TPath, ...args: [...inferHandlerInput<TMutations[TPath]>, TRPCRequestOptions?]): CancellablePromise<inferProcedureOutput<TMutations[TPath]>>;
|
|
61
59
|
subscription<TSubscriptions extends TRouter['_def']['subscriptions'], TPath extends string & keyof TSubscriptions, TOutput extends inferSubscriptionOutput<TRouter, TPath>, TInput extends inferProcedureInput<TSubscriptions[TPath]>>(path: TPath, input: TInput, opts: TRPCRequestOptions & Partial<Observer<TRPCResultMessage<TOutput>, TRPCClientError<TRouter>>>): Unsubscribable;
|
|
62
60
|
}
|
|
63
61
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,4BAA4B,EAE5B,iBAAiB,EACjB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"TRPCClient.d.ts","sourceRoot":"","sources":["../../src/internals/TRPCClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../../../dist/declarations/src/links/httpBatchLink";
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
6
|
+
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
7
|
+
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
8
|
+
require('@babel/runtime/helpers/classCallCheck');
|
|
9
|
+
require('@babel/runtime/helpers/createClass');
|
|
10
|
+
var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
|
|
11
|
+
var transformRPCResponse = require('../../../dist/transformRPCResponse-c6cc4677.cjs.dev.js');
|
|
12
|
+
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
|
|
13
|
+
require('@babel/runtime/helpers/assertThisInitialized');
|
|
14
|
+
require('@babel/runtime/helpers/inherits');
|
|
15
|
+
require('@babel/runtime/helpers/createSuper');
|
|
16
|
+
require('@babel/runtime/helpers/wrapNativeSuper');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
24
|
+
* Less configuration, no caching, and allows you to cancel requests
|
|
25
|
+
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
26
|
+
*/
|
|
27
|
+
function dataLoader(fetchMany, opts) {
|
|
28
|
+
var batch = null;
|
|
29
|
+
var dispatchTimer = null;
|
|
30
|
+
|
|
31
|
+
var destroyTimerAndBatch = function destroyTimerAndBatch() {
|
|
32
|
+
clearTimeout(dispatchTimer);
|
|
33
|
+
dispatchTimer = null;
|
|
34
|
+
batch = null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function dispatch() {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
39
|
+
var batchCopy = batch;
|
|
40
|
+
destroyTimerAndBatch();
|
|
41
|
+
|
|
42
|
+
var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
|
|
43
|
+
return v.key;
|
|
44
|
+
})),
|
|
45
|
+
promise = _fetchMany.promise,
|
|
46
|
+
cancel = _fetchMany.cancel;
|
|
47
|
+
|
|
48
|
+
batchCopy.cancel = cancel;
|
|
49
|
+
promise.then(function (result) {
|
|
50
|
+
for (var i = 0; i < result.length; i++) {
|
|
51
|
+
var _value = result[i];
|
|
52
|
+
batchCopy.items[i].resolve(_value);
|
|
53
|
+
}
|
|
54
|
+
}).catch(function (cause) {
|
|
55
|
+
var _iterator = _createForOfIteratorHelper(batchCopy.items),
|
|
56
|
+
_step;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
60
|
+
var item = _step.value;
|
|
61
|
+
item.reject(cause);
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_iterator.e(err);
|
|
65
|
+
} finally {
|
|
66
|
+
_iterator.f();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function load(key) {
|
|
72
|
+
var batchItem = {
|
|
73
|
+
cancelled: false,
|
|
74
|
+
key: key
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (!batch) {
|
|
78
|
+
batch = {
|
|
79
|
+
items: [],
|
|
80
|
+
cancel: function cancel() {
|
|
81
|
+
destroyTimerAndBatch();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var thisBatch = batch;
|
|
87
|
+
var promise = new Promise(function (resolve, reject) {
|
|
88
|
+
var item = batchItem;
|
|
89
|
+
item.reject = reject;
|
|
90
|
+
item.resolve = resolve;
|
|
91
|
+
thisBatch.items.push(item);
|
|
92
|
+
|
|
93
|
+
if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
|
|
94
|
+
dispatch();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
if (!dispatchTimer) {
|
|
100
|
+
dispatchTimer = setTimeout(dispatch);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var cancel = function cancel() {
|
|
104
|
+
batchItem.cancelled = true;
|
|
105
|
+
|
|
106
|
+
if (thisBatch.items.some(function (item) {
|
|
107
|
+
return !item.cancelled;
|
|
108
|
+
})) {
|
|
109
|
+
// there are still things that can be resolved
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
thisBatch.cancel();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
promise: promise,
|
|
118
|
+
cancel: cancel
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
load: load
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function httpBatchLink(opts) {
|
|
128
|
+
var url = opts.url,
|
|
129
|
+
maxBatchSize = opts.maxBatchSize; // initialized config
|
|
130
|
+
|
|
131
|
+
return function (runtime) {
|
|
132
|
+
// initialized in app
|
|
133
|
+
var getHeaders = /*#__PURE__*/function () {
|
|
134
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(arg1) {
|
|
135
|
+
var val;
|
|
136
|
+
return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
|
|
137
|
+
while (1) {
|
|
138
|
+
switch (_context.prev = _context.next) {
|
|
139
|
+
case 0:
|
|
140
|
+
val = opts.headers;
|
|
141
|
+
_context.t0 = _objectSpread;
|
|
142
|
+
_context.t1 = _objectSpread;
|
|
143
|
+
_context.t2 = {};
|
|
144
|
+
_context.next = 6;
|
|
145
|
+
return runtime.headers();
|
|
146
|
+
|
|
147
|
+
case 6:
|
|
148
|
+
_context.t3 = _context.sent;
|
|
149
|
+
_context.t4 = (0, _context.t1)(_context.t2, _context.t3);
|
|
150
|
+
|
|
151
|
+
if (!(typeof val === 'function')) {
|
|
152
|
+
_context.next = 14;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
_context.next = 11;
|
|
157
|
+
return val(arg1);
|
|
158
|
+
|
|
159
|
+
case 11:
|
|
160
|
+
_context.t5 = _context.sent;
|
|
161
|
+
_context.next = 15;
|
|
162
|
+
break;
|
|
163
|
+
|
|
164
|
+
case 14:
|
|
165
|
+
_context.t5 = val;
|
|
166
|
+
|
|
167
|
+
case 15:
|
|
168
|
+
_context.t6 = _context.t5;
|
|
169
|
+
return _context.abrupt("return", (0, _context.t0)(_context.t4, _context.t6));
|
|
170
|
+
|
|
171
|
+
case 17:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context.stop();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, _callee);
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
return function getHeaders(_x) {
|
|
180
|
+
return _ref.apply(this, arguments);
|
|
181
|
+
};
|
|
182
|
+
}();
|
|
183
|
+
|
|
184
|
+
var fetcher = function fetcher(type) {
|
|
185
|
+
return function (pairs) {
|
|
186
|
+
var _opts$fetch, _opts$AbortController;
|
|
187
|
+
|
|
188
|
+
var path = pairs.map(function (op) {
|
|
189
|
+
return op.path;
|
|
190
|
+
}).join(',');
|
|
191
|
+
var inputs = pairs.map(function (op) {
|
|
192
|
+
return op.input;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
var _httpRequest = transformRPCResponse.httpRequest({
|
|
196
|
+
url: url,
|
|
197
|
+
inputs: inputs,
|
|
198
|
+
path: path,
|
|
199
|
+
type: type,
|
|
200
|
+
fetch: transformRPCResponse.getFetch((_opts$fetch = opts.fetch) !== null && _opts$fetch !== void 0 ? _opts$fetch : runtime.fetch),
|
|
201
|
+
AbortController: transformRPCResponse.getAbortController((_opts$AbortController = opts.AbortController) !== null && _opts$AbortController !== void 0 ? _opts$AbortController : runtime.AbortController),
|
|
202
|
+
headers: function headers() {
|
|
203
|
+
return getHeaders({
|
|
204
|
+
operations: pairs
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
transformer: runtime.transformer
|
|
208
|
+
}),
|
|
209
|
+
promise = _httpRequest.promise,
|
|
210
|
+
cancel = _httpRequest.cancel;
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
promise: promise.then(function (res) {
|
|
214
|
+
if (!Array.isArray(res)) {
|
|
215
|
+
return pairs.map(function () {
|
|
216
|
+
return res;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return res;
|
|
221
|
+
}),
|
|
222
|
+
cancel: cancel
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
var query = dataLoader(fetcher('query'), {
|
|
228
|
+
maxBatchSize: maxBatchSize
|
|
229
|
+
});
|
|
230
|
+
var mutation = dataLoader(fetcher('mutation'), {
|
|
231
|
+
maxBatchSize: maxBatchSize
|
|
232
|
+
});
|
|
233
|
+
var subscription = dataLoader(fetcher('subscription'), {
|
|
234
|
+
maxBatchSize: maxBatchSize
|
|
235
|
+
});
|
|
236
|
+
var loaders = {
|
|
237
|
+
query: query,
|
|
238
|
+
subscription: subscription,
|
|
239
|
+
mutation: mutation
|
|
240
|
+
};
|
|
241
|
+
return function (_ref2) {
|
|
242
|
+
var op = _ref2.op,
|
|
243
|
+
prev = _ref2.prev,
|
|
244
|
+
onDestroy = _ref2.onDestroy;
|
|
245
|
+
var loader = loaders[op.type];
|
|
246
|
+
|
|
247
|
+
var _loader$load = loader.load(op),
|
|
248
|
+
promise = _loader$load.promise,
|
|
249
|
+
cancel = _loader$load.cancel;
|
|
250
|
+
|
|
251
|
+
var isDone = false;
|
|
252
|
+
|
|
253
|
+
var prevOnce = function prevOnce(result) {
|
|
254
|
+
if (isDone) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
isDone = true;
|
|
259
|
+
prev(result);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
onDestroy(function () {
|
|
263
|
+
prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
|
|
264
|
+
isDone: true
|
|
265
|
+
}));
|
|
266
|
+
cancel();
|
|
267
|
+
});
|
|
268
|
+
promise.then(function (envelope) {
|
|
269
|
+
prevOnce(transformRPCResponse.transformRPCResponse({
|
|
270
|
+
envelope: envelope,
|
|
271
|
+
runtime: runtime
|
|
272
|
+
}));
|
|
273
|
+
}).catch(function (cause) {
|
|
274
|
+
prevOnce(TRPCClientError.TRPCClientError.from(cause));
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
exports.httpBatchLink = httpBatchLink;
|