@trpc/client 10.0.0-alpha.21 → 10.0.0-alpha.22

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 (87) hide show
  1. package/dist/index.js +313 -270
  2. package/dist/index.mjs +301 -257
  3. package/dist/internals/TRPCClient.d.ts +12 -7
  4. package/dist/internals/TRPCClient.d.ts.map +1 -1
  5. package/dist/internals/dataLoader.d.ts +7 -6
  6. package/dist/internals/dataLoader.d.ts.map +1 -1
  7. package/dist/links/dedupeLink.d.ts.map +1 -1
  8. package/dist/links/httpBatchLink.d.ts +1 -1
  9. package/dist/links/httpBatchLink.d.ts.map +1 -1
  10. package/dist/links/index.d.ts +0 -2
  11. package/dist/links/index.d.ts.map +1 -1
  12. package/dist/links/internals/httpUtils.d.ts +15 -7
  13. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  14. package/dist/links/internals/transformOperationResult.d.ts +17 -3
  15. package/dist/links/internals/transformOperationResult.d.ts.map +1 -1
  16. package/dist/links/loggerLink.d.ts.map +1 -1
  17. package/dist/links/retryLink.d.ts.map +1 -1
  18. package/dist/links/types.d.ts +10 -7
  19. package/dist/links/types.d.ts.map +1 -1
  20. package/dist/links/wsLink.d.ts +1 -1
  21. package/dist/links/wsLink.d.ts.map +1 -1
  22. package/package.json +5 -11
  23. package/src/internals/TRPCClient.ts +48 -24
  24. package/src/internals/dataLoader.ts +116 -54
  25. package/src/links/dedupeLink.test.ts +1 -1
  26. package/src/links/dedupeLink.ts +1 -2
  27. package/src/links/httpBatchLink.ts +54 -31
  28. package/src/links/httpLink.ts +3 -3
  29. package/src/links/index.ts +0 -2
  30. package/src/links/internals/createChain.test.ts +1 -1
  31. package/src/links/internals/createChain.ts +1 -1
  32. package/src/links/internals/httpUtils.ts +52 -31
  33. package/src/links/internals/transformOperationResult.ts +40 -12
  34. package/src/links/loggerLink.ts +1 -1
  35. package/src/links/retryLink.ts +1 -2
  36. package/src/links/splitLink.test.ts +1 -1
  37. package/src/links/splitLink.ts +4 -4
  38. package/src/links/types.ts +12 -7
  39. package/src/links/wsLink.ts +11 -10
  40. package/dist/links/transformerLink.d.ts +0 -4
  41. package/dist/links/transformerLink.d.ts.map +0 -1
  42. package/dist/observable/index.d.ts +0 -4
  43. package/dist/observable/index.d.ts.map +0 -1
  44. package/dist/observable/index.js +0 -38
  45. package/dist/observable/index.mjs +0 -31
  46. package/dist/observable/index.ts.js +0 -1
  47. package/dist/observable/internals/identity.d.ts +0 -2
  48. package/dist/observable/internals/identity.d.ts.map +0 -1
  49. package/dist/observable/internals/observableToPromise.d.ts +0 -10
  50. package/dist/observable/internals/observableToPromise.d.ts.map +0 -1
  51. package/dist/observable/internals/pipe.d.ts +0 -4
  52. package/dist/observable/internals/pipe.d.ts.map +0 -1
  53. package/dist/observable/observable.d.ts +0 -4
  54. package/dist/observable/observable.d.ts.map +0 -1
  55. package/dist/observable/operators/index.d.ts +0 -4
  56. package/dist/observable/operators/index.d.ts.map +0 -1
  57. package/dist/observable/operators/map.d.ts +0 -3
  58. package/dist/observable/operators/map.d.ts.map +0 -1
  59. package/dist/observable/operators/share.d.ts +0 -6
  60. package/dist/observable/operators/share.d.ts.map +0 -1
  61. package/dist/observable/operators/tap.d.ts +0 -3
  62. package/dist/observable/operators/tap.d.ts.map +0 -1
  63. package/dist/observable/types.d.ts +0 -29
  64. package/dist/observable/types.d.ts.map +0 -1
  65. package/dist/tap-0dcdee86.js +0 -243
  66. package/dist/tap-136a9a90.mjs +0 -239
  67. package/observable/dist/trpc-client-rx.cjs.d.ts +0 -1
  68. package/observable/dist/trpc-client-rx.cjs.dev.js +0 -9
  69. package/observable/dist/trpc-client-rx.cjs.js +0 -7
  70. package/observable/dist/trpc-client-rx.cjs.prod.js +0 -9
  71. package/observable/dist/trpc-client-rx.esm.js +0 -1
  72. package/observable/index.d.ts +0 -1
  73. package/observable/index.js +0 -1
  74. package/src/links/transformerLink.ts +0 -74
  75. package/src/observable/index.ts +0 -3
  76. package/src/observable/internals/identity.ts +0 -3
  77. package/src/observable/internals/observableToPromise.ts +0 -49
  78. package/src/observable/internals/pipe.ts +0 -22
  79. package/src/observable/observable.test.ts +0 -101
  80. package/src/observable/observable.ts +0 -70
  81. package/src/observable/operators/index.ts +0 -3
  82. package/src/observable/operators/map.test.ts +0 -92
  83. package/src/observable/operators/map.ts +0 -25
  84. package/src/observable/operators/share.test.ts +0 -60
  85. package/src/observable/operators/share.ts +0 -67
  86. package/src/observable/operators/tap.ts +0 -26
  87. package/src/observable/types.ts +0 -69
@@ -1,92 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import { expectTypeOf } from 'expect-type';
3
- import { map } from '.';
4
- import { observable } from '../observable';
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
- });
@@ -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
- }
@@ -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
- >;