@rethinkhealth/hl7v2-lint-message-version 0.12.0 → 0.13.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/dist/index.js +46 -61
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,66 +1,51 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
1
|
import { value } from "@rethinkhealth/hl7v2-util-query";
|
|
3
2
|
import { satisfies } from "@rethinkhealth/hl7v2-util-semver";
|
|
4
3
|
import ensureError from "ensure-error";
|
|
5
4
|
import { lintRule } from "unified-lint-rule";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
file.message(
|
|
53
|
-
`MSH-12 (version) field value '${result.value}' does not satisfy expression '${options.expression}'`,
|
|
54
|
-
{
|
|
55
|
-
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
56
|
-
place: result?.node?.position || result?.ancestors.at(-1)?.position || rootTree.position
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
var index_default = hl7v2LintMessageVersion;
|
|
63
|
-
export {
|
|
64
|
-
index_default as default
|
|
65
|
-
};
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
const defaultOptions = { expression: "<3.0.0 >=2.3" };
|
|
7
|
+
const hl7v2LintMessageVersion = lintRule({
|
|
8
|
+
origin: "hl7v2-lint:message-version",
|
|
9
|
+
url: "https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-message-version#readme"
|
|
10
|
+
}, (tree, file, opts) => {
|
|
11
|
+
const options = {
|
|
12
|
+
...defaultOptions,
|
|
13
|
+
...opts
|
|
14
|
+
};
|
|
15
|
+
if (tree.type !== "root") {
|
|
16
|
+
file.message(`Root node type must be 'root' — received '${tree.type}' instead`, {
|
|
17
|
+
ancestors: [tree],
|
|
18
|
+
place: tree.position
|
|
19
|
+
});
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const rootTree = tree;
|
|
23
|
+
const result = value(rootTree, "MSH-12.1");
|
|
24
|
+
if (!result?.value || result.value === "") {
|
|
25
|
+
file.message("Required MSH-12 (version) field is missing or empty", {
|
|
26
|
+
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
27
|
+
place: result?.node?.position || result?.ancestors.at(-1)?.position || rootTree.position
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let isValid = false;
|
|
32
|
+
try {
|
|
33
|
+
isValid = satisfies(result.value, options.expression);
|
|
34
|
+
} catch (caughtError) {
|
|
35
|
+
const error = ensureError(caughtError);
|
|
36
|
+
file.message(`MSH-12 (version) field value '${result.value}' is not valid`, {
|
|
37
|
+
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
38
|
+
cause: error,
|
|
39
|
+
place: result?.node?.position || rootTree.position
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!isValid) file.message(`MSH-12 (version) field value '${result.value}' does not satisfy expression '${options.expression}'`, {
|
|
44
|
+
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
45
|
+
place: result?.node?.position || result?.ancestors.at(-1)?.position || rootTree.position
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
//#endregion
|
|
49
|
+
export { hl7v2LintMessageVersion as default };
|
|
50
|
+
|
|
66
51
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Nodes, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport { value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { satisfies } from \"@rethinkhealth/hl7v2-util-semver\";\nimport ensureError from \"ensure-error\";\nimport { lintRule } from \"unified-lint-rule\";\n\nexport interface MessageVersionLintOptions {\n expression: string;\n}\n\nconst defaultOptions = {\n expression: \"<3.0.0 >=2.3\",\n} as const;\n\nconst hl7v2LintMessageVersion = lintRule<Nodes, MessageVersionLintOptions>(\n {\n origin: \"hl7v2-lint:message-version\",\n url: \"https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-message-version#readme\",\n },\n // oxlint-disable-next-line complexity\n (tree, file, opts) => {\n const options = { ...defaultOptions, ...opts };\n\n // 1. Validate tree is a Root node.\n if (tree.type !== \"root\") {\n file.message(\n `Root node type must be 'root' — received '${tree.type}' instead`,\n {\n ancestors: [tree],\n place: tree.position,\n }\n );\n return;\n }\n\n const rootTree = tree as Root;\n\n // 2. Extract message info from annotated data or parse from MSH segment.\n const result = value(rootTree, \"MSH-12.1\");\n\n if (!result?.value || result.value === \"\") {\n file.message(\"Required MSH-12 (version) field is missing or empty\", {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n place:\n result?.node?.position ||\n result?.ancestors.at(-1)?.position ||\n rootTree.position,\n });\n return;\n }\n\n // 5. Ensure version satisfies allowed expression.\n let isValid = false;\n try {\n isValid = satisfies(result.value, options.expression);\n } catch (caughtError) {\n const error = ensureError(caughtError);\n file.message(\n `MSH-12 (version) field value '${result.value}' is not valid`,\n {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n cause: error,\n place: result?.node?.position || rootTree.position,\n }\n );\n return;\n }\n\n if (!isValid) {\n file.message(\n `MSH-12 (version) field value '${result.value}' does not satisfy expression '${options.expression}'`,\n {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n place:\n result?.node?.position ||\n result?.ancestors.at(-1)?.position ||\n rootTree.position,\n }\n );\n }\n }\n);\n\nexport default hl7v2LintMessageVersion;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Nodes, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport { value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { satisfies } from \"@rethinkhealth/hl7v2-util-semver\";\nimport ensureError from \"ensure-error\";\nimport { lintRule } from \"unified-lint-rule\";\n\nexport interface MessageVersionLintOptions {\n expression: string;\n}\n\nconst defaultOptions = {\n expression: \"<3.0.0 >=2.3\",\n} as const;\n\nconst hl7v2LintMessageVersion = lintRule<Nodes, MessageVersionLintOptions>(\n {\n origin: \"hl7v2-lint:message-version\",\n url: \"https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-message-version#readme\",\n },\n // oxlint-disable-next-line complexity\n (tree, file, opts) => {\n const options = { ...defaultOptions, ...opts };\n\n // 1. Validate tree is a Root node.\n if (tree.type !== \"root\") {\n file.message(\n `Root node type must be 'root' — received '${tree.type}' instead`,\n {\n ancestors: [tree],\n place: tree.position,\n }\n );\n return;\n }\n\n const rootTree = tree as Root;\n\n // 2. Extract message info from annotated data or parse from MSH segment.\n const result = value(rootTree, \"MSH-12.1\");\n\n if (!result?.value || result.value === \"\") {\n file.message(\"Required MSH-12 (version) field is missing or empty\", {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n place:\n result?.node?.position ||\n result?.ancestors.at(-1)?.position ||\n rootTree.position,\n });\n return;\n }\n\n // 5. Ensure version satisfies allowed expression.\n let isValid = false;\n try {\n isValid = satisfies(result.value, options.expression);\n } catch (caughtError) {\n const error = ensureError(caughtError);\n file.message(\n `MSH-12 (version) field value '${result.value}' is not valid`,\n {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n cause: error,\n place: result?.node?.position || rootTree.position,\n }\n );\n return;\n }\n\n if (!isValid) {\n file.message(\n `MSH-12 (version) field value '${result.value}' does not satisfy expression '${options.expression}'`,\n {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n place:\n result?.node?.position ||\n result?.ancestors.at(-1)?.position ||\n rootTree.position,\n }\n );\n }\n }\n);\n\nexport default hl7v2LintMessageVersion;\n"],"mappings":";;;;;AAUA,MAAM,iBAAiB,EACrB,YAAY,gBACb;AAED,MAAM,0BAA0B,SAC9B;CACE,QAAQ;CACR,KAAK;CACN,GAEA,MAAM,MAAM,SAAS;CACpB,MAAM,UAAU;EAAE,GAAG;EAAgB,GAAG;EAAM;AAG9C,KAAI,KAAK,SAAS,QAAQ;AACxB,OAAK,QACH,6CAA6C,KAAK,KAAK,YACvD;GACE,WAAW,CAAC,KAAK;GACjB,OAAO,KAAK;GACb,CACF;AACD;;CAGF,MAAM,WAAW;CAGjB,MAAM,SAAS,MAAM,UAAU,WAAW;AAE1C,KAAI,CAAC,QAAQ,SAAS,OAAO,UAAU,IAAI;AACzC,OAAK,QAAQ,uDAAuD;GAClE,WAAW,SAAS,CAAC,GAAG,OAAO,WAAW,OAAO,KAAK,GAAG,CAAC,SAAS;GACnE,OACE,QAAQ,MAAM,YACd,QAAQ,UAAU,GAAG,GAAG,EAAE,YAC1B,SAAS;GACZ,CAAC;AACF;;CAIF,IAAI,UAAU;AACd,KAAI;AACF,YAAU,UAAU,OAAO,OAAO,QAAQ,WAAW;UAC9C,aAAa;EACpB,MAAM,QAAQ,YAAY,YAAY;AACtC,OAAK,QACH,iCAAiC,OAAO,MAAM,iBAC9C;GACE,WAAW,SAAS,CAAC,GAAG,OAAO,WAAW,OAAO,KAAK,GAAG,CAAC,SAAS;GACnE,OAAO;GACP,OAAO,QAAQ,MAAM,YAAY,SAAS;GAC3C,CACF;AACD;;AAGF,KAAI,CAAC,QACH,MAAK,QACH,iCAAiC,OAAO,MAAM,iCAAiC,QAAQ,WAAW,IAClG;EACE,WAAW,SAAS,CAAC,GAAG,OAAO,WAAW,OAAO,KAAK,GAAG,CAAC,SAAS;EACnE,OACE,QAAQ,MAAM,YACd,QAAQ,UAAU,GAAG,GAAG,EAAE,YAC1B,SAAS;EACZ,CACF;EAGN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rethinkhealth/hl7v2-lint-message-version",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.2",
|
|
4
4
|
"description": "hl7v2-lint rule to warn when message version is not supported",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"definition",
|
|
@@ -35,21 +35,21 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"ensure-error": "5.0.0",
|
|
37
37
|
"unified-lint-rule": "3.0.1",
|
|
38
|
-
"@rethinkhealth/hl7v2-util-query": "0.
|
|
39
|
-
"@rethinkhealth/hl7v2-util-semver": "0.
|
|
38
|
+
"@rethinkhealth/hl7v2-util-query": "0.13.2",
|
|
39
|
+
"@rethinkhealth/hl7v2-util-semver": "0.13.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^25.5.0",
|
|
43
43
|
"@types/unist": "^3.0.3",
|
|
44
44
|
"@vitest/coverage-v8": "4.1.0",
|
|
45
|
-
"
|
|
45
|
+
"tsdown": "0.21.7",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
47
|
"unified": "^11.0.5",
|
|
48
48
|
"vfile": "^6.0.3",
|
|
49
49
|
"vitest": "4.1.0",
|
|
50
|
-
"@rethinkhealth/hl7v2-
|
|
50
|
+
"@rethinkhealth/hl7v2-ast": "0.13.2",
|
|
51
|
+
"@rethinkhealth/hl7v2-builder": "0.13.2",
|
|
51
52
|
"@rethinkhealth/testing": "0.0.2",
|
|
52
|
-
"@rethinkhealth/hl7v2-ast": "0.12.0",
|
|
53
53
|
"@rethinkhealth/tsconfig": "0.0.1"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"packageManager": "pnpm@10.14.0",
|
|
59
59
|
"scripts": {
|
|
60
|
-
"build": "
|
|
60
|
+
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
61
61
|
"check-types": "tsc --noEmit",
|
|
62
62
|
"test": "vitest run",
|
|
63
63
|
"test:coverage": "vitest run --coverage",
|