@cosyte/mllp 0.1.6 → 0.1.9

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.
@@ -0,0 +1,86 @@
1
+ /**
2
+ * MLLP warning code registry and `MllpWarning` factory.
3
+ *
4
+ * `WarningCode` is a **stable public API**. Renaming or removing a code is a breaking change.
5
+ * New codes may only be added in minor versions.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { createWarning, type MllpWarning, type WarningCode } from '@cosyte/mllp';
10
+ * const w: MllpWarning = createWarning('MLLP_EMPTY_PAYLOAD', 128, 'Empty payload between VT and FS');
11
+ * ```
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ /**
16
+ * Union of all stable MLLP warning codes.
17
+ *
18
+ * These codes are a **public API**, they appear in `onWarning` handlers, log pipelines,
19
+ * monitoring dashboards, and error messages. Renaming is a breaking change.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const code: WarningCode = 'MLLP_FS_WITHOUT_CR';
24
+ * ```
25
+ */
26
+ type WarningCode = "MLLP_MISSING_LEADING_VT" | "MLLP_FS_WITHOUT_CR" | "MLLP_LF_AFTER_FS" | "MLLP_LEADING_WHITESPACE" | "MLLP_TRAILING_BYTES" | "MLLP_PAYLOAD_CONTAINS_VT" | "MLLP_PAYLOAD_CONTAINS_FS" | "MLLP_EMPTY_PAYLOAD" | "MLLP_FRAME_TOO_LARGE" | "MLLP_ACK_UNMATCHED_CONTROL_ID" | "MLLP_ACK_AFTER_TIMEOUT";
27
+ /**
28
+ * A frozen warning object emitted when the decoder tolerates a framing deviation.
29
+ *
30
+ * `connectionId` is `undefined` when emitted by a standalone `FrameReader`.
31
+ * `Connection` enriches it to the real UUIDv4 before forwarding upstream.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const reader = new FrameReader({
36
+ * onFrame: (p) => process(p),
37
+ * onWarning: (w: MllpWarning) => logger.warn(w),
38
+ * allowFsOnly: true,
39
+ * });
40
+ * ```
41
+ */
42
+ interface MllpWarning {
43
+ readonly code: WarningCode;
44
+ /**
45
+ * Stable human-readable description. It carries structural facts (a byte
46
+ * offset, an accumulated size) and **never a run of payload content**.
47
+ *
48
+ * Two codes carry exactly one input byte, and it is worth knowing which:
49
+ * `MLLP_MISSING_LEADING_VT` and `MLLP_FS_WITHOUT_CR` render the hex of the
50
+ * single byte found where a framing byte was expected, and on a stream that
51
+ * omits its leading `VT` that byte is the first byte of the unframed content.
52
+ * One byte, never a run, the same bound `MllpFramingError.snippet` carries. If
53
+ * that is more than your threat model allows, log `code` and `byteOffset`
54
+ * rather than `message`.
55
+ *
56
+ * The ACK-correlation codes are stricter: their text comes from a frozen
57
+ * registry and does not vary with the wire at all.
58
+ */
59
+ readonly message: string;
60
+ /** Absolute stream byte offset where the anomaly was detected. */
61
+ readonly byteOffset: number;
62
+ /**
63
+ * Connection identifier. `undefined` at the framing layer;
64
+ * enriched by `Connection` before emitting upstream.
65
+ */
66
+ readonly connectionId: string | undefined;
67
+ /** Wall-clock time at point of emission. */
68
+ readonly timestamp: Date;
69
+ }
70
+ /**
71
+ * Create a frozen `MllpWarning` object. The returned object is `Object.freeze()`'d
72
+ * so subscribers cannot mutate shared warning state.
73
+ *
74
+ * `connectionId` is always `undefined` here; `Connection` enriches it via
75
+ * `{ ...w, connectionId: this.connectionId }` then re-freezes.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const w = createWarning('MLLP_EMPTY_PAYLOAD', 64, 'Empty payload between VT and FS');
80
+ * // w.connectionId === undefined
81
+ * ```
82
+ */
83
+ declare function createWarning(code: WarningCode, byteOffset: number, message: string): MllpWarning;
84
+
85
+ export { createWarning as c };
86
+ export type { MllpWarning as M, WarningCode as W };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * MLLP warning code registry and `MllpWarning` factory.
3
+ *
4
+ * `WarningCode` is a **stable public API**. Renaming or removing a code is a breaking change.
5
+ * New codes may only be added in minor versions.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { createWarning, type MllpWarning, type WarningCode } from '@cosyte/mllp';
10
+ * const w: MllpWarning = createWarning('MLLP_EMPTY_PAYLOAD', 128, 'Empty payload between VT and FS');
11
+ * ```
12
+ *
13
+ * @packageDocumentation
14
+ */
15
+ /**
16
+ * Union of all stable MLLP warning codes.
17
+ *
18
+ * These codes are a **public API**, they appear in `onWarning` handlers, log pipelines,
19
+ * monitoring dashboards, and error messages. Renaming is a breaking change.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const code: WarningCode = 'MLLP_FS_WITHOUT_CR';
24
+ * ```
25
+ */
26
+ type WarningCode = "MLLP_MISSING_LEADING_VT" | "MLLP_FS_WITHOUT_CR" | "MLLP_LF_AFTER_FS" | "MLLP_LEADING_WHITESPACE" | "MLLP_TRAILING_BYTES" | "MLLP_PAYLOAD_CONTAINS_VT" | "MLLP_PAYLOAD_CONTAINS_FS" | "MLLP_EMPTY_PAYLOAD" | "MLLP_FRAME_TOO_LARGE" | "MLLP_ACK_UNMATCHED_CONTROL_ID" | "MLLP_ACK_AFTER_TIMEOUT";
27
+ /**
28
+ * A frozen warning object emitted when the decoder tolerates a framing deviation.
29
+ *
30
+ * `connectionId` is `undefined` when emitted by a standalone `FrameReader`.
31
+ * `Connection` enriches it to the real UUIDv4 before forwarding upstream.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const reader = new FrameReader({
36
+ * onFrame: (p) => process(p),
37
+ * onWarning: (w: MllpWarning) => logger.warn(w),
38
+ * allowFsOnly: true,
39
+ * });
40
+ * ```
41
+ */
42
+ interface MllpWarning {
43
+ readonly code: WarningCode;
44
+ /**
45
+ * Stable human-readable description. It carries structural facts (a byte
46
+ * offset, an accumulated size) and **never a run of payload content**.
47
+ *
48
+ * Two codes carry exactly one input byte, and it is worth knowing which:
49
+ * `MLLP_MISSING_LEADING_VT` and `MLLP_FS_WITHOUT_CR` render the hex of the
50
+ * single byte found where a framing byte was expected, and on a stream that
51
+ * omits its leading `VT` that byte is the first byte of the unframed content.
52
+ * One byte, never a run, the same bound `MllpFramingError.snippet` carries. If
53
+ * that is more than your threat model allows, log `code` and `byteOffset`
54
+ * rather than `message`.
55
+ *
56
+ * The ACK-correlation codes are stricter: their text comes from a frozen
57
+ * registry and does not vary with the wire at all.
58
+ */
59
+ readonly message: string;
60
+ /** Absolute stream byte offset where the anomaly was detected. */
61
+ readonly byteOffset: number;
62
+ /**
63
+ * Connection identifier. `undefined` at the framing layer;
64
+ * enriched by `Connection` before emitting upstream.
65
+ */
66
+ readonly connectionId: string | undefined;
67
+ /** Wall-clock time at point of emission. */
68
+ readonly timestamp: Date;
69
+ }
70
+ /**
71
+ * Create a frozen `MllpWarning` object. The returned object is `Object.freeze()`'d
72
+ * so subscribers cannot mutate shared warning state.
73
+ *
74
+ * `connectionId` is always `undefined` here; `Connection` enriches it via
75
+ * `{ ...w, connectionId: this.connectionId }` then re-freezes.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const w = createWarning('MLLP_EMPTY_PAYLOAD', 64, 'Empty payload between VT and FS');
80
+ * // w.connectionId === undefined
81
+ * ```
82
+ */
83
+ declare function createWarning(code: WarningCode, byteOffset: number, message: string): MllpWarning;
84
+
85
+ export { createWarning as c };
86
+ export type { MllpWarning as M, WarningCode as W };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosyte/mllp",
3
- "version": "0.1.6",
3
+ "version": "0.1.9",
4
4
  "description": "MLLP transport for HL7 v2 in Node.js and TypeScript: client and server, framing, ACK correlation, auto-reconnect, TLS, and an in-memory transport for tests.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -25,7 +25,9 @@
25
25
  "interoperability",
26
26
  "tcp",
27
27
  "tls",
28
- "typescript"
28
+ "typescript",
29
+ "client",
30
+ "server"
29
31
  ],
30
32
  "files": [
31
33
  "dist",
@@ -69,6 +71,16 @@
69
71
  "default": "./dist/ack-from-hl7/index.cjs"
70
72
  }
71
73
  },
74
+ "./arbitraries": {
75
+ "import": {
76
+ "types": "./dist/arbitraries/index.d.ts",
77
+ "default": "./dist/arbitraries/index.mjs"
78
+ },
79
+ "require": {
80
+ "types": "./dist/arbitraries/index.d.cts",
81
+ "default": "./dist/arbitraries/index.cjs"
82
+ }
83
+ },
72
84
  "./package.json": "./package.json"
73
85
  },
74
86
  "publishConfig": {
@@ -77,20 +89,25 @@
77
89
  },
78
90
  "prettier": "@cosyte/prettier-config",
79
91
  "peerDependencies": {
80
- "@cosyte/hl7": ">=0.0.0"
92
+ "@cosyte/hl7": ">=0.0.0",
93
+ "fast-check": "^4.0.0"
81
94
  },
82
95
  "peerDependenciesMeta": {
83
96
  "@cosyte/hl7": {
84
97
  "optional": true
98
+ },
99
+ "fast-check": {
100
+ "optional": true
85
101
  }
86
102
  },
87
103
  "devDependencies": {
88
104
  "@arethetypeswrong/cli": "0.18.5",
89
105
  "@changesets/cli": "2.31.0",
106
+ "@cosyte/bench": "^0.1.1",
90
107
  "@cosyte/eslint-config": "^0.1.4",
91
108
  "@cosyte/hl7": "^0.1.0",
92
109
  "@cosyte/prettier-config": "^0.1",
93
- "@cosyte/process": "^0.1.6",
110
+ "@cosyte/process": "^0.1.7",
94
111
  "@cosyte/script-utils": "^0.1.8",
95
112
  "@cosyte/test-utils": "^0.1.3",
96
113
  "@cosyte/tsconfig": "^0.1",
@@ -129,8 +146,13 @@
129
146
  "test": "cosyte-process test",
130
147
  "test:watch": "cosyte-process test --watch",
131
148
  "test:coverage": "cosyte-process test --coverage",
149
+ "test:perf": "vitest run --config vitest.perf.config.ts",
132
150
  "fuzz": "vitest run test/property/fuzz.property.test.ts test/property/transport-fuzz.property.test.ts test/property/ack-fuzz.property.test.ts",
133
151
  "examples": "tsx scripts/run-examples.ts",
152
+ "bench:reading": "cosyte-bench run --suite bench/mllp.bench.mjs --target dist/index.mjs",
153
+ "bench:compare": "cosyte-bench compare --suite bench/mllp.bench.mjs",
154
+ "bench:profile": "node bench/profile.mjs",
155
+ "bench:socket": "node --expose-gc bench/socket.mjs",
134
156
  "certs:gen": "node scripts/generate-test-certs.mjs",
135
157
  "clean": "rm -rf dist coverage",
136
158
  "attw": "cosyte-attw",