tmc.js 0.3.0 → 0.3.1

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.
@@ -0,0 +1,33 @@
1
+ declare namespace MessageFields {
2
+ type TYPE = 'messageType';
3
+ type CODE = 'statusCode';
4
+ type PHRASE = 'statusPhrase';
5
+ type FLAG = 'flag';
6
+ type TOKEN = 'token';
7
+ type CONTENT = 'content';
8
+ type APP_KEY = 'app_key';
9
+ type GROUP_NAME = 'group_name';
10
+ type TIMESTAMP = 'timestamp';
11
+ type SIGN = 'sign';
12
+ type SDK = 'sdk';
13
+ type INTRANET_IP = 'intranet_ip';
14
+ type ID = 'id';
15
+ type TOPIC = 'topic';
16
+ }
17
+
18
+ declare class MessageFields {
19
+ static TYPE: MessageFields.TYPE;
20
+ static CODE: MessageFields.CODE;
21
+ static PHRASE: MessageFields.PHRASE;
22
+ static FLAG: MessageFields.FLAG;
23
+ static TOKEN: MessageFields.TOKEN;
24
+ static CONTENT: MessageFields.CONTENT;
25
+ static APP_KEY: MessageFields.APP_KEY;
26
+ static GROUP_NAME: MessageFields.GROUP_NAME;
27
+ static TIMESTAMP: MessageFields.TIMESTAMP;
28
+ static SIGN: MessageFields.SIGN;
29
+ static SDK: MessageFields.SDK;
30
+ static INTRANET_IP: MessageFields.INTRANET_IP;
31
+ static ID: MessageFields.ID;
32
+ static TOPIC: MessageFields.TOPIC;
33
+ }
@@ -0,0 +1,23 @@
1
+ declare namespace MessageKind {
2
+ type None = 0;
3
+ type PullRequest = 1;
4
+ type Confirm = 2;
5
+ type Data = 3;
6
+ type Failed = 20;
7
+ interface includes {
8
+ (value: any): boolean;
9
+ }
10
+ interface toPrimitive {
11
+ (): '__kind';
12
+ }
13
+ }
14
+
15
+ declare class MessageKind {
16
+ static None: MessageKind.None;
17
+ static PullRequest: MessageKind.PullRequest;
18
+ static Confirm: MessageKind.Confirm;
19
+ static Data: MessageKind.Data;
20
+ static Failed: MessageKind.Failed;
21
+ static includes: MessageKind.includes;
22
+ static [Symbol.toPrimitive]: MessageKind.toPrimitive;
23
+ }
@@ -0,0 +1,17 @@
1
+ declare namespace MessageType {
2
+ type CONNECT = 0;
3
+ type CONNECTACK = 1;
4
+ type SEND = 2;
5
+ type SENDACK = 3;
6
+ interface includes {
7
+ (value: any): boolean;
8
+ }
9
+ }
10
+
11
+ declare class MessageType {
12
+ static CONNECT: MessageType.CONNECT;
13
+ static CONNECTACK: MessageType.CONNECTACK;
14
+ static SEND: MessageType.SEND;
15
+ static SENDACK: MessageType.SENDACK;
16
+ static includes: MessageType.includes;
17
+ }
@@ -1,20 +1,76 @@
1
- declare interface Message {
2
- protocolVersion: number;
3
- messageType: number;
4
- statusCode?: number;
5
- statusPhrase?: string;
6
- flag?: number;
7
- token?: string;
8
- content?: MessageContent;
1
+ /// <reference types="node" />
2
+ /// <reference path="header-type.d.ts" />
3
+ /// <reference path="message-kind.d.ts" />
4
+
5
+ declare class Message {
6
+ constructor(
7
+ type?: MessageType.CONNECT | MessageType.CONNECTACK | MessageType.SEND | MessageType.SENDACK,
8
+ kind?: MessageKind.None | MessageKind.PullRequest | MessageKind.Confirm | MessageKind.Data | MessageKind.Failed
9
+ );
10
+ protocolVersion: number;
11
+ messageType: number;
12
+ statusCode?: number;
13
+ statusPhrase?: string;
14
+ flag?: number;
15
+ token?: string;
16
+ content?: MessageContent;
17
+ with(key: string, value?: number | bigint | string | Buffer | Date): this;
18
+ get buffer(): Buffer;
19
+ static from(buf: Buffer): Message;
9
20
  }
10
21
 
11
22
  declare interface MessageContent {
12
- __kind?: number;
13
- id?: number | bigint;
14
- content?: string;
23
+ __kind?: MessageKind.None | MessageKind.PullRequest | MessageKind.Confirm | MessageKind.Data | MessageKind.Failed;
24
+ id?: number | bigint;
25
+ nick?: string;
26
+ retried?: number;
27
+ dataid?: number | bigint;
28
+ outtime?: string | Date;
29
+ topic?: string;
30
+ publisher?: string;
31
+ time?: string | Date;
32
+ userid?: number | bigint;
33
+ notify?: string;
34
+ content?: string | object;
15
35
  }
16
36
 
17
- namespace Message {
18
- export class Encoder {}
19
- export class Decoder {}
37
+ declare namespace Message {
38
+ class Encoder {
39
+ constructor(message: Message);
40
+ compress(): this;
41
+ put(value: number): this;
42
+ putShort(value: number): this;
43
+ putInt(value: number): this;
44
+ putLong(value: number | bigint): this;
45
+ writeCountedString(value?: string): this;
46
+ writeCustomValue(value?: number | bigint | string | Buffer | Date): this;
47
+ get buffer(): Buffer;
48
+ }
49
+ class Decoder {
50
+ constructor(buf: Buffer);
51
+ extract(): this;
52
+ pick0(): Message;
53
+ pick1(): Message;
54
+ pick2(): Message;
55
+ pick3(): Message;
56
+ pick4(): Message;
57
+ pick5(): Message;
58
+ reset(): this;
59
+ get(): number;
60
+ getShort(): number;
61
+ getInt(): number;
62
+ getLong(): bigint;
63
+ readBuffer(): Buffer;
64
+ readCountedString(): null | string;
65
+ readCustomValue(): null | number | bigint | string | Buffer | Date;
66
+ parse0(): null;
67
+ parse1(): number;
68
+ parse2(): number;
69
+ parse3(): number;
70
+ parse4(): bigint;
71
+ parse5(): Date;
72
+ parse6(): Buffer;
73
+ parse7(): string;
74
+ get message(): Message;
75
+ }
20
76
  }
@@ -0,0 +1,21 @@
1
+ declare namespace ValueFormat {
2
+ type Void = 0;
3
+ type CountedString = 1;
4
+ type Byte = 2;
5
+ type Int16 = 3;
6
+ type Int32 = 4;
7
+ type Int64 = 5;
8
+ type Date = 6;
9
+ type ByteArray = 7;
10
+ }
11
+
12
+ declare class ValueFormat {
13
+ static Void: ValueFormat.Void;
14
+ static CountedString: ValueFormat.CountedString;
15
+ static Byte: ValueFormat.Byte;
16
+ static Int16: ValueFormat.Int16;
17
+ static Int32: ValueFormat.Int32;
18
+ static Int64: ValueFormat.Int64;
19
+ static Date: ValueFormat.Date;
20
+ static ByteArray: ValueFormat.ByteArray;
21
+ }