@glion/jsonify 0.15.3 → 0.19.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 +10 -12
- package/dist/index.js.map +1 -1
- package/package.json +13 -14
package/dist/index.js
CHANGED
|
@@ -29,23 +29,21 @@ function materializeField(field) {
|
|
|
29
29
|
if (c.children?.length === 1) return c.children[0].value;
|
|
30
30
|
return c.children ? c.children.map((sc) => sc.value) : [];
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const toRepetition = (r) => {
|
|
33
|
+
if (r.children.length === 0) return "";
|
|
34
|
+
if (r.children.length === 1) return toComponent(r.children[0]);
|
|
35
|
+
return r.children.map((c) => toComponent(c));
|
|
36
|
+
};
|
|
33
37
|
const repetitions = field.children;
|
|
38
|
+
if (repetitions.length === 0) return "";
|
|
34
39
|
if (repetitions.length === 1) {
|
|
35
40
|
const rep = repetitions[0];
|
|
36
41
|
if (!rep) throw new Error("Expected a field repetition");
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return Array.isArray(compVal) ? [compVal] : compVal;
|
|
41
|
-
}
|
|
42
|
-
return toRepetitionArray(rep);
|
|
42
|
+
const repVal = toRepetition(rep);
|
|
43
|
+
if (rep.children.length === 1) return Array.isArray(repVal) ? [repVal] : repVal;
|
|
44
|
+
return repVal;
|
|
43
45
|
}
|
|
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
|
-
});
|
|
46
|
+
return repetitions.map((r) => toRepetition(r));
|
|
49
47
|
}
|
|
50
48
|
//#endregion
|
|
51
49
|
//#region src/processor.ts
|
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
|
|
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;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,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/jsonify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "hl7v2 plugin to transform hl7v2 messages to a simplified JSON representation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -34,28 +34,27 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"unified": "11.0.5",
|
|
37
|
-
"@glion/ast": "0.
|
|
37
|
+
"@glion/ast": "0.19.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "
|
|
40
|
+
"@types/node": "25.6.0",
|
|
41
41
|
"@types/unist": "^3.0.3",
|
|
42
|
-
"@vitest/coverage-v8": "4.1.
|
|
42
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
43
43
|
"publint": "0.3.18",
|
|
44
|
-
"tsdown": "0.21.
|
|
45
|
-
"typescript": "
|
|
46
|
-
"vitest": "4.1.
|
|
47
|
-
"@glion/builder": "0.
|
|
48
|
-
"@glion/check-readme": "0.
|
|
49
|
-
"@glion/
|
|
50
|
-
"@glion/
|
|
44
|
+
"tsdown": "0.21.10",
|
|
45
|
+
"typescript": "6.0.3",
|
|
46
|
+
"vitest": "4.1.11",
|
|
47
|
+
"@glion/builder": "0.19.0",
|
|
48
|
+
"@glion/check-readme": "0.18.0",
|
|
49
|
+
"@glion/testing": "0.18.0",
|
|
50
|
+
"@glion/tsconfig": "0.18.0"
|
|
51
51
|
},
|
|
52
52
|
"engines": {
|
|
53
|
-
"node": ">=
|
|
53
|
+
"node": ">=22"
|
|
54
54
|
},
|
|
55
|
-
"packageManager": "pnpm@10.14.0",
|
|
56
55
|
"scripts": {
|
|
57
56
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
58
|
-
"check-types": "tsc --noEmit",
|
|
57
|
+
"check-types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
|
|
59
58
|
"check:readme": "glion-check-readme",
|
|
60
59
|
"test": "vitest run",
|
|
61
60
|
"test:coverage": "vitest run --coverage",
|