import { native, object, integer, filters, text } from "./core.ts"; import type { SearchInput } from "./core.ts"; import type { MessagePage } from "./types.ts"; /** * Search local message text with a literal, case-insensitive substring, including archived text. * @param input - Required query (1..500 characters), optional chatId, limit (1..50, default 20), scanLimit (1..200, default 100), beforeMessageId, ISO after/before, service, and fromMe. Follow the cursor until hasMore is false for a complete search. * @returns Matching messages and scan counts. Text or archives over 64 KiB may be truncated or unavailable, never silently claimed as a complete search. * @example * import search from 'kody:@tannerlinsley/imessage/search'; * const page = await search({query:'dinner',limit:10,scanLimit:100}); */ export default async function search(input: SearchInput): Promise { const p = object(input, [ "query", "chatId", "limit", "scanLimit", "beforeMessageId", "after", "before", "service", "fromMe", ]); return native({ action: "search", ...filters(p), query: text(p.query, "query", 500), limit: integer(p.limit, "limit", 20, 50), scanLimit: integer(p.scanLimit, "scanLimit", 100, 200), }); }