mirror of
https://git.openapi.site/https://github.com/desirecore/registry.git
synced 2026-12-06 03:39:05 +08:00
merge: 同步 main 并改用已合入的作者契约
main 已在 #16 合入受主仓固定的 4.3 作者 Schema(95afcff…)和校验逻辑,因此保留其字节,不再引入本分支的候选 Schema(29ece0b…)。 - 删除 application-release-contract.mjs:它要求所有条目声明 definitionPath,会拒绝已上架的 definitionSource: manifest 条目;其余检查 main 已覆盖,仅把 definitionPath 规范路径检查移入 application-contract.mjs。 - 保留 webBundles 统计,并在 authored-release 测试样本中声明,与客户端 checkout 校验一致。 - 测试不再写死条目数,并增加 CLI 校验入口与作者 Schema 摘要断言。 - README 合并到现有作者契约章节,移除已过时的候选说明。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
80e0ff0355
38 files changed
+2240
-82
No files matched your search
@@ -4,7 +4,7 @@ import { fileURLToPath } from 'node:url'
|
||||
import Ajv from 'ajv'
|
||||
import { findStaticMetrics } from './catalog/static-metadata.mjs'
|
||||
import { validateApplicationContract } from './catalog/application-contract.mjs'
|
||||
import { validateApplicationReleaseContract } from './catalog/application-release-contract.mjs'
|
||||
import { AUTHORED_ENTRY_SCHEMA_FILENAME, isAuthoredRegistryEntry } from './catalog/entry-schema.mjs'
|
||||
|
||||
const scriptDirectory = dirname(fileURLToPath(import.meta.url))
|
||||
const rootArgumentIndex = process.argv.indexOf('--root')
|
||||
@@ -282,6 +282,7 @@ const validateExternalIntegration = async (entryDirectory, manifest) => {
|
||||
const schemaVersion = (await readText(join(repositoryRoot, 'SCHEMA_VERSION')))?.trim()
|
||||
const rootManifest = await readJson(join(repositoryRoot, 'manifest.json'))
|
||||
const entrySchema = await readJson(join(repositoryRoot, 'schemas', 'registry-entry.schema.json'))
|
||||
const authoredEntrySchema = await readJson(join(repositoryRoot, 'schemas', AUTHORED_ENTRY_SCHEMA_FILENAME))
|
||||
|
||||
if (!schemaVersion || !/^\d+\.\d+\.\d+$/.test(schemaVersion)) {
|
||||
addError('SCHEMA_VERSION: expected a semantic version')
|
||||
@@ -291,16 +292,22 @@ if (rootManifest) {
|
||||
if (rootManifest.dataVersion !== schemaVersion) addError('manifest.json#dataVersion must equal SCHEMA_VERSION')
|
||||
}
|
||||
|
||||
let validateEntry = null
|
||||
if (entrySchema) {
|
||||
const compileEntrySchema = (schema, filename) => {
|
||||
if (schema === null || Array.isArray(schema) || !['object', 'boolean'].includes(typeof schema)) {
|
||||
addError(`schemas/${filename}: Schema root must be an object or boolean`)
|
||||
return null
|
||||
}
|
||||
try {
|
||||
// Draft-07 条件块补充父 Schema 的约束;无需在每个 then/not 再写局部 type。
|
||||
const ajv = new Ajv({ allErrors: true, strict: true, strictTypes: false, strictRequired: false, validateFormats: false })
|
||||
validateEntry = ajv.compile(entrySchema)
|
||||
return ajv.compile(schema)
|
||||
} catch (error) {
|
||||
addError(`schemas/registry-entry.schema.json: unable to compile (${error.message})`)
|
||||
addError(`schemas/${filename}: unable to compile (${error.message})`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
const validateEntry = compileEntrySchema(entrySchema, 'registry-entry.schema.json')
|
||||
const validateAuthoredEntry = compileEntrySchema(authoredEntrySchema, AUTHORED_ENTRY_SCHEMA_FILENAME)
|
||||
|
||||
const manifests = []
|
||||
const seenIds = new Set()
|
||||
@@ -345,11 +352,11 @@ for (const directoryEntry of await readdir(entriesRoot, { withFileTypes: true })
|
||||
}
|
||||
}
|
||||
|
||||
if (validateEntry && !validateEntry(manifest)) {
|
||||
addError(`entries/${directoryEntry.name}/manifest.json: ${formatAjvErrors(validateEntry.errors)}`)
|
||||
const validateManifest = isAuthoredRegistryEntry(manifest) ? validateAuthoredEntry : validateEntry
|
||||
if (validateManifest && !validateManifest(manifest)) {
|
||||
addError(`entries/${directoryEntry.name}/manifest.json: ${formatAjvErrors(validateManifest.errors)}`)
|
||||
}
|
||||
for (const message of validateApplicationContract(manifest)) addError(`entries/${directoryEntry.name}/manifest.json: ${message}`)
|
||||
for (const message of validateApplicationReleaseContract(manifest)) addError(`entries/${directoryEntry.name}/manifest.json: ${message}`)
|
||||
if (manifest.type === 'external-integration') {
|
||||
await validateExternalIntegration(entryDirectory, manifest)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user