import type { IEntityClass } from '../Entity.ts'; import type { EntityPrivacyPolicy, EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy.ts'; import type { EntityQueryContext } from '../EntityQueryContext.ts'; import type { ReadonlyEntity } from '../ReadonlyEntity.ts'; import type { ViewerContext } from '../ViewerContext.ts'; import { PrivacyPolicyRule, RuleEvaluationResult } from './PrivacyPolicyRule.ts'; /** * Directive for specifying the parent relationship in AllowIfInParentCascadeDeletionPrivacyPolicyRule. */ export interface AllowIfInParentCascadeDeletionDirective>, TParentEntity extends ReadonlyEntity, TParentPrivacyPolicy extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields = keyof TFields, TParentSelectedFields extends keyof TParentFields = keyof TParentFields> { /** * Class (or classes) of parent entity that should trigger a cascade set null update to a field * within the entity being authorized. Pass an array when multiple sibling classes backed by the * same table can be the deletion source. */ parentEntityClass: IEntityClass | readonly IEntityClass[]; /** * Field of the current entity with references the deleting instace of parentEntityClass. */ fieldIdentifyingParentEntity: keyof Pick; /** * Field in parentEntityClass referenced by the value of fieldIdentifyingParentEntity. * If not provided, ID is assumed. */ parentEntityLookupByField?: keyof Pick; } /** * A generic privacy policy rule that allows when an entity is being authorized * as part of a cascading delete from a parent entity. Handles two cases: * - When the field has not yet been null'ed out due to a cascading set null. This is often * required for read rules to authorize the initial re-read of the entity being update set null'ed. * - When the field has been null'ed out due to a cascading set null. This is often required * the update rules for the field nullification. * * These two cases could theoretically be handled by two separate (stricter) rules, but are combined * to simplify configuration since practically there are few cases where having them be combined would * preset an issue. * * @example * Billing info owned by an account, but records who created the billing info in creating_user_id. User is a member of that account. * User can delete themselves, and the billing info's creating_user_id field is cascade set null'ed when the user is deleted. * * ```ts * class BillingInfoEntityPrivacyPolicy extends EntityPrivacyPolicy<...> { * protected override readonly readRules = [ * ..., * new AllowIfInParentCascadeDeletionPrivacyPolicyRule<...>({ * fieldIdentifyingParentEntity: 'creating_user_id', * parentEntityClass: UserEntity, * }), * ]; * * protected override readonly updateRules = [ * ..., * new AllowIfInParentCascadeDeletionPrivacyPolicyRule<...>({ * fieldIdentifyingParentEntity: 'creating_user_id', * parentEntityClass: UserEntity, * }), * ]; * } * ``` */ export declare class AllowIfInParentCascadeDeletionPrivacyPolicyRule>, TViewerContext extends ViewerContext, TEntity extends ReadonlyEntity, TFields2 extends object, TIDField2 extends keyof NonNullable>, TEntity2 extends ReadonlyEntity, TPrivacyPolicy2 extends EntityPrivacyPolicy, TSelectedFields extends keyof TFields = keyof TFields, TSelectedFields2 extends keyof TFields2 = keyof TFields2> extends PrivacyPolicyRule { private readonly directive; constructor(directive: AllowIfInParentCascadeDeletionDirective); evaluateAsync(_viewerContext: TViewerContext, _queryContext: EntityQueryContext, evaluationContext: EntityPrivacyPolicyEvaluationContext, entity: TEntity): Promise; }