File
Blob: src/worker/contracts/primitives.ts
| 1 | import { eg, type TypeFromCodec } from "@cloudflare/util-en-garde"; |
| 2 | |
| 3 | export const PositiveInteger = eg.brand("PositiveInteger", eg.number, (value) => Number.isInteger(value) && value > 0); |
| 4 | export type PositiveInteger = TypeFromCodec<typeof PositiveInteger>; |
| 5 | |
| 6 | export const ProjectRunStatus = eg.union([ |
| 7 | eg.literal("pending"), |
| 8 | eg.literal("executable"), |
| 9 | eg.literal("active"), |
| 10 | eg.literal("cancel_requested"), |
| 11 | eg.literal("passed"), |
| 12 | eg.literal("failed"), |
| 13 | eg.literal("canceled"), |
| 14 | ]); |
| 15 | export type ProjectRunStatus = TypeFromCodec<typeof ProjectRunStatus>; |
| 16 | |
| 17 | export const ProjectRunTerminalStatus = eg.union([eg.literal("passed"), eg.literal("failed"), eg.literal("canceled")]); |
| 18 | export type ProjectRunTerminalStatus = TypeFromCodec<typeof ProjectRunTerminalStatus>; |
| 19 | |
| 20 | export const D1SyncStatus = eg.union([ |
| 21 | eg.literal("needs_create"), |
| 22 | eg.literal("needs_update"), |
| 23 | eg.literal("current"), |
| 24 | eg.literal("needs_terminal_update"), |
| 25 | eg.literal("done"), |
| 26 | ]); |
| 27 | export type D1SyncStatus = TypeFromCodec<typeof D1SyncStatus>; |
| 28 | |
| 29 | export const DispatchStatus = eg.union([ |
| 30 | eg.literal("blocked"), |
| 31 | eg.literal("pending"), |
| 32 | eg.literal("queued"), |
| 33 | eg.literal("started"), |
| 34 | eg.literal("terminal"), |
| 35 | ]); |
| 36 | export type DispatchStatus = TypeFromCodec<typeof DispatchStatus>; |
| 37 | |
| 38 | export const isTerminalStatus = (status: string): status is ProjectRunTerminalStatus => |
| 39 | ProjectRunTerminalStatus.is(status); |