Skip to content
File

Blob: src/worker/durable/project-do/types.ts

typescript125 lines
1import type { DrizzleSqliteDODatabase } from "drizzle-orm/durable-sqlite";
2 
3import type { DispatchMode, ExecutionRuntime, ProjectId, UnixTimestampMs, WebhookProvider } from "@/contracts";
4import type { ProjectRunStatus } from "@/worker/contracts";
5import type * as projectSchema from "@/worker/db/durable/schema/project-do";
6import type { EncryptedSecret } from "@/worker/security/secrets";
7import type { Logger } from "@/worker/services/logger";
8import type { WebhookVerificationMaterial } from "./webhooks/types";
9 
10export type ProjectTx = Parameters<DrizzleSqliteDODatabase<typeof projectSchema>["transaction"]>[0] extends (
11 tx: infer T,
12) => unknown
13 ? T
14 : never;
15export type ProjectDb = DrizzleSqliteDODatabase<typeof projectSchema>;
16export type ProjectStore = ProjectDb | ProjectTx;
17 
18export type ProjectConfigRow = typeof projectSchema.projectConfig.$inferSelect;
19export type ProjectRunRow = typeof projectSchema.projectRuns.$inferSelect;
20export type ProjectStateRow = typeof projectSchema.projectState.$inferSelect;
21 
22export type ProjectIndexSyncStatus = "current" | "needs_update";
23export type D1RetryPhase = "create" | "metadata" | "terminal";
24export type ProjectIndexRetryPhase = "project_index";
25 
26export interface D1RetryState {
27 attempt: number;
28 nextAt: number;
29 phase: D1RetryPhase;
30}
31 
32export interface ProjectIndexRetryState {
33 attempt: number;
34 nextAt: number;
35 phase: ProjectIndexRetryPhase;
36}
37 
38export interface SandboxCleanupRetryState {
39 attempt: number;
40 nextAt: number;
41}
42 
43export interface CancelTransitionResult {
44 row: ProjectRunRow;
45 runStatus: ProjectRunStatus;
46 cancelRequestedAt: UnixTimestampMs | null;
47 runDoAction: "none" | "cancel_requested" | "canceled";
48}
49 
50export type RunDoCancelUpdateOutcome = "applied" | "deferred" | "noop";
51 
52export 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 
65export 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 
76export 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 
87export interface ProjectExecutionMaterial {
88 projectId: ProjectId;
89 encryptedRepoToken: EncryptedSecret | null;
90}
91 
92export interface ProjectWebhookIngressState {
93 projectId: ProjectId;
94 repoUrl: string;
95 defaultBranch: string;
96 configPath: string;
97 webhook: WebhookVerificationMaterial;
98}
99 
100export 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 
118export interface ProjectDoContext {
119 ctx: DurableObjectState;
120 env: Env;
121 db: ProjectDb;
122 logger: Logger;
123 cacheProjectId: (projectId: ProjectId) => void;
124}