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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/createTRPCClient.d.ts +5 -1
  2. package/dist/createTRPCClient.d.ts.map +1 -1
  3. package/dist/index.js +49 -40
  4. package/dist/index.mjs +49 -40
  5. package/dist/internals/TRPCClient.d.ts +3 -5
  6. package/dist/internals/TRPCClient.d.ts.map +1 -1
  7. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +1 -0
  8. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +280 -0
  9. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +7 -0
  10. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +280 -0
  11. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +272 -0
  12. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +1 -0
  13. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +134 -0
  14. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +7 -0
  15. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +134 -0
  16. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +126 -0
  17. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +1 -0
  18. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +89 -0
  19. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +7 -0
  20. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +89 -0
  21. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +85 -0
  22. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +1 -0
  23. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +19 -0
  24. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +7 -0
  25. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +19 -0
  26. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +15 -0
  27. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +1 -0
  28. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +397 -0
  29. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +7 -0
  30. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +397 -0
  31. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +392 -0
  32. package/package.json +4 -4
  33. package/src/createTRPCClient.ts +56 -1
  34. package/src/internals/TRPCClient.ts +0 -17
@@ -1,5 +1,9 @@
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 type EnsureRecord<T> = T extends Record<string, any> ? T : Record<string, never>;
4
+ declare type FlattenRouter<TRouter extends AnyRouter> = {
5
+ [Key in keyof TRouter['_def']['procedures']]: TRouter['_def']['procedures'][Key] extends AnyRouter ? FlattenRouter<TRouter['_def']['procedures'][Key]> : TRouter['_def']['procedures'][Key];
6
+ };
7
+ export declare function createTRPCClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): Client<TRouter> & FlattenRouter<TRouter>;
4
8
  export type { TRPCRequestOptions, CreateTRPCClientOptions, TRPCClient, } from './internals/TRPCClient';
5
9
  //# sourceMappingURL=createTRPCClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,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,mBAGvC;AAED,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,GACX,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"","sources":["../src/createTRPCClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,UAAU,IAAI,MAAM,EACpB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAEhC,oBAAY,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACvD,CAAC,GACD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE1B,aAAK,aAAa,CAAC,OAAO,SAAS,SAAS,IAAI;KAC7C,GAAG,IAAI,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,SAAS,SAAS,GAC9F,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,GACjD,OAAO,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC;CACvC,CAAC;AAyCF,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,4CAKvC;AAID,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,UAAU,GACX,MAAM,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -229,22 +229,6 @@ function getRequestId() {
229
229
  return ++idCounter;
230
230
  }
231
231
 
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
232
  var TRPCClient = /*#__PURE__*/function () {
249
233
  function TRPCClient(opts) {
250
234
  var _this = this;
@@ -253,8 +237,6 @@ var TRPCClient = /*#__PURE__*/function () {
253
237
 
254
238
  this.links = void 0;
255
239
  this.runtime = void 0;
256
- this.queries = void 0;
257
- this.mutations = void 0;
258
240
 
259
241
  var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
260
242
 
@@ -300,21 +282,6 @@ var TRPCClient = /*#__PURE__*/function () {
300
282
  url: opts.url
301
283
  })(this.runtime)];
302
284
  }
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
285
  }
319
286
 
320
287
  _createClass__default["default"](TRPCClient, [{
@@ -370,8 +337,8 @@ var TRPCClient = /*#__PURE__*/function () {
370
337
  value: function query(path) {
371
338
  var _args$;
372
339
 
373
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
374
- args[_key4 - 1] = arguments[_key4];
340
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
341
+ args[_key - 1] = arguments[_key];
375
342
  }
376
343
 
377
344
  var context = (_args$ = args[1]) === null || _args$ === void 0 ? void 0 : _args$.context;
@@ -387,8 +354,8 @@ var TRPCClient = /*#__PURE__*/function () {
387
354
  value: function mutation(path) {
388
355
  var _args$2;
389
356
 
390
- for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
391
- args[_key5 - 1] = arguments[_key5];
357
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
358
+ args[_key2 - 1] = arguments[_key2];
392
359
  }
393
360
 
394
361
  var context = (_args$2 = args[1]) === null || _args$2 === void 0 ? void 0 : _args$2.context;
@@ -441,11 +408,53 @@ var TRPCClient = /*#__PURE__*/function () {
441
408
  return TRPCClient;
442
409
  }();
443
410
 
444
- /* eslint-disable @typescript-eslint/no-explicit-any */
445
- function createTRPCClient(opts) {
446
- return new TRPCClient(opts);
411
+ function makeProxy(client) {
412
+ for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
413
+ path[_key - 1] = arguments[_key];
414
+ }
415
+
416
+ var proxy = new Proxy(function () {// noop
417
+ }, {
418
+ get: function get(_obj, name) {
419
+ if (name in client && !path.length) {
420
+ return client[name];
421
+ }
422
+
423
+ if (typeof name === 'string') {
424
+ return makeProxy.apply(void 0, [client].concat(path, [name]));
425
+ }
426
+
427
+ return client;
428
+ },
429
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
430
+ apply: function apply(_1, _2, args) {
431
+ var _ref;
432
+
433
+ var pathCopy = [].concat(path);
434
+ var type = pathCopy.pop();
435
+
436
+ if (type === 'mutate') {
437
+ type = 'mutation';
438
+ }
439
+
440
+ var fullPath = pathCopy.join('.');
441
+
442
+ if (type.startsWith('use')) {
443
+ throw new Error("Invalid hook call");
444
+ }
445
+
446
+ return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray__default["default"](args)));
447
+ }
448
+ });
449
+ return proxy;
447
450
  }
448
451
 
452
+ function createTRPCClient(opts) {
453
+ var client = new TRPCClient(opts); // Here we need to wrap the client in a Proxy to be able to call deep objects and translate them to `client.query`-calls
454
+
455
+ return makeProxy(client);
456
+ } // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
457
+
449
458
  exports.TRPCClientError = links_wsLink.TRPCClientError;
450
459
  exports.createWSClient = links_wsLink.createWSClient;
451
460
  exports.wsLink = links_wsLink.wsLink;
package/dist/index.mjs CHANGED
@@ -221,22 +221,6 @@ function getRequestId() {
221
221
  return ++idCounter;
222
222
  }
223
223
 
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
224
  var TRPCClient = /*#__PURE__*/function () {
241
225
  function TRPCClient(opts) {
242
226
  var _this = this;
@@ -245,8 +229,6 @@ var TRPCClient = /*#__PURE__*/function () {
245
229
 
246
230
  this.links = void 0;
247
231
  this.runtime = void 0;
248
- this.queries = void 0;
249
- this.mutations = void 0;
250
232
 
251
233
  var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
252
234
 
@@ -292,21 +274,6 @@ var TRPCClient = /*#__PURE__*/function () {
292
274
  url: opts.url
293
275
  })(this.runtime)];
294
276
  }
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
277
  }
311
278
 
312
279
  _createClass(TRPCClient, [{
@@ -362,8 +329,8 @@ var TRPCClient = /*#__PURE__*/function () {
362
329
  value: function query(path) {
363
330
  var _args$;
364
331
 
365
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
366
- args[_key4 - 1] = arguments[_key4];
332
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
333
+ args[_key - 1] = arguments[_key];
367
334
  }
368
335
 
369
336
  var context = (_args$ = args[1]) === null || _args$ === void 0 ? void 0 : _args$.context;
@@ -379,8 +346,8 @@ var TRPCClient = /*#__PURE__*/function () {
379
346
  value: function mutation(path) {
380
347
  var _args$2;
381
348
 
382
- for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
383
- args[_key5 - 1] = arguments[_key5];
349
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
350
+ args[_key2 - 1] = arguments[_key2];
384
351
  }
385
352
 
386
353
  var context = (_args$2 = args[1]) === null || _args$2 === void 0 ? void 0 : _args$2.context;
@@ -433,9 +400,51 @@ var TRPCClient = /*#__PURE__*/function () {
433
400
  return TRPCClient;
434
401
  }();
435
402
 
436
- /* eslint-disable @typescript-eslint/no-explicit-any */
437
- function createTRPCClient(opts) {
438
- return new TRPCClient(opts);
403
+ function makeProxy(client) {
404
+ for (var _len = arguments.length, path = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
405
+ path[_key - 1] = arguments[_key];
406
+ }
407
+
408
+ var proxy = new Proxy(function () {// noop
409
+ }, {
410
+ get: function get(_obj, name) {
411
+ if (name in client && !path.length) {
412
+ return client[name];
413
+ }
414
+
415
+ if (typeof name === 'string') {
416
+ return makeProxy.apply(void 0, [client].concat(path, [name]));
417
+ }
418
+
419
+ return client;
420
+ },
421
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
422
+ apply: function apply(_1, _2, args) {
423
+ var _ref;
424
+
425
+ var pathCopy = [].concat(path);
426
+ var type = pathCopy.pop();
427
+
428
+ if (type === 'mutate') {
429
+ type = 'mutation';
430
+ }
431
+
432
+ var fullPath = pathCopy.join('.');
433
+
434
+ if (type.startsWith('use')) {
435
+ throw new Error("Invalid hook call");
436
+ }
437
+
438
+ return (_ref = client)[type].apply(_ref, [fullPath].concat(_toConsumableArray(args)));
439
+ }
440
+ });
441
+ return proxy;
439
442
  }
440
443
 
444
+ function createTRPCClient(opts) {
445
+ var client = new TRPCClient(opts); // Here we need to wrap the client in a Proxy to be able to call deep objects and translate them to `client.query`-calls
446
+
447
+ return makeProxy(client);
448
+ } // Also the client created above needs to somehow be like `TRPCClient<Router> & Omit<Router, 'createCaller' | 'createProcedure' | '_def' | 'transformer' | 'errorFormatter' | 'getErrorShape>`
449
+
441
450
  export { createTRPCClient, 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<import("@trpc/server").ThenArg<ReturnType<TQueries[TPath]>>>;
60
- mutation<TMutations extends TRouter['_def']['mutations'], TPath extends string & keyof TMutations>(path: TPath, ...args: [...inferHandlerInput<TMutations[TPath]>, TRPCRequestOptions?]): CancellablePromise<import("@trpc/server").ThenArg<ReturnType<TMutations[TPath]>>>;
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,EAEnB,uBAAuB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,QAAQ,EACR,cAAc,EAIf,MAAM,yBAAyB,CAA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GACxE,cAAc;CA4BlB"}
@@ -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;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./trpc-client-links-httpBatchLink.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./trpc-client-links-httpBatchLink.cjs.dev.js");
7
+ }