@glion/mllp 0.15.3 → 0.19.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/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/transport/decoder.ts"],"sourcesContent":["import { MLLP_END_BYTE_1, MLLP_END_BYTE_2, MLLP_START_BYTE } from \"./constants\";\nimport { TransportError } from \"./errors\";\nimport type { DecodedMessage, DecoderOptions } from \"./types\";\nimport { TransportErrorCode } from \"./types\";\n\n/**\n * Decode a single MLLP frame (VT ... FS CR) into a message.\n *\n * Validates framing, strips the envelope, and returns the payload as\n * both raw bytes and decoded text. Throws {@link TransportError} on\n * any structural issue.\n *\n * For streaming / chunked TCP data, use {@link createDecoderStream} instead.\n *\n * @throws TransportError with `INVALID_START_BYTE` if byte 0 is not 0x0B\n * @throws TransportError with `INVALID_END_SEQUENCE` if frame doesn't end with\n * 0x1C 0x0D\n * @throws TransportError with `MESSAGE_TOO_LARGE` if payload exceeds\n * `maxMessageSize`\n */\nexport function decode(\n frame: Uint8Array,\n options?: DecoderOptions\n): DecodedMessage {\n if (frame.length < 3) {\n throw new TransportError(\n TransportErrorCode.INVALID_END_SEQUENCE,\n \"Frame too short to contain valid MLLP structure\",\n 0\n );\n }\n\n const startByte = frame[0];\n if (startByte !== MLLP_START_BYTE) {\n throw new TransportError(\n TransportErrorCode.INVALID_START_BYTE,\n `Invalid start byte: expected 0x0B, got 0x${(startByte ?? 0).toString(16).padStart(2, \"0\")}`,\n 0\n );\n }\n\n const len = frame.length;\n const endByte1 = frame[len - 2];\n const endByte2 = frame[len - 1];\n if (endByte1 !== MLLP_END_BYTE_1 || endByte2 !== MLLP_END_BYTE_2) {\n throw new TransportError(\n TransportErrorCode.INVALID_END_SEQUENCE,\n `Invalid end sequence: expected 0x1C 0x0D, got 0x${(endByte1 ?? 0).toString(16).padStart(2, \"0\")} 0x${(endByte2 ?? 0).toString(16).padStart(2, \"0\")}`,\n len - 2\n );\n }\n\n const messageLength = len - 3;\n if (\n options?.maxMessageSize !== undefined &&\n messageLength > options.maxMessageSize\n ) {\n throw new TransportError(\n TransportErrorCode.MESSAGE_TOO_LARGE,\n `Message size ${messageLength} exceeds maximum ${options.maxMessageSize}`,\n 0\n );\n }\n\n const data = frame.subarray(1, len - 2);\n const text = new TextDecoder(options?.encoding ?? \"utf8\").decode(data);\n\n return {\n byteLength: messageLength,\n data,\n text,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAgB,OACd,OACA,SACgB;AAChB,KAAI,MAAM,SAAS,EACjB,OAAM,IAAI,eACR,mBAAmB,sBACnB,mDACA,EACD;CAGH,MAAM,YAAY,MAAM;AACxB,KAAI,cAAA,GACF,OAAM,IAAI,eACR,mBAAmB,oBACnB,6CAA6C,aAAa,GAAG,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,IAC1F,EACD;CAGH,MAAM,MAAM,MAAM;CAClB,MAAM,WAAW,MAAM,MAAM;CAC7B,MAAM,WAAW,MAAM,MAAM;AAC7B,KAAI,aAAA,MAAgC,aAAA,GAClC,OAAM,IAAI,eACR,mBAAmB,sBACnB,oDAAoD,YAAY,GAAG,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,YAAY,GAAG,SAAS,GAAG,CAAC,SAAS,GAAG,IAAI,IACnJ,MAAM,EACP;CAGH,MAAM,gBAAgB,MAAM;AAC5B,KACE,SAAS,mBAAmB,KAAA,KAC5B,gBAAgB,QAAQ,eAExB,OAAM,IAAI,eACR,mBAAmB,mBACnB,gBAAgB,cAAc,mBAAmB,QAAQ,kBACzD,EACD;CAGH,MAAM,OAAO,MAAM,SAAS,GAAG,MAAM,EAAE;AAGvC,QAAO;EACL,YAAY;EACZ;EACA,MALW,IAAI,YAAY,SAAS,YAAY,OAAO,CAAC,OAAO,KAAK;EAMrE"}
@@ -1,24 +0,0 @@
1
- /**
2
- * MLLP Start Byte - Vertical Tab (VT)
3
- * Marks the beginning of an MLLP frame
4
- */
5
- export declare const MLLP_START_BYTE = 11;
6
- /**
7
- * MLLP End Byte 1 - File Separator (FS)
8
- * First byte of the end sequence
9
- */
10
- export declare const MLLP_END_BYTE_1 = 28;
11
- /**
12
- * MLLP End Byte 2 - Carriage Return (CR)
13
- * Second byte of the end sequence
14
- */
15
- export declare const MLLP_END_BYTE_2 = 13;
16
- /**
17
- * MLLP header as a Uint8Array containing the start byte
18
- */
19
- export declare const MLLP_HEADER: Uint8Array<ArrayBuffer>;
20
- /**
21
- * MLLP trailer as a Uint8Array containing the end sequence
22
- */
23
- export declare const MLLP_TRAILER: Uint8Array<ArrayBuffer>;
24
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/transport/constants.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,eAAe,KAAO,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,eAAe,KAAO,CAAC;AAEpC;;;GAGG;AACH,eAAO,MAAM,eAAe,KAAO,CAAC;AAMpC;;GAEG;AACH,eAAO,MAAM,WAAW,yBAAoC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,YAAY,yBAAqD,CAAC"}
@@ -1,49 +0,0 @@
1
- import type { DecodedMessage, DecoderOptions } from "./types";
2
- /**
3
- * Create a `TransformStream` that extracts MLLP messages from a raw
4
- * byte stream.
5
- *
6
- * Pipe a TCP socket's `ReadableStream<Uint8Array>` through this stream
7
- * to receive one {@link DecodedMessage} per MLLP frame, regardless of
8
- * how the bytes are chunked on the wire.
9
- *
10
- * @example
11
- * ```typescript
12
- * import { createDecoderStream } from "@glion/mllp";
13
- *
14
- * const decoder = createDecoderStream({
15
- * maxMessageSize: 1024 * 1024, // 1 MB limit
16
- * onError: (err) => log.warn(err), // custom error handler
17
- * });
18
- *
19
- * const messages = socket.readable.pipeThrough(decoder).getReader();
20
- *
21
- * while (true) {
22
- * const { done, value } = await messages.read();
23
- * if (done) break;
24
- * console.log(value.text); // HL7v2 message string
25
- * }
26
- * ```;
27
- *
28
- * @param options - Optional decoder settings (max size, encoding, error
29
- * handler).
30
- * @returns A `TransformStream<Uint8Array, DecodedMessage>`.
31
- */
32
- export declare function createDecoderStream(options?: DecoderOptions): TransformStream<Uint8Array, DecodedMessage>;
33
- /**
34
- * Class-based variant of {@link createDecoderStream} for cases where
35
- * a reusable instance is preferred over the factory function.
36
- *
37
- * Functionally identical — both delegate to the same internal
38
- * transformer.
39
- *
40
- * @example
41
- * ```typescript
42
- * const decoder = new MLLPDecoderStream({ maxMessageSize: 512_000 });
43
- * socket.readable.pipeThrough(decoder);
44
- * ```;
45
- */
46
- export declare class MLLPDecoderStream extends TransformStream<Uint8Array, DecodedMessage> {
47
- constructor(options?: DecoderOptions);
48
- }
49
- //# sourceMappingURL=decoder-stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decoder-stream.d.ts","sourceRoot":"","sources":["../../src/transport/decoder-stream.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AA0W9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,CAAC,EAAE,cAAc,GACvB,eAAe,CAAC,UAAU,EAAE,cAAc,CAAC,CAE7C;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,iBAAkB,SAAQ,eAAe,CACpD,UAAU,EACV,cAAc,CACf;gBACa,OAAO,CAAC,EAAE,cAAc;CAGrC"}
@@ -1,18 +0,0 @@
1
- import type { DecodedMessage, DecoderOptions } from "./types";
2
- /**
3
- * Decode a single MLLP frame (VT ... FS CR) into a message.
4
- *
5
- * Validates framing, strips the envelope, and returns the payload as
6
- * both raw bytes and decoded text. Throws {@link TransportError} on
7
- * any structural issue.
8
- *
9
- * For streaming / chunked TCP data, use {@link createDecoderStream} instead.
10
- *
11
- * @throws TransportError with `INVALID_START_BYTE` if byte 0 is not 0x0B
12
- * @throws TransportError with `INVALID_END_SEQUENCE` if frame doesn't end with
13
- * 0x1C 0x0D
14
- * @throws TransportError with `MESSAGE_TOO_LARGE` if payload exceeds
15
- * `maxMessageSize`
16
- */
17
- export declare function decode(frame: Uint8Array, options?: DecoderOptions): DecodedMessage;
18
- //# sourceMappingURL=decoder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decoder.d.ts","sourceRoot":"","sources":["../../src/transport/decoder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,cAAc,GACvB,cAAc,CAiDhB"}
@@ -1,28 +0,0 @@
1
- /**
2
- * A growable byte buffer with geometric capacity doubling.
3
- *
4
- * Designed for protocol decoders that accumulate bytes from arbitrarily
5
- * chunked TCP streams. Amortizes copy cost to O(n) total — the same
6
- * strategy used by pg-protocol, NATS.js, and Java's ArrayList.
7
- *
8
- * The buffer maintains a read offset so consumed bytes can be skipped
9
- * without shifting data. When the wasted prefix exceeds half the
10
- * capacity, the buffer auto-compacts by shifting remaining bytes to
11
- * the front.
12
- *
13
- * @internal
14
- */
15
- export declare class DynamicBuffer {
16
- private _buffer;
17
- private _length;
18
- private _offset;
19
- constructor(initialCapacity?: number);
20
- get capacity(): number;
21
- get available(): number;
22
- append(chunk: Uint8Array): void;
23
- view(): Uint8Array;
24
- consume(n: number): void;
25
- reset(): void;
26
- private _compact;
27
- }
28
- //# sourceMappingURL=dynamic-buffer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamic-buffer.d.ts","sourceRoot":"","sources":["../../src/transport/dynamic-buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;gBAER,eAAe,SAAO;IAIlC,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAY/B,IAAI,IAAI,UAAU;IAIlB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAYxB,KAAK,IAAI,IAAI;IAKb,OAAO,CAAC,QAAQ;CAMjB"}
@@ -1,14 +0,0 @@
1
- import type { EncoderInput, EncoderOptions } from "./types";
2
- /**
3
- * Encode a single HL7v2 message into an MLLP frame.
4
- *
5
- * Wraps the message with MLLP framing:
6
- * - Start byte: 0x0B (VT)
7
- * - End sequence: 0x1C 0x0D (FS + CR)
8
- */
9
- export declare function encode(message: EncoderInput, _options?: EncoderOptions): Uint8Array;
10
- /**
11
- * Encode multiple HL7v2 messages into concatenated MLLP frames.
12
- */
13
- export declare function encodeMultiple(messages: EncoderInput[], options?: EncoderOptions): Uint8Array;
14
- //# sourceMappingURL=encoder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/transport/encoder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAK5D;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,OAAO,EAAE,YAAY,EACrB,QAAQ,CAAC,EAAE,cAAc,GACxB,UAAU,CAWZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,YAAY,EAAE,EACxB,OAAO,CAAC,EAAE,cAAc,GACvB,UAAU,CAaZ"}
@@ -1,13 +0,0 @@
1
- import { MllpError } from "../errors";
2
- import type { TransportErrorCode } from "./types";
3
- /**
4
- * Transport-level error for MLLP framing issues (invalid framing, incomplete
5
- * messages, etc.)
6
- */
7
- export declare class TransportError extends MllpError {
8
- readonly code: TransportErrorCode;
9
- /** Position in the data where the error occurred (if applicable) */
10
- readonly position?: number;
11
- constructor(code: TransportErrorCode, message: string, position?: number);
12
- }
13
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/transport/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,qBAAa,cAAe,SAAQ,SAAS;IAC3C,SAAiB,IAAI,EAAE,kBAAkB,CAAC;IAC1C,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEf,IAAI,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;CAKzE"}
@@ -1,8 +0,0 @@
1
- export { MLLP_END_BYTE_1, MLLP_END_BYTE_2, MLLP_HEADER, MLLP_START_BYTE, MLLP_TRAILER, } from "./constants";
2
- export { decode } from "./decoder";
3
- export { createDecoderStream, MLLPDecoderStream } from "./decoder-stream";
4
- export { encode, encodeMultiple } from "./encoder";
5
- export { TransportError } from "./errors";
6
- export { TransportErrorCode as ErrorCode } from "./types";
7
- export type { DecodedMessage, DecoderOptions, EncoderInput, EncoderOptions, } from "./types";
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,WAAW,EACX,eAAe,EACf,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,kBAAkB,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC1D,YAAY,EACV,cAAc,EACd,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,SAAS,CAAC"}
@@ -1,49 +0,0 @@
1
- import type { TransportError } from "./errors";
2
- /**
3
- * Input types for encoding - supports both string and binary
4
- */
5
- export type EncoderInput = string | Uint8Array;
6
- /**
7
- * Decoded message result from MLLP frame
8
- */
9
- export interface DecodedMessage {
10
- /** The raw message payload (without MLLP framing) */
11
- data: Uint8Array;
12
- /** Message decoded as string (convenience) */
13
- text: string;
14
- /** Byte length of the original message */
15
- byteLength: number;
16
- }
17
- /**
18
- * Options for the MLLP encoder
19
- */
20
- export interface EncoderOptions {
21
- /** Encoding for string input (default: 'utf-8') */
22
- encoding?: string;
23
- }
24
- /**
25
- * Options for the MLLP decoder
26
- */
27
- export interface DecoderOptions {
28
- /** Maximum message size in bytes (optional, no default limit) */
29
- maxMessageSize?: number;
30
- /** Encoding for text conversion (default: 'utf-8') */
31
- encoding?: string;
32
- /** Error callback for logging/handling errors */
33
- onError?: (error: TransportError) => void;
34
- }
35
- /**
36
- * Error codes for MLLP frame-level errors
37
- */
38
- export declare const TransportErrorCode: {
39
- /** Stream ended with incomplete MLLP message */
40
- readonly INCOMPLETE_MESSAGE: "INCOMPLETE_MESSAGE";
41
- /** Frame does not end with MLLP end sequence (0x1C 0x0D) */
42
- readonly INVALID_END_SEQUENCE: "INVALID_END_SEQUENCE";
43
- /** Frame does not start with MLLP start byte (0x0B) */
44
- readonly INVALID_START_BYTE: "INVALID_START_BYTE";
45
- /** Message exceeds configured maximum size */
46
- readonly MESSAGE_TOO_LARGE: "MESSAGE_TOO_LARGE";
47
- };
48
- export type TransportErrorCode = (typeof TransportErrorCode)[keyof typeof TransportErrorCode];
49
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/transport/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qDAAqD;IACrD,IAAI,EAAE,UAAU,CAAC;IACjB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CAC3C;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;IAC7B,gDAAgD;;IAEhD,4DAA4D;;IAE5D,uDAAuD;;IAEvD,8CAA8C;;CAEtC,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC"}