serial-core 0.2.4 → 0.3.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.
@@ -1,68 +0,0 @@
1
- /**
2
- * QueueManager acts as an intermediate buffer.
3
- * It prevents serial port saturation and guarantees messages
4
- * leave in the order they arrived (FIFO).
5
- */
6
- export declare class QueueManager {
7
- private queue;
8
- private isProcessing;
9
- private _currentAlias;
10
- private waitingForResponse;
11
- private currentTimeoutTimer;
12
- private currentItem;
13
- private writeHandler;
14
- /**
15
- * Initializes the QueueManager with a write handler function.
16
- * @param writeHandler - Function to execute when writing data to the port
17
- */
18
- constructor(writeHandler: (data: Buffer | string) => Promise<void>);
19
- /**
20
- * Adds a command to the queue and returns a promise that resolves when processed.
21
- * @param data - The data to queue (string or Buffer)
22
- * @param options - Optional queue item configuration
23
- * @param options.alias - Command identifier for response correlation
24
- * @param options.timeout - Maximum time to wait for operation/response in milliseconds
25
- * @param options.waitResponse - If true, block queue until response is received
26
- * @returns Promise that resolves when the command has been processed
27
- */
28
- add(data: Buffer | string, options?: {
29
- alias?: string;
30
- timeout?: number;
31
- waitResponse?: boolean;
32
- }): Promise<void>;
33
- /**
34
- * Gets the alias of the command currently processing or just processed.
35
- * Useful for correlating received responses with sent commands.
36
- * @returns The alias of the current command, or undefined if none
37
- */
38
- get currentAlias(): string | undefined;
39
- /**
40
- * Clears all pending items from the queue.
41
- * Useful when handling abrupt disconnections.
42
- * All pending items will be rejected with a disconnection error.
43
- */
44
- clear(): void;
45
- /**
46
- * Notifies the queue that a response has been received.
47
- * If waiting for a response, this triggers resolution of the current command
48
- * and processes the next item in the queue.
49
- */
50
- notifyResponse(): void;
51
- /**
52
- * Processes the queue recursively, executing items one by one.
53
- * Handles timeouts and response waiting when configured.
54
- * @private
55
- */
56
- private process;
57
- /**
58
- * Handles timeout when waiting for a response to a sent command.
59
- * @private
60
- * @param item - The queue item that timed out
61
- */
62
- private handleResponseTimeout;
63
- /**
64
- * Checks if the queue is idle (no pending items, not processing, not waiting for response).
65
- * @returns True if the queue has no pending operations
66
- */
67
- isIdle(): boolean;
68
- }
package/dist/types.d.cts DELETED
@@ -1,42 +0,0 @@
1
- export declare const SerialStatus: {
2
- readonly DISCONNECTED: "DISCONNECTED";
3
- readonly SCANNING: "SCANNING";
4
- readonly CONNECTING: "CONNECTING";
5
- readonly CONNECTED: "CONNECTED";
6
- readonly RECONNECTING: "RECONNECTING";
7
- };
8
- export type SerialStatus = (typeof SerialStatus)[keyof typeof SerialStatus];
9
- export interface SerialConfig {
10
- baudRate: number;
11
- path?: string;
12
- vendorId?: string;
13
- productId?: string;
14
- reconnectInterval: number;
15
- autoConnect: boolean;
16
- parser?: NodeJS.ReadWriteStream;
17
- handshake?: {
18
- command: string | Buffer;
19
- pattern: string | RegExp;
20
- timeout: number;
21
- hexPattern?: boolean;
22
- callback?: ((data: Buffer | string) => boolean) | null;
23
- };
24
- }
25
- export interface QueueItem {
26
- data: Buffer | string;
27
- alias?: string;
28
- timeout?: number;
29
- waitResponse?: boolean;
30
- resolve: () => void;
31
- reject: (err: Error) => void;
32
- }
33
- export interface SerialEvents {
34
- status: (status: SerialStatus) => void;
35
- data: (data: Buffer | string, alias?: string) => void;
36
- error: (err: Error) => void;
37
- connected: (info: {
38
- path: string;
39
- baudRate: number;
40
- }) => void;
41
- disconnected: (reason: string) => void;
42
- }
package/dist/types.d.ts DELETED
@@ -1,42 +0,0 @@
1
- export declare const SerialStatus: {
2
- readonly DISCONNECTED: "DISCONNECTED";
3
- readonly SCANNING: "SCANNING";
4
- readonly CONNECTING: "CONNECTING";
5
- readonly CONNECTED: "CONNECTED";
6
- readonly RECONNECTING: "RECONNECTING";
7
- };
8
- export type SerialStatus = (typeof SerialStatus)[keyof typeof SerialStatus];
9
- export interface SerialConfig {
10
- baudRate: number;
11
- path?: string;
12
- vendorId?: string;
13
- productId?: string;
14
- reconnectInterval: number;
15
- autoConnect: boolean;
16
- parser?: NodeJS.ReadWriteStream;
17
- handshake?: {
18
- command: string | Buffer;
19
- pattern: string | RegExp;
20
- timeout: number;
21
- hexPattern?: boolean;
22
- callback?: ((data: Buffer | string) => boolean) | null;
23
- };
24
- }
25
- export interface QueueItem {
26
- data: Buffer | string;
27
- alias?: string;
28
- timeout?: number;
29
- waitResponse?: boolean;
30
- resolve: () => void;
31
- reject: (err: Error) => void;
32
- }
33
- export interface SerialEvents {
34
- status: (status: SerialStatus) => void;
35
- data: (data: Buffer | string, alias?: string) => void;
36
- error: (err: Error) => void;
37
- connected: (info: {
38
- path: string;
39
- baudRate: number;
40
- }) => void;
41
- disconnected: (reason: string) => void;
42
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * Optimized helpers for Buffer operations.
3
- * Designed to minimize unnecessary copies and validations where possible.
4
- */
5
- /**
6
- * Efficiently converts various input types to Buffer.
7
- * If input is already a Buffer, returns it as is (zero-copy).
8
- * @param data - The data to convert (string, number array, Uint8Array, or Buffer)
9
- * @returns A Buffer instance
10
- */
11
- export declare function toBuffer(data: string | number[] | Uint8Array | Buffer): Buffer;
12
- /**
13
- * Converts a Buffer to Uint8Array.
14
- * In Node.js, Buffers ARE Uint8Arrays, so this is ideally zero-copy.
15
- * @param buf - The buffer to convert
16
- * @returns The buffer as a Uint8Array
17
- */
18
- export declare function toUint8Array(buf: Buffer): Uint8Array;
19
- /**
20
- * Converts a Buffer to string with optional encoding (default utf8).
21
- * Wrapper alias for toString().
22
- * @param buf - The buffer to convert
23
- * @param encoding - The character encoding to use (default: 'utf8')
24
- * @returns The buffer contents as a string
25
- */
26
- export declare function toString(buf: Buffer, encoding?: BufferEncoding): string;
27
- /**
28
- * Converts a Buffer to ASCII string representation.
29
- * @param buf - The buffer to convert
30
- * @returns The buffer contents as an ASCII string
31
- */
32
- export declare function toAscii(buf: Buffer): string;
33
- /**
34
- * Converts a Buffer to an array of byte values.
35
- * Note: Using spread operator may be slow for very large buffers.
36
- * @param buf - The buffer to convert
37
- * @returns An array of numbers representing each byte
38
- */
39
- export declare function toArray(buf: Buffer): number[];
@@ -1,39 +0,0 @@
1
- /**
2
- * Optimized helpers for Buffer operations.
3
- * Designed to minimize unnecessary copies and validations where possible.
4
- */
5
- /**
6
- * Efficiently converts various input types to Buffer.
7
- * If input is already a Buffer, returns it as is (zero-copy).
8
- * @param data - The data to convert (string, number array, Uint8Array, or Buffer)
9
- * @returns A Buffer instance
10
- */
11
- export declare function toBuffer(data: string | number[] | Uint8Array | Buffer): Buffer;
12
- /**
13
- * Converts a Buffer to Uint8Array.
14
- * In Node.js, Buffers ARE Uint8Arrays, so this is ideally zero-copy.
15
- * @param buf - The buffer to convert
16
- * @returns The buffer as a Uint8Array
17
- */
18
- export declare function toUint8Array(buf: Buffer): Uint8Array;
19
- /**
20
- * Converts a Buffer to string with optional encoding (default utf8).
21
- * Wrapper alias for toString().
22
- * @param buf - The buffer to convert
23
- * @param encoding - The character encoding to use (default: 'utf8')
24
- * @returns The buffer contents as a string
25
- */
26
- export declare function toString(buf: Buffer, encoding?: BufferEncoding): string;
27
- /**
28
- * Converts a Buffer to ASCII string representation.
29
- * @param buf - The buffer to convert
30
- * @returns The buffer contents as an ASCII string
31
- */
32
- export declare function toAscii(buf: Buffer): string;
33
- /**
34
- * Converts a Buffer to an array of byte values.
35
- * Note: Using spread operator may be slow for very large buffers.
36
- * @param buf - The buffer to convert
37
- * @returns An array of numbers representing each byte
38
- */
39
- export declare function toArray(buf: Buffer): number[];