@trpc/client 10.0.0-alpha.1 → 10.0.0-alpha.10

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 (202) hide show
  1. package/dist/{TRPCClientError-e1da1ef0.esm.js → TRPCClientError-17b117e1.mjs} +16 -7
  2. package/dist/TRPCClientError-ec6bd2ca.js +94 -0
  3. package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -29
  4. package/dist/TRPCClientError.d.ts.map +1 -0
  5. package/dist/{createChain-93a38e1c.cjs.dev.js → createChain-3b458753.js} +2 -2
  6. package/dist/{createChain-e45e6cf2.esm.js → createChain-b7cb1f5a.mjs} +2 -2
  7. package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -5
  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-a1426e14.cjs.dev.js → httpUtils-1f9e4e3c.js} +9 -1
  12. package/dist/{httpUtils-e45c9056.esm.js → httpUtils-c09d7b79.mjs} +5 -1
  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/{trpc-client.cjs.dev.js → index.js} +24 -81
  16. package/dist/{trpc-client.esm.js → index.mjs} +17 -79
  17. package/dist/index.ts.js +1 -0
  18. package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +62 -64
  19. package/dist/internals/TRPCClient.d.ts.map +1 -0
  20. package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +16 -14
  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/links/dedupeLink.d.ts +4 -0
  27. package/dist/links/dedupeLink.d.ts.map +1 -0
  28. package/dist/links/httpBatchLink.d.ts +8 -0
  29. package/dist/links/httpBatchLink.d.ts.map +1 -0
  30. package/dist/links/httpBatchLink.js +195 -0
  31. package/dist/links/httpBatchLink.mjs +191 -0
  32. package/dist/links/httpBatchLink.ts.js +1 -0
  33. package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -4
  34. package/dist/links/httpLink.d.ts.map +1 -0
  35. package/dist/links/httpLink.js +44 -0
  36. package/dist/links/httpLink.mjs +40 -0
  37. package/dist/links/httpLink.ts.js +1 -0
  38. package/dist/{declarations/src/links → links}/httpUtils.d.ts +21 -21
  39. package/dist/links/httpUtils.d.ts.map +1 -0
  40. package/dist/{declarations/src/links → links}/internals/createChain.d.ts +7 -7
  41. package/dist/links/internals/createChain.d.ts.map +1 -0
  42. package/dist/{declarations/src/links → links}/internals/transformOperationResult.d.ts +15 -15
  43. package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
  44. package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -38
  45. package/dist/links/loggerLink.d.ts.map +1 -0
  46. package/dist/links/loggerLink.js +107 -0
  47. package/dist/links/loggerLink.mjs +98 -0
  48. package/dist/links/loggerLink.ts.js +1 -0
  49. package/dist/links/retryLink.d.ts +6 -0
  50. package/dist/links/retryLink.d.ts.map +1 -0
  51. package/dist/{declarations/src/links → links}/splitLink.d.ts +13 -13
  52. package/dist/links/splitLink.d.ts.map +1 -0
  53. package/dist/links/splitLink.js +32 -0
  54. package/dist/links/splitLink.mjs +28 -0
  55. package/dist/links/splitLink.ts.js +1 -0
  56. package/dist/{declarations/src/links → links}/transformerLink.d.ts +3 -3
  57. package/dist/links/transformerLink.d.ts.map +1 -0
  58. package/dist/links/transformerLink.js +79 -0
  59. package/dist/links/transformerLink.mjs +71 -0
  60. package/dist/links/transformerLink.ts.js +1 -0
  61. package/dist/{declarations/src/links → links}/types.d.ts +38 -39
  62. package/dist/links/types.d.ts.map +1 -0
  63. package/dist/{declarations/src/links → links}/wsLink.d.ts +20 -19
  64. package/dist/links/wsLink.d.ts.map +1 -0
  65. package/dist/links/wsLink.js +385 -0
  66. package/dist/links/wsLink.mjs +370 -0
  67. package/dist/links/wsLink.ts.js +1 -0
  68. package/dist/rx.d.ts +11 -0
  69. package/dist/rx.d.ts.map +1 -0
  70. package/dist/rx.js +88 -0
  71. package/dist/rx.mjs +73 -0
  72. package/dist/rx.ts.js +1 -0
  73. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +68 -38
  74. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +68 -38
  75. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +67 -37
  76. package/links/httpBatchLink/index.d.ts +1 -0
  77. package/links/httpBatchLink/index.js +1 -0
  78. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +52 -29
  79. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +52 -29
  80. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +52 -29
  81. package/links/httpLink/index.d.ts +1 -0
  82. package/links/httpLink/index.js +1 -0
  83. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +19 -31
  84. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +19 -31
  85. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +19 -31
  86. package/links/loggerLink/index.d.ts +1 -0
  87. package/links/loggerLink/index.js +1 -0
  88. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +7 -20
  89. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +7 -20
  90. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +7 -20
  91. package/links/splitLink/index.d.ts +1 -0
  92. package/links/splitLink/index.js +1 -0
  93. package/links/transformerLink/index.d.ts +1 -0
  94. package/links/transformerLink/index.js +1 -0
  95. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +84 -60
  96. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +84 -60
  97. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +84 -60
  98. package/links/wsLink/index.d.ts +1 -0
  99. package/links/wsLink/index.js +1 -0
  100. package/package.json +54 -23
  101. package/src/internals/TRPCClient.ts +6 -12
  102. package/src/internals/dataLoader.ts +13 -1
  103. package/src/links/dedupeLink.test.ts +3 -3
  104. package/src/links/dedupeLink.ts +28 -27
  105. package/src/links/httpBatchLink.ts +11 -5
  106. package/src/links/httpLink.ts +2 -2
  107. package/src/links/internals/createChain.test.ts +7 -7
  108. package/src/links/internals/createChain.ts +2 -2
  109. package/src/links/loggerLink.ts +2 -3
  110. package/src/links/retryLink.ts +2 -3
  111. package/src/links/splitLink.test.ts +3 -3
  112. package/src/links/splitLink.ts +2 -2
  113. package/src/links/transformerLink.ts +10 -6
  114. package/src/links/types.ts +3 -4
  115. package/src/links/wsLink.ts +4 -3
  116. package/src/{rx/util/observableToPromise.ts → rx.ts} +7 -6
  117. package/dist/TRPCClientError-a5312a5f.cjs.dev.js +0 -74
  118. package/dist/TRPCClientError-ea7d89b2.cjs.prod.js +0 -74
  119. package/dist/createChain-e45e052a.cjs.prod.js +0 -27
  120. package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
  121. package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
  122. package/dist/declarations/src/getFetch.d.ts.map +0 -1
  123. package/dist/declarations/src/index.d.ts.map +0 -1
  124. package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
  125. package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
  126. package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
  127. package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
  128. package/dist/declarations/src/links/httpBatchLink.d.ts +0 -5
  129. package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
  130. package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
  131. package/dist/declarations/src/links/httpUtils.d.ts.map +0 -1
  132. package/dist/declarations/src/links/internals/createChain.d.ts.map +0 -1
  133. package/dist/declarations/src/links/internals/transformOperationResult.d.ts.map +0 -1
  134. package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
  135. package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
  136. package/dist/declarations/src/links/transformerLink.d.ts.map +0 -1
  137. package/dist/declarations/src/links/types.d.ts.map +0 -1
  138. package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
  139. package/dist/declarations/src/rx/index.d.ts +0 -3
  140. package/dist/declarations/src/rx/index.d.ts.map +0 -1
  141. package/dist/declarations/src/rx/observable.d.ts +0 -4
  142. package/dist/declarations/src/rx/observable.d.ts.map +0 -1
  143. package/dist/declarations/src/rx/operators/index.d.ts +0 -4
  144. package/dist/declarations/src/rx/operators/index.d.ts.map +0 -1
  145. package/dist/declarations/src/rx/operators/map.d.ts +0 -3
  146. package/dist/declarations/src/rx/operators/map.d.ts.map +0 -1
  147. package/dist/declarations/src/rx/operators/share.d.ts +0 -6
  148. package/dist/declarations/src/rx/operators/share.d.ts.map +0 -1
  149. package/dist/declarations/src/rx/operators/tap.d.ts +0 -3
  150. package/dist/declarations/src/rx/operators/tap.d.ts.map +0 -1
  151. package/dist/declarations/src/rx/types.d.ts +0 -29
  152. package/dist/declarations/src/rx/types.d.ts.map +0 -1
  153. package/dist/declarations/src/rx/util/identity.d.ts +0 -2
  154. package/dist/declarations/src/rx/util/identity.d.ts.map +0 -1
  155. package/dist/declarations/src/rx/util/observableToPromise.d.ts +0 -10
  156. package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +0 -1
  157. package/dist/declarations/src/rx/util/pipe.d.ts +0 -4
  158. package/dist/declarations/src/rx/util/pipe.d.ts.map +0 -1
  159. package/dist/httpUtils-299a66f6.cjs.prod.js +0 -89
  160. package/dist/observable-01534ea8.esm.js +0 -102
  161. package/dist/observable-9aad8c3e.cjs.dev.js +0 -104
  162. package/dist/observable-ccb54234.cjs.prod.js +0 -104
  163. package/dist/share-5a8c2543.cjs.prod.js +0 -106
  164. package/dist/share-ca585761.esm.js +0 -104
  165. package/dist/share-f2ac9332.cjs.dev.js +0 -106
  166. package/dist/tap-2d565250.cjs.dev.js +0 -32
  167. package/dist/tap-606957cb.esm.js +0 -30
  168. package/dist/tap-d907998d.cjs.prod.js +0 -32
  169. package/dist/trpc-client.cjs.d.ts +0 -1
  170. package/dist/trpc-client.cjs.js +0 -7
  171. package/dist/trpc-client.cjs.prod.js +0 -300
  172. package/links/httpBatchLink/package.json +0 -4
  173. package/links/httpLink/package.json +0 -4
  174. package/links/loggerLink/package.json +0 -4
  175. package/links/splitLink/package.json +0 -4
  176. package/links/transformerLink/package.json +0 -4
  177. package/links/wsLink/package.json +0 -4
  178. package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
  179. package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
  180. package/rx/dist/trpc-client-rx.cjs.js +0 -7
  181. package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
  182. package/rx/dist/trpc-client-rx.esm.js +0 -1
  183. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
  184. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
  185. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
  186. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
  187. package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
  188. package/rx/operators/package.json +0 -4
  189. package/rx/package.json +0 -4
  190. package/src/internals/transformRPCResponse.ts +0 -25
  191. package/src/rx/index.ts +0 -2
  192. package/src/rx/observable.test.ts +0 -83
  193. package/src/rx/observable.ts +0 -70
  194. package/src/rx/operators/index.ts +0 -3
  195. package/src/rx/operators/map.test.ts +0 -92
  196. package/src/rx/operators/map.ts +0 -25
  197. package/src/rx/operators/share.test.ts +0 -60
  198. package/src/rx/operators/share.ts +0 -67
  199. package/src/rx/operators/tap.ts +0 -26
  200. package/src/rx/types.ts +0 -69
  201. package/src/rx/util/identity.ts +0 -3
  202. package/src/rx/util/pipe.ts +0 -22
@@ -1,83 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
- import { observable } from './observable';
3
- import { tap } from './operators';
4
- import { share } from './operators/share';
5
-
6
- test('vanilla observable', () => {
7
- const obs = observable<number, Error>((observer) => {
8
- observer.next(1);
9
- observer.complete();
10
- });
11
-
12
- const next = jest.fn();
13
- const error = jest.fn();
14
- const complete = jest.fn();
15
- obs.subscribe({
16
- next,
17
- error,
18
- complete,
19
- });
20
- expect(next.mock.calls).toHaveLength(1);
21
- expect(complete.mock.calls).toHaveLength(1);
22
- expect(error.mock.calls).toHaveLength(0);
23
- expect(next.mock.calls[0][0]).toBe(1);
24
- });
25
-
26
- test('pipe - combine operators', () => {
27
- const taps = {
28
- next: jest.fn(),
29
- complete: jest.fn(),
30
- error: jest.fn(),
31
- };
32
- const obs = observable<number, Error>((observer) => {
33
- observer.next(1);
34
- }).pipe(
35
- // operators:
36
- share(),
37
- tap(taps),
38
- );
39
- {
40
- const next = jest.fn();
41
- const error = jest.fn();
42
- const complete = jest.fn();
43
- obs.subscribe({
44
- next,
45
- error,
46
- complete,
47
- });
48
- expect(next.mock.calls).toHaveLength(1);
49
- expect(complete.mock.calls).toHaveLength(0);
50
- expect(error.mock.calls).toHaveLength(0);
51
- expect(next.mock.calls[0][0]).toBe(1);
52
- }
53
-
54
- {
55
- const next = jest.fn();
56
- const error = jest.fn();
57
- const complete = jest.fn();
58
- obs.subscribe({
59
- next,
60
- error,
61
- complete,
62
- });
63
- expect(next.mock.calls).toHaveLength(0);
64
- expect(complete.mock.calls).toHaveLength(0);
65
- expect(error.mock.calls).toHaveLength(0);
66
- }
67
-
68
- expect({
69
- next: taps.next.mock.calls,
70
- error: taps.error.mock.calls,
71
- complete: taps.complete.mock.calls,
72
- }).toMatchInlineSnapshot(`
73
- Object {
74
- "complete": Array [],
75
- "error": Array [],
76
- "next": Array [
77
- Array [
78
- 1,
79
- ],
80
- ],
81
- }
82
- `);
83
- });
@@ -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,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
- }