/** * vapor-chamber — streaming JSON parser * * Adapted from a dependency-free incremental JSON parser (bytes → state * machine → values), for progressively consuming a `fetch()` response body * (LLM/AI streaming completions, SSE tokens, large exports) without * buffering the whole payload. Framework-agnostic — no Vue imports; pair * with `http.ts`'s `HttpClient` or a bare `fetch()`. * * Reorganized from the source's one large dispatch switch into small * per-state-group handlers (CDCC: functions stay near cyclomatic complexity * 10) — notably, the keyword states (`true`/`false`/`null`) collapse from * ten near-duplicate `S_TRUE_1`/`S_FALSE_2`/… cases into one target-string * index walk. * * @example * const parser = createStreamParser({ onValue: (key, value, path) => console.log(key, value) }); * const response = await fetch('/api/stream'); * await parser.stream(response); * * @example Manual chunk feeding * const parser = createStreamParser({ onValue: (k, v) => items.push(v) }); * parser.write('{"items":['); * parser.write('1,2,3]}'); * parser.end(); */ export type StreamParserPath = ReadonlyArray; export type StreamParserError = { message: string; state: number; depth: number; path: StreamParserPath; }; export type StreamParserCallbacks = { /** Emitted for each complete value (object/array members and top-level scalars). */ onValue?: (key: string, value: unknown, path: StreamParserPath) => void; onObjectStart?: (path: StreamParserPath) => void; onObjectEnd?: (path: StreamParserPath) => void; onArrayStart?: (path: StreamParserPath) => void; onArrayEnd?: (path: StreamParserPath) => void; onError?: (error: StreamParserError) => void; onEnd?: () => void; }; export type StreamParserOptions = { /** Max nesting depth. Default: 256. */ maxDepth?: number; }; export type ParserSnapshot = { state: number; depth: number; path: StreamParserPath; }; export declare class StreamParser { private readonly callbacks; private state; private isKey; private hexIndex; private readonly hexBuf; private readonly parents; private readonly path; private readonly arrayIndices; private readonly strBuf; private numStr; private currentKey; private keywordTarget; private keywordIndex; private readonly maxDepth; constructor(callbacks?: StreamParserCallbacks, options?: StreamParserOptions); /** Feed a string chunk to the parser. */ write(chunk: string): void; /** Signal end of input. Flushes any pending number. */ end(): void; /** Stream from a fetch Response (ReadableStream body). */ stream(response: Response): Promise; /** Current parser position (for pause/resume). */ getState(): ParserSnapshot; /** Reset to initial state. */ reset(): void; private codepoint; private handleValue; private handleAfterValue; private handleKey; private handleAfterKey; private handleString; private handleEscape; private handleHex; /** `true`/`false`/`null` — a single target-string index walk instead of * ten near-duplicate per-letter states. */ private startKeyword; private pendingKeywordValue; private handleKeyword; private handleNumber; private openObject; private openArray; private closeObject; private closeArray; private afterValue; private emitValue; private closeNumber; private err; } /** Factory matching the rest of vapor-chamber's `createX()` naming convention. */ export declare function createStreamParser(callbacks?: StreamParserCallbacks, options?: StreamParserOptions): StreamParser; //# sourceMappingURL=stream-parser.d.ts.map