feat(meta-compile,meta-decompile): состав плана обмена — Content.xml (v1.42/v0.31)

Соседний Ext/Content.xml (состав плана обмена: объекты-участники + признак
авторегистрации) был вне скоупа раундтрипа → при декомпиляции→компиляции состав
терялся (компилятор писал пустой <ExchangePlanContent/>, декомпилятор не захватывал).

DSL content/Состав: массив MDObjectRef — строка "Type.Name" (AutoRecord=Deny,
дефолт) / "Type.Name: autoRecord" (Allow; токен-признак autoRecord/АвтоРегистрация,
регистронезав.; прощающе : Allow/: Разрешить) ЛИБО объект {metadata, autoRecord:
bool|Allow/Deny/Разрешить/Запретить} (синонимы Метаданные/объект, АвтоРегистрация).
Декомпилятор пишет короткую строковую форму.

Class-2 фикс заголовка: пустой <ExchangePlanContent/> писался с 2 namespace,
реальный 1С — с 4 (+xmlns:xs/xsi); чинил и пустой шаблон.

Роундтрип 42 ЭП (acc+erp): match 39/42, TOTAL 146 без новых диффов (остаток —
известный хвост TS-LineNumber/FillValue-пробелы). Регресс 48/48 ps1+py, ps1↔py
identical. 1С-cert ✓ (пустой 4-ns корень + непустой состав); verify-snapshots
расширен: getStructuralDeps стабит объекты состава ЭП по MDObjectRef + стаб Constant.
spec §7.2a, кейс exchange-plan-content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-07-06 12:55:08 +03:00
co-authored by Claude Opus 4.8
parent 126ce0bbd8
commit 11e7abfc3f
13 changed files with 567 additions and 9 deletions
@@ -1,4 +1,4 @@
# meta-compile v1.41 — Compile 1C metadata object from JSON
# meta-compile v1.42 — Compile 1C metadata object from JSON
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
param(
[Parameter(Mandatory)]
@@ -4037,11 +4037,51 @@ if ($objType -in $typesWithModule) {
}
# Special files
# --- Состав плана обмена (ExchangePlan, Ext/Content.xml). Ключ `content`/`Состав`:
# [ "MDRef" (AutoRecord=Deny, дефолт) | "MDRef: autoRecord" (Allow) | {metadata, autoRecord} ].
# Токен-признак autoRecord/АвтоРегистрация (или Allow/Разрешить) → авторегистрация вкл. Метаданные — MDObjectRef verbatim. ---
function Parse-ExchangeContentItem($entry) {
if ($entry -is [string]) {
$s = "$entry"; $ref = $s; $ar = 'Deny'
$ci = $s.LastIndexOf(':')
if ($ci -ge 0) {
$ref = $s.Substring(0, $ci).Trim()
$flag = $s.Substring($ci + 1).Trim()
if ($flag -match '^(autoRecord|АвтоРегистрация|Allow|Разрешить)$') { $ar = 'Allow' }
elseif ($flag -match '^(Deny|Запретить)$') { $ar = 'Deny' }
}
return @{ metadata = $ref.Trim(); autoRecord = $ar }
}
$ref = if ($null -ne $entry.metadata) { "$($entry.metadata)" } elseif ($null -ne $entry.Метаданные) { "$($entry.Метаданные)" } elseif ($null -ne $entry.объект) { "$($entry.объект)" } else { '' }
$rawAr = if ($null -ne $entry.autoRecord) { $entry.autoRecord } elseif ($null -ne $entry.АвтоРегистрация) { $entry.АвтоРегистрация } else { $false }
$ar = 'Deny'
if ($rawAr -is [bool]) { if ($rawAr) { $ar = 'Allow' } }
elseif ("$rawAr" -match '^(Allow|Разрешить|true|autoRecord|АвтоРегистрация)$') { $ar = 'Allow' }
return @{ metadata = $ref.Trim(); autoRecord = $ar }
}
if ($objType -eq "ExchangePlan") {
$contentPath = Join-Path $extDir "Content.xml"
if (-not (Test-Path $contentPath)) {
$xepNs = 'xmlns="http://v8.1c.ru/8.3/xcf/extrnprops" xmlns:xr="http://v8.1c.ru/8.3/xcf/readable" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
$cItems = @()
$cSrc = if ($null -ne $def.content) { $def.content } elseif ($null -ne $def.Состав) { $def.Состав } else { $null }
if ($cSrc) { foreach ($e in @($cSrc)) { $it = Parse-ExchangeContentItem $e; if ($it.metadata) { $cItems += $it } } }
if ($cItems.Count -gt 0) {
Ensure-ExtDir
$contentXml = "<?xml version=`"1.0`" encoding=`"UTF-8`"?>`r`n<ExchangePlanContent xmlns=`"http://v8.1c.ru/8.3/xcf/extrnprops`" xmlns:xr=`"http://v8.1c.ru/8.3/xcf/readable`" version=`"$($script:formatVersion)`"/>`r`n"
$sbC = New-Object System.Text.StringBuilder
[void]$sbC.Append("<?xml version=`"1.0`" encoding=`"UTF-8`"?>`r`n")
[void]$sbC.Append("<ExchangePlanContent $xepNs version=`"$($script:formatVersion)`">`r`n")
foreach ($it in $cItems) {
[void]$sbC.Append("`t<Item>`r`n")
[void]$sbC.Append("`t`t<Metadata>$(Esc-Xml $it.metadata)</Metadata>`r`n")
[void]$sbC.Append("`t`t<AutoRecord>$($it.autoRecord)</AutoRecord>`r`n")
[void]$sbC.Append("`t</Item>`r`n")
}
[void]$sbC.Append("</ExchangePlanContent>`r`n")
[System.IO.File]::WriteAllText($contentPath, $sbC.ToString(), $enc)
$modulesCreated += $contentPath
} elseif (-not (Test-Path $contentPath)) {
Ensure-ExtDir
$contentXml = "<?xml version=`"1.0`" encoding=`"UTF-8`"?>`r`n<ExchangePlanContent $xepNs version=`"$($script:formatVersion)`"/>`r`n"
[System.IO.File]::WriteAllText($contentPath, $contentXml, $enc)
$modulesCreated += $contentPath
}
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# meta-compile v1.41 — Compile 1C metadata object from JSON
# meta-compile v1.42 — Compile 1C metadata object from JSON
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
import argparse
@@ -3810,11 +3810,62 @@ def build_predefined_calc_type_xml(items):
return '\n'.join(out) + '\n'
# Special files
# --- Состав плана обмена (ExchangePlan, Ext/Content.xml). Ключ `content`/`Состав`:
# [ "MDRef" (AutoRecord=Deny, дефолт) | "MDRef: autoRecord" (Allow) | {metadata, autoRecord} ]. ---
def parse_exchange_content_item(entry):
if isinstance(entry, str):
ref, ar = entry, 'Deny'
ci = entry.rfind(':')
if ci >= 0:
ref = entry[:ci].strip()
flag = entry[ci + 1:].strip()
if re.match(r'^(autoRecord|АвтоРегистрация|Allow|Разрешить)$', flag, re.I):
ar = 'Allow'
elif re.match(r'^(Deny|Запретить)$', flag, re.I):
ar = 'Deny'
return {'metadata': ref.strip(), 'autoRecord': ar}
ref = ''
for k in ('metadata', 'Метаданные', 'объект'):
if entry.get(k) is not None:
ref = str(entry[k]); break
raw_ar = entry.get('autoRecord')
if raw_ar is None:
raw_ar = entry.get('АвтоРегистрация')
ar = 'Deny'
if isinstance(raw_ar, bool):
if raw_ar:
ar = 'Allow'
elif raw_ar is not None and re.match(r'^(Allow|Разрешить|true|autoRecord|АвтоРегистрация)$', str(raw_ar), re.I):
ar = 'Allow'
return {'metadata': ref.strip(), 'autoRecord': ar}
if obj_type == 'ExchangePlan':
content_path = os.path.join(ext_dir, 'Content.xml')
if not os.path.isfile(content_path):
xep_ns = 'xmlns="http://v8.1c.ru/8.3/xcf/extrnprops" xmlns:xr="http://v8.1c.ru/8.3/xcf/readable" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
c_src = defn.get('content')
if c_src is None:
c_src = defn.get('Состав')
c_items = []
if c_src:
for e in (c_src if isinstance(c_src, list) else [c_src]):
it = parse_exchange_content_item(e)
if it['metadata']:
c_items.append(it)
if c_items:
ensure_ext_dir()
content_xml = f'<?xml version="1.0" encoding="UTF-8"?>\r\n<ExchangePlanContent xmlns="http://v8.1c.ru/8.3/xcf/extrnprops" xmlns:xr="http://v8.1c.ru/8.3/xcf/readable" version="{format_version}"/>\r\n'
parts = ['<?xml version="1.0" encoding="UTF-8"?>\r\n',
f'<ExchangePlanContent {xep_ns} version="{format_version}">\r\n']
for it in c_items:
parts.append('\t<Item>\r\n')
parts.append(f'\t\t<Metadata>{esc_xml(it["metadata"])}</Metadata>\r\n')
parts.append(f'\t\t<AutoRecord>{it["autoRecord"]}</AutoRecord>\r\n')
parts.append('\t</Item>\r\n')
parts.append('</ExchangePlanContent>\r\n')
write_utf8_bom(content_path, ''.join(parts))
modules_created.append(content_path)
elif not os.path.isfile(content_path):
ensure_ext_dir()
content_xml = f'<?xml version="1.0" encoding="UTF-8"?>\r\n<ExchangePlanContent {xep_ns} version="{format_version}"/>\r\n'
write_utf8_bom(content_path, content_xml)
modules_created.append(content_path)
@@ -1,4 +1,4 @@
# meta-decompile v0.30 — XML объекта метаданных 1С → JSON-черновик формата meta-compile
# meta-decompile v0.31 — XML объекта метаданных 1С → JSON-черновик формата meta-compile
# Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
#
# Поддержаны: Catalog, ExchangePlan, ChartOfCharacteristicTypes, ChartOfAccounts. Инверс meta-compile (omit-on-default: ключ эмитим только
@@ -898,6 +898,27 @@ if (Test-Path -LiteralPath $predefPath) {
if ($rootItems.Count -gt 0) { $dsl['predefined'] = $rootItems }
}
# --- Состав плана обмена (соседний Ext/Content.xml) → DSL content (ExchangePlan).
# Каждый <Item>{<Metadata>MDRef</Metadata><AutoRecord>Deny|Allow</AutoRecord>}.
# Deny (дефолт) → строка "MDRef"; Allow → "MDRef: autoRecord". ---
if ($objType -eq 'ExchangePlan') {
$contentPath = Join-Path (Join-Path (Join-Path $objDir $objName) 'Ext') 'Content.xml'
if (Test-Path -LiteralPath $contentPath) {
$cdoc = New-Object System.Xml.XmlDocument
$cdoc.Load($contentPath)
$contentItems = [System.Collections.ArrayList]@()
foreach ($it in @($cdoc.DocumentElement.SelectNodes("*[local-name()='Item']"))) {
$mdEl = $it.SelectSingleNode("*[local-name()='Metadata']")
if (-not $mdEl -or -not $mdEl.InnerText) { continue }
$ref = $mdEl.InnerText
$arEl = $it.SelectSingleNode("*[local-name()='AutoRecord']")
$ar = if ($arEl) { $arEl.InnerText } else { 'Deny' }
if ($ar -eq 'Allow') { [void]$contentItems.Add("${ref}: autoRecord") } else { [void]$contentItems.Add($ref) }
}
if ($contentItems.Count -gt 0) { $dsl['content'] = $contentItems }
}
}
# === Вывод ===
$json = ConvertTo-CompactJson $dsl 0
if ($OutputPath) {