libshv-js 3.9.0 → 3.9.2

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.
@@ -0,0 +1,239 @@
1
+ import { type RpcMessage, type ErrorMap } from './rpcmessage';
2
+ import { type RpcValue, type Null, type Int, type IMap, type ShvMap } from './rpcvalue';
3
+ import { StringGetter } from './utils';
4
+ type SubscriptionCallback = (path: string, method: string, param?: RpcValue) => void;
5
+ type ResultOrError<T = RpcValue> = T | Error;
6
+ type Login = {
7
+ type: 'PLAIN';
8
+ user: string;
9
+ password: string;
10
+ } | {
11
+ type: 'TOKEN';
12
+ token: string;
13
+ };
14
+ type WsClientOptionsCommon = {
15
+ logDebug: (...args: string[]) => void;
16
+ wsUri: string;
17
+ parseMessage?: (rpcVal: RpcValue) => RpcMessage;
18
+ };
19
+ export declare class RequestHandler {
20
+ options: {
21
+ result: Promise<RpcValue>;
22
+ onAbort?: () => void;
23
+ onProgressQuery?: () => number | Promise<number>;
24
+ };
25
+ constructor(options: {
26
+ result: Promise<RpcValue>;
27
+ onAbort?: () => void;
28
+ onProgressQuery?: () => number | Promise<number>;
29
+ });
30
+ }
31
+ export declare const validateLsParam: (param: RpcValue) => param is string | undefined;
32
+ export declare const validateDirParam: (param: RpcValue) => param is string | boolean | undefined;
33
+ export type DirEntry = IMap<{
34
+ [DIR_NAME]: string;
35
+ [DIR_FLAGS]: number;
36
+ [DIR_PARAM]: string | Null;
37
+ [DIR_RESULT]: string | Null;
38
+ [DIR_ACCESS]: Int;
39
+ [DIR_SIGNALS]: ShvMap<Record<string, string | Null>>;
40
+ [DIR_EXTRA]: ShvMap;
41
+ }>;
42
+ export type DirResult = DirEntry[];
43
+ export type MethodHandler = {
44
+ paramValidator?: (param: RpcValue) => boolean;
45
+ handler: (shvPath: string, method: string, params: RpcValue, delay: (progress: number) => void) => Promise<RpcValue> | RpcValue | RequestHandler;
46
+ };
47
+ export type WsClientOptionsLogin<MethodHandlerType = MethodHandler> = WsClientOptionsCommon & {
48
+ mountPoint?: string;
49
+ login: Login;
50
+ timeout?: number;
51
+ pingInterval?: number;
52
+ onConnected: () => void;
53
+ onConnectionFailure: (error: Error) => void;
54
+ onDisconnected: () => void;
55
+ onRequest: (shvPath: string) => {
56
+ ls: (shvPath: string) => string[] | Promise<string[]>;
57
+ dirEntries: Array<{
58
+ entry: DirEntry;
59
+ } & MethodHandlerType>;
60
+ } | undefined;
61
+ };
62
+ export type WsClientOptionsWorkflows = WsClientOptionsCommon & {
63
+ onWorkflows: (workflows: RpcValue) => void;
64
+ onWorkflowsFailed: () => void;
65
+ };
66
+ export type WsClientOptions<MethodHandlerType> = WsClientOptionsLogin<MethodHandlerType> | WsClientOptionsWorkflows;
67
+ type LsResult = string[];
68
+ export declare enum DirFlags {
69
+ Reserved = 1,
70
+ Getter = 2,
71
+ Setter = 4,
72
+ LargeResultHint = 8,
73
+ NotIdempotent = 16,
74
+ RequiresClientId = 32
75
+ }
76
+ export declare const DIR_NAME = 1;
77
+ export declare const DIR_FLAGS = 2;
78
+ export declare const DIR_PARAM = 3;
79
+ export declare const DIR_RESULT = 4;
80
+ export declare const DIR_ACCESS = 5;
81
+ export declare const DIR_SIGNALS = 6;
82
+ export declare const DIR_EXTRA = 63;
83
+ export declare const InvalidRequest: {
84
+ new (errInfoOrMsg: ErrorMap | string): {
85
+ readonly err_info: ErrorMap;
86
+ data(): RpcValue;
87
+ name: string;
88
+ message: string;
89
+ stack?: string;
90
+ cause?: unknown;
91
+ };
92
+ };
93
+ export declare const MethodNotFound: {
94
+ new (errInfoOrMsg: ErrorMap | string): {
95
+ readonly err_info: ErrorMap;
96
+ data(): RpcValue;
97
+ name: string;
98
+ message: string;
99
+ stack?: string;
100
+ cause?: unknown;
101
+ };
102
+ };
103
+ export declare const InvalidParams: {
104
+ new (errInfoOrMsg: ErrorMap | string): {
105
+ readonly err_info: ErrorMap;
106
+ data(): RpcValue;
107
+ name: string;
108
+ message: string;
109
+ stack?: string;
110
+ cause?: unknown;
111
+ };
112
+ };
113
+ export declare const InternalError: {
114
+ new (errInfoOrMsg: ErrorMap | string): {
115
+ readonly err_info: ErrorMap;
116
+ data(): RpcValue;
117
+ name: string;
118
+ message: string;
119
+ stack?: string;
120
+ cause?: unknown;
121
+ };
122
+ };
123
+ export declare const ParseError: {
124
+ new (errInfoOrMsg: ErrorMap | string): {
125
+ readonly err_info: ErrorMap;
126
+ data(): RpcValue;
127
+ name: string;
128
+ message: string;
129
+ stack?: string;
130
+ cause?: unknown;
131
+ };
132
+ };
133
+ export declare const MethodCallTimeout: {
134
+ new (errInfoOrMsg: ErrorMap | string): {
135
+ readonly err_info: ErrorMap;
136
+ data(): RpcValue;
137
+ name: string;
138
+ message: string;
139
+ stack?: string;
140
+ cause?: unknown;
141
+ };
142
+ };
143
+ export declare const MethodCallCancelled: {
144
+ new (errInfoOrMsg: ErrorMap | string): {
145
+ readonly err_info: ErrorMap;
146
+ data(): RpcValue;
147
+ name: string;
148
+ message: string;
149
+ stack?: string;
150
+ cause?: unknown;
151
+ };
152
+ };
153
+ export declare const MethodCallException: {
154
+ new (errInfoOrMsg: ErrorMap | string): {
155
+ readonly err_info: ErrorMap;
156
+ data(): RpcValue;
157
+ name: string;
158
+ message: string;
159
+ stack?: string;
160
+ cause?: unknown;
161
+ };
162
+ };
163
+ export declare const Unknown: {
164
+ new (errInfoOrMsg: ErrorMap | string): {
165
+ readonly err_info: ErrorMap;
166
+ data(): RpcValue;
167
+ name: string;
168
+ message: string;
169
+ stack?: string;
170
+ cause?: unknown;
171
+ };
172
+ };
173
+ export declare const LoginRequired: {
174
+ new (errInfoOrMsg: ErrorMap | string): {
175
+ readonly err_info: ErrorMap;
176
+ data(): RpcValue;
177
+ name: string;
178
+ message: string;
179
+ stack?: string;
180
+ cause?: unknown;
181
+ };
182
+ };
183
+ export declare const UserIDRequired: {
184
+ new (errInfoOrMsg: ErrorMap | string): {
185
+ readonly err_info: ErrorMap;
186
+ data(): RpcValue;
187
+ name: string;
188
+ message: string;
189
+ stack?: string;
190
+ cause?: unknown;
191
+ };
192
+ };
193
+ export declare const NotImplemented: {
194
+ new (errInfoOrMsg: ErrorMap | string): {
195
+ readonly err_info: ErrorMap;
196
+ data(): RpcValue;
197
+ name: string;
198
+ message: string;
199
+ stack?: string;
200
+ cause?: unknown;
201
+ };
202
+ };
203
+ declare class RpcRequestPromise<Result> extends Promise<Result> {
204
+ readonly abort: () => void;
205
+ readonly progressQuery: () => void;
206
+ constructor(executor: (resolve: (value: Result | PromiseLike<Result>) => void, reject: (reason?: unknown) => void) => void, abort: () => void, progressQuery: () => void);
207
+ }
208
+ export type CallRpcMethodOptions = {
209
+ delayCallback?: (progress: number) => void;
210
+ requestUserId?: boolean;
211
+ };
212
+ declare class WsClient {
213
+ private requestId;
214
+ private pingTimerId;
215
+ private rpcHandlers;
216
+ private requestHandlers;
217
+ private abortedRequests;
218
+ private readonly subscriptions;
219
+ private readonly websocket;
220
+ private readonly options;
221
+ private readonly timeout;
222
+ constructor(options: WsClientOptions<MethodHandler>);
223
+ callRpcMethod(shvPath: '.broker/currentClient', method: 'accessGrantForMethodCall', params: [string, string], options?: CallRpcMethodOptions): RpcRequestPromise<ResultOrError<string>>;
224
+ callRpcMethod(shvPath: '.broker/currentClient', method: 'accessLevelForMethodCall', params: [string, string], options?: CallRpcMethodOptions): RpcRequestPromise<ResultOrError<number>>;
225
+ callRpcMethod(shvPath: string | undefined, method: 'dir', params?: RpcValue, options?: CallRpcMethodOptions): RpcRequestPromise<ResultOrError<DirResult>>;
226
+ callRpcMethod(shvPath: string | undefined, method: 'ls', params?: RpcValue, options?: CallRpcMethodOptions): RpcRequestPromise<ResultOrError<LsResult>>;
227
+ callRpcMethod(shvPath: string | undefined, method: string, params?: RpcValue, options?: CallRpcMethodOptions): RpcRequestPromise<ResultOrError>;
228
+ sendRpcMessage(rpcMsg: RpcMessage): void;
229
+ subscribe(subscriber: string, pathGetter: StringGetter, method: string, callback: SubscriptionCallback): Promise<void>;
230
+ unsubscribe(subscriber: string, pathGetter: StringGetter, method: string): Promise<void>;
231
+ sendPing(): void;
232
+ accessGrantForMethodCall(path: string, method: string): RpcRequestPromise<ResultOrError<string>>;
233
+ accessLevelForMethodCall(path: string, method: string): RpcRequestPromise<ResultOrError<number>>;
234
+ close(): void;
235
+ protected logDebug(...args: string[]): void;
236
+ private workflowsProcedure;
237
+ private loginProcedure;
238
+ }
239
+ export { WsClient };