libshv-js 3.14.0 → 3.15.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ws-client.ts +35 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.14.0",
3
+ "version": "3.15.0",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/ws-client.ts CHANGED
@@ -64,11 +64,10 @@ export class RequestHandler {
64
64
 
65
65
  export const LsParamZod = z.undefined().or(z.string());
66
66
  export const DirParamZod = z.undefined().or(z.boolean()).or(z.string());
67
- type DirParam = z.infer<typeof DirParamZod>;
68
67
 
69
68
  export type DirEntry = IMap<{
70
69
  [DIR_NAME]: string;
71
- [DIR_FLAGS]: DirFlags;
70
+ [DIR_FLAGS]: number;
72
71
  [DIR_PARAM]: string | Null;
73
72
  [DIR_RESULT]: string | Null;
74
73
  [DIR_ACCESS]: Int;
@@ -79,10 +78,8 @@ export type DirEntry = IMap<{
79
78
  export type DirResult = DirEntry[];
80
79
 
81
80
  export type MethodHandler = {
82
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- paramParser: z.ZodType<any>,
84
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
- handler: (shvPath: string, method: string, params: any, delay: (progress: number) => void) => Promise<RpcValue> | RpcValue | RequestHandler,
81
+ paramParser: z.ZodType<RpcValue>,
82
+ handler: (shvPath: string, method: string, params: RpcValue, delay: (progress: number) => void) => Promise<RpcValue> | RpcValue | RequestHandler,
86
83
  };
87
84
 
88
85
  type WsClientOptionsLogin = WsClientOptionsCommon & {
@@ -93,7 +90,10 @@ type WsClientOptionsLogin = WsClientOptionsCommon & {
93
90
  onConnected: () => void;
94
91
  onConnectionFailure: (error: Error) => void;
95
92
  onDisconnected: () => void;
96
- onRequest: (shvPath: string) => Array<{entry: DirEntry} & MethodHandler> | undefined;
93
+ onRequest: (shvPath: string) => {
94
+ ls: (shvPath: string) => string[] | Promise<string[]>;
95
+ dirEntries: Array<{entry: DirEntry} & MethodHandler>;
96
+ } | undefined;
97
97
  };
98
98
 
99
99
  type WsClientOptionsWorkflows = WsClientOptionsCommon & {
@@ -255,9 +255,12 @@ class WsClient {
255
255
  if (RPC_MESSAGE_ABORT in request.value) {
256
256
  const requestHandler = this.requestHandlers.get(requestId);
257
257
 
258
- if (request.value[RPC_MESSAGE_ABORT] === true && requestHandler?.options.onAbort !== undefined) {
258
+ if (request.value[RPC_MESSAGE_ABORT] === true) {
259
259
  this.abortedRequests.add(requestId);
260
- requestHandler.options.onAbort();
260
+
261
+ if (requestHandler?.options.onAbort !== undefined) {
262
+ requestHandler.options.onAbort();
263
+ }
261
264
  }
262
265
 
263
266
  if (request.value[RPC_MESSAGE_ABORT] === false && requestHandler?.options.onProgressQuery !== undefined) {
@@ -291,9 +294,18 @@ class WsClient {
291
294
  const dirEntry = makeIMap({
292
295
  [DIR_NAME]: 'dir',
293
296
  [DIR_FLAGS]: 0,
294
- [DIR_PARAM]: '',
295
- [DIR_RESULT]: '',
296
- [DIR_ACCESS]: accessLevelFromAccessString('rd'),
297
+ [DIR_PARAM]: 'DirParam',
298
+ [DIR_RESULT]: 'DirResult',
299
+ [DIR_ACCESS]: accessLevelFromAccessString('bws'),
300
+ [DIR_SIGNALS]: makeMap({}),
301
+ [DIR_EXTRA]: makeMap({}),
302
+ });
303
+ const lsEntry = makeIMap({
304
+ [DIR_NAME]: 'ls',
305
+ [DIR_FLAGS]: 0,
306
+ [DIR_PARAM]: 'LsParam',
307
+ [DIR_RESULT]: 'LsResult',
308
+ [DIR_ACCESS]: accessLevelFromAccessString('bws'),
297
309
  [DIR_SIGNALS]: makeMap({}),
298
310
  [DIR_EXTRA]: makeMap({}),
299
311
  });
@@ -302,8 +314,8 @@ class WsClient {
302
314
  return {
303
315
  entry: dirEntry,
304
316
  paramParser: DirParamZod,
305
- handler(_shvPath, _method, param: DirParam) {
306
- const methodsResult = [dirEntry, ...methods.map(method => method.entry)];
317
+ handler(_shvPath, _method, param) {
318
+ const methodsResult = [dirEntry, lsEntry, ...methods.dirEntries.map(method => method.entry)];
307
319
  switch (true) {
308
320
  case typeof param === 'string':
309
321
  return methodsResult.find(method => method[DIR_NAME] === param) ?? false;
@@ -314,8 +326,16 @@ class WsClient {
314
326
  }
315
327
  },
316
328
  };
329
+ case 'ls':
330
+ return {
331
+ entry: lsEntry,
332
+ paramParser: LsParamZod,
333
+ handler(shvPath) {
334
+ return methods.ls(shvPath);
335
+ },
336
+ };
317
337
  default:
318
- return methods.find(method => method.entry[DIR_NAME] === methodName);
338
+ return methods.dirEntries.find(method => method.entry[DIR_NAME] === methodName);
319
339
  }
320
340
  })();
321
341