feat(skd): modify-parameter operation, availableValues/denyIncompleteValues support

- skd-edit: new modify-parameter operation — set use, denyIncompleteValues, add availableValue entries to existing parameters
- skd-compile: availableValues array and denyIncompleteValues in parameter JSON DSL
- Auto-detect DesignTimeValue type for reference values in availableValue entries

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-04-06 19:19:32 +03:00
parent 87e636f644
commit d755c41233
4 changed files with 216 additions and 2 deletions
@@ -886,6 +886,33 @@ function Emit-SingleParam {
X "`t`t<valueListAllowed>true</valueListAllowed>"
}
# AvailableValues
if ($p -isnot [string] -and $p.availableValues) {
foreach ($av in $p.availableValues) {
$avVal = "$($av.value)"
$avType = "xs:string"
if ($avVal -match '^(Перечисление|Справочник|ПланСчетов|Документ|ПланВидовХарактеристик|ПланВидовРасчета)\.') {
$avType = "dcscor:DesignTimeValue"
}
X "`t`t<availableValue>"
X "`t`t`t<value xsi:type=`"$avType`">$(Esc-Xml $avVal)</value>"
if ($av.presentation) {
X "`t`t`t<presentation xsi:type=`"v8:LocalStringType`">"
X "`t`t`t`t<v8:item>"
X "`t`t`t`t`t<v8:lang>ru</v8:lang>"
X "`t`t`t`t`t<v8:content>$(Esc-Xml "$($av.presentation)")</v8:content>"
X "`t`t`t`t</v8:item>"
X "`t`t`t</presentation>"
}
X "`t`t</availableValue>"
}
}
# DenyIncompleteValues
if ($p -isnot [string] -and $p.denyIncompleteValues -eq $true) {
X "`t`t<denyIncompleteValues>true</denyIncompleteValues>"
}
# Use
if ($p -isnot [string] -and $p.use) {
X "`t`t<use>$(Esc-Xml "$($p.use)")</use>"
@@ -754,6 +754,28 @@ def emit_single_param(lines, p, parsed):
if parsed.get('valueListAllowed'):
lines.append('\t\t<valueListAllowed>true</valueListAllowed>')
# AvailableValues
if p is not None and not isinstance(p, str) and p.get('availableValues'):
for av in p['availableValues']:
av_val = str(av.get('value', ''))
av_type = 'xs:string'
if re.match(r'^(Перечисление|Справочник|ПланСчетов|Документ|ПланВидовХарактеристик|ПланВидовРасчета)\.', av_val):
av_type = 'dcscor:DesignTimeValue'
lines.append('\t\t<availableValue>')
lines.append(f'\t\t\t<value xsi:type="{av_type}">{esc_xml(av_val)}</value>')
if av.get('presentation'):
lines.append('\t\t\t<presentation xsi:type="v8:LocalStringType">')
lines.append('\t\t\t\t<v8:item>')
lines.append('\t\t\t\t\t<v8:lang>ru</v8:lang>')
lines.append(f'\t\t\t\t\t<v8:content>{esc_xml(str(av["presentation"]))}</v8:content>')
lines.append('\t\t\t\t</v8:item>')
lines.append('\t\t\t</presentation>')
lines.append('\t\t</availableValue>')
# DenyIncompleteValues
if p is not None and not isinstance(p, str) and p.get('denyIncompleteValues') is True:
lines.append('\t\t<denyIncompleteValues>true</denyIncompleteValues>')
# Use
if p is not None and not isinstance(p, str) and p.get('use'):
lines.append(f'\t\t<use>{esc_xml(str(p["use"]))}</use>')
+104 -1
View File
@@ -10,7 +10,7 @@ param(
"add-dataParameter","add-order","add-selection","add-dataSetLink",
"add-dataSet","add-variant","add-conditionalAppearance",
"set-query","patch-query","set-outputParameter","set-structure",
"modify-field","modify-filter","modify-dataParameter",
"modify-field","modify-filter","modify-dataParameter","modify-parameter",
"clear-selection","clear-order","clear-filter",
"remove-field","remove-total","remove-calculated-field","remove-parameter","remove-filter")]
[string]$Operation,
@@ -1655,6 +1655,109 @@ switch ($Operation) {
}
}
"modify-parameter" {
foreach ($val in $values) {
# Parse: "ParamName key=value key=value"
$parts = $val -split '\s+', 2
$paramName = $parts[0].Trim()
$rest = if ($parts.Count -gt 1) { $parts[1].Trim() } else { "" }
# Find parameter element
$paramEl = Find-ElementByChildValue $xmlDoc.DocumentElement "parameter" "name" $paramName $schNs
if (-not $paramEl) {
Write-Host "[WARN] Parameter `"$paramName`" not found — skipped"
continue
}
$childIndent = Get-ChildIndent $paramEl
# Parse key=value pairs (special handling for availableValue)
if ($rest -match '^availableValue=(.+)') {
$avRest = $rest -replace '^availableValue=', ''
# Parse: "Перечисление...X presentation=текст"
$avParts = $avRest -split '\s+presentation=', 2
$avValue = $avParts[0].Trim()
$avPresentation = if ($avParts.Count -gt 1) { $avParts[1].Trim() } else { "" }
# Detect value type
$avType = "xs:string"
if ($avValue -match '^(Перечисление|Справочник|ПланСчетов|Документ|ПланВидовХарактеристик|ПланВидовРасчета)\.') {
$avType = "dcscor:DesignTimeValue"
}
$avLines = @()
$avLines += "$childIndent<availableValue>"
$avLines += "$childIndent`t<value xsi:type=`"$avType`">$(Esc-Xml $avValue)</value>"
if ($avPresentation) {
$avLines += "$childIndent`t<presentation xsi:type=`"v8:LocalStringType`">"
$avLines += "$childIndent`t`t<v8:item>"
$avLines += "$childIndent`t`t`t<v8:lang>ru</v8:lang>"
$avLines += "$childIndent`t`t`t<v8:content>$(Esc-Xml $avPresentation)</v8:content>"
$avLines += "$childIndent`t`t</v8:item>"
$avLines += "$childIndent`t</presentation>"
}
$avLines += "$childIndent</availableValue>"
$fragXml = $avLines -join "`r`n"
# Insert before denyIncompleteValues/use or at end
$refNode = $null
foreach ($tag in @("denyIncompleteValues","use")) {
$found = $paramEl.SelectSingleNode($tag)
if ($found) { $refNode = $found; break }
}
$nodes = Import-Fragment $xmlDoc $fragXml
foreach ($node in $nodes) {
Insert-BeforeElement $paramEl $node $refNode $childIndent
}
Write-Host "[OK] Parameter `"$paramName`": availableValue added"
} else {
# Simple key=value pairs: use=Always, denyIncompleteValues=true
$kvPairs = [regex]::Matches($rest, '(\w+)=(\S+)')
foreach ($kv in $kvPairs) {
$key = $kv.Groups[1].Value
$value = $kv.Groups[2].Value
$existing = $paramEl.SelectSingleNode($key)
if ($existing) {
$existing.InnerText = $value
Write-Host "[OK] Parameter `"$paramName`": $key updated to $value"
} else {
# Determine insertion order
$afterTags = switch ($key) {
"denyIncompleteValues" { @("availableValue","useRestriction","availableAsField","expression","value","valueType","title","name") }
"use" { @("denyIncompleteValues","availableValue","useRestriction","availableAsField","expression","value","valueType","title","name") }
default { @("name") }
}
$refNode = $null
foreach ($tag in @("denyIncompleteValues","use")) {
if ($tag -eq $key) { continue }
$found = $paramEl.SelectSingleNode($tag)
if ($found -and ($afterTags -contains $tag -eq $false)) {
$refNode = $found; break
}
}
$fragXml = "$childIndent<$key>$(Esc-Xml $value)</$key>"
$nodes = Import-Fragment $xmlDoc $fragXml
foreach ($node in $nodes) {
# Append before closing tag (last whitespace child)
$lastChild = $paramEl.LastChild
if ($lastChild.NodeType -eq 'Whitespace' -or $lastChild.NodeType -eq 'SignificantWhitespace') {
$paramEl.InsertBefore($node, $lastChild) | Out-Null
} else {
$paramEl.AppendChild($node) | Out-Null
}
}
# Add trailing whitespace
$ws = $xmlDoc.CreateWhitespace("`r`n$($childIndent -replace '`t$','')")
$paramEl.AppendChild($ws) | Out-Null
Write-Host "[OK] Parameter `"$paramName`": $key=$value added"
}
}
}
}
}
"add-filter" {
$settings = Resolve-VariantSettings
$varName = Get-VariantName
+63 -1
View File
@@ -18,7 +18,7 @@ VALID_OPS = [
"add-dataParameter", "add-order", "add-selection", "add-dataSetLink",
"add-dataSet", "add-variant", "add-conditionalAppearance",
"set-query", "patch-query", "set-outputParameter", "set-structure",
"modify-field", "modify-filter", "modify-dataParameter",
"modify-field", "modify-filter", "modify-dataParameter", "modify-parameter",
"clear-selection", "clear-order", "clear-filter",
"remove-field", "remove-total", "remove-calculated-field", "remove-parameter", "remove-filter",
]
@@ -1435,6 +1435,68 @@ elif operation == "add-parameter":
if parsed.get("autoDates"):
print('[OK] Auto-parameters "\u0414\u0430\u0442\u0430\u041d\u0430\u0447\u0430\u043b\u0430", "\u0414\u0430\u0442\u0430\u041e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f" added')
elif operation == "modify-parameter":
for val in values:
parts = val.split(None, 1)
param_name = parts[0].strip()
rest = parts[1].strip() if len(parts) > 1 else ""
param_el = find_element_by_child_value(xml_doc, "parameter", "name", param_name, SCH_NS)
if param_el is None:
print(f'[WARN] Parameter "{param_name}" not found -- skipped')
continue
child_indent = get_child_indent(param_el)
if rest.startswith("availableValue="):
av_rest = rest[len("availableValue="):]
av_parts = av_rest.split(" presentation=", 1)
av_value = av_parts[0].strip()
av_presentation = av_parts[1].strip() if len(av_parts) > 1 else ""
av_type = "xs:string"
if re.match(r'^(Перечисление|Справочник|ПланСчетов|Документ|ПланВидовХарактеристик|ПланВидовРасчета)\.', av_value):
av_type = "dcscor:DesignTimeValue"
av_lines = [f"{child_indent}<availableValue>"]
av_lines.append(f'{child_indent}\t<value xsi:type="{av_type}">{esc_xml(av_value)}</value>')
if av_presentation:
av_lines.append(f'{child_indent}\t<presentation xsi:type="v8:LocalStringType">')
av_lines.append(f"{child_indent}\t\t<v8:item>")
av_lines.append(f"{child_indent}\t\t\t<v8:lang>ru</v8:lang>")
av_lines.append(f"{child_indent}\t\t\t<v8:content>{esc_xml(av_presentation)}</v8:content>")
av_lines.append(f"{child_indent}\t\t</v8:item>")
av_lines.append(f"{child_indent}\t</presentation>")
av_lines.append(f"{child_indent}</availableValue>")
frag_xml = "\r\n".join(av_lines)
ref_node = None
for tag in ["denyIncompleteValues", "use"]:
found = param_el.find(tag)
if found is not None:
ref_node = found
break
nodes = import_fragment(xml_doc, frag_xml)
for node in nodes:
insert_before_element(param_el, node, ref_node, child_indent)
print(f'[OK] Parameter "{param_name}": availableValue added')
else:
for m in re.finditer(r'(\w+)=(\S+)', rest):
key, value = m.group(1), m.group(2)
existing = param_el.find(key)
if existing is not None:
existing.text = value
print(f'[OK] Parameter "{param_name}": {key} updated to {value}')
else:
frag_xml = f"{child_indent}<{key}>{esc_xml(value)}</{key}>"
nodes = import_fragment(xml_doc, frag_xml)
for node in nodes:
last_child = list(param_el)[-1] if len(param_el) else None
if last_child is not None:
last_child.tail = (last_child.tail or "") + "\r\n" + child_indent
param_el.append(node)
print(f'[OK] Parameter "{param_name}": {key}={value} added')
elif operation == "add-filter":
settings = resolve_variant_settings()
var_name = get_variant_name()