libshv-js 5.1.0 → 6.0.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.
@@ -3,6 +3,7 @@ export declare const RPC_MESSAGE_REQUEST_ID = 8;
3
3
  export declare const RPC_MESSAGE_SHV_PATH = 9;
4
4
  export declare const RPC_MESSAGE_METHOD = 10;
5
5
  export declare const RPC_MESSAGE_CALLER_IDS = 11;
6
+ export declare const RPC_MESSAGE_USER_ID = 16;
6
7
  export declare const RPC_MESSAGE_ACCESS_LEVEL = 17;
7
8
  export declare const RPC_MESSAGE_PARAMS = 1;
8
9
  export declare const RPC_MESSAGE_RESULT = 2;
@@ -36,6 +37,7 @@ type RpcRequestMeta = MetaMap<{
36
37
  [RPC_MESSAGE_SHV_PATH]: string;
37
38
  [RPC_MESSAGE_METHOD]: string;
38
39
  [RPC_MESSAGE_CALLER_IDS]?: number | number[] | undefined;
40
+ [RPC_MESSAGE_USER_ID]?: string | undefined;
39
41
  [RPC_MESSAGE_ACCESS_LEVEL]?: number | undefined;
40
42
  }>;
41
43
  type RpcRequestValue = IMap<{
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isResponse = exports.isRequest = exports.isSignal = exports.ErrorCode = exports.ERROR_DATA = exports.ERROR_MESSAGE = exports.ERROR_CODE = exports.RPC_MESSAGE_ABORT = exports.RPC_MESSAGE_DELAY = exports.RPC_MESSAGE_ERROR = exports.RPC_MESSAGE_RESULT = exports.RPC_MESSAGE_PARAMS = exports.RPC_MESSAGE_ACCESS_LEVEL = exports.RPC_MESSAGE_CALLER_IDS = exports.RPC_MESSAGE_METHOD = exports.RPC_MESSAGE_SHV_PATH = exports.RPC_MESSAGE_REQUEST_ID = void 0;
3
+ exports.isResponse = exports.isRequest = exports.isSignal = exports.ErrorCode = exports.ERROR_DATA = exports.ERROR_MESSAGE = exports.ERROR_CODE = exports.RPC_MESSAGE_ABORT = exports.RPC_MESSAGE_DELAY = exports.RPC_MESSAGE_ERROR = exports.RPC_MESSAGE_RESULT = exports.RPC_MESSAGE_PARAMS = exports.RPC_MESSAGE_ACCESS_LEVEL = exports.RPC_MESSAGE_USER_ID = exports.RPC_MESSAGE_CALLER_IDS = exports.RPC_MESSAGE_METHOD = exports.RPC_MESSAGE_SHV_PATH = exports.RPC_MESSAGE_REQUEST_ID = void 0;
4
4
  exports.RPC_MESSAGE_REQUEST_ID = 8;
5
5
  exports.RPC_MESSAGE_SHV_PATH = 9;
6
6
  exports.RPC_MESSAGE_METHOD = 10;
7
7
  exports.RPC_MESSAGE_CALLER_IDS = 11;
8
+ exports.RPC_MESSAGE_USER_ID = 16;
8
9
  exports.RPC_MESSAGE_ACCESS_LEVEL = 17;
9
10
  exports.RPC_MESSAGE_PARAMS = 1;
10
11
  exports.RPC_MESSAGE_RESULT = 2;
@@ -205,6 +205,10 @@ declare class RpcRequestPromise<Result> extends Promise<Result> {
205
205
  readonly progressQuery: () => void;
206
206
  constructor(executor: (resolve: (value: Result | PromiseLike<Result>) => void, reject: (reason?: unknown) => void) => void, abort: () => void, progressQuery: () => void);
207
207
  }
208
+ export type CallRpcMethodOptions = {
209
+ delayCallback?: (progress: number) => void;
210
+ requestUserId?: boolean;
211
+ };
208
212
  declare class WsClient {
209
213
  private requestId;
210
214
  private pingTimerId;
@@ -216,11 +220,11 @@ declare class WsClient {
216
220
  private readonly options;
217
221
  private readonly timeout;
218
222
  constructor(options: WsClientOptions<MethodHandler>);
219
- callRpcMethod(shvPath: '.broker/currentClient', method: 'accessGrantForMethodCall', params: [string, string], delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<string>>;
220
- callRpcMethod(shvPath: '.broker/currentClient', method: 'accessLevelForMethodCall', params: [string, string], delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<number>>;
221
- callRpcMethod(shvPath: string | undefined, method: 'dir', params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<DirResult>>;
222
- callRpcMethod(shvPath: string | undefined, method: 'ls', params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<LsResult>>;
223
- callRpcMethod(shvPath: string | undefined, method: string, params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError>;
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>;
224
228
  sendRpcMessage(rpcMsg: RpcMessage): void;
225
229
  subscribe(subscriber: string, pathGetter: StringGetter, method: string, callback: SubscriptionCallback): Promise<void>;
226
230
  unsubscribe(subscriber: string, pathGetter: StringGetter, method: string): Promise<void>;
package/dist/ws-client.js CHANGED
@@ -376,20 +376,21 @@ class WsClient {
376
376
  this.loginProcedure(this.options);
377
377
  }
378
378
  }
379
- callRpcMethod(shvPath, method, params, delayCallback) {
379
+ callRpcMethod(shvPath, method, params, options) {
380
380
  const rqId = this.requestId++;
381
381
  const makeRq = (value) => new rpcvalue_1.RpcValueWithMetaData((0, rpcvalue_1.makeMetaMap)({
382
382
  [rpcmessage_1.RPC_MESSAGE_CALLER_IDS]: undefined,
383
383
  [rpcmessage_1.RPC_MESSAGE_REQUEST_ID]: rqId,
384
384
  [rpcmessage_1.RPC_MESSAGE_METHOD]: method ?? '',
385
385
  [rpcmessage_1.RPC_MESSAGE_SHV_PATH]: shvPath ?? '',
386
+ ...(options?.requestUserId === true ? { [rpcmessage_1.RPC_MESSAGE_USER_ID]: '' } : {}),
386
387
  }), value);
387
388
  const rq = makeRq((0, rpcvalue_1.makeIMap)({
388
389
  [rpcmessage_1.RPC_MESSAGE_PARAMS]: params,
389
390
  }));
390
391
  this.sendRpcMessage(rq);
391
392
  const promise = new RpcRequestPromise(resolve => {
392
- this.rpcHandlers[rqId] = { resolve, timeout_handle: makeTimeout(this.timeout, resolve), delayCallback };
393
+ this.rpcHandlers[rqId] = { resolve, timeout_handle: makeTimeout(this.timeout, resolve), delayCallback: options?.delayCallback };
393
394
  }, () => {
394
395
  this.sendRpcMessage(makeRq((0, rpcvalue_1.makeIMap)({
395
396
  [rpcmessage_1.RPC_MESSAGE_ABORT]: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "5.1.0",
3
+ "version": "6.0.0",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",