mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 14:45:44 +01:00
Answer architecture round 1: 2 🔴, 6 🟡 (0 misread); one escaping path refusing null characters, block writers returning their pieces, the HTML writer split, shared entry checks, lint between formats
This commit is contained in:
+12
-1
@@ -1,6 +1,7 @@
|
||||
import type { ConvertFault } from '../result.ts'
|
||||
import { failure, faulted, success, type ConvertFault, type Result } from '../result.ts'
|
||||
import { isJsonValue, overNested, type JsonValue } from '../json-value.ts'
|
||||
import { largestNesting } from '../nesting.ts'
|
||||
import { longestOutput, tooLong } from '../length-bound.ts'
|
||||
import { serializeCanonicalJson } from '../canonical-json.ts'
|
||||
|
||||
export type AdfAttributes = { [key: string]: JsonValue }
|
||||
@@ -48,6 +49,16 @@ export function adfDocumentFault(value: unknown): ConvertFault | undefined {
|
||||
return nestingFault(content)
|
||||
}
|
||||
|
||||
// The checks every writer opens with; `undefined` where the document holds no `content` key, which each format spells its own way.
|
||||
export function writableContent(document: AdfDocument): Result<readonly AdfNode[] | undefined> {
|
||||
const fault = adfDocumentFault(document)
|
||||
if (fault !== undefined) return faulted(fault, [])
|
||||
if (document.version !== 1) return failure('unsupported-document-version', `no format this library writes carries ADF version ${document.version}`, [])
|
||||
if (document.content === undefined) return success(undefined)
|
||||
// Every character of text is written at least once, so this much text cannot fit, and none of it is written.
|
||||
return heldTextLength(document.content) > longestOutput ? tooLong() : success(document.content)
|
||||
}
|
||||
|
||||
export function attributeNestingMessage(key: string, type: string): string {
|
||||
return `the ${key} attribute of ${type} nests deeper than the ${largestNesting} levels an attribute carries`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user