@glion/jsonify 0.20.0 → 0.22.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.js CHANGED
@@ -20,7 +20,8 @@ function processGroup(group) {
20
20
  else if (child.type === "group") children.push(processGroup(child));
21
21
  return {
22
22
  children,
23
- group: group.name ?? ""
23
+ group: group.id,
24
+ name: group.name
24
25
  };
25
26
  }
26
27
  function materializeField(field) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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 \"@glion/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 toRepetition = (r: FieldRepetition): FieldJson | FieldJson[] => {\n if (r.children.length === 0) {\n return \"\";\n }\n if (r.children.length === 1) {\n return toComponent(r.children[0] as Component);\n }\n return r.children.map((c) => toComponent(c as Component));\n };\n\n const repetitions = field.children as FieldRepetition[];\n\n if (repetitions.length === 0) {\n return \"\";\n }\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 const repVal = toRepetition(rep);\n if (rep.children.length === 1) {\n // Single-component rep: preserve nested-array shape when component is composite.\n return Array.isArray(repVal)\n ? ([repVal] as FieldJson[])\n : (repVal as FieldJson);\n }\n return repVal as FieldJson | FieldJson[];\n }\n\n // Multiple repetitions: project each repetition to a value (string or array)\n return repetitions.map((r) => toRepetition(r as FieldRepetition)) as string[];\n}\n","import type { Node, Nodes, Root } from \"@glion/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;EA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ourcesContent":["import type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Nodes,\n Root,\n Segment,\n Subcomponent,\n} from \"@glion/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.id, name: 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 toRepetition = (r: FieldRepetition): FieldJson | FieldJson[] => {\n if (r.children.length === 0) {\n return \"\";\n }\n if (r.children.length === 1) {\n return toComponent(r.children[0] as Component);\n }\n return r.children.map((c) => toComponent(c as Component));\n };\n\n const repetitions = field.children as FieldRepetition[];\n\n if (repetitions.length === 0) {\n return \"\";\n }\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 const repVal = toRepetition(rep);\n if (rep.children.length === 1) {\n // Single-component rep: preserve nested-array shape when component is composite.\n return Array.isArray(repVal)\n ? ([repVal] as FieldJson[])\n : (repVal as FieldJson);\n }\n return repVal as FieldJson | FieldJson[];\n }\n\n // Multiple repetitions: project each repetition to a value (string or array)\n return repetitions.map((r) => toRepetition(r as FieldRepetition)) as string[];\n}\n","import type { Node, Nodes, Root } from \"@glion/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;EAAI,MAAM,MAAM;EAAM;;AAIxD,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,gBAAgB,MAAgD;AACpE,MAAI,EAAE,SAAS,WAAW,EACxB,QAAO;AAET,MAAI,EAAE,SAAS,WAAW,EACxB,QAAO,YAAY,EAAE,SAAS,GAAgB;AAEhD,SAAO,EAAE,SAAS,KAAK,MAAM,YAAY,EAAe,CAAC;;CAG3D,MAAM,cAAc,MAAM;AAE1B,KAAI,YAAY,WAAW,EACzB,QAAO;AAGT,KAAI,YAAY,WAAW,GAAG;EAC5B,MAAM,MAAM,YAAY;AAExB,MAAI,CAAC,IACH,OAAM,IAAI,MAAM,8BAA8B;EAGhD,MAAM,SAAS,aAAa,IAAI;AAChC,MAAI,IAAI,SAAS,WAAW,EAE1B,QAAO,MAAM,QAAQ,OAAO,GACvB,CAAC,OAAO,GACR;AAEP,SAAO;;AAIT,QAAO,YAAY,KAAK,MAAM,aAAa,EAAqB,CAAC;;;;ACjGnE,SAAgB,eAA8B;CAC5C,MAAM,OAAO;CAQb,SAAS,SAAS,MAA8B;AAC9C,SAAO,cAAc,KAAK;;AAG5B,MAAK,WAAW"}
package/dist/types.d.ts CHANGED
@@ -4,7 +4,10 @@ export interface SegmentJson {
4
4
  fields: (FieldJson | FieldJson[])[];
5
5
  }
6
6
  export interface GroupJson {
7
+ /** The group ID, such as `PATIENT_VISIT`. */
7
8
  group: string;
9
+ /** The group name, such as `Patient Visit`. */
10
+ name: string;
8
11
  children: (SegmentJson | GroupJson)[];
9
12
  }
10
13
  export type Hl7v2JsonResult = (SegmentJson | GroupJson)[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,SAAS;IACxB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC;CACvC;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/jsonify",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "hl7v2 plugin to transform hl7v2 messages to a simplified JSON representation",
5
5
  "keywords": [
6
6
  "health",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unified": "11.0.5",
37
- "@glion/ast": "0.20.0"
37
+ "@glion/ast": "0.22.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "25.6.0",
@@ -44,8 +44,8 @@
44
44
  "tsdown": "0.21.10",
45
45
  "typescript": "6.0.3",
46
46
  "vitest": "4.1.11",
47
- "@glion/builder": "0.20.0",
48
47
  "@glion/check-readme": "0.18.0",
48
+ "@glion/builder": "0.22.0",
49
49
  "@glion/testing": "0.18.0",
50
50
  "@glion/tsconfig": "0.18.0"
51
51
  },