document.ts

Overview

This file defines TypeScript interfaces that describe the shape of request bodies related to parser configuration changes and document metadata updates in a document processing system. It provides type-safe contracts to ensure consistent data structures when interacting with APIs or services that perform operations such as updating parser settings, handling document metadata, or managing page chunking and layout recognition tasks.

The file includes three interfaces:


Interfaces

IChangeParserConfigRequestBody

Defines the configuration details required to change the parser's settings.

Property

Type

Description

pages

number[][]

A two-dimensional array representing groups of page numbers. Each inner array is a group of pages.

chunk_token_num

number

The number of tokens per chunk. This typically controls how the document text is split for processing.

layout_recognize

boolean

Flag indicating whether layout recognition is enabled. When true, the parser analyzes document layout.

task_page_size

number

The size of pages to process per task, influencing batching or workload distribution.

Usage Example

const config: IChangeParserConfigRequestBody = {
  pages: [[1, 2, 3], [4, 5]],
  chunk_token_num: 512,
  layout_recognize: true,
  task_page_size: 2,
};

IChangeParserRequestBody

Represents a request to change parser settings for a specific document.

Property

Type

Description

parser_id

string

Unique identifier of the parser to be changed.

doc_id

string

Unique identifier of the document being parsed.

parser_config

IChangeParserConfigRequestBody

Configuration parameters to apply to the parser.

Usage Example

const changeParserRequest: IChangeParserRequestBody = {
  parser_id: "parser123",
  doc_id: "doc456",
  parser_config: {
    pages: [[1, 2], [3, 4]],
    chunk_token_num: 256,
    layout_recognize: false,
    task_page_size: 1,
  },
};

IDocumentMetaRequestBody

Defines the structure to update or set metadata for a document.

Property

Type

Description

documentId

string

Unique identifier of the document.

meta

string

Metadata represented as a JSON-formatted string.

Usage Example

const metaRequest: IDocumentMetaRequestBody = {
  documentId: "doc789",
  meta: JSON.stringify({ author: "John Doe", created: "2024-05-01" }),
};

Implementation Details


Interaction with Other System Components


Mermaid Diagram

The below class diagram shows the relationship between the three interfaces and their properties:

classDiagram
    class IChangeParserConfigRequestBody {
        +number[][] pages
        +number chunk_token_num
        +boolean layout_recognize
        +number task_page_size
    }

    class IChangeParserRequestBody {
        +string parser_id
        +string doc_id
        +IChangeParserConfigRequestBody parser_config
    }

    class IDocumentMetaRequestBody {
        +string documentId
        +string meta
    }

    IChangeParserRequestBody --> IChangeParserConfigRequestBody : uses

Summary

document.ts provides essential TypeScript interfaces that define the structure of request bodies for changing parser configurations and updating document metadata. These interfaces enable safe and predictable communication between frontend or client components and backend services responsible for document parsing workflows. The file itself is a foundational piece supporting document processing, layout analysis, chunking strategies, and metadata management within the broader system.