import type { EponymeCollectionDefinition, EponymeCollectionDefinitionBase, EponymeConfig, EponymeData, EponymeFormDefinitionBase, EponymeSchema, EponymeStatus, FieldValue } from './eponyme.js'; import type { ArrayFieldDefinition, ArrayItemDefinition, ArrayItemFieldDefinition, ArrayItemSchema, ArrayItemValue, FieldDefinition, RelationFieldDefinition, SectionFieldDefinition, TabFieldDefinition } from './field.js'; /** * How many levels of relations a read resolves. `0` leaves every relation as the slug it stores. The * runtime ceiling is `eponyme.relations.maxDepth`; the type stops at 5. */ export type EponymePopulateDepth = 0 | 1 | 2 | 3 | 4 | 5; /** `PrevDepth[D]` is `D - 1`, floored at zero. */ type PrevDepth = [0, 0, 1, 2, 3, 4]; /** What a populated relation holds in place of the slug it stores. */ export interface EponymeRelationTarget> { /** `/`, the name the entry is read and cache-tagged by. */ name: string; /** What the relation stores: the slug of a collection entry, or the name of a singleton in its folder. */ slug: string; /** The collection's title field, or the slug when it is empty or the target is a singleton. */ title: string; data: Data; status: EponymeStatus; publishedAt: string | null; updatedAt: string | null; } /** The node of the config a slash-separated name designates. */ export type EponymeConfigNodeAtPath = Name extends `${infer Folder}/${infer Rest}` ? Folder extends keyof T ? T[Folder] extends EponymeConfig ? EponymeConfigNodeAtPath : never : never : Name extends keyof T ? T[Name] : never; /** The schema of a singleton or of a collection, by name. */ export type EponymeSchemaByName = EponymeConfigNodeAtPath extends infer Node ? Node extends EponymeCollectionDefinition ? Schema : Node extends EponymeCollectionDefinitionBase | EponymeFormDefinitionBase ? never : Node extends EponymeSchema ? Node : never : never; /** The content a relation's target holds, resolved to the given depth. */ export type EponymeRelationTargetData = string extends To ? Record : EponymeConfigNodeAtPath extends infer Node ? Node extends EponymeCollectionDefinition ? EponymePopulatedData : Node extends EponymeCollectionDefinitionBase | EponymeFormDefinitionBase ? Record : Node extends EponymeSchema ? Record : Node extends EponymeConfig ? { [K in keyof Node]: Node[K] extends EponymeCollectionDefinitionBase | EponymeFormDefinitionBase ? never : Node[K] extends EponymeSchema ? EponymePopulatedData : never; }[keyof Node] : Record : never; type PopulatedRelation = Multiple extends true ? Array>> : EponymeRelationTarget> | null; type PopulatedArrayItem = Item extends RelationFieldDefinition ? PopulatedRelation : Item extends ArrayItemFieldDefinition ? ArrayItemValue : Item extends ArrayItemSchema ? { [K in keyof Item]: PopulatedArrayItem; } : never; /** One field's value once its relations, at any depth of sections, tabs and arrays, are resolved. */ export type EponymePopulatedValue = F extends RelationFieldDefinition ? PopulatedRelation : F extends ArrayFieldDefinition ? Array> : F extends SectionFieldDefinition ? { [K in keyof Section]: EponymePopulatedValue; } : F extends TabFieldDefinition ? { [K in keyof Tabs]: { [P in keyof Tabs[K]['fields']]: EponymePopulatedValue; }; } : FieldValue; /** A schema's data with its relations resolved to `Depth` levels. `0` is the stored shape. */ export type EponymePopulatedData = Depth extends 0 ? EponymeData : { [K in keyof S]: S[K] extends FieldDefinition ? EponymePopulatedValue : never; }; /** An entry that points at another, as the inverse lookup returns it. */ export interface EponymeReferrer { /** Full name of the entry holding the reference. */ name: string; /** Set when the referrer is a collection entry. */ collection: string | null; slug: string | null; title: string; status: EponymeStatus; publishedAt: string | null; updatedAt: string | null; } export {};