import { ServiceNowInstance } from "../ServiceNowInstance.js"; import { CodeSearchOptions, CodeSearchResult, CodeSearchRecordTypeResult, CodeSearchTable, CodeSearchGroup, CodeSearchGroupQueryOptions, AddCodeSearchTableOptions, CodeSearchTableRecord } from './CodeSearchModels.js'; /** * CodeSearch class for querying ServiceNow's code search REST API. * Supports searching across the platform, within specific applications or tables, * listing search groups, and listing tables within a search group. */ export declare class CodeSearch { private static readonly SEARCH_API_PATH; private static readonly TABLES_API_PATH; private static readonly SEARCH_GROUP_TABLE; private static readonly SEARCH_TABLE_TABLE; private _logger; private _req; private _tableAPI; private _instance; constructor(instance: ServiceNowInstance); /** * Search across the ServiceNow platform for code matching the given term. * Returns flattened results for easy consumption by CLI and MCP consumers. * Uses GET /api/sn_codesearch/code_search/search * * @param options Search options including the required search term * @returns Array of flattened CodeSearchResult items * @throws Error if term is empty or if table is specified without search_group */ search(options: CodeSearchOptions): Promise; /** * Search and return the raw hierarchical response from the API. * Results are grouped by record type, then by hit, then by field match. * Use this when you need the full response structure. * * @param options Search options including the required search term * @returns Array of CodeSearchRecordTypeResult groups * @throws Error if term is empty or if table is specified without search_group */ searchRaw(options: CodeSearchOptions): Promise; /** * Search for code within a specific application scope. * Convenience method that sets current_app and search_all_scopes=false. * * @param term The search term * @param appScope The application scope to search within (e.g., "x_myapp") * @param additionalOptions Optional additional search options * @returns Array of flattened CodeSearchResult items */ searchInApp(term: string, appScope: string, additionalOptions?: Omit): Promise; /** * Search for code within a specific table. * Convenience method that sets table and search_group. * * @param term The search term * @param tableName The table to search in * @param searchGroup The search group name (required when searching by table) * @param additionalOptions Optional additional search options * @returns Array of flattened CodeSearchResult items */ searchInTable(term: string, tableName: string, searchGroup: string, additionalOptions?: Omit): Promise; /** * List the tables that would be searched for a given search group. * Uses GET /api/sn_codesearch/code_search/tables * * @param searchGroup The search group NAME * @returns Array of CodeSearchTable items * @throws Error if searchGroup is empty */ getTablesForSearchGroup(searchGroup: string): Promise; /** * List all available code search groups. * Queries the sn_codesearch_search_group table via Table API. * * @param options Optional query/limit options * @returns Array of CodeSearchGroup records */ getSearchGroups(options?: CodeSearchGroupQueryOptions): Promise; /** * Add a new table to an existing code search group. * Inserts a record into the sn_codesearch_table table via Table API POST. * * @param options The table name, search fields, and search group sys_id * @returns The created CodeSearchTableRecord including its sys_id * @throws Error if any required field is empty or if the API call fails */ addTableToSearchGroup(options: AddCodeSearchTableOptions): Promise; /** * List table records for a search group from the sn_codesearch_table table. * Unlike getTablesForSearchGroup() which uses the REST API and returns {name, label}, * this method uses the Table API and returns full records including sys_id. * * @param searchGroupSysId The sys_id of the search group * @param options Optional query/limit options * @returns Array of CodeSearchTableRecord records * @throws Error if searchGroupSysId is empty or if the API call fails */ getTableRecordsForSearchGroup(searchGroupSysId: string, options?: CodeSearchGroupQueryOptions): Promise; /** * Flatten the hierarchical search API response into a simple array of results. * Each entry represents one field match in one record — ideal for CLI display or MCP output. * * @param rawResults The raw record type results from searchRaw() * @returns Flattened array of CodeSearchResult */ static flattenResults(rawResults: CodeSearchRecordTypeResult[]): CodeSearchResult[]; /** * Format flattened search results as a simple text summary. * Useful for CLI output. * * @param results Flattened search results from search() * @returns Formatted string */ static formatResultsAsText(results: CodeSearchResult[]): string; }