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