staticql
Version:
Type-safe query engine for static content including Markdown, YAML, JSON, and more.
58 lines (57 loc) • 2.36 kB
TypeScript
import { Validator } from "./validator/Validator.js";
import type { StorageRepository } from "./repository/StorageRepository.js";
import { ResolvedSourceConfig as RSC, SourceConfigResolver as Resolver, SourceRecord } from "./SourceConfigResolver.js";
/**
* Responsible for loading and validating content from static sources.
*/
export declare class SourceLoader<T extends SourceRecord> {
private repository;
private resolver;
private validator;
private cache;
constructor(repository: StorageRepository, resolver: Resolver, validator: Validator);
/**
* Loads all records for a given source name.
*
* @param sourceName - The name of the source defined in config.
* @returns An array of validated records.
*/
loadBySourceName(sourceName: string): Promise<T[]>;
/**
* Loads and validates content from a specific file path.
*
* @param filePath - The path to the file.
* @param rsc - The resolved source configuration.
* @returns Parsed and validated content.
*/
load(filePath: string, rsc: RSC): Promise<any>;
/**
* Loads and validates a single record by source name and slug.
* If the file contains an array of records, the one matching the slug is returned.
*
* @param sourceName - The name of the source defined in config.
* @param slug - The unique slug identifier.
* @returns The matching validated record.
* @throws If the source or slug is not found or fails validation.
*/
loadBySlug(sourceName: string, slug: string): Promise<T>;
/**
* Loads and validates multiple records by slugs for the given source.
*
* @param sourceName - The name of the source.
* @param slugs - Array of slug identifiers.
* @returns An array of matched and validated records.
*/
loadBySlugs(sourceName: string, slugs: string[]): Promise<T[]>;
/**
* Parses and validates a single file.
* Ensures slug consistency if the file name pattern contains wildcards.
*
* @param filePath - Logical file path (may include pattern).
* @param rsc - The resolved source configuration.
* @param fullPath - Actual resolved file path.
* @returns Parsed and validated record and raw data.
* @throws If the slug is inconsistent or unsupported type.
*/
private parseFile;
}