1- import {
2- assignBooleanField ,
3- assignNumberField ,
4- assignStringField ,
5- assignStringArrayField ,
6- } from "./field-mappers.js" ;
7- import { type PlainRecord , isPlainRecord } from "./types.js" ;
1+ import { assignBooleanField , assignNumberField , assignStringArrayField , assignStringField } from "./field-mappers.js" ;
2+ import { isPlainRecord , type PlainRecord } from "./types.js" ;
83
94/**
105 * Config types - these should match the types from @kreuzberg/node
@@ -79,18 +74,8 @@ export interface ExtractionConfig {
7974function mapTesseractConfig ( raw : PlainRecord ) : TesseractConfig {
8075 const config : TesseractConfig = { } ;
8176 assignNumberField ( config as PlainRecord , raw , "psm" , "psm" ) ;
82- assignBooleanField (
83- config as PlainRecord ,
84- raw ,
85- "enable_table_detection" ,
86- "enableTableDetection" ,
87- ) ;
88- assignStringField (
89- config as PlainRecord ,
90- raw ,
91- "tessedit_char_whitelist" ,
92- "tesseditCharWhitelist" ,
93- ) ;
77+ assignBooleanField ( config as PlainRecord , raw , "enable_table_detection" , "enableTableDetection" ) ;
78+ assignStringField ( config as PlainRecord , raw , "tessedit_char_whitelist" , "tesseditCharWhitelist" ) ;
9479 return config ;
9580}
9681
@@ -128,25 +113,10 @@ function mapChunkingConfig(raw: PlainRecord): ChunkingConfig {
128113 */
129114function mapImageExtractionConfig ( raw : PlainRecord ) : ImageExtractionConfig {
130115 const config : ImageExtractionConfig = { } ;
131- assignBooleanField (
132- config as PlainRecord ,
133- raw ,
134- "extract_images" ,
135- "extractImages" ,
136- ) ;
116+ assignBooleanField ( config as PlainRecord , raw , "extract_images" , "extractImages" ) ;
137117 assignNumberField ( config as PlainRecord , raw , "target_dpi" , "targetDpi" ) ;
138- assignNumberField (
139- config as PlainRecord ,
140- raw ,
141- "max_image_dimension" ,
142- "maxImageDimension" ,
143- ) ;
144- assignBooleanField (
145- config as PlainRecord ,
146- raw ,
147- "auto_adjust_dpi" ,
148- "autoAdjustDpi" ,
149- ) ;
118+ assignNumberField ( config as PlainRecord , raw , "max_image_dimension" , "maxImageDimension" ) ;
119+ assignBooleanField ( config as PlainRecord , raw , "auto_adjust_dpi" , "autoAdjustDpi" ) ;
150120 assignNumberField ( config as PlainRecord , raw , "min_dpi" , "minDpi" ) ;
151121 assignNumberField ( config as PlainRecord , raw , "max_dpi" , "maxDpi" ) ;
152122 return config ;
@@ -157,19 +127,9 @@ function mapImageExtractionConfig(raw: PlainRecord): ImageExtractionConfig {
157127 */
158128function mapPdfConfig ( raw : PlainRecord ) : PdfConfig {
159129 const config : PdfConfig = { } ;
160- assignBooleanField (
161- config as PlainRecord ,
162- raw ,
163- "extract_images" ,
164- "extractImages" ,
165- ) ;
130+ assignBooleanField ( config as PlainRecord , raw , "extract_images" , "extractImages" ) ;
166131 assignStringArrayField ( config as PlainRecord , raw , "passwords" , "passwords" ) ;
167- assignBooleanField (
168- config as PlainRecord ,
169- raw ,
170- "extract_metadata" ,
171- "extractMetadata" ,
172- ) ;
132+ assignBooleanField ( config as PlainRecord , raw , "extract_metadata" , "extractMetadata" ) ;
173133 return config ;
174134}
175135
@@ -179,12 +139,7 @@ function mapPdfConfig(raw: PlainRecord): PdfConfig {
179139function mapTokenReductionConfig ( raw : PlainRecord ) : TokenReductionConfig {
180140 const config : TokenReductionConfig = { } ;
181141 assignStringField ( config as PlainRecord , raw , "mode" , "mode" ) ;
182- assignBooleanField (
183- config as PlainRecord ,
184- raw ,
185- "preserve_important_words" ,
186- "preserveImportantWords" ,
187- ) ;
142+ assignBooleanField ( config as PlainRecord , raw , "preserve_important_words" , "preserveImportantWords" ) ;
188143 return config ;
189144}
190145
@@ -194,18 +149,8 @@ function mapTokenReductionConfig(raw: PlainRecord): TokenReductionConfig {
194149function mapLanguageDetectionConfig ( raw : PlainRecord ) : LanguageDetectionConfig {
195150 const config : LanguageDetectionConfig = { } ;
196151 assignBooleanField ( config as PlainRecord , raw , "enabled" , "enabled" ) ;
197- assignNumberField (
198- config as PlainRecord ,
199- raw ,
200- "min_confidence" ,
201- "minConfidence" ,
202- ) ;
203- assignBooleanField (
204- config as PlainRecord ,
205- raw ,
206- "detect_multiple" ,
207- "detectMultiple" ,
208- ) ;
152+ assignNumberField ( config as PlainRecord , raw , "min_confidence" , "minConfidence" ) ;
153+ assignBooleanField ( config as PlainRecord , raw , "detect_multiple" , "detectMultiple" ) ;
209154 return config ;
210155}
211156
@@ -215,18 +160,8 @@ function mapLanguageDetectionConfig(raw: PlainRecord): LanguageDetectionConfig {
215160function mapPostProcessorConfig ( raw : PlainRecord ) : PostProcessorConfig {
216161 const config : PostProcessorConfig = { } ;
217162 assignBooleanField ( config as PlainRecord , raw , "enabled" , "enabled" ) ;
218- assignStringArrayField (
219- config as PlainRecord ,
220- raw ,
221- "enabled_processors" ,
222- "enabledProcessors" ,
223- ) ;
224- assignStringArrayField (
225- config as PlainRecord ,
226- raw ,
227- "disabled_processors" ,
228- "disabledProcessors" ,
229- ) ;
163+ assignStringArrayField ( config as PlainRecord , raw , "enabled_processors" , "enabledProcessors" ) ;
164+ assignStringArrayField ( config as PlainRecord , raw , "disabled_processors" , "disabledProcessors" ) ;
230165 return config ;
231166}
232167
@@ -244,19 +179,9 @@ export function buildConfig(raw: unknown): ExtractionConfig {
244179 const target = result as PlainRecord ;
245180
246181 assignBooleanField ( target , source , "use_cache" , "useCache" ) ;
247- assignBooleanField (
248- target ,
249- source ,
250- "enable_quality_processing" ,
251- "enableQualityProcessing" ,
252- ) ;
182+ assignBooleanField ( target , source , "enable_quality_processing" , "enableQualityProcessing" ) ;
253183 assignBooleanField ( target , source , "force_ocr" , "forceOcr" ) ;
254- assignNumberField (
255- target ,
256- source ,
257- "max_concurrent_extractions" ,
258- "maxConcurrentExtractions" ,
259- ) ;
184+ assignNumberField ( target , source , "max_concurrent_extractions" , "maxConcurrentExtractions" ) ;
260185
261186 if ( isPlainRecord ( source [ "ocr" ] ) ) {
262187 const mapped = mapOcrConfig ( source [ "ocr" ] ) ;
@@ -282,9 +207,7 @@ export function buildConfig(raw: unknown): ExtractionConfig {
282207 }
283208
284209 if ( isPlainRecord ( source [ "language_detection" ] ) ) {
285- result . languageDetection = mapLanguageDetectionConfig (
286- source [ "language_detection" ] ,
287- ) ;
210+ result . languageDetection = mapLanguageDetectionConfig ( source [ "language_detection" ] ) ;
288211 }
289212
290213 if ( isPlainRecord ( source [ "postprocessor" ] ) ) {
0 commit comments