import type { LuaCollectionQuery, LuaQueryCollection, } 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); } /** * Run the full indexing pipeline (validation, multi-tag expansion, * tag transforms) and return the resulting objects each paired with * the tag they're indexed under. Read-only — no DB writes. */ export function previewProcessedObjects( page: string, objects: ObjectValue[], ): Promise<{ tag: string; object: ObjectValue }[]> { return syscall("index.previewProcessedObjects", page, objects); } /** * Returns objects carrying the given tag as a query collection. */ export function objects(tagName: string): Promise { return syscall("index.objects", tagName); } /** * Returns all pages (optionally filtered by an additional tag) as a query collection. */ export function pages(tagName?: string): Promise { return syscall("index.pages", tagName); } /** * Returns all sub-pages of the given page (pages whose name starts with `/`) * as a query collection. */ export function subPages(pageName: string): Promise { return syscall("index.subPages", pageName); } /** * Returns all documents as a query collection. */ export function documents(): Promise { return syscall("index.documents"); } /** * Returns all links as a query collection. */ export function links(): Promise { return syscall("index.links"); } /** * Returns all relation objects as a query collection. */ export function relations(): Promise { return syscall("index.relations"); } /** * Returns all tasks (optionally filtered by an additional tag) as a query collection. */ export function tasks(tagName?: string): Promise { return syscall("index.tasks", tagName); } /** * Returns all headers (optionally filtered by an additional tag) as a query collection. */ export function headers(tagName?: string): Promise { return syscall("index.headers", tagName); } /** * Returns all list items (optionally filtered by an additional tag) as a query collection. */ export function items(tagName?: string): Promise { return syscall("index.items", tagName); } /** * Returns all paragraphs (optionally filtered by an additional tag) as a query collection. */ export function paragraphs(tagName?: string): Promise { return syscall("index.paragraphs", tagName); } /** * Returns all tables (optionally filtered by an additional tag) as a query collection. */ export function tables(tagName?: string): Promise { return syscall("index.tables", tagName); } /** * Returns all aspiring (referenced but not yet created) pages as a query collection. */ export function aspiringPages(): Promise { return syscall("index.aspiringPages"); } /** * Returns all tag objects as a query collection. */ export function tags(): Promise { return syscall("index.tags"); } /** * 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); } export type { AnchorHit, ResolveAnchorResult, } from "../../plugs/index/types.ts"; import type { ResolveAnchorResult } from "../../plugs/index/types.ts"; /** * Resolves a `$name` anchor to its host. Returns `ok: true` with page + * hostTag + range on success, or `ok: false` with `missing`/`duplicate` * reason. When `page` is provided, the lookup is filtered to that page. */ export function resolveAnchor( name: string, page?: string, ): Promise { return syscall("index.resolveAnchor", name, page); } /** * Returns a map of tag name → raw JSON Schema for every defined object-type / * [[Tag]] that declares a schema. Tags without a schema are omitted. * Use it to discover what attributes a tag's objects carry before querying them. */ export function describeSchema(): Promise> { return syscall("index.describeSchema"); } /** * Returns the raw JSON Schema for a single tag, or null if the tag is not * defined or has no schema. */ export function tagSchema(tagName: string): Promise { return syscall("index.tagSchema", tagName); }