@glion/lint-max-message-size 0.15.1 → 0.15.3

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.
Files changed (2) hide show
  1. package/README.md +52 -55
  2. package/package.json +10 -6
package/README.md CHANGED
@@ -1,51 +1,32 @@
1
1
  # @glion/lint-max-message-size
2
2
 
3
- A [`unified`][github-unified] lint rule that warns when an HL7v2 message exceeds a configurable maximum size in bytes or number of segments.
3
+ Lint rule that flags HL7v2 messages exceeding a maximum byte size or segment count.
4
4
 
5
- - **Default max size:** 10,000,000 bytes (10MB)
6
- - **Optional:** Limit the number of segments
5
+ ## What it does
7
6
 
8
- ## What is this?
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
- This package is **ESM only**. In Node.js (v16+), install with npm:
29
-
30
- ```sh
11
+ ```bash
31
12
  npm install @glion/lint-max-message-size
32
13
  ```
33
14
 
34
15
  ## Use
35
16
 
36
- On the API:
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 msg = `MSH|^~\\&|...`;
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(hl7v2Parse)
47
- .use(hl7v2LintMaxMessageSize)
48
- .process(msg);
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
- Warns when the HL7v2 message exceeds a configurable maximum size in bytes (default: 10,000,000 bytes) or, optionally, a maximum number of segments.
58
- Reports a message if the message is too large or has too many segments.
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
- ###### Returns
51
+ declare const hl7v2LintMaxMessageSize: Plugin<[MaxMessageSizeOptions?], Root>;
52
+ export default hl7v2LintMaxMessageSize;
53
+ ```
61
54
 
62
- A `unified` Transformer that adds messages to the file.
55
+ ## What it checks
63
56
 
64
- ## Security
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
- This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
59
+ ### Valid
67
60
 
68
- ## Contributing
61
+ A small message with `maxBytes: 1_000_000` (well under the limit):
69
62
 
70
- We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
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
- 1. Fork the repository
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
- ## Code of Conduct
70
+ A message whose UTF-8 size exceeds `maxBytes`:
79
71
 
80
- To ensure a welcoming and positive environment, we have a [Code of Conduct][github-code-of-conduct] that all contributors and participants are expected to adhere to.
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
- ## License
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
- Copyright 2025 Rethink Health, SUARL. All rights reserved.
84
+ ## Part of Glion
85
85
 
86
- This program is licensed to you under the terms of the [MIT License](https://opensource.org/licenses/MIT). This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [LICENSE][github-license] file for details.
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
- [github-code-of-conduct]: https://github.com/rethinkhealth/glion/blob/main/CODE_OF_CONDUCT.md
89
- [github-license]: https://github.com/rethinkhealth/glion/blob/main/LICENSE
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.1",
3
+ "version": "0.15.3",
4
4
  "description": "hl7v2-lint rule to warn when message size exceeds the maximum allowed size",
5
5
  "keywords": [
6
6
  "definition",
@@ -47,14 +47,16 @@
47
47
  "@types/pluralize": "^0.0.33",
48
48
  "@types/unist": "^3.0.3",
49
49
  "@vitest/coverage-v8": "4.1.2",
50
+ "publint": "0.3.18",
50
51
  "tsdown": "0.21.7",
51
52
  "typescript": "^5.9.3",
52
53
  "vfile": "^6.0.3",
53
54
  "vitest": "4.1.2",
54
- "@glion/ast": "0.15.1",
55
- "@glion/builder": "0.15.1",
56
- "@glion/testing": "0.15.1",
57
- "@glion/tsconfig": "0.15.1"
55
+ "@glion/builder": "0.15.3",
56
+ "@glion/check-readme": "0.15.3",
57
+ "@glion/ast": "0.15.3",
58
+ "@glion/testing": "0.15.3",
59
+ "@glion/tsconfig": "0.15.3"
58
60
  },
59
61
  "engines": {
60
62
  "node": ">=18"
@@ -63,8 +65,10 @@
63
65
  "scripts": {
64
66
  "build": "tsdown && tsc --emitDeclarationOnly",
65
67
  "check-types": "tsc --noEmit",
68
+ "check:readme": "glion-check-readme",
66
69
  "test": "vitest run",
67
70
  "test:coverage": "vitest run --coverage",
68
- "test:watch": "vitest"
71
+ "test:watch": "vitest",
72
+ "publint": "publint --strict"
69
73
  }
70
74
  }