Skip to content
File

Blob: src/worker/contracts/project-run.ts

typescript101 lines
1import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde";
2 
3import {
4 BranchName,
5 CommitSha,
6 ProjectId,
7 RunId,
8 TriggerType,
9 UnixTimestampMs,
10 UserId,
11 WebhookProvider,
12} from "@/contracts/common";
13import { DispatchMode, ExecutionRuntime } from "@/contracts/execution/dispatch";
14 
15export const AcceptedRunSnapshot = eg.exactStrict(
16 eg.object({
17 runId: RunId,
18 projectId: ProjectId,
19 triggerType: TriggerType,
20 triggeredByUserId: eg.union([UserId, eg.null]),
21 branch: BranchName,
22 commitSha: eg.union([CommitSha, eg.null]),
23 repoUrl: eg.string,
24 configPath: eg.string,
25 dispatchMode: DispatchMode,
26 executionRuntime: ExecutionRuntime,
27 queuedAt: UnixTimestampMs,
28 }),
29);
30export type AcceptedRunSnapshot = TypeFromCodec<typeof AcceptedRunSnapshot>;
31 
32export const AcceptQueuedRunInput = eg.exactStrict(
33 eg.object({
34 projectId: ProjectId,
35 triggerType: TriggerType,
36 triggeredByUserId: eg.union([UserId, eg.null]),
37 branch: BranchName,
38 commitSha: eg.union([CommitSha, eg.null]),
39 repoUrl: eg.string,
40 configPath: eg.string,
41 provider: eg.union([WebhookProvider, eg.null]),
42 deliveryId: eg.union([eg.string, eg.null]),
43 dispatchMode: DispatchMode,
44 executionRuntime: ExecutionRuntime,
45 }),
46);
47export type AcceptQueuedRunInput = TypeFromCodec<typeof AcceptQueuedRunInput>;
48 
49export const AcceptManualRunInput = eg.exactStrict(
50 eg.object({
51 projectId: ProjectId,
52 triggeredByUserId: UserId,
53 branch: eg.union([BranchName, eg.null]),
54 }),
55);
56export type AcceptManualRunInput = TypeFromCodec<typeof AcceptManualRunInput>;
57 
58export const AcceptedRunResult = eg.exactStrict(
59 eg.object({
60 runId: RunId,
61 queuedAt: UnixTimestampMs,
62 executable: eg.boolean,
63 }),
64);
65export type AcceptedRunResult = TypeFromCodec<typeof AcceptedRunResult>;
66 
67export const AcceptManualRunResult = eg.union([
68 eg.exactStrict(
69 eg.object({
70 kind: eg.literal("accepted"),
71 runId: RunId,
72 queuedAt: UnixTimestampMs,
73 executable: eg.boolean,
74 }),
75 ),
76 eg.exactStrict(
77 eg.object({
78 kind: eg.literal("rejected"),
79 reason: eg.literal("queue_full"),
80 }),
81 ),
82]);
83export type AcceptManualRunResult = TypeFromCodec<typeof AcceptManualRunResult>;
84 
85export const PendingRunState = eg.exactStrict(
86 eg.object({
87 runId: RunId,
88 branch: BranchName,
89 queuedAt: UnixTimestampMs,
90 }),
91);
92export type PendingRunState = TypeFromCodec<typeof PendingRunState>;
93 
94export const ProjectDetailState = eg.exactStrict(
95 eg.object({
96 activeRunId: eg.union([RunId, eg.null]),
97 pendingRuns: eg.array(PendingRunState),
98 }),
99);
100export type ProjectDetailState = TypeFromCodec<typeof ProjectDetailState>;