Type Alias: StreamMessageEntry
StreamMessageEntry = {
message:Hl7Message;ok:true;position:Hl7Position;raw:string;streamWarnings: readonlyHl7ParseWarning[]; } | {error:Hl7ParseError;ok:false;position:Hl7Position;raw:string;streamWarnings: readonlyHl7ParseWarning[]; }
One message yielded by parseStream. Discriminated on ok, mirroring
splitBatch's per-message entry: a successful parse carries the
Hl7Message (whose own .warnings hold per-message Tier-2 deviations); a
message that hit one of the four Tier-3 fatals carries the Hl7ParseError
instead: isolated, so the rest of the stream still yields.
raw is the message's verbatim source (re-parseable by parseHL7);
position.segmentIndex is the message's MSH (or, for stray pre-MSH
content, its first) segment index in the overall stream: the streaming
analogue of splitBatch's message position. streamWarnings holds
stream-level diagnostics that are not per-message parse warnings: today
only unterminatedStreamMessage on a final message that lacked a
terminator. It is kept separate from message.warnings (which stays exactly
what a whole-buffer parseHL7 of the same bytes would produce) and is
empty for every message but a possibly-truncated final one. Both the entry
and streamWarnings are frozen.
Example
import { parseStream, WARNING_CODES } from "@cosyte/hl7";
for await (const entry of parseStream(source)) {
for (const w of entry.streamWarnings) {
if (w.code === WARNING_CODES.UNTERMINATED_STREAM_MESSAGE) {
// the feed may have been cut off mid-message
}
}
}