@workers-community/workers-types 4.20250910.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.
Files changed (3) hide show
  1. package/index.d.ts +132 -21
  2. package/index.ts +238 -16
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -294,6 +294,7 @@ interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
294
294
  FixedLengthStream: typeof FixedLengthStream;
295
295
  IdentityTransformStream: typeof IdentityTransformStream;
296
296
  HTMLRewriter: typeof HTMLRewriter;
297
+ Performance: typeof Performance;
297
298
  }
298
299
  declare function addEventListener<Type extends keyof WorkerGlobalScopeEventMap>(
299
300
  type: Type,
@@ -387,10 +388,10 @@ declare const Cloudflare: Cloudflare;
387
388
  declare const origin: string;
388
389
  declare const navigator: Navigator;
389
390
  interface TestController {}
390
- interface ExecutionContext {
391
+ interface ExecutionContext<Props = unknown> {
391
392
  waitUntil(promise: Promise<any>): void;
392
393
  passThroughOnException(): void;
393
- props: any;
394
+ readonly props: Props;
394
395
  }
395
396
  type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown> = (
396
397
  request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>,
@@ -466,18 +467,6 @@ declare abstract class Navigator {
466
467
  readonly userAgent: string;
467
468
  readonly hardwareConcurrency: number;
468
469
  }
469
- /**
470
- * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
471
- * as well as timing of subrequests and other operations.
472
- *
473
- * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
474
- */
475
- interface Performance {
476
- /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
477
- readonly timeOrigin: number;
478
- /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
479
- now(): number;
480
- }
481
470
  interface AlarmInvocationInfo {
482
471
  readonly isRetry: boolean;
483
472
  readonly retryCount: number;
@@ -551,9 +540,12 @@ type DurableObjectLocationHint =
551
540
  interface DurableObjectNamespaceGetDurableObjectOptions {
552
541
  locationHint?: DurableObjectLocationHint;
553
542
  }
554
- interface DurableObjectState {
543
+ interface DurableObjectClass<
544
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
545
+ > {}
546
+ interface DurableObjectState<Props = unknown> {
555
547
  waitUntil(promise: Promise<any>): void;
556
- props: any;
548
+ readonly props: Props;
557
549
  readonly id: DurableObjectId;
558
550
  readonly storage: DurableObjectStorage;
559
551
  container?: Container;
@@ -3091,6 +3083,30 @@ interface MessagePort extends EventTarget {
3091
3083
  interface MessagePortPostMessageOptions {
3092
3084
  transfer?: any[];
3093
3085
  }
3086
+ 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
+ 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
+ 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>);
3094
3110
  interface SyncKvStorage {
3095
3111
  get<T = unknown>(key: string): T | undefined;
3096
3112
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3105,6 +3121,52 @@ interface SyncKvListOptions {
3105
3121
  reverse?: boolean;
3106
3122
  limit?: number;
3107
3123
  }
3124
+ interface WorkerStub {
3125
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3126
+ name?: string,
3127
+ options?: WorkerStubEntrypointOptions,
3128
+ ): Fetcher<T>;
3129
+ }
3130
+ interface WorkerStubEntrypointOptions {
3131
+ props?: any;
3132
+ }
3133
+ interface WorkerLoader {
3134
+ get(
3135
+ name: string,
3136
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3137
+ ): WorkerStub;
3138
+ }
3139
+ interface WorkerLoaderModule {
3140
+ js?: string;
3141
+ cjs?: string;
3142
+ text?: string;
3143
+ data?: ArrayBuffer;
3144
+ json?: any;
3145
+ py?: string;
3146
+ }
3147
+ 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
+ }
3158
+ /**
3159
+ * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3160
+ * as well as timing of subrequests and other operations.
3161
+ *
3162
+ * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
3163
+ */
3164
+ declare abstract class Performance {
3165
+ /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
3166
+ get timeOrigin(): number;
3167
+ /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3168
+ now(): number;
3169
+ }
3108
3170
  type AiImageClassificationInput = {
3109
3171
  image: number[];
3110
3172
  };
@@ -8015,7 +8077,53 @@ declare namespace Rpc {
8015
8077
  };
8016
8078
  }
8017
8079
  declare namespace Cloudflare {
8080
+ // Type of `env`.
8081
+ //
8082
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8083
+ // will merge all declarations.
8084
+ //
8085
+ // You can use `wrangler types` to generate the `Env` type automatically.
8018
8086
  interface Env {}
8087
+ // Project-specific parameters used to inform types.
8088
+ //
8089
+ // This interface is, again, intended to be declared in project-specific files, and then that
8090
+ // declaration will be merged with this one.
8091
+ //
8092
+ // A project should have a declaration like this:
8093
+ //
8094
+ // interface GlobalProps {
8095
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8096
+ // // of `ctx.exports`.
8097
+ // mainModule: typeof import("my-main-module");
8098
+ //
8099
+ // // Declares which of the main module's exports are configured with durable storage, and
8100
+ // // thus should behave as Durable Object namsepace bindings.
8101
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8102
+ // }
8103
+ //
8104
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8105
+ interface GlobalProps {}
8106
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8107
+ // present.
8108
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8109
+ ? GlobalProps[K]
8110
+ : Default;
8111
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8112
+ // `mainModule` property.
8113
+ type MainModule = GlobalProp<"mainModule", {}>;
8114
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8115
+ type Exports = {
8116
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8117
+ // If the export is listed in `durableNamespaces`, then it is also a
8118
+ // DurableObjectNamespace.
8119
+ (K extends GlobalProp<"durableNamespaces", never>
8120
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8121
+ ? DoInstance extends Rpc.DurableObjectBranded
8122
+ ? DurableObjectNamespace<DoInstance>
8123
+ : DurableObjectNamespace<undefined>
8124
+ : DurableObjectNamespace<undefined>
8125
+ : {});
8126
+ };
8019
8127
  }
8020
8128
  declare module "cloudflare:node" {
8021
8129
  export interface DefaultHandler {
@@ -8033,7 +8141,7 @@ declare module "cloudflare:node" {
8033
8141
  handlers?: Omit<DefaultHandler, "fetch">,
8034
8142
  ): DefaultHandler;
8035
8143
  }
8036
- declare module "cloudflare:workers" {
8144
+ declare namespace CloudflareWorkersModule {
8037
8145
  export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8038
8146
  export const RpcStub: {
8039
8147
  new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
@@ -8042,11 +8150,11 @@ declare module "cloudflare:workers" {
8042
8150
  [Rpc.__RPC_TARGET_BRAND]: never;
8043
8151
  }
8044
8152
  // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8045
- export abstract class WorkerEntrypoint<Env = unknown>
8153
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8046
8154
  implements Rpc.WorkerEntrypointBranded
8047
8155
  {
8048
8156
  [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8049
- protected ctx: ExecutionContext;
8157
+ protected ctx: ExecutionContext<Props>;
8050
8158
  protected env: Env;
8051
8159
  constructor(ctx: ExecutionContext, env: Env);
8052
8160
  fetch?(request: Request): Response | Promise<Response>;
@@ -8056,11 +8164,11 @@ declare module "cloudflare:workers" {
8056
8164
  queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8057
8165
  test?(controller: TestController): void | Promise<void>;
8058
8166
  }
8059
- export abstract class DurableObject<Env = unknown>
8167
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8060
8168
  implements Rpc.DurableObjectBranded
8061
8169
  {
8062
8170
  [Rpc.__DURABLE_OBJECT_BRAND]: never;
8063
- protected ctx: DurableObjectState;
8171
+ protected ctx: DurableObjectState<Props>;
8064
8172
  protected env: Env;
8065
8173
  constructor(ctx: DurableObjectState, env: Env);
8066
8174
  fetch?(request: Request): Response | Promise<Response>;
@@ -8147,6 +8255,9 @@ declare module "cloudflare:workers" {
8147
8255
  export function waitUntil(promise: Promise<unknown>): void;
8148
8256
  export const env: Cloudflare.Env;
8149
8257
  }
8258
+ declare module "cloudflare:workers" {
8259
+ export = CloudflareWorkersModule;
8260
+ }
8150
8261
  interface SecretsStoreSecret {
8151
8262
  /**
8152
8263
  * Get a secret from the Secrets Store, returning a string of the secret value
package/index.ts CHANGED
@@ -294,6 +294,7 @@ export interface ServiceWorkerGlobalScope extends WorkerGlobalScope {
294
294
  FixedLengthStream: typeof FixedLengthStream;
295
295
  IdentityTransformStream: typeof IdentityTransformStream;
296
296
  HTMLRewriter: typeof HTMLRewriter;
297
+ Performance: typeof Performance;
297
298
  }
298
299
  export declare function addEventListener<
299
300
  Type extends keyof WorkerGlobalScopeEventMap,
@@ -389,10 +390,10 @@ export declare const Cloudflare: Cloudflare;
389
390
  export declare const origin: string;
390
391
  export declare const navigator: Navigator;
391
392
  export interface TestController {}
392
- export interface ExecutionContext {
393
+ export interface ExecutionContext<Props = unknown> {
393
394
  waitUntil(promise: Promise<any>): void;
394
395
  passThroughOnException(): void;
395
- props: any;
396
+ readonly props: Props;
396
397
  }
397
398
  export type ExportedHandlerFetchHandler<
398
399
  Env = unknown,
@@ -471,18 +472,6 @@ export declare abstract class Navigator {
471
472
  readonly userAgent: string;
472
473
  readonly hardwareConcurrency: number;
473
474
  }
474
- /**
475
- * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
476
- * as well as timing of subrequests and other operations.
477
- *
478
- * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
479
- */
480
- export interface Performance {
481
- /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
482
- readonly timeOrigin: number;
483
- /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
484
- now(): number;
485
- }
486
475
  export interface AlarmInvocationInfo {
487
476
  readonly isRetry: boolean;
488
477
  readonly retryCount: number;
@@ -556,9 +545,12 @@ export type DurableObjectLocationHint =
556
545
  export interface DurableObjectNamespaceGetDurableObjectOptions {
557
546
  locationHint?: DurableObjectLocationHint;
558
547
  }
559
- export interface DurableObjectState {
548
+ export interface DurableObjectClass<
549
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
550
+ > {}
551
+ export interface DurableObjectState<Props = unknown> {
560
552
  waitUntil(promise: Promise<any>): void;
561
- props: any;
553
+ readonly props: Props;
562
554
  readonly id: DurableObjectId;
563
555
  readonly storage: DurableObjectStorage;
564
556
  container?: Container;
@@ -3102,6 +3094,30 @@ export interface MessagePort extends EventTarget {
3102
3094
  export interface MessagePortPostMessageOptions {
3103
3095
  transfer?: any[];
3104
3096
  }
3097
+ export type LoopbackForExport<
3098
+ T extends
3099
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3100
+ | ExportedHandler<any, any, any>
3101
+ | undefined = undefined,
3102
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3103
+ ? LoopbackServiceStub<InstanceType<T>>
3104
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3105
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3106
+ : T extends ExportedHandler<any, any, any>
3107
+ ? LoopbackServiceStub<undefined>
3108
+ : undefined;
3109
+ export type LoopbackServiceStub<
3110
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3111
+ > = Fetcher<T> &
3112
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3113
+ ? (opts: { props?: Props }) => Fetcher<T>
3114
+ : (opts: { props?: any }) => Fetcher<T>);
3115
+ export type LoopbackDurableObjectClass<
3116
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3117
+ > = DurableObjectClass<T> &
3118
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3119
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3120
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3105
3121
  export interface SyncKvStorage {
3106
3122
  get<T = unknown>(key: string): T | undefined;
3107
3123
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3116,6 +3132,52 @@ export interface SyncKvListOptions {
3116
3132
  reverse?: boolean;
3117
3133
  limit?: number;
3118
3134
  }
3135
+ export interface WorkerStub {
3136
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3137
+ name?: string,
3138
+ options?: WorkerStubEntrypointOptions,
3139
+ ): Fetcher<T>;
3140
+ }
3141
+ export interface WorkerStubEntrypointOptions {
3142
+ props?: any;
3143
+ }
3144
+ export interface WorkerLoader {
3145
+ get(
3146
+ name: string,
3147
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3148
+ ): WorkerStub;
3149
+ }
3150
+ export interface WorkerLoaderModule {
3151
+ js?: string;
3152
+ cjs?: string;
3153
+ text?: string;
3154
+ data?: ArrayBuffer;
3155
+ json?: any;
3156
+ py?: string;
3157
+ }
3158
+ export interface WorkerLoaderWorkerCode {
3159
+ compatibilityDate: string;
3160
+ compatibilityFlags?: string[];
3161
+ allowExperimental?: boolean;
3162
+ mainModule: string;
3163
+ modules: Record<string, WorkerLoaderModule | string>;
3164
+ env?: any;
3165
+ globalOutbound?: Fetcher | null;
3166
+ tails?: Fetcher[];
3167
+ streamingTails?: Fetcher[];
3168
+ }
3169
+ /**
3170
+ * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3171
+ * as well as timing of subrequests and other operations.
3172
+ *
3173
+ * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
3174
+ */
3175
+ export declare abstract class Performance {
3176
+ /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
3177
+ get timeOrigin(): number;
3178
+ /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3179
+ now(): number;
3180
+ }
3119
3181
  export type AiImageClassificationInput = {
3120
3182
  image: number[];
3121
3183
  };
@@ -7997,7 +8059,167 @@ export declare namespace Rpc {
7997
8059
  };
7998
8060
  }
7999
8061
  export declare namespace Cloudflare {
8062
+ // Type of `env`.
8063
+ //
8064
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8065
+ // will merge all declarations.
8066
+ //
8067
+ // You can use `wrangler types` to generate the `Env` type automatically.
8000
8068
  interface Env {}
8069
+ // Project-specific parameters used to inform types.
8070
+ //
8071
+ // This interface is, again, intended to be declared in project-specific files, and then that
8072
+ // declaration will be merged with this one.
8073
+ //
8074
+ // A project should have a declaration like this:
8075
+ //
8076
+ // interface GlobalProps {
8077
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8078
+ // // of `ctx.exports`.
8079
+ // mainModule: typeof import("my-main-module");
8080
+ //
8081
+ // // Declares which of the main module's exports are configured with durable storage, and
8082
+ // // thus should behave as Durable Object namsepace bindings.
8083
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8084
+ // }
8085
+ //
8086
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8087
+ interface GlobalProps {}
8088
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8089
+ // present.
8090
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8091
+ ? GlobalProps[K]
8092
+ : Default;
8093
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8094
+ // `mainModule` property.
8095
+ type MainModule = GlobalProp<"mainModule", {}>;
8096
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8097
+ type Exports = {
8098
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8099
+ // If the export is listed in `durableNamespaces`, then it is also a
8100
+ // DurableObjectNamespace.
8101
+ (K extends GlobalProp<"durableNamespaces", never>
8102
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8103
+ ? DoInstance extends Rpc.DurableObjectBranded
8104
+ ? DurableObjectNamespace<DoInstance>
8105
+ : DurableObjectNamespace<undefined>
8106
+ : DurableObjectNamespace<undefined>
8107
+ : {});
8108
+ };
8109
+ }
8110
+ export declare namespace CloudflareWorkersModule {
8111
+ export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8112
+ export const RpcStub: {
8113
+ new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
8114
+ };
8115
+ export abstract class RpcTarget implements Rpc.RpcTargetBranded {
8116
+ [Rpc.__RPC_TARGET_BRAND]: never;
8117
+ }
8118
+ // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8119
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8120
+ implements Rpc.WorkerEntrypointBranded
8121
+ {
8122
+ [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8123
+ protected ctx: ExecutionContext<Props>;
8124
+ protected env: Env;
8125
+ constructor(ctx: ExecutionContext, env: Env);
8126
+ fetch?(request: Request): Response | Promise<Response>;
8127
+ tail?(events: TraceItem[]): void | Promise<void>;
8128
+ trace?(traces: TraceItem[]): void | Promise<void>;
8129
+ scheduled?(controller: ScheduledController): void | Promise<void>;
8130
+ queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8131
+ test?(controller: TestController): void | Promise<void>;
8132
+ }
8133
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8134
+ implements Rpc.DurableObjectBranded
8135
+ {
8136
+ [Rpc.__DURABLE_OBJECT_BRAND]: never;
8137
+ protected ctx: DurableObjectState<Props>;
8138
+ protected env: Env;
8139
+ constructor(ctx: DurableObjectState, env: Env);
8140
+ fetch?(request: Request): Response | Promise<Response>;
8141
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
8142
+ webSocketMessage?(
8143
+ ws: WebSocket,
8144
+ message: string | ArrayBuffer,
8145
+ ): void | Promise<void>;
8146
+ webSocketClose?(
8147
+ ws: WebSocket,
8148
+ code: number,
8149
+ reason: string,
8150
+ wasClean: boolean,
8151
+ ): void | Promise<void>;
8152
+ webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>;
8153
+ }
8154
+ export type WorkflowDurationLabel =
8155
+ | "second"
8156
+ | "minute"
8157
+ | "hour"
8158
+ | "day"
8159
+ | "week"
8160
+ | "month"
8161
+ | "year";
8162
+ export type WorkflowSleepDuration =
8163
+ | `${number} ${WorkflowDurationLabel}${"s" | ""}`
8164
+ | number;
8165
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
8166
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
8167
+ export type WorkflowRetentionDuration = WorkflowSleepDuration;
8168
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
8169
+ export type WorkflowStepConfig = {
8170
+ retries?: {
8171
+ limit: number;
8172
+ delay: WorkflowDelayDuration | number;
8173
+ backoff?: WorkflowBackoff;
8174
+ };
8175
+ timeout?: WorkflowTimeoutDuration | number;
8176
+ };
8177
+ export type WorkflowEvent<T> = {
8178
+ payload: Readonly<T>;
8179
+ timestamp: Date;
8180
+ instanceId: string;
8181
+ };
8182
+ export type WorkflowStepEvent<T> = {
8183
+ payload: Readonly<T>;
8184
+ timestamp: Date;
8185
+ type: string;
8186
+ };
8187
+ export abstract class WorkflowStep {
8188
+ do<T extends Rpc.Serializable<T>>(
8189
+ name: string,
8190
+ callback: () => Promise<T>,
8191
+ ): Promise<T>;
8192
+ do<T extends Rpc.Serializable<T>>(
8193
+ name: string,
8194
+ config: WorkflowStepConfig,
8195
+ callback: () => Promise<T>,
8196
+ ): Promise<T>;
8197
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
8198
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
8199
+ waitForEvent<T extends Rpc.Serializable<T>>(
8200
+ name: string,
8201
+ options: {
8202
+ type: string;
8203
+ timeout?: WorkflowTimeoutDuration | number;
8204
+ },
8205
+ ): Promise<WorkflowStepEvent<T>>;
8206
+ }
8207
+ export abstract class WorkflowEntrypoint<
8208
+ Env = unknown,
8209
+ T extends Rpc.Serializable<T> | unknown = unknown,
8210
+ > implements Rpc.WorkflowEntrypointBranded
8211
+ {
8212
+ [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
8213
+ protected ctx: ExecutionContext;
8214
+ protected env: Env;
8215
+ constructor(ctx: ExecutionContext, env: Env);
8216
+ run(
8217
+ event: Readonly<WorkflowEvent<T>>,
8218
+ step: WorkflowStep,
8219
+ ): Promise<unknown>;
8220
+ }
8221
+ export function waitUntil(promise: Promise<unknown>): void;
8222
+ export const env: Cloudflare.Env;
8001
8223
  }
8002
8224
  export interface SecretsStoreSecret {
8003
8225
  /**
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "author": "Workers Community",
9
9
  "license": "MIT OR Apache-2.0",
10
- "version": "4.20250910.0",
10
+ "version": "4.20250912.0",
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./index.d.ts",