@rethinkhealth/hl7v2-jsonify 0.12.0 → 0.13.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/dist/index.js CHANGED
@@ -1,77 +1,62 @@
1
- // src/runtime.ts
1
+ //#region src/runtime.ts
2
2
  function toJsonRuntime(root) {
3
- const r = root;
4
- const out = [];
5
- for (const child of r.children) {
6
- if (child.type === "segment") {
7
- out.push(processSegment(child));
8
- } else if (child.type === "group") {
9
- out.push(processGroup(child));
10
- }
11
- }
12
- return out;
3
+ const r = root;
4
+ const out = [];
5
+ for (const child of r.children) if (child.type === "segment") out.push(processSegment(child));
6
+ else if (child.type === "group") out.push(processGroup(child));
7
+ return out;
13
8
  }
14
9
  function processSegment(segment) {
15
- const fields = [];
16
- for (const f of segment.children) {
17
- fields.push(materializeField(f));
18
- }
19
- return { fields, segment: segment.name };
10
+ const fields = [];
11
+ for (const f of segment.children) fields.push(materializeField(f));
12
+ return {
13
+ fields,
14
+ segment: segment.name
15
+ };
20
16
  }
21
17
  function processGroup(group) {
22
- const children = [];
23
- for (const child of group.children) {
24
- if (child.type === "segment") {
25
- children.push(processSegment(child));
26
- } else if (child.type === "group") {
27
- children.push(processGroup(child));
28
- }
29
- }
30
- return { children, group: group.name ?? "" };
18
+ const children = [];
19
+ for (const child of group.children) if (child.type === "segment") children.push(processSegment(child));
20
+ else if (child.type === "group") children.push(processGroup(child));
21
+ return {
22
+ children,
23
+ group: group.name ?? ""
24
+ };
31
25
  }
32
26
  function materializeField(field) {
33
- const toComponent = (c) => {
34
- if (c.children?.length === 0) {
35
- return "";
36
- }
37
- if (c.children?.length === 1) {
38
- return c.children[0].value;
39
- }
40
- return c.children ? c.children.map((sc) => sc.value) : [];
41
- };
42
- const toRepetitionArray = (r) => r.children.map((c) => toComponent(c));
43
- const repetitions = field.children;
44
- if (repetitions.length === 1) {
45
- const rep = repetitions[0];
46
- if (!rep) {
47
- throw new Error("Expected a field repetition");
48
- }
49
- if (rep.children.length === 1) {
50
- const comp = rep.children[0];
51
- const compVal = toComponent(comp);
52
- return Array.isArray(compVal) ? [compVal] : compVal;
53
- }
54
- return toRepetitionArray(rep);
55
- }
56
- return repetitions.map((r) => {
57
- const rep = r;
58
- if (rep.children.length === 1) {
59
- return toComponent(rep.children[0]);
60
- }
61
- return toRepetitionArray(rep);
62
- });
27
+ const toComponent = (c) => {
28
+ if (c.children?.length === 0) return "";
29
+ if (c.children?.length === 1) return c.children[0].value;
30
+ return c.children ? c.children.map((sc) => sc.value) : [];
31
+ };
32
+ const toRepetitionArray = (r) => r.children.map((c) => toComponent(c));
33
+ const repetitions = field.children;
34
+ if (repetitions.length === 1) {
35
+ const rep = repetitions[0];
36
+ if (!rep) throw new Error("Expected a field repetition");
37
+ if (rep.children.length === 1) {
38
+ const comp = rep.children[0];
39
+ const compVal = toComponent(comp);
40
+ return Array.isArray(compVal) ? [compVal] : compVal;
41
+ }
42
+ return toRepetitionArray(rep);
43
+ }
44
+ return repetitions.map((r) => {
45
+ const rep = r;
46
+ if (rep.children.length === 1) return toComponent(rep.children[0]);
47
+ return toRepetitionArray(rep);
48
+ });
63
49
  }
64
-
65
- // src/processor.ts
50
+ //#endregion
51
+ //#region src/processor.ts
66
52
  function hl7v2Jsonify() {
67
- const self = this;
68
- function compiler(tree) {
69
- return toJsonRuntime(tree);
70
- }
71
- self.compiler = compiler;
53
+ const self = this;
54
+ function compiler(tree) {
55
+ return toJsonRuntime(tree);
56
+ }
57
+ self.compiler = compiler;
72
58
  }
73
- export {
74
- hl7v2Jsonify,
75
- toJsonRuntime
76
- };
59
+ //#endregion
60
+ export { hl7v2Jsonify, toJsonRuntime };
61
+
77
62
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime.ts","../src/processor.ts"],"sourcesContent":["import type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Nodes,\n Root,\n Segment,\n Subcomponent,\n} from \"@rethinkhealth/hl7v2-ast\";\n\nimport type {\n FieldJson,\n GroupJson,\n Hl7v2JsonResult,\n SegmentJson,\n} from \"./types\";\n\nexport function toJsonRuntime(root: Nodes): Hl7v2JsonResult {\n const r = root as Root;\n const out: Hl7v2JsonResult = [];\n\n for (const child of r.children) {\n if (child.type === \"segment\") {\n out.push(processSegment(child as Segment));\n } else if (child.type === \"group\") {\n out.push(processGroup(child as Group));\n }\n }\n\n return out;\n}\n\nfunction processSegment(segment: Segment): SegmentJson {\n const fields: (FieldJson | FieldJson[])[] = [];\n\n for (const f of segment.children) {\n fields.push(materializeField(f));\n }\n\n return { fields, segment: segment.name };\n}\n\nfunction processGroup(group: Group): GroupJson {\n const children: (SegmentJson | GroupJson)[] = [];\n\n for (const child of group.children) {\n if (child.type === \"segment\") {\n children.push(processSegment(child as Segment));\n } else if (child.type === \"group\") {\n children.push(processGroup(child as Group));\n }\n }\n\n return { children, group: group.name ?? \"\" };\n}\n\n// Convert a Field into JSON-friendly value: string or nested arrays representing reps/components/subcomponents\nfunction materializeField(field: Field): FieldJson | FieldJson[] {\n const toComponent = (c: Component): FieldJson => {\n if (c.children?.length === 0) {\n return \"\";\n }\n if (c.children?.length === 1) {\n return (c.children[0] as Subcomponent).value;\n }\n return c.children ? c.children.map((sc) => (sc as Subcomponent).value) : [];\n };\n\n const toRepetitionArray = (r: FieldRepetition): FieldJson[] =>\n r.children.map((c) => toComponent(c as Component));\n\n const repetitions = field.children as FieldRepetition[];\n\n if (repetitions.length === 1) {\n const rep = repetitions[0];\n\n if (!rep) {\n throw new Error(\"Expected a field repetition\");\n }\n\n if (rep.children.length === 1) {\n const comp = rep.children[0] as Component;\n const compVal = toComponent(comp);\n\n return Array.isArray(compVal) ? [compVal] : compVal;\n }\n return toRepetitionArray(rep);\n }\n\n // Multiple repetitions: project each repetition to a value (string or array)\n return repetitions.map((r) => {\n const rep = r as FieldRepetition;\n if (rep.children.length === 1) {\n return toComponent(rep.children[0] as Component);\n }\n return toRepetitionArray(rep);\n }) as string[];\n}\n","import type { Node, Nodes, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport type { Processor } from \"unified\";\n\nimport { toJsonRuntime } from \"./runtime\";\nimport type { Hl7v2JsonResult } from \"./types\";\n\nexport function hl7v2Jsonify(this: Processor) {\n const self = this as unknown as Processor<\n Node,\n undefined,\n undefined,\n Root,\n undefined\n >;\n\n function compiler(tree: Nodes): Hl7v2JsonResult {\n return toJsonRuntime(tree);\n }\n\n self.compiler = compiler as unknown as typeof self.compiler;\n}\n"],"mappings":";AAkBO,SAAS,cAAc,MAA8B;AAC1D,QAAM,IAAI;AACV,QAAM,MAAuB,CAAC;AAE9B,aAAW,SAAS,EAAE,UAAU;AAC9B,QAAI,MAAM,SAAS,WAAW;AAC5B,UAAI,KAAK,eAAe,KAAgB,CAAC;AAAA,IAC3C,WAAW,MAAM,SAAS,SAAS;AACjC,UAAI,KAAK,aAAa,KAAc,CAAC;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,SAA+B;AACrD,QAAM,SAAsC,CAAC;AAE7C,aAAW,KAAK,QAAQ,UAAU;AAChC,WAAO,KAAK,iBAAiB,CAAC,CAAC;AAAA,EACjC;AAEA,SAAO,EAAE,QAAQ,SAAS,QAAQ,KAAK;AACzC;AAEA,SAAS,aAAa,OAAyB;AAC7C,QAAM,WAAwC,CAAC;AAE/C,aAAW,SAAS,MAAM,UAAU;AAClC,QAAI,MAAM,SAAS,WAAW;AAC5B,eAAS,KAAK,eAAe,KAAgB,CAAC;AAAA,IAChD,WAAW,MAAM,SAAS,SAAS;AACjC,eAAS,KAAK,aAAa,KAAc,CAAC;AAAA,IAC5C;AAAA,EACF;AAEA,SAAO,EAAE,UAAU,OAAO,MAAM,QAAQ,GAAG;AAC7C;AAGA,SAAS,iBAAiB,OAAuC;AAC/D,QAAM,cAAc,CAAC,MAA4B;AAC/C,QAAI,EAAE,UAAU,WAAW,GAAG;AAC5B,aAAO;AAAA,IACT;AACA,QAAI,EAAE,UAAU,WAAW,GAAG;AAC5B,aAAQ,EAAE,SAAS,CAAC,EAAmB;AAAA,IACzC;AACA,WAAO,EAAE,WAAW,EAAE,SAAS,IAAI,CAAC,OAAQ,GAAoB,KAAK,IAAI,CAAC;AAAA,EAC5E;AAEA,QAAM,oBAAoB,CAAC,MACzB,EAAE,SAAS,IAAI,CAAC,MAAM,YAAY,CAAc,CAAC;AAEnD,QAAM,cAAc,MAAM;AAE1B,MAAI,YAAY,WAAW,GAAG;AAC5B,UAAM,MAAM,YAAY,CAAC;AAEzB,QAAI,CAAC,KAAK;AACR,YAAM,IAAI,MAAM,6BAA6B;AAAA,IAC/C;AAEA,QAAI,IAAI,SAAS,WAAW,GAAG;AAC7B,YAAM,OAAO,IAAI,SAAS,CAAC;AAC3B,YAAM,UAAU,YAAY,IAAI;AAEhC,aAAO,MAAM,QAAQ,OAAO,IAAI,CAAC,OAAO,IAAI;AAAA,IAC9C;AACA,WAAO,kBAAkB,GAAG;AAAA,EAC9B;AAGA,SAAO,YAAY,IAAI,CAAC,MAAM;AAC5B,UAAM,MAAM;AACZ,QAAI,IAAI,SAAS,WAAW,GAAG;AAC7B,aAAO,YAAY,IAAI,SAAS,CAAC,CAAc;AAAA,IACjD;AACA,WAAO,kBAAkB,GAAG;AAAA,EAC9B,CAAC;AACH;;;AC5FO,SAAS,eAA8B;AAC5C,QAAM,OAAO;AAQb,WAAS,SAAS,MAA8B;AAC9C,WAAO,cAAc,IAAI;AAAA,EAC3B;AAEA,OAAK,WAAW;AAClB;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/runtime.ts","../src/processor.ts"],"sourcesContent":["import type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Nodes,\n Root,\n Segment,\n Subcomponent,\n} from \"@rethinkhealth/hl7v2-ast\";\n\nimport type {\n FieldJson,\n GroupJson,\n Hl7v2JsonResult,\n SegmentJson,\n} from \"./types\";\n\nexport function toJsonRuntime(root: Nodes): Hl7v2JsonResult {\n const r = root as Root;\n const out: Hl7v2JsonResult = [];\n\n for (const child of r.children) {\n if (child.type === \"segment\") {\n out.push(processSegment(child as Segment));\n } else if (child.type === \"group\") {\n out.push(processGroup(child as Group));\n }\n }\n\n return out;\n}\n\nfunction processSegment(segment: Segment): SegmentJson {\n const fields: (FieldJson | FieldJson[])[] = [];\n\n for (const f of segment.children) {\n fields.push(materializeField(f));\n }\n\n return { fields, segment: segment.name };\n}\n\nfunction processGroup(group: Group): GroupJson {\n const children: (SegmentJson | GroupJson)[] = [];\n\n for (const child of group.children) {\n if (child.type === \"segment\") {\n children.push(processSegment(child as Segment));\n } else if (child.type === \"group\") {\n children.push(processGroup(child as Group));\n }\n }\n\n return { children, group: group.name ?? \"\" };\n}\n\n// Convert a Field into JSON-friendly value: string or nested arrays representing reps/components/subcomponents\nfunction materializeField(field: Field): FieldJson | FieldJson[] {\n const toComponent = (c: Component): FieldJson => {\n if (c.children?.length === 0) {\n return \"\";\n }\n if (c.children?.length === 1) {\n return (c.children[0] as Subcomponent).value;\n }\n return c.children ? c.children.map((sc) => (sc as Subcomponent).value) : [];\n };\n\n const toRepetitionArray = (r: FieldRepetition): FieldJson[] =>\n r.children.map((c) => toComponent(c as Component));\n\n const repetitions = field.children as FieldRepetition[];\n\n if (repetitions.length === 1) {\n const rep = repetitions[0];\n\n if (!rep) {\n throw new Error(\"Expected a field repetition\");\n }\n\n if (rep.children.length === 1) {\n const comp = rep.children[0] as Component;\n const compVal = toComponent(comp);\n\n return Array.isArray(compVal) ? [compVal] : compVal;\n }\n return toRepetitionArray(rep);\n }\n\n // Multiple repetitions: project each repetition to a value (string or array)\n return repetitions.map((r) => {\n const rep = r as FieldRepetition;\n if (rep.children.length === 1) {\n return toComponent(rep.children[0] as Component);\n }\n return toRepetitionArray(rep);\n }) as string[];\n}\n","import type { Node, Nodes, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport type { Processor } from \"unified\";\n\nimport { toJsonRuntime } from \"./runtime\";\nimport type { Hl7v2JsonResult } from \"./types\";\n\nexport function hl7v2Jsonify(this: Processor) {\n const self = this as unknown as Processor<\n Node,\n undefined,\n undefined,\n Root,\n undefined\n >;\n\n function compiler(tree: Nodes): Hl7v2JsonResult {\n return toJsonRuntime(tree);\n }\n\n self.compiler = compiler as unknown as typeof self.compiler;\n}\n"],"mappings":";AAkBA,SAAgB,cAAc,MAA8B;CAC1D,MAAM,IAAI;CACV,MAAM,MAAuB,EAAE;AAE/B,MAAK,MAAM,SAAS,EAAE,SACpB,KAAI,MAAM,SAAS,UACjB,KAAI,KAAK,eAAe,MAAiB,CAAC;UACjC,MAAM,SAAS,QACxB,KAAI,KAAK,aAAa,MAAe,CAAC;AAI1C,QAAO;;AAGT,SAAS,eAAe,SAA+B;CACrD,MAAM,SAAsC,EAAE;AAE9C,MAAK,MAAM,KAAK,QAAQ,SACtB,QAAO,KAAK,iBAAiB,EAAE,CAAC;AAGlC,QAAO;EAAE;EAAQ,SAAS,QAAQ;EAAM;;AAG1C,SAAS,aAAa,OAAyB;CAC7C,MAAM,WAAwC,EAAE;AAEhD,MAAK,MAAM,SAAS,MAAM,SACxB,KAAI,MAAM,SAAS,UACjB,UAAS,KAAK,eAAe,MAAiB,CAAC;UACtC,MAAM,SAAS,QACxB,UAAS,KAAK,aAAa,MAAe,CAAC;AAI/C,QAAO;EAAE;EAAU,OAAO,MAAM,QAAQ;EAAI;;AAI9C,SAAS,iBAAiB,OAAuC;CAC/D,MAAM,eAAe,MAA4B;AAC/C,MAAI,EAAE,UAAU,WAAW,EACzB,QAAO;AAET,MAAI,EAAE,UAAU,WAAW,EACzB,QAAQ,EAAE,SAAS,GAAoB;AAEzC,SAAO,EAAE,WAAW,EAAE,SAAS,KAAK,OAAQ,GAAoB,MAAM,GAAG,EAAE;;CAG7E,MAAM,qBAAqB,MACzB,EAAE,SAAS,KAAK,MAAM,YAAY,EAAe,CAAC;CAEpD,MAAM,cAAc,MAAM;AAE1B,KAAI,YAAY,WAAW,GAAG;EAC5B,MAAM,MAAM,YAAY;AAExB,MAAI,CAAC,IACH,OAAM,IAAI,MAAM,8BAA8B;AAGhD,MAAI,IAAI,SAAS,WAAW,GAAG;GAC7B,MAAM,OAAO,IAAI,SAAS;GAC1B,MAAM,UAAU,YAAY,KAAK;AAEjC,UAAO,MAAM,QAAQ,QAAQ,GAAG,CAAC,QAAQ,GAAG;;AAE9C,SAAO,kBAAkB,IAAI;;AAI/B,QAAO,YAAY,KAAK,MAAM;EAC5B,MAAM,MAAM;AACZ,MAAI,IAAI,SAAS,WAAW,EAC1B,QAAO,YAAY,IAAI,SAAS,GAAgB;AAElD,SAAO,kBAAkB,IAAI;GAC7B;;;;AC3FJ,SAAgB,eAA8B;CAC5C,MAAM,OAAO;CAQb,SAAS,SAAS,MAA8B;AAC9C,SAAO,cAAc,KAAK;;AAG5B,MAAK,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rethinkhealth/hl7v2-jsonify",
3
- "version": "0.12.0",
3
+ "version": "0.13.1",
4
4
  "description": "hl7v2 plugin to transform hl7v2 messages to a simplified JSON representation",
5
5
  "keywords": [
6
6
  "health",
@@ -30,25 +30,25 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "unified": "11.0.5",
33
- "@rethinkhealth/hl7v2-ast": "0.12.0"
33
+ "@rethinkhealth/hl7v2-ast": "0.13.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.5.0",
37
37
  "@types/unist": "^3.0.3",
38
38
  "@vitest/coverage-v8": "4.1.0",
39
- "tsup": "^8.5.1",
39
+ "tsdown": "0.21.7",
40
40
  "typescript": "^5.9.3",
41
41
  "vitest": "4.1.0",
42
- "@rethinkhealth/hl7v2-builder": "0.12.0",
43
- "@rethinkhealth/tsconfig": "0.0.1",
44
- "@rethinkhealth/testing": "0.0.2"
42
+ "@rethinkhealth/hl7v2-builder": "0.13.1",
43
+ "@rethinkhealth/testing": "0.0.2",
44
+ "@rethinkhealth/tsconfig": "0.0.1"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=18"
48
48
  },
49
49
  "packageManager": "pnpm@10.14.0",
50
50
  "scripts": {
51
- "build": "tsup && tsc --emitDeclarationOnly",
51
+ "build": "tsdown && tsc --emitDeclarationOnly",
52
52
  "check-types": "tsc --noEmit",
53
53
  "test": "vitest run",
54
54
  "test:coverage": "vitest run --coverage",