UNPKG

@cloudflare/workers-types

Version:

TypeScript typings for Cloudflare Workers

1,318 lines (1,317 loc) 527 kB
/*! ***************************************************************************** Copyright (c) Cloudflare. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* eslint-disable */ // noinspection JSUnusedGlobalSymbols export declare var onmessage: never; /** * The **`DOMException`** interface represents an abnormal event (called an **exception**) that occurs as a result of calling a method or accessing a property of a web API. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException) */ export declare class DOMException extends Error { constructor(message?: string, name?: string); /** * The **`message`** read-only property of the a message or description associated with the given error name. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/message) */ readonly message: string; /** * The **`name`** read-only property of the one of the strings associated with an error name. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/name) */ readonly name: string; /** * The **`code`** read-only property of the DOMException interface returns one of the legacy error code constants, or `0` if none match. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/code) */ readonly code: number; static readonly INDEX_SIZE_ERR: number; static readonly DOMSTRING_SIZE_ERR: number; static readonly HIERARCHY_REQUEST_ERR: number; static readonly WRONG_DOCUMENT_ERR: number; static readonly INVALID_CHARACTER_ERR: number; static readonly NO_DATA_ALLOWED_ERR: number; static readonly NO_MODIFICATION_ALLOWED_ERR: number; static readonly NOT_FOUND_ERR: number; static readonly NOT_SUPPORTED_ERR: number; static readonly INUSE_ATTRIBUTE_ERR: number; static readonly INVALID_STATE_ERR: number; static readonly SYNTAX_ERR: number; static readonly INVALID_MODIFICATION_ERR: number; static readonly NAMESPACE_ERR: number; static readonly INVALID_ACCESS_ERR: number; static readonly VALIDATION_ERR: number; static readonly TYPE_MISMATCH_ERR: number; static readonly SECURITY_ERR: number; static readonly NETWORK_ERR: number; static readonly ABORT_ERR: number; static readonly URL_MISMATCH_ERR: number; static readonly QUOTA_EXCEEDED_ERR: number; static readonly TIMEOUT_ERR: number; static readonly INVALID_NODE_TYPE_ERR: number; static readonly DATA_CLONE_ERR: number; get stack(): any; set stack(value: any); } export type WorkerGlobalScopeEventMap = { fetch: FetchEvent; scheduled: ScheduledEvent; queue: QueueEvent; unhandledrejection: PromiseRejectionEvent; rejectionhandled: PromiseRejectionEvent; }; export declare abstract class WorkerGlobalScope extends EventTarget<WorkerGlobalScopeEventMap> { EventTarget: typeof EventTarget; } /* The **`console`** object provides access to the debugging console (e.g., the Web console in Firefox). * * The **`console`** object provides access to the debugging console (e.g., the Web console in Firefox). * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console) */ export interface Console { "assert"(condition?: boolean, ...data: any[]): void; /** * The **`console.clear()`** static method clears the console if possible. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/clear_static) */ clear(): void; /** * The **`console.count()`** static method logs the number of times that this particular call to `count()` has been called. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/count_static) */ count(label?: string): void; /** * The **`console.countReset()`** static method resets counter used with console/count_static. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/countReset_static) */ countReset(label?: string): void; /** * The **`console.debug()`** static method outputs a message to the console at the 'debug' log level. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug_static) */ debug(...data: any[]): void; /** * The **`console.dir()`** static method displays a list of the properties of the specified JavaScript object. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dir_static) */ dir(item?: any, options?: any): void; /** * The **`console.dirxml()`** static method displays an interactive tree of the descendant elements of the specified XML/HTML element. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/dirxml_static) */ dirxml(...data: any[]): void; /** * The **`console.error()`** static method outputs a message to the console at the 'error' log level. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/error_static) */ error(...data: any[]): void; /** * The **`console.group()`** static method creates a new inline group in the Web console log, causing any subsequent console messages to be indented by an additional level, until console/groupEnd_static is called. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/group_static) */ group(...data: any[]): void; /** * The **`console.groupCollapsed()`** static method creates a new inline group in the console. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupCollapsed_static) */ groupCollapsed(...data: any[]): void; /** * The **`console.groupEnd()`** static method exits the current inline group in the console. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/groupEnd_static) */ groupEnd(): void; /** * The **`console.info()`** static method outputs a message to the console at the 'info' log level. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/info_static) */ info(...data: any[]): void; /** * The **`console.log()`** static method outputs a message to the console. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static) */ log(...data: any[]): void; /** * The **`console.table()`** static method displays tabular data as a table. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/table_static) */ table(tabularData?: any, properties?: string[]): void; /** * The **`console.time()`** static method starts a timer you can use to track how long an operation takes. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/time_static) */ time(label?: string): void; /** * The **`console.timeEnd()`** static method stops a timer that was previously started by calling console/time_static. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeEnd_static) */ timeEnd(label?: string): void; /** * The **`console.timeLog()`** static method logs the current value of a timer that was previously started by calling console/time_static. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/timeLog_static) */ timeLog(label?: string, ...data: any[]): void; timeStamp(label?: string): void; /** * The **`console.trace()`** static method outputs a stack trace to the console. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/trace_static) */ trace(...data: any[]): void; /** * The **`console.warn()`** static method outputs a warning message to the console at the 'warning' log level. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/warn_static) */ warn(...data: any[]): void; } export declare const console: Console; export type BufferSource = ArrayBufferView | ArrayBuffer; export type TypedArray = | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array; export declare namespace WebAssembly { class CompileError extends Error { constructor(message?: string); } class RuntimeError extends Error { constructor(message?: string); } type ValueType = | "anyfunc" | "externref" | "f32" | "f64" | "i32" | "i64" | "v128"; interface GlobalDescriptor { value: ValueType; mutable?: boolean; } class Global { constructor(descriptor: GlobalDescriptor, value?: any); value: any; valueOf(): any; } type ImportValue = ExportValue | number; type ModuleImports = Record<string, ImportValue>; type Imports = Record<string, ModuleImports>; type ExportValue = Function | Global | Memory | Table; type Exports = Record<string, ExportValue>; class Instance { constructor(module: Module, imports?: Imports); readonly exports: Exports; } interface MemoryDescriptor { initial: number; maximum?: number; shared?: boolean; } class Memory { constructor(descriptor: MemoryDescriptor); readonly buffer: ArrayBuffer; grow(delta: number): number; } type ImportExportKind = "function" | "global" | "memory" | "table"; interface ModuleExportDescriptor { kind: ImportExportKind; name: string; } interface ModuleImportDescriptor { kind: ImportExportKind; module: string; name: string; } abstract class Module { static customSections(module: Module, sectionName: string): ArrayBuffer[]; static exports(module: Module): ModuleExportDescriptor[]; static imports(module: Module): ModuleImportDescriptor[]; } type TableKind = "anyfunc" | "externref"; interface TableDescriptor { element: TableKind; initial: number; maximum?: number; } class Table { constructor(descriptor: TableDescriptor, value?: any); readonly length: number; get(index: number): any; grow(delta: number, value?: any): number; set(index: number, value?: any): void; } function instantiate(module: Module, imports?: Imports): Promise<Instance>; function validate(bytes: BufferSource): boolean; } /** * The **`ServiceWorkerGlobalScope`** interface of the Service Worker API represents the global execution context of a service worker. * Available only in secure contexts. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorkerGlobalScope) */ export interface ServiceWorkerGlobalScope extends WorkerGlobalScope { DOMException: typeof DOMException; WorkerGlobalScope: typeof WorkerGlobalScope; btoa(data: string): string; atob(data: string): string; setTimeout(callback: (...args: any[]) => void, msDelay?: number): number; setTimeout<Args extends any[]>( callback: (...args: Args) => void, msDelay?: number, ...args: Args ): number; clearTimeout(timeoutId: number | null): void; setInterval(callback: (...args: any[]) => void, msDelay?: number): number; setInterval<Args extends any[]>( callback: (...args: Args) => void, msDelay?: number, ...args: Args ): number; clearInterval(timeoutId: number | null): void; queueMicrotask(task: Function): void; structuredClone<T>(value: T, options?: StructuredSerializeOptions): T; reportError(error: any): void; fetch( input: RequestInfo | URL, init?: RequestInit<RequestInitCfProperties>, ): Promise<Response>; self: ServiceWorkerGlobalScope; crypto: Crypto; caches: CacheStorage; scheduler: Scheduler; performance: Performance; Cloudflare: Cloudflare; readonly origin: string; Event: typeof Event; ExtendableEvent: typeof ExtendableEvent; CustomEvent: typeof CustomEvent; PromiseRejectionEvent: typeof PromiseRejectionEvent; FetchEvent: typeof FetchEvent; TailEvent: typeof TailEvent; TraceEvent: typeof TailEvent; ScheduledEvent: typeof ScheduledEvent; MessageEvent: typeof MessageEvent; CloseEvent: typeof CloseEvent; ReadableStreamDefaultReader: typeof ReadableStreamDefaultReader; ReadableStreamBYOBReader: typeof ReadableStreamBYOBReader; ReadableStream: typeof ReadableStream; WritableStream: typeof WritableStream; WritableStreamDefaultWriter: typeof WritableStreamDefaultWriter; TransformStream: typeof TransformStream; ByteLengthQueuingStrategy: typeof ByteLengthQueuingStrategy; CountQueuingStrategy: typeof CountQueuingStrategy; ErrorEvent: typeof ErrorEvent; EventSource: typeof EventSource; CompressionStream: typeof CompressionStream; DecompressionStream: typeof DecompressionStream; TextEncoderStream: typeof TextEncoderStream; TextDecoderStream: typeof TextDecoderStream; Headers: typeof Headers; Body: typeof Body; Request: typeof Request; Response: typeof Response; WebSocket: typeof WebSocket; WebSocketPair: typeof WebSocketPair; WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair; AbortController: typeof AbortController; AbortSignal: typeof AbortSignal; TextDecoder: typeof TextDecoder; TextEncoder: typeof TextEncoder; navigator: Navigator; Navigator: typeof Navigator; URL: typeof URL; URLSearchParams: typeof URLSearchParams; URLPattern: typeof URLPattern; Blob: typeof Blob; File: typeof File; FormData: typeof FormData; Crypto: typeof Crypto; SubtleCrypto: typeof SubtleCrypto; CryptoKey: typeof CryptoKey; CacheStorage: typeof CacheStorage; Cache: typeof Cache; FixedLengthStream: typeof FixedLengthStream; IdentityTransformStream: typeof IdentityTransformStream; HTMLRewriter: typeof HTMLRewriter; } export declare function addEventListener< Type extends keyof WorkerGlobalScopeEventMap, >( type: Type, handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, options?: EventTargetAddEventListenerOptions | boolean, ): void; export declare function removeEventListener< Type extends keyof WorkerGlobalScopeEventMap, >( type: Type, handler: EventListenerOrEventListenerObject<WorkerGlobalScopeEventMap[Type]>, options?: EventTargetEventListenerOptions | boolean, ): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent) */ export declare function dispatchEvent( event: WorkerGlobalScopeEventMap[keyof WorkerGlobalScopeEventMap], ): boolean; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/btoa) */ export declare function btoa(data: string): string; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/atob) */ export declare function atob(data: string): string; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setTimeout) */ export declare function setTimeout( callback: (...args: any[]) => void, msDelay?: number, ): number; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setTimeout) */ export declare function setTimeout<Args extends any[]>( callback: (...args: Args) => void, msDelay?: number, ...args: Args ): number; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/clearTimeout) */ export declare function clearTimeout(timeoutId: number | null): void; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setInterval) */ export declare function setInterval( callback: (...args: any[]) => void, msDelay?: number, ): number; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/setInterval) */ export declare function setInterval<Args extends any[]>( callback: (...args: Args) => void, msDelay?: number, ...args: Args ): number; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/clearInterval) */ export declare function clearInterval(timeoutId: number | null): void; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/queueMicrotask) */ export declare function queueMicrotask(task: Function): void; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/structuredClone) */ export declare function structuredClone<T>( value: T, options?: StructuredSerializeOptions, ): T; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/reportError) */ export declare function reportError(error: any): void; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/fetch) */ export declare function fetch( input: RequestInfo | URL, init?: RequestInit<RequestInitCfProperties>, ): Promise<Response>; export declare const self: ServiceWorkerGlobalScope; /** * The Web Crypto API provides a set of low-level functions for common cryptographic tasks. * The Workers runtime implements the full surface of this API, but with some differences in * the [supported algorithms](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#supported-algorithms) * compared to those implemented in most browsers. * * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/) */ export declare const crypto: Crypto; /** * The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache. * * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/) */ export declare const caches: CacheStorage; export declare const scheduler: Scheduler; /** * The Workers runtime supports a subset of the Performance API, used to measure timing and performance, * as well as timing of subrequests and other operations. * * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/) */ export declare const performance: Performance; export declare const Cloudflare: Cloudflare; export declare const origin: string; export declare const navigator: Navigator; export interface TestController {} export interface ExecutionContext<Props = unknown> { waitUntil(promise: Promise<any>): void; passThroughOnException(): void; readonly props: Props; cache?: CacheContext; readonly access?: CloudflareAccessContext; tracing: Tracing; } export type ExportedHandlerFetchHandler< Env = unknown, CfHostMetadata = unknown, Props = unknown, > = ( request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: Env, ctx: ExecutionContext<Props>, ) => Response | Promise<Response>; export type ExportedHandlerConnectHandler<Env = unknown, Props = unknown> = ( socket: Socket, env: Env, ctx: ExecutionContext<Props>, ) => void | Promise<void>; export type ExportedHandlerTailHandler<Env = unknown, Props = unknown> = ( events: TraceItem[], env: Env, ctx: ExecutionContext<Props>, ) => void | Promise<void>; export type ExportedHandlerTraceHandler<Env = unknown, Props = unknown> = ( traces: TraceItem[], env: Env, ctx: ExecutionContext<Props>, ) => void | Promise<void>; export type ExportedHandlerTailStreamHandler<Env = unknown, Props = unknown> = ( event: TailStream.TailEvent<TailStream.Onset>, env: Env, ctx: ExecutionContext<Props>, ) => TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType>; export type ExportedHandlerScheduledHandler<Env = unknown, Props = unknown> = ( controller: ScheduledController, env: Env, ctx: ExecutionContext<Props>, ) => void | Promise<void>; export type ExportedHandlerQueueHandler< Env = unknown, Message = unknown, Props = unknown, > = ( batch: MessageBatch<Message>, env: Env, ctx: ExecutionContext<Props>, ) => void | Promise<void>; export type ExportedHandlerTestHandler<Env = unknown, Props = unknown> = ( controller: TestController, env: Env, ctx: ExecutionContext<Props>, ) => void | Promise<void>; export interface ExportedHandler< Env = unknown, QueueHandlerMessage = unknown, CfHostMetadata = unknown, Props = unknown, > { fetch?: ExportedHandlerFetchHandler<Env, CfHostMetadata, Props>; connect?: ExportedHandlerConnectHandler<Env, Props>; tail?: ExportedHandlerTailHandler<Env, Props>; trace?: ExportedHandlerTraceHandler<Env, Props>; tailStream?: ExportedHandlerTailStreamHandler<Env, Props>; scheduled?: ExportedHandlerScheduledHandler<Env, Props>; test?: ExportedHandlerTestHandler<Env, Props>; email?: EmailExportedHandler<Env, Props>; queue?: ExportedHandlerQueueHandler<Env, QueueHandlerMessage, Props>; } export interface StructuredSerializeOptions { transfer?: any[]; } export declare abstract class Navigator { sendBeacon(url: string, body?: BodyInit): boolean; readonly userAgent: string; readonly hardwareConcurrency: number; readonly platform: string; } export interface AlarmInvocationInfo { readonly isRetry: boolean; readonly retryCount: number; readonly scheduledTime: number; } export interface Cloudflare { readonly compatibilityFlags: Record<string, boolean>; } export interface CachePurgeError { code: number; message: string; } export interface CachePurgeResult { success: boolean; errors: CachePurgeError[]; } export interface CachePurgeOptions { tags?: string[]; pathPrefixes?: string[]; purgeEverything?: boolean; } export interface CacheContext { purge(options: CachePurgeOptions): Promise<CachePurgeResult>; } export interface CloudflareAccessContext { readonly aud: string; getIdentity(): Promise<CloudflareAccessIdentity | undefined>; } export declare abstract class ColoLocalActorNamespace { get(actorId: string): Fetcher; } export interface DurableObject { fetch(request: Request): Response | Promise<Response>; connect?(socket: Socket): void | Promise<void>; alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>; webSocketMessage?( ws: WebSocket, message: string | ArrayBuffer, ): void | Promise<void>; webSocketClose?( ws: WebSocket, code: number, reason: string, wasClean: boolean, ): void | Promise<void>; webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>; } export type DurableObjectStub< T extends Rpc.DurableObjectBranded | undefined = undefined, > = Fetcher< T, "alarm" | "connect" | "webSocketMessage" | "webSocketClose" | "webSocketError" > & { readonly id: DurableObjectId; readonly name?: string; }; export interface DurableObjectId { toString(): string; equals(other: DurableObjectId): boolean; readonly name?: string; readonly jurisdiction?: string; } export declare abstract class DurableObjectNamespace< T extends Rpc.DurableObjectBranded | undefined = undefined, > { newUniqueId( options?: DurableObjectNamespaceNewUniqueIdOptions, ): DurableObjectId; idFromName(name: string): DurableObjectId; idFromString(id: string): DurableObjectId; get( id: DurableObjectId, options?: DurableObjectNamespaceGetDurableObjectOptions, ): DurableObjectStub<T>; getByName( name: string, options?: DurableObjectNamespaceGetDurableObjectOptions, ): DurableObjectStub<T>; jurisdiction( jurisdiction: DurableObjectJurisdiction, ): DurableObjectNamespace<T>; } export type DurableObjectJurisdiction = "eu" | "fedramp" | "fedramp-high"; export interface DurableObjectNamespaceNewUniqueIdOptions { jurisdiction?: DurableObjectJurisdiction; } export type DurableObjectLocationHint = | "wnam" | "enam" | "sam" | "weur" | "eeur" | "apac" | "apac-ne" | "apac-se" | "oc" | "afr" | "me"; export type DurableObjectRoutingMode = "primary-only"; export interface DurableObjectNamespaceGetDurableObjectOptions { locationHint?: DurableObjectLocationHint; routingMode?: DurableObjectRoutingMode; } export interface DurableObjectClass< _T extends Rpc.DurableObjectBranded | undefined = undefined, > {} export interface DurableObjectState<Props = unknown> { waitUntil(promise: Promise<any>): void; readonly props: Props; readonly id: DurableObjectId; readonly storage: DurableObjectStorage; container?: Container; facets: DurableObjectFacets; blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>; acceptWebSocket(ws: WebSocket, tags?: string[]): void; getWebSockets(tag?: string): WebSocket[]; setWebSocketAutoResponse(maybeReqResp?: WebSocketRequestResponsePair): void; getWebSocketAutoResponse(): WebSocketRequestResponsePair | null; getWebSocketAutoResponseTimestamp(ws: WebSocket): Date | null; setHibernatableWebSocketEventTimeout(timeoutMs?: number): void; getHibernatableWebSocketEventTimeout(): number | null; getTags(ws: WebSocket): string[]; abort(reason?: string): void; } export interface DurableObjectTransaction { get<T = unknown>( key: string, options?: DurableObjectGetOptions, ): Promise<T | undefined>; get<T = unknown>( keys: string[], options?: DurableObjectGetOptions, ): Promise<Map<string, T>>; list<T = unknown>( options?: DurableObjectListOptions, ): Promise<Map<string, T>>; put<T>( key: string, value: T, options?: DurableObjectPutOptions, ): Promise<void>; put<T>( entries: Record<string, T>, options?: DurableObjectPutOptions, ): Promise<void>; delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>; delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>; rollback(): void; getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>; setAlarm( scheduledTime: number | Date, options?: DurableObjectSetAlarmOptions, ): Promise<void>; deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>; } export interface DurableObjectStorage { get<T = unknown>( key: string, options?: DurableObjectGetOptions, ): Promise<T | undefined>; get<T = unknown>( keys: string[], options?: DurableObjectGetOptions, ): Promise<Map<string, T>>; list<T = unknown>( options?: DurableObjectListOptions, ): Promise<Map<string, T>>; put<T>( key: string, value: T, options?: DurableObjectPutOptions, ): Promise<void>; put<T>( entries: Record<string, T>, options?: DurableObjectPutOptions, ): Promise<void>; delete(key: string, options?: DurableObjectPutOptions): Promise<boolean>; delete(keys: string[], options?: DurableObjectPutOptions): Promise<number>; deleteAll(options?: DurableObjectPutOptions): Promise<void>; transaction<T>( closure: (txn: DurableObjectTransaction) => Promise<T>, ): Promise<T>; getAlarm(options?: DurableObjectGetAlarmOptions): Promise<number | null>; setAlarm( scheduledTime: number | Date, options?: DurableObjectSetAlarmOptions, ): Promise<void>; deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>; sync(): Promise<void>; sql: SqlStorage; kv: SyncKvStorage; transactionSync<T>(closure: () => T): T; getCurrentBookmark(): Promise<string>; getBookmarkForTime(timestamp: number | Date): Promise<string>; onNextSessionRestoreBookmark(bookmark: string): Promise<string>; } export interface DurableObjectListOptions { start?: string; startAfter?: string; end?: string; prefix?: string; reverse?: boolean; limit?: number; allowConcurrency?: boolean; noCache?: boolean; } export interface DurableObjectGetOptions { allowConcurrency?: boolean; noCache?: boolean; } export interface DurableObjectGetAlarmOptions { allowConcurrency?: boolean; } export interface DurableObjectPutOptions { allowConcurrency?: boolean; allowUnconfirmed?: boolean; noCache?: boolean; } export interface DurableObjectSetAlarmOptions { allowConcurrency?: boolean; allowUnconfirmed?: boolean; } export declare class WebSocketRequestResponsePair { constructor(request: string, response: string); get request(): string; get response(): string; } export interface DurableObjectFacets { get<T extends Rpc.DurableObjectBranded | undefined = undefined>( name: string, getStartupOptions: () => | FacetStartupOptions<T> | Promise<FacetStartupOptions<T>>, ): Fetcher<T>; abort(name: string, reason: any): void; delete(name: string): void; clone(src: string, dst: string): void; } export interface FacetStartupOptions< T extends Rpc.DurableObjectBranded | undefined = undefined, > { id?: DurableObjectId | string; class: DurableObjectClass<T>; } export interface AnalyticsEngineDataset { writeDataPoint(event?: AnalyticsEngineDataPoint): void; } export interface AnalyticsEngineDataPoint { indexes?: ((ArrayBuffer | string) | null)[]; doubles?: number[]; blobs?: ((ArrayBuffer | string) | null)[]; } /** * The **`Event`** interface represents an event which takes place on an `EventTarget`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event) */ export declare class Event { constructor(type: string, init?: EventInit); /** * The **`type`** read-only property of the Event interface returns a string containing the event's type. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/type) */ get type(): string; /** * The **`eventPhase`** read-only property of the being evaluated. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/eventPhase) */ get eventPhase(): number; /** * The read-only **`composed`** property of the or not the event will propagate across the shadow DOM boundary into the standard DOM. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composed) */ get composed(): boolean; /** * The **`bubbles`** read-only property of the Event interface indicates whether the event bubbles up through the DOM tree or not. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/bubbles) */ get bubbles(): boolean; /** * The **`cancelable`** read-only property of the Event interface indicates whether the event can be canceled, and therefore prevented as if the event never happened. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelable) */ get cancelable(): boolean; /** * The **`defaultPrevented`** read-only property of the Event interface returns a boolean value indicating whether or not the call to Event.preventDefault() canceled the event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/defaultPrevented) */ get defaultPrevented(): boolean; /** * The Event property **`returnValue`** indicates whether the default action for this event has been prevented or not. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/returnValue) */ get returnValue(): boolean; /** * The **`currentTarget`** read-only property of the Event interface identifies the element to which the event handler has been attached. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/currentTarget) */ get currentTarget(): EventTarget | undefined; /** * The read-only **`target`** property of the dispatched. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/target) */ get target(): EventTarget | undefined; /** * The deprecated **`Event.srcElement`** is an alias for the Event.target property. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/srcElement) */ get srcElement(): EventTarget | undefined; /** * The **`timeStamp`** read-only property of the Event interface returns the time (in milliseconds) at which the event was created. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/timeStamp) */ get timeStamp(): number; /** * The **`isTrusted`** read-only property of the when the event was generated by the user agent (including via user actions and programmatic methods such as HTMLElement.focus()), and `false` when the event was dispatched via The only exception is the `click` event, which initializes the `isTrusted` property to `false` in user agents. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/isTrusted) */ get isTrusted(): boolean; /** * The **`cancelBubble`** property of the Event interface is deprecated. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble) */ get cancelBubble(): boolean; /** * The **`cancelBubble`** property of the Event interface is deprecated. * @deprecated * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/cancelBubble) */ set cancelBubble(value: boolean); /** * The **`stopImmediatePropagation()`** method of the If several listeners are attached to the same element for the same event type, they are called in the order in which they were added. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopImmediatePropagation) */ stopImmediatePropagation(): void; /** * The **`preventDefault()`** method of the Event interface tells the user agent that if the event does not get explicitly handled, its default action should not be taken as it normally would be. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/preventDefault) */ preventDefault(): void; /** * The **`stopPropagation()`** method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation) */ stopPropagation(): void; /** * The **`composedPath()`** method of the Event interface returns the event's path which is an array of the objects on which listeners will be invoked. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Event/composedPath) */ composedPath(): EventTarget[]; static readonly NONE: number; static readonly CAPTURING_PHASE: number; static readonly AT_TARGET: number; static readonly BUBBLING_PHASE: number; } export interface EventInit { bubbles?: boolean; cancelable?: boolean; composed?: boolean; } export type EventListener<EventType extends Event = Event> = ( event: EventType, ) => void; export interface EventListenerObject<EventType extends Event = Event> { handleEvent(event: EventType): void; } export type EventListenerOrEventListenerObject< EventType extends Event = Event, > = EventListener<EventType> | EventListenerObject<EventType>; /** * The **`EventTarget`** interface is implemented by objects that can receive events and may have listeners for them. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget) */ export declare class EventTarget< EventMap extends Record<string, Event> = Record<string, Event>, > { constructor(); /** * The **`addEventListener()`** method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener) */ addEventListener<Type extends keyof EventMap>( type: Type, handler: EventListenerOrEventListenerObject<EventMap[Type]>, options?: EventTargetAddEventListenerOptions | boolean, ): void; /** * The **`removeEventListener()`** method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener) */ removeEventListener<Type extends keyof EventMap>( type: Type, handler: EventListenerOrEventListenerObject<EventMap[Type]>, options?: EventTargetEventListenerOptions | boolean, ): void; /** * The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent) */ dispatchEvent(event: EventMap[keyof EventMap]): boolean; } export interface EventTargetEventListenerOptions { capture?: boolean; } export interface EventTargetAddEventListenerOptions { capture?: boolean; passive?: boolean; once?: boolean; signal?: AbortSignal; } export interface EventTargetHandlerObject { handleEvent: (event: Event) => any | undefined; } /** * The **`AbortController`** interface represents a controller object that allows you to abort one or more Web requests as and when desired. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController) */ export declare class AbortController { constructor(); /** * The **`signal`** read-only property of the AbortController interface returns an AbortSignal object instance, which can be used to communicate with/abort an asynchronous operation as desired. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/signal) */ get signal(): AbortSignal; /** * The **`abort()`** method of the AbortController interface aborts an asynchronous operation before it has completed. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortController/abort) */ abort(reason?: any): void; } /** * The **`AbortSignal`** interface represents a signal object that allows you to communicate with an asynchronous operation (such as a fetch request) and abort it if required via an AbortController object. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal) */ export declare abstract class AbortSignal extends EventTarget { /** * The **`AbortSignal.abort()`** static method returns an AbortSignal that is already set as aborted (and which does not trigger an AbortSignal/abort_event event). * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_static) */ static abort(reason?: any): AbortSignal; /** * The **`AbortSignal.timeout()`** static method returns an AbortSignal that will automatically abort after a specified time. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/timeout_static) */ static timeout(delay: number): AbortSignal; /** * The **`AbortSignal.any()`** static method takes an iterable of abort signals and returns an AbortSignal. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/any_static) */ static any(signals: AbortSignal[]): AbortSignal; /** * The **`aborted`** read-only property returns a value that indicates whether the asynchronous operations the signal is communicating with are aborted (`true`) or not (`false`). * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/aborted) */ get aborted(): boolean; /** * The **`reason`** read-only property returns a JavaScript value that indicates the abort reason. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/reason) */ get reason(): any; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_event) */ get onabort(): any | null; /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/abort_event) */ set onabort(value: any | null); /** * The **`throwIfAborted()`** method throws the signal's abort AbortSignal.reason if the signal has been aborted; otherwise it does nothing. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/AbortSignal/throwIfAborted) */ throwIfAborted(): void; } export interface Scheduler { wait(delay: number, maybeOptions?: SchedulerWaitOptions): Promise<void>; } export interface SchedulerWaitOptions { signal?: AbortSignal; } /** * The **`ExtendableEvent`** interface extends the lifetime of the `install` and `activate` events dispatched on the global scope as part of the service worker lifecycle. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent) */ export declare abstract class ExtendableEvent extends Event { /** * The **`ExtendableEvent.waitUntil()`** method tells the event dispatcher that work is ongoing. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ExtendableEvent/waitUntil) */ waitUntil(promise: Promise<any>): void; } /** * The **`CustomEvent`** interface represents events initialized by an application for any purpose. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent) */ export declare class CustomEvent<T = any> extends Event { constructor(type: string, init?: CustomEventCustomEventInit); /** * The read-only **`detail`** property of the CustomEvent interface returns any data passed when initializing the event. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail) */ get detail(): T; } export interface CustomEventCustomEventInit { bubbles?: boolean; cancelable?: boolean; composed?: boolean; detail?: any; } /** * The **`Blob`** interface represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream so its methods can be used for processing the data. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob) */ export declare class Blob { constructor( bits?: ((ArrayBuffer | ArrayBufferView) | string | Blob)[], options?: BlobOptions, ); /** * The **`size`** read-only property of the Blob interface returns the size of the Blob or File in bytes. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */ get size(): number; /** * The **`type`** read-only property of the Blob interface returns the MIME type of the file. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */ get type(): string; /** * The **`slice()`** method of the Blob interface creates and returns a new `Blob` object which contains data from a subset of the blob on which it's called. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */ slice(start?: number, end?: number, type?: string): Blob; /** * The **`arrayBuffer()`** method of the Blob interface returns a Promise that resolves with the contents of the blob as binary data contained in an ArrayBuffer. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/arrayBuffer) */ arrayBuffer(): Promise<ArrayBuffer>; /** * The **`bytes()`** method of the Blob interface returns a Promise that resolves with a Uint8Array containing the contents of the blob as an array of bytes. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/bytes) */ bytes(): Promise<Uint8Array>; /** * The **`text()`** method of the string containing the contents of the blob, interpreted as UTF-8. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */ text(): Promise<string>; /** * The **`stream()`** method of the Blob interface returns a ReadableStream which upon reading returns the data contained within the `Blob`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */ stream(): ReadableStream; } export interface BlobOptions { type?: string; } /** * The **`File`** interface provides information about files and allows JavaScript in a web page to access their content. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/File) */ export declare class File extends Blob { constructor( bits: ((ArrayBuffer | ArrayBufferView) | string | Blob)[] | undefined, name: string, options?: FileOptions, ); /** * The **`name`** read-only property of the File interface returns the name of the file represented by a File object. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */ get name(): string; /** * The **`lastModified`** read-only property of the File interface provides the last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */ get lastModified(): number; } export interface FileOptions { type?: string; lastModified?: number; } /** * The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache. * * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/) */ export declare abstract class CacheStorage { /** * The **`open()`** method of the the Cache object matching the `cacheName`. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CacheStorage/open) */ open(cacheName: string): Promise<Cache>; readonly default: Cache; } /** * The Cache API allows fine grained control of reading and writing from the Cloudflare global network cache. * * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/) */ export declare abstract class Cache { /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#delete) */ delete( request: RequestInfo | URL, options?: CacheQueryOptions, ): Promise<boolean>; /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#match) */ match( request: RequestInfo | URL, options?: CacheQueryOptions, ): Promise<Response | undefined>; /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/cache/#put) */ put(request: RequestInfo | URL, response: Response): Promise<void>; } export interface CacheQueryOptions { ignoreMethod?: boolean; } /** * The Web Crypto API provides a set of low-level functions for common cryptographic tasks. * The Workers runtime implements the full surface of this API, but with some differences in * the [supported algorithms](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/#supported-algorithms) * compared to those implemented in most browsers. * * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/web-crypto/) */ export declare abstract class Crypto { /** * The **`Crypto.subtle`** read-only property returns a cryptographic operations. * Available only in secure contexts. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/subtle) */ get subtle(): SubtleCrypto; /** * The **`Crypto.getRandomValues()`** method lets you get cryptographically strong random values. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/getRandomValues) */ getRandomValues< T extends | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array, >(buffer: T): T; /** * The **`randomUUID()`** method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator. * Available only in secure contexts. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Crypto/randomUUID) */ randomUUID(): string; DigestStream: typeof DigestStream; } /** * The **`SubtleCrypto`** interface of the Web Crypto API provides a number of low-level cryptographic functions. * Available only in secure contexts. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto) */ export declare abstract class SubtleCrypto { /** * The **`encrypt()`** method of the SubtleCrypto interface encrypts data. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/encrypt) */ encrypt( algorithm: string | SubtleCryptoEncryptAlgorithm, key: CryptoKey, plainText: ArrayBuffer | ArrayBufferView, ): Promise<ArrayBuffer>; /** * The **`decrypt()`** method of the SubtleCrypto interface decrypts some encrypted data. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/decrypt) */ decrypt( algorithm: string | SubtleCryptoEncryptAlgorithm, key: CryptoKey, cipherText: ArrayBuffer | ArrayBufferView, ): Promise<ArrayBuffer>; /** * The **`sign()`** method of the SubtleCrypto interface generates a digital signature. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/sign) */ sign( algorithm: string | SubtleCryptoSignAlgorithm, key: CryptoKey, data: ArrayBuffer | ArrayBufferView, ): Promise<ArrayBuffer>; /** * The **`verify()`** method of the SubtleCrypto interface verifies a digital signature. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/verify) */ verify( algorithm: string | SubtleCryptoSignAlgorithm, key: CryptoKey, signature: ArrayBuffer | ArrayBufferView, data: ArrayBuffer | ArrayBufferView, ): Promise<boolean>; /** * The **`digest()`** method of the SubtleCrypto interface generates a _digest_ of the given data, using the specified hash function. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/SubtleCrypto/digest) */ digest( algorithm: string | SubtleCryptoHashAlgorithm, data: ArrayBuffer | ArrayBufferView, ): Promise<ArrayBuffer>; /** * The **`generateKey()`** method of the SubtleCrypto interface is used to generate a new key (for symmetric algorithms) or key pair (for public-key algorithms). * * [MDN Reference](https://developer.mozilla.