@cloudflare/workers-types 4.20240909.0 → 4.20240924.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.
@@ -2283,15 +2283,15 @@ declare class TransformStream<I = any, O = any> {
2283
2283
  }
2284
2284
  declare class FixedLengthStream extends IdentityTransformStream {
2285
2285
  constructor(
2286
- param1: number | bigint,
2287
- param2?: IdentityTransformStreamQueuingStrategy,
2286
+ expectedLength: number | bigint,
2287
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2288
2288
  );
2289
2289
  }
2290
2290
  declare class IdentityTransformStream extends TransformStream<
2291
2291
  ArrayBuffer | ArrayBufferView,
2292
2292
  Uint8Array
2293
2293
  > {
2294
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2294
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2295
2295
  }
2296
2296
  interface IdentityTransformStreamQueuingStrategy {
2297
2297
  highWaterMark?: number | bigint;
@@ -2769,21 +2769,35 @@ declare const WebSocketPair: {
2769
2769
  };
2770
2770
  };
2771
2771
  interface SqlStorage {
2772
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2773
- prepare(query: string): SqlStorageStatement;
2772
+ exec<T extends Record<string, SqlStorageValue>>(
2773
+ query: string,
2774
+ ...bindings: any[]
2775
+ ): SqlStorageCursor<T>;
2774
2776
  get databaseSize(): number;
2775
2777
  Cursor: typeof SqlStorageCursor;
2776
2778
  Statement: typeof SqlStorageStatement;
2777
2779
  }
2778
2780
  declare abstract class SqlStorageStatement {}
2779
- declare abstract class SqlStorageCursor {
2780
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2781
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2782
+ declare abstract class SqlStorageCursor<
2783
+ T extends Record<string, SqlStorageValue>,
2784
+ > {
2785
+ next():
2786
+ | {
2787
+ done?: false;
2788
+ value: T;
2789
+ }
2790
+ | {
2791
+ done: true;
2792
+ value?: never;
2793
+ };
2794
+ toArray(): T[];
2795
+ one(): T;
2796
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2781
2797
  get columnNames(): string[];
2782
2798
  get rowsRead(): number;
2783
2799
  get rowsWritten(): number;
2784
- [Symbol.iterator](): IterableIterator<
2785
- Record<string, (ArrayBuffer | string | number) | null>
2786
- >;
2800
+ [Symbol.iterator](): IterableIterator<T>;
2787
2801
  }
2788
2802
  interface Socket {
2789
2803
  get readable(): ReadableStream;
@@ -3322,7 +3336,7 @@ interface GPUOrigin3DDict {
3322
3336
  z?: number;
3323
3337
  }
3324
3338
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3325
- declare class EventSource {
3339
+ declare class EventSource extends EventTarget {
3326
3340
  constructor(url: string, init?: EventSourceEventSourceInit);
3327
3341
  /**
3328
3342
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5587,12 +5601,69 @@ interface DispatchNamespace {
5587
5601
  ): Fetcher;
5588
5602
  }
5589
5603
  /**
5590
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5591
- * an error that makes the instance fail immediately without triggering a retry.
5604
+ * NonRetryableError allows for a user to throw a fatal error
5605
+ * that makes a Workflow instance fail immediately without triggering a retry
5592
5606
  */
5593
- declare class NonRetryableError extends Error {
5594
- // __brand has been explicity omitted because it's a internal brand used for
5595
- // the Workflows' engine and user's shouldn't be able to override it
5596
- // (at least, in a direct way)
5597
- public constructor(message: string, name?: string);
5607
+ declare module "cloudflare:workflows" {
5608
+ export abstract class NonRetryableError extends Error {
5609
+ /**
5610
+ * `__brand` is used to differentiate between `NonRetryableError` and `Error`
5611
+ * and is omitted from the constructor because users should not set it
5612
+ */
5613
+ public constructor(message: string, name?: string);
5614
+ }
5615
+ }
5616
+ declare abstract class Workflow {
5617
+ /**
5618
+ * Get a handle to an existing instance of the Workflow.
5619
+ * @param id Id for the instance of this Workflow
5620
+ * @returns A promise that resolves with a handle for the Instance
5621
+ */
5622
+ public get(id: string): Promise<Instance>;
5623
+ /**
5624
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5625
+ * @param id Id to create the instance of this Workflow with
5626
+ * @param params The payload to send over to this instance
5627
+ * @returns A promise that resolves with a handle for the Instance
5628
+ */
5629
+ public create(id: string, params: object): Promise<Instance>;
5630
+ }
5631
+ type InstanceStatus = {
5632
+ status:
5633
+ | "queued"
5634
+ | "running"
5635
+ | "paused"
5636
+ | "errored"
5637
+ | "terminated"
5638
+ | "complete"
5639
+ | "unknown";
5640
+ error?: string;
5641
+ output?: object;
5642
+ };
5643
+ interface WorkflowError {
5644
+ code?: number;
5645
+ message: string;
5646
+ }
5647
+ declare abstract class Instance {
5648
+ public id: string;
5649
+ /**
5650
+ * Pause the instance.
5651
+ */
5652
+ public pause(): Promise<void>;
5653
+ /**
5654
+ * Resume the instance. If it is already running, an error will be thrown.
5655
+ */
5656
+ public resume(): Promise<void>;
5657
+ /**
5658
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5659
+ */
5660
+ public abort(): Promise<void>;
5661
+ /**
5662
+ * Restart the instance.
5663
+ */
5664
+ public restart(): Promise<void>;
5665
+ /**
5666
+ * Returns the current status of the instance.
5667
+ */
5668
+ public status(): Promise<InstanceStatus>;
5598
5669
  }
@@ -2289,15 +2289,15 @@ export declare class TransformStream<I = any, O = any> {
2289
2289
  }
2290
2290
  export declare class FixedLengthStream extends IdentityTransformStream {
2291
2291
  constructor(
2292
- param1: number | bigint,
2293
- param2?: IdentityTransformStreamQueuingStrategy,
2292
+ expectedLength: number | bigint,
2293
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2294
2294
  );
2295
2295
  }
2296
2296
  export declare class IdentityTransformStream extends TransformStream<
2297
2297
  ArrayBuffer | ArrayBufferView,
2298
2298
  Uint8Array
2299
2299
  > {
2300
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2300
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2301
2301
  }
2302
2302
  export interface IdentityTransformStreamQueuingStrategy {
2303
2303
  highWaterMark?: number | bigint;
@@ -2778,21 +2778,35 @@ export declare const WebSocketPair: {
2778
2778
  };
2779
2779
  };
2780
2780
  export interface SqlStorage {
2781
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2782
- prepare(query: string): SqlStorageStatement;
2781
+ exec<T extends Record<string, SqlStorageValue>>(
2782
+ query: string,
2783
+ ...bindings: any[]
2784
+ ): SqlStorageCursor<T>;
2783
2785
  get databaseSize(): number;
2784
2786
  Cursor: typeof SqlStorageCursor;
2785
2787
  Statement: typeof SqlStorageStatement;
2786
2788
  }
2787
2789
  export declare abstract class SqlStorageStatement {}
2788
- export declare abstract class SqlStorageCursor {
2789
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2790
+ export type SqlStorageValue = ArrayBuffer | string | number | null;
2791
+ export declare abstract class SqlStorageCursor<
2792
+ T extends Record<string, SqlStorageValue>,
2793
+ > {
2794
+ next():
2795
+ | {
2796
+ done?: false;
2797
+ value: T;
2798
+ }
2799
+ | {
2800
+ done: true;
2801
+ value?: never;
2802
+ };
2803
+ toArray(): T[];
2804
+ one(): T;
2805
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2790
2806
  get columnNames(): string[];
2791
2807
  get rowsRead(): number;
2792
2808
  get rowsWritten(): number;
2793
- [Symbol.iterator](): IterableIterator<
2794
- Record<string, (ArrayBuffer | string | number) | null>
2795
- >;
2809
+ [Symbol.iterator](): IterableIterator<T>;
2796
2810
  }
2797
2811
  export interface Socket {
2798
2812
  get readable(): ReadableStream;
@@ -3331,7 +3345,7 @@ export interface GPUOrigin3DDict {
3331
3345
  z?: number;
3332
3346
  }
3333
3347
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3334
- export declare class EventSource {
3348
+ export declare class EventSource extends EventTarget {
3335
3349
  constructor(url: string, init?: EventSourceEventSourceInit);
3336
3350
  /**
3337
3351
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5501,13 +5515,57 @@ export interface DispatchNamespace {
5501
5515
  options?: DynamicDispatchOptions,
5502
5516
  ): Fetcher;
5503
5517
  }
5504
- /**
5505
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5506
- * an error that makes the instance fail immediately without triggering a retry.
5507
- */
5508
- export declare class NonRetryableError extends Error {
5509
- // __brand has been explicity omitted because it's a internal brand used for
5510
- // the Workflows' engine and user's shouldn't be able to override it
5511
- // (at least, in a direct way)
5512
- public constructor(message: string, name?: string);
5518
+ export declare abstract class Workflow {
5519
+ /**
5520
+ * Get a handle to an existing instance of the Workflow.
5521
+ * @param id Id for the instance of this Workflow
5522
+ * @returns A promise that resolves with a handle for the Instance
5523
+ */
5524
+ public get(id: string): Promise<Instance>;
5525
+ /**
5526
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5527
+ * @param id Id to create the instance of this Workflow with
5528
+ * @param params The payload to send over to this instance
5529
+ * @returns A promise that resolves with a handle for the Instance
5530
+ */
5531
+ public create(id: string, params: object): Promise<Instance>;
5532
+ }
5533
+ export type InstanceStatus = {
5534
+ status:
5535
+ | "queued"
5536
+ | "running"
5537
+ | "paused"
5538
+ | "errored"
5539
+ | "terminated"
5540
+ | "complete"
5541
+ | "unknown";
5542
+ error?: string;
5543
+ output?: object;
5544
+ };
5545
+ export interface WorkflowError {
5546
+ code?: number;
5547
+ message: string;
5548
+ }
5549
+ export declare abstract class Instance {
5550
+ public id: string;
5551
+ /**
5552
+ * Pause the instance.
5553
+ */
5554
+ public pause(): Promise<void>;
5555
+ /**
5556
+ * Resume the instance. If it is already running, an error will be thrown.
5557
+ */
5558
+ public resume(): Promise<void>;
5559
+ /**
5560
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5561
+ */
5562
+ public abort(): Promise<void>;
5563
+ /**
5564
+ * Restart the instance.
5565
+ */
5566
+ public restart(): Promise<void>;
5567
+ /**
5568
+ * Returns the current status of the instance.
5569
+ */
5570
+ public status(): Promise<InstanceStatus>;
5513
5571
  }
@@ -2283,15 +2283,15 @@ declare class TransformStream<I = any, O = any> {
2283
2283
  }
2284
2284
  declare class FixedLengthStream extends IdentityTransformStream {
2285
2285
  constructor(
2286
- param1: number | bigint,
2287
- param2?: IdentityTransformStreamQueuingStrategy,
2286
+ expectedLength: number | bigint,
2287
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2288
2288
  );
2289
2289
  }
2290
2290
  declare class IdentityTransformStream extends TransformStream<
2291
2291
  ArrayBuffer | ArrayBufferView,
2292
2292
  Uint8Array
2293
2293
  > {
2294
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2294
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2295
2295
  }
2296
2296
  interface IdentityTransformStreamQueuingStrategy {
2297
2297
  highWaterMark?: number | bigint;
@@ -2769,21 +2769,35 @@ declare const WebSocketPair: {
2769
2769
  };
2770
2770
  };
2771
2771
  interface SqlStorage {
2772
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2773
- prepare(query: string): SqlStorageStatement;
2772
+ exec<T extends Record<string, SqlStorageValue>>(
2773
+ query: string,
2774
+ ...bindings: any[]
2775
+ ): SqlStorageCursor<T>;
2774
2776
  get databaseSize(): number;
2775
2777
  Cursor: typeof SqlStorageCursor;
2776
2778
  Statement: typeof SqlStorageStatement;
2777
2779
  }
2778
2780
  declare abstract class SqlStorageStatement {}
2779
- declare abstract class SqlStorageCursor {
2780
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2781
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2782
+ declare abstract class SqlStorageCursor<
2783
+ T extends Record<string, SqlStorageValue>,
2784
+ > {
2785
+ next():
2786
+ | {
2787
+ done?: false;
2788
+ value: T;
2789
+ }
2790
+ | {
2791
+ done: true;
2792
+ value?: never;
2793
+ };
2794
+ toArray(): T[];
2795
+ one(): T;
2796
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2781
2797
  get columnNames(): string[];
2782
2798
  get rowsRead(): number;
2783
2799
  get rowsWritten(): number;
2784
- [Symbol.iterator](): IterableIterator<
2785
- Record<string, (ArrayBuffer | string | number) | null>
2786
- >;
2800
+ [Symbol.iterator](): IterableIterator<T>;
2787
2801
  }
2788
2802
  interface Socket {
2789
2803
  get readable(): ReadableStream;
@@ -3322,7 +3336,7 @@ interface GPUOrigin3DDict {
3322
3336
  z?: number;
3323
3337
  }
3324
3338
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3325
- declare class EventSource {
3339
+ declare class EventSource extends EventTarget {
3326
3340
  constructor(url: string, init?: EventSourceEventSourceInit);
3327
3341
  /**
3328
3342
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5587,12 +5601,69 @@ interface DispatchNamespace {
5587
5601
  ): Fetcher;
5588
5602
  }
5589
5603
  /**
5590
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5591
- * an error that makes the instance fail immediately without triggering a retry.
5604
+ * NonRetryableError allows for a user to throw a fatal error
5605
+ * that makes a Workflow instance fail immediately without triggering a retry
5592
5606
  */
5593
- declare class NonRetryableError extends Error {
5594
- // __brand has been explicity omitted because it's a internal brand used for
5595
- // the Workflows' engine and user's shouldn't be able to override it
5596
- // (at least, in a direct way)
5597
- public constructor(message: string, name?: string);
5607
+ declare module "cloudflare:workflows" {
5608
+ export abstract class NonRetryableError extends Error {
5609
+ /**
5610
+ * `__brand` is used to differentiate between `NonRetryableError` and `Error`
5611
+ * and is omitted from the constructor because users should not set it
5612
+ */
5613
+ public constructor(message: string, name?: string);
5614
+ }
5615
+ }
5616
+ declare abstract class Workflow {
5617
+ /**
5618
+ * Get a handle to an existing instance of the Workflow.
5619
+ * @param id Id for the instance of this Workflow
5620
+ * @returns A promise that resolves with a handle for the Instance
5621
+ */
5622
+ public get(id: string): Promise<Instance>;
5623
+ /**
5624
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5625
+ * @param id Id to create the instance of this Workflow with
5626
+ * @param params The payload to send over to this instance
5627
+ * @returns A promise that resolves with a handle for the Instance
5628
+ */
5629
+ public create(id: string, params: object): Promise<Instance>;
5630
+ }
5631
+ type InstanceStatus = {
5632
+ status:
5633
+ | "queued"
5634
+ | "running"
5635
+ | "paused"
5636
+ | "errored"
5637
+ | "terminated"
5638
+ | "complete"
5639
+ | "unknown";
5640
+ error?: string;
5641
+ output?: object;
5642
+ };
5643
+ interface WorkflowError {
5644
+ code?: number;
5645
+ message: string;
5646
+ }
5647
+ declare abstract class Instance {
5648
+ public id: string;
5649
+ /**
5650
+ * Pause the instance.
5651
+ */
5652
+ public pause(): Promise<void>;
5653
+ /**
5654
+ * Resume the instance. If it is already running, an error will be thrown.
5655
+ */
5656
+ public resume(): Promise<void>;
5657
+ /**
5658
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5659
+ */
5660
+ public abort(): Promise<void>;
5661
+ /**
5662
+ * Restart the instance.
5663
+ */
5664
+ public restart(): Promise<void>;
5665
+ /**
5666
+ * Returns the current status of the instance.
5667
+ */
5668
+ public status(): Promise<InstanceStatus>;
5598
5669
  }
@@ -2289,15 +2289,15 @@ export declare class TransformStream<I = any, O = any> {
2289
2289
  }
2290
2290
  export declare class FixedLengthStream extends IdentityTransformStream {
2291
2291
  constructor(
2292
- param1: number | bigint,
2293
- param2?: IdentityTransformStreamQueuingStrategy,
2292
+ expectedLength: number | bigint,
2293
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2294
2294
  );
2295
2295
  }
2296
2296
  export declare class IdentityTransformStream extends TransformStream<
2297
2297
  ArrayBuffer | ArrayBufferView,
2298
2298
  Uint8Array
2299
2299
  > {
2300
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2300
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2301
2301
  }
2302
2302
  export interface IdentityTransformStreamQueuingStrategy {
2303
2303
  highWaterMark?: number | bigint;
@@ -2778,21 +2778,35 @@ export declare const WebSocketPair: {
2778
2778
  };
2779
2779
  };
2780
2780
  export interface SqlStorage {
2781
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2782
- prepare(query: string): SqlStorageStatement;
2781
+ exec<T extends Record<string, SqlStorageValue>>(
2782
+ query: string,
2783
+ ...bindings: any[]
2784
+ ): SqlStorageCursor<T>;
2783
2785
  get databaseSize(): number;
2784
2786
  Cursor: typeof SqlStorageCursor;
2785
2787
  Statement: typeof SqlStorageStatement;
2786
2788
  }
2787
2789
  export declare abstract class SqlStorageStatement {}
2788
- export declare abstract class SqlStorageCursor {
2789
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2790
+ export type SqlStorageValue = ArrayBuffer | string | number | null;
2791
+ export declare abstract class SqlStorageCursor<
2792
+ T extends Record<string, SqlStorageValue>,
2793
+ > {
2794
+ next():
2795
+ | {
2796
+ done?: false;
2797
+ value: T;
2798
+ }
2799
+ | {
2800
+ done: true;
2801
+ value?: never;
2802
+ };
2803
+ toArray(): T[];
2804
+ one(): T;
2805
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2790
2806
  get columnNames(): string[];
2791
2807
  get rowsRead(): number;
2792
2808
  get rowsWritten(): number;
2793
- [Symbol.iterator](): IterableIterator<
2794
- Record<string, (ArrayBuffer | string | number) | null>
2795
- >;
2809
+ [Symbol.iterator](): IterableIterator<T>;
2796
2810
  }
2797
2811
  export interface Socket {
2798
2812
  get readable(): ReadableStream;
@@ -3331,7 +3345,7 @@ export interface GPUOrigin3DDict {
3331
3345
  z?: number;
3332
3346
  }
3333
3347
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3334
- export declare class EventSource {
3348
+ export declare class EventSource extends EventTarget {
3335
3349
  constructor(url: string, init?: EventSourceEventSourceInit);
3336
3350
  /**
3337
3351
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5501,13 +5515,57 @@ export interface DispatchNamespace {
5501
5515
  options?: DynamicDispatchOptions,
5502
5516
  ): Fetcher;
5503
5517
  }
5504
- /**
5505
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5506
- * an error that makes the instance fail immediately without triggering a retry.
5507
- */
5508
- export declare class NonRetryableError extends Error {
5509
- // __brand has been explicity omitted because it's a internal brand used for
5510
- // the Workflows' engine and user's shouldn't be able to override it
5511
- // (at least, in a direct way)
5512
- public constructor(message: string, name?: string);
5518
+ export declare abstract class Workflow {
5519
+ /**
5520
+ * Get a handle to an existing instance of the Workflow.
5521
+ * @param id Id for the instance of this Workflow
5522
+ * @returns A promise that resolves with a handle for the Instance
5523
+ */
5524
+ public get(id: string): Promise<Instance>;
5525
+ /**
5526
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5527
+ * @param id Id to create the instance of this Workflow with
5528
+ * @param params The payload to send over to this instance
5529
+ * @returns A promise that resolves with a handle for the Instance
5530
+ */
5531
+ public create(id: string, params: object): Promise<Instance>;
5532
+ }
5533
+ export type InstanceStatus = {
5534
+ status:
5535
+ | "queued"
5536
+ | "running"
5537
+ | "paused"
5538
+ | "errored"
5539
+ | "terminated"
5540
+ | "complete"
5541
+ | "unknown";
5542
+ error?: string;
5543
+ output?: object;
5544
+ };
5545
+ export interface WorkflowError {
5546
+ code?: number;
5547
+ message: string;
5548
+ }
5549
+ export declare abstract class Instance {
5550
+ public id: string;
5551
+ /**
5552
+ * Pause the instance.
5553
+ */
5554
+ public pause(): Promise<void>;
5555
+ /**
5556
+ * Resume the instance. If it is already running, an error will be thrown.
5557
+ */
5558
+ public resume(): Promise<void>;
5559
+ /**
5560
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5561
+ */
5562
+ public abort(): Promise<void>;
5563
+ /**
5564
+ * Restart the instance.
5565
+ */
5566
+ public restart(): Promise<void>;
5567
+ /**
5568
+ * Returns the current status of the instance.
5569
+ */
5570
+ public status(): Promise<InstanceStatus>;
5513
5571
  }