@cosyte/mllp 0.1.6 → 0.1.7
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 +19 -0
- package/README.md +23 -12
- package/dist/ack-from-hl7/index.cjs.map +1 -1
- package/dist/ack-from-hl7/index.d.cts +1 -1
- package/dist/ack-from-hl7/index.d.ts +1 -1
- package/dist/ack-from-hl7/index.mjs.map +1 -1
- package/dist/arbitraries/index.cjs +282 -0
- package/dist/arbitraries/index.cjs.map +1 -0
- package/dist/arbitraries/index.d.cts +245 -0
- package/dist/arbitraries/index.d.ts +245 -0
- package/dist/arbitraries/index.mjs +271 -0
- package/dist/arbitraries/index.mjs.map +1 -0
- package/dist/index.cjs +57 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -100
- package/dist/index.d.ts +33 -100
- package/dist/index.mjs +57 -17
- package/dist/index.mjs.map +1 -1
- package/dist/registry-CyGU_l8N.d.cts +86 -0
- package/dist/registry-CyGU_l8N.d.ts +86 -0
- package/package.json +17 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,92 +1,10 @@
|
|
|
1
|
+
import { W as WarningCode, M as MllpWarning } from './registry-CyGU_l8N.cjs';
|
|
2
|
+
export { c as createWarning } from './registry-CyGU_l8N.cjs';
|
|
1
3
|
import { T as Transport } from './index-CD8V2Mtk.cjs';
|
|
2
4
|
import { EventEmitter } from 'node:events';
|
|
3
5
|
import { Socket } from 'node:net';
|
|
4
6
|
import { TLSSocket } from 'node:tls';
|
|
5
7
|
|
|
6
|
-
/**
|
|
7
|
-
* MLLP warning code registry and `MllpWarning` factory.
|
|
8
|
-
*
|
|
9
|
-
* `WarningCode` is a **stable public API**. Renaming or removing a code is a breaking change.
|
|
10
|
-
* New codes may only be added in minor versions.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { createWarning, type MllpWarning, type WarningCode } from '@cosyte/mllp';
|
|
15
|
-
* const w: MllpWarning = createWarning('MLLP_EMPTY_PAYLOAD', 128, 'Empty payload between VT and FS');
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @packageDocumentation
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Union of all stable MLLP warning codes.
|
|
22
|
-
*
|
|
23
|
-
* These codes are a **public API**, they appear in `onWarning` handlers, log pipelines,
|
|
24
|
-
* monitoring dashboards, and error messages. Renaming is a breaking change.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const code: WarningCode = 'MLLP_FS_WITHOUT_CR';
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
type WarningCode = "MLLP_MISSING_LEADING_VT" | "MLLP_FS_WITHOUT_CR" | "MLLP_LF_AFTER_FS" | "MLLP_LEADING_WHITESPACE" | "MLLP_TRAILING_BYTES" | "MLLP_PAYLOAD_CONTAINS_VT" | "MLLP_PAYLOAD_CONTAINS_FS" | "MLLP_EMPTY_PAYLOAD" | "MLLP_FRAME_TOO_LARGE" | "MLLP_ACK_UNMATCHED_CONTROL_ID" | "MLLP_ACK_AFTER_TIMEOUT";
|
|
32
|
-
/**
|
|
33
|
-
* A frozen warning object emitted when the decoder tolerates a framing deviation.
|
|
34
|
-
*
|
|
35
|
-
* `connectionId` is `undefined` when emitted by a standalone `FrameReader`.
|
|
36
|
-
* `Connection` enriches it to the real UUIDv4 before forwarding upstream.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const reader = new FrameReader({
|
|
41
|
-
* onFrame: (p) => process(p),
|
|
42
|
-
* onWarning: (w: MllpWarning) => logger.warn(w),
|
|
43
|
-
* allowFsOnly: true,
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
interface MllpWarning {
|
|
48
|
-
readonly code: WarningCode;
|
|
49
|
-
/**
|
|
50
|
-
* Stable human-readable description. It carries structural facts (a byte
|
|
51
|
-
* offset, an accumulated size) and **never a run of payload content**.
|
|
52
|
-
*
|
|
53
|
-
* Two codes carry exactly one input byte, and it is worth knowing which:
|
|
54
|
-
* `MLLP_MISSING_LEADING_VT` and `MLLP_FS_WITHOUT_CR` render the hex of the
|
|
55
|
-
* single byte found where a framing byte was expected, and on a stream that
|
|
56
|
-
* omits its leading `VT` that byte is the first byte of the unframed content.
|
|
57
|
-
* One byte, never a run, the same bound `MllpFramingError.snippet` carries. If
|
|
58
|
-
* that is more than your threat model allows, log `code` and `byteOffset`
|
|
59
|
-
* rather than `message`.
|
|
60
|
-
*
|
|
61
|
-
* The ACK-correlation codes are stricter: their text comes from a frozen
|
|
62
|
-
* registry and does not vary with the wire at all.
|
|
63
|
-
*/
|
|
64
|
-
readonly message: string;
|
|
65
|
-
/** Absolute stream byte offset where the anomaly was detected. */
|
|
66
|
-
readonly byteOffset: number;
|
|
67
|
-
/**
|
|
68
|
-
* Connection identifier. `undefined` at the framing layer;
|
|
69
|
-
* enriched by `Connection` before emitting upstream.
|
|
70
|
-
*/
|
|
71
|
-
readonly connectionId: string | undefined;
|
|
72
|
-
/** Wall-clock time at point of emission. */
|
|
73
|
-
readonly timestamp: Date;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Create a frozen `MllpWarning` object. The returned object is `Object.freeze()`'d
|
|
77
|
-
* so subscribers cannot mutate shared warning state.
|
|
78
|
-
*
|
|
79
|
-
* `connectionId` is always `undefined` here; `Connection` enriches it via
|
|
80
|
-
* `{ ...w, connectionId: this.connectionId }` then re-freezes.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* const w = createWarning('MLLP_EMPTY_PAYLOAD', 64, 'Empty payload between VT and FS');
|
|
85
|
-
* // w.connectionId === undefined
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
declare function createWarning(code: WarningCode, byteOffset: number, message: string): MllpWarning;
|
|
89
|
-
|
|
90
8
|
/**
|
|
91
9
|
* Typed framing error class for unrecoverable MLLP wire-format violations.
|
|
92
10
|
*
|
|
@@ -1409,6 +1327,15 @@ declare class Connection extends EventEmitter {
|
|
|
1409
1327
|
private _warningsTruncated;
|
|
1410
1328
|
private _onWarningFn;
|
|
1411
1329
|
private _drainPromise;
|
|
1330
|
+
/** Resolves {@link Connection._leftDraining}; called on the transition out of `DRAINING`. */
|
|
1331
|
+
private _leaveDraining;
|
|
1332
|
+
/**
|
|
1333
|
+
* Settles when the connection leaves `DRAINING` by any route: the drain finishing, the drain
|
|
1334
|
+
* timeout, a `destroy()`, or the peer closing. A connection enters `DRAINING` at most once, so
|
|
1335
|
+
* one promise per connection is enough. The drain races it, so a `close()` never outlives the
|
|
1336
|
+
* drain it waits on.
|
|
1337
|
+
*/
|
|
1338
|
+
private readonly _leftDraining;
|
|
1412
1339
|
/**
|
|
1413
1340
|
* beforeClose hook, no-op default that resolves immediately.
|
|
1414
1341
|
*
|
|
@@ -1445,7 +1372,9 @@ declare class Connection extends EventEmitter {
|
|
|
1445
1372
|
* Notify the connection that the transport handshake has completed.
|
|
1446
1373
|
*
|
|
1447
1374
|
* Transitions `CONNECTING → CONNECTED` and emits the `'connect'` event.
|
|
1448
|
-
* Called externally by Server/Client after the socket connects.
|
|
1375
|
+
* Called externally by Server/Client after the socket connects. In any other state it does
|
|
1376
|
+
* nothing: a connection closed before its socket connected stays `CLOSED` and emits no
|
|
1377
|
+
* `'connect'`, and a second call on a `CONNECTED` connection emits no second one.
|
|
1449
1378
|
*
|
|
1450
1379
|
* @param remoteAddress - Remote peer IP address, or `null` if unavailable.
|
|
1451
1380
|
* @param remotePort - Remote peer port, or `null` if unavailable.
|
|
@@ -1482,6 +1411,10 @@ declare class Connection extends EventEmitter {
|
|
|
1482
1411
|
* then `DRAINING → DISCONNECTED` once the hook resolves, or `DRAINING → CLOSED`
|
|
1483
1412
|
* if the drain timeout elapses first.
|
|
1484
1413
|
* - If `DRAINING`: waits for the existing drain to complete (idempotent).
|
|
1414
|
+
*
|
|
1415
|
+
* Every pending `close()` resolves as soon as the connection leaves `DRAINING`, by whatever
|
|
1416
|
+
* route: the hook resolving, the drain timeout, a `destroy()`, or the peer closing. A
|
|
1417
|
+
* `destroy()` during a long drain therefore ends the wait at once, not at the drain timeout.
|
|
1485
1418
|
* - If `CLOSED` or `DISCONNECTED`: no-op.
|
|
1486
1419
|
*
|
|
1487
1420
|
* @param opts.drainTimeoutMs - Override drain timeout (default: `opts.drainTimeoutMs ?? 30_000`).
|
|
@@ -1712,7 +1645,7 @@ declare class MllpConnectionError extends Error {
|
|
|
1712
1645
|
* regardless of what arrives on the wire. It is the same shape, and for the same reason, as
|
|
1713
1646
|
* the correlation registry beside it.
|
|
1714
1647
|
*
|
|
1715
|
-
*
|
|
1648
|
+
* **What these diagnostics may carry**
|
|
1716
1649
|
*
|
|
1717
1650
|
* Stable codes, byte counts, byte offsets, elapsed times, and an acknowledgement code drawn
|
|
1718
1651
|
* from the closed six-code Table 0008 set. Nothing else. A control ID is payload content, a
|
|
@@ -2454,7 +2387,7 @@ declare function createStarterServer(opts: StarterServerOptions): Promise<MllpSe
|
|
|
2454
2387
|
* path, the HL7 Table 0008 acknowledgement-code union, and the error type a message
|
|
2455
2388
|
* handler throws to request a specific negative acknowledgement.
|
|
2456
2389
|
*
|
|
2457
|
-
*
|
|
2390
|
+
* **Why this is safety-critical**
|
|
2458
2391
|
*
|
|
2459
2392
|
* A positive acknowledgement (`AA`) tells the sender "you may forget this message, I
|
|
2460
2393
|
* have it." If a server emits `AA` *before* the message is durably handled and then the
|
|
@@ -2608,7 +2541,7 @@ declare function rawAckUncorrelatable(payload: Buffer): boolean;
|
|
|
2608
2541
|
* negative codes, adds a **static, PHI-free** MSA-3 reason. A fresh control ID fills the
|
|
2609
2542
|
* ACK's own MSH-10.
|
|
2610
2543
|
*
|
|
2611
|
-
*
|
|
2544
|
+
* **Why the delimiters are read, not assumed**
|
|
2612
2545
|
*
|
|
2613
2546
|
* MSH-1 **is** the field separator (HL7 v2.5.1 §2.5.4): the byte at offset 3 of the MSH
|
|
2614
2547
|
* segment *defines* it for the whole message. `|` is overwhelmingly common but it is a
|
|
@@ -2627,7 +2560,7 @@ declare function rawAckUncorrelatable(payload: Buffer): boolean;
|
|
|
2627
2560
|
* single component rather than two. Echoing MSH-1 and MSH-2 keeps the content and
|
|
2628
2561
|
* the delimiters that define it together.
|
|
2629
2562
|
*
|
|
2630
|
-
*
|
|
2563
|
+
* **It reads the MSH through the SHARED scanner**
|
|
2631
2564
|
*
|
|
2632
2565
|
* The MSH read is `readMshSegment` from `src/internal/control-id.ts`, the same call the
|
|
2633
2566
|
* client's correlator makes to derive the key it will later match this ACK against. That
|
|
@@ -2647,7 +2580,7 @@ declare function rawAckUncorrelatable(payload: Buffer): boolean;
|
|
|
2647
2580
|
* is not the goal; agreeing on the *correct*, *tolerant* answer is. A lenient reader may
|
|
2648
2581
|
* never drop data that is there (Postel's Law, CLAUDE.md).
|
|
2649
2582
|
*
|
|
2650
|
-
*
|
|
2583
|
+
* **The fail-safe downgrade: never a positive `AA`/`CA` it cannot correlate**
|
|
2651
2584
|
*
|
|
2652
2585
|
* A positive acknowledgement is a promise the sender may forget the message. If it names a
|
|
2653
2586
|
* control ID the sender cannot match, or names one message out of several it never read,
|
|
@@ -2688,7 +2621,7 @@ declare function buildRawAck(payload: Buffer, code: AckCode): Buffer;
|
|
|
2688
2621
|
* handed a value cannot interpolate one, regardless of what arrives on the
|
|
2689
2622
|
* wire.
|
|
2690
2623
|
*
|
|
2691
|
-
*
|
|
2624
|
+
* **What this replaces, and why the shape matters more than the wording**
|
|
2692
2625
|
*
|
|
2693
2626
|
* The `correlateByControlId` path used to build its diagnostics by
|
|
2694
2627
|
* interpolation, and both ends of it were consumer-controlled and unbounded.
|
|
@@ -2703,7 +2636,7 @@ declare function buildRawAck(payload: Buffer, code: AckCode): Buffer;
|
|
|
2703
2636
|
* PID-3, a patient's medical record number, as the "control ID" of a truncated
|
|
2704
2637
|
* MSH. Withholding the bytes is the defence that survives the next such bug.
|
|
2705
2638
|
*
|
|
2706
|
-
*
|
|
2639
|
+
* **What a correlation diagnostic says instead**
|
|
2707
2640
|
*
|
|
2708
2641
|
* That a control id did not match, plus **numbers**: a byte length, a stream
|
|
2709
2642
|
* offset, an elapsed time. A number is a shape, not content. A truncated id is
|
|
@@ -3579,7 +3512,7 @@ declare class MllpClient extends EventEmitter {
|
|
|
3579
3512
|
*
|
|
3580
3513
|
* Emits a frozen `'ack'` event on every successful match.
|
|
3581
3514
|
*
|
|
3582
|
-
*
|
|
3515
|
+
* **Enhanced acknowledgement mode**
|
|
3583
3516
|
*
|
|
3584
3517
|
* A message whose MSH-15 or MSH-16 is not null asks for the two-part protocol of HL7
|
|
3585
3518
|
* v2.5.1 §2.9, and on a client correlating by control ID this method delivers it: the
|
|
@@ -4666,14 +4599,14 @@ declare function resolveDifferentialPeer(raw: string | undefined | null): Differ
|
|
|
4666
4599
|
* `JSON.stringify` a run straight into a log pipeline or a review artifact and read it
|
|
4667
4600
|
* programmatically without scraping human-readable text.
|
|
4668
4601
|
*
|
|
4669
|
-
*
|
|
4602
|
+
* **What this report is, and what it is not**
|
|
4670
4603
|
*
|
|
4671
4604
|
* It records what was **observed** on the wire. It is not a conformance verdict and never
|
|
4672
4605
|
* becomes one: no field says a peer is conformant, no field says a run passed, and nothing
|
|
4673
4606
|
* here decides whether an interface is fit to carry clinical traffic. That judgement
|
|
4674
4607
|
* belongs to the people standing the interface up, with this evidence in front of them.
|
|
4675
4608
|
*
|
|
4676
|
-
*
|
|
4609
|
+
* **Why no payload content appears anywhere**
|
|
4677
4610
|
*
|
|
4678
4611
|
* A peer answering this harness may be a live engine holding real patients, and a report
|
|
4679
4612
|
* is a diagnostic surface that gets written to a file, pasted into a ticket and mailed to
|
|
@@ -4849,7 +4782,7 @@ interface DifferentialReportPeer {
|
|
|
4849
4782
|
* The differential run: send each canonical message at a peer, read what comes back, and
|
|
4850
4783
|
* report what was observed.
|
|
4851
4784
|
*
|
|
4852
|
-
*
|
|
4785
|
+
* **What it does, exchange by exchange**
|
|
4853
4786
|
*
|
|
4854
4787
|
* One connection per exchange, opened, used and closed. That is deliberate: a peer that
|
|
4855
4788
|
* refuses or drops one connection then costs one exchange rather than the whole run, which
|
|
@@ -4862,14 +4795,14 @@ interface DifferentialReportPeer {
|
|
|
4862
4795
|
* that deviates from the block is described by the stable warning code for that deviation
|
|
4863
4796
|
* rather than killing the run with an opaque error.
|
|
4864
4797
|
*
|
|
4865
|
-
*
|
|
4798
|
+
* **What byte parity means here**
|
|
4866
4799
|
*
|
|
4867
4800
|
* The MLLP **envelope** the peer emitted, compared against the canonical Release 1 block
|
|
4868
4801
|
* this package emits for the same payload. It is not equality of message content, which
|
|
4869
4802
|
* can never hold: an acknowledgement carries the peer's own control ID, its own timestamp
|
|
4870
4803
|
* and its own sending application, and it is supposed to.
|
|
4871
4804
|
*
|
|
4872
|
-
*
|
|
4805
|
+
* **Aim it with care**
|
|
4873
4806
|
*
|
|
4874
4807
|
* A run sends real bytes into whatever engine it is pointed at. Those bytes are synthetic
|
|
4875
4808
|
* patients, so an engine that accepts them stores synthetic patients. Point it at a test
|
|
@@ -4981,5 +4914,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
|
|
|
4981
4914
|
*/
|
|
4982
4915
|
declare const VERSION: string;
|
|
4983
4916
|
|
|
4984
|
-
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer,
|
|
4985
|
-
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta,
|
|
4917
|
+
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
4918
|
+
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,92 +1,10 @@
|
|
|
1
|
+
import { W as WarningCode, M as MllpWarning } from './registry-CyGU_l8N.js';
|
|
2
|
+
export { c as createWarning } from './registry-CyGU_l8N.js';
|
|
1
3
|
import { T as Transport } from './index-CD8V2Mtk.js';
|
|
2
4
|
import { EventEmitter } from 'node:events';
|
|
3
5
|
import { Socket } from 'node:net';
|
|
4
6
|
import { TLSSocket } from 'node:tls';
|
|
5
7
|
|
|
6
|
-
/**
|
|
7
|
-
* MLLP warning code registry and `MllpWarning` factory.
|
|
8
|
-
*
|
|
9
|
-
* `WarningCode` is a **stable public API**. Renaming or removing a code is a breaking change.
|
|
10
|
-
* New codes may only be added in minor versions.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { createWarning, type MllpWarning, type WarningCode } from '@cosyte/mllp';
|
|
15
|
-
* const w: MllpWarning = createWarning('MLLP_EMPTY_PAYLOAD', 128, 'Empty payload between VT and FS');
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @packageDocumentation
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Union of all stable MLLP warning codes.
|
|
22
|
-
*
|
|
23
|
-
* These codes are a **public API**, they appear in `onWarning` handlers, log pipelines,
|
|
24
|
-
* monitoring dashboards, and error messages. Renaming is a breaking change.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const code: WarningCode = 'MLLP_FS_WITHOUT_CR';
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
type WarningCode = "MLLP_MISSING_LEADING_VT" | "MLLP_FS_WITHOUT_CR" | "MLLP_LF_AFTER_FS" | "MLLP_LEADING_WHITESPACE" | "MLLP_TRAILING_BYTES" | "MLLP_PAYLOAD_CONTAINS_VT" | "MLLP_PAYLOAD_CONTAINS_FS" | "MLLP_EMPTY_PAYLOAD" | "MLLP_FRAME_TOO_LARGE" | "MLLP_ACK_UNMATCHED_CONTROL_ID" | "MLLP_ACK_AFTER_TIMEOUT";
|
|
32
|
-
/**
|
|
33
|
-
* A frozen warning object emitted when the decoder tolerates a framing deviation.
|
|
34
|
-
*
|
|
35
|
-
* `connectionId` is `undefined` when emitted by a standalone `FrameReader`.
|
|
36
|
-
* `Connection` enriches it to the real UUIDv4 before forwarding upstream.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const reader = new FrameReader({
|
|
41
|
-
* onFrame: (p) => process(p),
|
|
42
|
-
* onWarning: (w: MllpWarning) => logger.warn(w),
|
|
43
|
-
* allowFsOnly: true,
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
interface MllpWarning {
|
|
48
|
-
readonly code: WarningCode;
|
|
49
|
-
/**
|
|
50
|
-
* Stable human-readable description. It carries structural facts (a byte
|
|
51
|
-
* offset, an accumulated size) and **never a run of payload content**.
|
|
52
|
-
*
|
|
53
|
-
* Two codes carry exactly one input byte, and it is worth knowing which:
|
|
54
|
-
* `MLLP_MISSING_LEADING_VT` and `MLLP_FS_WITHOUT_CR` render the hex of the
|
|
55
|
-
* single byte found where a framing byte was expected, and on a stream that
|
|
56
|
-
* omits its leading `VT` that byte is the first byte of the unframed content.
|
|
57
|
-
* One byte, never a run, the same bound `MllpFramingError.snippet` carries. If
|
|
58
|
-
* that is more than your threat model allows, log `code` and `byteOffset`
|
|
59
|
-
* rather than `message`.
|
|
60
|
-
*
|
|
61
|
-
* The ACK-correlation codes are stricter: their text comes from a frozen
|
|
62
|
-
* registry and does not vary with the wire at all.
|
|
63
|
-
*/
|
|
64
|
-
readonly message: string;
|
|
65
|
-
/** Absolute stream byte offset where the anomaly was detected. */
|
|
66
|
-
readonly byteOffset: number;
|
|
67
|
-
/**
|
|
68
|
-
* Connection identifier. `undefined` at the framing layer;
|
|
69
|
-
* enriched by `Connection` before emitting upstream.
|
|
70
|
-
*/
|
|
71
|
-
readonly connectionId: string | undefined;
|
|
72
|
-
/** Wall-clock time at point of emission. */
|
|
73
|
-
readonly timestamp: Date;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Create a frozen `MllpWarning` object. The returned object is `Object.freeze()`'d
|
|
77
|
-
* so subscribers cannot mutate shared warning state.
|
|
78
|
-
*
|
|
79
|
-
* `connectionId` is always `undefined` here; `Connection` enriches it via
|
|
80
|
-
* `{ ...w, connectionId: this.connectionId }` then re-freezes.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* const w = createWarning('MLLP_EMPTY_PAYLOAD', 64, 'Empty payload between VT and FS');
|
|
85
|
-
* // w.connectionId === undefined
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
declare function createWarning(code: WarningCode, byteOffset: number, message: string): MllpWarning;
|
|
89
|
-
|
|
90
8
|
/**
|
|
91
9
|
* Typed framing error class for unrecoverable MLLP wire-format violations.
|
|
92
10
|
*
|
|
@@ -1409,6 +1327,15 @@ declare class Connection extends EventEmitter {
|
|
|
1409
1327
|
private _warningsTruncated;
|
|
1410
1328
|
private _onWarningFn;
|
|
1411
1329
|
private _drainPromise;
|
|
1330
|
+
/** Resolves {@link Connection._leftDraining}; called on the transition out of `DRAINING`. */
|
|
1331
|
+
private _leaveDraining;
|
|
1332
|
+
/**
|
|
1333
|
+
* Settles when the connection leaves `DRAINING` by any route: the drain finishing, the drain
|
|
1334
|
+
* timeout, a `destroy()`, or the peer closing. A connection enters `DRAINING` at most once, so
|
|
1335
|
+
* one promise per connection is enough. The drain races it, so a `close()` never outlives the
|
|
1336
|
+
* drain it waits on.
|
|
1337
|
+
*/
|
|
1338
|
+
private readonly _leftDraining;
|
|
1412
1339
|
/**
|
|
1413
1340
|
* beforeClose hook, no-op default that resolves immediately.
|
|
1414
1341
|
*
|
|
@@ -1445,7 +1372,9 @@ declare class Connection extends EventEmitter {
|
|
|
1445
1372
|
* Notify the connection that the transport handshake has completed.
|
|
1446
1373
|
*
|
|
1447
1374
|
* Transitions `CONNECTING → CONNECTED` and emits the `'connect'` event.
|
|
1448
|
-
* Called externally by Server/Client after the socket connects.
|
|
1375
|
+
* Called externally by Server/Client after the socket connects. In any other state it does
|
|
1376
|
+
* nothing: a connection closed before its socket connected stays `CLOSED` and emits no
|
|
1377
|
+
* `'connect'`, and a second call on a `CONNECTED` connection emits no second one.
|
|
1449
1378
|
*
|
|
1450
1379
|
* @param remoteAddress - Remote peer IP address, or `null` if unavailable.
|
|
1451
1380
|
* @param remotePort - Remote peer port, or `null` if unavailable.
|
|
@@ -1482,6 +1411,10 @@ declare class Connection extends EventEmitter {
|
|
|
1482
1411
|
* then `DRAINING → DISCONNECTED` once the hook resolves, or `DRAINING → CLOSED`
|
|
1483
1412
|
* if the drain timeout elapses first.
|
|
1484
1413
|
* - If `DRAINING`: waits for the existing drain to complete (idempotent).
|
|
1414
|
+
*
|
|
1415
|
+
* Every pending `close()` resolves as soon as the connection leaves `DRAINING`, by whatever
|
|
1416
|
+
* route: the hook resolving, the drain timeout, a `destroy()`, or the peer closing. A
|
|
1417
|
+
* `destroy()` during a long drain therefore ends the wait at once, not at the drain timeout.
|
|
1485
1418
|
* - If `CLOSED` or `DISCONNECTED`: no-op.
|
|
1486
1419
|
*
|
|
1487
1420
|
* @param opts.drainTimeoutMs - Override drain timeout (default: `opts.drainTimeoutMs ?? 30_000`).
|
|
@@ -1712,7 +1645,7 @@ declare class MllpConnectionError extends Error {
|
|
|
1712
1645
|
* regardless of what arrives on the wire. It is the same shape, and for the same reason, as
|
|
1713
1646
|
* the correlation registry beside it.
|
|
1714
1647
|
*
|
|
1715
|
-
*
|
|
1648
|
+
* **What these diagnostics may carry**
|
|
1716
1649
|
*
|
|
1717
1650
|
* Stable codes, byte counts, byte offsets, elapsed times, and an acknowledgement code drawn
|
|
1718
1651
|
* from the closed six-code Table 0008 set. Nothing else. A control ID is payload content, a
|
|
@@ -2454,7 +2387,7 @@ declare function createStarterServer(opts: StarterServerOptions): Promise<MllpSe
|
|
|
2454
2387
|
* path, the HL7 Table 0008 acknowledgement-code union, and the error type a message
|
|
2455
2388
|
* handler throws to request a specific negative acknowledgement.
|
|
2456
2389
|
*
|
|
2457
|
-
*
|
|
2390
|
+
* **Why this is safety-critical**
|
|
2458
2391
|
*
|
|
2459
2392
|
* A positive acknowledgement (`AA`) tells the sender "you may forget this message, I
|
|
2460
2393
|
* have it." If a server emits `AA` *before* the message is durably handled and then the
|
|
@@ -2608,7 +2541,7 @@ declare function rawAckUncorrelatable(payload: Buffer): boolean;
|
|
|
2608
2541
|
* negative codes, adds a **static, PHI-free** MSA-3 reason. A fresh control ID fills the
|
|
2609
2542
|
* ACK's own MSH-10.
|
|
2610
2543
|
*
|
|
2611
|
-
*
|
|
2544
|
+
* **Why the delimiters are read, not assumed**
|
|
2612
2545
|
*
|
|
2613
2546
|
* MSH-1 **is** the field separator (HL7 v2.5.1 §2.5.4): the byte at offset 3 of the MSH
|
|
2614
2547
|
* segment *defines* it for the whole message. `|` is overwhelmingly common but it is a
|
|
@@ -2627,7 +2560,7 @@ declare function rawAckUncorrelatable(payload: Buffer): boolean;
|
|
|
2627
2560
|
* single component rather than two. Echoing MSH-1 and MSH-2 keeps the content and
|
|
2628
2561
|
* the delimiters that define it together.
|
|
2629
2562
|
*
|
|
2630
|
-
*
|
|
2563
|
+
* **It reads the MSH through the SHARED scanner**
|
|
2631
2564
|
*
|
|
2632
2565
|
* The MSH read is `readMshSegment` from `src/internal/control-id.ts`, the same call the
|
|
2633
2566
|
* client's correlator makes to derive the key it will later match this ACK against. That
|
|
@@ -2647,7 +2580,7 @@ declare function rawAckUncorrelatable(payload: Buffer): boolean;
|
|
|
2647
2580
|
* is not the goal; agreeing on the *correct*, *tolerant* answer is. A lenient reader may
|
|
2648
2581
|
* never drop data that is there (Postel's Law, CLAUDE.md).
|
|
2649
2582
|
*
|
|
2650
|
-
*
|
|
2583
|
+
* **The fail-safe downgrade: never a positive `AA`/`CA` it cannot correlate**
|
|
2651
2584
|
*
|
|
2652
2585
|
* A positive acknowledgement is a promise the sender may forget the message. If it names a
|
|
2653
2586
|
* control ID the sender cannot match, or names one message out of several it never read,
|
|
@@ -2688,7 +2621,7 @@ declare function buildRawAck(payload: Buffer, code: AckCode): Buffer;
|
|
|
2688
2621
|
* handed a value cannot interpolate one, regardless of what arrives on the
|
|
2689
2622
|
* wire.
|
|
2690
2623
|
*
|
|
2691
|
-
*
|
|
2624
|
+
* **What this replaces, and why the shape matters more than the wording**
|
|
2692
2625
|
*
|
|
2693
2626
|
* The `correlateByControlId` path used to build its diagnostics by
|
|
2694
2627
|
* interpolation, and both ends of it were consumer-controlled and unbounded.
|
|
@@ -2703,7 +2636,7 @@ declare function buildRawAck(payload: Buffer, code: AckCode): Buffer;
|
|
|
2703
2636
|
* PID-3, a patient's medical record number, as the "control ID" of a truncated
|
|
2704
2637
|
* MSH. Withholding the bytes is the defence that survives the next such bug.
|
|
2705
2638
|
*
|
|
2706
|
-
*
|
|
2639
|
+
* **What a correlation diagnostic says instead**
|
|
2707
2640
|
*
|
|
2708
2641
|
* That a control id did not match, plus **numbers**: a byte length, a stream
|
|
2709
2642
|
* offset, an elapsed time. A number is a shape, not content. A truncated id is
|
|
@@ -3579,7 +3512,7 @@ declare class MllpClient extends EventEmitter {
|
|
|
3579
3512
|
*
|
|
3580
3513
|
* Emits a frozen `'ack'` event on every successful match.
|
|
3581
3514
|
*
|
|
3582
|
-
*
|
|
3515
|
+
* **Enhanced acknowledgement mode**
|
|
3583
3516
|
*
|
|
3584
3517
|
* A message whose MSH-15 or MSH-16 is not null asks for the two-part protocol of HL7
|
|
3585
3518
|
* v2.5.1 §2.9, and on a client correlating by control ID this method delivers it: the
|
|
@@ -4666,14 +4599,14 @@ declare function resolveDifferentialPeer(raw: string | undefined | null): Differ
|
|
|
4666
4599
|
* `JSON.stringify` a run straight into a log pipeline or a review artifact and read it
|
|
4667
4600
|
* programmatically without scraping human-readable text.
|
|
4668
4601
|
*
|
|
4669
|
-
*
|
|
4602
|
+
* **What this report is, and what it is not**
|
|
4670
4603
|
*
|
|
4671
4604
|
* It records what was **observed** on the wire. It is not a conformance verdict and never
|
|
4672
4605
|
* becomes one: no field says a peer is conformant, no field says a run passed, and nothing
|
|
4673
4606
|
* here decides whether an interface is fit to carry clinical traffic. That judgement
|
|
4674
4607
|
* belongs to the people standing the interface up, with this evidence in front of them.
|
|
4675
4608
|
*
|
|
4676
|
-
*
|
|
4609
|
+
* **Why no payload content appears anywhere**
|
|
4677
4610
|
*
|
|
4678
4611
|
* A peer answering this harness may be a live engine holding real patients, and a report
|
|
4679
4612
|
* is a diagnostic surface that gets written to a file, pasted into a ticket and mailed to
|
|
@@ -4849,7 +4782,7 @@ interface DifferentialReportPeer {
|
|
|
4849
4782
|
* The differential run: send each canonical message at a peer, read what comes back, and
|
|
4850
4783
|
* report what was observed.
|
|
4851
4784
|
*
|
|
4852
|
-
*
|
|
4785
|
+
* **What it does, exchange by exchange**
|
|
4853
4786
|
*
|
|
4854
4787
|
* One connection per exchange, opened, used and closed. That is deliberate: a peer that
|
|
4855
4788
|
* refuses or drops one connection then costs one exchange rather than the whole run, which
|
|
@@ -4862,14 +4795,14 @@ interface DifferentialReportPeer {
|
|
|
4862
4795
|
* that deviates from the block is described by the stable warning code for that deviation
|
|
4863
4796
|
* rather than killing the run with an opaque error.
|
|
4864
4797
|
*
|
|
4865
|
-
*
|
|
4798
|
+
* **What byte parity means here**
|
|
4866
4799
|
*
|
|
4867
4800
|
* The MLLP **envelope** the peer emitted, compared against the canonical Release 1 block
|
|
4868
4801
|
* this package emits for the same payload. It is not equality of message content, which
|
|
4869
4802
|
* can never hold: an acknowledgement carries the peer's own control ID, its own timestamp
|
|
4870
4803
|
* and its own sending application, and it is supposed to.
|
|
4871
4804
|
*
|
|
4872
|
-
*
|
|
4805
|
+
* **Aim it with care**
|
|
4873
4806
|
*
|
|
4874
4807
|
* A run sends real bytes into whatever engine it is pointed at. Those bytes are synthetic
|
|
4875
4808
|
* patients, so an engine that accepts them stores synthetic patients. Point it at a test
|
|
@@ -4981,5 +4914,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
|
|
|
4981
4914
|
*/
|
|
4982
4915
|
declare const VERSION: string;
|
|
4983
4916
|
|
|
4984
|
-
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer,
|
|
4985
|
-
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta,
|
|
4917
|
+
export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, tlsConfigurationMessage };
|
|
4918
|
+
export type { AckCode, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
|