import type { LuaCollectionQuery } from "../../client/space_lua/query_collection.ts"; import { syscall } from "@silverbulletmd/silverbullet/syscall"; import type { ObjectValue } from "../../plug-api/types/index.ts"; /** * Exposes the SilverBullet object indexing system * @module */ /** * Indexes objects for a specific page * @param page - The page identifier where objects will be indexed * @param objects - Array of objects to be indexed * @returns Promise that resolves when indexing is complete */ export function indexObjects( page: string, objects: ObjectValue[], ): Promise { return syscall("index.indexObjects", page, objects); } export function validateObjects( page: string, objects: ObjectValue[], ): Promise<{ error: string; object: ObjectValue } | null> { return syscall("index.validateObjects", page, objects); } /** * Queries objects using a Lua-based collection query * @param tag - The tag to filter objects by * @param query - Lua query parameters to filter objects * @param scopedVariables - Optional variables to be used in the Lua query * @returns Promise that resolves with an array of matching objects */ export function queryLuaObjects( tag: string, query: LuaCollectionQuery, scopedVariables?: Record, ): Promise[]> { return syscall("index.queryLuaObjects", tag, query, scopedVariables); } /** * Retrieves a specific object by its reference * @param page - The page identifier where the object is located * @param tag - The tag of the object * @param ref - The reference identifier of the object * @returns Promise that resolves with the matching object or undefined if not found */ export function getObjectByRef( page: string, tag: string, ref: string, ): Promise | undefined> { return syscall("index.getObjectByRef", page, tag, ref); } /** * Ensures that the full index is built and up-to-date */ export function ensureFullIndex(): Promise { return syscall("index.ensureFullIndex"); } export function reindexSpace(): Promise { return syscall("index.reindexSpace"); } export function deleteObject( page: string, tag: string, ref: string, ): Promise { return syscall("index.deleteObject", page, tag, ref); }