@cosyte/mllp 0.1.14 → 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 +10 -0
- package/README.md +13 -8
- 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.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 +279 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +183 -43
- package/dist/index.d.ts +183 -43
- package/dist/index.mjs +279 -63
- 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,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 0.1.14
|
|
4
14
|
### Patch Changes
|
|
5
15
|
|
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
|