@glion/lint-profile-field-max-length 0.14.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Rethink Health
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ import type { Root } from "@glion/ast";
2
+ /**
3
+ * Lint rule that validates field value lengths against HL7v2 profile maxLength.
4
+ *
5
+ * For each field with a defined `maxLength` in the profile, checks that
6
+ * each repetition's content length does not exceed the limit.
7
+ *
8
+ * The length is measured using `getLength()` from `hl7v2-utils`, which
9
+ * recursively sums the string lengths of all subcomponent values.
10
+ * Delimiters are not included in the count.
11
+ *
12
+ * Fields without `maxLength` in the profile and empty fields are skipped.
13
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * unified().use(hl7v2LintFieldMaxLength);
18
+ * ```;
19
+ */
20
+ declare const hl7v2LintFieldMaxLength: import("unified-lint-rule").Plugin<Root, unknown>;
21
+ export default hl7v2LintFieldMaxLength;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAKvC;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,uBAAuB,mDAqD5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ import { SKIP, visit } from "@glion/util-visit";
2
+ import { getLength, isEmptyNode } from "@glion/utils";
3
+ import { lintRule } from "unified-lint-rule";
4
+ //#region src/index.ts
5
+ /**
6
+ * Lint rule that validates field value lengths against HL7v2 profile maxLength.
7
+ *
8
+ * For each field with a defined `maxLength` in the profile, checks that
9
+ * each repetition's content length does not exceed the limit.
10
+ *
11
+ * The length is measured using `getLength()` from `hl7v2-utils`, which
12
+ * recursively sums the string lengths of all subcomponent values.
13
+ * Delimiters are not included in the count.
14
+ *
15
+ * Fields without `maxLength` in the profile and empty fields are skipped.
16
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * unified().use(hl7v2LintFieldMaxLength);
21
+ * ```;
22
+ */
23
+ const hl7v2LintFieldMaxLength = lintRule({ origin: "hl7v2-lint:field-max-length" }, (tree, file) => {
24
+ const ctx = file.data.profile;
25
+ if (!ctx) return;
26
+ visit(tree, "segment", (segment, segmentAncestors) => {
27
+ const fieldDef = ctx.fields.get(segment.name);
28
+ if (!fieldDef) return SKIP;
29
+ visit(segment, "field", (fieldNode, _fieldAncestors, info) => {
30
+ if (isEmptyNode(fieldNode)) return SKIP;
31
+ const profile = fieldDef.bySequence.get(info.sequence);
32
+ if (!profile?.maxLength) return SKIP;
33
+ for (const repetition of fieldNode.children) {
34
+ const len = getLength(repetition);
35
+ if (len === 0) continue;
36
+ if (len > profile.maxLength) file.message(`Field ${segment.name}-${info.sequence} exceeds max length of ${profile.maxLength} (actual: ${len})`, {
37
+ ancestors: [
38
+ ...segmentAncestors,
39
+ segment,
40
+ fieldNode,
41
+ repetition
42
+ ],
43
+ place: repetition.position ?? fieldNode.position
44
+ });
45
+ }
46
+ return SKIP;
47
+ });
48
+ return SKIP;
49
+ });
50
+ });
51
+ //#endregion
52
+ export { hl7v2LintFieldMaxLength as default };
53
+
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable-next-line no-unused-vars -- triggers VFile DataMap augmentation\nimport type { ProfileContext } from \"@glion/annotate-profile-context\";\nimport type { Root } from \"@glion/ast\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { getLength, isEmptyNode } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/**\n * Lint rule that validates field value lengths against HL7v2 profile maxLength.\n *\n * For each field with a defined `maxLength` in the profile, checks that\n * each repetition's content length does not exceed the limit.\n *\n * The length is measured using `getLength()` from `hl7v2-utils`, which\n * recursively sums the string lengths of all subcomponent values.\n * Delimiters are not included in the count.\n *\n * Fields without `maxLength` in the profile and empty fields are skipped.\n * Segments without a known profile (e.g., Z-segments) are silently skipped.\n *\n * @example\n * ```typescript\n * unified().use(hl7v2LintFieldMaxLength);\n * ```;\n */\nconst hl7v2LintFieldMaxLength = lintRule<Root>(\n { origin: \"hl7v2-lint:field-max-length\" },\n (tree, file) => {\n const ctx = file.data.profile;\n if (!ctx) {\n return;\n }\n\n visit(tree, \"segment\", (segment, segmentAncestors) => {\n const fieldDef = ctx.fields.get(segment.name);\n if (!fieldDef) {\n return SKIP;\n }\n\n visit(segment, \"field\", (fieldNode, _fieldAncestors, info) => {\n if (isEmptyNode(fieldNode)) {\n return SKIP;\n }\n\n const profile = fieldDef.bySequence.get(info.sequence);\n\n if (!profile?.maxLength) {\n return SKIP;\n }\n\n for (const repetition of fieldNode.children) {\n const len = getLength(repetition);\n if (len === 0) {\n continue;\n }\n\n if (len > profile.maxLength) {\n file.message(\n `Field ${segment.name}-${info.sequence} exceeds max length of ${profile.maxLength} (actual: ${len})`,\n {\n ancestors: [\n ...segmentAncestors,\n segment,\n fieldNode,\n repetition,\n ],\n place: repetition.position ?? fieldNode.position,\n }\n );\n }\n }\n\n return SKIP;\n });\n\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintFieldMaxLength;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAM,0BAA0B,SAC9B,EAAE,QAAQ,+BAA+B,GACxC,MAAM,SAAS;CACd,MAAM,MAAM,KAAK,KAAK;AACtB,KAAI,CAAC,IACH;AAGF,OAAM,MAAM,YAAY,SAAS,qBAAqB;EACpD,MAAM,WAAW,IAAI,OAAO,IAAI,QAAQ,KAAK;AAC7C,MAAI,CAAC,SACH,QAAO;AAGT,QAAM,SAAS,UAAU,WAAW,iBAAiB,SAAS;AAC5D,OAAI,YAAY,UAAU,CACxB,QAAO;GAGT,MAAM,UAAU,SAAS,WAAW,IAAI,KAAK,SAAS;AAEtD,OAAI,CAAC,SAAS,UACZ,QAAO;AAGT,QAAK,MAAM,cAAc,UAAU,UAAU;IAC3C,MAAM,MAAM,UAAU,WAAW;AACjC,QAAI,QAAQ,EACV;AAGF,QAAI,MAAM,QAAQ,UAChB,MAAK,QACH,SAAS,QAAQ,KAAK,GAAG,KAAK,SAAS,yBAAyB,QAAQ,UAAU,YAAY,IAAI,IAClG;KACE,WAAW;MACT,GAAG;MACH;MACA;MACA;MACD;KACD,OAAO,WAAW,YAAY,UAAU;KACzC,CACF;;AAIL,UAAO;IACP;AAEF,SAAO;GACP;EAEL"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@glion/lint-profile-field-max-length",
3
+ "version": "0.14.1",
4
+ "description": "Lint rule to validate field value lengths against HL7v2 profile maxLength",
5
+ "keywords": [
6
+ "health",
7
+ "healthcare",
8
+ "hl7",
9
+ "hl7v2",
10
+ "nodejs",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://glion.dev",
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "Melek Somai",
17
+ "email": "melek@rethinkhealth.io"
18
+ },
19
+ "repository": "rethinkhealth/glion.git",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "type": "module",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": "./dist/index.js"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "unified-lint-rule": "3.0.1",
33
+ "@glion/ast": "0.14.1",
34
+ "@glion/util-visit": "0.14.1",
35
+ "@glion/utils": "0.14.1"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^25.5.0",
39
+ "@vitest/coverage-v8": "4.1.2",
40
+ "tsdown": "0.21.7",
41
+ "typescript": "^5.9.3",
42
+ "unified": "^11.0.5",
43
+ "vfile": "^6.0.3",
44
+ "vitest": "4.1.2",
45
+ "@glion/annotate-profile-context": "0.14.1",
46
+ "@glion/builder": "0.14.1",
47
+ "@glion/testing": "0.0.2",
48
+ "@glion/tsconfig": "0.0.1"
49
+ },
50
+ "engines": {
51
+ "node": ">=18"
52
+ },
53
+ "scripts": {
54
+ "build": "tsdown && tsc --emitDeclarationOnly",
55
+ "check-types": "tsc --noEmit",
56
+ "bench": "vitest bench --run",
57
+ "test": "vitest run",
58
+ "test:coverage": "vitest run --coverage",
59
+ "test:watch": "vitest"
60
+ }
61
+ }