@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/index.d.ts CHANGED
@@ -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;
@@ -3024,6 +3027,30 @@ interface MessagePort extends EventTarget {
3024
3027
  interface MessagePortPostMessageOptions {
3025
3028
  transfer?: any[];
3026
3029
  }
3030
+ type LoopbackForExport<
3031
+ T extends
3032
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3033
+ | ExportedHandler<any, any, any>
3034
+ | undefined = undefined,
3035
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3036
+ ? LoopbackServiceStub<InstanceType<T>>
3037
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3038
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3039
+ : T extends ExportedHandler<any, any, any>
3040
+ ? LoopbackServiceStub<undefined>
3041
+ : undefined;
3042
+ type LoopbackServiceStub<
3043
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3044
+ > = Fetcher<T> &
3045
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3046
+ ? (opts: { props?: Props }) => Fetcher<T>
3047
+ : (opts: { props?: any }) => Fetcher<T>);
3048
+ type LoopbackDurableObjectClass<
3049
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3050
+ > = DurableObjectClass<T> &
3051
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3052
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3053
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3027
3054
  interface SyncKvStorage {
3028
3055
  get<T = unknown>(key: string): T | undefined;
3029
3056
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3038,98 +3065,51 @@ interface SyncKvListOptions {
3038
3065
  reverse?: boolean;
3039
3066
  limit?: number;
3040
3067
  }
3068
+ interface WorkerStub {
3069
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3070
+ name?: string,
3071
+ options?: WorkerStubEntrypointOptions,
3072
+ ): Fetcher<T>;
3073
+ }
3074
+ interface WorkerStubEntrypointOptions {
3075
+ props?: any;
3076
+ }
3077
+ interface WorkerLoader {
3078
+ get(
3079
+ name: string,
3080
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3081
+ ): WorkerStub;
3082
+ }
3083
+ interface WorkerLoaderModule {
3084
+ js?: string;
3085
+ cjs?: string;
3086
+ text?: string;
3087
+ data?: ArrayBuffer;
3088
+ json?: any;
3089
+ py?: string;
3090
+ }
3091
+ interface WorkerLoaderWorkerCode {
3092
+ compatibilityDate: string;
3093
+ compatibilityFlags?: string[];
3094
+ allowExperimental?: boolean;
3095
+ mainModule: string;
3096
+ modules: Record<string, WorkerLoaderModule | string>;
3097
+ env?: any;
3098
+ globalOutbound?: Fetcher | null;
3099
+ tails?: Fetcher[];
3100
+ streamingTails?: Fetcher[];
3101
+ }
3041
3102
  /**
3042
3103
  * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3043
3104
  * as well as timing of subrequests and other operations.
3044
3105
  *
3045
3106
  * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
3046
3107
  */
3047
- declare abstract class Performance extends EventTarget {
3108
+ declare abstract class Performance {
3048
3109
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
3049
3110
  get timeOrigin(): number;
3050
3111
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3051
3112
  now(): number;
3052
- get eventCounts(): EventCounts;
3053
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMarks) */
3054
- clearMarks(name?: string): void;
3055
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMeasures) */
3056
- clearMeasures(name?: string): void;
3057
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearResourceTimings) */
3058
- clearResourceTimings(): void;
3059
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntries) */
3060
- getEntries(): PerformanceEntry[];
3061
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByName) */
3062
- getEntriesByName(name: string, type: string): PerformanceEntry[];
3063
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByType) */
3064
- getEntriesByType(type: string): PerformanceEntry[];
3065
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/mark) */
3066
- mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
3067
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/measure) */
3068
- measure(
3069
- measureName: string,
3070
- measureOptionsOrStartMark: PerformanceMeasureOptions | string,
3071
- maybeEndMark?: string,
3072
- ): PerformanceMeasure;
3073
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/setResourceTimingBufferSize) */
3074
- setResourceTimingBufferSize(size: number): void;
3075
- }
3076
- /**
3077
- * 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.
3078
- *
3079
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark)
3080
- */
3081
- interface PerformanceMark extends PerformanceEntry {
3082
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark/detail) */
3083
- get detail(): any;
3084
- }
3085
- /**
3086
- * 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.
3087
- *
3088
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure)
3089
- */
3090
- interface PerformanceMeasure extends PerformanceEntry {
3091
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure/detail) */
3092
- get detail(): any;
3093
- }
3094
- interface PerformanceMarkOptions {
3095
- detail?: any;
3096
- startTime?: number;
3097
- }
3098
- interface PerformanceMeasureOptions {
3099
- detail?: any;
3100
- start?: number;
3101
- duration?: number;
3102
- end?: number;
3103
- }
3104
- /**
3105
- * 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).
3106
- *
3107
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry)
3108
- */
3109
- declare abstract class PerformanceEntry {
3110
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/name) */
3111
- get name(): string;
3112
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/entryType) */
3113
- get entryType(): string;
3114
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/startTime) */
3115
- get startTime(): number;
3116
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/duration) */
3117
- get duration(): number;
3118
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/toJSON) */
3119
- toJSON(): any;
3120
- }
3121
- interface EventCounts {
3122
- get size(): number;
3123
- get(eventType: string): number | undefined;
3124
- has(eventType: string): boolean;
3125
- entries(): IterableIterator<string[]>;
3126
- keys(): IterableIterator<string>;
3127
- values(): IterableIterator<number>;
3128
- forEach(
3129
- param1: (param0: number, param1: string, param2: EventCounts) => void,
3130
- param2?: any,
3131
- ): void;
3132
- [Symbol.iterator](): IterableIterator<string[]>;
3133
3113
  }
3134
3114
  type AiImageClassificationInput = {
3135
3115
  image: number[];
@@ -8041,7 +8021,53 @@ declare namespace Rpc {
8041
8021
  };
8042
8022
  }
8043
8023
  declare namespace Cloudflare {
8024
+ // Type of `env`.
8025
+ //
8026
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8027
+ // will merge all declarations.
8028
+ //
8029
+ // You can use `wrangler types` to generate the `Env` type automatically.
8044
8030
  interface Env {}
8031
+ // Project-specific parameters used to inform types.
8032
+ //
8033
+ // This interface is, again, intended to be declared in project-specific files, and then that
8034
+ // declaration will be merged with this one.
8035
+ //
8036
+ // A project should have a declaration like this:
8037
+ //
8038
+ // interface GlobalProps {
8039
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8040
+ // // of `ctx.exports`.
8041
+ // mainModule: typeof import("my-main-module");
8042
+ //
8043
+ // // Declares which of the main module's exports are configured with durable storage, and
8044
+ // // thus should behave as Durable Object namsepace bindings.
8045
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8046
+ // }
8047
+ //
8048
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8049
+ interface GlobalProps {}
8050
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8051
+ // present.
8052
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8053
+ ? GlobalProps[K]
8054
+ : Default;
8055
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8056
+ // `mainModule` property.
8057
+ type MainModule = GlobalProp<"mainModule", {}>;
8058
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8059
+ type Exports = {
8060
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8061
+ // If the export is listed in `durableNamespaces`, then it is also a
8062
+ // DurableObjectNamespace.
8063
+ (K extends GlobalProp<"durableNamespaces", never>
8064
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8065
+ ? DoInstance extends Rpc.DurableObjectBranded
8066
+ ? DurableObjectNamespace<DoInstance>
8067
+ : DurableObjectNamespace<undefined>
8068
+ : DurableObjectNamespace<undefined>
8069
+ : {});
8070
+ };
8045
8071
  }
8046
8072
  declare module "cloudflare:node" {
8047
8073
  export interface DefaultHandler {
@@ -8059,7 +8085,7 @@ declare module "cloudflare:node" {
8059
8085
  handlers?: Omit<DefaultHandler, "fetch">,
8060
8086
  ): DefaultHandler;
8061
8087
  }
8062
- declare module "cloudflare:workers" {
8088
+ declare namespace CloudflareWorkersModule {
8063
8089
  export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8064
8090
  export const RpcStub: {
8065
8091
  new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
@@ -8068,11 +8094,11 @@ declare module "cloudflare:workers" {
8068
8094
  [Rpc.__RPC_TARGET_BRAND]: never;
8069
8095
  }
8070
8096
  // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8071
- export abstract class WorkerEntrypoint<Env = unknown>
8097
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8072
8098
  implements Rpc.WorkerEntrypointBranded
8073
8099
  {
8074
8100
  [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8075
- protected ctx: ExecutionContext;
8101
+ protected ctx: ExecutionContext<Props>;
8076
8102
  protected env: Env;
8077
8103
  constructor(ctx: ExecutionContext, env: Env);
8078
8104
  fetch?(request: Request): Response | Promise<Response>;
@@ -8082,11 +8108,11 @@ declare module "cloudflare:workers" {
8082
8108
  queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8083
8109
  test?(controller: TestController): void | Promise<void>;
8084
8110
  }
8085
- export abstract class DurableObject<Env = unknown>
8111
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8086
8112
  implements Rpc.DurableObjectBranded
8087
8113
  {
8088
8114
  [Rpc.__DURABLE_OBJECT_BRAND]: never;
8089
- protected ctx: DurableObjectState;
8115
+ protected ctx: DurableObjectState<Props>;
8090
8116
  protected env: Env;
8091
8117
  constructor(ctx: DurableObjectState, env: Env);
8092
8118
  fetch?(request: Request): Response | Promise<Response>;
@@ -8173,6 +8199,9 @@ declare module "cloudflare:workers" {
8173
8199
  export function waitUntil(promise: Promise<unknown>): void;
8174
8200
  export const env: Cloudflare.Env;
8175
8201
  }
8202
+ declare module "cloudflare:workers" {
8203
+ export = CloudflareWorkersModule;
8204
+ }
8176
8205
  interface SecretsStoreSecret {
8177
8206
  /**
8178
8207
  * Get a secret from the Secrets Store, returning a string of the secret value
package/index.ts CHANGED
@@ -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;
@@ -3035,6 +3038,30 @@ export interface MessagePort extends EventTarget {
3035
3038
  export interface MessagePortPostMessageOptions {
3036
3039
  transfer?: any[];
3037
3040
  }
3041
+ export type LoopbackForExport<
3042
+ T extends
3043
+ | (new (...args: any[]) => Rpc.EntrypointBranded)
3044
+ | ExportedHandler<any, any, any>
3045
+ | undefined = undefined,
3046
+ > = T extends new (...args: any[]) => Rpc.WorkerEntrypointBranded
3047
+ ? LoopbackServiceStub<InstanceType<T>>
3048
+ : T extends new (...args: any[]) => Rpc.DurableObjectBranded
3049
+ ? LoopbackDurableObjectClass<InstanceType<T>>
3050
+ : T extends ExportedHandler<any, any, any>
3051
+ ? LoopbackServiceStub<undefined>
3052
+ : undefined;
3053
+ export type LoopbackServiceStub<
3054
+ T extends Rpc.WorkerEntrypointBranded | undefined = undefined,
3055
+ > = Fetcher<T> &
3056
+ (T extends CloudflareWorkersModule.WorkerEntrypoint<any, infer Props>
3057
+ ? (opts: { props?: Props }) => Fetcher<T>
3058
+ : (opts: { props?: any }) => Fetcher<T>);
3059
+ export type LoopbackDurableObjectClass<
3060
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
3061
+ > = DurableObjectClass<T> &
3062
+ (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3063
+ ? (opts: { props?: Props }) => DurableObjectClass<T>
3064
+ : (opts: { props?: any }) => DurableObjectClass<T>);
3038
3065
  export interface SyncKvStorage {
3039
3066
  get<T = unknown>(key: string): T | undefined;
3040
3067
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3049,98 +3076,51 @@ export interface SyncKvListOptions {
3049
3076
  reverse?: boolean;
3050
3077
  limit?: number;
3051
3078
  }
3079
+ export interface WorkerStub {
3080
+ getEntrypoint<T extends Rpc.WorkerEntrypointBranded | undefined>(
3081
+ name?: string,
3082
+ options?: WorkerStubEntrypointOptions,
3083
+ ): Fetcher<T>;
3084
+ }
3085
+ export interface WorkerStubEntrypointOptions {
3086
+ props?: any;
3087
+ }
3088
+ export interface WorkerLoader {
3089
+ get(
3090
+ name: string,
3091
+ getCode: () => WorkerLoaderWorkerCode | Promise<WorkerLoaderWorkerCode>,
3092
+ ): WorkerStub;
3093
+ }
3094
+ export interface WorkerLoaderModule {
3095
+ js?: string;
3096
+ cjs?: string;
3097
+ text?: string;
3098
+ data?: ArrayBuffer;
3099
+ json?: any;
3100
+ py?: string;
3101
+ }
3102
+ export interface WorkerLoaderWorkerCode {
3103
+ compatibilityDate: string;
3104
+ compatibilityFlags?: string[];
3105
+ allowExperimental?: boolean;
3106
+ mainModule: string;
3107
+ modules: Record<string, WorkerLoaderModule | string>;
3108
+ env?: any;
3109
+ globalOutbound?: Fetcher | null;
3110
+ tails?: Fetcher[];
3111
+ streamingTails?: Fetcher[];
3112
+ }
3052
3113
  /**
3053
3114
  * The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
3054
3115
  * as well as timing of subrequests and other operations.
3055
3116
  *
3056
3117
  * [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/)
3057
3118
  */
3058
- export declare abstract class Performance extends EventTarget {
3119
+ export declare abstract class Performance {
3059
3120
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancetimeorigin) */
3060
3121
  get timeOrigin(): number;
3061
3122
  /* [Cloudflare Docs Reference](https://developers.cloudflare.com/workers/runtime-apis/performance/#performancenow) */
3062
3123
  now(): number;
3063
- get eventCounts(): EventCounts;
3064
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMarks) */
3065
- clearMarks(name?: string): void;
3066
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearMeasures) */
3067
- clearMeasures(name?: string): void;
3068
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/clearResourceTimings) */
3069
- clearResourceTimings(): void;
3070
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntries) */
3071
- getEntries(): PerformanceEntry[];
3072
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByName) */
3073
- getEntriesByName(name: string, type: string): PerformanceEntry[];
3074
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/getEntriesByType) */
3075
- getEntriesByType(type: string): PerformanceEntry[];
3076
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/mark) */
3077
- mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
3078
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/measure) */
3079
- measure(
3080
- measureName: string,
3081
- measureOptionsOrStartMark: PerformanceMeasureOptions | string,
3082
- maybeEndMark?: string,
3083
- ): PerformanceMeasure;
3084
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Performance/setResourceTimingBufferSize) */
3085
- setResourceTimingBufferSize(size: number): void;
3086
- }
3087
- /**
3088
- * 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.
3089
- *
3090
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark)
3091
- */
3092
- export interface PerformanceMark extends PerformanceEntry {
3093
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMark/detail) */
3094
- get detail(): any;
3095
- }
3096
- /**
3097
- * 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.
3098
- *
3099
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure)
3100
- */
3101
- export interface PerformanceMeasure extends PerformanceEntry {
3102
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceMeasure/detail) */
3103
- get detail(): any;
3104
- }
3105
- export interface PerformanceMarkOptions {
3106
- detail?: any;
3107
- startTime?: number;
3108
- }
3109
- export interface PerformanceMeasureOptions {
3110
- detail?: any;
3111
- start?: number;
3112
- duration?: number;
3113
- end?: number;
3114
- }
3115
- /**
3116
- * 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).
3117
- *
3118
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry)
3119
- */
3120
- export declare abstract class PerformanceEntry {
3121
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/name) */
3122
- get name(): string;
3123
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/entryType) */
3124
- get entryType(): string;
3125
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/startTime) */
3126
- get startTime(): number;
3127
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/duration) */
3128
- get duration(): number;
3129
- /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PerformanceEntry/toJSON) */
3130
- toJSON(): any;
3131
- }
3132
- export interface EventCounts {
3133
- get size(): number;
3134
- get(eventType: string): number | undefined;
3135
- has(eventType: string): boolean;
3136
- entries(): IterableIterator<string[]>;
3137
- keys(): IterableIterator<string>;
3138
- values(): IterableIterator<number>;
3139
- forEach(
3140
- param1: (param0: number, param1: string, param2: EventCounts) => void,
3141
- param2?: any,
3142
- ): void;
3143
- [Symbol.iterator](): IterableIterator<string[]>;
3144
3124
  }
3145
3125
  export type AiImageClassificationInput = {
3146
3126
  image: number[];
@@ -8023,7 +8003,167 @@ export declare namespace Rpc {
8023
8003
  };
8024
8004
  }
8025
8005
  export declare namespace Cloudflare {
8006
+ // Type of `env`.
8007
+ //
8008
+ // The specific project can extend `Env` by redeclaring it in project-specific files. Typescript
8009
+ // will merge all declarations.
8010
+ //
8011
+ // You can use `wrangler types` to generate the `Env` type automatically.
8026
8012
  interface Env {}
8013
+ // Project-specific parameters used to inform types.
8014
+ //
8015
+ // This interface is, again, intended to be declared in project-specific files, and then that
8016
+ // declaration will be merged with this one.
8017
+ //
8018
+ // A project should have a declaration like this:
8019
+ //
8020
+ // interface GlobalProps {
8021
+ // // Declares the main module's exports. Used to populate Cloudflare.Exports aka the type
8022
+ // // of `ctx.exports`.
8023
+ // mainModule: typeof import("my-main-module");
8024
+ //
8025
+ // // Declares which of the main module's exports are configured with durable storage, and
8026
+ // // thus should behave as Durable Object namsepace bindings.
8027
+ // durableNamespaces: "MyDurableObject" | "AnotherDurableObject";
8028
+ // }
8029
+ //
8030
+ // You can use `wrangler types` to generate `GlobalProps` automatically.
8031
+ interface GlobalProps {}
8032
+ // Evaluates to the type of a property in GlobalProps, defaulting to `Default` if it is not
8033
+ // present.
8034
+ type GlobalProp<K extends string, Default> = K extends keyof GlobalProps
8035
+ ? GlobalProps[K]
8036
+ : Default;
8037
+ // The type of the program's main module exports, if known. Requires `GlobalProps` to declare the
8038
+ // `mainModule` property.
8039
+ type MainModule = GlobalProp<"mainModule", {}>;
8040
+ // The type of ctx.exports, which contains loopback bindings for all top-level exports.
8041
+ type Exports = {
8042
+ [K in keyof MainModule]: LoopbackForExport<MainModule[K]> &
8043
+ // If the export is listed in `durableNamespaces`, then it is also a
8044
+ // DurableObjectNamespace.
8045
+ (K extends GlobalProp<"durableNamespaces", never>
8046
+ ? MainModule[K] extends new (...args: any[]) => infer DoInstance
8047
+ ? DoInstance extends Rpc.DurableObjectBranded
8048
+ ? DurableObjectNamespace<DoInstance>
8049
+ : DurableObjectNamespace<undefined>
8050
+ : DurableObjectNamespace<undefined>
8051
+ : {});
8052
+ };
8053
+ }
8054
+ export declare namespace CloudflareWorkersModule {
8055
+ export type RpcStub<T extends Rpc.Stubable> = Rpc.Stub<T>;
8056
+ export const RpcStub: {
8057
+ new <T extends Rpc.Stubable>(value: T): Rpc.Stub<T>;
8058
+ };
8059
+ export abstract class RpcTarget implements Rpc.RpcTargetBranded {
8060
+ [Rpc.__RPC_TARGET_BRAND]: never;
8061
+ }
8062
+ // `protected` fields don't appear in `keyof`s, so can't be accessed over RPC
8063
+ export abstract class WorkerEntrypoint<Env = Cloudflare.Env, Props = {}>
8064
+ implements Rpc.WorkerEntrypointBranded
8065
+ {
8066
+ [Rpc.__WORKER_ENTRYPOINT_BRAND]: never;
8067
+ protected ctx: ExecutionContext<Props>;
8068
+ protected env: Env;
8069
+ constructor(ctx: ExecutionContext, env: Env);
8070
+ fetch?(request: Request): Response | Promise<Response>;
8071
+ tail?(events: TraceItem[]): void | Promise<void>;
8072
+ trace?(traces: TraceItem[]): void | Promise<void>;
8073
+ scheduled?(controller: ScheduledController): void | Promise<void>;
8074
+ queue?(batch: MessageBatch<unknown>): void | Promise<void>;
8075
+ test?(controller: TestController): void | Promise<void>;
8076
+ }
8077
+ export abstract class DurableObject<Env = Cloudflare.Env, Props = {}>
8078
+ implements Rpc.DurableObjectBranded
8079
+ {
8080
+ [Rpc.__DURABLE_OBJECT_BRAND]: never;
8081
+ protected ctx: DurableObjectState<Props>;
8082
+ protected env: Env;
8083
+ constructor(ctx: DurableObjectState, env: Env);
8084
+ fetch?(request: Request): Response | Promise<Response>;
8085
+ alarm?(alarmInfo?: AlarmInvocationInfo): void | Promise<void>;
8086
+ webSocketMessage?(
8087
+ ws: WebSocket,
8088
+ message: string | ArrayBuffer,
8089
+ ): void | Promise<void>;
8090
+ webSocketClose?(
8091
+ ws: WebSocket,
8092
+ code: number,
8093
+ reason: string,
8094
+ wasClean: boolean,
8095
+ ): void | Promise<void>;
8096
+ webSocketError?(ws: WebSocket, error: unknown): void | Promise<void>;
8097
+ }
8098
+ export type WorkflowDurationLabel =
8099
+ | "second"
8100
+ | "minute"
8101
+ | "hour"
8102
+ | "day"
8103
+ | "week"
8104
+ | "month"
8105
+ | "year";
8106
+ export type WorkflowSleepDuration =
8107
+ | `${number} ${WorkflowDurationLabel}${"s" | ""}`
8108
+ | number;
8109
+ export type WorkflowDelayDuration = WorkflowSleepDuration;
8110
+ export type WorkflowTimeoutDuration = WorkflowSleepDuration;
8111
+ export type WorkflowRetentionDuration = WorkflowSleepDuration;
8112
+ export type WorkflowBackoff = "constant" | "linear" | "exponential";
8113
+ export type WorkflowStepConfig = {
8114
+ retries?: {
8115
+ limit: number;
8116
+ delay: WorkflowDelayDuration | number;
8117
+ backoff?: WorkflowBackoff;
8118
+ };
8119
+ timeout?: WorkflowTimeoutDuration | number;
8120
+ };
8121
+ export type WorkflowEvent<T> = {
8122
+ payload: Readonly<T>;
8123
+ timestamp: Date;
8124
+ instanceId: string;
8125
+ };
8126
+ export type WorkflowStepEvent<T> = {
8127
+ payload: Readonly<T>;
8128
+ timestamp: Date;
8129
+ type: string;
8130
+ };
8131
+ export abstract class WorkflowStep {
8132
+ do<T extends Rpc.Serializable<T>>(
8133
+ name: string,
8134
+ callback: () => Promise<T>,
8135
+ ): Promise<T>;
8136
+ do<T extends Rpc.Serializable<T>>(
8137
+ name: string,
8138
+ config: WorkflowStepConfig,
8139
+ callback: () => Promise<T>,
8140
+ ): Promise<T>;
8141
+ sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
8142
+ sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
8143
+ waitForEvent<T extends Rpc.Serializable<T>>(
8144
+ name: string,
8145
+ options: {
8146
+ type: string;
8147
+ timeout?: WorkflowTimeoutDuration | number;
8148
+ },
8149
+ ): Promise<WorkflowStepEvent<T>>;
8150
+ }
8151
+ export abstract class WorkflowEntrypoint<
8152
+ Env = unknown,
8153
+ T extends Rpc.Serializable<T> | unknown = unknown,
8154
+ > implements Rpc.WorkflowEntrypointBranded
8155
+ {
8156
+ [Rpc.__WORKFLOW_ENTRYPOINT_BRAND]: never;
8157
+ protected ctx: ExecutionContext;
8158
+ protected env: Env;
8159
+ constructor(ctx: ExecutionContext, env: Env);
8160
+ run(
8161
+ event: Readonly<WorkflowEvent<T>>,
8162
+ step: WorkflowStep,
8163
+ ): Promise<unknown>;
8164
+ }
8165
+ export function waitUntil(promise: Promise<unknown>): void;
8166
+ export const env: Cloudflare.Env;
8027
8167
  }
8028
8168
  export interface SecretsStoreSecret {
8029
8169
  /**