vortez-io 1.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/.gitignore +15 -0
- package/LICENSE +201 -0
- package/PROTOCOL.md +245 -0
- package/README.md +103 -0
- package/build/Frame.d.ts +118 -0
- package/build/Frame.js +241 -0
- package/build/Frame.js.map +1 -0
- package/build/Isomorphic.d.ts +7 -0
- package/build/Isomorphic.js +2 -0
- package/build/Isomorphic.js.map +1 -0
- package/build/RequestManager.d.ts +74 -0
- package/build/RequestManager.js +61 -0
- package/build/RequestManager.js.map +1 -0
- package/build/VIO.d.ts +82 -0
- package/build/VIO.js +219 -0
- package/build/VIO.js.map +1 -0
- package/build/VIOError.d.ts +17 -0
- package/build/VIOError.js +25 -0
- package/build/VIOError.js.map +1 -0
- package/build/VIOStrict.d.ts +62 -0
- package/build/VIOStrict.js +103 -0
- package/build/VIOStrict.js.map +1 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/build/support/LineParser.d.ts +25 -0
- package/build/support/LineParser.js +50 -0
- package/build/support/LineParser.js.map +1 -0
- package/build/support/UTF8Codec.d.ts +34 -0
- package/build/support/UTF8Codec.js +155 -0
- package/build/support/UTF8Codec.js.map +1 -0
- package/build/support/UUID.d.ts +62 -0
- package/build/support/UUID.js +109 -0
- package/build/support/UUID.js.map +1 -0
- package/build/support/Varint.d.ts +26 -0
- package/build/support/Varint.js +61 -0
- package/build/support/Varint.js.map +1 -0
- package/docs/PROTOCOL-PROPOSE.md +252 -0
- package/package.json +35 -0
- package/scripts/build.sh +14 -0
- package/src/Frame.ts +312 -0
- package/src/Isomorphic.ts +7 -0
- package/src/RequestManager.ts +114 -0
- package/src/VIO.ts +194 -0
- package/src/VIOError.ts +22 -0
- package/src/VIOStrict.ts +123 -0
- package/src/index.ts +4 -0
- package/src/support/LineParser.ts +55 -0
- package/src/support/UTF8Codec.ts +166 -0
- package/src/support/UUID.ts +125 -0
- package/src/support/Varint.ts +62 -0
- package/tsconfig.json +17 -0
package/build/VIO.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { Events } from "@netfeez/common";
|
|
2
|
+
import RequestManager from "./RequestManager.js";
|
|
3
|
+
import VIOError from "./VIOError.js";
|
|
4
|
+
import Frame from "./Frame.js";
|
|
5
|
+
import UTF8Codec from "./support/UTF8Codec.js";
|
|
6
|
+
import LineCodec from "./support/LineParser.js";
|
|
7
|
+
export class VIO extends Events {
|
|
8
|
+
mRequest;
|
|
9
|
+
vTransport;
|
|
10
|
+
constructor(dependencies) {
|
|
11
|
+
super();
|
|
12
|
+
this.mRequest = new RequestManager(dependencies);
|
|
13
|
+
this.mRequest.on('error', (error) => this.emit('error', error));
|
|
14
|
+
this.mRequest.on('send', this.sendRequest.bind(this));
|
|
15
|
+
this.vTransport = new Events.Emitter();
|
|
16
|
+
}
|
|
17
|
+
get transport() { return this.vTransport; }
|
|
18
|
+
async request(data, options) {
|
|
19
|
+
return this.mRequest.send(data, options);
|
|
20
|
+
}
|
|
21
|
+
event(name, data) {
|
|
22
|
+
this.sendEvent(name, data);
|
|
23
|
+
}
|
|
24
|
+
handle(data) {
|
|
25
|
+
try {
|
|
26
|
+
const frame = Frame.decode(data);
|
|
27
|
+
switch (frame.type) {
|
|
28
|
+
case 'RAW':
|
|
29
|
+
this.handleRaw(frame);
|
|
30
|
+
break;
|
|
31
|
+
case 'EVENT':
|
|
32
|
+
this.handleEvent(frame);
|
|
33
|
+
break;
|
|
34
|
+
case 'REQUEST':
|
|
35
|
+
this.handleRequest(frame);
|
|
36
|
+
break;
|
|
37
|
+
case 'RESPONSE':
|
|
38
|
+
this.handleResponse(frame);
|
|
39
|
+
break;
|
|
40
|
+
case 'ERROR':
|
|
41
|
+
this.handleError(frame);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
this.sendError(new VIOError(VIOError.Code.INVALID_DATA, 'Unknown frame type'));
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.emit('error', error instanceof VIOError ? error : new VIOError(VIOError.Code.INVALID_DATA, 'Failed to decode frame'));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async handleRaw(frame) {
|
|
53
|
+
this.emit('raw', frame);
|
|
54
|
+
}
|
|
55
|
+
async handleEvent(frame) {
|
|
56
|
+
try {
|
|
57
|
+
if (frame.mode == 'BINARY' || frame.mode == 'CUSTOM') {
|
|
58
|
+
const data = new Uint8Array(frame.data);
|
|
59
|
+
this.emit('event', frame.identifier.id, frame.mode, data);
|
|
60
|
+
}
|
|
61
|
+
else if (frame.mode == 'JSON') {
|
|
62
|
+
const json = UTF8Codec.decode(new Uint8Array(frame.data));
|
|
63
|
+
const data = JSON.parse(json);
|
|
64
|
+
this.emit('event', frame.identifier.id, frame.mode, data);
|
|
65
|
+
}
|
|
66
|
+
else if (frame.mode == 'LINE') {
|
|
67
|
+
const data = LineCodec.decode(frame.data);
|
|
68
|
+
this.emit('event', frame.identifier.id, frame.mode, data);
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
this.sendError(new VIOError(VIOError.Code.UNKNOWN_MODE, `Unknown mode: ${frame.mode}`));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
this.emit('error', error instanceof VIOError ? error : new VIOError(VIOError.Code.INVALID_DATA, 'Failed to process event data'));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async handleRequest(frame) {
|
|
78
|
+
if (!frame.identifier.id)
|
|
79
|
+
return this.sendError(new VIOError(VIOError.Code.INVALID_HEADER, 'Request frame missing UUID'));
|
|
80
|
+
const uuid = frame.identifier.id;
|
|
81
|
+
try {
|
|
82
|
+
if (frame.mode == 'BINARY' || frame.mode == 'CUSTOM') {
|
|
83
|
+
const data = new Uint8Array(frame.data);
|
|
84
|
+
const done = (data) => this.sendResponse(uuid, data);
|
|
85
|
+
const fail = (error) => this.sendError(error, uuid);
|
|
86
|
+
this.emit('request', frame.mode, data, done, fail);
|
|
87
|
+
}
|
|
88
|
+
else if (frame.mode == 'JSON') {
|
|
89
|
+
const json = UTF8Codec.decode(new Uint8Array(frame.data));
|
|
90
|
+
const data = JSON.parse(json);
|
|
91
|
+
const done = (data) => this.sendResponse(uuid, data);
|
|
92
|
+
const fail = (error) => this.sendError(error, uuid);
|
|
93
|
+
this.emit('request', frame.mode, data, done, fail);
|
|
94
|
+
}
|
|
95
|
+
else if (frame.mode == 'LINE') {
|
|
96
|
+
const data = LineCodec.decode(frame.data);
|
|
97
|
+
const done = (data) => this.sendResponse(uuid, data);
|
|
98
|
+
const fail = (error) => this.sendError(error, uuid);
|
|
99
|
+
this.emit('request', frame.mode, data, done, fail);
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
this.sendError(new VIOError(VIOError.Code.UNKNOWN_MODE, `Unknown mode: ${frame.mode}`), uuid);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
this.sendError(new VIOError(VIOError.Code.INVALID_DATA, 'Failed to process request data'), uuid);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async handleResponse(frame) {
|
|
109
|
+
if (!frame.identifier.id)
|
|
110
|
+
return this.sendError(new VIOError(VIOError.Code.INVALID_HEADER, 'Response frame missing UUID'));
|
|
111
|
+
try {
|
|
112
|
+
if (frame.mode == 'BINARY' || frame.mode == 'CUSTOM') {
|
|
113
|
+
const data = new Uint8Array(frame.data);
|
|
114
|
+
this.mRequest.handle(frame.identifier.id, { mode: frame.mode, data });
|
|
115
|
+
}
|
|
116
|
+
else if (frame.mode == 'JSON') {
|
|
117
|
+
const json = UTF8Codec.decode(new Uint8Array(frame.data));
|
|
118
|
+
const data = JSON.parse(json);
|
|
119
|
+
this.mRequest.handle(frame.identifier.id, { mode: 'JSON', data });
|
|
120
|
+
}
|
|
121
|
+
else if (frame.mode == 'LINE') {
|
|
122
|
+
const data = LineCodec.decode(frame.data);
|
|
123
|
+
this.mRequest.handle(frame.identifier.id, { mode: 'LINE', data });
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
this.mRequest.handle(frame.identifier.id, undefined, new VIOError(VIOError.Code.UNKNOWN_MODE, `Unknown mode: ${frame.mode}`));
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
this.mRequest.handle(frame.identifier.id, undefined, new VIOError(VIOError.Code.INVALID_DATA, 'Failed to process response data'));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async handleError(frame) {
|
|
133
|
+
try {
|
|
134
|
+
if (frame.identifier.type === 'NONE') {
|
|
135
|
+
const error = new VIOError(VIOError.Code.INVALID_DATA, 'Unknown error');
|
|
136
|
+
return this.emit('error', error);
|
|
137
|
+
}
|
|
138
|
+
if (frame.mode == 'BINARY' || frame.mode == 'CUSTOM') {
|
|
139
|
+
const data = new Uint8Array(frame.data);
|
|
140
|
+
const error = new VIOError(VIOError.Code.INVALID_DATA, `Error response with binary data: ${data.length} bytes`);
|
|
141
|
+
this.mRequest.handle(frame.identifier.id, undefined, error);
|
|
142
|
+
}
|
|
143
|
+
else if (frame.mode == 'JSON') {
|
|
144
|
+
const json = UTF8Codec.decode(new Uint8Array(frame.data));
|
|
145
|
+
const data = JSON.parse(json);
|
|
146
|
+
const error = new VIOError(VIOError.Code.INVALID_DATA, data.error || 'Unknown error');
|
|
147
|
+
this.mRequest.handle(frame.identifier.id, undefined, error);
|
|
148
|
+
}
|
|
149
|
+
else if (frame.mode == 'LINE') {
|
|
150
|
+
const data = LineCodec.decode(frame.data);
|
|
151
|
+
const error = new VIOError(VIOError.Code.INVALID_DATA, `Error response with line data: ${JSON.stringify(data)}`);
|
|
152
|
+
this.mRequest.handle(frame.identifier.id, undefined, error);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const error = new VIOError(VIOError.Code.UNKNOWN_MODE, `Unknown mode: ${frame.mode}`);
|
|
156
|
+
this.mRequest.handle(frame.identifier.id, undefined, error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
const vioError = new VIOError(VIOError.Code.INVALID_DATA, 'Failed to process error data');
|
|
161
|
+
if (frame.identifier.type === 'UUID')
|
|
162
|
+
this.mRequest.handle(frame.identifier.id, undefined, vioError);
|
|
163
|
+
this.emit('error', vioError);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
sendEvent(name, data, mode) {
|
|
167
|
+
const { content, finalMode } = this.serialize(data, mode);
|
|
168
|
+
const frame = Frame.encode('EVENT', finalMode, content, { type: 'STRING', id: name });
|
|
169
|
+
try {
|
|
170
|
+
this.vTransport.emit('send', frame);
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
this.vTransport.emit('transport:error', err instanceof Error ? err : new Error(String(err)), { stage: 'send', frameType: 'EVENT', info: { name } });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
sendRequest(uuid, data, mode) {
|
|
177
|
+
const { content, finalMode } = this.serialize(data, mode);
|
|
178
|
+
const frame = Frame.encode('REQUEST', finalMode, content, { type: 'UUID', id: uuid });
|
|
179
|
+
try {
|
|
180
|
+
this.vTransport.emit('send', frame);
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
this.vTransport.emit('transport:error', err instanceof Error ? err : new Error(String(err)), { stage: 'send', frameType: 'REQUEST', uuid, info: {} });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
sendResponse(uuid, data, mode) {
|
|
187
|
+
const { content, finalMode } = this.serialize(data, mode);
|
|
188
|
+
const frame = Frame.encode('RESPONSE', finalMode, content, { type: 'UUID', id: uuid });
|
|
189
|
+
try {
|
|
190
|
+
this.vTransport.emit('send', frame);
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
this.vTransport.emit('transport:error', err instanceof Error ? err : new Error(String(err)), { stage: 'send', frameType: 'RESPONSE', uuid, info: {} });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
sendError(error, uuid) {
|
|
197
|
+
const json = JSON.stringify({ error: error.message, code: error.code });
|
|
198
|
+
const content = UTF8Codec.encode(json);
|
|
199
|
+
const frame = Frame.encode('ERROR', 'JSON', content, uuid ? { type: 'UUID', id: uuid } : { type: 'NONE' });
|
|
200
|
+
try {
|
|
201
|
+
this.vTransport.emit('send', frame);
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
this.vTransport.emit('transport:error', err instanceof Error ? err : new Error(String(err)), { stage: 'send', frameType: 'ERROR', uuid, info: {} });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
serialize(data, mode) {
|
|
208
|
+
if (data instanceof Uint8Array)
|
|
209
|
+
return { content: data, finalMode: 'BINARY' };
|
|
210
|
+
if (data instanceof ArrayBuffer)
|
|
211
|
+
return { content: new Uint8Array(data), finalMode: 'BINARY' };
|
|
212
|
+
if (mode === 'LINE')
|
|
213
|
+
return { content: LineCodec.encode(data), finalMode: 'LINE' };
|
|
214
|
+
const json = JSON.stringify(data ?? {});
|
|
215
|
+
return { content: UTF8Codec.encode(json), finalMode: 'JSON' };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
export default VIO;
|
|
219
|
+
//# sourceMappingURL=VIO.js.map
|
package/build/VIO.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VIO.js","sourceRoot":"","sources":["../src/VIO.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAEhD,MAAM,OAAO,GAAmB,SAAQ,MAAoB;IAC9C,QAAQ,CAAoB;IAC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AAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAAC,CAAC;IACxK,CAAC;IACS,SAAS,CAAC,IAAS,EAAE,IAAa;QACxC,IAAI,IAAI,YAAY,UAAU;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;QAC9E,IAAI,IAAI,YAAY,WAAW;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;QAC/F,IAAI,IAAI,KAAK,MAAM;YAAE,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QACnF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACxC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAClE,CAAC;CACJ;AAwBD,eAAe,GAAG,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class VIOError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
code: VIOError.Code;
|
|
4
|
+
constructor(code: VIOError.Code, message: string);
|
|
5
|
+
toString(): string;
|
|
6
|
+
}
|
|
7
|
+
export declare namespace VIOError {
|
|
8
|
+
enum Code {
|
|
9
|
+
INVALID_HEADER = "INVALID_HEADER",
|
|
10
|
+
INVALID_UUID = "INVALID_UUID",
|
|
11
|
+
INVALID_DATA = "INVALID_DATA",
|
|
12
|
+
UNKNOWN_TYPE = "UNKNOWN_TYPE",
|
|
13
|
+
UNKNOWN_MODE = "UNKNOWN_MODE",
|
|
14
|
+
BUFFER_TOO_SHORT = "BUFFER_TOO_SHORT"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default VIOError;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class VIOError extends Error {
|
|
2
|
+
name = 'VIOError';
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'VIOError';
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
toString() {
|
|
10
|
+
return `${this.name} [${this.code}]: ${this.message}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
(function (VIOError) {
|
|
14
|
+
let Code;
|
|
15
|
+
(function (Code) {
|
|
16
|
+
Code["INVALID_HEADER"] = "INVALID_HEADER";
|
|
17
|
+
Code["INVALID_UUID"] = "INVALID_UUID";
|
|
18
|
+
Code["INVALID_DATA"] = "INVALID_DATA";
|
|
19
|
+
Code["UNKNOWN_TYPE"] = "UNKNOWN_TYPE";
|
|
20
|
+
Code["UNKNOWN_MODE"] = "UNKNOWN_MODE";
|
|
21
|
+
Code["BUFFER_TOO_SHORT"] = "BUFFER_TOO_SHORT";
|
|
22
|
+
})(Code = VIOError.Code || (VIOError.Code = {}));
|
|
23
|
+
})(VIOError || (VIOError = {}));
|
|
24
|
+
export default VIOError;
|
|
25
|
+
//# sourceMappingURL=VIOError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VIOError.js","sourceRoot":"","sources":["../src/VIOError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAS,SAAQ,KAAK;IACxB,IAAI,GAAW,UAAU,CAAC;IAC1B,IAAI,CAAgB;IAC3B,YAAmB,IAAmB,EAAE,OAAe;QAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IACM,QAAQ;QACX,OAAO,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;IAC1D,CAAC;CACJ;AACD,WAAiB,QAAQ;IACrB,IAAY,IAOX;IAPD,WAAY,IAAI;QACZ,yCAAiC,CAAA;QACjC,qCAA6B,CAAA;QAC7B,qCAA6B,CAAA;QAC7B,qCAA6B,CAAA;QAC7B,qCAA6B,CAAA;QAC7B,6CAAqC,CAAA;IACzC,CAAC,EAPW,IAAI,GAAJ,aAAI,KAAJ,aAAI,QAOf;AACL,CAAC,EATgB,QAAQ,KAAR,QAAQ,QASxB;AACD,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Events, Schema } from "@netfeez/common";
|
|
2
|
+
import RequestManager from "./RequestManager.js";
|
|
3
|
+
import VIO from "./VIO.js";
|
|
4
|
+
import VIOError from "./VIOError.js";
|
|
5
|
+
import { Frame } from "./Frame.js";
|
|
6
|
+
export declare const RRSchema: Schema.Utils.FromObject<{
|
|
7
|
+
readonly name: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly required: true;
|
|
10
|
+
};
|
|
11
|
+
readonly content: {
|
|
12
|
+
readonly type: "object";
|
|
13
|
+
readonly required: true;
|
|
14
|
+
};
|
|
15
|
+
}, undefined>;
|
|
16
|
+
export declare class VIOStrict<const T extends any, const IEMap extends VIOStrict.EMap, const OEMap extends VIOStrict.EMap, const IRRMap extends VIOStrict.RRMap, const ORRMap extends VIOStrict.RRMap> {
|
|
17
|
+
protected inEMap: IEMap;
|
|
18
|
+
protected outEMap: OEMap;
|
|
19
|
+
protected inRRMap: IRRMap;
|
|
20
|
+
protected outRRMap: ORRMap;
|
|
21
|
+
protected readonly VIO: VIO<T>;
|
|
22
|
+
protected readonly vioEmitter: Events.Emitter<VIOStrict.VIOEventMap>;
|
|
23
|
+
protected readonly eventEmitter: Events.Emitter<VIOStrict.EventMap<IEMap>>;
|
|
24
|
+
protected readonly requestEmitter: Events.Emitter<VIOStrict.ReqEventMap<IRRMap>>;
|
|
25
|
+
constructor(dependencies: RequestManager.DEPENDENCIES<T>, inEMap: IEMap, outEMap: OEMap, inRRMap: IRRMap, outRRMap: ORRMap);
|
|
26
|
+
get trp(): Events<VIO.TransportEventMap>;
|
|
27
|
+
get vio(): Events<VIOStrict.VIOEventMap>;
|
|
28
|
+
get evt(): Events<VIOStrict.EventMap<IEMap>>;
|
|
29
|
+
get rqt(): Events<VIOStrict.ReqEventMap<IRRMap>>;
|
|
30
|
+
event<Name extends string & keyof OEMap>(name: Name, data: OEMap[Name]['infer']): void;
|
|
31
|
+
request<id extends string & keyof ORRMap>(action: id, data: ORRMap[id]['request']['inferToProcess'], options?: RequestManager.SendOptions): Promise<ORRMap[id]['response']['infer']>;
|
|
32
|
+
handle(data: ArrayBuffer | Uint8Array): void;
|
|
33
|
+
protected eventHandler(name: string, _mode: Frame.Mode, data: any): void;
|
|
34
|
+
protected requestHandler(mode: Frame.Mode, data: any, done: (data: any) => void, fail: (error: VIOError) => void): void;
|
|
35
|
+
}
|
|
36
|
+
export declare namespace VIOStrict {
|
|
37
|
+
interface EMap {
|
|
38
|
+
[name: string]: Schema<Schema.Property>;
|
|
39
|
+
}
|
|
40
|
+
interface RREntry {
|
|
41
|
+
request: Schema<Schema.Definition.Object>;
|
|
42
|
+
response: Schema<Schema.Definition.Object>;
|
|
43
|
+
}
|
|
44
|
+
interface RRMap {
|
|
45
|
+
[name: string]: RREntry;
|
|
46
|
+
}
|
|
47
|
+
type VIOEventMap = {
|
|
48
|
+
error: [error: VIOError];
|
|
49
|
+
raw: [frame: Frame];
|
|
50
|
+
};
|
|
51
|
+
type ReqEventMap<RRMap extends VIOStrict.RRMap> = {
|
|
52
|
+
[Name in string & keyof RRMap]: [
|
|
53
|
+
data: RRMap[Name]['request']['infer'],
|
|
54
|
+
respond: (data: RRMap[Name]['response']['inferToProcess']) => void,
|
|
55
|
+
reject: (error: VIOError) => void
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
type EventMap<EMap extends VIOStrict.EMap> = {
|
|
59
|
+
[Name in string & keyof EMap]: [data: EMap[Name]['infer']];
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export default VIOStrict;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Events, Schema } from "@netfeez/common";
|
|
2
|
+
import VIO from "./VIO.js";
|
|
3
|
+
import VIOError from "./VIOError.js";
|
|
4
|
+
export const RRSchema = Schema.fromObject({
|
|
5
|
+
name: { type: 'string', required: true },
|
|
6
|
+
content: { type: 'object', required: true }
|
|
7
|
+
});
|
|
8
|
+
export class VIOStrict {
|
|
9
|
+
inEMap;
|
|
10
|
+
outEMap;
|
|
11
|
+
inRRMap;
|
|
12
|
+
outRRMap;
|
|
13
|
+
VIO;
|
|
14
|
+
vioEmitter;
|
|
15
|
+
eventEmitter;
|
|
16
|
+
requestEmitter;
|
|
17
|
+
constructor(dependencies, inEMap, outEMap, inRRMap, outRRMap) {
|
|
18
|
+
this.inEMap = inEMap;
|
|
19
|
+
this.outEMap = outEMap;
|
|
20
|
+
this.inRRMap = inRRMap;
|
|
21
|
+
this.outRRMap = outRRMap;
|
|
22
|
+
this.VIO = new VIO(dependencies);
|
|
23
|
+
this.vioEmitter = new Events.Emitter();
|
|
24
|
+
this.eventEmitter = new Events.Emitter();
|
|
25
|
+
this.requestEmitter = new Events.Emitter();
|
|
26
|
+
this.VIO.on('event', this.eventHandler.bind(this));
|
|
27
|
+
this.VIO.on('request', this.requestHandler.bind(this));
|
|
28
|
+
this.VIO.on('raw', (frame) => this.vioEmitter.emit('raw', frame));
|
|
29
|
+
this.VIO.on('error', (error) => this.vioEmitter.emit('error', error));
|
|
30
|
+
}
|
|
31
|
+
get trp() { return this.VIO.transport; }
|
|
32
|
+
get vio() { return this.vioEmitter; }
|
|
33
|
+
get evt() { return this.eventEmitter; }
|
|
34
|
+
get rqt() { return this.requestEmitter; }
|
|
35
|
+
event(name, data) {
|
|
36
|
+
const schema = this.outEMap[name];
|
|
37
|
+
if (!schema)
|
|
38
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown event type: ${String(name)}`);
|
|
39
|
+
const processedData = schema.processData(data);
|
|
40
|
+
this.VIO.event(name, processedData);
|
|
41
|
+
}
|
|
42
|
+
async request(action, data, options) {
|
|
43
|
+
const { request: RQS, response: RSS } = this.outRRMap[action];
|
|
44
|
+
if (!RQS)
|
|
45
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown request type: ${String(action)}`);
|
|
46
|
+
if (!RSS)
|
|
47
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown response type: ${String(action)}`);
|
|
48
|
+
const readyData = RQS.processData(data);
|
|
49
|
+
const toSend = RRSchema.processData({ name: action, content: readyData });
|
|
50
|
+
const response = await this.VIO.request(toSend, options);
|
|
51
|
+
if (response.mode !== 'JSON')
|
|
52
|
+
throw new VIOError(VIOError.Code.INVALID_DATA, `Invalid response mode: ${response.mode}`);
|
|
53
|
+
const parsed = RRSchema.processData(response.data);
|
|
54
|
+
if (parsed.name !== action)
|
|
55
|
+
throw new VIOError(VIOError.Code.INVALID_DATA, `Response action mismatch: expected ${action}, got ${parsed.name}`);
|
|
56
|
+
return RSS.processData(parsed.content);
|
|
57
|
+
}
|
|
58
|
+
handle(data) {
|
|
59
|
+
this.VIO.handle(data);
|
|
60
|
+
}
|
|
61
|
+
eventHandler(name, _mode, data) {
|
|
62
|
+
const schema = this.inEMap[name];
|
|
63
|
+
if (!schema)
|
|
64
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown event type: ${String(name)}`);
|
|
65
|
+
const processedData = schema.processData(data);
|
|
66
|
+
this.eventEmitter.emit(name, processedData);
|
|
67
|
+
}
|
|
68
|
+
requestHandler(mode, data, done, fail) {
|
|
69
|
+
if (mode !== 'JSON')
|
|
70
|
+
return fail(new VIOError(VIOError.Code.INVALID_DATA, `Invalid request mode: ${mode}`));
|
|
71
|
+
const parsed = RRSchema.processData(data);
|
|
72
|
+
const { name, content } = parsed;
|
|
73
|
+
const rrEntry = this.inRRMap[name];
|
|
74
|
+
if (!rrEntry)
|
|
75
|
+
return fail(new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown request type: ${String(name)}`));
|
|
76
|
+
const { request: RQS, response: RSS } = rrEntry;
|
|
77
|
+
if (!RQS)
|
|
78
|
+
return fail(new VIOError(VIOError.Code.UNKNOWN_TYPE, `Missing request schema for type: ${String(name)}`));
|
|
79
|
+
if (!RSS)
|
|
80
|
+
return fail(new VIOError(VIOError.Code.UNKNOWN_TYPE, `Missing response schema for type: ${String(name)}`));
|
|
81
|
+
let processedRequest;
|
|
82
|
+
try {
|
|
83
|
+
processedRequest = RQS.processData(content);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
return fail(new VIOError(VIOError.Code.INVALID_DATA, `Failed to process request data for type ${String(name)}: ${error.message}`));
|
|
87
|
+
}
|
|
88
|
+
const respond = (responseData) => {
|
|
89
|
+
let readyResponse;
|
|
90
|
+
try {
|
|
91
|
+
readyResponse = RSS.processData(responseData);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return fail(new VIOError(VIOError.Code.INVALID_DATA, `Failed to process response data for type ${String(name)}: ${error.message}`));
|
|
95
|
+
}
|
|
96
|
+
const toSend = RRSchema.processData({ name, content: readyResponse });
|
|
97
|
+
done(toSend);
|
|
98
|
+
};
|
|
99
|
+
this.requestEmitter.emit(name, processedRequest, respond, fail);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export default VIOStrict;
|
|
103
|
+
//# sourceMappingURL=VIOStrict.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VIOStrict.js","sourceRoot":"","sources":["../src/VIOStrict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,QAAQ,MAAM,eAAe,CAAC;A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IAAI,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,2CAA2C,MAAM,CAAC,IAAI,CAAC,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAAC,CAAC;QAChK,MAAM,OAAO,GAAG,CAAC,YAAuC,EAAE,EAAE;YACxD,IAAI,aAAkB,CAAC;YACvB,IAAI,CAAC;gBAAC,aAAa,GAAG,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;YAAC,CAAC;YACtD,OAAO,KAAK,EAAE,CAAC;gBAAC,OAAO,IAAI,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,4CAA4C,MAAM,CAAC,IAAI,CAAC,KAAM,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAAC,CAAC;YACjK,MAAM,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;YACtE,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB,CAAC,CAAC;QACF,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;CACJ;AA2BD,eAAe,SAAS,CAAC"}
|
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class LineCodec {
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a ContentMap into a Uint8Array containing line-based content.
|
|
4
|
+
* Each key-value pair in the ContentMap is converted into a block of text where the key is on the first line, followed by the value on subsequent lines.
|
|
5
|
+
* Lines are separated by \r\n, and key-value pairs are separated by \r\n\r\n.
|
|
6
|
+
* If a value contains multiple lines, each subsequent line after the first will start with a space character to indicate that it is a continuation of the previous line.
|
|
7
|
+
* @param data A ContentMap object where each key is a string and each value is the corresponding string value to be encoded.
|
|
8
|
+
* @returns A Uint8Array containing the UTF-8 encoded line-based content representing the input ContentMap.
|
|
9
|
+
*/
|
|
10
|
+
static encode(data: LineCodec.ContentMap): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Decodes a Uint8Array containing line-based content into a ContentMap.
|
|
13
|
+
* The input is expected to be UTF-8 encoded and formatted with lines separated by \r\n, and key-value pairs separated by \r\n\r\n.
|
|
14
|
+
* Values that span multiple lines should have subsequent lines starting with a space character.
|
|
15
|
+
* @param content A Uint8Array containing the UTF-8 encoded line-based content.
|
|
16
|
+
* @returns A ContentMap object where each key is a string and each value is the corresponding string value from the input, with multi-line values properly concatenated.
|
|
17
|
+
*/
|
|
18
|
+
static decode(content: ArrayBuffer | Uint8Array): LineCodec.ContentMap;
|
|
19
|
+
}
|
|
20
|
+
export declare namespace LineCodec {
|
|
21
|
+
interface ContentMap {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default LineCodec;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gemail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Provides encoding and decoding functionality for line-based content used in the Vortez IO protocol.
|
|
6
|
+
* The LineCodec class allows for converting between a ContentMap (a mapping of string keys to string values) and a line-based text format where each key-value pair is represented as a block of text with specific formatting rules.
|
|
7
|
+
* This is useful for encoding structured data in a human-readable format that can be easily transmitted and parsed within the Vortez IO protocol.
|
|
8
|
+
*/
|
|
9
|
+
import UTF8Codec from "./UTF8Codec.js";
|
|
10
|
+
export class LineCodec {
|
|
11
|
+
/**
|
|
12
|
+
* Encodes a ContentMap into a Uint8Array containing line-based content.
|
|
13
|
+
* Each key-value pair in the ContentMap is converted into a block of text where the key is on the first line, followed by the value on subsequent lines.
|
|
14
|
+
* Lines are separated by \r\n, and key-value pairs are separated by \r\n\r\n.
|
|
15
|
+
* If a value contains multiple lines, each subsequent line after the first will start with a space character to indicate that it is a continuation of the previous line.
|
|
16
|
+
* @param data A ContentMap object where each key is a string and each value is the corresponding string value to be encoded.
|
|
17
|
+
* @returns A Uint8Array containing the UTF-8 encoded line-based content representing the input ContentMap.
|
|
18
|
+
*/
|
|
19
|
+
static encode(data) {
|
|
20
|
+
let content = '';
|
|
21
|
+
for (const [key, value] of Object.entries(data)) {
|
|
22
|
+
const valueProcessed = value.replace(/\r\n/g, '\r\n ');
|
|
23
|
+
content += `${key}\r\n${valueProcessed}\r\n\r\n`;
|
|
24
|
+
}
|
|
25
|
+
return UTF8Codec.encode(content);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decodes a Uint8Array containing line-based content into a ContentMap.
|
|
29
|
+
* The input is expected to be UTF-8 encoded and formatted with lines separated by \r\n, and key-value pairs separated by \r\n\r\n.
|
|
30
|
+
* Values that span multiple lines should have subsequent lines starting with a space character.
|
|
31
|
+
* @param content A Uint8Array containing the UTF-8 encoded line-based content.
|
|
32
|
+
* @returns A ContentMap object where each key is a string and each value is the corresponding string value from the input, with multi-line values properly concatenated.
|
|
33
|
+
*/
|
|
34
|
+
static decode(content) {
|
|
35
|
+
const view = content instanceof ArrayBuffer ? new Uint8Array(content) : content;
|
|
36
|
+
const decodedContent = UTF8Codec.decode(view);
|
|
37
|
+
const lines = decodedContent.split('\r\n\r\n');
|
|
38
|
+
const result = {};
|
|
39
|
+
for (const line of lines) {
|
|
40
|
+
const [key, ...valueParts] = line.split('\r\n');
|
|
41
|
+
if (!key)
|
|
42
|
+
continue;
|
|
43
|
+
const value = valueParts.join('\r\n').replace(/\r\n /g, '\r\n');
|
|
44
|
+
result[key] = value;
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default LineCodec;
|
|
50
|
+
//# sourceMappingURL=LineParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LineParser.js","sourceRoot":"","sources":["../../src/support/LineParser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC,MAAM,OAAO,SAAS;IAClB;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAAC,IAA0B;QAC3C,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvD,OAAO,IAAI,GAAG,GAAG,OAAO,cAAc,UAAU,CAAC;QACrD,CAAC;QACD,OAAO,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IACD;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,OAAiC;QAClD,MAAM,IAAI,GAAG,OAAO,YAAY,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAChF,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAChD,IAAI,CAAC,GAAG;gBAAE,SAAS;YACnB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAChE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAMD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@netfeez.dev>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description UTF-8 encoder/decoder optimized for:
|
|
6
|
+
* - predictable memory usage (pre-allocation)
|
|
7
|
+
* - safe decoding (malformed/truncated input)
|
|
8
|
+
* - zero external dependencies
|
|
9
|
+
*
|
|
10
|
+
* ⚠️ Fully standards-compliant behavior for replacement (U+FFFD)
|
|
11
|
+
*/
|
|
12
|
+
export declare class UTF8Codec {
|
|
13
|
+
private static readonly REPLACEMENT_CHAR;
|
|
14
|
+
/**
|
|
15
|
+
* Encodes a string into a UTF-8 byte array.
|
|
16
|
+
* @param text The string to encode.
|
|
17
|
+
* @returns A Uint8Array containing the UTF-8 encoded bytes of the input string.
|
|
18
|
+
*/
|
|
19
|
+
static encode(text: string): Uint8Array;
|
|
20
|
+
/**
|
|
21
|
+
* Decodes a UTF-8 byte array into a string. Malformed sequences are replaced with the Unicode replacement character (U+FFFD).
|
|
22
|
+
* @param bytes The Uint8Array containing the UTF-8 encoded bytes to decode.
|
|
23
|
+
* @returns The decoded string, with any malformed sequences replaced by U+FFFD.
|
|
24
|
+
*/
|
|
25
|
+
static decode(bytes: Uint8Array): string;
|
|
26
|
+
/**
|
|
27
|
+
* Writes the UTF-8 encoding of the replacement character (U+FFFD) to the output buffer at the specified offset.
|
|
28
|
+
* @param out The output buffer to write to.
|
|
29
|
+
* @param offset The offset in the buffer where the replacement character should be written.
|
|
30
|
+
* @returns The new offset after writing the replacement character.
|
|
31
|
+
*/
|
|
32
|
+
protected static writeReplacement(out: Uint8Array, offset: number): number;
|
|
33
|
+
}
|
|
34
|
+
export default UTF8Codec;
|