< Summary - Kestrun — Combined Coverage

Information
Class: Public.SharedState.Set-KrSharedState
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/SharedState/Set-KrSharedState.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
100%
Covered lines: 1
Uncovered lines: 0
Coverable lines: 1
Total lines: 49
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/SharedState/Set-KrSharedState.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Defines or updates a global variable accessible across Kestrun scripts.
 4
 5    .DESCRIPTION
 6        Stores a value in the Kestrun global variable table. Variables may be marked
 7        as read-only to prevent accidental modification.
 8        If the variable already exists, its value is updated. If it does not exist,
 9        it is created.
 10    .PARAMETER Name
 11        Name of the variable to create or update.
 12    .PARAMETER Value
 13        Value to assign to the variable.
 14    .PARAMETER AllowsValueType
 15        If specified, allows the variable to hold value types (e.g., int, bool).
 16    .EXAMPLE
 17        Set-KrSharedState -Name "MyVariable" -Value "Hello, World!"
 18        This creates a global variable "MyVariable" with the value "Hello, World!".
 19    .EXAMPLE
 20        Set-KrSharedState -Name "MyNamespace.MyVariable" -Value @{item=42}
 21        This creates a global variable "MyNamespace.MyVariable" with the value @{item=42}.
 22    .NOTES
 23        This function is part of the Kestrun.SharedState module and is used to define or update global variables.
 24#>
 25function Set-KrSharedState {
 26    [KestrunRuntimeApi('Definition')]
 27    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
 28    [CmdletBinding()]
 29    [OutputType([Kestrun.Hosting.KestrunHost])]
 30    param(
 31        [Parameter(Mandatory)]
 32        [string]$Name,
 33
 34        [Parameter(Mandatory)]
 35        [object]$Value,
 36
 37        [Parameter()]
 38        [switch]$AllowsValueType
 39    )
 40    process {
 41        # Define or update the variable; throws if it was already read-only
 142        $null = [Kestrun.SharedState.SharedStateStore]::Set(
 43            $Name,
 44            $Value,
 45            $AllowsValueType.IsPresent  # Allow value types if specified
 46        )
 47    }
 48}
 49

Methods/Properties

Set-KrSharedState()