@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
121 lines (120 loc) • 3.74 kB
TypeScript
/**
* JSON Processing Utility
*
* Handles downloading, validating, and processing JSON files.
* Provides parsed JSON content with validation and metadata extraction.
*
* Features:
* - JSON syntax validation
* - Pretty-printing for valid JSON
* - Metadata extraction (key count, array length)
* - Graceful error handling with detailed messages
*
* @module processors/data/JsonProcessor
*
* @example
* ```typescript
* import { jsonProcessor, isJsonFile, processJson } from "./JsonProcessor.js";
*
* // Check if file is JSON
* if (isJsonFile("application/json", "config.json")) {
* // Process the file
* const result = await processJson(fileInfo);
* if (result.success && result.data) {
* console.log("Parsed JSON:", result.data.parsed);
* console.log("Pretty-printed:", result.data.content);
* }
* }
* ```
*/
import { BaseFileProcessor } from "../base/BaseFileProcessor.js";
import type { FileInfo, ProcessorFileProcessingResult, ProcessOptions, ProcessedJson } from "../../types/index.js";
/**
* JSON file processor.
* Extends BaseFileProcessor with JSON-specific parsing and validation.
*
* @example
* ```typescript
* const processor = new JsonProcessor();
*
* const result = await processor.processFile({
* id: "file-123",
* name: "config.json",
* mimetype: "application/json",
* size: 1024,
* buffer: jsonBuffer,
* });
*
* if (result.success && result.data?.valid) {
* console.log("JSON keys:", result.data.keyCount);
* }
* ```
*/
export declare class JsonProcessor extends BaseFileProcessor<ProcessedJson> {
constructor();
/**
* Validate downloaded JSON is parseable.
*
* @param buffer - Downloaded file content
* @param _fileInfo - Original file information
* @returns null if valid, error message if invalid
*/
protected validateDownloadedFile(buffer: Buffer, _fileInfo: FileInfo): Promise<string | null>;
/**
* Build processed JSON result with parsed content.
*
* @param buffer - Downloaded file content
* @param fileInfo - Original file information
* @returns Processed JSON result
*/
protected buildProcessedResult(buffer: Buffer, fileInfo: FileInfo): ProcessedJson;
}
/** Singleton JSON processor instance */
export declare const jsonProcessor: JsonProcessor;
/**
* Check if a file is a JSON file based on MIME type or extension.
*
* @param mimetype - MIME type of the file
* @param filename - Filename (for extension-based detection)
* @returns true if the file is a JSON file
*
* @example
* ```typescript
* if (isJsonFile("application/json", "config.json")) {
* // Process as JSON
* }
* ```
*/
export declare function isJsonFile(mimetype: string, filename: string): boolean;
/**
* Validate JSON file size against configured limit.
*
* @param sizeBytes - File size in bytes
* @returns true if size is within the limit
*/
export declare function validateJsonSize(sizeBytes: number): boolean;
/**
* Process a single JSON file.
*
* @param fileInfo - File information (with URL or buffer)
* @param options - Optional processing options (auth headers, timeout, retry config)
* @returns Processing result with parsed JSON or error
*
* @example
* ```typescript
* const result = await processJson({
* id: "file-123",
* name: "data.json",
* mimetype: "application/json",
* size: 2048,
* url: "https://example.com/data.json",
* }, {
* authHeaders: { "Authorization": "Bearer token" },
* });
*
* if (result.success && result.data) {
* console.log("Parsed:", result.data.parsed);
* }
* ```
*/
export declare function processJson(fileInfo: FileInfo, options?: ProcessOptions): Promise<ProcessorFileProcessingResult<ProcessedJson>>;