@pezkuwi/rpc-core 16.5.5 → 16.5.8
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/LICENSE +201 -0
- package/build/LICENSE +201 -0
- package/build/README.md +3 -0
- package/build/bundle.d.ts +1 -1
- package/build/bundle.js +411 -0
- package/build/cjs/bundle.d.ts +91 -0
- package/build/cjs/bundle.js +417 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +7 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/types/base.d.ts +22 -0
- package/build/cjs/types/base.js +2 -0
- package/build/cjs/types/index.d.ts +2 -0
- package/build/cjs/types/index.js +5 -0
- package/build/cjs/types/jsonrpc.d.ts +2 -0
- package/build/cjs/types/jsonrpc.js +2 -0
- package/build/cjs/util/drr.d.ts +15 -0
- package/build/cjs/util/drr.js +31 -0
- package/build/cjs/util/index.d.ts +3 -0
- package/build/cjs/util/index.js +6 -0
- package/build/cjs/util/memo.d.ts +6 -0
- package/build/cjs/util/memo.js +18 -0
- package/build/cjs/util/refCountDelay.d.ts +3 -0
- package/build/cjs/util/refCountDelay.js +40 -0
- package/build/index.js +2 -0
- package/build/package.json +209 -0
- package/build/packageDetect.js +5 -0
- package/build/packageInfo.js +1 -0
- package/build/types/base.js +1 -0
- package/build/types/index.js +2 -0
- package/build/types/jsonrpc.js +1 -0
- package/build/util/drr.js +28 -0
- package/build/util/index.js +3 -0
- package/build/util/memo.js +15 -0
- package/build/util/refCountDelay.js +37 -0
- package/build-deno/README.md +3 -0
- package/build-deno/bundle.ts +532 -0
- package/build-deno/checkTypes.manual.ts +2 -0
- package/build-deno/index.ts +4 -0
- package/build-deno/mod.ts +2 -0
- package/build-deno/packageDetect.ts +9 -0
- package/build-deno/packageInfo.ts +3 -0
- package/build-deno/types/base.ts +26 -0
- package/build-deno/types/index.ts +4 -0
- package/build-deno/types/jsonrpc.ts +4 -0
- package/build-deno/util/drr.ts +50 -0
- package/build-deno/util/index.ts +4 -0
- package/build-deno/util/memo.ts +30 -0
- package/build-deno/util/refCountDelay.ts +43 -0
- package/build-tsc/bundle.d.ts +91 -0
- package/build-tsc/index.d.ts +2 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc/types/base.d.ts +22 -0
- package/build-tsc/types/index.d.ts +2 -0
- package/build-tsc/types/jsonrpc.d.ts +2 -0
- package/build-tsc/util/drr.d.ts +15 -0
- package/build-tsc/util/index.d.ts +3 -0
- package/build-tsc/util/memo.d.ts +6 -0
- package/build-tsc/util/refCountDelay.d.ts +3 -0
- package/build-tsc-cjs/bundle.js +417 -0
- package/build-tsc-cjs/index.js +5 -0
- package/build-tsc-cjs/packageDetect.js +7 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-cjs/types/base.js +2 -0
- package/build-tsc-cjs/types/index.js +5 -0
- package/build-tsc-cjs/types/jsonrpc.js +2 -0
- package/build-tsc-cjs/util/drr.js +31 -0
- package/build-tsc-cjs/util/index.js +6 -0
- package/build-tsc-cjs/util/memo.js +18 -0
- package/build-tsc-cjs/util/refCountDelay.js +40 -0
- package/build-tsc-esm/bundle.js +411 -0
- package/build-tsc-esm/index.js +2 -0
- package/build-tsc-esm/packageDetect.js +5 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/build-tsc-esm/types/base.js +1 -0
- package/build-tsc-esm/types/index.js +2 -0
- package/build-tsc-esm/types/jsonrpc.js +1 -0
- package/build-tsc-esm/util/drr.js +28 -0
- package/build-tsc-esm/util/index.js +3 -0
- package/build-tsc-esm/util/memo.js +15 -0
- package/build-tsc-esm/util/refCountDelay.js +37 -0
- package/bundle.d.ts +91 -0
- package/bundle.js +411 -0
- package/cjs/bundle.d.ts +91 -0
- package/cjs/bundle.js +417 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.d.ts +1 -0
- package/cjs/packageDetect.js +7 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/types/base.d.ts +22 -0
- package/cjs/types/base.js +2 -0
- package/cjs/types/index.d.ts +2 -0
- package/cjs/types/index.js +5 -0
- package/cjs/types/jsonrpc.d.ts +2 -0
- package/cjs/types/jsonrpc.js +2 -0
- package/cjs/util/drr.d.ts +15 -0
- package/cjs/util/drr.js +31 -0
- package/cjs/util/index.d.ts +3 -0
- package/cjs/util/index.js +6 -0
- package/cjs/util/memo.d.ts +6 -0
- package/cjs/util/memo.js +18 -0
- package/cjs/util/refCountDelay.d.ts +3 -0
- package/cjs/util/refCountDelay.js +40 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +186 -12
- package/packageDetect.d.ts +1 -0
- package/packageDetect.js +5 -0
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/src/bundle.ts +2 -2
- package/src/cached.spec.ts +1 -1
- package/src/checkTypes.manual.ts +1 -1
- package/src/index.spec.ts +1 -1
- package/src/index.ts +1 -1
- package/src/methodSend.spec.ts +1 -1
- package/src/mod.ts +1 -1
- package/src/packageDetect.ts +2 -2
- package/src/packageInfo.ts +3 -3
- package/src/replay.spec.ts +1 -1
- package/src/types/base.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/types/jsonrpc.ts +1 -1
- package/src/util/drr.spec.ts +1 -1
- package/src/util/drr.ts +1 -1
- package/src/util/index.ts +1 -1
- package/src/util/memo.ts +1 -1
- package/src/util/refCountDelay.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.spec.tsbuildinfo +1 -0
- package/types/base.d.ts +22 -0
- package/types/base.js +1 -0
- package/types/index.d.ts +2 -0
- package/types/index.js +2 -0
- package/types/jsonrpc.d.ts +2 -0
- package/types/jsonrpc.js +1 -0
- package/util/drr.d.ts +15 -0
- package/util/drr.js +28 -0
- package/util/index.d.ts +3 -0
- package/util/index.js +3 -0
- package/util/memo.d.ts +6 -0
- package/util/memo.js +15 -0
- package/util/refCountDelay.d.ts +3 -0
- package/util/refCountDelay.js +37 -0
package/util/drr.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
export type DrrResult = <T>(source$: Observable<T>) => Observable<T>;
|
|
3
|
+
interface Options {
|
|
4
|
+
delay?: number;
|
|
5
|
+
skipChange?: boolean;
|
|
6
|
+
skipTimeout?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
|
|
10
|
+
*
|
|
11
|
+
* @ignore
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare function drr({ delay, skipChange, skipTimeout }?: Options): DrrResult;
|
|
15
|
+
export {};
|
package/util/drr.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { catchError, distinctUntilChanged, publishReplay, refCount, tap } from 'rxjs';
|
|
2
|
+
import { stringify } from '@pezkuwi/util';
|
|
3
|
+
import { refCountDelay } from './refCountDelay.js';
|
|
4
|
+
function CMP(a, b) {
|
|
5
|
+
return stringify({ t: a }) === stringify({ t: b });
|
|
6
|
+
}
|
|
7
|
+
function ERR(error) {
|
|
8
|
+
throw error;
|
|
9
|
+
}
|
|
10
|
+
function NOOP() {
|
|
11
|
+
// empty
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
|
|
15
|
+
*
|
|
16
|
+
* @ignore
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export function drr({ delay, skipChange = false, skipTimeout = false } = {}) {
|
|
20
|
+
return (source$) => source$.pipe(catchError(ERR), skipChange
|
|
21
|
+
? tap(NOOP)
|
|
22
|
+
: distinctUntilChanged(CMP),
|
|
23
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
24
|
+
publishReplay(1), skipTimeout
|
|
25
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
26
|
+
? refCount()
|
|
27
|
+
: refCountDelay(delay));
|
|
28
|
+
}
|
package/util/index.d.ts
ADDED
package/util/index.js
ADDED
package/util/memo.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Memoized } from '@pezkuwi/util/types';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
type ObsFn<T> = (...params: unknown[]) => Observable<T>;
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare function memo<T>(instanceId: string, inner: Function): Memoized<ObsFn<T>>;
|
|
6
|
+
export {};
|
package/util/memo.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { memoize } from '@pezkuwi/util';
|
|
3
|
+
import { drr } from './drr.js';
|
|
4
|
+
/** @internal */
|
|
5
|
+
export function memo(instanceId, inner) {
|
|
6
|
+
const options = { getInstanceId: () => instanceId };
|
|
7
|
+
const cached = memoize((...params) => new Observable((observer) => {
|
|
8
|
+
const subscription = inner(...params).subscribe(observer);
|
|
9
|
+
return () => {
|
|
10
|
+
cached.unmemoize(...params);
|
|
11
|
+
subscription.unsubscribe();
|
|
12
|
+
};
|
|
13
|
+
}).pipe(drr()), options);
|
|
14
|
+
return cached;
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { asapScheduler, Observable, Subscription } from 'rxjs';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export function refCountDelay(delay = 1750) {
|
|
4
|
+
return (source) => {
|
|
5
|
+
// state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
|
|
6
|
+
let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
|
|
7
|
+
return new Observable((ob) => {
|
|
8
|
+
source.subscribe(ob);
|
|
9
|
+
if (refCount++ === 0) {
|
|
10
|
+
if (state === 1) {
|
|
11
|
+
scheduler.unsubscribe();
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
15
|
+
connection = source.connect();
|
|
16
|
+
}
|
|
17
|
+
state = 3;
|
|
18
|
+
}
|
|
19
|
+
return () => {
|
|
20
|
+
if (--refCount === 0) {
|
|
21
|
+
if (state === 2) {
|
|
22
|
+
state = 0;
|
|
23
|
+
scheduler.unsubscribe();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
// state === 3
|
|
27
|
+
state = 1;
|
|
28
|
+
scheduler = asapScheduler.schedule(() => {
|
|
29
|
+
state = 0;
|
|
30
|
+
connection.unsubscribe();
|
|
31
|
+
}, delay);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|