@dsillman2000/yaml-reference-ts 1.0.5 → 1.0.6
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 +64 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,10 @@ A Node.js TypeScript library for resolving YAML documents containing `!reference
|
|
|
11
11
|
- **CLI Interface**: Command-line tool for resolving YAML files
|
|
12
12
|
- **TypeScript Support**: Full type definitions included
|
|
13
13
|
|
|
14
|
+
## Spec
|
|
15
|
+
|
|
16
|
+
This Node.js TypeScript library implements the YAML specification for cross-file references in YAML files using tags `!reference` and `!reference-all` as defined in the [yaml-reference-specs project](https://github.com/dsillman2000/yaml-reference-specs).
|
|
17
|
+
|
|
14
18
|
## Installation
|
|
15
19
|
|
|
16
20
|
```bash
|
|
@@ -56,11 +60,11 @@ files: !reference-all {glob: ./data/*.yaml}
|
|
|
56
60
|
### Basic Usage
|
|
57
61
|
|
|
58
62
|
```typescript
|
|
59
|
-
import {
|
|
63
|
+
import { loadYamlWithReferences } from '@dsillman2000/yaml-reference-ts';
|
|
60
64
|
|
|
61
65
|
async function loadConfig() {
|
|
62
66
|
try {
|
|
63
|
-
const resolved = await
|
|
67
|
+
const resolved = await loadYamlWithReferences('./config/main.yaml');
|
|
64
68
|
console.log(resolved);
|
|
65
69
|
} catch (error) {
|
|
66
70
|
console.error('Failed to resolve references:', error);
|
|
@@ -73,7 +77,7 @@ async function loadConfig() {
|
|
|
73
77
|
#### `loadYamlWithReferences(filePath: string): Promise<any>`
|
|
74
78
|
Loads a YAML file and resolves all `!reference` and `!reference-all` tags, returning the fully resolved object.
|
|
75
79
|
|
|
76
|
-
#### `parseYamlWithReferences(content: string, filePath: string): any
|
|
80
|
+
#### `parseYamlWithReferences(content: string, filePath: string): Promise<any>`
|
|
77
81
|
Parses YAML content with custom tags, setting `_location` on Reference objects.
|
|
78
82
|
|
|
79
83
|
#### `loadYamlWithReferencesSync(filePath: string): any`
|
|
@@ -96,17 +100,67 @@ Represents a `!reference-all` tag with properties:
|
|
|
96
100
|
|
|
97
101
|
The package includes a CLI tool called `yaml-reference-cli`:
|
|
98
102
|
|
|
103
|
+
If an example `config.yaml` contains:
|
|
104
|
+
```yaml
|
|
105
|
+
services:
|
|
106
|
+
- !reference {path: services/etl-hub.yaml}
|
|
107
|
+
- !reference {path: services/etl-worker.yaml}
|
|
108
|
+
connections: !reference-all {glob: databases/*.yaml}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
With other files containing valid YAML data, then we can use the CLI to visualize the resolved YAML as JSON:
|
|
112
|
+
|
|
99
113
|
```bash
|
|
100
|
-
# Basic usage
|
|
101
|
-
yaml-reference-cli config.yaml
|
|
114
|
+
# Basic usage (resolve references, stdout as json)
|
|
115
|
+
$ yaml-reference-cli config.yaml
|
|
116
|
+
{
|
|
117
|
+
"connections": [
|
|
118
|
+
{
|
|
119
|
+
"name": "payments_pg",
|
|
120
|
+
"type": "postgres"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "transactions_redis",
|
|
124
|
+
"type": "redis"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"services": [
|
|
128
|
+
{
|
|
129
|
+
"name": "etl-hub",
|
|
130
|
+
"type": "service"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"name": "etl-worker",
|
|
134
|
+
"type": "service"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
# Pipe to a file
|
|
139
|
+
$ yaml-reference-cli config.yaml > .compiled/config.json
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
If you have the `yq` CLI installed ([mikefarah/yq](https://github.com/mikefarah/yq)), resolved YAML can be pretty-printed as well (with keys sorted):
|
|
102
143
|
|
|
103
|
-
|
|
104
|
-
|
|
144
|
+
```bash
|
|
145
|
+
# Basic usage (resolve references, stdout as json, convert to YAML)
|
|
146
|
+
$ yaml-reference-cli config.yaml | yq -P
|
|
147
|
+
connections:
|
|
148
|
+
- name: payments_pg
|
|
149
|
+
type: postgres
|
|
150
|
+
- name: transactions_redis
|
|
151
|
+
type: redis
|
|
152
|
+
services:
|
|
153
|
+
- name: etl-hub
|
|
154
|
+
type: service
|
|
155
|
+
- name: etl-worker
|
|
156
|
+
type: service
|
|
157
|
+
# Pipe to a file
|
|
158
|
+
$ yaml-reference-cli config.yaml | yq -P > .compiled/config.yaml
|
|
159
|
+
```
|
|
105
160
|
|
|
106
|
-
|
|
107
|
-
yaml-reference-cli config.yaml | yq -P > .compiled/config.yaml
|
|
161
|
+
This basic CLI usage is also explained in the help message.
|
|
108
162
|
|
|
109
|
-
|
|
163
|
+
```bash
|
|
110
164
|
yaml-reference-cli --help
|
|
111
165
|
```
|
|
112
166
|
|
package/package.json
CHANGED