@blackglory/estore-js 0.6.0 → 0.7.0
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/README.md +12 -1
- package/lib/contract.d.ts +9 -1
- package/lib/contract.js +1 -1
- package/lib/contract.js.map +1 -1
- package/lib/estore-client.d.ts +1 -0
- package/lib/estore-client.js +9 -1
- package/lib/estore-client.js.map +1 -1
- package/lib/utils/rpc-client.browser.d.ts +1 -1
- package/lib/utils/rpc-client.browser.js +6 -3
- package/lib/utils/rpc-client.browser.js.map +1 -1
- package/lib/utils/rpc-client.d.ts +1 -1
- package/lib/utils/rpc-client.js +6 -3
- package/lib/utils/rpc-client.js.map +1 -1
- package/package.json +23 -23
- package/src/contract.ts +18 -2
- package/src/estore-client.ts +28 -1
- package/src/utils/rpc-client.browser.ts +12 -2
- package/src/utils/rpc-client.ts +12 -2
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ export class EStoreClient {
|
|
|
54
54
|
): Promise<number>
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* @param nextEventIndex 如果指定,
|
|
57
|
+
* @param nextEventIndex 如果指定, 则会在不匹配下一个index时抛出EventIndexConflict错误.
|
|
58
58
|
* @throws {EventIndexConflict}
|
|
59
59
|
*/
|
|
60
60
|
appendEvent(
|
|
@@ -65,6 +65,17 @@ export class EStoreClient {
|
|
|
65
65
|
, signal?: ABortSignal
|
|
66
66
|
): Promise<void>
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @param lastEventIndex 如果指定, 则会在不匹配最后一个index时抛出EventIndexConflict错误.
|
|
70
|
+
* @throws {EventIndexConflict}
|
|
71
|
+
*/
|
|
72
|
+
popEvent(
|
|
73
|
+
namespace: string
|
|
74
|
+
, itemId: string
|
|
75
|
+
, lastEventIndex?: number
|
|
76
|
+
, signal?: AbortSignal
|
|
77
|
+
): Promise<void>
|
|
78
|
+
|
|
68
79
|
getEvent(
|
|
69
80
|
namespace: string
|
|
70
81
|
, itemId: string
|
package/lib/contract.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomError } from '@blackglory/errors';
|
|
2
2
|
import { JSONValue } from 'justypes';
|
|
3
|
-
export declare const expectedVersion = "^0.4.
|
|
3
|
+
export declare const expectedVersion = "^0.4.1";
|
|
4
4
|
export interface INamespaceStats {
|
|
5
5
|
items: number;
|
|
6
6
|
}
|
|
@@ -22,6 +22,14 @@ export interface IAPI {
|
|
|
22
22
|
event: JSONValue,
|
|
23
23
|
nextEventIndex: number
|
|
24
24
|
]): null;
|
|
25
|
+
popEvent(...args: [
|
|
26
|
+
namespace: string,
|
|
27
|
+
itemId: string
|
|
28
|
+
] | [
|
|
29
|
+
namespace: string,
|
|
30
|
+
itemId: string,
|
|
31
|
+
lastEventIndex: number
|
|
32
|
+
]): null;
|
|
25
33
|
getEvent(namespace: string, itemId: string, eventIndex: number): JSONValue | null;
|
|
26
34
|
}
|
|
27
35
|
export declare class EventIndexConflict extends CustomError {
|
package/lib/contract.js
CHANGED
package/lib/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA;AAgEvC,MAAM,OAAO,kBAAmB,SAAQ,WAAW;CAAG"}
|
package/lib/estore-client.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class EStoreClient {
|
|
|
22
22
|
removeItem(namespace: string, itemId: string, signal?: AbortSignal): Promise<void>;
|
|
23
23
|
getItemSize(namespace: string, itemId: string, signal?: AbortSignal): Promise<number>;
|
|
24
24
|
appendEvent(namespace: string, itemId: string, event: JSONValue, nextEventIndex?: number, signal?: AbortSignal): Promise<void>;
|
|
25
|
+
popEvent(namespace: string, itemId: string, lastEventIndex?: number, signal?: AbortSignal): Promise<void>;
|
|
25
26
|
getEvent(namespace: string, itemId: string, index: number, signal?: AbortSignal): Promise<JSONValue | null>;
|
|
26
27
|
private withTimeout;
|
|
27
28
|
}
|
package/lib/estore-client.js
CHANGED
|
@@ -4,7 +4,7 @@ import { isntUndefined, isUndefined } from '@blackglory/prelude';
|
|
|
4
4
|
export { EventIndexConflict } from './contract.js';
|
|
5
5
|
export class EStoreClient {
|
|
6
6
|
static async create(options) {
|
|
7
|
-
const { client, close } = await createRPCClient(options.server, options.retryIntervalForReconnection);
|
|
7
|
+
const { client, close } = await createRPCClient(options.server, options.retryIntervalForReconnection, options.timeout);
|
|
8
8
|
return new EStoreClient(client, close, options.timeout);
|
|
9
9
|
}
|
|
10
10
|
constructor(client, closeClients, timeout) {
|
|
@@ -44,6 +44,14 @@ export class EStoreClient {
|
|
|
44
44
|
await this.client.appendEvent(namespace, itemId, event, nextEventIndex, this.withTimeout(signal));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
async popEvent(namespace, itemId, lastEventIndex, signal) {
|
|
48
|
+
if (isUndefined(lastEventIndex)) {
|
|
49
|
+
await this.client.popEvent(namespace, itemId, this.withTimeout(signal));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
await this.client.popEvent(namespace, itemId, lastEventIndex, this.withTimeout(signal));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
47
55
|
async getEvent(namespace, itemId, index, signal) {
|
|
48
56
|
return await this.client.getEvent(namespace, itemId, index, this.withTimeout(signal));
|
|
49
57
|
}
|
package/lib/estore-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estore-client.js","sourceRoot":"","sources":["../src/estore-client.ts"],"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I,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC;YAC1D,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAPI } from "../contract.js";
|
|
2
2
|
import { ClientProxy } from 'delight-rpc';
|
|
3
|
-
export declare function createRPCClient(url: string, retryIntervalForReconnection?: number): Promise<{
|
|
3
|
+
export declare function createRPCClient(url: string, retryIntervalForReconnection?: number, timeoutForConnection?: number): Promise<{
|
|
4
4
|
client: ClientProxy<IAPI>;
|
|
5
5
|
close: () => Promise<void>;
|
|
6
6
|
}>;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { expectedVersion } from "../contract.js";
|
|
2
2
|
import { createClient } from '@delight-rpc/extra-native-websocket';
|
|
3
3
|
import { ExtraNativeWebSocket, autoReconnect } from 'extra-native-websocket';
|
|
4
|
-
|
|
4
|
+
import { timeoutSignal } from 'extra-abort';
|
|
5
|
+
export async function createRPCClient(url, retryIntervalForReconnection, timeoutForConnection) {
|
|
5
6
|
const ws = new ExtraNativeWebSocket(() => new WebSocket(url));
|
|
6
|
-
const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection);
|
|
7
|
-
await ws.connect(
|
|
7
|
+
const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection, timeoutForConnection);
|
|
8
|
+
await ws.connect(timeoutForConnection
|
|
9
|
+
? timeoutSignal(timeoutForConnection)
|
|
10
|
+
: undefined);
|
|
8
11
|
const [client, closeClient] = createClient(ws, { expectedVersion });
|
|
9
12
|
return {
|
|
10
13
|
client,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-client.browser.js","sourceRoot":"","sources":["../../src/utils/rpc-client.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,eAAe,EAAE,uBAAwB;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"rpc-client.browser.js","sourceRoot":"","sources":["../../src/utils/rpc-client.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,eAAe,EAAE,uBAAwB;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AAClE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAW,EACX,4BAAqC,EACrC,oBAA6B;IAK7B,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7D,MAAM,mBAAmB,GAAG,aAAa,CACvC,EAAE,EACF,4BAA4B,EAC5B,oBAAoB,CACrB,CAAA;IACD,MAAM,EAAE,CAAC,OAAO,CACd,oBAAoB;QACtB,CAAC,CAAC,aAAa,CAAC,oBAAoB,CAAC;QACrC,CAAC,CAAC,SAAS,CACV,CAAA;IAED,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,YAAY,CAAO,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IAEzE,OAAO;QACL,MAAM;QACN,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,WAAW,EAAE,CAAA;YACb,mBAAmB,EAAE,CAAA;YACrB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;QAClB,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAPI } from "../contract.js";
|
|
2
2
|
import { ClientProxy } from 'delight-rpc';
|
|
3
|
-
export declare function createRPCClient(url: string, retryIntervalForReconnection?: number): Promise<{
|
|
3
|
+
export declare function createRPCClient(url: string, retryIntervalForReconnection?: number, timeoutForConnection?: number): Promise<{
|
|
4
4
|
client: ClientProxy<IAPI>;
|
|
5
5
|
close: () => Promise<void>;
|
|
6
6
|
}>;
|
package/lib/utils/rpc-client.js
CHANGED
|
@@ -2,10 +2,13 @@ import { expectedVersion } from "../contract.js";
|
|
|
2
2
|
import { createClient } from '@delight-rpc/extra-websocket';
|
|
3
3
|
import { WebSocket } from 'ws';
|
|
4
4
|
import { ExtraWebSocket, autoReconnect } from 'extra-websocket';
|
|
5
|
-
|
|
5
|
+
import { timeoutSignal } from 'extra-abort';
|
|
6
|
+
export async function createRPCClient(url, retryIntervalForReconnection, timeoutForConnection) {
|
|
6
7
|
const ws = new ExtraWebSocket(() => new WebSocket(url));
|
|
7
|
-
const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection);
|
|
8
|
-
await ws.connect(
|
|
8
|
+
const cancelAutoReconnect = autoReconnect(ws, retryIntervalForReconnection, timeoutForConnection);
|
|
9
|
+
await ws.connect(timeoutForConnection
|
|
10
|
+
? timeoutSignal(timeoutForConnection)
|
|
11
|
+
: undefined);
|
|
9
12
|
const [client, closeClient] = createClient(ws, { expectedVersion });
|
|
10
13
|
return {
|
|
11
14
|
client,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/utils/rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,eAAe,EAAE,uBAAwB;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/utils/rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,eAAe,EAAE,uBAAwB;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAW,EACX,4BAAqC,EACrC,oBAA6B;IAK7B,MAAM,EAAE,GAAG,IAAI,cAAc,CAAC,GAAG,EAAE,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,MAAM,mBAAmB,GAAG,aAAa,CACvC,EAAE,EACF,4BAA4B,EAC5B,oBAAoB,CACrB,CAAA;IACD,MAAM,EAAE,CAAC,OAAO,CACd,oBAAoB;QACtB,CAAC,CAAC,aAAa,CAAC,oBAAoB,CAAC;QACrC,CAAC,CAAC,SAAS,CACV,CAAA;IAED,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,YAAY,CAAO,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IAEzE,OAAO;QACL,MAAM;QACN,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,WAAW,EAAE,CAAA;YACb,mBAAmB,EAAE,CAAA;YACrB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAA;QAClB,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blackglory/estore-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -41,36 +41,36 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^
|
|
45
|
-
"@commitlint/config-conventional": "^
|
|
46
|
-
"@eslint/js": "^
|
|
44
|
+
"@commitlint/cli": "^20.4.4",
|
|
45
|
+
"@commitlint/config-conventional": "^20.4.4",
|
|
46
|
+
"@eslint/js": "^10.0.1",
|
|
47
47
|
"@types/ws": "^8.18.1",
|
|
48
|
-
"cross-env": "^
|
|
49
|
-
"eslint": "^
|
|
50
|
-
"extra-utils": "^
|
|
48
|
+
"cross-env": "^10.1.0",
|
|
49
|
+
"eslint": "^10.0.3",
|
|
50
|
+
"extra-utils": "^6.1.0",
|
|
51
51
|
"husky": "4",
|
|
52
52
|
"npm-run-all": "^4.1.5",
|
|
53
|
-
"rimraf": "^6.
|
|
53
|
+
"rimraf": "^6.1.3",
|
|
54
54
|
"standard-version": "^9.3.2",
|
|
55
55
|
"ts-patch": "^3.3.0",
|
|
56
56
|
"tslib": "^2.8.1",
|
|
57
|
-
"typescript": "5.
|
|
58
|
-
"typescript-eslint": "^8.
|
|
59
|
-
"typescript-transform-paths": "^3.5.
|
|
60
|
-
"vite": "^
|
|
61
|
-
"vite-tsconfig-paths": "^
|
|
62
|
-
"vitest": "^
|
|
57
|
+
"typescript": "5.9.3",
|
|
58
|
+
"typescript-eslint": "^8.57.0",
|
|
59
|
+
"typescript-transform-paths": "^3.5.6",
|
|
60
|
+
"vite": "^8.0.0",
|
|
61
|
+
"vite-tsconfig-paths": "^6.1.1",
|
|
62
|
+
"vitest": "^4.1.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@blackglory/errors": "^3.0
|
|
65
|
+
"@blackglory/errors": "^3.1.0",
|
|
66
66
|
"@blackglory/prelude": "^0.4.0",
|
|
67
|
-
"@delight-rpc/extra-native-websocket": "^0.6.
|
|
68
|
-
"@delight-rpc/extra-websocket": "^0.7.
|
|
69
|
-
"delight-rpc": "^
|
|
70
|
-
"extra-abort": "^0.4.
|
|
71
|
-
"extra-native-websocket": "^0.
|
|
72
|
-
"extra-websocket": "^0.
|
|
73
|
-
"justypes": "^4.
|
|
74
|
-
"ws": "^8.
|
|
67
|
+
"@delight-rpc/extra-native-websocket": "^0.6.6",
|
|
68
|
+
"@delight-rpc/extra-websocket": "^0.7.8",
|
|
69
|
+
"delight-rpc": "^7.0.0",
|
|
70
|
+
"extra-abort": "^0.4.1",
|
|
71
|
+
"extra-native-websocket": "^0.5.1",
|
|
72
|
+
"extra-websocket": "^0.5.1",
|
|
73
|
+
"justypes": "^4.5.0",
|
|
74
|
+
"ws": "^8.19.0"
|
|
75
75
|
}
|
|
76
76
|
}
|
package/src/contract.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CustomError } from '@blackglory/errors'
|
|
2
2
|
import { JSONValue } from 'justypes'
|
|
3
3
|
|
|
4
|
-
export const expectedVersion = '^0.4.
|
|
4
|
+
export const expectedVersion = '^0.4.1'
|
|
5
5
|
|
|
6
6
|
export interface INamespaceStats {
|
|
7
7
|
items: number
|
|
@@ -25,7 +25,7 @@ export interface IAPI {
|
|
|
25
25
|
getItemSize(namespace: string, itemId: string): number
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @param nextEventIndex 如果指定,
|
|
28
|
+
* @param nextEventIndex 如果指定, 则会在不匹配下一个index时抛出EventIndexConflict错误.
|
|
29
29
|
* @throws {EventIndexConflict}
|
|
30
30
|
*/
|
|
31
31
|
appendEvent(...args:
|
|
@@ -42,6 +42,22 @@ export interface IAPI {
|
|
|
42
42
|
]
|
|
43
43
|
): null
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @param lastEventIndex 如果指定, 则会在不匹配最后一个index时抛出EventIndexConflict错误.
|
|
47
|
+
* @throws {EventIndexConflict}
|
|
48
|
+
*/
|
|
49
|
+
popEvent(...args:
|
|
50
|
+
| [
|
|
51
|
+
namespace: string
|
|
52
|
+
, itemId: string
|
|
53
|
+
]
|
|
54
|
+
| [
|
|
55
|
+
namespace: string
|
|
56
|
+
, itemId: string
|
|
57
|
+
, lastEventIndex: number
|
|
58
|
+
]
|
|
59
|
+
): null
|
|
60
|
+
|
|
45
61
|
getEvent(
|
|
46
62
|
namespace: string
|
|
47
63
|
, itemId: string
|
package/src/estore-client.ts
CHANGED
|
@@ -17,6 +17,7 @@ export class EStoreClient {
|
|
|
17
17
|
const { client, close } = await createRPCClient(
|
|
18
18
|
options.server
|
|
19
19
|
, options.retryIntervalForReconnection
|
|
20
|
+
, options.timeout
|
|
20
21
|
)
|
|
21
22
|
return new EStoreClient(client, close, options.timeout)
|
|
22
23
|
}
|
|
@@ -92,7 +93,7 @@ export class EStoreClient {
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
|
-
* @param nextEventIndex 如果指定,
|
|
96
|
+
* @param nextEventIndex 如果指定, 则会在不匹配下一个index时抛出EventIndexConflict错误.
|
|
96
97
|
* @throws {EventIndexConflict}
|
|
97
98
|
*/
|
|
98
99
|
async appendEvent(
|
|
@@ -120,6 +121,32 @@ export class EStoreClient {
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
/**
|
|
125
|
+
* @param lastEventIndex 如果指定, 则会在不匹配最后一个index时抛出EventIndexConflict错误.
|
|
126
|
+
* @throws {EventIndexConflict}
|
|
127
|
+
*/
|
|
128
|
+
async popEvent(
|
|
129
|
+
namespace: string
|
|
130
|
+
, itemId: string
|
|
131
|
+
, lastEventIndex?: number
|
|
132
|
+
, signal?: AbortSignal
|
|
133
|
+
): Promise<void> {
|
|
134
|
+
if (isUndefined(lastEventIndex)) {
|
|
135
|
+
await this.client.popEvent(
|
|
136
|
+
namespace
|
|
137
|
+
, itemId
|
|
138
|
+
, this.withTimeout(signal)
|
|
139
|
+
)
|
|
140
|
+
} else {
|
|
141
|
+
await this.client.popEvent(
|
|
142
|
+
namespace
|
|
143
|
+
, itemId
|
|
144
|
+
, lastEventIndex
|
|
145
|
+
, this.withTimeout(signal)
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
123
150
|
async getEvent(
|
|
124
151
|
namespace: string
|
|
125
152
|
, itemId: string
|
|
@@ -2,17 +2,27 @@ import { IAPI, expectedVersion } from '@src/contract.js'
|
|
|
2
2
|
import { ClientProxy } from 'delight-rpc'
|
|
3
3
|
import { createClient } from '@delight-rpc/extra-native-websocket'
|
|
4
4
|
import { ExtraNativeWebSocket, autoReconnect } from 'extra-native-websocket'
|
|
5
|
+
import { timeoutSignal } from 'extra-abort'
|
|
5
6
|
|
|
6
7
|
export async function createRPCClient(
|
|
7
8
|
url: string
|
|
8
9
|
, retryIntervalForReconnection?: number
|
|
10
|
+
, timeoutForConnection?: number
|
|
9
11
|
): Promise<{
|
|
10
12
|
client: ClientProxy<IAPI>
|
|
11
13
|
close: () => Promise<void>
|
|
12
14
|
}> {
|
|
13
15
|
const ws = new ExtraNativeWebSocket(() => new WebSocket(url))
|
|
14
|
-
const cancelAutoReconnect = autoReconnect(
|
|
15
|
-
|
|
16
|
+
const cancelAutoReconnect = autoReconnect(
|
|
17
|
+
ws
|
|
18
|
+
, retryIntervalForReconnection
|
|
19
|
+
, timeoutForConnection
|
|
20
|
+
)
|
|
21
|
+
await ws.connect(
|
|
22
|
+
timeoutForConnection
|
|
23
|
+
? timeoutSignal(timeoutForConnection)
|
|
24
|
+
: undefined
|
|
25
|
+
)
|
|
16
26
|
|
|
17
27
|
const [client, closeClient] = createClient<IAPI>(ws, { expectedVersion })
|
|
18
28
|
|
package/src/utils/rpc-client.ts
CHANGED
|
@@ -3,17 +3,27 @@ import { ClientProxy } from 'delight-rpc'
|
|
|
3
3
|
import { createClient } from '@delight-rpc/extra-websocket'
|
|
4
4
|
import { WebSocket } from 'ws'
|
|
5
5
|
import { ExtraWebSocket, autoReconnect } from 'extra-websocket'
|
|
6
|
+
import { timeoutSignal } from 'extra-abort'
|
|
6
7
|
|
|
7
8
|
export async function createRPCClient(
|
|
8
9
|
url: string
|
|
9
10
|
, retryIntervalForReconnection?: number
|
|
11
|
+
, timeoutForConnection?: number
|
|
10
12
|
): Promise<{
|
|
11
13
|
client: ClientProxy<IAPI>
|
|
12
14
|
close: () => Promise<void>
|
|
13
15
|
}> {
|
|
14
16
|
const ws = new ExtraWebSocket(() => new WebSocket(url))
|
|
15
|
-
const cancelAutoReconnect = autoReconnect(
|
|
16
|
-
|
|
17
|
+
const cancelAutoReconnect = autoReconnect(
|
|
18
|
+
ws
|
|
19
|
+
, retryIntervalForReconnection
|
|
20
|
+
, timeoutForConnection
|
|
21
|
+
)
|
|
22
|
+
await ws.connect(
|
|
23
|
+
timeoutForConnection
|
|
24
|
+
? timeoutSignal(timeoutForConnection)
|
|
25
|
+
: undefined
|
|
26
|
+
)
|
|
17
27
|
|
|
18
28
|
const [client, closeClient] = createClient<IAPI>(ws, { expectedVersion })
|
|
19
29
|
|