@glion/config 0.14.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/LICENSE +21 -0
- package/README.md +390 -0
- package/dist/define.d.ts +20 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +18 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +3 -0
- package/dist/json-schema2.js +1085 -0
- package/dist/json-schema2.js.map +1 -0
- package/dist/loader.d.ts +68 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +119 -0
- package/dist/loader.js.map +1 -0
- package/dist/schema.d.ts +292 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +51 -0
- package/dist/schema.js.map +1 -0
- package/package.json +59 -0
- package/schema.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Rethink Health
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
# @glion/config
|
|
2
|
+
|
|
3
|
+
Configuration schema and loader for hl7v2-specific settings.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
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.
|
|
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
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @glion/config
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
Create a `.hl7v2rc.json` file in your project:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"$schema": "https://raw.githubusercontent.com/rethinkhealth/glion/main/packages/hl7v2-config/schema.json",
|
|
31
|
+
"plugins": ["preset-lint-recommended"],
|
|
32
|
+
"settings": {
|
|
33
|
+
"delimiters": {
|
|
34
|
+
"field": "|",
|
|
35
|
+
"component": "^",
|
|
36
|
+
"subcomponent": "&",
|
|
37
|
+
"repetition": "~",
|
|
38
|
+
"escape": "\\",
|
|
39
|
+
"segment": "\r"
|
|
40
|
+
},
|
|
41
|
+
"experimental": {
|
|
42
|
+
"emptyMode": "empty"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then load the configuration:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import { loadConfig } from "@glion/config";
|
|
52
|
+
|
|
53
|
+
const { settings } = loadConfig();
|
|
54
|
+
console.log(settings.delimiters.field); // "|"
|
|
55
|
+
console.log(settings.experimental.emptyMode); // "empty"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration Schema
|
|
59
|
+
|
|
60
|
+
### Settings
|
|
61
|
+
|
|
62
|
+
The `settings` field contains hl7v2-specific configuration:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
type HL7v2Settings = {
|
|
66
|
+
delimiters?: {
|
|
67
|
+
field?: string; // default: "|"
|
|
68
|
+
component?: string; // default: "^"
|
|
69
|
+
subcomponent?: string; // default: "&"
|
|
70
|
+
repetition?: string; // default: "~"
|
|
71
|
+
escape?: string; // default: "\\"
|
|
72
|
+
segment?: string; // default: "\r"
|
|
73
|
+
};
|
|
74
|
+
experimental?: {
|
|
75
|
+
emptyMode?: "legacy" | "empty"; // default: "legacy"
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Delimiters
|
|
81
|
+
|
|
82
|
+
Configure custom delimiters for HL7v2 message parsing. Each delimiter must be exactly one character.
|
|
83
|
+
|
|
84
|
+
| Option | Default | Description |
|
|
85
|
+
| -------------- | ------- | ---------------------- |
|
|
86
|
+
| `field` | `\|` | Field separator |
|
|
87
|
+
| `component` | `^` | Component separator |
|
|
88
|
+
| `subcomponent` | `&` | Subcomponent separator |
|
|
89
|
+
| `repetition` | `~` | Repetition separator |
|
|
90
|
+
| `escape` | `\\` | Escape character |
|
|
91
|
+
| `segment` | `\r` | Segment terminator |
|
|
92
|
+
|
|
93
|
+
**Example:** Using custom delimiters for a non-standard system:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"settings": {
|
|
98
|
+
"delimiters": {
|
|
99
|
+
"field": "#",
|
|
100
|
+
"component": "@"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Experimental Features
|
|
107
|
+
|
|
108
|
+
##### `emptyMode`
|
|
109
|
+
|
|
110
|
+
Controls how empty fields/components are represented in the AST.
|
|
111
|
+
|
|
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: []`) |
|
|
116
|
+
|
|
117
|
+
**Status:** Experimental. Will become the default in v0.6.0.
|
|
118
|
+
|
|
119
|
+
### Plugins
|
|
120
|
+
|
|
121
|
+
The `plugins` field is handled by unified-args and follows the standard unified plugin configuration format:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"plugins": [
|
|
126
|
+
"plugin-name",
|
|
127
|
+
["plugin-name", { "option": "value" }],
|
|
128
|
+
["plugin-name", ["error", { "option": "value" }]]
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
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 |
|
|
139
|
+
|
|
140
|
+
## Configuration Files
|
|
141
|
+
|
|
142
|
+
The loader searches for configuration in the following locations (in order):
|
|
143
|
+
|
|
144
|
+
| Location | Format |
|
|
145
|
+
| ----------------------------------------------------------- | ------------------- |
|
|
146
|
+
| `package.json` | Under `hl7v2` field |
|
|
147
|
+
| `.hl7v2rc` | JSON |
|
|
148
|
+
| `.hl7v2rc.json` | JSON |
|
|
149
|
+
| `.hl7v2rc.yaml` / `.hl7v2rc.yml` | YAML |
|
|
150
|
+
| `.hl7v2rc.js` / `.hl7v2rc.cjs` / `.hl7v2rc.mjs` | JavaScript |
|
|
151
|
+
| `hl7v2.config.js` / `hl7v2.config.cjs` / `hl7v2.config.mjs` | JavaScript |
|
|
152
|
+
|
|
153
|
+
### JSON Configuration
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"$schema": "https://raw.githubusercontent.com/rethinkhealth/glion/main/packages/hl7v2-config/schema.json",
|
|
158
|
+
"plugins": [
|
|
159
|
+
"preset-lint-recommended",
|
|
160
|
+
["lint-max-message-size", ["error", { "maxBytes": 5000000 }]]
|
|
161
|
+
],
|
|
162
|
+
"settings": {
|
|
163
|
+
"experimental": {
|
|
164
|
+
"emptyMode": "empty"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### TypeScript Configuration
|
|
171
|
+
|
|
172
|
+
For type-safe configuration with IDE autocomplete, use `defineConfig()`:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// hl7v2.config.ts
|
|
176
|
+
import { defineConfig } from "@glion/config";
|
|
177
|
+
|
|
178
|
+
export default defineConfig({
|
|
179
|
+
plugins: ["preset-lint-recommended"],
|
|
180
|
+
settings: {
|
|
181
|
+
delimiters: {
|
|
182
|
+
field: "|",
|
|
183
|
+
component: "^",
|
|
184
|
+
},
|
|
185
|
+
experimental: {
|
|
186
|
+
emptyMode: "empty",
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### JavaScript Configuration
|
|
193
|
+
|
|
194
|
+
For dynamic configuration, use a JavaScript config file:
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
// hl7v2.config.js
|
|
198
|
+
export default {
|
|
199
|
+
plugins: [
|
|
200
|
+
"preset-lint-recommended",
|
|
201
|
+
[
|
|
202
|
+
"lint-max-message-size",
|
|
203
|
+
["error", { maxBytes: parseInt(process.env.MAX_SIZE || "10000000") }],
|
|
204
|
+
],
|
|
205
|
+
],
|
|
206
|
+
settings: {
|
|
207
|
+
delimiters: {
|
|
208
|
+
segment: process.env.HL7_SEGMENT_TERMINATOR || "\r",
|
|
209
|
+
},
|
|
210
|
+
experimental: {
|
|
211
|
+
emptyMode: process.env.HL7_EMPTY_MODE || "legacy",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Package.json Configuration
|
|
218
|
+
|
|
219
|
+
```json
|
|
220
|
+
{
|
|
221
|
+
"name": "my-project",
|
|
222
|
+
"version": "1.0.0",
|
|
223
|
+
"hl7v2": {
|
|
224
|
+
"plugins": ["preset-lint-recommended"],
|
|
225
|
+
"settings": {
|
|
226
|
+
"experimental": {
|
|
227
|
+
"emptyMode": "empty"
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## API
|
|
235
|
+
|
|
236
|
+
### `loadConfig(searchFrom?)`
|
|
237
|
+
|
|
238
|
+
Load and validate hl7v2 configuration synchronously.
|
|
239
|
+
|
|
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:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
import { unified } from "unified";
|
|
331
|
+
import { parseHL7v2 } from "@glion/hl7v2";
|
|
332
|
+
|
|
333
|
+
const processor = unified()
|
|
334
|
+
.use(parseHL7v2)
|
|
335
|
+
.data("settings", {
|
|
336
|
+
delimiters: {
|
|
337
|
+
field: "|",
|
|
338
|
+
component: "^",
|
|
339
|
+
},
|
|
340
|
+
experimental: {
|
|
341
|
+
emptyMode: "empty",
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const tree = processor.parse("MSH|^~\\&|...");
|
|
346
|
+
```
|
|
347
|
+
|
|
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
|
|
363
|
+
|
|
364
|
+
## Security
|
|
365
|
+
|
|
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.
|
|
367
|
+
|
|
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.
|
|
381
|
+
|
|
382
|
+
## License
|
|
383
|
+
|
|
384
|
+
Copyright 2025 Rethink Health, SUARL. All rights reserved.
|
|
385
|
+
|
|
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.
|
|
387
|
+
|
|
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
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { HL7v2ConfigInput } from "./schema";
|
|
2
|
+
/**
|
|
3
|
+
* Helper for type-safe configuration authoring.
|
|
4
|
+
*
|
|
5
|
+
* Use in your `hl7v2.config.ts` file for IDE autocomplete:
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { defineConfig } from "@glion/config";
|
|
10
|
+
*
|
|
11
|
+
* export default defineConfig({
|
|
12
|
+
* plugins: ["preset-lint-recommended"],
|
|
13
|
+
* settings: {
|
|
14
|
+
* experimental: { emptyMode: "empty" },
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
* ```;
|
|
18
|
+
*/
|
|
19
|
+
export declare function defineConfig(config: HL7v2ConfigInput): HL7v2ConfigInput;
|
|
20
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../src/define.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAEvE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration schema and loader for hl7v2.
|
|
3
|
+
*
|
|
4
|
+
* This package provides type-safe configuration loading for hl7v2-specific
|
|
5
|
+
* settings that augment the standard unified-args configuration system.
|
|
6
|
+
*
|
|
7
|
+
* ## Usage
|
|
8
|
+
*
|
|
9
|
+
* ### Load configuration programmatically (Synchronous - Recommended)
|
|
10
|
+
*
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { loadConfig } from "@glion/config";
|
|
13
|
+
*
|
|
14
|
+
* // Load full configuration
|
|
15
|
+
* const config = loadConfig();
|
|
16
|
+
* console.log(config.settings.experimental.emptyMode); // 'legacy' or 'empty'
|
|
17
|
+
* console.log(config.plugins); // Array of plugin configurations
|
|
18
|
+
*
|
|
19
|
+
* // Or destructure to get only settings
|
|
20
|
+
* const { settings } = loadConfig();
|
|
21
|
+
* console.log(settings.experimental.emptyMode); // 'legacy' or 'empty'
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* ### Load configuration asynchronously
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { loadConfigAsync } from "@glion/config";
|
|
28
|
+
*
|
|
29
|
+
* const config = await loadConfigAsync();
|
|
30
|
+
* const { settings } = await loadConfigAsync();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ### Configuration file format
|
|
34
|
+
*
|
|
35
|
+
* Create a `.hl7v2rc.json` file:
|
|
36
|
+
*
|
|
37
|
+
* ```json
|
|
38
|
+
* {
|
|
39
|
+
* "$schema": "https://raw.githubusercontent.com/rethinkhealth/hl7v2/main/packages/hl7v2-config/schema.json",
|
|
40
|
+
* "plugins": [
|
|
41
|
+
* "preset-lint-recommended"
|
|
42
|
+
* ],
|
|
43
|
+
* "settings": {
|
|
44
|
+
* "experimental": {
|
|
45
|
+
* "emptyMode": "empty"
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @module @glion/config
|
|
52
|
+
*/
|
|
53
|
+
import type { HL7v2Settings } from "./schema.js";
|
|
54
|
+
export { defineConfig } from "./define";
|
|
55
|
+
export { jsonSchema } from "./json-schema";
|
|
56
|
+
export { ConfigurationError, clearCaches, loadConfig, loadConfigAsync, } from "./loader";
|
|
57
|
+
export type { HL7v2Config, HL7v2ConfigInput, HL7v2Settings } from "./schema";
|
|
58
|
+
export { HL7v2ConfigSchema } from "./schema";
|
|
59
|
+
declare module "unified" {
|
|
60
|
+
interface Settings extends HL7v2Settings {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,QAAS,SAAQ,aAAa;KAAG;CAC5C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { t as jsonSchema } from "./json-schema2.js";
|
|
2
|
+
import { HL7v2ConfigSchema } from "./schema.js";
|
|
3
|
+
import { ConfigurationError, clearCaches, loadConfig, loadConfigAsync } from "./loader.js";
|
|
4
|
+
//#region src/define.ts
|
|
5
|
+
/**
|
|
6
|
+
* Helper for type-safe configuration authoring.
|
|
7
|
+
*
|
|
8
|
+
* Use in your `hl7v2.config.ts` file for IDE autocomplete:
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { defineConfig } from "@glion/config";
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* plugins: ["preset-lint-recommended"],
|
|
16
|
+
* settings: {
|
|
17
|
+
* experimental: { emptyMode: "empty" },
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
* ```;
|
|
21
|
+
*/
|
|
22
|
+
function defineConfig(config) {
|
|
23
|
+
return config;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ConfigurationError, HL7v2ConfigSchema, clearCaches, defineConfig, jsonSchema, loadConfig, loadConfigAsync };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/define.ts"],"sourcesContent":["import type { HL7v2ConfigInput } from \"./schema\";\n\n/**\n * Helper for type-safe configuration authoring.\n *\n * Use in your `hl7v2.config.ts` file for IDE autocomplete:\n *\n * @example\n * ```typescript\n * import { defineConfig } from \"@glion/config\";\n *\n * export default defineConfig({\n * plugins: [\"preset-lint-recommended\"],\n * settings: {\n * experimental: { emptyMode: \"empty\" },\n * },\n * });\n * ```;\n */\nexport function defineConfig(config: HL7v2ConfigInput): HL7v2ConfigInput {\n return config;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,aAAa,QAA4C;AACvE,QAAO"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema for hl7v2 configuration.
|
|
3
|
+
*
|
|
4
|
+
* This schema can be used for IDE autocomplete by adding:
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* {
|
|
8
|
+
* "$schema": "https://raw.githubusercontent.com/rethinkhealth/hl7v2/main/packages/hl7v2-config/schema.json"
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const jsonSchema: import("zod-to-json-schema").JsonSchema7Type & {
|
|
13
|
+
$schema?: string | undefined;
|
|
14
|
+
definitions?: {
|
|
15
|
+
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
16
|
+
} | undefined;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU;;;;;CAIrB,CAAC"}
|