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