Skip to content
File

Blob: src/worker/tasks/types.ts

typescript65 lines
1import { z } from "zod";
2 
3export { z };
4 
5export type RepoQueueMessageHandle<Body> = MessageBatch<Body>["messages"][number];
6 
7export const CompactionQueueMessageSchema = z.object({
8 kind: z.literal("compaction"),
9 doId: z.string(),
10 repoId: z.string().optional(),
11});
12 
13export type CompactionQueueMessage = z.infer<typeof CompactionQueueMessageSchema>;
14 
15export const CompactionDeleteQueueMessageSchema = z.object({
16 kind: z.literal("compaction-delete"),
17 doId: z.string(),
18 repoId: z.string().optional(),
19 packKeys: z.array(z.string()),
20});
21 
22export type CompactionDeleteQueueMessage = z.infer<typeof CompactionDeleteQueueMessageSchema>;
23 
24export const PackRefBackfillQueueMessageSchema = z.object({
25 kind: z.literal("pack-ref-backfill"),
26 doId: z.string(),
27 repoId: z.string().optional(),
28 packKey: z.string(),
29});
30 
31export type PackRefBackfillQueueMessage = z.infer<typeof PackRefBackfillQueueMessageSchema>;
32 
33export const RouteCacheSyncMessageSchema = z.object({
34 kind: z.literal("route-cache-sync"),
35 repositoryId: z.string(),
36 namespaceSlug: z.string(),
37 repoSlug: z.string(),
38 enqueuedAt: z.number(),
39});
40 
41export type RouteCacheSyncMessage = z.infer<typeof RouteCacheSyncMessageSchema>;
42 
43export const RepositoryDeleteMessageSchema = z.object({
44 kind: z.literal("repository-delete"),
45 repositoryId: z.string(),
46 namespaceId: z.string(),
47 namespaceSlug: z.string(),
48 repoSlug: z.string(),
49 doName: z.string(),
50 actor: z.string(),
51 requestedAt: z.number(),
52});
53 
54export type RepositoryDeleteMessage = z.infer<typeof RepositoryDeleteMessageSchema>;
55 
56export const RepoTaskQueueMessageSchema = z.discriminatedUnion("kind", [
57 CompactionQueueMessageSchema,
58 CompactionDeleteQueueMessageSchema,
59 PackRefBackfillQueueMessageSchema,
60 RouteCacheSyncMessageSchema,
61 RepositoryDeleteMessageSchema,
62]);
63 
64export type RepoTaskQueueMessage = z.infer<typeof RepoTaskQueueMessageSchema>;