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