Skip to content

Commit df80708

Browse files
Document representation-preserving YAML removal
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 1f66f22 commit df80708

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The module exports:
3333
| `Format-Yaml` | Normalize YAML streams without projecting representation nodes to PowerShell values. |
3434
| `Import-Yaml` | Strictly decode and parse YAML files. |
3535
| `Merge-Yaml` | Merge complete YAML streams without losing representation graph details. |
36+
| `Remove-YamlEntry` | Remove selected entries or documents without losing representation graph details. |
3637
| `Test-Yaml` | Test YAML syntax, tags, duplicate keys, and configured resource limits. |
3738

3839
## Parse YAML
@@ -217,6 +218,29 @@ creation, charged merge operations, and the resulting stream graph. Index,
217218
fingerprint, candidate, alias-traversal, and equality work all consume the merge
218219
operation budget. Alias and expanded-tag budgets are also enforced on the result.
219220

221+
## Remove YAML entries
222+
223+
`Remove-YamlEntry` removes mapping entries, sequence items, or whole documents directly from a deep-cloned representation graph. Input array elements and pipeline records are joined with LF as one YAML stream, matching `Format-Yaml`.
224+
225+
```powershell
226+
$cleanYaml = Get-Content -Path '.\config.yaml' |
227+
Remove-YamlEntry -Path @('/metadata/internalId', '/services/1/deprecated')
228+
```
229+
230+
Paths use [RFC 6901 JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901). An empty pointer selects a document root, `~0` addresses a tilde, and `~1` addresses a slash. Mapping tokens match only scalar YAML string keys by ordinal content, so numeric, complex, and unknown-tagged keys are never coerced or guessed. Sequence tokens must be `0` or a non-zero decimal index without signs or leading zeros.
231+
232+
Document zero is selected by default. Use `-DocumentIndex` for another zero-based document, or `-AllDocuments` to apply every path independently to every original document. `-IgnoreMissing` skips only unresolved document/path combinations.
233+
234+
```powershell
235+
$withoutTemporaryData = Remove-YamlEntry $stream '/temporary' `
236+
-AllDocuments -IgnoreMissing -Indent 4
237+
$withoutSecondDocument = Remove-YamlEntry $stream '' -DocumentIndex 1
238+
```
239+
240+
Every required target is resolved before mutation, duplicate logical targets are coalesced, and ancestors subsume descendants. Removing inside a shared mapping or sequence changes every alias to that node; removing an alias edge removes only that edge. Original sequence indexes and document roots are removed in descending order.
241+
242+
Output preserves unaffected tags, anchors, aliases, shared and cyclic identity, complex keys, mapping order, and document order. It is one deterministic string with LF line endings and no final newline; removing every document returns an empty string. Parser limits are mirrored, while cloning, pointer and mutation work, and output validation use independent resource ceilings.
243+
220244
## Export YAML files
221245

222246
`Export-Yaml` aggregates pipeline records like `ConvertTo-Yaml`, serializes the
@@ -265,6 +289,8 @@ limit violations. Unexpected runtime failures are not suppressed.
265289
YAML 1.2 core schema.
266290
- YAML stream merging compares effective tags and structural representation
267291
values without projecting through PowerShell objects.
292+
- YAML entry removal resolves JSON Pointers against an immutable representation
293+
clone and mutates shared nodes by identity without object projection.
268294
- Parsing defaults to depth 100, 100000 nodes, 1000 aliases, 1048576 decoded
269295
characters per scalar, 1024 characters per expanded tag, 65536 cumulative
270296
expanded tag characters, and 4096 digits per numeric scalar. The

examples/General.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ service:
6161
$mergedYaml = Merge-Yaml -InputObject @($baseYaml, $overlayYaml)
6262
$mergedYaml
6363

64+
# Remove selected YAML entries without projecting the representation graph.
65+
$cleanedYaml = $mergedYaml |
66+
Remove-YamlEntry -Path @('/service/image', '/service/ports/0')
67+
$cleanedYaml
68+
6469
# Atomically export one file, then import it with strict decoding.
6570
$configPath = Join-Path $env:TEMP 'yaml-example.yaml'
6671
$config | Export-Yaml -Path $configPath -PassThru

0 commit comments

Comments
 (0)