@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.
package/oldest/index.d.ts CHANGED
@@ -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
  }
package/oldest/index.ts CHANGED
@@ -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
  }
package/package.json CHANGED
@@ -7,5 +7,5 @@
7
7
  },
8
8
  "author": "Cloudflare Workers DevProd Team <workers-devprod@cloudflare.com> (https://workers.cloudflare.com)",
9
9
  "license": "MIT OR Apache-2.0",
10
- "version": "4.20240909.0"
10
+ "version": "4.20240924.0"
11
11
  }