libshv-js 3.24.0 → 4.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.
package/dist/index.d.ts CHANGED
@@ -5,7 +5,4 @@ export * from './cpon';
5
5
  export * from './json';
6
6
  export * from './rpcmessage';
7
7
  export * from './rpcvalue';
8
- export * from './vue-shv';
9
8
  export * from './ws-client';
10
- export * from './zod';
11
- export * from './zod-ws-client';
package/dist/index.js CHANGED
@@ -21,7 +21,4 @@ __exportStar(require("./cpon"), exports);
21
21
  __exportStar(require("./json"), exports);
22
22
  __exportStar(require("./rpcmessage"), exports);
23
23
  __exportStar(require("./rpcvalue"), exports);
24
- __exportStar(require("./vue-shv"), exports);
25
24
  __exportStar(require("./ws-client"), exports);
26
- __exportStar(require("./zod"), exports);
27
- __exportStar(require("./zod-ws-client"), exports);
@@ -1,5 +1,4 @@
1
- import * as z from './zod';
2
- import { type shvMapType } from './rpcvalue';
1
+ import { Double, IMap, MetaMap, RpcValue, type RpcValueWithMetaData } from './rpcvalue';
3
2
  export declare const RPC_MESSAGE_REQUEST_ID = 8;
4
3
  export declare const RPC_MESSAGE_SHV_PATH = 9;
5
4
  export declare const RPC_MESSAGE_METHOD = 10;
@@ -13,7 +12,7 @@ export declare const RPC_MESSAGE_ABORT = 5;
13
12
  export declare const ERROR_CODE = 1;
14
13
  export declare const ERROR_MESSAGE = 2;
15
14
  export declare const ERROR_DATA = 3;
16
- declare enum ErrorCode {
15
+ export declare enum ErrorCode {
17
16
  InvalidRequest = 1,
18
17
  MethodNotFound = 2,
19
18
  InvalidParams = 3,
@@ -27,259 +26,46 @@ declare enum ErrorCode {
27
26
  UserIDRequired = 11,
28
27
  NotImplemented = 12
29
28
  }
30
- declare const ErrorMapZod: z.ZodCustom<{
31
- 1: number;
32
- 2?: string | undefined;
33
- 3?: import("./rpcvalue").RpcValue;
34
- } & {
35
- [shvMapType]: "imap";
36
- }, {
37
- 1: number;
38
- 2?: string | undefined;
39
- 3?: import("./rpcvalue").RpcValue;
40
- } & {
41
- [shvMapType]: "imap";
29
+ export type ErrorMap = IMap<{
30
+ [ERROR_CODE]: number;
31
+ [ERROR_MESSAGE]?: string | undefined;
32
+ [ERROR_DATA]?: RpcValue;
42
33
  }>;
43
- export type ErrorMap = z.infer<typeof ErrorMapZod>;
44
- declare const RpcResponseValueZod: z.ZodUnion<[z.ZodUnion<[z.ZodCustom<{
45
- 2: import("./rpcvalue").RpcValue;
46
- } & {
47
- [shvMapType]: "imap";
48
- }, {
49
- 2: import("./rpcvalue").RpcValue;
50
- } & {
51
- [shvMapType]: "imap";
52
- }>, z.ZodCustom<{
53
- 3: {
54
- 1: number;
55
- 2?: string | undefined;
56
- 3?: import("./rpcvalue").RpcValue;
57
- } & {
58
- [shvMapType]: "imap";
59
- };
60
- } & {
61
- [shvMapType]: "imap";
62
- }, {
63
- 3: {
64
- 1: number;
65
- 2?: string | undefined;
66
- 3?: import("./rpcvalue").RpcValue;
67
- } & {
68
- [shvMapType]: "imap";
69
- };
70
- } & {
71
- [shvMapType]: "imap";
72
- }>]>, z.ZodCustom<{
73
- 4: import("./rpcvalue").Double;
74
- } & {
75
- [shvMapType]: "imap";
76
- }, {
77
- 4: import("./rpcvalue").Double;
78
- } & {
79
- [shvMapType]: "imap";
80
- }>]>;
81
- declare const RpcRequestZod: z.ZodCustom<import("./rpcvalue").RpcValueWithMetaData<{
82
- 8: number;
83
- 10: string;
84
- 9: string;
85
- 11?: number | number[] | undefined;
86
- 17?: number | undefined;
87
- } & {
88
- [shvMapType]: "metamap";
89
- }, ({
90
- 1?: import("./rpcvalue").RpcValue;
91
- } & {
92
- [shvMapType]: "imap";
93
- }) | ({
94
- 5: boolean;
95
- } & {
96
- [shvMapType]: "imap";
97
- })>, import("./rpcvalue").RpcValueWithMetaData<{
98
- 8: number;
99
- 10: string;
100
- 9: string;
101
- 11?: number | number[] | undefined;
102
- 17?: number | undefined;
103
- } & {
104
- [shvMapType]: "metamap";
105
- }, ({
106
- 1?: import("./rpcvalue").RpcValue;
107
- } & {
108
- [shvMapType]: "imap";
109
- }) | ({
110
- 5: boolean;
111
- } & {
112
- [shvMapType]: "imap";
113
- })>>;
114
- declare const RpcResponseZod: z.ZodCustom<import("./rpcvalue").RpcValueWithMetaData<{
115
- 8: number;
116
- 11?: number | number[] | undefined;
117
- } & {
118
- [shvMapType]: "metamap";
119
- }, ({
120
- 2: import("./rpcvalue").RpcValue;
121
- } & {
122
- [shvMapType]: "imap";
123
- }) | ({
124
- 3: {
125
- 1: number;
126
- 2?: string | undefined;
127
- 3?: import("./rpcvalue").RpcValue;
128
- } & {
129
- [shvMapType]: "imap";
130
- };
131
- } & {
132
- [shvMapType]: "imap";
133
- }) | ({
134
- 4: import("./rpcvalue").Double;
135
- } & {
136
- [shvMapType]: "imap";
137
- })>, import("./rpcvalue").RpcValueWithMetaData<{
138
- 8: number;
139
- 11?: number | number[] | undefined;
140
- } & {
141
- [shvMapType]: "metamap";
142
- }, ({
143
- 2: import("./rpcvalue").RpcValue;
144
- } & {
145
- [shvMapType]: "imap";
146
- }) | ({
147
- 3: {
148
- 1: number;
149
- 2?: string | undefined;
150
- 3?: import("./rpcvalue").RpcValue;
151
- } & {
152
- [shvMapType]: "imap";
153
- };
154
- } & {
155
- [shvMapType]: "imap";
156
- }) | ({
157
- 4: import("./rpcvalue").Double;
158
- } & {
159
- [shvMapType]: "imap";
160
- })>>;
161
- declare const RpcSignalZod: z.ZodCustom<import("./rpcvalue").RpcValueWithMetaData<{
162
- 9: string;
163
- 10: string;
164
- } & {
165
- [shvMapType]: "metamap";
166
- }, {
167
- 1?: import("./rpcvalue").RpcValue;
168
- } & {
169
- [shvMapType]: "imap";
170
- }>, import("./rpcvalue").RpcValueWithMetaData<{
171
- 9: string;
172
- 10: string;
173
- } & {
174
- [shvMapType]: "metamap";
175
- }, {
176
- 1?: import("./rpcvalue").RpcValue;
177
- } & {
178
- [shvMapType]: "imap";
179
- }>>;
180
- declare const RpcMessageZod: z.ZodUnion<readonly [z.ZodCustom<import("./rpcvalue").RpcValueWithMetaData<{
181
- 8: number;
182
- 10: string;
183
- 9: string;
184
- 11?: number | number[] | undefined;
185
- 17?: number | undefined;
186
- } & {
187
- [shvMapType]: "metamap";
188
- }, ({
189
- 1?: import("./rpcvalue").RpcValue;
190
- } & {
191
- [shvMapType]: "imap";
192
- }) | ({
193
- 5: boolean;
194
- } & {
195
- [shvMapType]: "imap";
196
- })>, import("./rpcvalue").RpcValueWithMetaData<{
197
- 8: number;
198
- 10: string;
199
- 9: string;
200
- 11?: number | number[] | undefined;
201
- 17?: number | undefined;
202
- } & {
203
- [shvMapType]: "metamap";
204
- }, ({
205
- 1?: import("./rpcvalue").RpcValue;
206
- } & {
207
- [shvMapType]: "imap";
208
- }) | ({
209
- 5: boolean;
210
- } & {
211
- [shvMapType]: "imap";
212
- })>>, z.ZodCustom<import("./rpcvalue").RpcValueWithMetaData<{
213
- 8: number;
214
- 11?: number | number[] | undefined;
215
- } & {
216
- [shvMapType]: "metamap";
217
- }, ({
218
- 2: import("./rpcvalue").RpcValue;
219
- } & {
220
- [shvMapType]: "imap";
221
- }) | ({
222
- 3: {
223
- 1: number;
224
- 2?: string | undefined;
225
- 3?: import("./rpcvalue").RpcValue;
226
- } & {
227
- [shvMapType]: "imap";
228
- };
229
- } & {
230
- [shvMapType]: "imap";
231
- }) | ({
232
- 4: import("./rpcvalue").Double;
233
- } & {
234
- [shvMapType]: "imap";
235
- })>, import("./rpcvalue").RpcValueWithMetaData<{
236
- 8: number;
237
- 11?: number | number[] | undefined;
238
- } & {
239
- [shvMapType]: "metamap";
240
- }, ({
241
- 2: import("./rpcvalue").RpcValue;
242
- } & {
243
- [shvMapType]: "imap";
244
- }) | ({
245
- 3: {
246
- 1: number;
247
- 2?: string | undefined;
248
- 3?: import("./rpcvalue").RpcValue;
249
- } & {
250
- [shvMapType]: "imap";
251
- };
252
- } & {
253
- [shvMapType]: "imap";
254
- }) | ({
255
- 4: import("./rpcvalue").Double;
256
- } & {
257
- [shvMapType]: "imap";
258
- })>>, z.ZodCustom<import("./rpcvalue").RpcValueWithMetaData<{
259
- 9: string;
260
- 10: string;
261
- } & {
262
- [shvMapType]: "metamap";
263
- }, {
264
- 1?: import("./rpcvalue").RpcValue;
265
- } & {
266
- [shvMapType]: "imap";
267
- }>, import("./rpcvalue").RpcValueWithMetaData<{
268
- 9: string;
269
- 10: string;
270
- } & {
271
- [shvMapType]: "metamap";
272
- }, {
273
- 1?: import("./rpcvalue").RpcValue;
274
- } & {
275
- [shvMapType]: "imap";
276
- }>>]>;
277
- export type RpcRequest = z.infer<typeof RpcRequestZod>;
278
- export type RpcResponse = z.infer<typeof RpcResponseZod>;
279
- export type RpcResponseValue = z.infer<typeof RpcResponseValueZod>;
280
- export type RpcSignal = z.infer<typeof RpcSignalZod>;
281
- export type RpcMessage = z.infer<typeof RpcMessageZod>;
282
- export declare const isSignal: (message: RpcMessage) => message is RpcSignal;
283
- export declare const isRequest: (message: RpcMessage) => message is RpcRequest;
284
- export declare const isResponse: (message: RpcMessage) => message is RpcResponse;
285
- export { RpcMessageZod, ErrorCode };
34
+ type RpcRequestMeta = MetaMap<{
35
+ [RPC_MESSAGE_REQUEST_ID]: number;
36
+ [RPC_MESSAGE_SHV_PATH]: string;
37
+ [RPC_MESSAGE_METHOD]: string;
38
+ [RPC_MESSAGE_CALLER_IDS]?: number | number[] | undefined;
39
+ [RPC_MESSAGE_ACCESS_LEVEL]?: number | undefined;
40
+ }>;
41
+ type RpcRequestValue = IMap<{
42
+ [RPC_MESSAGE_PARAMS]?: RpcValue;
43
+ }> | IMap<{
44
+ [RPC_MESSAGE_ABORT]: boolean;
45
+ }>;
46
+ export type RpcRequest = RpcValueWithMetaData<RpcRequestMeta, RpcRequestValue>;
47
+ type RpcResponseMeta = MetaMap<{
48
+ [RPC_MESSAGE_REQUEST_ID]: number;
49
+ [RPC_MESSAGE_CALLER_IDS]?: number | number[] | undefined;
50
+ }>;
51
+ export type RpcResponseValue = IMap<{
52
+ [RPC_MESSAGE_RESULT]: RpcValue;
53
+ }> | IMap<{
54
+ [RPC_MESSAGE_ERROR]: ErrorMap;
55
+ }> | IMap<{
56
+ [RPC_MESSAGE_DELAY]: Double;
57
+ }>;
58
+ export type RpcResponse = RpcValueWithMetaData<RpcResponseMeta, RpcResponseValue>;
59
+ type RpcSignalMeta = MetaMap<{
60
+ [RPC_MESSAGE_SHV_PATH]: string;
61
+ [RPC_MESSAGE_METHOD]: string;
62
+ }>;
63
+ type RpcSignalValue = IMap<{
64
+ [RPC_MESSAGE_PARAMS]?: RpcValue;
65
+ }>;
66
+ export type RpcSignal = RpcValueWithMetaData<RpcSignalMeta, RpcSignalValue>;
67
+ export type RpcMessage = RpcRequest | RpcResponse | RpcSignal;
68
+ export declare const isSignal: (message: unknown) => message is RpcSignal;
69
+ export declare const isRequest: (message: unknown) => message is RpcRequest;
70
+ export declare const isResponse: (message: unknown) => message is RpcResponse;
71
+ export {};
@@ -1,40 +1,6 @@
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.ErrorCode = exports.RpcMessageZod = exports.isResponse = exports.isRequest = exports.isSignal = 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;
37
- const z = __importStar(require("./zod"));
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;
38
4
  exports.RPC_MESSAGE_REQUEST_ID = 8;
39
5
  exports.RPC_MESSAGE_SHV_PATH = 9;
40
6
  exports.RPC_MESSAGE_METHOD = 10;
@@ -63,49 +29,14 @@ var ErrorCode;
63
29
  ErrorCode[ErrorCode["UserIDRequired"] = 11] = "UserIDRequired";
64
30
  ErrorCode[ErrorCode["NotImplemented"] = 12] = "NotImplemented";
65
31
  })(ErrorCode || (exports.ErrorCode = ErrorCode = {}));
66
- const ErrorMapZod = z.imap({
67
- [exports.ERROR_CODE]: z.number(),
68
- [exports.ERROR_MESSAGE]: z.string().optional(),
69
- [exports.ERROR_DATA]: z.rpcvalue().optional(),
70
- });
71
- const RpcRequestMetaZod = z.metamap({
72
- [exports.RPC_MESSAGE_CALLER_IDS]: z.int().or(z.array(z.int())).optional(),
73
- [exports.RPC_MESSAGE_REQUEST_ID]: z.number(),
74
- [exports.RPC_MESSAGE_METHOD]: z.string(),
75
- [exports.RPC_MESSAGE_SHV_PATH]: z.string(),
76
- [exports.RPC_MESSAGE_ACCESS_LEVEL]: z.int().gte(0).lte(63).optional(),
77
- });
78
- const RpcRequestValueZod = z.imap({
79
- [exports.RPC_MESSAGE_PARAMS]: z.rpcvalue().optional(),
80
- }).or(z.imap({
81
- [exports.RPC_MESSAGE_ABORT]: z.boolean(),
82
- }));
83
- const RpcResponseMetaZod = z.metamap({
84
- [exports.RPC_MESSAGE_CALLER_IDS]: z.int().or(z.array(z.int())).optional(),
85
- [exports.RPC_MESSAGE_REQUEST_ID]: z.number(),
86
- });
87
- const RpcResponseValueZod = z.imap({
88
- [exports.RPC_MESSAGE_RESULT]: z.rpcvalue(),
89
- }).or(z.imap({
90
- [exports.RPC_MESSAGE_ERROR]: ErrorMapZod,
91
- })).or(z.imap({
92
- [exports.RPC_MESSAGE_DELAY]: z.double(),
93
- }));
94
- const RpcSignalMetaZod = z.metamap({
95
- [exports.RPC_MESSAGE_SHV_PATH]: z.string(),
96
- [exports.RPC_MESSAGE_METHOD]: z.string(),
97
- });
98
- const RpcSignalValueZod = z.imap({
99
- [exports.RPC_MESSAGE_PARAMS]: z.rpcvalue().optional(),
100
- });
101
- const RpcRequestZod = z.withMeta(RpcRequestMetaZod, RpcRequestValueZod);
102
- const RpcResponseZod = z.withMeta(RpcResponseMetaZod, RpcResponseValueZod);
103
- const RpcSignalZod = z.withMeta(RpcSignalMetaZod, RpcSignalValueZod);
104
- const RpcMessageZod = z.union([RpcRequestZod, RpcResponseZod, RpcSignalZod]);
105
- exports.RpcMessageZod = RpcMessageZod;
106
- const isSignal = (message) => !(exports.RPC_MESSAGE_REQUEST_ID in message.meta) && exports.RPC_MESSAGE_METHOD in message.meta;
32
+ const implRpcMessage = (message) => typeof message === 'object'
33
+ && message !== null
34
+ && 'meta' in message
35
+ && typeof message.meta === 'object'
36
+ && message.meta !== null;
37
+ const isSignal = (message) => implRpcMessage(message) && !(exports.RPC_MESSAGE_REQUEST_ID in message.meta) && exports.RPC_MESSAGE_METHOD in message.meta;
107
38
  exports.isSignal = isSignal;
108
- const isRequest = (message) => exports.RPC_MESSAGE_REQUEST_ID in message.meta && exports.RPC_MESSAGE_METHOD in message.meta;
39
+ const isRequest = (message) => implRpcMessage(message) && exports.RPC_MESSAGE_REQUEST_ID in message.meta && exports.RPC_MESSAGE_METHOD in message.meta;
109
40
  exports.isRequest = isRequest;
110
- const isResponse = (message) => exports.RPC_MESSAGE_REQUEST_ID in message.meta && !(exports.RPC_MESSAGE_METHOD in message.meta);
41
+ const isResponse = (message) => implRpcMessage(message) && exports.RPC_MESSAGE_REQUEST_ID in message.meta && !(exports.RPC_MESSAGE_METHOD in message.meta);
111
42
  exports.isResponse = isResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.24.0",
3
+ "version": "4.0.0",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,8 +8,8 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "test": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.js && node dist-tests/tests/test_zod.js",
12
- "test:ci": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.js && node dist-tests/tests/test_zod.js",
11
+ "test": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.js",
12
+ "test:ci": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.js",
13
13
  "lint": "eslint --format unix src/",
14
14
  "fix": "npm run lint -- --fix",
15
15
  "typecheck": "tsc -p tsconfig.tests.json --noEmit",
@@ -34,16 +34,7 @@
34
34
  "./rpcmessage": "./dist/rpcmessage.js",
35
35
  "./rpcvalue": "./dist/rpcvalue.js",
36
36
  "./utils": "./dist/utils.js",
37
- "./vue-shv": "./dist/vue-shv.js",
38
- "./ws-client": "./dist/ws-client.js",
39
- "./zod": "./dist/zod.js",
40
- "./zod-ws-client": "./dist/zod-ws-client.js"
41
- },
42
- "dependencies": {
43
- "@vueuse/core": "^13.5.0",
44
- "js-pkce": "^2.0.0",
45
- "vue": "^3.5.22",
46
- "zod": "^4.0.11"
37
+ "./ws-client": "./dist/ws-client.js"
47
38
  },
48
39
  "devDependencies": {
49
40
  "@typescript-eslint/parser": "^8.38.0",
package/dist/vue-shv.d.ts DELETED
@@ -1,94 +0,0 @@
1
- import { ComputedRef, Ref } from 'vue';
2
- import { type WsClient, type WsClientOptionsLogin } from './ws-client';
3
- import PKCE from 'js-pkce';
4
- import * as z from './zod';
5
- import { type shvMapType } from './rpcvalue';
6
- import { RpcValue } from './rpcvalue';
7
- import { StringGetter } from './utils';
8
- import { ZodMethodHandler } from './zod-ws-client';
9
- type GlobalResourceOptions<ResourceType> = {
10
- shvPath: StringGetter;
11
- method: string;
12
- validator: z.ZodType<ResourceType>;
13
- signalName: string;
14
- signalHandler: (param: RpcValue, resource: Ref<ResourceType | undefined>, reinit: () => void) => void;
15
- };
16
- type VueShvOptions = {
17
- wsUri: StringGetter;
18
- onRequest: WsClientOptionsLogin<ZodMethodHandler>['onRequest'];
19
- azureCodeRedirect?: string;
20
- mountPoint?: string;
21
- };
22
- type ShvLocalStorage = {
23
- azureAccessToken?: string;
24
- azureRedirectTo?: string;
25
- };
26
- type ShvSessionStorage = {
27
- shvLoginUser?: string;
28
- shvLoginPassword?: string;
29
- azureWorkflow?: z.infer<typeof OAuth2AzureWorkflowZod>;
30
- };
31
- declare const OAuth2AzureWorkflowZod: z.ZodCustom<{
32
- type: "oauth2-azure";
33
- authorizeUrl: string;
34
- tokenUrl: string;
35
- clientId: string;
36
- scopes: string | string[];
37
- } & {
38
- [shvMapType]: "map";
39
- }, {
40
- type: "oauth2-azure";
41
- authorizeUrl: string;
42
- tokenUrl: string;
43
- clientId: string;
44
- scopes: string | string[];
45
- } & {
46
- [shvMapType]: "map";
47
- }>;
48
- export declare enum LoginFailureReason {
49
- NoCredentials = 0,
50
- AzureTimedOut = 1,
51
- AzureUnsupported = 2,
52
- CouldntLogin = 3,
53
- LoggedOut = 4
54
- }
55
- type LoginFailure = {
56
- reason: LoginFailureReason;
57
- message?: string;
58
- };
59
- declare const makePkce: (oauthOptions: {
60
- azureCodeRedirect: string;
61
- clientId: string;
62
- authorizeUrl: string;
63
- tokenUrl: string;
64
- scopes: string | string[];
65
- }) => PKCE;
66
- export { makePkce as azure };
67
- export declare function useShv(options: VueShvOptions): {
68
- azureAuth: (redirectTo: string) => Promise<void>;
69
- azureHandlerError: Ref<string, string>;
70
- connected: Ref<"connected" | "connecting" | "disconnected", "connected" | "connecting" | "disconnected">;
71
- displayEmail: Ref<string, string>;
72
- displayFullName: Ref<string, string>;
73
- displayName: Ref<string, string>;
74
- displayPhoto: Ref<string | undefined, string | undefined>;
75
- displayShortName: Ref<string, string>;
76
- getConnection: () => Promise<WsClient>;
77
- handleAzureCode: () => Promise<string | void>;
78
- logContents: Ref<string, string>;
79
- loginFailure: Ref<LoginFailure | undefined, LoginFailure | undefined>;
80
- makeGlobalResource: {
81
- <ResourceType>(options: GlobalResourceOptions<ResourceType>): () => Ref<ResourceType | undefined>;
82
- <ResourceType>(options: GlobalResourceOptions<ResourceType> & {
83
- default: ResourceType;
84
- }): () => ComputedRef<ResourceType>;
85
- };
86
- makeRpcCall: <ResultType>(shvPath: StringGetter, method: string, validator: z.ZodType<ResultType>) => () => Promise<Error | ResultType>;
87
- makeRpcCallParam: <ResultType, ParamType extends RpcValue>(shvPath: StringGetter, method: string, _paramType: z.ZodType<ParamType>, validator: z.ZodType<ResultType>) => (param: ParamType) => Promise<Error | ResultType>;
88
- rpcCall: (shvPath: StringGetter, method: string, params?: RpcValue) => Promise<Error | RpcValue>;
89
- setShvCredentials: (userName: string, password: string) => void;
90
- shvLocalStorage: import("@vueuse/shared").RemovableRef<ShvLocalStorage>;
91
- shvLogout: () => void;
92
- shvSessionStorage: import("@vueuse/shared").RemovableRef<ShvSessionStorage>;
93
- };
94
- export declare const fullReloadHandler: (_param: RpcValue, _resource: unknown, reinit: () => void) => void;
package/dist/vue-shv.js DELETED
@@ -1,441 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.fullReloadHandler = exports.azure = exports.LoginFailureReason = void 0;
40
- exports.useShv = useShv;
41
- const vue_1 = require("vue");
42
- const core_1 = require("@vueuse/core");
43
- const js_pkce_1 = __importDefault(require("js-pkce"));
44
- const z = __importStar(require("./zod"));
45
- const utils_1 = require("./utils");
46
- const zod_ws_client_1 = require("./zod-ws-client");
47
- const OAuth2AzureWorkflowZod = z.map({
48
- type: z.literal('oauth2-azure'),
49
- authorizeUrl: z.string(),
50
- tokenUrl: z.string(),
51
- clientId: z.string(),
52
- scopes: z.string().or(z.array(z.string())),
53
- });
54
- var LoginFailureReason;
55
- (function (LoginFailureReason) {
56
- LoginFailureReason[LoginFailureReason["NoCredentials"] = 0] = "NoCredentials";
57
- LoginFailureReason[LoginFailureReason["AzureTimedOut"] = 1] = "AzureTimedOut";
58
- LoginFailureReason[LoginFailureReason["AzureUnsupported"] = 2] = "AzureUnsupported";
59
- LoginFailureReason[LoginFailureReason["CouldntLogin"] = 3] = "CouldntLogin";
60
- LoginFailureReason[LoginFailureReason["LoggedOut"] = 4] = "LoggedOut";
61
- })(LoginFailureReason || (exports.LoginFailureReason = LoginFailureReason = {}));
62
- const makePkce = (oauthOptions) => {
63
- const pkce = new js_pkce_1.default({
64
- client_id: oauthOptions.clientId,
65
- redirect_uri: (() => {
66
- const url = new URL(globalThis.location.href);
67
- url.pathname = oauthOptions.azureCodeRedirect;
68
- url.search = '';
69
- return url.toString();
70
- })(),
71
- authorization_endpoint: oauthOptions.authorizeUrl,
72
- token_endpoint: oauthOptions.tokenUrl,
73
- requested_scopes: Array.isArray(oauthOptions.scopes) ? oauthOptions.scopes.join(' ') : oauthOptions.scopes,
74
- });
75
- return pkce;
76
- };
77
- exports.azure = makePkce;
78
- function useShv(options) {
79
- const shvLocalStorage = (0, core_1.useLocalStorage)('vue-shv', {});
80
- const shvSessionStorage = (0, core_1.useSessionStorage)('vue-shv', {});
81
- const displayName = (0, vue_1.ref)('Loading...');
82
- const displayShortName = (0, vue_1.ref)('');
83
- const displayFullName = (0, vue_1.ref)('');
84
- const displayEmail = (0, vue_1.ref)('');
85
- const displayPhoto = (0, vue_1.ref)();
86
- const state = {
87
- ws: undefined,
88
- reconnectService: undefined,
89
- };
90
- const waitingForSocket = [];
91
- const resetAzureToken = () => {
92
- shvLocalStorage.value.azureAccessToken = undefined;
93
- };
94
- const azureAvailable = async () => {
95
- const accessToken = shvLocalStorage.value.azureAccessToken;
96
- if (accessToken === undefined) {
97
- return LoginFailureReason.NoCredentials;
98
- }
99
- const resp = await fetch('https://graph.microsoft.com/v1.0/me', {
100
- headers: {
101
- Authorization: `Bearer ${accessToken}`,
102
- },
103
- });
104
- const json = await resp.json();
105
- if (typeof json === 'object' && json !== null) {
106
- if ('displayName' in json && typeof json.displayName === 'string') {
107
- displayName.value = json.displayName;
108
- }
109
- if ('givenName' in json && typeof json.givenName === 'string'
110
- && 'surname' in json && typeof json.surname === 'string') {
111
- const firstName = json.givenName;
112
- const lastname = json.surname;
113
- displayShortName.value = firstName.charAt(0) + lastname.charAt(0);
114
- displayFullName.value = firstName + ' ' + lastname;
115
- }
116
- if ('mail' in json && typeof json.mail === 'string') {
117
- displayEmail.value = json.mail;
118
- }
119
- }
120
- const photo = await fetch('https://graph.microsoft.com/v1.0/me/photos/48x48/$value', {
121
- headers: {
122
- Authorization: `Bearer ${accessToken}`,
123
- },
124
- });
125
- if (photo.ok) {
126
- displayPhoto.value = URL.createObjectURL(await photo.blob());
127
- }
128
- if (!resp.ok) {
129
- resetAzureToken();
130
- }
131
- return resp.ok ? 'azureAvailable' : LoginFailureReason.AzureTimedOut;
132
- };
133
- const debug = (...args) => {
134
- logContents.value = logContents.value + args.join(' ') + '\n';
135
- console.debug(...args);
136
- };
137
- const azureAuth = async (redirectTo) => {
138
- if (options.azureCodeRedirect === undefined) {
139
- throw new Error('Azure redirect URL not set');
140
- }
141
- const { azureCodeRedirect } = options;
142
- shvLocalStorage.value.azureRedirectTo = redirectTo;
143
- const noBrokerSupport = () => {
144
- loginFailure.value = {
145
- reason: LoginFailureReason.AzureUnsupported,
146
- message: 'Broker does not support Azure',
147
- };
148
- };
149
- state.ws = (0, zod_ws_client_1.createZodWsClient)({
150
- logDebug: debug,
151
- wsUri: await (0, utils_1.resolveString)(options.wsUri),
152
- onWorkflows(workflows) {
153
- if (!Array.isArray(workflows)) {
154
- noBrokerSupport();
155
- return;
156
- }
157
- for (const workflow of workflows) {
158
- const parsedWorkflow = OAuth2AzureWorkflowZod.safeParse(workflow);
159
- if (!parsedWorkflow.success) {
160
- continue;
161
- }
162
- shvSessionStorage.value.azureWorkflow = parsedWorkflow.data;
163
- globalThis.location.replace(makePkce({ ...parsedWorkflow.data, azureCodeRedirect }).authorizeUrl());
164
- }
165
- noBrokerSupport();
166
- },
167
- onWorkflowsFailed() {
168
- noBrokerSupport();
169
- },
170
- });
171
- };
172
- const setShvCredentials = (userName, password) => {
173
- shvLogout();
174
- shvSessionStorage.value.shvLoginUser = userName;
175
- shvSessionStorage.value.shvLoginPassword = password;
176
- };
177
- const rpcCall = async (shvPath, method, params) => {
178
- const shv = await getConnection();
179
- return shv.callRpcMethod(await (0, utils_1.resolveString)(shvPath), method, params);
180
- };
181
- const makeRpcCall = (shvPath, method, validator) => async () => {
182
- const resultOrError = await rpcCall(await (0, utils_1.resolveString)(shvPath), method);
183
- if (resultOrError instanceof Error) {
184
- return resultOrError;
185
- }
186
- const parsed = validator.safeParse(resultOrError);
187
- if (!parsed.success) {
188
- return new Error(parsed.error.message);
189
- }
190
- return parsed.data;
191
- };
192
- const makeRpcCallParam = (shvPath, method, _paramType, validator) => async (param) => {
193
- const resultOrError = await rpcCall(await (0, utils_1.resolveString)(shvPath), method, param);
194
- if (resultOrError instanceof Error) {
195
- return resultOrError;
196
- }
197
- const parsed = validator.safeParse(resultOrError);
198
- if (!parsed.success) {
199
- return new Error(parsed.error.message);
200
- }
201
- return parsed.data;
202
- };
203
- const connected = (0, vue_1.ref)('disconnected');
204
- const logContents = (0, vue_1.ref)('');
205
- const shvLogout = () => {
206
- resetAzureToken();
207
- shvSessionStorage.value.shvLoginUser = undefined;
208
- shvSessionStorage.value.shvLoginPassword = undefined;
209
- for (const waiter of waitingForSocket) {
210
- waiter.reject();
211
- }
212
- connected.value = 'disconnected';
213
- waitingForSocket.length = 0;
214
- state.ws?.close();
215
- displayName.value = 'Logged out';
216
- displayPhoto.value = undefined;
217
- state.ws = undefined;
218
- };
219
- const loginFailure = (0, vue_1.ref)();
220
- const getConnection = async () => {
221
- if (connected.value === 'connected') {
222
- return state.ws;
223
- }
224
- return new Promise((resolve, reject) => {
225
- waitingForSocket.push({ resolve, reject });
226
- if (connected.value === 'connecting') {
227
- // We should try to connect only once at the same time.
228
- return;
229
- }
230
- connected.value = 'connecting';
231
- const doConnect = async (user, password, loginType) => {
232
- const wsUri = await (0, utils_1.resolveString)(options.wsUri);
233
- console.log('Connecting to', wsUri);
234
- const makeLoginOptions = () => {
235
- switch (loginType) {
236
- case 'PLAIN':
237
- return {
238
- type: loginType,
239
- user,
240
- password,
241
- };
242
- case 'TOKEN':
243
- return {
244
- type: loginType,
245
- token: `oauth2-azure:${password}`,
246
- };
247
- }
248
- };
249
- state.ws = (0, zod_ws_client_1.createZodWsClient)({
250
- login: makeLoginOptions(),
251
- wsUri,
252
- timeout: 120_000,
253
- mountPoint: options.mountPoint,
254
- logDebug: debug,
255
- onConnected() {
256
- for (const waiter of waitingForSocket) {
257
- waiter.resolve(state.ws);
258
- }
259
- waitingForSocket.length = 0;
260
- console.log('Connected to', wsUri);
261
- connected.value = 'connected';
262
- },
263
- onConnectionFailure(error) {
264
- console.error(`Failed to connect to: ${wsUri}`, error);
265
- shvLogout();
266
- loginFailure.value = {
267
- reason: LoginFailureReason.CouldntLogin,
268
- message: error.message,
269
- };
270
- },
271
- onDisconnected() {
272
- connected.value = 'disconnected';
273
- const RECONNECT_INTERVAL = 3000;
274
- if (shvLocalStorage.value.azureAccessToken !== undefined) {
275
- console.log('Disconnected from', wsUri, 'reconnecting in', RECONNECT_INTERVAL, 'ms');
276
- state.reconnectService = globalThis.setTimeout(async () => {
277
- await getConnection();
278
- }, RECONNECT_INTERVAL);
279
- }
280
- },
281
- onRequest: options.onRequest,
282
- });
283
- };
284
- const shvUser = shvSessionStorage.value.shvLoginUser;
285
- const shvPassword = shvSessionStorage.value.shvLoginPassword;
286
- if (shvUser !== undefined && shvPassword !== undefined) {
287
- displayName.value = shvUser;
288
- displayShortName.value = shvUser[0];
289
- displayFullName.value = shvUser;
290
- doConnect(shvUser, shvPassword, 'PLAIN')
291
- .catch((error) => {
292
- console.error('Unexpected failure in doConnect:', error);
293
- });
294
- return;
295
- }
296
- azureAvailable().then(isAzureAvailable => {
297
- switch (isAzureAvailable) {
298
- case LoginFailureReason.NoCredentials:
299
- case LoginFailureReason.AzureTimedOut:
300
- shvLogout();
301
- loginFailure.value = {
302
- reason: isAzureAvailable,
303
- };
304
- return;
305
- case 'azureAvailable':
306
- break;
307
- }
308
- const accessToken = shvLocalStorage.value.azureAccessToken;
309
- if (accessToken !== undefined) {
310
- doConnect('', accessToken, 'TOKEN')
311
- .catch((error) => {
312
- console.error('Unexpected failure in doConnect:', error);
313
- });
314
- }
315
- }).catch((error) => {
316
- console.error('Failed to fetch verify azure info, redirecting to the login page in 3 seconds', error);
317
- setTimeout(() => {
318
- loginFailure.value = {
319
- reason: LoginFailureReason.CouldntLogin,
320
- message: 'Failed to fetch verify azure info',
321
- };
322
- }, 3000);
323
- });
324
- });
325
- };
326
- function makeGlobalResource(options) {
327
- const resource = (0, vue_1.ref)();
328
- const resourceCall = makeRpcCall(options.shvPath, options.method, options.validator);
329
- const refreshValue = async () => {
330
- const newResource = await resourceCall();
331
- if (newResource instanceof Error) {
332
- return;
333
- }
334
- resource.value = newResource;
335
- };
336
- const initialize = async () => {
337
- const shvPath = await (0, utils_1.resolveString)(options.shvPath);
338
- const resIdentifier = `${shvPath}:${options.method}`;
339
- try {
340
- await refreshValue();
341
- const connection = await getConnection();
342
- await connection.subscribe(`Global-${resIdentifier}:`, shvPath, options.signalName, (_path, _method, param) => {
343
- options.signalHandler(param, resource, async () => refreshValue().catch((error) => {
344
- console.error(`Failed to initialize ${resIdentifier}`, error);
345
- }));
346
- });
347
- }
348
- catch (error) {
349
- console.error(`Failed to initialize ${resIdentifier}`, error);
350
- }
351
- };
352
- let initialized = false;
353
- return () => {
354
- if (!initialized) {
355
- initialized = true;
356
- (0, vue_1.watchEffect)(async () => {
357
- (0, vue_1.onWatcherCleanup)(() => {
358
- initialized = false;
359
- resource.value = undefined;
360
- });
361
- if (connected.value !== 'connected') {
362
- return;
363
- }
364
- const shvPath = await (0, utils_1.resolveString)(options.shvPath);
365
- const resIdentifier = `${shvPath}:${options.method}`;
366
- initialize().catch((error) => {
367
- console.error(`Failed to initialize ${resIdentifier}`, error);
368
- });
369
- });
370
- }
371
- if ('default' in options) {
372
- const defaultValue = options.default;
373
- const withDefault = (0, vue_1.computed)(() => {
374
- if (resource.value === undefined) {
375
- return defaultValue;
376
- }
377
- return resource.value;
378
- });
379
- return withDefault;
380
- }
381
- return resource;
382
- };
383
- }
384
- const azureHandlerError = (0, vue_1.ref)('');
385
- const handleAzureCode = async () => {
386
- if (shvSessionStorage.value.azureWorkflow === undefined) {
387
- azureHandlerError.value = 'Azure error: no active login procedure';
388
- return;
389
- }
390
- if (options.azureCodeRedirect === undefined) {
391
- throw new Error('Azure redirect URL not set');
392
- }
393
- const { azureCodeRedirect } = options;
394
- return makePkce({ ...shvSessionStorage.value.azureWorkflow, azureCodeRedirect }).exchangeForAccessToken(globalThis.location.href).then(resp => {
395
- shvSessionStorage.value.azureWorkflow = undefined;
396
- const token = resp.access_token;
397
- if (token === undefined) {
398
- azureHandlerError.value = 'Couldn\'t authenticate to Azure: unable to exchange access token';
399
- return;
400
- }
401
- // Store the token and remove the code from the query params.
402
- shvLogout();
403
- shvLocalStorage.value.azureAccessToken = token;
404
- const redirectTo = shvLocalStorage.value.azureRedirectTo;
405
- if (redirectTo === undefined) {
406
- azureHandlerError.value = 'Couldn\'t authenticate to Azure: no redirect URL';
407
- return;
408
- }
409
- shvLocalStorage.value.azureRedirectTo = undefined;
410
- return redirectTo;
411
- }).catch((error) => {
412
- azureHandlerError.value = `Couldn't authenticate to Azure: ${JSON.stringify(error)}`;
413
- });
414
- };
415
- return {
416
- azureAuth,
417
- azureHandlerError,
418
- connected,
419
- displayEmail,
420
- displayFullName,
421
- displayName,
422
- displayPhoto,
423
- displayShortName,
424
- getConnection,
425
- handleAzureCode,
426
- logContents,
427
- loginFailure,
428
- makeGlobalResource,
429
- makeRpcCall,
430
- makeRpcCallParam,
431
- rpcCall,
432
- setShvCredentials,
433
- shvLocalStorage,
434
- shvLogout,
435
- shvSessionStorage,
436
- };
437
- }
438
- const fullReloadHandler = (_param, _resource, reinit) => {
439
- reinit();
440
- };
441
- exports.fullReloadHandler = fullReloadHandler;
@@ -1,11 +0,0 @@
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 };
@@ -1,82 +0,0 @@
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 DELETED
@@ -1,31 +0,0 @@
1
- import { z, type ZodType } from 'zod/v4';
2
- import { Decimal, Double, type MetaMap, RpcValue, type RpcValueType, RpcValueWithMetaData, shvMapType, UInt } from './rpcvalue';
3
- export declare const map: <T extends Record<string, ZodType<any>>>(schema: T) => z.ZodCustom<z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}> & {
4
- [shvMapType]: "map";
5
- }, z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}> & {
6
- [shvMapType]: "map";
7
- }>;
8
- export declare const imap: <T extends Record<number, ZodType<any>>>(schema: T) => z.ZodCustom<z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}> & {
9
- [shvMapType]: "imap";
10
- }, z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}> & {
11
- [shvMapType]: "imap";
12
- }>;
13
- export declare const metamap: <T extends Record<string | number, ZodType<any>>>(schema: T) => z.ZodCustom<z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}> & {
14
- [shvMapType]: "metamap";
15
- }, z.core.$InferObjectOutput<{ -readonly [P in keyof T]: T[P]; }, {}> & {
16
- [shvMapType]: "metamap";
17
- }>;
18
- export declare const recmap: <T extends ZodType<any>>(schema: T) => z.ZodCustom<Record<any, z.core.output<T>> & {
19
- [shvMapType]: "map";
20
- }, Record<any, z.core.output<T>> & {
21
- [shvMapType]: "map";
22
- }>;
23
- export declare const uint: () => z.ZodCustom<UInt<number>, UInt<number>>;
24
- export declare const double: () => z.ZodCustom<Double, Double>;
25
- export declare const decimal: () => z.ZodCustom<Decimal, Decimal>;
26
- export declare const blob: () => z.ZodCustom<ArrayBuffer, ArrayBuffer>;
27
- export declare const list: () => z.ZodArray<z.ZodLazy<z.ZodType<RpcValue>>>;
28
- export declare const rpcvalue: () => ZodType<RpcValue>;
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
- export * from 'zod/v4';
31
- export { z } from 'zod/v4';
package/dist/zod.js DELETED
@@ -1,114 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
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
- /* eslint-disable @typescript-eslint/no-explicit-any */
19
- const v4_1 = require("zod/v4");
20
- const rpcvalue_1 = require("./rpcvalue");
21
- const implMakeMapParser = (mapValidator, _mapBrand, mapName, objectParser) => v4_1.z.custom().check(ctx => {
22
- if (!mapValidator(ctx.value)) {
23
- ctx.issues.push({
24
- expected: 'map',
25
- code: 'invalid_type',
26
- input: ctx.value,
27
- message: `Invalid input: expected ${mapName}, received ${(0, rpcvalue_1.typeName)(ctx.value)}`,
28
- });
29
- return;
30
- }
31
- // For record, Zod finds out map brand, and calls the record's value parser with the value. There's no way to detect
32
- // it, because Zod does not supply the parser with the key. To prevent this, remove the key before passing the value
33
- // to Zod. This unfortunately means that we need to copy the whole object. :/
34
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
35
- const { [rpcvalue_1.shvMapType]: zodMustNotHaveThis, ...rest } = { ...ctx.value };
36
- const parsedObject = objectParser.safeParse(rest);
37
- if (!parsedObject.success) {
38
- ctx.issues = parsedObject.error.issues;
39
- }
40
- });
41
- const map = (schema) => implMakeMapParser(rpcvalue_1.isShvMap, 'map', 'ShvMap', v4_1.z.object(schema));
42
- exports.map = map;
43
- const imap = (schema) => implMakeMapParser(rpcvalue_1.isIMap, 'imap', 'IMap', v4_1.z.object(schema));
44
- exports.imap = imap;
45
- const metamap = (schema) => implMakeMapParser(rpcvalue_1.isMetaMap, 'metamap', 'MetaMap', v4_1.z.object(schema));
46
- exports.metamap = metamap;
47
- const recmap = (schema) => implMakeMapParser(val => (0, rpcvalue_1.isShvMap)(val) || (0, rpcvalue_1.isIMap)(val), 'map', 'ShvMap', v4_1.z.record(v4_1.z.any(), schema));
48
- exports.recmap = recmap;
49
- const uint = () => v4_1.z.instanceof((rpcvalue_1.UInt));
50
- exports.uint = uint;
51
- const double = () => v4_1.z.instanceof(rpcvalue_1.Double);
52
- exports.double = double;
53
- const decimal = () => v4_1.z.instanceof(rpcvalue_1.Decimal);
54
- exports.decimal = decimal;
55
- const blob = () => v4_1.z.instanceof(ArrayBuffer);
56
- exports.blob = blob;
57
- const list = () => v4_1.z.array(v4_1.z.lazy(exports.rpcvalue));
58
- exports.list = list;
59
- const withMetaInstanceParser = v4_1.z.instanceof(rpcvalue_1.RpcValueWithMetaData);
60
- const rpcvalue = () => v4_1.z.lazy(() => v4_1.z.union([
61
- v4_1.z.undefined(),
62
- v4_1.z.boolean(),
63
- v4_1.z.number(),
64
- (0, exports.uint)(),
65
- (0, exports.double)(),
66
- (0, exports.decimal)(),
67
- (0, exports.blob)(),
68
- v4_1.z.string(),
69
- v4_1.z.date(),
70
- (0, exports.list)(),
71
- (0, exports.recmap)((0, exports.rpcvalue)()),
72
- withMetaInstanceParser,
73
- ]));
74
- exports.rpcvalue = rpcvalue;
75
- const withMeta = (metaParser, valueParser) => v4_1.z.custom().check(ctx => {
76
- if (!withMetaInstanceParser.safeParse(ctx.value).success) {
77
- ctx.issues.push({
78
- expected: 'map',
79
- code: 'invalid_type',
80
- input: ctx.value,
81
- message: 'Invalid input: expected a value with metadata, got a value with no metadata}',
82
- });
83
- return;
84
- }
85
- const parsedMeta = metaParser.safeParse(ctx.value.meta);
86
- if (!parsedMeta.success) {
87
- ctx.issues = [
88
- {
89
- expected: 'map',
90
- code: 'invalid_type',
91
- input: ctx.value,
92
- message: 'Wrong RpcValueWithMetaData meta',
93
- },
94
- ...parsedMeta.error.issues,
95
- ];
96
- return;
97
- }
98
- const parsedValue = valueParser.safeParse(ctx.value.value);
99
- if (!parsedValue.success) {
100
- ctx.issues = [
101
- {
102
- expected: 'map',
103
- code: 'invalid_type',
104
- input: ctx.value,
105
- message: 'Wrong RpcValueWithMetaData value',
106
- },
107
- ...parsedValue.error.issues,
108
- ];
109
- }
110
- });
111
- exports.withMeta = withMeta;
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; } });