import type eponymeConfig from '#eponyme/config'; import type { H3Event } from 'h3'; import type { EponymeCollectionFilter, EponymeCollectionName, EponymeName, EponymeSchema, EponymeStatus } from '../../types/index.js'; import type { EponymePopulateDepth, EponymePopulatedData, EponymeReferrer, EponymeSchemaByName } from '../../types/relations.js'; import type { EponymeSortDirection } from '../services/eponyme-store.js'; type Config = typeof eponymeConfig; type CollectionName = EponymeCollectionName; type SingletonName = EponymeName; /** The data of a singleton or collection entry, with its relations resolved `Depth` levels deep. */ export type EponymeReadData = EponymeSchemaByName extends infer Schema extends EponymeSchema ? EponymePopulatedData : Record; export interface EponymeReadOptions { /** * `published` (the default) answers what a visitor sees: live now, scheduling and trash included. `draft` * reads the working copy - server code is trusted, so no session is asked for. */ status?: 'published' | 'draft'; /** Levels of relations to resolve. `0` keeps the stored slugs. */ depth?: Depth; /** Keeps `{{ variables }}` unresolved. */ raw?: boolean; /** * The request to tag the response of. Defaults to the current one when Nitro's `asyncContext` is on; * a draft read never tags anything. */ event?: H3Event; } /** A singleton as a server read returns it. */ export interface EponymeSingletonEntry { name: string; data: Data; status: EponymeStatus; publishedAt: string | null; scheduledPublishAt: string | null; scheduledUnpublishAt: string | null; updatedAt: string | null; } /** A collection entry as a server read returns it. */ export interface EponymeServerEntry extends EponymeSingletonEntry { collection: string; slug: string; title: string; } export interface EponymeCollectionReadOptions extends EponymeReadOptions { /** Keeps only the entries matching every key, as on the public listing. */ where?: EponymeCollectionFilter; /** A metadata key (`updatedAt`, `publishedAt`, `title`, `slug`) or a field of the collection. */ orderBy?: 'updatedAt' | 'publishedAt' | 'title' | 'slug' | (keyof EponymeReadData & string); order?: EponymeSortDirection; /** No ceiling: server code may read a whole collection, a sitemap being the usual reason. */ limit?: number; offset?: number; /** Substring of the title or of the slug. */ search?: string; } export interface EponymeCollectionReadResult { entries: Array>; /** Matching entries before `limit` and `offset`. */ total: number; } export interface EponymeReferrersOptions { /** Only referrers of this collection. */ collection?: CollectionName; /** `published` (the default) only returns live referrers whose published version holds the reference. */ status?: 'published' | 'draft'; event?: H3Event; } /** * One collection entry by slug, typed from the config. `null` when it does not exist, is in the trash, or - * for a published read - is not live right now. * * @example * ```ts * const redirect = await getEponymeEntry('redirects', slug) * const article = await getEponymeEntry('articles', slug, { depth: 1 }) * article?.data.author?.data.name * ``` */ export declare function getEponymeEntry(collection: Name, slug: string, options?: EponymeReadOptions): Promise> | null>; /** * One singleton, typed from the config. `null` when a published read finds it unpublished or not yet live. * * @example * ```ts * const home = await getEponymeSingleton('pages/home', { depth: 1 }) * ``` */ export declare function getEponymeSingleton(name: Name, options?: EponymeReadOptions): Promise> | null>; /** * A filtered, sorted page of a collection, typed from the config. The filter goes through the same index * as the public listing; published reads only see what is live. * * @example * ```ts * const { entries } = await queryEponymeCollection('articles', { * where: { tags: 'nuxt' }, * orderBy: 'publishedAt', * limit: 10, * depth: 1, * }) * ``` */ export declare function queryEponymeCollection(collection: Name, options?: EponymeCollectionReadOptions): Promise>>; /** * Entries pointing at `target` (`/`, or a singleton's name), read from the relation index * rather than by scanning content. * * @example * ```ts * const articles = await getEponymeReferrers('authors/jane', { collection: 'articles' }) * ``` */ export declare function getEponymeReferrers(target: string, options?: EponymeReferrersOptions): Promise; /** * Adds tags to a response without dropping the ones already there, so several reads in one handler all * end up in the header a CDN purges by. */ export declare function appendEponymeCacheTags(event: H3Event, tags: string[]): void; export {};