@rethinkhealth/hl7v2-lint-message-version 0.2.30 → 0.3.0
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.d.ts.map +1 -1
- package/dist/index.js +29 -40
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAQ,MAAM,0BAA0B,CAAC;AAM5D,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAMF,QAAA,MAAM,uBAAuB,sEAgE5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
// ../hl7v2-util-message-info/dist/index.js
|
|
2
|
-
import { value } from "@rethinkhealth/hl7v2-util-query";
|
|
3
|
-
function getMessageInfo(tree) {
|
|
4
|
-
return {
|
|
5
|
-
version: getVersion(tree),
|
|
6
|
-
messageCode: getMessageCode(tree),
|
|
7
|
-
triggerEvent: getTriggerEvent(tree),
|
|
8
|
-
messageStructure: getMessageStructure(tree)
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function getVersion(tree) {
|
|
12
|
-
const result = value(tree, "MSH-12");
|
|
13
|
-
return result?.value || void 0;
|
|
14
|
-
}
|
|
15
|
-
function getMessageCode(tree) {
|
|
16
|
-
const result = value(tree, "MSH-9.1");
|
|
17
|
-
return result?.value || void 0;
|
|
18
|
-
}
|
|
19
|
-
function getTriggerEvent(tree) {
|
|
20
|
-
const result = value(tree, "MSH-9.2");
|
|
21
|
-
return result?.value || void 0;
|
|
22
|
-
}
|
|
23
|
-
function getMessageStructure(tree) {
|
|
24
|
-
const result = value(tree, "MSH-9.3");
|
|
25
|
-
return result?.value || void 0;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
1
|
// src/index.ts
|
|
29
|
-
import {
|
|
2
|
+
import { value } from "@rethinkhealth/hl7v2-util-query";
|
|
3
|
+
import { satisfies } from "@rethinkhealth/hl7v2-util-semver";
|
|
4
|
+
import ensureError from "ensure-error";
|
|
30
5
|
import { lintRule } from "unified-lint-rule";
|
|
31
6
|
var defaultOptions = {
|
|
32
7
|
expression: "<3.0.0 >=2.3"
|
|
@@ -40,30 +15,44 @@ var hl7v2LintMessageVersion = lintRule(
|
|
|
40
15
|
const options = { ...defaultOptions, ...opts };
|
|
41
16
|
if (tree.type !== "root") {
|
|
42
17
|
file.fail(
|
|
43
|
-
`Root node type must be 'root' \u2014 received '${tree.type}' instead
|
|
18
|
+
`Root node type must be 'root' \u2014 received '${tree.type}' instead`,
|
|
19
|
+
{
|
|
20
|
+
ancestors: [tree],
|
|
21
|
+
place: tree.position
|
|
22
|
+
}
|
|
44
23
|
);
|
|
45
24
|
return;
|
|
46
25
|
}
|
|
47
26
|
const rootTree = tree;
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
const result = value(rootTree, "MSH-12");
|
|
28
|
+
if (!result?.value || result.value === "") {
|
|
29
|
+
file.fail("Required MSH-12 (version) field is missing or empty", {
|
|
30
|
+
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
31
|
+
place: result?.node?.position || result?.ancestors.at(-1)?.position || rootTree.position
|
|
32
|
+
});
|
|
52
33
|
return;
|
|
53
34
|
}
|
|
35
|
+
let isValid = false;
|
|
54
36
|
try {
|
|
55
|
-
|
|
56
|
-
} catch {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
37
|
+
isValid = satisfies(result.value, options.expression);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
const error = ensureError(err);
|
|
40
|
+
file.fail(`MSH-12 (version) field value '${result.value}' is not valid`, {
|
|
41
|
+
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
42
|
+
place: result?.node?.position || rootTree.position,
|
|
43
|
+
cause: error
|
|
44
|
+
});
|
|
60
45
|
return;
|
|
61
46
|
}
|
|
62
|
-
const isValid = satisfies(messageInfo.version, options.expression);
|
|
63
47
|
if (!isValid) {
|
|
64
48
|
file.fail(
|
|
65
|
-
`MSH-12 (version) field value '${
|
|
49
|
+
`MSH-12 (version) field value '${result.value}' does not satisfy expression '${options.expression}'`,
|
|
50
|
+
{
|
|
51
|
+
ancestors: result ? [...result.ancestors, result.node] : [rootTree],
|
|
52
|
+
place: result?.node?.position || result?.ancestors.at(-1)?.position || rootTree.position
|
|
53
|
+
}
|
|
66
54
|
);
|
|
55
|
+
return;
|
|
67
56
|
}
|
|
68
57
|
}
|
|
69
58
|
);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
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 type 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 (tree, file, opts) => {\n const options = { ...defaultOptions, ...opts };\n\n // 1. Validate tree is a Root node.\n if (tree.type !== \"root\") {\n file.fail(\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\");\n\n if (!result?.value || result.value === \"\") {\n file.fail(\"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 (err) {\n const error = ensureError(err);\n file.fail(`MSH-12 (version) field value '${result.value}' is not valid`, {\n ancestors: result ? [...result.ancestors, result.node] : [rootTree],\n place: result?.node?.position || rootTree.position,\n cause: error,\n });\n return;\n }\n\n if (!isValid) {\n file.fail(\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 return;\n }\n }\n);\n\nexport default hl7v2LintMessageVersion;\n"],"mappings":";AACA,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,OAAO,iBAAiB;AACxB,SAAS,gBAAgB;AAMzB,IAAM,iBAAiB;AAAA,EACrB,YAAY;AACd;AAEA,IAAM,0BAA0B;AAAA,EAC9B;AAAA,IACE,QAAQ;AAAA,IACR,KAAK;AAAA,EACP;AAAA,EACA,CAAC,MAAM,MAAM,SAAS;AACpB,UAAM,UAAU,EAAE,GAAG,gBAAgB,GAAG,KAAK;AAG7C,QAAI,KAAK,SAAS,QAAQ;AACxB,WAAK;AAAA,QACH,kDAA6C,KAAK,IAAI;AAAA,QACtD;AAAA,UACE,WAAW,CAAC,IAAI;AAAA,UAChB,OAAO,KAAK;AAAA,QACd;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,WAAW;AAGjB,UAAM,SAAS,MAAM,UAAU,QAAQ;AAEvC,QAAI,CAAC,QAAQ,SAAS,OAAO,UAAU,IAAI;AACzC,WAAK,KAAK,uDAAuD;AAAA,QAC/D,WAAW,SAAS,CAAC,GAAG,OAAO,WAAW,OAAO,IAAI,IAAI,CAAC,QAAQ;AAAA,QAClE,OACE,QAAQ,MAAM,YACd,QAAQ,UAAU,GAAG,EAAE,GAAG,YAC1B,SAAS;AAAA,MACb,CAAC;AACD;AAAA,IACF;AAGA,QAAI,UAAU;AACd,QAAI;AACF,gBAAU,UAAU,OAAO,OAAO,QAAQ,UAAU;AAAA,IACtD,SAAS,KAAK;AACZ,YAAM,QAAQ,YAAY,GAAG;AAC7B,WAAK,KAAK,iCAAiC,OAAO,KAAK,kBAAkB;AAAA,QACvE,WAAW,SAAS,CAAC,GAAG,OAAO,WAAW,OAAO,IAAI,IAAI,CAAC,QAAQ;AAAA,QAClE,OAAO,QAAQ,MAAM,YAAY,SAAS;AAAA,QAC1C,OAAO;AAAA,MACT,CAAC;AACD;AAAA,IACF;AAEA,QAAI,CAAC,SAAS;AACZ,WAAK;AAAA,QACH,iCAAiC,OAAO,KAAK,kCAAkC,QAAQ,UAAU;AAAA,QACjG;AAAA,UACE,WAAW,SAAS,CAAC,GAAG,OAAO,WAAW,OAAO,IAAI,IAAI,CAAC,QAAQ;AAAA,UAClE,OACE,QAAQ,MAAM,YACd,QAAQ,UAAU,GAAG,EAAE,GAAG,YAC1B,SAAS;AAAA,QACb;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rethinkhealth/hl7v2-lint-message-version",
|
|
3
3
|
"description": "hl7v2-lint rule to warn when message version is not supported",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Melek Somai",
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
".": "./dist/index.js"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"ensure-error": "^5.0.0",
|
|
19
20
|
"unified-lint-rule": "3.0.1",
|
|
20
|
-
"@rethinkhealth/hl7v2-util-query": "0.
|
|
21
|
-
"@rethinkhealth/hl7v2-util-semver": "0.
|
|
21
|
+
"@rethinkhealth/hl7v2-util-query": "0.3.0",
|
|
22
|
+
"@rethinkhealth/hl7v2-util-semver": "0.3.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/node": "24.10.0",
|
|
@@ -29,11 +30,11 @@
|
|
|
29
30
|
"unified": "^11.0.5",
|
|
30
31
|
"vfile": "^6.0.3",
|
|
31
32
|
"vitest": "^4.0.6",
|
|
32
|
-
"@rethinkhealth/hl7v2-
|
|
33
|
-
"@rethinkhealth/hl7v2-
|
|
33
|
+
"@rethinkhealth/hl7v2-ast": "0.3.0",
|
|
34
|
+
"@rethinkhealth/hl7v2-builder": "0.3.0",
|
|
34
35
|
"@rethinkhealth/testing": "0.0.2",
|
|
35
|
-
"@rethinkhealth/
|
|
36
|
-
"@rethinkhealth/
|
|
36
|
+
"@rethinkhealth/hl7v2-util-message-info": "0.3.0",
|
|
37
|
+
"@rethinkhealth/tsconfig": "0.0.1"
|
|
37
38
|
},
|
|
38
39
|
"repository": "rethinkhealth/hl7v2.git",
|
|
39
40
|
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|