import type { ArrayFieldDefinition, ArrayItemValue, BooleanFieldDefinition, CheckboxGroupFieldDefinition, EmailFieldDefinition, EponymeCustomFieldDefinition, FieldDefinition, EponymeImageValue, ImageFieldDefinition, MediaPlayerFieldDefinition, MediaPlayerValue, NumberFieldDefinition, PhoneFieldDefinition, RadioFieldDefinition, RelationFieldDefinition, SectionFieldDefinition, SectionValue, SelectFieldDefinition, SlugFieldDefinition, StringFieldDefinition, TabFieldDefinition, TagsFieldDefinition, TagsValueOf, TabsValue, TextareaFieldDefinition, UrlFieldDefinition, UrlValue } from './field.js'; export type EponymeAction = 'draft' | 'publish' | 'unpublish' | 'revertToDraft' | 'schedule' | 'unschedule'; export type EponymeStatus = 'draft' | 'published' | 'unpublished'; export type EponymeSchema = Record; export interface EponymeCollectionDefinitionBase { __eponymeCollection: true; label?: string; description?: string; addLabel?: string; publication?: boolean; fields: EponymeSchema; slugField: string; titleField: string; } export interface EponymeCollectionOptions { label?: string; description?: string; /** Replaces the whole text of the create button. Defaults to `+ New `. */ addLabel?: string; /** Whether entries of this collection offer the publication tab. */ publication?: boolean; fields: T; slugField: keyof T & string; titleField: keyof T & string; } export interface EponymeCollectionDefinition extends EponymeCollectionOptions { __eponymeCollection: true; fields: T; slugField: keyof T & string; titleField: keyof T & string; } /** A public form only accepts field types a visitor can meaningfully fill in. */ export type EponymeFormFieldDefinition = StringFieldDefinition | TextareaFieldDefinition | EmailFieldDefinition | PhoneFieldDefinition | UrlFieldDefinition | NumberFieldDefinition | BooleanFieldDefinition | SelectFieldDefinition | RadioFieldDefinition | CheckboxGroupFieldDefinition; export type EponymeFormSchema = Record; /** `custom` leaves delivery to the host application; `managed` stores the submission. */ export type EponymeFormMode = 'custom' | 'managed'; export interface EponymeFormSubmissionOptions { mode?: EponymeFormMode; /** * Whether the dashboard collects submissions a `custom` route stored itself with * `storeEponymeFormSubmission()`. */ store?: boolean; /** Maximum retained rows for this form. `false` disables the cap. @default 10000 */ maxStored?: number | false; /** Delete rows older than this many days. `false` disables age retention. @default 365 */ retentionDays?: number | false; } export interface EponymeFormOptions { label?: string; description?: string; fields: T; submission?: EponymeFormSubmissionOptions; /** Name of the trap field bots fill in. `false` disables the check. */ honeypot?: string | false; /** In bytes. */ maxBodyBytes?: number; } export interface EponymeFormDefinitionBase { __eponymeForm: true; label?: string; description?: string; fields: EponymeFormSchema; submission: Required; honeypot: string | false; maxBodyBytes: number; } export interface EponymeFormDefinition extends EponymeFormDefinitionBase { fields: T; } export interface EponymeConfig { [name: string]: EponymeSchema | EponymeCollectionDefinitionBase | EponymeFormDefinitionBase | EponymeConfig; } export type CollectionSlugField = { [K in keyof T & string]: T[K] extends SlugFieldDefinition ? K : never; }[keyof T & string]; export type FieldValue = T extends { type: 'number' | 'duration'; } ? number : T extends { type: 'boolean'; } ? boolean : T extends UrlFieldDefinition ? UrlValue : T extends MediaPlayerFieldDefinition ? MediaPlayerValue : T extends ArrayFieldDefinition ? Array> : T extends CheckboxGroupFieldDefinition ? Value[] : T extends RelationFieldDefinition ? (Multiple extends true ? string[] : string) : T extends TagsFieldDefinition ? Array> : T extends EponymeCustomFieldDefinition ? Value : T extends SectionFieldDefinition ? SectionValue
: T extends TabFieldDefinition ? TabsValue : T extends ImageFieldDefinition ? EponymeImageValue | null : string; export type EponymeData = { [K in keyof T]: T[K] extends FieldDefinition ? FieldValue : never; }; export type EponymeDataByName> = EponymeDataAtPath; export type EponymeCollectionName = { [K in keyof T & string]: T[K] extends EponymeCollectionDefinitionBase ? K : T[K] extends EponymeFormDefinitionBase ? never : T[K] extends EponymeSchema ? never : T[K] extends EponymeConfig ? `${K}/${EponymeCollectionName}` : never; }[keyof T & string]; export type EponymeCollectionDataByName> = EponymeCollectionAtPath extends EponymeCollectionDefinition ? EponymeData : never; /** Field types a `where` can filter on, mirroring the write path's `INDEXABLE_TYPES`. */ type FilterableFieldType = 'tags' | 'checkboxGroup' | 'select' | 'radio' | 'boolean' | 'date' | 'datetime'; /** A multi-valued field is filtered by one of its items, not by the whole list. */ type FilterOperand = FieldValue extends readonly (infer Item)[] ? Item : FieldValue; /** * Bounds, offered only where alphabetical order is the value's natural order - which is `field.date()` and * `field.datetime()`, both pinned to chronological strings. */ export interface EponymeFilterBounds { gte?: string; lte?: string; gt?: string; lt?: string; } type FilterOperators = { /** Any of these, the same as passing the list directly. */ in?: readonly FilterOperand[]; /** None of these. Combines with the positive operators to narrow then subtract. */ not?: FilterOperand | readonly FilterOperand[]; /** Substring of the stored value, case-insensitive. */ contains?: string; } & (T extends { type: 'date' | 'datetime'; } ? EponymeFilterBounds : unknown); /** The values of one key are ORed; the keys of a `where` are ANDed. */ export type EponymeFieldFilter = FilterOperand | readonly FilterOperand[] | FilterOperators; /** The filter a schema accepts, keyed by field name. */ export type EponymeFilterInput = { [K in keyof T as T[K] extends { type: FilterableFieldType; } ? K : never]?: T[K] extends FieldDefinition ? EponymeFieldFilter : never; }; export type EponymeCollectionFilter> = EponymeCollectionAtPath extends EponymeCollectionDefinition ? EponymeFilterInput : never; export type EponymeName = { [K in keyof T & string]: T[K] extends EponymeCollectionDefinitionBase ? never : T[K] extends EponymeFormDefinitionBase ? never : T[K] extends EponymeSchema ? K : T[K] extends EponymeConfig ? `${K}/${EponymeName}` : never; }[keyof T & string]; export type EponymeFormName = { [K in keyof T & string]: T[K] extends EponymeFormDefinitionBase ? K : T[K] extends EponymeCollectionDefinitionBase ? never : T[K] extends EponymeSchema ? never : T[K] extends EponymeConfig ? `${K}/${EponymeFormName}` : never; }[keyof T & string]; export type EponymeFormDataByName> = EponymeFormAtPath extends EponymeFormDefinition ? EponymeData : never; type EponymeDataAtPath = Name extends `${infer Folder}/${infer Rest}` ? Folder extends keyof T ? T[Folder] extends EponymeConfig ? EponymeDataAtPath : never : never : Name extends keyof T ? T[Name] extends EponymeSchema ? EponymeData : never : never; type EponymeCollectionAtPath = Name extends `${infer Folder}/${infer Rest}` ? Folder extends keyof T ? T[Folder] extends EponymeConfig ? EponymeCollectionAtPath : never : never : Name extends keyof T ? T[Name] : never; type EponymeFormAtPath = Name extends `${infer Folder}/${infer Rest}` ? Folder extends keyof T ? T[Folder] extends EponymeConfig ? EponymeFormAtPath : never : never : Name extends keyof T ? T[Name] : never; export {};