@cosyte/mllp 0.1.6 → 0.1.8
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 +24 -0
- package/README.md +29 -16
- package/dist/ack-from-hl7/index.cjs +48 -27
- 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 +48 -27
- 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 +276 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -103
- package/dist/index.d.ts +74 -103
- package/dist/index.mjs +276 -82
- 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 +23 -3
|
@@ -62,26 +62,17 @@ function createWarning(code, byteOffset, message) {
|
|
|
62
62
|
function encodeFrame(payload, opts) {
|
|
63
63
|
const allow = opts?.allowDelimiterBytesInPayload === true;
|
|
64
64
|
const onWarning = opts?.onWarning;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
code,
|
|
77
|
-
i,
|
|
78
|
-
`Payload contains ${byte === VT ? "VT" : "FS"} byte (${byteHex}) at offset ${i}; frame will be ambiguous`
|
|
79
|
-
);
|
|
80
|
-
try {
|
|
81
|
-
onWarning(warning);
|
|
82
|
-
} catch {
|
|
83
|
-
}
|
|
84
|
-
}
|
|
65
|
+
if (!(payload instanceof Uint8Array)) {
|
|
66
|
+
scanEachByte(payload, allow, onWarning);
|
|
67
|
+
} else if (!allow || onWarning !== void 0) {
|
|
68
|
+
let vt = payload.indexOf(VT);
|
|
69
|
+
let fs = payload.indexOf(FS);
|
|
70
|
+
while (vt !== -1 || fs !== -1) {
|
|
71
|
+
const isVt = fs === -1 || vt !== -1 && vt < fs;
|
|
72
|
+
const i = isVt ? vt : fs;
|
|
73
|
+
delimiterAt(isVt ? VT : FS, i, allow, onWarning);
|
|
74
|
+
if (isVt) vt = payload.indexOf(VT, i + 1);
|
|
75
|
+
else fs = payload.indexOf(FS, i + 1);
|
|
85
76
|
}
|
|
86
77
|
}
|
|
87
78
|
const frame = Buffer.allocUnsafe(payload.length + 3);
|
|
@@ -91,6 +82,31 @@ function encodeFrame(payload, opts) {
|
|
|
91
82
|
frame[payload.length + 2] = CR;
|
|
92
83
|
return frame;
|
|
93
84
|
}
|
|
85
|
+
function scanEachByte(payload, allow, onWarning) {
|
|
86
|
+
for (let i = 0; i < payload.length; i++) {
|
|
87
|
+
const byte = payload[i];
|
|
88
|
+
if (byte === void 0) break;
|
|
89
|
+
if (byte === VT || byte === FS) delimiterAt(byte, i, allow, onWarning);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function delimiterAt(byte, i, allow, onWarning) {
|
|
93
|
+
const code = byte === VT ? "MLLP_PAYLOAD_CONTAINS_VT" : "MLLP_PAYLOAD_CONTAINS_FS";
|
|
94
|
+
if (!allow) {
|
|
95
|
+
throw new MllpFramingError(code, i, Buffer.from([byte]));
|
|
96
|
+
}
|
|
97
|
+
if (onWarning !== void 0) {
|
|
98
|
+
const byteHex = byte === VT ? "0x0B" : "0x1C";
|
|
99
|
+
const warning = createWarning(
|
|
100
|
+
code,
|
|
101
|
+
i,
|
|
102
|
+
`Payload contains ${byte === VT ? "VT" : "FS"} byte (${byteHex}) at offset ${i}; frame will be ambiguous`
|
|
103
|
+
);
|
|
104
|
+
try {
|
|
105
|
+
onWarning(warning);
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
94
110
|
|
|
95
111
|
// src/internal/control-id.ts
|
|
96
112
|
var ASCII_M = 77;
|
|
@@ -111,17 +127,22 @@ var UNSAFE_FIELD_SEPARATORS = /* @__PURE__ */ new Set([
|
|
|
111
127
|
function isMshSegmentAt(buf, i) {
|
|
112
128
|
return i + 3 < buf.length && buf[i] === ASCII_M && buf[i + 1] === ASCII_S && buf[i + 2] === ASCII_H && !UNSAFE_FIELD_SEPARATORS.has(buf[i + 3]);
|
|
113
129
|
}
|
|
114
|
-
function
|
|
115
|
-
let
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
130
|
+
function segmentEnds(buf) {
|
|
131
|
+
let cr = -2;
|
|
132
|
+
let lf = -2;
|
|
133
|
+
return (i) => {
|
|
134
|
+
if (cr !== -1 && cr < i) cr = buf.indexOf(SEGMENT_SEPARATOR_CR, i);
|
|
135
|
+
if (lf !== -1 && lf < i) lf = buf.indexOf(SEGMENT_SEPARATOR_LF, i);
|
|
136
|
+
const atCr = cr === -1 ? buf.length : cr;
|
|
137
|
+
const atLf = lf === -1 ? buf.length : lf;
|
|
138
|
+
return atCr < atLf ? atCr : atLf;
|
|
139
|
+
};
|
|
120
140
|
}
|
|
121
141
|
function findMshSegment(buf) {
|
|
142
|
+
const segmentEnd = segmentEnds(buf);
|
|
122
143
|
let segStart = 0;
|
|
123
144
|
while (segStart < buf.length) {
|
|
124
|
-
const end = segmentEnd(
|
|
145
|
+
const end = segmentEnd(segStart);
|
|
125
146
|
if (isMshSegmentAt(buf, segStart)) return { start: segStart, end };
|
|
126
147
|
let next = end;
|
|
127
148
|
while (next < buf.length && (buf[next] === SEGMENT_SEPARATOR_CR || buf[next] === SEGMENT_SEPARATOR_LF)) {
|