@cosyte/mllp 0.1.14 → 0.1.16
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 +31 -0
- package/README.md +16 -8
- package/TRADEMARKS.md +5 -5
- package/dist/ack-from-hl7/index.cjs +13 -14
- package/dist/ack-from-hl7/index.cjs.map +1 -1
- package/dist/ack-from-hl7/index.d.cts +3 -1
- package/dist/ack-from-hl7/index.d.ts +3 -1
- package/dist/ack-from-hl7/index.mjs +6 -5
- package/dist/ack-from-hl7/index.mjs.map +1 -1
- package/dist/arbitraries/index.cjs +23 -31
- package/dist/arbitraries/index.cjs.map +1 -1
- package/dist/arbitraries/index.d.cts +6 -4
- package/dist/arbitraries/index.d.ts +6 -4
- package/dist/arbitraries/index.mjs +7 -15
- package/dist/arbitraries/index.mjs.map +1 -1
- package/dist/index.cjs +350 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +244 -99
- package/dist/index.d.ts +244 -99
- package/dist/index.mjs +320 -111
- package/dist/index.mjs.map +1 -1
- package/dist/{registry-CyGU_l8N.d.cts → registry-BPOSRmcX.d.cts} +2 -2
- package/dist/{registry-CyGU_l8N.d.ts → registry-BPOSRmcX.d.ts} +2 -2
- package/dist/testing/index.cjs +3 -1
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +3 -2
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.mjs +2 -0
- package/dist/testing/index.mjs.map +1 -1
- package/dist/{index-CD8V2Mtk.d.cts → transport-2Zo_VBmG.d.cts} +3 -16
- package/dist/{index-CD8V2Mtk.d.ts → transport-2Zo_VBmG.d.ts} +3 -16
- package/package.json +21 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.16
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- b61fc13: The doc comments in the published type declarations no longer cite our internal tracking ids or a file outside the package; each says in words what the code does.
|
|
7
|
+
|
|
8
|
+
The comment on `getStats().warningsByCode` now also says that the code set may grow in any release, so a caller keeps a default branch, and that removing or renaming a code is a change a caller must act on. No behavior changes.
|
|
9
|
+
- 2d5d616: The optional peer range on `@cosyte/hl7`, which only `@cosyte/mllp/ack-from-hl7` uses, is now `^0.1.5`, the release our tests run against; it was `>=0.0.0`, which admitted versions nothing had tested.
|
|
10
|
+
|
|
11
|
+
What a caller must change: if you use `@cosyte/mllp/ack-from-hl7` with a `@cosyte/hl7` older than 0.1.5, upgrade `@cosyte/hl7` to 0.1.5 or later on the 0.1 line.
|
|
12
|
+
- df61625: The README now tells you to pin an exact version of `@cosyte/mllp` (`pnpm add --save-exact @cosyte/mllp`) and read the changelog before upgrading, since every release is a patch and a patch may carry a change you must act on.
|
|
13
|
+
|
|
14
|
+
The doc comment on the warning code registry no longer says new codes arrive only in minor versions: the set is open, a code may be added in any release, and renaming or removing one is a change a caller must act on.
|
|
15
|
+
- edfb070: The properties of `ServerOptions`, `StarterServerOptions`, `ConnectionOptions`, `FrameReaderOptions`, and `EncoderOptions` are now `readonly` in the type declarations, and the optional last parameter of `encodeFrame`, `Connection.close`, `MllpServer.close`, `MllpClient.connect`, `MllpClient.send`, and `MllpClient.close` is named `options` and defaults to `{}`; calls behave as before.
|
|
16
|
+
|
|
17
|
+
The source now imports `Buffer` from `node:buffer` everywhere it uses it, instead of reading the global, so the declarations name it the same way.
|
|
18
|
+
|
|
19
|
+
What a caller must change: TypeScript code that assigns to a property of one of those options objects after creating it must build the object with every property in place instead, for example with a spread.
|
|
20
|
+
- ad0d8ac: The names table in `TRADEMARKS.md` is now aligned by the formatter; its words are unchanged.
|
|
21
|
+
- 30f5796: The subpaths `@cosyte/mllp/testing`, `@cosyte/mllp/ack-from-hl7`, and `@cosyte/mllp/arbitraries` now resolve their types for a TypeScript project that uses the older `node` (node10) module resolution, through a `typesVersions` map in `package.json`; before, such a project found no types for them.
|
|
22
|
+
- fe4980b: The doc comment on `VERSION` now names `cosyte-process sync-version` as the step that keeps it equal to the package version; the value and its type are unchanged.
|
|
23
|
+
|
|
24
|
+
## 0.1.15
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 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.
|
|
28
|
+
- 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`.
|
|
29
|
+
- 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.
|
|
30
|
+
- 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.
|
|
31
|
+
|
|
32
|
+
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.
|
|
33
|
+
|
|
3
34
|
## 0.1.14
|
|
4
35
|
### Patch Changes
|
|
5
36
|
|
package/README.md
CHANGED
|
@@ -71,6 +71,9 @@ pnpm add @cosyte/mllp
|
|
|
71
71
|
pnpm add @cosyte/hl7
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
Every release is a patch, and a patch may carry a change you must act on, so pin an exact version
|
|
75
|
+
(`pnpm add --save-exact @cosyte/mllp`) and read the changelog before you move to a newer one.
|
|
76
|
+
|
|
74
77
|
Node.js 22 or later, tested on 22, 24, and 26 (`engines.node` is `>=22.0.0`). The package ships
|
|
75
78
|
dual ESM (`import`) and CommonJS (`require`) builds, each with its own type declarations, and has
|
|
76
79
|
zero runtime dependencies. The optional `@cosyte/mllp/arbitraries` entry point, fast-check
|
|
@@ -111,7 +114,8 @@ const msa = ack
|
|
|
111
114
|
.split("\r")
|
|
112
115
|
.find((segment) => segment.startsWith("MSA|"))
|
|
113
116
|
?.split("|");
|
|
114
|
-
|
|
117
|
+
const code = msa?.[1];
|
|
118
|
+
console.log("acknowledgement code:", code);
|
|
115
119
|
console.log("MSA-2 echoes the control id sent:", msa?.[2] === "CTRL0001");
|
|
116
120
|
console.log("messages committed:", committed.length);
|
|
117
121
|
|
|
@@ -171,10 +175,11 @@ receiver must never send one before the message is durably handled, or the messa
|
|
|
171
175
|
**awaits your handler and only then acknowledges**.
|
|
172
176
|
|
|
173
177
|
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
|
-
|
|
178
|
+
acknowledgment** (no readable `MSH`, an empty `MSH-10`, or a batch or concatenated payload). In that
|
|
179
|
+
case the commit still happened, but the acknowledgment is downgraded to `AE` and a `nack` event names
|
|
180
|
+
the reason, because a positive acknowledgment the sender cannot match is one it will resend. A frame
|
|
181
|
+
with a stray `VT` or `FS` inside it never reaches your handler: it is refused whole with a coded
|
|
182
|
+
error and the connection closes. Handler throws, you get `AE`, or `AR` via `MllpAckError`.
|
|
178
183
|
`autoAck: 'AA'` _without_ a handler is documented as a transport-accept: "received and framed", not
|
|
179
184
|
"processed".
|
|
180
185
|
|
|
@@ -350,8 +355,11 @@ bounded segment reads above it does not inspect it. It writes nothing to disk: t
|
|
|
350
355
|
write-ahead log, no replay store, and no cache anywhere in this package. Library code calls no logger
|
|
351
356
|
and no `console` method.
|
|
352
357
|
|
|
353
|
-
**What its diagnostics can carry.** Shape rather than content: no error, warning,
|
|
354
|
-
|
|
358
|
+
**What its diagnostics can carry.** Shape rather than content: no error, warning, stats object or
|
|
359
|
+
event payload ever echoes a run of message content, except the `message` and `ack` events and the
|
|
360
|
+
`onCommitAck` report, which hand you a message or an acknowledgment by design. The
|
|
361
|
+
[options page](https://github.com/cosyte/mllp/blob/main/docs-content/options-and-events.md#what-is-safe-to-log)
|
|
362
|
+
says, field by field, what is safe to log.
|
|
355
363
|
|
|
356
364
|
- A **framing error** carries at most the single byte at the structural violation, plus that byte's
|
|
357
365
|
offset.
|
|
@@ -398,7 +406,7 @@ pnpm test
|
|
|
398
406
|
pnpm format:check
|
|
399
407
|
pnpm check:no-emdash
|
|
400
408
|
pnpm check:no-internal-refs
|
|
401
|
-
pnpm check:documents # the README, CLAUDE.md
|
|
409
|
+
pnpm check:documents # the README, CLAUDE.md, catalog line and docs-content
|
|
402
410
|
pnpm phi-scan
|
|
403
411
|
pnpm build
|
|
404
412
|
pnpm changeset # every meaningful change carries one
|
package/TRADEMARKS.md
CHANGED
|
@@ -21,11 +21,11 @@ including an explicit statement that Epic and Cerner are **not** part of the har
|
|
|
21
21
|
|
|
22
22
|
## Names referenced
|
|
23
23
|
|
|
24
|
-
| Name
|
|
25
|
-
|
|
|
26
|
-
| Mirth Connect, NextGen
|
|
27
|
-
| Google Cloud Healthcare
|
|
28
|
-
| Epic, Cerner
|
|
24
|
+
| Name | Where it appears |
|
|
25
|
+
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| Mirth Connect, NextGen | Named as an engine in the differential test harness. |
|
|
27
|
+
| Google Cloud Healthcare | Named as an engine in the differential test harness (the MLLP adapter). |
|
|
28
|
+
| Epic, Cerner | Named in `docs-content/limitations.md` to record that this package is **not** differentially verified against them. |
|
|
29
29
|
| HAPI, python-hl7, simple-hl7 | Named in `docs-content/coming-from-an-engine.md`, in the table that maps their listener and acknowledgment settings to ours. |
|
|
30
30
|
|
|
31
31
|
All product names, logos, and brands are the property of their respective owners. Use of a name here
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var buffer = require('buffer');
|
|
3
4
|
var module$1 = require('module');
|
|
4
5
|
|
|
5
6
|
// node_modules/.pnpm/tsup@9.0.0_postcss@8.5.32_tsx@4.23.15_typescript@5.9.3_yaml@2.9.1/node_modules/tsup/assets/cjs_shims.js
|
|
@@ -10,8 +11,6 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
|
10
11
|
var VT = 11;
|
|
11
12
|
var FS = 28;
|
|
12
13
|
var CR = 13;
|
|
13
|
-
|
|
14
|
-
// src/framing/error.ts
|
|
15
14
|
var MAX_SNIPPET_BYTES = 64;
|
|
16
15
|
var MllpFramingError = class _MllpFramingError extends Error {
|
|
17
16
|
name = "MllpFramingError";
|
|
@@ -46,7 +45,7 @@ var MllpFramingError = class _MllpFramingError extends Error {
|
|
|
46
45
|
super(message ?? `MLLP framing error: ${code} at byte offset ${byteOffset}`);
|
|
47
46
|
this.code = code;
|
|
48
47
|
this.byteOffset = byteOffset;
|
|
49
|
-
this.snippet = Buffer.from(snippet.subarray(0, MAX_SNIPPET_BYTES));
|
|
48
|
+
this.snippet = buffer.Buffer.from(snippet.subarray(0, MAX_SNIPPET_BYTES));
|
|
50
49
|
if (Error.captureStackTrace) {
|
|
51
50
|
Error.captureStackTrace(this, _MllpFramingError);
|
|
52
51
|
}
|
|
@@ -65,9 +64,9 @@ function createWarning(code, byteOffset, message) {
|
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
// src/framing/encoder.ts
|
|
68
|
-
function encodeFrame(payload,
|
|
69
|
-
const allow =
|
|
70
|
-
const onWarning =
|
|
67
|
+
function encodeFrame(payload, options = {}) {
|
|
68
|
+
const allow = options.allowDelimiterBytesInPayload === true;
|
|
69
|
+
const onWarning = options.onWarning;
|
|
71
70
|
if (!(payload instanceof Uint8Array)) {
|
|
72
71
|
scanEachByte(payload, allow, onWarning);
|
|
73
72
|
} else if (!allow || onWarning !== void 0) {
|
|
@@ -81,7 +80,7 @@ function encodeFrame(payload, opts) {
|
|
|
81
80
|
else fs = payload.indexOf(FS, i + 1);
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
|
-
const frame = Buffer.allocUnsafe(payload.length + 3);
|
|
83
|
+
const frame = buffer.Buffer.allocUnsafe(payload.length + 3);
|
|
85
84
|
frame[0] = VT;
|
|
86
85
|
payload.copy(frame, 1);
|
|
87
86
|
frame[payload.length + 1] = FS;
|
|
@@ -98,7 +97,7 @@ function scanEachByte(payload, allow, onWarning) {
|
|
|
98
97
|
function delimiterAt(byte, i, allow, onWarning) {
|
|
99
98
|
const code = byte === VT ? "MLLP_PAYLOAD_CONTAINS_VT" : "MLLP_PAYLOAD_CONTAINS_FS";
|
|
100
99
|
if (!allow) {
|
|
101
|
-
throw new MllpFramingError(code, i, Buffer.from([byte]));
|
|
100
|
+
throw new MllpFramingError(code, i, buffer.Buffer.from([byte]));
|
|
102
101
|
}
|
|
103
102
|
if (onWarning !== void 0) {
|
|
104
103
|
const byteHex = byte === VT ? "0x0B" : "0x1C";
|
|
@@ -291,7 +290,7 @@ function assertKnownAckCode(peer, code) {
|
|
|
291
290
|
}
|
|
292
291
|
function resolveEncoding(inbound, options) {
|
|
293
292
|
if (options.encoding !== void 0) return options.encoding;
|
|
294
|
-
return Buffer.isBuffer(inbound) ? BYTES_INBOUND_ENCODING : TEXT_INBOUND_ENCODING;
|
|
293
|
+
return buffer.Buffer.isBuffer(inbound) ? BYTES_INBOUND_ENCODING : TEXT_INBOUND_ENCODING;
|
|
295
294
|
}
|
|
296
295
|
function assertSerializableAckEncoding(encoding) {
|
|
297
296
|
if (SERIALIZABLE_ACK_ENCODINGS.has(encoding.toLowerCase())) return;
|
|
@@ -300,8 +299,8 @@ function assertSerializableAckEncoding(encoding) {
|
|
|
300
299
|
);
|
|
301
300
|
}
|
|
302
301
|
function inboundBytes(inbound, encoding) {
|
|
303
|
-
if (Buffer.isBuffer(inbound)) return inbound;
|
|
304
|
-
if (typeof inbound === "string") return Buffer.from(inbound, encoding);
|
|
302
|
+
if (buffer.Buffer.isBuffer(inbound)) return inbound;
|
|
303
|
+
if (typeof inbound === "string") return buffer.Buffer.from(inbound, encoding);
|
|
305
304
|
return void 0;
|
|
306
305
|
}
|
|
307
306
|
function verifyVerbatimEcho(ackPayload, inboundRaw) {
|
|
@@ -318,7 +317,7 @@ function verifyVerbatimEcho(ackPayload, inboundRaw) {
|
|
|
318
317
|
};
|
|
319
318
|
}
|
|
320
319
|
function verifyTextInboundEcho(controlId, inbound) {
|
|
321
|
-
if (Buffer.isBuffer(inbound)) return null;
|
|
320
|
+
if (buffer.Buffer.isBuffer(inbound)) return null;
|
|
322
321
|
if (controlId === "") return null;
|
|
323
322
|
let hasNonAscii = false;
|
|
324
323
|
for (let i = 0; i < controlId.length; i++) {
|
|
@@ -335,7 +334,7 @@ function verifyTextInboundEcho(controlId, inbound) {
|
|
|
335
334
|
}
|
|
336
335
|
function toMllpAck(params) {
|
|
337
336
|
const { ack, requestedCode, code, correlationId, mode, warnings, options, encoding } = params;
|
|
338
|
-
const payload = Buffer.from(ack.toString(), encoding);
|
|
337
|
+
const payload = buffer.Buffer.from(ack.toString(), encoding);
|
|
339
338
|
const frame = encodeFrame(payload, {
|
|
340
339
|
allowDelimiterBytesInPayload: options.allowDelimiterBytesInPayload ?? false
|
|
341
340
|
});
|
|
@@ -386,7 +385,7 @@ function buildUnparseableFallback(peer, requestedCode, fatalCode, options, encod
|
|
|
386
385
|
});
|
|
387
386
|
}
|
|
388
387
|
function resolveInbound(peer, inbound, encoding) {
|
|
389
|
-
if (Buffer.isBuffer(inbound)) {
|
|
388
|
+
if (buffer.Buffer.isBuffer(inbound)) {
|
|
390
389
|
return peer.parseHL7(stripLeadingSegmentTerminators(inbound).toString(encoding));
|
|
391
390
|
}
|
|
392
391
|
if (typeof inbound === "string") {
|