@trpc/client 9.18.0 → 10.0.0-alpha.3

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 (208) hide show
  1. package/dist/TRPCClientError-17b117e1.mjs +81 -0
  2. package/dist/TRPCClientError-ec6bd2ca.js +94 -0
  3. package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -33
  4. package/dist/TRPCClientError.d.ts.map +1 -0
  5. package/dist/createChain-389cc116.mjs +25 -0
  6. package/dist/createChain-864dbb30.js +27 -0
  7. package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -6
  8. package/dist/createTRPCClient.d.ts.map +1 -0
  9. package/dist/{declarations/src/getFetch.d.ts → getFetch.d.ts} +1 -1
  10. package/dist/getFetch.d.ts.map +1 -0
  11. package/dist/httpUtils-1f9e4e3c.js +97 -0
  12. package/dist/httpUtils-c09d7b79.mjs +91 -0
  13. package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +314 -0
  16. package/dist/index.mjs +299 -0
  17. package/dist/index.ts.js +1 -0
  18. package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +64 -61
  19. package/dist/internals/TRPCClient.d.ts.map +1 -0
  20. package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +14 -16
  21. package/dist/internals/dataLoader.d.ts.map +1 -0
  22. package/dist/{declarations/src/internals → internals}/fetchHelpers.d.ts +2 -2
  23. package/dist/internals/fetchHelpers.d.ts.map +1 -0
  24. package/dist/{declarations/src/internals → internals}/retryDelay.d.ts +1 -1
  25. package/dist/internals/retryDelay.d.ts.map +1 -0
  26. package/dist/internals/transformRPCResponse.d.ts +15 -0
  27. package/dist/internals/transformRPCResponse.d.ts.map +1 -0
  28. package/dist/links/dedupeLink.d.ts +4 -0
  29. package/dist/links/dedupeLink.d.ts.map +1 -0
  30. package/dist/links/httpBatchLink.d.ts +5 -0
  31. package/dist/links/httpBatchLink.d.ts.map +1 -0
  32. package/dist/links/httpBatchLink.js +189 -0
  33. package/dist/links/httpBatchLink.mjs +185 -0
  34. package/dist/links/httpBatchLink.ts.js +1 -0
  35. package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -3
  36. package/dist/links/httpLink.d.ts.map +1 -0
  37. package/dist/links/httpLink.js +44 -0
  38. package/dist/links/httpLink.mjs +40 -0
  39. package/dist/links/httpLink.ts.js +1 -0
  40. package/dist/links/httpUtils.d.ts +22 -0
  41. package/dist/links/httpUtils.d.ts.map +1 -0
  42. package/dist/links/internals/createChain.d.ts +8 -0
  43. package/dist/links/internals/createChain.d.ts.map +1 -0
  44. package/dist/links/internals/transformOperationResult.d.ts +16 -0
  45. package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
  46. package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -37
  47. package/dist/links/loggerLink.d.ts.map +1 -0
  48. package/dist/links/loggerLink.js +108 -0
  49. package/dist/links/loggerLink.mjs +99 -0
  50. package/dist/links/loggerLink.ts.js +1 -0
  51. package/dist/links/retryLink.d.ts +6 -0
  52. package/dist/links/retryLink.d.ts.map +1 -0
  53. package/dist/links/splitLink.d.ts +14 -0
  54. package/dist/links/splitLink.d.ts.map +1 -0
  55. package/dist/links/splitLink.js +32 -0
  56. package/dist/links/splitLink.mjs +28 -0
  57. package/dist/links/splitLink.ts.js +1 -0
  58. package/dist/links/transformerLink.d.ts +4 -0
  59. package/dist/links/transformerLink.d.ts.map +1 -0
  60. package/dist/links/transformerLink.js +75 -0
  61. package/dist/links/transformerLink.mjs +67 -0
  62. package/dist/links/transformerLink.ts.js +1 -0
  63. package/dist/links/types.d.ts +40 -0
  64. package/dist/links/types.d.ts.map +1 -0
  65. package/dist/{declarations/src/links → links}/wsLink.d.ts +19 -26
  66. package/dist/links/wsLink.d.ts.map +1 -0
  67. package/dist/links/wsLink.js +384 -0
  68. package/dist/links/wsLink.mjs +370 -0
  69. package/dist/links/wsLink.ts.js +1 -0
  70. package/dist/observable-7e66cb56.mjs +102 -0
  71. package/dist/observable-85669100.js +104 -0
  72. package/dist/rx/index.d.ts +3 -0
  73. package/dist/rx/index.d.ts.map +1 -0
  74. package/dist/rx/index.js +9 -0
  75. package/dist/rx/index.mjs +1 -0
  76. package/dist/rx/index.ts.js +1 -0
  77. package/dist/rx/observable.d.ts +4 -0
  78. package/dist/rx/observable.d.ts.map +1 -0
  79. package/dist/rx/operators/index.d.ts +4 -0
  80. package/dist/rx/operators/index.d.ts.map +1 -0
  81. package/dist/rx/operators/index.js +38 -0
  82. package/dist/rx/operators/index.mjs +32 -0
  83. package/dist/rx/operators/index.ts.js +1 -0
  84. package/dist/rx/operators/map.d.ts +3 -0
  85. package/dist/rx/operators/map.d.ts.map +1 -0
  86. package/dist/rx/operators/share.d.ts +6 -0
  87. package/dist/rx/operators/share.d.ts.map +1 -0
  88. package/dist/rx/operators/tap.d.ts +3 -0
  89. package/dist/rx/operators/tap.d.ts.map +1 -0
  90. package/dist/rx/types.d.ts +29 -0
  91. package/dist/rx/types.d.ts.map +1 -0
  92. package/dist/rx/util/identity.d.ts +2 -0
  93. package/dist/rx/util/identity.d.ts.map +1 -0
  94. package/dist/rx/util/observableToPromise.d.ts +10 -0
  95. package/dist/rx/util/observableToPromise.d.ts.map +1 -0
  96. package/dist/rx/util/pipe.d.ts +4 -0
  97. package/dist/rx/util/pipe.d.ts.map +1 -0
  98. package/dist/share-4d79dc49.js +110 -0
  99. package/dist/share-671b63fa.mjs +108 -0
  100. package/dist/tap-538fa07f.mjs +30 -0
  101. package/dist/tap-799a2d33.js +32 -0
  102. package/links/httpBatchLink/index.d.ts +1 -0
  103. package/links/httpBatchLink/index.js +1 -0
  104. package/links/httpLink/index.d.ts +1 -0
  105. package/links/httpLink/index.js +1 -0
  106. package/links/loggerLink/index.d.ts +1 -0
  107. package/links/loggerLink/index.js +1 -0
  108. package/links/splitLink/index.d.ts +1 -0
  109. package/links/splitLink/index.js +1 -0
  110. package/links/transformerLink/index.d.ts +1 -0
  111. package/links/transformerLink/index.js +1 -0
  112. package/links/wsLink/index.d.ts +1 -0
  113. package/links/wsLink/index.js +1 -0
  114. package/package.json +58 -18
  115. package/rx/dist/trpc-client-rx.cjs.d.ts +1 -0
  116. package/rx/dist/trpc-client-rx.cjs.dev.js +9 -0
  117. package/rx/dist/trpc-client-rx.cjs.js +7 -0
  118. package/rx/dist/trpc-client-rx.cjs.prod.js +9 -0
  119. package/rx/dist/trpc-client-rx.esm.js +1 -0
  120. package/rx/index.d.ts +1 -0
  121. package/rx/index.js +1 -0
  122. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +1 -0
  123. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +39 -0
  124. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +7 -0
  125. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +39 -0
  126. package/rx/operators/dist/trpc-client-rx-operators.esm.js +33 -0
  127. package/rx/operators/index.d.ts +1 -0
  128. package/rx/operators/index.js +1 -0
  129. package/src/TRPCClientError.ts +17 -21
  130. package/src/createTRPCClient.ts +4 -3
  131. package/src/index.ts +1 -1
  132. package/src/internals/TRPCClient.ts +80 -88
  133. package/src/internals/dataLoader.ts +2 -14
  134. package/src/internals/transformRPCResponse.ts +2 -2
  135. package/src/links/dedupeLink.test.ts +134 -0
  136. package/src/links/dedupeLink.ts +53 -0
  137. package/src/links/httpBatchLink.ts +36 -52
  138. package/src/links/httpLink.ts +26 -37
  139. package/src/{internals/httpRequest.ts → links/httpUtils.ts} +30 -21
  140. package/src/links/internals/createChain.test.ts +132 -0
  141. package/src/links/internals/createChain.ts +31 -0
  142. package/src/links/internals/transformOperationResult.ts +25 -0
  143. package/src/links/loggerLink.ts +40 -22
  144. package/src/links/retryLink.ts +45 -14
  145. package/src/links/splitLink.test.ts +56 -0
  146. package/src/links/splitLink.ts +23 -38
  147. package/src/links/transformerLink.ts +70 -0
  148. package/src/links/{core.ts → types.ts} +40 -46
  149. package/src/links/wsLink.ts +56 -77
  150. package/src/rx/index.ts +2 -0
  151. package/src/rx/observable.test.ts +83 -0
  152. package/src/rx/observable.ts +70 -0
  153. package/src/rx/operators/index.ts +3 -0
  154. package/src/rx/operators/map.test.ts +92 -0
  155. package/src/rx/operators/map.ts +25 -0
  156. package/src/rx/operators/share.test.ts +60 -0
  157. package/src/rx/operators/share.ts +67 -0
  158. package/src/rx/operators/tap.ts +26 -0
  159. package/src/rx/types.ts +69 -0
  160. package/src/rx/util/identity.ts +3 -0
  161. package/src/rx/util/observableToPromise.ts +49 -0
  162. package/src/rx/util/pipe.ts +22 -0
  163. package/dist/TRPCClientError-09b8a26b.esm.js +0 -77
  164. package/dist/TRPCClientError-bfee2bf5.cjs.dev.js +0 -79
  165. package/dist/TRPCClientError-e9bf96e9.cjs.prod.js +0 -79
  166. package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
  167. package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
  168. package/dist/declarations/src/getFetch.d.ts.map +0 -1
  169. package/dist/declarations/src/index.d.ts.map +0 -1
  170. package/dist/declarations/src/internals/TRPCAbortError.d.ts +0 -4
  171. package/dist/declarations/src/internals/TRPCAbortError.d.ts.map +0 -1
  172. package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
  173. package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
  174. package/dist/declarations/src/internals/executeChain.d.ts +0 -8
  175. package/dist/declarations/src/internals/executeChain.d.ts.map +0 -1
  176. package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
  177. package/dist/declarations/src/internals/httpRequest.d.ts +0 -14
  178. package/dist/declarations/src/internals/httpRequest.d.ts.map +0 -1
  179. package/dist/declarations/src/internals/observable.d.ts +0 -18
  180. package/dist/declarations/src/internals/observable.d.ts.map +0 -1
  181. package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
  182. package/dist/declarations/src/internals/transformRPCResponse.d.ts +0 -7
  183. package/dist/declarations/src/internals/transformRPCResponse.d.ts.map +0 -1
  184. package/dist/declarations/src/links/core.d.ts +0 -45
  185. package/dist/declarations/src/links/core.d.ts.map +0 -1
  186. package/dist/declarations/src/links/httpBatchLink.d.ts +0 -7
  187. package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
  188. package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
  189. package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
  190. package/dist/declarations/src/links/splitLink.d.ts +0 -24
  191. package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
  192. package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
  193. package/dist/transformRPCResponse-57e80136.cjs.dev.js +0 -133
  194. package/dist/transformRPCResponse-739c13d0.cjs.prod.js +0 -133
  195. package/dist/transformRPCResponse-f7f8b0e1.esm.js +0 -129
  196. package/dist/trpc-client.cjs.d.ts +0 -1
  197. package/dist/trpc-client.cjs.dev.js +0 -379
  198. package/dist/trpc-client.cjs.js +0 -7
  199. package/dist/trpc-client.cjs.prod.js +0 -379
  200. package/dist/trpc-client.esm.js +0 -374
  201. package/links/httpBatchLink/package.json +0 -4
  202. package/links/httpLink/package.json +0 -4
  203. package/links/loggerLink/package.json +0 -4
  204. package/links/splitLink/package.json +0 -4
  205. package/links/wsLink/package.json +0 -4
  206. package/src/internals/TRPCAbortError.ts +0 -7
  207. package/src/internals/executeChain.ts +0 -67
  208. package/src/internals/observable.ts +0 -89
@@ -0,0 +1,92 @@
1
+ import { expectTypeOf } from 'expect-type';
2
+ import { observable } from '../observable';
3
+ import { map } from '.';
4
+ import { EventEmitter } from 'events';
5
+
6
+ interface SubscriptionEvents<TOutput> {
7
+ data: (data: TOutput) => void;
8
+ }
9
+
10
+ declare interface CustomEventEmitter<TOutput> {
11
+ on<U extends keyof SubscriptionEvents<TOutput>>(
12
+ event: U,
13
+ listener: SubscriptionEvents<TOutput>[U],
14
+ ): this;
15
+
16
+ once<U extends keyof SubscriptionEvents<TOutput>>(
17
+ event: U,
18
+ listener: SubscriptionEvents<TOutput>[U],
19
+ ): this;
20
+
21
+ emit<U extends keyof SubscriptionEvents<TOutput>>(
22
+ event: U,
23
+ ...args: Parameters<SubscriptionEvents<TOutput>[U]>
24
+ ): boolean;
25
+ }
26
+ class CustomEventEmitter<TOutput>
27
+ extends EventEmitter
28
+ implements CustomEventEmitter<TOutput> {}
29
+ test('map', () => {
30
+ type EventShape = { num: number };
31
+ const ee = new CustomEventEmitter<EventShape>();
32
+ const eventObservable = observable<EventShape, unknown>((observer) => {
33
+ const callback = (data: EventShape) => {
34
+ observer.next(data);
35
+ };
36
+ ee.on('data', callback);
37
+
38
+ return () => {
39
+ ee.off('data', callback);
40
+ };
41
+ });
42
+ const pipeCalls = jest.fn();
43
+ const piped = eventObservable.pipe(
44
+ map((...args) => {
45
+ pipeCalls(...args);
46
+ const [value] = args;
47
+ return value.num;
48
+ }),
49
+ );
50
+
51
+ const next = jest.fn();
52
+ const subscription = piped.subscribe({
53
+ next(value) {
54
+ expectTypeOf<number>(value);
55
+ next(value);
56
+ },
57
+ });
58
+ expect(next).not.toHaveBeenCalled();
59
+ ee.emit('data', { num: 1 });
60
+ ee.emit('data', { num: 2 });
61
+ expect(next).toHaveBeenCalledTimes(2);
62
+ expect(next.mock.calls).toMatchInlineSnapshot(`
63
+ Array [
64
+ Array [
65
+ 1,
66
+ ],
67
+ Array [
68
+ 2,
69
+ ],
70
+ ]
71
+ `);
72
+ expect(pipeCalls.mock.calls).toMatchInlineSnapshot(`
73
+ Array [
74
+ Array [
75
+ Object {
76
+ "num": 1,
77
+ },
78
+ 0,
79
+ ],
80
+ Array [
81
+ Object {
82
+ "num": 2,
83
+ },
84
+ 1,
85
+ ],
86
+ ]
87
+ `);
88
+
89
+ expect(ee.listeners('data')).toHaveLength(1);
90
+ subscription.unsubscribe();
91
+ expect(ee.listeners('data')).toHaveLength(0);
92
+ });
@@ -0,0 +1,25 @@
1
+ import { OperatorFunction } from '../types';
2
+
3
+ export function map<TValueBefore, TError, TValueAfter>(
4
+ project: (value: TValueBefore, index: number) => TValueAfter,
5
+ ): OperatorFunction<TValueBefore, TError, TValueAfter, TError> {
6
+ return (originalObserver) => {
7
+ return {
8
+ subscribe(observer) {
9
+ let index = 0;
10
+ const subscription = originalObserver.subscribe({
11
+ next(value) {
12
+ observer.next?.(project(value, index++));
13
+ },
14
+ error(error) {
15
+ observer.error?.(error);
16
+ },
17
+ complete() {
18
+ observer.complete?.();
19
+ },
20
+ });
21
+ return subscription;
22
+ },
23
+ };
24
+ };
25
+ }
@@ -0,0 +1,60 @@
1
+ /* eslint-disable no-var */
2
+ import { observable } from '../observable';
3
+ import { share } from './share';
4
+
5
+ test('share', () => {
6
+ const obs = share()(
7
+ observable<number, Error>((observer) => {
8
+ observer.next(1);
9
+ }),
10
+ );
11
+
12
+ {
13
+ const next = jest.fn();
14
+ const error = jest.fn();
15
+ const complete = jest.fn();
16
+ var subscription1 = obs.subscribe({
17
+ next,
18
+ error,
19
+ complete,
20
+ });
21
+ expect(next.mock.calls).toHaveLength(1);
22
+ expect(complete.mock.calls).toHaveLength(0);
23
+ expect(error.mock.calls).toHaveLength(0);
24
+ expect(next.mock.calls[0][0]).toBe(1);
25
+ }
26
+
27
+ {
28
+ // subscribe again - it's shared so should not propagate any results
29
+ const next = jest.fn();
30
+ const error = jest.fn();
31
+ const complete = jest.fn();
32
+ var subscription2 = obs.subscribe({
33
+ next,
34
+ error,
35
+ complete,
36
+ });
37
+ expect(next.mock.calls).toHaveLength(0);
38
+ expect(complete.mock.calls).toHaveLength(0);
39
+ expect(error.mock.calls).toHaveLength(0);
40
+ }
41
+
42
+ subscription1.unsubscribe();
43
+ subscription2.unsubscribe();
44
+ // now it should be reset so we can do a new subscription
45
+ {
46
+ const next = jest.fn();
47
+ const error = jest.fn();
48
+ const complete = jest.fn();
49
+ var subscription3 = obs.subscribe({
50
+ next,
51
+ error,
52
+ complete,
53
+ });
54
+ expect(next.mock.calls).toHaveLength(1);
55
+ expect(complete.mock.calls).toHaveLength(0);
56
+ expect(error.mock.calls).toHaveLength(0);
57
+ expect(next.mock.calls[0][0]).toBe(1);
58
+ subscription3.unsubscribe();
59
+ }
60
+ });
@@ -0,0 +1,67 @@
1
+ import { MonoTypeOperatorFunction, Observer, Unsubscribable } from '../types';
2
+
3
+ /* eslint-disable @typescript-eslint/no-empty-interface */
4
+ interface ShareConfig {}
5
+ export function share<TValue, TError>(
6
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7
+ _opts?: ShareConfig,
8
+ ): MonoTypeOperatorFunction<TValue, TError> {
9
+ return (originalObserver) => {
10
+ let refCount = 0;
11
+
12
+ let subscription: Unsubscribable | null = null;
13
+ const observers: Partial<Observer<TValue, TError>>[] = [];
14
+
15
+ function startIfNeeded() {
16
+ if (subscription) {
17
+ return;
18
+ }
19
+ subscription = originalObserver.subscribe({
20
+ next(value) {
21
+ for (const observer of observers) {
22
+ observer.next?.(value);
23
+ }
24
+ },
25
+ error(error) {
26
+ for (const observer of observers) {
27
+ observer.error?.(error);
28
+ }
29
+ },
30
+ complete() {
31
+ for (const observer of observers) {
32
+ observer.complete?.();
33
+ }
34
+ },
35
+ });
36
+ }
37
+ function resetIfNeeded() {
38
+ // "resetOnRefCountZero"
39
+ if (refCount === 0 && subscription) {
40
+ const _sub = subscription;
41
+ subscription = null;
42
+ _sub.unsubscribe();
43
+ }
44
+ }
45
+
46
+ return {
47
+ subscribe(observer) {
48
+ refCount++;
49
+
50
+ observers.push(observer);
51
+ startIfNeeded();
52
+ return {
53
+ unsubscribe() {
54
+ refCount--;
55
+ resetIfNeeded();
56
+
57
+ const index = observers.findIndex((v) => v === observer);
58
+
59
+ if (index > -1) {
60
+ observers.splice(index, 1);
61
+ }
62
+ },
63
+ };
64
+ },
65
+ };
66
+ };
67
+ }
@@ -0,0 +1,26 @@
1
+ import { MonoTypeOperatorFunction, Observer } from '../types';
2
+
3
+ export function tap<TValue, TError>(
4
+ observer: Partial<Observer<TValue, TError>>,
5
+ ): MonoTypeOperatorFunction<TValue, TError> {
6
+ return (originalObserver) => {
7
+ return {
8
+ subscribe(observer2) {
9
+ return originalObserver.subscribe({
10
+ next(v) {
11
+ observer.next?.(v);
12
+ observer2.next?.(v);
13
+ },
14
+ error(v) {
15
+ observer.error?.(v);
16
+ observer2.error?.(v);
17
+ },
18
+ complete() {
19
+ observer.complete?.();
20
+ observer2.complete?.();
21
+ },
22
+ });
23
+ },
24
+ };
25
+ };
26
+ }
@@ -0,0 +1,69 @@
1
+ export interface Unsubscribable {
2
+ unsubscribe(): void;
3
+ }
4
+ export type UnsubscribeFn = () => void;
5
+ export interface Subscribable<TValue, TError> {
6
+ subscribe(observer: Partial<Observer<TValue, TError>>): Unsubscribable;
7
+ }
8
+ export interface Observable<TValue, TError>
9
+ extends Subscribable<TValue, TError> {
10
+ pipe(): Observable<TValue, TError>;
11
+ pipe<V1, E1>(
12
+ op1: OperatorFunction<TValue, TError, V1, E1>,
13
+ ): Observable<V1, E1>;
14
+ pipe<V1, E1, V2, E2>(
15
+ op1: OperatorFunction<TValue, TError, V1, E1>,
16
+ op2: OperatorFunction<V1, E1, V2, E2>,
17
+ ): Observable<V2, E2>;
18
+ pipe<V1, E1, V2, E2, V3, E3>(
19
+ op1: OperatorFunction<TValue, TError, V1, E1>,
20
+ op2: OperatorFunction<V1, E1, V2, E2>,
21
+ op3: OperatorFunction<V2, E2, V3, E3>,
22
+ ): Observable<V2, E2>;
23
+ pipe<V1, E1, V2, E2, V3, E3, V4, E4>(
24
+ op1: OperatorFunction<TValue, TError, V1, E1>,
25
+ op2: OperatorFunction<V1, E1, V2, E2>,
26
+ op3: OperatorFunction<V2, E2, V3, E3>,
27
+ op4: OperatorFunction<V3, E3, V4, E4>,
28
+ ): Observable<V2, E2>;
29
+ pipe<V1, E1, V2, E2, V3, E3, V4, E4, V5, E5>(
30
+ op1: OperatorFunction<TValue, TError, V1, E1>,
31
+ op2: OperatorFunction<V1, E1, V2, E2>,
32
+ op3: OperatorFunction<V2, E2, V3, E3>,
33
+ op4: OperatorFunction<V3, E3, V4, E4>,
34
+ op5: OperatorFunction<V4, E4, V5, E5>,
35
+ ): Observable<V2, E2>;
36
+ }
37
+ export interface SubscriptionLike extends Unsubscribable {
38
+ unsubscribe(): void;
39
+ readonly closed: boolean;
40
+ }
41
+
42
+ export interface Observer<TValue, TError> {
43
+ next: (value: TValue) => void;
44
+ error: (err: TError) => void;
45
+ complete: () => void;
46
+ }
47
+
48
+ export type TeardownLogic =
49
+ // | SubscriptionLike
50
+ Unsubscribable | UnsubscribeFn | void;
51
+
52
+ export type UnaryFunction<T, R> = (source: T) => R;
53
+
54
+ export type OperatorFunction<
55
+ TValueBefore,
56
+ TErrorBefore,
57
+ TValueAfter,
58
+ TErrorAfter,
59
+ > = UnaryFunction<
60
+ Subscribable<TValueBefore, TErrorBefore>,
61
+ Subscribable<TValueAfter, TErrorAfter>
62
+ >;
63
+
64
+ export type MonoTypeOperatorFunction<TValue, TError> = OperatorFunction<
65
+ TValue,
66
+ TError,
67
+ TValue,
68
+ TError
69
+ >;
@@ -0,0 +1,3 @@
1
+ export function identity<T>(x: T): T {
2
+ return x;
3
+ }
@@ -0,0 +1,49 @@
1
+ import { Observable } from '../types';
2
+
3
+ export class ObservableAbortError extends Error {
4
+ constructor(message: string) {
5
+ super(message);
6
+ this.name = 'ObservableAbortError';
7
+ Object.setPrototypeOf(this, ObservableAbortError.prototype);
8
+ }
9
+ }
10
+
11
+ /** @internal */
12
+ export function observableToPromise<TValue>(
13
+ observable: Observable<TValue, unknown>,
14
+ ) {
15
+ let abort: () => void;
16
+ const promise = new Promise<TValue>((resolve, reject) => {
17
+ let isDone = false;
18
+ function onDone() {
19
+ if (isDone) {
20
+ return;
21
+ }
22
+ isDone = true;
23
+ reject(new ObservableAbortError('This operation was cancelled.'));
24
+ obs$.unsubscribe();
25
+ }
26
+ const obs$ = observable.subscribe({
27
+ next(data) {
28
+ isDone = true;
29
+ resolve(data);
30
+ onDone();
31
+ },
32
+ error(data) {
33
+ isDone = true;
34
+ reject(data);
35
+ onDone();
36
+ },
37
+ complete() {
38
+ isDone = true;
39
+ onDone();
40
+ },
41
+ });
42
+ abort = onDone;
43
+ });
44
+ return {
45
+ promise,
46
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
47
+ abort: abort!,
48
+ };
49
+ }
@@ -0,0 +1,22 @@
1
+ import { identity } from './identity';
2
+ import { UnaryFunction } from '../types';
3
+
4
+ /** @internal */
5
+ export function pipeFromArray<T, R>(
6
+ fns: Array<UnaryFunction<T, R>>,
7
+ ): UnaryFunction<T, R> {
8
+ if (fns.length === 0) {
9
+ return identity as UnaryFunction<any, any>;
10
+ }
11
+
12
+ if (fns.length === 1) {
13
+ return fns[0];
14
+ }
15
+
16
+ return function piped(input: T): R {
17
+ return fns.reduce(
18
+ (prev: any, fn: UnaryFunction<T, R>) => fn(prev),
19
+ input as any,
20
+ );
21
+ };
22
+ }
@@ -1,77 +0,0 @@
1
- import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
2
- import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
3
- import _createClass from '@babel/runtime/helpers/esm/createClass';
4
- import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
5
- import _inherits from '@babel/runtime/helpers/esm/inherits';
6
- import _createSuper from '@babel/runtime/helpers/esm/createSuper';
7
- import _wrapNativeSuper from '@babel/runtime/helpers/esm/wrapNativeSuper';
8
-
9
- var TRPCClientError = /*#__PURE__*/function (_Error) {
10
- _inherits(TRPCClientError, _Error);
11
-
12
- var _super = /*#__PURE__*/_createSuper(TRPCClientError);
13
-
14
- /**
15
- * @deprecated use `cause`
16
- */
17
-
18
- /**
19
- * Fatal error - expect no more results after this error
20
- * Used for when WebSockets disconnect prematurely.
21
- */
22
- function TRPCClientError(message, opts) {
23
- var _opts$cause, _opts$isDone, _opts$result, _opts$result2;
24
-
25
- var _this;
26
-
27
- _classCallCheck(this, TRPCClientError);
28
-
29
- var cause = (_opts$cause = opts.cause) !== null && _opts$cause !== void 0 ? _opts$cause : opts.originalError; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
30
- // @ts-ignore https://github.com/tc39/proposal-error-cause
31
-
32
- _this = _super.call(this, message, {
33
- cause: cause
34
- });
35
- _this.originalError = void 0;
36
- _this.cause = void 0;
37
- _this.shape = void 0;
38
- _this.data = void 0;
39
- _this.isDone = void 0;
40
- _this.isDone = (_opts$isDone = opts.isDone) !== null && _opts$isDone !== void 0 ? _opts$isDone : false;
41
- _this.cause = _this.originalError = cause;
42
- _this.shape = (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
43
- _this.data = (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
44
- _this.name = 'TRPCClientError';
45
- Object.setPrototypeOf(_assertThisInitialized(_this), TRPCClientError.prototype);
46
- return _this;
47
- }
48
-
49
- _createClass(TRPCClientError, null, [{
50
- key: "from",
51
- value: function from(result) {
52
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
53
-
54
- if (!(result instanceof Error)) {
55
- var _message;
56
-
57
- return new TRPCClientError((_message = result.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread(_objectSpread({}, opts), {}, {
58
- cause: null,
59
- result: result
60
- }));
61
- }
62
-
63
- if (result.name === 'TRPCClientError') {
64
- return result;
65
- }
66
-
67
- return new TRPCClientError(result.message, _objectSpread(_objectSpread({}, opts), {}, {
68
- cause: result,
69
- result: null
70
- }));
71
- }
72
- }]);
73
-
74
- return TRPCClientError;
75
- }( /*#__PURE__*/_wrapNativeSuper(Error));
76
-
77
- export { TRPCClientError as T };
@@ -1,79 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
5
- var _createClass = require('@babel/runtime/helpers/createClass');
6
- var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
7
- var _inherits = require('@babel/runtime/helpers/inherits');
8
- var _createSuper = require('@babel/runtime/helpers/createSuper');
9
- var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
10
-
11
- var TRPCClientError = /*#__PURE__*/function (_Error) {
12
- _inherits(TRPCClientError, _Error);
13
-
14
- var _super = /*#__PURE__*/_createSuper(TRPCClientError);
15
-
16
- /**
17
- * @deprecated use `cause`
18
- */
19
-
20
- /**
21
- * Fatal error - expect no more results after this error
22
- * Used for when WebSockets disconnect prematurely.
23
- */
24
- function TRPCClientError(message, opts) {
25
- var _opts$cause, _opts$isDone, _opts$result, _opts$result2;
26
-
27
- var _this;
28
-
29
- _classCallCheck(this, TRPCClientError);
30
-
31
- var cause = (_opts$cause = opts.cause) !== null && _opts$cause !== void 0 ? _opts$cause : opts.originalError; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
- // @ts-ignore https://github.com/tc39/proposal-error-cause
33
-
34
- _this = _super.call(this, message, {
35
- cause: cause
36
- });
37
- _this.originalError = void 0;
38
- _this.cause = void 0;
39
- _this.shape = void 0;
40
- _this.data = void 0;
41
- _this.isDone = void 0;
42
- _this.isDone = (_opts$isDone = opts.isDone) !== null && _opts$isDone !== void 0 ? _opts$isDone : false;
43
- _this.cause = _this.originalError = cause;
44
- _this.shape = (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
45
- _this.data = (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
46
- _this.name = 'TRPCClientError';
47
- Object.setPrototypeOf(_assertThisInitialized(_this), TRPCClientError.prototype);
48
- return _this;
49
- }
50
-
51
- _createClass(TRPCClientError, null, [{
52
- key: "from",
53
- value: function from(result) {
54
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
55
-
56
- if (!(result instanceof Error)) {
57
- var _message;
58
-
59
- return new TRPCClientError((_message = result.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread(_objectSpread({}, opts), {}, {
60
- cause: null,
61
- result: result
62
- }));
63
- }
64
-
65
- if (result.name === 'TRPCClientError') {
66
- return result;
67
- }
68
-
69
- return new TRPCClientError(result.message, _objectSpread(_objectSpread({}, opts), {}, {
70
- cause: result,
71
- result: null
72
- }));
73
- }
74
- }]);
75
-
76
- return TRPCClientError;
77
- }( /*#__PURE__*/_wrapNativeSuper(Error));
78
-
79
- exports.TRPCClientError = TRPCClientError;
@@ -1,79 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
5
- var _createClass = require('@babel/runtime/helpers/createClass');
6
- var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
7
- var _inherits = require('@babel/runtime/helpers/inherits');
8
- var _createSuper = require('@babel/runtime/helpers/createSuper');
9
- var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
10
-
11
- var TRPCClientError = /*#__PURE__*/function (_Error) {
12
- _inherits(TRPCClientError, _Error);
13
-
14
- var _super = /*#__PURE__*/_createSuper(TRPCClientError);
15
-
16
- /**
17
- * @deprecated use `cause`
18
- */
19
-
20
- /**
21
- * Fatal error - expect no more results after this error
22
- * Used for when WebSockets disconnect prematurely.
23
- */
24
- function TRPCClientError(message, opts) {
25
- var _opts$cause, _opts$isDone, _opts$result, _opts$result2;
26
-
27
- var _this;
28
-
29
- _classCallCheck(this, TRPCClientError);
30
-
31
- var cause = (_opts$cause = opts.cause) !== null && _opts$cause !== void 0 ? _opts$cause : opts.originalError; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
32
- // @ts-ignore https://github.com/tc39/proposal-error-cause
33
-
34
- _this = _super.call(this, message, {
35
- cause: cause
36
- });
37
- _this.originalError = void 0;
38
- _this.cause = void 0;
39
- _this.shape = void 0;
40
- _this.data = void 0;
41
- _this.isDone = void 0;
42
- _this.isDone = (_opts$isDone = opts.isDone) !== null && _opts$isDone !== void 0 ? _opts$isDone : false;
43
- _this.cause = _this.originalError = cause;
44
- _this.shape = (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
45
- _this.data = (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
46
- _this.name = 'TRPCClientError';
47
- Object.setPrototypeOf(_assertThisInitialized(_this), TRPCClientError.prototype);
48
- return _this;
49
- }
50
-
51
- _createClass(TRPCClientError, null, [{
52
- key: "from",
53
- value: function from(result) {
54
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
55
-
56
- if (!(result instanceof Error)) {
57
- var _message;
58
-
59
- return new TRPCClientError((_message = result.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread(_objectSpread({}, opts), {}, {
60
- cause: null,
61
- result: result
62
- }));
63
- }
64
-
65
- if (result.name === 'TRPCClientError') {
66
- return result;
67
- }
68
-
69
- return new TRPCClientError(result.message, _objectSpread(_objectSpread({}, opts), {}, {
70
- cause: result,
71
- result: null
72
- }));
73
- }
74
- }]);
75
-
76
- return TRPCClientError;
77
- }( /*#__PURE__*/_wrapNativeSuper(Error));
78
-
79
- exports.TRPCClientError = TRPCClientError;
@@ -1 +0,0 @@
1
- {"version":3,"file":"TRPCClientError.d.ts","sourceRoot":"../../../src","sources":["TRPCClientError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,mBAAmB,CAAC,OAAO,SAAS,SAAS;IAC5D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CACzD;AAED,qBAAa,eAAe,CAAC,OAAO,SAAS,SAAS,CACpD,SAAQ,KACR,YAAW,mBAAmB,CAAC,OAAO,CAAC;IAEvC;;OAEG;IACH,SAAgB,aAAa,eAAC;IAC9B,SAAgB,KAAK,eAAC;IACtB,SAAgB,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,SAAgB,IAAI,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D;;;OAGG;IACH,SAAgB,MAAM,EAAE,OAAO,CAAC;gBAG9B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;QACJ,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC5D;;YAEI;QACJ,aAAa,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7B,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QACrB,MAAM,CAAC,EAAE,OAAO,CAAC;KAClB;WAkBW,IAAI,CAAC,OAAO,SAAS,SAAS,EAC1C,MAAM,EAAE,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,EACtC,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAO,GAC9B,eAAe,CAAC,OAAO,CAAC;CAkB5B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTRPCClient.d.ts","sourceRoot":"../../../src","sources":["createTRPCClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,uBAAuB,EACvB,UAAU,IAAI,MAAM,EACrB,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,mBAGvC;AAED,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEtE,oBAAY,UAAU,CAAC,OAAO,SAAS,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AAEpE,YAAY,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFetch.d.ts","sourceRoot":"../../../src","sources":["getFetch.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,GAAG,OAAO,KAAK,CAYvD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"../../../src","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
@@ -1,4 +0,0 @@
1
- export declare class TRPCAbortError extends Error {
2
- constructor();
3
- }
4
- //# sourceMappingURL=TRPCAbortError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TRPCAbortError.d.ts","sourceRoot":"../../../../src/internals","sources":["TRPCAbortError.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;;CAMxC"}