@glion/lint-profile-extra-fields 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,15 @@
1
+ import type { Root } from "@glion/ast";
2
+ /**
3
+ * Lint rule that warns when a segment contains fields beyond the maximum
4
+ * sequence number defined in its profile.
5
+ *
6
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * unified().use(hl7v2LintExtraFields);
11
+ * ```;
12
+ */
13
+ declare const hl7v2LintExtraFields: import("unified-lint-rule").Plugin<Root, unknown>;
14
+ export default hl7v2LintExtraFields;
15
+ //# 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;AAIvC;;;;;;;;;;GAUG;AACH,QAAA,MAAM,oBAAoB,mDAoCzB,CAAC;AAaF,eAAe,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { SKIP, visit } from "@glion/util-visit";
2
+ import { lintRule } from "unified-lint-rule";
3
+ //#region src/index.ts
4
+ /**
5
+ * Lint rule that warns when a segment contains fields beyond the maximum
6
+ * sequence number defined in its profile.
7
+ *
8
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * unified().use(hl7v2LintExtraFields);
13
+ * ```;
14
+ */
15
+ const hl7v2LintExtraFields = lintRule({ origin: "hl7v2-lint:extra-fields" }, (tree, file) => {
16
+ const ctx = file.data.profile;
17
+ if (!ctx) return;
18
+ visit(tree, "segment", (segment, segmentAncestors) => {
19
+ const fieldDef = ctx.fields.get(segment.name);
20
+ if (!fieldDef) return SKIP;
21
+ const maxSequence = maxKey(fieldDef.bySequence);
22
+ if (maxSequence === 0) return SKIP;
23
+ visit(segment, "field", (fieldNode, _fieldAncestors, info) => {
24
+ if (info.sequence > maxSequence) file.message(`Field ${segment.name}-${info.sequence} is beyond the defined fields for ${segment.name} (max: ${maxSequence} in v${ctx.version})`, {
25
+ ancestors: [
26
+ ...segmentAncestors,
27
+ segment,
28
+ fieldNode
29
+ ],
30
+ place: fieldNode.position
31
+ });
32
+ return SKIP;
33
+ });
34
+ return SKIP;
35
+ });
36
+ });
37
+ /** Return the highest numeric key in a Map, or 0 if empty. */
38
+ function maxKey(map) {
39
+ let max = 0;
40
+ for (const key of map.keys()) if (key > max) max = key;
41
+ return max;
42
+ }
43
+ //#endregion
44
+ export { hl7v2LintExtraFields as default };
45
+
46
+ //# 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 { lintRule } from \"unified-lint-rule\";\n\n/**\n * Lint rule that warns when a segment contains fields beyond the maximum\n * sequence number defined in its profile.\n *\n * Segments without a known profile (e.g., Z-segments) are silently skipped.\n *\n * @example\n * ```typescript\n * unified().use(hl7v2LintExtraFields);\n * ```;\n */\nconst hl7v2LintExtraFields = lintRule<Root>(\n { origin: \"hl7v2-lint:extra-fields\" },\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 const maxSequence = maxKey(fieldDef.bySequence);\n if (maxSequence === 0) {\n return SKIP;\n }\n\n visit(segment, \"field\", (fieldNode, _fieldAncestors, info) => {\n if (info.sequence > maxSequence) {\n file.message(\n `Field ${segment.name}-${info.sequence} is beyond the defined fields for ${segment.name} (max: ${maxSequence} in v${ctx.version})`,\n {\n ancestors: [...segmentAncestors, segment, fieldNode],\n place: fieldNode.position,\n }\n );\n }\n\n return SKIP;\n });\n\n return SKIP;\n });\n }\n);\n\n/** Return the highest numeric key in a Map, or 0 if empty. */\nfunction maxKey(map: ReadonlyMap<number, unknown>): number {\n let max = 0;\n for (const key of map.keys()) {\n if (key > max) {\n max = key;\n }\n }\n return max;\n}\n\nexport default hl7v2LintExtraFields;\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,uBAAuB,SAC3B,EAAE,QAAQ,2BAA2B,GACpC,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;EAGT,MAAM,cAAc,OAAO,SAAS,WAAW;AAC/C,MAAI,gBAAgB,EAClB,QAAO;AAGT,QAAM,SAAS,UAAU,WAAW,iBAAiB,SAAS;AAC5D,OAAI,KAAK,WAAW,YAClB,MAAK,QACH,SAAS,QAAQ,KAAK,GAAG,KAAK,SAAS,oCAAoC,QAAQ,KAAK,SAAS,YAAY,OAAO,IAAI,QAAQ,IAChI;IACE,WAAW;KAAC,GAAG;KAAkB;KAAS;KAAU;IACpD,OAAO,UAAU;IAClB,CACF;AAGH,UAAO;IACP;AAEF,SAAO;GACP;EAEL;;AAGD,SAAS,OAAO,KAA2C;CACzD,IAAI,MAAM;AACV,MAAK,MAAM,OAAO,IAAI,MAAM,CAC1B,KAAI,MAAM,IACR,OAAM;AAGV,QAAO"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@glion/lint-profile-extra-fields",
3
+ "version": "0.14.1",
4
+ "description": "Lint rule that warns when a segment contains fields beyond the maximum sequence defined in its profile",
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/util-visit": "0.14.1",
34
+ "@glion/ast": "0.14.1"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^25.5.0",
38
+ "@vitest/coverage-v8": "4.1.2",
39
+ "tsdown": "0.21.7",
40
+ "typescript": "^5.9.3",
41
+ "unified": "^11.0.5",
42
+ "vfile": "^6.0.3",
43
+ "vitest": "4.1.2",
44
+ "@glion/annotate-profile-context": "0.14.1",
45
+ "@glion/builder": "0.14.1",
46
+ "@glion/tsconfig": "0.0.1",
47
+ "@glion/testing": "0.0.2"
48
+ },
49
+ "engines": {
50
+ "node": ">=18"
51
+ },
52
+ "scripts": {
53
+ "build": "tsdown && tsc --emitDeclarationOnly",
54
+ "check-types": "tsc --noEmit",
55
+ "bench": "vitest bench --run",
56
+ "test": "vitest run",
57
+ "test:coverage": "vitest run --coverage",
58
+ "test:watch": "vitest"
59
+ }
60
+ }