@cloudflare/workers-types

4.20240909.04.20240919.0
2022-01-31/index.ts
~2022-01-31/index.tsModified
+73−22
Index: package/2022-01-31/index.ts
===================================================================
--- package/2022-01-31/index.ts
+++ package/2022-01-31/index.ts
@@ -1528,9 +1528,13 @@
  *
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
  */
 export declare class Response extends Body {
-  constructor(body?: BodyInit | null, init?: ResponseInit);
+  constructor(
+    body?: BodyInit | null,
+    init?: ResponseInit,
+    webSocket?: WebSocket,
+  );
   /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/redirect_static) */
   static redirect(url: string, status?: number): Response;
   /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/json_static) */
   static json(any: any, maybeInit?: ResponseInit | Response): Response;
@@ -1555,9 +1559,9 @@
   status?: number;
   statusText?: string;
   headers?: HeadersInit;
   cf?: any;
-  webSocket?: WebSocket | null;
+  webSocket?: WebSocket;
   encodeBody?: "automatic" | "manual";
 }
 export type RequestInfo<
   CfHostMetadata = unknown,
@@ -2263,17 +2267,17 @@
   get writable(): WritableStream<I>;
 }
 export declare class FixedLengthStream extends IdentityTransformStream {
   constructor(
-    param1: number | bigint,
-    param2?: IdentityTransformStreamQueuingStrategy,
+    expectedLength: number | bigint,
+    queuingStrategy?: IdentityTransformStreamQueuingStrategy,
   );
 }
 export declare class IdentityTransformStream extends TransformStream<
   ArrayBuffer | ArrayBufferView,
   Uint8Array
 > {
-  constructor(param1?: IdentityTransformStreamQueuingStrategy);
+  constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
 }
 export interface IdentityTransformStreamQueuingStrategy {
   highWaterMark?: number | bigint;
 }
@@ -2753,23 +2757,26 @@
     1: WebSocket;
   };
 };
 export interface SqlStorage {
-  exec(query: string, ...bindings: any[]): SqlStorageCursor;
-  prepare(query: string): SqlStorageStatement;
+  exec<T extends Record<string, SqlStorageValue>>(
+    query: string,
+    ...bindings: any[]
+  ): SqlStorageCursor<T>;
   get databaseSize(): number;
   Cursor: typeof SqlStorageCursor;
   Statement: typeof SqlStorageStatement;
 }
 export declare abstract class SqlStorageStatement {}
-export declare abstract class SqlStorageCursor {
-  raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
+export type SqlStorageValue = ArrayBuffer | string | number | null;
+export declare abstract class SqlStorageCursor<
+  T extends Record<string, SqlStorageValue>,
+> {
+  raw<U extends SqlStorageValue[]>(): IterableIterator<U>;
   get columnNames(): string[];
   get rowsRead(): number;
   get rowsWritten(): number;
-  [Symbol.iterator](): IterableIterator<
-    Record<string, (ArrayBuffer | string | number) | null>
-  >;
+  [Symbol.iterator](): IterableIterator<T>;
 }
 export interface Socket {
   get readable(): ReadableStream;
   get writable(): WritableStream;
@@ -3299,9 +3306,9 @@
   y?: number;
   z?: number;
 }
 /* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
-export declare class EventSource {
+export declare class EventSource extends EventTarget {
   constructor(url: string, init?: EventSourceEventSourceInit);
   /**
    * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
    *
@@ -5469,14 +5476,58 @@
     },
     options?: DynamicDispatchOptions,
   ): Fetcher;
 }
-/**
- * NonRetryableError allows for a Workflow to throw a "fatal" error as in,
- * an error that makes the instance fail immediately without triggering a retry.
- */
-export declare class NonRetryableError extends Error {
-  // __brand has been explicity omitted because it's a internal brand used for
-  // the Workflows' engine and user's shouldn't be able to override it
-  // (at least, in a direct way)
-  public constructor(message: string, name?: string);
+export declare abstract class Workflow {
+  /**
+   * Get a handle to an existing instance of the Workflow.
+   * @param id Id for the instance of this Workflow
+   * @returns A promise that resolves with a handle for the Instance
+   */
+  public get(id: string): Promise<Instance>;
+  /**
+   * Create a new instance and return a handle to it. If a provided id exists, an error will be thrown.
+   * @param id Id to create the instance of this Workflow with
+   * @param params The payload to send over to this instance
+   * @returns A promise that resolves with a handle for the Instance
+   */
+  public create(id: string, params: object): Promise<Instance>;
 }
+export type InstanceStatus = {
+  status:
+    | "queued"
+    | "running"
+    | "paused"
+    | "errored"
+    | "terminated"
+    | "complete"
+    | "unknown";
+  error?: string;
+  output?: object;
+};
+export interface WorkflowError {
+  code?: number;
+  message: string;
+}
+export declare abstract class Instance {
+  public id: string;
+  /**
+   * Pause the instance.
+   */
+  public pause(): Promise<void>;
+  /**
+   * Resume the instance. If it is already running, an error will be thrown.
+   */
+  public resume(): Promise<void>;
+  /**
+   * Abort the instance. If it is errored, terminated or complete, an error will be thrown.
+   */
+  public abort(): Promise<void>;
+  /**
+   * Restart the instance.
+   */
+  public restart(): Promise<void>;
+  /**
+   * Returns the current status of the instance.
+   */
+  public status(): Promise<InstanceStatus>;
+}