@cosyte/mllp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +529 -0
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/ack-from-hl7/index.cjs +417 -0
- package/dist/ack-from-hl7/index.cjs.map +1 -0
- package/dist/ack-from-hl7/index.d.cts +425 -0
- package/dist/ack-from-hl7/index.d.ts +425 -0
- package/dist/ack-from-hl7/index.mjs +400 -0
- package/dist/ack-from-hl7/index.mjs.map +1 -0
- package/dist/index-DjGQJtYE.d.cts +83 -0
- package/dist/index-DjGQJtYE.d.ts +83 -0
- package/dist/index.cjs +3455 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3112 -0
- package/dist/index.d.ts +3112 -0
- package/dist/index.mjs +3428 -0
- package/dist/index.mjs.map +1 -0
- package/dist/testing/index.cjs +243 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +174 -0
- package/dist/testing/index.d.ts +174 -0
- package/dist/testing/index.mjs +241 -0
- package/dist/testing/index.mjs.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport interface — the abstraction boundary between Connection and raw I/O.
|
|
3
|
+
*
|
|
4
|
+
* All transports implement this callback-bag contract. Implementations:
|
|
5
|
+
* - `NetTransport` — wraps `net.Socket` (production TCP)
|
|
6
|
+
* - `TlsTransport` — wraps `tls.TLSSocket` (Phase 8 — MLLPS / TLS hardening)
|
|
7
|
+
* - `InMemoryTransport` — deterministic test double (`@cosyte/mllp/testing`)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { NetTransport } from '@cosyte/mllp';
|
|
12
|
+
* import { createConnection } from 'node:net';
|
|
13
|
+
* const socket = createConnection({ host: 'localhost', port: 2575 });
|
|
14
|
+
* const transport: Transport = new NetTransport(socket);
|
|
15
|
+
* transport.onData((chunk) => reader.push(chunk));
|
|
16
|
+
* transport.onConnect(() => console.log('connected'));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pure callback-bag transport abstraction.
|
|
24
|
+
*
|
|
25
|
+
* Each `onXxx` registration is **set-once**: calling `onData(fn)` a second time
|
|
26
|
+
* replaces the first handler. This prevents listener leaks across reconnect cycles
|
|
27
|
+
* where Connection re-registers handlers on a fresh Transport.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* function writeAll(t: Transport, chunks: Buffer[]): void {
|
|
32
|
+
* for (const chunk of chunks) t.write(chunk);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
interface Transport {
|
|
37
|
+
/**
|
|
38
|
+
* Write `buf` to the underlying transport.
|
|
39
|
+
*
|
|
40
|
+
* @returns `true` if the bytes were flushed to the kernel immediately;
|
|
41
|
+
* `false` if the write was buffered (backpressure — caller should pause sending
|
|
42
|
+
* until the `onDrain` event fires at the Connection layer).
|
|
43
|
+
*/
|
|
44
|
+
write(buf: Buffer): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Initiate graceful close of the underlying transport.
|
|
47
|
+
* The registered `onClose` handler fires once the socket is fully closed.
|
|
48
|
+
*/
|
|
49
|
+
close(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Abruptly destroy the transport, discarding any pending writes.
|
|
52
|
+
* Fires `onError(reason)` (if provided) then `onClose`.
|
|
53
|
+
*
|
|
54
|
+
* @param reason - Optional error describing why the transport was destroyed.
|
|
55
|
+
*/
|
|
56
|
+
destroy(reason?: Error): void;
|
|
57
|
+
/**
|
|
58
|
+
* Register the data handler. Called synchronously for each received chunk.
|
|
59
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
60
|
+
*
|
|
61
|
+
* @param fn - Called with each raw chunk as it arrives from the OS.
|
|
62
|
+
*/
|
|
63
|
+
onData(fn: (chunk: Buffer) => void): void;
|
|
64
|
+
/**
|
|
65
|
+
* Register the connect handler. Called once after TCP (or TLS) handshake completes.
|
|
66
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
67
|
+
*/
|
|
68
|
+
onConnect(fn: () => void): void;
|
|
69
|
+
/**
|
|
70
|
+
* Register the close handler. Called once when the underlying socket is fully closed.
|
|
71
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
72
|
+
*/
|
|
73
|
+
onClose(fn: () => void): void;
|
|
74
|
+
/**
|
|
75
|
+
* Register the error handler. Called for socket-level errors (ECONNRESET, ETIMEDOUT, etc.).
|
|
76
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
77
|
+
*
|
|
78
|
+
* @param fn - Receives the underlying OS or TLS error.
|
|
79
|
+
*/
|
|
80
|
+
onError(fn: (err: Error) => void): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type { Transport as T };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport interface — the abstraction boundary between Connection and raw I/O.
|
|
3
|
+
*
|
|
4
|
+
* All transports implement this callback-bag contract. Implementations:
|
|
5
|
+
* - `NetTransport` — wraps `net.Socket` (production TCP)
|
|
6
|
+
* - `TlsTransport` — wraps `tls.TLSSocket` (Phase 8 — MLLPS / TLS hardening)
|
|
7
|
+
* - `InMemoryTransport` — deterministic test double (`@cosyte/mllp/testing`)
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { NetTransport } from '@cosyte/mllp';
|
|
12
|
+
* import { createConnection } from 'node:net';
|
|
13
|
+
* const socket = createConnection({ host: 'localhost', port: 2575 });
|
|
14
|
+
* const transport: Transport = new NetTransport(socket);
|
|
15
|
+
* transport.onData((chunk) => reader.push(chunk));
|
|
16
|
+
* transport.onConnect(() => console.log('connected'));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @packageDocumentation
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pure callback-bag transport abstraction.
|
|
24
|
+
*
|
|
25
|
+
* Each `onXxx` registration is **set-once**: calling `onData(fn)` a second time
|
|
26
|
+
* replaces the first handler. This prevents listener leaks across reconnect cycles
|
|
27
|
+
* where Connection re-registers handlers on a fresh Transport.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* function writeAll(t: Transport, chunks: Buffer[]): void {
|
|
32
|
+
* for (const chunk of chunks) t.write(chunk);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
interface Transport {
|
|
37
|
+
/**
|
|
38
|
+
* Write `buf` to the underlying transport.
|
|
39
|
+
*
|
|
40
|
+
* @returns `true` if the bytes were flushed to the kernel immediately;
|
|
41
|
+
* `false` if the write was buffered (backpressure — caller should pause sending
|
|
42
|
+
* until the `onDrain` event fires at the Connection layer).
|
|
43
|
+
*/
|
|
44
|
+
write(buf: Buffer): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Initiate graceful close of the underlying transport.
|
|
47
|
+
* The registered `onClose` handler fires once the socket is fully closed.
|
|
48
|
+
*/
|
|
49
|
+
close(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Abruptly destroy the transport, discarding any pending writes.
|
|
52
|
+
* Fires `onError(reason)` (if provided) then `onClose`.
|
|
53
|
+
*
|
|
54
|
+
* @param reason - Optional error describing why the transport was destroyed.
|
|
55
|
+
*/
|
|
56
|
+
destroy(reason?: Error): void;
|
|
57
|
+
/**
|
|
58
|
+
* Register the data handler. Called synchronously for each received chunk.
|
|
59
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
60
|
+
*
|
|
61
|
+
* @param fn - Called with each raw chunk as it arrives from the OS.
|
|
62
|
+
*/
|
|
63
|
+
onData(fn: (chunk: Buffer) => void): void;
|
|
64
|
+
/**
|
|
65
|
+
* Register the connect handler. Called once after TCP (or TLS) handshake completes.
|
|
66
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
67
|
+
*/
|
|
68
|
+
onConnect(fn: () => void): void;
|
|
69
|
+
/**
|
|
70
|
+
* Register the close handler. Called once when the underlying socket is fully closed.
|
|
71
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
72
|
+
*/
|
|
73
|
+
onClose(fn: () => void): void;
|
|
74
|
+
/**
|
|
75
|
+
* Register the error handler. Called for socket-level errors (ECONNRESET, ETIMEDOUT, etc.).
|
|
76
|
+
* Replaces any previously registered handler (set-once semantics).
|
|
77
|
+
*
|
|
78
|
+
* @param fn - Receives the underlying OS or TLS error.
|
|
79
|
+
*/
|
|
80
|
+
onError(fn: (err: Error) => void): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type { Transport as T };
|