Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
cache: "pnpm"

- run: pnpm install
- name: Check worker types are up to date
run: pnpm run generate-types:check
- run: pnpm run typecheck
- run: pnpm run lint
- run: pnpm run format:check
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"deploy": "wrangler deploy --minify --env production",
"dev:miniflare": "wrangler dev --env dev --port 9999 --live-reload",
"generate-types": "wrangler types --config test/wrangler.test.jsonc --include-env=false",
"typecheck": "pnpm run generate-types && tsc --noEmit && tsc --noEmit --project test/tsconfig.json && tsc --noEmit --project push/tsconfig.json",
"generate-types:check": "wrangler types --config test/wrangler.test.jsonc --include-env=false --check",
"typecheck": "tsc --noEmit && tsc --noEmit --project test/tsconfig.json && tsc --noEmit --project push/tsconfig.json",
"lint": "eslint .",
"format": "prettier --write .",
"format:check": "prettier --check .",
Expand Down
134 changes: 121 additions & 13 deletions worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
// Runtime types generated with workerd@1.20260730.1 2024-09-09 nodejs_compat
// Runtime types generated with workerd@1.20260811.1 2024-09-09 nodejs_compat
// Begin runtime types
/*! *****************************************************************************
Copyright (c) Cloudflare. All rights reserved.
Expand Down Expand Up @@ -422,6 +422,7 @@ interface ExecutionContext<Props = unknown> {
cache?: CacheContext;
readonly access?: CloudflareAccessContext;
tracing: Tracing;
abort(reason?: any): void;
}
type ExportedHandlerFetchHandler<Env = unknown, CfHostMetadata = unknown, Props = unknown> = (request: Request<CfHostMetadata, IncomingRequestCfProperties<CfHostMetadata>>, env: Env, ctx: ExecutionContext<Props>) => Response | Promise<Response>;
type ExportedHandlerConnectHandler<Env = unknown, Props = unknown> = (socket: Socket, env: Env, ctx: ExecutionContext<Props>) => void | Promise<void>;
Expand Down Expand Up @@ -2744,6 +2745,12 @@ interface TraceLog {
readonly timestamp: number;
readonly level: string;
readonly message: any;
readonly errorInfo?: (TraceLogErrorInfo | null)[];
}
interface TraceLogErrorInfo {
name: string;
message: string;
stack?: string;
}
interface TraceException {
readonly timestamp: number;
Expand Down Expand Up @@ -3283,18 +3290,26 @@ interface ContainerExecOptions {
cwd?: string;
env?: Record<string, string>;
user?: string;
signal?: AbortSignal;
pty?: boolean | ContainerExecPtyOptions;
stdin?: ReadableStream | "pipe";
stdout?: "pipe" | "ignore";
stderr?: "pipe" | "ignore" | "combined";
}
interface ContainerExecPtyOptions {
cols?: number;
rows?: number;
}
interface ExecProcess {
readonly stdin: WritableStream | null;
readonly stdout: ReadableStream | null;
readonly stderr: ReadableStream | null;
readonly pid: number;
readonly isPty: boolean;
readonly exitCode: Promise<number>;
output(): Promise<ExecOutput>;
kill(signal?: number): void;
resize(cols: number, rows: number): void;
}
interface Container {
get running(): boolean;
Expand Down Expand Up @@ -3341,6 +3356,11 @@ interface ContainerStartupOptions {
directorySnapshots?: ContainerDirectorySnapshotRestoreParams[];
containerSnapshot?: ContainerSnapshot;
}
interface ContainerStartResources {
vcpu: number;
memoryMib: number;
diskMb: number;
}
/**
* The **`MessagePort`** interface of the Channel Messaging API represents one of the two ports of a MessageChannel, allowing messages to be sent from one port and listening out for them arriving at the other.
*
Expand Down Expand Up @@ -3461,11 +3481,13 @@ declare abstract class Performance {
interface Tracing {
enterSpan<T, A extends unknown[]>(name: string, callback: (span: Span, ...args: A) => T, ...args: A): T;
startActiveSpan<T, A extends unknown[]>(name: string, callback: (span: Span, ...args: A) => T, ...args: A): T;
startSpan(name: string): Span;
Span: typeof Span;
}
declare abstract class Span {
get isTraced(): boolean;
setAttribute(key: string, value?: (boolean | number | string)): void;
setAttribute(key: string, value: boolean | number | string): this;
setAttributes(attributes: Record<string, boolean | number | string | undefined>): this;
end(): void;
}
/**
Expand Down Expand Up @@ -4105,6 +4127,13 @@ type AiSearchListItemsParams = {
source?: string;
/** JSON-encoded Vectorize filter for metadata filtering. */
metadata_filter?: string;
/** Filter items by their unique ID. Returns at most one item. */
item_id?: string;
/**
* Filter items by their exact key (object key / filename). Keys are unique
* per source, so combine with `source` to disambiguate across data sources.
*/
key?: string;
};
type AiSearchListItemsResponse = {
result: AiSearchItemInfo[];
Expand Down Expand Up @@ -12393,6 +12422,15 @@ interface Hyperdrive {
* for your database.
*/
readonly host: string;
/*
* A synthetic IPv4 address (in the reserved 240.0.0.0/4 range) that, like the
* host field, is only valid within the context of the currently running
* Worker and, when passed into the `connect()` function from the
* "cloudflare:sockets" module, will connect to the Hyperdrive instance for
* your database. This is provided for database drivers that require the host
* to be an IP literal rather than a hostname.
*/
readonly ip: string;
/*
* The port that must be paired the the host field when connecting.
*/
Expand Down Expand Up @@ -13079,6 +13117,26 @@ declare namespace CloudflareWorkersModule {
timeout?: WorkflowTimeoutDuration | number;
sensitive?: WorkflowStepSensitivity;
};
// Internal discriminators used only for `WorkflowStep.do` overload
// resolution. They mirror `WorkflowStepConfig` but pin `retries.delay` to a
// single kind so the callback context can be narrowed based on the shape of
// the config argument (rather than on an inferred type parameter, which is
// lost when the caller supplies an explicit return-type argument). Not
// exported: they must not widen the public type surface.
type WorkflowStepConfigWithStaticDelay = Omit<WorkflowStepConfig, 'retries'> & {
retries?: {
limit: number;
delay: WorkflowDelayDuration | number;
backoff?: WorkflowBackoff;
};
};
type WorkflowStepConfigWithDelayFunction = Omit<WorkflowStepConfig, 'retries'> & {
retries: {
limit: number;
delay: WorkflowDelayFunction;
backoff?: WorkflowBackoff;
};
};
export type WorkflowStepRollbackConfig = Pick<WorkflowStepConfig, 'retries' | 'timeout'>;
export type WorkflowCronSchedule = {
/** Cron expression that triggered this event. */
Expand Down Expand Up @@ -13116,23 +13174,35 @@ declare namespace CloudflareWorkersModule {
sensitive?: WorkflowStepSensitivity;
};
};
export type WorkflowRollbackContext<T = unknown> = {
ctx: WorkflowStepContext;
// The rollback handler receives the step context, so it mirrors the same
// delay discriminant as the step callback: when the step was configured with
// a dynamic delay function the resolved `config.retries.delay` is omitted,
// otherwise it is present. `Delay` is threaded from the `WorkflowStep.do`
// overload that matched the step config.
export type WorkflowRollbackContext<T = unknown, Delay = WorkflowDelayDuration | number> = {
ctx: WorkflowStepContext<Delay>;
error: Error;
output: T | undefined;
/** @deprecated Use `ctx.step.name` and `ctx.step.count` instead. */
stepName: string;
};
export type WorkflowRollbackHandler<T = unknown> = (ctx: WorkflowRollbackContext<T>) => Promise<void>;
export type WorkflowStepRollbackOptions<T = unknown> = {
rollback: WorkflowRollbackHandler<T>;
export type WorkflowRollbackHandler<T = unknown, Delay = WorkflowDelayDuration | number> = (ctx: WorkflowRollbackContext<T, Delay>) => Promise<void>;
export type WorkflowStepRollbackOptions<T = unknown, Delay = WorkflowDelayDuration | number> = {
rollback: WorkflowRollbackHandler<T, Delay>;
rollbackConfig?: WorkflowStepRollbackConfig;
};
export abstract class WorkflowStep {
do<T extends Rpc.Serializable<T>>(name: string, callback: (ctx: WorkflowStepContext) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
do<T extends Rpc.Serializable<T>, const C extends WorkflowStepConfig>(name: string, config: C, callback: (ctx: WorkflowStepContext<C['retries'] extends {
delay: infer D;
} ? D : WorkflowDelayDuration | number>) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
// The config overloads discriminate on the shape of `config.retries.delay`
// so the callback context reflects whether the resolved delay is present
// (static delay) or omitted (dynamic delay function). Each has a single
// type parameter, so an explicit return-type argument (`do<T>(...)`) still
// resolves here. ORDERING IS LOAD-BEARING: the broad `WorkflowStepConfig`
// fallback MUST remain last, otherwise it shadows the discriminating
// overloads and narrowing is silently lost.
do<T extends Rpc.Serializable<T>>(name: string, config: WorkflowStepConfigWithDelayFunction, callback: (ctx: WorkflowStepContext<WorkflowDelayFunction>) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T, WorkflowDelayFunction>): Promise<T>;
do<T extends Rpc.Serializable<T>>(name: string, config: WorkflowStepConfigWithStaticDelay, callback: (ctx: WorkflowStepContext<WorkflowDelayDuration | number>) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T, WorkflowDelayDuration | number>): Promise<T>;
do<T extends Rpc.Serializable<T>>(name: string, config: WorkflowStepConfig, callback: (ctx: WorkflowStepContext) => Promise<T>, rollbackOptions?: WorkflowStepRollbackOptions<T>): Promise<T>;
sleep: (name: string, duration: WorkflowSleepDuration) => Promise<void>;
sleepUntil: (name: string, timestamp: Date | number) => Promise<void>;
waitForEvent<T extends Rpc.Serializable<T>>(name: string, options: {
Expand Down Expand Up @@ -13907,11 +13977,12 @@ type MarkdownDocument = {
name: string;
blob: Blob;
};
type OutputFormat = 'markdown' | 'text';
type ConversionResponse = {
id: string;
name: string;
mimeType: string;
format: 'markdown';
format: OutputFormat;
tokens: number;
data: string;
} | {
Expand All @@ -13928,7 +13999,11 @@ type EmbeddedImageConversionOptions = ImageConversionOptions & {
convert?: boolean;
maxConvertedImages?: number;
};
type ConversionOutputOptions = {
format?: OutputFormat;
};
type ConversionOptions = {
output?: ConversionOutputOptions;
html?: {
images?: EmbeddedImageConversionOptions & {
convertOGImage?: boolean;
Expand Down Expand Up @@ -14077,11 +14152,22 @@ declare namespace TailStream {
readonly message: string;
readonly stack?: string;
}
interface Log {
interface TailStreamErrorInfo {
readonly name: string;
readonly message: string;
readonly stack?: string;
}
type Log = {
readonly type: "log";
readonly level: "debug" | "error" | "info" | "log" | "warn";
readonly errorInfo?: readonly (TailStreamErrorInfo | null)[];
} & ({
readonly message: object;
}
readonly truncated?: false;
} | {
readonly message: string;
readonly truncated: true;
});
interface DroppedEventsDiagnostic {
readonly diagnosticsType: "droppedEvents";
readonly count: number;
Expand Down Expand Up @@ -14559,7 +14645,25 @@ declare abstract class Workflow<PARAMS = unknown> {
* @returns A promise that resolves with a list of handles for the created instances.
*/
public createBatch(batch: WorkflowInstanceCreateOptions<PARAMS>[]): Promise<WorkflowInstance[]>;
/**
* Delete a batch of Workflow instances and their stored state.
* `deleteBatch` is limited to 100 instances at a time. Duplicate IDs are deleted once.
* The result contains one entry for each input position; IDs that do not exist are returned as per-instance errors.
* @param instanceIds IDs of the Workflow instances to delete
* @returns A promise that resolves with the successfully deleted instances and any per-instance errors.
*/
public deleteBatch(instanceIds: string[]): Promise<WorkflowBatchDeleteResult>;
}
type WorkflowBatchDeleteResult = {
deleted: {
id: string;
}[];
errors: {
id: string;
code: number;
message: string;
}[];
};
type WorkflowDurationLabel = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year';
type WorkflowSleepDuration = `${number} ${WorkflowDurationLabel}${'s' | ''}` | number;
type WorkflowRetentionDuration = WorkflowSleepDuration;
Expand Down Expand Up @@ -14646,6 +14750,10 @@ declare abstract class WorkflowInstance {
* @param options Options for the restart, including an optional step to restart from.
*/
public restart(options?: WorkflowInstanceRestartOptions): Promise<void>;
/**
* Delete the instance and its stored state.
*/
public delete(): Promise<void>;
/**
* Returns the current status of the instance.
*/
Expand Down