@trpc/client 10.0.0-alpha.11 → 10.0.0-alpha.12
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.
- package/dist/{createChain-b7cb1f5a.mjs → createChain-480b6341.mjs} +4 -4
- package/dist/{createChain-3b458753.js → createChain-e77be464.js} +4 -4
- package/dist/index.js +79 -10
- package/dist/index.mjs +72 -8
- package/dist/internals/TRPCClient.d.ts +4 -2
- package/dist/internals/TRPCClient.d.ts.map +1 -1
- package/dist/links/dedupeLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +2 -2
- package/dist/links/httpBatchLink.mjs +2 -2
- package/dist/links/httpLink.js +2 -2
- package/dist/links/httpLink.mjs +2 -2
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +4 -3
- package/dist/links/loggerLink.mjs +3 -2
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +3 -3
- package/dist/links/splitLink.mjs +3 -3
- package/dist/links/transformerLink.js +2 -2
- package/dist/links/transformerLink.mjs +2 -2
- package/dist/links/types.d.ts +4 -3
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +1 -2
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +2 -2
- package/dist/links/wsLink.mjs +2 -2
- package/dist/observable/index.d.ts +4 -0
- package/dist/observable/index.d.ts.map +1 -0
- package/dist/observable/index.js +40 -0
- package/dist/observable/index.mjs +33 -0
- package/dist/{rx.ts.js → observable/index.ts.js} +0 -0
- package/dist/observable/observable.d.ts +4 -0
- package/dist/observable/observable.d.ts.map +1 -0
- package/dist/observable/operators/index.d.ts +4 -0
- package/dist/observable/operators/index.d.ts.map +1 -0
- package/dist/observable/operators/map.d.ts +3 -0
- package/dist/observable/operators/map.d.ts.map +1 -0
- package/dist/observable/operators/share.d.ts +6 -0
- package/dist/observable/operators/share.d.ts.map +1 -0
- package/dist/observable/operators/tap.d.ts +3 -0
- package/dist/observable/operators/tap.d.ts.map +1 -0
- package/dist/observable/types.d.ts +29 -0
- package/dist/observable/types.d.ts.map +1 -0
- package/dist/observable/util/identity.d.ts +2 -0
- package/dist/observable/util/identity.d.ts.map +1 -0
- package/dist/observable/util/observableToPromise.d.ts +10 -0
- package/dist/observable/util/observableToPromise.d.ts.map +1 -0
- package/dist/observable/util/pipe.d.ts +4 -0
- package/dist/observable/util/pipe.d.ts.map +1 -0
- package/dist/observable-16fde241.mjs +102 -0
- package/dist/observable-9aaca086.js +104 -0
- package/dist/share-4afc084f.js +110 -0
- package/dist/share-9f12d26c.mjs +108 -0
- package/dist/tap-aacf31bf.js +32 -0
- package/dist/tap-f567ea97.mjs +30 -0
- package/package.json +12 -12
- package/src/internals/TRPCClient.ts +8 -4
- package/src/links/dedupeLink.test.ts +3 -3
- package/src/links/dedupeLink.ts +27 -26
- package/src/links/httpBatchLink.ts +2 -2
- package/src/links/httpLink.ts +2 -2
- package/src/links/internals/createChain.test.ts +7 -7
- package/src/links/internals/createChain.ts +4 -4
- package/src/links/loggerLink.ts +3 -2
- package/src/links/retryLink.ts +3 -2
- package/src/links/splitLink.test.ts +3 -3
- package/src/links/splitLink.ts +2 -2
- package/src/links/transformerLink.ts +2 -2
- package/src/links/types.ts +4 -3
- package/src/links/wsLink.ts +3 -4
- package/src/observable/index.ts +3 -0
- package/src/observable/observable.test.ts +103 -0
- package/src/observable/observable.ts +70 -0
- package/src/observable/operators/index.ts +3 -0
- package/src/observable/operators/map.test.ts +92 -0
- package/src/observable/operators/map.ts +25 -0
- package/src/observable/operators/share.test.ts +60 -0
- package/src/observable/operators/share.ts +67 -0
- package/src/observable/operators/tap.ts +26 -0
- package/src/observable/types.ts +69 -0
- package/src/observable/util/identity.ts +3 -0
- package/src/observable/util/observableToPromise.ts +49 -0
- package/src/observable/util/pipe.ts +22 -0
- package/dist/rx.d.ts +0 -12
- package/dist/rx.d.ts.map +0 -1
- package/dist/rx.js +0 -130
- package/dist/rx.mjs +0 -114
- package/src/rx.ts +0 -82
|
@@ -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,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
|
+
}
|
package/dist/rx.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MonoTypeOperatorFunction, Observable } from 'rxjs';
|
|
2
|
-
export declare type inferObservableValue<TObservable extends Observable<any>> = TObservable extends Observable<infer TValue> ? TValue : never;
|
|
3
|
-
export declare class ObservableAbortError extends Error {
|
|
4
|
-
constructor(message: string);
|
|
5
|
-
}
|
|
6
|
-
/** @internal */
|
|
7
|
-
export declare function observableToPromise<TValue>(observable: Observable<TValue>): {
|
|
8
|
-
promise: Promise<TValue>;
|
|
9
|
-
abort: () => void;
|
|
10
|
-
};
|
|
11
|
-
export declare function share<T>(): MonoTypeOperatorFunction<T>;
|
|
12
|
-
//# sourceMappingURL=rx.d.ts.map
|
package/dist/rx.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rx.d.ts","sourceRoot":"","sources":["../src/rx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,UAAU,EAGX,MAAM,MAAM,CAAC;AAEd,oBAAY,oBAAoB,CAAC,WAAW,SAAS,UAAU,CAAC,GAAG,CAAC,IAClE,WAAW,SAAS,UAAU,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC;AAEhE,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;CAK5B;AAED,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC;;iBACvD,IAAI;EAkCtB;AAED,wBAAgB,KAAK,CAAC,CAAC,KAAK,wBAAwB,CAAC,CAAC,CAAC,CAyBtD"}
|
package/dist/rx.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
6
|
-
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
7
|
-
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
8
|
-
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
9
|
-
var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
10
|
-
var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
|
|
11
|
-
var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
|
12
|
-
var rxjs = require('rxjs');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
17
|
-
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
18
|
-
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
19
|
-
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
20
|
-
var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
|
|
21
|
-
var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
|
|
22
|
-
var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
|
|
23
|
-
|
|
24
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
25
|
-
|
|
26
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
|
-
var ObservableAbortError = /*#__PURE__*/function (_Error) {
|
|
28
|
-
_inherits__default["default"](ObservableAbortError, _Error);
|
|
29
|
-
|
|
30
|
-
var _super = /*#__PURE__*/_createSuper(ObservableAbortError);
|
|
31
|
-
|
|
32
|
-
function ObservableAbortError(message) {
|
|
33
|
-
var _this;
|
|
34
|
-
|
|
35
|
-
_classCallCheck__default["default"](this, ObservableAbortError);
|
|
36
|
-
|
|
37
|
-
_this = _super.call(this, message);
|
|
38
|
-
_this.name = 'ObservableAbortError';
|
|
39
|
-
Object.setPrototypeOf(_assertThisInitialized__default["default"](_this), ObservableAbortError.prototype);
|
|
40
|
-
return _this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return _createClass__default["default"](ObservableAbortError);
|
|
44
|
-
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
|
|
45
|
-
/** @internal */
|
|
46
|
-
|
|
47
|
-
function observableToPromise(observable) {
|
|
48
|
-
var abort;
|
|
49
|
-
var promise = new Promise(function (resolve, reject) {
|
|
50
|
-
var isDone = false;
|
|
51
|
-
|
|
52
|
-
function onDone() {
|
|
53
|
-
if (isDone) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
isDone = true;
|
|
58
|
-
reject(new ObservableAbortError('This operation was cancelled.'));
|
|
59
|
-
subscription.unsubscribe();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var subscription = observable.subscribe({
|
|
63
|
-
next: function next(data) {
|
|
64
|
-
isDone = true;
|
|
65
|
-
resolve(data);
|
|
66
|
-
onDone();
|
|
67
|
-
},
|
|
68
|
-
error: function error(data) {
|
|
69
|
-
isDone = true;
|
|
70
|
-
reject(data);
|
|
71
|
-
onDone();
|
|
72
|
-
},
|
|
73
|
-
complete: function complete() {
|
|
74
|
-
isDone = true;
|
|
75
|
-
onDone();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
abort = onDone;
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
promise: promise,
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
|
-
abort: abort
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function share() {
|
|
87
|
-
var subscribers = new Set();
|
|
88
|
-
var connection = null;
|
|
89
|
-
return function (source) {
|
|
90
|
-
return new rxjs.Observable(function (subscriber) {
|
|
91
|
-
subscribers.add(subscriber);
|
|
92
|
-
subscriber.add(function () {
|
|
93
|
-
subscribers.delete(subscriber);
|
|
94
|
-
|
|
95
|
-
if (subscribers.size === 0) {
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
97
|
-
connection.unsubscribe();
|
|
98
|
-
connection = null;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
if (!connection) {
|
|
103
|
-
connection = source.subscribe({
|
|
104
|
-
next: function next(value) {
|
|
105
|
-
return subscribers.forEach(function (s) {
|
|
106
|
-
return s.next(value);
|
|
107
|
-
});
|
|
108
|
-
},
|
|
109
|
-
error: function error(_error) {
|
|
110
|
-
return subscribers.forEach(function (s) {
|
|
111
|
-
return s.error(_error);
|
|
112
|
-
});
|
|
113
|
-
},
|
|
114
|
-
complete: function complete() {
|
|
115
|
-
return subscribers.forEach(function (s) {
|
|
116
|
-
return s.complete();
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
connection.add(function () {
|
|
121
|
-
return subscribers.clear();
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
exports.ObservableAbortError = ObservableAbortError;
|
|
129
|
-
exports.observableToPromise = observableToPromise;
|
|
130
|
-
exports.share = share;
|
package/dist/rx.mjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import _createClass from '@babel/runtime/helpers/createClass';
|
|
2
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
-
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
4
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
5
|
-
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
7
|
-
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
8
|
-
import { Observable } from 'rxjs';
|
|
9
|
-
|
|
10
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
-
|
|
12
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
|
-
var ObservableAbortError = /*#__PURE__*/function (_Error) {
|
|
14
|
-
_inherits(ObservableAbortError, _Error);
|
|
15
|
-
|
|
16
|
-
var _super = /*#__PURE__*/_createSuper(ObservableAbortError);
|
|
17
|
-
|
|
18
|
-
function ObservableAbortError(message) {
|
|
19
|
-
var _this;
|
|
20
|
-
|
|
21
|
-
_classCallCheck(this, ObservableAbortError);
|
|
22
|
-
|
|
23
|
-
_this = _super.call(this, message);
|
|
24
|
-
_this.name = 'ObservableAbortError';
|
|
25
|
-
Object.setPrototypeOf(_assertThisInitialized(_this), ObservableAbortError.prototype);
|
|
26
|
-
return _this;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return _createClass(ObservableAbortError);
|
|
30
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
31
|
-
/** @internal */
|
|
32
|
-
|
|
33
|
-
function observableToPromise(observable) {
|
|
34
|
-
var abort;
|
|
35
|
-
var promise = new Promise(function (resolve, reject) {
|
|
36
|
-
var isDone = false;
|
|
37
|
-
|
|
38
|
-
function onDone() {
|
|
39
|
-
if (isDone) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
isDone = true;
|
|
44
|
-
reject(new ObservableAbortError('This operation was cancelled.'));
|
|
45
|
-
subscription.unsubscribe();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var subscription = observable.subscribe({
|
|
49
|
-
next: function next(data) {
|
|
50
|
-
isDone = true;
|
|
51
|
-
resolve(data);
|
|
52
|
-
onDone();
|
|
53
|
-
},
|
|
54
|
-
error: function error(data) {
|
|
55
|
-
isDone = true;
|
|
56
|
-
reject(data);
|
|
57
|
-
onDone();
|
|
58
|
-
},
|
|
59
|
-
complete: function complete() {
|
|
60
|
-
isDone = true;
|
|
61
|
-
onDone();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
abort = onDone;
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
promise: promise,
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
69
|
-
abort: abort
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function share() {
|
|
73
|
-
var subscribers = new Set();
|
|
74
|
-
var connection = null;
|
|
75
|
-
return function (source) {
|
|
76
|
-
return new Observable(function (subscriber) {
|
|
77
|
-
subscribers.add(subscriber);
|
|
78
|
-
subscriber.add(function () {
|
|
79
|
-
subscribers.delete(subscriber);
|
|
80
|
-
|
|
81
|
-
if (subscribers.size === 0) {
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
|
-
connection.unsubscribe();
|
|
84
|
-
connection = null;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!connection) {
|
|
89
|
-
connection = source.subscribe({
|
|
90
|
-
next: function next(value) {
|
|
91
|
-
return subscribers.forEach(function (s) {
|
|
92
|
-
return s.next(value);
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
error: function error(_error) {
|
|
96
|
-
return subscribers.forEach(function (s) {
|
|
97
|
-
return s.error(_error);
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
complete: function complete() {
|
|
101
|
-
return subscribers.forEach(function (s) {
|
|
102
|
-
return s.complete();
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
connection.add(function () {
|
|
107
|
-
return subscribers.clear();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export { ObservableAbortError, observableToPromise, share };
|