Settle one failure policy for the trial spellings, and lift the attribute vocabulary above the markdown layer
CI / gate (push) Successful in 5s

This commit is contained in:
2026-08-26 09:19:43 +02:00
parent efc267db2b
commit b196132dae
10 changed files with 93 additions and 70 deletions
+6 -6
View File
@@ -1,11 +1,11 @@
import type { AdfAttributes, AttributeKind } from './adf-document.ts'
import type { AdfAttributes, AttributeKind, AttributeVocabulary } from './adf-document.ts'
import type { JsonValue } from './json-value.ts'
import { failure, type ConvertErrorPath, type Result } from './result.ts'
import { serializeCanonicalJson } from './canonical-json.ts'
export type AttributeFault = { key: string; kind: AttributeKind | undefined }
export type AttributeVocabulary = Readonly<Record<string, AttributeKind>>
export type SpelledPairs = { fault: AttributeFault; pairs?: undefined } | { fault?: undefined; pairs: [string, string][] }
const bareToken = /^[A-Za-z0-9_-]+$/
@@ -18,17 +18,17 @@ export function attributeFailure<T>(type: string, fault: AttributeFault, path: C
return failure('unsupported-node-shape', `the ${type} attribute ${fault.key} holds no ${fault.kind}`, path)
}
export function vocabularyPairs(attrs: AdfAttributes, vocabulary: AttributeVocabulary, slot: string | undefined): AttributeFault | [string, string][] {
export function vocabularyPairs(attrs: AdfAttributes, vocabulary: AttributeVocabulary, slot: string | undefined): SpelledPairs {
const pairs: [string, string][] = []
for (const [key, value] of Object.entries(attrs)) {
if (key === slot) continue
const kind = Object.hasOwn(vocabulary, key) ? vocabulary[key] : undefined
if (kind === undefined) return { key, kind: undefined }
if (kind === undefined) return { fault: { key, kind: undefined } }
const spelled = spellAttributeValue(value, kind)
if (spelled === undefined) return { key, kind }
if (spelled === undefined) return { fault: { key, kind } }
pairs.push([key, spelled])
}
return pairs
return { pairs }
}
export function spellAttributes(pairs: readonly (readonly [string, string])[]): string {