import type { EponymeConfig, EponymeFormDefinitionBase } from '../../types/index.js'; import { type ValidationErrors } from '../../utils/validate-eponyme-data.js'; /** Kept here rather than imported, so the store stays free of H3 imports. */ type DateValue = Date | string; export interface EponymeFormSubmission { id: string; formName: string; data: Record; createdAt: string; } export interface EponymeFormSubmissionPage { submissions: EponymeFormSubmission[]; total: number; page: number; perPage: number; } export interface PrismaEponymeFormSubmissionRow { id: string; formName: string; data: unknown; createdAt: DateValue; } /** One clause per searchable field, ORed together. */ export interface EponymeSubmissionSearch { OR: Array<{ data: { path: string[]; string_contains: string; mode: 'insensitive'; }; }>; } export type EponymeSubmissionWhere = { formName: string; createdAt?: { gte?: Date; lt?: Date; }; } & Partial; /** What an export keeps: a window of reception dates, and the same search as the dashboard. */ export interface EponymeSubmissionExportFilter { /** Inclusive. */ from?: Date; /** Exclusive. */ to?: Date; search?: string; } type SubmissionOrder = { createdAt: 'asc' | 'desc'; } | Array<{ createdAt: 'asc' | 'desc'; } | { id: 'asc' | 'desc'; }>; export type PrismaEponymeFormClient = { eponymeFormSubmission: { create(args: { data: { id: string; formName: string; data: Record; }; }): Promise; findMany(args: { where: EponymeSubmissionWhere; orderBy: SubmissionOrder; skip?: number; take: number; select?: { id: true; }; /** Keyset pagination, which an export walks with so a long one never re-reads what it skipped. */ cursor?: { id: string; }; }): Promise; count(args: { where: EponymeSubmissionWhere; }): Promise; findUnique(args: { where: { id: string; }; }): Promise; delete(args: { where: { id: string; }; }): Promise; deleteMany(args: { where: { formName: string; createdAt?: { lt: Date; }; } | { id: { in: string[]; }; }; }): Promise<{ count: number; }>; }; /** Optional: the doubles the tests build have no transactions, and the fallback below is the same work. */ $transaction?: (fn: (tx: PrismaEponymeFormClient) => Promise) => Promise; }; export declare class EponymeFormService { private readonly client; private readonly forms; private nextRetentionAt; constructor(config: EponymeConfig, client: PrismaEponymeFormClient); getForm(name: string): EponymeFormDefinitionBase | undefined; /** * Without this, a missing model surfaces as "Cannot read properties of undefined (reading 'create')", * which tells the developer nothing about the two steps they actually skipped. */ private submissions; names(): string[]; /** * Runs the same rules as the dashboard, in `publish` mode: a public form has no draft state, so * `required` and the minimum bounds always apply. */ validate(name: string, payload: unknown): { data: Record; } | { errors: ValidationErrors; } | undefined; isHoneypotTriggered(name: string, payload: unknown): boolean; submit(name: string, payload: unknown): Promise<{ submission: EponymeFormSubmission; } | { errors: ValidationErrors; } | undefined>; /** * The counterpart of `submit` for a `custom` form: the host route has already decided to accept the * submission, so this only validates and writes. */ store(name: string, payload: unknown): Promise<{ submission: EponymeFormSubmission; } | { errors: ValidationErrors; } | undefined>; listSubmissions(name: string, options?: { page?: number; perPage?: number; search?: string; }): Promise; /** * An empty `OR` matches nothing in Prisma, so a form with no free-text field must fall back to the * unfiltered clause rather than answer that it has no submissions. */ private submissionWhere; /** Whether the form keeps submissions an export could read. */ collects(name: string): boolean; countSubmissions(name: string, filter?: EponymeSubmissionExportFilter): Promise; /** * Every matching submission, oldest first, read in batches over a keyset: memory stays one batch whatever * the size of the form, and a row inserted during the walk can neither be read twice nor shift a page. */ iterateSubmissions(name: string, filter?: EponymeSubmissionExportFilter, batchSize?: number): AsyncGenerator; private exportWhere; getSubmission(name: string, id: string): Promise; deleteSubmission(name: string, id: string): Promise; /** * Scoped by form name as well as by id: the ids come from the client, and an opaque id alone would let * one form's page delete another form's rows. */ deleteSubmissions(name: string, ids: string[]): Promise; deleteAllSubmissions(name: string): Promise; /** * The quota is made room for and the row written as one unit, so a failed insert cannot leave a deletion * behind. Two submissions landing at the same instant can still both read the same count: a strictly * enforced ceiling would need a serializable transaction, which this does not take. */ private storeSubmission; /** * Retention on a clock rather than on traffic alone: a form that stopped receiving submissions kept * everything it had, however short its configured window. */ private applyRetentionOnSchedule; /** Applies retention and quotas at boot, even when a form no longer receives traffic. */ pruneStoredSubmissions(): Promise; private pruneSubmissions; } /** * A UUIDv7 (RFC 9562) with a 12-bit counter, so ids made by this process sort in the order they were made, * the same millisecond included. Submissions written before keep their random ids, which still order them * consistently, if not chronologically, behind `createdAt`. */ export declare function createSubmissionId(now?: number): string; export {};