File
Blob: src/contracts/project.ts
| 1 | import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde"; |
| 2 | |
| 3 | import { |
| 4 | BranchName, |
| 5 | IsoDateTime, |
| 6 | OwnerSlug, |
| 7 | ProjectId, |
| 8 | ProjectSlug, |
| 9 | RunId, |
| 10 | RunStatus, |
| 11 | UserId, |
| 12 | } from "@/contracts/common"; |
| 13 | import { DispatchMode } from "@/contracts/execution/dispatch"; |
| 14 | import { RunSummary } from "@/contracts/run"; |
| 15 | |
| 16 | export const CreateProjectRequest = eg.exactStrict( |
| 17 | eg.object({ |
| 18 | projectSlug: ProjectSlug, |
| 19 | name: eg.string, |
| 20 | repoUrl: eg.string, |
| 21 | defaultBranch: BranchName, |
| 22 | configPath: eg.string.optional, |
| 23 | dispatchMode: DispatchMode.optional, |
| 24 | repoToken: eg.union([eg.string, eg.null]).optional, |
| 25 | }), |
| 26 | ); |
| 27 | export type CreateProjectRequest = TypeFromCodec<typeof CreateProjectRequest>; |
| 28 | |
| 29 | export const UpdateProjectRequest = eg.exactStrict( |
| 30 | eg.object({ |
| 31 | name: eg.string.optional, |
| 32 | repoUrl: eg.string.optional, |
| 33 | defaultBranch: BranchName.optional, |
| 34 | configPath: eg.string.optional, |
| 35 | dispatchMode: DispatchMode.optional, |
| 36 | repoToken: eg.union([eg.string, eg.null]).optional, |
| 37 | }), |
| 38 | ); |
| 39 | export type UpdateProjectRequest = TypeFromCodec<typeof UpdateProjectRequest>; |
| 40 | |
| 41 | export const ProjectSummary = eg.exactStrict( |
| 42 | eg.object({ |
| 43 | id: ProjectId, |
| 44 | ownerUserId: UserId, |
| 45 | ownerSlug: OwnerSlug, |
| 46 | projectSlug: ProjectSlug, |
| 47 | name: eg.string, |
| 48 | repoUrl: eg.string, |
| 49 | defaultBranch: BranchName, |
| 50 | configPath: eg.string, |
| 51 | createdAt: IsoDateTime, |
| 52 | updatedAt: IsoDateTime, |
| 53 | lastRunStatus: eg.union([RunStatus, eg.null]), |
| 54 | }), |
| 55 | ); |
| 56 | export type ProjectSummary = TypeFromCodec<typeof ProjectSummary>; |
| 57 | |
| 58 | export const ProjectConfigSummary = eg.exactStrict( |
| 59 | eg.object({ |
| 60 | id: ProjectId, |
| 61 | ownerUserId: UserId, |
| 62 | ownerSlug: OwnerSlug, |
| 63 | projectSlug: ProjectSlug, |
| 64 | name: eg.string, |
| 65 | repoUrl: eg.string, |
| 66 | defaultBranch: BranchName, |
| 67 | configPath: eg.string, |
| 68 | dispatchMode: DispatchMode, |
| 69 | createdAt: IsoDateTime, |
| 70 | updatedAt: IsoDateTime, |
| 71 | lastRunStatus: eg.union([RunStatus, eg.null]), |
| 72 | }), |
| 73 | ); |
| 74 | export type ProjectConfigSummary = TypeFromCodec<typeof ProjectConfigSummary>; |
| 75 | |
| 76 | export const GetProjectsResponse = eg.exactStrict( |
| 77 | eg.object({ |
| 78 | projects: eg.array(ProjectSummary), |
| 79 | }), |
| 80 | ); |
| 81 | export type GetProjectsResponse = TypeFromCodec<typeof GetProjectsResponse>; |
| 82 | |
| 83 | export const ProjectResponse = eg.exactStrict( |
| 84 | eg.object({ |
| 85 | project: ProjectConfigSummary, |
| 86 | }), |
| 87 | ); |
| 88 | export type ProjectResponse = TypeFromCodec<typeof ProjectResponse>; |
| 89 | |
| 90 | export const PendingRunSummary = eg.exactStrict( |
| 91 | eg.object({ |
| 92 | runId: RunId, |
| 93 | branch: BranchName, |
| 94 | queuedAt: IsoDateTime, |
| 95 | }), |
| 96 | ); |
| 97 | export type PendingRunSummary = TypeFromCodec<typeof PendingRunSummary>; |
| 98 | |
| 99 | export const ProjectDetail = eg.exactStrict( |
| 100 | eg.object({ |
| 101 | project: ProjectConfigSummary, |
| 102 | activeRun: eg.union([RunSummary, eg.null]), |
| 103 | pendingRuns: eg.array(PendingRunSummary), |
| 104 | }), |
| 105 | ); |
| 106 | export type ProjectDetail = TypeFromCodec<typeof ProjectDetail>; |