libshv-js 7.2.0 → 8.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/access.js +1 -5
- package/dist/chainpack.d.ts +3 -3
- package/dist/chainpack.js +28 -35
- package/dist/cpcontext.js +1 -5
- package/dist/cpon.d.ts +2 -2
- package/dist/cpon.js +31 -40
- package/dist/index.d.ts +9 -9
- package/dist/index.js +9 -25
- package/dist/json.d.ts +1 -1
- package/dist/json.js +19 -24
- package/dist/rpcmessage.d.ts +1 -1
- package/dist/rpcmessage.js +19 -25
- package/dist/rpcvalue.js +2 -17
- package/dist/shv-ri.js +1 -5
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -7
- package/dist/ws-client.d.ts +3 -3
- package/dist/ws-client.js +153 -159
- package/package.json +2 -1
package/dist/json.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const cpcontext_1 = require("./cpcontext");
|
|
5
|
-
const cpon_1 = require("./cpon");
|
|
6
|
-
const rpcvalue_1 = require("./rpcvalue");
|
|
1
|
+
import { UnpackContext } from './cpcontext.js';
|
|
2
|
+
import { CponReader, stringifyDate } from './cpon.js';
|
|
3
|
+
import { Decimal, Double, isIMap, isShvMap, makeIMap, makeMap, makeMetaMap, RpcValueWithMetaData, UInt } from './rpcvalue.js';
|
|
7
4
|
// eslint-disable-next-line @typescript-eslint/no-restricted-types
|
|
8
|
-
const decodeMap = (x) =>
|
|
5
|
+
const decodeMap = (x) => makeMap(Object.fromEntries(Object.entries(x).map(([key, value]) => [key, decodeValueJson(value)])));
|
|
9
6
|
const decodeValueJson = (x) => {
|
|
10
7
|
switch (true) {
|
|
11
8
|
case Array.isArray(x): {
|
|
@@ -31,13 +28,13 @@ const decodeValueJson = (x) => {
|
|
|
31
28
|
if (Object.keys(typeValue).some(key => !/^-?\d+$/v.test(key))) {
|
|
32
29
|
throw new TypeError(`Invalid JSON-encoded IMap (non-Int key): '${JSON.stringify(typeValue)}'`);
|
|
33
30
|
}
|
|
34
|
-
return
|
|
31
|
+
return makeIMap(decodeMap(typeValue));
|
|
35
32
|
case typeName === 'DateTime':
|
|
36
33
|
if (typeof typeValue !== 'string') {
|
|
37
34
|
throw new TypeError(`Invalid JSON-encoded DateTime: '${JSON.stringify(typeValue)}'`);
|
|
38
35
|
}
|
|
39
36
|
// Kinda lame that I'm encoding the datetime string, but this is the easiest way right now.
|
|
40
|
-
return new
|
|
37
|
+
return new CponReader(new UnpackContext(new TextEncoder().encode(typeValue).buffer)).readDateTimeInner();
|
|
41
38
|
default:
|
|
42
39
|
throw new TypeError(`Invalid JSON-encoded type name: '${JSON.stringify(typeName)}'`);
|
|
43
40
|
}
|
|
@@ -53,14 +50,14 @@ const decodeValueJson = (x) => {
|
|
|
53
50
|
const value = (() => {
|
|
54
51
|
if (list.length === 3) {
|
|
55
52
|
const decoded = decodeValueJson(list[2]);
|
|
56
|
-
if (decoded instanceof
|
|
53
|
+
if (decoded instanceof RpcValueWithMetaData) {
|
|
57
54
|
throw new TypeError('Logic error: got RpcValueWithMetaData as the value in JSON-encoded RpcValueWithMetaData, please report this bug to the maintainer.');
|
|
58
55
|
}
|
|
59
56
|
return decoded;
|
|
60
57
|
}
|
|
61
58
|
return handleType(list[3], list[4]);
|
|
62
59
|
})();
|
|
63
|
-
return new
|
|
60
|
+
return new RpcValueWithMetaData(makeMetaMap(decodeMap(list[1])), value);
|
|
64
61
|
}
|
|
65
62
|
default:
|
|
66
63
|
return list.map(value => decodeValueJson(value));
|
|
@@ -78,14 +75,13 @@ const decodeValueJson = (x) => {
|
|
|
78
75
|
throw new Error(`Unknown JSON-encoded value: ${JSON.stringify(x)}`);
|
|
79
76
|
}
|
|
80
77
|
};
|
|
81
|
-
const fromJson = (str) => decodeValueJson(JSON.parse(str));
|
|
82
|
-
exports.fromJson = fromJson;
|
|
78
|
+
export const fromJson = (str) => decodeValueJson(JSON.parse(str));
|
|
83
79
|
const JSON_TAG_META = '!shvMeta';
|
|
84
80
|
const JSON_TAG_TYPE = '!shvType';
|
|
85
81
|
const encodeValueJson = (x) => {
|
|
86
82
|
switch (true) {
|
|
87
|
-
case x instanceof
|
|
88
|
-
const res = [JSON_TAG_META, encodeValueJson(
|
|
83
|
+
case x instanceof RpcValueWithMetaData: {
|
|
84
|
+
const res = [JSON_TAG_META, encodeValueJson(makeMap(x.meta))];
|
|
89
85
|
const encoded = encodeValueJson(x.value);
|
|
90
86
|
if (Array.isArray(encoded) && encoded[0] === JSON_TAG_TYPE) {
|
|
91
87
|
return [...res, ...encoded];
|
|
@@ -94,25 +90,24 @@ const encodeValueJson = (x) => {
|
|
|
94
90
|
}
|
|
95
91
|
case Array.isArray(x):
|
|
96
92
|
return x.map(value => encodeValueJson(value));
|
|
97
|
-
case
|
|
93
|
+
case isShvMap(x): {
|
|
98
94
|
const map = x;
|
|
99
95
|
return Object.fromEntries(Object.entries(map).map(([key, value]) => [key, encodeValueJson(value)]));
|
|
100
96
|
}
|
|
101
|
-
case
|
|
102
|
-
return [JSON_TAG_TYPE, 'IMap', encodeValueJson(
|
|
97
|
+
case isIMap(x):
|
|
98
|
+
return [JSON_TAG_TYPE, 'IMap', encodeValueJson(makeMap(x))];
|
|
103
99
|
case x instanceof ArrayBuffer:
|
|
104
100
|
return [JSON_TAG_TYPE, 'Blob', new Uint8Array(x).reduce((acc, v) => acc + v.toString(16).padStart(2, '0'), '')];
|
|
105
101
|
case x instanceof Date:
|
|
106
|
-
return [JSON_TAG_TYPE, 'DateTime',
|
|
102
|
+
return [JSON_TAG_TYPE, 'DateTime', stringifyDate(x)];
|
|
107
103
|
case x === undefined:
|
|
108
104
|
return null;
|
|
109
|
-
case x instanceof
|
|
110
|
-
case x instanceof
|
|
111
|
-
case x instanceof
|
|
105
|
+
case x instanceof Decimal:
|
|
106
|
+
case x instanceof UInt:
|
|
107
|
+
case x instanceof Double:
|
|
112
108
|
throw new TypeError('Decimal/Double/UInt not supported in JSON');
|
|
113
109
|
default:
|
|
114
110
|
return x;
|
|
115
111
|
}
|
|
116
112
|
};
|
|
117
|
-
const toJson = (value) => JSON.stringify(encodeValueJson(value));
|
|
118
|
-
exports.toJson = toJson;
|
|
113
|
+
export const toJson = (value) => JSON.stringify(encodeValueJson(value));
|
package/dist/rpcmessage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Double, type IMap, type MetaMap, type RpcValue, type RpcValueWithMetaData } from './rpcvalue';
|
|
1
|
+
import { type Double, type IMap, type MetaMap, type RpcValue, type RpcValueWithMetaData } from './rpcvalue.js';
|
|
2
2
|
export declare const RPC_MESSAGE_REQUEST_ID = 8;
|
|
3
3
|
export declare const RPC_MESSAGE_SHV_PATH = 9;
|
|
4
4
|
export declare const RPC_MESSAGE_METHOD = 10;
|
package/dist/rpcmessage.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.ERROR_MESSAGE = 2;
|
|
17
|
-
exports.ERROR_DATA = 3;
|
|
18
|
-
var ErrorCode;
|
|
1
|
+
export const RPC_MESSAGE_REQUEST_ID = 8;
|
|
2
|
+
export const RPC_MESSAGE_SHV_PATH = 9;
|
|
3
|
+
export const RPC_MESSAGE_METHOD = 10;
|
|
4
|
+
export const RPC_MESSAGE_CALLER_IDS = 11;
|
|
5
|
+
export const RPC_MESSAGE_USER_ID = 16;
|
|
6
|
+
export const RPC_MESSAGE_ACCESS_LEVEL = 17;
|
|
7
|
+
export const RPC_MESSAGE_PARAMS = 1;
|
|
8
|
+
export const RPC_MESSAGE_RESULT = 2;
|
|
9
|
+
export const RPC_MESSAGE_ERROR = 3;
|
|
10
|
+
export const RPC_MESSAGE_DELAY = 4;
|
|
11
|
+
export const RPC_MESSAGE_ABORT = 5;
|
|
12
|
+
export const ERROR_CODE = 1;
|
|
13
|
+
export const ERROR_MESSAGE = 2;
|
|
14
|
+
export const ERROR_DATA = 3;
|
|
15
|
+
export var ErrorCode;
|
|
19
16
|
(function (ErrorCode) {
|
|
20
17
|
ErrorCode[ErrorCode["InvalidRequest"] = 1] = "InvalidRequest";
|
|
21
18
|
ErrorCode[ErrorCode["MethodNotFound"] = 2] = "MethodNotFound";
|
|
@@ -29,15 +26,12 @@ var ErrorCode;
|
|
|
29
26
|
ErrorCode[ErrorCode["LoginRequired"] = 10] = "LoginRequired";
|
|
30
27
|
ErrorCode[ErrorCode["UserIDRequired"] = 11] = "UserIDRequired";
|
|
31
28
|
ErrorCode[ErrorCode["NotImplemented"] = 12] = "NotImplemented";
|
|
32
|
-
})(ErrorCode || (
|
|
29
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
33
30
|
const implRpcMessage = (message) => typeof message === 'object'
|
|
34
31
|
&& message !== null
|
|
35
32
|
&& 'meta' in message
|
|
36
33
|
&& typeof message.meta === 'object'
|
|
37
34
|
&& message.meta !== null;
|
|
38
|
-
const isSignal = (message) => implRpcMessage(message) && !Object.hasOwn(message.meta,
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
exports.isRequest = isRequest;
|
|
42
|
-
const isResponse = (message) => implRpcMessage(message) && Object.hasOwn(message.meta, exports.RPC_MESSAGE_REQUEST_ID) && !Object.hasOwn(message.meta, exports.RPC_MESSAGE_METHOD);
|
|
43
|
-
exports.isResponse = isResponse;
|
|
35
|
+
export const isSignal = (message) => implRpcMessage(message) && !Object.hasOwn(message.meta, RPC_MESSAGE_REQUEST_ID) && Object.hasOwn(message.meta, RPC_MESSAGE_METHOD);
|
|
36
|
+
export const isRequest = (message) => implRpcMessage(message) && Object.hasOwn(message.meta, RPC_MESSAGE_REQUEST_ID) && Object.hasOwn(message.meta, RPC_MESSAGE_METHOD);
|
|
37
|
+
export const isResponse = (message) => implRpcMessage(message) && Object.hasOwn(message.meta, RPC_MESSAGE_REQUEST_ID) && !Object.hasOwn(message.meta, RPC_MESSAGE_METHOD);
|
package/dist/rpcvalue.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isShvMap = exports.isMetaMap = exports.isIMap = exports.makeMetaMap = exports.makeIMap = exports.makeMap = exports.withOffset = exports.UInt = exports.RpcValueWithMetaData = exports.Double = exports.Decimal = exports.shvMapType = exports.typeName = void 0;
|
|
4
1
|
class UInt {
|
|
5
2
|
value;
|
|
6
3
|
constructor(u) {
|
|
@@ -20,14 +17,12 @@ class UInt {
|
|
|
20
17
|
return this.value.toString();
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
|
-
exports.UInt = UInt;
|
|
24
20
|
class Double {
|
|
25
21
|
value;
|
|
26
22
|
constructor(u) {
|
|
27
23
|
this.value = u;
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
|
-
exports.Double = Double;
|
|
31
26
|
class Decimal {
|
|
32
27
|
mantisa;
|
|
33
28
|
exponent;
|
|
@@ -39,22 +34,16 @@ class Decimal {
|
|
|
39
34
|
this.exponent = exponent;
|
|
40
35
|
}
|
|
41
36
|
}
|
|
42
|
-
exports.Decimal = Decimal;
|
|
43
37
|
const withOffset = (date, utcOffset) => {
|
|
44
38
|
const clonedDate = new Date(date);
|
|
45
39
|
clonedDate.utc_offset = utcOffset;
|
|
46
40
|
return clonedDate;
|
|
47
41
|
};
|
|
48
|
-
exports.withOffset = withOffset;
|
|
49
42
|
const shvMapType = Symbol('shvMapType');
|
|
50
|
-
exports.shvMapType = shvMapType;
|
|
51
43
|
const isShvMap = (x) => typeof x === 'object' && x[shvMapType] === 'map';
|
|
52
|
-
exports.isShvMap = isShvMap;
|
|
53
44
|
const isIMap = (x) => typeof x === 'object' && x[shvMapType] === 'imap';
|
|
54
|
-
exports.isIMap = isIMap;
|
|
55
45
|
const isMetaMap = (x) => typeof x === 'object' && x[shvMapType] === 'metamap';
|
|
56
|
-
|
|
57
|
-
const typeName = (x) => {
|
|
46
|
+
export const typeName = (x) => {
|
|
58
47
|
switch (true) {
|
|
59
48
|
case x === undefined: return 'Null';
|
|
60
49
|
case typeof x === 'boolean': return 'Bool';
|
|
@@ -72,22 +61,18 @@ const typeName = (x) => {
|
|
|
72
61
|
default: return '<unknown type>';
|
|
73
62
|
}
|
|
74
63
|
};
|
|
75
|
-
exports.typeName = typeName;
|
|
76
64
|
const makeMetaMap = (x = {}) => ({
|
|
77
65
|
...x,
|
|
78
66
|
[shvMapType]: 'metamap',
|
|
79
67
|
});
|
|
80
|
-
exports.makeMetaMap = makeMetaMap;
|
|
81
68
|
const makeIMap = (x = {}) => ({
|
|
82
69
|
...x,
|
|
83
70
|
[shvMapType]: 'imap',
|
|
84
71
|
});
|
|
85
|
-
exports.makeIMap = makeIMap;
|
|
86
72
|
const makeMap = (x = {}) => ({
|
|
87
73
|
...x,
|
|
88
74
|
[shvMapType]: 'map',
|
|
89
75
|
});
|
|
90
|
-
exports.makeMap = makeMap;
|
|
91
76
|
class RpcValueWithMetaData {
|
|
92
77
|
meta;
|
|
93
78
|
value;
|
|
@@ -97,4 +82,4 @@ class RpcValueWithMetaData {
|
|
|
97
82
|
// nothing
|
|
98
83
|
}
|
|
99
84
|
}
|
|
100
|
-
|
|
85
|
+
export { shvMapType, Decimal, Double, RpcValueWithMetaData, UInt, withOffset, makeMap, makeIMap, makeMetaMap, isIMap, isMetaMap, isShvMap };
|
package/dist/shv-ri.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShvRI = void 0;
|
|
4
|
-
class ShvRI {
|
|
1
|
+
export class ShvRI {
|
|
5
2
|
static fromPathMethodSignal(path, method, signal) {
|
|
6
3
|
const m = method.length === 0 ? '*' : method;
|
|
7
4
|
const ri = signal !== undefined
|
|
@@ -52,4 +49,3 @@ class ShvRI {
|
|
|
52
49
|
return this.ri;
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
|
-
exports.ShvRI = ShvRI;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ShvRI } from './shv-ri';
|
|
1
|
+
import { type ShvRI } from './shv-ri.js';
|
|
2
2
|
export type StringGetter = string | Promise<string> | (() => string | Promise<string>);
|
|
3
3
|
export declare const resolveString: (input: StringGetter) => string | Promise<string>;
|
|
4
4
|
export type RIGetter = ShvRI | Promise<ShvRI> | (() => ShvRI | Promise<ShvRI>);
|
package/dist/utils.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveRI = exports.resolveString = void 0;
|
|
4
|
-
const resolveString = (input) => {
|
|
1
|
+
export const resolveString = (input) => {
|
|
5
2
|
if (typeof input === 'function') {
|
|
6
3
|
input = input();
|
|
7
4
|
}
|
|
8
5
|
return input;
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
const resolveRI = (input) => {
|
|
7
|
+
export const resolveRI = (input) => {
|
|
12
8
|
if (typeof input === 'function') {
|
|
13
9
|
input = input();
|
|
14
10
|
}
|
|
15
11
|
return input;
|
|
16
12
|
};
|
|
17
|
-
exports.resolveRI = resolveRI;
|
package/dist/ws-client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type RpcMessage, type RpcRequest, type ErrorMap } from './rpcmessage';
|
|
2
|
-
import { type RpcValue, type Null, type Int, type IMap, type ShvMap } from './rpcvalue';
|
|
3
|
-
import { type RIGetter } from './utils';
|
|
1
|
+
import { type RpcMessage, type RpcRequest, type ErrorMap } from './rpcmessage.js';
|
|
2
|
+
import { type RpcValue, type Null, type Int, type IMap, type ShvMap } from './rpcvalue.js';
|
|
3
|
+
import { type RIGetter } from './utils.js';
|
|
4
4
|
type SubscriptionCallback = (path: string, signal: string, param?: RpcValue) => void;
|
|
5
5
|
type ResultOrError<T = RpcValue> = T | Error;
|
|
6
6
|
type Login = {
|