@glion/lint-profile-required-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,20 @@
1
+ import type { Root } from "@glion/ast";
2
+ /**
3
+ * Lint rule that validates required fields per HL7v2 profile.
4
+ *
5
+ * For each segment, checks that all fields marked `required: true`
6
+ * in the field definition are present and non-empty.
7
+ *
8
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
9
+ *
10
+ * Requires `@glion/annotate-profile-context` to run first
11
+ * so that `file.data.fields` is populated.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * unified().use(hl7v2AnnotateProfileContext).use(hl7v2LintRequiredFields);
16
+ * ```;
17
+ */
18
+ declare const hl7v2LintRequiredFields: import("unified-lint-rule").Plugin<Root, unknown>;
19
+ export default hl7v2LintRequiredFields;
20
+ //# 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;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,uBAAuB,mDA+B5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ import { visit } from "@glion/util-visit";
2
+ import { isEmptyNode } from "@glion/utils";
3
+ import { lintRule } from "unified-lint-rule";
4
+ //#region src/index.ts
5
+ /**
6
+ * Lint rule that validates required fields per HL7v2 profile.
7
+ *
8
+ * For each segment, checks that all fields marked `required: true`
9
+ * in the field definition are present and non-empty.
10
+ *
11
+ * Segments without a known profile (e.g., Z-segments) are silently skipped.
12
+ *
13
+ * Requires `@glion/annotate-profile-context` to run first
14
+ * so that `file.data.fields` is populated.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * unified().use(hl7v2AnnotateProfileContext).use(hl7v2LintRequiredFields);
19
+ * ```;
20
+ */
21
+ const hl7v2LintRequiredFields = lintRule({ origin: "hl7v2-lint:required-fields" }, (tree, file) => {
22
+ const ctx = file.data.profile;
23
+ if (!ctx) return;
24
+ visit(tree, "segment", (node, parents) => {
25
+ const fieldDef = ctx.fields.get(node.name);
26
+ if (!fieldDef) return;
27
+ for (const sequence of fieldDef.requiredSequences) {
28
+ const fieldNode = node.children[sequence - 1];
29
+ if (!fieldNode || isEmptyNode(fieldNode)) {
30
+ const profile = fieldDef.bySequence.get(sequence);
31
+ const name = profile?.name ? ` (${profile.name})` : "";
32
+ file.message(`Required field ${node.name}-${sequence}${name} is missing or empty`, {
33
+ ancestors: [
34
+ ...parents,
35
+ node,
36
+ ...fieldNode ? [fieldNode] : []
37
+ ],
38
+ place: fieldNode?.position ?? node.position
39
+ });
40
+ }
41
+ }
42
+ });
43
+ });
44
+ //#endregion
45
+ export { hl7v2LintRequiredFields as default };
46
+
47
+ //# 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 { visit } from \"@glion/util-visit\";\nimport { isEmptyNode } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/**\n * Lint rule that validates required fields per HL7v2 profile.\n *\n * For each segment, checks that all fields marked `required: true`\n * in the field definition are present and non-empty.\n *\n * Segments without a known profile (e.g., Z-segments) are silently skipped.\n *\n * Requires `@glion/annotate-profile-context` to run first\n * so that `file.data.fields` is populated.\n *\n * @example\n * ```typescript\n * unified().use(hl7v2AnnotateProfileContext).use(hl7v2LintRequiredFields);\n * ```;\n */\nconst hl7v2LintRequiredFields = lintRule<Root>(\n { origin: \"hl7v2-lint:required-fields\" },\n (tree, file) => {\n const ctx = file.data.profile;\n if (!ctx) {\n return;\n }\n\n visit(tree, \"segment\", (node, parents) => {\n const fieldDef = ctx.fields.get(node.name);\n if (!fieldDef) {\n return;\n }\n\n for (const sequence of fieldDef.requiredSequences) {\n const fieldNode = node.children[sequence - 1];\n\n if (!fieldNode || isEmptyNode(fieldNode)) {\n const profile = fieldDef.bySequence.get(sequence);\n const name = profile?.name ? ` (${profile.name})` : \"\";\n file.message(\n `Required field ${node.name}-${sequence}${name} is missing or empty`,\n {\n ancestors: [...parents, node, ...(fieldNode ? [fieldNode] : [])],\n place: fieldNode?.position ?? node.position,\n }\n );\n }\n }\n });\n }\n);\n\nexport default hl7v2LintRequiredFields;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,0BAA0B,SAC9B,EAAE,QAAQ,8BAA8B,GACvC,MAAM,SAAS;CACd,MAAM,MAAM,KAAK,KAAK;AACtB,KAAI,CAAC,IACH;AAGF,OAAM,MAAM,YAAY,MAAM,YAAY;EACxC,MAAM,WAAW,IAAI,OAAO,IAAI,KAAK,KAAK;AAC1C,MAAI,CAAC,SACH;AAGF,OAAK,MAAM,YAAY,SAAS,mBAAmB;GACjD,MAAM,YAAY,KAAK,SAAS,WAAW;AAE3C,OAAI,CAAC,aAAa,YAAY,UAAU,EAAE;IACxC,MAAM,UAAU,SAAS,WAAW,IAAI,SAAS;IACjD,MAAM,OAAO,SAAS,OAAO,KAAK,QAAQ,KAAK,KAAK;AACpD,SAAK,QACH,kBAAkB,KAAK,KAAK,GAAG,WAAW,KAAK,uBAC/C;KACE,WAAW;MAAC,GAAG;MAAS;MAAM,GAAI,YAAY,CAAC,UAAU,GAAG,EAAE;MAAE;KAChE,OAAO,WAAW,YAAY,KAAK;KACpC,CACF;;;GAGL;EAEL"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@glion/lint-profile-required-fields",
3
+ "version": "0.14.1",
4
+ "description": "Lint rule to validate required fields per HL7v2 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/utils": "0.14.1",
34
+ "@glion/util-visit": "0.14.1",
35
+ "@glion/ast": "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/testing": "0.0.2",
46
+ "@glion/annotate-profile-context": "0.14.1",
47
+ "@glion/tsconfig": "0.0.1",
48
+ "@glion/builder": "0.14.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
+ }