libshv-js 3.17.0 → 3.21.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/access.d.ts +69 -0
- package/dist/access.js +98 -0
- package/dist/chainpack.d.ts +39 -0
- package/dist/chainpack.js +562 -0
- package/dist/cpcontext.d.ts +18 -0
- package/dist/cpcontext.js +78 -0
- package/dist/cpon.d.ts +55 -0
- package/dist/cpon.js +900 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +26 -0
- package/dist/json.d.ts +3 -0
- package/dist/json.js +118 -0
- package/dist/rpcmessage.d.ts +285 -0
- package/dist/rpcmessage.js +111 -0
- package/dist/rpcvalue.d.ts +56 -0
- package/dist/rpcvalue.js +100 -0
- package/dist/vue-shv.d.ts +92 -0
- package/dist/vue-shv.js +425 -0
- package/dist/ws-client.d.ts +232 -0
- package/dist/ws-client.js +586 -0
- package/dist/zod.d.ts +30 -0
- package/dist/zod.js +112 -0
- package/package.json +1 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './access';
|
|
2
|
+
export * from './chainpack';
|
|
3
|
+
export * from './cpcontext';
|
|
4
|
+
export * from './cpon';
|
|
5
|
+
export * from './json';
|
|
6
|
+
export * from './rpcmessage';
|
|
7
|
+
export * from './rpcvalue';
|
|
8
|
+
export * from './vue-shv';
|
|
9
|
+
export * from './ws-client';
|
|
10
|
+
export * from './zod';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
__exportStar(require("./access"), exports);
|
|
18
|
+
__exportStar(require("./chainpack"), exports);
|
|
19
|
+
__exportStar(require("./cpcontext"), exports);
|
|
20
|
+
__exportStar(require("./cpon"), exports);
|
|
21
|
+
__exportStar(require("./json"), exports);
|
|
22
|
+
__exportStar(require("./rpcmessage"), exports);
|
|
23
|
+
__exportStar(require("./rpcvalue"), exports);
|
|
24
|
+
__exportStar(require("./vue-shv"), exports);
|
|
25
|
+
__exportStar(require("./ws-client"), exports);
|
|
26
|
+
__exportStar(require("./zod"), exports);
|
package/dist/json.d.ts
ADDED
package/dist/json.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toJson = exports.fromJson = void 0;
|
|
4
|
+
const cpcontext_1 = require("./cpcontext");
|
|
5
|
+
const cpon_1 = require("./cpon");
|
|
6
|
+
const rpcvalue_1 = require("./rpcvalue");
|
|
7
|
+
const decodeMap = (x) => (0, rpcvalue_1.makeMap)(Object.fromEntries(Object.entries(x).map(([key, value]) => [key, decodeValueJson(value)])));
|
|
8
|
+
const decodeValueJson = (x) => {
|
|
9
|
+
switch (true) {
|
|
10
|
+
case Array.isArray(x): {
|
|
11
|
+
const list = x;
|
|
12
|
+
const handleType = (typeName, typeValue) => {
|
|
13
|
+
switch (true) {
|
|
14
|
+
case typeName === 'Blob': {
|
|
15
|
+
if (typeof typeValue !== 'string' || typeValue.length % 2 !== 0) {
|
|
16
|
+
throw new TypeError(`Invalid JSON-encoded Blob: '${JSON.stringify(typeValue)}'`);
|
|
17
|
+
}
|
|
18
|
+
const buffer = new ArrayBuffer(typeValue.length / 2);
|
|
19
|
+
const array = new Uint8Array(buffer);
|
|
20
|
+
// I can assume even length because of the previous check.
|
|
21
|
+
for (let i = 0; i < typeValue.length / 2; i++) {
|
|
22
|
+
array[i] = Number.parseInt(typeValue.slice(i * 2, (i * 2) + 2), 16);
|
|
23
|
+
}
|
|
24
|
+
return buffer;
|
|
25
|
+
}
|
|
26
|
+
case typeName === 'IMap':
|
|
27
|
+
if (typeof typeValue !== 'object' || typeValue === null) {
|
|
28
|
+
throw new TypeError(`Invalid JSON-encoded IMap: '${JSON.stringify(typeValue)}'`);
|
|
29
|
+
}
|
|
30
|
+
if (Object.keys(typeValue).some(key => !/^-?\d+$/.test(key))) {
|
|
31
|
+
throw new TypeError(`Invalid JSON-encoded IMap (non-Int key): '${JSON.stringify(typeValue)}'`);
|
|
32
|
+
}
|
|
33
|
+
return (0, rpcvalue_1.makeIMap)(decodeMap(typeValue));
|
|
34
|
+
case typeName === 'DateTime':
|
|
35
|
+
if (typeof typeValue !== 'string') {
|
|
36
|
+
throw new TypeError(`Invalid JSON-encoded DateTime: '${JSON.stringify(typeValue)}'`);
|
|
37
|
+
}
|
|
38
|
+
// Kinda lame that I'm encoding the datetime string, but this is the easiest way right now.
|
|
39
|
+
return new cpon_1.CponReader(new cpcontext_1.UnpackContext(new TextEncoder().encode(typeValue).buffer)).readDateTimeInner();
|
|
40
|
+
default:
|
|
41
|
+
throw new TypeError(`Invalid JSON-encoded type name: '${JSON.stringify(typeName)}'`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
switch (true) {
|
|
45
|
+
case list.length === 3 && list[0] === JSON_TAG_TYPE:
|
|
46
|
+
return handleType(list[1], list[2]);
|
|
47
|
+
case list.length === 3 && list[0] === JSON_TAG_META:
|
|
48
|
+
case list.length === 5 && list[0] === JSON_TAG_META && list[2] === JSON_TAG_TYPE: {
|
|
49
|
+
if (typeof list[1] !== 'object' || list[1] === null) {
|
|
50
|
+
throw new TypeError(`Invalid JSON-encoded MetaData: '${JSON.stringify(list[1])}'`);
|
|
51
|
+
}
|
|
52
|
+
const value = (() => {
|
|
53
|
+
if (list.length === 3) {
|
|
54
|
+
const decoded = decodeValueJson(list[2]);
|
|
55
|
+
if (decoded instanceof rpcvalue_1.RpcValueWithMetaData) {
|
|
56
|
+
throw new TypeError('Logic error: got RpcValueWithMetaData as the value in JSON-encoded RpcValueWithMetaData, please report this bug to the maintainer.');
|
|
57
|
+
}
|
|
58
|
+
return decoded;
|
|
59
|
+
}
|
|
60
|
+
return handleType(list[3], list[4]);
|
|
61
|
+
})();
|
|
62
|
+
return new rpcvalue_1.RpcValueWithMetaData((0, rpcvalue_1.makeMetaMap)(decodeMap(list[1])), value);
|
|
63
|
+
}
|
|
64
|
+
default:
|
|
65
|
+
return list.map(value => decodeValueJson(value));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
case x === null:
|
|
69
|
+
return undefined;
|
|
70
|
+
case typeof x === 'object':
|
|
71
|
+
return decodeMap(x);
|
|
72
|
+
case typeof x === 'number':
|
|
73
|
+
case typeof x === 'boolean':
|
|
74
|
+
case typeof x === 'string':
|
|
75
|
+
return x;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unknown JSON-encoded value: ${JSON.stringify(x)}`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const fromJson = (str) => decodeValueJson(JSON.parse(str));
|
|
81
|
+
exports.fromJson = fromJson;
|
|
82
|
+
const JSON_TAG_META = '!shvMeta';
|
|
83
|
+
const JSON_TAG_TYPE = '!shvType';
|
|
84
|
+
const encodeValueJson = (x) => {
|
|
85
|
+
switch (true) {
|
|
86
|
+
case x instanceof rpcvalue_1.RpcValueWithMetaData: {
|
|
87
|
+
const res = [JSON_TAG_META, encodeValueJson((0, rpcvalue_1.makeMap)(x.meta))];
|
|
88
|
+
const encoded = encodeValueJson(x.value);
|
|
89
|
+
if (Array.isArray(encoded) && encoded[0] === JSON_TAG_TYPE) {
|
|
90
|
+
return [...res, ...encoded];
|
|
91
|
+
}
|
|
92
|
+
return [...res, encoded];
|
|
93
|
+
}
|
|
94
|
+
case Array.isArray(x):
|
|
95
|
+
return x.map(value => encodeValueJson(value));
|
|
96
|
+
case (0, rpcvalue_1.isShvMap)(x): {
|
|
97
|
+
const map = x;
|
|
98
|
+
return Object.fromEntries(Object.entries(map).map(([key, value]) => [key, encodeValueJson(value)]));
|
|
99
|
+
}
|
|
100
|
+
case (0, rpcvalue_1.isIMap)(x):
|
|
101
|
+
return [JSON_TAG_TYPE, 'IMap', encodeValueJson((0, rpcvalue_1.makeMap)(x))];
|
|
102
|
+
case x instanceof ArrayBuffer:
|
|
103
|
+
return [JSON_TAG_TYPE, 'Blob', new Uint8Array(x).reduce((acc, v) => acc + v.toString(16).padStart(2, '0'), '')];
|
|
104
|
+
case x instanceof Date:
|
|
105
|
+
return [JSON_TAG_TYPE, 'DateTime', (0, cpon_1.stringifyDate)(x)];
|
|
106
|
+
case x === undefined:
|
|
107
|
+
// eslint-disable-next-line unicorn/no-null
|
|
108
|
+
return null;
|
|
109
|
+
case x instanceof rpcvalue_1.Decimal:
|
|
110
|
+
case x instanceof rpcvalue_1.UInt:
|
|
111
|
+
case x instanceof rpcvalue_1.Double:
|
|
112
|
+
throw new TypeError('Decimal/Double/UInt not supported in JSON');
|
|
113
|
+
default:
|
|
114
|
+
return x;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const toJson = (value) => JSON.stringify(encodeValueJson(value));
|
|
118
|
+
exports.toJson = toJson;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import * as z from './zod';
|
|
2
|
+
import { type shvMapType } from './rpcvalue';
|
|
3
|
+
export declare const RPC_MESSAGE_REQUEST_ID = 8;
|
|
4
|
+
export declare const RPC_MESSAGE_SHV_PATH = 9;
|
|
5
|
+
export declare const RPC_MESSAGE_METHOD = 10;
|
|
6
|
+
export declare const RPC_MESSAGE_CALLER_IDS = 11;
|
|
7
|
+
export declare const RPC_MESSAGE_ACCESS_LEVEL = 17;
|
|
8
|
+
export declare const RPC_MESSAGE_PARAMS = 1;
|
|
9
|
+
export declare const RPC_MESSAGE_RESULT = 2;
|
|
10
|
+
export declare const RPC_MESSAGE_ERROR = 3;
|
|
11
|
+
export declare const RPC_MESSAGE_DELAY = 4;
|
|
12
|
+
export declare const RPC_MESSAGE_ABORT = 5;
|
|
13
|
+
export declare const ERROR_CODE = 1;
|
|
14
|
+
export declare const ERROR_MESSAGE = 2;
|
|
15
|
+
export declare const ERROR_DATA = 3;
|
|
16
|
+
declare enum ErrorCode {
|
|
17
|
+
InvalidRequest = 1,
|
|
18
|
+
MethodNotFound = 2,
|
|
19
|
+
InvalidParams = 3,
|
|
20
|
+
InternalError = 4,
|
|
21
|
+
ParseError = 5,
|
|
22
|
+
MethodCallTimeout = 6,
|
|
23
|
+
MethodCallCancelled = 7,
|
|
24
|
+
MethodCallException = 8,
|
|
25
|
+
Unknown = 9,
|
|
26
|
+
LoginRequired = 10,
|
|
27
|
+
UserIDRequired = 11,
|
|
28
|
+
NotImplemented = 12
|
|
29
|
+
}
|
|
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";
|
|
42
|
+
}>;
|
|
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 };
|
|
@@ -0,0 +1,111 @@
|
|
|
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.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"));
|
|
38
|
+
exports.RPC_MESSAGE_REQUEST_ID = 8;
|
|
39
|
+
exports.RPC_MESSAGE_SHV_PATH = 9;
|
|
40
|
+
exports.RPC_MESSAGE_METHOD = 10;
|
|
41
|
+
exports.RPC_MESSAGE_CALLER_IDS = 11;
|
|
42
|
+
exports.RPC_MESSAGE_ACCESS_LEVEL = 17;
|
|
43
|
+
exports.RPC_MESSAGE_PARAMS = 1;
|
|
44
|
+
exports.RPC_MESSAGE_RESULT = 2;
|
|
45
|
+
exports.RPC_MESSAGE_ERROR = 3;
|
|
46
|
+
exports.RPC_MESSAGE_DELAY = 4;
|
|
47
|
+
exports.RPC_MESSAGE_ABORT = 5;
|
|
48
|
+
exports.ERROR_CODE = 1;
|
|
49
|
+
exports.ERROR_MESSAGE = 2;
|
|
50
|
+
exports.ERROR_DATA = 3;
|
|
51
|
+
var ErrorCode;
|
|
52
|
+
(function (ErrorCode) {
|
|
53
|
+
ErrorCode[ErrorCode["InvalidRequest"] = 1] = "InvalidRequest";
|
|
54
|
+
ErrorCode[ErrorCode["MethodNotFound"] = 2] = "MethodNotFound";
|
|
55
|
+
ErrorCode[ErrorCode["InvalidParams"] = 3] = "InvalidParams";
|
|
56
|
+
ErrorCode[ErrorCode["InternalError"] = 4] = "InternalError";
|
|
57
|
+
ErrorCode[ErrorCode["ParseError"] = 5] = "ParseError";
|
|
58
|
+
ErrorCode[ErrorCode["MethodCallTimeout"] = 6] = "MethodCallTimeout";
|
|
59
|
+
ErrorCode[ErrorCode["MethodCallCancelled"] = 7] = "MethodCallCancelled";
|
|
60
|
+
ErrorCode[ErrorCode["MethodCallException"] = 8] = "MethodCallException";
|
|
61
|
+
ErrorCode[ErrorCode["Unknown"] = 9] = "Unknown";
|
|
62
|
+
ErrorCode[ErrorCode["LoginRequired"] = 10] = "LoginRequired";
|
|
63
|
+
ErrorCode[ErrorCode["UserIDRequired"] = 11] = "UserIDRequired";
|
|
64
|
+
ErrorCode[ErrorCode["NotImplemented"] = 12] = "NotImplemented";
|
|
65
|
+
})(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;
|
|
107
|
+
exports.isSignal = isSignal;
|
|
108
|
+
const isRequest = (message) => exports.RPC_MESSAGE_REQUEST_ID in message.meta && exports.RPC_MESSAGE_METHOD in message.meta;
|
|
109
|
+
exports.isRequest = isRequest;
|
|
110
|
+
const isResponse = (message) => exports.RPC_MESSAGE_REQUEST_ID in message.meta && !(exports.RPC_MESSAGE_METHOD in message.meta);
|
|
111
|
+
exports.isResponse = isResponse;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
declare class UInt<T extends number = number> {
|
|
2
|
+
readonly value: T;
|
|
3
|
+
constructor(u: T | UInt<T>);
|
|
4
|
+
[Symbol.toPrimitive](): T;
|
|
5
|
+
toString(): string;
|
|
6
|
+
}
|
|
7
|
+
declare class Double {
|
|
8
|
+
readonly value: number;
|
|
9
|
+
constructor(u: number);
|
|
10
|
+
}
|
|
11
|
+
declare class Decimal {
|
|
12
|
+
mantisa: number;
|
|
13
|
+
exponent: number;
|
|
14
|
+
constructor(mantisa: number, exponent: number);
|
|
15
|
+
}
|
|
16
|
+
export type Null = undefined;
|
|
17
|
+
export type Bool = boolean;
|
|
18
|
+
export type Blob = ArrayBuffer;
|
|
19
|
+
export type ShvString = string;
|
|
20
|
+
export type DateTime = Date & {
|
|
21
|
+
utc_offset?: number;
|
|
22
|
+
};
|
|
23
|
+
declare const withOffset: (date: Date, utcOffset?: number) => DateTime;
|
|
24
|
+
export type List = RpcValue[];
|
|
25
|
+
declare const shvMapType: unique symbol;
|
|
26
|
+
type IMap<T extends Record<number, RpcValue> = Record<number, any>> = {
|
|
27
|
+
[Key in keyof T]: T[Key];
|
|
28
|
+
} & {
|
|
29
|
+
[shvMapType]: 'imap';
|
|
30
|
+
};
|
|
31
|
+
type ShvMap<T extends Record<string, RpcValue> = Record<string, any>> = {
|
|
32
|
+
[Key in keyof T]: T[Key];
|
|
33
|
+
} & {
|
|
34
|
+
[shvMapType]: 'map';
|
|
35
|
+
};
|
|
36
|
+
export type Int = number;
|
|
37
|
+
export type RpcValueType = Null | Bool | Int | UInt | Double | Decimal | Blob | ShvString | DateTime | List | ShvMap | IMap;
|
|
38
|
+
type MetaMap<T extends Record<string | number, RpcValue> = Record<string | number, RpcValue>> = {
|
|
39
|
+
[Key in keyof T]: T[Key];
|
|
40
|
+
} & {
|
|
41
|
+
[shvMapType]: 'metamap';
|
|
42
|
+
};
|
|
43
|
+
declare const isShvMap: (x: unknown) => x is ShvMap;
|
|
44
|
+
declare const isIMap: (x: unknown) => x is IMap;
|
|
45
|
+
declare const isMetaMap: (x: unknown) => x is IMap;
|
|
46
|
+
export declare const typeName: (x: unknown) => string;
|
|
47
|
+
declare const makeMetaMap: <T extends Record<string | number, RpcValue> = Record<string | number, RpcValue>, U extends Record<number, RpcValue> = Omit<T, typeof shvMapType>>(x?: U) => MetaMap<U>;
|
|
48
|
+
declare const makeIMap: <T extends Record<number, RpcValue> = Record<number, RpcValue>, U extends Record<number, RpcValue> = Omit<T, typeof shvMapType>>(x?: U) => IMap<U>;
|
|
49
|
+
declare const makeMap: <T extends Record<string, RpcValue> = Record<string, RpcValue>, U extends Record<string, RpcValue> = Omit<T, typeof shvMapType>>(x?: U) => ShvMap<U>;
|
|
50
|
+
declare class RpcValueWithMetaData<MetaSchema extends MetaMap = MetaMap, ValueSchema extends RpcValueType = RpcValueType> {
|
|
51
|
+
meta: MetaSchema;
|
|
52
|
+
value: ValueSchema;
|
|
53
|
+
constructor(meta: MetaSchema, value: ValueSchema);
|
|
54
|
+
}
|
|
55
|
+
export type RpcValue = RpcValueType | RpcValueWithMetaData;
|
|
56
|
+
export { shvMapType, Decimal, Double, type IMap, type MetaMap, RpcValueWithMetaData, type ShvMap, UInt, withOffset, makeMap, makeIMap, makeMetaMap, isIMap, isMetaMap, isShvMap };
|