@cloudflare/workers-types
4.20240909.04.20240919.0
2022-11-30/index.d.ts~
2022-11-30/index.d.tsModified+84−20
Index: package/2022-11-30/index.d.ts
===================================================================
--- package/2022-11-30/index.d.ts
+++ package/2022-11-30/index.d.ts
@@ -1545,9 +1545,13 @@
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
*/
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;
@@ -1572,9 +1576,9 @@
status?: number;
statusText?: string;
headers?: HeadersInit;
cf?: any;
- webSocket?: WebSocket | null;
+ webSocket?: WebSocket;
encodeBody?: "automatic" | "manual";
}
type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> =
| Request<CfHostMetadata, Cf>
@@ -2280,17 +2284,17 @@
get writable(): WritableStream<I>;
}
declare class FixedLengthStream extends IdentityTransformStream {
constructor(
- param1: number | bigint,
- param2?: IdentityTransformStreamQueuingStrategy,
+ expectedLength: number | bigint,
+ queuingStrategy?: IdentityTransformStreamQueuingStrategy,
);
}
declare class IdentityTransformStream extends TransformStream<
ArrayBuffer | ArrayBufferView,
Uint8Array
> {
- constructor(param1?: IdentityTransformStreamQueuingStrategy);
+ constructor(queuingStrategy?: IdentityTransformStreamQueuingStrategy);
}
interface IdentityTransformStreamQueuingStrategy {
highWaterMark?: number | bigint;
}
@@ -2766,23 +2770,26 @@
1: WebSocket;
};
};
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;
}
declare abstract class SqlStorageStatement {}
-declare abstract class SqlStorageCursor {
- raw(): IterableIterator<((ArrayBuffer | string | number) | null)[]>;
+type SqlStorageValue = ArrayBuffer | string | number | null;
+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>;
}
interface Socket {
get readable(): ReadableStream;
get writable(): WritableStream;
@@ -3319,9 +3326,9 @@
y?: number;
z?: number;
}
/* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource) */
-declare class EventSource {
+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.
*
@@ -5584,13 +5591,70 @@
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.
+ * NonRetryableError allows for a user to throw a fatal error
+ * that makes a Workflow instance fail immediately without triggering a retry
*/
-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);
+declare module "cloudflare:workflows" {
+ export abstract class NonRetryableError extends Error {
+ /**
+ * `__brand` is used to differentiate between `NonRetryableError` and `Error`
+ * and is omitted from the constructor because users should not set it
+ */
+ public constructor(message: string, name?: string);
+ }
}
+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>;
+}
+type InstanceStatus = {
+ status:
+ | "queued"
+ | "running"
+ | "paused"
+ | "errored"
+ | "terminated"
+ | "complete"
+ | "unknown";
+ error?: string;
+ output?: object;
+};
+interface WorkflowError {
+ code?: number;
+ message: string;
+}
+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>;
+}