@cloudflare/workers-types 4.20250911.0 → 4.20250912.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -388,10 +388,10 @@ declare const Cloudflare: Cloudflare;
388
388
  declare const origin: string;
389
389
  declare const navigator: Navigator;
390
390
  interface TestController {}
391
- interface ExecutionContext {
391
+ interface ExecutionContext<Props = unknown> {
392
392
  waitUntil(promise: Promise<any>): void;
393
393
  passThroughOnException(): void;
394
- props: any;
394
+ readonly props: Props;
395
395
  }
396
396
  type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = (
397
397
  request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
@@ -540,9 +540,12 @@ type DurableObjectLocationHint =
540
540
  interface DurableObjectNamespaceGetDurableObjectOptions {
541
541
  locationHint?: DurableObjectLocationHint;
542
542
  }
543
- interface DurableObjectState {
543
+ interface DurableObjectClass<
544
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
545
+ > {}
546
+ interface DurableObjectState<Props = unknown> {
544
547
  waitUntil(promise: Promise<any>): void;
545
- props: any;
548
+ readonly props: Props;
546
549
  readonly id: DurableObjectId;
547
550
  readonly storage: DurableObjectStorage;
548
551
  container?: Container;
@@ -3078,6 +3081,30 @@ interface MessagePort extends EventTarget {
3078
3081
  interface MessagePortPostMessageOptions {
3079
3082
  transfer?: any[];
3080
3083
  }
3084
+ type LoopbackForExport<
3085
+ T extends
3086
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3087
+ | ExportedHandler<any, any, any>
3088
+ | undefined = undefined,
3089
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3090
+ ? LoopbackServiceStub<InstanceType<T>>
3091
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3092
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3093
+ : T extends ExportedHandler<any, any, any>
3094
+ ? LoopbackServiceStub<undefined>
3095
+ : undefined;
3096
+ type LoopbackServiceStub<
3097
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3098
+ > = Fetcher<T> &
3099
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3100
+ ? (opts: { props?: Props }) => Fetcher<T>
3101
+ : (opts: { props?: any }) => Fetcher<T>);
3102
+ type LoopbackDurableObjectClass<
3103
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3104
+ > = DurableObjectClass<T> &
3105
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3106
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3107
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3081
3108
  interface SyncKvStorage {
3082
3109
  get<T = unknown>(key: string): T | undefined;
3083
3110
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3092,98 +3119,51 @@ interface SyncKvListOptions {
3092
3119
  reverse?: boolean;
3093
3120
  limit?: number;
3094
3121
  }
3122
+ interface WorkerStub {
3123
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3124
+ name?: string,
3125
+ options?: WorkerStubEntrypointOptions,
3126
+ ): Fetcher<T>;
3127
+ }
3128
+ interface WorkerStubEntrypointOptions {
3129
+ props?: any;
3130
+ }
3131
+ interface WorkerLoader {
3132
+ get(
3133
+ name: string,
3134
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3135
+ ): WorkerStub;
3136
+ }
3137
+ interface WorkerLoaderModule {
3138
+ js?: string;
3139
+ cjs?: string;
3140
+ text?: string;
3141
+ data?: ArrayBuffer;
3142
+ json?: any;
3143
+ py?: string;
3144
+ }
3145
+ interface WorkerLoaderWorkerCode {
3146
+ compatibilityDate: string;
3147
+ compatibilityFlags?: string[];
3148
+ allowExperimental?: boolean;
3149
+ mainModule: string;
3150
+ modules: Record<string, WorkerLoaderModule | string>;
3151
+ env?: any;
3152
+ globalOutbound?: Fetcher | null;
3153
+ tails?: Fetcher[];
3154
+ streamingTails?: Fetcher[];
3155
+ }
3095
3156
  /**
3096
3157
  * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3097
3158
  * as well as timing of subrequests and other operations.
3098
3159
  *
3099
3160
  * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
3100
3161
  */
3101
- declare abstract class Performance extends EventTarget {
3162
+ declare abstract class Performance {
3102
3163
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
3103
3164
  get timeOrigin(): number;
3104
3165
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3105
3166
  now(): number;
3106
- get eventCounts(): EventCounts;
3107
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMarks) */
3108
- clearMarks(name?: string): void;
3109
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMeasures) */
3110
- clearMeasures(name?: string): void;
3111
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearResourceTimings) */
3112
- clearResourceTimings(): void;
3113
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntries) */
3114
- getEntries(): PerformanceEntry[];
3115
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByName) */
3116
- getEntriesByName(name: string, type: string): PerformanceEntry[];
3117
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByType) */
3118
- getEntriesByType(type: string): PerformanceEntry[];
3119
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/mark) */
3120
- mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
3121
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/measure) */
3122
- measure(
3123
- measureName: string,
3124
- measureOptionsOrStartMark: PerformanceMeasureOptions | string,
3125
- maybeEndMark?: string,
3126
- ): PerformanceMeasure;
3127
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/setResourceTimingBufferSize) */
3128
- setResourceTimingBufferSize(size: number): void;
3129
- }
3130
- /**
3131
- * PerformanceMark is an abstract interface for PerformanceEntry objects with an entryType of "mark". Entries of this type are created by calling performance.mark() to add a named DOMHighResTimeStamp (the mark) to the browser's performance timeline.
3132
- *
3133
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark)
3134
- */
3135
- interface PerformanceMark extends PerformanceEntry {
3136
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark/detail) */
3137
- get detail(): any;
3138
- }
3139
- /**
3140
- * PerformanceMeasure is an abstract interface for PerformanceEntry objects with an entryType of "measure". Entries of this type are created by calling performance.measure() to add a named DOMHighResTimeStamp (the measure) between two marks to the browser's performance timeline.
3141
- *
3142
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure)
3143
- */
3144
- interface PerformanceMeasure extends PerformanceEntry {
3145
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure/detail) */
3146
- get detail(): any;
3147
- }
3148
- interface PerformanceMarkOptions {
3149
- detail?: any;
3150
- startTime?: number;
3151
- }
3152
- interface PerformanceMeasureOptions {
3153
- detail?: any;
3154
- start?: number;
3155
- duration?: number;
3156
- end?: number;
3157
- }
3158
- /**
3159
- * Encapsulates a single performance metric that is part of the performance timeline. A performance entry can be directly created by making a performance mark or measure (for example by calling the mark() method) at an explicit point in an application. Performance entries are also created in indirect ways such as loading a resource (such as an image).
3160
- *
3161
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry)
3162
- */
3163
- declare abstract class PerformanceEntry {
3164
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/name) */
3165
- get name(): string;
3166
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/entryType) */
3167
- get entryType(): string;
3168
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/startTime) */
3169
- get startTime(): number;
3170
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/duration) */
3171
- get duration(): number;
3172
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/toJSON) */
3173
- toJSON(): any;
3174
- }
3175
- interface EventCounts {
3176
- get size(): number;
3177
- get(eventType: string): number | undefined;
3178
- has(eventType: string): boolean;
3179
- entries(): IterableIterator<string[]>;
3180
- keys(): IterableIterator<string>;
3181
- values(): IterableIterator<number>;
3182
- forEach(
3183
- param1: (param0: number, param1: string, param2: EventCounts) => void,
3184
- param2?: any,
3185
- ): void;
3186
- [Symbol.iterator](): IterableIterator<string[]>;
3187
3167
  }
3188
3168
  type AiImageClassificationInput = {
3189
3169
  image: number[];
@@ -8095,7 +8075,53 @@ declare namespace Rpc {
8095
8075
  };
8096
8076
  }
8097
8077
  declare namespace Cloudflare {
8078
+ // Type of `env`.
8079
+ //
8080
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8081
+ // will merge all declarations.
8082
+ //
8083
+ // You can use `wrangler types` to generate the `Env` type automatically.
8098
8084
  interface Env {}
8085
+ // Project-specific parameters used to inform types.
8086
+ //
8087
+ // This interface is, again, intended to be declared in project-specific files, and then that
8088
+ // declaration will be merged with this one.
8089
+ //
8090
+ // A project should have a declaration like this:
8091
+ //
8092
+ // interface GlobalProps {
8093
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8094
+ // // of `ctx.exports`.
8095
+ // mainModule: typeof import("my-main-module");
8096
+ //
8097
+ // // Declares which of the main module's exports are configured with durable storage, and
8098
+ // // thus should behave as Durable Object namsepace bindings.
8099
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8100
+ // }
8101
+ //
8102
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8103
+ interface GlobalProps {}
8104
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8105
+ // present.
8106
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8107
+ ? GlobalProps[K]
8108
+ : Default;
8109
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8110
+ // `mainModule` property.
8111
+ type MainModule = GlobalProp<"mainModule", {}>;
8112
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8113
+ type Exports = {
8114
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8115
+ // If the export is listed in `durableNamespaces`, then it is also a
8116
+ // DurableObjectNamespace.
8117
+ (K extends GlobalProp<"durableNamespaces", never>
8118
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8119
+ ? DoInstance extends Rpc.DurableObjectBranded
8120
+ ? DurableObjectNamespace<DoInstance>
8121
+ : DurableObjectNamespace<undefined>
8122
+ : DurableObjectNamespace<undefined>
8123
+ : {});
8124
+ };
8099
8125
  }
8100
8126
  declare module "cloudflare:node" {
8101
8127
  export interface DefaultHandler {
@@ -8113,7 +8139,7 @@ declare module "cloudflare:node" {
8113
8139
  handlers?: Omit<DefaultHandler, "fetch">,
8114
8140
  ): DefaultHandler;
8115
8141
  }
8116
- declare module "cloudflare:workers" {
8142
+ declare namespace CloudflareWorkersModule {
8117
8143
  export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8118
8144
  export const RpcStub: {
8119
8145
  new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
@@ -8122,11 +8148,11 @@ declare module "cloudflare:workers" {
8122
8148
  [Rpc.__RPC_TARGET_BRAND]: never;
8123
8149
  }
8124
8150
  // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8125
- export abstract class WorkerEntrypoint<Env = unknown>
8151
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8126
8152
  implements Rpc.WorkerEntrypointBranded
8127
8153
  {
8128
8154
  [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8129
- protected ctx: ExecutionContext;
8155
+ protected ctx: ExecutionContext<Props>;
8130
8156
  protected env: Env;
8131
8157
  constructor(ctx: ExecutionContext, env: Env);
8132
8158
  fetch?(request: Request): Response | Promise<Response>;
@@ -8136,11 +8162,11 @@ declare module "cloudflare:workers" {
8136
8162
  queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8137
8163
  test?(controller: TestController): void | Promise<void>;
8138
8164
  }
8139
- export abstract class DurableObject<Env = unknown>
8165
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8140
8166
  implements Rpc.DurableObjectBranded
8141
8167
  {
8142
8168
  [Rpc.__DURABLE_OBJECT_BRAND]: never;
8143
- protected ctx: DurableObjectState;
8169
+ protected ctx: DurableObjectState<Props>;
8144
8170
  protected env: Env;
8145
8171
  constructor(ctx: DurableObjectState, env: Env);
8146
8172
  fetch?(request: Request): Response | Promise<Response>;
@@ -8227,6 +8253,9 @@ declare module "cloudflare:workers" {
8227
8253
  export function waitUntil(promise: Promise<unknown>): void;
8228
8254
  export const env: Cloudflare.Env;
8229
8255
  }
8256
+ declare module "cloudflare:workers" {
8257
+ export = CloudflareWorkersModule;
8258
+ }
8230
8259
  interface SecretsStoreSecret {
8231
8260
  /**
8232
8261
  * Get a secret from the Secrets Store, returning a string of the secret value
@@ -390,10 +390,10 @@ export declare const Cloudflare: Cloudflare;
390
390
  export declare const origin: string;
391
391
  export declare const navigator: Navigator;
392
392
  export interface TestController {}
393
- export interface ExecutionContext {
393
+ export interface ExecutionContext<Props = unknown> {
394
394
  waitUntil(promise: Promise<any>): void;
395
395
  passThroughOnException(): void;
396
- props: any;
396
+ readonly props: Props;
397
397
  }
398
398
  export type ExportedHandlerFetchHandler<
399
399
  Env = unknown,
@@ -545,9 +545,12 @@ export type DurableObjectLocationHint =
545
545
  export interface DurableObjectNamespaceGetDurableObjectOptions {
546
546
  locationHint?: DurableObjectLocationHint;
547
547
  }
548
- export interface DurableObjectState {
548
+ export interface DurableObjectClass<
549
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
550
+ > {}
551
+ export interface DurableObjectState<Props = unknown> {
549
552
  waitUntil(promise: Promise<any>): void;
550
- props: any;
553
+ readonly props: Props;
551
554
  readonly id: DurableObjectId;
552
555
  readonly storage: DurableObjectStorage;
553
556
  container?: Container;
@@ -3089,6 +3092,30 @@ export interface MessagePort extends EventTarget {
3089
3092
  export interface MessagePortPostMessageOptions {
3090
3093
  transfer?: any[];
3091
3094
  }
3095
+ export type LoopbackForExport<
3096
+ T extends
3097
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3098
+ | ExportedHandler<any, any, any>
3099
+ | undefined = undefined,
3100
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3101
+ ? LoopbackServiceStub<InstanceType<T>>
3102
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3103
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3104
+ : T extends ExportedHandler<any, any, any>
3105
+ ? LoopbackServiceStub<undefined>
3106
+ : undefined;
3107
+ export type LoopbackServiceStub<
3108
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3109
+ > = Fetcher<T> &
3110
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3111
+ ? (opts: { props?: Props }) => Fetcher<T>
3112
+ : (opts: { props?: any }) => Fetcher<T>);
3113
+ export type LoopbackDurableObjectClass<
3114
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3115
+ > = DurableObjectClass<T> &
3116
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3117
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3118
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3092
3119
  export interface SyncKvStorage {
3093
3120
  get<T = unknown>(key: string): T | undefined;
3094
3121
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3103,98 +3130,51 @@ export interface SyncKvListOptions {
3103
3130
  reverse?: boolean;
3104
3131
  limit?: number;
3105
3132
  }
3133
+ export interface WorkerStub {
3134
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3135
+ name?: string,
3136
+ options?: WorkerStubEntrypointOptions,
3137
+ ): Fetcher<T>;
3138
+ }
3139
+ export interface WorkerStubEntrypointOptions {
3140
+ props?: any;
3141
+ }
3142
+ export interface WorkerLoader {
3143
+ get(
3144
+ name: string,
3145
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3146
+ ): WorkerStub;
3147
+ }
3148
+ export interface WorkerLoaderModule {
3149
+ js?: string;
3150
+ cjs?: string;
3151
+ text?: string;
3152
+ data?: ArrayBuffer;
3153
+ json?: any;
3154
+ py?: string;
3155
+ }
3156
+ export interface WorkerLoaderWorkerCode {
3157
+ compatibilityDate: string;
3158
+ compatibilityFlags?: string[];
3159
+ allowExperimental?: boolean;
3160
+ mainModule: string;
3161
+ modules: Record<string, WorkerLoaderModule | string>;
3162
+ env?: any;
3163
+ globalOutbound?: Fetcher | null;
3164
+ tails?: Fetcher[];
3165
+ streamingTails?: Fetcher[];
3166
+ }
3106
3167
  /**
3107
3168
  * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3108
3169
  * as well as timing of subrequests and other operations.
3109
3170
  *
3110
3171
  * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
3111
3172
  */
3112
- export declare abstract class Performance extends EventTarget {
3173
+ export declare abstract class Performance {
3113
3174
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
3114
3175
  get timeOrigin(): number;
3115
3176
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3116
3177
  now(): number;
3117
- get eventCounts(): EventCounts;
3118
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMarks) */
3119
- clearMarks(name?: string): void;
3120
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMeasures) */
3121
- clearMeasures(name?: string): void;
3122
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearResourceTimings) */
3123
- clearResourceTimings(): void;
3124
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntries) */
3125
- getEntries(): PerformanceEntry[];
3126
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByName) */
3127
- getEntriesByName(name: string, type: string): PerformanceEntry[];
3128
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByType) */
3129
- getEntriesByType(type: string): PerformanceEntry[];
3130
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/mark) */
3131
- mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
3132
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/measure) */
3133
- measure(
3134
- measureName: string,
3135
- measureOptionsOrStartMark: PerformanceMeasureOptions | string,
3136
- maybeEndMark?: string,
3137
- ): PerformanceMeasure;
3138
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/setResourceTimingBufferSize) */
3139
- setResourceTimingBufferSize(size: number): void;
3140
- }
3141
- /**
3142
- * PerformanceMark is an abstract interface for PerformanceEntry objects with an entryType of "mark". Entries of this type are created by calling performance.mark() to add a named DOMHighResTimeStamp (the mark) to the browser's performance timeline.
3143
- *
3144
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark)
3145
- */
3146
- export interface PerformanceMark extends PerformanceEntry {
3147
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark/detail) */
3148
- get detail(): any;
3149
- }
3150
- /**
3151
- * PerformanceMeasure is an abstract interface for PerformanceEntry objects with an entryType of "measure". Entries of this type are created by calling performance.measure() to add a named DOMHighResTimeStamp (the measure) between two marks to the browser's performance timeline.
3152
- *
3153
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure)
3154
- */
3155
- export interface PerformanceMeasure extends PerformanceEntry {
3156
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure/detail) */
3157
- get detail(): any;
3158
- }
3159
- export interface PerformanceMarkOptions {
3160
- detail?: any;
3161
- startTime?: number;
3162
- }
3163
- export interface PerformanceMeasureOptions {
3164
- detail?: any;
3165
- start?: number;
3166
- duration?: number;
3167
- end?: number;
3168
- }
3169
- /**
3170
- * Encapsulates a single performance metric that is part of the performance timeline. A performance entry can be directly created by making a performance mark or measure (for example by calling the mark() method) at an explicit point in an application. Performance entries are also created in indirect ways such as loading a resource (such as an image).
3171
- *
3172
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry)
3173
- */
3174
- export declare abstract class PerformanceEntry {
3175
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/name) */
3176
- get name(): string;
3177
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/entryType) */
3178
- get entryType(): string;
3179
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/startTime) */
3180
- get startTime(): number;
3181
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/duration) */
3182
- get duration(): number;
3183
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/toJSON) */
3184
- toJSON(): any;
3185
- }
3186
- export interface EventCounts {
3187
- get size(): number;
3188
- get(eventType: string): number | undefined;
3189
- has(eventType: string): boolean;
3190
- entries(): IterableIterator<string[]>;
3191
- keys(): IterableIterator<string>;
3192
- values(): IterableIterator<number>;
3193
- forEach(
3194
- param1: (param0: number, param1: string, param2: EventCounts) => void,
3195
- param2?: any,
3196
- ): void;
3197
- [Symbol.iterator](): IterableIterator<string[]>;
3198
3178
  }
3199
3179
  export type AiImageClassificationInput = {
3200
3180
  image: number[];
@@ -8077,7 +8057,167 @@ export declare namespace Rpc {
8077
8057
  };
8078
8058
  }
8079
8059
  export declare namespace Cloudflare {
8060
+ // Type of `env`.
8061
+ //
8062
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8063
+ // will merge all declarations.
8064
+ //
8065
+ // You can use `wrangler types` to generate the `Env` type automatically.
8080
8066
  interface Env {}
8067
+ // Project-specific parameters used to inform types.
8068
+ //
8069
+ // This interface is, again, intended to be declared in project-specific files, and then that
8070
+ // declaration will be merged with this one.
8071
+ //
8072
+ // A project should have a declaration like this:
8073
+ //
8074
+ // interface GlobalProps {
8075
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8076
+ // // of `ctx.exports`.
8077
+ // mainModule: typeof import("my-main-module");
8078
+ //
8079
+ // // Declares which of the main module's exports are configured with durable storage, and
8080
+ // // thus should behave as Durable Object namsepace bindings.
8081
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8082
+ // }
8083
+ //
8084
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8085
+ interface GlobalProps {}
8086
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8087
+ // present.
8088
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8089
+ ? GlobalProps[K]
8090
+ : Default;
8091
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8092
+ // `mainModule` property.
8093
+ type MainModule = GlobalProp<"mainModule", {}>;
8094
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8095
+ type Exports = {
8096
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8097
+ // If the export is listed in `durableNamespaces`, then it is also a
8098
+ // DurableObjectNamespace.
8099
+ (K extends GlobalProp<"durableNamespaces", never>
8100
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8101
+ ? DoInstance extends Rpc.DurableObjectBranded
8102
+ ? DurableObjectNamespace<DoInstance>
8103
+ : DurableObjectNamespace<undefined>
8104
+ : DurableObjectNamespace<undefined>
8105
+ : {});
8106
+ };
8107
+ }
8108
+ export declare namespace CloudflareWorkersModule {
8109
+ export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8110
+ export const RpcStub: {
8111
+ new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
8112
+ };
8113
+ export abstract class RpcTarget implements Rpc.RpcTargetBranded {
8114
+ [Rpc.__RPC_TARGET_BRAND]: never;
8115
+ }
8116
+ // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8117
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8118
+ implements Rpc.WorkerEntrypointBranded
8119
+ {
8120
+ [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8121
+ protected ctx: ExecutionContext<Props>;
8122
+ protected env: Env;
8123
+ constructor(ctx: ExecutionContext, env: Env);
8124
+ fetch?(request: Request): Response | Promise<Response>;
8125
+ tail?(events: TraceItem[]): void | Promise<void>;
8126
+ trace?(traces: TraceItem[]): void | Promise<void>;
8127
+ scheduled?(controller: ScheduledController): void | Promise<void>;
8128
+ queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8129
+ test?(controller: TestController): void | Promise<void>;
8130
+ }
8131
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8132
+ implements Rpc.DurableObjectBranded
8133
+ {
8134
+ [Rpc.__DURABLE_OBJECT_BRAND]: never;
8135
+ protected ctx: DurableObjectState<Props>;
8136
+ protected env: Env;
8137
+ constructor(ctx: DurableObjectState, env: Env);
8138
+ fetch?(request: Request): Response | Promise<Response>;
8139
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
8140
+ webSocketMessage?(
8141
+ ws: WebSocket,
8142
+ message: string | ArrayBuffer,
8143
+ ): void | Promise<void>;
8144
+ webSocketClose?(
8145
+ ws: WebSocket,
8146
+ code: number,
8147
+ reason: string,
8148
+ wasClean: boolean,
8149
+ ): void | Promise<void>;
8150
+ webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>;
8151
+ }
8152
+ export type WorkflowDurationLabel =
8153
+ | "second"
8154
+ | "minute"
8155
+ | "hour"
8156
+ | "day"
8157
+ | "week"
8158
+ | "month"
8159
+ | "year";
8160
+ export type WorkflowSleepDuration =
8161
+ | `${number} ${WorkflowDurationLabel}${"s" | ""}`
8162
+ | number;
8163
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
8164
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
8165
+ export type WorkflowRetentionDuration = WorkflowSleepDuration;
8166
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
8167
+ export type WorkflowStepConfig = {
8168
+ retries?: {
8169
+ limit: number;
8170
+ delay: WorkflowDelayDuration | number;
8171
+ backoff?: WorkflowBackoff;
8172
+ };
8173
+ timeout?: WorkflowTimeoutDuration | number;
8174
+ };
8175
+ export type WorkflowEvent<T> = {
8176
+ payload: Readonly<T>;
8177
+ timestamp: Date;
8178
+ instanceId: string;
8179
+ };
8180
+ export type WorkflowStepEvent<T> = {
8181
+ payload: Readonly<T>;
8182
+ timestamp: Date;
8183
+ type: string;
8184
+ };
8185
+ export abstract class WorkflowStep {
8186
+ do<T extends Rpc.Serializable<T>>(
8187
+ name: string,
8188
+ callback: () => Promise<T>,
8189
+ ): Promise<T>;
8190
+ do<T extends Rpc.Serializable<T>>(
8191
+ name: string,
8192
+ config: WorkflowStepConfig,
8193
+ callback: () => Promise<T>,
8194
+ ): Promise<T>;
8195
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
8196
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
8197
+ waitForEvent<T extends Rpc.Serializable<T>>(
8198
+ name: string,
8199
+ options: {
8200
+ type: string;
8201
+ timeout?: WorkflowTimeoutDuration | number;
8202
+ },
8203
+ ): Promise<WorkflowStepEvent<T>>;
8204
+ }
8205
+ export abstract class WorkflowEntrypoint<
8206
+ Env = unknown,
8207
+ T extends Rpc.Serializable<T> | unknown = unknown,
8208
+ > implements Rpc.WorkflowEntrypointBranded
8209
+ {
8210
+ [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
8211
+ protected ctx: ExecutionContext;
8212
+ protected env: Env;
8213
+ constructor(ctx: ExecutionContext, env: Env);
8214
+ run(
8215
+ event: Readonly<WorkflowEvent<T>>,
8216
+ step: WorkflowStep,
8217
+ ): Promise<unknown>;
8218
+ }
8219
+ export function waitUntil(promise: Promise<unknown>): void;
8220
+ export const env: Cloudflare.Env;
8081
8221
  }
8082
8222
  export interface SecretsStoreSecret {
8083
8223
  /**