feat(platform): complete the Gelios external data loop

This commit is contained in:
Codex
2026-07-20 20:45:05 +03:00
parent def9a24e0d
commit 8a7465cf0e
66 changed files with 5730 additions and 123 deletions
+28
View File
@@ -5,6 +5,7 @@ import { loadCatalog, serviceRoot } from './catalog.mjs'
const ID_RE = /^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9_]*)+$/
const RULE_ID_RE = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/
const ROLE_ID_RE = /^[a-z][a-z0-9_]*$/
const FIELD_ID_RE = /^[a-z][a-z0-9_]*$/
const ALLOWED_RELATION_STATUSES = new Set([
'source-confirmed',
'source-evidenced',
@@ -92,6 +93,7 @@ export async function validateCatalog() {
for (const status of entity.status || []) {
assert(statusVocabulary.has(status), `entity ${entity.id} uses unknown status: ${status}`, errors)
}
validateValueContract(entity.valueContract, entity.id, errors)
}
assertUnique(relations.relations.map((relation) => relation.id), 'relation', errors)
@@ -354,6 +356,32 @@ export async function validateCatalog() {
}
}
function validateValueContract(valueContract, entityId, errors) {
if (valueContract === undefined) return
const label = `entity ${entityId}.valueContract`
assert(valueContract && typeof valueContract === 'object' && !Array.isArray(valueContract), `${label} must be object`, errors)
if (!valueContract || typeof valueContract !== 'object' || Array.isArray(valueContract)) return
assert(FIELD_ID_RE.test(valueContract.field || ''), `${label}.field invalid`, errors)
assert(Array.isArray(valueContract.values) && valueContract.values.length > 0, `${label}.values must be non-empty array`, errors)
const values = []
for (const [index, item] of (valueContract.values || []).entries()) {
const itemLabel = `${label}.values[${index}]`
assert(item && typeof item === 'object' && !Array.isArray(item), `${itemLabel} must be object`, errors)
if (!item || typeof item !== 'object' || Array.isArray(item)) continue
assert(FIELD_ID_RE.test(item.value || ''), `${itemLabel}.value invalid`, errors)
assert(typeof item.label === 'string' && item.label.trim(), `${itemLabel}.label required`, errors)
assert(typeof item.sourceLabel === 'string' && item.sourceLabel.trim(), `${itemLabel}.sourceLabel required`, errors)
values.push(item.value)
}
assert(new Set(values).size === values.length, `${label}.values duplicate value`, errors)
for (const key of ['sourcePaths', 'rules']) {
assert(Array.isArray(valueContract[key]) && valueContract[key].length > 0, `${label}.${key} must be non-empty array`, errors)
for (const item of valueContract[key] || []) {
assert(typeof item === 'string' && item.trim(), `${label}.${key} contains empty item`, errors)
}
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
const result = await validateCatalog()
if (!result.ok) {