This is page 4 of 4. Use http://codebase.md/stripe/agent-toolkit?lines=true&page={x} to view the full context. # Directory Structure ``` ├── .github │ ├── ISSUE_TEMPLATE │ │ ├── bug_report.yml │ │ ├── config.yml │ │ └── feature_request.yml │ └── workflows │ ├── main.yml │ ├── npm_agent_toolkit_release.yml │ ├── npm_mcp_release.yml │ └── pypi_release.yml ├── .gitignore ├── .vscode │ ├── extensions.json │ ├── launch.json │ └── settings.json ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── evals │ ├── .env.example │ ├── .gitignore │ ├── braintrust_openai.ts │ ├── cases.ts │ ├── eval.ts │ ├── package.json │ ├── pnpm-lock.yaml │ ├── README.md │ ├── scorer.ts │ └── tsconfig.json ├── gemini-extension.json ├── LICENSE ├── modelcontextprotocol │ ├── .dxtignore │ ├── .gitignore │ ├── .node-version │ ├── .prettierrc │ ├── build-dxt.js │ ├── Dockerfile │ ├── eslint.config.mjs │ ├── jest.config.ts │ ├── manifest.json │ ├── package.json │ ├── pnpm-lock.yaml │ ├── README.md │ ├── src │ │ ├── index.ts │ │ └── test │ │ └── index.test.ts │ ├── stripe_icon.png │ └── tsconfig.json ├── python │ ├── .editorconfig │ ├── .flake8 │ ├── examples │ │ ├── crewai │ │ │ ├── .env.template │ │ │ ├── main.py │ │ │ └── README.md │ │ ├── langchain │ │ │ ├── __init__.py │ │ │ ├── .env.template │ │ │ ├── main.py │ │ │ └── README.md │ │ ├── openai │ │ │ ├── .env.template │ │ │ ├── customer_support │ │ │ │ ├── .env.template │ │ │ │ ├── emailer.py │ │ │ │ ├── env.py │ │ │ │ ├── main.py │ │ │ │ ├── pyproject.toml │ │ │ │ ├── README.md │ │ │ │ ├── repl.py │ │ │ │ └── support_agent.py │ │ │ ├── file_search │ │ │ │ ├── main.py │ │ │ │ └── README.md │ │ │ └── web_search │ │ │ ├── .env.template │ │ │ ├── main.py │ │ │ └── README.md │ │ └── strands │ │ └── main.py │ ├── Makefile │ ├── pyproject.toml │ ├── README.md │ ├── requirements.txt │ ├── stripe_agent_toolkit │ │ ├── __init__.py │ │ ├── api.py │ │ ├── configuration.py │ │ ├── crewai │ │ │ ├── tool.py │ │ │ └── toolkit.py │ │ ├── functions.py │ │ ├── langchain │ │ │ ├── tool.py │ │ │ └── toolkit.py │ │ ├── openai │ │ │ ├── hooks.py │ │ │ ├── tool.py │ │ │ └── toolkit.py │ │ ├── prompts.py │ │ ├── schema.py │ │ ├── strands │ │ │ ├── __init__.py │ │ │ ├── hooks.py │ │ │ ├── tool.py │ │ │ └── toolkit.py │ │ └── tools.py │ └── tests │ ├── __init__.py │ ├── test_configuration.py │ └── test_functions.py ├── README.md ├── SECURITY.md └── typescript ├── .gitignore ├── .prettierrc ├── eslint.config.mjs ├── examples │ ├── ai-sdk │ │ ├── .env.template │ │ ├── index.ts │ │ ├── package.json │ │ ├── README.md │ │ └── tsconfig.json │ ├── cloudflare │ │ ├── .dev.vars.example │ │ ├── .gitignore │ │ ├── biome.json │ │ ├── package.json │ │ ├── README.md │ │ ├── src │ │ │ ├── app.ts │ │ │ ├── imageGenerator.ts │ │ │ ├── index.ts │ │ │ ├── oauth.ts │ │ │ └── utils.ts │ │ ├── tsconfig.json │ │ ├── worker-configuration.d.ts │ │ └── wrangler.jsonc │ ├── langchain │ │ ├── .env.template │ │ ├── index.ts │ │ ├── package.json │ │ ├── README.md │ │ └── tsconfig.json │ └── openai │ ├── .env.template │ ├── index.ts │ ├── package.json │ ├── README.md │ └── tsconfig.json ├── jest.config.ts ├── package.json ├── pnpm-lock.yaml ├── pnpm-workspace.yaml ├── README.md ├── src │ ├── ai-sdk │ │ ├── index.ts │ │ ├── tool.ts │ │ └── toolkit.ts │ ├── cloudflare │ │ ├── index.ts │ │ └── README.md │ ├── langchain │ │ ├── index.ts │ │ ├── tool.ts │ │ └── toolkit.ts │ ├── modelcontextprotocol │ │ ├── index.ts │ │ ├── README.md │ │ ├── register-paid-tool.ts │ │ └── toolkit.ts │ ├── openai │ │ ├── index.ts │ │ └── toolkit.ts │ ├── shared │ │ ├── api.ts │ │ ├── balance │ │ │ └── retrieveBalance.ts │ │ ├── configuration.ts │ │ ├── coupons │ │ │ ├── createCoupon.ts │ │ │ └── listCoupons.ts │ │ ├── customers │ │ │ ├── createCustomer.ts │ │ │ └── listCustomers.ts │ │ ├── disputes │ │ │ ├── listDisputes.ts │ │ │ └── updateDispute.ts │ │ ├── documentation │ │ │ └── searchDocumentation.ts │ │ ├── invoiceItems │ │ │ └── createInvoiceItem.ts │ │ ├── invoices │ │ │ ├── createInvoice.ts │ │ │ ├── finalizeInvoice.ts │ │ │ └── listInvoices.ts │ │ ├── paymentIntents │ │ │ └── listPaymentIntents.ts │ │ ├── paymentLinks │ │ │ └── createPaymentLink.ts │ │ ├── prices │ │ │ ├── createPrice.ts │ │ │ └── listPrices.ts │ │ ├── products │ │ │ ├── createProduct.ts │ │ │ └── listProducts.ts │ │ ├── refunds │ │ │ └── createRefund.ts │ │ ├── subscriptions │ │ │ ├── cancelSubscription.ts │ │ │ ├── listSubscriptions.ts │ │ │ └── updateSubscription.ts │ │ └── tools.ts │ └── test │ ├── modelcontextprotocol │ │ └── register-paid-tool.test.ts │ └── shared │ ├── balance │ │ ├── functions.test.ts │ │ └── parameters.test.ts │ ├── configuration.test.ts │ ├── customers │ │ ├── functions.test.ts │ │ └── parameters.test.ts │ ├── disputes │ │ └── functions.test.ts │ ├── documentation │ │ ├── functions.test.ts │ │ └── parameters.test.ts │ ├── invoiceItems │ │ ├── functions.test.ts │ │ ├── parameters.test.ts │ │ └── prompts.test.ts │ ├── invoices │ │ ├── functions.test.ts │ │ ├── parameters.test.ts │ │ └── prompts.test.ts │ ├── paymentIntents │ │ ├── functions.test.ts │ │ ├── parameters.test.ts │ │ └── prompts.test.ts │ ├── paymentLinks │ │ ├── functions.test.ts │ │ ├── parameters.test.ts │ │ └── prompts.test.ts │ ├── prices │ │ ├── functions.test.ts │ │ └── parameters.test.ts │ ├── products │ │ ├── functions.test.ts │ │ └── parameters.test.ts │ ├── refunds │ │ ├── functions.test.ts │ │ └── parameters.test.ts │ └── subscriptions │ ├── functions.test.ts │ ├── parameters.test.ts │ └── prompts.test.ts ├── tsconfig.json └── tsup.config.ts ``` # Files -------------------------------------------------------------------------------- /typescript/examples/cloudflare/worker-configuration.d.ts: -------------------------------------------------------------------------------- ```typescript 1 | /* eslint-disable */ 2 | // Generated by Wrangler by running `wrangler types` (hash: f288c27142788e231048d40611ac8313) 3 | // Runtime types generated with [email protected] 2025-03-10 nodejs_compat,nodejs_compat_populate_process_env 4 | declare namespace Cloudflare { 5 | interface Env { 6 | OAUTH_KV: KVNamespace; 7 | STRIPE_SECRET_KEY: string; 8 | STRIPE_PRICE_ID_ONE_TIME_PAYMENT: string; 9 | STRIPE_PRICE_ID_SUBSCRIPTION: string; 10 | STRIPE_PRICE_ID_USAGE_BASED_SUBSCRIPTION: string; 11 | MCP_OBJECT: DurableObjectNamespace<import('./src/index').MyMCP>; 12 | } 13 | } 14 | interface Env extends Cloudflare.Env {} 15 | type StringifyValues<EnvType extends Record<string, unknown>> = { 16 | [Binding in keyof EnvType]: EnvType[Binding] extends string 17 | ? EnvType[Binding] 18 | : string; 19 | }; 20 | declare namespace NodeJS { 21 | interface ProcessEnv 22 | extends StringifyValues< 23 | Pick< 24 | Cloudflare.Env, 25 | | 'STRIPE_SECRET_KEY' 26 | | 'STRIPE_PRICE_ID_ONE_TIME_PAYMENT' 27 | | 'STRIPE_PRICE_ID_SUBSCRIPTION' 28 | | 'STRIPE_PRICE_ID_USAGE_BASED_SUBSCRIPTION' 29 | > 30 | > {} 31 | } 32 | 33 | // Begin runtime types 34 | /*! ***************************************************************************** 35 | Copyright (c) Cloudflare. All rights reserved. 36 | Copyright (c) Microsoft Corporation. All rights reserved. 37 | 38 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 39 | this file except in compliance with the License. You may obtain a copy of the 40 | License at http://www.apache.org/licenses/LICENSE-2.0 41 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 42 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 43 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 44 | MERCHANTABLITY OR NON-INFRINGEMENT. 45 | See the Apache Version 2.0 License for specific language governing permissions 46 | and limitations under the License. 47 | ***************************************************************************** */ 48 | /* eslint-disable */ 49 | // noinspection JSUnusedGlobalSymbols 50 | declare var onmessage: never; 51 | /** 52 | * An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API. 53 | * 54 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException) 55 | */ 56 | declare class DOMException extends Error { 57 | constructor(message?: string, name?: string); 58 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/message) */ 59 | readonly message: string; 60 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/name) */ 61 | readonly name: string; 62 | /** 63 | * @deprecated 64 | * 65 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/code) 66 | */ 67 | readonly code: number; 68 | static readonly INDEX_SIZE_ERR: number; 69 | static readonly DOMSTRING_SIZE_ERR: number; 70 | static readonly HIERARCHY_REQUEST_ERR: number; 71 | static readonly WRONG_DOCUMENT_ERR: number; 72 | static readonly INVALID_CHARACTER_ERR: number; 73 | static readonly NO_DATA_ALLOWED_ERR: number; 74 | static readonly NO_MODIFICATION_ALLOWED_ERR: number; 75 | static readonly NOT_FOUND_ERR: number; 76 | static readonly NOT_SUPPORTED_ERR: number; 77 | static readonly INUSE_ATTRIBUTE_ERR: number; 78 | static readonly INVALID_STATE_ERR: number; 79 | static readonly SYNTAX_ERR: number; 80 | static readonly INVALID_MODIFICATION_ERR: number; 81 | static readonly NAMESPACE_ERR: number; 82 | static readonly INVALID_ACCESS_ERR: number; 83 | static readonly VALIDATION_ERR: number; 84 | static readonly TYPE_MISMATCH_ERR: number; 85 | static readonly SECURITY_ERR: number; 86 | static readonly NETWORK_ERR: number; 87 | static readonly ABORT_ERR: number; 88 | static readonly URL_MISMATCH_ERR: number; 89 | static readonly QUOTA_EXCEEDED_ERR: number; 90 | static readonly TIMEOUT_ERR: number; 91 | static readonly INVALID_NODE_TYPE_ERR: number; 92 | static readonly DATA_CLONE_ERR: number; 93 | get stack(): any; 94 | set stack(value: any); 95 | } 96 | type WorkerGlobalScopeEventMap = { 97 | fetch: FetchEvent; 98 | scheduled: ScheduledEvent; 99 | queue: QueueEvent; 100 | unhandledrejection: PromiseRejectionEvent; 101 | rejectionhandled: PromiseRejectionEvent; 102 | }; 103 | declare abstract class WorkerGlobalScope extends EventTarget<WorkerGlobalScopeEventMap> { 104 | EventTarget: typeof EventTarget; 105 | } 106 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console) */ 107 | interface Console { 108 | 'assert'(condition?: boolean, ...data: any[]): void; 109 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/clear_static) */ 110 | clear(): void; 111 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/count_static) */ 112 | count(label?: string): void; 113 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/countreset_static) */ 114 | countReset(label?: string): void; 115 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug_static) */ 116 | debug(...data: any[]): void; 117 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dir_static) */ 118 | dir(item?: any, options?: any): void; 119 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dirxml_static) */ 120 | dirxml(...data: any[]): void; 121 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error_static) */ 122 | error(...data: any[]): void; 123 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/group_static) */ 124 | group(...data: any[]): void; 125 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupcollapsed_static) */ 126 | groupCollapsed(...data: any[]): void; 127 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupend_static) */ 128 | groupEnd(): void; 129 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/info_static) */ 130 | info(...data: any[]): void; 131 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static) */ 132 | log(...data: any[]): void; 133 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/table_static) */ 134 | table(tabularData?: any, properties?: string[]): void; 135 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/time_static) */ 136 | time(label?: string): void; 137 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeend_static) */ 138 | timeEnd(label?: string): void; 139 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timelog_static) */ 140 | timeLog(label?: string, ...data: any[]): void; 141 | timeStamp(label?: string): void; 142 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/trace_static) */ 143 | trace(...data: any[]): void; 144 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/warn_static) */ 145 | warn(...data: any[]): void; 146 | } 147 | declare const console: Console; 148 | type BufferSource = ArrayBufferView | ArrayBuffer; 149 | type TypedArray = 150 | | Int8Array 151 | | Uint8Array 152 | | Uint8ClampedArray 153 | | Int16Array 154 | | Uint16Array 155 | | Int32Array 156 | | Uint32Array 157 | | Float32Array 158 | | Float64Array 159 | | BigInt64Array 160 | | BigUint64Array; 161 | declare namespace WebAssembly { 162 | class CompileError extends Error { 163 | constructor(message?: string); 164 | } 165 | class RuntimeError extends Error { 166 | constructor(message?: string); 167 | } 168 | type ValueType = 169 | | 'anyfunc' 170 | | 'externref' 171 | | 'f32' 172 | | 'f64' 173 | | 'i32' 174 | | 'i64' 175 | | 'v128'; 176 | interface GlobalDescriptor { 177 | value: ValueType; 178 | mutable?: boolean; 179 | } 180 | class Global { 181 | constructor(descriptor: GlobalDescriptor, value?: any); 182 | value: any; 183 | valueOf(): any; 184 | } 185 | type ImportValue = ExportValue | number; 186 | type ModuleImports = Record<string, ImportValue>; 187 | type Imports = Record<string, ModuleImports>; 188 | type ExportValue = Function | Global | Memory | Table; 189 | type Exports = Record<string, ExportValue>; 190 | class Instance { 191 | constructor(module: Module, imports?: Imports); 192 | readonly exports: Exports; 193 | } 194 | interface MemoryDescriptor { 195 | initial: number; 196 | maximum?: number; 197 | shared?: boolean; 198 | } 199 | class Memory { 200 | constructor(descriptor: MemoryDescriptor); 201 | readonly buffer: ArrayBuffer; 202 | grow(delta: number): number; 203 | } 204 | type ImportExportKind = 'function' | 'global' | 'memory' | 'table'; 205 | interface ModuleExportDescriptor { 206 | kind: ImportExportKind; 207 | name: string; 208 | } 209 | interface ModuleImportDescriptor { 210 | kind: ImportExportKind; 211 | module: string; 212 | name: string; 213 | } 214 | abstract class Module { 215 | static customSections(module: Module, sectionName: string): ArrayBuffer[]; 216 | static exports(module: Module): ModuleExportDescriptor[]; 217 | static imports(module: Module): ModuleImportDescriptor[]; 218 | } 219 | type TableKind = 'anyfunc' | 'externref'; 220 | interface TableDescriptor { 221 | element: TableKind; 222 | initial: number; 223 | maximum?: number; 224 | } 225 | class Table { 226 | constructor(descriptor: TableDescriptor, value?: any); 227 | readonly length: number; 228 | get(index: number): any; 229 | grow(delta: number, value?: any): number; 230 | set(index: number, value?: any): void; 231 | } 232 | function instantiate(module: Module, imports?: Imports): Promise<Instance>; 233 | function validate(bytes: BufferSource): boolean; 234 | } 235 | /** 236 | * This ServiceWorker API interface represents the global execution context of a service worker. 237 | * Available only in secure contexts. 238 | * 239 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerGlobalScope) 240 | */ 241 | interface ServiceWorkerGlobalScope extends WorkerGlobalScope { 242 | DOMException: typeof DOMException; 243 | WorkerGlobalScope: typeof WorkerGlobalScope; 244 | btoa(data: string): string; 245 | atob(data: string): string; 246 | setTimeout(callback: (...args: any[]) => void, msDelay?: number): number; 247 | setTimeout<Args extends any[]>( 248 | callback: (...args: Args) => void, 249 | msDelay?: number, 250 | ...args: Args 251 | ): number; 252 | clearTimeout(timeoutId: number | null): void; 253 | setInterval(callback: (...args: any[]) => void, msDelay?: number): number; 254 | setInterval<Args extends any[]>( 255 | callback: (...args: Args) => void, 256 | msDelay?: number, 257 | ...args: Args 258 | ): number; 259 | clearInterval(timeoutId: number | null): void; 260 | queueMicrotask(task: Function): void; 261 | structuredClone<T>(value: T, options?: StructuredSerializeOptions): T; 262 | reportError(error: any): void; 263 | fetch( 264 | input: RequestInfo | URL, 265 | init?: RequestInit<RequestInitCfProperties> 266 | ): Promise<Response>; 267 | self: ServiceWorkerGlobalScope; 268 | crypto: Crypto; 269 | caches: CacheStorage; 270 | scheduler: Scheduler; 271 | performance: Performance; 272 | Cloudflare: Cloudflare; 273 | readonly origin: string; 274 | Event: typeof Event; 275 | ExtendableEvent: typeof ExtendableEvent; 276 | CustomEvent: typeof CustomEvent; 277 | PromiseRejectionEvent: typeof PromiseRejectionEvent; 278 | FetchEvent: typeof FetchEvent; 279 | TailEvent: typeof TailEvent; 280 | TraceEvent: typeof TailEvent; 281 | ScheduledEvent: typeof ScheduledEvent; 282 | MessageEvent: typeof MessageEvent; 283 | CloseEvent: typeof CloseEvent; 284 | ReadableStreamDefaultReader: typeof ReadableStreamDefaultReader; 285 | ReadableStreamBYOBReader: typeof ReadableStreamBYOBReader; 286 | ReadableStream: typeof ReadableStream; 287 | WritableStream: typeof WritableStream; 288 | WritableStreamDefaultWriter: typeof WritableStreamDefaultWriter; 289 | TransformStream: typeof TransformStream; 290 | ByteLengthQueuingStrategy: typeof ByteLengthQueuingStrategy; 291 | CountQueuingStrategy: typeof CountQueuingStrategy; 292 | ErrorEvent: typeof ErrorEvent; 293 | EventSource: typeof EventSource; 294 | ReadableStreamBYOBRequest: typeof ReadableStreamBYOBRequest; 295 | ReadableStreamDefaultController: typeof ReadableStreamDefaultController; 296 | ReadableByteStreamController: typeof ReadableByteStreamController; 297 | WritableStreamDefaultController: typeof WritableStreamDefaultController; 298 | TransformStreamDefaultController: typeof TransformStreamDefaultController; 299 | CompressionStream: typeof CompressionStream; 300 | DecompressionStream: typeof DecompressionStream; 301 | TextEncoderStream: typeof TextEncoderStream; 302 | TextDecoderStream: typeof TextDecoderStream; 303 | Headers: typeof Headers; 304 | Body: typeof Body; 305 | Request: typeof Request; 306 | Response: typeof Response; 307 | WebSocket: typeof WebSocket; 308 | WebSocketPair: typeof WebSocketPair; 309 | WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair; 310 | AbortController: typeof AbortController; 311 | AbortSignal: typeof AbortSignal; 312 | TextDecoder: typeof TextDecoder; 313 | TextEncoder: typeof TextEncoder; 314 | navigator: Navigator; 315 | Navigator: typeof Navigator; 316 | URL: typeof URL; 317 | URLSearchParams: typeof URLSearchParams; 318 | URLPattern: typeof URLPattern; 319 | Blob: typeof Blob; 320 | File: typeof File; 321 | FormData: typeof FormData; 322 | Crypto: typeof Crypto; 323 | SubtleCrypto: typeof SubtleCrypto; 324 | CryptoKey: typeof CryptoKey; 325 | CacheStorage: typeof CacheStorage; 326 | Cache: typeof Cache; 327 | FixedLengthStream: typeof FixedLengthStream; 328 | IdentityTransformStream: typeof IdentityTransformStream; 329 | HTMLRewriter: typeof HTMLRewriter; 330 | } 331 | declare function addEventListener<Type extends keyof WorkerGlobalScopeEventMap>( 332 | type: Type, 333 | handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, 334 | options?: EventTargetAddEventListenerOptions | boolean 335 | ): void; 336 | declare function removeEventListener< 337 | Type extends keyof WorkerGlobalScopeEventMap, 338 | >( 339 | type: Type, 340 | handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, 341 | options?: EventTargetEventListenerOptions | boolean 342 | ): void; 343 | /** 344 | * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. 345 | * 346 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent) 347 | */ 348 | declare function dispatchEvent( 349 | event: WorkerGlobalScopeEventMap[keyof WorkerGlobalScopeEventMap] 350 | ): boolean; 351 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ 352 | declare function btoa(data: string): string; 353 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ 354 | declare function atob(data: string): string; 355 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/setTimeout) */ 356 | declare function setTimeout( 357 | callback: (...args: any[]) => void, 358 | msDelay?: number 359 | ): number; 360 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/setTimeout) */ 361 | declare function setTimeout<Args extends any[]>( 362 | callback: (...args: Args) => void, 363 | msDelay?: number, 364 | ...args: Args 365 | ): number; 366 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/clearTimeout) */ 367 | declare function clearTimeout(timeoutId: number | null): void; 368 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/setInterval) */ 369 | declare function setInterval( 370 | callback: (...args: any[]) => void, 371 | msDelay?: number 372 | ): number; 373 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/setInterval) */ 374 | declare function setInterval<Args extends any[]>( 375 | callback: (...args: Args) => void, 376 | msDelay?: number, 377 | ...args: Args 378 | ): number; 379 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/clearInterval) */ 380 | declare function clearInterval(timeoutId: number | null): void; 381 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/queueMicrotask) */ 382 | declare function queueMicrotask(task: Function): void; 383 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/structuredClone) */ 384 | declare function structuredClone<T>( 385 | value: T, 386 | options?: StructuredSerializeOptions 387 | ): T; 388 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/reportError) */ 389 | declare function reportError(error: any): void; 390 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/fetch) */ 391 | declare function fetch( 392 | input: RequestInfo | URL, 393 | init?: RequestInit<RequestInitCfProperties> 394 | ): Promise<Response>; 395 | declare const self: ServiceWorkerGlobalScope; 396 | /** 397 | * The Web Crypto API provides a set of low-level functions for common cryptographic tasks. 398 | * The Workers runtime implements the full surface of this API, but with some differences in 399 | * the [supported algorithms](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#supported-algorithms) 400 | * compared to those implemented in most browsers. 401 | * 402 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/) 403 | */ 404 | declare const crypto: Crypto; 405 | /** 406 | * The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache. 407 | * 408 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/) 409 | */ 410 | declare const caches: CacheStorage; 411 | declare const scheduler: Scheduler; 412 | /** 413 | * The Workers runtime supports a subset of the Performance API, used to measure timing and performance, 414 | * as well as timing of subrequests and other operations. 415 | * 416 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/) 417 | */ 418 | declare const performance: Performance; 419 | declare const Cloudflare: Cloudflare; 420 | declare const origin: string; 421 | declare const navigator: Navigator; 422 | interface TestController {} 423 | interface ExecutionContext { 424 | waitUntil(promise: Promise<any>): void; 425 | passThroughOnException(): void; 426 | props: any; 427 | } 428 | type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = ( 429 | request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, 430 | env: Env, 431 | ctx: ExecutionContext 432 | ) => Response | Promise<Response>; 433 | type ExportedHandlerTailHandler<Env = unknown> = ( 434 | events: TraceItem[], 435 | env: Env, 436 | ctx: ExecutionContext 437 | ) => void | Promise<void>; 438 | type ExportedHandlerTraceHandler<Env = unknown> = ( 439 | traces: TraceItem[], 440 | env: Env, 441 | ctx: ExecutionContext 442 | ) => void | Promise<void>; 443 | type ExportedHandlerTailStreamHandler<Env = unknown> = ( 444 | event: TailStream.TailEvent, 445 | env: Env, 446 | ctx: ExecutionContext 447 | ) => TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType>; 448 | type ExportedHandlerScheduledHandler<Env = unknown> = ( 449 | controller: ScheduledController, 450 | env: Env, 451 | ctx: ExecutionContext 452 | ) => void | Promise<void>; 453 | type ExportedHandlerQueueHandler<Env = unknown, Message = unknown> = ( 454 | batch: MessageBatch<Message>, 455 | env: Env, 456 | ctx: ExecutionContext 457 | ) => void | Promise<void>; 458 | type ExportedHandlerTestHandler<Env = unknown> = ( 459 | controller: TestController, 460 | env: Env, 461 | ctx: ExecutionContext 462 | ) => void | Promise<void>; 463 | interface ExportedHandler< 464 | Env = unknown, 465 | QueueHandlerMessage = unknown, 466 | CfHostMetadata = unknown, 467 | > { 468 | fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata>; 469 | tail?: ExportedHandlerTailHandler<Env>; 470 | trace?: ExportedHandlerTraceHandler<Env>; 471 | tailStream?: ExportedHandlerTailStreamHandler<Env>; 472 | scheduled?: ExportedHandlerScheduledHandler<Env>; 473 | test?: ExportedHandlerTestHandler<Env>; 474 | email?: EmailExportedHandler<Env>; 475 | queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage>; 476 | } 477 | interface StructuredSerializeOptions { 478 | transfer?: any[]; 479 | } 480 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PromiseRejectionEvent) */ 481 | declare abstract class PromiseRejectionEvent extends Event { 482 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PromiseRejectionEvent/promise) */ 483 | readonly promise: Promise<any>; 484 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PromiseRejectionEvent/reason) */ 485 | readonly reason: any; 486 | } 487 | declare abstract class Navigator { 488 | sendBeacon( 489 | url: string, 490 | body?: 491 | | ReadableStream 492 | | string 493 | | (ArrayBuffer | ArrayBufferView) 494 | | Blob 495 | | FormData 496 | | URLSearchParams 497 | | URLSearchParams 498 | ): boolean; 499 | readonly userAgent: string; 500 | readonly hardwareConcurrency: number; 501 | } 502 | /** 503 | * The Workers runtime supports a subset of the Performance API, used to measure timing and performance, 504 | * as well as timing of subrequests and other operations. 505 | * 506 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/) 507 | */ 508 | interface Performance { 509 | /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */ 510 | readonly timeOrigin: number; 511 | /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */ 512 | now(): number; 513 | } 514 | interface AlarmInvocationInfo { 515 | readonly isRetry: boolean; 516 | readonly retryCount: number; 517 | } 518 | interface Cloudflare { 519 | readonly compatibilityFlags: Record<string, boolean>; 520 | } 521 | interface DurableObject { 522 | fetch(request: Request): Response | Promise<Response>; 523 | alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>; 524 | webSocketMessage?( 525 | ws: WebSocket, 526 | message: string | ArrayBuffer 527 | ): void | Promise<void>; 528 | webSocketClose?( 529 | ws: WebSocket, 530 | code: number, 531 | reason: string, 532 | wasClean: boolean 533 | ): void | Promise<void>; 534 | webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>; 535 | } 536 | type DurableObjectStub< 537 | T extends Rpc.DurableObjectBranded | undefined = undefined, 538 | > = Fetcher< 539 | T, 540 | 'alarm' | 'webSocketMessage' | 'webSocketClose' | 'webSocketError' 541 | > & { 542 | readonly id: DurableObjectId; 543 | readonly name?: string; 544 | }; 545 | interface DurableObjectId { 546 | toString(): string; 547 | equals(other: DurableObjectId): boolean; 548 | readonly name?: string; 549 | } 550 | interface DurableObjectNamespace< 551 | T extends Rpc.DurableObjectBranded | undefined = undefined, 552 | > { 553 | newUniqueId( 554 | options?: DurableObjectNamespaceNewUniqueIdOptions 555 | ): DurableObjectId; 556 | idFromName(name: string): DurableObjectId; 557 | idFromString(id: string): DurableObjectId; 558 | get( 559 | id: DurableObjectId, 560 | options?: DurableObjectNamespaceGetDurableObjectOptions 561 | ): DurableObjectStub<T>; 562 | jurisdiction( 563 | jurisdiction: DurableObjectJurisdiction 564 | ): DurableObjectNamespace<T>; 565 | } 566 | type DurableObjectJurisdiction = 'eu' | 'fedramp'; 567 | interface DurableObjectNamespaceNewUniqueIdOptions { 568 | jurisdiction?: DurableObjectJurisdiction; 569 | } 570 | type DurableObjectLocationHint = 571 | | 'wnam' 572 | | 'enam' 573 | | 'sam' 574 | | 'weur' 575 | | 'eeur' 576 | | 'apac' 577 | | 'oc' 578 | | 'afr' 579 | | 'me'; 580 | interface DurableObjectNamespaceGetDurableObjectOptions { 581 | locationHint?: DurableObjectLocationHint; 582 | } 583 | interface DurableObjectState { 584 | waitUntil(promise: Promise<any>): void; 585 | readonly id: DurableObjectId; 586 | readonly storage: DurableObjectStorage; 587 | container?: Container; 588 | blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>; 589 | acceptWebSocket(ws: WebSocket, tags?: string[]): void; 590 | getWebSockets(tag?: string): WebSocket[]; 591 | setWebSocketAutoResponse(maybeReqResp?: WebSocketRequestResponsePair): void; 592 | getWebSocketAutoResponse(): WebSocketRequestResponsePair | null; 593 | getWebSocketAutoResponseTimestamp(ws: WebSocket): Date | null; 594 | setHibernatableWebSocketEventTimeout(timeoutMs?: number): void; 595 | getHibernatableWebSocketEventTimeout(): number | null; 596 | getTags(ws: WebSocket): string[]; 597 | abort(reason?: string): void; 598 | } 599 | interface DurableObjectTransaction { 600 | get<T = unknown>( 601 | key: string, 602 | options?: DurableObjectGetOptions 603 | ): Promise<T | undefined>; 604 | get<T = unknown>( 605 | keys: string[], 606 | options?: DurableObjectGetOptions 607 | ): Promise<Map<string, T>>; 608 | list<T = unknown>( 609 | options?: DurableObjectListOptions 610 | ): Promise<Map<string, T>>; 611 | put<T>( 612 | key: string, 613 | value: T, 614 | options?: DurableObjectPutOptions 615 | ): Promise<void>; 616 | put<T>( 617 | entries: Record<string, T>, 618 | options?: DurableObjectPutOptions 619 | ): Promise<void>; 620 | delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>; 621 | delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>; 622 | rollback(): void; 623 | getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>; 624 | setAlarm( 625 | scheduledTime: number | Date, 626 | options?: DurableObjectSetAlarmOptions 627 | ): Promise<void>; 628 | deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>; 629 | } 630 | interface DurableObjectStorage { 631 | get<T = unknown>( 632 | key: string, 633 | options?: DurableObjectGetOptions 634 | ): Promise<T | undefined>; 635 | get<T = unknown>( 636 | keys: string[], 637 | options?: DurableObjectGetOptions 638 | ): Promise<Map<string, T>>; 639 | list<T = unknown>( 640 | options?: DurableObjectListOptions 641 | ): Promise<Map<string, T>>; 642 | put<T>( 643 | key: string, 644 | value: T, 645 | options?: DurableObjectPutOptions 646 | ): Promise<void>; 647 | put<T>( 648 | entries: Record<string, T>, 649 | options?: DurableObjectPutOptions 650 | ): Promise<void>; 651 | delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>; 652 | delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>; 653 | deleteAll(options?: DurableObjectPutOptions): Promise<void>; 654 | transaction<T>( 655 | closure: (txn: DurableObjectTransaction) => Promise<T> 656 | ): Promise<T>; 657 | getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>; 658 | setAlarm( 659 | scheduledTime: number | Date, 660 | options?: DurableObjectSetAlarmOptions 661 | ): Promise<void>; 662 | deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>; 663 | sync(): Promise<void>; 664 | sql: SqlStorage; 665 | transactionSync<T>(closure: () => T): T; 666 | getCurrentBookmark(): Promise<string>; 667 | getBookmarkForTime(timestamp: number | Date): Promise<string>; 668 | onNextSessionRestoreBookmark(bookmark: string): Promise<string>; 669 | } 670 | interface DurableObjectListOptions { 671 | start?: string; 672 | startAfter?: string; 673 | end?: string; 674 | prefix?: string; 675 | reverse?: boolean; 676 | limit?: number; 677 | allowConcurrency?: boolean; 678 | noCache?: boolean; 679 | } 680 | interface DurableObjectGetOptions { 681 | allowConcurrency?: boolean; 682 | noCache?: boolean; 683 | } 684 | interface DurableObjectGetAlarmOptions { 685 | allowConcurrency?: boolean; 686 | } 687 | interface DurableObjectPutOptions { 688 | allowConcurrency?: boolean; 689 | allowUnconfirmed?: boolean; 690 | noCache?: boolean; 691 | } 692 | interface DurableObjectSetAlarmOptions { 693 | allowConcurrency?: boolean; 694 | allowUnconfirmed?: boolean; 695 | } 696 | declare class WebSocketRequestResponsePair { 697 | constructor(request: string, response: string); 698 | get request(): string; 699 | get response(): string; 700 | } 701 | interface AnalyticsEngineDataset { 702 | writeDataPoint(event?: AnalyticsEngineDataPoint): void; 703 | } 704 | interface AnalyticsEngineDataPoint { 705 | indexes?: ((ArrayBuffer | string) | null)[]; 706 | doubles?: number[]; 707 | blobs?: ((ArrayBuffer | string) | null)[]; 708 | } 709 | /** 710 | * An event which takes place in the DOM. 711 | * 712 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) 713 | */ 714 | declare class Event { 715 | constructor(type: string, init?: EventInit); 716 | /** 717 | * Returns the type of event, e.g. "click", "hashchange", or "submit". 718 | * 719 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type) 720 | */ 721 | get type(): string; 722 | /** 723 | * Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE. 724 | * 725 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase) 726 | */ 727 | get eventPhase(): number; 728 | /** 729 | * Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise. 730 | * 731 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed) 732 | */ 733 | get composed(): boolean; 734 | /** 735 | * Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise. 736 | * 737 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles) 738 | */ 739 | get bubbles(): boolean; 740 | /** 741 | * Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method. 742 | * 743 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable) 744 | */ 745 | get cancelable(): boolean; 746 | /** 747 | * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. 748 | * 749 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented) 750 | */ 751 | get defaultPrevented(): boolean; 752 | /** 753 | * @deprecated 754 | * 755 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue) 756 | */ 757 | get returnValue(): boolean; 758 | /** 759 | * Returns the object whose event listener's callback is currently being invoked. 760 | * 761 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) 762 | */ 763 | get currentTarget(): EventTarget | undefined; 764 | /** 765 | * Returns the object to which event is dispatched (its target). 766 | * 767 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) 768 | */ 769 | get target(): EventTarget | undefined; 770 | /** 771 | * @deprecated 772 | * 773 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement) 774 | */ 775 | get srcElement(): EventTarget | undefined; 776 | /** 777 | * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. 778 | * 779 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp) 780 | */ 781 | get timeStamp(): number; 782 | /** 783 | * Returns true if event was dispatched by the user agent, and false otherwise. 784 | * 785 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted) 786 | */ 787 | get isTrusted(): boolean; 788 | /** 789 | * @deprecated 790 | * 791 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble) 792 | */ 793 | get cancelBubble(): boolean; 794 | /** 795 | * @deprecated 796 | * 797 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble) 798 | */ 799 | set cancelBubble(value: boolean); 800 | /** 801 | * Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects. 802 | * 803 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation) 804 | */ 805 | stopImmediatePropagation(): void; 806 | /** 807 | * If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled. 808 | * 809 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault) 810 | */ 811 | preventDefault(): void; 812 | /** 813 | * When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object. 814 | * 815 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation) 816 | */ 817 | stopPropagation(): void; 818 | /** 819 | * Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget. 820 | * 821 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath) 822 | */ 823 | composedPath(): EventTarget[]; 824 | static readonly NONE: number; 825 | static readonly CAPTURING_PHASE: number; 826 | static readonly AT_TARGET: number; 827 | static readonly BUBBLING_PHASE: number; 828 | } 829 | interface EventInit { 830 | bubbles?: boolean; 831 | cancelable?: boolean; 832 | composed?: boolean; 833 | } 834 | type EventListener<EventType extends Event = Event> = ( 835 | event: EventType 836 | ) => void; 837 | interface EventListenerObject<EventType extends Event = Event> { 838 | handleEvent(event: EventType): void; 839 | } 840 | type EventListenerOrEventListenerObject<EventType extends Event = Event> = 841 | | EventListener<EventType> 842 | | EventListenerObject<EventType>; 843 | /** 844 | * EventTarget is a DOM interface implemented by objects that can receive events and may have listeners for them. 845 | * 846 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget) 847 | */ 848 | declare class EventTarget< 849 | EventMap extends Record<string, Event> = Record<string, Event>, 850 | > { 851 | constructor(); 852 | /** 853 | * Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched. 854 | * 855 | * The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture. 856 | * 857 | * When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET. 858 | * 859 | * When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners. 860 | * 861 | * When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed. 862 | * 863 | * If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted. 864 | * 865 | * The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture. 866 | * 867 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) 868 | */ 869 | addEventListener<Type extends keyof EventMap>( 870 | type: Type, 871 | handler: EventListenerOrEventListenerObject<EventMap[Type]>, 872 | options?: EventTargetAddEventListenerOptions | boolean 873 | ): void; 874 | /** 875 | * Removes the event listener in target's event listener list with the same type, callback, and options. 876 | * 877 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) 878 | */ 879 | removeEventListener<Type extends keyof EventMap>( 880 | type: Type, 881 | handler: EventListenerOrEventListenerObject<EventMap[Type]>, 882 | options?: EventTargetEventListenerOptions | boolean 883 | ): void; 884 | /** 885 | * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. 886 | * 887 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent) 888 | */ 889 | dispatchEvent(event: EventMap[keyof EventMap]): boolean; 890 | } 891 | interface EventTargetEventListenerOptions { 892 | capture?: boolean; 893 | } 894 | interface EventTargetAddEventListenerOptions { 895 | capture?: boolean; 896 | passive?: boolean; 897 | once?: boolean; 898 | signal?: AbortSignal; 899 | } 900 | interface EventTargetHandlerObject { 901 | handleEvent: (event: Event) => any | undefined; 902 | } 903 | /** 904 | * A controller object that allows you to abort one or more DOM requests as and when desired. 905 | * 906 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController) 907 | */ 908 | declare class AbortController { 909 | constructor(); 910 | /** 911 | * Returns the AbortSignal object associated with this object. 912 | * 913 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/signal) 914 | */ 915 | get signal(): AbortSignal; 916 | /** 917 | * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted. 918 | * 919 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort) 920 | */ 921 | abort(reason?: any): void; 922 | } 923 | /** 924 | * A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. 925 | * 926 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal) 927 | */ 928 | declare abstract class AbortSignal extends EventTarget { 929 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_static) */ 930 | static abort(reason?: any): AbortSignal; 931 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/timeout_static) */ 932 | static timeout(delay: number): AbortSignal; 933 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/any_static) */ 934 | static any(signals: AbortSignal[]): AbortSignal; 935 | /** 936 | * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise. 937 | * 938 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/aborted) 939 | */ 940 | get aborted(): boolean; 941 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/reason) */ 942 | get reason(): any; 943 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_event) */ 944 | get onabort(): any | null; 945 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_event) */ 946 | set onabort(value: any | null); 947 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/throwIfAborted) */ 948 | throwIfAborted(): void; 949 | } 950 | interface Scheduler { 951 | wait(delay: number, maybeOptions?: SchedulerWaitOptions): Promise<void>; 952 | } 953 | interface SchedulerWaitOptions { 954 | signal?: AbortSignal; 955 | } 956 | /** 957 | * Extends the lifetime of the install and activate events dispatched on the global scope as part of the service worker lifecycle. This ensures that any functional events (like FetchEvent) are not dispatched until it upgrades database schemas and deletes the outdated cache entries. 958 | * 959 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent) 960 | */ 961 | declare abstract class ExtendableEvent extends Event { 962 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil) */ 963 | waitUntil(promise: Promise<any>): void; 964 | } 965 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent) */ 966 | declare class CustomEvent<T = any> extends Event { 967 | constructor(type: string, init?: CustomEventCustomEventInit); 968 | /** 969 | * Returns any custom data event was created with. Typically used for synthetic events. 970 | * 971 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail) 972 | */ 973 | get detail(): T; 974 | } 975 | interface CustomEventCustomEventInit { 976 | bubbles?: boolean; 977 | cancelable?: boolean; 978 | composed?: boolean; 979 | detail?: any; 980 | } 981 | /** 982 | * A file-like object of immutable, raw data. Blobs represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system. 983 | * 984 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob) 985 | */ 986 | declare class Blob { 987 | constructor( 988 | type?: ((ArrayBuffer | ArrayBufferView) | string | Blob)[], 989 | options?: BlobOptions 990 | ); 991 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */ 992 | get size(): number; 993 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */ 994 | get type(): string; 995 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */ 996 | slice(start?: number, end?: number, type?: string): Blob; 997 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */ 998 | arrayBuffer(): Promise<ArrayBuffer>; 999 | bytes(): Promise<Uint8Array>; 1000 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */ 1001 | text(): Promise<string>; 1002 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */ 1003 | stream(): ReadableStream; 1004 | } 1005 | interface BlobOptions { 1006 | type?: string; 1007 | } 1008 | /** 1009 | * Provides information about files and allows JavaScript in a web page to access their content. 1010 | * 1011 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/File) 1012 | */ 1013 | declare class File extends Blob { 1014 | constructor( 1015 | bits: ((ArrayBuffer | ArrayBufferView) | string | Blob)[] | undefined, 1016 | name: string, 1017 | options?: FileOptions 1018 | ); 1019 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */ 1020 | get name(): string; 1021 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */ 1022 | get lastModified(): number; 1023 | } 1024 | interface FileOptions { 1025 | type?: string; 1026 | lastModified?: number; 1027 | } 1028 | /** 1029 | * The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache. 1030 | * 1031 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/) 1032 | */ 1033 | declare abstract class CacheStorage { 1034 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CacheStorage/open) */ 1035 | open(cacheName: string): Promise<Cache>; 1036 | readonly default: Cache; 1037 | } 1038 | /** 1039 | * The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache. 1040 | * 1041 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/) 1042 | */ 1043 | declare abstract class Cache { 1044 | /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#delete) */ 1045 | delete( 1046 | request: RequestInfo | URL, 1047 | options?: CacheQueryOptions 1048 | ): Promise<boolean>; 1049 | /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#match) */ 1050 | match( 1051 | request: RequestInfo | URL, 1052 | options?: CacheQueryOptions 1053 | ): Promise<Response | undefined>; 1054 | /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#put) */ 1055 | put(request: RequestInfo | URL, response: Response): Promise<void>; 1056 | } 1057 | interface CacheQueryOptions { 1058 | ignoreMethod?: boolean; 1059 | } 1060 | /** 1061 | * The Web Crypto API provides a set of low-level functions for common cryptographic tasks. 1062 | * The Workers runtime implements the full surface of this API, but with some differences in 1063 | * the [supported algorithms](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#supported-algorithms) 1064 | * compared to those implemented in most browsers. 1065 | * 1066 | * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/) 1067 | */ 1068 | declare abstract class Crypto { 1069 | /** 1070 | * Available only in secure contexts. 1071 | * 1072 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/subtle) 1073 | */ 1074 | get subtle(): SubtleCrypto; 1075 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/getRandomValues) */ 1076 | getRandomValues< 1077 | T extends 1078 | | Int8Array 1079 | | Uint8Array 1080 | | Int16Array 1081 | | Uint16Array 1082 | | Int32Array 1083 | | Uint32Array 1084 | | BigInt64Array 1085 | | BigUint64Array, 1086 | >(buffer: T): T; 1087 | /** 1088 | * Available only in secure contexts. 1089 | * 1090 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID) 1091 | */ 1092 | randomUUID(): string; 1093 | DigestStream: typeof DigestStream; 1094 | } 1095 | /** 1096 | * This Web Crypto API interface provides a number of low-level cryptographic functions. It is accessed via the Crypto.subtle properties available in a window context (via Window.crypto). 1097 | * Available only in secure contexts. 1098 | * 1099 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto) 1100 | */ 1101 | declare abstract class SubtleCrypto { 1102 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/encrypt) */ 1103 | encrypt( 1104 | algorithm: string | SubtleCryptoEncryptAlgorithm, 1105 | key: CryptoKey, 1106 | plainText: ArrayBuffer | ArrayBufferView 1107 | ): Promise<ArrayBuffer>; 1108 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/decrypt) */ 1109 | decrypt( 1110 | algorithm: string | SubtleCryptoEncryptAlgorithm, 1111 | key: CryptoKey, 1112 | cipherText: ArrayBuffer | ArrayBufferView 1113 | ): Promise<ArrayBuffer>; 1114 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/sign) */ 1115 | sign( 1116 | algorithm: string | SubtleCryptoSignAlgorithm, 1117 | key: CryptoKey, 1118 | data: ArrayBuffer | ArrayBufferView 1119 | ): Promise<ArrayBuffer>; 1120 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/verify) */ 1121 | verify( 1122 | algorithm: string | SubtleCryptoSignAlgorithm, 1123 | key: CryptoKey, 1124 | signature: ArrayBuffer | ArrayBufferView, 1125 | data: ArrayBuffer | ArrayBufferView 1126 | ): Promise<boolean>; 1127 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/digest) */ 1128 | digest( 1129 | algorithm: string | SubtleCryptoHashAlgorithm, 1130 | data: ArrayBuffer | ArrayBufferView 1131 | ): Promise<ArrayBuffer>; 1132 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/generateKey) */ 1133 | generateKey( 1134 | algorithm: string | SubtleCryptoGenerateKeyAlgorithm, 1135 | extractable: boolean, 1136 | keyUsages: string[] 1137 | ): Promise<CryptoKey | CryptoKeyPair>; 1138 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/deriveKey) */ 1139 | deriveKey( 1140 | algorithm: string | SubtleCryptoDeriveKeyAlgorithm, 1141 | baseKey: CryptoKey, 1142 | derivedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, 1143 | extractable: boolean, 1144 | keyUsages: string[] 1145 | ): Promise<CryptoKey>; 1146 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/deriveBits) */ 1147 | deriveBits( 1148 | algorithm: string | SubtleCryptoDeriveKeyAlgorithm, 1149 | baseKey: CryptoKey, 1150 | length?: number | null 1151 | ): Promise<ArrayBuffer>; 1152 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/importKey) */ 1153 | importKey( 1154 | format: string, 1155 | keyData: (ArrayBuffer | ArrayBufferView) | JsonWebKey, 1156 | algorithm: string | SubtleCryptoImportKeyAlgorithm, 1157 | extractable: boolean, 1158 | keyUsages: string[] 1159 | ): Promise<CryptoKey>; 1160 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/exportKey) */ 1161 | exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>; 1162 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/wrapKey) */ 1163 | wrapKey( 1164 | format: string, 1165 | key: CryptoKey, 1166 | wrappingKey: CryptoKey, 1167 | wrapAlgorithm: string | SubtleCryptoEncryptAlgorithm 1168 | ): Promise<ArrayBuffer>; 1169 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/unwrapKey) */ 1170 | unwrapKey( 1171 | format: string, 1172 | wrappedKey: ArrayBuffer | ArrayBufferView, 1173 | unwrappingKey: CryptoKey, 1174 | unwrapAlgorithm: string | SubtleCryptoEncryptAlgorithm, 1175 | unwrappedKeyAlgorithm: string | SubtleCryptoImportKeyAlgorithm, 1176 | extractable: boolean, 1177 | keyUsages: string[] 1178 | ): Promise<CryptoKey>; 1179 | timingSafeEqual( 1180 | a: ArrayBuffer | ArrayBufferView, 1181 | b: ArrayBuffer | ArrayBufferView 1182 | ): boolean; 1183 | } 1184 | /** 1185 | * The CryptoKey dictionary of the Web Crypto API represents a cryptographic key. 1186 | * Available only in secure contexts. 1187 | * 1188 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey) 1189 | */ 1190 | declare abstract class CryptoKey { 1191 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/type) */ 1192 | readonly type: string; 1193 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/extractable) */ 1194 | readonly extractable: boolean; 1195 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/algorithm) */ 1196 | readonly algorithm: 1197 | | CryptoKeyKeyAlgorithm 1198 | | CryptoKeyAesKeyAlgorithm 1199 | | CryptoKeyHmacKeyAlgorithm 1200 | | CryptoKeyRsaKeyAlgorithm 1201 | | CryptoKeyEllipticKeyAlgorithm 1202 | | CryptoKeyArbitraryKeyAlgorithm; 1203 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CryptoKey/usages) */ 1204 | readonly usages: string[]; 1205 | } 1206 | interface CryptoKeyPair { 1207 | publicKey: CryptoKey; 1208 | privateKey: CryptoKey; 1209 | } 1210 | interface JsonWebKey { 1211 | kty: string; 1212 | use?: string; 1213 | key_ops?: string[]; 1214 | alg?: string; 1215 | ext?: boolean; 1216 | crv?: string; 1217 | x?: string; 1218 | y?: string; 1219 | d?: string; 1220 | n?: string; 1221 | e?: string; 1222 | p?: string; 1223 | q?: string; 1224 | dp?: string; 1225 | dq?: string; 1226 | qi?: string; 1227 | oth?: RsaOtherPrimesInfo[]; 1228 | k?: string; 1229 | } 1230 | interface RsaOtherPrimesInfo { 1231 | r?: string; 1232 | d?: string; 1233 | t?: string; 1234 | } 1235 | interface SubtleCryptoDeriveKeyAlgorithm { 1236 | name: string; 1237 | salt?: ArrayBuffer | ArrayBufferView; 1238 | iterations?: number; 1239 | hash?: string | SubtleCryptoHashAlgorithm; 1240 | $public?: CryptoKey; 1241 | info?: ArrayBuffer | ArrayBufferView; 1242 | } 1243 | interface SubtleCryptoEncryptAlgorithm { 1244 | name: string; 1245 | iv?: ArrayBuffer | ArrayBufferView; 1246 | additionalData?: ArrayBuffer | ArrayBufferView; 1247 | tagLength?: number; 1248 | counter?: ArrayBuffer | ArrayBufferView; 1249 | length?: number; 1250 | label?: ArrayBuffer | ArrayBufferView; 1251 | } 1252 | interface SubtleCryptoGenerateKeyAlgorithm { 1253 | name: string; 1254 | hash?: string | SubtleCryptoHashAlgorithm; 1255 | modulusLength?: number; 1256 | publicExponent?: ArrayBuffer | ArrayBufferView; 1257 | length?: number; 1258 | namedCurve?: string; 1259 | } 1260 | interface SubtleCryptoHashAlgorithm { 1261 | name: string; 1262 | } 1263 | interface SubtleCryptoImportKeyAlgorithm { 1264 | name: string; 1265 | hash?: string | SubtleCryptoHashAlgorithm; 1266 | length?: number; 1267 | namedCurve?: string; 1268 | compressed?: boolean; 1269 | } 1270 | interface SubtleCryptoSignAlgorithm { 1271 | name: string; 1272 | hash?: string | SubtleCryptoHashAlgorithm; 1273 | dataLength?: number; 1274 | saltLength?: number; 1275 | } 1276 | interface CryptoKeyKeyAlgorithm { 1277 | name: string; 1278 | } 1279 | interface CryptoKeyAesKeyAlgorithm { 1280 | name: string; 1281 | length: number; 1282 | } 1283 | interface CryptoKeyHmacKeyAlgorithm { 1284 | name: string; 1285 | hash: CryptoKeyKeyAlgorithm; 1286 | length: number; 1287 | } 1288 | interface CryptoKeyRsaKeyAlgorithm { 1289 | name: string; 1290 | modulusLength: number; 1291 | publicExponent: ArrayBuffer | ArrayBufferView; 1292 | hash?: CryptoKeyKeyAlgorithm; 1293 | } 1294 | interface CryptoKeyEllipticKeyAlgorithm { 1295 | name: string; 1296 | namedCurve: string; 1297 | } 1298 | interface CryptoKeyArbitraryKeyAlgorithm { 1299 | name: string; 1300 | hash?: CryptoKeyKeyAlgorithm; 1301 | namedCurve?: string; 1302 | length?: number; 1303 | } 1304 | declare class DigestStream extends WritableStream< 1305 | ArrayBuffer | ArrayBufferView 1306 | > { 1307 | constructor(algorithm: string | SubtleCryptoHashAlgorithm); 1308 | readonly digest: Promise<ArrayBuffer>; 1309 | get bytesWritten(): number | bigint; 1310 | } 1311 | /** 1312 | * A decoder for a specific method, that is a specific character encoding, like utf-8, iso-8859-2, koi8, cp1261, gbk, etc. A decoder takes a stream of bytes as input and emits a stream of code points. For a more scalable, non-native library, see StringView – a C-like representation of strings based on typed arrays. 1313 | * 1314 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextDecoder) 1315 | */ 1316 | declare class TextDecoder { 1317 | constructor(label?: string, options?: TextDecoderConstructorOptions); 1318 | /** 1319 | * Returns the result of running encoding's decoder. The method can be invoked zero or more times with options's stream set to true, and then once without options's stream (or set to false), to process a fragmented input. If the invocation without options's stream (or set to false) has no input, it's clearest to omit both arguments. 1320 | * 1321 | * ``` 1322 | * var string = "", decoder = new TextDecoder(encoding), buffer; 1323 | * while(buffer = next_chunk()) { 1324 | * string += decoder.decode(buffer, {stream:true}); 1325 | * } 1326 | * string += decoder.decode(); // end-of-queue 1327 | * ``` 1328 | * 1329 | * If the error mode is "fatal" and encoding's decoder returns error, throws a TypeError. 1330 | * 1331 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextDecoder/decode) 1332 | */ 1333 | decode( 1334 | input?: ArrayBuffer | ArrayBufferView, 1335 | options?: TextDecoderDecodeOptions 1336 | ): string; 1337 | get encoding(): string; 1338 | get fatal(): boolean; 1339 | get ignoreBOM(): boolean; 1340 | } 1341 | /** 1342 | * TextEncoder takes a stream of code points as input and emits a stream of bytes. For a more scalable, non-native library, see StringView – a C-like representation of strings based on typed arrays. 1343 | * 1344 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoder) 1345 | */ 1346 | declare class TextEncoder { 1347 | constructor(); 1348 | /** 1349 | * Returns the result of running UTF-8's encoder. 1350 | * 1351 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoder/encode) 1352 | */ 1353 | encode(input?: string): Uint8Array; 1354 | /** 1355 | * Runs the UTF-8 encoder on source, stores the result of that operation into destination, and returns the progress made as an object wherein read is the number of converted code units of source and written is the number of bytes modified in destination. 1356 | * 1357 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoder/encodeInto) 1358 | */ 1359 | encodeInto( 1360 | input: string, 1361 | buffer: ArrayBuffer | ArrayBufferView 1362 | ): TextEncoderEncodeIntoResult; 1363 | get encoding(): string; 1364 | } 1365 | interface TextDecoderConstructorOptions { 1366 | fatal: boolean; 1367 | ignoreBOM: boolean; 1368 | } 1369 | interface TextDecoderDecodeOptions { 1370 | stream: boolean; 1371 | } 1372 | interface TextEncoderEncodeIntoResult { 1373 | read: number; 1374 | written: number; 1375 | } 1376 | /** 1377 | * Events providing information related to errors in scripts or in files. 1378 | * 1379 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ErrorEvent) 1380 | */ 1381 | declare class ErrorEvent extends Event { 1382 | constructor(type: string, init?: ErrorEventErrorEventInit); 1383 | get filename(): string; 1384 | get message(): string; 1385 | get lineno(): number; 1386 | get colno(): number; 1387 | get error(): any; 1388 | } 1389 | interface ErrorEventErrorEventInit { 1390 | message?: string; 1391 | filename?: string; 1392 | lineno?: number; 1393 | colno?: number; 1394 | error?: any; 1395 | } 1396 | /** 1397 | * Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data". 1398 | * 1399 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData) 1400 | */ 1401 | declare class FormData { 1402 | constructor(); 1403 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/append) */ 1404 | append(name: string, value: string): void; 1405 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/append) */ 1406 | append(name: string, value: Blob, filename?: string): void; 1407 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/delete) */ 1408 | delete(name: string): void; 1409 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/get) */ 1410 | get(name: string): (File | string) | null; 1411 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/getAll) */ 1412 | getAll(name: string): (File | string)[]; 1413 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/has) */ 1414 | has(name: string): boolean; 1415 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/set) */ 1416 | set(name: string, value: string): void; 1417 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FormData/set) */ 1418 | set(name: string, value: Blob, filename?: string): void; 1419 | /* Returns an array of key, value pairs for every entry in the list. */ 1420 | entries(): IterableIterator<[key: string, value: File | string]>; 1421 | /* Returns a list of keys in the list. */ 1422 | keys(): IterableIterator<string>; 1423 | /* Returns a list of values in the list. */ 1424 | values(): IterableIterator<File | string>; 1425 | forEach<This = unknown>( 1426 | callback: ( 1427 | this: This, 1428 | value: File | string, 1429 | key: string, 1430 | parent: FormData 1431 | ) => void, 1432 | thisArg?: This 1433 | ): void; 1434 | [Symbol.iterator](): IterableIterator<[key: string, value: File | string]>; 1435 | } 1436 | interface ContentOptions { 1437 | html?: boolean; 1438 | } 1439 | declare class HTMLRewriter { 1440 | constructor(); 1441 | on( 1442 | selector: string, 1443 | handlers: HTMLRewriterElementContentHandlers 1444 | ): HTMLRewriter; 1445 | onDocument(handlers: HTMLRewriterDocumentContentHandlers): HTMLRewriter; 1446 | transform(response: Response): Response; 1447 | } 1448 | interface HTMLRewriterElementContentHandlers { 1449 | element?(element: Element): void | Promise<void>; 1450 | comments?(comment: Comment): void | Promise<void>; 1451 | text?(element: Text): void | Promise<void>; 1452 | } 1453 | interface HTMLRewriterDocumentContentHandlers { 1454 | doctype?(doctype: Doctype): void | Promise<void>; 1455 | comments?(comment: Comment): void | Promise<void>; 1456 | text?(text: Text): void | Promise<void>; 1457 | end?(end: DocumentEnd): void | Promise<void>; 1458 | } 1459 | interface Doctype { 1460 | readonly name: string | null; 1461 | readonly publicId: string | null; 1462 | readonly systemId: string | null; 1463 | } 1464 | interface Element { 1465 | tagName: string; 1466 | readonly attributes: IterableIterator<string[]>; 1467 | readonly removed: boolean; 1468 | readonly namespaceURI: string; 1469 | getAttribute(name: string): string | null; 1470 | hasAttribute(name: string): boolean; 1471 | setAttribute(name: string, value: string): Element; 1472 | removeAttribute(name: string): Element; 1473 | before( 1474 | content: string | ReadableStream | Response, 1475 | options?: ContentOptions 1476 | ): Element; 1477 | after( 1478 | content: string | ReadableStream | Response, 1479 | options?: ContentOptions 1480 | ): Element; 1481 | prepend( 1482 | content: string | ReadableStream | Response, 1483 | options?: ContentOptions 1484 | ): Element; 1485 | append( 1486 | content: string | ReadableStream | Response, 1487 | options?: ContentOptions 1488 | ): Element; 1489 | replace( 1490 | content: string | ReadableStream | Response, 1491 | options?: ContentOptions 1492 | ): Element; 1493 | remove(): Element; 1494 | removeAndKeepContent(): Element; 1495 | setInnerContent( 1496 | content: string | ReadableStream | Response, 1497 | options?: ContentOptions 1498 | ): Element; 1499 | onEndTag(handler: (tag: EndTag) => void | Promise<void>): void; 1500 | } 1501 | interface EndTag { 1502 | name: string; 1503 | before( 1504 | content: string | ReadableStream | Response, 1505 | options?: ContentOptions 1506 | ): EndTag; 1507 | after( 1508 | content: string | ReadableStream | Response, 1509 | options?: ContentOptions 1510 | ): EndTag; 1511 | remove(): EndTag; 1512 | } 1513 | interface Comment { 1514 | text: string; 1515 | readonly removed: boolean; 1516 | before(content: string, options?: ContentOptions): Comment; 1517 | after(content: string, options?: ContentOptions): Comment; 1518 | replace(content: string, options?: ContentOptions): Comment; 1519 | remove(): Comment; 1520 | } 1521 | interface Text { 1522 | readonly text: string; 1523 | readonly lastInTextNode: boolean; 1524 | readonly removed: boolean; 1525 | before( 1526 | content: string | ReadableStream | Response, 1527 | options?: ContentOptions 1528 | ): Text; 1529 | after( 1530 | content: string | ReadableStream | Response, 1531 | options?: ContentOptions 1532 | ): Text; 1533 | replace( 1534 | content: string | ReadableStream | Response, 1535 | options?: ContentOptions 1536 | ): Text; 1537 | remove(): Text; 1538 | } 1539 | interface DocumentEnd { 1540 | append(content: string, options?: ContentOptions): DocumentEnd; 1541 | } 1542 | /** 1543 | * This is the event type for fetch events dispatched on the service worker global scope. It contains information about the fetch, including the request and how the receiver will treat the response. It provides the event.respondWith() method, which allows us to provide a response to this fetch. 1544 | * 1545 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent) 1546 | */ 1547 | declare abstract class FetchEvent extends ExtendableEvent { 1548 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/request) */ 1549 | readonly request: Request; 1550 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/FetchEvent/respondWith) */ 1551 | respondWith(promise: Response | Promise<Response>): void; 1552 | passThroughOnException(): void; 1553 | } 1554 | type HeadersInit = 1555 | | Headers 1556 | | Iterable<Iterable<string>> 1557 | | Record<string, string>; 1558 | /** 1559 | * This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs. You can add to this using methods like append() (see Examples.) In all methods of this interface, header names are matched by case-insensitive byte sequence. 1560 | * 1561 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers) 1562 | */ 1563 | declare class Headers { 1564 | constructor(init?: HeadersInit); 1565 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/get) */ 1566 | get(name: string): string | null; 1567 | getAll(name: string): string[]; 1568 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/getSetCookie) */ 1569 | getSetCookie(): string[]; 1570 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/has) */ 1571 | has(name: string): boolean; 1572 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/set) */ 1573 | set(name: string, value: string): void; 1574 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/append) */ 1575 | append(name: string, value: string): void; 1576 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Headers/delete) */ 1577 | delete(name: string): void; 1578 | forEach<This = unknown>( 1579 | callback: (this: This, value: string, key: string, parent: Headers) => void, 1580 | thisArg?: This 1581 | ): void; 1582 | /* Returns an iterator allowing to go through all key/value pairs contained in this object. */ 1583 | entries(): IterableIterator<[key: string, value: string]>; 1584 | /* Returns an iterator allowing to go through all keys of the key/value pairs contained in this object. */ 1585 | keys(): IterableIterator<string>; 1586 | /* Returns an iterator allowing to go through all values of the key/value pairs contained in this object. */ 1587 | values(): IterableIterator<string>; 1588 | [Symbol.iterator](): IterableIterator<[key: string, value: string]>; 1589 | } 1590 | type BodyInit = 1591 | | ReadableStream<Uint8Array> 1592 | | string 1593 | | ArrayBuffer 1594 | | ArrayBufferView 1595 | | Blob 1596 | | URLSearchParams 1597 | | FormData; 1598 | declare abstract class Body { 1599 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body) */ 1600 | get body(): ReadableStream | null; 1601 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */ 1602 | get bodyUsed(): boolean; 1603 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */ 1604 | arrayBuffer(): Promise<ArrayBuffer>; 1605 | bytes(): Promise<Uint8Array>; 1606 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/text) */ 1607 | text(): Promise<string>; 1608 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/json) */ 1609 | json<T>(): Promise<T>; 1610 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/formData) */ 1611 | formData(): Promise<FormData>; 1612 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */ 1613 | blob(): Promise<Blob>; 1614 | } 1615 | /** 1616 | * This Fetch API interface represents the response to a request. 1617 | * 1618 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response) 1619 | */ 1620 | declare var Response: { 1621 | prototype: Response; 1622 | new (body?: BodyInit | null, init?: ResponseInit): Response; 1623 | error(): Response; 1624 | redirect(url: string, status?: number): Response; 1625 | json(any: any, maybeInit?: ResponseInit | Response): Response; 1626 | }; 1627 | /** 1628 | * This Fetch API interface represents the response to a request. 1629 | * 1630 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response) 1631 | */ 1632 | interface Response extends Body { 1633 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone) */ 1634 | clone(): Response; 1635 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/status) */ 1636 | status: number; 1637 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/statusText) */ 1638 | statusText: string; 1639 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/headers) */ 1640 | headers: Headers; 1641 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/ok) */ 1642 | ok: boolean; 1643 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirected) */ 1644 | redirected: boolean; 1645 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/url) */ 1646 | url: string; 1647 | webSocket: WebSocket | null; 1648 | cf: any | undefined; 1649 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/type) */ 1650 | type: 'default' | 'error'; 1651 | } 1652 | interface ResponseInit { 1653 | status?: number; 1654 | statusText?: string; 1655 | headers?: HeadersInit; 1656 | cf?: any; 1657 | webSocket?: WebSocket | null; 1658 | encodeBody?: 'automatic' | 'manual'; 1659 | } 1660 | type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> = 1661 | | Request<CfHostMetadata, Cf> 1662 | | string; 1663 | /** 1664 | * This Fetch API interface represents a resource request. 1665 | * 1666 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request) 1667 | */ 1668 | declare var Request: { 1669 | prototype: Request; 1670 | new <CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>>( 1671 | input: RequestInfo<CfProperties> | URL, 1672 | init?: RequestInit<Cf> 1673 | ): Request<CfHostMetadata, Cf>; 1674 | }; 1675 | /** 1676 | * This Fetch API interface represents a resource request. 1677 | * 1678 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request) 1679 | */ 1680 | interface Request<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> 1681 | extends Body { 1682 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/clone) */ 1683 | clone(): Request<CfHostMetadata, Cf>; 1684 | /** 1685 | * Returns request's HTTP method, which is "GET" by default. 1686 | * 1687 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/method) 1688 | */ 1689 | method: string; 1690 | /** 1691 | * Returns the URL of request as a string. 1692 | * 1693 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/url) 1694 | */ 1695 | url: string; 1696 | /** 1697 | * Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header. 1698 | * 1699 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/headers) 1700 | */ 1701 | headers: Headers; 1702 | /** 1703 | * Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default. 1704 | * 1705 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/redirect) 1706 | */ 1707 | redirect: string; 1708 | fetcher: Fetcher | null; 1709 | /** 1710 | * Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. 1711 | * 1712 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/signal) 1713 | */ 1714 | signal: AbortSignal; 1715 | cf: Cf | undefined; 1716 | /** 1717 | * Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI] 1718 | * 1719 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/integrity) 1720 | */ 1721 | integrity: string; 1722 | /* Returns a boolean indicating whether or not request can outlive the global in which it was created. */ 1723 | keepalive: boolean; 1724 | /** 1725 | * Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. 1726 | * 1727 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/cache) 1728 | */ 1729 | cache?: 'no-store'; 1730 | } 1731 | interface RequestInit<Cf = CfProperties> { 1732 | /* A string to set request's method. */ 1733 | method?: string; 1734 | /* A Headers object, an object literal, or an array of two-item arrays to set request's headers. */ 1735 | headers?: HeadersInit; 1736 | /* A BodyInit object or null to set request's body. */ 1737 | body?: BodyInit | null; 1738 | /* A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. */ 1739 | redirect?: string; 1740 | fetcher?: Fetcher | null; 1741 | cf?: Cf; 1742 | /* A string indicating how the request will interact with the browser's cache to set request's cache. */ 1743 | cache?: 'no-store'; 1744 | /* A cryptographic hash of the resource to be fetched by request. Sets request's integrity. */ 1745 | integrity?: string; 1746 | /* An AbortSignal to set request's signal. */ 1747 | signal?: AbortSignal | null; 1748 | encodeResponseBody?: 'automatic' | 'manual'; 1749 | } 1750 | type Service<T extends Rpc.WorkerEntrypointBranded | undefined = undefined> = 1751 | Fetcher<T>; 1752 | type Fetcher< 1753 | T extends Rpc.EntrypointBranded | undefined = undefined, 1754 | Reserved extends string = never, 1755 | > = (T extends Rpc.EntrypointBranded 1756 | ? Rpc.Provider<T, Reserved | 'fetch' | 'connect'> 1757 | : unknown) & { 1758 | fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>; 1759 | connect(address: SocketAddress | string, options?: SocketOptions): Socket; 1760 | }; 1761 | interface KVNamespaceListKey<Metadata, Key extends string = string> { 1762 | name: Key; 1763 | expiration?: number; 1764 | metadata?: Metadata; 1765 | } 1766 | type KVNamespaceListResult<Metadata, Key extends string = string> = 1767 | | { 1768 | list_complete: false; 1769 | keys: KVNamespaceListKey<Metadata, Key>[]; 1770 | cursor: string; 1771 | cacheStatus: string | null; 1772 | } 1773 | | { 1774 | list_complete: true; 1775 | keys: KVNamespaceListKey<Metadata, Key>[]; 1776 | cacheStatus: string | null; 1777 | }; 1778 | interface KVNamespace<Key extends string = string> { 1779 | get( 1780 | key: Key, 1781 | options?: Partial<KVNamespaceGetOptions<undefined>> 1782 | ): Promise<string | null>; 1783 | get(key: Key, type: 'text'): Promise<string | null>; 1784 | get<ExpectedValue = unknown>( 1785 | key: Key, 1786 | type: 'json' 1787 | ): Promise<ExpectedValue | null>; 1788 | get(key: Key, type: 'arrayBuffer'): Promise<ArrayBuffer | null>; 1789 | get(key: Key, type: 'stream'): Promise<ReadableStream | null>; 1790 | get( 1791 | key: Key, 1792 | options?: KVNamespaceGetOptions<'text'> 1793 | ): Promise<string | null>; 1794 | get<ExpectedValue = unknown>( 1795 | key: Key, 1796 | options?: KVNamespaceGetOptions<'json'> 1797 | ): Promise<ExpectedValue | null>; 1798 | get( 1799 | key: Key, 1800 | options?: KVNamespaceGetOptions<'arrayBuffer'> 1801 | ): Promise<ArrayBuffer | null>; 1802 | get( 1803 | key: Key, 1804 | options?: KVNamespaceGetOptions<'stream'> 1805 | ): Promise<ReadableStream | null>; 1806 | get(key: Array<Key>, type: 'text'): Promise<Map<string, string | null>>; 1807 | get<ExpectedValue = unknown>( 1808 | key: Array<Key>, 1809 | type: 'json' 1810 | ): Promise<Map<string, ExpectedValue | null>>; 1811 | get( 1812 | key: Array<Key>, 1813 | options?: Partial<KVNamespaceGetOptions<undefined>> 1814 | ): Promise<Map<string, string | null>>; 1815 | get( 1816 | key: Array<Key>, 1817 | options?: KVNamespaceGetOptions<'text'> 1818 | ): Promise<Map<string, string | null>>; 1819 | get<ExpectedValue = unknown>( 1820 | key: Array<Key>, 1821 | options?: KVNamespaceGetOptions<'json'> 1822 | ): Promise<Map<string, ExpectedValue | null>>; 1823 | list<Metadata = unknown>( 1824 | options?: KVNamespaceListOptions 1825 | ): Promise<KVNamespaceListResult<Metadata, Key>>; 1826 | put( 1827 | key: Key, 1828 | value: string | ArrayBuffer | ArrayBufferView | ReadableStream, 1829 | options?: KVNamespacePutOptions 1830 | ): Promise<void>; 1831 | getWithMetadata<Metadata = unknown>( 1832 | key: Key, 1833 | options?: Partial<KVNamespaceGetOptions<undefined>> 1834 | ): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>; 1835 | getWithMetadata<Metadata = unknown>( 1836 | key: Key, 1837 | type: 'text' 1838 | ): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>; 1839 | getWithMetadata<ExpectedValue = unknown, Metadata = unknown>( 1840 | key: Key, 1841 | type: 'json' 1842 | ): Promise<KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>; 1843 | getWithMetadata<Metadata = unknown>( 1844 | key: Key, 1845 | type: 'arrayBuffer' 1846 | ): Promise<KVNamespaceGetWithMetadataResult<ArrayBuffer, Metadata>>; 1847 | getWithMetadata<Metadata = unknown>( 1848 | key: Key, 1849 | type: 'stream' 1850 | ): Promise<KVNamespaceGetWithMetadataResult<ReadableStream, Metadata>>; 1851 | getWithMetadata<Metadata = unknown>( 1852 | key: Key, 1853 | options: KVNamespaceGetOptions<'text'> 1854 | ): Promise<KVNamespaceGetWithMetadataResult<string, Metadata>>; 1855 | getWithMetadata<ExpectedValue = unknown, Metadata = unknown>( 1856 | key: Key, 1857 | options: KVNamespaceGetOptions<'json'> 1858 | ): Promise<KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>>; 1859 | getWithMetadata<Metadata = unknown>( 1860 | key: Key, 1861 | options: KVNamespaceGetOptions<'arrayBuffer'> 1862 | ): Promise<KVNamespaceGetWithMetadataResult<ArrayBuffer, Metadata>>; 1863 | getWithMetadata<Metadata = unknown>( 1864 | key: Key, 1865 | options: KVNamespaceGetOptions<'stream'> 1866 | ): Promise<KVNamespaceGetWithMetadataResult<ReadableStream, Metadata>>; 1867 | getWithMetadata<Metadata = unknown>( 1868 | key: Array<Key>, 1869 | type: 'text' 1870 | ): Promise<Map<string, KVNamespaceGetWithMetadataResult<string, Metadata>>>; 1871 | getWithMetadata<ExpectedValue = unknown, Metadata = unknown>( 1872 | key: Array<Key>, 1873 | type: 'json' 1874 | ): Promise< 1875 | Map<string, KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>> 1876 | >; 1877 | getWithMetadata<Metadata = unknown>( 1878 | key: Array<Key>, 1879 | options?: Partial<KVNamespaceGetOptions<undefined>> 1880 | ): Promise<Map<string, KVNamespaceGetWithMetadataResult<string, Metadata>>>; 1881 | getWithMetadata<Metadata = unknown>( 1882 | key: Array<Key>, 1883 | options?: KVNamespaceGetOptions<'text'> 1884 | ): Promise<Map<string, KVNamespaceGetWithMetadataResult<string, Metadata>>>; 1885 | getWithMetadata<ExpectedValue = unknown, Metadata = unknown>( 1886 | key: Array<Key>, 1887 | options?: KVNamespaceGetOptions<'json'> 1888 | ): Promise< 1889 | Map<string, KVNamespaceGetWithMetadataResult<ExpectedValue, Metadata>> 1890 | >; 1891 | delete(key: Key): Promise<void>; 1892 | } 1893 | interface KVNamespaceListOptions { 1894 | limit?: number; 1895 | prefix?: string | null; 1896 | cursor?: string | null; 1897 | } 1898 | interface KVNamespaceGetOptions<Type> { 1899 | type: Type; 1900 | cacheTtl?: number; 1901 | } 1902 | interface KVNamespacePutOptions { 1903 | expiration?: number; 1904 | expirationTtl?: number; 1905 | metadata?: any | null; 1906 | } 1907 | interface KVNamespaceGetWithMetadataResult<Value, Metadata> { 1908 | value: Value | null; 1909 | metadata: Metadata | null; 1910 | cacheStatus: string | null; 1911 | } 1912 | type QueueContentType = 'text' | 'bytes' | 'json' | 'v8'; 1913 | interface Queue<Body = unknown> { 1914 | send(message: Body, options?: QueueSendOptions): Promise<void>; 1915 | sendBatch( 1916 | messages: Iterable<MessageSendRequest<Body>>, 1917 | options?: QueueSendBatchOptions 1918 | ): Promise<void>; 1919 | } 1920 | interface QueueSendOptions { 1921 | contentType?: QueueContentType; 1922 | delaySeconds?: number; 1923 | } 1924 | interface QueueSendBatchOptions { 1925 | delaySeconds?: number; 1926 | } 1927 | interface MessageSendRequest<Body = unknown> { 1928 | body: Body; 1929 | contentType?: QueueContentType; 1930 | delaySeconds?: number; 1931 | } 1932 | interface QueueRetryOptions { 1933 | delaySeconds?: number; 1934 | } 1935 | interface Message<Body = unknown> { 1936 | readonly id: string; 1937 | readonly timestamp: Date; 1938 | readonly body: Body; 1939 | readonly attempts: number; 1940 | retry(options?: QueueRetryOptions): void; 1941 | ack(): void; 1942 | } 1943 | interface QueueEvent<Body = unknown> extends ExtendableEvent { 1944 | readonly messages: readonly Message<Body>[]; 1945 | readonly queue: string; 1946 | retryAll(options?: QueueRetryOptions): void; 1947 | ackAll(): void; 1948 | } 1949 | interface MessageBatch<Body = unknown> { 1950 | readonly messages: readonly Message<Body>[]; 1951 | readonly queue: string; 1952 | retryAll(options?: QueueRetryOptions): void; 1953 | ackAll(): void; 1954 | } 1955 | interface R2Error extends Error { 1956 | readonly name: string; 1957 | readonly code: number; 1958 | readonly message: string; 1959 | readonly action: string; 1960 | readonly stack: any; 1961 | } 1962 | interface R2ListOptions { 1963 | limit?: number; 1964 | prefix?: string; 1965 | cursor?: string; 1966 | delimiter?: string; 1967 | startAfter?: string; 1968 | include?: ('httpMetadata' | 'customMetadata')[]; 1969 | } 1970 | declare abstract class R2Bucket { 1971 | head(key: string): Promise<R2Object | null>; 1972 | get( 1973 | key: string, 1974 | options: R2GetOptions & { 1975 | onlyIf: R2Conditional | Headers; 1976 | } 1977 | ): Promise<R2ObjectBody | R2Object | null>; 1978 | get(key: string, options?: R2GetOptions): Promise<R2ObjectBody | null>; 1979 | put( 1980 | key: string, 1981 | value: 1982 | | ReadableStream 1983 | | ArrayBuffer 1984 | | ArrayBufferView 1985 | | string 1986 | | null 1987 | | Blob, 1988 | options?: R2PutOptions & { 1989 | onlyIf: R2Conditional | Headers; 1990 | } 1991 | ): Promise<R2Object | null>; 1992 | put( 1993 | key: string, 1994 | value: 1995 | | ReadableStream 1996 | | ArrayBuffer 1997 | | ArrayBufferView 1998 | | string 1999 | | null 2000 | | Blob, 2001 | options?: R2PutOptions 2002 | ): Promise<R2Object>; 2003 | createMultipartUpload( 2004 | key: string, 2005 | options?: R2MultipartOptions 2006 | ): Promise<R2MultipartUpload>; 2007 | resumeMultipartUpload(key: string, uploadId: string): R2MultipartUpload; 2008 | delete(keys: string | string[]): Promise<void>; 2009 | list(options?: R2ListOptions): Promise<R2Objects>; 2010 | } 2011 | interface R2MultipartUpload { 2012 | readonly key: string; 2013 | readonly uploadId: string; 2014 | uploadPart( 2015 | partNumber: number, 2016 | value: ReadableStream | (ArrayBuffer | ArrayBufferView) | string | Blob, 2017 | options?: R2UploadPartOptions 2018 | ): Promise<R2UploadedPart>; 2019 | abort(): Promise<void>; 2020 | complete(uploadedParts: R2UploadedPart[]): Promise<R2Object>; 2021 | } 2022 | interface R2UploadedPart { 2023 | partNumber: number; 2024 | etag: string; 2025 | } 2026 | declare abstract class R2Object { 2027 | readonly key: string; 2028 | readonly version: string; 2029 | readonly size: number; 2030 | readonly etag: string; 2031 | readonly httpEtag: string; 2032 | readonly checksums: R2Checksums; 2033 | readonly uploaded: Date; 2034 | readonly httpMetadata?: R2HTTPMetadata; 2035 | readonly customMetadata?: Record<string, string>; 2036 | readonly range?: R2Range; 2037 | readonly storageClass: string; 2038 | readonly ssecKeyMd5?: string; 2039 | writeHttpMetadata(headers: Headers): void; 2040 | } 2041 | interface R2ObjectBody extends R2Object { 2042 | get body(): ReadableStream; 2043 | get bodyUsed(): boolean; 2044 | arrayBuffer(): Promise<ArrayBuffer>; 2045 | text(): Promise<string>; 2046 | json<T>(): Promise<T>; 2047 | blob(): Promise<Blob>; 2048 | } 2049 | type R2Range = 2050 | | { 2051 | offset: number; 2052 | length?: number; 2053 | } 2054 | | { 2055 | offset?: number; 2056 | length: number; 2057 | } 2058 | | { 2059 | suffix: number; 2060 | }; 2061 | interface R2Conditional { 2062 | etagMatches?: string; 2063 | etagDoesNotMatch?: string; 2064 | uploadedBefore?: Date; 2065 | uploadedAfter?: Date; 2066 | secondsGranularity?: boolean; 2067 | } 2068 | interface R2GetOptions { 2069 | onlyIf?: R2Conditional | Headers; 2070 | range?: R2Range | Headers; 2071 | ssecKey?: ArrayBuffer | string; 2072 | } 2073 | interface R2PutOptions { 2074 | onlyIf?: R2Conditional | Headers; 2075 | httpMetadata?: R2HTTPMetadata | Headers; 2076 | customMetadata?: Record<string, string>; 2077 | md5?: (ArrayBuffer | ArrayBufferView) | string; 2078 | sha1?: (ArrayBuffer | ArrayBufferView) | string; 2079 | sha256?: (ArrayBuffer | ArrayBufferView) | string; 2080 | sha384?: (ArrayBuffer | ArrayBufferView) | string; 2081 | sha512?: (ArrayBuffer | ArrayBufferView) | string; 2082 | storageClass?: string; 2083 | ssecKey?: ArrayBuffer | string; 2084 | } 2085 | interface R2MultipartOptions { 2086 | httpMetadata?: R2HTTPMetadata | Headers; 2087 | customMetadata?: Record<string, string>; 2088 | storageClass?: string; 2089 | ssecKey?: ArrayBuffer | string; 2090 | } 2091 | interface R2Checksums { 2092 | readonly md5?: ArrayBuffer; 2093 | readonly sha1?: ArrayBuffer; 2094 | readonly sha256?: ArrayBuffer; 2095 | readonly sha384?: ArrayBuffer; 2096 | readonly sha512?: ArrayBuffer; 2097 | toJSON(): R2StringChecksums; 2098 | } 2099 | interface R2StringChecksums { 2100 | md5?: string; 2101 | sha1?: string; 2102 | sha256?: string; 2103 | sha384?: string; 2104 | sha512?: string; 2105 | } 2106 | interface R2HTTPMetadata { 2107 | contentType?: string; 2108 | contentLanguage?: string; 2109 | contentDisposition?: string; 2110 | contentEncoding?: string; 2111 | cacheControl?: string; 2112 | cacheExpiry?: Date; 2113 | } 2114 | type R2Objects = { 2115 | objects: R2Object[]; 2116 | delimitedPrefixes: string[]; 2117 | } & ( 2118 | | { 2119 | truncated: true; 2120 | cursor: string; 2121 | } 2122 | | { 2123 | truncated: false; 2124 | } 2125 | ); 2126 | interface R2UploadPartOptions { 2127 | ssecKey?: ArrayBuffer | string; 2128 | } 2129 | declare abstract class ScheduledEvent extends ExtendableEvent { 2130 | readonly scheduledTime: number; 2131 | readonly cron: string; 2132 | noRetry(): void; 2133 | } 2134 | interface ScheduledController { 2135 | readonly scheduledTime: number; 2136 | readonly cron: string; 2137 | noRetry(): void; 2138 | } 2139 | interface QueuingStrategy<T = any> { 2140 | highWaterMark?: number | bigint; 2141 | size?: (chunk: T) => number | bigint; 2142 | } 2143 | interface UnderlyingSink<W = any> { 2144 | type?: string; 2145 | start?: (controller: WritableStreamDefaultController) => void | Promise<void>; 2146 | write?: ( 2147 | chunk: W, 2148 | controller: WritableStreamDefaultController 2149 | ) => void | Promise<void>; 2150 | abort?: (reason: any) => void | Promise<void>; 2151 | close?: () => void | Promise<void>; 2152 | } 2153 | interface UnderlyingByteSource { 2154 | type: 'bytes'; 2155 | autoAllocateChunkSize?: number; 2156 | start?: (controller: ReadableByteStreamController) => void | Promise<void>; 2157 | pull?: (controller: ReadableByteStreamController) => void | Promise<void>; 2158 | cancel?: (reason: any) => void | Promise<void>; 2159 | } 2160 | interface UnderlyingSource<R = any> { 2161 | type?: '' | undefined; 2162 | start?: ( 2163 | controller: ReadableStreamDefaultController<R> 2164 | ) => void | Promise<void>; 2165 | pull?: ( 2166 | controller: ReadableStreamDefaultController<R> 2167 | ) => void | Promise<void>; 2168 | cancel?: (reason: any) => void | Promise<void>; 2169 | expectedLength?: number | bigint; 2170 | } 2171 | interface Transformer<I = any, O = any> { 2172 | readableType?: string; 2173 | writableType?: string; 2174 | start?: ( 2175 | controller: TransformStreamDefaultController<O> 2176 | ) => void | Promise<void>; 2177 | transform?: ( 2178 | chunk: I, 2179 | controller: TransformStreamDefaultController<O> 2180 | ) => void | Promise<void>; 2181 | flush?: ( 2182 | controller: TransformStreamDefaultController<O> 2183 | ) => void | Promise<void>; 2184 | cancel?: (reason: any) => void | Promise<void>; 2185 | expectedLength?: number; 2186 | } 2187 | interface StreamPipeOptions { 2188 | /** 2189 | * Pipes this readable stream to a given writable stream destination. The way in which the piping process behaves under various error conditions can be customized with a number of passed options. It returns a promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered. 2190 | * 2191 | * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader. 2192 | * 2193 | * Errors and closures of the source and destination streams propagate as follows: 2194 | * 2195 | * An error in this source readable stream will abort destination, unless preventAbort is truthy. The returned promise will be rejected with the source's error, or with any error that occurs during aborting the destination. 2196 | * 2197 | * An error in destination will cancel this source readable stream, unless preventCancel is truthy. The returned promise will be rejected with the destination's error, or with any error that occurs during canceling the source. 2198 | * 2199 | * When this source readable stream closes, destination will be closed, unless preventClose is truthy. The returned promise will be fulfilled once this process completes, unless an error is encountered while closing the destination, in which case it will be rejected with that error. 2200 | * 2201 | * If destination starts out closed or closing, this source readable stream will be canceled, unless preventCancel is true. The returned promise will be rejected with an error indicating piping to a closed stream failed, or with any error that occurs during canceling the source. 2202 | * 2203 | * The signal option can be set to an AbortSignal to allow aborting an ongoing pipe operation via the corresponding AbortController. In this case, this source readable stream will be canceled, and destination aborted, unless the respective options preventCancel or preventAbort are set. 2204 | */ 2205 | preventClose?: boolean; 2206 | preventAbort?: boolean; 2207 | preventCancel?: boolean; 2208 | signal?: AbortSignal; 2209 | } 2210 | type ReadableStreamReadResult<R = any> = 2211 | | { 2212 | done: false; 2213 | value: R; 2214 | } 2215 | | { 2216 | done: true; 2217 | value?: undefined; 2218 | }; 2219 | /** 2220 | * This Streams API interface represents a readable stream of byte data. The Fetch API offers a concrete instance of a ReadableStream through the body property of a Response object. 2221 | * 2222 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream) 2223 | */ 2224 | interface ReadableStream<R = any> { 2225 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/locked) */ 2226 | get locked(): boolean; 2227 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/cancel) */ 2228 | cancel(reason?: any): Promise<void>; 2229 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/getReader) */ 2230 | getReader(): ReadableStreamDefaultReader<R>; 2231 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/getReader) */ 2232 | getReader(options: ReadableStreamGetReaderOptions): ReadableStreamBYOBReader; 2233 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/pipeThrough) */ 2234 | pipeThrough<T>( 2235 | transform: ReadableWritablePair<T, R>, 2236 | options?: StreamPipeOptions 2237 | ): ReadableStream<T>; 2238 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/pipeTo) */ 2239 | pipeTo( 2240 | destination: WritableStream<R>, 2241 | options?: StreamPipeOptions 2242 | ): Promise<void>; 2243 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream/tee) */ 2244 | tee(): [ReadableStream<R>, ReadableStream<R>]; 2245 | values(options?: ReadableStreamValuesOptions): AsyncIterableIterator<R>; 2246 | [Symbol.asyncIterator]( 2247 | options?: ReadableStreamValuesOptions 2248 | ): AsyncIterableIterator<R>; 2249 | } 2250 | /** 2251 | * This Streams API interface represents a readable stream of byte data. The Fetch API offers a concrete instance of a ReadableStream through the body property of a Response object. 2252 | * 2253 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStream) 2254 | */ 2255 | declare const ReadableStream: { 2256 | prototype: ReadableStream; 2257 | new ( 2258 | underlyingSource: UnderlyingByteSource, 2259 | strategy?: QueuingStrategy<Uint8Array> 2260 | ): ReadableStream<Uint8Array>; 2261 | new <R = any>( 2262 | underlyingSource?: UnderlyingSource<R>, 2263 | strategy?: QueuingStrategy<R> 2264 | ): ReadableStream<R>; 2265 | }; 2266 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader) */ 2267 | declare class ReadableStreamDefaultReader<R = any> { 2268 | constructor(stream: ReadableStream); 2269 | get closed(): Promise<void>; 2270 | cancel(reason?: any): Promise<void>; 2271 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/read) */ 2272 | read(): Promise<ReadableStreamReadResult<R>>; 2273 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultReader/releaseLock) */ 2274 | releaseLock(): void; 2275 | } 2276 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader) */ 2277 | declare class ReadableStreamBYOBReader { 2278 | constructor(stream: ReadableStream); 2279 | get closed(): Promise<void>; 2280 | cancel(reason?: any): Promise<void>; 2281 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/read) */ 2282 | read<T extends ArrayBufferView>( 2283 | view: T 2284 | ): Promise<ReadableStreamReadResult<T>>; 2285 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBReader/releaseLock) */ 2286 | releaseLock(): void; 2287 | readAtLeast<T extends ArrayBufferView>( 2288 | minElements: number, 2289 | view: T 2290 | ): Promise<ReadableStreamReadResult<T>>; 2291 | } 2292 | interface ReadableStreamBYOBReaderReadableStreamBYOBReaderReadOptions { 2293 | min?: number; 2294 | } 2295 | interface ReadableStreamGetReaderOptions { 2296 | /** 2297 | * Creates a ReadableStreamBYOBReader and locks the stream to the new reader. 2298 | * 2299 | * This call behaves the same way as the no-argument variant, except that it only works on readable byte streams, i.e. streams which were constructed specifically with the ability to handle "bring your own buffer" reading. The returned BYOB reader provides the ability to directly read individual chunks from the stream via its read() method, into developer-supplied buffers, allowing more precise control over allocation. 2300 | */ 2301 | mode: 'byob'; 2302 | } 2303 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest) */ 2304 | declare abstract class ReadableStreamBYOBRequest { 2305 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/view) */ 2306 | get view(): Uint8Array | null; 2307 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respond) */ 2308 | respond(bytesWritten: number): void; 2309 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamBYOBRequest/respondWithNewView) */ 2310 | respondWithNewView(view: ArrayBuffer | ArrayBufferView): void; 2311 | get atLeast(): number | null; 2312 | } 2313 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultController) */ 2314 | declare abstract class ReadableStreamDefaultController<R = any> { 2315 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultController/desiredSize) */ 2316 | get desiredSize(): number | null; 2317 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultController/close) */ 2318 | close(): void; 2319 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultController/enqueue) */ 2320 | enqueue(chunk?: R): void; 2321 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableStreamDefaultController/error) */ 2322 | error(reason: any): void; 2323 | } 2324 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController) */ 2325 | declare abstract class ReadableByteStreamController { 2326 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/byobRequest) */ 2327 | get byobRequest(): ReadableStreamBYOBRequest | null; 2328 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/desiredSize) */ 2329 | get desiredSize(): number | null; 2330 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/close) */ 2331 | close(): void; 2332 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/enqueue) */ 2333 | enqueue(chunk: ArrayBuffer | ArrayBufferView): void; 2334 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/error) */ 2335 | error(reason: any): void; 2336 | } 2337 | /** 2338 | * This Streams API interface represents a controller allowing control of a WritableStream's state. When constructing a WritableStream, the underlying sink is given a corresponding WritableStreamDefaultController instance to manipulate. 2339 | * 2340 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultController) 2341 | */ 2342 | declare abstract class WritableStreamDefaultController { 2343 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultController/signal) */ 2344 | get signal(): AbortSignal; 2345 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultController/error) */ 2346 | error(reason?: any): void; 2347 | } 2348 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStreamDefaultController) */ 2349 | declare abstract class TransformStreamDefaultController<O = any> { 2350 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStreamDefaultController/desiredSize) */ 2351 | get desiredSize(): number | null; 2352 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStreamDefaultController/enqueue) */ 2353 | enqueue(chunk?: O): void; 2354 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStreamDefaultController/error) */ 2355 | error(reason: any): void; 2356 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStreamDefaultController/terminate) */ 2357 | terminate(): void; 2358 | } 2359 | interface ReadableWritablePair<R = any, W = any> { 2360 | /** 2361 | * Provides a convenient, chainable way of piping this readable stream through a transform stream (or any other { writable, readable } pair). It simply pipes the stream into the writable side of the supplied pair, and returns the readable side for further use. 2362 | * 2363 | * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader. 2364 | */ 2365 | writable: WritableStream<W>; 2366 | readable: ReadableStream<R>; 2367 | } 2368 | /** 2369 | * This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing. 2370 | * 2371 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStream) 2372 | */ 2373 | declare class WritableStream<W = any> { 2374 | constructor( 2375 | underlyingSink?: UnderlyingSink, 2376 | queuingStrategy?: QueuingStrategy 2377 | ); 2378 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStream/locked) */ 2379 | get locked(): boolean; 2380 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStream/abort) */ 2381 | abort(reason?: any): Promise<void>; 2382 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStream/close) */ 2383 | close(): Promise<void>; 2384 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStream/getWriter) */ 2385 | getWriter(): WritableStreamDefaultWriter<W>; 2386 | } 2387 | /** 2388 | * This Streams API interface is the object returned by WritableStream.getWriter() and once created locks the < writer to the WritableStream ensuring that no other streams can write to the underlying sink. 2389 | * 2390 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter) 2391 | */ 2392 | declare class WritableStreamDefaultWriter<W = any> { 2393 | constructor(stream: WritableStream); 2394 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/closed) */ 2395 | get closed(): Promise<void>; 2396 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/ready) */ 2397 | get ready(): Promise<void>; 2398 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/desiredSize) */ 2399 | get desiredSize(): number | null; 2400 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/abort) */ 2401 | abort(reason?: any): Promise<void>; 2402 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/close) */ 2403 | close(): Promise<void>; 2404 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/write) */ 2405 | write(chunk?: W): Promise<void>; 2406 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/WritableStreamDefaultWriter/releaseLock) */ 2407 | releaseLock(): void; 2408 | } 2409 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStream) */ 2410 | declare class TransformStream<I = any, O = any> { 2411 | constructor( 2412 | transformer?: Transformer<I, O>, 2413 | writableStrategy?: QueuingStrategy<I>, 2414 | readableStrategy?: QueuingStrategy<O> 2415 | ); 2416 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStream/readable) */ 2417 | get readable(): ReadableStream<O>; 2418 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TransformStream/writable) */ 2419 | get writable(): WritableStream<I>; 2420 | } 2421 | declare class FixedLengthStream extends IdentityTransformStream { 2422 | constructor( 2423 | expectedLength: number | bigint, 2424 | queuingStrategy?: IdentityTransformStreamQueuingStrategy 2425 | ); 2426 | } 2427 | declare class IdentityTransformStream extends TransformStream< 2428 | ArrayBuffer | ArrayBufferView, 2429 | Uint8Array 2430 | > { 2431 | constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy); 2432 | } 2433 | interface IdentityTransformStreamQueuingStrategy { 2434 | highWaterMark?: number | bigint; 2435 | } 2436 | interface ReadableStreamValuesOptions { 2437 | preventCancel?: boolean; 2438 | } 2439 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CompressionStream) */ 2440 | declare class CompressionStream extends TransformStream< 2441 | ArrayBuffer | ArrayBufferView, 2442 | Uint8Array 2443 | > { 2444 | constructor(format: 'gzip' | 'deflate' | 'deflate-raw'); 2445 | } 2446 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DecompressionStream) */ 2447 | declare class DecompressionStream extends TransformStream< 2448 | ArrayBuffer | ArrayBufferView, 2449 | Uint8Array 2450 | > { 2451 | constructor(format: 'gzip' | 'deflate' | 'deflate-raw'); 2452 | } 2453 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextEncoderStream) */ 2454 | declare class TextEncoderStream extends TransformStream<string, Uint8Array> { 2455 | constructor(); 2456 | get encoding(): string; 2457 | } 2458 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/TextDecoderStream) */ 2459 | declare class TextDecoderStream extends TransformStream< 2460 | ArrayBuffer | ArrayBufferView, 2461 | string 2462 | > { 2463 | constructor(label?: string, options?: TextDecoderStreamTextDecoderStreamInit); 2464 | get encoding(): string; 2465 | get fatal(): boolean; 2466 | get ignoreBOM(): boolean; 2467 | } 2468 | interface TextDecoderStreamTextDecoderStreamInit { 2469 | fatal?: boolean; 2470 | ignoreBOM?: boolean; 2471 | } 2472 | /** 2473 | * This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. 2474 | * 2475 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ByteLengthQueuingStrategy) 2476 | */ 2477 | declare class ByteLengthQueuingStrategy 2478 | implements QueuingStrategy<ArrayBufferView> 2479 | { 2480 | constructor(init: QueuingStrategyInit); 2481 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ByteLengthQueuingStrategy/highWaterMark) */ 2482 | get highWaterMark(): number; 2483 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/ByteLengthQueuingStrategy/size) */ 2484 | get size(): (chunk?: any) => number; 2485 | } 2486 | /** 2487 | * This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. 2488 | * 2489 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CountQueuingStrategy) 2490 | */ 2491 | declare class CountQueuingStrategy implements QueuingStrategy { 2492 | constructor(init: QueuingStrategyInit); 2493 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CountQueuingStrategy/highWaterMark) */ 2494 | get highWaterMark(): number; 2495 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/CountQueuingStrategy/size) */ 2496 | get size(): (chunk?: any) => number; 2497 | } 2498 | interface QueuingStrategyInit { 2499 | /** 2500 | * Creates a new ByteLengthQueuingStrategy with the provided high water mark. 2501 | * 2502 | * Note that the provided high water mark will not be validated ahead of time. Instead, if it is negative, NaN, or not a number, the resulting ByteLengthQueuingStrategy will cause the corresponding stream constructor to throw. 2503 | */ 2504 | highWaterMark: number; 2505 | } 2506 | interface ScriptVersion { 2507 | id?: string; 2508 | tag?: string; 2509 | message?: string; 2510 | } 2511 | declare abstract class TailEvent extends ExtendableEvent { 2512 | readonly events: TraceItem[]; 2513 | readonly traces: TraceItem[]; 2514 | } 2515 | interface TraceItem { 2516 | readonly event: 2517 | | ( 2518 | | TraceItemFetchEventInfo 2519 | | TraceItemJsRpcEventInfo 2520 | | TraceItemScheduledEventInfo 2521 | | TraceItemAlarmEventInfo 2522 | | TraceItemQueueEventInfo 2523 | | TraceItemEmailEventInfo 2524 | | TraceItemTailEventInfo 2525 | | TraceItemCustomEventInfo 2526 | | TraceItemHibernatableWebSocketEventInfo 2527 | ) 2528 | | null; 2529 | readonly eventTimestamp: number | null; 2530 | readonly logs: TraceLog[]; 2531 | readonly exceptions: TraceException[]; 2532 | readonly diagnosticsChannelEvents: TraceDiagnosticChannelEvent[]; 2533 | readonly scriptName: string | null; 2534 | readonly entrypoint?: string; 2535 | readonly scriptVersion?: ScriptVersion; 2536 | readonly dispatchNamespace?: string; 2537 | readonly scriptTags?: string[]; 2538 | readonly outcome: string; 2539 | readonly executionModel: string; 2540 | readonly truncated: boolean; 2541 | readonly cpuTime: number; 2542 | readonly wallTime: number; 2543 | } 2544 | interface TraceItemAlarmEventInfo { 2545 | readonly scheduledTime: Date; 2546 | } 2547 | interface TraceItemCustomEventInfo {} 2548 | interface TraceItemScheduledEventInfo { 2549 | readonly scheduledTime: number; 2550 | readonly cron: string; 2551 | } 2552 | interface TraceItemQueueEventInfo { 2553 | readonly queue: string; 2554 | readonly batchSize: number; 2555 | } 2556 | interface TraceItemEmailEventInfo { 2557 | readonly mailFrom: string; 2558 | readonly rcptTo: string; 2559 | readonly rawSize: number; 2560 | } 2561 | interface TraceItemTailEventInfo { 2562 | readonly consumedEvents: TraceItemTailEventInfoTailItem[]; 2563 | } 2564 | interface TraceItemTailEventInfoTailItem { 2565 | readonly scriptName: string | null; 2566 | } 2567 | interface TraceItemFetchEventInfo { 2568 | readonly response?: TraceItemFetchEventInfoResponse; 2569 | readonly request: TraceItemFetchEventInfoRequest; 2570 | } 2571 | interface TraceItemFetchEventInfoRequest { 2572 | readonly cf?: any; 2573 | readonly headers: Record<string, string>; 2574 | readonly method: string; 2575 | readonly url: string; 2576 | getUnredacted(): TraceItemFetchEventInfoRequest; 2577 | } 2578 | interface TraceItemFetchEventInfoResponse { 2579 | readonly status: number; 2580 | } 2581 | interface TraceItemJsRpcEventInfo { 2582 | readonly rpcMethod: string; 2583 | } 2584 | interface TraceItemHibernatableWebSocketEventInfo { 2585 | readonly getWebSocketEvent: 2586 | | TraceItemHibernatableWebSocketEventInfoMessage 2587 | | TraceItemHibernatableWebSocketEventInfoClose 2588 | | TraceItemHibernatableWebSocketEventInfoError; 2589 | } 2590 | interface TraceItemHibernatableWebSocketEventInfoMessage { 2591 | readonly webSocketEventType: string; 2592 | } 2593 | interface TraceItemHibernatableWebSocketEventInfoClose { 2594 | readonly webSocketEventType: string; 2595 | readonly code: number; 2596 | readonly wasClean: boolean; 2597 | } 2598 | interface TraceItemHibernatableWebSocketEventInfoError { 2599 | readonly webSocketEventType: string; 2600 | } 2601 | interface TraceLog { 2602 | readonly timestamp: number; 2603 | readonly level: string; 2604 | readonly message: any; 2605 | } 2606 | interface TraceException { 2607 | readonly timestamp: number; 2608 | readonly message: string; 2609 | readonly name: string; 2610 | readonly stack?: string; 2611 | } 2612 | interface TraceDiagnosticChannelEvent { 2613 | readonly timestamp: number; 2614 | readonly channel: string; 2615 | readonly message: any; 2616 | } 2617 | interface TraceMetrics { 2618 | readonly cpuTime: number; 2619 | readonly wallTime: number; 2620 | } 2621 | interface UnsafeTraceMetrics { 2622 | fromTrace(item: TraceItem): TraceMetrics; 2623 | } 2624 | /** 2625 | * The URL interface represents an object providing static methods used for creating object URLs. 2626 | * 2627 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL) 2628 | */ 2629 | declare class URL { 2630 | constructor(url: string | URL, base?: string | URL); 2631 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/origin) */ 2632 | get origin(): string; 2633 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/href) */ 2634 | get href(): string; 2635 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/href) */ 2636 | set href(value: string); 2637 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/protocol) */ 2638 | get protocol(): string; 2639 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/protocol) */ 2640 | set protocol(value: string); 2641 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/username) */ 2642 | get username(): string; 2643 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/username) */ 2644 | set username(value: string); 2645 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/password) */ 2646 | get password(): string; 2647 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/password) */ 2648 | set password(value: string); 2649 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/host) */ 2650 | get host(): string; 2651 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/host) */ 2652 | set host(value: string); 2653 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hostname) */ 2654 | get hostname(): string; 2655 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hostname) */ 2656 | set hostname(value: string); 2657 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/port) */ 2658 | get port(): string; 2659 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/port) */ 2660 | set port(value: string); 2661 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname) */ 2662 | get pathname(): string; 2663 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname) */ 2664 | set pathname(value: string); 2665 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/search) */ 2666 | get search(): string; 2667 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/search) */ 2668 | set search(value: string); 2669 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hash) */ 2670 | get hash(): string; 2671 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/hash) */ 2672 | set hash(value: string); 2673 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/searchParams) */ 2674 | get searchParams(): URLSearchParams; 2675 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/toJSON) */ 2676 | toJSON(): string; 2677 | /*function toString() { [native code] }*/ 2678 | toString(): string; 2679 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/canParse_static) */ 2680 | static canParse(url: string, base?: string): boolean; 2681 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/parse_static) */ 2682 | static parse(url: string, base?: string): URL | null; 2683 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static) */ 2684 | static createObjectURL(object: File | Blob): string; 2685 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static) */ 2686 | static revokeObjectURL(object_url: string): void; 2687 | } 2688 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams) */ 2689 | declare class URLSearchParams { 2690 | constructor( 2691 | init?: Iterable<Iterable<string>> | Record<string, string> | string 2692 | ); 2693 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/size) */ 2694 | get size(): number; 2695 | /** 2696 | * Appends a specified key/value pair as a new search parameter. 2697 | * 2698 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/append) 2699 | */ 2700 | append(name: string, value: string): void; 2701 | /** 2702 | * Deletes the given search parameter, and its associated value, from the list of all search parameters. 2703 | * 2704 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/delete) 2705 | */ 2706 | delete(name: string, value?: string): void; 2707 | /** 2708 | * Returns the first value associated to the given search parameter. 2709 | * 2710 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/get) 2711 | */ 2712 | get(name: string): string | null; 2713 | /** 2714 | * Returns all the values association with a given search parameter. 2715 | * 2716 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll) 2717 | */ 2718 | getAll(name: string): string[]; 2719 | /** 2720 | * Returns a Boolean indicating if such a search parameter exists. 2721 | * 2722 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/has) 2723 | */ 2724 | has(name: string, value?: string): boolean; 2725 | /** 2726 | * Sets the value associated to a given search parameter to the given value. If there were several values, delete the others. 2727 | * 2728 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/set) 2729 | */ 2730 | set(name: string, value: string): void; 2731 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/sort) */ 2732 | sort(): void; 2733 | /* Returns an array of key, value pairs for every entry in the search params. */ 2734 | entries(): IterableIterator<[key: string, value: string]>; 2735 | /* Returns a list of keys in the search params. */ 2736 | keys(): IterableIterator<string>; 2737 | /* Returns a list of values in the search params. */ 2738 | values(): IterableIterator<string>; 2739 | forEach<This = unknown>( 2740 | callback: ( 2741 | this: This, 2742 | value: string, 2743 | key: string, 2744 | parent: URLSearchParams 2745 | ) => void, 2746 | thisArg?: This 2747 | ): void; 2748 | /*function toString() { [native code] } Returns a string containing a query string suitable for use in a URL. Does not include the question mark. */ 2749 | toString(): string; 2750 | [Symbol.iterator](): IterableIterator<[key: string, value: string]>; 2751 | } 2752 | declare class URLPattern { 2753 | constructor( 2754 | input?: string | URLPatternInit, 2755 | baseURL?: string | URLPatternOptions, 2756 | patternOptions?: URLPatternOptions 2757 | ); 2758 | get protocol(): string; 2759 | get username(): string; 2760 | get password(): string; 2761 | get hostname(): string; 2762 | get port(): string; 2763 | get pathname(): string; 2764 | get search(): string; 2765 | get hash(): string; 2766 | test(input?: string | URLPatternInit, baseURL?: string): boolean; 2767 | exec( 2768 | input?: string | URLPatternInit, 2769 | baseURL?: string 2770 | ): URLPatternResult | null; 2771 | } 2772 | interface URLPatternInit { 2773 | protocol?: string; 2774 | username?: string; 2775 | password?: string; 2776 | hostname?: string; 2777 | port?: string; 2778 | pathname?: string; 2779 | search?: string; 2780 | hash?: string; 2781 | baseURL?: string; 2782 | } 2783 | interface URLPatternComponentResult { 2784 | input: string; 2785 | groups: Record<string, string>; 2786 | } 2787 | interface URLPatternResult { 2788 | inputs: (string | URLPatternInit)[]; 2789 | protocol: URLPatternComponentResult; 2790 | username: URLPatternComponentResult; 2791 | password: URLPatternComponentResult; 2792 | hostname: URLPatternComponentResult; 2793 | port: URLPatternComponentResult; 2794 | pathname: URLPatternComponentResult; 2795 | search: URLPatternComponentResult; 2796 | hash: URLPatternComponentResult; 2797 | } 2798 | interface URLPatternOptions { 2799 | ignoreCase?: boolean; 2800 | } 2801 | /** 2802 | * A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute. 2803 | * 2804 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent) 2805 | */ 2806 | declare class CloseEvent extends Event { 2807 | constructor(type: string, initializer?: CloseEventInit); 2808 | /** 2809 | * Returns the WebSocket connection close code provided by the server. 2810 | * 2811 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/code) 2812 | */ 2813 | readonly code: number; 2814 | /** 2815 | * Returns the WebSocket connection close reason provided by the server. 2816 | * 2817 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/reason) 2818 | */ 2819 | readonly reason: string; 2820 | /** 2821 | * Returns true if the connection closed cleanly; false otherwise. 2822 | * 2823 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CloseEvent/wasClean) 2824 | */ 2825 | readonly wasClean: boolean; 2826 | } 2827 | interface CloseEventInit { 2828 | code?: number; 2829 | reason?: string; 2830 | wasClean?: boolean; 2831 | } 2832 | /** 2833 | * A message received by a target object. 2834 | * 2835 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent) 2836 | */ 2837 | declare class MessageEvent extends Event { 2838 | constructor(type: string, initializer: MessageEventInit); 2839 | /** 2840 | * Returns the data of the message. 2841 | * 2842 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/MessageEvent/data) 2843 | */ 2844 | readonly data: ArrayBuffer | string; 2845 | } 2846 | interface MessageEventInit { 2847 | data: ArrayBuffer | string; 2848 | } 2849 | type WebSocketEventMap = { 2850 | close: CloseEvent; 2851 | message: MessageEvent; 2852 | open: Event; 2853 | error: ErrorEvent; 2854 | }; 2855 | /** 2856 | * Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. 2857 | * 2858 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket) 2859 | */ 2860 | declare var WebSocket: { 2861 | prototype: WebSocket; 2862 | new (url: string, protocols?: string[] | string): WebSocket; 2863 | readonly READY_STATE_CONNECTING: number; 2864 | readonly CONNECTING: number; 2865 | readonly READY_STATE_OPEN: number; 2866 | readonly OPEN: number; 2867 | readonly READY_STATE_CLOSING: number; 2868 | readonly CLOSING: number; 2869 | readonly READY_STATE_CLOSED: number; 2870 | readonly CLOSED: number; 2871 | }; 2872 | /** 2873 | * Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. 2874 | * 2875 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket) 2876 | */ 2877 | interface WebSocket extends EventTarget<WebSocketEventMap> { 2878 | accept(): void; 2879 | /** 2880 | * Transmits data using the WebSocket connection. data can be a string, a Blob, an ArrayBuffer, or an ArrayBufferView. 2881 | * 2882 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/send) 2883 | */ 2884 | send(message: (ArrayBuffer | ArrayBufferView) | string): void; 2885 | /** 2886 | * Closes the WebSocket connection, optionally using code as the the WebSocket connection close code and reason as the the WebSocket connection close reason. 2887 | * 2888 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/close) 2889 | */ 2890 | close(code?: number, reason?: string): void; 2891 | serializeAttachment(attachment: any): void; 2892 | deserializeAttachment(): any | null; 2893 | /** 2894 | * Returns the state of the WebSocket object's connection. It can have the values described below. 2895 | * 2896 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/readyState) 2897 | */ 2898 | readyState: number; 2899 | /** 2900 | * Returns the URL that was used to establish the WebSocket connection. 2901 | * 2902 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/url) 2903 | */ 2904 | url: string | null; 2905 | /** 2906 | * Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation. 2907 | * 2908 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/protocol) 2909 | */ 2910 | protocol: string | null; 2911 | /** 2912 | * Returns the extensions selected by the server, if any. 2913 | * 2914 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/WebSocket/extensions) 2915 | */ 2916 | extensions: string | null; 2917 | } 2918 | declare const WebSocketPair: { 2919 | new (): { 2920 | 0: WebSocket; 2921 | 1: WebSocket; 2922 | }; 2923 | }; 2924 | interface SqlStorage { 2925 | exec<T extends Record<string, SqlStorageValue>>( 2926 | query: string, 2927 | ...bindings: any[] 2928 | ): SqlStorageCursor<T>; 2929 | get databaseSize(): number; 2930 | Cursor: typeof SqlStorageCursor; 2931 | Statement: typeof SqlStorageStatement; 2932 | } 2933 | declare abstract class SqlStorageStatement {} 2934 | type SqlStorageValue = ArrayBuffer | string | number | null; 2935 | declare abstract class SqlStorageCursor< 2936 | T extends Record<string, SqlStorageValue>, 2937 | > { 2938 | next(): 2939 | | { 2940 | done?: false; 2941 | value: T; 2942 | } 2943 | | { 2944 | done: true; 2945 | value?: never; 2946 | }; 2947 | toArray(): T[]; 2948 | one(): T; 2949 | raw<U extends SqlStorageValue[]>(): IterableIterator<U>; 2950 | columnNames: string[]; 2951 | get rowsRead(): number; 2952 | get rowsWritten(): number; 2953 | [Symbol.iterator](): IterableIterator<T>; 2954 | } 2955 | interface Socket { 2956 | get readable(): ReadableStream; 2957 | get writable(): WritableStream; 2958 | get closed(): Promise<void>; 2959 | get opened(): Promise<SocketInfo>; 2960 | get upgraded(): boolean; 2961 | get secureTransport(): 'on' | 'off' | 'starttls'; 2962 | close(): Promise<void>; 2963 | startTls(options?: TlsOptions): Socket; 2964 | } 2965 | interface SocketOptions { 2966 | secureTransport?: string; 2967 | allowHalfOpen: boolean; 2968 | highWaterMark?: number | bigint; 2969 | } 2970 | interface SocketAddress { 2971 | hostname: string; 2972 | port: number; 2973 | } 2974 | interface TlsOptions { 2975 | expectedServerHostname?: string; 2976 | } 2977 | interface SocketInfo { 2978 | remoteAddress?: string; 2979 | localAddress?: string; 2980 | } 2981 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */ 2982 | declare class EventSource extends EventTarget { 2983 | constructor(url: string, init?: EventSourceEventSourceInit); 2984 | /** 2985 | * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED. 2986 | * 2987 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close) 2988 | */ 2989 | close(): void; 2990 | /** 2991 | * Returns the URL providing the event stream. 2992 | * 2993 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url) 2994 | */ 2995 | get url(): string; 2996 | /** 2997 | * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise. 2998 | * 2999 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials) 3000 | */ 3001 | get withCredentials(): boolean; 3002 | /** 3003 | * Returns the state of this EventSource object's connection. It can have the values described below. 3004 | * 3005 | * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState) 3006 | */ 3007 | get readyState(): number; 3008 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */ 3009 | get onopen(): any | null; 3010 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */ 3011 | set onopen(value: any | null); 3012 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */ 3013 | get onmessage(): any | null; 3014 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */ 3015 | set onmessage(value: any | null); 3016 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */ 3017 | get onerror(): any | null; 3018 | /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */ 3019 | set onerror(value: any | null); 3020 | static readonly CONNECTING: number; 3021 | static readonly OPEN: number; 3022 | static readonly CLOSED: number; 3023 | static from(stream: ReadableStream): EventSource; 3024 | } 3025 | interface EventSourceEventSourceInit { 3026 | withCredentials?: boolean; 3027 | fetcher?: Fetcher; 3028 | } 3029 | interface Container { 3030 | get running(): boolean; 3031 | start(options?: ContainerStartupOptions): void; 3032 | monitor(): Promise<void>; 3033 | destroy(error?: any): Promise<void>; 3034 | signal(signo: number): void; 3035 | getTcpPort(port: number): Fetcher; 3036 | } 3037 | interface ContainerStartupOptions { 3038 | entrypoint?: string[]; 3039 | enableInternet: boolean; 3040 | env?: Record<string, string>; 3041 | } 3042 | type AiImageClassificationInput = { 3043 | image: number[]; 3044 | }; 3045 | type AiImageClassificationOutput = { 3046 | score?: number; 3047 | label?: string; 3048 | }[]; 3049 | declare abstract class BaseAiImageClassification { 3050 | inputs: AiImageClassificationInput; 3051 | postProcessedOutputs: AiImageClassificationOutput; 3052 | } 3053 | type AiImageToTextInput = { 3054 | image: number[]; 3055 | prompt?: string; 3056 | max_tokens?: number; 3057 | temperature?: number; 3058 | top_p?: number; 3059 | top_k?: number; 3060 | seed?: number; 3061 | repetition_penalty?: number; 3062 | frequency_penalty?: number; 3063 | presence_penalty?: number; 3064 | raw?: boolean; 3065 | messages?: RoleScopedChatInput[]; 3066 | }; 3067 | type AiImageToTextOutput = { 3068 | description: string; 3069 | }; 3070 | declare abstract class BaseAiImageToText { 3071 | inputs: AiImageToTextInput; 3072 | postProcessedOutputs: AiImageToTextOutput; 3073 | } 3074 | type AiImageTextToTextInput = { 3075 | image: string; 3076 | prompt?: string; 3077 | max_tokens?: number; 3078 | temperature?: number; 3079 | ignore_eos?: boolean; 3080 | top_p?: number; 3081 | top_k?: number; 3082 | seed?: number; 3083 | repetition_penalty?: number; 3084 | frequency_penalty?: number; 3085 | presence_penalty?: number; 3086 | raw?: boolean; 3087 | messages?: RoleScopedChatInput[]; 3088 | }; 3089 | type AiImageTextToTextOutput = { 3090 | description: string; 3091 | }; 3092 | declare abstract class BaseAiImageTextToText { 3093 | inputs: AiImageTextToTextInput; 3094 | postProcessedOutputs: AiImageTextToTextOutput; 3095 | } 3096 | type AiObjectDetectionInput = { 3097 | image: number[]; 3098 | }; 3099 | type AiObjectDetectionOutput = { 3100 | score?: number; 3101 | label?: string; 3102 | }[]; 3103 | declare abstract class BaseAiObjectDetection { 3104 | inputs: AiObjectDetectionInput; 3105 | postProcessedOutputs: AiObjectDetectionOutput; 3106 | } 3107 | type AiSentenceSimilarityInput = { 3108 | source: string; 3109 | sentences: string[]; 3110 | }; 3111 | type AiSentenceSimilarityOutput = number[]; 3112 | declare abstract class BaseAiSentenceSimilarity { 3113 | inputs: AiSentenceSimilarityInput; 3114 | postProcessedOutputs: AiSentenceSimilarityOutput; 3115 | } 3116 | type AiAutomaticSpeechRecognitionInput = { 3117 | audio: number[]; 3118 | }; 3119 | type AiAutomaticSpeechRecognitionOutput = { 3120 | text?: string; 3121 | words?: { 3122 | word: string; 3123 | start: number; 3124 | end: number; 3125 | }[]; 3126 | vtt?: string; 3127 | }; 3128 | declare abstract class BaseAiAutomaticSpeechRecognition { 3129 | inputs: AiAutomaticSpeechRecognitionInput; 3130 | postProcessedOutputs: AiAutomaticSpeechRecognitionOutput; 3131 | } 3132 | type AiSummarizationInput = { 3133 | input_text: string; 3134 | max_length?: number; 3135 | }; 3136 | type AiSummarizationOutput = { 3137 | summary: string; 3138 | }; 3139 | declare abstract class BaseAiSummarization { 3140 | inputs: AiSummarizationInput; 3141 | postProcessedOutputs: AiSummarizationOutput; 3142 | } 3143 | type AiTextClassificationInput = { 3144 | text: string; 3145 | }; 3146 | type AiTextClassificationOutput = { 3147 | score?: number; 3148 | label?: string; 3149 | }[]; 3150 | declare abstract class BaseAiTextClassification { 3151 | inputs: AiTextClassificationInput; 3152 | postProcessedOutputs: AiTextClassificationOutput; 3153 | } 3154 | type AiTextEmbeddingsInput = { 3155 | text: string | string[]; 3156 | }; 3157 | type AiTextEmbeddingsOutput = { 3158 | shape: number[]; 3159 | data: number[][]; 3160 | }; 3161 | declare abstract class BaseAiTextEmbeddings { 3162 | inputs: AiTextEmbeddingsInput; 3163 | postProcessedOutputs: AiTextEmbeddingsOutput; 3164 | } 3165 | type RoleScopedChatInput = { 3166 | role: 3167 | | 'user' 3168 | | 'assistant' 3169 | | 'system' 3170 | | 'tool' 3171 | | (string & NonNullable<unknown>); 3172 | content: string; 3173 | name?: string; 3174 | }; 3175 | type AiTextGenerationToolLegacyInput = { 3176 | name: string; 3177 | description: string; 3178 | parameters?: { 3179 | type: 'object' | (string & NonNullable<unknown>); 3180 | properties: { 3181 | [key: string]: { 3182 | type: string; 3183 | description?: string; 3184 | }; 3185 | }; 3186 | required: string[]; 3187 | }; 3188 | }; 3189 | type AiTextGenerationToolInput = { 3190 | type: 'function' | (string & NonNullable<unknown>); 3191 | function: { 3192 | name: string; 3193 | description: string; 3194 | parameters?: { 3195 | type: 'object' | (string & NonNullable<unknown>); 3196 | properties: { 3197 | [key: string]: { 3198 | type: string; 3199 | description?: string; 3200 | }; 3201 | }; 3202 | required: string[]; 3203 | }; 3204 | }; 3205 | }; 3206 | type AiTextGenerationFunctionsInput = { 3207 | name: string; 3208 | code: string; 3209 | }; 3210 | type AiTextGenerationResponseFormat = { 3211 | type: string; 3212 | json_schema?: any; 3213 | }; 3214 | type AiTextGenerationInput = { 3215 | prompt?: string; 3216 | raw?: boolean; 3217 | stream?: boolean; 3218 | max_tokens?: number; 3219 | temperature?: number; 3220 | top_p?: number; 3221 | top_k?: number; 3222 | seed?: number; 3223 | repetition_penalty?: number; 3224 | frequency_penalty?: number; 3225 | presence_penalty?: number; 3226 | messages?: RoleScopedChatInput[]; 3227 | response_format?: AiTextGenerationResponseFormat; 3228 | tools?: 3229 | | AiTextGenerationToolInput[] 3230 | | AiTextGenerationToolLegacyInput[] 3231 | | (object & NonNullable<unknown>); 3232 | functions?: AiTextGenerationFunctionsInput[]; 3233 | }; 3234 | type AiTextGenerationOutput = 3235 | | { 3236 | response?: string; 3237 | tool_calls?: { 3238 | name: string; 3239 | arguments: unknown; 3240 | }[]; 3241 | } 3242 | | ReadableStream; 3243 | declare abstract class BaseAiTextGeneration { 3244 | inputs: AiTextGenerationInput; 3245 | postProcessedOutputs: AiTextGenerationOutput; 3246 | } 3247 | type AiTextToSpeechInput = { 3248 | prompt: string; 3249 | lang?: string; 3250 | }; 3251 | type AiTextToSpeechOutput = 3252 | | Uint8Array 3253 | | { 3254 | audio: string; 3255 | }; 3256 | declare abstract class BaseAiTextToSpeech { 3257 | inputs: AiTextToSpeechInput; 3258 | postProcessedOutputs: AiTextToSpeechOutput; 3259 | } 3260 | type AiTextToImageInput = { 3261 | prompt: string; 3262 | negative_prompt?: string; 3263 | height?: number; 3264 | width?: number; 3265 | image?: number[]; 3266 | image_b64?: string; 3267 | mask?: number[]; 3268 | num_steps?: number; 3269 | strength?: number; 3270 | guidance?: number; 3271 | seed?: number; 3272 | }; 3273 | type AiTextToImageOutput = ReadableStream<Uint8Array>; 3274 | declare abstract class BaseAiTextToImage { 3275 | inputs: AiTextToImageInput; 3276 | postProcessedOutputs: AiTextToImageOutput; 3277 | } 3278 | type AiTranslationInput = { 3279 | text: string; 3280 | target_lang: string; 3281 | source_lang?: string; 3282 | }; 3283 | type AiTranslationOutput = { 3284 | translated_text?: string; 3285 | }; 3286 | declare abstract class BaseAiTranslation { 3287 | inputs: AiTranslationInput; 3288 | postProcessedOutputs: AiTranslationOutput; 3289 | } 3290 | type Ai_Cf_Openai_Whisper_Input = 3291 | | string 3292 | | { 3293 | /** 3294 | * An array of integers that represent the audio data constrained to 8-bit unsigned integer values 3295 | */ 3296 | audio: number[]; 3297 | }; 3298 | interface Ai_Cf_Openai_Whisper_Output { 3299 | /** 3300 | * The transcription 3301 | */ 3302 | text: string; 3303 | word_count?: number; 3304 | words?: { 3305 | word?: string; 3306 | /** 3307 | * The second this word begins in the recording 3308 | */ 3309 | start?: number; 3310 | /** 3311 | * The ending second when the word completes 3312 | */ 3313 | end?: number; 3314 | }[]; 3315 | vtt?: string; 3316 | } 3317 | declare abstract class Base_Ai_Cf_Openai_Whisper { 3318 | inputs: Ai_Cf_Openai_Whisper_Input; 3319 | postProcessedOutputs: Ai_Cf_Openai_Whisper_Output; 3320 | } 3321 | type Ai_Cf_Unum_Uform_Gen2_Qwen_500M_Input = 3322 | | string 3323 | | { 3324 | /** 3325 | * The input text prompt for the model to generate a response. 3326 | */ 3327 | prompt?: string; 3328 | /** 3329 | * If true, a chat template is not applied and you must adhere to the specific model's expected formatting. 3330 | */ 3331 | raw?: boolean; 3332 | /** 3333 | * Controls the creativity of the AI's responses by adjusting how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses. 3334 | */ 3335 | top_p?: number; 3336 | /** 3337 | * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises. 3338 | */ 3339 | top_k?: number; 3340 | /** 3341 | * Random seed for reproducibility of the generation. 3342 | */ 3343 | seed?: number; 3344 | /** 3345 | * Penalty for repeated tokens; higher values discourage repetition. 3346 | */ 3347 | repetition_penalty?: number; 3348 | /** 3349 | * Decreases the likelihood of the model repeating the same lines verbatim. 3350 | */ 3351 | frequency_penalty?: number; 3352 | /** 3353 | * Increases the likelihood of the model introducing new topics. 3354 | */ 3355 | presence_penalty?: number; 3356 | image: number[] | (string & NonNullable<unknown>); 3357 | /** 3358 | * The maximum number of tokens to generate in the response. 3359 | */ 3360 | max_tokens?: number; 3361 | }; 3362 | interface Ai_Cf_Unum_Uform_Gen2_Qwen_500M_Output { 3363 | description?: string; 3364 | } 3365 | declare abstract class Base_Ai_Cf_Unum_Uform_Gen2_Qwen_500M { 3366 | inputs: Ai_Cf_Unum_Uform_Gen2_Qwen_500M_Input; 3367 | postProcessedOutputs: Ai_Cf_Unum_Uform_Gen2_Qwen_500M_Output; 3368 | } 3369 | type Ai_Cf_Openai_Whisper_Tiny_En_Input = 3370 | | string 3371 | | { 3372 | /** 3373 | * An array of integers that represent the audio data constrained to 8-bit unsigned integer values 3374 | */ 3375 | audio: number[]; 3376 | }; 3377 | interface Ai_Cf_Openai_Whisper_Tiny_En_Output { 3378 | /** 3379 | * The transcription 3380 | */ 3381 | text: string; 3382 | word_count?: number; 3383 | words?: { 3384 | word?: string; 3385 | /** 3386 | * The second this word begins in the recording 3387 | */ 3388 | start?: number; 3389 | /** 3390 | * The ending second when the word completes 3391 | */ 3392 | end?: number; 3393 | }[]; 3394 | vtt?: string; 3395 | } 3396 | declare abstract class Base_Ai_Cf_Openai_Whisper_Tiny_En { 3397 | inputs: Ai_Cf_Openai_Whisper_Tiny_En_Input; 3398 | postProcessedOutputs: Ai_Cf_Openai_Whisper_Tiny_En_Output; 3399 | } 3400 | interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input { 3401 | /** 3402 | * Base64 encoded value of the audio data. 3403 | */ 3404 | audio: string; 3405 | /** 3406 | * Supported tasks are 'translate' or 'transcribe'. 3407 | */ 3408 | task?: string; 3409 | /** 3410 | * The language of the audio being transcribed or translated. 3411 | */ 3412 | language?: string; 3413 | /** 3414 | * Preprocess the audio with a voice activity detection model. 3415 | */ 3416 | vad_filter?: string; 3417 | /** 3418 | * A text prompt to help provide context to the model on the contents of the audio. 3419 | */ 3420 | initial_prompt?: string; 3421 | /** 3422 | * The prefix it appended the the beginning of the output of the transcription and can guide the transcription result. 3423 | */ 3424 | prefix?: string; 3425 | } 3426 | interface Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output { 3427 | transcription_info?: { 3428 | /** 3429 | * The language of the audio being transcribed or translated. 3430 | */ 3431 | language?: string; 3432 | /** 3433 | * The confidence level or probability of the detected language being accurate, represented as a decimal between 0 and 1. 3434 | */ 3435 | language_probability?: number; 3436 | /** 3437 | * The total duration of the original audio file, in seconds. 3438 | */ 3439 | duration?: number; 3440 | /** 3441 | * The duration of the audio after applying Voice Activity Detection (VAD) to remove silent or irrelevant sections, in seconds. 3442 | */ 3443 | duration_after_vad?: number; 3444 | }; 3445 | /** 3446 | * The complete transcription of the audio. 3447 | */ 3448 | text: string; 3449 | /** 3450 | * The total number of words in the transcription. 3451 | */ 3452 | word_count?: number; 3453 | segments?: { 3454 | /** 3455 | * The starting time of the segment within the audio, in seconds. 3456 | */ 3457 | start?: number; 3458 | /** 3459 | * The ending time of the segment within the audio, in seconds. 3460 | */ 3461 | end?: number; 3462 | /** 3463 | * The transcription of the segment. 3464 | */ 3465 | text?: string; 3466 | /** 3467 | * The temperature used in the decoding process, controlling randomness in predictions. Lower values result in more deterministic outputs. 3468 | */ 3469 | temperature?: number; 3470 | /** 3471 | * The average log probability of the predictions for the words in this segment, indicating overall confidence. 3472 | */ 3473 | avg_logprob?: number; 3474 | /** 3475 | * The compression ratio of the input to the output, measuring how much the text was compressed during the transcription process. 3476 | */ 3477 | compression_ratio?: number; 3478 | /** 3479 | * The probability that the segment contains no speech, represented as a decimal between 0 and 1. 3480 | */ 3481 | no_speech_prob?: number; 3482 | words?: { 3483 | /** 3484 | * The individual word transcribed from the audio. 3485 | */ 3486 | word?: string; 3487 | /** 3488 | * The starting time of the word within the audio, in seconds. 3489 | */ 3490 | start?: number; 3491 | /** 3492 | * The ending time of the word within the audio, in seconds. 3493 | */ 3494 | end?: number; 3495 | }[]; 3496 | }[]; 3497 | /** 3498 | * The transcription in WebVTT format, which includes timing and text information for use in subtitles. 3499 | */ 3500 | vtt?: string; 3501 | } 3502 | declare abstract class Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo { 3503 | inputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Input; 3504 | postProcessedOutputs: Ai_Cf_Openai_Whisper_Large_V3_Turbo_Output; 3505 | } 3506 | type Ai_Cf_Baai_Bge_M3_Input = BGEM3InputQueryAndContexts | BGEM3InputEmbedding; 3507 | interface BGEM3InputQueryAndContexts { 3508 | /** 3509 | * A query you wish to perform against the provided contexts. If no query is provided the model with respond with embeddings for contexts 3510 | */ 3511 | query?: string; 3512 | /** 3513 | * List of provided contexts. Note that the index in this array is important, as the response will refer to it. 3514 | */ 3515 | contexts: { 3516 | /** 3517 | * One of the provided context content 3518 | */ 3519 | text?: string; 3520 | }[]; 3521 | /** 3522 | * When provided with too long context should the model error out or truncate the context to fit? 3523 | */ 3524 | truncate_inputs?: boolean; 3525 | } 3526 | interface BGEM3InputEmbedding { 3527 | text: string | string[]; 3528 | /** 3529 | * When provided with too long context should the model error out or truncate the context to fit? 3530 | */ 3531 | truncate_inputs?: boolean; 3532 | } 3533 | type Ai_Cf_Baai_Bge_M3_Output = 3534 | | BGEM3OuputQuery 3535 | | BGEM3OutputEmbeddingForContexts 3536 | | BGEM3OuputEmbedding; 3537 | interface BGEM3OuputQuery { 3538 | response?: { 3539 | /** 3540 | * Index of the context in the request 3541 | */ 3542 | id?: number; 3543 | /** 3544 | * Score of the context under the index. 3545 | */ 3546 | score?: number; 3547 | }[]; 3548 | } 3549 | interface BGEM3OutputEmbeddingForContexts { 3550 | response?: number[][]; 3551 | shape?: number[]; 3552 | /** 3553 | * The pooling method used in the embedding process. 3554 | */ 3555 | pooling?: 'mean' | 'cls'; 3556 | } 3557 | interface BGEM3OuputEmbedding { 3558 | shape?: number[]; 3559 | /** 3560 | * Embeddings of the requested text values 3561 | */ 3562 | data?: number[][]; 3563 | /** 3564 | * The pooling method used in the embedding process. 3565 | */ 3566 | pooling?: 'mean' | 'cls'; 3567 | } 3568 | declare abstract class Base_Ai_Cf_Baai_Bge_M3 { 3569 | inputs: Ai_Cf_Baai_Bge_M3_Input; 3570 | postProcessedOutputs: Ai_Cf_Baai_Bge_M3_Output; 3571 | } 3572 | interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input { 3573 | /** 3574 | * A text description of the image you want to generate. 3575 | */ 3576 | prompt: string; 3577 | /** 3578 | * The number of diffusion steps; higher values can improve quality but take longer. 3579 | */ 3580 | steps?: number; 3581 | } 3582 | interface Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output { 3583 | /** 3584 | * The generated image in Base64 format. 3585 | */ 3586 | image?: string; 3587 | } 3588 | declare abstract class Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell { 3589 | inputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Input; 3590 | postProcessedOutputs: Ai_Cf_Black_Forest_Labs_Flux_1_Schnell_Output; 3591 | } 3592 | type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input = Prompt | Messages; 3593 | interface Prompt { 3594 | /** 3595 | * The input text prompt for the model to generate a response. 3596 | */ 3597 | prompt: string; 3598 | image?: number[] | (string & NonNullable<unknown>); 3599 | /** 3600 | * If true, a chat template is not applied and you must adhere to the specific model's expected formatting. 3601 | */ 3602 | raw?: boolean; 3603 | /** 3604 | * If true, the response will be streamed back incrementally using SSE, Server Sent Events. 3605 | */ 3606 | stream?: boolean; 3607 | /** 3608 | * The maximum number of tokens to generate in the response. 3609 | */ 3610 | max_tokens?: number; 3611 | /** 3612 | * Controls the randomness of the output; higher values produce more random results. 3613 | */ 3614 | temperature?: number; 3615 | /** 3616 | * Adjusts the creativity of the AI's responses by controlling how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses. 3617 | */ 3618 | top_p?: number; 3619 | /** 3620 | * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises. 3621 | */ 3622 | top_k?: number; 3623 | /** 3624 | * Random seed for reproducibility of the generation. 3625 | */ 3626 | seed?: number; 3627 | /** 3628 | * Penalty for repeated tokens; higher values discourage repetition. 3629 | */ 3630 | repetition_penalty?: number; 3631 | /** 3632 | * Decreases the likelihood of the model repeating the same lines verbatim. 3633 | */ 3634 | frequency_penalty?: number; 3635 | /** 3636 | * Increases the likelihood of the model introducing new topics. 3637 | */ 3638 | presence_penalty?: number; 3639 | /** 3640 | * Name of the LoRA (Low-Rank Adaptation) model to fine-tune the base model. 3641 | */ 3642 | lora?: string; 3643 | } 3644 | interface Messages { 3645 | /** 3646 | * An array of message objects representing the conversation history. 3647 | */ 3648 | messages: { 3649 | /** 3650 | * The role of the message sender (e.g., 'user', 'assistant', 'system', 'tool'). 3651 | */ 3652 | role: string; 3653 | /** 3654 | * The content of the message as a string. 3655 | */ 3656 | content: string; 3657 | }[]; 3658 | image?: number[] | string; 3659 | functions?: { 3660 | name: string; 3661 | code: string; 3662 | }[]; 3663 | /** 3664 | * A list of tools available for the assistant to use. 3665 | */ 3666 | tools?: ( 3667 | | { 3668 | /** 3669 | * The name of the tool. More descriptive the better. 3670 | */ 3671 | name: string; 3672 | /** 3673 | * A brief description of what the tool does. 3674 | */ 3675 | description: string; 3676 | /** 3677 | * Schema defining the parameters accepted by the tool. 3678 | */ 3679 | parameters: { 3680 | /** 3681 | * The type of the parameters object (usually 'object'). 3682 | */ 3683 | type: string; 3684 | /** 3685 | * List of required parameter names. 3686 | */ 3687 | required?: string[]; 3688 | /** 3689 | * Definitions of each parameter. 3690 | */ 3691 | properties: { 3692 | [k: string]: { 3693 | /** 3694 | * The data type of the parameter. 3695 | */ 3696 | type: string; 3697 | /** 3698 | * A description of the expected parameter. 3699 | */ 3700 | description: string; 3701 | }; 3702 | }; 3703 | }; 3704 | } 3705 | | { 3706 | /** 3707 | * Specifies the type of tool (e.g., 'function'). 3708 | */ 3709 | type: string; 3710 | /** 3711 | * Details of the function tool. 3712 | */ 3713 | function: { 3714 | /** 3715 | * The name of the function. 3716 | */ 3717 | name: string; 3718 | /** 3719 | * A brief description of what the function does. 3720 | */ 3721 | description: string; 3722 | /** 3723 | * Schema defining the parameters accepted by the function. 3724 | */ 3725 | parameters: { 3726 | /** 3727 | * The type of the parameters object (usually 'object'). 3728 | */ 3729 | type: string; 3730 | /** 3731 | * List of required parameter names. 3732 | */ 3733 | required?: string[]; 3734 | /** 3735 | * Definitions of each parameter. 3736 | */ 3737 | properties: { 3738 | [k: string]: { 3739 | /** 3740 | * The data type of the parameter. 3741 | */ 3742 | type: string; 3743 | /** 3744 | * A description of the expected parameter. 3745 | */ 3746 | description: string; 3747 | }; 3748 | }; 3749 | }; 3750 | }; 3751 | } 3752 | )[]; 3753 | /** 3754 | * If true, the response will be streamed back incrementally. 3755 | */ 3756 | stream?: boolean; 3757 | /** 3758 | * The maximum number of tokens to generate in the response. 3759 | */ 3760 | max_tokens?: number; 3761 | /** 3762 | * Controls the randomness of the output; higher values produce more random results. 3763 | */ 3764 | temperature?: number; 3765 | /** 3766 | * Controls the creativity of the AI's responses by adjusting how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses. 3767 | */ 3768 | top_p?: number; 3769 | /** 3770 | * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises. 3771 | */ 3772 | top_k?: number; 3773 | /** 3774 | * Random seed for reproducibility of the generation. 3775 | */ 3776 | seed?: number; 3777 | /** 3778 | * Penalty for repeated tokens; higher values discourage repetition. 3779 | */ 3780 | repetition_penalty?: number; 3781 | /** 3782 | * Decreases the likelihood of the model repeating the same lines verbatim. 3783 | */ 3784 | frequency_penalty?: number; 3785 | /** 3786 | * Increases the likelihood of the model introducing new topics. 3787 | */ 3788 | presence_penalty?: number; 3789 | } 3790 | type Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output = 3791 | | { 3792 | /** 3793 | * The generated text response from the model 3794 | */ 3795 | response?: string; 3796 | /** 3797 | * An array of tool calls requests made during the response generation 3798 | */ 3799 | tool_calls?: { 3800 | /** 3801 | * The arguments passed to be passed to the tool call request 3802 | */ 3803 | arguments?: object; 3804 | /** 3805 | * The name of the tool to be called 3806 | */ 3807 | name?: string; 3808 | }[]; 3809 | } 3810 | | ReadableStream; 3811 | declare abstract class Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct { 3812 | inputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Input; 3813 | postProcessedOutputs: Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct_Output; 3814 | } 3815 | interface Ai_Cf_Meta_Llama_Guard_3_8B_Input { 3816 | /** 3817 | * An array of message objects representing the conversation history. 3818 | */ 3819 | messages: { 3820 | /** 3821 | * The role of the message sender must alternate between 'user' and 'assistant'. 3822 | */ 3823 | role: 'user' | 'assistant'; 3824 | /** 3825 | * The content of the message as a string. 3826 | */ 3827 | content: string; 3828 | }[]; 3829 | /** 3830 | * The maximum number of tokens to generate in the response. 3831 | */ 3832 | max_tokens?: number; 3833 | /** 3834 | * Controls the randomness of the output; higher values produce more random results. 3835 | */ 3836 | temperature?: number; 3837 | /** 3838 | * Dictate the output format of the generated response. 3839 | */ 3840 | response_format?: { 3841 | /** 3842 | * Set to json_object to process and output generated text as JSON. 3843 | */ 3844 | type?: string; 3845 | }; 3846 | } 3847 | interface Ai_Cf_Meta_Llama_Guard_3_8B_Output { 3848 | response?: 3849 | | string 3850 | | { 3851 | /** 3852 | * Whether the conversation is safe or not. 3853 | */ 3854 | safe?: boolean; 3855 | /** 3856 | * A list of what hazard categories predicted for the conversation, if the conversation is deemed unsafe. 3857 | */ 3858 | categories?: string[]; 3859 | }; 3860 | /** 3861 | * Usage statistics for the inference request 3862 | */ 3863 | usage?: { 3864 | /** 3865 | * Total number of tokens in input 3866 | */ 3867 | prompt_tokens?: number; 3868 | /** 3869 | * Total number of tokens in output 3870 | */ 3871 | completion_tokens?: number; 3872 | /** 3873 | * Total number of input and output tokens 3874 | */ 3875 | total_tokens?: number; 3876 | }; 3877 | } 3878 | declare abstract class Base_Ai_Cf_Meta_Llama_Guard_3_8B { 3879 | inputs: Ai_Cf_Meta_Llama_Guard_3_8B_Input; 3880 | postProcessedOutputs: Ai_Cf_Meta_Llama_Guard_3_8B_Output; 3881 | } 3882 | interface Ai_Cf_Baai_Bge_Reranker_Base_Input { 3883 | /** 3884 | * A query you wish to perform against the provided contexts. 3885 | */ 3886 | /** 3887 | * Number of returned results starting with the best score. 3888 | */ 3889 | top_k?: number; 3890 | /** 3891 | * List of provided contexts. Note that the index in this array is important, as the response will refer to it. 3892 | */ 3893 | contexts: { 3894 | /** 3895 | * One of the provided context content 3896 | */ 3897 | text?: string; 3898 | }[]; 3899 | } 3900 | interface Ai_Cf_Baai_Bge_Reranker_Base_Output { 3901 | response?: { 3902 | /** 3903 | * Index of the context in the request 3904 | */ 3905 | id?: number; 3906 | /** 3907 | * Score of the context under the index. 3908 | */ 3909 | score?: number; 3910 | }[]; 3911 | } 3912 | declare abstract class Base_Ai_Cf_Baai_Bge_Reranker_Base { 3913 | inputs: Ai_Cf_Baai_Bge_Reranker_Base_Input; 3914 | postProcessedOutputs: Ai_Cf_Baai_Bge_Reranker_Base_Output; 3915 | } 3916 | type Ai_Cf_Meta_Llama_4_Scout_17B_16E_Instruct_Input = 3917 | | Ai_Cf_Meta_Llama_4_Prompt 3918 | | Ai_Cf_Meta_Llama_4_Messages; 3919 | interface Ai_Cf_Meta_Llama_4_Prompt { 3920 | /** 3921 | * The input text prompt for the model to generate a response. 3922 | */ 3923 | prompt: string; 3924 | /** 3925 | * JSON schema that should be fulfilled for the response. 3926 | */ 3927 | guided_json?: object; 3928 | /** 3929 | * If true, a chat template is not applied and you must adhere to the specific model's expected formatting. 3930 | */ 3931 | raw?: boolean; 3932 | /** 3933 | * If true, the response will be streamed back incrementally using SSE, Server Sent Events. 3934 | */ 3935 | stream?: boolean; 3936 | /** 3937 | * The maximum number of tokens to generate in the response. 3938 | */ 3939 | max_tokens?: number; 3940 | /** 3941 | * Controls the randomness of the output; higher values produce more random results. 3942 | */ 3943 | temperature?: number; 3944 | /** 3945 | * Adjusts the creativity of the AI's responses by controlling how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses. 3946 | */ 3947 | top_p?: number; 3948 | /** 3949 | * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises. 3950 | */ 3951 | top_k?: number; 3952 | /** 3953 | * Random seed for reproducibility of the generation. 3954 | */ 3955 | seed?: number; 3956 | /** 3957 | * Penalty for repeated tokens; higher values discourage repetition. 3958 | */ 3959 | repetition_penalty?: number; 3960 | /** 3961 | * Decreases the likelihood of the model repeating the same lines verbatim. 3962 | */ 3963 | frequency_penalty?: number; 3964 | /** 3965 | * Increases the likelihood of the model introducing new topics. 3966 | */ 3967 | presence_penalty?: number; 3968 | } 3969 | interface Ai_Cf_Meta_Llama_4_Messages { 3970 | /** 3971 | * An array of message objects representing the conversation history. 3972 | */ 3973 | messages: { 3974 | /** 3975 | * The role of the message sender (e.g., 'user', 'assistant', 'system', 'tool'). 3976 | */ 3977 | role?: string; 3978 | /** 3979 | * The tool call id. Must be supplied for tool calls for Mistral-3. If you don't know what to put here you can fall back to 000000001 3980 | */ 3981 | tool_call_id?: string; 3982 | content?: 3983 | | string 3984 | | { 3985 | /** 3986 | * Type of the content provided 3987 | */ 3988 | type?: string; 3989 | text?: string; 3990 | image_url?: { 3991 | /** 3992 | * image uri with data (e.g. data:image/jpeg;base64,/9j/...). HTTP URL will not be accepted 3993 | */ 3994 | url?: string; 3995 | }; 3996 | }[] 3997 | | { 3998 | /** 3999 | * Type of the content provided 4000 | */ 4001 | type?: string; 4002 | text?: string; 4003 | image_url?: { 4004 | /** 4005 | * image uri with data (e.g. data:image/jpeg;base64,/9j/...). HTTP URL will not be accepted 4006 | */ 4007 | url?: string; 4008 | }; 4009 | }; 4010 | }[]; 4011 | functions?: { 4012 | name: string; 4013 | code: string; 4014 | }[]; 4015 | /** 4016 | * A list of tools available for the assistant to use. 4017 | */ 4018 | tools?: ( 4019 | | { 4020 | /** 4021 | * The name of the tool. More descriptive the better. 4022 | */ 4023 | name: string; 4024 | /** 4025 | * A brief description of what the tool does. 4026 | */ 4027 | description: string; 4028 | /** 4029 | * Schema defining the parameters accepted by the tool. 4030 | */ 4031 | parameters: { 4032 | /** 4033 | * The type of the parameters object (usually 'object'). 4034 | */ 4035 | type: string; 4036 | /** 4037 | * List of required parameter names. 4038 | */ 4039 | required?: string[]; 4040 | /** 4041 | * Definitions of each parameter. 4042 | */ 4043 | properties: { 4044 | [k: string]: { 4045 | /** 4046 | * The data type of the parameter. 4047 | */ 4048 | type: string; 4049 | /** 4050 | * A description of the expected parameter. 4051 | */ 4052 | description: string; 4053 | }; 4054 | }; 4055 | }; 4056 | } 4057 | | { 4058 | /** 4059 | * Specifies the type of tool (e.g., 'function'). 4060 | */ 4061 | type: string; 4062 | /** 4063 | * Details of the function tool. 4064 | */ 4065 | function: { 4066 | /** 4067 | * The name of the function. 4068 | */ 4069 | name: string; 4070 | /** 4071 | * A brief description of what the function does. 4072 | */ 4073 | description: string; 4074 | /** 4075 | * Schema defining the parameters accepted by the function. 4076 | */ 4077 | parameters: { 4078 | /** 4079 | * The type of the parameters object (usually 'object'). 4080 | */ 4081 | type: string; 4082 | /** 4083 | * List of required parameter names. 4084 | */ 4085 | required?: string[]; 4086 | /** 4087 | * Definitions of each parameter. 4088 | */ 4089 | properties: { 4090 | [k: string]: { 4091 | /** 4092 | * The data type of the parameter. 4093 | */ 4094 | type: string; 4095 | /** 4096 | * A description of the expected parameter. 4097 | */ 4098 | description: string; 4099 | }; 4100 | }; 4101 | }; 4102 | }; 4103 | } 4104 | )[]; 4105 | /** 4106 | * JSON schema that should be fufilled for the response. 4107 | */ 4108 | guided_json?: object; 4109 | /** 4110 | * If true, a chat template is not applied and you must adhere to the specific model's expected formatting. 4111 | */ 4112 | raw?: boolean; 4113 | /** 4114 | * If true, the response will be streamed back incrementally using SSE, Server Sent Events. 4115 | */ 4116 | stream?: boolean; 4117 | /** 4118 | * The maximum number of tokens to generate in the response. 4119 | */ 4120 | max_tokens?: number; 4121 | /** 4122 | * Controls the randomness of the output; higher values produce more random results. 4123 | */ 4124 | temperature?: number; 4125 | /** 4126 | * Adjusts the creativity of the AI's responses by controlling how many possible words it considers. Lower values make outputs more predictable; higher values allow for more varied and creative responses. 4127 | */ 4128 | top_p?: number; 4129 | /** 4130 | * Limits the AI to choose from the top 'k' most probable words. Lower values make responses more focused; higher values introduce more variety and potential surprises. 4131 | */ 4132 | top_k?: number; 4133 | /** 4134 | * Random seed for reproducibility of the generation. 4135 | */ 4136 | seed?: number; 4137 | /** 4138 | * Penalty for repeated tokens; higher values discourage repetition. 4139 | */ 4140 | repetition_penalty?: number; 4141 | /** 4142 | * Decreases the likelihood of the model repeating the same lines verbatim. 4143 | */ 4144 | frequency_penalty?: number; 4145 | /** 4146 | * Increases the likelihood of the model introducing new topics. 4147 | */ 4148 | presence_penalty?: number; 4149 | } 4150 | type Ai_Cf_Meta_Llama_4_Scout_17B_16E_Instruct_Output = 4151 | | { 4152 | /** 4153 | * The generated text response from the model 4154 | */ 4155 | response: string; 4156 | /** 4157 | * Usage statistics for the inference request 4158 | */ 4159 | usage?: { 4160 | /** 4161 | * Total number of tokens in input 4162 | */ 4163 | prompt_tokens?: number; 4164 | /** 4165 | * Total number of tokens in output 4166 | */ 4167 | completion_tokens?: number; 4168 | /** 4169 | * Total number of input and output tokens 4170 | */ 4171 | total_tokens?: number; 4172 | }; 4173 | /** 4174 | * An array of tool calls requests made during the response generation 4175 | */ 4176 | tool_calls?: { 4177 | /** 4178 | * The arguments passed to be passed to the tool call request 4179 | */ 4180 | arguments?: object; 4181 | /** 4182 | * The name of the tool to be called 4183 | */ 4184 | name?: string; 4185 | }[]; 4186 | } 4187 | | string; 4188 | declare abstract class Base_Ai_Cf_Meta_Llama_4_Scout_17B_16E_Instruct { 4189 | inputs: Ai_Cf_Meta_Llama_4_Scout_17B_16E_Instruct_Input; 4190 | postProcessedOutputs: Ai_Cf_Meta_Llama_4_Scout_17B_16E_Instruct_Output; 4191 | } 4192 | interface AiModels { 4193 | '@cf/huggingface/distilbert-sst-2-int8': BaseAiTextClassification; 4194 | '@cf/stabilityai/stable-diffusion-xl-base-1.0': BaseAiTextToImage; 4195 | '@cf/runwayml/stable-diffusion-v1-5-inpainting': BaseAiTextToImage; 4196 | '@cf/runwayml/stable-diffusion-v1-5-img2img': BaseAiTextToImage; 4197 | '@cf/lykon/dreamshaper-8-lcm': BaseAiTextToImage; 4198 | '@cf/bytedance/stable-diffusion-xl-lightning': BaseAiTextToImage; 4199 | '@cf/myshell-ai/melotts': BaseAiTextToSpeech; 4200 | '@cf/baai/bge-base-en-v1.5': BaseAiTextEmbeddings; 4201 | '@cf/baai/bge-small-en-v1.5': BaseAiTextEmbeddings; 4202 | '@cf/baai/bge-large-en-v1.5': BaseAiTextEmbeddings; 4203 | '@cf/microsoft/resnet-50': BaseAiImageClassification; 4204 | '@cf/facebook/detr-resnet-50': BaseAiObjectDetection; 4205 | '@cf/meta/llama-2-7b-chat-int8': BaseAiTextGeneration; 4206 | '@cf/mistral/mistral-7b-instruct-v0.1': BaseAiTextGeneration; 4207 | '@cf/meta/llama-2-7b-chat-fp16': BaseAiTextGeneration; 4208 | '@hf/thebloke/llama-2-13b-chat-awq': BaseAiTextGeneration; 4209 | '@hf/thebloke/mistral-7b-instruct-v0.1-awq': BaseAiTextGeneration; 4210 | '@hf/thebloke/zephyr-7b-beta-awq': BaseAiTextGeneration; 4211 | '@hf/thebloke/openhermes-2.5-mistral-7b-awq': BaseAiTextGeneration; 4212 | '@hf/thebloke/neural-chat-7b-v3-1-awq': BaseAiTextGeneration; 4213 | '@hf/thebloke/llamaguard-7b-awq': BaseAiTextGeneration; 4214 | '@hf/thebloke/deepseek-coder-6.7b-base-awq': BaseAiTextGeneration; 4215 | '@hf/thebloke/deepseek-coder-6.7b-instruct-awq': BaseAiTextGeneration; 4216 | '@cf/deepseek-ai/deepseek-math-7b-instruct': BaseAiTextGeneration; 4217 | '@cf/defog/sqlcoder-7b-2': BaseAiTextGeneration; 4218 | '@cf/openchat/openchat-3.5-0106': BaseAiTextGeneration; 4219 | '@cf/tiiuae/falcon-7b-instruct': BaseAiTextGeneration; 4220 | '@cf/thebloke/discolm-german-7b-v1-awq': BaseAiTextGeneration; 4221 | '@cf/qwen/qwen1.5-0.5b-chat': BaseAiTextGeneration; 4222 | '@cf/qwen/qwen1.5-7b-chat-awq': BaseAiTextGeneration; 4223 | '@cf/qwen/qwen1.5-14b-chat-awq': BaseAiTextGeneration; 4224 | '@cf/tinyllama/tinyllama-1.1b-chat-v1.0': BaseAiTextGeneration; 4225 | '@cf/microsoft/phi-2': BaseAiTextGeneration; 4226 | '@cf/qwen/qwen1.5-1.8b-chat': BaseAiTextGeneration; 4227 | '@cf/mistral/mistral-7b-instruct-v0.2-lora': BaseAiTextGeneration; 4228 | '@hf/nousresearch/hermes-2-pro-mistral-7b': BaseAiTextGeneration; 4229 | '@hf/nexusflow/starling-lm-7b-beta': BaseAiTextGeneration; 4230 | '@hf/google/gemma-7b-it': BaseAiTextGeneration; 4231 | '@cf/meta-llama/llama-2-7b-chat-hf-lora': BaseAiTextGeneration; 4232 | '@cf/google/gemma-2b-it-lora': BaseAiTextGeneration; 4233 | '@cf/google/gemma-7b-it-lora': BaseAiTextGeneration; 4234 | '@hf/mistral/mistral-7b-instruct-v0.2': BaseAiTextGeneration; 4235 | '@cf/meta/llama-3-8b-instruct': BaseAiTextGeneration; 4236 | '@cf/fblgit/una-cybertron-7b-v2-bf16': BaseAiTextGeneration; 4237 | '@cf/meta/llama-3-8b-instruct-awq': BaseAiTextGeneration; 4238 | '@hf/meta-llama/meta-llama-3-8b-instruct': BaseAiTextGeneration; 4239 | '@cf/meta/llama-3.1-8b-instruct': BaseAiTextGeneration; 4240 | '@cf/meta/llama-3.1-8b-instruct-fp8': BaseAiTextGeneration; 4241 | '@cf/meta/llama-3.1-8b-instruct-awq': BaseAiTextGeneration; 4242 | '@cf/meta/llama-3.2-3b-instruct': BaseAiTextGeneration; 4243 | '@cf/meta/llama-3.2-1b-instruct': BaseAiTextGeneration; 4244 | '@cf/meta/llama-3.3-70b-instruct-fp8-fast': BaseAiTextGeneration; 4245 | '@cf/deepseek-ai/deepseek-r1-distill-qwen-32b': BaseAiTextGeneration; 4246 | '@cf/meta/m2m100-1.2b': BaseAiTranslation; 4247 | '@cf/facebook/bart-large-cnn': BaseAiSummarization; 4248 | '@cf/llava-hf/llava-1.5-7b-hf': BaseAiImageToText; 4249 | '@cf/openai/whisper': Base_Ai_Cf_Openai_Whisper; 4250 | '@cf/unum/uform-gen2-qwen-500m': Base_Ai_Cf_Unum_Uform_Gen2_Qwen_500M; 4251 | '@cf/openai/whisper-tiny-en': Base_Ai_Cf_Openai_Whisper_Tiny_En; 4252 | '@cf/openai/whisper-large-v3-turbo': Base_Ai_Cf_Openai_Whisper_Large_V3_Turbo; 4253 | '@cf/baai/bge-m3': Base_Ai_Cf_Baai_Bge_M3; 4254 | '@cf/black-forest-labs/flux-1-schnell': Base_Ai_Cf_Black_Forest_Labs_Flux_1_Schnell; 4255 | '@cf/meta/llama-3.2-11b-vision-instruct': Base_Ai_Cf_Meta_Llama_3_2_11B_Vision_Instruct; 4256 | '@cf/meta/llama-guard-3-8b': Base_Ai_Cf_Meta_Llama_Guard_3_8B; 4257 | '@cf/baai/bge-reranker-base': Base_Ai_Cf_Baai_Bge_Reranker_Base; 4258 | '@cf/meta/llama-4-scout-17b-16e-instruct': Base_Ai_Cf_Meta_Llama_4_Scout_17B_16E_Instruct; 4259 | } 4260 | type AiOptions = { 4261 | gateway?: GatewayOptions; 4262 | returnRawResponse?: boolean; 4263 | prefix?: string; 4264 | extraHeaders?: object; 4265 | }; 4266 | type ConversionResponse = { 4267 | name: string; 4268 | mimeType: string; 4269 | format: 'markdown'; 4270 | tokens: number; 4271 | data: string; 4272 | }; 4273 | type AiModelsSearchParams = { 4274 | author?: string; 4275 | hide_experimental?: boolean; 4276 | page?: number; 4277 | per_page?: number; 4278 | search?: string; 4279 | source?: number; 4280 | task?: string; 4281 | }; 4282 | type AiModelsSearchObject = { 4283 | id: string; 4284 | source: number; 4285 | name: string; 4286 | description: string; 4287 | task: { 4288 | id: string; 4289 | name: string; 4290 | description: string; 4291 | }; 4292 | tags: string[]; 4293 | properties: { 4294 | property_id: string; 4295 | value: string; 4296 | }[]; 4297 | }; 4298 | interface InferenceUpstreamError extends Error {} 4299 | interface AiInternalError extends Error {} 4300 | type AiModelListType = Record<string, any>; 4301 | declare abstract class Ai<AiModelList extends AiModelListType = AiModels> { 4302 | aiGatewayLogId: string | null; 4303 | gateway(gatewayId: string): AiGateway; 4304 | autorag(autoragId: string): AutoRAG; 4305 | run<Name extends keyof AiModelList, Options extends AiOptions>( 4306 | model: Name, 4307 | inputs: AiModelList[Name]['inputs'], 4308 | options?: Options 4309 | ): Promise< 4310 | Options extends { 4311 | returnRawResponse: true; 4312 | } 4313 | ? Response 4314 | : AiModelList[Name]['postProcessedOutputs'] 4315 | >; 4316 | models(params?: AiModelsSearchParams): Promise<AiModelsSearchObject[]>; 4317 | toMarkdown( 4318 | files: { 4319 | name: string; 4320 | blob: Blob; 4321 | }[], 4322 | options?: { 4323 | gateway?: GatewayOptions; 4324 | extraHeaders?: object; 4325 | } 4326 | ): Promise<ConversionResponse[]>; 4327 | toMarkdown( 4328 | files: { 4329 | name: string; 4330 | blob: Blob; 4331 | }, 4332 | options?: { 4333 | gateway?: GatewayOptions; 4334 | extraHeaders?: object; 4335 | } 4336 | ): Promise<ConversionResponse>; 4337 | } 4338 | type GatewayRetries = { 4339 | maxAttempts?: 1 | 2 | 3 | 4 | 5; 4340 | retryDelayMs?: number; 4341 | backoff?: 'constant' | 'linear' | 'exponential'; 4342 | }; 4343 | type GatewayOptions = { 4344 | id: string; 4345 | cacheKey?: string; 4346 | cacheTtl?: number; 4347 | skipCache?: boolean; 4348 | metadata?: Record<string, number | string | boolean | null | bigint>; 4349 | collectLog?: boolean; 4350 | eventId?: string; 4351 | requestTimeoutMs?: number; 4352 | retries?: GatewayRetries; 4353 | }; 4354 | type AiGatewayPatchLog = { 4355 | score?: number | null; 4356 | feedback?: -1 | 1 | null; 4357 | metadata?: Record<string, number | string | boolean | null | bigint> | null; 4358 | }; 4359 | type AiGatewayLog = { 4360 | id: string; 4361 | provider: string; 4362 | model: string; 4363 | model_type?: string; 4364 | path: string; 4365 | duration: number; 4366 | request_type?: string; 4367 | request_content_type?: string; 4368 | status_code: number; 4369 | response_content_type?: string; 4370 | success: boolean; 4371 | cached: boolean; 4372 | tokens_in?: number; 4373 | tokens_out?: number; 4374 | metadata?: Record<string, number | string | boolean | null | bigint>; 4375 | step?: number; 4376 | cost?: number; 4377 | custom_cost?: boolean; 4378 | request_size: number; 4379 | request_head?: string; 4380 | request_head_complete: boolean; 4381 | response_size: number; 4382 | response_head?: string; 4383 | response_head_complete: boolean; 4384 | created_at: Date; 4385 | }; 4386 | type AIGatewayProviders = 4387 | | 'workers-ai' 4388 | | 'anthropic' 4389 | | 'aws-bedrock' 4390 | | 'azure-openai' 4391 | | 'google-vertex-ai' 4392 | | 'huggingface' 4393 | | 'openai' 4394 | | 'perplexity-ai' 4395 | | 'replicate' 4396 | | 'groq' 4397 | | 'cohere' 4398 | | 'google-ai-studio' 4399 | | 'mistral' 4400 | | 'grok' 4401 | | 'openrouter' 4402 | | 'deepseek' 4403 | | 'cerebras' 4404 | | 'cartesia' 4405 | | 'elevenlabs' 4406 | | 'adobe-firefly'; 4407 | type AIGatewayHeaders = { 4408 | 'cf-aig-metadata': 4409 | | Record<string, number | string | boolean | null | bigint> 4410 | | string; 4411 | 'cf-aig-custom-cost': 4412 | | { 4413 | per_token_in?: number; 4414 | per_token_out?: number; 4415 | } 4416 | | { 4417 | total_cost?: number; 4418 | } 4419 | | string; 4420 | 'cf-aig-cache-ttl': number | string; 4421 | 'cf-aig-skip-cache': boolean | string; 4422 | 'cf-aig-cache-key': string; 4423 | 'cf-aig-event-id': string; 4424 | 'cf-aig-request-timeout': number | string; 4425 | 'cf-aig-max-attempts': number | string; 4426 | 'cf-aig-retry-delay': number | string; 4427 | 'cf-aig-backoff': string; 4428 | 'cf-aig-collect-log': boolean | string; 4429 | Authorization: string; 4430 | 'Content-Type': string; 4431 | [key: string]: string | number | boolean | object; 4432 | }; 4433 | type AIGatewayUniversalRequest = { 4434 | provider: AIGatewayProviders | string; // eslint-disable-line 4435 | endpoint: string; 4436 | headers: Partial<AIGatewayHeaders>; 4437 | query: unknown; 4438 | }; 4439 | interface AiGatewayInternalError extends Error {} 4440 | interface AiGatewayLogNotFound extends Error {} 4441 | declare abstract class AiGateway { 4442 | patchLog(logId: string, data: AiGatewayPatchLog): Promise<void>; 4443 | getLog(logId: string): Promise<AiGatewayLog>; 4444 | run( 4445 | data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[], 4446 | options?: { 4447 | gateway?: GatewayOptions; 4448 | extraHeaders?: object; 4449 | } 4450 | ): Promise<Response>; 4451 | getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line 4452 | } 4453 | interface AutoRAGInternalError extends Error {} 4454 | interface AutoRAGNotFoundError extends Error {} 4455 | interface AutoRAGUnauthorizedError extends Error {} 4456 | type ComparisonFilter = { 4457 | key: string; 4458 | type: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte'; 4459 | value: string | number | boolean; 4460 | }; 4461 | type CompoundFilter = { 4462 | type: 'and' | 'or'; 4463 | filters: ComparisonFilter[]; 4464 | }; 4465 | type AutoRagSearchRequest = { 4466 | query: string; 4467 | filters?: CompoundFilter | ComparisonFilter; 4468 | max_num_results?: number; 4469 | ranking_options?: { 4470 | ranker?: string; 4471 | score_threshold?: number; 4472 | }; 4473 | rewrite_query?: boolean; 4474 | }; 4475 | type AutoRagAiSearchRequest = AutoRagSearchRequest & { 4476 | stream?: boolean; 4477 | }; 4478 | type AutoRagAiSearchRequestStreaming = Omit< 4479 | AutoRagAiSearchRequest, 4480 | 'stream' 4481 | > & { 4482 | stream: true; 4483 | }; 4484 | type AutoRagSearchResponse = { 4485 | object: 'vector_store.search_results.page'; 4486 | search_query: string; 4487 | data: { 4488 | file_id: string; 4489 | filename: string; 4490 | score: number; 4491 | attributes: Record<string, string | number | boolean | null>; 4492 | content: { 4493 | type: 'text'; 4494 | text: string; 4495 | }[]; 4496 | }[]; 4497 | has_more: boolean; 4498 | next_page: string | null; 4499 | }; 4500 | type AutoRagAiSearchResponse = AutoRagSearchResponse & { 4501 | response: string; 4502 | }; 4503 | declare abstract class AutoRAG { 4504 | search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>; 4505 | aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>; 4506 | aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>; 4507 | aiSearch( 4508 | params: AutoRagAiSearchRequest 4509 | ): Promise<AutoRagAiSearchResponse | Response>; 4510 | } 4511 | interface BasicImageTransformations { 4512 | /** 4513 | * Maximum width in image pixels. The value must be an integer. 4514 | */ 4515 | width?: number; 4516 | /** 4517 | * Maximum height in image pixels. The value must be an integer. 4518 | */ 4519 | height?: number; 4520 | /** 4521 | * Resizing mode as a string. It affects interpretation of width and height 4522 | * options: 4523 | * - scale-down: Similar to contain, but the image is never enlarged. If 4524 | * the image is larger than given width or height, it will be resized. 4525 | * Otherwise its original size will be kept. 4526 | * - contain: Resizes to maximum size that fits within the given width and 4527 | * height. If only a single dimension is given (e.g. only width), the 4528 | * image will be shrunk or enlarged to exactly match that dimension. 4529 | * Aspect ratio is always preserved. 4530 | * - cover: Resizes (shrinks or enlarges) to fill the entire area of width 4531 | * and height. If the image has an aspect ratio different from the ratio 4532 | * of width and height, it will be cropped to fit. 4533 | * - crop: The image will be shrunk and cropped to fit within the area 4534 | * specified by width and height. The image will not be enlarged. For images 4535 | * smaller than the given dimensions it's the same as scale-down. For 4536 | * images larger than the given dimensions, it's the same as cover. 4537 | * See also trim. 4538 | * - pad: Resizes to the maximum size that fits within the given width and 4539 | * height, and then fills the remaining area with a background color 4540 | * (white by default). Use of this mode is not recommended, as the same 4541 | * effect can be more efficiently achieved with the contain mode and the 4542 | * CSS object-fit: contain property. 4543 | * - squeeze: Stretches and deforms to the width and height given, even if it 4544 | * breaks aspect ratio 4545 | */ 4546 | fit?: 'scale-down' | 'contain' | 'cover' | 'crop' | 'pad' | 'squeeze'; 4547 | /** 4548 | * When cropping with fit: "cover", this defines the side or point that should 4549 | * be left uncropped. The value is either a string 4550 | * "left", "right", "top", "bottom", "auto", or "center" (the default), 4551 | * or an object {x, y} containing focal point coordinates in the original 4552 | * image expressed as fractions ranging from 0.0 (top or left) to 1.0 4553 | * (bottom or right), 0.5 being the center. {fit: "cover", gravity: "top"} will 4554 | * crop bottom or left and right sides as necessary, but won’t crop anything 4555 | * from the top. {fit: "cover", gravity: {x:0.5, y:0.2}} will crop each side to 4556 | * preserve as much as possible around a point at 20% of the height of the 4557 | * source image. 4558 | */ 4559 | gravity?: 4560 | | 'left' 4561 | | 'right' 4562 | | 'top' 4563 | | 'bottom' 4564 | | 'center' 4565 | | 'auto' 4566 | | 'entropy' 4567 | | BasicImageTransformationsGravityCoordinates; 4568 | /** 4569 | * Background color to add underneath the image. Applies only to images with 4570 | * transparency (such as PNG). Accepts any CSS color (#RRGGBB, rgba(…), 4571 | * hsl(…), etc.) 4572 | */ 4573 | background?: string; 4574 | /** 4575 | * Number of degrees (90, 180, 270) to rotate the image by. width and height 4576 | * options refer to axes after rotation. 4577 | */ 4578 | rotate?: 0 | 90 | 180 | 270 | 360; 4579 | } 4580 | interface BasicImageTransformationsGravityCoordinates { 4581 | x?: number; 4582 | y?: number; 4583 | mode?: 'remainder' | 'box-center'; 4584 | } 4585 | /** 4586 | * In addition to the properties you can set in the RequestInit dict 4587 | * that you pass as an argument to the Request constructor, you can 4588 | * set certain properties of a `cf` object to control how Cloudflare 4589 | * features are applied to that new Request. 4590 | * 4591 | * Note: Currently, these properties cannot be tested in the 4592 | * playground. 4593 | */ 4594 | interface RequestInitCfProperties extends Record<string, unknown> { 4595 | cacheEverything?: boolean; 4596 | /** 4597 | * A request's cache key is what determines if two requests are 4598 | * "the same" for caching purposes. If a request has the same cache key 4599 | * as some previous request, then we can serve the same cached response for 4600 | * both. (e.g. 'some-key') 4601 | * 4602 | * Only available for Enterprise customers. 4603 | */ 4604 | cacheKey?: string; 4605 | /** 4606 | * This allows you to append additional Cache-Tag response headers 4607 | * to the origin response without modifications to the origin server. 4608 | * This will allow for greater control over the Purge by Cache Tag feature 4609 | * utilizing changes only in the Workers process. 4610 | * 4611 | * Only available for Enterprise customers. 4612 | */ 4613 | cacheTags?: string[]; 4614 | /** 4615 | * Force response to be cached for a given number of seconds. (e.g. 300) 4616 | */ 4617 | cacheTtl?: number; 4618 | /** 4619 | * Force response to be cached for a given number of seconds based on the Origin status code. 4620 | * (e.g. { '200-299': 86400, '404': 1, '500-599': 0 }) 4621 | */ 4622 | cacheTtlByStatus?: Record<string, number>; 4623 | scrapeShield?: boolean; 4624 | apps?: boolean; 4625 | image?: RequestInitCfPropertiesImage; 4626 | minify?: RequestInitCfPropertiesImageMinify; 4627 | mirage?: boolean; 4628 | polish?: 'lossy' | 'lossless' | 'off'; 4629 | r2?: RequestInitCfPropertiesR2; 4630 | /** 4631 | * Redirects the request to an alternate origin server. You can use this, 4632 | * for example, to implement load balancing across several origins. 4633 | * (e.g.us-east.example.com) 4634 | * 4635 | * Note - For security reasons, the hostname set in resolveOverride must 4636 | * be proxied on the same Cloudflare zone of the incoming request. 4637 | * Otherwise, the setting is ignored. CNAME hosts are allowed, so to 4638 | * resolve to a host under a different domain or a DNS only domain first 4639 | * declare a CNAME record within your own zone’s DNS mapping to the 4640 | * external hostname, set proxy on Cloudflare, then set resolveOverride 4641 | * to point to that CNAME record. 4642 | */ 4643 | resolveOverride?: string; 4644 | } 4645 | interface RequestInitCfPropertiesImageDraw extends BasicImageTransformations { 4646 | /** 4647 | * Absolute URL of the image file to use for the drawing. It can be any of 4648 | * the supported file formats. For drawing of watermarks or non-rectangular 4649 | * overlays we recommend using PNG or WebP images. 4650 | */ 4651 | url: string; 4652 | /** 4653 | * Floating-point number between 0 (transparent) and 1 (opaque). 4654 | * For example, opacity: 0.5 makes overlay semitransparent. 4655 | */ 4656 | opacity?: number; 4657 | /** 4658 | * - If set to true, the overlay image will be tiled to cover the entire 4659 | * area. This is useful for stock-photo-like watermarks. 4660 | * - If set to "x", the overlay image will be tiled horizontally only 4661 | * (form a line). 4662 | * - If set to "y", the overlay image will be tiled vertically only 4663 | * (form a line). 4664 | */ 4665 | repeat?: true | 'x' | 'y'; 4666 | /** 4667 | * Position of the overlay image relative to a given edge. Each property is 4668 | * an offset in pixels. 0 aligns exactly to the edge. For example, left: 10 4669 | * positions left side of the overlay 10 pixels from the left edge of the 4670 | * image it's drawn over. bottom: 0 aligns bottom of the overlay with bottom 4671 | * of the background image. 4672 | * 4673 | * Setting both left & right, or both top & bottom is an error. 4674 | * 4675 | * If no position is specified, the image will be centered. 4676 | */ 4677 | top?: number; 4678 | left?: number; 4679 | bottom?: number; 4680 | right?: number; 4681 | } 4682 | interface RequestInitCfPropertiesImage extends BasicImageTransformations { 4683 | /** 4684 | * Device Pixel Ratio. Default 1. Multiplier for width/height that makes it 4685 | * easier to specify higher-DPI sizes in <img srcset>. 4686 | */ 4687 | dpr?: number; 4688 | /** 4689 | * Allows you to trim your image. Takes dpr into account and is performed before 4690 | * resizing or rotation. 4691 | * 4692 | * It can be used as: 4693 | * - left, top, right, bottom - it will specify the number of pixels to cut 4694 | * off each side 4695 | * - width, height - the width/height you'd like to end up with - can be used 4696 | * in combination with the properties above 4697 | * - border - this will automatically trim the surroundings of an image based on 4698 | * it's color. It consists of three properties: 4699 | * - color: rgb or hex representation of the color you wish to trim (todo: verify the rgba bit) 4700 | * - tolerance: difference from color to treat as color 4701 | * - keep: the number of pixels of border to keep 4702 | */ 4703 | trim?: 4704 | | 'border' 4705 | | { 4706 | top?: number; 4707 | bottom?: number; 4708 | left?: number; 4709 | right?: number; 4710 | width?: number; 4711 | height?: number; 4712 | border?: 4713 | | boolean 4714 | | { 4715 | color?: string; 4716 | tolerance?: number; 4717 | keep?: number; 4718 | }; 4719 | }; 4720 | /** 4721 | * Quality setting from 1-100 (useful values are in 60-90 range). Lower values 4722 | * make images look worse, but load faster. The default is 85. It applies only 4723 | * to JPEG and WebP images. It doesn’t have any effect on PNG. 4724 | */ 4725 | quality?: number | 'low' | 'medium-low' | 'medium-high' | 'high'; 4726 | /** 4727 | * Output format to generate. It can be: 4728 | * - avif: generate images in AVIF format. 4729 | * - webp: generate images in Google WebP format. Set quality to 100 to get 4730 | * the WebP-lossless format. 4731 | * - json: instead of generating an image, outputs information about the 4732 | * image, in JSON format. The JSON object will contain image size 4733 | * (before and after resizing), source image’s MIME type, file size, etc. 4734 | * - jpeg: generate images in JPEG format. 4735 | * - png: generate images in PNG format. 4736 | */ 4737 | format?: 4738 | | 'avif' 4739 | | 'webp' 4740 | | 'json' 4741 | | 'jpeg' 4742 | | 'png' 4743 | | 'baseline-jpeg' 4744 | | 'png-force' 4745 | | 'svg'; 4746 | /** 4747 | * Whether to preserve animation frames from input files. Default is true. 4748 | * Setting it to false reduces animations to still images. This setting is 4749 | * recommended when enlarging images or processing arbitrary user content, 4750 | * because large GIF animations can weigh tens or even hundreds of megabytes. 4751 | * It is also useful to set anim:false when using format:"json" to get the 4752 | * response quicker without the number of frames. 4753 | */ 4754 | anim?: boolean; 4755 | /** 4756 | * What EXIF data should be preserved in the output image. Note that EXIF 4757 | * rotation and embedded color profiles are always applied ("baked in" into 4758 | * the image), and aren't affected by this option. Note that if the Polish 4759 | * feature is enabled, all metadata may have been removed already and this 4760 | * option may have no effect. 4761 | * - keep: Preserve most of EXIF metadata, including GPS location if there's 4762 | * any. 4763 | * - copyright: Only keep the copyright tag, and discard everything else. 4764 | * This is the default behavior for JPEG files. 4765 | * - none: Discard all invisible EXIF metadata. Currently WebP and PNG 4766 | * output formats always discard metadata. 4767 | */ 4768 | metadata?: 'keep' | 'copyright' | 'none'; 4769 | /** 4770 | * Strength of sharpening filter to apply to the image. Floating-point 4771 | * number between 0 (no sharpening, default) and 10 (maximum). 1.0 is a 4772 | * recommended value for downscaled images. 4773 | */ 4774 | sharpen?: number; 4775 | /** 4776 | * Radius of a blur filter (approximate gaussian). Maximum supported radius 4777 | * is 250. 4778 | */ 4779 | blur?: number; 4780 | /** 4781 | * Overlays are drawn in the order they appear in the array (last array 4782 | * entry is the topmost layer). 4783 | */ 4784 | draw?: RequestInitCfPropertiesImageDraw[]; 4785 | /** 4786 | * Fetching image from authenticated origin. Setting this property will 4787 | * pass authentication headers (Authorization, Cookie, etc.) through to 4788 | * the origin. 4789 | */ 4790 | 'origin-auth'?: 'share-publicly'; 4791 | /** 4792 | * Adds a border around the image. The border is added after resizing. Border 4793 | * width takes dpr into account, and can be specified either using a single 4794 | * width property, or individually for each side. 4795 | */ 4796 | border?: 4797 | | { 4798 | color: string; 4799 | width: number; 4800 | } 4801 | | { 4802 | color: string; 4803 | top: number; 4804 | right: number; 4805 | bottom: number; 4806 | left: number; 4807 | }; 4808 | /** 4809 | * Increase brightness by a factor. A value of 1.0 equals no change, a value 4810 | * of 0.5 equals half brightness, and a value of 2.0 equals twice as bright. 4811 | * 0 is ignored. 4812 | */ 4813 | brightness?: number; 4814 | /** 4815 | * Increase contrast by a factor. A value of 1.0 equals no change, a value of 4816 | * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is 4817 | * ignored. 4818 | */ 4819 | contrast?: number; 4820 | /** 4821 | * Increase exposure by a factor. A value of 1.0 equals no change, a value of 4822 | * 0.5 darkens the image, and a value of 2.0 lightens the image. 0 is ignored. 4823 | */ 4824 | gamma?: number; 4825 | /** 4826 | * Increase contrast by a factor. A value of 1.0 equals no change, a value of 4827 | * 0.5 equals low contrast, and a value of 2.0 equals high contrast. 0 is 4828 | * ignored. 4829 | */ 4830 | saturation?: number; 4831 | /** 4832 | * Flips the images horizontally, vertically, or both. Flipping is applied before 4833 | * rotation, so if you apply flip=h,rotate=90 then the image will be flipped 4834 | * horizontally, then rotated by 90 degrees. 4835 | */ 4836 | flip?: 'h' | 'v' | 'hv'; 4837 | /** 4838 | * Slightly reduces latency on a cache miss by selecting a 4839 | * quickest-to-compress file format, at a cost of increased file size and 4840 | * lower image quality. It will usually override the format option and choose 4841 | * JPEG over WebP or AVIF. We do not recommend using this option, except in 4842 | * unusual circumstances like resizing uncacheable dynamically-generated 4843 | * images. 4844 | */ 4845 | compression?: 'fast'; 4846 | } 4847 | interface RequestInitCfPropertiesImageMinify { 4848 | javascript?: boolean; 4849 | css?: boolean; 4850 | html?: boolean; 4851 | } 4852 | interface RequestInitCfPropertiesR2 { 4853 | /** 4854 | * Colo id of bucket that an object is stored in 4855 | */ 4856 | bucketColoId?: number; 4857 | } 4858 | /** 4859 | * Request metadata provided by Cloudflare's edge. 4860 | */ 4861 | type IncomingRequestCfProperties<HostMetadata = unknown> = 4862 | IncomingRequestCfPropertiesBase & 4863 | IncomingRequestCfPropertiesBotManagementEnterprise & 4864 | IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> & 4865 | IncomingRequestCfPropertiesGeographicInformation & 4866 | IncomingRequestCfPropertiesCloudflareAccessOrApiShield; 4867 | interface IncomingRequestCfPropertiesBase extends Record<string, unknown> { 4868 | /** 4869 | * [ASN](https://www.iana.org/assignments/as-numbers/as-numbers.xhtml) of the incoming request. 4870 | * 4871 | * @example 395747 4872 | */ 4873 | asn: number; 4874 | /** 4875 | * The organization which owns the ASN of the incoming request. 4876 | * 4877 | * @example "Google Cloud" 4878 | */ 4879 | asOrganization: string; 4880 | /** 4881 | * The original value of the `Accept-Encoding` header if Cloudflare modified it. 4882 | * 4883 | * @example "gzip, deflate, br" 4884 | */ 4885 | clientAcceptEncoding?: string; 4886 | /** 4887 | * The number of milliseconds it took for the request to reach your worker. 4888 | * 4889 | * @example 22 4890 | */ 4891 | clientTcpRtt?: number; 4892 | /** 4893 | * The three-letter [IATA](https://en.wikipedia.org/wiki/IATA_airport_code) 4894 | * airport code of the data center that the request hit. 4895 | * 4896 | * @example "DFW" 4897 | */ 4898 | colo: string; 4899 | /** 4900 | * Represents the upstream's response to a 4901 | * [TCP `keepalive` message](https://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html) 4902 | * from cloudflare. 4903 | * 4904 | * For workers with no upstream, this will always be `1`. 4905 | * 4906 | * @example 3 4907 | */ 4908 | edgeRequestKeepAliveStatus: IncomingRequestCfPropertiesEdgeRequestKeepAliveStatus; 4909 | /** 4910 | * The HTTP Protocol the request used. 4911 | * 4912 | * @example "HTTP/2" 4913 | */ 4914 | httpProtocol: string; 4915 | /** 4916 | * The browser-requested prioritization information in the request object. 4917 | * 4918 | * If no information was set, defaults to the empty string `""` 4919 | * 4920 | * @example "weight=192;exclusive=0;group=3;group-weight=127" 4921 | * @default "" 4922 | */ 4923 | requestPriority: string; 4924 | /** 4925 | * The TLS version of the connection to Cloudflare. 4926 | * In requests served over plaintext (without TLS), this property is the empty string `""`. 4927 | * 4928 | * @example "TLSv1.3" 4929 | */ 4930 | tlsVersion: string; 4931 | /** 4932 | * The cipher for the connection to Cloudflare. 4933 | * In requests served over plaintext (without TLS), this property is the empty string `""`. 4934 | * 4935 | * @example "AEAD-AES128-GCM-SHA256" 4936 | */ 4937 | tlsCipher: string; 4938 | /** 4939 | * Metadata containing the [`HELLO`](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2) and [`FINISHED`](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9) messages from this request's TLS handshake. 4940 | * 4941 | * If the incoming request was served over plaintext (without TLS) this field is undefined. 4942 | */ 4943 | tlsExportedAuthenticator?: IncomingRequestCfPropertiesExportedAuthenticatorMetadata; 4944 | } 4945 | interface IncomingRequestCfPropertiesBotManagementBase { 4946 | /** 4947 | * Cloudflare’s [level of certainty](https://developers.cloudflare.com/bots/concepts/bot-score/) that a request comes from a bot, 4948 | * represented as an integer percentage between `1` (almost certainly a bot) and `99` (almost certainly human). 4949 | * 4950 | * @example 54 4951 | */ 4952 | score: number; 4953 | /** 4954 | * A boolean value that is true if the request comes from a good bot, like Google or Bing. 4955 | * Most customers choose to allow this traffic. For more details, see [Traffic from known bots](https://developers.cloudflare.com/firewall/known-issues-and-faq/#how-does-firewall-rules-handle-traffic-from-known-bots). 4956 | */ 4957 | verifiedBot: boolean; 4958 | /** 4959 | * A boolean value that is true if the request originates from a 4960 | * Cloudflare-verified proxy service. 4961 | */ 4962 | corporateProxy: boolean; 4963 | /** 4964 | * A boolean value that's true if the request matches [file extensions](https://developers.cloudflare.com/bots/reference/static-resources/) for many types of static resources. 4965 | */ 4966 | staticResource: boolean; 4967 | /** 4968 | * List of IDs that correlate to the Bot Management heuristic detections made on a request (you can have multiple heuristic detections on the same request). 4969 | */ 4970 | detectionIds: number[]; 4971 | } 4972 | interface IncomingRequestCfPropertiesBotManagement { 4973 | /** 4974 | * Results of Cloudflare's Bot Management analysis 4975 | */ 4976 | botManagement: IncomingRequestCfPropertiesBotManagementBase; 4977 | /** 4978 | * Duplicate of `botManagement.score`. 4979 | * 4980 | * @deprecated 4981 | */ 4982 | clientTrustScore: number; 4983 | } 4984 | interface IncomingRequestCfPropertiesBotManagementEnterprise 4985 | extends IncomingRequestCfPropertiesBotManagement { 4986 | /** 4987 | * Results of Cloudflare's Bot Management analysis 4988 | */ 4989 | botManagement: IncomingRequestCfPropertiesBotManagementBase & { 4990 | /** 4991 | * A [JA3 Fingerprint](https://developers.cloudflare.com/bots/concepts/ja3-fingerprint/) to help profile specific SSL/TLS clients 4992 | * across different destination IPs, Ports, and X509 certificates. 4993 | */ 4994 | ja3Hash: string; 4995 | }; 4996 | } 4997 | interface IncomingRequestCfPropertiesCloudflareForSaaSEnterprise<HostMetadata> { 4998 | /** 4999 | * Custom metadata set per-host in [Cloudflare for SaaS](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/). 5000 | * 5001 | * This field is only present if you have Cloudflare for SaaS enabled on your account 5002 | * and you have followed the [required steps to enable it]((https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/)). 5003 | */ 5004 | hostMetadata: HostMetadata; 5005 | } 5006 | interface IncomingRequestCfPropertiesCloudflareAccessOrApiShield { 5007 | /** 5008 | * Information about the client certificate presented to Cloudflare. 5009 | * 5010 | * This is populated when the incoming request is served over TLS using 5011 | * either Cloudflare Access or API Shield (mTLS) 5012 | * and the presented SSL certificate has a valid 5013 | * [Certificate Serial Number](https://ldapwiki.com/wiki/Certificate%20Serial%20Number) 5014 | * (i.e., not `null` or `""`). 5015 | * 5016 | * Otherwise, a set of placeholder values are used. 5017 | * 5018 | * The property `certPresented` will be set to `"1"` when 5019 | * the object is populated (i.e. the above conditions were met). 5020 | */ 5021 | tlsClientAuth: 5022 | | IncomingRequestCfPropertiesTLSClientAuth 5023 | | IncomingRequestCfPropertiesTLSClientAuthPlaceholder; 5024 | } 5025 | /** 5026 | * Metadata about the request's TLS handshake 5027 | */ 5028 | interface IncomingRequestCfPropertiesExportedAuthenticatorMetadata { 5029 | /** 5030 | * The client's [`HELLO` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2), encoded in hexadecimal 5031 | * 5032 | * @example "44372ba35fa1270921d318f34c12f155dc87b682cf36a790cfaa3ba8737a1b5d" 5033 | */ 5034 | clientHandshake: string; 5035 | /** 5036 | * The server's [`HELLO` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2), encoded in hexadecimal 5037 | * 5038 | * @example "44372ba35fa1270921d318f34c12f155dc87b682cf36a790cfaa3ba8737a1b5d" 5039 | */ 5040 | serverHandshake: string; 5041 | /** 5042 | * The client's [`FINISHED` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9), encoded in hexadecimal 5043 | * 5044 | * @example "084ee802fe1348f688220e2a6040a05b2199a761f33cf753abb1b006792d3f8b" 5045 | */ 5046 | clientFinished: string; 5047 | /** 5048 | * The server's [`FINISHED` message](https://www.rfc-editor.org/rfc/rfc5246#section-7.4.9), encoded in hexadecimal 5049 | * 5050 | * @example "084ee802fe1348f688220e2a6040a05b2199a761f33cf753abb1b006792d3f8b" 5051 | */ 5052 | serverFinished: string; 5053 | } 5054 | /** 5055 | * Geographic data about the request's origin. 5056 | */ 5057 | interface IncomingRequestCfPropertiesGeographicInformation { 5058 | /** 5059 | * The [ISO 3166-1 Alpha 2](https://www.iso.org/iso-3166-country-codes.html) country code the request originated from. 5060 | * 5061 | * If your worker is [configured to accept TOR connections](https://support.cloudflare.com/hc/en-us/articles/203306930-Understanding-Cloudflare-Tor-support-and-Onion-Routing), this may also be `"T1"`, indicating a request that originated over TOR. 5062 | * 5063 | * If Cloudflare is unable to determine where the request originated this property is omitted. 5064 | * 5065 | * The country code `"T1"` is used for requests originating on TOR. 5066 | * 5067 | * @example "GB" 5068 | */ 5069 | country?: Iso3166Alpha2Code | 'T1'; 5070 | /** 5071 | * If present, this property indicates that the request originated in the EU 5072 | * 5073 | * @example "1" 5074 | */ 5075 | isEUCountry?: '1'; 5076 | /** 5077 | * A two-letter code indicating the continent the request originated from. 5078 | * 5079 | * @example "AN" 5080 | */ 5081 | continent?: ContinentCode; 5082 | /** 5083 | * The city the request originated from 5084 | * 5085 | * @example "Austin" 5086 | */ 5087 | city?: string; 5088 | /** 5089 | * Postal code of the incoming request 5090 | * 5091 | * @example "78701" 5092 | */ 5093 | postalCode?: string; 5094 | /** 5095 | * Latitude of the incoming request 5096 | * 5097 | * @example "30.27130" 5098 | */ 5099 | latitude?: string; 5100 | /** 5101 | * Longitude of the incoming request 5102 | * 5103 | * @example "-97.74260" 5104 | */ 5105 | longitude?: string; 5106 | /** 5107 | * Timezone of the incoming request 5108 | * 5109 | * @example "America/Chicago" 5110 | */ 5111 | timezone?: string; 5112 | /** 5113 | * If known, the ISO 3166-2 name for the first level region associated with 5114 | * the IP address of the incoming request 5115 | * 5116 | * @example "Texas" 5117 | */ 5118 | region?: string; 5119 | /** 5120 | * If known, the ISO 3166-2 code for the first-level region associated with 5121 | * the IP address of the incoming request 5122 | * 5123 | * @example "TX" 5124 | */ 5125 | regionCode?: string; 5126 | /** 5127 | * Metro code (DMA) of the incoming request 5128 | * 5129 | * @example "635" 5130 | */ 5131 | metroCode?: string; 5132 | } 5133 | /** Data about the incoming request's TLS certificate */ 5134 | interface IncomingRequestCfPropertiesTLSClientAuth { 5135 | /** Always `"1"`, indicating that the certificate was presented */ 5136 | certPresented: '1'; 5137 | /** 5138 | * Result of certificate verification. 5139 | * 5140 | * @example "FAILED:self signed certificate" 5141 | */ 5142 | certVerified: Exclude<CertVerificationStatus, 'NONE'>; 5143 | /** The presented certificate's revokation status. 5144 | * 5145 | * - A value of `"1"` indicates the certificate has been revoked 5146 | * - A value of `"0"` indicates the certificate has not been revoked 5147 | */ 5148 | certRevoked: '1' | '0'; 5149 | /** 5150 | * The certificate issuer's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) 5151 | * 5152 | * @example "CN=cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 5153 | */ 5154 | certIssuerDN: string; 5155 | /** 5156 | * The certificate subject's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) 5157 | * 5158 | * @example "CN=*.cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 5159 | */ 5160 | certSubjectDN: string; 5161 | /** 5162 | * The certificate issuer's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) ([RFC 2253](https://www.rfc-editor.org/rfc/rfc2253.html) formatted) 5163 | * 5164 | * @example "CN=cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 5165 | */ 5166 | certIssuerDNRFC2253: string; 5167 | /** 5168 | * The certificate subject's [distinguished name](https://knowledge.digicert.com/generalinformation/INFO1745.html) ([RFC 2253](https://www.rfc-editor.org/rfc/rfc2253.html) formatted) 5169 | * 5170 | * @example "CN=*.cloudflareaccess.com, C=US, ST=Texas, L=Austin, O=Cloudflare" 5171 | */ 5172 | certSubjectDNRFC2253: string; 5173 | /** The certificate issuer's distinguished name (legacy policies) */ 5174 | certIssuerDNLegacy: string; 5175 | /** The certificate subject's distinguished name (legacy policies) */ 5176 | certSubjectDNLegacy: string; 5177 | /** 5178 | * The certificate's serial number 5179 | * 5180 | * @example "00936EACBE07F201DF" 5181 | */ 5182 | certSerial: string; 5183 | /** 5184 | * The certificate issuer's serial number 5185 | * 5186 | * @example "2489002934BDFEA34" 5187 | */ 5188 | certIssuerSerial: string; 5189 | /** 5190 | * The certificate's Subject Key Identifier 5191 | * 5192 | * @example "BB:AF:7E:02:3D:FA:A6:F1:3C:84:8E:AD:EE:38:98:EC:D9:32:32:D4" 5193 | */ 5194 | certSKI: string; 5195 | /** 5196 | * The certificate issuer's Subject Key Identifier 5197 | * 5198 | * @example "BB:AF:7E:02:3D:FA:A6:F1:3C:84:8E:AD:EE:38:98:EC:D9:32:32:D4" 5199 | */ 5200 | certIssuerSKI: string; 5201 | /** 5202 | * The certificate's SHA-1 fingerprint 5203 | * 5204 | * @example "6b9109f323999e52259cda7373ff0b4d26bd232e" 5205 | */ 5206 | certFingerprintSHA1: string; 5207 | /** 5208 | * The certificate's SHA-256 fingerprint 5209 | * 5210 | * @example "acf77cf37b4156a2708e34c4eb755f9b5dbbe5ebb55adfec8f11493438d19e6ad3f157f81fa3b98278453d5652b0c1fd1d71e5695ae4d709803a4d3f39de9dea" 5211 | */ 5212 | certFingerprintSHA256: string; 5213 | /** 5214 | * The effective starting date of the certificate 5215 | * 5216 | * @example "Dec 22 19:39:00 2018 GMT" 5217 | */ 5218 | certNotBefore: string; 5219 | /** 5220 | * The effective expiration date of the certificate 5221 | * 5222 | * @example "Dec 22 19:39:00 2018 GMT" 5223 | */ 5224 | certNotAfter: string; 5225 | } 5226 | /** Placeholder values for TLS Client Authorization */ 5227 | interface IncomingRequestCfPropertiesTLSClientAuthPlaceholder { 5228 | certPresented: '0'; 5229 | certVerified: 'NONE'; 5230 | certRevoked: '0'; 5231 | certIssuerDN: ''; 5232 | certSubjectDN: ''; 5233 | certIssuerDNRFC2253: ''; 5234 | certSubjectDNRFC2253: ''; 5235 | certIssuerDNLegacy: ''; 5236 | certSubjectDNLegacy: ''; 5237 | certSerial: ''; 5238 | certIssuerSerial: ''; 5239 | certSKI: ''; 5240 | certIssuerSKI: ''; 5241 | certFingerprintSHA1: ''; 5242 | certFingerprintSHA256: ''; 5243 | certNotBefore: ''; 5244 | certNotAfter: ''; 5245 | } 5246 | /** Possible outcomes of TLS verification */ 5247 | declare type CertVerificationStatus = 5248 | /** Authentication succeeded */ 5249 | | 'SUCCESS' 5250 | /** No certificate was presented */ 5251 | | 'NONE' 5252 | /** Failed because the certificate was self-signed */ 5253 | | 'FAILED:self signed certificate' 5254 | /** Failed because the certificate failed a trust chain check */ 5255 | | 'FAILED:unable to verify the first certificate' 5256 | /** Failed because the certificate not yet valid */ 5257 | | 'FAILED:certificate is not yet valid' 5258 | /** Failed because the certificate is expired */ 5259 | | 'FAILED:certificate has expired' 5260 | /** Failed for another unspecified reason */ 5261 | | 'FAILED'; 5262 | /** 5263 | * An upstream endpoint's response to a TCP `keepalive` message from Cloudflare. 5264 | */ 5265 | declare type IncomingRequestCfPropertiesEdgeRequestKeepAliveStatus = 5266 | | 0 /** Unknown */ 5267 | | 1 /** no keepalives (not found) */ 5268 | | 2 /** no connection re-use, opening keepalive connection failed */ 5269 | | 3 /** no connection re-use, keepalive accepted and saved */ 5270 | | 4 /** connection re-use, refused by the origin server (`TCP FIN`) */ 5271 | | 5; /** connection re-use, accepted by the origin server */ 5272 | /** ISO 3166-1 Alpha-2 codes */ 5273 | declare type Iso3166Alpha2Code = 5274 | | 'AD' 5275 | | 'AE' 5276 | | 'AF' 5277 | | 'AG' 5278 | | 'AI' 5279 | | 'AL' 5280 | | 'AM' 5281 | | 'AO' 5282 | | 'AQ' 5283 | | 'AR' 5284 | | 'AS' 5285 | | 'AT' 5286 | | 'AU' 5287 | | 'AW' 5288 | | 'AX' 5289 | | 'AZ' 5290 | | 'BA' 5291 | | 'BB' 5292 | | 'BD' 5293 | | 'BE' 5294 | | 'BF' 5295 | | 'BG' 5296 | | 'BH' 5297 | | 'BI' 5298 | | 'BJ' 5299 | | 'BL' 5300 | | 'BM' 5301 | | 'BN' 5302 | | 'BO' 5303 | | 'BQ' 5304 | | 'BR' 5305 | | 'BS' 5306 | | 'BT' 5307 | | 'BV' 5308 | | 'BW' 5309 | | 'BY' 5310 | | 'BZ' 5311 | | 'CA' 5312 | | 'CC' 5313 | | 'CD' 5314 | | 'CF' 5315 | | 'CG' 5316 | | 'CH' 5317 | | 'CI' 5318 | | 'CK' 5319 | | 'CL' 5320 | | 'CM' 5321 | | 'CN' 5322 | | 'CO' 5323 | | 'CR' 5324 | | 'CU' 5325 | | 'CV' 5326 | | 'CW' 5327 | | 'CX' 5328 | | 'CY' 5329 | | 'CZ' 5330 | | 'DE' 5331 | | 'DJ' 5332 | | 'DK' 5333 | | 'DM' 5334 | | 'DO' 5335 | | 'DZ' 5336 | | 'EC' 5337 | | 'EE' 5338 | | 'EG' 5339 | | 'EH' 5340 | | 'ER' 5341 | | 'ES' 5342 | | 'ET' 5343 | | 'FI' 5344 | | 'FJ' 5345 | | 'FK' 5346 | | 'FM' 5347 | | 'FO' 5348 | | 'FR' 5349 | | 'GA' 5350 | | 'GB' 5351 | | 'GD' 5352 | | 'GE' 5353 | | 'GF' 5354 | | 'GG' 5355 | | 'GH' 5356 | | 'GI' 5357 | | 'GL' 5358 | | 'GM' 5359 | | 'GN' 5360 | | 'GP' 5361 | | 'GQ' 5362 | | 'GR' 5363 | | 'GS' 5364 | | 'GT' 5365 | | 'GU' 5366 | | 'GW' 5367 | | 'GY' 5368 | | 'HK' 5369 | | 'HM' 5370 | | 'HN' 5371 | | 'HR' 5372 | | 'HT' 5373 | | 'HU' 5374 | | 'ID' 5375 | | 'IE' 5376 | | 'IL' 5377 | | 'IM' 5378 | | 'IN' 5379 | | 'IO' 5380 | | 'IQ' 5381 | | 'IR' 5382 | | 'IS' 5383 | | 'IT' 5384 | | 'JE' 5385 | | 'JM' 5386 | | 'JO' 5387 | | 'JP' 5388 | | 'KE' 5389 | | 'KG' 5390 | | 'KH' 5391 | | 'KI' 5392 | | 'KM' 5393 | | 'KN' 5394 | | 'KP' 5395 | | 'KR' 5396 | | 'KW' 5397 | | 'KY' 5398 | | 'KZ' 5399 | | 'LA' 5400 | | 'LB' 5401 | | 'LC' 5402 | | 'LI' 5403 | | 'LK' 5404 | | 'LR' 5405 | | 'LS' 5406 | | 'LT' 5407 | | 'LU' 5408 | | 'LV' 5409 | | 'LY' 5410 | | 'MA' 5411 | | 'MC' 5412 | | 'MD' 5413 | | 'ME' 5414 | | 'MF' 5415 | | 'MG' 5416 | | 'MH' 5417 | | 'MK' 5418 | | 'ML' 5419 | | 'MM' 5420 | | 'MN' 5421 | | 'MO' 5422 | | 'MP' 5423 | | 'MQ' 5424 | | 'MR' 5425 | | 'MS' 5426 | | 'MT' 5427 | | 'MU' 5428 | | 'MV' 5429 | | 'MW' 5430 | | 'MX' 5431 | | 'MY' 5432 | | 'MZ' 5433 | | 'NA' 5434 | | 'NC' 5435 | | 'NE' 5436 | | 'NF' 5437 | | 'NG' 5438 | | 'NI' 5439 | | 'NL' 5440 | | 'NO' 5441 | | 'NP' 5442 | | 'NR' 5443 | | 'NU' 5444 | | 'NZ' 5445 | | 'OM' 5446 | | 'PA' 5447 | | 'PE' 5448 | | 'PF' 5449 | | 'PG' 5450 | | 'PH' 5451 | | 'PK' 5452 | | 'PL' 5453 | | 'PM' 5454 | | 'PN' 5455 | | 'PR' 5456 | | 'PS' 5457 | | 'PT' 5458 | | 'PW' 5459 | | 'PY' 5460 | | 'QA' 5461 | | 'RE' 5462 | | 'RO' 5463 | | 'RS' 5464 | | 'RU' 5465 | | 'RW' 5466 | | 'SA' 5467 | | 'SB' 5468 | | 'SC' 5469 | | 'SD' 5470 | | 'SE' 5471 | | 'SG' 5472 | | 'SH' 5473 | | 'SI' 5474 | | 'SJ' 5475 | | 'SK' 5476 | | 'SL' 5477 | | 'SM' 5478 | | 'SN' 5479 | | 'SO' 5480 | | 'SR' 5481 | | 'SS' 5482 | | 'ST' 5483 | | 'SV' 5484 | | 'SX' 5485 | | 'SY' 5486 | | 'SZ' 5487 | | 'TC' 5488 | | 'TD' 5489 | | 'TF' 5490 | | 'TG' 5491 | | 'TH' 5492 | | 'TJ' 5493 | | 'TK' 5494 | | 'TL' 5495 | | 'TM' 5496 | | 'TN' 5497 | | 'TO' 5498 | | 'TR' 5499 | | 'TT' 5500 | | 'TV' 5501 | | 'TW' 5502 | | 'TZ' 5503 | | 'UA' 5504 | | 'UG' 5505 | | 'UM' 5506 | | 'US' 5507 | | 'UY' 5508 | | 'UZ' 5509 | | 'VA' 5510 | | 'VC' 5511 | | 'VE' 5512 | | 'VG' 5513 | | 'VI' 5514 | | 'VN' 5515 | | 'VU' 5516 | | 'WF' 5517 | | 'WS' 5518 | | 'YE' 5519 | | 'YT' 5520 | | 'ZA' 5521 | | 'ZM' 5522 | | 'ZW'; 5523 | /** The 2-letter continent codes Cloudflare uses */ 5524 | declare type ContinentCode = 'AF' | 'AN' | 'AS' | 'EU' | 'NA' | 'OC' | 'SA'; 5525 | type CfProperties<HostMetadata = unknown> = 5526 | | IncomingRequestCfProperties<HostMetadata> 5527 | | RequestInitCfProperties; 5528 | interface D1Meta { 5529 | duration: number; 5530 | size_after: number; 5531 | rows_read: number; 5532 | rows_written: number; 5533 | last_row_id: number; 5534 | changed_db: boolean; 5535 | changes: number; 5536 | /** 5537 | * The region of the database instance that executed the query. 5538 | */ 5539 | served_by_region?: string; 5540 | /** 5541 | * True if-and-only-if the database instance that executed the query was the primary. 5542 | */ 5543 | served_by_primary?: boolean; 5544 | timings?: { 5545 | /** 5546 | * The duration of the SQL query execution by the database instance. It doesn't include any network time. 5547 | */ 5548 | sql_duration_ms: number; 5549 | }; 5550 | } 5551 | interface D1Response { 5552 | success: true; 5553 | meta: D1Meta & Record<string, unknown>; 5554 | error?: never; 5555 | } 5556 | type D1Result<T = unknown> = D1Response & { 5557 | results: T[]; 5558 | }; 5559 | interface D1ExecResult { 5560 | count: number; 5561 | duration: number; 5562 | } 5563 | type D1SessionConstraint = 5564 | // Indicates that the first query should go to the primary, and the rest queries 5565 | // using the same D1DatabaseSession will go to any replica that is consistent with 5566 | // the bookmark maintained by the session (returned by the first query). 5567 | | 'first-primary' 5568 | // Indicates that the first query can go anywhere (primary or replica), and the rest queries 5569 | // using the same D1DatabaseSession will go to any replica that is consistent with 5570 | // the bookmark maintained by the session (returned by the first query). 5571 | | 'first-unconstrained'; 5572 | type D1SessionBookmark = string; 5573 | declare abstract class D1Database { 5574 | prepare(query: string): D1PreparedStatement; 5575 | batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>; 5576 | exec(query: string): Promise<D1ExecResult>; 5577 | /** 5578 | * Creates a new D1 Session anchored at the given constraint or the bookmark. 5579 | * All queries executed using the created session will have sequential consistency, 5580 | * meaning that all writes done through the session will be visible in subsequent reads. 5581 | * 5582 | * @param constraintOrBookmark Either the session constraint or the explicit bookmark to anchor the created session. 5583 | */ 5584 | withSession( 5585 | constraintOrBookmark?: D1SessionBookmark | D1SessionConstraint 5586 | ): D1DatabaseSession; 5587 | /** 5588 | * @deprecated dump() will be removed soon, only applies to deprecated alpha v1 databases. 5589 | */ 5590 | dump(): Promise<ArrayBuffer>; 5591 | } 5592 | declare abstract class D1DatabaseSession { 5593 | prepare(query: string): D1PreparedStatement; 5594 | batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>; 5595 | /** 5596 | * @returns The latest session bookmark across all executed queries on the session. 5597 | * If no query has been executed yet, `null` is returned. 5598 | */ 5599 | getBookmark(): D1SessionBookmark | null; 5600 | } 5601 | declare abstract class D1PreparedStatement { 5602 | bind(...values: unknown[]): D1PreparedStatement; 5603 | first<T = unknown>(colName: string): Promise<T | null>; 5604 | first<T = Record<string, unknown>>(): Promise<T | null>; 5605 | run<T = Record<string, unknown>>(): Promise<D1Result<T>>; 5606 | all<T = Record<string, unknown>>(): Promise<D1Result<T>>; 5607 | raw<T = unknown[]>(options: {columnNames: true}): Promise<[string[], ...T[]]>; 5608 | raw<T = unknown[]>(options?: {columnNames?: false}): Promise<T[]>; 5609 | } 5610 | // `Disposable` was added to TypeScript's standard lib types in version 5.2. 5611 | // To support older TypeScript versions, define an empty `Disposable` interface. 5612 | // Users won't be able to use `using`/`Symbol.dispose` without upgrading to 5.2, 5613 | // but this will ensure type checking on older versions still passes. 5614 | // TypeScript's interface merging will ensure our empty interface is effectively 5615 | // ignored when `Disposable` is included in the standard lib. 5616 | interface Disposable {} 5617 | /** 5618 | * An email message that can be sent from a Worker. 5619 | */ 5620 | interface EmailMessage { 5621 | /** 5622 | * Envelope From attribute of the email message. 5623 | */ 5624 | readonly from: string; 5625 | /** 5626 | * Envelope To attribute of the email message. 5627 | */ 5628 | readonly to: string; 5629 | } 5630 | /** 5631 | * An email message that is sent to a consumer Worker and can be rejected/forwarded. 5632 | */ 5633 | interface ForwardableEmailMessage extends EmailMessage { 5634 | /** 5635 | * Stream of the email message content. 5636 | */ 5637 | readonly raw: ReadableStream<Uint8Array>; 5638 | /** 5639 | * An [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers). 5640 | */ 5641 | readonly headers: Headers; 5642 | /** 5643 | * Size of the email message content. 5644 | */ 5645 | readonly rawSize: number; 5646 | /** 5647 | * Reject this email message by returning a permanent SMTP error back to the connecting client including the given reason. 5648 | * @param reason The reject reason. 5649 | * @returns void 5650 | */ 5651 | setReject(reason: string): void; 5652 | /** 5653 | * Forward this email message to a verified destination address of the account. 5654 | * @param rcptTo Verified destination address. 5655 | * @param headers A [Headers object](https://developer.mozilla.org/en-US/docs/Web/API/Headers). 5656 | * @returns A promise that resolves when the email message is forwarded. 5657 | */ 5658 | forward(rcptTo: string, headers?: Headers): Promise<void>; 5659 | /** 5660 | * Reply to the sender of this email message with a new EmailMessage object. 5661 | * @param message The reply message. 5662 | * @returns A promise that resolves when the email message is replied. 5663 | */ 5664 | reply(message: EmailMessage): Promise<void>; 5665 | } 5666 | /** 5667 | * A binding that allows a Worker to send email messages. 5668 | */ 5669 | interface SendEmail { 5670 | send(message: EmailMessage): Promise<void>; 5671 | } 5672 | declare abstract class EmailEvent extends ExtendableEvent { 5673 | readonly message: ForwardableEmailMessage; 5674 | } 5675 | declare type EmailExportedHandler<Env = unknown> = ( 5676 | message: ForwardableEmailMessage, 5677 | env: Env, 5678 | ctx: ExecutionContext 5679 | ) => void | Promise<void>; 5680 | declare module 'cloudflare:email' { 5681 | let _EmailMessage: { 5682 | prototype: EmailMessage; 5683 | new (from: string, to: string, raw: ReadableStream | string): EmailMessage; 5684 | }; 5685 | export {_EmailMessage as EmailMessage}; 5686 | } 5687 | interface Hyperdrive { 5688 | /** 5689 | * Connect directly to Hyperdrive as if it's your database, returning a TCP socket. 5690 | * 5691 | * Calling this method returns an idential socket to if you call 5692 | * `connect("host:port")` using the `host` and `port` fields from this object. 5693 | * Pick whichever approach works better with your preferred DB client library. 5694 | * 5695 | * Note that this socket is not yet authenticated -- it's expected that your 5696 | * code (or preferably, the client library of your choice) will authenticate 5697 | * using the information in this class's readonly fields. 5698 | */ 5699 | connect(): Socket; 5700 | /** 5701 | * A valid DB connection string that can be passed straight into the typical 5702 | * client library/driver/ORM. This will typically be the easiest way to use 5703 | * Hyperdrive. 5704 | */ 5705 | readonly connectionString: string; 5706 | /* 5707 | * A randomly generated hostname that is only valid within the context of the 5708 | * currently running Worker which, when passed into `connect()` function from 5709 | * the "cloudflare:sockets" module, will connect to the Hyperdrive instance 5710 | * for your database. 5711 | */ 5712 | readonly host: string; 5713 | /* 5714 | * The port that must be paired the the host field when connecting. 5715 | */ 5716 | readonly port: number; 5717 | /* 5718 | * The username to use when authenticating to your database via Hyperdrive. 5719 | * Unlike the host and password, this will be the same every time 5720 | */ 5721 | readonly user: string; 5722 | /* 5723 | * The randomly generated password to use when authenticating to your 5724 | * database via Hyperdrive. Like the host field, this password is only valid 5725 | * within the context of the currently running Worker instance from which 5726 | * it's read. 5727 | */ 5728 | readonly password: string; 5729 | /* 5730 | * The name of the database to connect to. 5731 | */ 5732 | readonly database: string; 5733 | } 5734 | // Copyright (c) 2024 Cloudflare, Inc. 5735 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: 5736 | // https://opensource.org/licenses/Apache-2.0 5737 | type ImageInfoResponse = 5738 | | { 5739 | format: 'image/svg+xml'; 5740 | } 5741 | | { 5742 | format: string; 5743 | fileSize: number; 5744 | width: number; 5745 | height: number; 5746 | }; 5747 | type ImageTransform = { 5748 | width?: number; 5749 | height?: number; 5750 | background?: string; 5751 | blur?: number; 5752 | border?: 5753 | | { 5754 | color?: string; 5755 | width?: number; 5756 | } 5757 | | { 5758 | top?: number; 5759 | bottom?: number; 5760 | left?: number; 5761 | right?: number; 5762 | }; 5763 | brightness?: number; 5764 | contrast?: number; 5765 | fit?: 'scale-down' | 'contain' | 'pad' | 'squeeze' | 'cover' | 'crop'; 5766 | flip?: 'h' | 'v' | 'hv'; 5767 | gamma?: number; 5768 | gravity?: 5769 | | 'left' 5770 | | 'right' 5771 | | 'top' 5772 | | 'bottom' 5773 | | 'center' 5774 | | 'auto' 5775 | | 'entropy' 5776 | | { 5777 | x?: number; 5778 | y?: number; 5779 | mode: 'remainder' | 'box-center'; 5780 | }; 5781 | rotate?: 0 | 90 | 180 | 270; 5782 | saturation?: number; 5783 | sharpen?: number; 5784 | trim?: 5785 | | 'border' 5786 | | { 5787 | top?: number; 5788 | bottom?: number; 5789 | left?: number; 5790 | right?: number; 5791 | width?: number; 5792 | height?: number; 5793 | border?: 5794 | | boolean 5795 | | { 5796 | color?: string; 5797 | tolerance?: number; 5798 | keep?: number; 5799 | }; 5800 | }; 5801 | }; 5802 | type ImageDrawOptions = { 5803 | opacity?: number; 5804 | repeat?: boolean | string; 5805 | top?: number; 5806 | left?: number; 5807 | bottom?: number; 5808 | right?: number; 5809 | }; 5810 | type ImageOutputOptions = { 5811 | format: 5812 | | 'image/jpeg' 5813 | | 'image/png' 5814 | | 'image/gif' 5815 | | 'image/webp' 5816 | | 'image/avif' 5817 | | 'rgb' 5818 | | 'rgba'; 5819 | quality?: number; 5820 | background?: string; 5821 | }; 5822 | interface ImagesBinding { 5823 | /** 5824 | * Get image metadata (type, width and height) 5825 | * @throws {@link ImagesError} with code 9412 if input is not an image 5826 | * @param stream The image bytes 5827 | */ 5828 | info(stream: ReadableStream<Uint8Array>): Promise<ImageInfoResponse>; 5829 | /** 5830 | * Begin applying a series of transformations to an image 5831 | * @param stream The image bytes 5832 | * @returns A transform handle 5833 | */ 5834 | input(stream: ReadableStream<Uint8Array>): ImageTransformer; 5835 | } 5836 | interface ImageTransformer { 5837 | /** 5838 | * Apply transform next, returning a transform handle. 5839 | * You can then apply more transformations, draw, or retrieve the output. 5840 | * @param transform 5841 | */ 5842 | transform(transform: ImageTransform): ImageTransformer; 5843 | /** 5844 | * Draw an image on this transformer, returning a transform handle. 5845 | * You can then apply more transformations, draw, or retrieve the output. 5846 | * @param image The image (or transformer that will give the image) to draw 5847 | * @param options The options configuring how to draw the image 5848 | */ 5849 | draw( 5850 | image: ReadableStream<Uint8Array> | ImageTransformer, 5851 | options?: ImageDrawOptions 5852 | ): ImageTransformer; 5853 | /** 5854 | * Retrieve the image that results from applying the transforms to the 5855 | * provided input 5856 | * @param options Options that apply to the output e.g. output format 5857 | */ 5858 | output(options: ImageOutputOptions): Promise<ImageTransformationResult>; 5859 | } 5860 | interface ImageTransformationResult { 5861 | /** 5862 | * The image as a response, ready to store in cache or return to users 5863 | */ 5864 | response(): Response; 5865 | /** 5866 | * The content type of the returned image 5867 | */ 5868 | contentType(): string; 5869 | /** 5870 | * The bytes of the response 5871 | */ 5872 | image(): ReadableStream<Uint8Array>; 5873 | } 5874 | interface ImagesError extends Error { 5875 | readonly code: number; 5876 | readonly message: string; 5877 | readonly stack?: string; 5878 | } 5879 | type Params<P extends string = any> = Record<P, string | string[]>; 5880 | type EventContext<Env, P extends string, Data> = { 5881 | request: Request<unknown, IncomingRequestCfProperties<unknown>>; 5882 | functionPath: string; 5883 | waitUntil: (promise: Promise<any>) => void; 5884 | passThroughOnException: () => void; 5885 | next: (input?: Request | string, init?: RequestInit) => Promise<Response>; 5886 | env: Env & { 5887 | ASSETS: { 5888 | fetch: typeof fetch; 5889 | }; 5890 | }; 5891 | params: Params<P>; 5892 | data: Data; 5893 | }; 5894 | type PagesFunction< 5895 | Env = unknown, 5896 | Params extends string = any, 5897 | Data extends Record<string, unknown> = Record<string, unknown>, 5898 | > = (context: EventContext<Env, Params, Data>) => Response | Promise<Response>; 5899 | type EventPluginContext<Env, P extends string, Data, PluginArgs> = { 5900 | request: Request<unknown, IncomingRequestCfProperties<unknown>>; 5901 | functionPath: string; 5902 | waitUntil: (promise: Promise<any>) => void; 5903 | passThroughOnException: () => void; 5904 | next: (input?: Request | string, init?: RequestInit) => Promise<Response>; 5905 | env: Env & { 5906 | ASSETS: { 5907 | fetch: typeof fetch; 5908 | }; 5909 | }; 5910 | params: Params<P>; 5911 | data: Data; 5912 | pluginArgs: PluginArgs; 5913 | }; 5914 | type PagesPluginFunction< 5915 | Env = unknown, 5916 | Params extends string = any, 5917 | Data extends Record<string, unknown> = Record<string, unknown>, 5918 | PluginArgs = unknown, 5919 | > = ( 5920 | context: EventPluginContext<Env, Params, Data, PluginArgs> 5921 | ) => Response | Promise<Response>; 5922 | declare module 'assets:*' { 5923 | export const onRequest: PagesFunction; 5924 | } 5925 | // Copyright (c) 2022-2023 Cloudflare, Inc. 5926 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: 5927 | // https://opensource.org/licenses/Apache-2.0 5928 | declare module 'cloudflare:pipelines' { 5929 | export abstract class PipelineTransformationEntrypoint< 5930 | Env = unknown, 5931 | I extends PipelineRecord = PipelineRecord, 5932 | O extends PipelineRecord = PipelineRecord, 5933 | > { 5934 | protected env: Env; 5935 | protected ctx: ExecutionContext; 5936 | constructor(ctx: ExecutionContext, env: Env); 5937 | /** 5938 | * run recieves an array of PipelineRecord which can be 5939 | * transformed and returned to the pipeline 5940 | * @param records Incoming records from the pipeline to be transformed 5941 | * @param metadata Information about the specific pipeline calling the transformation entrypoint 5942 | * @returns A promise containing the transformed PipelineRecord array 5943 | */ 5944 | public run(records: I[], metadata: PipelineBatchMetadata): Promise<O[]>; 5945 | } 5946 | export type PipelineRecord = Record<string, unknown>; 5947 | export type PipelineBatchMetadata = { 5948 | pipelineId: string; 5949 | pipelineName: string; 5950 | }; 5951 | export interface Pipeline<T extends PipelineRecord = PipelineRecord> { 5952 | /** 5953 | * The Pipeline interface represents the type of a binding to a Pipeline 5954 | * 5955 | * @param records The records to send to the pipeline 5956 | */ 5957 | send(records: T[]): Promise<void>; 5958 | } 5959 | } 5960 | // PubSubMessage represents an incoming PubSub message. 5961 | // The message includes metadata about the broker, the client, and the payload 5962 | // itself. 5963 | // https://developers.cloudflare.com/pub-sub/ 5964 | interface PubSubMessage { 5965 | // Message ID 5966 | readonly mid: number; 5967 | // MQTT broker FQDN in the form mqtts://BROKER.NAMESPACE.cloudflarepubsub.com:PORT 5968 | readonly broker: string; 5969 | // The MQTT topic the message was sent on. 5970 | readonly topic: string; 5971 | // The client ID of the client that published this message. 5972 | readonly clientId: string; 5973 | // The unique identifier (JWT ID) used by the client to authenticate, if token 5974 | // auth was used. 5975 | readonly jti?: string; 5976 | // A Unix timestamp (seconds from Jan 1, 1970), set when the Pub/Sub Broker 5977 | // received the message from the client. 5978 | readonly receivedAt: number; 5979 | // An (optional) string with the MIME type of the payload, if set by the 5980 | // client. 5981 | readonly contentType: string; 5982 | // Set to 1 when the payload is a UTF-8 string 5983 | // https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901063 5984 | readonly payloadFormatIndicator: number; 5985 | // Pub/Sub (MQTT) payloads can be UTF-8 strings, or byte arrays. 5986 | // You can use payloadFormatIndicator to inspect this before decoding. 5987 | payload: string | Uint8Array; 5988 | } 5989 | // JsonWebKey extended by kid parameter 5990 | interface JsonWebKeyWithKid extends JsonWebKey { 5991 | // Key Identifier of the JWK 5992 | readonly kid: string; 5993 | } 5994 | interface RateLimitOptions { 5995 | key: string; 5996 | } 5997 | interface RateLimitOutcome { 5998 | success: boolean; 5999 | } 6000 | interface RateLimit { 6001 | /** 6002 | * Rate limit a request based on the provided options. 6003 | * @see https://developers.cloudflare.com/workers/runtime-apis/bindings/rate-limit/ 6004 | * @returns A promise that resolves with the outcome of the rate limit. 6005 | */ 6006 | limit(options: RateLimitOptions): Promise<RateLimitOutcome>; 6007 | } 6008 | // Namespace for RPC utility types. Unfortunately, we can't use a `module` here as these types need 6009 | // to referenced by `Fetcher`. This is included in the "importable" version of the types which 6010 | // strips all `module` blocks. 6011 | declare namespace Rpc { 6012 | // Branded types for identifying `WorkerEntrypoint`/`DurableObject`/`Target`s. 6013 | // TypeScript uses *structural* typing meaning anything with the same shape as type `T` is a `T`. 6014 | // For the classes exported by `cloudflare:workers` we want *nominal* typing (i.e. we only want to 6015 | // accept `WorkerEntrypoint` from `cloudflare:workers`, not any other class with the same shape) 6016 | export const __RPC_STUB_BRAND: '__RPC_STUB_BRAND'; 6017 | export const __RPC_TARGET_BRAND: '__RPC_TARGET_BRAND'; 6018 | export const __WORKER_ENTRYPOINT_BRAND: '__WORKER_ENTRYPOINT_BRAND'; 6019 | export const __DURABLE_OBJECT_BRAND: '__DURABLE_OBJECT_BRAND'; 6020 | export const __WORKFLOW_ENTRYPOINT_BRAND: '__WORKFLOW_ENTRYPOINT_BRAND'; 6021 | export interface RpcTargetBranded { 6022 | [__RPC_TARGET_BRAND]: never; 6023 | } 6024 | export interface WorkerEntrypointBranded { 6025 | [__WORKER_ENTRYPOINT_BRAND]: never; 6026 | } 6027 | export interface DurableObjectBranded { 6028 | [__DURABLE_OBJECT_BRAND]: never; 6029 | } 6030 | export interface WorkflowEntrypointBranded { 6031 | [__WORKFLOW_ENTRYPOINT_BRAND]: never; 6032 | } 6033 | export type EntrypointBranded = 6034 | | WorkerEntrypointBranded 6035 | | DurableObjectBranded 6036 | | WorkflowEntrypointBranded; 6037 | // Types that can be used through `Stub`s 6038 | export type Stubable = RpcTargetBranded | ((...args: any[]) => any); 6039 | // Types that can be passed over RPC 6040 | // The reason for using a generic type here is to build a serializable subset of structured 6041 | // cloneable composite types. This allows types defined with the "interface" keyword to pass the 6042 | // serializable check as well. Otherwise, only types defined with the "type" keyword would pass. 6043 | type Serializable<T> = 6044 | // Structured cloneables 6045 | | BaseType 6046 | // Structured cloneable composites 6047 | | Map< 6048 | T extends Map<infer U, unknown> ? Serializable<U> : never, 6049 | T extends Map<unknown, infer U> ? Serializable<U> : never 6050 | > 6051 | | Set<T extends Set<infer U> ? Serializable<U> : never> 6052 | | ReadonlyArray<T extends ReadonlyArray<infer U> ? Serializable<U> : never> 6053 | | { 6054 | [K in keyof T]: K extends number | string ? Serializable<T[K]> : never; 6055 | } 6056 | // Special types 6057 | | Stub<Stubable> 6058 | // Serialized as stubs, see `Stubify` 6059 | | Stubable; 6060 | // Base type for all RPC stubs, including common memory management methods. 6061 | // `T` is used as a marker type for unwrapping `Stub`s later. 6062 | interface StubBase<T extends Stubable> extends Disposable { 6063 | [__RPC_STUB_BRAND]: T; 6064 | dup(): this; 6065 | } 6066 | export type Stub<T extends Stubable> = Provider<T> & StubBase<T>; 6067 | // This represents all the types that can be sent as-is over an RPC boundary 6068 | type BaseType = 6069 | | void 6070 | | undefined 6071 | | null 6072 | | boolean 6073 | | number 6074 | | bigint 6075 | | string 6076 | | TypedArray 6077 | | ArrayBuffer 6078 | | DataView 6079 | | Date 6080 | | Error 6081 | | RegExp 6082 | | ReadableStream<Uint8Array> 6083 | | WritableStream<Uint8Array> 6084 | | Request 6085 | | Response 6086 | | Headers; 6087 | // Recursively rewrite all `Stubable` types with `Stub`s 6088 | // prettier-ignore 6089 | type Stubify<T> = T extends Stubable ? Stub<T> : T extends Map<infer K, infer V> ? Map<Stubify<K>, Stubify<V>> : T extends Set<infer V> ? Set<Stubify<V>> : T extends Array<infer V> ? Array<Stubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Stubify<V>> : T extends BaseType ? T : T extends { 6090 | [key: string | number]: any; 6091 | } ? { 6092 | [K in keyof T]: Stubify<T[K]>; 6093 | } : T; 6094 | // Recursively rewrite all `Stub<T>`s with the corresponding `T`s. 6095 | // Note we use `StubBase` instead of `Stub` here to avoid circular dependencies: 6096 | // `Stub` depends on `Provider`, which depends on `Unstubify`, which would depend on `Stub`. 6097 | // prettier-ignore 6098 | type Unstubify<T> = T extends StubBase<infer V> ? V : T extends Map<infer K, infer V> ? Map<Unstubify<K>, Unstubify<V>> : T extends Set<infer V> ? Set<Unstubify<V>> : T extends Array<infer V> ? Array<Unstubify<V>> : T extends ReadonlyArray<infer V> ? ReadonlyArray<Unstubify<V>> : T extends BaseType ? T : T extends { 6099 | [key: string | number]: unknown; 6100 | } ? { 6101 | [K in keyof T]: Unstubify<T[K]>; 6102 | } : T; 6103 | type UnstubifyAll<A extends any[]> = { 6104 | [I in keyof A]: Unstubify<A[I]>; 6105 | }; 6106 | // Utility type for adding `Provider`/`Disposable`s to `object` types only. 6107 | // Note `unknown & T` is equivalent to `T`. 6108 | type MaybeProvider<T> = T extends object ? Provider<T> : unknown; 6109 | type MaybeDisposable<T> = T extends object ? Disposable : unknown; 6110 | // Type for method return or property on an RPC interface. 6111 | // - Stubable types are replaced by stubs. 6112 | // - Serializable types are passed by value, with stubable types replaced by stubs 6113 | // and a top-level `Disposer`. 6114 | // Everything else can't be passed over PRC. 6115 | // Technically, we use custom thenables here, but they quack like `Promise`s. 6116 | // Intersecting with `(Maybe)Provider` allows pipelining. 6117 | // prettier-ignore 6118 | type Result<R> = R extends Stubable ? Promise<Stub<R>> & Provider<R> : R extends Serializable<R> ? Promise<Stubify<R> & MaybeDisposable<R>> & MaybeProvider<R> : never; 6119 | // Type for method or property on an RPC interface. 6120 | // For methods, unwrap `Stub`s in parameters, and rewrite returns to be `Result`s. 6121 | // Unwrapping `Stub`s allows calling with `Stubable` arguments. 6122 | // For properties, rewrite types to be `Result`s. 6123 | // In each case, unwrap `Promise`s. 6124 | type MethodOrProperty<V> = V extends (...args: infer P) => infer R 6125 | ? (...args: UnstubifyAll<P>) => Result<Awaited<R>> 6126 | : Result<Awaited<V>>; 6127 | // Type for the callable part of an `Provider` if `T` is callable. 6128 | // This is intersected with methods/properties. 6129 | type MaybeCallableProvider<T> = T extends (...args: any[]) => any 6130 | ? MethodOrProperty<T> 6131 | : unknown; 6132 | // Base type for all other types providing RPC-like interfaces. 6133 | // Rewrites all methods/properties to be `MethodOrProperty`s, while preserving callable types. 6134 | // `Reserved` names (e.g. stub method names like `dup()`) and symbols can't be accessed over RPC. 6135 | export type Provider< 6136 | T extends object, 6137 | Reserved extends string = never, 6138 | > = MaybeCallableProvider<T> & { 6139 | [K in Exclude< 6140 | keyof T, 6141 | Reserved | symbol | keyof StubBase<never> 6142 | >]: MethodOrProperty<T[K]>; 6143 | }; 6144 | } 6145 | declare namespace Cloudflare { 6146 | interface Env {} 6147 | } 6148 | declare module 'cloudflare:workers' { 6149 | export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>; 6150 | export const RpcStub: { 6151 | new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>; 6152 | }; 6153 | export abstract class RpcTarget implements Rpc.RpcTargetBranded { 6154 | [Rpc.__RPC_TARGET_BRAND]: never; 6155 | } 6156 | // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC 6157 | export abstract class WorkerEntrypoint<Env = unknown> 6158 | implements Rpc.WorkerEntrypointBranded 6159 | { 6160 | [Rpc.__WORKER_ENTRYPOINT_BRAND]: never; 6161 | protected ctx: ExecutionContext; 6162 | protected env: Env; 6163 | constructor(ctx: ExecutionContext, env: Env); 6164 | fetch?(request: Request): Response | Promise<Response>; 6165 | tail?(events: TraceItem[]): void | Promise<void>; 6166 | trace?(traces: TraceItem[]): void | Promise<void>; 6167 | scheduled?(controller: ScheduledController): void | Promise<void>; 6168 | queue?(batch: MessageBatch<unknown>): void | Promise<void>; 6169 | test?(controller: TestController): void | Promise<void>; 6170 | } 6171 | export abstract class DurableObject<Env = unknown> 6172 | implements Rpc.DurableObjectBranded 6173 | { 6174 | [Rpc.__DURABLE_OBJECT_BRAND]: never; 6175 | protected ctx: DurableObjectState; 6176 | protected env: Env; 6177 | constructor(ctx: DurableObjectState, env: Env); 6178 | fetch?(request: Request): Response | Promise<Response>; 6179 | alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>; 6180 | webSocketMessage?( 6181 | ws: WebSocket, 6182 | message: string | ArrayBuffer 6183 | ): void | Promise<void>; 6184 | webSocketClose?( 6185 | ws: WebSocket, 6186 | code: number, 6187 | reason: string, 6188 | wasClean: boolean 6189 | ): void | Promise<void>; 6190 | webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>; 6191 | } 6192 | export type WorkflowDurationLabel = 6193 | | 'second' 6194 | | 'minute' 6195 | | 'hour' 6196 | | 'day' 6197 | | 'week' 6198 | | 'month' 6199 | | 'year'; 6200 | export type WorkflowSleepDuration = 6201 | | `${number} ${WorkflowDurationLabel}${'s' | ''}` 6202 | | number; 6203 | export type WorkflowDelayDuration = WorkflowSleepDuration; 6204 | export type WorkflowTimeoutDuration = WorkflowSleepDuration; 6205 | export type WorkflowBackoff = 'constant' | 'linear' | 'exponential'; 6206 | export type WorkflowStepConfig = { 6207 | retries?: { 6208 | limit: number; 6209 | delay: WorkflowDelayDuration | number; 6210 | backoff?: WorkflowBackoff; 6211 | }; 6212 | timeout?: WorkflowTimeoutDuration | number; 6213 | }; 6214 | export type WorkflowEvent<T> = { 6215 | payload: Readonly<T>; 6216 | timestamp: Date; 6217 | instanceId: string; 6218 | }; 6219 | export type WorkflowStepEvent<T> = { 6220 | payload: Readonly<T>; 6221 | timestamp: Date; 6222 | type: string; 6223 | }; 6224 | export abstract class WorkflowStep { 6225 | do<T extends Rpc.Serializable<T>>( 6226 | name: string, 6227 | callback: () => Promise<T> 6228 | ): Promise<T>; 6229 | do<T extends Rpc.Serializable<T>>( 6230 | name: string, 6231 | config: WorkflowStepConfig, 6232 | callback: () => Promise<T> 6233 | ): Promise<T>; 6234 | sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>; 6235 | sleepUntil: (name: string, timestamp: Date | number) => Promise<void>; 6236 | waitForEvent<T extends Rpc.Serializable<T>>( 6237 | name: string, 6238 | options: { 6239 | type: string; 6240 | timeout?: WorkflowTimeoutDuration | number; 6241 | } 6242 | ): Promise<WorkflowStepEvent<T>>; 6243 | } 6244 | export abstract class WorkflowEntrypoint< 6245 | Env = unknown, 6246 | T extends Rpc.Serializable<T> | unknown = unknown, 6247 | > implements Rpc.WorkflowEntrypointBranded 6248 | { 6249 | [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never; 6250 | protected ctx: ExecutionContext; 6251 | protected env: Env; 6252 | constructor(ctx: ExecutionContext, env: Env); 6253 | run( 6254 | event: Readonly<WorkflowEvent<T>>, 6255 | step: WorkflowStep 6256 | ): Promise<unknown>; 6257 | } 6258 | export const env: Cloudflare.Env; 6259 | } 6260 | interface SecretsStoreSecret { 6261 | /** 6262 | * Get a secret from the Secrets Store, returning a string of the secret value 6263 | * if it exists, or throws an error if it does not exist 6264 | */ 6265 | get(): Promise<string>; 6266 | } 6267 | declare module 'cloudflare:sockets' { 6268 | function _connect( 6269 | address: string | SocketAddress, 6270 | options?: SocketOptions 6271 | ): Socket; 6272 | export {_connect as connect}; 6273 | } 6274 | declare namespace TailStream { 6275 | interface Header { 6276 | readonly name: string; 6277 | readonly value: string; 6278 | } 6279 | interface FetchEventInfo { 6280 | readonly type: 'fetch'; 6281 | readonly method: string; 6282 | readonly url: string; 6283 | readonly cfJson: string; 6284 | readonly headers: Header[]; 6285 | } 6286 | interface JsRpcEventInfo { 6287 | readonly type: 'jsrpc'; 6288 | readonly methodName: string; 6289 | } 6290 | interface ScheduledEventInfo { 6291 | readonly type: 'scheduled'; 6292 | readonly scheduledTime: Date; 6293 | readonly cron: string; 6294 | } 6295 | interface AlarmEventInfo { 6296 | readonly type: 'alarm'; 6297 | readonly scheduledTime: Date; 6298 | } 6299 | interface QueueEventInfo { 6300 | readonly type: 'queue'; 6301 | readonly queueName: string; 6302 | readonly batchSize: number; 6303 | } 6304 | interface EmailEventInfo { 6305 | readonly type: 'email'; 6306 | readonly mailFrom: string; 6307 | readonly rcptTo: string; 6308 | readonly rawSize: number; 6309 | } 6310 | interface TraceEventInfo { 6311 | readonly type: 'trace'; 6312 | readonly traces: (string | null)[]; 6313 | } 6314 | interface HibernatableWebSocketEventInfoMessage { 6315 | readonly type: 'message'; 6316 | } 6317 | interface HibernatableWebSocketEventInfoError { 6318 | readonly type: 'error'; 6319 | } 6320 | interface HibernatableWebSocketEventInfoClose { 6321 | readonly type: 'close'; 6322 | readonly code: number; 6323 | readonly wasClean: boolean; 6324 | } 6325 | interface HibernatableWebSocketEventInfo { 6326 | readonly type: 'hibernatableWebSocket'; 6327 | readonly info: 6328 | | HibernatableWebSocketEventInfoClose 6329 | | HibernatableWebSocketEventInfoError 6330 | | HibernatableWebSocketEventInfoMessage; 6331 | } 6332 | interface Resume { 6333 | readonly type: 'resume'; 6334 | readonly attachment?: any; 6335 | } 6336 | interface CustomEventInfo { 6337 | readonly type: 'custom'; 6338 | } 6339 | interface FetchResponseInfo { 6340 | readonly type: 'fetch'; 6341 | readonly statusCode: number; 6342 | } 6343 | type EventOutcome = 6344 | | 'ok' 6345 | | 'canceled' 6346 | | 'exception' 6347 | | 'unknown' 6348 | | 'killSwitch' 6349 | | 'daemonDown' 6350 | | 'exceededCpu' 6351 | | 'exceededMemory' 6352 | | 'loadShed' 6353 | | 'responseStreamDisconnected' 6354 | | 'scriptNotFound'; 6355 | interface ScriptVersion { 6356 | readonly id: string; 6357 | readonly tag?: string; 6358 | readonly message?: string; 6359 | } 6360 | interface Trigger { 6361 | readonly traceId: string; 6362 | readonly invocationId: string; 6363 | readonly spanId: string; 6364 | } 6365 | interface Onset { 6366 | readonly type: 'onset'; 6367 | readonly dispatchNamespace?: string; 6368 | readonly entrypoint?: string; 6369 | readonly scriptName?: string; 6370 | readonly scriptTags?: string[]; 6371 | readonly scriptVersion?: ScriptVersion; 6372 | readonly trigger?: Trigger; 6373 | readonly info: 6374 | | FetchEventInfo 6375 | | JsRpcEventInfo 6376 | | ScheduledEventInfo 6377 | | AlarmEventInfo 6378 | | QueueEventInfo 6379 | | EmailEventInfo 6380 | | TraceEventInfo 6381 | | HibernatableWebSocketEventInfo 6382 | | Resume 6383 | | CustomEventInfo; 6384 | } 6385 | interface Outcome { 6386 | readonly type: 'outcome'; 6387 | readonly outcome: EventOutcome; 6388 | readonly cpuTime: number; 6389 | readonly wallTime: number; 6390 | } 6391 | interface Hibernate { 6392 | readonly type: 'hibernate'; 6393 | } 6394 | interface SpanOpen { 6395 | readonly type: 'spanOpen'; 6396 | readonly op?: string; 6397 | readonly info?: FetchEventInfo | JsRpcEventInfo | Attribute[]; 6398 | } 6399 | interface SpanClose { 6400 | readonly type: 'spanClose'; 6401 | readonly outcome: EventOutcome; 6402 | } 6403 | interface DiagnosticChannelEvent { 6404 | readonly type: 'diagnosticChannel'; 6405 | readonly channel: string; 6406 | readonly message: any; 6407 | } 6408 | interface Exception { 6409 | readonly type: 'exception'; 6410 | readonly name: string; 6411 | readonly message: string; 6412 | readonly stack?: string; 6413 | } 6414 | interface Log { 6415 | readonly type: 'log'; 6416 | readonly level: 'debug' | 'error' | 'info' | 'log' | 'warn'; 6417 | readonly message: string; 6418 | } 6419 | interface Return { 6420 | readonly type: 'return'; 6421 | readonly info?: FetchResponseInfo | Attribute[]; 6422 | } 6423 | interface Link { 6424 | readonly type: 'link'; 6425 | readonly label?: string; 6426 | readonly traceId: string; 6427 | readonly invocationId: string; 6428 | readonly spanId: string; 6429 | } 6430 | interface Attribute { 6431 | readonly type: 'attribute'; 6432 | readonly name: string; 6433 | readonly value: string | string[] | boolean | boolean[] | number | number[]; 6434 | } 6435 | type Mark = 6436 | | DiagnosticChannelEvent 6437 | | Exception 6438 | | Log 6439 | | Return 6440 | | Link 6441 | | Attribute[]; 6442 | interface TailEvent { 6443 | readonly traceId: string; 6444 | readonly invocationId: string; 6445 | readonly spanId: string; 6446 | readonly timestamp: Date; 6447 | readonly sequence: number; 6448 | readonly event: Onset | Outcome | Hibernate | SpanOpen | SpanClose | Mark; 6449 | } 6450 | type TailEventHandler = (event: TailEvent) => void | Promise<void>; 6451 | type TailEventHandlerName = 6452 | | 'onset' 6453 | | 'outcome' 6454 | | 'hibernate' 6455 | | 'spanOpen' 6456 | | 'spanClose' 6457 | | 'diagnosticChannel' 6458 | | 'exception' 6459 | | 'log' 6460 | | 'return' 6461 | | 'link' 6462 | | 'attribute'; 6463 | type TailEventHandlerObject = Record<TailEventHandlerName, TailEventHandler>; 6464 | type TailEventHandlerType = TailEventHandler | TailEventHandlerObject; 6465 | } 6466 | // Copyright (c) 2022-2023 Cloudflare, Inc. 6467 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: 6468 | // https://opensource.org/licenses/Apache-2.0 6469 | /** 6470 | * Data types supported for holding vector metadata. 6471 | */ 6472 | type VectorizeVectorMetadataValue = string | number | boolean | string[]; 6473 | /** 6474 | * Additional information to associate with a vector. 6475 | */ 6476 | type VectorizeVectorMetadata = 6477 | | VectorizeVectorMetadataValue 6478 | | Record<string, VectorizeVectorMetadataValue>; 6479 | type VectorFloatArray = Float32Array | Float64Array; 6480 | interface VectorizeError { 6481 | code?: number; 6482 | error: string; 6483 | } 6484 | /** 6485 | * Comparison logic/operation to use for metadata filtering. 6486 | * 6487 | * This list is expected to grow as support for more operations are released. 6488 | */ 6489 | type VectorizeVectorMetadataFilterOp = '$eq' | '$ne'; 6490 | /** 6491 | * Filter criteria for vector metadata used to limit the retrieved query result set. 6492 | */ 6493 | type VectorizeVectorMetadataFilter = { 6494 | [field: string]: 6495 | | Exclude<VectorizeVectorMetadataValue, string[]> 6496 | | null 6497 | | { 6498 | [Op in VectorizeVectorMetadataFilterOp]?: Exclude< 6499 | VectorizeVectorMetadataValue, 6500 | string[] 6501 | > | null; 6502 | }; 6503 | }; 6504 | /** 6505 | * Supported distance metrics for an index. 6506 | * Distance metrics determine how other "similar" vectors are determined. 6507 | */ 6508 | type VectorizeDistanceMetric = 'euclidean' | 'cosine' | 'dot-product'; 6509 | /** 6510 | * Metadata return levels for a Vectorize query. 6511 | * 6512 | * Default to "none". 6513 | * 6514 | * @property all Full metadata for the vector return set, including all fields (including those un-indexed) without truncation. This is a more expensive retrieval, as it requires additional fetching & reading of un-indexed data. 6515 | * @property indexed Return all metadata fields configured for indexing in the vector return set. This level of retrieval is "free" in that no additional overhead is incurred returning this data. However, note that indexed metadata is subject to truncation (especially for larger strings). 6516 | * @property none No indexed metadata will be returned. 6517 | */ 6518 | type VectorizeMetadataRetrievalLevel = 'all' | 'indexed' | 'none'; 6519 | interface VectorizeQueryOptions { 6520 | topK?: number; 6521 | namespace?: string; 6522 | returnValues?: boolean; 6523 | returnMetadata?: boolean | VectorizeMetadataRetrievalLevel; 6524 | filter?: VectorizeVectorMetadataFilter; 6525 | } 6526 | /** 6527 | * Information about the configuration of an index. 6528 | */ 6529 | type VectorizeIndexConfig = 6530 | | { 6531 | dimensions: number; 6532 | metric: VectorizeDistanceMetric; 6533 | } 6534 | | { 6535 | preset: string; // keep this generic, as we'll be adding more presets in the future and this is only in a read capacity 6536 | }; 6537 | /** 6538 | * Metadata about an existing index. 6539 | * 6540 | * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released. 6541 | * See {@link VectorizeIndexInfo} for its post-beta equivalent. 6542 | */ 6543 | interface VectorizeIndexDetails { 6544 | /** The unique ID of the index */ 6545 | readonly id: string; 6546 | /** The name of the index. */ 6547 | name: string; 6548 | /** (optional) A human readable description for the index. */ 6549 | description?: string; 6550 | /** The index configuration, including the dimension size and distance metric. */ 6551 | config: VectorizeIndexConfig; 6552 | /** The number of records containing vectors within the index. */ 6553 | vectorsCount: number; 6554 | } 6555 | /** 6556 | * Metadata about an existing index. 6557 | */ 6558 | interface VectorizeIndexInfo { 6559 | /** The number of records containing vectors within the index. */ 6560 | vectorCount: number; 6561 | /** Number of dimensions the index has been configured for. */ 6562 | dimensions: number; 6563 | /** ISO 8601 datetime of the last processed mutation on in the index. All changes before this mutation will be reflected in the index state. */ 6564 | processedUpToDatetime: number; 6565 | /** UUIDv4 of the last mutation processed by the index. All changes before this mutation will be reflected in the index state. */ 6566 | processedUpToMutation: number; 6567 | } 6568 | /** 6569 | * Represents a single vector value set along with its associated metadata. 6570 | */ 6571 | interface VectorizeVector { 6572 | /** The ID for the vector. This can be user-defined, and must be unique. It should uniquely identify the object, and is best set based on the ID of what the vector represents. */ 6573 | id: string; 6574 | /** The vector values */ 6575 | values: VectorFloatArray | number[]; 6576 | /** The namespace this vector belongs to. */ 6577 | namespace?: string; 6578 | /** Metadata associated with the vector. Includes the values of other fields and potentially additional details. */ 6579 | metadata?: Record<string, VectorizeVectorMetadata>; 6580 | } 6581 | /** 6582 | * Represents a matched vector for a query along with its score and (if specified) the matching vector information. 6583 | */ 6584 | type VectorizeMatch = Pick<Partial<VectorizeVector>, 'values'> & 6585 | Omit<VectorizeVector, 'values'> & { 6586 | /** The score or rank for similarity, when returned as a result */ 6587 | score: number; 6588 | }; 6589 | /** 6590 | * A set of matching {@link VectorizeMatch} for a particular query. 6591 | */ 6592 | interface VectorizeMatches { 6593 | matches: VectorizeMatch[]; 6594 | count: number; 6595 | } 6596 | /** 6597 | * Results of an operation that performed a mutation on a set of vectors. 6598 | * Here, `ids` is a list of vectors that were successfully processed. 6599 | * 6600 | * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released. 6601 | * See {@link VectorizeAsyncMutation} for its post-beta equivalent. 6602 | */ 6603 | interface VectorizeVectorMutation { 6604 | /* List of ids of vectors that were successfully processed. */ 6605 | ids: string[]; 6606 | /* Total count of the number of processed vectors. */ 6607 | count: number; 6608 | } 6609 | /** 6610 | * Result type indicating a mutation on the Vectorize Index. 6611 | * Actual mutations are processed async where the `mutationId` is the unique identifier for the operation. 6612 | */ 6613 | interface VectorizeAsyncMutation { 6614 | /** The unique identifier for the async mutation operation containing the changeset. */ 6615 | mutationId: string; 6616 | } 6617 | /** 6618 | * A Vectorize Vector Search Index for querying vectors/embeddings. 6619 | * 6620 | * This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released. 6621 | * See {@link Vectorize} for its new implementation. 6622 | */ 6623 | declare abstract class VectorizeIndex { 6624 | /** 6625 | * Get information about the currently bound index. 6626 | * @returns A promise that resolves with information about the current index. 6627 | */ 6628 | public describe(): Promise<VectorizeIndexDetails>; 6629 | /** 6630 | * Use the provided vector to perform a similarity search across the index. 6631 | * @param vector Input vector that will be used to drive the similarity search. 6632 | * @param options Configuration options to massage the returned data. 6633 | * @returns A promise that resolves with matched and scored vectors. 6634 | */ 6635 | public query( 6636 | vector: VectorFloatArray | number[], 6637 | options?: VectorizeQueryOptions 6638 | ): Promise<VectorizeMatches>; 6639 | /** 6640 | * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown. 6641 | * @param vectors List of vectors that will be inserted. 6642 | * @returns A promise that resolves with the ids & count of records that were successfully processed. 6643 | */ 6644 | public insert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation>; 6645 | /** 6646 | * Upsert a list of vectors into the index dataset. If a provided id exists, it will be replaced with the new values. 6647 | * @param vectors List of vectors that will be upserted. 6648 | * @returns A promise that resolves with the ids & count of records that were successfully processed. 6649 | */ 6650 | public upsert(vectors: VectorizeVector[]): Promise<VectorizeVectorMutation>; 6651 | /** 6652 | * Delete a list of vectors with a matching id. 6653 | * @param ids List of vector ids that should be deleted. 6654 | * @returns A promise that resolves with the ids & count of records that were successfully processed (and thus deleted). 6655 | */ 6656 | public deleteByIds(ids: string[]): Promise<VectorizeVectorMutation>; 6657 | /** 6658 | * Get a list of vectors with a matching id. 6659 | * @param ids List of vector ids that should be returned. 6660 | * @returns A promise that resolves with the raw unscored vectors matching the id set. 6661 | */ 6662 | public getByIds(ids: string[]): Promise<VectorizeVector[]>; 6663 | } 6664 | /** 6665 | * A Vectorize Vector Search Index for querying vectors/embeddings. 6666 | * 6667 | * Mutations in this version are async, returning a mutation id. 6668 | */ 6669 | declare abstract class Vectorize { 6670 | /** 6671 | * Get information about the currently bound index. 6672 | * @returns A promise that resolves with information about the current index. 6673 | */ 6674 | public describe(): Promise<VectorizeIndexInfo>; 6675 | /** 6676 | * Use the provided vector to perform a similarity search across the index. 6677 | * @param vector Input vector that will be used to drive the similarity search. 6678 | * @param options Configuration options to massage the returned data. 6679 | * @returns A promise that resolves with matched and scored vectors. 6680 | */ 6681 | public query( 6682 | vector: VectorFloatArray | number[], 6683 | options?: VectorizeQueryOptions 6684 | ): Promise<VectorizeMatches>; 6685 | /** 6686 | * Use the provided vector-id to perform a similarity search across the index. 6687 | * @param vectorId Id for a vector in the index against which the index should be queried. 6688 | * @param options Configuration options to massage the returned data. 6689 | * @returns A promise that resolves with matched and scored vectors. 6690 | */ 6691 | public queryById( 6692 | vectorId: string, 6693 | options?: VectorizeQueryOptions 6694 | ): Promise<VectorizeMatches>; 6695 | /** 6696 | * Insert a list of vectors into the index dataset. If a provided id exists, an error will be thrown. 6697 | * @param vectors List of vectors that will be inserted. 6698 | * @returns A promise that resolves with a unique identifier of a mutation containing the insert changeset. 6699 | */ 6700 | public insert(vectors: VectorizeVector[]): Promise<VectorizeAsyncMutation>; 6701 | /** 6702 | * Upsert a list of vectors into the index dataset. If a provided id exists, it will be replaced with the new values. 6703 | * @param vectors List of vectors that will be upserted. 6704 | * @returns A promise that resolves with a unique identifier of a mutation containing the upsert changeset. 6705 | */ 6706 | public upsert(vectors: VectorizeVector[]): Promise<VectorizeAsyncMutation>; 6707 | /** 6708 | * Delete a list of vectors with a matching id. 6709 | * @param ids List of vector ids that should be deleted. 6710 | * @returns A promise that resolves with a unique identifier of a mutation containing the delete changeset. 6711 | */ 6712 | public deleteByIds(ids: string[]): Promise<VectorizeAsyncMutation>; 6713 | /** 6714 | * Get a list of vectors with a matching id. 6715 | * @param ids List of vector ids that should be returned. 6716 | * @returns A promise that resolves with the raw unscored vectors matching the id set. 6717 | */ 6718 | public getByIds(ids: string[]): Promise<VectorizeVector[]>; 6719 | } 6720 | /** 6721 | * The interface for "version_metadata" binding 6722 | * providing metadata about the Worker Version using this binding. 6723 | */ 6724 | type WorkerVersionMetadata = { 6725 | /** The ID of the Worker Version using this binding */ 6726 | id: string; 6727 | /** The tag of the Worker Version using this binding */ 6728 | tag: string; 6729 | /** The timestamp of when the Worker Version was uploaded */ 6730 | timestamp: string; 6731 | }; 6732 | interface DynamicDispatchLimits { 6733 | /** 6734 | * Limit CPU time in milliseconds. 6735 | */ 6736 | cpuMs?: number; 6737 | /** 6738 | * Limit number of subrequests. 6739 | */ 6740 | subRequests?: number; 6741 | } 6742 | interface DynamicDispatchOptions { 6743 | /** 6744 | * Limit resources of invoked Worker script. 6745 | */ 6746 | limits?: DynamicDispatchLimits; 6747 | /** 6748 | * Arguments for outbound Worker script, if configured. 6749 | */ 6750 | outbound?: { 6751 | [key: string]: any; 6752 | }; 6753 | } 6754 | interface DispatchNamespace { 6755 | /** 6756 | * @param name Name of the Worker script. 6757 | * @param args Arguments to Worker script. 6758 | * @param options Options for Dynamic Dispatch invocation. 6759 | * @returns A Fetcher object that allows you to send requests to the Worker script. 6760 | * @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown. 6761 | */ 6762 | get( 6763 | name: string, 6764 | args?: { 6765 | [key: string]: any; 6766 | }, 6767 | options?: DynamicDispatchOptions 6768 | ): Fetcher; 6769 | } 6770 | declare module 'cloudflare:workflows' { 6771 | /** 6772 | * NonRetryableError allows for a user to throw a fatal error 6773 | * that makes a Workflow instance fail immediately without triggering a retry 6774 | */ 6775 | export class NonRetryableError extends Error { 6776 | public constructor(message: string, name?: string); 6777 | } 6778 | } 6779 | declare abstract class Workflow<PARAMS = unknown> { 6780 | /** 6781 | * Get a handle to an existing instance of the Workflow. 6782 | * @param id Id for the instance of this Workflow 6783 | * @returns A promise that resolves with a handle for the Instance 6784 | */ 6785 | public get(id: string): Promise<WorkflowInstance>; 6786 | /** 6787 | * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown. 6788 | * @param options Options when creating an instance including id and params 6789 | * @returns A promise that resolves with a handle for the Instance 6790 | */ 6791 | public create( 6792 | options?: WorkflowInstanceCreateOptions<PARAMS> 6793 | ): Promise<WorkflowInstance>; 6794 | /** 6795 | * Create a batch of instances and return handle for all of them. If a provided id exists, an error will be thrown. 6796 | * `createBatch` is limited at 100 instances at a time or when the RPC limit for the batch (1MiB) is reached. 6797 | * @param batch List of Options when creating an instance including name and params 6798 | * @returns A promise that resolves with a list of handles for the created instances. 6799 | */ 6800 | public createBatch( 6801 | batch: WorkflowInstanceCreateOptions<PARAMS>[] 6802 | ): Promise<WorkflowInstance[]>; 6803 | } 6804 | interface WorkflowInstanceCreateOptions<PARAMS = unknown> { 6805 | /** 6806 | * An id for your Workflow instance. Must be unique within the Workflow. 6807 | */ 6808 | id?: string; 6809 | /** 6810 | * The event payload the Workflow instance is triggered with 6811 | */ 6812 | params?: PARAMS; 6813 | } 6814 | type InstanceStatus = { 6815 | status: 6816 | | 'queued' // means that instance is waiting to be started (see concurrency limits) 6817 | | 'running' 6818 | | 'paused' 6819 | | 'errored' 6820 | | 'terminated' // user terminated the instance while it was running 6821 | | 'complete' 6822 | | 'waiting' // instance is hibernating and waiting for sleep or event to finish 6823 | | 'waitingForPause' // instance is finishing the current work to pause 6824 | | 'unknown'; 6825 | error?: string; 6826 | output?: object; 6827 | }; 6828 | interface WorkflowError { 6829 | code?: number; 6830 | message: string; 6831 | } 6832 | declare abstract class WorkflowInstance { 6833 | public id: string; 6834 | /** 6835 | * Pause the instance. 6836 | */ 6837 | public pause(): Promise<void>; 6838 | /** 6839 | * Resume the instance. If it is already running, an error will be thrown. 6840 | */ 6841 | public resume(): Promise<void>; 6842 | /** 6843 | * Terminate the instance. If it is errored, terminated or complete, an error will be thrown. 6844 | */ 6845 | public terminate(): Promise<void>; 6846 | /** 6847 | * Restart the instance. 6848 | */ 6849 | public restart(): Promise<void>; 6850 | /** 6851 | * Returns the current status of the instance. 6852 | */ 6853 | public status(): Promise<InstanceStatus>; 6854 | /** 6855 | * Send an event to this instance. 6856 | */ 6857 | public sendEvent({ 6858 | type, 6859 | payload, 6860 | }: { 6861 | type: string; 6862 | payload: unknown; 6863 | }): Promise<void>; 6864 | } 6865 | ```