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

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

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 41 42 43 44 45 46 472x 2x                   2x 2x         2x                     2x               2x                    
import { z } from "zod";
import { flexibleBoolean, requiredId } from "../utils";
 
// ============================================================================
// browse_labels - CQRS Query Tool (discriminated union schema)
// Actions: list, get
// Uses z.discriminatedUnion() for type-safe action handling.
// Schema pipeline flattens to flat JSON Schema for AI clients that don't support oneOf.
// ============================================================================
 
// --- Shared fields ---
const namespaceField = z.string().describe("Namespace path (group or project)");
const includeAncestorGroupsField = flexibleBoolean
  .optional()
  .describe("Include ancestor groups when listing or getting labels");
 
// --- Action: list ---
const ListLabelsSchema = z.object({
  action: z.literal("list").describe("List labels with optional filtering"),
  namespace: namespaceField,
  search: z.string().optional().describe("Keyword to filter labels by"),
  with_counts: flexibleBoolean.optional().describe("Include issue and merge request counts"),
  include_ancestor_groups: includeAncestorGroupsField,
  per_page: z.number().optional().describe("Number of items per page"),
  page: z.number().optional().describe("Page number"),
});
 
// --- Action: get ---
const GetLabelSchema = z.object({
  action: z.literal("get").describe("Get a single label by ID or title"),
  namespace: namespaceField,
  label_id: requiredId.describe("The ID or title of the label"),
  include_ancestor_groups: includeAncestorGroupsField,
});
 
// --- Discriminated union combining all actions ---
export const BrowseLabelsSchema = z.discriminatedUnion("action", [
  ListLabelsSchema,
  GetLabelSchema,
]);
 
// ============================================================================
// Type exports
// ============================================================================
 
export type BrowseLabelsInput = z.infer<typeof BrowseLabelsSchema>;