import { EventEmitter } from "events"; export type EvalStats = { interrupts: number; evalTimeMs: number; cpuTimeMs: number; }; export type QuickJSMemoryStats = Record; export type QuickJSImportsResult = string | boolean | { src?: string; resolve?: string; }; export type QuickJSOptions = { console?: Console; channelSize?: number; maxEvalMs?: number; maxCpuMs?: number; maxMemoryBytes?: number; maxStackSizeBytes?: number; maxInterrupt?: number; gcThresholdAlloc?: number; gcIntervalMs?: number; globals?: Record; modules?: Record | Map; imports?: ((moduleName: string) => QuickJSImportsResult) | boolean; }; export type EvalOptions = { filename?: string; args?: any[]; maxEvalMs?: number; maxCpuMs?: number; }; export type QuickJSHandleType = "undefined" | "null" | "boolean" | "number" | "string" | "bigint" | "symbol" | "function" | "array" | "object" | "date" | "regexp" | "map" | "set" | "arraybuffer" | "typedarray" | "error" | "promise"; export type QuickJSHandleTypeInfo = { type: QuickJSHandleType; callable: boolean; constructorName?: string; }; export type QuickJSHandleExecOptions = { maxEvalMs?: number; maxCpuMs?: number; }; export type QuickJSHandleAwaitOptions = QuickJSHandleExecOptions & { returnValue?: boolean; untilNonPromise?: boolean; }; export type QuickJSHandleApplyOp = { op: "get"; path?: string; } | { op: "set"; path: string; value: any; } | { op: "call"; path?: string; args?: any[]; } | { op: "has"; path: string; } | { op: "delete"; path: string; } | { op: "getType"; path?: string; } | { op: "toJSON"; path?: string; } | { op: "isCallable"; path?: string; } | { op: "isPromise"; path?: string; }; export type QuickJSHandle = { readonly id: string; readonly rootType: QuickJSHandleTypeInfo; readonly disposed: boolean; get(path?: string, options?: QuickJSHandleExecOptions): Promise; has(path: string, options?: QuickJSHandleExecOptions): Promise; set(path: string, value: any, options?: QuickJSHandleExecOptions): Promise; delete(path: string, options?: QuickJSHandleExecOptions): Promise; keys(path?: string, options?: QuickJSHandleExecOptions): Promise; entries(path?: string, options?: QuickJSHandleExecOptions): Promise; getOwnPropertyDescriptor(path: string, options?: QuickJSHandleExecOptions): Promise; define(path: string, descriptor: PropertyDescriptor, options?: QuickJSHandleExecOptions): Promise; instanceOf(constructorPath: string, options?: QuickJSHandleExecOptions): Promise; isCallable(path?: string, options?: QuickJSHandleExecOptions): Promise; isPromise(path?: string, options?: QuickJSHandleExecOptions): Promise; call(args?: any[], options?: QuickJSHandleExecOptions): Promise; call(path: string, args?: any[], options?: QuickJSHandleExecOptions): Promise; construct(args?: any[], options?: QuickJSHandleExecOptions): Promise; await(options?: QuickJSHandleAwaitOptions): Promise; clone(options?: QuickJSHandleExecOptions): Promise; toJSON(path?: string, options?: QuickJSHandleExecOptions): Promise; apply(ops: QuickJSHandleApplyOp[], options?: QuickJSHandleExecOptions): Promise; getType(path?: string, options?: QuickJSHandleExecOptions): Promise; dispose(options?: QuickJSHandleExecOptions): Promise; [Symbol.asyncDispose](): Promise; _run?: (op: QuickJSHandleApplyOp | Record, options?: QuickJSHandleExecOptions) => Promise; }; export type QuickJSHandleApi = { get(path: string, options?: QuickJSHandleExecOptions): Promise; tryGet(path: string, options?: QuickJSHandleExecOptions): Promise; eval(source: string, options?: QuickJSHandleExecOptions): Promise; }; export type QuickJSGlobalApi = { set(path: string, value: any, options?: QuickJSHandleExecOptions): Promise; get(path: string, options?: QuickJSHandleExecOptions): Promise; has(path: string, options?: QuickJSHandleExecOptions): Promise; delete(path: string, options?: QuickJSHandleExecOptions): Promise; keys(path?: string, options?: QuickJSHandleExecOptions): Promise; entries(path?: string, options?: QuickJSHandleExecOptions): Promise; getOwnPropertyDescriptor(path: string, options?: QuickJSHandleExecOptions): Promise; define(path: string, descriptor: PropertyDescriptor, options?: QuickJSHandleExecOptions): Promise; isCallable(path?: string, options?: QuickJSHandleExecOptions): Promise; isPromise(path?: string, options?: QuickJSHandleExecOptions): Promise; call(path: string, args?: any[], options?: QuickJSHandleExecOptions): Promise; construct(path: string, args?: any[], options?: QuickJSHandleExecOptions): Promise; await(path: string, options?: QuickJSHandleAwaitOptions): Promise; clone(path: string, options?: QuickJSHandleExecOptions): Promise; toJSON(path?: string, options?: QuickJSHandleExecOptions): Promise; apply(path: string, ops: QuickJSHandleApplyOp[], options?: QuickJSHandleExecOptions): Promise; getType(path?: string, options?: QuickJSHandleExecOptions): Promise; instanceOf(path: string, constructorPath: string, options?: QuickJSHandleExecOptions): Promise; }; export type QuickJSModuleEvalOptions = EvalOptions & { moduleName?: string; cjs?: boolean; }; export type QuickJSModuleApi = { import = Record>(specifier: string): Promise; eval = Record>(source: string, options?: QuickJSModuleEvalOptions): Promise; register(moduleName: string, source: string, options?: QuickJSModuleEvalOptions): Promise; clear(moduleName: string): Promise; }; type NativeQuickJSWorker = { on(event: string, cb: (...args: any[]) => void): void; close(): Promise; ref(): void; unref(): void; activeTimerCount?(): number; isClosed(): boolean; eval(code: string, options?: any): Promise<[any, EvalStats]>; evalSync(code: string, options?: any): [any, EvalStats]; setGlobal(key: string, value: any): Promise; postMessage(msg: any): any; postMessages?(msgs: any[]): any; postMessageFrame?(frame: Uint8Array): any; postMessagesFrame?(frames: Uint8Array[] | Uint8Array): any; drainMessages?(): any[]; drainMessagesFrame?(): Uint8Array; getByteCode(code: string): Promise; loadByteCode(bytes: Uint8Array): Promise; gc(): Promise; memory(): Promise; cpu(measureMs: number): Promise; }; export type QuickJSCpuOptions = { measureMs?: number; }; export type QuickJSCpuStats = { cpuTimeMs: number; measureMs: number; usagePercentage: number; }; export type QuickJSWindowOptions = { windowMs?: number; }; export type QuickJSRatesStats = { windowMs: number; evalPerSec: number; handlePerSec: number; globalPerSec: number; modulePerSec: number; messagesPerSec: number; otherPerSec: number; }; export type QuickJSLatencyStats = { windowMs: number; count: number; avgMs: number; maxMs: number; }; export type QuickJSEventLoopLagOptions = { measureMs?: number; }; export type QuickJSEventLoopLagStats = { measureMs: number; lagMs: number; }; export type QuickJSTotalsStats = { ops: number; errors: number; eval: number; handle: number; global: number; module: number; other: number; messagesOut: number; messagesIn: number; bytesOut: number; bytesIn: number; }; export type QuickJSStatsResetOptions = { totals?: boolean; }; export type QuickJSStatsApi = { readonly activeOps: number; readonly lastExecution: EvalStats | null; cpu(options?: QuickJSCpuOptions): Promise; rates(options?: QuickJSWindowOptions): Promise; latency(options?: QuickJSWindowOptions): Promise; eventLoopLag(options?: QuickJSEventLoopLagOptions): Promise; readonly totals: QuickJSTotalsStats; reset(options?: QuickJSStatsResetOptions): void; memory(): Promise; }; export type QuickJSRuntimeEvent = { kind: string; ts: number; opId?: string; hostFile?: string; hostLine?: number; hostColumn?: number; hostCallSite?: string; hostImmediateFile?: string; hostImmediateLine?: number; hostImmediateColumn?: number; hostImmediateCallSite?: string; [key: string]: any; }; export type QuickJSErrorEvent = QuickJSRuntimeEvent & { kind: "error.thrown"; surface: "eval" | "evalSync"; error: any; }; type QuickJSStatsKind = "eval" | "handle" | "global" | "module" | "message" | "other"; type QuickJSOpSample = { ts: number; kind: QuickJSStatsKind; durationMs: number; }; export declare class QuickJSWorker extends EventEmitter { id: string; _lastExecution: EvalStats | null; _closed: boolean; _bridgeReady: boolean; _bridgePromise: Promise | null; _moduleCounter: number; _modules: Map; _activeHandles: Set; _userImports: any; _rawOptions: QuickJSOptions; _native: NativeQuickJSWorker; _activeOpsCount: number; _opSamples: QuickJSOpSample[]; _totalsStats: QuickJSTotalsStats; _closeNotified: boolean; _messageHandlers: Set<(msg: any) => void>; _messageBatchHandlers: Set<(msgs: any[]) => void>; _closeHandlers: Set<() => void>; _runtimeHandlers: Set<(event: QuickJSRuntimeEvent) => void>; _errorHandlers: Set<(event: QuickJSErrorEvent) => void>; _hostCallsiteByOpId: Map>; _nextOpId: number; _messageDrainScheduled: boolean; _loopRefCount: number; _timerLoopHeld: boolean; module: QuickJSModuleApi; handle: QuickJSHandleApi; global: QuickJSGlobalApi; stats: QuickJSStatsApi; constructor(options?: QuickJSOptions); _normalizeModuleSource(value: any): string; _composeImports(): any; _emitRuntime(kind: string, extra?: any): void; _dispatchMessage(msg: any): void; _dispatchMessageBatch(msgs: any[]): void; _scheduleMessageDrain(): void; _dispatchClose(): void; _dispatchRuntime(event: QuickJSRuntimeEvent): void; _dispatchError(surface: "eval" | "evalSync", error: any, opId?: string): void; _startRuntimeOp(kind: "eval.begin" | "evalSync.begin", extra?: Record): string; _captureHostCallsiteMeta(): Partial; on(event: "message", cb: (msg: any) => void): this; on(event: "messageBatch", cb: (msgs: any[]) => void): this; on(event: "close", cb: () => void): this; on(event: "runtime", cb: (event: QuickJSRuntimeEvent) => void): this; on(event: "error", cb: (event: QuickJSErrorEvent) => void): this; off(event: "message", cb?: (msg: any) => void): this; off(event: "messageBatch", cb?: (msgs: any[]) => void): this; off(event: "close", cb?: () => void): this; off(event: "runtime", cb?: (event: QuickJSRuntimeEvent) => void): this; off(event: "error", cb?: (event: QuickJSErrorEvent) => void): this; _ensureBridge(): Promise; _normalizeOptions(options?: EvalOptions | string): EvalOptions | undefined; _pruneOpSamples(now?: number): void; _recordOp(kind: QuickJSStatsKind, startedAt: number): void; _recordTotals(kind: QuickJSStatsKind): void; _retainLoopRef(): void; _releaseLoopRef(): void; _syncTimerLoopRef(): void; _trackAsyncOp(kind: QuickJSStatsKind, run: () => Promise): Promise; _trackSyncOp(kind: QuickJSStatsKind, run: () => T): T; _evalRaw(code: string, options?: EvalOptions | undefined): Promise; _evalSyncRaw(code: string, options?: EvalOptions | undefined): T; _collectWindowSamples(windowMs: number): QuickJSOpSample[]; _statsCpu(options?: QuickJSCpuOptions): Promise; _statsRates(options?: QuickJSWindowOptions): Promise; _statsLatency(options?: QuickJSWindowOptions): Promise; _statsEventLoopLag(options?: QuickJSEventLoopLagOptions): Promise; _statsReset(options?: QuickJSStatsResetOptions): void; eval(code: string, options?: EvalOptions | string | undefined): Promise; evalSync(code: string, options?: EvalOptions | string | undefined): T; evalModule = Record>(code: string, options?: QuickJSModuleEvalOptions | string | undefined): Promise; _globalOp(payload: any, options?: any): Promise; _globalSet(path: string, value: any, options?: any): Promise; setGlobal(key: string, value: any): Promise; postMessage(msg: any): any; postMessages(messages: any[]): any; getByteCode(code: string): Promise; loadByteCode(bytes: Uint8Array): Promise; gc(): Promise; memory(): Promise; close(): Promise; isClosed(): boolean; [Symbol.asyncDispose](): Promise; _moduleRegister(moduleName: string, source: string, options?: any): Promise; _moduleClear(moduleName: string): Promise; _moduleEval = Record>(source: string, options?: any): Promise; _moduleImport = Record>(specifier: string): Promise; _moduleImportRaw = Record>(specifier: string): Promise; _wrapModuleNamespace>(meta: any): T; _runHandleOp(payload: any, options?: any): Promise; _createHandleFromMeta(meta: any, defaultOptions?: any): Promise; _handleGet(path: string, options?: any): Promise; _handleTryGet(path: string, options?: any): Promise; _handleEval(source: string, options?: any): Promise; } export {};