libshv-js 3.23.3 → 3.24.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/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export * from './rpcvalue';
8
8
  export * from './vue-shv';
9
9
  export * from './ws-client';
10
10
  export * from './zod';
11
+ export * from './zod-ws-client';
package/dist/index.js CHANGED
@@ -24,3 +24,4 @@ __exportStar(require("./rpcvalue"), exports);
24
24
  __exportStar(require("./vue-shv"), exports);
25
25
  __exportStar(require("./ws-client"), exports);
26
26
  __exportStar(require("./zod"), exports);
27
+ __exportStar(require("./zod-ws-client"), exports);
package/dist/vue-shv.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ComputedRef, Ref } from 'vue';
2
- import { WsClient, WsClientOptionsLogin } from './ws-client';
2
+ import { type WsClient, type WsClientOptionsLogin } from './ws-client';
3
3
  import PKCE from 'js-pkce';
4
4
  import * as z from './zod';
5
5
  import { type shvMapType } from './rpcvalue';
6
6
  import { RpcValue } from './rpcvalue';
7
7
  import { StringGetter } from './utils';
8
+ import { ZodMethodHandler } from './zod-ws-client';
8
9
  type GlobalResourceOptions<ResourceType> = {
9
10
  shvPath: StringGetter;
10
11
  method: string;
@@ -14,7 +15,7 @@ type GlobalResourceOptions<ResourceType> = {
14
15
  };
15
16
  type VueShvOptions = {
16
17
  wsUri: StringGetter;
17
- onRequest: WsClientOptionsLogin['onRequest'];
18
+ onRequest: WsClientOptionsLogin<ZodMethodHandler>['onRequest'];
18
19
  azureCodeRedirect?: string;
19
20
  mountPoint?: string;
20
21
  };
package/dist/vue-shv.js CHANGED
@@ -39,11 +39,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.fullReloadHandler = exports.azure = exports.LoginFailureReason = void 0;
40
40
  exports.useShv = useShv;
41
41
  const vue_1 = require("vue");
42
- const ws_client_1 = require("./ws-client");
43
42
  const core_1 = require("@vueuse/core");
44
43
  const js_pkce_1 = __importDefault(require("js-pkce"));
45
44
  const z = __importStar(require("./zod"));
46
45
  const utils_1 = require("./utils");
46
+ const zod_ws_client_1 = require("./zod-ws-client");
47
47
  const OAuth2AzureWorkflowZod = z.map({
48
48
  type: z.literal('oauth2-azure'),
49
49
  authorizeUrl: z.string(),
@@ -146,7 +146,7 @@ function useShv(options) {
146
146
  message: 'Broker does not support Azure',
147
147
  };
148
148
  };
149
- state.ws = new ws_client_1.WsClient({
149
+ state.ws = (0, zod_ws_client_1.createZodWsClient)({
150
150
  logDebug: debug,
151
151
  wsUri: await (0, utils_1.resolveString)(options.wsUri),
152
152
  onWorkflows(workflows) {
@@ -246,7 +246,7 @@ function useShv(options) {
246
246
  };
247
247
  }
248
248
  };
249
- state.ws = new ws_client_1.WsClient({
249
+ state.ws = (0, zod_ws_client_1.createZodWsClient)({
250
250
  login: makeLoginOptions(),
251
251
  wsUri,
252
252
  timeout: 120_000,
@@ -1,7 +1,6 @@
1
1
  import { type RpcMessage, type ErrorMap } from './rpcmessage';
2
2
  import { type RpcValue, type Null, type Int, type IMap, type ShvMap } from './rpcvalue';
3
3
  import { StringGetter } from './utils';
4
- import * as z from './zod';
5
4
  type SubscriptionCallback = (path: string, method: string, param?: RpcValue) => void;
6
5
  type ResultOrError<T = RpcValue> = T | Error;
7
6
  type Login = {
@@ -15,6 +14,7 @@ type Login = {
15
14
  type WsClientOptionsCommon = {
16
15
  logDebug: (...args: string[]) => void;
17
16
  wsUri: string;
17
+ parseMessage?: (rpcVal: RpcValue) => RpcMessage;
18
18
  };
19
19
  export declare class RequestHandler {
20
20
  options: {
@@ -28,8 +28,8 @@ export declare class RequestHandler {
28
28
  onProgressQuery?: () => number | Promise<number>;
29
29
  });
30
30
  }
31
- export declare const LsParamZod: z.ZodUnion<[z.ZodUndefined, z.ZodString]>;
32
- export declare const DirParamZod: z.ZodUnion<[z.ZodUnion<[z.ZodUndefined, z.ZodBoolean]>, z.ZodString]>;
31
+ export declare const validateLsParam: (param: RpcValue) => param is string | undefined;
32
+ export declare const validateDirParam: (param: RpcValue) => param is string | boolean | undefined;
33
33
  export type DirEntry = IMap<{
34
34
  [DIR_NAME]: string;
35
35
  [DIR_FLAGS]: number;
@@ -41,10 +41,10 @@ export type DirEntry = IMap<{
41
41
  }>;
42
42
  export type DirResult = DirEntry[];
43
43
  export type MethodHandler = {
44
- paramParser: z.ZodType<RpcValue>;
44
+ paramValidator?: (param: RpcValue) => boolean;
45
45
  handler: (shvPath: string, method: string, params: RpcValue, delay: (progress: number) => void) => Promise<RpcValue> | RpcValue | RequestHandler;
46
46
  };
47
- export type WsClientOptionsLogin = WsClientOptionsCommon & {
47
+ export type WsClientOptionsLogin<MethodHandlerType = MethodHandler> = WsClientOptionsCommon & {
48
48
  mountPoint?: string;
49
49
  login: Login;
50
50
  timeout?: number;
@@ -56,14 +56,14 @@ export type WsClientOptionsLogin = WsClientOptionsCommon & {
56
56
  ls: (shvPath: string) => string[] | Promise<string[]>;
57
57
  dirEntries: Array<{
58
58
  entry: DirEntry;
59
- } & MethodHandler>;
59
+ } & MethodHandlerType>;
60
60
  } | undefined;
61
61
  };
62
- type WsClientOptionsWorkflows = WsClientOptionsCommon & {
62
+ export type WsClientOptionsWorkflows = WsClientOptionsCommon & {
63
63
  onWorkflows: (workflows: RpcValue) => void;
64
64
  onWorkflowsFailed: () => void;
65
65
  };
66
- type WsClientOptions = WsClientOptionsLogin | WsClientOptionsWorkflows;
66
+ export type WsClientOptions<MethodHandlerType> = WsClientOptionsLogin<MethodHandlerType> | WsClientOptionsWorkflows;
67
67
  type LsResult = string[];
68
68
  export declare enum DirFlags {
69
69
  Reserved = 1,
@@ -215,7 +215,7 @@ declare class WsClient {
215
215
  private readonly websocket;
216
216
  private readonly options;
217
217
  private readonly timeout;
218
- constructor(options: WsClientOptions);
218
+ constructor(options: WsClientOptions<MethodHandler>);
219
219
  callRpcMethod(shvPath: '.broker/currentClient', method: 'accessGrantForMethodCall', params: [string, string], delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<string>>;
220
220
  callRpcMethod(shvPath: string | undefined, method: 'dir', params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<DirResult>>;
221
221
  callRpcMethod(shvPath: string | undefined, method: 'ls', params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<LsResult>>;
@@ -226,7 +226,7 @@ declare class WsClient {
226
226
  sendPing(): void;
227
227
  accessGrantForMethodCall(path: string, method: string): RpcRequestPromise<ResultOrError<string>>;
228
228
  close(): void;
229
- private logDebug;
229
+ protected logDebug(...args: string[]): void;
230
230
  private workflowsProcedure;
231
231
  private loginProcedure;
232
232
  }
package/dist/ws-client.js CHANGED
@@ -1,48 +1,19 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.WsClient = exports.NotImplemented = exports.UserIDRequired = exports.LoginRequired = exports.Unknown = exports.MethodCallException = exports.MethodCallCancelled = exports.MethodCallTimeout = exports.ParseError = exports.InternalError = exports.InvalidParams = exports.MethodNotFound = exports.InvalidRequest = exports.DIR_EXTRA = exports.DIR_SIGNALS = exports.DIR_ACCESS = exports.DIR_RESULT = exports.DIR_PARAM = exports.DIR_FLAGS = exports.DIR_NAME = exports.DirFlags = exports.DirParamZod = exports.LsParamZod = exports.RequestHandler = void 0;
3
+ exports.WsClient = exports.NotImplemented = exports.UserIDRequired = exports.LoginRequired = exports.Unknown = exports.MethodCallException = exports.MethodCallCancelled = exports.MethodCallTimeout = exports.ParseError = exports.InternalError = exports.InvalidParams = exports.MethodNotFound = exports.InvalidRequest = exports.DIR_EXTRA = exports.DIR_SIGNALS = exports.DIR_ACCESS = exports.DIR_RESULT = exports.DIR_PARAM = exports.DIR_FLAGS = exports.DIR_NAME = exports.DirFlags = exports.validateDirParam = exports.validateLsParam = exports.RequestHandler = void 0;
37
4
  const access_1 = require("./access");
38
5
  const chainpack_1 = require("./chainpack");
39
6
  const cpon_1 = require("./cpon");
40
7
  const rpcmessage_1 = require("./rpcmessage");
41
8
  const rpcvalue_1 = require("./rpcvalue");
42
9
  const utils_1 = require("./utils");
43
- const z = __importStar(require("./zod"));
44
10
  const DEFAULT_TIMEOUT = 5000;
45
11
  const DEFAULT_PING_INTERVAL = 30 * 1000;
12
+ const defaultParseMessage = (rpcVal) => {
13
+ // Assume rpcVal is a valid RpcMessage - no runtime validation
14
+ const rpcMsg = rpcVal;
15
+ return rpcMsg;
16
+ };
46
17
  const dataToRpcValue = (buff) => {
47
18
  const rd = new chainpack_1.ChainPackReader(buff);
48
19
  rd.readUIntData();
@@ -66,8 +37,10 @@ class RequestHandler {
66
37
  }
67
38
  }
68
39
  exports.RequestHandler = RequestHandler;
69
- exports.LsParamZod = z.undefined().or(z.string());
70
- exports.DirParamZod = z.undefined().or(z.boolean()).or(z.string());
40
+ const validateLsParam = (param) => param === undefined || typeof param === 'string';
41
+ exports.validateLsParam = validateLsParam;
42
+ const validateDirParam = (param) => param === undefined || typeof param === 'string' || typeof param === 'boolean';
43
+ exports.validateDirParam = validateDirParam;
71
44
  var DirFlags;
72
45
  (function (DirFlags) {
73
46
  DirFlags[DirFlags["Reserved"] = 1] = "Reserved";
@@ -251,7 +224,7 @@ class WsClient {
251
224
  case 'dir':
252
225
  return {
253
226
  entry: dirEntry,
254
- paramParser: exports.DirParamZod,
227
+ paramValidator: exports.validateDirParam,
255
228
  handler(_shvPath, _method, param) {
256
229
  const methodsResult = [dirEntry, lsEntry, ...methods.dirEntries.map(method => method.entry)];
257
230
  switch (true) {
@@ -267,7 +240,7 @@ class WsClient {
267
240
  case 'ls':
268
241
  return {
269
242
  entry: lsEntry,
270
- paramParser: exports.LsParamZod,
243
+ paramValidator: exports.validateLsParam,
271
244
  handler(shvPath) {
272
245
  return methods.ls(shvPath);
273
246
  },
@@ -285,11 +258,10 @@ class WsClient {
285
258
  return;
286
259
  }
287
260
  const requestParam = request.value[rpcmessage_1.RPC_MESSAGE_PARAMS];
288
- const parsedParam = methodDefinition.paramParser.safeParse(requestParam);
289
- if (!parsedParam.success) {
290
- throw new exports.InvalidParams(`Unexpected param for method ${methodName} on path '${shvPath}': ${(0, cpon_1.toCpon)(requestParam)}`);
261
+ if (methodDefinition.paramValidator !== undefined && !methodDefinition.paramValidator(requestParam)) {
262
+ throw new exports.InvalidParams(`Unexpected param '${shvPath}:${methodName}': ${(0, cpon_1.toCpon)(requestParam)}`);
291
263
  }
292
- let result = methodDefinition.handler(shvPath, methodName, parsedParam.data, sendDelay);
264
+ let result = methodDefinition.handler(shvPath, methodName, requestParam, sendDelay);
293
265
  if (result instanceof RequestHandler) {
294
266
  this.requestHandlers.set(requestId, result);
295
267
  result = result.options.result;
@@ -380,7 +352,8 @@ class WsClient {
380
352
  };
381
353
  this.websocket.addEventListener('message', async (evt) => {
382
354
  const rpcVal = dataToRpcValue(evt.data);
383
- const rpcMsg = rpcmessage_1.RpcMessageZod.parse(rpcVal);
355
+ const parseMessage = this.options.parseMessage ?? defaultParseMessage;
356
+ const rpcMsg = parseMessage(rpcVal);
384
357
  this.logDebug(`message received: ${(0, cpon_1.toCpon)(rpcMsg)}`);
385
358
  if ((0, rpcmessage_1.isSignal)(rpcMsg)) {
386
359
  handleSignal(rpcMsg);
@@ -0,0 +1,11 @@
1
+ import { WsClient, WsClientOptions } from './ws-client';
2
+ import { type RpcValue } from './rpcvalue';
3
+ import * as z from './zod';
4
+ export declare const LsParamZod: z.ZodUnion<[z.ZodUndefined, z.ZodString]>;
5
+ export declare const DirParamZod: z.ZodUnion<[z.ZodUnion<[z.ZodUndefined, z.ZodBoolean]>, z.ZodString]>;
6
+ export type ZodMethodHandler = {
7
+ paramParser: z.ZodType<RpcValue>;
8
+ handler: (shvPath: string, method: string, params: RpcValue, delay: (progress: number) => void) => Promise<RpcValue> | RpcValue | import('./ws-client').RequestHandler;
9
+ };
10
+ declare function createZodWsClient(options: WsClientOptions<ZodMethodHandler>): WsClient;
11
+ export { createZodWsClient };
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DirParamZod = exports.LsParamZod = void 0;
37
+ exports.createZodWsClient = createZodWsClient;
38
+ const ws_client_1 = require("./ws-client");
39
+ const rpcmessage_1 = require("./rpcmessage");
40
+ const z = __importStar(require("./zod"));
41
+ exports.LsParamZod = z.undefined().or(z.string());
42
+ exports.DirParamZod = z.undefined().or(z.boolean()).or(z.string());
43
+ function createZodWsClient(options) {
44
+ const parseMessage = (rpcVal) => {
45
+ try {
46
+ return rpcmessage_1.RpcMessageZod.parse(rpcVal);
47
+ }
48
+ catch (error) {
49
+ console.error('RPC Message validation failed:', error);
50
+ throw error;
51
+ }
52
+ };
53
+ const convertedOptions = 'login' in options ? {
54
+ ...options,
55
+ parseMessage,
56
+ onRequest(shvPath) {
57
+ const zodHandlers = options.onRequest(shvPath);
58
+ if (zodHandlers === undefined) {
59
+ return;
60
+ }
61
+ return {
62
+ ls: zodHandlers.ls,
63
+ dirEntries: zodHandlers.dirEntries.map(zodHandler => ({
64
+ entry: zodHandler.entry,
65
+ paramValidator(param) {
66
+ const result = zodHandler.paramParser.safeParse(param);
67
+ if (!result.success) {
68
+ console.error(`Parameter validation failed for '${shvPath}:${zodHandler.entry[ws_client_1.DIR_NAME]}':`, result.error.message);
69
+ return false;
70
+ }
71
+ return true;
72
+ },
73
+ handler: zodHandler.handler,
74
+ })),
75
+ };
76
+ },
77
+ } : {
78
+ ...options,
79
+ parseMessage,
80
+ };
81
+ return new ws_client_1.WsClient(convertedOptions);
82
+ }
package/dist/zod.d.ts CHANGED
@@ -28,3 +28,4 @@ export declare const list: () => z.ZodArray<z.ZodLazy<z.ZodType<RpcValue>>>;
28
28
  export declare const rpcvalue: () => ZodType<RpcValue>;
29
29
  export declare const withMeta: <MetaSchema extends MetaMap, ValueSchema extends RpcValueType>(metaParser: ZodType<MetaSchema>, valueParser: ZodType<ValueSchema>) => z.ZodCustom<RpcValueWithMetaData<MetaSchema, ValueSchema>, RpcValueWithMetaData<MetaSchema, ValueSchema>>;
30
30
  export * from 'zod/v4';
31
+ export { z } from 'zod/v4';
package/dist/zod.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.withMeta = exports.rpcvalue = exports.list = exports.blob = exports.decimal = exports.double = exports.uint = exports.recmap = exports.metamap = exports.imap = exports.map = void 0;
17
+ exports.z = exports.withMeta = exports.rpcvalue = exports.list = exports.blob = exports.decimal = exports.double = exports.uint = exports.recmap = exports.metamap = exports.imap = exports.map = void 0;
18
18
  /* eslint-disable @typescript-eslint/no-explicit-any */
19
19
  const v4_1 = require("zod/v4");
20
20
  const rpcvalue_1 = require("./rpcvalue");
@@ -110,3 +110,5 @@ const withMeta = (metaParser, valueParser) => v4_1.z.custom().check(ctx => {
110
110
  });
111
111
  exports.withMeta = withMeta;
112
112
  __exportStar(require("zod/v4"), exports);
113
+ var v4_2 = require("zod/v4");
114
+ Object.defineProperty(exports, "z", { enumerable: true, get: function () { return v4_2.z; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.23.3",
3
+ "version": "3.24.0",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -36,12 +36,13 @@
36
36
  "./utils": "./dist/utils.js",
37
37
  "./vue-shv": "./dist/vue-shv.js",
38
38
  "./ws-client": "./dist/ws-client.js",
39
- "./zod": "./dist/zod.js"
39
+ "./zod": "./dist/zod.js",
40
+ "./zod-ws-client": "./dist/zod-ws-client.js"
40
41
  },
41
42
  "dependencies": {
42
43
  "@vueuse/core": "^13.5.0",
43
44
  "js-pkce": "^2.0.0",
44
- "vue": "^3.5.18",
45
+ "vue": "^3.5.22",
45
46
  "zod": "^4.0.11"
46
47
  },
47
48
  "devDependencies": {