@glion/lint-max-message-size 0.15.0 → 0.15.2
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/README.md +52 -55
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -1,51 +1,32 @@
|
|
|
1
1
|
# @glion/lint-max-message-size
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lint rule that flags HL7v2 messages exceeding a maximum byte size or segment count.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- **Optional:** Limit the number of segments
|
|
5
|
+
## What it does
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
This package validates the **maximum message size** in HL7v2 syntax trees produced by parsers like [`@glion/parser`][github-hl7v2-parser].
|
|
11
|
-
|
|
12
|
-
It reports a message when the HL7v2 message exceeds a configurable maximum size in bytes (default: 1,000,000 bytes) or, optionally, a maximum number of segments.
|
|
13
|
-
|
|
14
|
-
## When should I use this?
|
|
15
|
-
|
|
16
|
-
Use this rule to enforce a maximum HL7v2 message size (in bytes) and/or segment count, helping to prevent oversized messages that may cause downstream processing issues or violate system constraints.
|
|
17
|
-
|
|
18
|
-
This linter is useful for:
|
|
19
|
-
|
|
20
|
-
- Ensuring HL7v2 messages do not exceed a safe or expected size limit (default: 10MB).
|
|
21
|
-
- Optionally restricting the number of segments in a message to catch unusually large or malformed messages.
|
|
22
|
-
- Improving reliability and performance by catching messages that could cause resource exhaustion or be rejected by receivers.
|
|
23
|
-
|
|
24
|
-
Configure the rule to match your system's requirements for message size and segment count.
|
|
7
|
+
Measures the UTF-8 byte length of the source message and, optionally, the number of segment nodes in the tree. Reports a warning when the message is larger than `maxBytes` (default 10,000,000) or when `maxSegments` is set and the tree contains more segments than allowed. Intended to protect downstream systems from oversized payloads that would cause resource or protocol limits to be hit.
|
|
25
8
|
|
|
26
9
|
## Install
|
|
27
10
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```sh
|
|
11
|
+
```bash
|
|
31
12
|
npm install @glion/lint-max-message-size
|
|
32
13
|
```
|
|
33
14
|
|
|
34
15
|
## Use
|
|
35
16
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
import { unified } from "unified";
|
|
40
|
-
import { hl7v2Parse } from "@glion/parser";
|
|
17
|
+
```ts
|
|
18
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
41
19
|
import hl7v2LintMaxMessageSize from "@glion/lint-max-message-size";
|
|
20
|
+
import { unified } from "unified";
|
|
42
21
|
import { reporter } from "vfile-reporter";
|
|
43
22
|
|
|
44
|
-
const
|
|
23
|
+
const message =
|
|
24
|
+
"MSH|^~\\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5";
|
|
25
|
+
|
|
45
26
|
const file = await unified()
|
|
46
|
-
.use(
|
|
47
|
-
.use(hl7v2LintMaxMessageSize)
|
|
48
|
-
.process(
|
|
27
|
+
.use(hl7v2Parser)
|
|
28
|
+
.use(hl7v2LintMaxMessageSize, { maxBytes: 1_000_000, maxSegments: 100 })
|
|
29
|
+
.process(message);
|
|
49
30
|
|
|
50
31
|
console.error(reporter([file]));
|
|
51
32
|
```
|
|
@@ -54,39 +35,55 @@ console.error(reporter([file]));
|
|
|
54
35
|
|
|
55
36
|
### `unified().use(hl7v2LintMaxMessageSize[, options])`
|
|
56
37
|
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
A `unified` lint rule plugin.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import type { Plugin } from "unified";
|
|
42
|
+
import type { Root } from "@glion/ast";
|
|
43
|
+
|
|
44
|
+
export interface MaxMessageSizeOptions {
|
|
45
|
+
/** Max allowed size of the source message in UTF-8 bytes. Default: 10_000_000 (10MB). */
|
|
46
|
+
maxBytes?: number;
|
|
47
|
+
/** Max allowed number of `segment` nodes. Default: undefined (disabled). */
|
|
48
|
+
maxSegments?: number;
|
|
49
|
+
}
|
|
59
50
|
|
|
60
|
-
|
|
51
|
+
declare const hl7v2LintMaxMessageSize: Plugin<[MaxMessageSizeOptions?], Root>;
|
|
52
|
+
export default hl7v2LintMaxMessageSize;
|
|
53
|
+
```
|
|
61
54
|
|
|
62
|
-
|
|
55
|
+
## What it checks
|
|
63
56
|
|
|
64
|
-
|
|
57
|
+
The message's UTF-8 byte length must not exceed `maxBytes`, and (when configured) the number of `segment` nodes must not exceed `maxSegments`.
|
|
65
58
|
|
|
66
|
-
|
|
59
|
+
### Valid
|
|
67
60
|
|
|
68
|
-
|
|
61
|
+
A small message with `maxBytes: 1_000_000` (well under the limit):
|
|
69
62
|
|
|
70
|
-
|
|
63
|
+
```hl7
|
|
64
|
+
MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5
|
|
65
|
+
PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
|
|
66
|
+
```
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
74
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
75
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
76
|
-
5. Open a Pull Request
|
|
68
|
+
### Invalid
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
A message whose UTF-8 size exceeds `maxBytes`:
|
|
79
71
|
|
|
80
|
-
|
|
72
|
+
```
|
|
73
|
+
Message size 2,000,000 bytes exceeds 1,000,000 bytes limit — trim payload or raise "maxBytes"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A tree with more segments than `maxSegments`:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
Message contains 150 segments (limit 100 segments) — reduce segment count or raise "maxSegments"
|
|
80
|
+
```
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
Byte and segment counts are interpolated with pluralization. Both checks are independent — if the message violates both thresholds, two messages are reported.
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
## Part of Glion
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
`@glion/lint-max-message-size` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
87
87
|
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
91
|
-
[github-unified]: https://github.com/unifiedjs/unified
|
|
92
|
-
[github-hl7v2-parser]: https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-parser
|
|
88
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
89
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/lint-max-message-size",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "hl7v2-lint rule to warn when message size exceeds the maximum allowed size",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"definition",
|
|
@@ -19,7 +19,11 @@
|
|
|
19
19
|
"name": "Melek Somai",
|
|
20
20
|
"email": "melek@rethinkhealth.io"
|
|
21
21
|
},
|
|
22
|
-
"repository":
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/rethinkhealth/glion.git",
|
|
25
|
+
"directory": "packages/lint-max-message-size"
|
|
26
|
+
},
|
|
23
27
|
"files": [
|
|
24
28
|
"dist"
|
|
25
29
|
],
|
|
@@ -43,14 +47,16 @@
|
|
|
43
47
|
"@types/pluralize": "^0.0.33",
|
|
44
48
|
"@types/unist": "^3.0.3",
|
|
45
49
|
"@vitest/coverage-v8": "4.1.2",
|
|
50
|
+
"publint": "0.3.18",
|
|
46
51
|
"tsdown": "0.21.7",
|
|
47
52
|
"typescript": "^5.9.3",
|
|
48
53
|
"vfile": "^6.0.3",
|
|
49
54
|
"vitest": "4.1.2",
|
|
50
|
-
"@glion/
|
|
51
|
-
"@glion/
|
|
52
|
-
"@glion/
|
|
53
|
-
"@glion/testing": "0.15.
|
|
55
|
+
"@glion/ast": "0.15.2",
|
|
56
|
+
"@glion/check-readme": "0.15.2",
|
|
57
|
+
"@glion/builder": "0.15.2",
|
|
58
|
+
"@glion/testing": "0.15.2",
|
|
59
|
+
"@glion/tsconfig": "0.15.2"
|
|
54
60
|
},
|
|
55
61
|
"engines": {
|
|
56
62
|
"node": ">=18"
|
|
@@ -59,8 +65,10 @@
|
|
|
59
65
|
"scripts": {
|
|
60
66
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
61
67
|
"check-types": "tsc --noEmit",
|
|
68
|
+
"check:readme": "glion-check-readme",
|
|
62
69
|
"test": "vitest run",
|
|
63
70
|
"test:coverage": "vitest run --coverage",
|
|
64
|
-
"test:watch": "vitest"
|
|
71
|
+
"test:watch": "vitest",
|
|
72
|
+
"publint": "publint --strict"
|
|
65
73
|
}
|
|
66
74
|
}
|