import knex from 'knex'; import type { Ctx } from '../types'; type OrderByCtx = Ctx & { alias?: string; }; type OrderBy = string | { [key: string]: 'asc' | 'desc'; } | OrderBy[]; type OrderByColumnValue = { column: string; order?: 'asc' | 'desc'; }; type OrderByRawValue = { rawExpression: 'status'; isI18n?: boolean; order?: 'asc' | 'desc'; }; export type OrderByValue = OrderByColumnValue | OrderByRawValue; /** * Builds a SQL CASE expression that maps each row to a numeric status rank: * 0 = draft/created (no published sibling with same documentId [+ locale]) * 1 = modified (draft updated_at > published updated_at for same documentId [+ locale]) * 2 = published * * @param db - Database instance (used to access knex raw) * @param tableName - Actual DB table name (used in correlated subqueries) * @param tableAlias - Alias of the table in the outer query (e.g. "t0") * @param isI18n - When true, adds a locale condition to avoid cross-locale contamination */ export declare const buildStatusSortExpression: (db: { connection: { raw: (sql: string, bindings?: unknown[]) => knex.Knex.Raw; }; }, tableName: string, tableAlias: string, isI18n?: boolean) => knex.Knex.Raw; /** DB handle accepted by {@link buildStatusSortExpression}. */ type StatusSortDb = Parameters[0]; /** * Shape passed to Knex `orderBy` for compound ordering. Knex accepts `Knex.Raw` in the column * position at runtime; generated typings sometimes only list string. */ export type KnexOrderByColumnDescriptor = { column: string | knex.Knex.Raw; order?: 'asc' | 'desc'; }; /** * Maps processed {@link OrderByValue} entries to descriptors Knex can consume. Translates the * virtual `status` sort into a parameterized raw SQL expression. */ export declare const toKnexOrderByDescriptor: (db: StatusSortDb, tableName: string, rootTableAlias: string, entry: OrderByValue) => KnexOrderByColumnDescriptor; export declare const processOrderBy: (orderBy: OrderBy, ctx: OrderByCtx) => OrderByValue[]; export declare const getStrapiOrderColumnAlias: (column: string) => string; /** * Wraps the original Knex query with deep sorting functionality. * * The function takes an original query and an OrderByCtx object as parameters and returns a new Knex query with deep sorting applied. */ export declare const wrapWithDeepSort: (originalQuery: knex.Knex.QueryBuilder, ctx: OrderByCtx) => knex.Knex.QueryBuilder; export {}; //# sourceMappingURL=order-by.d.ts.map