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