@dsillman2000/yaml-reference-ts 0.0.0 → 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 CHANGED
@@ -11,16 +11,20 @@ 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
17
- npm install yaml-reference-ts
21
+ npm install @dsillman2000/yaml-reference-ts
18
22
  ```
19
23
 
20
24
  Or for global CLI usage:
21
25
 
22
26
  ```bash
23
- npm install -g yaml-reference-ts
27
+ npm install -g @dsillman2000/yaml-reference-ts
24
28
  ```
25
29
 
26
30
  ## YAML Syntax Examples
@@ -56,11 +60,11 @@ files: !reference-all {glob: ./data/*.yaml}
56
60
  ### Basic Usage
57
61
 
58
62
  ```typescript
59
- import { loadAndResolve } from 'yaml-reference-ts';
63
+ import { loadYamlWithReferences } from '@dsillman2000/yaml-reference-ts';
60
64
 
61
65
  async function loadConfig() {
62
66
  try {
63
- const resolved = await loadAndResolve('./config/main.yaml');
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
- # With conversion back to YAML (requires yq)
104
- yaml-reference-cli config.yaml | yq -P
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
- # Save output to file
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
- # Show help
163
+ ```bash
110
164
  yaml-reference-cli --help
111
165
  ```
112
166
 
package/dist/cli/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,15 @@
1
1
  {
2
2
  "name": "@dsillman2000/yaml-reference-ts",
3
- "version": "0.0.0",
3
+ "version": "1.0.6",
4
4
  "description": "A Node.js TypeScript library for resolving YAML documents containing !reference and !reference-all tags",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/dsillman2000/yaml-reference-ts"
8
+ },
9
+ "homepage": "https://github.com/dsillman2000/yaml-reference-ts#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/dsillman2000/yaml-reference-ts/issues"
12
+ },
5
13
  "main": "dist/index.js",
6
14
  "types": "dist/index.d.ts",
7
15
  "bin": {
@@ -1,15 +0,0 @@
1
- # Additional configuration file
2
- extra_config:
3
- enabled: true
4
- options:
5
- - option1
6
- - option2
7
- - option3
8
- settings:
9
- timeout: 5000
10
- retry_count: 5
11
- fallback: true
12
- metadata:
13
- created: 2024-01-15
14
- updated: 2024-01-20
15
- version: 2.1.0
@@ -1,11 +0,0 @@
1
- # Database configuration
2
- host: localhost
3
- port: 5432
4
- database: myapp_production
5
- username: admin
6
- password: secret123
7
- pool:
8
- max: 20
9
- min: 5
10
- idle: 10000
11
- ssl: true
@@ -1,15 +0,0 @@
1
- # Application settings
2
- debug: false
3
- log_level: info
4
- cache:
5
- enabled: true
6
- ttl: 3600
7
- max_size: 1000
8
- api:
9
- timeout: 30000
10
- retries: 3
11
- base_url: https://api.example.com
12
- features:
13
- analytics: true
14
- notifications: false
15
- dark_mode: true
@@ -1,30 +0,0 @@
1
- # Products data file
2
- products:
3
- - id: 101
4
- name: Laptop Pro
5
- category: electronics
6
- price: 1299.99
7
- in_stock: true
8
- features:
9
- - 16GB RAM
10
- - 512GB SSD
11
- - Intel i7
12
- - 15.6" Display
13
- - id: 102
14
- name: Wireless Mouse
15
- category: accessories
16
- price: 49.99
17
- in_stock: true
18
- features:
19
- - Bluetooth 5.0
20
- - Rechargeable
21
- - Ergonomic design
22
- - id: 103
23
- name: USB-C Cable
24
- category: accessories
25
- price: 19.99
26
- in_stock: false
27
- features:
28
- - 3m length
29
- - Fast charging
30
- - Data transfer
@@ -1,17 +0,0 @@
1
- # Users data file
2
- users:
3
- - id: 1
4
- name: Alice Smith
5
- email: alice@example.com
6
- role: admin
7
- active: true
8
- - id: 2
9
- name: Bob Johnson
10
- email: bob@example.com
11
- role: user
12
- active: true
13
- - id: 3
14
- name: Charlie Brown
15
- email: charlie@example.com
16
- role: user
17
- active: false
@@ -1,19 +0,0 @@
1
- # Example main.yaml file with !reference and !reference-all tags
2
- # This demonstrates the usage of the yaml-reference-ts library
3
-
4
- app:
5
- name: My Application
6
- version: 1.0.0
7
- config: !reference
8
- path: ./config/database.yaml
9
- settings: !reference { path: ./config/settings.yaml }
10
-
11
- data:
12
- files: !reference-all
13
- glob: ./data/*.yaml
14
- additional: !reference-all { glob: ./additional/*.yaml }
15
-
16
- metadata:
17
- author: John Doe
18
- created: 2024-01-01
19
- description: Example configuration with references