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

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

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 47 48 49 50 51 52 53 54 554x                   4x 4x                         4x               4x                       4x                    
import { z } from "zod";
 
// ============================================================================
// browse_variables - 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 filterField = z
  .object({
    environment_scope: z
      .string()
      .optional()
      .describe(
        'The environment scope filter. Use "*" for all environments or specific environment name like "production".'
      ),
  })
  .optional()
  .describe("Filter parameters for variable lookup");
 
// --- Action: list ---
const ListVariablesSchema = z.object({
  action: z.literal("list").describe("List all CI/CD variables"),
  namespace: namespaceField,
  per_page: z.number().optional().describe("Number of items per page"),
  page: z.number().optional().describe("Page number"),
});
 
// --- Action: get ---
const GetVariableSchema = z.object({
  action: z.literal("get").describe("Get a single CI/CD variable by key"),
  namespace: namespaceField,
  key: z
    .string()
    .describe(
      "The key of the CI/CD variable. Maximum 255 characters, alphanumeric and underscore only."
    ),
  filter: filterField,
});
 
// --- Discriminated union combining all actions ---
export const BrowseVariablesSchema = z.discriminatedUnion("action", [
  ListVariablesSchema,
  GetVariableSchema,
]);
 
// ============================================================================
// Type exports
// ============================================================================
 
export type BrowseVariablesInput = z.infer<typeof BrowseVariablesSchema>;