import type { Result } from '@expo/results'; import type { IEntityClass } from './Entity.ts'; import type { EntityPrivacyPolicy } from './EntityPrivacyPolicy.ts'; import type { EntityQueryContext } from './EntityQueryContext.ts'; import type { ReadonlyEntity } from './ReadonlyEntity.ts'; import type { ViewerContext } from './ViewerContext.ts'; /** * An association loader is a set of convenience methods for loading entities * associated with an entity. In relational databases, these entities are often referenced * by foreign keys. */ export declare class AuthorizationResultBasedEntityAssociationLoader, TIDField extends keyof NonNullable>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity, TSelectedFields extends keyof TFields = keyof TFields> { private readonly entity; private readonly queryContext; constructor(entity: TEntity, queryContext: EntityQueryContext); /** * Load an associated entity identified by a field value of this entity. In a relational database, * the field in this entity is a foreign key to the ID of the associated entity. * @param fieldIdentifyingAssociatedEntity - field of this entity containing the ID of the associated entity * @param associatedEntityClass - class of the associated entity */ loadAssociatedEntityAsync, TAssociatedFields extends object, TAssociatedIDField extends keyof NonNullable>, TAssociatedEntity extends ReadonlyEntity, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: TIdentifyingField, associatedEntityClass: IEntityClass): Promise>; /** * Load many entities associated with this entity, often referred to as entites belonging * to this entity. In a relational database, the field in the foreign entity is a * foreign key to the ID of this entity. Also commonly referred to as a has many relationship, * where this entity has many associated entities. * @param associatedEntityClass - class of the associated entities * @param associatedEntityFieldContainingThisID - field of associated entity which contains the ID of this entity */ loadManyAssociatedEntitiesAsync>, TAssociatedEntity extends ReadonlyEntity, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(associatedEntityClass: IEntityClass, associatedEntityFieldContainingThisID: keyof Pick): Promise[]>; /** * Load an associated entity identified by a field value of this entity. In a relational database, * the field in this entity is a foreign key to a unique field of the associated entity. * @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entity * @param associatedEntityClass - class of the associated entity * @param associatedEntityLookupByField - field of associated entity with which to look up the associated entity */ loadAssociatedEntityByFieldEqualingAsync>, TAssociatedEntity extends ReadonlyEntity, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick, associatedEntityClass: IEntityClass, associatedEntityLookupByField: keyof Pick): Promise | null>; /** * Load many associated entities identified by a field value of this entity. In a relational database, * the field in this entity refers to a field of the associated entity. * @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entities * @param associatedEntityClass - class of the associated entities * @param associatedEntityLookupByField - field of associated entities with which to look up the associated entities */ loadManyAssociatedEntitiesByFieldEqualingAsync>, TAssociatedEntity extends ReadonlyEntity, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields>(fieldIdentifyingAssociatedEntity: keyof Pick, associatedEntityClass: IEntityClass, associatedEntityLookupByField: keyof Pick): Promise[]>; /** * Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each * fold step, load an associated entity identified by a field value of the current fold value. * @param loadDirectives - associated entity load directives instructing each step of the folds */ loadAssociatedEntityThroughAsync>, TEntity2 extends ReadonlyEntity, TPrivacyPolicy2 extends EntityPrivacyPolicy, TSelectedFields2 extends keyof TFields2 = keyof TFields2>(loadDirectives: [ EntityLoadThroughDirective ]): Promise | null>; /** * Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each * fold step, load an associated entity identified by a field value of the current fold value. * @param loadDirectives - associated entity load directives instructing each step of the folds */ loadAssociatedEntityThroughAsync>, TEntity2 extends ReadonlyEntity, TPrivacyPolicy2 extends EntityPrivacyPolicy, TFields3 extends object, TIDField3 extends keyof NonNullable>, TEntity3 extends ReadonlyEntity, TPrivacyPolicy3 extends EntityPrivacyPolicy, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3>(loadDirectives: [ EntityLoadThroughDirective, EntityLoadThroughDirective ]): Promise | null>; /** * Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each * fold step, load an associated entity identified by a field value of the current fold value. * @param loadDirectives - associated entity load directives instructing each step of the folds */ loadAssociatedEntityThroughAsync>, TEntity2 extends ReadonlyEntity, TPrivacyPolicy2 extends EntityPrivacyPolicy, TFields3 extends object, TIDField3 extends keyof NonNullable>, TEntity3 extends ReadonlyEntity, TPrivacyPolicy3 extends EntityPrivacyPolicy, TFields4 extends object, TIDField4 extends keyof NonNullable>, TEntity4 extends ReadonlyEntity, TPrivacyPolicy4 extends EntityPrivacyPolicy, TSelectedFields2 extends keyof TFields2 = keyof TFields2, TSelectedFields3 extends keyof TFields3 = keyof TFields3, TSelectedFields4 extends keyof TFields4 = keyof TFields4>(loadDirectives: [ EntityLoadThroughDirective, EntityLoadThroughDirective, EntityLoadThroughDirective ]): Promise | null>; /** * Load an associated entity by folding a sequence of EntityLoadThroughDirective. At each * fold step, load an associated entity identified by a field value of the current fold value. * @param loadDirectives - associated entity load directives instructing each step of the folds */ loadAssociatedEntityThroughAsync(loadDirectives: EntityLoadThroughDirective[]): Promise> | null>; } /** * Instruction for each step of a load-associated-through method. */ export interface EntityLoadThroughDirective>, TAssociatedEntity extends ReadonlyEntity, TAssociatedPrivacyPolicy extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields = keyof TFields, TAssociatedSelectedFields extends keyof TAssociatedFields = keyof TAssociatedFields> { /** * Class of entity to load at this step. */ associatedEntityClass: IEntityClass; /** * Field of the current entity with which to load an instance of associatedEntityClass. */ fieldIdentifyingAssociatedEntity: keyof Pick; /** * Field by which to load the instance of associatedEntityClass. If not provided, the * associatedEntityClass instance is fetched by its ID. */ associatedEntityLookupByField?: keyof Pick; }