@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.
package/latest/index.d.ts CHANGED
@@ -396,10 +396,10 @@ declare const Cloudflare: Cloudflare;
396
396
  declare const origin: string;
397
397
  declare const navigator: Navigator;
398
398
  interface TestController {}
399
- interface ExecutionContext {
399
+ interface ExecutionContext<Props = unknown> {
400
400
  waitUntil(promise: Promise<any>): void;
401
401
  passThroughOnException(): void;
402
- props: any;
402
+ readonly props: Props;
403
403
  }
404
404
  type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = (
405
405
  request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
@@ -550,9 +550,12 @@ type DurableObjectLocationHint =
550
550
  interface DurableObjectNamespaceGetDurableObjectOptions {
551
551
  locationHint?: DurableObjectLocationHint;
552
552
  }
553
- interface DurableObjectState {
553
+ interface DurableObjectClass<
554
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
555
+ > {}
556
+ interface DurableObjectState<Props = unknown> {
554
557
  waitUntil(promise: Promise<any>): void;
555
- props: any;
558
+ readonly props: Props;
556
559
  readonly id: DurableObjectId;
557
560
  readonly storage: DurableObjectStorage;
558
561
  container?: Container;
@@ -3115,6 +3118,30 @@ declare class MessageChannel {
3115
3118
  interface MessagePortPostMessageOptions {
3116
3119
  transfer?: any[];
3117
3120
  }
3121
+ type LoopbackForExport<
3122
+ T extends
3123
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3124
+ | ExportedHandler<any, any, any>
3125
+ | undefined = undefined,
3126
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3127
+ ? LoopbackServiceStub<InstanceType<T>>
3128
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3129
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3130
+ : T extends ExportedHandler<any, any, any>
3131
+ ? LoopbackServiceStub<undefined>
3132
+ : undefined;
3133
+ type LoopbackServiceStub<
3134
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3135
+ > = Fetcher<T> &
3136
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3137
+ ? (opts: { props?: Props }) => Fetcher<T>
3138
+ : (opts: { props?: any }) => Fetcher<T>);
3139
+ type LoopbackDurableObjectClass<
3140
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3141
+ > = DurableObjectClass<T> &
3142
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3143
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3144
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3118
3145
  interface SyncKvStorage {
3119
3146
  get<T = unknown>(key: string): T | undefined;
3120
3147
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3129,6 +3156,40 @@ interface SyncKvListOptions {
3129
3156
  reverse?: boolean;
3130
3157
  limit?: number;
3131
3158
  }
3159
+ interface WorkerStub {
3160
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3161
+ name?: string,
3162
+ options?: WorkerStubEntrypointOptions,
3163
+ ): Fetcher<T>;
3164
+ }
3165
+ interface WorkerStubEntrypointOptions {
3166
+ props?: any;
3167
+ }
3168
+ interface WorkerLoader {
3169
+ get(
3170
+ name: string,
3171
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3172
+ ): WorkerStub;
3173
+ }
3174
+ interface WorkerLoaderModule {
3175
+ js?: string;
3176
+ cjs?: string;
3177
+ text?: string;
3178
+ data?: ArrayBuffer;
3179
+ json?: any;
3180
+ py?: string;
3181
+ }
3182
+ interface WorkerLoaderWorkerCode {
3183
+ compatibilityDate: string;
3184
+ compatibilityFlags?: string[];
3185
+ allowExperimental?: boolean;
3186
+ mainModule: string;
3187
+ modules: Record<string, WorkerLoaderModule | string>;
3188
+ env?: any;
3189
+ globalOutbound?: Fetcher | null;
3190
+ tails?: Fetcher[];
3191
+ streamingTails?: Fetcher[];
3192
+ }
3132
3193
  /**
3133
3194
  * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3134
3195
  * as well as timing of subrequests and other operations.
@@ -3150,7 +3211,7 @@ declare abstract class Performance extends EventTarget {
3150
3211
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntries) */
3151
3212
  getEntries(): PerformanceEntry[];
3152
3213
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByName) */
3153
- getEntriesByName(name: string, type: string): PerformanceEntry[];
3214
+ getEntriesByName(name: string, type?: string): PerformanceEntry[];
3154
3215
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByType) */
3155
3216
  getEntriesByType(type: string): PerformanceEntry[];
3156
3217
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/mark) */
@@ -3169,9 +3230,11 @@ declare abstract class Performance extends EventTarget {
3169
3230
  *
3170
3231
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark)
3171
3232
  */
3172
- declare abstract class PerformanceMark extends PerformanceEntry {
3233
+ declare class PerformanceMark extends PerformanceEntry {
3234
+ constructor(name: string, maybeOptions?: PerformanceMarkOptions);
3173
3235
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark/detail) */
3174
- get detail(): any;
3236
+ get detail(): any | undefined;
3237
+ toJSON(): any;
3175
3238
  }
3176
3239
  /**
3177
3240
  * 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.
@@ -3180,7 +3243,8 @@ declare abstract class PerformanceMark extends PerformanceEntry {
3180
3243
  */
3181
3244
  declare abstract class PerformanceMeasure extends PerformanceEntry {
3182
3245
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure/detail) */
3183
- get detail(): any;
3246
+ get detail(): any | undefined;
3247
+ toJSON(): any;
3184
3248
  }
3185
3249
  interface PerformanceMarkOptions {
3186
3250
  detail?: any;
@@ -3273,11 +3337,10 @@ declare class PerformanceObserver {
3273
3337
  readonly supportedEntryTypes: string[];
3274
3338
  }
3275
3339
  interface PerformanceObserverObserveOptions {
3276
- buffered: boolean;
3277
- durationThreshold: number;
3278
- entryTypes: string[];
3340
+ buffered?: boolean;
3341
+ durationThreshold?: number;
3342
+ entryTypes?: string[];
3279
3343
  type?: string;
3280
- name?: string;
3281
3344
  }
3282
3345
  interface EventCounts {
3283
3346
  get size(): number;
@@ -8202,7 +8265,53 @@ declare namespace Rpc {
8202
8265
  };
8203
8266
  }
8204
8267
  declare namespace Cloudflare {
8268
+ // Type of `env`.
8269
+ //
8270
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8271
+ // will merge all declarations.
8272
+ //
8273
+ // You can use `wrangler types` to generate the `Env` type automatically.
8205
8274
  interface Env {}
8275
+ // Project-specific parameters used to inform types.
8276
+ //
8277
+ // This interface is, again, intended to be declared in project-specific files, and then that
8278
+ // declaration will be merged with this one.
8279
+ //
8280
+ // A project should have a declaration like this:
8281
+ //
8282
+ // interface GlobalProps {
8283
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8284
+ // // of `ctx.exports`.
8285
+ // mainModule: typeof import("my-main-module");
8286
+ //
8287
+ // // Declares which of the main module's exports are configured with durable storage, and
8288
+ // // thus should behave as Durable Object namsepace bindings.
8289
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8290
+ // }
8291
+ //
8292
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8293
+ interface GlobalProps {}
8294
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8295
+ // present.
8296
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8297
+ ? GlobalProps[K]
8298
+ : Default;
8299
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8300
+ // `mainModule` property.
8301
+ type MainModule = GlobalProp<"mainModule", {}>;
8302
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8303
+ type Exports = {
8304
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8305
+ // If the export is listed in `durableNamespaces`, then it is also a
8306
+ // DurableObjectNamespace.
8307
+ (K extends GlobalProp<"durableNamespaces", never>
8308
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8309
+ ? DoInstance extends Rpc.DurableObjectBranded
8310
+ ? DurableObjectNamespace<DoInstance>
8311
+ : DurableObjectNamespace<undefined>
8312
+ : DurableObjectNamespace<undefined>
8313
+ : {});
8314
+ };
8206
8315
  }
8207
8316
  declare module "cloudflare:node" {
8208
8317
  export interface DefaultHandler {
@@ -8220,7 +8329,7 @@ declare module "cloudflare:node" {
8220
8329
  handlers?: Omit<DefaultHandler, "fetch">,
8221
8330
  ): DefaultHandler;
8222
8331
  }
8223
- declare module "cloudflare:workers" {
8332
+ declare namespace CloudflareWorkersModule {
8224
8333
  export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8225
8334
  export const RpcStub: {
8226
8335
  new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
@@ -8229,11 +8338,11 @@ declare module "cloudflare:workers" {
8229
8338
  [Rpc.__RPC_TARGET_BRAND]: never;
8230
8339
  }
8231
8340
  // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8232
- export abstract class WorkerEntrypoint<Env = unknown>
8341
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8233
8342
  implements Rpc.WorkerEntrypointBranded
8234
8343
  {
8235
8344
  [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8236
- protected ctx: ExecutionContext;
8345
+ protected ctx: ExecutionContext<Props>;
8237
8346
  protected env: Env;
8238
8347
  constructor(ctx: ExecutionContext, env: Env);
8239
8348
  fetch?(request: Request): Response | Promise<Response>;
@@ -8243,11 +8352,11 @@ declare module "cloudflare:workers" {
8243
8352
  queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8244
8353
  test?(controller: TestController): void | Promise<void>;
8245
8354
  }
8246
- export abstract class DurableObject<Env = unknown>
8355
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8247
8356
  implements Rpc.DurableObjectBranded
8248
8357
  {
8249
8358
  [Rpc.__DURABLE_OBJECT_BRAND]: never;
8250
- protected ctx: DurableObjectState;
8359
+ protected ctx: DurableObjectState<Props>;
8251
8360
  protected env: Env;
8252
8361
  constructor(ctx: DurableObjectState, env: Env);
8253
8362
  fetch?(request: Request): Response | Promise<Response>;
@@ -8334,6 +8443,9 @@ declare module "cloudflare:workers" {
8334
8443
  export function waitUntil(promise: Promise<unknown>): void;
8335
8444
  export const env: Cloudflare.Env;
8336
8445
  }
8446
+ declare module "cloudflare:workers" {
8447
+ export = CloudflareWorkersModule;
8448
+ }
8337
8449
  interface SecretsStoreSecret {
8338
8450
  /**
8339
8451
  * Get a secret from the Secrets Store, returning a string of the secret value
package/latest/index.ts CHANGED
@@ -398,10 +398,10 @@ export declare const Cloudflare: Cloudflare;
398
398
  export declare const origin: string;
399
399
  export declare const navigator: Navigator;
400
400
  export interface TestController {}
401
- export interface ExecutionContext {
401
+ export interface ExecutionContext<Props = unknown> {
402
402
  waitUntil(promise: Promise<any>): void;
403
403
  passThroughOnException(): void;
404
- props: any;
404
+ readonly props: Props;
405
405
  }
406
406
  export type ExportedHandlerFetchHandler<
407
407
  Env = unknown,
@@ -555,9 +555,12 @@ export type DurableObjectLocationHint =
555
555
  export interface DurableObjectNamespaceGetDurableObjectOptions {
556
556
  locationHint?: DurableObjectLocationHint;
557
557
  }
558
- export interface DurableObjectState {
558
+ export interface DurableObjectClass<
559
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
560
+ > {}
561
+ export interface DurableObjectState<Props = unknown> {
559
562
  waitUntil(promise: Promise<any>): void;
560
- props: any;
563
+ readonly props: Props;
561
564
  readonly id: DurableObjectId;
562
565
  readonly storage: DurableObjectStorage;
563
566
  container?: Container;
@@ -3126,6 +3129,30 @@ export declare class MessageChannel {
3126
3129
  export interface MessagePortPostMessageOptions {
3127
3130
  transfer?: any[];
3128
3131
  }
3132
+ export type LoopbackForExport<
3133
+ T extends
3134
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3135
+ | ExportedHandler<any, any, any>
3136
+ | undefined = undefined,
3137
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3138
+ ? LoopbackServiceStub<InstanceType<T>>
3139
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3140
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3141
+ : T extends ExportedHandler<any, any, any>
3142
+ ? LoopbackServiceStub<undefined>
3143
+ : undefined;
3144
+ export type LoopbackServiceStub<
3145
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3146
+ > = Fetcher<T> &
3147
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3148
+ ? (opts: { props?: Props }) => Fetcher<T>
3149
+ : (opts: { props?: any }) => Fetcher<T>);
3150
+ export type LoopbackDurableObjectClass<
3151
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3152
+ > = DurableObjectClass<T> &
3153
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3154
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3155
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3129
3156
  export interface SyncKvStorage {
3130
3157
  get<T = unknown>(key: string): T | undefined;
3131
3158
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3140,6 +3167,40 @@ export interface SyncKvListOptions {
3140
3167
  reverse?: boolean;
3141
3168
  limit?: number;
3142
3169
  }
3170
+ export interface WorkerStub {
3171
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3172
+ name?: string,
3173
+ options?: WorkerStubEntrypointOptions,
3174
+ ): Fetcher<T>;
3175
+ }
3176
+ export interface WorkerStubEntrypointOptions {
3177
+ props?: any;
3178
+ }
3179
+ export interface WorkerLoader {
3180
+ get(
3181
+ name: string,
3182
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3183
+ ): WorkerStub;
3184
+ }
3185
+ export interface WorkerLoaderModule {
3186
+ js?: string;
3187
+ cjs?: string;
3188
+ text?: string;
3189
+ data?: ArrayBuffer;
3190
+ json?: any;
3191
+ py?: string;
3192
+ }
3193
+ export interface WorkerLoaderWorkerCode {
3194
+ compatibilityDate: string;
3195
+ compatibilityFlags?: string[];
3196
+ allowExperimental?: boolean;
3197
+ mainModule: string;
3198
+ modules: Record<string, WorkerLoaderModule | string>;
3199
+ env?: any;
3200
+ globalOutbound?: Fetcher | null;
3201
+ tails?: Fetcher[];
3202
+ streamingTails?: Fetcher[];
3203
+ }
3143
3204
  /**
3144
3205
  * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3145
3206
  * as well as timing of subrequests and other operations.
@@ -3161,7 +3222,7 @@ export declare abstract class Performance extends EventTarget {
3161
3222
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntries) */
3162
3223
  getEntries(): PerformanceEntry[];
3163
3224
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByName) */
3164
- getEntriesByName(name: string, type: string): PerformanceEntry[];
3225
+ getEntriesByName(name: string, type?: string): PerformanceEntry[];
3165
3226
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByType) */
3166
3227
  getEntriesByType(type: string): PerformanceEntry[];
3167
3228
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/mark) */
@@ -3180,9 +3241,11 @@ export declare abstract class Performance extends EventTarget {
3180
3241
  *
3181
3242
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark)
3182
3243
  */
3183
- export declare abstract class PerformanceMark extends PerformanceEntry {
3244
+ export declare class PerformanceMark extends PerformanceEntry {
3245
+ constructor(name: string, maybeOptions?: PerformanceMarkOptions);
3184
3246
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark/detail) */
3185
- get detail(): any;
3247
+ get detail(): any | undefined;
3248
+ toJSON(): any;
3186
3249
  }
3187
3250
  /**
3188
3251
  * 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.
@@ -3191,7 +3254,8 @@ export declare abstract class PerformanceMark extends PerformanceEntry {
3191
3254
  */
3192
3255
  export declare abstract class PerformanceMeasure extends PerformanceEntry {
3193
3256
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure/detail) */
3194
- get detail(): any;
3257
+ get detail(): any | undefined;
3258
+ toJSON(): any;
3195
3259
  }
3196
3260
  export interface PerformanceMarkOptions {
3197
3261
  detail?: any;
@@ -3284,11 +3348,10 @@ export declare class PerformanceObserver {
3284
3348
  readonly supportedEntryTypes: string[];
3285
3349
  }
3286
3350
  export interface PerformanceObserverObserveOptions {
3287
- buffered: boolean;
3288
- durationThreshold: number;
3289
- entryTypes: string[];
3351
+ buffered?: boolean;
3352
+ durationThreshold?: number;
3353
+ entryTypes?: string[];
3290
3354
  type?: string;
3291
- name?: string;
3292
3355
  }
3293
3356
  export interface EventCounts {
3294
3357
  get size(): number;
@@ -8184,7 +8247,167 @@ export declare namespace Rpc {
8184
8247
  };
8185
8248
  }
8186
8249
  export declare namespace Cloudflare {
8250
+ // Type of `env`.
8251
+ //
8252
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8253
+ // will merge all declarations.
8254
+ //
8255
+ // You can use `wrangler types` to generate the `Env` type automatically.
8187
8256
  interface Env {}
8257
+ // Project-specific parameters used to inform types.
8258
+ //
8259
+ // This interface is, again, intended to be declared in project-specific files, and then that
8260
+ // declaration will be merged with this one.
8261
+ //
8262
+ // A project should have a declaration like this:
8263
+ //
8264
+ // interface GlobalProps {
8265
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8266
+ // // of `ctx.exports`.
8267
+ // mainModule: typeof import("my-main-module");
8268
+ //
8269
+ // // Declares which of the main module's exports are configured with durable storage, and
8270
+ // // thus should behave as Durable Object namsepace bindings.
8271
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8272
+ // }
8273
+ //
8274
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8275
+ interface GlobalProps {}
8276
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8277
+ // present.
8278
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8279
+ ? GlobalProps[K]
8280
+ : Default;
8281
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8282
+ // `mainModule` property.
8283
+ type MainModule = GlobalProp<"mainModule", {}>;
8284
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8285
+ type Exports = {
8286
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8287
+ // If the export is listed in `durableNamespaces`, then it is also a
8288
+ // DurableObjectNamespace.
8289
+ (K extends GlobalProp<"durableNamespaces", never>
8290
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8291
+ ? DoInstance extends Rpc.DurableObjectBranded
8292
+ ? DurableObjectNamespace<DoInstance>
8293
+ : DurableObjectNamespace<undefined>
8294
+ : DurableObjectNamespace<undefined>
8295
+ : {});
8296
+ };
8297
+ }
8298
+ export declare namespace CloudflareWorkersModule {
8299
+ export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8300
+ export const RpcStub: {
8301
+ new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
8302
+ };
8303
+ export abstract class RpcTarget implements Rpc.RpcTargetBranded {
8304
+ [Rpc.__RPC_TARGET_BRAND]: never;
8305
+ }
8306
+ // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8307
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8308
+ implements Rpc.WorkerEntrypointBranded
8309
+ {
8310
+ [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8311
+ protected ctx: ExecutionContext<Props>;
8312
+ protected env: Env;
8313
+ constructor(ctx: ExecutionContext, env: Env);
8314
+ fetch?(request: Request): Response | Promise<Response>;
8315
+ tail?(events: TraceItem[]): void | Promise<void>;
8316
+ trace?(traces: TraceItem[]): void | Promise<void>;
8317
+ scheduled?(controller: ScheduledController): void | Promise<void>;
8318
+ queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8319
+ test?(controller: TestController): void | Promise<void>;
8320
+ }
8321
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8322
+ implements Rpc.DurableObjectBranded
8323
+ {
8324
+ [Rpc.__DURABLE_OBJECT_BRAND]: never;
8325
+ protected ctx: DurableObjectState<Props>;
8326
+ protected env: Env;
8327
+ constructor(ctx: DurableObjectState, env: Env);
8328
+ fetch?(request: Request): Response | Promise<Response>;
8329
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
8330
+ webSocketMessage?(
8331
+ ws: WebSocket,
8332
+ message: string | ArrayBuffer,
8333
+ ): void | Promise<void>;
8334
+ webSocketClose?(
8335
+ ws: WebSocket,
8336
+ code: number,
8337
+ reason: string,
8338
+ wasClean: boolean,
8339
+ ): void | Promise<void>;
8340
+ webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>;
8341
+ }
8342
+ export type WorkflowDurationLabel =
8343
+ | "second"
8344
+ | "minute"
8345
+ | "hour"
8346
+ | "day"
8347
+ | "week"
8348
+ | "month"
8349
+ | "year";
8350
+ export type WorkflowSleepDuration =
8351
+ | `${number} ${WorkflowDurationLabel}${"s" | ""}`
8352
+ | number;
8353
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
8354
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
8355
+ export type WorkflowRetentionDuration = WorkflowSleepDuration;
8356
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
8357
+ export type WorkflowStepConfig = {
8358
+ retries?: {
8359
+ limit: number;
8360
+ delay: WorkflowDelayDuration | number;
8361
+ backoff?: WorkflowBackoff;
8362
+ };
8363
+ timeout?: WorkflowTimeoutDuration | number;
8364
+ };
8365
+ export type WorkflowEvent<T> = {
8366
+ payload: Readonly<T>;
8367
+ timestamp: Date;
8368
+ instanceId: string;
8369
+ };
8370
+ export type WorkflowStepEvent<T> = {
8371
+ payload: Readonly<T>;
8372
+ timestamp: Date;
8373
+ type: string;
8374
+ };
8375
+ export abstract class WorkflowStep {
8376
+ do<T extends Rpc.Serializable<T>>(
8377
+ name: string,
8378
+ callback: () => Promise<T>,
8379
+ ): Promise<T>;
8380
+ do<T extends Rpc.Serializable<T>>(
8381
+ name: string,
8382
+ config: WorkflowStepConfig,
8383
+ callback: () => Promise<T>,
8384
+ ): Promise<T>;
8385
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
8386
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
8387
+ waitForEvent<T extends Rpc.Serializable<T>>(
8388
+ name: string,
8389
+ options: {
8390
+ type: string;
8391
+ timeout?: WorkflowTimeoutDuration | number;
8392
+ },
8393
+ ): Promise<WorkflowStepEvent<T>>;
8394
+ }
8395
+ export abstract class WorkflowEntrypoint<
8396
+ Env = unknown,
8397
+ T extends Rpc.Serializable<T> | unknown = unknown,
8398
+ > implements Rpc.WorkflowEntrypointBranded
8399
+ {
8400
+ [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
8401
+ protected ctx: ExecutionContext;
8402
+ protected env: Env;
8403
+ constructor(ctx: ExecutionContext, env: Env);
8404
+ run(
8405
+ event: Readonly<WorkflowEvent<T>>,
8406
+ step: WorkflowStep,
8407
+ ): Promise<unknown>;
8408
+ }
8409
+ export function waitUntil(promise: Promise<unknown>): void;
8410
+ export const env: Cloudflare.Env;
8188
8411
  }
8189
8412
  export interface SecretsStoreSecret {
8190
8413
  /**