@glion/builder 0.15.2 → 0.16.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/README.md +9 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -33
- package/dist/index.js.map +1 -1
- package/package.json +11 -13
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ Build a `Segment` node.
|
|
|
56
56
|
|
|
57
57
|
Build a `Field` node.
|
|
58
58
|
|
|
59
|
-
- No arguments → empty field
|
|
59
|
+
- No arguments → empty field (`children: []`).
|
|
60
60
|
- Strings become components with a single subcomponent containing the value.
|
|
61
61
|
- `Component` instances are added directly.
|
|
62
62
|
- `FieldRepetition` instances are preserved so you can control repetitions explicitly.
|
|
@@ -67,7 +67,7 @@ Build a `Field` node.
|
|
|
67
67
|
|
|
68
68
|
Build a `FieldRepetition` node.
|
|
69
69
|
|
|
70
|
-
- No arguments → repetition
|
|
70
|
+
- No arguments → empty field-repetition (`children: []`).
|
|
71
71
|
- Strings become components with a single subcomponent containing the value.
|
|
72
72
|
- Components are inserted as-is.
|
|
73
73
|
- Arrays are flattened one level for convenience.
|
|
@@ -76,7 +76,7 @@ Build a `FieldRepetition` node.
|
|
|
76
76
|
|
|
77
77
|
Build a `Component` node.
|
|
78
78
|
|
|
79
|
-
- No arguments → component
|
|
79
|
+
- No arguments → empty component (`children: []`).
|
|
80
80
|
- Strings become subcomponents.
|
|
81
81
|
- Arrays are flattened one level, so `c('DOE', ['JOHN', 'Q'])` works.
|
|
82
82
|
|
|
@@ -88,19 +88,17 @@ For advanced scenarios — multiple repetitions per field, custom metadata, node
|
|
|
88
88
|
- **Composable.** Each helper is a thin wrapper over `unist-builder`, so raw nodes from `u()` and other utilities can be mixed freely.
|
|
89
89
|
- **Minimal.** A small surface means fewer abstractions to learn and less room for divergent interpretations of the HL7v2 model.
|
|
90
90
|
|
|
91
|
-
###
|
|
91
|
+
### Empty fields, repetitions, and components
|
|
92
92
|
|
|
93
|
-
|
|
93
|
+
Calling `f()`, `r()`, or `c()` with no arguments produces a node with an empty `children` array — no implicit child placeholders.
|
|
94
94
|
|
|
95
95
|
```ts
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// Empty mode (via .hl7v2rc.json: { settings: { experimental: { emptyMode: "empty" } } }):
|
|
100
|
-
f(); // → Field with children: []
|
|
96
|
+
f(); // → { type: "field", children: [] }
|
|
97
|
+
r(); // → { type: "field-repetition", children: [] }
|
|
98
|
+
c(); // → { type: "component", children: [] }
|
|
101
99
|
```
|
|
102
100
|
|
|
103
|
-
|
|
101
|
+
Pass `f("")` (or any explicit string) to materialize the full subcomponent leaf.
|
|
104
102
|
|
|
105
103
|
## Part of Glion
|
|
106
104
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,eAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,OAAO,EACR,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,eAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,OAAO,EACR,MAAM,YAAY,CAAC;AAGpB,wBAAgB,CAAC,CAAC,GAAG,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAElD;AAED,wBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,GAAG,KAAK,CAIvE;AAKD,wBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAI3D;AAED,KAAK,UAAU,GAAG,eAAe,GAAG,SAAS,GAAG,MAAM,CAAC;AACvD,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAoB9B,kBAAkB;AAClB,wBAAgB,CAAC,IAAI,KAAK,CAAC;AAC3B,wBAAgB,CAAC,CAAC,GAAG,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,GAAG,KAAK,CAAC;AAuC/D,wBAAgB,CAAC,IAAI,eAAe,CAAC;AACrC,wBAAgB,CAAC,CACf,GAAG,UAAU,EAAE,WAAW,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE,GAC/C,eAAe,CAAC;AAmBnB,wBAAgB,CAAC,IAAI,SAAS,CAAC;AAC/B,wBAAgB,CAAC,CAAC,GAAG,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { loadConfig } from "@glion/config";
|
|
2
1
|
import { u } from "unist-builder";
|
|
3
2
|
//#region src/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Get the emptyMode setting from the configuration. Falls back to 'legacy' if
|
|
6
|
-
* no config is found or if the setting is not defined.
|
|
7
|
-
*/
|
|
8
|
-
function getEmptyMode() {
|
|
9
|
-
return loadConfig().settings.experimental.emptyMode;
|
|
10
|
-
}
|
|
11
3
|
function m(...children) {
|
|
12
4
|
return u("root", children);
|
|
13
5
|
}
|
|
@@ -31,15 +23,9 @@ function isComponent(value) {
|
|
|
31
23
|
return typeof value === "object" && value !== null && value.type === "component";
|
|
32
24
|
}
|
|
33
25
|
function f(...values) {
|
|
34
|
-
if (values.length === 0)
|
|
35
|
-
if (getEmptyMode() === "empty") return u("field", []);
|
|
36
|
-
return u("field", [r()]);
|
|
37
|
-
}
|
|
26
|
+
if (values.length === 0) return u("field", []);
|
|
38
27
|
const flat = flatten(values);
|
|
39
|
-
if (flat.length === 0)
|
|
40
|
-
if (getEmptyMode() === "empty") return u("field", []);
|
|
41
|
-
return u("field", [r()]);
|
|
42
|
-
}
|
|
28
|
+
if (flat.length === 0) return u("field", []);
|
|
43
29
|
const repetitions = [];
|
|
44
30
|
let pendingComponents = [];
|
|
45
31
|
const flushPending = () => {
|
|
@@ -56,31 +42,18 @@ function f(...values) {
|
|
|
56
42
|
if (isComponent(value) || typeof value === "string") pendingComponents.push(value);
|
|
57
43
|
}
|
|
58
44
|
flushPending();
|
|
59
|
-
if (repetitions.length === 0) return u("field", [r()]);
|
|
60
45
|
return u("field", repetitions);
|
|
61
46
|
}
|
|
62
47
|
function r(...components) {
|
|
63
|
-
if (components.length === 0)
|
|
64
|
-
if (getEmptyMode() === "empty") return u("field-repetition", []);
|
|
65
|
-
return u("field-repetition", [c()]);
|
|
66
|
-
}
|
|
48
|
+
if (components.length === 0) return u("field-repetition", []);
|
|
67
49
|
const flat = flatten(components);
|
|
68
|
-
if (flat.length === 0)
|
|
69
|
-
if (getEmptyMode() === "empty") return u("field-repetition", []);
|
|
70
|
-
return u("field-repetition", [c()]);
|
|
71
|
-
}
|
|
50
|
+
if (flat.length === 0) return u("field-repetition", []);
|
|
72
51
|
return u("field-repetition", flat.map((value) => typeof value === "string" ? c(value) : value));
|
|
73
52
|
}
|
|
74
53
|
function c(...values) {
|
|
75
|
-
if (values.length === 0)
|
|
76
|
-
if (getEmptyMode() === "empty") return u("component", []);
|
|
77
|
-
return u("component", [u("subcomponent", "")]);
|
|
78
|
-
}
|
|
54
|
+
if (values.length === 0) return u("component", []);
|
|
79
55
|
const flat = flatten(values);
|
|
80
|
-
if (flat.length === 0)
|
|
81
|
-
if (getEmptyMode() === "empty") return u("component", []);
|
|
82
|
-
return u("component", [u("subcomponent", "")]);
|
|
83
|
-
}
|
|
56
|
+
if (flat.length === 0) return u("component", []);
|
|
84
57
|
return u("component", flat.map((subcomponent) => u("subcomponent", subcomponent)));
|
|
85
58
|
}
|
|
86
59
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable typescript/unified-signatures\nimport type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Root,\n RootContent,\n Segment,\n} from \"@glion/ast\";\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable typescript/unified-signatures\nimport type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Root,\n RootContent,\n Segment,\n} from \"@glion/ast\";\nimport { u } from \"unist-builder\";\n\nexport function m(...children: RootContent[]): Root {\n return u(\"root\", children);\n}\n\nexport function g(name: string, ...children: (Segment | Group)[]): Group {\n const group = u(\"group\", children) as Group;\n group.name = name;\n return group;\n}\n\n// TODO: Add support for string[]\n// export function s(name: string, ...fields: string[]): Segment;\n// export function s(name: string, ...fields: string[] | Field[]): Segment {\nexport function s(name: string, ...fields: Field[]): Segment {\n const segment = u(\"segment\", fields) as Segment;\n segment.name = name;\n return segment;\n}\n\ntype FieldValue = FieldRepetition | Component | string;\ntype Flattenable<T> = T | T[];\n\nfunction flatten<T>(values: Flattenable<T>[]): T[] {\n return values.flatMap((value) => (Array.isArray(value) ? value : [value]));\n}\n\nfunction isFieldRepetition(value: FieldValue): value is FieldRepetition {\n return (\n typeof value === \"object\" &&\n value !== null &&\n value.type === \"field-repetition\"\n );\n}\n\nfunction isComponent(value: FieldValue): value is Component {\n return (\n typeof value === \"object\" && value !== null && value.type === \"component\"\n );\n}\n\n/** Empty field */\nexport function f(): Field;\nexport function f(...values: Flattenable<FieldValue>[]): Field;\nexport function f(...values: Flattenable<FieldValue>[]): Field {\n if (values.length === 0) {\n return u(\"field\", []);\n }\n\n const flat = flatten<FieldValue>(values);\n if (flat.length === 0) {\n return u(\"field\", []);\n }\n\n const repetitions: FieldRepetition[] = [];\n let pendingComponents: (Component | string)[] = [];\n\n const flushPending = () => {\n if (pendingComponents.length === 0) {\n return;\n }\n repetitions.push(r(...pendingComponents));\n pendingComponents = [];\n };\n\n for (const value of flat) {\n if (isFieldRepetition(value)) {\n flushPending();\n repetitions.push(value);\n continue;\n }\n\n if (isComponent(value) || typeof value === \"string\") {\n pendingComponents.push(value);\n }\n }\n\n flushPending();\n\n return u(\"field\", repetitions);\n}\n\nexport function r(): FieldRepetition;\nexport function r(\n ...components: Flattenable<Component | string>[]\n): FieldRepetition;\nexport function r(\n ...components: Flattenable<Component | string>[]\n): FieldRepetition {\n if (components.length === 0) {\n return u(\"field-repetition\", []);\n }\n\n const flat = flatten<Component | string>(components);\n if (flat.length === 0) {\n return u(\"field-repetition\", []);\n }\n\n return u(\n \"field-repetition\",\n flat.map((value) => (typeof value === \"string\" ? c(value) : value))\n );\n}\n\nexport function c(): Component;\nexport function c(...values: Flattenable<string>[]): Component;\nexport function c(...values: Flattenable<string>[]): Component {\n if (values.length === 0) {\n return u(\"component\", []);\n }\n\n const flat = flatten<string>(values);\n if (flat.length === 0) {\n return u(\"component\", []);\n }\n\n return u(\n \"component\",\n flat.map((subcomponent) => u(\"subcomponent\", subcomponent))\n );\n}\n"],"mappings":";;AAYA,SAAgB,EAAE,GAAG,UAA+B;AAClD,QAAO,EAAE,QAAQ,SAAS;;AAG5B,SAAgB,EAAE,MAAc,GAAG,UAAsC;CACvE,MAAM,QAAQ,EAAE,SAAS,SAAS;AAClC,OAAM,OAAO;AACb,QAAO;;AAMT,SAAgB,EAAE,MAAc,GAAG,QAA0B;CAC3D,MAAM,UAAU,EAAE,WAAW,OAAO;AACpC,SAAQ,OAAO;AACf,QAAO;;AAMT,SAAS,QAAW,QAA+B;AACjD,QAAO,OAAO,SAAS,UAAW,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAE;;AAG5E,SAAS,kBAAkB,OAA6C;AACtE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,MAAM,SAAS;;AAInB,SAAS,YAAY,OAAuC;AAC1D,QACE,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,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": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Build HL7v2 AST nodes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -34,26 +34,24 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"unist-builder": "4.0.0",
|
|
37
|
-
"@glion/
|
|
38
|
-
"@glion/ast": "0.15.2"
|
|
37
|
+
"@glion/ast": "0.16.0"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@types/node": "
|
|
40
|
+
"@types/node": "25.6.0",
|
|
42
41
|
"@types/unist": "^3.0.3",
|
|
43
|
-
"@vitest/coverage-v8": "4.1.
|
|
42
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
44
43
|
"publint": "0.3.18",
|
|
45
|
-
"tsdown": "0.21.
|
|
46
|
-
"typescript": "
|
|
44
|
+
"tsdown": "0.21.10",
|
|
45
|
+
"typescript": "6.0.3",
|
|
47
46
|
"unified": "^11.0.5",
|
|
48
|
-
"vitest": "4.1.
|
|
49
|
-
"@glion/check-readme": "0.
|
|
50
|
-
"@glion/testing": "0.
|
|
51
|
-
"@glion/tsconfig": "0.
|
|
47
|
+
"vitest": "4.1.5",
|
|
48
|
+
"@glion/check-readme": "0.16.0",
|
|
49
|
+
"@glion/testing": "0.16.0",
|
|
50
|
+
"@glion/tsconfig": "0.16.0"
|
|
52
51
|
},
|
|
53
52
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
53
|
+
"node": ">=20"
|
|
55
54
|
},
|
|
56
|
-
"packageManager": "pnpm@10.14.0",
|
|
57
55
|
"scripts": {
|
|
58
56
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
59
57
|
"check-types": "tsc --noEmit",
|