libshv-js 3.16.1 → 3.20.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/{src/chainpack.ts → dist/chainpack.js} +120 -218
- package/dist/cpcontext.d.ts +18 -0
- package/{src/cpcontext.ts → dist/cpcontext.js} +18 -27
- package/dist/cpon.d.ts +55 -0
- package/{src/cpon.ts → dist/cpon.js} +192 -292
- package/dist/index.d.ts +10 -0
- package/dist/index.js +26 -0
- package/dist/json.d.ts +3 -0
- package/{src/json.ts → dist/json.js} +31 -49
- 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 +91 -0
- package/{src/vue-shv.ts → dist/vue-shv.js} +104 -164
- 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 +21 -13
- package/.github/workflows/check-version-bump.yml +0 -22
- package/.github/workflows/lint.yml +0 -33
- package/.github/workflows/publish.yml +0 -24
- package/.github/workflows/test.yml +0 -31
- package/eslint.config.js +0 -103
- package/examples/websocketosaurus.html +0 -44
- package/examples/websocketosaurus.js +0 -94
- package/src/access.ts +0 -103
- package/src/rpcmessage.ts +0 -91
- package/src/rpcvalue.ts +0 -147
- package/src/ws-client.ts +0 -708
- package/src/zod.ts +0 -95
- package/test.ts +0 -110
- package/test_json.ts +0 -44
- package/test_zod.ts +0 -24
- package/tsconfig.json +0 -108
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare class UnpackContext {
|
|
2
|
+
index: number;
|
|
3
|
+
private readonly data;
|
|
4
|
+
constructor(buf: ArrayBufferLike);
|
|
5
|
+
getByte(): number;
|
|
6
|
+
peekByte(): number;
|
|
7
|
+
getBytes(str: string): void;
|
|
8
|
+
}
|
|
9
|
+
declare class PackContext {
|
|
10
|
+
static CHUNK_LEN: number;
|
|
11
|
+
data: Uint8Array<ArrayBuffer>;
|
|
12
|
+
length: number;
|
|
13
|
+
putByte(b: number): void;
|
|
14
|
+
writeStringUtf8(str: string): void;
|
|
15
|
+
writeCharCodeUtf8(charcode: number): void;
|
|
16
|
+
buffer(): ArrayBuffer;
|
|
17
|
+
}
|
|
18
|
+
export { PackContext, UnpackContext };
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnpackContext = exports.PackContext = void 0;
|
|
1
4
|
class UnpackContext {
|
|
2
|
-
index
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
constructor(buf: ArrayBufferLike) {
|
|
5
|
+
index;
|
|
6
|
+
data;
|
|
7
|
+
constructor(buf) {
|
|
6
8
|
this.data = new Uint8Array(buf);
|
|
7
9
|
this.index = 0;
|
|
8
10
|
}
|
|
9
|
-
|
|
10
11
|
getByte() {
|
|
11
12
|
if (this.index >= this.data.length) {
|
|
12
13
|
throw new RangeError('unexpected end of data');
|
|
13
14
|
}
|
|
14
|
-
|
|
15
15
|
return this.data[this.index++];
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
peekByte() {
|
|
19
18
|
if (this.index >= this.data.length) {
|
|
20
19
|
return -1;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
return this.data[this.index];
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
getBytes(str: string) {
|
|
23
|
+
getBytes(str) {
|
|
27
24
|
for (let i = 0; i < str.length; i++) {
|
|
28
25
|
if (str.codePointAt(i) !== this.getByte()) {
|
|
29
26
|
throw new TypeError(`'${str}' expected`);
|
|
@@ -31,57 +28,51 @@ class UnpackContext {
|
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
const transfer = (source
|
|
31
|
+
exports.UnpackContext = UnpackContext;
|
|
32
|
+
const transfer = (source, length) => {
|
|
36
33
|
if (length <= source.byteLength) {
|
|
37
34
|
return source.slice(0, length);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
const sourceView = new Uint8Array(source);
|
|
41
37
|
const destView = new Uint8Array(new ArrayBuffer(length));
|
|
42
38
|
destView.set(sourceView);
|
|
43
39
|
return destView.buffer;
|
|
44
40
|
};
|
|
45
|
-
|
|
46
41
|
class PackContext {
|
|
47
42
|
static CHUNK_LEN = 1024;
|
|
48
43
|
data = new Uint8Array(0);
|
|
49
44
|
length = 0;
|
|
50
|
-
|
|
51
|
-
putByte(b: number) {
|
|
45
|
+
putByte(b) {
|
|
52
46
|
if (this.length >= this.data.length) {
|
|
53
47
|
const buffer = transfer(this.data.buffer, this.data.length + PackContext.CHUNK_LEN);
|
|
54
48
|
this.data = new Uint8Array(buffer);
|
|
55
49
|
}
|
|
56
|
-
|
|
57
50
|
this.data[this.length++] = b;
|
|
58
51
|
}
|
|
59
|
-
|
|
60
|
-
writeStringUtf8(str: string) {
|
|
52
|
+
writeStringUtf8(str) {
|
|
61
53
|
for (let i = 0; i < str.length; i++) {
|
|
62
|
-
const charcode = str.codePointAt(i)
|
|
54
|
+
const charcode = str.codePointAt(i);
|
|
63
55
|
this.writeCharCodeUtf8(charcode);
|
|
64
56
|
}
|
|
65
57
|
}
|
|
66
|
-
|
|
67
|
-
writeCharCodeUtf8(charcode: number) {
|
|
58
|
+
writeCharCodeUtf8(charcode) {
|
|
68
59
|
/* eslint-disable no-bitwise */
|
|
69
60
|
if (charcode < 0x80) {
|
|
70
61
|
this.putByte(charcode);
|
|
71
|
-
}
|
|
62
|
+
}
|
|
63
|
+
else if (charcode < 0x8_00) {
|
|
72
64
|
this.putByte(0xC0 | (charcode >> 6));
|
|
73
65
|
this.putByte(0x80 | (charcode & 0x3F));
|
|
74
|
-
}
|
|
66
|
+
}
|
|
67
|
+
else if (charcode < 0xD8_00 || charcode >= 0xE0_00) {
|
|
75
68
|
this.putByte(0xE0 | (charcode >> 12));
|
|
76
69
|
this.putByte(0x80 | ((charcode >> 6) & 0x3F));
|
|
77
70
|
this.putByte(0x80 | (charcode & 0x3F));
|
|
78
71
|
}
|
|
79
72
|
/* eslint-enable no-bitwise */
|
|
80
73
|
}
|
|
81
|
-
|
|
82
74
|
buffer() {
|
|
83
75
|
return this.data.buffer.slice(0, this.length);
|
|
84
76
|
}
|
|
85
77
|
}
|
|
86
|
-
|
|
87
|
-
export {PackContext, UnpackContext};
|
|
78
|
+
exports.PackContext = PackContext;
|
package/dist/cpon.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type RpcValue, type RpcValueType, type DateTime, type List, Decimal, Double, type IMap, type Int, type MetaMap, RpcValueWithMetaData, type ShvMap, UInt } from './rpcvalue';
|
|
2
|
+
import { PackContext, UnpackContext } from './cpcontext';
|
|
3
|
+
export declare const stringifyDate: (dt: DateTime) => string;
|
|
4
|
+
declare const utf8ToString: (bytearray: ArrayBuffer) => string;
|
|
5
|
+
declare class CponReader {
|
|
6
|
+
ctx: UnpackContext;
|
|
7
|
+
constructor(unpackContext: UnpackContext);
|
|
8
|
+
read(): RpcValue;
|
|
9
|
+
skipWhitespace(): void;
|
|
10
|
+
readDateTime(): DateTime;
|
|
11
|
+
readDateTimeInner(): DateTime;
|
|
12
|
+
readCString(): string;
|
|
13
|
+
readBlobEsc(): ArrayBuffer;
|
|
14
|
+
readBlobHex(): ArrayBuffer;
|
|
15
|
+
readList(): (string | number | boolean | Double | Decimal | ArrayBuffer | DateTime | UInt<number> | List | ShvMap<Record<string, any>> | IMap<Record<number, any>> | RpcValueWithMetaData<MetaMap<Record<string | number, RpcValue>>, RpcValueType> | undefined)[];
|
|
16
|
+
readMetaMap(): MetaMap;
|
|
17
|
+
readMap(): ShvMap;
|
|
18
|
+
readIMap(): IMap;
|
|
19
|
+
readInt(): number;
|
|
20
|
+
readNumber(): number | Decimal | UInt<number>;
|
|
21
|
+
private implReadMap;
|
|
22
|
+
}
|
|
23
|
+
declare class CponWriter {
|
|
24
|
+
private readonly indentString?;
|
|
25
|
+
private oneLiners;
|
|
26
|
+
ctx: PackContext;
|
|
27
|
+
nestLevel: number;
|
|
28
|
+
constructor(indentString?: string | undefined, oneLiners?: OneLiners);
|
|
29
|
+
write(rpcVal: RpcValue): void;
|
|
30
|
+
writeJSString(str: string): void;
|
|
31
|
+
writeBlob(buffer: ArrayBuffer): void;
|
|
32
|
+
writeDateTime(dt: DateTime): void;
|
|
33
|
+
writeBool(b: boolean): void;
|
|
34
|
+
writeMeta(map: MetaMap): void;
|
|
35
|
+
writeIMap(map: IMap): void;
|
|
36
|
+
writeMap(map: ShvMap): void;
|
|
37
|
+
writeMapContent(map: MetaMap | ShvMap | IMap, delimiterStart: string, delimiterEnd: string): void;
|
|
38
|
+
writeList(lst: RpcValue[]): void;
|
|
39
|
+
writeUInt(num: UInt): void;
|
|
40
|
+
writeInt(num: Int): void;
|
|
41
|
+
writeDouble(num: Double): void;
|
|
42
|
+
writeDecimal(val: Decimal): void;
|
|
43
|
+
private doIndentIfNotOneliner;
|
|
44
|
+
private isOneLiner;
|
|
45
|
+
private increaseIndentIfNotOneLiner;
|
|
46
|
+
private decreaseIndentIfNotOneLiner;
|
|
47
|
+
}
|
|
48
|
+
export declare enum OneLiners {
|
|
49
|
+
Yes = 0,
|
|
50
|
+
No = 1
|
|
51
|
+
}
|
|
52
|
+
declare const toCpon: (value: RpcValue, indentString?: string, oneLiners?: OneLiners) => string;
|
|
53
|
+
declare const fromCpon: (str: string | Uint8Array) => RpcValue;
|
|
54
|
+
declare const CPON_PROTOCOL_TYPE = 2;
|
|
55
|
+
export { utf8ToString, CponWriter, CponReader, CPON_PROTOCOL_TYPE, toCpon, fromCpon };
|