@cosyte/mllp 0.1.5 → 0.1.7

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 };
@@ -1,4 +1,4 @@
1
- import { T as Transport } from '../index-CD8V2Mtk.cjs';
1
+ import { Transport } from '../index.cjs';
2
2
 
3
3
  /**
4
4
  * InMemoryTransport, deterministic, socket-free Transport for tests.
@@ -1,4 +1,4 @@
1
- import { T as Transport } from '../index-CD8V2Mtk.js';
1
+ import { Transport } from '../index.js';
2
2
 
3
3
  /**
4
4
  * InMemoryTransport, deterministic, socket-free Transport for tests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosyte/mllp",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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": {
@@ -69,6 +69,16 @@
69
69
  "default": "./dist/ack-from-hl7/index.cjs"
70
70
  }
71
71
  },
72
+ "./arbitraries": {
73
+ "import": {
74
+ "types": "./dist/arbitraries/index.d.ts",
75
+ "default": "./dist/arbitraries/index.mjs"
76
+ },
77
+ "require": {
78
+ "types": "./dist/arbitraries/index.d.cts",
79
+ "default": "./dist/arbitraries/index.cjs"
80
+ }
81
+ },
72
82
  "./package.json": "./package.json"
73
83
  },
74
84
  "publishConfig": {
@@ -77,67 +87,69 @@
77
87
  },
78
88
  "prettier": "@cosyte/prettier-config",
79
89
  "peerDependencies": {
80
- "@cosyte/hl7": ">=0.0.0"
90
+ "@cosyte/hl7": ">=0.0.0",
91
+ "fast-check": "^4.0.0"
81
92
  },
82
93
  "peerDependenciesMeta": {
83
94
  "@cosyte/hl7": {
84
95
  "optional": true
96
+ },
97
+ "fast-check": {
98
+ "optional": true
85
99
  }
86
100
  },
87
101
  "devDependencies": {
88
102
  "@arethetypeswrong/cli": "0.18.5",
89
103
  "@changesets/cli": "2.31.0",
90
- "@cosyte/eslint-config": "^0.1",
104
+ "@cosyte/eslint-config": "^0.1.4",
91
105
  "@cosyte/hl7": "^0.1.0",
92
106
  "@cosyte/prettier-config": "^0.1",
93
- "@cosyte/script-utils": "^0.1.7",
94
- "@cosyte/test-utils": "^0.1",
107
+ "@cosyte/process": "^0.1.7",
108
+ "@cosyte/script-utils": "^0.1.8",
109
+ "@cosyte/test-utils": "^0.1.3",
95
110
  "@cosyte/tsconfig": "^0.1",
96
- "@cosyte/tsup-config": "^0.1",
111
+ "@cosyte/tsup-config": "^0.1.3",
97
112
  "@cosyte/vitest-config": "^0.1",
98
113
  "@types/node": "^22.0.0",
99
114
  "@types/node-forge": "1.3.14",
100
- "@vitest/coverage-v8": "4.1.12",
101
- "eslint": "10.14.0",
102
115
  "fast-check": "4.10.2",
103
116
  "node-forge": "1.4.1",
104
- "prettier": "3.9.10",
105
117
  "selfsigned": "2.4.1",
106
118
  "simple-git-hooks": "2.14.0",
107
- "tsup": "8.5.1",
108
119
  "tsx": "4.23.15",
109
120
  "typescript": "5.9.3",
110
121
  "vite": "8.3.6",
111
- "vitest": "4.1.12"
122
+ "vitest": "5.1.0"
112
123
  },
113
124
  "simple-git-hooks": {
114
125
  "pre-commit": "pnpm phi-scan --staged"
115
126
  },
116
127
  "scripts": {
117
- "build": "tsup",
128
+ "build": "cosyte-process build",
118
129
  "changeset": "changeset",
119
- "typecheck": "tsc --noEmit && tsc --noEmit -p examples",
130
+ "typecheck": "cosyte-process typecheck",
120
131
  "phi-scan": "tsx scripts/phi-scan.ts",
121
132
  "check:catalog": "cosyte-catalog",
122
133
  "check:claude-card": "cosyte-claude-card",
123
134
  "check:documents": "pnpm check:readme && pnpm check:claude-card && pnpm check:catalog",
124
135
  "check:no-emdash": "cosyte-no-emdash",
125
136
  "check:no-internal-refs": "cosyte-internal-refs",
137
+ "check:process": "cosyte-process check",
126
138
  "check:readme": "cosyte-readme",
127
- "lint": "eslint \"src/**/*.ts\" \"scripts/**/*.ts\" \"test/**/*.ts\" \"examples/**/*.ts\" --max-warnings=0 --no-error-on-unmatched-pattern",
128
- "lint:fix": "eslint \"src/**/*.ts\" \"scripts/**/*.ts\" \"test/**/*.ts\" \"examples/**/*.ts\" --fix --no-error-on-unmatched-pattern",
129
- "format": "prettier --write \"src/**/*.{ts,md}\" \"test/**/*.ts\" \"scripts/**/*.{ts,mjs}\" \"examples/**/*.{ts,json}\" \"docs-content/**/*.{md,json}\" \"*.{json,md,yml}\"",
130
- "format:check": "prettier --check \"src/**/*.{ts,md}\" \"test/**/*.ts\" \"scripts/**/*.{ts,mjs}\" \"examples/**/*.{ts,json}\" \"docs-content/**/*.{md,json}\" \"*.{json,md,yml}\"",
131
- "test": "vitest run",
132
- "test:watch": "vitest",
133
- "test:coverage": "vitest run --coverage",
139
+ "lint": "cosyte-process lint",
140
+ "lint:fix": "cosyte-process lint --fix",
141
+ "format": "cosyte-process format",
142
+ "format:check": "cosyte-process format --check",
143
+ "test": "cosyte-process test",
144
+ "test:watch": "cosyte-process test --watch",
145
+ "test:coverage": "cosyte-process test --coverage",
134
146
  "fuzz": "vitest run test/property/fuzz.property.test.ts test/property/transport-fuzz.property.test.ts test/property/ack-fuzz.property.test.ts",
135
147
  "examples": "tsx scripts/run-examples.ts",
136
148
  "certs:gen": "node scripts/generate-test-certs.mjs",
137
149
  "clean": "rm -rf dist coverage",
138
150
  "attw": "cosyte-attw",
139
- "pack:docs": "bash scripts/build-docs-artifacts.sh",
140
- "version": "changeset version && node scripts/sync-version.mjs && prettier --write package.json src/index.ts",
151
+ "pack:docs": "cosyte-process pack-docs",
152
+ "version": "changeset version && node scripts/sync-version.mjs && cosyte-process format",
141
153
  "publish:dry": "pnpm publish --dry-run --no-git-checks",
142
154
  "release": "changeset publish"
143
155
  }