libshv-js 3.25.0 → 5.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 +0 -2
- package/dist/index.js +0 -2
- package/dist/rpcmessage.d.ts +44 -258
- package/dist/rpcmessage.js +9 -78
- package/dist/ws-client.js +1 -1
- package/package.json +4 -9
- package/dist/zod-ws-client.d.ts +0 -11
- package/dist/zod-ws-client.js +0 -82
- package/dist/zod.d.ts +0 -31
- package/dist/zod.js +0 -114
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -22,5 +22,3 @@ __exportStar(require("./json"), exports);
|
|
|
22
22
|
__exportStar(require("./rpcmessage"), exports);
|
|
23
23
|
__exportStar(require("./rpcvalue"), exports);
|
|
24
24
|
__exportStar(require("./ws-client"), exports);
|
|
25
|
-
__exportStar(require("./zod"), exports);
|
|
26
|
-
__exportStar(require("./zod-ws-client"), exports);
|
package/dist/rpcmessage.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
[
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
[
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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 {};
|
package/dist/rpcmessage.js
CHANGED
|
@@ -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.
|
|
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
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
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/dist/ws-client.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libshv-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.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
|
|
12
|
-
"test:ci": "tsc -p tsconfig.tests.json && node dist-tests/tests/test.js && node dist-tests/tests/test_json.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,12 +34,7 @@
|
|
|
34
34
|
"./rpcmessage": "./dist/rpcmessage.js",
|
|
35
35
|
"./rpcvalue": "./dist/rpcvalue.js",
|
|
36
36
|
"./utils": "./dist/utils.js",
|
|
37
|
-
"./ws-client": "./dist/ws-client.js"
|
|
38
|
-
"./zod": "./dist/zod.js",
|
|
39
|
-
"./zod-ws-client": "./dist/zod-ws-client.js"
|
|
40
|
-
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"zod": "^4.0.11"
|
|
37
|
+
"./ws-client": "./dist/ws-client.js"
|
|
43
38
|
},
|
|
44
39
|
"devDependencies": {
|
|
45
40
|
"@typescript-eslint/parser": "^8.38.0",
|
package/dist/zod-ws-client.d.ts
DELETED
|
@@ -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 };
|
package/dist/zod-ws-client.js
DELETED
|
@@ -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; } });
|