UNPKG

@stacksjs/dtsx

Version:

A modern, fast .d.ts generation tool, powered by Bun.

85 lines (84 loc) 2.36 kB
import type { Declaration, DtsGenerationConfig } from './types'; /** * Create a worker pool with default configuration */ export declare function createWorkerPool(config?: WorkerPoolConfig): WorkerPool; /** * Process files in parallel using a temporary worker pool */ export declare function parallelProcess(files: Array<{ path: string, content: string }>, config?: Partial<DtsGenerationConfig>, poolConfig?: WorkerPoolConfig): Promise<WorkerResult[]>; /** * Batch files into chunks for processing */ export declare function batchFiles<T>(files: T[], batchSize: number): T[][]; /** * Calculate optimal batch size based on file count and CPU cores */ export declare function calculateOptimalBatchSize(fileCount: number, cpuCount?: number): number; /** * Worker pool configuration */ export declare interface WorkerPoolConfig { maxWorkers?: number taskTimeout?: number recycleAfter?: number idleTimeout?: number initialWorkers?: number } /** * Task to be processed by a worker */ export declare interface WorkerTask { id: string type: 'process' | 'extract' | 'transform' | 'process-batch' filePath: string sourceCode?: string files?: Array<{ filePath: string, sourceCode?: string, outPath?: string }> filePaths?: string[] sources?: string[] outPaths?: string[] config: Partial<DtsGenerationConfig> writeOutput?: boolean } /** * Result from a worker task */ export declare interface WorkerBatchResult { filePath: string success: boolean content?: string declarations?: Declaration[] error?: string } export declare interface WorkerResult { id: string success: boolean filePath: string content?: string declarations?: Declaration[] batchResults?: WorkerBatchResult[] error?: string duration: number } /** * Worker statistics */ export declare interface WorkerStats { totalTasks: number completedTasks: number failedTasks: number averageDuration: number activeWorkers: number idleWorkers: number } /** * Worker pool for parallel processing */ export declare class WorkerPool { constructor(config?: WorkerPoolConfig); init(): Promise<void>; submit(task: WorkerTask): Promise<WorkerResult>; processFiles(files: Array<{ path: string, content: string }>, config?: Partial<DtsGenerationConfig>): Promise<WorkerResult[]>; getStats(): WorkerStats; shutdown(): Promise<void>; }