@trpc/client 10.0.0-alpha.16 → 10.0.0-alpha.17

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/index.mjs CHANGED
@@ -2,12 +2,12 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
2
2
  import _createClass from '@babel/runtime/helpers/createClass';
3
3
  import { o as observable, s as share, t as tap } from './tap-4bc60fb0.mjs';
4
4
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
6
  import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
6
7
  import _inherits from '@babel/runtime/helpers/inherits';
7
8
  import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
8
9
  import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
9
10
  import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
10
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
11
11
 
12
12
  function getWindow() {
13
13
  if (typeof window !== 'undefined') {
@@ -35,6 +35,59 @@ function getFetch(f) {
35
35
  throw new Error('No fetch implementation found');
36
36
  }
37
37
 
38
+ function dedupeLink() {
39
+ // initialized config
40
+ return function () {
41
+ // initialized in app
42
+ var pending = {};
43
+ return function (_ref) {
44
+ var op = _ref.op,
45
+ next = _ref.next;
46
+
47
+ // initialized for request
48
+ if (op.type !== 'query') {
49
+ // pass through
50
+ return next(op);
51
+ }
52
+
53
+ var key = JSON.stringify([op.path, op.input]);
54
+
55
+ if (pending[key]) {
56
+ // console.log('hooking into pending', { op });
57
+ return observable(function (observer) {
58
+ return pending[key].subscribe(observer);
59
+ });
60
+ }
61
+
62
+ var shared$ = observable(function (observer) {
63
+ function reset() {
64
+ delete pending[key];
65
+ }
66
+
67
+ var subscription = next(op).subscribe({
68
+ next: function next(v) {
69
+ observer.next(v);
70
+ },
71
+ error: function error(e) {
72
+ reset();
73
+ observer.error(e);
74
+ },
75
+ complete: function complete() {
76
+ reset();
77
+ observer.complete();
78
+ }
79
+ });
80
+ return function () {
81
+ reset();
82
+ subscription.unsubscribe();
83
+ };
84
+ }).pipe(share());
85
+ pending[key] = shared$;
86
+ return shared$;
87
+ };
88
+ };
89
+ }
90
+
38
91
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
39
92
 
40
93
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -309,6 +362,196 @@ function httpBatchLink(opts) {
309
362
  };
310
363
  }
311
364
 
365
+ function httpLink(opts) {
366
+ var url = opts.url;
367
+ return function (runtime) {
368
+ return function (_ref) {
369
+ var op = _ref.op;
370
+ return observable(function (observer) {
371
+ var path = op.path,
372
+ input = op.input,
373
+ type = op.type;
374
+
375
+ var _httpRequest = httpRequest({
376
+ runtime: runtime,
377
+ path: path,
378
+ input: input,
379
+ type: type,
380
+ url: url
381
+ }),
382
+ promise = _httpRequest.promise,
383
+ cancel = _httpRequest.cancel;
384
+
385
+ promise.then(function (res) {
386
+ observer.next({
387
+ context: res.meta,
388
+ data: res.json
389
+ });
390
+ observer.complete();
391
+ }).catch(observer.error);
392
+ return function () {
393
+ cancel();
394
+ };
395
+ });
396
+ };
397
+ };
398
+ }
399
+
400
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
401
+
402
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
403
+ var palette = {
404
+ query: ['72e3ff', '3fb0d8'],
405
+ mutation: ['c5a3fc', '904dfc'],
406
+ subscription: ['ff49e1', 'd83fbe']
407
+ };
408
+
409
+ // maybe this should be moved to it's own package
410
+ var defaultLogger = function defaultLogger() {
411
+ var c = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : console;
412
+ return function (props) {
413
+ var direction = props.direction,
414
+ input = props.input,
415
+ type = props.type,
416
+ path = props.path,
417
+ context = props.context,
418
+ id = props.id;
419
+
420
+ var _palette$type = _slicedToArray(palette[type], 2),
421
+ light = _palette$type[0],
422
+ dark = _palette$type[1];
423
+
424
+ var css = "\n background-color: #".concat(direction === 'up' ? light : dark, "; \n color: ").concat(direction === 'up' ? 'black' : 'white', ";\n padding: 2px;\n ");
425
+ var parts = ['%c', direction === 'up' ? '>>' : '<<', type, "#".concat(id), "%c".concat(path, "%c"), '%O'];
426
+ var args = [css, "".concat(css, "; font-weight: bold;"), "".concat(css, "; font-weight: normal;")];
427
+
428
+ if (props.direction === 'up') {
429
+ args.push({
430
+ input: input,
431
+ context: context
432
+ });
433
+ } else {
434
+ args.push({
435
+ input: input,
436
+ result: props.result,
437
+ elapsedMs: props.elapsedMs,
438
+ context: context
439
+ });
440
+ }
441
+
442
+ var fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.data) ? 'error' : 'log';
443
+ c[fn].apply(null, [parts.join(' ')].concat(args));
444
+ };
445
+ };
446
+
447
+ function loggerLink() {
448
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
449
+ var _opts$enabled = opts.enabled,
450
+ enabled = _opts$enabled === void 0 ? function () {
451
+ return true;
452
+ } : _opts$enabled;
453
+ var _opts$logger = opts.logger,
454
+ logger = _opts$logger === void 0 ? defaultLogger(opts.console) : _opts$logger;
455
+ return function () {
456
+ return function (_ref) {
457
+ var op = _ref.op,
458
+ next = _ref.next;
459
+ return observable(function (observer) {
460
+ // ->
461
+ enabled(_objectSpread$2(_objectSpread$2({}, op), {}, {
462
+ direction: 'up'
463
+ })) && logger(_objectSpread$2(_objectSpread$2({}, op), {}, {
464
+ direction: 'up'
465
+ }));
466
+ var requestStartTime = Date.now();
467
+
468
+ function logResult(result) {
469
+ var elapsedMs = Date.now() - requestStartTime;
470
+ enabled(_objectSpread$2(_objectSpread$2({}, op), {}, {
471
+ direction: 'down',
472
+ result: result
473
+ })) && logger(_objectSpread$2(_objectSpread$2({}, op), {}, {
474
+ direction: 'down',
475
+ elapsedMs: elapsedMs,
476
+ result: result
477
+ }));
478
+ }
479
+
480
+ return next(op).pipe(tap({
481
+ next: function next(result) {
482
+ logResult(result);
483
+ },
484
+ error: function error(result) {
485
+ logResult(result);
486
+ }
487
+ })).subscribe(observer);
488
+ });
489
+ };
490
+ };
491
+ }
492
+
493
+ function retryLink(opts) {
494
+ // initialized config
495
+ return function () {
496
+ // initialized in app
497
+ return function (_ref) {
498
+ var op = _ref.op,
499
+ next = _ref.next;
500
+ // initialized for request
501
+ return observable(function (observer) {
502
+ var next$ = null;
503
+ var attempts = 0;
504
+ var isDone = false;
505
+
506
+ function attempt() {
507
+ var _next$;
508
+
509
+ attempts++;
510
+ (_next$ = next$) === null || _next$ === void 0 ? void 0 : _next$.unsubscribe();
511
+ next$ = next(op).subscribe({
512
+ error: function error(_error) {
513
+ if (attempts >= opts.attempts) {
514
+ observer.error(_error);
515
+ return;
516
+ }
517
+
518
+ attempt();
519
+ },
520
+ next: function next(result) {
521
+ if ('result' in result.data) {
522
+ isDone = true;
523
+ observer.next(result);
524
+ return;
525
+ }
526
+
527
+ if (attempts >= opts.attempts) {
528
+ isDone = true;
529
+ observer.next(result);
530
+ return;
531
+ }
532
+
533
+ attempt();
534
+ },
535
+ complete: function complete() {
536
+ if (isDone) {
537
+ observer.complete();
538
+ }
539
+ }
540
+ });
541
+ }
542
+
543
+ attempt();
544
+ return function () {
545
+ var _next$2;
546
+
547
+ isDone = true;
548
+ (_next$2 = next$) === null || _next$2 === void 0 ? void 0 : _next$2.unsubscribe();
549
+ };
550
+ });
551
+ };
552
+ };
553
+ }
554
+
312
555
  /** @internal */
313
556
  function createChain(opts) {
314
557
  return observable(function (observer) {
@@ -331,576 +574,9 @@ function createChain(opts) {
331
574
  });
332
575
  }
333
576
 
334
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
335
-
336
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
337
-
338
- function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
339
-
340
- function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
341
-
342
- var TRPCClientError = /*#__PURE__*/function (_Error) {
343
- _inherits(TRPCClientError, _Error);
344
-
345
- var _super = /*#__PURE__*/_createSuper$2(TRPCClientError);
346
-
347
- /**
348
- * @deprecated use `cause`
349
- */
350
- function TRPCClientError(message, opts) {
351
- var _opts$cause, _opts$result, _opts$result2;
352
-
353
- var _this;
354
-
355
- _classCallCheck(this, TRPCClientError);
356
-
357
- var cause = (_opts$cause = opts === null || opts === void 0 ? void 0 : opts.cause) !== null && _opts$cause !== void 0 ? _opts$cause : opts === null || opts === void 0 ? void 0 : opts.originalError; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
358
- // @ts-ignore https://github.com/tc39/proposal-error-cause
359
-
360
- _this = _super.call(this, message, {
361
- cause: cause
362
- });
363
- _this.originalError = void 0;
364
- _this.cause = void 0;
365
- _this.shape = void 0;
366
- _this.data = void 0;
367
- _this.meta = void 0;
368
- _this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
369
- _this.cause = _this.originalError = cause;
370
- _this.shape = opts === null || opts === void 0 ? void 0 : (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
371
- _this.data = opts === null || opts === void 0 ? void 0 : (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
372
- _this.name = 'TRPCClientError';
373
- Object.setPrototypeOf(_assertThisInitialized(_this), TRPCClientError.prototype);
374
- return _this;
375
- }
376
-
377
- _createClass(TRPCClientError, null, [{
378
- key: "from",
379
- value: function from(cause) {
380
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
381
-
382
- if (!(cause instanceof Error)) {
383
- var _message;
384
-
385
- return new TRPCClientError((_message = cause.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread$2(_objectSpread$2({}, opts), {}, {
386
- cause: null,
387
- result: cause
388
- }));
389
- }
390
-
391
- if (cause.name === 'TRPCClientError') {
392
- return cause;
393
- }
394
-
395
- return new TRPCClientError(cause.message, _objectSpread$2(_objectSpread$2({}, opts), {}, {
396
- cause: cause,
397
- result: null
398
- }));
399
- }
400
- }]);
401
-
402
- return TRPCClientError;
403
- }( /*#__PURE__*/_wrapNativeSuper(Error));
404
-
405
- /** @internal */
406
- function transformOperationResult$1(result) {
407
- var context = result.context;
408
-
409
- if ('error' in result.data) {
410
- var error = TRPCClientError.from(result.data);
411
- return {
412
- ok: false,
413
- error: error,
414
- context: context
415
- };
416
- }
417
-
418
- var data = result.data.result.data;
419
- return {
420
- ok: true,
421
- data: data,
422
- context: context
423
- };
424
- }
425
-
426
- function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
427
-
428
- function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
429
-
430
- var ObservableAbortError = /*#__PURE__*/function (_Error) {
431
- _inherits(ObservableAbortError, _Error);
432
-
433
- var _super = /*#__PURE__*/_createSuper$1(ObservableAbortError);
434
-
435
- function ObservableAbortError(message) {
436
- var _this;
437
-
438
- _classCallCheck(this, ObservableAbortError);
439
-
440
- _this = _super.call(this, message);
441
- _this.name = 'ObservableAbortError';
442
- Object.setPrototypeOf(_assertThisInitialized(_this), ObservableAbortError.prototype);
443
- return _this;
444
- }
445
-
446
- return _createClass(ObservableAbortError);
447
- }( /*#__PURE__*/_wrapNativeSuper(Error));
448
- /** @internal */
449
-
450
- function observableToPromise(observable) {
451
- var abort;
452
- var promise = new Promise(function (resolve, reject) {
453
- var isDone = false;
454
-
455
- function onDone() {
456
- if (isDone) {
457
- return;
458
- }
459
-
460
- isDone = true;
461
- reject(new ObservableAbortError('This operation was cancelled.'));
462
- obs$.unsubscribe();
463
- }
464
-
465
- var obs$ = observable.subscribe({
466
- next: function next(data) {
467
- isDone = true;
468
- resolve(data);
469
- onDone();
470
- },
471
- error: function error(data) {
472
- isDone = true;
473
- reject(data);
474
- onDone();
475
- },
476
- complete: function complete() {
477
- isDone = true;
478
- onDone();
479
- }
480
- });
481
- abort = onDone;
482
- });
483
- return {
484
- promise: promise,
485
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
486
- abort: abort
487
- };
488
- }
489
-
490
- var idCounter = 0;
491
-
492
- function getRequestId() {
493
- return ++idCounter;
494
- }
495
-
496
- var TRPCClient = /*#__PURE__*/function () {
497
- function TRPCClient(opts) {
498
- var _this = this;
499
-
500
- _classCallCheck(this, TRPCClient);
501
-
502
- this.links = void 0;
503
- this.runtime = void 0;
504
-
505
- var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
506
-
507
- var AC = getAbortController(opts === null || opts === void 0 ? void 0 : opts.AbortController);
508
-
509
- function getHeadersFn() {
510
- if (opts.headers) {
511
- var headers = opts.headers;
512
- return typeof headers === 'function' ? headers : function () {
513
- return headers;
514
- };
515
- }
516
-
517
- return function () {
518
- return {};
519
- };
520
- }
521
-
522
- this.runtime = {
523
- AbortController: AC,
524
- fetch: _fetch,
525
- headers: getHeadersFn()
526
- };
527
-
528
- if ('links' in opts) {
529
- this.links = opts.links.map(function (link) {
530
- return link(_this.runtime);
531
- });
532
- } else {
533
- this.links = [httpBatchLink({
534
- url: opts.url
535
- })(this.runtime)];
536
- }
537
- }
538
-
539
- _createClass(TRPCClient, [{
540
- key: "$request",
541
- value: function $request(_ref) {
542
- var type = _ref.type,
543
- input = _ref.input,
544
- path = _ref.path,
545
- _ref$context = _ref.context,
546
- context = _ref$context === void 0 ? {} : _ref$context;
547
- var chain$ = createChain({
548
- links: this.links,
549
- op: {
550
- id: getRequestId(),
551
- type: type,
552
- path: path,
553
- input: input,
554
- context: context
555
- }
556
- });
557
- return chain$.pipe(share());
558
- }
559
- }, {
560
- key: "requestAsPromise",
561
- value: function requestAsPromise(opts) {
562
- var req$ = this.$request(opts);
563
-
564
- var _observableToPromise = observableToPromise(req$),
565
- promise = _observableToPromise.promise,
566
- abort = _observableToPromise.abort;
567
-
568
- var cancellablePromise = new Promise(function (resolve, reject) {
569
- promise.then(function (result) {
570
- var transformed = transformOperationResult$1(result);
571
-
572
- if (transformed.ok) {
573
- resolve(transformed.data);
574
- return;
575
- }
576
-
577
- reject(transformed.error);
578
- }).catch(function (err) {
579
- reject(TRPCClientError.from(err));
580
- });
581
- });
582
- cancellablePromise.cancel = abort;
583
- return cancellablePromise;
584
- }
585
- }, {
586
- key: "query",
587
- value: function query(path) {
588
- var _ref2;
589
-
590
- var context = (_ref2 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref2 === void 0 ? void 0 : _ref2.context;
591
- return this.requestAsPromise({
592
- type: 'query',
593
- path: path,
594
- input: arguments.length <= 1 ? undefined : arguments[1],
595
- context: context
596
- });
597
- }
598
- }, {
599
- key: "mutation",
600
- value: function mutation(path) {
601
- var _ref3;
602
-
603
- var context = (_ref3 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref3 === void 0 ? void 0 : _ref3.context;
604
- return this.requestAsPromise({
605
- type: 'mutation',
606
- path: path,
607
- input: arguments.length <= 1 ? undefined : arguments[1],
608
- context: context
609
- });
610
- }
611
- }, {
612
- key: "subscription",
613
- value: function subscription(path, input, opts) {
614
- var observable$ = this.$request({
615
- type: 'subscription',
616
- path: path,
617
- input: input,
618
- context: opts.context
619
- });
620
- return observable$.subscribe({
621
- next: function next(result) {
622
- var _opts$next;
623
-
624
- if ('error' in result.data) {
625
- var _opts$error;
626
-
627
- var err = TRPCClientError.from(result.data, {
628
- meta: result.context
629
- });
630
- (_opts$error = opts.error) === null || _opts$error === void 0 ? void 0 : _opts$error.call(opts, err);
631
- return;
632
- }
633
-
634
- (_opts$next = opts.next) === null || _opts$next === void 0 ? void 0 : _opts$next.call(opts, result.data.result);
635
- },
636
- error: function error(err) {
637
- var _opts$error2;
638
-
639
- (_opts$error2 = opts.error) === null || _opts$error2 === void 0 ? void 0 : _opts$error2.call(opts, err);
640
- },
641
- complete: function complete() {
642
- var _opts$complete;
643
-
644
- (_opts$complete = opts.complete) === null || _opts$complete === void 0 ? void 0 : _opts$complete.call(opts);
645
- }
646
- });
647
- }
648
- }]);
649
-
650
- return TRPCClient;
651
- }();
652
-
653
- /* eslint-disable @typescript-eslint/no-explicit-any */
654
- function createTRPCClient(opts) {
655
- return new TRPCClient(opts);
656
- }
657
-
658
- function dedupeLink() {
659
- // initialized config
660
- return function () {
661
- // initialized in app
662
- var pending = {};
663
- return function (_ref) {
664
- var op = _ref.op,
665
- next = _ref.next;
666
-
667
- // initialized for request
668
- if (op.type !== 'query') {
669
- // pass through
670
- return next(op);
671
- }
672
-
673
- var key = JSON.stringify([op.path, op.input]);
674
-
675
- if (pending[key]) {
676
- // console.log('hooking into pending', { op });
677
- return observable(function (observer) {
678
- return pending[key].subscribe(observer);
679
- });
680
- }
681
-
682
- var shared$ = observable(function (observer) {
683
- function reset() {
684
- delete pending[key];
685
- }
686
-
687
- var subscription = next(op).subscribe({
688
- next: function next(v) {
689
- observer.next(v);
690
- },
691
- error: function error(e) {
692
- reset();
693
- observer.error(e);
694
- },
695
- complete: function complete() {
696
- reset();
697
- observer.complete();
698
- }
699
- });
700
- return function () {
701
- reset();
702
- subscription.unsubscribe();
703
- };
704
- }).pipe(share());
705
- pending[key] = shared$;
706
- return shared$;
707
- };
708
- };
709
- }
710
-
711
- function httpLink(opts) {
712
- var url = opts.url;
713
- return function (runtime) {
714
- return function (_ref) {
715
- var op = _ref.op;
716
- return observable(function (observer) {
717
- var path = op.path,
718
- input = op.input,
719
- type = op.type;
720
-
721
- var _httpRequest = httpRequest({
722
- runtime: runtime,
723
- path: path,
724
- input: input,
725
- type: type,
726
- url: url
727
- }),
728
- promise = _httpRequest.promise,
729
- cancel = _httpRequest.cancel;
730
-
731
- promise.then(function (res) {
732
- observer.next({
733
- context: res.meta,
734
- data: res.json
735
- });
736
- observer.complete();
737
- }).catch(observer.error);
738
- return function () {
739
- cancel();
740
- };
741
- });
742
- };
743
- };
744
- }
745
-
746
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
747
-
748
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
749
- var palette = {
750
- query: ['72e3ff', '3fb0d8'],
751
- mutation: ['c5a3fc', '904dfc'],
752
- subscription: ['ff49e1', 'd83fbe']
753
- };
754
-
755
- // maybe this should be moved to it's own package
756
- var defaultLogger = function defaultLogger() {
757
- var c = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : console;
758
- return function (props) {
759
- var direction = props.direction,
760
- input = props.input,
761
- type = props.type,
762
- path = props.path,
763
- context = props.context,
764
- id = props.id;
765
-
766
- var _palette$type = _slicedToArray(palette[type], 2),
767
- light = _palette$type[0],
768
- dark = _palette$type[1];
769
-
770
- var css = "\n background-color: #".concat(direction === 'up' ? light : dark, "; \n color: ").concat(direction === 'up' ? 'black' : 'white', ";\n padding: 2px;\n ");
771
- var parts = ['%c', direction === 'up' ? '>>' : '<<', type, "#".concat(id), "%c".concat(path, "%c"), '%O'];
772
- var args = [css, "".concat(css, "; font-weight: bold;"), "".concat(css, "; font-weight: normal;")];
773
-
774
- if (props.direction === 'up') {
775
- args.push({
776
- input: input,
777
- context: context
778
- });
779
- } else {
780
- args.push({
781
- input: input,
782
- result: props.result,
783
- elapsedMs: props.elapsedMs,
784
- context: context
785
- });
786
- }
787
-
788
- var fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.data) ? 'error' : 'log';
789
- c[fn].apply(null, [parts.join(' ')].concat(args));
790
- };
791
- };
792
-
793
- function loggerLink() {
794
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
795
- var _opts$enabled = opts.enabled,
796
- enabled = _opts$enabled === void 0 ? function () {
797
- return true;
798
- } : _opts$enabled;
799
- var _opts$logger = opts.logger,
800
- logger = _opts$logger === void 0 ? defaultLogger(opts.console) : _opts$logger;
801
- return function () {
802
- return function (_ref) {
803
- var op = _ref.op,
804
- next = _ref.next;
805
- return observable(function (observer) {
806
- // ->
807
- enabled(_objectSpread$1(_objectSpread$1({}, op), {}, {
808
- direction: 'up'
809
- })) && logger(_objectSpread$1(_objectSpread$1({}, op), {}, {
810
- direction: 'up'
811
- }));
812
- var requestStartTime = Date.now();
813
-
814
- function logResult(result) {
815
- var elapsedMs = Date.now() - requestStartTime;
816
- enabled(_objectSpread$1(_objectSpread$1({}, op), {}, {
817
- direction: 'down',
818
- result: result
819
- })) && logger(_objectSpread$1(_objectSpread$1({}, op), {}, {
820
- direction: 'down',
821
- elapsedMs: elapsedMs,
822
- result: result
823
- }));
824
- }
825
-
826
- return next(op).pipe(tap({
827
- next: function next(result) {
828
- logResult(result);
829
- },
830
- error: function error(result) {
831
- logResult(result);
832
- }
833
- })).subscribe(observer);
834
- });
835
- };
836
- };
837
- }
838
-
839
- function retryLink(opts) {
840
- // initialized config
841
- return function () {
842
- // initialized in app
843
- return function (_ref) {
844
- var op = _ref.op,
845
- next = _ref.next;
846
- // initialized for request
847
- return observable(function (observer) {
848
- var next$ = null;
849
- var attempts = 0;
850
- var isDone = false;
851
-
852
- function attempt() {
853
- var _next$;
854
-
855
- attempts++;
856
- (_next$ = next$) === null || _next$ === void 0 ? void 0 : _next$.unsubscribe();
857
- next$ = next(op).subscribe({
858
- error: function error(_error) {
859
- if (attempts >= opts.attempts) {
860
- observer.error(_error);
861
- return;
862
- }
863
-
864
- attempt();
865
- },
866
- next: function next(result) {
867
- if ('result' in result.data) {
868
- isDone = true;
869
- observer.next(result);
870
- return;
871
- }
872
-
873
- if (attempts >= opts.attempts) {
874
- isDone = true;
875
- observer.next(result);
876
- return;
877
- }
878
-
879
- attempt();
880
- },
881
- complete: function complete() {
882
- if (isDone) {
883
- observer.complete();
884
- }
885
- }
886
- });
887
- }
888
-
889
- attempt();
890
- return function () {
891
- var _next$2;
892
-
893
- isDone = true;
894
- (_next$2 = next$) === null || _next$2 === void 0 ? void 0 : _next$2.unsubscribe();
895
- };
896
- });
897
- };
898
- };
899
- }
900
-
901
- function asArray(value) {
902
- return Array.isArray(value) ? value : [value];
903
- }
577
+ function asArray(value) {
578
+ return Array.isArray(value) ? value : [value];
579
+ }
904
580
 
905
581
  function splitLink(opts) {
906
582
  return function (rt) {
@@ -922,17 +598,17 @@ function splitLink(opts) {
922
598
  };
923
599
  }
924
600
 
925
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
601
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
926
602
 
927
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
603
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
928
604
 
929
605
  /**
930
606
  * @internal
931
607
  */
932
- function transformOperationResult(result, transformer) {
608
+ function transformOperationResult$1(result, transformer) {
933
609
  if ('error' in result.data) {
934
- return _objectSpread(_objectSpread({}, result), {}, {
935
- data: _objectSpread(_objectSpread({}, result.data), {}, {
610
+ return _objectSpread$1(_objectSpread$1({}, result), {}, {
611
+ data: _objectSpread$1(_objectSpread$1({}, result.data), {}, {
936
612
  error: transformer.deserialize(result.data.error)
937
613
  })
938
614
  });
@@ -942,9 +618,9 @@ function transformOperationResult(result, transformer) {
942
618
  return result;
943
619
  }
944
620
 
945
- return _objectSpread(_objectSpread({}, result), {}, {
946
- data: _objectSpread(_objectSpread({}, result.data), {}, {
947
- result: _objectSpread(_objectSpread({}, result.data.result), {}, {
621
+ return _objectSpread$1(_objectSpread$1({}, result), {}, {
622
+ data: _objectSpread$1(_objectSpread$1({}, result.data), {}, {
623
+ result: _objectSpread$1(_objectSpread$1({}, result.data.result), {}, {
948
624
  data: transformer.deserialize(result.data.result.data)
949
625
  })
950
626
  })
@@ -969,11 +645,11 @@ function transformerLink(transformer) {
969
645
  var input = _transformer.serialize(props.op.input);
970
646
 
971
647
  return observable(function (observer) {
972
- var subscription = props.next(_objectSpread(_objectSpread({}, props.op), {}, {
648
+ var subscription = props.next(_objectSpread$1(_objectSpread$1({}, props.op), {}, {
973
649
  input: input
974
650
  })).subscribe({
975
651
  next: function next(value) {
976
- var transformed = transformOperationResult(value, _transformer);
652
+ var transformed = transformOperationResult$1(value, _transformer);
977
653
  observer.next(transformed);
978
654
  },
979
655
  error: function error(err) {
@@ -994,9 +670,80 @@ var retryDelay = function retryDelay(attemptIndex) {
994
670
  return attemptIndex === 0 ? 0 : Math.min(1000 * Math.pow(2, attemptIndex), 30000);
995
671
  };
996
672
 
997
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
673
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
674
+
675
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
676
+
677
+ function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
678
+
679
+ function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
680
+
681
+ var TRPCClientError = /*#__PURE__*/function (_Error) {
682
+ _inherits(TRPCClientError, _Error);
683
+
684
+ var _super = /*#__PURE__*/_createSuper$2(TRPCClientError);
685
+
686
+ /**
687
+ * @deprecated use `cause`
688
+ */
689
+ function TRPCClientError(message, opts) {
690
+ var _opts$cause, _opts$result, _opts$result2;
691
+
692
+ var _this;
693
+
694
+ _classCallCheck(this, TRPCClientError);
695
+
696
+ var cause = (_opts$cause = opts === null || opts === void 0 ? void 0 : opts.cause) !== null && _opts$cause !== void 0 ? _opts$cause : opts === null || opts === void 0 ? void 0 : opts.originalError; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
697
+ // @ts-ignore https://github.com/tc39/proposal-error-cause
698
+
699
+ _this = _super.call(this, message, {
700
+ cause: cause
701
+ });
702
+ _this.originalError = void 0;
703
+ _this.cause = void 0;
704
+ _this.shape = void 0;
705
+ _this.data = void 0;
706
+ _this.meta = void 0;
707
+ _this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
708
+ _this.cause = _this.originalError = cause;
709
+ _this.shape = opts === null || opts === void 0 ? void 0 : (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
710
+ _this.data = opts === null || opts === void 0 ? void 0 : (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
711
+ _this.name = 'TRPCClientError';
712
+ Object.setPrototypeOf(_assertThisInitialized(_this), TRPCClientError.prototype);
713
+ return _this;
714
+ }
715
+
716
+ _createClass(TRPCClientError, null, [{
717
+ key: "from",
718
+ value: function from(cause) {
719
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
720
+
721
+ if (!(cause instanceof Error)) {
722
+ var _message;
723
+
724
+ return new TRPCClientError((_message = cause.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread(_objectSpread({}, opts), {}, {
725
+ cause: null,
726
+ result: cause
727
+ }));
728
+ }
729
+
730
+ if (cause.name === 'TRPCClientError') {
731
+ return cause;
732
+ }
733
+
734
+ return new TRPCClientError(cause.message, _objectSpread(_objectSpread({}, opts), {}, {
735
+ cause: cause,
736
+ result: null
737
+ }));
738
+ }
739
+ }]);
740
+
741
+ return TRPCClientError;
742
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
743
+
744
+ function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
998
745
 
999
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
746
+ function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1000
747
  function createWSClient(opts) {
1001
748
  var url = opts.url,
1002
749
  _opts$WebSocket = opts.WebSocket,
@@ -1260,7 +1007,7 @@ function createWSClient(opts) {
1260
1007
  var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
1261
1008
  _inherits(TRPCWebSocketClosedError, _Error);
1262
1009
 
1263
- var _super = /*#__PURE__*/_createSuper(TRPCWebSocketClosedError);
1010
+ var _super = /*#__PURE__*/_createSuper$1(TRPCWebSocketClosedError);
1264
1011
 
1265
1012
  function TRPCWebSocketClosedError(message) {
1266
1013
  var _this;
@@ -1279,7 +1026,7 @@ var TRPCWebSocketClosedError = /*#__PURE__*/function (_Error) {
1279
1026
  var TRPCSubscriptionEndedError = /*#__PURE__*/function (_Error2) {
1280
1027
  _inherits(TRPCSubscriptionEndedError, _Error2);
1281
1028
 
1282
- var _super2 = /*#__PURE__*/_createSuper(TRPCSubscriptionEndedError);
1029
+ var _super2 = /*#__PURE__*/_createSuper$1(TRPCSubscriptionEndedError);
1283
1030
 
1284
1031
  function TRPCSubscriptionEndedError(message) {
1285
1032
  var _this2;
@@ -1347,4 +1094,257 @@ function wsLink(opts) {
1347
1094
  };
1348
1095
  }
1349
1096
 
1097
+ /** @internal */
1098
+ function transformOperationResult(result) {
1099
+ var context = result.context;
1100
+
1101
+ if ('error' in result.data) {
1102
+ var error = TRPCClientError.from(result.data);
1103
+ return {
1104
+ ok: false,
1105
+ error: error,
1106
+ context: context
1107
+ };
1108
+ }
1109
+
1110
+ var data = result.data.result.data;
1111
+ return {
1112
+ ok: true,
1113
+ data: data,
1114
+ context: context
1115
+ };
1116
+ }
1117
+
1118
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1119
+
1120
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1121
+
1122
+ var ObservableAbortError = /*#__PURE__*/function (_Error) {
1123
+ _inherits(ObservableAbortError, _Error);
1124
+
1125
+ var _super = /*#__PURE__*/_createSuper(ObservableAbortError);
1126
+
1127
+ function ObservableAbortError(message) {
1128
+ var _this;
1129
+
1130
+ _classCallCheck(this, ObservableAbortError);
1131
+
1132
+ _this = _super.call(this, message);
1133
+ _this.name = 'ObservableAbortError';
1134
+ Object.setPrototypeOf(_assertThisInitialized(_this), ObservableAbortError.prototype);
1135
+ return _this;
1136
+ }
1137
+
1138
+ return _createClass(ObservableAbortError);
1139
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
1140
+ /** @internal */
1141
+
1142
+ function observableToPromise(observable) {
1143
+ var abort;
1144
+ var promise = new Promise(function (resolve, reject) {
1145
+ var isDone = false;
1146
+
1147
+ function onDone() {
1148
+ if (isDone) {
1149
+ return;
1150
+ }
1151
+
1152
+ isDone = true;
1153
+ reject(new ObservableAbortError('This operation was cancelled.'));
1154
+ obs$.unsubscribe();
1155
+ }
1156
+
1157
+ var obs$ = observable.subscribe({
1158
+ next: function next(data) {
1159
+ isDone = true;
1160
+ resolve(data);
1161
+ onDone();
1162
+ },
1163
+ error: function error(data) {
1164
+ isDone = true;
1165
+ reject(data);
1166
+ onDone();
1167
+ },
1168
+ complete: function complete() {
1169
+ isDone = true;
1170
+ onDone();
1171
+ }
1172
+ });
1173
+ abort = onDone;
1174
+ });
1175
+ return {
1176
+ promise: promise,
1177
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1178
+ abort: abort
1179
+ };
1180
+ }
1181
+
1182
+ var idCounter = 0;
1183
+
1184
+ function getRequestId() {
1185
+ return ++idCounter;
1186
+ }
1187
+
1188
+ var TRPCClient = /*#__PURE__*/function () {
1189
+ function TRPCClient(opts) {
1190
+ var _this = this;
1191
+
1192
+ _classCallCheck(this, TRPCClient);
1193
+
1194
+ this.links = void 0;
1195
+ this.runtime = void 0;
1196
+
1197
+ var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
1198
+
1199
+ var AC = getAbortController(opts === null || opts === void 0 ? void 0 : opts.AbortController);
1200
+
1201
+ function getHeadersFn() {
1202
+ if (opts.headers) {
1203
+ var headers = opts.headers;
1204
+ return typeof headers === 'function' ? headers : function () {
1205
+ return headers;
1206
+ };
1207
+ }
1208
+
1209
+ return function () {
1210
+ return {};
1211
+ };
1212
+ }
1213
+
1214
+ this.runtime = {
1215
+ AbortController: AC,
1216
+ fetch: _fetch,
1217
+ headers: getHeadersFn()
1218
+ };
1219
+
1220
+ if ('links' in opts) {
1221
+ this.links = opts.links.map(function (link) {
1222
+ return link(_this.runtime);
1223
+ });
1224
+ } else {
1225
+ this.links = [httpBatchLink({
1226
+ url: opts.url
1227
+ })(this.runtime)];
1228
+ }
1229
+ }
1230
+
1231
+ _createClass(TRPCClient, [{
1232
+ key: "$request",
1233
+ value: function $request(_ref) {
1234
+ var type = _ref.type,
1235
+ input = _ref.input,
1236
+ path = _ref.path,
1237
+ _ref$context = _ref.context,
1238
+ context = _ref$context === void 0 ? {} : _ref$context;
1239
+ var chain$ = createChain({
1240
+ links: this.links,
1241
+ op: {
1242
+ id: getRequestId(),
1243
+ type: type,
1244
+ path: path,
1245
+ input: input,
1246
+ context: context
1247
+ }
1248
+ });
1249
+ return chain$.pipe(share());
1250
+ }
1251
+ }, {
1252
+ key: "requestAsPromise",
1253
+ value: function requestAsPromise(opts) {
1254
+ var req$ = this.$request(opts);
1255
+
1256
+ var _observableToPromise = observableToPromise(req$),
1257
+ promise = _observableToPromise.promise,
1258
+ abort = _observableToPromise.abort;
1259
+
1260
+ var cancellablePromise = new Promise(function (resolve, reject) {
1261
+ promise.then(function (result) {
1262
+ var transformed = transformOperationResult(result);
1263
+
1264
+ if (transformed.ok) {
1265
+ resolve(transformed.data);
1266
+ return;
1267
+ }
1268
+
1269
+ reject(transformed.error);
1270
+ }).catch(function (err) {
1271
+ reject(TRPCClientError.from(err));
1272
+ });
1273
+ });
1274
+ cancellablePromise.cancel = abort;
1275
+ return cancellablePromise;
1276
+ }
1277
+ }, {
1278
+ key: "query",
1279
+ value: function query(path) {
1280
+ var _ref2;
1281
+
1282
+ var context = (_ref2 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref2 === void 0 ? void 0 : _ref2.context;
1283
+ return this.requestAsPromise({
1284
+ type: 'query',
1285
+ path: path,
1286
+ input: arguments.length <= 1 ? undefined : arguments[1],
1287
+ context: context
1288
+ });
1289
+ }
1290
+ }, {
1291
+ key: "mutation",
1292
+ value: function mutation(path) {
1293
+ var _ref3;
1294
+
1295
+ var context = (_ref3 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref3 === void 0 ? void 0 : _ref3.context;
1296
+ return this.requestAsPromise({
1297
+ type: 'mutation',
1298
+ path: path,
1299
+ input: arguments.length <= 1 ? undefined : arguments[1],
1300
+ context: context
1301
+ });
1302
+ }
1303
+ }, {
1304
+ key: "subscription",
1305
+ value: function subscription(path, input, opts) {
1306
+ var observable$ = this.$request({
1307
+ type: 'subscription',
1308
+ path: path,
1309
+ input: input,
1310
+ context: opts.context
1311
+ });
1312
+ return observable$.subscribe({
1313
+ next: function next(result) {
1314
+ var _opts$next;
1315
+
1316
+ if ('error' in result.data) {
1317
+ var _opts$error;
1318
+
1319
+ var err = TRPCClientError.from(result.data, {
1320
+ meta: result.context
1321
+ });
1322
+ (_opts$error = opts.error) === null || _opts$error === void 0 ? void 0 : _opts$error.call(opts, err);
1323
+ return;
1324
+ }
1325
+
1326
+ (_opts$next = opts.next) === null || _opts$next === void 0 ? void 0 : _opts$next.call(opts, result.data.result);
1327
+ },
1328
+ error: function error(err) {
1329
+ var _opts$error2;
1330
+
1331
+ (_opts$error2 = opts.error) === null || _opts$error2 === void 0 ? void 0 : _opts$error2.call(opts, err);
1332
+ },
1333
+ complete: function complete() {
1334
+ var _opts$complete;
1335
+
1336
+ (_opts$complete = opts.complete) === null || _opts$complete === void 0 ? void 0 : _opts$complete.call(opts);
1337
+ }
1338
+ });
1339
+ }
1340
+ }]);
1341
+
1342
+ return TRPCClient;
1343
+ }();
1344
+
1345
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1346
+ function createTRPCClient(opts) {
1347
+ return new TRPCClient(opts);
1348
+ }
1349
+
1350
1350
  export { TRPCClientError, createTRPCClient, createWSClient, dedupeLink, getFetch, httpBatchLink, httpLink, loggerLink, retryLink, splitLink, transformerLink, wsLink };