@cloudflare/workers-types 4.20260701.1 → 5.20260703.1

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/README.md CHANGED
@@ -34,69 +34,14 @@ The following is a minimal `tsconfig.json` for use alongside this package:
34
34
 
35
35
  ### Compatibility dates
36
36
 
37
- ![Entrypoints for compatibility dates](./npm/workers-types/entrypoints.svg)
38
-
39
- The Cloudflare Workers runtime manages backwards compatibility through the use of [Compatibility Dates](https://developers.cloudflare.com/workers/platform/compatibility-dates/). Using different compatibility dates affects the runtime types available to your Worker, and so it's important you specify the correct entrypoint to the `workers-types` package to match your compatibility date (which is usually set in your `wrangler.toml` configuration file). `workers-types` currently exposes the following entrypoints to choose from:
40
-
41
- - `@cloudflare/workers-types`
42
-
43
- The default entrypoint exposes the runtime types for a compatibility date before `2021-11-03`.
44
-
45
- - `@cloudflare/workers-types/2021-11-03`
46
-
47
- This entrypoint exposes the runtime types for a compatibility date between `2021-11-03` and `2022-01-31`.
48
-
49
- - `@cloudflare/workers-types/2022-01-31`
50
-
51
- This entrypoint exposes the runtime types for a compatibility date between `2022-01-31` and `2022-03-21`.
52
-
53
- - `@cloudflare/workers-types/2022-03-21`
54
-
55
- This entrypoint exposes the runtime types for a compatibility date between `2022-03-21` and `2022-08-04`.
56
-
57
- - `@cloudflare/workers-types/2022-08-04`
58
-
59
- This entrypoint exposes the runtime types for a compatibility date between `2022-08-04` and `2022-10-31`.
60
-
61
- - `@cloudflare/workers-types/2022-10-31`
62
-
63
- This entrypoint exposes the runtime types for a compatibility date between `2022-10-31` and `2022-11-30`.
64
-
65
- - `@cloudflare/workers-types/2022-11-30`
66
-
67
- This entrypoint exposes the runtime types for a compatibility date between `2022-11-30` and `2023-03-01`.
68
-
69
- - `@cloudflare/workers-types/2023-03-01`
70
-
71
- This entrypoint exposes the runtime types for a compatibility date between `2023-03-01` and `2023-07-01`.
72
-
73
- - `@cloudflare/workers-types/2023-07-01`
74
-
75
- This entrypoint exposes the runtime types for a compatibility date after `2023-07-01`.
76
-
77
- - `@cloudflare/workers-types/experimental`
78
-
79
- This entrypoint exposes the runtime types for the latest compatibility date. The types exposed by this entrypoint will change over time to always reflect the latest version of the Workers runtime.
80
-
81
- To use one of these entrypoints, you need to specify them in your `tsconfig.json`. For example, this is a sample `tsconfig.json` for using the `2022-08-04` entrypoint.
82
-
83
- ```json
84
- {
85
- "compilerOptions": {
86
- "target": "esnext",
87
- "module": "esnext",
88
- "lib": ["esnext"],
89
- "types": ["@cloudflare/workers-types/2022-08-04"]
90
- }
91
- }
92
- ```
37
+ The Cloudflare Workers runtime manages backwards compatibility through the use of [Compatibility Dates](https://developers.cloudflare.com/workers/platform/compatibility-dates/). The `@cloudflare/workers-types` package provides a typing environment that corresponds to the latest version of the Cloudflare Workers runtime. The `@cloudflare/workers-types/experimental` entrypoint is also available for APIs guarded by experimental compatibility flags. Instead of using `@cloudflare/workers-types` directly, we recommend following the [Typescript language documentation](https://developers.cloudflare.com/workers/languages/typescript/) for Cloudflare Workers to generate a runtime typing environment that corresponds exactly to your compatibility date and flags.
93
38
 
94
39
  ### Importable Types
95
40
 
96
41
  It's not always possible (or desirable) to modify the `tsconfig.json` settings for a project to include all the Cloudflare Workers types. For use cases like that, this package provides importable versions of its types, which are usable with no additional `tsconfig.json` setup. For example:
97
42
 
98
43
  ```ts
99
- import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types/experimental"
44
+ import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types"
100
45
 
101
46
  export default {
102
47
  fetch(request: WorkerRequest, env: unknown, ctx: ExecutionContext) {
@@ -132,4 +77,3 @@ export {}
132
77
  ```
133
78
 
134
79
  Wrangler can also generate this for you automatically from your `wrangler.toml` configuration file, using the `wrangler types` command.
135
-
@@ -668,7 +668,7 @@ declare abstract class DurableObjectNamespace<
668
668
  jurisdiction: DurableObjectJurisdiction,
669
669
  ): DurableObjectNamespace<T>;
670
670
  }
671
- type DurableObjectJurisdiction = "eu" | "fedramp" | "fedramp-high";
671
+ type DurableObjectJurisdiction = "eu" | "fedramp" | "fedramp-high" | "us";
672
672
  interface DurableObjectNamespaceNewUniqueIdOptions {
673
673
  jurisdiction?: DurableObjectJurisdiction;
674
674
  }
@@ -14307,6 +14307,13 @@ interface ForwardableEmailMessage extends EmailMessage {
14307
14307
  * @returns A promise that resolves when the email message is replied.
14308
14308
  */
14309
14309
  reply(message: EmailMessage): Promise<EmailSendResult>;
14310
+ /**
14311
+ * Reply to the sender of this email message with a message built from the given
14312
+ * fields. Threading headers (In-Reply-To/References) are set automatically.
14313
+ * @param builder The reply message contents.
14314
+ * @returns A promise that resolves when the email message is replied.
14315
+ */
14316
+ reply(builder: EmailReplyMessageBuilder): Promise<EmailSendResult>;
14310
14317
  }
14311
14318
  /** A file attachment for an email message */
14312
14319
  type EmailAttachment =
@@ -14329,23 +14336,50 @@ interface EmailAddress {
14329
14336
  name: string;
14330
14337
  email: string;
14331
14338
  }
14339
+ /**
14340
+ * Recipient fields for `SendEmail.send()`. At least one of `to`, `cc`, or
14341
+ * `bcc` must be provided.
14342
+ */
14343
+ type EmailDestinations = {
14344
+ to?: string | EmailAddress | (string | EmailAddress)[];
14345
+ cc?: string | EmailAddress | (string | EmailAddress)[];
14346
+ bcc?: string | EmailAddress | (string | EmailAddress)[];
14347
+ } & (
14348
+ | {
14349
+ to: string | EmailAddress | (string | EmailAddress)[];
14350
+ }
14351
+ | {
14352
+ cc: string | EmailAddress | (string | EmailAddress)[];
14353
+ }
14354
+ | {
14355
+ bcc: string | EmailAddress | (string | EmailAddress)[];
14356
+ }
14357
+ );
14358
+ /**
14359
+ * Fields shared by all composed emails (no recipients). Used directly by
14360
+ * `ForwardableEmailMessage.reply()`, which always replies to the original
14361
+ * sender, and extended by `EmailMessageBuilder` for `SendEmail.send()`.
14362
+ */
14363
+ interface EmailReplyMessageBuilder {
14364
+ from: string | EmailAddress;
14365
+ subject: string;
14366
+ replyTo?: string | EmailAddress;
14367
+ headers?: Record<string, string>;
14368
+ text?: string;
14369
+ html?: string;
14370
+ attachments?: EmailAttachment[];
14371
+ }
14372
+ /**
14373
+ * Fields for composing an email without constructing raw MIME, for
14374
+ * `SendEmail.send()`. Requires at least one of `to`, `cc`, or `bcc`.
14375
+ */
14376
+ type EmailMessageBuilder = EmailReplyMessageBuilder & EmailDestinations;
14332
14377
  /**
14333
14378
  * A binding that allows a Worker to send email messages.
14334
14379
  */
14335
14380
  interface SendEmail {
14336
14381
  send(message: EmailMessage): Promise<EmailSendResult>;
14337
- send(builder: {
14338
- from: string | EmailAddress;
14339
- to: string | EmailAddress | (string | EmailAddress)[];
14340
- subject: string;
14341
- replyTo?: string | EmailAddress;
14342
- cc?: string | EmailAddress | (string | EmailAddress)[];
14343
- bcc?: string | EmailAddress | (string | EmailAddress)[];
14344
- headers?: Record<string, string>;
14345
- text?: string;
14346
- html?: string;
14347
- attachments?: EmailAttachment[];
14348
- }): Promise<EmailSendResult>;
14382
+ send(builder: EmailMessageBuilder): Promise<EmailSendResult>;
14349
14383
  }
14350
14384
  declare abstract class EmailEvent extends ExtendableEvent {
14351
14385
  readonly message: ForwardableEmailMessage;
@@ -15356,6 +15390,13 @@ declare namespace CloudflareWorkersModule {
15356
15390
  | `${number} ${WorkflowDurationLabel}${"s" | ""}`
15357
15391
  | number;
15358
15392
  export type WorkflowDelayDuration = WorkflowSleepDuration;
15393
+ export type WorkflowDynamicDelayContext = {
15394
+ ctx: WorkflowStepContext<WorkflowDelayFunction>;
15395
+ error: Error;
15396
+ };
15397
+ export type WorkflowDelayFunction = (
15398
+ input: WorkflowDynamicDelayContext,
15399
+ ) => WorkflowDelayDuration | Promise<WorkflowDelayDuration>;
15359
15400
  export type WorkflowTimeoutDuration = WorkflowSleepDuration;
15360
15401
  export type WorkflowRetentionDuration = WorkflowSleepDuration;
15361
15402
  export type WorkflowBackoff = "constant" | "linear" | "exponential";
@@ -15363,7 +15404,7 @@ declare namespace CloudflareWorkersModule {
15363
15404
  export type WorkflowStepConfig = {
15364
15405
  retries?: {
15365
15406
  limit: number;
15366
- delay: WorkflowDelayDuration | number;
15407
+ delay: WorkflowDelayDuration | number | WorkflowDelayFunction;
15367
15408
  backoff?: WorkflowBackoff;
15368
15409
  };
15369
15410
  timeout?: WorkflowTimeoutDuration | number;
@@ -15392,13 +15433,24 @@ declare namespace CloudflareWorkersModule {
15392
15433
  type: string;
15393
15434
  sensitive?: WorkflowStepSensitivity;
15394
15435
  };
15395
- export type WorkflowStepContext = {
15436
+ export type WorkflowStepContext<Delay = WorkflowDelayDuration | number> = {
15396
15437
  step: {
15397
15438
  name: string;
15398
15439
  count: number;
15399
15440
  };
15400
15441
  attempt: number;
15401
- config: WorkflowStepConfig;
15442
+ config: {
15443
+ retries?: {
15444
+ limit: number;
15445
+ backoff?: WorkflowBackoff;
15446
+ } & (Delay extends WorkflowDelayFunction
15447
+ ? {}
15448
+ : {
15449
+ delay: WorkflowDelayDuration | number;
15450
+ });
15451
+ timeout?: WorkflowTimeoutDuration | number;
15452
+ sensitive?: WorkflowStepSensitivity;
15453
+ };
15402
15454
  };
15403
15455
  export type WorkflowRollbackContext<T = unknown> = {
15404
15456
  ctx: WorkflowStepContext;
@@ -15420,10 +15472,18 @@ declare namespace CloudflareWorkersModule {
15420
15472
  callback: (ctx: WorkflowStepContext) => Promise<T>,
15421
15473
  rollbackOptions?: WorkflowStepRollbackOptions<T>,
15422
15474
  ): Promise<T>;
15423
- do<T extends Rpc.Serializable<T>>(
15475
+ do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(
15424
15476
  name: string,
15425
- config: WorkflowStepConfig,
15426
- callback: (ctx: WorkflowStepContext) => Promise<T>,
15477
+ config: C,
15478
+ callback: (
15479
+ ctx: WorkflowStepContext<
15480
+ C["retries"] extends {
15481
+ delay: infer D;
15482
+ }
15483
+ ? D
15484
+ : WorkflowDelayDuration | number
15485
+ >,
15486
+ ) => Promise<T>,
15427
15487
  rollbackOptions?: WorkflowStepRollbackOptions<T>,
15428
15488
  ): Promise<T>;
15429
15489
  sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
@@ -16401,6 +16461,7 @@ declare namespace TailStream {
16401
16461
  readonly dispatchNamespace?: string;
16402
16462
  readonly entrypoint?: string;
16403
16463
  readonly executionModel: string;
16464
+ readonly durableObjectId?: string;
16404
16465
  readonly scriptName?: string;
16405
16466
  readonly scriptTags?: string[];
16406
16467
  readonly scriptVersion?: ScriptVersion;
@@ -17037,6 +17098,13 @@ interface WorkflowError {
17037
17098
  code?: number;
17038
17099
  message: string;
17039
17100
  }
17101
+ interface WorkflowInstanceTerminateOptions {
17102
+ /**
17103
+ * If true, run registered rollback handlers before terminating the instance.
17104
+ * Only steps that registered rollback handlers are rolled back.
17105
+ */
17106
+ rollback?: boolean;
17107
+ }
17040
17108
  interface WorkflowInstanceRestartOptions {
17041
17109
  /**
17042
17110
  * Restart from a specific step. If omitted, the instance restarts from the beginning.
@@ -17070,8 +17138,9 @@ declare abstract class WorkflowInstance {
17070
17138
  public resume(): Promise<void>;
17071
17139
  /**
17072
17140
  * Terminate the instance. If it is errored, terminated or complete, an error will be thrown.
17141
+ * @param options Options for termination, including whether registered rollback handlers should run.
17073
17142
  */
17074
- public terminate(): Promise<void>;
17143
+ public terminate(options?: WorkflowInstanceTerminateOptions): Promise<void>;
17075
17144
  /**
17076
17145
  * Restart the instance. Optionally restart from a specific step, preserving
17077
17146
  * cached results for all steps before it.
@@ -670,7 +670,11 @@ export declare abstract class DurableObjectNamespace<
670
670
  jurisdiction: DurableObjectJurisdiction,
671
671
  ): DurableObjectNamespace<T>;
672
672
  }
673
- export type DurableObjectJurisdiction = "eu" | "fedramp" | "fedramp-high";
673
+ export type DurableObjectJurisdiction =
674
+ | "eu"
675
+ | "fedramp"
676
+ | "fedramp-high"
677
+ | "us";
674
678
  export interface DurableObjectNamespaceNewUniqueIdOptions {
675
679
  jurisdiction?: DurableObjectJurisdiction;
676
680
  }
@@ -14334,6 +14338,13 @@ export interface ForwardableEmailMessage extends EmailMessage {
14334
14338
  * @returns A promise that resolves when the email message is replied.
14335
14339
  */
14336
14340
  reply(message: EmailMessage): Promise<EmailSendResult>;
14341
+ /**
14342
+ * Reply to the sender of this email message with a message built from the given
14343
+ * fields. Threading headers (In-Reply-To/References) are set automatically.
14344
+ * @param builder The reply message contents.
14345
+ * @returns A promise that resolves when the email message is replied.
14346
+ */
14347
+ reply(builder: EmailReplyMessageBuilder): Promise<EmailSendResult>;
14337
14348
  }
14338
14349
  /** A file attachment for an email message */
14339
14350
  export type EmailAttachment =
@@ -14356,23 +14367,50 @@ export interface EmailAddress {
14356
14367
  name: string;
14357
14368
  email: string;
14358
14369
  }
14370
+ /**
14371
+ * Recipient fields for `SendEmail.send()`. At least one of `to`, `cc`, or
14372
+ * `bcc` must be provided.
14373
+ */
14374
+ export type EmailDestinations = {
14375
+ to?: string | EmailAddress | (string | EmailAddress)[];
14376
+ cc?: string | EmailAddress | (string | EmailAddress)[];
14377
+ bcc?: string | EmailAddress | (string | EmailAddress)[];
14378
+ } & (
14379
+ | {
14380
+ to: string | EmailAddress | (string | EmailAddress)[];
14381
+ }
14382
+ | {
14383
+ cc: string | EmailAddress | (string | EmailAddress)[];
14384
+ }
14385
+ | {
14386
+ bcc: string | EmailAddress | (string | EmailAddress)[];
14387
+ }
14388
+ );
14389
+ /**
14390
+ * Fields shared by all composed emails (no recipients). Used directly by
14391
+ * `ForwardableEmailMessage.reply()`, which always replies to the original
14392
+ * sender, and extended by `EmailMessageBuilder` for `SendEmail.send()`.
14393
+ */
14394
+ export interface EmailReplyMessageBuilder {
14395
+ from: string | EmailAddress;
14396
+ subject: string;
14397
+ replyTo?: string | EmailAddress;
14398
+ headers?: Record<string, string>;
14399
+ text?: string;
14400
+ html?: string;
14401
+ attachments?: EmailAttachment[];
14402
+ }
14403
+ /**
14404
+ * Fields for composing an email without constructing raw MIME, for
14405
+ * `SendEmail.send()`. Requires at least one of `to`, `cc`, or `bcc`.
14406
+ */
14407
+ export type EmailMessageBuilder = EmailReplyMessageBuilder & EmailDestinations;
14359
14408
  /**
14360
14409
  * A binding that allows a Worker to send email messages.
14361
14410
  */
14362
14411
  export interface SendEmail {
14363
14412
  send(message: EmailMessage): Promise<EmailSendResult>;
14364
- send(builder: {
14365
- from: string | EmailAddress;
14366
- to: string | EmailAddress | (string | EmailAddress)[];
14367
- subject: string;
14368
- replyTo?: string | EmailAddress;
14369
- cc?: string | EmailAddress | (string | EmailAddress)[];
14370
- bcc?: string | EmailAddress | (string | EmailAddress)[];
14371
- headers?: Record<string, string>;
14372
- text?: string;
14373
- html?: string;
14374
- attachments?: EmailAttachment[];
14375
- }): Promise<EmailSendResult>;
14413
+ send(builder: EmailMessageBuilder): Promise<EmailSendResult>;
14376
14414
  }
14377
14415
  export declare abstract class EmailEvent extends ExtendableEvent {
14378
14416
  readonly message: ForwardableEmailMessage;
@@ -15330,6 +15368,13 @@ export declare namespace CloudflareWorkersModule {
15330
15368
  | `${number} ${WorkflowDurationLabel}${"s" | ""}`
15331
15369
  | number;
15332
15370
  export type WorkflowDelayDuration = WorkflowSleepDuration;
15371
+ export type WorkflowDynamicDelayContext = {
15372
+ ctx: WorkflowStepContext<WorkflowDelayFunction>;
15373
+ error: Error;
15374
+ };
15375
+ export type WorkflowDelayFunction = (
15376
+ input: WorkflowDynamicDelayContext,
15377
+ ) => WorkflowDelayDuration | Promise<WorkflowDelayDuration>;
15333
15378
  export type WorkflowTimeoutDuration = WorkflowSleepDuration;
15334
15379
  export type WorkflowRetentionDuration = WorkflowSleepDuration;
15335
15380
  export type WorkflowBackoff = "constant" | "linear" | "exponential";
@@ -15337,7 +15382,7 @@ export declare namespace CloudflareWorkersModule {
15337
15382
  export type WorkflowStepConfig = {
15338
15383
  retries?: {
15339
15384
  limit: number;
15340
- delay: WorkflowDelayDuration | number;
15385
+ delay: WorkflowDelayDuration | number | WorkflowDelayFunction;
15341
15386
  backoff?: WorkflowBackoff;
15342
15387
  };
15343
15388
  timeout?: WorkflowTimeoutDuration | number;
@@ -15366,13 +15411,24 @@ export declare namespace CloudflareWorkersModule {
15366
15411
  type: string;
15367
15412
  sensitive?: WorkflowStepSensitivity;
15368
15413
  };
15369
- export type WorkflowStepContext = {
15414
+ export type WorkflowStepContext<Delay = WorkflowDelayDuration | number> = {
15370
15415
  step: {
15371
15416
  name: string;
15372
15417
  count: number;
15373
15418
  };
15374
15419
  attempt: number;
15375
- config: WorkflowStepConfig;
15420
+ config: {
15421
+ retries?: {
15422
+ limit: number;
15423
+ backoff?: WorkflowBackoff;
15424
+ } & (Delay extends WorkflowDelayFunction
15425
+ ? {}
15426
+ : {
15427
+ delay: WorkflowDelayDuration | number;
15428
+ });
15429
+ timeout?: WorkflowTimeoutDuration | number;
15430
+ sensitive?: WorkflowStepSensitivity;
15431
+ };
15376
15432
  };
15377
15433
  export type WorkflowRollbackContext<T = unknown> = {
15378
15434
  ctx: WorkflowStepContext;
@@ -15394,10 +15450,18 @@ export declare namespace CloudflareWorkersModule {
15394
15450
  callback: (ctx: WorkflowStepContext) => Promise<T>,
15395
15451
  rollbackOptions?: WorkflowStepRollbackOptions<T>,
15396
15452
  ): Promise<T>;
15397
- do<T extends Rpc.Serializable<T>>(
15453
+ do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(
15398
15454
  name: string,
15399
- config: WorkflowStepConfig,
15400
- callback: (ctx: WorkflowStepContext) => Promise<T>,
15455
+ config: C,
15456
+ callback: (
15457
+ ctx: WorkflowStepContext<
15458
+ C["retries"] extends {
15459
+ delay: infer D;
15460
+ }
15461
+ ? D
15462
+ : WorkflowDelayDuration | number
15463
+ >,
15464
+ ) => Promise<T>,
15401
15465
  rollbackOptions?: WorkflowStepRollbackOptions<T>,
15402
15466
  ): Promise<T>;
15403
15467
  sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
@@ -16365,6 +16429,7 @@ export declare namespace TailStream {
16365
16429
  readonly dispatchNamespace?: string;
16366
16430
  readonly entrypoint?: string;
16367
16431
  readonly executionModel: string;
16432
+ readonly durableObjectId?: string;
16368
16433
  readonly scriptName?: string;
16369
16434
  readonly scriptTags?: string[];
16370
16435
  readonly scriptVersion?: ScriptVersion;
@@ -16992,6 +17057,13 @@ export interface WorkflowError {
16992
17057
  code?: number;
16993
17058
  message: string;
16994
17059
  }
17060
+ export interface WorkflowInstanceTerminateOptions {
17061
+ /**
17062
+ * If true, run registered rollback handlers before terminating the instance.
17063
+ * Only steps that registered rollback handlers are rolled back.
17064
+ */
17065
+ rollback?: boolean;
17066
+ }
16995
17067
  export interface WorkflowInstanceRestartOptions {
16996
17068
  /**
16997
17069
  * Restart from a specific step. If omitted, the instance restarts from the beginning.
@@ -17025,8 +17097,9 @@ export declare abstract class WorkflowInstance {
17025
17097
  public resume(): Promise<void>;
17026
17098
  /**
17027
17099
  * Terminate the instance. If it is errored, terminated or complete, an error will be thrown.
17100
+ * @param options Options for termination, including whether registered rollback handlers should run.
17028
17101
  */
17029
- public terminate(): Promise<void>;
17102
+ public terminate(options?: WorkflowInstanceTerminateOptions): Promise<void>;
17030
17103
  /**
17031
17104
  * Restart the instance. Optionally restart from a specific step, preserving
17032
17105
  * cached results for all steps before it.