@cosyte/mllp 0.1.13 → 0.1.15
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 +16 -0
- package/README.md +13 -8
- package/dist/ack-from-hl7/index.cjs +5 -2
- package/dist/ack-from-hl7/index.cjs.map +1 -1
- package/dist/ack-from-hl7/index.d.cts +2 -1
- package/dist/ack-from-hl7/index.d.ts +2 -1
- package/dist/ack-from-hl7/index.mjs +5 -2
- package/dist/ack-from-hl7/index.mjs.map +1 -1
- package/dist/arbitraries/index.cjs +6 -15
- package/dist/arbitraries/index.cjs.map +1 -1
- package/dist/arbitraries/index.d.cts +5 -4
- package/dist/arbitraries/index.d.ts +5 -4
- package/dist/arbitraries/index.mjs +6 -15
- package/dist/arbitraries/index.mjs.map +1 -1
- package/dist/index.cjs +364 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +260 -46
- package/dist/index.d.ts +260 -46
- package/dist/index.mjs +364 -70
- package/dist/index.mjs.map +1 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.15
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- e687245: **A frame delivered before a refused one is still acknowledged before the connection closes, so the sender does not resend a message already committed.** When a good frame and a frame with a fatal framing error arrived in the same read (a sender that writes its next frame before the previous acknowledgment arrives), the good frame reached the handler but the connection closed at once on the error, before the acknowledgment went out, even for a synchronous handler; the sender resent the message and it was processed twice. Now, on a fatal framing error, the connection reads nothing more, moves to `DRAINING`, waits for every delivered frame's handler to settle and its acknowledgment to be written (`AA`, a negative ACK for a handler that throws, a custom builder's bytes, or a manual-mode handler's own `send`), then moves to `CLOSED` and ends the socket gracefully. The wait is bounded by `drainTimeoutMs` (30 seconds by default, `ServerOptions.drainTimeoutMs` on a server): a handler still running then is abandoned and the socket destroyed, so a handler that never settles cannot hold the connection open. With nothing running, the connection is destroyed at once as before. New: `Connection.holdOpenFor(work)` registers the work answering a delivered frame; `MllpServer` calls it for every message, and a caller driving a bare `Connection` may call it too. What a caller sees: on a server with a handler still running, a fatal framing error now shows `CONNECTED` to `DRAINING` to `CLOSED` on `'stateChange'` instead of `CONNECTED` to `CLOSED`, and the `'close'` event comes once the answers are out.
|
|
7
|
+
- 7d4a5ff: **`server.close()` waits for the handlers still running and sends their ACKs before it closes each connection, so a graceful shutdown no longer makes the sender resend a message already committed.** A shutdown during a slow `onMessage` commit used to end the connection at once: the handler finished its commit, but its ACK was never sent, the sender resent the message, and it was processed twice. Now `close()` reads nothing more on each connection (bytes a sender writes from then on are dropped unread, so no new message reaches a handler), waits for every handler still running and the ACK it writes (`AA`, a negative ACK for a handler that rejects, a custom builder's bytes), then ends the socket gracefully. In manual mode the wait lasts until the handler's promise settles, so send the ACK before the handler returns or resolves. In custom-ACK mode the `onMessage` observer is not waited for, since it writes no ACK. A connection accepted after `close()` began (a TLS handshake that finished during the wait) is closed at once, unread. The wait is bounded by `drainTimeoutMs` (30 seconds by default): work still running then is abandoned, its connection destroyed, and an `MllpConnectionError` with `phase: 'close'` on `'error'` counts per message how many were delivered without their ACK being sent, how many manual-mode handlers may not have sent theirs, and, separately, how many observers were still running. The same report is made when the sender closes or half-closes the connection before that work settles, since its ACK can then not reach it. An ACK whose handler settles after its connection has closed is now reported as `ACK not sent: the connection closed before the handler settled`, no longer as socket backpressure. On a bare `Connection`, `close()` now also waits for the work passed to `holdOpenFor()`, which takes a new optional `{ kind: 'ack' | 'manual' | 'observer' }` saying what that work owes the peer (`'ack'` by default, as before; `close()` does not wait for an `'observer'`), and the new `stopReading()` drops every byte that arrives from then on. What a caller sees: `server.close()` takes as long as the slowest handler still running, up to `drainTimeoutMs`.
|
|
8
|
+
- a50eeea: **The docs now say, field by field, what is safe to log from a live link, and no example prints a whole message, an acknowledgment or a control id read off the wire.** A new "What is safe to log" section on the options page names, for every event, hook, error and report (the shutdown report included), the fields that can hold message bytes (the `message` and `ack` events' `payload`, the `ack` event's `controlId`, the `onCommitAck` report's `payload`, a framing error's one-byte `snippet`, and an `ack-from-hl7` result's `frame`, `payload`, `ack` and `correlationId`) and the fields that hold only codes, counts, byte lengths, offsets and times. Four API reference samples printed message content and now print a length or a code instead: `client.send()` logged the whole acknowledgment, the `InMemoryTransport` samples printed raw chunks, and the `MllpAck` sample printed the echoed control id. The README and the reliability page no longer say that no event payload carries message content, which the `message` and `ack` events do by design, and the options page now gives the `error` event's payload as it is: `{ connectionId, error }` on a client and for a connection's error on a server.
|
|
9
|
+
- db74c6a: **A frame with a stray `FS` or `VT` inside it is refused whole, so no message in it is lost or left unacknowledged without a word.** Two messages joined by a bare `FS` inside one frame used to reach a default server's handler as the first message, after which the reader threw on the second and the connection closed before the first could be acknowledged; the sender resent it, and the second was never read. Joined by a `VT`, the first was dropped and the second handed to the handler and committed under an `AE`. Now `FrameReader` delivers nothing from such a frame and throws an `MllpFramingError` coded `MLLP_PAYLOAD_CONTAINS_VT` (a `VT` inside a frame, whatever the tolerances) or `MLLP_PAYLOAD_CONTAINS_FS` (with `allowFsOnly`, an `FS` that no `CR`, `LF` or next `VT` follows), whose `byteOffset` is the stray byte's own offset, whose `snippet` is that one framing byte and whose `message` holds no payload byte. On a server or a client that arrives on `'error'` with `connectionCause: 'framing-fatal'`, and the connection closes with no acknowledgment sent; the outcome is the same however the frame is split across reads. An `FS` followed by the next frame's `VT` is still two frames, both delivered and acknowledged in order. What a caller sees: frames that used to be delivered as a fragment (`MLLP_TRAILING_BYTES`, answered `AE` with the `nack` reason `'discarded-bytes'`), or delivered with the byte after a bare `FS` dropped, now close the connection with one of those codes instead; `MLLP_TRAILING_BYTES` and `'discarded-bytes'` stay in their types but are no longer raised or sent. From `@cosyte/mllp/arbitraries`, `messyStream()` no longer generates a frame with a `VT` or a bare `FS` inside it, since no reader accepts one.
|
|
10
|
+
|
|
11
|
+
What a caller must change: code that alerts on `MLLP_TRAILING_BYTES`, or on a `nack` reason of `'discarded-bytes'`, for a frame with a stray `FS` or `VT` alerts on `MLLP_PAYLOAD_CONTAINS_VT` and `MLLP_PAYLOAD_CONTAINS_FS` on the `'error'` event instead.
|
|
12
|
+
|
|
13
|
+
## 0.1.14
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 660fcf7: **An acknowledgment or message that starts with a UTF-8 byte order mark is now read.** Some engines write `EF BB BF` before the `MSH` when they encode a message as UTF-8. Before this, the mark hid the `MSH`, so a healthy acknowledgment behind one could not be matched by control ID under `correlateByControlId: true`, and in FIFO mode it drew the `MLLP_ACK_FIFO_MSA1_UNREADABLE` warning (or rejected the send under `fifoUnreadableAck: "reject"`); on the server, a positive auto-ACK for an inbound message behind one was downgraded to `AE` with an empty MSA-2, and `buildRawAck` and `rawAckUncorrelatable` did the same. Now a whole mark at byte 0 is skipped for reading the `MSH`, MSA-1 and MSA-2 in both client modes and on the server, so those acknowledgments settle their sends with no warning and those messages get an `AA` that echoes MSH-10. The bytes handed to the caller stay exactly as received, mark included. A mark anywhere else (after a leading `CR`, a second mark, or part of one) still hides the `MSH`, as before. Nothing for a caller to change: a handler that counted on the `AE` downgrade for such a message now sees `AA`.
|
|
17
|
+
- d3ebc5d: **A client correlating in order no longer settles a send on a frame that is not an acknowledgment without saying so.** In FIFO mode, the default, the oldest pending send is settled by whatever frame arrives next, and before this a lone `0x06` or `0x15` byte, an `MSH` with no `MSA`, or an MSA-1 outside HL7 Table 0008 resolved `send()` with no signal at all. Now the client emits the `'warning'` `MLLP_ACK_FIFO_MSA1_UNREADABLE` (an `AckModeWarning` carrying `msa1Bytes` and `byteOffset`, never field content) whenever the frame that settles a send has no readable MSA-1. What a caller sees by default: `send()` still resolves with the frame, exactly as before, plus that one warning; a `'warning'` handler that checks for an exhaustive set of codes has to allow the new one. What a caller may change: the new client option `fifoUnreadableAck: "reject"` (also on `createStarterClient`) makes such a send reject with the new `MllpUnreadableAckError` instead, whose `msa1Bytes`, `byteOffset` and `elapsedMs` are numbers only; the frame still takes that send's turn, so the next send settles on the next frame. `fifoUnreadableAck` takes `"warn"` (the default) or `"reject"`, and any other value throws a `TypeError` at construction. With `correlateByControlId: true` nothing changes: such a frame matches no send and settles nothing, and correlating by control ID remains what we recommend whenever the peer echoes MSH-10 in MSA-2.
|
|
18
|
+
|
|
3
19
|
## 0.1.13
|
|
4
20
|
### Patch Changes
|
|
5
21
|
|
package/README.md
CHANGED
|
@@ -111,7 +111,8 @@ const msa = ack
|
|
|
111
111
|
.split("\r")
|
|
112
112
|
.find((segment) => segment.startsWith("MSA|"))
|
|
113
113
|
?.split("|");
|
|
114
|
-
|
|
114
|
+
const code = msa?.[1];
|
|
115
|
+
console.log("acknowledgement code:", code);
|
|
115
116
|
console.log("MSA-2 echoes the control id sent:", msa?.[2] === "CTRL0001");
|
|
116
117
|
console.log("messages committed:", committed.length);
|
|
117
118
|
|
|
@@ -171,10 +172,11 @@ receiver must never send one before the message is durably handled, or the messa
|
|
|
171
172
|
**awaits your handler and only then acknowledges**.
|
|
172
173
|
|
|
173
174
|
Handler resolves, you get `AA`, **unless the inbound could not carry a correlatable positive
|
|
174
|
-
acknowledgment** (no readable `MSH`, an empty `MSH-10`, a batch or concatenated payload
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
acknowledgment** (no readable `MSH`, an empty `MSH-10`, or a batch or concatenated payload). In that
|
|
176
|
+
case the commit still happened, but the acknowledgment is downgraded to `AE` and a `nack` event names
|
|
177
|
+
the reason, because a positive acknowledgment the sender cannot match is one it will resend. A frame
|
|
178
|
+
with a stray `VT` or `FS` inside it never reaches your handler: it is refused whole with a coded
|
|
179
|
+
error and the connection closes. Handler throws, you get `AE`, or `AR` via `MllpAckError`.
|
|
178
180
|
`autoAck: 'AA'` _without_ a handler is documented as a transport-accept: "received and framed", not
|
|
179
181
|
"processed".
|
|
180
182
|
|
|
@@ -350,8 +352,11 @@ bounded segment reads above it does not inspect it. It writes nothing to disk: t
|
|
|
350
352
|
write-ahead log, no replay store, and no cache anywhere in this package. Library code calls no logger
|
|
351
353
|
and no `console` method.
|
|
352
354
|
|
|
353
|
-
**What its diagnostics can carry.** Shape rather than content: no error, warning,
|
|
354
|
-
|
|
355
|
+
**What its diagnostics can carry.** Shape rather than content: no error, warning, stats object or
|
|
356
|
+
event payload ever echoes a run of message content, except the `message` and `ack` events and the
|
|
357
|
+
`onCommitAck` report, which hand you a message or an acknowledgment by design. The
|
|
358
|
+
[options page](https://github.com/cosyte/mllp/blob/main/docs-content/options-and-events.md#what-is-safe-to-log)
|
|
359
|
+
says, field by field, what is safe to log.
|
|
355
360
|
|
|
356
361
|
- A **framing error** carries at most the single byte at the structural violation, plus that byte's
|
|
357
362
|
offset.
|
|
@@ -398,7 +403,7 @@ pnpm test
|
|
|
398
403
|
pnpm format:check
|
|
399
404
|
pnpm check:no-emdash
|
|
400
405
|
pnpm check:no-internal-refs
|
|
401
|
-
pnpm check:documents # the README, CLAUDE.md
|
|
406
|
+
pnpm check:documents # the README, CLAUDE.md, catalog line and docs-content
|
|
402
407
|
pnpm phi-scan
|
|
403
408
|
pnpm build
|
|
404
409
|
pnpm changeset # every meaningful change carries one
|
|
@@ -144,9 +144,12 @@ function segmentEnds(buf) {
|
|
|
144
144
|
return atCr < atLf ? atCr : atLf;
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
|
+
function firstSegmentStart(buf) {
|
|
148
|
+
return buf[0] === 239 && buf[1] === 187 && buf[2] === 191 ? 3 : 0;
|
|
149
|
+
}
|
|
147
150
|
function findMshSegment(buf) {
|
|
148
151
|
const segmentEnd = segmentEnds(buf);
|
|
149
|
-
let segStart =
|
|
152
|
+
let segStart = firstSegmentStart(buf);
|
|
150
153
|
while (segStart < buf.length) {
|
|
151
154
|
const end = segmentEnd(segStart);
|
|
152
155
|
if (isMshSegmentAt(buf, segStart)) return { start: segStart, end };
|
|
@@ -192,7 +195,7 @@ function readMsaSegment(buf) {
|
|
|
192
195
|
if (msh === null) return null;
|
|
193
196
|
const fieldSep = msh.fieldSep.charCodeAt(0);
|
|
194
197
|
const end = buf.length;
|
|
195
|
-
let segStart =
|
|
198
|
+
let segStart = firstSegmentStart(buf);
|
|
196
199
|
while (segStart < end) {
|
|
197
200
|
let segEnd = segStart;
|
|
198
201
|
while (segEnd < end && buf[segEnd] !== SEGMENT_SEPARATOR_CR && buf[segEnd] !== SEGMENT_SEPARATOR_LF) {
|