staticql
Version:
Type-safe query engine for static content including Markdown, YAML, JSON, and more.
129 lines (128 loc) • 4.43 kB
TypeScript
import { SourceConfigResolver as Resolver, SourceRecord } from "./SourceConfigResolver.js";
import { StorageRepository } from "./repository/StorageRepository.js";
import { SourceLoader } from "./SourceLoader";
import { LoggerProvider } from "./logger/LoggerProvider";
import { PrefixIndexDepth, PrefixIndexLine } from "./utils/typs.js";
export type DiffEntry = {
status: "A" | "D" | "M";
source: string;
slug: string;
fields?: Record<string, unknown>;
};
export type DirectRelationMap = {
foreignMap: Map<string, SourceRecord[]>;
};
export type ThroughRelationMap = {
targetMap: Map<string, SourceRecord[]>;
throughMap: Map<string, SourceRecord[]>;
};
/**
* Indexer: core class for building and updating search indexes.
*/
export declare class Indexer {
private readonly sourceLoader;
private readonly repository;
private readonly resolver;
private readonly logger;
static indexPrefix: string;
static indexDepth: PrefixIndexDepth;
private cache;
private customIndexers;
constructor(sourceLoader: SourceLoader<SourceRecord>, repository: StorageRepository, resolver: Resolver, logger: LoggerProvider, customIndexers?: Record<string, (value: any, record?: SourceRecord) => any>);
/**
* Saves indexes and slug lists for all sources.
*
* @throws Error if writing to storage fails.
*/
save(): Promise<void>;
/**
* Incrementally updates affected indexes based on diff entries.
*
* @param diffEntries - List of file change entries.
*/
updateIndexesForFiles(diffEntries: DiffEntry[]): Promise<string[]>;
/**
* Get PrefixIndexLines for next page.
*/
readForwardPrefixIndexLines(rootDir: string, pageSize?: number, cursor?: string, orderByKey?: string, isDesc?: boolean): AsyncGenerator<PrefixIndexLine, void, unknown>;
/**
* Get PrefixIndexLines for backward pagination.
*/
readBackwardPrefixIndexLines(rootDir: string, pageSize?: number, cursor?: string, orderByKey?: string, isDesc?: boolean): AsyncGenerator<PrefixIndexLine, void, unknown>;
/**
* Read index file lines.
*/
readIndexFileLines(indexPath: string, reverse: boolean): AsyncGenerator<PrefixIndexLine>;
/**
* Get the first index of the specified directory.
*/
private findFirstIndexPath;
/**
* Get the index of the deepest level below the specified directory.
*/
private findLastIndexPath;
/**
* Indexes are scanned downward from the specified index directory.
*/
walkPrefixIndexesDownword(indexParentDir: string): AsyncGenerator<string>;
/**
* Indexes are scanned upward from the specified index directory.
*/
walkPrefixIndexesUpword(indexParentDir: string): AsyncGenerator<string, void, any>;
/**
*
* @param unflattened
* @returns
*/
flatPrefixIndexLine(unflattened: PrefixIndexLine[]): PrefixIndexLine[];
/**
* Get Prefix Index directories path converted with Unicode.
*
* @param value
* @param depth
* @returns
*/
getPrefixIndexPath(value: string, depth: number): string;
/**
* Builds indexable records for a single source (with joined relations).
*/
private buildRecords;
/**
* Organize the prefix directory paths for each index file location from resolved records.
*/
private getPrefixIndexPathByResolvedRecords;
/**
* Organize the map of search keys for the PrefixIndexLine.
*/
private createIndexLines;
/**
* Get converted PrefixIndex paths.
*/
private collectPrefixDirs;
/**
* Get increametal index entry status.
*/
private getStatus;
/**
* Extract index field from SourceRecord.
*/
private extractIndexField;
/**
* Determines whether the relation is a through-type.
*/
private isThroughRelation;
/** Returns the path to the prefixes index dir. */
static getIndexDir(sourceName: string, field: string): string;
/**
* Get Prefix Index file path converted with Unicode.
*/
private getIndexPath;
/**
* Find PrefixIndexLine list with stream.
*/
findIndexLines(sourceName: string, field: string, value: string, filterCallback?: (indexValue: string, argValue: string) => boolean): Promise<null | PrefixIndexLine[]>;
/**
* Sort PrefixIndexLine.
*/
private indexSort;
}