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:
IChangeParserConfigRequestBody: Configuration parameters for adjusting a parser's behavior.IChangeParserRequestBody: Encapsulates a parser change request including the parser ID and the new configuration.IDocumentMetaRequestBody: Represents a request to update or set metadata for a document.
Interfaces
IChangeParserConfigRequestBody
Defines the configuration details required to change the parser's settings.
Property | Type | Description |
|---|---|---|
|
| A two-dimensional array representing groups of page numbers. Each inner array is a group of pages. |
|
| The number of tokens per chunk. This typically controls how the document text is split for processing. |
|
| Flag indicating whether layout recognition is enabled. When true, the parser analyzes document layout. |
|
| 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 |
|---|---|---|
|
| Unique identifier of the parser to be changed. |
|
| Unique identifier of the document being parsed. |
|
| 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 |
|---|---|---|
|
| Unique identifier of the document. |
|
| 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
The interfaces are purely type definitions and have no runtime behavior.
pagesinIChangeParserConfigRequestBodybeing a 2D array indicates a design that supports grouping pages, possibly for batch processing or layout recognition.chunk_token_numsuggests chunking textual content into token-sized pieces, likely for NLP or parsing optimization.layout_recognizeas a boolean allows toggling advanced parsing features related to document layout.Metadata is managed as a JSON string to allow flexible yet structured data storage without enforcing a strict TypeScript schema.
Interaction with Other System Components
These request bodies are likely used in API calls to backend services responsible for document parsing and metadata management.
IChangeParserRequestBodywould be submitted when a user or system component wants to update how a document is parsed, including layout analysis and chunking.IDocumentMetaRequestBodyis used when updating or adding metadata, which can be used to enhance search, categorization, or auditing features.The interfaces ensure that components interacting with parsing services have a consistent contract, reducing errors from malformed requests.
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.