@cloudflare/workers-types 4.20240903.0 → 4.20240919.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.
@@ -544,6 +544,7 @@ export interface DurableObjectState {
544
544
  setHibernatableWebSocketEventTimeout(timeoutMs?: number): void;
545
545
  getHibernatableWebSocketEventTimeout(): number | null;
546
546
  getTags(ws: WebSocket): string[];
547
+ abort(reason?: string): void;
547
548
  }
548
549
  export interface DurableObjectTransaction {
549
550
  get<T = unknown>(
@@ -610,7 +611,11 @@ export interface DurableObjectStorage {
610
611
  ): Promise<void>;
611
612
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
612
613
  sync(): Promise<void>;
614
+ sql: SqlStorage;
613
615
  transactionSync<T>(closure: () => T): T;
616
+ getCurrentBookmark(): Promise<string>;
617
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
618
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
614
619
  }
615
620
  export interface DurableObjectListOptions {
616
621
  start?: string;
@@ -1524,7 +1529,11 @@ export declare abstract class Body {
1524
1529
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1525
1530
  */
1526
1531
  export declare class Response extends Body {
1527
- constructor(body?: BodyInit | null, init?: ResponseInit);
1532
+ constructor(
1533
+ body?: BodyInit | null,
1534
+ init?: ResponseInit,
1535
+ webSocket?: WebSocket,
1536
+ );
1528
1537
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
1529
1538
  static redirect(url: string, status?: number): Response;
1530
1539
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
@@ -1551,7 +1560,7 @@ export interface ResponseInit {
1551
1560
  statusText?: string;
1552
1561
  headers?: HeadersInit;
1553
1562
  cf?: any;
1554
- webSocket?: WebSocket | null;
1563
+ webSocket?: WebSocket;
1555
1564
  encodeBody?: "automatic" | "manual";
1556
1565
  }
1557
1566
  export type RequestInfo<
@@ -2259,15 +2268,15 @@ export declare class TransformStream<I = any, O = any> {
2259
2268
  }
2260
2269
  export declare class FixedLengthStream extends IdentityTransformStream {
2261
2270
  constructor(
2262
- param1: number | bigint,
2263
- param2?: IdentityTransformStreamQueuingStrategy,
2271
+ expectedLength: number | bigint,
2272
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2264
2273
  );
2265
2274
  }
2266
2275
  export declare class IdentityTransformStream extends TransformStream<
2267
2276
  ArrayBuffer | ArrayBufferView,
2268
2277
  Uint8Array
2269
2278
  > {
2270
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2279
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2271
2280
  }
2272
2281
  export interface IdentityTransformStreamQueuingStrategy {
2273
2282
  highWaterMark?: number | bigint;
@@ -2748,6 +2757,26 @@ export declare const WebSocketPair: {
2748
2757
  1: WebSocket;
2749
2758
  };
2750
2759
  };
2760
+ export interface SqlStorage {
2761
+ exec<T extends Record<string, SqlStorageValue>>(
2762
+ query: string,
2763
+ ...bindings: any[]
2764
+ ): SqlStorageCursor<T>;
2765
+ get databaseSize(): number;
2766
+ Cursor: typeof SqlStorageCursor;
2767
+ Statement: typeof SqlStorageStatement;
2768
+ }
2769
+ export declare abstract class SqlStorageStatement {}
2770
+ export type SqlStorageValue = ArrayBuffer | string | number | null;
2771
+ export declare abstract class SqlStorageCursor<
2772
+ T extends Record<string, SqlStorageValue>,
2773
+ > {
2774
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2775
+ get columnNames(): string[];
2776
+ get rowsRead(): number;
2777
+ get rowsWritten(): number;
2778
+ [Symbol.iterator](): IterableIterator<T>;
2779
+ }
2751
2780
  export interface Socket {
2752
2781
  get readable(): ReadableStream;
2753
2782
  get writable(): WritableStream;
@@ -3278,7 +3307,7 @@ export interface GPUOrigin3DDict {
3278
3307
  z?: number;
3279
3308
  }
3280
3309
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3281
- export declare class EventSource {
3310
+ export declare class EventSource extends EventTarget {
3282
3311
  constructor(url: string, init?: EventSourceEventSourceInit);
3283
3312
  /**
3284
3313
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -4940,6 +4969,18 @@ export declare abstract class PipelineTransform {
4940
4969
  */
4941
4970
  public transformJson(data: object[]): Promise<object[]>;
4942
4971
  }
4972
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
4973
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
4974
+ // https://opensource.org/licenses/Apache-2.0
4975
+ export interface Pipeline {
4976
+ /**
4977
+ * send takes an array of javascript objects which are
4978
+ * then received by the pipeline for processing
4979
+ *
4980
+ * @param data The data to be sent
4981
+ */
4982
+ send(data: object[]): Promise<void>;
4983
+ }
4943
4984
  // PubSubMessage represents an incoming PubSub message.
4944
4985
  // The message includes metadata about the broker, the client, and the payload
4945
4986
  // itself.
@@ -5436,3 +5477,57 @@ export interface DispatchNamespace {
5436
5477
  options?: DynamicDispatchOptions,
5437
5478
  ): Fetcher;
5438
5479
  }
5480
+ export declare abstract class Workflow {
5481
+ /**
5482
+ * Get a handle to an existing instance of the Workflow.
5483
+ * @param id Id for the instance of this Workflow
5484
+ * @returns A promise that resolves with a handle for the Instance
5485
+ */
5486
+ public get(id: string): Promise<Instance>;
5487
+ /**
5488
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5489
+ * @param id Id to create the instance of this Workflow with
5490
+ * @param params The payload to send over to this instance
5491
+ * @returns A promise that resolves with a handle for the Instance
5492
+ */
5493
+ public create(id: string, params: object): Promise<Instance>;
5494
+ }
5495
+ export type InstanceStatus = {
5496
+ status:
5497
+ | "queued"
5498
+ | "running"
5499
+ | "paused"
5500
+ | "errored"
5501
+ | "terminated"
5502
+ | "complete"
5503
+ | "unknown";
5504
+ error?: string;
5505
+ output?: object;
5506
+ };
5507
+ export interface WorkflowError {
5508
+ code?: number;
5509
+ message: string;
5510
+ }
5511
+ export declare abstract class Instance {
5512
+ public id: string;
5513
+ /**
5514
+ * Pause the instance.
5515
+ */
5516
+ public pause(): Promise<void>;
5517
+ /**
5518
+ * Resume the instance. If it is already running, an error will be thrown.
5519
+ */
5520
+ public resume(): Promise<void>;
5521
+ /**
5522
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5523
+ */
5524
+ public abort(): Promise<void>;
5525
+ /**
5526
+ * Restart the instance.
5527
+ */
5528
+ public restart(): Promise<void>;
5529
+ /**
5530
+ * Returns the current status of the instance.
5531
+ */
5532
+ public status(): Promise<InstanceStatus>;
5533
+ }
@@ -556,6 +556,7 @@ interface DurableObjectState {
556
556
  setHibernatableWebSocketEventTimeout(timeoutMs?: number): void;
557
557
  getHibernatableWebSocketEventTimeout(): number | null;
558
558
  getTags(ws: WebSocket): string[];
559
+ abort(reason?: string): void;
559
560
  }
560
561
  interface DurableObjectTransaction {
561
562
  get<T = unknown>(
@@ -622,7 +623,11 @@ interface DurableObjectStorage {
622
623
  ): Promise<void>;
623
624
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
624
625
  sync(): Promise<void>;
626
+ sql: SqlStorage;
625
627
  transactionSync<T>(closure: () => T): T;
628
+ getCurrentBookmark(): Promise<string>;
629
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
630
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
626
631
  }
627
632
  interface DurableObjectListOptions {
628
633
  start?: string;
@@ -1536,7 +1541,11 @@ declare abstract class Body {
1536
1541
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1537
1542
  */
1538
1543
  declare class Response extends Body {
1539
- constructor(body?: BodyInit | null, init?: ResponseInit);
1544
+ constructor(
1545
+ body?: BodyInit | null,
1546
+ init?: ResponseInit,
1547
+ webSocket?: WebSocket,
1548
+ );
1540
1549
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
1541
1550
  static redirect(url: string, status?: number): Response;
1542
1551
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
@@ -1563,7 +1572,7 @@ interface ResponseInit {
1563
1572
  statusText?: string;
1564
1573
  headers?: HeadersInit;
1565
1574
  cf?: any;
1566
- webSocket?: WebSocket | null;
1575
+ webSocket?: WebSocket;
1567
1576
  encodeBody?: "automatic" | "manual";
1568
1577
  }
1569
1578
  type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> =
@@ -2270,15 +2279,15 @@ declare class TransformStream<I = any, O = any> {
2270
2279
  }
2271
2280
  declare class FixedLengthStream extends IdentityTransformStream {
2272
2281
  constructor(
2273
- param1: number | bigint,
2274
- param2?: IdentityTransformStreamQueuingStrategy,
2282
+ expectedLength: number | bigint,
2283
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2275
2284
  );
2276
2285
  }
2277
2286
  declare class IdentityTransformStream extends TransformStream<
2278
2287
  ArrayBuffer | ArrayBufferView,
2279
2288
  Uint8Array
2280
2289
  > {
2281
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2290
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2282
2291
  }
2283
2292
  interface IdentityTransformStreamQueuingStrategy {
2284
2293
  highWaterMark?: number | bigint;
@@ -2756,6 +2765,26 @@ declare const WebSocketPair: {
2756
2765
  1: WebSocket;
2757
2766
  };
2758
2767
  };
2768
+ interface SqlStorage {
2769
+ exec<T extends Record<string, SqlStorageValue>>(
2770
+ query: string,
2771
+ ...bindings: any[]
2772
+ ): SqlStorageCursor<T>;
2773
+ get databaseSize(): number;
2774
+ Cursor: typeof SqlStorageCursor;
2775
+ Statement: typeof SqlStorageStatement;
2776
+ }
2777
+ declare abstract class SqlStorageStatement {}
2778
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2779
+ declare abstract class SqlStorageCursor<
2780
+ T extends Record<string, SqlStorageValue>,
2781
+ > {
2782
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2783
+ get columnNames(): string[];
2784
+ get rowsRead(): number;
2785
+ get rowsWritten(): number;
2786
+ [Symbol.iterator](): IterableIterator<T>;
2787
+ }
2759
2788
  interface Socket {
2760
2789
  get readable(): ReadableStream;
2761
2790
  get writable(): WritableStream;
@@ -3293,7 +3322,7 @@ interface GPUOrigin3DDict {
3293
3322
  z?: number;
3294
3323
  }
3295
3324
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3296
- declare class EventSource {
3325
+ declare class EventSource extends EventTarget {
3297
3326
  constructor(url: string, init?: EventSourceEventSourceInit);
3298
3327
  /**
3299
3328
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -4952,6 +4981,18 @@ declare abstract class PipelineTransform {
4952
4981
  */
4953
4982
  public transformJson(data: object[]): Promise<object[]>;
4954
4983
  }
4984
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
4985
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
4986
+ // https://opensource.org/licenses/Apache-2.0
4987
+ interface Pipeline {
4988
+ /**
4989
+ * send takes an array of javascript objects which are
4990
+ * then received by the pipeline for processing
4991
+ *
4992
+ * @param data The data to be sent
4993
+ */
4994
+ send(data: object[]): Promise<void>;
4995
+ }
4955
4996
  // PubSubMessage represents an incoming PubSub message.
4956
4997
  // The message includes metadata about the broker, the client, and the payload
4957
4998
  // itself.
@@ -5545,3 +5586,70 @@ interface DispatchNamespace {
5545
5586
  options?: DynamicDispatchOptions,
5546
5587
  ): Fetcher;
5547
5588
  }
5589
+ /**
5590
+ * NonRetryableError allows for a user to throw a fatal error
5591
+ * that makes a Workflow instance fail immediately without triggering a retry
5592
+ */
5593
+ declare module "cloudflare:workflows" {
5594
+ export abstract class NonRetryableError extends Error {
5595
+ /**
5596
+ * `__brand` is used to differentiate between `NonRetryableError` and `Error`
5597
+ * and is omitted from the constructor because users should not set it
5598
+ */
5599
+ public constructor(message: string, name?: string);
5600
+ }
5601
+ }
5602
+ declare abstract class Workflow {
5603
+ /**
5604
+ * Get a handle to an existing instance of the Workflow.
5605
+ * @param id Id for the instance of this Workflow
5606
+ * @returns A promise that resolves with a handle for the Instance
5607
+ */
5608
+ public get(id: string): Promise<Instance>;
5609
+ /**
5610
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5611
+ * @param id Id to create the instance of this Workflow with
5612
+ * @param params The payload to send over to this instance
5613
+ * @returns A promise that resolves with a handle for the Instance
5614
+ */
5615
+ public create(id: string, params: object): Promise<Instance>;
5616
+ }
5617
+ type InstanceStatus = {
5618
+ status:
5619
+ | "queued"
5620
+ | "running"
5621
+ | "paused"
5622
+ | "errored"
5623
+ | "terminated"
5624
+ | "complete"
5625
+ | "unknown";
5626
+ error?: string;
5627
+ output?: object;
5628
+ };
5629
+ interface WorkflowError {
5630
+ code?: number;
5631
+ message: string;
5632
+ }
5633
+ declare abstract class Instance {
5634
+ public id: string;
5635
+ /**
5636
+ * Pause the instance.
5637
+ */
5638
+ public pause(): Promise<void>;
5639
+ /**
5640
+ * Resume the instance. If it is already running, an error will be thrown.
5641
+ */
5642
+ public resume(): Promise<void>;
5643
+ /**
5644
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5645
+ */
5646
+ public abort(): Promise<void>;
5647
+ /**
5648
+ * Restart the instance.
5649
+ */
5650
+ public restart(): Promise<void>;
5651
+ /**
5652
+ * Returns the current status of the instance.
5653
+ */
5654
+ public status(): Promise<InstanceStatus>;
5655
+ }
@@ -561,6 +561,7 @@ export interface DurableObjectState {
561
561
  setHibernatableWebSocketEventTimeout(timeoutMs?: number): void;
562
562
  getHibernatableWebSocketEventTimeout(): number | null;
563
563
  getTags(ws: WebSocket): string[];
564
+ abort(reason?: string): void;
564
565
  }
565
566
  export interface DurableObjectTransaction {
566
567
  get<T = unknown>(
@@ -627,7 +628,11 @@ export interface DurableObjectStorage {
627
628
  ): Promise<void>;
628
629
  deleteAlarm(options?: DurableObjectSetAlarmOptions): Promise<void>;
629
630
  sync(): Promise<void>;
631
+ sql: SqlStorage;
630
632
  transactionSync<T>(closure: () => T): T;
633
+ getCurrentBookmark(): Promise<string>;
634
+ getBookmarkForTime(timestamp: number | Date): Promise<string>;
635
+ onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
631
636
  }
632
637
  export interface DurableObjectListOptions {
633
638
  start?: string;
@@ -1541,7 +1546,11 @@ export declare abstract class Body {
1541
1546
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
1542
1547
  */
1543
1548
  export declare class Response extends Body {
1544
- constructor(body?: BodyInit | null, init?: ResponseInit);
1549
+ constructor(
1550
+ body?: BodyInit | null,
1551
+ init?: ResponseInit,
1552
+ webSocket?: WebSocket,
1553
+ );
1545
1554
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
1546
1555
  static redirect(url: string, status?: number): Response;
1547
1556
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
@@ -1568,7 +1577,7 @@ export interface ResponseInit {
1568
1577
  statusText?: string;
1569
1578
  headers?: HeadersInit;
1570
1579
  cf?: any;
1571
- webSocket?: WebSocket | null;
1580
+ webSocket?: WebSocket;
1572
1581
  encodeBody?: "automatic" | "manual";
1573
1582
  }
1574
1583
  export type RequestInfo<
@@ -2276,15 +2285,15 @@ export declare class TransformStream<I = any, O = any> {
2276
2285
  }
2277
2286
  export declare class FixedLengthStream extends IdentityTransformStream {
2278
2287
  constructor(
2279
- param1: number | bigint,
2280
- param2?: IdentityTransformStreamQueuingStrategy,
2288
+ expectedLength: number | bigint,
2289
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2281
2290
  );
2282
2291
  }
2283
2292
  export declare class IdentityTransformStream extends TransformStream<
2284
2293
  ArrayBuffer | ArrayBufferView,
2285
2294
  Uint8Array
2286
2295
  > {
2287
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2296
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2288
2297
  }
2289
2298
  export interface IdentityTransformStreamQueuingStrategy {
2290
2299
  highWaterMark?: number | bigint;
@@ -2765,6 +2774,26 @@ export declare const WebSocketPair: {
2765
2774
  1: WebSocket;
2766
2775
  };
2767
2776
  };
2777
+ export interface SqlStorage {
2778
+ exec<T extends Record<string, SqlStorageValue>>(
2779
+ query: string,
2780
+ ...bindings: any[]
2781
+ ): SqlStorageCursor<T>;
2782
+ get databaseSize(): number;
2783
+ Cursor: typeof SqlStorageCursor;
2784
+ Statement: typeof SqlStorageStatement;
2785
+ }
2786
+ export declare abstract class SqlStorageStatement {}
2787
+ export type SqlStorageValue = ArrayBuffer | string | number | null;
2788
+ export declare abstract class SqlStorageCursor<
2789
+ T extends Record<string, SqlStorageValue>,
2790
+ > {
2791
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2792
+ get columnNames(): string[];
2793
+ get rowsRead(): number;
2794
+ get rowsWritten(): number;
2795
+ [Symbol.iterator](): IterableIterator<T>;
2796
+ }
2768
2797
  export interface Socket {
2769
2798
  get readable(): ReadableStream;
2770
2799
  get writable(): WritableStream;
@@ -3302,7 +3331,7 @@ export interface GPUOrigin3DDict {
3302
3331
  z?: number;
3303
3332
  }
3304
3333
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3305
- export declare class EventSource {
3334
+ export declare class EventSource extends EventTarget {
3306
3335
  constructor(url: string, init?: EventSourceEventSourceInit);
3307
3336
  /**
3308
3337
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -4964,6 +4993,18 @@ export declare abstract class PipelineTransform {
4964
4993
  */
4965
4994
  public transformJson(data: object[]): Promise<object[]>;
4966
4995
  }
4996
+ // Copyright (c) 2022-2023 Cloudflare, Inc.
4997
+ // Licensed under the Apache 2.0 license found in the LICENSE file or at:
4998
+ // https://opensource.org/licenses/Apache-2.0
4999
+ export interface Pipeline {
5000
+ /**
5001
+ * send takes an array of javascript objects which are
5002
+ * then received by the pipeline for processing
5003
+ *
5004
+ * @param data The data to be sent
5005
+ */
5006
+ send(data: object[]): Promise<void>;
5007
+ }
4967
5008
  // PubSubMessage represents an incoming PubSub message.
4968
5009
  // The message includes metadata about the broker, the client, and the payload
4969
5010
  // itself.
@@ -5460,3 +5501,57 @@ export interface DispatchNamespace {
5460
5501
  options?: DynamicDispatchOptions,
5461
5502
  ): Fetcher;
5462
5503
  }
5504
+ export declare abstract class Workflow {
5505
+ /**
5506
+ * Get a handle to an existing instance of the Workflow.
5507
+ * @param id Id for the instance of this Workflow
5508
+ * @returns A promise that resolves with a handle for the Instance
5509
+ */
5510
+ public get(id: string): Promise<Instance>;
5511
+ /**
5512
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5513
+ * @param id Id to create the instance of this Workflow with
5514
+ * @param params The payload to send over to this instance
5515
+ * @returns A promise that resolves with a handle for the Instance
5516
+ */
5517
+ public create(id: string, params: object): Promise<Instance>;
5518
+ }
5519
+ export type InstanceStatus = {
5520
+ status:
5521
+ | "queued"
5522
+ | "running"
5523
+ | "paused"
5524
+ | "errored"
5525
+ | "terminated"
5526
+ | "complete"
5527
+ | "unknown";
5528
+ error?: string;
5529
+ output?: object;
5530
+ };
5531
+ export interface WorkflowError {
5532
+ code?: number;
5533
+ message: string;
5534
+ }
5535
+ export declare abstract class Instance {
5536
+ public id: string;
5537
+ /**
5538
+ * Pause the instance.
5539
+ */
5540
+ public pause(): Promise<void>;
5541
+ /**
5542
+ * Resume the instance. If it is already running, an error will be thrown.
5543
+ */
5544
+ public resume(): Promise<void>;
5545
+ /**
5546
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5547
+ */
5548
+ public abort(): Promise<void>;
5549
+ /**
5550
+ * Restart the instance.
5551
+ */
5552
+ public restart(): Promise<void>;
5553
+ /**
5554
+ * Returns the current status of the instance.
5555
+ */
5556
+ public status(): Promise<InstanceStatus>;
5557
+ }