File
Blob: src/worker/durable/project-do/types.ts
| 1 | import type { DrizzleSqliteDODatabase } from "drizzle-orm/durable-sqlite"; |
| 2 | |
| 3 | import type { DispatchMode, ExecutionRuntime, ProjectId, UnixTimestampMs, WebhookProvider } from "@/contracts"; |
| 4 | import type { ProjectRunStatus } from "@/worker/contracts"; |
| 5 | import type * as projectSchema from "@/worker/db/durable/schema/project-do"; |
| 6 | import type { EncryptedSecret } from "@/worker/security/secrets"; |
| 7 | import type { Logger } from "@/worker/services/logger"; |
| 8 | import type { WebhookVerificationMaterial } from "./webhooks/types"; |
| 9 | |
| 10 | export type ProjectTx = Parameters<DrizzleSqliteDODatabase<typeof projectSchema>["transaction"]>[0] extends ( |
| 11 | tx: infer T, |
| 12 | ) => unknown |
| 13 | ? T |
| 14 | : never; |
| 15 | export type ProjectDb = DrizzleSqliteDODatabase<typeof projectSchema>; |
| 16 | export type ProjectStore = ProjectDb | ProjectTx; |
| 17 | |
| 18 | export type ProjectConfigRow = typeof projectSchema.projectConfig.$inferSelect; |
| 19 | export type ProjectRunRow = typeof projectSchema.projectRuns.$inferSelect; |
| 20 | export type ProjectStateRow = typeof projectSchema.projectState.$inferSelect; |
| 21 | |
| 22 | export type ProjectIndexSyncStatus = "current" | "needs_update"; |
| 23 | export type D1RetryPhase = "create" | "metadata" | "terminal"; |
| 24 | export type ProjectIndexRetryPhase = "project_index"; |
| 25 | |
| 26 | export interface D1RetryState { |
| 27 | attempt: number; |
| 28 | nextAt: number; |
| 29 | phase: D1RetryPhase; |
| 30 | } |
| 31 | |
| 32 | export interface ProjectIndexRetryState { |
| 33 | attempt: number; |
| 34 | nextAt: number; |
| 35 | phase: ProjectIndexRetryPhase; |
| 36 | } |
| 37 | |
| 38 | export interface SandboxCleanupRetryState { |
| 39 | attempt: number; |
| 40 | nextAt: number; |
| 41 | } |
| 42 | |
| 43 | export interface CancelTransitionResult { |
| 44 | row: ProjectRunRow; |
| 45 | runStatus: ProjectRunStatus; |
| 46 | cancelRequestedAt: UnixTimestampMs | null; |
| 47 | runDoAction: "none" | "cancel_requested" | "canceled"; |
| 48 | } |
| 49 | |
| 50 | export type RunDoCancelUpdateOutcome = "applied" | "deferred" | "noop"; |
| 51 | |
| 52 | export interface InitializeProjectInput { |
| 53 | projectId: ProjectId; |
| 54 | name: string; |
| 55 | repoUrl: string; |
| 56 | defaultBranch: string; |
| 57 | configPath: string; |
| 58 | encryptedRepoToken: EncryptedSecret | null; |
| 59 | dispatchMode: DispatchMode; |
| 60 | executionRuntime: ExecutionRuntime; |
| 61 | createdAt: number; |
| 62 | updatedAt: number; |
| 63 | } |
| 64 | |
| 65 | export interface UpdateProjectConfigInput { |
| 66 | projectId: ProjectId; |
| 67 | name?: string; |
| 68 | repoUrl?: string; |
| 69 | defaultBranch?: string; |
| 70 | configPath?: string; |
| 71 | dispatchMode?: DispatchMode; |
| 72 | encryptedRepoToken?: EncryptedSecret | null; |
| 73 | now: number; |
| 74 | } |
| 75 | |
| 76 | export interface ProjectConfigState { |
| 77 | projectId: ProjectId; |
| 78 | name: string; |
| 79 | repoUrl: string; |
| 80 | defaultBranch: string; |
| 81 | configPath: string; |
| 82 | dispatchMode: DispatchMode; |
| 83 | createdAt: number; |
| 84 | updatedAt: number; |
| 85 | } |
| 86 | |
| 87 | export interface ProjectExecutionMaterial { |
| 88 | projectId: ProjectId; |
| 89 | encryptedRepoToken: EncryptedSecret | null; |
| 90 | } |
| 91 | |
| 92 | export interface ProjectWebhookIngressState { |
| 93 | projectId: ProjectId; |
| 94 | repoUrl: string; |
| 95 | defaultBranch: string; |
| 96 | configPath: string; |
| 97 | webhook: WebhookVerificationMaterial; |
| 98 | } |
| 99 | |
| 100 | export type UpdateProjectConfigResult = |
| 101 | | { |
| 102 | kind: "applied"; |
| 103 | config: ProjectConfigState; |
| 104 | } |
| 105 | | { |
| 106 | kind: "invalid"; |
| 107 | status: number; |
| 108 | code: string; |
| 109 | message: string; |
| 110 | details?: { |
| 111 | providers: string[]; |
| 112 | }; |
| 113 | } |
| 114 | | { |
| 115 | kind: "not_found"; |
| 116 | }; |
| 117 | |
| 118 | export interface ProjectDoContext { |
| 119 | ctx: DurableObjectState; |
| 120 | env: Env; |
| 121 | db: ProjectDb; |
| 122 | logger: Logger; |
| 123 | cacheProjectId: (projectId: ProjectId) => void; |
| 124 | } |