UNPKG

staticql

Version:

Type-safe query engine for static content including Markdown, YAML, JSON, and more.

45 lines (44 loc) 2.21 kB
import { DirectRelationMap, ThroughRelationMap } from "../Indexer.js"; import { DirectRelation, SourceRecord, ThroughRelation } from "../SourceConfigResolver.js"; /** * Builds a map from foreign key values to parent objects. * * Useful for indexing related records by a specified field. * * @param data - Array of objects to index. * @param foreignKeyPath - Dot-notated path to the key field. * @returns A map of key to array of matching objects. */ export declare function buildForeignKeyMap(data: SourceRecord[], foreignKeyPath: string): Map<string, SourceRecord[]>; /** * Finds map entries whose keys partially match a keyword. * * @param map - A map to search. * @param keyword - Keyword to match. * @param options - Optional case-insensitive matching. * @returns Matching values. */ export declare function findEntriesByPartialKey<K extends string | undefined, V>(map: Map<K, V>, keyword: string, options?: { caseInsensitive?: boolean; }): V[]; /** * Resolves a direct relation (e.g., hasOne, hasMany) for a given row. * * @param row - The source object. * @param rel - Relation metadata (including localKey and foreignKey). * @param foreignData - The target dataset to match against. * @param foreignMapOpt - (optional) Pre-built foreign key map for performance. * @returns Related object(s) or null. */ export declare function resolveDirectRelation(row: any, rel: DirectRelation, foreignData: SourceRecord[], foreignMapOpt?: DirectRelationMap["foreignMap"]): SourceRecord | SourceRecord[] | null; /** * Resolves a through-relation (e.g., hasOneThrough, hasManyThrough). * * @param row - The source object. * @param rel - Relation metadata including through and target keys. * @param throughData - The intermediate dataset. * @param targetData - The final related dataset. * @param targetMapOpt - (optional) Pre-built target key map for performance. * @returns Related object(s) or null. */ export declare function resolveThroughRelation(row: any, rel: ThroughRelation, throughData: SourceRecord[], targetData: SourceRecord[], targetMapOpt?: ThroughRelationMap["targetMap"], throughMapOpt?: ThroughRelationMap["targetMap"]): SourceRecord | SourceRecord[] | null;