@origints/yaml 0.1.0 → 0.1.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/README.md +173 -0
- package/package.json +11 -11
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# @origints/yaml
|
|
2
|
+
|
|
3
|
+
> YAML parsing for Origins with anchor/alias/tag preservation and full lineage tracking.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
YAML parsers typically discard structural information like anchors, aliases, and tags during parsing. When you need to trace where a value came from in a complex YAML document with references, you're out of luck.
|
|
10
|
+
|
|
11
|
+
This package preserves YAML's structural features while integrating with Origins' provenance system. Every value can be traced back to its source location, even through anchor references.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Parse single or multi-document YAML streams
|
|
18
|
+
- Preserve anchors, aliases, and custom tags
|
|
19
|
+
- Full source location tracking for every node
|
|
20
|
+
- Navigation API with type-safe extraction
|
|
21
|
+
- JSON conversion with customizable options
|
|
22
|
+
- Integrates with Origins transform registry
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @origints/yaml @origints/core
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { parseYaml } from "@origints/yaml";
|
|
34
|
+
|
|
35
|
+
const yaml = `
|
|
36
|
+
name: Alice
|
|
37
|
+
age: 30
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const result = parseYaml(yaml);
|
|
41
|
+
|
|
42
|
+
if (result.ok) {
|
|
43
|
+
console.log(result.value.get("name").asString());
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Expected output:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
Alice
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
- Supported platforms:
|
|
58
|
+
- macOS / Linux / Windows
|
|
59
|
+
- Runtime requirements:
|
|
60
|
+
- Node.js >= 18
|
|
61
|
+
- Package managers:
|
|
62
|
+
- npm, pnpm, yarn
|
|
63
|
+
- Peer dependencies:
|
|
64
|
+
- @origints/core ^0.1.0
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install @origints/yaml @origints/core
|
|
68
|
+
# or
|
|
69
|
+
pnpm add @origints/yaml @origints/core
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Usage
|
|
75
|
+
|
|
76
|
+
### Basic parsing
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { parseYaml } from "@origints/yaml";
|
|
80
|
+
|
|
81
|
+
const result = parseYaml(`
|
|
82
|
+
database:
|
|
83
|
+
host: localhost
|
|
84
|
+
port: 5432
|
|
85
|
+
`);
|
|
86
|
+
|
|
87
|
+
if (result.ok) {
|
|
88
|
+
const node = result.value;
|
|
89
|
+
const host = node.get("database").get("host").asString();
|
|
90
|
+
const port = node.get("database").get("port").asNumber();
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Multi-document streams
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import { parseYamlAll } from "@origints/yaml";
|
|
98
|
+
|
|
99
|
+
const result = parseYamlAll(`
|
|
100
|
+
---
|
|
101
|
+
name: doc1
|
|
102
|
+
---
|
|
103
|
+
name: doc2
|
|
104
|
+
`);
|
|
105
|
+
|
|
106
|
+
if (result.ok) {
|
|
107
|
+
for (const doc of result.value) {
|
|
108
|
+
console.log(doc.get("name").asString());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Using with Origins plans
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { Planner, loadFile, globalRegistry } from "@origints/core";
|
|
117
|
+
import { parseYaml, registerYamlTransforms } from "@origints/yaml";
|
|
118
|
+
|
|
119
|
+
registerYamlTransforms(globalRegistry);
|
|
120
|
+
|
|
121
|
+
const plan = Planner.in(loadFile("config.yaml"))
|
|
122
|
+
.mapIn(parseYaml())
|
|
123
|
+
.emit((out, $) => {
|
|
124
|
+
out.add("host", $.get("database").get("host").asString());
|
|
125
|
+
})
|
|
126
|
+
.compile();
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Converting to JSON
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import { parseYaml, toJson } from "@origints/yaml";
|
|
133
|
+
|
|
134
|
+
const result = parseYaml(yamlString);
|
|
135
|
+
if (result.ok) {
|
|
136
|
+
const json = toJson(result.value);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Project Status
|
|
143
|
+
|
|
144
|
+
- **Experimental** - APIs may change
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Non-Goals
|
|
149
|
+
|
|
150
|
+
- Not a YAML serializer (output/writing)
|
|
151
|
+
- Not a schema validator for YAML
|
|
152
|
+
- Not a replacement for js-yaml or yaml packages
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Documentation
|
|
157
|
+
|
|
158
|
+
- See `@origints/core` for Origins concepts
|
|
159
|
+
- See [yaml](https://www.npmjs.com/package/yaml) for underlying parser
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Contributing
|
|
164
|
+
|
|
165
|
+
- Open an issue before large changes
|
|
166
|
+
- Keep PRs focused
|
|
167
|
+
- Tests required for new features
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@origints/yaml",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "YAML parsing for Origins with anchor/alias/tag preservation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vite build",
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"lint": "eslint \"{src,tests}/**/*.{ts,tsx}\" --max-warnings 0",
|
|
28
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
29
|
+
},
|
|
23
30
|
"dependencies": {
|
|
24
31
|
"yaml": "^2.7.1"
|
|
25
32
|
},
|
|
@@ -27,20 +34,13 @@
|
|
|
27
34
|
"@origints/core": "^0.1.0"
|
|
28
35
|
},
|
|
29
36
|
"devDependencies": {
|
|
37
|
+
"@origints/core": "workspace:*",
|
|
30
38
|
"@types/node": "25.0.6",
|
|
31
39
|
"@vitest/coverage-v8": "^4.0.16",
|
|
32
40
|
"eslint": "9.39.2",
|
|
33
41
|
"typescript": "5.9.3",
|
|
34
42
|
"vite": "7.3.1",
|
|
35
43
|
"vite-plugin-dts": "4.5.4",
|
|
36
|
-
"vitest": "4.0.16"
|
|
37
|
-
"@origints/core": "0.1.0"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "vite build",
|
|
41
|
-
"test": "vitest run",
|
|
42
|
-
"test:coverage": "vitest run --coverage",
|
|
43
|
-
"lint": "eslint \"{src,tests}/**/*.{ts,tsx}\" --max-warnings 0",
|
|
44
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
44
|
+
"vitest": "4.0.16"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|