/** * String Extraction Transform * * Extracts large string literals from AST and replaces them with reference IDs. * This prevents large data from entering the JavaScript sandbox. * * @packageDocumentation */ import type * as acorn from 'acorn'; /** * Configuration for string extraction */ export interface StringExtractionConfig { /** * Size threshold in bytes to trigger extraction * Strings larger than this are lifted to the sidecar */ threshold: number; /** * Callback function to store extracted string * Should return the reference ID to replace the string with */ onExtract: (value: string) => string; } /** * Result of string extraction */ export interface StringExtractionResult { /** * Number of strings that were extracted */ extractedCount: number; /** * Total bytes extracted */ extractedBytes: number; /** * Reference IDs that were created */ referenceIds: string[]; } /** * Extract large string literals from an AST * * This function mutates the AST in place, replacing large string literals * with reference ID strings. The original strings are passed to the * `onExtract` callback for storage. * * @param ast - The AST to process (mutated in place) * @param config - Extraction configuration * @returns Information about extracted strings * * @example * ```typescript * const sidecar = new ReferenceSidecar(config); * * const result = extractLargeStrings(ast, { * threshold: 64 * 1024, // 64KB * onExtract: (value) => sidecar.store(value, 'extraction'), * }); * * console.log(`Extracted ${result.extractedCount} strings (${result.extractedBytes} bytes)`); * ``` */ export declare function extractLargeStrings(ast: acorn.Node, config: StringExtractionConfig): StringExtractionResult; /** * Check if a string should be extracted based on size * * @param value - The string to check * @param threshold - Size threshold in bytes * @returns true if the string should be extracted */ export declare function shouldExtract(value: string, threshold: number): boolean;