import { Resource } from '../model/note'; import { FoamWorkspace } from '../model/workspace'; import { FoamGraph } from '../model/graph'; import { URI } from '../model/uri'; /** * Builds a RegExp from a user-supplied pattern. Returns either the compiled * regex or a user-facing warning string explaining why it was rejected * (catastrophic backtracking, invalid syntax). The caller is responsible for * logging and/or surfacing the warning. */ export declare function tryBuildUserRegex(pattern: string, source: string, flags?: string): { regex: RegExp; } | { warning: string; }; export type QueryFilter = string | { tag?: string; type?: string; path?: string; title?: string; links_to?: string | URI; links_from?: string | URI; jexl?: string; /** * @deprecated Replaced by `jexl`. The previous implementation used * `eval()` and is no longer evaluated — this field is kept on the * schema only so old query bodies fail loudly rather than being * silently re-interpreted. Use `jexl` instead. */ expression?: string; and?: QueryFilter[]; or?: QueryFilter[]; not?: QueryFilter; }; export type SelectInput = string | { field: string; label?: string; link?: boolean; }; /** * Normalised projection entry. Every field is resolved — renderers read * `link` directly without re-deriving the default. The "title links by * default, everything else is plain text" rule lives in `normalizeSelectEntry`, * not in the rendering layer. */ export type SelectEntry = { field: string; label: string; link: boolean; }; export interface QueryDescriptor { filter?: QueryFilter; select?: SelectInput[]; sort?: string; limit?: number; offset?: number; format?: 'table' | 'list' | 'count'; } export declare function beautifyFieldLabel(field: string): string; export declare function normalizeSelectEntry(input: SelectInput): SelectEntry; /** * A row in a query result. The URI is structurally guaranteed — it's the * resource's identity, present on every projected row regardless of the * `select` clause. All other fields are user-selected. */ export type ResourceView = { uri: URI; } & Record; export declare const DEFAULT_SELECT: SelectEntry[]; export declare const DEFAULT_LIST_SELECT: SelectEntry[]; type Predicate = (r: Resource) => boolean; /** * Result of parsing a filter. `warnings` collects user-facing strings * describing each parse-time problem (rejected regex, deprecated field, * unresolved link target, Jexl compile error, ...). An empty array means * the filter parsed cleanly. Warnings are plain text — callers wrap them * for their output medium (HTML for the markdown preview, log line, etc.). */ export interface FilterResult { predicate: Predicate; warnings: string[]; } export interface QueryExecutionResult { results: ResourceView[]; warnings: string[]; } export declare function parseFilter(filter: QueryFilter | undefined, workspace: FoamWorkspace, graph: FoamGraph, trusted: boolean): FilterResult; /** * Synchronous reader returning the raw markdown source of a resource. * Injected by the host (VS Code, CLI, MCP) so the query layer stays * independent of `IDataStore`'s async API. When omitted, source-derived * fields (`body`, `content`, `section[...]`) resolve to `undefined`. */ export type SourceReader = (uri: URI) => string | null | undefined; /** * Returns true for fields whose value is derived from the resource's raw * source text (`body`, `content`, `section[Label]`, and — eventually — * `block[id]`). These fields require a `SourceReader` to resolve and are * rendered as markdown rather than escaped as scalars. Centralised here so * we add a new content-bearing field by editing one place. */ export declare function requiresSource(field: string): boolean; export declare const ALL_QUERY_FIELDS: string[]; /** * Fluent builder for programmatic queries. * Call `foam.pages(filter)` in foam-query-js blocks to obtain one. */ export declare class QueryResult { private readonly workspace; private readonly graph; private readonly trusted; private readonly readSource?; private _descriptor; private _jsPredicates; constructor(workspace: FoamWorkspace, graph: FoamGraph, trusted: boolean, filter?: QueryFilter, readSource?: SourceReader); get descriptor(): QueryDescriptor; private clone; /** Add a JS predicate applied after the base filter. */ where(predicate: (r: ResourceView) => boolean): QueryResult; sortBy(field: string, direction?: 'asc' | 'desc'): QueryResult; limit(n: number): QueryResult; offset(n: number): QueryResult; select(fields: SelectInput[]): QueryResult; format(f: 'table' | 'list' | 'count'): QueryResult; /** * Executes the query and returns projected ResourceViews. `.where(...)` * predicates may reference source-derived fields, so they force the slow * path: fetch the full view, filter, then sort/limit. Without `.where`, * sort/offset/limit are pushed into `executeQuery` so source is read only * for the surviving slice. */ toArray(): ResourceView[]; } export declare function executeQuery(query: QueryDescriptor, workspace: FoamWorkspace, graph: FoamGraph, options: { trusted: boolean; readSource?: SourceReader; }): QueryExecutionResult; export {}; //# sourceMappingURL=index.d.ts.map