vortez-io 1.0.1 → 2.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/README.md +4 -0
- package/build/Frame.js +1 -1
- package/build/RequestManager.d.ts +15 -14
- package/build/RequestManager.js +6 -0
- package/build/RequestManager.js.map +1 -1
- package/build/VIO.d.ts +133 -11
- package/build/VIO.js +105 -4
- package/build/VIO.js.map +1 -1
- package/build/VIOError.d.ts +6 -0
- package/build/VIOError.js +6 -0
- package/build/VIOError.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/strict/VIOStrict.d.ts +57 -0
- package/build/strict/VIOStrict.js +56 -0
- package/build/strict/VIOStrict.js.map +1 -0
- package/build/strict/channel/Channel.d.ts +34 -0
- package/build/strict/channel/Channel.js +16 -0
- package/build/strict/channel/Channel.js.map +1 -0
- package/build/strict/channel/EventChannel.d.ts +53 -0
- package/build/strict/channel/EventChannel.js +58 -0
- package/build/strict/channel/EventChannel.js.map +1 -0
- package/build/strict/channel/RequestChannel.d.ts +67 -0
- package/build/strict/channel/RequestChannel.js +96 -0
- package/build/strict/channel/RequestChannel.js.map +1 -0
- package/build/strict/channel/TransportChannel.d.ts +38 -0
- package/build/strict/channel/TransportChannel.js +30 -0
- package/build/strict/channel/TransportChannel.js.map +1 -0
- package/build/support/Isomorphic.d.ts +18 -0
- package/build/support/Isomorphic.js +2 -0
- package/build/support/Isomorphic.js.map +1 -0
- package/build/support/LineParser.js +2 -4
- package/build/support/LineParser.js.map +1 -1
- package/build/support/UTF8Codec.d.ts +2 -7
- package/build/support/UTF8Codec.js +2 -7
- package/build/support/UTF8Codec.js.map +1 -1
- package/build/support/UUID.d.ts +1 -1
- package/build/support/UUID.js +1 -1
- package/build/support/Varint.js +2 -4
- package/build/support/Varint.js.map +1 -1
- package/docs/ARCHITECTURE.md +200 -0
- package/package.json +5 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Strict typed wrapper around VIO event, request, and transport channels.
|
|
6
|
+
*/
|
|
7
|
+
import type Isomorphic from "../support/Isomorphic.js";
|
|
8
|
+
import { Events } from "@netfeez/common";
|
|
9
|
+
import VIO from "../VIO.js";
|
|
10
|
+
import VIOError from "../VIOError.js";
|
|
11
|
+
import Frame from "../Frame.js";
|
|
12
|
+
import EventChannel from "./channel/EventChannel.js";
|
|
13
|
+
import RequestChannel from "./channel/RequestChannel.js";
|
|
14
|
+
import TransportChannel from "./channel/TransportChannel.js";
|
|
15
|
+
export declare class VIOStrict<const TimeoutType extends any, const IEMap extends EventChannel.EMap, const OEMap extends EventChannel.EMap, const IRRMap extends RequestChannel.RRMap, const ORRMap extends RequestChannel.RRMap> extends Events<VIOStrict.EventMap> {
|
|
16
|
+
protected inEMap: IEMap;
|
|
17
|
+
protected outEMap: OEMap;
|
|
18
|
+
protected inRRMap: IRRMap;
|
|
19
|
+
protected outRRMap: ORRMap;
|
|
20
|
+
protected readonly VIO: VIO<TimeoutType>;
|
|
21
|
+
readonly event: EventChannel<TimeoutType, IEMap, OEMap>;
|
|
22
|
+
readonly request: RequestChannel<TimeoutType, IRRMap, ORRMap>;
|
|
23
|
+
readonly transport: TransportChannel<TimeoutType>;
|
|
24
|
+
constructor(dependencies: Isomorphic.DependencyList<TimeoutType>, inEMap: IEMap, outEMap: OEMap, inRRMap: IRRMap, outRRMap: ORRMap);
|
|
25
|
+
/**
|
|
26
|
+
* Sends a raw data frame through the transport layer.
|
|
27
|
+
* This method is used to send data that does not conform to the structured formats defined in the EventChannel or RequestChannel, allowing for more flexible communication when needed.
|
|
28
|
+
* The data should be provided as a Frame with mode 'RAW', and it will be sent through the VIO instance's transport layer.
|
|
29
|
+
* @param data The raw data frame to send, which should be a Frame with mode 'RAW'. The method will extract the data from the frame and send it through the transport layer.
|
|
30
|
+
*
|
|
31
|
+
* ⚠️ WARNING: Using this method can lead to runtime errors and unexpected behavior if the data is not recognized by the remote side.
|
|
32
|
+
* Use only when you are certain that the data will be handled correctly on the remote side.
|
|
33
|
+
*
|
|
34
|
+
* This is a convenience method: it delegates to `transport.send()` so callers
|
|
35
|
+
* can either call `vioStrict.raw(...)` or `vioStrict.transport.send(...)`.
|
|
36
|
+
*
|
|
37
|
+
* Semantics:
|
|
38
|
+
* - `raw(...)` / `transport.send(...)` send raw bytes through the transport
|
|
39
|
+
* layer (same as sending a `RAW` frame).
|
|
40
|
+
* - `transport` also re-emits incoming `raw` frames from the underlying
|
|
41
|
+
* `VIO` instance; `vioStrict` itself also emits `raw` (duplicated for
|
|
42
|
+
* convenience).
|
|
43
|
+
*
|
|
44
|
+
* Use `raw` only when you intentionally want to bypass the typed
|
|
45
|
+
* `event`/`request` channels and exchange transport-level payloads.
|
|
46
|
+
*
|
|
47
|
+
* @param data The raw data to be sent, which can be an ArrayBuffer or Uint8Array.
|
|
48
|
+
*/
|
|
49
|
+
raw(data: ArrayBuffer | Uint8Array): void;
|
|
50
|
+
}
|
|
51
|
+
export declare namespace VIOStrict {
|
|
52
|
+
type EventMap = {
|
|
53
|
+
raw: [data: Frame<'RAW'>];
|
|
54
|
+
error: [error: VIOError];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export default VIOStrict;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Events } from "@netfeez/common";
|
|
2
|
+
import VIO from "../VIO.js";
|
|
3
|
+
import EventChannel from "./channel/EventChannel.js";
|
|
4
|
+
import RequestChannel from "./channel/RequestChannel.js";
|
|
5
|
+
import TransportChannel from "./channel/TransportChannel.js";
|
|
6
|
+
export class VIOStrict extends Events {
|
|
7
|
+
inEMap;
|
|
8
|
+
outEMap;
|
|
9
|
+
inRRMap;
|
|
10
|
+
outRRMap;
|
|
11
|
+
VIO;
|
|
12
|
+
event;
|
|
13
|
+
request;
|
|
14
|
+
transport;
|
|
15
|
+
constructor(dependencies, inEMap, outEMap, inRRMap, outRRMap) {
|
|
16
|
+
super();
|
|
17
|
+
this.inEMap = inEMap;
|
|
18
|
+
this.outEMap = outEMap;
|
|
19
|
+
this.inRRMap = inRRMap;
|
|
20
|
+
this.outRRMap = outRRMap;
|
|
21
|
+
const vio = new VIO(dependencies);
|
|
22
|
+
this.VIO = vio;
|
|
23
|
+
this.event = new EventChannel(vio, inEMap, outEMap);
|
|
24
|
+
this.request = new RequestChannel(vio, inRRMap, outRRMap);
|
|
25
|
+
this.transport = new TransportChannel(vio);
|
|
26
|
+
vio.on('raw', (...args) => this.emit('raw', ...args));
|
|
27
|
+
vio.on('error', (...args) => this.emit('error', ...args));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sends a raw data frame through the transport layer.
|
|
31
|
+
* This method is used to send data that does not conform to the structured formats defined in the EventChannel or RequestChannel, allowing for more flexible communication when needed.
|
|
32
|
+
* The data should be provided as a Frame with mode 'RAW', and it will be sent through the VIO instance's transport layer.
|
|
33
|
+
* @param data The raw data frame to send, which should be a Frame with mode 'RAW'. The method will extract the data from the frame and send it through the transport layer.
|
|
34
|
+
*
|
|
35
|
+
* ⚠️ WARNING: Using this method can lead to runtime errors and unexpected behavior if the data is not recognized by the remote side.
|
|
36
|
+
* Use only when you are certain that the data will be handled correctly on the remote side.
|
|
37
|
+
*
|
|
38
|
+
* This is a convenience method: it delegates to `transport.send()` so callers
|
|
39
|
+
* can either call `vioStrict.raw(...)` or `vioStrict.transport.send(...)`.
|
|
40
|
+
*
|
|
41
|
+
* Semantics:
|
|
42
|
+
* - `raw(...)` / `transport.send(...)` send raw bytes through the transport
|
|
43
|
+
* layer (same as sending a `RAW` frame).
|
|
44
|
+
* - `transport` also re-emits incoming `raw` frames from the underlying
|
|
45
|
+
* `VIO` instance; `vioStrict` itself also emits `raw` (duplicated for
|
|
46
|
+
* convenience).
|
|
47
|
+
*
|
|
48
|
+
* Use `raw` only when you intentionally want to bypass the typed
|
|
49
|
+
* `event`/`request` channels and exchange transport-level payloads.
|
|
50
|
+
*
|
|
51
|
+
* @param data The raw data to be sent, which can be an ArrayBuffer or Uint8Array.
|
|
52
|
+
*/
|
|
53
|
+
raw(data) { this.transport.send(data); }
|
|
54
|
+
}
|
|
55
|
+
export default VIOStrict;
|
|
56
|
+
//# sourceMappingURL=VIOStrict.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VIOStrict.js","sourceRoot":"","sources":["../../src/strict/VIOStrict.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,GAAG,MAAM,WAAW,CAAC;AAI5B,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAE7D,MAAM,OAAO,SAMX,SAAQ,MAA0B;IASlB;IACA;IACA;IACA;IAXK,GAAG,CAAmB;IAEzB,KAAK,CAA0C;IAC/C,OAAO,CAA8C;IACrD,SAAS,CAAgC;IAEzD,YACI,YAAoD,EAC1C,MAAa,EACb,OAAc,EACd,OAAe,EACf,QAAgB;QAC1B,KAAK,EAAE,CAAC;QAJE,WAAM,GAAN,MAAM,CAAO;QACb,YAAO,GAAP,OAAO,CAAO;QACd,YAAO,GAAP,OAAO,CAAQ;QACf,aAAQ,GAAR,QAAQ,CAAQ;QAE1B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QAClC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QAEf,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC1D,IAAI,CAAC,SAAS,GAAG,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAE3C,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QACtD,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACI,GAAG,CAAC,IAA8B,IAAU,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAClF;AAOD,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Base abstract channel shared by strict VIO channel implementations.
|
|
6
|
+
*/
|
|
7
|
+
import { Events } from "@netfeez/common";
|
|
8
|
+
import VIO from "../../VIO.js";
|
|
9
|
+
export declare abstract class Channel<TimeoutType extends any, EventMap extends Events.EventMap> extends Events<EventMap> {
|
|
10
|
+
protected readonly VIO: VIO<TimeoutType>;
|
|
11
|
+
constructor(VIO: VIO<TimeoutType>);
|
|
12
|
+
/**
|
|
13
|
+
* Sends a message through the channel.
|
|
14
|
+
* The implementation of this method should handle the actual transmission of the message, whether it's through a WebSocket, HTTP request, or any other means.
|
|
15
|
+
* The arguments and return type can be defined based on the specific requirements of the channel implementation.
|
|
16
|
+
*
|
|
17
|
+
* ⚠️ IMPORTANT: The visibility of this method should be carefully considered based on how it will be used within the application.
|
|
18
|
+
* If the channel is intended to be used internally within a module or class, it may be appropriate to keep this method protected.
|
|
19
|
+
* However, if the channel needs to be accessed and handled from outside its defining class, it may need to be made public.
|
|
20
|
+
*/
|
|
21
|
+
protected abstract send(...args: any[]): any;
|
|
22
|
+
/**
|
|
23
|
+
* Handles incoming messages for the channel.
|
|
24
|
+
* The implementation of this method should process the incoming data, validate it, and emit the appropriate events based on the EventMap defined for the channel.
|
|
25
|
+
* The arguments can be defined based on the specific requirements of the channel implementation, such as the raw data received and any metadata associated with it.
|
|
26
|
+
*
|
|
27
|
+
* ⚠️ IMPORTANT: The visibility of this method should be carefully considered based on how it will be used within the application.
|
|
28
|
+
* If the channel is intended to be used internally within a module or class, it may be appropriate to keep this method protected.
|
|
29
|
+
* However, if the channel needs to be accessed and handled from outside its defining class, it may need to be made public.
|
|
30
|
+
*/
|
|
31
|
+
protected abstract handle(...args: any[]): any;
|
|
32
|
+
}
|
|
33
|
+
export declare namespace Channel { }
|
|
34
|
+
export default Channel;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Base abstract channel shared by strict VIO channel implementations.
|
|
6
|
+
*/
|
|
7
|
+
import { Events } from "@netfeez/common";
|
|
8
|
+
export class Channel extends Events {
|
|
9
|
+
VIO;
|
|
10
|
+
constructor(VIO) {
|
|
11
|
+
super();
|
|
12
|
+
this.VIO = VIO;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default Channel;
|
|
16
|
+
//# sourceMappingURL=Channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Channel.js","sourceRoot":"","sources":["../../../src/strict/channel/Channel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,MAAM,OAAgB,OAGpB,SAAQ,MAAgB;IAEC;IADvB,YACuB,GAAqB;QACxC,KAAK,EAAE,CAAC;QADW,QAAG,GAAH,GAAG,CAAkB;IAC/B,CAAC;CAqBjB;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Typed event channel for validating inbound and outbound event payloads.
|
|
6
|
+
*/
|
|
7
|
+
import type { Schema } from "@netfeez/common";
|
|
8
|
+
import type VIO from "../../VIO.js";
|
|
9
|
+
import Channel from "./Channel.js";
|
|
10
|
+
import Frame from "../../Frame.js";
|
|
11
|
+
export declare class EventChannel<const TimeoutType extends any, const IEMap extends EventChannel.EMap, const OEMap extends EventChannel.EMap> extends Channel<TimeoutType, EventChannel.EventMap<IEMap>> {
|
|
12
|
+
protected VIO: VIO<TimeoutType>;
|
|
13
|
+
protected inEMap: IEMap;
|
|
14
|
+
protected outEMap: OEMap;
|
|
15
|
+
constructor(VIO: VIO<TimeoutType>, inEMap: IEMap, outEMap: OEMap);
|
|
16
|
+
/**
|
|
17
|
+
* Sends a custom event to the remote side without validating the event name or data against the OEMap.
|
|
18
|
+
* This method should be used with caution, as it bypasses all type safety and validation checks.
|
|
19
|
+
* It is recommended to use the send method instead, which ensures that the event name and data conform to the defined schemas in the OEMap.
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ WARNING: Using this method can lead to runtime errors and unexpected behavior if the event name or data is not recognized by the remote side.
|
|
22
|
+
* Use only when you are certain that the event will be handled correctly on the remote side.
|
|
23
|
+
*
|
|
24
|
+
* @param name The name of the event to send. Can be any string.
|
|
25
|
+
* @param data The data to send with the event. Can be any value.
|
|
26
|
+
*/
|
|
27
|
+
custom(name: string, data: any): void;
|
|
28
|
+
/**
|
|
29
|
+
* Sends an event to the remote side.
|
|
30
|
+
* The event name must be defined in the OEMap, and the data must conform to the schema defined for that event. If the event name is not recognized, or if the data does not conform to the schema, a VIOError will be thrown.
|
|
31
|
+
* @param name The name of the event to send. Must be a key in the OEMap.
|
|
32
|
+
* @param data The data to send with the event. Must conform to the schema defined for the event in the OEMap.
|
|
33
|
+
* @throws VIOError if the event name is not recognized or if the data does not conform to the schema.
|
|
34
|
+
*/
|
|
35
|
+
send<Name extends string & keyof OEMap>(name: Name, data: OEMap[Name]['infer']): void;
|
|
36
|
+
/**
|
|
37
|
+
* Handles incoming events by validating the event name and data against the IEMap, and then emitting the event if it is recognized. If the event name is not recognized, or if the data does not conform to the schema, a VIOError will be thrown.
|
|
38
|
+
* @param name The name of the incoming event. Must be a key in the IEMap.
|
|
39
|
+
* @param mode The mode of the incoming frame, which can be used for additional processing if needed.
|
|
40
|
+
* @param data The data associated with the incoming event. Must conform to the schema defined for the event in the IEMap.
|
|
41
|
+
* @throws VIOError if the event name is not recognized or if the data does not conform to the schema.
|
|
42
|
+
*/
|
|
43
|
+
protected handle(name: string, mode: Frame.Mode, data: any): void;
|
|
44
|
+
}
|
|
45
|
+
export declare namespace EventChannel {
|
|
46
|
+
interface EMap {
|
|
47
|
+
[name: string]: Schema<Schema.Property>;
|
|
48
|
+
}
|
|
49
|
+
type EventMap<EMap extends EventChannel.EMap> = {
|
|
50
|
+
[Name in string & keyof EMap]: [data: EMap[Name]['infer']];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export default EventChannel;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Channel from "./Channel.js";
|
|
2
|
+
import VIOError from "../../VIOError.js";
|
|
3
|
+
export class EventChannel extends Channel {
|
|
4
|
+
VIO;
|
|
5
|
+
inEMap;
|
|
6
|
+
outEMap;
|
|
7
|
+
constructor(VIO, inEMap, outEMap) {
|
|
8
|
+
super(VIO);
|
|
9
|
+
this.VIO = VIO;
|
|
10
|
+
this.inEMap = inEMap;
|
|
11
|
+
this.outEMap = outEMap;
|
|
12
|
+
this.VIO.on('event', this.handle.bind(this));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Sends a custom event to the remote side without validating the event name or data against the OEMap.
|
|
16
|
+
* This method should be used with caution, as it bypasses all type safety and validation checks.
|
|
17
|
+
* It is recommended to use the send method instead, which ensures that the event name and data conform to the defined schemas in the OEMap.
|
|
18
|
+
*
|
|
19
|
+
* ⚠️ WARNING: Using this method can lead to runtime errors and unexpected behavior if the event name or data is not recognized by the remote side.
|
|
20
|
+
* Use only when you are certain that the event will be handled correctly on the remote side.
|
|
21
|
+
*
|
|
22
|
+
* @param name The name of the event to send. Can be any string.
|
|
23
|
+
* @param data The data to send with the event. Can be any value.
|
|
24
|
+
*/
|
|
25
|
+
custom(name, data) {
|
|
26
|
+
this.VIO.event(name, data);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sends an event to the remote side.
|
|
30
|
+
* The event name must be defined in the OEMap, and the data must conform to the schema defined for that event. If the event name is not recognized, or if the data does not conform to the schema, a VIOError will be thrown.
|
|
31
|
+
* @param name The name of the event to send. Must be a key in the OEMap.
|
|
32
|
+
* @param data The data to send with the event. Must conform to the schema defined for the event in the OEMap.
|
|
33
|
+
* @throws VIOError if the event name is not recognized or if the data does not conform to the schema.
|
|
34
|
+
*/
|
|
35
|
+
send(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
|
+
/**
|
|
43
|
+
* Handles incoming events by validating the event name and data against the IEMap, and then emitting the event if it is recognized. If the event name is not recognized, or if the data does not conform to the schema, a VIOError will be thrown.
|
|
44
|
+
* @param name The name of the incoming event. Must be a key in the IEMap.
|
|
45
|
+
* @param mode The mode of the incoming frame, which can be used for additional processing if needed.
|
|
46
|
+
* @param data The data associated with the incoming event. Must conform to the schema defined for the event in the IEMap.
|
|
47
|
+
* @throws VIOError if the event name is not recognized or if the data does not conform to the schema.
|
|
48
|
+
*/
|
|
49
|
+
handle(name, mode, data) {
|
|
50
|
+
const schema = this.inEMap[name];
|
|
51
|
+
if (!schema)
|
|
52
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown event type: ${String(name)}`);
|
|
53
|
+
const processed = schema.processData(data);
|
|
54
|
+
this.emit(name, processed);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export default EventChannel;
|
|
58
|
+
//# sourceMappingURL=EventChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventChannel.js","sourceRoot":"","sources":["../../../src/strict/channel/EventChannel.ts"],"names":[],"mappings":"AASA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,QAAQ,MAAM,mBAAmB,CAAC;AAGzC,MAAM,OAAO,YAIX,SAAQ,OAAkD;IAE1C;IACA;IACA;IAHd,YACc,GAAqB,EACrB,MAAa,EACb,OAAc;QACxB,KAAK,CAAC,GAAG,CAAC,CAAC;QAHD,QAAG,GAAH,GAAG,CAAkB;QACrB,WAAM,GAAN,MAAM,CAAO;QACb,YAAO,GAAP,OAAO,CAAO;QAExB,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjD,CAAC;IACD;;;;;;;;;;OAUG;IACI,MAAM,CAAC,IAAY,EAAE,IAAS;QACjC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IACD;;;;;;OAMG;IACa,IAAI,CAAoC,IAAU,EAAE,IAA0B;QAC1F,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,uBAAuB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnG,MAAM,aAAa,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACxC,CAAC;IACD;;;;;;OAMG;IACgB,MAAM,CAAC,IAAY,EAAE,IAAgB,EAAE,IAAS;QAC/D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,uBAAuB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnG,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC;CACJ;AASD,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Typed request channel for request/response validation and dispatch.
|
|
6
|
+
*/
|
|
7
|
+
import { Schema } from "@netfeez/common";
|
|
8
|
+
import VIOError from "../../VIOError.js";
|
|
9
|
+
import VIO from "../../VIO.js";
|
|
10
|
+
import Channel from "./Channel.js";
|
|
11
|
+
import type RequestManager from "../../RequestManager.js";
|
|
12
|
+
import Frame from "../../Frame.js";
|
|
13
|
+
export declare const RRSchema: Schema.Utils.FromObject<{
|
|
14
|
+
readonly name: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
readonly required: true;
|
|
17
|
+
};
|
|
18
|
+
readonly content: {
|
|
19
|
+
readonly type: "object";
|
|
20
|
+
readonly required: true;
|
|
21
|
+
};
|
|
22
|
+
}, undefined>;
|
|
23
|
+
export declare class RequestChannel<const TimeoutType extends any, const IRRMap extends RequestChannel.RRMap, const ORRMap extends RequestChannel.RRMap> extends Channel<TimeoutType, RequestChannel.EventMap<IRRMap>> {
|
|
24
|
+
protected VIO: VIO<TimeoutType>;
|
|
25
|
+
protected inRRMap: IRRMap;
|
|
26
|
+
protected outRRMap: ORRMap;
|
|
27
|
+
constructor(VIO: VIO<TimeoutType>, inRRMap: IRRMap, outRRMap: ORRMap);
|
|
28
|
+
/**
|
|
29
|
+
* Sends a request to the remote side and awaits a response. The request action must be defined in the ORRMap, and the request data must conform to the schema defined for that action. If the action is not recognized, or if the request data does not conform to the schema, a VIOError will be thrown. The method returns a promise that resolves with the response data processed according to the schema defined for the response of that action.
|
|
30
|
+
* @param action The name of the request action to send. Must be a key in the ORRMap.
|
|
31
|
+
* @param data The data to send with the request. Must conform to the schema defined for the request in the ORRMap.
|
|
32
|
+
* @param options Optional settings for sending the request, such as timeout duration and retry attempts.
|
|
33
|
+
* @returns A promise that resolves with the response data processed according to the schema defined for the response of the specified action.
|
|
34
|
+
* @throws VIOError if the action is not recognized or if the request data does not conform to the schema.
|
|
35
|
+
*/
|
|
36
|
+
send<Action extends string & keyof ORRMap>(action: Action, data: ORRMap[Action]['request']['inferToProcess'], options?: RequestManager.SendOptions): Promise<ORRMap[Action]['response']['infer']>;
|
|
37
|
+
/**
|
|
38
|
+
* Handles incoming requests from the remote side.
|
|
39
|
+
* The request action must be defined in the IRRMap, and the request data must conform to the schema defined for that action.
|
|
40
|
+
* If the action is not recognized, or if the request data does not conform to the schema, the fail callback will be called with a VIOError.
|
|
41
|
+
* If the request is valid, the corresponding event will be emitted with the processed request data, a respond callback for sending the response, and a reject callback for handling errors.
|
|
42
|
+
* The respond callback should be called with the response data, which will be processed according to the schema defined for the response of that action before being sent back to the requester.
|
|
43
|
+
* The reject callback should be called with a VIOError if there is an error processing the request or preparing the response.
|
|
44
|
+
* @param mode The mode of the incoming request, which should be 'JSON' for valid requests.
|
|
45
|
+
* @param data The raw data of the incoming request, which should be processed according to the schema defined for the request action in the IRRMap.
|
|
46
|
+
* @param done A callback function that should be called with the response data once it is ready to be sent back to the requester. The response data will be processed according to the schema defined for the response of the request action in the IRRMap before being sent.
|
|
47
|
+
* @param fail A callback function that should be called with a VIOError if there is an error processing the request or preparing the response. This will send an error response back to the requester.
|
|
48
|
+
*/
|
|
49
|
+
protected handle(mode: Frame.Mode, data: any, done: (data: any) => void, fail: (error: VIOError) => void): void;
|
|
50
|
+
}
|
|
51
|
+
export declare namespace RequestChannel {
|
|
52
|
+
interface RREntry {
|
|
53
|
+
request: Schema<Schema.Definition.Object>;
|
|
54
|
+
response: Schema<Schema.Definition.Object>;
|
|
55
|
+
}
|
|
56
|
+
interface RRMap {
|
|
57
|
+
[name: string]: RREntry;
|
|
58
|
+
}
|
|
59
|
+
type EventMap<RRMap extends RequestChannel.RRMap> = {
|
|
60
|
+
[Name in string & keyof RRMap]: [
|
|
61
|
+
data: RRMap[Name]['request']['infer'],
|
|
62
|
+
respond: (data: RRMap[Name]['response']['inferToProcess']) => void,
|
|
63
|
+
reject: (error: VIOError) => void
|
|
64
|
+
];
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export default RequestChannel;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Typed request channel for request/response validation and dispatch.
|
|
6
|
+
*/
|
|
7
|
+
import { Schema } from "@netfeez/common";
|
|
8
|
+
import VIOError from "../../VIOError.js";
|
|
9
|
+
import Channel from "./Channel.js";
|
|
10
|
+
export const RRSchema = Schema.fromObject({
|
|
11
|
+
name: { type: 'string', required: true },
|
|
12
|
+
content: { type: 'object', required: true }
|
|
13
|
+
});
|
|
14
|
+
export class RequestChannel extends Channel {
|
|
15
|
+
VIO;
|
|
16
|
+
inRRMap;
|
|
17
|
+
outRRMap;
|
|
18
|
+
constructor(VIO, inRRMap, outRRMap) {
|
|
19
|
+
super(VIO);
|
|
20
|
+
this.VIO = VIO;
|
|
21
|
+
this.inRRMap = inRRMap;
|
|
22
|
+
this.outRRMap = outRRMap;
|
|
23
|
+
this.VIO.on('request', this.handle.bind(this));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Sends a request to the remote side and awaits a response. The request action must be defined in the ORRMap, and the request data must conform to the schema defined for that action. If the action is not recognized, or if the request data does not conform to the schema, a VIOError will be thrown. The method returns a promise that resolves with the response data processed according to the schema defined for the response of that action.
|
|
27
|
+
* @param action The name of the request action to send. Must be a key in the ORRMap.
|
|
28
|
+
* @param data The data to send with the request. Must conform to the schema defined for the request in the ORRMap.
|
|
29
|
+
* @param options Optional settings for sending the request, such as timeout duration and retry attempts.
|
|
30
|
+
* @returns A promise that resolves with the response data processed according to the schema defined for the response of the specified action.
|
|
31
|
+
* @throws VIOError if the action is not recognized or if the request data does not conform to the schema.
|
|
32
|
+
*/
|
|
33
|
+
async send(action, data, options) {
|
|
34
|
+
const { request: RQS, response: RSS } = this.outRRMap[action];
|
|
35
|
+
if (!RQS)
|
|
36
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown request type: ${String(action)}`);
|
|
37
|
+
if (!RSS)
|
|
38
|
+
throw new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown response type: ${String(action)}`);
|
|
39
|
+
const readyData = RQS.processData(data);
|
|
40
|
+
const toSend = RRSchema.processData({ name: action, content: readyData });
|
|
41
|
+
const response = await this.VIO.request(toSend, options);
|
|
42
|
+
if (response.mode !== 'JSON')
|
|
43
|
+
throw new VIOError(VIOError.Code.INVALID_DATA, `Invalid response mode: ${response.mode}`);
|
|
44
|
+
const parsed = RRSchema.processData(response.data);
|
|
45
|
+
if (parsed.name !== action)
|
|
46
|
+
throw new VIOError(VIOError.Code.INVALID_DATA, `Response action mismatch: expected ${action}, got ${parsed.name}`);
|
|
47
|
+
return RSS.processData(parsed.content);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Handles incoming requests from the remote side.
|
|
51
|
+
* The request action must be defined in the IRRMap, and the request data must conform to the schema defined for that action.
|
|
52
|
+
* If the action is not recognized, or if the request data does not conform to the schema, the fail callback will be called with a VIOError.
|
|
53
|
+
* If the request is valid, the corresponding event will be emitted with the processed request data, a respond callback for sending the response, and a reject callback for handling errors.
|
|
54
|
+
* The respond callback should be called with the response data, which will be processed according to the schema defined for the response of that action before being sent back to the requester.
|
|
55
|
+
* The reject callback should be called with a VIOError if there is an error processing the request or preparing the response.
|
|
56
|
+
* @param mode The mode of the incoming request, which should be 'JSON' for valid requests.
|
|
57
|
+
* @param data The raw data of the incoming request, which should be processed according to the schema defined for the request action in the IRRMap.
|
|
58
|
+
* @param done A callback function that should be called with the response data once it is ready to be sent back to the requester. The response data will be processed according to the schema defined for the response of the request action in the IRRMap before being sent.
|
|
59
|
+
* @param fail A callback function that should be called with a VIOError if there is an error processing the request or preparing the response. This will send an error response back to the requester.
|
|
60
|
+
*/
|
|
61
|
+
handle(mode, data, done, fail) {
|
|
62
|
+
if (mode !== 'JSON')
|
|
63
|
+
return fail(new VIOError(VIOError.Code.INVALID_DATA, `Invalid request mode: ${mode}`));
|
|
64
|
+
const parsed = RRSchema.processData(data);
|
|
65
|
+
const { name, content } = parsed;
|
|
66
|
+
const rrEntry = this.inRRMap[name];
|
|
67
|
+
if (!rrEntry)
|
|
68
|
+
return fail(new VIOError(VIOError.Code.UNKNOWN_TYPE, `Unknown request type: ${String(name)}`));
|
|
69
|
+
const { request: RQS, response: RSS } = rrEntry;
|
|
70
|
+
if (!RQS)
|
|
71
|
+
return fail(new VIOError(VIOError.Code.UNKNOWN_TYPE, `Missing request schema for type: ${String(name)}`));
|
|
72
|
+
if (!RSS)
|
|
73
|
+
return fail(new VIOError(VIOError.Code.UNKNOWN_TYPE, `Missing response schema for type: ${String(name)}`));
|
|
74
|
+
let processedRequest;
|
|
75
|
+
try {
|
|
76
|
+
processedRequest = RQS.processData(content);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return fail(new VIOError(VIOError.Code.INVALID_DATA, `Failed to process request data for type ${String(name)}: ${error.message}`));
|
|
80
|
+
}
|
|
81
|
+
const respond = (responseData) => {
|
|
82
|
+
let readyResponse;
|
|
83
|
+
try {
|
|
84
|
+
readyResponse = RSS.processData(responseData);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return fail(new VIOError(VIOError.Code.INVALID_DATA, `Failed to process response data for type ${String(name)}: ${error.message}`));
|
|
88
|
+
}
|
|
89
|
+
const toSend = RRSchema.processData({ name, content: readyResponse });
|
|
90
|
+
done(toSend);
|
|
91
|
+
};
|
|
92
|
+
this.emit(name, processedRequest, respond, fail);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export default RequestChannel;
|
|
96
|
+
//# sourceMappingURL=RequestChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestChannel.js","sourceRoot":"","sources":["../../../src/strict/channel/RequestChannel.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Transport channel bridge for raw frame send and receive events.
|
|
6
|
+
*/
|
|
7
|
+
import Frame from "../../Frame.js";
|
|
8
|
+
import VIO from "../../VIO.js";
|
|
9
|
+
import Channel from "./Channel.js";
|
|
10
|
+
export declare class TransportChannel<TimeoutType extends any> extends Channel<TimeoutType, TransportChannel.EventMap> {
|
|
11
|
+
protected VIO: VIO<TimeoutType>;
|
|
12
|
+
constructor(VIO: VIO<TimeoutType>);
|
|
13
|
+
/**
|
|
14
|
+
* Sends a raw data frame through the transport layer.
|
|
15
|
+
* This method is used to send data that does not conform to the structured formats defined in the EventChannel or RequestChannel, allowing for more flexible communication when needed.
|
|
16
|
+
* The data should be provided as a Frame with mode 'RAW', and it will be sent through the VIO instance's transport layer.
|
|
17
|
+
* @param data The raw data frame to send, which should be a Frame with mode 'RAW'. The method will extract the data from the frame and send it through the transport layer.
|
|
18
|
+
*
|
|
19
|
+
* ⚠️ WARNING: Using this method can lead to runtime errors and unexpected behavior if the data is not recognized by the remote side.
|
|
20
|
+
* Use only when you are certain that the data will be handled correctly on the remote side.
|
|
21
|
+
*
|
|
22
|
+
* @param data The raw data to be sended, which can be an ArrayBuffer or Uint8Array.
|
|
23
|
+
*/
|
|
24
|
+
send(data: ArrayBuffer | Uint8Array): void;
|
|
25
|
+
/**
|
|
26
|
+
* Handles incoming raw data frames by passing them to the VIO instance for processing. This method is called when raw data is received from the transport layer, and it should not be called directly by external code. The VIO instance will handle the raw data and emit the appropriate events based on the content of the frame.
|
|
27
|
+
* @param data The raw data frame received from the transport layer, which can be an ArrayBuffer or Uint8Array.
|
|
28
|
+
*/
|
|
29
|
+
protected handle(data: ArrayBuffer | Uint8Array): void;
|
|
30
|
+
}
|
|
31
|
+
export declare namespace TransportChannel {
|
|
32
|
+
type EventMap = {
|
|
33
|
+
send: [frame: ArrayBuffer];
|
|
34
|
+
raw: [frame: Frame<'RAW'>];
|
|
35
|
+
error: [error: Error, context: VIO.ErrorContext];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export default TransportChannel;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Channel from "./Channel.js";
|
|
2
|
+
export class TransportChannel extends Channel {
|
|
3
|
+
VIO;
|
|
4
|
+
constructor(VIO) {
|
|
5
|
+
super(VIO);
|
|
6
|
+
this.VIO = VIO;
|
|
7
|
+
this.VIO.transport.on('send', (...args) => this.emit('send', ...args));
|
|
8
|
+
this.VIO.transport.on('error', (...args) => this.emit('error', ...args));
|
|
9
|
+
this.VIO.on('raw', (...args) => this.emit('raw', ...args));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Sends a raw data frame through the transport layer.
|
|
13
|
+
* This method is used to send data that does not conform to the structured formats defined in the EventChannel or RequestChannel, allowing for more flexible communication when needed.
|
|
14
|
+
* The data should be provided as a Frame with mode 'RAW', and it will be sent through the VIO instance's transport layer.
|
|
15
|
+
* @param data The raw data frame to send, which should be a Frame with mode 'RAW'. The method will extract the data from the frame and send it through the transport layer.
|
|
16
|
+
*
|
|
17
|
+
* ⚠️ WARNING: Using this method can lead to runtime errors and unexpected behavior if the data is not recognized by the remote side.
|
|
18
|
+
* Use only when you are certain that the data will be handled correctly on the remote side.
|
|
19
|
+
*
|
|
20
|
+
* @param data The raw data to be sended, which can be an ArrayBuffer or Uint8Array.
|
|
21
|
+
*/
|
|
22
|
+
send(data) { this.VIO.raw(data); }
|
|
23
|
+
/**
|
|
24
|
+
* Handles incoming raw data frames by passing them to the VIO instance for processing. This method is called when raw data is received from the transport layer, and it should not be called directly by external code. The VIO instance will handle the raw data and emit the appropriate events based on the content of the frame.
|
|
25
|
+
* @param data The raw data frame received from the transport layer, which can be an ArrayBuffer or Uint8Array.
|
|
26
|
+
*/
|
|
27
|
+
handle(data) { this.VIO.handle(data); }
|
|
28
|
+
}
|
|
29
|
+
export default TransportChannel;
|
|
30
|
+
//# sourceMappingURL=TransportChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransportChannel.js","sourceRoot":"","sources":["../../../src/strict/channel/TransportChannel.ts"],"names":[],"mappings":"AAQA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,MAAM,OAAO,gBAA0C,SAAQ,OAA+C;IACpF;IAAtB,YAAsB,GAAqB;QAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QAApC,QAAG,GAAH,GAAG,CAAkB;QACvC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QACvE,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD;;;;;;;;;;OAUG;IACa,IAAI,CAAC,IAA8B,IAAU,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClF;;;OAGG;IACgB,MAAM,CAAC,IAA8B,IAAU,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CAC7F;AAQD,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module vortez-io
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
|
+
* @license Apache-2.0
|
|
5
|
+
* @description Isomorphic dependency types shared across runtime environments.
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace Isomorphic {
|
|
8
|
+
type TimeoutHandler = () => void | Promise<void>;
|
|
9
|
+
type setTimeout<T> = (handler: TimeoutHandler, timeout: number) => T;
|
|
10
|
+
type clearTimeout<T> = (id: T) => void;
|
|
11
|
+
type createUUID = () => string;
|
|
12
|
+
interface DependencyList<TimeoutType extends any> {
|
|
13
|
+
setTimeout: Isomorphic.setTimeout<TimeoutType>;
|
|
14
|
+
clearTimeout: Isomorphic.clearTimeout<TimeoutType>;
|
|
15
|
+
createUUID?: Isomorphic.createUUID;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export default Isomorphic;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Isomorphic.js","sourceRoot":"","sources":["../../src/support/Isomorphic.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module vortez-io
|
|
3
|
-
* @author NetFeez <netfeez.dev@
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
4
|
* @license Apache-2.0
|
|
5
|
-
* @description
|
|
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.
|
|
5
|
+
* @description Line-based content encoder and decoder for VIO.
|
|
8
6
|
*/
|
|
9
7
|
import UTF8Codec from "./UTF8Codec.js";
|
|
10
8
|
export class LineCodec {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineParser.js","sourceRoot":"","sources":["../../src/support/LineParser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"LineParser.js","sourceRoot":"","sources":["../../src/support/LineParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module vortez-io
|
|
3
|
-
* @author NetFeez <netfeez.dev@
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
4
|
* @license Apache-2.0
|
|
5
|
-
* @description UTF-8 encoder
|
|
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)
|
|
5
|
+
* @description UTF-8 encoder and decoder with replacement-character handling.
|
|
11
6
|
*/
|
|
12
7
|
export declare class UTF8Codec {
|
|
13
8
|
private static readonly REPLACEMENT_CHAR;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module vortez-io
|
|
3
|
-
* @author NetFeez <netfeez.dev@
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>
|
|
4
4
|
* @license Apache-2.0
|
|
5
|
-
* @description UTF-8 encoder
|
|
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)
|
|
5
|
+
* @description UTF-8 encoder and decoder with replacement-character handling.
|
|
11
6
|
*/
|
|
12
7
|
export class UTF8Codec {
|
|
13
8
|
static REPLACEMENT_CHAR = '\uFFFD';
|