All files / src/entities/webhooks schema-readonly.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 414x 4x                         4x               4x               4x                    
import { z } from "zod";
import { PaginationOptionsSchema } from "../shared";
 
// ============================================================================
// list_webhooks - CQRS Query Tool (discriminated union schema)
// Actions: project, group
//
// Uses z.discriminatedUnion() for type-safe scope handling.
// Each scope has only its relevant ID field:
// - scope="project" requires projectId
// - scope="group" requires groupId
// ============================================================================
 
// --- Project scope: list webhooks for a project ---
const ListProjectWebhooksSchema = z
  .object({
    scope: z.literal("project").describe("List webhooks for a project"),
    projectId: z.string().describe("Project ID or path"),
  })
  .merge(PaginationOptionsSchema);
 
// --- Group scope: list webhooks for a group ---
const ListGroupWebhooksSchema = z
  .object({
    scope: z.literal("group").describe("List webhooks for a group"),
    groupId: z.string().describe("Group ID or path"),
  })
  .merge(PaginationOptionsSchema);
 
// --- Discriminated union combining all scopes ---
export const ListWebhooksSchema = z.discriminatedUnion("scope", [
  ListProjectWebhooksSchema,
  ListGroupWebhooksSchema,
]);
 
// ============================================================================
// Type exports
// ============================================================================
 
export type ListWebhooksOptions = z.infer<typeof ListWebhooksSchema>;