// global.d.ts declare global { // WebSocket 相关类型 interface WebSocketConnection { TypeTextMessage: number; TypeBinaryMessage: number; readText(): Promise; read(): Promise<{ type: number; data: Uint8Array; }>; writeText(data: string): Promise; write(mType: number, data: string | Uint8Array): Promise; } function websocket(): WebSocketConnection; // Event 相关类型 interface EventSystem { load(key: string): Promise; put(key: string, value: string): Promise; } // @ts-ignore const event: EventSystem; //元数据 const meta:Meta; interface Meta { // 组织名称 org:string; // 仓库名称 repo:string; // 提交 id commit:string; } // Request 相关类型 interface RequestObject { method: string; url: string; rawPath: string; host: string; remoteAddr: string; remoteIP: string; proto: string; httpVersion: string; path: string; query: Record; headers: Record; get(key: string): string | null; getQuery(key: string): string; getHeader(name: string): string; getHeaderNames(): string[]; getHeaders(): Record; getRawHeaderNames(): string[]; hasHeader(name: string): boolean; readBody(): Uint8Array; protocol: string; } const request: RequestObject; // Response 相关类型 interface CookieOptions { maxAge?: number; expires?: number; path?: string; domain?: string; secure?: boolean; httpOnly?: boolean; sameSite?: "lax" | "strict" | "none"; } interface ResponseObject { setHeader(key: string, value: string): void; getHeader(key: string): string; removeHeader(key: string): void; hasHeader(key: string): boolean; setStatus(statusCode: number): void; statusCode(statusCode: number): void; write(data: string): void; writeHead(statusCode: number, headers?: Record): void; end(data?: string): void; redirect(location: string, statusCode?: number): void; json(data: any): void; setCookie(name: string, value: string, options?: CookieOptions): void; } const response: ResponseObject; // KV 存储相关类型 interface KVListResult { keys: string[]; cursor: string; hasNext: boolean; } interface KVOps { get(key: string): string | null; set(key: string, value: string, ttl?: number): void; delete(key: string): boolean; putIfNotExists(key: string, value: string, ttl?: number): boolean; compareAndSwap(key: string, oldValue: string, newValue: string): boolean; list(limit?: number, cursor?: string): KVListResult; } interface KVSystem { repo(...group: string[]): KVOps; org(...group: string[]): KVOps; } const kv: KVSystem; // localStorage 模拟 interface Storage { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; clear(): void; key(index: number): string | null; } const localStorage: Storage; // Console 相关 (假设通过 require 引入) interface Console { log(...args: any[]): void; warn(...args: any[]): void; error(...args: any[]): void; info(...args: any[]): void; debug(...args: any[]): void; } // @ts-ignore const console: Console; // Fetch API 相关类型 interface FetchResponse { ok: boolean; status: number; statusText: string; headers: Record; text(): Promise; json(): Promise; } interface FetchOptions { method?: string; headers?: Record; body?: string; } function fetch(url: string, options?: FetchOptions): Promise; } export {};