All files / src/entities/wiki 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 47 48 49 50 5116x 16x                   16x     16x               16x             16x           16x                              
import { z } from 'zod';
import { flexibleBoolean, paginationFields } from '../utils';
 
// ============================================================================
// browse_wiki - 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)');
 
// --- Action: list ---
const ListWikiSchema = z.object({
  action: z.literal('list').describe('List all wiki pages'),
  namespace: namespaceField,
  with_content: flexibleBoolean.optional().describe('Include content of the wiki pages'),
  ...paginationFields(),
});
 
// --- Action: get ---
const GetWikiSchema = z.object({
  action: z.literal('get').describe('Get a single wiki page by slug'),
  namespace: namespaceField,
  slug: z.string().describe('URL-encoded slug of the wiki page'),
});
 
// --- Discriminated union combining all actions ---
export const BrowseWikiSchema = z.discriminatedUnion('action', [ListWikiSchema, GetWikiSchema]);
 
// ============================================================================
// Response schemas for wiki pages
// ============================================================================
 
export const GitLabWikiPageSchema = z.object({
  title: z.string(),
  slug: z.string(),
  format: z.string(),
  content: z.string().optional(),
  created_at: z.string().optional(),
  updated_at: z.string().optional(),
});
 
// ============================================================================
// Type exports
// ============================================================================
 
export type BrowseWikiInput = z.infer<typeof BrowseWikiSchema>;
export type GitLabWikiPage = z.infer<typeof GitLabWikiPageSchema>;