@trpc/client 10.0.0-alpha.9 → 10.0.0-proxy-alpha.54

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 (177) hide show
  1. package/README.md +58 -1
  2. package/dist/TRPCClientError.d.ts +16 -20
  3. package/dist/TRPCClientError.d.ts.map +1 -1
  4. package/dist/createTRPCClient.d.ts +5 -3
  5. package/dist/createTRPCClient.d.ts.map +1 -1
  6. package/dist/createTRPCClientProxy.d.ts +37 -0
  7. package/dist/createTRPCClientProxy.d.ts.map +1 -0
  8. package/dist/httpUtils-44781613.mjs +76 -0
  9. package/dist/httpUtils-801112a6.js +79 -0
  10. package/dist/index.d.ts +2 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +262 -280
  13. package/dist/index.mjs +255 -271
  14. package/dist/internals/TRPCClient.d.ts +39 -21
  15. package/dist/internals/TRPCClient.d.ts.map +1 -1
  16. package/dist/internals/dataLoader.d.ts +7 -6
  17. package/dist/internals/dataLoader.d.ts.map +1 -1
  18. package/dist/internals/fetchHelpers.d.ts +1 -1
  19. package/dist/internals/fetchHelpers.d.ts.map +1 -1
  20. package/dist/internals/retryDelay.d.ts.map +1 -1
  21. package/dist/links/dedupeLink.d.ts.map +1 -1
  22. package/dist/links/httpBatchLink.d.ts +2 -2
  23. package/dist/links/httpBatchLink.d.ts.map +1 -1
  24. package/dist/links/httpBatchLink.js +189 -172
  25. package/dist/links/httpBatchLink.mjs +189 -172
  26. package/dist/links/httpLink.d.ts +1 -1
  27. package/dist/links/httpLink.d.ts.map +1 -1
  28. package/dist/links/httpLink.js +31 -35
  29. package/dist/links/httpLink.mjs +31 -35
  30. package/dist/links/index.d.ts +9 -0
  31. package/dist/links/index.d.ts.map +1 -0
  32. package/dist/links/internals/createChain.d.ts.map +1 -1
  33. package/dist/links/internals/httpUtils.d.ts +31 -0
  34. package/dist/links/internals/httpUtils.d.ts.map +1 -0
  35. package/dist/links/internals/transformResult.d.ts +28 -0
  36. package/dist/links/internals/transformResult.d.ts.map +1 -0
  37. package/dist/links/loggerLink.d.ts +3 -3
  38. package/dist/links/loggerLink.d.ts.map +1 -1
  39. package/dist/links/loggerLink.js +90 -96
  40. package/dist/links/loggerLink.mjs +90 -91
  41. package/dist/links/retryLink.d.ts.map +1 -1
  42. package/dist/links/splitLink.d.ts +1 -1
  43. package/dist/links/splitLink.d.ts.map +1 -1
  44. package/dist/links/splitLink.js +3 -25
  45. package/dist/links/splitLink.mjs +2 -28
  46. package/dist/links/types.d.ts +13 -12
  47. package/dist/links/types.d.ts.map +1 -1
  48. package/dist/links/wsLink.d.ts +12 -5
  49. package/dist/links/wsLink.d.ts.map +1 -1
  50. package/dist/links/wsLink.js +250 -358
  51. package/dist/links/wsLink.mjs +250 -348
  52. package/dist/splitLink-695ae288.js +48 -0
  53. package/dist/splitLink-ad44a55d.mjs +45 -0
  54. package/dist/transformResult-106791d7.mjs +62 -0
  55. package/dist/transformResult-e15ccdf6.js +65 -0
  56. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +15 -13
  57. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +15 -13
  58. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +12 -10
  59. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +4 -4
  60. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +4 -4
  61. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +1 -1
  62. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +3 -1
  63. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +3 -1
  64. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +3 -1
  65. package/package.json +23 -34
  66. package/src/TRPCClientError.ts +38 -28
  67. package/src/createTRPCClient.ts +11 -3
  68. package/src/createTRPCClientProxy.ts +113 -0
  69. package/src/index.ts +2 -1
  70. package/src/internals/TRPCClient.ts +118 -77
  71. package/src/internals/dataLoader.ts +116 -53
  72. package/src/internals/fetchHelpers.ts +2 -2
  73. package/src/links/dedupeLink.test.ts +9 -15
  74. package/src/links/dedupeLink.ts +6 -7
  75. package/src/links/httpBatchLink.ts +73 -36
  76. package/src/links/httpLink.ts +18 -6
  77. package/src/links/index.ts +8 -0
  78. package/src/links/internals/createChain.test.ts +23 -38
  79. package/src/links/internals/createChain.ts +8 -3
  80. package/src/links/internals/httpUtils.ts +117 -0
  81. package/src/links/internals/transformResult.ts +40 -0
  82. package/src/links/loggerLink.ts +6 -7
  83. package/src/links/retryLink.ts +2 -3
  84. package/src/links/splitLink.test.ts +3 -3
  85. package/src/links/splitLink.ts +5 -5
  86. package/src/links/types.ts +15 -12
  87. package/src/links/wsLink.ts +57 -23
  88. package/dist/TRPCClientError-17b117e1.mjs +0 -81
  89. package/dist/TRPCClientError-ec6bd2ca.js +0 -94
  90. package/dist/createChain-389cc116.mjs +0 -25
  91. package/dist/createChain-864dbb30.js +0 -27
  92. package/dist/httpUtils-1f9e4e3c.js +0 -97
  93. package/dist/httpUtils-c09d7b79.mjs +0 -91
  94. package/dist/index.ts.js +0 -1
  95. package/dist/links/httpBatchLink.ts.js +0 -1
  96. package/dist/links/httpLink.ts.js +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/internals/transformOperationResult.d.ts +0 -16
  100. package/dist/links/internals/transformOperationResult.d.ts.map +0 -1
  101. package/dist/links/loggerLink.ts.js +0 -1
  102. package/dist/links/splitLink.ts.js +0 -1
  103. package/dist/links/transformerLink.d.ts +0 -4
  104. package/dist/links/transformerLink.d.ts.map +0 -1
  105. package/dist/links/transformerLink.js +0 -75
  106. package/dist/links/transformerLink.mjs +0 -67
  107. package/dist/links/transformerLink.ts.js +0 -1
  108. package/dist/links/wsLink.ts.js +0 -1
  109. package/dist/observable-7e66cb56.mjs +0 -102
  110. package/dist/observable-85669100.js +0 -104
  111. package/dist/rx/index.d.ts +0 -3
  112. package/dist/rx/index.d.ts.map +0 -1
  113. package/dist/rx/index.js +0 -9
  114. package/dist/rx/index.mjs +0 -1
  115. package/dist/rx/index.ts.js +0 -1
  116. package/dist/rx/observable.d.ts +0 -4
  117. package/dist/rx/observable.d.ts.map +0 -1
  118. package/dist/rx/operators/index.d.ts +0 -4
  119. package/dist/rx/operators/index.d.ts.map +0 -1
  120. package/dist/rx/operators/index.js +0 -38
  121. package/dist/rx/operators/index.mjs +0 -32
  122. package/dist/rx/operators/index.ts.js +0 -1
  123. package/dist/rx/operators/map.d.ts +0 -3
  124. package/dist/rx/operators/map.d.ts.map +0 -1
  125. package/dist/rx/operators/share.d.ts +0 -6
  126. package/dist/rx/operators/share.d.ts.map +0 -1
  127. package/dist/rx/operators/tap.d.ts +0 -3
  128. package/dist/rx/operators/tap.d.ts.map +0 -1
  129. package/dist/rx/types.d.ts +0 -29
  130. package/dist/rx/types.d.ts.map +0 -1
  131. package/dist/rx/util/identity.d.ts +0 -2
  132. package/dist/rx/util/identity.d.ts.map +0 -1
  133. package/dist/rx/util/observableToPromise.d.ts +0 -10
  134. package/dist/rx/util/observableToPromise.d.ts.map +0 -1
  135. package/dist/rx/util/pipe.d.ts +0 -4
  136. package/dist/rx/util/pipe.d.ts.map +0 -1
  137. package/dist/share-4d79dc49.js +0 -110
  138. package/dist/share-671b63fa.mjs +0 -108
  139. package/dist/tap-538fa07f.mjs +0 -30
  140. package/dist/tap-799a2d33.js +0 -32
  141. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
  142. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
  143. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
  144. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
  145. package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
  146. package/links/transformerLink/index.d.ts +0 -1
  147. package/links/transformerLink/index.js +0 -1
  148. package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
  149. package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
  150. package/rx/dist/trpc-client-rx.cjs.js +0 -7
  151. package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
  152. package/rx/dist/trpc-client-rx.esm.js +0 -1
  153. package/rx/index.d.ts +0 -1
  154. package/rx/index.js +0 -1
  155. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
  156. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
  157. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
  158. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
  159. package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
  160. package/rx/operators/index.d.ts +0 -1
  161. package/rx/operators/index.js +0 -1
  162. package/src/links/httpUtils.ts +0 -94
  163. package/src/links/internals/transformOperationResult.ts +0 -25
  164. package/src/links/transformerLink.ts +0 -70
  165. package/src/rx/index.ts +0 -2
  166. package/src/rx/observable.test.ts +0 -83
  167. package/src/rx/observable.ts +0 -70
  168. package/src/rx/operators/index.ts +0 -3
  169. package/src/rx/operators/map.test.ts +0 -92
  170. package/src/rx/operators/map.ts +0 -25
  171. package/src/rx/operators/share.test.ts +0 -60
  172. package/src/rx/operators/share.ts +0 -67
  173. package/src/rx/operators/tap.ts +0 -26
  174. package/src/rx/types.ts +0 -69
  175. package/src/rx/util/identity.ts +0 -3
  176. package/src/rx/util/observableToPromise.ts +0 -49
  177. package/src/rx/util/pipe.ts +0 -22
@@ -1,70 +0,0 @@
1
- import { pipeFromArray } from './util/pipe';
2
- import { Observable, Observer, OperatorFunction, TeardownLogic } from './types';
3
-
4
- export type inferObservableValue<TObservable extends Observable<any, any>> =
5
- TObservable extends Observable<infer TValue, any> ? TValue : never;
6
-
7
- export function observable<TValue, TError = unknown>(
8
- subscribe: (observer: Observer<TValue, TError>) => TeardownLogic,
9
- ): Observable<TValue, TError> {
10
- const self: Observable<TValue, TError> = {
11
- subscribe(observer) {
12
- let teardownRef: TeardownLogic | null = null;
13
- let isDone = false;
14
- let unsubscribed = false;
15
- let teardownImmediately = false;
16
- function unsubscribe() {
17
- if (teardownRef === null) {
18
- teardownImmediately = true;
19
- return;
20
- }
21
- if (unsubscribed) {
22
- return;
23
- }
24
- unsubscribed = true;
25
-
26
- if (typeof teardownRef === 'function') {
27
- teardownRef();
28
- } else if (teardownRef) {
29
- teardownRef.unsubscribe();
30
- }
31
- }
32
- teardownRef = subscribe({
33
- next(value) {
34
- if (isDone) {
35
- return;
36
- }
37
- observer.next?.(value);
38
- },
39
- error(err) {
40
- if (isDone) {
41
- return;
42
- }
43
- isDone = true;
44
- observer.error?.(err);
45
- unsubscribe();
46
- },
47
- complete() {
48
- if (isDone) {
49
- return;
50
- }
51
- isDone = true;
52
- observer.complete?.();
53
- unsubscribe();
54
- },
55
- });
56
- if (teardownImmediately) {
57
- unsubscribe();
58
- }
59
- return {
60
- unsubscribe,
61
- };
62
- },
63
- pipe(
64
- ...operations: OperatorFunction<any, any, any, any>[]
65
- ): Observable<any, any> {
66
- return pipeFromArray(operations)(self) as any;
67
- },
68
- };
69
- return self;
70
- }
@@ -1,3 +0,0 @@
1
- export * from './share';
2
- export * from './map';
3
- export * from './tap';
@@ -1,92 +0,0 @@
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
- });
@@ -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
- }