Skip to main content

DocumentParser

@forge/monorepo


@forge/monorepo / backend/src / DocumentParser

Interface: DocumentParser

Defined in: backend/src/documents/index.ts:168

A parser for one family of media types.

mediaTypes is data rather than a canParse(type) method so the pipeline can build its dispatch table once and answer "is this type supported at all" without running anything — which is what makes unsupported-type a decision taken before a byte is read.

Properties

id

readonly id: string

Defined in: backend/src/documents/index.ts:169


mediaTypes

readonly mediaTypes: readonly string[]

Defined in: backend/src/documents/index.ts:170

Methods

parse()

parse(input): Promise<ExtractedDocument | ExtractionFailure>

Defined in: backend/src/documents/index.ts:177

Parse, or return a typed failure.

Returns rather than throws for document problems; a thrown error means the parser itself is broken, and the pipeline records that separately so the two are never confused in a report.

Parameters

input
bytes

Uint8Array

limits

ExtractionLimits

mediaType

string

The normalised media type, without parameters.

Passed in rather than re-derived: a parser serving five types has to know which one it was handed, and a parser that guessed from the bytes would disagree with the dispatch table that chose it.

Returns

Promise<ExtractedDocument | ExtractionFailure>