/** * Console 运行环境类型:同时兼容 Cloudflare Workers 与本地 Bun 运行时。 * D1Database / R2Bucket 为本项目实际用到的最小接口子集。 */ /** # 成员变量: D1 预处理语句最小接口 **/ export interface D1PreparedStatement { bind(...values: unknown[]): D1PreparedStatement; first>(colName?: string): Promise; all>(): Promise<{ results: T[]; success?: boolean; meta?: unknown }>; run(): Promise<{ success: boolean; meta: { changes?: number; last_row_id?: number } }>; } /** # 成员变量: D1 数据库最小接口 **/ export interface D1Database { prepare(query: string): D1PreparedStatement; batch(statements: D1PreparedStatement[]): Promise; exec(query: string): Promise; } /** # 成员变量: R2 对象最小接口 **/ export interface R2ObjectBody { arrayBuffer(): Promise; text(): Promise; json(): Promise; } /** # 成员变量: R2 桶最小接口 **/ export interface R2Bucket { put( key: string, value: ArrayBuffer | Uint8Array | string | ReadableStream | Blob, options?: { httpMetadata?: Record }, ): Promise; get(key: string): Promise; delete(keys: string | string[]): Promise; head(key: string): Promise<{ key: string; size: number } | null>; } /** # 成员变量: Console env 绑定 **/ export interface Env { /** D1 数据库(本地运行时由 LocalD1 提供) **/ DB: D1Database; /** R2 桶(本地运行时由 LocalR2 提供) **/ R2: R2Bucket; /** Workers 静态资源绑定(本地运行时为空,由 Bun 直接读文件) **/ ASSETS?: { fetch(request: Request): Promise }; /** 会话/加密主密钥;未提供时自动生成并持久化到 settings 表 **/ SESSION_SECRET?: string; /** Console 对外地址(用于 OAuth redirect_uri 与展示) **/ PUBLIC_BASE_URL?: string; /** Cloudflare OAuth 客户端;两个都配置时走真实 OAuth,否则进入本地 sim 模式 **/ CF_OAUTH_CLIENT_ID?: string; CF_OAUTH_CLIENT_SECRET?: string; CF_OAUTH_REDIRECT_URI?: string; /** 本地联调:允许 webhook endpoint 指向私网/localhost("1"),生产严禁开启 **/ WMAILHUB_ALLOW_PRIVATE_WEBHOOKS?: string; } /** # 成员变量: Workers 执行上下文最小接口 **/ export interface WorkersExecutionContext { waitUntil(promise: Promise): void; passThroughOnException(): void; } /** # 成员变量: Workers Cron 触发事件最小接口 **/ export interface ScheduledEvent { cron: string; scheduledTime: number; } /** # 成员变量: Hono context 变量 **/ export interface AppVars { /** 已登录用户 ID(cookie 会话) **/ userId?: string; /** internal 路由中已读出的原始请求体(workerAuth 中间件缓存) **/ rawBody?: Uint8Array; /** internal 路由中通过校验的 worker credential id **/ workerCredentialId?: string; /** internal 路由中 credential 所属的 Console 账号 id **/ workerAccountId?: string; }