import type { EntityConstructionUtils, EntityPrivacyPolicy, EntityQueryContext, IEntityMetricsAdapter, ReadonlyEntity, ViewerContext } from '@expo/entity'; import type { AuthorizationResultBasedKnexEntityLoader, EntityLoaderLoadPageArgs, EntityLoaderQuerySelectionModifiers } from './AuthorizationResultBasedKnexEntityLoader.ts'; import type { FieldEqualityCondition } from './BasePostgresEntityDatabaseAdapter.ts'; import { BaseSQLQueryBuilder } from './BaseSQLQueryBuilder.ts'; import type { SQLFragment } from './SQLOperator.ts'; import type { Connection, EntityKnexDataManager } from './internal/EntityKnexDataManager.ts'; /** * Enforcing knex entity loader for non-data-loader-based load methods. * All loads through this loader will throw if the load is not successful. */ export declare class EnforcingKnexEntityLoader, TIDField extends keyof NonNullable>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity, TPrivacyPolicy extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields> { private readonly knexEntityLoader; private readonly queryContext; private readonly knexDataManager; protected readonly metricsAdapter: IEntityMetricsAdapter; private readonly constructionUtils; constructor(knexEntityLoader: AuthorizationResultBasedKnexEntityLoader, queryContext: EntityQueryContext, knexDataManager: EntityKnexDataManager, metricsAdapter: IEntityMetricsAdapter, constructionUtils: EntityConstructionUtils); /** * Load the first entity matching the conjunction of field equality operands and * query modifiers. * * This is a convenience method for {@link loadManyByFieldEqualityConjunctionAsync}. However, the * orderBy query modifier is required to ensure consistent results if more than one entity matches * the filters. * * @throws EntityNotAuthorizedError if viewer is not authorized to view the entity * @returns the first entity matching the filters, or null if none match */ loadFirstByFieldEqualityConjunctionAsync>(fieldEqualityOperands: FieldEqualityCondition[], querySelectionModifiers: Omit, 'limit'> & Required, 'orderBy'>>): Promise; /** * Load entities matching the conjunction of field equality operands and * query modifiers. * * Typically this is used for complex queries that cannot be expressed through simpler * convenience methods such as {@link loadManyByFieldEqualingAsync}. * * @throws EntityNotAuthorizedError if viewer is not authorized to view the entity * @returns entities matching the filters */ loadManyByFieldEqualityConjunctionAsync>(fieldEqualityOperands: FieldEqualityCondition[], querySelectionModifiers?: EntityLoaderQuerySelectionModifiers): Promise; /** * Count entities matching the conjunction of field equality operands. * This does not perform authorization since count does not load full entities. * Note that this should be used with the same caution as loadManyByFieldEqualityConjunctionAsync * regarding indexing since counts can be expensive on large datasets without appropriate indexes. * * @returns count of entities matching the filters */ countByFieldEqualityConjunctionAsync>(fieldEqualityOperands: FieldEqualityCondition[]): Promise; /** * Count entities matching a SQL fragment. * This does not perform authorization since count does not load full entity rows. * Note that this should be used with the same caution as loadManyBySQL regarding indexing * since counts can be expensive on large datasets without appropriate indexes. * * @returns count of entities matching the query */ countBySQLAsync(fragment: SQLFragment>): Promise; /** * Load entities using a SQL query builder. When executed, all queries will enforce authorization and throw if not authorized. * * @example * ```ts * const entities = await ExampleEntity.loader(vc) * .loadManyBySQL(sql`age >= ${18} AND status = ${'active'}`) * .orderBy('createdAt', 'DESC') * .limit(10) * .executeAsync(); * * const { between, inArray } = SQLExpression; * const filtered = await ExampleEntity.loader(vc) * .loadManyBySQL( * sql`${between('age', 18, 65)} AND ${inArray('role', ['admin', 'moderator'])}` * ) * .executeAsync(); * ``` */ loadManyBySQL(fragment: SQLFragment>, modifiers?: EntityLoaderQuerySelectionModifiers): EnforcingSQLQueryBuilder; /** * Load a page of entities with Relay-style cursor pagination. * * @param args - Pagination arguments with pagination and either first/after or last/before * @returns a page of entities matching the pagination arguments * @throws EntityNotAuthorizedError if viewer is not authorized to view any returned entity */ loadPageAsync(args: EntityLoaderLoadPageArgs): Promise>; /** * Get cursor for a given entity that matches what loadPageAsync would produce. * Useful for constructing pagination cursors for entities returned from other loader methods that can then be passed to loadPageAsync for pagination. * Most commonly used for testing pagination behavior. * * @param entity - The entity to get the pagination cursor for. * @returns The pagination cursor for the given entity. */ getPaginationCursorForEntity(entity: TEntity): string; } /** * SQL query builder for EnforcingKnexEntityLoader. * Provides a fluent API for building and executing SQL queries with enforced authorization. */ export declare class EnforcingSQLQueryBuilder, TIDField extends keyof NonNullable>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity, TPrivacyPolicy extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields> extends BaseSQLQueryBuilder { private readonly knexEntityLoader; constructor(knexEntityLoader: AuthorizationResultBasedKnexEntityLoader, sqlFragment: SQLFragment>, modifiers: EntityLoaderQuerySelectionModifiers); /** * Execute the query. * @returns entities matching the query * @throws EntityNotAuthorizedError if viewer is not authorized to view any entity */ executeInternalAsync(): Promise; }