pg-workflows 0.9.0 → 0.10.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/dist/client.entry.cjs +48 -12
- package/dist/client.entry.d.cts +37 -10
- package/dist/client.entry.d.ts +37 -10
- package/dist/client.entry.js +1 -1
- package/dist/client.entry.js.map +8 -8
- package/dist/index.cjs +369 -83
- package/dist/index.d.cts +68 -20
- package/dist/index.d.ts +68 -20
- package/dist/index.js +326 -73
- package/dist/index.js.map +10 -10
- package/dist/shared/{chunk-fr76gdwj.js → chunk-nygamc7b.js} +50 -14
- package/dist/shared/chunk-nygamc7b.js.map +16 -0
- package/package.json +1 -1
- package/dist/shared/chunk-fr76gdwj.js.map +0 -16
package/dist/index.js.map
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["src/client.ts", "src/constants.ts", "src/db/migration.ts", "src/db/queries.ts", "src/error.ts", "src/types.ts", "src/definition.ts", "src/duration.ts", "src/engine.ts", "src/ast-parser.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { merge } from 'es-toolkit';\nimport pg from 'pg';\nimport { type Db, PgBoss } from 'pg-boss';\nimport { DEFAULT_PGBOSS_SCHEMA, PAUSE_EVENT_NAME, WORKFLOW_RUN_QUEUE_NAME } from './constants';\nimport { runMigrations } from './db/migration';\nimport {\n getWorkflowRun,\n getWorkflowRuns,\n insertWorkflowRun,\n updateWorkflowRun,\n withPostgresTransaction,\n} from './db/queries';\nimport type { WorkflowRun } from './db/types';\nimport {\n validateResourceId,\n validateWorkflowId,\n WorkflowEngineError,\n WorkflowRunNotFoundError,\n} from './error';\nimport {\n type InferInputParameters,\n type InputParameters,\n type WorkflowLogger,\n type WorkflowRef,\n type WorkflowRunProgress,\n WorkflowStatus,\n} from './types';\n\nconst LOG_PREFIX = '[WorkflowClient]';\n\ntype WorkflowRunJobParameters = {\n runId: string;\n resourceId?: string;\n workflowId: string;\n input: unknown;\n event?: {\n name: string;\n data?: Record<string, unknown>;\n };\n};\n\nexport type WorkflowClientOptions = {\n logger?: WorkflowLogger;\n /**\n * Pre-configured pg-boss instance. Pass this when the engine side uses a\n * non-default pg-boss config (schema, retention, logger, etc.) so the\n * client enqueues jobs where the engine reads them. Mirrors the same\n * option on `WorkflowEngineOptions`.\n */\n boss?: PgBoss;\n} & ({ pool: pg.Pool; connectionString?: never } | { connectionString: string; pool?: never });\n\nexport type StartWorkflowOptions = {\n resourceId?: string;\n timeout?: number;\n retries?: number;\n expireInSeconds?: number;\n idempotencyKey?: string;\n};\n\nconst defaultLogger: WorkflowLogger = {\n log: (_message: string) => console.warn(_message),\n error: (message: string, error: Error) => console.error(message, error),\n};\n\nconst defaultExpireInSeconds = process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS, 10)\n : 5 * 60;\n\nexport class WorkflowClient {\n private boss: PgBoss;\n private db: Db;\n private pool: pg.Pool;\n private _ownsPool = false;\n private _started = false;\n private logger: WorkflowLogger;\n\n constructor({ logger, boss, ...connectionOptions }: WorkflowClientOptions) {\n this.logger = logger ?? defaultLogger;\n\n if ('pool' in connectionOptions && connectionOptions.pool) {\n this.pool = connectionOptions.pool;\n } else if ('connectionString' in connectionOptions && connectionOptions.connectionString) {\n this.pool = new pg.Pool({ connectionString: connectionOptions.connectionString });\n this._ownsPool = true;\n } else {\n throw new WorkflowEngineError('Either pool or connectionString must be provided');\n }\n\n const db: Db = {\n executeSql: (text: string, values?: unknown[]) =>\n this.pool.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n\n if (boss) {\n this.boss = boss;\n } else {\n this.boss = new PgBoss({ db, schema: DEFAULT_PGBOSS_SCHEMA });\n }\n this.db = db;\n }\n\n async start(): Promise<void> {\n if (this._started) {\n return;\n }\n\n await this.boss.start();\n this.db = this.boss.getDb();\n await runMigrations(this.db);\n await this.boss.createQueue(WORKFLOW_RUN_QUEUE_NAME);\n\n this._started = true;\n this.logger.log(`${LOG_PREFIX} Client started`);\n }\n\n async stop(): Promise<void> {\n await this.boss.stop();\n\n if (this._ownsPool) {\n await this.pool.end();\n }\n\n this._started = false;\n this.logger.log(`${LOG_PREFIX} Client stopped`);\n }\n\n async startWorkflow<TInput extends InputParameters>(\n ref: WorkflowRef<TInput>,\n input: InferInputParameters<TInput>,\n options?: StartWorkflowOptions,\n ): Promise<WorkflowRun>;\n\n async startWorkflow(params: {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n }): Promise<WorkflowRun>;\n\n async startWorkflow<TInput extends InputParameters>(\n refOrParams:\n | WorkflowRef<TInput>\n | {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n },\n inputArg?: InferInputParameters<TInput>,\n optionsArg?: StartWorkflowOptions,\n ): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n let workflowId: string;\n let input: unknown;\n let resourceId: string | undefined;\n let idempotencyKey: string | undefined;\n let options: StartWorkflowOptions | undefined;\n\n if (typeof refOrParams === 'function' && 'id' in refOrParams) {\n const ref = refOrParams as WorkflowRef<TInput>;\n workflowId = ref.id;\n input = inputArg;\n options = optionsArg;\n resourceId = optionsArg?.resourceId;\n idempotencyKey = optionsArg?.idempotencyKey;\n\n if (ref.inputSchema) {\n const result = await ref.inputSchema['~standard'].validate(input);\n if (result.issues) {\n throw new WorkflowEngineError(\n JSON.stringify(result.issues),\n workflowId,\n undefined,\n undefined,\n result.issues,\n );\n }\n }\n } else {\n const params = refOrParams as {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n };\n workflowId = params.workflowId;\n input = params.input;\n resourceId = params.resourceId;\n idempotencyKey = params.idempotencyKey;\n options = params.options;\n }\n\n validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n const run = await withPostgresTransaction(\n this.db,\n async (_db) => {\n const timeoutAt = options?.timeout ? new Date(Date.now() + options.timeout) : null;\n\n const { run: insertedRun, created } = await insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId: '__start__',\n status: WorkflowStatus.RUNNING,\n input,\n maxRetries: options?.retries ?? 0,\n timeoutAt,\n idempotencyKey,\n },\n _db,\n );\n\n if (created) {\n const job: WorkflowRunJobParameters = {\n runId: insertedRun.id,\n resourceId,\n workflowId,\n input,\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: new Date(),\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n }\n\n return insertedRun;\n },\n this.pool,\n );\n\n this.logger.log(`${LOG_PREFIX} Started workflow run ${run.id} for ${workflowId}`);\n\n return run;\n }\n\n async triggerEvent({\n runId,\n resourceId,\n eventName,\n data,\n options,\n }: {\n runId: string;\n resourceId?: string;\n eventName: string;\n data?: Record<string, unknown>;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: resourceId ?? run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: {\n name: eventName,\n data,\n },\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n\n this.logger.log(`${LOG_PREFIX} Event ${eventName} sent for workflow run ${runId}`);\n return run;\n }\n\n async pauseWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await updateWorkflowRun(\n {\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.PAUSED,\n pausedAt: new Date(),\n },\n expectedStatuses: [WorkflowStatus.RUNNING, WorkflowStatus.PENDING],\n },\n this.db,\n );\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n this.logger.log(`${LOG_PREFIX} Paused workflow run ${runId}`);\n return run;\n }\n\n async resumeWorkflow({\n runId,\n resourceId,\n options,\n }: {\n runId: string;\n resourceId?: string;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const current = await this.getRun({ runId, resourceId });\n if (current.status !== WorkflowStatus.PAUSED) {\n throw new WorkflowEngineError(\n `Cannot resume workflow run in '${current.status}' status, must be 'paused'`,\n current.workflowId,\n runId,\n );\n }\n\n return this.triggerEvent({\n runId,\n resourceId,\n eventName: PAUSE_EVENT_NAME,\n data: {},\n options,\n });\n }\n\n async fastForwardWorkflow({\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data?: Record<string, unknown>;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n if (run.status !== WorkflowStatus.PAUSED) {\n return run;\n }\n\n const stepId = run.currentStepId;\n const waitForEntry = run.timeline[`${stepId}-wait-for`];\n if (!waitForEntry || typeof waitForEntry !== 'object' || !('waitFor' in waitForEntry)) {\n return run;\n }\n\n const { eventName, timeoutEvent, skipOutput } = (\n waitForEntry as { waitFor: { eventName?: string; timeoutEvent?: string; skipOutput?: true } }\n ).waitFor;\n\n // step.pause() - delegate to resumeWorkflow\n if (eventName === PAUSE_EVENT_NAME) {\n return this.resumeWorkflow({ runId, resourceId });\n }\n\n // step.poll() - write output to timeline first, then trigger resume\n if (skipOutput && timeoutEvent) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await getWorkflowRun({ runId, resourceId }, { exclusiveLock: true, db });\n if (!freshRun) throw new WorkflowRunNotFoundError(runId);\n return updateWorkflowRun(\n {\n runId,\n resourceId,\n data: {\n timeline: merge(freshRun.timeline, {\n [stepId]: {\n output: data ?? {},\n timestamp: new Date(),\n },\n }),\n },\n },\n db,\n );\n },\n this.pool,\n );\n\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });\n }\n\n // waitFor steps - trigger the event with data\n if (eventName) {\n return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });\n }\n\n // delay/waitUntil steps - trigger the timeout event\n if (timeoutEvent) {\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });\n }\n\n return run;\n }\n\n async cancelWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await updateWorkflowRun(\n {\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.CANCELLED,\n },\n expectedStatuses: [WorkflowStatus.PENDING, WorkflowStatus.RUNNING, WorkflowStatus.PAUSED],\n },\n this.db,\n );\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n this.logger.log(`${LOG_PREFIX} Cancelled workflow run ${runId}`);\n return run;\n }\n\n async getRun({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await getWorkflowRun({ runId, resourceId }, { db: this.db });\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async checkProgress({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRunProgress> {\n const run = await this.getRun({ runId, resourceId });\n\n const completedSteps = Object.values(run.timeline).filter(\n (entry): entry is { output: unknown; timestamp: Date } =>\n typeof entry === 'object' &&\n entry !== null &&\n 'output' in entry &&\n entry.output !== undefined,\n ).length;\n\n // Without registered workflow definitions, total steps are unknown.\n // Use completed steps as best-effort estimate for in-progress runs.\n const totalSteps = run.status === WorkflowStatus.COMPLETED ? completedSteps : 0;\n const completionPercentage =\n run.status === WorkflowStatus.COMPLETED\n ? 100\n : run.status === WorkflowStatus.FAILED || run.status === WorkflowStatus.CANCELLED\n ? 0\n : 0;\n\n return {\n ...run,\n completedSteps,\n completionPercentage,\n totalSteps,\n };\n }\n\n async getRuns({\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: WorkflowStatus[];\n workflowId?: string;\n }): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n }> {\n await this.ensureStarted();\n\n if (workflowId) validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n return getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit,\n statuses,\n workflowId,\n },\n this.db,\n );\n }\n\n private async ensureStarted(): Promise<void> {\n if (!this._started) {\n await this.start();\n }\n }\n}\n",
|
|
6
|
-
"export const PAUSE_EVENT_NAME = '__internal_pause';\nexport const WORKFLOW_RUN_QUEUE_NAME = 'workflow-run';\nexport const WORKFLOW_RUN_DLQ_QUEUE_NAME = 'workflow_run_dlq';\nexport const DEFAULT_PGBOSS_SCHEMA = 'pgboss_v12_pgworkflow';\nexport const MAX_WORKFLOW_ID_LENGTH = 256;\nexport const MAX_RESOURCE_ID_LENGTH = 256;\n",
|
|
7
|
-
"import type { Db } from 'pg-boss';\n\n// Arbitrary but stable lock ID for serializing migrations across processes\nexport const MIGRATION_LOCK_ID = 738291645;\n\n// Bump this when adding new migrations. The engine stores the current version\n// in a `workflow_schema_version` table so migrations only run once per version.\nconst CURRENT_SCHEMA_VERSION =
|
|
8
|
-
"import ksuid from 'ksuid';\nimport type { Db } from 'pg-boss';\nimport type { WorkflowRun } from './types';\n\nexport function generateKSUID(prefix?: string): string {\n return `${prefix ? `${prefix}_` : ''}${ksuid.randomSync().string}`;\n}\n\ntype WorkflowRunRow = {\n id: string;\n created_at: string | Date;\n updated_at: string | Date;\n resource_id: string | null;\n workflow_id: string;\n status: 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled';\n input: string | unknown;\n output: string | unknown | null;\n error: string | null;\n current_step_id: string;\n timeline: string | Record<string, unknown>;\n paused_at: string | Date | null;\n resumed_at: string | Date | null;\n completed_at: string | Date | null;\n timeout_at: string | Date | null;\n retry_count: number;\n max_retries: number;\n job_id: string | null;\n idempotency_key: string | null;\n};\n\nfunction mapRowToWorkflowRun(row: WorkflowRunRow): WorkflowRun {\n return {\n id: row.id,\n createdAt: new Date(row.created_at),\n updatedAt: new Date(row.updated_at),\n resourceId: row.resource_id,\n workflowId: row.workflow_id,\n status: row.status,\n input: typeof row.input === 'string' ? JSON.parse(row.input) : row.input,\n output:\n typeof row.output === 'string'\n ? row.output.trim().startsWith('{') || row.output.trim().startsWith('[')\n ? JSON.parse(row.output)\n : row.output\n : (row.output ?? null),\n error: row.error,\n currentStepId: row.current_step_id,\n timeline: typeof row.timeline === 'string' ? JSON.parse(row.timeline) : row.timeline,\n pausedAt: row.paused_at ? new Date(row.paused_at) : null,\n resumedAt: row.resumed_at ? new Date(row.resumed_at) : null,\n completedAt: row.completed_at ? new Date(row.completed_at) : null,\n timeoutAt: row.timeout_at ? new Date(row.timeout_at) : null,\n retryCount: row.retry_count,\n maxRetries: row.max_retries,\n jobId: row.job_id,\n idempotencyKey: row.idempotency_key,\n };\n}\n\nexport async function insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId,\n status,\n input,\n maxRetries,\n timeoutAt,\n idempotencyKey,\n }: {\n resourceId?: string;\n workflowId: string;\n currentStepId: string;\n status: string;\n input: unknown;\n maxRetries: number;\n timeoutAt: Date | null;\n idempotencyKey?: string;\n },\n db: Db,\n): Promise<{ run: WorkflowRun; created: boolean }> {\n const runId = generateKSUID('run');\n const now = new Date();\n\n const result = await db.executeSql(\n `INSERT INTO workflow_runs (\n id,\n resource_id,\n workflow_id,\n current_step_id,\n status,\n input,\n max_retries,\n timeout_at,\n created_at,\n updated_at,\n timeline,\n retry_count,\n idempotency_key\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)\n ON CONFLICT (idempotency_key) WHERE idempotency_key IS NOT NULL DO NOTHING\n RETURNING *`,\n [\n runId,\n resourceId ?? null,\n workflowId,\n currentStepId,\n status,\n JSON.stringify(input),\n maxRetries,\n timeoutAt,\n now,\n now,\n '{}',\n 0,\n idempotencyKey ?? null,\n ],\n );\n\n if (result.rows[0]) {\n return { run: mapRowToWorkflowRun(result.rows[0]), created: true };\n }\n\n // Conflict - fetch the existing row\n const existing = await db.executeSql('SELECT * FROM workflow_runs WHERE idempotency_key = $1', [\n idempotencyKey,\n ]);\n\n if (!existing.rows[0]) {\n throw new Error(`Idempotency conflict: existing run not found for key \"${idempotencyKey}\"`);\n }\n\n return { run: mapRowToWorkflowRun(existing.rows[0]), created: false };\n}\n\nexport async function getWorkflowRun(\n {\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db: Db },\n): Promise<WorkflowRun | null> {\n const lockSuffix = exclusiveLock ? 'FOR UPDATE' : '';\n\n const result = resourceId\n ? await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1 AND resource_id = $2\n ${lockSuffix}`,\n [runId, resourceId],\n )\n : await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1\n ${lockSuffix}`,\n [runId],\n );\n\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function updateWorkflowRun(\n {\n runId,\n resourceId,\n data,\n expectedStatuses,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n expectedStatuses?: string[];\n },\n db: Db,\n): Promise<WorkflowRun | null> {\n const now = new Date();\n\n const updates: string[] = ['updated_at = $1'];\n const values: (string | number | Date | null | string[])[] = [now];\n let paramIndex = 2;\n\n if (data.status !== undefined) {\n updates.push(`status = $${paramIndex}`);\n values.push(data.status);\n paramIndex++;\n }\n if (data.currentStepId !== undefined) {\n updates.push(`current_step_id = $${paramIndex}`);\n values.push(data.currentStepId);\n paramIndex++;\n }\n if (data.timeline !== undefined) {\n updates.push(`timeline = $${paramIndex}`);\n values.push(JSON.stringify(data.timeline));\n paramIndex++;\n }\n if (data.pausedAt !== undefined) {\n updates.push(`paused_at = $${paramIndex}`);\n values.push(data.pausedAt);\n paramIndex++;\n }\n if (data.resumedAt !== undefined) {\n updates.push(`resumed_at = $${paramIndex}`);\n values.push(data.resumedAt);\n paramIndex++;\n }\n if (data.completedAt !== undefined) {\n updates.push(`completed_at = $${paramIndex}`);\n values.push(data.completedAt);\n paramIndex++;\n }\n if (data.output !== undefined) {\n updates.push(`output = $${paramIndex}`);\n values.push(JSON.stringify(data.output));\n paramIndex++;\n }\n if (data.error !== undefined) {\n updates.push(`error = $${paramIndex}`);\n values.push(data.error);\n paramIndex++;\n }\n if (data.retryCount !== undefined) {\n updates.push(`retry_count = $${paramIndex}`);\n values.push(data.retryCount);\n paramIndex++;\n }\n if (data.jobId !== undefined) {\n updates.push(`job_id = $${paramIndex}`);\n values.push(data.jobId);\n paramIndex++;\n }\n\n values.push(runId);\n const idParam = paramIndex;\n paramIndex++;\n\n if (resourceId) {\n values.push(resourceId);\n paramIndex++;\n }\n\n if (expectedStatuses && expectedStatuses.length > 0) {\n values.push(expectedStatuses);\n paramIndex++;\n }\n\n let whereClause = resourceId\n ? `WHERE id = $${idParam} AND resource_id = $${idParam + 1}`\n : `WHERE id = $${idParam}`;\n\n if (expectedStatuses && expectedStatuses.length > 0) {\n whereClause += ` AND status = ANY($${paramIndex - 1})`;\n }\n\n const query = `\n UPDATE workflow_runs \n SET ${updates.join(', ')}\n ${whereClause}\n RETURNING *\n `;\n\n const result = await db.executeSql(query, values);\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: string[];\n workflowId?: string;\n },\n db: Db,\n): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n}> {\n const conditions: string[] = [];\n const values: (string | number | string[] | Date)[] = [];\n let paramIndex = 1;\n\n if (resourceId) {\n conditions.push(`resource_id = $${paramIndex}`);\n values.push(resourceId);\n paramIndex++;\n }\n\n if (statuses && statuses.length > 0) {\n conditions.push(`status = ANY($${paramIndex})`);\n values.push(statuses);\n paramIndex++;\n }\n\n if (workflowId) {\n conditions.push(`workflow_id = $${paramIndex}`);\n values.push(workflowId);\n paramIndex++;\n }\n\n const cursorIds = [startingAfter, endingBefore].filter(Boolean) as string[];\n if (cursorIds.length > 0) {\n const cursorResult = await db.executeSql(\n 'SELECT id, created_at FROM workflow_runs WHERE id = ANY($1)',\n [cursorIds],\n );\n const cursorMap = new Map<string, Date>();\n for (const row of cursorResult.rows) {\n cursorMap.set(\n row.id,\n typeof row.created_at === 'string' ? new Date(row.created_at) : row.created_at,\n );\n }\n\n if (startingAfter) {\n const cursor = cursorMap.get(startingAfter);\n if (cursor) {\n conditions.push(`created_at < $${paramIndex}`);\n values.push(cursor);\n paramIndex++;\n }\n }\n\n if (endingBefore) {\n const cursor = cursorMap.get(endingBefore);\n if (cursor) {\n conditions.push(`created_at > $${paramIndex}`);\n values.push(cursor);\n paramIndex++;\n }\n }\n }\n\n const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';\n const actualLimit = Math.min(Math.max(limit, 1), 100) + 1;\n\n const isBackward = !!endingBefore && !startingAfter;\n\n const query = `\n SELECT * FROM workflow_runs\n ${whereClause}\n ORDER BY created_at ${isBackward ? 'ASC' : 'DESC'}\n LIMIT $${paramIndex}\n `;\n values.push(actualLimit);\n\n const result = await db.executeSql(query, values);\n const rows = result.rows;\n\n const hasExtraRow = rows.length > (limit ?? 20);\n const rawItems = hasExtraRow ? rows.slice(0, limit) : rows;\n\n if (isBackward) {\n rawItems.reverse();\n }\n\n const items = rawItems.map((row) => mapRowToWorkflowRun(row));\n\n const hasMore = isBackward ? items.length > 0 : hasExtraRow;\n const hasPrev = isBackward ? hasExtraRow : !!startingAfter && items.length > 0;\n\n const nextCursor = hasMore && items.length > 0 ? (items[items.length - 1]?.id ?? null) : null;\n const prevCursor = hasPrev && items.length > 0 ? (items[0]?.id ?? null) : null;\n\n return { items, nextCursor, prevCursor, hasMore, hasPrev };\n}\n\n/**\n * Run a callback inside a PostgreSQL transaction using a dedicated client.\n *\n * When a `pool` is provided, a dedicated client is checked out so that\n * BEGIN / COMMIT / ROLLBACK all execute on the **same** connection.\n * This is critical for `SELECT … FOR UPDATE` locks and any work that\n * yields to the event-loop inside the transaction (e.g. async step handlers).\n *\n * Falls back to the pg-boss `Db` adapter when no pool is given (unit-test path).\n */\nexport async function withPostgresTransaction<T>(\n db: Db,\n callback: (db: Db) => Promise<T>,\n pool?: {\n connect: () => Promise<{\n query: (text: string, values?: unknown[]) => Promise<unknown>;\n release: () => void;\n }>;\n },\n): Promise<T> {\n let txDb: Db;\n let release: (() => void) | undefined;\n\n if (pool) {\n const client = await pool.connect();\n txDb = {\n executeSql: (text: string, values?: unknown[]) =>\n client.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n release = () => client.release();\n } else {\n txDb = db;\n }\n\n try {\n await txDb.executeSql('BEGIN', []);\n const result = await callback(txDb);\n await txDb.executeSql('COMMIT', []);\n return result;\n } catch (error) {\n await txDb.executeSql('ROLLBACK', []);\n throw error;\n } finally {\n release?.();\n }\n}\n",
|
|
5
|
+
"import { merge } from 'es-toolkit';\nimport pg from 'pg';\nimport { type Db, PgBoss } from 'pg-boss';\nimport {\n DEFAULT_PGBOSS_SCHEMA,\n invokeChildWorkflowTimelineKey,\n isInvokeChildWorkflowTimelineEntry,\n PAUSE_EVENT_NAME,\n WORKFLOW_RUN_QUEUE_NAME,\n waitForTimelineKey,\n} from './constants';\nimport { runMigrations } from './db/migration';\nimport {\n getWorkflowRun,\n getWorkflowRuns,\n insertWorkflowRun,\n updateWorkflowRun,\n withPostgresTransaction,\n} from './db/queries';\nimport type { WorkflowRun } from './db/types';\nimport {\n validateResourceId,\n validateWorkflowId,\n WorkflowEngineError,\n WorkflowRunNotFoundError,\n} from './error';\nimport {\n type InferInputParameters,\n type InputParameters,\n type WorkflowLogger,\n type WorkflowRef,\n type WorkflowRunOptions,\n type WorkflowRunProgress,\n WorkflowStatus,\n} from './types';\n\nconst LOG_PREFIX = '[WorkflowClient]';\n\ntype WorkflowRunJobParameters = {\n runId: string;\n resourceId?: string;\n workflowId: string;\n input: unknown;\n event?: {\n name: string;\n data?: Record<string, unknown>;\n };\n};\n\nexport type WorkflowClientOptions = {\n logger?: WorkflowLogger;\n /**\n * Pre-configured pg-boss instance. Pass this when the engine side uses a\n * non-default pg-boss config (schema, retention, logger, etc.) so the\n * client enqueues jobs where the engine reads them. Mirrors the same\n * option on `WorkflowEngineOptions`.\n */\n boss?: PgBoss;\n} & ({ pool: pg.Pool; connectionString?: never } | { connectionString: string; pool?: never });\n\nexport type StartWorkflowOptions = WorkflowRunOptions;\n\nconst defaultLogger: WorkflowLogger = {\n log: (_message: string) => console.warn(_message),\n error: (message: string, error: Error) => console.error(message, error),\n};\n\nconst defaultExpireInSeconds = process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS, 10)\n : 5 * 60;\n\nexport class WorkflowClient {\n private boss: PgBoss;\n private db: Db;\n private pool: pg.Pool;\n private _ownsPool = false;\n private _started = false;\n private logger: WorkflowLogger;\n\n constructor({ logger, boss, ...connectionOptions }: WorkflowClientOptions) {\n this.logger = logger ?? defaultLogger;\n\n if ('pool' in connectionOptions && connectionOptions.pool) {\n this.pool = connectionOptions.pool;\n } else if ('connectionString' in connectionOptions && connectionOptions.connectionString) {\n this.pool = new pg.Pool({ connectionString: connectionOptions.connectionString });\n this._ownsPool = true;\n } else {\n throw new WorkflowEngineError('Either pool or connectionString must be provided');\n }\n\n const db: Db = {\n executeSql: (text: string, values?: unknown[]) =>\n this.pool.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n\n if (boss) {\n this.boss = boss;\n } else {\n this.boss = new PgBoss({ db, schema: DEFAULT_PGBOSS_SCHEMA });\n }\n this.db = db;\n }\n\n async start(): Promise<void> {\n if (this._started) {\n return;\n }\n\n await this.boss.start();\n this.db = this.boss.getDb();\n await runMigrations(this.db);\n await this.boss.createQueue(WORKFLOW_RUN_QUEUE_NAME);\n\n this._started = true;\n this.logger.log(`${LOG_PREFIX} Client started`);\n }\n\n async stop(): Promise<void> {\n await this.boss.stop();\n\n if (this._ownsPool) {\n await this.pool.end();\n }\n\n this._started = false;\n this.logger.log(`${LOG_PREFIX} Client stopped`);\n }\n\n async startWorkflow<TInput extends InputParameters>(\n ref: WorkflowRef<TInput>,\n input: InferInputParameters<TInput>,\n options?: StartWorkflowOptions,\n ): Promise<WorkflowRun>;\n\n async startWorkflow(params: {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n }): Promise<WorkflowRun>;\n\n async startWorkflow<TInput extends InputParameters>(\n refOrParams:\n | WorkflowRef<TInput>\n | {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n },\n inputArg?: InferInputParameters<TInput>,\n optionsArg?: StartWorkflowOptions,\n ): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n let workflowId: string;\n let input: unknown;\n let resourceId: string | undefined;\n let idempotencyKey: string | undefined;\n let options: StartWorkflowOptions | undefined;\n\n if (typeof refOrParams === 'function' && 'id' in refOrParams) {\n const ref = refOrParams as WorkflowRef<TInput>;\n workflowId = ref.id;\n input = inputArg;\n options = optionsArg;\n resourceId = optionsArg?.resourceId;\n idempotencyKey = optionsArg?.idempotencyKey;\n\n if (ref.inputSchema) {\n const result = await ref.inputSchema['~standard'].validate(input);\n if (result.issues) {\n throw new WorkflowEngineError(\n JSON.stringify(result.issues),\n workflowId,\n undefined,\n undefined,\n result.issues,\n );\n }\n }\n } else {\n const params = refOrParams as {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n };\n workflowId = params.workflowId;\n input = params.input;\n resourceId = params.resourceId;\n idempotencyKey = params.idempotencyKey;\n options = params.options;\n }\n\n validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n const run = await withPostgresTransaction(\n this.db,\n async (_db) => {\n const timeoutAt = options?.timeout ? new Date(Date.now() + options.timeout) : null;\n\n const { run: insertedRun, created } = await insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId: '__start__',\n status: WorkflowStatus.RUNNING,\n input,\n maxRetries: options?.retries ?? 0,\n timeoutAt,\n idempotencyKey,\n },\n _db,\n );\n\n if (created) {\n const job: WorkflowRunJobParameters = {\n runId: insertedRun.id,\n resourceId,\n workflowId,\n input,\n };\n\n // Same connection (`_db`) used for the workflow_runs INSERT is passed\n // to `boss.send` so the pgboss.job INSERT joins the same transaction.\n // The two writes commit or roll back together, so we never leak an\n // orphan workflow_runs row when the queue insert fails.\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: new Date(),\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n db: _db,\n });\n }\n\n return insertedRun;\n },\n this.pool,\n );\n\n this.logger.log(`${LOG_PREFIX} Started workflow run ${run.id} for ${workflowId}`);\n\n return run;\n }\n\n async triggerEvent({\n runId,\n resourceId,\n eventName,\n data,\n options,\n }: {\n runId: string;\n resourceId?: string;\n eventName: string;\n data?: Record<string, unknown>;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: resourceId ?? run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: {\n name: eventName,\n data,\n },\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n\n this.logger.log(`${LOG_PREFIX} Event ${eventName} sent for workflow run ${runId}`);\n return run;\n }\n\n async pauseWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await updateWorkflowRun(\n {\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.PAUSED,\n pausedAt: new Date(),\n },\n expectedStatuses: [WorkflowStatus.RUNNING, WorkflowStatus.PENDING],\n },\n this.db,\n );\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n this.logger.log(`${LOG_PREFIX} Paused workflow run ${runId}`);\n return run;\n }\n\n async resumeWorkflow({\n runId,\n resourceId,\n options,\n }: {\n runId: string;\n resourceId?: string;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const current = await this.getRun({ runId, resourceId });\n if (current.status !== WorkflowStatus.PAUSED) {\n throw new WorkflowEngineError(\n `Cannot resume workflow run in '${current.status}' status, must be 'paused'`,\n current.workflowId,\n runId,\n );\n }\n\n const currentStepId = current.currentStepId;\n const currentStepTimelineEntry =\n current.timeline[invokeChildWorkflowTimelineKey(currentStepId)];\n if (isInvokeChildWorkflowTimelineEntry(currentStepTimelineEntry)) {\n return current;\n }\n\n return this.triggerEvent({\n runId,\n resourceId,\n eventName: PAUSE_EVENT_NAME,\n data: {},\n options,\n });\n }\n\n async fastForwardWorkflow({\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data?: Record<string, unknown>;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n if (run.status !== WorkflowStatus.PAUSED) {\n return run;\n }\n\n const currentStepId = run.currentStepId;\n const currentStepTimelineEntry = run.timeline[invokeChildWorkflowTimelineKey(currentStepId)];\n if (isInvokeChildWorkflowTimelineEntry(currentStepTimelineEntry)) {\n return run;\n }\n\n const waitForEntry = run.timeline[waitForTimelineKey(currentStepId)];\n if (!waitForEntry || typeof waitForEntry !== 'object' || !('waitFor' in waitForEntry)) {\n return run;\n }\n\n const { eventName, timeoutEvent, skipOutput } = (\n waitForEntry as { waitFor: { eventName?: string; timeoutEvent?: string; skipOutput?: true } }\n ).waitFor;\n\n // step.pause() - delegate to resumeWorkflow\n if (eventName === PAUSE_EVENT_NAME) {\n return this.resumeWorkflow({ runId, resourceId });\n }\n\n // step.poll() - write output to timeline first, then trigger resume\n if (skipOutput && timeoutEvent) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await getWorkflowRun({ runId, resourceId }, { exclusiveLock: true, db });\n if (!freshRun) throw new WorkflowRunNotFoundError(runId);\n return updateWorkflowRun(\n {\n runId,\n resourceId,\n data: {\n timeline: merge(freshRun.timeline, {\n [currentStepId]: {\n output: data ?? {},\n timestamp: new Date(),\n },\n }),\n },\n },\n db,\n );\n },\n this.pool,\n );\n\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });\n }\n\n // waitFor steps - trigger the event with data\n if (eventName) {\n return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });\n }\n\n // delay/waitUntil steps - trigger the timeout event\n if (timeoutEvent) {\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });\n }\n\n return run;\n }\n\n async cancelWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await updateWorkflowRun(\n {\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.CANCELLED,\n },\n expectedStatuses: [WorkflowStatus.PENDING, WorkflowStatus.RUNNING, WorkflowStatus.PAUSED],\n },\n this.db,\n );\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n this.logger.log(`${LOG_PREFIX} Cancelled workflow run ${runId}`);\n return run;\n }\n\n async getRun({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.ensureStarted();\n\n const run = await getWorkflowRun({ runId, resourceId }, { db: this.db });\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async checkProgress({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRunProgress> {\n const run = await this.getRun({ runId, resourceId });\n\n const completedSteps = Object.values(run.timeline).filter(\n (entry): entry is { output: unknown; timestamp: Date } =>\n typeof entry === 'object' &&\n entry !== null &&\n 'output' in entry &&\n entry.output !== undefined,\n ).length;\n\n // Without registered workflow definitions, total steps are unknown.\n // Use completed steps as best-effort estimate for in-progress runs.\n const totalSteps = run.status === WorkflowStatus.COMPLETED ? completedSteps : 0;\n const completionPercentage =\n run.status === WorkflowStatus.COMPLETED\n ? 100\n : run.status === WorkflowStatus.FAILED || run.status === WorkflowStatus.CANCELLED\n ? 0\n : 0;\n\n return {\n ...run,\n completedSteps,\n completionPercentage,\n totalSteps,\n };\n }\n\n async getRuns({\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: WorkflowStatus[];\n workflowId?: string;\n }): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n }> {\n await this.ensureStarted();\n\n if (workflowId) validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n return getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit,\n statuses,\n workflowId,\n },\n this.db,\n );\n }\n\n private async ensureStarted(): Promise<void> {\n if (!this._started) {\n await this.start();\n }\n }\n}\n",
|
|
6
|
+
"export const PAUSE_EVENT_NAME = '__internal_pause';\nexport const WORKFLOW_RUN_QUEUE_NAME = 'workflow-run';\nexport const WORKFLOW_RUN_DLQ_QUEUE_NAME = 'workflow_run_dlq';\nexport const DEFAULT_PGBOSS_SCHEMA = 'pgboss_v12_pgworkflow';\nexport const MAX_WORKFLOW_ID_LENGTH = 256;\nexport const MAX_RESOURCE_ID_LENGTH = 256;\n\n// Per-step timeline key suffixes. The shared helpers below are the single\n// source of truth for engine + client so timeline-shape changes only need to\n// happen in one place.\nexport const INVOKE_CHILD_WORKFLOW_TIMELINE_SUFFIX = 'invoke-child-workflow';\nexport const WAIT_FOR_TIMELINE_SUFFIX = 'wait-for';\nexport const invokeChildWorkflowTimelineKey = (stepId: string) =>\n `${stepId}-${INVOKE_CHILD_WORKFLOW_TIMELINE_SUFFIX}`;\nexport const waitForTimelineKey = (stepId: string) => `${stepId}-${WAIT_FOR_TIMELINE_SUFFIX}`;\n\n/**\n * Type guard for `${stepId}-invoke-child-workflow` timeline entries. Used by the\n * engine to dispatch invoke-aware behavior and by the client's resume /\n * fast-forward no-op guards. Centralizing this keeps the timeline shape\n * contract in one place.\n */\nexport const isInvokeChildWorkflowTimelineEntry = (\n entry: unknown,\n): entry is { invokeChildWorkflow: { childRunId: string; childWorkflowId: string } } =>\n !!entry && typeof entry === 'object' && 'invokeChildWorkflow' in entry;\n",
|
|
7
|
+
"import type { Db } from 'pg-boss';\n\n// Arbitrary but stable lock ID for serializing migrations across processes\nexport const MIGRATION_LOCK_ID = 738291645;\n\n// Bump this when adding new migrations. The engine stores the current version\n// in a `workflow_schema_version` table so migrations only run once per version.\nconst CURRENT_SCHEMA_VERSION = 4;\n\nexport async function runMigrations(db: Db): Promise<void> {\n // Fast path: skip the advisory lock if schema is already current.\n // This is the common case - every engine.start() after initial setup.\n if (await isSchemaUpToDate(db)) {\n return;\n }\n\n // Slow path: build migration SQL based on current version, then execute\n // everything in a single transaction with an advisory lock.\n // This mirrors pg-boss's approach: one executeSql call ensures all DDL\n // runs on a single connection inside BEGIN/COMMIT, and pg_advisory_xact_lock\n // auto-releases on commit or rollback (no manual unlock needed).\n const currentVersion = await getCurrentVersion(db);\n\n const commands: string[] = [];\n\n if (currentVersion < 1) {\n commands.push(`\n CREATE TABLE IF NOT EXISTS workflow_runs (\n id varchar(32) PRIMARY KEY NOT NULL,\n created_at timestamp with time zone DEFAULT now() NOT NULL,\n updated_at timestamp with time zone DEFAULT now() NOT NULL,\n resource_id varchar(256),\n workflow_id varchar(256) NOT NULL,\n status text DEFAULT 'pending' NOT NULL,\n input jsonb NOT NULL,\n output jsonb,\n error text,\n current_step_id varchar(256) NOT NULL,\n timeline jsonb DEFAULT '{}'::jsonb NOT NULL,\n paused_at timestamp with time zone,\n resumed_at timestamp with time zone,\n completed_at timestamp with time zone,\n timeout_at timestamp with time zone,\n retry_count integer DEFAULT 0 NOT NULL,\n max_retries integer DEFAULT 0 NOT NULL,\n job_id varchar(256)\n )\n `);\n commands.push(`\n CREATE INDEX IF NOT EXISTS workflow_runs_created_at_idx ON workflow_runs USING btree (created_at)\n `);\n commands.push(`\n CREATE INDEX IF NOT EXISTS workflow_runs_resource_id_created_at_idx ON workflow_runs USING btree (resource_id, created_at DESC)\n `);\n commands.push(`\n CREATE INDEX IF NOT EXISTS workflow_runs_status_created_at_idx ON workflow_runs USING btree (status, created_at DESC)\n `);\n commands.push(`\n CREATE INDEX IF NOT EXISTS workflow_runs_workflow_id_created_at_idx ON workflow_runs USING btree (workflow_id, created_at DESC)\n `);\n commands.push(`\n CREATE INDEX IF NOT EXISTS workflow_runs_resource_id_workflow_id_created_at_idx ON workflow_runs USING btree (resource_id, workflow_id, created_at DESC)\n `);\n }\n\n if (currentVersion < 2) {\n commands.push('DROP INDEX IF EXISTS workflow_runs_workflow_id_idx');\n commands.push('DROP INDEX IF EXISTS workflow_runs_resource_id_idx');\n commands.push(\n 'ALTER TABLE workflow_runs ADD COLUMN IF NOT EXISTS idempotency_key varchar(256)',\n );\n commands.push(`\n CREATE UNIQUE INDEX IF NOT EXISTS workflow_runs_idempotency_key_idx ON workflow_runs (idempotency_key) WHERE idempotency_key IS NOT NULL\n `);\n }\n\n if (currentVersion < 3) {\n commands.push('ALTER TABLE workflow_runs ALTER COLUMN resource_id TYPE varchar(256)');\n commands.push('ALTER TABLE workflow_runs ALTER COLUMN workflow_id TYPE varchar(256)');\n }\n\n if (currentVersion < 4) {\n commands.push('ALTER TABLE workflow_runs ADD COLUMN IF NOT EXISTS parent_run_id varchar(32)');\n commands.push('ALTER TABLE workflow_runs ADD COLUMN IF NOT EXISTS parent_step_id varchar(256)');\n commands.push(\n 'ALTER TABLE workflow_runs ADD COLUMN IF NOT EXISTS parent_resource_id varchar(256)',\n );\n }\n\n // Upsert the schema version\n if (currentVersion === 0) {\n commands.push(\n `INSERT INTO workflow_schema_version (version) VALUES (${CURRENT_SCHEMA_VERSION})`,\n );\n } else {\n commands.push(`UPDATE workflow_schema_version SET version = ${CURRENT_SCHEMA_VERSION}`);\n }\n\n if (commands.length === 0) {\n return;\n }\n\n const sql = [\n 'BEGIN',\n \"SET LOCAL lock_timeout = '30s'\",\n \"SET LOCAL idle_in_transaction_session_timeout = '30s'\",\n `SELECT pg_advisory_xact_lock(${MIGRATION_LOCK_ID})`,\n 'CREATE TABLE IF NOT EXISTS workflow_schema_version (version integer NOT NULL)',\n ...commands,\n 'COMMIT',\n ].join(';\\n');\n\n await db.executeSql(sql, []);\n}\n\nasync function isSchemaUpToDate(db: Db): Promise<boolean> {\n try {\n const result = await db.executeSql('SELECT version FROM workflow_schema_version LIMIT 1', []);\n return (\n ((result.rows[0] as { version: number } | undefined)?.version ?? 0) >= CURRENT_SCHEMA_VERSION\n );\n } catch {\n // Table doesn't exist yet - needs migration\n return false;\n }\n}\n\nasync function getCurrentVersion(db: Db): Promise<number> {\n try {\n const result = await db.executeSql('SELECT version FROM workflow_schema_version LIMIT 1', []);\n return (result.rows[0] as { version: number } | undefined)?.version ?? 0;\n } catch {\n return 0;\n }\n}\n",
|
|
8
|
+
"import ksuid from 'ksuid';\nimport type { Db } from 'pg-boss';\nimport type { WorkflowRun } from './types';\n\nexport function generateKSUID(prefix?: string): string {\n return `${prefix ? `${prefix}_` : ''}${ksuid.randomSync().string}`;\n}\n\ntype WorkflowRunRow = {\n id: string;\n created_at: string | Date;\n updated_at: string | Date;\n resource_id: string | null;\n workflow_id: string;\n status: 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled';\n input: string | unknown;\n output: string | unknown | null;\n error: string | null;\n current_step_id: string;\n timeline: string | Record<string, unknown>;\n paused_at: string | Date | null;\n resumed_at: string | Date | null;\n completed_at: string | Date | null;\n timeout_at: string | Date | null;\n retry_count: number;\n max_retries: number;\n job_id: string | null;\n idempotency_key: string | null;\n parent_run_id: string | null;\n parent_step_id: string | null;\n parent_resource_id: string | null;\n};\n\nfunction mapRowToWorkflowRun(row: WorkflowRunRow): WorkflowRun {\n return {\n id: row.id,\n createdAt: new Date(row.created_at),\n updatedAt: new Date(row.updated_at),\n resourceId: row.resource_id,\n workflowId: row.workflow_id,\n status: row.status,\n input: typeof row.input === 'string' ? JSON.parse(row.input) : row.input,\n output:\n typeof row.output === 'string'\n ? row.output.trim().startsWith('{') || row.output.trim().startsWith('[')\n ? JSON.parse(row.output)\n : row.output\n : (row.output ?? null),\n error: row.error,\n currentStepId: row.current_step_id,\n timeline: typeof row.timeline === 'string' ? JSON.parse(row.timeline) : row.timeline,\n pausedAt: row.paused_at ? new Date(row.paused_at) : null,\n resumedAt: row.resumed_at ? new Date(row.resumed_at) : null,\n completedAt: row.completed_at ? new Date(row.completed_at) : null,\n timeoutAt: row.timeout_at ? new Date(row.timeout_at) : null,\n retryCount: row.retry_count,\n maxRetries: row.max_retries,\n jobId: row.job_id,\n idempotencyKey: row.idempotency_key,\n parentRunId: row.parent_run_id,\n parentStepId: row.parent_step_id,\n parentResourceId: row.parent_resource_id,\n };\n}\n\nexport async function insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId,\n status,\n input,\n maxRetries,\n timeoutAt,\n idempotencyKey,\n parentRunId,\n parentStepId,\n parentResourceId,\n }: {\n resourceId?: string;\n workflowId: string;\n currentStepId: string;\n status: string;\n input: unknown;\n maxRetries: number;\n timeoutAt: Date | null;\n idempotencyKey?: string;\n parentRunId?: string;\n parentStepId?: string;\n parentResourceId?: string;\n },\n db: Db,\n): Promise<{ run: WorkflowRun; created: boolean }> {\n const runId = generateKSUID('run');\n const now = new Date();\n\n const result = await db.executeSql(\n `INSERT INTO workflow_runs (\n id,\n resource_id,\n workflow_id,\n current_step_id,\n status,\n input,\n max_retries,\n timeout_at,\n created_at,\n updated_at,\n timeline,\n retry_count,\n idempotency_key,\n parent_run_id,\n parent_step_id,\n parent_resource_id\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)\n ON CONFLICT (idempotency_key) WHERE idempotency_key IS NOT NULL DO NOTHING\n RETURNING *`,\n [\n runId,\n resourceId ?? null,\n workflowId,\n currentStepId,\n status,\n JSON.stringify(input),\n maxRetries,\n timeoutAt,\n now,\n now,\n '{}',\n 0,\n idempotencyKey ?? null,\n parentRunId ?? null,\n parentStepId ?? null,\n parentResourceId ?? null,\n ],\n );\n\n if (result.rows[0]) {\n return { run: mapRowToWorkflowRun(result.rows[0]), created: true };\n }\n\n // Conflict - fetch the existing row\n const existing = await db.executeSql('SELECT * FROM workflow_runs WHERE idempotency_key = $1', [\n idempotencyKey,\n ]);\n\n if (!existing.rows[0]) {\n throw new Error(`Idempotency conflict: existing run not found for key \"${idempotencyKey}\"`);\n }\n\n return { run: mapRowToWorkflowRun(existing.rows[0]), created: false };\n}\n\nexport async function getWorkflowRun(\n {\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db: Db },\n): Promise<WorkflowRun | null> {\n const lockSuffix = exclusiveLock ? 'FOR UPDATE' : '';\n\n const result = resourceId\n ? await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1 AND resource_id = $2\n ${lockSuffix}`,\n [runId, resourceId],\n )\n : await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1\n ${lockSuffix}`,\n [runId],\n );\n\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function updateWorkflowRun(\n {\n runId,\n resourceId,\n data,\n expectedStatuses,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n expectedStatuses?: string[];\n },\n db: Db,\n): Promise<WorkflowRun | null> {\n const now = new Date();\n\n const updates: string[] = ['updated_at = $1'];\n const values: (string | number | Date | null | string[])[] = [now];\n let paramIndex = 2;\n\n if (data.status !== undefined) {\n updates.push(`status = $${paramIndex}`);\n values.push(data.status);\n paramIndex++;\n }\n if (data.currentStepId !== undefined) {\n updates.push(`current_step_id = $${paramIndex}`);\n values.push(data.currentStepId);\n paramIndex++;\n }\n if (data.timeline !== undefined) {\n updates.push(`timeline = $${paramIndex}`);\n values.push(JSON.stringify(data.timeline));\n paramIndex++;\n }\n if (data.pausedAt !== undefined) {\n updates.push(`paused_at = $${paramIndex}`);\n values.push(data.pausedAt);\n paramIndex++;\n }\n if (data.resumedAt !== undefined) {\n updates.push(`resumed_at = $${paramIndex}`);\n values.push(data.resumedAt);\n paramIndex++;\n }\n if (data.completedAt !== undefined) {\n updates.push(`completed_at = $${paramIndex}`);\n values.push(data.completedAt);\n paramIndex++;\n }\n if (data.output !== undefined) {\n updates.push(`output = $${paramIndex}`);\n values.push(JSON.stringify(data.output));\n paramIndex++;\n }\n if (data.error !== undefined) {\n updates.push(`error = $${paramIndex}`);\n values.push(data.error);\n paramIndex++;\n }\n if (data.retryCount !== undefined) {\n updates.push(`retry_count = $${paramIndex}`);\n values.push(data.retryCount);\n paramIndex++;\n }\n if (data.jobId !== undefined) {\n updates.push(`job_id = $${paramIndex}`);\n values.push(data.jobId);\n paramIndex++;\n }\n\n values.push(runId);\n const idParam = paramIndex;\n paramIndex++;\n\n if (resourceId) {\n values.push(resourceId);\n paramIndex++;\n }\n\n if (expectedStatuses && expectedStatuses.length > 0) {\n values.push(expectedStatuses);\n paramIndex++;\n }\n\n let whereClause = resourceId\n ? `WHERE id = $${idParam} AND resource_id = $${idParam + 1}`\n : `WHERE id = $${idParam}`;\n\n if (expectedStatuses && expectedStatuses.length > 0) {\n whereClause += ` AND status = ANY($${paramIndex - 1})`;\n }\n\n const query = `\n UPDATE workflow_runs \n SET ${updates.join(', ')}\n ${whereClause}\n RETURNING *\n `;\n\n const result = await db.executeSql(query, values);\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: string[];\n workflowId?: string;\n },\n db: Db,\n): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n}> {\n const conditions: string[] = [];\n const values: (string | number | string[] | Date)[] = [];\n let paramIndex = 1;\n\n if (resourceId) {\n conditions.push(`resource_id = $${paramIndex}`);\n values.push(resourceId);\n paramIndex++;\n }\n\n if (statuses && statuses.length > 0) {\n conditions.push(`status = ANY($${paramIndex})`);\n values.push(statuses);\n paramIndex++;\n }\n\n if (workflowId) {\n conditions.push(`workflow_id = $${paramIndex}`);\n values.push(workflowId);\n paramIndex++;\n }\n\n const cursorIds = [startingAfter, endingBefore].filter(Boolean) as string[];\n if (cursorIds.length > 0) {\n const cursorResult = await db.executeSql(\n 'SELECT id, created_at FROM workflow_runs WHERE id = ANY($1)',\n [cursorIds],\n );\n const cursorMap = new Map<string, Date>();\n for (const row of cursorResult.rows) {\n cursorMap.set(\n row.id,\n typeof row.created_at === 'string' ? new Date(row.created_at) : row.created_at,\n );\n }\n\n if (startingAfter) {\n const cursor = cursorMap.get(startingAfter);\n if (cursor) {\n conditions.push(`created_at < $${paramIndex}`);\n values.push(cursor);\n paramIndex++;\n }\n }\n\n if (endingBefore) {\n const cursor = cursorMap.get(endingBefore);\n if (cursor) {\n conditions.push(`created_at > $${paramIndex}`);\n values.push(cursor);\n paramIndex++;\n }\n }\n }\n\n const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';\n const actualLimit = Math.min(Math.max(limit, 1), 100) + 1;\n\n const isBackward = !!endingBefore && !startingAfter;\n\n const query = `\n SELECT * FROM workflow_runs\n ${whereClause}\n ORDER BY created_at ${isBackward ? 'ASC' : 'DESC'}\n LIMIT $${paramIndex}\n `;\n values.push(actualLimit);\n\n const result = await db.executeSql(query, values);\n const rows = result.rows;\n\n const hasExtraRow = rows.length > (limit ?? 20);\n const rawItems = hasExtraRow ? rows.slice(0, limit) : rows;\n\n if (isBackward) {\n rawItems.reverse();\n }\n\n const items = rawItems.map((row) => mapRowToWorkflowRun(row));\n\n const hasMore = isBackward ? items.length > 0 : hasExtraRow;\n const hasPrev = isBackward ? hasExtraRow : !!startingAfter && items.length > 0;\n\n const nextCursor = hasMore && items.length > 0 ? (items[items.length - 1]?.id ?? null) : null;\n const prevCursor = hasPrev && items.length > 0 ? (items[0]?.id ?? null) : null;\n\n return { items, nextCursor, prevCursor, hasMore, hasPrev };\n}\n\n/**\n * Run a callback inside a PostgreSQL transaction using a dedicated client.\n *\n * When a `pool` is provided, a dedicated client is checked out so that\n * BEGIN / COMMIT / ROLLBACK all execute on the **same** connection.\n * This is critical for `SELECT … FOR UPDATE` locks and any work that\n * yields to the event-loop inside the transaction (e.g. async step handlers).\n *\n * Falls back to the pg-boss `Db` adapter when no pool is given (unit-test path).\n */\nexport async function withPostgresTransaction<T>(\n db: Db,\n callback: (db: Db) => Promise<T>,\n pool?: {\n connect: () => Promise<{\n query: (text: string, values?: unknown[]) => Promise<unknown>;\n release: () => void;\n }>;\n },\n): Promise<T> {\n let txDb: Db;\n let release: (() => void) | undefined;\n\n if (pool) {\n const client = await pool.connect();\n txDb = {\n executeSql: (text: string, values?: unknown[]) =>\n client.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n release = () => client.release();\n } else {\n txDb = db;\n }\n\n try {\n await txDb.executeSql('BEGIN', []);\n const result = await callback(txDb);\n await txDb.executeSql('COMMIT', []);\n return result;\n } catch (error) {\n await txDb.executeSql('ROLLBACK', []);\n throw error;\n } finally {\n release?.();\n }\n}\n",
|
|
9
9
|
"import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { MAX_RESOURCE_ID_LENGTH, MAX_WORKFLOW_ID_LENGTH } from './constants';\n\nexport function validateWorkflowId(workflowId: string): void {\n if (workflowId.length > MAX_WORKFLOW_ID_LENGTH) {\n throw new WorkflowEngineError(\n `workflowId exceeds maximum length of ${MAX_WORKFLOW_ID_LENGTH} characters (got ${workflowId.length})`,\n workflowId,\n );\n }\n}\n\nexport function validateResourceId(resourceId: string | undefined | null): void {\n if (resourceId != null && resourceId.length > MAX_RESOURCE_ID_LENGTH) {\n throw new WorkflowEngineError(\n `resourceId exceeds maximum length of ${MAX_RESOURCE_ID_LENGTH} characters (got ${resourceId.length})`,\n );\n }\n}\n\nexport class WorkflowEngineError extends Error {\n constructor(\n message: string,\n public readonly workflowId?: string,\n public readonly runId?: string,\n public override readonly cause: Error | undefined = undefined,\n public readonly issues?: StandardSchemaV1.FailureResult['issues'] | undefined,\n ) {\n super(message);\n this.name = 'WorkflowEngineError';\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, WorkflowEngineError);\n }\n }\n}\n\nexport class WorkflowRunNotFoundError extends WorkflowEngineError {\n constructor(runId?: string, workflowId?: string) {\n super('Workflow run not found', workflowId, runId);\n this.name = 'WorkflowRunNotFoundError';\n }\n}\n",
|
|
10
|
-
"import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\n\nexport enum WorkflowStatus {\n PENDING = 'pending',\n RUNNING = 'running',\n PAUSED = 'paused',\n COMPLETED = 'completed',\n FAILED = 'failed',\n CANCELLED = 'cancelled',\n}\n\nexport enum StepType {\n PAUSE = 'pause',\n RUN = 'run',\n WAIT_FOR = 'waitFor',\n WAIT_UNTIL = 'waitUntil',\n DELAY = 'delay',\n POLL = 'poll',\n}\n\nexport type InputParameters = StandardSchemaV1;\nexport type InferInputParameters<P extends InputParameters> = StandardSchemaV1.InferOutput<P>;\n\nexport type WorkflowOptions<I extends InputParameters> = {\n timeout?: number;\n retries?: number;\n inputSchema?: I;\n};\n\nexport type StepBaseContext = {\n run: <T>(stepId: string, handler: () => Promise<T>) => Promise<T>;\n waitFor: {\n <T extends InputParameters>(\n stepId: string,\n options: { eventName: string; schema?: T },\n ): Promise<InferInputParameters<T>>;\n <T extends InputParameters>(\n stepId: string,\n options: { eventName: string; timeout: number; schema?: T },\n ): Promise<InferInputParameters<T> | undefined>;\n };\n waitUntil: {\n (stepId: string, date: Date): Promise<void>;\n (stepId: string, dateString: string): Promise<void>;\n (stepId: string, options: { date: Date | string }): Promise<void>;\n };\n /** Delay execution for a duration (sugar over waitUntil). Alias: sleep. */\n delay: (stepId: string, duration: Duration) => Promise<void>;\n /** Alias for delay. */\n sleep: (stepId: string, duration: Duration) => Promise<void>;\n pause: (stepId: string) => Promise<void>;\n poll: <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => Promise<{ timedOut: false; data: T } | { timedOut: true }>;\n};\n\n/**\n * Plugin that extends the workflow step API with extra methods.\n * @template TStepBase - The step type this plugin receives (base + previous plugins).\n * @template TStepExt - The extra methods this plugin adds to step.\n */\nexport interface WorkflowPlugin<TStepBase = StepBaseContext, TStepExt = object> {\n name: string;\n methods: (step: TStepBase) => TStepExt;\n}\n\nexport type WorkflowContext<\n TInput extends InputParameters = InputParameters,\n TStep extends StepBaseContext = StepBaseContext,\n> = {\n input: InferInputParameters<TInput>;\n step: TStep;\n workflowId: string;\n runId: string;\n timeline: Record<string, unknown>;\n logger: WorkflowLogger;\n};\n\nexport type WorkflowDefinition<TInput extends InputParameters = InputParameters> = {\n id: string;\n /** Widest context avoids contravariance when collecting definitions; `workflow()` still types the handler narrowly. */\n handler: (context: WorkflowContext<InputParameters, StepBaseContext>) => Promise<unknown>;\n inputSchema?: TInput;\n timeout?: number; // milliseconds\n retries?: number;\n plugins?: WorkflowPlugin[];\n};\n\nexport type StepInternalDefinition = {\n id: string;\n type: StepType;\n conditional: boolean;\n loop: boolean;\n isDynamic: boolean;\n};\n\nexport type WorkflowInternalDefinition<TInput extends InputParameters = InputParameters> =\n WorkflowDefinition<TInput> & {\n steps: StepInternalDefinition[];\n };\n\n/**\n * Chainable workflow factory: call as (id, handler, options) and/or use .use(plugin).\n * TStepExt is the accumulated step extension from all plugins (step = StepContext & TStepExt).\n */\nexport interface WorkflowFactory<TStepExt = object> {\n <I extends InputParameters = InputParameters>(\n id: string,\n handler: (context: WorkflowContext<I, StepBaseContext & TStepExt>) => Promise<unknown>,\n options?: WorkflowOptions<I>,\n ): WorkflowDefinition<I>;\n use<TNewExt>(\n plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>,\n ): WorkflowFactory<TStepExt & TNewExt>;\n ref<TInput extends InputParameters = InputParameters>(\n id: string,\n options?: { inputSchema?: TInput },\n ): WorkflowRef<TInput>;\n}\n\n/**\n * Lightweight workflow reference - carries the workflow ID and input type\n * but no handler code. Safe to import in API services without pulling in\n * heavy worker dependencies.\n *\n * Callable: pass a handler to create a full WorkflowDefinition.\n */\nexport interface WorkflowRef
|
|
11
|
-
"import type {\n InputParameters,\n StepBaseContext,\n WorkflowContext,\n WorkflowDefinition,\n WorkflowFactory,\n WorkflowOptions,\n WorkflowPlugin,\n WorkflowRef,\n} from './types';\n\n/**\n * Create a lightweight workflow reference.\n * Safe to import from `pg-workflows/client` - no engine or handler code.\n */\nexport function createWorkflowRef
|
|
10
|
+
"import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\n\nexport enum WorkflowStatus {\n PENDING = 'pending',\n RUNNING = 'running',\n PAUSED = 'paused',\n COMPLETED = 'completed',\n FAILED = 'failed',\n CANCELLED = 'cancelled',\n}\n\nexport enum StepType {\n PAUSE = 'pause',\n RUN = 'run',\n WAIT_FOR = 'waitFor',\n WAIT_UNTIL = 'waitUntil',\n DELAY = 'delay',\n POLL = 'poll',\n INVOKE_CHILD_WORKFLOW = 'invokeChildWorkflow',\n}\n\nexport type InputParameters = StandardSchemaV1;\nexport type InferInputParameters<P extends InputParameters> = StandardSchemaV1.InferOutput<P>;\n\nexport type WorkflowRunOptions = {\n resourceId?: string;\n timeout?: number;\n retries?: number;\n expireInSeconds?: number;\n idempotencyKey?: string;\n};\n\nexport type WorkflowOptions<I extends InputParameters> = {\n timeout?: number;\n retries?: number;\n inputSchema?: I;\n};\n\nexport type StepBaseContext = {\n run: <T>(stepId: string, handler: () => Promise<T>) => Promise<T>;\n waitFor: {\n <T extends InputParameters>(\n stepId: string,\n options: { eventName: string; schema?: T },\n ): Promise<InferInputParameters<T>>;\n <T extends InputParameters>(\n stepId: string,\n options: { eventName: string; timeout: number; schema?: T },\n ): Promise<InferInputParameters<T> | undefined>;\n };\n waitUntil: {\n (stepId: string, date: Date): Promise<void>;\n (stepId: string, dateString: string): Promise<void>;\n (stepId: string, options: { date: Date | string }): Promise<void>;\n };\n /** Delay execution for a duration (sugar over waitUntil). Alias: sleep. */\n delay: (stepId: string, duration: Duration) => Promise<void>;\n /** Alias for delay. */\n sleep: (stepId: string, duration: Duration) => Promise<void>;\n pause: (stepId: string) => Promise<void>;\n poll: <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => Promise<{ timedOut: false; data: T } | { timedOut: true }>;\n /**\n * Invoke a child workflow from inside the current workflow and pause until\n * the child run reaches a terminal state.\n */\n invokeChildWorkflow: {\n <TInput extends InputParameters, TOutput = unknown>(\n stepId: string,\n ref: WorkflowRef<TInput, TOutput>,\n input: InferInputParameters<TInput>,\n options?: WorkflowRunOptions,\n ): Promise<TOutput>;\n <TOutput = unknown>(\n stepId: string,\n params: {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: WorkflowRunOptions;\n },\n ): Promise<TOutput>;\n };\n};\n\n/**\n * Plugin that extends the workflow step API with extra methods.\n * @template TStepBase - The step type this plugin receives (base + previous plugins).\n * @template TStepExt - The extra methods this plugin adds to step.\n */\nexport interface WorkflowPlugin<TStepBase = StepBaseContext, TStepExt = object> {\n name: string;\n methods: (step: TStepBase) => TStepExt;\n}\n\nexport type WorkflowContext<\n TInput extends InputParameters = InputParameters,\n TStep extends StepBaseContext = StepBaseContext,\n> = {\n input: InferInputParameters<TInput>;\n step: TStep;\n workflowId: string;\n runId: string;\n timeline: Record<string, unknown>;\n logger: WorkflowLogger;\n};\n\nexport type WorkflowDefinition<TInput extends InputParameters = InputParameters> = {\n id: string;\n /** Widest context avoids contravariance when collecting definitions; `workflow()` still types the handler narrowly. */\n handler: (context: WorkflowContext<InputParameters, StepBaseContext>) => Promise<unknown>;\n inputSchema?: TInput;\n timeout?: number; // milliseconds\n retries?: number;\n plugins?: WorkflowPlugin[];\n};\n\nexport type StepInternalDefinition = {\n id: string;\n type: StepType;\n conditional: boolean;\n loop: boolean;\n isDynamic: boolean;\n};\n\nexport type WorkflowInternalDefinition<TInput extends InputParameters = InputParameters> =\n WorkflowDefinition<TInput> & {\n steps: StepInternalDefinition[];\n };\n\n/**\n * Chainable workflow factory: call as (id, handler, options) and/or use .use(plugin).\n * TStepExt is the accumulated step extension from all plugins (step = StepContext & TStepExt).\n */\nexport interface WorkflowFactory<TStepExt = object> {\n <I extends InputParameters = InputParameters>(\n id: string,\n handler: (context: WorkflowContext<I, StepBaseContext & TStepExt>) => Promise<unknown>,\n options?: WorkflowOptions<I>,\n ): WorkflowDefinition<I>;\n use<TNewExt>(\n plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>,\n ): WorkflowFactory<TStepExt & TNewExt>;\n ref<TInput extends InputParameters = InputParameters, TOutput = unknown>(\n id: string,\n options?: { inputSchema?: TInput },\n ): WorkflowRef<TInput, TOutput>;\n}\n\n/**\n * Lightweight workflow reference - carries the workflow ID and input type\n * but no handler code. Safe to import in API services without pulling in\n * heavy worker dependencies.\n *\n * Callable: pass a handler to create a full WorkflowDefinition.\n */\nexport interface WorkflowRef<\n TInput extends InputParameters = InputParameters,\n // biome-ignore lint/correctness/noUnusedVariables: phantom type carried for typed return inference\n TOutput = unknown,\n> {\n (\n handler: (context: WorkflowContext<TInput, StepBaseContext>) => Promise<unknown>,\n options?: Omit<WorkflowOptions<TInput>, 'inputSchema'>,\n ): WorkflowDefinition<TInput>;\n readonly id: string;\n readonly inputSchema?: TInput;\n}\n\nexport type WorkflowRunProgress = WorkflowRun & {\n completionPercentage: number;\n totalSteps: number;\n completedSteps: number;\n};\n\nexport interface WorkflowLogger {\n log(message: string): void;\n error(message: string, ...args: unknown[]): void;\n}\n\nexport type WorkflowInternalLoggerContext = {\n runId?: string;\n workflowId?: string;\n};\nexport interface WorkflowInternalLogger {\n log(message: string, context?: WorkflowInternalLoggerContext): void;\n error(message: string, error: Error, context?: WorkflowInternalLoggerContext): void;\n}\n",
|
|
11
|
+
"import type {\n InputParameters,\n StepBaseContext,\n WorkflowContext,\n WorkflowDefinition,\n WorkflowFactory,\n WorkflowOptions,\n WorkflowPlugin,\n WorkflowRef,\n} from './types';\n\n/**\n * Create a lightweight workflow reference.\n * Safe to import from `pg-workflows/client` - no engine or handler code.\n */\nexport function createWorkflowRef<\n TOutput = unknown,\n TInput extends InputParameters = InputParameters,\n>(id: string, options?: { inputSchema?: TInput }): WorkflowRef<TInput, TOutput> {\n const ref = ((\n handler: (context: WorkflowContext<TInput, StepBaseContext>) => Promise<unknown>,\n defineOptions?: Omit<WorkflowOptions<TInput>, 'inputSchema'>,\n ): WorkflowDefinition<TInput> => ({\n id,\n handler: handler as (\n context: WorkflowContext<InputParameters, StepBaseContext>,\n ) => Promise<unknown>,\n inputSchema: options?.inputSchema,\n timeout: defineOptions?.timeout,\n retries: defineOptions?.retries,\n })) as WorkflowRef<TInput, TOutput>;\n\n Object.defineProperty(ref, 'id', { value: id, enumerable: true });\n Object.defineProperty(ref, 'inputSchema', {\n value: options?.inputSchema,\n enumerable: true,\n });\n\n return ref;\n}\n\nfunction createWorkflowFactory<TStepExt extends object = object>(\n plugins: Array<WorkflowPlugin<unknown, object>> = [],\n): WorkflowFactory<TStepExt> {\n const factory = (<I extends InputParameters>(\n id: string,\n handler: (context: WorkflowContext<I, StepBaseContext & TStepExt>) => Promise<unknown>,\n { inputSchema, timeout, retries }: WorkflowOptions<I> = {},\n ): WorkflowDefinition<I> => ({\n id,\n handler: handler as (\n context: WorkflowContext<InputParameters, StepBaseContext>,\n ) => Promise<unknown>,\n inputSchema,\n timeout,\n retries,\n plugins: plugins.length > 0 ? (plugins as WorkflowPlugin[]) : undefined,\n })) as WorkflowFactory<TStepExt>;\n\n factory.use = <TNewExt>(\n plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>,\n ): WorkflowFactory<TStepExt & TNewExt> =>\n createWorkflowFactory<TStepExt & TNewExt>([\n ...plugins,\n plugin as WorkflowPlugin<unknown, object>,\n ]);\n\n factory.ref = createWorkflowRef;\n\n return factory;\n}\n\nexport const workflow: WorkflowFactory = createWorkflowFactory();\n",
|
|
12
12
|
"import parse from 'parse-duration';\nimport { WorkflowEngineError } from './error';\n\nexport type DurationObject = {\n weeks?: number;\n days?: number;\n hours?: number;\n minutes?: number;\n seconds?: number;\n};\n\nexport type Duration = string | DurationObject;\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\n\nexport function parseDuration(duration: Duration): number {\n if (typeof duration === 'string') {\n if (duration.trim() === '') {\n throw new WorkflowEngineError('Invalid duration: empty string');\n }\n\n const ms = parse(duration);\n\n if (ms == null || ms <= 0) {\n throw new WorkflowEngineError(`Invalid duration: \"${duration}\"`);\n }\n\n return ms;\n }\n\n const { weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0 } = duration;\n\n const ms =\n weeks * MS_PER_WEEK +\n days * MS_PER_DAY +\n hours * MS_PER_HOUR +\n minutes * MS_PER_MINUTE +\n seconds * MS_PER_SECOND;\n\n if (ms <= 0) {\n throw new WorkflowEngineError('Invalid duration: must be a positive value');\n }\n\n return ms;\n}\n",
|
|
13
|
-
"import { merge } from 'es-toolkit';\nimport pg from 'pg';\nimport { type Db, type JobWithMetadata, PgBoss } from 'pg-boss';\nimport { parseWorkflowHandler } from './ast-parser';\nimport {\n DEFAULT_PGBOSS_SCHEMA,\n PAUSE_EVENT_NAME,\n WORKFLOW_RUN_DLQ_QUEUE_NAME,\n WORKFLOW_RUN_QUEUE_NAME,\n} from './constants';\nimport { runMigrations } from './db/migration';\nimport {\n getWorkflowRun,\n getWorkflowRuns,\n insertWorkflowRun,\n updateWorkflowRun,\n withPostgresTransaction,\n} from './db/queries';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\nimport { parseDuration } from './duration';\nimport {\n validateResourceId,\n validateWorkflowId,\n WorkflowEngineError,\n WorkflowRunNotFoundError,\n} from './error';\nimport {\n type InferInputParameters,\n type InputParameters,\n StepType,\n type WorkflowContext,\n type WorkflowDefinition,\n type WorkflowInternalDefinition,\n type WorkflowInternalLogger,\n type WorkflowInternalLoggerContext,\n type WorkflowLogger,\n type WorkflowRef,\n type WorkflowRunProgress,\n WorkflowStatus,\n} from './types';\n\nconst LOG_PREFIX = '[WorkflowEngine]';\n\ntype StartWorkflowOptions = {\n resourceId?: string;\n timeout?: number;\n retries?: number;\n expireInSeconds?: number;\n batchSize?: number;\n idempotencyKey?: string;\n};\n\nexport type WorkflowEngineOptions = {\n workflows?: WorkflowDefinition[];\n logger?: WorkflowLogger;\n boss?: PgBoss;\n} & ({ pool: pg.Pool; connectionString?: never } | { connectionString: string; pool?: never });\n\nconst StepTypeToIcon = {\n [StepType.RUN]: 'λ',\n [StepType.WAIT_FOR]: '○',\n [StepType.PAUSE]: '⏸',\n [StepType.WAIT_UNTIL]: '⏲',\n [StepType.DELAY]: '⏱',\n [StepType.POLL]: '↻',\n};\n\n// Timeline entry types\ntype TimelineStepEntry = {\n output?: unknown;\n timedOut?: true;\n timestamp: Date;\n};\n\ntype TimelineWaitForEntry = {\n waitFor: {\n eventName?: string;\n timeoutEvent?: string;\n skipOutput?: true;\n };\n timestamp: Date;\n};\n\ntype WorkflowRunJobParameters = {\n runId: string;\n resourceId?: string;\n workflowId: string;\n input: unknown;\n event?: {\n name: string;\n data?: Record<string, unknown>;\n };\n};\n\nconst defaultLogger: WorkflowLogger = {\n log: (_message: string) => console.warn(_message),\n error: (message: string, error: Error) => console.error(message, error),\n};\n\nconst defaultExpireInSeconds = process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS, 10)\n : 5 * 60; // 5 minutes\n\n// retryDelay is the base for pg-boss's exponential backoff:\n// `retryDelay * 2^retryCount` seconds (with up to ±50% jitter), so a base\n// of 1 second yields ~1s, ~2s, ~4s, ~8s, … between attempts.\nconst retrySendOptions = (maxRetries: number) => ({\n retryLimit: maxRetries,\n retryBackoff: true,\n retryDelay: 1,\n});\n\n// pg-boss workers auto-touch heartbeat_on every heartbeatSeconds / 2 seconds\n// while the process is alive. If the worker dies, heartbeats stop and pg-boss's\n// monitor (~60s ticks) routes the job to the dead-letter queue. Minimum is 10.\nconst defaultHeartbeatSeconds = process.env.WORKFLOW_RUN_HEARTBEAT_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_HEARTBEAT_SECONDS, 10)\n : 30;\n\nexport class WorkflowEngine {\n private boss: PgBoss;\n private db: Db;\n private pool: pg.Pool;\n private _ownsPool = false;\n private unregisteredWorkflows = new Map<string, WorkflowDefinition>();\n private _started = false;\n\n public workflows: Map<string, WorkflowInternalDefinition> = new Map<\n string,\n WorkflowInternalDefinition\n >();\n private logger: WorkflowInternalLogger;\n\n constructor({ workflows, logger, boss, ...connectionOptions }: WorkflowEngineOptions) {\n this.logger = this.buildLogger(logger ?? defaultLogger);\n\n if ('pool' in connectionOptions && connectionOptions.pool) {\n this.pool = connectionOptions.pool;\n } else if ('connectionString' in connectionOptions && connectionOptions.connectionString) {\n this.pool = new pg.Pool({ connectionString: connectionOptions.connectionString });\n this._ownsPool = true;\n } else {\n throw new WorkflowEngineError('Either pool or connectionString must be provided');\n }\n\n if (workflows) {\n this.unregisteredWorkflows = new Map(workflows.map((workflow) => [workflow.id, workflow]));\n }\n\n const db: Db = {\n executeSql: (text: string, values?: unknown[]) =>\n this.pool.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n\n if (boss) {\n this.boss = boss;\n } else {\n this.boss = new PgBoss({ db, schema: DEFAULT_PGBOSS_SCHEMA });\n }\n this.db = this.boss.getDb();\n }\n\n async start(\n asEngine = true,\n {\n batchSize = 1,\n heartbeatSeconds = defaultHeartbeatSeconds,\n }: { batchSize?: number; heartbeatSeconds?: number } = {},\n ): Promise<void> {\n if (this._started) {\n return;\n }\n\n // Start boss first to get the database connection\n await this.boss.start();\n\n await runMigrations(this.boss.getDb());\n\n if (this.unregisteredWorkflows.size > 0) {\n for (const workflow of this.unregisteredWorkflows.values()) {\n await this.registerWorkflow(workflow);\n }\n }\n\n // pg-boss handles retries: every send sets retryLimit + retryBackoff\n // per-job from the workflow's `retries` option. Failures (thrown error,\n // expired job, missed heartbeats) re-enqueue automatically; once a job's\n // retries are exhausted, pg-boss routes it to the DLQ where\n // handleWorkflowRunDlq marks the run FAILED. heartbeatSeconds lets\n // pg-boss detect dead workers in ~heartbeatSeconds + monitorInterval\n // (≈60s) instead of waiting for the full expireInSeconds.\n const mainQueueOptions = {\n retryLimit: 0,\n deadLetter: WORKFLOW_RUN_DLQ_QUEUE_NAME,\n heartbeatSeconds,\n };\n await this.boss.createQueue(WORKFLOW_RUN_DLQ_QUEUE_NAME, { retryLimit: 0 });\n await this.boss.createQueue(WORKFLOW_RUN_QUEUE_NAME, mainQueueOptions);\n // createQueue is a no-op for existing queues; updateQueue ensures\n // installations that predate the DLQ adopt these settings on next start.\n await this.boss.updateQueue(WORKFLOW_RUN_QUEUE_NAME, mainQueueOptions);\n\n const numWorkers: number = +(process.env.WORKFLOW_RUN_WORKERS ?? 3);\n\n if (asEngine) {\n // includeMetadata exposes job.retryCount so we can mirror pg-boss's\n // attempt counter into workflow_runs.retryCount.\n await Promise.all(\n Array.from({ length: numWorkers }, (_, i) =>\n this.boss\n .work<WorkflowRunJobParameters>(\n WORKFLOW_RUN_QUEUE_NAME,\n { pollingIntervalSeconds: 0.5, batchSize, includeMetadata: true },\n (jobs) => this.handleWorkflowRun(jobs),\n )\n .then(() => {\n this.logger.log(\n `Worker ${i + 1}/${numWorkers} started for queue ${WORKFLOW_RUN_QUEUE_NAME}`,\n );\n }),\n ),\n );\n\n await this.boss.work<WorkflowRunJobParameters>(\n WORKFLOW_RUN_DLQ_QUEUE_NAME,\n { pollingIntervalSeconds: 0.5, batchSize: 1 },\n (jobs) => this.handleWorkflowRunDlq(jobs),\n );\n this.logger.log(`Worker started for queue ${WORKFLOW_RUN_DLQ_QUEUE_NAME}`);\n }\n\n this._started = true;\n\n this.logger.log('Workflow engine started!');\n }\n\n async stop(): Promise<void> {\n await this.boss.stop();\n\n if (this._ownsPool) {\n await this.pool.end();\n }\n\n this._started = false;\n\n this.logger.log('Workflow engine stopped');\n }\n\n async registerWorkflow(definition: WorkflowDefinition<InputParameters>): Promise<WorkflowEngine> {\n if (this.workflows.has(definition.id)) {\n throw new WorkflowEngineError(\n `Workflow ${definition.id} is already registered`,\n definition.id,\n );\n }\n\n const { steps } = parseWorkflowHandler(\n definition.handler as (context: WorkflowContext) => Promise<unknown>,\n );\n\n this.workflows.set(definition.id, {\n ...definition,\n steps,\n } as WorkflowInternalDefinition);\n\n this.logger.log(`Registered workflow \"${definition.id}\" with steps:`);\n for (const step of steps.values()) {\n const tags = [];\n if (step.conditional) tags.push('[conditional]');\n if (step.loop) tags.push('[loop]');\n if (step.isDynamic) tags.push('[dynamic]');\n this.logger.log(` └─ (${StepTypeToIcon[step.type]}) ${step.id} ${tags.join(' ')}`);\n }\n\n return this;\n }\n\n async unregisterWorkflow(workflowId: string): Promise<WorkflowEngine> {\n this.workflows.delete(workflowId);\n return this;\n }\n\n async unregisterAllWorkflows(): Promise<WorkflowEngine> {\n this.workflows.clear();\n return this;\n }\n\n async startWorkflow<TInput extends InputParameters>(\n ref: WorkflowRef<TInput>,\n input: InferInputParameters<TInput>,\n options?: StartWorkflowOptions,\n ): Promise<WorkflowRun>;\n\n async startWorkflow(params: {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n }): Promise<WorkflowRun>;\n\n async startWorkflow<TInput extends InputParameters>(\n refOrParams:\n | WorkflowRef<TInput>\n | {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n },\n inputArg?: InferInputParameters<TInput>,\n optionsArg?: StartWorkflowOptions,\n ): Promise<WorkflowRun> {\n let workflowId: string;\n let input: unknown;\n let resourceId: string | undefined;\n let idempotencyKey: string | undefined;\n let options: StartWorkflowOptions | undefined;\n\n if (typeof refOrParams === 'function' && 'id' in refOrParams) {\n workflowId = refOrParams.id;\n input = inputArg;\n options = optionsArg;\n resourceId = optionsArg?.resourceId;\n idempotencyKey = optionsArg?.idempotencyKey;\n } else {\n const params = refOrParams as {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n };\n workflowId = params.workflowId;\n input = params.input;\n resourceId = params.resourceId;\n idempotencyKey = params.idempotencyKey;\n options = params.options;\n }\n\n validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n if (!this._started) {\n await this.start(false, { batchSize: options?.batchSize ?? 1 });\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Unknown workflow ${workflowId}`);\n }\n\n const hasSteps = workflow.steps.length > 0 && workflow.steps[0];\n const hasPlugins = (workflow.plugins?.length ?? 0) > 0;\n if (!hasSteps && !hasPlugins) {\n throw new WorkflowEngineError(`Workflow ${workflowId} has no steps`, workflowId);\n }\n if (workflow.inputSchema) {\n const result = await workflow.inputSchema['~standard'].validate(input);\n if (result.issues) {\n throw new WorkflowEngineError(\n JSON.stringify(result.issues),\n workflowId,\n undefined,\n undefined,\n result.issues,\n );\n }\n }\n\n const initialStepId = workflow.steps[0]?.id ?? '__start__';\n\n const run = await withPostgresTransaction(\n this.boss.getDb(),\n async (_db) => {\n const timeoutAt = options?.timeout\n ? new Date(Date.now() + options.timeout)\n : workflow.timeout\n ? new Date(Date.now() + workflow.timeout)\n : null;\n\n const { run: insertedRun, created } = await insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId: initialStepId,\n status: WorkflowStatus.RUNNING,\n input,\n maxRetries: options?.retries ?? workflow.retries ?? 0,\n timeoutAt,\n idempotencyKey,\n },\n _db,\n );\n\n if (created) {\n const job: WorkflowRunJobParameters = {\n runId: insertedRun.id,\n resourceId,\n workflowId,\n input,\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: new Date(),\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n ...retrySendOptions(insertedRun.maxRetries),\n });\n }\n\n return insertedRun;\n },\n this.pool,\n );\n\n this.logger.log('Started workflow run', {\n runId: run.id,\n workflowId,\n });\n\n return run;\n }\n\n async pauseWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n // TODO: Pause all running steps immediately\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.PAUSED,\n pausedAt: new Date(),\n },\n expectedStatuses: [WorkflowStatus.RUNNING, WorkflowStatus.PENDING],\n });\n\n this.logger.log('Paused workflow run', {\n runId,\n workflowId: run.workflowId,\n });\n\n return run;\n }\n\n async resumeWorkflow({\n runId,\n resourceId,\n options,\n }: {\n runId: string;\n resourceId?: string;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const current = await this.getRun({ runId, resourceId });\n if (current.status !== WorkflowStatus.PAUSED) {\n throw new WorkflowEngineError(\n `Cannot resume workflow run in '${current.status}' status, must be 'paused'`,\n current.workflowId,\n runId,\n );\n }\n\n return this.triggerEvent({\n runId,\n resourceId,\n eventName: PAUSE_EVENT_NAME,\n data: {},\n options,\n });\n }\n\n async fastForwardWorkflow({\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data?: Record<string, unknown>;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n if (run.status !== WorkflowStatus.PAUSED) {\n return run;\n }\n\n const stepId = run.currentStepId;\n const waitForStep = this.getWaitForStepEntry(run.timeline, stepId);\n\n if (!waitForStep) {\n return run;\n }\n\n const { eventName, timeoutEvent, skipOutput } = waitForStep.waitFor;\n\n // step.pause() - delegate to resumeWorkflow\n if (eventName === PAUSE_EVENT_NAME) {\n return this.resumeWorkflow({ runId, resourceId });\n }\n\n // step.poll() - write output to timeline first, then trigger resume\n if (skipOutput && timeoutEvent) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun({ runId, resourceId }, { exclusiveLock: true, db });\n return this.updateRun(\n {\n runId,\n resourceId,\n data: {\n timeline: merge(freshRun.timeline, {\n [stepId]: {\n output: data ?? {},\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });\n }\n\n // waitFor steps - trigger the event with data\n if (eventName) {\n return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });\n }\n\n // delay/waitUntil steps - trigger the timeout event\n if (timeoutEvent) {\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });\n }\n\n return run;\n }\n\n async cancelWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.CANCELLED,\n },\n expectedStatuses: [WorkflowStatus.PENDING, WorkflowStatus.RUNNING, WorkflowStatus.PAUSED],\n });\n\n this.logger.log(`cancelled workflow run with id ${runId}`);\n\n return run;\n }\n\n async triggerEvent({\n runId,\n resourceId,\n eventName,\n data,\n options,\n }: {\n runId: string;\n resourceId?: string;\n eventName: string;\n data?: Record<string, unknown>;\n options?: {\n expireInSeconds?: number;\n };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n const jobResourceId = resourceId ?? run.resourceId ?? undefined;\n\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: jobResourceId,\n workflowId: run.workflowId,\n input: run.input,\n event: {\n name: eventName,\n data,\n },\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n });\n\n this.logger.log(`event ${eventName} sent for workflow run with id ${runId}`);\n return run;\n }\n\n async getRun(\n { runId, resourceId }: { runId: string; resourceId?: string },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await getWorkflowRun({ runId, resourceId }, { exclusiveLock, db: db ?? this.db });\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async updateRun(\n {\n runId,\n resourceId,\n data,\n expectedStatuses,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n expectedStatuses?: string[];\n },\n { db }: { db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await updateWorkflowRun(\n { runId, resourceId, data, expectedStatuses },\n db ?? this.db,\n );\n\n if (!run) {\n if (expectedStatuses) {\n const current = await getWorkflowRun({ runId, resourceId }, { db: db ?? this.db });\n if (current) {\n throw new WorkflowEngineError(\n `Cannot update workflow run in '${current.status}' status, expected: ${expectedStatuses.join(', ')}`,\n current.workflowId,\n runId,\n );\n }\n }\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async checkProgress({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRunProgress> {\n const run = await this.getRun({ runId, resourceId });\n const workflow = this.workflows.get(run.workflowId);\n\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${run.workflowId} not found`, run.workflowId, runId);\n }\n const steps = workflow?.steps ?? [];\n\n let completionPercentage = 0;\n let completedSteps = 0;\n\n if (steps.length > 0) {\n completedSteps = Object.values(run.timeline).filter(\n (step): step is TimelineStepEntry =>\n typeof step === 'object' &&\n step !== null &&\n 'output' in step &&\n step.output !== undefined,\n ).length;\n\n if (run.status === WorkflowStatus.COMPLETED) {\n completionPercentage = 100;\n } else if (run.status === WorkflowStatus.FAILED || run.status === WorkflowStatus.CANCELLED) {\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n } else {\n const currentStepIndex = steps.findIndex((step) => step.id === run.currentStepId);\n if (currentStepIndex >= 0) {\n completionPercentage = (currentStepIndex / steps.length) * 100;\n } else {\n const completedSteps = Object.keys(run.timeline).length;\n\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n }\n }\n }\n\n return {\n ...run,\n completedSteps,\n completionPercentage: Math.round(completionPercentage * 100) / 100, // Round to 2 decimal places\n totalSteps: steps.length,\n };\n }\n\n /**\n * Resolves the resource id used for scoped DB access (getRun/updateRun).\n * When the job omits resourceId, the run's stored resourceId is used.\n * When the job includes resourceId, it must match the run's resourceId if the run is scoped;\n * unscoped runs reject a job-supplied resourceId (authorization).\n */\n private resolveScopedResourceId(\n jobResourceId: string | undefined,\n run: WorkflowRun,\n ): string | undefined {\n const jobResourceProvided =\n jobResourceId !== undefined && jobResourceId !== null && jobResourceId !== '';\n\n if (jobResourceProvided) {\n if (run.resourceId === null) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n if (run.resourceId !== jobResourceId) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n return jobResourceId;\n }\n\n return run.resourceId ?? undefined;\n }\n\n private async handleWorkflowRun([job]: JobWithMetadata<WorkflowRunJobParameters>[]) {\n const { runId = '', resourceId, workflowId = '', event } = job?.data ?? {};\n\n let run: WorkflowRun | undefined;\n let scopedResourceId: string | undefined;\n\n try {\n if (!runId) {\n throw new WorkflowEngineError('Invalid workflow run job, missing runId', workflowId);\n }\n\n if (!workflowId) {\n throw new WorkflowEngineError(\n 'Invalid workflow run job, missing workflowId',\n undefined,\n runId,\n );\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${workflowId} not found`, workflowId, runId);\n }\n\n this.logger.log('Processing workflow run...', {\n runId,\n workflowId,\n });\n\n run = await this.getRun({ runId });\n\n if (run.workflowId !== workflowId) {\n throw new WorkflowEngineError(\n `Workflow run ${runId} does not match job workflowId ${workflowId}`,\n workflowId,\n runId,\n );\n }\n\n scopedResourceId = this.resolveScopedResourceId(resourceId, run);\n\n // Mirror pg-boss's attempt counter so workflow_runs.retryCount stays\n // observable to API consumers across retries.\n if (job?.retryCount !== undefined && run.retryCount !== job.retryCount) {\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: { retryCount: job.retryCount },\n });\n run = { ...run, retryCount: job.retryCount };\n }\n\n if (run.status === WorkflowStatus.CANCELLED) {\n this.logger.log(`Workflow run ${runId} is cancelled, skipping`);\n return;\n }\n\n if (!run.currentStepId) {\n throw new WorkflowEngineError('Missing current step id', workflowId, runId);\n }\n\n if (run.status === WorkflowStatus.PAUSED) {\n run = await withPostgresTransaction(\n this.db,\n async (db) => {\n const lockedRun = await this.getRun(\n { runId, resourceId: scopedResourceId },\n { exclusiveLock: true, db },\n );\n if (lockedRun.status !== WorkflowStatus.PAUSED) {\n return lockedRun;\n }\n\n const waitForStep = this.getWaitForStepEntry(\n lockedRun.timeline,\n lockedRun.currentStepId,\n );\n const currentStep = this.getCachedStepEntry(\n lockedRun.timeline,\n lockedRun.currentStepId,\n );\n const waitFor = waitForStep?.waitFor;\n const hasCurrentStepOutput = currentStep?.output !== undefined;\n\n const eventMatches =\n waitFor &&\n event?.name &&\n (event.name === waitFor.eventName || event.name === waitFor.timeoutEvent) &&\n !hasCurrentStepOutput;\n\n if (eventMatches) {\n const isTimeout = event?.name === waitFor?.timeoutEvent;\n const skipOutput = waitFor?.skipOutput;\n return this.updateRun(\n {\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n ...(skipOutput\n ? {}\n : {\n timeline: merge(lockedRun.timeline, {\n [lockedRun.currentStepId]: {\n output: event?.data ?? {},\n ...(isTimeout ? { timedOut: true as const } : {}),\n timestamp: new Date(),\n },\n }),\n }),\n },\n },\n { db },\n );\n }\n\n return this.updateRun(\n {\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n },\n },\n { db },\n );\n },\n this.pool,\n );\n }\n\n const baseStep = {\n run: async <T>(stepId: string, handler: () => Promise<T>) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n return this.runStep({ stepId, run, handler }) as Promise<T>;\n },\n waitFor: async <T extends InputParameters>(\n stepId: string,\n { eventName, timeout }: { eventName: string; timeout?: number; schema?: T },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const timeoutDate = timeout ? new Date(Date.now() + timeout) : undefined;\n return this.waitStep({ run, stepId, eventName, timeoutDate }) as Promise<\n InferInputParameters<T> | undefined\n >;\n },\n waitUntil: async (\n stepId: string,\n dateOrOptions: Date | string | { date: Date | string },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const date =\n dateOrOptions instanceof Date\n ? dateOrOptions\n : typeof dateOrOptions === 'string'\n ? new Date(dateOrOptions)\n : dateOrOptions.date instanceof Date\n ? dateOrOptions.date\n : new Date(dateOrOptions.date);\n await this.waitStep({ run, stepId, timeoutDate: date });\n },\n pause: async (stepId: string) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({ run, stepId, eventName: PAUSE_EVENT_NAME });\n },\n delay: async (stepId: string, duration: Duration) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({\n run,\n stepId,\n timeoutDate: new Date(Date.now() + parseDuration(duration)),\n });\n },\n get sleep() {\n return this.delay;\n },\n poll: async <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const intervalMs = parseDuration(options?.interval ?? '30s');\n if (intervalMs < 30_000) {\n throw new WorkflowEngineError(\n `step.poll interval must be at least 30s (got ${intervalMs}ms)`,\n workflowId,\n runId,\n );\n }\n const timeoutMs = options?.timeout ? parseDuration(options.timeout) : undefined;\n return this.pollStep({ run, stepId, conditionFn, intervalMs, timeoutMs }) as Promise<\n { timedOut: false; data: T } | { timedOut: true }\n >;\n },\n };\n\n let step = { ...baseStep };\n const plugins = workflow.plugins ?? [];\n for (const plugin of plugins) {\n const extra = plugin.methods(step);\n step = { ...step, ...extra };\n }\n\n const context: WorkflowContext = {\n input: run.input as InferInputParameters<InputParameters>,\n workflowId: run.workflowId,\n runId: run.id,\n timeline: run.timeline,\n logger: this.logger,\n step,\n };\n\n const result = await workflow.handler(context);\n\n run = await this.getRun({ runId, resourceId: scopedResourceId });\n\n const isLastParsedStep = run.currentStepId === workflow.steps[workflow.steps.length - 1]?.id;\n const hasPluginSteps = (workflow.plugins?.length ?? 0) > 0;\n const noParsedSteps = workflow.steps.length === 0;\n const shouldComplete =\n run.status === WorkflowStatus.RUNNING &&\n (noParsedSteps || isLastParsedStep || (hasPluginSteps && result !== undefined));\n if (shouldComplete) {\n const normalizedResult = result === undefined ? {} : result;\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.COMPLETED,\n output: normalizedResult,\n completedAt: new Date(),\n jobId: job?.id,\n },\n });\n\n this.logger.log('Workflow run completed.', {\n runId,\n workflowId,\n });\n }\n } catch (error) {\n // Persist the error so the DLQ handler can surface it after retries\n // are exhausted. pg-boss handles the retry-vs-DLQ decision based on\n // the per-job retryLimit set when the job was enqueued.\n if (runId) {\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n error: error instanceof Error ? error.message : String(error),\n jobId: job?.id,\n },\n });\n }\n\n throw error;\n }\n }\n\n /**\n * Reconciles workflow runs whose retries pg-boss has exhausted (handler\n * threw on the final attempt, or worker died and missed the heartbeat\n * past the retry budget). The DLQ entry tells us the run is unrecoverable;\n * we mark it FAILED with whatever error message the catch block last\n * persisted, falling back to a worker-death message.\n */\n private async handleWorkflowRunDlq([job]: { data?: WorkflowRunJobParameters }[]) {\n const { runId } = job?.data ?? {};\n if (!runId) return;\n\n const run = await getWorkflowRun({ runId }, { db: this.db });\n if (!run || run.status !== WorkflowStatus.RUNNING) return;\n\n await this.updateRun({\n runId,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.FAILED,\n error: run.error ?? 'Workflow run worker died or job expired before completion',\n },\n });\n\n this.logger.log('Marked stuck workflow run as failed', {\n runId,\n workflowId: run.workflowId,\n });\n }\n\n private getCachedStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineStepEntry | null {\n const stepEntry = timeline[stepId];\n return stepEntry && typeof stepEntry === 'object' && 'output' in stepEntry\n ? (stepEntry as TimelineStepEntry)\n : null;\n }\n\n private getWaitForStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineWaitForEntry | null {\n const entry = timeline[`${stepId}-wait-for`];\n return entry && typeof entry === 'object' && 'waitFor' in entry\n ? (entry as TimelineWaitForEntry)\n : null;\n }\n\n private async runStep({\n stepId,\n run,\n handler,\n }: {\n stepId: string;\n run: WorkflowRun;\n handler: () => Promise<unknown>;\n }) {\n return withPostgresTransaction(\n this.db,\n async (db) => {\n const persistedRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n {\n exclusiveLock: true,\n db,\n },\n );\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n this.logger.log(`Step ${stepId} skipped, workflow run is ${persistedRun.status}`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return;\n }\n\n try {\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.output;\n }\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n },\n },\n { db },\n );\n\n this.logger.log(`Running step ${stepId}...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n let output = await handler();\n\n if (output === undefined) {\n output = {};\n }\n\n run = await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n timeline: merge(persistedRun.timeline, {\n [stepId]: {\n output,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n\n return output;\n } catch (error) {\n this.logger.error(`Step ${stepId} failed:`, error as Error, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.FAILED,\n error: error instanceof Error ? `${error.message}\\n${error.stack}` : String(error),\n },\n },\n { db },\n );\n\n throw error;\n }\n },\n this.pool,\n );\n }\n\n private async waitStep({\n run,\n stepId,\n eventName,\n timeoutDate,\n }: {\n run: WorkflowRun;\n stepId: string;\n eventName?: string;\n timeoutDate?: Date;\n }): Promise<unknown> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return;\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? undefined : cached.output;\n }\n\n const timeoutEvent = timeoutDate ? `__timeout_${stepId}` : undefined;\n\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(freshRun.timeline, {\n [`${stepId}-wait-for`]: {\n waitFor: { eventName, timeoutEvent },\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n\n if (timeoutDate && timeoutEvent) {\n try {\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: timeoutEvent, data: { date: timeoutDate.toISOString() } },\n };\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: timeoutDate.getTime() <= Date.now() ? new Date() : timeoutDate,\n expireInSeconds: defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n });\n } catch (error) {\n // Revert PAUSED status so the workflow can retry this step\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: { status: WorkflowStatus.RUNNING, pausedAt: null },\n });\n throw error;\n }\n }\n\n this.logger.log(\n `Step ${stepId} waiting${eventName ? ` for event \"${eventName}\"` : ''}${timeoutDate ? ` until ${timeoutDate.toISOString()}` : ''}`,\n { runId: run.id, workflowId: run.workflowId },\n );\n }\n\n private async pollStep<T>({\n run,\n stepId,\n conditionFn,\n intervalMs,\n timeoutMs,\n }: {\n run: WorkflowRun;\n stepId: string;\n conditionFn: () => Promise<T | false>;\n intervalMs: number;\n timeoutMs?: number;\n }): Promise<{ timedOut: false; data: T } | { timedOut: true } | undefined> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return { timedOut: true };\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? { timedOut: true } : { timedOut: false, data: cached.output as T };\n }\n\n const pollStateEntry = persistedRun.timeline[`${stepId}-poll`];\n const startedAt =\n pollStateEntry && typeof pollStateEntry === 'object' && 'startedAt' in pollStateEntry\n ? new Date((pollStateEntry as { startedAt: string }).startedAt)\n : new Date();\n\n if (timeoutMs !== undefined && Date.now() >= startedAt.getTime() + timeoutMs) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(freshRun.timeline, {\n [stepId]: { output: {}, timedOut: true as const, timestamp: new Date() },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n return { timedOut: true };\n }\n\n let result: T | false;\n try {\n result = await conditionFn();\n } catch (error) {\n this.logger.error(\n `Poll conditionFn for step ${stepId} threw an error, treating as non-match and continuing to poll`,\n error as Error,\n { runId: run.id, workflowId: run.workflowId },\n );\n\n // If the poll has timed out, respect the timeout even though conditionFn threw\n if (timeoutMs !== undefined && Date.now() >= startedAt.getTime() + timeoutMs) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(freshRun.timeline, {\n [stepId]: { output: {}, timedOut: true as const, timestamp: new Date() },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n return { timedOut: true };\n }\n\n result = false;\n }\n\n if (result !== false) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(freshRun.timeline, {\n [stepId]: { output: result, timestamp: new Date() },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n return { timedOut: false, data: result };\n }\n\n const pollEvent = `__poll_${stepId}`;\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(freshRun.timeline, {\n [`${stepId}-poll`]: { startedAt: startedAt.toISOString() },\n [`${stepId}-wait-for`]: {\n waitFor: { timeoutEvent: pollEvent, skipOutput: true },\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n\n try {\n await this.boss.send(\n WORKFLOW_RUN_QUEUE_NAME,\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: pollEvent, data: {} },\n },\n {\n startAfter: new Date(Date.now() + intervalMs),\n expireInSeconds: defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n },\n );\n } catch (error) {\n // Revert PAUSED status so the workflow can retry this step\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: { status: WorkflowStatus.RUNNING, pausedAt: null },\n });\n throw error;\n }\n\n this.logger.log(`Step ${stepId} polling every ${intervalMs}ms...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return { timedOut: false, data: undefined as T };\n }\n\n private async checkIfHasStarted(): Promise<void> {\n if (!this._started) {\n throw new WorkflowEngineError('Workflow engine not started');\n }\n }\n\n private buildLogger(logger: WorkflowLogger): WorkflowInternalLogger {\n return {\n log: (message: string, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.log(`${parts}: ${message}`);\n },\n error: (message: string, error: Error, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.error(`${parts}: ${message}`, error);\n },\n };\n }\n\n async getRuns({\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: WorkflowStatus[];\n workflowId?: string;\n }): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n }> {\n if (workflowId) validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n return getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit,\n statuses,\n workflowId,\n },\n this.db,\n );\n }\n}\n",
|
|
14
|
-
"import * as ts from 'typescript';\nimport type { StepInternalDefinition, WorkflowContext } from './types';\nimport { StepType } from './types';\n\ntype ParseWorkflowHandlerReturnType = {\n steps: StepInternalDefinition[];\n};\n\nexport function parseWorkflowHandler(\n handler: (context: WorkflowContext) => Promise<unknown>,\n): ParseWorkflowHandlerReturnType {\n const handlerSource = handler.toString();\n const sourceFile = ts.createSourceFile('handler.ts', handlerSource, ts.ScriptTarget.Latest, true);\n\n const steps: Map<string, StepInternalDefinition> = new Map();\n\n function isInConditional(node: ts.Node): boolean {\n let current = node.parent;\n while (current) {\n if (\n ts.isIfStatement(current) ||\n ts.isConditionalExpression(current) ||\n ts.isSwitchStatement(current) ||\n ts.isCaseClause(current)\n ) {\n return true;\n }\n current = current.parent;\n }\n return false;\n }\n\n function isInLoop(node: ts.Node): boolean {\n let current = node.parent;\n while (current) {\n if (\n ts.isForStatement(current) ||\n ts.isForInStatement(current) ||\n ts.isForOfStatement(current) ||\n ts.isWhileStatement(current) ||\n ts.isDoStatement(current)\n ) {\n return true;\n }\n current = current.parent;\n }\n return false;\n }\n\n function extractStepId(arg: ts.Expression): {\n id: string;\n isDynamic: boolean;\n } {\n if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) {\n return { id: arg.text, isDynamic: false };\n }\n\n if (ts.isTemplateExpression(arg)) {\n let templateStr = arg.head.text;\n for (const span of arg.templateSpans) {\n templateStr += `\\${...}`;\n templateStr += span.literal.text;\n }\n return { id: templateStr, isDynamic: true };\n }\n\n return { id: arg.getText(sourceFile), isDynamic: true };\n }\n\n function visit(node: ts.Node) {\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {\n const propertyAccess = node.expression;\n const objectName = propertyAccess.expression.getText(sourceFile);\n const methodName = propertyAccess.name.text;\n\n if (\n objectName === 'step' &&\n (methodName === 'run' ||\n methodName === 'waitFor' ||\n methodName === 'pause' ||\n methodName === 'waitUntil' ||\n methodName === 'delay' ||\n methodName === 'sleep' ||\n methodName === 'poll')\n ) {\n const firstArg = node.arguments[0];\n if (firstArg) {\n const { id, isDynamic } = extractStepId(firstArg);\n const stepType = methodName === 'sleep' ? StepType.DELAY : (methodName as StepType);\n\n const stepDefinition: StepInternalDefinition = {\n id,\n type: stepType,\n conditional: isInConditional(node),\n loop: isInLoop(node),\n isDynamic,\n };\n\n if (steps.has(id)) {\n throw new Error(\n `Duplicate step ID detected: '${id}'. Step IDs must be unique within a workflow.`,\n );\n }\n\n steps.set(id, stepDefinition);\n }\n }\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n\n return { steps: Array.from(steps.values()) };\n}\n"
|
|
13
|
+
"import { merge } from 'es-toolkit';\nimport pg from 'pg';\nimport { type Db, type JobWithMetadata, PgBoss } from 'pg-boss';\nimport { parseWorkflowHandler } from './ast-parser';\nimport {\n DEFAULT_PGBOSS_SCHEMA,\n invokeChildWorkflowTimelineKey,\n isInvokeChildWorkflowTimelineEntry,\n PAUSE_EVENT_NAME,\n WORKFLOW_RUN_DLQ_QUEUE_NAME,\n WORKFLOW_RUN_QUEUE_NAME,\n waitForTimelineKey,\n} from './constants';\nimport { runMigrations } from './db/migration';\nimport {\n getWorkflowRun,\n getWorkflowRuns,\n insertWorkflowRun,\n updateWorkflowRun,\n withPostgresTransaction,\n} from './db/queries';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\nimport { parseDuration } from './duration';\nimport {\n validateResourceId,\n validateWorkflowId,\n WorkflowEngineError,\n WorkflowRunNotFoundError,\n} from './error';\nimport {\n type InferInputParameters,\n type InputParameters,\n StepType,\n type WorkflowContext,\n type WorkflowDefinition,\n type WorkflowInternalDefinition,\n type WorkflowInternalLogger,\n type WorkflowInternalLoggerContext,\n type WorkflowLogger,\n type WorkflowRef,\n type WorkflowRunOptions,\n type WorkflowRunProgress,\n WorkflowStatus,\n} from './types';\n\nconst LOG_PREFIX = '[WorkflowEngine]';\n\ntype StartWorkflowOptions = WorkflowRunOptions & {\n batchSize?: number;\n};\n\ntype ResolvedWorkflowRunParameters<TOptions extends WorkflowRunOptions = WorkflowRunOptions> = {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: TOptions;\n};\n\nexport type WorkflowEngineOptions = {\n workflows?: WorkflowDefinition[];\n logger?: WorkflowLogger;\n boss?: PgBoss;\n} & ({ pool: pg.Pool; connectionString?: never } | { connectionString: string; pool?: never });\n\nconst StepTypeToIcon = {\n [StepType.RUN]: 'λ',\n [StepType.WAIT_FOR]: '○',\n [StepType.PAUSE]: '⏸',\n [StepType.WAIT_UNTIL]: '⏲',\n [StepType.DELAY]: '⏱',\n [StepType.POLL]: '↻',\n [StepType.INVOKE_CHILD_WORKFLOW]: '↪',\n};\n\n// Timeline entry types\ntype TimelineStepEntry = {\n output?: unknown;\n timedOut?: true;\n timestamp: Date;\n};\n\ntype TimelineWaitForEntry = {\n waitFor: {\n eventName?: string;\n timeoutEvent?: string;\n skipOutput?: true;\n };\n timestamp: Date;\n};\n\ntype TimelineInvokeChildWorkflowEntry = {\n invokeChildWorkflow: {\n childRunId: string;\n childWorkflowId: string;\n childResourceId?: string | null;\n };\n timestamp: Date;\n};\n\ntype WorkflowRunJobParameters = {\n runId: string;\n resourceId?: string;\n workflowId: string;\n input: unknown;\n event?: {\n name: string;\n data?: unknown;\n };\n};\n\nconst defaultLogger: WorkflowLogger = {\n log: (_message: string) => console.warn(_message),\n error: (message: string, error: Error) => console.error(message, error),\n};\n\nconst defaultExpireInSeconds = process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS, 10)\n : 5 * 60; // 5 minutes\n\n// retryDelay is the base for pg-boss's exponential backoff:\n// `retryDelay * 2^retryCount` seconds (with up to ±50% jitter), so a base\n// of 1 second yields ~1s, ~2s, ~4s, ~8s, … between attempts.\nconst retrySendOptions = (maxRetries: number) => ({\n retryLimit: maxRetries,\n retryBackoff: true,\n retryDelay: 1,\n});\n\nconst getInvokeChildWorkflowEventName = (childRunId: string) =>\n `__invoke_child_workflow_completed:${childRunId}`;\n\n// pg-boss workers auto-touch heartbeat_on every heartbeatSeconds / 2 seconds\n// while the process is alive. If the worker dies, heartbeats stop and pg-boss's\n// monitor (~60s ticks) routes the job to the dead-letter queue. Minimum is 10.\nconst defaultHeartbeatSeconds = process.env.WORKFLOW_RUN_HEARTBEAT_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_HEARTBEAT_SECONDS, 10)\n : 30;\n\nexport class WorkflowEngine {\n private boss: PgBoss;\n private db: Db;\n private pool: pg.Pool;\n private _ownsPool = false;\n private unregisteredWorkflows = new Map<string, WorkflowDefinition>();\n private _started = false;\n\n public workflows: Map<string, WorkflowInternalDefinition> = new Map<\n string,\n WorkflowInternalDefinition\n >();\n private logger: WorkflowInternalLogger;\n\n constructor({ workflows, logger, boss, ...connectionOptions }: WorkflowEngineOptions) {\n this.logger = this.buildLogger(logger ?? defaultLogger);\n\n if ('pool' in connectionOptions && connectionOptions.pool) {\n this.pool = connectionOptions.pool;\n } else if ('connectionString' in connectionOptions && connectionOptions.connectionString) {\n this.pool = new pg.Pool({ connectionString: connectionOptions.connectionString });\n this._ownsPool = true;\n } else {\n throw new WorkflowEngineError('Either pool or connectionString must be provided');\n }\n\n if (workflows) {\n this.unregisteredWorkflows = new Map(workflows.map((workflow) => [workflow.id, workflow]));\n }\n\n const db: Db = {\n executeSql: (text: string, values?: unknown[]) =>\n this.pool.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n\n if (boss) {\n this.boss = boss;\n } else {\n this.boss = new PgBoss({ db, schema: DEFAULT_PGBOSS_SCHEMA });\n }\n this.db = this.boss.getDb();\n }\n\n async start(\n asEngine = true,\n {\n batchSize = 1,\n heartbeatSeconds = defaultHeartbeatSeconds,\n }: { batchSize?: number; heartbeatSeconds?: number } = {},\n ): Promise<void> {\n if (this._started) {\n return;\n }\n\n // Start boss first to get the database connection\n await this.boss.start();\n\n await runMigrations(this.boss.getDb());\n\n if (this.unregisteredWorkflows.size > 0) {\n for (const workflow of this.unregisteredWorkflows.values()) {\n await this.registerWorkflow(workflow);\n }\n }\n\n // pg-boss handles retries: every send sets retryLimit + retryBackoff\n // per-job from the workflow's `retries` option. Failures (thrown error,\n // expired job, missed heartbeats) re-enqueue automatically; once a job's\n // retries are exhausted, pg-boss routes it to the DLQ where\n // handleWorkflowRunDlq marks the run FAILED. heartbeatSeconds lets\n // pg-boss detect dead workers in ~heartbeatSeconds + monitorInterval\n // (≈60s) instead of waiting for the full expireInSeconds.\n const mainQueueOptions = {\n retryLimit: 0,\n deadLetter: WORKFLOW_RUN_DLQ_QUEUE_NAME,\n heartbeatSeconds,\n };\n await this.boss.createQueue(WORKFLOW_RUN_DLQ_QUEUE_NAME, { retryLimit: 0 });\n await this.boss.createQueue(WORKFLOW_RUN_QUEUE_NAME, mainQueueOptions);\n // createQueue is a no-op for existing queues; updateQueue ensures\n // installations that predate the DLQ adopt these settings on next start.\n await this.boss.updateQueue(WORKFLOW_RUN_QUEUE_NAME, mainQueueOptions);\n\n const numWorkers: number = +(process.env.WORKFLOW_RUN_WORKERS ?? 3);\n\n if (asEngine) {\n // includeMetadata exposes job.retryCount so we can mirror pg-boss's\n // attempt counter into workflow_runs.retryCount.\n await Promise.all(\n Array.from({ length: numWorkers }, (_, i) =>\n this.boss\n .work<WorkflowRunJobParameters>(\n WORKFLOW_RUN_QUEUE_NAME,\n { pollingIntervalSeconds: 0.5, batchSize, includeMetadata: true },\n (jobs) => this.handleWorkflowRun(jobs),\n )\n .then(() => {\n this.logger.log(\n `Worker ${i + 1}/${numWorkers} started for queue ${WORKFLOW_RUN_QUEUE_NAME}`,\n );\n }),\n ),\n );\n\n await this.boss.work<WorkflowRunJobParameters>(\n WORKFLOW_RUN_DLQ_QUEUE_NAME,\n { pollingIntervalSeconds: 0.5, batchSize: 1 },\n (jobs) => this.handleWorkflowRunDlq(jobs),\n );\n this.logger.log(`Worker started for queue ${WORKFLOW_RUN_DLQ_QUEUE_NAME}`);\n }\n\n this._started = true;\n\n this.logger.log('Workflow engine started!');\n }\n\n async stop(): Promise<void> {\n await this.boss.stop();\n\n if (this._ownsPool) {\n await this.pool.end();\n }\n\n this._started = false;\n\n this.logger.log('Workflow engine stopped');\n }\n\n async registerWorkflow(definition: WorkflowDefinition<InputParameters>): Promise<WorkflowEngine> {\n if (this.workflows.has(definition.id)) {\n throw new WorkflowEngineError(\n `Workflow ${definition.id} is already registered`,\n definition.id,\n );\n }\n\n const { steps } = parseWorkflowHandler(\n definition.handler as (context: WorkflowContext) => Promise<unknown>,\n );\n\n this.workflows.set(definition.id, {\n ...definition,\n steps,\n } as WorkflowInternalDefinition);\n\n this.logger.log(`Registered workflow \"${definition.id}\" with steps:`);\n for (const step of steps.values()) {\n const tags = [];\n if (step.conditional) tags.push('[conditional]');\n if (step.loop) tags.push('[loop]');\n if (step.isDynamic) tags.push('[dynamic]');\n this.logger.log(` └─ (${StepTypeToIcon[step.type]}) ${step.id} ${tags.join(' ')}`);\n }\n\n return this;\n }\n\n async unregisterWorkflow(workflowId: string): Promise<WorkflowEngine> {\n this.workflows.delete(workflowId);\n return this;\n }\n\n async unregisterAllWorkflows(): Promise<WorkflowEngine> {\n this.workflows.clear();\n return this;\n }\n\n private resolveWorkflowRunParameters<\n TInput extends InputParameters,\n TOptions extends WorkflowRunOptions,\n >(\n refOrParams:\n | WorkflowRef<TInput, unknown>\n | {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: TOptions;\n },\n inputArg?: InferInputParameters<TInput>,\n optionsArg?: TOptions,\n ): ResolvedWorkflowRunParameters<TOptions> {\n if (typeof refOrParams === 'function' && 'id' in refOrParams) {\n return {\n workflowId: refOrParams.id,\n input: inputArg,\n options: optionsArg,\n resourceId: optionsArg?.resourceId,\n idempotencyKey: optionsArg?.idempotencyKey,\n };\n }\n\n const params = refOrParams as {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: TOptions;\n };\n\n return {\n workflowId: params.workflowId,\n input: params.input,\n resourceId: params.resourceId ?? params.options?.resourceId,\n idempotencyKey: params.idempotencyKey ?? params.options?.idempotencyKey,\n options: params.options,\n };\n }\n\n async startWorkflow<TInput extends InputParameters>(\n ref: WorkflowRef<TInput>,\n input: InferInputParameters<TInput>,\n options?: StartWorkflowOptions,\n ): Promise<WorkflowRun>;\n\n async startWorkflow(params: {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n }): Promise<WorkflowRun>;\n\n async startWorkflow<TInput extends InputParameters>(\n refOrParams:\n | WorkflowRef<TInput>\n | {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n idempotencyKey?: string;\n options?: StartWorkflowOptions;\n },\n inputArg?: InferInputParameters<TInput>,\n optionsArg?: StartWorkflowOptions,\n ): Promise<WorkflowRun> {\n const { workflowId, input, resourceId, idempotencyKey, options } =\n this.resolveWorkflowRunParameters(refOrParams, inputArg, optionsArg);\n\n if (!this._started) {\n await this.start(false, { batchSize: options?.batchSize ?? 1 });\n }\n\n const { run } = await this.createWorkflowRun({\n workflowId,\n input,\n resourceId,\n idempotencyKey,\n options,\n });\n\n this.logger.log('Started workflow run', {\n runId: run.id,\n workflowId,\n });\n\n return run;\n }\n\n private async createWorkflowRun({\n workflowId,\n input,\n resourceId,\n idempotencyKey,\n options,\n parentRunId,\n parentStepId,\n parentResourceId,\n enqueue = true,\n db,\n }: {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: WorkflowRunOptions;\n parentRunId?: string;\n parentStepId?: string;\n parentResourceId?: string;\n enqueue?: boolean;\n db?: Db;\n }): Promise<{ run: WorkflowRun; created: boolean }> {\n validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Unknown workflow ${workflowId}`);\n }\n\n const hasSteps = workflow.steps.length > 0 && workflow.steps[0];\n const hasPlugins = (workflow.plugins?.length ?? 0) > 0;\n if (!hasSteps && !hasPlugins) {\n throw new WorkflowEngineError(`Workflow ${workflowId} has no steps`, workflowId);\n }\n if (workflow.inputSchema) {\n const result = await workflow.inputSchema['~standard'].validate(input);\n if (result.issues) {\n throw new WorkflowEngineError(\n JSON.stringify(result.issues),\n workflowId,\n undefined,\n undefined,\n result.issues,\n );\n }\n }\n\n const initialStepId = workflow.steps[0]?.id ?? '__start__';\n const timeoutAt = options?.timeout\n ? new Date(Date.now() + options.timeout)\n : workflow.timeout\n ? new Date(Date.now() + workflow.timeout)\n : null;\n\n const insertRun = async (targetDb: Db) =>\n await insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId: initialStepId,\n status: WorkflowStatus.RUNNING,\n input,\n maxRetries: options?.retries ?? workflow.retries ?? 0,\n timeoutAt,\n idempotencyKey,\n parentRunId,\n parentStepId,\n parentResourceId,\n },\n targetDb,\n );\n\n // Pipe the same transaction connection through pg-boss so the\n // INSERT into workflow_runs and the INSERT into pgboss.job\n // commit (or roll back) together. If `boss.send` throws, the\n // workflow_runs row is rolled back too, so we never end up with\n // an orphan run that has no job, or a job that points at no run.\n const insertAndEnqueue = async (targetDb: Db) => {\n const result = await insertRun(targetDb);\n if (enqueue && result.created) {\n await this.enqueueWorkflowRun(result.run, options, targetDb);\n }\n return result;\n };\n\n const { run, created } = db\n ? await insertAndEnqueue(db)\n : await withPostgresTransaction(this.boss.getDb(), insertAndEnqueue, this.pool);\n\n return { run, created };\n }\n\n private async enqueueWorkflowRun(\n run: WorkflowRun,\n options?: { expireInSeconds?: number },\n db?: Db,\n ) {\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: new Date(),\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n ...(db ? { db } : {}),\n });\n }\n\n private async notifyParentOfChildTerminalRun(childRun: WorkflowRun) {\n if (!childRun.parentRunId || !childRun.parentStepId) {\n return;\n }\n\n const parentRun = await getWorkflowRun(\n {\n runId: childRun.parentRunId,\n resourceId: childRun.parentResourceId ?? undefined,\n },\n { db: this.db },\n );\n if (\n !parentRun ||\n parentRun.status === WorkflowStatus.COMPLETED ||\n parentRun.status === WorkflowStatus.FAILED ||\n parentRun.status === WorkflowStatus.CANCELLED\n ) {\n return;\n }\n\n await this.triggerEvent({\n runId: parentRun.id,\n resourceId: parentRun.resourceId ?? undefined,\n eventName: getInvokeChildWorkflowEventName(childRun.id),\n });\n }\n\n async pauseWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n // TODO: Pause all running steps immediately\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.PAUSED,\n pausedAt: new Date(),\n },\n expectedStatuses: [WorkflowStatus.RUNNING, WorkflowStatus.PENDING],\n });\n\n this.logger.log('Paused workflow run', {\n runId,\n workflowId: run.workflowId,\n });\n\n return run;\n }\n\n async resumeWorkflow({\n runId,\n resourceId,\n options,\n }: {\n runId: string;\n resourceId?: string;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const current = await this.getRun({ runId, resourceId });\n if (current.status !== WorkflowStatus.PAUSED) {\n throw new WorkflowEngineError(\n `Cannot resume workflow run in '${current.status}' status, must be 'paused'`,\n current.workflowId,\n runId,\n );\n }\n\n if (this.getInvokeChildWorkflowStepEntry(current.timeline, current.currentStepId)) {\n return current;\n }\n\n return this.triggerEvent({\n runId,\n resourceId,\n eventName: PAUSE_EVENT_NAME,\n data: {},\n options,\n });\n }\n\n async fastForwardWorkflow({\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data?: Record<string, unknown>;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n if (run.status !== WorkflowStatus.PAUSED) {\n return run;\n }\n\n const stepId = run.currentStepId;\n if (this.getInvokeChildWorkflowStepEntry(run.timeline, stepId)) {\n return run;\n }\n\n const waitForStep = this.getWaitForStepEntry(run.timeline, stepId);\n\n if (!waitForStep) {\n return run;\n }\n\n const { eventName, timeoutEvent, skipOutput } = waitForStep.waitFor;\n\n // step.pause() - delegate to resumeWorkflow\n if (eventName === PAUSE_EVENT_NAME) {\n return this.resumeWorkflow({ runId, resourceId });\n }\n\n // step.poll() - write output to timeline first, then trigger resume\n if (skipOutput && timeoutEvent) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun({ runId, resourceId }, { exclusiveLock: true, db });\n return this.updateRun(\n {\n runId,\n resourceId,\n data: {\n timeline: merge(freshRun.timeline, {\n [stepId]: {\n output: data ?? {},\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });\n }\n\n // waitFor steps - trigger the event with data\n if (eventName) {\n return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });\n }\n\n // delay/waitUntil steps - trigger the timeout event\n if (timeoutEvent) {\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });\n }\n\n return run;\n }\n\n async cancelWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.CANCELLED,\n },\n expectedStatuses: [WorkflowStatus.PENDING, WorkflowStatus.RUNNING, WorkflowStatus.PAUSED],\n });\n\n this.logger.log(`cancelled workflow run with id ${runId}`);\n\n await this.notifyParentOfChildTerminalRun(run);\n\n return run;\n }\n\n async triggerEvent({\n runId,\n resourceId,\n eventName,\n data,\n options,\n }: {\n runId: string;\n resourceId?: string;\n eventName: string;\n data?: Record<string, unknown>;\n options?: {\n expireInSeconds?: number;\n };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n const jobResourceId = resourceId ?? run.resourceId ?? undefined;\n\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: jobResourceId,\n workflowId: run.workflowId,\n input: run.input,\n event: {\n name: eventName,\n data,\n },\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n });\n\n this.logger.log(`event ${eventName} sent for workflow run with id ${runId}`);\n return run;\n }\n\n async getRun(\n { runId, resourceId }: { runId: string; resourceId?: string },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await getWorkflowRun({ runId, resourceId }, { exclusiveLock, db: db ?? this.db });\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async updateRun(\n {\n runId,\n resourceId,\n data,\n expectedStatuses,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n expectedStatuses?: string[];\n },\n { db }: { db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await updateWorkflowRun(\n { runId, resourceId, data, expectedStatuses },\n db ?? this.db,\n );\n\n if (!run) {\n if (expectedStatuses) {\n const current = await getWorkflowRun({ runId, resourceId }, { db: db ?? this.db });\n if (current) {\n throw new WorkflowEngineError(\n `Cannot update workflow run in '${current.status}' status, expected: ${expectedStatuses.join(', ')}`,\n current.workflowId,\n runId,\n );\n }\n }\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async checkProgress({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRunProgress> {\n const run = await this.getRun({ runId, resourceId });\n const workflow = this.workflows.get(run.workflowId);\n\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${run.workflowId} not found`, run.workflowId, runId);\n }\n const steps = workflow?.steps ?? [];\n\n let completionPercentage = 0;\n let completedSteps = 0;\n\n if (steps.length > 0) {\n completedSteps = Object.values(run.timeline).filter(\n (step): step is TimelineStepEntry =>\n typeof step === 'object' &&\n step !== null &&\n 'output' in step &&\n step.output !== undefined,\n ).length;\n\n if (run.status === WorkflowStatus.COMPLETED) {\n completionPercentage = 100;\n } else if (run.status === WorkflowStatus.FAILED || run.status === WorkflowStatus.CANCELLED) {\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n } else {\n const currentStepIndex = steps.findIndex((step) => step.id === run.currentStepId);\n if (currentStepIndex >= 0) {\n completionPercentage = (currentStepIndex / steps.length) * 100;\n } else {\n const completedSteps = Object.keys(run.timeline).length;\n\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n }\n }\n }\n\n return {\n ...run,\n completedSteps,\n completionPercentage: Math.round(completionPercentage * 100) / 100, // Round to 2 decimal places\n totalSteps: steps.length,\n };\n }\n\n /**\n * Resolves the resource id used for scoped DB access (getRun/updateRun).\n * When the job omits resourceId, the run's stored resourceId is used.\n * When the job includes resourceId, it must match the run's resourceId if the run is scoped;\n * unscoped runs reject a job-supplied resourceId (authorization).\n */\n private resolveScopedResourceId(\n jobResourceId: string | undefined,\n run: WorkflowRun,\n ): string | undefined {\n const jobResourceProvided =\n jobResourceId !== undefined && jobResourceId !== null && jobResourceId !== '';\n\n if (jobResourceProvided) {\n if (run.resourceId === null) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n if (run.resourceId !== jobResourceId) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n return jobResourceId;\n }\n\n return run.resourceId ?? undefined;\n }\n\n private async handleWorkflowRun([job]: JobWithMetadata<WorkflowRunJobParameters>[]) {\n const { runId = '', resourceId, workflowId = '', event } = job?.data ?? {};\n\n let run: WorkflowRun | undefined;\n let scopedResourceId: string | undefined;\n\n try {\n if (!runId) {\n throw new WorkflowEngineError('Invalid workflow run job, missing runId', workflowId);\n }\n\n if (!workflowId) {\n throw new WorkflowEngineError(\n 'Invalid workflow run job, missing workflowId',\n undefined,\n runId,\n );\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${workflowId} not found`, workflowId, runId);\n }\n\n this.logger.log('Processing workflow run...', {\n runId,\n workflowId,\n });\n\n run = await this.getRun({ runId });\n\n if (run.workflowId !== workflowId) {\n throw new WorkflowEngineError(\n `Workflow run ${runId} does not match job workflowId ${workflowId}`,\n workflowId,\n runId,\n );\n }\n\n scopedResourceId = this.resolveScopedResourceId(resourceId, run);\n\n // Mirror pg-boss's attempt counter so workflow_runs.retryCount stays\n // observable to API consumers across retries.\n if (job?.retryCount !== undefined && run.retryCount !== job.retryCount) {\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: { retryCount: job.retryCount },\n });\n run = { ...run, retryCount: job.retryCount };\n }\n\n if (run.status === WorkflowStatus.CANCELLED) {\n this.logger.log(`Workflow run ${runId} is cancelled, skipping`);\n return;\n }\n\n if (!run.currentStepId) {\n throw new WorkflowEngineError('Missing current step id', workflowId, runId);\n }\n\n if (run.status === WorkflowStatus.PAUSED) {\n run = await withPostgresTransaction(\n this.db,\n async (db) => {\n const lockedRun = await this.getRun(\n { runId, resourceId: scopedResourceId },\n { exclusiveLock: true, db },\n );\n if (lockedRun.status !== WorkflowStatus.PAUSED) {\n return lockedRun;\n }\n\n const waitForStep = this.getWaitForStepEntry(\n lockedRun.timeline,\n lockedRun.currentStepId,\n );\n const currentStep = this.getCachedStepEntry(\n lockedRun.timeline,\n lockedRun.currentStepId,\n );\n const waitFor = waitForStep?.waitFor;\n const hasCurrentStepOutput = currentStep?.output !== undefined;\n\n const eventMatches =\n waitFor &&\n event?.name &&\n (event.name === waitFor.eventName || event.name === waitFor.timeoutEvent) &&\n !hasCurrentStepOutput;\n\n if (eventMatches) {\n const isTimeout = event?.name === waitFor?.timeoutEvent;\n const skipOutput = waitFor?.skipOutput;\n return this.updateRun(\n {\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n ...(skipOutput\n ? {}\n : {\n timeline: merge(lockedRun.timeline, {\n [lockedRun.currentStepId]: {\n output: event?.data ?? {},\n ...(isTimeout ? { timedOut: true as const } : {}),\n timestamp: new Date(),\n },\n }),\n }),\n },\n },\n { db },\n );\n }\n\n return this.updateRun(\n {\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n },\n },\n { db },\n );\n },\n this.pool,\n );\n }\n\n const baseStep = {\n run: async <T>(stepId: string, handler: () => Promise<T>) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n return this.runStep({ stepId, run, handler }) as Promise<T>;\n },\n waitFor: async <T extends InputParameters>(\n stepId: string,\n { eventName, timeout }: { eventName: string; timeout?: number; schema?: T },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const timeoutDate = timeout ? new Date(Date.now() + timeout) : undefined;\n return this.waitStep({ run, stepId, eventName, timeoutDate }) as Promise<\n InferInputParameters<T> | undefined\n >;\n },\n waitUntil: async (\n stepId: string,\n dateOrOptions: Date | string | { date: Date | string },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const date =\n dateOrOptions instanceof Date\n ? dateOrOptions\n : typeof dateOrOptions === 'string'\n ? new Date(dateOrOptions)\n : dateOrOptions.date instanceof Date\n ? dateOrOptions.date\n : new Date(dateOrOptions.date);\n await this.waitStep({ run, stepId, timeoutDate: date });\n },\n pause: async (stepId: string) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({ run, stepId, eventName: PAUSE_EVENT_NAME });\n },\n delay: async (stepId: string, duration: Duration) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({\n run,\n stepId,\n timeoutDate: new Date(Date.now() + parseDuration(duration)),\n });\n },\n get sleep() {\n return this.delay;\n },\n poll: async <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const intervalMs = parseDuration(options?.interval ?? '30s');\n if (intervalMs < 30_000) {\n throw new WorkflowEngineError(\n `step.poll interval must be at least 30s (got ${intervalMs}ms)`,\n workflowId,\n runId,\n );\n }\n const timeoutMs = options?.timeout ? parseDuration(options.timeout) : undefined;\n return this.pollStep({ run, stepId, conditionFn, intervalMs, timeoutMs }) as Promise<\n { timedOut: false; data: T } | { timedOut: true }\n >;\n },\n invokeChildWorkflow: async <TInput extends InputParameters, TOutput = unknown>(\n stepId: string,\n refOrParams:\n | WorkflowRef<TInput, TOutput>\n | {\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: WorkflowRunOptions;\n },\n inputArg?: InferInputParameters<TInput>,\n optionsArg?: WorkflowRunOptions,\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n\n // Resolve overload input (typed ref or params object) into one shape\n // before handing off to the durable child-invocation implementation.\n const resolvedChildCall = this.resolveWorkflowRunParameters(\n refOrParams,\n inputArg,\n optionsArg,\n );\n const childWorkflowInvocation = {\n run,\n stepId,\n workflowId: resolvedChildCall.workflowId,\n input: resolvedChildCall.input,\n options: resolvedChildCall.options,\n resourceId: resolvedChildCall.resourceId,\n idempotencyKey: resolvedChildCall.idempotencyKey,\n };\n return this.invokeChildWorkflowStep(childWorkflowInvocation) as Promise<TOutput>;\n },\n };\n\n let step = { ...baseStep };\n const plugins = workflow.plugins ?? [];\n for (const plugin of plugins) {\n const extra = plugin.methods(step);\n step = { ...step, ...extra };\n }\n\n const context: WorkflowContext = {\n input: run.input as InferInputParameters<InputParameters>,\n workflowId: run.workflowId,\n runId: run.id,\n timeline: run.timeline,\n logger: this.logger,\n step,\n };\n\n const result = await workflow.handler(context);\n\n run = await this.getRun({ runId, resourceId: scopedResourceId });\n\n const isLastParsedStep = run.currentStepId === workflow.steps[workflow.steps.length - 1]?.id;\n const hasPluginSteps = (workflow.plugins?.length ?? 0) > 0;\n const noParsedSteps = workflow.steps.length === 0;\n const shouldComplete =\n run.status === WorkflowStatus.RUNNING &&\n (noParsedSteps || isLastParsedStep || (hasPluginSteps && result !== undefined));\n if (shouldComplete) {\n const normalizedResult = result === undefined ? {} : result;\n const completedRun = await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.COMPLETED,\n output: normalizedResult,\n completedAt: new Date(),\n jobId: job?.id,\n },\n });\n await this.notifyParentOfChildTerminalRun(completedRun);\n\n this.logger.log('Workflow run completed.', {\n runId,\n workflowId,\n });\n }\n } catch (error) {\n // Persist the error so the DLQ handler can surface it after retries\n // are exhausted. pg-boss handles the retry-vs-DLQ decision based on\n // the per-job retryLimit set when the job was enqueued.\n if (runId) {\n const updatedRun = await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n error: error instanceof Error ? error.message : String(error),\n jobId: job?.id,\n },\n });\n if (\n updatedRun.status === WorkflowStatus.COMPLETED ||\n updatedRun.status === WorkflowStatus.FAILED ||\n updatedRun.status === WorkflowStatus.CANCELLED\n ) {\n await this.notifyParentOfChildTerminalRun(updatedRun);\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Reconciles workflow runs whose retries pg-boss has exhausted (handler\n * threw on the final attempt, or worker died and missed the heartbeat\n * past the retry budget). The DLQ entry tells us the run is unrecoverable;\n * we mark it FAILED with whatever error message the catch block last\n * persisted, falling back to a worker-death message.\n */\n private async handleWorkflowRunDlq([job]: { data?: WorkflowRunJobParameters }[]) {\n const { runId } = job?.data ?? {};\n if (!runId) return;\n\n const run = await getWorkflowRun({ runId }, { db: this.db });\n if (!run || run.status !== WorkflowStatus.RUNNING) return;\n\n const failedRun = await this.updateRun({\n runId,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.FAILED,\n error: run.error ?? 'Workflow run worker died or job expired before completion',\n },\n });\n await this.notifyParentOfChildTerminalRun(failedRun);\n\n this.logger.log('Marked stuck workflow run as failed', {\n runId,\n workflowId: run.workflowId,\n });\n }\n\n private getCachedStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineStepEntry | null {\n const stepEntry = timeline[stepId];\n return stepEntry && typeof stepEntry === 'object' && 'output' in stepEntry\n ? (stepEntry as TimelineStepEntry)\n : null;\n }\n\n private getWaitForStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineWaitForEntry | null {\n const entry = timeline[waitForTimelineKey(stepId)];\n return entry && typeof entry === 'object' && 'waitFor' in entry\n ? (entry as TimelineWaitForEntry)\n : null;\n }\n\n private getInvokeChildWorkflowStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineInvokeChildWorkflowEntry | null {\n const entry = timeline[invokeChildWorkflowTimelineKey(stepId)];\n return isInvokeChildWorkflowTimelineEntry(entry)\n ? (entry as TimelineInvokeChildWorkflowEntry)\n : null;\n }\n\n /**\n * Returns the cached output for a COMPLETED child run. Treats `undefined`\n * outputs as `{}` so the parent timeline always has a defined value.\n * Caller must ensure `childRun.status === COMPLETED` before calling.\n */\n private getCompletedChildOutput(childRun: WorkflowRun): unknown {\n return childRun.output === undefined ? {} : childRun.output;\n }\n\n /**\n * Throws a `WorkflowEngineError` describing why an invoked child run did not\n * produce output (it FAILED or was CANCELLED). The throw aborts the parent\n * step, which is then caught by `handleWorkflowRun` and marks the parent\n * FAILED with the same message — no fake sentinel value is ever written to\n * the parent timeline.\n */\n private throwForNonCompletedChild(childRun: WorkflowRun): never {\n throw new WorkflowEngineError(\n `Child workflow ${childRun.workflowId} ${childRun.status}${childRun.error ? `: ${childRun.error}` : ''}`,\n childRun.workflowId,\n childRun.id,\n );\n }\n\n private assertInvokeChildWorkflowStepOwnership({\n childRun,\n parentRun,\n stepId,\n workflowId,\n }: {\n childRun: WorkflowRun;\n parentRun: WorkflowRun;\n stepId: string;\n workflowId: string;\n }) {\n const expectedParentResourceId = parentRun.resourceId ?? null;\n const matches =\n childRun.workflowId === workflowId &&\n childRun.parentRunId === parentRun.id &&\n childRun.parentStepId === stepId &&\n childRun.parentResourceId === expectedParentResourceId;\n\n if (!matches) {\n throw new WorkflowEngineError(\n `Idempotency key resolved to workflow run ${childRun.id}, which does not belong to invokeChildWorkflow step '${stepId}'`,\n workflowId,\n parentRun.id,\n );\n }\n }\n\n // The whole step runs inside a single SELECT … FOR UPDATE transaction so that\n // every state transition (cache hit, terminal-child cache, fresh child create,\n // re-pause for a still-running existing child) sees a consistent parent row\n // and can never overwrite a status another worker just wrote (e.g. a\n // concurrent invoke-completion event flipping the parent to COMPLETED).\n //\n // The child run insert AND its pgboss.job enqueue both join this same\n // transaction. The parent pause, child run row, and child job all commit (or\n // roll back) together, so a worker crashing between \"parent paused\" and\n // \"child enqueued\" is impossible — there is no such interleaving window.\n private async invokeChildWorkflowStep({\n run,\n stepId,\n workflowId,\n input,\n resourceId,\n idempotencyKey,\n options,\n }: {\n run: WorkflowRun;\n stepId: string;\n workflowId: string;\n input: unknown;\n resourceId?: string;\n idempotencyKey?: string;\n options?: WorkflowRunOptions;\n }): Promise<unknown> {\n let invokeOutput: unknown;\n let hasInvokeOutput = false;\n const childResourceId = resourceId ?? run.resourceId ?? undefined;\n const childIdempotencyKey = idempotencyKey;\n\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const lockedRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n\n // If the parent isn't RUNNING, fall through and return `undefined`. The\n // worker's outer loop won't act on it: subsequent `step.run` calls\n // short-circuit the same way (see `runStep`), and the post-handler\n // `shouldComplete` check requires `status === RUNNING` so no terminal\n // state is written. Matches the pattern used by the other step kinds.\n if (\n lockedRun.status === WorkflowStatus.CANCELLED ||\n lockedRun.status === WorkflowStatus.PAUSED ||\n lockedRun.status === WorkflowStatus.FAILED\n ) {\n return;\n }\n\n const lockedCached = this.getCachedStepEntry(lockedRun.timeline, stepId);\n if (lockedCached?.output !== undefined) {\n invokeOutput = lockedCached.output;\n hasInvokeOutput = true;\n return;\n }\n\n const lockedInvoke = this.getInvokeChildWorkflowStepEntry(lockedRun.timeline, stepId);\n if (lockedInvoke) {\n const existingChildResourceId =\n 'childResourceId' in lockedInvoke.invokeChildWorkflow\n ? (lockedInvoke.invokeChildWorkflow.childResourceId ?? undefined)\n : childResourceId;\n const existingChildRun = await this.getRun({\n runId: lockedInvoke.invokeChildWorkflow.childRunId,\n resourceId: existingChildResourceId,\n });\n if (existingChildRun.status === WorkflowStatus.COMPLETED) {\n invokeOutput = this.getCompletedChildOutput(existingChildRun);\n hasInvokeOutput = true;\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n timeline: merge(lockedRun.timeline, {\n [stepId]: {\n output: invokeOutput,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n return;\n }\n if (\n existingChildRun.status === WorkflowStatus.FAILED ||\n existingChildRun.status === WorkflowStatus.CANCELLED\n ) {\n // No timeline write — let the throw roll back the txn (a no-op\n // here since we only did SELECTs) and bubble up so the parent\n // is marked FAILED by the worker's catch handler.\n this.throwForNonCompletedChild(existingChildRun);\n }\n\n // Child is still RUNNING/PAUSED. The original enqueue committed\n // with the prior parent-pause txn, so pg-boss already owns the\n // child job — re-pause the parent and wait for the next terminal\n // event without re-enqueueing.\n await this.pauseRunForWait({\n run: lockedRun,\n stepId,\n eventName: getInvokeChildWorkflowEventName(existingChildRun.id),\n skipOutput: true,\n db,\n });\n return;\n }\n\n const result = await this.createWorkflowRun({\n workflowId,\n input,\n resourceId: childResourceId,\n idempotencyKey: childIdempotencyKey,\n options,\n parentRunId: run.id,\n parentStepId: stepId,\n parentResourceId: run.resourceId ?? undefined,\n enqueue: true,\n db,\n });\n const childRun = result.run;\n\n if (!result.created) {\n this.assertInvokeChildWorkflowStepOwnership({\n childRun,\n parentRun: lockedRun,\n stepId,\n workflowId,\n });\n\n if (childRun.status === WorkflowStatus.COMPLETED) {\n invokeOutput = this.getCompletedChildOutput(childRun);\n hasInvokeOutput = true;\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n timeline: merge(lockedRun.timeline, {\n [invokeChildWorkflowTimelineKey(stepId)]: {\n invokeChildWorkflow: {\n childRunId: childRun.id,\n childWorkflowId: childRun.workflowId,\n childResourceId: childRun.resourceId,\n },\n timestamp: new Date(),\n },\n [stepId]: {\n output: invokeOutput,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n return;\n }\n if (\n childRun.status === WorkflowStatus.FAILED ||\n childRun.status === WorkflowStatus.CANCELLED\n ) {\n // Same throw-and-rollback contract as the existing-child branch:\n // we deliberately do NOT record the parent timeline binding for\n // a child we matched-by-idempotency-key but never owned the\n // creation of. The throw propagates and the parent fails.\n this.throwForNonCompletedChild(childRun);\n }\n }\n\n await this.pauseRunForWait({\n run: lockedRun,\n stepId,\n eventName: getInvokeChildWorkflowEventName(childRun.id),\n skipOutput: true,\n db,\n timeline: merge(lockedRun.timeline, {\n [invokeChildWorkflowTimelineKey(stepId)]: {\n invokeChildWorkflow: {\n childRunId: childRun.id,\n childWorkflowId: childRun.workflowId,\n childResourceId: childRun.resourceId,\n },\n timestamp: new Date(),\n },\n }),\n });\n },\n this.pool,\n );\n\n if (hasInvokeOutput) {\n return invokeOutput;\n }\n }\n\n private async pauseRunForWait({\n run,\n stepId,\n eventName,\n timeoutEvent,\n skipOutput,\n db,\n timeline,\n }: {\n run: WorkflowRun;\n stepId: string;\n eventName?: string;\n timeoutEvent?: string;\n skipOutput?: true;\n db?: Db;\n timeline?: Record<string, unknown>;\n }) {\n const baseTimeline = timeline ?? run.timeline;\n const waitFor: TimelineWaitForEntry['waitFor'] = {};\n if (eventName) waitFor.eventName = eventName;\n if (timeoutEvent) waitFor.timeoutEvent = timeoutEvent;\n if (skipOutput) waitFor.skipOutput = true;\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(baseTimeline, {\n [waitForTimelineKey(stepId)]: {\n waitFor,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n }\n\n private async runStep({\n stepId,\n run,\n handler,\n }: {\n stepId: string;\n run: WorkflowRun;\n handler: () => Promise<unknown>;\n }) {\n return withPostgresTransaction(\n this.db,\n async (db) => {\n const persistedRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n {\n exclusiveLock: true,\n db,\n },\n );\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n this.logger.log(`Step ${stepId} skipped, workflow run is ${persistedRun.status}`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return;\n }\n\n try {\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.output;\n }\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n },\n },\n { db },\n );\n\n this.logger.log(`Running step ${stepId}...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n let output = await handler();\n\n if (output === undefined) {\n output = {};\n }\n\n run = await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n timeline: merge(persistedRun.timeline, {\n [stepId]: {\n output,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n\n return output;\n } catch (error) {\n this.logger.error(`Step ${stepId} failed:`, error as Error, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.FAILED,\n error: error instanceof Error ? `${error.message}\\n${error.stack}` : String(error),\n },\n },\n { db },\n );\n\n throw error;\n }\n },\n this.pool,\n );\n }\n\n private async waitStep({\n run,\n stepId,\n eventName,\n timeoutDate,\n }: {\n run: WorkflowRun;\n stepId: string;\n eventName?: string;\n timeoutDate?: Date;\n }): Promise<unknown> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return;\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? undefined : cached.output;\n }\n\n const timeoutEvent = timeoutDate ? `__timeout_${stepId}` : undefined;\n\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.pauseRunForWait({ run: freshRun, stepId, eventName, timeoutEvent, db });\n },\n this.pool,\n );\n\n if (timeoutDate && timeoutEvent) {\n try {\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: timeoutEvent, data: { date: timeoutDate.toISOString() } },\n };\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: timeoutDate.getTime() <= Date.now() ? new Date() : timeoutDate,\n expireInSeconds: defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n });\n } catch (error) {\n // Revert PAUSED status so the workflow can retry this step\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: { status: WorkflowStatus.RUNNING, pausedAt: null },\n });\n throw error;\n }\n }\n\n this.logger.log(\n `Step ${stepId} waiting${eventName ? ` for event \"${eventName}\"` : ''}${timeoutDate ? ` until ${timeoutDate.toISOString()}` : ''}`,\n { runId: run.id, workflowId: run.workflowId },\n );\n }\n\n private async pollStep<T>({\n run,\n stepId,\n conditionFn,\n intervalMs,\n timeoutMs,\n }: {\n run: WorkflowRun;\n stepId: string;\n conditionFn: () => Promise<T | false>;\n intervalMs: number;\n timeoutMs?: number;\n }): Promise<{ timedOut: false; data: T } | { timedOut: true } | undefined> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return { timedOut: true };\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? { timedOut: true } : { timedOut: false, data: cached.output as T };\n }\n\n const pollStateEntry = persistedRun.timeline[`${stepId}-poll`];\n const startedAt =\n pollStateEntry && typeof pollStateEntry === 'object' && 'startedAt' in pollStateEntry\n ? new Date((pollStateEntry as { startedAt: string }).startedAt)\n : new Date();\n\n if (timeoutMs !== undefined && Date.now() >= startedAt.getTime() + timeoutMs) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(freshRun.timeline, {\n [stepId]: { output: {}, timedOut: true as const, timestamp: new Date() },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n return { timedOut: true };\n }\n\n let result: T | false;\n try {\n result = await conditionFn();\n } catch (error) {\n this.logger.error(\n `Poll conditionFn for step ${stepId} threw an error, treating as non-match and continuing to poll`,\n error as Error,\n { runId: run.id, workflowId: run.workflowId },\n );\n\n // If the poll has timed out, respect the timeout even though conditionFn threw\n if (timeoutMs !== undefined && Date.now() >= startedAt.getTime() + timeoutMs) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(freshRun.timeline, {\n [stepId]: { output: {}, timedOut: true as const, timestamp: new Date() },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n return { timedOut: true };\n }\n\n result = false;\n }\n\n if (result !== false) {\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(freshRun.timeline, {\n [stepId]: { output: result, timestamp: new Date() },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n return { timedOut: false, data: result };\n }\n\n const pollEvent = `__poll_${stepId}`;\n await withPostgresTransaction(\n this.db,\n async (db) => {\n const freshRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n { exclusiveLock: true, db },\n );\n return this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(freshRun.timeline, {\n [`${stepId}-poll`]: { startedAt: startedAt.toISOString() },\n [waitForTimelineKey(stepId)]: {\n waitFor: { timeoutEvent: pollEvent, skipOutput: true },\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n },\n this.pool,\n );\n\n try {\n await this.boss.send(\n WORKFLOW_RUN_QUEUE_NAME,\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: pollEvent, data: {} },\n },\n {\n startAfter: new Date(Date.now() + intervalMs),\n expireInSeconds: defaultExpireInSeconds,\n ...retrySendOptions(run.maxRetries),\n },\n );\n } catch (error) {\n // Revert PAUSED status so the workflow can retry this step\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: { status: WorkflowStatus.RUNNING, pausedAt: null },\n });\n throw error;\n }\n\n this.logger.log(`Step ${stepId} polling every ${intervalMs}ms...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return { timedOut: false, data: undefined as T };\n }\n\n private async checkIfHasStarted(): Promise<void> {\n if (!this._started) {\n throw new WorkflowEngineError('Workflow engine not started');\n }\n }\n\n private buildLogger(logger: WorkflowLogger): WorkflowInternalLogger {\n return {\n log: (message: string, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.log(`${parts}: ${message}`);\n },\n error: (message: string, error: Error, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.error(`${parts}: ${message}`, error);\n },\n };\n }\n\n async getRuns({\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: WorkflowStatus[];\n workflowId?: string;\n }): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n }> {\n if (workflowId) validateWorkflowId(workflowId);\n validateResourceId(resourceId);\n\n return getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit,\n statuses,\n workflowId,\n },\n this.db,\n );\n }\n}\n",
|
|
14
|
+
"import * as ts from 'typescript';\nimport type { StepInternalDefinition, WorkflowContext } from './types';\nimport { StepType } from './types';\n\ntype ParseWorkflowHandlerReturnType = {\n steps: StepInternalDefinition[];\n};\n\nexport function parseWorkflowHandler(\n handler: (context: WorkflowContext) => Promise<unknown>,\n): ParseWorkflowHandlerReturnType {\n const handlerSource = handler.toString();\n const sourceFile = ts.createSourceFile('handler.ts', handlerSource, ts.ScriptTarget.Latest, true);\n\n const steps: Map<string, StepInternalDefinition> = new Map();\n\n function isInConditional(node: ts.Node): boolean {\n let current = node.parent;\n while (current) {\n if (\n ts.isIfStatement(current) ||\n ts.isConditionalExpression(current) ||\n ts.isSwitchStatement(current) ||\n ts.isCaseClause(current)\n ) {\n return true;\n }\n current = current.parent;\n }\n return false;\n }\n\n function isInLoop(node: ts.Node): boolean {\n let current = node.parent;\n while (current) {\n if (\n ts.isForStatement(current) ||\n ts.isForInStatement(current) ||\n ts.isForOfStatement(current) ||\n ts.isWhileStatement(current) ||\n ts.isDoStatement(current)\n ) {\n return true;\n }\n current = current.parent;\n }\n return false;\n }\n\n function extractStepId(arg: ts.Expression): {\n id: string;\n isDynamic: boolean;\n } {\n if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) {\n return { id: arg.text, isDynamic: false };\n }\n\n if (ts.isTemplateExpression(arg)) {\n let templateStr = arg.head.text;\n for (const span of arg.templateSpans) {\n templateStr += `\\${...}`;\n templateStr += span.literal.text;\n }\n return { id: templateStr, isDynamic: true };\n }\n\n return { id: arg.getText(sourceFile), isDynamic: true };\n }\n\n function visit(node: ts.Node) {\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {\n const propertyAccess = node.expression;\n const objectName = propertyAccess.expression.getText(sourceFile);\n const methodName = propertyAccess.name.text;\n\n if (\n objectName === 'step' &&\n (methodName === 'run' ||\n methodName === 'waitFor' ||\n methodName === 'pause' ||\n methodName === 'waitUntil' ||\n methodName === 'delay' ||\n methodName === 'sleep' ||\n methodName === 'poll' ||\n methodName === 'invokeChildWorkflow')\n ) {\n const firstArg = node.arguments[0];\n if (firstArg) {\n const { id, isDynamic } = extractStepId(firstArg);\n const stepType = methodName === 'sleep' ? StepType.DELAY : (methodName as StepType);\n\n const stepDefinition: StepInternalDefinition = {\n id,\n type: stepType,\n conditional: isInConditional(node),\n loop: isInLoop(node),\n isDynamic,\n };\n\n if (steps.has(id)) {\n throw new Error(\n `Duplicate step ID detected: '${id}'. Step IDs must be unique within a workflow.`,\n );\n }\n\n steps.set(id, stepDefinition);\n }\n }\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n\n return { steps: Array.from(steps.values()) };\n}\n"
|
|
15
15
|
],
|
|
16
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAsB,IAAtB;AACe,IAAf;AACgC,IAAhC;;;ACFO,IAAM,mBAAmB;AACzB,IAAM,0BAA0B;AAChC,IAAM,8BAA8B;AACpC,IAAM,wBAAwB;AAC9B,IAAM,yBAAyB;AAC/B,IAAM,yBAAyB;;;ACF/B,IAAM,oBAAoB;AAIjC,IAAM,yBAAyB;AAE/B,eAAsB,aAAa,CAAC,IAAuB;AAAA,EAGzD,IAAI,MAAM,iBAAiB,EAAE,GAAG;AAAA,IAC9B;AAAA,EACF;AAAA,EAOA,MAAM,iBAAiB,MAAM,kBAAkB,EAAE;AAAA,EAEjD,MAAM,WAAqB,CAAC;AAAA,EAE5B,IAAI,iBAAiB,GAAG;AAAA,IACtB,SAAS,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAqBb;AAAA,IACD,SAAS,KAAK;AAAA;AAAA,KAEb;AAAA,IACD,SAAS,KAAK;AAAA;AAAA,KAEb;AAAA,IACD,SAAS,KAAK;AAAA;AAAA,KAEb;AAAA,IACD,SAAS,KAAK;AAA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