libshv-js 3.8.0 → 3.9.1
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/package.json +1 -1
- package/src/chainpack.ts +15 -1
- package/src/rpcmessage.ts +4 -0
- package/src/ws-client.ts +12 -6
package/package.json
CHANGED
package/src/chainpack.ts
CHANGED
|
@@ -416,7 +416,8 @@ class ChainPackWriter {
|
|
|
416
416
|
this.writeDateTime(rpcVal);
|
|
417
417
|
break;
|
|
418
418
|
case rpcVal instanceof Double:
|
|
419
|
-
|
|
419
|
+
this.writeDouble(rpcVal);
|
|
420
|
+
break;
|
|
420
421
|
case typeof rpcVal === 'object':
|
|
421
422
|
switch (rpcVal[shvMapType]) {
|
|
422
423
|
case 'imap':
|
|
@@ -575,6 +576,19 @@ class ChainPackWriter {
|
|
|
575
576
|
this.writeUIntDataHelper(bi, 'UInt');
|
|
576
577
|
}
|
|
577
578
|
|
|
579
|
+
writeDouble(double: Double) {
|
|
580
|
+
this.ctx.putByte(PackingSchema.Double);
|
|
581
|
+
const buffer = new ArrayBuffer(8);
|
|
582
|
+
const view = new DataView(buffer);
|
|
583
|
+
|
|
584
|
+
view.setFloat64(0, double.value, true);
|
|
585
|
+
|
|
586
|
+
const data = new Uint8Array(buffer);
|
|
587
|
+
for (let i = 0; i < 8; i++) {
|
|
588
|
+
this.ctx.putByte(data[i]);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
578
592
|
writeList(lst: RpcValue[]) {
|
|
579
593
|
this.ctx.putByte(PackingSchema.List);
|
|
580
594
|
for (const element of lst) {
|
package/src/rpcmessage.ts
CHANGED
|
@@ -8,6 +8,7 @@ export const RPC_MESSAGE_CALLER_IDS = 11;
|
|
|
8
8
|
export const RPC_MESSAGE_PARAMS = 1;
|
|
9
9
|
export const RPC_MESSAGE_RESULT = 2;
|
|
10
10
|
export const RPC_MESSAGE_ERROR = 3;
|
|
11
|
+
export const RPC_MESSAGE_DELAY = 4;
|
|
11
12
|
|
|
12
13
|
export const ERROR_CODE = 1;
|
|
13
14
|
export const ERROR_MESSAGE = 2;
|
|
@@ -51,10 +52,13 @@ const RpcResponseMetaZod = z.metamap({
|
|
|
51
52
|
[RPC_MESSAGE_CALLER_IDS]: z.int().or(z.array(z.int())).optional(),
|
|
52
53
|
[RPC_MESSAGE_REQUEST_ID]: z.number(),
|
|
53
54
|
});
|
|
55
|
+
|
|
54
56
|
const RpcResponseValueZod = z.imap({
|
|
55
57
|
[RPC_MESSAGE_RESULT]: z.rpcvalue(),
|
|
56
58
|
}).or(z.imap({
|
|
57
59
|
[RPC_MESSAGE_ERROR]: ErrorMapZod,
|
|
60
|
+
})).or(z.imap({
|
|
61
|
+
[RPC_MESSAGE_DELAY]: z.double(),
|
|
58
62
|
}));
|
|
59
63
|
|
|
60
64
|
const RpcSignalMetaZod = z.metamap({
|
package/src/ws-client.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {ChainPackReader, CHAINPACK_PROTOCOL_TYPE, ChainPackWriter, toChainPack} from './chainpack';
|
|
2
2
|
import {type CponReader, CPON_PROTOCOL_TYPE, toCpon} from './cpon';
|
|
3
|
-
import {ERROR_MESSAGE, ErrorCode, ERROR_CODE, RpcMessageZod, type RpcMessage, isSignal, isRequest, type RpcRequest, isResponse, ERROR_DATA, type ErrorMap, RPC_MESSAGE_METHOD, RPC_MESSAGE_SHV_PATH, RPC_MESSAGE_REQUEST_ID, RPC_MESSAGE_PARAMS, RPC_MESSAGE_ERROR, RPC_MESSAGE_RESULT, RPC_MESSAGE_CALLER_IDS, RpcResponseValue} from './rpcmessage';
|
|
4
|
-
import {type RpcValue, type Null, type Int, type IMap, type ShvMap, makeMap, makeIMap, RpcValueWithMetaData, makeMetaMap} from './rpcvalue';
|
|
3
|
+
import {ERROR_MESSAGE, ErrorCode, ERROR_CODE, RpcMessageZod, type RpcMessage, isSignal, isRequest, type RpcRequest, isResponse, ERROR_DATA, type ErrorMap, RPC_MESSAGE_METHOD, RPC_MESSAGE_SHV_PATH, RPC_MESSAGE_REQUEST_ID, RPC_MESSAGE_PARAMS, RPC_MESSAGE_ERROR, RPC_MESSAGE_RESULT, RPC_MESSAGE_CALLER_IDS, RpcResponseValue, RPC_MESSAGE_DELAY} from './rpcmessage';
|
|
4
|
+
import {type RpcValue, type Null, type Int, type IMap, type ShvMap, makeMap, makeIMap, RpcValueWithMetaData, makeMetaMap, Double} from './rpcvalue';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_TIMEOUT = 5000;
|
|
7
7
|
const DEFAULT_PING_INTERVAL = 30 * 1000;
|
|
@@ -58,7 +58,7 @@ type WsClientOptionsLogin = WsClientOptionsCommon & {
|
|
|
58
58
|
onConnected: () => void;
|
|
59
59
|
onConnectionFailure: (error: Error) => void;
|
|
60
60
|
onDisconnected: () => void;
|
|
61
|
-
onRequest: (shvPath: string, method: string, param
|
|
61
|
+
onRequest: (shvPath: string, method: string, param: RpcValue, delay: (progress: number) => void) => Promise<RpcValue>;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
type WsClientOptionsWorkflows = WsClientOptionsCommon & {
|
|
@@ -139,10 +139,10 @@ export const NotImplemented = createErrorClass(ErrorCode.NotImplemented);
|
|
|
139
139
|
|
|
140
140
|
class WsClient {
|
|
141
141
|
private requestId = 1;
|
|
142
|
-
private pingTimerId =
|
|
142
|
+
private pingTimerId: ReturnType<typeof globalThis.setInterval> | undefined = undefined;
|
|
143
143
|
private rpcHandlers: Array<{
|
|
144
144
|
resolve: RpcResponseResolver;
|
|
145
|
-
timeout_handle:
|
|
145
|
+
timeout_handle: ReturnType<typeof globalThis.setTimeout>;
|
|
146
146
|
}> = [];
|
|
147
147
|
private readonly subscriptions: Subscription[] = [];
|
|
148
148
|
private readonly websocket: WebSocket;
|
|
@@ -187,8 +187,14 @@ class WsClient {
|
|
|
187
187
|
};
|
|
188
188
|
|
|
189
189
|
try {
|
|
190
|
+
const sendDelay = (progress: number) => {
|
|
191
|
+
respond(makeIMap({
|
|
192
|
+
[RPC_MESSAGE_DELAY]: new Double(progress),
|
|
193
|
+
}));
|
|
194
|
+
};
|
|
195
|
+
|
|
190
196
|
respond(makeIMap({
|
|
191
|
-
[RPC_MESSAGE_RESULT]: await this.options.onRequest(rpcMsg.meta[RPC_MESSAGE_SHV_PATH], rpcMsg.meta[RPC_MESSAGE_METHOD], rpcMsg.value[RPC_MESSAGE_PARAMS]),
|
|
197
|
+
[RPC_MESSAGE_RESULT]: await this.options.onRequest(rpcMsg.meta[RPC_MESSAGE_SHV_PATH], rpcMsg.meta[RPC_MESSAGE_METHOD], rpcMsg.value[RPC_MESSAGE_PARAMS], sendDelay),
|
|
192
198
|
}));
|
|
193
199
|
} catch (error: unknown) {
|
|
194
200
|
const sendError = (error: RpcError) => {
|