@glion/config 0.15.1 → 0.15.3

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.
Files changed (2) hide show
  1. package/README.md +118 -193
  2. package/package.json +9 -5
package/README.md CHANGED
@@ -1,27 +1,18 @@
1
1
  # @glion/config
2
2
 
3
- Configuration schema and loader for hl7v2-specific settings.
3
+ Configuration schema and loader for `.hl7v2rc.json` and related config files.
4
4
 
5
- ## Overview
5
+ ## What it does
6
6
 
7
- This package provides type-safe configuration loading for hl7v2-specific settings that augment the standard [unified-args](https://github.com/unifiedjs/unified-args) configuration system.
7
+ Discovers and validates HL7v2-specific configuration from `.hl7v2rc.*` files, `hl7v2.config.*`, or a `hl7v2` field in `package.json`. Supports JSON, YAML, JavaScript (ESM/CJS), and TypeScript config formats, returns a typed object with `plugins` and `settings`, and ships a JSON Schema so editors can autocomplete config files. Augments the standard [unified-args](https://github.com/unifiedjs/unified-args) configuration system rather than replacing it — `plugins` is passed through, `settings` is validated here.
8
8
 
9
- **Key Features:**
10
-
11
- - ✅ Type-safe settings with TypeScript types
12
- - ✅ Runtime validation with Zod
13
- - ✅ JSON Schema for IDE autocomplete
14
- - ✅ Compatible with all unified-args RC file formats
15
- - ✅ Validates only hl7v2-specific `settings` - `plugins` handled by unified-args
16
- - ✅ Synchronous API for fast startup
17
-
18
- ## Installation
9
+ ## Install
19
10
 
20
11
  ```bash
21
12
  npm install @glion/config
22
13
  ```
23
14
 
24
- ## Quick Start
15
+ ## Use
25
16
 
26
17
  Create a `.hl7v2rc.json` file in your project:
27
18
 
@@ -55,11 +46,72 @@ console.log(settings.delimiters.field); // "|"
55
46
  console.log(settings.experimental.emptyMode); // "empty"
56
47
  ```
57
48
 
58
- ## Configuration Schema
49
+ ## API
50
+
51
+ ### `loadConfig(searchFrom?)`
52
+
53
+ Loads and validates HL7v2 configuration synchronously. Recommended for CLI tools and startup code.
54
+
55
+ ```typescript
56
+ import { loadConfig } from "@glion/config";
57
+
58
+ // Load full config
59
+ const config = loadConfig();
60
+
61
+ // Load from a specific directory
62
+ const config2 = loadConfig("/path/to/project");
63
+
64
+ // Destructure to get only settings
65
+ const { settings } = loadConfig();
66
+ ```
67
+
68
+ - Parameters: `searchFrom` (optional) — Directory to start searching from (defaults to cwd).
69
+ - Returns: `HL7v2Config` — object containing `plugins` and `settings`.
70
+ - Throws: `ConfigurationError` if configuration is invalid.
71
+
72
+ ### `loadConfigAsync(searchFrom?)`
73
+
74
+ Loads and validates HL7v2 configuration asynchronously. Use when you need non-blocking I/O or are in an async context.
75
+
76
+ ```typescript
77
+ import { loadConfigAsync } from "@glion/config";
78
+
79
+ const config = await loadConfigAsync();
80
+ const { settings } = await loadConfigAsync();
81
+ ```
82
+
83
+ - Parameters: `searchFrom` (optional) — Directory to start searching from (defaults to cwd).
84
+ - Returns: `Promise<HL7v2Config>`.
85
+ - Throws: `ConfigurationError` if configuration is invalid.
86
+
87
+ ### `defineConfig(config)`
88
+
89
+ Type-safe helper for authoring configuration files. Provides IDE autocomplete with no runtime overhead (identity function for type inference).
90
+
91
+ ```typescript
92
+ // hl7v2.config.ts
93
+ import { defineConfig } from "@glion/config";
94
+
95
+ export default defineConfig({
96
+ plugins: ["preset-lint-recommended"],
97
+ settings: {
98
+ delimiters: { field: "|", component: "^" },
99
+ experimental: { emptyMode: "empty" },
100
+ },
101
+ });
102
+ ```
103
+
104
+ ### `ConfigurationError`
105
+
106
+ Error thrown when configuration validation fails.
59
107
 
60
- ### Settings
108
+ ```typescript
109
+ class ConfigurationError extends Error {
110
+ cause?: unknown;
111
+ }
112
+ ```
61
113
 
62
- The `settings` field contains hl7v2-specific configuration:
114
+ ### `HL7v2Settings`
63
115
 
64
116
  ```typescript
65
117
  type HL7v2Settings = {
@@ -77,11 +129,13 @@ type HL7v2Settings = {
77
129
  };
78
130
  ```
79
131
 
80
- #### Delimiters
132
+ ## Configuration keys
133
+
134
+ ### `settings.delimiters`
81
135
 
82
136
  Configure custom delimiters for HL7v2 message parsing. Each delimiter must be exactly one character.
83
137
 
84
- | Option | Default | Description |
138
+ | Key | Default | Description |
85
139
  | -------------- | ------- | ---------------------- |
86
140
  | `field` | `\|` | Field separator |
87
141
  | `component` | `^` | Component separator |
@@ -90,7 +144,7 @@ Configure custom delimiters for HL7v2 message parsing. Each delimiter must be ex
90
144
  | `escape` | `\\` | Escape character |
91
145
  | `segment` | `\r` | Segment terminator |
92
146
 
93
- **Example:** Using custom delimiters for a non-standard system:
147
+ Example — using custom delimiters for a non-standard system:
94
148
 
95
149
  ```json
96
150
  {
@@ -103,22 +157,20 @@ Configure custom delimiters for HL7v2 message parsing. Each delimiter must be ex
103
157
  }
104
158
  ```
105
159
 
106
- #### Experimental Features
107
-
108
- ##### `emptyMode`
160
+ ### `settings.experimental.emptyMode`
109
161
 
110
- Controls how empty fields/components are represented in the AST.
162
+ Controls how empty fields and components are represented in the AST.
111
163
 
112
- | Value | Description |
113
- | -------------------- | --------------------------------------------------------------------------------- |
114
- | `"legacy"` (default) | Empty fields create full structure (Field -> Rep -> Comp -> Sub with `value: ""`) |
115
- | `"empty"` | Empty fields have no children (Field with `children: []`) |
164
+ | Value | Description |
165
+ | -------------------- | ------------------------------------------------------------------------------- |
166
+ | `"legacy"` (default) | Empty fields create full structure (Field → Rep → Comp → Sub with `value: ""`). |
167
+ | `"empty"` | Empty fields have no children (Field with `children: []`). |
116
168
 
117
- **Status:** Experimental. Will become the default in v0.6.0.
169
+ Experimental — will become the default in v0.6.0.
118
170
 
119
- ### Plugins
171
+ ### `plugins`
120
172
 
121
- The `plugins` field is handled by unified-args and follows the standard unified plugin configuration format:
173
+ Handled by unified-args; follows the standard unified plugin configuration format:
122
174
 
123
175
  ```json
124
176
  {
@@ -130,16 +182,17 @@ The `plugins` field is handled by unified-args and follows the standard unified
130
182
  }
131
183
  ```
132
184
 
133
- **Severity Levels:**
134
- | Value | Description |
135
- |-------|-------------|
136
- | `"off"` or `0` | Disable the rule |
137
- | `"on"` or `"warn"` or `1` | Enable as warning |
138
- | `"error"` or `2` | Enable as error |
185
+ Severity levels:
186
+
187
+ | Value | Description |
188
+ | ----------------------- | ----------------- |
189
+ | `"off"` or `0` | Disable the rule |
190
+ | `"on"` / `"warn"` / `1` | Enable as warning |
191
+ | `"error"` or `2` | Enable as error |
139
192
 
140
- ## Configuration Files
193
+ ### Configuration file locations
141
194
 
142
- The loader searches for configuration in the following locations (in order):
195
+ The loader searches for configuration in the following locations, in order:
143
196
 
144
197
  | Location | Format |
145
198
  | ----------------------------------------------------------- | ------------------- |
@@ -150,7 +203,9 @@ The loader searches for configuration in the following locations (in order):
150
203
  | `.hl7v2rc.js` / `.hl7v2rc.cjs` / `.hl7v2rc.mjs` | JavaScript |
151
204
  | `hl7v2.config.js` / `hl7v2.config.cjs` / `hl7v2.config.mjs` | JavaScript |
152
205
 
153
- ### JSON Configuration
206
+ ## Examples
207
+
208
+ ### JSON configuration
154
209
 
155
210
  ```json
156
211
  {
@@ -167,9 +222,7 @@ The loader searches for configuration in the following locations (in order):
167
222
  }
168
223
  ```
169
224
 
170
- ### TypeScript Configuration
171
-
172
- For type-safe configuration with IDE autocomplete, use `defineConfig()`:
225
+ ### TypeScript configuration
173
226
 
174
227
  ```typescript
175
228
  // hl7v2.config.ts
@@ -178,20 +231,13 @@ import { defineConfig } from "@glion/config";
178
231
  export default defineConfig({
179
232
  plugins: ["preset-lint-recommended"],
180
233
  settings: {
181
- delimiters: {
182
- field: "|",
183
- component: "^",
184
- },
185
- experimental: {
186
- emptyMode: "empty",
187
- },
234
+ delimiters: { field: "|", component: "^" },
235
+ experimental: { emptyMode: "empty" },
188
236
  },
189
237
  });
190
238
  ```
191
239
 
192
- ### JavaScript Configuration
193
-
194
- For dynamic configuration, use a JavaScript config file:
240
+ ### JavaScript configuration
195
241
 
196
242
  ```javascript
197
243
  // hl7v2.config.js
@@ -214,7 +260,7 @@ export default {
214
260
  };
215
261
  ```
216
262
 
217
- ### Package.json Configuration
263
+ ### Package.json configuration
218
264
 
219
265
  ```json
220
266
  {
@@ -223,108 +269,15 @@ export default {
223
269
  "hl7v2": {
224
270
  "plugins": ["preset-lint-recommended"],
225
271
  "settings": {
226
- "experimental": {
227
- "emptyMode": "empty"
228
- }
272
+ "experimental": { "emptyMode": "empty" }
229
273
  }
230
274
  }
231
275
  }
232
276
  ```
233
277
 
234
- ## API
235
-
236
- ### `loadConfig(searchFrom?)`
237
-
238
- Load and validate hl7v2 configuration synchronously.
278
+ ### Parser integration
239
279
 
240
- **Recommended for:** CLI tools, startup code, and most use cases.
241
-
242
- ```typescript
243
- import { loadConfig } from "@glion/config";
244
-
245
- // Load full config
246
- const config = loadConfig();
247
-
248
- // Load from a specific directory
249
- const config = loadConfig("/path/to/project");
250
-
251
- // Destructure to get only settings
252
- const { settings } = loadConfig();
253
- ```
254
-
255
- **Parameters:**
256
-
257
- - `searchFrom` (optional): Directory to start searching from (defaults to cwd)
258
-
259
- **Returns:** `HL7v2Config` - Configuration object containing `plugins` and `settings`
260
-
261
- **Throws:** `ConfigurationError` if configuration is invalid
262
-
263
- ### `loadConfigAsync(searchFrom?)`
264
-
265
- Load and validate hl7v2 configuration asynchronously.
266
-
267
- **Use when:** You need non-blocking I/O or are in an async context.
268
-
269
- ```typescript
270
- import { loadConfigAsync } from "@glion/config";
271
-
272
- const config = await loadConfigAsync();
273
- const { settings } = await loadConfigAsync();
274
- ```
275
-
276
- **Parameters:**
277
-
278
- - `searchFrom` (optional): Directory to start searching from (defaults to cwd)
279
-
280
- **Returns:** `Promise<HL7v2Config>` - Configuration object containing `plugins` and `settings`
281
-
282
- **Throws:** `ConfigurationError` if configuration is invalid
283
-
284
- ### `defineConfig(config)`
285
-
286
- Type-safe helper for authoring configuration files. Provides IDE autocomplete without any runtime overhead.
287
-
288
- ```typescript
289
- import { defineConfig } from "@glion/config";
290
-
291
- export default defineConfig({
292
- plugins: ["preset-lint-recommended"],
293
- settings: {
294
- experimental: { emptyMode: "empty" },
295
- },
296
- });
297
- ```
298
-
299
- **Parameters:**
300
-
301
- - `config`: Configuration object
302
-
303
- **Returns:** The same config object (identity function for type inference)
304
-
305
- ### `ConfigurationError`
306
-
307
- Error thrown when configuration validation fails.
308
-
309
- ```typescript
310
- class ConfigurationError extends Error {
311
- cause?: unknown;
312
- }
313
- ```
314
-
315
- ## IDE Support
316
-
317
- For IDE autocomplete and validation, add the `$schema` field to your JSON configuration:
318
-
319
- ```json
320
- {
321
- "$schema": "https://raw.githubusercontent.com/rethinkhealth/glion/main/packages/hl7v2-config/schema.json"
322
- }
323
- ```
324
-
325
- ## Integration with Parser
326
-
327
- The parser automatically reads settings from the unified processor:
280
+ The parser reads settings from the unified processor:
328
281
 
329
282
  ```typescript
330
283
  import { unified } from "unified";
@@ -333,58 +286,30 @@ import { parseHL7v2 } from "@glion/hl7v2";
333
286
  const processor = unified()
334
287
  .use(parseHL7v2)
335
288
  .data("settings", {
336
- delimiters: {
337
- field: "|",
338
- component: "^",
339
- },
340
- experimental: {
341
- emptyMode: "empty",
342
- },
289
+ delimiters: { field: "|", component: "^" },
290
+ experimental: { emptyMode: "empty" },
343
291
  });
344
292
 
345
293
  const tree = processor.parse("MSH|^~\\&|...");
346
294
  ```
347
295
 
348
- When using the CLI, settings are automatically loaded from configuration files.
349
-
350
- ## Design Principles
351
-
352
- 1. **Augments, not replaces** - Extends unified-args via the `settings` field
353
- 2. **Validates only settings** - The `plugins` field is handled by unified-args
354
- 3. **Type-safe** - Full TypeScript support with Zod validation
355
- 4. **IDE-friendly** - JSON Schema for autocomplete and validation
356
- 5. **Backward compatible** - Defaults work without configuration
357
-
358
- ## Related Packages
359
-
360
- - [@glion/hl7v2](../hl7v2) - Main hl7v2 parser
361
- - [@glion/cli](../hl7v2-cli) - CLI that uses this configuration
362
- - [unified-args](https://github.com/unifiedjs/unified-args) - Plugin configuration system
296
+ When using the CLI, settings are loaded from configuration files automatically.
363
297
 
364
- ## Security
298
+ ### IDE support
365
299
 
366
- This package only validates configuration and does not execute arbitrary code from configuration files (except JS/MJS config files which are explicitly imported). Ensure you trust the source of your configuration files.
300
+ For autocomplete and validation, add the `$schema` field to your JSON configuration:
367
301
 
368
- ## Contributing
369
-
370
- We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
371
-
372
- 1. Fork the repository
373
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
374
- 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
375
- 4. Push to the branch (`git push origin feature/amazing-feature`)
376
- 5. Open a Pull Request
377
-
378
- ## Code of Conduct
379
-
380
- To ensure a welcoming and positive environment, we have a [Code of Conduct][github-code-of-conduct] that all contributors and participants are expected to adhere to.
302
+ ```json
303
+ {
304
+ "$schema": "https://raw.githubusercontent.com/rethinkhealth/glion/main/packages/hl7v2-config/schema.json"
305
+ }
306
+ ```
381
307
 
382
- ## License
308
+ This package only validates configuration and does not execute arbitrary code from config files, except JS/MJS/TS config files which are explicitly imported. Ensure you trust the source of your configuration files.
383
309
 
384
- Copyright 2025 Rethink Health, SUARL. All rights reserved.
310
+ ## Part of Glion
385
311
 
386
- This program is licensed to you under the terms of the [MIT License](https://opensource.org/licenses/MIT). This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [LICENSE][github-license] file for details.
312
+ `@glion/config` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
387
313
 
388
- [github-code-of-conduct]: https://github.com/rethinkhealth/glion/blob/main/CODE_OF_CONDUCT.md
389
- [github-license]: https://github.com/rethinkhealth/glion/blob/main/LICENSE
390
- [github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
314
+ [Glion]: https://github.com/rethinkhealth/glion#readme
315
+ [Glion README]: https://github.com/rethinkhealth/glion#readme
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/config",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "description": "Configuration schema and loader for hl7v2",
5
5
  "keywords": [
6
6
  "config",
@@ -37,17 +37,19 @@
37
37
  "cosmiconfig": "9.0.1",
38
38
  "unified": "11.0.5",
39
39
  "zod": "3.25.76",
40
- "@glion/utils": "0.15.1"
40
+ "@glion/utils": "0.15.3"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^25.5.0",
44
44
  "@vitest/coverage-v8": "4.1.2",
45
+ "publint": "0.3.18",
45
46
  "tsdown": "0.21.7",
46
47
  "typescript": "^5.9.3",
47
48
  "vitest": "4.1.2",
48
49
  "zod-to-json-schema": "3.25.0",
49
- "@glion/tsconfig": "0.15.1",
50
- "@glion/testing": "0.15.1"
50
+ "@glion/check-readme": "0.15.3",
51
+ "@glion/tsconfig": "0.15.3",
52
+ "@glion/testing": "0.15.3"
51
53
  },
52
54
  "engines": {
53
55
  "node": ">=18"
@@ -57,8 +59,10 @@
57
59
  "build": "tsdown && tsc --emitDeclarationOnly && pnpm build:schema",
58
60
  "build:schema": "node --input-type=module -e \"import{writeFileSync}from'fs';import{jsonSchema}from'./dist/json-schema.js';writeFileSync('schema.json',JSON.stringify(jsonSchema,null,2));\"",
59
61
  "check-types": "tsc --noEmit",
62
+ "check:readme": "glion-check-readme",
60
63
  "test": "vitest run",
61
64
  "test:coverage": "vitest run --coverage",
62
- "test:watch": "vitest"
65
+ "test:watch": "vitest",
66
+ "publint": "publint --strict"
63
67
  }
64
68
  }