Skip to content
Draft
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
199 changes: 4 additions & 195 deletions example/convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @module
*/

import { ComponentApi } from "../../../src/client/types.js";
import type * as admin from "../admin.js";
import type * as example from "../example.js";
import type * as transcription from "../transcription.js";
Expand Down Expand Up @@ -43,199 +44,7 @@ export declare const internal: FilterApi<
>;

export declare const components: {
workflow: {
journal: {
load: FunctionReference<
"query",
"internal",
{ workflowId: string },
{
journalEntries: Array<{
_creationTime: number;
_id: string;
step: {
args: any;
argsSize: number;
completedAt?: number;
functionType: "query" | "mutation" | "action";
handle: string;
inProgress: boolean;
name: string;
runResult?:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
startedAt: number;
workId?: string;
};
stepNumber: number;
workflowId: string;
}>;
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
ok: boolean;
workflow: {
_creationTime: number;
_id: string;
args: any;
generationNumber: number;
logLevel?: any;
name?: string;
onComplete?: { context?: any; fnHandle: string };
runResult?:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
startedAt?: any;
state?: any;
workflowHandle: string;
};
}
>;
startSteps: FunctionReference<
"mutation",
"internal",
{
generationNumber: number;
steps: Array<{
retry?:
| boolean
| { base: number; initialBackoffMs: number; maxAttempts: number };
schedulerOptions?: { runAt?: number } | { runAfter?: number };
step: {
args: any;
argsSize: number;
completedAt?: number;
functionType: "query" | "mutation" | "action";
handle: string;
inProgress: boolean;
name: string;
runResult?:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
startedAt: number;
workId?: string;
};
}>;
workflowId: string;
workpoolOptions?: {
defaultRetryBehavior?: {
base: number;
initialBackoffMs: number;
maxAttempts: number;
};
logLevel?: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
maxParallelism?: number;
retryActionsByDefault?: boolean;
};
},
Array<{
_creationTime: number;
_id: string;
step: {
args: any;
argsSize: number;
completedAt?: number;
functionType: "query" | "mutation" | "action";
handle: string;
inProgress: boolean;
name: string;
runResult?:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
startedAt: number;
workId?: string;
};
stepNumber: number;
workflowId: string;
}>
>;
};
workflow: {
cancel: FunctionReference<
"mutation",
"internal",
{ workflowId: string },
null
>;
cleanup: FunctionReference<
"mutation",
"internal",
{ workflowId: string },
boolean
>;
complete: FunctionReference<
"mutation",
"internal",
{
generationNumber: number;
runResult:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
workflowId: string;
},
null
>;
create: FunctionReference<
"mutation",
"internal",
{
maxParallelism?: number;
onComplete?: { context?: any; fnHandle: string };
startAsync?: boolean;
workflowArgs: any;
workflowHandle: string;
workflowName: string;
},
string
>;
getStatus: FunctionReference<
"query",
"internal",
{ workflowId: string },
{
inProgress: Array<{
_creationTime: number;
_id: string;
step: {
args: any;
argsSize: number;
completedAt?: number;
functionType: "query" | "mutation" | "action";
handle: string;
inProgress: boolean;
name: string;
runResult?:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
startedAt: number;
workId?: string;
};
stepNumber: number;
workflowId: string;
}>;
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
workflow: {
_creationTime: number;
_id: string;
args: any;
generationNumber: number;
logLevel?: any;
name?: string;
onComplete?: { context?: any; fnHandle: string };
runResult?:
| { kind: "success"; returnValue: any }
| { error: string; kind: "failed" }
| { kind: "canceled" };
startedAt?: any;
state?: any;
workflowHandle: string;
};
}
>;
};
};
workflow: ComponentApi<
typeof import("../../../src/component/_generated/api.js").api
>;
};
4 changes: 2 additions & 2 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { ObjectType, PropertyValidators, Validator } from "convex/values";
import type { Step } from "../component/schema.js";
import type { OnCompleteArgs, WorkflowId } from "../types.js";
import { safeFunctionName } from "./safeFunctionName.js";
import type { OpaqueIds, WorkflowComponent, WorkflowStep } from "./types.js";
import type { WorkflowComponent, WorkflowStep } from "./types.js";
import { workflowMutation } from "./workflowMutation.js";

export { vWorkflowId, type WorkflowId } from "../types.js";
Expand Down Expand Up @@ -71,7 +71,7 @@ export type WorkflowDefinition<
};

export type WorkflowStatus =
| { type: "inProgress"; running: OpaqueIds<Step>[] }
| { type: "inProgress"; running: Step[] }
| { type: "completed" }
| { type: "canceled" }
| { type: "failed"; error: string };
Expand Down
34 changes: 15 additions & 19 deletions src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { RetryOption, WorkId } from "@convex-dev/workpool";
import type { RetryOption } from "@convex-dev/workpool";
import type {
Expand,
FunctionArgs,
FunctionReference,
FunctionReturnType,
} from "convex/server";
import type { api } from "../component/_generated/api.js";
import type { GenericId } from "convex/values";
import type { GenericId, Value } from "convex/values";
import type { WorkflowId } from "../types.js";

export type WorkflowComponent = UseApi<typeof api>;
export type WorkflowComponent = ComponentApi<typeof api>;

export type RunOptions = {
/**
Expand Down Expand Up @@ -83,31 +83,27 @@ export type WorkflowStep = {
): Promise<FunctionReturnType<Action>>;
};

export type UseApi<API> = Expand<{
export type ComponentApi<API> = Expand<{
[mod in keyof API]: API[mod] extends FunctionReference<
infer FType,
"public",
infer FArgs,
infer FReturnType,
infer FComponentPath
infer FReturnType
>
? FunctionReference<
FType,
"internal",
OpaqueIds<FArgs>,
OpaqueIds<FReturnType>,
FComponentPath
StringifyIds<FArgs>,
StringifyIds<FReturnType>
>
: UseApi<API[mod]>;
: ComponentApi<API[mod]>;
}>;

export type OpaqueIds<T> =
T extends GenericId<infer _T>
export type StringifyIds<T> =
T extends GenericId<string>
? string
: T extends WorkId
? string
: T extends (infer U)[]
? OpaqueIds<U>[]
: T extends object
? { [K in keyof T]: OpaqueIds<T[K]> }
: T;
: T extends (infer U)[]
? StringifyIds<U>[]
: T extends Record<string, Value | undefined>
? { [K in keyof T]: StringifyIds<T[K]> }
: T;
90 changes: 4 additions & 86 deletions src/component/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @module
*/

import type { ComponentApi } from "../../client/types.ts";
import type * as journal from "../journal.js";
import type * as logging from "../logging.js";
import type * as model from "../model.js";
Expand Down Expand Up @@ -247,90 +248,7 @@ export declare const internal: FilterApi<
>;

export declare const components: {
workpool: {
lib: {
cancel: FunctionReference<
"mutation",
"internal",
{
id: string;
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
},
any
>;
cancelAll: FunctionReference<
"mutation",
"internal",
{
before?: number;
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
},
any
>;
enqueue: FunctionReference<
"mutation",
"internal",
{
config: {
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
maxParallelism: number;
};
fnArgs: any;
fnHandle: string;
fnName: string;
fnType: "action" | "mutation" | "query";
onComplete?: { context?: any; fnHandle: string };
retryBehavior?: {
base: number;
initialBackoffMs: number;
maxAttempts: number;
};
runAt: number;
},
string
>;
enqueueBatch: FunctionReference<
"mutation",
"internal",
{
config: {
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
maxParallelism: number;
};
items: Array<{
fnArgs: any;
fnHandle: string;
fnName: string;
fnType: "action" | "mutation" | "query";
onComplete?: { context?: any; fnHandle: string };
retryBehavior?: {
base: number;
initialBackoffMs: number;
maxAttempts: number;
};
runAt: number;
}>;
},
Array<string>
>;
status: FunctionReference<
"query",
"internal",
{ id: string },
| { previousAttempts: number; state: "pending" }
| { previousAttempts: number; state: "running" }
| { state: "finished" }
>;
statusBatch: FunctionReference<
"query",
"internal",
{ ids: Array<string> },
Array<
| { previousAttempts: number; state: "pending" }
| { previousAttempts: number; state: "running" }
| { state: "finished" }
>
>;
};
};
workpool: ComponentApi<
typeof import("../../../node_modules/@convex-dev/workpool/dist/component/_generated/api.js").api
>;
};
Loading