@rethinkhealth/hl7v2-lint-message-version 0.2.22 → 0.2.24

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 CHANGED
@@ -1,7 +1,7 @@
1
- import type { Node } from "@rethinkhealth/hl7v2-ast";
1
+ import type { Nodes } from "@rethinkhealth/hl7v2-ast";
2
2
  export type MessageVersionLintOptions = {
3
3
  expression: string;
4
4
  };
5
- declare const hl7v2LintMessageVersion: import("unified-lint-rule").Plugin<Node, MessageVersionLintOptions>;
5
+ declare const hl7v2LintMessageVersion: import("unified-lint-rule").Plugin<Nodes, MessageVersionLintOptions>;
6
6
  export default hl7v2LintMessageVersion;
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,0BAA0B,CAAC;AAK3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAMF,QAAA,MAAM,uBAAuB,qEA6D5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAQ,MAAM,0BAA0B,CAAC;AAK5D,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAMF,QAAA,MAAM,uBAAuB,sEAuD5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -14,48 +14,38 @@ var hl7v2LintMessageVersion = lintRule(
14
14
  const options = { ...defaultOptions, ...opts };
15
15
  if (tree.type !== "root") {
16
16
  file.fail(
17
- `The root node is expected to be a message. Received ${tree.type} instead.`,
18
- {
19
- ancestors: [tree],
20
- place: tree.position
21
- }
17
+ `The root node is expected to be a Root node. Received ${tree.type} instead.`
22
18
  );
23
- return;
24
19
  }
25
20
  const msh12 = find(tree, "MSH-12");
26
- const place = msh12?.position ?? tree.position;
27
21
  if (!msh12) {
28
- file.fail("Message version (MSH.12) is not present.", {
29
- ancestors: [tree],
30
- place
31
- });
32
- return;
22
+ file.fail("MSH-12 segment is missing.");
33
23
  }
34
24
  const versionStr = value(tree, "MSH-12");
35
25
  if (!versionStr) {
36
26
  file.fail(
37
- "Unexpected value `undefined` for `MSH-12`, expected `string`",
38
- {
39
- ancestors: [tree, msh12],
40
- place
41
- }
27
+ "MSH-12 segment value is required. Received empty string instead."
42
28
  );
43
- return;
44
29
  }
45
- const version = parse(versionStr);
46
- if (!version) {
47
- file.fail("The message version is not valid.", {
48
- ancestors: [tree, msh12],
49
- place
50
- });
51
- return;
30
+ try {
31
+ parse(versionStr ?? "");
32
+ } catch (_err) {
33
+ file.fail(
34
+ `MSH-12 segment value is invalid. Received '${versionStr}' instead.`
35
+ );
52
36
  }
53
- if (!satisfies(versionStr, options.expression)) {
54
- file.fail("Message version is not supported.", {
55
- ancestors: [tree, msh12],
56
- place
57
- });
58
- return;
37
+ let isValid = false;
38
+ try {
39
+ isValid = satisfies(versionStr ?? "", options.expression);
40
+ } catch (_err) {
41
+ file.fail(
42
+ `MSH-12 segment value is not supported. Received '${versionStr}' instead.`
43
+ );
44
+ }
45
+ if (!isValid) {
46
+ file.fail(
47
+ `MSH-12 segment value is not supported. Received '${versionStr}' instead.`
48
+ );
59
49
  }
60
50
  }
61
51
  );
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Node, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport { find, value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { parse, satisfies } from \"@rethinkhealth/hl7v2-util-semver\";\nimport { lintRule } from \"unified-lint-rule\";\n\nexport type MessageVersionLintOptions = {\n expression: string;\n};\n\nconst defaultOptions: Required<MessageVersionLintOptions> = {\n expression: \"<3.0.0 >=2.3\",\n};\n\nconst hl7v2LintMessageVersion = lintRule<Node, 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 if (tree.type !== \"root\") {\n file.fail(\n `The root node is expected to be a message. Received ${tree.type} instead.`,\n {\n ancestors: [tree],\n place: tree.position,\n }\n );\n return;\n }\n\n const msh12 = find(tree as Root, \"MSH-12\");\n const place = msh12?.position ?? tree.position;\n\n if (!msh12) {\n file.fail(\"Message version (MSH.12) is not present.\", {\n ancestors: [tree],\n place,\n });\n return;\n }\n\n const versionStr = value(tree as Root, \"MSH-12\");\n\n if (!versionStr) {\n file.fail(\n \"Unexpected value `undefined` for `MSH-12`, expected `string`\",\n {\n ancestors: [tree, msh12],\n place,\n }\n );\n return;\n }\n\n const version = parse(versionStr);\n\n if (!version) {\n file.fail(\"The message version is not valid.\", {\n ancestors: [tree, msh12],\n place,\n });\n return;\n }\n\n if (!satisfies(versionStr, options.expression)) {\n file.fail(\"Message version is not supported.\", {\n ancestors: [tree, msh12],\n place,\n });\n return;\n }\n }\n);\n\nexport default hl7v2LintMessageVersion;\n"],"mappings":";AACA,SAAS,MAAM,aAAa;AAC5B,SAAS,OAAO,iBAAiB;AACjC,SAAS,gBAAgB;AAMzB,IAAM,iBAAsD;AAAA,EAC1D,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;AAE7C,QAAI,KAAK,SAAS,QAAQ;AACxB,WAAK;AAAA,QACH,uDAAuD,KAAK,IAAI;AAAA,QAChE;AAAA,UACE,WAAW,CAAC,IAAI;AAAA,UAChB,OAAO,KAAK;AAAA,QACd;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,QAAQ,KAAK,MAAc,QAAQ;AACzC,UAAM,QAAQ,OAAO,YAAY,KAAK;AAEtC,QAAI,CAAC,OAAO;AACV,WAAK,KAAK,4CAA4C;AAAA,QACpD,WAAW,CAAC,IAAI;AAAA,QAChB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,UAAM,aAAa,MAAM,MAAc,QAAQ;AAE/C,QAAI,CAAC,YAAY;AACf,WAAK;AAAA,QACH;AAAA,QACA;AAAA,UACE,WAAW,CAAC,MAAM,KAAK;AAAA,UACvB;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,UAAU,MAAM,UAAU;AAEhC,QAAI,CAAC,SAAS;AACZ,WAAK,KAAK,qCAAqC;AAAA,QAC7C,WAAW,CAAC,MAAM,KAAK;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,QAAI,CAAC,UAAU,YAAY,QAAQ,UAAU,GAAG;AAC9C,WAAK,KAAK,qCAAqC;AAAA,QAC7C,WAAW,CAAC,MAAM,KAAK;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Nodes, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport { find, value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { parse, satisfies } from \"@rethinkhealth/hl7v2-util-semver\";\nimport { lintRule } from \"unified-lint-rule\";\n\nexport type MessageVersionLintOptions = {\n expression: string;\n};\n\nconst defaultOptions: Required<MessageVersionLintOptions> = {\n expression: \"<3.0.0 >=2.3\",\n};\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. Ensure the root node is a Root node.\n if (tree.type !== \"root\") {\n file.fail(\n `The root node is expected to be a Root node. Received ${tree.type} instead.`\n );\n }\n\n // 2. Ensure the MSH-12 segment is present.\n const msh12 = find(tree as Root, \"MSH-12\");\n\n if (!msh12) {\n file.fail(\"MSH-12 segment is missing.\");\n }\n\n const versionStr = value(tree as Root, \"MSH-12\");\n\n if (!versionStr) {\n file.fail(\n \"MSH-12 segment value is required. Received empty string instead.\"\n );\n }\n\n // 3. Ensure the MSH-12 segment value is a valid version.\n try {\n parse(versionStr ?? \"\");\n } catch (_err) {\n file.fail(\n `MSH-12 segment value is invalid. Received '${versionStr}' instead.`\n );\n }\n\n // 4. Ensure the MSH-12 segment value satisfies the expression.\n let isValid = false;\n try {\n isValid = satisfies(versionStr ?? \"\", options.expression);\n } catch (_err) {\n file.fail(\n `MSH-12 segment value is not supported. Received '${versionStr}' instead.`\n );\n }\n\n if (!isValid) {\n file.fail(\n `MSH-12 segment value is not supported. Received '${versionStr}' instead.`\n );\n }\n }\n);\n\nexport default hl7v2LintMessageVersion;\n"],"mappings":";AACA,SAAS,MAAM,aAAa;AAC5B,SAAS,OAAO,iBAAiB;AACjC,SAAS,gBAAgB;AAMzB,IAAM,iBAAsD;AAAA,EAC1D,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,yDAAyD,KAAK,IAAI;AAAA,MACpE;AAAA,IACF;AAGA,UAAM,QAAQ,KAAK,MAAc,QAAQ;AAEzC,QAAI,CAAC,OAAO;AACV,WAAK,KAAK,4BAA4B;AAAA,IACxC;AAEA,UAAM,aAAa,MAAM,MAAc,QAAQ;AAE/C,QAAI,CAAC,YAAY;AACf,WAAK;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAGA,QAAI;AACF,YAAM,cAAc,EAAE;AAAA,IACxB,SAAS,MAAM;AACb,WAAK;AAAA,QACH,8CAA8C,UAAU;AAAA,MAC1D;AAAA,IACF;AAGA,QAAI,UAAU;AACd,QAAI;AACF,gBAAU,UAAU,cAAc,IAAI,QAAQ,UAAU;AAAA,IAC1D,SAAS,MAAM;AACb,WAAK;AAAA,QACH,oDAAoD,UAAU;AAAA,MAChE;AAAA,IACF;AAEA,QAAI,CAAC,SAAS;AACZ,WAAK;AAAA,QACH,oDAAoD,UAAU;AAAA,MAChE;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.2.22",
4
+ "version": "0.2.24",
5
5
  "license": "MIT",
6
6
  "author": {
7
7
  "name": "Melek Somai",
@@ -17,23 +17,22 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "unified-lint-rule": "3.0.1",
20
- "@rethinkhealth/hl7v2-util-semver": "0.2.22",
21
- "@rethinkhealth/hl7v2-util-query": "0.2.22"
20
+ "@rethinkhealth/hl7v2-util-query": "0.2.24",
21
+ "@rethinkhealth/hl7v2-util-semver": "0.2.24"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/node": "24.8.1",
24
+ "@types/node": "24.9.2",
25
25
  "@types/unist": "^3.0.3",
26
- "@vitest/coverage-v8": "^3.2.4",
26
+ "@vitest/coverage-v8": "^4.0.5",
27
27
  "tsup": "8.5.0",
28
28
  "typescript": "^5.9.3",
29
29
  "unified": "^11.0.5",
30
30
  "vfile": "^6.0.3",
31
- "vfile-reporter": "^8.1.1",
32
- "vitest": "^3.2.4",
33
- "@rethinkhealth/hl7v2-builder": "0.2.22",
34
- "@rethinkhealth/hl7v2-ast": "0.2.22",
35
- "@rethinkhealth/testing": "0.0.1",
36
- "@rethinkhealth/tsconfig": "0.0.1"
31
+ "vitest": "^4.0.6",
32
+ "@rethinkhealth/testing": "0.0.2",
33
+ "@rethinkhealth/tsconfig": "0.0.1",
34
+ "@rethinkhealth/hl7v2-builder": "0.2.24",
35
+ "@rethinkhealth/hl7v2-ast": "0.2.24"
37
36
  },
38
37
  "repository": "rethinkhealth/hl7v2.git",
39
38
  "homepage": "https://www.rethinkhealth.io/hl7v2/docs",