Skip to content

Commit 56337da

Browse files
Add comment-based help and inline parameter docs to Remove-YamlEntry private helpers
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c6544ce commit 56337da

8 files changed

Lines changed: 168 additions & 0 deletions

src/functions/private/Add-YamlRemovalWork.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,40 @@ function Add-YamlRemovalWork {
22
<#
33
.SYNOPSIS
44
Charges deterministic operations to the YAML removal work budget.
5+
6+
.DESCRIPTION
7+
Increments the shared work counter for expensive removal steps.
8+
Centralizing the charge keeps pointer resolution, coalescing, mutation,
9+
and validation on one deterministic budget and produces a
10+
location-aware exception when exceeded.
11+
12+
.EXAMPLE
13+
Add-YamlRemovalWork -State $state -Count 3 -Operation 'target ordering' -Node $target.Node
14+
15+
Charges three target-ordering operations and throws if the removal budget is exceeded.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[CmdletBinding()]
721
param (
22+
# The shared state carries current and maximum work counts for the
23+
# removal invocation.
824
[Parameter(Mandatory)]
925
[pscustomobject] $State,
1026

27+
# The operation cost is configurable because some steps charge a batch
28+
# of work at once.
1129
[Parameter()]
1230
[ValidateRange(1, 2147483647)]
1331
[int] $Count = 1,
1432

33+
# The operation name explains which removal phase consumed the budget.
1534
[Parameter(Mandatory)]
1635
[string] $Operation,
1736

37+
# The optional node anchors any budget exception to the YAML source
38+
# location.
1839
[Parameter()]
1940
[AllowNull()]
2041
[pscustomobject] $Node

src/functions/private/Assert-YamlRemovalGraph.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,61 @@ function Assert-YamlRemovalGraph {
22
<#
33
.SYNOPSIS
44
Validates a removed representation graph and its resource budgets.
5+
6+
.DESCRIPTION
7+
Traverses the post-removal representation graph to enforce depth, node,
8+
alias, scalar, and tag limits before emitting YAML. It also rechecks
9+
tagged collection invariants and duplicate-key comparisons so removed
10+
output remains valid and deterministic.
11+
12+
.EXAMPLE
13+
Assert-YamlRemovalGraph -Documents $documents -Depth 100 -MaxNodes 100000 -MaxAliases 1000 -MaxScalarLength 1048576 -MaxTagLength 1024 -MaxTotalTagLength 65536 -State $state
14+
15+
Validates the mutated documents and throws a classified removal exception if an output limit is exceeded.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[CmdletBinding()]
721
param (
22+
# The post-removal document roots are walked so validation covers exactly
23+
# what will be emitted.
824
[Parameter(Mandatory)]
925
[AllowEmptyCollection()]
1026
[object[]] $Documents,
1127

28+
# The depth limit prevents a removal result from producing an over-deep
29+
# graph.
1230
[Parameter(Mandatory)]
1331
[int] $Depth,
1432

33+
# The node limit bounds traversal, duplicate-key comparison, and output
34+
# graph size.
1535
[Parameter(Mandatory)]
1636
[int] $MaxNodes,
1737

38+
# The alias limit keeps emitted alias count within the caller's resource
39+
# budget.
1840
[Parameter(Mandatory)]
1941
[int] $MaxAliases,
2042

43+
# The scalar length limit rejects oversized decoded scalar content after
44+
# mutation.
2145
[Parameter(Mandatory)]
2246
[int] $MaxScalarLength,
2347

48+
# The per-tag limit prevents an emitted node from carrying an oversized
49+
# expanded tag.
2450
[Parameter(Mandatory)]
2551
[int] $MaxTagLength,
2652

53+
# The cumulative tag limit bounds total expanded tag text across the
54+
# output graph.
2755
[Parameter(Mandatory)]
2856
[int] $MaxTotalTagLength,
2957

58+
# The shared removal work state accounts validation operations against
59+
# the invocation budget.
3060
[Parameter(Mandatory)]
3161
[pscustomobject] $State
3262
)

src/functions/private/ConvertFrom-YamlJsonPointer.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@ function ConvertFrom-YamlJsonPointer {
22
<#
33
.SYNOPSIS
44
Parses and strictly decodes one RFC 6901 JSON Pointer.
5+
6+
.DESCRIPTION
7+
Validates that a removal path is an RFC 6901 JSON Pointer and decodes
8+
each token's tilde escapes. Strict decoding prevents ambiguous or
9+
non-standard paths from selecting unintended YAML graph edges.
10+
11+
.EXAMPLE
12+
ConvertFrom-YamlJsonPointer -Pointer '/metadata/internal~1id' -State $state
13+
14+
Returns a boxed token array containing metadata and internal/id.
15+
16+
.LINK
17+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
518
#>
619
[CmdletBinding()]
720
[OutputType([pscustomobject])]
821
param (
22+
# The raw removal path must be decoded once so later graph resolution
23+
# uses canonical tokens.
924
[Parameter(Mandatory)]
1025
[AllowEmptyString()]
1126
[string] $Pointer,
1227

28+
# The work state charges parsing by pointer length to keep path
29+
# processing bounded.
1330
[Parameter(Mandatory)]
1431
[pscustomobject] $State
1532
)

src/functions/private/Get-YamlRemovalNode.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,31 @@ function Get-YamlRemovalNode {
22
<#
33
.SYNOPSIS
44
Resolves aliases to an effective YAML node with cycle-safe accounting.
5+
6+
.DESCRIPTION
7+
Follows alias nodes until it reaches the effective scalar, sequence, or
8+
mapping node used by removal logic. It records alias traversal work and
9+
detects alias-only cycles or broken aliases so pointer walks cannot loop
10+
forever.
11+
12+
.EXAMPLE
13+
Get-YamlRemovalNode -Node $entry.Value -State $state
14+
15+
Returns the non-alias node that removal logic should inspect for the entry value.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[CmdletBinding()]
721
[OutputType([pscustomobject])]
822
param (
23+
# The candidate node may be an alias, so removal needs its effective
24+
# target before inspecting kind or value.
925
[Parameter(Mandatory)]
1026
[pscustomobject] $Node,
1127

28+
# The work state charges each alias hop and enforces traversal safety for
29+
# this invocation.
1230
[Parameter(Mandatory)]
1331
[pscustomobject] $State
1432
)

src/functions/private/New-YamlRemovalException.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ function New-YamlRemovalException {
22
<#
33
.SYNOPSIS
44
Creates a classified exception for a YAML removal failure.
5+
6+
.DESCRIPTION
7+
Wraps removal failures in the module's YAML exception shape with the
8+
correct error id and source marks. It falls back to a zero mark when no
9+
node is available so budget and pointer parse failures remain
10+
classified.
11+
12+
.EXAMPLE
13+
New-YamlRemovalException -ErrorId 'YamlRemovalPathNotFound' -Message 'The path was not found.' -Node $node
14+
15+
Returns a classified exception whose source marks point at the supplied node.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
721
'PSUseShouldProcessForStateChangingFunctions', '',
@@ -10,12 +24,18 @@ function New-YamlRemovalException {
1024
[CmdletBinding()]
1125
[OutputType([System.FormatException])]
1226
param (
27+
# The removal-specific error id classifies the failure for callers and
28+
# tests.
1329
[Parameter(Mandatory)]
1430
[string] $ErrorId,
1531

32+
# The message explains the exact pointer, graph, or budget problem to
33+
# report.
1634
[Parameter(Mandatory)]
1735
[string] $Message,
1836

37+
# The node supplies source marks when a graph location exists; null
38+
# failures use a synthetic mark.
1939
[Parameter()]
2040
[AllowNull()]
2141
[pscustomobject] $Node

src/functions/private/Remove-YamlRepresentationTarget.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,40 @@ function Remove-YamlRepresentationTarget {
22
<#
33
.SYNOPSIS
44
Applies resolved YAML removal targets in stable mutation order.
5+
6+
.DESCRIPTION
7+
Mutates the cloned document list and container nodes for previously
8+
resolved removal targets. It groups and sorts targets deepest-first and
9+
descending by index so removing documents, sequence items, and mapping
10+
entries does not shift later mutations.
11+
12+
.EXAMPLE
13+
Remove-YamlRepresentationTarget -Documents $documents -Targets $targets -State $state
14+
15+
Detaches the resolved document, sequence, and mapping targets from the cloned representation graph.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
721
'PSUseShouldProcessForStateChangingFunctions', '',
822
Justification = 'Mutates only an isolated in-memory representation graph.'
923
)]
1024
[CmdletBinding()]
1125
param (
26+
# The cloned document list is mutated when a target removes an entire
27+
# YAML document.
1228
[Parameter(Mandatory)]
1329
[System.Collections.Generic.List[object]] $Documents,
1430

31+
# The resolved targets identify exact document, sequence, or mapping
32+
# edges to detach.
1533
[Parameter(Mandatory)]
1634
[AllowEmptyCollection()]
1735
[object[]] $Targets,
1836

37+
# The work state charges ordering and mutation steps so transaction
38+
# application is budgeted.
1939
[Parameter(Mandatory)]
2040
[pscustomobject] $State
2141
)

src/functions/private/Resolve-YamlRemovalTarget.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,49 @@ function Resolve-YamlRemovalTarget {
22
<#
33
.SYNOPSIS
44
Resolves one decoded JSON Pointer against one YAML document.
5+
6+
.DESCRIPTION
7+
Walks a single document's representation graph using decoded RFC 6901
8+
tokens and returns the exact document, mapping, or sequence edge to
9+
remove. It preserves YAML semantics by resolving aliases safely and
10+
matching only scalar string mapping keys without coercion.
11+
12+
.EXAMPLE
13+
Resolve-YamlRemovalTarget -Document $document -DocumentIndex 0 -Pointer '/service/obsolete' -Tokens @('service', 'obsolete') -State $state
14+
15+
Returns the parent edge that addresses /service/obsolete in document zero.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[CmdletBinding()]
721
[OutputType([pscustomobject])]
822
param (
23+
# The document root provides the representation graph that the pointer
24+
# is resolved against.
925
[Parameter(Mandatory)]
1026
[pscustomobject] $Document,
1127

28+
# The document index is included in target keys and diagnostics so
29+
# multi-document removals stay distinct.
1230
[Parameter(Mandatory)]
1331
[int] $DocumentIndex,
1432

33+
# The original pointer is preserved for diagnostics attached to
34+
# unresolved or ambiguous paths.
1535
[Parameter(Mandatory)]
1636
[AllowEmptyString()]
1737
[string] $Pointer,
1838

39+
# Decoded pointer tokens drive each mapping-key or sequence-index lookup
40+
# without re-parsing the path.
1941
[Parameter(Mandatory)]
2042
[AllowEmptyCollection()]
2143
[AllowEmptyString()]
2244
[string[]] $Tokens,
2345

46+
# The shared work state bounds token resolution, alias traversal, and
47+
# mapping scans.
2448
[Parameter(Mandatory)]
2549
[pscustomobject] $State
2650
)

src/functions/private/Select-YamlRemovalTarget.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@ function Select-YamlRemovalTarget {
22
<#
33
.SYNOPSIS
44
Coalesces duplicate targets and drops fully subsumed descendants.
5+
6+
.DESCRIPTION
7+
Combines multiple resolved removal requests that address the same edge
8+
and removes descendants already covered by ancestor removals. This
9+
prevents duplicate mutation attempts and keeps transaction ordering
10+
stable.
11+
12+
.EXAMPLE
13+
Select-YamlRemovalTarget -Targets $resolvedTargets -State $state
14+
15+
Returns a boxed target list with duplicates coalesced and ancestor-covered descendants removed.
16+
17+
.LINK
18+
https://psmodule.io/Yaml/Functions/Remove-YamlEntry/
519
#>
620
[CmdletBinding()]
721
[OutputType([pscustomobject])]
822
param (
23+
# The resolved target set may contain duplicate edges or descendant paths
24+
# that one ancestor mutation will already remove.
925
[Parameter(Mandatory)]
1026
[AllowEmptyCollection()]
1127
[object[]] $Targets,
1228

29+
# The work state accounts coalescing and ancestry indexing so target
30+
# selection stays bounded.
1331
[Parameter(Mandatory)]
1432
[pscustomobject] $State
1533
)

0 commit comments

Comments
 (0)