@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.
@@ -2252,15 +2252,15 @@ declare class TransformStream<I = any, O = any> {
2252
2252
  }
2253
2253
  declare class FixedLengthStream extends IdentityTransformStream {
2254
2254
  constructor(
2255
- param1: number | bigint,
2256
- param2?: IdentityTransformStreamQueuingStrategy,
2255
+ expectedLength: number | bigint,
2256
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2257
2257
  );
2258
2258
  }
2259
2259
  declare class IdentityTransformStream extends TransformStream<
2260
2260
  ArrayBuffer | ArrayBufferView,
2261
2261
  Uint8Array
2262
2262
  > {
2263
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2263
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2264
2264
  }
2265
2265
  interface IdentityTransformStreamQueuingStrategy {
2266
2266
  highWaterMark?: number | bigint;
@@ -2719,21 +2719,35 @@ declare const WebSocketPair: {
2719
2719
  };
2720
2720
  };
2721
2721
  interface SqlStorage {
2722
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2723
- prepare(query: string): SqlStorageStatement;
2722
+ exec<T extends Record<string, SqlStorageValue>>(
2723
+ query: string,
2724
+ ...bindings: any[]
2725
+ ): SqlStorageCursor<T>;
2724
2726
  get databaseSize(): number;
2725
2727
  Cursor: typeof SqlStorageCursor;
2726
2728
  Statement: typeof SqlStorageStatement;
2727
2729
  }
2728
2730
  declare abstract class SqlStorageStatement {}
2729
- declare abstract class SqlStorageCursor {
2730
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2731
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2732
+ declare abstract class SqlStorageCursor<
2733
+ T extends Record<string, SqlStorageValue>,
2734
+ > {
2735
+ next():
2736
+ | {
2737
+ done?: false;
2738
+ value: T;
2739
+ }
2740
+ | {
2741
+ done: true;
2742
+ value?: never;
2743
+ };
2744
+ toArray(): T[];
2745
+ one(): T;
2746
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2731
2747
  get columnNames(): string[];
2732
2748
  get rowsRead(): number;
2733
2749
  get rowsWritten(): number;
2734
- [Symbol.iterator](): IterableIterator<
2735
- Record<string, (ArrayBuffer | string | number) | null>
2736
- >;
2750
+ [Symbol.iterator](): IterableIterator<T>;
2737
2751
  }
2738
2752
  interface Socket {
2739
2753
  get readable(): ReadableStream;
@@ -3265,7 +3279,7 @@ interface GPUOrigin3DDict {
3265
3279
  z?: number;
3266
3280
  }
3267
3281
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3268
- declare class EventSource {
3282
+ declare class EventSource extends EventTarget {
3269
3283
  constructor(url: string, init?: EventSourceEventSourceInit);
3270
3284
  /**
3271
3285
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5530,12 +5544,69 @@ interface DispatchNamespace {
5530
5544
  ): Fetcher;
5531
5545
  }
5532
5546
  /**
5533
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5534
- * an error that makes the instance fail immediately without triggering a retry.
5547
+ * NonRetryableError allows for a user to throw a fatal error
5548
+ * that makes a Workflow instance fail immediately without triggering a retry
5535
5549
  */
5536
- declare class NonRetryableError extends Error {
5537
- // __brand has been explicity omitted because it's a internal brand used for
5538
- // the Workflows' engine and user's shouldn't be able to override it
5539
- // (at least, in a direct way)
5540
- public constructor(message: string, name?: string);
5550
+ declare module "cloudflare:workflows" {
5551
+ export abstract class NonRetryableError extends Error {
5552
+ /**
5553
+ * `__brand` is used to differentiate between `NonRetryableError` and `Error`
5554
+ * and is omitted from the constructor because users should not set it
5555
+ */
5556
+ public constructor(message: string, name?: string);
5557
+ }
5558
+ }
5559
+ declare abstract class Workflow {
5560
+ /**
5561
+ * Get a handle to an existing instance of the Workflow.
5562
+ * @param id Id for the instance of this Workflow
5563
+ * @returns A promise that resolves with a handle for the Instance
5564
+ */
5565
+ public get(id: string): Promise<Instance>;
5566
+ /**
5567
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5568
+ * @param id Id to create the instance of this Workflow with
5569
+ * @param params The payload to send over to this instance
5570
+ * @returns A promise that resolves with a handle for the Instance
5571
+ */
5572
+ public create(id: string, params: object): Promise<Instance>;
5573
+ }
5574
+ type InstanceStatus = {
5575
+ status:
5576
+ | "queued"
5577
+ | "running"
5578
+ | "paused"
5579
+ | "errored"
5580
+ | "terminated"
5581
+ | "complete"
5582
+ | "unknown";
5583
+ error?: string;
5584
+ output?: object;
5585
+ };
5586
+ interface WorkflowError {
5587
+ code?: number;
5588
+ message: string;
5589
+ }
5590
+ declare abstract class Instance {
5591
+ public id: string;
5592
+ /**
5593
+ * Pause the instance.
5594
+ */
5595
+ public pause(): Promise<void>;
5596
+ /**
5597
+ * Resume the instance. If it is already running, an error will be thrown.
5598
+ */
5599
+ public resume(): Promise<void>;
5600
+ /**
5601
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5602
+ */
5603
+ public abort(): Promise<void>;
5604
+ /**
5605
+ * Restart the instance.
5606
+ */
5607
+ public restart(): Promise<void>;
5608
+ /**
5609
+ * Returns the current status of the instance.
5610
+ */
5611
+ public status(): Promise<InstanceStatus>;
5541
5612
  }
@@ -2258,15 +2258,15 @@ export declare class TransformStream<I = any, O = any> {
2258
2258
  }
2259
2259
  export declare class FixedLengthStream extends IdentityTransformStream {
2260
2260
  constructor(
2261
- param1: number | bigint,
2262
- param2?: IdentityTransformStreamQueuingStrategy,
2261
+ expectedLength: number | bigint,
2262
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2263
2263
  );
2264
2264
  }
2265
2265
  export declare class IdentityTransformStream extends TransformStream<
2266
2266
  ArrayBuffer | ArrayBufferView,
2267
2267
  Uint8Array
2268
2268
  > {
2269
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2269
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2270
2270
  }
2271
2271
  export interface IdentityTransformStreamQueuingStrategy {
2272
2272
  highWaterMark?: number | bigint;
@@ -2728,21 +2728,35 @@ export declare const WebSocketPair: {
2728
2728
  };
2729
2729
  };
2730
2730
  export interface SqlStorage {
2731
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2732
- prepare(query: string): SqlStorageStatement;
2731
+ exec<T extends Record<string, SqlStorageValue>>(
2732
+ query: string,
2733
+ ...bindings: any[]
2734
+ ): SqlStorageCursor<T>;
2733
2735
  get databaseSize(): number;
2734
2736
  Cursor: typeof SqlStorageCursor;
2735
2737
  Statement: typeof SqlStorageStatement;
2736
2738
  }
2737
2739
  export declare abstract class SqlStorageStatement {}
2738
- export declare abstract class SqlStorageCursor {
2739
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2740
+ export type SqlStorageValue = ArrayBuffer | string | number | null;
2741
+ export declare abstract class SqlStorageCursor<
2742
+ T extends Record<string, SqlStorageValue>,
2743
+ > {
2744
+ next():
2745
+ | {
2746
+ done?: false;
2747
+ value: T;
2748
+ }
2749
+ | {
2750
+ done: true;
2751
+ value?: never;
2752
+ };
2753
+ toArray(): T[];
2754
+ one(): T;
2755
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2740
2756
  get columnNames(): string[];
2741
2757
  get rowsRead(): number;
2742
2758
  get rowsWritten(): number;
2743
- [Symbol.iterator](): IterableIterator<
2744
- Record<string, (ArrayBuffer | string | number) | null>
2745
- >;
2759
+ [Symbol.iterator](): IterableIterator<T>;
2746
2760
  }
2747
2761
  export interface Socket {
2748
2762
  get readable(): ReadableStream;
@@ -3274,7 +3288,7 @@ export interface GPUOrigin3DDict {
3274
3288
  z?: number;
3275
3289
  }
3276
3290
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3277
- export declare class EventSource {
3291
+ export declare class EventSource extends EventTarget {
3278
3292
  constructor(url: string, init?: EventSourceEventSourceInit);
3279
3293
  /**
3280
3294
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5444,13 +5458,57 @@ export interface DispatchNamespace {
5444
5458
  options?: DynamicDispatchOptions,
5445
5459
  ): Fetcher;
5446
5460
  }
5447
- /**
5448
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5449
- * an error that makes the instance fail immediately without triggering a retry.
5450
- */
5451
- export declare class NonRetryableError extends Error {
5452
- // __brand has been explicity omitted because it's a internal brand used for
5453
- // the Workflows' engine and user's shouldn't be able to override it
5454
- // (at least, in a direct way)
5455
- public constructor(message: string, name?: string);
5461
+ export declare abstract class Workflow {
5462
+ /**
5463
+ * Get a handle to an existing instance of the Workflow.
5464
+ * @param id Id for the instance of this Workflow
5465
+ * @returns A promise that resolves with a handle for the Instance
5466
+ */
5467
+ public get(id: string): Promise<Instance>;
5468
+ /**
5469
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5470
+ * @param id Id to create the instance of this Workflow with
5471
+ * @param params The payload to send over to this instance
5472
+ * @returns A promise that resolves with a handle for the Instance
5473
+ */
5474
+ public create(id: string, params: object): Promise<Instance>;
5475
+ }
5476
+ export type InstanceStatus = {
5477
+ status:
5478
+ | "queued"
5479
+ | "running"
5480
+ | "paused"
5481
+ | "errored"
5482
+ | "terminated"
5483
+ | "complete"
5484
+ | "unknown";
5485
+ error?: string;
5486
+ output?: object;
5487
+ };
5488
+ export interface WorkflowError {
5489
+ code?: number;
5490
+ message: string;
5491
+ }
5492
+ export declare abstract class Instance {
5493
+ public id: string;
5494
+ /**
5495
+ * Pause the instance.
5496
+ */
5497
+ public pause(): Promise<void>;
5498
+ /**
5499
+ * Resume the instance. If it is already running, an error will be thrown.
5500
+ */
5501
+ public resume(): Promise<void>;
5502
+ /**
5503
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5504
+ */
5505
+ public abort(): Promise<void>;
5506
+ /**
5507
+ * Restart the instance.
5508
+ */
5509
+ public restart(): Promise<void>;
5510
+ /**
5511
+ * Returns the current status of the instance.
5512
+ */
5513
+ public status(): Promise<InstanceStatus>;
5456
5514
  }
@@ -2258,15 +2258,15 @@ declare class TransformStream<I = any, O = any> {
2258
2258
  }
2259
2259
  declare class FixedLengthStream extends IdentityTransformStream {
2260
2260
  constructor(
2261
- param1: number | bigint,
2262
- param2?: IdentityTransformStreamQueuingStrategy,
2261
+ expectedLength: number | bigint,
2262
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2263
2263
  );
2264
2264
  }
2265
2265
  declare class IdentityTransformStream extends TransformStream<
2266
2266
  ArrayBuffer | ArrayBufferView,
2267
2267
  Uint8Array
2268
2268
  > {
2269
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2269
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2270
2270
  }
2271
2271
  interface IdentityTransformStreamQueuingStrategy {
2272
2272
  highWaterMark?: number | bigint;
@@ -2745,21 +2745,35 @@ declare const WebSocketPair: {
2745
2745
  };
2746
2746
  };
2747
2747
  interface SqlStorage {
2748
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2749
- prepare(query: string): SqlStorageStatement;
2748
+ exec<T extends Record<string, SqlStorageValue>>(
2749
+ query: string,
2750
+ ...bindings: any[]
2751
+ ): SqlStorageCursor<T>;
2750
2752
  get databaseSize(): number;
2751
2753
  Cursor: typeof SqlStorageCursor;
2752
2754
  Statement: typeof SqlStorageStatement;
2753
2755
  }
2754
2756
  declare abstract class SqlStorageStatement {}
2755
- declare abstract class SqlStorageCursor {
2756
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2757
+ type SqlStorageValue = ArrayBuffer | string | number | null;
2758
+ declare abstract class SqlStorageCursor<
2759
+ T extends Record<string, SqlStorageValue>,
2760
+ > {
2761
+ next():
2762
+ | {
2763
+ done?: false;
2764
+ value: T;
2765
+ }
2766
+ | {
2767
+ done: true;
2768
+ value?: never;
2769
+ };
2770
+ toArray(): T[];
2771
+ one(): T;
2772
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2757
2773
  get columnNames(): string[];
2758
2774
  get rowsRead(): number;
2759
2775
  get rowsWritten(): number;
2760
- [Symbol.iterator](): IterableIterator<
2761
- Record<string, (ArrayBuffer | string | number) | null>
2762
- >;
2776
+ [Symbol.iterator](): IterableIterator<T>;
2763
2777
  }
2764
2778
  interface Socket {
2765
2779
  get readable(): ReadableStream;
@@ -3291,7 +3305,7 @@ interface GPUOrigin3DDict {
3291
3305
  z?: number;
3292
3306
  }
3293
3307
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3294
- declare class EventSource {
3308
+ declare class EventSource extends EventTarget {
3295
3309
  constructor(url: string, init?: EventSourceEventSourceInit);
3296
3310
  /**
3297
3311
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5556,12 +5570,69 @@ interface DispatchNamespace {
5556
5570
  ): Fetcher;
5557
5571
  }
5558
5572
  /**
5559
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5560
- * an error that makes the instance fail immediately without triggering a retry.
5573
+ * NonRetryableError allows for a user to throw a fatal error
5574
+ * that makes a Workflow instance fail immediately without triggering a retry
5561
5575
  */
5562
- declare class NonRetryableError extends Error {
5563
- // __brand has been explicity omitted because it's a internal brand used for
5564
- // the Workflows' engine and user's shouldn't be able to override it
5565
- // (at least, in a direct way)
5566
- public constructor(message: string, name?: string);
5576
+ declare module "cloudflare:workflows" {
5577
+ export abstract class NonRetryableError extends Error {
5578
+ /**
5579
+ * `__brand` is used to differentiate between `NonRetryableError` and `Error`
5580
+ * and is omitted from the constructor because users should not set it
5581
+ */
5582
+ public constructor(message: string, name?: string);
5583
+ }
5584
+ }
5585
+ declare abstract class Workflow {
5586
+ /**
5587
+ * Get a handle to an existing instance of the Workflow.
5588
+ * @param id Id for the instance of this Workflow
5589
+ * @returns A promise that resolves with a handle for the Instance
5590
+ */
5591
+ public get(id: string): Promise<Instance>;
5592
+ /**
5593
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5594
+ * @param id Id to create the instance of this Workflow with
5595
+ * @param params The payload to send over to this instance
5596
+ * @returns A promise that resolves with a handle for the Instance
5597
+ */
5598
+ public create(id: string, params: object): Promise<Instance>;
5599
+ }
5600
+ type InstanceStatus = {
5601
+ status:
5602
+ | "queued"
5603
+ | "running"
5604
+ | "paused"
5605
+ | "errored"
5606
+ | "terminated"
5607
+ | "complete"
5608
+ | "unknown";
5609
+ error?: string;
5610
+ output?: object;
5611
+ };
5612
+ interface WorkflowError {
5613
+ code?: number;
5614
+ message: string;
5615
+ }
5616
+ declare abstract class Instance {
5617
+ public id: string;
5618
+ /**
5619
+ * Pause the instance.
5620
+ */
5621
+ public pause(): Promise<void>;
5622
+ /**
5623
+ * Resume the instance. If it is already running, an error will be thrown.
5624
+ */
5625
+ public resume(): Promise<void>;
5626
+ /**
5627
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5628
+ */
5629
+ public abort(): Promise<void>;
5630
+ /**
5631
+ * Restart the instance.
5632
+ */
5633
+ public restart(): Promise<void>;
5634
+ /**
5635
+ * Returns the current status of the instance.
5636
+ */
5637
+ public status(): Promise<InstanceStatus>;
5567
5638
  }
@@ -2264,15 +2264,15 @@ export declare class TransformStream<I = any, O = any> {
2264
2264
  }
2265
2265
  export declare class FixedLengthStream extends IdentityTransformStream {
2266
2266
  constructor(
2267
- param1: number | bigint,
2268
- param2?: IdentityTransformStreamQueuingStrategy,
2267
+ expectedLength: number | bigint,
2268
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
2269
2269
  );
2270
2270
  }
2271
2271
  export declare class IdentityTransformStream extends TransformStream<
2272
2272
  ArrayBuffer | ArrayBufferView,
2273
2273
  Uint8Array
2274
2274
  > {
2275
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
2275
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
2276
2276
  }
2277
2277
  export interface IdentityTransformStreamQueuingStrategy {
2278
2278
  highWaterMark?: number | bigint;
@@ -2754,21 +2754,35 @@ export declare const WebSocketPair: {
2754
2754
  };
2755
2755
  };
2756
2756
  export interface SqlStorage {
2757
- exec(query: string, ...bindings: any[]): SqlStorageCursor;
2758
- prepare(query: string): SqlStorageStatement;
2757
+ exec<T extends Record<string, SqlStorageValue>>(
2758
+ query: string,
2759
+ ...bindings: any[]
2760
+ ): SqlStorageCursor<T>;
2759
2761
  get databaseSize(): number;
2760
2762
  Cursor: typeof SqlStorageCursor;
2761
2763
  Statement: typeof SqlStorageStatement;
2762
2764
  }
2763
2765
  export declare abstract class SqlStorageStatement {}
2764
- export declare abstract class SqlStorageCursor {
2765
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
2766
+ export type SqlStorageValue = ArrayBuffer | string | number | null;
2767
+ export declare abstract class SqlStorageCursor<
2768
+ T extends Record<string, SqlStorageValue>,
2769
+ > {
2770
+ next():
2771
+ | {
2772
+ done?: false;
2773
+ value: T;
2774
+ }
2775
+ | {
2776
+ done: true;
2777
+ value?: never;
2778
+ };
2779
+ toArray(): T[];
2780
+ one(): T;
2781
+ raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
2766
2782
  get columnNames(): string[];
2767
2783
  get rowsRead(): number;
2768
2784
  get rowsWritten(): number;
2769
- [Symbol.iterator](): IterableIterator<
2770
- Record<string, (ArrayBuffer | string | number) | null>
2771
- >;
2785
+ [Symbol.iterator](): IterableIterator<T>;
2772
2786
  }
2773
2787
  export interface Socket {
2774
2788
  get readable(): ReadableStream;
@@ -3300,7 +3314,7 @@ export interface GPUOrigin3DDict {
3300
3314
  z?: number;
3301
3315
  }
3302
3316
  /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
3303
- export declare class EventSource {
3317
+ export declare class EventSource extends EventTarget {
3304
3318
  constructor(url: string, init?: EventSourceEventSourceInit);
3305
3319
  /**
3306
3320
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -5470,13 +5484,57 @@ export interface DispatchNamespace {
5470
5484
  options?: DynamicDispatchOptions,
5471
5485
  ): Fetcher;
5472
5486
  }
5473
- /**
5474
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
5475
- * an error that makes the instance fail immediately without triggering a retry.
5476
- */
5477
- export declare class NonRetryableError extends Error {
5478
- // __brand has been explicity omitted because it's a internal brand used for
5479
- // the Workflows' engine and user's shouldn't be able to override it
5480
- // (at least, in a direct way)
5481
- public constructor(message: string, name?: string);
5487
+ export declare abstract class Workflow {
5488
+ /**
5489
+ * Get a handle to an existing instance of the Workflow.
5490
+ * @param id Id for the instance of this Workflow
5491
+ * @returns A promise that resolves with a handle for the Instance
5492
+ */
5493
+ public get(id: string): Promise<Instance>;
5494
+ /**
5495
+ * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
5496
+ * @param id Id to create the instance of this Workflow with
5497
+ * @param params The payload to send over to this instance
5498
+ * @returns A promise that resolves with a handle for the Instance
5499
+ */
5500
+ public create(id: string, params: object): Promise<Instance>;
5501
+ }
5502
+ export type InstanceStatus = {
5503
+ status:
5504
+ | "queued"
5505
+ | "running"
5506
+ | "paused"
5507
+ | "errored"
5508
+ | "terminated"
5509
+ | "complete"
5510
+ | "unknown";
5511
+ error?: string;
5512
+ output?: object;
5513
+ };
5514
+ export interface WorkflowError {
5515
+ code?: number;
5516
+ message: string;
5517
+ }
5518
+ export declare abstract class Instance {
5519
+ public id: string;
5520
+ /**
5521
+ * Pause the instance.
5522
+ */
5523
+ public pause(): Promise<void>;
5524
+ /**
5525
+ * Resume the instance. If it is already running, an error will be thrown.
5526
+ */
5527
+ public resume(): Promise<void>;
5528
+ /**
5529
+ * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
5530
+ */
5531
+ public abort(): Promise<void>;
5532
+ /**
5533
+ * Restart the instance.
5534
+ */
5535
+ public restart(): Promise<void>;
5536
+ /**
5537
+ * Returns the current status of the instance.
5538
+ */
5539
+ public status(): Promise<InstanceStatus>;
5482
5540
  }