| 296 | |
| 297 | /** Reads one job row (type/status/payload) scoped to its table. Null when absent. */ |
| 298 | export async function getTableJob( |
| 299 | tableId: string, |
| 300 | jobId: string |
| 301 | ): Promise<{ id: string; type: string; status: string; payload: unknown } | null> { |
| 302 | const [job] = await db |
| 303 | .select({ |
| 304 | id: tableJobs.id, |
| 305 | type: tableJobs.type, |
| 306 | status: tableJobs.status, |
| 307 | payload: tableJobs.payload, |
| 308 | }) |
| 309 | .from(tableJobs) |
| 310 | .where(and(eq(tableJobs.id, jobId), eq(tableJobs.tableId, tableId))) |
| 311 | .limit(1) |
| 312 | return job ?? null |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Stamps an export job's generated-file storage key onto its payload (`{ resultKey }` merge). |