@trpc/client 10.0.0-alpha.3 → 10.0.0-alpha.32

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 (172) hide show
  1. package/dist/TRPCClientError.d.ts +3 -11
  2. package/dist/TRPCClientError.d.ts.map +1 -1
  3. package/dist/createTRPCClient.d.ts +3 -4
  4. package/dist/createTRPCClient.d.ts.map +1 -1
  5. package/dist/createTRPCClientProxy.d.ts +8 -0
  6. package/dist/createTRPCClientProxy.d.ts.map +1 -0
  7. package/dist/{httpUtils-c09d7b79.mjs → httpUtils-089853f6.mjs} +38 -30
  8. package/dist/{httpUtils-1f9e4e3c.js → httpUtils-a0169eef.js} +38 -29
  9. package/dist/index.d.ts +2 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +266 -104
  12. package/dist/index.mjs +253 -95
  13. package/dist/internals/TRPCClient.d.ts +14 -17
  14. package/dist/internals/TRPCClient.d.ts.map +1 -1
  15. package/dist/internals/dataLoader.d.ts +7 -4
  16. package/dist/internals/dataLoader.d.ts.map +1 -1
  17. package/dist/links/dedupeLink.d.ts.map +1 -1
  18. package/dist/links/httpBatchLink.d.ts +5 -2
  19. package/dist/links/httpBatchLink.d.ts.map +1 -1
  20. package/dist/links/httpBatchLink.js +197 -69
  21. package/dist/links/httpBatchLink.mjs +197 -69
  22. package/dist/links/httpLink.d.ts +1 -1
  23. package/dist/links/httpLink.d.ts.map +1 -1
  24. package/dist/links/httpLink.js +5 -5
  25. package/dist/links/httpLink.mjs +5 -5
  26. package/dist/links/index.d.ts +9 -0
  27. package/dist/links/index.d.ts.map +1 -0
  28. package/dist/links/internals/httpUtils.d.ts +30 -0
  29. package/dist/links/internals/httpUtils.d.ts.map +1 -0
  30. package/dist/links/internals/transformOperationResult.d.ts +17 -3
  31. package/dist/links/internals/transformOperationResult.d.ts.map +1 -1
  32. package/dist/links/loggerLink.d.ts.map +1 -1
  33. package/dist/links/loggerLink.js +2 -3
  34. package/dist/links/loggerLink.mjs +1 -2
  35. package/dist/links/retryLink.d.ts.map +1 -1
  36. package/dist/links/splitLink.d.ts +1 -1
  37. package/dist/links/splitLink.d.ts.map +1 -1
  38. package/dist/links/splitLink.js +3 -25
  39. package/dist/links/splitLink.mjs +2 -28
  40. package/dist/links/types.d.ts +12 -9
  41. package/dist/links/types.d.ts.map +1 -1
  42. package/dist/links/wsLink.d.ts +3 -3
  43. package/dist/links/wsLink.d.ts.map +1 -1
  44. package/dist/links/wsLink.js +11 -376
  45. package/dist/links/wsLink.mjs +9 -369
  46. package/dist/splitLink-62ff9db0.mjs +49 -0
  47. package/dist/splitLink-8202386e.js +52 -0
  48. package/dist/wsLink-69f5adb8.js +451 -0
  49. package/dist/wsLink-9468a563.mjs +436 -0
  50. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +81 -15
  51. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +81 -15
  52. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +77 -15
  53. package/links/httpBatchLink/index.d.ts +1 -1
  54. package/links/httpBatchLink/index.js +1 -1
  55. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +76 -9
  56. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +76 -9
  57. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +72 -9
  58. package/links/httpLink/index.d.ts +1 -1
  59. package/links/httpLink/index.js +1 -1
  60. package/links/loggerLink/index.d.ts +1 -1
  61. package/links/loggerLink/index.js +1 -1
  62. package/links/splitLink/index.d.ts +1 -1
  63. package/links/splitLink/index.js +1 -1
  64. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +3 -1
  65. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +3 -1
  66. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +3 -1
  67. package/links/wsLink/index.d.ts +1 -1
  68. package/links/wsLink/index.js +1 -1
  69. package/package.json +23 -30
  70. package/src/TRPCClientError.ts +5 -13
  71. package/src/createTRPCClient.ts +8 -3
  72. package/src/createTRPCClientProxy.ts +56 -0
  73. package/src/index.ts +2 -1
  74. package/src/internals/TRPCClient.ts +52 -36
  75. package/src/internals/dataLoader.ts +120 -45
  76. package/src/links/dedupeLink.test.ts +1 -1
  77. package/src/links/dedupeLink.ts +3 -5
  78. package/src/links/httpBatchLink.ts +64 -31
  79. package/src/links/httpLink.ts +4 -4
  80. package/src/links/index.ts +8 -0
  81. package/src/links/internals/createChain.test.ts +5 -5
  82. package/src/links/internals/createChain.ts +3 -3
  83. package/src/links/internals/httpUtils.ts +116 -0
  84. package/src/links/internals/transformOperationResult.ts +40 -12
  85. package/src/links/loggerLink.ts +1 -2
  86. package/src/links/retryLink.ts +1 -2
  87. package/src/links/splitLink.test.ts +3 -3
  88. package/src/links/splitLink.ts +5 -5
  89. package/src/links/types.ts +14 -9
  90. package/src/links/wsLink.ts +16 -14
  91. package/dist/TRPCClientError-17b117e1.mjs +0 -81
  92. package/dist/TRPCClientError-ec6bd2ca.js +0 -94
  93. package/dist/createChain-389cc116.mjs +0 -25
  94. package/dist/createChain-864dbb30.js +0 -27
  95. package/dist/internals/transformRPCResponse.d.ts +0 -15
  96. package/dist/internals/transformRPCResponse.d.ts.map +0 -1
  97. package/dist/links/httpUtils.d.ts +0 -22
  98. package/dist/links/httpUtils.d.ts.map +0 -1
  99. package/dist/links/transformerLink.d.ts +0 -4
  100. package/dist/links/transformerLink.d.ts.map +0 -1
  101. package/dist/links/transformerLink.js +0 -75
  102. package/dist/links/transformerLink.mjs +0 -67
  103. package/dist/links/transformerLink.ts.js +0 -1
  104. package/dist/observable-7e66cb56.mjs +0 -102
  105. package/dist/observable-85669100.js +0 -104
  106. package/dist/rx/index.d.ts +0 -3
  107. package/dist/rx/index.d.ts.map +0 -1
  108. package/dist/rx/index.js +0 -9
  109. package/dist/rx/index.mjs +0 -1
  110. package/dist/rx/index.ts.js +0 -1
  111. package/dist/rx/observable.d.ts +0 -4
  112. package/dist/rx/observable.d.ts.map +0 -1
  113. package/dist/rx/operators/index.d.ts +0 -4
  114. package/dist/rx/operators/index.d.ts.map +0 -1
  115. package/dist/rx/operators/index.js +0 -38
  116. package/dist/rx/operators/index.mjs +0 -32
  117. package/dist/rx/operators/index.ts.js +0 -1
  118. package/dist/rx/operators/map.d.ts +0 -3
  119. package/dist/rx/operators/map.d.ts.map +0 -1
  120. package/dist/rx/operators/share.d.ts +0 -6
  121. package/dist/rx/operators/share.d.ts.map +0 -1
  122. package/dist/rx/operators/tap.d.ts +0 -3
  123. package/dist/rx/operators/tap.d.ts.map +0 -1
  124. package/dist/rx/types.d.ts +0 -29
  125. package/dist/rx/types.d.ts.map +0 -1
  126. package/dist/rx/util/identity.d.ts +0 -2
  127. package/dist/rx/util/identity.d.ts.map +0 -1
  128. package/dist/rx/util/observableToPromise.d.ts +0 -10
  129. package/dist/rx/util/observableToPromise.d.ts.map +0 -1
  130. package/dist/rx/util/pipe.d.ts +0 -4
  131. package/dist/rx/util/pipe.d.ts.map +0 -1
  132. package/dist/share-4d79dc49.js +0 -110
  133. package/dist/share-671b63fa.mjs +0 -108
  134. package/dist/tap-538fa07f.mjs +0 -30
  135. package/dist/tap-799a2d33.js +0 -32
  136. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
  137. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
  138. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
  139. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
  140. package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
  141. package/links/transformerLink/index.d.ts +0 -1
  142. package/links/transformerLink/index.js +0 -1
  143. package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
  144. package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
  145. package/rx/dist/trpc-client-rx.cjs.js +0 -7
  146. package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
  147. package/rx/dist/trpc-client-rx.esm.js +0 -1
  148. package/rx/index.d.ts +0 -1
  149. package/rx/index.js +0 -1
  150. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
  151. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
  152. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
  153. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
  154. package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
  155. package/rx/operators/index.d.ts +0 -1
  156. package/rx/operators/index.js +0 -1
  157. package/src/internals/transformRPCResponse.ts +0 -25
  158. package/src/links/httpUtils.ts +0 -94
  159. package/src/links/transformerLink.ts +0 -70
  160. package/src/rx/index.ts +0 -2
  161. package/src/rx/observable.test.ts +0 -83
  162. package/src/rx/observable.ts +0 -70
  163. package/src/rx/operators/index.ts +0 -3
  164. package/src/rx/operators/map.test.ts +0 -92
  165. package/src/rx/operators/map.ts +0 -25
  166. package/src/rx/operators/share.test.ts +0 -60
  167. package/src/rx/operators/share.ts +0 -67
  168. package/src/rx/operators/tap.ts +0 -26
  169. package/src/rx/types.ts +0 -69
  170. package/src/rx/util/identity.ts +0 -3
  171. package/src/rx/util/observableToPromise.ts +0 -49
  172. package/src/rx/util/pipe.ts +0 -22
@@ -1,25 +0,0 @@
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
- }
@@ -1,60 +0,0 @@
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
- });
@@ -1,67 +0,0 @@
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
- }
@@ -1,26 +0,0 @@
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
- }
package/src/rx/types.ts DELETED
@@ -1,69 +0,0 @@
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
- >;
@@ -1,3 +0,0 @@
1
- export function identity<T>(x: T): T {
2
- return x;
3
- }
@@ -1,49 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }