import type { EntityConfiguration, EntityQueryContext, IEntityMetricsAdapter } from '@expo/entity'; import type { BasePostgresEntityDatabaseAdapter, FieldEqualityCondition, PostgresOrderByClause, PostgresQuerySelectionModifiers } from '../BasePostgresEntityDatabaseAdapter.ts'; import { PaginationStrategy } from '../PaginationStrategy.ts'; import { SQLFragment } from '../SQLOperator.ts'; import type { NonNullableKeys } from './utilityTypes.ts'; interface DataManagerStandardSpecification> { strategy: PaginationStrategy.STANDARD; orderBy: readonly PostgresOrderByClause[]; } type DataManagerFieldNameConstructorFn> = (fieldName: keyof TFields) => SQLFragment; type DataManagerSearchFieldSQLFragmentFnSpecification> = { fieldConstructor: (getFragmentForFieldName: DataManagerFieldNameConstructorFn) => SQLFragment; }; type DataManagerSearchFieldSpecification> = NonNullableKeys | DataManagerSearchFieldSQLFragmentFnSpecification; interface DataManagerSearchSpecificationBase> { term: string; fields: readonly DataManagerSearchFieldSpecification[]; } interface DataManagerILikeSearchSpecification> extends DataManagerSearchSpecificationBase { strategy: PaginationStrategy.ILIKE_SEARCH; } interface DataManagerTrigramSearchSpecification> extends DataManagerSearchSpecificationBase { strategy: PaginationStrategy.TRIGRAM_SEARCH; threshold: number; extraOrderByFields?: readonly DataManagerSearchFieldSpecification[]; } type DataManagerSearchSpecification> = DataManagerILikeSearchSpecification | DataManagerTrigramSearchSpecification; type DataManagerPaginationSpecification> = DataManagerStandardSpecification | DataManagerSearchSpecification; interface BaseUnifiedPaginationArgs> { where?: SQLFragment; pagination: DataManagerPaginationSpecification; } interface ForwardUnifiedPaginationArgs> extends BaseUnifiedPaginationArgs { first: number; last?: never; before?: never; after?: string; } interface BackwardUnifiedPaginationArgs> extends BaseUnifiedPaginationArgs { first?: never; last: number; before?: string; after?: never; } type LoadPageArgs> = ForwardUnifiedPaginationArgs | BackwardUnifiedPaginationArgs; /** * Edge in a connection */ export interface Edge { cursor: string; node: TNode; } /** * Page information for pagination */ export interface PageInfo { hasNextPage: boolean; hasPreviousPage: boolean; startCursor: string | null; endCursor: string | null; } /** * Relay-style Connection type */ export interface Connection { edges: readonly Edge[]; pageInfo: PageInfo; } /** * A knex data manager is responsible for handling non-dataloader-based * database operations. * * @internal */ export declare class EntityKnexDataManager, TIDField extends keyof TFields> { private readonly entityConfiguration; private readonly databaseAdapter; private readonly metricsAdapter; private readonly entityClassName; constructor(entityConfiguration: EntityConfiguration, databaseAdapter: BasePostgresEntityDatabaseAdapter, metricsAdapter: IEntityMetricsAdapter, entityClassName: string); /** * Loads many objects matching the conjunction of where clauses constructed from * specified field equality operands. * * @param queryContext - query context in which to perform the load * @param fieldEqualityOperands - list of field equality where clause operand specifications * @param querySelectionModifiers - limit, offset, and orderBy for the query * @returns array of objects matching the query */ loadManyByFieldEqualityConjunctionAsync(queryContext: EntityQueryContext, fieldEqualityOperands: readonly FieldEqualityCondition[], querySelectionModifiers: PostgresQuerySelectionModifiers): Promise[]>; countByFieldEqualityConjunctionAsync(queryContext: EntityQueryContext, fieldEqualityOperands: readonly FieldEqualityCondition[]): Promise; loadManyBySQLFragmentAsync(queryContext: EntityQueryContext, sqlFragment: SQLFragment, querySelectionModifiers: PostgresQuerySelectionModifiers): Promise[]>; countBySQLFragmentAsync(queryContext: EntityQueryContext, sqlFragment: SQLFragment): Promise; /** * Load a page of objects using cursor-based pagination with unified pagination specification. * * @remarks * * This method implements cursor-based pagination using the seek method for efficient pagination even on large datasets * given appropriate indexes. Cursors are opaque and encode the necessary information to fetch the next page based on the * specified pagination strategy (standard, ILIKE search, or trigram search). For this implementation in particular, * the cursor encodes the ID of the last entity in the page to ensure correct pagination for all strategies, even in cases * where multiple rows have the same value for all fields other than the ID. If the entity referenced by a cursor has been * deleted, the load will return an empty page with `hasNextPage: false`. * * @param queryContext - query context in which to perform the load * @param args - pagination arguments including pagination and first/after or last/before * @returns connection with edges containing field objects and page info */ loadPageAsync(queryContext: EntityQueryContext, args: LoadPageArgs): Promise>>; getCursorForEntityID(entityID: TFields[TIDField]): string; /** * Internal method for loading a page with cursor-based pagination. * Shared logic for both regular and search pagination. */ private loadPageInternalAsync; private combineWhereConditions; private augmentOrderByIfNecessary; private static flipNullsOrderingSpread; private static validateOrderByClauses; /** * Cursor-based pagination uses Postgres tuple comparison (e.g., (a, b) \> (x, y)) which * applies a single comparison direction to all columns. Mixed ordering directions would * produce incorrect pagination results. */ private static validateOrderByClausesHaveConsistentDirection; private encodeOpaqueCursor; private decodeOpaqueCursor; private resolveSearchFieldToSQLFragment; private buildCursorCondition; private buildILikeConditions; private buildTrigramSimilarityExpressions; private buildTrigramExactMatchCaseExpression; private buildTrigramSimilarityGreatestExpression; private buildTrigramCursorCondition; private buildSearchConditionAndOrderBy; private static escapeILikePattern; } export {};